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]);
}
已解决! 转到解答。
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?
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?
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?
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.