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.

timers.h 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  5. * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
  6. * Copyright (c) 2017 Victor Perez
  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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include <stdint.h>
  24. // ------------------------
  25. // Defines
  26. // ------------------------
  27. #define FORCE_INLINE __attribute__((always_inline)) inline
  28. #define hal_timer_t uint32_t // TODO: One is 16-bit, one 32-bit - does this need to be checked?
  29. #define HAL_TIMER_TYPE_MAX 0xFFFF
  30. #define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq() / 2) // frequency of timer peripherals
  31. #ifndef STEP_TIMER_NUM
  32. #define STEP_TIMER_NUM 0 // Timer Index for Stepper
  33. #endif
  34. #ifndef PULSE_TIMER_NUM
  35. #define PULSE_TIMER_NUM STEP_TIMER_NUM
  36. #endif
  37. #ifndef TEMP_TIMER_NUM
  38. #define TEMP_TIMER_NUM 1 // Timer Index for Temperature
  39. #endif
  40. #define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
  41. #define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
  42. #define STEPPER_TIMER_PRESCALE 54 // was 40,prescaler for setting stepper timer, 2Mhz
  43. #define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer
  44. #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
  45. #define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
  46. #define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
  47. #define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
  48. #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
  49. #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
  50. #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
  51. #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
  52. #define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
  53. #define TEMP_ISR_ENABLED() HAL_timer_interrupt_enabled(TEMP_TIMER_NUM)
  54. // TODO change this
  55. extern void TC5_Handler();
  56. extern void TC7_Handler();
  57. #ifndef HAL_STEP_TIMER_ISR
  58. #define HAL_STEP_TIMER_ISR() void TC5_Handler()
  59. #endif
  60. #ifndef HAL_TEMP_TIMER_ISR
  61. #define HAL_TEMP_TIMER_ISR() void TC7_Handler()
  62. #endif
  63. // ------------------------
  64. // Types
  65. // ------------------------
  66. typedef struct {
  67. TIM_HandleTypeDef timerdef;
  68. IRQn_Type IRQ_Id;
  69. uint32_t callback;
  70. } tTimerConfig;
  71. // ------------------------
  72. // Public Variables
  73. // ------------------------
  74. //extern const tTimerConfig timerConfig[];
  75. // ------------------------
  76. // Public functions
  77. // ------------------------
  78. void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
  79. void HAL_timer_enable_interrupt(const uint8_t timer_num);
  80. void HAL_timer_disable_interrupt(const uint8_t timer_num);
  81. bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
  82. void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare);
  83. hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
  84. uint32_t HAL_timer_get_count(const uint8_t timer_num);
  85. void HAL_timer_isr_prologue(const uint8_t timer_num);
  86. #define HAL_timer_isr_epilogue(TIMER_NUM)