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.

CC2340R5: Want a base code for RTOS Task Creation.

Part Number: CC2340R5

Tool/software:

Hi Forum,

I want to implement a scanning of TPMS as, UART communication as a separate RTOS task. Also, in future i may want to have task for specific GATT profile data exchange. So, Do you have any code base for task creation?

Also, if you could suggest steps or documentation for it, would be a better.

Regards

Vaibhav

  • Hi !

    You can follow the chapter of our User Guide about how to create a FreeRTOS task.

    The sample code looks like this

    #include <FreeRTOS.h>
    
    #include <task.h>
    
    #include <stdarg.h>
    
    
    #define TASK_PRIORITY 1
    
    #define TASK_STACK_SIZE 2048 /* bytes */
    
    
    TaskHandle_t taskHandle = NULL;
    
    
    /* Task function */
    
    void taskFunction(void* a0)
    
    {
    
        /* Local variables. Variables here go onto task stack!! */
    
    
        /* Run one-time code when task starts */
    
    
        while (1) /* Run loop forever (unless terminated) */
    
        {
    
            /*
    
             * Block on a signal or for a duration. Examples:
    
             *  ``xSemaphoreTake()``
    
             *  ``xQueueReceive``
    
             *  ``vTaskDelay()``
    
             *
    
             * "Process data"
    
             */
    
        }
    
    
        /* Tasks must not attempt to return from their implementing
    
        function or otherwise exit. If it is necessary for a task to
    
        exit then have the task call vTaskDelete( NULL ) to ensure
    
        its exit is clean. */
    
        vTaskDelete( NULL );
    
    }
    
    
    int main() {
    
    
        BaseType_t xReturned;
    
    
        /* Create the task, storing the handle. */
    
        xReturned = xTaskCreate(
    
                taskFxn,                                /* Function that implements the task. */
    
                "MY_NEW_TASK",                          /* Text name for the task. */
    
                TASK_STACK_SIZE / sizeof(uint32_t),     /* Stack size in words, not bytes. */
    
                ( void * ) 1,                           /* Parameter passed into the task. */
    
                TASK_PRIORITY,                          /* Priority at which the task is created. */
    
                &taskHandle );                                /* Used to pass out the created task's handle. */
    
    
        if(xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY)
    
        {
    
            /* Creation of FreeRTOS task failed */
    
            while(1);
    
        }
    
    
        /* Start the FreeRTOS scheduler */
    
                vTaskStartScheduler();
    
    
    }

    Kind regards,
    Lea