fix buffer index calculation

they take a bit field as an argument, and then immediately use a clz instruction to convert it back to an index for some reason
This commit is contained in:
Kilian Bracher 2025-06-18 16:18:45 +02:00
parent 1b79e5cbea
commit 2ab77d75d6
Signed by: k.bracher
SSH Key Fingerprint: SHA256:mXpyZkK7RDiJ7qeHCKJX108woM0cl5TrCvNBJASu6lM

View File

@ -230,12 +230,14 @@ HAL_StatusTypeDef ftcan_get_tx_queue_length(uint32_t *length) {
}
#if FTCAN_NUM_TX_BUFFERS
static_assert(FDCAN_TX_BUFFER11 == 1 << 11 && FDCAN_TX_BUFFER21 == 1 << 21, "Your HAL version has a different definition for the transmit buffer indices. Please update your HAL version or change the code below.");
HAL_StatusTypeDef ftcan_transmit_buffer(uint16_t id, const uint8_t *data, size_t datalen, uint32_t buffer_index) {
static FDCAN_TxHeaderTypeDef header;
if (buffer_index >= FTCAN_NUM_TX_BUFFERS) {
return HAL_ERROR;
}
return HAL_FDCAN_AddMessageToTxBuffer(hcan, fdcan_initialize_tx_header(&header, id, datalen), data, buffer_index);
return HAL_FDCAN_AddMessageToTxBuffer(hcan, fdcan_initialize_tx_header(&header, id, datalen), data, 1 << buffer_index);
}
#endif // FTCAN_NUM_TX_BUFFERS
#endif