Nordic是协议栈的调用方式

匿名 (未验证) 提交于 2019-12-03 00:38:01

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等
    1. NRF_SD_SVCS // SoftDevice Manager, 协议栈管理,主要用来开启关闭协议栈,查询协议栈是否开启,以及在bootloader被enabled时指明中断向量表
    2. BLE_L2CAP_SVCS // L2CAP API SVC numbers
    3. BLE_GATTS_SVCS // GATTS API SVC numbers.
    4. BLE_GATTC_SVCS //GATTC API SVC numbers.
    5. BLE_GAP_SVCS // GAP API SVC numbers.
    6. 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).




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



运行时保护(第16页)。

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

写博客实在耗时间,但为了总结学到的知识,还是很有必要的~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~欢迎留言

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!