Skip to content

Commit

Permalink
Use GPIO lib for reset GPIO, clear errors only if they were raised
Browse files Browse the repository at this point in the history
Signed-off-by: Cornelius Claussen <[email protected]>
  • Loading branch information
corneliusclaussen committed Mar 25, 2024
1 parent a5e4173 commit a6303d0
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 37 deletions.
1 change: 0 additions & 1 deletion modules/YetiDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ target_sources(${MODULE_NAME}
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
# insert other things like install cmds etc here
install(FILES yetiR1_2.0-1_firmware.bin DESTINATION ${CMAKE_INSTALL_DATADIR}/everest/modules/YetiDriver/firmware)

# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1
16 changes: 13 additions & 3 deletions modules/YetiDriver/YetiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void YetiDriver::init() {
void YetiDriver::ready() {
serial.run();

if (!serial.reset(config.reset_gpio)) {
if (!serial.reset(config.reset_gpio_chip, config.reset_gpio)) {
EVLOG_AND_THROW(EVEXCEPTION(Everest::EverestInternalError, "Yeti reset not successful."));
}

Expand Down Expand Up @@ -110,8 +110,15 @@ bool connector_lock_failed;
bool cp_signal_fault;

void YetiDriver::clear_errors_on_unplug() {
p_board_support->request_clear_all_evse_board_support_MREC2GroundFailure();
p_connector_lock->request_clear_all_connector_lock_MREC1ConnectorLockFailure();
if (error_MREC2GroundFailure) {
p_board_support->request_clear_all_evse_board_support_MREC2GroundFailure();
}
error_MREC2GroundFailure = false;

if (error_MREC1ConnectorLockFailure) {
p_connector_lock->request_clear_all_connector_lock_MREC1ConnectorLockFailure();
}
error_MREC1ConnectorLockFailure = false;
}

void YetiDriver::error_handling(ErrorFlags e) {
Expand All @@ -125,6 +132,7 @@ void YetiDriver::error_handling(ErrorFlags e) {
if (e.rcd_triggered and not last_error_flags.rcd_triggered) {
p_board_support->raise_evse_board_support_MREC2GroundFailure("Onboard RCD triggered",
Everest::error::Severity::High);
error_MREC2GroundFailure = true;
}

if (e.ventilation_not_available and not last_error_flags.ventilation_not_available) {
Expand All @@ -137,6 +145,8 @@ void YetiDriver::error_handling(ErrorFlags e) {
if (e.connector_lock_failed and not last_error_flags.connector_lock_failed) {
p_connector_lock->raise_connector_lock_MREC1ConnectorLockFailure("Lock motor failure",
Everest::error::Severity::High);

error_MREC1ConnectorLockFailure = true;
}

if (e.cp_signal_fault and not last_error_flags.cp_signal_fault) {
Expand Down
5 changes: 4 additions & 1 deletion modules/YetiDriver/YetiDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace module {
struct Conf {
std::string serial_port;
int baud_rate;
std::string control_mode;
std::string reset_gpio_chip;
int reset_gpio;
int caps_min_current_A;
};
Expand Down Expand Up @@ -78,6 +78,9 @@ class YetiDriver : public Everest::ModuleBase {
Everest::Thread telemetryThreadHandle;
void error_handling(ErrorFlags e);
ErrorFlags last_error_flags;

std::atomic_bool error_MREC2GroundFailure{false};
std::atomic_bool error_MREC1ConnectorLockFailure{false};
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
};

Expand Down
17 changes: 6 additions & 11 deletions modules/YetiDriver/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,15 @@ config:
minimum: 9600
maximum: 230400
default: 115200
control_mode:
description: none, high or low
reset_gpio_chip:
description: >-
Reset GPIO chip to use to HW reset Yeti. If set to empty string, it is disabled.
type: string
enum:
- none
- high
- low
default: low
default: 'gpiochip0'
reset_gpio:
description: Reset GPIO number to use to HW reset Yeti. If set <0 it is disabled.
description: GPIO line to use to reset Yeti
type: integer
minimum: -1
maximum: 1000
default: -1
default: 27
caps_min_current_A:
description: Minimal current on AC side. For AC this is typically 6, but for HLC this can be less. -1 means use limit reported by HW.
type: integer
Expand Down
1 change: 1 addition & 0 deletions modules/YetiDriver/yeti_comms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ target_link_libraries(yeti_comms
PRIVATE
Pal::Sigslot
everest::framework
everest::gpio
)
37 changes: 17 additions & 20 deletions modules/YetiDriver/yeti_comms/evSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <everest/3rd_party/nanopb/pb_decode.h>
#include <everest/3rd_party/nanopb/pb_encode.h>

#include <gpio.hpp>

#include "yeti.pb.h"

evSerial::evSerial() {
Expand Down Expand Up @@ -83,11 +85,11 @@ bool evSerial::setSerialAttributes() {
// disable IGNBRK for mismatched speed tests; otherwise receive break
// as \000 chars
tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IXANY);
tty.c_lflag = 0; // no signaling chars, no echo,
// no canonical processing
tty.c_oflag = 0; // no remapping, no delays
tty.c_cc[VMIN] = 0; // read blocks
tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout
tty.c_lflag = 0; // no signaling chars, no echo,
// no canonical processing
tty.c_oflag = 0; // no remapping, no delays
tty.c_cc[VMIN] = 0; // read blocks
tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout

tty.c_cflag |= (CLOCAL | CREAD); // ignore modem controls,
// enable reading
Expand Down Expand Up @@ -334,26 +336,21 @@ void evSerial::forceUnlock() {
linkWrite(&msg_out);
}

bool evSerial::reset(const int reset_pin) {
bool evSerial::reset(const std::string& reset_chip, const int reset_line) {

reset_done_flag = false;
forced_reset = true;

if (reset_pin > 0) {
if (not reset_chip.empty()) {
// Try to hardware reset Yeti controller to be in a known state
char cmd[100];
sprintf(cmd, "echo %i >/sys/class/gpio/export", reset_pin);
system(cmd);
sprintf(cmd, "echo out > /sys/class/gpio/gpio%i/direction", reset_pin);
system(cmd);
sprintf(cmd, "echo 0 > /sys/class/gpio/gpio%i/value", reset_pin);
system(cmd);

// clear uart input and output buffer
// tcflush(fd, TCIOFLUSH);

sprintf(cmd, "echo 1 > /sys/class/gpio/gpio%i/value", reset_pin);
system(cmd);
Everest::Gpio reset_gpio;
reset_gpio.open(reset_chip, reset_line);
reset_gpio.set_output(true);
reset_gpio.set(true);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
reset_gpio.set(false);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
reset_gpio.set(true);
} else {
// Try to soft reset Yeti controller to be in a known state
EverestToMcu msg_out = EverestToMcu_init_default;
Expand Down
2 changes: 1 addition & 1 deletion modules/YetiDriver/yeti_comms/evSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class evSerial {
void readThread();
void run();

bool reset(const int reset_pin);
bool reset(const std::string& reset_chip, const int reset_line);
void firmwareUpdate(bool rom);
void keepAlive();

Expand Down

0 comments on commit a6303d0

Please sign in to comment.