<tdclass="cellrowborder"valign="top"width="58.44584458445845%"headers="mcps1.2.4.1.3 "><pid="p1717215119159"><aname="p1717215119159"></a><aname="p1717215119159"></a>Converts milliseconds into ticks.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p61721311101517"><aname="p61721311101517"></a><aname="p61721311101517"></a>Converts ticks into milliseconds.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p14367121422016"><aname="p14367121422016"></a><aname="p14367121422016"></a>Converts cycles into milliseconds. Two UINT32 values indicate the high-order and low-order 32 bits of the result value, respectively.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p26621730152310"><aname="p26621730152310"></a><aname="p26621730152310"></a>Converts cycles into microseconds. Two UINT32 values indicate the high-order and low-order 32 bits of the result value, respectively.</p>
<tdclass="cellrowborder"valign="top"width="58.44584458445845%"headers="mcps1.2.4.1.3 "><pid="p1827813571317"><aname="p1827813571317"></a><aname="p1827813571317"></a>Obtains the system clock.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p17278163512131"><aname="p17278163512131"></a><aname="p17278163512131"></a>Obtains the number of ticks since the system starts.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p827819358134"><aname="p827819358134"></a><aname="p827819358134"></a>Obtains the number of cycles for each tick.</p>
</td>
</tr>
</tbody>
</table>
| Category| API| Description|
| -------- | -------- | -------- |
| Time conversion| LOS_MS2Tick | Converts milliseconds into ticks.|
| | LOS_Tick2MS | Converts ticks into milliseconds.|
| | OsCpuTick2MS | Converts cycles into milliseconds. Two UINT32 values indicate the high-order and low-order 32 bits of the result value, respectively.|
| | OsCpuTick2US | Converts cycles into microseconds. Two UINT32 values indicate the high-order and low-order 32 bits of the result value, respectively.|
| Time statistics| LOS_SysClockGet | Obtains the system clock.|
| | LOS_TickCountGet | Obtains the number of ticks since the system starts.|
| | LOS_CyclePerTickGet | Obtains the number of cycles for each tick.|
| | LOS_CurrNanosec |Obtains the number of nanoseconds since the system starts.|
| Delay management| LOS_UDelay |Performs busy waiting in μs, which can be preempted by a task with a higher priority.|
| | LOS_MDelay |Performs busy waiting in ms, which can be preempted by a task with a higher priority.|
## How to Develop<a name="section783435801510"></a>
...
...
@@ -95,7 +49,8 @@ The typical development process of time management is as follows:
1. Complete board configuration and adaptation as required, and configure the system clock frequency \(**OS\_SYS\_CLOCK** in Hz and **LOSCFG\_BASE\_CORE\_TICK\_PER\_SECOND**\). The default value of **OS\_SYS\_CLOCK** varies with the hardware platform.
>- The time management module depends on **OS\_SYS\_CLOCK** and **LOSCFG\_BASE\_CORE\_TICK\_PER\_SECOND**.
>- The number of system ticks is not counted when the interrupt feature is disabled. Therefore, the number of ticks cannot be used as the accurate time.
>- The configuration options are maintained in the **target\_config.h** file of the development board project.
...
...
@@ -106,8 +61,8 @@ The typical development process of time management is as follows:
The following example describes basic time management methods, including:
1. Time conversion: convert milliseconds to ticks or convert ticks to milliseconds.
2. Time statistics: obtain the number of cycles per tick, number of ticks since system startup, and number of delayed ticks.
- Time conversion: convert milliseconds to ticks or convert ticks to milliseconds.
- Time statistics: obtain the number of cycles per tick, number of ticks since system startup, and number of delayed ticks.
<tbody><trid="row14701707188"><tdclass="cellrowborder"rowspan="2"valign="top"width="12.85128512851285%"headers="mcps1.2.4.1.1 "><pid="p54707061819"><aname="p54707061819"></a><aname="p54707061819"></a>Creating or deleting interrupts</p>
<tdclass="cellrowborder"valign="top"width="57.34573457345735%"headers="mcps1.2.4.1.3 "><pid="p74706011818"><aname="p74706011818"></a><aname="p74706011818"></a>Creates an interrupt and registers the interrupt ID, interrupt triggering mode, interrupt priority, and interrupt handler. When an interrupt is triggered, the interrupt handler will be called.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p114700091815"><aname="p114700091815"></a><aname="p114700091815"></a>Deletes an interrupt based on the specified interrupt ID.</p>
</td>
</tr>
<trid="row15470506188"><tdclass="cellrowborder"rowspan="3"valign="top"width="12.85128512851285%"headers="mcps1.2.4.1.1 "><pid="p147010001812"><aname="p147010001812"></a><aname="p147010001812"></a>Enabling or disabling interrupts</p>
<tdclass="cellrowborder"valign="top"width="57.34573457345735%"headers="mcps1.2.4.1.3 "><pid="p1847018014188"><aname="p1847018014188"></a><aname="p1847018014188"></a>Enables the CPU to respond to all interrupt requests.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p194719071819"><aname="p194719071819"></a><aname="p194719071819"></a>Disables the CPU from responding to interrupt requests.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p1947100121811"><aname="p1947100121811"></a><aname="p1947100121811"></a>Restores the interrupt status before the <strongid="b160497829844357"><aname="b160497829844357"></a><aname="b160497829844357"></a>LOS_IntLock</strong> and <strongid="b123452092644357"><aname="b123452092644357"></a><aname="b123452092644357"></a>LOS_IntUnLock</strong> operations are performed.</p>
</td>
</tr>
</tbody>
</table>
| Category| API| Description|
| -------- | -------- | -------- |
| Creating or deleting an interrupt| LOS_HwiCreate | Creates an interrupt and registers the interrupt ID, triggering mode, priority, and interrupt handler. When an interrupt is triggered, the interrupt handler will be called.|
| | LOS_HwiDelete | Deletes an interrupt based on the specified interrupt ID.|
| Locking or unlocking interrupts| LOS_IntUnLock | Enables the CPU to respond to all interrupt requests.|
| | LOS_IntLock | Disables the CPU from responding to interrupt requests.|
| | LOS_IntRestore | Restores the interrupt status before the **LOS_IntLock** and **LOS_IntUnLock** operations are performed.|
| Enabling or disabling an interrupt| LOS_HwiDisable | Disables the CPU from responding to the specified interrupt by setting the register.|
| | LOS_HwiEnable | Enables the CPU to respond to the specified interrupt by setting the register.|
| Setting the interrupt priority| LOS_HwiSetPriority | Sets the interrupt priority.|
| Triggering an interrupt| LOS_HwiTrigger | Triggers an interrupt (simulate an external interrupt by writing the related register of the interrupt controller).|
| Clearing interrupt register status| LOS_HwiClear | Clears the status bit of the interrupt register corresponding to the interrupt ID. The implementation of this API depends on the interrupt controller version. It is optional.|
## How to Develop<a name="section11841123033618"></a>
1. Create an interrupt by calling **HalHwiCreate**.
2. Call **TestHwiTrigger** to trigger the specified interrupt. \(This API is defined in the test suite. It simulates an external interrupt by writing the related register of the interrupt controller. Skip this step for common peripheral devices.\)
3. Call **HalHwiDelete** to delete the specified interrupt. Use this API based on actual requirements.
1.Call **LOS_HwiCreate** to create an interrupt.
2.Call **LOS_HwiTrigger** to trigger the interrupt.
3.Call **LOS_HwiDelete** to delete the specified interrupt. Use this API based on actual requirements.
<tbody><trid="row4287183182010"><tdclass="cellrowborder"rowspan="3"valign="top"width="12.85128512851285%"headers="mcps1.2.4.1.1 "><pid="p6287831122018"><aname="p6287831122018"></a><aname="p6287831122018"></a>Creating or deleting a task</p>
<tdclass="cellrowborder"valign="top"width="57.34573457345735%"headers="mcps1.2.4.1.3 "><pid="p14287173112013"><aname="p14287173112013"></a><aname="p14287173112013"></a>Creates a task and suspends the task to disable scheduling of the task. To enable scheduling of the task, call <strongid="b129220316444426"><aname="b129220316444426"></a><aname="b129220316444426"></a>LOS_TaskResume</strong> to make the task enter the Ready state.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p12886315207"><aname="p12886315207"></a><aname="p12886315207"></a>Creates a task and places the task in the Ready state. If there is no task with a higher priority in the Ready queue, the task will be executed.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p17288133172017"><aname="p17288133172017"></a><aname="p17288133172017"></a>Deletes the specified task.</p>
<tdclass="cellrowborder"valign="top"width="57.34573457345735%"headers="mcps1.2.4.1.3 "><pid="p228823192011"><aname="p228823192011"></a><aname="p228823192011"></a>Resumes a suspended task to place the task in the Ready state.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p628816315207"><aname="p628816315207"></a><aname="p628816315207"></a>Suspends the specified task and performs task switching.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p20288123172015"><aname="p20288123172015"></a><aname="p20288123172015"></a>Suspends this task till the specified task is complete and the task control block resources are reclaimed.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p202881831192011"><aname="p202881831192011"></a><aname="p202881831192011"></a>Makes a task wait for a period of time (in ticks) and releases CPU resources. When the delay time expires, the task enters the Ready state again. The input parameter is the number of ticks.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p128803112012"><aname="p128803112012"></a><aname="p128803112012"></a>Converts the input parameter number of milliseconds into number of ticks, and use the result to call <strongid="b56235690044426"><aname="b56235690044426"></a><aname="b56235690044426"></a>LOS_TaskDelay</strong>.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p1728893192018"><aname="p1728893192018"></a><aname="p1728893192018"></a>Sets the time slice of the current task to <strongid="b5591310044426"><aname="b5591310044426"></a><aname="b5591310044426"></a>0</strong> to release CPU resources and schedule the task with the highest priority in the Ready queue to run.</p>
<tdclass="cellrowborder"valign="top"width="57.34573457345735%"headers="mcps1.2.4.1.3 "><pid="p328863117203"><aname="p328863117203"></a><aname="p328863117203"></a>Locks task scheduling. However, tasks can still be interrupted.</p>
<tdclass="cellrowborder"valign="top"width="57.34573457345735%"headers="mcps1.2.4.1.3 "><pid="p728993182020"><aname="p728993182020"></a><aname="p728993182020"></a>Sets the priority for the current task.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p20289163122017"><aname="p20289163122017"></a><aname="p20289163122017"></a>Sets the priority for a specified task.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p228933119206"><aname="p228933119206"></a><aname="p228933119206"></a>Obtains the priority of a specified task.</p>
<tdclass="cellrowborder"valign="top"width="57.34573457345735%"headers="mcps1.2.4.1.3 "><pid="p15289031122015"><aname="p15289031122015"></a><aname="p15289031122015"></a>Obtains the ID of the current task.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p16289133142013"><aname="p16289133142013"></a><aname="p16289133142013"></a>Obtains the ID of the task with the highest priority in the Ready queue.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p18289163192018"><aname="p18289163192018"></a><aname="p18289163192018"></a>Same as <strongid="b59459526844426"><aname="b59459526844426"></a><aname="b59459526844426"></a>LOS_NextTaskIDGet</strong>.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p10289631132012"><aname="p10289631132012"></a><aname="p10289631132012"></a>Obtains the name of the current task.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p4289331142014"><aname="p4289331142014"></a><aname="p4289331142014"></a>Obtains the name of a specified task.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p19289153142013"><aname="p19289153142013"></a><aname="p19289153142013"></a>Obtains the state of a specified task.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p62901231112010"><aname="p62901231112010"></a><aname="p62901231112010"></a>Obtains information about a specified task, including the task state, priority, stack size, stack pointer (SP), task entry function, and used stack space.</p>
<tdclass="cellrowborder"valign="top"headers="mcps1.2.4.1.2 "><pid="p1290113114206"><aname="p1290113114206"></a><aname="p1290113114206"></a>Checks whether the task module has started scheduling.</p>
</td>
</tr>
<trid="row1529017317206"><tdclass="cellrowborder"valign="top"width="12.85128512851285%"headers="mcps1.2.4.1.1 "><pid="p14290143162014"><aname="p14290143162014"></a><aname="p14290143162014"></a>Maintaining and testing task information</p>
<tdclass="cellrowborder"valign="top"width="57.34573457345735%"headers="mcps1.2.4.1.3 "><pid="p17290153116200"><aname="p17290153116200"></a><aname="p17290153116200"></a>Obtains task switching information. The macro <strongid="b125259128644426"><aname="b125259128644426"></a><aname="b125259128644426"></a>LOSCFG_BASE_CORE_EXC_TSK_SWITCH</strong> must be enabled.</p>
</td>
</tr>
</tbody>
</table>
| Category| API| Description|
| -------- | -------- | -------- |
| Creating or deleting a task| LOS_TaskCreateOnly | Creates a task and suspends the task to disable scheduling of the task. To enable scheduling of the task, call **LOS_TaskResume** to make the task enter the Ready state.|
| | LOS_TaskCreate | Creates a task and places the task in the Ready state. If there is no task with a higher priority in the Ready queue, the task will be executed.|
| | LOS_TaskDelete | Deletes a task.|
| Controlling task status| LOS_TaskResume | Resumes a suspended task to place it in the Ready state.|
| | LOS_TaskSuspend | Suspends the specified task and performs task switching.|
| | LOS_TaskJoin | Suspends this task till the specified task is complete and the task control block resources are reclaimed.|
| | LOS_TaskDetach | Changes the task attribute from **joinable** to **detach**. After the task of the **detach** attribute is complete, the task control block resources will be automatically reclaimed.|
| | LOS_TaskDelay | Makes a task wait for a period of time (in ticks) and releases CPU resources. When the delay time expires, the task enters the Ready state again. The input parameter is the number of ticks.|
| | LOS_Msleep | Converts the input number of milliseconds into number of ticks, and use the result to call **LOS_TaskDelay**.|
| | LOS_TaskYield | Sets the time slice of the current task to **0** to release CPU resources and schedule the task with the highest priority in the Ready queue to run.|
| Controlling task scheduling| LOS_TaskLock | Locks task scheduling. However, tasks can still be interrupted.|
| | LOS_TaskUnlock | Unlocks task scheduling.|
| | LOS_Schedule | Triggers task scheduling|
| Controlling task priority| LOS_CurTaskPriSet | Sets the priority for the current task.|
| | LOS_TaskPriSet | Sets the priority for a specified task.|
| | LOS_TaskPriGet | Obtains the priority of a specified task.|
| Obtaining Job information| LOS_CurTaskIDGet | Obtains the ID of the current task.|
| | LOS_NextTaskIDGet | Obtains the ID of the task with the highest priority in the Ready queue.|
| | LOS_NewTaskIDGet | Same as **LOS_NextTaskIDGet**.|
| | LOS_CurTaskNameGet | Obtains the name of the current task.|
| | LOS_TaskNameGet | Obtains the name of a specified task.|
| | LOS_TaskStatusGet | Obtains the state of a specified task.|
| | LOS_TaskInfoGet | Obtains information about a specified task, including the task state, priority, stack size, stack pointer (SP), task entry function, and used stack space.|
| | LOS_TaskIsRunning | Checks whether the task module has started scheduling.|
| Updating task information| LOS_TaskSwitchInfoGet | Obtains task switching information. The macro **LOSCFG_BASE_CORE_EXC_TSK_SWITCH** must be enabled.|