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.h 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  5. * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.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 <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #pragma once
  22. /**
  23. * HAL timers for Linux X86_64
  24. */
  25. // --------------------------------------------------------------------------
  26. // Includes
  27. // --------------------------------------------------------------------------
  28. #include <stdint.h>
  29. // --------------------------------------------------------------------------
  30. // Defines
  31. // --------------------------------------------------------------------------
  32. #define FORCE_INLINE __attribute__((always_inline)) inline
  33. typedef uint32_t hal_timer_t;
  34. #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
  35. #define HAL_TIMER_RATE ((SystemCoreClock) / 4) // frequency of timers peripherals
  36. #define STEP_TIMER_NUM 0 // Timer Index for Stepper
  37. #define TEMP_TIMER_NUM 1 // Timer Index for Temperature
  38. #define PULSE_TIMER_NUM STEP_TIMER_NUM
  39. #define TEMP_TIMER_RATE 1000000
  40. #define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
  41. #define STEPPER_TIMER_RATE HAL_TIMER_RATE // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
  42. #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
  43. #define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
  44. #define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
  45. #define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
  46. #define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
  47. #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
  48. #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
  49. #define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(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 HAL_STEP_TIMER_ISR() extern "C" void TIMER0_IRQHandler(void)
  53. #define HAL_TEMP_TIMER_ISR() extern "C" void TIMER1_IRQHandler(void)
  54. // PWM timer
  55. #define HAL_PWM_TIMER
  56. #define HAL_PWM_TIMER_ISR() extern "C" void TIMER3_IRQHandler(void)
  57. #define HAL_PWM_TIMER_IRQn
  58. void HAL_timer_init(void);
  59. void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
  60. void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare);
  61. hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
  62. hal_timer_t HAL_timer_get_count(const uint8_t timer_num);
  63. FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) {
  64. const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks;
  65. if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp);
  66. }
  67. void HAL_timer_enable_interrupt(const uint8_t timer_num);
  68. void HAL_timer_disable_interrupt(const uint8_t timer_num);
  69. bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
  70. #define HAL_timer_isr_prologue(TIMER_NUM)
  71. #define HAL_timer_isr_epilogue(TIMER_NUM)