当前位置:网站首页>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
边栏推荐
- [matlab] - draw a five-star red flag
- Image super-resolution using deep convolutional networks(SRCNN)解读与实现
- RT thread -- FTP of LwIP (2)
- After five years of testing in byte, I was ruthlessly dismissed in July, hoping to wake up my brother who was paddling
- ESBuild & SWC浅谈: 新一代构建工具
- KS008基于SSM的新闻发布系统
- 如何修改表中的字段约束条件(类型,default, null等)
- C language -- structs, unions, enumerations, and custom types
- MySQL reads missing data from a table in a continuous period of time
- UDP reliable transport protocol (quic)
猜你喜欢
C#(二十八)之C#鼠标事件、键盘事件
Multi project programming minimalist use case
Python implementation of maddpg - (1) openai maddpg environment configuration
2.2 STM32 GPIO操作
遥感图像超分辨率论文推荐
C#(二十七)之C#窗体应用
BUAA计算器(表达式计算-表达式树实现)
After five years of testing in byte, I was ruthlessly dismissed in July, hoping to wake up my brother who was paddling
How to standardize the deployment of automated testing?
Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
随机推荐
3.1 detailed explanation of rtthread serial port device (V1)
Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
three. JS page background animation liquid JS special effect
Take you to wechat applet development in 3 minutes
Pytorch基础——(1)张量(tensor)的初始化
WPF效果第一百九十一篇之框选ListBox
【FPGA教程案例12】基于vivado核的复数乘法器设计与实现
User experience index system
施努卡:3d视觉检测应用行业 机器视觉3d检测
The solution of permission denied (750 permissions should be used with caution)
2.2 STM32 GPIO操作
Blue Bridge Cup - Castle formula
Introduction to DeNO
MySQL 中的数据类型介绍
Simple blog system
[American competition] mathematical terms
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 -- FTP of LwIP (2)
简易博客系统
No qualifying bean of type ‘......‘ available