Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #175 from solarcaratuva/can-auto-reset-2
Browse files Browse the repository at this point in the history
MotorControllerCAN auto-reset
  • Loading branch information
edward-noe authored Jul 10, 2022
2 parents e326fbd + a6f2cec commit ee37931
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ECU/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <mbed.h>
#include <rtos.h>

#define LOG_LEVEL LOG_FATAL
#define LOG_LEVEL LOG_DEBUG
#define MAIN_LOOP_PERIOD 1s
#define MOTOR_THREAD_PERIOD 10ms
#define POWERAUX_THREAD_PERIOD 10ms
Expand Down
3 changes: 3 additions & 0 deletions Motor/lib/include/MotorControllerCANInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "CANInterface.h"
#include "MotorControllerCANStructs.h"
#include <mbed.h>

class MotorControllerCANInterface : public CANInterface {
public:
Expand All @@ -15,6 +16,8 @@ class MotorControllerCANInterface : public CANInterface {

private:
void message_handler() override;
Thread bus_status_thread;
void check_bus_status();
};

#endif
22 changes: 22 additions & 0 deletions Motor/lib/src/MotorControllerCANInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include "MotorControllerCANInterface.h"
#include "ThisThread.h"
#include "log.h"

MotorControllerCANInterface::MotorControllerCANInterface(PinName rd, PinName td,
PinName standby_pin)
: CANInterface(rd, td, standby_pin) {
can.frequency(125000);
bus_status_thread.start(
callback(this, &MotorControllerCANInterface::check_bus_status));
}

int MotorControllerCANInterface::request_frames(bool power_status_frame,
Expand Down Expand Up @@ -63,3 +66,22 @@ void MotorControllerCANInterface::message_handler() {
}
}
}

void MotorControllerCANInterface::check_bus_status() {
while (true) {
int rderror = can.rderror();
int tderror = can.tderror();

if (rderror >= 128 || tderror >= 128) {
can.reset();
log_warn("MotorControllerCANInterface reset due to RX error %d TX "
"error %d",
rderror, tderror);
} else {
log_debug("MotorControllerCANInterface RX error %d TX error %d",
rderror, tderror);
}

ThisThread::sleep_for(1s);
}
}
2 changes: 1 addition & 1 deletion Motor/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <mbed.h>
#include <rtos.h>

#define LOG_LEVEL LOG_FATAL
#define LOG_LEVEL LOG_DEBUG
#define MAIN_LOOP_PERIOD 100ms

EventQueue event_queue(32 * EVENTS_EVENT_SIZE);
Expand Down
2 changes: 1 addition & 1 deletion PowerAux/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <mbed.h>
#include <rtos.h>

#define LOG_LEVEL LOG_FATAL
#define LOG_LEVEL LOG_DEBUG
#define MAIN_LOOP_PERIOD 1s
#define ERROR_CHECK_PERIOD 100ms
#define FLASH_PERIOD 500ms
Expand Down
2 changes: 1 addition & 1 deletion Solar/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <mbed.h>
#include <rtos.h>

#define LOG_LEVEL LOG_FATAL
#define LOG_LEVEL LOG_DEBUG
#define MAIN_LOOP_PERIOD 1s

SolarCANInterface vehicle_can_interface(CAN_RX, CAN_TX, CAN_STBY);
Expand Down

0 comments on commit ee37931

Please sign in to comment.