diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index fbd8e81..b0d301f 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -7,7 +7,7 @@ name: CMake # Define the workflow's triggers on: pull_request: - branches: [ main ] + branches: [main] # Set necessary environment variables env: @@ -30,20 +30,25 @@ jobs: - name: Install Compiler and Linter run: | sudo apt-get install gcc-arm-none-eabi - sudo apt-get install clang-format-12 - sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-12 10000 + sudo apt-get install clang-format-15 + sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 10000 # Build the code for all supported chips - - name: F302 Build - run: | - cmake -DTARGET_DEV=STM32F302x8 -B ${{github.workspace}}/build - cmake --build ${{github.workspace}}/build +# - name: F302 Build +# run: | +# cmake -DTARGET_DEV=STM32F302x8 -B ${{github.workspace}}/build +# cmake --build ${{github.workspace}}/build - name: F334 Build run: | cmake -DTARGET_DEV=STM32F334x8 -B ${{github.workspace}}/build cmake --build ${{github.workspace}}/build +# - name: F446 Build +# run: | +# cmake -DTARGET_DEV=STM32F446xx -B ${{github.workspace}}/build +# cmake --build ${{github.workspace}}/build + # Apply clang-format formatting to the branch and create a new commit if any files are changed - name: Apply Formatting run: | @@ -57,4 +62,4 @@ jobs: git config --global user.name "GitHub Build" git commit -a -m "Applied Formatting Changes During GitHub Build" git push origin - fi \ No newline at end of file + fi diff --git a/CMakeLists.txt b/CMakeLists.txt index 6192f65..92fb4c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,9 +4,9 @@ cmake_minimum_required(VERSION 3.15) # Convert CMake flags to compiler flags -if(EVT_CORE_LOG_ENABLE) +if (EVT_CORE_LOG_ENABLE) add_compile_definitions(EVT_CORE_LOG_ENABLE) -endif() +endif () # Allow for up to 8 CANopen TPDOs add_compile_definitions(CO_TPDO_N=8) @@ -23,11 +23,11 @@ add_compile_definitions(USE_HAL_DRIVER) # Handle Selection of the target device option(TARGET_DEV "Target device" "STM32F302x8") -if(NOT TARGET_DEV) +if (NOT TARGET_DEV) set(TARGET_DEV "STM32F334x8") -endif() +endif () -set(EVT_CORE_DIR ${CMAKE_SOURCE_DIR}/libs/EVT-core) +set(EVT_CORE_DIR ${CMAKE_SOURCE_DIR}/libs/EVT-core) # Link to the EVT-core library add_subdirectory(libs/EVT-core/) @@ -39,11 +39,11 @@ include(${EVT_CORE_DIR}/cmake/evt-core_install.cmake) ############################################################################### # Project Setup ############################################################################### -set(BOARD_LIB_NAME BMS) -if("${BOARD_LIB_NAME}" STREQUAL BOARD_NAME) +set(BOARD_LIB_NAME BMS) +if ("${BOARD_LIB_NAME}" STREQUAL BOARD_NAME) message(FATAL_ERROR "You must set the template project name in the top-level CMakeLists.txt") -endif() +endif () file(STRINGS version.txt BOARD_VERSION) @@ -56,14 +56,14 @@ add_library(${PROJECT_NAME} STATIC) # Add sources target_sources(${PROJECT_NAME} PRIVATE - src/BMS.cpp - src/BQSettingStorage.cpp - src/BQSetting.cpp - src/ResetHandler.cpp - src/SystemDetect.cpp - src/dev/BQ76952.cpp - src/dev/Interlock.cpp - src/dev/ThermistorMux.cpp + src/BMS.cpp + src/BQSettingStorage.cpp + src/BQSetting.cpp + src/ResetHandler.cpp + src/SystemDetect.cpp + src/dev/BQ76952.cpp + src/dev/Interlock.cpp + src/dev/ThermistorMux.cpp ) ############################################################################### @@ -71,7 +71,7 @@ target_sources(${PROJECT_NAME} PRIVATE ############################################################################### target_link_libraries(${PROJECT_NAME} PUBLIC EVT - ) +) ############################################################################### # Install and expose library diff --git a/include/BMS.hpp b/include/BMS.hpp index 6e68b5b..85452b3 100644 --- a/include/BMS.hpp +++ b/include/BMS.hpp @@ -1,21 +1,19 @@ #pragma once -#include - -#include -#include -#include +#include +#include +#include +#include #include #include -#include -#include #include #include + #include #include -namespace IO = EVT::core::IO; +namespace IO = core::io; namespace BMS { @@ -58,11 +56,13 @@ class BMS : public CANDevice { static constexpr IO::Pin CAN_RX_PIN = IO::Pin::PA_11; static constexpr IO::Pin I2C_SCL_PIN = IO::Pin::PB_6; static constexpr IO::Pin I2C_SDA_PIN = IO::Pin::PB_7; - static constexpr IO::Pin INTERLOCK_PIN = IO::Pin::PA_3; + static constexpr IO::Pin INTERLOCK_PIN = IO::Pin::PF_0; static constexpr IO::Pin TEMP_INPUT_PIN = IO::Pin::PA_0; static constexpr IO::Pin MUX_S1_PIN = IO::Pin::PA_15; static constexpr IO::Pin MUX_S2_PIN = IO::Pin::PB_4; static constexpr IO::Pin MUX_S3_PIN = IO::Pin::PA_8; + static constexpr IO::Pin ERROR_LED_PIN = IO::Pin::PA_7; + static constexpr IO::Pin BQ_RESET_PIN = IO::Pin::PB_1; /** Error values */ static constexpr uint8_t BQ_COMM_ERROR = 0x01; @@ -72,18 +72,20 @@ class BMS : public CANDevice { /** * Make a new instance of the BMS with the given devices * - * @param bqSettingsStorage Object used to manage BQ settings storage - * @param bq BQ chip instance - * @param interlock GPIO used to check the interlock status - * @param alarm GPIO used to check the BQ alarm status - * @param systemDetect Object used to detect what system the BMS is connected to - * @param bmsOK GPIO used to output the OK signal from the BMS - * @param thermMux MUX for pack thermistors - * @param resetHandler Handler for reset messages - */ - BMS(BQSettingsStorage& bqSettingsStorage, DEV::BQ76952 bq, DEV::Interlock& interlock, - IO::GPIO& alarm, SystemDetect& systemDetect, IO::GPIO& bmsOK, - DEV::ThermistorMux& thermMux, ResetHandler& resetHandler, EVT::core::DEV::IWDG& iwdg); + * @param[in] bqSettingsStorage Object used to manage BQ settings storage + * @param[in] bq BQ chip instance + * @param[in] interlock GPIO used to check the interlock status + * @param[in] alarm GPIO used to check the BQ alarm status + * @param[in] systemDetect Object used to detect what system the BMS is connected to + * @param[in] bmsOK GPIO used to output the OK signal from the BMS + * @param[in] errorLed GPIO used to indicate a BMS error with an LED + * @param[in] thermMux MUX for pack thermistors + * @param[in] resetHandler Handler for reset messages + * @param[in] iwdg Internal watchdog to ensure the BMS code is running without getting stuck + */ + BMS(BQSettingsStorage& bqSettingsStorage, const dev::BQ76952 &bq, dev::Interlock& interlock, + IO::GPIO& alarm, SystemDetect& systemDetect, IO::GPIO& bmsOK, IO::GPIO& errorLed, + const dev::ThermistorMux& thermMux, ResetHandler& resetHandler, core::dev::IWDG& iwdg); /** * The node ID used to identify the device on the CAN network. @@ -185,7 +187,7 @@ class BMS : public CANDevice { /** * Interface to the BQ chip */ - DEV::BQ76952 bq; + dev::BQ76952 bq; /** * The current state of the BMS @@ -195,7 +197,7 @@ class BMS : public CANDevice { /** * The interlock which is used to detect a cable plugged in */ - DEV::Interlock& interlock; + dev::Interlock& interlock; /** * This GPIO is connected to the ALARM pin of the BQ @@ -223,15 +225,20 @@ class BMS : public CANDevice { */ IO::GPIO& bmsOK; + /** + * LED to indicate an error in the BMS + */ + IO::GPIO& errorLed; + /** * Multiplexer to handle pack thermistors */ - DEV::ThermistorMux thermistorMux; + dev::ThermistorMux thermistorMux; /** * Internal watchdog to detect STM hang */ - EVT::core::DEV::IWDG& iwdg; + core::dev::IWDG& iwdg; /** * Boolean flag which represents that a state has just changed @@ -318,7 +325,7 @@ class BMS : public CANDevice { * by reading the voltage from the BQ chip and is then exposed over * CANopen. */ - uint16_t cellVoltage[DEV::BQ76952::NUM_CELLS] = {}; + uint16_t cellVoltage[dev::BQ76952::NUM_CELLS] = {}; /** * Used to store values which the BMS updates. diff --git a/include/BMSCANOpenMacros.hpp b/include/BMSCANOpenMacros.hpp index 75be10f..4c7f11e 100644 --- a/include/BMSCANOpenMacros.hpp +++ b/include/BMSCANOpenMacros.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include /** * This macro creates a TPDO settings object for an extra node on a single diff --git a/include/BQSettingStorage.hpp b/include/BQSettingStorage.hpp index a14d022..2d73c52 100644 --- a/include/BQSettingStorage.hpp +++ b/include/BQSettingStorage.hpp @@ -2,7 +2,7 @@ #include -#include +#include #include #include @@ -37,7 +37,7 @@ class BQSettingsStorage { * @param eeprom EEPROM instance that stores settings * @param bq BQ instance to send settings to */ - BQSettingsStorage(EVT::core::DEV::M24C32& eeprom, DEV::BQ76952& bq); + BQSettingsStorage(core::dev::M24C32& eeprom, dev::BQ76952& bq); /** * Get the number of settings stored for the BQ @@ -94,7 +94,7 @@ class BQSettingsStorage { * * @return The EEPROM instance */ - EVT::core::DEV::M24C32& getEEPROM(); + core::dev::M24C32& getEEPROM(); /** * Reset the transfer setting logic @@ -126,7 +126,7 @@ class BQSettingsStorage { * @param[out] isComplete Flag that represents all settings have been transferred * @return The resulting status of the transfer operation */ - BMS::DEV::BQ76952::Status transferSetting(bool& isComplete); + dev::BQ76952::Status transferSetting(bool& isComplete); /** * Check if the settings are stored and can be used @@ -158,11 +158,11 @@ class BQSettingsStorage { /** * EEPROM for storing the BQ settings. */ - EVT::core::DEV::M24C32& eeprom; + core::dev::M24C32& eeprom; /** * The BQ chip interface */ - DEV::BQ76952& bq; + dev::BQ76952& bq; /** * This is a count of the number of settings that have been written into * EEPROM. This is used for determining if all the settings have been @@ -175,7 +175,7 @@ class BQSettingsStorage { */ uint16_t numSettingsTransferred = 0; - friend class BMS; + friend class bms; }; }// namespace BMS diff --git a/include/ResetHandler.hpp b/include/ResetHandler.hpp index ddddfee..629eb3a 100644 --- a/include/ResetHandler.hpp +++ b/include/ResetHandler.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace BMS { @@ -19,7 +19,7 @@ class ResetHandler { * * @param msg Message to register */ - void registerInput(EVT::core::IO::CANMessage msg); + void registerInput(core::io::CANMessage msg); /** * Check whether reset messages have been received, indicating that the BMS @@ -43,7 +43,7 @@ class ResetHandler { {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; /** Array of last MSG_HIST_LEN messages received */ - EVT::core::IO::CANMessage msgHistory[MSG_HIST_LEN] = {}; + core::io::CANMessage msgHistory[MSG_HIST_LEN] = {}; /** Index of the last registered message */ uint8_t lastRegMsgIndex = 0; }; diff --git a/include/dev/BQ76952.hpp b/include/dev/BQ76952.hpp index db91b2f..6bdca65 100644 --- a/include/dev/BQ76952.hpp +++ b/include/dev/BQ76952.hpp @@ -1,13 +1,14 @@ #pragma once -#include +#include +#include #include #include #include -namespace BMS::DEV { +namespace BMS::dev { /** * Represents the functionality of the BQ76952. This is a layer of abstraction @@ -48,8 +49,9 @@ class BQ76952 { * * @param[in] i2c I2C interface to use to communicate on the bus * @param[in] i2cAddress The address of the BQ76952 to use + * @param[in] resetPin GPIO instance to reset the BQ */ - BQ76952(EVT::core::IO::I2C& i2c, uint8_t i2cAddress); + BQ76952(core::io::I2C& i2c, uint8_t i2cAddress, core::io::GPIO& resetPin); /** * Write out the given setting @@ -225,6 +227,11 @@ class BQ76952 { */ Status getBQStatus(uint8_t bqStatusArr[7]); + /** + * Reset the BQ + */ + void reset(); + /** CANopen interface for probing the state of the balancing */ //CO_OBJ_TYPE balancingCANOpen; @@ -278,9 +285,11 @@ class BQ76952 { static constexpr uint16_t BQ_ID = 0x7695; /** I2C bus to communicate over */ - EVT::core::IO::I2C& i2c; - /** The address of the BQ76952 on the I2C bus */ + core::io::I2C& i2c; + /** The address of the BQ on the I2C bus */ uint8_t i2cAddress; + /** Reset pin of the BQ */ + core::io::GPIO& resetPin; }; -}// namespace BMS::DEV +}// namespace BMS::dev diff --git a/include/dev/Interlock.hpp b/include/dev/Interlock.hpp index a29ca28..abf61b7 100644 --- a/include/dev/Interlock.hpp +++ b/include/dev/Interlock.hpp @@ -1,8 +1,8 @@ #pragma once -#include +#include -namespace BMS::DEV { +namespace BMS::dev { /** * Represents the interlock which detects if the battery is has a cable @@ -16,7 +16,7 @@ class Interlock { * * @pre The GPIO is set as an input */ - explicit Interlock(EVT::core::IO::GPIO& gpio); + explicit Interlock(core::io::GPIO& gpio); /** * See if a cable is detected in the interlock @@ -25,10 +25,10 @@ class Interlock { private: /** Active high state of the detect GPIO */ - static constexpr EVT::core::IO::GPIO::State ACTIVE_STATE = EVT::core::IO::GPIO::State::HIGH; + static constexpr core::io::GPIO::State ACTIVE_STATE = core::io::GPIO::State::HIGH; /** GPIO which is used to read the detect state */ - EVT::core::IO::GPIO& gpio; + core::io::GPIO& gpio; }; -}// namespace BMS::DEV +}// namespace BMS::dev diff --git a/include/dev/ThermistorMux.hpp b/include/dev/ThermistorMux.hpp index 491dde9..0ce809e 100644 --- a/include/dev/ThermistorMux.hpp +++ b/include/dev/ThermistorMux.hpp @@ -1,13 +1,13 @@ #pragma once -#include -#include -#include +#include +#include +#include -namespace IO = EVT::core::IO; -namespace time = EVT::core::time; +namespace IO = core::io; +namespace time = core::time; -namespace BMS::DEV { +namespace BMS::dev { /** * Multiplexer connected to thermistors @@ -34,7 +34,7 @@ class ThermistorMux { /** Array of MUX select pins */ IO::GPIO* muxSelectArr[3]; /** Thermistor instance to read the temperatures with */ - EVT::core::DEV::Thermistor therm; + core::dev::Thermistor therm; /** * Conversion equation from ADC counts to temperature in Celsius @@ -54,4 +54,4 @@ class ThermistorMux { } }; -}// namespace BMS::DEV +}// namespace BMS::dev diff --git a/libs/EVT-core b/libs/EVT-core index b46eedf..39b624b 160000 --- a/libs/EVT-core +++ b/libs/EVT-core @@ -1 +1 @@ -Subproject commit b46eedfd6429d9054fc271cdf9cf90d7774c6bc3 +Subproject commit 39b624b162a1b60c4e985a5a52ea63e68d3057fd diff --git a/src/BMS.cpp b/src/BMS.cpp index b4647e1..852ee94 100644 --- a/src/BMS.cpp +++ b/src/BMS.cpp @@ -1,22 +1,26 @@ #include -#include -#include +#include +#include #include -namespace time = EVT::core::time; -namespace log = EVT::core::log; +#include + +namespace time = core::time; +namespace log = core::log; namespace BMS { -BMS::BMS(BQSettingsStorage& bqSettingsStorage, DEV::BQ76952 bq, - DEV::Interlock& interlock, IO::GPIO& alarm, SystemDetect& systemDetect, - IO::GPIO& bmsOK, DEV::ThermistorMux& thermMux, - ResetHandler& resetHandler, EVT::core::DEV::IWDG& iwdg) : bqSettingsStorage(bqSettingsStorage), +BMS::BMS(BQSettingsStorage& bqSettingsStorage, const dev::BQ76952 &bq, + dev::Interlock& interlock, IO::GPIO& alarm, SystemDetect& systemDetect, + IO::GPIO& bmsOK, IO::GPIO& errorLed, const dev::ThermistorMux& thermMux, + ResetHandler& resetHandler, core::dev::IWDG& iwdg) : bqSettingsStorage(bqSettingsStorage), bq(bq), state(State::START), interlock(interlock), alarm(alarm), systemDetect(systemDetect), resetHandler(resetHandler), - bmsOK(bmsOK), thermistorMux(thermMux), iwdg(iwdg), stateChanged(true) { + bmsOK(bmsOK), errorLed(errorLed), thermistorMux(thermMux), + iwdg(iwdg), stateChanged(true) { bmsOK.writePin(IO::GPIO::State::LOW); + errorLed.writePin(IO::GPIO::State::LOW); updateBQData(); } @@ -144,7 +148,7 @@ void BMS::startState() { .temp1 = 0, .temp2 = 0, }; - memset(thermistorTemperature, 0, DEV::BQ76952::NUM_CELLS * sizeof(uint16_t)); + memset(thermistorTemperature, 0, dev::BQ76952::NUM_CELLS * sizeof(uint16_t)); memset(bqStatusArr, 0, sizeof(uint8_t) * 3); errorRegister = 0; lastCheckedThermNum = -1; @@ -163,8 +167,8 @@ void BMS::startState() { } // Check to see if communication is possible with the BQ chip - DEV::BQ76952::Status status = bq.communicationStatus(); - if (status != DEV::BQ76952::Status::OK) { + dev::BQ76952::Status status = bq.communicationStatus(); + if (status != dev::BQ76952::Status::OK) { // Increment the number of errors that have taken place numBqAttemptsMade++; @@ -194,6 +198,7 @@ void BMS::startState() { void BMS::initializationErrorState() { if (stateChanged) { bmsOK.writePin(BMS_NOT_OK); + errorLed.writePin(IO::GPIO::State::HIGH); stateChanged = false; clearVoltageReadings(); log::LOGGER.log(log::Logger::LogLevel::INFO, "Entering initialization error state"); @@ -202,6 +207,8 @@ void BMS::initializationErrorState() { updateThermistorReading(); if (resetHandler.shouldReset()) { + bq.reset(); + errorLed.writePin(IO::GPIO::State::LOW); state = State::START; stateChanged = true; } @@ -244,7 +251,7 @@ void BMS::transferSettingsState() { bool isComplete = false; auto result = bqSettingsStorage.transferSetting(isComplete); - if (result != DEV::BQ76952::Status::OK) { + if (result != dev::BQ76952::Status::OK) { numBqAttemptsMade++; // If the number of errors are over the max @@ -302,6 +309,7 @@ void BMS::systemReadyState() { void BMS::unsafeConditionsError() { if (stateChanged) { bmsOK.writePin(BMS_NOT_OK); + errorLed.writePin(IO::GPIO::State::HIGH); stateChanged = false; log::LOGGER.log(log::Logger::LogLevel::INFO, "Entering unsafe conditions state"); } @@ -310,6 +318,8 @@ void BMS::unsafeConditionsError() { updateThermistorReading(); if (resetHandler.shouldReset()) { + bq.reset(); + errorLed.writePin(IO::GPIO::State::LOW); state = State::START; stateChanged = true; } @@ -390,25 +400,25 @@ void BMS::updateBQData() { } } - DEV::BQ76952::Status result = bq.getCellVoltage(cellVoltage, totalVoltage, voltageInfo); + dev::BQ76952::Status result = bq.getCellVoltage(cellVoltage, totalVoltage, voltageInfo); - if (result == DEV::BQ76952::Status::OK) { + if (result == dev::BQ76952::Status::OK) { result = bq.getTotalVoltage(batteryVoltage); } - if (result == DEV::BQ76952::Status::OK) { + if (result == dev::BQ76952::Status::OK) { result = bq.getCurrent(current); } - if (result == DEV::BQ76952::Status::OK) { + if (result == dev::BQ76952::Status::OK) { result = bq.getTemps(bqTempInfo); } - if (result == DEV::BQ76952::Status::OK) { + if (result == dev::BQ76952::Status::OK) { result = bq.getBQStatus(bqStatusArr); } - if (result != DEV::BQ76952::Status::OK) { + if (result != dev::BQ76952::Status::OK) { numBqAttemptsMade++; // If the number of errors are over the max @@ -474,7 +484,7 @@ void BMS::clearVoltageReadings() { voltageInfo = {0, 0, 0, 0}; // Zero out all cell voltages - memset(cellVoltage, 0, DEV::BQ76952::NUM_CELLS * sizeof(uint16_t)); + memset(cellVoltage, 0, dev::BQ76952::NUM_CELLS * sizeof(uint16_t)); } }// namespace BMS diff --git a/src/BQSetting.cpp b/src/BQSetting.cpp index 37fb3de..677fbb4 100644 --- a/src/BQSetting.cpp +++ b/src/BQSetting.cpp @@ -1,8 +1,8 @@ #include -#include +#include -namespace log = EVT::core::log; +namespace log = core::log; namespace BMS { diff --git a/src/BQSettingStorage.cpp b/src/BQSettingStorage.cpp index ae3df35..e8b355f 100644 --- a/src/BQSettingStorage.cpp +++ b/src/BQSettingStorage.cpp @@ -1,8 +1,8 @@ #include -#include +#include -namespace log = EVT::core::log; +namespace log = core::log; /////////////////////////////////////////////////////////////////////////////// // Functions for interacting with the BQSettingsStorage through CANopen @@ -141,7 +141,7 @@ namespace log = EVT::core::log; namespace BMS { -BQSettingsStorage::BQSettingsStorage(EVT::core::DEV::M24C32& eeprom, DEV::BQ76952& bq) ://canOpenInterface{ +BQSettingsStorage::BQSettingsStorage(core::dev::M24C32& eeprom, dev::BQ76952& bq) ://canOpenInterface{ // COBQSettingSize, // COBQSettingCtrl, // COBQSettingRead, @@ -167,10 +167,10 @@ void BQSettingsStorage::setNumSettings(uint32_t numSettings) { } void BQSettingsStorage::readSetting(BQSetting& setting) { - uint8_t buffer[BMS::BQSetting::ARRAY_SIZE]; + uint8_t buffer[BQSetting::ARRAY_SIZE]; eeprom.readBytes(addressLocation, - buffer, BMS::BQSetting::ARRAY_SIZE); + buffer, BQSetting::ARRAY_SIZE); log::LOGGER.log(log::Logger::LogLevel::DEBUG, "Address Location: %u", addressLocation); @@ -199,10 +199,10 @@ void BQSettingsStorage::writeSetting(BQSetting& setting) { addressLocation); // Write the array of data into the EEPROM eeprom.writeBytes(addressLocation, - buffer, BMS::BQSetting::ARRAY_SIZE); + buffer, BQSetting::ARRAY_SIZE); // Increment where to write to next - addressLocation += BMS::BQSetting::ARRAY_SIZE; + addressLocation += BQSetting::ARRAY_SIZE; // Increment the number of settings that have been written numSettingsWritten += 1; @@ -227,11 +227,11 @@ void BQSettingsStorage::resetTransfer() { resetEEPROMOffset(); } -BMS::DEV::BQ76952::Status BQSettingsStorage::transferSetting(bool& isComplete) { +dev::BQ76952::Status BQSettingsStorage::transferSetting(bool& isComplete) { // If all settings have already been transferred, do nothing if (numSettingsTransferred == numSettings) { isComplete = true; - return BMS::DEV::BQ76952::Status::OK; + return dev::BQ76952::Status::OK; } if (numSettingsTransferred == 0) { @@ -239,13 +239,13 @@ BMS::DEV::BQ76952::Status BQSettingsStorage::transferSetting(bool& isComplete) { } // Otherwise transfer a single setting - BMS::DEV::BQ76952::Status status; + dev::BQ76952::Status status; BQSetting setting; readSetting(setting); status = bq.writeSetting(setting); // Make sure the status was ok - if (status != BMS::DEV::BQ76952::Status::OK) { + if (status != dev::BQ76952::Status::OK) { isComplete = false; log::LOGGER.log(log::Logger::LogLevel::ERROR, @@ -264,7 +264,7 @@ BMS::DEV::BQ76952::Status BQSettingsStorage::transferSetting(bool& isComplete) { if (isComplete) { bq.exitConfigUpdateMode(); } - return BMS::DEV::BQ76952::Status::OK; + return dev::BQ76952::Status::OK; } bool BQSettingsStorage::hasSettings() { diff --git a/src/ResetHandler.cpp b/src/ResetHandler.cpp index 297af92..18db4db 100644 --- a/src/ResetHandler.cpp +++ b/src/ResetHandler.cpp @@ -1,18 +1,18 @@ #include -namespace IO = EVT::core::IO; +namespace io = core::io; namespace BMS { ResetHandler::ResetHandler() = default; -void ResetHandler::registerInput(IO::CANMessage msg) { +void ResetHandler::registerInput(io::CANMessage msg) { lastRegMsgIndex = (lastRegMsgIndex + 1) % MSG_HIST_LEN; msgHistory[lastRegMsgIndex] = msg; } bool ResetHandler::shouldReset() { - for (IO::CANMessage msg : msgHistory) { + for (io::CANMessage msg : msgHistory) { if (msg.getId() != RESET_ID || msg.getDataLength() != RESET_ARR_LEN) { return false; } @@ -27,7 +27,7 @@ bool ResetHandler::shouldReset() { // Clear message history for (uint8_t i = 0; i < MSG_HIST_LEN; i++) { - msgHistory[i] = IO::CANMessage(); + msgHistory[i] = io::CANMessage(); } return true; diff --git a/src/SystemDetect.cpp b/src/SystemDetect.cpp index 5b825f1..1d7a6be 100644 --- a/src/SystemDetect.cpp +++ b/src/SystemDetect.cpp @@ -1,8 +1,8 @@ #include -#include +#include -namespace time = EVT::core::time; +namespace time = core::time; namespace BMS { diff --git a/src/dev/BQ76952.cpp b/src/dev/BQ76952.cpp index 7b145fb..1a2e097 100644 --- a/src/dev/BQ76952.cpp +++ b/src/dev/BQ76952.cpp @@ -1,14 +1,14 @@ #include -#include -#include +#include +#include #include #include // (void)0 is added to the end of each macro to force users to follow the macro with a ';' /// Macro to make an I2C transfer and return an error on failure #define BQ_I2C_RETURN_IF_ERR(func) \ - if (func != EVT::core::IO::I2C::I2CStatus::OK) { \ + if (func != core::io::I2C::I2CStatus::OK) { \ return Status::I2C_ERROR; \ } \ (void) 0 @@ -18,7 +18,7 @@ { \ Status result_ = func; \ if (result_ != Status::OK) { \ - EVT::core::log::LOGGER.log(EVT::core::log::Logger::LogLevel::ERROR, "BQ ERROR: %d", \ + core::log::LOGGER.log(core::log::Logger::LogLevel::ERROR, "BQ ERROR: %d", \ (uint8_t) result_); \ return result_; \ } \ @@ -77,12 +77,12 @@ static CO_ERR COBQBalancingRead(CO_OBJ_T* obj, CO_NODE_T* node, void* buf, auto targetCell = static_cast(obj->Data); - auto* bq = (BMS::DEV::BQ76952*) priv; + auto* bq = (bms::dev::BQ76952*) priv; bool isBalancing = false; - BMS::DEV::BQ76952::Status status = bq->isBalancing(targetCell, &isBalancing); + bms::dev::BQ76952::Status status = bq->isBalancing(targetCell, &isBalancing); - if (status != BMS::DEV::BQ76952::Status::OK) { + if (status != bms::dev::BQ76952::Status::OK) { return CO_ERR_OBJ_READ; } @@ -113,14 +113,14 @@ static CO_ERR COBQBalancingWrite(CO_OBJ_T* obj, CO_NODE_T* node, void* buf, auto targetCell = static_cast(obj->Data); - auto* bq = (BMS::DEV::BQ76952*) priv; + auto* bq = (bms::dev::BQ76952*) priv; uint8_t balancingState = *(uint8_t*) buf; balancingState = balancingState > 0 ? 1 : 0; - BMS::DEV::BQ76952::Status status = bq->setBalancing(targetCell, balancingState); + bms::dev::BQ76952::Status status = bq->setBalancing(targetCell, balancingState); - if (status != BMS::DEV::BQ76952::Status::OK) { + if (status != bms::dev::BQ76952::Status::OK) { return CO_ERR_OBJ_WRITE; } @@ -143,9 +143,9 @@ static CO_ERR COBalancingCtrl(CO_OBJ* obj, CO_NODE_T* node, uint16_t func, return CO_ERR_NONE; } */ -namespace BMS::DEV { +namespace BMS::dev { -BQ76952::BQ76952(EVT::core::IO::I2C& i2c, uint8_t i2cAddress) : /* +BQ76952::BQ76952(core::io::I2C& i2c, uint8_t i2cAddress, core::io::GPIO& resetPin) : /* balancingCANOpen{ COBQBalancingSize, COBalancingCtrl, @@ -154,12 +154,15 @@ BQ76952::BQ76952(EVT::core::IO::I2C& i2c, uint8_t i2cAddress) : /* this, }, */ - i2c(i2c), i2cAddress(i2cAddress) {} + i2c(i2c), i2cAddress(i2cAddress), resetPin(resetPin) { + // Ensure the pin is initialized to low, so it doesn't reset or shut down the BQ + resetPin.writePin(core::io::GPIO::State::LOW); +} -BQ76952::Status BQ76952::writeSetting(BMS::BQSetting& setting) { +BQ76952::Status BQ76952::writeSetting(BQSetting& setting) { // Right now, the BQ only accepts settings made into RAM - if (setting.getSettingType() != BMS::BQSetting::BQSettingType::RAM) { - EVT::core::log::LOGGER.log(EVT::core::log::Logger::LogLevel::ERROR, "Setting type is incorrect"); + if (setting.getSettingType() != BQSetting::BQSettingType::RAM) { + core::log::LOGGER.log(core::log::Logger::LogLevel::ERROR, "Setting type is incorrect"); return Status::ERROR; } return writeRAMSetting(setting); @@ -252,7 +255,7 @@ BQ76952::Status BQ76952::makeRAMRead(uint16_t reg, uint32_t* result) { return Status::OK; } -BQ76952::Status BQ76952::writeRAMSetting(BMS::BQSetting& setting) { +BQ76952::Status BQ76952::writeRAMSetting(BQSetting& setting) { // Array which stores all bytes that make up a RAM write request // transfer[0]: LSB of the address in RAM // transfer[1]: MSB of the address in RAM @@ -299,7 +302,7 @@ BQ76952::Status BQ76952::writeRAMSetting(BMS::BQSetting& setting) { uint16_t address = 0; uint16_t targetAddress = setting.getAddress(); uint16_t rawResponse; - uint32_t startTime = EVT::core::time::millis(); + uint32_t startTime = core::time::millis(); // Try to read back the address that was written out while (address != targetAddress) { @@ -308,7 +311,7 @@ BQ76952::Status BQ76952::writeRAMSetting(BMS::BQSetting& setting) { address = rawResponse; // Check to see if a timeout occurred - if (EVT::core::time::millis() - startTime > TIMEOUT) { + if (core::time::millis() - startTime > TIMEOUT) { return Status::TIMEOUT; } } @@ -495,4 +498,11 @@ BQ76952::Status BQ76952::getBQStatus(uint8_t bqStatusArr[7]) { return BQ76952::Status::OK; } -}// namespace BMS::DEV +void BQ76952::reset() { + resetPin.writePin(core::io::GPIO::State::HIGH); + // Wait an arbitrary amount of time to ensure the BQ actually resets + core::time::wait(10); + resetPin.writePin(core::io::GPIO::State::LOW); +} + +}// namespace BMS::dev diff --git a/src/dev/Interlock.cpp b/src/dev/Interlock.cpp index 90e4e71..57ec52b 100644 --- a/src/dev/Interlock.cpp +++ b/src/dev/Interlock.cpp @@ -1,12 +1,12 @@ #include -namespace BMS::DEV { +namespace BMS::dev { -Interlock::Interlock(EVT::core::IO::GPIO& gpio) : gpio(gpio) {} +Interlock::Interlock(core::io::GPIO& gpio) : gpio(gpio) {} bool Interlock::isDetected() { // TODO: Use debounce for handling potential noise based issues return gpio.readPin() == ACTIVE_STATE; } -}// namespace BMS::DEV +}// namespace BMS::dev diff --git a/src/dev/ThermistorMux.cpp b/src/dev/ThermistorMux.cpp index c335883..80dd544 100644 --- a/src/dev/ThermistorMux.cpp +++ b/src/dev/ThermistorMux.cpp @@ -1,10 +1,10 @@ #include -namespace BMS::DEV { +namespace BMS::dev { ThermistorMux::ThermistorMux(IO::GPIO** muxSelectArr, IO::ADC& adc) : muxSelectArr{ muxSelectArr[0], muxSelectArr[1], muxSelectArr[2]}, - therm(EVT::core::DEV::Thermistor(adc, convert)) {} + therm(core::dev::Thermistor(adc, convert)) {} uint16_t ThermistorMux::getTemp(uint8_t thermNum) { for (uint8_t i = 0; i < 3; i++) { @@ -15,4 +15,4 @@ uint16_t ThermistorMux::getTemp(uint8_t thermNum) { return therm.getTempCelcius(); } -}// namespace BMS::DEV +}// namespace BMS::dev diff --git a/targets/DEV1-BMS/main.cpp b/targets/DEV1-BMS/main.cpp index 93b3bf6..84d5330 100644 --- a/targets/DEV1-BMS/main.cpp +++ b/targets/DEV1-BMS/main.cpp @@ -2,27 +2,27 @@ * This is the main target to be used for the BMS in the DEV1 battery packs */ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include -#include -#include +#include +#include -#include -#include +#include +#include #include #include #include -namespace IO = EVT::core::IO; -namespace DEV = EVT::core::DEV; -namespace time = EVT::core::time; -namespace log = EVT::core::log; +namespace IO = core::io; +namespace DEV = core::dev; +namespace time = core::time; +namespace log = core::log; #define BIKE_HEART_BEAT 0x70A // NODE_ID = 10 #define CHARGER_HEART_BEAT 0x710// NODE_ID = 16 @@ -34,7 +34,7 @@ namespace log = EVT::core::log; * to the interrupt handler. */ struct CANInterruptParams { - EVT::core::types::FixedQueue* queue; + core::types::FixedQueue* queue; BMS::SystemDetect* systemDetect; BMS::ResetHandler* resetHandler; }; @@ -47,8 +47,7 @@ struct CANInterruptParams { void canInterruptHandler(IO::CANMessage& message, void* priv) { struct CANInterruptParams* params = (CANInterruptParams*) priv; - EVT::core::types::FixedQueue* queue = - params->queue; + core::types::FixedQueue* queue = params->queue; BMS::SystemDetect* systemDetect = params->systemDetect; BMS::ResetHandler* resetHandler = params->resetHandler; @@ -64,10 +63,10 @@ void canInterruptHandler(IO::CANMessage& message, void* priv) { int main() { // Initialize system - EVT::core::platform::init(); + core::platform::init(); // Queue that will store CANopen messages - EVT::core::types::FixedQueue canOpenQueue; + core::types::FixedQueue canOpenQueue; // Initialize the system detect BMS::SystemDetect systemDetect(BIKE_HEART_BEAT, CHARGER_HEART_BEAT, @@ -76,7 +75,7 @@ int main() { BMS::ResetHandler resetHandler; // Create struct that will hold CAN interrupt parameters - struct CANInterruptParams canParams = { + CANInterruptParams canParams = { .queue = &canOpenQueue, .systemDetect = &systemDetect, .resetHandler = &resetHandler, @@ -85,27 +84,29 @@ int main() { // Initialize IO // TODO: Investigate adding CAN filters IO::CAN& can = IO::getCAN(); - can.addIRQHandler(canInterruptHandler, reinterpret_cast(&canParams)); - IO::UART& uart = IO::getUART(115200, true); + can.addIRQHandler(canInterruptHandler, &canParams); + + IO::UART& uart = IO::getUART(115200); IO::I2C& i2c = IO::getI2C(); // Initialize the timer DEV::Timer& timer = DEV::getTimer(100); // Initialize the EEPROM - EVT::core::DEV::M24C32 eeprom(0x57, i2c); + DEV::M24C32 eeprom(0x57, i2c); // Initialize the logger log::LOGGER.setUART(&uart); log::LOGGER.setLogLevel(log::Logger::LogLevel::INFO); // Initialize the BQ interfaces - BMS::DEV::BQ76952 bq(i2c, 0x08); + IO::GPIO& bqReset = IO::getGPIO(); + BMS::dev::BQ76952 bq(i2c, 0x08, bqReset); BMS::BQSettingsStorage bqSettingsStorage(eeprom, bq); // Initialize the Interlock IO::GPIO& interlockGPIO = IO::getGPIO(IO::GPIO::Direction::INPUT); - BMS::DEV::Interlock interlock(interlockGPIO); + BMS::dev::Interlock interlock(interlockGPIO); // Initialize the alarm pin IO::GPIO& alarm = IO::getGPIO(IO::GPIO::Direction::INPUT); @@ -113,6 +114,9 @@ int main() { // Initialize the system OK pin IO::GPIO& bmsOK = IO::getGPIO(IO::GPIO::Direction::OUTPUT); + // Initialize the error LED pin + IO::GPIO& errorLed = IO::getGPIO(IO::GPIO::Direction::OUTPUT); + // Initialize the thermistor MUX IO::GPIO* muxSelectArr[3] = { &IO::getGPIO(), @@ -121,12 +125,12 @@ int main() { }; IO::ADC& thermAdc = IO::getADC(); - BMS::DEV::ThermistorMux thermMux(muxSelectArr, thermAdc); + BMS::dev::ThermistorMux thermMux(muxSelectArr, thermAdc); DEV::IWDG& iwdg = DEV::getIWDG(500); // Initialize the BMS itself - BMS::BMS bms(bqSettingsStorage, bq, interlock, alarm, systemDetect, bmsOK, thermMux, resetHandler, iwdg); + BMS::BMS bms(bqSettingsStorage, bq, interlock, alarm, systemDetect, bmsOK, errorLed, thermMux, resetHandler, iwdg); /////////////////////////////////////////////////////////////////////////// // Setup CAN configuration, this handles making drivers, applying settings. @@ -134,38 +138,45 @@ int main() { // between the application (the code we write) and the physical CAN network /////////////////////////////////////////////////////////////////////////// - // Will store CANopen messages that will be populated by the EVT-core CAN - // interrupt - // Reserved memory for CANopen stack usage uint8_t sdoBuffer[CO_SSDO_N * CO_SDO_BUF_BYTE]; CO_TMR_MEM appTmrMem[16]; - // Initialize the CANopen drivers + // Reserve driver variables CO_IF_DRV canStackDriver; + CO_IF_CAN_DRV canDriver; CO_IF_TIMER_DRV timerDriver; CO_IF_NVM_DRV nvmDriver; + CO_NODE canNode; + // Attempt to join the CAN network + IO::CAN::CANStatus result = can.connect(); + + // test that the board is connected to the can network + if (result != IO::CAN::CANStatus::OK) { + log::LOGGER.log(log::Logger::LogLevel::ERROR, "Failed to connect to CAN network\r\n"); + return 1; + } + // Initialize all the CANOpen drivers. IO::initializeCANopenDriver(&canOpenQueue, &can, &timer, &canStackDriver, &nvmDriver, &timerDriver, &canDriver); // Initialize the CANOpen node we are using. IO::initializeCANopenNode(&canNode, &bms, &canStackDriver, sdoBuffer, appTmrMem); - time::wait(500); - // Attempt to join the CAN network - IO::CAN::CANStatus result = can.connect(true); + // Set the node to operational mode + CONmtSetMode(&canNode.Nmt, CO_OPERATIONAL); - if (result != IO::CAN::CANStatus::OK) { - uart.printf("Failed to connect to CAN network\r\n"); + time::wait(500); + + if (CO_ERR canError = CONodeGetErr(&canNode); canError != CO_ERR_NONE) { + log::LOGGER.log(log::Logger::LogLevel::INFO, "CANopen initialization failed %d", canError); return 1; } - CONmtSetMode(&canNode.Nmt, CO_OPERATIONAL); - - log::LOGGER.log(log::Logger::LogLevel::INFO, "Initialization complete"); + log::LOGGER.log(log::Logger::LogLevel::INFO, "CAN initialization complete"); // Main processing loop, contains the following logic // 1. Update CANopen logic and processing incoming messages diff --git a/targets/bms_canopen/main.cpp b/targets/bms_canopen/main.cpp index 0ac50b1..1204d04 100644 --- a/targets/bms_canopen/main.cpp +++ b/targets/bms_canopen/main.cpp @@ -2,26 +2,26 @@ * This is a target used for testing BMS CANopen output */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include -#include +#include +#include -#include -#include +#include +#include #include "SystemDetect.hpp" #include #include -namespace IO = EVT::core::IO; -namespace DEV = EVT::core::DEV; -namespace time = EVT::core::time; -namespace log = EVT::core::log; +namespace io = core::io; +namespace dev = core::dev; +namespace time = core::time; +namespace log = core::log; #define BIKE_HEART_BEAT 0x70A // NODE_ID = 10 #define CHARGER_HEART_BEAT 0x710// NODE_ID = 16 @@ -33,7 +33,7 @@ namespace log = EVT::core::log; * to the interrupt handler. */ struct CANInterruptParams { - EVT::core::types::FixedQueue* queue; + core::types::FixedQueue* queue; BMS::SystemDetect* systemDetect; }; @@ -42,10 +42,10 @@ struct CANInterruptParams { * * @param priv[in] The private data (FixedQueue) */ -void canInterruptHandler(IO::CANMessage& message, void* priv) { +void canInterruptHandler(io::CANMessage& message, void* priv) { struct CANInterruptParams* params = (CANInterruptParams*) priv; - EVT::core::types::FixedQueue* queue = + core::types::FixedQueue* queue = params->queue; BMS::SystemDetect* systemDetect = params->systemDetect; @@ -66,10 +66,10 @@ extern "C" void CONodeFatalError(void) { int main() { // Initialize system - EVT::core::platform::init(); + core::platform::init(); // Queue that will store CANopen messages - EVT::core::types::FixedQueue canOpenQueue; + core::types::FixedQueue canOpenQueue; // Initialize the system detect BMS::SystemDetect systemDetect(BIKE_HEART_BEAT, CHARGER_HEART_BEAT, @@ -83,50 +83,54 @@ int main() { .systemDetect = &systemDetect, }; - // Initialize IO - IO::CAN& can = IO::getCAN(); + // Initialize io + io::CAN& can = io::getCAN(); can.addIRQHandler(canInterruptHandler, reinterpret_cast(&canParams)); - IO::UART& uart = IO::getUART(115200, true); - IO::I2C& i2c = IO::getI2C(); + io::UART& uart = io::getUART(115200); + io::I2C& i2c = io::getI2C(); // Initialize the timer - DEV::Timer& timer = DEV::getTimer(100); + dev::Timer& timer = dev::getTimer(100); // Initialize the EEPROM - EVT::core::DEV::M24C32 eeprom(0x57, i2c); + core::dev::M24C32 eeprom(0x57, i2c); // Initialize the logger log::LOGGER.setUART(&uart); log::LOGGER.setLogLevel(log::Logger::LogLevel::DEBUG); // Initialize the BQ interfaces - BMS::DEV::BQ76952 bq(i2c, 0x08); + io::GPIO& bqReset = io::getGPIO(); + BMS::dev::BQ76952 bq(i2c, 0x08, bqReset); BMS::BQSettingsStorage bqSettingsStorage(eeprom, bq); // Initialize the Interlock - IO::GPIO& interlockGPIO = IO::getGPIO(IO::GPIO::Direction::INPUT); - BMS::DEV::Interlock interlock(interlockGPIO); + io::GPIO& interlockGPIO = io::getGPIO(io::GPIO::Direction::INPUT); + BMS::dev::Interlock interlock(interlockGPIO); // Initialize the alarm pin - IO::GPIO& alarm = IO::getGPIO(IO::GPIO::Direction::INPUT); + io::GPIO& alarm = io::getGPIO(io::GPIO::Direction::INPUT); // Initialize the system OK pin - IO::GPIO& bmsOK = IO::getGPIO(IO::GPIO::Direction::OUTPUT); + io::GPIO& bmsOK = io::getGPIO(io::GPIO::Direction::OUTPUT); + + // Initialize the error LED pin + io::GPIO& errorLed = io::getGPIO(io::GPIO::Direction::OUTPUT); // Initialize the thermistor MUX - IO::GPIO* muxSelectArr[3] = { - &IO::getGPIO(), - &IO::getGPIO(), - &IO::getGPIO(), + io::GPIO* muxSelectArr[3] = { + &io::getGPIO(), + &io::getGPIO(), + &io::getGPIO(), }; - IO::ADC& thermAdc = IO::getADC(); + io::ADC& thermAdc = io::getADC(); - BMS::DEV::ThermistorMux thermMux(muxSelectArr, thermAdc); + BMS::dev::ThermistorMux thermMux(muxSelectArr, thermAdc); - DEV::IWDG& iwdg = DEV::getIWDG(500); + dev::IWDG& iwdg = dev::getIWDG(500); // Initialize the BMS itself - BMS::BMS bms(bqSettingsStorage, bq, interlock, alarm, systemDetect, bmsOK, thermMux, resetHandler, iwdg); + BMS::BMS bms(bqSettingsStorage, bq, interlock, alarm, systemDetect, bmsOK, errorLed, thermMux, resetHandler, iwdg); /////////////////////////////////////////////////////////////////////////// // Setup CAN configuration, this handles making drivers, applying settings. @@ -149,16 +153,16 @@ int main() { CO_NODE canNode; // Initialize all the CANOpen drivers. - IO::initializeCANopenDriver(&canOpenQueue, &can, &timer, &canStackDriver, &nvmDriver, &timerDriver, &canDriver); + io::initializeCANopenDriver(&canOpenQueue, &can, &timer, &canStackDriver, &nvmDriver, &timerDriver, &canDriver); // Initialize the CANOpen node we are using. - IO::initializeCANopenNode(&canNode, &bms, &canStackDriver, sdoBuffer, appTmrMem); + io::initializeCANopenNode(&canNode, &bms, &canStackDriver, sdoBuffer, appTmrMem); time::wait(500); // Attempt to join the CAN network - IO::CAN::CANStatus result = can.connect(true); + io::CAN::CANStatus result = can.connect(true); - if (result != IO::CAN::CANStatus::OK) { + if (result != io::CAN::CANStatus::OK) { uart.printf("Failed to connect to CAN network\r\n"); return 1; } @@ -173,7 +177,7 @@ int main() { // 3. Wait for new data to come in while (1) { // Process CANopen - IO::processCANopenNode(&canNode); + io::processCANopenNode(&canNode); // Update the state of the BMS bms.canTest(); // Wait for new data to come in diff --git a/targets/bq_interface/main.cpp b/targets/bq_interface/main.cpp index fd4dbfc..1f60167 100644 --- a/targets/bq_interface/main.cpp +++ b/targets/bq_interface/main.cpp @@ -5,24 +5,24 @@ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include -namespace IO = EVT::core::IO; -namespace time = EVT::core::time; -namespace log = EVT::core::log; +namespace io = core::io; +namespace time = core::time; +namespace log = core::log; constexpr size_t MAX_BUFF = 100; char inputBuffer[MAX_BUFF]; -void printHelp(IO::UART& uart) { +void printHelp(io::UART& uart) { uart.printf("Available commands:\r\n"); uart.printf(" h - Print this help message\r\n"); uart.printf(" d - Direct read\r\n"); @@ -40,6 +40,7 @@ void printHelp(IO::UART& uart) { uart.printf(" i - Get interlock state\r\n"); uart.printf(" a - Get alarm state\r\n"); uart.printf(" o - Set OK signal output\r\n"); + uart.printf(" e - Set error LED output\r\n"); uart.printf(" v - Read voltages\r\n"); uart.printf(" t - Transfer settings\r\n"); @@ -52,7 +53,7 @@ void printHelp(IO::UART& uart) { * @param[in] uart The UART interface to read in from * @param[in] bq The BQ interface to communicate with */ -void directRead(IO::UART& uart, BMS::DEV::BQ76952& bq) { +void directRead(io::UART& uart, BMS::dev::BQ76952& bq) { uart.printf("Enter the direct address in hex: 0x"); uart.gets(inputBuffer, MAX_BUFF); uart.printf("\r\n"); @@ -63,7 +64,7 @@ void directRead(IO::UART& uart, BMS::DEV::BQ76952& bq) { auto result = bq.makeDirectRead(reg, ®Value); // Make sure the read was successful - if (result != BMS::DEV::BQ76952::Status::OK) { + if (result != BMS::dev::BQ76952::Status::OK) { uart.printf("Failed to read register: 0x%x\r\n", reg); return; } @@ -77,14 +78,14 @@ void directRead(IO::UART& uart, BMS::DEV::BQ76952& bq) { * * @param[in] uart The UART interface to write in from */ -void directWrite(IO::UART& uart) {} +void directWrite(io::UART& uart) {} /** * Function for making an indirect write request * * @param[in] uart The UART interface to write in from */ -void indirectWrite(IO::UART& uart) {} +void indirectWrite(io::UART& uart) {} /** * Function for making a subcommand request @@ -92,7 +93,7 @@ void indirectWrite(IO::UART& uart) {} * @param[in] uart The UART interface to read from * @param[in] bq The BQ interface */ -void subcommandRead(IO::UART& uart, BMS::DEV::BQ76952& bq) { +void subcommandRead(io::UART& uart, BMS::dev::BQ76952& bq) { uart.printf("Enter the subcommand address in hex: 0x"); uart.gets(inputBuffer, MAX_BUFF); uart.printf("\r\n"); @@ -105,7 +106,7 @@ void subcommandRead(IO::UART& uart, BMS::DEV::BQ76952& bq) { auto result = bq.makeSubcommandRead(reg, &subcommandValue); // Make sure the read was successful - if (result != BMS::DEV::BQ76952::Status::OK) { + if (result != BMS::dev::BQ76952::Status::OK) { uart.printf("Failed to read register: 0x%x\r\n", reg); return; } @@ -113,7 +114,7 @@ void subcommandRead(IO::UART& uart, BMS::DEV::BQ76952& bq) { uart.printf("Register 0x%x: 0x%08X\r\n", reg, subcommandValue); } -void commandOnlySub(IO::UART& uart, BMS::DEV::BQ76952& bq) { +void commandOnlySub(io::UART& uart, BMS::dev::BQ76952& bq) { uart.printf("Enter the command-only subcommand address in hex: 0x"); uart.gets(inputBuffer, MAX_BUFF); uart.printf("\r\n"); @@ -125,7 +126,7 @@ void commandOnlySub(IO::UART& uart, BMS::DEV::BQ76952& bq) { auto result = bq.commandOnlySubcommand(reg); // Make sure the read was successful - if (result != BMS::DEV::BQ76952::Status::OK) { + if (result != BMS::dev::BQ76952::Status::OK) { uart.printf("Failed to read register: 0x%x\r\n", reg); return; } @@ -139,7 +140,7 @@ void commandOnlySub(IO::UART& uart, BMS::DEV::BQ76952& bq) { * @param[in] uart The UART interface to read in from * @param[in] bq The BQ interface to use */ -void ramRead(IO::UART& uart, BMS::DEV::BQ76952& bq) { +void ramRead(io::UART& uart, BMS::dev::BQ76952& bq) { uart.printf("Enter the RAM address in hex: 0x"); uart.gets(inputBuffer, MAX_BUFF); uart.printf("\r\n"); @@ -152,7 +153,7 @@ void ramRead(IO::UART& uart, BMS::DEV::BQ76952& bq) { auto result = bq.makeRAMRead(reg, &ramValue); // Make sure the read was successful - if (result != BMS::DEV::BQ76952::Status::OK) { + if (result != BMS::dev::BQ76952::Status::OK) { uart.printf("Failed to read register: 0x%x\r\n", reg); return; } @@ -167,10 +168,10 @@ void ramRead(IO::UART& uart, BMS::DEV::BQ76952& bq) { * * @param[in] uart The UART interface to write in from */ -void ramWrite(IO::UART& uart, BMS::DEV::BQ76952& bq) { +void ramWrite(io::UART& uart, BMS::dev::BQ76952& bq) { bool inConfigMode; auto result = bq.inConfigMode(&inConfigMode); - if (result != BMS::DEV::BQ76952::Status::OK) { + if (result != BMS::dev::BQ76952::Status::OK) { uart.printf("Failed to get if the BQ is in config update mode\r\n"); return; } @@ -220,7 +221,7 @@ void ramWrite(IO::UART& uart, BMS::DEV::BQ76952& bq) { result = bq.writeRAMSetting(setting); - if (result != BMS::DEV::BQ76952::Status::OK) { + if (result != BMS::dev::BQ76952::Status::OK) { uart.printf("Failed to write out RAM setting\r\n"); return; } @@ -239,7 +240,7 @@ void ramWrite(IO::UART& uart, BMS::DEV::BQ76952& bq) { * @param[in] uart The UART interface to read in from * @param[in] bq The BQ interface to use */ -void readBalancing(IO::UART& uart, BMS::DEV::BQ76952& bq) { +void readBalancing(io::UART& uart, BMS::dev::BQ76952& bq) { uart.printf("Enter the cell to read balancing of: "); uart.gets(inputBuffer, MAX_BUFF); uart.printf("\r\n"); @@ -247,7 +248,7 @@ void readBalancing(IO::UART& uart, BMS::DEV::BQ76952& bq) { uint8_t targetCell = strtol(inputBuffer, nullptr, 10); bool isBalancing; - if (bq.isBalancing(targetCell, &isBalancing) != BMS::DEV::BQ76952::Status::OK) { + if (bq.isBalancing(targetCell, &isBalancing) != BMS::dev::BQ76952::Status::OK) { uart.printf("Failed to read balancing state\r\n"); } @@ -260,7 +261,7 @@ void readBalancing(IO::UART& uart, BMS::DEV::BQ76952& bq) { * @param[in] uart The UART interface to read from * @param[in] bq The BQ interface to use */ -void setBalancing(IO::UART& uart, BMS::DEV::BQ76952& bq) { +void setBalancing(io::UART& uart, BMS::dev::BQ76952& bq) { uart.printf("Enter the cell to set balancing of: "); uart.gets(inputBuffer, MAX_BUFF); uart.printf("\r\n"); @@ -273,7 +274,7 @@ void setBalancing(IO::UART& uart, BMS::DEV::BQ76952& bq) { uint8_t targetState = strtol(inputBuffer, nullptr, 10); - if (bq.setBalancing(targetCell, targetState) != BMS::DEV::BQ76952::Status::OK) { + if (bq.setBalancing(targetCell, targetState) != BMS::dev::BQ76952::Status::OK) { uart.printf("Failed to set the state of balancing\r\n"); } } @@ -284,12 +285,12 @@ void setBalancing(IO::UART& uart, BMS::DEV::BQ76952& bq) { * @param[in] uart The interface to print status messages to * @param[in] bq The interface to communicate with the BQ */ -void enterConfigMode(IO::UART& uart, BMS::DEV::BQ76952& bq) { +void enterConfigMode(io::UART& uart, BMS::dev::BQ76952& bq) { uart.printf("Putting the BQ chip into config mode\r\n"); // Attempt to put the BQ into configure update mode auto result = bq.enterConfigUpdateMode(); - if (result != BMS::DEV::BQ76952::Status::OK) { + if (result != BMS::dev::BQ76952::Status::OK) { uart.printf("Failed writing out config update mode\r\n"); return; } @@ -303,12 +304,12 @@ void enterConfigMode(IO::UART& uart, BMS::DEV::BQ76952& bq) { * @param[in] uart The interface to print status messages to * @param[in] bq The interface to communicate with the BQ */ -void exitConfigMode(IO::UART& uart, BMS::DEV::BQ76952& bq) { +void exitConfigMode(io::UART& uart, BMS::dev::BQ76952& bq) { uart.printf("Pulling the BQ chip out of config mode\r\n"); // Attempt to put the BQ into configure update mode auto result = bq.exitConfigUpdateMode(); - if (result != BMS::DEV::BQ76952::Status::OK) { + if (result != BMS::dev::BQ76952::Status::OK) { uart.printf("Failed writing out config update mode\r\n"); return; } @@ -316,10 +317,10 @@ void exitConfigMode(IO::UART& uart, BMS::DEV::BQ76952& bq) { uart.printf("BQ not in config mode\r\n"); } -void getTemperatures(IO::UART& uart, BMS::DEV::BQ76952& bq, BMS::DEV::ThermistorMux tMux) { +void getTemperatures(io::UART& uart, BMS::dev::BQ76952& bq, BMS::dev::ThermistorMux tMux) { for (uint8_t i = 0; i < 6; i++) { uint16_t temp = tMux.getTemp(i); - uart.printf("Thermistor %d: %d.%03d\r\n", i, temp / 1000, temp % 1000); + uart.printf("Thermistor %d: %d\r\n", i, temp); } uint16_t result; bq.makeDirectRead(0x68, &result); @@ -333,28 +334,41 @@ void getTemperatures(IO::UART& uart, BMS::DEV::BQ76952& bq, BMS::DEV::Thermistor uart.printf("BQ Board Temp 2: %d.%01d\r\n", result / 10, result % 10); } -void getInterlock(IO::UART& uart, BMS::DEV::Interlock interlock) { +void getInterlock(io::UART& uart, BMS::dev::Interlock interlock) { uart.printf("Interlock Detected: %s\r\n", interlock.isDetected() ? "true" : "false"); } -void getAlarm(IO::UART& uart, IO::GPIO& alarm) { - uart.printf("Alarm Set: %s\r\n", alarm.readPin() == IO::GPIO::State::HIGH ? "true" : "false"); +void getAlarm(io::UART& uart, io::GPIO& alarm) { + uart.printf("Alarm Set: %s\r\n", alarm.readPin() == io::GPIO::State::HIGH ? "true" : "false"); } -void setOK(IO::UART& uart, IO::GPIO& bmsOK) { +void setOK(io::UART& uart, io::GPIO& bmsOK) { uart.printf("Set OK pin (0/1): "); uart.printf("\r\n"); uart.gets(inputBuffer, MAX_BUFF); if (inputBuffer[0] == '1') { - bmsOK.writePin(IO::GPIO::State::HIGH); + bmsOK.writePin(io::GPIO::State::HIGH); uart.printf("Set BMS OK high\r\n"); } else { - bmsOK.writePin(IO::GPIO::State::LOW); + bmsOK.writePin(io::GPIO::State::LOW); uart.printf("Set BMS OK low\r\n"); } } -void getVoltages(IO::UART& uart, BMS::DEV::BQ76952& bq) { +void setError(io::UART& uart, io::GPIO& errorLed) { + uart.printf("Set error LED pin (0/1): "); + uart.printf("\r\n"); + uart.gets(inputBuffer, MAX_BUFF); + if (inputBuffer[0] == '1') { + errorLed.writePin(io::GPIO::State::HIGH); + uart.printf("Set error LED high\r\n"); + } else { + errorLed.writePin(io::GPIO::State::LOW); + uart.printf("Set error LED low\r\n"); + } +} + +void getVoltages(io::UART& uart, BMS::dev::BQ76952& bq) { uint16_t tot = 0; for (uint8_t i = 0; i < 16; i++) { uint8_t reg = 0x14 + 2 * i; @@ -362,7 +376,7 @@ void getVoltages(IO::UART& uart, BMS::DEV::BQ76952& bq) { auto result = bq.makeDirectRead(reg, ®Value); // Make sure the read was successful - if (result != BMS::DEV::BQ76952::Status::OK) { + if (result != BMS::dev::BQ76952::Status::OK) { uart.printf("Failed to read register: 0x%x\r\n", reg); return; } @@ -374,7 +388,7 @@ void getVoltages(IO::UART& uart, BMS::DEV::BQ76952& bq) { uart.printf("Total: %d.%d", tot / 1000, tot % 1000); } -void transferSettings(IO::UART& uart, BMS::DEV::BQ76952& bq, EVT::core::DEV::M24C32 eeprom) { +void transferSettings(io::UART& uart, BMS::dev::BQ76952& bq, core::dev::M24C32 eeprom) { uart.printf("Really transfer settings? (y/n): "); uart.gets(inputBuffer, MAX_BUFF); uart.printf("\r\n"); @@ -388,16 +402,16 @@ void transferSettings(IO::UART& uart, BMS::DEV::BQ76952& bq, EVT::core::DEV::M24 auto status = settingsStorage.transferSetting(isComplete); switch (status) { - case BMS::DEV::BQ76952::Status::ERROR: + case BMS::dev::BQ76952::Status::ERROR: uart.printf("FAILED: BQ specific error\r\n"); break; - case BMS::DEV::BQ76952::Status::I2C_ERROR: + case BMS::dev::BQ76952::Status::I2C_ERROR: uart.printf("FAILED: I2C error\r\n"); break; - case BMS::DEV::BQ76952::Status::TIMEOUT: + case BMS::dev::BQ76952::Status::TIMEOUT: uart.printf("FAILED: Timeout waiting for BQ\r\n"); break; - case BMS::DEV::BQ76952::Status::OK: + case BMS::dev::BQ76952::Status::OK: uart.printf("SUCCESS\r\n"); break; default: @@ -412,31 +426,34 @@ void transferSettings(IO::UART& uart, BMS::DEV::BQ76952& bq, EVT::core::DEV::M24 } int main() { - EVT::core::platform::init(); + core::platform::init(); - IO::I2C& i2c = IO::getI2C(); - BMS::DEV::BQ76952 bq(i2c, 0x08); - EVT::core::DEV::M24C32 eeprom(0x57, i2c); + io::I2C& i2c = io::getI2C(); + io::GPIO& bqReset = io::getGPIO(); + BMS::dev::BQ76952 bq(i2c, 0x08, bqReset); + core::dev::M24C32 eeprom(0x57, i2c); - IO::UART& uart = IO::getUART(115200, true); + io::UART& uart = io::getUART(115200); log::LOGGER.setUART(&uart); log::LOGGER.setLogLevel(log::Logger::LogLevel::DEBUG); - IO::ADC& adc = IO::getADC(); + io::ADC& adc = io::getADC(); + + io::GPIO& muxs1 = io::getGPIO(); + io::GPIO& muxs2 = io::getGPIO(); + io::GPIO& muxs3 = io::getGPIO(); + io::GPIO* muxPinArr[3] = {&muxs1, &muxs2, &muxs3}; - IO::GPIO& muxs1 = IO::getGPIO(); - IO::GPIO& muxs2 = IO::getGPIO(); - IO::GPIO& muxs3 = IO::getGPIO(); - IO::GPIO* muxPinArr[3] = {&muxs1, &muxs2, &muxs3}; + BMS::dev::ThermistorMux tmux(muxPinArr, adc); - BMS::DEV::ThermistorMux tmux(muxPinArr, adc); + io::GPIO& interlockGPIO = io::getGPIO(io::GPIO::Direction::INPUT); + BMS::dev::Interlock interlock(interlockGPIO); - IO::GPIO& interlockGPIO = IO::getGPIO(IO::GPIO::Direction::INPUT); - BMS::DEV::Interlock interlock(interlockGPIO); + io::GPIO& alarm = io::getGPIO(io::GPIO::Direction::INPUT); - IO::GPIO& alarm = IO::getGPIO(IO::GPIO::Direction::INPUT); + io::GPIO& bmsOK = io::getGPIO(io::GPIO::Direction::OUTPUT); - IO::GPIO& bmsOK = IO::getGPIO(IO::GPIO::Direction::OUTPUT); + io::GPIO& errorLed = io::getGPIO(io::GPIO::Direction::OUTPUT); time::wait(500); @@ -519,6 +536,10 @@ int main() { case 'o': setOK(uart, bmsOK); break; + // Set OK signal output + case 'e': + setError(uart, errorLed); + break; } } diff --git a/targets/bq_settings/main.cpp b/targets/bq_settings/main.cpp index 6d3e10c..5a91350 100644 --- a/targets/bq_settings/main.cpp +++ b/targets/bq_settings/main.cpp @@ -4,15 +4,15 @@ * correctly. */ -#include +#include #include #include -namespace IO = EVT::core::IO; +namespace io = core::io; /** Print the content of the array in a user friendly manner */ -void printArray(IO::UART& uart, uint8_t* buffer, uint8_t size) { +void printArray(io::UART& uart, uint8_t* buffer, uint8_t size) { uart.printf("{ "); for (uint8_t i = 0; i < size; i++) uart.printf("0x%2x ", buffer[i]); @@ -32,7 +32,7 @@ bool arraysEqual(uint8_t* first, uint8_t* second, uint8_t size) { * array with known contents to the BQSettings and ensure the parsed results * match expectation. */ -void deserializeTest(IO::UART& uart) { +void deserializeTest(io::UART& uart) { /** * Command Byte: Direct command with 1 byte of data * Address: 0x0001 @@ -78,7 +78,7 @@ void deserializeTest(IO::UART& uart) { * Will make a settings value, convert it into an array, and compare it against * the expected output. */ -void serializeTest(IO::UART& uart) { +void serializeTest(io::UART& uart) { BMS::BQSetting setting(BMS::BQSetting::BQSettingType::RAM, 4, 0x1122, 0x12345678); uint8_t expectedArray[] = {0x12, 0x22, 0x11, 0x78, 0x56, 0x34, 0x12}; @@ -100,7 +100,7 @@ void serializeTest(IO::UART& uart) { * Third test, ensure the settings can be serialized and deserialized back * and forth. */ -void serializeDeserializeTest(IO::UART& uart) { +void serializeDeserializeTest(io::UART& uart) { BMS::BQSetting original(BMS::BQSetting::BQSettingType::SUBCOMMAND, 4, 0x2345, 0x45678901); uint8_t serializedArray[BMS::BQSetting::ARRAY_SIZE]; @@ -138,9 +138,9 @@ void serializeDeserializeTest(IO::UART& uart) { } int main() { - EVT::core::platform::init(); + core::platform::init(); - IO::UART& uart = IO::getUART(115200, true); + io::UART& uart = io::getUART(115200); uart.printf("\r\n\r\nBQ SETTING TEST\r\n"); diff --git a/targets/eeprom_dump/main.cpp b/targets/eeprom_dump/main.cpp index 3b6fc0b..3dee0d1 100644 --- a/targets/eeprom_dump/main.cpp +++ b/targets/eeprom_dump/main.cpp @@ -4,32 +4,33 @@ * the target. */ -#include -#include -#include +#include +#include +#include #include #include #include #include -namespace IO = EVT::core::IO; -namespace log = EVT::core::log; +namespace io = core::io; +namespace log = core::log; int main() { - EVT::core::platform::init(); + core::platform::init(); - IO::UART& uart = IO::getUART(115200, true); + IO::UART& uart = IO::getUART(115200); uart.printf("\r\n\r\nEEPROM Dump\r\n"); IO::I2C& i2c = IO::getI2C(); - EVT::core::DEV::M24C32 eeprom(0x57, i2c); + core::dev::M24C32 eeprom(0x57, i2c); log::LOGGER.setUART(&uart); log::LOGGER.setLogLevel(log::Logger::LogLevel::DEBUG); - BMS::DEV::BQ76952 bq(i2c, 0x08); + IO::GPIO& bqReset = IO::getGPIO(); + BMS::dev::BQ76952 bq(i2c, 0x08, bqReset); BMS::BQSettingsStorage bqSettingsStorage(eeprom, bq); bqSettingsStorage.resetEEPROMOffset(); diff --git a/targets/reset_handler/main.cpp b/targets/reset_handler/main.cpp index 8db550e..7ac6453 100644 --- a/targets/reset_handler/main.cpp +++ b/targets/reset_handler/main.cpp @@ -5,20 +5,20 @@ */ #include -#include -#include +#include +#include #include -namespace DEV = EVT::core::DEV; -namespace IO = EVT::core::IO; -namespace log = EVT::core::log; +namespace dev = core::dev; +namespace io = core::io; +namespace log = core::log; /** * Interrupt handler for incoming CAN messages. * * @param priv[in] The private data (FixedQueue) */ -void canInterruptHandler(IO::CANMessage& message, void* priv) { +void canInterruptHandler(io::CANMessage& message, void* priv) { auto* resetHandler = (BMS::ResetHandler*) priv; resetHandler->registerInput(message); @@ -27,9 +27,9 @@ void canInterruptHandler(IO::CANMessage& message, void* priv) { } int main() { - EVT::core::platform::init(); + core::platform::init(); - IO::UART& uart = IO::getUART(115200, true); + io::UART& uart = io::getUART(115200); uart.printf("\r\n\r\nReset Handler Test\r\n"); @@ -38,13 +38,13 @@ int main() { BMS::ResetHandler resetHandler; - IO::CAN& can = IO::getCAN(); + io::CAN& can = io::getCAN(); can.addIRQHandler(canInterruptHandler, &resetHandler); // Attempt to join the CAN network - IO::CAN::CANStatus result = can.connect(true); + io::CAN::CANStatus result = can.connect(true); - if (result != IO::CAN::CANStatus::OK) { + if (result != io::CAN::CANStatus::OK) { uart.printf("Failed to connect to the CAN network\r\n"); return 1; } diff --git a/targets/settings_transfer/main.cpp b/targets/settings_transfer/main.cpp index 3e46fb6..dffc853 100644 --- a/targets/settings_transfer/main.cpp +++ b/targets/settings_transfer/main.cpp @@ -3,36 +3,37 @@ * BQ chip. */ -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include #include -namespace IO = EVT::core::IO; -namespace log = EVT::core::log; +namespace io = core::io; +namespace log = core::log; constexpr uint8_t BQ_I2C_ADDR = 0x08; int main() { - EVT::core::platform::init(); + core::platform::init(); - IO::UART& uart = IO::getUART(115200, true); - IO::I2C& i2c = IO::getI2C(); - EVT::core::DEV::M24C32 eeprom(0x57, i2c); + io::UART& uart = io::getUART(115200); + io::I2C& i2c = io::getI2C(); + dev::M24C32 eeprom(0x57, i2c); uart.printf("\r\n\r\nBQ Setting Transfer Test\r\n"); log::LOGGER.setUART(&uart); log::LOGGER.setLogLevel(log::Logger::LogLevel::DEBUG); - EVT::core::time::wait(500); + core::time::wait(500); - BMS::DEV::BQ76952 bq(i2c, BQ_I2C_ADDR); + io::GPIO& bqReset = io::getGPIO(); + BMS::dev::BQ76952 bq(i2c, 0x08, bqReset); BMS::BQSettingsStorage settingsStorage(eeprom, bq); bool isComplete = false; @@ -41,16 +42,16 @@ int main() { auto status = settingsStorage.transferSetting(isComplete); switch (status) { - case BMS::DEV::BQ76952::Status::ERROR: + case BMS::dev::BQ76952::Status::ERROR: uart.printf("FAILED: BQ specific error\r\n"); break; - case BMS::DEV::BQ76952::Status::I2C_ERROR: + case BMS::dev::BQ76952::Status::I2C_ERROR: uart.printf("FAILED: I2C error\r\n"); break; - case BMS::DEV::BQ76952::Status::TIMEOUT: + case BMS::dev::BQ76952::Status::TIMEOUT: uart.printf("FAILED: Timeout waiting for BQ\r\n"); break; - case BMS::DEV::BQ76952::Status::OK: + case BMS::dev::BQ76952::Status::OK: uart.printf("SUCCESS\r\n"); break; default: @@ -59,7 +60,7 @@ int main() { } } - EVT::core::time::wait(500); + core::time::wait(500); uart.printf("Setting transfer complete"); } diff --git a/targets/system_detect/main.cpp b/targets/system_detect/main.cpp index cf197c0..19d56db 100644 --- a/targets/system_detect/main.cpp +++ b/targets/system_detect/main.cpp @@ -4,26 +4,26 @@ * messages. */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include -#include +#include +#include -#include -#include +#include +#include #include #include #include -namespace IO = EVT::core::IO; -namespace DEV = EVT::core::DEV; -namespace time = EVT::core::time; -namespace log = EVT::core::log; +namespace io = core::io; +namespace dev = core::dev; +namespace time = core::time; +namespace log = core::log; #define BIKE_HEART_BEAT 0x70A // NODE_ID = 10 #define CHARGER_HEART_BEAT 0x710// NODE_ID = 16 @@ -35,7 +35,7 @@ namespace log = EVT::core::log; * to the interrupt handler. */ struct CANInterruptParams { - EVT::core::types::FixedQueue* queue; + core::types::FixedQueue* queue; BMS::SystemDetect* systemDetect; }; @@ -44,10 +44,10 @@ struct CANInterruptParams { * * @param priv[in] The private data (FixedQueue) */ -void canInterruptHandler(IO::CANMessage& message, void* priv) { +void canInterruptHandler(io::CANMessage& message, void* priv) { struct CANInterruptParams* params = (CANInterruptParams*) priv; - EVT::core::types::FixedQueue* queue = + core::types::FixedQueue* queue = params->queue; BMS::SystemDetect* systemDetect = params->systemDetect; @@ -61,10 +61,10 @@ void canInterruptHandler(IO::CANMessage& message, void* priv) { int main() { // Initialize system - EVT::core::platform::init(); + core::platform::init(); // Queue that will store CANopen messages - EVT::core::types::FixedQueue canOpenQueue; + core::types::FixedQueue canOpenQueue; // Initialize the system detect BMS::SystemDetect systemDetect(BIKE_HEART_BEAT, CHARGER_HEART_BEAT, @@ -79,51 +79,53 @@ int main() { }; // Initialize IO - IO::CAN& can = IO::getCAN(); + io::CAN& can = io::getCAN(); can.addIRQHandler(canInterruptHandler, reinterpret_cast(&canParams)); - IO::UART& uart = IO::getUART(115200, true); - IO::I2C& i2c = IO::getI2C(); + io::UART& uart = io::getUART(115200); + io::I2C& i2c = io::getI2C(); // Initialize the timer - DEV::Timer& timer = DEV::getTimer(100); + dev::Timer& timer = dev::getTimer(100); // Initialize the EEPROM - EVT::core::DEV::M24C32 eeprom(0x50, i2c); + core::dev::M24C32 eeprom(0x50, i2c); // Initialize the logger log::LOGGER.setUART(&uart); log::LOGGER.setLogLevel(log::Logger::LogLevel::ERROR); // Initialize the BQ interfaces - BMS::DEV::BQ76952 bq(i2c, 0x08); + io::GPIO& bqReset = io::getGPIO(); + BMS::dev::BQ76952 bq(i2c, 0x08, bqReset); BMS::BQSettingsStorage bqSettingsStorage(eeprom, bq); // Initialize the Interlock - // TODO: Determine actual interlock GPIO - IO::GPIO& interlockGPIO = IO::getGPIO(IO::GPIO::Direction::INPUT); - BMS::DEV::Interlock interlock(interlockGPIO); + io::GPIO& interlockGPIO = io::getGPIO(io::GPIO::Direction::INPUT); + BMS::dev::Interlock interlock(interlockGPIO); // Initialize the alarm pin - IO::GPIO& alarm = IO::getGPIO(IO::GPIO::Direction::INPUT); + io::GPIO& alarm = io::getGPIO(io::GPIO::Direction::INPUT); // Initialize the system OK pin - // TODO: Determine actual system ok pin - IO::GPIO& bmsOK = IO::getGPIO(IO::GPIO::Direction::OUTPUT); + io::GPIO& bmsOK = io::getGPIO(io::GPIO::Direction::OUTPUT); + + // Initialize the error LED pin + io::GPIO& errorLed = io::getGPIO(io::GPIO::Direction::OUTPUT); // Initialize the thermistor MUX - IO::GPIO* muxSelectArr[3] = { - &IO::getGPIO(), - &IO::getGPIO(), - &IO::getGPIO(), + io::GPIO* muxSelectArr[3] = { + &io::getGPIO(), + &io::getGPIO(), + &io::getGPIO(), }; - IO::ADC& thermAdc = IO::getADC(); + io::ADC& thermAdc = io::getADC(); - BMS::DEV::ThermistorMux thermMux(muxSelectArr, thermAdc); + BMS::dev::ThermistorMux thermMux(muxSelectArr, thermAdc); - DEV::IWDG& iwdg = DEV::getIWDG(500); + dev::IWDG& iwdg = dev::getIWDG(500); // Initialize the BMS itself - BMS::BMS bms(bqSettingsStorage, bq, interlock, alarm, systemDetect, bmsOK, thermMux, resetHandler, iwdg); + BMS::BMS bms(bqSettingsStorage, bq, interlock, alarm, systemDetect, bmsOK, errorLed, thermMux, resetHandler, iwdg); /////////////////////////////////////////////////////////////////////////// // Setup CAN configuration, this handles making drivers, applying settings. @@ -146,16 +148,16 @@ int main() { CO_NODE canNode; // Initialize all the CANOpen drivers. - IO::initializeCANopenDriver(&canOpenQueue, &can, &timer, &canStackDriver, &nvmDriver, &timerDriver, &canDriver); + io::initializeCANopenDriver(&canOpenQueue, &can, &timer, &canStackDriver, &nvmDriver, &timerDriver, &canDriver); // Initialize the CANOpen node we are using. - IO::initializeCANopenNode(&canNode, &bms, &canStackDriver, sdoBuffer, appTmrMem); + io::initializeCANopenNode(&canNode, &bms, &canStackDriver, sdoBuffer, appTmrMem); time::wait(500); // Attempt to join the CAN network - IO::CAN::CANStatus result = can.connect(true); + io::CAN::CANStatus result = can.connect(true); - if (result != IO::CAN::CANStatus::OK) { + if (result != io::CAN::CANStatus::OK) { uart.printf("Failed to connect to CAN network\r\n"); return 1; } diff --git a/targets/thermistor_mux/main.cpp b/targets/thermistor_mux/main.cpp index f5a2743..07696de 100644 --- a/targets/thermistor_mux/main.cpp +++ b/targets/thermistor_mux/main.cpp @@ -2,31 +2,31 @@ * This test demonstrates the functionality of the ThermistorMux class. */ -#include -#include -#include -#include +#include +#include +#include +#include #include #include -namespace IO = EVT::core::IO; +namespace io = core::io; -namespace time = EVT::core::time; +namespace time = core::time; int main() { - EVT::core::platform::init(); + core::platform::init(); - IO::ADC& adc = IO::getADC(); - IO::UART& uart = IO::getUART(115200, true); + io::ADC& adc = io::getADC(); + io::UART& uart = io::getUART(115200); - IO::GPIO& muxs1 = IO::getGPIO(); - IO::GPIO& muxs2 = IO::getGPIO(); - IO::GPIO& muxs3 = IO::getGPIO(); + io::GPIO& muxs1 = io::getGPIO(); + io::GPIO& muxs2 = io::getGPIO(); + io::GPIO& muxs3 = io::getGPIO(); - IO::GPIO* muxPinArr[3] = {&muxs1, &muxs2, &muxs3}; + io::GPIO* muxPinArr[3] = {&muxs1, &muxs2, &muxs3}; - BMS::DEV::ThermistorMux thermistorMux(muxPinArr, adc); + BMS::dev::ThermistorMux thermistorMux(muxPinArr, adc); uint8_t looper = 0; diff --git a/targets/uart_settings_upload/main.cpp b/targets/uart_settings_upload/main.cpp index 18d8f91..39b154b 100644 --- a/targets/uart_settings_upload/main.cpp +++ b/targets/uart_settings_upload/main.cpp @@ -4,19 +4,19 @@ */ #include -#include -#include +#include +#include -namespace IO = EVT::core::IO; +namespace io = core::io; int main() { // Initialize system - EVT::core::platform::init(); + core::platform::init(); - IO::UART& uart = IO::getUART(9600, true); + io::UART& uart = io::getUART(9600); - IO::I2C& i2c = IO::getI2C(); - EVT::core::DEV::M24C32 eeprom(0x57, i2c); + io::I2C& i2c = io::getI2C(); + core::dev::M24C32 eeprom(0x57, i2c); uart.printf("Test start\r\n"); uint8_t buf[2]; diff --git a/version.txt b/version.txt index 6c6aa7c..0c89fc9 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.1.0 \ No newline at end of file +4.0.0 \ No newline at end of file