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

sd_nvic_region_enter/exit

In regard to the following functions

uint32_t sd_nvic_critical_region_enter ( uint8_t * p_is_nested_critical_region ) uint32_t sd_nvic_critical_region_exit ( uint8_t is_nested_critical_region )

It appears that these functions keep track of nested critcal regions for us. How are they to be used. I have just been passing in a local variable (is_nested). Do the functions themselves manage the value of the variable for me. Should they be made global? Or is local fine?

Also will these functions disable all user mode interrupts? Software-timers, hw timers, serial communication, ect... I assume they leave the critical soft device interrupts enabled?

Thank you for the support.

Parents
  • Hi,

    As long as you are willing to limit your entering and exiting critical regions to the same scope, you can use the macros CRITICAL_REGION_ENTER and CRITICAL_REGION_EXIT in app_util.h. The macros deal with the is nested variable for you.

    I think it is clear from the implementation of the macros that sd_nvic_critical_region_enter determines if the region is nested and you must keep track of that in the variable. I think locals would definitely be better. Otherwise once the global is set, how do you know when you have fully exited the nested regions?

    Regards, John

  • From what you describe this sudo code should be valid

    f2() {

    uint8_t is_nested;

    sd_nvic_critical_region_enter ( &is_nested ) ;

    sd_nvic_critical_region_exit ( is_nested );

    }

    f1() {

    uint8_t is_nested;

    sd_nvic_critical_region_enter ( &is_nested ) ;

    f2();

    sd_nvic_critical_region_exit ( is_nested );

    }

    f2 would not cause the program to leave the critical region correct.

Reply
  • From what you describe this sudo code should be valid

    f2() {

    uint8_t is_nested;

    sd_nvic_critical_region_enter ( &is_nested ) ;

    sd_nvic_critical_region_exit ( is_nested );

    }

    f1() {

    uint8_t is_nested;

    sd_nvic_critical_region_enter ( &is_nested ) ;

    f2();

    sd_nvic_critical_region_exit ( is_nested );

    }

    f2 would not cause the program to leave the critical region correct.

Children
No Data
Related