no-OS
ad5421.h
Go to the documentation of this file.
1 /**************************************************************************/
34 #ifndef _AD5421_H_
35 #define _AD5421_H_
36 
37 /*****************************************************************************/
38 /***************************** Include Files *********************************/
39 /*****************************************************************************/
40 #include <stdint.h>
41 #include "no_os_gpio.h"
42 #include "no_os_spi.h"
43 
44 /*****************************************************************************/
45 /******************** Macros and Constants Definitions ***********************/
46 /*****************************************************************************/
47 /* COMMAND Bytes */
48 #define AD5421_CMDWRDAC 1
49 #define AD5421_CMDWRCTRL 2
50 #define AD5421_CMDWROFFSET 3
51 #define AD5421_CMDWRGAIN 4
52 #define AD5421_CMDRST 7
53 #define AD5421_CMDMEASVTEMP 8
54 #define AD5421_NO_OP 9
55 #define AD5421_CMDRDDAC 129
56 #define AD5421_CMDRDCTRL 130
57 #define AD5421_CMDRDOFFSET 131
58 #define AD5421_CMDRDGAIN 132
59 #define AD5421_CMDRDFAULT 133
60 
61 /* AD5421 COMMAND mask */
62 #define AD5421_CMD(x) ((x & 0xFF) << 16)
63 
64 /* AD5421 GPIO */
65 #define AD5421_LDAC_OUT no_os_gpio_direction_output(dev->gpio_ldac, \
66  NO_OS_GPIO_HIGH)
67 #define AD5421_LDAC_LOW no_os_gpio_set_value(dev->gpio_ldac, \
68  NO_OS_GPIO_LOW)
69 #define AD5421_LDAC_HIGH no_os_gpio_set_value(dev->gpio_ldac, \
70  NO_OS_GPIO_HIGH)
71 #define AD5421_FAULT_IN no_os_gpio_direction_input(dev->gpio_faultin)
72 
73 /* CONTROL register bits */
74 #define CTRL_SPI_WATCHDOG (1 << 12)
75 #define CTRL_AUTO_FAULT_RDBK (1 << 11)
76 #define CTRL_SEL_ADC_INPUT (1 << 8)
77 #define CTRL_ONCHIP_ADC (1 << 7)
78 
79 /******************************************************************************/
80 /*************************** Types Declarations *******************************/
81 /******************************************************************************/
82 
83 struct ad5421_dev {
84  /* SPI */
86  /* GPIO */
89 };
90 
92  /* SPI */
94  /* GPIO */
97 };
98 
99 /*****************************************************************************/
100 /************************* Functions Declarations ****************************/
101 /*****************************************************************************/
102 /* Initialize the communication with the device. */
103 int32_t ad5421_init(struct ad5421_dev **device,
105 /* Free the resources allocated by ad5421_init(). */
106 int32_t ad5421_remove(struct ad5421_dev *dev);
107 /* Set the value of DAC register. */
108 void ad5421_set_dac(struct ad5421_dev *dev,
109  int32_t dac_value);
110 /* Set the value of OFFSET register. */
111 void ad5421_set_offset(struct ad5421_dev *dev,
112  int32_t offset_value);
113 /* Set the value of GAIN register. */
114 void ad5421_set_gain(struct ad5421_dev *dev,
115  int32_t gain_value);
116 /* Read the DAC register. */
117 int32_t ad5421_get_dac(struct ad5421_dev *dev);
118 /* Read OFFSET register. */
119 int32_t ad5421_get_offset(struct ad5421_dev *dev);
120 /* Read GAIN register. */
121 int32_t ad5421_get_gain(struct ad5421_dev *dev);
122 /* Read FAULT register. */
123 int32_t ad5421_get_fault(struct ad5421_dev *dev);
124 /* Read the temperature from Fault register. */
125 int32_t ad5421_get_temp(struct ad5421_dev *dev);
126 /* Read VLoop-COM from Fault register. */
127 float ad5421_get_vloop(struct ad5421_dev *dev);
128 /* Send command via SPI. */
129 int32_t ad5421_set(struct ad5421_dev *dev,
130  int32_t *i_value);
131 /* Receive value via SPI. */
132 int32_t ad5421_get(struct ad5421_dev *dev);
133 /* Resets the AD5421 device. */
134 void ad5421_reset(struct ad5421_dev *dev);
135 
136 #endif /* _AD5421_H_ */
AD5421_CMDWRGAIN
#define AD5421_CMDWRGAIN
Definition: ad5421.h:51
AD5421_CMDRDGAIN
#define AD5421_CMDRDGAIN
Definition: ad5421.h:58
ad5421_dev::gpio_faultin
struct no_os_gpio_desc * gpio_faultin
Definition: ad5421.h:88
no_os_alloc.h
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:79
ad5421_init_param::gpio_faultin
struct no_os_gpio_init_param gpio_faultin
Definition: ad5421.h:96
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
ad5421_get_vloop
float ad5421_get_vloop(struct ad5421_dev *dev)
Read VLoop-COM from Fault register.
Definition: ad5421.c:324
ad5421_get
int32_t ad5421_get(struct ad5421_dev *dev)
Read data via SPI.
Definition: ad5421.c:393
no_os_spi.h
Header file of SPI Interface.
ad5421_get
int32_t ad5421_get(struct ad5421_dev *dev)
Read data via SPI.
Definition: ad5421.c:393
AD5421_CMDWROFFSET
#define AD5421_CMDWROFFSET
Definition: ad5421.h:50
AD5421_CMDWRCTRL
#define AD5421_CMDWRCTRL
Definition: ad5421.h:49
ad5421_reset
void ad5421_reset(struct ad5421_dev *dev)
Resets the ad5421 device.
Definition: ad5421.c:418
ad5421_get_dac
int32_t ad5421_get_dac(struct ad5421_dev *dev)
Read from the DAC register.
Definition: ad5421.c:198
ad5421_set
int32_t ad5421_set(struct ad5421_dev *dev, int32_t *value)
Send data via SPI.
Definition: ad5421.c:365
device
Definition: ad9361_util.h:69
ad5421_init_param
Definition: ad5421.h:91
CTRL_ONCHIP_ADC
#define CTRL_ONCHIP_ADC
Definition: ad5421.h:77
ad5421_dev::gpio_ldac
struct no_os_gpio_desc * gpio_ldac
Definition: ad5421.h:87
ad5421_init_param::gpio_ldac
struct no_os_gpio_init_param gpio_ldac
Definition: ad5421.h:95
AD5421_CMDMEASVTEMP
#define AD5421_CMDMEASVTEMP
Definition: ad5421.h:53
CTRL_SPI_WATCHDOG
#define CTRL_SPI_WATCHDOG
Definition: ad5421.h:74
ad5421_init
int32_t ad5421_init(struct ad5421_dev **device, struct ad5421_init_param init_param)
Initialize SPI and Initial Values for AD5421 Board.
Definition: ad5421.c:57
CTRL_AUTO_FAULT_RDBK
#define CTRL_AUTO_FAULT_RDBK
Definition: ad5421.h:75
ad5421_get_fault
int32_t ad5421_get_fault(struct ad5421_dev *dev)
Read from the Fault register.
Definition: ad5421.c:261
ad5421_get_dac
int32_t ad5421_get_dac(struct ad5421_dev *dev)
Read from the DAC register.
Definition: ad5421.c:198
AD5421_CMDRDDAC
#define AD5421_CMDRDDAC
Definition: ad5421.h:55
ad5421_get_gain
int32_t ad5421_get_gain(struct ad5421_dev *dev)
Read from the Gain Adjust register.
Definition: ad5421.c:240
AD5421_CMDRDOFFSET
#define AD5421_CMDRDOFFSET
Definition: ad5421.h:57
ad5421_init
int32_t ad5421_init(struct ad5421_dev **device, struct ad5421_init_param init_param)
Initialize SPI and Initial Values for AD5421 Board.
Definition: ad5421.c:57
ad5421_get_fault
int32_t ad5421_get_fault(struct ad5421_dev *dev)
Read from the Fault register.
Definition: ad5421.c:261
AD5421_CMD
#define AD5421_CMD(x)
Definition: ad5421.h:62
AD5421_CMDRST
#define AD5421_CMDRST
Definition: ad5421.h:52
AD5421_NO_OP
#define AD5421_NO_OP
Definition: ad5421.h:54
ad5421_set
int32_t ad5421_set(struct ad5421_dev *dev, int32_t *i_value)
Send data via SPI.
Definition: ad5421.c:365
ad5421_set_dac
void ad5421_set_dac(struct ad5421_dev *dev, int32_t dac_value)
Write to the DAC register.
Definition: ad5421.c:139
ad5421_set_gain
void ad5421_set_gain(struct ad5421_dev *dev, int32_t gain_value)
Write to the Gain Adjust register.
Definition: ad5421.c:179
ad5421_dev
Definition: ad5421.h:83
ad5421_get_temp
int32_t ad5421_get_temp(struct ad5421_dev *dev)
Read the temperature from Fault register.
Definition: ad5421.c:283
ad5421_remove
int32_t ad5421_remove(struct ad5421_dev *dev)
Free the resources allocated by ad5421_init().
Definition: ad5421.c:117
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
ad5421_set_gain
void ad5421_set_gain(struct ad5421_dev *dev, int32_t gain_value)
Write to the Gain Adjust register.
Definition: ad5421.c:179
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:192
ad5421_get_gain
int32_t ad5421_get_gain(struct ad5421_dev *dev)
Read from the Gain Adjust register.
Definition: ad5421.c:240
ad5421_get_temp
int32_t ad5421_get_temp(struct ad5421_dev *dev)
Read the temperature from Fault register.
Definition: ad5421.c:283
AD5421_FAULT_IN
#define AD5421_FAULT_IN
Definition: ad5421.h:71
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:96
ad5421_get_offset
int32_t ad5421_get_offset(struct ad5421_dev *dev)
Read from the Offset Adjust register.
Definition: ad5421.c:219
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
ad5421_get_offset
int32_t ad5421_get_offset(struct ad5421_dev *dev)
Read from the Offset Adjust register.
Definition: ad5421.c:219
no_os_malloc
void * no_os_malloc(size_t size)
Allocate memory and return a pointer to it.
Definition: chibios_alloc.c:43
AD5421_LDAC_OUT
#define AD5421_LDAC_OUT
Definition: ad5421.h:65
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
CTRL_SEL_ADC_INPUT
#define CTRL_SEL_ADC_INPUT
Definition: ad5421.h:76
AD5421_CMDRDFAULT
#define AD5421_CMDRDFAULT
Definition: ad5421.h:59
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
ad5421_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: ad5421.h:85
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
no_os_gpio.h
Header file of GPIO Interface.
ad5421_init_param::spi_init
struct no_os_spi_init_param spi_init
Definition: ad5421.h:93
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
ad5421_get_vloop
float ad5421_get_vloop(struct ad5421_dev *dev)
Read VLoop-COM from Fault register.
Definition: ad5421.c:324
ad5421.h
Header file of AD5421 Driver for Microblaze processor.
AD5421_CMDWRDAC
#define AD5421_CMDWRDAC
Definition: ad5421.h:48
ad5421_set_dac
void ad5421_set_dac(struct ad5421_dev *dev, int32_t dac_value)
Write to the DAC register.
Definition: ad5421.c:139
AD5421_CMDRDCTRL
#define AD5421_CMDRDCTRL
Definition: ad5421.h:56
ad5421_set_offset
void ad5421_set_offset(struct ad5421_dev *dev, int32_t offset_value)
Write to the Offset Adjust register.
Definition: ad5421.c:159
ad5421_remove
int32_t ad5421_remove(struct ad5421_dev *dev)
Free the resources allocated by ad5421_init().
Definition: ad5421.c:117
ad5421_reset
void ad5421_reset(struct ad5421_dev *dev)
Resets the ad5421 device.
Definition: ad5421.c:418
AD5421_LDAC_LOW
#define AD5421_LDAC_LOW
Definition: ad5421.h:67
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140
ad5421_set_offset
void ad5421_set_offset(struct ad5421_dev *dev, int32_t offset_value)
Write to the Offset Adjust register.
Definition: ad5421.c:159