Hi all… Today we are going to see FreeRTOS LPC2148 Tutorial – Task Creation.
Suggest To Read
FreeRTOS LPC2148 Tutorial – Task Creation
FreeRTOS contains many API. But the very basic is Creating a Task. Because tasks are concurrently running when system boots up. So today we will look at simple task creation.
This FreeRTOS API is used to create a task. Using this API we can create more number of tasks.
portBASE_TYPE xTaskCreate ( pdTASK_CODE pvTaskCode,
const signed portCHAR * const pcName,
unsigned portSHORT usStackDepth,
unsigned portBASE_TYPE uxPriority,
xTaskHandle *pxCreatedTask );
- pvTaskCode: a pointer to the function where the task is implemented. (Address of the fuction)
- pcName: given name to the task. This is useless to FreeRTOS but is intented to debugging purpose only.
- usStackDepth: length of the stack for this task in words. The actual size of the stack depends on the micro controller.
- pvParameters: a pointer to arguments given to the task.
- uxPriority: priority given to the task, a number between 0 and MAX_PRIORITIES – 1.
- pxCreatedTask: a pointer to an identifier that allows to handle the task. If the task does not have to be handled in the future, this can be leaved NULL.
We are using this API for delay purpose.
void vTaskDelay( TickType_t xTicksToDelay );
- xTicksToDelay : The number of tick interrupts that the calling task will remain in the Blocked state before being transitioned back into the Ready state. For example, if a task called vTaskDelay( 100 ) when the tick count was 10,000, then it would immediately enter the Blocked state and remain in the Blocked state until the tick count reached 10,100. Any time that remains between vTaskDelay() being called, and the next tick interrupt occurring, counts as one complete tick period. Therefore, the highest time resolution that can be achieved when specifying a delay period is, in the worst case, equal to one complete tick interrupt period. The macro pdMS_TO_TICKS() can be used to convert milliseconds into ticks.
Starts the FreeRTOS scheduler running.
Typically, before the scheduler has been started, main() (or a function called by main()) will be executing. After the scheduler has been started, only tasks and interrupts will ever execute.
Starting the scheduler causes the highest priority task that was created while the scheduler
was in the Initialization state to enter the Running state.
void vTaskStartScheduler( void );
In this code i’m creating two tasks.
- Task 1
- Task 2
Task 1 prints “Task1 functioning” in serial port. Task 2 prints “Task2 functioning” in serial port. Let’s go through the code. Here i’m adding only the main file. If you want to download the full project, please visit here (GitHub).
void task1(void *q);
void task2(void *a);
void task1(void *q)
void task2(void *a)