1 /**************************************************************************//**
2  * @file     icc_api.c
3  * @brief    This file defines the data types and macro for ICC API implementation.
4  *
5  * @version  V1.00
6  * @date     2017-06-05
7  *
8  * @note
9  *
10  ******************************************************************************
11  *
12  * Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved.
13  *
14  ******************************************************************************/
15 
16 #ifndef MBED_ICC_API_H
17 #define MBED_ICC_API_H
18 #if (defined(CONFIG_PLATFORM_8195BHP) && (CONFIG_PLATFORM_8195BHP == 1))  ||  (defined(CONFIG_PLATFORM_8195BLP) && (CONFIG_PLATFORM_8195BLP == 1))
19 ///@name AmebaPro Only
20 ///@{
21 
22 #include "device.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 /** @addtogroup icc ICC
28  *  @ingroup    hal
29  *  @brief      ICC(Inter CPU Communication) HAL APIs
30  *  @{
31  */
32 
33 /**
34   \brief  ICC message queue ID.
35 */
36 typedef enum icc_api_msg_qid_e {
37     ICC_MsgHQ           = 0,  ///<  higher priority message queue, data is this queue will be processed first
38     ICC_MsgLQ           = 1   ///<   lower priority message queue
39 } icc_msg_qid_t, *picc_msg_qid_t;
40 
41 /**
42   \brief  Default type for ICC user application command word.
43 */
44 typedef struct icc_user_cmd_s {
45     union {
46         uint32_t cmd_w;
47         struct {
48             uint32_t para0:24;  ///< command parameter 0. User application can re-define this field
49             uint32_t cmd:8;     ///< command type, bit[31:24] is dedicated for the command type.
50         } cmd_b;
51     };
52 } icc_user_cmd_t, *picc_user_cmd_t;
53 
54 #if 0
55 /**
56   \brief  Default type for ICC user application message word.
57 */
58 typedef struct icc_user_msg_s{
59     union {
60         uint32_t msg_w;
61         struct {
62             icc_msg_qid_t msg_q:8;  ///< message queue selection, bit[7:0] is dedicated for the message queue ID.
63             uint32_t msg_op:8;      ///< message operland. User application can re-define this field.
64             uint32_t msg_type:8;    ///< message type, bit[23:13] is dedicated for the message type.
65             uint32_t cmd:8; ///< command type, bit[31:24] is reserved for the command type. User application should not use this field.
66         } msg_b;
67     };
68 } icc_user_msg_t, *picc_user_msg_t;
69 #endif
70 
71 /**
72   \brief  The function type of the ICC command callback function.
73 */
74 typedef void (*icc_user_cmd_callback_t)(uint32_t icc_cmd, uint32_t icc_cmd_op, uint32_t cb_arg);
75 /**
76   \brief  The function type of the ICC message callback function.
77 */
78 typedef void (*icc_user_msg_callback_t)(uint8_t *pmsg_buf, uint32_t msg_size, uint32_t cb_arg);
79 
80 /**
81   \brief  The function type of the message data transfer complete callback function.
82 */
83 typedef void (*icc_msg_tx_callback_t)(uint32_t cb_arg);
84 
85 /**
86  *  @brief Initials the ICC (Inter CPU Communication) object.
87  *         The secure region ICC object should be initialed first.
88  *
89  *  @returns    void.
90  */
91 void icc_init (void);
92 
93 /**
94  *  @brief Disables the ICC interface.
95  *
96  *  @returns void.
97  */
98 void icc_deinit (void);
99 
100 /**
101  *  @brief Submits a message RX request with RX data buffer to the ICC HAL. The RX requests
102  *         are used to receive messages from HS platform.
103  *  @param[in]  rx_req  The message RX request will to be added to the message RX request pending queue.
104  *  @param[in]  pbuf  The data buffer for ICC message data receiving.
105  *  @param[in]  size  The size, in byte, of the data buffer.
106  *
107  *  @return     void.
108  */
109 void icc_msg_rx_req_submit (icc_msg_rx_req_t *rx_req, uint8_t *pbuf, uint32_t size);
110 
111 /**
112  *  @brief Registers(add) an ICC command to the user application ICC command table.
113  *
114  *  @param[in]  cmd  The user application ICC command type to be registered.
115  *  @param[in]  callback  The handler function of this user application ICC command type.
116  *  @param[in]  cb_arg  The application data will be passed back to the application with the callback function.
117  *
118  *  @return     void.
119  */
120 void icc_cmd_register(uint8_t cmd, icc_user_cmd_callback_t callback, uint32_t cb_arg);
121 
122 /**
123  *  @brief Unregisters(remove) an ICC command from the user application ICC command table.
124  *
125  *  @param[in]  cmd  The ICC command type to be removed from the user application ICC command table.
126  *
127  *  @returns    void.
128  */
129 void icc_cmd_unregister(uint8_t cmd);
130 
131 /**
132  *  @brief Sends an ICC command to the LS platform.
133  *
134  *  @param[in]  cmd  The ICC command word 0, it contains the command type and the data word0.
135  *  @param[in]  cmd_para1  The ICC command parameter(data word1).
136  *  @param[in]  timeout_us  The period, in micro-second, to wait the completion of
137  *                          command sending.
138  *                            -Value 0: no wait.
139  *                            -Value 0xFFFFFFFF: wait forever.
140  *  @param[in]  task_yield  The OS task yield function. The ICC HAL will call this function
141  *                          while wait for the command sending is finished.
142  *
143  *  @return     void.
144  */
145 void icc_cmd_send (uint32_t cmd_w, uint32_t cmd_para1, uint32_t timeout_us, void *task_yield);
146 
147 /**
148  *  @brief Registers(adds) an ICC user application message to the
149  *         ICC user application message table.
150  *
151  *  @param[in]  msg_type  The ICC message type to be registered.
152  *  @param[in]  frame  The frame type(category) of this ICC message.
153  *  @param[in]  callback  The ICC message handler function of this new added message type.
154  *  @param[in]  cb_arg  The application data will be passed back to the application
155  *                      with the callback function.
156  *
157  *  @return     void.
158  */
159 void icc_msg_register (uint8_t msg_type, uint8_t frame,
160                           icc_user_msg_callback_t callback, uint32_t cb_arg);
161 
162 /**
163  *  @brief Un-register(remove) an user application ICC message from the
164  *         user application ICC message table.
165  *
166  *  @param[in]  msg  The user application ICC message type to be removed
167  *                   from the user application ICC message table.
168  *  @param[in]  frame  The frame type(category) of this ICC message.
169  *
170  *  @returns    void.
171  */
172 void icc_msg_unregister (uint8_t msg, uint8_t frame);
173 
174 /**
175  *  @brief Sends a ICC message (with message data) to peer.
176  *  @param[in]  msg_type  The message type of the ICC message to be send.
177  *  @param[in]  frame_type  The frame type(category) of the message type.
178  *  @param[in]  q_id  The message queue ID. It assign the message queue to send this message(with its data).
179  *  @param[in]  msg_data  The buffer of the message data to be send.
180  *  @param[in]  msg_len  The length(in byte) of data in the buffer msg_data to be send.
181  *  @param[in]  callback  The call-back function for the message data transfer is done.
182  *  @param[in]  callback_arg  The argument of the call-back function.
183  *
184  *  @return     0: Message send OK. (the TX request adds to the TX pending queue OK).
185  *  @return     < 0: Gor error on Message sending.
186  */
187 int32_t icc_msg_tx_submit (uint8_t msg_type, uint8_t frame_type, uint8_t *msg_data, uint16_t msg_len,
188                     icc_msg_tx_callback_t callback, uint32_t callback_arg);
189 
190 
191 /** @} */ /* End of group icc */
192 
193 #ifdef __cplusplus
194 }
195 #endif
196 
197 ///@}
198 #endif  // end of "#if defined(CONFIG_PLATFORM_8195BHP) || defined(CONFIG_PLATFORM_8195BLP)"
199 #endif  // end of "#ifndef MBED_ICC_API_H"
200 
201