xref: /utopia/UTPA2-700.0.x/modules/mbx/hal/k6lite/mbx/halMBX.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
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 static MS_U16 _u16MbxGroupIdMBXHAL[E_MBX_ROLE_MAX][E_MBX_ROLE_MAX] =
146                                         { {0xFF, REG_MBX_GROUP0, REG_MBX_GROUP4}, {REG_MBX_GROUP1, 0xFF, REG_MBX_GROUP3}, {REG_MBX_GROUP3, 0xFF, 0xFF} };
147 static MS_VIRT _virtRIUBaseAddrMBX = 0;
148 //=============================================================================
149 // Global Variables
150 //=============================================================================
151 
152 //=============================================================================
153 // Local Function Prototypes
154 //=============================================================================
155 static void _MHAL_MBX_FireMsg (MBX_Msg* pMbxMsg, MBX_ROLE_ID eSrcRole);
156 static void _MHAL_MBX_RecvMsg(MBX_Msg* pMbxMsg, MBX_ROLE_ID eDstRole);
157 
158 //=============================================================================
159 // Local Function
160 //=============================================================================
161 //-------------------------------------------------------------------------------------------------
162 /// Fire Msg to MailBox hardware.
163 /// @param  eSrcCPUID                  \b IN: The Firer CPUID
164 /// @return void
165 /// @attention
166 /// <b>[MXLIB] <em> </em></b>
167 //-------------------------------------------------------------------------------------------------
_MHAL_MBX_FireMsg(MBX_Msg * pMbxMsg,MBX_ROLE_ID eSrcRole)168 void _MHAL_MBX_FireMsg (MBX_Msg* pMbxMsg, MBX_ROLE_ID eSrcRole)
169 {
170     MS_S32 s32Idx;
171 
172     /* fill mail box register. */
173     //REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eSrcCPUID], REG8_MBX_CTRL) = pMbxMsg->u8Ctrl;
174     REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID], REG8_MBX_MAIL_CLASS) = pMbxMsg->u8MsgClass;
175     REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID], REG8_MBX_MAIL_IDX) = pMbxMsg->u8Index;
176     REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID], REG8_MBX_PARAMETER_CNT) = pMbxMsg->u8ParameterCount;
177 
178     for(s32Idx=0;  s32Idx<pMbxMsg->u8ParameterCount; s32Idx++)
179     {
180         REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID], s32Idx+REG8_MBX_PARAMETER_S) = pMbxMsg->u8Parameters[s32Idx];
181     }
182 
183     //REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eSrcCPUID], REG8_MBX_STATE_0) = pMbxMsg->u8S0;
184     //REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eSrcCPUID], REG8_MBX_STATE_1) = pMbxMsg->u8S1;
185 }
186 
187 //-------------------------------------------------------------------------------------------------
188 /// Recv Msg From MailBox hardware.
189 /// @param  pMbxMsg                  \b INOUT: The Recv CPUID, and where mail to put
190 /// @return void
191 /// @attention
192 /// <b>[MXLIB] <em> </em></b>
193 //-------------------------------------------------------------------------------------------------
_MHAL_MBX_RecvMsg(MBX_Msg * pMbxMsg,MBX_ROLE_ID eDstRole)194 void _MHAL_MBX_RecvMsg(MBX_Msg* pMbxMsg, MBX_ROLE_ID eDstRole)
195 {
196     MS_S32 s32Idx;
197 
198     pMbxMsg->u8Ctrl = REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole], REG8_MBX_CTRL);
199     pMbxMsg->u8MsgClass = REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole], REG8_MBX_MAIL_CLASS);
200     pMbxMsg->u8Index = REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole], REG8_MBX_MAIL_IDX);
201     pMbxMsg->u8ParameterCount = REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole], REG8_MBX_PARAMETER_CNT);
202 
203     for(s32Idx=0;  s32Idx<10; s32Idx++)
204     {
205         pMbxMsg->u8Parameters[s32Idx] = REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole], s32Idx+REG8_MBX_PARAMETER_S);
206     }
207 
208     pMbxMsg->u8S0 = REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole], REG8_MBX_STATE_0);
209     pMbxMsg->u8S1 = REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole], REG8_MBX_STATE_1);
210 }
211 
212 //=============================================================================
213 // Mailbox HAL Driver Function
214 //=============================================================================
215 
216 //-------------------------------------------------------------------------------------------------
217 /// Init MailBox hardware.
218 /// @param  eHostRole                  \b IN: The host Role ID
219 /// @param  u32RIUBaseAddrMBX                  \b IN: The RIU Base Addr.
220 /// @return E_MBX_SUCCESS: success
221 /// @attention
222 /// <b>[MXLIB] <em> </em></b>
223 //-------------------------------------------------------------------------------------------------
MHAL_MBX_Init(MBX_ROLE_ID eHostRole,MS_VIRT virtRIUBaseAddrMBX)224 MBX_Result MHAL_MBX_Init(MBX_ROLE_ID eHostRole, MS_VIRT virtRIUBaseAddrMBX)
225 {
226     _virtRIUBaseAddrMBX = virtRIUBaseAddrMBX;
227 
228     return MHAL_MBX_SetConfig(eHostRole);
229 }
230 
231 //-------------------------------------------------------------------------------------------------
232 /// Set MailBox Group Regs.
233 /// @param  eHostRole                  \b IN: The host Role ID
234 /// @return E_MBX_SUCCESS: success
235 /// @attention
236 /// <b>[MXLIB] <em>Can't be called Before MHAL_MBX_Init </em></b>
237 //-------------------------------------------------------------------------------------------------
MHAL_MBX_SetConfig(MBX_ROLE_ID eHostRole)238 MBX_Result MHAL_MBX_SetConfig(MBX_ROLE_ID eHostRole)
239 {
240     MS_S32 s32MailIdx;
241 
242     /* clear host mail box register. */
243     if(E_MBX_ROLE_HK == eHostRole) //It is HouseKeeping
244     {
245         for(s32MailIdx=0; s32MailIdx<16; s32MailIdx++)
246         {
247             REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[E_MBX_ROLE_HK][E_MBX_ROLE_CP], s32MailIdx) = 0x00;
248             REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[E_MBX_ROLE_HK][E_MBX_ROLE_PM], s32MailIdx) = 0x00;
249         }
250     }
251     else
252     {
253         for(s32MailIdx=0; s32MailIdx<16; s32MailIdx++)
254         {
255             REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eHostRole][E_MBX_ROLE_HK], s32MailIdx) = 0x00;
256         }
257     }
258 
259     return E_MBX_SUCCESS;
260 }
261 
262 //-------------------------------------------------------------------------------------------------
263 /// Set Information to dedicated Mailbox HW Regs.
264 /// @param  eTargetRole \b IN: The correpsonded Role ID for which MBX HW Group will be used for Set
265 /// @param  pU8Info \b IN: The Information which need to set
266 /// @param  u8Size \b IN: The Size(bytes) of pU8Info
267 /// @return E_MBX_SUCCESS
268 /// @return E_MBX_UNKNOW_ERROR
269 /// @attention
270 /// <b>[MXLIB] <em>It is used for speciall need when Init-Coprocesser</em></b>
271 //-------------------------------------------------------------------------------------------------
MHAL_MBX_SetInformation(MBX_ROLE_ID eTargetRole,MS_VIRT virtRIUBaseAddrMBX,MS_U8 * pU8Info,MS_U8 u8Size)272 MBX_Result  MHAL_MBX_SetInformation(MBX_ROLE_ID eTargetRole, MS_VIRT virtRIUBaseAddrMBX, MS_U8 *pU8Info, MS_U8 u8Size)
273 {
274     MS_S32 s32Idx;
275 
276     _virtRIUBaseAddrMBX = virtRIUBaseAddrMBX;
277 
278     REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 0+REG8_MBX_PARAMETER_S) = 0x00;
279     REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 1+REG8_MBX_PARAMETER_S) = 0x00;
280 
281     for(s32Idx=0; s32Idx<u8Size; s32Idx++)
282     {
283         REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], s32Idx+2+REG8_MBX_PARAMETER_S) = pU8Info[s32Idx];
284     }
285 
286     REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 0+REG8_MBX_PARAMETER_S) = 0x78;
287     REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 1+REG8_MBX_PARAMETER_S) = 0x56;
288 
289     while((REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 0+REG8_MBX_PARAMETER_S) == 0x78)
290             && (REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 1+REG8_MBX_PARAMETER_S) == 0x56));
291 
292     return E_MBX_SUCCESS;
293 }
294 
295 //-------------------------------------------------------------------------------------------------
296 /// Get Information from dedicated Mailbox HW Regs.
297 /// @param  eTargetRole \b IN: The correpsonded Role ID for which MBX HW Group will be used for Get
298 /// @param  pU8Info \b OUT: The Information Where we get to put
299 /// @param  u8Size \b IN: The Size(bytes) need to get
300 /// @return E_MBX_SUCCESS
301 /// @return E_MBX_UNKNOW_ERROR
302 /// @attention
303 /// <b>[MXLIB] <em>It is used for speciall need when Init-Coprocesser.</em></b>
304 //-------------------------------------------------------------------------------------------------
MHAL_MBX_GetInformation(MBX_ROLE_ID eTargetRole,MS_VIRT virtRIUBaseAddrMBX,MS_U8 * pU8Info,MS_U8 u8Size)305 MBX_Result  MHAL_MBX_GetInformation(MBX_ROLE_ID eTargetRole, MS_VIRT virtRIUBaseAddrMBX, MS_U8 *pU8Info, MS_U8 u8Size)
306 {
307     MS_S32 s32Idx;
308 
309     _virtRIUBaseAddrMBX = virtRIUBaseAddrMBX;
310 
311     while((REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 0+REG8_MBX_PARAMETER_S) != 0x78)
312             || (REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 1+REG8_MBX_PARAMETER_S) != 0x56));
313 
314     for(s32Idx=0; s32Idx<u8Size; s32Idx++)
315     {
316         pU8Info[s32Idx] = REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], s32Idx+2+REG8_MBX_PARAMETER_S);
317     }
318 
319     REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 0+REG8_MBX_PARAMETER_S) = 0x00;
320     REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eTargetRole][E_MBX_ROLE_HK], 1+REG8_MBX_PARAMETER_S) = 0x00;
321 
322     return E_MBX_SUCCESS;
323 }
324 
MHAL_MBX_ClearAll(MBX_Msg * pMbxMsg,MBX_ROLE_ID eSrcRole)325 MBX_Result MHAL_MBX_ClearAll (MBX_Msg* pMbxMsg, MBX_ROLE_ID eSrcRole)
326 {
327 	MS_U8 index = 0;
328 	for (index = 0; index < 16; index++)
329 		REG8_MBX_GROUP(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID], index) = 0x00;
330 
331 	return E_MBX_SUCCESS;
332 
333 
334 }
335 
336 //-------------------------------------------------------------------------------------------------
337 /// Fire Mail to MailBox hardware.
338 /// @param  eSrcCPUID                  \b IN: The Firer CPUID
339 /// @return E_MBX_ERR_PEER_CPU_NOTREADY: THE Peer CPU in fetching the msg
340 /// @return E_MBX_ERR_PEER_CPU_NOT_ALIVE: The Peer CPU Looks like not alive
341 /// @return E_MBX_SUCCESS: success
342 /// @attention
343 /// <b>[MXLIB] <em> </em></b>
344 //-------------------------------------------------------------------------------------------------
MHAL_MBX_Fire(MBX_Msg * pMbxMsg,MBX_ROLE_ID eSrcRole)345 MBX_Result MHAL_MBX_Fire (MBX_Msg* pMbxMsg, MBX_ROLE_ID eSrcRole)
346 {
347     MS_BOOL bIPState;
348 
349     /* check paramter. */
350     if(0xFF == _u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID])
351     {
352         return E_MBX_ERR_INVALID_PARAM;
353     }
354 
355     /* check send bit in CONTROL register. */
356     bIPState = _FIRE(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID]);
357 
358     if(bIPState > 0)
359     {
360         bIPState = _BUSY(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID]);
361         if(bIPState > 0)
362         {//the mail is in process
363             MBXHAL_ERROR("[Fire Mail Fail] : co-processor is not ready!\n");
364             return  E_MBX_ERR_PEER_CPU_NOTREADY;
365         }
366         else
367         {//mail not processed yet!
368             MBXHAL_ERROR("[Fire Mail Fail] : co-processor is not alive!\n");
369             return  E_MBX_ERR_PEER_CPU_NOT_ALIVE;
370         }
371     }
372 
373     /* clear status1 register. */
374     _S1_C(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID]);
375     // Clear Instant Setting:
376     _INSTANT_C(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID]);
377 
378     /* fill mail box register. */
379     _MHAL_MBX_FireMsg(pMbxMsg, eSrcRole);
380 
381     /* set instant message attribute */
382     if(pMbxMsg->eMsgType == E_MBX_MSG_TYPE_INSTANT)
383     {
384         _INSTANT_S(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID]);
385     }
386 
387     _FIRE_S(_u16MbxGroupIdMBXHAL[eSrcRole][pMbxMsg->eRoleID]);
388 
389     return E_MBX_SUCCESS;
390 }
391 
392 //-------------------------------------------------------------------------------------------------
393 /// Get HW Fire Status
394 /// @param  eSrcRole                  \b IN: The Firer Src Role
395 /// @param  eDstRole                  \b IN: The Firer Dst Role
396 /// @param  pFireStatus               \b OUT: THE Fire Status
397 /// @return E_MBX_ERR_INVALID_PARAM
398 /// @return E_MBX_SUCCESS
399 /// @attention
400 /// <b>[MXLIB] <em> </em></b>
401 //-------------------------------------------------------------------------------------------------
MHAL_MBX_GetFireStatus(MBX_ROLE_ID eSrcRole,MBX_ROLE_ID eDstRole,MBXHAL_Fire_Status * pFireStatus)402 MBX_Result MHAL_MBX_GetFireStatus(MBX_ROLE_ID eSrcRole, MBX_ROLE_ID eDstRole, MBXHAL_Fire_Status *pFireStatus)
403 {
404     /* check paramter. */
405     if((0xFF == _u16MbxGroupIdMBXHAL[eSrcRole][eDstRole])
406         || (NULL == pFireStatus))
407     {
408         return E_MBX_ERR_INVALID_PARAM;
409     }
410 
411     //still on Firing:
412     if(_FIRE(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]))
413     {
414         *pFireStatus = E_MBXHAL_FIRE_ONGOING;
415     }
416     else if(_OVERFLOW(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]))
417     {    //If Overflow:
418         *pFireStatus = E_MBXHAL_FIRE_OVERFLOW;
419     }
420     else if(_DISABLED(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]))
421     {   //If Disabled:
422         *pFireStatus = E_MBXHAL_FIRE_DISABLED;
423     }
424     else
425     {
426         *pFireStatus = E_MBXHAL_FIRE_SUCCESS;
427     }
428 
429     return E_MBX_SUCCESS;
430 }
431 
432 //-------------------------------------------------------------------------------------------------
433 /// Recv Mail From MailBox hardware.
434 /// @param  pMbxMsg                  \b INOUT: The Recv Src RoleID, and where mail to put
435 /// @param  eDstRole                  \b IN: The Recv Dst RoleID
436 /// @return E_MBX_ERR_MSG_ALREADY_FETCHED: THE Msg has been fetched
437 /// @return E_MBX_ERR_INVALID_PARAM: THE Input Src Role & Dst Role is incorrect
438 /// @return E_MBX_SUCCESS: success
439 /// @attention
440 /// <b>[MXLIB] <em> </em></b>
441 //-------------------------------------------------------------------------------------------------
MHAL_MBX_Recv(MBX_Msg * pMbxMsg,MBX_ROLE_ID eDstRole)442 MBX_Result MHAL_MBX_Recv(MBX_Msg* pMbxMsg, MBX_ROLE_ID eDstRole)
443 {
444     MS_BOOL bIPState;
445 
446     /* check paramter. */
447     if(0xFF == _u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole])
448     {
449         return E_MBX_ERR_INVALID_PARAM;
450     }
451 
452     /* check send bit in CONTROL register. */
453     bIPState = _FIRE(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole]);
454     if(bIPState <= 0) //the message already fetched!
455         return  E_MBX_ERR_MSG_ALREADY_FETCHED;
456 
457     /* set busy bit */
458     _BUSY_S(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole]);
459 
460     bIPState = _INSTANT(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole]) | _READBACK(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole]);
461     if(bIPState)
462         pMbxMsg->eMsgType= E_MBX_MSG_TYPE_INSTANT;
463     else
464         pMbxMsg->eMsgType= E_MBX_MSG_TYPE_NORMAL;
465 
466     /* recv mail msg */
467     _MHAL_MBX_RecvMsg(pMbxMsg, eDstRole);
468 
469     /* clear busy bit */
470     //_BUSY_C(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole]);
471     /* clear send bit */
472     //_FIRE_C(_u16MbxGroupIdMBXHAL[pMbxMsg->eRoleID][eDstRole]);
473 
474     return E_MBX_SUCCESS;
475 }
476 
477 //-------------------------------------------------------------------------------------------------
478 /// End Recv Mail From MailBox hardware. Set Status for FeedBack
479 /// @param  eSrcRole                  \b IN: The Recv Src RoleID
480 /// @param  eDstRole                  \b IN: The Recv Dst RoleID
481 /// @param  eRecvSatus                  \b IN: The Recv Status
482 /// @return E_MBX_ERR_INVALID_PARAM: THE Input Src Role & Dst Role is incorrect
483 /// @return E_MBX_SUCCESS: success
484 /// @attention
485 /// <b>[MXLIB] <em> </em></b>
486 //-------------------------------------------------------------------------------------------------
MHAL_MBX_RecvEnd(MBX_ROLE_ID eSrcRole,MBX_ROLE_ID eDstRole,MBXHAL_Recv_Status eRecvSatus)487 MBX_Result MHAL_MBX_RecvEnd(MBX_ROLE_ID eSrcRole, MBX_ROLE_ID eDstRole, MBXHAL_Recv_Status eRecvSatus)
488 {
489     /* check paramter. */
490     if(0xFF == _u16MbxGroupIdMBXHAL[eSrcRole][eDstRole])
491     {
492         return E_MBX_ERR_INVALID_PARAM;
493     }
494 
495     switch(eRecvSatus)
496     {
497         case E_MBXHAL_RECV_OVERFLOW:
498             //Set OverFlow & Error:
499             _OVERFLOW_S(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]);
500             _ERR_S(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]);
501             break;
502         case E_MBXHAL_RECV_DISABLED:
503             //Set Disable & Error:
504             _DISABLED_S(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]);
505             _ERR_S(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]);
506             break;
507         default:
508             break;
509     }
510 
511     /* clear busy bit */
512     _BUSY_C(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]);
513     /* clear send bit */
514     _FIRE_C(_u16MbxGroupIdMBXHAL[eSrcRole][eDstRole]);
515 
516     return E_MBX_SUCCESS;
517 }
518 
519