Allow pins override of *_TIMER_NUM and HAL_*_TIMER_ISR (#18128)
Co-authored-by: Scott Lahteine <github@thinkyhead.com>
This commit is contained in:
parent
2bf63e29c6
commit
33d1e77e2e
43 changed files with 461 additions and 338 deletions
|
@ -68,9 +68,6 @@
|
||||||
// Types
|
// Types
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
|
||||||
typedef uint16_t hal_timer_t;
|
|
||||||
#define HAL_TIMER_TYPE_MAX 0xFFFF
|
|
||||||
|
|
||||||
typedef int8_t pin_t;
|
typedef int8_t pin_t;
|
||||||
|
|
||||||
#define SHARED_SERVOS HAS_SERVOS
|
#define SHARED_SERVOS HAS_SERVOS
|
||||||
|
@ -143,220 +140,6 @@ extern "C" {
|
||||||
}
|
}
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
// timers
|
|
||||||
#define HAL_TIMER_RATE ((F_CPU) / 8) // i.e., 2MHz or 2.5MHz
|
|
||||||
|
|
||||||
#define STEP_TIMER_NUM 1
|
|
||||||
#define TEMP_TIMER_NUM 0
|
|
||||||
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
|
||||||
|
|
||||||
#define TEMP_TIMER_FREQUENCY ((F_CPU) / 64.0 / 256.0)
|
|
||||||
|
|
||||||
#define STEPPER_TIMER_RATE HAL_TIMER_RATE
|
|
||||||
#define STEPPER_TIMER_PRESCALE 8
|
|
||||||
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
|
|
||||||
|
|
||||||
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
|
|
||||||
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
|
|
||||||
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
|
|
||||||
|
|
||||||
#define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A)
|
|
||||||
#define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
|
|
||||||
#define STEPPER_ISR_ENABLED() TEST(TIMSK1, OCIE1A)
|
|
||||||
|
|
||||||
#define ENABLE_TEMPERATURE_INTERRUPT() SBI(TIMSK0, OCIE0B)
|
|
||||||
#define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
|
|
||||||
#define TEMPERATURE_ISR_ENABLED() TEST(TIMSK0, OCIE0B)
|
|
||||||
|
|
||||||
FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t) {
|
|
||||||
switch (timer_num) {
|
|
||||||
case STEP_TIMER_NUM:
|
|
||||||
// waveform generation = 0100 = CTC
|
|
||||||
SET_WGM(1, CTC_OCRnA);
|
|
||||||
|
|
||||||
// output mode = 00 (disconnected)
|
|
||||||
SET_COMA(1, NORMAL);
|
|
||||||
|
|
||||||
// Set the timer pre-scaler
|
|
||||||
// Generally we use a divider of 8, resulting in a 2MHz timer
|
|
||||||
// frequency on a 16MHz MCU. If you are going to change this, be
|
|
||||||
// sure to regenerate speed_lookuptable.h with
|
|
||||||
// create_speed_lookuptable.py
|
|
||||||
SET_CS(1, PRESCALER_8); // CS 2 = 1/8 prescaler
|
|
||||||
|
|
||||||
// Init Stepper ISR to 122 Hz for quick starting
|
|
||||||
// (F_CPU) / (STEPPER_TIMER_PRESCALE) / frequency
|
|
||||||
OCR1A = 0x4000;
|
|
||||||
TCNT1 = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TEMP_TIMER_NUM:
|
|
||||||
// Use timer0 for temperature measurement
|
|
||||||
// Interleave temperature interrupt with millies interrupt
|
|
||||||
OCR0B = 128;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TIMER_OCR_1 OCR1A
|
|
||||||
#define TIMER_COUNTER_1 TCNT1
|
|
||||||
|
|
||||||
#define TIMER_OCR_0 OCR0A
|
|
||||||
#define TIMER_COUNTER_0 TCNT0
|
|
||||||
|
|
||||||
#define _CAT(a,V...) a##V
|
|
||||||
#define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
|
|
||||||
#define HAL_timer_get_compare(timer) _CAT(TIMER_OCR_, timer)
|
|
||||||
#define HAL_timer_get_count(timer) _CAT(TIMER_COUNTER_, timer)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* On AVR there is no hardware prioritization and preemption of
|
|
||||||
* interrupts, so this emulates it. The UART has first priority
|
|
||||||
* (otherwise, characters will be lost due to UART overflow).
|
|
||||||
* Then: Stepper, Endstops, Temperature, and -finally- all others.
|
|
||||||
*/
|
|
||||||
#define HAL_timer_isr_prologue(TIMER_NUM)
|
|
||||||
#define HAL_timer_isr_epilogue(TIMER_NUM)
|
|
||||||
|
|
||||||
/* 18 cycles maximum latency */
|
|
||||||
#define HAL_STEP_TIMER_ISR() \
|
|
||||||
extern "C" void TIMER1_COMPA_vect() __attribute__ ((signal, naked, used, externally_visible)); \
|
|
||||||
extern "C" void TIMER1_COMPA_vect_bottom() asm ("TIMER1_COMPA_vect_bottom") __attribute__ ((used, externally_visible, noinline)); \
|
|
||||||
void TIMER1_COMPA_vect() { \
|
|
||||||
__asm__ __volatile__ ( \
|
|
||||||
A("push r16") /* 2 Save R16 */ \
|
|
||||||
A("in r16, __SREG__") /* 1 Get SREG */ \
|
|
||||||
A("push r16") /* 2 Save SREG into stack */ \
|
|
||||||
A("lds r16, %[timsk0]") /* 2 Load into R0 the Temperature timer Interrupt mask register */ \
|
|
||||||
A("push r16") /* 2 Save TIMSK0 into the stack */ \
|
|
||||||
A("andi r16,~%[msk0]") /* 1 Disable the temperature ISR */ \
|
|
||||||
A("sts %[timsk0], r16") /* 2 And set the new value */ \
|
|
||||||
A("lds r16, %[timsk1]") /* 2 Load into R0 the stepper timer Interrupt mask register [TIMSK1] */ \
|
|
||||||
A("andi r16,~%[msk1]") /* 1 Disable the stepper ISR */ \
|
|
||||||
A("sts %[timsk1], r16") /* 2 And set the new value */ \
|
|
||||||
A("push r16") /* 2 Save TIMSK1 into stack */ \
|
|
||||||
A("in r16, 0x3B") /* 1 Get RAMPZ register */ \
|
|
||||||
A("push r16") /* 2 Save RAMPZ into stack */ \
|
|
||||||
A("in r16, 0x3C") /* 1 Get EIND register */ \
|
|
||||||
A("push r0") /* C runtime can modify all the following registers without restoring them */ \
|
|
||||||
A("push r1") \
|
|
||||||
A("push r18") \
|
|
||||||
A("push r19") \
|
|
||||||
A("push r20") \
|
|
||||||
A("push r21") \
|
|
||||||
A("push r22") \
|
|
||||||
A("push r23") \
|
|
||||||
A("push r24") \
|
|
||||||
A("push r25") \
|
|
||||||
A("push r26") \
|
|
||||||
A("push r27") \
|
|
||||||
A("push r30") \
|
|
||||||
A("push r31") \
|
|
||||||
A("clr r1") /* C runtime expects this register to be 0 */ \
|
|
||||||
A("call TIMER1_COMPA_vect_bottom") /* Call the bottom handler - No inlining allowed, otherwise registers used are not saved */ \
|
|
||||||
A("pop r31") \
|
|
||||||
A("pop r30") \
|
|
||||||
A("pop r27") \
|
|
||||||
A("pop r26") \
|
|
||||||
A("pop r25") \
|
|
||||||
A("pop r24") \
|
|
||||||
A("pop r23") \
|
|
||||||
A("pop r22") \
|
|
||||||
A("pop r21") \
|
|
||||||
A("pop r20") \
|
|
||||||
A("pop r19") \
|
|
||||||
A("pop r18") \
|
|
||||||
A("pop r1") \
|
|
||||||
A("pop r0") \
|
|
||||||
A("out 0x3C, r16") /* 1 Restore EIND register */ \
|
|
||||||
A("pop r16") /* 2 Get the original RAMPZ register value */ \
|
|
||||||
A("out 0x3B, r16") /* 1 Restore RAMPZ register to its original value */ \
|
|
||||||
A("pop r16") /* 2 Get the original TIMSK1 value but with stepper ISR disabled */ \
|
|
||||||
A("ori r16,%[msk1]") /* 1 Reenable the stepper ISR */ \
|
|
||||||
A("cli") /* 1 Disable global interrupts - Reenabling Stepper ISR can reenter amd temperature can reenter, and we want that, if it happens, after this ISR has ended */ \
|
|
||||||
A("sts %[timsk1], r16") /* 2 And restore the old value - This reenables the stepper ISR */ \
|
|
||||||
A("pop r16") /* 2 Get the temperature timer Interrupt mask register [TIMSK0] */ \
|
|
||||||
A("sts %[timsk0], r16") /* 2 And restore the old value - This reenables the temperature ISR */ \
|
|
||||||
A("pop r16") /* 2 Get the old SREG value */ \
|
|
||||||
A("out __SREG__, r16") /* 1 And restore the SREG value */ \
|
|
||||||
A("pop r16") /* 2 Restore R16 value */ \
|
|
||||||
A("reti") /* 4 Return from interrupt */ \
|
|
||||||
: \
|
|
||||||
: [timsk0] "i" ((uint16_t)&TIMSK0), \
|
|
||||||
[timsk1] "i" ((uint16_t)&TIMSK1), \
|
|
||||||
[msk0] "M" ((uint8_t)(1<<OCIE0B)),\
|
|
||||||
[msk1] "M" ((uint8_t)(1<<OCIE1A)) \
|
|
||||||
: \
|
|
||||||
); \
|
|
||||||
} \
|
|
||||||
void TIMER1_COMPA_vect_bottom()
|
|
||||||
|
|
||||||
/* 14 cycles maximum latency */
|
|
||||||
#define HAL_TEMP_TIMER_ISR() \
|
|
||||||
extern "C" void TIMER0_COMPB_vect() __attribute__ ((signal, naked, used, externally_visible)); \
|
|
||||||
extern "C" void TIMER0_COMPB_vect_bottom() asm ("TIMER0_COMPB_vect_bottom") __attribute__ ((used, externally_visible, noinline)); \
|
|
||||||
void TIMER0_COMPB_vect() { \
|
|
||||||
__asm__ __volatile__ ( \
|
|
||||||
A("push r16") /* 2 Save R16 */ \
|
|
||||||
A("in r16, __SREG__") /* 1 Get SREG */ \
|
|
||||||
A("push r16") /* 2 Save SREG into stack */ \
|
|
||||||
A("lds r16, %[timsk0]") /* 2 Load into R0 the Temperature timer Interrupt mask register */ \
|
|
||||||
A("andi r16,~%[msk0]") /* 1 Disable the temperature ISR */ \
|
|
||||||
A("sts %[timsk0], r16") /* 2 And set the new value */ \
|
|
||||||
A("sei") /* 1 Enable global interrupts - It is safe, as the temperature ISR is disabled, so we cannot reenter it */ \
|
|
||||||
A("push r16") /* 2 Save TIMSK0 into stack */ \
|
|
||||||
A("in r16, 0x3B") /* 1 Get RAMPZ register */ \
|
|
||||||
A("push r16") /* 2 Save RAMPZ into stack */ \
|
|
||||||
A("in r16, 0x3C") /* 1 Get EIND register */ \
|
|
||||||
A("push r0") /* C runtime can modify all the following registers without restoring them */ \
|
|
||||||
A("push r1") \
|
|
||||||
A("push r18") \
|
|
||||||
A("push r19") \
|
|
||||||
A("push r20") \
|
|
||||||
A("push r21") \
|
|
||||||
A("push r22") \
|
|
||||||
A("push r23") \
|
|
||||||
A("push r24") \
|
|
||||||
A("push r25") \
|
|
||||||
A("push r26") \
|
|
||||||
A("push r27") \
|
|
||||||
A("push r30") \
|
|
||||||
A("push r31") \
|
|
||||||
A("clr r1") /* C runtime expects this register to be 0 */ \
|
|
||||||
A("call TIMER0_COMPB_vect_bottom") /* Call the bottom handler - No inlining allowed, otherwise registers used are not saved */ \
|
|
||||||
A("pop r31") \
|
|
||||||
A("pop r30") \
|
|
||||||
A("pop r27") \
|
|
||||||
A("pop r26") \
|
|
||||||
A("pop r25") \
|
|
||||||
A("pop r24") \
|
|
||||||
A("pop r23") \
|
|
||||||
A("pop r22") \
|
|
||||||
A("pop r21") \
|
|
||||||
A("pop r20") \
|
|
||||||
A("pop r19") \
|
|
||||||
A("pop r18") \
|
|
||||||
A("pop r1") \
|
|
||||||
A("pop r0") \
|
|
||||||
A("out 0x3C, r16") /* 1 Restore EIND register */ \
|
|
||||||
A("pop r16") /* 2 Get the original RAMPZ register value */ \
|
|
||||||
A("out 0x3B, r16") /* 1 Restore RAMPZ register to its original value */ \
|
|
||||||
A("pop r16") /* 2 Get the original TIMSK0 value but with temperature ISR disabled */ \
|
|
||||||
A("ori r16,%[msk0]") /* 1 Enable temperature ISR */ \
|
|
||||||
A("cli") /* 1 Disable global interrupts - We must do this, as we will reenable the temperature ISR, and we don't want to reenter this handler until the current one is done */ \
|
|
||||||
A("sts %[timsk0], r16") /* 2 And restore the old value */ \
|
|
||||||
A("pop r16") /* 2 Get the old SREG */ \
|
|
||||||
A("out __SREG__, r16") /* 1 And restore the SREG value */ \
|
|
||||||
A("pop r16") /* 2 Restore R16 */ \
|
|
||||||
A("reti") /* 4 Return from interrupt */ \
|
|
||||||
: \
|
|
||||||
: [timsk0] "i"((uint16_t)&TIMSK0), \
|
|
||||||
[msk0] "M" ((uint8_t)(1<<OCIE0B)) \
|
|
||||||
: \
|
|
||||||
); \
|
|
||||||
} \
|
|
||||||
void TIMER0_COMPB_vect_bottom()
|
|
||||||
|
|
||||||
// ADC
|
// ADC
|
||||||
#ifdef DIDR2
|
#ifdef DIDR2
|
||||||
#define HAL_ANALOG_SELECT(ind) do{ if (ind < 8) SBI(DIDR0, ind); else SBI(DIDR2, ind & 0x07); }while(0)
|
#define HAL_ANALOG_SELECT(ind) do{ if (ind < 8) SBI(DIDR0, ind); else SBI(DIDR2, ind & 0x07); }while(0)
|
||||||
|
|
259
Marlin/src/HAL/AVR/timers.h
Normal file
259
Marlin/src/HAL/AVR/timers.h
Normal file
|
@ -0,0 +1,259 @@
|
||||||
|
/**
|
||||||
|
* Marlin 3D Printer Firmware
|
||||||
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||||
|
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// ------------------------
|
||||||
|
// Types
|
||||||
|
// ------------------------
|
||||||
|
|
||||||
|
typedef uint16_t hal_timer_t;
|
||||||
|
#define HAL_TIMER_TYPE_MAX 0xFFFF
|
||||||
|
|
||||||
|
// ------------------------
|
||||||
|
// Defines
|
||||||
|
// ------------------------
|
||||||
|
|
||||||
|
#define HAL_TIMER_RATE ((F_CPU) / 8) // i.e., 2MHz or 2.5MHz
|
||||||
|
|
||||||
|
#ifndef STEP_TIMER_NUM
|
||||||
|
#define STEP_TIMER_NUM 1
|
||||||
|
#endif
|
||||||
|
#ifndef PULSE_TIMER_NUM
|
||||||
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||||
|
#endif
|
||||||
|
#ifndef TEMP_TIMER_NUM
|
||||||
|
#define TEMP_TIMER_NUM 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TEMP_TIMER_FREQUENCY ((F_CPU) / 64.0 / 256.0)
|
||||||
|
|
||||||
|
#define STEPPER_TIMER_RATE HAL_TIMER_RATE
|
||||||
|
#define STEPPER_TIMER_PRESCALE 8
|
||||||
|
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
|
||||||
|
|
||||||
|
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
|
||||||
|
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
|
||||||
|
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
|
||||||
|
|
||||||
|
#define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A)
|
||||||
|
#define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
|
||||||
|
#define STEPPER_ISR_ENABLED() TEST(TIMSK1, OCIE1A)
|
||||||
|
|
||||||
|
#define ENABLE_TEMPERATURE_INTERRUPT() SBI(TIMSK0, OCIE0B)
|
||||||
|
#define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
|
||||||
|
#define TEMPERATURE_ISR_ENABLED() TEST(TIMSK0, OCIE0B)
|
||||||
|
|
||||||
|
FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t) {
|
||||||
|
switch (timer_num) {
|
||||||
|
case STEP_TIMER_NUM:
|
||||||
|
// waveform generation = 0100 = CTC
|
||||||
|
SET_WGM(1, CTC_OCRnA);
|
||||||
|
|
||||||
|
// output mode = 00 (disconnected)
|
||||||
|
SET_COMA(1, NORMAL);
|
||||||
|
|
||||||
|
// Set the timer pre-scaler
|
||||||
|
// Generally we use a divider of 8, resulting in a 2MHz timer
|
||||||
|
// frequency on a 16MHz MCU. If you are going to change this, be
|
||||||
|
// sure to regenerate speed_lookuptable.h with
|
||||||
|
// create_speed_lookuptable.py
|
||||||
|
SET_CS(1, PRESCALER_8); // CS 2 = 1/8 prescaler
|
||||||
|
|
||||||
|
// Init Stepper ISR to 122 Hz for quick starting
|
||||||
|
// (F_CPU) / (STEPPER_TIMER_PRESCALE) / frequency
|
||||||
|
OCR1A = 0x4000;
|
||||||
|
TCNT1 = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TEMP_TIMER_NUM:
|
||||||
|
// Use timer0 for temperature measurement
|
||||||
|
// Interleave temperature interrupt with millies interrupt
|
||||||
|
OCR0B = 128;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TIMER_OCR_1 OCR1A
|
||||||
|
#define TIMER_COUNTER_1 TCNT1
|
||||||
|
|
||||||
|
#define TIMER_OCR_0 OCR0A
|
||||||
|
#define TIMER_COUNTER_0 TCNT0
|
||||||
|
|
||||||
|
#define _CAT(a,V...) a##V
|
||||||
|
#define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
|
||||||
|
#define HAL_timer_get_compare(timer) _CAT(TIMER_OCR_, timer)
|
||||||
|
#define HAL_timer_get_count(timer) _CAT(TIMER_COUNTER_, timer)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On AVR there is no hardware prioritization and preemption of
|
||||||
|
* interrupts, so this emulates it. The UART has first priority
|
||||||
|
* (otherwise, characters will be lost due to UART overflow).
|
||||||
|
* Then: Stepper, Endstops, Temperature, and -finally- all others.
|
||||||
|
*/
|
||||||
|
#define HAL_timer_isr_prologue(TIMER_NUM)
|
||||||
|
#define HAL_timer_isr_epilogue(TIMER_NUM)
|
||||||
|
|
||||||
|
/* 18 cycles maximum latency */
|
||||||
|
#ifndef HAL_STEP_TIMER_ISR
|
||||||
|
|
||||||
|
#define HAL_STEP_TIMER_ISR() \
|
||||||
|
extern "C" void TIMER1_COMPA_vect() __attribute__ ((signal, naked, used, externally_visible)); \
|
||||||
|
extern "C" void TIMER1_COMPA_vect_bottom() asm ("TIMER1_COMPA_vect_bottom") __attribute__ ((used, externally_visible, noinline)); \
|
||||||
|
void TIMER1_COMPA_vect() { \
|
||||||
|
__asm__ __volatile__ ( \
|
||||||
|
A("push r16") /* 2 Save R16 */ \
|
||||||
|
A("in r16, __SREG__") /* 1 Get SREG */ \
|
||||||
|
A("push r16") /* 2 Save SREG into stack */ \
|
||||||
|
A("lds r16, %[timsk0]") /* 2 Load into R0 the Temperature timer Interrupt mask register */ \
|
||||||
|
A("push r16") /* 2 Save TIMSK0 into the stack */ \
|
||||||
|
A("andi r16,~%[msk0]") /* 1 Disable the temperature ISR */ \
|
||||||
|
A("sts %[timsk0], r16") /* 2 And set the new value */ \
|
||||||
|
A("lds r16, %[timsk1]") /* 2 Load into R0 the stepper timer Interrupt mask register [TIMSK1] */ \
|
||||||
|
A("andi r16,~%[msk1]") /* 1 Disable the stepper ISR */ \
|
||||||
|
A("sts %[timsk1], r16") /* 2 And set the new value */ \
|
||||||
|
A("push r16") /* 2 Save TIMSK1 into stack */ \
|
||||||
|
A("in r16, 0x3B") /* 1 Get RAMPZ register */ \
|
||||||
|
A("push r16") /* 2 Save RAMPZ into stack */ \
|
||||||
|
A("in r16, 0x3C") /* 1 Get EIND register */ \
|
||||||
|
A("push r0") /* C runtime can modify all the following registers without restoring them */ \
|
||||||
|
A("push r1") \
|
||||||
|
A("push r18") \
|
||||||
|
A("push r19") \
|
||||||
|
A("push r20") \
|
||||||
|
A("push r21") \
|
||||||
|
A("push r22") \
|
||||||
|
A("push r23") \
|
||||||
|
A("push r24") \
|
||||||
|
A("push r25") \
|
||||||
|
A("push r26") \
|
||||||
|
A("push r27") \
|
||||||
|
A("push r30") \
|
||||||
|
A("push r31") \
|
||||||
|
A("clr r1") /* C runtime expects this register to be 0 */ \
|
||||||
|
A("call TIMER1_COMPA_vect_bottom") /* Call the bottom handler - No inlining allowed, otherwise registers used are not saved */ \
|
||||||
|
A("pop r31") \
|
||||||
|
A("pop r30") \
|
||||||
|
A("pop r27") \
|
||||||
|
A("pop r26") \
|
||||||
|
A("pop r25") \
|
||||||
|
A("pop r24") \
|
||||||
|
A("pop r23") \
|
||||||
|
A("pop r22") \
|
||||||
|
A("pop r21") \
|
||||||
|
A("pop r20") \
|
||||||
|
A("pop r19") \
|
||||||
|
A("pop r18") \
|
||||||
|
A("pop r1") \
|
||||||
|
A("pop r0") \
|
||||||
|
A("out 0x3C, r16") /* 1 Restore EIND register */ \
|
||||||
|
A("pop r16") /* 2 Get the original RAMPZ register value */ \
|
||||||
|
A("out 0x3B, r16") /* 1 Restore RAMPZ register to its original value */ \
|
||||||
|
A("pop r16") /* 2 Get the original TIMSK1 value but with stepper ISR disabled */ \
|
||||||
|
A("ori r16,%[msk1]") /* 1 Reenable the stepper ISR */ \
|
||||||
|
A("cli") /* 1 Disable global interrupts - Reenabling Stepper ISR can reenter amd temperature can reenter, and we want that, if it happens, after this ISR has ended */ \
|
||||||
|
A("sts %[timsk1], r16") /* 2 And restore the old value - This reenables the stepper ISR */ \
|
||||||
|
A("pop r16") /* 2 Get the temperature timer Interrupt mask register [TIMSK0] */ \
|
||||||
|
A("sts %[timsk0], r16") /* 2 And restore the old value - This reenables the temperature ISR */ \
|
||||||
|
A("pop r16") /* 2 Get the old SREG value */ \
|
||||||
|
A("out __SREG__, r16") /* 1 And restore the SREG value */ \
|
||||||
|
A("pop r16") /* 2 Restore R16 value */ \
|
||||||
|
A("reti") /* 4 Return from interrupt */ \
|
||||||
|
: \
|
||||||
|
: [timsk0] "i" ((uint16_t)&TIMSK0), \
|
||||||
|
[timsk1] "i" ((uint16_t)&TIMSK1), \
|
||||||
|
[msk0] "M" ((uint8_t)(1<<OCIE0B)),\
|
||||||
|
[msk1] "M" ((uint8_t)(1<<OCIE1A)) \
|
||||||
|
: \
|
||||||
|
); \
|
||||||
|
} \
|
||||||
|
void TIMER1_COMPA_vect_bottom()
|
||||||
|
|
||||||
|
#endif // HAL_STEP_TIMER_ISR
|
||||||
|
|
||||||
|
#ifndef HAL_TEMP_TIMER_ISR
|
||||||
|
|
||||||
|
/* 14 cycles maximum latency */
|
||||||
|
#define HAL_TEMP_TIMER_ISR() \
|
||||||
|
extern "C" void TIMER0_COMPB_vect() __attribute__ ((signal, naked, used, externally_visible)); \
|
||||||
|
extern "C" void TIMER0_COMPB_vect_bottom() asm ("TIMER0_COMPB_vect_bottom") __attribute__ ((used, externally_visible, noinline)); \
|
||||||
|
void TIMER0_COMPB_vect() { \
|
||||||
|
__asm__ __volatile__ ( \
|
||||||
|
A("push r16") /* 2 Save R16 */ \
|
||||||
|
A("in r16, __SREG__") /* 1 Get SREG */ \
|
||||||
|
A("push r16") /* 2 Save SREG into stack */ \
|
||||||
|
A("lds r16, %[timsk0]") /* 2 Load into R0 the Temperature timer Interrupt mask register */ \
|
||||||
|
A("andi r16,~%[msk0]") /* 1 Disable the temperature ISR */ \
|
||||||
|
A("sts %[timsk0], r16") /* 2 And set the new value */ \
|
||||||
|
A("sei") /* 1 Enable global interrupts - It is safe, as the temperature ISR is disabled, so we cannot reenter it */ \
|
||||||
|
A("push r16") /* 2 Save TIMSK0 into stack */ \
|
||||||
|
A("in r16, 0x3B") /* 1 Get RAMPZ register */ \
|
||||||
|
A("push r16") /* 2 Save RAMPZ into stack */ \
|
||||||
|
A("in r16, 0x3C") /* 1 Get EIND register */ \
|
||||||
|
A("push r0") /* C runtime can modify all the following registers without restoring them */ \
|
||||||
|
A("push r1") \
|
||||||
|
A("push r18") \
|
||||||
|
A("push r19") \
|
||||||
|
A("push r20") \
|
||||||
|
A("push r21") \
|
||||||
|
A("push r22") \
|
||||||
|
A("push r23") \
|
||||||
|
A("push r24") \
|
||||||
|
A("push r25") \
|
||||||
|
A("push r26") \
|
||||||
|
A("push r27") \
|
||||||
|
A("push r30") \
|
||||||
|
A("push r31") \
|
||||||
|
A("clr r1") /* C runtime expects this register to be 0 */ \
|
||||||
|
A("call TIMER0_COMPB_vect_bottom") /* Call the bottom handler - No inlining allowed, otherwise registers used are not saved */ \
|
||||||
|
A("pop r31") \
|
||||||
|
A("pop r30") \
|
||||||
|
A("pop r27") \
|
||||||
|
A("pop r26") \
|
||||||
|
A("pop r25") \
|
||||||
|
A("pop r24") \
|
||||||
|
A("pop r23") \
|
||||||
|
A("pop r22") \
|
||||||
|
A("pop r21") \
|
||||||
|
A("pop r20") \
|
||||||
|
A("pop r19") \
|
||||||
|
A("pop r18") \
|
||||||
|
A("pop r1") \
|
||||||
|
A("pop r0") \
|
||||||
|
A("out 0x3C, r16") /* 1 Restore EIND register */ \
|
||||||
|
A("pop r16") /* 2 Get the original RAMPZ register value */ \
|
||||||
|
A("out 0x3B, r16") /* 1 Restore RAMPZ register to its original value */ \
|
||||||
|
A("pop r16") /* 2 Get the original TIMSK0 value but with temperature ISR disabled */ \
|
||||||
|
A("ori r16,%[msk0]") /* 1 Enable temperature ISR */ \
|
||||||
|
A("cli") /* 1 Disable global interrupts - We must do this, as we will reenable the temperature ISR, and we don't want to reenter this handler until the current one is done */ \
|
||||||
|
A("sts %[timsk0], r16") /* 2 And restore the old value */ \
|
||||||
|
A("pop r16") /* 2 Get the old SREG */ \
|
||||||
|
A("out __SREG__, r16") /* 1 And restore the SREG value */ \
|
||||||
|
A("pop r16") /* 2 Restore R16 */ \
|
||||||
|
A("reti") /* 4 Return from interrupt */ \
|
||||||
|
: \
|
||||||
|
: [timsk0] "i"((uint16_t)&TIMSK0), \
|
||||||
|
[msk0] "M" ((uint8_t)(1<<OCIE0B)) \
|
||||||
|
: \
|
||||||
|
); \
|
||||||
|
} \
|
||||||
|
void TIMER0_COMPB_vect_bottom()
|
||||||
|
|
||||||
|
#endif // HAL_TEMP_TIMER_ISR
|
|
@ -35,7 +35,6 @@
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
#include "watchdog.h"
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
#include "HAL.h"
|
#include "HAL.h"
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
static pin_t tone_pin;
|
static pin_t tone_pin;
|
||||||
volatile static int32_t toggles;
|
volatile static int32_t toggles;
|
||||||
|
|
|
@ -34,8 +34,6 @@
|
||||||
#include "../../inc/MarlinConfig.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
#include "HAL.h"
|
#include "HAL.h"
|
||||||
|
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// Local defines
|
// Local defines
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
|
|
@ -40,11 +40,17 @@ typedef uint32_t hal_timer_t;
|
||||||
#define HAL_TIMER_RATE ((F_CPU) / 2) // frequency of timers peripherals
|
#define HAL_TIMER_RATE ((F_CPU) / 2) // frequency of timers peripherals
|
||||||
|
|
||||||
#ifndef STEP_TIMER_NUM
|
#ifndef STEP_TIMER_NUM
|
||||||
#define STEP_TIMER_NUM 2 // index of timer to use for stepper
|
#define STEP_TIMER_NUM 2 // Timer Index for Stepper
|
||||||
#endif
|
#endif
|
||||||
#define TEMP_TIMER_NUM 4 // index of timer to use for temperature
|
#ifndef PULSE_TIMER_NUM
|
||||||
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||||
|
#endif
|
||||||
|
#ifndef TEMP_TIMER_NUM
|
||||||
|
#define TEMP_TIMER_NUM 4 // Timer Index for Temperature
|
||||||
|
#endif
|
||||||
|
#ifndef TONE_TIMER_NUM
|
||||||
#define TONE_TIMER_NUM 6 // index of timer to use for beeper tones
|
#define TONE_TIMER_NUM 6 // index of timer to use for beeper tones
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
||||||
|
|
||||||
|
@ -66,8 +72,12 @@ typedef uint32_t hal_timer_t;
|
||||||
#ifndef HAL_STEP_TIMER_ISR
|
#ifndef HAL_STEP_TIMER_ISR
|
||||||
#define HAL_STEP_TIMER_ISR() void TC2_Handler()
|
#define HAL_STEP_TIMER_ISR() void TC2_Handler()
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef HAL_TEMP_TIMER_ISR
|
||||||
#define HAL_TEMP_TIMER_ISR() void TC4_Handler()
|
#define HAL_TEMP_TIMER_ISR() void TC4_Handler()
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_TONE_TIMER_ISR
|
||||||
#define HAL_TONE_TIMER_ISR() void TC6_Handler()
|
#define HAL_TONE_TIMER_ISR() void TC6_Handler()
|
||||||
|
#endif
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// Types
|
// Types
|
||||||
|
|
|
@ -21,15 +21,13 @@
|
||||||
*/
|
*/
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
|
|
||||||
#include "HAL.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
#include "timers.h"
|
|
||||||
#include <rom/rtc.h>
|
#include <rom/rtc.h>
|
||||||
#include <driver/adc.h>
|
#include <driver/adc.h>
|
||||||
#include <esp_adc_cal.h>
|
#include <esp_adc_cal.h>
|
||||||
#include <HardwareSerial.h>
|
#include <HardwareSerial.h>
|
||||||
|
|
||||||
#include "../../inc/MarlinConfigPre.h"
|
|
||||||
|
|
||||||
#if ENABLED(WIFISUPPORT)
|
#if ENABLED(WIFISUPPORT)
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
|
|
|
@ -34,8 +34,6 @@
|
||||||
#include "watchdog.h"
|
#include "watchdog.h"
|
||||||
#include "i2s.h"
|
#include "i2s.h"
|
||||||
|
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
#if ENABLED(WIFISUPPORT)
|
#if ENABLED(WIFISUPPORT)
|
||||||
#include "WebSocketSerial.h"
|
#include "WebSocketSerial.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -22,13 +22,12 @@
|
||||||
*/
|
*/
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
|
|
||||||
#include "HAL.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
#include "../shared/HAL_SPI.h"
|
|
||||||
#include <pins_arduino.h>
|
|
||||||
#include "spi_pins.h"
|
|
||||||
#include <SPI.h>
|
|
||||||
|
|
||||||
#include "../../core/macros.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
|
|
||||||
|
#include <pins_arduino.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// Public Variables
|
// Public Variables
|
||||||
|
|
|
@ -27,9 +27,7 @@
|
||||||
#include <driver/periph_ctrl.h>
|
#include <driver/periph_ctrl.h>
|
||||||
#include <driver/timer.h>
|
#include <driver/timer.h>
|
||||||
|
|
||||||
#include "HAL.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
|
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// Local defines
|
// Local defines
|
||||||
|
|
|
@ -38,10 +38,18 @@
|
||||||
typedef uint64_t hal_timer_t;
|
typedef uint64_t hal_timer_t;
|
||||||
#define HAL_TIMER_TYPE_MAX 0xFFFFFFFFFFFFFFFFULL
|
#define HAL_TIMER_TYPE_MAX 0xFFFFFFFFFFFFFFFFULL
|
||||||
|
|
||||||
#define STEP_TIMER_NUM 0 // index of timer to use for stepper
|
#ifndef STEP_TIMER_NUM
|
||||||
#define TEMP_TIMER_NUM 1 // index of timer to use for temperature
|
#define STEP_TIMER_NUM 0 // Timer Index for Stepper
|
||||||
#define PWM_TIMER_NUM 2 // index of timer to use for PWM outputs
|
#endif
|
||||||
|
#ifndef PULSE_TIMER_NUM
|
||||||
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||||
|
#endif
|
||||||
|
#ifndef TEMP_TIMER_NUM
|
||||||
|
#define TEMP_TIMER_NUM 1 // Timer Index for Temperature
|
||||||
|
#endif
|
||||||
|
#ifndef PWM_TIMER_NUM
|
||||||
|
#define PWM_TIMER_NUM 2 // index of timer to use for PWM outputs
|
||||||
|
#endif
|
||||||
|
|
||||||
#define HAL_TIMER_RATE APB_CLK_FREQ // frequency of timer peripherals
|
#define HAL_TIMER_RATE APB_CLK_FREQ // frequency of timer peripherals
|
||||||
|
|
||||||
|
@ -79,9 +87,15 @@ typedef uint64_t hal_timer_t;
|
||||||
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_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 DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
|
||||||
|
|
||||||
|
#ifndef HAL_TEMP_TIMER_ISR
|
||||||
#define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler()
|
#define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler()
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_STEP_TIMER_ISR
|
||||||
#define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler()
|
#define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler()
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_PWM_TIMER_ISR
|
||||||
#define HAL_PWM_TIMER_ISR() extern "C" void pwmTC_Handler()
|
#define HAL_PWM_TIMER_ISR() extern "C" void pwmTC_Handler()
|
||||||
|
#endif
|
||||||
|
|
||||||
extern "C" void tempTC_Handler();
|
extern "C" void tempTC_Handler();
|
||||||
extern "C" void stepTC_Handler();
|
extern "C" void stepTC_Handler();
|
||||||
|
|
|
@ -56,7 +56,6 @@ uint8_t _getc();
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
#include "watchdog.h"
|
||||||
#include "timers.h"
|
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
|
|
||||||
#define SHARED_SERVOS HAS_SERVOS
|
#define SHARED_SERVOS HAS_SERVOS
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#include "hardware/Timer.h"
|
#include "hardware/Timer.h"
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use POSIX signals to attempt to emulate Interrupts
|
* Use POSIX signals to attempt to emulate Interrupts
|
||||||
|
|
|
@ -37,9 +37,15 @@ typedef uint32_t hal_timer_t;
|
||||||
|
|
||||||
#define HAL_TIMER_RATE ((SystemCoreClock) / 4) // frequency of timers peripherals
|
#define HAL_TIMER_RATE ((SystemCoreClock) / 4) // frequency of timers peripherals
|
||||||
|
|
||||||
|
#ifndef STEP_TIMER_NUM
|
||||||
#define STEP_TIMER_NUM 0 // Timer Index for Stepper
|
#define STEP_TIMER_NUM 0 // Timer Index for Stepper
|
||||||
#define TEMP_TIMER_NUM 1 // Timer Index for Temperature
|
#endif
|
||||||
|
#ifndef PULSE_TIMER_NUM
|
||||||
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||||
|
#endif
|
||||||
|
#ifndef TEMP_TIMER_NUM
|
||||||
|
#define TEMP_TIMER_NUM 1 // Timer Index for Temperature
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TEMP_TIMER_RATE 1000000
|
#define TEMP_TIMER_RATE 1000000
|
||||||
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
||||||
|
@ -59,8 +65,12 @@ typedef uint32_t hal_timer_t;
|
||||||
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_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 DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
|
||||||
|
|
||||||
|
#ifndef HAL_STEP_TIMER_ISR
|
||||||
#define HAL_STEP_TIMER_ISR() extern "C" void TIMER0_IRQHandler()
|
#define HAL_STEP_TIMER_ISR() extern "C" void TIMER0_IRQHandler()
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_TEMP_TIMER_ISR
|
||||||
#define HAL_TEMP_TIMER_ISR() extern "C" void TIMER1_IRQHandler()
|
#define HAL_TEMP_TIMER_ISR() extern "C" void TIMER1_IRQHandler()
|
||||||
|
#endif
|
||||||
|
|
||||||
// PWM timer
|
// PWM timer
|
||||||
#define HAL_PWM_TIMER
|
#define HAL_PWM_TIMER
|
||||||
|
|
|
@ -41,7 +41,6 @@ extern "C" volatile uint32_t _millis;
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
#include "watchdog.h"
|
||||||
#include "timers.h"
|
|
||||||
#include "MarlinSerial.h"
|
#include "MarlinSerial.h"
|
||||||
|
|
||||||
#include <adc.h>
|
#include <adc.h>
|
||||||
|
|
|
@ -38,8 +38,6 @@ extern "C" {
|
||||||
#include "../../sd/cardreader.h"
|
#include "../../sd/cardreader.h"
|
||||||
#include "../../inc/MarlinConfig.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
#include "../../core/millis_t.h"
|
#include "../../core/millis_t.h"
|
||||||
#include "HAL.h"
|
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
extern uint32_t MSC_SD_Init(uint8_t pdrv);
|
extern uint32_t MSC_SD_Init(uint8_t pdrv);
|
||||||
extern "C" int isLPC1769();
|
extern "C" int isLPC1769();
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#ifdef TARGET_LPC1768
|
#ifdef TARGET_LPC1768
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
void HAL_timer_init() {
|
void HAL_timer_init() {
|
||||||
SBI(LPC_SC->PCONP, SBIT_TIMER0); // Power ON Timer 0
|
SBI(LPC_SC->PCONP, SBIT_TIMER0); // Power ON Timer 0
|
||||||
|
|
|
@ -61,10 +61,18 @@ typedef uint32_t hal_timer_t;
|
||||||
|
|
||||||
#define HAL_TIMER_RATE ((F_CPU) / 4) // frequency of timers peripherals
|
#define HAL_TIMER_RATE ((F_CPU) / 4) // frequency of timers peripherals
|
||||||
|
|
||||||
|
#ifndef STEP_TIMER_NUM
|
||||||
#define STEP_TIMER_NUM 0 // Timer Index for Stepper
|
#define STEP_TIMER_NUM 0 // Timer Index for Stepper
|
||||||
#define TEMP_TIMER_NUM 1 // Timer Index for Temperature
|
#endif
|
||||||
|
#ifndef PULSE_TIMER_NUM
|
||||||
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||||
|
#endif
|
||||||
|
#ifndef TEMP_TIMER_NUM
|
||||||
|
#define TEMP_TIMER_NUM 1 // Timer Index for Temperature
|
||||||
|
#endif
|
||||||
|
#ifndef PWM_TIMER_NUM
|
||||||
#define PWM_TIMER_NUM 3 // Timer Index for PWM
|
#define PWM_TIMER_NUM 3 // Timer Index for PWM
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TEMP_TIMER_RATE 1000000
|
#define TEMP_TIMER_RATE 1000000
|
||||||
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
||||||
|
@ -84,8 +92,12 @@ typedef uint32_t hal_timer_t;
|
||||||
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_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 DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
|
||||||
|
|
||||||
|
#ifndef HAL_STEP_TIMER_ISR
|
||||||
#define HAL_STEP_TIMER_ISR() _HAL_TIMER_ISR(STEP_TIMER_NUM)
|
#define HAL_STEP_TIMER_ISR() _HAL_TIMER_ISR(STEP_TIMER_NUM)
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_TEMP_TIMER_ISR
|
||||||
#define HAL_TEMP_TIMER_ISR() _HAL_TIMER_ISR(TEMP_TIMER_NUM)
|
#define HAL_TEMP_TIMER_ISR() _HAL_TIMER_ISR(TEMP_TIMER_NUM)
|
||||||
|
#endif
|
||||||
|
|
||||||
// Timer references by index
|
// Timer references by index
|
||||||
#define STEP_TIMER_PTR _HAL_TIMER(STEP_TIMER_NUM)
|
#define STEP_TIMER_PTR _HAL_TIMER(STEP_TIMER_NUM)
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
#include "watchdog.h"
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
#ifdef ADAFRUIT_GRAND_CENTRAL_M4
|
#ifdef ADAFRUIT_GRAND_CENTRAL_M4
|
||||||
#include "MarlinSerial_AGCM4.h"
|
#include "MarlinSerial_AGCM4.h"
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
#include "../shared/servo.h"
|
#include "../shared/servo.h"
|
||||||
#include "../shared/servo_private.h"
|
#include "../shared/servo_private.h"
|
||||||
#include "SAMD51.h"
|
#include "SAMD51.h"
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
#define __TC_GCLK_ID(t) TC##t##_GCLK_ID
|
#define __TC_GCLK_ID(t) TC##t##_GCLK_ID
|
||||||
#define _TC_GCLK_ID(t) __TC_GCLK_ID(t)
|
#define _TC_GCLK_ID(t) __TC_GCLK_ID(t)
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
// Includes
|
// Includes
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
#include "../../inc/MarlinConfig.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// Local defines
|
// Local defines
|
||||||
|
|
|
@ -32,9 +32,15 @@ typedef uint32_t hal_timer_t;
|
||||||
|
|
||||||
#define HAL_TIMER_RATE F_CPU // frequency of timers peripherals
|
#define HAL_TIMER_RATE F_CPU // frequency of timers peripherals
|
||||||
|
|
||||||
#define STEP_TIMER_NUM 0 // index of timer to use for stepper (also +1 for 32bits counter)
|
#ifndef STEP_TIMER_NUM
|
||||||
|
#define STEP_TIMER_NUM 0 // Timer Index for Stepper
|
||||||
|
#endif
|
||||||
|
#ifndef PULSE_TIMER_NUM
|
||||||
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||||
#define TEMP_TIMER_NUM RTC_TIMER_NUM // index of timer to use for temperature
|
#endif
|
||||||
|
#ifndef TEMP_TIMER_NUM
|
||||||
|
#define TEMP_TIMER_NUM RTC_TIMER_NUM // Timer Index for Temperature
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
||||||
|
|
||||||
|
@ -59,7 +65,9 @@ typedef uint32_t hal_timer_t;
|
||||||
|
|
||||||
#define _TC_HANDLER(t) void TC##t##_Handler()
|
#define _TC_HANDLER(t) void TC##t##_Handler()
|
||||||
#define TC_HANDLER(t) _TC_HANDLER(t)
|
#define TC_HANDLER(t) _TC_HANDLER(t)
|
||||||
|
#ifndef HAL_STEP_TIMER_ISR
|
||||||
#define HAL_STEP_TIMER_ISR() TC_HANDLER(STEP_TIMER_NUM)
|
#define HAL_STEP_TIMER_ISR() TC_HANDLER(STEP_TIMER_NUM)
|
||||||
|
#endif
|
||||||
#if STEP_TIMER_NUM != PULSE_TIMER_NUM
|
#if STEP_TIMER_NUM != PULSE_TIMER_NUM
|
||||||
#define HAL_PULSE_TIMER_ISR() TC_HANDLER(PULSE_TIMER_NUM)
|
#define HAL_PULSE_TIMER_ISR() TC_HANDLER(PULSE_TIMER_NUM)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -119,7 +119,6 @@
|
||||||
#define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.availableForWrite
|
#define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.availableForWrite
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: review this to return 1 for pins that are not analog input
|
* TODO: review this to return 1 for pins that are not analog input
|
||||||
|
|
|
@ -36,8 +36,9 @@
|
||||||
//
|
//
|
||||||
#if defined(PLATFORMIO) && defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
|
#if defined(PLATFORMIO) && defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
|
||||||
|
|
||||||
|
#include "../../inc/MarlinConfig.h"
|
||||||
|
|
||||||
#include "SoftwareSerial.h"
|
#include "SoftwareSerial.h"
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
#define OVERSAMPLE 3 // in RX, Timer will generate interruption OVERSAMPLE time during a bit. Thus OVERSAMPLE ticks in a bit. (interrupt not synchonized with edge).
|
#define OVERSAMPLE 3 // in RX, Timer will generate interruption OVERSAMPLE time during a bit. Thus OVERSAMPLE ticks in a bit. (interrupt not synchonized with edge).
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,6 @@
|
||||||
*/
|
*/
|
||||||
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
|
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
|
||||||
|
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
|
|
@ -33,9 +33,15 @@
|
||||||
#define hal_timer_t uint32_t
|
#define hal_timer_t uint32_t
|
||||||
#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF // Timers can be 16 or 32 bit
|
#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF // Timers can be 16 or 32 bit
|
||||||
|
|
||||||
#define STEP_TIMER_NUM 0 // index of timer to use for stepper
|
#ifndef STEP_TIMER_NUM
|
||||||
#define TEMP_TIMER_NUM 1 // index of timer to use for temperature
|
#define STEP_TIMER_NUM 0 // Timer Index for Stepper
|
||||||
|
#endif
|
||||||
|
#ifndef PULSE_TIMER_NUM
|
||||||
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||||
|
#endif
|
||||||
|
#ifndef TEMP_TIMER_NUM
|
||||||
|
#define TEMP_TIMER_NUM 1 // Timer Index for Temperature
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TEMP_TIMER_FREQUENCY 1000 // Temperature::isr() is expected to be called at around 1kHz
|
#define TEMP_TIMER_FREQUENCY 1000 // Temperature::isr() is expected to be called at around 1kHz
|
||||||
|
|
||||||
|
@ -57,8 +63,13 @@
|
||||||
|
|
||||||
extern void Step_Handler(HardwareTimer *htim);
|
extern void Step_Handler(HardwareTimer *htim);
|
||||||
extern void Temp_Handler(HardwareTimer *htim);
|
extern void Temp_Handler(HardwareTimer *htim);
|
||||||
|
|
||||||
|
#ifndef HAL_STEP_TIMER_ISR
|
||||||
#define HAL_STEP_TIMER_ISR() void Step_Handler(HardwareTimer *htim)
|
#define HAL_STEP_TIMER_ISR() void Step_Handler(HardwareTimer *htim)
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_TEMP_TIMER_ISR
|
||||||
#define HAL_TEMP_TIMER_ISR() void Temp_Handler(HardwareTimer *htim)
|
#define HAL_TEMP_TIMER_ISR() void Temp_Handler(HardwareTimer *htim)
|
||||||
|
#endif
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// Public Variables
|
// Public Variables
|
||||||
|
|
|
@ -36,7 +36,6 @@
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
#include "watchdog.h"
|
||||||
|
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <util/atomic.h>
|
#include <util/atomic.h>
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
uint8_t ServoCount = 0;
|
uint8_t ServoCount = 0;
|
||||||
|
|
||||||
#include "Servo.h"
|
#include "Servo.h"
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
//#include "Servo.h"
|
//#include "Servo.h"
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,6 @@
|
||||||
#ifdef __STM32F1__
|
#ifdef __STM32F1__
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
#include "HAL.h"
|
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// Local defines
|
// Local defines
|
||||||
|
|
|
@ -61,14 +61,20 @@ typedef uint16_t hal_timer_t;
|
||||||
* - Otherwise it uses Timer 8 on boards with STM32_HIGH_DENSITY
|
* - Otherwise it uses Timer 8 on boards with STM32_HIGH_DENSITY
|
||||||
* or Timer 4 on other boards.
|
* or Timer 4 on other boards.
|
||||||
*/
|
*/
|
||||||
|
#ifndef STEP_TIMER_NUM
|
||||||
#if defined(MCU_STM32F103CB) || defined(MCU_STM32F103C8)
|
#if defined(MCU_STM32F103CB) || defined(MCU_STM32F103C8)
|
||||||
#define STEP_TIMER_NUM 4 // For C8/CB boards, use timer 4
|
#define STEP_TIMER_NUM 4 // For C8/CB boards, use timer 4
|
||||||
#else
|
#else
|
||||||
#define STEP_TIMER_NUM 5 // for other boards, five is fine.
|
#define STEP_TIMER_NUM 5 // for other boards, five is fine.
|
||||||
#endif
|
#endif
|
||||||
#define TEMP_TIMER_NUM 2 // index of timer to use for temperature
|
#endif
|
||||||
//#define TEMP_TIMER_NUM 4 // 2->4, Timer 2 for Stepper Current PWM
|
#ifndef PULSE_TIMER_NUM
|
||||||
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||||
|
#endif
|
||||||
|
#ifndef TEMP_TIMER_NUM
|
||||||
|
#define TEMP_TIMER_NUM 2 // Timer Index for Temperature
|
||||||
|
//#define TEMP_TIMER_NUM 4 // 2->4, Timer 2 for Stepper Current PWM
|
||||||
|
#endif
|
||||||
|
|
||||||
#if MB(BTT_SKR_MINI_E3_V1_0, BTT_SKR_E3_DIP, BTT_SKR_MINI_E3_V1_2, MKS_ROBIN_LITE)
|
#if MB(BTT_SKR_MINI_E3_V1_0, BTT_SKR_E3_DIP, BTT_SKR_MINI_E3_V1_2, MKS_ROBIN_LITE)
|
||||||
// SKR Mini E3 boards use PA8 as FAN_PIN, so TIMER 1 is used for Fan PWM.
|
// SKR Mini E3 boards use PA8 as FAN_PIN, so TIMER 1 is used for Fan PWM.
|
||||||
|
@ -111,8 +117,12 @@ timer_dev* get_timer_dev(int number);
|
||||||
|
|
||||||
// TODO change this
|
// TODO change this
|
||||||
|
|
||||||
|
#ifndef HAL_TEMP_TIMER_ISR
|
||||||
#define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler()
|
#define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler()
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_STEP_TIMER_ISR
|
||||||
#define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler()
|
#define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler()
|
||||||
|
#endif
|
||||||
|
|
||||||
extern "C" void tempTC_Handler();
|
extern "C" void tempTC_Handler();
|
||||||
extern "C" void stepTC_Handler();
|
extern "C" void stepTC_Handler();
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
|
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "timers.h"
|
|
||||||
#include "watchdog.h"
|
#include "watchdog.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
|
@ -21,8 +21,7 @@
|
||||||
*/
|
*/
|
||||||
#if defined(STM32GENERIC) && defined(STM32F4)
|
#if defined(STM32GENERIC) && defined(STM32F4)
|
||||||
|
|
||||||
#include "../HAL.h"
|
#include "../../../inc/MarlinConfig.h"
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// Local defines
|
// Local defines
|
||||||
|
|
|
@ -34,9 +34,15 @@
|
||||||
|
|
||||||
#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq() / 2) // frequency of timer peripherals
|
#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq() / 2) // frequency of timer peripherals
|
||||||
|
|
||||||
#define STEP_TIMER_NUM 0 // index of timer to use for stepper
|
#ifndef STEP_TIMER_NUM
|
||||||
#define TEMP_TIMER_NUM 1 // index of timer to use for temperature
|
#define STEP_TIMER_NUM 0 // Timer Index for Stepper
|
||||||
|
#endif
|
||||||
|
#ifndef PULSE_TIMER_NUM
|
||||||
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||||
|
#endif
|
||||||
|
#ifndef TEMP_TIMER_NUM
|
||||||
|
#define TEMP_TIMER_NUM 1 // Timer Index for Temperature
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
|
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
|
||||||
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
||||||
|
@ -59,17 +65,19 @@
|
||||||
// TODO change this
|
// TODO change this
|
||||||
|
|
||||||
#ifdef STM32GENERIC
|
#ifdef STM32GENERIC
|
||||||
extern void TC5_Handler();
|
#define TC_TIMER_ARGS
|
||||||
extern void TC7_Handler();
|
|
||||||
#define HAL_STEP_TIMER_ISR() void TC5_Handler()
|
|
||||||
#define HAL_TEMP_TIMER_ISR() void TC7_Handler()
|
|
||||||
#else
|
#else
|
||||||
extern void TC5_Handler(stimer_t *htim);
|
#define TC_TIMER_ARGS stimer_t *htim
|
||||||
extern void TC7_Handler(stimer_t *htim);
|
|
||||||
#define HAL_STEP_TIMER_ISR() void TC5_Handler(stimer_t *htim)
|
|
||||||
#define HAL_TEMP_TIMER_ISR() void TC7_Handler(stimer_t *htim)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern void TC5_Handler(TC_TIMER_ARGS);
|
||||||
|
extern void TC7_Handler(TC_TIMER_ARGS);
|
||||||
|
#ifndef HAL_STEP_TIMER_ISR
|
||||||
|
#define HAL_STEP_TIMER_ISR() void TC5_Handler(TC_TIMER_ARGS)
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_TEMP_TIMER_ISR
|
||||||
|
#define HAL_TEMP_TIMER_ISR() void TC7_Handler(TC_TIMER_ARGS)
|
||||||
|
#endif
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// Types
|
// Types
|
||||||
|
|
|
@ -21,8 +21,7 @@
|
||||||
*/
|
*/
|
||||||
#if defined(STM32GENERIC) && defined(STM32F7)
|
#if defined(STM32GENERIC) && defined(STM32F7)
|
||||||
|
|
||||||
#include "../HAL.h"
|
#include "../../../inc/MarlinConfig.h"
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// Local defines
|
// Local defines
|
||||||
|
|
|
@ -34,9 +34,15 @@
|
||||||
|
|
||||||
#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq() / 2) // frequency of timer peripherals
|
#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq() / 2) // frequency of timer peripherals
|
||||||
|
|
||||||
#define STEP_TIMER_NUM 0 // index of timer to use for stepper
|
#ifndef STEP_TIMER_NUM
|
||||||
#define TEMP_TIMER_NUM 1 // index of timer to use for temperature
|
#define STEP_TIMER_NUM 0 // Timer Index for Stepper
|
||||||
|
#endif
|
||||||
|
#ifndef PULSE_TIMER_NUM
|
||||||
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||||
|
#endif
|
||||||
|
#ifndef TEMP_TIMER_NUM
|
||||||
|
#define TEMP_TIMER_NUM 1 // Timer Index for Temperature
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
||||||
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
|
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
|
||||||
|
@ -62,8 +68,12 @@
|
||||||
|
|
||||||
extern void TC5_Handler();
|
extern void TC5_Handler();
|
||||||
extern void TC7_Handler();
|
extern void TC7_Handler();
|
||||||
|
#ifndef HAL_STEP_TIMER_ISR
|
||||||
#define HAL_STEP_TIMER_ISR() void TC5_Handler()
|
#define HAL_STEP_TIMER_ISR() void TC5_Handler()
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_TEMP_TIMER_ISR
|
||||||
#define HAL_TEMP_TIMER_ISR() void TC7_Handler()
|
#define HAL_TEMP_TIMER_ISR() void TC7_Handler()
|
||||||
|
#endif
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// Types
|
// Types
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
#include "watchdog.h"
|
||||||
|
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,7 @@
|
||||||
|
|
||||||
#ifdef __MK20DX256__
|
#ifdef __MK20DX256__
|
||||||
|
|
||||||
#include "HAL.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
/** \brief Instruction Synchronization Barrier
|
/** \brief Instruction Synchronization Barrier
|
||||||
Instruction Synchronization Barrier flushes the pipeline in the processor,
|
Instruction Synchronization Barrier flushes the pipeline in the processor,
|
||||||
|
|
|
@ -47,9 +47,15 @@ typedef uint32_t hal_timer_t;
|
||||||
|
|
||||||
#define HAL_TIMER_RATE (FTM0_TIMER_RATE)
|
#define HAL_TIMER_RATE (FTM0_TIMER_RATE)
|
||||||
|
|
||||||
#define STEP_TIMER_NUM 0
|
#ifndef STEP_TIMER_NUM
|
||||||
#define TEMP_TIMER_NUM 1
|
#define STEP_TIMER_NUM 0 // Timer Index for Stepper
|
||||||
|
#endif
|
||||||
|
#ifndef PULSE_TIMER_NUM
|
||||||
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||||
|
#endif
|
||||||
|
#ifndef TEMP_TIMER_NUM
|
||||||
|
#define TEMP_TIMER_NUM 1 // Timer Index for Temperature
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TEMP_TIMER_FREQUENCY 1000
|
#define TEMP_TIMER_FREQUENCY 1000
|
||||||
|
|
||||||
|
@ -68,8 +74,12 @@ typedef uint32_t hal_timer_t;
|
||||||
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_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 DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
|
||||||
|
|
||||||
|
#ifndef HAL_STEP_TIMER_ISR
|
||||||
#define HAL_STEP_TIMER_ISR() extern "C" void ftm0_isr() //void TC3_Handler()
|
#define HAL_STEP_TIMER_ISR() extern "C" void ftm0_isr() //void TC3_Handler()
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_TEMP_TIMER_ISR
|
||||||
#define HAL_TEMP_TIMER_ISR() extern "C" void ftm1_isr() //void TC4_Handler()
|
#define HAL_TEMP_TIMER_ISR() extern "C" void ftm1_isr() //void TC4_Handler()
|
||||||
|
#endif
|
||||||
|
|
||||||
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
|
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,6 @@
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
#include "watchdog.h"
|
||||||
|
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <util/atomic.h>
|
#include <util/atomic.h>
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,7 @@
|
||||||
|
|
||||||
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
||||||
|
|
||||||
#include "HAL.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
/** \brief Instruction Synchronization Barrier
|
/** \brief Instruction Synchronization Barrier
|
||||||
Instruction Synchronization Barrier flushes the pipeline in the processor,
|
Instruction Synchronization Barrier flushes the pipeline in the processor,
|
||||||
|
|
|
@ -46,9 +46,15 @@ typedef uint32_t hal_timer_t;
|
||||||
|
|
||||||
#define HAL_TIMER_RATE (FTM0_TIMER_RATE)
|
#define HAL_TIMER_RATE (FTM0_TIMER_RATE)
|
||||||
|
|
||||||
#define STEP_TIMER_NUM 0
|
#ifndef STEP_TIMER_NUM
|
||||||
#define TEMP_TIMER_NUM 1
|
#define STEP_TIMER_NUM 0 // Timer Index for Stepper
|
||||||
|
#endif
|
||||||
|
#ifndef PULSE_TIMER_NUM
|
||||||
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||||
|
#endif
|
||||||
|
#ifndef TEMP_TIMER_NUM
|
||||||
|
#define TEMP_TIMER_NUM 1 // Timer Index for Temperature
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TEMP_TIMER_FREQUENCY 1000
|
#define TEMP_TIMER_FREQUENCY 1000
|
||||||
|
|
||||||
|
@ -67,8 +73,12 @@ typedef uint32_t hal_timer_t;
|
||||||
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_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 DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
|
||||||
|
|
||||||
|
#ifndef HAL_STEP_TIMER_ISR
|
||||||
#define HAL_STEP_TIMER_ISR() extern "C" void ftm0_isr() //void TC3_Handler()
|
#define HAL_STEP_TIMER_ISR() extern "C" void ftm0_isr() //void TC3_Handler()
|
||||||
|
#endif
|
||||||
|
#ifndef HAL_TEMP_TIMER_ISR
|
||||||
#define HAL_TEMP_TIMER_ISR() extern "C" void ftm1_isr() //void TC4_Handler()
|
#define HAL_TEMP_TIMER_ISR() extern "C" void ftm1_isr() //void TC4_Handler()
|
||||||
|
#endif
|
||||||
|
|
||||||
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
|
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "../HAL/HAL.h"
|
#include "../HAL/HAL.h"
|
||||||
|
|
||||||
#include "../pins/pins.h"
|
#include "../pins/pins.h"
|
||||||
|
#include HAL_PATH(../HAL, timers.h)
|
||||||
#include HAL_PATH(../HAL, spi_pins.h)
|
#include HAL_PATH(../HAL, spi_pins.h)
|
||||||
|
|
||||||
#include "Conditionals_post.h"
|
#include "Conditionals_post.h"
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
//
|
//
|
||||||
// Timers
|
// Timers
|
||||||
//
|
//
|
||||||
|
// These are already defined in DUE, so must be undefined first
|
||||||
#define STEP_TIMER_NUM 3
|
#define STEP_TIMER_NUM 3
|
||||||
#define HAL_STEP_TIMER_ISR() void TC3_Handler()
|
#define HAL_STEP_TIMER_ISR() void TC3_Handler()
|
||||||
|
|
||||||
|
|
Reference in a new issue