1 /* 2 * Copyright (C) 2017-2019 Alibaba Group Holding Limited 3 */ 4 5 /****************************************************************************** 6 * @file drv_mailbox.h 7 * @brief header file for mailbox driver 8 * @version V1.0 9 * @date 28. Jan 2019 10 * @model mailbox 11 ******************************************************************************/ 12 13 #ifndef _CSI_MAILBOX_H_ 14 #define _CSI_MAILBOX_H_ 15 16 17 #include <drv/common.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 typedef struct { 24 int count; 25 struct { 26 uint32_t mailbox_id; 27 uint32_t tx_chnl; 28 uint32_t rx_chnl; 29 } config[]; 30 } mailbox_chnl_config_t; 31 32 /// definition for mailbox handle. 33 typedef void *mailbox_handle_t; 34 35 /****** MAILBOX Event *****/ 36 typedef enum { 37 MAILBOX_EVENT_SEND_COMPLETE = 0, ///< Send completed; however mailbox may still transmit data 38 MAILBOX_EVENT_RECEIVED = 1, ///< Data Received, only in mailbox buf, call memcpy() get the data 39 } mailbox_event_e; 40 41 typedef void (*mailbox_event_cb_t)(mailbox_handle_t handle, int32_t mailbox_id, uint32_t received_len, mailbox_event_e event); ///< Pointer to \ref mailbox_event_cb_t : MAILBOX Event call back. 42 43 /** 44 \brief Initialize MAILBOX Interface. 1. Initializes the resources needed for the MAILBOX interface 2.registers event callback function 45 \param[in] cb_event event call back function \ref mailbox_event_cb_t 46 \return return mailbox handle if success 47 */ 48 mailbox_handle_t csi_mailbox_initialize(mailbox_event_cb_t cb_event); 49 50 /** 51 \brief De-initialize MAILBOX Interface. stops operation and releases the software resources used by the interface 52 \param[in] handle mailbox handle to operate. 53 \return error code 54 */ 55 int32_t csi_mailbox_uninitialize(mailbox_handle_t handle); 56 57 /** 58 \brief Start sending data to MAILBOX transmitter,(received data is ignored). 59 This function is non-blocking,\ref mailbox_event_e is signaled when operation completes or error happens. 60 \ref csi_mailbox_get_status can get operation status. 61 \param[in] handle mailbox handle to operate. 62 \param[in] mailbox_id index of dest mailbox 63 \param[in] data Pointer to buffer with data to send to MAILBOX transmitter. 64 \param[in] num Number of data items to send 65 \return sent number of data 66 */ 67 int32_t csi_mailbox_send(mailbox_handle_t handle, int32_t mailbox_id, const void *data, uint32_t num); 68 69 /** 70 \brief Start Receiving data from Mailbox receiver. 71 \param[in] handle mailbox handle to operate. 72 \param[in] mailbox_id index of dest mailbox 73 \param[out] data Pointer to buffer with data to receive from mailbox. 74 \param[in] num Number of data items to receive 75 \return received number or error code 76 */ 77 int32_t csi_mailbox_receive(mailbox_handle_t handle, int32_t mailbox_id, void *data, uint32_t num); 78 79 /** 80 \brief enable mailbox ch irq 81 \param[in] cb_event event call back function \ref mailbox_event_cb_t 82 \return return mailbox handle if success 83 */ 84 int32_t csi_mailbox_chnl_enable(mailbox_handle_t handle, int32_t mailbox_id); 85 86 #ifdef __cplusplus 87 } 88 #endif 89 90 #endif /* _CSI_MAILBOX_H_ */ 91