|
@ -15,12 +15,14 @@ void Hardware::hardwareinit() { |
|
|
debug_light_init(); |
|
|
debug_light_init(); |
|
|
can_init(); |
|
|
can_init(); |
|
|
temperature_init(); |
|
|
temperature_init(); |
|
|
|
|
|
fan_init(1000); |
|
|
peltier_init(); |
|
|
peltier_init(); |
|
|
} |
|
|
} |
|
|
void Hardware::periodicJob() { |
|
|
void Hardware::periodicJob() { |
|
|
debug_light_periodicJob(); |
|
|
debug_light_periodicJob(); |
|
|
can_periodicJob(); |
|
|
can_periodicJob(); |
|
|
temperature_periodicJob(); |
|
|
temperature_periodicJob(); |
|
|
|
|
|
fan_periodicJob(); |
|
|
peltier_periodicJob(); |
|
|
peltier_periodicJob(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -154,6 +156,147 @@ void Hardware::temperature_periodicJob() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
/*******************************************************************************
|
|
|
|
|
|
* 风扇 * |
|
|
|
|
|
*******************************************************************************/ |
|
|
|
|
|
void Hardware::fan_init(int freq) { |
|
|
|
|
|
STM32_HAL::setPWMFreq(&htim2, freq); // fan0->fan3
|
|
|
|
|
|
STM32_HAL::setPWMFreq(&htim4, freq); // fan4
|
|
|
|
|
|
STM32_HAL::setPWMFreq(&htim8, freq); // fan5
|
|
|
|
|
|
|
|
|
|
|
|
// fan0 fan1 fan2 fan3
|
|
|
|
|
|
STM32_HAL::gpioInitAsOutput(GPIOC, GPIO_PIN_0, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|
|
|
|
|
// fan4
|
|
|
|
|
|
STM32_HAL::gpioInitAsOutput(GPIOC, GPIO_PIN_2, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|
|
|
|
|
// fan5
|
|
|
|
|
|
STM32_HAL::gpioInitAsOutput(GPIOC, GPIO_PIN_3, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 风扇反馈初始化 |
|
|
|
|
|
* |
|
|
|
|
|
* FAN0_FB_INT PC1 |
|
|
|
|
|
* FAN1_FB_INT PC4 |
|
|
|
|
|
* FAN2_FB_INT PC5 |
|
|
|
|
|
* FAN3_FB_INT PC6 |
|
|
|
|
|
* FAN4_FB_INT PC7 |
|
|
|
|
|
* FAN5_FB_INT PC10 |
|
|
|
|
|
*/ |
|
|
|
|
|
// m_fan.fanStateMonitor[0].initialize(this, GPIOC, GPIO_PIN_1, fanGetPowerState(0));
|
|
|
|
|
|
// m_fan.fanStateMonitor[1].initialize(this, GPIOC, GPIO_PIN_4, fanGetPowerState(1));
|
|
|
|
|
|
// m_fan.fanStateMonitor[2].initialize(this, GPIOC, GPIO_PIN_5, fanGetPowerState(2));
|
|
|
|
|
|
// m_fan.fanStateMonitor[3].initialize(this, GPIOC, GPIO_PIN_6, fanGetPowerState(3));
|
|
|
|
|
|
// m_fan.fanStateMonitor[4].initialize(this, GPIOC, GPIO_PIN_7, fanGetPowerState(4));
|
|
|
|
|
|
// m_fan.fanStateMonitor[5].initialize(this, GPIOC, GPIO_PIN_10, fanGetPowerState(5));
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Hardware::fanSetDutyCycle(int fanIndex, uint16_t dutyCycle) { |
|
|
|
|
|
if (fanIndex > 5) { |
|
|
|
|
|
while (1) { |
|
|
|
|
|
ZLOGE(TAG, "fanIndex is out of range!"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (fanIndex <= 3) { |
|
|
|
|
|
STM32_HAL::setPWMDuty(&htim2, TIM_CHANNEL_2, dutyCycle); |
|
|
|
|
|
|
|
|
|
|
|
m_fan.fan0_3duty = dutyCycle; |
|
|
|
|
|
|
|
|
|
|
|
m_fan.m_fanState[0] = dutyCycle > 0; |
|
|
|
|
|
m_fan.m_fanState[1] = dutyCycle > 0; |
|
|
|
|
|
m_fan.m_fanState[2] = dutyCycle > 0; |
|
|
|
|
|
m_fan.m_fanState[3] = dutyCycle > 0; |
|
|
|
|
|
|
|
|
|
|
|
if (dutyCycle > 0) { |
|
|
|
|
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_SET); |
|
|
|
|
|
} else { |
|
|
|
|
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_RESET); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else if (fanIndex == 4) { |
|
|
|
|
|
STM32_HAL::setPWMDuty(&htim4, TIM_CHANNEL_3, dutyCycle); |
|
|
|
|
|
m_fan.m_fanState[4] = dutyCycle > 0; |
|
|
|
|
|
|
|
|
|
|
|
if (dutyCycle > 0) { |
|
|
|
|
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, GPIO_PIN_SET); |
|
|
|
|
|
} else { |
|
|
|
|
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, GPIO_PIN_RESET); |
|
|
|
|
|
} |
|
|
|
|
|
} else if (fanIndex == 5) { |
|
|
|
|
|
STM32_HAL::setPWMDuty(&htim8, TIM_CHANNEL_3, dutyCycle); |
|
|
|
|
|
m_fan.m_fanState[5] = dutyCycle > 0; |
|
|
|
|
|
|
|
|
|
|
|
if (dutyCycle > 0) { |
|
|
|
|
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3, GPIO_PIN_SET); |
|
|
|
|
|
} else { |
|
|
|
|
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3, GPIO_PIN_RESET); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
void Hardware::fanSetState0to3(uint16_t dutyCycle) { |
|
|
|
|
|
fanSetDutyCycle(0, dutyCycle); |
|
|
|
|
|
m_fan.fan0_3duty = dutyCycle; |
|
|
|
|
|
} |
|
|
|
|
|
void Hardware::fanSetState4(uint16_t dutyCycle) { |
|
|
|
|
|
fanSetDutyCycle(4, dutyCycle); |
|
|
|
|
|
m_fan.fan4duty = dutyCycle; |
|
|
|
|
|
} |
|
|
|
|
|
void Hardware::fanSetState5(uint16_t dutyCycle) { |
|
|
|
|
|
fanSetDutyCycle(5, dutyCycle); |
|
|
|
|
|
m_fan.fan5duty = dutyCycle; |
|
|
|
|
|
} |
|
|
|
|
|
uint16_t Hardware::fanReadState0to3() { return m_fan.fan0_3duty; } |
|
|
|
|
|
uint16_t Hardware::fanReadState4() { return m_fan.fan4duty; } |
|
|
|
|
|
uint16_t Hardware::fanReadState5() { return m_fan.fan5duty; } |
|
|
|
|
|
bool *Hardware::fanGetPowerState(int fanIndex) { |
|
|
|
|
|
if (fanIndex > 5) { |
|
|
|
|
|
while (1) { |
|
|
|
|
|
ZLOGE(TAG, "fanIndex is out of range!"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return &m_fan.m_fanState[fanIndex]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Hardware::fan_periodicJob() { |
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 风扇状态监控服务周期调度 |
|
|
|
|
|
*/ |
|
|
|
|
|
// for (size_t i = 0; i < ZARRAY_SIZE(m_fan.fanStateMonitor); i++) {
|
|
|
|
|
|
// m_fan.fanStateMonitor[i].periodicJob();
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 风扇测试 |
|
|
|
|
|
*/ |
|
|
|
|
|
if (testHardwareFlag) { |
|
|
|
|
|
static uint32_t lastcall; |
|
|
|
|
|
static int duty = 0; |
|
|
|
|
|
if (hasPassedMS(lastcall) > 1000) { |
|
|
|
|
|
lastcall = getTicket(); |
|
|
|
|
|
duty += 10; |
|
|
|
|
|
if (duty > 100) duty = 0; |
|
|
|
|
|
fanSetState0to3(duty); |
|
|
|
|
|
fanSetState4(duty); |
|
|
|
|
|
fanSetState5(duty); |
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief DUYT大于零 FANPowerState为1 |
|
|
|
|
|
*/ |
|
|
|
|
|
ZLOGI(TAG, "Duty:%d,FANState:%d,%d,%d,%d,%d,%d", duty, *fanGetPowerState(0), //
|
|
|
|
|
|
*fanGetPowerState(1), //
|
|
|
|
|
|
*fanGetPowerState(2), //
|
|
|
|
|
|
*fanGetPowerState(3), //
|
|
|
|
|
|
*fanGetPowerState(4), //
|
|
|
|
|
|
*fanGetPowerState(5)); //
|
|
|
|
|
|
|
|
|
|
|
|
// ZLOGI(TAG, "FANCount:%d,%d,%d,%d,%d,%d", m_fan.fanStateMonitor[0].getCount(), //
|
|
|
|
|
|
// m_fan.fanStateMonitor[1].getCount(), //
|
|
|
|
|
|
// m_fan.fanStateMonitor[2].getCount(), //
|
|
|
|
|
|
// m_fan.fanStateMonitor[3].getCount(), //
|
|
|
|
|
|
// m_fan.fanStateMonitor[4].getCount(), //
|
|
|
|
|
|
// m_fan.fanStateMonitor[5].getCount());
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
* 帕尔贴 * |
|
|
* 帕尔贴 * |
|
|
*******************************************************************************/ |
|
|
*******************************************************************************/ |
|
|
void Hardware::peltier_cold_ctr_pwm(int pwm) { STM32_HAL::setPWMDuty(&htim1, TIM_CHANNEL_1, pwm); } |
|
|
void Hardware::peltier_cold_ctr_pwm(int pwm) { STM32_HAL::setPWMDuty(&htim1, TIM_CHANNEL_1, pwm); } |
|
|