Skip to content

Commit

Permalink
replace critical driverlib methods with HWREG alternative for sake of…
Browse files Browse the repository at this point in the history
… time spent in ISR
  • Loading branch information
sq7bti committed Aug 28, 2014
1 parent fce2db2 commit f78042a
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions iAccelStepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ static unsigned int all_instances;
static unsigned long ulPeriod;

void iAccelStepper::ISR(void) {
TimerIntClear(g_ulTIMERBase[id], TIMER_TIMA_TIMEOUT);
//TimerIntClear(g_ulTIMERBase[id], TIMER_TIMA_TIMEOUT);
HWREG(g_ulTIMERBase[id] + TIMER_O_ICR) = TIMER_TIMA_TIMEOUT;

// falling edge produce space for length _stepInterval
if(_state[id]) {
_state[id] = false;
HWREG(_port_step[id]) = 0;
TimerLoadSet(g_ulTIMERBase[id], TIMER_A, _stepInterval - ulPeriod);
TimerEnable(g_ulTIMERBase[id], TIMER_A);
//TimerLoadSet(g_ulTIMERBase[id], TIMER_A, _stepInterval - ulPeriod);
HWREG(g_ulTIMERBase[id] + TIMER_O_TAILR) = _stepInterval - ulPeriod;
//TimerEnable(g_ulTIMERBase[id], TIMER_A);
HWREG(g_ulTIMERBase[id] + TIMER_O_CTL) |= TIMER_A & (TIMER_CTL_TAEN | TIMER_CTL_TBEN);
} else {
// prepare for the next period
// rising edge - calculate everything necessary and calculate _stepInterval
Expand All @@ -35,7 +38,8 @@ void iAccelStepper::ISR(void) {

// either fire the timer again for another period or switch it off when the move is finished
if((_stepInterval == 0) || (abs(distanceToGo()) < 1)) {
TimerDisable(g_ulTIMERBase[id], TIMER_A);
//TimerDisable(g_ulTIMERBase[id], TIMER_A);
HWREG(g_ulTIMERBase[id] + TIMER_O_CTL) &= ~(TIMER_A & (TIMER_CTL_TAEN | TIMER_CTL_TBEN));
running = false;
} else {
_state[id] = true;
Expand All @@ -44,8 +48,10 @@ void iAccelStepper::ISR(void) {
direction[id] = _direction;
HWREG(_port_dir[id]) = _direction?_pin_dir[id]:0;
}
TimerLoadSet(g_ulTIMERBase[id], TIMER_A, ulPeriod);
TimerEnable(g_ulTIMERBase[id], TIMER_A);
//TimerLoadSet(g_ulTIMERBase[id], TIMER_A, ulPeriod);
HWREG(g_ulTIMERBase[id] + TIMER_O_TAILR) = ulPeriod;
//TimerEnable(g_ulTIMERBase[id], TIMER_A);
HWREG(g_ulTIMERBase[id] + TIMER_O_CTL) |= TIMER_A & (TIMER_CTL_TAEN | TIMER_CTL_TBEN);
}
}
}
Expand Down Expand Up @@ -122,7 +128,9 @@ void iAccelStepper::moveTo(long absolute)
HWREG(_port_step[id]) = _pin_step[id];
_state[id] = true;

TimerLoadSet(g_ulTIMERBase[id], TIMER_A, ulPeriod);
TimerEnable(g_ulTIMERBase[id], TIMER_A);
//TimerLoadSet(g_ulTIMERBase[id], TIMER_A, ulPeriod);
HWREG(g_ulTIMERBase[id] + TIMER_O_TAILR) = ulPeriod;
//TimerEnable(g_ulTIMERBase[id], TIMER_A);
HWREG(g_ulTIMERBase[id] + TIMER_O_CTL) |= TIMER_A & (TIMER_CTL_TAEN | TIMER_CTL_TBEN);
}
}

0 comments on commit f78042a

Please sign in to comment.