1 /***************************************************************************//**
2  * @file
3  * @brief Power Manager execution modes HAL API implementation.
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 #include "em_device.h"
32 #include "sl_power_manager_config.h"
33 #if defined(SL_POWER_MANAGER_EXECUTION_MODES_FEATURE_EN) && (SL_POWER_MANAGER_EXECUTION_MODES_FEATURE_EN == 1)
34 #include "sl_power_manager.h"
35 #include "sli_power_manager_execution_modes_private.h"
36 #include "sli_clock_manager.h"
37 #include "sl_assert.h"
38 
39 /*******************************************************************************
40  *******************************  DEFINES   ************************************
41  ******************************************************************************/
42 
43 // The execution modes feature on SIXG301 changes the SYSCLK clock source.
44 // For SIXG301 devices, those clock sources are prefined to the below values.
45 #define EXECUTION_MODE_STANDARD_CLOCK_SOURCE     SL_OSCILLATOR_HFRCODPLL
46 #define EXECUTION_MODE_PERFORMANCE_CLOCK_SOURCE  SL_OSCILLATOR_SOCPLL
47 
48 /*******************************************************************************
49  **************************   GLOBAL FUNCTIONS   *******************************
50  ******************************************************************************/
51 
52 /***************************************************************************//**
53  * Initialize execution modes with original mode as standard mode.
54  ******************************************************************************/
sli_power_manager_executions_modes_hal_init(void)55 void sli_power_manager_executions_modes_hal_init(void)
56 {
57   sli_power_manager_hal_apply_standard_mode();
58 }
59 
60 /***************************************************************************//**
61  * Updates SYSCLK to achieve performance mode execution.
62  ******************************************************************************/
sli_power_manager_hal_apply_performance_mode(void)63 void sli_power_manager_hal_apply_performance_mode(void)
64 {
65   if ((HFXO0->STATUS & _HFXO_STATUS_RDY_MASK) == 0) {
66     // Force-enable HFXO.
67     HFXO0->CTRL_SET = HFXO_CTRL_FORCEEN;
68   } else {
69     sl_status_t status = sli_clock_manager_set_sysclk_source(EXECUTION_MODE_PERFORMANCE_CLOCK_SOURCE);
70     EFM_ASSERT(status == SL_STATUS_OK);
71   }
72 }
73 
74 /***************************************************************************//**
75  * Updates SYSCLK to achieve standard mode execution.
76  ******************************************************************************/
sli_power_manager_hal_apply_standard_mode(void)77 void sli_power_manager_hal_apply_standard_mode(void)
78 {
79   sl_status_t status = sli_clock_manager_set_sysclk_source(EXECUTION_MODE_STANDARD_CLOCK_SOURCE);
80   EFM_ASSERT(status == SL_STATUS_OK);
81 }
82 #endif // SL_POWER_MANAGER_EXECUTION_MODES_FEATURE_EN
83