diff --git a/src/ext/CMakeLists.txt b/src/ext/CMakeLists.txt index 5d94512..5b594d1 100644 --- a/src/ext/CMakeLists.txt +++ b/src/ext/CMakeLists.txt @@ -1,7 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 target_sources(app PRIVATE - ext.cpp oled.cpp serial.cpp can.cpp diff --git a/src/ext/ext.cpp b/src/ext/ext.cpp deleted file mode 100644 index 59430c6..0000000 --- a/src/ext/ext.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2019 Martin Jäger / Libre Solar - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "ext.h" - -#include - -// necessary for PlatformIO debug session -void std::__throw_bad_alloc() -{ - while (true) {} -} - -// necessary to compile Zephyr v2.2 -void std::__throw_length_error(char const*) -{ - while (true) {} -} - -// we use code to self register objects at construction time. -// It relies on the fact that initially this pointer will be initialized -// with NULL ! This is only true for global variables or static members of classes -// so this must remain a static class member -std::vector* ExtManager::interfaces; - -// run the respective function on all objects in the "devices" list -// use the c++11 lambda expressions here for the for_each loop, keeps things compact - -void ExtManager::process_asap() -{ - for_each(std::begin(*interfaces),std::end(*interfaces), [](ExtInterface* tsif) { - tsif->process_asap(); - }); -} - -void ExtManager::enable_all() -{ - for_each(std::begin(*interfaces),std::end(*interfaces), [](ExtInterface* tsif) { - tsif->enable(); - }); -} - -void ExtManager::process_1s() -{ - for_each(std::begin(*interfaces),std::end(*interfaces), [](ExtInterface* tsif) { - tsif->process_1s(); - }); -} - -void ExtManager::check_list() -{ - if (ExtManager::interfaces == NULL) { - ExtManager::interfaces = new std::vector; - } -} - -void ExtManager::add_ext(ExtInterface* member) -{ - check_list(); - interfaces->push_back(member); -} - -ExtManager::ExtManager() -{ - check_list(); -} - -ExtInterface::ExtInterface() -{ - ext_mgr.add_ext(this); -} - -ExtManager ext_mgr; diff --git a/src/ext/ext.h b/src/ext/ext.h deleted file mode 100644 index f0b802e..0000000 --- a/src/ext/ext.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2019 Martin Jäger / Libre Solar - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef EXT_H_ -#define EXT_H_ - -#include - -/** @file - * - * @brief Classes to handle EXTensions and EXTernal communication interfaces - */ - -class ExtInterface -{ -public: - ExtInterface(); - virtual void process_asap() {}; - virtual void process_1s() {}; - virtual void enable() {}; -}; - -class ExtManager -{ -public: - ExtManager(); - - /** UEXT interface process function - * - * This function is called in each main loop, as soon as all other tasks finished. - */ - virtual void process_asap(); - - /** UEXT interface process function - * - * This function is called every second, if no other task was blocking for a longer time. - * It should be used for state machines, etc. - */ - virtual void process_1s(); - - /* UEXT interface initialization - * - * This function is called only once at startup. - */ - virtual void enable_all(); - - /** - * Adds an ExtInterface object to the list of managed extensions, - * automatically called by ExtInterface objects during construction - */ - static void add_ext(ExtInterface*); - -private: - /** - * Stores list of all ExtInterface objects - */ - static std::vector* interfaces; - - /** - * Makes sure there is an internal interfacts vector created, does nothing if it exists - */ - static void check_list(); -}; - -extern ExtManager ext_mgr; - -#endif /* EXT_H_ */ diff --git a/src/ext/template.cpp b/src/ext/template.cpp deleted file mode 100644 index 931ed8d..0000000 --- a/src/ext/template.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2018 Martin Jäger / Libre Solar - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** EXT interface description template - * - * The UEXT port can be used to connect several different extension modules to the charge controller. - * - * Use this file as a template for custom interfaces. If the UEXT port is not used, UEXT_DUMMY_ENABLED - * has to be defined in config.h to implement the functions. - */ - -// Only compile if this EXT interface is enabled in config.h -#ifdef CONFIG_EXT_TEMPLATE_ENABLED - -// implement specific extension inherited from ExtInterface -class ExtTemplate: public ExtInterface -{ -public: - ExtTemplate(); - void enable(); - void process_asap(); - void process_1s(); -}; - -static ExtTemplate ext_template; // local instance, will self register itself - -/** - * Constructor, place basic initialization here, if necessary - */ -ExtTemplate::ExtTemplate() {} - -/** - * Enable operation, place start of use code here, if necessary - */ -void ExtTemplate::enable() { - // add you init functions here -} - -void ExtTemplate::process_asap(void) { - // add functions to be called as soon as possible during each loop in main function -} - -void ExtTemplate::process_1s(void) { - // add functions to be called every second here -} - -#endif /* EXT_TEMPLATE_ENABLED */ diff --git a/src/leds.cpp b/src/leds.cpp index 58faf33..312034c 100644 --- a/src/leds.cpp +++ b/src/leds.cpp @@ -288,3 +288,7 @@ void leds_update_soc(int soc, bool load_off_low_soc) } #endif } + +#ifndef UNIT_TEST +K_THREAD_DEFINE(leds_thread, 256, leds_update_thread, NULL, NULL, NULL, 4, 0, 100); +#endif diff --git a/src/main.cpp b/src/main.cpp index 5d7eb19..69e42b4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,6 @@ #include "pwm_switch.h" // PWM charge controller #include "bat_charger.h" // battery settings and charger state machine #include "daq.h" // ADC using DMA and conversion to measurement values -#include "ext/ext.h" // communication interfaces, displays, etc. in UEXT connector #include "eeprom.h" // external I2C EEPROM #include "load.h" // load and USB output management #include "leds.h" // LED switching using charlieplexing @@ -46,9 +45,6 @@ void main(void) // Data Acquisition (DAQ) setup daq_setup(); - // initialize all extensions and external communication interfaces - ext_mgr.enable_all(); - #if CONFIG_HV_TERMINAL_SOLAR || CONFIG_LV_TERMINAL_SOLAR || CONFIG_PWM_TERMINAL_SOLAR solar_terminal.init_solar(); #endif @@ -171,33 +167,7 @@ void control_thread() } } -void ext_mgr_thread() -{ - uint32_t last_call = 0; - int wdt_channel = watchdog_register(3000); - - // quite long watchdog timeout as we might be dealing with slow communication (e.g. modems - // using AT commands via serial interface) - - while (true) { - - watchdog_feed(wdt_channel); - - uint32_t now = k_uptime_get() / 1000; - ext_mgr.process_asap(); // approx. every millisecond - if (now >= last_call + 1) { - last_call = now; - ext_mgr.process_1s(); - } - k_sleep(K_MSEC(1)); - } -} - // 2s delay for control thread as a safety feature: be able to re-flash before starting K_THREAD_DEFINE(control_thread_id, 1024, control_thread, NULL, NULL, NULL, 2, 0, 2000); -K_THREAD_DEFINE(leds_thread, 256, leds_update_thread, NULL, NULL, NULL, 4, 0, 100); - -K_THREAD_DEFINE(ext_thread, 1024, ext_mgr_thread, NULL, NULL, NULL, 6, 0, 1000); - #endif // UNIT_TEST diff --git a/src/setup.cpp b/src/setup.cpp index 77ea147..23e9b0b 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -19,7 +19,6 @@ #include "pwm_switch.h" // PWM charge controller #include "bat_charger.h" // battery settings and charger state machine #include "daq.h" // ADC using DMA and conversion to measurement values -#include "ext/ext.h" // communication interfaces, displays, etc. in UEXT connector #include "eeprom.h" // external I2C EEPROM #include "load.h" // load and USB output management #include "leds.h" // LED switching using charlieplexing