From 17a8e2db01a2a804c5dfa1850bbe8b040a35bfeb Mon Sep 17 00:00:00 2001 From: bubnikv Date: Sat, 20 Jan 2018 14:58:30 +0100 Subject: [PATCH] Documented the interrupt blocking by a main thread by its maximum time. Added a debug output to serial line on stepper timer overflow. --- Firmware/cmdqueue.cpp | 4 ++++ Firmware/planner.cpp | 4 ++++ Firmware/stepper.cpp | 11 +++++++++++ 3 files changed, 19 insertions(+) diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp index 771daafe..bdf4c3ab 100644 --- a/Firmware/cmdqueue.cpp +++ b/Firmware/cmdqueue.cpp @@ -627,6 +627,10 @@ void get_command() sd_count.value = 0; cli(); + // This block locks the interrupts globally for 3.56 us, + // which corresponds to a maximum repeat frequency of 280.70 kHz. + // This blocking is safe in the context of a 10kHz stepper driver interrupt + // or a 115200 Bd serial line receive interrupt, which will not trigger faster than 12kHz. ++ buflen; bufindw += len; sdpos_atomic = card.get_sdpos()+1; diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 7738d5cb..0aa60866 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -264,6 +264,10 @@ void calculate_trapezoid_for_block(block_t *block, float entry_speed, float exit } CRITICAL_SECTION_START; // Fill variables used by the stepper in a critical section + // This block locks the interrupts globally for 4.38 us, + // which corresponds to a maximum repeat frequency of 228.57 kHz. + // This blocking is safe in the context of a 10kHz stepper driver interrupt + // or a 115200 Bd serial line receive interrupt, which will not trigger faster than 12kHz. if (! block->busy) { // Don't update variables if block is busy. block->accelerate_until = accelerate_steps; block->decelerate_after = accelerate_steps+plateau_steps; diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 38ece7ea..e915e7ea 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -854,6 +854,11 @@ void isr() { if (OCR1A < TCNT1) { stepper_timer_overflow_state = true; WRITE_NC(BEEPER, HIGH); + SERIAL_PROTOCOLPGM("Stepper timer overflow "); + SERIAL_PROTOCOL(OCR1A); + SERIAL_PROTOCOLPGM("<"); + SERIAL_PROTOCOL(TCNT1); + SERIAL_PROTOCOLLN("!"); } #endif } @@ -1137,6 +1142,7 @@ void st_init() // create_speed_lookuptable.py TCCR1B = (TCCR1B & ~(0x07<