From 5ebfae3d5831b53ecbb93a7feaa90bab6e9aeee5 Mon Sep 17 00:00:00 2001 From: lianzhian Date: Mon, 16 May 2022 17:26:00 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=96=B0=E5=A2=9E3861=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E6=A0=B7=E4=BE=8B=E4=BE=9B=E5=BC=80=E5=8F=91=E8=80=85=E5=8F=82?= =?UTF-8?q?=E8=80=8300=5Fthread?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lianzhian --- hispark_pegasus/demo/00_thread/BUILD.gn | 23 +++ hispark_pegasus/demo/00_thread/README.md | 187 +++++++++++++++++++++++ hispark_pegasus/demo/00_thread/thread.c | 85 +++++++++++ 3 files changed, 295 insertions(+) create mode 100644 hispark_pegasus/demo/00_thread/BUILD.gn create mode 100644 hispark_pegasus/demo/00_thread/README.md create mode 100644 hispark_pegasus/demo/00_thread/thread.c diff --git a/hispark_pegasus/demo/00_thread/BUILD.gn b/hispark_pegasus/demo/00_thread/BUILD.gn new file mode 100644 index 00000000..07d4bf4d --- /dev/null +++ b/hispark_pegasus/demo/00_thread/BUILD.gn @@ -0,0 +1,23 @@ +# Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +static_library("thread_demo") { + sources = [ + "thread.c" + ] + + include_dirs = [ + "//utils/native/lite/include", + "//kernel/liteos_m/components/cmsis/2.0", + ] +} diff --git a/hispark_pegasus/demo/00_thread/README.md b/hispark_pegasus/demo/00_thread/README.md new file mode 100644 index 00000000..f4737ee0 --- /dev/null +++ b/hispark_pegasus/demo/00_thread/README.md @@ -0,0 +1,187 @@ +# HiSpark WiFi-IoT 鸿蒙开发套件样例开发--线程(Thread) + +![hihope_illustration](https://gitee.com/hihopeorg/hispark-hm-pegasus/raw/master/docs/figures/hihope_illustration.png) + +[HiSpark WiFi-IoT鸿蒙开发套件](https://item.taobao.com/item.htm?spm=a1z10.1-c-s.w5003-23341819265.1.bf644a82Da9PZK&id=622343426064&scene=taobao_shop) 首发于HDC 2020,是首批支持HarmonyOS 2.0的开发套件,亦是鸿蒙官方推荐套件,由润和软件HiHope量身打造,已在鸿蒙社区和广大鸿蒙开发者中得到广泛应用。 + +![wifi_iot](https://gitee.com/hihopeorg/hispark-hm-pegasus/raw/master/docs/figures/wifi_iot.png) + +## 一、Thread API + +| API名称 | 说明 | +| --------------------- | ------------------------------------------------------ | +| osThreadNew | 创建一个线程并将其加入活跃线程组中 | +| osThreadGetName | 返回指定线程的名字 | +| osThreadGetId | 返回当前运行线程的线程ID | +| osThreadGetState | 返回当前线程的状态 | +| osThreadSetPriority | 设置指定线程的优先级 | +| osThreadGetPriority | 获取当前线程的优先级 | +| osThreadYield | 将运行控制转交给下一个处于READY状态的线程 | +| osThreadSuspend | 挂起指定线程的运行 | +| osThreadResume | 恢复指定线程的运行 | +| osThreadDetach | 分离指定的线程(当线程终止运行时,线程存储可以被回收) | +| osThreadJoin | 等待指定线程终止运行 | +| osThreadExit | 终止当前线程的运行 | +| osThreadTerminate | 终止指定线程的运行 | +| osThreadGetStackSize | 获取指定线程的栈空间大小 | +| osThreadGetStackSpace | 获取指定线程的未使用的栈空间大小 | +| osThreadGetCount | 获取活跃线程数 | +| osThreadEnumerate | 获取线程组中的活跃线程数 | + +### osThreadNew() + +```c +osThreadId_t osThreadNew(osThreadFunc_t func, void *argument,const osThreadAttr_t *attr ) +``` + +> **注意** :不能在中断服务调用该函数 + +**参数:** + +| 名字 | 描述 | +| :------- | :------------------------------- | +| func | 线程函数. | +| argument | 作为启动参数传递给线程函数的指针 | +| attr | 线程属性 | + +### osThreadTerminate() + +```c +osStatus_t osThreadTerminate (osThreadId_t thread_id) +``` + +| 名字 | 描述 | +| --------- | ---------------------------------------------------- | +| thread_id | 指定线程id,该id是由osThreadNew或者osThreadGetId获得 | + +## 二、代码分析 + +创建线程,创建成功则打印线程名字和线程ID + +``` +osThreadId_t newThread(char *name, osThreadFunc_t func, void *arg) { + osThreadAttr_t attr = { + name, 0, NULL, 0, NULL, 1024*2, osPriorityNormal, 0, 0 + }; + osThreadId_t tid = osThreadNew(func, arg, &attr); + if (tid == NULL) { + printf("osThreadNew(%s) failed.\r\n", name); + } else { + printf("osThreadNew(%s) success, thread id: %d.\r\n", name, tid); + } + return tid; +} +``` + +该函数首先会打印自己的参数,然后对全局变量count进行循环+1操作,之后会打印count的值 + +``` +void threadTest(void *arg) { + static int count = 0; + printf("%s\r\n",(char *)arg); + osThreadId_t tid = osThreadGetId(); + printf("threadTest osThreadGetId, thread id:%p\r\n", tid); + while (1) { + count++; + printf("threadTest, count: %d.\r\n", count); + osDelay(20); + } +} +``` + +主程序rtosv2_thread_main创建线程并运行,并使用上述API进行相关操作,最后终止所创建的线程。 + +``` +void rtosv2_thread_main(void *arg) { + (void)arg; + osThreadId_t tid=newThread("test_thread", threadTest, "This is a test thread."); + + const char *t_name = osThreadGetName(tid); + printf("[Thread Test]osThreadGetName, thread name: %s.\r\n", t_name); + + osThreadState_t state = osThreadGetState(tid); + printf("[Thread Test]osThreadGetState, state :%d.\r\n", state); + + osStatus_t status = osThreadSetPriority(tid, osPriorityNormal4); + printf("[Thread Test]osThreadSetPriority, status: %d.\r\n", status); + + osPriority_t pri = osThreadGetPriority (tid); + printf("[Thread Test]osThreadGetPriority, priority: %d.\r\n", pri); + + status = osThreadSuspend(tid); + printf("[Thread Test]osThreadSuspend, status: %d.\r\n", status); + + status = osThreadResume(tid); + printf("[Thread Test]osThreadResume, status: %d.\r\n", status); + + uint32_t stacksize = osThreadGetStackSize(tid); + printf("[Thread Test]osThreadGetStackSize, stacksize: %d.\r\n", stacksize); + + uint32_t stackspace = osThreadGetStackSpace(tid); + printf("[Thread Test]osThreadGetStackSpace, stackspace: %d.\r\n", stackspace); + + uint32_t t_count = osThreadGetCount(); + printf("[Thread Test]osThreadGetCount, count: %d.\r\n", t_count); + + osDelay(100); + status = osThreadTerminate(tid); + printf("[Thread Test]osThreadTerminate, status: %d.\r\n", status); +} +``` + +## 三、如何编译 + +1. 将此目录下的 `thread.c` 和 `BUILD.gn` 复制到openharmony源码的`applications\sample\wifi-iot\app\iothardware`目录下, +2. 修改openharmony源码的`applications\sample\wifi-iot\app\BUILD.gn`文件,将其中的 `features` 改为: + +``` + features = [ + "iothardware:thread_demo", + ] +``` + + 3.在openharmony源码顶层目录执行:`python build.py wifiiot` + +## 四、运行结果 + +``` +[Thread Test] osThreadNew(test_thread) success. +[Thread Test] osThreadGetName, thread name: test_thread. +[Thread Test] osThreadGetState, state :1. +[Thread Test] This is a test thread. <-testThread log +[Thread Test] threadTest osThreadGetId, thread id:0xe8544 +[Thread Test] threadTest, count: 1. <-testThread log +[Thread Test] osThreadSetPriority, status: 0. +[Thread Test] osThreadGetPriority, priority: 28. +[Thread Test] osThreadSuspend, status: 0. +[Thread Test] osThreadResume, status: 0. +[Thread Test] osThreadGetStackSize, stacksize: 2048. +[Thread Test] osThreadGetStackSpace, stackspace: 1144. +[Thread Test] osThreadGetCount, count: 12. +[Thread Test] threadTest, count: 2. <-testThread log +[Thread Test] threadTest, count: 3. <-testThread log +[Thread Test] threadTest, count: 4. <-testThread log +[Thread Test] threadTest, count: 5. <-testThread log +[Thread Test] threadTest, count: 6. <-testThread log +[Thread Test] osThreadTerminate, status: 0. +``` + +### 【套件支持】 + +##### 1. 套件介绍 http://www.hihope.org/pro/pro1.aspx?mtt=8 + +##### 2. 套件购买 https://item.taobao.com/item.htm?id=622343426064&scene=taobao_shop + +##### 3. 技术资料 + +- Gitee码云网站(OpenHarmony Sample Code等) **https://gitee.com/hihopeorg** + +- HiHope官网-资源中心(SDK包、技术文档下载)[**www.hihope.org**](http://www.hihope.org/) + +##### 4. 互动交流 + +- 润和HiHope鸿蒙技术交流-微信群(加群管理员微信13605188699,发送文字#申请加入润和官方鸿蒙群#,予以邀请入群) +- HiHope开发者社区-论坛 **https://bbs.elecfans.com/group_1429** +- 润和HiHope鸿蒙售后服务群(QQ:980599547) +- 售后服务电话(025-52668590) + diff --git a/hispark_pegasus/demo/00_thread/thread.c b/hispark_pegasus/demo/00_thread/thread.c new file mode 100644 index 00000000..9d7950ed --- /dev/null +++ b/hispark_pegasus/demo/00_thread/thread.c @@ -0,0 +1,85 @@ +#include +#include + +#include "ohos_init.h" +#include "cmsis_os2.h" + +osThreadId_t newThread(char *name, osThreadFunc_t func, void *arg) { + osThreadAttr_t attr = { + name, 0, NULL, 0, NULL, 1024*2, osPriorityNormal, 0, 0 + }; + osThreadId_t tid = osThreadNew(func, arg, &attr); + if (tid == NULL) { + printf("[Thread Test] osThreadNew(%s) failed.\r\n", name); + } else { + printf("[Thread Test] osThreadNew(%s) success, thread id: %d.\r\n", name, tid); + } + return tid; +} + +void threadTest(void *arg) { + static int count = 0; + printf("%s\r\n",(char *)arg); + osThreadId_t tid = osThreadGetId(); + printf("[Thread Test] threadTest osThreadGetId, thread id:%p\r\n", tid); + while (1) { + count++; + printf("[Thread Test] threadTest, count: %d.\r\n", count); + osDelay(20); + } +} + +void rtosv2_thread_main(void *arg) { + (void)arg; + osThreadId_t tid=newThread("test_thread", threadTest, "This is a test thread."); + + const char *t_name = osThreadGetName(tid); + printf("[Thread Test] osThreadGetName, thread name: %s.\r\n", t_name); + + osThreadState_t state = osThreadGetState(tid); + printf("[Thread Test] osThreadGetState, state :%d.\r\n", state); + + osStatus_t status = osThreadSetPriority(tid, osPriorityNormal4); + printf("[Thread Test] osThreadSetPriority, status: %d.\r\n", status); + + osPriority_t pri = osThreadGetPriority (tid); + printf("[Thread Test] osThreadGetPriority, priority: %d.\r\n", pri); + + status = osThreadSuspend(tid); + printf("[Thread Test] osThreadSuspend, status: %d.\r\n", status); + + status = osThreadResume(tid); + printf("[Thread Test] osThreadResume, status: %d.\r\n", status); + + uint32_t stacksize = osThreadGetStackSize(tid); + printf("[Thread Test] osThreadGetStackSize, stacksize: %u.\r\n", stacksize); + + uint32_t stackspace = osThreadGetStackSpace(tid); + printf("[Thread Test] osThreadGetStackSpace, stackspace: %u.\r\n", stackspace); + + uint32_t t_count = osThreadGetCount(); + printf("[Thread Test] osThreadGetCount, count: %u.\r\n", t_count); + + osDelay(100); + status = osThreadTerminate(tid); + printf("[Thread Test] osThreadTerminate, status: %d.\r\n", status); +} + +static void ThreadTestTask(void) +{ + osThreadAttr_t attr; + + attr.name = "rtosv2_thread_main"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = 1024; + attr.priority = osPriorityNormal; + + if (osThreadNew((osThreadFunc_t)rtosv2_thread_main, NULL, &attr) == NULL) { + printf("[ThreadTestTask] Falied to create rtosv2_thread_main!\n"); + } +} + +APP_FEATURE_INIT(ThreadTestTask); \ No newline at end of file -- Gitee From 9d9ea6fa5894571a41e3bec7d125a05469290392 Mon Sep 17 00:00:00 2001 From: lianzhian Date: Mon, 16 May 2022 17:26:00 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E6=96=B0=E5=A2=9E3861=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E6=A0=B7=E4=BE=8B=E4=BE=9B=E5=BC=80=E5=8F=91=E8=80=85=E5=8F=82?= =?UTF-8?q?=E8=80=8300=5Fthread?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lianzhian --- hispark_pegasus/.DS_Store | Bin 0 -> 6148 bytes hispark_pegasus/demo/.DS_Store | Bin 0 -> 6148 bytes hispark_pegasus/demo/00_thread/BUILD.gn | 23 +++ hispark_pegasus/demo/00_thread/README.md | 187 +++++++++++++++++++++++ hispark_pegasus/demo/00_thread/thread.c | 101 ++++++++++++ 5 files changed, 311 insertions(+) create mode 100644 hispark_pegasus/.DS_Store create mode 100644 hispark_pegasus/demo/.DS_Store create mode 100644 hispark_pegasus/demo/00_thread/BUILD.gn create mode 100644 hispark_pegasus/demo/00_thread/README.md create mode 100644 hispark_pegasus/demo/00_thread/thread.c diff --git a/hispark_pegasus/.DS_Store b/hispark_pegasus/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8067953377d8b700e3360ca97c3b8bbbe5e1c918 GIT binary patch literal 6148 zcmeH~F>b>!3`IW^4*{}x%&4UY=naG*IYBQFB<_~NLy=ua&nLyDZs)=XJ^}KHlnL8^ zuuK4Ud`$1a2w+Ed;?2XtjQM~GpZLN&ec$fadA@s*w&{SU^bw2w+!myO6p#W^Knh5K z6)BL%_-?NP&d{+n$ep{-5c8&HsxQrBXl& zyqE$uoIXxRzEqyAzh2Mlm#q4_(aE@+;m1z^6F-U%^f2xhUywD~I$5FVM<8TSkOKdz Fz!O6Z5~=_I literal 0 HcmV?d00001 diff --git a/hispark_pegasus/demo/.DS_Store b/hispark_pegasus/demo/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..11e5f02e1ebaeb70ae749c686dd9b5653235346f GIT binary patch literal 6148 zcmeHKIZgvX5Ud6VMkEdi=LztGk!4=M130`$1ePoT&NuSA{4}bM0Bdn(603UEQ!_nX zv)T%#w*lC4H#`6f0CTz{_C8F__uVIURS_f7dBz7m@s3vv!`CGH?|^e}aL?x%-@p0m z&D(an@okwDkOERb3P=Gda7G2HxXy3Sc&3h$0#e{I6!80@(H(o?m>5?FhiCzaGls)B zk6wbLuSI;@%xt2bM9C>C$$`7P36JyD|+kOIdF zT<3D(_5YE6qW?c8X(a`uz(pxwv(?jT$xo` **注意** :不能在中断服务调用该函数 + +**参数:** + +| 名字 | 描述 | +| :------- | :------------------------------- | +| func | 线程函数. | +| argument | 作为启动参数传递给线程函数的指针 | +| attr | 线程属性 | + +### osThreadTerminate() + +```c +osStatus_t osThreadTerminate (osThreadId_t thread_id) +``` + +| 名字 | 描述 | +| --------- | ---------------------------------------------------- | +| thread_id | 指定线程id,该id是由osThreadNew或者osThreadGetId获得 | + +## 二、代码分析 + +创建线程,创建成功则打印线程名字和线程ID + +``` +osThreadId_t newThread(char *name, osThreadFunc_t func, void *arg) { + osThreadAttr_t attr = { + name, 0, NULL, 0, NULL, 1024*2, osPriorityNormal, 0, 0 + }; + osThreadId_t tid = osThreadNew(func, arg, &attr); + if (tid == NULL) { + printf("osThreadNew(%s) failed.\r\n", name); + } else { + printf("osThreadNew(%s) success, thread id: %d.\r\n", name, tid); + } + return tid; +} +``` + +该函数首先会打印自己的参数,然后对全局变量count进行循环+1操作,之后会打印count的值 + +``` +void threadTest(void *arg) { + static int count = 0; + printf("%s\r\n",(char *)arg); + osThreadId_t tid = osThreadGetId(); + printf("threadTest osThreadGetId, thread id:%p\r\n", tid); + while (1) { + count++; + printf("threadTest, count: %d.\r\n", count); + osDelay(20); + } +} +``` + +主程序rtosv2_thread_main创建线程并运行,并使用上述API进行相关操作,最后终止所创建的线程。 + +``` +void rtosv2_thread_main(void *arg) { + (void)arg; + osThreadId_t tid=newThread("test_thread", threadTest, "This is a test thread."); + + const char *t_name = osThreadGetName(tid); + printf("[Thread Test]osThreadGetName, thread name: %s.\r\n", t_name); + + osThreadState_t state = osThreadGetState(tid); + printf("[Thread Test]osThreadGetState, state :%d.\r\n", state); + + osStatus_t status = osThreadSetPriority(tid, osPriorityNormal4); + printf("[Thread Test]osThreadSetPriority, status: %d.\r\n", status); + + osPriority_t pri = osThreadGetPriority (tid); + printf("[Thread Test]osThreadGetPriority, priority: %d.\r\n", pri); + + status = osThreadSuspend(tid); + printf("[Thread Test]osThreadSuspend, status: %d.\r\n", status); + + status = osThreadResume(tid); + printf("[Thread Test]osThreadResume, status: %d.\r\n", status); + + uint32_t stacksize = osThreadGetStackSize(tid); + printf("[Thread Test]osThreadGetStackSize, stacksize: %d.\r\n", stacksize); + + uint32_t stackspace = osThreadGetStackSpace(tid); + printf("[Thread Test]osThreadGetStackSpace, stackspace: %d.\r\n", stackspace); + + uint32_t t_count = osThreadGetCount(); + printf("[Thread Test]osThreadGetCount, count: %d.\r\n", t_count); + + osDelay(100); + status = osThreadTerminate(tid); + printf("[Thread Test]osThreadTerminate, status: %d.\r\n", status); +} +``` + +## 三、如何编译 + +1. 将此目录下的 `thread.c` 和 `BUILD.gn` 复制到openharmony源码的`applications\sample\wifi-iot\app\iothardware`目录下, +2. 修改openharmony源码的`applications\sample\wifi-iot\app\BUILD.gn`文件,将其中的 `features` 改为: + +``` + features = [ + "iothardware:thread_demo", + ] +``` + + 3.在openharmony源码顶层目录执行:`python build.py wifiiot` + +## 四、运行结果 + +``` +[Thread Test] osThreadNew(test_thread) success. +[Thread Test] osThreadGetName, thread name: test_thread. +[Thread Test] osThreadGetState, state :1. +[Thread Test] This is a test thread. <-testThread log +[Thread Test] threadTest osThreadGetId, thread id:0xe8544 +[Thread Test] threadTest, count: 1. <-testThread log +[Thread Test] osThreadSetPriority, status: 0. +[Thread Test] osThreadGetPriority, priority: 28. +[Thread Test] osThreadSuspend, status: 0. +[Thread Test] osThreadResume, status: 0. +[Thread Test] osThreadGetStackSize, stacksize: 2048. +[Thread Test] osThreadGetStackSpace, stackspace: 1144. +[Thread Test] osThreadGetCount, count: 12. +[Thread Test] threadTest, count: 2. <-testThread log +[Thread Test] threadTest, count: 3. <-testThread log +[Thread Test] threadTest, count: 4. <-testThread log +[Thread Test] threadTest, count: 5. <-testThread log +[Thread Test] threadTest, count: 6. <-testThread log +[Thread Test] osThreadTerminate, status: 0. +``` + +### 【套件支持】 + +##### 1. 套件介绍 http://www.hihope.org/pro/pro1.aspx?mtt=8 + +##### 2. 套件购买 https://item.taobao.com/item.htm?id=622343426064&scene=taobao_shop + +##### 3. 技术资料 + +- Gitee码云网站(OpenHarmony Sample Code等) **https://gitee.com/hihopeorg** + +- HiHope官网-资源中心(SDK包、技术文档下载)[**www.hihope.org**](http://www.hihope.org/) + +##### 4. 互动交流 + +- 润和HiHope鸿蒙技术交流-微信群(加群管理员微信13605188699,发送文字#申请加入润和官方鸿蒙群#,予以邀请入群) +- HiHope开发者社区-论坛 **https://bbs.elecfans.com/group_1429** +- 润和HiHope鸿蒙售后服务群(QQ:980599547) +- 售后服务电话(025-52668590) + diff --git a/hispark_pegasus/demo/00_thread/thread.c b/hispark_pegasus/demo/00_thread/thread.c new file mode 100644 index 00000000..6003a495 --- /dev/null +++ b/hispark_pegasus/demo/00_thread/thread.c @@ -0,0 +1,101 @@ +#include +#include + +/* + * Copyright (C) 2022 HiHope Open Source Organization . + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http:// www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * + * limitations under the License. + */ + +#include "ohos_init.h" +#include "cmsis_os2.h" + +osThreadId_t newThread(char *name, osThreadFunc_t func, void *arg) { + osThreadAttr_t attr = { + name, 0, NULL, 0, NULL, 1024*2, osPriorityNormal, 0, 0 + }; + osThreadId_t tid = osThreadNew(func, arg, &attr); + if (tid == NULL) { + printf("[Thread Test] osThreadNew(%s) failed.\r\n", name); + } else { + printf("[Thread Test] osThreadNew(%s) success, thread id: %d.\r\n", name, tid); + } + return tid; +} + +void threadTest(void *arg) { + static int count = 0; + printf("%s\r\n",(char *)arg); + osThreadId_t tid = osThreadGetId(); + printf("[Thread Test] threadTest osThreadGetId, thread id:%p\r\n", tid); + while (1) { + count++; + printf("[Thread Test] threadTest, count: %d.\r\n", count); + osDelay(20); + } +} + +void rtosv2_thread_main(void *arg) { + (void)arg; + osThreadId_t tid = newThread("test_thread", threadTest, "This is a test thread."); + + const char *t_name = osThreadGetName(tid); + printf("[Thread Test] osThreadGetName, thread name: %s.\r\n", t_name); + + osThreadState_t state = osThreadGetState(tid); + printf("[Thread Test] osThreadGetState, state :%d.\r\n", state); + + osStatus_t status = osThreadSetPriority(tid, osPriorityNormal4); + printf("[Thread Test] osThreadSetPriority, status: %d.\r\n", status); + + osPriority_t pri = osThreadGetPriority (tid); + printf("[Thread Test] osThreadGetPriority, priority: %d.\r\n", pri); + + status = osThreadSuspend(tid); + printf("[Thread Test] osThreadSuspend, status: %d.\r\n", status); + + status = osThreadResume(tid); + printf("[Thread Test] osThreadResume, status: %d.\r\n", status); + + uint32_t stacksize = osThreadGetStackSize(tid); + printf("[Thread Test] osThreadGetStackSize, stacksize: %u.\r\n", stacksize); + + uint32_t stackspace = osThreadGetStackSpace(tid); + printf("[Thread Test] osThreadGetStackSpace, stackspace: %u.\r\n", stackspace); + + uint32_t t_count = osThreadGetCount(); + printf("[Thread Test] osThreadGetCount, count: %u.\r\n", t_count); + + osDelay(100); + status = osThreadTerminate(tid); + printf("[Thread Test] osThreadTerminate, status: %d.\r\n", status); +} + +static void ThreadTestTask(void) +{ + osThreadAttr_t attr; + + attr.name = "rtosv2_thread_main"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = 1024; + attr.priority = osPriorityNormal; + + if (osThreadNew((osThreadFunc_t)rtosv2_thread_main, NULL, &attr) == NULL) { + printf("[ThreadTestTask] Falied to create rtosv2_thread_main!\n"); + } +} + +APP_FEATURE_INIT(ThreadTestTask); \ No newline at end of file -- Gitee From 2ebec521ccddbc1439ea87f93e8d41afe47c6945 Mon Sep 17 00:00:00 2001 From: lianzhian Date: Tue, 17 May 2022 10:12:45 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=9D=99=E6=80=81?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E9=83=A8=E5=88=86=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lianzhian --- hispark_pegasus/.DS_Store | Bin 6148 -> 0 bytes hispark_pegasus/demo/.DS_Store | Bin 6148 -> 0 bytes hispark_pegasus/demo/00_thread/README.md | 2 +- hispark_pegasus/demo/00_thread/thread.c | 23 +++++++++++++++-------- 4 files changed, 16 insertions(+), 9 deletions(-) delete mode 100644 hispark_pegasus/.DS_Store delete mode 100644 hispark_pegasus/demo/.DS_Store diff --git a/hispark_pegasus/.DS_Store b/hispark_pegasus/.DS_Store deleted file mode 100644 index 8067953377d8b700e3360ca97c3b8bbbe5e1c918..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~F>b>!3`IW^4*{}x%&4UY=naG*IYBQFB<_~NLy=ua&nLyDZs)=XJ^}KHlnL8^ zuuK4Ud`$1a2w+Ed;?2XtjQM~GpZLN&ec$fadA@s*w&{SU^bw2w+!myO6p#W^Knh5K z6)BL%_-?NP&d{+n$ep{-5c8&HsxQrBXl& zyqE$uoIXxRzEqyAzh2Mlm#q4_(aE@+;m1z^6F-U%^f2xhUywD~I$5FVM<8TSkOKdz Fz!O6Z5~=_I diff --git a/hispark_pegasus/demo/.DS_Store b/hispark_pegasus/demo/.DS_Store deleted file mode 100644 index 11e5f02e1ebaeb70ae749c686dd9b5653235346f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKIZgvX5Ud6VMkEdi=LztGk!4=M130`$1ePoT&NuSA{4}bM0Bdn(603UEQ!_nX zv)T%#w*lC4H#`6f0CTz{_C8F__uVIURS_f7dBz7m@s3vv!`CGH?|^e}aL?x%-@p0m z&D(an@okwDkOERb3P=Gda7G2HxXy3Sc&3h$0#e{I6!80@(H(o?m>5?FhiCzaGls)B zk6wbLuSI;@%xt2bM9C>C$$`7P36JyD|+kOIdF zT<3D(_5YE6qW?c8X(a`uz(pxwv(?jT$xo` Date: Mon, 23 May 2022 14:42:30 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86?= =?UTF-8?q?=E9=9D=99=E6=80=81=E6=A3=80=E6=B5=8B=E4=BB=A3=E7=A0=811.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lianzhian --- hispark_pegasus/demo/00_thread/README.md | 10 +++++----- hispark_pegasus/demo/00_thread/thread.c | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/hispark_pegasus/demo/00_thread/README.md b/hispark_pegasus/demo/00_thread/README.md index 4259838e..e6768fec 100644 --- a/hispark_pegasus/demo/00_thread/README.md +++ b/hispark_pegasus/demo/00_thread/README.md @@ -1,10 +1,10 @@ -# HiSpark WiFi-IoT 鸿蒙开发套件样例开发--线程(Thread) +# HiSpark WiFi-IoT 开发套件样例开发--线程(Thread) ![hihope_illustration](https://gitee.com/hihopeorg/hispark-hm-pegasus/raw/master/docs/figures/hihope_illustration.png) -[HiSpark WiFi-IoT鸿蒙开发套件]首发于HDC 2020,是首批支持HarmonyOS 2.0的开发套件,亦是鸿蒙官方推荐套件,由润和软件HiHope量身打造,已在鸿蒙社区和广大鸿蒙开发者中得到广泛应用。 +[HiSpark WiFi-IoT开发套件]首发于HDC 2020,是首批支持OpenHarmony 2.0的开发套件,亦是官方推荐套件,由润和软件HiHope量身打造,已在OpenHarmony社区和广大OpenHarmony开发者中得到广泛应用。 -![wifi_iot](https://gitee.com/hihopeorg/hispark-hm-pegasus/raw/master/docs/figures/wifi_iot.png) +![wifi_iot](https://gitee.com/hihopeorg/hispark-hm-pegasus/raw/master/docs/figures/2.png) ## 一、Thread API @@ -180,8 +180,8 @@ void rtosv2_thread_main(void *arg) { ##### 4. 互动交流 -- 润和HiHope鸿蒙技术交流-微信群(加群管理员微信13605188699,发送文字#申请加入润和官方鸿蒙群#,予以邀请入群) +- 润和HiHope技术交流-微信群(加群管理员微信13605188699,发送文字#申请加入润和官方OpenHarmony群#,予以邀请入群) - HiHope开发者社区-论坛 **https://bbs.elecfans.com/group_1429** -- 润和HiHope鸿蒙售后服务群(QQ:980599547) +- 润和HiHope售后服务群(QQ:980599547) - 售后服务电话(025-52668590) diff --git a/hispark_pegasus/demo/00_thread/thread.c b/hispark_pegasus/demo/00_thread/thread.c index a57a530a..f5d67a85 100644 --- a/hispark_pegasus/demo/00_thread/thread.c +++ b/hispark_pegasus/demo/00_thread/thread.c @@ -1,10 +1,10 @@ /* - * Copyright (C) 2022 HiHope Open Source Organization . + * Copyright (C) 2021 HiHope Open Source Organization . * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http:// www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,7 +23,7 @@ #define OS_DELAY 100 #define OS_DELAYONE 20 -osThreadId_t newThread(char *name, osThreadFunc_t func, void *arg) +osThreadId_t newThread(char *name, osThreadFunc_t func, int*arg) { osThreadAttr_t attr = { name, 0, NULL, 0, NULL, 1024*2, osPriorityNormal, 0, 0 @@ -37,10 +37,10 @@ osThreadId_t newThread(char *name, osThreadFunc_t func, void *arg) return tid; } -void threadTest(void *arg) +void threadTest(int *arg) { static int count = 0; - printf("%s\r\n",(char *)arg); + printf("%s\r\n", (char *)arg); osThreadId_t tid = osThreadGetId(); printf("[Thread Test] threadTest osThreadGetId, thread id:%p\r\n", tid); while (1) { @@ -50,9 +50,9 @@ void threadTest(void *arg) } } -void rtosv2_thread_main(void *arg) +void rtosv2_thread_main(int *arg) { - (void)arg; + (int)arg; osThreadId_t tid = newThread("test_thread", threadTest, "This is a test thread."); const char *t_name = osThreadGetName(tid); -- Gitee From a3effb6f515a0f7e971fc3f4d7e578cfab8d0a23 Mon Sep 17 00:00:00 2001 From: lianzhian Date: Tue, 24 May 2022 09:33:01 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9format=5Fcheck=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hispark_pegasus/demo/00_thread/thread.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/hispark_pegasus/demo/00_thread/thread.c b/hispark_pegasus/demo/00_thread/thread.c index f5d67a85..a423a19c 100644 --- a/hispark_pegasus/demo/00_thread/thread.c +++ b/hispark_pegasus/demo/00_thread/thread.c @@ -1,10 +1,10 @@ /* - * Copyright (C) 2021 HiHope Open Source Organization . + * Copyright (C) 2022 HiHope Open Source Organization . * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http:// www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -64,11 +64,11 @@ void rtosv2_thread_main(int *arg) osStatus_t status = osThreadSetPriority(tid, osPriorityNormal4); printf("[Thread Test] osThreadSetPriority, status: %d.\r\n", status); - osPriority_t pri = osThreadGetPriority(tid); + osPriority_t pri = osThreadGetPriority(tid); printf("[Thread Test] osThreadGetPriority, priority: %d.\r\n", pri); status = osThreadSuspend(tid); - printf("[Thread Test] osThreadSuspend, status: %d.\r\n", status); + printf("[Thread Test] osThreadSuspend, status: %d.\r\n", status); status = osThreadResume(tid); printf("[Thread Test] osThreadResume, status: %d.\r\n", status); @@ -80,7 +80,7 @@ void rtosv2_thread_main(int *arg) printf("[Thread Test] osThreadGetStackSpace, stackspace: %u.\r\n", stackspace); uint32_t t_count = osThreadGetCount(); - printf("[Thread Test] osThreadGetCount, count: %d.\r\n", t_count); + printf("[Thread Test] osThreadGetCount, count: %u.\r\n", t_count); osDelay(OS_DELAY); status = osThreadTerminate(tid); @@ -90,7 +90,6 @@ void rtosv2_thread_main(int *arg) static void ThreadTestTask(void) { osThreadAttr_t attr; - attr.name = "rtosv2_thread_main"; attr.attr_bits = 0U; attr.cb_mem = NULL; -- Gitee From 95067bc343b80d0e4bf4fd64e8ddfaef26e28228 Mon Sep 17 00:00:00 2001 From: lianzhian Date: Tue, 24 May 2022 09:37:55 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9format=5Fcheck=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lianzhian --- hispark_pegasus/demo/00_thread/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hispark_pegasus/demo/00_thread/thread.c b/hispark_pegasus/demo/00_thread/thread.c index a423a19c..305b417f 100644 --- a/hispark_pegasus/demo/00_thread/thread.c +++ b/hispark_pegasus/demo/00_thread/thread.c @@ -52,7 +52,7 @@ void threadTest(int *arg) void rtosv2_thread_main(int *arg) { - (int)arg; + (void)arg; osThreadId_t tid = newThread("test_thread", threadTest, "This is a test thread."); const char *t_name = osThreadGetName(tid); -- Gitee From 2f368faf9d51b8cba6ca30c8fa522127a4a61cdc Mon Sep 17 00:00:00 2001 From: lianzhian Date: Tue, 24 May 2022 10:54:59 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9format=5Fcheck=E9=94=99?= =?UTF-8?q?=E8=AF=AF1.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lianzhian --- hispark_pegasus/demo/00_thread/BUILD.gn | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/hispark_pegasus/demo/00_thread/BUILD.gn b/hispark_pegasus/demo/00_thread/BUILD.gn index 9ee6a429..9389703b 100644 --- a/hispark_pegasus/demo/00_thread/BUILD.gn +++ b/hispark_pegasus/demo/00_thread/BUILD.gn @@ -12,12 +12,10 @@ # limitations under the License. static_library("thread_demo") { - sources = [ - "thread.c" - ] + sources = [ "thread.c" ] - include_dirs = [ - "//utils/native/lite/include", - "//kernel/liteos_m/components/cmsis/2.0", - ] + include_dirs = [ + "//utils/native/lite/include", + "//kernel/liteos_m/components/cmsis/2.0", + ] } -- Gitee From 1e7cffdea0ae20c3e19d0598d75b7a649ea19b09 Mon Sep 17 00:00:00 2001 From: lianzhian Date: Tue, 24 May 2022 11:02:15 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9format=5Fcheck1.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lianzhian --- hispark_pegasus/demo/00_thread/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hispark_pegasus/demo/00_thread/thread.c b/hispark_pegasus/demo/00_thread/thread.c index 305b417f..a423a19c 100644 --- a/hispark_pegasus/demo/00_thread/thread.c +++ b/hispark_pegasus/demo/00_thread/thread.c @@ -52,7 +52,7 @@ void threadTest(int *arg) void rtosv2_thread_main(int *arg) { - (void)arg; + (int)arg; osThreadId_t tid = newThread("test_thread", threadTest, "This is a test thread."); const char *t_name = osThreadGetName(tid); -- Gitee