2 FreeRTOS.org V4.8.0 - 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! Why not get us to quote to get FreeRTOS.org *
\r
30 * running on your hardware - or even write all or part of your application*
\r
31 * for you? See http://www.OpenRTOS.com for details. *
\r
33 ***************************************************************************
\r
34 ***************************************************************************
\r
36 Please ensure to read the configuration and relevant port sections of the
\r
37 online documentation.
\r
39 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
42 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
45 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
46 licensing and training services.
\r
50 Changes since V4.3.1:
\r
52 + Added xTaskGetSchedulerState() function.
\r
58 #include "portable.h"
\r
64 /*-----------------------------------------------------------
\r
65 * MACROS AND DEFINITIONS
\r
66 *----------------------------------------------------------*/
\r
68 #define tskKERNEL_VERSION_NUMBER "V4.7.2"
\r
73 * Type by which tasks are referenced. For example, a call to xTaskCreate
\r
74 * returns (via a pointer parameter) an xTaskHandle variable that can then
\r
75 * be used as a parameter to vTaskDelete to delete the task.
\r
77 * \page xTaskHandle xTaskHandle
\r
80 typedef void * xTaskHandle;
\r
83 * Used internally only.
\r
85 typedef struct xTIME_OUT
\r
87 portBASE_TYPE xOverflowCount;
\r
88 portTickType xTimeOnEntering;
\r
92 * Defines the priority used by the idle task. This must not be modified.
\r
94 * \ingroup TaskUtils
\r
96 #define tskIDLE_PRIORITY ( ( unsigned portBASE_TYPE ) 0 )
\r
101 * Macro for forcing a context switch.
\r
103 * \page taskYIELD taskYIELD
\r
104 * \ingroup SchedulerControl
\r
106 #define taskYIELD() portYIELD()
\r
111 * Macro to mark the start of a critical code region. Preemptive context
\r
112 * switches cannot occur when in a critical region.
\r
114 * NOTE: This may alter the stack (depending on the portable implementation)
\r
115 * so must be used with care!
\r
117 * \page taskENTER_CRITICAL taskENTER_CRITICAL
\r
118 * \ingroup SchedulerControl
\r
120 #define taskENTER_CRITICAL() portENTER_CRITICAL()
\r
125 * Macro to mark the end of a critical code region. Preemptive context
\r
126 * switches cannot occur when in a critical region.
\r
128 * NOTE: This may alter the stack (depending on the portable implementation)
\r
129 * so must be used with care!
\r
131 * \page taskEXIT_CRITICAL taskEXIT_CRITICAL
\r
132 * \ingroup SchedulerControl
\r
134 #define taskEXIT_CRITICAL() portEXIT_CRITICAL()
\r
139 * Macro to disable all maskable interrupts.
\r
141 * \page taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
\r
142 * \ingroup SchedulerControl
\r
144 #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
\r
149 * Macro to enable microcontroller interrupts.
\r
151 * \page taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
\r
152 * \ingroup SchedulerControl
\r
154 #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
\r
156 /* Definitions returned by xTaskGetSchedulerState(). */
\r
157 #define taskSCHEDULER_NOT_STARTED 0
\r
158 #define taskSCHEDULER_RUNNING 1
\r
159 #define taskSCHEDULER_SUSPENDED 2
\r
161 /*-----------------------------------------------------------
\r
162 * TASK CREATION API
\r
163 *----------------------------------------------------------*/
\r
168 portBASE_TYPE xTaskCreate(
\r
169 pdTASK_CODE pvTaskCode,
\r
170 const portCHAR * const pcName,
\r
171 unsigned portSHORT usStackDepth,
\r
172 void *pvParameters,
\r
173 unsigned portBASE_TYPE uxPriority,
\r
174 xTaskHandle *pvCreatedTask
\r
177 * Create a new task and add it to the list of tasks that are ready to run.
\r
179 * @param pvTaskCode Pointer to the task entry function. Tasks
\r
180 * must be implemented to never return (i.e. continuous loop).
\r
182 * @param pcName A descriptive name for the task. This is mainly used to
\r
183 * facilitate debugging. Max length defined by tskMAX_TASK_NAME_LEN - default
\r
186 * @param usStackDepth The size of the task stack specified as the number of
\r
187 * variables the stack can hold - not the number of bytes. For example, if
\r
188 * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
\r
189 * will be allocated for stack storage.
\r
191 * @param pvParameters Pointer that will be used as the parameter for the task
\r
194 * @param uxPriority The priority at which the task should run.
\r
196 * @param pvCreatedTask Used to pass back a handle by which the created task
\r
197 * can be referenced.
\r
199 * @return pdPASS if the task was successfully created and added to a ready
\r
200 * list, otherwise an error code defined in the file errors. h
\r
204 // Task to be created.
\r
205 void vTaskCode( void * pvParameters )
\r
209 // Task code goes here.
\r
213 // Function that creates a task.
\r
214 void vOtherFunction( void )
\r
216 unsigned char ucParameterToPass;
\r
217 xTaskHandle xHandle;
\r
219 // Create the task, storing the handle.
\r
220 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
\r
222 // Use the handle to delete the task.
\r
223 vTaskDelete( xHandle );
\r
226 * \defgroup xTaskCreate xTaskCreate
\r
229 signed portBASE_TYPE xTaskCreate( pdTASK_CODE pvTaskCode, const signed portCHAR * const pcName, unsigned portSHORT usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pvCreatedTask );
\r
233 * <pre>void vTaskDelete( xTaskHandle pxTask );</pre>
\r
235 * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
\r
236 * See the configuration section for more information.
\r
238 * Remove a task from the RTOS real time kernels management. The task being
\r
239 * deleted will be removed from all ready, blocked, suspended and event lists.
\r
241 * NOTE: The idle task is responsible for freeing the kernel allocated
\r
242 * memory from tasks that have been deleted. It is therefore important that
\r
243 * the idle task is not starved of microcontroller processing time if your
\r
244 * application makes any calls to vTaskDelete (). Memory allocated by the
\r
245 * task code is not automatically freed, and should be freed before the task
\r
248 * See the demo application file death.c for sample code that utilises
\r
251 * @param pxTask The handle of the task to be deleted. Passing NULL will
\r
252 * cause the calling task to be deleted.
\r
256 void vOtherFunction( void )
\r
258 xTaskHandle xHandle;
\r
260 // Create the task, storing the handle.
\r
261 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
263 // Use the handle to delete the task.
\r
264 vTaskDelete( xHandle );
\r
267 * \defgroup vTaskDelete vTaskDelete
\r
270 void vTaskDelete( xTaskHandle pxTask );
\r
273 /*-----------------------------------------------------------
\r
275 *----------------------------------------------------------*/
\r
279 * <pre>void vTaskDelay( portTickType xTicksToDelay );</pre>
\r
281 * Delay a task for a given number of ticks. The actual time that the
\r
282 * task remains blocked depends on the tick rate. The constant
\r
283 * portTICK_RATE_MS can be used to calculate real time from the tick
\r
284 * rate - with the resolution of one tick period.
\r
286 * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
\r
287 * See the configuration section for more information.
\r
289 * @param xTicksToDelay The amount of time, in tick periods, that
\r
290 * the calling task should block.
\r
294 // Wait 10 ticks before performing an action.
\r
296 // This is for demonstration only and would be better achieved
\r
297 // using vTaskDelayUntil ().
\r
298 void vTaskFunction( void * pvParameters )
\r
300 portTickType xDelay, xNextTime;
\r
302 // Calc the time at which we want to perform the action
\r
304 xNextTime = xTaskGetTickCount () + ( portTickType ) 10;
\r
308 xDelay = xNextTime - xTaskGetTickCount ();
\r
309 xNextTime += ( portTickType ) 10;
\r
311 // Guard against overflow
\r
312 if( xDelay <= ( portTickType ) 10 )
\r
314 vTaskDelay( xDelay );
\r
317 // Perform action here.
\r
321 * \defgroup vTaskDelay vTaskDelay
\r
322 * \ingroup TaskCtrl
\r
324 void vTaskDelay( portTickType xTicksToDelay );
\r
328 * <pre>void vTaskDelayUntil( portTickType *pxPreviousWakeTime, portTickType xTimeIncrement );</pre>
\r
330 * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
\r
331 * See the configuration section for more information.
\r
333 * Delay a task until a specified time. This function can be used by cyclical
\r
334 * tasks to ensure a constant execution frequency.
\r
336 * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
\r
337 * cause a task to block for the specified number of ticks from the time vTaskDelay () is
\r
338 * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
\r
339 * execution frequency as the time between a task starting to execute and that task
\r
340 * calling vTaskDelay () may not be fixed [the task may take a different path though the
\r
341 * code between calls, or may get interrupted or preempted a different number of times
\r
342 * each time it executes].
\r
344 * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
\r
345 * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
\r
348 * The constant portTICK_RATE_MS can be used to calculate real time from the tick
\r
349 * rate - with the resolution of one tick period.
\r
351 * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
\r
352 * task was last unblocked. The variable must be initialised with the current time
\r
353 * prior to its first use (see the example below). Following this the variable is
\r
354 * automatically updated within vTaskDelayUntil ().
\r
356 * @param xTimeIncrement The cycle time period. The task will be unblocked at
\r
357 * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the
\r
358 * same xTimeIncrement parameter value will cause the task to execute with
\r
359 * a fixed interface period.
\r
363 // Perform an action every 10 ticks.
\r
364 void vTaskFunction( void * pvParameters )
\r
366 portTickType xLastWakeTime;
\r
367 const portTickType xFrequency = 10;
\r
369 // Initialise the xLastWakeTime variable with the current time.
\r
370 xLastWakeTime = xTaskGetTickCount ();
\r
373 // Wait for the next cycle.
\r
374 vTaskDelayUntil( &xLastWakeTime, xFrequency );
\r
376 // Perform action here.
\r
380 * \defgroup vTaskDelayUntil vTaskDelayUntil
\r
381 * \ingroup TaskCtrl
\r
383 void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement );
\r
387 * <pre>unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );</pre>
\r
389 * INCLUDE_xTaskPriorityGet must be defined as 1 for this function to be available.
\r
390 * See the configuration section for more information.
\r
392 * Obtain the priority of any task.
\r
394 * @param pxTask Handle of the task to be queried. Passing a NULL
\r
395 * handle results in the priority of the calling task being returned.
\r
397 * @return The priority of pxTask.
\r
401 void vAFunction( void )
\r
403 xTaskHandle xHandle;
\r
405 // Create a task, storing the handle.
\r
406 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
410 // Use the handle to obtain the priority of the created task.
\r
411 // It was created with tskIDLE_PRIORITY, but may have changed
\r
413 if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
\r
415 // The task has changed it's priority.
\r
420 // Is our priority higher than the created task?
\r
421 if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
\r
423 // Our priority (obtained using NULL handle) is higher.
\r
427 * \defgroup uxTaskPriorityGet uxTaskPriorityGet
\r
428 * \ingroup TaskCtrl
\r
430 unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );
\r
434 * <pre>void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );</pre>
\r
436 * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
\r
437 * See the configuration section for more information.
\r
439 * Set the priority of any task.
\r
441 * A context switch will occur before the function returns if the priority
\r
442 * being set is higher than the currently executing task.
\r
444 * @param pxTask Handle to the task for which the priority is being set.
\r
445 * Passing a NULL handle results in the priority of the calling task being set.
\r
447 * @param uxNewPriority The priority to which the task will be set.
\r
451 void vAFunction( void )
\r
453 xTaskHandle xHandle;
\r
455 // Create a task, storing the handle.
\r
456 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
460 // Use the handle to raise the priority of the created task.
\r
461 vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
\r
465 // Use a NULL handle to raise our priority to the same value.
\r
466 vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
\r
469 * \defgroup vTaskPrioritySet vTaskPrioritySet
\r
470 * \ingroup TaskCtrl
\r
472 void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );
\r
476 * <pre>void vTaskSuspend( xTaskHandle pxTaskToSuspend );</pre>
\r
478 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
\r
479 * See the configuration section for more information.
\r
481 * Suspend any task. When suspended a task will never get any microcontroller
\r
482 * processing time, no matter what its priority.
\r
484 * Calls to vTaskSuspend are not accumulative -
\r
485 * i.e. calling vTaskSuspend () twice on the same task still only requires one
\r
486 * call to vTaskResume () to ready the suspended task.
\r
488 * @param pxTaskToSuspend Handle to the task being suspended. Passing a NULL
\r
489 * handle will cause the calling task to be suspended.
\r
493 void vAFunction( void )
\r
495 xTaskHandle xHandle;
\r
497 // Create a task, storing the handle.
\r
498 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
502 // Use the handle to suspend the created task.
\r
503 vTaskSuspend( xHandle );
\r
507 // The created task will not run during this period, unless
\r
508 // another task calls vTaskResume( xHandle ).
\r
513 // Suspend ourselves.
\r
514 vTaskSuspend( NULL );
\r
516 // We cannot get here unless another task calls vTaskResume
\r
517 // with our handle as the parameter.
\r
520 * \defgroup vTaskSuspend vTaskSuspend
\r
521 * \ingroup TaskCtrl
\r
523 void vTaskSuspend( xTaskHandle pxTaskToSuspend );
\r
527 * <pre>void vTaskResume( xTaskHandle pxTaskToResume );</pre>
\r
529 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
\r
530 * See the configuration section for more information.
\r
532 * Resumes a suspended task.
\r
534 * A task that has been suspended by one of more calls to vTaskSuspend ()
\r
535 * will be made available for running again by a single call to
\r
538 * @param pxTaskToResume Handle to the task being readied.
\r
542 void vAFunction( void )
\r
544 xTaskHandle xHandle;
\r
546 // Create a task, storing the handle.
\r
547 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
551 // Use the handle to suspend the created task.
\r
552 vTaskSuspend( xHandle );
\r
556 // The created task will not run during this period, unless
\r
557 // another task calls vTaskResume( xHandle ).
\r
562 // Resume the suspended task ourselves.
\r
563 vTaskResume( xHandle );
\r
565 // The created task will once again get microcontroller processing
\r
566 // time in accordance with it priority within the system.
\r
569 * \defgroup vTaskResume vTaskResume
\r
570 * \ingroup TaskCtrl
\r
572 void vTaskResume( xTaskHandle pxTaskToResume );
\r
576 * <pre>void xTaskResumeFromISR( xTaskHandle pxTaskToResume );</pre>
\r
578 * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
\r
579 * available. See the configuration section for more information.
\r
581 * An implementation of vTaskResume() that can be called from within an ISR.
\r
583 * A task that has been suspended by one of more calls to vTaskSuspend ()
\r
584 * will be made available for running again by a single call to
\r
585 * xTaskResumeFromISR ().
\r
587 * @param pxTaskToResume Handle to the task being readied.
\r
589 * \defgroup vTaskResumeFromISR vTaskResumeFromISR
\r
590 * \ingroup TaskCtrl
\r
592 portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume );
\r
594 /*-----------------------------------------------------------
\r
595 * SCHEDULER CONTROL
\r
596 *----------------------------------------------------------*/
\r
600 * <pre>void vTaskStartScheduler( void );</pre>
\r
602 * Starts the real time kernel tick processing. After calling the kernel
\r
603 * has control over which tasks are executed and when. This function
\r
604 * does not return until an executing task calls vTaskEndScheduler ().
\r
606 * At least one task should be created via a call to xTaskCreate ()
\r
607 * before calling vTaskStartScheduler (). The idle task is created
\r
608 * automatically when the first application task is created.
\r
610 * See the demo application file main.c for an example of creating
\r
611 * tasks and starting the kernel.
\r
615 void vAFunction( void )
\r
617 // Create at least one task before starting the kernel.
\r
618 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
620 // Start the real time kernel with preemption.
\r
621 vTaskStartScheduler ();
\r
623 // Will not get here unless a task calls vTaskEndScheduler ()
\r
627 * \defgroup vTaskStartScheduler vTaskStartScheduler
\r
628 * \ingroup SchedulerControl
\r
630 void vTaskStartScheduler( void );
\r
634 * <pre>void vTaskEndScheduler( void );</pre>
\r
636 * Stops the real time kernel tick. All created tasks will be automatically
\r
637 * deleted and multitasking (either preemptive or cooperative) will
\r
638 * stop. Execution then resumes from the point where vTaskStartScheduler ()
\r
639 * was called, as if vTaskStartScheduler () had just returned.
\r
641 * See the demo application file main. c in the demo/PC directory for an
\r
642 * example that uses vTaskEndScheduler ().
\r
644 * vTaskEndScheduler () requires an exit function to be defined within the
\r
645 * portable layer (see vPortEndScheduler () in port. c for the PC port). This
\r
646 * performs hardware specific operations such as stopping the kernel tick.
\r
648 * vTaskEndScheduler () will cause all of the resources allocated by the
\r
649 * kernel to be freed - but will not free resources allocated by application
\r
654 void vTaskCode( void * pvParameters )
\r
658 // Task code goes here.
\r
660 // At some point we want to end the real time kernel processing
\r
662 vTaskEndScheduler ();
\r
666 void vAFunction( void )
\r
668 // Create at least one task before starting the kernel.
\r
669 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
671 // Start the real time kernel with preemption.
\r
672 vTaskStartScheduler ();
\r
674 // Will only get here when the vTaskCode () task has called
\r
675 // vTaskEndScheduler (). When we get here we are back to single task
\r
680 * \defgroup vTaskEndScheduler vTaskEndScheduler
\r
681 * \ingroup SchedulerControl
\r
683 void vTaskEndScheduler( void );
\r
687 * <pre>void vTaskSuspendAll( void );</pre>
\r
689 * Suspends all real time kernel activity while keeping interrupts (including the
\r
690 * kernel tick) enabled.
\r
692 * After calling vTaskSuspendAll () the calling task will continue to execute
\r
693 * without risk of being swapped out until a call to xTaskResumeAll () has been
\r
698 void vTask1( void * pvParameters )
\r
702 // Task code goes here.
\r
706 // At some point the task wants to perform a long operation during
\r
707 // which it does not want to get swapped out. It cannot use
\r
708 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
\r
709 // operation may cause interrupts to be missed - including the
\r
712 // Prevent the real time kernel swapping out the task.
\r
713 vTaskSuspendAll ();
\r
715 // Perform the operation here. There is no need to use critical
\r
716 // sections as we have all the microcontroller processing time.
\r
717 // During this time interrupts will still operate and the kernel
\r
718 // tick count will be maintained.
\r
722 // The operation is complete. Restart the kernel.
\r
727 * \defgroup vTaskSuspendAll vTaskSuspendAll
\r
728 * \ingroup SchedulerControl
\r
730 void vTaskSuspendAll( void );
\r
734 * <pre>portCHAR xTaskResumeAll( void );</pre>
\r
736 * Resumes real time kernel activity following a call to vTaskSuspendAll ().
\r
737 * After a call to vTaskSuspendAll () the kernel will take control of which
\r
738 * task is executing at any time.
\r
740 * @return If resuming the scheduler caused a context switch then pdTRUE is
\r
741 * returned, otherwise pdFALSE is returned.
\r
745 void vTask1( void * pvParameters )
\r
749 // Task code goes here.
\r
753 // At some point the task wants to perform a long operation during
\r
754 // which it does not want to get swapped out. It cannot use
\r
755 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
\r
756 // operation may cause interrupts to be missed - including the
\r
759 // Prevent the real time kernel swapping out the task.
\r
760 vTaskSuspendAll ();
\r
762 // Perform the operation here. There is no need to use critical
\r
763 // sections as we have all the microcontroller processing time.
\r
764 // During this time interrupts will still operate and the real
\r
765 // time kernel tick count will be maintained.
\r
769 // The operation is complete. Restart the kernel. We want to force
\r
770 // a context switch - but there is no point if resuming the scheduler
\r
771 // caused a context switch already.
\r
772 if( !xTaskResumeAll () )
\r
779 * \defgroup xTaskResumeAll xTaskResumeAll
\r
780 * \ingroup SchedulerControl
\r
782 signed portBASE_TYPE xTaskResumeAll( void );
\r
785 /*-----------------------------------------------------------
\r
787 *----------------------------------------------------------*/
\r
791 * <PRE>volatile portTickType xTaskGetTickCount( void );</PRE>
\r
793 * @return The count of ticks since vTaskStartScheduler was called.
\r
795 * \page xTaskGetTickCount xTaskGetTickCount
\r
796 * \ingroup TaskUtils
\r
798 portTickType xTaskGetTickCount( void );
\r
802 * <PRE>unsigned portSHORT uxTaskGetNumberOfTasks( void );</PRE>
\r
804 * @return The number of tasks that the real time kernel is currently managing.
\r
805 * This includes all ready, blocked and suspended tasks. A task that
\r
806 * has been deleted but not yet freed by the idle task will also be
\r
807 * included in the count.
\r
809 * \page uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
\r
810 * \ingroup TaskUtils
\r
812 unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void );
\r
816 * <PRE>void vTaskList( portCHAR *pcWriteBuffer );</PRE>
\r
818 * configUSE_TRACE_FACILITY, INCLUDE_vTaskDelete and INCLUDE_vTaskSuspend
\r
819 * must all be defined as 1 for this function to be available.
\r
820 * See the configuration section for more information.
\r
822 * NOTE: This function will disable interrupts for its duration. It is
\r
823 * not intended for normal application runtime use but as a debug aid.
\r
825 * Lists all the current tasks, along with their current state and stack
\r
826 * usage high water mark.
\r
828 * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
\r
831 * @param pcWriteBuffer A buffer into which the above mentioned details
\r
832 * will be written, in ascii form. This buffer is assumed to be large
\r
833 * enough to contain the generated report. Approximately 40 bytes per
\r
834 * task should be sufficient.
\r
836 * \page vTaskList vTaskList
\r
837 * \ingroup TaskUtils
\r
839 void vTaskList( signed portCHAR *pcWriteBuffer );
\r
843 * <PRE>void vTaskStartTrace( portCHAR * pcBuffer, unsigned portBASE_TYPE uxBufferSize );</PRE>
\r
845 * Starts a real time kernel activity trace. The trace logs the identity of
\r
846 * which task is running when.
\r
848 * The trace file is stored in binary format. A separate DOS utility called
\r
849 * convtrce.exe is used to convert this into a tab delimited text file which
\r
850 * can be viewed and plotted in a spread sheet.
\r
852 * @param pcBuffer The buffer into which the trace will be written.
\r
854 * @param ulBufferSize The size of pcBuffer in bytes. The trace will continue
\r
855 * until either the buffer in full, or ulTaskEndTrace () is called.
\r
857 * \page vTaskStartTrace vTaskStartTrace
\r
858 * \ingroup TaskUtils
\r
860 void vTaskStartTrace( signed portCHAR * pcBuffer, unsigned portLONG ulBufferSize );
\r
864 * <PRE>unsigned portLONG ulTaskEndTrace( void );</PRE>
\r
866 * Stops a kernel activity trace. See vTaskStartTrace ().
\r
868 * @return The number of bytes that have been written into the trace buffer.
\r
870 * \page usTaskEndTrace usTaskEndTrace
\r
871 * \ingroup TaskUtils
\r
873 unsigned portLONG ulTaskEndTrace( void );
\r
877 * <PRE>unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );</PRE>
\r
879 * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
\r
880 * this function to be available.
\r
882 * Returns the high water mark of the stack associated with xTask. That is,
\r
883 * the minimum free stack space there has been (in bytes) since the task
\r
884 * started. The smaller the returned number the closer the task has come
\r
885 * to overflowing its stack.
\r
887 * @param xTask Handle of the task associated with the stack to be checked.
\r
888 * Set xTask to NULL to check the stack of the calling task.
\r
890 * @return The smallest amount of free stack space there has been (in bytes)
\r
891 * since the task referenced by xTask was created.
\r
893 unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );
\r
895 /*-----------------------------------------------------------
\r
896 * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
\r
897 *----------------------------------------------------------*/
\r
900 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
\r
901 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
\r
902 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
904 * Called from the real time kernel tick (either preemptive or cooperative),
\r
905 * this increments the tick count and checks if any tasks that are blocked
\r
906 * for a finite period required removing from a blocked list and placing on
\r
909 inline void vTaskIncrementTick( void );
\r
912 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
913 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
915 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
\r
917 * Removes the calling task from the ready list and places it both
\r
918 * on the list of tasks waiting for a particular event, and the
\r
919 * list of delayed tasks. The task will be removed from both lists
\r
920 * and replaced on the ready list should either the event occur (and
\r
921 * there be no higher priority tasks waiting on the same event) or
\r
922 * the delay period expires.
\r
924 * @param pxEventList The list containing tasks that are blocked waiting
\r
925 * for the event to occur.
\r
927 * @param xTicksToWait The maximum amount of time that the task should wait
\r
928 * for the event to occur. This is specified in kernel ticks,the constant
\r
929 * portTICK_RATE_MS can be used to convert kernel ticks into a real time
\r
932 void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicksToWait );
\r
935 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
936 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
938 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
\r
940 * Removes a task from both the specified event list and the list of blocked
\r
941 * tasks, and places it on a ready queue.
\r
943 * xTaskRemoveFromEventList () will be called if either an event occurs to
\r
944 * unblock a task, or the block timeout period expires.
\r
946 * @return pdTRUE if the task being removed has a higher priority than the task
\r
947 * making the call, otherwise pdFALSE.
\r
949 signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList );
\r
952 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
953 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
955 * INCLUDE_vTaskCleanUpResources and INCLUDE_vTaskSuspend must be defined as 1
\r
956 * for this function to be available.
\r
957 * See the configuration section for more information.
\r
959 * Empties the ready and delayed queues of task control blocks, freeing the
\r
960 * memory allocated for the task control block and task stacks as it goes.
\r
962 void vTaskCleanUpResources( void );
\r
965 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
\r
966 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
\r
967 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
969 * Sets the pointer to the current TCB to the TCB of the highest priority task
\r
970 * that is ready to run.
\r
972 inline void vTaskSwitchContext( void );
\r
975 * Return the handle of the calling task.
\r
977 xTaskHandle xTaskGetCurrentTaskHandle( void );
\r
980 * Capture the current time status for future reference.
\r
982 void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut );
\r
985 * Compare the time status now with that previously captured to see if the
\r
986 * timeout has expired.
\r
988 portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType * const pxTicksToWait );
\r
991 * Shortcut used by the queue implementation to prevent unnecessary call to
\r
994 void vTaskMissedYield( void );
\r
997 * Returns the scheduler state as taskSCHEDULER_RUNNING,
\r
998 * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
\r
1000 portBASE_TYPE xTaskGetSchedulerState( void );
\r
1003 * Raises the priority of the mutex holder to that of the calling task should
\r
1004 * the mutex holder have a priority less than the calling task.
\r
1006 void vTaskPriorityInherit( xTaskHandle * const pxMutexHolder );
\r
1009 * Set the priority of a task back to its proper priority in the case that it
\r
1010 * inherited a higher priority while it was holding a semaphore.
\r
1012 void vTaskPriorityDisinherit( xTaskHandle * const pxMutexHolder );
\r
1014 #ifdef __cplusplus
\r
1017 #endif /* TASK_H */
\r