-
Notifications
You must be signed in to change notification settings - Fork 2.1k
atmega: use software interrupt for context swap #5763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
atmega: use software interrupt for context swap #5763
Conversation
I'm testing this PR on arduino-mega2560 without success... I tested Maybe the interruptions are not well handled? PCINT are not handled for now BTW... |
fd143da
to
e5513de
Compare
Looks like I had a typo in the pin, should have been PJ6, but was PJ7. If the symptoms were that the context swap was not happening, then this should fix that. |
Oh ok, but actually what I meant is that you are using a PCINT* interruption, if you look here you can see that only INT* interruptions are handled. |
I see. Actually the PCINT ISR is handled directly in thread_arch.c e5513de#diff-2a1694366e0c652ed876c23bb1758083R273 e5513de#diff-2a1694366e0c652ed876c23bb1758083R273 In order to handle the context swap correctly, it needs to be a naked handler.
|
#define AVR_CONTEXT_SWAP_INIT do { \ | ||
DDRB |= (1 << PB5); \ | ||
PCICR |= (1 << PCIE0); \ | ||
PCMSK0 |= (1 << PCINT0); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it should be PCINT5
.
Besides the small typo the PR works very well, even the xtimer tests work better now. Maybe @kaspar030 would like to test his modifications to xtimer after this PR gets merged? For the waspmote I'm trying to investigate where Thus ACK and let's see what Murdock thinks. |
Fixes RIOT-OS#5745 For AVR based boards, three defines must be defined AVR_CONTEXT_SWAP_INIT, AVR_CONTEXT_SWAP_INTERRUPT_VECT, and AVR_CONTEXT_SWAP_TRIGGER. These defines are used to trigger a software interrupt used for context switching. When AVR_CONTEXT_SWAP_INTERRUPT_VECT is handled, the scheduler is run and a context swap will happen if necessary, with the resulting thread starting following the reti instruction. This results in threads running at normal priority instead of at interrupt priority. Atmega devices do provide a pure software interrupt. The method used here for waspmote-pro and arduino-mega2560 is to use pin change interrupts, set the pin to act as an output, and toggle the value to simulate a software interrupt. The main limitation here is that a physical pin is now occupied and must be defined for each board supported by RIOT. On the plus side, it provides an easy method for detecting context swaps with an oscilloscope.
e5513de
to
e0365e0
Compare
@kYc0o Just checking in on the status of this PR |
Oups! I forgot this one. Yes it can be merged now but I don't know if additional checks are needed since the github interface has changed. Maybe @aabadie can take a look? |
Fixes #5745
For AVR based boards, three defines must be defined AVR_CONTEXT_SWAP_INIT,
AVR_CONTEXT_SWAP_INTERRUPT_VECT, and AVR_CONTEXT_SWAP_TRIGGER.
These defines are used to trigger a software interrupt used for context
switching.
When AVR_CONTEXT_SWAP_INTERRUPT_VECT is handled, the scheduler is run
and a context swap will happen if necessary, with the resulting thread
starting following the reti instruction. This results in threads running
at normal priority instead of at interrupt priority.
Atmega devices do provide a pure software interrupt. The method used
here for waspmote-pro and arduino-mega2560 is to use pin change
interrupts, set the pin to act as an output, and toggle the value to
simulate a software interrupt. The main limitation here is that a
physical pin is now occupied and must be defined for each board
supported by RIOT. On the plus side, it provides an easy method for
detecting context swaps with an oscilloscope.
I don't have access to either the arduino or waspmote boards, so it would be good to verify that the pins chosen are ok. The waspmote seems to use all the PCINT and INT pins, so I just chose one that looked generic.