Skip to content

Commit 553b078

Browse files
committed
Switched to more generic ISR prefix and suffix for extra HAL code insertion
1 parent ac8a7d3 commit 553b078

File tree

3 files changed

+29
-56
lines changed

3 files changed

+29
-56
lines changed

Timer.ino

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -96,24 +96,12 @@ ISR(TIMER1_COMPA_vect,ISR_NOBLOCK)
9696
IRAM_ATTR ISR(TIMER1_COMPA_vect)
9797
#endif
9898
{
99-
#ifdef HAL_TIMER1_INT_CLEAR
100-
HAL_TIMER1_INT_CLEAR;
101-
#endif
102-
#ifdef ESP32
103-
portENTER_CRITICAL_ISR(&siderealTimerMux);
99+
#ifdef HAL_TIMER1_PREFIX
100+
HAL_TIMER1_PREFIX;
104101
#endif
105102

106103
// run 1/3 of the time at 3x the rate, unless a goto is happening
107-
if (trackingState!=TrackingMoveTo) {
108-
cnt++;
109-
if (cnt%3!=0) {
110-
#ifdef ESP32
111-
portEXIT_CRITICAL_ISR(&siderealTimerMux);
112-
#endif
113-
return;
114-
}
115-
cnt=0;
116-
}
104+
if (trackingState!=TrackingMoveTo) { cnt++; if (cnt%3!=0) goto done; cnt=0; }
117105
lst++;
118106

119107
// handle buzzer
@@ -123,9 +111,10 @@ IRAM_ATTR ISR(TIMER1_COMPA_vect)
123111
timerSuper();
124112
#endif
125113

126-
#ifdef ESP32
127-
portEXIT_CRITICAL_ISR(&siderealTimerMux);
128-
#endif
114+
done: {}
115+
#ifdef HAL_TIMER1_SUFFIX
116+
HAL_TIMER1_SUFFIX;
117+
#endif
129118
}
130119

131120
void timerSuper() {
@@ -248,22 +237,11 @@ void timerSuper() {
248237

249238
IRAM_ATTR ISR(TIMER3_COMPA_vect)
250239
{
251-
#ifdef HAL_TIMER3_INT_CLEAR
252-
HAL_TIMER3_INT_CLEAR;
253-
#endif
254-
#ifdef ESP32
255-
portENTER_CRITICAL_ISR(&motorTimerMux);
240+
#ifdef HAL_TIMER3_PREFIX
241+
HAL_TIMER3_PREFIX;
256242
#endif
257243

258-
if (!fastAxis1) {
259-
t3cnt++;
260-
if (t3cnt%t3rep!=0) {
261-
#ifdef ESP32
262-
portEXIT_CRITICAL_ISR(&motorTimerMux);
263-
#endif
264-
return;
265-
}
266-
}
244+
if (!fastAxis1) { t3cnt++; if (t3cnt%t3rep!=0) goto done; }
267245

268246
StepPinAxis1_LOW;
269247

@@ -325,29 +303,19 @@ IRAM_ATTR ISR(TIMER3_COMPA_vect)
325303
}
326304
#endif
327305

328-
#ifdef ESP32
329-
portEXIT_CRITICAL_ISR(&motorTimerMux);
306+
done: {}
307+
#ifdef HAL_TIMER3_SUFFIX
308+
HAL_TIMER3_SUFFIX;
330309
#endif
331310
}
332311

333312
IRAM_ATTR ISR(TIMER4_COMPA_vect)
334313
{
335-
#ifdef HAL_TIMER4_INT_CLEAR
336-
HAL_TIMER4_INT_CLEAR;
337-
#endif
338-
#ifdef ESP32
339-
portENTER_CRITICAL_ISR(&motorTimerMux);
314+
#ifdef HAL_TIMER4_PREFIX
315+
HAL_TIMER4_PREFIX;
340316
#endif
341317

342-
if (!fastAxis2) {
343-
t4cnt++;
344-
if (t4cnt%t4rep!=0) {
345-
#ifdef ESP32
346-
portEXIT_CRITICAL_ISR(&motorTimerMux);
347-
#endif
348-
return;
349-
}
350-
}
318+
if (!fastAxis2) { t4cnt++; if (t4cnt%t4rep!=0) goto done; }
351319

352320
StepPinAxis2_LOW;
353321

@@ -409,8 +377,9 @@ IRAM_ATTR ISR(TIMER4_COMPA_vect)
409377
}
410378
#endif
411379

412-
#ifdef ESP32
413-
portEXIT_CRITICAL_ISR(&motorTimerMux);
380+
done: {}
381+
#ifdef HAL_TIMER4_SUFFIX
382+
HAL_TIMER4_SUFFIX;
414383
#endif
415384
}
416385

@@ -453,4 +422,3 @@ void clockSync() {
453422
PPSlastMicroS=t;
454423
}
455424
#endif
456-

src/HAL/HAL_ESP32/HAL_ESP32.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ void TIMER4_COMPA_vect(void);
4848
portMUX_TYPE siderealTimerMux = portMUX_INITIALIZER_UNLOCKED;
4949
portMUX_TYPE motorTimerMux = portMUX_INITIALIZER_UNLOCKED;
5050

51+
#define HAL_TIMER1_PREFIX portENTER_CRITICAL_ISR( &siderealTimerMux )
52+
#define HAL_TIMER3_PREFIX portENTER_CRITICAL_ISR( &motorTimerMux )
53+
#define HAL_TIMER4_PREFIX portENTER_CRITICAL_ISR( &motorTimerMux )
54+
#define HAL_TIMER1_SUFFIX portEXIT_CRITICAL_ISR( &siderealTimerMux )
55+
#define HAL_TIMER3_SUFFIX portEXIT_CRITICAL_ISR( &motorTimerMux )
56+
#define HAL_TIMER4_SUFFIX portEXIT_CRITICAL_ISR( &motorTimerMux )
57+
5158
// Override cli/sei and use for muxes
5259
#undef cli
5360
IRAM_ATTR void cli() { portENTER_CRITICAL(&motorTimerMux); portENTER_CRITICAL(&siderealTimerMux); }
@@ -140,4 +147,3 @@ IRAM_ATTR void QuickSetIntervalAxis2(uint32_t r) {
140147
#define StepPinAxis2_LOW digitalWrite(Axis2StepPin, LOW)
141148
#define DirPinAxis2_HIGH digitalWrite(Axis2DirPin, HIGH)
142149
#define DirPinAxis2_LOW digitalWrite(Axis2DirPin, LOW)
143-

src/HAL/HAL_Tiva_C/HAL_Tiva_C.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
// Interrupts
4040
#define cli() noInterrupts()
4141
#define sei() interrupts()
42-
#define HAL_TIMER1_INT_CLEAR TimerIntClear( Timer1_base, TIMER_TIMA_TIMEOUT )
43-
#define HAL_TIMER3_INT_CLEAR TimerIntClear( Timer3_base, TIMER_TIMA_TIMEOUT )
44-
#define HAL_TIMER4_INT_CLEAR TimerIntClear( Timer4_base, TIMER_TIMA_TIMEOUT )
42+
#define HAL_TIMER1_PREFIX TimerIntClear( Timer1_base, TIMER_TIMA_TIMEOUT )
43+
#define HAL_TIMER3_PREFIX TimerIntClear( Timer3_base, TIMER_TIMA_TIMEOUT )
44+
#define HAL_TIMER4_PREFIX TimerIntClear( Timer4_base, TIMER_TIMA_TIMEOUT )
4545

4646
// Lower limit (fastest) step rate in uS for this platform
4747
#if defined(__TM4C1294NCPDT__) || defined(__TM4C1294XNCZAD__)
@@ -212,4 +212,3 @@ void QuickSetIntervalAxis2(uint32_t r) {
212212
#define StepPinAxis2_LOW CLR(Axis2StepPORT, Axis2StepBit)
213213
#define DirPinAxis2_HIGH SET(Axis2DirPORT, Axis2DirBit)
214214
#define DirPinAxis2_LOW CLR(Axis2DirPORT, Axis2DirBit)
215-

0 commit comments

Comments
 (0)