⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xgpiops_intr.c

📁 自学ZedBoard:使用IP通过ARM PS访问FPGA(源代码)
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Id: xgpiops_intr.c,v 1.1.2.1 2011/01/20 03:42:36 sadanan Exp $ *//******************************************************************************** (c) Copyright 2010-12 Xilinx, Inc. All rights reserved.** This file contains confidential and proprietary information of Xilinx, Inc.* and is protected under U.S. and international copyright and other* intellectual property laws.** DISCLAIMER* This disclaimer is not a license and does not grant any rights to the* materials distributed herewith. Except as otherwise provided in a valid* license issued to you by Xilinx, and to the maximum extent permitted by* applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL* FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS,* IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF* MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE;* and (2) Xilinx shall not be liable (whether in contract or tort, including* negligence, or under any other theory of liability) for any loss or damage* of any kind or nature related to, arising under or in connection with these* materials, including for any direct, or any indirect, special, incidental,* or consequential loss or damage (including loss of data, profits, goodwill,* or any type of loss or damage suffered as a result of any action brought by* a third party) even if such damage or loss was reasonably foreseeable or* Xilinx had been advised of the possibility of the same.** CRITICAL APPLICATIONS* Xilinx products are not designed or intended to be fail-safe, or for use in* any application requiring fail-safe performance, such as life-support or* safety devices or systems, Class III medical devices, nuclear facilities,* applications related to the deployment of airbags, or any other applications* that could lead to death, personal injury, or severe property or* environmental damage (individually and collectively, "Critical* Applications"). Customer assumes the sole risk and liability of any use of* Xilinx products in Critical Applications, subject only to applicable laws* and regulations governing limitations on product liability.** THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE* AT ALL TIMES.*******************************************************************************//*****************************************************************************//**** @file xgpiops_intr.c** This file contains functions related to GPIO interrupt handling.** <pre>* MODIFICATION HISTORY:** Ver   Who  Date     Changes* ----- ---- -------- -----------------------------------------------* 1.00a sv   01/18/10 First Release* </pre>*******************************************************************************//***************************** Include Files *********************************/#include "xgpiops.h"/************************** Constant Definitions *****************************//**************************** Type Definitions *******************************//***************** Macros (Inline Functions) Definitions *********************//************************** Variable Definitions *****************************//************************** Function Prototypes ******************************/void StubHandler(void *CallBackRef, int Bank, u32 Status);/****************************************************************************//**** This function enables the interrupts for the specified pins in the specified* 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	Mask is the bit mask of the pins for which interrupts are to*		be enabled. Bit positions of 1 will be enabled. Bit positions*		of 0 will keep the previous setting.** @return	None.** @note		None.******************************************************************************/void XGpioPs_IntrEnable(XGpioPs *InstancePtr, u8 Bank, u32 Mask){	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_INTEN_OFFSET, Mask);}/****************************************************************************//**** This function enables the interrupt for the specified pin.** @param	InstancePtr is a pointer to the XGpioPs instance.* @param	Pin is the pin number for which the interrupt is to be enabled.*		Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.** @return	None.** @note		None.******************************************************************************/void XGpioPs_IntrEnablePin(XGpioPs *InstancePtr, int Pin){	u8 Bank;	u8 PinNumber;	u32 IntrReg = 0;	Xil_AssertVoid(InstancePtr != NULL);	Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);	Xil_AssertVoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);	/*	 * Get the Bank number and Pin number within the bank.	 */	XGpioPs_GetBankPin(Pin, &Bank, &PinNumber);	IntrReg = 1 << PinNumber;	XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,			  ((Bank) * XGPIOPS_REG_MASK_OFFSET) +			  XGPIOPS_INTEN_OFFSET, IntrReg);}/****************************************************************************//**** This function disables the interrupts for the specified pins in the specified* 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	Mask is the bit mask of the pins for which interrupts are*		to be disabled. Bit positions of 1 will be disabled. Bit*		positions of 0 will keep the previous setting.** @return	None.** @note		None.******************************************************************************/void XGpioPs_IntrDisable(XGpioPs *InstancePtr, u8 Bank, u32 Mask){	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_INTDIS_OFFSET, Mask);}/****************************************************************************//**** This function disables the interrupts for the specified pin.** @param	InstancePtr is a pointer to the XGpioPs instance.* @param	Pin is the pin number for which the interrupt is to be disabled.*		Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.** @return	None.** @note		None.******************************************************************************/void XGpioPs_IntrDisablePin(XGpioPs *InstancePtr, int Pin){	u8 Bank;	u8 PinNumber;	u32 IntrReg = 0;	Xil_AssertVoid(InstancePtr != NULL);	Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);	Xil_AssertVoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);	/*	 * Get the Bank number and Pin number within the bank.	 */	XGpioPs_GetBankPin(Pin, &Bank, &PinNumber);	IntrReg =  1 << PinNumber;	XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,			  ((Bank) * XGPIOPS_REG_MASK_OFFSET) +			  XGPIOPS_INTDIS_OFFSET, IntrReg);}/****************************************************************************//**** This function returns the interrupt enable status for a 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	Enabled interrupt(s) in a 32-bit format. Bit positions with 1*		indicate that the interrupt for that pin is enabled, bit*		positions with 0 indicate that the interrupt for that pin is*		disabled.** @note		None.******************************************************************************/u32 XGpioPs_IntrGetEnabled(XGpioPs *InstancePtr, u8 Bank){	u32 IntrMask;	Xil_AssertNonvoid(InstancePtr != NULL);	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);	Xil_AssertNonvoid(Bank < XGPIOPS_MAX_BANKS);	IntrMask = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,				    ((Bank) * XGPIOPS_REG_MASK_OFFSET) +				    XGPIOPS_INTMASK_OFFSET);	return ~IntrMask;}/****************************************************************************//**** This function returns whether interrupts are enabled for the specified pin.** @param	InstancePtr is a pointer to the XGpioPs instance.* @param	Pin is the pin number for which the interrupt enable status*		is to be known.*		Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.** @return*		- TRUE if the interrupt is enabled.*		- FALSE if the interrupt is disabled.** @note		None.******************************************************************************/int XGpioPs_IntrGetEnabledPin(XGpioPs *InstancePtr, int Pin){	u8 Bank;	u8 PinNumber;	u32 IntrReg;	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);	IntrReg  = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,				    ((Bank) * XGPIOPS_REG_MASK_OFFSET) +				    XGPIOPS_INTMASK_OFFSET);	return (IntrReg & (1 << Pin)) ? TRUE : FALSE;}/****************************************************************************//**** This function returns interrupt status read from Interrupt Status Register.** @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	The value read from Interrupt Status Register.** @note		None.******************************************************************************/u32 XGpioPs_IntrGetStatus(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_INTSTS_OFFSET);}/****************************************************************************//**** This function returns interrupt enable status of the specified pin.** @param	InstancePtr is a pointer to the XGpioPs instance.* @param	Pin is the pin number for which the interrupt enable status*		is to be known.*		Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.** @return*		- TRUE if the interrupt has occurred.*		- FALSE if the interrupt has not occurred.** @note		None.******************************************************************************/int XGpioPs_IntrGetStatusPin(XGpioPs *InstancePtr, int Pin){	u8 Bank;	u8 PinNumber;	u32 IntrReg;	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);	IntrReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,				   ((Bank) * XGPIOPS_REG_MASK_OFFSET) +				   XGPIOPS_INTSTS_OFFSET);	return (IntrReg & (1 << Pin)) ? TRUE : FALSE;}/****************************************************************************//**** This function clears pending interrupt(s) with the provided mask. This* function should be called after the software has serviced the interrupts* that are pending.** @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	Mask is the mask of the interrupts to be cleared. Bit positions*		of 1 will be cleared. Bit positions of 0 will not change the*		previous interrupt status.** @note		None.******************************************************************************/void XGpioPs_IntrClear(XGpioPs *InstancePtr, u8 Bank, u32 Mask){	Xil_AssertVoid(InstancePtr != NULL);	Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);	Xil_AssertVoid(Bank < XGPIOPS_MAX_BANKS);	/*	 * Clear the currently pending interrupts.	 */	XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,			  ((Bank) * XGPIOPS_REG_MASK_OFFSET) +			  XGPIOPS_INTSTS_OFFSET, Mask);}/****************************************************************************//**** This function clears the specified pending interrupt. This function should be* called after the software has serviced the interrupts that are pending.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -