1 // Copyright (C) 2022 Beken Corporation 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 <components/log.h> 18 #include "mailbox_hal.h" 19 #include <driver/mailbox.h> 20 #include <driver/mailbox_types.h> 21 #include "mailbox_base_map.h" 22 #include <driver/int.h> 23 24 #define MAILBOX_TAG "mailbox" 25 26 #if (CONFIG_SHELL_ASYNCLOG && CONFIG_SLAVE_CORE) 27 #define MAILBOX_LOGI(...) 28 #define MAILBOX_LOGW(...) 29 #define MAILBOX_LOGE(...) 30 #define MAILBOX_LOGD(...) 31 #else 32 #define MAILBOX_LOGI(...) BK_LOGI(MAILBOX_TAG, ##__VA_ARGS__) 33 #define MAILBOX_LOGW(...) BK_LOGW(MAILBOX_TAG, ##__VA_ARGS__) 34 #define MAILBOX_LOGE(...) BK_LOGE(MAILBOX_TAG, ##__VA_ARGS__) 35 #define MAILBOX_LOGD(...) BK_LOGD(MAILBOX_TAG, ##__VA_ARGS__) 36 #endif 37 38 #define MAILBOX_SEND_WAIT_COUNT 1000 39 40 typedef void (*mailbox_callback_t)(mailbox_data_t *data); 41 #define MAILBOX_CALLBACK_NUMBER 2 42 43 44 typedef enum 45 { 46 MAILBOX0 = 0, 47 MAILBOX1 = 1, 48 MAILBOX2 = 2, 49 MAILBOX3 = 3, 50 } mailbox_num_t; 51 52 typedef struct { 53 mailbox_num_t id; 54 icu_int_src_t icu_src; 55 mailbox_endpoint_t src; 56 mailbox_endpoint_t dst; 57 } mailbox_config_t; 58 59 typedef struct { 60 void (*mailbox_isr)(); 61 void (*rx[MAILBOX_CALLBACK_NUMBER])(); 62 }mailbox_implement_t; 63 64 65 typedef struct { 66 mailbox_hal_t hal; 67 mailbox_config_t dir; 68 mailbox_implement_t imp; 69 }mailbox_info_t; 70 71 bk_err_t bk_mailbox_init(void); 72 bk_err_t bk_mailbox_deinit(void); 73 bk_err_t bk_mailbox_set_param(mailbox_data_t *data, uint32_t p0, uint32_t p1, uint32_t p2, uint32_t p3); 74 bk_err_t bk_mailbox_recv_callback_register(mailbox_endpoint_t src, mailbox_endpoint_t dst, mailbox_callback_t callback); 75 bk_err_t bk_mailbox_recv_callback_unregister(mailbox_endpoint_t src, mailbox_endpoint_t dst); 76 bk_err_t bk_mailbox_send(mailbox_data_t *data, mailbox_endpoint_t src, mailbox_endpoint_t dst, void *arg); 77 78 void mailbox_driver_init(void); 79 void mailbox_driver_deinit(void); 80 81 82