From 2f40c61c3e1eaf97ae12650a00530718bf9cd4be Mon Sep 17 00:00:00 2001 From: Glenn Ruben Bakke Date: Wed, 24 May 2017 23:22:23 +0200 Subject: [PATCH] nrf5/hal/irq: Adding wrappers for handling nvic calls when Bluetooth LE stack is enabled. --- nrf5/hal/hal_irq.h | 84 +++++++++++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 24 deletions(-) diff --git a/nrf5/hal/hal_irq.h b/nrf5/hal/hal_irq.h index 266758beec..a610f1035a 100644 --- a/nrf5/hal/hal_irq.h +++ b/nrf5/hal/hal_irq.h @@ -32,52 +32,88 @@ #include "nrf.h" #if BLUETOOTH_SD -#if NRF51 - #include "nrf_sdm.h" -#elif NRF52 +#include "py/nlr.h" +#include "ble_drv.h" + +#define BLUETOOTH_STACK_ENABLED() (ble_drv_stack_enabled()) + +#ifdef NRF51 + #include "nrf_soc.h" +#elif defined(NRF52) #include "nrf_nvic.h" #endif -#endif +#endif // BLUETOOTH_SD static inline void hal_irq_clear(uint32_t irq_num) { #if BLUETOOTH_SD - sd_nvic_ClearPendingIRQ(irq_num); -#else - NVIC_ClearPendingIRQ(irq_num); -#endif + if (BLUETOOTH_STACK_ENABLED() == 1) { + if (sd_nvic_ClearPendingIRQ(irq_num) != 0) { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, + "IRQ (%d) clear error", irq_num)); + } + } else +#endif // BLUETOOTH_SD + { + NVIC_ClearPendingIRQ(irq_num); + } } static inline void hal_irq_enable(uint32_t irq_num) { hal_irq_clear(irq_num); + #if BLUETOOTH_SD - sd_nvic_EnableIRQ(irq_num); -#else - NVIC_EnableIRQ(irq_num); -#endif + if (BLUETOOTH_STACK_ENABLED() == 1) { + if (sd_nvic_EnableIRQ(irq_num) != 0) { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, + "IRQ (%d) enable error", irq_num)); + } + } else +#endif // BLUETOOTH_SD + { + NVIC_EnableIRQ(irq_num); + } } static inline void hal_irq_disable(uint32_t irq_num) { #if BLUETOOTH_SD - sd_nvic_DisableIRQ(irq_num); -#else - NVIC_DisableIRQ(irq_num); -#endif + if (BLUETOOTH_STACK_ENABLED() == 1) { + if (sd_nvic_DisableIRQ(irq_num) != 0) { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, + "IRQ (%d) disable error", irq_num)); + } + } else +#endif // BLUETOOTH_SD + { + NVIC_DisableIRQ(irq_num); + } } static inline void hal_irq_priority(uint32_t irq_num, uint8_t priority) { #if BLUETOOTH_SD - sd_nvic_SetPriority(irq_num, priority); -#else - NVIC_SetPriority(irq_num, priority); -#endif + if (BLUETOOTH_STACK_ENABLED() == 1) { + if (sd_nvic_SetPriority(irq_num, priority) != 0) { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, + "IRQ (%d) priority error", irq_num, priority)); + } + } else +#endif // BLUETOOTH_SD + { + NVIC_SetPriority(irq_num, priority); + } } static inline void hal_irq_pending(uint32_t irq_num) { #if BLUETOOTH_SD - sd_nvic_SetPendingIRQ(irq_num); -#else - NVIC_SetPendingIRQ(irq_num); -#endif + if (BLUETOOTH_STACK_ENABLED() == 1) { + if (sd_nvic_SetPendingIRQ(irq_num) != 0) { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, + "IRQ (%d) pending error", irq_num)); + } + } else +#endif // BLUETOOTH_SD + { + NVIC_SetPendingIRQ(irq_num); + } } #endif // HAL_IRQ_H__