AnsweredAssumed Answered

Error in FreeRTOS UART Example Application?

Question asked by Myke Predko on Mar 26, 2020
Latest reply on Mar 30, 2020 by Daniel Chen

I'm following the TWRK21F "freertos_uart" example application and I just noticed that in the code, the setup/initial transmit APIs are written as:

 

if (0 > UART_RTOS_Init(&handle, &t_handle, &uart_config))
{
vTaskSuspend(NULL);
}

/* Send introduction message. */
if (0 > UART_RTOS_Send(&handle, (uint8_t *)to_send, strlen(to_send)))
{
vTaskSuspend(NULL);
}

In this code, the "vTaskSuspend(NULL); statements will only execute IFF the return value is less than zero (ie negative).  

 

When I look at the source code (in fsl_uart_freertos.c), the return values are defined (in fsl_common.h) as:

enum _generic_status
{
kStatus_Success = MAKE_STATUS(kStatusGroup_Generic, 0),
kStatus_Fail = MAKE_STATUS(kStatusGroup_Generic, 1),
kStatus_ReadOnly = MAKE_STATUS(kStatusGroup_Generic, 2),
kStatus_OutOfRange = MAKE_STATUS(kStatusGroup_Generic, 3),
kStatus_InvalidArgument = MAKE_STATUS(kStatusGroup_Generic, 4),
kStatus_Timeout = MAKE_STATUS(kStatusGroup_Generic, 5),
kStatus_NoTransferInProgress = MAKE_STATUS(kStatusGroup_Generic, 6),
};

As the return values will never be less than zero, won't the return tests for the APIs never become active? 

 

Shouldn't the first block of code be something like one of the two checks below?

 

if (0 != UART_RTOS_Init(&handle, &t_handle, &uart_config))  //  Not Equal to Zero
{
vTaskSuspend(NULL);
}

/* Send introduction message. */
if (UART_RTOS_Send(&handle, (uint8_t *)to_send, strlen(to_send)))  //  More Efficient way of detecting != Zero
{
vTaskSuspend(NULL);
}

Outcomes