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