00001
00039 #ifndef REGS_XMEGA_PORT_H_INCLUDED
00040 #define REGS_XMEGA_PORT_H_INCLUDED
00041
00042 #include <chip/memory-map.h>
00043 #include <io.h>
00044
00051
00052
00053 #define PORT_DIR 0x00 //!< Data Direction
00054 #define PORT_DIRSET 0x01 //!< Data Direction Set
00055 #define PORT_DIRCLR 0x02 //!< Data Direction Clear
00056 #define PORT_DIRTGL 0x03 //!< Data Direction Toggle
00057 #define PORT_OUT 0x04 //!< Data Output Value
00058 #define PORT_OUTSET 0x05 //!< Data Output Value Set
00059 #define PORT_OUTCLR 0x06 //!< Data Output Value Clear
00060 #define PORT_OUTTGL 0x07 //!< Data Output Value Toggle
00061 #define PORT_IN 0x08 //!< Data Input Value
00062 #define PORT_INTCTRL 0x09 //!< Interrupt Control
00063 #define PORT_INT0MASK 0x0A //!< Interrupt 0 Mask
00064 #define PORT_INT1MASK 0x0B //!< Interrupt 1 Mask
00065 #define PORT_INTFLAGS 0x0C //!< Interrupt Flags
00066 #define PORT_PIN0CTRL 0x10 //!< Pin 0 Configuration
00067 #define PORT_PIN1CTRL 0x11 //!< Pin 1 Configuration
00068 #define PORT_PIN2CTRL 0x12 //!< Pin 2 Configuration
00069 #define PORT_PIN3CTRL 0x13 //!< Pin 3 Configuration
00070 #define PORT_PIN4CTRL 0x14 //!< Pin 4 Configuration
00071 #define PORT_PIN5CTRL 0x15 //!< Pin 5 Configuration
00072 #define PORT_PIN6CTRL 0x16 //!< Pin 6 Configuration
00073 #define PORT_PIN7CTRL 0x17 //!< Pin 7 Configuration
00074
00075
00077
00078 #define PORT_INTCTRL_INT0LVL_START 0 //!< Interrupt 0 Level
00079 #define PORT_INTCTRL_INT0LVL_SIZE 2 //!< Interrupt 0 Level
00080 #define PORT_INTCTRL_INT1LVL_START 2 //!< Interrupt 1 Level
00081 #define PORT_INTCTRL_INT1LVL_SIZE 2 //!< Interrupt 1 Level
00082
00083
00085
00086 #define PORT_INTFLAGS_INT0IF_BIT 0 //!< Interrupt 0 Flag
00087 #define PORT_INTFLAGS_INT1IF_BIT 1 //!< Interrupt 1 Flag
00088
00089
00091
00092 #define PORT_PINCTRL_ISC_START 0 //!< Input/Sense Configuration
00093 #define PORT_PINCTRL_ISC_SIZE 3 //!< Input/Sense Configuration
00094 #define PORT_PINCTRL_OPC_START 3 //!< Output and Pull Configuration
00095 #define PORT_PINCTRL_OPC_SIZE 3 //!< Output and Pull Configuration
00096 #define PORT_PINCTRL_INVEN_BIT 6 //!< Inverted I/O Enable
00097 #define PORT_PINCTRL_SRLEN_BIT 7 //!< Slew Rate Limit Enable
00098
00099
00101
00102 #define PORT_PINCTRL_TOTEM 0x0 //!< Totempole/(N/A)
00103 #define PORT_PINCTRL_BUSKEEPER 0x1 //!< Totempole/Bus keeper
00104 #define PORT_PINCTRL_PULLDOWN 0x2 //!< Totempole/Pull-down (on input)
00105 #define PORT_PINCTRL_PULLUP 0x3 //!< Totempole/Pull-up (on input)
00106 #define PORT_PINCTRL_WIREDOR 0x4 //!< Wired OR/(N/A)
00107 #define PORT_PINCTRL_WIREDAND 0x5 //!< Wired AND/(N/A)
00108 #define PORT_PINCTRL_WIREDORPULL 0x6 //!< Wired OR/Pull-down
00109 #define PORT_PINCTRL_WIREDANDPULL 0x7 //!< Wired AND/Pull-up
00110
00111
00113
00114 #define PORT_PINCTRL_ISC_BOTHEDGES 0x0 //!< Sense Both Edges
00115 #define PORT_PINCTRL_ISC_RISING 0x1 //!< Sense Rising Edge
00116 #define PORT_PINCTRL_ISC_FALLING 0x2 //!< Sense Falling Edge
00117 #define PORT_PINCTRL_ISC_LEVEL 0x3 //!< Sense Low Level
00118 #define PORT_PINCTRL_ISC_INPUT_DISABLE 0x7 //!< Input Buffer Disabled
00119
00120
00122
00123
00124 #define PORT_BIT(name) \
00125 (1U << PORT_##name##_BIT)
00126
00127 #define PORT_BF(name, value) \
00128 ((value) << PORT_##name##_START)
00129
00130 #define PORT_BFMASK(name) \
00131 (((1U << %s_##name##_SIZE) - 1) << %s_##name##_START)
00132
00133 #define PORT_BFEXT(name, regval) \
00134 (((regval) >> PORT_##name##_START) \
00135 & ((1U << PORT_##name##_SIZE) - 1))
00136
00137 #define PORT_BFINS(name, value, regval) \
00138 (((regval) & ~(((1U << PORT_##name##_SIZE) - 1) \
00139 << PORT_##name##_START)) \
00140 | PORT_BF(name, value))
00141
00142
00144
00145
00146 #define port_read_reg(base, reg) \
00147 mmio_read8((void *)((uintptr_t)(base) + PORT_##reg))
00148
00149 #define port_write_reg(base, reg, value) \
00150 mmio_write8((void *)((uintptr_t)(base) + PORT_##reg), (value))
00151
00152
00154 #endif