Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added timestamps to CAN messages when receiving #309

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/modm/architecture/interface/can_message.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2014, 2016, Niklas Hauser
* Copyright (c) 2015-2016, Sascha Schade
* Copyright (c) 2019, Benjamin Weps
*
* This file is part of the modm project.
*
Expand All @@ -16,6 +17,7 @@
#include <stdint.h>
#include <modm/io/iostream.hpp>
#include <modm/architecture/utils.hpp>
#include <modm/processing/timer/timestamp.hpp>

namespace modm
{
Expand Down Expand Up @@ -80,6 +82,18 @@ struct Message
length = len;
}

inline Timestamp
getTimestamp()
{
return timestamp;
}

inline void
setTimestamp(Timestamp ts)
{
timestamp = ts;
}

public:
uint32_t identifier;
uint8_t modm_aligned(4) data[8];
Expand All @@ -94,6 +108,7 @@ struct Message
bool extended : 1;
} flags;
uint8_t length;
Timestamp timestamp;

public:
bool
Expand Down
3 changes: 3 additions & 0 deletions src/modm/platform/can/stm32/can.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <modm/architecture/interface/assert.hpp>
#include <modm/architecture/interface/interrupt.hpp>
#include <modm/architecture/interface/delay.hpp>
#include <modm/architecture/interface/clock.hpp>
#include <modm/platform/clock/rcc.hpp>

%% if id == ""
Expand Down Expand Up @@ -264,6 +265,7 @@ MODM_ISR({{ reg }}_RX0)

%% if options["buffer.rx"] > 0
RxMessage rxMessage;
rxMessage.message.setTimestamp(modm::Clock::now());
readMailbox(rxMessage.message, 0, &(rxMessage.filter_id));

// Release FIFO (access the next message)
Expand Down Expand Up @@ -291,6 +293,7 @@ MODM_ISR({{ reg }}_RX1)

%% if options["buffer.rx"] > 0
RxMessage rxMessage;
rxMessage.message.setTimestamp(modm::Clock::now());
readMailbox(rxMessage.message, 1, &(rxMessage.filter_id));

// Release FIFO (access the next message)
Expand Down