郑重声明,版权所有!

转载需说明。

FREERTOS堆栈大小的单位是word,不是byte.

根据处理器架构优化系统的任务优先级不能超过32,If the architecture optimized method is used then configMAX_PRIORITIES cannot be greater than 32.

vTaskDelay() delay from call the vTaskDelay

vTaskDelayUntil delay from last wake up time

 

It is the responsibility of the idle task to free memory allocated to tasks that have since been deleted.

Ready state tasks of equal priority will enter the Running state in turn.  ‘Round Robin Scheduling’

同一优先级任务实行时间片轮转调度。

A time slice is equal to the time between two RTOS tick interrupts.

时间片值等于TICK时钟值

消息序列让局部变量存放在序列中,函数退出时局部变量仍然在序列中

In practice it is very common for a queue to have multiple writers, but much less common for a queue to have multiple readers.

多个任务等待同一序列:Queues can have multiple readers, so it is possible for a single queue to have more than one task blocked on it waiting for data. When this is the case, only one task will be unblocked when data becomes available. The task that is unblocked will always be the highest priority task that is waiting for data. If the blocked tasks have equal priority, then the task that has been waiting for data the longest will be unblocked.

应该任务等待多个序列:Queues can be grouped into sets, allowing a task to enter the Blocked state to wait for data to become available on any of the queues in the set.

创建序列返回的是序列指针,序列本身由OS内部动态分配在OS的Heap中:The xQueueCreate() API function creates a queue and returns a QueueHandle_t that references the queue it created.

清空序列:xQueueReset() API function can be used to return the queue to its original empty state.

xQueueSendToBack() is used to send data to the back (tail) of a queue xQueueSendToFront() is used to send data to the front (head) of a queue.

xQueueSend() = xQueueSendToBack().

xTicksToWait 是0则立即返回,Both xQueueSendToFront() and xQueueSendToBack() will return immediately if xTicksToWait is zero and the queue is already full.

xTicksToWait 是portMAX_DELAY则一直等待:Setting xTicksToWait to portMAX_DELAY will cause the task to wait indefinitely (without timing out), provided INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h.

请求序列有多少个信息:uxQueueMessagesWaiting() is used to query the number of items that are currently in a queue.

序列传指针注意事项:when queuing pointers, extreme care must be taken to ensure that:

1. The owner of the RAM being pointed to is clearly defined.

2. The RAM being pointed to remains valid.动态分配必须没有被free

序列集:

xQueueAddToSet() adds a queue or semaphore to a queue set

FREERTOS CAN Using a Queue to Create a Mailbox

邮箱是长度为1的序列:In this book the term mailbox is used to refer to a queue that has a length of one

邮箱被读取后并不会被消耗,只会在重新发送时被覆盖:A mailbox is used to hold data that can be read by any task, or any interrupt service routine. The data does not pass through the mailbox, but instead remains in the mailbox until it is overwritten. The sender overwrites the value in the mailbox. The receiver reads the value from the mailbox, but does not remove the value from the mailbox.

邮箱具有广播特性!!!,任务读取后不被覆盖,别的任务依然可以读取,邮箱大小永远是1,只能读到发送的最新的邮件,读消息邮箱每次都会读到,根据时间戳可以判断是不是被更新。

if the queue is already full, then xQueueOverwrite() will overwrite data that is already in the queue.

xQueuePeek() is used to receive (read) an item from a queue without the item being removed from the queue.

参考手册4.7节设计消息邮箱功能。

Software Timer

软件定时器适合的应用场合:

l  事件发生后加一个延迟产生一个动作

l  周期性执行某个函数(任务中系统调用只有delay的任务)

They should be kept short, and must not enter the Blocked state.

会在上下文切换时调用

The xTimerDelete() API function deletes a timer. A timer can be deleted at any time.

All software timer callback functions execute in the context of the same RTOS daemon (or ‘timer service’) task1.

The daemon task is a standard FreeRTOS task that is created automatically when the scheduler is started. Its priority and stack size are set by the configTIMER_TASK_PRIORITY and configTIMER_TASK_STACK_DEPTH compile time configuration constants respectively. Both constants are defined within FreeRTOSConfig.h.

软件定时器回调函数由系统守护进程(定时器服务)调用,在配置里可以配置它的优先级和堆栈大小。

configTIMER_TASK_STACK_DEPTH决定最多由多少个在线软件定时器,为保证软件定时器无阻塞正常执行,执行后不需要的定时器需要删除

xTimerChangePeriod()改变定时器周期

软件定时器可以做超时检测并处理,类似于看门狗,当正常接收时reset定时器,溢出时调用定时器回调函数做超时处理

 

 

任务优先级低于任何硬件的中断优先级,任务无法抢占中断!

Tasks will only run when there are no ISRs running, so the lowest priority interrupt will interrupt the highest priority task, and there is no way for a task to pre-empt an ISR.

任务中函数引起上下文切换立即切换,中断引起的上下文切换在中断退出后开始切换(中断优先级高于内核调度)

中断中如需进行上下文切换需调用portYIELD_FROM_ISR()如不调用,则中断引起的上下文切换会在下一次上下文切换时发生(最晚在ostick中断中发生)

中断尽量短,中断把工作延迟给任务有以下优点:

最高优先级任务优先级比中断低,中断过长阻塞高优先级任务

中断是随机的,影响任务执行的连续性

中断中有新中断产生优先级比当前中断低则会被延迟

中断嵌套会增加调度复杂性,中断短之后嵌套概率变小

短时间可以执行完的在中断内执行,否则延迟到任务执行

二进制信号量和互斥信号量的区别:

二进制信号量进程本身获得之后不需要再给出,而互斥信号量必须是谁获得谁给出。

二进制信号量只借不还,互斥信号量有借有还!

互斥信号量不同于二进制信号量的是互斥信号量有优先级继承特性(防止优先级反转)

二进制信号量与计数信号量

慢速信号或单次信号可以通过二进制信号量进行同步,连续快速随机信号可以通过计数信号量缓存,保证信号不被丢失,计数值表示产生的信号数与已经处理的信号数之差,如果计数信号量一直处于满的状态说明信号处理程序过慢不能达到要求

同时计数信号量还可以用于有限个资源管理,进程需要资源时获取信号量,使用完资源后释放信号量。

低时间延迟要求的事件可以通过xTimerPendFunctionCallFromISR()直接调用守护进程执行事件处理函数,减少单独处理任务,简化设计。

中断产生消息序列不太可取(这样使用操作系统API速度会变慢速度慢),最好用DMA或者环形缓冲区

中断逻辑优先级高于configMAX_SYSCALL_INTERRUPT_PRIORITY不会被FREERTOS临界段屏蔽,小于等于的的会被屏蔽

只有逻辑优先级小于等于configMAX_SYSCALL_INTERRUPT_PRIORITY的中断可以调用OS的API

Typically, functionality that requires very strict timing accuracy (motor control, for example) would use a priority above configMAX_SYSCALL_INTERRUPT_PRIORITY to ensure the scheduler does not introduce jitter into the interrupt response time.

If a function does not access any data other than data stored on the stack or held in a

register, then the function is reentrant, and thread safe

尽量减少任务共享资源,所有任务共享资源需要保护。

进出临界段只会屏蔽优先级低于configMAX_SYSCALL_INTERRUPT_PRIORITY的中断

taskENTER_CRITICAL()

taskEXIT_CRITICAL(),

Basic critical sections must be kept very short, otherwise they will adversely affect interrupt response times. 临界段要短!

挂起和解挂调度(未关闭中断)

vTaskSuspendAll()

xTaskResumeAll()

最好把使用互斥信号量的功能写成函数,保证“有借有还”,成对使用。

it is normally bad practice for a task to wait indefinitely (without a time out) to obtain a mutex.没用TIMEOUT的等待可能导致死锁

递归互斥信号量可以被同一任务连续多次请求,然后多次释放。

vApplicationTickHook()中的OS函数必须用FromISR()形式,因为tick函数是再tick中断中调用的。

Gatekeeper Tasks(守门员任务):此任务用来替代互斥信号量,避免出现优先级反转或死锁的情况,此任务由用户自己设计,所有任务中只有此任务可以访问共享资源,此任务轮询等待一个消息,得到消息后此任务开始对共享资源进行访问,之后继续挂起等待消息。需要访问共享资源的任务想此任务发送消息,之后此由任务进行共享资源访问。

事件标志组可以用于多个任务同步,具有广播特性。

 

事件标志组可以让一个任务等待多个事件,或者让一个任务等待多个事件之一;

 

事件标志组可以让多个任务等待多个事件,或者让多个任务等待多个事件之一;

 

等待事件标志组函数的参数可以配置函数调用后是否清除uxBitsToWaitFor对应事件位

 

可以单独通过函数xEventGroupClearBits()清除事件标志位

事件标志组进行多任务同步(多个任务同时等待多个事件,期望同时进入就绪态)需要使用xEventGroupSync()进行同步,直接使用事件标志组挂起函数会导致调度不能同步。

 

Task Notifications

更加快速通知任务,更节省RAM空间。

针对单个任务的通知,中断不能接收通知,但中断可以发出通知

非缓存,非广播。

task’s notification类似于一个针对任务的计数信号量,give让任务通知加一,take收到并让通知减一或清零。

xTaskNotify()可以看作是轻量级的二进制信号量,计数信号量,事件标志组,甚至是通知任务的消息邮箱。

调试手段

ConfigASSERT()

FREERTOS+Trace

DEBUG HOOK

Viewing run-time and task state information (statistics)

常见问题:

调用操作系统API的中断优先级必须小于等于configMAX_SYSCALL_INTERRUPT_PRIORITY

Cortex-m内核处理器确保所有的中断优先级都分配非抢占优先级,不要子优先级;

堆栈溢出问题:

uxTaskGetStackHighWaterMark() 获取任务再整个系统运行过程中堆栈的最小剩余值

 

设置configCHECK_FOR_STACK_OVERFLOW为1或2

重写函数vApplicationStackOverflowHook(),这个函数再上下文切换中断中调用,其入口参数是任务句柄和任务名

针对嵌入式系统改进(重写)printf()函数

Printf-stdarg.c是个不错的选择,其中的sprintf是一个最小实现,其中的printf是相对慢的,占用较大堆栈的,直接输出的。

 

如果系统堆栈不足导致vTaskStartScheduler()失败,vTaskStartScheduler()会返回Including a null loop [ for(;;); ] after the call to vTaskStartScheduler() can make this error easier to debug.

FREERTOS 手册阅读笔记的更多相关文章

  1. 阿里巴巴java开发手册阅读笔记

    1. long 或者 Long 初始赋值时,必须使用大写的 L. Long a = 2L; 2. POJO 类(DO/DTO/BO/VO )必须写 toString 方法 3. final 可提高程序 ...

  2. CI框架源码阅读笔记4 引导文件CodeIgniter.php

    到了这里,终于进入CI框架的核心了.既然是“引导”文件,那么就是对用户的请求.参数等做相应的导向,让用户请求和数据流按照正确的线路各就各位.例如,用户的请求url: http://you.host.c ...

  3. CI框架源码阅读笔记3 全局函数Common.php

    从本篇开始,将深入CI框架的内部,一步步去探索这个框架的实现.结构和设计. Common.php文件定义了一系列的全局函数(一般来说,全局函数具有最高的加载优先权,因此大多数的框架中BootStrap ...

  4. Mongodb Manual阅读笔记:CH7 索引

    7索引 Mongodb Manual阅读笔记:CH2 Mongodb CRUD 操作Mongodb Manual阅读笔记:CH3 数据模型(Data Models)Mongodb Manual阅读笔记 ...

  5. Mongodb Manual阅读笔记:CH6 聚合

    6 聚合 Mongodb Manual阅读笔记:CH2 Mongodb CRUD 操作Mongodb Manual阅读笔记:CH3 数据模型(Data Models)Mongodb Manual阅读笔 ...

  6. Mongodb源代码阅读笔记:Journal机制

    Mongodb源代码阅读笔记:Journal机制 Mongodb源代码阅读笔记:Journal机制 涉及的文件 一些说明 PREPLOGBUFFER WRITETOJOURNAL WRITETODAT ...

  7. Mongodb Manual阅读笔记:CH5 安全性

    5 安全性 Mongodb Manual阅读笔记:CH2 Mongodb CRUD 操作Mongodb Manual阅读笔记:CH3 数据模型(Data Models)Mongodb Manual阅读 ...

  8. Mongodb Manual阅读笔记:CH4 管理

    4 管理 Mongodb Manual阅读笔记:CH2 Mongodb CRUD 操作Mongodb Manual阅读笔记:CH3 数据模型(Data Models)Mongodb Manual阅读笔 ...

  9. Mongodb Manual阅读笔记:CH2 Mongodb CRUD 操作

    2 Mongodb CRUD 操作 Mongodb Manual阅读笔记:CH2 Mongodb CRUD 操作Mongodb Manual阅读笔记:CH3 数据模型(Data Models)Mong ...

随机推荐

  1. 【.net 深呼吸】细说CodeDom(6):方法参数

    本文老周就给大伙伴们介绍一下方法参数代码的生成. 在开始之前,先补充一下上一篇烂文的内容.在上一篇文章中,老周检讨了 MemberAttributes 枚举的用法,老周此前误以为该枚举不能进行按位操作 ...

  2. node-webkit 环境搭建与基础demo

    首先去github上面下载(地址),具体更具自己的系统,我的是windows,这里只给出windows的做法 下载windows x64版本 下载之后解压,得到以下东西 为了方便,我们直接在这个目录中 ...

  3. NodeJs在Linux下使用的各种问题

    环境:ubuntu16.04 ubuntu中安装NodeJs 通过apt-get命令安装后发现只能使用nodejs,而没有node命令 如果想避免这种情况请看下面连接的这种安装方式: 拓展见:Linu ...

  4. 【疯狂造轮子-iOS】JSON转Model系列之一

    [疯狂造轮子-iOS]JSON转Model系列之一 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 之前一直看别人的源码,虽然对自己提升比较大,但毕竟不是自己写的,很容易遗 ...

  5. 告别被拒,如何提升iOS审核通过率(上篇)

    iOS审核一直是每款移动产品上架苹果商店时面对的一座大山,每次提审都像是一次漫长而又悲壮的旅行,经常被苹果拒之门外,无比煎熬.那么问题来了,我们有没有什么办法准确把握苹果审核准则,从而提升审核的通过率 ...

  6. ASP.NET Core HTTP 管道中的那些事儿

    前言 马上2016年就要过去了,时间可是真快啊. 上次写完 Identity 系列之后,反响还不错,所以本来打算写一个 ASP.NET Core 中间件系列的,但是中间遇到了很多事情.首先是 NPOI ...

  7. ASP.NET Aries 入门开发教程8:树型列表及自定义右键菜单

    前言: 前面几篇重点都在讲普通列表的相关操作. 本篇主要讲树型列表的操作. 框架在设计时,已经把树型列表和普通列表全面统一了操作,用法几乎是一致的. 下面介绍一些差距化的内容: 1:树型列表绑定: v ...

  8. WebApi - 路由

    这段时间的博客打算和大家一起分享下webapi的使用和心得,主要原因是群里面有朋友说希望能有这方面的文章分享,随便自己也再回顾下:后面将会和大家分不同篇章来分享交流心得,希望各位多多扫码支持和点赞,谢 ...

  9. python学习笔记(python介绍)

    为什么要学python? python和shell的比较,和PHP.和JAVA比较 运维开发只是用到python的很小一部分 python在一些知名公司的应用: 谷歌:python的创始人原来在谷歌工 ...

  10. 练习JavaScript判断上传文件后缀名

    <script type = text/javascript> function jiance(filename) { var pic = ["jpg","p ...