gdb_if: Use a doubled buffer scheme for reading data from USB

Needed, as the OTG driver erases the data read after eventually calling the callback
This commit is contained in:
Uwe Bonnes 2013-01-20 21:47:03 +01:00
parent 1fa961841d
commit 749fb318e7
3 changed files with 28 additions and 7 deletions

View File

@ -21,7 +21,10 @@
#ifndef __GDB_IF_H
#define __GDB_IF_H
#include <libopencm3/usb/usbd.h>
int gdb_if_init(void);
void gdb_usb_out_cb(usbd_device *dev, uint8_t ep);
unsigned char gdb_if_getchar(void);
unsigned char gdb_if_getchar_to(int timeout);
void gdb_if_putchar(unsigned char c, int flush);

View File

@ -36,6 +36,7 @@
#include <stdlib.h>
#include "platform.h"
#include "gdb_if.h"
#if defined(PLATFORM_HAS_TRACESWO)
#include <traceswo.h>
#endif
@ -487,7 +488,7 @@ static void cdcacm_set_config(usbd_device *dev, u16 wValue)
/* GDB interface */
usbd_ep_setup(dev, 0x01, USB_ENDPOINT_ATTR_BULK,
CDCACM_PACKET_SIZE, NULL);
CDCACM_PACKET_SIZE, gdb_usb_out_cb);
usbd_ep_setup(dev, 0x81, USB_ENDPOINT_ATTR_BULK,
CDCACM_PACKET_SIZE, NULL);
usbd_ep_setup(dev, 0x82, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);

View File

@ -28,9 +28,11 @@
#include "gdb_if.h"
static uint32_t count_out;
static uint32_t count_new;
static uint32_t count_in;
static uint32_t out_ptr;
static uint8_t buffer_out[CDCACM_PACKET_SIZE];
static uint8_t double_buffer_out[CDCACM_PACKET_SIZE];
static uint8_t buffer_in[CDCACM_PACKET_SIZE];
void gdb_if_putchar(unsigned char c, int flush)
@ -49,17 +51,28 @@ void gdb_if_putchar(unsigned char c, int flush)
}
}
void gdb_usb_out_cb(usbd_device *dev, uint8_t ep)
{
(void)ep;
count_new = usbd_ep_read_packet(dev, CDCACM_GDB_ENDPOINT,
double_buffer_out, CDCACM_PACKET_SIZE);
}
unsigned char gdb_if_getchar(void)
{
while(!(out_ptr < count_out)) {
/* Detach if port closed */
if(!cdcacm_get_dtr())
return 0x04;
while(cdcacm_get_config() != 1);
count_out = usbd_ep_read_packet(usbdev, CDCACM_GDB_ENDPOINT,
buffer_out, CDCACM_PACKET_SIZE);
out_ptr = 0;
if (count_new) {
memcpy(buffer_out, double_buffer_out,count_new);
count_out = count_new;
count_new = 0;
out_ptr = 0;
}
}
return buffer_out[out_ptr++];
@ -74,9 +87,13 @@ unsigned char gdb_if_getchar_to(int timeout)
if(!cdcacm_get_dtr())
return 0x04;
count_out = usbd_ep_read_packet(usbdev, CDCACM_GDB_ENDPOINT,
buffer_out, CDCACM_PACKET_SIZE);
out_ptr = 0;
while(cdcacm_get_config() != 1);
if (count_new) {
memcpy(buffer_out, double_buffer_out,count_new);
count_out = count_new;
count_new = 0;
out_ptr = 0;
}
} while(timeout_counter && !(out_ptr < count_out));
if(out_ptr < count_out)