2 FreeRTOS.org V4.6.0 - Copyright (C) 2003-2007 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 See http://www.FreeRTOS.org for documentation, latest information, license
\r
28 and contact details. Please ensure to read the configuration and relevant
\r
29 port sections of the online documentation.
\r
31 Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along
\r
32 with commercial development and support options.
\r
33 ***************************************************************************
\r
37 Changes since V4.3.1:
\r
39 + Added xTaskGetSchedulerState() function.
\r
45 #include "portable.h"
\r
48 /*-----------------------------------------------------------
\r
49 * MACROS AND DEFINITIONS
\r
50 *----------------------------------------------------------*/
\r
52 #define tskKERNEL_VERSION_NUMBER "V4.4.0"
\r
57 * Type by which tasks are referenced. For example, a call to xTaskCreate
\r
58 * returns (via a pointer parameter) an xTaskHandle variable that can then
\r
59 * be used as a parameter to vTaskDelete to delete the task.
\r
61 * \page xTaskHandle xTaskHandle
\r
64 typedef void * xTaskHandle;
\r
67 * Used internally only.
\r
69 typedef struct xTIME_OUT
\r
71 portBASE_TYPE xOverflowCount;
\r
72 portTickType xTimeOnEntering;
\r
76 * Defines the priority used by the idle task. This must not be modified.
\r
78 * \ingroup TaskUtils
\r
80 #define tskIDLE_PRIORITY ( ( unsigned portBASE_TYPE ) 0 )
\r
85 * Macro for forcing a context switch.
\r
87 * \page taskYIELD taskYIELD
\r
88 * \ingroup SchedulerControl
\r
90 #define taskYIELD() portYIELD()
\r
95 * Macro to mark the start of a critical code region. Preemptive context
\r
96 * switches cannot occur when in a critical region.
\r
98 * NOTE: This may alter the stack (depending on the portable implementation)
\r
99 * so must be used with care!
\r
101 * \page taskENTER_CRITICAL taskENTER_CRITICAL
\r
102 * \ingroup SchedulerControl
\r
104 #define taskENTER_CRITICAL() portENTER_CRITICAL()
\r
109 * Macro to mark the end of a critical code region. Preemptive context
\r
110 * switches cannot occur when in a critical region.
\r
112 * NOTE: This may alter the stack (depending on the portable implementation)
\r
113 * so must be used with care!
\r
115 * \page taskEXIT_CRITICAL taskEXIT_CRITICAL
\r
116 * \ingroup SchedulerControl
\r
118 #define taskEXIT_CRITICAL() portEXIT_CRITICAL()
\r
123 * Macro to disable all maskable interrupts.
\r
125 * \page taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
\r
126 * \ingroup SchedulerControl
\r
128 #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
\r
133 * Macro to enable microcontroller interrupts.
\r
135 * \page taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
\r
136 * \ingroup SchedulerControl
\r
138 #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
\r
140 /* Definitions returned by xTaskGetSchedulerState(). */
\r
141 #define taskSCHEDULER_NOT_STARTED 0
\r
142 #define taskSCHEDULER_RUNNING 1
\r
143 #define taskSCHEDULER_SUSPENDED 2
\r
145 /*-----------------------------------------------------------
\r
146 * TASK CREATION API
\r
147 *----------------------------------------------------------*/
\r
152 portBASE_TYPE xTaskCreate(
\r
153 pdTASK_CODE pvTaskCode,
\r
154 const portCHAR * const pcName,
\r
155 unsigned portSHORT usStackDepth,
\r
156 void *pvParameters,
\r
157 unsigned portBASE_TYPE uxPriority,
\r
158 xTaskHandle *pvCreatedTask
\r
161 * Create a new task and add it to the list of tasks that are ready to run.
\r
163 * @param pvTaskCode Pointer to the task entry function. Tasks
\r
164 * must be implemented to never return (i.e. continuous loop).
\r
166 * @param pcName A descriptive name for the task. This is mainly used to
\r
167 * facilitate debugging. Max length defined by tskMAX_TASK_NAME_LEN - default
\r
170 * @param usStackDepth The size of the task stack specified as the number of
\r
171 * variables the stack can hold - not the number of bytes. For example, if
\r
172 * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
\r
173 * will be allocated for stack storage.
\r
175 * @param pvParameters Pointer that will be used as the parameter for the task
\r
178 * @param uxPriority The priority at which the task should run.
\r
180 * @param pvCreatedTask Used to pass back a handle by which the created task
\r
181 * can be referenced.
\r
183 * @return pdPASS if the task was successfully created and added to a ready
\r
184 * list, otherwise an error code defined in the file errors. h
\r
188 // Task to be created.
\r
189 void vTaskCode( void * pvParameters )
\r
193 // Task code goes here.
\r
197 // Function that creates a task.
\r
198 void vOtherFunction( void )
\r
200 unsigned char ucParameterToPass;
\r
201 xTaskHandle xHandle;
\r
203 // Create the task, storing the handle.
\r
204 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
\r
206 // Use the handle to delete the task.
\r
207 vTaskDelete( xHandle );
\r
210 * \defgroup xTaskCreate xTaskCreate
\r
213 signed portBASE_TYPE xTaskCreate( pdTASK_CODE pvTaskCode, const signed portCHAR * const pcName, unsigned portSHORT usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pvCreatedTask );
\r
217 * <pre>void vTaskDelete( xTaskHandle pxTask );</pre>
\r
219 * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
\r
220 * See the configuration section for more information.
\r
222 * Remove a task from the RTOS real time kernels management. The task being
\r
223 * deleted will be removed from all ready, blocked, suspended and event lists.
\r
225 * NOTE: The idle task is responsible for freeing the kernel allocated
\r
226 * memory from tasks that have been deleted. It is therefore important that
\r
227 * the idle task is not starved of microcontroller processing time if your
\r
228 * application makes any calls to vTaskDelete (). Memory allocated by the
\r
229 * task code is not automatically freed, and should be freed before the task
\r
232 * See the demo application file death.c for sample code that utilises
\r
235 * @param pxTask The handle of the task to be deleted. Passing NULL will
\r
236 * cause the calling task to be deleted.
\r
240 void vOtherFunction( void )
\r
242 xTaskHandle xHandle;
\r
244 // Create the task, storing the handle.
\r
245 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
247 // Use the handle to delete the task.
\r
248 vTaskDelete( xHandle );
\r
251 * \defgroup vTaskDelete vTaskDelete
\r
254 void vTaskDelete( xTaskHandle pxTask );
\r
257 /*-----------------------------------------------------------
\r
259 *----------------------------------------------------------*/
\r
263 * <pre>void vTaskDelay( portTickType xTicksToDelay );</pre>
\r
265 * Delay a task for a given number of ticks. The actual time that the
\r
266 * task remains blocked depends on the tick rate. The constant
\r
267 * portTICK_RATE_MS can be used to calculate real time from the tick
\r
268 * rate - with the resolution of one tick period.
\r
270 * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
\r
271 * See the configuration section for more information.
\r
273 * @param xTicksToDelay The amount of time, in tick periods, that
\r
274 * the calling task should block.
\r
278 // Wait 10 ticks before performing an action.
\r
280 // This is for demonstration only and would be better achieved
\r
281 // using vTaskDelayUntil ().
\r
282 void vTaskFunction( void * pvParameters )
\r
284 portTickType xDelay, xNextTime;
\r
286 // Calc the time at which we want to perform the action
\r
288 xNextTime = xTaskGetTickCount () + ( portTickType ) 10;
\r
292 xDelay = xNextTime - xTaskGetTickCount ();
\r
293 xNextTime += ( portTickType ) 10;
\r
295 // Guard against overflow
\r
296 if( xDelay <= ( portTickType ) 10 )
\r
298 vTaskDelay( xDelay );
\r
301 // Perform action here.
\r
305 * \defgroup vTaskDelay vTaskDelay
\r
306 * \ingroup TaskCtrl
\r
308 void vTaskDelay( portTickType xTicksToDelay );
\r
312 * <pre>void vTaskDelayUntil( portTickType *pxPreviousWakeTime, portTickType xTimeIncrement );</pre>
\r
314 * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
\r
315 * See the configuration section for more information.
\r
317 * Delay a task until a specified time. This function can be used by cyclical
\r
318 * tasks to ensure a constant execution frequency.
\r
320 * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
\r
321 * cause a task to block for the specified number of ticks from the time vTaskDelay () is
\r
322 * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
\r
323 * execution frequency as the time between a task starting to execute and that task
\r
324 * calling vTaskDelay () may not be fixed [the task may take a different path though the
\r
325 * code between calls, or may get interrupted or preempted a different number of times
\r
326 * each time it executes].
\r
328 * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
\r
329 * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
\r
332 * The constant portTICK_RATE_MS can be used to calculate real time from the tick
\r
333 * rate - with the resolution of one tick period.
\r
335 * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
\r
336 * task was last unblocked. The variable must be initialised with the current time
\r
337 * prior to its first use (see the example below). Following this the variable is
\r
338 * automatically updated within vTaskDelayUntil ().
\r
340 * @param xTimeIncrement The cycle time period. The task will be unblocked at
\r
341 * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the
\r
342 * same xTimeIncrement parameter value will cause the task to execute with
\r
343 * a fixed interface period.
\r
347 // Perform an action every 10 ticks.
\r
348 void vTaskFunction( void * pvParameters )
\r
350 portTickType xLastWakeTime;
\r
351 const portTickType xFrequency = 10;
\r
353 // Initialise the xLastWakeTime variable with the current time.
\r
354 xLastWakeTime = xTaskGetTickCount ();
\r
357 // Wait for the next cycle.
\r
358 vTaskDelayUntil( &xLastWakeTime, xFrequency );
\r
360 // Perform action here.
\r
364 * \defgroup vTaskDelayUntil vTaskDelayUntil
\r
365 * \ingroup TaskCtrl
\r
367 void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement );
\r
371 * <pre>unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );</pre>
\r
373 * INCLUDE_xTaskPriorityGet must be defined as 1 for this function to be available.
\r
374 * See the configuration section for more information.
\r
376 * Obtain the priority of any task.
\r
378 * @param pxTask Handle of the task to be queried. Passing a NULL
\r
379 * handle results in the priority of the calling task being returned.
\r
381 * @return The priority of pxTask.
\r
385 void vAFunction( void )
\r
387 xTaskHandle xHandle;
\r
389 // Create a task, storing the handle.
\r
390 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
394 // Use the handle to obtain the priority of the created task.
\r
395 // It was created with tskIDLE_PRIORITY, but may have changed
\r
397 if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
\r
399 // The task has changed it's priority.
\r
404 // Is our priority higher than the created task?
\r
405 if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
\r
407 // Our priority (obtained using NULL handle) is higher.
\r
411 * \defgroup uxTaskPriorityGet uxTaskPriorityGet
\r
412 * \ingroup TaskCtrl
\r
414 unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );
\r
418 * <pre>void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );</pre>
\r
420 * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
\r
421 * See the configuration section for more information.
\r
423 * Set the priority of any task.
\r
425 * A context switch will occur before the function returns if the priority
\r
426 * being set is higher than the currently executing task.
\r
428 * @param pxTask Handle to the task for which the priority is being set.
\r
429 * Passing a NULL handle results in the priority of the calling task being set.
\r
431 * @param uxNewPriority The priority to which the task will be set.
\r
435 void vAFunction( void )
\r
437 xTaskHandle xHandle;
\r
439 // Create a task, storing the handle.
\r
440 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
444 // Use the handle to raise the priority of the created task.
\r
445 vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
\r
449 // Use a NULL handle to raise our priority to the same value.
\r
450 vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
\r
453 * \defgroup vTaskPrioritySet vTaskPrioritySet
\r
454 * \ingroup TaskCtrl
\r
456 void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );
\r
460 * <pre>void vTaskSuspend( xTaskHandle pxTaskToSuspend );</pre>
\r
462 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
\r
463 * See the configuration section for more information.
\r
465 * Suspend any task. When suspended a task will never get any microcontroller
\r
466 * processing time, no matter what its priority.
\r
468 * Calls to vTaskSuspend are not accumulative -
\r
469 * i.e. calling vTaskSuspend () twice on the same task still only requires one
\r
470 * call to vTaskResume () to ready the suspended task.
\r
472 * @param pxTaskToSuspend Handle to the task being suspended. Passing a NULL
\r
473 * handle will cause the calling task to be suspended.
\r
477 void vAFunction( void )
\r
479 xTaskHandle xHandle;
\r
481 // Create a task, storing the handle.
\r
482 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
486 // Use the handle to suspend the created task.
\r
487 vTaskSuspend( xHandle );
\r
491 // The created task will not run during this period, unless
\r
492 // another task calls vTaskResume( xHandle ).
\r
497 // Suspend ourselves.
\r
498 vTaskSuspend( NULL );
\r
500 // We cannot get here unless another task calls vTaskResume
\r
501 // with our handle as the parameter.
\r
504 * \defgroup vTaskSuspend vTaskSuspend
\r
505 * \ingroup TaskCtrl
\r
507 void vTaskSuspend( xTaskHandle pxTaskToSuspend );
\r
511 * <pre>void vTaskResume( xTaskHandle pxTaskToResume );</pre>
\r
513 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
\r
514 * See the configuration section for more information.
\r
516 * Resumes a suspended task.
\r
518 * A task that has been suspended by one of more calls to vTaskSuspend ()
\r
519 * will be made available for running again by a single call to
\r
522 * @param pxTaskToResume Handle to the task being readied.
\r
526 void vAFunction( void )
\r
528 xTaskHandle xHandle;
\r
530 // Create a task, storing the handle.
\r
531 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
535 // Use the handle to suspend the created task.
\r
536 vTaskSuspend( xHandle );
\r
540 // The created task will not run during this period, unless
\r
541 // another task calls vTaskResume( xHandle ).
\r
546 // Resume the suspended task ourselves.
\r
547 vTaskResume( xHandle );
\r
549 // The created task will once again get microcontroller processing
\r
550 // time in accordance with it priority within the system.
\r
553 * \defgroup vTaskResume vTaskResume
\r
554 * \ingroup TaskCtrl
\r
556 void vTaskResume( xTaskHandle pxTaskToResume );
\r
560 * <pre>void xTaskResumeFromISR( xTaskHandle pxTaskToResume );</pre>
\r
562 * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
\r
563 * available. See the configuration section for more information.
\r
565 * An implementation of vTaskResume() that can be called from within an ISR.
\r
567 * A task that has been suspended by one of more calls to vTaskSuspend ()
\r
568 * will be made available for running again by a single call to
\r
569 * xTaskResumeFromISR ().
\r
571 * @param pxTaskToResume Handle to the task being readied.
\r
573 * \defgroup vTaskResumeFromISR vTaskResumeFromISR
\r
574 * \ingroup TaskCtrl
\r
576 portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume );
\r
578 /*-----------------------------------------------------------
\r
579 * SCHEDULER CONTROL
\r
580 *----------------------------------------------------------*/
\r
584 * <pre>void vTaskStartScheduler( void );</pre>
\r
586 * Starts the real time kernel tick processing. After calling the kernel
\r
587 * has control over which tasks are executed and when. This function
\r
588 * does not return until an executing task calls vTaskEndScheduler ().
\r
590 * At least one task should be created via a call to xTaskCreate ()
\r
591 * before calling vTaskStartScheduler (). The idle task is created
\r
592 * automatically when the first application task is created.
\r
594 * See the demo application file main.c for an example of creating
\r
595 * tasks and starting the kernel.
\r
599 void vAFunction( void )
\r
601 // Create at least one task before starting the kernel.
\r
602 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
604 // Start the real time kernel with preemption.
\r
605 vTaskStartScheduler ();
\r
607 // Will not get here unless a task calls vTaskEndScheduler ()
\r
611 * \defgroup vTaskStartScheduler vTaskStartScheduler
\r
612 * \ingroup SchedulerControl
\r
614 void vTaskStartScheduler( void );
\r
618 * <pre>void vTaskEndScheduler( void );</pre>
\r
620 * Stops the real time kernel tick. All created tasks will be automatically
\r
621 * deleted and multitasking (either preemptive or cooperative) will
\r
622 * stop. Execution then resumes from the point where vTaskStartScheduler ()
\r
623 * was called, as if vTaskStartScheduler () had just returned.
\r
625 * See the demo application file main. c in the demo/PC directory for an
\r
626 * example that uses vTaskEndScheduler ().
\r
628 * vTaskEndScheduler () requires an exit function to be defined within the
\r
629 * portable layer (see vPortEndScheduler () in port. c for the PC port). This
\r
630 * performs hardware specific operations such as stopping the kernel tick.
\r
632 * vTaskEndScheduler () will cause all of the resources allocated by the
\r
633 * kernel to be freed - but will not free resources allocated by application
\r
638 void vTaskCode( void * pvParameters )
\r
642 // Task code goes here.
\r
644 // At some point we want to end the real time kernel processing
\r
646 vTaskEndScheduler ();
\r
650 void vAFunction( void )
\r
652 // Create at least one task before starting the kernel.
\r
653 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
655 // Start the real time kernel with preemption.
\r
656 vTaskStartScheduler ();
\r
658 // Will only get here when the vTaskCode () task has called
\r
659 // vTaskEndScheduler (). When we get here we are back to single task
\r
664 * \defgroup vTaskEndScheduler vTaskEndScheduler
\r
665 * \ingroup SchedulerControl
\r
667 void vTaskEndScheduler( void );
\r
671 * <pre>void vTaskSuspendAll( void );</pre>
\r
673 * Suspends all real time kernel activity while keeping interrupts (including the
\r
674 * kernel tick) enabled.
\r
676 * After calling vTaskSuspendAll () the calling task will continue to execute
\r
677 * without risk of being swapped out until a call to xTaskResumeAll () has been
\r
682 void vTask1( void * pvParameters )
\r
686 // Task code goes here.
\r
690 // At some point the task wants to perform a long operation during
\r
691 // which it does not want to get swapped out. It cannot use
\r
692 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
\r
693 // operation may cause interrupts to be missed - including the
\r
696 // Prevent the real time kernel swapping out the task.
\r
697 vTaskSuspendAll ();
\r
699 // Perform the operation here. There is no need to use critical
\r
700 // sections as we have all the microcontroller processing time.
\r
701 // During this time interrupts will still operate and the kernel
\r
702 // tick count will be maintained.
\r
706 // The operation is complete. Restart the kernel.
\r
711 * \defgroup vTaskSuspendAll vTaskSuspendAll
\r
712 * \ingroup SchedulerControl
\r
714 void vTaskSuspendAll( void );
\r
718 * <pre>portCHAR xTaskResumeAll( void );</pre>
\r
720 * Resumes real time kernel activity following a call to vTaskSuspendAll ().
\r
721 * After a call to vTaskSuspendAll () the kernel will take control of which
\r
722 * task is executing at any time.
\r
724 * @return If resuming the scheduler caused a context switch then pdTRUE is
\r
725 * returned, otherwise pdFALSE is returned.
\r
729 void vTask1( void * pvParameters )
\r
733 // Task code goes here.
\r
737 // At some point the task wants to perform a long operation during
\r
738 // which it does not want to get swapped out. It cannot use
\r
739 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
\r
740 // operation may cause interrupts to be missed - including the
\r
743 // Prevent the real time kernel swapping out the task.
\r
744 vTaskSuspendAll ();
\r
746 // Perform the operation here. There is no need to use critical
\r
747 // sections as we have all the microcontroller processing time.
\r
748 // During this time interrupts will still operate and the real
\r
749 // time kernel tick count will be maintained.
\r
753 // The operation is complete. Restart the kernel. We want to force
\r
754 // a context switch - but there is no point if resuming the scheduler
\r
755 // caused a context switch already.
\r
756 if( !xTaskResumeAll () )
\r
763 * \defgroup xTaskResumeAll xTaskResumeAll
\r
764 * \ingroup SchedulerControl
\r
766 signed portBASE_TYPE xTaskResumeAll( void );
\r
769 /*-----------------------------------------------------------
\r
771 *----------------------------------------------------------*/
\r
775 * <PRE>volatile portTickType xTaskGetTickCount( void );</PRE>
\r
777 * @return The count of ticks since vTaskStartScheduler was called.
\r
779 * \page xTaskGetTickCount xTaskGetTickCount
\r
780 * \ingroup TaskUtils
\r
782 portTickType xTaskGetTickCount( void );
\r
786 * <PRE>unsigned portSHORT uxTaskGetNumberOfTasks( void );</PRE>
\r
788 * @return The number of tasks that the real time kernel is currently managing.
\r
789 * This includes all ready, blocked and suspended tasks. A task that
\r
790 * has been deleted but not yet freed by the idle task will also be
\r
791 * included in the count.
\r
793 * \page uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
\r
794 * \ingroup TaskUtils
\r
796 unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void );
\r
800 * <PRE>void vTaskList( portCHAR *pcWriteBuffer );</PRE>
\r
802 * configUSE_TRACE_FACILITY, INCLUDE_vTaskDelete and INCLUDE_vTaskSuspend
\r
803 * must all be defined as 1 for this function to be available.
\r
804 * See the configuration section for more information.
\r
806 * NOTE: This function will disable interrupts for its duration. It is
\r
807 * not intended for normal application runtime use but as a debug aid.
\r
809 * Lists all the current tasks, along with their current state and stack
\r
810 * usage high water mark.
\r
812 * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
\r
815 * @param pcWriteBuffer A buffer into which the above mentioned details
\r
816 * will be written, in ascii form. This buffer is assumed to be large
\r
817 * enough to contain the generated report. Approximately 40 bytes per
\r
818 * task should be sufficient.
\r
820 * \page vTaskList vTaskList
\r
821 * \ingroup TaskUtils
\r
823 void vTaskList( signed portCHAR *pcWriteBuffer );
\r
827 * <PRE>void vTaskStartTrace( portCHAR * pcBuffer, unsigned portBASE_TYPE uxBufferSize );</PRE>
\r
829 * Starts a real time kernel activity trace. The trace logs the identity of
\r
830 * which task is running when.
\r
832 * The trace file is stored in binary format. A separate DOS utility called
\r
833 * convtrce.exe is used to convert this into a tab delimited text file which
\r
834 * can be viewed and plotted in a spread sheet.
\r
836 * @param pcBuffer The buffer into which the trace will be written.
\r
838 * @param ulBufferSize The size of pcBuffer in bytes. The trace will continue
\r
839 * until either the buffer in full, or ulTaskEndTrace () is called.
\r
841 * \page vTaskStartTrace vTaskStartTrace
\r
842 * \ingroup TaskUtils
\r
844 void vTaskStartTrace( signed portCHAR * pcBuffer, unsigned portLONG ulBufferSize );
\r
848 * <PRE>unsigned portLONG ulTaskEndTrace( void );</PRE>
\r
850 * Stops a kernel activity trace. See vTaskStartTrace ().
\r
852 * @return The number of bytes that have been written into the trace buffer.
\r
854 * \page usTaskEndTrace usTaskEndTrace
\r
855 * \ingroup TaskUtils
\r
857 unsigned portLONG ulTaskEndTrace( void );
\r
860 /*-----------------------------------------------------------
\r
861 * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
\r
862 *----------------------------------------------------------*/
\r
865 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
\r
866 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
\r
867 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
869 * Called from the real time kernel tick (either preemptive or cooperative),
\r
870 * this increments the tick count and checks if any tasks that are blocked
\r
871 * for a finite period required removing from a blocked list and placing on
\r
874 inline void vTaskIncrementTick( void );
\r
877 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
878 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
880 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
\r
882 * Removes the calling task from the ready list and places it both
\r
883 * on the list of tasks waiting for a particular event, and the
\r
884 * list of delayed tasks. The task will be removed from both lists
\r
885 * and replaced on the ready list should either the event occur (and
\r
886 * there be no higher priority tasks waiting on the same event) or
\r
887 * the delay period expires.
\r
889 * @param pxEventList The list containing tasks that are blocked waiting
\r
890 * for the event to occur.
\r
892 * @param xTicksToWait The maximum amount of time that the task should wait
\r
893 * for the event to occur. This is specified in kernel ticks,the constant
\r
894 * portTICK_RATE_MS can be used to convert kernel ticks into a real time
\r
897 void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicksToWait );
\r
900 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
901 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
903 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
\r
905 * Removes a task from both the specified event list and the list of blocked
\r
906 * tasks, and places it on a ready queue.
\r
908 * xTaskRemoveFromEventList () will be called if either an event occurs to
\r
909 * unblock a task, or the block timeout period expires.
\r
911 * @return pdTRUE if the task being removed has a higher priority than the task
\r
912 * making the call, otherwise pdFALSE.
\r
914 signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList );
\r
917 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
918 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
920 * INCLUDE_vTaskCleanUpResources and INCLUDE_vTaskSuspend must be defined as 1
\r
921 * for this function to be available.
\r
922 * See the configuration section for more information.
\r
924 * Empties the ready and delayed queues of task control blocks, freeing the
\r
925 * memory allocated for the task control block and task stacks as it goes.
\r
927 void vTaskCleanUpResources( void );
\r
930 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
\r
931 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
\r
932 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
934 * Sets the pointer to the current TCB to the TCB of the highest priority task
\r
935 * that is ready to run.
\r
937 inline void vTaskSwitchContext( void );
\r
940 * Return the handle of the calling task.
\r
942 xTaskHandle xTaskGetCurrentTaskHandle( void );
\r
945 * Capture the current time status for future reference.
\r
947 void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut );
\r
950 * Compare the time status now with that previously captured to see if the
\r
951 * timeout has expired.
\r
953 portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType * const pxTicksToWait );
\r
956 * Shortcut used by the queue implementation to prevent unnecessary call to
\r
959 void vTaskMissedYield( void );
\r
962 * Returns the scheduler state as taskSCHEDULER_RUNNING,
\r
963 * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
\r
965 portBASE_TYPE xTaskGetSchedulerState( void );
\r
968 * Raises the priority of the mutex holder to that of the calling task should
\r
969 * the mutex holder have a priority less than the calling task.
\r
971 void vTaskPriorityInherit( xTaskHandle * const pxMutexHolder );
\r
974 * Set the priority of a task back to its proper priority in the case that it
\r
975 * inherited a higher priority while it was holding a semaphore.
\r
977 void vTaskPriorityDisinherit( xTaskHandle * const pxMutexHolder );
\r
979 #endif /* TASK_H */
\r