12 changed files with 164 additions and 317 deletions
-
9chip/zpwm_generator_muti_channel.cpp
-
9components/api/zi_dc_motor_ctrl_module.hpp
-
6components/api/zi_pwm_fan_ctrl_module.hpp
-
5components/api/zi_pwm_pump_ctrl_module.hpp
-
153components/fan_group_ctrl_module/fan_group_ctrl_module.cpp
-
91components/fan_group_ctrl_module/fan_group_ctrl_module.hpp
-
6components/water_cooling_temperature_control_module/pwm_ctrl_module.hpp
-
48components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.cpp
-
22components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.hpp
-
74components/zcancmder_module/zcan_fan_ctrl_module.cpp
-
56components/zcancmder_module/zcan_fan_ctrl_module.hpp
-
2components/zprotocols/zcancmder_v2
@ -1,153 +0,0 @@ |
|||
#include "fan_group_ctrl_module.hpp"
|
|||
|
|||
#include "sdk\components\zprotocols\zcancmder_v2\api\api.hpp"
|
|||
#include "sdk\components\zprotocols\zcancmder_v2\api\errorcode.hpp"
|
|||
using namespace iflytop; |
|||
#define TAG "FGCM"
|
|||
void FanGroupCtrlMoudle::initialize(config_t* pcfg) { |
|||
ZASSERT(pcfg->name != nullptr); |
|||
ZASSERT(pcfg); |
|||
m_mutex.init(); |
|||
// ZASSERT(pcfg->fanCtrlTim);
|
|||
cfg = *pcfg; |
|||
m_enablefbcheck = pcfg->enablefbcheck; |
|||
|
|||
if (m_enablefbcheck) { |
|||
for (int32_t i = 0; i < ZARRAY_SIZE(cfg.fanFBGpioCfg); i++) { |
|||
if (cfg.fanFBGpioCfg[i].pin != PinNull) { |
|||
m_fanFBGpio[i].initAsInput(cfg.fanFBGpioCfg[i].pin, //
|
|||
cfg.fanFBGpioCfg[i].mode, //
|
|||
ZGPIO::kIRQ_risingIrq, //
|
|||
cfg.fanFBGpioCfg[i].mirror); |
|||
m_fanFBGpio[i].regListener([this, i](ZGPIO* GPIO_Pin, ZGPIO::IrqTypeEvent_t irqevent) { onfbgpioirq(i); }); |
|||
m_nfanFBGpio++; |
|||
} |
|||
} |
|||
ZASSERT(pcfg->nfan == m_nfanFBGpio); |
|||
} |
|||
|
|||
for (int32_t i = 0; i < ZARRAY_SIZE(cfg.fanPowerGpioCfg); i++) { |
|||
if (cfg.fanPowerGpioCfg[i].pin != PinNull) { |
|||
m_fanPowerGpio[i].initAsOutput(cfg.fanPowerGpioCfg[i].pin, //
|
|||
cfg.fanPowerGpioCfg[i].mode, //
|
|||
cfg.fanPowerGpioCfg[i].initLevel, //
|
|||
cfg.fanPowerGpioCfg[i].mirror); |
|||
m_fanPowerGpio[i].enableTrace(pcfg->enableTrace); |
|||
m_nfanPowerPin++; |
|||
} |
|||
} |
|||
cfg.pwm_cfg.calltrace = pcfg->enableTrace; |
|||
m_fanCtrlPwm.initialize(&cfg.pwm_cfg); |
|||
OSDefaultSchduler::getInstance()->regPeriodJob([this](OSDefaultSchduler::Context&) { checkfanState(); }, 1000); |
|||
} |
|||
|
|||
int32_t FanGroupCtrlMoudle::module_xxx_reg(int32_t param_id, bool read, int32_t& val) { |
|||
switch (param_id) { |
|||
MODULE_COMMON_PROCESS_REG_CB(); |
|||
default: |
|||
return err::kmodule_not_find_config_index; |
|||
break; |
|||
} |
|||
return 0; |
|||
} |
|||
|
|||
void FanGroupCtrlMoudle::onfbgpioirq(int32_t fanindex) { |
|||
// IRQ Context,ÖжÏÉÏÏÂÎÄ
|
|||
m_fanstate[fanindex].fanFBCount++; |
|||
m_fanstate[fanindex].lastupdateFanFBCountTime = zos_get_tick(); |
|||
} |
|||
|
|||
int32_t FanGroupCtrlMoudle::startModule(int32_t duty) { |
|||
// ZLOGI("startModule duty:%d", duty);
|
|||
zlock_guard lck(m_mutex); |
|||
if (duty < 20) duty = 20; |
|||
fanisworking = true; |
|||
|
|||
clearError(); |
|||
startFanPWM(duty); |
|||
powerON(); |
|||
m_lastcheckTime = zos_get_tick(); |
|||
return 0; |
|||
} |
|||
int32_t FanGroupCtrlMoudle::stopModule() { |
|||
zlock_guard lck(m_mutex); |
|||
|
|||
fanisworking = false; |
|||
stopFanPWM(); |
|||
powerOff(); |
|||
return 0; |
|||
} |
|||
|
|||
int32_t FanGroupCtrlMoudle::getSubModuleErrorState(int32_t fanindex, int32_t* error_state) { |
|||
if (fanindex > 3) { |
|||
return err::kfail; |
|||
} |
|||
|
|||
*error_state = m_fanstate[fanindex].fanerrorstate; |
|||
return 0; |
|||
} |
|||
|
|||
bool FanGroupCtrlMoudle::isError() { |
|||
bool iserror = false; |
|||
for (int32_t i = 0; i < cfg.nfan; i++) { |
|||
if (m_fanstate[i].fanerrorstate > 0) { |
|||
iserror = true; |
|||
break; |
|||
} |
|||
} |
|||
return iserror; |
|||
} |
|||
|
|||
void FanGroupCtrlMoudle::checkfanState() { |
|||
zlock_guard lck(m_mutex); |
|||
if (!m_enablefbcheck) return; |
|||
|
|||
if (zos_haspassedms(m_lastcheckTime) < 3 * 1000) { |
|||
return; |
|||
} |
|||
|
|||
m_lastcheckTime = zos_get_tick(); |
|||
for (int32_t i = 0; i < cfg.nfan; i++) { |
|||
checkfanState(i); |
|||
} |
|||
} |
|||
|
|||
void FanGroupCtrlMoudle::checkfanState(int32_t fanindex) { |
|||
if (fanisworking && zos_haspassedms(m_fanstate[fanindex].lastupdateFanFBCountTime) > 10 * 1000) { |
|||
m_fanstate[fanindex].fanerrorstate = 1; |
|||
ZLOGE(TAG, "%s checkfanState fanindex:%d error", cfg.name, fanindex); |
|||
stopModule(); |
|||
} |
|||
} |
|||
|
|||
void FanGroupCtrlMoudle::powerON() { |
|||
for (int32_t i = 0; i < m_nfanPowerPin; i++) { |
|||
m_fanPowerGpio[i].setState(true); |
|||
} |
|||
} |
|||
void FanGroupCtrlMoudle::powerOff() { |
|||
for (int32_t i = 0; i < m_nfanPowerPin; i++) { |
|||
m_fanPowerGpio[i].setState(false); |
|||
} |
|||
} |
|||
|
|||
void FanGroupCtrlMoudle::clearError() { |
|||
for (int32_t i = 0; i < cfg.nfan; i++) { |
|||
m_fanstate[i].fanerrorstate = 0; |
|||
} |
|||
} |
|||
|
|||
void FanGroupCtrlMoudle::startFanPWM(int32_t duty) { |
|||
for (int32_t i = 0; i < ZARRAY_SIZE(cfg.fan0Channel); i++) { |
|||
if (cfg.fan0Channel[i] != 0) { |
|||
m_fanCtrlPwm.startPWM(cfg.fan0Channel[i], duty); |
|||
} |
|||
} |
|||
} |
|||
void FanGroupCtrlMoudle::stopFanPWM() { |
|||
for (int32_t i = 0; i < ZARRAY_SIZE(cfg.fan0Channel); i++) { |
|||
if (cfg.fan0Channel[i] != 0) { |
|||
m_fanCtrlPwm.stopPWM(cfg.fan0Channel[i]); |
|||
} |
|||
} |
|||
} |
@ -1,91 +0,0 @@ |
|||
#pragma once
|
|||
/**
|
|||
* @file |
|||
* @author zhaohe (h_zhaohe@163.com) |
|||
* @brief |
|||
* @version 0.1 |
|||
* @date 2023-04-14 |
|||
* |
|||
* @copyright Copyright (c) 2023 |
|||
* |
|||
*/ |
|||
#include <stdint.h>
|
|||
|
|||
#include "sdk/os/zos.hpp"
|
|||
#include "sdk\chip\zpwm_generator_muti_channel.hpp"
|
|||
#include "sdk\components\zprotocols\zcancmder_v2\api\api.hpp"
|
|||
#include "sdk\components\zprotocols\zcancmder_v2\api\zi_module.hpp"
|
|||
#include "sdk\os\mutex.hpp"
|
|||
//
|
|||
|
|||
namespace iflytop { |
|||
// SUPPORT REG
|
|||
|
|||
class FanGroupCtrlMoudle : public ZIModule { |
|||
ENABLE_MODULE(FanGroupCtrlMoudle, kfan_ctrl_module, 1); |
|||
|
|||
public: |
|||
typedef struct { |
|||
// TIM_HandleTypeDef* fanCtrlTim;
|
|||
const char* name; |
|||
|
|||
ZPWMGeneratorMutiChannel::hardware_config_t pwm_cfg; |
|||
|
|||
int32_t nfan; |
|||
int32_t fan0Channel[4]; |
|||
ZGPIO::InputGpioCfg_t fanFBGpioCfg[4]; |
|||
ZGPIO::OutputGpioCfg_t fanPowerGpioCfg[4]; |
|||
bool enablefbcheck; |
|||
bool enableTrace; |
|||
} config_t; |
|||
|
|||
typedef struct { |
|||
int32_t fanFBCount; |
|||
uint32_t lastupdateFanFBCountTime; |
|||
int32_t fanerrorstate; |
|||
} fanState_t; |
|||
|
|||
ZPWMGeneratorMutiChannel m_fanCtrlPwm; |
|||
|
|||
ZGPIO m_fanFBGpio[4]; |
|||
int32_t m_nfanFBGpio = 0; |
|||
|
|||
ZGPIO m_fanPowerGpio[4]; |
|||
int32_t m_nfanPowerPin = 0; |
|||
|
|||
fanState_t m_fanstate[4]; |
|||
bool fanisworking = false; |
|||
uint32_t m_lastcheckTime = 0; |
|||
|
|||
config_t cfg; |
|||
|
|||
bool m_enablefbcheck = false; |
|||
zmutex m_mutex; |
|||
|
|||
public: |
|||
FanGroupCtrlMoudle(){}; |
|||
|
|||
void initialize(config_t* fangroup); |
|||
|
|||
int32_t startModule(int32_t duty); |
|||
int32_t stopModule(); |
|||
|
|||
int32_t getSubModuleErrorState(int32_t fanindex, int32_t* error_state); |
|||
bool isError(); |
|||
|
|||
private: |
|||
void checkfanState(); |
|||
void onfbgpioirq(int32_t fanindex); |
|||
|
|||
private: |
|||
void checkfanState(int32_t fanindex); |
|||
void powerON(); |
|||
void powerOff(); |
|||
void clearError(); |
|||
void startFanPWM(int32_t duty); |
|||
void stopFanPWM(); |
|||
|
|||
virtual int32_t module_xxx_reg(int32_t param_id, bool read, int32_t& val) override; |
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -0,0 +1,74 @@ |
|||
#include "zcan_fan_ctrl_module.hpp"
|
|||
using namespace iflytop; |
|||
using namespace std; |
|||
#if 1
|
|||
#define TAG "ZcanFanCtrlModule"
|
|||
void ZcanFanCtrlModule::initialize(int32_t id, ZIPWMFanCtrlModule* fanmodule, int32_t default_speed) { |
|||
m_id = id; |
|||
m_fanmodule = fanmodule; |
|||
ZASSERT(m_fanmodule != nullptr); |
|||
|
|||
OSDefaultSchduler::getInstance()->regPeriodJob( |
|||
[this](OSDefaultSchduler::Context& context) { //
|
|||
if (m_isworking && m_com_reg.module_errorcode == 0) { |
|||
if (m_fanmodule->isError()) { |
|||
ZLOGE(TAG, "detect fan error,stop fan"); |
|||
m_com_reg.module_errorcode = err::khwardware_error; |
|||
m_fanmodule->clearError(); |
|||
module_stop(); |
|||
} |
|||
} |
|||
}, |
|||
10); |
|||
} |
|||
|
|||
int32_t ZcanFanCtrlModule::getid(int32_t* id) { |
|||
*id = m_id; |
|||
return 0; |
|||
} |
|||
int32_t ZcanFanCtrlModule::module_get_status(int32_t* status) { |
|||
if (m_com_reg.module_errorcode != 0) { |
|||
*status = 2; |
|||
} else if (m_isworking) { |
|||
*status = 1; |
|||
} else { |
|||
*status = 0; |
|||
} |
|||
return 0; |
|||
} |
|||
int32_t ZcanFanCtrlModule::set_fan_default_speed(int32_t default_speed) { |
|||
m_default_speed = default_speed; |
|||
if (m_isworking) m_fanmodule->setFanSpeed(default_speed); |
|||
return 0; |
|||
} |
|||
|
|||
int32_t ZcanFanCtrlModule::module_xxx_reg(int32_t param_id, bool read, int32_t& val) { |
|||
switch (param_id) { |
|||
MODULE_COMMON_PROCESS_REG_CB(); |
|||
PROCESS_REG(kreg_fan0_ctrl_speed_level, REG_GET(m_default_speed), set_fan_default_speed(val)); |
|||
break; |
|||
default: |
|||
return err::kmodule_not_find_config_index; |
|||
} |
|||
return err::kmodule_not_find_config_index; |
|||
} |
|||
|
|||
int32_t ZcanFanCtrlModule::module_stop() { |
|||
m_isworking = false; |
|||
m_fanmodule->stop(); |
|||
return 0; |
|||
} |
|||
int32_t ZcanFanCtrlModule::module_start() { |
|||
module_clear_error(); |
|||
|
|||
if (m_default_speed == 0) { |
|||
module_stop(); |
|||
} |
|||
|
|||
m_isworking = true; |
|||
m_fanmodule->setFanSpeed(m_default_speed); |
|||
return 0; |
|||
} |
|||
|
|||
int32_t ZcanFanCtrlModule::do_action(int32_t actioncode) { return 0; } |
|||
#endif
|
@ -0,0 +1,56 @@ |
|||
#pragma once
|
|||
/**
|
|||
* @file tmp117.hpp |
|||
* @author zhaohe (h_zhaohe@163.com) |
|||
* @brief |
|||
* @version 0.1 |
|||
* @date 2023-04-14 |
|||
* |
|||
* @copyright Copyright (c) 2023 |
|||
* |
|||
* |
|||
* 1. 参考:https://github.com/rkiyak/TMP117.git
|
|||
* 2. 同级目录有芯片的datasheet。 |
|||
*/ |
|||
#include <stdint.h>
|
|||
|
|||
#include "sdk/os/zos.hpp"
|
|||
//
|
|||
#include "sdk\components\api\zi_pwm_fan_ctrl_module.hpp"
|
|||
#include "sdk\components\zprotocols\zcancmder_v2\api\api.hpp"
|
|||
|
|||
namespace iflytop { |
|||
/**
|
|||
* @brief |
|||
* 水冷温度控制模块 |
|||
*/ |
|||
|
|||
class ZcanFanCtrlModule : public ZIModule { |
|||
ENABLE_MODULE(ZcanFanCtrlModule, kfan_ctrl_module, 1); |
|||
|
|||
public: |
|||
ZIPWMFanCtrlModule* m_fanmodule = nullptr; |
|||
int32_t m_id = 0; |
|||
|
|||
bool m_isworking = false; |
|||
|
|||
int32_t m_default_speed = 50; |
|||
|
|||
public: |
|||
ZcanFanCtrlModule(){}; |
|||
virtual ~ZcanFanCtrlModule(){}; |
|||
|
|||
void initialize(int32_t id, ZIPWMFanCtrlModule* fanmodule, int32_t default_speed); |
|||
|
|||
virtual int32_t getid(int32_t* id) override; |
|||
virtual int32_t module_get_status(int32_t* status) override; |
|||
virtual int32_t module_start() override; |
|||
virtual int32_t module_stop() override; |
|||
virtual int32_t module_xxx_reg(int32_t param_id, bool read, int32_t& val) override; |
|||
|
|||
public: |
|||
virtual int32_t set_fan_default_speed(int32_t default_speed); |
|||
virtual int32_t do_action(int32_t actioncode) override; |
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -1 +1 @@ |
|||
Subproject commit ab909260b588f575c9286bf4d3a72560f2f1ede7 |
|||
Subproject commit 57636804cb7e8bd84466ce009d57c372cc20b9ea |
Write
Preview
Loading…
Cancel
Save
Reference in new issue