TI's CC3100 websocket camera demo with Arducam mini ov5642 and freertos. Should work with other M3's. Work in progress test demo.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers task.h Source File

task.h

00001 /*
00002     FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.
00003     All rights reserved
00004 
00005     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
00006 
00007     This file is part of the FreeRTOS distribution.
00008 
00009     FreeRTOS is free software; you can redistribute it and/or modify it under
00010     the terms of the GNU General Public License (version 2) as published by the
00011     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
00012 
00013     ***************************************************************************
00014     >>!   NOTE: The modification to the GPL is included to allow you to     !<<
00015     >>!   distribute a combined work that includes FreeRTOS without being   !<<
00016     >>!   obliged to provide the source code for proprietary components     !<<
00017     >>!   outside of the FreeRTOS kernel.                                   !<<
00018     ***************************************************************************
00019 
00020     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
00021     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00022     FOR A PARTICULAR PURPOSE.  Full license text is available on the following
00023     link: http://www.freertos.org/a00114.html
00024 
00025     ***************************************************************************
00026      *                                                                       *
00027      *    FreeRTOS provides completely free yet professionally developed,    *
00028      *    robust, strictly quality controlled, supported, and cross          *
00029      *    platform software that is more than just the market leader, it     *
00030      *    is the industry's de facto standard.                               *
00031      *                                                                       *
00032      *    Help yourself get started quickly while simultaneously helping     *
00033      *    to support the FreeRTOS project by purchasing a FreeRTOS           *
00034      *    tutorial book, reference manual, or both:                          *
00035      *    http://www.FreeRTOS.org/Documentation                              *
00036      *                                                                       *
00037     ***************************************************************************
00038 
00039     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
00040     the FAQ page "My application does not run, what could be wrong?".  Have you
00041     defined configASSERT()?
00042 
00043     http://www.FreeRTOS.org/support - In return for receiving this top quality
00044     embedded software for free we request you assist our global community by
00045     participating in the support forum.
00046 
00047     http://www.FreeRTOS.org/training - Investing in training allows your team to
00048     be as productive as possible as early as possible.  Now you can receive
00049     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
00050     Ltd, and the world's leading authority on the world's leading RTOS.
00051 
00052     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
00053     including FreeRTOS+Trace - an indispensable productivity tool, a DOS
00054     compatible FAT file system, and our tiny thread aware UDP/IP stack.
00055 
00056     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
00057     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
00058 
00059     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
00060     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
00061     licenses offer ticketed support, indemnification and commercial middleware.
00062 
00063     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
00064     engineered and independently SIL3 certified version for use in safety and
00065     mission critical applications that require provable dependability.
00066 
00067     1 tab == 4 spaces!
00068 */
00069 
00070 
00071 #ifndef INC_TASK_H
00072 #define INC_TASK_H
00073 
00074 #ifndef INC_FREERTOS_H
00075     #error "include FreeRTOS.h must appear in source files before include task.h"
00076 #endif
00077 
00078 #include "list.h"
00079 
00080 #ifdef __cplusplus
00081 extern "C" {
00082 #endif
00083 
00084 /*-----------------------------------------------------------
00085  * MACROS AND DEFINITIONS
00086  *----------------------------------------------------------*/
00087 
00088 #define tskKERNEL_VERSION_NUMBER "V8.2.1"
00089 #define tskKERNEL_VERSION_MAJOR 8
00090 #define tskKERNEL_VERSION_MINOR 2
00091 #define tskKERNEL_VERSION_BUILD 1
00092 
00093 /**
00094  * task. h
00095  *
00096  * Type by which tasks are referenced.  For example, a call to xTaskCreate
00097  * returns (via a pointer parameter) an TaskHandle_t variable that can then
00098  * be used as a parameter to vTaskDelete to delete the task.
00099  *
00100  * \defgroup TaskHandle_t TaskHandle_t
00101  * \ingroup Tasks
00102  */
00103 typedef void * TaskHandle_t;
00104 
00105 /*
00106  * Defines the prototype to which the application task hook function must
00107  * conform.
00108  */
00109 typedef BaseType_t (*TaskHookFunction_t)( void * );
00110 
00111 /* Task states returned by eTaskGetState. */
00112 typedef enum
00113 {
00114     eRunning = 0,   /* A task is querying the state of itself, so must be running. */
00115     eReady,         /* The task being queried is in a read or pending ready list. */
00116     eBlocked,       /* The task being queried is in the Blocked state. */
00117     eSuspended,     /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
00118     eDeleted        /* The task being queried has been deleted, but its TCB has not yet been freed. */
00119 } eTaskState;
00120 
00121 /* Actions that can be performed when vTaskNotify() is called. */
00122 typedef enum
00123 {
00124     eNoAction = 0,              /* Notify the task without updating its notify value. */
00125     eSetBits,                   /* Set bits in the task's notification value. */
00126     eIncrement,                 /* Increment the task's notification value. */
00127     eSetValueWithOverwrite,     /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */
00128     eSetValueWithoutOverwrite   /* Set the task's notification value if the previous value has been read by the task. */
00129 } eNotifyAction;
00130 
00131 /*
00132  * Used internally only.
00133  */
00134 typedef struct xTIME_OUT
00135 {
00136     BaseType_t xOverflowCount;
00137     TickType_t xTimeOnEntering;
00138 } TimeOut_t;
00139 
00140 /*
00141  * Defines the memory ranges allocated to the task when an MPU is used.
00142  */
00143 typedef struct xMEMORY_REGION
00144 {
00145     void *pvBaseAddress;
00146     uint32_t ulLengthInBytes;
00147     uint32_t ulParameters;
00148 } MemoryRegion_t;
00149 
00150 /*
00151  * Parameters required to create an MPU protected task.
00152  */
00153 
00154 typedef struct xTASK_PARAMETERS
00155 {
00156     TaskFunction_t pvTaskCode;
00157     const char * const pcName;  /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
00158     uint16_t usStackDepth;
00159     void *pvParameters;
00160     UBaseType_t uxPriority;
00161     StackType_t *puxStackBuffer;
00162     MemoryRegion_t xRegions[ portNUM_CONFIGURABLE_REGIONS ];
00163 } TaskParameters_t;
00164 
00165 
00166 /* Used with the uxTaskGetSystemState() function to return the state of each task
00167 in the system. */
00168 typedef struct xTASK_STATUS
00169 {
00170     TaskHandle_t xHandle;           /* The handle of the task to which the rest of the information in the structure relates. */
00171     const char *pcTaskName;         /* A pointer to the task's name.  This value will be invalid if the task was deleted since the structure was populated! */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
00172     UBaseType_t xTaskNumber;        /* A number unique to the task. */
00173     eTaskState eCurrentState;       /* The state in which the task existed when the structure was populated. */
00174     UBaseType_t uxCurrentPriority;  /* The priority at which the task was running (may be inherited) when the structure was populated. */
00175     UBaseType_t uxBasePriority;     /* The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex.  Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */
00176     uint32_t ulRunTimeCounter;      /* The total run time allocated to the task so far, as defined by the run time stats clock.  See http://www.freertos.org/rtos-run-time-stats.html.  Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */
00177     uint16_t usStackHighWaterMark;  /* The minimum amount of stack space that has remained for the task since the task was created.  The closer this value is to zero the closer the task has come to overflowing its stack. */
00178 } TaskStatus_t;
00179 
00180 /* Possible return values for eTaskConfirmSleepModeStatus(). */
00181 typedef enum
00182 {
00183     eAbortSleep = 0,        /* A task has been made ready or a context switch pended since portSUPPORESS_TICKS_AND_SLEEP() was called - abort entering a sleep mode. */
00184     eStandardSleep,         /* Enter a sleep mode that will not last any longer than the expected idle time. */
00185     eNoTasksWaitingTimeout  /* No tasks are waiting for a timeout so it is safe to enter a sleep mode that can only be exited by an external interrupt. */
00186 } eSleepModeStatus;
00187 
00188 
00189 /**
00190  * Defines the priority used by the idle task.  This must not be modified.
00191  *
00192  * \ingroup TaskUtils
00193  */
00194 #define tskIDLE_PRIORITY            ( ( UBaseType_t ) 0U )
00195 
00196 /**
00197  * task. h
00198  *
00199  * Macro for forcing a context switch.
00200  *
00201  * \defgroup taskYIELD taskYIELD
00202  * \ingroup SchedulerControl
00203  */
00204 #define taskYIELD()                 portYIELD()
00205 
00206 /**
00207  * task. h
00208  *
00209  * Macro to mark the start of a critical code region.  Preemptive context
00210  * switches cannot occur when in a critical region.
00211  *
00212  * NOTE: This may alter the stack (depending on the portable implementation)
00213  * so must be used with care!
00214  *
00215  * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL
00216  * \ingroup SchedulerControl
00217  */
00218 #define taskENTER_CRITICAL()        portENTER_CRITICAL()
00219 #define taskENTER_CRITICAL_FROM_ISR( x ) portSET_INTERRUPT_MASK_FROM_ISR( x )
00220 
00221 /**
00222  * task. h
00223  *
00224  * Macro to mark the end of a critical code region.  Preemptive context
00225  * switches cannot occur when in a critical region.
00226  *
00227  * NOTE: This may alter the stack (depending on the portable implementation)
00228  * so must be used with care!
00229  *
00230  * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL
00231  * \ingroup SchedulerControl
00232  */
00233 #define taskEXIT_CRITICAL()         portEXIT_CRITICAL()
00234 #define taskEXIT_CRITICAL_FROM_ISR() portCLEAR_INTERRUPT_MASK_FROM_ISR()
00235 /**
00236  * task. h
00237  *
00238  * Macro to disable all maskable interrupts.
00239  *
00240  * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
00241  * \ingroup SchedulerControl
00242  */
00243 #define taskDISABLE_INTERRUPTS()    portDISABLE_INTERRUPTS()
00244 
00245 /**
00246  * task. h
00247  *
00248  * Macro to enable microcontroller interrupts.
00249  *
00250  * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
00251  * \ingroup SchedulerControl
00252  */
00253 #define taskENABLE_INTERRUPTS()     portENABLE_INTERRUPTS()
00254 
00255 /* Definitions returned by xTaskGetSchedulerState().  taskSCHEDULER_SUSPENDED is
00256 0 to generate more optimal code when configASSERT() is defined as the constant
00257 is used in assert() statements. */
00258 #define taskSCHEDULER_SUSPENDED     ( ( BaseType_t ) 0 )
00259 #define taskSCHEDULER_NOT_STARTED   ( ( BaseType_t ) 1 )
00260 #define taskSCHEDULER_RUNNING       ( ( BaseType_t ) 2 )
00261 
00262 
00263 /*-----------------------------------------------------------
00264  * TASK CREATION API
00265  *----------------------------------------------------------*/
00266 
00267 /**
00268  * task. h
00269  *<pre>
00270  BaseType_t xTaskCreate(
00271                               TaskFunction_t pvTaskCode,
00272                               const char * const pcName,
00273                               uint16_t usStackDepth,
00274                               void *pvParameters,
00275                               UBaseType_t uxPriority,
00276                               TaskHandle_t *pvCreatedTask
00277                           );</pre>
00278  *
00279  * Create a new task and add it to the list of tasks that are ready to run.
00280  *
00281  * xTaskCreate() can only be used to create a task that has unrestricted
00282  * access to the entire microcontroller memory map.  Systems that include MPU
00283  * support can alternatively create an MPU constrained task using
00284  * xTaskCreateRestricted().
00285  *
00286  * @param pvTaskCode Pointer to the task entry function.  Tasks
00287  * must be implemented to never return (i.e. continuous loop).
00288  *
00289  * @param pcName A descriptive name for the task.  This is mainly used to
00290  * facilitate debugging.  Max length defined by configMAX_TASK_NAME_LEN - default
00291  * is 16.
00292  *
00293  * @param usStackDepth The size of the task stack specified as the number of
00294  * variables the stack can hold - not the number of bytes.  For example, if
00295  * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
00296  * will be allocated for stack storage.
00297  *
00298  * @param pvParameters Pointer that will be used as the parameter for the task
00299  * being created.
00300  *
00301  * @param uxPriority The priority at which the task should run.  Systems that
00302  * include MPU support can optionally create tasks in a privileged (system)
00303  * mode by setting bit portPRIVILEGE_BIT of the priority parameter.  For
00304  * example, to create a privileged task at priority 2 the uxPriority parameter
00305  * should be set to ( 2 | portPRIVILEGE_BIT ).
00306  *
00307  * @param pvCreatedTask Used to pass back a handle by which the created task
00308  * can be referenced.
00309  *
00310  * @return pdPASS if the task was successfully created and added to a ready
00311  * list, otherwise an error code defined in the file projdefs.h
00312  *
00313  * Example usage:
00314    <pre>
00315  // Task to be created.
00316  void vTaskCode( void * pvParameters )
00317  {
00318      for( ;; )
00319      {
00320          // Task code goes here.
00321      }
00322  }
00323 
00324  // Function that creates a task.
00325  void vOtherFunction( void )
00326  {
00327  static uint8_t ucParameterToPass;
00328  TaskHandle_t xHandle = NULL;
00329 
00330      // Create the task, storing the handle.  Note that the passed parameter ucParameterToPass
00331      // must exist for the lifetime of the task, so in this case is declared static.  If it was just an
00332      // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
00333      // the new task attempts to access it.
00334      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
00335      configASSERT( xHandle );
00336 
00337      // Use the handle to delete the task.
00338      if( xHandle != NULL )
00339      {
00340          vTaskDelete( xHandle );
00341      }
00342  }
00343    </pre>
00344  * \defgroup xTaskCreate xTaskCreate
00345  * \ingroup Tasks
00346  */
00347 #define xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask ) xTaskGenericCreate( ( pvTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( uxPriority ), ( pxCreatedTask ), ( NULL ), ( NULL ) )
00348 
00349 /**
00350  * task. h
00351  *<pre>
00352  BaseType_t xTaskCreateRestricted( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );</pre>
00353  *
00354  * xTaskCreateRestricted() should only be used in systems that include an MPU
00355  * implementation.
00356  *
00357  * Create a new task and add it to the list of tasks that are ready to run.
00358  * The function parameters define the memory regions and associated access
00359  * permissions allocated to the task.
00360  *
00361  * @param pxTaskDefinition Pointer to a structure that contains a member
00362  * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
00363  * documentation) plus an optional stack buffer and the memory region
00364  * definitions.
00365  *
00366  * @param pxCreatedTask Used to pass back a handle by which the created task
00367  * can be referenced.
00368  *
00369  * @return pdPASS if the task was successfully created and added to a ready
00370  * list, otherwise an error code defined in the file projdefs.h
00371  *
00372  * Example usage:
00373    <pre>
00374 // Create an TaskParameters_t structure that defines the task to be created.
00375 static const TaskParameters_t xCheckTaskParameters =
00376 {
00377     vATask,     // pvTaskCode - the function that implements the task.
00378     "ATask",    // pcName - just a text name for the task to assist debugging.
00379     100,        // usStackDepth - the stack size DEFINED IN WORDS.
00380     NULL,       // pvParameters - passed into the task function as the function parameters.
00381     ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
00382     cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
00383 
00384     // xRegions - Allocate up to three separate memory regions for access by
00385     // the task, with appropriate access permissions.  Different processors have
00386     // different memory alignment requirements - refer to the FreeRTOS documentation
00387     // for full information.
00388     {
00389         // Base address                 Length  Parameters
00390         { cReadWriteArray,              32,     portMPU_REGION_READ_WRITE },
00391         { cReadOnlyArray,               32,     portMPU_REGION_READ_ONLY },
00392         { cPrivilegedOnlyAccessArray,   128,    portMPU_REGION_PRIVILEGED_READ_WRITE }
00393     }
00394 };
00395 
00396 int main( void )
00397 {
00398 TaskHandle_t xHandle;
00399 
00400     // Create a task from the const structure defined above.  The task handle
00401     // is requested (the second parameter is not NULL) but in this case just for
00402     // demonstration purposes as its not actually used.
00403     xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
00404 
00405     // Start the scheduler.
00406     vTaskStartScheduler();
00407 
00408     // Will only get here if there was insufficient memory to create the idle
00409     // and/or timer task.
00410     for( ;; );
00411 }
00412    </pre>
00413  * \defgroup xTaskCreateRestricted xTaskCreateRestricted
00414  * \ingroup Tasks
00415  */
00416 #define xTaskCreateRestricted( x, pxCreatedTask ) xTaskGenericCreate( ((x)->pvTaskCode), ((x)->pcName), ((x)->usStackDepth), ((x)->pvParameters), ((x)->uxPriority), (pxCreatedTask), ((x)->puxStackBuffer), ((x)->xRegions) )
00417 
00418 /**
00419  * task. h
00420  *<pre>
00421  void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions );</pre>
00422  *
00423  * Memory regions are assigned to a restricted task when the task is created by
00424  * a call to xTaskCreateRestricted().  These regions can be redefined using
00425  * vTaskAllocateMPURegions().
00426  *
00427  * @param xTask The handle of the task being updated.
00428  *
00429  * @param xRegions A pointer to an MemoryRegion_t structure that contains the
00430  * new memory region definitions.
00431  *
00432  * Example usage:
00433    <pre>
00434 // Define an array of MemoryRegion_t structures that configures an MPU region
00435 // allowing read/write access for 1024 bytes starting at the beginning of the
00436 // ucOneKByte array.  The other two of the maximum 3 definable regions are
00437 // unused so set to zero.
00438 static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
00439 {
00440     // Base address     Length      Parameters
00441     { ucOneKByte,       1024,       portMPU_REGION_READ_WRITE },
00442     { 0,                0,          0 },
00443     { 0,                0,          0 }
00444 };
00445 
00446 void vATask( void *pvParameters )
00447 {
00448     // This task was created such that it has access to certain regions of
00449     // memory as defined by the MPU configuration.  At some point it is
00450     // desired that these MPU regions are replaced with that defined in the
00451     // xAltRegions const struct above.  Use a call to vTaskAllocateMPURegions()
00452     // for this purpose.  NULL is used as the task handle to indicate that this
00453     // function should modify the MPU regions of the calling task.
00454     vTaskAllocateMPURegions( NULL, xAltRegions );
00455 
00456     // Now the task can continue its function, but from this point on can only
00457     // access its stack and the ucOneKByte array (unless any other statically
00458     // defined or shared regions have been declared elsewhere).
00459 }
00460    </pre>
00461  * \defgroup xTaskCreateRestricted xTaskCreateRestricted
00462  * \ingroup Tasks
00463  */
00464 void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION;
00465 
00466 /**
00467  * task. h
00468  * <pre>void vTaskDelete( TaskHandle_t xTask );</pre>
00469  *
00470  * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
00471  * See the configuration section for more information.
00472  *
00473  * Remove a task from the RTOS real time kernel's management.  The task being
00474  * deleted will be removed from all ready, blocked, suspended and event lists.
00475  *
00476  * NOTE:  The idle task is responsible for freeing the kernel allocated
00477  * memory from tasks that have been deleted.  It is therefore important that
00478  * the idle task is not starved of microcontroller processing time if your
00479  * application makes any calls to vTaskDelete ().  Memory allocated by the
00480  * task code is not automatically freed, and should be freed before the task
00481  * is deleted.
00482  *
00483  * See the demo application file death.c for sample code that utilises
00484  * vTaskDelete ().
00485  *
00486  * @param xTask The handle of the task to be deleted.  Passing NULL will
00487  * cause the calling task to be deleted.
00488  *
00489  * Example usage:
00490    <pre>
00491  void vOtherFunction( void )
00492  {
00493  TaskHandle_t xHandle;
00494 
00495      // Create the task, storing the handle.
00496      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
00497 
00498      // Use the handle to delete the task.
00499      vTaskDelete( xHandle );
00500  }
00501    </pre>
00502  * \defgroup vTaskDelete vTaskDelete
00503  * \ingroup Tasks
00504  */
00505 void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION;
00506 
00507 /*-----------------------------------------------------------
00508  * TASK CONTROL API
00509  *----------------------------------------------------------*/
00510 
00511 /**
00512  * task. h
00513  * <pre>void vTaskDelay( const TickType_t xTicksToDelay );</pre>
00514  *
00515  * Delay a task for a given number of ticks.  The actual time that the
00516  * task remains blocked depends on the tick rate.  The constant
00517  * portTICK_PERIOD_MS can be used to calculate real time from the tick
00518  * rate - with the resolution of one tick period.
00519  *
00520  * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
00521  * See the configuration section for more information.
00522  *
00523  *
00524  * vTaskDelay() specifies a time at which the task wishes to unblock relative to
00525  * the time at which vTaskDelay() is called.  For example, specifying a block
00526  * period of 100 ticks will cause the task to unblock 100 ticks after
00527  * vTaskDelay() is called.  vTaskDelay() does not therefore provide a good method
00528  * of controlling the frequency of a periodic task as the path taken through the
00529  * code, as well as other task and interrupt activity, will effect the frequency
00530  * at which vTaskDelay() gets called and therefore the time at which the task
00531  * next executes.  See vTaskDelayUntil() for an alternative API function designed
00532  * to facilitate fixed frequency execution.  It does this by specifying an
00533  * absolute time (rather than a relative time) at which the calling task should
00534  * unblock.
00535  *
00536  * @param xTicksToDelay The amount of time, in tick periods, that
00537  * the calling task should block.
00538  *
00539  * Example usage:
00540 
00541  void vTaskFunction( void * pvParameters )
00542  {
00543  // Block for 500ms.
00544  const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
00545 
00546      for( ;; )
00547      {
00548          // Simply toggle the LED every 500ms, blocking between each toggle.
00549          vToggleLED();
00550          vTaskDelay( xDelay );
00551      }
00552  }
00553 
00554  * \defgroup vTaskDelay vTaskDelay
00555  * \ingroup TaskCtrl
00556  */
00557 void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
00558 
00559 /**
00560  * task. h
00561  * <pre>void vTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );</pre>
00562  *
00563  * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
00564  * See the configuration section for more information.
00565  *
00566  * Delay a task until a specified time.  This function can be used by periodic
00567  * tasks to ensure a constant execution frequency.
00568  *
00569  * This function differs from vTaskDelay () in one important aspect:  vTaskDelay () will
00570  * cause a task to block for the specified number of ticks from the time vTaskDelay () is
00571  * called.  It is therefore difficult to use vTaskDelay () by itself to generate a fixed
00572  * execution frequency as the time between a task starting to execute and that task
00573  * calling vTaskDelay () may not be fixed [the task may take a different path though the
00574  * code between calls, or may get interrupted or preempted a different number of times
00575  * each time it executes].
00576  *
00577  * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
00578  * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
00579  * unblock.
00580  *
00581  * The constant portTICK_PERIOD_MS can be used to calculate real time from the tick
00582  * rate - with the resolution of one tick period.
00583  *
00584  * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
00585  * task was last unblocked.  The variable must be initialised with the current time
00586  * prior to its first use (see the example below).  Following this the variable is
00587  * automatically updated within vTaskDelayUntil ().
00588  *
00589  * @param xTimeIncrement The cycle time period.  The task will be unblocked at
00590  * time *pxPreviousWakeTime + xTimeIncrement.  Calling vTaskDelayUntil with the
00591  * same xTimeIncrement parameter value will cause the task to execute with
00592  * a fixed interface period.
00593  *
00594  * Example usage:
00595    <pre>
00596  // Perform an action every 10 ticks.
00597  void vTaskFunction( void * pvParameters )
00598  {
00599  TickType_t xLastWakeTime;
00600  const TickType_t xFrequency = 10;
00601 
00602      // Initialise the xLastWakeTime variable with the current time.
00603      xLastWakeTime = xTaskGetTickCount ();
00604      for( ;; )
00605      {
00606          // Wait for the next cycle.
00607          vTaskDelayUntil( &xLastWakeTime, xFrequency );
00608 
00609          // Perform action here.
00610      }
00611  }
00612    </pre>
00613  * \defgroup vTaskDelayUntil vTaskDelayUntil
00614  * \ingroup TaskCtrl
00615  */
00616 void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
00617 
00618 /**
00619  * task. h
00620  * <pre>UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask );</pre>
00621  *
00622  * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available.
00623  * See the configuration section for more information.
00624  *
00625  * Obtain the priority of any task.
00626  *
00627  * @param xTask Handle of the task to be queried.  Passing a NULL
00628  * handle results in the priority of the calling task being returned.
00629  *
00630  * @return The priority of xTask.
00631  *
00632  * Example usage:
00633    <pre>
00634  void vAFunction( void )
00635  {
00636  TaskHandle_t xHandle;
00637 
00638      // Create a task, storing the handle.
00639      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
00640 
00641      // ...
00642 
00643      // Use the handle to obtain the priority of the created task.
00644      // It was created with tskIDLE_PRIORITY, but may have changed
00645      // it itself.
00646      if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
00647      {
00648          // The task has changed it's priority.
00649      }
00650 
00651      // ...
00652 
00653      // Is our priority higher than the created task?
00654      if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
00655      {
00656          // Our priority (obtained using NULL handle) is higher.
00657      }
00658  }
00659    </pre>
00660  * \defgroup uxTaskPriorityGet uxTaskPriorityGet
00661  * \ingroup TaskCtrl
00662  */
00663 UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
00664 
00665 /**
00666  * task. h
00667  * <pre>UBaseType_t uxTaskPriorityGetFromISR( TaskHandle_t xTask );</pre>
00668  *
00669  * A version of uxTaskPriorityGet() that can be used from an ISR.
00670  */
00671 UBaseType_t uxTaskPriorityGetFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
00672 
00673 /**
00674  * task. h
00675  * <pre>eTaskState eTaskGetState( TaskHandle_t xTask );</pre>
00676  *
00677  * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
00678  * See the configuration section for more information.
00679  *
00680  * Obtain the state of any task.  States are encoded by the eTaskState
00681  * enumerated type.
00682  *
00683  * @param xTask Handle of the task to be queried.
00684  *
00685  * @return The state of xTask at the time the function was called.  Note the
00686  * state of the task might change between the function being called, and the
00687  * functions return value being tested by the calling task.
00688  */
00689 eTaskState eTaskGetState( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
00690 
00691 /**
00692  * task. h
00693  * <pre>void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority );</pre>
00694  *
00695  * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
00696  * See the configuration section for more information.
00697  *
00698  * Set the priority of any task.
00699  *
00700  * A context switch will occur before the function returns if the priority
00701  * being set is higher than the currently executing task.
00702  *
00703  * @param xTask Handle to the task for which the priority is being set.
00704  * Passing a NULL handle results in the priority of the calling task being set.
00705  *
00706  * @param uxNewPriority The priority to which the task will be set.
00707  *
00708  * Example usage:
00709    <pre>
00710  void vAFunction( void )
00711  {
00712  TaskHandle_t xHandle;
00713 
00714      // Create a task, storing the handle.
00715      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
00716 
00717      // ...
00718 
00719      // Use the handle to raise the priority of the created task.
00720      vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
00721 
00722      // ...
00723 
00724      // Use a NULL handle to raise our priority to the same value.
00725      vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
00726  }
00727    </pre>
00728  * \defgroup vTaskPrioritySet vTaskPrioritySet
00729  * \ingroup TaskCtrl
00730  */
00731 void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority ) PRIVILEGED_FUNCTION;
00732 
00733 /**
00734  * task. h
00735  * <pre>void vTaskSuspend( TaskHandle_t xTaskToSuspend );</pre>
00736  *
00737  * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
00738  * See the configuration section for more information.
00739  *
00740  * Suspend any task.  When suspended a task will never get any microcontroller
00741  * processing time, no matter what its priority.
00742  *
00743  * Calls to vTaskSuspend are not accumulative -
00744  * i.e. calling vTaskSuspend () twice on the same task still only requires one
00745  * call to vTaskResume () to ready the suspended task.
00746  *
00747  * @param xTaskToSuspend Handle to the task being suspended.  Passing a NULL
00748  * handle will cause the calling task to be suspended.
00749  *
00750  * Example usage:
00751    <pre>
00752  void vAFunction( void )
00753  {
00754  TaskHandle_t xHandle;
00755 
00756      // Create a task, storing the handle.
00757      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
00758 
00759      // ...
00760 
00761      // Use the handle to suspend the created task.
00762      vTaskSuspend( xHandle );
00763 
00764      // ...
00765 
00766      // The created task will not run during this period, unless
00767      // another task calls vTaskResume( xHandle ).
00768 
00769      //...
00770 
00771 
00772      // Suspend ourselves.
00773      vTaskSuspend( NULL );
00774 
00775      // We cannot get here unless another task calls vTaskResume
00776      // with our handle as the parameter.
00777  }
00778    </pre>
00779  * \defgroup vTaskSuspend vTaskSuspend
00780  * \ingroup TaskCtrl
00781  */
00782 void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION;
00783 
00784 /**
00785  * task. h
00786  * <pre>void vTaskResume( TaskHandle_t xTaskToResume );</pre>
00787  *
00788  * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
00789  * See the configuration section for more information.
00790  *
00791  * Resumes a suspended task.
00792  *
00793  * A task that has been suspended by one or more calls to vTaskSuspend ()
00794  * will be made available for running again by a single call to
00795  * vTaskResume ().
00796  *
00797  * @param xTaskToResume Handle to the task being readied.
00798  *
00799  * Example usage:
00800    <pre>
00801  void vAFunction( void )
00802  {
00803  TaskHandle_t xHandle;
00804 
00805      // Create a task, storing the handle.
00806      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
00807 
00808      // ...
00809 
00810      // Use the handle to suspend the created task.
00811      vTaskSuspend( xHandle );
00812 
00813      // ...
00814 
00815      // The created task will not run during this period, unless
00816      // another task calls vTaskResume( xHandle ).
00817 
00818      //...
00819 
00820 
00821      // Resume the suspended task ourselves.
00822      vTaskResume( xHandle );
00823 
00824      // The created task will once again get microcontroller processing
00825      // time in accordance with its priority within the system.
00826  }
00827    </pre>
00828  * \defgroup vTaskResume vTaskResume
00829  * \ingroup TaskCtrl
00830  */
00831 void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
00832 
00833 /**
00834  * task. h
00835  * <pre>void xTaskResumeFromISR( TaskHandle_t xTaskToResume );</pre>
00836  *
00837  * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
00838  * available.  See the configuration section for more information.
00839  *
00840  * An implementation of vTaskResume() that can be called from within an ISR.
00841  *
00842  * A task that has been suspended by one or more calls to vTaskSuspend ()
00843  * will be made available for running again by a single call to
00844  * xTaskResumeFromISR ().
00845  *
00846  * xTaskResumeFromISR() should not be used to synchronise a task with an
00847  * interrupt if there is a chance that the interrupt could arrive prior to the
00848  * task being suspended - as this can lead to interrupts being missed. Use of a
00849  * semaphore as a synchronisation mechanism would avoid this eventuality.
00850  *
00851  * @param xTaskToResume Handle to the task being readied.
00852  *
00853  * @return pdTRUE if resuming the task should result in a context switch,
00854  * otherwise pdFALSE. This is used by the ISR to determine if a context switch
00855  * may be required following the ISR.
00856  *
00857  * \defgroup vTaskResumeFromISR vTaskResumeFromISR
00858  * \ingroup TaskCtrl
00859  */
00860 BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
00861 
00862 /*-----------------------------------------------------------
00863  * SCHEDULER CONTROL
00864  *----------------------------------------------------------*/
00865 
00866 /**
00867  * task. h
00868  * <pre>void vTaskStartScheduler( void );</pre>
00869  *
00870  * Starts the real time kernel tick processing.  After calling the kernel
00871  * has control over which tasks are executed and when.
00872  *
00873  * See the demo application file main.c for an example of creating
00874  * tasks and starting the kernel.
00875  *
00876  * Example usage:
00877    <pre>
00878  void vAFunction( void )
00879  {
00880      // Create at least one task before starting the kernel.
00881      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
00882 
00883      // Start the real time kernel with preemption.
00884      vTaskStartScheduler ();
00885 
00886      // Will not get here unless a task calls vTaskEndScheduler ()
00887  }
00888    </pre>
00889  *
00890  * \defgroup vTaskStartScheduler vTaskStartScheduler
00891  * \ingroup SchedulerControl
00892  */
00893 void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
00894 
00895 /**
00896  * task. h
00897  * <pre>void vTaskEndScheduler( void );</pre>
00898  *
00899  * NOTE:  At the time of writing only the x86 real mode port, which runs on a PC
00900  * in place of DOS, implements this function.
00901  *
00902  * Stops the real time kernel tick.  All created tasks will be automatically
00903  * deleted and multitasking (either preemptive or cooperative) will
00904  * stop.  Execution then resumes from the point where vTaskStartScheduler ()
00905  * was called, as if vTaskStartScheduler () had just returned.
00906  *
00907  * See the demo application file main. c in the demo/PC directory for an
00908  * example that uses vTaskEndScheduler ().
00909  *
00910  * vTaskEndScheduler () requires an exit function to be defined within the
00911  * portable layer (see vPortEndScheduler () in port. c for the PC port).  This
00912  * performs hardware specific operations such as stopping the kernel tick.
00913  *
00914  * vTaskEndScheduler () will cause all of the resources allocated by the
00915  * kernel to be freed - but will not free resources allocated by application
00916  * tasks.
00917  *
00918  * Example usage:
00919    <pre>
00920  void vTaskCode( void * pvParameters )
00921  {
00922      for( ;; )
00923      {
00924          // Task code goes here.
00925 
00926          // At some point we want to end the real time kernel processing
00927          // so call ...
00928          vTaskEndScheduler ();
00929      }
00930  }
00931 
00932  void vAFunction( void )
00933  {
00934      // Create at least one task before starting the kernel.
00935      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
00936 
00937      // Start the real time kernel with preemption.
00938      vTaskStartScheduler ();
00939 
00940      // Will only get here when the vTaskCode () task has called
00941      // vTaskEndScheduler ().  When we get here we are back to single task
00942      // execution.
00943  }
00944    </pre>
00945  *
00946  * \defgroup vTaskEndScheduler vTaskEndScheduler
00947  * \ingroup SchedulerControl
00948  */
00949 void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
00950 
00951 /**
00952  * task. h
00953  * <pre>void vTaskSuspendAll( void );</pre>
00954  *
00955  * Suspends the scheduler without disabling interrupts.  Context switches will
00956  * not occur while the scheduler is suspended.
00957  *
00958  * After calling vTaskSuspendAll () the calling task will continue to execute
00959  * without risk of being swapped out until a call to xTaskResumeAll () has been
00960  * made.
00961  *
00962  * API functions that have the potential to cause a context switch (for example,
00963  * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
00964  * is suspended.
00965  *
00966  * Example usage:
00967    <pre>
00968  void vTask1( void * pvParameters )
00969  {
00970      for( ;; )
00971      {
00972          // Task code goes here.
00973 
00974          // ...
00975 
00976          // At some point the task wants to perform a long operation during
00977          // which it does not want to get swapped out.  It cannot use
00978          // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
00979          // operation may cause interrupts to be missed - including the
00980          // ticks.
00981 
00982          // Prevent the real time kernel swapping out the task.
00983          vTaskSuspendAll ();
00984 
00985          // Perform the operation here.  There is no need to use critical
00986          // sections as we have all the microcontroller processing time.
00987          // During this time interrupts will still operate and the kernel
00988          // tick count will be maintained.
00989 
00990          // ...
00991 
00992          // The operation is complete.  Restart the kernel.
00993          xTaskResumeAll ();
00994      }
00995  }
00996    </pre>
00997  * \defgroup vTaskSuspendAll vTaskSuspendAll
00998  * \ingroup SchedulerControl
00999  */
01000 void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
01001 
01002 /**
01003  * task. h
01004  * <pre>BaseType_t xTaskResumeAll( void );</pre>
01005  *
01006  * Resumes scheduler activity after it was suspended by a call to
01007  * vTaskSuspendAll().
01008  *
01009  * xTaskResumeAll() only resumes the scheduler.  It does not unsuspend tasks
01010  * that were previously suspended by a call to vTaskSuspend().
01011  *
01012  * @return If resuming the scheduler caused a context switch then pdTRUE is
01013  *        returned, otherwise pdFALSE is returned.
01014  *
01015  * Example usage:
01016    <pre>
01017  void vTask1( void * pvParameters )
01018  {
01019      for( ;; )
01020      {
01021          // Task code goes here.
01022 
01023          // ...
01024 
01025          // At some point the task wants to perform a long operation during
01026          // which it does not want to get swapped out.  It cannot use
01027          // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
01028          // operation may cause interrupts to be missed - including the
01029          // ticks.
01030 
01031          // Prevent the real time kernel swapping out the task.
01032          vTaskSuspendAll ();
01033 
01034          // Perform the operation here.  There is no need to use critical
01035          // sections as we have all the microcontroller processing time.
01036          // During this time interrupts will still operate and the real
01037          // time kernel tick count will be maintained.
01038 
01039          // ...
01040 
01041          // The operation is complete.  Restart the kernel.  We want to force
01042          // a context switch - but there is no point if resuming the scheduler
01043          // caused a context switch already.
01044          if( !xTaskResumeAll () )
01045          {
01046               taskYIELD ();
01047          }
01048      }
01049  }
01050    </pre>
01051  * \defgroup xTaskResumeAll xTaskResumeAll
01052  * \ingroup SchedulerControl
01053  */
01054 BaseType_t xTaskResumeAll( void ) PRIVILEGED_FUNCTION;
01055 
01056 /*-----------------------------------------------------------
01057  * TASK UTILITIES
01058  *----------------------------------------------------------*/
01059 
01060 /**
01061  * task. h
01062  * <PRE>TickType_t xTaskGetTickCount( void );</PRE>
01063  *
01064  * @return The count of ticks since vTaskStartScheduler was called.
01065  *
01066  * \defgroup xTaskGetTickCount xTaskGetTickCount
01067  * \ingroup TaskUtils
01068  */
01069 TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
01070 
01071 /**
01072  * task. h
01073  * <PRE>TickType_t xTaskGetTickCountFromISR( void );</PRE>
01074  *
01075  * @return The count of ticks since vTaskStartScheduler was called.
01076  *
01077  * This is a version of xTaskGetTickCount() that is safe to be called from an
01078  * ISR - provided that TickType_t is the natural word size of the
01079  * microcontroller being used or interrupt nesting is either not supported or
01080  * not being used.
01081  *
01082  * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR
01083  * \ingroup TaskUtils
01084  */
01085 TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
01086 
01087 /**
01088  * task. h
01089  * <PRE>uint16_t uxTaskGetNumberOfTasks( void );</PRE>
01090  *
01091  * @return The number of tasks that the real time kernel is currently managing.
01092  * This includes all ready, blocked and suspended tasks.  A task that
01093  * has been deleted but not yet freed by the idle task will also be
01094  * included in the count.
01095  *
01096  * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
01097  * \ingroup TaskUtils
01098  */
01099 UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
01100 
01101 /**
01102  * task. h
01103  * <PRE>char *pcTaskGetTaskName( TaskHandle_t xTaskToQuery );</PRE>
01104  *
01105  * @return The text (human readable) name of the task referenced by the handle
01106  * xTaskToQuery.  A task can query its own name by either passing in its own
01107  * handle, or by setting xTaskToQuery to NULL.  INCLUDE_pcTaskGetTaskName must be
01108  * set to 1 in FreeRTOSConfig.h for pcTaskGetTaskName() to be available.
01109  *
01110  * \defgroup pcTaskGetTaskName pcTaskGetTaskName
01111  * \ingroup TaskUtils
01112  */
01113 char *pcTaskGetTaskName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
01114 
01115 /**
01116  * task.h
01117  * <PRE>UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );</PRE>
01118  *
01119  * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
01120  * this function to be available.
01121  *
01122  * Returns the high water mark of the stack associated with xTask.  That is,
01123  * the minimum free stack space there has been (in words, so on a 32 bit machine
01124  * a value of 1 means 4 bytes) since the task started.  The smaller the returned
01125  * number the closer the task has come to overflowing its stack.
01126  *
01127  * @param xTask Handle of the task associated with the stack to be checked.
01128  * Set xTask to NULL to check the stack of the calling task.
01129  *
01130  * @return The smallest amount of free stack space there has been (in words, so
01131  * actual spaces on the stack rather than bytes) since the task referenced by
01132  * xTask was created.
01133  */
01134 UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
01135 
01136 /* When using trace macros it is sometimes necessary to include task.h before
01137 FreeRTOS.h.  When this is done TaskHookFunction_t will not yet have been defined,
01138 so the following two prototypes will cause a compilation error.  This can be
01139 fixed by simply guarding against the inclusion of these two prototypes unless
01140 they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
01141 constant. */
01142 #ifdef configUSE_APPLICATION_TASK_TAG
01143     #if configUSE_APPLICATION_TASK_TAG == 1
01144         /**
01145          * task.h
01146          * <pre>void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );</pre>
01147          *
01148          * Sets pxHookFunction to be the task hook function used by the task xTask.
01149          * Passing xTask as NULL has the effect of setting the calling tasks hook
01150          * function.
01151          */
01152         void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION;
01153 
01154         /**
01155          * task.h
01156          * <pre>void xTaskGetApplicationTaskTag( TaskHandle_t xTask );</pre>
01157          *
01158          * Returns the pxHookFunction value assigned to the task xTask.
01159          */
01160         TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
01161     #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
01162 #endif /* ifdef configUSE_APPLICATION_TASK_TAG */
01163 
01164 #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
01165 
01166     /* Each task contains an array of pointers that is dimensioned by the
01167     configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h.  The
01168     kernel does not use the pointers itself, so the application writer can use
01169     the pointers for any purpose they wish.  The following two functions are
01170     used to set and query a pointer respectively. */
01171     void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue );
01172     void *pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex );
01173 
01174 #endif
01175 
01176 /**
01177  * task.h
01178  * <pre>BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );</pre>
01179  *
01180  * Calls the hook function associated with xTask.  Passing xTask as NULL has
01181  * the effect of calling the Running tasks (the calling task) hook function.
01182  *
01183  * pvParameter is passed to the hook function for the task to interpret as it
01184  * wants.  The return value is the value returned by the task hook function
01185  * registered by the user.
01186  */
01187 BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ) PRIVILEGED_FUNCTION;
01188 
01189 /**
01190  * xTaskGetIdleTaskHandle() is only available if
01191  * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
01192  *
01193  * Simply returns the handle of the idle task.  It is not valid to call
01194  * xTaskGetIdleTaskHandle() before the scheduler has been started.
01195  */
01196 TaskHandle_t xTaskGetIdleTaskHandle( void );
01197 
01198 /**
01199  * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
01200  * uxTaskGetSystemState() to be available.
01201  *
01202  * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in
01203  * the system.  TaskStatus_t structures contain, among other things, members
01204  * for the task handle, task name, task priority, task state, and total amount
01205  * of run time consumed by the task.  See the TaskStatus_t structure
01206  * definition in this file for the full member list.
01207  *
01208  * NOTE:  This function is intended for debugging use only as its use results in
01209  * the scheduler remaining suspended for an extended period.
01210  *
01211  * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures.
01212  * The array must contain at least one TaskStatus_t structure for each task
01213  * that is under the control of the RTOS.  The number of tasks under the control
01214  * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.
01215  *
01216  * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray
01217  * parameter.  The size is specified as the number of indexes in the array, or
01218  * the number of TaskStatus_t structures contained in the array, not by the
01219  * number of bytes in the array.
01220  *
01221  * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in
01222  * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the
01223  * total run time (as defined by the run time stats clock, see
01224  * http://www.freertos.org/rtos-run-time-stats.html) since the target booted.
01225  * pulTotalRunTime can be set to NULL to omit the total run time information.
01226  *
01227  * @return The number of TaskStatus_t structures that were populated by
01228  * uxTaskGetSystemState().  This should equal the number returned by the
01229  * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed
01230  * in the uxArraySize parameter was too small.
01231  *
01232  * Example usage:
01233    <pre>
01234     // This example demonstrates how a human readable table of run time stats
01235     // information is generated from raw data provided by uxTaskGetSystemState().
01236     // The human readable table is written to pcWriteBuffer
01237     void vTaskGetRunTimeStats( char *pcWriteBuffer )
01238     {
01239     TaskStatus_t *pxTaskStatusArray;
01240     volatile UBaseType_t uxArraySize, x;
01241     uint32_t ulTotalRunTime, ulStatsAsPercentage;
01242 
01243         // Make sure the write buffer does not contain a string.
01244         *pcWriteBuffer = 0x00;
01245 
01246         // Take a snapshot of the number of tasks in case it changes while this
01247         // function is executing.
01248         uxArraySize = uxTaskGetNumberOfTasks();
01249 
01250         // Allocate a TaskStatus_t structure for each task.  An array could be
01251         // allocated statically at compile time.
01252         pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
01253 
01254         if( pxTaskStatusArray != NULL )
01255         {
01256             // Generate raw status information about each task.
01257             uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
01258 
01259             // For percentage calculations.
01260             ulTotalRunTime /= 100UL;
01261 
01262             // Avoid divide by zero errors.
01263             if( ulTotalRunTime > 0 )
01264             {
01265                 // For each populated position in the pxTaskStatusArray array,
01266                 // format the raw data as human readable ASCII data
01267                 for( x = 0; x < uxArraySize; x++ )
01268                 {
01269                     // What percentage of the total run time has the task used?
01270                     // This will always be rounded down to the nearest integer.
01271                     // ulTotalRunTimeDiv100 has already been divided by 100.
01272                     ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
01273 
01274                     if( ulStatsAsPercentage > 0UL )
01275                     {
01276                         sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
01277                     }
01278                     else
01279                     {
01280                         // If the percentage is zero here then the task has
01281                         // consumed less than 1% of the total run time.
01282                         sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
01283                     }
01284 
01285                     pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
01286                 }
01287             }
01288 
01289             // The array is no longer needed, free the memory it consumes.
01290             vPortFree( pxTaskStatusArray );
01291         }
01292     }
01293     </pre>
01294  */
01295 UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime );
01296 
01297 /**
01298  * task. h
01299  * <PRE>void vTaskList( char *pcWriteBuffer );</PRE>
01300  *
01301  * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must
01302  * both be defined as 1 for this function to be available.  See the
01303  * configuration section of the FreeRTOS.org website for more information.
01304  *
01305  * NOTE 1: This function will disable interrupts for its duration.  It is
01306  * not intended for normal application runtime use but as a debug aid.
01307  *
01308  * Lists all the current tasks, along with their current state and stack
01309  * usage high water mark.
01310  *
01311  * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
01312  * suspended ('S').
01313  *
01314  * PLEASE NOTE:
01315  *
01316  * This function is provided for convenience only, and is used by many of the
01317  * demo applications.  Do not consider it to be part of the scheduler.
01318  *
01319  * vTaskList() calls uxTaskGetSystemState(), then formats part of the
01320  * uxTaskGetSystemState() output into a human readable table that displays task
01321  * names, states and stack usage.
01322  *
01323  * vTaskList() has a dependency on the sprintf() C library function that might
01324  * bloat the code size, use a lot of stack, and provide different results on
01325  * different platforms.  An alternative, tiny, third party, and limited
01326  * functionality implementation of sprintf() is provided in many of the
01327  * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
01328  * printf-stdarg.c does not provide a full snprintf() implementation!).
01329  *
01330  * It is recommended that production systems call uxTaskGetSystemState()
01331  * directly to get access to raw stats data, rather than indirectly through a
01332  * call to vTaskList().
01333  *
01334  * @param pcWriteBuffer A buffer into which the above mentioned details
01335  * will be written, in ASCII form.  This buffer is assumed to be large
01336  * enough to contain the generated report.  Approximately 40 bytes per
01337  * task should be sufficient.
01338  *
01339  * \defgroup vTaskList vTaskList
01340  * \ingroup TaskUtils
01341  */
01342 void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
01343 
01344 /**
01345  * task. h
01346  * <PRE>void vTaskGetRunTimeStats( char *pcWriteBuffer );</PRE>
01347  *
01348  * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
01349  * must both be defined as 1 for this function to be available.  The application
01350  * must also then provide definitions for
01351  * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
01352  * to configure a peripheral timer/counter and return the timers current count
01353  * value respectively.  The counter should be at least 10 times the frequency of
01354  * the tick count.
01355  *
01356  * NOTE 1: This function will disable interrupts for its duration.  It is
01357  * not intended for normal application runtime use but as a debug aid.
01358  *
01359  * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
01360  * accumulated execution time being stored for each task.  The resolution
01361  * of the accumulated time value depends on the frequency of the timer
01362  * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
01363  * Calling vTaskGetRunTimeStats() writes the total execution time of each
01364  * task into a buffer, both as an absolute count value and as a percentage
01365  * of the total system execution time.
01366  *
01367  * NOTE 2:
01368  *
01369  * This function is provided for convenience only, and is used by many of the
01370  * demo applications.  Do not consider it to be part of the scheduler.
01371  *
01372  * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the
01373  * uxTaskGetSystemState() output into a human readable table that displays the
01374  * amount of time each task has spent in the Running state in both absolute and
01375  * percentage terms.
01376  *
01377  * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function
01378  * that might bloat the code size, use a lot of stack, and provide different
01379  * results on different platforms.  An alternative, tiny, third party, and
01380  * limited functionality implementation of sprintf() is provided in many of the
01381  * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
01382  * printf-stdarg.c does not provide a full snprintf() implementation!).
01383  *
01384  * It is recommended that production systems call uxTaskGetSystemState() directly
01385  * to get access to raw stats data, rather than indirectly through a call to
01386  * vTaskGetRunTimeStats().
01387  *
01388  * @param pcWriteBuffer A buffer into which the execution times will be
01389  * written, in ASCII form.  This buffer is assumed to be large enough to
01390  * contain the generated report.  Approximately 40 bytes per task should
01391  * be sufficient.
01392  *
01393  * \defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats
01394  * \ingroup TaskUtils
01395  */
01396 void vTaskGetRunTimeStats( char *pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
01397 
01398 /**
01399  * task. h
01400  * <PRE>BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );</PRE>
01401  *
01402  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
01403  * function to be available.
01404  *
01405  * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
01406  * "notification value", which is a 32-bit unsigned integer (uint32_t).
01407  *
01408  * Events can be sent to a task using an intermediary object.  Examples of such
01409  * objects are queues, semaphores, mutexes and event groups.  Task notifications
01410  * are a method of sending an event directly to a task without the need for such
01411  * an intermediary object.
01412  *
01413  * A notification sent to a task can optionally perform an action, such as
01414  * update, overwrite or increment the task's notification value.  In that way
01415  * task notifications can be used to send data to a task, or be used as light
01416  * weight and fast binary or counting semaphores.
01417  *
01418  * A notification sent to a task will remain pending until it is cleared by the
01419  * task calling xTaskNotifyWait() or ulTaskNotifyTake().  If the task was
01420  * already in the Blocked state to wait for a notification when the notification
01421  * arrives then the task will automatically be removed from the Blocked state
01422  * (unblocked) and the notification cleared.
01423  *
01424  * A task can use xTaskNotifyWait() to [optionally] block to wait for a
01425  * notification to be pending, or ulTaskNotifyTake() to [optionally] block
01426  * to wait for its notification value to have a non-zero value.  The task does
01427  * not consume any CPU time while it is in the Blocked state.
01428  *
01429  * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
01430  *
01431  * @param xTaskToNotify The handle of the task being notified.  The handle to a
01432  * task can be returned from the xTaskCreate() API function used to create the
01433  * task, and the handle of the currently running task can be obtained by calling
01434  * xTaskGetCurrentTaskHandle().
01435  *
01436  * @param ulValue Data that can be sent with the notification.  How the data is
01437  * used depends on the value of the eAction parameter.
01438  *
01439  * @param eAction Specifies how the notification updates the task's notification
01440  * value, if at all.  Valid values for eAction are as follows:
01441  *
01442  *  eSetBits -
01443  *  The task's notification value is bitwise ORed with ulValue.  xTaskNofify()
01444  *  always returns pdPASS in this case.
01445  *
01446  *  eIncrement -
01447  *  The task's notification value is incremented.  ulValue is not used and
01448  *  xTaskNotify() always returns pdPASS in this case.
01449  *
01450  *  eSetValueWithOverwrite -
01451  *  The task's notification value is set to the value of ulValue, even if the
01452  *  task being notified had not yet processed the previous notification (the
01453  *  task already had a notification pending).  xTaskNotify() always returns
01454  *  pdPASS in this case.
01455  *
01456  *  eSetValueWithoutOverwrite -
01457  *  If the task being notified did not already have a notification pending then
01458  *  the task's notification value is set to ulValue and xTaskNotify() will
01459  *  return pdPASS.  If the task being notified already had a notification
01460  *  pending then no action is performed and pdFAIL is returned.
01461  *
01462  *  eNoAction -
01463  *  The task receives a notification without its notification value being
01464  *  updated.  ulValue is not used and xTaskNotify() always returns pdPASS in
01465  *  this case.
01466  *
01467  *  pulPreviousNotificationValue -
01468  *  Can be used to pass out the subject task's notification value before any
01469  *  bits are modified by the notify function.
01470  *
01471  * @return Dependent on the value of eAction.  See the description of the
01472  * eAction parameter.
01473  *
01474  * \defgroup xTaskNotify xTaskNotify
01475  * \ingroup TaskNotifications
01476  */
01477 BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue );
01478 #define xTaskNotify( xTaskToNotify, ulValue, eAction ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL )
01479 #define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
01480 
01481 /**
01482  * task. h
01483  * <PRE>BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
01484  *
01485  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
01486  * function to be available.
01487  *
01488  * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
01489  * "notification value", which is a 32-bit unsigned integer (uint32_t).
01490  *
01491  * A version of xTaskNotify() that can be used from an interrupt service routine
01492  * (ISR).
01493  *
01494  * Events can be sent to a task using an intermediary object.  Examples of such
01495  * objects are queues, semaphores, mutexes and event groups.  Task notifications
01496  * are a method of sending an event directly to a task without the need for such
01497  * an intermediary object.
01498  *
01499  * A notification sent to a task can optionally perform an action, such as
01500  * update, overwrite or increment the task's notification value.  In that way
01501  * task notifications can be used to send data to a task, or be used as light
01502  * weight and fast binary or counting semaphores.
01503  *
01504  * A notification sent to a task will remain pending until it is cleared by the
01505  * task calling xTaskNotifyWait() or ulTaskNotifyTake().  If the task was
01506  * already in the Blocked state to wait for a notification when the notification
01507  * arrives then the task will automatically be removed from the Blocked state
01508  * (unblocked) and the notification cleared.
01509  *
01510  * A task can use xTaskNotifyWait() to [optionally] block to wait for a
01511  * notification to be pending, or ulTaskNotifyTake() to [optionally] block
01512  * to wait for its notification value to have a non-zero value.  The task does
01513  * not consume any CPU time while it is in the Blocked state.
01514  *
01515  * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
01516  *
01517  * @param xTaskToNotify The handle of the task being notified.  The handle to a
01518  * task can be returned from the xTaskCreate() API function used to create the
01519  * task, and the handle of the currently running task can be obtained by calling
01520  * xTaskGetCurrentTaskHandle().
01521  *
01522  * @param ulValue Data that can be sent with the notification.  How the data is
01523  * used depends on the value of the eAction parameter.
01524  *
01525  * @param eAction Specifies how the notification updates the task's notification
01526  * value, if at all.  Valid values for eAction are as follows:
01527  *
01528  *  eSetBits -
01529  *  The task's notification value is bitwise ORed with ulValue.  xTaskNofify()
01530  *  always returns pdPASS in this case.
01531  *
01532  *  eIncrement -
01533  *  The task's notification value is incremented.  ulValue is not used and
01534  *  xTaskNotify() always returns pdPASS in this case.
01535  *
01536  *  eSetValueWithOverwrite -
01537  *  The task's notification value is set to the value of ulValue, even if the
01538  *  task being notified had not yet processed the previous notification (the
01539  *  task already had a notification pending).  xTaskNotify() always returns
01540  *  pdPASS in this case.
01541  *
01542  *  eSetValueWithoutOverwrite -
01543  *  If the task being notified did not already have a notification pending then
01544  *  the task's notification value is set to ulValue and xTaskNotify() will
01545  *  return pdPASS.  If the task being notified already had a notification
01546  *  pending then no action is performed and pdFAIL is returned.
01547  *
01548  *  eNoAction -
01549  *  The task receives a notification without its notification value being
01550  *  updated.  ulValue is not used and xTaskNotify() always returns pdPASS in
01551  *  this case.
01552  *
01553  * @param pxHigherPriorityTaskWoken  xTaskNotifyFromISR() will set
01554  * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
01555  * task to which the notification was sent to leave the Blocked state, and the
01556  * unblocked task has a priority higher than the currently running task.  If
01557  * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should
01558  * be requested before the interrupt is exited.  How a context switch is
01559  * requested from an ISR is dependent on the port - see the documentation page
01560  * for the port in use.
01561  *
01562  * @return Dependent on the value of eAction.  See the description of the
01563  * eAction parameter.
01564  *
01565  * \defgroup xTaskNotify xTaskNotify
01566  * \ingroup TaskNotifications
01567  */
01568 BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );
01569 
01570 /**
01571  * task. h
01572  * <PRE>BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );</pre>
01573  *
01574  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
01575  * function to be available.
01576  *
01577  * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
01578  * "notification value", which is a 32-bit unsigned integer (uint32_t).
01579  *
01580  * Events can be sent to a task using an intermediary object.  Examples of such
01581  * objects are queues, semaphores, mutexes and event groups.  Task notifications
01582  * are a method of sending an event directly to a task without the need for such
01583  * an intermediary object.
01584  *
01585  * A notification sent to a task can optionally perform an action, such as
01586  * update, overwrite or increment the task's notification value.  In that way
01587  * task notifications can be used to send data to a task, or be used as light
01588  * weight and fast binary or counting semaphores.
01589  *
01590  * A notification sent to a task will remain pending until it is cleared by the
01591  * task calling xTaskNotifyWait() or ulTaskNotifyTake().  If the task was
01592  * already in the Blocked state to wait for a notification when the notification
01593  * arrives then the task will automatically be removed from the Blocked state
01594  * (unblocked) and the notification cleared.
01595  *
01596  * A task can use xTaskNotifyWait() to [optionally] block to wait for a
01597  * notification to be pending, or ulTaskNotifyTake() to [optionally] block
01598  * to wait for its notification value to have a non-zero value.  The task does
01599  * not consume any CPU time while it is in the Blocked state.
01600  *
01601  * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
01602  *
01603  * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value
01604  * will be cleared in the calling task's notification value before the task
01605  * checks to see if any notifications are pending, and optionally blocks if no
01606  * notifications are pending.  Setting ulBitsToClearOnEntry to ULONG_MAX (if
01607  * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have
01608  * the effect of resetting the task's notification value to 0.  Setting
01609  * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.
01610  *
01611  * @param ulBitsToClearOnExit If a notification is pending or received before
01612  * the calling task exits the xTaskNotifyWait() function then the task's
01613  * notification value (see the xTaskNotify() API function) is passed out using
01614  * the pulNotificationValue parameter.  Then any bits that are set in
01615  * ulBitsToClearOnExit will be cleared in the task's notification value (note
01616  * *pulNotificationValue is set before any bits are cleared).  Setting
01617  * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL
01618  * (if limits.h is not included) will have the effect of resetting the task's
01619  * notification value to 0 before the function exits.  Setting
01620  * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged
01621  * when the function exits (in which case the value passed out in
01622  * pulNotificationValue will match the task's notification value).
01623  *
01624  * @param pulNotificationValue Used to pass the task's notification value out
01625  * of the function.  Note the value passed out will not be effected by the
01626  * clearing of any bits caused by ulBitsToClearOnExit being non-zero.
01627  *
01628  * @param xTicksToWait The maximum amount of time that the task should wait in
01629  * the Blocked state for a notification to be received, should a notification
01630  * not already be pending when xTaskNotifyWait() was called.  The task
01631  * will not consume any processing time while it is in the Blocked state.  This
01632  * is specified in kernel ticks, the macro pdMS_TO_TICSK( value_in_ms ) can be
01633  * used to convert a time specified in milliseconds to a time specified in
01634  * ticks.
01635  *
01636  * @return If a notification was received (including notifications that were
01637  * already pending when xTaskNotifyWait was called) then pdPASS is
01638  * returned.  Otherwise pdFAIL is returned.
01639  *
01640  * \defgroup xTaskNotifyWait xTaskNotifyWait
01641  * \ingroup TaskNotifications
01642  */
01643 BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
01644 
01645 /**
01646  * task. h
01647  * <PRE>BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );</PRE>
01648  *
01649  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
01650  * to be available.
01651  *
01652  * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
01653  * "notification value", which is a 32-bit unsigned integer (uint32_t).
01654  *
01655  * Events can be sent to a task using an intermediary object.  Examples of such
01656  * objects are queues, semaphores, mutexes and event groups.  Task notifications
01657  * are a method of sending an event directly to a task without the need for such
01658  * an intermediary object.
01659  *
01660  * A notification sent to a task can optionally perform an action, such as
01661  * update, overwrite or increment the task's notification value.  In that way
01662  * task notifications can be used to send data to a task, or be used as light
01663  * weight and fast binary or counting semaphores.
01664  *
01665  * xTaskNotifyGive() is a helper macro intended for use when task notifications
01666  * are used as light weight and faster binary or counting semaphore equivalents.
01667  * Actual FreeRTOS semaphores are given using the xSemaphoreGive() API function,
01668  * the equivalent action that instead uses a task notification is
01669  * xTaskNotifyGive().
01670  *
01671  * When task notifications are being used as a binary or counting semaphore
01672  * equivalent then the task being notified should wait for the notification
01673  * using the ulTaskNotificationTake() API function rather than the
01674  * xTaskNotifyWait() API function.
01675  *
01676  * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
01677  *
01678  * @param xTaskToNotify The handle of the task being notified.  The handle to a
01679  * task can be returned from the xTaskCreate() API function used to create the
01680  * task, and the handle of the currently running task can be obtained by calling
01681  * xTaskGetCurrentTaskHandle().
01682  *
01683  * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the
01684  * eAction parameter set to eIncrement - so pdPASS is always returned.
01685  *
01686  * \defgroup xTaskNotifyGive xTaskNotifyGive
01687  * \ingroup TaskNotifications
01688  */
01689 #define xTaskNotifyGive( xTaskToNotify ) xTaskNotify( ( xTaskToNotify ), 0, eIncrement );
01690 
01691 /**
01692  * task. h
01693  * <PRE>void vTaskNotifyGiveFromISR( TaskHandle_t xTaskHandle, BaseType_t *pxHigherPriorityTaskWoken );
01694  *
01695  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
01696  * to be available.
01697  *
01698  * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
01699  * "notification value", which is a 32-bit unsigned integer (uint32_t).
01700  *
01701  * A version of xTaskNotifyGive() that can be called from an interrupt service
01702  * routine (ISR).
01703  *
01704  * Events can be sent to a task using an intermediary object.  Examples of such
01705  * objects are queues, semaphores, mutexes and event groups.  Task notifications
01706  * are a method of sending an event directly to a task without the need for such
01707  * an intermediary object.
01708  *
01709  * A notification sent to a task can optionally perform an action, such as
01710  * update, overwrite or increment the task's notification value.  In that way
01711  * task notifications can be used to send data to a task, or be used as light
01712  * weight and fast binary or counting semaphores.
01713  *
01714  * vTaskNotifyGiveFromISR() is intended for use when task notifications are
01715  * used as light weight and faster binary or counting semaphore equivalents.
01716  * Actual FreeRTOS semaphores are given from an ISR using the
01717  * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses
01718  * a task notification is vTaskNotifyGiveFromISR().
01719  *
01720  * When task notifications are being used as a binary or counting semaphore
01721  * equivalent then the task being notified should wait for the notification
01722  * using the ulTaskNotificationTake() API function rather than the
01723  * xTaskNotifyWait() API function.
01724  *
01725  * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
01726  *
01727  * @param xTaskToNotify The handle of the task being notified.  The handle to a
01728  * task can be returned from the xTaskCreate() API function used to create the
01729  * task, and the handle of the currently running task can be obtained by calling
01730  * xTaskGetCurrentTaskHandle().
01731  *
01732  * @param pxHigherPriorityTaskWoken  vTaskNotifyGiveFromISR() will set
01733  * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
01734  * task to which the notification was sent to leave the Blocked state, and the
01735  * unblocked task has a priority higher than the currently running task.  If
01736  * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch
01737  * should be requested before the interrupt is exited.  How a context switch is
01738  * requested from an ISR is dependent on the port - see the documentation page
01739  * for the port in use.
01740  *
01741  * \defgroup xTaskNotifyWait xTaskNotifyWait
01742  * \ingroup TaskNotifications
01743  */
01744 void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify, BaseType_t *pxHigherPriorityTaskWoken );
01745 
01746 /**
01747  * task. h
01748  * <PRE>uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );</pre>
01749  *
01750  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
01751  * function to be available.
01752  *
01753  * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
01754  * "notification value", which is a 32-bit unsigned integer (uint32_t).
01755  *
01756  * Events can be sent to a task using an intermediary object.  Examples of such
01757  * objects are queues, semaphores, mutexes and event groups.  Task notifications
01758  * are a method of sending an event directly to a task without the need for such
01759  * an intermediary object.
01760  *
01761  * A notification sent to a task can optionally perform an action, such as
01762  * update, overwrite or increment the task's notification value.  In that way
01763  * task notifications can be used to send data to a task, or be used as light
01764  * weight and fast binary or counting semaphores.
01765  *
01766  * ulTaskNotifyTake() is intended for use when a task notification is used as a
01767  * faster and lighter weight binary or counting semaphore alternative.  Actual
01768  * FreeRTOS semaphores are taken using the xSemaphoreTake() API function, the
01769  * equivalent action that instead uses a task notification is
01770  * ulTaskNotifyTake().
01771  *
01772  * When a task is using its notification value as a binary or counting semaphore
01773  * other tasks should send notifications to it using the xTaskNotifyGive()
01774  * macro, or xTaskNotify() function with the eAction parameter set to
01775  * eIncrement.
01776  *
01777  * ulTaskNotifyTake() can either clear the task's notification value to
01778  * zero on exit, in which case the notification value acts like a binary
01779  * semaphore, or decrement the task's notification value on exit, in which case
01780  * the notification value acts like a counting semaphore.
01781  *
01782  * A task can use ulTaskNotifyTake() to [optionally] block to wait for a
01783  * the task's notification value to be non-zero.  The task does not consume any
01784  * CPU time while it is in the Blocked state.
01785  *
01786  * Where as xTaskNotifyWait() will return when a notification is pending,
01787  * ulTaskNotifyTake() will return when the task's notification value is
01788  * not zero.
01789  *
01790  * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
01791  *
01792  * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's
01793  * notification value is decremented when the function exits.  In this way the
01794  * notification value acts like a counting semaphore.  If xClearCountOnExit is
01795  * not pdFALSE then the task's notification value is cleared to zero when the
01796  * function exits.  In this way the notification value acts like a binary
01797  * semaphore.
01798  *
01799  * @param xTicksToWait The maximum amount of time that the task should wait in
01800  * the Blocked state for the task's notification value to be greater than zero,
01801  * should the count not already be greater than zero when
01802  * ulTaskNotifyTake() was called.  The task will not consume any processing
01803  * time while it is in the Blocked state.  This is specified in kernel ticks,
01804  * the macro pdMS_TO_TICSK( value_in_ms ) can be used to convert a time
01805  * specified in milliseconds to a time specified in ticks.
01806  *
01807  * @return The task's notification count before it is either cleared to zero or
01808  * decremented (see the xClearCountOnExit parameter).
01809  *
01810  * \defgroup ulTaskNotifyTake ulTaskNotifyTake
01811  * \ingroup TaskNotifications
01812  */
01813 uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
01814 
01815 /*-----------------------------------------------------------
01816  * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
01817  *----------------------------------------------------------*/
01818 
01819 /*
01820  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS ONLY
01821  * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
01822  * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
01823  *
01824  * Called from the real time kernel tick (either preemptive or cooperative),
01825  * this increments the tick count and checks if any tasks that are blocked
01826  * for a finite period required removing from a blocked list and placing on
01827  * a ready list.  If a non-zero value is returned then a context switch is
01828  * required because either:
01829  *   + A task was removed from a blocked list because its timeout had expired,
01830  *     or
01831  *   + Time slicing is in use and there is a task of equal priority to the
01832  *     currently running task.
01833  */
01834 BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
01835 
01836 /*
01837  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN
01838  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
01839  *
01840  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
01841  *
01842  * Removes the calling task from the ready list and places it both
01843  * on the list of tasks waiting for a particular event, and the
01844  * list of delayed tasks.  The task will be removed from both lists
01845  * and replaced on the ready list should either the event occur (and
01846  * there be no higher priority tasks waiting on the same event) or
01847  * the delay period expires.
01848  *
01849  * The 'unordered' version replaces the event list item value with the
01850  * xItemValue value, and inserts the list item at the end of the list.
01851  *
01852  * The 'ordered' version uses the existing event list item value (which is the
01853  * owning tasks priority) to insert the list item into the event list is task
01854  * priority order.
01855  *
01856  * @param pxEventList The list containing tasks that are blocked waiting
01857  * for the event to occur.
01858  *
01859  * @param xItemValue The item value to use for the event list item when the
01860  * event list is not ordered by task priority.
01861  *
01862  * @param xTicksToWait The maximum amount of time that the task should wait
01863  * for the event to occur.  This is specified in kernel ticks,the constant
01864  * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time
01865  * period.
01866  */
01867 void vTaskPlaceOnEventList( List_t * const pxEventList, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
01868 void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const TickType_t xItemValue, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
01869 
01870 /*
01871  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN
01872  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
01873  *
01874  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
01875  *
01876  * This function performs nearly the same function as vTaskPlaceOnEventList().
01877  * The difference being that this function does not permit tasks to block
01878  * indefinitely, whereas vTaskPlaceOnEventList() does.
01879  *
01880  */
01881 void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
01882 
01883 /*
01884  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN
01885  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
01886  *
01887  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
01888  *
01889  * Removes a task from both the specified event list and the list of blocked
01890  * tasks, and places it on a ready queue.
01891  *
01892  * xTaskRemoveFromEventList()/xTaskRemoveFromUnorderedEventList() will be called
01893  * if either an event occurs to unblock a task, or the block timeout period
01894  * expires.
01895  *
01896  * xTaskRemoveFromEventList() is used when the event list is in task priority
01897  * order.  It removes the list item from the head of the event list as that will
01898  * have the highest priority owning task of all the tasks on the event list.
01899  * xTaskRemoveFromUnorderedEventList() is used when the event list is not
01900  * ordered and the event list items hold something other than the owning tasks
01901  * priority.  In this case the event list item value is updated to the value
01902  * passed in the xItemValue parameter.
01903  *
01904  * @return pdTRUE if the task being removed has a higher priority than the task
01905  * making the call, otherwise pdFALSE.
01906  */
01907 BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION;
01908 BaseType_t xTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, const TickType_t xItemValue ) PRIVILEGED_FUNCTION;
01909 
01910 /*
01911  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS ONLY
01912  * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
01913  * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
01914  *
01915  * Sets the pointer to the current TCB to the TCB of the highest priority task
01916  * that is ready to run.
01917  */
01918 void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
01919 
01920 /*
01921  * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE.  THEY ARE USED BY
01922  * THE EVENT BITS MODULE.
01923  */
01924 TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION;
01925 
01926 /*
01927  * Return the handle of the calling task.
01928  */
01929 TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
01930 
01931 /*
01932  * Capture the current time status for future reference.
01933  */
01934 void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
01935 
01936 /*
01937  * Compare the time status now with that previously captured to see if the
01938  * timeout has expired.
01939  */
01940 BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;
01941 
01942 /*
01943  * Shortcut used by the queue implementation to prevent unnecessary call to
01944  * taskYIELD();
01945  */
01946 void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
01947 
01948 /*
01949  * Returns the scheduler state as taskSCHEDULER_RUNNING,
01950  * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
01951  */
01952 BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
01953 
01954 /*
01955  * Raises the priority of the mutex holder to that of the calling task should
01956  * the mutex holder have a priority less than the calling task.
01957  */
01958 void vTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
01959 
01960 /*
01961  * Set the priority of a task back to its proper priority in the case that it
01962  * inherited a higher priority while it was holding a semaphore.
01963  */
01964 BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
01965 
01966 /*
01967  * Generic version of the task creation function which is in turn called by the
01968  * xTaskCreate() and xTaskCreateRestricted() macros.
01969  */
01970 BaseType_t xTaskGenericCreate( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, TaskHandle_t * const pxCreatedTask, StackType_t * const puxStackBuffer, const MemoryRegion_t * const xRegions ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
01971 
01972 /*
01973  * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
01974  */
01975 UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
01976 
01977 /*
01978  * Set the uxTaskNumber of the task referenced by the xTask parameter to
01979  * uxHandle.
01980  */
01981 void vTaskSetTaskNumber( TaskHandle_t xTask, const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION;
01982 
01983 /*
01984  * Only available when configUSE_TICKLESS_IDLE is set to 1.
01985  * If tickless mode is being used, or a low power mode is implemented, then
01986  * the tick interrupt will not execute during idle periods.  When this is the
01987  * case, the tick count value maintained by the scheduler needs to be kept up
01988  * to date with the actual execution time by being skipped forward by a time
01989  * equal to the idle period.
01990  */
01991 void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION;
01992 
01993 /*
01994  * Only avilable when configUSE_TICKLESS_IDLE is set to 1.
01995  * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port
01996  * specific sleep function to determine if it is ok to proceed with the sleep,
01997  * and if it is ok to proceed, if it is ok to sleep indefinitely.
01998  *
01999  * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only
02000  * called with the scheduler suspended, not from within a critical section.  It
02001  * is therefore possible for an interrupt to request a context switch between
02002  * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being
02003  * entered.  eTaskConfirmSleepModeStatus() should be called from a short
02004  * critical section between the timer being stopped and the sleep mode being
02005  * entered to ensure it is ok to proceed into the sleep mode.
02006  */
02007 eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION;
02008 
02009 /*
02010  * For internal use only.  Increment the mutex held count when a mutex is
02011  * taken and return the handle of the task that has taken the mutex.
02012  */
02013 void *pvTaskIncrementMutexHeldCount( void );
02014 
02015 #ifdef __cplusplus
02016 }
02017 #endif
02018 #endif /* INC_TASK_H */
02019 
02020 
02021 
02022