avr_io(3)

πŸ“¦ version 2.2.1, in fedora 43, fedora 44, opensuse-leap 16.0

✨ avr_io ✨

okay bestie, welcome to avr_io β€” this is the manual page for avr-libc's big shiny IO header situation, and honestly? it's giving backstage-pass-to-the-whole-microcontroller πŸ’…


🌸 SYNOPSIS 🌸

πŸŽ€ Macros

#define _PROTECTED_WRITE(reg, value)

πŸ’– DESCRIPTION πŸ’–

πŸ¦‹ Detailed Description

#include <avr/io.h>

so like. this header file pulls in the apropriate IO definitions for whatever device you told the compiler about with the -mmcu= compiler command-line switch. (yes, "apropriate" β€” that's the original spelling, we do not touch the spelling, it's part of the lore 🫢)

how does it do that? it diverts to the matching file <avr/ioXXXX.h> β€” and listen, that file should never be included directly, okay? don't do it. no cap. πŸ™ˆ

some register names that are common to all AVR devices are defined right inside <avr/common.h>, which gets included by <avr/io.h>, but most of the juicy details come from the respective include file for your device.

heads up: this file always includes the following files, every single time:
#include <avr/sfr_defs.h>
#include <avr/portpins.h>
#include <avr/common.h>
#include <avr/version.h>

if you want more deets about that first one, go peek at <avr/sfr_defs.h>: Special function registers β€” it explains that header way better than I could rn.

included in all this are definitions of the IO register set and their respective bit values, exactly as specified in the Atmel documentation ✨ but note the inconsistencies in naming conventions β€” like, even identical functions sometimes get different names on different devices. it's a whole thing, we don't question it, we just vibe with it 😭

also included: the specific names you can use for interrupt function definitions, as documented over there in the docs.

and finally, the following macros are defined:

  • RAMEND β€” the last on-chip RAM address πŸ‘‘
  • XRAMEND β€” the last possible RAM location that is addressable. for devices that don't allow external RAM, this equals RAMEND. for devices that do allow external RAM, this will be larger than RAMEND.
  • E2END β€” the last EEPROM address πŸ“
  • FLASHEND β€” the last byte address in the Flash program space πŸ”₯
  • SPM_PAGESIZE β€” for devices with bootloader support, the flash pagesize (in bytes) to be used for the SPM instruction.
  • E2PAGESIZE β€” the size of the EEPROM page.

🌈 Macro Definition Documentation 🌈

πŸ’œ #define _PROTECTED_WRITE(reg, value)

writes value value to IO register reg that is protected through the Xmega configuration change protection (CCP) mechanism. basically it implements the timed sequence that's required for CCP β€” the register is like "you can't just walk in here" and this macro is the bouncer with the clipboard 🫢

here's the example to modify the CPU clock, straight up iconic:

#include <avr/io.h>

_PROTECTED_WRITE(CLK_PSCTRL, CLK_PSADIV0_bm);
_PROTECTED_WRITE(CLK_CTRL, CLK_SCLKSEL0_bm);

⭐ Author ⭐

Generated automatically by Doxygen for avr-libc from the source code. (the robots did this one, we simply say thank you πŸ€–πŸ’–)


okay that's the whole page, ily, go write some embedded code 🧚✨

Version 2.1.0 Β· Sat Jan 29 2022 Β· brought to you by the avr-libc girlies β€” mwah, catch you in the next manpage πŸ’…πŸ’–πŸŒΈ

πŸ“¦ where this page comes from