|
|
|
@@ -38,44 +38,48 @@ extern Timer0 step_timer;
|
|
|
|
|
// Timer Configurations
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
// TODO: some calculations (step irq min_step_rate) require the timer rate to be known at compile time
|
|
|
|
|
// this is not possible with the HC32F460, as the timer rate depends on PCLK1
|
|
|
|
|
// as a workaround, PCLK1 = 50MHz is assumed (check with clock dump in MarlinHAL::init())
|
|
|
|
|
#define HAL_TIMER_RATE 50000000 // 50MHz
|
|
|
|
|
// #define HAL_TIMER_RATE TIMER0_BASE_FREQUENCY
|
|
|
|
|
|
|
|
|
|
// TODO: CYCLES_PER_MICROSECOND seems to be used by Marlin to calculate the number of cycles per microsecond in the timer ISRs
|
|
|
|
|
// by default, it uses F_CPU, but since that is not known at compile time for HC32, we overwrite it here
|
|
|
|
|
#undef CYCLES_PER_MICROSECOND
|
|
|
|
|
#define CYCLES_PER_MICROSECOND (HAL_TIMER_RATE / 1000000UL)
|
|
|
|
|
/**
|
|
|
|
|
* HAL_TIMER_RATE must be known at compile time since it's used to calculate
|
|
|
|
|
* STEPPER_TIMER_RATE, which is used in 'constexpr' calculations.
|
|
|
|
|
* On the HC32F460 the timer rate depends on PCLK1, which is derived from the
|
|
|
|
|
* system clock configured at runtime. As a workaround, we use the existing
|
|
|
|
|
* assumption of a 200MHz clock, defining F_CPU as 200000000, then configure PCLK1
|
|
|
|
|
* as F_CPU with a divider of 4 in 'sysclock.cpp::core_hook_sysclock_init'.
|
|
|
|
|
*
|
|
|
|
|
* If you face issues with this assumption, please double-check with the values
|
|
|
|
|
* printed by 'MarlinHAL::HAL_clock_frequencies_dump'.
|
|
|
|
|
*
|
|
|
|
|
* TODO: If the 'constexpr' requirement is ever lifted, use TIMER0_BASE_FREQUENCY instead
|
|
|
|
|
*/
|
|
|
|
|
#define HAL_TIMER_RATE (F_CPU / 4) // i.e., 50MHz
|
|
|
|
|
//#define HAL_TIMER_RATE TIMER0_BASE_FREQUENCY
|
|
|
|
|
|
|
|
|
|
// Temperature timer
|
|
|
|
|
#define TEMP_TIMER_NUM (&temp_timer)
|
|
|
|
|
#define TEMP_TIMER_PRIORITY DDL_IRQ_PRIORITY_02
|
|
|
|
|
#define TEMP_TIMER_PRESCALE 16ul
|
|
|
|
|
#define TEMP_TIMER_RATE 1000 // 1kHz
|
|
|
|
|
#define TEMP_TIMER_FREQUENCY TEMP_TIMER_RATE // Alias for Marlin
|
|
|
|
|
#define TEMP_TIMER_NUM (&temp_timer)
|
|
|
|
|
#define TEMP_TIMER_PRIORITY DDL_IRQ_PRIORITY_02
|
|
|
|
|
#define TEMP_TIMER_PRESCALE 16UL // 12.5MHz
|
|
|
|
|
#define TEMP_TIMER_RATE 1000 // 1kHz
|
|
|
|
|
#define TEMP_TIMER_FREQUENCY TEMP_TIMER_RATE // 1kHz also
|
|
|
|
|
|
|
|
|
|
// Stepper timer
|
|
|
|
|
#define STEP_TIMER_NUM (&step_timer)
|
|
|
|
|
#define STEP_TIMER_PRIORITY DDL_IRQ_PRIORITY_01
|
|
|
|
|
#define STEPPER_TIMER_PRESCALE 16ul
|
|
|
|
|
#define STEP_TIMER_NUM (&step_timer)
|
|
|
|
|
#define STEP_TIMER_PRIORITY DDL_IRQ_PRIORITY_00 // Top priority, nothing else uses it
|
|
|
|
|
#define STEPPER_TIMER_PRESCALE 16UL // 12.5MHz
|
|
|
|
|
|
|
|
|
|
// TODO: STEPPER_TIMER_RATE seems to work fine like this, but requires further testing...
|
|
|
|
|
#define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // 50MHz / 16 = 3.125MHz
|
|
|
|
|
#define STEPPER_TIMER_TICKS_PER_US (STEPPER_TIMER_RATE / 1000000)
|
|
|
|
|
#define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // 50MHz / 16 = 3.125MHz
|
|
|
|
|
#define STEPPER_TIMER_TICKS_PER_US (STEPPER_TIMER_RATE / 1000000UL) // Integer 3
|
|
|
|
|
|
|
|
|
|
// Pulse timer (== stepper timer)
|
|
|
|
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
|
|
|
|
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
|
|
|
|
|
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
|
|
|
|
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
|
|
|
|
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
|
|
|
|
|
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Channel aliases
|
|
|
|
|
//
|
|
|
|
|
#define MF_TIMER_TEMP TEMP_TIMER_NUM
|
|
|
|
|
#define MF_TIMER_STEP STEP_TIMER_NUM
|
|
|
|
|
#define MF_TIMER_PULSE PULSE_TIMER_NUM
|
|
|
|
|
#define MF_TIMER_TEMP TEMP_TIMER_NUM
|
|
|
|
|
#define MF_TIMER_STEP STEP_TIMER_NUM
|
|
|
|
|
#define MF_TIMER_PULSE PULSE_TIMER_NUM
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// HAL functions
|
|
|
|
|