When used for mutual exclusion the mutex acts like a token that is used to guard a resource. Mutexes use the same semaphore access API functions so also permit a block time to be specified. Unlike binary semaphores however — mutexes employ priority inheritance. This means that if a high priority task blocks while attempting to obtain a mutex token that is currently held by a lower priority task, then the priority of the task holding the token is temporarily raised to that of the blocking task. Priority inheritance does not cure priority inversion! It just minimises its effect in some situations.
|Genre:||Health and Food|
|Published (Last):||4 December 2006|
|PDF File Size:||4.78 Mb|
|ePub File Size:||10.58 Mb|
|Price:||Free* [*Free Regsitration Required]|
Return pdPASS if the task was successfully created and added to a ready list, otherwise an error code defined in the file projdefs. Tasks must be implemented to never return i. This is mainly used to facilitate debugging.
Values 0 or 1 indicate the index number of the CPU which the task should be pinned to. The second block is used by the task as its stack. If a task is created using xTaskCreate then both blocks of memory are automatically dynamically allocated inside the xTaskCreate function. If a task is created using xTaskCreateStatic then the application writer must provide the required memory. See xTaskCreateStatic for a version that does not use any dynamic memory allocation.
Parameters pvTaskCode: Pointer to the task entry function. The task being deleted will be removed from all ready, blocked, suspended and event lists. See the configuration section for more information. See the demo application file death. Note The idle task is responsible for freeing the kernel allocated memory from tasks that have been deleted.
It is therefore important that the idle task is not starved of microcontroller processing time if your application makes any calls to vTaskDelete. Memory allocated by the task code is not automatically freed, and should be freed before the task is deleted. Passing NULL will cause the calling task to be deleted.
The actual time that the task remains blocked depends on the tick rate. For example, specifying a block period of ticks will cause the task to unblock ticks after vTaskDelay is called.
It does this by specifying an absolute time rather than a relative time at which the calling task should unblock. This function can be used by periodic tasks to ensure a constant execution frequency. This function differs from vTaskDelay in one important aspect: vTaskDelay will cause a task to block for the specified number of ticks from the time vTaskDelay is called. It is therefore difficult to use vTaskDelay by itself to generate a fixed execution frequency as the time between a task starting to execute and that task calling vTaskDelay may not be fixed [the task may take a different path though the code between calls, or may get interrupted or preempted a different number of times each time it executes].
Whereas vTaskDelay specifies a wake time relative to the time at which the function is called, vTaskDelayUntil specifies the absolute exact time at which it wishes to unblock. The variable must be initialised with the current time prior to its first use see the example below. Following this the variable is automatically updated within vTaskDelayUntil. Calling vTaskDelayUntil with the same xTimeIncrement parameter value will cause the task to execute with a fixed interface period. Parameters xTask: Handle of the task to be queried.
Passing a NULL handle results in the priority of the calling task being returned. Return The priority of xTask. Obtain the state of any task. States are encoded by the eTaskState enumerated type. Return The state of xTask at the time the function was called.
Note the state of the task might change between the function being called, and the functions return value being tested by the calling task. A context switch will occur before the function returns if the priority being set is higher than the currently executing task. Passing a NULL handle results in the priority of the calling task being set. When suspended, a task will never get any microcontroller processing time, no matter what its priority.
Calls to vTaskSuspend are not accumulative - i. Passing a NULL handle will cause the calling task to be suspended. A task that has been suspended by one or more calls to vTaskSuspend will be made available for running again by a single call to vTaskResume.
Use of a semaphore as a synchronisation mechanism would avoid this eventuality. Parameters xTaskToResume: Handle to the task being readied. Context switches will not occur while the scheduler is suspended. After calling vTaskSuspendAll the calling task will continue to execute without risk of being swapped out until a call to xTaskResumeAll has been made. Restart the kernel.
It does not unsuspend tasks that were previously suspended by a call to vTaskSuspend.
How to use mutex and semaphores in a FreeRTOS and SDK2.0 Project
Implementing std::mutex with FreeRTOS
Subscribe to RSS