Implemented 2 DAP buffers (for SAM D11 for now)

This commit is contained in:
Alex Taradov 2022-07-30 18:57:35 -07:00
parent bf9c66a6bf
commit cd75a36c65
3 changed files with 67 additions and 16 deletions

View File

@ -13,7 +13,7 @@
#define DAP_CONFIG_DEFAULT_CLOCK 1000000 // Hz #define DAP_CONFIG_DEFAULT_CLOCK 1000000 // Hz
#define DAP_CONFIG_PACKET_SIZE 64 #define DAP_CONFIG_PACKET_SIZE 64
#define DAP_CONFIG_PACKET_COUNT 1 #define DAP_CONFIG_PACKET_COUNT 2
#define DAP_CONFIG_JTAG_DEV_COUNT 8 #define DAP_CONFIG_JTAG_DEV_COUNT 8

View File

@ -9,10 +9,10 @@
#include "hal_gpio.h" #include "hal_gpio.h"
/*- Definitions -------------------------------------------------------------*/ /*- Definitions -------------------------------------------------------------*/
//#define HAL_BOARD_STD #define HAL_BOARD_STD
//#define HAL_BOARD_VCP_V1 //#define HAL_BOARD_VCP_V1
//#define HAL_BOARD_VCP_V3 //#define HAL_BOARD_VCP_V3
#define HAL_BOARD_OBD //#define HAL_BOARD_OBD
#if defined(HAL_BOARD_CUSTOM) #if defined(HAL_BOARD_CUSTOM)
// Externally supplied board configuration takes precedence // Externally supplied board configuration takes precedence

View File

@ -22,9 +22,14 @@
/*- Variables ---------------------------------------------------------------*/ /*- Variables ---------------------------------------------------------------*/
static alignas(4) uint8_t app_req_buf_hid[DAP_CONFIG_PACKET_SIZE]; static alignas(4) uint8_t app_req_buf_hid[DAP_CONFIG_PACKET_SIZE];
static alignas(4) uint8_t app_resp_buf_hid[DAP_CONFIG_PACKET_SIZE];
static alignas(4) uint8_t app_req_buf_bulk[DAP_CONFIG_PACKET_SIZE]; static alignas(4) uint8_t app_req_buf_bulk[DAP_CONFIG_PACKET_SIZE];
static alignas(4) uint8_t app_resp_buf_bulk[DAP_CONFIG_PACKET_SIZE]; static alignas(4) uint8_t app_req_buf[DAP_CONFIG_PACKET_SIZE];
static alignas(4) uint8_t app_resp_buf[DAP_CONFIG_PACKET_SIZE];
static int app_req_buf_hid_size = 0;
static int app_req_buf_bulk_size = 0;
static int app_resp_size = 0;
static bool app_resp_free = true;
static int app_resp_interface;
static uint64_t app_system_time = 0; static uint64_t app_system_time = 0;
static uint64_t app_status_timeout = 0; static uint64_t app_status_timeout = 0;
static bool app_dap_event = false; static bool app_dap_event = false;
@ -253,37 +258,35 @@ void usb_cdc_recv_callback(int size)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void usb_hid_send_callback(void) void usb_hid_send_callback(void)
{ {
usb_hid_recv(app_req_buf_hid, DAP_CONFIG_PACKET_SIZE); app_resp_free = true;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void usb_hid_recv_callback(int size) void usb_hid_recv_callback(int size)
{ {
app_dap_event = true; app_req_buf_hid_size = size;
dap_process_request(app_req_buf_hid, sizeof(app_req_buf_hid),
app_resp_buf_hid, sizeof(app_resp_buf_hid));
usb_hid_send(app_resp_buf_hid, sizeof(app_resp_buf_hid));
(void)size;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
static void usb_bulk_send_callback(void) static void usb_bulk_send_callback(void)
{ {
usb_recv(USB_BULK_EP_RECV, app_req_buf_bulk, sizeof(app_req_buf_bulk)); app_resp_free = true;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
static void usb_bulk_recv_callback(int size) static void usb_bulk_recv_callback(int size)
{ {
app_dap_event = true; app_req_buf_bulk_size = size;
size = dap_process_request(app_req_buf_bulk, size,
app_resp_buf_bulk, sizeof(app_resp_buf_bulk));
usb_send(USB_BULK_EP_SEND, app_resp_buf_bulk, size);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void usb_configuration_callback(int config) void usb_configuration_callback(int config)
{ {
app_resp_size = 0;
app_resp_free = true;
app_req_buf_hid_size = 0;
app_req_buf_bulk_size = 0;
usb_set_send_callback(USB_BULK_EP_SEND, usb_bulk_send_callback); usb_set_send_callback(USB_BULK_EP_SEND, usb_bulk_send_callback);
usb_set_recv_callback(USB_BULK_EP_RECV, usb_bulk_recv_callback); usb_set_recv_callback(USB_BULK_EP_RECV, usb_bulk_recv_callback);
@ -325,6 +328,52 @@ static void status_timer_task(void)
#endif #endif
} }
//-----------------------------------------------------------------------------
static void dap_task(void)
{
int size;
if (app_resp_size && app_resp_free)
{
if (USB_INTF_BULK == app_resp_interface)
usb_send(USB_BULK_EP_SEND, app_resp_buf, app_resp_size);
else
usb_hid_send(app_resp_buf, sizeof(app_resp_buf));
app_resp_free = false;
app_resp_size = 0;
}
if (app_req_buf_hid_size)
{
size = app_req_buf_hid_size;
app_req_buf_hid_size = 0;
app_resp_interface = USB_INTF_HID;
memcpy(app_req_buf, app_req_buf_hid, size);
usb_hid_recv(app_req_buf_hid, sizeof(app_req_buf_hid));
}
else if (app_req_buf_bulk_size)
{
size = app_req_buf_bulk_size;
app_req_buf_bulk_size = 0;
app_resp_interface = USB_INTF_BULK;
memcpy(app_req_buf, app_req_buf_bulk, size);
usb_recv(USB_BULK_EP_RECV, app_req_buf_bulk, sizeof(app_req_buf_bulk));
}
else
{
return;
}
app_dap_event = true;
app_resp_size = dap_process_request(app_req_buf, size, app_resp_buf, sizeof(app_resp_buf));
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
int main(void) int main(void)
{ {
@ -356,6 +405,7 @@ int main(void)
sys_time_task(); sys_time_task();
status_timer_task(); status_timer_task();
usb_task(); usb_task();
dap_task();
#ifdef HAL_CONFIG_ENABLE_VCP #ifdef HAL_CONFIG_ENABLE_VCP
tx_task(); tx_task();
@ -370,3 +420,4 @@ int main(void)
return 0; return 0;
} }