Convert maths macros to inlines
For parity with #10728 Co-Authored-By: ejtagle <ejtagle@hotmail.com>
This commit is contained in:
parent
431a81fc66
commit
7c6dd087c9
@ -243,59 +243,63 @@ volatile int32_t Stepper::endstops_trigsteps[XYZ];
|
|||||||
|
|
||||||
// intRes = longIn1 * longIn2 >> 24
|
// intRes = longIn1 * longIn2 >> 24
|
||||||
// uses:
|
// uses:
|
||||||
// r26 to store 0
|
// A[tmp] to store 0
|
||||||
// r27 to store bits 16-23 of the 48bit result. The top bit is used to round the two byte result.
|
// B[tmp] to store bits 16-23 of the 48bit result. The top bit is used to round the two byte result.
|
||||||
// note that the lower two bytes and the upper byte of the 48bit result are not calculated.
|
// note that the lower two bytes and the upper byte of the 48bit result are not calculated.
|
||||||
// this can cause the result to be out by one as the lower bytes may cause carries into the upper ones.
|
// this can cause the result to be out by one as the lower bytes may cause carries into the upper ones.
|
||||||
// B0 A0 are bits 24-39 and are the returned value
|
// B A are bits 24-39 and are the returned value
|
||||||
// C1 B1 A1 is longIn1
|
// C B A is longIn1
|
||||||
// D2 C2 B2 A2 is longIn2
|
// D C B A is longIn2
|
||||||
//
|
//
|
||||||
#define MultiU24X32toH16(intRes, longIn1, longIn2) \
|
static FORCE_INLINE uint16_t MultiU24X32toH16(uint32_t longIn1, uint32_t longIn2) {
|
||||||
asm volatile ( \
|
register uint8_t tmp1;
|
||||||
A("clr r26") \
|
register uint8_t tmp2;
|
||||||
A("mul %A1, %B2") \
|
register uint16_t intRes;
|
||||||
A("mov r27, r1") \
|
__asm__ __volatile__(
|
||||||
A("mul %B1, %C2") \
|
A("clr %[tmp1]")
|
||||||
A("movw %A0, r0") \
|
A("mul %A[longIn1], %B[longIn2]")
|
||||||
A("mul %C1, %C2") \
|
A("mov %[tmp2], r1")
|
||||||
A("add %B0, r0") \
|
A("mul %B[longIn1], %C[longIn2]")
|
||||||
A("mul %C1, %B2") \
|
A("movw %A[intRes], r0")
|
||||||
A("add %A0, r0") \
|
A("mul %C[longIn1], %C[longIn2]")
|
||||||
A("adc %B0, r1") \
|
A("add %B[intRes], r0")
|
||||||
A("mul %A1, %C2") \
|
A("mul %C[longIn1], %B[longIn2]")
|
||||||
A("add r27, r0") \
|
A("add %A[intRes], r0")
|
||||||
A("adc %A0, r1") \
|
A("adc %B[intRes], r1")
|
||||||
A("adc %B0, r26") \
|
A("mul %A[longIn1], %C[longIn2]")
|
||||||
A("mul %B1, %B2") \
|
A("add %[tmp2], r0")
|
||||||
A("add r27, r0") \
|
A("adc %A[intRes], r1")
|
||||||
A("adc %A0, r1") \
|
A("adc %B[intRes], %[tmp1]")
|
||||||
A("adc %B0, r26") \
|
A("mul %B[longIn1], %B[longIn2]")
|
||||||
A("mul %C1, %A2") \
|
A("add %[tmp2], r0")
|
||||||
A("add r27, r0") \
|
A("adc %A[intRes], r1")
|
||||||
A("adc %A0, r1") \
|
A("adc %B[intRes], %[tmp1]")
|
||||||
A("adc %B0, r26") \
|
A("mul %C[longIn1], %A[longIn2]")
|
||||||
A("mul %B1, %A2") \
|
A("add %[tmp2], r0")
|
||||||
A("add r27, r1") \
|
A("adc %A[intRes], r1")
|
||||||
A("adc %A0, r26") \
|
A("adc %B[intRes], %[tmp1]")
|
||||||
A("adc %B0, r26") \
|
A("mul %B[longIn1], %A[longIn2]")
|
||||||
A("lsr r27") \
|
A("add %[tmp2], r1")
|
||||||
A("adc %A0, r26") \
|
A("adc %A[intRes], %[tmp1]")
|
||||||
A("adc %B0, r26") \
|
A("adc %B[intRes], %[tmp1]")
|
||||||
A("mul %D2, %A1") \
|
A("lsr %[tmp2]")
|
||||||
A("add %A0, r0") \
|
A("adc %A[intRes], %[tmp1]")
|
||||||
A("adc %B0, r1") \
|
A("adc %B[intRes], %[tmp1]")
|
||||||
A("mul %D2, %B1") \
|
A("mul %D[longIn2], %A[longIn1]")
|
||||||
A("add %B0, r0") \
|
A("add %A[intRes], r0")
|
||||||
A("clr r1") \
|
A("adc %B[intRes], r1")
|
||||||
: \
|
A("mul %D[longIn2], %B[longIn1]")
|
||||||
"=&r" (intRes) \
|
A("add %B[intRes], r0")
|
||||||
: \
|
A("clr r1")
|
||||||
"d" (longIn1), \
|
: [intRes] "=&r" (intRes),
|
||||||
"d" (longIn2) \
|
[tmp1] "=&r" (tmp1),
|
||||||
: \
|
[tmp2] "=&r" (tmp2)
|
||||||
"r26" , "r27" \
|
: [longIn1] "d" (longIn1),
|
||||||
)
|
[longIn2] "d" (longIn2)
|
||||||
|
: "cc"
|
||||||
|
);
|
||||||
|
return intRes;
|
||||||
|
}
|
||||||
|
|
||||||
// Some useful constants
|
// Some useful constants
|
||||||
|
|
||||||
@ -1506,10 +1510,7 @@ void Stepper::isr() {
|
|||||||
? _eval_bezier_curve(acceleration_time)
|
? _eval_bezier_curve(acceleration_time)
|
||||||
: current_block->cruise_rate;
|
: current_block->cruise_rate;
|
||||||
#else
|
#else
|
||||||
MultiU24X32toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
|
acc_step_rate = MultiU24X32toH16(acceleration_time, current_block->acceleration_rate) + current_block->initial_rate;
|
||||||
acc_step_rate += current_block->initial_rate;
|
|
||||||
|
|
||||||
// upper limit
|
|
||||||
NOMORE(acc_step_rate, current_block->nominal_rate);
|
NOMORE(acc_step_rate, current_block->nominal_rate);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1540,7 +1541,6 @@ void Stepper::isr() {
|
|||||||
#if ENABLED(BEZIER_JERK_CONTROL)
|
#if ENABLED(BEZIER_JERK_CONTROL)
|
||||||
// If this is the 1st time we process the 2nd half of the trapezoid...
|
// If this is the 1st time we process the 2nd half of the trapezoid...
|
||||||
if (!bezier_2nd_half) {
|
if (!bezier_2nd_half) {
|
||||||
|
|
||||||
// Initialize the Bézier speed curve
|
// Initialize the Bézier speed curve
|
||||||
_calc_bezier_curve_coeffs(current_block->cruise_rate, current_block->final_rate, current_block->deceleration_time_inverse);
|
_calc_bezier_curve_coeffs(current_block->cruise_rate, current_block->final_rate, current_block->deceleration_time_inverse);
|
||||||
bezier_2nd_half = true;
|
bezier_2nd_half = true;
|
||||||
@ -1553,14 +1553,14 @@ void Stepper::isr() {
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
// Using the old trapezoidal control
|
// Using the old trapezoidal control
|
||||||
MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
|
step_rate = MultiU24X32toH16(deceleration_time, current_block->acceleration_rate);
|
||||||
|
|
||||||
if (step_rate < acc_step_rate) { // Still decelerating?
|
if (step_rate < acc_step_rate) { // Still decelerating?
|
||||||
step_rate = acc_step_rate - step_rate;
|
step_rate = acc_step_rate - step_rate;
|
||||||
NOLESS(step_rate, current_block->final_rate);
|
NOLESS(step_rate, current_block->final_rate);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
step_rate = current_block->final_rate;
|
step_rate = current_block->final_rate;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// step_rate to timer interval
|
// step_rate to timer interval
|
||||||
|
@ -61,26 +61,28 @@ extern Stepper stepper;
|
|||||||
// uses:
|
// uses:
|
||||||
// r26 to store 0
|
// r26 to store 0
|
||||||
// r27 to store the byte 1 of the 24 bit result
|
// r27 to store the byte 1 of the 24 bit result
|
||||||
#define MultiU16X8toH16(intRes, charIn1, intIn2) \
|
static FORCE_INLINE uint16_t MultiU16X8toH16(uint8_t charIn1, uint16_t intIn2) {
|
||||||
asm volatile ( \
|
register uint8_t tmp;
|
||||||
A("clr r26") \
|
register uint16_t intRes;
|
||||||
A("mul %A1, %B2") \
|
__asm__ __volatile__ (
|
||||||
A("movw %A0, r0") \
|
A("clr %[tmp]")
|
||||||
A("mul %A1, %A2") \
|
A("mul %[charIn1], %B[intIn2]")
|
||||||
A("add %A0, r1") \
|
A("movw %A[intRes], r0")
|
||||||
A("adc %B0, r26") \
|
A("mul %[charIn1], %A[intIn2]")
|
||||||
A("lsr r0") \
|
A("add %A[intRes], r1")
|
||||||
A("adc %A0, r26") \
|
A("adc %B[intRes], %[tmp]")
|
||||||
A("adc %B0, r26") \
|
A("lsr r0")
|
||||||
A("clr r1") \
|
A("adc %A[intRes], %[tmp]")
|
||||||
: \
|
A("adc %B[intRes], %[tmp]")
|
||||||
"=&r" (intRes) \
|
A("clr r1")
|
||||||
: \
|
: [intRes] "=&r" (intRes),
|
||||||
"d" (charIn1), \
|
[tmp] "=&r" (tmp)
|
||||||
"d" (intIn2) \
|
: [charIn1] "d" (charIn1),
|
||||||
: \
|
[intIn2] "d" (intIn2)
|
||||||
"r26" \
|
: "cc"
|
||||||
)
|
);
|
||||||
|
return intRes;
|
||||||
|
}
|
||||||
|
|
||||||
class Stepper {
|
class Stepper {
|
||||||
|
|
||||||
@ -346,17 +348,15 @@ class Stepper {
|
|||||||
NOLESS(step_rate, F_CPU / 500000);
|
NOLESS(step_rate, F_CPU / 500000);
|
||||||
step_rate -= F_CPU / 500000; // Correct for minimal speed
|
step_rate -= F_CPU / 500000; // Correct for minimal speed
|
||||||
if (step_rate >= (8 * 256)) { // higher step rate
|
if (step_rate >= (8 * 256)) { // higher step rate
|
||||||
unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate >> 8)][0];
|
uint16_t table_address = (uint16_t)&speed_lookuptable_fast[(uint8_t)(step_rate >> 8)][0],
|
||||||
unsigned char tmp_step_rate = (step_rate & 0x00FF);
|
gain = (uint16_t)pgm_read_word_near(table_address + 2);
|
||||||
unsigned short gain = (unsigned short)pgm_read_word_near(table_address + 2);
|
timer = (uint16_t)pgm_read_word_near(table_address) - MultiU16X8toH16(step_rate & 0x00FF, gain);
|
||||||
MultiU16X8toH16(timer, tmp_step_rate, gain);
|
|
||||||
timer = (unsigned short)pgm_read_word_near(table_address) - timer;
|
|
||||||
}
|
}
|
||||||
else { // lower step rates
|
else { // lower step rates
|
||||||
unsigned short table_address = (unsigned short)&speed_lookuptable_slow[0][0];
|
uint16_t table_address = (uint16_t)&speed_lookuptable_slow[0][0];
|
||||||
table_address += ((step_rate) >> 1) & 0xFFFC;
|
table_address += ((step_rate) >> 1) & 0xFFFC;
|
||||||
timer = (unsigned short)pgm_read_word_near(table_address);
|
timer = (uint16_t)pgm_read_word_near(table_address)
|
||||||
timer -= (((unsigned short)pgm_read_word_near(table_address + 2) * (unsigned char)(step_rate & 0x0007)) >> 3);
|
- (((uint16_t)pgm_read_word_near(table_address + 2) * (uint8_t)(step_rate & 0x0007)) >> 3);
|
||||||
}
|
}
|
||||||
if (timer < 100) { // (20kHz - this should never happen)
|
if (timer < 100) { // (20kHz - this should never happen)
|
||||||
timer = 100;
|
timer = 100;
|
||||||
|
Loading…
Reference in New Issue
Block a user