@@ -41,6 +41,11 @@ const int FIRMWARE_VERSION_MINOR = 3;
4141
4242#include " settings.h"
4343
44+ #define MAX_CPU_CORES 2
45+ #define IDLE_COUNT_PER_SECOND 196289
46+ #define IDLE_TIME_DISPLAY_SECONDS 5
47+ #define MAX_IDLE_TIME_COUNT (IDLE_TIME_DISPLAY_SECONDS * IDLE_COUNT_PER_SECOND)
48+
4449// Hardware connections
4550// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
4651// These pins are set in beginBoard()
@@ -417,6 +422,10 @@ unsigned long systemTestDisplayTime = 0; //Timestamp for swapping the graphic du
417422uint8_t systemTestDisplayNumber = 0 ; // Tracks which test screen we're looking at
418423unsigned long rtcWaitTime = 0 ; // At poweron, we give the RTC a few seconds to update during PointPerfect Key checking
419424
425+ uint32_t cpuIdleCount[MAX_CPU_CORES];
426+ TaskHandle_t idleTaskHandle[MAX_CPU_CORES];
427+ uint32_t cpuLastIdleDisplayTime;
428+
420429// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
421430
422431void setup ()
@@ -426,6 +435,11 @@ void setup()
426435 Wire.begin (); // Start I2C on core 1
427436 // Wire.setClock(400000);
428437
438+ // Initialize the CPU idle time counts
439+ for (int index = 0 ; index < MAX_CPU_CORES; index++)
440+ cpuIdleCount[index] = 0 ;
441+ cpuLastIdleDisplayTime = millis ();
442+
429443 beginDisplay (); // Start display first to be able to display any errors
430444
431445 beginGNSS (); // Connect to GNSS to get module type
@@ -463,10 +477,15 @@ void setup()
463477 log_d (" Boot time: %d" , millis ());
464478
465479 danceLEDs (); // Turn on LEDs like a car dashboard
480+
481+ beginIdleTasks ();
466482}
467483
468484void loop ()
469485{
486+ uint32_t delayTime;
487+
488+
470489 if (online.gnss == true )
471490 {
472491 i2cGNSS.checkUblox (); // Regularly poll to get latest data and any RTCM
@@ -501,7 +520,40 @@ void loop()
501520 // Convert current system time to minutes. This is used in F9PSerialReadTask()/updateLogs() to see if we are within max log window.
502521 systemTime_minutes = millis () / 1000L / 60 ;
503522
504- delay (10 ); // A small delay prevents panic if no other I2C or functions are called
523+ // Display the CPU idle time
524+ if (settings.enablePrintIdleTime )
525+ printIdleTimes ();
526+
527+ // A small delay prevents panic if no other I2C or functions are called
528+ delay (10 );
529+ }
530+
531+ // Print the CPU idle times
532+ void printIdleTimes ()
533+ {
534+ uint32_t idleCount[MAX_CPU_CORES];
535+ int index;
536+
537+ // Determine if it is time to print the CPU idle times
538+ if ((millis () - cpuLastIdleDisplayTime) >= (IDLE_TIME_DISPLAY_SECONDS * 1000 ))
539+ {
540+ // Get the idle times
541+ cpuLastIdleDisplayTime = millis ();
542+ for (index = 0 ; index < MAX_CPU_CORES; index++)
543+ {
544+ idleCount[index] = cpuIdleCount[index];
545+ cpuIdleCount[index] = 0 ;
546+ }
547+
548+ // Display the idle times
549+ for (int index = 0 ; index < MAX_CPU_CORES; index++)
550+ Serial.printf (" CPU %d idle time: %d%% (%d/%d)\r\n " , index,
551+ idleCount[index] * 100 / MAX_IDLE_TIME_COUNT,
552+ idleCount[index], MAX_IDLE_TIME_COUNT);
553+
554+ // Print the task count
555+ Serial.printf (" %d Tasks\r\n " , uxTaskGetNumberOfTasks ());
556+ }
505557}
506558
507559// Create or close files as needed (startup or as user changes settings)
0 commit comments