Skip to content
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

Add support for the rest of the megaAVR 0-series, the tinyAVR 0/1-series, and the new AVR Dx-series, make interrupt safe. #94

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

SpenceKonde
Copy link

These all have the same patterns in register locations, so can use the same formulae for them.

This also switches to using the VPORT registers instead of the PORT registers, which makes setting or clearing a single bit into an atomic, single word, single cycle operation (SBI/CBI), as opposed to requiring a read-modify-write cycle like the PORT.OUT and PORT.DIR registers do, making those operations interrupt safe like they were on classic AVRs, as well as reducing sketch size and executing faster. Taking advantage of the consistent numbering of ports returned by digitalPinToPort() among the cores supporting these parts to get the base register address shrinks the compiled sketch size a touch too.

Non-pins passed to digitalPinToPort() will get back NOT_A_PORT, which is defined as 255, would give base reg of 0x03FC, which falls into one of the many gaps in the register space on these parts as well - so it won't fiddle with some random other peripheral somewhere (as it happens, it's right before where the PORT registers start at 0x0400, which seems fitting for "port -1")

Instead of checking for the single 0-series megaAVR that is most common, check for all tinyAVR 0/1-series, megaAVR 0-series (__AVR_ARCH__103) as well as the Dx series (__AVR_ARCH__=104), since they use the same kind of peripherals
Use the VPORTx registers - should give slightly smaller, faster, atomic code. Previous implementation used the PORTx registers; those are not in the I/O space, so |= and &= were not atomic! They still may not be in all cases (depending on what the compiler is able to optimize away) - but this will transparently take advantage of updates to the macros supplied with the cores which do, if/when they come.
Fix -fpermissive warning
@SpenceKonde
Copy link
Author

Just discovered something: AVR_ARCH is 102, 103, or 104 for the new Dx series parts, not always 104. 103 which is what it is on the tinyAVR/megaAVR 0/1-series as well as 32k Dx parts; these can map all of their flash in the data space at once. 102 is for 64k (two sections), and 104 is for 128k parts (which have to split their flash into 4 sections)

Updated pr to account for this discovery.

@BigGene
Copy link

BigGene commented May 19, 2021

Please add this support for the new AVRs in the next version. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants