当前位置:网站首页>FreeRTOS 任务函数里面的死循环
FreeRTOS 任务函数里面的死循环
2022-07-06 09:16:00 【薇远镖局】
任务函数是一个无限循环且不带返回值的函数。
任务必须是死循环,否则任务将经过 LR 返回,如果 LR 指向了非法内存就会产生HardFault_Handler,而 FreeRTOS 指向一个死循环,那么任务返回以后就在死循环中执行,这样子的任务是不安全的。
编程时应避免这种状况,任务通常都是死循环而且无返回值的。
若是单次任务,执行一次以后就进行删除,则不影响系统运行,所以,只执行一次的任务在执行完毕要记得及时删除。即就是在任务结束的时候,加上 vTaskDelete(NULL)
。
循环任务里面的延时函数必须使用 FreeRTOS 里面提供的延时函数,并不能使用咱们裸机编程中的那种延时。这两种延时的区别是 FreeRTOS 里面的延时是阻塞延时,即调用vTaskDelay()函数的时候,当前任务会被挂起,调度器会切换到其它就绪的任务,从而实现多任务。若是仍是使用裸机编程中的那种延时,那么整个任务就成为了一个死循环,若是刚好该任务的优先级是最高的,那么系统永远都是在这个任务中运行,比它优先级更低的任务没法运行,根本没法实现多任务。
当任务进入延时的时候,由于没有另外就绪的用户任务,那么系统就会进入空闲任务,空闲任务是 FreeRTOS 系统本身启动的一个任务,优先级最低。当整个系统都没有就绪任务的时候,系统必须保证有一个任务在运行,空闲任务就是为这个设计的。当用户任务延时到期,又会从空闲任务切换回用户任务。
边栏推荐
- Word排版(小计)
- 分布式事务的实现方案
- Yarn installation and use
- [Flink] cdh/cdp Flink on Yan log configuration
- Double to int precision loss
- [CDH] cdh5.16 configuring the setting of yarn task centralized allocation does not take effect
- 保姆级出题教程
- [NPUCTF2020]ReadlezPHP
- {one week summary} take you into the ocean of JS knowledge
- [BSidesCF_2020]Had_a_bad_day
猜你喜欢
FTP file upload file implementation, regularly scan folders to upload files in the specified format to the server, C language to realize FTP file upload details and code case implementation
Mtcnn face detection
2019 Tencent summer intern formal written examination
电商数据分析--用户行为分析
小L的试卷
FTP文件上传文件实现,定时扫描文件夹上传指定格式文件文件到服务器,C语言实现FTP文件上传详解及代码案例实现
wangeditor富文本引用、表格使用问题
MySQL and C language connection (vs2019 version)
Connexion sans mot de passe du noeud distribué
Redis面试题
随机推荐
机器学习--线性回归(sklearn)
Some concepts often asked in database interview
MongoDB
【yarn】CDP集群 Yarn配置capacity调度器批量分配
常用正则表达式整理
vs2019 第一个MFC应用程序
[NPUCTF2020]ReadlezPHP
Dependency in dependencymanagement cannot be downloaded and red is reported
Mysql的索引实现之B树和B+树
Solution to the practice set of ladder race LV1 (all)
【flink】flink学习
Redis interview questions
MySQL realizes read-write separation
Aborted connection 1055898 to db:
[Bluebridge cup 2021 preliminary] weight weighing
MySQL数据库面试题
MTCNN人脸检测
Encodermappreduce notes
天梯赛练习集题解LV1(all)
encoderMapReduce 随手记