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:
parent
1fa961841d
commit
749fb318e7
@ -21,7 +21,10 @@
|
|||||||
#ifndef __GDB_IF_H
|
#ifndef __GDB_IF_H
|
||||||
#define __GDB_IF_H
|
#define __GDB_IF_H
|
||||||
|
|
||||||
|
#include <libopencm3/usb/usbd.h>
|
||||||
|
|
||||||
int gdb_if_init(void);
|
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(void);
|
||||||
unsigned char gdb_if_getchar_to(int timeout);
|
unsigned char gdb_if_getchar_to(int timeout);
|
||||||
void gdb_if_putchar(unsigned char c, int flush);
|
void gdb_if_putchar(unsigned char c, int flush);
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
#include "gdb_if.h"
|
||||||
#if defined(PLATFORM_HAS_TRACESWO)
|
#if defined(PLATFORM_HAS_TRACESWO)
|
||||||
#include <traceswo.h>
|
#include <traceswo.h>
|
||||||
#endif
|
#endif
|
||||||
@ -487,7 +488,7 @@ static void cdcacm_set_config(usbd_device *dev, u16 wValue)
|
|||||||
|
|
||||||
/* GDB interface */
|
/* GDB interface */
|
||||||
usbd_ep_setup(dev, 0x01, USB_ENDPOINT_ATTR_BULK,
|
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,
|
usbd_ep_setup(dev, 0x81, USB_ENDPOINT_ATTR_BULK,
|
||||||
CDCACM_PACKET_SIZE, NULL);
|
CDCACM_PACKET_SIZE, NULL);
|
||||||
usbd_ep_setup(dev, 0x82, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
usbd_ep_setup(dev, 0x82, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
|
||||||
|
@ -28,9 +28,11 @@
|
|||||||
#include "gdb_if.h"
|
#include "gdb_if.h"
|
||||||
|
|
||||||
static uint32_t count_out;
|
static uint32_t count_out;
|
||||||
|
static uint32_t count_new;
|
||||||
static uint32_t count_in;
|
static uint32_t count_in;
|
||||||
static uint32_t out_ptr;
|
static uint32_t out_ptr;
|
||||||
static uint8_t buffer_out[CDCACM_PACKET_SIZE];
|
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];
|
static uint8_t buffer_in[CDCACM_PACKET_SIZE];
|
||||||
|
|
||||||
void gdb_if_putchar(unsigned char c, int flush)
|
void gdb_if_putchar(unsigned char c, int flush)
|
||||||
@ -49,18 +51,29 @@ 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)
|
unsigned char gdb_if_getchar(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
while(!(out_ptr < count_out)) {
|
while(!(out_ptr < count_out)) {
|
||||||
/* Detach if port closed */
|
/* Detach if port closed */
|
||||||
if(!cdcacm_get_dtr())
|
if(!cdcacm_get_dtr())
|
||||||
return 0x04;
|
return 0x04;
|
||||||
|
|
||||||
while(cdcacm_get_config() != 1);
|
while(cdcacm_get_config() != 1);
|
||||||
count_out = usbd_ep_read_packet(usbdev, CDCACM_GDB_ENDPOINT,
|
if (count_new) {
|
||||||
buffer_out, CDCACM_PACKET_SIZE);
|
memcpy(buffer_out, double_buffer_out,count_new);
|
||||||
|
count_out = count_new;
|
||||||
|
count_new = 0;
|
||||||
out_ptr = 0;
|
out_ptr = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return buffer_out[out_ptr++];
|
return buffer_out[out_ptr++];
|
||||||
}
|
}
|
||||||
@ -74,9 +87,13 @@ unsigned char gdb_if_getchar_to(int timeout)
|
|||||||
if(!cdcacm_get_dtr())
|
if(!cdcacm_get_dtr())
|
||||||
return 0x04;
|
return 0x04;
|
||||||
|
|
||||||
count_out = usbd_ep_read_packet(usbdev, CDCACM_GDB_ENDPOINT,
|
while(cdcacm_get_config() != 1);
|
||||||
buffer_out, CDCACM_PACKET_SIZE);
|
if (count_new) {
|
||||||
|
memcpy(buffer_out, double_buffer_out,count_new);
|
||||||
|
count_out = count_new;
|
||||||
|
count_new = 0;
|
||||||
out_ptr = 0;
|
out_ptr = 0;
|
||||||
|
}
|
||||||
} while(timeout_counter && !(out_ptr < count_out));
|
} while(timeout_counter && !(out_ptr < count_out));
|
||||||
|
|
||||||
if(out_ptr < count_out)
|
if(out_ptr < count_out)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user