Marlin/Marlin/src/HAL/HC32/timers.cpp
Scott Lahteine 1c6b723ee6 🧑‍💻 Timer general cleanup
erps
2025-11-14 13:45:55 -06:00

54 lines
1.8 KiB
C++

/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#ifdef ARDUINO_ARCH_HC32
#include "timers.h"
#include <core_debug.h>
/**
* Timer0 Unit 2 Channel A is used for Temperature interrupts
*/
Timer0 temp_timer(&TIMER02A_config, &Temp_Handler);
/**
* Timer0 Unit 2 Channel B is used for Step interrupts
*/
Timer0 step_timer(&TIMER02B_config, &Step_Handler);
void HAL_timer_start(const timer_channel_t timer_ch, const uint32_t frequency) {
if (timer_ch == MF_TIMER_TEMP) {
CORE_DEBUG_PRINTF("HAL_timer_start: temp timer, f=%ld\n", long(frequency));
timer_ch->start(frequency, TEMP_TIMER_PRESCALE);
timer_ch->setCallbackPriority(TEMP_TIMER_PRIORITY);
}
else if (timer_ch == MF_TIMER_STEP) {
CORE_DEBUG_PRINTF("HAL_timer_start: step timer, f=%ld\n", long(frequency));
timer_ch->start(frequency, STEPPER_TIMER_PRESCALE);
timer_ch->setCallbackPriority(STEP_TIMER_PRIORITY);
}
else {
CORE_ASSERT_FAIL("HAL_timer_start: invalid timer_ch")
}
}
#endif // ARDUINO_ARCH_HC32