This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/CC2640: BLE enabled RTOS task

Part Number: CC2640


Tool/software: TI-RTOS

CC2640 4x4 custom board, ble_sdk_2_02_01_18, CCS 6.2, XDS200 debugger

A uart task has been added to the application to replace using the uart driver in

read callback mode. This was a solution to a hard fault bus error. The uart_task

priority is 2 and the SBP task priority is 1. Currently, when the uart task is finished,

it posts a semaphore to the SBP task.

The uart task uses the osal_snv read and write APIs. I understand this requires

the uart task to be a BLE enabled RTOS task.

In reading this wiki, I have the questions pasted below. Please alert me if any of

my above assumptions are incorrect.

1. The RTOS task (notification task) described in this wiki is the same as

the UART_task in my application, correct?

2. I add the code from page 2 of this wiki to the main_loop of the uart Task?

3. When do I post the NOTIFY_TASK (uart_TASK) SELECT EVENT? I don't

have an Hwi event in the uart task. I do know when there is a need to read or

write to the snv from the uart_task.

4. Lastly I set these predefined symbols as follows:

OSAL_MAX_NUM_PROXY_TASKS=3 (SBP task, GAPRoleTask, Uart task).

ICALL_MAX_NUM_TASKS=4 (stack task, SBP task, uart task and GAP role task).

Thanks,

Priya

Thanks,

Priya

  • Hi Priya,

    If your task isn't using any interrupts, you'll have to poll (probably something like Task_sleep() and check the UART peripheral's status register) the UART (not exactly power efficient).
  •  Tom,

    I tried setting the uart driver in readcallback mode and using the swi to generate

    a NOTIFY_TASK_SELECT_EVT.

    BLE advertises but the uart never gets read. Is there a way to make this solution

    feasible?

    static void NotificationTask_init(void)

    {

      // ******************************************************************

      // N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp

      // ******************************************************************

      // Register the current thread as an ICall dispatcher application

      // so that the application can send and receive messages.

      ICall_registerApp(&selfEntity, &sem);

         UART_initialize();

    }

    /*********************************************************************

    188  * @fn      NotificationTask_taskFxn

    189  *

    190  * @brief   Application task entry point for the Notification Task.

    191  *

    192  * @param   a0, a1 - not used.

    193  *

    194  * @return  None.

    195  */

    static void NotificationTask_taskFxn(UArg a0, UArg a1)

    {

    // Initialize application

    NotificationTask_init();

    // Application main loop

    for (;;)

    {

    uint8_t byte;

       // Waits for a signal to the semaphore associated with the calling thread.

       // Note that the semaphore associated with a thread is signaled when a

       // message is queued to the message receive queue of the thread or when

       // ICall_signal() function is called onto the semaphore.

       ICall_Errno errno = ICall_wait(ICALL_TIMEOUT_FOREVER);

    if (uartTx == 0){

    if ( UART_read(uart, &byte, 1) == UART_ERROR) {

               System_printf("UART_read() timeout");

    }

       }

       if (events & NOTIFY_TASK_SELECT_EVT)

       {

           receiveUartMsg(byte);

        //Set up notificaiton data

        uint16 len = sizeof(UInt32);

    attHandleValueNoti_t noti;

    bStatus_t status;

    noti.handle = 0x1E;

    noti.len = len;

    //attempt to allocate payload

    noti.pValue = (uint8 *)GATT_bm_alloc( 0, ATT_HANDLE_VALUE_NOTI, GATT_MAX_MTU, &len );

    if ( noti.pValue != NULL ) //if allocated

    {

     //place index

     noti.pValue[0] = (dataToNotify >> 24) & 0xFF;

     noti.pValue[1] = (dataToNotify >> 16) & 0xFF;

     noti.pValue[2] = (dataToNotify >> 8) & 0xFF;

     noti.pValue[3] = dataToNotify & 0xFF;

     status = GATT_Notification( 0, &noti, 0 );    //attempt to send

     if ( status != SUCCESS ) //if noti not sent

     {

    GATT_bm_free( (gattMsg_t *)&noti, ATT_HANDLE_VALUE_NOTI );

     }

    }

    else

    {

     //bleNoResources

     asm(" NOP");

    }

    //Clear the event

        events &= ~NOTIFY_TASK_SELECT_EVT;

       }

    }

     }

    static void UART_initialize(void)

    {

        UART_Params uartParams;

        UART_init();

        /* Create a UART with data processing off. */

        UART_Params_init(&uartParams);

        uartParams.writeDataMode = UART_DATA_BINARY;

        uartParams.readDataMode = UART_DATA_BINARY;

        uartParams.readReturnMode = UART_RETURN_FULL;

        uartParams.readMode = UART_MODE_CALLBACK;

        uartParams.writeMode = UART_MODE_BLOCKING;

        uartParams.readCallback = UARTCallback;

        uartParams.baudRate = 9600;

        uart = UART_open(Board_UART, &uartParams);

        if (uart == NULL) {

            System_abort("Error opening the UART");

        }

        uartTx = 0;

    }

    static void UARTCallback(UART_Handle uart, void *byte, size_t size)

    {

        events |= NOTIFY_TASK_SELECT_EVT;

        Semaphore_post(sem);

    }

  • How can I confirm the app is getting past ICall_Errno errno = ICall_wait(ICALL_TIMEOUT_FOREVER);
    inside the notificationTask?

    sem2errNo = ICall_registerApp(&selfEntity2, &sem2); was a successful call.

    What is the syntax to check the UART peripheral's status register?

    Thanks,
    Priya
  • The uart task is finally BLE enabled. The uart task was changed to read continuously

    on the read callback. There is actually some pretty clear info on 4.2.5 ICall Thread

    Synchronization of the SDG. ICall is accepting the semaphore posted on the swi.

    Thanks,

    Priya