Nordic是协议栈以hex文件的方式提供,那么app怎么是怎么通过api来调用协议栈的呢。
1. 应用层通过API的方式调用协议栈的函数,通过SVC中断方式。
当协议栈被使能时,共用了0X10~0XFF,具体来说就是每个API函数对应一个number。
#define SOC_SVC_BASE (0x20)
#define BLE_SVC_BASE 0x60 /**< Common BLE SVC base. */
#define BLE_SVC_LAST 0x6B /**< Common BLE SVC last. */
#define BLE_GAP_SVC_BASE 0x6C /**< GAP BLE SVC base. */
#define BLE_GAP_SVC_LAST 0x93 /**< GAP BLE SVC last. */
#define BLE_GATTC_SVC_BASE 0x94 /**< GATTC BLE SVC base. */
#define BLE_GATTC_SVC_LAST 0x9F /**< GATTC BLE SVC last. */
#define BLE_GATTS_SVC_BASE 0xA0 /**< GATTS BLE SVC base. */
#define BLE_GATTS_SVC_LAST 0xAF /**< GATTS BLE SVC last. */
#define BLE_L2CAP_SVC_BASE 0xB0 /**< L2CAP BLE SVC base. */
#define BLE_L2CAP_SVC_LAST 0xBF /**< L2CAP BLE SVC last. */
2.而协议栈则通过SWI中断开通知APP.
由上图可以可以看到 SWI用到了SWI1, SWI2, SWI5, 但SWI5是协议栈本身调度使用了。在sdk代码中也体现了这一点。
#define SD_EVT_IRQn (SWI2_EGU2_IRQn) /**< SoftDevice
#define SD_EVT_IRQHandler (SWI2_EGU2_IRQHandler) /**< SoftDevice
#define RADIO_NOTIFICATION_IRQn (SWI1_EGU1_IRQn) /**< The radio
#define RADIO_NOTIFICATION_IRQHandler (SWI1_EGU1_IRQHandler) /**< The radio