5 #include "stm32/stm32f4xx_misc.h"
9 #define EXTCLK_DIR_UP 0
10 #define EXTCLK_DIR_DOWN 1
12 #define CS_DEVICE_ID 0x01
13 #define CS_DEVICE_CTRL 0x02
14 #define CS_DEVICE_CFG1 0x03
15 #define CS_GLOBAL_CFG 0x05
16 #define CS_RATIO_3 0x06
17 #define CS_RATIO_2 0x07
18 #define CS_RATIO_1 0x08
19 #define CS_RATIO_0 0x09
20 #define CS_FUNCT_CFG1 0x16
21 #define CS_FUNCT_CFG2 0x17
23 static status_e clk_gen_WriteReg(
struct clock_gen_t *dev, uint8_t reg, uint8_t Value)
26 const uint8_t cmd [] =
53 static uint32_t ratio_compute(
const struct _clk_gen_info_t *g)
66 status_e clock_gen_init(
struct clock_gen_t *dev, uint32_t OutFreq, uint32_t InFreq)
71 dev->info.f_in = InFreq;
72 dev->info.f_out = OutFreq;
82 ratio = ratio_compute(&dev->info);
85 status = clk_gen_WriteReg(dev, CS_GLOBAL_CFG, 0x08);
92 status = clk_gen_WriteReg(dev, CS_DEVICE_CTRL, 0x02);
99 status = clk_gen_WriteReg(dev, CS_DEVICE_CFG1, 0x00);
105 status = clk_gen_WriteReg(dev, CS_RATIO_3, (uint8_t) (((ratio & 0xFF000000) >> 24)));
111 status = clk_gen_WriteReg(dev, CS_RATIO_2, (uint8_t) (((ratio & 0xFF0000) >> 16)));
117 status = clk_gen_WriteReg(dev, CS_RATIO_1, (uint8_t) (((ratio & 0xFF00) >> 8)));
123 status = clk_gen_WriteReg(dev, CS_RATIO_0, (uint8_t) (ratio & 0xFF));
130 status = clk_gen_WriteReg(dev, CS_FUNCT_CFG1, 0x08);
137 status = clk_gen_WriteReg(dev, CS_GLOBAL_CFG, 0x01);
146 status_e clock_gen_adjust_ppm(
struct clock_gen_t *dev, int32_t ppm)
152 old_ratio = ratio_compute(&dev->info);
153 dev->info.ppm += ppm;
154 ratio = ratio_compute(&dev->info);
156 if (old_ratio == ratio)
163 status = clk_gen_WriteReg(dev, CS_GLOBAL_CFG, 0x09);
170 status = clk_gen_WriteReg(dev, CS_RATIO_3, (uint8_t) (((ratio & 0xFF000000) >> 24)));
176 status = clk_gen_WriteReg(dev, CS_RATIO_2, (uint8_t) (((ratio & 0xFF0000) >> 16)));
182 status = clk_gen_WriteReg(dev, CS_RATIO_1, (uint8_t) (((ratio & 0xFF00) >> 8)));
188 status = clk_gen_WriteReg(dev, CS_RATIO_0, (uint8_t) (ratio & 0xFF));
195 status = clk_gen_WriteReg(dev, CS_GLOBAL_CFG, 0x01);
This file contains all the functions prototypes for the RCC firmware library.
This file contains all the functions prototypes for the GPIO firmware library.
status_e bus_release(const struct heivs_bus_t *bus)
Release exclusive access to the bus.
status_e bus_write(const struct heivs_bus_t *bus, uint32_t address, const void *data, size_t len)
Write data to the bus.
This file contains all the functions prototypes for the I2C firmware library.
status_e bus_init(const struct heivs_bus_t *bus)
initialize the bus
status_e bus_get(const struct heivs_bus_t *bus)
Get exclusive access to the bus.
#define ARRAY_SIZE(x)
Number of elements in the array.