1 // Copyright 2020 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <stdint.h>
18 #include <stdbool.h>
19 
20 #include "esp_err.h"
21 
22 #include "soc/soc_caps.h"
23 #include "hal/cpu_hal.h"
24 #include "hal/soc_ll.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #if SOC_CPU_CORES_NUM > 1
31 // Utility functions for multicore targets
32 #define __SOC_HAL_PERFORM_ON_OTHER_CORES(action)    { \
33                                                         for (uint32_t i = 0, cur = cpu_hal_get_core_id(); i < SOC_CPU_CORES_NUM; i++) { \
34                                                             if (i != cur) { \
35                                                                 action(i); \
36                                                             } \
37                                                         } \
38                                                     }
39 
40 #define SOC_HAL_STALL_OTHER_CORES()                 __SOC_HAL_PERFORM_ON_OTHER_CORES(soc_hal_stall_core);
41 #define SOC_HAL_UNSTALL_OTHER_CORES()               __SOC_HAL_PERFORM_ON_OTHER_CORES(soc_hal_unstall_core);
42 #define SOC_HAL_RESET_OTHER_CORES()                 __SOC_HAL_PERFORM_ON_OTHER_CORES(soc_hal_reset_core);
43 
44 /**
45  * Stall the specified CPU core.
46  *
47  * @note Has no effect if the core is already stalled - does not return an
48  * ESP_ERR_INVALID_STATE.
49  *
50  * @param core core to stall [0..SOC_CPU_CORES_NUM - 1]
51  */
52 void soc_hal_stall_core(int core);
53 
54 /**
55  * Unstall the specified CPU core.
56  *
57  * @note Has no effect if the core is already unstalled - does not return an
58  * ESP_ERR_INVALID_STATE.
59  *
60  * @param core core to unstall [0..SOC_CPU_CORES_NUM - 1]
61  */
62 void soc_hal_unstall_core(int core);
63 
64 #endif // SOC_CPU_CORES_NUM > 1
65 
66 /**
67  * Reset the specified core.
68  *
69  * @param core core to reset [0..SOC_CPU_CORES_NUM - 1]
70  */
71 #define soc_hal_reset_core(core)         soc_ll_reset_core((core))
72 
73 #ifdef __cplusplus
74 }
75 #endif
76