-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdap_process.c
54 lines (48 loc) · 1.4 KB
/
dap_process.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "usbd_core.h"
#include "DAP_config.h"
#include "DAP.h"
uint8_t USB_Request[DAP_PACKET_SIZE]; // Request Buffer
static uint8_t USB_Response[DAP_PACKET_SIZE]; // Response Buffer
volatile uint8_t dealing_data = 0;
volatile uint8_t dap_send_busy = 0;
void usb_dap_recv_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
{
if (USB_Request[0] == ID_DAP_TransferAbort) {
usbd_ep_start_read(0, ep, USB_Request, DAP_PACKET_SIZE);
DAP_TransferAbort = 1;
return;
}
if (dealing_data) {
// TODO:
usbd_ep_start_read(busid, ep, USB_Request, DAP_PACKET_SIZE);
return; // Discard packet when buffer is full
}
dealing_data = 1;
usbd_ep_start_read(busid, ep, USB_Request, DAP_PACKET_SIZE);
}
void usb_dap_send_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
{
if (dap_send_busy == 1) {
dap_send_busy = 0;
}
}
void dap_process(void)
{
static uint8_t res_len = 0;
if (dealing_data) {
res_len = DAP_ProcessCommand(USB_Request, USB_Response);
usbd_ep_start_write(0, 0x82, USB_Response, res_len);
dap_send_busy = 1;
while (dap_send_busy) {
/*!< wait */
}
dealing_data = 0;
}
}
void gpio_init(void)
{
gpio_set_mode(LED_CONNECTED, GPIO_OUTPUT_MODE);
gpio_set_mode(LED_RUNNING, GPIO_OUTPUT_MODE);
gpio_write(LED_CONNECTED, 1U);
gpio_write(LED_RUNNING, 1U);
}