Hi
The UART break condition is a special state where the data line is held low for a period longer than that of a normal character - the UART can't be configured to recognise normal characters as break conditions.
It is also possible to use an idle line detection to signal the end of a reception packet (assuming it is not generally possible for multiple packets to arrive without any idle line spacing between them).
For random data reception a free-running method is usually most suitable and the uTasker project integrates FreeRTOS free running UART reception since this is a popular configuration which otherwise has difficulties to be realised when using the standard peripheral libraries. Essentially a low priority FreeRTOS task polls the DMA reception as follows:
static void uart_task(void *pvParameters)
{
QUEUE_TRANSFER length = 0;
QUEUE_HANDLE uart_handle;
unsigned char dataBuffer[1];
while ((uart_handle = fnGetUART_Handle()) == NO_ID_ALLOCATED) { // get the UART handle
vTaskDelay(500/portTICK_RATE_MS); // wait for 500ms in order to allow uTasker to configure UART interfaces
}
fnDebugMsg("FreeRTOS Output\r\n"); // test a UART transmission when the task starts and the UART is ready
FOREVER_LOOP() {
length = fnRead(uart_handle, dataBuffer, sizeof(dataBuffer)); // read waiting data from the DMA input buffer (returns immediately)
if (length != 0) { // if something is available
fnDebugMsg("FreeRTOS Echo:"); // echo it back
fnWrite(uart_handle, dataBuffer, length); // send the reception back
fnDebugMsg("\r\n"); // with termination
}
else { // nothing in the input buffer
vTaskDelay(1); // wait a single tick to allow other tasks to execute
}
}
}
When using idle line instead it looks like
static void uart_task(void *pvParameters)
{
QUEUE_TRANSFER length = 0;
QUEUE_HANDLE uart_handle;
unsigned char dataBuffer[128];
xSemaphore = xSemaphoreCreateBinary(); // create a binary semaphore
while ((uart_handle = fnGetUART_Handle()) == NO_ID_ALLOCATED) { // get the UART handle
vTaskDelay(500/portTICK_RATE_MS); // wait for 500ms in order to allow uTasker to configure UART interfaces
}
fnDebugMsg("FreeRTOS Output\r\n"); // test a UART transmission when the task starts and the UART is ready
FOREVER_LOOP() {
xSemaphoreTake(xSemaphore, portMAX_DELAY); // take semaphore/wait for semaphore to become free (idle line detection)
length = fnRead(uart_handle, dataBuffer, sizeof(dataBuffer)); // read waiting data from the DMA input buffer (returns immediately)
if (length != 0) { // if something is available
fnDebugMsg("FreeRTOS Echo:"); // echo it back
fnWrite(uart_handle, dataBuffer, length); // send the reception back
fnDebugMsg("\r\n"); // with termination
}
}
}
Regards
Mark
[uTasker project developer for Kinetis and i.MX RT]
Contact me by personal message or on the uTasker web site to discuss professional training, solutions to problems or product development requirements