📄 gpio1.txt
字号:
register BOOL bIntState = 0;
if (uGPIOPin < NUM_OF_GPIOS)
{
if (uGPIOPin > 31)
{
uBitPos = uGPIOPin - 32;
pGPIOPtr = p_GRP2_INT_STAT;
}
else if (uGPIOPin > 15)
{
uBitPos = uGPIOPin - 16;
pGPIOPtr = p_GRP1_INT_STAT;
}
else
{
uBitPos = uGPIOPin;
pGPIOPtr = p_GRP0_INT_STAT;
}
if ( *pGPIOPtr & (1 << uBitPos) )
{
bIntState = 1;
}
else
{
bIntState = 0;
}
}
return bIntState;
}
/****************************************************************************
*
* Name: void ClearGPIOIntStatus( UINT8 uGPIOPin )
*
* Description: Clears the interrupt associated with the GPIO
*
* Inputs: UINT8 uGPIOPin = which GPIO
*
* Outputs: none
*
***************************************************************************/
void ClearGPIOIntStatus( UINT8 uGPIOPin )
{
UINT32 uBitPos;
UINT32 ByteOffSet;
volatile UINT32* pGPIOStatPtr;
if (uGPIOPin < NUM_OF_GPIOS)
{
ByteOffSet = ((uGPIOPin / NUM_GPIOS_PER_REGISTER) * GRP_REG_OFFSET);
// Calculate corresponding GPIO Output Enable register. Use byte pointer addition
// to match HW register definitions.
pGPIOStatPtr = (volatile UINT32 *) ((volatile UINT8 *)(p_GRP0_INT_STAT) + ByteOffSet);
// Calculate bit position within the register.
uBitPos = (uGPIOPin % NUM_GPIOS_PER_REGISTER);
HW_REG_WRITE(pGPIOStatPtr, (1 << uBitPos)); /* writing a 1 clears the status */
}
}
/****************************************************************************
*
* Name: void SetGPIOIntPolarity( UINT8 uGPIOPin, BOOL bPolarity )
*
* Description: Sets GPIO interrupt polarity
*
* Inputs: UINT8 uGPIOPin = which GPIO
* BOOL bPolarity = polarity (1 = rising edge,
* 0 = falling edge)
*
* Outputs: none
*
***************************************************************************/
void SetGPIOIntPolarity( UINT8 uGPIOPin, BOOL bPolarity )
{
#ifndef DEVICE_YELLOWSTONE
register UINT32 uBitPos;
register UINT32 uValue;
register volatile UINT32* pGPIOPtr;
register int OldLevel;
uValue = 0;
/*assert ( (uGPIOPin > =0) && (uGPIOPin < NUM_OF_GPIOS) );*/
if (uGPIOPin > 31)
{
uBitPos = uGPIOPin - 32;
pGPIOPtr = GPIO_IPC3;
}
else if (uGPIOPin > 15)
{
uBitPos = uGPIOPin - 16;
pGPIOPtr = GPIO_IPC2;
}
else
{
uBitPos = uGPIOPin;
pGPIOPtr = GPIO_IPC1;
}
/* Upper word is the IPC bit mask */
/* Lower work is the IPC bit level polarity */
/* Set all mask bits and do read-modify-write due to register mask bug */
OldLevel = intLock();
uValue = *pGPIOPtr | 0xFFFF0000;
if ( GP_IRQ_POL_POSITIVE == bPolarity ) /*uValue 0 in lower 16 bits, only check for positive */
{
uValue |= (1 << uBitPos);
}
else
{
uValue &= ~(1 << uBitPos);
}
*pGPIOPtr = uValue;
intUnlock(OldLevel);
#endif
}
/****************************************************************************
*
* Name: BOOL ReadGPIOIntPolarity( UINT8 uGPIOPin )
*
* Description: Reads a GPIO pin interrupt polarity control bit
*
* Inputs: UINT8 uGPIOPin = which GPIO
*
* Outputs: Returns BOOL polarity control state
*
***************************************************************************/
BOOL ReadGPIOIntPolarity( UINT8 uGPIOPin )
{
register BOOL bIntState = 0;
#ifndef DEVICE_YELLOWSTONE
register UINT32 uBitPos;
register volatile UINT32* pGPIOPtr;
/*assert ( (uGPIOPin >= 0) && (uGPIOPin < NUM_OF_GPIOS) );*/
if (uGPIOPin > 31)
{
uBitPos = uGPIOPin - 32;
pGPIOPtr = GPIO_IPC3;
}
else if (uGPIOPin > 15)
{
uBitPos = uGPIOPin - 16;
pGPIOPtr = GPIO_IPC2;
}
else
{
uBitPos = uGPIOPin;
pGPIOPtr = GPIO_IPC1;
}
/* Only look at lower 16-bits. Top 16-bits are function masks */
if ( (*pGPIOPtr & 0xFFFF) & (1 << uBitPos) )
{
bIntState = 1;
}
else
{
bIntState = 0;
}
#endif
return bIntState;
}
/****************************************************************************
*
* Name: void SetGPIOIntMode( UINT8 uGPIOIntS, BOOL bState )
*
* Description: Enables or disables the particular GPIO interrupt
* and enables the global interrupt if necessary
*
* Inputs: UINT8 uGPIOPin = which GPIO
* BOOL bState = pin state
*
* Outputs: none
*
***************************************************************************/
void SetGPIOIntMode( UINT8 uGPIOPin, BOOL bPolarity )
{
#ifndef DEVICE_YELLOWSTONE
UINT32 uBitPos;
UINT32 ByteOffSet;
UINT32 uValue = 0;
volatile UINT32* pGPIOIntModePtr;
register int OldLevel;
if (uGPIOPin<NUM_OF_GPIOS)
{
ByteOffSet = ((uGPIOPin / NUM_GPIOS_PER_REGISTER) * GRP_REG_OFFSET);
// Calculate corresponding GPIO Output Enable register. Use byte pointer addition
// to match HW register definitions.
pGPIOIntModePtr = (volatile UINT32 *) ((volatile UINT8 *)(p_GRP0_ISM0) + ByteOffSet);
// Calculate bit position within the register.
uBitPos = (uGPIOPin % NUM_GPIOS_PER_REGISTER);
/* Upper word is the IER bit mask */
/* Lower work is the IER bit enable */
/* Set all mask bits and do read-modify-write due to register mask bug */
OldLevel = intLock();
HW_REG_READ(pGPIOIntModePtr, uValue);
uValue |= 0xFFFF0000;
if ( 0 != bPolarity )
{
uValue |= (1 << uBitPos);
}
else
{
uValue &= ~(1 << uBitPos);
}
HW_REG_WRITE(pGPIOIntModePtr, uValue);
intUnlock(OldLevel);
}
#endif
}
/****************************************************************************
*
* Name: void SetGPIOIntEnable( UINT8 uGPIOIntE, BOOL bState )
*
* Description: Enables or disables the particular GPIO interrupt
* and enables the global interrupt if necessary
*
* Inputs: UINT8 uGPIOPin = which GPIO
* BOOL bState = pin state
*
* Outputs: none
*
***************************************************************************/
void SetGPIOIntEnable( UINT8 uGPIOPin, BOOL bState )
{
#ifndef DEVICE_YELLOWSTONE
UINT32 uBitPos;
UINT32 ByteOffSet;
UINT32 uValue = 0;
volatile UINT32* pGPIOIntMaskPtr;
register int OldLevel;
if (uGPIOPin < NUM_OF_GPIOS)
{
ByteOffSet = ((uGPIOPin / NUM_GPIOS_PER_REGISTER) * GRP_REG_OFFSET);
// Calculate corresponding GPIO Output Enable register. Use byte pointer addition
// to match HW register definitions.
pGPIOIntMaskPtr = (volatile UINT32 *) ((volatile UINT8 *)(p_GRP0_INT_MASK) + ByteOffSet);
// Calculate bit position within the register.
uBitPos = (uGPIOPin % NUM_GPIOS_PER_REGISTER);
/* Upper word is the IER bit mask */
/* Lower work is the IER bit enable */
/*************************/
#ifdef DEVICE_YELLOWSTONE
/*************************/
uValue = 1 << (uBitPos + 16);
if ( IRQ_ON == bState )
{
uValue |= (1 << uBitPos);
}
else
{
uValue &= (~(1 << uBitPos));
}
HW_REG_WRITE(pGPIOIntMaskPtr, uValue);
/*************************/
#else
/*************************/
/* Set all mask bits and do read-modify-write due to register mask bug */
OldLevel = intLock();
HW_REG_READ(pGPIOIntMaskPtr, uValue);
uValue |= 0xFFFF0000;
if ( IRQ_ON == bState )
{
uValue |= (1 << uBitPos);
}
else
{
uValue &= (~(1 << uBitPos));
}
/* Before enabling the interrupt, must clear the status to not get initial interrupt */
ClearGPIOIntStatus ( uGPIOPin );
HW_REG_WRITE(pGPIOIntMaskPtr, uValue);
intUnlock(OldLevel);
#endif
}
#endif
}
/****************************************************************************
*
* Name: BOOL ReadGPIOIntEnable( UINT8 uGPIOPin )
*
* Description: Reads a GPIO pin interrupt status bit
*
* Inputs: UINT8 uGPIOPin = which GPIO
*
* Outputs: Returns BOOL interrupt status
*
***************************************************************************/
BOOL ReadGPIOIntEnable( UINT8 uGPIOPin )
{
UINT32 Value = 0;
UINT32 uBitPos;
UINT32 ByteOffSet;
volatile UINT32* pGPIOIntMaskPtr;
if (uGPIOPin < NUM_OF_GPIOS)
{
ByteOffSet = ((uGPIOPin / NUM_GPIOS_PER_REGISTER) * GRP_REG_OFFSET);
// Calculate corresponding GPIO Output Enable register. Use byte pointer addition
// to match HW register definitions.
pGPIOIntMaskPtr = (volatile UINT32 *) ((volatile UINT8 *)(p_GRP0_INT_MASK) + ByteOffSet);
// Calculate bit position within the register.
uBitPos = (uGPIOPin % NUM_GPIOS_PER_REGISTER);
HW_REG_READ(pGPIOIntMaskPtr, Value);
Value &= (1 << uBitPos);
}
return (Value);
}
EXPORT_SYMBOL(SetGPIODir);
EXPORT_SYMBOL(SetGPIOUsage);
EXPORT_SYMBOL(WriteGPIOData);
EXPORT_SYMBOL(ReadGPIOData);
EXPORT_SYMBOL(ReadGPIOIntStatus);
EXPORT_SYMBOL(ClearGPIOIntStatus);
EXPORT_SYMBOL(SetGPIOIntPolarity);
EXPORT_SYMBOL(ReadGPIOIntPolarity);
EXPORT_SYMBOL(SetGPIOIntMode);
EXPORT_SYMBOL(SetGPIOIntEnable);
EXPORT_SYMBOL(SetGPIOInputEnable);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -