From c7d84ce2399cee2322f7b32b1610e5d264f2ef91 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 15 Oct 2019 14:07:20 +0200 Subject: [PATCH] hw status: Detect slow clock drift problems --- armsrc/appmain.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index b524c4883..a0c9a78f2 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -354,6 +354,17 @@ void SendStatus(void) { while ((AT91C_BASE_PMC->PMC_MCFR & AT91C_CKGR_MAINRDY) == 0); // Wait for MAINF value to become available... uint16_t mainf = AT91C_BASE_PMC->PMC_MCFR & AT91C_CKGR_MAINF; // Get # main clocks within 16 slow clocks Dbprintf(" Slow clock..............%d Hz", (16 * MAINCK) / mainf); + uint32_t delta_time = 0; + uint32_t start_time = GetTickCount(); + #define SLCK_CHECK_MS 50 + WaitMS(SLCK_CHECK_MS); + delta_time = GetTickCountDelta(start_time); + if ((delta_time < SLCK_CHECK_MS - 1) || (delta_time > SLCK_CHECK_MS + 1)) { + // error > 2% with SLCK_CHECK_MS=50 + Dbprintf(_RED_(" Slow Clock speed change detected, TIA needed")); + Dbprintf(_YELLOW_(" Slow Clock actual speed seems closer to %d kHz"), + (16 * MAINCK / 1000) / mainf * delta_time / SLCK_CHECK_MS); + } DbpString(_BLUE_("Installed StandAlone Mode")); ModInfo();