Skip to content

Commit

Permalink
Switched to more generic ISR prefix and suffix for extra HAL code ins…
Browse files Browse the repository at this point in the history
…ertion
  • Loading branch information
hjd1964 committed Sep 20, 2018
1 parent ac8a7d3 commit 553b078
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 56 deletions.
70 changes: 19 additions & 51 deletions Timer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,12 @@ ISR(TIMER1_COMPA_vect,ISR_NOBLOCK)
IRAM_ATTR ISR(TIMER1_COMPA_vect)
#endif
{
#ifdef HAL_TIMER1_INT_CLEAR
HAL_TIMER1_INT_CLEAR;
#endif
#ifdef ESP32
portENTER_CRITICAL_ISR(&siderealTimerMux);
#ifdef HAL_TIMER1_PREFIX
HAL_TIMER1_PREFIX;
#endif

// run 1/3 of the time at 3x the rate, unless a goto is happening
if (trackingState!=TrackingMoveTo) {
cnt++;
if (cnt%3!=0) {
#ifdef ESP32
portEXIT_CRITICAL_ISR(&siderealTimerMux);
#endif
return;
}
cnt=0;
}
if (trackingState!=TrackingMoveTo) { cnt++; if (cnt%3!=0) goto done; cnt=0; }
lst++;

// handle buzzer
Expand All @@ -123,9 +111,10 @@ IRAM_ATTR ISR(TIMER1_COMPA_vect)
timerSuper();
#endif

#ifdef ESP32
portEXIT_CRITICAL_ISR(&siderealTimerMux);
#endif
done: {}
#ifdef HAL_TIMER1_SUFFIX
HAL_TIMER1_SUFFIX;
#endif
}

void timerSuper() {
Expand Down Expand Up @@ -248,22 +237,11 @@ void timerSuper() {

IRAM_ATTR ISR(TIMER3_COMPA_vect)
{
#ifdef HAL_TIMER3_INT_CLEAR
HAL_TIMER3_INT_CLEAR;
#endif
#ifdef ESP32
portENTER_CRITICAL_ISR(&motorTimerMux);
#ifdef HAL_TIMER3_PREFIX
HAL_TIMER3_PREFIX;
#endif

if (!fastAxis1) {
t3cnt++;
if (t3cnt%t3rep!=0) {
#ifdef ESP32
portEXIT_CRITICAL_ISR(&motorTimerMux);
#endif
return;
}
}
if (!fastAxis1) { t3cnt++; if (t3cnt%t3rep!=0) goto done; }

StepPinAxis1_LOW;

Expand Down Expand Up @@ -325,29 +303,19 @@ IRAM_ATTR ISR(TIMER3_COMPA_vect)
}
#endif

#ifdef ESP32
portEXIT_CRITICAL_ISR(&motorTimerMux);
done: {}
#ifdef HAL_TIMER3_SUFFIX
HAL_TIMER3_SUFFIX;
#endif
}

IRAM_ATTR ISR(TIMER4_COMPA_vect)
{
#ifdef HAL_TIMER4_INT_CLEAR
HAL_TIMER4_INT_CLEAR;
#endif
#ifdef ESP32
portENTER_CRITICAL_ISR(&motorTimerMux);
#ifdef HAL_TIMER4_PREFIX
HAL_TIMER4_PREFIX;
#endif

if (!fastAxis2) {
t4cnt++;
if (t4cnt%t4rep!=0) {
#ifdef ESP32
portEXIT_CRITICAL_ISR(&motorTimerMux);
#endif
return;
}
}
if (!fastAxis2) { t4cnt++; if (t4cnt%t4rep!=0) goto done; }

StepPinAxis2_LOW;

Expand Down Expand Up @@ -409,8 +377,9 @@ IRAM_ATTR ISR(TIMER4_COMPA_vect)
}
#endif

#ifdef ESP32
portEXIT_CRITICAL_ISR(&motorTimerMux);
done: {}
#ifdef HAL_TIMER4_SUFFIX
HAL_TIMER4_SUFFIX;
#endif
}

Expand Down Expand Up @@ -453,4 +422,3 @@ void clockSync() {
PPSlastMicroS=t;
}
#endif

8 changes: 7 additions & 1 deletion src/HAL/HAL_ESP32/HAL_ESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ void TIMER4_COMPA_vect(void);
portMUX_TYPE siderealTimerMux = portMUX_INITIALIZER_UNLOCKED;
portMUX_TYPE motorTimerMux = portMUX_INITIALIZER_UNLOCKED;

#define HAL_TIMER1_PREFIX portENTER_CRITICAL_ISR( &siderealTimerMux )
#define HAL_TIMER3_PREFIX portENTER_CRITICAL_ISR( &motorTimerMux )
#define HAL_TIMER4_PREFIX portENTER_CRITICAL_ISR( &motorTimerMux )
#define HAL_TIMER1_SUFFIX portEXIT_CRITICAL_ISR( &siderealTimerMux )
#define HAL_TIMER3_SUFFIX portEXIT_CRITICAL_ISR( &motorTimerMux )
#define HAL_TIMER4_SUFFIX portEXIT_CRITICAL_ISR( &motorTimerMux )

// Override cli/sei and use for muxes
#undef cli
IRAM_ATTR void cli() { portENTER_CRITICAL(&motorTimerMux); portENTER_CRITICAL(&siderealTimerMux); }
Expand Down Expand Up @@ -140,4 +147,3 @@ IRAM_ATTR void QuickSetIntervalAxis2(uint32_t r) {
#define StepPinAxis2_LOW digitalWrite(Axis2StepPin, LOW)
#define DirPinAxis2_HIGH digitalWrite(Axis2DirPin, HIGH)
#define DirPinAxis2_LOW digitalWrite(Axis2DirPin, LOW)

7 changes: 3 additions & 4 deletions src/HAL/HAL_Tiva_C/HAL_Tiva_C.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
// Interrupts
#define cli() noInterrupts()
#define sei() interrupts()
#define HAL_TIMER1_INT_CLEAR TimerIntClear( Timer1_base, TIMER_TIMA_TIMEOUT )
#define HAL_TIMER3_INT_CLEAR TimerIntClear( Timer3_base, TIMER_TIMA_TIMEOUT )
#define HAL_TIMER4_INT_CLEAR TimerIntClear( Timer4_base, TIMER_TIMA_TIMEOUT )
#define HAL_TIMER1_PREFIX TimerIntClear( Timer1_base, TIMER_TIMA_TIMEOUT )
#define HAL_TIMER3_PREFIX TimerIntClear( Timer3_base, TIMER_TIMA_TIMEOUT )
#define HAL_TIMER4_PREFIX TimerIntClear( Timer4_base, TIMER_TIMA_TIMEOUT )

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

0 comments on commit 553b078

Please sign in to comment.