Nut/OS  5.0.5
API Reference
XgNutArchCm3Lpc177x_8xGpio

Defines

#define NUTGPIOPORT_MAX   NUTGPIO_PORT5+1

Functions

uint32_t GpioPinConfigGet (int bank, int bit)
 Get pin configuration.
int GpioPortConfigSet (int bank, uint32_t 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.
int GpioIrqStatus (GPIO_SIGNAL *sig, int bit)
 Query the status of a specified GPIO interrupt.
int GpioIrqSetMode (GPIO_SIGNAL *sig, int bit, int mode)
 Set the GPIO interrupt mode for a pin.

Define Documentation

#define NUTGPIOPORT_MAX   NUTGPIO_PORT5+1

Function Documentation

int GpioPortConfigSet ( int  bank,
uint32_t  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(). If NUTDEBUG is enabled accessing an undefined port will rise an assertion.
Port P0-7 .. P0-9 pins (W-Mode pins) are a little bit special and need bit 7 always be set for normal operation
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 __IO, _BV, CM3REG, GPIO_BANKID2BASE, GPIO_CFG_DEBOUNCE, GPIO_CFG_INVERT, GPIO_CFG_MULTIDRIVE, GPIO_CFG_OUTPUT, GPIO_CFG_PERIPHERAL_MASK, GPIO_CFG_PERIPHERAL_POS, GPIO_CFG_PULLDOWN, GPIO_CFG_PULLUP, GPIO_CFG_REPEATER, IOCON_ADMODE, IOCON_DACEN, IOCON_FUNC_BITMASK, IOCON_GLITCH_FILTER, IOCON_HYSTERESIS, IOCON_INVERTED, IOCON_MODE_PULLDOWN, IOCON_MODE_PULLUP, IOCON_MODE_REPEATER, IOCON_ODMODE, IOCON_SLEW, LPC_IOCON_BASE, NUTASSERT, NUTGPIO_PORT0, NUTGPIO_PORT5, and NUTGPIOPORT_MAX.

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 __IO, _BV, CM3BBREG, GPIO_BANKID2BASE, GPIO_CFG_DEBOUNCE, GPIO_CFG_INVERT, GPIO_CFG_MULTIDRIVE, GPIO_CFG_OUTPUT, GPIO_CFG_PERIPHERAL_MASK, GPIO_CFG_PERIPHERAL_POS, GPIO_CFG_PULLDOWN, GPIO_CFG_PULLUP, GPIO_CFG_REPEATER, IOCON_ADMODE, IOCON_ADMODE_BITMASK, IOCON_DACEN, IOCON_DACEN_BITMASK, IOCON_FUNC_BITMASK, IOCON_GLITCH_FILTER, IOCON_GLITCH_FILTER_BITMASK, IOCON_HYSTERESIS, IOCON_HYSTERESIS_BITMASK, IOCON_I2C_MODE_BITMASK, IOCON_INVERT_BITMASK, IOCON_INVERTED, IOCON_MODE_BITMASK, IOCON_MODE_PULLDOWN, IOCON_MODE_PULLUP, IOCON_MODE_REPEATER, IOCON_ODMODE, IOCON_ODMODE_BITMASK, IOCON_SLEW, IOCON_SLEW_BITMASK, LPC_IOCON_BASE, NUTASSERT, NUTGPIO_PORT0, NUTGPIOPORT_MAX, and rc.

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().

On the LPC17xx interrupts are triggered on rising, falling or both edges. Level triggering 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 a rising edge 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_GPIO0, 4, PinChange, NULL);
     GpioIrqSetMode(&sig_GPIO0, 4, NUT_IRQMODE_RISINGEDGE);
     GpioIrqEnable(&sig_GPIO0, 4);
     ...
 }
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_vector, GPIO_VECTOR::iov_arg, GPIO_VECTOR::iov_handler, IRQ_HANDLER::ir_handler, LPC_GPIOINT, malloc(), memset(), NULL, NutIrqEnable(), NutRegisterIrqHandler(), rc, and sig_PIO.

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.

int GpioIrqStatus ( GPIO_SIGNAL sig,
int  bit 
)

Query the status of a specified GPIO interrupt.

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

Parameters:
sigInterrupt to query
bitBit number of the specified bank/port.
Returns:
0 if interrupt is disabled, 1 of enabled

References GPIO_SIGNAL::ios_ctl, and NUT_IRQCTL_STATUS.

int GpioIrqSetMode ( GPIO_SIGNAL sig,
int  bit,
int  mode 
)

Set the GPIO interrupt mode for a pin.

Parameters:
sigInterrupt to configure.
bitBit number of the specified bank/port.
modeone of the following modes: NUT_IRQMODE_RISINGEDGE, NUT_IRQMODE_FALLINGEDGE, NUT_IRQMODE_BOTHEDGE, NUT_IRQMODE_NONE,
Returns:
0 on success, -1 otherwise.

References GPIO_SIGNAL::ios_ctl, and NUT_IRQCTL_SETMODE.