1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
32 33 34 35
36
37 package ti.sysbios.knl;
38
39 import xdc.rov.ViewInfo;
40
41 import xdc.runtime.Error;
42 import xdc.runtime.Assert;
43 import xdc.runtime.Diags;
44 import xdc.runtime.Log;
45 import xdc.runtime.IHeap;
46
47 import ti.sysbios.knl.Queue;
48
49 /*!
50 * ======== Task ========
51 * Task Manager.
52 *
53 * The Task module makes available a set of functions that manipulate task
54 * objects accessed through pointers of type {@link #Handle}. Tasks represent
55 * independent threads of control that conceptually execute functions in
56 * parallel within a single C program; in reality, concurrency is achieved
57 * by switching the processor from one task to another.
58 *
59 * When you create a task, it is provided with its own run-time stack,
60 * used for storing local variables as well as for further nesting of
61 * function calls. Each stack must be large enough to handle normal
62 * subroutine calls and one task preemption context.
63 * A task preemption context is the context that gets saved when one task
64 * preempts another as a result of an interrupt thread readying
65 * a higher-priority task.
66 *
67 * All tasks executing within a single program share a common set of
68 * global variables, accessed according to the standard rules of scope
69 * defined for C functions.
70 *
71 * Each task is in one of five modes of execution at any point in time:
72 * running, ready, blocked, terminated, or inactive. By design, there is
73 * always one
74 * (and only one) task currently running, even if it is only the idle task
75 * managed internally by Task. The current task can be suspended from
76 * execution by calling certain Task functions, as well as functions
77 * provided by other modules like the Semaphore or Event Modules.
78 * The current task
79 * can also terminate its own execution. In either case, the processor
80 * is switched to the highest priority task that is ready to run.
81 *
82 * You can assign numeric priorities to tasks. Tasks are
83 * readied for execution in strict priority order; tasks of the same
84 * priority are scheduled on a first-come, first-served basis.
85 * The priority of the currently running task is never lower
86 * than the priority of any ready task. Conversely, the running task
87 * is preempted and re-scheduled for execution whenever there exists
88 * some ready task of higher priority.
89 *
90 * @a(Task Deletion)
91 *
92 * Any dynamically created task that is not in the Task_Mode_RUNNING
93 * state (ie not the currently running task) can be deleted using the
94 * {@link #delete} API.
95 *
96 * Task_delete() removes the task from all internal queues and calls
97 * Memory_free() is used to free the task object and its stack.
98 * Memory_free() must acquire a lock to the memory before proceeding.
99 * If another task already holds a lock to the memory, then the thread
100 * performing the delete will be blocked until the memory is unlocked.
101 *
102 * Note:
103 * Task_delete() should be called with extreme care.
104 * As mentioned above, the scope of Task_delete() is limited to
105 * freeing the Task object itself, freeing the task's stack memory
106 * if it was allocated at create time, and removing the task from
107 * any SYS/BIOS-internal state structures.
108 *
109 * SYS/BIOS does not keep track of any resources the task may have
110 * acquired or used during its lifetime.
111 *
112 * It is the application's responsibility to guarantee the integrity
113 * of a task's partnerships prior to deleting that task.
114 *
115 * For example, if a task has obtained exclusive access to a resource,
116 * deleting that task will make the resource forever unavailable.
117 *
118 * Task_delete() sets the referenced task handle to NULL. Any subsequent
119 * call to a Task instance API using that null task handle will behave
120 * unpredictably and will usually result in an application crash.
121 *
122 * Assuming a task completely cleans up after itself prior to calling
123 * Task_exit() (or falling through the the bottom of the task
124 * function), it is then safest to use Task_delete() only when a task
125 * is in the 'Task_Mode_TERMINATED' state.
126 *
127 * Delete hooks:
128 * You can specify application-wide Delete hook functions that
129 * run whenever a task is deleted. See the discussion of Hook Functions
130 * below for details.
131 *
132 * Task_delete() constraints:
133 * @p(blist)
134 * -The task cannot be the currently executing task (Task_self()).
135 * -Task_delete cannot be called from a Swi or Hwi.
136 * -No check is performed to prevent Task_delete from being used on a
137 * statically-created object. If a program attempts to delete a task object
138 * that was created statically, the Memory_free() call will result in an
139 * assertion failure in its corresponding Heap manager, causing the
140 * application to exit.
141 * @p
142 *
143 * @a(Stack Alignment)
144 *
145 * Stack size parameters for both static and dynamic tasks are rounded
146 * up to the nearest integer multiple of a target-specific alignment
147 * requirement.
148 *
149 * In the case of Task's which are created with a user-provided stack,
150 * both the base address and the stackSize are aligned. The base address
151 * is increased to the nearest aligned address. The stack size is decreased
152 * accordingly and then rounded down to the nearest integer multiple of the
153 * target-specific required alignment.
154 *
155 * @p(html)
156 * <a name="hookfunc"></a>
157 * @p
158 *
159 * @a(Hook Functions)
160 *
161 * Sets of hook functions can be specified for the Task module. Each
162 * set can contains these hook functions:
163 * @p(blist)
164 * -Register: A function called before any statically created tasks
165 * are initialized at runtime. The register hook is called at boot time
166 * before main() and before interrupts are enabled.
167 * -Create: A function that is called when a task is created.
168 * This includes tasks that are created statically and those
169 * created dynamically using {@link #create} or {@link #construct}.
170 * The create hook is called outside of a Task_disable/enable block and
171 * before the task has been added to the ready list.
172 * -Ready: A function that is called when a task becomes ready to run.
173 * The ready hook is called from within a Task_disable/enable block with
174 * interrupts enabled.
175 * -Switch: A function that is called just before a task switch
176 * occurs. The 'prev' and 'next' task handles are passed to the Switch
177 * hook. 'prev' is set to NULL for the initial task switch that occurs
178 * during SYS/BIOS startup. The Switch hook is called from within a
179 * Task_disable/enable block with interrupts enabled.
180 * -Exit: A function that is called when a task exits using
181 * {@link #exit}. The exit hook is passed the handle of the exiting
182 * task. The exit hook is called outside of a Task_disable/enable block
183 * and before the task has been removed from the kernel lists.
184 * -Delete: A function that is called when any task is deleted at
185 * run-time with {@link #delete}. The delete hook is called outside
186 * of a Task_disable/enable block.
187 * @p
188 * Hook functions can only be configured statically.
189 *
190 * If you define more than one set of hook functions, all the functions
191 * of a particular type will be run when a Swi triggers that type of
192 * hook.
193 *
194 * @p(html)
195 * <B>Register Function</B>
196 * @p
197 *
198 * The Register function is provided to allow a hook set to store its
199 * hookset ID. This id can be passed to {@link #setHookContext} and
200 * {@link #getHookContext} to set or get hookset-specific context. The
201 * Register function must be specified if the hook implementation
202 * needs to use {@link #setHookContext} or {@link #getHookContext}.
203 * The registerFxn hook function is called during system initialization
204 * before interrupts have been enabled.
205 *
206 * @p(code)
207 * Void myRegisterFxn(Int id);
208 * @p
209 *
210 * @p(html)
211 * <B>Create and Delete Functions</B>
212 * @p
213 *
214 * The create and delete functions are called whenever a Task is created
215 * or deleted. They are called with interrupts enabled (unless called
216 * at boot time or from main()).
217 *
218 * @p(code)
219 * Void myCreateFxn(Task_Handle task, Error_Block *eb);
220 * @p
221 *
222 * @p(code)
223 * Void myDeleteFxn(Task_Handle task);
224 * @p
225 *
226 * @p(html)
227 * <B>Switch Function</B>
228 * @p
229 *
230 * If a switch function is specified, it is invoked just before the new task
231 * is switched to. The switch function is called with interrupts enabled.
232 *
233 * This function can be used to save/restore additional task context (for
234 * example, external hardware registers), to check for task stack overflow,
235 * to monitor the time used by each task, etc.
236 *
237 * @p(code)
238 * Void mySwitchFxn(Task_Handle prev, Task_Handle next);
239 * @p
240 *
241 * To properly handle the switch to the first task your switchFxn should
242 * check for "prev == NULL" before using prev:
243 *
244 * @p(code)
245 * Void mySwitchFxn(Task_Handle prev, Task_Handle next)
246 * {
247 * if (prev != NULL) {
248 * ...
249 * }
250 * ...
251 * }
252 * @p
253 *
254 * @p(html)
255 * <B>Ready Function</B>
256 * @p
257 *
258 * If a ready function is specified, it is invoked whenever a task is made
259 * ready to run. The ready function is called with interrupts enabled
260 * (unless called at boot time or from main()).
261 *
262 * @p(code)
263 * Void myReadyFxn(Task_Handle task);
264 * @p
265 *
266 * @p(html)
267 * <B>Exit Function</B>
268 * @p
269 *
270 * If an exit function is specified, it is invoked when a task exits (via
271 * call to Task_exit() or when a task returns from its' main function).
272 * The Exit Function is called with interrupts enabled.
273 *
274 * @p(code)
275 * Void myExitFxn(Task_Handle task);
276 * @p
277 *
278 * @p(html)
279 * <h3> Calling Context </h3>
280 * <table border="1" cellpadding="3">
281 * <colgroup span="1"></colgroup> <colgroup span="5" align="center">
282 * </colgroup>
283 *
284 * <tr><th> Function </th><th> Hwi </th><th> Swi </th>
285 * <th> Task </th><th> Main </th><th> Startup </th></tr>
286 * <!-- -->
287 * <tr><td> {@link #create} </td><td> N </td><td> N </td>
288 * <td> Y </td><td> Y </td><td> N </td></tr>
289 * <tr><td> {@link #disable} </td><td> Y </td><td> Y </td>
290 * <td> Y </td><td> Y </td><td> N </td></tr>
291 * <tr><td> {@link #exit} </td><td> N </td><td> N </td>
292 * <td> Y </td><td> N </td><td> N </td></tr>
293 * <tr><td> {@link #getIdleTask} </td><td> Y </td><td> Y </td>
294 * <td> Y </td><td> Y </td><td> N </td></tr>
295 * <tr><td> {@link #Params_init} </td><td> Y </td><td> Y </td>
296 * <td> Y </td><td> Y </td><td> Y </td></tr>
297 * <tr><td> {@link #restore} </td><td> Y </td><td> Y </td>
298 * <td> Y </td><td> Y </td><td> N </td></tr>
299 * <tr><td> {@link #self} </td><td> Y </td><td> Y </td>
300 * <td> Y </td><td> Y </td><td> N </td></tr>
301 * <tr><td> {@link #sleep} </td><td> N </td><td> N </td>
302 * <td> Y </td><td> N </td><td> N </td></tr>
303 * <tr><td> {@link #yield} </td><td> Y </td><td> Y </td>
304 * <td> Y </td><td> N </td><td> N </td></tr>
305 * <tr><td> {@link #construct} </td><td> N </td><td> N </td>
306 * <td> Y </td><td> Y </td><td> N </td></tr>
307 * <tr><td> {@link #delete} </td><td> N </td><td> N </td>
308 * <td> Y </td><td> Y </td><td> N </td></tr>
309 * <tr><td> {@link #destruct} </td><td> N </td><td> N </td>
310 * <td> Y </td><td> Y </td><td> N </td></tr>
311 * <tr><td> {@link #getEnv} </td><td> Y </td><td> Y </td>
312 * <td> Y </td><td> Y </td><td> N </td></tr>
313 * <tr><td> {@link #getHookContext} </td><td> Y </td><td> Y </td>
314 * <td> Y </td><td> Y </td><td> N </td></tr>
315 * <tr><td> {@link #getMode} </td><td> Y </td><td> Y </td>
316 * <td> Y </td><td> Y </td><td> N </td></tr>
317 * <tr><td> {@link #getPri} </td><td> Y </td><td> Y </td>
318 * <td> Y </td><td> Y </td><td> N </td></tr>
319 * <tr><td> {@link #getFunc} </td><td> Y </td><td> Y </td>
320 * <td> Y </td><td> Y </td><td> N </td></tr>
321 * <tr><td> {@link #setEnv} </td><td> Y </td><td> Y </td>
322 * <td> Y </td><td> Y </td><td> N </td></tr>
323 * <tr><td> {@link #setHookContext} </td><td> Y </td><td> Y </td>
324 * <td> Y </td><td> Y </td><td> N </td></tr>
325 * <tr><td> {@link #setPri} </td><td> Y </td><td> Y </td>
326 * <td> Y </td><td> N </td><td> N </td></tr>
327 * <tr><td> {@link #stat} </td><td> Y </td><td> Y </td>
328 * <td> Y </td><td> Y </td><td> N </td></tr>
329 * <tr><td colspan="6"> Definitions: <br />
330 * <ul>
331 * <li> <b>Hwi</b>: API is callable from a Hwi thread. </li>
332 * <li> <b>Swi</b>: API is callable from a Swi thread. </li>
333 * <li> <b>Task</b>: API is callable from a Task thread. </li>
334 * <li> <b>Main</b>: API is callable during any of these phases: </li>
335 * <ul>
336 * <li> In your module startup after this module is started
337 * (e.g. Task_Module_startupDone() returns TRUE). </li>
338 * <li> During xdc.runtime.Startup.lastFxns. </li>
339 * <li> During main().</li>
340 * <li> During BIOS.startupFxns.</li>
341 * </ul>
342 * <li> <b>Startup</b>: API is callable during any of these phases:</li>
343 * <ul>
344 * <li> During xdc.runtime.Startup.firstFxns.</li>
345 * <li> In your module startup before this module is started
346 * (e.g. Task_Module_startupDone() returns FALSE).</li>
347 * </ul>
348 * </ul>
349 * </td></tr>
350 *
351 * </table>
352 * @p
353 */
354
355 @DirectCall
356 @ModuleStartup
357 @InstanceInitStatic
358 @InstanceFinalize
359 @InstanceInitError
360
361 module Task
362 {
363
364
365
366
367
368 /*! Task function type definition. */
369 typedef Void (*FuncPtr)(UArg, UArg);
370
371 /*! "All Task Blocked" function type definition. */
372 typedef Void (*AllBlockedFuncPtr)(Void);
373
374 /*!
375 * Task execution modes.
376 *
377 * These enumerations are the range of modes or states that
378 * a task can be in. A task's current mode can be gotten using
379 * {@link #stat}.
380 */
381 enum Mode {
382 Mode_RUNNING, /*! Task is currently executing. */
383 Mode_READY, /*! Task is scheduled for execution. */
384 Mode_BLOCKED, /*! Task is suspended from execution. */
385 Mode_TERMINATED, /*! Task is terminated from execution. */
386 Mode_INACTIVE /*! Task is on inactive task list */
387 };
388
389 /*!
390 * Task Status Buffer.
391 *
392 * Passed to and filled in by {@link #stat};
393 */
394 struct Stat {
395 Int priority; /*! Task priority. */
396 Ptr stack; /*! Task stack. */
397 SizeT stackSize; /*! Task stack size. */
398 IHeap.Handle stackHeap; /*! Heap used to alloc stack. */
399 Ptr env; /*! Global environment struct. */
400 Mode mode; /*! Task's current mode. */
401 Ptr sp; /*! Task's current stack pointer. */
402 SizeT used; /*! max # of words used on stack. */
403 };
404
405 /*!
406 * Task hook set type definition.
407 *
408 * Sets of hook functions can be specified for the Task module.
409 * See {@link #hookfunc Hook Functions} for details.
410 */
411 struct HookSet {
412 Void (*registerFxn)(Int);
413 Void (*createFxn)(Handle, Error.Block *);
414 Void (*readyFxn)(Handle);
415 Void (*switchFxn)(Handle, Handle);
416 Void (*exitFxn)(Handle);
417 Void (*deleteFxn)(Handle);
418 };
419
420 /*! "Don't care" task affinity */
421 const UInt AFFINITY_NONE = ~(0);
422
423 /*! @_nodoc */
424 metaonly struct BasicView {
425 String label;
426 Int priority;
427 String mode;
428 String fxn[];
429 UArg arg0;
430 UArg arg1;
431 SizeT stackSize;
432 Ptr stackBase;
433 String curCoreId;
434 String affinity;
435 }
436
437 /*! @_nodoc */
438 metaonly struct DetailedView {
439 String label;
440 Int priority;
441 String mode;
442 String fxn[];
443 UArg arg0;
444 UArg arg1;
445 String stackPeak;
446 SizeT stackSize;
447 Ptr stackBase;
448 String curCoreId;
449 String affinity;
450 String blockedOn;
451 }
452
453 /*! @_nodoc */
454 metaonly struct ModuleView {
455 String schedulerState;
456 String readyQMask[];
457 Bool workPending;
458 UInt numVitalTasks;
459 Ptr currentTask[];
460 String hwiStackPeak;
461 SizeT hwiStackSize;
462 Ptr hwiStackBase;
463 }
464
465 /*! @_nodoc (not used by view) */
466 metaonly struct CallStackView {
467 Int depth;
468 String decode;
469 }
470
471 /*! @_nodoc */
472 metaonly struct ReadyQView {
473 Ptr task;
474 Ptr next;
475 Ptr prev;
476 Ptr readyQ;
477 String label;
478 Int priority;
479 String mode;
480 String fxn[];
481 String curCoreId;
482 String affinity;
483 }
484
485 /*! @_nodoc */
486 @Facet
487 metaonly config ViewInfo.Instance rovViewInfo =
488 ViewInfo.create({
489 viewMap: [
490 ['Basic', {type: ViewInfo.INSTANCE, viewInitFxn: 'viewInitBasic', structName: 'BasicView'}],
491 ['Detailed', {type: ViewInfo.INSTANCE, viewInitFxn: 'viewInitDetailed', structName: 'DetailedView'}],
492 ['CallStacks', {type: ViewInfo.TREE, viewInitFxn: 'viewInitCallStack', structName: 'CallStackView'}],
493 ['ReadyQs', {type: ViewInfo.TREE_TABLE, viewInitFxn: 'viewInitReadyQs', structName: 'ReadyQView'}],
494 ['Module', {type: ViewInfo.MODULE, viewInitFxn: 'viewInitModule', structName: 'ModuleView'}],
495 ]
496 });
497
498
499
500
501
502 /*! Logged on every task switch */
503 config Log.Event LM_switch = {
504 mask: Diags.USER1 | Diags.USER2,
505 msg: "LM_switch: oldtsk: 0x%x, oldfunc: 0x%x, newtsk: 0x%x, newfunc: 0x%x"
506 };
507
508 /*! Logged on calls to Task_sleep */
509 config Log.Event LM_sleep = {
510 mask: Diags.USER1 | Diags.USER2,
511 msg: "LM_sleep: tsk: 0x%x, func: 0x%x, timeout: %d"
512 };
513
514 /*! Logged when a task is made ready to run (ie Semaphore_post()) */
515 config Log.Event LD_ready = {
516 mask: Diags.USER2,
517 msg: "LD_ready: tsk: 0x%x, func: 0x%x, pri: %d"
518 };
519
520 /*! Logged when a task is blocked (ie Semaphore_pend()) */
521 config Log.Event LD_block = {
522 mask: Diags.USER2,
523 msg: "LD_block: tsk: 0x%x, func: 0x%x"
524 };
525
526 /*! Logged on calls to Task_yield */
527 config Log.Event LM_yield = {
528 mask: Diags.USER1 | Diags.USER2,
529 msg: "LM_yield: tsk: 0x%x, func: 0x%x, currThread: %d"
530 };
531
532 /*! Logged on calls to Task_setPri */
533 config Log.Event LM_setPri = {
534 mask: Diags.USER1 | Diags.USER2,
535 msg: "LM_setPri: tsk: 0x%x, func: 0x%x, oldPri: %d, newPri %d"
536 };
537
538 /*!
539 * Logged when Task functions fall thru the bottom
540 * or when Task_exit() is explicitly called.
541 */
542 config Log.Event LD_exit = {
543 mask: Diags.USER2,
544 msg: "LD_exit: tsk: 0x%x, func: 0x%x"
545 };
546
547 /*! Logged on calls to Task_setAffinity */
548 config Log.Event LM_setAffinity = {
549 mask: Diags.USER1 | Diags.USER2,
550 msg: "LM_setAffinity: tsk: 0x%x, func: 0x%x, oldCore: %d, oldAffinity %d, newAffinity %d"
551 };
552
553 /*! Logged on every task schedule entry */
554 config Log.Event LM_schedule = {
555 mask: Diags.USER3,
556 msg: "LD_schedule: coreId: %d, workFlag: %d, curSetLocal: %d, curSetX: %d, curMaskLocal: %d"
557 };
558
559 /*! Logged when no scheduling work was found */
560 config Log.Event LM_noWork = {
561 mask: Diags.USER3,
562 msg: "LD_noWork: coreId: %d, curSetLocal: %d, curSetX: %d, curMaskLocal: %d"
563 };
564
565
566
567 /*!
568 * Error raised when a stack overflow (or corruption) is detected.
569 *
570 * This error is raised by kernel's stack checking function. This
571 * function checks the stacks before every task switch to make sure
572 * that reserved word at top of stack has not been modified.
573 *
574 * The stack checking logic is enabled by the {@link #initStackFlag} and
575 * {@link #checkStackFlag} configuration parameters. If both of these
576 * flags are set to true, the kernel will validate the stacks.
577 */
578 config Error.Id E_stackOverflow = {
579 msg: "E_stackOverflow: Task 0x%x stack overflow."
580 };
581
582 /*!
583 * Error raised when a task's stack pointer (SP) does not point
584 * somewhere within the task's stack.
585 *
586 * This error is raised by kernel's stack checking function. This
587 * function checks the SPs before every task switch to make sure
588 * they point within the task's stack.
589 *
590 * The stack checking logic is enabled by the {@link #initStackFlag} and
591 * {@link #checkStackFlag} configuration parameters. If both of these
592 * flags are set to true, the kernel will validate the stack pointers.
593 */
594 config Error.Id E_spOutOfBounds = {
595 msg: "E_spOutOfBounds: Task 0x%x stack error, SP = 0x%x."
596 };
597
598 config Error.Id E_deleteNotAllowed = {
599 msg: "E_deleteNotAllowed: Task 0x%x."
600 };
601
602
603
604 /*! Asserted in Task_create and Task_delete */
605 config Assert.Id A_badThreadType = {
606 msg: "A_badThreadType: Cannot create/delete a task from Hwi or Swi thread."
607 };
608
609 /*! Asserted in Task_delete */
610 config Assert.Id A_badTaskState = {
611 msg: "A_badTaskState: Can't delete a task in RUNNING state."
612 };
613
614 /*! Asserted in Task_delete */
615 config Assert.Id A_noPendElem = {
616 msg: "A_noPendElem: Not enough info to delete BLOCKED task."
617 };
618
619 /*! Asserted in Task_create */
620 config Assert.Id A_taskDisabled = {
621 msg: "A_taskDisabled: Cannot create a task when tasking is disabled."
622 };
623
624 /*! Asserted in Task_create */
625 config Assert.Id A_badPriority = {
626 msg: "A_badPriority: An invalid task priority was used."
627 };
628
629 /*! Asserted in Task_sleep */
630 config Assert.Id A_badTimeout = {
631 msg: "A_badTimeout: Can't sleep FOREVER."
632 };
633
634 /*! Asserted in Task_setAffinity */
635 config Assert.Id A_badAffinity = {
636 msg: "A_badAffinity: Invalid affinity."
637 };
638
639 /*! Asserted in Task_sleep */
640 config Assert.Id A_sleepTaskDisabled = {
641 msg: "A_sleepTaskDisabled: Cannot call Task_sleep() while the Task scheduler is disabled."
642 };
643
644 /*! Asserted in Task_getIdleTaskHandle */
645 config Assert.Id A_invalidCoreId = {
646 msg: "A_invalidCoreId: Cannot pass a non-zero CoreId in a non-SMP application."
647 };
648
649 /*!
650 * Number of Task priorities supported. Default is 16.
651 *
652 * The maximum number of priorities supported is
653 * target specific and depends on the number of
654 * bits in a UInt data type. For 6x and ARM devices
655 * the maximum number of priorities is therefore 32.
656 * For 28x, 55x, and MSP430 devices, the maximum number of
657 * priorities is 16.
658 */
659 config UInt numPriorities = 16;
660
661 /*!
662 * Default stack size (in MAUs) used for all tasks.
663 *
664 * Default is obtained from the family-specific TaskSupport module
665 * (e.g. {@link ti.sysbios.family.arm.m3.TaskSupport},
666 * {@link ti.sysbios.family.c62.TaskSupport}).
667 */
668 config SizeT defaultStackSize;
669
670 /*!
671 * Default memory section used for all statically created task stacks.
672 *
673 * The default stack section name is target/device specific.
674 * For C6x targets it is ".far:taskStackSection".
675 * For C28x targets it is ".taskStackSection".
676 * For GNU targets it is ".bss".
677 * For all other targets it is ".bss:taskStackSection".
678 *
679 * By default, all statically created task stacks are grouped together
680 * into the defaultStackSection and placed where ever
681 * the target specific defaultStackSection base section name
682 * (ie .bss, .far, .ebss) is placed.
683 *
684 * To place all task stacks into a different memory segment,
685 * add the following to your config script:
686 *
687 * @p(code)
688 * Program.sectMap[Task.defaultStackSection] = new Program.SectionSpec();
689 * Program.sectMap[Task.defaultStackSection].loadSegment =
690 * "yourMemorySegment";
691 * @p
692 *
693 * To group all task stacks into a different section AND place that
694 * section into a specific memory segment, add the following to your
695 * config script:
696 *
697 * @p(code)
698 * Task.defaultStackSection = ".yourSectionName";
699 * Program.sectMap[Task.defaultStackSection] = new Program.SectionSpec();
700 * Program.sectMap[Task.defaultStackSection].loadSegment =
701 * "yourMemorySegment";
702 * @p
703 *
704 * Where "yourSectionName" can be just about anything, and
705 * "yourMemorySegment"
706 * must be a memory segment defined for your board.
707 */
708 metaonly config String defaultStackSection;
709
710 /*!
711 * Default Mem heap used for all dynamically created task stacks.
712 *
713 * Default is null.
714 */
715 config IHeap.Handle defaultStackHeap;
716
717 /*!
718 * Default core affinity for newly created tasks.
719 *
720 * Default is Task_AFFINITY_NONE, meaning don't care.
721 */
722 metaonly config UInt defaultAffinity = AFFINITY_NONE;
723
724 /*!
725 * Create a task (of priority 0) to run the Idle functions in.
726 *
727 * When set to true, a task is created that continuously calls the
728 * {@link Idle#run Idle_run()} function, which, in turn calls each of
729 * the configured Idle functions.
730 *
731 * When set to false, no Idle Task is created and it is up to the
732 * user to call the Idle_run() function if the configured Idle
733 * functions need to be run. Or, by adding the following lines to
734 * the config script, the Idle functions will run whenever all
735 * tasks are blocked ({@link #allBlockedFunc Task.allBlockedFunc}):
736 *
737 * @p(code)
738 * Task.enableIdleTask = false;
739 * Task.allBlockedFunc = Idle.run;
740 * @p
741 *
742 * Default is true.
743 *
744 * @see #idleTaskStackSize
745 * @see #idleTaskStackSection
746 * @see #idleTaskVitalTaskFlag
747 * @see #allBlockedFunc
748 */
749 metaonly config Bool enableIdleTask = true;
750
751 /*!
752 * Idle task stack size in MAUs.
753 *
754 * Default is inherited from module config defaultStackSize.
755 */
756 metaonly config SizeT idleTaskStackSize;
757
758 /*!
759 * Idle task stack section
760 *
761 * Default is inherited from module config defaultStackSection;
762 */
763 metaonly config String idleTaskStackSection;
764
765 /*!
766 * Idle task's vitalTaskFlag.
767 * (see {@link #vitalTaskFlag}).
768 *
769 * Default is true.
770 */
771 metaonly config Bool idleTaskVitalTaskFlag = true;
772
773 /*!
774 * Function to call while all tasks are blocked.
775 *
776 * This function will be called repeatedly while no tasks are
777 * ready to run.
778 *
779 * Ordinarily (in applications that have tasks ready to run at startup),
780 * the function will run in the context of the last task to block.
781 *
782 * In an application where there are no tasks ready to run
783 * when BIOS_start() is called, the allBlockedFunc function is
784 * called within the BIOS_start() thread which runs on the system/ISR
785 * stack.
786 *
787 * By default, allBlockedFunc is initialized to point to an internal
788 * function that simply returns.
789 *
790 * By adding the following lines to the config script, the Idle
791 * functions will run whenever all tasks are blocked:
792 *
793 * @p(code)
794 * Task.enableIdleTask = false;
795 * Task.allBlockedFunc = Idle.run;
796 * @p
797 *
798 * @see #enableIdleTask
799 *
800 * @a(constraints)
801 * The configured allBlockedFunc is designed to be called repeatedly.
802 * It must return in order for the task scheduler to check if all
803 * tasks are STILL blocked and if not, run the highest priority task
804 * currently ready to run.
805 *
806 * The configured allBlockedFunc function is called with interrupts
807 * disabled. If your function must run with interrupts enabled,
808 * surround the body of your code with Hwi_enable()/Hwi_restore()
809 * function calls per the following example:
810 *
811 * @p(code)
812 * Void yourFunc() {
813 * UInt hwiKey;
814 *
815 * hwiKey = Hwi_enable();
816 *
817 * ... // your code here
818 *
819 * Hwi_restore(hwiKey);
820 * }
821 * @p
822 */
823 config AllBlockedFuncPtr allBlockedFunc = null;
824
825 /*!
826 * Initialize stack with known value for stack checking at runtime
827 * (see {@link #checkStackFlag}).
828 *
829 * This is also useful for inspection of stack in debugger or core
830 * dump utilities.
831 * Default is true.
832 */
833 config Bool initStackFlag = true;
834
835 /*!
836 * Check 'from' and 'to' task stacks before task context switch.
837 *
838 * The check consists of testing the top of stack value against
839 * its initial value (see {@link #initStackFlag}). If it is no
840 * longer at this value, the assumption is that the task has
841 * overrun its stack. If the test fails, then the
842 * {@link #E_stackOverflow} error is raised.
843 *
844 * Runtime stack checking is only performed if {@link #initStackFlag} is
845 * also true.
846 *
847 * Default is true.
848 *
849 * To enable or disable full stack checking, you should set both this
850 * flag and the {@link ti.sysbios.hal.Hwi#checkStackFlag}.
851 *
852 * @a(Note)
853 * Enabling stack checking will add some interrupt latency because the
854 * checks are made within the Task scheduler while interrupts are
855 * disabled.
856 */
857 config Bool checkStackFlag = true;
858
859 /*!
860 * Automatically delete terminated tasks.
861 *
862 * If this feature is enabled, an Idle function is installed that
863 * deletes dynamically created Tasks that have terminated either
864 * by falling through their task function or by explicitly calling
865 * Task_exit().
866 *
867 * A list of terminated Tasks that were created dynmically is
868 * maintained internally. Each invocation of the installed Idle function
869 * deletes the first Task on this list. This one-at-a-time process
870 * continues until the list is empty.
871 *
872 * @a(Note)
873 * This feature is disabled by default.
874 *
875 * @a(WARNING)
876 * When this feature is enabled, an error will be raised if the user's
877 * application attempts to delete a terminated task. If a terminated task
878 * has already been automatically deleted and THEN the user's application
879 * attempts to delete it (ie: using a stale Task handle), the results are
880 * undefined and probably catastrophic!
881 *
882 */
883 config Bool deleteTerminatedTasks = false;
884
885 /*!
886 * Const array that holds the HookSet objects.
887 *
888 * See {@link #hookfunc Hook Functions} for details about HookSets.
889 */
890 config HookSet hooks[length] = [];
891
892
893
894 /*!
895 * ======== addHookSet ========
896 * addHookSet is used in a config file to add a hook set.
897 *
898 * Configures a set of hook functions for the
899 * Task module. Each set contains these hook functions:
900 *
901 * @p(blist)
902 * -Register: A function called before any statically created tasks
903 * are initialized at runtime. The register hook is called at boot time
904 * before main() and before interrupts are enabled.
905 * -Create: A function that is called when a task is created.
906 * This includes tasks that are created statically and those
907 * created dynamically using {@link #create} or {@link #construct}.
908 * The create hook is called outside of a Task_disable/enable block and
909 * before the task has been added to the ready list.
910 * -Ready: A function that is called when a task becomes ready to run.
911 * The ready hook is called from within a Task_disable/enable block with
912 * interrupts enabled.
913 * -Switch: A function that is called just before a task switch
914 * occurs. The 'prev' and 'next' task handles are passed to the Switch
915 * hook. 'prev' is set to NULL for the initial task switch that occurs
916 * during SYS/BIOS startup. The Switch hook is called from within a
917 * Task_disable/enable block with interrupts enabled.
918 * -Exit: A function that is called when a task exits using
919 * {@link #exit}. The exit hook is passed the handle of the exiting
920 * task. The exit hook is called outside of a Task_disable/enable block
921 * and before the task has been removed from the kernel lists.
922 * -Delete: A function that is called when any task is deleted at
923 * run-time with {@link #delete}. The delete hook is called outside
924 * of a Task_disable/enable block.
925 * @p
926 * Hook functions can only be configured statically.
927 *
928 * See {@link #hookfunc Hook Functions} for more details.
929 *
930 * HookSet structure elements may be omitted, in which case those
931 * elements will not exist.
932 *
933 * For example, the following configuration code defines a HookSet:
934 *
935 * @p(code)
936 * // Hook Set 1
937 * Task.addHookSet({
938 * registerFxn: '&myRegister1',
939 * createFxn: '&myCreate1',
940 * readyFxn: '&myReady1',
941 * switchFxn: '&mySwitch1',
942 * exitFxn: '&myExit1',
943 * deleteFxn: '&myDelete1'
944 * });
945 * @p
946 *
947 * @param(hook) structure of type HookSet
948 */
949 metaonly Void addHookSet(HookSet hook);
950
951 /*!
952 * @_nodoc
953 * ======== Task_startup ========
954 * Start the task scheduler.
955 *
956 * Task_startup signals the end of boot operations, enables
957 * the Task scheduler and schedules the highest priority ready
958 * task for execution.
959 *
960 * Task_startup is called by BIOS_start() after Hwi_enable()
961 * and Swi_enable(). There is no return from this function as the
962 * execution thread is handed to the highest priority ready task.
963 */
964 Void startup();
965
966 /*!
967 * ======== Task_enabled ========
968 * Returns TRUE if the Task scheduler is enabled
969 *
970 * @_nodoc
971 */
972 Bool enabled();
973
974 /*!
975 * @_nodoc
976 * ======== unlockSched ========
977 * Force a Task scheduler unlock. Used by Core_atExit() & Core_hwiFunc()
978 * to unlock Task scheduler before exiting.
979 *
980 * This function should only be called after a Hwi_disable() has entered
981 * the Inter-core gate and disabled interrupts locally.
982 */
983 Void unlockSched();
984
985 /*!
986 * ======== Task_disable ========
987 * Disable the task scheduler.
988 *
989 * {@link #disable} and {@link #restore} control Task scheduling.
990 * {@link #disable} disables all other Tasks from running until
991 * {@link #restore} is called. Hardware and Software interrupts
992 * can still run.
993 *
994 * {@link #disable} and {@link #restore} allow you to ensure that
995 * statements
996 * that must be performed together during critical processing are not
997 * preempted by other Tasks.
998 *
999 * The value of the key returned is opaque to applications and is meant
1000 * to be passed to Task_restore().
1001 *
1002 * In the following example, the critical section is
1003 * not preempted by any Tasks.
1004 *
1005 * @p(code)
1006 * key = Task_disable();
1007 * `critical section`
1008 * Task_restore(key);
1009 * @p
1010 *
1011 * You can also use {@link #disable} and {@link #restore} to
1012 * create several Tasks and allow them to be invoked in
1013 * priority order.
1014 *
1015 * {@link #disable} calls can be nested.
1016 *
1017 * @b(returns) key for use with {@link #restore}
1018 *
1019 * @a(constraints)
1020 * Do not call any function that can cause the current task to block
1021 * within a {@link #disable}/{@link #restore} block. For example,
1022 * {@link ti.sysbios.knl.Semaphore#pend Semaphore_pend}
1023 * (if timeout is non-zero),
1024 * {@link #sleep}, {@link #yield}, and Memory_alloc can all
1025 * cause blocking.
1026 */
1027 UInt disable();
1028
1029 /*!
1030 * @_nodoc
1031 * ======== enable ========
1032 * Enable the task scheduler.
1033 *
1034 * {@link #enable} unconditionally enables the Task scheduler and
1035 * schedules the highest priority ready task for execution.
1036 *
1037 * This function is called by {@link #startup} (which is called by
1038 * {@link ti.sysbios.BIOS#start BIOS_start}) to begin multi-tasking
1039 * operations.
1040 */
1041 Void enable();
1042
1043 /*!
1044 * ======== restore ========
1045 * Restore Task scheduling state.
1046 *
1047 * {@link #disable} and {@link #restore} control Task scheduling
1048 * {@link #disable} disables all other Tasks from running until
1049 * {@link #restore} is called. Hardware and Software interrupts
1050 * can still run.
1051 *
1052 * {@link #disable} and {@link #restore} allow you to ensure that
1053 * statements
1054 * that must be performed together during critical processing are not
1055 * preempted.
1056
1057 * In the following example, the critical section is not preempted
1058 * by any Tasks.
1059 *
1060 * @p(code)
1061 * key = Task_disable();
1062 * `critical section`
1063 * Task_restore(key);
1064 * @p
1065 *
1066 * You can also use {@link #disable} and {@link #restore} to create
1067 * several Tasks and allow them to be performed in priority order.
1068 *
1069 * {@link #disable} calls can be nested.
1070 *
1071 * {@link #restore} returns with interrupts enabled if the key unlocks
1072 * the scheduler
1073 *
1074 * @param(key) key to restore previous Task scheduler state
1075 *
1076 * @a(constraints)
1077 * Do not call any function that can cause the current task to block
1078 * within a {@link #disable}/{@link #restore} block. For example,
1079 * {@link ti.sysbios.knl.Semaphore#pend Semaphore_pend()}
1080 * (if timeout is non-zero),
1081 * {@link #sleep}, {@link #yield}, and Memory_alloc can all
1082 * cause blocking.
1083 *
1084 * {@link #restore} internally calls Hwi_enable() if the key passed
1085 * to it results in the unlocking of the Task scheduler (ie if this
1086 * is root Task_disable/Task_restore pair).
1087 */
1088 Void restore(UInt key);
1089
1090 /*!
1091 * @_nodoc
1092 * ======== restoreHwi ========
1093 * Restore Task scheduling state.
1094 * Used by dispatcher. Does not re-enable Ints.
1095 */
1096 Void restoreHwi(UInt key);
1097
1098 /*!
1099 * ======== self ========
1100 * Returns a handle to the currently executing Task object.
1101 *
1102 * Task_self returns the object handle for the currently executing task.
1103 * This function is useful when inspecting the object or when the current
1104 * task changes its own priority through {@link #setPri}.
1105 *
1106 * No task switch occurs when calling Task_self.
1107 *
1108 * Task_self will return NULL until Tasking is initiated at the end of
1109 * BIOS_start().
1110 *
1111 * @b(returns) address of currently executing task object
1112 */
1113 Handle self();
1114
1115 /*!
1116 * ======== selfMacro ========
1117 * Returns a handle to the currently executing Task object.
1118 *
1119 * Task_selfMacro is identical to {@link #self} but is implemented as
1120 * and inline macro.
1121 *
1122 * @b(returns) address of currently executing task object
1123 */
1124 @Macro
1125 Handle selfMacro();
1126
1127 /*!
1128 * @_nodoc
1129 * ======== checkStacks ========
1130 * Check for stack overflow.
1131 *
1132 * This function is usually called by the {@link #HookSet} switchFxn to
1133 * make sure task stacks are valid before performing the context
1134 * switch.
1135 *
1136 * If a stack overflow is detected on either the oldTask or the
1137 * newTask, a {@link #E_stackOverflow} Error is raised and the system
1138 * exited.
1139 *
1140 * In order to work properly, {@link #checkStacks} requires that the
1141 * {@link #initStackFlag} set to true, which it is by default.
1142 *
1143 * You can call {@link #checkStacks} directly from your application.
1144 * For example, you can check the current task's stack integrity
1145 * at any time with a call like the following:
1146 *
1147 * @p(code)
1148 * Task_checkStacks(Task_self(), Task_self());
1149 * @p
1150 *
1151 * @param(oldTask) leaving Task Object Ptr
1152 * @param(newTask) entering Task Object Ptr
1153 */
1154 Void checkStacks(Handle oldTask, Handle newTask);
1155
1156 /*!
1157 * ======== exit ========
1158 * Terminate execution of the current task.
1159 *
1160 * Task_exit terminates execution of the current task, changing its mode
1161 * from {@link #Mode_RUNNING} to {@link #Mode_TERMINATED}. If all tasks
1162 * have been terminated, or if all remaining tasks have their
1163 * vitalTaskFlag attribute set to FALSE, then SYS/BIOS terminates the
1164 * program as a whole by calling the function System_exit with a status
1165 * code of 0.
1166 *
1167 * Task_exit is automatically called whenever a task returns from its
1168 * top-level function.
1169 *
1170 * Exit Hooks (see exitFxn in {@link #HookSet}) can be used to provide
1171 * functions that run whenever a task is terminated. The exitFxn Hooks
1172 * are called before the task has been blocked and marked
1173 * {@link #Mode_TERMINATED}.
1174 * See {@link #hookfunc Hook Functions} for more information.
1175 *
1176 * Any SYS/BIOS function can be called from an Exit Hook function.
1177 *
1178 * Calling {@link #self} within an Exit function returns the task
1179 * being exited. Your Exit function declaration should be similar to
1180 * the following:
1181 * @p(code)
1182 * Void myExitFxn(Void);
1183 * @p
1184 *
1185 * A task switch occurs when calling Task_exit unless the program as a
1186 * whole is terminated
1187 *
1188 * @a(constraints)
1189 * Task_exit cannot be called from a Swi or Hwi.
1190 *
1191 * Task_exit cannot be called from the program's main() function.
1192 */
1193 Void exit();
1194
1195 /*!
1196 * ======== sleep ========
1197 * Delay execution of the current task.
1198 *
1199 * Task_sleep changes the current task's mode from {@link #Mode_RUNNING}
1200 * to {@link #Mode_BLOCKED}, and delays its execution for nticks
1201 * increments of the {@link Clock system clock}. The actual time
1202 * delayed can be up to 1 system clock tick less than nticks due to
1203 * granularity in system timekeeping and the time elapsed per
1204 * tick is determined by {@link Clock#tickPeriod Clock_tickPeriod}.
1205 *
1206 * After the specified period of time has elapsed, the task reverts to
1207 * the {@link #Mode_READY} mode and is scheduled for execution.
1208 *
1209 * A task switch always occurs when calling Task_sleep if nticks > 0.
1210 *
1211 * @param(nticks) number of system clock ticks to sleep
1212 *
1213 * @a(constraints)
1214 * Task_sleep cannot be called from a Swi or Hwi, or within a
1215 * {@link #disable} / {@link #restore} block.
1216 *
1217 * Task_sleep cannot be called from the program's main() function.
1218 *
1219 * Task_sleep should not be called from within an Idle function. Doing
1220 * so prevents analysis tools from gathering run-time information.
1221 *
1222 * nticks cannot be {@link ti.sysbios.BIOS#WAIT_FOREVER BIOS_WAIT_FOREVER}.
1223 */
1224 Void sleep(UInt32 nticks);
1225
1226 /*!
1227 * ======== yield ========
1228 * Yield processor to equal priority task.
1229 *
1230 * Task_yield yields the processor to another task of equal priority.
1231 *
1232 * A task switch occurs when you call Task_yield if there is an equal
1233 * priority task ready to run.
1234 *
1235 * Tasks of higher priority preempt the currently running task without
1236 * the need for a call to Task_yield. If only lower-priority tasks are
1237 * ready to run when you call Task_yield, the current task continues to
1238 * run. Control does not pass to a lower-priority task.
1239 *
1240 * @a(constraints)
1241 * When called within an Hwi, the code sequence calling Task_yield
1242 * must be invoked by the Hwi dispatcher.
1243 *
1244 * Task_yield cannot be called from the program's main() function.
1245 */
1246 Void yield();
1247
1248 /*!
1249 * ======== getIdleTask ========
1250 * returns a handle to the idle task object (for core 0)
1251 */
1252 Handle getIdleTask();
1253
1254 /*!
1255 * ======== getIdleTaskHandle ========
1256 * returns a handle to the idle task object for the specified coreId
1257 * (should be used only in applications built with
1258 * {@link ti.sysbios.BIOS#smpEnabled} set to true)
1259 *
1260 * @a(Note)
1261 * If this function is called in a non-SMP application, coreId should
1262 * always be 0.
1263 */
1264 Handle getIdleTaskHandle(UInt coreId);
1265
1266 1267 1268 1269 1270
1271 Void startCore(UInt coreId);
1272
1273 /*!
1274 * ======== getNickName ========
1275 *
1276 */
1277 metaonly String getNickName(Any tskView);
1278
1279 instance:
1280
1281 /*!
1282 * ======== create ========
1283 * Create a Task.
1284 *
1285 * Task_create creates a new task object. If successful, Task_create
1286 * returns the handle of the new task object. If unsuccessful,
1287 * Task_create returns NULL unless it aborts.
1288 *
1289 * The fxn parameter uses the {@link #FuncPtr} type to pass a pointer to
1290 * the function the Task object should run. For example, if myFxn is a
1291 * function in your program, your C code can create a Task object
1292 * to call that
1293 * function as follows:
1294 *
1295 * @p(code)
1296 * Task_Params taskParams;
1297 *
1298 * // Create task with priority 15
1299 * Task_Params_init(&taskParams);
1300 * taskParams.stackSize = 512;
1301 * taskParams.priority = 15;
1302 * Task_create((Task_FuncPtr)myFxn, &taskParams, &eb);
1303 * @p
1304 *
1305 * The following statements statically create a task in the
1306 * configuration file:
1307 *
1308 * @p(code)
1309 * var params = new Task.Params;
1310 * params.instance.name = "tsk0";
1311 * params.arg0 = 1;
1312 * params.arg1 = 2;
1313 * params.priority = 1;
1314 * Task.create('&tsk0_func', params);
1315 * @p
1316 *
1317 * If NULL is passed instead of a pointer to an actual Task_Params
1318 * struct, a
1319 * default set of parameters is used. The "eb" is an error block that
1320 * you can use
1321 * to handle errors that may occur during Task object creation.
1322 *
1323 * The newly created task is placed in {@link #Mode_READY} mode, and is
1324 * scheduled to begin concurrent execution of the following function
1325 * call:
1326 *
1327 * @p(code)
1328 * (*fxn)(arg1, arg2);
1329 * @p
1330 *
1331 * As a result of being made ready to run, the task runs any
1332 * application-wide Ready functions that have been specified.
1333 *
1334 * Task_exit is automatically called if and when the task returns
1335 * from fxn.
1336 *
1337 * @p(html)
1338 * <B>Create Hook Functions</B>
1339 * @p
1340 *
1341 * You can specify application-wide Create hook functions in your config
1342 * file that run whenever a task is created. This includes tasks that
1343 * are created statically and those created dynamically using
1344 * Task_create.
1345 *
1346 * For Task objects created statically, Create functions are called
1347 * during the Task module initialization phase of the program startup
1348 * process prior to main().
1349 *
1350 * For Task objects created dynamically, Create functions
1351 * are called after the task handle has been initialized but before the
1352 * task has been placed on its ready queue.
1353 *
1354 * Any SYS/BIOS function can be called from Create functions.
1355 * SYS/BIOS passes the task handle of the task being created to each of
1356 * the Create functions.
1357 *
1358 * All Create function declarations should be similar to this:
1359 * @p(code)
1360 * Void myCreateFxn(Task_Handle task);
1361 * @p
1362 *
1363 * @param(fxn) Task Function
1364 *
1365 * @a(constraints)
1366 * @p(blist)
1367 * - The fxn parameter and the name attribute cannot be NULL.
1368 * - The priority attribute must be less than or equal to
1369 * ({@link #numPriorities} - 1) and greater than or equal to one (1)
1370 * (priority 0 is owned by the Idle task).
1371 * - The priority can be set to -1 for tasks that will not execute
1372 * until another task changes the priority to a positive value.
1373 * - The stackHeap attribute must identify a valid memory Heap.
1374 * @p
1375 */
1376 create(FuncPtr fxn);
1377
1378
1379
1380 /*! Task function argument. Default is 0 */
1381 config UArg arg0 = 0;
1382
1383 /*! Task function argument. Default is 0 */
1384 config UArg arg1 = 0;
1385
1386 /*!
1387 * Task priority (0 to Task.numPriorities-1, or -1).
1388 * Default is 1.
1389 */
1390 config Int priority = 1;
1391
1392 /*!
1393 * Task stack pointer. Default = null.
1394 *
1395 * Null indicates that the stack is to be allocated by create().
1396 *
1397 * Example: To statically initialize "tsk0"'s stack to a literal
1398 * address, use the following syntax:
1399 *
1400 * @p(code)
1401 * Program.global.tsk0.stack = $addr(literal);
1402 * @p
1403 *
1404 */
1405 config Ptr stack = null;
1406
1407 /*!
1408 * Task stack size in MAUs.
1409 *
1410 * The default value of 0 means that the module config
1411 * {@link #defaultStackSize} is used.
1412 */
1413 config SizeT stackSize = 0;
1414
1415 /*!
1416 * Mem section used for statically created task stacks.
1417 *
1418 * Default is inherited from module config defaultStackSection.
1419 */
1420 metaonly config String stackSection;
1421
1422 /*!
1423 * Mem heap used for dynamically created task stack.
1424 *
1425 * The default value of NULL means that the module config
1426 * {@link #defaultStackHeap} is used.
1427 */
1428 config IHeap.Handle stackHeap = null;
1429
1430 /*! Environment data struct. */
1431 config Ptr env = null;
1432
1433 /*!
1434 * Exit system immediately when the last task with this
1435 * flag set to TRUE has terminated.
1436 *
1437 * Default is true.
1438 */
1439 config Bool vitalTaskFlag = true;
1440
1441 /*!
1442 * The core which this task is to run on. Default is Task_AFFINITY_NONE
1443 *
1444 * If there is a compelling reason for a task to be pinned to a
1445 * particular core, then setting 'affinity' to the corresponding core
1446 * id will force the task to only be run on that core.
1447 *
1448 * The default affinity is inherited from {@link #defaultAffinity
1449 * Task.defaultAffinity}
1450 * which in turn defaults to {@link #AFFINITY_NONE Task_AFFINITY_NONE},
1451 * which means the task can be run on either core.
1452 *
1453 * Furthermore, Task_AFFINITY_NONE implies that the task can be moved
1454 * from core to core as deemed necessary by the Task scheduler in order
1455 * to keep the two highest priority ready tasks running simultaneously.
1456 */
1457 config UInt affinity;
1458
1459
1460
1461 /*!
1462 * @_nodoc
1463 * ======== getArg0 ========
1464 * Returns arg0 passed via params to create.
1465 *
1466 * @b(returns) task's arg0
1467 */
1468 UArg getArg0();
1469
1470 /*!
1471 * @_nodoc
1472 * ======== getArg1 ========
1473 * Returns arg1 passed via params to create.
1474 *
1475 * @b(returns) task's arg1
1476 */
1477 UArg getArg1();
1478
1479 /*!
1480 * ======== getEnv ========
1481 * Get task environment pointer.
1482 *
1483 * Task_getEnv returns the environment pointer of the specified task. The
1484 * environment pointer references an arbitrary application-defined data
1485 * structure.
1486 *
1487 * If your program uses multiple hook sets, {@link #getHookContext}
1488 * allows you to get environment pointers you have set for a particular
1489 * hook set and Task object combination.
1490 *
1491 * @b(returns) task environment pointer
1492 */
1493 Ptr getEnv();
1494
1495 /*!
1496 * ======== getFunc ========
1497 * Get Task function and arguments
1498 *
1499 * If either arg0 or arg1 is NULL, then the corresponding argument is not
1500 * returned.
1501 *
1502 * @param(arg0) pointer for returning Task's first function argument
1503 * @param(arg1) pointer for returning Task's second function argument
1504 *
1505 * @b(returns) Task function
1506 */
1507 FuncPtr getFunc(UArg *arg0, UArg *arg1);
1508
1509 /*!
1510 * ======== getHookContext ========
1511 * Get hook set's context for a task.
1512 *
1513 * For example, this C code gets the HookContext, prints it,
1514 * and sets a new value for the HookContext.
1515 *
1516 * @p(code)
1517 * Ptr pEnv;
1518 * Task_Handle myTask;
1519 * Int myHookSetId1;
1520 *
1521 * pEnv = Task_getHookContext(task, myHookSetId1);
1522 *
1523 * System_printf("myEnd1: pEnv = 0x%lx, time = %ld\n",
1524 * (ULong)pEnv, (ULong)Timestamp_get32());
1525 *
1526 * Task_setHookContext(task, myHookSetId1, (Ptr)0xc0de1);
1527 * @p
1528 *
1529 * See {@link #hookfunc Hook Functions} for more details.
1530 *
1531 * @param(id) hook set ID
1532 * @b(returns) hook set context for task
1533 */
1534 Ptr getHookContext(Int id);
1535
1536 /*!
1537 * ======== getPri ========
1538 * Get task priority.
1539 *
1540 * Task_getPri returns the priority of the referenced task.
1541 *
1542 * @b(returns) task priority
1543 */
1544 Int getPri();
1545
1546 /*!
1547 * @_nodoc
1548 * ======== setArg0 ========
1549 * Set arg0 (used primarily for legacy support)
1550 */
1551 Void setArg0(UArg arg);
1552
1553 /*!
1554 * @_nodoc
1555 * ======== setArg1 ========
1556 * Set arg1 (used primarily for legacy support)
1557 */
1558 Void setArg1(UArg arg);
1559
1560 /*!
1561 * ======== setEnv ========
1562 * Set task environment.
1563 *
1564 * Task_setEnv sets the task environment pointer to env. The
1565 * environment pointer references an arbitrary application-defined
1566 * data structure.
1567 *
1568 * If your program uses multiple hook sets, {@link #setHookContext}
1569 * allows you to set environment pointers for any
1570 * hook set and Task object combination.
1571 *
1572 * @param(env) task environment pointer
1573 */
1574 Void setEnv(Ptr env);
1575
1576 /*!
1577 * ======== setHookContext ========
1578 * Set hook instance's context for a task.
1579 *
1580 * For example, this C code gets the HookContext, prints it,
1581 * and sets a new value for the HookContext.
1582 *
1583 * @p(code)
1584 * Ptr pEnv;
1585 * Task_Handle myTask;
1586 * Int myHookSetId1;
1587 *
1588 * pEnv = Task_getHookContext(task, myHookSetId1);
1589 *
1590 * System_printf("myEnd1: pEnv = 0x%lx, time = %ld\n",
1591 * (ULong)pEnv, (ULong)Timestamp_get32());
1592 *
1593 * Task_setHookContext(task, myHookSetId1, (Ptr)0xc0de1);
1594 * @p
1595 *
1596 * See {@link #hookfunc Hook Functions} for more details.
1597 *
1598 * @param(id) hook set ID
1599 * @param(hookContext) value to write to context
1600 */
1601 Void setHookContext(Int id, Ptr hookContext);
1602
1603 /*!
1604 * ======== setPri ========
1605 * Set a task's priority
1606 *
1607 * Task_setpri sets the execution priority of task to newpri, and returns
1608 * that task's old priority value. Raising or lowering a task's priority
1609 * does not necessarily force preemption and re-scheduling of the caller:
1610 * tasks in the {@link #Mode_BLOCKED} mode remain suspended despite a
1611 * change in priority; and tasks in the {@link #Mode_READY} mode gain
1612 * control only if their new priority is greater than that of the
1613 * currently executing task.
1614 *
1615 * newpri should be set to a value greater than or equal to 1 and
1616 * less than or equal to ({@link #numPriorities} - 1). newpri can also
1617 * be set to -1 which puts the the task into the INACTIVE state and the
1618 * task will not run until its priority is raised at a later time by
1619 * another task. Priority 0 is reserved for the idle task.
1620 * If newpri equals ({@link #numPriorities} - 1), execution of the task
1621 * effectively locks out all other program activity, except for the
1622 * handling of interrupts.
1623 *
1624 * The current task can change its own priority (and possibly preempt its
1625 * execution) by passing the output of {@link #self} as the value of the
1626 * task parameter.
1627 *
1628 * A context switch occurs when calling Task_setpri if a currently
1629 * running task priority is set lower than the priority of another
1630 * currently ready task, or if another ready task is made to have a
1631 * higher priority than the currently running task.
1632 *
1633 * Task_setpri can be used for mutual exclusion.
1634 *
1635 * If a task's new priority is different than its previous priority,
1636 * then its relative placement in its new ready task priority
1637 * queue can be different than the one it was removed from. This can
1638 * effect the relative order in which it becomes the running task.
1639 *
1640 * The effected task is placed at the head of its new priority queue
1641 * if it is the currently running task. Otherwise it is placed at
1642 * at the end of its new task priority queue.
1643 *
1644 * @param(newpri) task's new priority
1645 * @b(returns) task's old priority
1646 *
1647 * @a(constraints)
1648 * newpri must be a value between 1 and ({@link #numPriorities} - 1) or -1.
1649 *
1650 * The task cannot be in the {@link #Mode_TERMINATED} mode.
1651 *
1652 * The new priority should not be zero (0). This priority level is
1653 * reserved for the Idle task.
1654 */
1655 UInt setPri(Int newpri);
1656
1657 /*!
1658 * ======== stat ========
1659 * Retrieve the status of a task.
1660 *
1661 * Task_stat retrieves attribute values and status information about a
1662 * task.
1663 *
1664 * Status information is returned through statbuf, which references a
1665 * structure of type {@link #Stat}.
1666 *
1667 * When a task is preempted by a software or hardware interrupt, the task
1668 * execution mode returned for that task by Task_stat is still
1669 * {@link #Mode_RUNNING} because the task runs when the preemption ends.
1670 *
1671 * The current task can inquire about itself by passing the output of
1672 * {@link #self} as the first argument to Task_stat. However, the task
1673 * stack pointer (sp) in the {@link #Stat} structure is the value from
1674 * the previous context switch.
1675 *
1676 * Task_stat has a non-deterministic execution time. As such, it is not
1677 * recommended to call this API from Swis or Hwis.
1678 *
1679 * @param(statbuf) pointer to task status structure
1680 *
1681 * @a(constraints)
1682 * statbuf cannot be NULL;
1683 */
1684 Void stat(Stat *statbuf);
1685
1686 /*!
1687 * ======== getMode ========
1688 * Retrieve the {@link #Mode} of a task.
1689 */
1690 Mode getMode();
1691
1692 /*!
1693 * ======== setAffinity ========
1694 * Set task's core affinity.
1695 *
1696 * If the new core ID is different than the current core affinity
1697 * a reschedule will be performed immediately.
1698 *
1699 * @a(constraints)
1700 * Must NOT be called with interrupts disabled
1701 * (ie within a Hwi_disable()/Hwi_restore() block).
1702 *
1703 * Must NOT be called with tasking disabled
1704 * (ie within a Task_disable()/Task_restore() block).
1705 *
1706 * @b(returns) task's previous core affinity
1707 */
1708 UInt setAffinity(UInt coreId);
1709
1710 /*!
1711 * ======== getAffinity ========
1712 * Return task's core affinity.
1713 *
1714 * @b(returns) task's current core affinity
1715 */
1716 UInt getAffinity();
1717
1718 /*!
1719 * @_nodoc
1720 * ======== block ========
1721 * Block a task.
1722 *
1723 * Remove a task from its ready list.
1724 * The effect of this API is manifest the next time the internal
1725 * Task scheduler is invoked.
1726 * This can be done directly by embedding the call within a
1727 * {@link #disable}/{@link #restore} block.
1728 * Otherwise, the effect will be manifest as a result of processing
1729 * the next dispatched interrupt, or by posting a Swi, or by falling
1730 * through the task function.
1731 *
1732 * @a(constraints)
1733 * If called from within a Hwi or a Swi, or main(), there is no need
1734 * to embed the call within a {@link #disable}/{@link #restore} block.
1735 */
1736 Void block();
1737
1738 /*!
1739 * @_nodoc
1740 * ======== unblock ========
1741 * Unblock a task.
1742 *
1743 * Place task in its ready list.
1744 * The effect of this API is manifest the next time the internal
1745 * Task scheduler is invoked.
1746 * This can be done directly by embedding the call within a
1747 * {@link #disable}/{@link #restore} block.
1748 * Otherwise, the effect will be manifest as a result of processing
1749 * the next dispatched interrupt, or by posting a Swi, or by falling
1750 * through the task function.
1751 *
1752 * @a(constraints)
1753 * If called from within a Hwi or a Swi, or main(), there is no need
1754 * to embed the call within a {@link #disable}/{@link #restore} block.
1755 */
1756 Void unblock();
1757
1758 /*!
1759 * @_nodoc
1760 * ======== blockI ========
1761 * Block a task.
1762 *
1763 * Remove a task from its ready list.
1764 * Must be called within Task_disable/Task_restore block
1765 * with interrupts disabled.
1766 * This API is meant to be used internally.
1767 */
1768 Void blockI();
1769
1770 /*!
1771 * @_nodoc
1772 * ======== unblockI ========
1773 * Unblock a task.
1774 *
1775 * Place task in its ready list.
1776 * Must be called within Task_disable/Task_restore block
1777 * with interrupts disabled.
1778 * This API is meant to be used internally.
1779 *
1780 * @param(hwiKey) key returned from Hwi_disable()
1781 */
1782 Void unblockI(UInt hwiKey);
1783
1784 internal:
1785
1786 /*! Target-specific support functions. */
1787 proxy SupportProxy inherits ti.sysbios.interfaces.ITaskSupport;
1788
1789 1790 1791 1792 1793 1794
1795 Void schedule();
1796
1797 1798 1799 1800
1801 Void enter();
1802
1803 1804 1805 1806
1807 Void sleepTimeout(UArg arg);
1808
1809 1810 1811 1812
1813 Int postInit(Object *task, Error.Block *eb);
1814
1815 1816 1817 1818 1819
1820 config UInt numConstructedTasks = 0;
1821
1822 1823 1824 1825
1826 Void allBlockedFunction();
1827
1828 1829 1830 1831 1832
1833 Void deleteTerminatedTasksFunc();
1834
1835 1836 1837 1838 1839
1840 Void processVitalTaskFlag(Object *task);
1841
1842 1843 1844 1845
1846 config Void (*startupHookFunc)(Void) = null;
1847
1848 1849 1850 1851
1852 struct PendElem {
1853 Queue.Elem qElem;
1854 Task.Handle task;
1855 Clock.Handle clock;
1856 };
1857
1858 struct Instance_State {
1859 Queue.Elem qElem;
1860 volatile Int priority;
1861 UInt mask;
1862 Ptr context;
1863
1864 Mode mode;
1865 PendElem *pendElem;
1866
1867 SizeT stackSize;
1868 Char stack[];
1869 IHeap.Handle stackHeap;
1870 FuncPtr fxn;
1871 UArg arg0;
1872 UArg arg1;
1873 Ptr env;
1874 Ptr hookEnv[];
1875 Bool vitalTaskFlag;
1876
1877 Queue.Handle readyQ;
1878 UInt curCoreId;
1879 UInt affinity;
1880
1881 };
1882
1883 struct Module_State {
1884 Bool locked;
1885 volatile UInt curSet;
1886 Bool workFlag;
1887
1888
1889 UInt vitalTasks;
1890
1891 Handle curTask;
1892 Queue.Handle curQ;
1893 Queue.Object readyQ[];
1894
1895 volatile UInt smpCurSet[];
1896
1897
1898 volatile UInt smpCurMask[];
1899 Handle smpCurTask[];
1900 Queue.Handle smpReadyQ[];
1901
1902
1903
1904 Queue.Object inactiveQ;
1905 Queue.Object terminatedQ;
1906
1907 Handle idleTask[];
1908 Handle constructedTasks[];
1909
1910 };
1911 }
1912