On the Calculation of FlexCAN Mailbox region

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

On the Calculation of FlexCAN Mailbox region

Jump to solution
544 Views
JihongZhang
Contributor II

Hi,

I am writing a FlexCAN driver. Refer to S32K144 FlexCAN driver. The MB area calculation function and data manual description do not match. Is there any mistake in my understanding?

As described in the data manual, the MB interval of 8 payloads is 16 bytes, but 32 bytes are calculated in the code. Is there any problem in understanding?

source Code:

volatile uint32_t* FLEXCAN_GetMsgBuffRegion(
CAN_Type * base,
uint32_t msgBuffIdx)
{
#if FEATURE_CAN_HAS_FD
uint8_t payload_size = FLEXCAN_GetPayloadSize(base);
#else
uint8_t payload_size = 8U;
#endif

uint8_t arbitration_field_size = 8U;
uint32_t ramBlockSize = 512U;
uint32_t ramBlockOffset;

uint8_t mb_size = (uint8_t)(payload_size + arbitration_field_size);
uint8_t maxMbNum = (uint8_t)(ramBlockSize / mb_size);

ramBlockOffset = 128U * (msgBuffIdx / (uint32_t)maxMbNum);

/* Multiply the MB index by the MB size (in words) */
uint32_t mb_index = ramBlockOffset + ((msgBuffIdx % (uint32_t)maxMbNum) * ((uint32_t)mb_size >> 2U));

return &(base->RAMn[mb_index]);
}

 

JihongZhang_0-1670381572362.png

 

0 Kudos
1 Solution
527 Views
Senlent
NXP TechSupport
NXP TechSupport

I didn't understand the logic of your formula, I did a simple calculation based on this function

for example:

msgBuffIdx 0 1 2 3
RAMn[CAN_RAMn_COUNT] RAMn[0] RAMn[4] RAMn[8] RAMn[12]

 

The offset address of RAMn is 0x80,the size of each RAMn[x]  is 4 bytes and each offset is 4 bytes, and the space occupied by one MB is exactly 16 bytes. Is there any problem?

View solution in original post

0 Kudos
4 Replies
535 Views
Senlent
NXP TechSupport
NXP TechSupport

I didn't get your point, isn't MB_SIZE equal to 16 here?(payloadSize =

Senlent_0-1670400058234.png

 

0 Kudos
532 Views
JihongZhang
Contributor II

My understanding is that this function is used to calculate the starting address of MB, but why is this function used to calculate the second MB of an 8-byte load offset by 32 bytes? Shouldn't it be 16 bytes? (1/32)*512 + (1%32)* 16 = 8 dword, 0x80 + 0x20 = 0xa0. But isn't the interval between two MB in the MB structure description 16 bytes?

JihongZhang_0-1670400672568.png

 

0 Kudos
528 Views
Senlent
NXP TechSupport
NXP TechSupport

I didn't understand the logic of your formula, I did a simple calculation based on this function

for example:

msgBuffIdx 0 1 2 3
RAMn[CAN_RAMn_COUNT] RAMn[0] RAMn[4] RAMn[8] RAMn[12]

 

The offset address of RAMn is 0x80,the size of each RAMn[x]  is 4 bytes and each offset is 4 bytes, and the space occupied by one MB is exactly 16 bytes. Is there any problem?

0 Kudos
493 Views
JihongZhang
Contributor II

hi Senlent,

As shown in the figure below,What is written in the document is the same as what you described, but why is the calculated result of this function different from what is described in the document? The calculated address of Mb [0] is 0x80, while Mb [1] is offset by 32 bytes.

JihongZhang_0-1670407139260.png

 

 

0 Kudos