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