AM273x MCU+ SDK  08.06.00
GPIO

The General-Purpose Input/Output (GPIO) driver provides API to configure general-purpose pins as either inputs or outputs. It also provided API to configure GPIO to produce host CPU interrupts and DMA synchronization events in different interrupt/event generation modes.

Features Supported

  • Supports up to 8-bit ports for a total of 64 GPIO
  • Supports up to 32 GPIO's which can be configured as interrupt
  • Supports up to 32 interrupt generating GPIO's.
  • Set/clear functionality

SysConfig Features

Note
It is strongly recommend to use SysConfig where it is available instead of using direct SW API calls. This will help simplify the SW application and also catch common mistakes early in the development cycle.
  • Set pin direction: input or output
  • Set interrupt trigger type
  • Set openDrain: enable or disable
  • Set interrupt level: high or low
  • Configuring pinmux based on selected pin

Features NOT Supported

NA

Important Usage Guidelines

  • Note: Not all GPIO pins, are present in a particular device. Refer device TRM for actual GPIO instances and pins supported

Example Usage

Include the below file to access the APIs

#include <drivers/gpio.h>

GPIO configuration as output

uint32_t pinNum = gGpioPinNum, pinValue;
GPIO_setDirMode(gGpioBaseAddr, pinNum, GPIO_DIRECTION_OUTPUT);
GPIO_pinWriteHigh(gGpioBaseAddr, pinNum);
GPIO_pinWriteLow(gGpioBaseAddr, pinNum);
/* Check output value */
pinValue = GPIO_pinRead(gGpioBaseAddr, pinNum);
if(pinValue != GPIO_PIN_LOW)
{
DebugP_assert(FALSE);
}

GPIO configuration as input

uint32_t pinNum = gGpioPinNum, pinValue;
GPIO_setDirMode(gGpioBaseAddr, pinNum, GPIO_DIRECTION_INPUT);
pinValue = GPIO_pinRead(gGpioBaseAddr, pinNum);
if(pinValue == GPIO_PIN_HIGH)
{
DebugP_log("Pin value is HIGH\r\n");
}
else
{
DebugP_log("Pin value is LOW\r\n");
}

GPIO configuration for interrupt

static void GPIO_portIsrFxn(void *args)
{
uint32_t pinNum = (uint32_t) args;
uint32_t pendingInterrupt;
pendingInterrupt = GPIO_getHighLowLevelPendingInterrupt(gGpioBaseAddr,GPIO_INTR_LEVEL_LOW);
GPIO_clearInterrupt(gGpioBaseAddr, pinNum);
if(pendingInterrupt )
{
/*
* Handle all the expected interrupts
*/
}
}
void gpio_interrupt_init(void)
{
int32_t retVal;
uint32_t pinNum = gGpioIntrPinNum;
HwiP_Params hwiPrms;
/* Interrupt setup */
GPIO_setDirMode(gGpioBaseAddr, pinNum, GPIO_DIRECTION_INPUT);
GPIO_setTrigType(gGpioBaseAddr, pinNum, GPIO_TRIG_TYPE_RISE_EDGE);
GPIO_enableInterrupt(gGpioBaseAddr, pinNum);
/* Register interrupt */
HwiP_Params_init(&hwiPrms);
hwiPrms.intNum = gGpioIntrNum;
hwiPrms.callback = &GPIO_portIsrFxn;
hwiPrms.args = (void *) pinNum;
retVal = HwiP_construct(&gGpioHwiObject, &hwiPrms);
if(SystemP_SUCCESS != retVal)
{
DebugP_assert(FALSE);
}
}
void gpio_interrupt_deinit(void)
{
uint32_t pinNum = gGpioIntrPinNum, pendingInterrupt;
/* Interrupt disable and clear any pending interrupts */
GPIO_disableInterrupt(gGpioBaseAddr, pinNum);
GPIO_setTrigType(gGpioBaseAddr, pinNum, GPIO_TRIG_TYPE_NONE);
pendingInterrupt = GPIO_getHighLowLevelPendingInterrupt(gGpioBaseAddr,GPIO_INTR_LEVEL_LOW);
(void)pendingInterrupt; /* kill warning about variable set but not used */
GPIO_clearInterrupt(gGpioBaseAddr, pinNum);
/* Unregister interrupt */
HwiP_destruct(&gGpioHwiObject);
}

API

APIs for GPIO

args
void * args
Definition: hsmclient_msg.h:4
HwiP_destruct
void HwiP_destruct(HwiP_Object *obj)
Cleanup, delete, destruct a Hwi object.
HwiP_Params
Parameters passed during HwiP_construct.
Definition: HwiP.h:72
GPIO_pinWriteLow
void GPIO_pinWriteLow(uint32_t baseAddr, uint32_t pinNum)
The function is used to write logic LOW state to a specific GPIO Port/Pin.
ClockP_sleep
void ClockP_sleep(uint32_t sec)
Sleep for user specified seconds.
GPIO_PIN_LOW
#define GPIO_PIN_LOW
GPIO pin is at logic low.
Definition: gpio/v1/gpio.h:78
GPIO_disableInterrupt
int32_t GPIO_disableInterrupt(uint32_t baseAddr, uint32_t pinNum)
The function is used to disable the interrupt on the GPIO Pin.
HwiP_construct
int32_t HwiP_construct(HwiP_Object *obj, HwiP_Params *params)
Create a Hwi object.
GPIO_clearInterrupt
int32_t GPIO_clearInterrupt(uint32_t baseAddr, uint32_t pinNum)
The function is used to clear the interrupt on the GPIO Pin.
GPIO_DIRECTION_INPUT
#define GPIO_DIRECTION_INPUT
Set GPIO direction as input.
Definition: gpio/v1/gpio.h:91
GPIO_pinWriteHigh
void GPIO_pinWriteHigh(uint32_t baseAddr, uint32_t pinNum)
The function is used to write logic HIGH state to a to a specific GPIO Pin.
GPIO_PIN_HIGH
#define GPIO_PIN_HIGH
GPIO pin is at logic high.
Definition: gpio/v1/gpio.h:80
HwiP_Params_init
void HwiP_Params_init(HwiP_Params *params)
Set default values to HwiP_Params.
DebugP_log
#define DebugP_log(format,...)
Function to log a string to the enabled console.
Definition: DebugP.h:225
GPIO_TRIG_TYPE_RISE_EDGE
#define GPIO_TRIG_TYPE_RISE_EDGE
Interrupt request on occurrence of a rising edge on the input pin.
Definition: gpio/v1/gpio.h:113
GPIO_setDirMode
void GPIO_setDirMode(uint32_t baseAddr, uint32_t pinNum, uint32_t pinDir)
The function is used to set the output data direction associated with a GPIO Pin.
GPIO_enableInterrupt
int32_t GPIO_enableInterrupt(uint32_t baseAddr, uint32_t pinNum)
The function is used to enable the interrupt on the GPIO Pin.
SystemP_SUCCESS
#define SystemP_SUCCESS
Return status when the API execution was successful.
Definition: SystemP.h:56
GPIO_DIRECTION_OUTPUT
#define GPIO_DIRECTION_OUTPUT
Set GPIO direction as output.
Definition: gpio/v1/gpio.h:89
GPIO_setTrigType
int32_t GPIO_setTrigType(uint32_t baseAddr, uint32_t pinNum, uint32_t polLevel)
The function is used to configure the GPIO Pin to control the interrupt polarity.
GPIO_ignoreOrHonorPolarity
int32_t GPIO_ignoreOrHonorPolarity(uint32_t baseAddr, uint32_t pinNum, uint32_t polLevel)
The function is used to configure the GPIO Pin to ignore or honor polarity.
GPIO_markHighLowLevelInterrupt
int32_t GPIO_markHighLowLevelInterrupt(uint32_t baseAddr, uint32_t pinNum, uint32_t interruptLevel)
The function is used to mark the interrupt as high level or low level for the specific GPIO Pin.
GPIO_INTR_LEVEL_LOW
#define GPIO_INTR_LEVEL_LOW
GPIO low interrupt level.
Definition: gpio/v1/gpio.h:126
HwiP_Params::callback
HwiP_FxnCallback callback
Definition: HwiP.h:75
gpio.h
HwiP_Params::args
void * args
Definition: HwiP.h:76
DebugP_assert
#define DebugP_assert(expression)
Function to call for assert check.
Definition: DebugP.h:177
HwiP_Params::intNum
uint32_t intNum
Definition: HwiP.h:74
GPIO_TRIG_TYPE_NONE
#define GPIO_TRIG_TYPE_NONE
No interrupt request on either rising or falling edges on the pin.
Definition: gpio/v1/gpio.h:111
GPIO_getHighLowLevelPendingInterrupt
uint32_t GPIO_getHighLowLevelPendingInterrupt(uint32_t baseAddr, uint32_t interruptLevel)
The function is used to get the high level or low level interrupt pending. The driver will need to cy...
GPIO_pinRead
uint32_t GPIO_pinRead(uint32_t baseAddr, uint32_t pinNum)
The function is used to get the data input for a specific GPIO Port/Pin.