Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/device_drivers/CN0209/cn0209.h

raw symbols SCIP
1 /***************************************************************************//**
2 * @file cn0209.c
3 * @brief Header file of CN0209 Driver for Microblaze processor.
4 * @author Lucian Sin ([email protected])
5 *
6 *******************************************************************************
7 * Copyright 2013(c) Analog Devices, Inc.
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 * - Neither the name of Analog Devices, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 * - The use of this software may or may not infringe the patent rights
23 * of one or more patent holders. This license does not release you
24 * from the requirement that you obtain separate licenses from these
25 * patent holders to use this software.
26 * - Use of the software either in source or binary form, must be run
27 * on or directly connected to an Analog Devices Inc. component.
28 *
29 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED
30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY
31 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
33 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 *******************************************************************************/
41 #ifndef _CN0209_H_
42 #define _CN0209_H_
43
44 /*****************************************************************************/
45 /* Include Files */
46 /*****************************************************************************/
47 #include "xil_types.h"
48 #include "xparameters.h"
49
50 /******************************************************************************/
51 /* SPI Configuration */
52 /******************************************************************************/
53 #define AD7193_RDY_PIN (1 << 1)
54
55 /******************************************************************************/
56 /* CN0209 GPIO */
57 /******************************************************************************/
58 #define ADG1414_CS_PIN (1 << 0) // ADG1414 CS Pin.
59 #define ADT7310_CS_PIN (1 << 1) // ADT7310 CS Pin.
60 #define AD7193_CS_PIN (1 << 2) // AD7193 CS Pin.
61 #define AD7193_INT1_PIN (1 << 3) // INT1 Pin.
62 #define AD7193_INT2_PIN (1 << 5) // INT2 Pin.
63 #define AD7193_READY_PIN (1 << 7) // Data Ready Pin.
64
65 #define AD7193_CS_OUT GPIO2_PIN_OUT
66 #define AD7193_CS_LOW GPIO2_LOW
67 #define AD7193_CS_HIGH GPIO2_HIGH
68
69 #define ADT7310_CS_OUT GPIO1_PIN_OUT
70 #define ADT7310_CS_LOW GPIO1_LOW
71 #define ADT7310_CS_HIGH GPIO1_HIGH
72
73 #define ADG1414_CS_OUT GPIO0_PIN_OUT
74 #define ADG1414_CS_LOW GPIO0_LOW
75 #define ADG1414_CS_HIGH GPIO0_HIGH
76
77 /******************************************************************************/
78 /* AD7193 */
79 /******************************************************************************/
80 /* AD7193 Registers */
81 #define AD7193_REG_COMM 0 // Communications Register(WO, 8-bit)
82 #define AD7193_REG_STAT 0 // Status Register (RO, 8-bit)
83 #define AD7193_REG_MODE 1 // Mode Register (RW, 24-bit)
84 #define AD7193_REG_CONF 2 // Configuration Register (RW, 24-bit)
85 #define AD7193_REG_DATA 3 // Data Register (RO, 24-bit)
86 #define AD7193_REG_ID 4 // ID Register (RO, 8-bit)
87 #define AD7193_REG_GPOCON 5 // GPOCON Register (RW, 8-bit)
88 #define AD7193_REG_OFFSET 6 // Offset Register (RW, 24-bit)
89 #define AD7192_REG_FULLSCALE 7 // Full-Scale Register (RW, 24-bit)
90
91 /* AD7193 Communications Register Bits */
92 #define AD7193_COMM_WEN (1 << 7) // Write Enable
93 #define AD7193_COMM_WRITE (0 << 6) // Write Operation
94 #define AD7193_COMM_READ (1 << 6) // Read Operation
95 #define AD7193_COMM_ADDR(x) (((x) & 0x7) << 3) // Register Address
96 #define AD7193_COMM_CREAD (1 << 2) // Continuous Read
97
98 /* AD7193 Status Register Bits */
99 #define AD7193_STAT_RDY (1 << 7) // Ready
100 #define AD7193_STAT_ERR (1 << 6) // Error (Overrange, Underrange)
101 #define AD7193_STAT_NOREF (1 << 5) // Error no external reference
102 #define AD7193_STAT_PARITY (1 << 4) // Parity
103 #define AD7193_STAT_CH3 (1 << 2) // Channel 3
104 #define AD7193_STAT_CH2 (1 << 2) // Channel 2
105 #define AD7193_STAT_CH1 (1 << 1) // Channel 1
106 #define AD7193_STAT_CH0 (1 << 0) // Channel 0
107
108 /* AD7193 Mode Register Bits */
109 #define AD7193_MODE_SEL(x) (((x) & 0x7) << 21) // Operation Mode Select
110 #define AD7193_MODE_DAT_STA (1 << 20) // Status Register transmission
111 #define AD7193_MODE_CLKSRC(x) (((x) & 0x3) << 18) // Clock Source Select
112 #define AD7193_MODE_AVG(x) (((x) & 0x3) << 16) // Fast settling filter
113 #define AD7193_MODE_SINC3 (1 << 15) // SINC3 Filter Select
114 #define AD7193_MODE_ENPAR (1 << 13) // Parity Enable
115 #define AD7193_MODE_CLKDIV (1 << 12) // Clock divide by 2
116 #define AD7193_MODE_SCYCLE (1 << 11) // Single cycle conversion
117 #define AD7193_MODE_REJ60 (1 << 10) // 50/60Hz notch filter
118 #define AD7193_MODE_RATE(x) ((x) & 0x3FF) // Filter Update Rate Select
119
120 /* AD7193_MODE_SEL(x) options */
121 #define AD7193_MODE_CONT 0 // Continuous Conversion Mode
122 #define AD7193_MODE_SINGLE 1 // Single Conversion Mode
123 #define AD7193_MODE_IDLE 2 // Idle Mode
124 #define AD7193_MODE_PWRDN 3 // Power-Down Mode
125 #define AD7193_MODE_CAL_INT_ZERO 4 // Internal Zero-Scale Calibration
126 #define AD7193_MODE_CAL_INT_FULL 5 // Internal Full-Scale Calibration
127 #define AD7193_MODE_CAL_SYS_ZERO 6 // System Zero-Scale Calibration
128 #define AD7193_MODE_CAL_SYS_FULL 7 // System Full-Scale Calibration
129
130 /* AD7193_MODE_CLKSRC(x) options */
131 #define AD7193_MODE_CLK_EXT_MCLK1_2 0 // External 4.92 MHz Clock connected from MCLK1 to MCLK2
132 #define AD7193_MODE_CLK_EXT_MCLK2 1 // External Clock applied to MCLK2
133 #define AD7193_MODE_CLK_INT 2 // Internal 4.92 MHz Clock not available at the MCLK2 pin
134 #define AD7193_MODE_CLK_INT_CO 3 // Internal 4.92 MHz Clock available at the MCLK2 pin
135
136 /* AD7193 Configuration Register Bits */
137 #define AD7193_CONF_CHOP (1 << 23) // CHOP enable
138 #define AD7193_CONF_REFSEL (1 << 20) // REFIN1/REFIN2 Reference Select
139 #define AD7193_CONF_PSEUDO (1 << 18) // Pseudo differential analog inputs
140 #define AD7193_CONF_SHORT (1 << 17) // Short channel
141 #define AD7193_CONF_TEMP (1 << 16) // Temperature sensor
142 #define AD7193_CONF_CHAN(x) (((x) & 0xFF) << 8) // Channel select
143 #define AD7193_CONF_BURN (1 << 7) // Burnout current enable
144 #define AD7193_CONF_REFDET (1 << 6) // Reference detect enable
145 #define AD7193_CONF_BUF (1 << 4) // Buffered Mode Enable
146 #define AD7193_CONF_UNIPOLAR (1 << 3) // Unipolar/Bipolar Enable
147 #define AD7193_CONF_GAIN(x) ((x) & 0x7) // Gain Select
148
149 /* AD7193_CONF_GAIN(x) options */
150 #define AD7193_CONF_GAIN_1 0 // Gain 1, ADC Input Range +-2.5 V
151 #define AD7193_CONF_GAIN_8 3 // Gain 8, ADC Input Range +-312.5 mV
152 #define AD7193_CONF_GAIN_16 4 // Gain 16, ADC Input Range +-156.2 mV
153 #define AD7193_CONF_GAIN_32 5 // Gain 32, ADC Input Range +-78.125 mV
154 #define AD7193_CONF_GAIN_64 6 // Gain 64, ADC Input Range +-39.06 mV
155 #define AD7193_CONF_GAIN_128 7 // Gain 128, ADC Input Range +-19.53 mV
156
157 /* GPOCON Register Bits */
158 #define AD7193_GPOCON_BPDSW (1 << 6) // Bridge power-down switch enable
159 #define AD7193_GPOCON_GP32EN (1 << 5) // Digital Output P3 and P2 enable
160 #define AD7193_GPOCON_GP10EN (1 << 4) // Digital Output P1 and P0 enable
161 #define AD7193_GPOCON_P3DAT (1 << 3) // P3 state
162 #define AD7193_GPOCON_P2DAT (1 << 2) // P2 state
163 #define AD7193_GPOCON_P1DAT (1 << 1) // P1 state
164 #define AD7193_GPOCON_P0DAT (1 << 0) // P0 state
165
166 /******************************************************************************/
167 /* ADT7310 */
168 /******************************************************************************/
169 /* ADT7310 Registers */
170 #define ADT7310_REG_STATUS 0x00 // Status Register (RO, 8-bit)
171 #define ADT7310_REG_CONFIG 0x01 // Configuration Register (RW, 8-bit)
172 #define ADT7310_REG_TEMPERATURE 0x02 // Temperature value (RO, 16-bit)
173 #define ADT7310_REG_ID 0x03 // ID (RO, 8-bit)
174 #define ADT7310_REG_TCRIT 0x04 // TCRIT setpoint (RW, 16-bit)
175 #define ADT7310_REG_THYST 0x05 // THYST setpoint (RW, 16-bit)
176 #define ADT7310_REG_THIGH 0x06 // THIGH setpoint (RW, 16-bit)
177 #define ADT7310_REG_TLOW 0x07 // TLOW setpoint (RW, 16-bit)
178
179 /* ADT7310 Command */
180 #define ADT7310_CMD_WRITE (0 << 6) // Write Operation
181 #define ADT7310_CMD_READ (1 << 6) // Read Operation
182 #define ADT7310_CMD_ADDR(x) (((x) & 0x7) << 3) // Register Address
183 #define ADT7310_CMD_CREAD (1 << 2) // Continuous Read
184
185 /******************************************************************************/
186 /* Functions Prototypes */
187 /******************************************************************************/
188 /* Reads data from ADT7310. */
189 unsigned short ADT7310_Read(unsigned char regAddress,
190 unsigned char bytesNumber);
191
192 /* Writes data to ADT7310. */
193 void ADT7310_Write(unsigned char regAddress,
194 unsigned char bytesNumber,
195 unsigned short regData);
196
197 /* Reads the temperature from ADT7310 device. */
198 float ADT7310_TemperatureRead(void);
199
200 /* Resets the serial interface with the ADT7310. */
201 void ADT7310_Reset(void);
202
203 /* Reads data from AD7193. */
204 unsigned long AD7193_Read(unsigned char regAddress,
205 unsigned char bytesNumber);
206
207 /* Writes data to AD7193. */
208 void AD7193_Write(unsigned char regAddress,
209 unsigned char bytesNumber,
210 unsigned long regData);
211
212 /* Returns the result of a single conversion from AD7193. */
213 unsigned long AD7193_SingleConversion(void);
214
215 /* Reads the temperature from AD7193 device. */
216 float AD7193_TemperatureRead(void);
217
218 /* Converts 24-bit raw data to millivolts. */
219 float AD7193_ConvertToVolts(unsigned long rawData,
220 float vRef,
221 unsigned char gain,
222 unsigned char polarity);
223
224 /* Reset the serial interface with the AD7193. */
225 void AD7193_Reset(void);
226
227 /* Updates the state of the ADG1414's switches. */
228 void ADG1414_State (unsigned char switches);
229
230 /* Initializes SPI and initial values for CN0209 board. */
231 char CN0209_Init(void);
232
233 #endif /* CN0209_H_ */