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, utzig, tfAteba, barthess
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: safely re-enabling interrupts after chSysDisable() Topic is solved
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
-
- Posts: 141
- Joined: Mon Sep 25, 2017 8:27 am
- Location: Canberra, Australia
- Has thanked: 10 times
- Been thanked: 20 times
- Contact:
Re: safely re-enabling interrupts after chSysDisable()
Giovanni wrote:Hi,
It is possible to do this in a portable way:
thanks, much appreciated!
Who is online
Users browsing this forum: Bing [Bot] and 47 guests