port_driver.h File Reference


Detailed Description

XMEGA I/O Port driver header file.

This file contains the function prototypes and enumerator definitions for various configuration parameters for the XMEGA I/O Port driver.

This driver is intended for rapid prototyping and documentation purposes for getting started with the XMEGA I/O Ports. The driver is not optimized for speed or size. However, functions that are just a few lines of code are written as macros to eliminate function call overhead. When using these macros it is important to use the correct data type for the arguments, as this is not checked by the compiler.

Application note:
AVR1313: Using the XMEGA I/O Pins and External Interrupts
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Revision
1569
Date
2008-04-22 13:03:43 +0200 (ti, 22 apr 2008)

Copyright (c) 2008, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file port_driver.h.

#include "avr_compiler.h"

Include dependency graph for port_driver.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define PORT_ClearInterruptFlags(_port, _bitMask)   ( (_port)->INTFLAGS = _bitMask )
 This macro clears interrupt flags, given by a bit mask, for an I/O port or a virtual port.
#define PORT_ClearOutputBit(_port, _bitPosition)   ( (_port)->OUT = (_port)->OUT & ~(1 << _bitPosition) )
 This macro clears a bit in the OUT register of an I/O port or virtual port.
#define PORT_ClearPins(_port, _clearMask)   ( (_port)->OUTCLR = _clearMask )
 Set the output value of a set of I/O pins to logic low.
#define PORT_GetInterruptFlags(_port, _bitMask)   ( (_port)->INTFLAGS & _bitMask )
 This macro returns the current state of the interrupt flags, given by a bit mask, for an I/O port or a virtual port.
#define PORT_GetPortValue(_port)   ( (_port)->IN )
 This macro returns the current logic value of the port or virtual port.
#define PORT_SetDirection(_port, _directionMask)   ( (_port)->DIR = _directionMask )
 This macro sets the data direction for all I/O pins in the port or the virtual port.
#define PORT_SetOutputBit(_port, _bitPosition)   ( (_port)->OUT = (_port)->OUT | (1 << _bitPosition) )
 This macro sets a bit in the OUT register of an I/O port or virtual port.
#define PORT_SetOutputValue(_port, _outValue)   ( (_port)->OUT = _outValue )
 This macro sets the output value/logic level of all pins in the I/O port or virtual port.
#define PORT_SetPinAsInput(_port, _bitPosition)   ( (_port)->DIR = (_port)->DIR & ~(1 << _bitPosition) )
 This macro configures a pin in an I/O port or virtual port as an input.
#define PORT_SetPinAsOutput(_port, _bitPosition)   ( (_port)->DIR = (_port)->DIR | (1 << _bitPosition) )
 This macro configures a pin in an I/O port or virtual port as an output.
#define PORT_SetPins(_port, _setMask)   ( (_port)->OUTSET = _setMask )
 Set the output value of a set of I/O pins to logic high.
#define PORT_SetPinsAsInput(_port, _inputMask)   ( (_port)->DIRCLR = _inputMask )
 Sets the data direction of a set of pins to input.
#define PORT_SetPinsAsOutput(_port, _outputMask)   ( (_port)->DIRSET = _outputMask )
 Sets the data direction of a set of pins to output.
#define PORT_ToggleDirection(_port, _toggleMask)   ( (_port)->DIRTGL = _toggleMask )
 Toggle the data direction of a set of pins.
#define PORT_TogglePins(_port, _toggleMask)   ( (_port)->OUTTGL = _toggleMask )
 Toggle the output value of a set of I/O pins.

Functions

void PORT_ConfigureInterrupt0 (PORT_t *port, PORT_INT0LVL_t intLevel, uint8_t pinMask)
 Configures interrupt 0.
void PORT_ConfigureInterrupt1 (PORT_t *port, PORT_INT1LVL_t intLevel, uint8_t pinMask)
 Configures interrupt 1.
void PORT_ConfigurePins (PORT_t *port, uint8_t pinMask, uint8_t slewRateEnable, uint8_t invertEnable, PORT_OPC_t opc, PORT_ISC_t isc)
 This function changes the configuration of a set of pins.
void PORT_MapVirtualPort0 (PORTCFG_VP0MAP_t realPort)
 Maps a real port to virtual port 0.
void PORT_MapVirtualPort1 (PORTCFG_VP1MAP_t realPort)
 Maps a real port to virtual port 1.
void PORT_MapVirtualPort2 (PORTCFG_VP2MAP_t realPort)
 Maps a real port to virtual port 2.
void PORT_MapVirtualPort3 (PORTCFG_VP3MAP_t realPort)
 Maps a real port to virtual port 3.


Define Documentation

#define PORT_ClearInterruptFlags ( _port,
_bitMask   )     ( (_port)->INTFLAGS = _bitMask )

This macro clears interrupt flags, given by a bit mask, for an I/O port or a virtual port.

/note This macro can be used for both I/O ports and virtual ports.

Parameters:
_port Pointer to the PORT_t or VPORT_t instance.
_bitMask Bit mask for interrupt flags to clear.

Definition at line 201 of file port_driver.h.

#define PORT_ClearOutputBit ( _port,
_bitPosition   )     ( (_port)->OUT = (_port)->OUT & ~(1 << _bitPosition) )

This macro clears a bit in the OUT register of an I/O port or virtual port.

Note:
This macro is especially efficient with virtual ports, since only one CBI instruction is invoked.
Parameters:
_port Pointer to the PORT_t or VPORT_t instance.
_bitPosition Position of bit to cleared.

Definition at line 227 of file port_driver.h.

#define PORT_ClearPins ( _port,
_clearMask   )     ( (_port)->OUTCLR = _clearMask )

Set the output value of a set of I/O pins to logic low.

This macro sets the output value of a set of I/O pins to logic low. (Unless inverted I/O has been enabled for the pins) It does not alter the pins not specified in the bit mask.

Parameters:
_port Pointer to the PORT_t instance.
_clearMask The bit mask of pins to set to logic low level.

Definition at line 152 of file port_driver.h.

#define PORT_GetInterruptFlags ( _port,
_bitMask   )     ( (_port)->INTFLAGS & _bitMask )

This macro returns the current state of the interrupt flags, given by a bit mask, for an I/O port or a virtual port.

/note This macro can also be used to access virtual ports.

Parameters:
_port Pointer to the PORT_t or VPORT_t instance.
_bitMask Bit mask for interrupt flags to read.
Returns:
The state of the interrupt flags.

Definition at line 189 of file port_driver.h.

#define PORT_GetPortValue ( _port   )     ( (_port)->IN )

This macro returns the current logic value of the port or virtual port.

/note This macro can also be used to access virtual ports.

Parameters:
_port Pointer to the PORT_t or VPORT_t instance.
Returns:
The current logic state of the port.

Definition at line 176 of file port_driver.h.

#define PORT_SetDirection ( _port,
_directionMask   )     ( (_port)->DIR = _directionMask )

This macro sets the data direction for all I/O pins in the port or the virtual port.

/note This macro can also be used to access virtual ports.

Parameters:
_port Pointer to the PORT_t or VPORT_t instance.
_directionMask The direction setting mask. The direction for pin n in the port is controlled by bit n. A 0 means input. A 1 means output.

Definition at line 75 of file port_driver.h.

#define PORT_SetOutputBit ( _port,
_bitPosition   )     ( (_port)->OUT = (_port)->OUT | (1 << _bitPosition) )

This macro sets a bit in the OUT register of an I/O port or virtual port.

Note:
This macro is especially efficient with virtual ports, since only one SBI instruction is invoked.
Parameters:
_port Pointer to the PORT_t or VPORT_t instance.
_bitPosition Position of bit to set.

Definition at line 214 of file port_driver.h.

#define PORT_SetOutputValue ( _port,
_outValue   )     ( (_port)->OUT = _outValue )

This macro sets the output value/logic level of all pins in the I/O port or virtual port.

/note This macro can also be used to access virtual ports.

Parameters:
_port Pointer to the PORT_t or VPORT_t instance.
_outValue The output value. Bit n in this parameter corresponds to pin n of the port.

Definition at line 126 of file port_driver.h.

#define PORT_SetPinAsInput ( _port,
_bitPosition   )     ( (_port)->DIR = (_port)->DIR & ~(1 << _bitPosition) )

This macro configures a pin in an I/O port or virtual port as an input.

Note:
This macro is especially efficient with virtual ports, since only one CBI instruction is invoked.
Parameters:
_port Pointer to the PORT_t or VPORT_t instance.
_bitPosition Position of bit to set as input.

Definition at line 253 of file port_driver.h.

#define PORT_SetPinAsOutput ( _port,
_bitPosition   )     ( (_port)->DIR = (_port)->DIR | (1 << _bitPosition) )

This macro configures a pin in an I/O port or virtual port as an output.

Note:
This macro is especially efficient with virtual ports, since only one SBI instruction is invoked.
Parameters:
_port Pointer to the PORT_t or VPORT_t instance.
_bitPosition Position of bit to set as output.

Definition at line 240 of file port_driver.h.

#define PORT_SetPins ( _port,
_setMask   )     ( (_port)->OUTSET = _setMask )

Set the output value of a set of I/O pins to logic high.

This macro sets the output value of a set of I/O pins to logic high. (Unless inverted I/O has been enabled for the pins) It does not alter the pins not specified in the bit mask.

Parameters:
_port Pointer to the PORT_t instance.
_setMask The bit mask of pins to set to logic high level.

Definition at line 139 of file port_driver.h.

#define PORT_SetPinsAsInput ( _port,
_inputMask   )     ( (_port)->DIRCLR = _inputMask )

Sets the data direction of a set of pins to input.

This macro sets the data direction of the selected port pins to input without altering the data direction of the other pins in that port.

Parameters:
_port Pointer to the PORT_t instance.
_inputMask A bit mask of the pins to set as input. A one in bit location n will configure pin n as input.

Definition at line 101 of file port_driver.h.

#define PORT_SetPinsAsOutput ( _port,
_outputMask   )     ( (_port)->DIRSET = _outputMask )

Sets the data direction of a set of pins to output.

This macro sets the data direction of the selected port pins to output without altering the data direction of the other pins in that port.

Parameters:
_port Pointer to the PORT_t instance.
_outputMask A bit mask of the pins to set as output. A one in bit location n will configure pin n as output.

Definition at line 88 of file port_driver.h.

#define PORT_ToggleDirection ( _port,
_toggleMask   )     ( (_port)->DIRTGL = _toggleMask )

Toggle the data direction of a set of pins.

This macro toggles the data direction of the selected port pins without altering the data direction of the other pins in that port.

Parameters:
_port Pointer to the PORT_t instance.
_toggleMask A bit mask of the pins on which to toggle input direction.

Definition at line 113 of file port_driver.h.

#define PORT_TogglePins ( _port,
_toggleMask   )     ( (_port)->OUTTGL = _toggleMask )

Toggle the output value of a set of I/O pins.

This macro toggles the output value of a set of I/O pins. It does not alter the output value of pins not specified in the bit mask.

Parameters:
_port Pointer to the PORT_t instance.
_toggleMask The bit mask of pins to toggle.

Definition at line 164 of file port_driver.h.


Function Documentation

void PORT_ConfigureInterrupt0 ( PORT_t *  port,
PORT_INT0LVL_t  intLevel,
uint8_t  pinMask 
)

Configures interrupt 0.

This function configures interrupt 0 to be associated with a set of pins and sets the desired interrupt level.

Parameters:
port The port to configure.
intLevel The desired interrupt level for port interrupt 0.
pinMask A mask that selects the pins to associate with port interrupt 0.

Definition at line 80 of file port_driver.c.

00083 {
00084         port->INTCTRL = ( port->INTCTRL & ~PORT_INT0LVL_gm ) | intLevel;
00085         port->INT0MASK = pinMask;
00086 }

void PORT_ConfigureInterrupt1 ( PORT_t *  port,
PORT_INT1LVL_t  intLevel,
uint8_t  pinMask 
)

Configures interrupt 1.

This function configures interrupt 1 to be associated with a set of pins and sets the desired interrupt level.

Parameters:
port The port to configure.
intLevel The desired interrupt level for port interrupt 1.
pinMask A mask that selects the pins to associate with port interrupt 1.

Definition at line 98 of file port_driver.c.

00101 {
00102         port->INTCTRL = ( port->INTCTRL & ~PORT_INT1LVL_gm ) | intLevel;
00103         port->INT1MASK = pinMask;
00104 }

void PORT_ConfigurePins ( PORT_t *  port,
uint8_t  pinMask,
uint8_t  slewRateEnable,
uint8_t  invertEnable,
PORT_OPC_t  opc,
PORT_ISC_t  isc 
)

This function changes the configuration of a set of pins.

Parameters:
port The port.
pinMask A bit mask that selects the pins to configure.
slewRateEnable Enable/disable slew rate control.
invertEnable Enable/disable I/O inversion.
opc Output/Pull Configuration.
isc Input/Sense Configuration.

Definition at line 117 of file port_driver.c.

00123 {
00124         /* Build pin control register value. */
00125         uint8_t temp = (uint8_t) opc |
00126                        isc |
00127                        (slewRateEnable ? PORT_SRLEN_bm : 0) |
00128                        (invertEnable ? PORT_INVEN_bm : 0);
00129 
00130         /* Configure the pins in one atomic operation. */
00131 
00132         /* Save status register. */
00133         uint8_t sreg = SREG;
00134 
00135         cli();
00136         PORTCFG.MPCMASK = pinMask;
00137         port->PIN0CTRL = temp;
00138 
00139         /* Restore status register. */
00140         SREG = sreg;
00141 }

void PORT_MapVirtualPort0 ( PORTCFG_VP0MAP_t  realPort  ) 

Maps a real port to virtual port 0.

This function maps a real port to virtual port 0 to make some of the registers available in I/O space.

Parameters:
realPort Selects the real port to map to virtual port 0.

Definition at line 151 of file port_driver.c.

00152 {
00153         PORTCFG.VPCTRLA = ( PORTCFG.VPCTRLA & ~PORTCFG_VP0MAP_gm ) | realPort;
00154 }

void PORT_MapVirtualPort1 ( PORTCFG_VP1MAP_t  realPort  ) 

Maps a real port to virtual port 1.

This function maps a real port to virtual port 1 to make some of the registers available in I/O space.

Parameters:
realPort Selects the real port to map to virtual port 1.

Definition at line 164 of file port_driver.c.

00165 {
00166         PORTCFG.VPCTRLA = ( PORTCFG.VPCTRLA & ~PORTCFG_VP1MAP_gm ) | realPort;
00167 }

void PORT_MapVirtualPort2 ( PORTCFG_VP2MAP_t  realPort  ) 

Maps a real port to virtual port 2.

This function maps a real port to virtual port 2 to make some of the registers available in I/O space.

Parameters:
realPort Selects the real port to map to virtual port 2.

Definition at line 177 of file port_driver.c.

00178 {
00179         PORTCFG.VPCTRLB = ( PORTCFG.VPCTRLB & ~PORTCFG_VP2MAP_gm ) | realPort;
00180 }

void PORT_MapVirtualPort3 ( PORTCFG_VP3MAP_t  realPort  ) 

Maps a real port to virtual port 3.

This function maps a real port to virtual port 3 to make some of the registers available in I/O space.

Parameters:
realPort Selects the real port to map to virtual port 3.

Definition at line 190 of file port_driver.c.

00191 {
00192         PORTCFG.VPCTRLB = ( PORTCFG.VPCTRLB & ~PORTCFG_VP3MAP_gm ) | realPort;
00193 }


Generated on Fri Sep 4 16:08:56 2009 for AVR1606: Calibration of the internal RC oscillator of XMEGA by  doxygen 1.5.6