📄 xadcps.c
字号:
/******************************************************************************** (c) Copyright 2012 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 xadcps.c** This file contains the driver API functions that can be used to access* the XADC device.** Refer to the xadcps.h header file for more information about this driver.** @note None.** <pre>** MODIFICATION HISTORY:** Ver Who Date Changes* ----- ----- -------- -----------------------------------------------------* 1.00a ssb 12/22/11 First release based on the XPS/AXI xadc driver** </pre>******************************************************************************//***************************** Include Files ********************************/#include "xadcps.h"/************************** Constant Definitions ****************************//**************************** Type Definitions ******************************//***************** Macros (Inline Functions) Definitions ********************//************************** Function Prototypes *****************************/void XAdcPs_WriteInternalReg(XAdcPs *InstancePtr, u32 RegOffset, u32 Data);u32 XAdcPs_ReadInternalReg(XAdcPs *InstancePtr, u32 RegOffset);/************************** Variable Definitions ****************************//*****************************************************************************//**** This function initializes a specific XAdcPs device/instance. This function* must be called prior to using the XADC device.** @param InstancePtr is a pointer to the XAdcPs instance.* @param ConfigPtr points to the XAdcPs device configuration structure.* @param EffectiveAddr is the device base address in the virtual memory* address space. If the address translation is not used then the* physical address is passed.* Unexpected errors may occur if the address mapping is changed* after this function is invoked.** @return* - XST_SUCCESS if successful.** @note The user needs to first call the XAdcPs_LookupConfig() API* which returns the Configuration structure pointer which is* passed as a parameter to the XAdcPs_CfgInitialize() API.*******************************************************************************/int XAdcPs_CfgInitialize(XAdcPs *InstancePtr, XAdcPs_Config *ConfigPtr, u32 EffectiveAddr){ u32 RegValue; /* * Assert the input arguments. */ Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(ConfigPtr != NULL); /* * Set the values read from the device config and the base address. */ InstancePtr->Config.DeviceId = ConfigPtr->DeviceId; InstancePtr->Config.BaseAddress = EffectiveAddr; /* Write Unlock value to Device Config Unlock register */ XAdcPs_WriteReg((InstancePtr)->Config.BaseAddress, XADCPS_UNLK_OFFSET, XADCPS_UNLK_VALUE); /* Enable the PS access of xadc and set FIFO thresholds */ RegValue = XAdcPs_ReadReg((InstancePtr)->Config.BaseAddress, XADCPS_CFG_OFFSET); RegValue = RegValue | XADCPS_CFG_ENABLE_MASK | XADCPS_CFG_CFIFOTH_MASK | XADCPS_CFG_DFIFOTH_MASK; XAdcPs_WriteReg((InstancePtr)->Config.BaseAddress, XADCPS_CFG_OFFSET, RegValue); /* Release xadc from reset */ XAdcPs_WriteReg((InstancePtr)->Config.BaseAddress, XADCPS_MCTL_OFFSET, 0x00); /* * Indicate the instance is now ready to use and * initialized without error. */ InstancePtr->IsReady = XIL_COMPONENT_IS_READY; return XST_SUCCESS;}/****************************************************************************//**** The functions sets the contents of the Config Register.** @param InstancePtr is a pointer to the XAdcPs instance.* @param Data is the 32 bit data to be written to the Register.** @return None.** @note None.******************************************************************************/void XAdcPs_SetConfigRegister(XAdcPs *InstancePtr, u32 Data){ /* * Assert the arguments. */ Xil_AssertVoid(InstancePtr != NULL); Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); XAdcPs_WriteReg((InstancePtr)->Config.BaseAddress, XADCPS_CFG_OFFSET, Data);}/****************************************************************************//**** The functions reads the contents of the Config Register.** @param InstancePtr is a pointer to the XAdcPs instance.** @return A 32-bit value representing the contents of the Config Register.* Use the XADCPS_SR_*_MASK constants defined in xadcps_hw.h to* interpret the returned value.** @note None.******************************************************************************/u32 XAdcPs_GetConfigRegister(XAdcPs *InstancePtr){ /* * Assert the arguments. */ Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); /* * Read the Config Register and return the value. */ return XAdcPs_ReadReg((InstancePtr)->Config.BaseAddress, XADCPS_CFG_OFFSET);}/****************************************************************************//**** The functions reads the contents of the Miscellaneous Status Register.** @param InstancePtr is a pointer to the XAdcPs instance.** @return A 32-bit value representing the contents of the Miscellaneous* Status Register. Use the XADCPS_MSTS_*_MASK constants defined* in xadcps_hw.h to interpret the returned value.** @note None.******************************************************************************/u32 XAdcPs_GetMiscStatus(XAdcPs *InstancePtr){ /* * Assert the arguments. */ Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); /* * Read the Miscellaneous Status Register and return the value. */ return XAdcPs_ReadReg((InstancePtr)->Config.BaseAddress, XADCPS_MSTS_OFFSET);}/****************************************************************************//**** The functions sets the contents of the Miscellaneous Control register.** @param InstancePtr is a pointer to the XAdcPs instance.* @param Data is the 32 bit data to be written to the Register.** @return None.** @note None.******************************************************************************/void XAdcPs_SetMiscCtrlRegister(XAdcPs *InstancePtr, u32 Data){ /* * Assert the arguments. */ Xil_AssertVoid(InstancePtr != NULL); Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); /* * Write to the Miscellaneous control register Register. */ XAdcPs_WriteReg((InstancePtr)->Config.BaseAddress, XADCPS_MCTL_OFFSET, Data);}/****************************************************************************//**** The functions reads the contents of the Miscellaneous control register.** @param InstancePtr is a pointer to the XAdcPs instance.** @return A 32-bit value representing the contents of the Config Register.* Use the XADCPS_SR_*_MASK constants defined in xadcps_hw.h to* interpret the returned value.** @note None.******************************************************************************/u32 XAdcPs_GetMiscCtrlRegister(XAdcPs *InstancePtr){ /* * Assert the arguments. */ Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); /* * Read the Miscellaneous control register and return the value. */ return XAdcPs_ReadReg((InstancePtr)->Config.BaseAddress, XADCPS_MCTL_OFFSET);}/*****************************************************************************//**** This function resets the XADC Hard Macro in the device.** @param InstancePtr is a pointer to the Xxadc instance.** @return None.** @note None.*******************************************************************************/void XAdcPs_Reset(XAdcPs *InstancePtr){ /* * Assert the arguments. */ Xil_AssertVoid(InstancePtr != NULL); Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); /* * Generate the reset by Control * register and release from reset */ XAdcPs_WriteReg((InstancePtr)->Config.BaseAddress, XADCPS_MCTL_OFFSET, 0x10); XAdcPs_WriteReg((InstancePtr)->Config.BaseAddress, XADCPS_MCTL_OFFSET, 0x00);}/****************************************************************************//**** Get the ADC converted data for the specified channel.** @param InstancePtr is a pointer to the XAdcPs instance.* @param Channel is the channel number. Use the XADCPS_CH_* defined in* the file xadcps.h.* The valid channels are* - 0 to 6* - 13 to 31** @return A 16-bit value representing the ADC converted data for the* specified channel. The XADC Monitor/ADC device guarantees* a 10 bit resolution for the ADC converted data and data is the* 10 MSB bits of the 16 data read from the device.** @note The channels 7,8,9 are used for calibration of the device and* hence there is no associated data with this channel.******************************************************************************/u16 XAdcPs_GetAdcData(XAdcPs *InstancePtr, u8 Channel){ u32 RegData; /* * Assert the arguments. */ Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); Xil_AssertNonvoid((Channel <= XADCPS_CH_VBRAM) || ((Channel >= XADCPS_CH_VCCPINT) && (Channel <= XADCPS_CH_AUX_MAX))); RegData = XAdcPs_ReadInternalReg(InstancePtr, (XADCPS_TEMP_OFFSET + Channel)); return (u16) RegData;}/****************************************************************************//**** This function gets the calibration coefficient data for the specified* parameter.** @param InstancePtr is a pointer to the XAdcPs instance.* @param CoeffType specifies the calibration coefficient* to be read. Use XADCPS_CALIB_* constants defined in xadcps.h to* specify the calibration coefficient to be read.** @return A 16-bit value representing the calibration coefficient.* The XADC device guarantees a 10 bit resolution for* the ADC converted data and data is the 10 MSB bits of the 16* data read from the device.** @note None.******************************************************************************/u16 XAdcPs_GetCalibCoefficient(XAdcPs *InstancePtr, u8 CoeffType){ u32 RegData; /* * Assert the arguments. */ Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); Xil_AssertNonvoid(CoeffType <= XADCPS_CALIB_GAIN_ERROR_COEFF); /* * Read the selected calibration coefficient. */ RegData = XAdcPs_ReadInternalReg(InstancePtr, (XADCPS_ADC_A_SUPPLY_CALIB_OFFSET + CoeffType)); return (u16) RegData;}/****************************************************************************//**** This function reads the Minimum/Maximum measurement for one of the* specified parameters. Use XADCPS_MAX_* and XADCPS_MIN_* constants defined in* xadcps.h to specify the parameters (Temperature, VccInt, VccAux, VBram,* VccPInt, VccPAux and VccPDro).** @param InstancePtr is a pointer to the XAdcPs instance.* @param MeasurementType specifies the parameter for which the* Minimum/Maximum measurement has to be read.* Use XADCPS_MAX_* and XADCPS_MIN_* constants defined in xadcps.h to* specify the data to be read.** @return A 16-bit value representing the maximum/minimum measurement for* specified parameter.* The XADC device guarantees a 10 bit resolution for* the ADC converted data and data is the 10 MSB bits of the 16* data read from the device.** @note None.******************************************************************************/u16 XAdcPs_GetMinMaxMeasurement(XAdcPs *InstancePtr, u8 MeasurementType){ u32 RegData; /* * Assert the arguments. */ Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); Xil_AssertNonvoid((MeasurementType <= XADCPS_MAX_VCCPDRO) || ((MeasurementType >= XADCPS_MIN_VCCPINT) && (MeasurementType <= XADCPS_MIN_VCCPDRO))) /* * Read and return the specified Minimum/Maximum measurement. */ RegData = XAdcPs_ReadInternalReg(InstancePtr, (XADCPS_MAX_TEMP_OFFSET + MeasurementType)); return (u16) RegData;}/****************************************************************************//**** This function sets the number of samples of averaging that is to be done for* all the channels in both the single channel mode and sequence mode of
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -