📄 bbu_dd_gpiocsl.h
字号:
/******************************************************************************\
* GPIO global macro declarations
\******************************************************************************/
/* Pin id definitions */
#define GPIO_PIN0 0x00000001u
#define GPIO_PIN1 0x00000002u
#define GPIO_PIN2 0x00000004u
#define GPIO_PIN3 0x00000008u
#define GPIO_PIN4 0x00000010u
#define GPIO_PIN5 0x00000020u
#define GPIO_PIN6 0x00000040u
#define GPIO_PIN7 0x00000080u
#define GPIO_PIN8 0x00000100u
#define GPIO_PIN9 0x00000200u
#define GPIO_PIN10 0x00000400u
#define GPIO_PIN11 0x00000800u
#define GPIO_PIN12 0x00001000u
#define GPIO_PIN13 0x00002000u
#define GPIO_PIN14 0x00004000u
#define GPIO_PIN15 0x00008000u
/* CPU Interrupt Pins */
#define GPIO_GPINT0 0
#define GPIO_GPINT4 1
#define GPIO_GPINT5 2
#define GPIO_GPINT6 3
#define GPIO_GPINT7 4
/* Interrupt Polarity */
#define GPIO_RISING_EDGE 0
#define GPIO_FALLING_EDGE 1
/* Pin Direction */
#define GPIO_INPUT 0
#define GPIO_OUTPUT 1
/* GPIO masks */
#define GPIO_MASK_NA 0x00000000u
#define GPIO_MASK_00 0x00000001u
#define GPIO_MASK_01 0x00000002u
#define GPIO_MASK_02 0x00000004u
#define GPIO_MASK_03 0x00000008u
#define GPIO_MASK_04 0x00000010u
#define GPIO_MASK_05 0x00000020u
#define GPIO_MASK_06 0x00000040u
#define GPIO_MASK_07 0x00000080u
#define GPIO_MASK_08 0x00000100u
#define GPIO_MASK_09 0x00000200u
#define GPIO_MASK_10 0x00000400u
#define GPIO_MASK_11 0x00000800u
#define GPIO_MASK_12 0x00001000u
#define GPIO_MASK_13 0x00002000u
#define GPIO_MASK_14 0x00004000u
#define GPIO_MASK_15 0x00008000u
/* Invalid Pointer to GPIO Handle */
#define GPIO_HINV ((void*)(-1))
#define PIN_ALLOCATION_MASK 0x0000FEF8u
#define GPIO_DEVICE_ENTRY { FALSE,\
(volatile Uint32*)GPIO_BASE_ADDR,\
(Uint32)PIN_ALLOCATION_MASK}
/*----------------------------------------------------------------------------*/
/******************************************************************************\
* GPIO Inline Function Declarations
\******************************************************************************/
IDECL void GPIO_pinDisable(GPIO_Handle *hGpio, Uint32 pinId);
IDECL void GPIO_pinEnable(GPIO_Handle *hGpio,Uint32 pinId);
IDECL Uint32 GPIO_pinDirection(GPIO_Handle *hGpio, Uint32 pinId, Uint32 direction);
IDECL Uint32 GPIO_pinRead(GPIO_Handle *hGpio,Uint32 pinId);
IDECL Uint32 GPIO_read(GPIO_Handle *hGpio, Uint32 pinMask);
IDECL void GPIO_pinWrite(GPIO_Handle *hGpio,Uint32 pinId, Uint32 val);
IDECL void GPIO_write(GPIO_Handle *hGpio, Uint32 pinMask, Uint32 val);
IDECL Uint32 GPIO_deltaHighGet(GPIO_Handle *hGpio,Uint32 pinId);
IDECL void GPIO_deltaHighClear(GPIO_Handle *hGpio,Uint32 pinId);
IDECL Uint32 GPIO_deltaLowGet(GPIO_Handle *hGpio,Uint32 pinId);
IDECL void GPIO_deltaLowClear(GPIO_Handle *hGpio,Uint32 pinId);
IDECL void GPIO_maskHighSet(GPIO_Handle *hGpio,Uint32 pinId);
IDECL void GPIO_maskHighClear(GPIO_Handle *hGpio,Uint32 pinId);
IDECL void GPIO_maskLowSet(GPIO_Handle *hGpio,Uint32 pinId);
IDECL void GPIO_maskLowClear(GPIO_Handle *hGpio,Uint32 pinId);
IDECL Uint32 GPIO_intPolarity(GPIO_Handle *hGpio,Uint32 signal, Uint32 polarity);
/******************************************************************************\
* GPIO inline function definitions
\******************************************************************************/
/* Enables the given GPIO pins as General Purpose Input/Output pins */
IDECL void GPIO_pinEnable(GPIO_Handle *hGpio,Uint32 pinId)
{
volatile Uint32 gpen;
gpen = GPIO_RGETH(hGpio,GPEN);
gpen = gpen | (pinId & hGpio->pinAllocMask);
GPIO_FSETH(hGpio,GPEN,GPXEN,gpen);
}
/*----------------------------------------------------------------------------*/
/* Disables the given GPIO pins as General Purpose Input/Output pins */
IDECL void GPIO_pinDisable(GPIO_Handle *hGpio,Uint32 pinId)
{
volatile Uint32 gpen;
gpen = GPIO_RGETH(hGpio,GPEN);
gpen = gpen & (~pinId & hGpio->pinAllocMask);
GPIO_FSETH(hGpio,GPEN,GPXEN,gpen);
}
/*----------------------------------------------------------------------------*/
/* Sets the direction of the given pins as input or output */
IDECL Uint32 GPIO_pinDirection(GPIO_Handle *hGpio,Uint32 pinId, Uint32 direction)
{
volatile Uint32 gpDir;
gpDir = GPIO_RGETH(hGpio,GPDIR);
if ( direction == GPIO_INPUT)
{
GPIO_RSETH(hGpio,GPDIR,(gpDir & (~pinId & hGpio->pinAllocMask)));
}
else
{
GPIO_RSETH(hGpio,GPDIR,(gpDir | (pinId & hGpio->pinAllocMask)));
}
return (Uint32)(GPIO_RGETH(hGpio,GPDIR));
}
/*----------------------------------------------------------------------------*/
/* Gets value of given pins */
IDECL Uint32 GPIO_pinRead(GPIO_Handle *hGpio,Uint32 pinId)
{
volatile Uint32 x = 0xFFFFFFFF;
if ((GPIO_RGETH(hGpio,GPVAL) & (pinId & hGpio->pinAllocMask))!= 0)
{
x = 1;
}
else
{
x = 0;
}
return x;
}
/*----------------------------------------------------------------------------*/
/* Reads data from a set of pins */
IDECL Uint32 GPIO_read(GPIO_Handle *hGpio, Uint32 pinMask)
{
return ((GPIO_RGETH(hGpio,GPVAL) & pinMask) & hGpio->pinAllocMask);
}
/*----------------------------------------------------------------------------*/
/* Writes value of given output pins */
IDECL void GPIO_pinWrite(GPIO_Handle *hGpio,Uint32 pinId, Uint32 val)
{
volatile Uint32 gpVal;
gpVal = GPIO_RGETH(hGpio,GPVAL);
if ( val == 0)
{
GPIO_RSETH(hGpio,GPVAL,(gpVal & (~pinId & hGpio->pinAllocMask)));
}
else
{
GPIO_RSETH(hGpio,GPVAL,(gpVal | (pinId & hGpio->pinAllocMask)));
}
}
/*----------------------------------------------------------------------------*/
/* Writes the value to the specified set of GPIO pins */
IDECL void GPIO_write(GPIO_Handle *hGpio, Uint32 pinMask, Uint32 val)
{
volatile Uint32 gpVal;
gpVal = GPIO_RGETH(hGpio,GPVAL);
GPIO_RSETH(hGpio,GPVAL, ((gpVal & ~pinMask) | (pinMask & val)));
}
/*----------------------------------------------------------------------------*/
/* Returns low-to-high transition detection status for given input pins*/
IDECL Uint32 GPIO_deltaHighGet(GPIO_Handle *hGpio,Uint32 pinId)
{
return (GPIO_FGETH(hGpio,GPDH,GPXDH) & (pinId & hGpio->pinAllocMask));
}
/*----------------------------------------------------------------------------*/
/* Clears bits of given input pins in Delta High Register */
IDECL void GPIO_deltaHighClear(GPIO_Handle *hGpio,Uint32 pinId)
{
volatile Uint32 gpdh;
gpdh = GPIO_RGETH(hGpio,GPDH);
GPIO_FSETH(hGpio,GPDH,GPXDH,(gpdh & (pinId & hGpio->pinAllocMask)));
}
/*----------------------------------------------------------------------------*/
/* Returns high-to-low transition detection status for given input pins */
IDECL Uint32 GPIO_deltaLowGet(GPIO_Handle *hGpio,Uint32 pinId)
{
return (GPIO_FGETH(hGpio,GPDL,GPXDL) & (pinId & hGpio->pinAllocMask));
}
/*----------------------------------------------------------------------------*/
/* Clears bits of given input pins in Delta Low Register */
IDECL void GPIO_deltaLowClear(GPIO_Handle *hGpio,Uint32 pinId)
{
volatile Uint32 gpdl;
gpdl = GPIO_RGETH(hGpio,GPDL);
GPIO_FSETH(hGpio,GPDL,GPXDL,(gpdl & (pinId & hGpio->pinAllocMask)));
}
/*----------------------------------------------------------------------------*/
/* Sets bits which cause a CPU interrupt or EDMA event. */
IDECL void GPIO_maskHighSet(GPIO_Handle *hGpio,Uint32 pinId)
{
volatile Uint32 gphm;
gphm = GPIO_RGETH(hGpio,GPHM);
GPIO_FSETH(hGpio,GPHM,GPXHM,(gphm | (pinId & hGpio->pinAllocMask)));
}
/*----------------------------------------------------------------------------*/
/* clears the bits of given pins in Mask High Register */
IDECL void GPIO_maskHighClear(GPIO_Handle *hGpio,Uint32 pinId)
{
volatile Uint32 gphm;
gphm = GPIO_RGETH(hGpio,GPHM);
GPIO_FSETH(hGpio,GPHM,GPXHM,(gphm & (~pinId & hGpio->pinAllocMask)));
}
/*----------------------------------------------------------------------------*/
/* Sets bits which cause a CPU interrupt or EDMA event */
IDECL void GPIO_maskLowSet(GPIO_Handle *hGpio,Uint32 pinId)
{
volatile Uint32 gplm;
gplm = GPIO_RGETH(hGpio,GPLM);
GPIO_FSETH(hGpio,GPLM,GPXLM,(gplm | (pinId & hGpio->pinAllocMask)));
}
/*----------------------------------------------------------------------------*/
/* Clears bits which cause a CPU interrupt or EDMA event */
IDECL void GPIO_maskLowClear(GPIO_Handle *hGpio,Uint32 pinId)
{
volatile Uint32 gplm;
gplm = GPIO_RGETH(hGpio,GPLM);
GPIO_FSETH(hGpio,GPLM,GPXLM,(gplm & (~pinId & hGpio->pinAllocMask)));
}
/*----------------------------------------------------------------------------*/
/* Sets the polarity of the GPINTx interrupt/even signals */
IDECL Uint32 GPIO_intPolarity(GPIO_Handle *hGpio,Uint32 pinId, Uint32 polarity)
{
volatile Uint32 gppol;
gppol = GPIO_RGETH(hGpio,GPPOL);
if ( polarity == GPIO_RISING_EDGE)
{
GPIO_FSETH(hGpio,GPPOL,GPINTXPOL,(gppol & (~pinId & hGpio->pinAllocMask)));
}
else
{
GPIO_FSETH(hGpio,GPPOL,GPINTXPOL,(gppol | (pinId & hGpio->pinAllocMask)));
}
return ( GPIO_RGETH(hGpio,GPPOL));
}
/*---------------------------------------------------------------------------*/
#endif /* _BBU_DD_GPIOCSL_H*/
/******************************************************************************\
* End of BBU_DD_GpioCsl.h
\******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -