Hi there,
I'm developing a device for data logging purpose. It mostly performs 2 FreeRTOS tasks. Firstly, forward all the packets received at UART2 to UART1 and vice versa (High priority). Secondly, send requests of its own to gather data for logging register values via UART1 (lower priority). As you can see, UART1 must be shared for both of these tasks. Moreover, maintain a robust concurrency. I have tried Mutexes, Semaphores, Queue, sometime with ISR (most of these introduces latency in data logging task). Semaphores seems to achieve this but is not flawless. Please suggest a best approach for achieving this.
sharing UART for multiple tasks.
-
- Posts: 1734
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: sharing UART for multiple tasks.
How do you determine what constitutes a 'packet' and when it is ok to insert a 'request' into the stream?forward all the packets received at UART2
What flaws do you see?Semaphores seems to achieve this but is not flawless.
Re: sharing UART for multiple tasks.
Any Modbus request with the correct checksum that is received in UART port 2 constitutes a packet.
At the moment, given that data logging task is initialised with lower priority, it misses a few logging cycles whenever UART1 is occupied. Moreover, the data logging contains time stamp, therefore using a queue/buffer would just delay the time stamp logs too. So I'd rather not even register that data.
At the moment, given that data logging task is initialised with lower priority, it misses a few logging cycles whenever UART1 is occupied. Moreover, the data logging contains time stamp, therefore using a queue/buffer would just delay the time stamp logs too. So I'd rather not even register that data.
-
- Posts: 1734
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: sharing UART for multiple tasks.
Task priorities shouldn't matter in this case.
Use an approach which leverages blocking operations to read from each UART; this is easily done via two tasks, one per UART.
Also, because the UART hardware and driver may buffer both TX and RX data, you may need to first wait for the TX (and RX) buffer to be empty to be able to 'synchronize' data sent to data subsequently received.
Use an approach which leverages blocking operations to read from each UART; this is easily done via two tasks, one per UART.
Also, because the UART hardware and driver may buffer both TX and RX data, you may need to first wait for the TX (and RX) buffer to be empty to be able to 'synchronize' data sent to data subsequently received.
Who is online
Users browsing this forum: No registered users and 187 guests