|
|
|
@ -51,7 +51,6 @@ typedef uint16_t hal_timer_t;
|
|
|
|
|
#define TEMP_TIMER_NUM 2 // index of timer to use for temperature
|
|
|
|
|
#define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define HAL_TIMER_RATE (F_CPU) // frequency of timers peripherals
|
|
|
|
|
#define STEPPER_TIMER_PRESCALE 36 // prescaler for setting stepper timer, 2Mhz
|
|
|
|
|
#define HAL_STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
|
|
|
|
@ -60,11 +59,11 @@ typedef uint16_t hal_timer_t;
|
|
|
|
|
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
|
|
|
|
|
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
|
|
|
|
|
|
|
|
|
#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt (STEP_TIMER_NUM)
|
|
|
|
|
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt (STEP_TIMER_NUM)
|
|
|
|
|
#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
|
|
|
|
|
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
|
|
|
|
|
|
|
|
|
|
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt (TEMP_TIMER_NUM)
|
|
|
|
|
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt (TEMP_TIMER_NUM)
|
|
|
|
|
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
|
|
|
|
|
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
|
|
|
|
|
|
|
|
|
|
#define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
|
|
|
|
|
// TODO change this
|
|
|
|
@ -92,7 +91,7 @@ static HardwareTimer TempTimer(TEMP_TIMER_NUM);
|
|
|
|
|
// Public functions
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void HAL_timer_start (uint8_t timer_num, uint32_t frequency);
|
|
|
|
|
void HAL_timer_start(uint8_t timer_num, uint32_t frequency);
|
|
|
|
|
void HAL_timer_enable_interrupt(uint8_t timer_num);
|
|
|
|
|
void HAL_timer_disable_interrupt(uint8_t timer_num);
|
|
|
|
|
|
|
|
|
@ -107,26 +106,26 @@ void HAL_timer_disable_interrupt(uint8_t timer_num);
|
|
|
|
|
* Todo: Look at that possibility later.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
FORCE_INLINE static void HAL_timer_set_count (uint8_t timer_num, uint32_t count) {
|
|
|
|
|
FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
|
|
|
|
|
switch (timer_num) {
|
|
|
|
|
case STEP_TIMER_NUM:
|
|
|
|
|
StepperTimer.pause();
|
|
|
|
|
StepperTimer.setCompare (STEP_TIMER_CHAN, count);
|
|
|
|
|
StepperTimer.refresh ();
|
|
|
|
|
StepperTimer.resume ();
|
|
|
|
|
StepperTimer.setCompare(STEP_TIMER_CHAN, count);
|
|
|
|
|
StepperTimer.refresh();
|
|
|
|
|
StepperTimer.resume();
|
|
|
|
|
break;
|
|
|
|
|
case TEMP_TIMER_NUM:
|
|
|
|
|
TempTimer.pause();
|
|
|
|
|
TempTimer.setCompare (TEMP_TIMER_CHAN, count);
|
|
|
|
|
TempTimer.refresh ();
|
|
|
|
|
TempTimer.resume ();
|
|
|
|
|
TempTimer.setCompare(TEMP_TIMER_CHAN, count);
|
|
|
|
|
TempTimer.refresh();
|
|
|
|
|
TempTimer.resume();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FORCE_INLINE static hal_timer_t HAL_timer_get_count (uint8_t timer_num) {
|
|
|
|
|
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
|
|
|
|
hal_timer_t temp;
|
|
|
|
|
switch (timer_num) {
|
|
|
|
|
case STEP_TIMER_NUM:
|
|
|
|
@ -142,7 +141,7 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count (uint8_t timer_num) {
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(uint8_t timer_num) {
|
|
|
|
|
FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
|
|
|
|
|
hal_timer_t temp;
|
|
|
|
|
switch (timer_num) {
|
|
|
|
|
case STEP_TIMER_NUM:
|
|
|
|
@ -159,9 +158,9 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(uint8_t timer_num) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//void HAL_timer_isr_prologue (uint8_t timer_num);
|
|
|
|
|
//void HAL_timer_isr_prologue (const uint8_t timer_num);
|
|
|
|
|
|
|
|
|
|
FORCE_INLINE static void HAL_timer_isr_prologue(uint8_t timer_num) {
|
|
|
|
|
FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
|
|
|
|
|
switch (timer_num) {
|
|
|
|
|
case STEP_TIMER_NUM:
|
|
|
|
|
StepperTimer.pause();
|
|
|
|
|