HPM SDK
HPMicro Software Development Kit
hpm_pllctlv2_drv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-2024 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_PLLCTLV2_DRV_H
9 #define HPM_PLLCTLV2_DRV_H
10 
11 
12 #include "hpm_common.h"
13 #include "hpm_soc_feature.h"
14 #include "hpm_pllctlv2_regs.h"
15 
16 #define PLLCTLV2_CLK_SRC_XTAL24M (0U)
17 #define PLLCTLV2_CLK_SRC_IRC24M (1U)
18 
30 static inline bool pllctlv2_xtal_is_stable(PLLCTLV2_Type *ptr)
31 {
33 }
34 
40 static inline bool pllctlv2_xtal_is_enabled(PLLCTLV2_Type *ptr)
41 {
43 }
44 
50 static inline void pllctlv2_xtal_set_rampup_time(PLLCTLV2_Type *ptr, uint32_t rc24m_cycles)
51 {
52  ptr->XTAL = (ptr->XTAL & ~PLLCTLV2_XTAL_RAMP_TIME_MASK) | PLLCTLV2_XTAL_RAMP_TIME_SET(rc24m_cycles);
53 }
54 
61 static inline bool pllctlv2_pll_is_stable(PLLCTLV2_Type *ptr, uint8_t pll)
62 {
64 }
65 
72 static inline bool pllctlv2_pll_is_enabled(PLLCTLV2_Type *ptr, uint8_t pll)
73 {
75 }
76 
85 static inline void pllctlv2_select_reference_clock(PLLCTLV2_Type *ptr, uint8_t pll, uint8_t src)
86 {
88 }
89 
97 void pllctlv2_enable_spread_spectrum(PLLCTLV2_Type *ptr, uint8_t pll, uint32_t step, uint32_t stop);
98 
104 static inline void pllctlv2_disable_spread_spectrum(PLLCTLV2_Type *ptr, uint8_t pll)
105 {
107 }
108 
115 static inline void pllctlv2_set_pll_lock_time(PLLCTLV2_Type *ptr, uint8_t pll, uint32_t xtal_cycles)
116 {
117  ptr->PLL[pll].LOCKTIME = PLLCTLV2_PLL_LOCKTIME_LOCKTIME_SET(xtal_cycles);
118 }
119 
126 static inline void pllctlv2_set_pll_step_time(PLLCTLV2_Type *ptr, uint8_t pll, uint32_t xtal_cycles)
127 {
128  ptr->PLL[pll].STEPTIME = PLLCTLV2_PLL_STEPTIME_STEPTIME_SET(xtal_cycles);
129 }
130 
138 void pllctlv2_set_postdiv(PLLCTLV2_Type *ptr, uint8_t pll, uint8_t div_index, uint8_t div_value);
139 
150 hpm_stat_t pllctlv2_set_pll_with_mfi_mfn(PLLCTLV2_Type *ptr, uint8_t pll, uint32_t mfi, uint32_t mfn);
151 
161 hpm_stat_t pllctlv2_init_pll_with_freq(PLLCTLV2_Type *ptr, uint8_t pll, uint32_t freq_in_hz);
162 
169 uint32_t pllctlv2_get_pll_freq_in_hz(PLLCTLV2_Type *ptr, uint8_t pll);
170 
178 uint32_t pllctlv2_get_pll_postdiv_freq_in_hz(PLLCTLV2_Type *ptr, uint8_t pll, uint8_t div_index);
179 
180 
184 #endif /* HPM_PLLCTLV2_DRV_H */
#define PLLCTLV2_XTAL_RESPONSE_MASK
Definition: hpm_pllctlv2_regs.h:51
#define PLLCTLV2_PLL_CONFIG_REFSEL_MASK
Definition: hpm_pllctlv2_regs.h:194
#define PLLCTLV2_PLL_MFI_ENABLE_MASK
Definition: hpm_pllctlv2_regs.h:110
#define PLLCTLV2_PLL_CONFIG_SPREAD_MASK
Definition: hpm_pllctlv2_regs.h:182
#define PLLCTLV2_PLL_MFI_RESPONSE_MASK
Definition: hpm_pllctlv2_regs.h:99
#define PLLCTLV2_PLL_STEPTIME_STEPTIME_SET(x)
Definition: hpm_pllctlv2_regs.h:218
#define PLLCTLV2_PLL_LOCKTIME_LOCKTIME_SET(x)
Definition: hpm_pllctlv2_regs.h:207
#define PLLCTLV2_XTAL_RAMP_TIME_MASK
Definition: hpm_pllctlv2_regs.h:75
#define PLLCTLV2_XTAL_RAMP_TIME_SET(x)
Definition: hpm_pllctlv2_regs.h:77
#define PLLCTLV2_XTAL_ENABLE_MASK
Definition: hpm_pllctlv2_regs.h:62
#define PLLCTLV2_PLL_CONFIG_REFSEL_SET(x)
Definition: hpm_pllctlv2_regs.h:196
uint32_t hpm_stat_t
Definition: hpm_common.h:123
#define IS_HPM_BITMASK_SET(val, mask)
Definition: hpm_common.h:61
uint32_t pllctlv2_get_pll_postdiv_freq_in_hz(PLLCTLV2_Type *ptr, uint8_t pll, uint8_t div_index)
Get the selected PLL post divider frequency.
Definition: hpm_pllctlv2_drv.c:103
static bool pllctlv2_xtal_is_enabled(PLLCTLV2_Type *ptr)
Check if external crystal is enabled.
Definition: hpm_pllctlv2_drv.h:40
static bool pllctlv2_pll_is_stable(PLLCTLV2_Type *ptr, uint8_t pll)
Check is PLL is stable.
Definition: hpm_pllctlv2_drv.h:61
uint32_t pllctlv2_get_pll_freq_in_hz(PLLCTLV2_Type *ptr, uint8_t pll)
Get the specified PLl clock frequency.
Definition: hpm_pllctlv2_drv.c:91
static bool pllctlv2_xtal_is_stable(PLLCTLV2_Type *ptr)
Check if external crystal is stable.
Definition: hpm_pllctlv2_drv.h:30
static void pllctlv2_set_pll_step_time(PLLCTLV2_Type *ptr, uint8_t pll, uint32_t xtal_cycles)
Set PLL step time.
Definition: hpm_pllctlv2_drv.h:126
hpm_stat_t pllctlv2_set_pll_with_mfi_mfn(PLLCTLV2_Type *ptr, uint8_t pll, uint32_t mfi, uint32_t mfn)
Set the PLL via the low-level MFI, MFD and MFN PLL frequency = REF CLOCK * (mfi + 1....
Definition: hpm_pllctlv2_drv.c:21
static void pllctlv2_disable_spread_spectrum(PLLCTLV2_Type *ptr, uint8_t pll)
Disable PLL Spread spectrum.
Definition: hpm_pllctlv2_drv.h:104
void pllctlv2_enable_spread_spectrum(PLLCTLV2_Type *ptr, uint8_t pll, uint32_t step, uint32_t stop)
Enable PLL Spread Spectrum feature.
Definition: hpm_pllctlv2_drv.c:64
static void pllctlv2_set_pll_lock_time(PLLCTLV2_Type *ptr, uint8_t pll, uint32_t xtal_cycles)
Set PLL lock time.
Definition: hpm_pllctlv2_drv.h:115
hpm_stat_t pllctlv2_init_pll_with_freq(PLLCTLV2_Type *ptr, uint8_t pll, uint32_t freq_in_hz)
Initialize PLL to specified frequency Note: the specified PLL clock needs to be enabled before being ...
Definition: hpm_pllctlv2_drv.c:39
static bool pllctlv2_pll_is_enabled(PLLCTLV2_Type *ptr, uint8_t pll)
Check if PLL is enabled.
Definition: hpm_pllctlv2_drv.h:72
static void pllctlv2_xtal_set_rampup_time(PLLCTLV2_Type *ptr, uint32_t rc24m_cycles)
Set external crystal ramp-up time.
Definition: hpm_pllctlv2_drv.h:50
static void pllctlv2_select_reference_clock(PLLCTLV2_Type *ptr, uint8_t pll, uint8_t src)
Select the PLL reference clock.
Definition: hpm_pllctlv2_drv.h:85
void pllctlv2_set_postdiv(PLLCTLV2_Type *ptr, uint8_t pll, uint8_t div_index, uint8_t div_value)
Set PLL Post divider.
Definition: hpm_pllctlv2_drv.c:82
Definition: hpm_pllctlv2_regs.h:12
__RW uint32_t CONFIG
Definition: hpm_pllctlv2_regs.h:21
struct PLLCTLV2_Type::@316 PLL[2]
__RW uint32_t XTAL
Definition: hpm_pllctlv2_regs.h:13
__RW uint32_t STEPTIME
Definition: hpm_pllctlv2_regs.h:23
__RW uint32_t MFI
Definition: hpm_pllctlv2_regs.h:16
__RW uint32_t LOCKTIME
Definition: hpm_pllctlv2_regs.h:22