📄 xgpiops.c
字号:
* @param InstancePtr is a pointer to the XGpioPs instance.* @param Bank is the bank number of the GPIO to operate on.* Valid values are 0 to XGPIOPS_MAX_BANKS - 1.* @param Direction is the 32 bit mask of the Pin direction to be set for* all the pins in the Bank. Bits with 0 are set to Input mode,* bits with 1 are set to Output Mode.** @return None.** @note This function is used for setting the direction of all the pins* in the specified bank. The previous state of the pins is* not maintained.******************************************************************************/void XGpioPs_SetDirection(XGpioPs *InstancePtr, u8 Bank, u32 Direction){ Xil_AssertVoid(InstancePtr != NULL); Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); Xil_AssertVoid(Bank < XGPIOPS_MAX_BANKS); XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr, ((Bank) * XGPIOPS_REG_MASK_OFFSET) + XGPIOPS_DIRM_OFFSET, Direction);}/****************************************************************************//**** Set the Direction of the specified pin.** @param InstancePtr is a pointer to the XGpioPs instance.* @param Pin is the pin number to which the Data is to be written.* Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.* @param Direction is the direction to be set for the specified pin.* Valid values are 0 for Input Direction, 1 for Output Direction.** @return None.******************************************************************************/void XGpioPs_SetDirectionPin(XGpioPs *InstancePtr, int Pin, int Direction){ u8 Bank; u8 PinNumber; u32 DirModeReg; Xil_AssertVoid(InstancePtr != NULL); Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); Xil_AssertVoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM); Xil_AssertVoid((Direction == 0) || (Direction == 1)); /* * Get the Bank number and Pin number within the bank. */ XGpioPs_GetBankPin(Pin, &Bank, &PinNumber); DirModeReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr, ((Bank) * XGPIOPS_REG_MASK_OFFSET) + XGPIOPS_DIRM_OFFSET); if (Direction) { /* Output Direction */ DirModeReg |= (1 << PinNumber); } else { /* Input Direction */ DirModeReg &= ~ (1 << PinNumber); } XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr, ((Bank) * XGPIOPS_REG_MASK_OFFSET) + XGPIOPS_DIRM_OFFSET, DirModeReg);}/****************************************************************************//**** Get the Direction of the pins of the specified GPIO Bank.** @param InstancePtr is a pointer to the XGpioPs instance.* @param Bank is the bank number of the GPIO to operate on.* Valid values are 0 to XGPIOPS_MAX_BANKS - 1.** return Returns a 32 bit mask of the Direction register. Bits with 0 are* in Input mode, bits with 1 are in Output Mode.** @note None.******************************************************************************/u32 XGpioPs_GetDirection(XGpioPs *InstancePtr, u8 Bank){ Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); Xil_AssertNonvoid(Bank < XGPIOPS_MAX_BANKS); return XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr, ((Bank) * XGPIOPS_REG_MASK_OFFSET) + XGPIOPS_DIRM_OFFSET);}/****************************************************************************//**** Get the Direction of the specified pin.** @param InstancePtr is a pointer to the XGpioPs instance.* @param Pin is the pin number for which the Direction is to be* retrieved.* Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.** @return Direction of the specified pin.* - 0 for Input Direction* - 1 for Output Direction** @note None.******************************************************************************/int XGpioPs_GetDirectionPin(XGpioPs *InstancePtr, int Pin){ u8 Bank; u8 PinNumber; Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); Xil_AssertNonvoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM); /* * Get the Bank number and Pin number within the bank. */ XGpioPs_GetBankPin(Pin, &Bank, &PinNumber); return (XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr, ((Bank) * XGPIOPS_REG_MASK_OFFSET) + XGPIOPS_DIRM_OFFSET) >> PinNumber) & 1;}/****************************************************************************//**** Set the Output Enable of the pins of the specified GPIO Bank.** @param InstancePtr is a pointer to the XGpioPs instance.* @param Bank is the bank number of the GPIO to operate on.* Valid values are 0 to XGPIOPS_MAX_BANKS - 1.* @param OpEnable is the 32 bit mask of the Output Enables to be set for* all the pins in the Bank. The Output Enable of bits with 0 are* disabled, the Output Enable of bits with 1 are enabled.** @return None.** @note This function is used for setting the Output Enables of all the* pins in the specified bank. The previous state of the Output* Enables is not maintained.******************************************************************************/void XGpioPs_SetOutputEnable(XGpioPs *InstancePtr, u8 Bank, u32 OpEnable){ Xil_AssertVoid(InstancePtr != NULL); Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); Xil_AssertVoid(Bank < XGPIOPS_MAX_BANKS); XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr, ((Bank) * XGPIOPS_REG_MASK_OFFSET) + XGPIOPS_OUTEN_OFFSET, OpEnable);}/****************************************************************************//**** Set the Output Enable of the specified pin.** @param InstancePtr is a pointer to the XGpioPs instance.* @param Pin is the pin number to which the Data is to be written.* Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.* @param OpEnable specifies whether the Output Enable for the specified* pin should be enabled.* Valid values are 0 for Disabling Output Enable,* 1 for Enabling Output Enable.** @return None.** @note None.******************************************************************************/void XGpioPs_SetOutputEnablePin(XGpioPs *InstancePtr, int Pin, int OpEnable){ u8 Bank; u8 PinNumber; u32 OpEnableReg; Xil_AssertVoid(InstancePtr != NULL); Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); Xil_AssertVoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM); Xil_AssertVoid((OpEnable == 0) || (OpEnable == 1)); /* * Get the Bank number and Pin number within the bank. */ XGpioPs_GetBankPin(Pin, &Bank, &PinNumber); OpEnableReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr, ((Bank) * XGPIOPS_REG_MASK_OFFSET) + XGPIOPS_OUTEN_OFFSET); if (OpEnable) { /* Enable Output Enable */ OpEnableReg |= (1 << PinNumber); } else { /* Disable Output Enable */ OpEnableReg &= ~ (1 << PinNumber); } XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr, ((Bank) * XGPIOPS_REG_MASK_OFFSET) + XGPIOPS_OUTEN_OFFSET, OpEnableReg);}/****************************************************************************//**** Get the Output Enable status of the pins of the specified GPIO Bank.** @param InstancePtr is a pointer to the XGpioPs instance.* @param Bank is the bank number of the GPIO to operate on.* Valid values are 0 to XGPIOPS_MAX_BANKS - 1.** return Returns a a 32 bit mask of the Output Enable register.* Bits with 0 are in Disabled state, bits with 1 are in* Enabled State.** @note None.******************************************************************************/u32 XGpioPs_GetOutputEnable(XGpioPs *InstancePtr, u8 Bank){ Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); Xil_AssertNonvoid(Bank < XGPIOPS_MAX_BANKS); return XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr, ((Bank) * XGPIOPS_REG_MASK_OFFSET) + XGPIOPS_OUTEN_OFFSET);}/****************************************************************************//**** Get the Output Enable status of the specified pin.** @param InstancePtr is a pointer to the XGpioPs instance.* @param Pin is the pin number for which the Output Enable status is to* be retrieved.* Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.** @return Output Enable of the specified pin.* - 0 if Output Enable is disabled for this pin* - 1 if Output Enable is enabled for this pin** @note None.******************************************************************************/int XGpioPs_GetOutputEnablePin(XGpioPs *InstancePtr, int Pin){ u8 Bank; u8 PinNumber; Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); Xil_AssertNonvoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM); /* * Get the Bank number and Pin number within the bank. */ XGpioPs_GetBankPin(Pin, &Bank, &PinNumber); return (XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr, ((Bank) * XGPIOPS_REG_MASK_OFFSET) + XGPIOPS_OUTEN_OFFSET) >> PinNumber) & 1;}/****************************************************************************//*** Get the Bank number and the Pin number in the Bank, for the given PinNumber* in the GPIO device.** @param PinNumber is the Pin number in the GPIO device.* @param BankNumber returns the Bank in which this GPIO pin is present.* Valid values are 0 to XGPIOPS_MAX_BANKS - 1.* @param PinNumberInBank returns the Pin Number within the Bank.** return None;** @note None.******************************************************************************/void XGpioPs_GetBankPin(u8 PinNumber, u8 *BankNumber, u8 *PinNumberInBank){ for (*BankNumber = 0; *BankNumber < 4; (*BankNumber)++) if (PinNumber <= XGpioPsPinTable[*BankNumber]) break; if (*BankNumber == 0) { *PinNumberInBank = PinNumber; } else { *PinNumberInBank = PinNumber % (XGpioPsPinTable[*BankNumber - 1] + 1); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -