Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/device_drivers/AD7790/ad7790.h

raw symbols SCIP
1 /***************************************************************************//**
2 * @file ad7790.c
3 * @brief Header file of AD7790 Driver for Microblaze processor.
4 * @author Lucian Sin ([email protected])
5 *
6 *******************************************************************************
7 * Copyright 2014(c) Analog Devices, Inc.
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without modification,
12 * 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, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34 * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 ******************************************************************************/
41 #ifndef _ad7790_H_
42 #define _ad7790_H_
43
44 /******************************************************************************/
45 /******************************* Include Files ********************************/
46 /******************************************************************************/
47 #include "xil_types.h"
48 #include "xparameters.h"
49
50 /******************************************************************************/
51 /********************** Macros and Constants Definitions **********************/
52 /******************************************************************************/
53 #define AD7790_SLAVE_ID 1
54
55 /******************************************************************************/
56 /******************************** AD7790 **************************************/
57 /******************************************************************************/
58
59 /* AD7790 Registers */
60 #define AD7790_REG_COMM 0 // Communications Register (WO, 8-bit)
61 #define AD7790_REG_STAT 0 // Status Register (RO, 8-bit)
62 #define AD7790_REG_MODE 1 // Mode Register (RW, 8-bit)
63 #define AD7790_REG_FILTER 2 // Mode Register (RW, 8-bit)
64 #define AD7790_REG_DATA 3 // Data Register (RO, 16-bit)
65
66 /* AD7790_REG_COMM Bits */
67 #define AD7790_COMM_WEN (1 << 7) // Write Enable - active low
68 #define AD7790_COMM_ADDR(x) (((x) & 0x3) << 4) // Register Address
69 #define AD7790_COMM_WRITE (0 << 3) // Write Operation
70 #define AD7790_COMM_READ (1 << 3) // Read Operation
71 #define AD7790_COMM_CREAD (1 << 2) // Continuous Read of Data Register
72 #define AD7790_COMM_CH(x) ((x) & 0x3) // Channel Selection
73
74 /* AD7790_REG_STAT Bits */
75 #define AD7790_STAT_RDY (1 << 7) // Ready bit for ADC
76 #define AD7790_STAT_ERR (1 << 6) // ADC Error Bit
77 #define AD7790_STAT_WL (0 << 2) // 0 if the device is AD7790
78 #define AD7790_STAT_CH1 (1 << 1) // Channel 1 bit
79 #define AD7790_STAT_CH0 (1 << 0) // Channel 2 bit
80
81 /* AD7790_REG_MODE */
82 #define AD7790_MODE_SEL(x) (((x) & 0x3) << 6) // Mode Select
83 #define AD7790_RANGE_SEL(x) (((x) & 0x3) << 4) // Range Select
84 #define AD7790_MODE_BO (1 << 3) // Burnout Current Enable Bit
85 #define AD7790_MODE_BUF (1 << 1) // Buffered Mode Enable
86
87 /* AD7790_MODE_SEL(x) options */
88 #define AD7790_MODE_CONT 0 // Continuous Conversion Mode
89 #define AD7790_MODE_SINGLE 2 // Single Conversion Mode
90 #define AD7790_MODE_PWRDN 3 // Power-Down Mode
91
92 /* AD7790_RANGE_SEL(x) options */
93 #define AD7790_RANGE_DIV_1 0 // -Vref to +Vref input range
94 #define AD7790_RANGE_DIV_2 1 // -Vref/2 to +Vref/2 input range
95 #define AD7790_RANGE_DIV_4 2 // -Vref/4 to +Vref/4 input range
96 #define AD7790_RANGE_DIV_8 3 // -Vref/8 to +Vref/8 input range
97
98 /* AD7790_REG_FILTER */
99 #define AD7790_FILTER_CDIV(x) (((x) & 0x3) << 4) // Divide clock.
100 #define AD7790_FILTER_FS(x) ((x) & 0x7) // Output update rate.
101
102 /* AD7790_FILTER_CDIV options */
103 #define AD7790_FILTER_CDIV_NORMAL 0 // Normal Mode
104 #define AD7790_FILTER_CDIV_DIV2 1 // Clock Divided by 2
105 #define AD7790_FILTER_CDIV_DIV4 2 // Clock Divided by 4
106 #define AD7790_FILTER_CDIV_DIV8 3 // Clock Divided by 8
107
108 /******************************************************************************/
109 /************************** Functions Declarations ****************************/
110 /******************************************************************************/
111
112 /* Initializes SPI and initial values for AD7790 device. */
113 char AD7790_Init(void);
114
115 /* Reads data from AD7790. */
116 unsigned long AD7790_Read(unsigned char regAddress,
117 unsigned char bytesNumber);
118
119 /* Writes data to AD7790. */
120 void AD7790_Write(unsigned char regAddress,
121 unsigned char regData);
122
123 /* Converts 24-bit raw data to millivolts. */
124 float AD7790_ConvertToVoltage(unsigned long rawData,
125 float vRef,
126 unsigned char polarity);
127
128 /* Resets the serial interface with the AD7790. */
129 void AD7790_Reset(void);
130
131 #endif /* ad7790_H_ */