freeRTOS学习一
freeRTOS中的链表结构:
/*
* Definition of the only type of object that a list can contain. 链表中的节点
*/
struct xLIST_ITEM
{
listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
configLIST_VOLATILE TickType_t xItemValue; /*< The value being listed. In most cases this is used to sort the list in descending order. */
struct xLIST_ITEM * configLIST_VOLATILE pxNext; /*< Pointer to the next ListItem_t in the list. */
struct xLIST_ITEM * configLIST_VOLATILE pxPrevious; /*< Pointer to the previous ListItem_t in the list. */
void * pvOwner; /*< Pointer to the object (normally a TCB) that contains the list item.
There is therefore a two way link between the object containing the list item and the list item itself.
指向该节点的拥有者 及内嵌在哪个数据结构中
*/
void * configLIST_VOLATILE pvContainer; /*< Pointer to the list in which this list item is placed (if any).通常指向链表的根节点 */
listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
};
typedef struct xLIST_ITEM ListItem_t; /* For some reason lint wants this as two separate definitions. */
/*
* Definition of the type of queue used by the scheduler. 链表
*/
typedef struct xLIST
{
listFIRST_LIST_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
configLIST_VOLATILE UBaseType_t uxNumberOfItems; 链表节点计数器
ListItem_t * configLIST_VOLATILE pxIndex; /*< Used to walk through the list. Points to the last item returned by a call to listGET_OWNER_OF_NEXT_ENTRY ().链表节点索引指针 */
MiniListItem_t xListEnd; /*< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */
listSECOND_LIST_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
} List_t;
struct xMINI_LIST_ITEM 链表的最后一个节点或者说是第一个节点 一个marker
{
listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
configLIST_VOLATILE TickType_t xItemValue;
struct xLIST_ITEM * configLIST_VOLATILE pxNext;
struct xLIST_ITEM * configLIST_VOLATILE pxPrevious;
};
typedef struct xMINI_LIST_ITEM MiniListItem_t;
对链表的插入删除操作可参见源码中的list.c。
任务的定义与切换:
main()函数里面顺序执行的无限循环,在这个循环中,CPU按照顺序完成各种操作。
多任务系统中,根据功能的不同,把整个系统分割成一个个独立的且无法返回的函数,这种函数就被称为任务。
多任务系统中,每个任务都是独立的、互不干扰的,所以要为每个任务分配独立的栈空间,这个栈空间通常是一个预先定义好的全局数组。也可以是动态分配的一段内存空间。
TCB任务控制块,相当于人物的身份证,里面存有任务的所有信息。以后对任务的全部操作都可以通过任务控制块来实现。
/*
* Task control block. A task control block (TCB) is allocated for each task,
* and stores task state information, including a pointer to the task's context
* (the task's run time environment, including register values)
*/
typedef struct tskTaskControlBlock
{
volatile StackType_t *pxTopOfStack; /*< Points to the location of the last item placed on the tasks stack. THIS MUST BE THE FIRST MEMBER OF THE TCB STRUCT. */栈顶 ListItem_t xStateListItem; /*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */ 任务节点
ListItem_t xEventListItem; /*< Used to reference a task from an event list. */
UBaseType_t uxPriority; /*< The priority of the task. 0 is the lowest priority. */
StackType_t *pxStack; /*< Points to the start of the stack. */ 任务栈起始地址
char pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created. Facilitates debugging only. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ } tskTCB; /* The old tskTCB name is maintained above then typedefed to the new TCB_t name
below to enable the use of older kernel aware debuggers. */
typedef tskTCB TCB_t;
任务创建函数,静态创建(PCB和栈的内存需要预先定义好,任务删除时,内存不能释放),动态创建(创建任务时动态分配,任务删除,可以释放)。
TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode, //函数入口
const char * const pcName, //任务名称
const uint32_t ulStackDepth, //任务栈大小
void * const pvParameters, //任务形参
UBaseType_t uxPriority,
StackType_t * const puxStackBuffer, //任务栈起始地址
StaticTask_t * const pxTaskBuffer ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ 任务控制块地址
定义就绪列表,任务创建好,需要把任务添加到就绪列表中,表示任务已经就绪,系统随时可以调度。就绪列表实际上就是一个List_t类型的数组。数组的下标对应任务的优先级,同一优先级的任务插入就绪队列中的同一条链表中。
将任务插入就序列表,TCB里面有一个xStateListItem成员,我们将任务插入就序列表中,就是通过将TCB中的该节点插入就序列表来实现的。
实现调度器,主要功能就是实现任务的切换,即从就序列表里面找到优先级最高的任务执行,
vTaskStartScheduler()
/*
启动FreeRTOS调度程序运行。
通常,在调度程序启动之前,将执行main()(或main()调用的函数)。 启动调度程序后,只会执行任务和中断。
启动调度程序会导致在调度程序处于“初始化”状态时创建的优先级最高的任务进入“运行”状态。
*/
freeRTOS学习一的更多相关文章
- 【FreeRTOS学习05】深度解剖FreeRTOSConfig.h实现对系统的自定义剪裁
ROM/RAM太小,因此要对系统进行剪裁: 相关文章 [FreeRTOS实战汇总]小白博主的RTOS学习实战快速进阶之路(持续更新) 文章目录 相关文章 1 系统的剪裁 2 FreeRTOSConfi ...
- FreeRTOS学习及移植笔记之一:开始FreeRTOS之旅
1.必要的准备工作 工欲善其事,必先利其器,在开始学习和移植之前,相应的准备工作必不可少.所以在开始我们写要准备如下: 测试环境:我准备在STM32F103平台上移植和测试FreeRTOS系统 准备F ...
- FreeRTOS学习笔记——任务间使用队列同步数据
1.前言 在嵌入式操作系统中队列是任务间数据交换的常用手段,队列是生产者消费者模型的重要组成部分.FreeRTOS的队列简单易用,下面结合一个具体例子说明FreeRTOS中的队列如何使用. 2.参考代 ...
- FREERTOS学习笔记
2012-02-25 21:43:40 为提升自己对实时操作系统(RTOS)的认识,我学习了freeRTOS. 理解了OS任务的状态.优先级的概念.信号量的概念.互斥的概念.队列.内存管理.这都是和R ...
- 020 - FreeRTOS学习路线总结
零.为什么写? 在H7-tools预售群里,有位朋友提出如何学习FreeRTOS这类的问题,便由此总结下自己的学习路线.最近又打算接触RTT,和FreeRTOS做个对比. 文章分两步来讲,学习路线和学 ...
- 【FreeRTOS学习06】深度解剖中断与任务之间同步的具体使用场景
嵌入式系统中中断是必不可少的一部分: [FreeRTOS实战汇总]小白博主的RTOS学习实战快速进阶之路(持续更新) 文章目录 1 前言 2 中断特点 3 延迟中断处理 3.1 信号量的使用 3.2 ...
- 【FreeRTOS学习04】小白都能懂的 Queue Management 消息队列使用详解
消息队列作为任务间同步扮演着必不可少的角色: 相关文章 [FreeRTOS实战汇总]小白博主的RTOS学习实战快速进阶之路(持续更新) 文章目录 相关文章 1 前言 2 xQUEUE 3 相关概念 3 ...
- 【FreeRTOS学习02】源码结构/数据类型/命名规则总结
个人不是很喜欢FreeRTOS的编程风格,但是没办法,白嫖人家的东西,只能忍了,这里先简单总结一下: 相关文章 [FreeRTOS实战汇总]小白博主的RTOS学习实战快速进阶之路(持续更新) 文章目录 ...
- 【FreeRTOS学习03】小白都能懂的Task Management 任务管理基本概念介绍
在FreeRTOS中,线程的术语又可以被称之为任务,或许这样更加合适,本文将介绍任务的创建/删除,任务参数的使用,以及任务优先级: 1 软实时和硬实时 硬实时系统的任务运行正确性与响应时限是紧密相关的 ...
- 【FreeRTOS学习01】CubeIDE快速整合FreeRTOS创建第一个任务
整个专栏主要是博主结合自身对FreeRTOS的实战学习以及源码分析,基于STM32F767 Nucleo-144平台,在CubeIDE下进行开发,结合官方的HAL库,将硬件环节的问题减少到最小,将精力 ...
随机推荐
- Windows 7 [Web应用程序项目***已配置为使用IIS。无法访问IIS元数据库,您没有足够的特权访问计算机上的IIS网站]
如下所示,我最近也遇到这个类似的错误(Win7 + IIS7.0),最后如下图解决 系统用户权限问题, 通过管理员运行 即可正常使用.
- [Cypress] Find Unstubbed Cypress Requests with Force 404
Requests that aren't stubbed will hit our real backend. To ensure we've stubbed all our routes, we c ...
- 题解 [51nod1201] 整数划分
题面 解析 首先,因为是不同的数字, 可以从小到大依次枚举加上每一个数字的贡献,再枚举每个数. 然而这样会T掉... 考虑到\(n\)只有\(50000\), 当分成的数最多时,设最大的数为\(m\) ...
- winform中的Windows Media Player播放器设置
namespace WindowsMediaPlayer{ public partial class Form1 : Form { Form2 form2;//声明from2窗体 public For ...
- C++头文件中#pragma once与#ifndef……#define……#endif
两者功能一样,防止重复包含被多次编译.建议头文件加入#pragma once C++头文件开头的两句与结尾的一句#ifndef <标识>#define <标识>类代码#endi ...
- PHP mysqli_fetch_field() 函数
返回结果集中下一字段(列),然后输出每个字段名称.表格和最大长度: <?php // 假定数据库用户名:root,密码:123456,数据库:RUNOOB $con=mysqli_connect ...
- SQL Server 基础:朝花夕拾
序言 INSERT INTO SELECT 与 SELECT INTO 通俗来讲,INSERT INTO SELECT 和 SELECT INTO 两个语句的作用都是复制表,因为都是从一个表中查询出数 ...
- Call JMS Web Service
The content type application/json of the response message does not match the content type of the bin ...
- javascript JSON.parse and JSON.stringify
var jstu = '{"name": "xiaoqiang", "age": 18}'; console.log(jstu); var ...
- python录音程序
# -*- coding: utf-8 -*- # @Time : 18-10-16 下午12:20 # @Author : Felix Wang import pyaudio import nump ...