aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/ext/mcux-sdk/devices/MIMX8QM6/drivers/fsl_sc_event.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/devices/MIMX8QM6/drivers/fsl_sc_event.h')
-rw-r--r--lib/chibios-contrib/ext/mcux-sdk/devices/MIMX8QM6/drivers/fsl_sc_event.h266
1 files changed, 266 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/devices/MIMX8QM6/drivers/fsl_sc_event.h b/lib/chibios-contrib/ext/mcux-sdk/devices/MIMX8QM6/drivers/fsl_sc_event.h
new file mode 100644
index 000000000..7aa4e2f5b
--- /dev/null
+++ b/lib/chibios-contrib/ext/mcux-sdk/devices/MIMX8QM6/drivers/fsl_sc_event.h
@@ -0,0 +1,266 @@
1/*
2 * Copyright 2019 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#ifndef _FSL_SC_EVENT_H_
9#define _FSL_SC_EVENT_H_
10
11#include "fsl_common.h"
12#include "svc/irq/irq_api.h"
13#include "svc/pad/pad_api.h"
14
15/*!
16 * @addtogroup sc_event_driver
17 * @{
18 */
19
20/*******************************************************************************
21 * Definitions
22 ******************************************************************************/
23
24/*! @name Driver version */
25/*@{*/
26/*! @brief Group interrupt driver version for SDK */
27#define FSL_SC_EVENT_DRIVER_VERSION (MAKE_VERSION(2, 0, 1)) /*!< Version 2.0.1. */
28/*@}*/
29
30/*! @brief The SC Event handler memory pool size in bytes. */
31#ifndef SC_EVENT_HANDLER_MEM_POOL_SIZE
32#define SC_EVENT_HANDLER_MEM_POOL_SIZE (200U)
33#endif
34
35/*!
36 * @brief The SYSCTR SC Event maybe used as wakeup source in low power applications.
37 * Such as in LPM module(lpm.c), the SYSCTR is used as wakeup source in tickless idle.
38 */
39#ifndef SC_EVENT_USE_SYSCTR
40#define SC_EVENT_USE_SYSCTR (0)
41#endif
42
43#define SC_EVENT_IRQ_DUMMY (0xFFFFFFFU) /* Dummy mask. */
44#define SC_EVENT_TYPE_TUPLE(group, irq) (((group) << 28) | (irq)) /* Marco to compose SC Event type. */
45#define SC_EVENT_GET_IRQ_GROUP(type) (((uint32_t)(type) >> 28) & 0xFU) /* Marco to get SC IRQ group. */
46#define SC_EVENT_GET_IRQ(type) ((uint32_t)(type) & 0xFFFFFFFU) /* Marco to get SC IRQ mask. */
47
48/*!
49 * @brief Get SC Event list object structure pointer.
50 */
51#define SC_EVENT_LIST_OBJ(type, field, list) (type)((uint32_t)(list) - (uint32_t)(&((type)0)->field))
52
53/*! @brief SC Event type. */
54typedef enum _sc_event
55{
56 kSCEvent_TempHigh = SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_HIGH), /*!< Temp alarm interrupt */
57 kSCEvent_TempCpu0High =
58 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_CPU0_HIGH), /*!< CPU0 temp alarm interrupt */
59 kSCEvent_TempCpu1High =
60 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_CPU1_HIGH), /*!< CPU1 temp alarm interrupt */
61 kSCEvent_TempGpu0High =
62 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_GPU0_HIGH), /*!< GPU0 temp alarm interrupt */
63 kSCEvent_TempGpu1High =
64 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_GPU1_HIGH), /*!< GPU1 temp alarm interrupt */
65 kSCEvent_TempDrc0High =
66 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_DRC0_HIGH), /*!< DRC0 temp alarm interrupt */
67 kSCEvent_TempDrc1High =
68 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_DRC1_HIGH), /*!< DRC1 temp alarm interrupt */
69 kSCEvent_TempVpuHigh =
70 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_VPU_HIGH), /*!< VPU temp alarm interrupt */
71 kSCEvent_TempPmic0High =
72 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_PMIC0_HIGH), /*!< PMIC0 temp alarm interrupt */
73 kSCEvent_TempPmic1High =
74 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_PMIC1_HIGH), /*!< PMIC1 temp alarm interrupt */
75 kSCEvent_TempLow = SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_LOW), /*!< Temp alarm interrupt */
76 kSCEvent_TempCpu0Low =
77 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_CPU0_LOW), /*!< CPU0 temp alarm interrupt */
78 kSCEvent_TempCpu1Low =
79 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_CPU1_LOW), /*!< CPU1 temp alarm interrupt */
80 kSCEvent_TempGpu0Low =
81 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_GPU0_LOW), /*!< GPU0 temp alarm interrupt */
82 kSCEvent_TempGpu1Low =
83 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_GPU1_LOW), /*!< GPU1 temp alarm interrupt */
84 kSCEvent_TempDrc0Low =
85 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_DRC0_LOW), /*!< DRC0 temp alarm interrupt */
86 kSCEvent_TempDrc1Low =
87 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_DRC1_LOW), /*!< DRC1 temp alarm interrupt */
88 kSCEvent_TempVpuLow = SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_VPU_LOW), /*!< VPU temp alarm interrupt */
89 kSCEvent_TempPmic0Low =
90 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_PMIC0_LOW), /*!< PMIC0 temp alarm interrupt */
91 kSCEvent_TempPmic1Low =
92 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_PMIC1_LOW), /*!< PMIC1 temp alarm interrupt */
93 kSCEvent_TempPmic2High =
94 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_PMIC2_HIGH), /*!< PMIC2 temp alarm interrupt */
95 kSCEvent_TempPmic2Low =
96 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_TEMP, SC_IRQ_TEMP_PMIC2_LOW), /*!< PMIC2 temp alarm interrupt */
97
98 kSCEvent_Wdog = SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_WDOG, SC_IRQ_WDOG), /*!< Watchdog interrupt */
99
100 kSCEvent_Rtc = SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_RTC, SC_IRQ_RTC), /*!< RTC interrupt */
101
102 kSCEvent_Button = SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_WAKE, SC_IRQ_BUTTON), /*!< Button interrupt */
103 kSCEvent_Pad = SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_WAKE, SC_IRQ_PAD), /*!< Pad wakeup */
104 kSCEvent_User1 = SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_WAKE, SC_IRQ_USR1), /*!< User defined 1 */
105 kSCEvent_User2 = SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_WAKE, SC_IRQ_USR2), /*!< User defined 2 */
106 kSCEvent_BcPad =
107 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_WAKE, SC_IRQ_BC_PAD), /*!< Pad wakeup (broadcast to all partitions) */
108#if (defined(SC_EVENT_USE_SYSCTR) && SC_EVENT_USE_SYSCTR)
109 kSCEvent_SysCtr = SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_SYSCTR, SC_IRQ_SYSCTR), /*!< System counter interrupts */
110#endif
111 kSCEvent_Rebooted =
112 SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_REBOOTED, SC_EVENT_IRQ_DUMMY), /*!< Partition reboot complete */
113
114 kSCEvent_Reboot = SC_EVENT_TYPE_TUPLE(SC_IRQ_GROUP_REBOOT, SC_EVENT_IRQ_DUMMY) /*!< Partition reboot starting */
115} sc_event_t;
116
117/*! @brief SC Event callback function.
118 *
119 * The SC Event callback returns a status from the underlying layer.
120 * The status reflects the SC IRQ status got by sc_irq_status SCFW API. It's the bitmask of enabled IRQ in a group.
121 * Such as for kSCEvent_Reboot/kSCEvent_Rebooted event, if more than one partition reboot event is enabled, this status
122 * flag can be used to identify which partition the event comes from. Refer to SCFW API sc_irq_status for more details.
123 */
124typedef void (*sc_event_callback_t)(uint32_t status, void *userData);
125
126/*! @brief SC Event Semaphore Wait function.
127 *
128 * The Semaphore Wait/Post function is used in RTOS envirnoment to pass Semaphore Wait/Post function into SC Event
129 * driver. Unused in baremetal envirnonment. The task can wait the event by calling SCEvent_WaitEvent function.
130 */
131typedef status_t (*sc_event_sema4_wait_t)(void *sem, uint32_t timeout);
132
133/*! @brief SC Event Semaphore Post function.
134 *
135 * The Semaphore Wait/Post function is used in RTOS envirnoment to pass Semaphore Wait/Post function into SC Event
136 * driver. Unused in baremetal envirnonment. The post function is called to give semaphore if event triggered in IRQ.
137 */
138typedef void (*sc_event_sema4_post_t)(void *sem);
139
140/**
141 * @brief SC Event list fields
142 */
143typedef struct _sc_event_list
144{
145 struct _sc_event_list *prev; /*!< previous list node */
146 struct _sc_event_list *next; /*!< next list node */
147} sc_event_list_t;
148
149/*! @brief SC Event handler structure. */
150struct _sc_event_handler
151{
152 sc_event_list_t node;
153 sc_event_t event; /*!< Event type. */
154 sc_event_callback_t callback; /*!< Event callback. */
155 void *data; /*!< User data. */
156};
157
158/*!
159 * @brief SC Event handler is a pointer to the SC Event handler instance
160 */
161typedef struct _sc_event_handler *sc_event_handler_t;
162/*******************************************************************************
163 * API
164 ******************************************************************************/
165
166#ifdef __cplusplus
167extern "C" {
168#endif
169
170/*!
171 * @brief Initialize SC Event module.
172
173 * This function enable the IPC MU interrupt, setup to listen the event comes from SCU/SCFW.
174 *
175 * @param priority The SC IRQ interrupt priority. Once any SC IRQ enabled, the SCU will broadcast MU interrupt through
176 * the IPC MU to M4 cores.
177 *
178 * @retval None.
179 */
180void SCEvent_Init(uint8_t priority);
181
182/*!
183 * @brief Deinitialize SC Event.
184 *
185 * This function disable the IPC MU interrupt.
186 *
187 */
188void SCEvent_Deinit(void);
189
190/*!
191 * @brief Register SC Event handler.
192
193 * This function register the handler for the specified event. When the event is enabled by SCEvent_Config and happens,
194 * the callback will be called from SCEvent_process. More than one callback can be added for an event.
195 * But the total registered events are limited to
196 * SC_EVENT_HANDLER_MEM_POOL_SIZE/(sizeof(struct _sc_event_handler)).
197 *
198 * @param event The event to be registered with.
199 * @param callback The callback function. This function will be called from SCEvent_process.
200 * @param userData User defined callback function parameter.
201 *
202 * @retval SC Event handler.
203 */
204sc_event_handler_t SCEvent_RegisterEventHandler(sc_event_t event, sc_event_callback_t callback, void *userData);
205
206/*!
207 * @brief Unregister SC Event handler.
208
209 * This function unregister and delete the given event handler.
210 *
211 * @param handler The SC Event handler to unregister.
212 *
213 * @retval none.
214 */
215void SCEvent_UnregisterEventHandler(sc_event_handler_t handler);
216
217/*!
218 * @brief Configure SC Event.
219
220 * This function enables/disables response for the event comes from SCU/SCFW.
221 *
222 * @param event The event to be configured.
223 * @param enable Enable the event or not.
224 * @param pt Which partition the event comes from. Only applicable for partition reboot event: kSCEvent_Rebooted,
225 kSCEvent_Reboot.
226 *
227 * @retval kStatus_Success - Configure SC Event Successfully.
228 * @retval kStatus_Fail - Failed to configure SC Event.
229 */
230status_t SCEvent_Config(sc_event_t event, bool enable, uint32_t pt);
231
232/*!
233 * @brief SCEvent Process function.
234 *
235 * This function is used to check SC event status and handle all the registered event handlers. The SCFW API call is
236 * a blocking call and used to check SC IRQ status, so this function should be executed in task context to make sure
237 * other event(interrupt) handled in time. In RTOS enviroment, application creats a task and wait for some events came
238 * using SCEvent_WaitEvent to run this function to handle the events. In baremetal enviroment, application need
239 * preiodically call this function to make sure the pending events handled.
240 */
241void SCEvent_Process(void);
242
243/*!
244 * @brief Set Semaphore and Semaphore wait/post funciton in RTOS environment.
245 *
246 * The Semaphore Wait/Post function is used in RTOS envirnoment to pass Semaphore Wait/Post function into SC Event
247 * driver. Unused in baremetal envirnonment. The SCEvent_process will wait the Semaphore registered by
248 * SCEvent_SetWaitPostFunc until the event comes, and give the Semaphore, then it will handle the event and call the
249 * event handler's callback.
250 *
251 * @param wait Semaphore wait function.
252 * @param post Semaphore post function.
253 * @param sem Semaphore.
254 * @param timeout timeout.
255 *
256 * @retval kStatus_Success if succeed, kStatus_Timeout if timeout.
257 */
258status_t SCEvent_WaitEvent(sc_event_sema4_wait_t wait, sc_event_sema4_post_t post, void *sem, uint32_t timeout);
259
260#ifdef __cplusplus
261}
262#endif
263
264/*@}*/
265
266#endif /* _SC_EVENT_H_ */