avr-libc
avr-libc copied to clipboard
[bug #37848] Add arrays to some Xmega peripheral structures
Sat 01 Dec 2012 02:37:33 AM CET
In developing my product I have a header file that lets me shuffle around all the various pinouts and peripherals to match the generation of PCB I'm running on, as well as utility libraries that operate on peripherals with multiple parallel subsystems (like the 4 capture channels of the timers).
I ended up changing (via a script that's attached) a decent chunk of all the Xmega headers to include unions inside the structs that give array access to common multiple registers:
From:
typedef struct PORT_struct { . . . register8_t reserved_0x0D; register8_t REMAP; /* I/O Port Pin Remap Register / register8_t reserved_0x0F; register8_t PIN0CTRL; / Pin 0 Control Register / register8_t PIN1CTRL; / Pin 1 Control Register / register8_t PIN2CTRL; / Pin 2 Control Register / register8_t PIN3CTRL; / Pin 3 Control Register / register8_t PIN4CTRL; / Pin 4 Control Register / register8_t PIN5CTRL; / Pin 5 Control Register / register8_t PIN6CTRL; / Pin 6 Control Register / register8_t PIN7CTRL; / Pin 7 Control Register */ } PORT_t;
To:
typedef struct PORT_struct { . . . register8_t reserved_0x0D; register8_t REMAP; /* I/O Port Pin Remap Register / register8_t reserved_0x0F; union { struct { register8_t PIN0CTRL; / Pin 0 Control Register / register8_t PIN1CTRL; / Pin 1 Control Register / register8_t PIN2CTRL; / Pin 2 Control Register / register8_t PIN3CTRL; / Pin 3 Control Register / register8_t PIN4CTRL; / Pin 4 Control Register / register8_t PIN5CTRL; / Pin 5 Control Register / register8_t PIN6CTRL; / Pin 6 Control Register / register8_t PIN7CTRL; / Pin 7 Control Register */ }; register8_t PINnCTRL[8]; }; } PORT_t;
This one in particular is highly useful, because I can specify a particular subsystem like:
#define DEBUG_USART USARTC0 #define DEBUG_USART_TX_bp 3
and then do:
DEBUG_USART.PINnCTRL[DEBUG_USART_TX_bp] = PIN_INVEN_bm;
The attached script takes the header filename on the commandline and outputs on stdout the altered header. Obviously this would be better implemented in the primary header conversion script, but that script is still quite opaque to me.
This issue was migrated from https://savannah.nongnu.org/bugs/?37848