no-OS
ad9833.h
Go to the documentation of this file.
1 /***************************************************************************/
40 #ifndef _AD9833_H_
41 #define _AD9833_H_
42 
43 /******************************************************************************/
44 /******************************* Include Files ********************************/
45 /******************************************************************************/
46 #include <stdint.h>
47 #include "no_os_delay.h"
48 #include "no_os_gpio.h"
49 #include "no_os_spi.h"
50 
51 /******************************************************************************/
52 /********************* Macros and Constants Definitions ***********************/
53 /******************************************************************************/
54 
55 #define AD9833_CTRLB28 (1 << 13)
56 #define AD9833_CTRLHLB (1 << 12)
57 #define AD9833_CTRLFSEL (1 << 11)
58 #define AD9833_CTRLPSEL (1 << 10)
59 #define AD9834_CTRLPINSW (1 << 9)
60 #define AD9833_CTRLRESET (1 << 8)
61 #define AD9833_CTRLSLEEP1 (1 << 7)
62 #define AD9833_CTRLSLEEP12 (1 << 6)
63 #define AD9833_CTRLOPBITEN (1 << 5)
64 #define AD9834_CTRLSIGNPIB (1 << 4)
65 #define AD9833_CTRLDIV2 (1 << 3)
66 #define AD9833_CTRLMODE (1 << 1)
67 
68 /* GPIOs */
69 #define AD9834_PSEL_OUT no_os_gpio_direction_output(dev->gpio_psel, \
70  NO_OS_GPIO_HIGH)
71 #define AD9834_PSEL_LOW no_os_gpio_set_value(dev->gpio_psel, \
72  NO_OS_GPIO_LOW)
73 #define AD9834_PSEL_HIGH no_os_gpio_set_value(dev->gpio_psel, \
74  NO_OS_GPIO_HIGH)
75 
76 #define AD9834_FSEL_OUT no_os_gpio_direction_output(dev->gpio_fsel, \
77  NO_OS_GPIO_HIGH)
78 #define AD9834_FSEL_LOW no_os_gpio_set_value(dev->gpio_fsel, \
79  NO_OS_GPIO_LOW)
80 #define AD9834_FSEL_HIGH no_os_gpio_set_value(dev->gpio_fsel, \
81  NO_OS_GPIO_HIGH)
82 
83 #define AD9834_RESET_OUT no_os_gpio_direction_output(dev->gpio_reset, \
84  NO_OS_GPIO_HIGH)
85 #define AD9834_RESET_LOW no_os_gpio_set_value(dev->gpio_reset, \
86  NO_OS_GPIO_LOW)
87 #define AD9834_RESET_HIGH pio_set_value(dev->gpio_reset, \
88  NO_OS_GPIO_HIGH)
89 
90 #define AD9834_SLEEP_OUT no_os_gpio_direction_output(dev->gpio_sleep, \
91  NO_OS_GPIO_HIGH)
92 #define AD9834_SLEEP_LOW no_os_gpio_set_value(dev->gpio_sleep, \
93  NO_OS_GPIO_LOW)
94 #define AD9834_SLEEP_HIGH no_os_gpio_set_value(dev->gpio_sleep, \
95  NO_OS_GPIO_HIGH)
96 
97 
98 #define BIT_F0ADDRESS 0x4000 // Frequency Register 0 address.
99 #define BIT_F1ADDRESS 0x8000 // Frequency Register 1 address.
100 #define BIT_P0ADDRESS 0xC000 // Phase Register 0 address.
101 #define BIT_P1ADDRESS 0xE000 // Phase Register 1 address.
102 
103 /******************************************************************************/
104 /*************************** Types Declarations *******************************/
105 /******************************************************************************/
106 
107 /* Supported devices */
113 };
114 
115 struct ad9833_dev {
116  /* SPI */
118  /* GPIO */
123  /* Device Settings */
125  uint8_t prog_method;
126  uint16_t ctrl_reg_value;
127  uint16_t test_opbiten;
128 };
129 
131  /* SPI */
133  /* GPIO */
138  /* Device Settings */
140 };
141 
143  uint32_t mclk;
144  float freq_const;
145 };
146 
147 /******************************************************************************/
148 /************************** Functions Declarations ****************************/
149 /******************************************************************************/
150 /* Initialize the SPI communication with the device. */
151 int8_t ad9833_init(struct ad9833_dev **device,
153 /* Free the resources allocated by adf7023_init(). */
154 int32_t ad9833_remove(struct ad9833_dev *dev);
155 /* Transmits 16 bits on SPI. */
156 void ad9833_tx_spi(struct ad9833_dev *dev,
157  int16_t value);
158 /* Selects the type of output. */
159 int8_t ad9833_out_mode(struct ad9833_dev *dev,
160  uint8_t v_out_mode);
161 /* Loads a frequency value in a register. */
162 void ad9833_set_freq(struct ad9833_dev *dev,
163  uint8_t register_number,
164  uint32_t frequency_value);
165 /* Loads a phase value in a register. */
166 void ad9833_set_phase(struct ad9833_dev *dev,
167  uint8_t register_number,
168  float phase_value);
169 /* Select the frequency register to be used. */
170 void ad9833_select_freq_reg(struct ad9833_dev *dev,
171  uint8_t freq_reg);
172 /* Select the phase register to be used. */
173 void ad9833_select_phase_reg(struct ad9833_dev *dev,
174  uint8_t phase_reg);
175 /* Enable / Disable the sleep function. */
176 void ad9833_sleep_mode(struct ad9833_dev *dev,
177  uint8_t sleep_mode);
178 
179 void ad9834_select_prog_method(struct ad9833_dev *dev,
180  uint8_t value);
181 
182 void ad9834_logic_output(struct ad9833_dev *dev,
183  uint8_t opbiten,
184  uint8_t signpib,
185  uint8_t div2);
186 
187 #endif /* _AD9833_H_ */
ad9833_dev
Definition: ad9833.h:115
AD9834_SLEEP_OUT
#define AD9834_SLEEP_OUT
Definition: ad9833.h:90
ad9833_dev::gpio_psel
struct no_os_gpio_desc * gpio_psel
Definition: ad9833.h:119
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:85
AD9834_FSEL_OUT
#define AD9834_FSEL_OUT
Definition: ad9833.h:76
ad9833_init_param::spi_init
no_os_spi_init_param spi_init
Definition: ad9833.h:132
ID_AD9833
@ ID_AD9833
Definition: ad9833.h:109
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
ad9833_sleep_mode
void ad9833_sleep_mode(struct ad9833_dev *dev, uint8_t sleep_mode)
Enable / Disable the sleep function.
Definition: ad9833.c:280
no_os_spi.h
Header file of SPI Interface.
ad9833_remove
int32_t ad9833_remove(struct ad9833_dev *dev)
Free the resources allocated by ad9833_init().
Definition: ad9833.c:151
ad9833_dev::gpio_fsel
struct no_os_gpio_desc * gpio_fsel
Definition: ad9833.h:120
ad9833_select_phase_reg
void ad9833_select_phase_reg(struct ad9833_dev *dev, uint8_t phase_reg)
Select the phase register to be used.
Definition: ad9833.c:425
AD9834_FSEL_LOW
#define AD9834_FSEL_LOW
Definition: ad9833.h:78
no_os_delay.h
Header file of Delay functions.
ad9833_init_param::gpio_reset
struct no_os_gpio_init_param gpio_reset
Definition: ad9833.h:136
AD9833_CTRLPSEL
#define AD9833_CTRLPSEL
Definition: ad9833.h:58
ad9833.h
Header file of AD9833 Driver for Microblaze processor.
ad9833_set_phase
void ad9833_set_phase(struct ad9833_dev *dev, uint8_t register_number, float phase_value)
Loads a phase value in a register.
Definition: ad9833.c:365
AD9833_CTRLSLEEP1
#define AD9833_CTRLSLEEP1
Definition: ad9833.h:61
ad9833_init_param
Definition: ad9833.h:130
device
Definition: ad9361_util.h:75
BIT_F1ADDRESS
#define BIT_F1ADDRESS
Definition: ad9833.h:99
ad9833_set_freq
void ad9833_set_freq(struct ad9833_dev *dev, uint8_t register_number, uint32_t frequency_value)
Loads a frequency value in a register.
Definition: ad9833.c:329
ad9833_set_phase
void ad9833_set_phase(struct ad9833_dev *dev, uint8_t register_number, float phase_value)
Loads a phase value in a register.
Definition: ad9833.c:365
ad9833_select_freq_reg
void ad9833_select_freq_reg(struct ad9833_dev *dev, uint8_t freq_reg)
Select the frequency register to be used.
Definition: ad9833.c:389
BIT_P0ADDRESS
#define BIT_P0ADDRESS
Definition: ad9833.h:100
ad9833_dev::ctrl_reg_value
uint16_t ctrl_reg_value
Definition: ad9833.h:126
ad9834_logic_output
void ad9834_logic_output(struct ad9833_dev *dev, uint8_t opbiten, uint8_t signpib, uint8_t div2)
Configures the control register for logic output. (only for AD9834 & AD9838)
Definition: ad9833.c:487
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: delay.c:130
ad9833_chip_info
Definition: ad9833.h:142
AD9833_CTRLOPBITEN
#define AD9833_CTRLOPBITEN
Definition: ad9833.h:63
ad9833_remove
int32_t ad9833_remove(struct ad9833_dev *dev)
Free the resources allocated by ad9833_init().
Definition: ad9833.c:151
AD9833_CTRLSLEEP12
#define AD9833_CTRLSLEEP12
Definition: ad9833.h:62
no_os_error.h
Error codes definition.
AD9833_CTRLFSEL
#define AD9833_CTRLFSEL
Definition: ad9833.h:57
ad9834_select_prog_method
void ad9834_select_prog_method(struct ad9833_dev *dev, uint8_t value)
Sets the programming method. (only for AD9834 & AD9838)
Definition: ad9833.c:461
AD9834_PSEL_HIGH
#define AD9834_PSEL_HIGH
Definition: ad9833.h:73
ad9833_select_phase_reg
void ad9833_select_phase_reg(struct ad9833_dev *dev, uint8_t phase_reg)
Select the phase register to be used.
Definition: ad9833.c:425
ad9833_dev::prog_method
uint8_t prog_method
Definition: ad9833.h:125
ad9833_select_freq_reg
void ad9833_select_freq_reg(struct ad9833_dev *dev, uint8_t freq_reg)
Select the frequency register to be used.
Definition: ad9833.c:389
AD9834_FSEL_HIGH
#define AD9834_FSEL_HIGH
Definition: ad9833.h:80
ad9833_chip_info::freq_const
float freq_const
Definition: ad9833.h:144
ad9833_out_mode
int8_t ad9833_out_mode(struct ad9833_dev *dev, uint8_t out_mode)
Selects the type of output.
Definition: ad9833.c:211
ID_AD9837
@ ID_AD9837
Definition: ad9833.h:111
ad9833_init_param::act_device
enum ad9833_type act_device
Definition: ad9833.h:139
AD9834_PSEL_OUT
#define AD9834_PSEL_OUT
Definition: ad9833.h:69
AD9834_RESET_OUT
#define AD9834_RESET_OUT
Definition: ad9833.h:83
ad9833_dev::gpio_sleep
struct no_os_gpio_desc * gpio_sleep
Definition: ad9833.h:122
BIT_F0ADDRESS
#define BIT_F0ADDRESS
Definition: ad9833.h:98
ad9834_logic_output
void ad9834_logic_output(struct ad9833_dev *dev, uint8_t opbiten, uint8_t signpib, uint8_t div2)
Configures the control register for logic output. (only for AD9834 & AD9838)
Definition: ad9833.c:487
ad9833_dev::act_device
enum ad9833_type act_device
Definition: ad9833.h:124
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
AD9834_SLEEP_HIGH
#define AD9834_SLEEP_HIGH
Definition: ad9833.h:94
ad9833_dev::spi_desc
no_os_spi_desc * spi_desc
Definition: ad9833.h:117
AD9834_SLEEP_LOW
#define AD9834_SLEEP_LOW
Definition: ad9833.h:92
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:102
AD9834_CTRLPINSW
#define AD9834_CTRLPINSW
Definition: ad9833.h:59
ad9833_init_param::gpio_fsel
struct no_os_gpio_init_param gpio_fsel
Definition: ad9833.h:135
ad9833_init
int8_t ad9833_init(struct ad9833_dev **device, struct ad9833_init_param init_param)
Initialize the SPI communication with the device.
Definition: ad9833.c:87
ad9834_select_prog_method
void ad9834_select_prog_method(struct ad9833_dev *dev, uint8_t value)
Sets the programming method. (only for AD9834 & AD9838)
Definition: ad9833.c:461
AD9834_RESET_LOW
#define AD9834_RESET_LOW
Definition: ad9833.h:85
ad9833_out_mode
int8_t ad9833_out_mode(struct ad9833_dev *dev, uint8_t v_out_mode)
Selects the type of output.
Definition: ad9833.c:211
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
ad9833_init
int8_t ad9833_init(struct ad9833_dev **device, struct ad9833_init_param init_param)
Initialize the SPI communication with the device.
Definition: ad9833.c:87
ad9833_sleep_mode
void ad9833_sleep_mode(struct ad9833_dev *dev, uint8_t sleep_mode)
Enable / Disable the sleep function.
Definition: ad9833.c:280
ad9833_tx_spi
void ad9833_tx_spi(struct ad9833_dev *dev, int16_t value)
Transmits 16 bits on SPI.
Definition: ad9833.c:175
ad9833_init_param::gpio_sleep
struct no_os_gpio_init_param gpio_sleep
Definition: ad9833.h:137
ad9833_dev::test_opbiten
uint16_t test_opbiten
Definition: ad9833.h:127
AD9834_CTRLSIGNPIB
#define AD9834_CTRLSIGNPIB
Definition: ad9833.h:64
ad9833_chip_info::mclk
uint32_t mclk
Definition: ad9833.h:143
ad9833_tx_spi
void ad9833_tx_spi(struct ad9833_dev *dev, int16_t value)
Transmits 16 bits on SPI.
Definition: ad9833.c:175
ID_AD9834
@ ID_AD9834
Definition: ad9833.h:110
ad9833_type
ad9833_type
Definition: ad9833.h:108
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:96
ad9833_init_param::gpio_psel
struct no_os_gpio_init_param gpio_psel
Definition: ad9833.h:134
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
no_os_gpio.h
Header file of GPIO Interface.
ad9833_set_freq
void ad9833_set_freq(struct ad9833_dev *dev, uint8_t register_number, uint32_t frequency_value)
Loads a frequency value in a register.
Definition: ad9833.c:329
AD9833_CTRLB28
#define AD9833_CTRLB28
Definition: ad9833.h:55
BIT_P1ADDRESS
#define BIT_P1ADDRESS
Definition: ad9833.h:101
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
phase_const
float phase_const
Definition: ad9833.c:51
AD9833_CTRLDIV2
#define AD9833_CTRLDIV2
Definition: ad9833.h:65
AD9833_CTRLMODE
#define AD9833_CTRLMODE
Definition: ad9833.h:66
AD9834_PSEL_LOW
#define AD9834_PSEL_LOW
Definition: ad9833.h:71
AD9833_CTRLRESET
#define AD9833_CTRLRESET
Definition: ad9833.h:60
ID_AD9838
@ ID_AD9838
Definition: ad9833.h:112
ad9833_dev::gpio_reset
struct no_os_gpio_desc * gpio_reset
Definition: ad9833.h:121
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:112