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 8a40c65f3f3e938f5c3ec2ed92ab830eaada5b69..723745dfa10904296c4da7e2eb3dd5ef39873996 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 cd9379dc05b2417bc77c026aa74ecb40663db2eb..78367b90d1a8779a3de345d6dd3fb42c6ac6841f 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 41d1077832d0d7984f9ad7ad1dda3e385f1cfd1e..e322f99de263f69fbd64f8e8779efb31df0543c3 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 6c161853b669ecdd896c3a11cd01deb5d6bdf624..f68c614ebb27208dad6ed6cf445b2b629d09a067 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 276b11e3294c256a3ef269e5fb53425dabbf0446..d0f42d0cf38a94711470d5d8300e94a4071aa614 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 0e9f963c0c631b7b8b8284dfa4f16e54d1de273d..24ede40cf65308b044001a305706232ff0105224 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 ```