Introduction
The GPIO module allows software to control the pins of the device directly if the IOC module has been configured to route the GPIO signal to a physical pin (called DIO). Alternatively, pins can be hardware controlled by other peripheral modules. For more information about the IOC module, how to configure physical pins, and how to select between software controlled and hardware controlled, see the IOC API.
The System CPU can access the GPIO module to read the value of any DIO of the device and if the IOC module has been configured such that one or more DIOs are GPIO controlled (software controlled) the System CPU can write these DIOs through the GPIO module.
The IOC module can also be configured to generate events on edge detection and these events can be read and cleared in the GPIO module by the System CPU.
API
The API functions can be grouped like this:
Set and get direction of DIO (output enable):
Write DIO (requires IOC to be configured for GPIO usage):
Set, clear, or toggle DIO (requires IOC to be configured for GPIO usage):
Read DIO (even if IOC is NOT configured for GPIO usage; however, the DIO must be configured for input enable in IOC):
Read or clear events (even if IOC is NOT configured for GPIO usage; however, the DIO must be configured for input enable in IOC):
The IOC API provides two functions for easy configuration of DIOs as GPIO enabled using typical settings. They also serve as examples on how to configure the IOC and GPIO modules for GPIO usage:
§ GPIO_clearDio()
static void GPIO_clearDio |
( |
uint32_t |
dioNumber | ) |
|
|
inlinestatic |
Clears a specific DIO to 0 (low).
- Parameters
-
dioNumber | specifies the DIO to clear (0-31). |
- Returns
- None
- See also
- GPIO_setDio()
static void GPIO_writeDio(uint32_t dioNumber, uint32_t value)
Writes a value to a specific DIO.
Definition: gpio.h:157
§ GPIO_clearEventDio()
static void GPIO_clearEventDio |
( |
uint32_t |
dioNumber | ) |
|
|
inlinestatic |
Clears the IO event status of a specific DIO.
- Parameters
-
dioNumber | specifies the DIO on which to clear the event status (0-31). |
- Returns
- None
- See also
- GPIO_getEventDio()
Referenced by IOCIntClear().
347 ASSERT( dioNumberLegal( dioNumber ));
352 HWREG( GPIO_BASE + GPIO_O_EVFLAGS47_32 ) = ( 1 << (dioNumber - 32) );
355 HWREG( GPIO_BASE + GPIO_O_EVFLAGS31_0 ) = ( 1 << dioNumber );
#define ASSERT(expr)
Definition: debug.h:71
§ GPIO_getEventDio()
static uint32_t GPIO_getEventDio |
( |
uint32_t |
dioNumber | ) |
|
|
inlinestatic |
Gets the event status of a specific DIO.
- Parameters
-
dioNumber | specifies the DIO to get the event status from (0-31). |
- Returns
- Returns the current event status on the specified DIO.
- 0 : Non-triggered event.
- 1 : Triggered event.
- See also
- GPIO_clearEventDio()
Referenced by IOCIntStatus(), and SysCtrlShutdownWithAbort().
322 ASSERT( dioNumberLegal( dioNumber ));
327 return (( HWREG( GPIO_BASE + GPIO_O_EVFLAGS47_32 ) >> (dioNumber - 32) ) & 1 );
329 return (( HWREG( GPIO_BASE + GPIO_O_EVFLAGS31_0 ) >> dioNumber ) & 1 );
#define ASSERT(expr)
Definition: debug.h:71
§ GPIO_getOutputEnableDio()
static uint32_t GPIO_getOutputEnableDio |
( |
uint32_t |
dioNumber | ) |
|
|
inlinestatic |
Gets the output enable status of a specific DIO.
This function returns the output enable status for the specified DIO. The DIO can be configured as either input or output under software control.
- Parameters
-
dioNumber | specifies the DIO to get the output enable setting from (0-31). |
- Returns
- Returns one of the enumerated data types (0 or 1):
- See also
- GPIO_setOutputEnableDio()
245 ASSERT( dioNumberLegal( dioNumber ));
250 return (( HWREG( GPIO_BASE + GPIO_O_DOE47_32 ) >> (dioNumber - 32) ) & 1 );
252 return (( HWREG( GPIO_BASE + GPIO_O_DOE31_0 ) >> dioNumber ) & 1 );
#define ASSERT(expr)
Definition: debug.h:71
§ GPIO_readDio()
static uint32_t GPIO_readDio |
( |
uint32_t |
dioNumber | ) |
|
|
inlinestatic |
Reads a specific DIO.
- Parameters
-
dioNumber | specifies the DIO to read (0-31). |
- Returns
- Returns 0 or 1 reflecting the input value of the specified DIO.
- See also
- GPIO_writeDio()
132 ASSERT( dioNumberLegal( dioNumber ));
137 return (( HWREG( GPIO_BASE + GPIO_O_DIN47_32 ) >> (dioNumber - 32) ) & 1 );
139 return (( HWREG( GPIO_BASE + GPIO_O_DIN31_0 ) >> dioNumber ) & 1 );
#define ASSERT(expr)
Definition: debug.h:71
§ GPIO_setDio()
static void GPIO_setDio |
( |
uint32_t |
dioNumber | ) |
|
|
inlinestatic |
Sets a specific DIO to 1 (high).
- Parameters
-
dioNumber | specifies the DIO to set (0-31). |
- Returns
- None
- See also
- GPIO_clearDio()
static void GPIO_writeDio(uint32_t dioNumber, uint32_t value)
Writes a value to a specific DIO.
Definition: gpio.h:157
§ GPIO_setOutputEnableDio()
static void GPIO_setOutputEnableDio |
( |
uint32_t |
dioNumber, |
|
|
uint32_t |
outputEnableValue |
|
) |
| |
|
inlinestatic |
Sets output enable of a specific DIO.
This function sets the GPIO output enable bit for the specified DIO. The DIO can be configured as either input or output under software control.
- Parameters
-
dioNumber | specifies the DIO to configure (0-31). |
outputEnableValue | specifies the output enable setting of the specified DIO:
|
- Returns
- None
- See also
- GPIO_getOutputEnableDio()
Referenced by IOCPinTypeGpioInput(), and IOCPinTypeGpioOutput().
276 ASSERT( dioNumberLegal( dioNumber ));
285 HWREG( GPIO_BASE + GPIO_O_DOE47_32 ) |= (1 << (dioNumber - 32));
289 HWREG( GPIO_BASE + GPIO_O_DOE31_0 ) |= (1 << dioNumber);
296 HWREG( GPIO_BASE + GPIO_O_DOE47_32 ) &= ~(1 << (dioNumber - 32));
300 HWREG( GPIO_BASE + GPIO_O_DOE31_0 ) &= ~(1 << dioNumber);
#define GPIO_OUTPUT_ENABLE
Definition: gpio.h:109
#define ASSERT(expr)
Definition: debug.h:71
#define GPIO_OUTPUT_DISABLE
Definition: gpio.h:108
§ GPIO_toggleDio()
static void GPIO_toggleDio |
( |
uint32_t |
dioNumber | ) |
|
|
inlinestatic |
Toggles a specific DIO.
- Parameters
-
dioNumber | specifies the DIO to toggle (0-31). |
- Returns
- None
214 ASSERT( dioNumberLegal( dioNumber ));
219 HWREG( GPIO_BASE + GPIO_O_DOUTTGL47_32 ) = ( 1 << (dioNumber - 32) );
222 HWREG( GPIO_BASE + GPIO_O_DOUTTGL31_0 ) = ( 1 << dioNumber );
#define ASSERT(expr)
Definition: debug.h:71
§ GPIO_writeDio()
static void GPIO_writeDio |
( |
uint32_t |
dioNumber, |
|
|
uint32_t |
value |
|
) |
| |
|
inlinestatic |
Writes a value to a specific DIO.
- Parameters
-
dioNumber | specifies the DIO to update (0-31). |
value | specifies the value to write
- 0 : Logic zero (low)
- 1 : Logic one (high)
|
- Returns
- None
- See also
- GPIO_readDio()
Referenced by GPIO_clearDio(), and GPIO_setDio().
160 ASSERT( dioNumberLegal( dioNumber ));
161 ASSERT(( value == 0 ) || ( value == 1 ));
164 HWREGB( GPIO_BASE + dioNumber ) = value;
#define ASSERT(expr)
Definition: debug.h:71
§ GPIO_OUTPUT_DISABLE
#define GPIO_OUTPUT_DISABLE 0x00000000 |
§ GPIO_OUTPUT_ENABLE
#define GPIO_OUTPUT_ENABLE 0x00000001 |