|
|
@ -5,7 +5,6 @@ |
|
|
|
#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"
|
|
|
|
//
|
|
|
@ -16,6 +15,14 @@ |
|
|
|
#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"
|
|
|
|
|
|
|
|
// cancmder basic
|
|
|
|
#include "sdk\components\cmdscheduler\cmd_scheduler_v2.hpp"
|
|
|
|
#include "sdk\components\hardware\uart\zuart_dma_receiver.hpp"
|
|
|
|
#include "sdk\components\zcancmder\zcan_board_module.hpp"
|
|
|
|
#include "sdk\components\zprotocol_helper\micro_computer_module_device_script_cmder_paser.hpp"
|
|
|
|
#include "sdk\components\zprotocols\zcancmder_v2\protocol_parser.hpp"
|
|
|
|
#include "sdk\components\zprotocols\zcancmder_v2\zmodule_device_manager.hpp"
|
|
|
|
//
|
|
|
|
#define TAG "main"
|
|
|
|
using namespace iflytop; |
|
|
|
using namespace std; |
|
|
@ -25,8 +32,14 @@ extern "C" { |
|
|
|
void StartDefaultTask(void const* argument) { umain(); } |
|
|
|
} |
|
|
|
|
|
|
|
static ZCanCmder g_zcanCmder; |
|
|
|
static ZIProtocolParser g_ziProtocolParser; |
|
|
|
// static ZCanCmder g_zcanCmder;
|
|
|
|
// static ZIProtocolParser g_ziProtocolParser;
|
|
|
|
|
|
|
|
static ZCanCmder g_zcanCmder; |
|
|
|
static ZIProtocolParser g_ziProtocolParser; |
|
|
|
static ZModuleDeviceManager g_zModuleDeviceManager; |
|
|
|
static MicroComputerModuleDeviceScriptCmderPaser g_zModuleDeviceScriptCmderPaser; |
|
|
|
static uint32_t g_deviceId = 0; |
|
|
|
|
|
|
|
uint8_t getId() { |
|
|
|
static bool init = false; |
|
|
@ -47,47 +60,32 @@ uint8_t getId() { |
|
|
|
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) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void initcfg() { |
|
|
|
/**
|
|
|
|
* @brief 初始化配置,系统中需要配置都需要在这里进行初始化 |
|
|
|
*/ |
|
|
|
#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(); |
|
|
|
|
|
|
|
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)); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
void initmodule() { |
|
|
|
#define TIMER2_FREQ 1000
|
|
|
|
#define TIMER1_FREQ 1000
|
|
|
|
#define HEART_SHAFT false
|
|
|
|
/*******************************************************************************
|
|
|
|
* 风扇配置 * |
|
|
|
*******************************************************************************/ |
|
|
|
PWMSpeedCtrlModule::config_t fan0cfg = { |
|
|
|
.fanCtrlTim = &htim2, |
|
|
|
.pwm_cfg = |
|
|
|
{ |
|
|
|
.name = "fan0pwmtimer", |
|
|
|
.htim = &htim2, |
|
|
|
.freq = TIMER2_FREQ, |
|
|
|
.polarity = true, |
|
|
|
}, |
|
|
|
.nfan = 2, |
|
|
|
.fan0Channel = {3, 0, 0, 0}, |
|
|
|
.fanFBGpioCfg = |
|
|
@ -97,11 +95,23 @@ void umain() { |
|
|
|
}, |
|
|
|
.fanPowerGpioCfg = |
|
|
|
{ |
|
|
|
{.pin = PC4, .mode = ZGPIO::kMode_nopull, .mirror = false}, |
|
|
|
{ |
|
|
|
.pin = PC4, |
|
|
|
.mode = ZGPIO::kMode_nopull, |
|
|
|
.mirror = false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
.enablefbcheck = true, |
|
|
|
.enableTrace = true, |
|
|
|
}; |
|
|
|
PWMSpeedCtrlModule::config_t fan1cfg = { |
|
|
|
.fanCtrlTim = &htim2, |
|
|
|
.pwm_cfg = |
|
|
|
{ |
|
|
|
.name = "fan1pwmtimer", |
|
|
|
.htim = &htim2, |
|
|
|
.freq = TIMER2_FREQ, |
|
|
|
.polarity = true, |
|
|
|
}, |
|
|
|
.nfan = 2, |
|
|
|
.fan0Channel = {4, 0, 0, 0}, |
|
|
|
.fanFBGpioCfg = |
|
|
@ -111,15 +121,28 @@ void umain() { |
|
|
|
}, |
|
|
|
.fanPowerGpioCfg = |
|
|
|
{ |
|
|
|
{.pin = PC5, .mode = ZGPIO::kMode_nopull, .mirror = false}, |
|
|
|
{ |
|
|
|
.pin = PC5, |
|
|
|
.mode = ZGPIO::kMode_nopull, |
|
|
|
.mirror = false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
.enablefbcheck = true, |
|
|
|
.enableTrace = true, |
|
|
|
}; |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 水泵配置 * |
|
|
|
*******************************************************************************/ |
|
|
|
PWMSpeedCtrlModule::config_t pumpcfg = { |
|
|
|
.fanCtrlTim = &htim2, |
|
|
|
.pwm_cfg = |
|
|
|
{ |
|
|
|
.name = "pumptime", |
|
|
|
.htim = &htim2, |
|
|
|
.freq = TIMER2_FREQ, |
|
|
|
.polarity = true, |
|
|
|
.calltrace = true, |
|
|
|
}, |
|
|
|
.nfan = 1, |
|
|
|
.fan0Channel = {2, 0, 0, 0}, |
|
|
|
.fanFBGpioCfg = |
|
|
@ -128,27 +151,48 @@ void umain() { |
|
|
|
}, |
|
|
|
.fanPowerGpioCfg = |
|
|
|
{ |
|
|
|
{.pin = PC2, .mode = ZGPIO::kMode_nopull, .mirror = false}, |
|
|
|
{ |
|
|
|
.pin = PC2, |
|
|
|
.mode = ZGPIO::kMode_nopull, |
|
|
|
.mirror = false, |
|
|
|
.log_when_setstate = true, |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
.enablefbcheck = false, |
|
|
|
.enableTrace = true, |
|
|
|
}; |
|
|
|
|
|
|
|
DRV8710::config_t peltier_config0 = { |
|
|
|
.tim = &htim1, |
|
|
|
.in1_chnannel_index = 1, |
|
|
|
.in2 = PE10, |
|
|
|
.pwm_cfg = |
|
|
|
{ |
|
|
|
.name = "peltier0_pwm", |
|
|
|
.htim = &htim1, |
|
|
|
.freq = TIMER1_FREQ, |
|
|
|
.polarity = true, |
|
|
|
}, |
|
|
|
.in1_chnannel_index = 1, // PE9
|
|
|
|
.in2 = PE11, |
|
|
|
.nsleep = PB2, |
|
|
|
.nfault = PB3, |
|
|
|
.shaft = false, |
|
|
|
.shaft = HEART_SHAFT, |
|
|
|
.enableTrace = true, |
|
|
|
}; |
|
|
|
|
|
|
|
DRV8710::config_t peltier_config1 = { |
|
|
|
.tim = &htim1, |
|
|
|
.in1_chnannel_index = 3, |
|
|
|
.pwm_cfg = |
|
|
|
{ |
|
|
|
.name = "peltier1_pwm", |
|
|
|
.htim = &htim1, |
|
|
|
.freq = TIMER1_FREQ, |
|
|
|
.polarity = true, |
|
|
|
}, |
|
|
|
.in1_chnannel_index = 3, // PE13
|
|
|
|
.in2 = PE14, |
|
|
|
.nsleep = PB13, |
|
|
|
.nfault = PB14, |
|
|
|
.shaft = false, |
|
|
|
|
|
|
|
.shaft = HEART_SHAFT, |
|
|
|
.enableTrace = true, |
|
|
|
}; |
|
|
|
|
|
|
|
static TMP117 temp[4]; |
|
|
@ -158,49 +202,101 @@ void umain() { |
|
|
|
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); |
|
|
|
fan0.initialize(&fan0cfg); |
|
|
|
fan1.initialize(&fan1cfg); |
|
|
|
pump.initialize(&pumpcfg); |
|
|
|
peltier0.initialize(&peltier_config0); |
|
|
|
peltier1.initialize(&peltier_config1); |
|
|
|
|
|
|
|
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}, |
|
|
|
} //
|
|
|
|
}; |
|
|
|
{ |
|
|
|
/**
|
|
|
|
* @brief 板子本身模块初始化 |
|
|
|
*/ |
|
|
|
static ZCanBoardModule::hardware_config_t cfg = { |
|
|
|
.input = |
|
|
|
{ |
|
|
|
{PC6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true}, |
|
|
|
{PC7, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true}, |
|
|
|
}, |
|
|
|
.output = |
|
|
|
{ |
|
|
|
{PD0, ZGPIO::kMode_nopull, false, false}, |
|
|
|
} //
|
|
|
|
}; |
|
|
|
static ZCanBoardModule boardmodule; |
|
|
|
boardmodule.initialize(g_deviceId, &cfg); |
|
|
|
g_ziProtocolParser.registerModule(&boardmodule); |
|
|
|
g_zModuleDeviceManager.registerModule(&boardmodule); |
|
|
|
} |
|
|
|
|
|
|
|
waterCoolingTemperatureControlModule.initialize(deviceId, &temp_ctrl_config, &hardwared_config); |
|
|
|
{ |
|
|
|
/*******************************************************************************
|
|
|
|
* 控温模块初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
static WaterCoolingTemperatureControlModule waterCoolingTemperatureControlModule; |
|
|
|
static 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}, |
|
|
|
}; |
|
|
|
|
|
|
|
auto zcanCmder_cfg = g_zcanCmder.createCFG(deviceId); |
|
|
|
g_zcanCmder.init(zcanCmder_cfg); |
|
|
|
waterCoolingTemperatureControlModule.initialize(g_deviceId + 1, &temp_ctrl_config, &hardwared_config); |
|
|
|
g_zModuleDeviceManager.registerModule(&waterCoolingTemperatureControlModule); |
|
|
|
g_ziProtocolParser.registerModule(&waterCoolingTemperatureControlModule); |
|
|
|
} |
|
|
|
} |
|
|
|
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); |
|
|
|
|
|
|
|
g_deviceId = getId() * 10; |
|
|
|
ZLOGI(TAG, "motorId:%d", g_deviceId); |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* NVSINIT * |
|
|
|
*******************************************************************************/ |
|
|
|
ZNVS::ins().initialize(IFLYTOP_NVS_CONFIG_FLASH_SECTOR); |
|
|
|
initcfg(); |
|
|
|
ZNVS::ins().init_config(); |
|
|
|
|
|
|
|
auto zcanCmder_cfg = g_zcanCmder.createCFG(g_deviceId); |
|
|
|
g_zcanCmder.init(zcanCmder_cfg); |
|
|
|
g_ziProtocolParser.initialize(&g_zcanCmder); |
|
|
|
g_ziProtocolParser.registerModule(&waterCoolingTemperatureControlModule); |
|
|
|
|
|
|
|
static ZUARTDmaReceiver dmaUartReceiver; |
|
|
|
static CmdSchedulerV2 cmder; |
|
|
|
ZUARTDmaReceiver::hardware_config_t cfg = { |
|
|
|
.huart = &DEBUG_UART, |
|
|
|
.dma_rx = &DEBUG_UART_DMA, |
|
|
|
.rxbuffersize = 1024, |
|
|
|
.rxovertime_ms = 10, |
|
|
|
}; |
|
|
|
dmaUartReceiver.initialize(&cfg); |
|
|
|
cmder.initialize(&dmaUartReceiver); |
|
|
|
g_zModuleDeviceManager.initialize(nullptr); |
|
|
|
g_zModuleDeviceScriptCmderPaser.initialize(&cmder, &g_zModuleDeviceManager); |
|
|
|
|
|
|
|
initmodule(); |
|
|
|
while (true) { |
|
|
|
OSDefaultSchduler::getInstance()->loop(); |
|
|
|
g_zcanCmder.loop(); |
|
|
|
cmder.schedule(); |
|
|
|
} |
|
|
|
}; |
|
|
|
} |