no-OS
ad738x.h
Go to the documentation of this file.
1 /***************************************************************************/
35 #ifndef SRC_AD738X_H_
36 #define SRC_AD738X_H_
37 
38 /******************************************************************************/
39 /***************************** Include Files **********************************/
40 /******************************************************************************/
41 #include "no_os_util.h"
42 #include "clk_axi_clkgen.h"
43 #include "no_os_spi.h"
44 
45 /******************************************************************************/
46 /********************** Macros and Constants Definitions **********************/
47 /******************************************************************************/
48 
49 /*
50  * AD738X registers definition
51  */
52 #define AD738X_REG_NOP 0x00
53 #define AD738X_REG_CONFIG1 0x01
54 #define AD738X_REG_CONFIG2 0x02
55 #define AD738X_REG_ALERT 0x03
56 #define AD738X_REG_ALERT_LOW_TH 0x04
57 #define AD738X_REG_ALERT_HIGH_TH 0x05
58 
59 /*
60  * AD738X_REG_CONFIG1
61  */
62 #define AD738X_CONFIG1_OS_MODE_MSK NO_OS_BIT(9)
63 #define AD738X_CONFIG1_OS_MODE(x) (((x) & 0x1) << 9)
64 #define AD738X_CONFIG1_OSR_MSK NO_OS_GENMASK(8, 6)
65 #define AD738X_CONFIG1_OSR(x) (((x) & 0x7) << 6)
66 #define AD738X_CONFIG1_CRC_W_MSK NO_OS_BIT(5)
67 #define AD738X_CONFIG1_CRC_W(x) (((x) & 0x1) << 5)
68 #define AD738X_CONFIG1_CRC_R_MSK NO_OS_BIT(4)
69 #define AD738X_CONFIG1_CRC_R(x) (((x) & 0x1) << 4)
70 #define AD738X_CONFIG1_ALERTEN_MSK NO_OS_BIT(3)
71 #define AD738X_CONFIG1_ALERTEN(x) (((x) & 0x1) << 3)
72 #define AD738X_CONFIG1_RES_MSK NO_OS_BIT(2)
73 #define AD738X_CONFIG1_RES(x) (((x) & 0x1) << 2)
74 #define AD738X_CONFIG1_REFSEL_MSK NO_OS_BIT(1)
75 #define AD738X_CONFIG1_REFSEL(x) (((x) & 0x1) << 1)
76 #define AD738X_CONFIG1_PMODE_MSK NO_OS_BIT(0)
77 #define AD738X_CONFIG1_PMODE(x) (((x) & 0x1) << 0)
78 
79 /*
80  * AD738X_REG_CONFIG2
81  */
82 #define AD738X_CONFIG2_SDO2_MSK NO_OS_BIT(8)
83 #define AD738X_CONFIG2_SDO2(x) (((x) & 0x1) << 8)
84 #define AD738X_CONFIG2_SDO4_MSK NO_OS_GENMASK(9, 8)
85 #define AD738X_CONFIG2_SDO4(x) (((x) & 0x3) << 8)
86 #define AD738X_CONFIG2_RESET_MSK NO_OS_GENMASK(7, 0)
87 #define AD738X_CONFIG2_RESET(x) (((x) & 0xFF) << 0)
88 
89 /*
90  * AD738X_REG_ALERT_LOW_TH
91  */
92 #define AD738X_ALERT_LOW_MSK NO_OS_GENMASK(11, 0)
93 #define AD738X_ALERT_LOW(x) (((x) & 0xFFF) << 0)
94 
95 /*
96  * AD738X_REG_ALERT_HIGH_TH
97  */
98 #define AD738X_ALERT_HIGH_MSK NO_OS_GENMASK(11, 0)
99 #define AD738X_ALERT_HIGH(x) (((x) & 0xFFF) << 0)
100 
101 /* Write to register x */
102 #define AD738X_REG_WRITE(x) ((1 << 7) | ((x & 0x7) << 4))
103 /* Read from register x */
104 #define AD738X_REG_READ(x) ((x & 0x7) << 4)
105 
106 #define AD738X_FLAG_STANDARD_SPI_DMA NO_OS_BIT(0)
107 #define AD738X_FLAG_OFFLOAD NO_OS_BIT(1)
108 /*****************************************************************************/
109 /*************************** Types Declarations *******************************/
110 /******************************************************************************/
114 };
115 
119 };
120 
128 };
129 
133 };
134 
138 };
139 
143 };
144 
148 };
149 
150 struct ad738x_dev {
151  /* SPI */
157 
158  /* Device Settings */
161  uint32_t ref_voltage_mv;
164  void (*dcache_invalidate_range)(uint32_t address, uint32_t bytes_count);
165  uint32_t flags;
166 };
167 
169  /* SPI */
172  uint32_t axi_clkgen_rate;
176 
177  /* Device Settings */
180  uint32_t ref_voltage_mv;
182  void (*dcache_invalidate_range)(uint32_t address, uint32_t bytes_count);
183  uint32_t flags;
184 };
185 
186 /******************************************************************************/
187 /************************ Functions Declarations ******************************/
188 /******************************************************************************/
190 int32_t ad738x_init(struct ad738x_dev **device,
191  struct ad738x_init_param *init_param);
193 int32_t ad738x_remove(struct ad738x_dev *dev);
195 int32_t ad738x_spi_reg_read(struct ad738x_dev *dev,
196  uint8_t reg_addr,
197  uint16_t *reg_data);
199 int32_t ad738x_spi_reg_write(struct ad738x_dev *dev,
200  uint8_t reg_addr,
201  uint16_t reg_data);
203 int32_t ad738x_spi_single_conversion(struct ad738x_dev *dev,
204  uint32_t *adc_data);
206 int32_t ad738x_spi_write_mask(struct ad738x_dev *dev,
207  uint8_t reg_addr,
208  uint32_t mask,
209  uint16_t data);
211 int32_t ad738x_set_conversion_mode(struct ad738x_dev *dev,
212  enum ad738x_conv_mode mode);
214 int32_t ad738x_reset(struct ad738x_dev *dev,
215  enum ad738x_reset_type reset);
217 int32_t ad738x_oversampling_config(struct ad738x_dev *dev,
218  enum ad738x_os_mode os_mode,
219  enum ad738x_os_ratio os_ratio,
220  enum ad738x_resolution res);
222 int32_t ad738x_power_down_mode(struct ad738x_dev *dev,
223  enum ad738x_pwd_mode pmode);
225 int32_t ad738x_reference_sel(struct ad738x_dev *dev,
226  enum ad738x_ref_sel ref_sel);
228 int32_t ad738x_read_data(struct ad738x_dev *dev,
229  uint32_t *buf,
230  uint16_t samples);
231 #endif /* SRC_AD738X_H_ */
ad738x_dev
Definition: ad738x.h:150
ad738x_init
int32_t ad738x_init(struct ad738x_dev **device, struct ad738x_init_param *init_param)
Definition: ad738x.c:394
adc_data
Definition: ad77681.h:490
OSR_X32
@ OSR_X32
Definition: ad738x.h:127
no_os_alloc.h
ad738x_init_param
Definition: ad738x.h:168
no_os_pwm_init_param
Structure containing the init parameters needed by the PWM generator.
Definition: no_os_pwm.h:66
ad738x_init_param::ref_sel
enum ad738x_ref_sel ref_sel
Definition: ad738x.h:179
AD738X_CONFIG1_OSR
#define AD738X_CONFIG1_OSR(x)
Definition: ad738x.h:65
ad738x_oversampling_config
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:181
ad738x_dev::dcache_invalidate_range
void(* dcache_invalidate_range)(uint32_t address, uint32_t bytes_count)
Definition: ad738x.h:164
AD738X_REG_CONFIG2
#define AD738X_REG_CONFIG2
Definition: ad738x.h:54
ad738x_dev::clkgen
struct axi_clkgen * clkgen
Definition: ad738x.h:155
AD738X_CONFIG1_PMODE_MSK
#define AD738X_CONFIG1_PMODE_MSK
Definition: ad738x.h:76
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
CS_LOW
#define CS_LOW
Definition: spi_engine.h:73
ad738x_reset
int32_t ad738x_reset(struct ad738x_dev *dev, enum ad738x_reset_type reset)
Definition: ad738x.c:153
no_os_spi.h
Header file of SPI Interface.
FULL_PWDM
@ FULL_PWDM
Definition: ad738x.h:142
spi_engine_offload_init
int32_t spi_engine_offload_init(struct no_os_spi_desc *desc, const struct spi_engine_offload_init_param *param)
Initialize the SPI engine's offload module.
Definition: spi_engine.c:763
no_os_pwm_remove
int32_t no_os_pwm_remove(struct no_os_pwm_desc *desc)
Free the resources allocated by no_os_pwm_init().
Definition: no_os_pwm.c:79
AD738X_CONFIG1_OS_MODE_MSK
#define AD738X_CONFIG1_OS_MODE_MSK
Definition: ad738x.h:62
NORMAL_OS_MODE
@ NORMAL_OS_MODE
Definition: ad738x.h:117
ad738x_os_mode
ad738x_os_mode
Definition: ad738x.h:116
AD738X_CONFIG2_RESET
#define AD738X_CONFIG2_RESET(x)
Definition: ad738x.h:87
clk_axi_clkgen.h
Driver for the Analog Devices AXI CLKGEN.
ad738x_reference_sel
int32_t ad738x_reference_sel(struct ad738x_dev *dev, enum ad738x_ref_sel ref_sel)
Definition: ad738x.c:235
AD738X_FLAG_OFFLOAD
#define AD738X_FLAG_OFFLOAD
Definition: ad738x.h:107
spi_engine_offload_message::commands_data
uint32_t * commands_data
Definition: spi_engine.h:167
no_os_spi_msg
Definition: no_os_spi.h:100
no_os_delay.h
Header file of Delay functions.
ad738x_conv_mode
ad738x_conv_mode
Definition: ad738x.h:111
axi_clkgen_init
Definition: clk_axi_clkgen.h:50
ad738x_reset_type
ad738x_reset_type
Definition: ad738x.h:135
axi_clkgen_set_rate
int32_t axi_clkgen_set_rate(struct axi_clkgen *clkgen, uint32_t rate)
axi_clkgen_set_rate
Definition: clk_axi_clkgen.c:414
ad738x_dev::conv_mode
enum ad738x_conv_mode conv_mode
Definition: ad738x.h:159
AD738X_CONFIG1_OS_MODE
#define AD738X_CONFIG1_OS_MODE(x)
Definition: ad738x.h:63
AD738X_REG_CONFIG1
#define AD738X_REG_CONFIG1
Definition: ad738x.h:53
ad738x_reference_sel
int32_t ad738x_reference_sel(struct ad738x_dev *dev, enum ad738x_ref_sel ref_sel)
Definition: ad738x.c:235
spi_engine_offload_message
Structure representing an offload message.
Definition: spi_engine.h:158
device
Definition: ad9361_util.h:69
no_os_spi_transfer_dma_sync
int32_t no_os_spi_transfer_dma_sync(struct no_os_spi_desc *desc, struct no_os_spi_msg *msgs, uint32_t len)
Transfer a list of messages using DMA and busy wait for the completion.
Definition: no_os_spi.c:224
ad738x_spi_write_mask
int32_t ad738x_spi_write_mask(struct ad738x_dev *dev, uint8_t reg_addr, uint32_t mask, uint16_t data)
Definition: ad738x.c:110
AD738X_CONFIG1_REFSEL_MSK
#define AD738X_CONFIG1_REFSEL_MSK
Definition: ad738x.h:74
axi_clkgen_init
int32_t axi_clkgen_init(struct axi_clkgen **clk, const struct axi_clkgen_init *init)
axi_clkgen_init
Definition: clk_axi_clkgen.c:520
ad738x_spi_reg_read
int32_t ad738x_spi_reg_read(struct ad738x_dev *dev, uint8_t reg_addr, uint16_t *reg_data)
Definition: ad738x.c:57
axi_clkgen
Definition: clk_axi_clkgen.h:44
NO_OS_ARRAY_SIZE
#define NO_OS_ARRAY_SIZE(x)
Definition: no_os_util.h:49
OSR_X16
@ OSR_X16
Definition: ad738x.h:126
ad738x_dev::ref_voltage_mv
uint32_t ref_voltage_mv
Definition: ad738x.h:161
AD738X_CONFIG1_PMODE
#define AD738X_CONFIG1_PMODE(x)
Definition: ad738x.h:77
EXT_REF
@ EXT_REF
Definition: ad738x.h:147
WRITE_READ
#define WRITE_READ(no_bytes)
Definition: spi_engine.h:65
ad738x_init
int32_t ad738x_init(struct ad738x_dev **device, struct ad738x_init_param *init_param)
Definition: ad738x.c:394
no_os_spi_msg::tx_buff
uint8_t * tx_buff
Definition: no_os_spi.h:102
NORMAL_PWDM
@ NORMAL_PWDM
Definition: ad738x.h:141
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: aducm3029_delay.c:126
ad738x.h
Header file for AD738x Driver.
CS_HIGH
#define CS_HIGH
Definition: spi_engine.h:72
AD738X_CONFIG1_RES_MSK
#define AD738X_CONFIG1_RES_MSK
Definition: ad738x.h:72
no_os_error.h
Error codes definition.
no_os_pwm_enable
int32_t no_os_pwm_enable(struct no_os_pwm_desc *desc)
Enable PWM signal generation.
Definition: no_os_pwm.c:98
OSR_X4
@ OSR_X4
Definition: ad738x.h:124
SOFT_RESET
@ SOFT_RESET
Definition: ad738x.h:136
AD738X_CONFIG1_OSR_MSK
#define AD738X_CONFIG1_OSR_MSK
Definition: ad738x.h:64
RES_18_BIT
@ RES_18_BIT
Definition: ad738x.h:132
AD738X_CONFIG2_SDO2
#define AD738X_CONFIG2_SDO2(x)
Definition: ad738x.h:83
ad738x_init_param::axi_clkgen_rate
uint32_t axi_clkgen_rate
Definition: ad738x.h:172
HARD_RESET
@ HARD_RESET
Definition: ad738x.h:137
ad7616_init_param::offload_init_param
struct spi_engine_offload_init_param * offload_init_param
Definition: ad7616.h:205
ad738x_spi_single_conversion
int32_t ad738x_spi_single_conversion(struct ad738x_dev *dev, uint32_t *adc_data)
Definition: ad738x.c:250
AD738X_CONFIG1_REFSEL
#define AD738X_CONFIG1_REFSEL(x)
Definition: ad738x.h:75
no_os_pwm_disable
int32_t no_os_pwm_disable(struct no_os_pwm_desc *desc)
Disable PWM signal generation.
Definition: no_os_pwm.c:115
spi_engine.h
ad738x_dev::offload_init_param
struct spi_engine_offload_init_param * offload_init_param
Definition: ad738x.h:154
ad738x_spi_reg_write
int32_t ad738x_spi_reg_write(struct ad738x_dev *dev, uint8_t reg_addr, uint16_t reg_data)
Definition: ad738x.c:90
INT_REF
@ INT_REF
Definition: ad738x.h:146
ad738x_init_param::ref_voltage_mv
uint32_t ref_voltage_mv
Definition: ad738x.h:180
OSR_X2
@ OSR_X2
Definition: ad738x.h:123
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:192
ad738x_init_param::dcache_invalidate_range
void(* dcache_invalidate_range)(uint32_t address, uint32_t bytes_count)
Definition: ad738x.h:182
ad738x_init_param::pwm_init
struct no_os_pwm_init_param * pwm_init
Definition: ad738x.h:175
ad738x_spi_write_mask
int32_t ad738x_spi_write_mask(struct ad738x_dev *dev, uint8_t reg_addr, uint32_t mask, uint16_t data)
Definition: ad738x.c:110
ad738x_read_data
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:364
ad738x_spi_single_conversion
int32_t ad738x_spi_single_conversion(struct ad738x_dev *dev, uint32_t *adc_data)
Definition: ad738x.c:250
ad738x_ref_sel
ad738x_ref_sel
Definition: ad738x.h:145
ad738x_pwd_mode
ad738x_pwd_mode
Definition: ad738x.h:140
ad738x_remove
int32_t ad738x_remove(struct ad738x_dev *dev)
Free the resources allocated by ad738x_init().
Definition: ad738x.c:457
ad738x_os_ratio
ad738x_os_ratio
Definition: ad738x.h:121
no_os_pwm_desc
Structure representing an PWM generator device.
Definition: no_os_pwm.h:93
AD738X_CONFIG2_RESET_MSK
#define AD738X_CONFIG2_RESET_MSK
Definition: ad738x.h:86
AD738X_CONFIG1_RES
#define AD738X_CONFIG1_RES(x)
Definition: ad738x.h:73
ad738x_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: ad738x.h:152
no_os_pwm_init
int32_t no_os_pwm_init(struct no_os_pwm_desc **desc, const struct no_os_pwm_init_param *param)
Initialize the PWM peripheral.
Definition: no_os_pwm.c:51
ad7616_init_param::dcache_invalidate_range
void(* dcache_invalidate_range)(uint32_t address, uint32_t bytes_count)
Definition: ad7616.h:230
ad7616_init_param::axi_clkgen_rate
uint32_t axi_clkgen_rate
Definition: ad7616.h:211
no_os_malloc
void * no_os_malloc(size_t size)
Allocate memory and return a pointer to it.
Definition: chibios_alloc.c:43
ad738x_spi_reg_write
int32_t ad738x_spi_reg_write(struct ad738x_dev *dev, uint8_t reg_addr, uint16_t reg_data)
Definition: ad738x.c:90
no_os_pwm.h
Header file of PWM Interface.
ad738x_dev::pwm_desc
struct no_os_pwm_desc * pwm_desc
Definition: ad738x.h:156
ONE_WIRE_MODE
@ ONE_WIRE_MODE
Definition: ad738x.h:113
ad738x_dev::ref_sel
enum ad738x_ref_sel ref_sel
Definition: ad738x.h:160
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
AD738X_FLAG_STANDARD_SPI_DMA
#define AD738X_FLAG_STANDARD_SPI_DMA
Definition: ad738x.h:106
ad738x_read_data
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:364
AD738X_REG_WRITE
#define AD738X_REG_WRITE(x)
Definition: ad738x.h:102
AD738X_REG_READ
#define AD738X_REG_READ(x)
Definition: ad738x.h:104
ad738x_oversampling_config
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:181
ad738x_remove
int32_t ad738x_remove(struct ad738x_dev *dev)
Free the resources allocated by ad738x_init().
Definition: ad738x.c:457
ad738x_init_param::offload_init_param
struct spi_engine_offload_init_param * offload_init_param
Definition: ad738x.h:174
AD738X_CONFIG2_SDO2_MSK
#define AD738X_CONFIG2_SDO2_MSK
Definition: ad738x.h:82
RES_16_BIT
@ RES_16_BIT
Definition: ad738x.h:131
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
ad738x_init_param::spi_param
struct no_os_spi_init_param * spi_param
Definition: ad738x.h:170
ad7616_init_param::clkgen_init
struct axi_clkgen_init * clkgen_init
Definition: ad7616.h:209
ad738x_set_conversion_mode
int32_t ad738x_set_conversion_mode(struct ad738x_dev *dev, enum ad738x_conv_mode mode)
Definition: ad738x.c:136
ad738x_spi_reg_read
int32_t ad738x_spi_reg_read(struct ad738x_dev *dev, uint8_t reg_addr, uint16_t *reg_data)
Definition: ad738x.c:57
ad738x_init_param::conv_mode
enum ad738x_conv_mode conv_mode
Definition: ad738x.h:178
spi_engine_offload_transfer
int32_t spi_engine_offload_transfer(struct no_os_spi_desc *desc, struct spi_engine_offload_message msg, uint32_t no_samples)
Initiate a SPI transfer in offload mode.
Definition: spi_engine.c:809
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
ad738x_power_down_mode
int32_t ad738x_power_down_mode(struct ad738x_dev *dev, enum ad738x_pwd_mode pmode)
Definition: ad738x.c:218
OSR_DISABLED
@ OSR_DISABLED
Definition: ad738x.h:122
spi_engine_offload_init_param
Structure containing the init parameters needed by the offload module.
Definition: spi_engine.h:143
ad738x_dev::flags
uint32_t flags
Definition: ad738x.h:165
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
OSR_X8
@ OSR_X8
Definition: ad738x.h:125
ad738x_init_param::clkgen_init
struct axi_clkgen_init * clkgen_init
Definition: ad738x.h:171
ad738x_init_param::flags
uint32_t flags
Definition: ad738x.h:183
axi_clkgen_remove
int32_t axi_clkgen_remove(struct axi_clkgen *clkgen)
axi_clkgen_remove
Definition: clk_axi_clkgen.c:541
no_os_util.h
Header file of utility functions.
ROLLING_OS_MODE
@ ROLLING_OS_MODE
Definition: ad738x.h:118
ad738x_dev::resolution
enum ad738x_resolution resolution
Definition: ad738x.h:162
ad738x_set_conversion_mode
int32_t ad738x_set_conversion_mode(struct ad738x_dev *dev, enum ad738x_conv_mode mode)
Definition: ad738x.c:136
TWO_WIRE_MODE
@ TWO_WIRE_MODE
Definition: ad738x.h:112
ad738x_resolution
ad738x_resolution
Definition: ad738x.h:130
ad7616_init_param::spi_param
struct no_os_spi_init_param * spi_param
Definition: ad7616.h:204
ad738x_power_down_mode
int32_t ad738x_power_down_mode(struct ad738x_dev *dev, enum ad738x_pwd_mode pmode)
Definition: ad738x.c:218
ad738x_reset
int32_t ad738x_reset(struct ad738x_dev *dev, enum ad738x_reset_type reset)
Definition: ad738x.c:153
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140