|
@@ -203,11 +203,8 @@ uint32_t Stepper::advance_divisor = 0,
|
203
|
203
|
bool Stepper::bezier_2nd_half; // =false If Bézier curve has been initialized or not
|
204
|
204
|
#endif
|
205
|
205
|
|
206
|
|
-uint32_t Stepper::nextMainISR = 0;
|
207
|
|
-
|
208
|
206
|
#if ENABLED(LIN_ADVANCE)
|
209
|
207
|
|
210
|
|
- constexpr uint32_t LA_ADV_NEVER = 0xFFFFFFFF;
|
211
|
208
|
uint32_t Stepper::nextAdvanceISR = LA_ADV_NEVER,
|
212
|
209
|
Stepper::LA_isr_rate = LA_ADV_NEVER;
|
213
|
210
|
uint16_t Stepper::LA_current_adv_steps = 0,
|
|
@@ -402,13 +399,13 @@ constexpr uint32_t NS_TO_PULSE_TIMER_TICKS(uint32_t NS) { return (NS + (NS_PER_P
|
402
|
399
|
#define PULSE_HIGH_TICK_COUNT hal_timer_t(NS_TO_PULSE_TIMER_TICKS(_MIN_PULSE_HIGH_NS - _MIN(_MIN_PULSE_HIGH_NS, TIMER_SETUP_NS)))
|
403
|
400
|
#define PULSE_LOW_TICK_COUNT hal_timer_t(NS_TO_PULSE_TIMER_TICKS(_MIN_PULSE_LOW_NS - _MIN(_MIN_PULSE_LOW_NS, TIMER_SETUP_NS)))
|
404
|
401
|
|
405
|
|
-#define USING_TIMED_PULSE() hal_timer_t end_tick_count = 0
|
406
|
|
-#define START_TIMED_PULSE(DIR) (end_tick_count = HAL_timer_get_count(PULSE_TIMER_NUM) + PULSE_##DIR##_TICK_COUNT)
|
407
|
|
-#define AWAIT_TIMED_PULSE() while (HAL_timer_get_count(PULSE_TIMER_NUM) < end_tick_count) { }
|
|
402
|
+#define USING_TIMED_PULSE() hal_timer_t start_pulse_count = 0
|
|
403
|
+#define START_TIMED_PULSE(DIR) (start_pulse_count = HAL_timer_get_count(PULSE_TIMER_NUM))
|
|
404
|
+#define AWAIT_TIMED_PULSE(DIR) while (PULSE_##DIR##_TICK_COUNT > HAL_timer_get_count(PULSE_TIMER_NUM) - start_pulse_count) { }
|
408
|
405
|
#define START_HIGH_PULSE() START_TIMED_PULSE(HIGH)
|
|
406
|
+#define AWAIT_HIGH_PULSE() AWAIT_TIMED_PULSE(HIGH)
|
409
|
407
|
#define START_LOW_PULSE() START_TIMED_PULSE(LOW)
|
410
|
|
-#define AWAIT_HIGH_PULSE() AWAIT_TIMED_PULSE()
|
411
|
|
-#define AWAIT_LOW_PULSE() AWAIT_TIMED_PULSE()
|
|
408
|
+#define AWAIT_LOW_PULSE() AWAIT_TIMED_PULSE(LOW)
|
412
|
409
|
|
413
|
410
|
#if MINIMUM_STEPPER_PRE_DIR_DELAY > 0
|
414
|
411
|
#define DIR_WAIT_BEFORE() DELAY_NS(MINIMUM_STEPPER_PRE_DIR_DELAY)
|
|
@@ -422,11 +419,6 @@ constexpr uint32_t NS_TO_PULSE_TIMER_TICKS(uint32_t NS) { return (NS + (NS_PER_P
|
422
|
419
|
#define DIR_WAIT_AFTER()
|
423
|
420
|
#endif
|
424
|
421
|
|
425
|
|
-void Stepper::wake_up() {
|
426
|
|
- // TCNT1 = 0;
|
427
|
|
- ENABLE_STEPPER_DRIVER_INTERRUPT();
|
428
|
|
-}
|
429
|
|
-
|
430
|
422
|
/**
|
431
|
423
|
* Set the stepper direction of each axis
|
432
|
424
|
*
|
|
@@ -1334,6 +1326,9 @@ HAL_STEP_TIMER_ISR() {
|
1334
|
1326
|
#endif
|
1335
|
1327
|
|
1336
|
1328
|
void Stepper::isr() {
|
|
1329
|
+
|
|
1330
|
+ static uint32_t nextMainISR = 0; // Interval until the next main Stepper Pulse phase (0 = Now)
|
|
1331
|
+
|
1337
|
1332
|
#ifndef __AVR__
|
1338
|
1333
|
// Disable interrupts, to avoid ISR preemption while we reprogram the period
|
1339
|
1334
|
// (AVR enters the ISR with global interrupts disabled, so no need to do it here)
|
|
@@ -1357,35 +1352,35 @@ void Stepper::isr() {
|
1357
|
1352
|
// Enable ISRs to reduce USART processing latency
|
1358
|
1353
|
ENABLE_ISRS();
|
1359
|
1354
|
|
1360
|
|
- // Run main stepping pulse phase ISR if we have to
|
1361
|
|
- if (!nextMainISR) Stepper::stepper_pulse_phase_isr();
|
|
1355
|
+ if (!nextMainISR) pulse_phase_isr(); // 0 = Do coordinated axes Stepper pulses
|
1362
|
1356
|
|
1363
|
1357
|
#if ENABLED(LIN_ADVANCE)
|
1364
|
|
- // Run linear advance stepper ISR if we have to
|
1365
|
|
- if (!nextAdvanceISR) nextAdvanceISR = Stepper::advance_isr();
|
|
1358
|
+ if (!nextAdvanceISR) nextAdvanceISR = advance_isr(); // 0 = Do Linear Advance E Stepper pulses
|
1366
|
1359
|
#endif
|
1367
|
1360
|
|
1368
|
1361
|
// ^== Time critical. NOTHING besides pulse generation should be above here!!!
|
1369
|
1362
|
|
1370
|
|
- // Run main stepping block processing ISR if we have to
|
1371
|
|
- if (!nextMainISR) nextMainISR = Stepper::stepper_block_phase_isr();
|
|
1363
|
+ if (!nextMainISR) nextMainISR = block_phase_isr(); // Manage acc/deceleration, get next block
|
1372
|
1364
|
|
1373
|
|
- uint32_t interval =
|
|
1365
|
+ // Get the interval to the next ISR call
|
|
1366
|
+ const uint32_t interval = _MIN(
|
|
1367
|
+ nextMainISR // Time until the next Stepper ISR
|
1374
|
1368
|
#if ENABLED(LIN_ADVANCE)
|
1375
|
|
- _MIN(nextAdvanceISR, nextMainISR) // Nearest time interval
|
1376
|
|
- #else
|
1377
|
|
- nextMainISR // Remaining stepper ISR time
|
|
1369
|
+ , nextAdvanceISR // Come back early for Linear Advance?
|
1378
|
1370
|
#endif
|
1379
|
|
- ;
|
|
1371
|
+ , uint32_t(HAL_TIMER_TYPE_MAX) // Come back in a very long time
|
|
1372
|
+ );
|
1380
|
1373
|
|
1381
|
|
- // Limit the value to the maximum possible value of the timer
|
1382
|
|
- NOMORE(interval, uint32_t(HAL_TIMER_TYPE_MAX));
|
|
1374
|
+ //
|
|
1375
|
+ // Compute remaining time for each ISR phase
|
|
1376
|
+ // NEVER : The phase is idle
|
|
1377
|
+ // Zero : The phase will occur on the next ISR call
|
|
1378
|
+ // Non-zero : The phase will occur on a future ISR call
|
|
1379
|
+ //
|
1383
|
1380
|
|
1384
|
|
- // Compute the time remaining for the main isr
|
1385
|
1381
|
nextMainISR -= interval;
|
1386
|
1382
|
|
1387
|
1383
|
#if ENABLED(LIN_ADVANCE)
|
1388
|
|
- // Compute the time remaining for the advance isr
|
1389
|
1384
|
if (nextAdvanceISR != LA_ADV_NEVER) nextAdvanceISR -= interval;
|
1390
|
1385
|
#endif
|
1391
|
1386
|
|
|
@@ -1471,7 +1466,7 @@ void Stepper::isr() {
|
1471
|
1466
|
* call to this method that might cause variation in the timing. The aim
|
1472
|
1467
|
* is to keep pulse timing as regular as possible.
|
1473
|
1468
|
*/
|
1474
|
|
-void Stepper::stepper_pulse_phase_isr() {
|
|
1469
|
+void Stepper::pulse_phase_isr() {
|
1475
|
1470
|
|
1476
|
1471
|
// If we must abort the current block, do so!
|
1477
|
1472
|
if (abort_current_block) {
|
|
@@ -1548,7 +1543,7 @@ void Stepper::stepper_pulse_phase_isr() {
|
1548
|
1543
|
// Don't step E here - But remember the number of steps to perform
|
1549
|
1544
|
motor_direction(E_AXIS) ? --LA_steps : ++LA_steps;
|
1550
|
1545
|
#else
|
1551
|
|
- step_needed.e = delta_error.e >= 0;
|
|
1546
|
+ step_needed.e = true;
|
1552
|
1547
|
#endif
|
1553
|
1548
|
}
|
1554
|
1549
|
#elif HAS_E0_STEP
|
|
@@ -1604,20 +1599,14 @@ void Stepper::stepper_pulse_phase_isr() {
|
1604
|
1599
|
|
1605
|
1600
|
#if DISABLED(LIN_ADVANCE)
|
1606
|
1601
|
#if ENABLED(MIXING_EXTRUDER)
|
1607
|
|
-
|
1608
|
1602
|
if (delta_error.e >= 0) {
|
1609
|
1603
|
delta_error.e -= advance_divisor;
|
1610
|
1604
|
E_STEP_WRITE(mixer.get_stepper(), INVERT_E_STEP_PIN);
|
1611
|
1605
|
}
|
1612
|
|
-
|
1613
|
|
- #else // !MIXING_EXTRUDER
|
1614
|
|
-
|
1615
|
|
- #if HAS_E0_STEP
|
1616
|
|
- PULSE_STOP(E);
|
1617
|
|
- #endif
|
1618
|
|
-
|
1619
|
|
- #endif // !MIXING_EXTRUDER
|
1620
|
|
- #endif // !LIN_ADVANCE
|
|
1606
|
+ #elif HAS_E0_STEP
|
|
1607
|
+ PULSE_STOP(E);
|
|
1608
|
+ #endif
|
|
1609
|
+ #endif
|
1621
|
1610
|
|
1622
|
1611
|
#if ISR_MULTI_STEPS
|
1623
|
1612
|
if (events_to_do) START_LOW_PULSE();
|
|
@@ -1630,10 +1619,10 @@ void Stepper::stepper_pulse_phase_isr() {
|
1630
|
1619
|
// properly schedules blocks from the planner. This is executed after creating
|
1631
|
1620
|
// the step pulses, so it is not time critical, as pulses are already done.
|
1632
|
1621
|
|
1633
|
|
-uint32_t Stepper::stepper_block_phase_isr() {
|
|
1622
|
+uint32_t Stepper::block_phase_isr() {
|
1634
|
1623
|
|
1635
|
|
- // If no queued movements, just wait 1ms for the next move
|
1636
|
|
- uint32_t interval = (STEPPER_TIMER_RATE) / 1000;
|
|
1624
|
+ // If no queued movements, just wait 1ms for the next block
|
|
1625
|
+ uint32_t interval = (STEPPER_TIMER_RATE) / 1000UL;
|
1637
|
1626
|
|
1638
|
1627
|
// If there is a current block
|
1639
|
1628
|
if (current_block) {
|
|
@@ -1667,16 +1656,14 @@ uint32_t Stepper::stepper_block_phase_isr() {
|
1667
|
1656
|
// acc_step_rate is in steps/second
|
1668
|
1657
|
|
1669
|
1658
|
// step_rate to timer interval and steps per stepper isr
|
1670
|
|
- interval = calc_timer_interval(acc_step_rate, oversampling_factor, &steps_per_isr);
|
|
1659
|
+ interval = calc_timer_interval(acc_step_rate, &steps_per_isr);
|
1671
|
1660
|
acceleration_time += interval;
|
1672
|
1661
|
|
1673
|
1662
|
#if ENABLED(LIN_ADVANCE)
|
1674
|
|
- if (LA_use_advance_lead) {
|
1675
|
|
- // Fire ISR if final adv_rate is reached
|
1676
|
|
- if (LA_steps && LA_isr_rate != current_block->advance_speed) nextAdvanceISR = 0;
|
1677
|
|
- }
|
1678
|
|
- else if (LA_steps) nextAdvanceISR = 0;
|
1679
|
|
- #endif // LIN_ADVANCE
|
|
1663
|
+ // Fire ISR if final adv_rate is reached
|
|
1664
|
+ if (LA_steps && (!LA_use_advance_lead || LA_isr_rate != current_block->advance_speed))
|
|
1665
|
+ initiateLA();
|
|
1666
|
+ #endif
|
1680
|
1667
|
}
|
1681
|
1668
|
// Are we in Deceleration phase ?
|
1682
|
1669
|
else if (step_events_completed > decelerate_after) {
|
|
@@ -1712,32 +1699,32 @@ uint32_t Stepper::stepper_block_phase_isr() {
|
1712
|
1699
|
// step_rate is in steps/second
|
1713
|
1700
|
|
1714
|
1701
|
// step_rate to timer interval and steps per stepper isr
|
1715
|
|
- interval = calc_timer_interval(step_rate, oversampling_factor, &steps_per_isr);
|
|
1702
|
+ interval = calc_timer_interval(step_rate, &steps_per_isr);
|
1716
|
1703
|
deceleration_time += interval;
|
1717
|
1704
|
|
1718
|
1705
|
#if ENABLED(LIN_ADVANCE)
|
1719
|
1706
|
if (LA_use_advance_lead) {
|
1720
|
1707
|
// Wake up eISR on first deceleration loop and fire ISR if final adv_rate is reached
|
1721
|
1708
|
if (step_events_completed <= decelerate_after + steps_per_isr || (LA_steps && LA_isr_rate != current_block->advance_speed)) {
|
1722
|
|
- nextAdvanceISR = 0;
|
|
1709
|
+ initiateLA();
|
1723
|
1710
|
LA_isr_rate = current_block->advance_speed;
|
1724
|
1711
|
}
|
1725
|
1712
|
}
|
1726
|
|
- else if (LA_steps) nextAdvanceISR = 0;
|
1727
|
|
- #endif // LIN_ADVANCE
|
|
1713
|
+ else if (LA_steps) initiateLA();
|
|
1714
|
+ #endif
|
1728
|
1715
|
}
|
1729
|
1716
|
// We must be in cruise phase otherwise
|
1730
|
1717
|
else {
|
1731
|
1718
|
|
1732
|
1719
|
#if ENABLED(LIN_ADVANCE)
|
1733
|
1720
|
// If there are any esteps, fire the next advance_isr "now"
|
1734
|
|
- if (LA_steps && LA_isr_rate != current_block->advance_speed) nextAdvanceISR = 0;
|
|
1721
|
+ if (LA_steps && LA_isr_rate != current_block->advance_speed) initiateLA();
|
1735
|
1722
|
#endif
|
1736
|
1723
|
|
1737
|
1724
|
// Calculate the ticks_nominal for this nominal speed, if not done yet
|
1738
|
1725
|
if (ticks_nominal < 0) {
|
1739
|
1726
|
// step_rate to timer interval and loops for the nominal speed
|
1740
|
|
- ticks_nominal = calc_timer_interval(current_block->nominal_rate, oversampling_factor, &steps_per_isr);
|
|
1727
|
+ ticks_nominal = calc_timer_interval(current_block->nominal_rate, &steps_per_isr);
|
1741
|
1728
|
}
|
1742
|
1729
|
|
1743
|
1730
|
// The timer interval is just the nominal value for the nominal speed
|
|
@@ -1846,17 +1833,17 @@ uint32_t Stepper::stepper_block_phase_isr() {
|
1846
|
1833
|
// No acceleration / deceleration time elapsed so far
|
1847
|
1834
|
acceleration_time = deceleration_time = 0;
|
1848
|
1835
|
|
1849
|
|
- uint8_t oversampling = 0; // Assume we won't use it
|
|
1836
|
+ uint8_t oversampling = 0; // Assume no axis smoothing (via oversampling)
|
1850
|
1837
|
|
1851
|
1838
|
#if ENABLED(ADAPTIVE_STEP_SMOOTHING)
|
1852
|
|
- // At this point, we must decide if we can use Stepper movement axis smoothing.
|
|
1839
|
+ // Decide if axis smoothing is possible
|
1853
|
1840
|
uint32_t max_rate = current_block->nominal_rate; // Get the maximum rate (maximum event speed)
|
1854
|
|
- while (max_rate < MIN_STEP_ISR_FREQUENCY) {
|
1855
|
|
- max_rate <<= 1;
|
1856
|
|
- if (max_rate >= MAX_STEP_ISR_FREQUENCY_1X) break;
|
1857
|
|
- ++oversampling;
|
|
1841
|
+ while (max_rate < MIN_STEP_ISR_FREQUENCY) { // As long as more ISRs are possible...
|
|
1842
|
+ max_rate <<= 1; // Try to double the rate
|
|
1843
|
+ if (max_rate >= MAX_STEP_ISR_FREQUENCY_1X) break; // Don't exceed the estimated ISR limit
|
|
1844
|
+ ++oversampling; // Increase the oversampling (used for left-shift)
|
1858
|
1845
|
}
|
1859
|
|
- oversampling_factor = oversampling;
|
|
1846
|
+ oversampling_factor = oversampling; // For all timer interval calculations
|
1860
|
1847
|
#endif
|
1861
|
1848
|
|
1862
|
1849
|
// Based on the oversampling factor, do the calculations
|
|
@@ -1894,8 +1881,7 @@ uint32_t Stepper::stepper_block_phase_isr() {
|
1894
|
1881
|
if ((LA_use_advance_lead = current_block->use_advance_lead)) {
|
1895
|
1882
|
LA_final_adv_steps = current_block->final_adv_steps;
|
1896
|
1883
|
LA_max_adv_steps = current_block->max_adv_steps;
|
1897
|
|
- //Start the ISR
|
1898
|
|
- nextAdvanceISR = 0;
|
|
1884
|
+ initiateLA(); // Start the ISR
|
1899
|
1885
|
LA_isr_rate = current_block->advance_speed;
|
1900
|
1886
|
}
|
1901
|
1887
|
else LA_isr_rate = LA_ADV_NEVER;
|
|
@@ -1954,7 +1940,7 @@ uint32_t Stepper::stepper_block_phase_isr() {
|
1954
|
1940
|
#endif
|
1955
|
1941
|
|
1956
|
1942
|
// Calculate the initial timer interval
|
1957
|
|
- interval = calc_timer_interval(current_block->initial_rate, oversampling_factor, &steps_per_isr);
|
|
1943
|
+ interval = calc_timer_interval(current_block->initial_rate, &steps_per_isr);
|
1958
|
1944
|
}
|
1959
|
1945
|
}
|
1960
|
1946
|
|
|
@@ -2054,6 +2040,7 @@ uint32_t Stepper::stepper_block_phase_isr() {
|
2054
|
2040
|
|
2055
|
2041
|
return interval;
|
2056
|
2042
|
}
|
|
2043
|
+
|
2057
|
2044
|
#endif // LIN_ADVANCE
|
2058
|
2045
|
|
2059
|
2046
|
// Check if the given block is busy or not - Must not be called from ISR contexts
|
|
@@ -2093,7 +2080,7 @@ void Stepper::init() {
|
2093
|
2080
|
digipot_motor = 255 * (motor_current[i] / 2.5);
|
2094
|
2081
|
dac084s085::setValue(i, digipot_motor);
|
2095
|
2082
|
}
|
2096
|
|
- #endif//MB(ALLIGATOR)
|
|
2083
|
+ #endif
|
2097
|
2084
|
|
2098
|
2085
|
// Init Microstepping Pins
|
2099
|
2086
|
#if HAS_MICROSTEPS
|
|
@@ -2287,7 +2274,7 @@ void Stepper::init() {
|
2287
|
2274
|
|
2288
|
2275
|
#if DISABLED(I2S_STEPPER_STREAM)
|
2289
|
2276
|
HAL_timer_start(STEP_TIMER_NUM, 122); // Init Stepper ISR to 122 Hz for quick starting
|
2290
|
|
- ENABLE_STEPPER_DRIVER_INTERRUPT();
|
|
2277
|
+ wake_up();
|
2291
|
2278
|
sei();
|
2292
|
2279
|
#endif
|
2293
|
2280
|
|
|
@@ -2341,19 +2328,43 @@ int32_t Stepper::position(const AxisEnum axis) {
|
2341
|
2328
|
#ifdef __AVR__
|
2342
|
2329
|
// Protect the access to the position. Only required for AVR, as
|
2343
|
2330
|
// any 32bit CPU offers atomic access to 32bit variables
|
2344
|
|
- const bool was_enabled = STEPPER_ISR_ENABLED();
|
2345
|
|
- if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
|
|
2331
|
+ const bool was_enabled = suspend();
|
2346
|
2332
|
#endif
|
2347
|
2333
|
|
2348
|
2334
|
const int32_t v = count_position[axis];
|
2349
|
2335
|
|
2350
|
2336
|
#ifdef __AVR__
|
2351
|
2337
|
// Reenable Stepper ISR
|
2352
|
|
- if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
|
|
2338
|
+ if (was_enabled) wake_up();
|
2353
|
2339
|
#endif
|
2354
|
2340
|
return v;
|
2355
|
2341
|
}
|
2356
|
2342
|
|
|
2343
|
+// Set the current position in steps
|
|
2344
|
+void Stepper::set_position(const int32_t &a, const int32_t &b, const int32_t &c, const int32_t &e) {
|
|
2345
|
+ planner.synchronize();
|
|
2346
|
+ const bool was_enabled = suspend();
|
|
2347
|
+ _set_position(a, b, c, e);
|
|
2348
|
+ if (was_enabled) wake_up();
|
|
2349
|
+}
|
|
2350
|
+
|
|
2351
|
+void Stepper::set_axis_position(const AxisEnum a, const int32_t &v) {
|
|
2352
|
+ planner.synchronize();
|
|
2353
|
+
|
|
2354
|
+ #ifdef __AVR__
|
|
2355
|
+ // Protect the access to the position. Only required for AVR, as
|
|
2356
|
+ // any 32bit CPU offers atomic access to 32bit variables
|
|
2357
|
+ const bool was_enabled = suspend();
|
|
2358
|
+ #endif
|
|
2359
|
+
|
|
2360
|
+ count_position[a] = v;
|
|
2361
|
+
|
|
2362
|
+ #ifdef __AVR__
|
|
2363
|
+ // Reenable Stepper ISR
|
|
2364
|
+ if (was_enabled) wake_up();
|
|
2365
|
+ #endif
|
|
2366
|
+}
|
|
2367
|
+
|
2357
|
2368
|
// Signal endstops were triggered - This function can be called from
|
2358
|
2369
|
// an ISR context (Temperature, Stepper or limits ISR), so we must
|
2359
|
2370
|
// be very careful here. If the interrupt being preempted was the
|
|
@@ -2362,8 +2373,7 @@ int32_t Stepper::position(const AxisEnum axis) {
|
2362
|
2373
|
// is properly canceled
|
2363
|
2374
|
void Stepper::endstop_triggered(const AxisEnum axis) {
|
2364
|
2375
|
|
2365
|
|
- const bool was_enabled = STEPPER_ISR_ENABLED();
|
2366
|
|
- if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
|
|
2376
|
+ const bool was_enabled = suspend();
|
2367
|
2377
|
endstops_trigsteps[axis] = (
|
2368
|
2378
|
#if IS_CORE
|
2369
|
2379
|
(axis == CORE_AXIS_2
|
|
@@ -2378,22 +2388,21 @@ void Stepper::endstop_triggered(const AxisEnum axis) {
|
2378
|
2388
|
// Discard the rest of the move if there is a current block
|
2379
|
2389
|
quick_stop();
|
2380
|
2390
|
|
2381
|
|
- if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
|
|
2391
|
+ if (was_enabled) wake_up();
|
2382
|
2392
|
}
|
2383
|
2393
|
|
2384
|
2394
|
int32_t Stepper::triggered_position(const AxisEnum axis) {
|
2385
|
2395
|
#ifdef __AVR__
|
2386
|
2396
|
// Protect the access to the position. Only required for AVR, as
|
2387
|
2397
|
// any 32bit CPU offers atomic access to 32bit variables
|
2388
|
|
- const bool was_enabled = STEPPER_ISR_ENABLED();
|
2389
|
|
- if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
|
|
2398
|
+ const bool was_enabled = suspend();
|
2390
|
2399
|
#endif
|
2391
|
2400
|
|
2392
|
2401
|
const int32_t v = endstops_trigsteps[axis];
|
2393
|
2402
|
|
2394
|
2403
|
#ifdef __AVR__
|
2395
|
2404
|
// Reenable Stepper ISR
|
2396
|
|
- if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
|
|
2405
|
+ if (was_enabled) wake_up();
|
2397
|
2406
|
#endif
|
2398
|
2407
|
|
2399
|
2408
|
return v;
|
|
@@ -2403,14 +2412,13 @@ void Stepper::report_positions() {
|
2403
|
2412
|
|
2404
|
2413
|
#ifdef __AVR__
|
2405
|
2414
|
// Protect the access to the position.
|
2406
|
|
- const bool was_enabled = STEPPER_ISR_ENABLED();
|
2407
|
|
- if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
|
|
2415
|
+ const bool was_enabled = suspend();
|
2408
|
2416
|
#endif
|
2409
|
2417
|
|
2410
|
2418
|
const xyz_long_t pos = count_position;
|
2411
|
2419
|
|
2412
|
2420
|
#ifdef __AVR__
|
2413
|
|
- if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
|
|
2421
|
+ if (was_enabled) wake_up();
|
2414
|
2422
|
#endif
|
2415
|
2423
|
|
2416
|
2424
|
#if CORE_IS_XY || CORE_IS_XZ || ENABLED(DELTA) || IS_SCARA
|
|
@@ -2571,16 +2579,21 @@ void Stepper::report_positions() {
|
2571
|
2579
|
Z_STEP_WRITE(INVERT_Z_STEP_PIN);
|
2572
|
2580
|
|
2573
|
2581
|
// Restore direction bits
|
|
2582
|
+ DIR_WAIT_BEFORE();
|
|
2583
|
+
|
2574
|
2584
|
X_DIR_WRITE(old_dir.x);
|
2575
|
2585
|
Y_DIR_WRITE(old_dir.y);
|
2576
|
2586
|
Z_DIR_WRITE(old_dir.z);
|
2577
|
2587
|
|
|
2588
|
+ DIR_WAIT_AFTER();
|
|
2589
|
+
|
2578
|
2590
|
#endif
|
2579
|
2591
|
|
2580
|
2592
|
} break;
|
2581
|
2593
|
|
2582
|
2594
|
default: break;
|
2583
|
2595
|
}
|
|
2596
|
+
|
2584
|
2597
|
sei();
|
2585
|
2598
|
}
|
2586
|
2599
|
|