I am using FreeRTOS in connection with libopencm3. Within a task however, I
would like to be able to query the TX or RX status prior to committing to a
blocking operation. However, libopencm3() only provides blocking
operations, which spin on the CPU.
The following code gives the spirit of what I am trying to do:
inline static int
usart_tx_ready(uint32_t usart) {
return (USART_SR(usart) & USART_SR_TXE) != 0;
}
static void
uart_task(void *args) {
char ch;
for (;;) {
/* Receive char to be TX */
if ( xQueueReceive(uart_txq,&ch,500) == pdPASS ) {
while ( !usart_tx_ready(USART1) )
taskYIELD(); /* Yield CPU to ready tasks */
usart_send_blocking(USART1,ch); /* blocking call */
}
}
}
The present code has the appearance of working but using the UART register
directly (is there a potential ISR conflict with this?)
Eventually, I'll want to do something similar for receiving. Ideally, this
would allow one thread (task) to handle both the RX and TX, to avoid thread
related problems.
So it would be a welcome addition to the libopencm3 library to provide
routines:
int usart_send_ready(uint32_t usart);
int usart_recv_ready(uint32_t usart);
Is there any interest in this? If not, is the approach used for TX above
valid? Will the same approach be safe for RX? I didn't look to see if the
recv side was interrupt driven or not.
Thanks, Warren
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
libopencm3-devel mailing list
libopencm3-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libopencm3-devel