WIP
This commit is contained in:
+8
-69
@@ -2,25 +2,7 @@
|
||||
#include "mmr_can.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
CanHandle *handle;
|
||||
uint8_t *result;
|
||||
|
||||
struct {
|
||||
CanRxHeader rx;
|
||||
MmrCanHeader mmr;
|
||||
} headers;
|
||||
|
||||
uint8_t fifo;
|
||||
} ReceptionParams;
|
||||
|
||||
|
||||
static HalStatus receiveOne(ReceptionParams *rp);
|
||||
static HalStatus receiveAll(ReceptionParams *rp);
|
||||
static bool headerIsMultiFrame(MmrCanHeader header, CanId targetId);
|
||||
|
||||
|
||||
MmrResult MMR_CAN_TryReceive(CanHandle *hcan, MmrCanMessage *result) {
|
||||
MmrResult MMR_CAN_TryReceive(MmrCan *can, MmrCanMessage *result) {
|
||||
size_t pendingMessages =
|
||||
HAL_CAN_GetRxFifoFillLevel(hcan, MMR_CAN_RX_FIFO);
|
||||
|
||||
@@ -34,58 +16,15 @@ MmrResult MMR_CAN_TryReceive(CanHandle *hcan, MmrCanMessage *result) {
|
||||
}
|
||||
|
||||
|
||||
HalStatus MMR_CAN_Receive(CanHandle *hcan, MmrCanMessage *result) {
|
||||
ReceptionParams rp = {
|
||||
.handle = hcan,
|
||||
.result = (uint8_t*)result->store,
|
||||
.fifo = MMR_CAN_RX_FIFO,
|
||||
};
|
||||
|
||||
HalStatus status = receiveOne(&rp);
|
||||
if (status != HAL_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
result->header = rp.headers.mmr;
|
||||
if (MMR_CAN_IsMultiFrame(rp.headers.mmr)) {
|
||||
status |= receiveAll(&rp);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
static HalStatus receiveAll(ReceptionParams *rp) {
|
||||
CanId targetId = rp->headers.mmr.senderId;
|
||||
HalStatus status = HAL_OK;
|
||||
do {
|
||||
rp->result += MMR_CAN_MAX_DATA_LENGTH;
|
||||
status |= receiveOne(rp);
|
||||
}
|
||||
while (
|
||||
headerIsMultiFrame(rp->headers.mmr, targetId) && status == HAL_OK
|
||||
);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
static HalStatus receiveOne(ReceptionParams *rp) {
|
||||
HalStatus MMR_CAN_Receive(MmrCan *can, MmrCanMessage *result) {
|
||||
CanRxHeader rxHeader = {};
|
||||
HalStatus status = HAL_CAN_GetRxMessage(
|
||||
rp->handle,
|
||||
rp->fifo,
|
||||
&rp->headers.rx,
|
||||
rp->result
|
||||
can->handle,
|
||||
can->fifo,
|
||||
&rxHeader,
|
||||
result->store
|
||||
);
|
||||
|
||||
rp->headers.mmr = MMR_CAN_HeaderFromBits(rp->headers.rx.ExtId);
|
||||
result->header = MMR_CAN_HeaderFromBits(rxHeader.ExtId);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
static bool headerIsMultiFrame(MmrCanHeader header, CanId targetId) {
|
||||
return
|
||||
MMR_CAN_IsMultiFrame(header) &&
|
||||
!MMR_CAN_IsMultiFrameEnd(header) &&
|
||||
header.senderId == targetId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user