Browse Source

update

master
zhaohe 2 years ago
parent
commit
a41640afe9
  1. 2
      chip/zpwm_generator_muti_channel.cpp
  2. 15
      components/water_cooling_temperature_control_module/pwm_ctrl_module.cpp
  3. 8
      components/water_cooling_temperature_control_module/pwm_ctrl_module.hpp
  4. 10
      components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.cpp
  5. 2
      components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.hpp

2
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) { void ZPWMGeneratorMutiChannel::startPWM(int32_t channelindex /*1£¬2£¬3£¬4*/, float duty) {
if (channelindex < 1 || channelindex > 4) return; if (channelindex < 1 || channelindex > 4) return;
m_pwmstate[channelindex] = true; 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); updatePWMState(channelindex, duty);
} }
void ZPWMGeneratorMutiChannel::stopPWM(int32_t channelindex) { void ZPWMGeneratorMutiChannel::stopPWM(int32_t channelindex) {

15
components/water_cooling_temperature_control_module/pwm_ctrl_module.cpp

@ -2,9 +2,11 @@
#include "sdk\components\zprotocols\zcancmder_v2\api\errorcode.hpp" #include "sdk\components\zprotocols\zcancmder_v2\api\errorcode.hpp"
using namespace iflytop; using namespace iflytop;
#define TAG "PWM_SCM"
void PWMSpeedCtrlModule::initialize(config_t* pcfg) { void PWMSpeedCtrlModule::initialize(config_t* pcfg) {
ZASSERT(pcfg->name != nullptr);
ZASSERT(pcfg); ZASSERT(pcfg);
m_mutex.init();
// ZASSERT(pcfg->fanCtrlTim); // ZASSERT(pcfg->fanCtrlTim);
cfg = *pcfg; cfg = *pcfg;
m_enablefbcheck = pcfg->enablefbcheck; m_enablefbcheck = pcfg->enablefbcheck;
@ -35,6 +37,7 @@ void PWMSpeedCtrlModule::initialize(config_t* pcfg) {
} }
cfg.pwm_cfg.calltrace = pcfg->enableTrace; cfg.pwm_cfg.calltrace = pcfg->enableTrace;
m_fanCtrlPwm.initialize(&cfg.pwm_cfg); m_fanCtrlPwm.initialize(&cfg.pwm_cfg);
OSDefaultSchduler::getInstance()->regPeriodJob([this](OSDefaultSchduler::Context&) { checkfanState(); }, 1000);
} }
void PWMSpeedCtrlModule::onfbgpioirq(int32_t fanindex) { void PWMSpeedCtrlModule::onfbgpioirq(int32_t fanindex) {
@ -44,6 +47,8 @@ void PWMSpeedCtrlModule::onfbgpioirq(int32_t fanindex) {
} }
int32_t PWMSpeedCtrlModule::startModule(int32_t duty) { int32_t PWMSpeedCtrlModule::startModule(int32_t duty) {
// ZLOGI("startModule duty:%d", duty);
zlock_guard lck(m_mutex);
if (duty < 20) duty = 20; if (duty < 20) duty = 20;
fanisworking = true; fanisworking = true;
@ -54,6 +59,8 @@ int32_t PWMSpeedCtrlModule::startModule(int32_t duty) {
return 0; return 0;
} }
int32_t PWMSpeedCtrlModule::stopModule() { int32_t PWMSpeedCtrlModule::stopModule() {
zlock_guard lck(m_mutex);
fanisworking = false; fanisworking = false;
stopFanPWM(); stopFanPWM();
powerOff(); powerOff();
@ -81,9 +88,10 @@ bool PWMSpeedCtrlModule::isError() {
} }
void PWMSpeedCtrlModule::checkfanState() { void PWMSpeedCtrlModule::checkfanState() {
zlock_guard lck(m_mutex);
if (!m_enablefbcheck) return; if (!m_enablefbcheck) return;
if (zos_haspassedms(m_lastcheckTime) < 10 * 1000) {
if (zos_haspassedms(m_lastcheckTime) < 3 * 1000) {
return; return;
} }
@ -96,7 +104,8 @@ void PWMSpeedCtrlModule::checkfanState() {
void PWMSpeedCtrlModule::checkfanState(int32_t fanindex) { void PWMSpeedCtrlModule::checkfanState(int32_t fanindex) {
if (fanisworking && zos_haspassedms(m_fanstate[fanindex].lastupdateFanFBCountTime) > 10 * 1000) { if (fanisworking && zos_haspassedms(m_fanstate[fanindex].lastupdateFanFBCountTime) > 10 * 1000) {
m_fanstate[fanindex].fanerrorstate = 1; m_fanstate[fanindex].fanerrorstate = 1;
powerOff();
ZLOGE(TAG, "%s checkfanState fanindex:%d error", cfg.name, fanindex);
stopModule();
} }
} }

8
components/water_cooling_temperature_control_module/pwm_ctrl_module.hpp

@ -16,6 +16,7 @@
#include "sdk/os/zos.hpp" #include "sdk/os/zos.hpp"
#include "sdk\chip\zpwm_generator_muti_channel.hpp" #include "sdk\chip\zpwm_generator_muti_channel.hpp"
#include "sdk\os\mutex.hpp"
// //
namespace iflytop { namespace iflytop {
@ -25,6 +26,7 @@ class PWMSpeedCtrlModule {
public: public:
typedef struct { typedef struct {
// TIM_HandleTypeDef* fanCtrlTim; // TIM_HandleTypeDef* fanCtrlTim;
const char* name;
ZPWMGeneratorMutiChannel::hardware_config_t pwm_cfg; ZPWMGeneratorMutiChannel::hardware_config_t pwm_cfg;
int32_t nfan; int32_t nfan;
@ -55,7 +57,8 @@ class PWMSpeedCtrlModule {
config_t cfg; config_t cfg;
bool m_enablefbcheck = false;
bool m_enablefbcheck = false;
zmutex m_mutex;
public: public:
PWMSpeedCtrlModule(){}; PWMSpeedCtrlModule(){};
@ -68,9 +71,8 @@ class PWMSpeedCtrlModule {
int32_t getSubModuleErrorState(int32_t fanindex, int32_t* error_state); int32_t getSubModuleErrorState(int32_t fanindex, int32_t* error_state);
bool isError(); bool isError();
void checkfanState();
private: private:
void checkfanState();
void onfbgpioirq(int32_t fanindex); void onfbgpioirq(int32_t fanindex);
private: private:

10
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_PELTIER_SET_POWER_LEVEL 1
#define ACTION_TEST_PUMP_SET_LEVEL 2 #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) { void WaterCoolingTemperatureControlModule::initialize(int32_t id, config_t* cfg, hardwared_config_t* hardwaredconfig) {
#if 0 #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); return test_peltier_set_power_level(m_reg.module_action_param1);
} else if (actioncode == ACTION_TEST_PUMP_SET_LEVEL) { } else if (actioncode == ACTION_TEST_PUMP_SET_LEVEL) {
return test_pump_set_level(m_reg.module_action_param1); 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 { } else {
return err::kmodule_not_support_action; return err::kmodule_not_support_action;
} }
@ -340,12 +340,10 @@ int32_t WaterCoolingTemperatureControlModule::test_pump_set_level(int32_t level)
} }
return 0; 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) { if (level == 0) {
pump_stop();
fan_stop(); fan_stop();
} else { } else {
pump_start(level);
fan_start(level); fan_start(level);
} }
return 0; return 0;

2
components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.hpp

@ -146,7 +146,7 @@ class WaterCoolingTemperatureControlModule : public ZIModule {
public: public:
int32_t test_peltier_set_power_level(int32_t level); int32_t test_peltier_set_power_level(int32_t level);
int32_t test_pump_set_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: private:
int32_t getworkstate(); int32_t getworkstate();

Loading…
Cancel
Save