| 123456789101112131415161718192021222324252627282930313233 |
- #include "onechip_include_header.h"
- /* ISR is the sole writer of last; foreground is the sole writer of head.
- * One slot remains empty to distinguish full from empty. */
- uint8_t g_wifi_rx_buf[WIFI_RX_BUF_SIZE];
- volatile uint32_t g_wifi_rx_last, g_wifi_rx_head, g_wifi_rx_last_tick;
- volatile uint8_t g_wifi_rx_fault;
- void esp_receive_Rec_IDLE(UART_HandleTypeDef *huart)
- {
- uint32_t sr = huart->Instance->SR;
- if (sr & (USART_SR_RXNE | USART_SR_ORE | USART_SR_FE | USART_SR_NE)) {
- uint8_t byte = (uint8_t)huart->Instance->DR; /* SR then DR clears errors */
- if (sr & (USART_SR_ORE | USART_SR_FE | USART_SR_NE)) g_wifi_rx_fault = 2;
- if (sr & USART_SR_RXNE) {
- uint32_t next = (g_wifi_rx_last + 1) % WIFI_RX_BUF_SIZE;
- if (next == g_wifi_rx_head) g_wifi_rx_fault = 1;
- else { g_wifi_rx_buf[g_wifi_rx_last] = byte; g_wifi_rx_last = next; }
- g_wifi_rx_last_tick = sysinf.conter10ms;
- }
- }
- }
- /* Discard only the current snapshot; never reset the ISR write cursor. */
- void wifi_receive_clear(void) { g_wifi_rx_head = g_wifi_rx_last; }
- void esp_receive_Rec_Start(UART_HandleTypeDef *huart)
- {
- __HAL_UART_CLEAR_IDLEFLAG(huart);
- wifi_receive_clear();
- g_wifi_rx_fault = 0;
- __HAL_UART_ENABLE_IT(huart, UART_IT_RXNE);
- }
|