2 FreeRTOS.org V4.3.1 - 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
39 #include "portable.h"
\r
42 /*-----------------------------------------------------------
\r
43 * MACROS AND DEFINITIONS
\r
44 *----------------------------------------------------------*/
\r
46 #define tskKERNEL_VERSION_NUMBER "V4.3.0"
\r
51 * Type by which tasks are referenced. For example, a call to xTaskCreate
\r
52 * returns (via a pointer parameter) an xTaskHandle variable that can then
\r
53 * be used as a parameter to vTaskDelete to delete the task.
\r
55 * \page xTaskHandle xTaskHandle
\r
58 typedef void * xTaskHandle;
\r
61 * Used internally only.
\r
63 typedef struct xTIME_OUT
\r
65 portBASE_TYPE xOverflowCount;
\r
66 portTickType xTimeOnEntering;
\r
70 * Defines the priority used by the idle task. This must not be modified.
\r
72 * \ingroup TaskUtils
\r
74 #define tskIDLE_PRIORITY ( ( unsigned portBASE_TYPE ) 0 )
\r
79 * Macro for forcing a context switch.
\r
81 * \page taskYIELD taskYIELD
\r
82 * \ingroup SchedulerControl
\r
84 #define taskYIELD() portYIELD()
\r
89 * Macro to mark the start of a critical code region. Preemptive context
\r
90 * switches cannot occur when in a critical region.
\r
92 * NOTE: This may alter the stack (depending on the portable implementation)
\r
93 * so must be used with care!
\r
95 * \page taskENTER_CRITICAL taskENTER_CRITICAL
\r
96 * \ingroup SchedulerControl
\r
98 #define taskENTER_CRITICAL() portENTER_CRITICAL()
\r
103 * Macro to mark the end of a critical code region. Preemptive context
\r
104 * switches cannot occur when in a critical region.
\r
106 * NOTE: This may alter the stack (depending on the portable implementation)
\r
107 * so must be used with care!
\r
109 * \page taskEXIT_CRITICAL taskEXIT_CRITICAL
\r
110 * \ingroup SchedulerControl
\r
112 #define taskEXIT_CRITICAL() portEXIT_CRITICAL()
\r
117 * Macro to disable all maskable interrupts.
\r
119 * \page taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
\r
120 * \ingroup SchedulerControl
\r
122 #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
\r
127 * Macro to enable microcontroller interrupts.
\r
129 * \page taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
\r
130 * \ingroup SchedulerControl
\r
132 #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
\r
135 /*-----------------------------------------------------------
\r
136 * TASK CREATION API
\r
137 *----------------------------------------------------------*/
\r
142 portBASE_TYPE xTaskCreate(
\r
143 pdTASK_CODE pvTaskCode,
\r
144 const portCHAR * const pcName,
\r
145 unsigned portSHORT usStackDepth,
\r
146 void *pvParameters,
\r
147 unsigned portBASE_TYPE uxPriority,
\r
148 xTaskHandle *pvCreatedTask
\r
151 * Create a new task and add it to the list of tasks that are ready to run.
\r
153 * @param pvTaskCode Pointer to the task entry function. Tasks
\r
154 * must be implemented to never return (i.e. continuous loop).
\r
156 * @param pcName A descriptive name for the task. This is mainly used to
\r
157 * facilitate debugging. Max length defined by tskMAX_TASK_NAME_LEN - default
\r
160 * @param usStackDepth The size of the task stack specified as the number of
\r
161 * variables the stack can hold - not the number of bytes. For example, if
\r
162 * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
\r
163 * will be allocated for stack storage.
\r
165 * @param pvParameters Pointer that will be used as the parameter for the task
\r
168 * @param uxPriority The priority at which the task should run.
\r
170 * @param pvCreatedTask Used to pass back a handle by which the created task
\r
171 * can be referenced.
\r
173 * @return pdPASS if the task was successfully created and added to a ready
\r
174 * list, otherwise an error code defined in the file errors. h
\r
178 // Task to be created.
\r
179 void vTaskCode( void * pvParameters )
\r
183 // Task code goes here.
\r
187 // Function that creates a task.
\r
188 void vOtherFunction( void )
\r
190 unsigned char ucParameterToPass;
\r
191 xTaskHandle xHandle;
\r
193 // Create the task, storing the handle.
\r
194 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
\r
196 // Use the handle to delete the task.
\r
197 vTaskDelete( xHandle );
\r
200 * \defgroup xTaskCreate xTaskCreate
\r
203 signed portBASE_TYPE xTaskCreate( pdTASK_CODE pvTaskCode, const signed portCHAR * const pcName, unsigned portSHORT usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pvCreatedTask );
\r
207 * <pre>void vTaskDelete( xTaskHandle pxTask );</pre>
\r
209 * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
\r
210 * See the configuration section for more information.
\r
212 * Remove a task from the RTOS real time kernels management. The task being
\r
213 * deleted will be removed from all ready, blocked, suspended and event lists.
\r
215 * NOTE: The idle task is responsible for freeing the kernel allocated
\r
216 * memory from tasks that have been deleted. It is therefore important that
\r
217 * the idle task is not starved of microcontroller processing time if your
\r
218 * application makes any calls to vTaskDelete (). Memory allocated by the
\r
219 * task code is not automatically freed, and should be freed before the task
\r
222 * See the demo application file death.c for sample code that utilises
\r
225 * @param pxTask The handle of the task to be deleted. Passing NULL will
\r
226 * cause the calling task to be deleted.
\r
230 void vOtherFunction( void )
\r
232 xTaskHandle xHandle;
\r
234 // Create the task, storing the handle.
\r
235 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
237 // Use the handle to delete the task.
\r
238 vTaskDelete( xHandle );
\r
241 * \defgroup vTaskDelete vTaskDelete
\r
244 void vTaskDelete( xTaskHandle pxTask );
\r
247 /*-----------------------------------------------------------
\r
249 *----------------------------------------------------------*/
\r
253 * <pre>void vTaskDelay( portTickType xTicksToDelay );</pre>
\r
255 * Delay a task for a given number of ticks. The actual time that the
\r
256 * task remains blocked depends on the tick rate. The constant
\r
257 * portTICK_RATE_MS can be used to calculate real time from the tick
\r
258 * rate - with the resolution of one tick period.
\r
260 * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
\r
261 * See the configuration section for more information.
\r
263 * @param xTicksToDelay The amount of time, in tick periods, that
\r
264 * the calling task should block.
\r
268 // Wait 10 ticks before performing an action.
\r
270 // This is for demonstration only and would be better achieved
\r
271 // using vTaskDelayUntil ().
\r
272 void vTaskFunction( void * pvParameters )
\r
274 portTickType xDelay, xNextTime;
\r
276 // Calc the time at which we want to perform the action
\r
278 xNextTime = xTaskGetTickCount () + ( portTickType ) 10;
\r
282 xDelay = xNextTime - xTaskGetTickCount ();
\r
283 xNextTime += ( portTickType ) 10;
\r
285 // Guard against overflow
\r
286 if( xDelay <= ( portTickType ) 10 )
\r
288 vTaskDelay( xDelay );
\r
291 // Perform action here.
\r
295 * \defgroup vTaskDelay vTaskDelay
\r
296 * \ingroup TaskCtrl
\r
298 void vTaskDelay( portTickType xTicksToDelay );
\r
302 * <pre>void vTaskDelayUntil( portTickType *pxPreviousWakeTime, portTickType xTimeIncrement );</pre>
\r
304 * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
\r
305 * See the configuration section for more information.
\r
307 * Delay a task until a specified time. This function can be used by cyclical
\r
308 * tasks to ensure a constant execution frequency.
\r
310 * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
\r
311 * cause a task to block for the specified number of ticks from the time vTaskDelay () is
\r
312 * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
\r
313 * execution frequency as the time between a task starting to execute and that task
\r
314 * calling vTaskDelay () may not be fixed [the task may take a different path though the
\r
315 * code between calls, or may get interrupted or preempted a different number of times
\r
316 * each time it executes].
\r
318 * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
\r
319 * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
\r
322 * The constant portTICK_RATE_MS can be used to calculate real time from the tick
\r
323 * rate - with the resolution of one tick period.
\r
325 * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
\r
326 * task was last unblocked. The variable must be initialised with the current time
\r
327 * prior to its first use (see the example below). Following this the variable is
\r
328 * automatically updated within vTaskDelayUntil ().
\r
330 * @param xTimeIncrement The cycle time period. The task will be unblocked at
\r
331 * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the
\r
332 * same xTimeIncrement parameter value will cause the task to execute with
\r
333 * a fixed interface period.
\r
337 // Perform an action every 10 ticks.
\r
338 void vTaskFunction( void * pvParameters )
\r
340 portTickType xLastWakeTime;
\r
341 const portTickType xFrequency = 10;
\r
343 // Initialise the xLastWakeTime variable with the current time.
\r
344 xLastWakeTime = xTaskGetTickCount ();
\r
347 // Wait for the next cycle.
\r
348 vTaskDelayUntil( &xLastWakeTime, xFrequency );
\r
350 // Perform action here.
\r
354 * \defgroup vTaskDelayUntil vTaskDelayUntil
\r
355 * \ingroup TaskCtrl
\r
357 void vTaskDelayUntil( portTickType *pxPreviousWakeTime, portTickType xTimeIncrement );
\r
361 * <pre>unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );</pre>
\r
363 * INCLUDE_xTaskPriorityGet must be defined as 1 for this function to be available.
\r
364 * See the configuration section for more information.
\r
366 * Obtain the priority of any task.
\r
368 * @param pxTask Handle of the task to be queried. Passing a NULL
\r
369 * handle results in the priority of the calling task being returned.
\r
371 * @return The priority of pxTask.
\r
375 void vAFunction( void )
\r
377 xTaskHandle xHandle;
\r
379 // Create a task, storing the handle.
\r
380 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
384 // Use the handle to obtain the priority of the created task.
\r
385 // It was created with tskIDLE_PRIORITY, but may have changed
\r
387 if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
\r
389 // The task has changed it's priority.
\r
394 // Is our priority higher than the created task?
\r
395 if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
\r
397 // Our priority (obtained using NULL handle) is higher.
\r
401 * \defgroup uxTaskPriorityGet uxTaskPriorityGet
\r
402 * \ingroup TaskCtrl
\r
404 unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );
\r
408 * <pre>void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );</pre>
\r
410 * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
\r
411 * See the configuration section for more information.
\r
413 * Set the priority of any task.
\r
415 * A context switch will occur before the function returns if the priority
\r
416 * being set is higher than the currently executing task.
\r
418 * @param pxTask Handle to the task for which the priority is being set.
\r
419 * Passing a NULL handle results in the priority of the calling task being set.
\r
421 * @param uxNewPriority The priority to which the task will be set.
\r
425 void vAFunction( void )
\r
427 xTaskHandle xHandle;
\r
429 // Create a task, storing the handle.
\r
430 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
434 // Use the handle to raise the priority of the created task.
\r
435 vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
\r
439 // Use a NULL handle to raise our priority to the same value.
\r
440 vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
\r
443 * \defgroup vTaskPrioritySet vTaskPrioritySet
\r
444 * \ingroup TaskCtrl
\r
446 void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );
\r
450 * <pre>void vTaskSuspend( xTaskHandle pxTaskToSuspend );</pre>
\r
452 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
\r
453 * See the configuration section for more information.
\r
455 * Suspend any task. When suspended a task will never get any microcontroller
\r
456 * processing time, no matter what its priority.
\r
458 * Calls to vTaskSuspend are not accumulative -
\r
459 * i.e. calling vTaskSuspend () twice on the same task still only requires one
\r
460 * call to vTaskResume () to ready the suspended task.
\r
462 * @param pxTaskToSuspend Handle to the task being suspended. Passing a NULL
\r
463 * handle will cause the calling task to be suspended.
\r
467 void vAFunction( void )
\r
469 xTaskHandle xHandle;
\r
471 // Create a task, storing the handle.
\r
472 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
476 // Use the handle to suspend the created task.
\r
477 vTaskSuspend( xHandle );
\r
481 // The created task will not run during this period, unless
\r
482 // another task calls vTaskResume( xHandle ).
\r
487 // Suspend ourselves.
\r
488 vTaskSuspend( NULL );
\r
490 // We cannot get here unless another task calls vTaskResume
\r
491 // with our handle as the parameter.
\r
494 * \defgroup vTaskSuspend vTaskSuspend
\r
495 * \ingroup TaskCtrl
\r
497 void vTaskSuspend( xTaskHandle pxTaskToSuspend );
\r
501 * <pre>void vTaskResume( xTaskHandle pxTaskToResume );</pre>
\r
503 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
\r
504 * See the configuration section for more information.
\r
506 * Resumes a suspended task.
\r
508 * A task that has been suspended by one of more calls to vTaskSuspend ()
\r
509 * will be made available for running again by a single call to
\r
512 * @param pxTaskToResume Handle to the task being readied.
\r
516 void vAFunction( void )
\r
518 xTaskHandle xHandle;
\r
520 // Create a task, storing the handle.
\r
521 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
525 // Use the handle to suspend the created task.
\r
526 vTaskSuspend( xHandle );
\r
530 // The created task will not run during this period, unless
\r
531 // another task calls vTaskResume( xHandle ).
\r
536 // Resume the suspended task ourselves.
\r
537 vTaskResume( xHandle );
\r
539 // The created task will once again get microcontroller processing
\r
540 // time in accordance with it priority within the system.
\r
543 * \defgroup vTaskResume vTaskResume
\r
544 * \ingroup TaskCtrl
\r
546 void vTaskResume( xTaskHandle pxTaskToResume );
\r
550 * <pre>void xTaskResumeFromISR( xTaskHandle pxTaskToResume );</pre>
\r
552 * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
\r
553 * available. See the configuration section for more information.
\r
555 * An implementation of vTaskResume() that can be called from within an ISR.
\r
557 * A task that has been suspended by one of more calls to vTaskSuspend ()
\r
558 * will be made available for running again by a single call to
\r
559 * xTaskResumeFromISR ().
\r
561 * @param pxTaskToResume Handle to the task being readied.
\r
563 * \defgroup vTaskResumeFromISR vTaskResumeFromISR
\r
564 * \ingroup TaskCtrl
\r
566 portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume );
\r
568 /*-----------------------------------------------------------
\r
569 * SCHEDULER CONTROL
\r
570 *----------------------------------------------------------*/
\r
574 * <pre>void vTaskStartScheduler( void );</pre>
\r
576 * Starts the real time kernel tick processing. After calling the kernel
\r
577 * has control over which tasks are executed and when. This function
\r
578 * does not return until an executing task calls vTaskEndScheduler ().
\r
580 * At least one task should be created via a call to xTaskCreate ()
\r
581 * before calling vTaskStartScheduler (). The idle task is created
\r
582 * automatically when the first application task is created.
\r
584 * See the demo application file main.c for an example of creating
\r
585 * tasks and starting the kernel.
\r
589 void vAFunction( void )
\r
591 // Create at least one task before starting the kernel.
\r
592 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
594 // Start the real time kernel with preemption.
\r
595 vTaskStartScheduler ();
\r
597 // Will not get here unless a task calls vTaskEndScheduler ()
\r
601 * \defgroup vTaskStartScheduler vTaskStartScheduler
\r
602 * \ingroup SchedulerControl
\r
604 void vTaskStartScheduler( void );
\r
608 * <pre>void vTaskEndScheduler( void );</pre>
\r
610 * Stops the real time kernel tick. All created tasks will be automatically
\r
611 * deleted and multitasking (either preemptive or cooperative) will
\r
612 * stop. Execution then resumes from the point where vTaskStartScheduler ()
\r
613 * was called, as if vTaskStartScheduler () had just returned.
\r
615 * See the demo application file main. c in the demo/PC directory for an
\r
616 * example that uses vTaskEndScheduler ().
\r
618 * vTaskEndScheduler () requires an exit function to be defined within the
\r
619 * portable layer (see vPortEndScheduler () in port. c for the PC port). This
\r
620 * performs hardware specific operations such as stopping the kernel tick.
\r
622 * vTaskEndScheduler () will cause all of the resources allocated by the
\r
623 * kernel to be freed - but will not free resources allocated by application
\r
628 void vTaskCode( void * pvParameters )
\r
632 // Task code goes here.
\r
634 // At some point we want to end the real time kernel processing
\r
636 vTaskEndScheduler ();
\r
640 void vAFunction( void )
\r
642 // Create at least one task before starting the kernel.
\r
643 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
645 // Start the real time kernel with preemption.
\r
646 vTaskStartScheduler ();
\r
648 // Will only get here when the vTaskCode () task has called
\r
649 // vTaskEndScheduler (). When we get here we are back to single task
\r
654 * \defgroup vTaskEndScheduler vTaskEndScheduler
\r
655 * \ingroup SchedulerControl
\r
657 void vTaskEndScheduler( void );
\r
661 * <pre>void vTaskSuspendAll( void );</pre>
\r
663 * Suspends all real time kernel activity while keeping interrupts (including the
\r
664 * kernel tick) enabled.
\r
666 * After calling vTaskSuspendAll () the calling task will continue to execute
\r
667 * without risk of being swapped out until a call to xTaskResumeAll () has been
\r
672 void vTask1( void * pvParameters )
\r
676 // Task code goes here.
\r
680 // At some point the task wants to perform a long operation during
\r
681 // which it does not want to get swapped out. It cannot use
\r
682 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
\r
683 // operation may cause interrupts to be missed - including the
\r
686 // Prevent the real time kernel swapping out the task.
\r
687 vTaskSuspendAll ();
\r
689 // Perform the operation here. There is no need to use critical
\r
690 // sections as we have all the microcontroller processing time.
\r
691 // During this time interrupts will still operate and the kernel
\r
692 // tick count will be maintained.
\r
696 // The operation is complete. Restart the kernel.
\r
701 * \defgroup vTaskSuspendAll vTaskSuspendAll
\r
702 * \ingroup SchedulerControl
\r
704 void vTaskSuspendAll( void );
\r
708 * <pre>portCHAR xTaskResumeAll( void );</pre>
\r
710 * Resumes real time kernel activity following a call to vTaskSuspendAll ().
\r
711 * After a call to vTaskSuspendAll () the kernel will take control of which
\r
712 * task is executing at any time.
\r
714 * @return If resuming the scheduler caused a context switch then pdTRUE is
\r
715 * returned, otherwise pdFALSE is returned.
\r
719 void vTask1( void * pvParameters )
\r
723 // Task code goes here.
\r
727 // At some point the task wants to perform a long operation during
\r
728 // which it does not want to get swapped out. It cannot use
\r
729 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
\r
730 // operation may cause interrupts to be missed - including the
\r
733 // Prevent the real time kernel swapping out the task.
\r
734 vTaskSuspendAll ();
\r
736 // Perform the operation here. There is no need to use critical
\r
737 // sections as we have all the microcontroller processing time.
\r
738 // During this time interrupts will still operate and the real
\r
739 // time kernel tick count will be maintained.
\r
743 // The operation is complete. Restart the kernel. We want to force
\r
744 // a context switch - but there is no point if resuming the scheduler
\r
745 // caused a context switch already.
\r
746 if( !xTaskResumeAll () )
\r
753 * \defgroup xTaskResumeAll xTaskResumeAll
\r
754 * \ingroup SchedulerControl
\r
756 signed portBASE_TYPE xTaskResumeAll( void );
\r
759 /*-----------------------------------------------------------
\r
761 *----------------------------------------------------------*/
\r
765 * <PRE>volatile portTickType xTaskGetTickCount( void );</PRE>
\r
767 * @return The count of ticks since vTaskStartScheduler was called.
\r
769 * \page xTaskGetTickCount xTaskGetTickCount
\r
770 * \ingroup TaskUtils
\r
772 portTickType xTaskGetTickCount( void );
\r
776 * <PRE>unsigned portSHORT uxTaskGetNumberOfTasks( void );</PRE>
\r
778 * @return The number of tasks that the real time kernel is currently managing.
\r
779 * This includes all ready, blocked and suspended tasks. A task that
\r
780 * has been deleted but not yet freed by the idle task will also be
\r
781 * included in the count.
\r
783 * \page uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
\r
784 * \ingroup TaskUtils
\r
786 unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void );
\r
790 * <PRE>void vTaskList( portCHAR *pcWriteBuffer );</PRE>
\r
792 * configUSE_TRACE_FACILITY, INCLUDE_vTaskDelete and INCLUDE_vTaskSuspend
\r
793 * must all be defined as 1 for this function to be available.
\r
794 * See the configuration section for more information.
\r
796 * NOTE: This function will disable interrupts for its duration. It is
\r
797 * not intended for normal application runtime use but as a debug aid.
\r
799 * Lists all the current tasks, along with their current state and stack
\r
800 * usage high water mark.
\r
802 * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
\r
805 * @param pcWriteBuffer A buffer into which the above mentioned details
\r
806 * will be written, in ascii form. This buffer is assumed to be large
\r
807 * enough to contain the generated report. Approximately 40 bytes per
\r
808 * task should be sufficient.
\r
810 * \page vTaskList vTaskList
\r
811 * \ingroup TaskUtils
\r
813 void vTaskList( signed portCHAR *pcWriteBuffer );
\r
817 * <PRE>void vTaskStartTrace( portCHAR * pcBuffer, unsigned portBASE_TYPE uxBufferSize );</PRE>
\r
819 * Starts a real time kernel activity trace. The trace logs the identity of
\r
820 * which task is running when.
\r
822 * The trace file is stored in binary format. A separate DOS utility called
\r
823 * convtrce.exe is used to convert this into a tab delimited text file which
\r
824 * can be viewed and plotted in a spread sheet.
\r
826 * @param pcBuffer The buffer into which the trace will be written.
\r
828 * @param ulBufferSize The size of pcBuffer in bytes. The trace will continue
\r
829 * until either the buffer in full, or ulTaskEndTrace () is called.
\r
831 * \page vTaskStartTrace vTaskStartTrace
\r
832 * \ingroup TaskUtils
\r
834 void vTaskStartTrace( signed portCHAR * pcBuffer, unsigned portLONG ulBufferSize );
\r
838 * <PRE>unsigned portLONG ulTaskEndTrace( void );</PRE>
\r
840 * Stops a kernel activity trace. See vTaskStartTrace ().
\r
842 * @return The number of bytes that have been written into the trace buffer.
\r
844 * \page usTaskEndTrace usTaskEndTrace
\r
845 * \ingroup TaskUtils
\r
847 unsigned portLONG ulTaskEndTrace( void );
\r
850 /*-----------------------------------------------------------
\r
851 * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
\r
852 *----------------------------------------------------------*/
\r
855 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
\r
856 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
\r
857 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
859 * Called from the real time kernel tick (either preemptive or cooperative),
\r
860 * this increments the tick count and checks if any tasks that are blocked
\r
861 * for a finite period required removing from a blocked list and placing on
\r
864 inline void vTaskIncrementTick( void );
\r
867 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
868 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
870 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
\r
872 * Removes the calling task from the ready list and places it both
\r
873 * on the list of tasks waiting for a particular event, and the
\r
874 * list of delayed tasks. The task will be removed from both lists
\r
875 * and replaced on the ready list should either the event occur (and
\r
876 * there be no higher priority tasks waiting on the same event) or
\r
877 * the delay period expires.
\r
879 * @param pxEventList The list containing tasks that are blocked waiting
\r
880 * for the event to occur.
\r
882 * @param xTicksToWait The maximum amount of time that the task should wait
\r
883 * for the event to occur. This is specified in kernel ticks,the constant
\r
884 * portTICK_RATE_MS can be used to convert kernel ticks into a real time
\r
887 void vTaskPlaceOnEventList( xList *pxEventList, portTickType xTicksToWait );
\r
890 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
891 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
893 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
\r
895 * Removes a task from both the specified event list and the list of blocked
\r
896 * tasks, and places it on a ready queue.
\r
898 * xTaskRemoveFromEventList () will be called if either an event occurs to
\r
899 * unblock a task, or the block timeout period expires.
\r
901 * @return pdTRUE if the task being removed has a higher priority than the task
\r
902 * making the call, otherwise pdFALSE.
\r
904 signed portBASE_TYPE xTaskRemoveFromEventList( const xList *pxEventList );
\r
907 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
908 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
910 * INCLUDE_vTaskCleanUpResources and INCLUDE_vTaskSuspend must be defined as 1
\r
911 * for this function to be available.
\r
912 * See the configuration section for more information.
\r
914 * Empties the ready and delayed queues of task control blocks, freeing the
\r
915 * memory allocated for the task control block and task stacks as it goes.
\r
917 void vTaskCleanUpResources( void );
\r
920 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
\r
921 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
\r
922 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
924 * Sets the pointer to the current TCB to the TCB of the highest priority task
\r
925 * that is ready to run.
\r
927 inline void vTaskSwitchContext( void );
\r
930 * Return the handle of the calling task.
\r
932 xTaskHandle xTaskGetCurrentTaskHandle( void );
\r
935 * Capture the current time status for future reference.
\r
937 void vTaskSetTimeOutState( xTimeOutType *pxTimeOut );
\r
940 * Compare the time status now with that previously captured to see if the
\r
941 * timeout has expired.
\r
943 portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType *pxTimeOut, portTickType *pxTicksToWait );
\r
946 * Shortcut used by the queue implementation to prevent unnecessary call to
\r
949 void vTaskMissedYield( void );
\r
951 #endif /* TASK_H */
\r