1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file halMBX.c
98 /// @brief MStar MailBox HAL level DDI
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101
102 #define _HAL_MBX_C
103
104 //=============================================================================
105 // Include Files
106 //=============================================================================
107 #include "MsCommon.h"
108 #include "drvMBX.h"
109 #include "regMBX.h"
110 #include "halMBX.h"
111 //=============================================================================
112 // Compile options
113 //=============================================================================
114
115
116 //=============================================================================
117 // Local Defines
118 //=============================================================================
119
120 //=============================================================================
121 // Debug Macros
122 //=============================================================================
123 //#define MBXHAL_DEBUG
124 #ifdef MBXHAL_DEBUG
125 #define MBXHAL_ERROR(fmt, args...) printf("[MBX HAL Driver USER ERR][%06d] " fmt, __LINE__, ## args)
126 #define MBXHAL_WARN(fmt, args...) printf("[MBX HAL Driver WARN][%06d] " fmt, __LINE__, ## args)
127 #define MBXHAL_PRINT(fmt, args...) printf("[MBX HAL Driver][%06d] " fmt, __LINE__, ## args)
128 #define MBXHAL_ASSERT(_cnd, _fmt, _args...) \
129 if (!(_cnd)) { \
130 MBXHAL_PRINT(_fmt, ##_args); \
131 }
132 #else
133 #define MBXHAL_ERROR(fmt, args...)
134 #define MBXHAL_WARN(fmt, args...)
135 #define MBXHAL_PRINT(fmt, args...)
136 #define MBXHAL_ASSERT(_cnd, _fmt, _args...)
137 #endif
138 //=============================================================================
139 // Macros
140 //=============================================================================
141
142 //=============================================================================
143 // Local Variables
144 //=============================================================================
145 #if 1//frcr2_integration###
146 static MS_U32 _u16MbxGroupIdMBXHAL[E_MBX_ROLE_MAX][E_MBX_ROLE_MAX] = {
147 #if defined (CONFIG_MBX_GROUP_PATCH)
148 {0xFF , REG_MBX_GROUP0, REG_MBX_GROUP4, REG_MBX_GROUP0, REG_MBX_GROUP6, REG_MBX_GROUP4},
149 {REG_MBX_GROUP1, 0xFF, REG_MBX_GROUP3, 0xFF, 0xFF, 0xFF},
150 {REG_MBX_GROUP3, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
151 {0xFF , 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
152 {REG_MBX_GROUP7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
153 {REG_MBX_GROUP1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
154 #else
155 {0xFF , REG_MBX_GROUP0, REG_MBX_GROUP4, REG_MBX_GROUP0, REG_MBX_GROUP6},
156 {REG_MBX_GROUP1, 0xFF, REG_MBX_GROUP3, 0xFF, 0xFF},
157 {REG_MBX_GROUP3, 0xFF, 0xFF, 0xFF, 0xFF},
158 {0xFF , 0xFF, 0xFF, 0xFF, 0xFF},
159 {REG_MBX_GROUP7, 0xFF, 0xFF, 0xFF, 0xFF},
160 #endif
161 };
162 #endif
163 static MS_VIRT _virtRIUBaseAddrMBX = 0;
164 //=============================================================================
165 // Global Variables
166 //=============================================================================
167
168 //=============================================================================
169 // Local Function Prototypes
170 //=============================================================================
171 static void _MHAL_MBX_FireMsg (MBX_Msg* pMbxMsg, MBX_ROLE_ID eSrcRole);
172 static void _MHAL_MBX_RecvMsg(MBX_Msg* pMbxMsg, MBX_ROLE_ID eDstRole);
173
174 //=============================================================================
175 // Local Function
176 //=============================================================================
177 //-------------------------------------------------------------------------------------------------
178 /// Fire Msg to MailBox hardware.
179 /// @param eSrcCPUID \b IN: The Firer CPUID
180 /// @return void
181 /// @attention
182 /// <b>[MXLIB] <em> </em></b>
183 //-------------------------------------------------------------------------------------------------
_MHAL_MBX_FireMsg(MBX_Msg * pMbxMsg,MBX_ROLE_ID eSrcRole)184 void _MHAL_MBX_FireMsg (MBX_Msg* pMbxMsg, MBX_ROLE_ID eSrcRole)
185 {
186 MS_S32 s32Idx;
187
188 /* fill mail box register. */
189 //REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eSrcCPUID], REG8_MBX_CTRL) = pMbxMsg->u8Ctrl;
190 REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID], REG8_MBX_MAIL_CLASS) = pMbxMsg->u8MsgClass;
191 REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID], REG8_MBX_MAIL_IDX) = pMbxMsg->u8Index;
192 REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID], REG8_MBX_PARAMETER_CNT) = pMbxMsg->u8ParameterCount;
193
194 for(s32Idx=0; s32Idx<pMbxMsg->u8ParameterCount; s32Idx++)
195 {
196 REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID], s32Idx+REG8_MBX_PARAMETER_S) = pMbxMsg->u8Parameters[s32Idx];
197 }
198
199 //REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eSrcCPUID], REG8_MBX_STATE_0) = pMbxMsg->u8S0;
200 //REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eSrcCPUID], REG8_MBX_STATE_1) = pMbxMsg->u8S1;
201 }
202
203 //-------------------------------------------------------------------------------------------------
204 /// Recv Msg From MailBox hardware.
205 /// @param pMbxMsg \b INOUT: The Recv CPUID, and where mail to put
206 /// @return void
207 /// @attention
208 /// <b>[MXLIB] <em> </em></b>
209 //-------------------------------------------------------------------------------------------------
_MHAL_MBX_RecvMsg(MBX_Msg * pMbxMsg,MBX_ROLE_ID eDstRole)210 void _MHAL_MBX_RecvMsg(MBX_Msg* pMbxMsg, MBX_ROLE_ID eDstRole)
211 {
212 MS_S32 s32Idx;
213
214 pMbxMsg->u8Ctrl = REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole], REG8_MBX_CTRL);
215 pMbxMsg->u8MsgClass = REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole], REG8_MBX_MAIL_CLASS);
216 pMbxMsg->u8Index = REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole], REG8_MBX_MAIL_IDX);
217 pMbxMsg->u8ParameterCount = REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole], REG8_MBX_PARAMETER_CNT);
218
219 for(s32Idx=0; s32Idx<10; s32Idx++)
220 {
221 pMbxMsg->u8Parameters[s32Idx] = REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole], s32Idx+REG8_MBX_PARAMETER_S);
222 }
223
224 pMbxMsg->u8S0 = REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole], REG8_MBX_STATE_0);
225 pMbxMsg->u8S1 = REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole], REG8_MBX_STATE_1);
226 }
227
228 //=============================================================================
229 // Mailbox HAL Driver Function
230 //=============================================================================
231
232 //-------------------------------------------------------------------------------------------------
233 /// Init MailBox hardware.
234 /// @param eHostRole \b IN: The host Role ID
235 /// @param u32RIUBaseAddrMBX \b IN: The RIU Base Addr.
236 /// @return E_MBX_SUCCESS: success
237 /// @attention
238 /// <b>[MXLIB] <em> </em></b>
239 //-------------------------------------------------------------------------------------------------
MHAL_MBX_Init(MBX_ROLE_ID eHostRole,MS_VIRT virtRIUBaseAddrMBX)240 MBX_Result MHAL_MBX_Init(MBX_ROLE_ID eHostRole, MS_VIRT virtRIUBaseAddrMBX)
241 {
242 _virtRIUBaseAddrMBX = virtRIUBaseAddrMBX;
243
244 return MHAL_MBX_SetConfig(eHostRole);
245 }
246
247 //-------------------------------------------------------------------------------------------------
248 /// Set MailBox Group Regs.
249 /// @param eHostRole \b IN: The host Role ID
250 /// @return E_MBX_SUCCESS: success
251 /// @attention
252 /// <b>[MXLIB] <em>Can't be called Before MHAL_MBX_Init </em></b>
253 //-------------------------------------------------------------------------------------------------
MHAL_MBX_SetConfig(MBX_ROLE_ID eHostRole)254 MBX_Result MHAL_MBX_SetConfig(MBX_ROLE_ID eHostRole)
255 {
256 MS_S32 s32MailIdx;
257
258 /* clear host mail box register. */
259 if(E_MBX_ROLE_HK == eHostRole) //It is HouseKeeping
260 {
261 for(s32MailIdx=0; s32MailIdx<16; s32MailIdx++)
262 {
263 REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[E_MBX_ROLE_HK][E_MBX_ROLE_CP], s32MailIdx) = 0x00;
264 REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[E_MBX_ROLE_HK][E_MBX_ROLE_PM], s32MailIdx) = 0x00;
265 REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[E_MBX_ROLE_HK][E_MBX_ROLE_FRC], s32MailIdx) = 0x00;//frcr2_integration###
266 }
267 }
268 else
269 {
270 for(s32MailIdx=0; s32MailIdx<16; s32MailIdx++)
271 {
272 REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eHostRole][E_MBX_ROLE_HK], s32MailIdx) = 0x00;
273 }
274 }
275
276 return E_MBX_SUCCESS;
277 }
278
279 //-------------------------------------------------------------------------------------------------
280 /// Set Information to dedicated Mailbox HW Regs.
281 /// @param eTargetRole \b IN: The correpsonded Role ID for which MBX HW Group will be used for Set
282 /// @param pU8Info \b IN: The Information which need to set
283 /// @param u8Size \b IN: The Size(bytes) of pU8Info
284 /// @return E_MBX_SUCCESS
285 /// @return E_MBX_UNKNOW_ERROR
286 /// @attention
287 /// <b>[MXLIB] <em>It is used for speciall need when Init-Coprocesser</em></b>
288 //-------------------------------------------------------------------------------------------------
MHAL_MBX_SetInformation(MBX_ROLE_ID eTargetRole,MS_VIRT virtRIUBaseAddrMBX,MS_U8 * pU8Info,MS_U8 u8Size)289 MBX_Result MHAL_MBX_SetInformation(MBX_ROLE_ID eTargetRole, MS_VIRT virtRIUBaseAddrMBX, MS_U8 *pU8Info, MS_U8 u8Size)
290 {
291 MS_S32 s32Idx;
292
293 _virtRIUBaseAddrMBX = virtRIUBaseAddrMBX;
294
295 REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 0+REG8_MBX_PARAMETER_S) = 0x00;
296 REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 1+REG8_MBX_PARAMETER_S) = 0x00;
297
298 for(s32Idx=0; s32Idx<u8Size; s32Idx++)
299 {
300 REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], s32Idx+2+REG8_MBX_PARAMETER_S) = pU8Info[s32Idx];
301 }
302
303 REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 0+REG8_MBX_PARAMETER_S) = 0x78;
304 REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 1+REG8_MBX_PARAMETER_S) = 0x56;
305
306 while((REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 0+REG8_MBX_PARAMETER_S) == 0x78)
307 && (REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 1+REG8_MBX_PARAMETER_S) == 0x56));
308
309 return E_MBX_SUCCESS;
310 }
311
312 //-------------------------------------------------------------------------------------------------
313 /// Get Information from dedicated Mailbox HW Regs.
314 /// @param eTargetRole \b IN: The correpsonded Role ID for which MBX HW Group will be used for Get
315 /// @param pU8Info \b OUT: The Information Where we get to put
316 /// @param u8Size \b IN: The Size(bytes) need to get
317 /// @return E_MBX_SUCCESS
318 /// @return E_MBX_UNKNOW_ERROR
319 /// @attention
320 /// <b>[MXLIB] <em>It is used for speciall need when Init-Coprocesser.</em></b>
321 //-------------------------------------------------------------------------------------------------
MHAL_MBX_GetInformation(MBX_ROLE_ID eTargetRole,MS_VIRT virtRIUBaseAddrMBX,MS_U8 * pU8Info,MS_U8 u8Size)322 MBX_Result MHAL_MBX_GetInformation(MBX_ROLE_ID eTargetRole, MS_VIRT virtRIUBaseAddrMBX, MS_U8 *pU8Info, MS_U8 u8Size)
323 {
324 MS_S32 s32Idx;
325
326 _virtRIUBaseAddrMBX = virtRIUBaseAddrMBX;
327
328 while((REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 0+REG8_MBX_PARAMETER_S) != 0x78)
329 || (REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 1+REG8_MBX_PARAMETER_S) != 0x56));
330
331 for(s32Idx=0; s32Idx<u8Size; s32Idx++)
332 {
333 pU8Info[s32Idx] = REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], s32Idx+2+REG8_MBX_PARAMETER_S);
334 }
335
336 REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 0+REG8_MBX_PARAMETER_S) = 0x00;
337 REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 1+REG8_MBX_PARAMETER_S) = 0x00;
338
339 return E_MBX_SUCCESS;
340 }
341
MHAL_MBX_ClearAll(MBX_Msg * pMbxMsg,MBX_ROLE_ID eSrcRole)342 MBX_Result MHAL_MBX_ClearAll (MBX_Msg* pMbxMsg, MBX_ROLE_ID eSrcRole)
343 {
344 MS_U8 index = 0;
345 for (index = 0; index < 16; index++)
346 REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID], index) = 0x00;
347
348 return E_MBX_SUCCESS;
349
350
351 }
352
353 //-------------------------------------------------------------------------------------------------
354 /// Fire Mail to MailBox hardware.
355 /// @param eSrcCPUID \b IN: The Firer CPUID
356 /// @return E_MBX_ERR_PEER_CPU_NOTREADY: THE Peer CPU in fetching the msg
357 /// @return E_MBX_ERR_PEER_CPU_NOT_ALIVE: The Peer CPU Looks like not alive
358 /// @return E_MBX_SUCCESS: success
359 /// @attention
360 /// <b>[MXLIB] <em> </em></b>
361 //-------------------------------------------------------------------------------------------------
MHAL_MBX_Fire(MBX_Msg * pMbxMsg,MBX_ROLE_ID eSrcRole)362 MBX_Result MHAL_MBX_Fire (MBX_Msg* pMbxMsg, MBX_ROLE_ID eSrcRole)
363 {
364 MS_BOOL bIPState;
365
366 /* check paramter. */
367 if(0xFF == _u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID])
368 {
369 return E_MBX_ERR_INVALID_PARAM;
370 }
371
372 /* check send bit in CONTROL register. */
373 bIPState = _FIRE(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID]);
374
375 if(bIPState > 0)
376 {
377 bIPState = _BUSY(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID]);
378 if(bIPState > 0)
379 {//the mail is in process
380 MBXHAL_ERROR("[Fire Mail Fail] : co-processor is not ready!\n");
381 return E_MBX_ERR_PEER_CPU_NOTREADY;
382 }
383 else
384 {//mail not processed yet!
385 MBXHAL_ERROR("[Fire Mail Fail] : co-processor is not alive!\n");
386 return E_MBX_ERR_PEER_CPU_NOT_ALIVE;
387 }
388 }
389
390 /* clear status1 register. */
391 _S1_C(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID]);
392 // Clear Instant Setting:
393 _INSTANT_C(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID]);
394
395 /* fill mail box register. */
396 _MHAL_MBX_FireMsg(pMbxMsg, eSrcRole);
397
398 /* set instant message attribute */
399 if(pMbxMsg->eMsgType == E_MBX_MSG_TYPE_INSTANT)
400 {
401 _INSTANT_S(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID]);
402 }
403
404 _FIRE_S(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID]);
405
406 return E_MBX_SUCCESS;
407 }
408
409 //-------------------------------------------------------------------------------------------------
410 /// Get HW Fire Status
411 /// @param eSrcRole \b IN: The Firer Src Role
412 /// @param eDstRole \b IN: The Firer Dst Role
413 /// @param pFireStatus \b OUT: THE Fire Status
414 /// @return E_MBX_ERR_INVALID_PARAM
415 /// @return E_MBX_SUCCESS
416 /// @attention
417 /// <b>[MXLIB] <em> </em></b>
418 //-------------------------------------------------------------------------------------------------
MHAL_MBX_GetFireStatus(MBX_ROLE_ID eSrcRole,MBX_ROLE_ID eDstRole,MBXHAL_Fire_Status * pFireStatus)419 MBX_Result MHAL_MBX_GetFireStatus(MBX_ROLE_ID eSrcRole, MBX_ROLE_ID eDstRole, MBXHAL_Fire_Status *pFireStatus)
420 {
421 /* check paramter. */
422 if((0xFF == _u16MbxGroupIdMBXHAL[eSrcRole][eDstRole])
423 || (NULL == pFireStatus))
424 {
425 return E_MBX_ERR_INVALID_PARAM;
426 }
427
428 //still on Firing:
429 if(_FIRE(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]))
430 {
431 *pFireStatus = E_MBXHAL_FIRE_ONGOING;
432 }
433 else if(_OVERFLOW(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]))
434 { //If Overflow:
435 *pFireStatus = E_MBXHAL_FIRE_OVERFLOW;
436 }
437 else if(_DISABLED(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]))
438 { //If Disabled:
439 *pFireStatus = E_MBXHAL_FIRE_DISABLED;
440 }
441 else
442 {
443 *pFireStatus = E_MBXHAL_FIRE_SUCCESS;
444 }
445
446 return E_MBX_SUCCESS;
447 }
448
449 //-------------------------------------------------------------------------------------------------
450 /// Recv Mail From MailBox hardware.
451 /// @param pMbxMsg \b INOUT: The Recv Src RoleID, and where mail to put
452 /// @param eDstRole \b IN: The Recv Dst RoleID
453 /// @return E_MBX_ERR_MSG_ALREADY_FETCHED: THE Msg has been fetched
454 /// @return E_MBX_ERR_INVALID_PARAM: THE Input Src Role & Dst Role is incorrect
455 /// @return E_MBX_SUCCESS: success
456 /// @attention
457 /// <b>[MXLIB] <em> </em></b>
458 //-------------------------------------------------------------------------------------------------
MHAL_MBX_Recv(MBX_Msg * pMbxMsg,MBX_ROLE_ID eDstRole)459 MBX_Result MHAL_MBX_Recv(MBX_Msg* pMbxMsg, MBX_ROLE_ID eDstRole)
460 {
461 MS_BOOL bIPState;
462
463 /* check paramter. */
464 if(0xFF == _u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole])
465 {
466 return E_MBX_ERR_INVALID_PARAM;
467 }
468
469 /* check send bit in CONTROL register. */
470 bIPState = _FIRE(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole]);
471 if(bIPState <= 0) //the message already fetched!
472 return E_MBX_ERR_MSG_ALREADY_FETCHED;
473
474 /* set busy bit */
475 _BUSY_S(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole]);
476
477 bIPState = _INSTANT(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole]) | _READBACK(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole]);
478 if(bIPState)
479 pMbxMsg->eMsgType= E_MBX_MSG_TYPE_INSTANT;
480 else
481 pMbxMsg->eMsgType= E_MBX_MSG_TYPE_NORMAL;
482
483 /* recv mail msg */
484 _MHAL_MBX_RecvMsg(pMbxMsg, eDstRole);
485
486 /* clear busy bit */
487 //_BUSY_C(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole]);
488 /* clear send bit */
489 //_FIRE_C(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole]);
490
491 return E_MBX_SUCCESS;
492 }
493
494 //-------------------------------------------------------------------------------------------------
495 /// End Recv Mail From MailBox hardware. Set Status for FeedBack
496 /// @param eSrcRole \b IN: The Recv Src RoleID
497 /// @param eDstRole \b IN: The Recv Dst RoleID
498 /// @param eRecvSatus \b IN: The Recv Status
499 /// @return E_MBX_ERR_INVALID_PARAM: THE Input Src Role & Dst Role is incorrect
500 /// @return E_MBX_SUCCESS: success
501 /// @attention
502 /// <b>[MXLIB] <em> </em></b>
503 //-------------------------------------------------------------------------------------------------
MHAL_MBX_RecvEnd(MBX_ROLE_ID eSrcRole,MBX_ROLE_ID eDstRole,MBXHAL_Recv_Status eRecvSatus)504 MBX_Result MHAL_MBX_RecvEnd(MBX_ROLE_ID eSrcRole, MBX_ROLE_ID eDstRole, MBXHAL_Recv_Status eRecvSatus)
505 {
506 /* check paramter. */
507 if(0xFF == _u16MbxGroupIdMBXHAL[eSrcRole][eDstRole])
508 {
509 return E_MBX_ERR_INVALID_PARAM;
510 }
511
512 switch(eRecvSatus)
513 {
514 case E_MBXHAL_RECV_OVERFLOW:
515 //Set OverFlow & Error:
516 _OVERFLOW_S(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]);
517 _ERR_S(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]);
518 break;
519 case E_MBXHAL_RECV_DISABLED:
520 //Set Disable & Error:
521 _DISABLED_S(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]);
522 _ERR_S(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]);
523 break;
524 default:
525 break;
526 }
527
528 /* clear busy bit */
529 _BUSY_C(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]);
530 /* clear send bit */
531 _FIRE_C(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]);
532
533 return E_MBX_SUCCESS;
534 }
535
536