After using chSysDisable() to disable interrupts the obvious thing to re-enable interrupts is chSysEnable(). That doesn't seem to cope with the case where the caller of the function had also disabled interrupts, so I'm wondering if there is a recommended approach to restore the previous interrupt mask state.
What I was expecting was something like:
isr_state_t state = chSysDisable();
// do stuff with interrupts disabled
chSysRestore(state);
is there an equivalent to this in ChibiOS? Or is there some other way to safely restore the previous interrupt mask state?
I'm on a stm32f4xx in case it matters.
Cheers, Tridge
safely re-enabling interrupts after chSysDisable() Topic is solved
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: safely re-enabling interrupts after chSysDisable()
Hi,
It is possible to do this in a portable way:
Note that depending on the architecture this can disable interrupts globally or raise the interrupt mask to a certain level. On the F4 it masks all IRQs up to priority 2 (0 and 1 are not masked), it operates on the BASEPRI register in order to do so. This is how critical zones are implemented.
chSysDisable() masks interrupts globally, it should not be used for critical zones.
Giovanni
It is possible to do this in a portable way:
Code: Select all
syssts_t sts = chSysGetStatusAndLockX(void);
...
chSysRestoreStatusX(sts);
Note that depending on the architecture this can disable interrupts globally or raise the interrupt mask to a certain level. On the F4 it masks all IRQs up to priority 2 (0 and 1 are not masked), it operates on the BASEPRI register in order to do so. This is how critical zones are implemented.
chSysDisable() masks interrupts globally, it should not be used for critical zones.
Giovanni