no-OS
ad400x.h
Go to the documentation of this file.
1 /***************************************************************************/
40 #ifndef SRC_AD400X_H_
41 #define SRC_AD400X_H_
42 
43 #include <stdbool.h>
44 
45 #if !defined(USE_STANDARD_SPI)
46 #include "spi_engine.h"
47 #include "clk_axi_clkgen.h"
48 #include "no_os_pwm.h"
49 #else
50 #include "no_os_spi.h"
51 #endif
52 #include "no_os_gpio.h"
53 
54 /******************************************************************************/
55 /********************** Macros and Constants Definitions **********************/
56 /******************************************************************************/
57 #define AD400X_READ_COMMAND 0x54
58 #define AD400X_WRITE_COMMAND 0x14
59 #define AD400X_RESERVED_MSK 0xE0
60 
61 #define AD400X_TURBO_MODE(x) (((x) & 0x1) << 1)
62 #define AD400X_HIGH_Z_MODE(x) (((x) & 0x1) << 2)
63 #define AD400X_SPAN_COMPRESSION(x) (((x) & 0x1) << 3)
64 #define AD400X_EN_STATUS_BITS(x) (((x) & 0x1) << 4)
65 
78 };
79 
81  uint16_t resolution;
82  char sign;
83 };
84 
85 struct ad400x_dev {
86  /* SPI */
88  /* Clock gen for hdl design structure */
89  struct axi_clkgen *clkgen;
90  /* Trigger conversion PWM generator descriptor */
94  /* Register access speed */
95  uint32_t reg_access_speed;
96  /* Device Settings */
101  const struct ad400x_dev_info *dev_info;
103  void (*dcache_invalidate_range)(uint32_t address, uint32_t bytes_count);
104  /* enable offload */
106 };
107 
109  /* SPI */
111  /* PWM generator init structure */
113  /* Clock gen for hdl design init structure */
115  /* Clock generator rate */
116  uint32_t axi_clkgen_rate;
119  /* Register access speed */
121  /* Device Settings */
126  void (*dcache_invalidate_range)(uint32_t address, uint32_t bytes_count);
127  /* buffer to store data samples */
128  uint32_t *buffer;
129  /* buffer size */
130  uint32_t buffer_size;
136 };
137 
138 int32_t ad400x_spi_reg_read(struct ad400x_dev *dev,
139  uint8_t *reg_data);
140 int32_t ad400x_spi_reg_write(struct ad400x_dev *dev,
141  uint8_t reg_data);
142 int32_t ad400x_init(struct ad400x_dev **device,
143  struct ad400x_init_param *init_param);
144 int32_t ad400x_remove(struct ad400x_dev *dev);
145 /* read data samples */
146 int32_t ad400x_read_data(struct ad400x_dev *dev, uint32_t *buf,
147  uint16_t samples);
148 #endif /* SRC_AD400X_H_ */
ad400x_spi_reg_write
int32_t ad400x_spi_reg_write(struct ad400x_dev *dev, uint8_t reg_data)
Definition: ad400x.c:125
no_os_alloc.h
ad400x_spi_reg_read
int32_t ad400x_spi_reg_read(struct ad400x_dev *dev, uint8_t *reg_data)
Definition: ad400x.c:80
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:85
no_os_pwm_init_param
Structure containing the init parameters needed by the PWM generator.
Definition: no_os_pwm.h:72
ad400x_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: ad400x.h:87
ID_ADAQ4003
@ ID_ADAQ4003
Definition: ad400x.h:77
ad400x_init_param
Definition: ad400x.h:108
ad400x_dev_info::sign
char sign
Definition: ad400x.h:82
NO_OS_GENMASK
#define NO_OS_GENMASK(h, l)
Definition: no_os_util.h:86
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:165
CS_LOW
#define CS_LOW
Definition: spi_engine.h:79
no_os_spi.h
Header file of SPI Interface.
ad400x_dev::dev_info
const struct ad400x_dev_info * dev_info
Definition: ad400x.h:101
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:759
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:85
ID_AD4002
@ ID_AD4002
Definition: ad400x.h:69
ad400x_init_param::clkgen_init
struct axi_clkgen_init * clkgen_init
Definition: ad400x.h:114
clk_axi_clkgen.h
Driver for the Analog Devices AXI CLKGEN.
ad400x_supported_dev_ids
ad400x_supported_dev_ids
Definition: ad400x.h:66
ID_AD4000
@ ID_AD4000
Definition: ad400x.h:67
spi_engine_offload_message::commands_data
uint32_t * commands_data
Definition: spi_engine.h:169
ad400x_init_param::axi_clkgen_rate
uint32_t axi_clkgen_rate
Definition: ad400x.h:116
AD400X_READ_COMMAND
#define AD400X_READ_COMMAND
Definition: ad400x.h:57
axi_clkgen_init
Definition: clk_axi_clkgen.h:56
ad400x_init_param::dcache_invalidate_range
void(* dcache_invalidate_range)(uint32_t address, uint32_t bytes_count)
Definition: ad400x.h:126
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:419
ad400x_dev_info::resolution
uint16_t resolution
Definition: ad400x.h:81
spi_engine_offload_message
Structure representing an offload message.
Definition: spi_engine.h:160
device
Definition: ad9361_util.h:75
ad400x_spi_reg_read
int32_t ad400x_spi_reg_read(struct ad400x_dev *dev, uint8_t *reg_data)
Definition: ad400x.c:80
ad400x_init_param::buffer
uint32_t * buffer
Definition: ad400x.h:128
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:525
axi_clkgen
Definition: clk_axi_clkgen.h:50
NO_OS_ARRAY_SIZE
#define NO_OS_ARRAY_SIZE(x)
Definition: no_os_util.h:53
AD400X_EN_STATUS_BITS
#define AD400X_EN_STATUS_BITS(x)
Definition: ad400x.h:64
ad400x_devices
const struct ad400x_dev_info ad400x_devices[]
Definition: ad400x.c:56
AD400X_RESERVED_MSK
#define AD400X_RESERVED_MSK
Definition: ad400x.h:59
ad400x_spi_reg_write
int32_t ad400x_spi_reg_write(struct ad400x_dev *dev, uint8_t reg_data)
Definition: ad400x.c:125
NO_OS_GPIO_LOW
@ NO_OS_GPIO_LOW
Definition: no_os_gpio.h:121
ad7616_init_param::reg_access_speed
uint32_t reg_access_speed
Definition: ad7616.h:218
ad400x_dev
Definition: ad400x.h:85
ad400x_remove
int32_t ad400x_remove(struct ad400x_dev *dev)
Free the resources allocated by ad400x_init().
Definition: ad400x.c:370
CS_HIGH
#define CS_HIGH
Definition: spi_engine.h:78
AD400X_TURBO_MODE
#define AD400X_TURBO_MODE(x)
Definition: ad400x.h:61
spi_engine_set_speed
void spi_engine_set_speed(struct no_os_spi_desc *desc, uint32_t speed_hz)
Set SPI engine clock frequency.
Definition: spi_engine.c:152
no_os_error.h
Error codes definition.
NO_OS_DIV_ROUND_UP
#define NO_OS_DIV_ROUND_UP(x, y)
Definition: no_os_util.h:56
ad400x_dev::dev_id
enum ad400x_supported_dev_ids dev_id
Definition: ad400x.h:97
ad400x_dev::reg_access_speed
uint32_t reg_access_speed
Definition: ad400x.h:95
spi_engine_set_transfer_width
int32_t spi_engine_set_transfer_width(struct no_os_spi_desc *desc, uint8_t data_wdith)
Set width of the transfered word over SPI.
Definition: spi_engine.c:131
ad400x_init_param::high_z_mode
bool high_z_mode
Definition: ad400x.h:133
AD400X_SPAN_COMPRESSION
#define AD400X_SPAN_COMPRESSION(x)
Definition: ad400x.h:63
ad400x_init_param::trigger_pwm_init
struct no_os_pwm_init_param * trigger_pwm_init
Definition: ad400x.h:112
ad7616_init_param::offload_init_param
struct spi_engine_offload_init_param * offload_init_param
Definition: ad7616.h:211
ad400x_dev::clkgen
struct axi_clkgen * clkgen
Definition: ad400x.h:89
ad7616_init_param::trigger_pwm_init
struct no_os_pwm_init_param * trigger_pwm_init
Definition: ad7616.h:213
spi_engine.h
ad400x_dev::trigger_pwm_desc
struct no_os_pwm_desc * trigger_pwm_desc
Definition: ad400x.h:91
ID_AD4003
@ ID_AD4003
Definition: ad400x.h:70
ad400x_dev_info
Definition: ad400x.h:80
ad400x_init_param::turbo_mode
bool turbo_mode
Definition: ad400x.h:132
ad400x_init_param::offload_enable
bool offload_enable
Definition: ad400x.h:131
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:110
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:177
ID_AD4004
@ ID_AD4004
Definition: ad400x.h:71
ad400x_init_param::spi_init
struct no_os_spi_init_param * spi_init
Definition: ad400x.h:110
ad400x_dev::dcache_invalidate_range
void(* dcache_invalidate_range)(uint32_t address, uint32_t bytes_count)
Definition: ad400x.h:103
ID_AD4001
@ ID_AD4001
Definition: ad400x.h:68
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:102
ad400x_dev::offload_enable
bool offload_enable
Definition: ad400x.h:105
ad400x_dev::offload_init_param
struct spi_engine_offload_init_param * offload_init_param
Definition: ad400x.h:99
no_os_pwm_desc
Structure representing an PWM generator device.
Definition: no_os_pwm.h:99
ID_AD4020
@ ID_AD4020
Definition: ad400x.h:76
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:57
ad400x_init_param::en_status_bits
bool en_status_bits
Definition: ad400x.h:135
ad400x_init
int32_t ad400x_init(struct ad400x_dev **device, struct ad400x_init_param *init_param)
Definition: ad400x.c:287
ad7616_init_param::dcache_invalidate_range
void(* dcache_invalidate_range)(uint32_t address, uint32_t bytes_count)
Definition: ad7616.h:236
ad7616_init_param::axi_clkgen_rate
uint32_t axi_clkgen_rate
Definition: ad7616.h:217
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
ad400x.h
Header file for ad400x Driver.
no_os_malloc
void * no_os_malloc(size_t size)
Allocate memory and return a pointer to it.
Definition: chibios_alloc.c:49
ad400x_init_param::offload_init_param
struct spi_engine_offload_init_param * offload_init_param
Definition: ad400x.h:124
ad400x_read_data
int32_t ad400x_read_data(struct ad400x_dev *dev, uint32_t *buf, uint16_t samples)
Definition: ad400x.c:258
no_os_pwm.h
Header file of PWM Interface.
ad400x_remove
int32_t ad400x_remove(struct ad400x_dev *dev)
Free the resources allocated by ad400x_init().
Definition: ad400x.c:370
ID_AD4007
@ ID_AD4007
Definition: ad400x.h:74
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:75
ad400x_init_param::gpio_cnv
struct no_os_gpio_init_param * gpio_cnv
Definition: ad400x.h:118
AD400X_HIGH_Z_MODE
#define AD400X_HIGH_Z_MODE(x)
Definition: ad400x.h:62
ad400x_init_param::buffer_size
uint32_t buffer_size
Definition: ad400x.h:130
no_os_get_unaligned_be32
uint32_t no_os_get_unaligned_be32(uint8_t *buf)
no_os_gpio_set_value
int32_t no_os_gpio_set_value(struct no_os_gpio_desc *desc, uint8_t value)
Set the value of the specified GPIO.
Definition: no_os_gpio.c:203
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:119
ad7616_init_param::clkgen_init
struct axi_clkgen_init * clkgen_init
Definition: ad7616.h:215
ad400x_init_param::reg_access_speed
uint32_t reg_access_speed
Definition: ad400x.h:120
ad400x_dev::gpio_cnv
struct no_os_gpio_desc * gpio_cnv
Definition: ad400x.h:93
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:805
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:122
spi_engine_offload_init_param
Structure containing the init parameters needed by the offload module.
Definition: spi_engine.h:145
no_os_gpio.h
Header file of GPIO Interface.
no_os_spi_desc::max_speed_hz
uint32_t max_speed_hz
Definition: no_os_spi.h:183
ID_AD4006
@ ID_AD4006
Definition: ad400x.h:73
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:58
ad400x_init
int32_t ad400x_init(struct ad400x_dev **device, struct ad400x_init_param *init_param)
Definition: ad400x.c:287
axi_clkgen_remove
int32_t axi_clkgen_remove(struct axi_clkgen *clkgen)
axi_clkgen_remove
Definition: clk_axi_clkgen.c:546
no_os_util.h
Header file of utility functions.
AD400X_WRITE_COMMAND
#define AD400X_WRITE_COMMAND
Definition: ad400x.h:58
ad400x_init_param::span_compression
bool span_compression
Definition: ad400x.h:134
ad400x_read_data
int32_t ad400x_read_data(struct ad400x_dev *dev, uint32_t *buf, uint16_t samples)
Definition: ad400x.c:258
no_os_gpio_direction_output
int32_t no_os_gpio_direction_output(struct no_os_gpio_desc *desc, uint8_t value)
Enable the output direction of the specified GPIO.
Definition: no_os_gpio.c:153
ID_AD4011
@ ID_AD4011
Definition: ad400x.h:75
READ
#define READ(no_bytes)
Definition: spi_engine.h:68
ad400x_init_param::dev_id
enum ad400x_supported_dev_ids dev_id
Definition: ad400x.h:122
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:131
ID_AD4005
@ ID_AD4005
Definition: ad400x.h:72