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