no-OS
ad525x.h
Go to the documentation of this file.
1 /**************************************************************************/
42 #ifndef __AD525X_H__
43 #define __AD525X_H__
44 
45 /*****************************************************************************/
46 /****************************** Include Files ********************************/
47 /*****************************************************************************/
48 #include <stdint.h>
49 #include "no_os_delay.h"
50 #include "no_os_gpio.h"
51 #include "no_os_spi.h"
52 #include "no_os_i2c.h"
53 
54 /*****************************************************************************/
55 /* Device specific MACROs */
56 /*****************************************************************************/
57 /* GPIOs */
58 #define AD525X_RESET_OUT no_os_gpio_direction_output(dev->gpio_reset, \
59  NO_OS_GPIO_HIGH)
60 #define AD525X_RESET_LOW no_os_gpio_set_value(dev->gpio_reset, \
61  NO_OS_GPIO_LOW)
62 #define AD525X_RESET_HIGH no_os_gpio_set_value(dev->gpio_reset, \
63  NO_OS_GPIO_HIGH)
64 #define AD525X_SHUTDOWN_OUT no_os_gpio_direction_output(dev->gpio_shutdown, \
65  NO_OS_GPIO_HIGH)
66 #define AD525X_SHUTDOWN_LOW no_os_gpio_set_value(dev->gpio_shutdown, \
67  NO_OS_GPIO_LOW)
68 #define AD525X_SHUTDOWN_HIGH no_os_gpio_set_value(dev->gpio_shutdown, \
69  NO_OS_GPIO_HIGH)
70 #define AD525X_READY_IN no_os_gpio_direction_input(dev->gpio_ready)
71 #define AD525X_READY_LOW no_os_gpio_set_value(dev->gpio_ready, \
72  NO_OS_GPIO_LOW)
73 #define AD525X_READY_HIGH no_os_gpio_set_value(dev->gpio_ready, \
74  NO_OS_GPIO_HIGH)
75 #define AD525X_WP_BF_OUT no_os_gpio_direction_output(dev->gpio_wpbf, \
76  NO_OS_GPIO_HIGH)
77 #define AD525X_WP_BF_LOW no_os_gpio_set_value(dev->gpio_wpbf, \
78  NO_OS_GPIO_LOW)
79 #define AD525X_WP_BF_HIGH no_os_gpio_set_value(dev->gpio_wpbf, \
80  NO_OS_GPIO_HIGH)
81 
82 /* Data word masks */
83 #define AD525X_MEM_ADDR_MASK 0xF
84 #define AD525X_RDAC_ADDR_MASK_1BIT 0x1
85 #define AD525X_RDAC_ADDR_MASK_3BIT 0x7
86 #define AD525X_DATA8_MASK 0xFF
87 #define AD525X_DATA10_MASK 0x3FF
88 
89 /*********************** Command definitions *********************************/
90 #define AD525X_CMD_NOP 0x0
91 #define AD525X_CMD_MEM2RDAC 0x1
92 #define AD525X_CMD_RDAC2MEM 0x2
93 #define AD525X_CMD_DECRDAC_6DB 0x3
94 #define AD525X_CMD_DECALLRDAC_6DB 0x4
95 #define AD525X_CMD_DECRDAC_ONE 0x5
96 #define AD525X_CMD_DECALLRDAC_ONE 0x6
97 #define AD525X_CMD_RESET 0x7
98 #define AD525X_CMD_INCRDAC_6DB 0x8
99 #define AD525X_CMD_INCALLRDAC_6DB 0x9
100 #define AD525X_CMD_INCRDAC_ONE 0xA
101 #define AD525X_CMD_INCALLRDAC_ONE 0xB
102 /*****************************************************************************/
103 
104 /**************************** SPI specific macros ****************************/
105 #define AD525X_CMD_SPI_OFFSET 0x4
106 #define AD525X_CMD_MASK 0xF
107 /* SPI Read/Write commands */
108 #define AD525X_CMD_SPI_SREG2MEM 0x3
109 #define AD525X_CMD_SPI_MEM2SREG 0x9 // Result in the next frame
110 #define AD525X_CMD_SPI_RDAC2SREG 0xA // Result in the next frame
111 #define AD525X_CMD_SPI_SREG2RDAC 0xB
112 
113 /*************************** I2C specific macros *****************************/
114 /* I2C device address */
115 #define AD525X_I2C_HARD_ADDR 0x2C
116 /* Package pin-programmable address bits */
117 #define AD525X_I2C_PIN_ADDR_MASK 0x03
118 /* Mask for I2C Control Bits */
119 #define AD525X_I2C_CNTR_MASK 0xBF
120 /* Access Types */
121 #define AD525X_I2C_CMD_OR_REG 0x80
122 #define AD525X_I2C_EE_OR_RDAC 0x20
123 /* Address mask for EEMEM addresses, one bit wider than at devices with SPI */
124 #define AD525X_I2C_MEM_ADDR_MASK 0x1F
125 /* The offset of the Command in the I2C word */
126 #define AD525X_CMD_I2C_OFFSET 0x3
127 
128 /*************************** Reading tolerance addresses *********************/
129 /* Note: The valid tolerance addresses varies on different devices. Check the data sheet for further information */
130 #define AD525x_RDAC_TOLERANCE 0x0F
131 #define AD525X_RDAC0_SIGN_TOL 0x18
132 #define AD525X_RDAC0_DECIMAL_TOL 0x19
133 #define AD525X_RDAC1_SIGN_TOL 0x1A
134 #define AD525X_RDAC1_DECIMAL_TOL 0x1B
135 #define AD525X_RDAC2_SIGN_TOL 0x1C
136 #define AD525X_RDAC2_DECIMAL_TOL 0x1D
137 #define AD525X_RDAC3_SIGN_TOL 0x1E
138 #define AD525X_RDAC4_DECIMAL_TOL 0x1F
139 
140 /******************************************************************************/
141 /*************************** Types Declarations *******************************/
142 /******************************************************************************/
143 
144 /* Custom boolean type */
145 enum bool_t {
146  false,
147  true
148 };
149 
150 /* Supported devices */
159 };
160 
161 /* Communication types */
165 };
166 
168  uint8_t num_channels;
170  uint16_t num_position;
171 };
172 
173 struct ad525x_dev {
174  /* I2C */
176  /* SPI */
178  /* GPIO */
183  /* Device Settings */
185 };
186 
188  /* I2C */
190  /* SPI */
192  /* GPIO */
197  /* Device Settings */
199 };
200 
201 /*****************************************************************************/
202 /* Functions Prototypes */
203 /*****************************************************************************/
204 /* Initialize the communication with the device */
205 int8_t ad525x_init(struct ad525x_dev **device,
207 
208 /* Free the resources allocated by ad525x_init(). */
209 int32_t ad525x_remove(struct ad525x_dev *dev);
210 
211 /* Read data from the EEMEM */
212 uint16_t ad525x_read_mem(struct ad525x_dev *dev,
213  uint8_t address);
214 
215 /* Write data to EEMEM */
216 void ad525x_write_mem(struct ad525x_dev *dev,
217  uint8_t address,
218  uint16_t data);
219 
220 /* Read the value of the RDAC register */
221 uint16_t ad525x_read_rdac(struct ad525x_dev *dev,
222  uint8_t address);
223 
224 /* Write the value of the RDAC register */
225 void ad525x_write_rdac(struct ad525x_dev *dev,
226  uint8_t address,
227  uint16_t data);
228 
229 /* Write quick commands to the device */
230 void ad525x_write_command(struct ad525x_dev *dev,
231  uint8_t command,
232  uint8_t address);
233 
234 #endif // __AD525X_H__
AD525X_CMD_SPI_MEM2SREG
#define AD525X_CMD_SPI_MEM2SREG
Definition: ad525x.h:109
AD525X_CMD_SPI_SREG2RDAC
#define AD525X_CMD_SPI_SREG2RDAC
Definition: ad525x.h:111
ad525x_write_command
void ad525x_write_command(struct ad525x_dev *dev, uint8_t command, uint8_t address)
Write quick commands to the device.
Definition: ad525x.c:398
ad525x_init_param::gpio_wpbf
struct no_os_gpio_init_param gpio_wpbf
Definition: ad525x.h:196
ad525x_chip_info::num_position
uint16_t num_position
Definition: ad525x.h:170
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:85
ad525x_write_mem
void ad525x_write_mem(struct ad525x_dev *dev, uint8_t address, uint16_t data)
Write data to EEMEM.
Definition: ad525x.c:244
ad525x_dev::gpio_ready
struct no_os_gpio_desc * gpio_ready
Definition: ad525x.h:181
AD525X_I2C_MEM_ADDR_MASK
#define AD525X_I2C_MEM_ADDR_MASK
Definition: ad525x.h:124
no_os_i2c_write
int32_t no_os_i2c_write(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Write data to slave device.
Definition: no_os_i2c.c:85
no_os_i2c_init
int32_t no_os_i2c_init(struct no_os_i2c_desc **desc, const struct no_os_i2c_init_param *param)
Initialize the I2C communication peripheral.
Definition: no_os_i2c.c:51
ad525x_chip_info::num_channels
uint8_t num_channels
Definition: ad525x.h:168
ID_ADN2850
@ ID_ADN2850
Definition: ad525x.h:154
ad525x_remove
int32_t ad525x_remove(struct ad525x_dev *dev)
Free the resources allocated by ad525x_init().
Definition: ad525x.c:153
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:82
ad525x_dev::spi_desc
no_os_spi_desc * spi_desc
Definition: ad525x.h:177
no_os_spi.h
Header file of SPI Interface.
ID_AD5254
@ ID_AD5254
Definition: ad525x.h:157
ad525x_write_command
void ad525x_write_command(struct ad525x_dev *dev, uint8_t command, uint8_t address)
Write quick commands to the device.
Definition: ad525x.c:398
no_os_i2c_remove
int32_t no_os_i2c_remove(struct no_os_i2c_desc *desc)
Free the resources allocated by no_os_i2c_init().
Definition: no_os_i2c.c:70
I2C
@ I2C
Definition: ad525x.h:164
comm_type_t
comm_type_t
Definition: ad5629r.h:139
chip_info
const struct adf4106_chip_info chip_info[]
Definition: adf4106.c:62
no_os_delay.h
Header file of Delay functions.
ID_AD5235
@ ID_AD5235
Definition: ad525x.h:153
AD525X_CMD_SPI_OFFSET
#define AD525X_CMD_SPI_OFFSET
Definition: ad525x.h:105
device
Definition: ad9361_util.h:75
ad525x_dev::gpio_wpbf
struct no_os_gpio_desc * gpio_wpbf
Definition: ad525x.h:182
AD525X_CMD_SPI_RDAC2SREG
#define AD525X_CMD_SPI_RDAC2SREG
Definition: ad525x.h:110
ad525x_write_mem
void ad525x_write_mem(struct ad525x_dev *dev, uint8_t address, uint16_t data)
Write data to EEMEM.
Definition: ad525x.c:244
AD525X_I2C_EE_OR_RDAC
#define AD525X_I2C_EE_OR_RDAC
Definition: ad525x.h:122
ad525x_init_param::gpio_ready
struct no_os_gpio_init_param gpio_ready
Definition: ad525x.h:195
AD525X_RDAC_ADDR_MASK_3BIT
#define AD525X_RDAC_ADDR_MASK_3BIT
Definition: ad525x.h:85
ID_AD5232
@ ID_AD5232
Definition: ad525x.h:152
SPI
@ SPI
Definition: ad525x.h:163
ad525x_init
int8_t ad525x_init(struct ad525x_dev **device, struct ad525x_init_param init_param)
Initialize SPI and Initial Values for AD5172 Board.
Definition: ad525x.c:105
ad525x_remove
int32_t ad525x_remove(struct ad525x_dev *dev)
Free the resources allocated by ad525x_init().
Definition: ad525x.c:153
AD525X_CMD_SPI_SREG2MEM
#define AD525X_CMD_SPI_SREG2MEM
Definition: ad525x.h:108
AD525X_MEM_ADDR_MASK
#define AD525X_MEM_ADDR_MASK
Definition: ad525x.h:83
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: delay.c:130
bool_t
bool_t
Definition: ad5446.h:63
ad525x_init_param::i2c_init
no_os_i2c_init_param i2c_init
Definition: ad525x.h:189
I2C
@ I2C
Definition: adxl372.h:323
ad525x_dev::gpio_reset
struct no_os_gpio_desc * gpio_reset
Definition: ad525x.h:179
LSB_BYTE_MASK
#define LSB_BYTE_MASK
Definition: ad525x.c:48
ad525x_init_param::gpio_shutdown
struct no_os_gpio_init_param gpio_shutdown
Definition: ad525x.h:194
ID_AD5253
@ ID_AD5253
Definition: ad525x.h:158
AD525X_READY_IN
#define AD525X_READY_IN
Definition: ad525x.h:70
AD525X_WP_BF_HIGH
#define AD525X_WP_BF_HIGH
Definition: ad525x.h:79
AD525X_WP_BF_OUT
#define AD525X_WP_BF_OUT
Definition: ad525x.h:75
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:95
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:132
AD525X_SHUTDOWN_OUT
#define AD525X_SHUTDOWN_OUT
Definition: ad525x.h:64
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:102
ONEBYTE_OFFSET
#define ONEBYTE_OFFSET
Definition: ad525x.c:49
ad525x_dev
Definition: ad525x.h:173
no_os_i2c_desc
Structure holding I2C descriptor.
Definition: no_os_i2c.h:81
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
AD525X_RESET_HIGH
#define AD525X_RESET_HIGH
Definition: ad525x.h:62
no_os_i2c_read
int32_t no_os_i2c_read(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Read data from slave device.
Definition: no_os_i2c.c:104
ad525x_dev::i2c_desc
no_os_i2c_desc * i2c_desc
Definition: ad525x.h:175
ID_AD5252
@ ID_AD5252
Definition: ad525x.h:155
no_os_i2c.h
Header file of I2C Interface.
AD525X_RESET_OUT
#define AD525X_RESET_OUT
Definition: ad525x.h:58
AD525X_CMD_MASK
#define AD525X_CMD_MASK
Definition: ad525x.h:106
AD525X_CMD_NOP
#define AD525X_CMD_NOP
Definition: ad525x.h:90
ad525x_write_rdac
void ad525x_write_rdac(struct ad525x_dev *dev, uint8_t address, uint16_t data)
Write data to RDAC register.
Definition: ad525x.c:352
AD525X_CMD_MEM2RDAC
#define AD525X_CMD_MEM2RDAC
Definition: ad525x.h:91
ad525x_read_rdac
uint16_t ad525x_read_rdac(struct ad525x_dev *dev, uint8_t address)
Read data from the RDAC register.
Definition: ad525x.c:289
ad525x_dev::gpio_shutdown
struct no_os_gpio_desc * gpio_shutdown
Definition: ad525x.h:180
ad525x_init_param::spi_init
no_os_spi_init_param spi_init
Definition: ad525x.h:191
ad525x_write_rdac
void ad525x_write_rdac(struct ad525x_dev *dev, uint8_t address, uint16_t data)
Write data to RDAC register.
Definition: ad525x.c:352
no_os_i2c_init_param
Structure holding the parameters for I2C initialization.
Definition: no_os_i2c.h:64
ad525x.h
Header file of AD525X Driver for Microblaze processor. This driver supporting the following devices :...
AD525X_CMD_RESET
#define AD525X_CMD_RESET
Definition: ad525x.h:97
AD525X_CMD_DECRDAC_6DB
#define AD525X_CMD_DECRDAC_6DB
Definition: ad525x.h:93
AD525X_SHUTDOWN_HIGH
#define AD525X_SHUTDOWN_HIGH
Definition: ad525x.h:68
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:96
ad525x_read_rdac
uint16_t ad525x_read_rdac(struct ad525x_dev *dev, uint8_t address)
Read data from the RDAC register.
Definition: ad525x.c:289
MSB_BYTE_MASK
#define MSB_BYTE_MASK
Definition: ad525x.c:47
AD525X_DATA10_MASK
#define AD525X_DATA10_MASK
Definition: ad525x.h:87
ad525x_dev::this_device
enum ad525_x_type_t this_device
Definition: ad525x.h:184
AD525X_CMD_INCRDAC_6DB
#define AD525X_CMD_INCRDAC_6DB
Definition: ad525x.h:98
ad525x_read_mem
uint16_t ad525x_read_mem(struct ad525x_dev *dev, uint8_t address)
Read data from the EEMEM.
Definition: ad525x.c:188
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:70
AD525X_CMD_I2C_OFFSET
#define AD525X_CMD_I2C_OFFSET
Definition: ad525x.h:126
ad525x_chip_info
Definition: ad525x.h:167
no_os_gpio.h
Header file of GPIO Interface.
ad525x_read_mem
uint16_t ad525x_read_mem(struct ad525x_dev *dev, uint8_t address)
Read data from the EEMEM.
Definition: ad525x.c:188
ID_AD5251
@ ID_AD5251
Definition: ad525x.h:156
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:51
ad525x_init_param
Definition: ad525x.h:187
AD525X_I2C_CMD_OR_REG
#define AD525X_I2C_CMD_OR_REG
Definition: ad525x.h:121
AD525X_RDAC_ADDR_MASK_1BIT
#define AD525X_RDAC_ADDR_MASK_1BIT
Definition: ad525x.h:84
ad525x_init
int8_t ad525x_init(struct ad525x_dev **device, struct ad525x_init_param init_param)
Initialize SPI and Initial Values for AD5172 Board.
Definition: ad525x.c:105
SPI
@ SPI
Definition: adxl372.h:322
ad525x_chip_info::comm_type
enum comm_type_t comm_type
Definition: ad525x.h:169
ad525x_init_param::this_device
enum ad525_x_type_t this_device
Definition: ad525x.h:198
ad525_x_type_t
ad525_x_type_t
Definition: ad525x.h:151
ad525x_init_param::gpio_reset
struct no_os_gpio_init_param gpio_reset
Definition: ad525x.h:193
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:112