My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HAL_timers_Teensy.h 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * Description: HAL for
  25. * Teensy3.2 (__MK20DX256__)
  26. */
  27. #pragma once
  28. // --------------------------------------------------------------------------
  29. // Includes
  30. // --------------------------------------------------------------------------
  31. #include <stdint.h>
  32. // --------------------------------------------------------------------------
  33. // Defines
  34. // --------------------------------------------------------------------------
  35. #define FORCE_INLINE __attribute__((always_inline)) inline
  36. typedef uint32_t hal_timer_t;
  37. #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
  38. #define FTM0_TIMER_PRESCALE 8
  39. #define FTM1_TIMER_PRESCALE 4
  40. #define FTM0_TIMER_PRESCALE_BITS 0b011
  41. #define FTM1_TIMER_PRESCALE_BITS 0b010
  42. #define FTM0_TIMER_RATE (F_BUS / FTM0_TIMER_PRESCALE) // 60MHz / 8 = 7500kHz
  43. #define FTM1_TIMER_RATE (F_BUS / FTM1_TIMER_PRESCALE) // 60MHz / 4 = 15MHz
  44. #define HAL_TIMER_RATE (FTM0_TIMER_RATE)
  45. #define STEP_TIMER_NUM 0
  46. #define TEMP_TIMER_NUM 1
  47. #define PULSE_TIMER_NUM STEP_TIMER_NUM
  48. #define TEMP_TIMER_FREQUENCY 1000
  49. #define STEPPER_TIMER_RATE HAL_TIMER_RATE
  50. #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000)
  51. #define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
  52. #define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
  53. #define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
  54. #define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
  55. #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
  56. #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
  57. #define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
  58. #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
  59. #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
  60. #define HAL_STEP_TIMER_ISR() extern "C" void ftm0_isr(void) //void TC3_Handler()
  61. #define HAL_TEMP_TIMER_ISR() extern "C" void ftm1_isr(void) //void TC4_Handler()
  62. void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
  63. FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
  64. switch (timer_num) {
  65. case 0: FTM0_C0V = compare; break;
  66. case 1: FTM1_C0V = compare; break;
  67. }
  68. }
  69. FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
  70. switch (timer_num) {
  71. case 0: return FTM0_C0V;
  72. case 1: return FTM1_C0V;
  73. }
  74. return 0;
  75. }
  76. FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
  77. switch (timer_num) {
  78. case 0: return FTM0_CNT;
  79. case 1: return FTM1_CNT;
  80. }
  81. return 0;
  82. }
  83. void HAL_timer_enable_interrupt(const uint8_t timer_num);
  84. void HAL_timer_disable_interrupt(const uint8_t timer_num);
  85. bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
  86. void HAL_timer_isr_prologue(const uint8_t timer_num);
  87. #define HAL_timer_isr_epilogue(TIMER_NUM)