-
Notifications
You must be signed in to change notification settings - Fork 958
AVR: any way to hookup an interrupt? #16
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
Comments
Not yet. There is some support for ARM (using What needs to be done is adding a special attribute to the function and somehow hooking it up into the ISR vector. While that is done, it's probably best to also auto-generate the interrupt vector for AVR from the .atdf files (it's now hardcoded at the interrupt vector for the ATmega328). It will probably look like this commit but without the .bss/.data setup (which is already done) and with an extra |
Looking at that commit, I would for sure need some help with this task. These are pragmas I am not familiar with, among other needed learning to make progress on this enhancement. |
Yeah, it's a bit involved and requires knowledge of how all these parts work. If you want to work on it, here are some pointers:
Otherwise I'll probably implement this the next time I'm working on TinyGo. |
I have implemented support for autogenerated interrupt vectors in b963831, which is the first step towards interrupts on AVR. This also means the AVR support isn't as tightly tied to the atmega328p as before. Turns out that adding the |
Found it, here is a branch you can try: https://github.com/aykevl/tinygo/tree/avr-interrupts I haven't tested it on the device but the generated assembly looks good. If you can confirm it works, I can merge it. You can use it like this: //go:interrupt INT0_vect
func handleINT0() {
// ...
} Of course, for communication between the ISR and main code, you need to use a volatile variable. This is currently supported using a hack: any type named |
That looks very exciting. I will start playing with it, and let you know how it goes. Thanks! |
I tried to define the following interrupt handler in //go:interrupt USART_RX_vect
func handleUSART_RX() {
// Read UDR register to reset flag
data := *avr.UDR0
// echo back
*avr.UDR0 = avr.RegValue(data)
} When compiling with this branch, I received the following error:
|
Took me a while to realize what was going on here. At least that's my best guess. |
After merging
|
Ah, that's a different conflict due to some refactoring I did yesterday (cleaning up some code to make it easier to test). I've merged master myself and added a fix. |
You see, this compiler is still rather in flux ;) and I'm doing these changes now so they don't need to be done later when things get even more complicated. |
Absolutely, yes! |
OK thanks for the update. The code now compiles, but does not work as expected. Hard to tell what is wrong, how can I tell if my interrupt handler is being called? Also does my syntax from above look correct to you? |
Copied your code into examples/serial and disassembled the output:
The ISR handler itself looks okay (ends in
The vector also looks okay to me (it lists
|
Something that should work everywhere: enable/disable a GPIO pin. That's an easy way to detect whether the interrupt gets called at all. |
I've added the interrupt support to master to make it easier to work on. Disassembly looks good to me so I'm expecting it to work... |
Just discovered that if I define my interrupt handler in |
Good news is it was called! |
I've seen this before and it was because the
|
Yes, still a problem. Here are the .ll and .elf files. |
Are you on master? (Just to be sure) |
Yes, on master. |
This is... weird. |
👻 |
Aaaah I think I got it. |
That is exactly it. My go vet or something removed the unused package from the imports, and I did not pay any attention. Verifying that now... |
Confirmed. Good catch on that! OK so the code is working as expected. My next question is, how can I use |
I think if you use this it should work - every element of the array is of type type __volatile uint8
var ringbuffer [20]__volatile
var head __volatile
var tail __volatile
// etc You might also get away with only using Ideally I want to remove this //go:volatile
type ringbuffer struct {
buf [20]byte
head uint8
tail uint8
}
// NOTE: does not work yet
var rx ringbuffer |
The current |
because it uses inputs for arbitrary request parameters which are not defined in action.yml.
I'd like to be able to use an interrupt to handle buffering of incoming UART data. Basically the same as this:
Is there a way to do this?
The text was updated successfully, but these errors were encountered: