nRF51 SDK - S130 SoftDevice
|
The SWI driver provides functions to manage software interrupts (SWI). It allows users to allocate SWIs and pass extra flags to interrupt handler functions.
Software interrupts are allocated from the available SWI pool. By default, there are six interrupts available: SWI0 to SWI5. Note that this number is decreased if you use a SoftDevice or the Gazell or ESB protocol. For more information about resource usage for a specific protocol library, see the appropriate specification.
You must initialize the driver by calling the nrf_drv_swi_init function. If initialization is successful, the function returns NRF_SUCCESS.
To allocate an interrupt, call the nrf_drv_swi_alloc function. As input, you must provide a pointer to the nrf_swi_t variable, an event handler function, and a value that indicates the interrupt priority. If allocation is successful, the function returns NRF_SUCCESS, and the provided pointer variable is set.
When allocating the driver, you must provide a callback function (see nrf_swi_handler_t). The arguments for this function are the SWI and some user flags. The user flags are represented as bit mask.
To trigger the interrupt, call nrf_drv_swi_trigger with a specific flag number. When an SWI is triggered, the corresponding callback function is called with all specified flags (represented as a bit mask). The flags can be used, for example, for interrupt source tracking, or they can be ignored if not needed. Note that the callback function might be invoked with more than one flag set if the SWI is triggered more than once with different flag numbers from a same or higher priority interrupt handler.
To disable specific SWIs from the pool, add a global define during compilation (SWI_DISABLE0 to SWI_DISABLE5). Any disabled SWI will not be allocated and will therefore not be available to the user.
See the following code for a usage example. Note that this example is not power optimized.
The library can be used with a SoftDevice. However, the amount of interrupts that are available to the user will be limited in this case. See the SoftDevice specification for more information about the resource usage.
Be careful when specifying APP_IRQ_PRIORITY_HIGH as SWI priority. Long interrupt routines with high priority might affect the proper operation of the SoftDevice.