From 8c347211ab210fdc1e748a8255e49300f5462b7e Mon Sep 17 00:00:00 2001 From: duangavin123 Date: Fri, 10 Sep 2021 18:18:09 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E5=AF=BC=E5=85=A5OpenHarmony=E5=B7=A5?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: duangavin123 --- .../kernel-mini-basic-ipc-queue-guide.md | 17 +++---- .../kernel-mini-basic-memory-dynamic.md | 3 ++ .../kernel/kernel-mini-basic-soft-guide.md | 51 ++++++++++--------- .../kernel/kernel-mini-basic-task-basic.md | 2 +- .../kernel-mini-basic-ipc-queue-guide.md | 17 +++---- .../kernel-mini-basic-memory-dynamic.md | 3 ++ .../kernel/kernel-mini-basic-soft-guide.md | 41 +++++++-------- .../kernel/kernel-mini-basic-task-basic.md | 2 +- 8 files changed, 71 insertions(+), 65 deletions(-) diff --git a/en/device-dev/kernel/kernel-mini-basic-ipc-queue-guide.md b/en/device-dev/kernel/kernel-mini-basic-ipc-queue-guide.md index 8a40c65f3f..723745dfa1 100644 --- a/en/device-dev/kernel/kernel-mini-basic-ipc-queue-guide.md +++ b/en/device-dev/kernel/kernel-mini-basic-ipc-queue-guide.md @@ -131,8 +131,6 @@ VOID RecvEntry(VOID) CHAR readBuf[BUFFER_LEN] = {0}; UINT32 readLen = BUFFER_LEN; - // Sleep for 1s. - usleep(1000000); ret = LOS_QueueReadCopy(g_queue, readBuf, &readLen, 0); if(ret != LOS_OK) { printf("recv message failure, error: %x\n", ret); @@ -145,12 +143,12 @@ VOID RecvEntry(VOID) printf("delete the queue failure, error: %x\n", ret); } - printf("delete the queue success!\n"); + printf("delete the queue success.\n"); } UINT32 ExampleQueue(VOID) { - printf("start queue example\n"); + printf("start queue example.\n"); UINT32 ret = 0; UINT32 task1, task2; TSK_INIT_PARAM_S initParam = {0}; @@ -169,6 +167,7 @@ UINT32 ExampleQueue(VOID) initParam.pcName = "RecvQueue"; initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)RecvEntry; + initParam.usTaskPrio = 10; ret = LOS_TaskCreate(&task2, &initParam); if(ret != LOS_OK) { printf("create task2 failed, error: %x\n", ret); @@ -180,7 +179,7 @@ UINT32 ExampleQueue(VOID) printf("create queue failure, error: %x\n", ret); } - printf("create the queue success!\n"); + printf("create the queue success.\n"); LOS_TaskUnlock(); return ret; } @@ -191,9 +190,9 @@ UINT32 ExampleQueue(VOID) The development is successful if the return result is as follows: ``` -start test example -create the queue success! -recv message: test message -delete the queue success! +start queue example. +create the queue success. +recv message: test message. +delete the queue success. ``` diff --git a/en/device-dev/kernel/kernel-mini-basic-memory-dynamic.md b/en/device-dev/kernel/kernel-mini-basic-memory-dynamic.md index cd9379dc05..78367b90d1 100644 --- a/en/device-dev/kernel/kernel-mini-basic-memory-dynamic.md +++ b/en/device-dev/kernel/kernel-mini-basic-memory-dynamic.md @@ -176,6 +176,9 @@ The sample code is as follows: ``` #include "los_memory.h" +#define TEST_POOL_SIZE (2*1024) +__attribute__((aligned(4))) UINT8 g_testPool[TEST_POOL_SIZE]; + VOID Example_DynMem(VOID) { UINT32 *mem = NULL; diff --git a/en/device-dev/kernel/kernel-mini-basic-soft-guide.md b/en/device-dev/kernel/kernel-mini-basic-soft-guide.md index 41d1077832..e322f99de2 100644 --- a/en/device-dev/kernel/kernel-mini-basic-soft-guide.md +++ b/en/device-dev/kernel/kernel-mini-basic-soft-guide.md @@ -112,57 +112,58 @@ UINT32 g_timerCount2 = 0; /* Task ID*/ UINT32 g_testTaskId01; -void Timer1_Callback(UINT32 arg) //Callback function 1 +void Timer1_Callback(UINT32 arg) // Callback function 1 { UINT32 tick_last1; g_timerCount1++; - tick_last1=(UINT32)LOS_TickCountGet(); //Obtain the current number of ticks. + tick_last1 = (UINT32)LOS_TickCountGet(); //Obtain the current number of ticks. printf("g_timerCount1=%d, tick_last1=%d\n", g_timerCount1, tick_last1); } -void Timer2_Callback(UINT32 arg) //Callback function 2 +void Timer2_Callback(UINT32 arg) // Callback function 2 { UINT32 tick_last2; - tick_last2=(UINT32)LOS_TickCountGet(); + tick_last2 = (UINT32)LOS_TickCountGet(); g_timerCount2++; printf("g_timerCount2=%d tick_last2=%d\n", g_timerCount2, tick_last2); } void Timer_example(void) { - UINT32 id1; // timer id - UINT32 id2; // timer id - UINT32 uwTick; + UINT32 ret; + UINT32 id1; // timer id1 + UINT32 id2; // timer id2 + UINT32 tickCount; /* Create a one-shot software timer, with the number of ticks set to 1000. When the number of ticks reaches 1000, callback function 1 is executed. */ - LOS_SwtmrCreate (1000, LOS_SWTMR_MODE_ONCE, Timer1_Callback, &id1, 1); + LOS_SwtmrCreate(1000, LOS_SWTMR_MODE_ONCE, Timer1_Callback, &id1, 1); /* Create a periodic software timer and execute callback function 2 every 100 ticks. */ LOS_SwtmrCreate(100, LOS_SWTMR_MODE_PERIOD, Timer2_Callback, &id2, 1); printf("create Timer1 success\n"); - LOS_SwtmrStart (id1); // Start the one-shot software timer. - printf("start Timer1 sucess\n"); + LOS_SwtmrStart(id1); // Start the one-shot software timer. + printf("start Timer1 success\n"); LOS_TaskDelay(200); // Delay 200 ticks. - LOS_SwtmrTimeGet(id1, &uwTick); // Obtain the number of remaining ticks of the one-short software timer. - printf("uwTick =%d\n", uwTick); + LOS_SwtmrTimeGet(id1, &tickCount); // Obtain the number of remaining ticks of the one-short software timer. + printf("tickCount=%d\n", tickCount); LOS_SwtmrStop(id1); // Stop the software timer. - printf("stop Timer1 sucess\n"); + printf("stop Timer1 success\n"); LOS_SwtmrStart(id1); LOS_TaskDelay(1000); - LOS_SwtmrDelete(id1); // Delete the software timer. - printf("delete Timer1 sucess\n"); - LOS_SwtmrStart(id2); // Start the periodic software timer. printf("start Timer2\n"); LOS_TaskDelay(1000); LOS_SwtmrStop(id2); - LOS_SwtmrDelete(id2); + ret = LOS_SwtmrDelete(id2); // Delete the software timer. + if (ret == LOS_OK) { + printf("delete Timer2 success\n"); + } } UINT32 Example_TaskEntry(VOID) @@ -170,11 +171,11 @@ UINT32 Example_TaskEntry(VOID) UINT32 ret; TSK_INIT_PARAM_S task1; - /* Lock task scheduling.*/ + /* Lock task scheduling. */ LOS_TaskLock(); - /* Create task 1.*/ - memset(&task1, 0, sizeof(TSK_INIT_PARAM_S)); + /* Create task 1. */ + (VOID)memset(&task1, 0, sizeof(TSK_INIT_PARAM_S)); task1.pfnTaskEntry = (TSK_ENTRY_FUNC)Timer_example; task1.pcName = "TimerTsk"; task1.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; @@ -185,7 +186,7 @@ UINT32 Example_TaskEntry(VOID) return LOS_NOK; } - /* Unlock task scheduling.*/ + /* Unlock task scheduling. */ LOS_TaskUnlock(); return LOS_OK; @@ -198,11 +199,10 @@ The output is as follows: ``` create Timer1 success -start Timer1 sucess -uwTick =798 -stop Timer1 sucess +start Timer1 success +tickCount=798 +stop Timer1 success g_timerCount1=1, tick_last1=1208 -delete Timer1 sucess start Timer2 g_timerCount2=1 tick_last2=1313 g_timerCount2=2 tick_last2=1413 @@ -214,5 +214,6 @@ g_timerCount2=7 tick_last2=1913 g_timerCount2=8 tick_last2=2013 g_timerCount2=9 tick_last2=2113 g_timerCount2=10 tick_last2=2213 +delete Timer2 success ``` diff --git a/en/device-dev/kernel/kernel-mini-basic-task-basic.md b/en/device-dev/kernel/kernel-mini-basic-task-basic.md index 0f3d463a36..fa4e6853cc 100644 --- a/en/device-dev/kernel/kernel-mini-basic-task-basic.md +++ b/en/device-dev/kernel/kernel-mini-basic-task-basic.md @@ -39,7 +39,7 @@ The task transition process is as follows: - Running → Blocked - When a running task is blocked \(suspended, delayed, or reading semaphores\), it will be deleted from the Ready queue and changes from the Running state to the Blocked state. Then, task switching is triggered to run the task with the highest priority in the Ready queue. + When a running task is blocked \(suspended, delayed, or reading semaphores\), it will be inserted into the corresponding blocking queue and changes from the Running state to the Blocked state. Then, task switching is triggered to run the task with the highest priority in the Ready queue. - Blocked → Ready \(Blocked → Running\) diff --git a/zh-cn/device-dev/kernel/kernel-mini-basic-ipc-queue-guide.md b/zh-cn/device-dev/kernel/kernel-mini-basic-ipc-queue-guide.md index 6c161853b6..f68c614ebb 100644 --- a/zh-cn/device-dev/kernel/kernel-mini-basic-ipc-queue-guide.md +++ b/zh-cn/device-dev/kernel/kernel-mini-basic-ipc-queue-guide.md @@ -131,8 +131,6 @@ VOID RecvEntry(VOID) CHAR readBuf[BUFFER_LEN] = {0}; UINT32 readLen = BUFFER_LEN; - //休眠1s - usleep(1000000); ret = LOS_QueueReadCopy(g_queue, readBuf, &readLen, 0); if(ret != LOS_OK) { printf("recv message failure, error: %x\n", ret); @@ -145,12 +143,12 @@ VOID RecvEntry(VOID) printf("delete the queue failure, error: %x\n", ret); } - printf("delete the queue success!\n"); + printf("delete the queue success.\n"); } UINT32 ExampleQueue(VOID) { - printf("start queue example\n"); + printf("start queue example.\n"); UINT32 ret = 0; UINT32 task1, task2; TSK_INIT_PARAM_S initParam = {0}; @@ -169,6 +167,7 @@ UINT32 ExampleQueue(VOID) initParam.pcName = "RecvQueue"; initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)RecvEntry; + initParam.usTaskPrio = 10; ret = LOS_TaskCreate(&task2, &initParam); if(ret != LOS_OK) { printf("create task2 failed, error: %x\n", ret); @@ -180,7 +179,7 @@ UINT32 ExampleQueue(VOID) printf("create queue failure, error: %x\n", ret); } - printf("create the queue success!\n"); + printf("create the queue success.\n"); LOS_TaskUnlock(); return ret; } @@ -191,9 +190,9 @@ UINT32 ExampleQueue(VOID) 编译运行得到的结果为: ``` -start test example -create the queue success! -recv message: test message -delete the queue success! +start queue example. +create the queue success. +recv message: test message. +delete the queue success. ``` diff --git a/zh-cn/device-dev/kernel/kernel-mini-basic-memory-dynamic.md b/zh-cn/device-dev/kernel/kernel-mini-basic-memory-dynamic.md index 276b11e329..d0f42d0cf3 100644 --- a/zh-cn/device-dev/kernel/kernel-mini-basic-memory-dynamic.md +++ b/zh-cn/device-dev/kernel/kernel-mini-basic-memory-dynamic.md @@ -197,6 +197,9 @@ OpenHarmony LiteOS-M的动态内存管理主要为用户提供以下功能,接 ``` #include "los_memory.h" +#define TEST_POOL_SIZE (2*1024) +__attribute__((aligned(4))) UINT8 g_testPool[TEST_POOL_SIZE]; + VOID Example_DynMem(VOID) { UINT32 *mem = NULL; diff --git a/zh-cn/device-dev/kernel/kernel-mini-basic-soft-guide.md b/zh-cn/device-dev/kernel/kernel-mini-basic-soft-guide.md index 0e9f963c0c..24ede40cf6 100644 --- a/zh-cn/device-dev/kernel/kernel-mini-basic-soft-guide.md +++ b/zh-cn/device-dev/kernel/kernel-mini-basic-soft-guide.md @@ -116,53 +116,54 @@ void Timer1_Callback(UINT32 arg) // 回调函数1 { UINT32 tick_last1; g_timerCount1++; - tick_last1=(UINT32)LOS_TickCountGet(); // 获取当前Tick数 + tick_last1 = (UINT32)LOS_TickCountGet(); // 获取当前Tick数 printf("g_timerCount1=%d, tick_last1=%d\n", g_timerCount1, tick_last1); } void Timer2_Callback(UINT32 arg) // 回调函数2 { UINT32 tick_last2; - tick_last2=(UINT32)LOS_TickCountGet(); + tick_last2 = (UINT32)LOS_TickCountGet(); g_timerCount2++; printf("g_timerCount2=%d tick_last2=%d\n", g_timerCount2, tick_last2); } void Timer_example(void) { - UINT32 id1; // timer id - UINT32 id2; // timer id - UINT32 uwTick; + UINT32 ret; + UINT32 id1; // timer id1 + UINT32 id2; // timer id2 + UINT32 tickCount; /*创建单次软件定时器,Tick数为1000,启动到1000Tick数时执行回调函数1 */ - LOS_SwtmrCreate (1000, LOS_SWTMR_MODE_ONCE, Timer1_Callback, &id1, 1); + LOS_SwtmrCreate(1000, LOS_SWTMR_MODE_ONCE, Timer1_Callback, &id1, 1); /*创建周期性软件定时器,每100Tick数执行回调函数2 */ LOS_SwtmrCreate(100, LOS_SWTMR_MODE_PERIOD, Timer2_Callback, &id2, 1); printf("create Timer1 success\n"); - LOS_SwtmrStart (id1); //启动单次软件定时器 - printf("start Timer1 sucess\n"); + LOS_SwtmrStart(id1); //启动单次软件定时器 + printf("start Timer1 success\n"); LOS_TaskDelay(200); //延时200Tick数 - LOS_SwtmrTimeGet(id1, &uwTick); // 获得单次软件定时器剩余Tick数 - printf("uwTick =%d\n", uwTick); + LOS_SwtmrTimeGet(id1, &tickCount); // 获得单次软件定时器剩余Tick数 + printf("tickCount=%d\n", tickCount); LOS_SwtmrStop(id1); // 停止软件定时器 - printf("stop Timer1 sucess\n"); + printf("stop Timer1 success\n"); LOS_SwtmrStart(id1); LOS_TaskDelay(1000); - LOS_SwtmrDelete(id1); // 删除软件定时器 - printf("delete Timer1 sucess\n"); - LOS_SwtmrStart(id2); // 启动周期性软件定时器 printf("start Timer2\n"); LOS_TaskDelay(1000); LOS_SwtmrStop(id2); - LOS_SwtmrDelete(id2); + ret = LOS_SwtmrDelete(id2); // 删除软件定时器 + if (ret == LOS_OK) { + printf("delete Timer2 success\n"); + } } UINT32 Example_TaskEntry(VOID) @@ -174,7 +175,7 @@ UINT32 Example_TaskEntry(VOID) LOS_TaskLock(); /* 创建任务1 */ - memset(&task1, 0, sizeof(TSK_INIT_PARAM_S)); + (VOID)memset(&task1, 0, sizeof(TSK_INIT_PARAM_S)); task1.pfnTaskEntry = (TSK_ENTRY_FUNC)Timer_example; task1.pcName = "TimerTsk"; task1.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; @@ -198,11 +199,10 @@ UINT32 Example_TaskEntry(VOID) ``` create Timer1 success -start Timer1 sucess -uwTick =798 -stop Timer1 sucess +start Timer1 success +tickCount=798 +stop Timer1 success g_timerCount1=1, tick_last1=1208 -delete Timer1 sucess start Timer2 g_timerCount2=1 tick_last2=1313 g_timerCount2=2 tick_last2=1413 @@ -214,5 +214,6 @@ g_timerCount2=7 tick_last2=1913 g_timerCount2=8 tick_last2=2013 g_timerCount2=9 tick_last2=2113 g_timerCount2=10 tick_last2=2213 +delete Timer2 success ``` diff --git a/zh-cn/device-dev/kernel/kernel-mini-basic-task-basic.md b/zh-cn/device-dev/kernel/kernel-mini-basic-task-basic.md index 074596f401..a9a5a554cf 100644 --- a/zh-cn/device-dev/kernel/kernel-mini-basic-task-basic.md +++ b/zh-cn/device-dev/kernel/kernel-mini-basic-task-basic.md @@ -39,7 +39,7 @@ OpenHarmony LiteOS-M的任务模块可以给用户提供多个任务,实现任 - 运行态→阻塞态 - 正在运行的任务发生阻塞(挂起、延时、读信号量等)时,该任务会从就绪队列中删除,任务状态由运行态变成阻塞态,然后发生任务切换,运行就绪队列中最高优先级任务。 + 正在运行的任务发生阻塞(挂起、延时、读信号量等)时,将该任务插入到对应的阻塞队列中,任务状态由运行态变成阻塞态,然后发生任务切换,运行就绪队列中最高优先级任务。 - 阻塞态→就绪态(阻塞态→运行态) -- GitLab