From 8a3b8a90e8d70c25bae226e4c99f626d783e1af6 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Sun, 21 Aug 2022 00:17:37 +0100 Subject: [PATCH] aux_serial: Renamed the receive FIFO indexes --- src/platforms/common/aux_serial.c | 22 +++++++++++----------- src/platforms/common/usb_serial.c | 10 +++++----- src/platforms/common/usbuart.h | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/platforms/common/aux_serial.c b/src/platforms/common/aux_serial.c index c27675f..8f2a1d4 100644 --- a/src/platforms/common/aux_serial.c +++ b/src/platforms/common/aux_serial.c @@ -38,9 +38,9 @@ #include "aux_serial.h" /* Fifo in pointer, writes assumed to be atomic, should be only incremented within RX ISR */ -uint8_t buf_rx_in; +uint8_t aux_serial_receive_write_index; /* Fifo out pointer, writes assumed to be atomic, should be only incremented outside RX ISR */ -uint8_t buf_rx_out; +uint8_t aux_serial_receive_read_index; #if defined(STM32F0) || defined(STM32F1) || defined(STM32F3) || defined(STM32F4) static char aux_serial_transmit_buffer[2U][AUX_UART_BUFFER_SIZE]; @@ -442,13 +442,13 @@ void USBUART_ISR(void) /* If the next increment of rx_in would put it at the same point * as rx_out, the FIFO is considered full. */ - if (((buf_rx_in + 1) % AUX_UART_BUFFER_SIZE) != buf_rx_out) { + if (((aux_serial_receive_write_index + 1) % AUX_UART_BUFFER_SIZE) != aux_serial_receive_read_index) { /* insert into FIFO */ - buf_rx[buf_rx_in++] = c; + buf_rx[aux_serial_receive_write_index++] = c; /* wrap out pointer */ - if (buf_rx_in >= AUX_UART_BUFFER_SIZE) - buf_rx_in = 0; + if (aux_serial_receive_write_index >= AUX_UART_BUFFER_SIZE) + aux_serial_receive_write_index = 0; } else flush = true; } @@ -456,16 +456,16 @@ void USBUART_ISR(void) if (flush) { /* forcibly empty fifo if no USB endpoint */ if (usb_get_config() != 1) { - buf_rx_out = buf_rx_in; + aux_serial_receive_read_index = aux_serial_receive_write_index; return; } char packet_buf[CDCACM_PACKET_SIZE]; uint8_t packet_size = 0; - uint8_t buf_out = buf_rx_out; + uint8_t buf_out = aux_serial_receive_read_index; /* copy from uart FIFO into local usb packet buffer */ - while (buf_rx_in != buf_out && packet_size < CDCACM_PACKET_SIZE) { + while (aux_serial_receive_write_index != buf_out && packet_size < CDCACM_PACKET_SIZE) { packet_buf[packet_size++] = buf_rx[buf_out++]; /* wrap out pointer */ @@ -474,9 +474,9 @@ void USBUART_ISR(void) } /* advance fifo out pointer by amount written */ - buf_rx_out += usbd_ep_write_packet(usbdev, + aux_serial_receive_read_index += usbd_ep_write_packet(usbdev, CDCACM_UART_ENDPOINT, packet_buf, packet_size); - buf_rx_out %= AUX_UART_BUFFER_SIZE; + aux_serial_receive_read_index %= AUX_UART_BUFFER_SIZE; } } #endif diff --git a/src/platforms/common/usb_serial.c b/src/platforms/common/usb_serial.c index 08789cc..c1e304f 100644 --- a/src/platforms/common/usb_serial.c +++ b/src/platforms/common/usb_serial.c @@ -240,12 +240,12 @@ static void debug_uart_send_rx_packet(void) { aux_serial_receive_complete = false; /* Calculate writing position in the FIFO */ - const uint32_t buf_rx_in = + const uint32_t aux_serial_receive_write_index = (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. * If fifo empty, nothing further to do. */ - if (usb_get_config() != 1 || (buf_rx_in == buf_rx_out + if (usb_get_config() != 1 || (aux_serial_receive_write_index == aux_serial_receive_read_index #ifdef ENABLE_DEBUG && usb_dbg_in == usb_dbg_out #endif @@ -254,7 +254,7 @@ static void debug_uart_send_rx_packet(void) #ifdef ENABLE_DEBUG usb_dbg_out = usb_dbg_in; #endif - buf_rx_out = buf_rx_in; + 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; @@ -280,11 +280,11 @@ static void debug_uart_send_rx_packet(void) #endif /* Copy data from uart RX FIFO into local usb packet buffer */ - packet_size = copy_from_fifo(packet_buf, buf_rx, buf_rx_out, buf_rx_in, CDCACM_PACKET_SIZE - 1, AUX_UART_BUFFER_SIZE); + packet_size = copy_from_fifo(packet_buf, buf_rx, aux_serial_receive_read_index, aux_serial_receive_write_index, CDCACM_PACKET_SIZE - 1, AUX_UART_BUFFER_SIZE); /* Advance fifo out pointer by amount written */ const uint16_t written = usbd_ep_write_packet(usbdev, CDCACM_UART_ENDPOINT, packet_buf, packet_size); - buf_rx_out = (buf_rx_out + written) % AUX_UART_BUFFER_SIZE; + aux_serial_receive_read_index = (aux_serial_receive_read_index + written) % AUX_UART_BUFFER_SIZE; } } diff --git a/src/platforms/common/usbuart.h b/src/platforms/common/usbuart.h index ce22761..6c4345e 100644 --- a/src/platforms/common/usbuart.h +++ b/src/platforms/common/usbuart.h @@ -58,6 +58,6 @@ extern uint8_t usb_dbg_out; extern char buf_rx[AUX_UART_BUFFER_SIZE]; #endif -extern uint8_t buf_rx_out; +extern uint8_t aux_serial_receive_read_index; #endif