浏览代码

Apply spacing, const to some HAL code

Scott Lahteine 7 年前
父节点
当前提交
2af62a5d8d

+ 6
- 6
Marlin/src/HAL/HAL_AVR/HAL_AVR.h 查看文件

@@ -112,21 +112,21 @@ extern "C" {
112 112
 #define ENABLE_TEMPERATURE_INTERRUPT()  SBI(TIMSK0, OCIE0B)
113 113
 #define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
114 114
 
115
-//void HAL_timer_start (uint8_t timer_num, uint32_t frequency);
116
-#define HAL_timer_start (timer_num,frequency)
115
+//void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
116
+#define HAL_timer_start(timer_num,frequency)
117 117
 
118
-//void HAL_timer_set_count (uint8_t timer_num, uint16_t count);
119
-#define HAL_timer_set_count(timer,count) timer = (count)
118
+//void HAL_timer_set_count(const uint8_t timer_num, const uint16_t count);
119
+#define HAL_timer_set_count(timer, count) timer = (count)
120 120
 
121 121
 #define HAL_timer_get_current_count(timer) timer
122 122
 
123
-//void HAL_timer_isr_prologue (uint8_t timer_num);
123
+//void HAL_timer_isr_prologue(const uint8_t timer_num);
124 124
 #define HAL_timer_isr_prologue(timer_num)
125 125
 
126 126
 #define HAL_STEP_TIMER_ISR ISR(TIMER1_COMPA_vect)
127 127
 #define HAL_TEMP_TIMER_ISR ISR(TIMER0_COMPB_vect)
128 128
 
129
-#define HAL_ENABLE_ISRs() do { cli(); if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
129
+#define HAL_ENABLE_ISRs() do { cli(); if (thermalManager.in_temp_isr) DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
130 130
 
131 131
 // ADC
132 132
 #ifdef DIDR2

+ 4
- 4
Marlin/src/HAL/HAL_AVR/servo_AVR.cpp 查看文件

@@ -96,19 +96,19 @@ static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t
96 96
 
97 97
   // Interrupt handlers for Arduino
98 98
   #if ENABLED(_useTimer1)
99
-    SIGNAL (TIMER1_COMPA_vect) { handle_interrupts(_timer1, &TCNT1, &OCR1A); }
99
+    SIGNAL(TIMER1_COMPA_vect) { handle_interrupts(_timer1, &TCNT1, &OCR1A); }
100 100
   #endif
101 101
 
102 102
   #if ENABLED(_useTimer3)
103
-    SIGNAL (TIMER3_COMPA_vect) { handle_interrupts(_timer3, &TCNT3, &OCR3A); }
103
+    SIGNAL(TIMER3_COMPA_vect) { handle_interrupts(_timer3, &TCNT3, &OCR3A); }
104 104
   #endif
105 105
 
106 106
   #if ENABLED(_useTimer4)
107
-    SIGNAL (TIMER4_COMPA_vect) { handle_interrupts(_timer4, &TCNT4, &OCR4A); }
107
+    SIGNAL(TIMER4_COMPA_vect) { handle_interrupts(_timer4, &TCNT4, &OCR4A); }
108 108
   #endif
109 109
 
110 110
   #if ENABLED(_useTimer5)
111
-    SIGNAL (TIMER5_COMPA_vect) { handle_interrupts(_timer5, &TCNT5, &OCR5A); }
111
+    SIGNAL(TIMER5_COMPA_vect) { handle_interrupts(_timer5, &TCNT5, &OCR5A); }
112 112
   #endif
113 113
 
114 114
 #else // WIRING

+ 1
- 1
Marlin/src/HAL/HAL_DUE/HAL_Due.cpp 查看文件

@@ -112,7 +112,7 @@ int freeMemory() {
112 112
 // ADC
113 113
 // --------------------------------------------------------------------------
114 114
 
115
-void HAL_adc_start_conversion (uint8_t adc_pin) {
115
+void HAL_adc_start_conversion(uint8_t adc_pin) {
116 116
   HAL_adc_result = analogRead(adc_pin);
117 117
 }
118 118
 

+ 19
- 19
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp 查看文件

@@ -92,18 +92,18 @@ const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
92 92
 */
93 93
 
94 94
 
95
-void HAL_timer_start (uint8_t timer_num, uint32_t frequency) {
96
-  Tc *tc = TimerConfig [timer_num].pTimerRegs;
97
-  IRQn_Type irq = TimerConfig [timer_num].IRQ_Id;
98
-  uint32_t channel = TimerConfig [timer_num].channel;
95
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
96
+  Tc *tc = TimerConfig[timer_num].pTimerRegs;
97
+  IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
98
+  uint32_t channel = TimerConfig[timer_num].channel;
99 99
 
100 100
   pmc_set_writeprotect(false);
101 101
   pmc_enable_periph_clk((uint32_t)irq);
102
-  NVIC_SetPriority (irq, TimerConfig [timer_num].priority);
102
+  NVIC_SetPriority(irq, TimerConfig [timer_num].priority);
103 103
 
104
-  TC_Configure (tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK1);
104
+  TC_Configure(tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK1);
105 105
 
106
-  TC_SetRC(tc, channel, VARIANT_MCK/2/frequency);
106
+  TC_SetRC(tc, channel, VARIANT_MCK / 2 / frequency);
107 107
   TC_Start(tc, channel);
108 108
 
109 109
   // enable interrupt on RC compare
@@ -112,25 +112,25 @@ void HAL_timer_start (uint8_t timer_num, uint32_t frequency) {
112 112
   NVIC_EnableIRQ(irq);
113 113
 }
114 114
 
115
-void HAL_timer_enable_interrupt (uint8_t timer_num) {
116
-  const tTimerConfig *pConfig = &TimerConfig [timer_num];
117
-  pConfig->pTimerRegs->TC_CHANNEL [pConfig->channel].TC_IER = TC_IER_CPCS;
115
+void HAL_timer_enable_interrupt(const uint8_t timer_num) {
116
+  const tTimerConfig *pConfig = &TimerConfig[timer_num];
117
+  pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IER = TC_IER_CPCS;
118 118
 }
119 119
 
120
-void HAL_timer_disable_interrupt (uint8_t timer_num) {
121
-  const tTimerConfig *pConfig = &TimerConfig [timer_num];
122
-  pConfig->pTimerRegs->TC_CHANNEL [pConfig->channel].TC_IDR = TC_IDR_CPCS;
120
+void HAL_timer_disable_interrupt(const uint8_t timer_num) {
121
+  const tTimerConfig *pConfig = &TimerConfig[timer_num];
122
+  pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IDR = TC_IDR_CPCS;
123 123
 }
124 124
 
125 125
 #if 0
126
-  void HAL_timer_set_count (uint8_t timer_num, uint32_t count) {
127
-    const tTimerConfig *pConfig = &TimerConfig [timer_num];
128
-    TC_SetRC (pConfig->pTimerRegs, pConfig->channel, count);
126
+  void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
127
+    const tTimerConfig *pConfig = &TimerConfig[timer_num];
128
+    TC_SetRC(pConfig->pTimerRegs, pConfig->channel, count);
129 129
   }
130 130
 
131
-  void HAL_timer_isr_prologue (uint8_t timer_num) {
132
-    const tTimerConfig *pConfig = &TimerConfig [timer_num];
133
-    TC_GetStatus (pConfig->pTimerRegs, pConfig->channel);
131
+  void HAL_timer_isr_prologue(const uint8_t timer_num) {
132
+    const tTimerConfig *pConfig = &TimerConfig[timer_num];
133
+    TC_GetStatus(pConfig->pTimerRegs, pConfig->channel);
134 134
   }
135 135
 #endif
136 136
 

+ 14
- 14
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h 查看文件

@@ -53,14 +53,14 @@
53 53
 
54 54
 #define TEMP_TIMER_FREQUENCY   1000 // temperature interrupt frequency
55 55
 
56
-#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt (STEP_TIMER_NUM)
57
-#define DISABLE_STEPPER_DRIVER_INTERRUPT()  HAL_timer_disable_interrupt (STEP_TIMER_NUM)
56
+#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
57
+#define DISABLE_STEPPER_DRIVER_INTERRUPT()  HAL_timer_disable_interrupt(STEP_TIMER_NUM)
58 58
 
59
-#define ENABLE_TEMPERATURE_INTERRUPT()  HAL_timer_enable_interrupt (TEMP_TIMER_NUM)
60
-#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt (TEMP_TIMER_NUM)
59
+#define ENABLE_TEMPERATURE_INTERRUPT()  HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
60
+#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
61
+
62
+#define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr) DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
61 63
 
62
-#define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
63
-//
64 64
 #define HAL_STEP_TIMER_ISR  void TC3_Handler()
65 65
 #define HAL_TEMP_TIMER_ISR  void TC4_Handler()
66 66
 
@@ -85,29 +85,29 @@ extern const tTimerConfig TimerConfig[];
85 85
 // Public functions
86 86
 // --------------------------------------------------------------------------
87 87
 
88
-void HAL_timer_start (uint8_t timer_num, uint32_t frequency);
88
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
89 89
 
90
-static FORCE_INLINE void HAL_timer_set_count (uint8_t timer_num, uint32_t count) {
90
+static FORCE_INLINE void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
91 91
   const tTimerConfig *pConfig = &TimerConfig[timer_num];
92 92
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count;
93 93
 }
94 94
 
95
-static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_count (uint8_t timer_num) {
95
+static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_count(const uint8_t timer_num) {
96 96
   const tTimerConfig *pConfig = &TimerConfig[timer_num];
97 97
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
98 98
 }
99 99
 
100
-static FORCE_INLINE uint32_t HAL_timer_get_current_count(uint8_t timer_num) {
100
+static FORCE_INLINE uint32_t HAL_timer_get_current_count(const uint8_t timer_num) {
101 101
   const tTimerConfig *pConfig = &TimerConfig[timer_num];
102 102
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
103 103
 }
104 104
 
105
-void HAL_timer_enable_interrupt(uint8_t timer_num);
106
-void HAL_timer_disable_interrupt(uint8_t timer_num);
105
+void HAL_timer_enable_interrupt(const uint8_t timer_num);
106
+void HAL_timer_disable_interrupt(const uint8_t timer_num);
107 107
 
108
-//void HAL_timer_isr_prologue (uint8_t timer_num);
108
+//void HAL_timer_isr_prologue(const uint8_t timer_num);
109 109
 
110
-static FORCE_INLINE void HAL_timer_isr_prologue(uint8_t timer_num) {
110
+static FORCE_INLINE void HAL_timer_isr_prologue(const uint8_t timer_num) {
111 111
   const tTimerConfig *pConfig = &TimerConfig[timer_num];
112 112
   // Reading the status register clears the interrupt flag
113 113
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_SR;

+ 33
- 42
Marlin/src/HAL/HAL_LPC1768/HAL_timers.cpp 查看文件

@@ -32,62 +32,53 @@
32 32
 #include "HAL_timers.h"
33 33
 
34 34
 void HAL_timer_init(void) {
35
-  LPC_SC->PCONP |= (0x1 << 0x1);  // power on timer0
35
+  SBI(LPC_SC->PCONP, 1);  // power on timer0
36 36
   LPC_TIM0->PR = ((HAL_TIMER_RATE / HAL_STEPPER_TIMER_RATE) - 1); // Use prescaler to set frequency if needed
37 37
 
38
-  LPC_SC->PCONP |= (0x1 << 0x2);  // power on timer1
38
+  SBI(LPC_SC->PCONP, 2);  // power on timer1
39 39
   LPC_TIM1->PR = ((HAL_TIMER_RATE / 1000000) - 1);
40 40
 }
41 41
 
42
-void HAL_timer_start(uint8_t timer_num, uint32_t frequency) {
43
-  switch(timer_num) {
44
-  case 0:
45
-    LPC_TIM0->MCR = 3;              // Match on MR0, reset on MR0
46
-    LPC_TIM0->MR0 = (uint32_t)(HAL_STEPPER_TIMER_RATE / frequency); // Match value (period) to set frequency
47
-    LPC_TIM0->TCR = (1 << 0);       // enable
48
-    break;
49
-  case 1:
50
-    LPC_TIM1->MCR = 3;
51
-    LPC_TIM1->MR0 = (uint32_t)(HAL_TEMP_TIMER_RATE / frequency);;
52
-    LPC_TIM1->TCR = (1 << 0);
53
-    break;
54
-  default:
55
-    return;
42
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
43
+  switch (timer_num) {
44
+    case 0:
45
+      LPC_TIM0->MCR = 3;              // Match on MR0, reset on MR0
46
+      LPC_TIM0->MR0 = (uint32_t)(HAL_STEPPER_TIMER_RATE / frequency); // Match value (period) to set frequency
47
+      LPC_TIM0->TCR = _BV(0);       // enable
48
+      break;
49
+    case 1:
50
+      LPC_TIM1->MCR = 3;
51
+      LPC_TIM1->MR0 = (uint32_t)(HAL_TEMP_TIMER_RATE / frequency);;
52
+      LPC_TIM1->TCR = _BV(0);
53
+      break;
54
+    default: break;
56 55
   }
57 56
 }
58 57
 
59
-void HAL_timer_enable_interrupt (uint8_t timer_num) {
60
-  switch(timer_num) {
61
-  case 0:
62
-    NVIC_EnableIRQ(TIMER0_IRQn);     // Enable interrupt handler
63
-    NVIC_SetPriority(TIMER0_IRQn, NVIC_EncodePriority(0, 1, 0));
64
-    break;
65
-  case 1:
66
-    NVIC_EnableIRQ(TIMER1_IRQn);
67
-    NVIC_SetPriority(TIMER1_IRQn, NVIC_EncodePriority(0, 2, 0));
68
-    break;
58
+void HAL_timer_enable_interrupt(const uint8_t timer_num) {
59
+  switch (timer_num) {
60
+    case 0:
61
+      NVIC_EnableIRQ(TIMER0_IRQn); // Enable interrupt handler
62
+      NVIC_SetPriority(TIMER0_IRQn, NVIC_EncodePriority(0, 1, 0));
63
+      break;
64
+    case 1:
65
+      NVIC_EnableIRQ(TIMER1_IRQn);
66
+      NVIC_SetPriority(TIMER1_IRQn, NVIC_EncodePriority(0, 2, 0));
67
+      break;
69 68
   }
70 69
 }
71 70
 
72
-void HAL_timer_disable_interrupt (uint8_t timer_num) {
73
-  switch(timer_num) {
74
-  case 0:
75
-    NVIC_DisableIRQ(TIMER0_IRQn);     // disable interrupt handler
76
-    break;
77
-  case 1:
78
-    NVIC_DisableIRQ(TIMER1_IRQn);
79
-    break;
71
+void HAL_timer_disable_interrupt(const uint8_t timer_num) {
72
+  switch (timer_num) {
73
+    case 0: NVIC_DisableIRQ(TIMER0_IRQn); break; // disable interrupt handler
74
+    case 1: NVIC_DisableIRQ(TIMER1_IRQn); break;
80 75
   }
81 76
 }
82 77
 
83
-void HAL_timer_isr_prologue (uint8_t timer_num) {
84
-  switch(timer_num) {
85
-  case 0:
86
-    LPC_TIM0->IR |= 1; //Clear the Interrupt
87
-    break;
88
-  case 1:
89
-    LPC_TIM1->IR |= 1;
90
-    break;
78
+void HAL_timer_isr_prologue(const uint8_t timer_num) {
79
+  switch (timer_num) {
80
+    case 0: SBI(LPC_TIM0->IR, 0); break; // Clear the Interrupt
81
+    case 1: SBI(LPC_TIM1->IR, 0); break;
91 82
   }
92 83
 }
93 84
 

+ 25
- 39
Marlin/src/HAL/HAL_LPC1768/HAL_timers.h 查看文件

@@ -53,14 +53,13 @@
53 53
 #define HAL_TEMP_TIMER_RATE    1000000
54 54
 #define TEMP_TIMER_FREQUENCY   1000 // temperature interrupt frequency
55 55
 
56
-#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt (STEP_TIMER_NUM)
57
-#define DISABLE_STEPPER_DRIVER_INTERRUPT()  HAL_timer_disable_interrupt (STEP_TIMER_NUM)
56
+#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
57
+#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
58
+#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
59
+#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
58 60
 
59
-#define ENABLE_TEMPERATURE_INTERRUPT()  HAL_timer_enable_interrupt (TEMP_TIMER_NUM)
60
-#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt (TEMP_TIMER_NUM)
61
+#define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr) DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
61 62
 
62
-#define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
63
-//
64 63
 #define HAL_STEP_TIMER_ISR  extern "C" void TIMER0_IRQHandler(void)
65 64
 #define HAL_TEMP_TIMER_ISR  extern "C" void TIMER1_IRQHandler(void)
66 65
 
@@ -75,47 +74,34 @@
75 74
 // --------------------------------------------------------------------------
76 75
 // Public functions
77 76
 // --------------------------------------------------------------------------
78
-void HAL_timer_init (void);
79
-void HAL_timer_start (uint8_t timer_num, uint32_t frequency);
80
-
81
-static FORCE_INLINE void HAL_timer_set_count (uint8_t timer_num, HAL_TIMER_TYPE count) {
82
-  switch(timer_num) {
83
-  case 0:
84
-    LPC_TIM0->MR0 = count;
85
-    break;
86
-  case 1:
87
-    LPC_TIM1->MR0 = count;
88
-    break;
89
-  default:
90
-    return;
77
+void HAL_timer_init(void);
78
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
79
+
80
+static FORCE_INLINE void HAL_timer_set_count(const uint8_t timer_num, const HAL_TIMER_TYPE count) {
81
+  switch (timer_num) {
82
+    case 0: LPC_TIM0->MR0 = count; break;
83
+    case 1: LPC_TIM1->MR0 = count; break;
91 84
   }
92 85
 }
93 86
 
94
-static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_count (uint8_t timer_num) {
95
-  switch(timer_num) {
96
-  case 0:
97
-    return LPC_TIM0->MR0;
98
-  case 1:
99
-    return LPC_TIM1->MR0;
100
-  default:
101
-    return 0;
87
+static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_count(const uint8_t timer_num) {
88
+  switch (timer_num) {
89
+    case 0: return LPC_TIM0->MR0;
90
+    case 1: return LPC_TIM1->MR0;
102 91
   }
92
+  return 0;
103 93
 }
104 94
 
105
-static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_current_count(uint8_t timer_num) {
106
-  switch(timer_num) {
107
-  case 0:
108
-    return LPC_TIM0->TC;
109
-  case 1:
110
-    return LPC_TIM1->TC;
111
-  default:
112
-    return 0;
95
+static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_current_count(const uint8_t timer_num) {
96
+  switch (timer_num) {
97
+    case 0: return LPC_TIM0->TC;
98
+    case 1: return LPC_TIM1->TC;
113 99
   }
100
+  return 0;
114 101
 }
115 102
 
116
-void HAL_timer_enable_interrupt(uint8_t timer_num);
117
-void HAL_timer_disable_interrupt(uint8_t timer_num);
118
-void HAL_timer_isr_prologue (uint8_t timer_num);
119
-
103
+void HAL_timer_enable_interrupt(const uint8_t timer_num);
104
+void HAL_timer_disable_interrupt(const uint8_t timer_num);
105
+void HAL_timer_isr_prologue(const uint8_t timer_num);
120 106
 
121 107
 #endif // _HAL_TIMERS_DUE_H

+ 3
- 3
Marlin/src/HAL/HAL_LPC1768/watchdog.cpp 查看文件

@@ -38,8 +38,8 @@ void HAL_clear_reset_source(void) {
38 38
   WDT_ClrTimeOutFlag();
39 39
 }
40 40
 
41
-uint8_t HAL_get_reset_source (void) {
42
-  if(WDT_ReadTimeOutFlag() & 1) return RST_WATCHDOG;
41
+uint8_t HAL_get_reset_source(void) {
42
+  if (TEST(WDT_ReadTimeOutFlag(), 0)) return RST_WATCHDOG;
43 43
   return RST_POWER_ON;
44 44
 }
45 45
 
@@ -50,4 +50,4 @@ void watchdog_reset() {
50 50
 
51 51
 #endif // USE_WATCHDOG
52 52
 
53
-#endif
53
+#endif // TARGET_LPC1768

+ 14
- 36
Marlin/src/HAL/HAL_TEENSY35_36/HAL_Teensy.cpp 查看文件

@@ -31,7 +31,6 @@
31 31
 
32 32
 uint16_t HAL_adc_result;
33 33
 
34
-
35 34
 static const uint8_t pin2sc1a[] = {
36 35
   5, 14, 8, 9, 13, 12, 6, 7, 15, 4, 3, 19+128, 14+128, 15+128, // 0-13 -> A0-A13
37 36
   5, 14, 8, 9, 13, 12, 6, 7, 15, 4, // 14-23 are A0-A9
@@ -49,45 +48,31 @@ static const uint8_t pin2sc1a[] = {
49 48
 };
50 49
 
51 50
 /*
52
-// disable interrupts
53
-void cli(void)
54
-{
55
-	noInterrupts();
56
-}
51
+  // disable interrupts
52
+  void cli(void) { noInterrupts(); }
57 53
 
58
-// enable interrupts
59
-void sei(void)
60
-{
61
-	interrupts();
62
-}
54
+  // enable interrupts
55
+  void sei(void) { interrupts(); }
63 56
 */
57
+
64 58
 void HAL_adc_init() {
65 59
   analog_init();
66 60
   while (ADC0_SC3 & ADC_SC3_CAL) {}; // Wait for calibration to finish
67 61
   NVIC_ENABLE_IRQ(IRQ_FTM1);
68 62
 }
69 63
 
70
-void HAL_clear_reset_source (void)
71
-{ }
64
+void HAL_clear_reset_source(void) { }
72 65
 
73
-uint8_t HAL_get_reset_source (void)
74
-{
75
-  switch ( RCM_SRS0 )
76
-  {
66
+uint8_t HAL_get_reset_source(void) {
67
+  switch (RCM_SRS0) {
77 68
     case 128: return RST_POWER_ON; break;
78 69
     case 64: return RST_EXTERNAL; break;
79 70
     case 32: return RST_WATCHDOG; break;
80
-//  case 8: return RST_LOSS_OF_LOCK; break;
81
-//  case 4: return RST_LOSS_OF_CLOCK; break;
82
-//  case 2: return RST_LOW_VOLTAGE; break;
83
-    default:
84
-      return 0;
71
+    // case 8: return RST_LOSS_OF_LOCK; break;
72
+    // case 4: return RST_LOSS_OF_CLOCK; break;
73
+    // case 2: return RST_LOW_VOLTAGE; break;
85 74
   }
86
-}
87
-
88
-void _delay_ms (int delay_ms)
89
-{
90
-	delay (delay_ms);
75
+  return 0;
91 76
 }
92 77
 
93 78
 extern "C" {
@@ -105,15 +90,8 @@ extern "C" {
105 90
   }
106 91
 }
107 92
 
108
-void HAL_adc_start_conversion (uint8_t adc_pin)
109
-{
110
-	ADC0_SC1A = pin2sc1a[adc_pin];
111
-}
93
+void HAL_adc_start_conversion(const uint8_t adc_pin) { ADC0_SC1A = pin2sc1a[adc_pin]; }
112 94
 
113
-uint16_t HAL_adc_get_result(void)
114
-{
115
-	return ADC0_RA;
116
-}
95
+uint16_t HAL_adc_get_result(void) { return ADC0_RA; }
117 96
 
118 97
 #endif // __MK64FX512__ || __MK66FX1M0__
119
-

+ 11
- 16
Marlin/src/HAL/HAL_TEENSY35_36/HAL_Teensy.h 查看文件

@@ -23,7 +23,6 @@
23 23
  * Description: HAL for Teensy 3.5 and Teensy 3.6
24 24
  */
25 25
 
26
-
27 26
 #ifndef _HAL_TEENSY_H
28 27
 #define _HAL_TEENSY_H
29 28
 
@@ -64,8 +63,6 @@
64 63
 
65 64
 #define HAL_SERVO_LIB libServo
66 65
 
67
-//#define _BV(bit) 	(1 << (bit))
68
-
69 66
 #ifndef analogInputToDigitalPin
70 67
   #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
71 68
 #endif
@@ -73,7 +70,6 @@
73 70
 #define CRITICAL_SECTION_START  unsigned char _sreg = SREG; cli();
74 71
 #define CRITICAL_SECTION_END    SREG = _sreg;
75 72
 
76
-
77 73
 // On AVR this is in math.h?
78 74
 #define square(x) ((x)*(x))
79 75
 
@@ -96,12 +92,12 @@
96 92
 #define RST_BACKUP     64
97 93
 
98 94
 /** clear reset reason */
99
-void HAL_clear_reset_source (void);
95
+void HAL_clear_reset_source(void);
100 96
 
101 97
 /** reset reason */
102
-uint8_t HAL_get_reset_source (void);
98
+uint8_t HAL_get_reset_source(void);
103 99
 
104
-void _delay_ms(int delay);
100
+FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
105 101
 
106 102
 extern "C" {
107 103
   int freeMemory(void);
@@ -124,21 +120,21 @@ void HAL_adc_init();
124 120
 
125 121
 #define HAL_ANALOG_SELECT(pin) NOOP;
126 122
 
127
-void HAL_adc_start_conversion (uint8_t adc_pin);
123
+void HAL_adc_start_conversion(uint8_t adc_pin);
128 124
 
129 125
 uint16_t HAL_adc_get_result(void);
130 126
 
131 127
 /*
132
-uint16_t HAL_getAdcReading(uint8_t chan);
128
+  uint16_t HAL_getAdcReading(uint8_t chan);
133 129
 
134
-void HAL_startAdcConversion(uint8_t chan);
135
-uint8_t HAL_pinToAdcChannel(int pin);
130
+  void HAL_startAdcConversion(uint8_t chan);
131
+  uint8_t HAL_pinToAdcChannel(int pin);
136 132
 
137
-uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
138
-//uint16_t HAL_getAdcSuperSample(uint8_t chan);
133
+  uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
134
+  //uint16_t HAL_getAdcSuperSample(uint8_t chan);
139 135
 
140
-void HAL_enable_AdcFreerun(void);
141
-//void HAL_disable_AdcFreerun(uint8_t chan);
136
+  void HAL_enable_AdcFreerun(void);
137
+  //void HAL_disable_AdcFreerun(uint8_t chan);
142 138
 */
143 139
 
144 140
 // --------------------------------------------------------------------------
@@ -146,4 +142,3 @@ void HAL_enable_AdcFreerun(void);
146 142
 // --------------------------------------------------------------------------
147 143
 
148 144
 #endif // _HAL_TEENSY_H
149
-

+ 36
- 46
Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.cpp 查看文件

@@ -30,65 +30,55 @@
30 30
 #include "HAL_timers_Teensy.h"
31 31
 
32 32
 
33
-void HAL_timer_start (uint8_t timer_num, uint32_t frequency) {
33
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
34 34
   switch (timer_num) {
35
-  case 0:
36
-    FTM0_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN;
37
-    FTM0_SC = 0x00; // Set this to zero before changing the modulus
38
-    FTM0_CNT = 0x0000; // Reset the count to zero
39
-    FTM0_MOD = 0xFFFF; // max modulus = 65535
40
-    FTM0_C0V = FTM0_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value
41
-    FTM0_SC = (FTM_SC_CLKS(0b1)&FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM0_TIMER_PRESCALE_BITS)&FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 8
42
-    FTM0_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
43
-    break;
44
-  case 1:
45
-    FTM1_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN; // Disable write protection, Enable FTM1
46
-    FTM1_SC = 0x00; // Set this to zero before changing the modulus
47
-    FTM1_CNT = 0x0000; // Reset the count to zero
48
-    FTM1_MOD = 0xFFFF; // max modulus = 65535
49
-    FTM1_C0V = FTM1_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value 65535
50
-    FTM1_SC = (FTM_SC_CLKS(0b1)&FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM1_TIMER_PRESCALE_BITS)&FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 4
51
-    FTM1_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
52
-    break;
53
-  default:
54
-    break;
35
+    case 0:
36
+      FTM0_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN;
37
+      FTM0_SC = 0x00; // Set this to zero before changing the modulus
38
+      FTM0_CNT = 0x0000; // Reset the count to zero
39
+      FTM0_MOD = 0xFFFF; // max modulus = 65535
40
+      FTM0_C0V = FTM0_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value
41
+      FTM0_SC = (FTM_SC_CLKS(0b1) & FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM0_TIMER_PRESCALE_BITS) & FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 8
42
+      FTM0_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
43
+      break;
44
+    case 1:
45
+      FTM1_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN; // Disable write protection, Enable FTM1
46
+      FTM1_SC = 0x00; // Set this to zero before changing the modulus
47
+      FTM1_CNT = 0x0000; // Reset the count to zero
48
+      FTM1_MOD = 0xFFFF; // max modulus = 65535
49
+      FTM1_C0V = FTM1_TIMER_RATE / frequency; // Initial FTM Channel 0 compare value 65535
50
+      FTM1_SC = (FTM_SC_CLKS(0b1) & FTM_SC_CLKS_MASK) | (FTM_SC_PS(FTM1_TIMER_PRESCALE_BITS) & FTM_SC_PS_MASK); // Bus clock 60MHz divided by prescaler 4
51
+      FTM1_C0SC = FTM_CSC_CHIE | FTM_CSC_MSA | FTM_CSC_ELSA;
52
+      break;
55 53
   }
56 54
 }
57 55
 
58
-void HAL_timer_enable_interrupt (uint8_t timer_num)
59
-{
56
+void HAL_timer_enable_interrupt(const uint8_t timer_num) {
60 57
   switch(timer_num) {
61
-  case 0: NVIC_ENABLE_IRQ(IRQ_FTM0); break;
62
-  case 1: NVIC_ENABLE_IRQ(IRQ_FTM1); break;
63
-  default:
64
-    break;
58
+    case 0: NVIC_ENABLE_IRQ(IRQ_FTM0); break;
59
+    case 1: NVIC_ENABLE_IRQ(IRQ_FTM1); break;
65 60
   }
66 61
 }
67 62
 
68
-void HAL_timer_disable_interrupt (uint8_t timer_num)
69
-{
63
+void HAL_timer_disable_interrupt(const uint8_t timer_num) {
70 64
   switch (timer_num) {
71
-  case 0: NVIC_DISABLE_IRQ(IRQ_FTM0); break;
72
-  case 1: NVIC_DISABLE_IRQ(IRQ_FTM1); break;
73
-  default:
74
-    break;
65
+    case 0: NVIC_DISABLE_IRQ(IRQ_FTM0); break;
66
+    case 1: NVIC_DISABLE_IRQ(IRQ_FTM1); break;
75 67
   }
76 68
 }
77 69
 
78
-void HAL_timer_isr_prologue(uint8_t timer_num) {
70
+void HAL_timer_isr_prologue(const uint8_t timer_num) {
79 71
   switch(timer_num) {
80
-  case 0:
81
-    FTM0_CNT = 0x0000;
82
-    FTM0_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
83
-    FTM0_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
84
-    break;
85
-  case 1:
86
-    FTM1_CNT = 0x0000;
87
-    FTM1_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
88
-    FTM1_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
89
-    break;
90
-  default:
91
-    break;
72
+    case 0:
73
+      FTM0_CNT = 0x0000;
74
+      FTM0_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
75
+      FTM0_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
76
+      break;
77
+    case 1:
78
+      FTM1_CNT = 0x0000;
79
+      FTM1_SC &= ~FTM_SC_TOF; // Clear FTM Overflow flag
80
+      FTM1_C0SC &= ~FTM_CSC_CHF; // Clear FTM Channel Compare flag
81
+      break;
92 82
   }
93 83
 }
94 84
 

+ 22
- 23
Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h 查看文件

@@ -52,8 +52,8 @@
52 52
 #define FTM0_TIMER_PRESCALE_BITS 0b011
53 53
 #define FTM1_TIMER_PRESCALE_BITS 0b010
54 54
 
55
-#define FTM0_TIMER_RATE F_BUS/FTM0_TIMER_PRESCALE // 60MHz / 8 = 7500kHz
56
-#define FTM1_TIMER_RATE F_BUS/FTM1_TIMER_PRESCALE // 60MHz / 4 = 15MHz
55
+#define FTM0_TIMER_RATE (F_BUS / FTM0_TIMER_PRESCALE) // 60MHz / 8 = 7500kHz
56
+#define FTM1_TIMER_RATE (F_BUS / FTM1_TIMER_PRESCALE) // 60MHz / 4 = 15MHz
57 57
 
58 58
 #define STEPPER_TIMER STEP_TIMER_NUM // Alias?
59 59
 #define STEPPER_TIMER_PRESCALE 0 // Not defined anywhere else!
@@ -64,46 +64,45 @@
64 64
 
65 65
 #define TEMP_TIMER_FREQUENCY   1000
66 66
 
67
-#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt (STEP_TIMER_NUM)
68
-#define DISABLE_STEPPER_DRIVER_INTERRUPT()  HAL_timer_disable_interrupt (STEP_TIMER_NUM)
69
-#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt (TEMP_TIMER_NUM)
70
-#define DISABLE_TEMPERATURE_INTERRUPT()  HAL_timer_disable_interrupt (TEMP_TIMER_NUM)
67
+#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
68
+#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
69
+#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
70
+#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
71 71
 
72 72
 #define HAL_STEP_TIMER_ISR  extern "C" void ftm0_isr(void) //void TC3_Handler()
73 73
 #define HAL_TEMP_TIMER_ISR  extern "C" void ftm1_isr(void) //void TC4_Handler()
74 74
 
75
-#define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
75
+#define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr) DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
76 76
 
77
-void HAL_timer_start (uint8_t timer_num, uint32_t frequency);
77
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
78 78
 
79
-static FORCE_INLINE void HAL_timer_set_count (uint8_t timer_num, uint32_t count) {
79
+static FORCE_INLINE void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
80 80
   switch(timer_num) {
81
-  case 0: FTM0_C0V = count; break;
82
-  case 1: FTM1_C0V = count; break;
83
-  default: break;
81
+    case 0: FTM0_C0V = count; break;
82
+    case 1: FTM1_C0V = count; break;
84 83
   }
85 84
 }
86 85
 
87
-static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_count (uint8_t timer_num) {
86
+static FORCE_INLINE HAL_TIMER_TYPE HAL_timer_get_count(const uint8_t timer_num) {
88 87
   switch(timer_num) {
89
-  case 0: return FTM0_C0V;
90
-  case 1: return FTM1_C0V;
91
-  default: return 0;
88
+    case 0: return FTM0_C0V;
89
+    case 1: return FTM1_C0V;
92 90
   }
91
+  return 0;
93 92
 }
94 93
 
95
-static FORCE_INLINE uint32_t HAL_timer_get_current_count(uint8_t timer_num) {
94
+static FORCE_INLINE uint32_t HAL_timer_get_current_count(const uint8_t timer_num) {
96 95
   switch(timer_num) {
97
-  case 0: return FTM0_CNT;
98
-  case 1: return FTM1_CNT;
99
-  default: return 0;
96
+    case 0: return FTM0_CNT;
97
+    case 1: return FTM1_CNT;
100 98
   }
99
+  return 0;
101 100
 }
102 101
 
103
-void HAL_timer_enable_interrupt (uint8_t timer_num);
104
-void HAL_timer_disable_interrupt (uint8_t timer_num);
102
+void HAL_timer_enable_interrupt(const uint8_t timer_num);
103
+void HAL_timer_disable_interrupt(const uint8_t timer_num);
105 104
 
106
-void HAL_timer_isr_prologue(uint8_t timer_num);
105
+void HAL_timer_isr_prologue(const uint8_t timer_num);
107 106
 
108 107
 #endif // _HAL_TIMERS_TEENSY_H
109 108
 

+ 1
- 1
Marlin/stepper.cpp 查看文件

@@ -1155,7 +1155,7 @@ void Stepper::init() {
1155 1155
   TCNT1 = 0;
1156 1156
 #else
1157 1157
   // Init Stepper ISR to 122 Hz for quick starting
1158
-  HAL_timer_start (STEP_TIMER_NUM, 122);
1158
+  HAL_timer_start(STEP_TIMER_NUM, 122);
1159 1159
 #endif
1160 1160
 
1161 1161
   ENABLE_STEPPER_DRIVER_INTERRUPT();

+ 3
- 3
Marlin/temperature.cpp 查看文件

@@ -1081,8 +1081,8 @@ void Temperature::init() {
1081 1081
     OCR0B = 128;
1082 1082
     SBI(TIMSK0, OCIE0B);
1083 1083
   #else
1084
-    HAL_timer_start (TEMP_TIMER_NUM, TEMP_TIMER_FREQUENCY);
1085
-    HAL_timer_enable_interrupt (TEMP_TIMER_NUM);
1084
+    HAL_timer_start(TEMP_TIMER_NUM, TEMP_TIMER_FREQUENCY);
1085
+    HAL_timer_enable_interrupt(TEMP_TIMER_NUM);
1086 1086
   #endif
1087 1087
 
1088 1088
   #if HAS_AUTO_FAN_0
@@ -1594,7 +1594,7 @@ void Temperature::set_current_temp_raw() {
1594 1594
  *  - For ENDSTOP_INTERRUPTS_FEATURE check endstops if flagged
1595 1595
  */
1596 1596
 HAL_TEMP_TIMER_ISR {
1597
-  HAL_timer_isr_prologue (TEMP_TIMER_NUM);
1597
+  HAL_timer_isr_prologue(TEMP_TIMER_NUM);
1598 1598
   Temperature::isr();
1599 1599
 }
1600 1600
 

正在加载...
取消
保存