Skip to content

Commit

Permalink
run format_code.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
gin66 committed May 1, 2024
1 parent 62c648c commit 56df459
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 79 deletions.
5 changes: 3 additions & 2 deletions src/FastAccelStepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ void FastAccelStepper::fill_queue() {
bool need_delayed_start = false;
uint32_t ticksPrepared = q->ticksInQueue();
while (!isQueueFull() &&
((ticksPrepared < _forward_planning_in_ticks) || q->queueEntries() <= 1) &&
((ticksPrepared < _forward_planning_in_ticks) ||
q->queueEntries() <= 1) &&
_rg.isRampGeneratorActive()) {
#if (TEST_MEASURE_ISR_SINGLE_FILL == 1)
// For run time measurement
Expand Down Expand Up @@ -509,7 +510,7 @@ void FastAccelStepper::init(FastAccelStepperEngine* engine, uint8_t num,
_dirPin = PIN_UNDEFINED;
_enablePinHighActive = PIN_UNDEFINED;
_enablePinLowActive = PIN_UNDEFINED;
_forward_planning_in_ticks = TICKS_PER_S/50;
_forward_planning_in_ticks = TICKS_PER_S / 50;
_rg.init();

_queue_num = num;
Expand Down
24 changes: 13 additions & 11 deletions src/FastAccelStepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -542,27 +542,29 @@ class FastAccelStepper {
// The stepper task is cyclically executed every ~4ms.
// Especially for avr, the step interrupts puts a significant load on the uC,
// so the cyclical stepper task can even run for 2-3 ms. On top of that,
// other interrupts caused by the application could increase the load even further.
// other interrupts caused by the application could increase the load even
// further.
//
// Consequently, the forward planning should fill the queue for ideally two cycles,
// this means 8ms. This means, the default 20ms provide a sufficient margin and
// even a missed cycle is not an issue.
// Consequently, the forward planning should fill the queue for ideally two
// cycles, this means 8ms. This means, the default 20ms provide a sufficient
// margin and even a missed cycle is not an issue.
//
// The drawback of the 20ms is, that any change in speed/acceleration are added after
// those 20ms and for an application, requiring fast reaction times, this may
// impact the expected performance.
// The drawback of the 20ms is, that any change in speed/acceleration are
// added after those 20ms and for an application, requiring fast reaction
// times, this may impact the expected performance.
//
// Due to this the forward planning time can be adjusted with the following API call
// for each stepper individually.
// Due to this the forward planning time can be adjusted with the following
// API call for each stepper individually.
//
// Attention:
// - This is only for advanced users: no error checking is implemented.
// - Only change the forward planning time, if the stepper is not running.
// - Too small values bear the risk of a stepper running at full speed suddenly stopping
// - Too small values bear the risk of a stepper running at full speed
// suddenly stopping
// due to lack of commands in the queue.
inline void setForwardPlanningTimeInMs(uint8_t ms) {
_forward_planning_in_ticks = ms;
_forward_planning_in_ticks *= TICKS_PER_S / 1000; // ticks per ms
_forward_planning_in_ticks *= TICKS_PER_S / 1000; // ticks per ms
}

// ## Low Level Stepper Queue Management (low level access)
Expand Down
8 changes: 3 additions & 5 deletions src/StepperISR.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,9 @@ class StepperQueue {
}
#endif
}
#if SUPPORT_UNSAFE_ABS_SPEED_LIMIT_SETTING == 1
void setAbsoluteSpeedLimit(uint16_t ticks) {
max_speed_in_ticks = ticks;
}
#endif
#if SUPPORT_UNSAFE_ABS_SPEED_LIMIT_SETTING == 1
void setAbsoluteSpeedLimit(uint16_t ticks) { max_speed_in_ticks = ticks; }
#endif
void adjustSpeedToStepperCount(uint8_t steppers);
static bool isValidStepPin(uint8_t step_pin);
static int8_t queueNumForStepPin(uint8_t step_pin);
Expand Down
123 changes: 62 additions & 61 deletions src/StepperISR_avr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
#define Stepper_Zero(T, X) \
TCCR##T##A = (TCCR##T##A | _BV(COM##T##X##1)) & ~_BV(COM##T##X##0)
// Force compare of Stepper_Toggle appears to be broken in simavr
// In other words, use of Stepper_Toggle yields errors in simavr, for which root cause is unclear
// In other words, use of Stepper_Toggle yields errors in simavr, for which root
// cause is unclear
#ifdef DISABLE
#define Stepper_Toggle(T, X) \
TCCR##T##A = (TCCR##T##A | _BV(COM##T##X##0)) & ~_BV(COM##T##X##1)
TCCR##T##A = (TCCR##T##A | _BV(COM##T##X##0)) & ~_BV(COM##T##X##1)
#endif
#define Stepper_One(T, X) TCCR##T##A |= _BV(COM##T##X##1) | _BV(COM##T##X##0)
#define Stepper_Disconnect(T, X) \
Expand Down Expand Up @@ -136,65 +137,65 @@ void StepperQueue::init(uint8_t queue_num, uint8_t step_pin) {
// Remark: Interrupt Flag is automatically cleared on ISR execution
//
// If reaching here without further commands, then the queue is done
#define AVR_STEPPER_ISR(T, CHANNEL) \
ISR(TIMER##T##_COMP##CHANNEL##_vect) { \
enterStepperISR(); \
uint8_t rp = fas_queue_##CHANNEL.read_idx; \
uint8_t wp = fas_queue_##CHANNEL.next_write_idx; \
if (rp == wp) { \
/* queue is empty => set to disconnect */ \
/* disable compare interrupt */ \
DisableCompareInterrupt(T, CHANNEL); \
Stepper_Disconnect(T, CHANNEL); \
/* force compare to ensure disconnect */ \
ForceCompare(T, CHANNEL); \
fas_queue_##CHANNEL._isRunning = false; \
fas_queue_##CHANNEL._noMoreCommands = false; \
exitStepperISR(); \
return; \
} \
struct queue_entry* e = &fas_queue_##CHANNEL.entry[rp & QUEUE_LEN_MASK]; \
/* There is a risk, that this new compare time is delayed by one cycle */ \
uint16_t ticks = e->ticks; \
/* Set output to zero, this works in any case. In case of pause: no-op */ \
Stepper_Zero(T, CHANNEL); \
ForceCompare(T, CHANNEL); \
if (e->steps > 1) { \
/* perform another step with this queue entry */ \
e->steps--; \
Stepper_One(T, CHANNEL); \
} else { \
/* either pause command or no more steps */ \
if (fas_queue_##CHANNEL._noMoreCommands) { \
/* new command received after running out of commands */ \
/* if this new command requires a step, then this step would be lost */ \
fas_queue_##CHANNEL._noMoreCommands = false; \
if (e->steps != 0) { \
/* New command needs steps, so do it immediately */ \
ticks = 10; \
} \
} \
else if (TEST_NOT_REPEATING_ENTRY) { \
rp++; \
fas_queue_##CHANNEL.read_idx = rp; \
if (rp == wp) { \
/* queue is empty, wait this command to complete, then disconnect */ \
fas_queue_##CHANNEL._noMoreCommands = true; \
OCR##T##CHANNEL += ticks; \
exitStepperISR(); \
return; \
} \
e = &fas_queue_##CHANNEL.entry[rp & QUEUE_LEN_MASK]; \
} \
if (e->toggle_dir) { \
Stepper_ToggleDirection(CHANNEL); \
} \
if (e->steps != 0) { \
Stepper_One(T, CHANNEL); \
} \
} \
OCR##T##CHANNEL += ticks; \
exitStepperISR(); \
#define AVR_STEPPER_ISR(T, CHANNEL) \
ISR(TIMER##T##_COMP##CHANNEL##_vect) { \
enterStepperISR(); \
uint8_t rp = fas_queue_##CHANNEL.read_idx; \
uint8_t wp = fas_queue_##CHANNEL.next_write_idx; \
if (rp == wp) { \
/* queue is empty => set to disconnect */ \
/* disable compare interrupt */ \
DisableCompareInterrupt(T, CHANNEL); \
Stepper_Disconnect(T, CHANNEL); \
/* force compare to ensure disconnect */ \
ForceCompare(T, CHANNEL); \
fas_queue_##CHANNEL._isRunning = false; \
fas_queue_##CHANNEL._noMoreCommands = false; \
exitStepperISR(); \
return; \
} \
struct queue_entry* e = &fas_queue_##CHANNEL.entry[rp & QUEUE_LEN_MASK]; \
/* There is a risk, that this new compare time is delayed by one cycle */ \
uint16_t ticks = e->ticks; \
/* Set output to zero, this works in any case. In case of pause: no-op */ \
Stepper_Zero(T, CHANNEL); \
ForceCompare(T, CHANNEL); \
if (e->steps > 1) { \
/* perform another step with this queue entry */ \
e->steps--; \
Stepper_One(T, CHANNEL); \
} else { \
/* either pause command or no more steps */ \
if (fas_queue_##CHANNEL._noMoreCommands) { \
/* new command received after running out of commands */ \
/* if this new command requires a step, then this step would be lost \
*/ \
fas_queue_##CHANNEL._noMoreCommands = false; \
if (e->steps != 0) { \
/* New command needs steps, so do it immediately */ \
ticks = 10; \
} \
} else if (TEST_NOT_REPEATING_ENTRY) { \
rp++; \
fas_queue_##CHANNEL.read_idx = rp; \
if (rp == wp) { \
/* queue is empty, wait this command to complete, then disconnect */ \
fas_queue_##CHANNEL._noMoreCommands = true; \
OCR##T##CHANNEL += ticks; \
exitStepperISR(); \
return; \
} \
e = &fas_queue_##CHANNEL.entry[rp & QUEUE_LEN_MASK]; \
} \
if (e->toggle_dir) { \
Stepper_ToggleDirection(CHANNEL); \
} \
if (e->steps != 0) { \
Stepper_One(T, CHANNEL); \
} \
} \
OCR##T##CHANNEL += ticks; \
exitStepperISR(); \
}

#define AVR_STEPPER_ISR_GEN(T, CHANNEL) AVR_STEPPER_ISR(T, CHANNEL)
Expand Down

0 comments on commit 56df459

Please sign in to comment.