1 /* 2 * Copyright (c) 2022 HPMicro 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 #include "hpm_common.h" 8 #include "hpm_ipc_event_mgr.h" 9 #include "hpm_ipc_event_mgr_mbx_internal.h" 10 11 /***************************************************************************************************************** 12 * 13 * Definitions 14 * 15 *****************************************************************************************************************/ 16 17 /***************************************************************************************************************** 18 * 19 * Prototypes 20 * 21 *****************************************************************************************************************/ 22 23 /***************************************************************************************************************** 24 * 25 * Variables 26 * 27 *****************************************************************************************************************/ 28 static ipc_event_t s_ipc_event_table[ipc_event_table_len]; 29 30 /***************************************************************************************************************** 31 * 32 * Codes 33 * 34 *****************************************************************************************************************/ ipc_init(void)35void ipc_init(void) 36 { 37 ipc_init_internal(); 38 } 39 ipc_enable_event_interrupt(uint32_t priority)40void ipc_enable_event_interrupt(uint32_t priority) 41 { 42 ipc_enable_event_interrupt_internal(priority); 43 } 44 ipc_disable_event_interrupt(void)45void ipc_disable_event_interrupt(void) 46 { 47 ipc_disable_event_interrupt_internal(); 48 } 49 ipc_register_event(ipc_event_type_t type,ipc_event_callback_t callback,void * callback_data)50hpm_stat_t ipc_register_event(ipc_event_type_t type, ipc_event_callback_t callback, void *callback_data) 51 { 52 hpm_stat_t status; 53 54 if ((type >= ipc_event_table_len) || (callback == NULL)) { 55 status = status_invalid_argument; 56 } else { 57 s_ipc_event_table[type].callback = callback; 58 s_ipc_event_table[type].callback_data = callback_data; 59 status = status_success; 60 } 61 62 return status; 63 } 64 ipc_tigger_event(ipc_event_type_t type,uint16_t event_data)65hpm_stat_t ipc_tigger_event(ipc_event_type_t type, uint16_t event_data) 66 { 67 hpm_stat_t status; 68 uint32_t remote_data; 69 70 if (type >= ipc_event_table_len) { 71 status = status_invalid_argument; 72 } else { 73 remote_data = (((uint32_t)type) << 16) | event_data; 74 ipc_tigger_event_internal(remote_data); 75 status = status_success; 76 } 77 78 return status; 79 } 80 ipc_event_handler(uint32_t data)81void ipc_event_handler(uint32_t data) 82 { 83 uint16_t event_type; 84 uint16_t event_data; 85 86 if (0U != data) { 87 event_type = (uint16_t)(data >> 16u); 88 event_data = (uint16_t)(data & 0x0000FFFFu); 89 90 if (((ipc_event_type_t)event_type >= ipc_remote_start_event) && ((ipc_event_type_t)event_type < ipc_event_table_len)) { 91 if (s_ipc_event_table[(ipc_event_type_t)event_type].callback != NULL) { 92 s_ipc_event_table[(ipc_event_type_t)event_type].callback( 93 event_data, s_ipc_event_table[(ipc_event_type_t)event_type].callback_data); 94 } 95 } 96 } 97 } 98