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.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 <http://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. #define STEP_TIMER_NUM 0 // index of timer to use for stepper
  32. #define TEMP_TIMER_NUM 1 // index of timer to use for temperature
  33. #define PULSE_TIMER_NUM STEP_TIMER_NUM
  34. #define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
  35. #define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
  36. #define STEPPER_TIMER_PRESCALE 54 // was 40,prescaler for setting stepper timer, 2Mhz
  37. #define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer
  38. #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
  39. #define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
  40. #define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
  41. #define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
  42. #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
  43. #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
  44. #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
  45. #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
  46. #define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
  47. #define TEMP_ISR_ENABLED() HAL_timer_interrupt_enabled(TEMP_TIMER_NUM)
  48. // TODO change this
  49. extern void TC5_Handler();
  50. extern void TC7_Handler();
  51. #define HAL_STEP_TIMER_ISR() void TC5_Handler()
  52. #define HAL_TEMP_TIMER_ISR() void TC7_Handler()
  53. // ------------------------
  54. // Types
  55. // ------------------------
  56. typedef struct {
  57. TIM_HandleTypeDef timerdef;
  58. IRQn_Type IRQ_Id;
  59. uint32_t callback;
  60. } tTimerConfig;
  61. // ------------------------
  62. // Public Variables
  63. // ------------------------
  64. //extern const tTimerConfig timerConfig[];
  65. // ------------------------
  66. // Public functions
  67. // ------------------------
  68. void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
  69. void HAL_timer_enable_interrupt(const uint8_t timer_num);
  70. void HAL_timer_disable_interrupt(const uint8_t timer_num);
  71. bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
  72. void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare);
  73. hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
  74. uint32_t HAL_timer_get_count(const uint8_t timer_num);
  75. void HAL_timer_isr_prologue(const uint8_t timer_num);
  76. #define HAL_timer_isr_epilogue(TIMER_NUM)