This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Interrupt priority

Hi,

While the softdevice is active (nRF51822) available interrupt priorities are:

typedef enum { NRF_APP_PRIORITY_HIGH = 1, NRF_APP_PRIORITY_LOW = 3 } nrf_app_irq_priority_t;

  1. Can I use interrupt priority = 2?
  2. SVC priority is 2, is it true? So I could't use Softdevice api-functions in interrupt handlers with NRF_APP_PRIORITY_HIGH priority?
  3. What does define "#define NRF_APP_PRIORITY_THREAD 4" in app_util.h mean?

Artem Z. Best Regards

  • Hi Artem,

    to answer your questions

    • 1. Can I use interrupt priority = 2? No, not while the SoftDevice is active. If you try to set this priority level using sd_nvic_SetPriority() you will get an error.
    • 2. SVC priority is 2, is it true? So I could't use Softdevice api-functions in interrupt handlers with NRF_APP_PRIORITY_HIGH priority? Correct. You would need to pass execution to a lower priority level, for example by using a software interrupt (SWIRQ) with NRF_APP_PRIORITY_LOW.
    • 3. What does define "#define NRF_APP_PRIORITY_THREAD 4" in app_util.h mean? It's used in "current_int_priority_get()" to indicate if the CPU is running in thread mode (main context), as opposed to running in interrupt mode with interrupt priority 0-3.
  • Hi Audun,

    Thanks for reply.

    One more question. Consider Write Request without Authorization. After receive "Write Request" and send "Write Response" Stack generate event BLE_GATTS_EVT_WRITE. As I understand, at first Stack handles Radio_IRQ with priority = 0 (max configuring priority for cortex m0) and then via software interrupt handle SWI2_IRQ with priority = 3 (where stack calls ble_evt_dispatch()). My question is in what handler (SWI2, Radio or somewhere else) really attribute will be written in GATT table?

    I asked this question because I am interested in what will happen if write request will be received during processing sd_ble_gatts_value_set()? For example: my service has attribute "Counter". Application is incrementing it's value via sd_ble_gatts_value_set(). And during sd_ble_gatts_value_set() stack receives "ATT Write request" to reset attribute "Counter" (assigns it to 0). How stack will resolve this situation?

    I suppose at first stack set this value in sd_ble_gatts_value_set(), then after SVC handler return, Stack will assign new value for attribute in SWI2 handler (this is the value received via write request).

  • I'll have to check with someone more intimately familiar with the stack to answer this question. Let me get back to you!

  • "My question is in what handler (SWI2, Radio or somewhere else) really attribute will be written in GATT table?"

    The SoftDevice operates on GATT table at the same priority as the SVC API, hence access to GATT table is context-safe.

  • Artem, did vich answer your question?

    Even though all access to the GATT database happens at the same priority, your application still needs to handle the case where both the Central and Peripheral writes to this characteristic in close succession. Maybe applying a "control point" type characteristic will make things easier? Several profiles have characteristics called "control points". The client will write commands to the control point, for example "clear counter command", and the application performs the action.

Related