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 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #include <stdint.h>
  24. #include <driver/timer.h>
  25. // Includes needed to get I2S_STEPPER_STREAM. Note that pins.h
  26. // is included in case this header is being included early.
  27. #include "../../inc/MarlinConfig.h"
  28. #include "../../pins/pins.h"
  29. // ------------------------
  30. // Defines
  31. // ------------------------
  32. //
  33. #define FORCE_INLINE __attribute__((always_inline)) inline
  34. typedef uint64_t hal_timer_t;
  35. #define HAL_TIMER_TYPE_MAX 0xFFFFFFFFFFFFFFFFULL
  36. #define STEP_TIMER_NUM 0 // index of timer to use for stepper
  37. #define TEMP_TIMER_NUM 1 // index of timer to use for temperature
  38. #define PWM_TIMER_NUM 2 // index of timer to use for PWM outputs
  39. #define PULSE_TIMER_NUM STEP_TIMER_NUM
  40. #define HAL_TIMER_RATE APB_CLK_FREQ // frequency of timer peripherals
  41. #if ENABLED(I2S_STEPPER_STREAM)
  42. #define STEPPER_TIMER_PRESCALE 1
  43. #define STEPPER_TIMER_RATE 250000 // 250khz, 4µs pulses of i2s word clock
  44. #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs // wrong would be 0.25
  45. #else
  46. #define STEPPER_TIMER_PRESCALE 40
  47. #define STEPPER_TIMER_RATE ((HAL_TIMER_RATE) / (STEPPER_TIMER_PRESCALE)) // frequency of stepper timer, 2MHz
  48. #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
  49. #endif
  50. #define STEP_TIMER_MIN_INTERVAL 8 // minimum time in µs between stepper interrupts
  51. #define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
  52. #define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
  53. #define PWM_TIMER_PRESCALE 10
  54. #if ENABLED(FAST_PWM_FAN)
  55. #define PWM_TIMER_FREQUENCY FAST_PWM_FAN_FREQUENCY
  56. #else
  57. #define PWM_TIMER_FREQUENCY (50*128) // 50Hz and 7bit resolution
  58. #endif
  59. #define MAX_PWM_PINS 32 // Number of PWM pin-slots
  60. #define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
  61. #define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
  62. #define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
  63. #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
  64. #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
  65. #define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
  66. #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
  67. #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
  68. #define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler()
  69. #define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler()
  70. #define HAL_PWM_TIMER_ISR() extern "C" void pwmTC_Handler()
  71. extern "C" void tempTC_Handler();
  72. extern "C" void stepTC_Handler();
  73. extern "C" void pwmTC_Handler();
  74. // ------------------------
  75. // Types
  76. // ------------------------
  77. typedef struct {
  78. timer_group_t group;
  79. timer_idx_t idx;
  80. uint32_t divider;
  81. void (*fn)();
  82. } tTimerConfig;
  83. // ------------------------
  84. // Public Variables
  85. // ------------------------
  86. extern const tTimerConfig TimerConfig[];
  87. // ------------------------
  88. // Public functions
  89. // ------------------------
  90. void HAL_timer_start (const uint8_t timer_num, uint32_t frequency);
  91. void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t count);
  92. hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
  93. hal_timer_t HAL_timer_get_count(const uint8_t timer_num);
  94. void HAL_timer_enable_interrupt(const uint8_t timer_num);
  95. void HAL_timer_disable_interrupt(const uint8_t timer_num);
  96. bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
  97. #define HAL_timer_isr_prologue(TIMER_NUM)
  98. #define HAL_timer_isr_epilogue(TIMER_NUM)