提交 8c347211 编写于 作者: D duangavin123

update 导入OpenHarmony工程

Signed-off-by: Nduangavin123 <duanxichao@huawei.com>
上级 589f5560
...@@ -131,8 +131,6 @@ VOID RecvEntry(VOID) ...@@ -131,8 +131,6 @@ VOID RecvEntry(VOID)
CHAR readBuf[BUFFER_LEN] = {0}; CHAR readBuf[BUFFER_LEN] = {0};
UINT32 readLen = BUFFER_LEN; UINT32 readLen = BUFFER_LEN;
// Sleep for 1s.
usleep(1000000);
ret = LOS_QueueReadCopy(g_queue, readBuf, &readLen, 0); ret = LOS_QueueReadCopy(g_queue, readBuf, &readLen, 0);
if(ret != LOS_OK) { if(ret != LOS_OK) {
printf("recv message failure, error: %x\n", ret); printf("recv message failure, error: %x\n", ret);
...@@ -145,12 +143,12 @@ VOID RecvEntry(VOID) ...@@ -145,12 +143,12 @@ VOID RecvEntry(VOID)
printf("delete the queue failure, error: %x\n", ret); printf("delete the queue failure, error: %x\n", ret);
} }
printf("delete the queue success!\n"); printf("delete the queue success.\n");
} }
UINT32 ExampleQueue(VOID) UINT32 ExampleQueue(VOID)
{ {
printf("start queue example\n"); printf("start queue example.\n");
UINT32 ret = 0; UINT32 ret = 0;
UINT32 task1, task2; UINT32 task1, task2;
TSK_INIT_PARAM_S initParam = {0}; TSK_INIT_PARAM_S initParam = {0};
...@@ -169,6 +167,7 @@ UINT32 ExampleQueue(VOID) ...@@ -169,6 +167,7 @@ UINT32 ExampleQueue(VOID)
initParam.pcName = "RecvQueue"; initParam.pcName = "RecvQueue";
initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)RecvEntry; initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)RecvEntry;
initParam.usTaskPrio = 10;
ret = LOS_TaskCreate(&task2, &initParam); ret = LOS_TaskCreate(&task2, &initParam);
if(ret != LOS_OK) { if(ret != LOS_OK) {
printf("create task2 failed, error: %x\n", ret); printf("create task2 failed, error: %x\n", ret);
...@@ -180,7 +179,7 @@ UINT32 ExampleQueue(VOID) ...@@ -180,7 +179,7 @@ UINT32 ExampleQueue(VOID)
printf("create queue failure, error: %x\n", ret); printf("create queue failure, error: %x\n", ret);
} }
printf("create the queue success!\n"); printf("create the queue success.\n");
LOS_TaskUnlock(); LOS_TaskUnlock();
return ret; return ret;
} }
...@@ -191,9 +190,9 @@ UINT32 ExampleQueue(VOID) ...@@ -191,9 +190,9 @@ UINT32 ExampleQueue(VOID)
The development is successful if the return result is as follows: The development is successful if the return result is as follows:
``` ```
start test example start queue example.
create the queue success! create the queue success.
recv message: test message recv message: test message.
delete the queue success! delete the queue success.
``` ```
...@@ -176,6 +176,9 @@ The sample code is as follows: ...@@ -176,6 +176,9 @@ The sample code is as follows:
``` ```
#include "los_memory.h" #include "los_memory.h"
#define TEST_POOL_SIZE (2*1024)
__attribute__((aligned(4))) UINT8 g_testPool[TEST_POOL_SIZE];
VOID Example_DynMem(VOID) VOID Example_DynMem(VOID)
{ {
UINT32 *mem = NULL; UINT32 *mem = NULL;
......
...@@ -112,57 +112,58 @@ UINT32 g_timerCount2 = 0; ...@@ -112,57 +112,58 @@ UINT32 g_timerCount2 = 0;
/* Task ID*/ /* Task ID*/
UINT32 g_testTaskId01; UINT32 g_testTaskId01;
void Timer1_Callback(UINT32 arg) //Callback function 1 void Timer1_Callback(UINT32 arg) // Callback function 1
{ {
UINT32 tick_last1; UINT32 tick_last1;
g_timerCount1++; 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); 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; UINT32 tick_last2;
tick_last2=(UINT32)LOS_TickCountGet(); tick_last2 = (UINT32)LOS_TickCountGet();
g_timerCount2++; g_timerCount2++;
printf("g_timerCount2=%d tick_last2=%d\n", g_timerCount2, tick_last2); printf("g_timerCount2=%d tick_last2=%d\n", g_timerCount2, tick_last2);
} }
void Timer_example(void) void Timer_example(void)
{ {
UINT32 id1; // timer id UINT32 ret;
UINT32 id2; // timer id UINT32 id1; // timer id1
UINT32 uwTick; 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. */ /* 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. */ /* Create a periodic software timer and execute callback function 2 every 100 ticks. */
LOS_SwtmrCreate(100, LOS_SWTMR_MODE_PERIOD, Timer2_Callback, &id2, 1); LOS_SwtmrCreate(100, LOS_SWTMR_MODE_PERIOD, Timer2_Callback, &id2, 1);
printf("create Timer1 success\n"); printf("create Timer1 success\n");
LOS_SwtmrStart (id1); // Start the one-shot software timer. LOS_SwtmrStart(id1); // Start the one-shot software timer.
printf("start Timer1 sucess\n"); printf("start Timer1 success\n");
LOS_TaskDelay(200); // Delay 200 ticks. LOS_TaskDelay(200); // Delay 200 ticks.
LOS_SwtmrTimeGet(id1, &uwTick); // Obtain the number of remaining ticks of the one-short software timer. LOS_SwtmrTimeGet(id1, &tickCount); // Obtain the number of remaining ticks of the one-short software timer.
printf("uwTick =%d\n", uwTick); printf("tickCount=%d\n", tickCount);
LOS_SwtmrStop(id1); // Stop the software timer. LOS_SwtmrStop(id1); // Stop the software timer.
printf("stop Timer1 sucess\n"); printf("stop Timer1 success\n");
LOS_SwtmrStart(id1); LOS_SwtmrStart(id1);
LOS_TaskDelay(1000); LOS_TaskDelay(1000);
LOS_SwtmrDelete(id1); // Delete the software timer.
printf("delete Timer1 sucess\n");
LOS_SwtmrStart(id2); // Start the periodic software timer. LOS_SwtmrStart(id2); // Start the periodic software timer.
printf("start Timer2\n"); printf("start Timer2\n");
LOS_TaskDelay(1000); LOS_TaskDelay(1000);
LOS_SwtmrStop(id2); 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) UINT32 Example_TaskEntry(VOID)
...@@ -170,11 +171,11 @@ UINT32 Example_TaskEntry(VOID) ...@@ -170,11 +171,11 @@ UINT32 Example_TaskEntry(VOID)
UINT32 ret; UINT32 ret;
TSK_INIT_PARAM_S task1; TSK_INIT_PARAM_S task1;
/* Lock task scheduling.*/ /* Lock task scheduling. */
LOS_TaskLock(); LOS_TaskLock();
/* Create task 1.*/ /* Create task 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.pfnTaskEntry = (TSK_ENTRY_FUNC)Timer_example;
task1.pcName = "TimerTsk"; task1.pcName = "TimerTsk";
task1.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; task1.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
...@@ -185,7 +186,7 @@ UINT32 Example_TaskEntry(VOID) ...@@ -185,7 +186,7 @@ UINT32 Example_TaskEntry(VOID)
return LOS_NOK; return LOS_NOK;
} }
/* Unlock task scheduling.*/ /* Unlock task scheduling. */
LOS_TaskUnlock(); LOS_TaskUnlock();
return LOS_OK; return LOS_OK;
...@@ -198,11 +199,10 @@ The output is as follows: ...@@ -198,11 +199,10 @@ The output is as follows:
``` ```
create Timer1 success create Timer1 success
start Timer1 sucess start Timer1 success
uwTick =798 tickCount=798
stop Timer1 sucess stop Timer1 success
g_timerCount1=1, tick_last1=1208 g_timerCount1=1, tick_last1=1208
delete Timer1 sucess
start Timer2 start Timer2
g_timerCount2=1 tick_last2=1313 g_timerCount2=1 tick_last2=1313
g_timerCount2=2 tick_last2=1413 g_timerCount2=2 tick_last2=1413
...@@ -214,5 +214,6 @@ g_timerCount2=7 tick_last2=1913 ...@@ -214,5 +214,6 @@ g_timerCount2=7 tick_last2=1913
g_timerCount2=8 tick_last2=2013 g_timerCount2=8 tick_last2=2013
g_timerCount2=9 tick_last2=2113 g_timerCount2=9 tick_last2=2113
g_timerCount2=10 tick_last2=2213 g_timerCount2=10 tick_last2=2213
delete Timer2 success
``` ```
...@@ -39,7 +39,7 @@ The task transition process is as follows: ...@@ -39,7 +39,7 @@ The task transition process is as follows:
- Running → Blocked - 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\) - Blocked → Ready \(Blocked → Running\)
......
...@@ -131,8 +131,6 @@ VOID RecvEntry(VOID) ...@@ -131,8 +131,6 @@ VOID RecvEntry(VOID)
CHAR readBuf[BUFFER_LEN] = {0}; CHAR readBuf[BUFFER_LEN] = {0};
UINT32 readLen = BUFFER_LEN; UINT32 readLen = BUFFER_LEN;
//休眠1s
usleep(1000000);
ret = LOS_QueueReadCopy(g_queue, readBuf, &readLen, 0); ret = LOS_QueueReadCopy(g_queue, readBuf, &readLen, 0);
if(ret != LOS_OK) { if(ret != LOS_OK) {
printf("recv message failure, error: %x\n", ret); printf("recv message failure, error: %x\n", ret);
...@@ -145,12 +143,12 @@ VOID RecvEntry(VOID) ...@@ -145,12 +143,12 @@ VOID RecvEntry(VOID)
printf("delete the queue failure, error: %x\n", ret); printf("delete the queue failure, error: %x\n", ret);
} }
printf("delete the queue success!\n"); printf("delete the queue success.\n");
} }
UINT32 ExampleQueue(VOID) UINT32 ExampleQueue(VOID)
{ {
printf("start queue example\n"); printf("start queue example.\n");
UINT32 ret = 0; UINT32 ret = 0;
UINT32 task1, task2; UINT32 task1, task2;
TSK_INIT_PARAM_S initParam = {0}; TSK_INIT_PARAM_S initParam = {0};
...@@ -169,6 +167,7 @@ UINT32 ExampleQueue(VOID) ...@@ -169,6 +167,7 @@ UINT32 ExampleQueue(VOID)
initParam.pcName = "RecvQueue"; initParam.pcName = "RecvQueue";
initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)RecvEntry; initParam.pfnTaskEntry = (TSK_ENTRY_FUNC)RecvEntry;
initParam.usTaskPrio = 10;
ret = LOS_TaskCreate(&task2, &initParam); ret = LOS_TaskCreate(&task2, &initParam);
if(ret != LOS_OK) { if(ret != LOS_OK) {
printf("create task2 failed, error: %x\n", ret); printf("create task2 failed, error: %x\n", ret);
...@@ -180,7 +179,7 @@ UINT32 ExampleQueue(VOID) ...@@ -180,7 +179,7 @@ UINT32 ExampleQueue(VOID)
printf("create queue failure, error: %x\n", ret); printf("create queue failure, error: %x\n", ret);
} }
printf("create the queue success!\n"); printf("create the queue success.\n");
LOS_TaskUnlock(); LOS_TaskUnlock();
return ret; return ret;
} }
...@@ -191,9 +190,9 @@ UINT32 ExampleQueue(VOID) ...@@ -191,9 +190,9 @@ UINT32 ExampleQueue(VOID)
编译运行得到的结果为: 编译运行得到的结果为:
``` ```
start test example start queue example.
create the queue success! create the queue success.
recv message: test message recv message: test message.
delete the queue success! delete the queue success.
``` ```
...@@ -197,6 +197,9 @@ OpenHarmony LiteOS-M的动态内存管理主要为用户提供以下功能,接 ...@@ -197,6 +197,9 @@ OpenHarmony LiteOS-M的动态内存管理主要为用户提供以下功能,接
``` ```
#include "los_memory.h" #include "los_memory.h"
#define TEST_POOL_SIZE (2*1024)
__attribute__((aligned(4))) UINT8 g_testPool[TEST_POOL_SIZE];
VOID Example_DynMem(VOID) VOID Example_DynMem(VOID)
{ {
UINT32 *mem = NULL; UINT32 *mem = NULL;
......
...@@ -116,53 +116,54 @@ void Timer1_Callback(UINT32 arg) // 回调函数1 ...@@ -116,53 +116,54 @@ void Timer1_Callback(UINT32 arg) // 回调函数1
{ {
UINT32 tick_last1; UINT32 tick_last1;
g_timerCount1++; 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); printf("g_timerCount1=%d, tick_last1=%d\n", g_timerCount1, tick_last1);
} }
void Timer2_Callback(UINT32 arg) // 回调函数2 void Timer2_Callback(UINT32 arg) // 回调函数2
{ {
UINT32 tick_last2; UINT32 tick_last2;
tick_last2=(UINT32)LOS_TickCountGet(); tick_last2 = (UINT32)LOS_TickCountGet();
g_timerCount2++; g_timerCount2++;
printf("g_timerCount2=%d tick_last2=%d\n", g_timerCount2, tick_last2); printf("g_timerCount2=%d tick_last2=%d\n", g_timerCount2, tick_last2);
} }
void Timer_example(void) void Timer_example(void)
{ {
UINT32 id1; // timer id UINT32 ret;
UINT32 id2; // timer id UINT32 id1; // timer id1
UINT32 uwTick; UINT32 id2; // timer id2
UINT32 tickCount;
/*创建单次软件定时器,Tick数为1000,启动到1000Tick数时执行回调函数1 */ /*创建单次软件定时器,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 */ /*创建周期性软件定时器,每100Tick数执行回调函数2 */
LOS_SwtmrCreate(100, LOS_SWTMR_MODE_PERIOD, Timer2_Callback, &id2, 1); LOS_SwtmrCreate(100, LOS_SWTMR_MODE_PERIOD, Timer2_Callback, &id2, 1);
printf("create Timer1 success\n"); printf("create Timer1 success\n");
LOS_SwtmrStart (id1); //启动单次软件定时器 LOS_SwtmrStart(id1); //启动单次软件定时器
printf("start Timer1 sucess\n"); printf("start Timer1 success\n");
LOS_TaskDelay(200); //延时200Tick数 LOS_TaskDelay(200); //延时200Tick数
LOS_SwtmrTimeGet(id1, &uwTick); // 获得单次软件定时器剩余Tick数 LOS_SwtmrTimeGet(id1, &tickCount); // 获得单次软件定时器剩余Tick数
printf("uwTick =%d\n", uwTick); printf("tickCount=%d\n", tickCount);
LOS_SwtmrStop(id1); // 停止软件定时器 LOS_SwtmrStop(id1); // 停止软件定时器
printf("stop Timer1 sucess\n"); printf("stop Timer1 success\n");
LOS_SwtmrStart(id1); LOS_SwtmrStart(id1);
LOS_TaskDelay(1000); LOS_TaskDelay(1000);
LOS_SwtmrDelete(id1); // 删除软件定时器
printf("delete Timer1 sucess\n");
LOS_SwtmrStart(id2); // 启动周期性软件定时器 LOS_SwtmrStart(id2); // 启动周期性软件定时器
printf("start Timer2\n"); printf("start Timer2\n");
LOS_TaskDelay(1000); LOS_TaskDelay(1000);
LOS_SwtmrStop(id2); LOS_SwtmrStop(id2);
LOS_SwtmrDelete(id2); ret = LOS_SwtmrDelete(id2); // 删除软件定时器
if (ret == LOS_OK) {
printf("delete Timer2 success\n");
}
} }
UINT32 Example_TaskEntry(VOID) UINT32 Example_TaskEntry(VOID)
...@@ -174,7 +175,7 @@ UINT32 Example_TaskEntry(VOID) ...@@ -174,7 +175,7 @@ UINT32 Example_TaskEntry(VOID)
LOS_TaskLock(); LOS_TaskLock();
/* 创建任务1 */ /* 创建任务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.pfnTaskEntry = (TSK_ENTRY_FUNC)Timer_example;
task1.pcName = "TimerTsk"; task1.pcName = "TimerTsk";
task1.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; task1.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
...@@ -198,11 +199,10 @@ UINT32 Example_TaskEntry(VOID) ...@@ -198,11 +199,10 @@ UINT32 Example_TaskEntry(VOID)
``` ```
create Timer1 success create Timer1 success
start Timer1 sucess start Timer1 success
uwTick =798 tickCount=798
stop Timer1 sucess stop Timer1 success
g_timerCount1=1, tick_last1=1208 g_timerCount1=1, tick_last1=1208
delete Timer1 sucess
start Timer2 start Timer2
g_timerCount2=1 tick_last2=1313 g_timerCount2=1 tick_last2=1313
g_timerCount2=2 tick_last2=1413 g_timerCount2=2 tick_last2=1413
...@@ -214,5 +214,6 @@ g_timerCount2=7 tick_last2=1913 ...@@ -214,5 +214,6 @@ g_timerCount2=7 tick_last2=1913
g_timerCount2=8 tick_last2=2013 g_timerCount2=8 tick_last2=2013
g_timerCount2=9 tick_last2=2113 g_timerCount2=9 tick_last2=2113
g_timerCount2=10 tick_last2=2213 g_timerCount2=10 tick_last2=2213
delete Timer2 success
``` ```
...@@ -39,7 +39,7 @@ OpenHarmony LiteOS-M的任务模块可以给用户提供多个任务,实现任 ...@@ -39,7 +39,7 @@ OpenHarmony LiteOS-M的任务模块可以给用户提供多个任务,实现任
- 运行态→阻塞态 - 运行态→阻塞态
正在运行的任务发生阻塞(挂起、延时、读信号量等)时,该任务会从就绪队列中删除,任务状态由运行态变成阻塞态,然后发生任务切换,运行就绪队列中最高优先级任务。 正在运行的任务发生阻塞(挂起、延时、读信号量等)时,将该任务插入到对应的阻塞队列中,任务状态由运行态变成阻塞态,然后发生任务切换,运行就绪队列中最高优先级任务。
- 阻塞态→就绪态(阻塞态→运行态) - 阻塞态→就绪态(阻塞态→运行态)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册