From a41640afe9d4f8e990c13c769238e1a79940fc88 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Tue, 7 Nov 2023 21:54:46 +0800 Subject: [PATCH] update --- chip/zpwm_generator_muti_channel.cpp | 2 +- .../pwm_ctrl_module.cpp | 15 ++++++++++++--- .../pwm_ctrl_module.hpp | 8 +++++--- .../water_cooling_temperature_control_module.cpp | 10 ++++------ .../water_cooling_temperature_control_module.hpp | 2 +- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/chip/zpwm_generator_muti_channel.cpp b/chip/zpwm_generator_muti_channel.cpp index 88536b4..3371703 100644 --- a/chip/zpwm_generator_muti_channel.cpp +++ b/chip/zpwm_generator_muti_channel.cpp @@ -75,7 +75,7 @@ void ZPWMGeneratorMutiChannel::updatePWMState(int32_t channelindex /*1 void ZPWMGeneratorMutiChannel::startPWM(int32_t channelindex /*1£¬2£¬3£¬4*/, float duty) { if (channelindex < 1 || channelindex > 4) return; m_pwmstate[channelindex] = true; - ZEARLY_LOGI(TAG, "[%s] startPWM tim:%s channelindex:%d duty:%f", m_cfg.name, chip_tim_get_name(m_htim->Instance), channelindex, duty); + ZEARLY_LOGI(TAG, "[%s] setpwm tim:%s ch:%d duty:%f", m_cfg.name, chip_tim_get_name(m_htim->Instance), channelindex, duty); updatePWMState(channelindex, duty); } void ZPWMGeneratorMutiChannel::stopPWM(int32_t channelindex) { diff --git a/components/water_cooling_temperature_control_module/pwm_ctrl_module.cpp b/components/water_cooling_temperature_control_module/pwm_ctrl_module.cpp index c67eb5a..665dd54 100644 --- a/components/water_cooling_temperature_control_module/pwm_ctrl_module.cpp +++ b/components/water_cooling_temperature_control_module/pwm_ctrl_module.cpp @@ -2,9 +2,11 @@ #include "sdk\components\zprotocols\zcancmder_v2\api\errorcode.hpp" using namespace iflytop; - +#define TAG "PWM_SCM" void PWMSpeedCtrlModule::initialize(config_t* pcfg) { + ZASSERT(pcfg->name != nullptr); ZASSERT(pcfg); + m_mutex.init(); // ZASSERT(pcfg->fanCtrlTim); cfg = *pcfg; m_enablefbcheck = pcfg->enablefbcheck; @@ -35,6 +37,7 @@ void PWMSpeedCtrlModule::initialize(config_t* pcfg) { } cfg.pwm_cfg.calltrace = pcfg->enableTrace; m_fanCtrlPwm.initialize(&cfg.pwm_cfg); + OSDefaultSchduler::getInstance()->regPeriodJob([this](OSDefaultSchduler::Context&) { checkfanState(); }, 1000); } void PWMSpeedCtrlModule::onfbgpioirq(int32_t fanindex) { @@ -44,6 +47,8 @@ void PWMSpeedCtrlModule::onfbgpioirq(int32_t fanindex) { } int32_t PWMSpeedCtrlModule::startModule(int32_t duty) { + // ZLOGI("startModule duty:%d", duty); + zlock_guard lck(m_mutex); if (duty < 20) duty = 20; fanisworking = true; @@ -54,6 +59,8 @@ int32_t PWMSpeedCtrlModule::startModule(int32_t duty) { return 0; } int32_t PWMSpeedCtrlModule::stopModule() { + zlock_guard lck(m_mutex); + fanisworking = false; stopFanPWM(); powerOff(); @@ -81,9 +88,10 @@ bool PWMSpeedCtrlModule::isError() { } void PWMSpeedCtrlModule::checkfanState() { + zlock_guard lck(m_mutex); if (!m_enablefbcheck) return; - if (zos_haspassedms(m_lastcheckTime) < 10 * 1000) { + if (zos_haspassedms(m_lastcheckTime) < 3 * 1000) { return; } @@ -96,7 +104,8 @@ void PWMSpeedCtrlModule::checkfanState() { void PWMSpeedCtrlModule::checkfanState(int32_t fanindex) { if (fanisworking && zos_haspassedms(m_fanstate[fanindex].lastupdateFanFBCountTime) > 10 * 1000) { m_fanstate[fanindex].fanerrorstate = 1; - powerOff(); + ZLOGE(TAG, "%s checkfanState fanindex:%d error", cfg.name, fanindex); + stopModule(); } } diff --git a/components/water_cooling_temperature_control_module/pwm_ctrl_module.hpp b/components/water_cooling_temperature_control_module/pwm_ctrl_module.hpp index 2081a89..efb574b 100644 --- a/components/water_cooling_temperature_control_module/pwm_ctrl_module.hpp +++ b/components/water_cooling_temperature_control_module/pwm_ctrl_module.hpp @@ -16,6 +16,7 @@ #include "sdk/os/zos.hpp" #include "sdk\chip\zpwm_generator_muti_channel.hpp" +#include "sdk\os\mutex.hpp" // namespace iflytop { @@ -25,6 +26,7 @@ class PWMSpeedCtrlModule { public: typedef struct { // TIM_HandleTypeDef* fanCtrlTim; + const char* name; ZPWMGeneratorMutiChannel::hardware_config_t pwm_cfg; int32_t nfan; @@ -55,7 +57,8 @@ class PWMSpeedCtrlModule { config_t cfg; - bool m_enablefbcheck = false; + bool m_enablefbcheck = false; + zmutex m_mutex; public: PWMSpeedCtrlModule(){}; @@ -68,9 +71,8 @@ class PWMSpeedCtrlModule { int32_t getSubModuleErrorState(int32_t fanindex, int32_t* error_state); bool isError(); - void checkfanState(); - private: + void checkfanState(); void onfbgpioirq(int32_t fanindex); private: 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 fd16816..9759028 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 @@ -9,7 +9,7 @@ using namespace iflytop; #define ACTION_TEST_PELTIER_SET_POWER_LEVEL 1 #define ACTION_TEST_PUMP_SET_LEVEL 2 -#define ACTION_TEST_PUMP_FAN_SET_LEVEL 3 +#define ACTION_TEST_FAN_SET_LEVEL 3 void WaterCoolingTemperatureControlModule::initialize(int32_t id, config_t* cfg, hardwared_config_t* hardwaredconfig) { #if 0 @@ -141,8 +141,8 @@ int32_t WaterCoolingTemperatureControlModule::do_action(int32_t actioncode) { return test_peltier_set_power_level(m_reg.module_action_param1); } else if (actioncode == ACTION_TEST_PUMP_SET_LEVEL) { return test_pump_set_level(m_reg.module_action_param1); - } else if (actioncode == ACTION_TEST_PUMP_FAN_SET_LEVEL) { - return test_pump_fan_set_level(m_reg.module_action_param1); + } else if (actioncode == ACTION_TEST_FAN_SET_LEVEL) { + return test_fan_set_level(m_reg.module_action_param1); } else { return err::kmodule_not_support_action; } @@ -340,12 +340,10 @@ int32_t WaterCoolingTemperatureControlModule::test_pump_set_level(int32_t level) } return 0; } -int32_t WaterCoolingTemperatureControlModule::test_pump_fan_set_level(int32_t level) { +int32_t WaterCoolingTemperatureControlModule::test_fan_set_level(int32_t level) { if (level == 0) { - pump_stop(); fan_stop(); } else { - pump_start(level); fan_start(level); } return 0; 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 510f693..2df01b4 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 @@ -146,7 +146,7 @@ class WaterCoolingTemperatureControlModule : public ZIModule { public: int32_t test_peltier_set_power_level(int32_t level); int32_t test_pump_set_level(int32_t level); - int32_t test_pump_fan_set_level(int32_t level); + int32_t test_fan_set_level(int32_t level); private: int32_t getworkstate();