当前位置:网站首页>ESP32_ FreeRTOS_ Arduino_ 1_ Create task
ESP32_ FreeRTOS_ Arduino_ 1_ Create task
2022-07-06 03:48:00 【Colorful 2022】
ESP32_FreeRTOS_Arduino_1_ Create tasks
About FreeRTOS stay arduino Applications in the environment
One 、 About FreeRTOS
1、 What is? FreeRTOS
FreeRTOS It is a real-time operating system running on a microcontroller , Can effectively manage tasks , Allocate hardware resources reasonably .
for instance , When we are using Windows perhaps Linux when , You can open multiple processes and Applications , It seems to be running at the same time . But for single core computers , Only one process can be executed at a time . So the computer actually switches between multiple tasks very quickly , So that users feel that everything is running at the same time .
The operating system provides us with a reasonable task scheduler mechanism , And manage the resources needed for these tasks , To ensure that each thread can be executed correctly , And meet its resource needs .
Here we have a new concept . Task scheduling mechanism , Don't look at the scheduling mechanism first , Let's look at the task first .
2、 What is a mission
Task is the basic module of real-time operating system , They execute in their own context ( This part of the concept , If necessary, please refer to some of my articles on the operating system ).
PS: Task switching involves context switching , In the multithreading section of my operating system column, I touch on .
And the scheduling mechanism , Is responsible for the decision CPU Which task should be performed at a certain time . If multiple tasks are executed concurrently , If there is no scheduling mechanism , It will be very bad, very bad , Here are specific examples .
3、 Suggest
Knowledge of the operating system , I will make a special summary , Those who need it can learn , It is suggested that beginners learn , It can be downloaded from Arduino Of FreeRTOS Learn and experience first , Then go to learn the concept of operating system systematically .
Two 、 establish FreeRTOS Mission
Let's start with Arduino in FreeRTOS Simple application of , In this example, we will first create two prints "hello world" Message task , Then delete them .
1、xTaskCreate Task creation function
API Parameters
- pvTaskCode
- A function pointer , Used to pass the function responsible for task implementation
- pcName
- The name of the task
- usStackDepth
- Task stack size , In bytes , Usually a large enough value will be used
- pvParameters
- The pointer , Point to the parameters received by the task function , The type must be (void *)
- uxPriority
- Task priority
- TaskHandle_t
- Returns a handle , It is used for the reference to the task when calling the function in the future
#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
static inline IRAM_ATTR BaseType_t xTaskCreate(
TaskFunction_t pvTaskCode,
const char * const pcName,
const uint32_t usStackDepth,
void * const pvParameters,
UBaseType_t uxPriority,
TaskHandle_t * const pvCreatedTask)
{
return xTaskCreatePinnedToCore( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pvCreatedTask, tskNO_AFFINITY );
}
#endif
2、setup function and Loop code
Serial port settings
First of all we need to Setup Function , Open a serial connection , Used to output the running results of the test program .
Serial.begin(115200);
delay(1000);
Create a task example
#include<Arduino.h>
#include<FreeRTOS.h>
void taskOne( void * parameter )
{
for( int i = 0;i<10;i++ ){
Serial.println("Hello from task 1");
delay(1000);
}
Serial.println("Ending task 1");
vTaskDelete( NULL );
}
void taskTwo( void * parameter)
{
for( int i = 0;i<10;i++ ){
Serial.println("Hello from task 2");
delay(1000);
}
Serial.println("Ending task 2");
vTaskDelete( NULL );
}
void setup() {
Serial.begin(112500);
delay(1000);
xTaskCreate(
taskOne, /* Task function. */
"TaskOne", /* String with name of task. */
10000, /* Stack size in bytes. */
NULL, /* Parameter passed as input of the task */
1, /* Priority of the task. */
NULL); /* Task handle. */
xTaskCreate(
taskTwo, /* Task function. */
"TaskTwo", /* String with name of task. */
10000, /* Stack size in bytes. */
NULL, /* Parameter passed as input of the task */
1, /* Priority of the task. */
NULL); /* Task handle. */
}
void loop() {
delay(1000);
}
Program execution result

边栏推荐
- three. JS page background animation liquid JS special effect
- [practice] mathematics in lottery
- Brush questions in summer -day3
- [slam] lidar camera external parameter calibration (Hong Kong University marslab) does not need a QR code calibration board
- LTE CSFB test analysis
- Oracle ORA error message
- 1. New project
- KS003基于JSP和Servlet实现的商城系统
- [001] [stm32] how to download STM32 original factory data
- RT-Thread--Lwip之FTP(2)
猜你喜欢

Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art

Recommended papers on remote sensing image super-resolution

WPF效果第一百九十一篇之框选ListBox

Python implementation of maddpg - (1) openai maddpg environment configuration

After five years of testing in byte, I was ruthlessly dismissed in July, hoping to wake up my brother who was paddling

Custom event of C (31)

给新人工程师组员的建议

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

RT-Thread--Lwip之FTP(2)

mysql关于自增长增长问题
随机推荐
On Data Mining
SWC introduction
Mapping between QoE and KQI
JS Vanke banner rotation chart JS special effect
[Qt5] QT QWidget immediately appears and disappears
Pytoch foundation - (1) initialization of tensors
潘多拉 IOT 开发板学习(HAL 库)—— 实验9 PWM输出实验(学习笔记)
Custom event of C (31)
C#(三十)之C#comboBox ListView treeView
Codeforces Global Round 19
User perceived monitoring experience
RT thread -- FTP of LwIP (2)
Pytorch load data
【Rust 笔记】18-宏
C#(二十八)之C#鼠标事件、键盘事件
Edcircles: a real time circle detector with a false detection control translation
Esbuild & SWC: a new generation of construction tools
简易博客系统
简述C语言中的符号和链接库
Flask learning and project practice 9: WTF form verification