GPIO Support

Name

GPIO Support -- Details

Synopsis

#include <cyg/hal/hal_io.h>    
    

cyg_uint32 pin = CYGHWR_HAL_MPC83XX_GPIO(ctlr, bit, mode);

CYGHWR_HAL_MPC83XX_GPIO_SET(pin);

CYGHWR_HAL_MPC83XX_GPIO_OUT(pin, val);

CYGHWR_HAL_MPC83XX_GPIO_IN(pin, val);

Description

This section describes how to use macros provided by eCos to manage GPIO functionality on the MPC83XX processors.

The MPC83XX HAL provides a number of macros to support the encoding of GPIO pin identity and configuration into a single 32 bit descriptor. This is useful to drivers and other packages that need to configure and use different lines for different devices.

A descriptor is created with CYGHWR_HAL_MPC83XX_GPIO(ctlr, bit, mode) which takes the following arguments:

ctlr

This identifies the GPIO controller to which the pin is attached. It may take the value 1 or 2.

bit

This gives the bit or pin number within the port. These are numbered from 0 to 32. Note that the bit numbers conform to the Freescale big-endian numbering scheme.

mode

This defines the mode in which the pin is to be used. There are 4 main options: INPUT sets the pin as an input, OUTPUT sets it as an output. INPUT_OPENDRAIN and OUTPUT_OPENDRAIN set it as input or output with an open drain.

The following examples show how this macro may be used:

// Define controller 1 pin 10 as an input    
#define CYGHWR_HAL_MPC8309_PIN1               CYGHWR_HAL_MPC83XX_GPIO( 1, 10, INPUT )

// Define controller 2 pin 23 as an open drain output
#define CYGHWR_HAL_MPC8309_PIN23              CYGHWR_HAL_MPC83XX_GPIO( 2, 23, OUTPUT_OPENDRAIN )
   

Additionally, the macro CYGHWR_HAL_MPC83XX_GPIO_NONE may be used in place of a pin descriptor and has a value that no valid descriptor can take. It may therefore be used as a placeholder where no GPIO pin is present or to be used.

The remaining macros all take a GPIO pin descriptor as an argument. CYGHWR_HAL_MPC83XX_GPIO_SET configures the pin according to the descriptor and must be called before any other macros. CYGHWR_HAL_MPC83XX_GPIO_OUT sets the output to the value of the least significant bit of the val argument. The val argument of CYGHWR_HAL_MPC83XX_GPIO_IN should be a pointer to an int, which will be set to 0 if the pin input is zero, and 1 otherwise.

2017-02-09
Documentation license for this page: eCosPro License