Name

GPIO Support — Use of GPIO

Synopsis

#include <cyg/hal/hal_io.h>
      

desc = CYGHWR_HAL_VIRTUAL_GPIO( pin , dir );

CYGHWR_HAL_VIRTUAL_GPIO_SET ( desc );

CYGHWR_HAL_VIRTUAL_GPIO_OUT ( desc , val );

CYGHWR_HAL_VIRTUAL_GPIO_IN ( desc , val );

Description

The HAL contains support for a VirtIO based GPIO controller. This is currently only available when a virtual machine is running under Xvisor.

The HAL provides a number of macros to support the encoding of GPIO pin configuration into a 32 bit descriptor. This is useful to drivers and other packages that need to configure and use different lines for different devices. Pin multiplexing is handled by the hypervisor, and is not considered here.

A GPIO descriptor is created with CYGHWR_HAL_VIRTUAL_GPIO( pin, dir ) which takes the following arguments:

pin
This gives the GPIO pin number. The range depends on the number of pins assigned to the GPIO device in the hypervisor.
dir
This defines the direction in which the pin will be used, either input or output. The value in this argument is the last element of a macro of the form, CYGHWR_HAL_VIRTUAL_GPIO_DIR_XXXXX, either IN or OUT.

Additionally, the macro CYGHWR_HAL_VIRTUAL_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. It may be passed to any GPIO macro which takes a descriptor and will be treated as a no-op.

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