root/Examples_CP-JR_ARM7_LPC2368/FreeRTOS_Book/Source-Code-For-Examples/FreeRTOS_Source/include/task.h

Revision 36, 35.2 kB (checked in by phil, 15 years ago)

added purchased FreeRTOS book

Line 
1 /*
2         FreeRTOS.org V5.0.4 - Copyright (C) 2003-2008 Richard Barry.
3
4         This file is part of the FreeRTOS.org distribution.
5
6         FreeRTOS.org is free software; you can redistribute it and/or modify
7         it under the terms of the GNU General Public License as published by
8         the Free Software Foundation; either version 2 of the License, or
9         (at your option) any later version.
10
11         FreeRTOS.org is distributed in the hope that it will be useful,
12         but WITHOUT ANY WARRANTY; without even the implied warranty of
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14         GNU General Public License for more details.
15
16         You should have received a copy of the GNU General Public License
17         along with FreeRTOS.org; if not, write to the Free Software
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20         A special exception to the GPL can be applied should you wish to distribute
21         a combined work that includes FreeRTOS.org, without being obliged to provide
22         the source code for any proprietary components.  See the licensing section
23         of http://www.FreeRTOS.org for full details of how and when the exception
24         can be applied.
25
26     ***************************************************************************
27     ***************************************************************************
28     *                                                                         *
29     * SAVE TIME AND MONEY!  We can port FreeRTOS.org to your own hardware,    *
30     * and even write all or part of your application on your behalf.          *
31     * See http://www.OpenRTOS.com for details of the services we provide to   *
32     * expedite your project.                                                  *
33     *                                                                         *
34     ***************************************************************************
35     ***************************************************************************
36
37         Please ensure to read the configuration and relevant port sections of the
38         online documentation.
39
40         http://www.FreeRTOS.org - Documentation, latest information, license and
41         contact details.
42
43         http://www.SafeRTOS.com - A version that is certified for use in safety
44         critical systems.
45
46         http://www.OpenRTOS.com - Commercial support, development, porting,
47         licensing and training services.
48 */
49
50
51 #ifndef INC_FREERTOS_H
52         #error "#include FreeRTOS.h" must appear in source files before "#include task.h"
53 #endif
54
55
56
57 #ifndef TASK_H
58 #define TASK_H
59
60 #include "portable.h"
61 #include "list.h"
62
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 /*-----------------------------------------------------------
67  * MACROS AND DEFINITIONS
68  *----------------------------------------------------------*/
69
70 #define tskKERNEL_VERSION_NUMBER "V5.0.4"
71
72 /**
73  * task. h
74  *
75  * Type by which tasks are referenced.  For example, a call to xTaskCreate
76  * returns (via a pointer parameter) an xTaskHandle variable that can then
77  * be used as a parameter to vTaskDelete to delete the task.
78  *
79  * \page xTaskHandle xTaskHandle
80  * \ingroup Tasks
81  */
82 typedef void * xTaskHandle;
83
84 /*
85  * Used internally only.
86  */
87 typedef struct xTIME_OUT
88 {
89     portBASE_TYPE xOverflowCount;
90     portTickType  xTimeOnEntering;
91 } xTimeOutType;
92
93 /*
94  * Defines the priority used by the idle task.  This must not be modified.
95  *
96  * \ingroup TaskUtils
97  */
98 #define tskIDLE_PRIORITY                        ( ( unsigned portBASE_TYPE ) 0 )
99
100 /**
101  * task. h
102  *
103  * Macro for forcing a context switch.
104  *
105  * \page taskYIELD taskYIELD
106  * \ingroup SchedulerControl
107  */
108 #define taskYIELD()                                     portYIELD()
109
110 /**
111  * task. h
112  *
113  * Macro to mark the start of a critical code region.  Preemptive context
114  * switches cannot occur when in a critical region.
115  *
116  * NOTE: This may alter the stack (depending on the portable implementation)
117  * so must be used with care!
118  *
119  * \page taskENTER_CRITICAL taskENTER_CRITICAL
120  * \ingroup SchedulerControl
121  */
122 #define taskENTER_CRITICAL()            portENTER_CRITICAL()
123
124 /**
125  * task. h
126  *
127  * Macro to mark the end of a critical code region.  Preemptive context
128  * switches cannot occur when in a critical region.
129  *
130  * NOTE: This may alter the stack (depending on the portable implementation)
131  * so must be used with care!
132  *
133  * \page taskEXIT_CRITICAL taskEXIT_CRITICAL
134  * \ingroup SchedulerControl
135  */
136 #define taskEXIT_CRITICAL()                     portEXIT_CRITICAL()
137
138 /**
139  * task. h
140  *
141  * Macro to disable all maskable interrupts.
142  *
143  * \page taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
144  * \ingroup SchedulerControl
145  */
146 #define taskDISABLE_INTERRUPTS()        portDISABLE_INTERRUPTS()
147
148 /**
149  * task. h
150  *
151  * Macro to enable microcontroller interrupts.
152  *
153  * \page taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
154  * \ingroup SchedulerControl
155  */
156 #define taskENABLE_INTERRUPTS()         portENABLE_INTERRUPTS()
157
158 /* Definitions returned by xTaskGetSchedulerState(). */
159 #define taskSCHEDULER_NOT_STARTED       0
160 #define taskSCHEDULER_RUNNING           1
161 #define taskSCHEDULER_SUSPENDED         2
162
163 /*-----------------------------------------------------------
164  * TASK CREATION API
165  *----------------------------------------------------------*/
166
167 /**
168  * task. h
169  *<pre>
170  portBASE_TYPE xTaskCreate(
171                               pdTASK_CODE pvTaskCode,
172                               const portCHAR * const pcName,
173                               unsigned portSHORT usStackDepth,
174                               void *pvParameters,
175                               unsigned portBASE_TYPE uxPriority,
176                               xTaskHandle *pvCreatedTask
177                           );</pre>
178  *
179  * Create a new task and add it to the list of tasks that are ready to run.
180  *
181  * @param pvTaskCode Pointer to the task entry function.  Tasks
182  * must be implemented to never return (i.e. continuous loop).
183  *
184  * @param pcName A descriptive name for the task.  This is mainly used to
185  * facilitate debugging.  Max length defined by tskMAX_TASK_NAME_LEN - default
186  * is 16.
187  *
188  * @param usStackDepth The size of the task stack specified as the number of
189  * variables the stack can hold - not the number of bytes.  For example, if
190  * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
191  * will be allocated for stack storage.
192  *
193  * @param pvParameters Pointer that will be used as the parameter for the task
194  * being created.
195  *
196  * @param uxPriority The priority at which the task should run.
197  *
198  * @param pvCreatedTask Used to pass back a handle by which the created task
199  * can be referenced.
200  *
201  * @return pdPASS if the task was successfully created and added to a ready
202  * list, otherwise an error code defined in the file errors. h
203  *
204  * Example usage:
205    <pre>
206  // Task to be created.
207  void vTaskCode( void * pvParameters )
208  {
209      for( ;; )
210      {
211          // Task code goes here.
212      }
213  }
214
215  // Function that creates a task.
216  void vOtherFunction( void )
217  {
218  static unsigned char ucParameterToPass;
219  xTaskHandle xHandle;
220                
221      // Create the task, storing the handle.  Note that the passed parameter ucParameterToPass
222      // must exist for the lifetime of the task, so in this case is declared static.  If it was just an
223      // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
224      // the new time attempts to access it.
225      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
226                
227      // Use the handle to delete the task.
228      vTaskDelete( xHandle );
229  }
230    </pre>
231  * \defgroup xTaskCreate xTaskCreate
232  * \ingroup Tasks
233  */
234 signed portBASE_TYPE xTaskCreate( pdTASK_CODE pvTaskCode, const signed portCHAR * const pcName, unsigned portSHORT usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pvCreatedTask );
235
236 /**
237  * task. h
238  * <pre>void vTaskDelete( xTaskHandle pxTask );</pre>
239  *
240  * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
241  * See the configuration section for more information.
242  *
243  * Remove a task from the RTOS real time kernels management.  The task being
244  * deleted will be removed from all ready, blocked, suspended and event lists.
245  *
246  * NOTE:  The idle task is responsible for freeing the kernel allocated
247  * memory from tasks that have been deleted.  It is therefore important that
248  * the idle task is not starved of microcontroller processing time if your
249  * application makes any calls to vTaskDelete ().  Memory allocated by the
250  * task code is not automatically freed, and should be freed before the task
251  * is deleted.
252  *
253  * See the demo application file death.c for sample code that utilises
254  * vTaskDelete ().
255  *
256  * @param pxTask The handle of the task to be deleted.  Passing NULL will
257  * cause the calling task to be deleted.
258  *
259  * Example usage:
260    <pre>
261  void vOtherFunction( void )
262  {
263  xTaskHandle xHandle;
264                
265      // Create the task, storing the handle.
266      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
267                
268      // Use the handle to delete the task.
269      vTaskDelete( xHandle );
270  }
271    </pre>
272  * \defgroup vTaskDelete vTaskDelete
273  * \ingroup Tasks
274  */
275 void vTaskDelete( xTaskHandle pxTask );
276
277
278 /*-----------------------------------------------------------
279  * TASK CONTROL API
280  *----------------------------------------------------------*/
281
282 /**
283  * task. h
284  * <pre>void vTaskDelay( portTickType xTicksToDelay );</pre>
285  *
286  * Delay a task for a given number of ticks.  The actual time that the
287  * task remains blocked depends on the tick rate.  The constant
288  * portTICK_RATE_MS can be used to calculate real time from the tick
289  * rate - with the resolution of one tick period.
290  *
291  * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
292  * See the configuration section for more information.
293  *
294  *
295  * vTaskDelay() specifies a time at which the task wishes to unblock relative to
296  * the time at which vTaskDelay() is called.  For example, specifying a block
297  * period of 100 ticks will cause the task to unblock 100 ticks after
298  * vTaskDelay() is called.  vTaskDelay() does not therefore provide a good method
299  * of controlling the frequency of a cyclical task as the path taken through the
300  * code, as well as other task and interrupt activity, will effect the frequency
301  * at which vTaskDelay() gets called and therefore the time at which the task
302  * next executes.  See vTaskDelayUntil() for an alternative API function designed
303  * to facilitate fixed frequency execution.  It does this by specifying an
304  * absolute time (rather than a relative time) at which the calling task should
305  * unblock.
306  *
307  * @param xTicksToDelay The amount of time, in tick periods, that
308  * the calling task should block.
309  *
310  * Example usage:
311
312  void vTaskFunction( void * pvParameters )
313  {
314  void vTaskFunction( void * pvParameters )
315  {
316  // Block for 500ms.
317  const portTickType xDelay = 500 / portTICK_RATE_MS;
318
319      for( ;; )
320      {
321          // Simply toggle the LED every 500ms, blocking between each toggle.
322          vToggleLED();
323          vTaskDelay( xDelay );
324      }
325  }
326
327  * \defgroup vTaskDelay vTaskDelay
328  * \ingroup TaskCtrl
329  */
330 void vTaskDelay( portTickType xTicksToDelay );
331
332 /**
333  * task. h
334  * <pre>void vTaskDelayUntil( portTickType *pxPreviousWakeTime, portTickType xTimeIncrement );</pre>
335  *
336  * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
337  * See the configuration section for more information.
338  *
339  * Delay a task until a specified time.  This function can be used by cyclical
340  * tasks to ensure a constant execution frequency.
341  *
342  * This function differs from vTaskDelay () in one important aspect:  vTaskDelay () will
343  * cause a task to block for the specified number of ticks from the time vTaskDelay () is
344  * called.  It is therefore difficult to use vTaskDelay () by itself to generate a fixed
345  * execution frequency as the time between a task starting to execute and that task
346  * calling vTaskDelay () may not be fixed [the task may take a different path though the
347  * code between calls, or may get interrupted or preempted a different number of times
348  * each time it executes].
349  *
350  * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
351  * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
352  * unblock.
353  *
354  * The constant portTICK_RATE_MS can be used to calculate real time from the tick
355  * rate - with the resolution of one tick period.
356  *
357  * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
358  * task was last unblocked.  The variable must be initialised with the current time
359  * prior to its first use (see the example below).  Following this the variable is
360  * automatically updated within vTaskDelayUntil ().
361  *
362  * @param xTimeIncrement The cycle time period.  The task will be unblocked at
363  * time *pxPreviousWakeTime + xTimeIncrement.  Calling vTaskDelayUntil with the
364  * same xTimeIncrement parameter value will cause the task to execute with
365  * a fixed interface period.
366  *
367  * Example usage:
368    <pre>
369  // Perform an action every 10 ticks.
370  void vTaskFunction( void * pvParameters )
371  {
372  portTickType xLastWakeTime;
373  const portTickType xFrequency = 10;
374
375      // Initialise the xLastWakeTime variable with the current time.
376      xLastWakeTime = xTaskGetTickCount ();
377      for( ;; )
378      {
379          // Wait for the next cycle.
380          vTaskDelayUntil( &xLastWakeTime, xFrequency );
381
382          // Perform action here.
383      }
384  }
385    </pre>
386  * \defgroup vTaskDelayUntil vTaskDelayUntil
387  * \ingroup TaskCtrl
388  */
389 void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement );
390
391 /**
392  * task. h
393  * <pre>unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );</pre>
394  *
395  * INCLUDE_xTaskPriorityGet must be defined as 1 for this function to be available.
396  * See the configuration section for more information.
397  *
398  * Obtain the priority of any task.
399  *
400  * @param pxTask Handle of the task to be queried.  Passing a NULL
401  * handle results in the priority of the calling task being returned.
402  *
403  * @return The priority of pxTask.
404  *
405  * Example usage:
406    <pre>
407  void vAFunction( void )
408  {
409  xTaskHandle xHandle;
410                
411      // Create a task, storing the handle.
412      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
413                
414      // ...
415
416      // Use the handle to obtain the priority of the created task.
417      // It was created with tskIDLE_PRIORITY, but may have changed
418      // it itself.
419      if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
420      {
421          // The task has changed it's priority.
422      }
423
424      // ...
425
426      // Is our priority higher than the created task?
427      if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
428      {
429          // Our priority (obtained using NULL handle) is higher.
430      }
431  }
432    </pre>
433  * \defgroup uxTaskPriorityGet uxTaskPriorityGet
434  * \ingroup TaskCtrl
435  */
436 unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );
437
438 /**
439  * task. h
440  * <pre>void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );</pre>
441  *
442  * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
443  * See the configuration section for more information.
444  *
445  * Set the priority of any task.
446  *
447  * A context switch will occur before the function returns if the priority
448  * being set is higher than the currently executing task.
449  *
450  * @param pxTask Handle to the task for which the priority is being set.
451  * Passing a NULL handle results in the priority of the calling task being set.
452  *
453  * @param uxNewPriority The priority to which the task will be set.
454  *
455  * Example usage:
456    <pre>
457  void vAFunction( void )
458  {
459  xTaskHandle xHandle;
460                
461      // Create a task, storing the handle.
462      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
463
464      // ...
465
466      // Use the handle to raise the priority of the created task.
467      vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
468
469      // ...
470
471      // Use a NULL handle to raise our priority to the same value.
472      vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
473  }
474    </pre>
475  * \defgroup vTaskPrioritySet vTaskPrioritySet
476  * \ingroup TaskCtrl
477  */
478 void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );
479
480 /**
481  * task. h
482  * <pre>void vTaskSuspend( xTaskHandle pxTaskToSuspend );</pre>
483  *
484  * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
485  * See the configuration section for more information.
486  *
487  * Suspend any task.  When suspended a task will never get any microcontroller
488  * processing time, no matter what its priority.
489  *
490  * Calls to vTaskSuspend are not accumulative -
491  * i.e. calling vTaskSuspend () twice on the same task still only requires one
492  * call to vTaskResume () to ready the suspended task.
493  *
494  * @param pxTaskToSuspend Handle to the task being suspended.  Passing a NULL
495  * handle will cause the calling task to be suspended.
496  *
497  * Example usage:
498    <pre>
499  void vAFunction( void )
500  {
501  xTaskHandle xHandle;
502                
503      // Create a task, storing the handle.
504      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
505                
506      // ...
507
508      // Use the handle to suspend the created task.
509      vTaskSuspend( xHandle );
510
511      // ...
512                
513      // The created task will not run during this period, unless
514      // another task calls vTaskResume( xHandle ).
515                
516      //...
517                
518
519      // Suspend ourselves.
520      vTaskSuspend( NULL );
521
522      // We cannot get here unless another task calls vTaskResume
523      // with our handle as the parameter.
524  }
525    </pre>
526  * \defgroup vTaskSuspend vTaskSuspend
527  * \ingroup TaskCtrl
528  */
529 void vTaskSuspend( xTaskHandle pxTaskToSuspend );
530
531 /**
532  * task. h
533  * <pre>void vTaskResume( xTaskHandle pxTaskToResume );</pre>
534  *
535  * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
536  * See the configuration section for more information.
537  *
538  * Resumes a suspended task.
539  *
540  * A task that has been suspended by one of more calls to vTaskSuspend ()
541  * will be made available for running again by a single call to
542  * vTaskResume ().
543  *
544  * @param pxTaskToResume Handle to the task being readied.
545  *
546  * Example usage:
547    <pre>
548  void vAFunction( void )
549  {
550  xTaskHandle xHandle;
551                
552      // Create a task, storing the handle.
553      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
554                
555      // ...
556
557      // Use the handle to suspend the created task.
558      vTaskSuspend( xHandle );
559
560      // ...
561        
562      // The created task will not run during this period, unless
563      // another task calls vTaskResume( xHandle ).
564                
565      //...
566                
567
568      // Resume the suspended task ourselves.
569      vTaskResume( xHandle );
570
571      // The created task will once again get microcontroller processing
572      // time in accordance with it priority within the system.
573  }
574    </pre>
575  * \defgroup vTaskResume vTaskResume
576  * \ingroup TaskCtrl
577  */
578 void vTaskResume( xTaskHandle pxTaskToResume );
579
580 /**
581  * task. h
582  * <pre>void xTaskResumeFromISR( xTaskHandle pxTaskToResume );</pre>
583  *
584  * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
585  * available.  See the configuration section for more information.
586  *
587  * An implementation of vTaskResume() that can be called from within an ISR.
588  *
589  * A task that has been suspended by one of more calls to vTaskSuspend ()
590  * will be made available for running again by a single call to
591  * xTaskResumeFromISR ().
592  *
593  * @param pxTaskToResume Handle to the task being readied.
594  *
595  * \defgroup vTaskResumeFromISR vTaskResumeFromISR
596  * \ingroup TaskCtrl
597  */
598 portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume );
599
600 /*-----------------------------------------------------------
601  * SCHEDULER CONTROL
602  *----------------------------------------------------------*/
603
604 /**
605  * task. h
606  * <pre>void vTaskStartScheduler( void );</pre>
607  *
608  * Starts the real time kernel tick processing.  After calling the kernel
609  * has control over which tasks are executed and when.  This function
610  * does not return until an executing task calls vTaskEndScheduler ().
611  *
612  * At least one task should be created via a call to xTaskCreate ()
613  * before calling vTaskStartScheduler ().  The idle task is created
614  * automatically when the first application task is created.
615  *
616  * See the demo application file main.c for an example of creating
617  * tasks and starting the kernel.
618  *
619  * Example usage:
620    <pre>
621  void vAFunction( void )
622  {
623      // Create at least one task before starting the kernel.
624      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
625
626      // Start the real time kernel with preemption.
627      vTaskStartScheduler ();
628
629      // Will not get here unless a task calls vTaskEndScheduler ()
630  }
631    </pre>
632  *
633  * \defgroup vTaskStartScheduler vTaskStartScheduler
634  * \ingroup SchedulerControl
635  */
636 void vTaskStartScheduler( void );
637
638 /**
639  * task. h
640  * <pre>void vTaskEndScheduler( void );</pre>
641  *
642  * Stops the real time kernel tick.  All created tasks will be automatically
643  * deleted and multitasking (either preemptive or cooperative) will
644  * stop.  Execution then resumes from the point where vTaskStartScheduler ()
645  * was called, as if vTaskStartScheduler () had just returned.
646  *
647  * See the demo application file main. c in the demo/PC directory for an
648  * example that uses vTaskEndScheduler ().
649  *
650  * vTaskEndScheduler () requires an exit function to be defined within the
651  * portable layer (see vPortEndScheduler () in port. c for the PC port).  This
652  * performs hardware specific operations such as stopping the kernel tick.
653  *
654  * vTaskEndScheduler () will cause all of the resources allocated by the
655  * kernel to be freed - but will not free resources allocated by application
656  * tasks.
657  *
658  * Example usage:
659    <pre>
660  void vTaskCode( void * pvParameters )
661  {
662      for( ;; )
663      {
664          // Task code goes here.
665
666          // At some point we want to end the real time kernel processing
667          // so call ...
668          vTaskEndScheduler ();
669      }
670  }
671
672  void vAFunction( void )
673  {
674      // Create at least one task before starting the kernel.
675      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
676
677      // Start the real time kernel with preemption.
678      vTaskStartScheduler ();
679
680      // Will only get here when the vTaskCode () task has called
681      // vTaskEndScheduler ().  When we get here we are back to single task
682      // execution.
683  }
684    </pre>
685  *
686  * \defgroup vTaskEndScheduler vTaskEndScheduler
687  * \ingroup SchedulerControl
688  */
689 void vTaskEndScheduler( void );
690
691 /**
692  * task. h
693  * <pre>void vTaskSuspendAll( void );</pre>
694  *
695  * Suspends all real time kernel activity while keeping interrupts (including the
696  * kernel tick) enabled.
697  *
698  * After calling vTaskSuspendAll () the calling task will continue to execute
699  * without risk of being swapped out until a call to xTaskResumeAll () has been
700  * made.
701  *
702  * API functions that have the potential to cause a context switch (for example,
703  * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
704  * is suspended.
705  *
706  * Example usage:
707    <pre>
708  void vTask1( void * pvParameters )
709  {
710      for( ;; )
711      {
712          // Task code goes here.
713
714          // ...
715
716          // At some point the task wants to perform a long operation during
717          // which it does not want to get swapped out.  It cannot use
718          // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
719          // operation may cause interrupts to be missed - including the
720          // ticks.
721
722          // Prevent the real time kernel swapping out the task.
723          vTaskSuspendAll ();
724
725          // Perform the operation here.  There is no need to use critical
726          // sections as we have all the microcontroller processing time.
727          // During this time interrupts will still operate and the kernel
728          // tick count will be maintained.
729
730          // ...
731
732          // The operation is complete.  Restart the kernel.
733          xTaskResumeAll ();
734      }
735  }
736    </pre>
737  * \defgroup vTaskSuspendAll vTaskSuspendAll
738  * \ingroup SchedulerControl
739  */
740 void vTaskSuspendAll( void );
741
742 /**
743  * task. h
744  * <pre>portCHAR xTaskResumeAll( void );</pre>
745  *
746  * Resumes real time kernel activity following a call to vTaskSuspendAll ().
747  * After a call to vTaskSuspendAll () the kernel will take control of which
748  * task is executing at any time.
749  *
750  * @return If resuming the scheduler caused a context switch then pdTRUE is
751  *         returned, otherwise pdFALSE is returned.
752  *
753  * Example usage:
754    <pre>
755  void vTask1( void * pvParameters )
756  {
757      for( ;; )
758      {
759          // Task code goes here.
760
761          // ...
762
763          // At some point the task wants to perform a long operation during
764          // which it does not want to get swapped out.  It cannot use
765          // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
766          // operation may cause interrupts to be missed - including the
767          // ticks.
768
769          // Prevent the real time kernel swapping out the task.
770          vTaskSuspendAll ();
771
772          // Perform the operation here.  There is no need to use critical
773          // sections as we have all the microcontroller processing time.
774          // During this time interrupts will still operate and the real
775          // time kernel tick count will be maintained.
776
777          // ...
778
779          // The operation is complete.  Restart the kernel.  We want to force
780          // a context switch - but there is no point if resuming the scheduler
781          // caused a context switch already.
782          if( !xTaskResumeAll () )
783          {
784               taskYIELD ();
785          }
786      }
787  }
788    </pre>
789  * \defgroup xTaskResumeAll xTaskResumeAll
790  * \ingroup SchedulerControl
791  */
792 signed portBASE_TYPE xTaskResumeAll( void );
793
794 /**
795  * task. h
796  * <pre>signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask );</pre>
797  *
798  * Utility task that simply returns pdTRUE if the task referenced by xTask is
799  * currently in the Suspended state, or pdFALSE if the task referenced by xTask
800  * is in any other state.
801  *
802  */
803 signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask );
804
805 /*-----------------------------------------------------------
806  * TASK UTILITIES
807  *----------------------------------------------------------*/
808
809 /**
810  * task. h
811  * <PRE>volatile portTickType xTaskGetTickCount( void );</PRE>
812  *
813  * @return The count of ticks since vTaskStartScheduler was called.
814  *
815  * \page xTaskGetTickCount xTaskGetTickCount
816  * \ingroup TaskUtils
817  */
818 portTickType xTaskGetTickCount( void );
819
820 /**
821  * task. h
822  * <PRE>unsigned portSHORT uxTaskGetNumberOfTasks( void );</PRE>
823  *
824  * @return The number of tasks that the real time kernel is currently managing.
825  * This includes all ready, blocked and suspended tasks.  A task that
826  * has been deleted but not yet freed by the idle task will also be
827  * included in the count.
828  *
829  * \page uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
830  * \ingroup TaskUtils
831  */
832 unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void );
833
834 /**
835  * task. h
836  * <PRE>void vTaskList( portCHAR *pcWriteBuffer );</PRE>
837  *
838  * configUSE_TRACE_FACILITY, INCLUDE_vTaskDelete and INCLUDE_vTaskSuspend
839  * must all be defined as 1 for this function to be available.
840  * See the configuration section for more information.
841  *
842  * NOTE: This function will disable interrupts for its duration.  It is
843  * not intended for normal application runtime use but as a debug aid.
844  *
845  * Lists all the current tasks, along with their current state and stack
846  * usage high water mark.
847  *
848  * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
849  * suspended ('S').
850  *
851  * @param pcWriteBuffer A buffer into which the above mentioned details
852  * will be written, in ascii form.  This buffer is assumed to be large
853  * enough to contain the generated report.  Approximately 40 bytes per
854  * task should be sufficient.
855  *
856  * \page vTaskList vTaskList
857  * \ingroup TaskUtils
858  */
859 void vTaskList( signed portCHAR *pcWriteBuffer );
860
861 /**
862  * task. h
863  * <PRE>void vTaskStartTrace( portCHAR * pcBuffer, unsigned portBASE_TYPE uxBufferSize );</PRE>
864  *
865  * Starts a real time kernel activity trace.  The trace logs the identity of
866  * which task is running when.
867  *
868  * The trace file is stored in binary format.  A separate DOS utility called
869  * convtrce.exe is used to convert this into a tab delimited text file which
870  * can be viewed and plotted in a spread sheet.
871  *
872  * @param pcBuffer The buffer into which the trace will be written.
873  *
874  * @param ulBufferSize The size of pcBuffer in bytes.  The trace will continue
875  * until either the buffer in full, or ulTaskEndTrace () is called.
876  *
877  * \page vTaskStartTrace vTaskStartTrace
878  * \ingroup TaskUtils
879  */
880 void vTaskStartTrace( signed portCHAR * pcBuffer, unsigned portLONG ulBufferSize );
881
882 /**
883  * task. h
884  * <PRE>unsigned portLONG ulTaskEndTrace( void );</PRE>
885  *
886  * Stops a kernel activity trace.  See vTaskStartTrace ().
887  *
888  * @return The number of bytes that have been written into the trace buffer.
889  *
890  * \page usTaskEndTrace usTaskEndTrace
891  * \ingroup TaskUtils
892  */
893 unsigned portLONG ulTaskEndTrace( void );
894
895 /**
896  * task.h
897  * <PRE>unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );</PRE>
898  *
899  * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
900  * this function to be available.
901  *
902  * Returns the high water mark of the stack associated with xTask.  That is,
903  * the minimum free stack space there has been (in bytes) since the task
904  * started.  The smaller the returned number the closer the task has come
905  * to overflowing its stack.
906  *
907  * @param xTask Handle of the task associated with the stack to be checked.
908  * Set xTask to NULL to check the stack of the calling task.
909  *
910  * @return The smallest amount of free stack space there has been (in bytes)
911  * since the task referenced by xTask was created.
912  */
913 unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );
914
915 /**
916  * task.h
917  * <pre>void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>
918  *
919  * Sets pxHookFunction to be the task hook function used by the task xTask.
920  * Passing xTask as NULL has the effect of setting the calling tasks hook
921  * function.
922  */
923 void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );
924
925 /**
926  * task.h
927  * <pre>portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>
928  *
929  * Calls the hook function associated with xTask.  Passing xTask as NULL has
930  * the effect of calling the Running tasks (the calling task) hook function.
931  *
932  * pvParameter is passed to the hook function for the task to interpret as it
933  * wants.
934  */
935 portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter );
936
937
938 /*-----------------------------------------------------------
939  * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
940  *----------------------------------------------------------*/
941
942 /*
943  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS ONLY
944  * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
945  * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
946  *
947  * Called from the real time kernel tick (either preemptive or cooperative),
948  * this increments the tick count and checks if any tasks that are blocked
949  * for a finite period required removing from a blocked list and placing on
950  * a ready list.
951  */
952 void vTaskIncrementTick( void );
953
954 /*
955  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN
956  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
957  *
958  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
959  *
960  * Removes the calling task from the ready list and places it both
961  * on the list of tasks waiting for a particular event, and the
962  * list of delayed tasks.  The task will be removed from both lists
963  * and replaced on the ready list should either the event occur (and
964  * there be no higher priority tasks waiting on the same event) or
965  * the delay period expires.
966  *
967  * @param pxEventList The list containing tasks that are blocked waiting
968  * for the event to occur.
969  *
970  * @param xTicksToWait The maximum amount of time that the task should wait
971  * for the event to occur.  This is specified in kernel ticks,the constant
972  * portTICK_RATE_MS can be used to convert kernel ticks into a real time
973  * period.
974  */
975 void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicksToWait );
976
977 /*
978  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN
979  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
980  *
981  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
982  *
983  * Removes a task from both the specified event list and the list of blocked
984  * tasks, and places it on a ready queue.
985  *
986  * xTaskRemoveFromEventList () will be called if either an event occurs to
987  * unblock a task, or the block timeout period expires.
988  *
989  * @return pdTRUE if the task being removed has a higher priority than the task
990  * making the call, otherwise pdFALSE.
991  */
992 signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList );
993
994 /*
995  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN
996  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
997  *
998  * INCLUDE_vTaskCleanUpResources and INCLUDE_vTaskSuspend must be defined as 1
999  * for this function to be available.
1000  * See the configuration section for more information.
1001  *
1002  * Empties the ready and delayed queues of task control blocks, freeing the
1003  * memory allocated for the task control block and task stacks as it goes.
1004  */
1005 void vTaskCleanUpResources( void );
1006
1007 /*
1008  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS ONLY
1009  * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
1010  * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
1011  *
1012  * Sets the pointer to the current TCB to the TCB of the highest priority task
1013  * that is ready to run.
1014  */
1015 void vTaskSwitchContext( void );
1016
1017 /*
1018  * Return the handle of the calling task.
1019  */
1020 xTaskHandle xTaskGetCurrentTaskHandle( void );
1021
1022 /*
1023  * Capture the current time status for future reference.
1024  */
1025 void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut );
1026
1027 /*
1028  * Compare the time status now with that previously captured to see if the
1029  * timeout has expired.
1030  */
1031 portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType * const pxTicksToWait );
1032
1033 /*
1034  * Shortcut used by the queue implementation to prevent unnecessary call to
1035  * taskYIELD();
1036  */
1037 void vTaskMissedYield( void );
1038
1039 /*
1040  * Returns the scheduler state as taskSCHEDULER_RUNNING,
1041  * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
1042  */
1043 portBASE_TYPE xTaskGetSchedulerState( void );
1044
1045 /*
1046  * Raises the priority of the mutex holder to that of the calling task should
1047  * the mutex holder have a priority less than the calling task.
1048  */
1049 void vTaskPriorityInherit( xTaskHandle * const pxMutexHolder );
1050
1051 /*
1052  * Set the priority of a task back to its proper priority in the case that it
1053  * inherited a higher priority while it was holding a semaphore.
1054  */
1055 void vTaskPriorityDisinherit( xTaskHandle * const pxMutexHolder );
1056
1057 #ifdef __cplusplus
1058 }
1059 #endif
1060 #endif /* TASK_H */
1061
1062
1063
Note: See TracBrowser for help on using the browser.