1 /*
2  * Copyright (c) 2022 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_IPC_EVENT_MGR_H
9 #define HPM_IPC_EVENT_MGR_H
10 
11 #ifdef __cplusplus
12 
13 extern "C" {
14 #endif
15 
16 /**
17  * @brief Type definition of event callback function pointer.
18  *
19  * @param [in] event data
20  * @param [in] callback context data
21  */
22 typedef void (*ipc_event_callback_t)(uint16_t event_data, void *context);
23 
24 /**
25  * @brief Type definition of structure with event handler and data.
26  */
27 typedef struct {
28     ipc_event_callback_t callback; /**< Pointer to callback function.*/
29     void *callback_data; /**< Context data for callback.*/
30 } ipc_event_t;
31 
32 /**
33  * @brief Type definition of event types.
34  */
35 typedef enum {
36     ipc_remote_start_event = 1,
37     ipc_remote_rpmsg_event,
38     ipc_event_table_len
39 } ipc_event_type_t;
40 
41 /**
42  * @brief IPC Init.
43  */
44 void ipc_init(void);
45 
46 /**
47  * @brief Enbale IPC event interrupt.
48  *
49  * @param [in] interrupt priority
50  */
51 void ipc_enable_event_interrupt(uint32_t priority);
52 
53 /**
54  * @brief Disbale IPC event interrupt.
55  */
56 void ipc_disable_event_interrupt(void);
57 
58 /**
59  * @brief Register IPC event
60  *
61  * @param [in] event type
62  * @param [in] event callback function
63  * @param [in] event callback data
64  *
65  * @retval status_success if no error occurred
66  * @retval status_invalid_argument if the parameter is invalid
67  */
68 hpm_stat_t ipc_register_event(ipc_event_type_t type, ipc_event_callback_t callback, void *callback_data);
69 
70 /**
71  * @brief Trigger IPC event
72  *
73  * @param [in] event type
74  * @param [in] event data
75  *
76  * @retval status_success if no error occurred
77  * @retval status_invalid_argument if any parameters are invalid
78  */
79 hpm_stat_t ipc_tigger_event(ipc_event_type_t type, uint16_t event_data);
80 
81 /*!
82  * @brief event handler
83  *
84  * This function is called when event received
85  *
86  * @param [in] event type and data.
87  */
88 void ipc_event_handler(uint32_t data);
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif /* HPM_IPC_EVENT_MGR_H */
95