-
Notifications
You must be signed in to change notification settings - Fork 2k
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
cpu/atmega_common: pseudomodule-based pin change interrupt implementation #11122
cpu/atmega_common: pseudomodule-based pin change interrupt implementation #11122
Conversation
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.
Some preliminary comments, I now need to attend some other stuff and will resume the review later
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 the remaining remarks
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.
Some more comments. (Sorry for spotting that not the first time.)
OK, code-wise it almost reached the point I'd ACK (@ZetaR60 and @kYc0o: I'd feel more comfortable if you also could have a brief look at this PR). The next step would be testing. I added a list of checkmarks above to track the state. I can test on ATmega328p and ATmega2560. Maybe @Josar can test for ATmega256rfr2? Regarding the ATmega1281 it will likely go untested, as no one seems to have a waspmote pro any more. (But this will not prevent this PR from merging.) |
Looks like I have a bug with the state, but should be easy to fix and we should be good to go for testing then. |
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.
Two more things (sorry for the seamlessly endless string of nit-picking):
- Some files do not have a newline at the end, the CI will complain about that. (I think it should be exactly one new line to keep them happy, as they will complain about two and more es well.)
- See inline comment
I added some remarks how testing can be done in the (a.f.a.i.k.) most straightforward way. |
Fun fact: atmega328p does not have all banks saturated. Will update shortly. Currently testing on an Arduino Uno! |
Some bad things are happening for me: make BUILD_IN_DOCKER=1 DOCKER="sudo docker" BOARD=arduino-uno all
make BOARD=arduino-uno all
|
Ah, that is the linker test failing because ROM/RAM requirements exceed the provided falsh/RAM. (On ARM the message is human readable and also says how much bytes need to be squeezed out of the build to fit the board.) This just means other means of testing are required for ATmega328P based boards |
(Btw: The test was to huge before this PR for the ATmega328p on the docker and my toolchain.) |
The |
Perfect. With all my remarks addressed please squash, so that others do not need to dig trough the long commit history. |
f9b5f0a
to
eddfdbc
Compare
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.
OK, this PR adds 147 B RAM with 3 pcint banks enabled. The minimum required RAM seems to be:
- Per bank: 1 byte to store the banks previous state
- Per pin:
- 2 byte to store the callback function
- 2 byte to store the user argument (
void *arg
) - 1 byte for the flank
In total this is 3 + 3 * 8 * 5 = 123
bytes. With the changes suggest above this PR reaches this requirements minimal required RAM overhead.
Also currently it adds 908B to the ROM size. I think by using a 1d array for pcint_mapping
this will become a bit less, but I didn't try.
Update: Fixed confusing language
Sorry for asking for more changes, but RIOT's internal code should be as efficient as possible to let the application developer have as much resources as possible left. (Also: I just wrote a simple test application that still doesn't fit the ATmega328p. I will really have trouble testing this :-() |
@roberthartung: Do you have an Arduino Uno? With the changes suggest above this test for the Arduino Uno can be build and flashed (at least with my toolchain). The test works without module |
(Btw: Feel free to just cherry-pick the commit adding the test into your PR. It might be useful to have the test around in RIOT.) |
How is it a test for Aduino Uno if your makefile says |
Output for melooks fine so far. |
OK, apart from the the test (which should expect To me it also is questionable if I am actually allowed to ACK the code of the test, as I authored most of it. Maybe I can open a separate PR for that and you (@roberthartung) could review the test? |
Oh, I forgot that ATmega32U4 has been merged in the meantime. Can you please rebase and add the pcint mapping for that one? I will test on the Arduino Leonardo. |
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.
OK, found one more bug (see above).
So this is still needed in order to ACK:
- Fix the bug above
- Squash and rebase on top of current master
- Add PCINT mapping for the ATmega32U4
I'm extremely sorry that this PR was so exhausting. But I'm confident it now is about to get merged :-)
82d7ff7
to
0adcf14
Compare
Sounds good for me, just removed the test from my code. |
0adcf14
to
9f976b8
Compare
ee33a32
to
9c8e2d3
Compare
9c8e2d3
to
c8d460e
Compare
rebased on latest master, one commit for basic implementation, one commit for each CPU. I think having more commits makes it clearer! Additionally I fixed a bug for atmega1284p (missing .dep file) and I added the atmega256rfr2 CPU. |
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.
ACK
@roberthartung: Thanks for your patience! |
Contribution description
This is pseudomodule-based version of pin change interrupts for the atmega common platform. Challenge was, that each bank of pin change interrupts (PCINT0, ..., PCINT3) mixes ports. Therefore some magic has to happen.
The memory consumption is: (1 byte (state) + 8 byte (mapping) + 8*6 (config)) per used bank. This means if a single PCINT is used on a pin we need 57 bytes of additional memory.
Additionally, each cpu needs an
atmega_pcint.h
for the specific PCINT mapping.Issues/PRs references
See also #7610, #8993, #9159. This is an follow up PR for #11114
Testing
waspmote-pro
) @maribu double checked config against the data sheet (no one has the board)mega-xplained
) @TorbenPetersen tested with the INGA boardarduino-mega2560
) PCINT9 and PCINT10 are not working yetjiminy-mega256rfr2
) @maribu double checked config against the data sheetarduino-uno
) @maribu tested, works as expectedTesting for non-Arduino boards
tests/periph_gpio
on your avr boardUSEMODULE += atmega_pcint0
, orUSEMODULE += atmega_pcint
.init_int
andenable_int
test if interrupts are correctly fired for a couple of pins.Testing for Arduino Uno and Arduino Mega2560
Flash and run the test added in this PR.
Update 1: Added TODO for testing
Update 2: Elaborated on testing
Update 3: Added instructions for testing on Arduino boards, added test results