This repository has been archived on 2026-02-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
can/Src/mmr_can_receive.c
T
Stefano Calabretti 7b09401b00 Multiple frames implementation (#2)
* 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>
2021-12-09 11:39:39 +01:00

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;
}