The need for RTOS Drivers

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

The need for RTOS Drivers

1,415 Views
PedroCastro
Contributor III

Hello everybody,

I am working on examples from the kinetis SDK 2.0 for the processor KV31F specifically the UART driver at the moment. Looking at the examples and the API, there are three drivers I could use: the UART Driver, the one using DMA and finally the UART FreeRTOS Driver. Since I would like to use the freeRTOS I was wondering why is there a need for an specific driver just to use with an RTOS. Why couldn't I just call the regular UART API inside an RTOS Task? Besides, is it possible or advisible to use the DMA Driver with the FreeRTOS?
I know my question is more theoretical than usual, but still I think it is a good point for discussion!

Thanks in advance

Labels (1)
0 Kudos
1 Reply

679 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Pedro,

Regarding your question, I think there are several  examples for the uart:

1)Polling_transfer: the example uses polling mode to read/write the uart data register, in other words, it polls the uart status register to check if the transmit register is empty or the receiver register is full.

2)interrupt example: it uses interrupt mechanism to write/read uart data register, in detail, in the ISR of uart transmitter, it write data register.

2)interrupt_transfer example: Firstly, it uses interrupt mechanism to write/read uart data registers, but it defines a structure

    uart_transfer_t sendXfer;
    uart_transfer_t receiveXfer;

when the block of data has been transfered completely, a callback function is called.

3)the interrupt_ring_buffer_transfer uses ring buffer, the other is the same as interrupt_transfer example, the edma_interrupt uses edma to transfer data.

4)there is an example located at:C:\DriverE\Freescale\SDK2.0_K22FProcessor\boards\twrk21f120m\rtos_examples\freertos_uart

The example is based on interrupt_transfer example, it create a task, in the task, the code is blocked at

    if (0 > UART_RTOS_Send(&handle, (uint8_t *)to_send, strlen(to_send)))
    {
        PRINTF("Error during UART send.\r\n");
        vTaskSuspend(NULL);
    }

especially the line ev = xEventGroupWaitBits(handle->tx_event, RTOS_UART_COMPLETE, pdTRUE, pdFALSE, portMAX_DELAY);

when the block of data has been tranfered and the callback is called, the callback function will post the handle->tx_event, following code is running.

Hope it can help you

BR

Xiangjun Rong

int UART_RTOS_Send(uart_rtos_handle_t *handle, const uint8_t *buffer, uint32_t length)
{
    EventBits_t ev;
    int retval = kStatus_Success;

    if (NULL == handle->base)
    {
        /* Invalid handle. */
        return kStatus_Fail;
    }
    if (0 == length)
    {
        return 0;
    }
    if (NULL == buffer)
    {
        return kStatus_InvalidArgument;
    }

    if (pdFALSE == xSemaphoreTake(handle->tx_sem, 0))
    {
        /* We could not take the semaphore, exit with 0 data received */
        return kStatus_Fail;
    }

    handle->tx_xfer.data = (uint8_t *)buffer;
    handle->tx_xfer.dataSize = (uint32_t)length;

    xEventGroupClearBits(handle->tx_event, RTOS_UART_COMPLETE);

    /* Non-blocking call */
    UART_TransferSendNonBlocking(handle->base, handle->t_state, &handle->tx_xfer);

    ev = xEventGroupWaitBits(handle->tx_event, RTOS_UART_COMPLETE, pdTRUE, pdFALSE, portMAX_DELAY);
    if (!(ev & RTOS_UART_COMPLETE))
    {
        retval = kStatus_Fail;
    }

    if (pdFALSE == xSemaphoreGive(handle->tx_sem))
    {
        /* We could not post the semaphore, exit with error */
        retval = kStatus_Fail;
    }

    return retval;
}

callback function,

C:\DriverE\Freescale\SDK2.0_K22FProcessor\boards\twrk21f120m\driver_examples\uart

pastedImage_1.png

0 Kudos