bugAVR C Runtime Library - Bugs: bug #37848, Add arrays to some Xmega...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #37848: Add arrays to some Xmega peripheral structures

Submitter:  Erik Walthinsen <omega>
Submitted:  Sat 01 Dec 2012 01:37:33 AM UTC
   
 
Category:  Feature Request Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Header files
Status:  None Assigned to:  None
Percent Complete:  0% Open/Closed:  Open
Release:  1.8.0 Fixed Release:  None

Sat 01 Dec 2012 01:37:33 AM UTC, original submission:  

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.

Erik Walthinsen <omega>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #27006:  xunion.py added by omega (2KiB - text/x-python)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by omega (Submitted the item)
  •  

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-12-01 omega Attached File- Added xunion.py, #27006

    Back to the top

    Powered by Savane 3.13-5884.
    Corresponding source code