Wait mode and race conditions

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Wait mode and race conditions

ソリューションへジャンプ
1,618件の閲覧回数
doynax
Contributor I

Hi! I'm new to the this microcontroller and this is my first post, so be kind. Anyway...

 

I often find it convenient to wait for some condition by triggering a future interrupt and putting the processor to sleep, then after waking up again processing whatever the event was in the main loop with only minimal logic in the interrupt handler itself (e.g. to avoid error-prone synchronization logic with volatiles and such.)

 

Alas I'm having a bit of trouble figuring out a clean way of doing this on the 68HCS08 without potential race conditions. That is in the case where the interrupt triggers before the wait instruction and the wait immediately goes to sleep until the next condition arises without having processed the last one.

 

E.g.

int main(...) {  for(;;) {    process(...);    set_pin_irq();    // If the pin interrupt triggers here we're in trouble

    _Wait;  }}
 

On the AVR I would clear the sleep-enable bit from within the interrupt handler to avoid this case. About the best method I've been able to come up with on this MCU is to wrap the whole block with the interrupt trigger and wait instruction in a setjmp, but that's problematic on so many levels that it's not even funny.

ラベル(1)
0 件の賞賛
返信
1 解決策
1,014件の閲覧回数
jag
Contributor IV

Hi,

you can put a DisableInterrupts; macro just before the set_pin_irq(); call.

This sets the I bit in the CCR register, that masks every interrupts.

 

In order to reset the I bit, and thus reenabling the interrupts, you have to use the EnableInterrupts; or _Wait; or _Stop; macros.

 

Check the datasheets for more infos.

 

Bye Jack 

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
1,015件の閲覧回数
jag
Contributor IV

Hi,

you can put a DisableInterrupts; macro just before the set_pin_irq(); call.

This sets the I bit in the CCR register, that masks every interrupts.

 

In order to reset the I bit, and thus reenabling the interrupts, you have to use the EnableInterrupts; or _Wait; or _Stop; macros.

 

Check the datasheets for more infos.

 

Bye Jack 

0 件の賞賛
返信
1,014件の閲覧回数
doynax
Contributor I

Ah, so WAIT implicitly enables interrupts. I figured the solution had to be something embarrasingly simple.

 

Thank you!

0 件の賞賛
返信