2022-11-18 13:02:37 +08:00
|
|
|
// TACH interrupt handler
|
2024-09-20 10:20:13 +08:00
|
|
|
static void EXTI2_IRQ_Handler(void) {
|
2022-11-18 13:02:37 +08:00
|
|
|
volatile unsigned int pr = EXTI->PR1 & (1U << 2);
|
|
|
|
if ((pr & (1U << 2)) != 0U) {
|
|
|
|
fan_state.tach_counter++;
|
|
|
|
}
|
|
|
|
EXTI->PR1 = (1U << 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void llfan_init(void) {
|
2024-08-19 08:43:27 +08:00
|
|
|
// 12000RPM * 4 tach edges / 60 seconds
|
|
|
|
REGISTER_INTERRUPT(EXTI2_IRQn, EXTI2_IRQ_Handler, 1000U, FAULT_INTERRUPT_RATE_TACH)
|
2022-11-18 13:02:37 +08:00
|
|
|
|
|
|
|
// Init PWM speed control
|
|
|
|
pwm_init(TIM3, 3);
|
|
|
|
|
|
|
|
// Init TACH interrupt
|
|
|
|
register_set(&(SYSCFG->EXTICR[0]), SYSCFG_EXTICR1_EXTI2_PD, 0xF00U);
|
|
|
|
register_set_bits(&(EXTI->IMR1), (1U << 2));
|
|
|
|
register_set_bits(&(EXTI->RTSR1), (1U << 2));
|
|
|
|
register_set_bits(&(EXTI->FTSR1), (1U << 2));
|
|
|
|
NVIC_EnableIRQ(EXTI2_IRQn);
|
|
|
|
}
|