Nut/OS  5.0.5
API Reference
gpio_nutos.c File Reference
#include <arch/avr32.h>
#include <stdlib.h>
#include <string.h>
#include <dev/gpio.h>
#include <avr32/io.h>
Include dependency graph for gpio_nutos.c:

Defines

#define PERIPHERALS_MASK   (GPIO_CFG_PERIPHERAL0|GPIO_CFG_PERIPHERAL1|GPIO_CFG_PERIPHERAL2|GPIO_CFG_PERIPHERAL3)

Functions

int GpioPinGet (int bank, int bit)
 Get pin level.
void GpioPinSetLow (int bank, int bit)
 Set pin level to low.
void GpioPinSetHigh (int bank, int bit)
 Set pin level to high.
void GpioPinSet (int bank, int bit, int value)
 Set pin level.
unsigned int GpioPortGet (int bank)
 Get all pin levels of a specified bank/port.
void GpioPortSetLow (int bank, unsigned int mask)
 Set multiple pin levels of a bank/port to low.
void GpioPortSetHigh (int bank, unsigned int mask)
 Set multiple pin levels of a bank/port to high.
void GpioPortSet (int bank, unsigned int value)
 Set all pin levels of a bank/port.
uint32_t GpioPinConfigGet (int bank, int bit)
 Get pin configuration.
int GpioPortConfigSet (int bank, unsigned int mask, uint32_t flags)
 Set port wide pin configuration.
int GpioPinConfigSet (int bank, int bit, uint32_t flags)
 Set pin configuration.
int GpioRegisterIrqHandler (GPIO_SIGNAL *sig, int bit, void(*handler)(void *), void *arg)
 Register a GPIO pin interrupt handler.
int GpioIrqEnable (GPIO_SIGNAL *sig, int bit)
 Enable a specified GPIO interrupt.
int GpioIrqDisable (GPIO_SIGNAL *sig, int bit)
 Disable a specified GPIO interrupt.

Define Documentation

#define PERIPHERALS_MASK   (GPIO_CFG_PERIPHERAL0|GPIO_CFG_PERIPHERAL1|GPIO_CFG_PERIPHERAL2|GPIO_CFG_PERIPHERAL3)

Referenced by GpioPortConfigSet().


Function Documentation

int GpioPinGet ( int  bank,
int  bit 
)

Get pin level.

Parameters:
bankGPIO bank/port number.
bitBit number of the specified bank/port.
Returns:
1 if the pin level is high. 0 is returned if the pin level is low or if the pin is undefined.
void GpioPinSetLow ( int  bank,
int  bit 
)

Set pin level to low.

Trying to set undefined pins is silently ignored.

Parameters:
bankGPIO bank/port number.
bitBit number of the specified bank/port.
void GpioPinSetHigh ( int  bank,
int  bit 
)

Set pin level to high.

Trying to set undefined pins is silently ignored.

Parameters:
bankGPIO bank/port number.
bitBit number of the specified bank/port.
void GpioPinSet ( int  bank,
int  bit,
int  value 
)

Set pin level.

Trying to set undefined pins is silently ignored.

Parameters:
bankGPIO bank/port number.
bitBit number of the specified bank/port.
valueLevel, 0 for low or any other value for high.
unsigned int GpioPortGet ( int  bank)

Get all pin levels of a specified bank/port.

Parameters:
bankGPIO bank/port number.
Returns:
Pin levels. 0 is returned for unknown banks and pins.
void GpioPortSetLow ( int  bank,
unsigned int  mask 
)

Set multiple pin levels of a bank/port to low.

Parameters:
bankGPIO bank/port number.
maskPin levels are set to low, if the corresponding bit in this mask is 1.
Returns:
Levels.
void GpioPortSetHigh ( int  bank,
unsigned int  mask 
)

Set multiple pin levels of a bank/port to high.

Trying to set undefined ports is silently ignored.

Parameters:
bankGPIO bank/port number.
maskPin levels are set to high, if the corresponding bit in this mask is 1.
void GpioPortSet ( int  bank,
unsigned int  value 
)

Set all pin levels of a bank/port.

This routine can be used to simultaneously set all pins of a specific port. However, in some implementations the high bit values will be set before the low bit values. If this is a problem, you should use GpioPortSetHigh() and GpioPortSetLow().

Parameters:
bankGPIO bank/port number.
valuePin levels are set to high, if the corresponding bit in this mask is 1. All other pin levels are set to low.
uint32_t GpioPinConfigGet ( int  bank,
int  bit 
)

Get pin configuration.

Parameters:
bankGPIO bank/port number.
bitBit number of the specified bank/port.
Returns:
Attribute flags of the pin.

References _BV, GPIO_CFG_DEBOUNCE, GPIO_CFG_DISABLED, GPIO_CFG_OUTPUT, GPIO_CFG_PERIPHERAL0, GPIO_CFG_PERIPHERAL1, GPIO_CFG_PERIPHERAL2, GPIO_CFG_PERIPHERAL3, GPIO_CFG_PULLUP, and rc.

int GpioPortConfigSet ( int  bank,
unsigned int  mask,
uint32_t  flags 
)

Set port wide pin configuration.

Note:
This function does not check for undefined ports and pins or invalid attributes. If this is required, use GpioPinConfigSet().
Parameters:
bankGPIO bank/port number.
maskThe given attributes are set for a specific pin, if the corresponding bit in this mask is 1.
flagsAttribute flags to set.
Returns:
Always 0.

References GPIO_CFG_DEBOUNCE, GPIO_CFG_DISABLED, GPIO_CFG_OUTPUT, GPIO_CFG_PULLUP, and PERIPHERALS_MASK.

int GpioPinConfigSet ( int  bank,
int  bit,
uint32_t  flags 
)

Set pin configuration.

Applications may also use this function to make sure, that a specific attribute is available for a specific pin.

Note:
GPIO pins are typically initialized to a safe state after power up. This routine is not able to determine the consequences of changing pin configurations. In the worst case you may permanently damage your hardware by bad pin settings.
Parameters:
bankGPIO bank/port number.
bitBit number of the specified bank/port.
flagsAttribute flags.
Returns:
0 if all attributes had been set, -1 otherwise.

References _BV, GpioPinConfigGet(), and GpioPortConfigSet().

Here is the call graph for this function:

int GpioRegisterIrqHandler ( GPIO_SIGNAL sig,
int  bit,
void(*)(void *)  handler,
void *  arg 
)

Register a GPIO pin interrupt handler.

Generating interrupts on GPIO pin changes is not supported on all platforms. In this case dedicated external interrupt pins may be used with NutRegisterIrqHandler().

Interrupts are triggered on rising and falling edges. Level triggering or triggering on specific edges is not supported.

After registering, interrupts are disabled. Calling GpioIrqEnable() is required to activate the interrupt.

The following code fragment registers an interrupt handler which is called on each change of bit 4 of the first GPIO port:

 #include <dev/gpio.h>

 static void PinChange(void *arg)
 {
     ...
 }

 {
     ...
     GpioPinConfigSet(0, 4, GPIO_CFG_PULLUP);
     GpioRegisterIrqHandler(&sig_GPIO, 4, PinChange, NULL);
     GpioIrqEnable(&sig_GPIO, 30);
     ...
 }
Parameters:
sigBank/port interrupt to be associated with this handler.
bitBit number of the specified bank/port.
handlerThis routine will be called by Nut/OS, when the specified pin changes its state.
argArgument to be passed to the interrupt handler routine.
Returns:
0 on success, -1 otherwise.

References GPIO_SIGNAL::ios_handler, GPIO_SIGNAL::ios_sig, GPIO_SIGNAL::ios_vector, GPIO_VECTOR::iov_arg, GPIO_VECTOR::iov_handler, malloc(), memset(), NutIrqEnable(), NutRegisterIrqHandler(), and rc.

Here is the call graph for this function:

int GpioIrqEnable ( GPIO_SIGNAL sig,
int  bit 
)

Enable a specified GPIO interrupt.

A related interrupt handler must have been registered before calling this function. See GpioRegisterIrqHandler().

Parameters:
sigInterrupt to enable.
bitBit number of the specified bank/port.
Returns:
0 on success, -1 otherwise.

References GPIO_SIGNAL::ios_ctl, NULL, and NUT_IRQCTL_ENABLE.

int GpioIrqDisable ( GPIO_SIGNAL sig,
int  bit 
)

Disable a specified GPIO interrupt.

Parameters:
sigInterrupt to disable.
bitBit number of the specified bank/port.
Returns:
0 on success, -1 otherwise.

References GPIO_SIGNAL::ios_ctl, NULL, and NUT_IRQCTL_DISABLE.