Merge remote-tracking branch 'origin/devel' into lowlevel-refactor

This commit is contained in:
Samuel Sadok
2020-08-19 11:51:08 +02:00
10 changed files with 627 additions and 203 deletions
+13 -5
View File
@@ -64,9 +64,7 @@ static void uart_server_thread(void * ctx) {
(void) ctx;
for (;;) {
osDelay(1);
// Check for UART errors and restart recieve DMA transfer if required
// Check for UART errors and restart receive DMA transfer if required
if (huart_->RxState != HAL_UART_STATE_BUSY_RX) {
HAL_UART_AbortReceive(huart_);
HAL_UART_Receive_DMA(huart_, dma_rx_buffer, sizeof(dma_rx_buffer));
@@ -94,12 +92,18 @@ static void uart_server_thread(void * ctx) {
new_rcv_idx - dma_last_rcv_idx, uart_stream_output);
dma_last_rcv_idx = new_rcv_idx;
}
};
// The thread is woken up by the control loop at 8kHz. This should be
// enough for most applications.
// At 1Mbaud/s that corresponds to at most 12.5 bytes which can arrive
// during the sleep period.
osThreadSuspend(nullptr);
}
}
// TODO: allow multiple UART server instances
void start_uart_server() {
// DMA is set up to recieve in a circular buffer forever.
// DMA is set up to receive in a circular buffer forever.
// We dont use interrupts to fetch the data, instead we periodically read
// data out of the circular buffer into a parse buffer, controlled by a state machine
HAL_UART_Receive_DMA(huart_, dma_rx_buffer, sizeof(dma_rx_buffer));
@@ -110,6 +114,10 @@ void start_uart_server() {
uart_thread = osThreadCreate(osThread(uart_server_thread_def), NULL);
}
void uart_poll() {
osThreadResume(uart_thread);
}
void HAL_UART_TxCpltCallback(UART_HandleTypeDef* huart) {
osSemaphoreRelease(sem_uart_dma);
}