clockgen4  2.0.0.0
clockgen4.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef CLOCKGEN4_H
29 #define CLOCKGEN4_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 #include "drv_spi_master.h"
49 #include "spi_specifics.h"
50 
71 #define CLOCKGEN4_REG_DEV_ID 0x01
72 #define CLOCKGEN4_REG_DEV_CTL 0x02
73 #define CLOCKGEN4_REG_DEV_CFG_1 0x03
74 #define CLOCKGEN4_REG_GLOB_CFG 0x05
75 #define CLOCKGEN4_REG_M_MSB 0x06
76 #define CLOCKGEN4_REG_L_MSB 0x07
77 #define CLOCKGEN4_REG_M_LSB 0x08
78 #define CLOCKGEN4_REG_L_LSB 0x09
79 #define CLOCKGEN4_REG_FNC_CFG_1 0x16
80 #define CLOCKGEN4_REG_FNC_CFG_2 0x17
81  // clockgen4_reg
83 
103 #define CLOCKGEN4_INCR_ENABLE 0x80
104 #define CLOCKGEN4_INCR_DISABLE 0x00
105 
110 #define CLOCKGEN4_PLL_UNLOCKED 0x00
111 #define CLOCKGEN4_PLL_LOCKED 0x80
112 #define CLOCKGEN4_AUX_OUT_EN 0x00
113 #define CLOCKGEN4_AUX_OUT_DIS 0x02
114 #define CLOCKGEN4_CLK_OUT_EN 0x00
115 #define CLOCKGEN4_CLK_OUT_DIS 0x01
116 
121 #define CLOCKGEN4_R_MOD_SEL_L_0 0x00
122 #define CLOCKGEN4_R_MOD_SEL_L_1 0x20
123 #define CLOCKGEN4_R_MOD_SEL_L_2 0x40
124 #define CLOCKGEN4_R_MOD_SEL_L_3 0x60
125 #define CLOCKGEN4_R_MOD_SEL_R_1 0x80
126 #define CLOCKGEN4_R_MOD_SEL_R_2 0xA0
127 #define CLOCKGEN4_R_MOD_SEL_R_3 0xC0
128 #define CLOCKGEN4_R_MOD_SEL_R_4 0xE0
129 #define CLOCKGEN4_REG_CLK 0x00
130 #define CLOCKGEN4_CLK_OUT 0x04
131 #define CLOCKGEN4_PLL_STAT_IND 0x06
132 #define CLOCKGEN4_DEV_CFG_1_EN 0x01
133 #define CLOCKGEN4_DEV_CFG_1_DIS 0x00
134 
139 #define CLOCKGEN4_DEV_CFG_FRZ 0x00
140 #define CLOCKGEN4_DEV_CFG_UNFRZ 0x08
141 #define CLOCKGEN4_DEV_CFG_2_EN 0x01
142 #define CLOCKGEN4_DEV_CFG_2_DIS 0x00
143 
148 #define CLOCKGEN4_AUX_OUT_ACT_H 0x00
149 #define CLOCKGEN4_AUX_OUT_ACT_L 0x40
150 #define CLOCKGEN4_REF_CLK_DIV_4 0x00
151 #define CLOCKGEN4_REF_CLK_DIV_2 0x08
152 #define CLOCKGEN4_REF_CLK_DIV_1 0x10
153 
158 #define CLOCKGEN4_CLK_OUT_UNL_L 0x00
159 #define CLOCKGEN4_CLK_OUT_UNL_U 0x10
160 
165 #define CLOCKGEN4_REF_CLK_25_MHZ 25.0
166 
172 #define CLOCKGEN4_I2C_ADR_GND 0x4E
173 #define CLOCKGEN4_I2C_ADR_VCC 0x4F
174 
175 #define CLOCKGEN4_SPI_CHIP_ADR 0x9E
176 
184 #define CLOCKGEN4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
185 #define CLOCKGEN4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
186  // clockgen4_set
187 
202 #define CLOCKGEN4_MAP_MIKROBUS( cfg, mikrobus ) \
203  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
204  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
205  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
206  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
207  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
208  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
209 
210  // clockgen4_map // clockgen4
212 
217 typedef enum
218 {
223 
228 typedef err_t ( *clockgen4_master_io_t )( struct clockgen4_s*, uint8_t, uint8_t*, uint8_t );
234 typedef struct clockgen4_s
235 {
236  i2c_master_t i2c;
237  spi_master_t spi;
239  uint8_t slave_address;
240  pin_name_t chip_select;
247 
252 typedef struct
253 {
254  pin_name_t scl;
255  pin_name_t sda;
256  pin_name_t miso;
257  pin_name_t mosi;
258  pin_name_t sck;
259  pin_name_t cs;
261  uint32_t i2c_speed;
262  uint8_t i2c_address;
264  uint32_t spi_speed;
265  spi_master_mode_t spi_mode;
266  spi_master_chip_select_polarity_t cs_polarity;
271 
276 typedef enum
277 {
279  CLOCKGEN4_ERROR = -1
280 
282 
299 
315 
331 
346 
362 err_t clockgen4_generic_write ( clockgen4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
363 
379 err_t clockgen4_generic_read ( clockgen4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
380 
391 void clockgen4_dev_ctl ( clockgen4_t *ctx, uint8_t dev_ctl );
392 
404 void clockgen4_dev_cfg ( clockgen4_t *ctx, uint8_t dev_cfg );
405 
417 void clockgen4_glob_cfg ( clockgen4_t *ctx, uint8_t glob_cfg );
418 
430 void clockgen4_fnc_cfg_1 ( clockgen4_t *ctx, uint8_t fnc_cfg );
431 
442 void clockgen4_fnc_cfg_2 ( clockgen4_t *ctx, uint8_t fnc_cfg );
443 
456 uint32_t clockgen4_set_ratio ( clockgen4_t *ctx, float ratio );
457 
458 
459 #ifdef __cplusplus
460 }
461 #endif
462 #endif // CLOCKGEN4_H
463  // clockgen4
465 
466 // ------------------------------------------------------------------------ END
clockgen4_s::slave_address
uint8_t slave_address
Definition: clockgen4.h:239
clockgen4_fnc_cfg_1
void clockgen4_fnc_cfg_1(clockgen4_t *ctx, uint8_t fnc_cfg)
Clock Gen 4 configuration 1 function.
clockgen4_set_ratio
uint32_t clockgen4_set_ratio(clockgen4_t *ctx, float ratio)
Clock Gen 4 set ratio function.
clockgen4_cfg_setup
void clockgen4_cfg_setup(clockgen4_cfg_t *cfg)
Clock Gen 4 configuration object setup function.
clockgen4_s
Clock Gen 4 Click context object.
Definition: clockgen4.h:235
spi_specifics.h
This file contains SPI specific macros, functions, etc.
CLOCKGEN4_DRV_SEL_SPI
@ CLOCKGEN4_DRV_SEL_SPI
Definition: clockgen4.h:219
clockgen4_cfg_t::scl
pin_name_t scl
Definition: clockgen4.h:254
clockgen4_drv_interface_selection
void clockgen4_drv_interface_selection(clockgen4_cfg_t *cfg, clockgen4_drv_t drv_sel)
Clock Gen 4 driver interface setup function.
clockgen4_drv_t
clockgen4_drv_t
Clock Gen 4 Click driver selector.
Definition: clockgen4.h:218
clockgen4_cfg_t::drv_sel
clockgen4_drv_t drv_sel
Definition: clockgen4.h:268
clockgen4_s::spi
spi_master_t spi
Definition: clockgen4.h:237
clockgen4_cfg_t::mosi
pin_name_t mosi
Definition: clockgen4.h:257
clockgen4_dev_ctl
void clockgen4_dev_ctl(clockgen4_t *ctx, uint8_t dev_ctl)
Clock Gen 4 device control function.
clockgen4_s::read_f
clockgen4_master_io_t read_f
Definition: clockgen4.h:244
clockgen4_s::i2c
i2c_master_t i2c
Definition: clockgen4.h:236
clockgen4_t
struct clockgen4_s clockgen4_t
Clock Gen 4 Click context object.
clockgen4_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: clockgen4.h:265
clockgen4_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: clockgen4.h:266
clockgen4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: clockgen4.h:261
clockgen4_s::chip_select
pin_name_t chip_select
Definition: clockgen4.h:240
clockgen4_cfg_t::cs
pin_name_t cs
Definition: clockgen4.h:259
clockgen4_init
err_t clockgen4_init(clockgen4_t *ctx, clockgen4_cfg_t *cfg)
Clock Gen 4 initialization function.
clockgen4_cfg_t::i2c_address
uint8_t i2c_address
Definition: clockgen4.h:262
clockgen4_return_value_t
clockgen4_return_value_t
Clock Gen 4 Click return value data.
Definition: clockgen4.h:277
clockgen4_cfg_t::sda
pin_name_t sda
Definition: clockgen4.h:255
CLOCKGEN4_OK
@ CLOCKGEN4_OK
Definition: clockgen4.h:278
CLOCKGEN4_DRV_SEL_I2C
@ CLOCKGEN4_DRV_SEL_I2C
Definition: clockgen4.h:220
clockgen4_glob_cfg
void clockgen4_glob_cfg(clockgen4_t *ctx, uint8_t glob_cfg)
Clock Gen 4 global configuration function.
clockgen4_generic_read
err_t clockgen4_generic_read(clockgen4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Clock Gen 4 data reading function.
clockgen4_dev_cfg
void clockgen4_dev_cfg(clockgen4_t *ctx, uint8_t dev_cfg)
Clock Gen 4 device configuration function.
clockgen4_cfg_t::sck
pin_name_t sck
Definition: clockgen4.h:258
clockgen4_s::write_f
clockgen4_master_io_t write_f
Definition: clockgen4.h:243
clockgen4_cfg_t::spi_speed
uint32_t spi_speed
Definition: clockgen4.h:264
CLOCKGEN4_ERROR
@ CLOCKGEN4_ERROR
Definition: clockgen4.h:279
clockgen4_cfg_t::miso
pin_name_t miso
Definition: clockgen4.h:256
clockgen4_master_io_t
err_t(* clockgen4_master_io_t)(struct clockgen4_s *, uint8_t, uint8_t *, uint8_t)
Clock Gen 4 Click driver interface.
Definition: clockgen4.h:228
clockgen4_generic_write
err_t clockgen4_generic_write(clockgen4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Clock Gen 4 data writing function.
clockgen4_s::drv_sel
clockgen4_drv_t drv_sel
Definition: clockgen4.h:241
clockgen4_cfg_t
Clock Gen 4 Click configuration object.
Definition: clockgen4.h:253
clockgen4_default_cfg
err_t clockgen4_default_cfg(clockgen4_t *ctx)
Clock Gen 4 default configuration function.
clockgen4_fnc_cfg_2
void clockgen4_fnc_cfg_2(clockgen4_t *ctx, uint8_t fnc_cfg)
Clock Gen 4 configuration 2 function.