当前位置:网站首页>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
边栏推荐
- 【按键消抖】基于FPGA的按键消抖模块开发
- Cross origin cross domain request
- Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
- MySQL reads missing data from a table in a continuous period of time
- 登录mysql输入密码时报错,ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO/YES
- On Data Mining
- Svg drag point crop image JS effect
- [rust notes] 18 macro
- 2.2 STM32 GPIO操作
- Image super resolution using deep revolutionary networks (srcnn) interpretation and Implementation
猜你喜欢
Recommended papers on remote sensing image super-resolution
2.2 fonctionnement stm32 GPIO
Cubemx 移植正点原子LCD显示例程
Serial port-rs232-rs485-ttl
[practice] mathematics in lottery
登录mysql输入密码时报错,ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO/YES
在 .NET 6 中使用 Startup.cs 更简洁的方法
Align items and align content in flex layout
Brush questions in summer -day3
BUAA计算器(表达式计算-表达式树实现)
随机推荐
Ybtoj coloring plan [tree chain dissection, segment tree, tarjan]
Pytoch foundation - (1) initialization of tensors
[optimization model] Monte Carlo method of optimization calculation
Alibaba testers use UI automated testing to achieve element positioning
Overview of super-resolution reconstruction of remote sensing images
BUAA计算器(表达式计算-表达式树实现)
Serial port-rs232-rs485-ttl
MySQL reads missing data from a table in a continuous period of time
MySQL about self growth
3.1 rtthread 串口设备(V1)详解
Prime protocol announces cross chain interconnection applications on moonbeam
JS Vanke banner rotation chart JS special effect
An article will give you a comprehensive understanding of the internal and external components of "computer"
Pytorch基础——(1)张量(tensor)的初始化
Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
Deno介绍
3.1 detailed explanation of rtthread serial port device (V1)
Prime Protocol宣布在Moonbeam上的跨链互连应用程序
three. JS page background animation liquid JS special effect
mysql从一个连续时间段的表中读取缺少数据