mirror of https://github.com/ARMmbed/mbed-os.git
Update critical section for NRF5x
parent
efa3461fd4
commit
cf61c240bf
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue