Nordic系列芯片讲解六 ( Nordic协议栈与应用层API的实现方式)

Nordic是协议栈以hex文件的方式提供,那么app怎么是怎么通过api来调用协议栈的呢。

一、应用层通过API的方式调用协议栈的函数,通过SVC中断方式。

1)SVC的宏定义

#define SVCALL(number, return_type, signature) return_type __svc(number) signature
SVCALL(SD_BLE_GAP_DATA_LENGTH_UPDATE, uint32_t, sd_ble_gap_data_length_update(uint16_t conn_handle, ble_gap_data_length_params_t const *p_dl_params, ble_gap_data_length_limitation_t *p_dl_limitation));

2)当协议栈被使能时,共用了0X10~0XFF,具体来说就是每个API函数对应一个number。通过SVC来调用的功能有:

  1. NRF_SOC_SVCS // SoC library,主要是一些外设PPI, FLASH, CLOCK等
  2. NRF_SD_SVCS // SoftDevice Manager, 协议栈管理,主要用来开启关闭协议栈,查询协议栈是否开启,以及在bootloader被enabled时指明中断向量表
  3. BLE_L2CAP_SVCS // L2CAP API SVC numbers
  4. BLE_GATTS_SVCS // GATTS API SVC numbers.
  5. BLE_GATTC_SVCS //GATTC API SVC numbers.
  6. BLE_GAP_SVCS // GAP API SVC numbers.
  7. BLE_COMMON_SVCS // Common API SVC numbers.

3)SVC number的范围

这里写图片描述
图中说明了0x10 ~0xff都被协议栈占用了。有兴趣可以在sdk中找具体每个api用到那个number。

二。我们知道了APP调用协议栈的函数时通过SVC异常来实现,那么协议栈产生的事件又是怎样通知各APP的呢。答案是SWI中断。

  1. SWI软中断的使用情况

这里写图片描述
这里写图片描述
由上图可以可以看到 SWI用到了
SWI1 : RADIO_NOTIFICATION
SWI2: SD_EVT
SWI5: SWI5是协议栈本身调度使用了。
在sdk代码中也体现了这一点。

#define SD_EVT_IRQn                       (SWI2_EGU2_IRQn)        /**< SoftDevice Event IRQ number. Used for both protocol events and SoC events. */
#define SD_EVT_IRQHandler                 (SWI2_EGU2_IRQHandler)  /**< SoftDevice Event IRQ handler. Used for both protocol events and SoC events.
                                                                       The default interrupt priority for this handler is set to 4 */
#define RADIO_NOTIFICATION_IRQn           (SWI1_EGU1_IRQn)        /**< The radio notification IRQ number. */
#define RADIO_NOTIFICATION_IRQHandler     (SWI1_EGU1_IRQHandler)  /**< The radio notification IRQ handler.
 

三、 中断的分布

这里写图片描述

The nRF52 SoC has eight configurable interrupt priorities ranging from 0 to 7 (with 0 being highest priority).On reset, all interrupts are configured with the highest priority (0).

• Level 0 is used for the SoftDevice’s timing critical processing.
• Level 1 is used for handling the memory isolation and run time protection, see Memory isolation and runtime protection on page 16.
• Level 4 is used by higher-level deferrable tasks and the API functions executed as SVC interrupts.
• Level 5 is reserved for future use for SoftDevice 4.0.x versions that are earlier than 4.0.3.

SoftDevice保留的中断优先级不能改变。 这个包括SVC中断。 处理器的优先级高于4(优先级较低值)既不能访问SoftDevice功能,也不能访问特定于应用的SVC或RTOS功能以较低的优先级运行(较高的数字优先级值)

•level 0 用于SoftDevice的时序关键处理。
•level 1用于处理内存隔离和运行时保护,请参阅内存隔离和
运行时保护(第16页)。
•level 4 更高级别的可延迟任务以及作为SVC中断执行的API函数。
•Level 5保留供将来在4.0.3之前使用的SoftDevice 4.0.x版本使用。

四、各中断的对应关系
level 4: 对应 SVC CALL,用于APP通知协议栈。
level 0: 对应SWI5, 即协议栈本身调度使用了。
level 1: 对应SWI2和SWI1, 即SD_EVT和RADIO_NOTIFICATION, 用于协议栈通知APP。

写博客实在耗时间,但为了总结学到的知识,还是很有必要的~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~欢迎留言。欢迎大家关注我的个人微信公众号“低功耗蓝牙技术研究及推广”!
在这里插入图片描述

  • 1
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值