My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

timers.h 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #pragma once
  21. /**
  22. * Description: HAL for
  23. * Teensy4.0/4.1 (__IMXRT1062__)
  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 0xFFFFFFFE
  32. #define GPT_TIMER_RATE F_BUS_ACTUAL // 150MHz
  33. #define GPT1_TIMER_PRESCALE 2
  34. #define GPT2_TIMER_PRESCALE 10
  35. #define GPT1_TIMER_RATE (GPT_TIMER_RATE / GPT1_TIMER_PRESCALE) // 75MHz
  36. #define GPT2_TIMER_RATE (GPT_TIMER_RATE / GPT2_TIMER_PRESCALE) // 15MHz
  37. #ifndef STEP_TIMER_NUM
  38. #define STEP_TIMER_NUM 0 // Timer Index for Stepper
  39. #endif
  40. #ifndef PULSE_TIMER_NUM
  41. #define PULSE_TIMER_NUM STEP_TIMER_NUM
  42. #endif
  43. #ifndef TEMP_TIMER_NUM
  44. #define TEMP_TIMER_NUM 1 // Timer Index for Temperature
  45. #endif
  46. #define TEMP_TIMER_RATE 1000000
  47. #define TEMP_TIMER_FREQUENCY 1000
  48. #define STEPPER_TIMER_RATE GPT1_TIMER_RATE
  49. #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000)
  50. #define STEPPER_TIMER_PRESCALE ((GPT_TIMER_RATE / 1000000) / STEPPER_TIMER_TICKS_PER_US)
  51. #define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
  52. #define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
  53. #define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
  54. #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
  55. #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
  56. #define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
  57. #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
  58. #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
  59. #ifndef HAL_STEP_TIMER_ISR
  60. #define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler() // GPT1_Handler()
  61. #endif
  62. #ifndef HAL_TEMP_TIMER_ISR
  63. #define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler() // GPT2_Handler()
  64. #endif
  65. extern "C" void stepTC_Handler();
  66. extern "C" void tempTC_Handler();
  67. void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
  68. FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
  69. switch (timer_num) {
  70. case 0:
  71. GPT1_OCR1 = compare - 1;
  72. break;
  73. case 1:
  74. GPT2_OCR1 = compare - 1;
  75. break;
  76. }
  77. }
  78. FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
  79. switch (timer_num) {
  80. case 0: return GPT1_OCR1;
  81. case 1: return GPT2_OCR1;
  82. }
  83. return 0;
  84. }
  85. FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
  86. switch (timer_num) {
  87. case 0: return GPT1_CNT;
  88. case 1: return GPT2_CNT;
  89. }
  90. return 0;
  91. }
  92. void HAL_timer_enable_interrupt(const uint8_t timer_num);
  93. void HAL_timer_disable_interrupt(const uint8_t timer_num);
  94. bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
  95. void HAL_timer_isr_prologue(const uint8_t timer_num);
  96. //void HAL_timer_isr_epilogue(const uint8_t timer_num) {}
  97. #define HAL_timer_isr_epilogue(TIMER_NUM)