avr_io(3avr)

πŸ’– avr_io πŸ’–

okay bestie, so this is avr_io, page 3avr from the AVR-LibC manual β€” and it's literally THE gateway to <avr/io.h>, aka the AVR device-specific IO definitions. if you're writing bare-metal AVR code and you've ever typed #include <avr/io.h> and just vibed, this is the page explaining what your girl is actually doing for you. ✨


🌸 SYNOPSIS 🌸

Macros

#define _PROTECTED_WRITE(reg,  value)
#define _PROTECTED_WRITE_SPM(reg,  value)

Detailed Description

#include <avr/io.h>

so here's the tea β˜• β€” this header pulls in the appropriate IO definitions for whichever device you told the compiler about with the -mmcu= compiler command-line switch. it does that by diverting you to the matching <avr/ioXXXX.h> file, and heads up: you should never include that one directly. rookie move, don't do it. πŸ™ˆ

some register names that are the same across all AVR devices live right inside <avr/common.h>, which gets included by <avr/io.h> β€” but most of the good stuff comes from that respective include file. it's giving curated-for-your-chip. πŸ’…

also, no cap, this file always includes the following files:

#include <avr/sfr_defs.h>
#include <avr/portpins.h>
#include <avr/common.h>
#include <avr/version.h>

peep <avr/sfr_defs.h>: Special function registers for more details on that header file. 🫢

included in all this: definitions of the IO register set plus their respective bit values, exactly as specified in the Atmel documentation. but listen β€” there are inconsistencies in naming conventions, so even identical functions sometimes get different names on different devices. not a bug, it's just ✨how it is✨.

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

and finally, these macros are defined:

  • RAMEND β€” the last on-chip RAM address.
  • XRAMEND β€” the last possible RAM location that is addressable. this equals RAMEND for devices that don't allow for external RAM. for devices that DO allow external RAM, this will be larger than RAMEND. main character energy, honestly.
  • 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)

write value value to IO register reg that is protected through the Xmega configuration change protection (CCP) mechanism. this implements the timed sequence that is required for CCP. ⏱️

ngl, the timed sequence part is not a suggestion β€” it's the whole point. that's what this macro is for. 😭

example to modify the CPU clock:

#include <avr/io.h>

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

πŸ¦‹ #define _PROTECTED_WRITE_SPM( reg, value)

write value value to register reg that is protected through the Xmega configuration change protection (CCP) key for self programming (SPM). this implements the timed sequence that is required for CCP. same energy, different key. πŸ”‘

example to modify the CPU clock:

#include <avr/io.h>

_PROTECTED_WRITE_SPM(NVMCTRL_CTRLA, NVMCTRL_CMD_PAGEERASEWRITE_gc);

🌈 Author 🌈

generated automatically by Doxygen for AVR-LibC from the source code. our girl Doxygen did all the typing so nobody had to. πŸ’€βœ¨


okay and that's the whole page, bestie β€” we literally made it to the end. this was avr_io(3avr), brought to you by AVR-LibC, Version 2.2.1. go forth, include <avr/io.h>, and slay. πŸ’…πŸŽ€πŸ‘‘

πŸ“¦ where this page comes from