no-OS
Loading...
Searching...
No Matches
ad738x.h
Go to the documentation of this file.
1/***************************************************************************/
34
35#ifndef SRC_AD738X_H_
36#define SRC_AD738X_H_
37
38#include "no_os_util.h"
39#include "no_os_spi.h"
40#ifdef XILINX_PLATFORM
41#include "clk_axi_clkgen.h"
42#endif
43
44/*
45 * AD738X registers definition
46 */
47#define AD738X_REG_NOP 0x00
48#define AD738X_REG_CONFIG1 0x01
49#define AD738X_REG_CONFIG2 0x02
50#define AD738X_REG_ALERT 0x03
51#define AD738X_REG_ALERT_LOW_TH 0x04
52#define AD738X_REG_ALERT_HIGH_TH 0x05
53
54/*
55 * AD738X_REG_CONFIG1
56 */
57#define AD738X_CONFIG1_OS_MODE_MSK NO_OS_BIT(9)
58#define AD738X_CONFIG1_OS_MODE(x) (((x) & 0x1) << 9)
59#define AD738X_CONFIG1_OSR_MSK NO_OS_GENMASK(8, 6)
60#define AD738X_CONFIG1_OSR(x) (((x) & 0x7) << 6)
61#define AD738X_CONFIG1_CRC_W_MSK NO_OS_BIT(5)
62#define AD738X_CONFIG1_CRC_W(x) (((x) & 0x1) << 5)
63#define AD738X_CONFIG1_CRC_R_MSK NO_OS_BIT(4)
64#define AD738X_CONFIG1_CRC_R(x) (((x) & 0x1) << 4)
65#define AD738X_CONFIG1_ALERTEN_MSK NO_OS_BIT(3)
66#define AD738X_CONFIG1_ALERTEN(x) (((x) & 0x1) << 3)
67#define AD738X_CONFIG1_RES_MSK NO_OS_BIT(2)
68#define AD738X_CONFIG1_RES(x) (((x) & 0x1) << 2)
69#define AD738X_CONFIG1_REFSEL_MSK NO_OS_BIT(1)
70#define AD738X_CONFIG1_REFSEL(x) (((x) & 0x1) << 1)
71#define AD738X_CONFIG1_PMODE_MSK NO_OS_BIT(0)
72#define AD738X_CONFIG1_PMODE(x) (((x) & 0x1) << 0)
73
74/*
75 * AD738X_REG_CONFIG2
76 */
77#define AD738X_CONFIG2_SDO2_MSK NO_OS_BIT(8)
78#define AD738X_CONFIG2_SDO2(x) (((x) & 0x1) << 8)
79#define AD738X_CONFIG2_SDO4_MSK NO_OS_GENMASK(9, 8)
80#define AD738X_CONFIG2_SDO4(x) (((x) & 0x3) << 8)
81#define AD738X_CONFIG2_RESET_MSK NO_OS_GENMASK(7, 0)
82#define AD738X_CONFIG2_RESET(x) (((x) & 0xFF) << 0)
83
84/*
85 * AD738X_REG_ALERT_LOW_TH
86 */
87#define AD738X_ALERT_LOW_MSK NO_OS_GENMASK(11, 0)
88#define AD738X_ALERT_LOW(x) (((x) & 0xFFF) << 0)
89
90/*
91 * AD738X_REG_ALERT_HIGH_TH
92 */
93#define AD738X_ALERT_HIGH_MSK NO_OS_GENMASK(11, 0)
94#define AD738X_ALERT_HIGH(x) (((x) & 0xFFF) << 0)
95
96/* Write to register x */
97#define AD738X_REG_WRITE(x) ((1 << 7) | ((x & 0x7) << 4))
98/* Read from register x */
99#define AD738X_REG_READ(x) ((x & 0x7) << 4)
100
101#define AD738X_FLAG_STANDARD_SPI_DMA NO_OS_BIT(0)
102#define AD738X_FLAG_OFFLOAD NO_OS_BIT(1)
107
112
121
126
131
136
141
143 /* SPI */
145#ifdef XILINX_PLATFORM
147 struct spi_engine_offload_init_param *offload_init_param;
148 struct axi_clkgen *clkgen;
149#endif
151
152 /* Device Settings */
158 void (*dcache_invalidate_range)(uint32_t address, uint32_t bytes_count);
159 uint32_t flags;
160};
161
163 /* SPI */
165#ifdef XILINX_PLATFORM
167 uint32_t axi_clkgen_rate;
169 struct spi_engine_offload_init_param *offload_init_param;
170#endif
172
173 /* Device Settings */
178 void (*dcache_invalidate_range)(uint32_t address, uint32_t bytes_count);
179 uint32_t flags;
180};
181
183int32_t ad738x_init(struct ad738x_dev **device,
186int32_t ad738x_remove(struct ad738x_dev *dev);
188int32_t ad738x_spi_reg_read(struct ad738x_dev *dev,
189 uint8_t reg_addr,
190 uint16_t *reg_data);
192int32_t ad738x_spi_reg_write(struct ad738x_dev *dev,
193 uint8_t reg_addr,
194 uint16_t reg_data);
196int32_t ad738x_spi_single_conversion(struct ad738x_dev *dev,
197 uint32_t *adc_data);
199int32_t ad738x_spi_write_mask(struct ad738x_dev *dev,
200 uint8_t reg_addr,
201 uint32_t mask,
202 uint16_t data);
204int32_t ad738x_set_conversion_mode(struct ad738x_dev *dev,
205 enum ad738x_conv_mode mode);
207int32_t ad738x_reset(struct ad738x_dev *dev,
208 enum ad738x_reset_type reset);
210int32_t ad738x_oversampling_config(struct ad738x_dev *dev,
211 enum ad738x_os_mode os_mode,
212 enum ad738x_os_ratio os_ratio,
213 enum ad738x_resolution res);
215int32_t ad738x_power_down_mode(struct ad738x_dev *dev,
216 enum ad738x_pwd_mode pmode);
218int32_t ad738x_reference_sel(struct ad738x_dev *dev,
219 enum ad738x_ref_sel ref_sel);
221int32_t ad738x_read_data(struct ad738x_dev *dev,
222 uint32_t *buf,
223 uint16_t samples);
224#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:106
ad738x_pwd_mode
Definition ad738x.h:132
@ NORMAL_PWDM
Definition ad738x.h:133
@ FULL_PWDM
Definition ad738x.h:134
int32_t ad738x_remove(struct ad738x_dev *dev)
Free the resources allocated by ad738x_init().
Definition ad738x.c:458
int32_t ad738x_power_down_mode(struct ad738x_dev *dev, enum ad738x_pwd_mode pmode)
Definition ad738x.c:214
int32_t ad738x_init(struct ad738x_dev **device, struct ad738x_init_param *init_param)
Definition ad738x.c:392
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:362
ad738x_conv_mode
Definition ad738x.h:103
@ TWO_WIRE_MODE
Definition ad738x.h:104
@ ONE_WIRE_MODE
Definition ad738x.h:105
int32_t ad738x_set_conversion_mode(struct ad738x_dev *dev, enum ad738x_conv_mode mode)
Definition ad738x.c:132
ad738x_ref_sel
Definition ad738x.h:137
@ INT_REF
Definition ad738x.h:138
@ EXT_REF
Definition ad738x.h:139
int32_t ad738x_reference_sel(struct ad738x_dev *dev, enum ad738x_ref_sel ref_sel)
Definition ad738x.c:231
ad738x_reset_type
Definition ad738x.h:127
@ HARD_RESET
Definition ad738x.h:129
int32_t ad738x_spi_reg_write(struct ad738x_dev *dev, uint8_t reg_addr, uint16_t reg_data)
Definition ad738x.c:86
ad738x_resolution
Definition ad738x.h:122
@ RES_16_BIT
Definition ad738x.h:123
@ RES_18_BIT
Definition ad738x.h:124
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:177
int32_t ad738x_reset(struct ad738x_dev *dev, enum ad738x_reset_type reset)
Definition ad738x.c:149
int32_t ad738x_spi_single_conversion(struct ad738x_dev *dev, uint32_t *adc_data)
Definition ad738x.c:246
ad738x_os_mode
Definition ad738x.h:108
@ ROLLING_OS_MODE
Definition ad738x.h:110
@ NORMAL_OS_MODE
Definition ad738x.h:109
int32_t ad738x_spi_reg_read(struct ad738x_dev *dev, uint8_t reg_addr, uint16_t *reg_data)
Definition ad738x.c:53
ad738x_os_ratio
Definition ad738x.h:113
@ OSR_X32
Definition ad738x.h:119
@ OSR_X16
Definition ad738x.h:118
@ OSR_DISABLED
Definition ad738x.h:114
@ OSR_X4
Definition ad738x.h:116
@ OSR_X8
Definition ad738x.h:117
@ OSR_X2
Definition ad738x.h:115
struct ad7616_init_param init_param
Definition ad7616_sdz.c:107
#define SOFT_RESET
Definition ad9361.h:568
Driver for the Analog Devices AXI CLKGEN.
Header file of SPI Interface.
Header file of utility functions.
Definition ad738x.h:142
struct no_os_spi_desc * spi_desc
Definition ad738x.h:144
void(* dcache_invalidate_range)(uint32_t address, uint32_t bytes_count)
Definition ad738x.h:158
uint32_t ref_voltage_mv
Definition ad738x.h:155
enum ad738x_resolution resolution
Definition ad738x.h:156
enum ad738x_conv_mode conv_mode
Definition ad738x.h:153
uint32_t flags
Definition ad738x.h:159
struct no_os_pwm_desc * pwm_desc
Definition ad738x.h:150
enum ad738x_ref_sel ref_sel
Definition ad738x.h:154
Definition ad738x.h:162
void(* dcache_invalidate_range)(uint32_t address, uint32_t bytes_count)
Definition ad738x.h:178
uint32_t flags
Definition ad738x.h:179
uint32_t ref_voltage_mv
Definition ad738x.h:176
enum ad738x_conv_mode conv_mode
Definition ad738x.h:174
struct no_os_pwm_init_param * pwm_init
Definition ad738x.h:171
struct no_os_spi_init_param * spi_param
Definition ad738x.h:164
enum ad738x_ref_sel ref_sel
Definition ad738x.h:175
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:131