7b09401b00
* Add rx event handlers * Fix compile errors and add constness * Pass sender id * Change api interface * Revert changes * Add filter fifo * Add default setup * Add receive function * Remove interrupt activation * Activate RX interrupts * Merge remote changes * Add event list constructor * Fix compilation bug * Send and receive multiple frames * Refactor * Refactor * Fix compile error * Use known syntax * Refactor * Provide storage * Add frame end * Add some documentation * Turn macros into functions * Refactor * Refactor * Fix compile error * Use ExtendedIds Co-authored-by: Riccardo998 <riccardo.storchi98@gmail.com>
55 lines
1.3 KiB
C
55 lines
1.3 KiB
C
#include <stdbool.h>
|
|
#include "mmr_can.h"
|
|
|
|
static HalStatus receiveOne(CanHandle *hcan, CanRxHeader *header, uint8_t *result);
|
|
static HalStatus receiveAll(CanHandle *hcan, CanRxHeader *header, uint8_t *result);
|
|
static bool headerIsMultiFrame(CanRxHeader *header, CanId targetId);
|
|
|
|
|
|
HalStatus MMR_CAN_Receive(CanHandle *hcan, MmrCanMessage *result) {
|
|
CanRxHeader header = {};
|
|
uint8_t *dest = result->store;
|
|
HalStatus status = receiveOne(hcan, &header, dest);
|
|
|
|
result->senderId = header.ExtId;
|
|
if (MMR_CAN_IsMultiFrame(&header)) {
|
|
status |= receiveAll(hcan, &header, dest);
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
|
|
static HalStatus receiveOne(
|
|
CanHandle *hcan,
|
|
CanRxHeader *header,
|
|
uint8_t *result
|
|
) {
|
|
return HAL_CAN_GetRxMessage(hcan, MMR_CAN_RX_FIFO, header, result);
|
|
}
|
|
|
|
static HalStatus receiveAll(
|
|
CanHandle *hcan,
|
|
CanRxHeader *header,
|
|
uint8_t *result
|
|
) {
|
|
CanId targetId = header->ExtId;
|
|
HalStatus status = HAL_OK;
|
|
do {
|
|
result += MMR_CAN_MAX_DATA_LENGTH;
|
|
status |= receiveOne(hcan, header, result);
|
|
} while (
|
|
headerIsMultiFrame(header, targetId) && status == HAL_OK
|
|
);
|
|
|
|
return status;
|
|
}
|
|
|
|
|
|
static bool headerIsMultiFrame(CanRxHeader *header, CanId targetId) {
|
|
return
|
|
MMR_CAN_IsMultiFrame(header) &&
|
|
!MMR_CAN_IsMultiFrameEnd(header) &&
|
|
header->DLC >= MMR_CAN_MAX_DATA_LENGTH;
|
|
}
|