My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

timers.h 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
  5. * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #pragma once
  22. /**
  23. * HAL Timers for Teensy 3.5 (MK64FX512) and Teensy 3.6 (MK66FX1M0)
  24. */
  25. #include <stdint.h>
  26. // ------------------------
  27. // Defines
  28. // ------------------------
  29. #define FORCE_INLINE __attribute__((always_inline)) inline
  30. typedef uint32_t hal_timer_t;
  31. #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
  32. #define FTM0_TIMER_PRESCALE 8
  33. #define FTM1_TIMER_PRESCALE 4
  34. #define FTM0_TIMER_PRESCALE_BITS 0b011
  35. #define FTM1_TIMER_PRESCALE_BITS 0b010
  36. #define FTM0_TIMER_RATE (F_BUS / FTM0_TIMER_PRESCALE) // 60MHz / 8 = 7500kHz
  37. #define FTM1_TIMER_RATE (F_BUS / FTM1_TIMER_PRESCALE) // 60MHz / 4 = 15MHz
  38. #define HAL_TIMER_RATE (FTM0_TIMER_RATE)
  39. #ifndef STEP_TIMER_NUM
  40. #define STEP_TIMER_NUM 0 // Timer Index for Stepper
  41. #endif
  42. #ifndef PULSE_TIMER_NUM
  43. #define PULSE_TIMER_NUM STEP_TIMER_NUM
  44. #endif
  45. #ifndef TEMP_TIMER_NUM
  46. #define TEMP_TIMER_NUM 1 // Timer Index for Temperature
  47. #endif
  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. #ifndef HAL_STEP_TIMER_ISR
  61. #define HAL_STEP_TIMER_ISR() extern "C" void ftm0_isr() //void TC3_Handler()
  62. #endif
  63. #ifndef HAL_TEMP_TIMER_ISR
  64. #define HAL_TEMP_TIMER_ISR() extern "C" void ftm1_isr() //void TC4_Handler()
  65. #endif
  66. void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
  67. FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
  68. switch (timer_num) {
  69. case 0: FTM0_C0V = compare; break;
  70. case 1: FTM1_C0V = compare; break;
  71. }
  72. }
  73. FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
  74. switch (timer_num) {
  75. case 0: return FTM0_C0V;
  76. case 1: return FTM1_C0V;
  77. }
  78. return 0;
  79. }
  80. FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
  81. switch (timer_num) {
  82. case 0: return FTM0_CNT;
  83. case 1: return FTM1_CNT;
  84. }
  85. return 0;
  86. }
  87. void HAL_timer_enable_interrupt(const uint8_t timer_num);
  88. void HAL_timer_disable_interrupt(const uint8_t timer_num);
  89. bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
  90. void HAL_timer_isr_prologue(const uint8_t timer_num);
  91. #define HAL_timer_isr_epilogue(TIMER_NUM)