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