You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
206 lines
6.6 KiB
206 lines
6.6 KiB
#include <stddef.h>
|
|
#include <stdio.h>
|
|
|
|
#include "sdk/os/zos.hpp"
|
|
#include "sdk\components\flash\zsimple_flash.hpp"
|
|
#include "sdk\components\zcancmder\zcanreceiver.hpp"
|
|
#include "sdk\components\zcancmder_module\zcan_basic_order_module.hpp"
|
|
#include "sdk\components\zprotocols\zcancmder_v2\protocol_parser.hpp"
|
|
//
|
|
#include "sdk\components\flash\znvs.hpp"
|
|
//
|
|
#include "sdk\components\sensors\tmp117\tmp117.hpp"
|
|
#include "sdk\components\ti\drv8710.hpp"
|
|
#include "sdk\components\water_cooling_temperature_control_module\pwm_ctrl_module.hpp"
|
|
#include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module.hpp"
|
|
#include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module_factory.cpp"
|
|
#include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module_factory.hpp"
|
|
|
|
#define TAG "main"
|
|
using namespace iflytop;
|
|
using namespace std;
|
|
|
|
extern void umain();
|
|
extern "C" {
|
|
void StartDefaultTask(void const* argument) { umain(); }
|
|
}
|
|
|
|
static ZCanCmder g_zcanCmder;
|
|
static ZIProtocolParser g_ziProtocolParser;
|
|
|
|
uint8_t getId() {
|
|
static bool init = false;
|
|
static ZGPIO ID0;
|
|
static ZGPIO ID1;
|
|
static ZGPIO ID2;
|
|
static ZGPIO ID3;
|
|
static ZGPIO ID4;
|
|
if (!init) {
|
|
ID0.initAsInput(ID0_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
|
|
ID1.initAsInput(ID1_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
|
|
ID2.initAsInput(ID2_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
|
|
ID3.initAsInput(ID3_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
|
|
ID4.initAsInput(ID4_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
|
|
init = true;
|
|
}
|
|
uint8_t id = ID0.getState() * 1 + ID1.getState() * 2 + ID2.getState() * 4 + ID3.getState() * 8 + ID4.getState() * 16;
|
|
return id;
|
|
}
|
|
|
|
void umain() {
|
|
chip_cfg_t chipcfg;
|
|
chipcfg.us_dleay_tim = &DELAY_US_TIMER;
|
|
chipcfg.tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER;
|
|
chipcfg.huart = &DEBUG_UART;
|
|
chipcfg.debuglight = DEBUG_LIGHT_GPIO;
|
|
|
|
chip_init(&chipcfg);
|
|
|
|
zos_cfg_t zoscfg;
|
|
zos_init(&zoscfg);
|
|
|
|
uint8_t deviceId = getId();
|
|
ZLOGI(TAG, "motorId:%d", deviceId);
|
|
|
|
if (deviceId == 0) {
|
|
ZLOGE(TAG, "motorId can't be 0");
|
|
chip_set_error();
|
|
while (true) {
|
|
}
|
|
}
|
|
|
|
#if 0
|
|
/*******************************************************************************
|
|
* NVSINIT *
|
|
*******************************************************************************/
|
|
ZNVS::ins().initialize(IFLYTOP_NVS_CONFIG_FLASH_SECTOR);
|
|
{
|
|
static I_StepMotorCtrlModule::flash_config_t cfg;
|
|
StepMotorCtrlModule::create_default_cfg(cfg);
|
|
ZNVS::ins().alloc_config(MOTOR_CFG_FLASH_MARK, (uint8_t*)&cfg, sizeof(cfg));
|
|
}
|
|
ZNVS::ins().init_config();
|
|
|
|
#endif
|
|
|
|
/*******************************************************************************
|
|
* ·çÉÈÅäÖà *
|
|
*******************************************************************************/
|
|
PWMSpeedCtrlModule::config_t fan0cfg = {
|
|
.fanCtrlTim = &htim2,
|
|
.nfan = 2,
|
|
.fan0Channel = {3, 0, 0, 0},
|
|
.fanFBGpioCfg =
|
|
{
|
|
{.pin = PC10},
|
|
{.pin = PC11},
|
|
},
|
|
.fanPowerGpioCfg =
|
|
{
|
|
{.pin = PC4, .mode = ZGPIO::kMode_nopull, .mirror = false},
|
|
},
|
|
};
|
|
PWMSpeedCtrlModule::config_t fan1cfg = {
|
|
.fanCtrlTim = &htim2,
|
|
.nfan = 2,
|
|
.fan0Channel = {4, 0, 0, 0},
|
|
.fanFBGpioCfg =
|
|
{
|
|
{.pin = PC12},
|
|
{.pin = PC13},
|
|
},
|
|
.fanPowerGpioCfg =
|
|
{
|
|
{.pin = PC5, .mode = ZGPIO::kMode_nopull, .mirror = false},
|
|
},
|
|
};
|
|
|
|
/*******************************************************************************
|
|
* Ë®±ÃÅäÖà *
|
|
*******************************************************************************/
|
|
PWMSpeedCtrlModule::config_t pumpcfg = {
|
|
.fanCtrlTim = &htim2,
|
|
.nfan = 1,
|
|
.fan0Channel = {2, 0, 0, 0},
|
|
.fanFBGpioCfg =
|
|
{
|
|
{.pin = PC3},
|
|
},
|
|
.fanPowerGpioCfg =
|
|
{
|
|
{.pin = PC2, .mode = ZGPIO::kMode_nopull, .mirror = false},
|
|
},
|
|
};
|
|
|
|
DRV8710::config_t peltier_config0 = {
|
|
.tim = &htim1,
|
|
.in1_chnannel_index = 1,
|
|
.in2 = PE10,
|
|
.nsleep = PB2,
|
|
.nfault = PB3,
|
|
.shaft = false,
|
|
};
|
|
|
|
DRV8710::config_t peltier_config1 = {
|
|
.tim = &htim1,
|
|
.in1_chnannel_index = 3,
|
|
.in2 = PE14,
|
|
.nsleep = PB13,
|
|
.nfault = PB14,
|
|
.shaft = false,
|
|
|
|
};
|
|
|
|
static TMP117 temp[4];
|
|
static PWMSpeedCtrlModule fan0;
|
|
static PWMSpeedCtrlModule fan1;
|
|
static PWMSpeedCtrlModule pump;
|
|
static DRV8710 peltier0;
|
|
static DRV8710 peltier1;
|
|
|
|
static WaterCoolingTemperatureControlModule waterCoolingTemperatureControlModule;
|
|
|
|
fan0.initialize(&fan0cfg, true);
|
|
fan1.initialize(&fan1cfg, true);
|
|
pump.initialize(&pumpcfg, false);
|
|
peltier0.initialize(&peltier_config0);
|
|
peltier1.initialize(&peltier_config1);
|
|
|
|
temp[0].initializate(&hi2c1, TMP117::ID0);
|
|
temp[1].initializate(&hi2c1, TMP117::ID1);
|
|
temp[2].initializate(&hi2c1, TMP117::ID2);
|
|
temp[3].initializate(&hi2c1, TMP117::ID3);
|
|
|
|
WaterCoolingTemperatureControlModule::config_t temp_ctrl_config;
|
|
waterCoolingTemperatureControlModule.createDefaultConfig(&temp_ctrl_config);
|
|
|
|
WaterCoolingTemperatureControlModule::hardwared_config_t hardwared_config = //
|
|
{
|
|
.temperature_sensor = {&temp[0], &temp[1], &temp[2], &temp[3]},
|
|
.fanTable = {&fan0, &fan1},
|
|
.pump = &pump,
|
|
.peltier_ctrl = {&peltier0, &peltier1},
|
|
.ext_input =
|
|
{
|
|
{PC6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true},
|
|
{PC7, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true},
|
|
},
|
|
.ext_output =
|
|
{
|
|
{PD0, ZGPIO::kMode_nopull, false, false},
|
|
} //
|
|
};
|
|
|
|
waterCoolingTemperatureControlModule.initialize(deviceId, &temp_ctrl_config, &hardwared_config);
|
|
|
|
auto zcanCmder_cfg = g_zcanCmder.createCFG(deviceId);
|
|
g_zcanCmder.init(zcanCmder_cfg);
|
|
|
|
g_ziProtocolParser.initialize(&g_zcanCmder);
|
|
g_ziProtocolParser.registerModule(&waterCoolingTemperatureControlModule);
|
|
|
|
while (true) {
|
|
OSDefaultSchduler::getInstance()->loop();
|
|
g_zcanCmder.loop();
|
|
}
|
|
};
|