Update critical section for NRF5x

pull/6547/head
Marcus Chang 2018-01-22 11:26:31 -08:00
parent efa3461fd4
commit cf61c240bf
1 changed files with 18 additions and 13 deletions

View File

@ -19,13 +19,13 @@
#include "app_util_platform.h"
#if defined(SOFTDEVICE_PRESENT)
static volatile uint32_t nordic_cr_nested = 0;
static volatile bool state_saved = false;
static void nordic_nvic_critical_region_enter(void);
static void nordic_nvic_critical_region_exit(void);
#endif
void core_util_critical_section_enter()
void hal_critical_section_enter()
{
#ifdef NRF52
ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
@ -39,7 +39,7 @@ void core_util_critical_section_enter()
#endif
}
void core_util_critical_section_exit()
void hal_critical_section_exit()
{
#ifdef NRF52
ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
@ -53,6 +53,13 @@ void core_util_critical_section_exit()
#endif
}
bool hal_in_critical_section(void)
{
return (state_saved != 0);
}
#if defined(SOFTDEVICE_PRESENT)
/**@brief Enters critical region.
*
@ -63,7 +70,7 @@ static inline void nordic_nvic_critical_region_enter(void)
{
int was_masked = __sd_nvic_irq_disable();
if (nordic_cr_nested == 0) {
if (state_saved == false) {
nrf_nvic_state.__irq_masks[0] = ( NVIC->ICER[0] & __NRF_NVIC_APP_IRQS_0 );
NVIC->ICER[0] = __NRF_NVIC_APP_IRQS_0;
#ifdef NRF52
@ -72,7 +79,7 @@ static inline void nordic_nvic_critical_region_enter(void)
#endif
}
nordic_cr_nested++;
state_saved = true;
if (!was_masked) {
__sd_nvic_irq_enable();
@ -86,17 +93,15 @@ static inline void nordic_nvic_critical_region_enter(void)
*/
static inline void nordic_nvic_critical_region_exit(void)
{
nordic_cr_nested--;
state_saved = false;
if (nordic_cr_nested == 0) {
int was_masked = __sd_nvic_irq_disable();
NVIC->ISER[0] = nrf_nvic_state.__irq_masks[0];
int was_masked = __sd_nvic_irq_disable();
NVIC->ISER[0] = nrf_nvic_state.__irq_masks[0];
#ifdef NRF52
NVIC->ISER[1] = nrf_nvic_state.__irq_masks[1];
NVIC->ISER[1] = nrf_nvic_state.__irq_masks[1];
#endif
if (!was_masked) {
__sd_nvic_irq_enable();
}
if (!was_masked) {
__sd_nvic_irq_enable();
}
}
#endif