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>
This commit is contained in:
committed by
GitHub
parent
90d1836dfa
commit
7b09401b00
+24
-11
@@ -1,8 +1,19 @@
|
||||
#include "mmr_can.h"
|
||||
#include "mmr_can_util.h"
|
||||
|
||||
static uint8_t maskIdLower5Bits(CanRxHeader *header);
|
||||
|
||||
|
||||
HalStatus MMR_CAN_BasicSetupAndStart(CanHandle *hcan) {
|
||||
return
|
||||
MMR_CAN_FilterConfigDefault(hcan) |
|
||||
HAL_CAN_Start(hcan)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
HalStatus MMR_CAN_FilterConfig(CanHandle *hcan, MmrCanFilterSettings settings) {
|
||||
CAN_FilterTypeDef filter = {
|
||||
CanFilter filter = {
|
||||
.FilterActivation = settings.enabled
|
||||
? CAN_FILTER_ENABLE
|
||||
: CAN_FILTER_DISABLE,
|
||||
@@ -19,11 +30,13 @@ HalStatus MMR_CAN_FilterConfig(CanHandle *hcan, MmrCanFilterSettings settings) {
|
||||
return HAL_CAN_ConfigFilter(hcan, &filter);
|
||||
}
|
||||
|
||||
|
||||
CanFilterMask MMR_CAN_AlignStandardMask(CanFilterMask baseMask) {
|
||||
static const uint8_t extendedMaskSurplusBytes = 5;
|
||||
return baseMask << extendedMaskSurplusBytes;
|
||||
}
|
||||
|
||||
|
||||
MmrCanFilterSettings MMR_CAN_GetDefaultFilterSettings() {
|
||||
return (MmrCanFilterSettings) {
|
||||
.enabled = true,
|
||||
@@ -35,14 +48,14 @@ MmrCanFilterSettings MMR_CAN_GetDefaultFilterSettings() {
|
||||
}
|
||||
|
||||
|
||||
HalStatus MMR_CAN_Send(CanHandle *hcan, MmrCanPacket packet) {
|
||||
CanTxHeader header = {
|
||||
.IDE = CAN_ID_STD,
|
||||
.RTR = CAN_RTR_DATA,
|
||||
.DLC = packet.length,
|
||||
.StdId = packet.remoteId,
|
||||
.TransmitGlobalTime = DISABLE,
|
||||
};
|
||||
|
||||
return HAL_CAN_AddTxMessage(hcan, &header, packet.data, packet.mailbox);
|
||||
bool MMR_CAN_IsMultiFrame(CanRxHeader *header) {
|
||||
return maskIdLower5Bits(header) == MMR_CAN_MESSAGE_TYPE_MULTI_FRAME;
|
||||
}
|
||||
|
||||
bool MMR_CAN_IsMultiFrameEnd(CanRxHeader *header) {
|
||||
return maskIdLower5Bits(header) == MMR_CAN_MESSAGE_TYPE_MULTI_FRAME;
|
||||
}
|
||||
|
||||
static always_inline uint8_t maskIdLower5Bits(CanRxHeader *header) {
|
||||
return mask(header->ExtId, B8_(0001, 1111));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user