OpenCores
URL https://opencores.org/ocsvn/openfire2/openfire2/trunk

Subversion Repositories openfire2

[/] [openfire2/] [trunk/] [sw/] [freertos/] [task.h] - Blame information for rev 6

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.