void UART_Send(void *pBuf) { if(!mqEnqueue(&uart_tx_queue, pBuf)) mqFree(pBuf); else uart_tx_task(); }
void * UART_Get(void) { uart_tx_task(); // Rx Task static uint8_t rx_pos = 0; static uint8_t rx_len = 0; static MQ_t * pRx_buf; static uint16_t rx_wd = 0; while(hal_uart_datardy(UART_PHY_PORT)) { uint8_t data = hal_uart_get(UART_PHY_PORT); rx_wd = (HAL_get_ms() & 0xFFFF); if(rx_len == 0) { if((data >= 2) && (data < sizeof(MQTTSN_MESSAGE_t))) { pRx_buf = mqAlloc(sizeof(MQ_t)); rx_len = data; rx_pos = 0; } } else { if(rx_pos < sizeof(MQTTSN_MESSAGE_t)) pRx_buf->m.raw[rx_pos++] = data; if(rx_pos == rx_len) { memcpy(pRx_buf->a.phy1addr, (const void *)&uart_addr, sizeof(UART_ADDR_t)); pRx_buf->Length = rx_len; rx_len = 0; #ifdef LED_On LED_On(); #endif // LED_On return pRx_buf; } } } if((rx_len != 0) && (((HAL_get_ms() & 0xFFFF) - rx_wd) > 100)) { rx_len = 0; mqFree(pRx_buf); } return NULL; }
void * UART_Get(void) { uart_tx_task(); // Rx Task static uint8_t rx_pos = 0; static uint8_t rx_len = 0; static MQ_t * pRx_buf; static uint32_t rx_wd = 0; while(hal_uart_datardy(UART_PHY_PORT)) { uint8_t data = hal_uart_get(UART_PHY_PORT); rx_wd = hal_get_ms() + 50; if(rx_len == 0) { if(data >= 2) { pRx_buf = mqAlloc(sizeof(MQ_t)); if(pRx_buf != NULL) rx_len = data; rx_pos = 0; } } else { if(rx_pos < sizeof(MQTTSN_MESSAGE_t)) pRx_buf->raw[rx_pos++] = data; if(rx_pos == rx_len) { memcpy(pRx_buf->phy1addr, (const void *)&uart_addr, sizeof(UART_ADDR_t)); pRx_buf->Length = rx_len; rx_len = 0; Activity(UART_PHY); return pRx_buf; } } } if((rx_len != 0) && (rx_wd < hal_get_ms())) rx_len = 0; return NULL; }