|
|
|
@ -19,6 +19,7 @@
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Busy wait delay cycles routines:
|
|
|
|
@ -28,13 +29,35 @@
|
|
|
|
|
* DELAY_US(count): Delay execution in microseconds
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef MARLIN_DELAY_H
|
|
|
|
|
#define MARLIN_DELAY_H
|
|
|
|
|
|
|
|
|
|
#include "../../core/macros.h"
|
|
|
|
|
#include "../../core/millis_t.h"
|
|
|
|
|
|
|
|
|
|
#if defined(__arm__) || defined(__thumb__)
|
|
|
|
|
|
|
|
|
|
#if __CORTEX_M == 7
|
|
|
|
|
|
|
|
|
|
// Cortex-M7 can use the cycle counter of the DWT unit
|
|
|
|
|
// http://www.anthonyvh.com/2017/05/18/cortex_m-cycle_counter/
|
|
|
|
|
|
|
|
|
|
FORCE_INLINE static void enableCycleCounter() {
|
|
|
|
|
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
|
|
|
|
|
|
|
|
|
// Unlock DWT.
|
|
|
|
|
DWT->LAR = 0xC5ACCE55;
|
|
|
|
|
|
|
|
|
|
DWT->CYCCNT = 0;
|
|
|
|
|
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FORCE_INLINE volatile uint32_t getCycleCount() { return DWT->CYCCNT; }
|
|
|
|
|
|
|
|
|
|
FORCE_INLINE static void DELAY_CYCLES(const uint32_t x) {
|
|
|
|
|
const uint32_t endCycles = getCycleCount() + x;
|
|
|
|
|
while (PENDING(getCycleCount(), endCycles)) { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
// https://blueprints.launchpad.net/gcc-arm-embedded/+spec/delay-cycles
|
|
|
|
|
|
|
|
|
|
#define nop() __asm__ __volatile__("nop;\n\t":::)
|
|
|
|
@ -80,6 +103,8 @@
|
|
|
|
|
}
|
|
|
|
|
#undef nop
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#elif defined(__AVR__)
|
|
|
|
|
|
|
|
|
|
#define nop() __asm__ __volatile__("nop;\n\t":::)
|
|
|
|
@ -144,5 +169,3 @@
|
|
|
|
|
|
|
|
|
|
// Delay in microseconds
|
|
|
|
|
#define DELAY_US(x) DELAY_CYCLES( (x) * (F_CPU / 1000000UL) )
|
|
|
|
|
|
|
|
|
|
#endif // MARLIN_DELAY_H
|
|
|
|
|