From 1b4998622123e3be4283d575549170bfddac674e Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sat, 18 Nov 2023 16:24:26 +0800 Subject: [PATCH] update --- components/api/zi_dc_motor_ctrl_module.hpp | 19 +++++ components/api/zi_fan_ctrl_module.hpp | 16 ---- components/api/zi_pwm_fan_ctrl_module.hpp | 18 +++++ components/api/zi_pwm_pump_ctrl_module.hpp | 19 +++++ components/ti/drv8710.cpp | 6 ++ components/ti/drv8710.hpp | 3 + .../water_cooling_temperature_control_module.cpp | 92 +++++++++++++++------- .../water_cooling_temperature_control_module.hpp | 42 +++++----- components/zprotocols/zcancmder_v2 | 2 +- 9 files changed, 149 insertions(+), 68 deletions(-) create mode 100644 components/api/zi_dc_motor_ctrl_module.hpp delete mode 100644 components/api/zi_fan_ctrl_module.hpp create mode 100644 components/api/zi_pwm_fan_ctrl_module.hpp create mode 100644 components/api/zi_pwm_pump_ctrl_module.hpp diff --git a/components/api/zi_dc_motor_ctrl_module.hpp b/components/api/zi_dc_motor_ctrl_module.hpp new file mode 100644 index 0000000..50509e9 --- /dev/null +++ b/components/api/zi_dc_motor_ctrl_module.hpp @@ -0,0 +1,19 @@ +#pragma once +#include + +#include + +#include "sdk\components\zprotocols\zcancmder_v2\api\errorcode.hpp" + +namespace iflytop { +using namespace std; +class ZIDcMotorCtrlModule { + public: + virtual ~ZIDcMotorCtrlModule() {} + + virtual void setSpeed(int32_t duty) = 0; + virtual void stop() = 0; + virtual bool isError() = 0; + virtual bool dumpErrorInfo() = 0; +}; +} // namespace iflytop \ No newline at end of file diff --git a/components/api/zi_fan_ctrl_module.hpp b/components/api/zi_fan_ctrl_module.hpp deleted file mode 100644 index 321a715..0000000 --- a/components/api/zi_fan_ctrl_module.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once -#include - -#include - -#include "sdk\components\zprotocols\zcancmder_v2\api\errorcode.hpp" - -namespace iflytop { -using namespace std; -class ZIFanCtrlModule { - public: - virtual ~ZIFanCtrlModule() {} - - virtual void setFanSpeed(int32_t duty) = 0; -}; -} // namespace iflytop \ No newline at end of file diff --git a/components/api/zi_pwm_fan_ctrl_module.hpp b/components/api/zi_pwm_fan_ctrl_module.hpp new file mode 100644 index 0000000..b972108 --- /dev/null +++ b/components/api/zi_pwm_fan_ctrl_module.hpp @@ -0,0 +1,18 @@ +#pragma once +#include + +#include + +#include "sdk\components\zprotocols\zcancmder_v2\api\errorcode.hpp" + +namespace iflytop { +using namespace std; +class ZIPWMFanCtrlModule { + public: + virtual ~ZIPWMFanCtrlModule() {} + + virtual void setFanSpeed(int32_t duty) = 0; + virtual void stop() = 0; + virtual bool isError() = 0; +}; +} // namespace iflytop \ No newline at end of file diff --git a/components/api/zi_pwm_pump_ctrl_module.hpp b/components/api/zi_pwm_pump_ctrl_module.hpp new file mode 100644 index 0000000..0438a6e --- /dev/null +++ b/components/api/zi_pwm_pump_ctrl_module.hpp @@ -0,0 +1,19 @@ +#pragma once +#include + +#include + +#include "sdk\components\zprotocols\zcancmder_v2\api\errorcode.hpp" + +namespace iflytop { +using namespace std; +class ZIPWMPumpCtrlModule { + public: + virtual ~ZIPWMPumpCtrlModule() {} + + virtual void setPumpSpeed(int32_t duty) = 0; + virtual void stop() = 0; + virtual bool isError() = 0; + +}; +} // namespace iflytop \ No newline at end of file diff --git a/components/ti/drv8710.cpp b/components/ti/drv8710.cpp index e5aafce..8099c24 100644 --- a/components/ti/drv8710.cpp +++ b/components/ti/drv8710.cpp @@ -6,9 +6,15 @@ void DRV8710::initialize(config_t* cfg) { // cfg->pwm_cfg.calltrace = cfg->enableTrace; m_pwmCtrl.initialize(&cfg->pwm_cfg); + ZASSERT(cfg->nsleep != PinNull); + ZASSERT(cfg->nfault != PinNull); + ZASSERT(cfg->sensePin != PinNull); + m_nsleep.initAsOutput(cfg->nsleep, ZGPIO::kMode_nopull, false, false); m_nsleep.enableTrace(cfg->enableTrace); m_nfault.initAsInput(cfg->nfault, ZGPIO::kMode_pullup, ZGPIO::kIRQ_noIrq, false); + m_nsensePin.initAsInput(cfg->sensePin, ZGPIO::kMode_pullup, ZGPIO::kIRQ_noIrq, false); + m_in2.initAsOutput(cfg->in2, ZGPIO::kMode_nopull, false, false); m_in2.enableTrace(cfg->enableTrace); enable(false); diff --git a/components/ti/drv8710.hpp b/components/ti/drv8710.hpp index 96f4c0e..aaa382c 100644 --- a/components/ti/drv8710.hpp +++ b/components/ti/drv8710.hpp @@ -33,6 +33,7 @@ class DRV8710 { Pin_t in2; Pin_t nsleep; Pin_t nfault; + Pin_t sensePin; bool shaft; bool enableTrace; @@ -43,6 +44,7 @@ class DRV8710 { ZGPIO m_in2; ZGPIO m_nsleep; ZGPIO m_nfault; + ZGPIO m_nsensePin; config_t m_cfg; // ZGPIO so; @@ -60,6 +62,7 @@ class DRV8710 { void move(int32_t duty); // -100->100 bool isFault(); + bool getSensePinState() { return m_nsensePin.getState(); } private: void set_direcetion(bool direcetion); diff --git a/components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.cpp b/components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.cpp index bfdcc7a..37acace 100644 --- a/components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.cpp +++ b/components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.cpp @@ -10,6 +10,7 @@ using namespace iflytop; #define ACTION_TEST_PELTIER_SET_POWER_LEVEL 1 #define ACTION_TEST_PUMP_SET_LEVEL 2 #define ACTION_TEST_FAN_SET_LEVEL 3 +#define ACTION_TEST_DUMP_DC_MOTOR_STATE 4 void WaterCoolingTemperatureControlModule::initialize(int32_t id, config_t* cfg, hardwared_config_t* hardwaredconfig) { #if 0 @@ -22,7 +23,7 @@ void WaterCoolingTemperatureControlModule::initialize(int32_t id, config_t* cfg, ZGPIO::InputGpioCfg_t ext_output[10]; #endif m_id = id; - +#if 0 for (int32_t i = 0; i < ZARRAY_SIZE(hardwaredconfig->temperature_sensor); i++) { if (!hardwaredconfig->temperature_sensor[i]) break; m_temperature_sensor[i] = hardwaredconfig->temperature_sensor[i]; @@ -42,6 +43,16 @@ void WaterCoolingTemperatureControlModule::initialize(int32_t id, config_t* cfg, m_peltier_ctrl[i] = hardwaredconfig->peltier_ctrl[i]; m_peltier_ctrl_num++; } +#endif + for (int32_t i = 0; i < ZARRAY_SIZE(hardwaredconfig->temperature_sensor); i++) { + if (!hardwaredconfig->temperature_sensor[i]) break; + m_temperature_sensor[i] = hardwaredconfig->temperature_sensor[i]; + m_n_temperature_sensor++; + } + + m_fan_ctrl = hardwaredconfig->fan_ctrl; + m_pelter_ctrl = hardwaredconfig->pelter_ctrl; + m_pump_ctrl = hardwaredconfig->pump_ctrl; m_pidmodule.initialize(&cfg->pid_cfg); m_thread.init("WaterCoolingTemperatureControlModule"); @@ -117,7 +128,12 @@ int32_t WaterCoolingTemperatureControlModule::do_action(int32_t actioncode) { return test_pump_set_level(m_com_reg.module_action_param1); } else if (actioncode == ACTION_TEST_FAN_SET_LEVEL) { return test_fan_set_level(m_com_reg.module_action_param1); - } else { + } else if (actioncode == ACTION_TEST_DUMP_DC_MOTOR_STATE) { + m_pelter_ctrl->dumpErrorInfo(); + return 0; + } + + else { return err::kmodule_not_support_action; } } @@ -180,7 +196,19 @@ void WaterCoolingTemperatureControlModule::workloop() { fan_stop(); } -int32_t WaterCoolingTemperatureControlModule::checkdevice() { return 0; } +#define BIT(x, n) ((x >> n) & 0x01) + +int32_t WaterCoolingTemperatureControlModule::checkdevice() { + m_com_reg.module_errorbitflag0 = geterrorbitflag0(); + if (m_com_reg.module_errorbitflag0 != 0) { + ZLOGE(TAG, "checkdevice errorbitflag0:%d %d %d", // + BIT(m_com_reg.module_errorbitflag0, 0), BIT(m_com_reg.module_errorbitflag0, 1), BIT(m_com_reg.module_errorbitflag0, 2)); + m_pelter_ctrl->dumpErrorInfo(); + m_com_reg.module_errorcode = err::khwardware_error; + } + + return 0; +} /******************************************************************************* * BASIC * @@ -190,39 +218,44 @@ float WaterCoolingTemperatureControlModule::read_pid_temperature() { return m_te void WaterCoolingTemperatureControlModule::pump_start(int32_t pump_speed) { ZLOGI(TAG, "pump_start %d", pump_speed); - m_pump->startModule(pump_speed); + // m_pump->startModule(pump_speed); + m_pump_ctrl->setPumpSpeed(pump_speed); } void WaterCoolingTemperatureControlModule::pump_stop() { ZLOGI(TAG, "pump_stop"); - m_pump->stopModule(); + m_pump_ctrl->stop(); } void WaterCoolingTemperatureControlModule::fan_start(int32_t pump_speed) { ZLOGI(TAG, "fan_start %d", pump_speed); - for (int32_t i = 0; i < m_fanNum; i++) { - m_fanTable[i]->startModule(pump_speed); - } + m_fan_ctrl->setFanSpeed(pump_speed); + // for (int32_t i = 0; i < m_fanNum; i++) { + // m_fanTable[i]->startModule(pump_speed); + // } } void WaterCoolingTemperatureControlModule::fan_stop() { ZLOGI(TAG, "fan_stop"); - for (int32_t i = 0; i < m_fanNum; i++) { - m_fanTable[i]->stopModule(); - } + m_fan_ctrl->stop(); + // for (int32_t i = 0; i < m_fanNum; i++) { + // m_fanTable[i]->stopModule(); + // } } void WaterCoolingTemperatureControlModule::peltier_set_power_level(int32_t level) { ZLOGI(TAG, "peltier_set_power_level %d", level); - for (int32_t i = 0; i < m_peltier_ctrl_num; i++) { - m_peltier_ctrl[i]->move(level); - m_peltier_ctrl[i]->enable(true); - } + m_pelter_ctrl->setSpeed(level); + // for (int32_t i = 0; i < m_peltier_ctrl_num; i++) { + // m_peltier_ctrl[i]->move(level); + // m_peltier_ctrl[i]->enable(true); + // } } void WaterCoolingTemperatureControlModule::peltier_stop() { ZLOGI(TAG, "peltier_stop"); - for (int32_t i = 0; i < m_peltier_ctrl_num; i++) { - m_peltier_ctrl[i]->move(0); - m_peltier_ctrl[i]->enable(false); - } + m_pelter_ctrl->stop(); + // for (int32_t i = 0; i < m_peltier_ctrl_num; i++) { + // m_peltier_ctrl[i]->move(0); + // m_peltier_ctrl[i]->enable(false); + // } } int32_t WaterCoolingTemperatureControlModule::getworkstate() { @@ -240,21 +273,20 @@ int32_t WaterCoolingTemperatureControlModule::getworkstate() { int32_t WaterCoolingTemperatureControlModule::geterrorbitflag0() { /** * @brief - * - * bit 0->3 fan0,fan1,fan2,fan3, - * bit 4->4 pump0, - * bit 8->9 peltier0_controler,peltier1_controler */ int32_t errorbitflag = 0; - if (m_fanTable[0]) errorbitflag |= m_fanTable[0]->isError() << 0; - if (m_fanTable[1]) errorbitflag |= m_fanTable[1]->isError() << 1; - if (m_fanTable[2]) errorbitflag |= m_fanTable[2]->isError() << 2; - if (m_fanTable[3]) errorbitflag |= m_fanTable[3]->isError() << 3; + errorbitflag |= m_fan_ctrl->isError() << 0; + errorbitflag |= m_pump_ctrl->isError() << 1; + errorbitflag |= m_pelter_ctrl->isError() << 2; + + // if (m_fanTable[1]) errorbitflag |= m_fanTable[1]->isError() << 1; + // if (m_fanTable[2]) errorbitflag |= m_fanTable[2]->isError() << 2; + // if (m_fanTable[3]) errorbitflag |= m_fanTable[3]->isError() << 3; - if (m_pump) errorbitflag |= m_pump->isError() << 4; + // if (m_pump) errorbitflag |= m_pump->isError() << 4; - if (m_peltier_ctrl[0]) errorbitflag |= m_peltier_ctrl[0]->isFault() << 8; - if (m_peltier_ctrl[1]) errorbitflag |= m_peltier_ctrl[1]->isFault() << 9; + // if (m_peltier_ctrl[0]) errorbitflag |= m_peltier_ctrl[0]->isFault() << 8; + // if (m_peltier_ctrl[1]) errorbitflag |= m_peltier_ctrl[1]->isFault() << 9; return errorbitflag; } diff --git a/components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.hpp b/components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.hpp index f47eb4d..4e48f0a 100644 --- a/components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.hpp +++ b/components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.hpp @@ -17,7 +17,11 @@ #include "sdk/os/zos.hpp" // #include "pwm_ctrl_module.hpp" -#include "sdk/components/api/zi_fan_ctrl_module.hpp" +// +#include "sdk\components\api\zi_dc_motor_ctrl_module.hpp" +#include "sdk\components\api\zi_pwm_fan_ctrl_module.hpp" +#include "sdk\components\api\zi_pwm_pump_ctrl_module.hpp" +// #include "sdk\components\algorithm\pid_module.hpp" #include "sdk\components\api\zi_temperature_sensor.hpp" #include "sdk\components\ti\drv8710.hpp" @@ -29,22 +33,6 @@ namespace iflytop { * 水冷温度控制模块 */ -#if 0 -namespace water_cooling_temperature_control { -class FanCtrlGroup { - public: -}; - -class PumpCtrlGroup { - public: -}; - -class PeltierCtrlGroup { - public: -}; - -} // namespace water_cooling_temperature_control -#endif class WaterCoolingTemperatureControlModule : public ZIModule { ENABLE_MODULE(WaterCoolingTemperatureControlModule, ktemperature_ctrl_module, 1); @@ -57,16 +45,29 @@ class WaterCoolingTemperatureControlModule : public ZIModule { } config_t; typedef struct { +#if 0 ZITemperatureSensor* temperature_sensor[4]; PWMSpeedCtrlModule* fanTable[4]; PWMSpeedCtrlModule* pump; DRV8710* peltier_ctrl[2]; +#endif + ZITemperatureSensor* temperature_sensor[4]; + ZIPWMFanCtrlModule* fan_ctrl; + ZIDcMotorCtrlModule* pelter_ctrl; + ZIPWMPumpCtrlModule* pump_ctrl; } hardwared_config_t; private: config_t m_cfg; - int32_t m_id = 1; + int32_t m_id = 0; + + ZITemperatureSensor* m_temperature_sensor[4]; + int32_t m_n_temperature_sensor = 0; + ZIPWMFanCtrlModule* m_fan_ctrl; + ZIDcMotorCtrlModule* m_pelter_ctrl; + ZIPWMPumpCtrlModule* m_pump_ctrl; +#if 0 // 温度传感器 ZITemperatureSensor* m_temperature_sensor[4] = {0}; int32_t m_n_temperature_sensor = 0; @@ -78,11 +79,10 @@ class WaterCoolingTemperatureControlModule : public ZIModule { // 帕尔贴控制器 DRV8710* m_peltier_ctrl[2]; int32_t m_peltier_ctrl_num = 0; +#endif - // PID模块 PidModule m_pidmodule; - // 模块ID - ZThread m_thread; + ZThread m_thread; float m_target_temperature = 0; diff --git a/components/zprotocols/zcancmder_v2 b/components/zprotocols/zcancmder_v2 index be3ba82..ab90926 160000 --- a/components/zprotocols/zcancmder_v2 +++ b/components/zprotocols/zcancmder_v2 @@ -1 +1 @@ -Subproject commit be3ba82dfcfdf7712af804b00eb6c81b3e5de7bd +Subproject commit ab909260b588f575c9286bf4d3a72560f2f1ede7