Name
Hardware Configuration Support on IMX Processors — Details
Synopsis
#include <cyg/hal/hal_io.h>
cyg_uint32 desc = CYGHWR_HAL_IMX_PAD(
pad
,
mode
)
;
CYGHWR_HAL_IMX_PAD_SET
(
desc
)
;
cyg_uint32 desc = CYGHWR_HAL_IMX_DAISY(
reg
,
value
)
;
CYGHWR_HAL_IMX_DAISY_SET
(
desc
)
;
cyg_uint32 desc = CYGHWR_HAL_IMX_CLOCK_GATE(
reg
,
gate
)
;
CYGHWR_HAL_IMX_CLOCK_ENABLE
(
desc
)
;
CYGHWR_HAL_IMX_CLOCK_DISABLE
(
desc
)
;
cyg_uint32 desc = CYGHWR_HAL_IMX_GPIO(
ctlr
,
pin
,
mode
)
;
CYGHWR_HAL_IMX_GPIO_SET
(
desc
)
;
CYGHWR_HAL_IMX_GPIO_OUT
(
desc
,
val
)
;
CYGHWR_HAL_IMX_GPIO_IN
(
desc
,
val
)
;
Description
The IMX HAL provides a number of macros to support the encoding of various hardware configuration options into a 32-bit descriptor. This is useful to drivers and other packages that need to configure the hardware.
PAD Multiplexing
Many of the IO pads on the chip can be connected to a
variety of different devices and have a variety of
properties that need to be configured. A pad descriptor is
created by the CYGHWR_HAL_IMX_PAD()
macro. The pad
argument defines the pad
to be configured, and follows the hardware naming
convention, for example AD_B0(12)
or
SD_B1(3)
. The mode
argument is the terminal part of a
CYGHWR_HAL_IMX_PAD_MODE_XXXX
macro; this
may be one supplied in the HAL, or one constructed by the
driver or application. This macro is defined as a
combination of the
CYGHWR_HAL_IMX_PAD_MODE_
definitions in
cyg/hal/var_io.h
, which correspond to
the definitions in the hardware pad MUX and CTL registers.
The macro CYGHWR_HAL_IMX_PAD_SET()
is
used to configure a pad according to the descriptor.
The following example shows how the LPUART pads are configured.
#define CYGHWR_HAL_IMX_PAD_MODE_LPUART_PAD(__alt) \ CYGHWR_HAL_IMX_PAD_MODE_MUX(__alt) | \ CYGHWR_HAL_IMX_PAD_MODE_PUE | \ CYGHWR_HAL_IMX_PAD_MODE_PKE | \ CYGHWR_HAL_IMX_PAD_MODE_PUS_47K_PU | \ CYGHWR_HAL_IMX_PAD_MODE_DSE(6) | \ CYGHWR_HAL_IMX_PAD_MODE_SPEED_MED2 #define CYGHWR_HAL_IMX_LPUART1_TX CYGHWR_HAL_IMX_PAD( AD_B0(12), LPUART_PAD(2) ) #define CYGHWR_HAL_IMX_LPUART1_RX CYGHWR_HAL_IMX_PAD( AD_B0(13), LPUART_PAD(2) )
PAD Daisy Chaining
Some device IO lines can connect to multiple pads, the daisy
chain registers select which pad is to be used for the
device. A daisy chain descriptor is created by the
CYGHWR_HAL_IMX_DAISY
macro. The
reg
argument selects which daisy chain
device line is to be programmed, and the
val
argument defines the pad
selection. Both of these arguments are fragments of macros
defined in cyg/hal/var_io.h
. Only
registers and values currently used are defined there, new
ones can be added there or defined in the driver or
application.
The CYGHWR_HAL_IMX_DAISY_SET
macro is
called to program the configuration from a descriptor into
the hardware.
The following example shows some daisy chain descriptor definitions.
# define CYGHWR_HAL_NXP_LPUART3_TXD_DAISY CYGHWR_HAL_IMX_DAISY(LPUART3_TX, AD_B1_06_ALT2) # define CYGHWR_HAL_NXP_LPUART3_RXD_DAISY CYGHWR_HAL_IMX_DAISY(LPUART3_RX, AD_B1_07_ALT2) # define CYGHWR_HAL_NXP_LPUART3_CTS_DAISY CYGHWR_HAL_IMX_DAISY(LPUART3_CTS_B, AD_B1_04_ALT2) # define CYGHWR_HAL_NXP_LPUART3_RTS_DAISY CYGHWR_HAL_IMX_DAISY_NONE
Clock Gating Control
Most device clocks are controlled by a gate that needs to be
switched on or off. The HAL provides macros which may be
used to enable or disable peripheral clocks. Effectively
this indicates whether the peripheral is powered on
(enabled) or powered down (disabled), and so may be used to
ensure unused peripherals are turned off to save power. The
macro CYGHWR_HAL_IMX_CLOCK_GATE()
defines
a clock gate descriptor. The reg
argument
gives the CCGR
register to be used and
the gate
argument selects the clock gate
bit in that register. Clock gate descriptors are defined in
cyg/hal/var_io.h
and new values will be
added there as needed.
The macros CYGHWR_HAL_IMX_CLOCK_ENABLE()
and CYGHWR_HAL_IMX_CLOCK_DISABLE()
enable
and disable the clock described by the descriptor. At
present clocks are either fully on or fully off, the option
to switch clocks off in WAIT mode is not implemented.
It is important to remember that before a peripheral can be used, it must be enabled. It is safe to re-enable a peripheral that is already enabled, although usually a device driver will only do so once in its initialization. eCos will automatically initialize some peripheral blocks where it needs to use the associated peripherals, and in eCos-supplied device drivers which are included in the eCos configuration. However this should not be relied on - it is always safest to enable the peripheral clocks anyway just in case.
GPIO
A descriptor is created by the
CYGHWR_HAL_IMX_GPIO()
macro. The
ctlr
argument selects the GPIO controller
while the pin
argument selects the GPIO pin
in the controller. The mode
argument
configures the pin within the GPIO controller. At present
interrupt configuration is not supported, so the mode may only
be IN
or OUT
.
In addition to GPIO configuration, the matching pad will need
to be configured using a PAD descriptor.
If a GPIO pin has been configured as an output then its value
may be set using
CYGHWR_HAL_IMX_GPIO_OUT()
. Similarly the
current value of an input pin can be read using
CYGHWR_HAL_IMX_GPIO_IN()
.
2023-04-25 | eCosPro Non-Commercial Public License |