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