1 /***************************************************************************//**
2  * @file
3  * @brief SLEEPTIMER SDK internal APIs.
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_SLEEPTIMER_H
32 #define SLI_SLEEPTIMER_H
33 
34 #include <stdint.h>
35 #include <stddef.h>
36 #include <stdbool.h>
37 #include "em_device.h"
38 #include "sl_sleeptimer_config.h"
39 
40 #define SLEEPTIMER_EVENT_OF (0x01)
41 #define SLEEPTIMER_EVENT_COMP (0x02)
42 
43 #define SLI_SLEEPTIMER_POWER_MANAGER_EARLY_WAKEUP_TIMER_FLAG 0x02
44 #define SLI_SLEEPTIMER_POWER_MANAGER_HF_ACCURACY_CLK_FLAG 0x04
45 
46 #if SL_SLEEPTIMER_PERIPHERAL == SL_SLEEPTIMER_PERIPHERAL_DEFAULT
47 #if defined(RTCC_PRESENT) && RTCC_COUNT >= 1
48 #undef SL_SLEEPTIMER_PERIPHERAL
49 #define SL_SLEEPTIMER_PERIPHERAL SL_SLEEPTIMER_PERIPHERAL_RTCC
50 #elif defined(RTC_PRESENT) && RTC_COUNT >= 1
51 #undef SL_SLEEPTIMER_PERIPHERAL
52 #define SL_SLEEPTIMER_PERIPHERAL SL_SLEEPTIMER_PERIPHERAL_RTC
53 #elif defined(SYSRTC_PRESENT) && SYSRTC_COUNT >= 1
54 #undef SL_SLEEPTIMER_PERIPHERAL
55 #define SL_SLEEPTIMER_PERIPHERAL SL_SLEEPTIMER_PERIPHERAL_SYSRTC
56 #elif defined(BURTC_PRESENT) && BURTC_COUNT >= 1
57 #undef SL_SLEEPTIMER_PERIPHERAL
58 #define SL_SLEEPTIMER_PERIPHERAL SL_SLEEPTIMER_PERIPHERAL_BURTC
59 #elif defined(WTIMER_PRESENT) && WTIMER_COUNT >= 1
60 #undef SL_SLEEPTIMER_PERIPHERAL
61 #define SL_SLEEPTIMER_PERIPHERAL SL_SLEEPTIMER_PERIPHERAL_WTIMER
62 #elif defined(TIMER_PRESENT) && TIMER_COUNT >= 1
63 #undef SL_SLEEPTIMER_PERIPHERAL
64 #define SL_SLEEPTIMER_PERIPHERAL SL_SLEEPTIMER_PERIPHERAL_TIMER
65 #endif
66 #endif
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
72 /*******************************************************************************
73  * Hardware Abstraction Layer to perform initialization related to Power Manager.
74  ******************************************************************************/
75 __WEAK void sli_sleeptimer_hal_power_manager_integration_init(void);
76 
77 /*******************************************************************************
78  * Hardware Abstraction Layer to perform initialization related to HFXO Manager.
79  ******************************************************************************/
80 __WEAK void sli_sleeptimer_hal_hfxo_manager_integration_init(void);
81 
82 /*******************************************************************************
83  * Hardware Abstraction Layer to get interrupt status.
84  *
85  * @param local_flag Internal interrupt flag.
86  *
87  * @return Boolean indicating if specified interrupt is set.
88  ******************************************************************************/
89 bool sli_sleeptimer_hal_is_int_status_set(uint8_t local_flag);
90 
91 /**************************************************************************//**
92  * Determines if next timer to expire has the option flag
93  * "SLI_SLEEPTIMER_POWER_MANAGER_EARLY_WAKEUP_TIMER_FLAG".
94  *
95  * @return true if power manager will expire at next compare match,
96  *         false otherwise.
97  *****************************************************************************/
98 bool sli_sleeptimer_is_power_manager_timer_next_to_expire(void);
99 
100 /***************************************************************************//**
101  * Set lowest energy mode based on a project's configurations and clock source
102  *
103  * @note If power_manager_no_deepsleep component is included in a project, the
104  *       lowest possible energy mode is EM1, else lowest energy mode is
105  *       determined by clock source.
106  ******************************************************************************/
107 #if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
108 void sli_sleeptimer_set_pm_em_requirement(void);
109 #endif
110 
111 /***************************************************************************//**
112  * @brief
113  *   Update sleep_on_isr_exit flag.
114  *
115  * @param flag Boolean value update_sleep_on_isr_exit will be set to.
116  ******************************************************************************/
117 void sli_sleeptimer_update_sleep_on_isr_exit(bool flag);
118 
119 /*******************************************************************************
120  * Gets the associated peripheral capture channel current value.
121  *
122  * @return Capture value
123  *         0 if capture channel is not valid
124  ******************************************************************************/
125 uint32_t sli_sleeptimer_get_capture(void);
126 
127 /*******************************************************************************
128  * Resets the PRS signal triggered by the associated peripheral.
129  ******************************************************************************/
130 void sli_sleeptimer_reset_prs_signal(void);
131 
132 #ifdef __cplusplus
133 }
134 #endif
135 
136 #endif /* SLI_SLEEPTIMER_H */
137