1 /*
2  * Copyright (c) 2014-2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2023 NXP
4  * All rights reserved.
5  *
6  *
7  * SPDX-License-Identifier: BSD-3-Clause
8  */
9 
10 #ifndef MCMGR_H
11 #define MCMGR_H
12 
13 #include <stdbool.h>
14 #include <stdint.h>
15 
16 /*!
17  * @addtogroup mcmgr
18  * @{
19  */
20 
21 /*! @brief Enumeration that defines MCMGR function return status codes. */
22 typedef enum _mcmgr_status
23 {
24     /*! @brief Operation was successful. */
25     kStatus_MCMGR_Success,
26     /*! @brief Operation was not successful. */
27     kStatus_MCMGR_Error,
28     /*! @brief Function is not implemented. */
29     kStatus_MCMGR_NotImplemented,
30     /*! @brief Operation result not ready. */
31     kStatus_MCMGR_NotReady
32 
33 } mcmgr_status_t;
34 
35 /*! @brief Enumeration that defines property of core. */
36 typedef enum _mcmgr_core_property
37 {
38     /*! @brief Status of core read from hardware core status flag. */
39     kMCMGR_CoreStatus,
40     /*! @brief Type of Core. */
41     kMCMGR_CoreType,
42     /*! @brief Power Mode of Core - implementation is hardware-specific. */
43     kMCMGR_CorePowerMode
44 } mcmgr_core_property_t;
45 
46 /*! @brief Enumeration that defines the property value of core status. */
47 typedef enum _mcmgr_core_status
48 {
49     /*! @brief Core is held in reset. */
50     kMCMGR_InReset,
51     /*! @brief Core is not in reset. */
52     kMCMGR_NotInReset
53 } mcmgr_core_status_t;
54 
55 /*! @brief Enumeration that defines property value of core type. */
56 typedef enum _mcmgr_core_type
57 {
58     /*! @brief Cortex M0 */
59     kMCMGR_CoreTypeCortexM0,
60     /*! @brief Cortex M0+ */
61     kMCMGR_CoreTypeCortexM0Plus,
62     /*! @brief Cortex M4 */
63     kMCMGR_CoreTypeCortexM4,
64     /*! @brief Cortex M33 */
65     kMCMGR_CoreTypeCortexM33,
66     /*! @brief Cortex M7 */
67     kMCMGR_CoreTypeCortexM7,
68     /*! @brief Cortex M3 */
69     kMCMGR_CoreTypeCortexM3
70 } mcmgr_core_type_t;
71 
72 /*! @brief Enumeration that defines core. */
73 typedef enum _mcmgr_core
74 {
75     /*! @brief Enum value for Core 0. */
76     kMCMGR_Core0,
77     /*! @brief Enum value for Core 1. */
78     kMCMGR_Core1
79 } mcmgr_core_t;
80 
81 /*! @brief Enumeration that defines start type. */
82 typedef enum _mcmgr_start_mode
83 {
84     /*! @brief Enum value for starting synchronously. */
85     kMCMGR_Start_Synchronous,
86     /*! @brief Enum value for starting asynchronously. */
87     kMCMGR_Start_Asynchronous
88 
89 } mcmgr_start_mode_t;
90 
91 /*! @brief Type definition of event types. */
92 typedef enum _mcmgr_event_type_t
93 {
94     kMCMGR_RemoteCoreUpEvent = 1,
95     kMCMGR_RemoteCoreDownEvent,
96     kMCMGR_RemoteExceptionEvent,
97     kMCMGR_StartupDataEvent,
98     kMCMGR_FeedStartupDataEvent,
99     kMCMGR_RemoteRPMsgEvent,
100     kMCMGR_RemoteApplicationEvent,
101     kMCMGR_FreeRtosMessageBuffersEvent,
102     kMCMGR_EventTableLength
103 } mcmgr_event_type_t;
104 
105 /*! @brief Type definition of event callback function pointer. */
106 typedef void (*mcmgr_event_callback_t)(uint16_t data, void *context);
107 
108 /*! @brief Set to 1 to enable exception handling. */
109 #ifndef MCMGR_HANDLE_EXCEPTIONS
110 #define MCMGR_HANDLE_EXCEPTIONS (0)
111 #endif
112 /*!
113  * @brief Version of MCMGR
114  *
115  * Version 1.0.0, for version 1.2.3 it will be 0x00010203
116  */
117 enum mcmgr_version_enum
118 {
119     kMCMGR_Version = 0x00040105
120 };
121 
122 #if defined(__cplusplus)
123 extern "C" {
124 #endif // __cplusplus
125 
126 /*!
127  * @brief Initialize the multicore manager, early init.
128  *
129  * After calling this function, MCMGR_TriggerEvent() and/or MCMGR_Init() can be called.
130  *
131  * @return kStatus_MCMGR_Success on success or kStatus_MCMGR_Error on failure.
132  */
133 mcmgr_status_t MCMGR_EarlyInit(void);
134 
135 /*!
136  * @brief Initialize the multicore manager
137  *
138  * After calling this function, all API can be used.
139  *
140  * @return kStatus_MCMGR_Success on success or kStatus_MCMGR_Error on failure.
141  */
142 mcmgr_status_t MCMGR_Init(void);
143 
144 /*!
145  * @brief Start a selected core
146  *
147  * This function causes a selected core to initialize and start the code execution.
148  * If the secondary core application boots from RAM, then there is a need to call the function,
149  * which copies this app. Image to RAM prior this function.
150  *
151  * @param[in] coreNum Enum of the core to be started.
152  * @param[in] bootAddress Boot address of the core to be started application.
153  * @param[in] startupData Data which can be get by the other core on startup.
154  * @param[in] mode Start mode, use kMCMGR_Start_Synchronous for synchronous mode (wait until the
155  *            core is started), kMCMGR_Start_Asynchronous for asynchronous mode (do not wait).
156  *
157  * @return kStatus_MCMGR_Success on success or kStatus_MCMGR_Error on failure.
158  */
159 mcmgr_status_t MCMGR_StartCore(mcmgr_core_t coreNum, void *bootAddress, uint32_t startupData, mcmgr_start_mode_t mode);
160 
161 /*!
162  * @brief Get startup data for the slave core.
163  *
164  * This function read startup data provided by the master core.
165  * Use only on the slave core during the startup.
166  *
167  * @param[out] startupData Data to read by this function.
168  *
169  * @return kStatus_MCMGR_Success on success or kStatus_MCMGR_Error on failure.
170  */
171 mcmgr_status_t MCMGR_GetStartupData(uint32_t *startupData);
172 
173 /*!
174  * @brief Stop a selected core
175  *
176  * This function causes a selected core to halt code execution.
177  *
178  * @param[in] coreNum Enum of core to be stopped.
179  *
180  * @return kStatus_MCMGR_Success on success or kStatus_MCMGR_Error on failure.
181  */
182 mcmgr_status_t MCMGR_StopCore(mcmgr_core_t coreNum);
183 
184 /*!
185  * @brief Get version of MCMGR
186  *
187  * This function returns a number of MCMGR version.
188  *
189  * @return a number of MCMGR version.
190  */
191 int32_t MCMGR_GetVersion(void);
192 
193 /*!
194  * @brief Get property of the CPU core
195  *
196  * This function provides the property of the CPU core.
197  *
198  * @param[in] coreNum Enum of core.
199  * @param[in] property Requested property type.
200  * @param[in,out] value Parameter for value of property.
201  * @param[in,out] length Parameter for size of property value in bytes.
202  *
203  * @return kStatus_MCMGR_Success on success or kStatus_MCMGR_Error on failure.
204  */
205 mcmgr_status_t MCMGR_GetCoreProperty(mcmgr_core_t coreNum,
206                                      mcmgr_core_property_t property,
207                                      void *value,
208                                      uint32_t *length);
209 
210 /*!
211  * @brief Return the count of cores in a multicore system
212  *
213  * This function returns the count of cores in a multicore system.
214  *
215  * @return the count of cores in a system.
216  */
217 uint32_t MCMGR_GetCoreCount(void);
218 
219 /*!
220  * @brief Get current CPU core
221  *
222  * This function returns enum of current core.
223  *
224  * @return Enum of current core.
225  */
226 mcmgr_core_t MCMGR_GetCurrentCore(void);
227 
228 /*!
229  * @brief Register event handler
230  *
231  * This function registers an event handler.
232  * for remote processor events handling.
233  *
234  * @param[in] type Type of the event.
235  * @param[in] callback User callback.
236  * @param[in] callbackData Data/context for user callback.
237  *
238  * @return kStatus_MCMGR_Success on success or kStatus_MCMGR_Error on failure.
239  */
240 mcmgr_status_t MCMGR_RegisterEvent(mcmgr_event_type_t type, mcmgr_event_callback_t callback, void *callbackData);
241 
242 /*!
243  * @brief Trigger event handler
244  *
245  * This function triggers an event handler
246  * on the remote core.
247  *
248  * @param[in] type Type of the event.
249  * @param[in] eventData Data to send to remote core.
250  *
251  * @return kStatus_MCMGR_Success on success or kStatus_MCMGR_Error on failure.
252  */
253 mcmgr_status_t MCMGR_TriggerEvent(mcmgr_event_type_t type, uint16_t eventData);
254 
255 /*!
256  * @brief Trigger event handler, force version
257  *
258  * This function triggers an event handler
259  * on the remote core, force version that does not check the consumption of previously sent data.
260  *
261  * @param[in] type Type of the event.
262  * @param[in] eventData Data to send to remote core.
263  *
264  * @return kStatus_MCMGR_Success on success or kStatus_MCMGR_Error on failure.
265  */
266 mcmgr_status_t MCMGR_TriggerEventForce(mcmgr_event_type_t type, uint16_t eventData);
267 
268 #if defined(__cplusplus)
269 }
270 #endif // __cplusplus
271 
272 /*! @} */
273 
274 #endif
275