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