highWaters
highWaters

Reputation: 3

Generic question on the main and interrupt contexts

I am trying to gain more understanding on the main and interrupt contexts. In contiki there is cooperative scheduling, i.e., the scheduler cannot interrupt the execution of the protothreads, however hardware interrupts can (like button clicks). An interrupt would switch the context from the main, effectively taking control from the protothread, and if in the interrupt handler we access the same variables as in the protothread, we need to take care of race conditions.

Here is what is somewhat unclear.

Once an interrupt comes, e.g. pressing the user button, does the protothread yield control? Or is it in pause, and will resume where it left of once the interrupt is handled? From here Mutual exclusion within a function Contiki, it says "If your list is accessed both from protothread and from interrupt handler contexts, you need to do all modifications in the list with interrupts disabled. So your lock/unlock code is disable/enable interrupts, respectively." Would this lock and unlock be used both in the protothread and interrupt context?

When we use the button object though, we wouldn't need to do this, since we are not dealing with the hardware directly? When we click the button, an interrupt is fired, but handled at a lower level? Or is it that we still would need to check if there is any race condition to be sure?

I have also seen these: How does Contiki OS process external interrupts?, TelosB GPIO interrupts in Contiki, Using ISR functions in the Contiki Context.

Thanks in advance :).

hw

Upvotes: 0

Views: 17

Answers (0)

Related Questions