no-OS
ad7280a.h
Go to the documentation of this file.
1 /**************************************************************************/
42 #ifndef _AD7280A_H_
43 #define _AD7280A_H_
44 
45 
46 /******************************************************************************/
47 /***************************** Include Files **********************************/
48 /******************************************************************************/
49 #include <stdint.h>
50 #include "no_os_delay.h"
51 #include "no_os_gpio.h"
52 #include "no_os_spi.h"
53 
54 /******************************************************************************/
55 /********************** Macros and Constants Definitions **********************/
56 /******************************************************************************/
57 /* GPIOs */
58 #define AD7280A_PD_OUT no_os_gpio_direction_output(dev->gpio_pd, \
59  NO_OS_GPIO_HIGH)
60 #define AD7280A_PD_HIGH no_os_gpio_set_value(dev->gpio_pd, \
61  NO_OS_GPIO_HIGH)
62 #define AD7280A_PD_LOW no_os_gpio_set_value(dev->gpio_pd, \
63  NO_OS_GPIO_LOW)
64 #define AD7280A_CNVST_OUT no_os_gpio_direction_output(dev->gpio_cnvst, \
65  NO_OS_GPIO_HIGH)
66 #define AD7280A_CNVST_HIGH no_os_gpio_set_value(dev->gpio_cnvst, \
67  NO_OS_GPIO_HIGH)
68 #define AD7280A_CNVST_LOW no_os_gpio_set_value(dev->gpio_cnvst, \
69  NO_OS_GPIO_LOW)
70 
71 #define AD7280A_ALERT_IN no_os_gpio_direction_input(dev->gpio_alert)
72 #define AD7280_ALERT (1 << 6)
73 
74 /* Acquisition time */
75 #define AD7280A_ACQ_TIME_400ns 0
76 #define AD7280A_ACQ_TIME_800ns 1
77 #define AD7280A_ACQ_TIME_1200ns 2
78 #define AD7280A_ACQ_TIME_1600ns 3
79 
80 /* Conversion averaging */
81 #define AD7280A_CONV_AVG_DIS 0
82 #define AD7280A_CONV_AVG_2 1
83 #define AD7280A_CONV_AVG_4 2
84 #define AD7280A_CONV_AVG_8 3
85 
86 /* Alert register bits */
87 #define AD7280A_ALERT_REMOVE_VIN5 (1 << 2)
88 #define AD7280A_ALERT_REMOVE_VIN4_VIN5 (2 << 2)
89 #define AD7280A_ALERT_REMOVE_AUX5 (1 << 0)
90 #define AD7280A_ALERT_REMOVE_AUX4_AUX5 (2 << 0)
91 
92 /* Registers */
93 #define AD7280A_CELL_VOLTAGE_1 0x0 /* D11 to D0, Read only */
94 #define AD7280A_CELL_VOLTAGE_2 0x1 /* D11 to D0, Read only */
95 #define AD7280A_CELL_VOLTAGE_3 0x2 /* D11 to D0, Read only */
96 #define AD7280A_CELL_VOLTAGE_4 0x3 /* D11 to D0, Read only */
97 #define AD7280A_CELL_VOLTAGE_5 0x4 /* D11 to D0, Read only */
98 #define AD7280A_CELL_VOLTAGE_6 0x5 /* D11 to D0, Read only */
99 #define AD7280A_AUX_ADC_1 0x6 /* D11 to D0, Read only */
100 #define AD7280A_AUX_ADC_2 0x7 /* D11 to D0, Read only */
101 #define AD7280A_AUX_ADC_3 0x8 /* D11 to D0, Read only */
102 #define AD7280A_AUX_ADC_4 0x9 /* D11 to D0, Read only */
103 #define AD7280A_AUX_ADC_5 0xA /* D11 to D0, Read only */
104 #define AD7280A_AUX_ADC_6 0xB /* D11 to D0, Read only */
105 #define AD7280A_SELF_TEST 0xC /* D11 to D0, Read only */
106 #define AD7280A_CONTROL_HB 0xD /* D15 to D8, Read/write */
107 #define AD7280A_CONTROL_LB 0xE /* D7 to D0, Read/write */
108 #define AD7280A_CELL_OVERVOLTAGE 0xF /* D7 to D0, Read/write */
109 #define AD7280A_CELL_UNDERVOLTAGE 0x10 /* D7 to D0, Read/write */
110 #define AD7280A_AUX_ADC_OVERVOLTAGE 0x11 /* D7 to D0, Read/write */
111 #define AD7280A_AUX_ADC_UNDERVOLTAGE 0x12 /* D7 to D0, Read/write */
112 #define AD7280A_ALERT 0x13 /* D7 to D0, Read/write */
113 #define AD7280A_CELL_BALANCE 0x14 /* D7 to D0, Read/write */
114 #define AD7280A_CB1_TIMER 0x15 /* D7 to D0, Read/write */
115 #define AD7280A_CB2_TIMER 0x16 /* D7 to D0, Read/write */
116 #define AD7280A_CB3_TIMER 0x17 /* D7 to D0, Read/write */
117 #define AD7280A_CB4_TIMER 0x18 /* D7 to D0, Read/write */
118 #define AD7280A_CB5_TIMER 0x19 /* D7 to D0, Read/write */
119 #define AD7280A_CB6_TIMER 0x1A /* D7 to D0, Read/write */
120 #define AD7280A_PD_TIMER 0x1B /* D7 to D0, Read/write */
121 #define AD7280A_READ 0x1C /* D7 to D0, Read/write */
122 #define AD7280A_CNVST_N_CONTROL 0x1D /* D7 to D0, Read/write */
123 
124 /* Bits and Masks */
125 #define AD7280A_CTRL_HB_CONV_INPUT_ALL (0 << 6)
126 #define AD7280A_CTRL_HB_CONV_INPUT_6CELL_AUX1_3_4 (1 << 6)
127 #define AD7280A_CTRL_HB_CONV_INPUT_6CELL (2 << 6)
128 #define AD7280A_CTRL_HB_CONV_INPUT_SELF_TEST (3 << 6)
129 #define AD7280A_CTRL_HB_CONV_RES_READ_ALL (0 << 4)
130 #define AD7280A_CTRL_HB_CONV_RES_READ_6CELL_AUX1_3_4 (1 << 4)
131 #define AD7280A_CTRL_HB_CONV_RES_READ_6CELL (2 << 4)
132 #define AD7280A_CTRL_HB_CONV_RES_READ_NO (3 << 4)
133 #define AD7280A_CTRL_HB_CONV_START_CNVST (0 << 3)
134 #define AD7280A_CTRL_HB_CONV_START_CS (1 << 3)
135 #define AD7280A_CTRL_HB_CONV_AVG_DIS (0 << 1)
136 #define AD7280A_CTRL_HB_CONV_AVG_2 (1 << 1)
137 #define AD7280A_CTRL_HB_CONV_AVG_4 (2 << 1)
138 #define AD7280A_CTRL_HB_CONV_AVG_8 (3 << 1)
139 #define AD7280A_CTRL_HB_CONV_AVG(x) ((x) << 1)
140 #define AD7280A_CTRL_HB_PWRDN_SW (1 << 0)
141 
142 #define AD7280A_CTRL_LB_SWRST (1 << 7)
143 #define AD7280A_CTRL_LB_ACQ_TIME_400ns (0 << 5)
144 #define AD7280A_CTRL_LB_ACQ_TIME_800ns (1 << 5)
145 #define AD7280A_CTRL_LB_ACQ_TIME_1200ns (2 << 5)
146 #define AD7280A_CTRL_LB_ACQ_TIME_1600ns (3 << 5)
147 #define AD7280A_CTRL_LB_ACQ_TIME(x) ((x) << 5)
148 #define AD7280A_CTRL_LB_MUST_SET (1 << 4)
149 #define AD7280A_CTRL_LB_THERMISTOR_EN (1 << 3)
150 #define AD7280A_CTRL_LB_LOCK_DEV_ADDR (1 << 2)
151 #define AD7280A_CTRL_LB_INC_DEV_ADDR (1 << 1)
152 #define AD7280A_CTRL_LB_DAISY_CHAIN_RB_EN (1 << 0)
153 
154 #define AD7280A_ALERT_GEN_STATIC_HIGH (1 << 6)
155 #define AD7280A_ALERT_RELAY_SIG_CHAIN_DOWN (3 << 6)
156 
157 #define AD7280A_ALL_CELLS (0xAD << 16)
158 
159 #define AD7280A_DEVADDR_MASTER 0
160 #define AD7280A_DEVADDR_ALL 0x1F
161 
162 /* Value to be sent when readings are performed */
163 #define AD7280A_READ_TXVAL 0xF800030A
164 
165 #define NUMBITS_READ 22 // Number of bits for CRC when reading
166 #define NUMBITS_WRITE 21 // Number of bits for CRC when writing
167 
168 /******************************************************************************/
169 /*************************** Types Declarations *******************************/
170 /******************************************************************************/
171 struct ad7280a_dev {
172  /* SPI */
174  /* GPIO */
178  /* Device Settings */
179  uint32_t read_data[24];
180  float cell_voltage[12];
181  float aux_adc[12];
182 };
183 
185  /* SPI */
187  /* GPIO */
191 };
192 
193 /*****************************************************************************/
194 /************************ Functions Declarations *****************************/
195 /*****************************************************************************/
196 /* Initializes the communication with the device. */
197 int8_t ad7280a_init(struct ad7280a_dev **device,
199 
200 /* Free the resources allocated by AD7280A_Init(). */
201 int32_t ad7280a_remove(struct ad7280a_dev *dev);
202 
203 /* Reads/transmits 32 data bits from/to AD7280A. */
204 uint32_t ad7280a_transfer_32bits(struct ad7280a_dev *dev,
205  uint32_t data);
206 
207 /* Computes the CRC value for a write transmission, and prepares the complete
208  write codeword */
209 uint32_t ad7280a_crc_write(uint32_t message);
210 
211 /* Checks the received message if the received CRC and computed CRC are
212 the same. */
213 int32_t ad7280a_crc_read(uint32_t message);
214 
215 /* Performs a read from all registers on 2 devices. */
216 int8_t ad7280a_convert_read_all(struct ad7280a_dev *dev);
217 
218 /* Converts acquired data to float values. */
219 int8_t ad7280a_convert_data_all(struct ad7280a_dev *dev);
220 
221 /* Reads the register content of one selected register. */
222 int16_t ad7280a_read_register(struct ad7280a_dev *dev,
223  uint8_t dev_addr,
224  uint8_t read_reg);
225 
226 /* Reads the conversion of one channel. */
227 int16_t ad7280a_read_conversion(struct ad7280a_dev *dev,
228  uint8_t dev_addr,
229  uint8_t read_reg);
230 
231 /* Converts the input data to a voltage value. */
232 float ad7280a_convert_data(uint8_t type,
233  uint16_t data);
234 
235 /* Writes the content of one selected register from the selected device. */
236 void ad7280a_write_register(struct ad7280a_dev *dev,
237  uint8_t dev_addr,
238  uint8_t read_reg,
239  uint8_t reg_val);
240 
241 /* Performs the self test for two devices(one master and one slave). */
242 void ad7280a_selftest_all(struct ad7280a_dev *dev,
243  float *self_test_reg_a,
244  float *self_test_reg_b);
245 
246 /* Reads the value of Alert Pin from the device. */
247 uint8_t ad7280a_alert_pin(struct ad7280a_dev *dev);
248 
249 #endif /*_AD7280A_H_*/
AD7280A_AUX_ADC_UNDERVOLTAGE
#define AD7280A_AUX_ADC_UNDERVOLTAGE
Definition: ad7280a.h:111
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:85
ad7280a_write_register
void ad7280a_write_register(struct ad7280a_dev *dev, uint8_t dev_addr, uint8_t read_reg, uint8_t reg_val)
Definition: ad7280a.c:548
AD7280A_READ_TXVAL
#define AD7280A_READ_TXVAL
Definition: ad7280a.h:163
ad7280a_read_register
int16_t ad7280a_read_register(struct ad7280a_dev *dev, uint8_t dev_addr, uint8_t read_reg)
Definition: ad7280a.c:384
ad7280a_dev::gpio_cnvst
struct no_os_gpio_desc * gpio_cnvst
Definition: ad7280a.h:176
ad7280a_remove
int32_t ad7280a_remove(struct ad7280a_dev *dev)
Free the resources allocated by AD7280A_Init().
Definition: ad7280a.c:126
no_os_spi_write_and_read
int32_t no_os_spi_write_and_read(struct no_os_spi_desc *desc, uint8_t *data, uint16_t bytes_number)
Write and read data to/from SPI.
Definition: no_os_spi.c:82
AD7280A_CNVST_HIGH
#define AD7280A_CNVST_HIGH
Definition: ad7280a.h:66
AD7280A_CELL_UNDERVOLTAGE
#define AD7280A_CELL_UNDERVOLTAGE
Definition: ad7280a.h:109
ad7280a_dev::cell_voltage
float cell_voltage[12]
Definition: ad7280a.h:180
ad7280a_read_register
int16_t ad7280a_read_register(struct ad7280a_dev *dev, uint8_t dev_addr, uint8_t read_reg)
Definition: ad7280a.c:384
no_os_spi.h
Header file of SPI Interface.
ad7280a_dev::spi_desc
no_os_spi_desc * spi_desc
Definition: ad7280a.h:173
AD7280A_CTRL_LB_LOCK_DEV_ADDR
#define AD7280A_CTRL_LB_LOCK_DEV_ADDR
Definition: ad7280a.h:150
no_os_gpio_get_value
int32_t no_os_gpio_get_value(struct no_os_gpio_desc *desc, uint8_t *value)
Get the value of the specified GPIO.
Definition: no_os_gpio.c:177
AD7280A_CELL_VOLTAGE_1
#define AD7280A_CELL_VOLTAGE_1
Definition: ad7280a.h:93
no_os_delay.h
Header file of Delay functions.
ad7280a_init
int8_t ad7280a_init(struct ad7280a_dev **device, struct ad7280a_init_param init_param)
Definition: ad7280a.c:63
AD7280A_CB1_TIMER
#define AD7280A_CB1_TIMER
Definition: ad7280a.h:114
ad7280a_convert_data_all
int8_t ad7280a_convert_data_all(struct ad7280a_dev *dev)
Definition: ad7280a.c:353
NUMBITS_WRITE
#define NUMBITS_WRITE
Definition: ad7280a.h:166
device
Definition: ad9361_util.h:75
ad7280a_crc_read
int32_t ad7280a_crc_read(uint32_t message)
Definition: ad7280a.c:234
AD7280A_PD_TIMER
#define AD7280A_PD_TIMER
Definition: ad7280a.h:120
ad7280a_read_conversion
int16_t ad7280a_read_conversion(struct ad7280a_dev *dev, uint8_t dev_addr, uint8_t read_reg)
Definition: ad7280a.c:444
ad7280a_alert_pin
uint8_t ad7280a_alert_pin(struct ad7280a_dev *dev)
Definition: ad7280a.c:754
ad7280a_dev
Definition: ad7280a.h:171
AD7280A_CONTROL_LB
#define AD7280A_CONTROL_LB
Definition: ad7280a.h:107
AD7280A_CNVST_N_CONTROL
#define AD7280A_CNVST_N_CONTROL
Definition: ad7280a.h:122
AD7280A_PD_OUT
#define AD7280A_PD_OUT
Definition: ad7280a.h:58
AD7280A_CELL_OVERVOLTAGE
#define AD7280A_CELL_OVERVOLTAGE
Definition: ad7280a.h:108
AD7280A_CTRL_HB_CONV_RES_READ_NO
#define AD7280A_CTRL_HB_CONV_RES_READ_NO
Definition: ad7280a.h:132
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: delay.c:130
AD7280A_CONTROL_HB
#define AD7280A_CONTROL_HB
Definition: ad7280a.h:106
AD7280A_ALERT_IN
#define AD7280A_ALERT_IN
Definition: ad7280a.h:71
ad7280a_convert_data
float ad7280a_convert_data(uint8_t type, uint16_t data)
Definition: ad7280a.c:518
ad7280a_crc_read
int32_t ad7280a_crc_read(uint32_t message)
Definition: ad7280a.c:234
ad7280a_convert_read_all
int8_t ad7280a_convert_read_all(struct ad7280a_dev *dev)
Definition: ad7280a.c:289
AD7280A_CELL_BALANCE
#define AD7280A_CELL_BALANCE
Definition: ad7280a.h:113
AD7280A_CNVST_OUT
#define AD7280A_CNVST_OUT
Definition: ad7280a.h:64
ad7280a_convert_data
float ad7280a_convert_data(uint8_t type, uint16_t data)
Definition: ad7280a.c:518
ad7280a_write_register
void ad7280a_write_register(struct ad7280a_dev *dev, uint8_t dev_addr, uint8_t read_reg, uint8_t reg_val)
Definition: ad7280a.c:548
ad7280a_convert_read_all
int8_t ad7280a_convert_read_all(struct ad7280a_dev *dev)
Definition: ad7280a.c:289
AD7280A_CB2_TIMER
#define AD7280A_CB2_TIMER
Definition: ad7280a.h:115
ad7280a_init_param::spi_init
no_os_spi_init_param spi_init
Definition: ad7280a.h:186
AD7280A_CB5_TIMER
#define AD7280A_CB5_TIMER
Definition: ad7280a.h:118
ad7280a_read_conversion
int16_t ad7280a_read_conversion(struct ad7280a_dev *dev, uint8_t dev_addr, uint8_t read_reg)
Definition: ad7280a.c:444
ad7280a_selftest_all
void ad7280a_selftest_all(struct ad7280a_dev *dev, float *self_test_reg_a, float *self_test_reg_b)
Definition: ad7280a.c:689
ad7280a_init_param::gpio_alert
struct no_os_gpio_init_param gpio_alert
Definition: ad7280a.h:190
no_os_gpio_remove
int32_t no_os_gpio_remove(struct no_os_gpio_desc *desc)
Free the resources allocated by no_os_gpio_get().
Definition: no_os_gpio.c:95
AD7280A_SELF_TEST
#define AD7280A_SELF_TEST
Definition: ad7280a.h:105
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:132
AD7280A_CTRL_HB_CONV_RES_READ_ALL
#define AD7280A_CTRL_HB_CONV_RES_READ_ALL
Definition: ad7280a.h:129
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:102
ad7280a.h
ad7280a_crc_write
uint32_t ad7280a_crc_write(uint32_t message)
Definition: ad7280a.c:182
AD7280A_READ
#define AD7280A_READ
Definition: ad7280a.h:121
AD7280A_AUX_ADC_OVERVOLTAGE
#define AD7280A_AUX_ADC_OVERVOLTAGE
Definition: ad7280a.h:110
AD7280A_PD_HIGH
#define AD7280A_PD_HIGH
Definition: ad7280a.h:60
no_os_gpio_get
int32_t no_os_gpio_get(struct no_os_gpio_desc **desc, const struct no_os_gpio_init_param *param)
Obtain the GPIO decriptor.
Definition: no_os_gpio.c:55
ad7280a_init_param::gpio_cnvst
struct no_os_gpio_init_param gpio_cnvst
Definition: ad7280a.h:189
AD7280A_CTRL_LB_MUST_SET
#define AD7280A_CTRL_LB_MUST_SET
Definition: ad7280a.h:148
ad7280a_crc_write
uint32_t ad7280a_crc_write(uint32_t message)
Definition: ad7280a.c:182
AD7280A_CTRL_HB_CONV_AVG_8
#define AD7280A_CTRL_HB_CONV_AVG_8
Definition: ad7280a.h:138
ad7280a_dev::aux_adc
float aux_adc[12]
Definition: ad7280a.h:181
NUMBITS_READ
#define NUMBITS_READ
Definition: ad7280a.h:165
ad7280a_init_param::gpio_pd
struct no_os_gpio_init_param gpio_pd
Definition: ad7280a.h:188
AD7280A_CNVST_LOW
#define AD7280A_CNVST_LOW
Definition: ad7280a.h:68
ad7280a_init_param
Definition: ad7280a.h:184
AD7280A_CB4_TIMER
#define AD7280A_CB4_TIMER
Definition: ad7280a.h:117
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:96
ad7280a_transfer_32bits
uint32_t ad7280a_transfer_32bits(struct ad7280a_dev *dev, uint32_t data)
Definition: ad7280a.c:149
ad7280a_init
int8_t ad7280a_init(struct ad7280a_dev **device, struct ad7280a_init_param init_param)
Definition: ad7280a.c:63
ad7280a_convert_data_all
int8_t ad7280a_convert_data_all(struct ad7280a_dev *dev)
Definition: ad7280a.c:353
AD7280A_ALERT
#define AD7280A_ALERT
Definition: ad7280a.h:112
no_os_spi_remove
int32_t no_os_spi_remove(struct no_os_spi_desc *desc)
Free the resources allocated by no_os_spi_init().
Definition: no_os_spi.c:70
no_os_gpio.h
Header file of GPIO Interface.
ad7280a_dev::gpio_pd
struct no_os_gpio_desc * gpio_pd
Definition: ad7280a.h:175
AD7280A_CTRL_HB_CONV_INPUT_ALL
#define AD7280A_CTRL_HB_CONV_INPUT_ALL
Definition: ad7280a.h:125
ad7280a_remove
int32_t ad7280a_remove(struct ad7280a_dev *dev)
Free the resources allocated by AD7280A_Init().
Definition: ad7280a.c:126
no_os_spi_init
int32_t no_os_spi_init(struct no_os_spi_desc **desc, const struct no_os_spi_init_param *param)
Initialize the SPI communication peripheral.
Definition: no_os_spi.c:51
ad7280a_alert_pin
uint8_t ad7280a_alert_pin(struct ad7280a_dev *dev)
Definition: ad7280a.c:754
AD7280A_CTRL_HB_CONV_INPUT_SELF_TEST
#define AD7280A_CTRL_HB_CONV_INPUT_SELF_TEST
Definition: ad7280a.h:128
ad7280a_transfer_32bits
uint32_t ad7280a_transfer_32bits(struct ad7280a_dev *dev, uint32_t data)
Definition: ad7280a.c:149
ad7280a_dev::read_data
uint32_t read_data[24]
Definition: ad7280a.h:179
ad7280a_selftest_all
void ad7280a_selftest_all(struct ad7280a_dev *dev, float *self_test_reg_a, float *self_test_reg_b)
Definition: ad7280a.c:689
AD7280A_CTRL_LB_DAISY_CHAIN_RB_EN
#define AD7280A_CTRL_LB_DAISY_CHAIN_RB_EN
Definition: ad7280a.h:152
AD7280A_CB3_TIMER
#define AD7280A_CB3_TIMER
Definition: ad7280a.h:116
ad7280a_dev::gpio_alert
struct no_os_gpio_desc * gpio_alert
Definition: ad7280a.h:177
AD7280A_CB6_TIMER
#define AD7280A_CB6_TIMER
Definition: ad7280a.h:119
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:112