1 /***************************************************************************//**
2  * @file
3  * @brief HFXO Manager API definition.
4  *******************************************************************************
5  * # License
6  * <b>Copyright 2019 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 SLI_HFXO_MANAGER_H
32 #define SLI_HFXO_MANAGER_H
33 
34 #include <stdbool.h>
35 #if defined(SL_COMPONENT_CATALOG_PRESENT)
36 #include "sl_component_catalog.h"
37 #endif
38 
39 #if defined(SL_CATALOG_SLEEPTIMER_PRESENT) && defined(SYSRTC_PRESENT)
40 #include "sli_sleeptimer.h"
41 #if (SL_SLEEPTIMER_PERIPHERAL == SL_SLEEPTIMER_PERIPHERAL_SYSRTC)
42 #define HFXO_MANAGER_SLEEPTIMER_SYSRTC_INTEGRATION_ON
43 #endif
44 #endif
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 /***************************************************************************//**
51  * HFXO Manager module hardware specific initialization.
52  ******************************************************************************/
53 void sli_hfxo_manager_init_hardware(void);
54 
55 /***************************************************************************//**
56  * Function to call just before starting HFXO, to save current tick count.
57  ******************************************************************************/
58 void sli_hfxo_manager_begin_startup_measurement(void);
59 
60 #if defined(HFXO_MANAGER_SLEEPTIMER_SYSRTC_INTEGRATION_ON)
61 /***************************************************************************//**
62  * Function to call when a SYSRTC compare match event produces a PRS signal to
63    start HFXO.
64  ******************************************************************************/
65 void sli_hfxo_manager_retrieve_begining_startup_measurement(void);
66 #endif
67 
68 /***************************************************************************//**
69  * Function to call just after HFXO becomes ready, to save current tick count
70  * and calculate HFXO startup time.
71  ******************************************************************************/
72 void sli_hfxo_manager_end_startup_measurement(void);
73 
74 /***************************************************************************//**
75  * Retrieves HFXO startup time average value.
76  ******************************************************************************/
77 uint32_t sli_hfxo_manager_get_startup_time(void);
78 
79 /***************************************************************************//**
80  * Retrieves HFXO startup time latest value.
81  ******************************************************************************/
82 uint32_t sli_hfxo_manager_get_latest_startup_time(void);
83 
84 /***************************************************************************//**
85  * Checks if HFXO is ready and, if needed, waits for it to be.
86  *
87  * @param  wait  True, to wait for HFXO to be ready.
88  *               False, otherwise.
89  *
90  * @return True, if HFXO is ready.
91  *         False, otherwise.
92  *
93  * @note This will also make sure we are not in the process of restarting HFXO
94  *       with different settings.
95  ******************************************************************************/
96 bool sli_hfxo_manager_is_hfxo_ready(bool wait);
97 
98 #ifdef __cplusplus
99 }
100 #endif
101 
102 #endif /* SLI_HFXO_MANAGER_H */
103