Skip to content

Commit

Permalink
Added Can messages as submodule and removed can ids from can driver
Browse files Browse the repository at this point in the history
  • Loading branch information
Quinn1876 committed Oct 16, 2022
1 parent 97f0ba2 commit f0b4792
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "G6-CAN-Messages"]
path = G6-CAN-Messages
url = ../G6-CAN-Messages
1 change: 1 addition & 0 deletions G6-CAN-Messages
Submodule G6-CAN-Messages added at 5e3460
8 changes: 4 additions & 4 deletions STM32G431KBTx/Core/Src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ int main(void)
can_driver.initialize();
if (!can_driver.push_filters(
CanMessageFilter::DualFilter(
CanMessage::Id::RelayFaultDetected,
CanMessage::Id::RelayFaultDetected
CanMessageId::RelayFaultDetected,
CanMessageId::RelayFaultDetected
),
CanMessageFilter::DualFilter(
CanMessage::Id::LVSensingFaultDetected,
CanMessage::Id::LVSensingFaultDetected
CanMessageId::LVSensingFaultDetected,
CanMessageId::LVSensingFaultDetected
)
)) {
Error_Handler();
Expand Down
3 changes: 2 additions & 1 deletion STM32G431KBTx/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ C_INCLUDES = \
-I ./Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F \
-I ./Drivers/CMSIS/Device/ST/STM32G4xx/Include \
-I ./Drivers/CMSIS/Include \
-I ../platform/inc
-I ../platform/inc \
-I ../G6-CAN-Messages

C_INCLUDES += $(USER_INCLUDES)

Expand Down
3 changes: 2 additions & 1 deletion STM32G473CBTx/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ C_INCLUDES = \
-I ./Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F \
-I ./Drivers/CMSIS/Device/ST/STM32G4xx/Include \
-I ./Drivers/CMSIS/Include \
-I ../platform/inc
-I ../platform/inc \
-I ../G6-CAN-Messages

C_INCLUDES += $(USER_INCLUDES)

Expand Down
1 change: 1 addition & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
THIS_DIR := $(shell readlink -f .)
BUILD_DIR = $(THIS_DIR)/build


all:
cd $(DEV) && make BUILD_DIR=$(BUILD_DIR)

Expand Down
16 changes: 3 additions & 13 deletions platform/inc/can.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "fdcan.h"
#include "stdint.h"
#include <type_traits>
#include "can_messages.h"

enum class CanFilterConfiguration : uint32_t {
Disable = FDCAN_FILTER_DISABLE,
Expand Down Expand Up @@ -92,30 +93,19 @@ struct CanMessage {
static constexpr size_t MAX_DATA_LENGTH = 64;
static constexpr uint32_t MAX_UINT32 = 0xffffffff;

enum Id : uint32_t {
RelayFaultDetected = 0x00,
BmsFaultDetected = 0x01,
McFaultDetected = 0x02,
LVSensingFaultDetected = 0x03,


// TODO Fill out with the rest of the values
DefaultRx = MAX_UINT32,
};

enum class ESI : uint32_t {
ERROR_ACTIVE = FDCAN_ESI_ACTIVE,
ERROR_PASSIVE = FDCAN_ESI_PASSIVE,

UNKNOWN_ERROR_STATE = MAX_UINT32,
};

CanMessage(Id id, uint8_t *data, uint32_t data_length=MAX_DATA_LENGTH);
CanMessage(CanMessageId id, uint8_t *data, uint32_t data_length=MAX_DATA_LENGTH);

void set_id(uint32_t id);
void set_ESI(uint32_t esi);

Id identifier;
CanMessageId identifier;
ESI error_state_indicator = ESI::ERROR_PASSIVE;
uint8_t message_marker;
uint8_t* data;
Expand Down
10 changes: 5 additions & 5 deletions platform/src/can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CanMessageFilter::CanMessageFilter(uint32_t filter_type,
filter_id2,
} {}

CanMessage::CanMessage(CanMessage::Id id,
CanMessage::CanMessage(CanMessageId id,
uint8_t *data,
uint32_t data_length)
: identifier(id),
Expand All @@ -53,7 +53,7 @@ CanMessage::CanMessage(CanMessage::Id id,
data_length(data_length) {}

void CanMessage::set_id(uint32_t id) {
using Id = CanMessage::Id;
using Id = CanMessageId;
switch (id) {
case 0x00:
identifier = Id::RelayFaultDetected;
Expand Down Expand Up @@ -88,7 +88,7 @@ void CanMessage::set_ESI(uint32_t esi) {

RxCanMessage::RxCanMessage(uint8_t *data,
uint32_t dataLength)
: CanMessage(Id::DefaultRx, data, dataLength) {}
: CanMessage(CanMessageId::DefaultRx, data, dataLength) {}


void CanDriver::initialize(OperatingMode initial_operating_mode) {
Expand Down Expand Up @@ -133,7 +133,7 @@ void CanDriver::test_driver() {
data[i] = i;
rx_data[i] = 0;
}
CanMessage msg(CanMessage::Id::RelayFaultDetected, data, 8);
CanMessage msg(CanMessageId::RelayFaultDetected, data, 8);
uint32_t id = write(msg);
await_write(id);
while (!rx_ready(CanRxFifo::FIFO0));
Expand All @@ -149,7 +149,7 @@ void CanDriver::test_driver() {
for (int i = 0; i < 8; i++) {
rx_data[i] = 0;
}
msg = CanMessage(CanMessage::Id::LVSensingFaultDetected, data, 8);
msg = CanMessage(CanMessageId::LVSensingFaultDetected, data, 8);
id = write(msg);
await_write(id);
while (!rx_ready(CanRxFifo::FIFO0));
Expand Down

0 comments on commit f0b4792

Please sign in to comment.