From a6303d06bd55215fd597ec98d7cceeb72a9b04d0 Mon Sep 17 00:00:00 2001 From: Cornelius Claussen Date: Mon, 25 Mar 2024 14:24:06 +0100 Subject: [PATCH] Use GPIO lib for reset GPIO, clear errors only if they were raised Signed-off-by: Cornelius Claussen --- modules/YetiDriver/CMakeLists.txt | 1 - modules/YetiDriver/YetiDriver.cpp | 16 +++++++-- modules/YetiDriver/YetiDriver.hpp | 5 ++- modules/YetiDriver/manifest.yaml | 17 ++++----- modules/YetiDriver/yeti_comms/CMakeLists.txt | 1 + modules/YetiDriver/yeti_comms/evSerial.cpp | 37 +++++++++----------- modules/YetiDriver/yeti_comms/evSerial.h | 2 +- 7 files changed, 42 insertions(+), 37 deletions(-) diff --git a/modules/YetiDriver/CMakeLists.txt b/modules/YetiDriver/CMakeLists.txt index 3948560755..f146f32aa8 100644 --- a/modules/YetiDriver/CMakeLists.txt +++ b/modules/YetiDriver/CMakeLists.txt @@ -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 diff --git a/modules/YetiDriver/YetiDriver.cpp b/modules/YetiDriver/YetiDriver.cpp index 435611dfa2..87263f4692 100644 --- a/modules/YetiDriver/YetiDriver.cpp +++ b/modules/YetiDriver/YetiDriver.cpp @@ -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.")); } @@ -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) { @@ -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) { @@ -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) { diff --git a/modules/YetiDriver/YetiDriver.hpp b/modules/YetiDriver/YetiDriver.hpp index b30f172008..462368c0cf 100644 --- a/modules/YetiDriver/YetiDriver.hpp +++ b/modules/YetiDriver/YetiDriver.hpp @@ -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; }; @@ -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 }; diff --git a/modules/YetiDriver/manifest.yaml b/modules/YetiDriver/manifest.yaml index d4b53adf85..cd1f738e20 100644 --- a/modules/YetiDriver/manifest.yaml +++ b/modules/YetiDriver/manifest.yaml @@ -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 diff --git a/modules/YetiDriver/yeti_comms/CMakeLists.txt b/modules/YetiDriver/yeti_comms/CMakeLists.txt index 15d4ed5a08..fa2f84cc9d 100644 --- a/modules/YetiDriver/yeti_comms/CMakeLists.txt +++ b/modules/YetiDriver/yeti_comms/CMakeLists.txt @@ -27,4 +27,5 @@ target_link_libraries(yeti_comms PRIVATE Pal::Sigslot everest::framework + everest::gpio ) diff --git a/modules/YetiDriver/yeti_comms/evSerial.cpp b/modules/YetiDriver/yeti_comms/evSerial.cpp index 59fb5a2ad9..c19d6b92fe 100644 --- a/modules/YetiDriver/yeti_comms/evSerial.cpp +++ b/modules/YetiDriver/yeti_comms/evSerial.cpp @@ -18,6 +18,8 @@ #include #include +#include + #include "yeti.pb.h" evSerial::evSerial() { @@ -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 @@ -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; diff --git a/modules/YetiDriver/yeti_comms/evSerial.h b/modules/YetiDriver/yeti_comms/evSerial.h index e6716e6a2b..d668569f77 100644 --- a/modules/YetiDriver/yeti_comms/evSerial.h +++ b/modules/YetiDriver/yeti_comms/evSerial.h @@ -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();