2 FreeRTOS.org V5.0.3 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
\r
30 * and even write all or part of your application on your behalf. *
\r
31 * See http://www.OpenRTOS.com for details of the services we provide to *
\r
32 * expedite your project. *
\r
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\r
51 #ifndef INC_FREERTOS_H
\r
52 #error "#include FreeRTOS.h" must appear in source files before "#include task.h"
\r
60 #include "portable.h"
\r
66 /*-----------------------------------------------------------
\r
67 * MACROS AND DEFINITIONS
\r
68 *----------------------------------------------------------*/
\r
70 #define tskKERNEL_VERSION_NUMBER "V5.0.3"
\r
75 * Type by which tasks are referenced. For example, a call to xTaskCreate
\r
76 * returns (via a pointer parameter) an xTaskHandle variable that can then
\r
77 * be used as a parameter to vTaskDelete to delete the task.
\r
79 * \page xTaskHandle xTaskHandle
\r
82 typedef void * xTaskHandle;
\r
85 * Used internally only.
\r
87 typedef struct xTIME_OUT
\r
89 portBASE_TYPE xOverflowCount;
\r
90 portTickType xTimeOnEntering;
\r
94 * Defines the priority used by the idle task. This must not be modified.
\r
96 * \ingroup TaskUtils
\r
98 #define tskIDLE_PRIORITY ( ( unsigned portBASE_TYPE ) 0 )
\r
103 * Macro for forcing a context switch.
\r
105 * \page taskYIELD taskYIELD
\r
106 * \ingroup SchedulerControl
\r
108 #define taskYIELD() portYIELD()
\r
113 * Macro to mark the start of a critical code region. Preemptive context
\r
114 * switches cannot occur when in a critical region.
\r
116 * NOTE: This may alter the stack (depending on the portable implementation)
\r
117 * so must be used with care!
\r
119 * \page taskENTER_CRITICAL taskENTER_CRITICAL
\r
120 * \ingroup SchedulerControl
\r
122 #define taskENTER_CRITICAL() portENTER_CRITICAL()
\r
127 * Macro to mark the end of a critical code region. Preemptive context
\r
128 * switches cannot occur when in a critical region.
\r
130 * NOTE: This may alter the stack (depending on the portable implementation)
\r
131 * so must be used with care!
\r
133 * \page taskEXIT_CRITICAL taskEXIT_CRITICAL
\r
134 * \ingroup SchedulerControl
\r
136 #define taskEXIT_CRITICAL() portEXIT_CRITICAL()
\r
141 * Macro to disable all maskable interrupts.
\r
143 * \page taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
\r
144 * \ingroup SchedulerControl
\r
146 #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
\r
151 * Macro to enable microcontroller interrupts.
\r
153 * \page taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
\r
154 * \ingroup SchedulerControl
\r
156 #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
\r
158 /* Definitions returned by xTaskGetSchedulerState(). */
\r
159 #define taskSCHEDULER_NOT_STARTED 0
\r
160 #define taskSCHEDULER_RUNNING 1
\r
161 #define taskSCHEDULER_SUSPENDED 2
\r
163 /*-----------------------------------------------------------
\r
164 * TASK CREATION API
\r
165 *----------------------------------------------------------*/
\r
170 portBASE_TYPE xTaskCreate(
\r
171 pdTASK_CODE pvTaskCode,
\r
172 const portCHAR * const pcName,
\r
173 unsigned portSHORT usStackDepth,
\r
174 void *pvParameters,
\r
175 unsigned portBASE_TYPE uxPriority,
\r
176 xTaskHandle *pvCreatedTask
\r
179 * Create a new task and add it to the list of tasks that are ready to run.
\r
181 * @param pvTaskCode Pointer to the task entry function. Tasks
\r
182 * must be implemented to never return (i.e. continuous loop).
\r
184 * @param pcName A descriptive name for the task. This is mainly used to
\r
185 * facilitate debugging. Max length defined by tskMAX_TASK_NAME_LEN - default
\r
188 * @param usStackDepth The size of the task stack specified as the number of
\r
189 * variables the stack can hold - not the number of bytes. For example, if
\r
190 * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
\r
191 * will be allocated for stack storage.
\r
193 * @param pvParameters Pointer that will be used as the parameter for the task
\r
196 * @param uxPriority The priority at which the task should run.
\r
198 * @param pvCreatedTask Used to pass back a handle by which the created task
\r
199 * can be referenced.
\r
201 * @return pdPASS if the task was successfully created and added to a ready
\r
202 * list, otherwise an error code defined in the file errors. h
\r
206 // Task to be created.
\r
207 void vTaskCode( void * pvParameters )
\r
211 // Task code goes here.
\r
215 // Function that creates a task.
\r
216 void vOtherFunction( void )
\r
218 static unsigned char ucParameterToPass;
\r
219 xTaskHandle xHandle;
\r
221 // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
\r
222 // must exist for the lifetime of the task, so in this case is declared static. If it was just an
\r
223 // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
\r
224 // the new time attempts to access it.
\r
225 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
\r
227 // Use the handle to delete the task.
\r
228 vTaskDelete( xHandle );
\r
231 * \defgroup xTaskCreate xTaskCreate
\r
234 signed portBASE_TYPE xTaskCreate( pdTASK_CODE pvTaskCode, const signed portCHAR * const pcName, unsigned portSHORT usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pvCreatedTask );
\r
238 * <pre>void vTaskDelete( xTaskHandle pxTask );</pre>
\r
240 * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
\r
241 * See the configuration section for more information.
\r
243 * Remove a task from the RTOS real time kernels management. The task being
\r
244 * deleted will be removed from all ready, blocked, suspended and event lists.
\r
246 * NOTE: The idle task is responsible for freeing the kernel allocated
\r
247 * memory from tasks that have been deleted. It is therefore important that
\r
248 * the idle task is not starved of microcontroller processing time if your
\r
249 * application makes any calls to vTaskDelete (). Memory allocated by the
\r
250 * task code is not automatically freed, and should be freed before the task
\r
253 * See the demo application file death.c for sample code that utilises
\r
256 * @param pxTask The handle of the task to be deleted. Passing NULL will
\r
257 * cause the calling task to be deleted.
\r
261 void vOtherFunction( void )
\r
263 xTaskHandle xHandle;
\r
265 // Create the task, storing the handle.
\r
266 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
268 // Use the handle to delete the task.
\r
269 vTaskDelete( xHandle );
\r
272 * \defgroup vTaskDelete vTaskDelete
\r
275 void vTaskDelete( xTaskHandle pxTask );
\r
278 /*-----------------------------------------------------------
\r
280 *----------------------------------------------------------*/
\r
284 * <pre>void vTaskDelay( portTickType xTicksToDelay );</pre>
\r
286 * Delay a task for a given number of ticks. The actual time that the
\r
287 * task remains blocked depends on the tick rate. The constant
\r
288 * portTICK_RATE_MS can be used to calculate real time from the tick
\r
289 * rate - with the resolution of one tick period.
\r
291 * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
\r
292 * See the configuration section for more information.
\r
295 * vTaskDelay() specifies a time at which the task wishes to unblock relative to
\r
296 * the time at which vTaskDelay() is called. For example, specifying a block
\r
297 * period of 100 ticks will cause the task to unblock 100 ticks after
\r
298 * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
\r
299 * of controlling the frequency of a cyclical task as the path taken through the
\r
300 * code, as well as other task and interrupt activity, will effect the frequency
\r
301 * at which vTaskDelay() gets called and therefore the time at which the task
\r
302 * next executes. See vTaskDelayUntil() for an alternative API function designed
\r
303 * to facilitate fixed frequency execution. It does this by specifying an
\r
304 * absolute time (rather than a relative time) at which the calling task should
\r
307 * @param xTicksToDelay The amount of time, in tick periods, that
\r
308 * the calling task should block.
\r
312 void vTaskFunction( void * pvParameters )
\r
314 void vTaskFunction( void * pvParameters )
\r
316 // Block for 500ms.
\r
317 const portTickType xDelay = 500 / portTICK_RATE_MS;
\r
321 // Simply toggle the LED every 500ms, blocking between each toggle.
\r
323 vTaskDelay( xDelay );
\r
327 * \defgroup vTaskDelay vTaskDelay
\r
328 * \ingroup TaskCtrl
\r
330 void vTaskDelay( portTickType xTicksToDelay );
\r
334 * <pre>void vTaskDelayUntil( portTickType *pxPreviousWakeTime, portTickType xTimeIncrement );</pre>
\r
336 * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
\r
337 * See the configuration section for more information.
\r
339 * Delay a task until a specified time. This function can be used by cyclical
\r
340 * tasks to ensure a constant execution frequency.
\r
342 * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
\r
343 * cause a task to block for the specified number of ticks from the time vTaskDelay () is
\r
344 * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
\r
345 * execution frequency as the time between a task starting to execute and that task
\r
346 * calling vTaskDelay () may not be fixed [the task may take a different path though the
\r
347 * code between calls, or may get interrupted or preempted a different number of times
\r
348 * each time it executes].
\r
350 * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
\r
351 * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
\r
354 * The constant portTICK_RATE_MS can be used to calculate real time from the tick
\r
355 * rate - with the resolution of one tick period.
\r
357 * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
\r
358 * task was last unblocked. The variable must be initialised with the current time
\r
359 * prior to its first use (see the example below). Following this the variable is
\r
360 * automatically updated within vTaskDelayUntil ().
\r
362 * @param xTimeIncrement The cycle time period. The task will be unblocked at
\r
363 * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the
\r
364 * same xTimeIncrement parameter value will cause the task to execute with
\r
365 * a fixed interface period.
\r
369 // Perform an action every 10 ticks.
\r
370 void vTaskFunction( void * pvParameters )
\r
372 portTickType xLastWakeTime;
\r
373 const portTickType xFrequency = 10;
\r
375 // Initialise the xLastWakeTime variable with the current time.
\r
376 xLastWakeTime = xTaskGetTickCount ();
\r
379 // Wait for the next cycle.
\r
380 vTaskDelayUntil( &xLastWakeTime, xFrequency );
\r
382 // Perform action here.
\r
386 * \defgroup vTaskDelayUntil vTaskDelayUntil
\r
387 * \ingroup TaskCtrl
\r
389 void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement );
\r
393 * <pre>unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );</pre>
\r
395 * INCLUDE_xTaskPriorityGet must be defined as 1 for this function to be available.
\r
396 * See the configuration section for more information.
\r
398 * Obtain the priority of any task.
\r
400 * @param pxTask Handle of the task to be queried. Passing a NULL
\r
401 * handle results in the priority of the calling task being returned.
\r
403 * @return The priority of pxTask.
\r
407 void vAFunction( void )
\r
409 xTaskHandle xHandle;
\r
411 // Create a task, storing the handle.
\r
412 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
416 // Use the handle to obtain the priority of the created task.
\r
417 // It was created with tskIDLE_PRIORITY, but may have changed
\r
419 if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
\r
421 // The task has changed it's priority.
\r
426 // Is our priority higher than the created task?
\r
427 if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
\r
429 // Our priority (obtained using NULL handle) is higher.
\r
433 * \defgroup uxTaskPriorityGet uxTaskPriorityGet
\r
434 * \ingroup TaskCtrl
\r
436 unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );
\r
440 * <pre>void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );</pre>
\r
442 * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
\r
443 * See the configuration section for more information.
\r
445 * Set the priority of any task.
\r
447 * A context switch will occur before the function returns if the priority
\r
448 * being set is higher than the currently executing task.
\r
450 * @param pxTask Handle to the task for which the priority is being set.
\r
451 * Passing a NULL handle results in the priority of the calling task being set.
\r
453 * @param uxNewPriority The priority to which the task will be set.
\r
457 void vAFunction( void )
\r
459 xTaskHandle xHandle;
\r
461 // Create a task, storing the handle.
\r
462 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
466 // Use the handle to raise the priority of the created task.
\r
467 vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
\r
471 // Use a NULL handle to raise our priority to the same value.
\r
472 vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
\r
475 * \defgroup vTaskPrioritySet vTaskPrioritySet
\r
476 * \ingroup TaskCtrl
\r
478 void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );
\r
482 * <pre>void vTaskSuspend( xTaskHandle pxTaskToSuspend );</pre>
\r
484 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
\r
485 * See the configuration section for more information.
\r
487 * Suspend any task. When suspended a task will never get any microcontroller
\r
488 * processing time, no matter what its priority.
\r
490 * Calls to vTaskSuspend are not accumulative -
\r
491 * i.e. calling vTaskSuspend () twice on the same task still only requires one
\r
492 * call to vTaskResume () to ready the suspended task.
\r
494 * @param pxTaskToSuspend Handle to the task being suspended. Passing a NULL
\r
495 * handle will cause the calling task to be suspended.
\r
499 void vAFunction( void )
\r
501 xTaskHandle xHandle;
\r
503 // Create a task, storing the handle.
\r
504 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
508 // Use the handle to suspend the created task.
\r
509 vTaskSuspend( xHandle );
\r
513 // The created task will not run during this period, unless
\r
514 // another task calls vTaskResume( xHandle ).
\r
519 // Suspend ourselves.
\r
520 vTaskSuspend( NULL );
\r
522 // We cannot get here unless another task calls vTaskResume
\r
523 // with our handle as the parameter.
\r
526 * \defgroup vTaskSuspend vTaskSuspend
\r
527 * \ingroup TaskCtrl
\r
529 void vTaskSuspend( xTaskHandle pxTaskToSuspend );
\r
533 * <pre>void vTaskResume( xTaskHandle pxTaskToResume );</pre>
\r
535 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
\r
536 * See the configuration section for more information.
\r
538 * Resumes a suspended task.
\r
540 * A task that has been suspended by one of more calls to vTaskSuspend ()
\r
541 * will be made available for running again by a single call to
\r
544 * @param pxTaskToResume Handle to the task being readied.
\r
548 void vAFunction( void )
\r
550 xTaskHandle xHandle;
\r
552 // Create a task, storing the handle.
\r
553 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
557 // Use the handle to suspend the created task.
\r
558 vTaskSuspend( xHandle );
\r
562 // The created task will not run during this period, unless
\r
563 // another task calls vTaskResume( xHandle ).
\r
568 // Resume the suspended task ourselves.
\r
569 vTaskResume( xHandle );
\r
571 // The created task will once again get microcontroller processing
\r
572 // time in accordance with it priority within the system.
\r
575 * \defgroup vTaskResume vTaskResume
\r
576 * \ingroup TaskCtrl
\r
578 void vTaskResume( xTaskHandle pxTaskToResume );
\r
582 * <pre>void xTaskResumeFromISR( xTaskHandle pxTaskToResume );</pre>
\r
584 * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
\r
585 * available. See the configuration section for more information.
\r
587 * An implementation of vTaskResume() that can be called from within an ISR.
\r
589 * A task that has been suspended by one of more calls to vTaskSuspend ()
\r
590 * will be made available for running again by a single call to
\r
591 * xTaskResumeFromISR ().
\r
593 * @param pxTaskToResume Handle to the task being readied.
\r
595 * \defgroup vTaskResumeFromISR vTaskResumeFromISR
\r
596 * \ingroup TaskCtrl
\r
598 portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume );
\r
600 /*-----------------------------------------------------------
\r
601 * SCHEDULER CONTROL
\r
602 *----------------------------------------------------------*/
\r
606 * <pre>void vTaskStartScheduler( void );</pre>
\r
608 * Starts the real time kernel tick processing. After calling the kernel
\r
609 * has control over which tasks are executed and when. This function
\r
610 * does not return until an executing task calls vTaskEndScheduler ().
\r
612 * At least one task should be created via a call to xTaskCreate ()
\r
613 * before calling vTaskStartScheduler (). The idle task is created
\r
614 * automatically when the first application task is created.
\r
616 * See the demo application file main.c for an example of creating
\r
617 * tasks and starting the kernel.
\r
621 void vAFunction( void )
\r
623 // Create at least one task before starting the kernel.
\r
624 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
626 // Start the real time kernel with preemption.
\r
627 vTaskStartScheduler ();
\r
629 // Will not get here unless a task calls vTaskEndScheduler ()
\r
633 * \defgroup vTaskStartScheduler vTaskStartScheduler
\r
634 * \ingroup SchedulerControl
\r
636 void vTaskStartScheduler( void );
\r
640 * <pre>void vTaskEndScheduler( void );</pre>
\r
642 * Stops the real time kernel tick. All created tasks will be automatically
\r
643 * deleted and multitasking (either preemptive or cooperative) will
\r
644 * stop. Execution then resumes from the point where vTaskStartScheduler ()
\r
645 * was called, as if vTaskStartScheduler () had just returned.
\r
647 * See the demo application file main. c in the demo/PC directory for an
\r
648 * example that uses vTaskEndScheduler ().
\r
650 * vTaskEndScheduler () requires an exit function to be defined within the
\r
651 * portable layer (see vPortEndScheduler () in port. c for the PC port). This
\r
652 * performs hardware specific operations such as stopping the kernel tick.
\r
654 * vTaskEndScheduler () will cause all of the resources allocated by the
\r
655 * kernel to be freed - but will not free resources allocated by application
\r
660 void vTaskCode( void * pvParameters )
\r
664 // Task code goes here.
\r
666 // At some point we want to end the real time kernel processing
\r
668 vTaskEndScheduler ();
\r
672 void vAFunction( void )
\r
674 // Create at least one task before starting the kernel.
\r
675 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
677 // Start the real time kernel with preemption.
\r
678 vTaskStartScheduler ();
\r
680 // Will only get here when the vTaskCode () task has called
\r
681 // vTaskEndScheduler (). When we get here we are back to single task
\r
686 * \defgroup vTaskEndScheduler vTaskEndScheduler
\r
687 * \ingroup SchedulerControl
\r
689 void vTaskEndScheduler( void );
\r
693 * <pre>void vTaskSuspendAll( void );</pre>
\r
695 * Suspends all real time kernel activity while keeping interrupts (including the
\r
696 * kernel tick) enabled.
\r
698 * After calling vTaskSuspendAll () the calling task will continue to execute
\r
699 * without risk of being swapped out until a call to xTaskResumeAll () has been
\r
702 * API functions that have the potential to cause a context switch (for example,
\r
703 * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
\r
708 void vTask1( void * pvParameters )
\r
712 // Task code goes here.
\r
716 // At some point the task wants to perform a long operation during
\r
717 // which it does not want to get swapped out. It cannot use
\r
718 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
\r
719 // operation may cause interrupts to be missed - including the
\r
722 // Prevent the real time kernel swapping out the task.
\r
723 vTaskSuspendAll ();
\r
725 // Perform the operation here. There is no need to use critical
\r
726 // sections as we have all the microcontroller processing time.
\r
727 // During this time interrupts will still operate and the kernel
\r
728 // tick count will be maintained.
\r
732 // The operation is complete. Restart the kernel.
\r
737 * \defgroup vTaskSuspendAll vTaskSuspendAll
\r
738 * \ingroup SchedulerControl
\r
740 void vTaskSuspendAll( void );
\r
744 * <pre>portCHAR xTaskResumeAll( void );</pre>
\r
746 * Resumes real time kernel activity following a call to vTaskSuspendAll ().
\r
747 * After a call to vTaskSuspendAll () the kernel will take control of which
\r
748 * task is executing at any time.
\r
750 * @return If resuming the scheduler caused a context switch then pdTRUE is
\r
751 * returned, otherwise pdFALSE is returned.
\r
755 void vTask1( void * pvParameters )
\r
759 // Task code goes here.
\r
763 // At some point the task wants to perform a long operation during
\r
764 // which it does not want to get swapped out. It cannot use
\r
765 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
\r
766 // operation may cause interrupts to be missed - including the
\r
769 // Prevent the real time kernel swapping out the task.
\r
770 vTaskSuspendAll ();
\r
772 // Perform the operation here. There is no need to use critical
\r
773 // sections as we have all the microcontroller processing time.
\r
774 // During this time interrupts will still operate and the real
\r
775 // time kernel tick count will be maintained.
\r
779 // The operation is complete. Restart the kernel. We want to force
\r
780 // a context switch - but there is no point if resuming the scheduler
\r
781 // caused a context switch already.
\r
782 if( !xTaskResumeAll () )
\r
789 * \defgroup xTaskResumeAll xTaskResumeAll
\r
790 * \ingroup SchedulerControl
\r
792 signed portBASE_TYPE xTaskResumeAll( void );
\r
796 * <pre>signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask );</pre>
\r
798 * Utility task that simply returns pdTRUE if the task referenced by xTask is
\r
799 * currently in the Suspended state, or pdFALSE if the task referenced by xTask
\r
800 * is in any other state.
\r
803 signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask );
\r
805 /*-----------------------------------------------------------
\r
807 *----------------------------------------------------------*/
\r
811 * <PRE>volatile portTickType xTaskGetTickCount( void );</PRE>
\r
813 * @return The count of ticks since vTaskStartScheduler was called.
\r
815 * \page xTaskGetTickCount xTaskGetTickCount
\r
816 * \ingroup TaskUtils
\r
818 portTickType xTaskGetTickCount( void );
\r
822 * <PRE>unsigned portSHORT uxTaskGetNumberOfTasks( void );</PRE>
\r
824 * @return The number of tasks that the real time kernel is currently managing.
\r
825 * This includes all ready, blocked and suspended tasks. A task that
\r
826 * has been deleted but not yet freed by the idle task will also be
\r
827 * included in the count.
\r
829 * \page uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
\r
830 * \ingroup TaskUtils
\r
832 unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void );
\r
836 * <PRE>void vTaskList( portCHAR *pcWriteBuffer );</PRE>
\r
838 * configUSE_TRACE_FACILITY, INCLUDE_vTaskDelete and INCLUDE_vTaskSuspend
\r
839 * must all be defined as 1 for this function to be available.
\r
840 * See the configuration section for more information.
\r
842 * NOTE: This function will disable interrupts for its duration. It is
\r
843 * not intended for normal application runtime use but as a debug aid.
\r
845 * Lists all the current tasks, along with their current state and stack
\r
846 * usage high water mark.
\r
848 * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
\r
851 * @param pcWriteBuffer A buffer into which the above mentioned details
\r
852 * will be written, in ascii form. This buffer is assumed to be large
\r
853 * enough to contain the generated report. Approximately 40 bytes per
\r
854 * task should be sufficient.
\r
856 * \page vTaskList vTaskList
\r
857 * \ingroup TaskUtils
\r
859 void vTaskList( signed portCHAR *pcWriteBuffer );
\r
863 * <PRE>void vTaskStartTrace( portCHAR * pcBuffer, unsigned portBASE_TYPE uxBufferSize );</PRE>
\r
865 * Starts a real time kernel activity trace. The trace logs the identity of
\r
866 * which task is running when.
\r
868 * The trace file is stored in binary format. A separate DOS utility called
\r
869 * convtrce.exe is used to convert this into a tab delimited text file which
\r
870 * can be viewed and plotted in a spread sheet.
\r
872 * @param pcBuffer The buffer into which the trace will be written.
\r
874 * @param ulBufferSize The size of pcBuffer in bytes. The trace will continue
\r
875 * until either the buffer in full, or ulTaskEndTrace () is called.
\r
877 * \page vTaskStartTrace vTaskStartTrace
\r
878 * \ingroup TaskUtils
\r
880 void vTaskStartTrace( signed portCHAR * pcBuffer, unsigned portLONG ulBufferSize );
\r
884 * <PRE>unsigned portLONG ulTaskEndTrace( void );</PRE>
\r
886 * Stops a kernel activity trace. See vTaskStartTrace ().
\r
888 * @return The number of bytes that have been written into the trace buffer.
\r
890 * \page usTaskEndTrace usTaskEndTrace
\r
891 * \ingroup TaskUtils
\r
893 unsigned portLONG ulTaskEndTrace( void );
\r
897 * <PRE>unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );</PRE>
\r
899 * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
\r
900 * this function to be available.
\r
902 * Returns the high water mark of the stack associated with xTask. That is,
\r
903 * the minimum free stack space there has been (in bytes) since the task
\r
904 * started. The smaller the returned number the closer the task has come
\r
905 * to overflowing its stack.
\r
907 * @param xTask Handle of the task associated with the stack to be checked.
\r
908 * Set xTask to NULL to check the stack of the calling task.
\r
910 * @return The smallest amount of free stack space there has been (in bytes)
\r
911 * since the task referenced by xTask was created.
\r
913 unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );
\r
917 * <pre>void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>
\r
919 * Sets pxHookFunction to be the task hook function used by the task xTask.
\r
920 * Passing xTask as NULL has the effect of setting the calling tasks hook
\r
923 void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );
\r
927 * <pre>portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>
\r
929 * Calls the hook function associated with xTask. Passing xTask as NULL has
\r
930 * the effect of calling the Running tasks (the calling task) hook function.
\r
932 * pvParameter is passed to the hook function for the task to interpret as it
\r
935 portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter );
\r
938 /*-----------------------------------------------------------
\r
939 * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
\r
940 *----------------------------------------------------------*/
\r
943 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
\r
944 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
\r
945 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
947 * Called from the real time kernel tick (either preemptive or cooperative),
\r
948 * this increments the tick count and checks if any tasks that are blocked
\r
949 * for a finite period required removing from a blocked list and placing on
\r
952 void vTaskIncrementTick( void );
\r
955 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
956 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
958 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
\r
960 * Removes the calling task from the ready list and places it both
\r
961 * on the list of tasks waiting for a particular event, and the
\r
962 * list of delayed tasks. The task will be removed from both lists
\r
963 * and replaced on the ready list should either the event occur (and
\r
964 * there be no higher priority tasks waiting on the same event) or
\r
965 * the delay period expires.
\r
967 * @param pxEventList The list containing tasks that are blocked waiting
\r
968 * for the event to occur.
\r
970 * @param xTicksToWait The maximum amount of time that the task should wait
\r
971 * for the event to occur. This is specified in kernel ticks,the constant
\r
972 * portTICK_RATE_MS can be used to convert kernel ticks into a real time
\r
975 void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicksToWait );
\r
978 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
979 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
981 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
\r
983 * Removes a task from both the specified event list and the list of blocked
\r
984 * tasks, and places it on a ready queue.
\r
986 * xTaskRemoveFromEventList () will be called if either an event occurs to
\r
987 * unblock a task, or the block timeout period expires.
\r
989 * @return pdTRUE if the task being removed has a higher priority than the task
\r
990 * making the call, otherwise pdFALSE.
\r
992 signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList );
\r
995 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
996 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
998 * INCLUDE_vTaskCleanUpResources and INCLUDE_vTaskSuspend must be defined as 1
\r
999 * for this function to be available.
\r
1000 * See the configuration section for more information.
\r
1002 * Empties the ready and delayed queues of task control blocks, freeing the
\r
1003 * memory allocated for the task control block and task stacks as it goes.
\r
1005 void vTaskCleanUpResources( void );
\r
1008 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
\r
1009 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
\r
1010 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
1012 * Sets the pointer to the current TCB to the TCB of the highest priority task
\r
1013 * that is ready to run.
\r
1015 void vTaskSwitchContext( void );
\r
1018 * Return the handle of the calling task.
\r
1020 xTaskHandle xTaskGetCurrentTaskHandle( void );
\r
1023 * Capture the current time status for future reference.
\r
1025 void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut );
\r
1028 * Compare the time status now with that previously captured to see if the
\r
1029 * timeout has expired.
\r
1031 portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType * const pxTicksToWait );
\r
1034 * Shortcut used by the queue implementation to prevent unnecessary call to
\r
1037 void vTaskMissedYield( void );
\r
1040 * Returns the scheduler state as taskSCHEDULER_RUNNING,
\r
1041 * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
\r
1043 portBASE_TYPE xTaskGetSchedulerState( void );
\r
1046 * Raises the priority of the mutex holder to that of the calling task should
\r
1047 * the mutex holder have a priority less than the calling task.
\r
1049 void vTaskPriorityInherit( xTaskHandle * const pxMutexHolder );
\r
1052 * Set the priority of a task back to its proper priority in the case that it
\r
1053 * inherited a higher priority while it was holding a semaphore.
\r
1055 void vTaskPriorityDisinherit( xTaskHandle * const pxMutexHolder );
\r
1057 #ifdef __cplusplus
\r
1060 #endif /* TASK_H */
\r