no-OS
Loading...
Searching...
No Matches
ad738x.h
Go to the documentation of this file.
1/***************************************************************************/
35
36#ifndef SRC_AD738X_H_
37#define SRC_AD738X_H_
38
39#include "no_os_util.h"
40#include "no_os_spi.h"
41#ifdef XILINX_PLATFORM
42#include "clk_axi_clkgen.h"
43#endif
44
45/*
46 * AD738X registers definition
47 */
48#define AD738X_REG_NOP 0x00
49#define AD738X_REG_CONFIG1 0x01
50#define AD738X_REG_CONFIG2 0x02
51#define AD738X_REG_ALERT 0x03
52#define AD738X_REG_ALERT_LOW_TH 0x04
53#define AD738X_REG_ALERT_HIGH_TH 0x05
54
55/*
56 * AD738X_REG_CONFIG1
57 */
58#define AD738X_CONFIG1_CH_SEQ_MSK NO_OS_GENMASK(11, 10)
59#define AD738X_CONFIG1_CH_SEQ(x) (((x) & 0x3) << 10)
60#define AD738X_CONFIG1_OS_MODE_MSK NO_OS_BIT(9)
61#define AD738X_CONFIG1_OS_MODE(x) (((x) & 0x1) << 9)
62#define AD738X_CONFIG1_OSR_MSK NO_OS_GENMASK(8, 6)
63#define AD738X_CONFIG1_OSR(x) (((x) & 0x7) << 6)
64#define AD738X_CONFIG1_CRC_W_MSK NO_OS_BIT(5)
65#define AD738X_CONFIG1_CRC_W(x) (((x) & 0x1) << 5)
66#define AD738X_CONFIG1_CRC_R_MSK NO_OS_BIT(4)
67#define AD738X_CONFIG1_CRC_R(x) (((x) & 0x1) << 4)
68#define AD738X_CONFIG1_ALERTEN_MSK NO_OS_BIT(3)
69#define AD738X_CONFIG1_ALERTEN(x) (((x) & 0x1) << 3)
70#define AD738X_CONFIG1_RES_MSK NO_OS_BIT(2)
71#define AD738X_CONFIG1_RES(x) (((x) & 0x1) << 2)
72#define AD738X_CONFIG1_REFSEL_MSK NO_OS_BIT(1)
73#define AD738X_CONFIG1_REFSEL(x) (((x) & 0x1) << 1)
74#define AD738X_CONFIG1_PMODE_MSK NO_OS_BIT(0)
75#define AD738X_CONFIG1_PMODE(x) (((x) & 0x1) << 0)
76
77/*
78 * AD738X_REG_CONFIG2
79 */
80#define AD738X_CONFIG2_SDO2_MSK NO_OS_BIT(8)
81#define AD738X_CONFIG2_SDO2(x) (((x) & 0x1) << 8)
82#define AD738X_CONFIG2_SDO4_MSK NO_OS_GENMASK(9, 8)
83#define AD738X_CONFIG2_SDO4(x) (((x) & 0x3) << 8)
84#define AD738X_CONFIG2_RESET_MSK NO_OS_GENMASK(7, 0)
85#define AD738X_CONFIG2_RESET(x) (((x) & 0xFF) << 0)
86
87/*
88 * AD738X_REG_ALERT_LOW_TH
89 */
90#define AD738X_ALERT_LOW_MSK NO_OS_GENMASK(11, 0)
91#define AD738X_ALERT_LOW(x) (((x) & 0xFFF) << 0)
92
93/*
94 * AD738X_REG_ALERT_HIGH_TH
95 */
96#define AD738X_ALERT_HIGH_MSK NO_OS_GENMASK(11, 0)
97#define AD738X_ALERT_HIGH(x) (((x) & 0xFFF) << 0)
98
99/* Write to register x */
100#define AD738X_REG_WRITE(x) ((1 << 7) | ((x & 0x7) << 4))
101/* Read from register x */
102#define AD738X_REG_READ(x) ((x & 0x7) << 4)
103
104#define AD738X_FLAG_STANDARD_SPI_DMA NO_OS_BIT(0)
105#define AD738X_FLAG_OFFLOAD NO_OS_BIT(1)
106#define AD738X_FLAG_NO_PWM NO_OS_BIT(2)
107
113
115 /* 0b00 (CH=0, SEQ=0): select CH0 pair (AINA0/AINB0) */
117 /* 0b01 (CH=0, SEQ=1): sequencer enabled, cycles AINx0 and AINx1 */
119 /* 0b10 (CH=1, SEQ=0): select CH1 pair (AINA1/AINB1) */
121};
122
127
136
141
146
151
156
158 /* SPI */
160
161#ifdef XILINX_PLATFORM
162 struct axi_clkgen *clkgen;
163#endif
165
166 /* Device Settings */
173 void (*dcache_invalidate_range)(uint32_t address, uint32_t bytes_count);
174 uint32_t flags;
175};
176
178 /* SPI */
180#ifdef XILINX_PLATFORM
182 uint32_t axi_clkgen_rate;
183#endif
184#if !defined(USE_STANDARD_SPI)
186#endif
188
189 /* Device Settings */
195 void (*dcache_invalidate_range)(uint32_t address, uint32_t bytes_count);
196 uint32_t flags;
197};
198
200int32_t ad738x_init(struct ad738x_dev **device,
203int32_t ad738x_remove(struct ad738x_dev *dev);
205int32_t ad738x_spi_reg_read(struct ad738x_dev *dev,
206 uint8_t reg_addr,
207 uint16_t *reg_data);
209int32_t ad738x_spi_reg_write(struct ad738x_dev *dev,
210 uint8_t reg_addr,
211 uint16_t reg_data);
213int32_t ad738x_spi_single_conversion(struct ad738x_dev *dev,
214 uint32_t *adc_data);
216int32_t ad738x_spi_write_mask(struct ad738x_dev *dev,
217 uint8_t reg_addr,
218 uint32_t mask,
219 uint16_t data);
221int32_t ad738x_set_conversion_mode(struct ad738x_dev *dev,
222 enum ad738x_conv_mode mode);
224int32_t ad738x_reset(struct ad738x_dev *dev,
225 enum ad738x_reset_type reset);
227int32_t ad738x_oversampling_config(struct ad738x_dev *dev,
228 enum ad738x_os_mode os_mode,
229 enum ad738x_os_ratio os_ratio,
230 enum ad738x_resolution res);
232int32_t ad738x_power_down_mode(struct ad738x_dev *dev,
233 enum ad738x_pwd_mode pmode);
235int32_t ad738x_reference_sel(struct ad738x_dev *dev,
236 enum ad738x_ref_sel ref_sel);
238int32_t ad738x_ch_seq_sel(struct ad738x_dev *dev,
239 enum ad738x_ch_seq_sel ch_seq_sel);
241int32_t ad738x_read_data(struct ad738x_dev *dev,
242 uint32_t *buf,
243 uint16_t samples);
244#endif /* SRC_AD738X_H_ */
struct axi_clkgen_init clkgen_init
Definition common_data.c:74
int32_t ad738x_spi_write_mask(struct ad738x_dev *dev, uint8_t reg_addr, uint32_t mask, uint16_t data)
Definition ad738x.c:107
ad738x_pwd_mode
Definition ad738x.h:147
@ NORMAL_PWDM
Definition ad738x.h:148
@ FULL_PWDM
Definition ad738x.h:149
int32_t ad738x_remove(struct ad738x_dev *dev)
Free the resources allocated by ad738x_init().
Definition ad738x.c:502
int32_t ad738x_power_down_mode(struct ad738x_dev *dev, enum ad738x_pwd_mode pmode)
Definition ad738x.c:240
int32_t ad738x_init(struct ad738x_dev **device, struct ad738x_init_param *init_param)
Definition ad738x.c:425
int32_t ad738x_read_data(struct ad738x_dev *dev, uint32_t *buf, uint16_t samples)
Read from device. Enter register mode to read/write registers.
Definition ad738x.c:393
ad738x_conv_mode
Definition ad738x.h:108
@ TWO_WIRE_MODE
Definition ad738x.h:109
@ FOUR_WIRE_MODE
Definition ad738x.h:111
@ ONE_WIRE_MODE
Definition ad738x.h:110
int32_t ad738x_set_conversion_mode(struct ad738x_dev *dev, enum ad738x_conv_mode mode)
Definition ad738x.c:133
ad738x_ref_sel
Definition ad738x.h:152
@ INT_REF
Definition ad738x.h:153
@ EXT_REF
Definition ad738x.h:154
int32_t ad738x_reference_sel(struct ad738x_dev *dev, enum ad738x_ref_sel ref_sel)
Definition ad738x.c:257
ad738x_ch_seq_sel
Definition ad738x.h:114
@ FIRST_FOUR
Definition ad738x.h:116
@ SECOND_FOUR
Definition ad738x.h:120
ad738x_reset_type
Definition ad738x.h:142
@ HARD_RESET
Definition ad738x.h:144
int32_t ad738x_spi_reg_write(struct ad738x_dev *dev, uint8_t reg_addr, uint16_t reg_data)
Definition ad738x.c:87
ad738x_resolution
Definition ad738x.h:137
@ RES_16_BIT
Definition ad738x.h:138
@ RES_18_BIT
Definition ad738x.h:139
int32_t ad738x_oversampling_config(struct ad738x_dev *dev, enum ad738x_os_mode os_mode, enum ad738x_os_ratio os_ratio, enum ad738x_resolution res)
Definition ad738x.c:203
int32_t ad738x_reset(struct ad738x_dev *dev, enum ad738x_reset_type reset)
Definition ad738x.c:175
int32_t ad738x_spi_single_conversion(struct ad738x_dev *dev, uint32_t *adc_data)
Definition ad738x.c:272
ad738x_os_mode
Definition ad738x.h:123
@ ROLLING_OS_MODE
Definition ad738x.h:125
@ NORMAL_OS_MODE
Definition ad738x.h:124
int32_t ad738x_spi_reg_read(struct ad738x_dev *dev, uint8_t reg_addr, uint16_t *reg_data)
Definition ad738x.c:54
ad738x_os_ratio
Definition ad738x.h:128
@ OSR_X32
Definition ad738x.h:134
@ OSR_X16
Definition ad738x.h:133
@ OSR_DISABLED
Definition ad738x.h:129
@ OSR_X4
Definition ad738x.h:131
@ OSR_X8
Definition ad738x.h:132
@ OSR_X2
Definition ad738x.h:130
struct ad7616_init_param init_param
Definition ad7616_sdz.c:106
#define SOFT_RESET
Definition ad9361.h:568
#define ALL
Definition api_def.h:26
Driver for the Analog Devices AXI CLKGEN.
Header file of SPI Interface.
Header file of utility functions.
Definition ad738x.h:157
struct no_os_spi_desc * spi_desc
Definition ad738x.h:159
void(* dcache_invalidate_range)(uint32_t address, uint32_t bytes_count)
Definition ad738x.h:173
uint32_t ref_voltage_mv
Definition ad738x.h:170
enum ad738x_resolution resolution
Definition ad738x.h:171
enum ad738x_ch_seq_sel ch_seq_sel
Definition ad738x.h:168
enum ad738x_conv_mode conv_mode
Definition ad738x.h:167
uint32_t flags
Definition ad738x.h:174
struct no_os_pwm_desc * pwm_desc
Definition ad738x.h:164
enum ad738x_ref_sel ref_sel
Definition ad738x.h:169
Definition ad738x.h:177
void(* dcache_invalidate_range)(uint32_t address, uint32_t bytes_count)
Definition ad738x.h:195
uint32_t flags
Definition ad738x.h:196
struct spi_engine_offload_init_param * offload_init_param
Definition ad738x.h:185
enum ad738x_ch_seq_sel ch_seq_sel
Definition ad738x.h:191
uint32_t ref_voltage_mv
Definition ad738x.h:193
enum ad738x_conv_mode conv_mode
Definition ad738x.h:190
struct no_os_pwm_init_param * pwm_init
Definition ad738x.h:187
struct no_os_spi_init_param * spi_param
Definition ad738x.h:179
enum ad738x_ref_sel ref_sel
Definition ad738x.h:192
Definition ad77681.h:484
Definition clk_axi_clkgen.h:44
Definition clk_axi_clkgen.h:38
Definition ad9361_util.h:63
Structure representing an PWM generator device.
Definition no_os_pwm.h:83
Structure containing the init parameters needed by the PWM generator.
Definition no_os_pwm.h:56
Structure holding SPI descriptor.
Definition no_os_spi.h:180
Structure holding the parameters for SPI initialization.
Definition no_os_spi.h:128
Structure containing the init parameters needed by the offload module.
Definition spi_engine.h:127