Abstract: ** This paper introduces how to transplant the sensor in LiteOS based on the little Bear development board, so as to achieve the relevant control of the sensor.
1 hello world
This article will introduce how to implement the sensor migration from hello_world_demo.
First we create the HelloWorld project, choose STM32_BearPi → hello_world_demo, the project name can be customized.
After creation, we click compile, then burn to the development board, open the serial port of VScode-IotLink, and set the serial port connection parameters according to the picture. After pressing Reset, we can see the serial port printing as shown in the picture below.
The LiteOS startup process was introduced in LiteOS series before. We know that after the program is downloaded to the development board, the development board will be started by pressing the Reset button. So the first function executed after the development board is powered on is the ReSet_Handler function.
Los_startup. S is a startup file written in assembly language. The startup process is described in LiteOS. The program will then start executing from the main function.
Next, look at the main function. In the main function, we initialize the hardware, initialize the kernel, then initialize the serial port, and then link_test(), where we create a task whose entry function is Link_main.
Link_main calls standard_app_demo_main() at the end of the Link_main function. According to the IDE search, we can see that there are a number of functions with the same name in the project, so how does the compiler know which one to execute? You can see that the user_demo macro definition in the.config file enables hello_world_demo, so the standard_app_demo_main() function in hello_world_demo is executed, According to the task created internally and the entry function, it can print Hello World! This is BearPi! . Next we move on to sensor porting.
2 Sensor transplantation
First of all, we can see that a large number of sensor codes have 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. Including pins and GPIO binding and so on.
First you need to add the sensor file path to the compile path so that the compiler can find the code, configure the sensor file path in userdemo.mk, and add the file path in the hello_world_demo section of that file. Then add custom variables user_sensor_src and user_hardware_inc to the source and header variables, as shown in Figure 83-84. Of course, if you define the names of user_hardware_src and user_hardware_inc that already exist in the compile path, you don’t need to add any code.
First we need to add the sensor header file to helloworld_demo.c for subsequent function calls.
#include "E53_SC1.h"
Copy the code
The structure is then called so that the data can be printed later.
E53_SC1_Data_TypeDef E53_SC1_Data;
Copy the code
Then in the hello_world_demo.c file, add the task function for the sensor data.
static int app_sensor_entry()
{
Init_E53_SC1();
while (1)
{
E53_SC1_Read_Data();
printf("luminance:%dn", (int)E53_SC1_Data.Lux);
osal_task_sleep(2*1000);
}
return 0;
}
Copy the code
Create the sensor task function in the main function.
osal_task_create("app_sensor_entry", app_sensor_entry, NULL, 0x400,NULL,2);
osal_task_sleep(2*1000);
Copy the code
The details are shown below.
Then we compile and burn, through the serial port to verify whether the transplant of the sensor is correct.
Click to follow, the first time to learn about Huawei cloud fresh technology ~