804 Star 2.4K Fork 1.2K

GVPHuawei LiteOS / LiteOS

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
programming-example-46.md 2.05 KB
一键复制 编辑 原始数据 按行查看 历史

Programming Example

Example Description

The programming example will cover the following functions:

  1. Time conversion: from milliseconds to ticks, or conversely
  2. Time measurement and deferral: measures the number of cycles per second, the number of ticks for which the system is running, and the number of ticks for which the deferral lasts

Example Code

Prerequisites

  • The default value 100 of LOSCFG_BASE_CORE_TICK_PER_SECOND is used. This configuration item specifies the number of ticks in a second.
  • The system main clock frequency OS_SYS_CLOCK (in Hz) is set.

Time conversion:

VOID Example_TransformTime(VOID)
{
    UINT32 ms;
    UINT32 tick;

     uwTick = LOS_MS2Tick(10000);//Convert 10000 ms into ticks 
    dprintf("tick = %d \n",tick);
     uwMs= LOS_Tick2MS(100);//Convert 100 ticks into ms 
    dprintf("ms = %d \n",ms);
}

Time measurement and delay:

VOID Example_GetTime(VOID)
{
    UINT32 cyclePerTick;
    UINT64 tickCount;

    cyclePerTick  = LOS_CyclePerTickGet();
    if(0 != cyclePerTick) {
        dprintf("LOS_CyclePerTickGet = %d \n", cyclePerTick);
    }

    tickCount = LOS_TickCountGet();
    if(0 != tickCount) {
        dprintf("LOS_TickCountGet = %d \n", (UINT32)tickCount);
    }

    LOS_TaskDelay(200);
    tickCount = LOS_TickCountGet();
    if(0 != tickCount) {
        dprintf("LOS_TickCountGet after delay = %d \n", (UINT32)tickCount);
    }
}

Verification

The verification result is as follows:

Time conversion:

tick = 1000
ms = 1000

Time measurement and delay:

LOS_CyclePerTickGet = 495000 
LOS_TickCountGet = 1 
LOS_TickCountGet after delay = 201

Complete Code

sample_time.c

C
1
https://gitee.com/LiteOS/LiteOS.git
git@gitee.com:LiteOS/LiteOS.git
LiteOS
LiteOS
LiteOS
master

搜索帮助