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 migrate sensors in LiteOS

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Today, I will talk to you about how to transplant sensors in LiteOS. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

1 hello world

I believe that whether you are learning the programming language at the beginning of the first function should be HelloWorld, the editor will introduce how to achieve the transplant of the sensor from hello_world_demo.

First, we create a HelloWorld project and select STM32_BearPi → hello_world_demo. The project name can be customized.

After creation, we click compile, and then burn to the development board, open the serial port of VSCode-IoTLink, and set the serial connection parameters according to the figure, then press Reset, you can see the serial port print as shown in the following figure.

First of all, let's introduce the simple process of running the code. We have introduced the startup process of LiteOS in the LiteOS series before. We know that after the program is downloaded to the development board, we will first press the Reset button to start the development board, so the first function to be executed after the development board is powered on is the ReSet_Handler function.

First of all, find the corresponding startup file los_startup.S file (according to the operating system used and the board MCU series to find the file directory), you can see that it is written by assembly language, the specific startup process has been introduced in the rambling LiteOS series, here only look at the low 91 lines, run to the main function, and then the program will be executed from the main function.

Next look at the main function, in the main function, from hardware initialization to kernel initialization, and then initialize the serial port, and then to the link_test () function, in which a task is created, and its entry function is the Link_main function.

At the end of the Link_main function, a function is called standard_app_demo_main (). According to the IDE search, we can see that there are a large number of functions with the same name in the project, so how does the compiler know which one is executed? you can see that the user_demo macro definition in the .config file enables hello_world_demo, so it executes the standard_app_demo_main () function in hello_world_demo. Thus according to its internal creation of the task and the entry function to achieve a print Hello World! This is BearPi! . Next, we transplant the sensors.

2 Transplantation of sensors

First of all, we can see that a lot of sensor code has been included in the LiteOS code. Here we take E53_SC1 as an example. Of course, these sensors have been adapted to the BearPi development board. If you want to use your own specific sensor, you can first transplant the sensor with the development board, including pins and GPIO binding and so on.

First of all, you need to add the sensor file path to the compilation path so that the compiler can find the code, configure the relevant path of the sensor file in userdemo.mk, and find the hello_world_demo part of the file to add the file path in this file. Line 83-84 below, and then add custom variables, user_sensor_src and user_hardware_inc, to the source and header file variables, but here you don't need to add related code if you directly define the names as user_hardware_src and user_hardware_inc that already exist in the compilation path.

First of all, we need to add the sensor header file to helloworld_demo.c to implement the later related function calls.

# include "E53_SC1.h"

The structure is then called so that the data can be printed later.

E53_SC1_Data_TypeDef E53_SC1_Data

Then in the hello_world_demo.c file, add the task function of the sensor data.

Static int app_sensor_entry () {Init_E53_SC1 (); while (1) {E53_SC1_Read_Data (); printf ("luminance:%d\ n", (int) E53_SC1_Data.Lux); osal_task_sleep (2x1000);} return 0;}

Create a sensor task function in the main function.

Osal_task_create ("app_sensor_entry", app_sensor_entry, NULL, 0x400, null, 2); osal_task_sleep (2, 000)

The details are as follows

After that, we compile and burn, and verify whether the transplant of the sensor is correct through the serial port.

After reading the above, do you have any further understanding of how to transplant sensors in LiteOS? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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

Servers

Wechat

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

12
Report