nrf51822代码阅读笔记二

Scheduler

51822的调度,先建个目录,后续在补详细的源码分析,主要是参考官方的库函数说明,可以说是大概的翻译吧,原文的链接地址如下:
https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v13.0.0%2Fgroup__app__scheduler.html

调度器的使用目的

nrf的官方给的说明文档中说,调度器是为了让程序有中断切换到正式运行的程序中。主要是用于软timer实现的中断,对于硬中断,包含IO口的中断,可以在初始化的时候选择是否启用调度器。

调度的初始化

uint32_t app_sched_init (   uint16_t max_event_size,uint16_t    queue_size,void *   p_evt_buffer )  

官方的库中给了调度初始化的函数。必须在进入主函数之前调用初始化函数,才能启动调度器。

max_event_size

max_event_size 指定了最大的事件大小。

queue_size

queue_size 指定了调度队列中最大的数目。

p_evt_buffer

p_evt_buffer指向用于存放调度程序队列的内存缓冲区的指针。 它必须使用APP_SCHED_BUFFER_SIZE()宏进行标注。 缓冲区必须与4字节的边界对齐。

APP_SCHED_INIT

其建议使用宏 APP_SCHED_INIT 来进行初始化,可以保证分配到调度的缓冲区,并且可以4字节对齐。
下面是APP_SCHED_INIT的实现:

do                                                                                             \
    {                                                                                              \
        static uint32_t APP_SCHED_BUF[CEIL_DIV(APP_SCHED_BUF_SIZE((EVENT_SIZE), (QUEUE_SIZE)),     \
                                               sizeof(uint32_t))];                                 \
        uint32_t ERR_CODE = app_sched_init((EVENT_SIZE), (QUEUE_SIZE), APP_SCHED_BUF);             \
        APP_ERROR_CHECK(ERR_CODE);                                                                 \
    } while (0)

上一篇文章解析了CEIL_DIV函数,其可以保证4字节对齐。其申请的调取器的buf空间APP_SCHED_BUF存在静态区,并且可以4个字节对齐,在程序结束的时候释放。

调度的暂停和恢复

nodic 官方提供了调度没得暂停和恢复函数。

void app_sched_pause    (   void        )
void app_sched_resume   (   void        )   

app_sched_pause 和 app_sched_resume 分别可以暂停地调度和将调度从暂停中恢复。两个函数可重复调用,但必须成对出现。在使用使用需要势能宏APP_SCHEDULER_WITH_PAUSE 启用调度的暂停功能。

获取调度队列的空闲空间

uint16_t app_sched_queue_space_get

如果从中断中添加调度时,此时可以先检查下队列的剩余空间。

observed queue utilization

uint16_t app_sched_queue_utilization_get    (   void        )   

获取队列的利用率。注意调用的时候需要先势能宏APP_SCHEDULER_WITH_PROFILER. Enabling scheduler profiling,启用调度分析。

将一个事件放入调度队列

uint32_t app_sched_event_put    (   void *  p_event_data,uint16_t   event_size,app_sched_event_handler_t    handler )   

[in] p_event_data Pointer to event data to be scheduled.
指针指向需要调度数据的地址。
[in] event_size Size of event data to be scheduled.
放入调度的数据大小。
[in] handler Event handler to receive the event.
调度的处理函数。

开始事件调度

void  app_sched_execute (void) 

调度的事件流示意

Receiving an event from the ble stack causing a service event
Receiving an event from the ble stack causing a service event

The battery timer expires
 The battery timer expires

不使用调度的事件流示意

Receiving an event from the ble stack causing a service event
 Receiving an event from the ble stack causing a service event

The battery timer expires]
The battery timer expires

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
nrf51822中文参考手册,nRF51822 是一款集成nRF51x系列无线收发器的超低功耗的片上系统 (Soc) , 包含一个32位ARM Cortex-M0 CPU , flash 存储器和模拟、数字外设。NORDIC SEMICONDUCTOR nRF51822 Product Specification v1.3 Liability disclaimer Nordic Semiconductor ASa reserves the right to make changes without further notice to the product to improve reliability, function or design. Nordic Semiconductor asa does not assume any liability arising out of the application or use of any product or circuits described herein ife support applications Nordic Semiconductor's products are not designed for use in life support appliances, devices, or systems where malfunction of these products can reasonably be expected to result in personal injury. Nordic Semiconductor ASa customers using or selling these products for use in such applications do so at their own risk and agree to fully indemnify Nordic Semiconductor ASA for any damages resulting from such improper use or sale Contact details Foryournearestdistributorpleasevisitwww.nordicsemi.com Information regarding product updates, downloads, and technical support can be accessed through your My Page account on our home page Main office: Otto Nielsens veg 12 Mailing address: Nordic Semiconductor 7052 Trondheim P.O. Box 2336 Norway 7004 Trondhe Phone:+4772898900 Norway 4772898989 画N远 NS-EN ISO 9001 CERTIFICATEDFIRM RoHS and reach statement Nordic semiconductor's products meet the requirements of Directive 2002/95/EC of the European Parliament and of the Council on the restriction of Hazardous Substances(roHS)and the requirements of the reach regulation(EC 1907/2006)on Registration, Evaluation, Authorization and Restriction of Chemicals. The SvHC(Substances of Very High Concern) candidate list is continually being updated Complete hazardous substance reports material composition reports and latest version of nordics reach statementcanbefoundonourwebsitewww.nordicsemicom Page 2 of 67 NORDIC SEMICONDUCTOR nRF51822 Product Specification v1.3 Datasheet status Status Description Objective Pro

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

002237

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值