Merge pull request #449 from madcowswe/fix_uart_latency

Increase UART polling frequency from 1kHz to 8kHz
This commit is contained in:
samuelsadok
2020-08-10 11:04:06 +02:00
committed by GitHub
4 changed files with 19 additions and 5 deletions
+4
View File
@@ -163,6 +163,10 @@ public:
// TODO: change arming logic to arm after waiting
bool main_continue = update_handler();
if (axis_num_ == 0) {
uart_poll(); // TODO: move to board-level control loop once it exists
}
// Check we meet deadlines after queueing
++loop_counter_;
+1
View File
@@ -12,6 +12,7 @@
#include <fibre/protocol.hpp>
#include <communication/interface_usb.h>
#include <communication/interface_i2c.h>
#include <communication/interface_uart.h>
extern "C" {
#endif
+13 -5
View File
@@ -62,9 +62,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 (huart4.RxState != HAL_UART_STATE_BUSY_RX) {
HAL_UART_AbortReceive(&huart4);
HAL_UART_Receive_DMA(&huart4, dma_rx_buffer, sizeof(dma_rx_buffer));
@@ -92,11 +90,17 @@ static void uart_server_thread(void * ctx) {
new_rcv_idx - dma_last_rcv_idx, uart4_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);
}
}
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(&huart4, dma_rx_buffer, sizeof(dma_rx_buffer));
@@ -107,6 +111,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);
}
+1
View File
@@ -14,6 +14,7 @@ extern osThreadId uart_thread;
extern const uint32_t stack_size_uart_thread;
void start_uart_server(void);
void uart_poll(void);
#ifdef __cplusplus
}