From d072fa036e8c8e57c41a72e45cceecc960b0cb48 Mon Sep 17 00:00:00 2001 From: kenneth Date: Fri, 10 Sep 2021 15:51:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A4=BE=E5=8C=BA=E8=B5=84?= =?UTF-8?q?=E6=96=99=E9=97=AE=E9=A2=98=EF=BC=9A=201=E3=80=81=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E4=BB=A3=E7=A0=81=EF=BC=9A=E5=8A=A8=E6=80=81=E5=86=85?= =?UTF-8?q?=E5=AD=98=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E6=9C=AA=E5=AE=9A=E4=B9=89=202=E3=80=81=E7=A4=BA=E4=BE=8B?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=9A=E5=8D=95=E6=AC=A1=E8=BD=AF=E4=BB=B6?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=99=A8=E4=B8=8D=E5=BA=94=E5=86=8D=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E5=81=9C=E6=AD=A2=E5=88=A0=E9=99=A4=E6=96=B9=E6=B3=95?= =?UTF-8?q?=203=E3=80=81=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81=EF=BC=9A?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E9=98=9F=E5=88=97=E5=BB=B6=E6=97=B6=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=9C=AA=E4=BD=BF=E7=94=A8LiteOS=E6=A0=87=E5=87=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #I49HD3 #I49HDQ #I49HE4 Signed-off-by: kenneth --- .../kernel-mini-basic-ipc-queue-guide.md | 17 +++---- .../kernel-mini-basic-memory-dynamic.md | 3 ++ .../kernel/kernel-mini-basic-soft-guide.md | 51 ++++++++++--------- .../kernel-mini-basic-ipc-queue-guide.md | 17 +++---- .../kernel-mini-basic-memory-dynamic.md | 3 ++ .../kernel/kernel-mini-basic-soft-guide.md | 41 +++++++-------- 6 files changed, 69 insertions(+), 63 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/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 ``` -- GitLab