Why mailboxes and message buffers are used interchangeably in examples and functions.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why mailboxes and message buffers are used interchangeably in examples and functions.

383 Views
Sang-Hoon_Ahn
Contributor I

hello
I am currently trying to implement CANFD communication using MPC5748G.

I am studying based on the basic examples provided with the S32 SDK.

I have a question here
First, in the example, there is a define statement that sets the number of mailboxes.

#define TX_MAILBOX (1UL)
#define RX_MAILBOX (0UL)

However, the FLEXCAN_DRV_Receive and FLEXCAN_DRV_Send functions used in the example all receive mb_idx as an input parameter, and mb_idx is described as 'Index of the message buffer' in the SDK help documentation.

In fact, TX_MAILBOX or RX_MAILBOX defined in the mb_idx parameter in the FLEXCAN_DRV function group is entered.


In the function descriptions and examples of the SDK, mailbox and message buffer are described as the same.

Therefore, defined in MPC5748G_features.h
#define FEATURE_CAN_MAX_MB_NUM (96U)
348 /* @brief Array of maximum number of Message Buffers supported for payload size 8 for all the CAN instances */

If interpreted as a syntax, RX_MAILBOX and TX_MAILBOX declared in the example seem to be possible up to 96.

Is my understanding correct?

And according to lines 322~348 of MPC5748G_features.h
FEATURE_CAN_MX_MB_NUM is declared per channel for the maximum number of channels of MPC5748G, which is 8 channels.
(FEATURE_CAN0_MX_MB_NUM, FEATURE_CAN1_MX_MB_NUM, FEATURE_CAN2_MX_MB_NUM...)


For example if I use 2 CAN FD channels

#define TX_CH1_MAILBOX (1UL)
#define RX_CH1_MAILBOX (0UL)
#define TX_CH2_MAILBOX (1UL)
#define RX_CH2_MAILBOX (0UL)

Doesn't it matter if the values of TX_CH1_MAILBOX and TX_CH2_MAILBOX are the same?

In the case of MPC5748G, up to 96 message buffers can be set for each channel, and each buffer is operated independently.


Finally, in the example, the CAN Receive construct is declared as below within the while construct of the main statement.

FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX, &recvBuff);

while((FLEXCAN_DRV_GetTransferStatus(INST_CANCOM1, RX_MAILBOX) & FLEXCAN_DRV_GetTransferStatus(INST_CANCOM2, RX_MAILBOX)) == STATUS_BUSY);


Nested use of while statements is inefficient in my opinion.

Most receive examples of other MCU boards are written to be performed within the interrupt vector function (ex: void PIT_Ch5_IRQHandler(void)).

Any good examples?

 

 

0 Kudos
1 Reply

367 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

each FlexCAN instance has up to 96 MBs assuming 8 byte payload. For CAN FD and memory block configured for different payload a number of available MBs decreases per RAM block. Refer to 43.4.41 FlexCAN Memory Partition for CAN FD of the RM.
RX_MAILBOX and TX_MAILBOX are just user macros to specify the MB used within API functions. If you will have TX_CH1_MAILBOX and TX_CH2_MAILBOX same value for same instance, it will make no sense. If channel means instance/module, then yes, but it is up to user how macros will be defined and used.
FlexCAN SDK driver always uses module interrupt. You can install callback function and use callback's event to know when interrupt happens and for which even (receive/transmit/rxfifo,...) and MB number.

BR, Petr

0 Kudos