当前位置:网站首页>Sample development of WiFi IOT Hongmeng development kit
Sample development of WiFi IOT Hongmeng development kit
2022-06-27 01:46:00 【Runhe hihope community】
HiSpark WiFi-IoT Hongmeng Development Kit First appeared in HDC 2020, Is the first to support HarmonyOS 2.0 Development of Kit , It is also the official recommended kit of Hongmeng , By Runhe Software HiHope Tailored , It has been widely used in Hongmeng community and Hongmeng developers . ![]() One 、Thread API osThreadNew() osThreadId_t osThreadNew(osThreadFunc_t func, void *argument,const osThreadAttr_t *attr ) Copy Be careful : This function cannot be called when a service is interrupted Parameters osThreadTerminate() osStatus_t osThreadTerminate (osThreadId_t thread_id) Copy Two 、 The code analysis Create thread , If the creation is successful, the thread name and thread will be printed 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;} Copy This function first prints its own parameters , Then the global variables count Cycle through +1 operation , Then print count Value 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); }} Copy The main program rtosv2_thread_main Create threads and run , And use the above API Carry out relevant operations , Finally, terminate the created thread . 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);} 3、 ... and 、 How to compile Put... In this directory thread.c and BUILD.gn Copied to the openharmony Source code applications\sample\wifi-iot\app\iothardware Under the table of contents , modify openharmony Source code applications\sample\wifi-iot\app\BUILD.gn file , Will be one of the features Change it to : features = [ "iothardware:thread_demo", ] Copy 3. stay openharmony The top-level directory of the source code executes :python build.py wifiiot Four 、 Running results [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. Copy |
边栏推荐
- 接口测试框架实战(一) | Requests 与接口请求构造
- Continuous delivery blue ocean application
- Oracle/PLSQL: NumToDSInterval Function
- Oracle/PLSQL: Length Function
- Learn the most basic operation of discodiffusion
- perl语言中 fork()、exec()、waitpid() 、 $? >> 8 组合
- Oracle/PLSQL: CharToRowid Function
- SystemVerilog simulation speed increase
- p5.js死亡星球
- Bs-gx-016 implementation of textbook management system based on SSM
猜你喜欢

Pointer compression for JVM

30 MySQL tutorial MySQL storage engine overview

George Washington University: Hanhan Zhou | PAC: auxiliary value factor decomposition with counterfactual prediction in Multi-Agent Reinforcement Learning

BS-GX-016基于SSM实现教材管理系统

按键控制LED状态翻转

Arbre binaire OJ sujet
Reading a book in idea is too much!

做了两天的唯美蝴蝶动画

递归是会更秀strtok

uvm中的config机制方法总结(二)
随机推荐
Amazon elasticache quickly builds a cache service cluster, which is fast
Oracle/PLSQL: Cast Function
接口测试框架实战(一) | Requests 与接口请求构造
我靠副业一个月挣了3W块:你看不起的行业,真的很挣钱!
Oracle/PLSQL: NumToYMInterval Function
Memcached basics 14
两个页面之间传参方法
二叉树oj题目
XSS attack notes (Part 1)
Oracle/PLSQL: Lower Function
Oracle/PLSQL: Soundex Function
getReader() has already been called for this request
I encountered some problems when connecting to the database. How can I solve them?
Memcached foundations 12
Interface test framework practice (I) | requests and interface request construction
The listing of Fuyuan pharmaceutical is imminent: the net amount raised will reach 1.6 billion yuan, and hubaifan is the actual controller
【毕业季】角色转换
Memcached foundation 9
D's appendto packaging
Oracle/PLSQL: VSize Function
