1 /*
2  * Copyright 2021-2023 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /**
8 *   @file    Mru_Ip.c
9 *
10 *   @defgroup   MRU_IP_DRIVER Mru Ip Driver
11 *   @ingroup    Platform
12 *
13 *   @addtogroup MRU_IP_DRIVER Mru Ip Driver
14 *   @{
15 */
16 
17 #ifdef __cplusplus
18 extern "C"
19 {
20 #endif
21 
22 /*==================================================================================================
23 *                                        INCLUDE FILES
24 * 1) system and project includes
25 * 2) needed interfaces from external units
26 * 3) internal and external interfaces from this unit
27 ==================================================================================================*/
28 #include "Mcal.h"
29 #include "Mru_Ip.h"
30 #include "OsIf.h"
31 #if (STD_ON == MRU_IP_DEV_ERROR_DETECT)
32     #include "Devassert.h"
33 #endif
34 
35 /*==================================================================================================
36 *                                       SOURCE FILE VERSION INFORMATION
37 ==================================================================================================*/
38 #define CDD_PLATFORM_MRU_IP_VENDOR_ID_C                      43
39 #define CDD_PLATFORM_MRU_IP_AR_RELEASE_MAJOR_VERSION_C       4
40 #define CDD_PLATFORM_MRU_IP_AR_RELEASE_MINOR_VERSION_C       7
41 #define CDD_PLATFORM_MRU_IP_AR_RELEASE_REVISION_VERSION_C    0
42 #define CDD_PLATFORM_MRU_IP_SW_MAJOR_VERSION_C               1
43 #define CDD_PLATFORM_MRU_IP_SW_MINOR_VERSION_C               0
44 #define CDD_PLATFORM_MRU_IP_SW_PATCH_VERSION_C               0
45 /*==================================================================================================
46 *                                     FILE VERSION CHECKS
47 ==================================================================================================*/
48 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
49     /* Check if current file and Mcal header file are of the same Autosar version */
50     #if ((CDD_PLATFORM_MRU_IP_AR_RELEASE_MAJOR_VERSION_C != MCAL_AR_RELEASE_MAJOR_VERSION) || \
51          (CDD_PLATFORM_MRU_IP_AR_RELEASE_MINOR_VERSION_C != MCAL_AR_RELEASE_MINOR_VERSION))
52     #error "AutoSar Version Numbers of Mru_Ip.c and Mcal.h are different"
53     #endif
54 #endif
55 
56 /* Check if Mru_Ip.h and Mru_Ip.c are of the same vendor */
57 #if (CDD_PLATFORM_MRU_IP_VENDOR_ID != CDD_PLATFORM_MRU_IP_VENDOR_ID_C)
58     #error "Mru_Ip.h and Mru_Ip.c have different vendor ids"
59 #endif
60 /* Check if Mru_Ip.h file and Mru_Ip.c file are of the same Autosar version */
61 #if ((CDD_PLATFORM_MRU_IP_AR_RELEASE_MAJOR_VERSION != CDD_PLATFORM_MRU_IP_AR_RELEASE_MAJOR_VERSION_C) || \
62      (CDD_PLATFORM_MRU_IP_AR_RELEASE_MINOR_VERSION != CDD_PLATFORM_MRU_IP_AR_RELEASE_MINOR_VERSION_C) || \
63      (CDD_PLATFORM_MRU_IP_AR_RELEASE_REVISION_VERSION != CDD_PLATFORM_MRU_IP_AR_RELEASE_REVISION_VERSION_C))
64 #error "AutoSar Version Numbers of Mru_Ip.h and Mru_Ip.c are different"
65 #endif
66 #if ((CDD_PLATFORM_MRU_IP_SW_MAJOR_VERSION != CDD_PLATFORM_MRU_IP_SW_MAJOR_VERSION_C) || \
67      (CDD_PLATFORM_MRU_IP_SW_MINOR_VERSION != CDD_PLATFORM_MRU_IP_SW_MINOR_VERSION_C) || \
68      (CDD_PLATFORM_MRU_IP_SW_PATCH_VERSION != CDD_PLATFORM_MRU_IP_SW_PATCH_VERSION_C))
69 #error "Software Version Numbers of Mru_Ip.h and Mru_Ip.c are different"
70 #endif
71 
72 /* Check if OsIf.h and Mru_Ip.c are of the same vendor */
73 #if (OSIF_VENDOR_ID != CDD_PLATFORM_MRU_IP_VENDOR_ID_C)
74     #error "OsIf.h and Mru_Ip.c have different vendor ids"
75 #endif
76 /* Check if OsIf.h file and Mru_Ip.c file are of the same Autosar version */
77 #if ((OSIF_AR_RELEASE_MAJOR_VERSION != CDD_PLATFORM_MRU_IP_AR_RELEASE_MAJOR_VERSION_C) || \
78      (OSIF_AR_RELEASE_MINOR_VERSION != CDD_PLATFORM_MRU_IP_AR_RELEASE_MINOR_VERSION_C) || \
79      (OSIF_AR_RELEASE_REVISION_VERSION != CDD_PLATFORM_MRU_IP_AR_RELEASE_REVISION_VERSION_C))
80 #error "AutoSar Version Numbers of OsIf.h and Mru_Ip.c are different"
81 #endif
82 #if ((OSIF_SW_MAJOR_VERSION != CDD_PLATFORM_MRU_IP_SW_MAJOR_VERSION_C) || \
83      (OSIF_SW_MINOR_VERSION != CDD_PLATFORM_MRU_IP_SW_MINOR_VERSION_C) || \
84      (OSIF_SW_PATCH_VERSION != CDD_PLATFORM_MRU_IP_SW_PATCH_VERSION_C))
85 #error "Software Version Numbers of OsIf.h and Mru_Ip.c are different"
86 #endif
87 
88 /*==================================================================================================
89 *                                       LOCAL FUNCTIONS
90 ==================================================================================================*/
91 #if ((STD_ON == MRU_IP_ENABLE_USER_MODE_SUPPORT) && (defined (MCAL_ENABLE_USER_MODE_SUPPORT)))
92     #define Call_Mru_Ip_Init(pHWUnitConfigPtr) \
93                 OsIf_Trusted_Call1param(Mru_Ip_Init_Privileged,(pHWUnitConfigPtr))
94     #define Call_Mru_Ip_Transmit(pTransmitChCfgPtr,pTxBufferPtr) \
95                 OsIf_Trusted_Call_Return2param(Mru_Ip_Transmit_Privileged,(pTransmitChCfgPtr),(pTxBufferPtr))
96     #define Call_Mru_Ip_ReadMailbox(ReceiveChCfgPtr,RxBufferPtr,Timeout) \
97                 OsIf_Trusted_Call_Return3param(Mru_Ip_ReadMailbox_Privileged,(ReceiveChCfgPtr),(RxBufferPtr),(Timeout))
98     #define Call_Mru_Ip_GetMailboxStatus(ReceiveChCfgPtr) \
99                 OsIf_Trusted_Call_Return1param(Mru_Ip_GetMailboxStatus_Privileged,(ReceiveChCfgPtr))
100 #else /*STD_ON == MRU_IP_ENABLE_USER_MODE_SUPPORT*/
101     #define Call_Mru_Ip_Init(pHWUnitConfigPtr) \
102                 Mru_Ip_Init_Privileged((pHWUnitConfigPtr))
103     #define Call_Mru_Ip_Transmit(pTransmitChCfgPtr,pTxBufferPtr) \
104                 Mru_Ip_Transmit_Privileged((pTransmitChCfgPtr),(pTxBufferPtr))
105     #define Call_Mru_Ip_ReadMailbox(ReceiveChCfgPtr,RxBufferPtr,Timeout) \
106                 Mru_Ip_ReadMailbox_Privileged((ReceiveChCfgPtr),(RxBufferPtr),(Timeout))
107     #define Call_Mru_Ip_GetMailboxStatus(ReceiveChCfgPtr) \
108                 Mru_Ip_GetMailboxStatus_Privileged((ReceiveChCfgPtr))
109 #endif /*STD_ON == MRU_IP_ENABLE_USER_MODE_SUPPORT*/
110 /*==================================================================================================
111 *                          LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
112 ==================================================================================================*/
113 
114 /*==================================================================================================
115 *                                       LOCAL MACROS
116 ==================================================================================================*/
117 
118 /*==================================================================================================
119 *                                       LOCAL CONSTANTS
120 ==================================================================================================*/
121 
122 /*==================================================================================================
123 *                                       LOCAL VARIABLES
124 ==================================================================================================*/
125 
126 /*==================================================================================================
127 *                                      GLOBAL CONSTANTS
128 ==================================================================================================*/
129 
130 /*==================================================================================================
131                                        GLOBAL VARIABLES
132 ==================================================================================================*/
133 
134 #define PLATFORM_START_SEC_VAR_CLEARED_UNSPECIFIED
135 #include "Platform_MemMap.h"
136 
137 Mru_Ip_StateStructureType Mru_Ip_axStateStructure[MRU_IP_NUMBER_OF_INSTANCES];
138 
139 Mru_Ip_StateStructureType* Mru_Ip_apxStateStructureArray[MRU_IP_NUMBER_OF_INSTANCES];
140 
141 #define PLATFORM_STOP_SEC_VAR_CLEARED_UNSPECIFIED
142 #include "Platform_MemMap.h"
143 /*==================================================================================================
144 *                                  LOCAL FUNCTION PROTOTYPES
145 ==================================================================================================*/
146 #define PLATFORM_START_SEC_CODE
147 #include "Platform_MemMap.h"
148 
149 /*==================================================================================================
150 *                                      LOCAL FUNCTIONS
151 ==================================================================================================*/
152 static void Mru_Ip_IrqHandlerReceiveMb(const Mru_Ip_ChannelCfgType * ChannelConfig, uint8 IntGroupId);
153 void Mru_Ip_Init_Privileged(const Mru_Ip_ConfigType *HWUnitConfigPtr);
154 Mru_Ip_StatusType Mru_Ip_Transmit_Privileged( const Mru_Ip_TransmitChannelType *TransmitChCfgPtr,
155                                               const uint32 *TxBufferPtr
156                                             );
157 Mru_Ip_StatusType Mru_Ip_ReadMailbox_Privileged( const Mru_Ip_ReceiveChannelType *ReceiveChCfgPtr,
158                                                  uint32 *RxBufferPtr,
159                                                  uint32 Timeout
160                                                );
161 Mru_Ip_MBStatusType Mru_Ip_GetMailboxStatus_Privileged( const Mru_Ip_ReceiveChannelType *ReceiveChCfgPtr );
162 /*================================================================================================*/
Mru_Ip_Init_Privileged(const Mru_Ip_ConfigType * HWUnitConfigPtr)163 void Mru_Ip_Init_Privileged(const Mru_Ip_ConfigType *HWUnitConfigPtr)
164 {
165     Mru_Ip_StateStructureType* State;
166     uint8 InstanceId = 0u;
167     uint8 CfgIndex = 0u;
168 
169 #if (MRU_IP_DEV_ERROR_DETECT == STD_ON)
170     DevAssert(NULL_PTR != HWUnitConfigPtr);
171 #endif
172     InstanceId = HWUnitConfigPtr->InstanceId;
173     State = Mru_Ip_apxStateStructureArray[InstanceId];
174 #if (MRU_IP_DEV_ERROR_DETECT == STD_ON)
175     DevAssert(NULL_PTR == State);
176 #endif
177     Mru_Ip_apxStateStructureArray[InstanceId] = &Mru_Ip_axStateStructure[HWUnitConfigPtr->StateIndex];
178     State = Mru_Ip_apxStateStructureArray[InstanceId];
179     State->HWUnitConfig = HWUnitConfigPtr;
180 
181     for(CfgIndex = 0u; CfgIndex < HWUnitConfigPtr->NumChannel; CfgIndex++)
182     {
183         if(NULL_PTR != HWUnitConfigPtr->ChannelCfg[CfgIndex].MBLinkReceiveChCfg)
184         {
185             /* Enables the channel configuration before writing to registers */
186             *HWUnitConfigPtr->ChannelCfg[CfgIndex].ChCFG0Add = MRU_IP_CH_CFG0_CHE_MASK;
187             /* Update channel CFG1 */
188             *HWUnitConfigPtr->ChannelCfg[CfgIndex].ChCFG1Add = HWUnitConfigPtr->ChannelCfg[CfgIndex].ChCFG1;
189             /* Update channel CFG0 */
190             *HWUnitConfigPtr->ChannelCfg[CfgIndex].ChCFG0Add = HWUnitConfigPtr->ChannelCfg[CfgIndex].ChCFG0 | MRU_IP_CH_CFG0_CHE_MASK;
191         }
192     }
193 }
194 /*================================================================================================*/
Mru_Ip_Transmit_Privileged(const Mru_Ip_TransmitChannelType * TransmitChCfgPtr,const uint32 * TxBufferPtr)195 Mru_Ip_StatusType Mru_Ip_Transmit_Privileged( const Mru_Ip_TransmitChannelType *TransmitChCfgPtr,
196                       const uint32 *TxBufferPtr
197                     )
198 {
199     uint8 BufferIndex = 0u;
200     Mru_Ip_StatusType Status = MRU_IP_STATUS_SUCCESS;
201     uint32 LastMbStatus = (*(TransmitChCfgPtr->ChMBSTATAdd)>> (TransmitChCfgPtr->LastTxMBIndex)) & MRU_IP_CH_MBSTAT_MBS0_MASK;
202 
203 #if (MRU_IP_DEV_ERROR_DETECT == STD_ON)
204     DevAssert(NULL_PTR != TransmitChCfgPtr);
205     DevAssert(NULL_PTR != TxBufferPtr);
206 #endif
207 
208     /* In case overwriting is not allowed, need to check flag of last transmission MailBox,
209        new data will be only wrote to Maiboxes if flag is cleared by receiver. */
210     if ((TRUE == TransmitChCfgPtr->bOverwriteMBEnb ) || (0U == LastMbStatus ))
211     {
212         /* Write data from Tx buffer to mailboxes */
213         for(BufferIndex = 0u; BufferIndex < TransmitChCfgPtr->NumTxMB; BufferIndex++)
214         {
215             *TransmitChCfgPtr->MBAddList[BufferIndex] = TxBufferPtr[BufferIndex];
216         }
217     }
218     else
219     {
220         Status = MRU_IP_STATUS_FAIL;
221     }
222 
223     return Status;
224 }
225 
Mru_Ip_ReadMailbox_Privileged(const Mru_Ip_ReceiveChannelType * ReceiveChCfgPtr,uint32 * RxBufferPtr,uint32 Timeout)226 Mru_Ip_StatusType Mru_Ip_ReadMailbox_Privileged( const Mru_Ip_ReceiveChannelType *ReceiveChCfgPtr,
227                                                  uint32 *RxBufferPtr,
228                                                  uint32 Timeout
229                                                )
230 {
231     uint32 CurrentTicks = 0u;
232     uint32 ElapsedTicks = 0u;
233     uint32 TimeoutTicks = OsIf_MicrosToTicks(Timeout, PLATFORM_TIMEOUT_TYPE);
234     Mru_Ip_StatusType Status = MRU_IP_STATUS_SUCCESS;
235     uint8 InstanceId = ReceiveChCfgPtr->InstanceId;
236     uint8 ChannelIdx = ReceiveChCfgPtr->ChannelIndex;
237     uint32 MailboxStatus = 0u;
238     const Mru_Ip_ChannelCfgType * ChannelConfig = NULL_PTR;
239     uint8 LastRxMailboxIdx= ReceiveChCfgPtr->NumRxMB -1U;
240     uint8 LastRxMailbox= (uint8)(ReceiveChCfgPtr->ListRxMB[LastRxMailboxIdx]); /* Last mailbox used in ReceiveChCfgPtr */
241     const Mru_Ip_StateStructureType* State = Mru_Ip_apxStateStructureArray[InstanceId];
242     uint8 MbIdx=0;
243 
244 #if (MRU_IP_DEV_ERROR_DETECT == STD_ON)
245     DevAssert(NULL_PTR != ReceiveChCfgPtr);
246     DevAssert(NULL_PTR != RxBufferPtr);
247 #endif
248     ChannelConfig = &State->HWUnitConfig->ChannelCfg[ChannelIdx];
249 
250     /* Get current ticks */
251     CurrentTicks = OsIf_GetCounter(PLATFORM_TIMEOUT_TYPE);
252     do
253     {
254         MailboxStatus = *ChannelConfig->ChMBSTATAdd;
255         ElapsedTicks += OsIf_GetElapsed(&CurrentTicks, PLATFORM_TIMEOUT_TYPE);
256         /* Check last mailbox status */
257     }while(( 0U == ((MRU_IP_CH_MBSTAT_MBS0_MASK<<LastRxMailbox) & MailboxStatus)) && (ElapsedTicks < TimeoutTicks));
258 
259     /* Check last mailbox status */
260     if( 0U != ((MRU_IP_CH_MBSTAT_MBS0_MASK<<LastRxMailbox) & MailboxStatus))
261     {
262         /*Last MB in ReceiveChCfgPtr is active*/
263         for(MbIdx=0; MbIdx < ReceiveChCfgPtr->NumRxMB; MbIdx++)
264         {
265             /* Copy data from Mailbox to buffer */
266             RxBufferPtr[MbIdx] = *ReceiveChCfgPtr->MBAddList[MbIdx];
267         }
268         /* Clear Mailbox Status*/
269         *ChannelConfig->ChMBSTATAdd = (uint32)(MRU_IP_CH_MBSTAT_MBS0_MASK << LastRxMailbox);
270         /* Call notification function */
271         if(NULL_PTR != ReceiveChCfgPtr->ReceiveNotification)
272         {
273             ReceiveChCfgPtr->ReceiveNotification(ReceiveChCfgPtr->ChannelId,
274                                                 RxBufferPtr,
275                                                 ReceiveChCfgPtr->NumRxMB
276                                                 );
277         }
278     }
279     else
280     {
281         if(ElapsedTicks >= TimeoutTicks)
282         {
283             Status = MRU_IP_STATUS_TIMEOUT;
284         }
285         else
286         {
287             /* if mailbox status is inactive, return fail*/
288             Status = MRU_IP_STATUS_FAIL;
289         }
290     }
291     return Status;
292 }
293 
Mru_Ip_GetMailboxStatus_Privileged(const Mru_Ip_ReceiveChannelType * ReceiveChCfgPtr)294 Mru_Ip_MBStatusType Mru_Ip_GetMailboxStatus_Privileged( const Mru_Ip_ReceiveChannelType *ReceiveChCfgPtr )
295 {
296     Mru_Ip_MBStatusType MbStatus = MRU_IP_MAILBOX_INACTIVE;
297     uint8 InstanceId = ReceiveChCfgPtr->InstanceId;
298     uint8 ChannelIdx = ReceiveChCfgPtr->ChannelIndex;
299     uint32 MailboxStatus = 0u;
300     const Mru_Ip_ChannelCfgType * ChannelConfig = NULL_PTR;
301     uint8 LastRxMailboxIdx= ReceiveChCfgPtr->NumRxMB -1U;
302     uint8 LastRxMailbox= (uint8)(ReceiveChCfgPtr->ListRxMB[LastRxMailboxIdx]); /* Last mailbox used in ReceiveChCfgPtr */
303     const Mru_Ip_StateStructureType* State = Mru_Ip_apxStateStructureArray[InstanceId];
304 
305 #if (MRU_IP_DEV_ERROR_DETECT == STD_ON)
306     DevAssert(NULL_PTR != ReceiveChCfgPtr);
307 #endif
308     ChannelConfig = &State->HWUnitConfig->ChannelCfg[ChannelIdx];
309     MailboxStatus = *ChannelConfig->ChMBSTATAdd;
310     /* Check last mailbox status */
311     if( 0U != ((MRU_IP_CH_MBSTAT_MBS0_MASK<<LastRxMailbox) & MailboxStatus))
312     {
313         /*Last MB in ReceiveChCfgPtr is active*/
314         MbStatus = MRU_IP_MAILBOX_ACTIVE;
315     }
316 
317     return MbStatus;
318 }
319 
320 /**
321 * @brief            MRU peripheral initialization.
322 * @details          The function initialize the MRU Unit specified in the configuration.
323 *
324 * @param[in]        HWUnitConfigPtr -  pointer to the specified MRU Unit configuration.
325 *
326 * @implements Mru_Ip_Init_Activity
327 */
Mru_Ip_Init(const Mru_Ip_ConfigType * HWUnitConfigPtr)328 void Mru_Ip_Init(const Mru_Ip_ConfigType *HWUnitConfigPtr)
329 {
330     Call_Mru_Ip_Init(HWUnitConfigPtr);
331 }
332 
333 /**
334 * @brief            MRU transmission.
335 * @details          This function writes the data to Mailboxes using the channel specified.
336 *
337 * @param[in]        TransmitChCfgPtr - pointer to the channel configuration where contains list of mailboxes to be written.
338 * @param[in]        TxBufferPtr - pointer to transmit buffer.
339 *
340 * @return           MRU_IP_STATUS_SUCCESS: Transmission command has been accepted.
341 *                   MRU_IP_STATUS_FAIL: Transmission command has not been accepted.
342 *
343 * @implements Mru_Ip_Transmit_Activity
344 */
Mru_Ip_Transmit(const Mru_Ip_TransmitChannelType * TransmitChCfgPtr,const uint32 * TxBufferPtr)345 Mru_Ip_StatusType Mru_Ip_Transmit( const Mru_Ip_TransmitChannelType *TransmitChCfgPtr,
346                                    const uint32 *TxBufferPtr
347                     )
348 {
349     return (Mru_Ip_StatusType)Call_Mru_Ip_Transmit(TransmitChCfgPtr, TxBufferPtr);
350 }
351 
352 /**
353 * @brief            MRU Read Mailbox.
354 * @details          This function read the data from Mailboxes using the channel specified with polling mode.
355 *
356 * @param[in]        ReceiveChCfgPtr - Pointer for the receive channel configuration.
357 * @param[in]        RxBufferPtr - Buffer pointer to receive data.
358 * @param[in]        Timeout - time-out
359 *
360 * @return           MRU_IP_STATUS_SUCCESS: Receive command has been accepted.
361 *                   MRU_IP_STATUS_FAIL: Receive command has not been accepted.
362 *                   MRU_IP_STATUS_TIMEOUT: Receive command has been timeout.
363 *
364 * @implements Mru_Ip_ReadMailbox_Activity
365 */
Mru_Ip_ReadMailbox(const Mru_Ip_ReceiveChannelType * ReceiveChCfgPtr,uint32 * RxBufferPtr,uint32 Timeout)366 Mru_Ip_StatusType Mru_Ip_ReadMailbox( const Mru_Ip_ReceiveChannelType *ReceiveChCfgPtr,
367                                       uint32 *RxBufferPtr,
368                                       uint32 Timeout
369                     )
370 {
371     return (Mru_Ip_StatusType)Call_Mru_Ip_ReadMailbox(ReceiveChCfgPtr, RxBufferPtr, Timeout);
372 }
373 
374 /**
375 * @brief   Get mailbox status.
376 * @details This function get mailbox status of a specific channel.
377 *
378 * @param[in]      ReceiveChCfgPtr       Pointer for the receive channel configuration.
379 *
380 * @return Mru_Ip_MBStatusType
381 * @retval MRU_IP_MAILBOX_INACTIVE       Mailbox status is inactive
382 * @retval MRU_IP_MAILBOX_ACTIVE         Mailbox status is active
383 *
384 * @implements    Mru_Ip_GetMailboxStatus_Activity
385 */
Mru_Ip_GetMailboxStatus(const Mru_Ip_ReceiveChannelType * ReceiveChCfgPtr)386 Mru_Ip_MBStatusType Mru_Ip_GetMailboxStatus( const Mru_Ip_ReceiveChannelType *ReceiveChCfgPtr )
387 {
388     return (Mru_Ip_MBStatusType)Call_Mru_Ip_GetMailboxStatus(ReceiveChCfgPtr);
389 }
390 /**
391 * @brief   This function is called by MRU ISRs.
392 * @details This function will process MRU interrupts.
393 *
394 * @param[in]     InstanceId            Instance Id of the hardware unit.
395 * @param[in]     IntGroupId            Interrupt group Id of the hardware unit.
396 *
397 * @implements Mru_Ip_IrqHandler_Activity
398 */
Mru_Ip_IrqHandler(uint8 InstanceId,uint8 IntGroupId)399 void Mru_Ip_IrqHandler(uint8 InstanceId, uint8 IntGroupId)
400 {
401     const Mru_Ip_StateStructureType* State = Mru_Ip_apxStateStructureArray[InstanceId];
402     uint8 ChannelIdx = 0u;
403     uint32 NotifyStatus = 0u;
404     const Mru_Ip_ChannelCfgType * ChannelConfig = NULL_PTR;
405 
406     /* Processing channels notification */
407     NotifyStatus = *State->HWUnitConfig->NOTIFYAdd[IntGroupId];
408     for(ChannelIdx = 0u; ChannelIdx < State->HWUnitConfig->NumChannel; ChannelIdx++)
409     {
410         if((NotifyStatus & MRU_IP_NOTIFY_CH1_IS_MASK) != 0u)
411         {
412             ChannelConfig = &State->HWUnitConfig->ChannelCfg[ChannelIdx];
413             if((*ChannelConfig->ChCFG0Add & MRU_IP_CH_CFG0_IE_MASK) != 0u)
414             {
415                 /* Receive mail box */
416                 Mru_Ip_IrqHandlerReceiveMb(ChannelConfig, IntGroupId);
417             }
418             else
419             {
420                 /* Channel enable interrupt flag is not set, nothing to do */
421             }
422         }
423         else
424         {
425             /* Channel status flag is not set, nothing to do */
426         }
427         NotifyStatus = NotifyStatus >> 1u;
428     }
429 }
430 
431 /**
432 * @brief   This function is called by MRU ISRs.
433 * @details This function will process MRU interrupts.
434 *
435 * @param[in]     InstanceId            Instance Id of the hardware unit.
436 * @param[in]     IntGroupId            Interrupt group Id of the hardware unit.
437 *
438 * @implementsMru_Ip_IrqHandlerReceiveMb_Activity
439 */
Mru_Ip_IrqHandlerReceiveMb(const Mru_Ip_ChannelCfgType * ChannelConfig,uint8 IntGroupId)440 static void Mru_Ip_IrqHandlerReceiveMb(const Mru_Ip_ChannelCfgType * ChannelConfig, uint8 IntGroupId)
441 {
442     const Mru_Ip_MBLinkReceiveChannelType (* MBLinkReceiveChConfig)[NUMBER_OF_INTERRUPT_GROUP];
443     volatile uint32 * ChMBSTATAddr;
444     uint32 MBStatus = 0u;
445     uint32 ChCFG1 = 0u;
446     uint32 MBIdx = 0u;
447     uint8 BufferIdx = 0u;
448     uint32 IntGroupCfg = ((uint32)IntGroupId) << MRU_IP_CH_CFG1_MBIC0_SHIFT;
449     const Mru_Ip_ReceiveChannelType * ReceiveChConfig = NULL_PTR;
450 
451     MBLinkReceiveChConfig = ChannelConfig->MBLinkReceiveChCfg;
452     if(MBLinkReceiveChConfig != NULL_PTR)
453     {
454         ChMBSTATAddr = ChannelConfig->ChMBSTATAdd;
455         MBStatus = *ChMBSTATAddr;
456         ChCFG1 = *ChannelConfig->ChCFG1Add;
457         for(MBIdx = 0u; MBIdx < ChannelConfig->NumMailbox; MBIdx++)
458         {
459             if(((ChCFG1 & MRU_IP_CH_CFG1_MBIC0_MASK) == IntGroupCfg) && ((MBStatus & MRU_IP_CH_MBSTAT_MBS0_MASK) != 0u))
460             {
461                 ReceiveChConfig = MBLinkReceiveChConfig[MBIdx][IntGroupId].ReceiveChCfg;
462                 if(ReceiveChConfig != NULL_PTR)
463                 {
464                     /* Copy data to RxBuffer */
465                     for(BufferIdx = 0u; BufferIdx < ReceiveChConfig->NumRxMB; BufferIdx++)
466                     {
467                         ReceiveChConfig->RxBuffer[BufferIdx] = *ReceiveChConfig->MBAddList[BufferIdx];
468                     }
469                     /* To support unidirectional communication, transmitter core will check Mailbox flag of Receiver MRU is cleared for triggering next transmit session.
470                     Mailbox flag should be clear after copy data to buffer and before call notification */
471                     *ChMBSTATAddr = (uint32)(MRU_IP_CH_MBSTAT_MBS0_MASK << MBIdx);
472                     /* Call notification function */
473                     if(NULL_PTR != ReceiveChConfig->ReceiveNotification)
474                     {
475                         ReceiveChConfig->ReceiveNotification(ReceiveChConfig->ChannelId,
476                                                             ReceiveChConfig->RxBuffer,
477                                                             ReceiveChConfig->NumRxMB
478                                                             );
479                     }
480                 }
481                 else
482                 {
483                     /* the mailbox was not configured using current interrupt group, nothing to do */
484                 }
485             }
486             else
487             {
488                 /* Mailbox status flag for current interrupt group is not set, nothing to do */
489             }
490             MBStatus = MBStatus >> MRU_CH_MBSTAT_MBS0_WIDTH;
491             ChCFG1 = ChCFG1 >> MRU_CH_CFG1_MBIC0_WIDTH;
492         }
493     }
494     else
495     {
496         /* the channel was not used by the driver, nothing to do */
497     }
498 }
499 
500 #define PLATFORM_STOP_SEC_CODE
501 #include "Platform_MemMap.h"
502 
503 #ifdef __cplusplus
504 }
505 #endif
506 
507 /** @} */
508