usb_serial: Begun refactoring out components of debug_uart_send_aux_serial_data()
This commit is contained in:
parent
90a0931f78
commit
cd67c7de29
|
@ -273,6 +273,33 @@ void aux_serial_send(const size_t len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t aux_serial_update_receive_buffer_fullness(void)
|
||||||
|
{
|
||||||
|
aux_serial_receive_write_index =
|
||||||
|
AUX_UART_BUFFER_SIZE - dma_get_number_of_data(USBUSART_DMA_BUS, USBUSART_DMA_RX_CHAN);
|
||||||
|
aux_serial_receive_write_index %= AUX_UART_BUFFER_SIZE;
|
||||||
|
return aux_serial_receive_write_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool aux_serial_receive_has_data(void)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
#ifdef ENABLE_DEBUG
|
||||||
|
usb_dbg_in != usb_dbg_out ||
|
||||||
|
#endif
|
||||||
|
aux_serial_receive_write_index != aux_serial_receive_read_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void aux_serial_drain_receive_buffer(void)
|
||||||
|
{
|
||||||
|
#ifdef ENABLE_DEBUG
|
||||||
|
usb_dbg_out = usb_dbg_in;
|
||||||
|
#endif
|
||||||
|
aux_serial_receive_read_index = aux_serial_receive_write_index;
|
||||||
|
/* Turn off LED */
|
||||||
|
usbuart_set_led_state(RX_LED_ACT, false);
|
||||||
|
}
|
||||||
|
|
||||||
static void aux_serial_receive_isr(const uint32_t usart, const uint8_t dma_irq)
|
static void aux_serial_receive_isr(const uint32_t usart, const uint8_t dma_irq)
|
||||||
{
|
{
|
||||||
nvic_disable_irq(dma_irq);
|
nvic_disable_irq(dma_irq);
|
||||||
|
|
|
@ -38,4 +38,8 @@ size_t aux_serial_transmit_buffer_fullness(void);
|
||||||
/* Send a number of bytes staged into the current transmit bufer */
|
/* Send a number of bytes staged into the current transmit bufer */
|
||||||
void aux_serial_send(size_t len);
|
void aux_serial_send(size_t len);
|
||||||
|
|
||||||
|
size_t aux_serial_update_receive_buffer_fullness(void);
|
||||||
|
bool aux_serial_receive_has_data(void);
|
||||||
|
void aux_serial_drain_receive_buffer(void);
|
||||||
|
|
||||||
#endif /*AUX_SERIAL_H*/
|
#endif /*AUX_SERIAL_H*/
|
||||||
|
|
|
@ -236,31 +236,18 @@ static uint32_t copy_from_fifo(char *dst, const char *src, uint32_t start, uint3
|
||||||
* Runs deferred processing for AUX serial RX, draining RX FIFO by sending
|
* Runs deferred processing for AUX serial RX, draining RX FIFO by sending
|
||||||
* characters to host PC via the debug serial interface. Allowed to write to FIFO OUT pointer.
|
* characters to host PC via the debug serial interface. Allowed to write to FIFO OUT pointer.
|
||||||
*/
|
*/
|
||||||
static void debug_uart_send_rx_packet(void)
|
static void debug_uart_send_aux_serial_data(void)
|
||||||
{
|
{
|
||||||
aux_serial_receive_complete = false;
|
aux_serial_receive_complete = false;
|
||||||
/* Calculate writing position in the FIFO */
|
/* Calculate writing position in the FIFO */
|
||||||
const uint32_t aux_serial_receive_write_index =
|
const size_t aux_serial_receive_write_index = aux_serial_update_receive_buffer_fullness();
|
||||||
(AUX_UART_BUFFER_SIZE - dma_get_number_of_data(USBUSART_DMA_BUS, USBUSART_DMA_RX_CHAN)) % AUX_UART_BUFFER_SIZE;
|
|
||||||
|
|
||||||
/* Forcibly empty fifo if no USB endpoint.
|
/* Forcibly empty fifo if no USB endpoint.
|
||||||
* If fifo empty, nothing further to do. */
|
* If fifo empty, nothing further to do. */
|
||||||
if (usb_get_config() != 1 || (aux_serial_receive_write_index == aux_serial_receive_read_index
|
if (usb_get_config() != 1 || !aux_serial_receive_has_data()) {
|
||||||
#ifdef ENABLE_DEBUG
|
aux_serial_drain_receive_buffer();
|
||||||
&& usb_dbg_in == usb_dbg_out
|
|
||||||
#endif
|
|
||||||
))
|
|
||||||
{
|
|
||||||
#ifdef ENABLE_DEBUG
|
|
||||||
usb_dbg_out = usb_dbg_in;
|
|
||||||
#endif
|
|
||||||
aux_serial_receive_read_index = aux_serial_receive_write_index;
|
|
||||||
/* Turn off LED */
|
|
||||||
usbuart_set_led_state(RX_LED_ACT, false);
|
|
||||||
aux_serial_receive_complete = true;
|
aux_serial_receive_complete = true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* To avoid the need of sending ZLP don't transmit full packet.
|
/* To avoid the need of sending ZLP don't transmit full packet.
|
||||||
* Also reserve space for copy function overrun.
|
* Also reserve space for copy function overrun.
|
||||||
*/
|
*/
|
||||||
|
@ -297,7 +284,7 @@ void debug_uart_run(void)
|
||||||
|
|
||||||
/* Try to send a packet if usb is idle */
|
/* Try to send a packet if usb is idle */
|
||||||
if (aux_serial_receive_complete)
|
if (aux_serial_receive_complete)
|
||||||
debug_uart_send_rx_packet();
|
debug_uart_send_aux_serial_data();
|
||||||
|
|
||||||
nvic_enable_irq(USB_IRQ);
|
nvic_enable_irq(USB_IRQ);
|
||||||
}
|
}
|
||||||
|
@ -307,7 +294,7 @@ static void debug_uart_send_callback(usbd_device *dev, uint8_t ep)
|
||||||
(void) ep;
|
(void) ep;
|
||||||
(void) dev;
|
(void) dev;
|
||||||
#if defined(STM32F0) || defined(STM32F1) || defined(STM32F3) || defined(STM32F4)
|
#if defined(STM32F0) || defined(STM32F1) || defined(STM32F3) || defined(STM32F4)
|
||||||
debug_uart_send_rx_packet();
|
debug_uart_send_aux_serial_data();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue