Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Helloworld and basic Development Framework

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to use Helloworld and basic development framework". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use Helloworld and basic development framework.

1. Directory structure planning

Add a new business hello_world under app, where hello_world.c is the business code and BUILD.gn is the compilation script. The specific directory structure is as follows:

. └── applications └── sample └── wifi-iot └── app │── hello_world │ │── hello_world.c │ └── BUILD.gn └── BUILD.gn

2. Hello_world.c source code

/ * Architecture of business code 1. Task processing function HelloWorld_Task, to achieve business initialization, and in while (1) to achieve circular processing of the business 2. Task entry function HelloWorld_Entry: initializes the task and registers the task handler function 3. Call Hongmeng SYS_RUN (HelloWorld_Entry) to register the business * / # include # include # include "ohos_init.h" # include "cmsis_os2.h" / * 1. Task function: hello_world task * / static void* HelloWorld_Task (const char* arg) {(void) arg; printf ("[HelloWorld] HelloWorld_Task ()\ n"); while (1) {/ / logic code for task usleep (500000); / / us delay} return NULL;} / * 2. Task entry function: initialize the task * / static void HelloWorld_Entry (void) {osThreadAttr_t attr = {0}; printf ("[HelloWorld] HelloWorld_Entry ()\ n"); attr.name = "HelloWorld_Task"; 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) HelloWorld_Task, NULL, & attr) = = NULL) {printf ("[HelloWorld] Falied to create LedTask!\ n");}} SYS_RUN (HelloWorld_Entry)

3. Compilation script BUILD.gn for business code

Path: code\ applications\ sample\ wifi-iot\ app\ hello_world\ BUILD.gn

Static_library ("hello_world_app") {sources = ["hello_world.c"] include_dirs = ["/ / utils/native/lite/include", "/ / kernel/liteos_m/components/cmsis/2.0", "/ / base/iot_hardware/interfaces/kits/wifiiot_lite",]}

4. The compilation script BUILD.gn for the module

Path: code\ applications\ sample\ wifi-iot\ app\ BUILD.gn

Import ("/ / build/lite/config/component/lite_component.gni") lite_component ("app") {features = ["startup", "hello_world:hello_world_app",]}

5. Execution result:

6. Summary

Note that the project path of the business code must be in the code\ applications\ sample\ wifi-iot\ app\ directory, and create a new folder according to the business.

A business, can be understood as a task or a thread, such as OLED liquid crystal display can be used as a separate business, the pipeline lamp can be used as a separate business.

In the follow-up code, simple functions will continue to be added to hello_world services, such as LED water lights, key interrupt lights, and complex functions (such as WIFI,OLED display) will start a new business.

At this point, I believe you have a deeper understanding of "how to use Helloworld and the basic development framework". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report