1 /***************************************************************************//**
2  * @file
3  * @brief Clock Manager HAL APIs.
4  *******************************************************************************
5  * # License
6  * <b>Copyright 2023 Silicon Laboratories Inc. www.silabs.com</b>
7  *******************************************************************************
8  *
9  * SPDX-License-Identifier: Zlib
10  *
11  * The licensor of this software is Silicon Laboratories Inc.
12  *
13  * This software is provided 'as-is', without any express or implied
14  * warranty. In no event will the authors be held liable for any damages
15  * arising from the use of this software.
16  *
17  * Permission is granted to anyone to use this software for any purpose,
18  * including commercial applications, and to alter it and redistribute it
19  * freely, subject to the following restrictions:
20  *
21  * 1. The origin of this software must not be misrepresented; you must not
22  *    claim that you wrote the original software. If you use this software
23  *    in a product, an acknowledgment in the product documentation would be
24  *    appreciated but is not required.
25  * 2. Altered source versions must be plainly marked as such, and must not be
26  *    misrepresented as being the original software.
27  * 3. This notice may not be removed or altered from any source distribution.
28  *
29  ******************************************************************************/
30 
31 #ifndef SL_CLOCK_MANAGER_HAL_H
32 #define SL_CLOCK_MANAGER_HAL_H
33 
34 #include "sl_clock_manager.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /***************************************************************************//**
41  * Performs Clock Manager runtime initialization.
42  ******************************************************************************/
43 sl_status_t sli_clock_manager_hal_runtime_init(void);
44 
45 /***************************************************************************//**
46  * Gets frequency of given oscillator.
47  ******************************************************************************/
48 SL_CODE_CLASSIFY(SL_CODE_COMPONENT_CLOCK_MANAGER, SL_CODE_CLASS_TIME_CRITICAL)
49 sl_status_t sli_clock_manager_hal_get_oscillator_frequency(sl_oscillator_t oscillator,
50                                                            uint32_t        *frequency);
51 
52 /***************************************************************************//**
53  * Gets precision of given oscillator.
54  ******************************************************************************/
55 sl_status_t sli_clock_manager_hal_get_oscillator_precision(sl_oscillator_t oscillator,
56                                                            uint16_t        *precision);
57 
58 /***************************************************************************//**
59  * Gets frequency of given clock branch.
60  ******************************************************************************/
61 SL_CODE_CLASSIFY(SL_CODE_COMPONENT_CLOCK_MANAGER, SL_CODE_CLASS_TIME_CRITICAL)
62 sl_status_t sli_clock_manager_hal_get_clock_branch_frequency(sl_clock_branch_t clock_branch,
63                                                              uint32_t          *frequency);
64 
65 /***************************************************************************//**
66  * Gets precision of given clock branch.
67  ******************************************************************************/
68 sl_status_t sli_clock_manager_hal_get_clock_branch_precision(sl_clock_branch_t clock_branch,
69                                                              uint16_t          *precision);
70 
71 /***************************************************************************//**
72  * Enables/Disables the bus clock associated with the given module.
73  ******************************************************************************/
74 sl_status_t sli_clock_manager_hal_enable_bus_clock(sl_bus_clock_t module,
75                                                    bool enable);
76 
77 /***************************************************************************//**
78  * Configures the exported clock feature on CMU to output user selected
79  * clock source specified GPIO pin.
80  ******************************************************************************/
81 sl_status_t sli_clock_manager_hal_set_gpio_clock_output(sl_clock_manager_export_clock_source_t export_clock_source,
82                                                         sl_clock_manager_export_clock_output_select_t output_select,
83                                                         uint16_t divider,
84                                                         uint32_t port,
85                                                         uint32_t pin);
86 
87 /***************************************************************************//**
88  * Sets the RC oscillator frequency tuning control.
89  ******************************************************************************/
90 sl_status_t sli_clock_manager_hal_set_rc_oscillator_calibration(sl_oscillator_t oscillator,
91                                                                 uint32_t val);
92 
93 /***************************************************************************//**
94  * Gets the RC oscillator frequency tuning setting.
95  ******************************************************************************/
96 sl_status_t sli_clock_manager_hal_get_rc_oscillator_calibration(sl_oscillator_t oscillator,
97                                                                 uint32_t *val);
98 
99 /***************************************************************************//**
100  * Sets the HFXO calibration value.
101  ******************************************************************************/
102 sl_status_t sli_clock_manager_hal_set_hfxo_calibration(uint32_t val);
103 
104 /***************************************************************************//**
105  * Gets the HFXO calibration value.
106  ******************************************************************************/
107 sl_status_t sli_clock_manager_hal_get_hfxo_calibration(uint32_t *val);
108 
109 /***************************************************************************//**
110  * Sets the HFXO CTUNE setting.
111  ******************************************************************************/
112 sl_status_t sli_clock_manager_hal_hfxo_set_ctune(uint32_t ctune);
113 
114 /***************************************************************************//**
115  * Gets the HFXO CTUNE setting.
116  ******************************************************************************/
117 sl_status_t sli_clock_manager_hal_hfxo_get_ctune(uint32_t *ctune);
118 
119 /***************************************************************************//**
120  * Updates the tuning capacitances and calibrate the Core Bias Current.
121  ******************************************************************************/
122 sl_status_t sli_clock_manager_hal_hfxo_calibrate_ctune(uint32_t ctune);
123 
124 /***************************************************************************//**
125  * Sets the LFXO frequency tuning control.
126  ******************************************************************************/
127 sl_status_t sli_clock_manager_hal_set_lfxo_calibration(uint32_t val);
128 
129 /***************************************************************************//**
130  * Gets the LFXO frequency tuning setting.
131  ******************************************************************************/
132 sl_status_t sli_clock_manager_hal_get_lfxo_calibration(uint32_t *val);
133 
134 /***************************************************************************//**
135  * Configures the RCO calibration.
136  *****************************************************************************/
137 sl_status_t sli_clock_manager_hal_configure_rco_calibration(uint32_t cycles,
138                                                             sl_clock_manager_clock_calibration_t down_counter_selection,
139                                                             sl_clock_manager_clock_calibration_t up_counter_selection,
140                                                             bool continuous_calibration);
141 
142 /***************************************************************************//**
143  * Starts the RCO calibration.
144  ******************************************************************************/
145 void sli_clock_manager_hal_start_rco_calibration (void);
146 
147 /***************************************************************************//**
148  * Stops the RCO calibration.
149  ******************************************************************************/
150 void sli_clock_manager_hal_stop_rco_calibration(void);
151 
152 /***************************************************************************//**
153  * Waits for the RCO calibration to finish.
154  ******************************************************************************/
155 void sli_clock_manager_hal_wait_rco_calibration(void);
156 
157 /***************************************************************************//**
158  * Gets calibration count value.
159  ******************************************************************************/
160 sl_status_t sli_clock_manager_hal_get_rco_calibration_count(uint32_t *count);
161 
162 /***************************************************************************//**
163  * Sets SYSCLK clock source.
164  ******************************************************************************/
165 sl_status_t sli_clock_manager_hal_set_sysclk_source(sl_oscillator_t source);
166 
167 /***************************************************************************//**
168  * Gets SYSCLK clock source.
169  ******************************************************************************/
170 sl_status_t sli_clock_manager_hal_get_sysclk_source(sl_oscillator_t *source);
171 
172 /***************************************************************************//**
173  * Waits for USBPLL clock to be ready.
174  ******************************************************************************/
175 sl_status_t sli_clock_manager_hal_wait_usbpll(void);
176 
177 /***************************************************************************//**
178  * Updates QSPI clock and reference clock.
179  *
180  * @note This API is not thread-safe and should therefore not be called
181          across multiple tasks.
182  ******************************************************************************/
183 SL_CODE_CLASSIFY(SL_CODE_COMPONENT_CLOCK_MANAGER, SL_CODE_CLASS_TIME_CRITICAL)
184 sl_status_t sli_clock_manager_hal_update_qspi_clk(sl_oscillator_t oscillator);
185 
186 /***************************************************************************//**
187  * Gets QSPI clock source.
188  ******************************************************************************/
189 SL_CODE_CLASSIFY(SL_CODE_COMPONENT_CLOCK_MANAGER, SL_CODE_CLASS_TIME_CRITICAL)
190 sl_status_t sli_clock_manager_get_current_qspi_clk(sl_oscillator_t *oscillator);
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 
196 #endif // SL_CLOCK_MANAGER_HAL_H
197