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.
302 lines
9.9 KiB
302 lines
9.9 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\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"
|
|
|
|
// 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;
|
|
|
|
extern void umain();
|
|
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 ZModuleDeviceManager g_zModuleDeviceManager;
|
|
static MicroComputerModuleDeviceScriptCmderPaser g_zModuleDeviceScriptCmderPaser;
|
|
static uint32_t g_deviceId = 0;
|
|
|
|
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 initcfg() {
|
|
/**
|
|
* @brief 初始化配置,系统中需要配置都需要在这里进行初始化
|
|
*/
|
|
#if 0
|
|
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 = {
|
|
.pwm_cfg =
|
|
{
|
|
.name = "fan0pwmtimer",
|
|
.htim = &htim2,
|
|
.freq = TIMER2_FREQ,
|
|
.polarity = true,
|
|
},
|
|
.nfan = 2,
|
|
.fan0Channel = {3, 0, 0, 0},
|
|
.fanFBGpioCfg =
|
|
{
|
|
{.pin = PC10},
|
|
{.pin = PC11},
|
|
},
|
|
.fanPowerGpioCfg =
|
|
{
|
|
{
|
|
.pin = PC4,
|
|
.mode = ZGPIO::kMode_nopull,
|
|
.mirror = false,
|
|
},
|
|
},
|
|
.enablefbcheck = true,
|
|
.enableTrace = true,
|
|
};
|
|
PWMSpeedCtrlModule::config_t fan1cfg = {
|
|
.pwm_cfg =
|
|
{
|
|
.name = "fan1pwmtimer",
|
|
.htim = &htim2,
|
|
.freq = TIMER2_FREQ,
|
|
.polarity = true,
|
|
},
|
|
.nfan = 2,
|
|
.fan0Channel = {4, 0, 0, 0},
|
|
.fanFBGpioCfg =
|
|
{
|
|
{.pin = PC12},
|
|
{.pin = PC13},
|
|
},
|
|
.fanPowerGpioCfg =
|
|
{
|
|
{
|
|
.pin = PC5,
|
|
.mode = ZGPIO::kMode_nopull,
|
|
.mirror = false,
|
|
},
|
|
},
|
|
.enablefbcheck = true,
|
|
.enableTrace = true,
|
|
};
|
|
|
|
/*******************************************************************************
|
|
* 水泵配置 *
|
|
*******************************************************************************/
|
|
PWMSpeedCtrlModule::config_t pumpcfg = {
|
|
.pwm_cfg =
|
|
{
|
|
.name = "pumptime",
|
|
.htim = &htim2,
|
|
.freq = TIMER2_FREQ,
|
|
.polarity = true,
|
|
.calltrace = true,
|
|
},
|
|
.nfan = 1,
|
|
.fan0Channel = {2, 0, 0, 0},
|
|
.fanFBGpioCfg =
|
|
{
|
|
{.pin = PC3},
|
|
},
|
|
.fanPowerGpioCfg =
|
|
{
|
|
{
|
|
.pin = PC2,
|
|
.mode = ZGPIO::kMode_nopull,
|
|
.mirror = false,
|
|
.log_when_setstate = true,
|
|
|
|
},
|
|
},
|
|
.enablefbcheck = false,
|
|
.enableTrace = true,
|
|
};
|
|
|
|
DRV8710::config_t peltier_config0 = {
|
|
.pwm_cfg =
|
|
{
|
|
.name = "peltier0_pwm",
|
|
.htim = &htim1,
|
|
.freq = TIMER1_FREQ,
|
|
.polarity = true,
|
|
},
|
|
.in1_chnannel_index = 1, // PE9
|
|
.in2 = PE11,
|
|
.nsleep = PB2,
|
|
.nfault = PB3,
|
|
.shaft = HEART_SHAFT,
|
|
.enableTrace = true,
|
|
};
|
|
|
|
DRV8710::config_t peltier_config1 = {
|
|
.pwm_cfg =
|
|
{
|
|
.name = "peltier1_pwm",
|
|
.htim = &htim1,
|
|
.freq = TIMER1_FREQ,
|
|
.polarity = true,
|
|
},
|
|
.in1_chnannel_index = 3, // PE13
|
|
.in2 = PE14,
|
|
.nsleep = PB13,
|
|
.nfault = PB14,
|
|
.shaft = HEART_SHAFT,
|
|
.enableTrace = true,
|
|
};
|
|
|
|
static TMP117 temp[4];
|
|
static PWMSpeedCtrlModule fan0;
|
|
static PWMSpeedCtrlModule fan1;
|
|
static PWMSpeedCtrlModule pump;
|
|
static DRV8710 peltier0;
|
|
static DRV8710 peltier1;
|
|
|
|
temp[0].initializate(&hi2c1, TMP117::ID0);
|
|
temp[1].initializate(&hi2c1, TMP117::ID1);
|
|
temp[2].initializate(&hi2c1, TMP117::ID2);
|
|
temp[3].initializate(&hi2c1, TMP117::ID3);
|
|
|
|
fan0.initialize(&fan0cfg);
|
|
fan1.initialize(&fan1cfg);
|
|
pump.initialize(&pumpcfg);
|
|
peltier0.initialize(&peltier_config0);
|
|
peltier1.initialize(&peltier_config1);
|
|
|
|
{
|
|
/**
|
|
* @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);
|
|
}
|
|
|
|
{
|
|
/*******************************************************************************
|
|
* 控温模块初始化 *
|
|
*******************************************************************************/
|
|
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},
|
|
};
|
|
|
|
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);
|
|
|
|
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();
|
|
}
|
|
}
|