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