usbuart: Moved usbuart_run() into usb_serial.c
This commit is contained in:
parent
04cf410247
commit
2d83b25b3c
|
@ -211,6 +211,20 @@ size_t debug_uart_write(const char *buf, const size_t len)
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void usbuart_run(void)
|
||||||
|
{
|
||||||
|
nvic_disable_irq(USB_IRQ);
|
||||||
|
|
||||||
|
/* Enable LED */
|
||||||
|
usbuart_set_led_state(RX_LED_ACT, true);
|
||||||
|
|
||||||
|
/* Try to send a packet if usb is idle */
|
||||||
|
if (rx_usb_trfr_cplt)
|
||||||
|
usbuart_send_rx_packet();
|
||||||
|
|
||||||
|
nvic_enable_irq(USB_IRQ);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* newlib defines _write as a weak link'd function for user code to override.
|
* newlib defines _write as a weak link'd function for user code to override.
|
||||||
*
|
*
|
||||||
|
|
|
@ -27,8 +27,13 @@
|
||||||
void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep);
|
void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep);
|
||||||
void usbuart_usb_in_cb(usbd_device *dev, uint8_t ep);
|
void usbuart_usb_in_cb(usbd_device *dev, uint8_t ep);
|
||||||
|
|
||||||
|
void usbuart_set_led_state(uint8_t ledn, bool state);
|
||||||
|
void usbuart_send_rx_packet(void);
|
||||||
void usbuart_run(void);
|
void usbuart_run(void);
|
||||||
|
|
||||||
|
#define TX_LED_ACT (1 << 0)
|
||||||
|
#define RX_LED_ACT (1 << 1)
|
||||||
|
|
||||||
/* F072 with st_usbfs_v2_usb_drive drops characters at the 64 byte boundary!*/
|
/* F072 with st_usbfs_v2_usb_drive drops characters at the 64 byte boundary!*/
|
||||||
#if !defined(USART_DMA_BUF_SIZE)
|
#if !defined(USART_DMA_BUF_SIZE)
|
||||||
# define USART_DMA_BUF_SIZE 128
|
# define USART_DMA_BUF_SIZE 128
|
||||||
|
@ -36,6 +41,9 @@ void usbuart_run(void);
|
||||||
#define RX_FIFO_SIZE (USART_DMA_BUF_SIZE)
|
#define RX_FIFO_SIZE (USART_DMA_BUF_SIZE)
|
||||||
#define TX_BUF_SIZE (USART_DMA_BUF_SIZE)
|
#define TX_BUF_SIZE (USART_DMA_BUF_SIZE)
|
||||||
|
|
||||||
|
extern bool tx_trfr_cplt;
|
||||||
|
extern bool rx_usb_trfr_cplt;
|
||||||
|
|
||||||
#ifdef ENABLE_DEBUG
|
#ifdef ENABLE_DEBUG
|
||||||
/* Debug Fifo buffer with space for copy fn overrun */
|
/* Debug Fifo buffer with space for copy fn overrun */
|
||||||
extern char usb_dbg_buf[RX_FIFO_SIZE + sizeof(uint64_t)];
|
extern char usb_dbg_buf[RX_FIFO_SIZE + sizeof(uint64_t)];
|
||||||
|
|
|
@ -49,9 +49,6 @@
|
||||||
#define DMA_CGIF DMA_IFCR_CGIF_BIT
|
#define DMA_CGIF DMA_IFCR_CGIF_BIT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TX_LED_ACT (1 << 0)
|
|
||||||
#define RX_LED_ACT (1 << 1)
|
|
||||||
|
|
||||||
/* TX double buffer */
|
/* TX double buffer */
|
||||||
static uint8_t buf_tx[TX_BUF_SIZE * 2];
|
static uint8_t buf_tx[TX_BUF_SIZE * 2];
|
||||||
/* Active buffer part idx */
|
/* Active buffer part idx */
|
||||||
|
@ -59,13 +56,13 @@ static uint8_t buf_tx_act_idx;
|
||||||
/* Active buffer part used capacity */
|
/* Active buffer part used capacity */
|
||||||
static uint8_t buf_tx_act_sz;
|
static uint8_t buf_tx_act_sz;
|
||||||
/* TX transfer complete */
|
/* TX transfer complete */
|
||||||
static bool tx_trfr_cplt = true;
|
bool tx_trfr_cplt = true;
|
||||||
/* RX Fifo buffer with space for copy fn overrun */
|
/* RX Fifo buffer with space for copy fn overrun */
|
||||||
static uint8_t buf_rx[RX_FIFO_SIZE + sizeof(uint64_t)];
|
static uint8_t buf_rx[RX_FIFO_SIZE + sizeof(uint64_t)];
|
||||||
/* RX Fifo out pointer, writes assumed to be atomic */
|
/* RX Fifo out pointer, writes assumed to be atomic */
|
||||||
static uint8_t buf_rx_out;
|
static uint8_t buf_rx_out;
|
||||||
/* RX usb transfer complete */
|
/* RX usb transfer complete */
|
||||||
static bool rx_usb_trfr_cplt = true;
|
bool rx_usb_trfr_cplt = true;
|
||||||
|
|
||||||
#ifdef ENABLE_DEBUG
|
#ifdef ENABLE_DEBUG
|
||||||
/* Debug Fifo buffer with space for copy fn overrun */
|
/* Debug Fifo buffer with space for copy fn overrun */
|
||||||
|
@ -79,7 +76,7 @@ uint8_t usb_dbg_out;
|
||||||
/*
|
/*
|
||||||
* Update led state atomically respecting RX anb TX states.
|
* Update led state atomically respecting RX anb TX states.
|
||||||
*/
|
*/
|
||||||
static void usbuart_set_led_state(uint8_t ledn, bool state)
|
void usbuart_set_led_state(uint8_t ledn, bool state)
|
||||||
{
|
{
|
||||||
CM_ATOMIC_CONTEXT();
|
CM_ATOMIC_CONTEXT();
|
||||||
|
|
||||||
|
@ -265,7 +262,7 @@ void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep)
|
||||||
* Runs deferred processing for USBUSART RX, draining RX FIFO by sending
|
* Runs deferred processing for USBUSART RX, draining RX FIFO by sending
|
||||||
* characters to host PC via CDCACM. Allowed to write to FIFO OUT pointer.
|
* characters to host PC via CDCACM. Allowed to write to FIFO OUT pointer.
|
||||||
*/
|
*/
|
||||||
static void usbuart_send_rx_packet(void)
|
void usbuart_send_rx_packet(void)
|
||||||
{
|
{
|
||||||
rx_usb_trfr_cplt = false;
|
rx_usb_trfr_cplt = false;
|
||||||
/* Calculate writing position in the FIFO */
|
/* Calculate writing position in the FIFO */
|
||||||
|
@ -324,20 +321,6 @@ void usbuart_usb_in_cb(usbd_device *dev, uint8_t ep)
|
||||||
usbuart_send_rx_packet();
|
usbuart_send_rx_packet();
|
||||||
}
|
}
|
||||||
|
|
||||||
void usbuart_run(void)
|
|
||||||
{
|
|
||||||
nvic_disable_irq(USB_IRQ);
|
|
||||||
|
|
||||||
/* Enable LED */
|
|
||||||
usbuart_set_led_state(RX_LED_ACT, true);
|
|
||||||
|
|
||||||
/* Try to send a packet if usb is idle */
|
|
||||||
if (rx_usb_trfr_cplt)
|
|
||||||
usbuart_send_rx_packet();
|
|
||||||
|
|
||||||
nvic_enable_irq(USB_IRQ);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(USART_ICR)
|
#if defined(USART_ICR)
|
||||||
#define USBUSART_ISR_TEMPLATE(USART, DMA_IRQ) do { \
|
#define USBUSART_ISR_TEMPLATE(USART, DMA_IRQ) do { \
|
||||||
nvic_disable_irq(DMA_IRQ); \
|
nvic_disable_irq(DMA_IRQ); \
|
||||||
|
|
Loading…
Reference in New Issue