Skip to content

Conversation

jthacker
Copy link
Contributor

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.

@OlegHahm OlegHahm added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Platform: AVR Platform: This PR/issue effects AVR-based platforms labels Aug 21, 2016
@OlegHahm OlegHahm added this to the Release 2016.10 milestone Aug 21, 2016
@kYc0o
Copy link
Contributor

kYc0o commented Aug 31, 2016

I'm testing this PR on arduino-mega2560 without success...

I tested
tests/msg_send_receive results are weird
tests/msg_try_receive doesn't work
tests/xtimer_msg doesn't work

Maybe the interruptions are not well handled? PCINT are not handled for now BTW...

@jthacker jthacker force-pushed the avr_thread_arch_isr_stack_usage branch from fd143da to e5513de Compare September 1, 2016 14:32
@jthacker
Copy link
Contributor Author

jthacker commented Sep 1, 2016

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.

@kYc0o
Copy link
Contributor

kYc0o commented Sep 1, 2016

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.
Is this important?

@jthacker
Copy link
Contributor Author

jthacker commented Sep 1, 2016

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.

On Sep 1, 2016, at 10:40, kYc0o notifications@github.com wrote:

Oh ok, but actually what I meant is that you are using a PCINT* interruption, if you look here https://github.com/RIOT-OS/RIOT/blob/master/cpu/atmega_common/periph/gpio.c#L250 you can see that only INT* interruptions are handled.
Is this important?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #5763 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AAbmlHrzOamOiZvLcxlKVQp7-fqFH5z6ks5qlvHmgaJpZM4JpFC3.

#define AVR_CONTEXT_SWAP_INIT do { \
DDRB |= (1 << PB5); \
PCICR |= (1 << PCIE0); \
PCMSK0 |= (1 << PCINT0); \
Copy link
Contributor

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.

@kYc0o
Copy link
Contributor

kYc0o commented Sep 2, 2016

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 PB5 is mapped, the only thing I know for now is that it's on the XBEE socket, but I don't know which pin. We can leave it like this for now and I could change it in the future if needed.

Thus ACK and let's see what Murdock thinks.

@kYc0o kYc0o added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Sep 2, 2016
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.
@jthacker jthacker force-pushed the avr_thread_arch_isr_stack_usage branch from e5513de to e0365e0 Compare September 7, 2016 19:36
@jthacker
Copy link
Contributor Author

@kYc0o Just checking in on the status of this PR

@kYc0o
Copy link
Contributor

kYc0o commented Sep 21, 2016

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: AVR Platform: This PR/issue effects AVR-based platforms Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants