|
|
@ -37,15 +37,15 @@ static volatile uint8_t buffer_in[CDCACM_PACKET_SIZE]; |
|
|
|
void gdb_if_putchar(unsigned char c, int flush) |
|
|
|
{ |
|
|
|
buffer_in[count_in++] = c; |
|
|
|
if(flush || (count_in == CDCACM_PACKET_SIZE)) { |
|
|
|
if (flush || count_in == CDCACM_PACKET_SIZE) { |
|
|
|
/* Refuse to send if USB isn't configured, and
|
|
|
|
* don't bother if nobody's listening */ |
|
|
|
if((usb_get_config() != 1) || !gdb_uart_get_dtr()) { |
|
|
|
if (usb_get_config() != 1 || !gdb_uart_get_dtr()) { |
|
|
|
count_in = 0; |
|
|
|
return; |
|
|
|
} |
|
|
|
while(usbd_ep_write_packet(usbdev, CDCACM_GDB_ENDPOINT, |
|
|
|
(uint8_t *)buffer_in, count_in) <= 0); |
|
|
|
while (usbd_ep_write_packet(usbdev, CDCACM_GDB_ENDPOINT, (uint8_t *)buffer_in, count_in) <= 0) |
|
|
|
continue; |
|
|
|
count_in = 0; |
|
|
|
} |
|
|
|
} |
|
|
@ -56,27 +56,23 @@ void gdb_usb_out_cb(usbd_device *dev, uint8_t ep) |
|
|
|
static uint8_t buf[CDCACM_PACKET_SIZE]; |
|
|
|
|
|
|
|
usbd_ep_nak_set(dev, CDCACM_GDB_ENDPOINT, 1); |
|
|
|
uint32_t count = usbd_ep_read_packet(dev, CDCACM_GDB_ENDPOINT, |
|
|
|
(uint8_t *)buf, CDCACM_PACKET_SIZE); |
|
|
|
uint32_t count = usbd_ep_read_packet(dev, CDCACM_GDB_ENDPOINT, (uint8_t *)buf, CDCACM_PACKET_SIZE); |
|
|
|
|
|
|
|
|
|
|
|
uint32_t idx; |
|
|
|
for (idx=0; idx<count; idx++) { |
|
|
|
for (uint32_t idx = 0; idx < count; idx++) |
|
|
|
buffer_out[head_out++ % sizeof(buffer_out)] = buf[idx]; |
|
|
|
} |
|
|
|
|
|
|
|
usbd_ep_nak_set(dev, CDCACM_GDB_ENDPOINT, 0); |
|
|
|
} |
|
|
|
|
|
|
|
unsigned char gdb_if_getchar(void) |
|
|
|
{ |
|
|
|
|
|
|
|
while(tail_out == head_out) { |
|
|
|
while (tail_out == head_out) { |
|
|
|
/* Detach if port closed */ |
|
|
|
if(!gdb_uart_get_dtr()) |
|
|
|
if (!gdb_uart_get_dtr()) |
|
|
|
return 0x04; |
|
|
|
|
|
|
|
while(usb_get_config() != 1); |
|
|
|
while (usb_get_config() != 1) |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
return buffer_out[tail_out++ % sizeof(buffer_out)]; |
|
|
@ -87,15 +83,17 @@ unsigned char gdb_if_getchar_to(int timeout) |
|
|
|
platform_timeout t; |
|
|
|
platform_timeout_set(&t, timeout); |
|
|
|
|
|
|
|
if(head_out == tail_out) do { |
|
|
|
/* Detach if port closed */ |
|
|
|
if(!gdb_uart_get_dtr()) |
|
|
|
return 0x04; |
|
|
|
if (head_out == tail_out) |
|
|
|
do { |
|
|
|
/* Detach if port closed */ |
|
|
|
if (!gdb_uart_get_dtr()) |
|
|
|
return 0x04; |
|
|
|
|
|
|
|
while(usb_get_config() != 1); |
|
|
|
} while(!platform_timeout_is_expired(&t) && head_out == tail_out); |
|
|
|
while (usb_get_config() != 1) |
|
|
|
continue; |
|
|
|
} while (!platform_timeout_is_expired(&t) && head_out == tail_out); |
|
|
|
|
|
|
|
if(head_out != tail_out) |
|
|
|
if (head_out != tail_out) |
|
|
|
return gdb_if_getchar(); |
|
|
|
|
|
|
|
return -1; |
|
|
|