Skip to content

Commit d1deb96

Browse files
authored
Merge pull request #227 from LeeLeahy2/idle-count
Idle count
2 parents e4431f0 + 6f348b6 commit d1deb96

File tree

2 files changed

+35
-57
lines changed

2 files changed

+35
-57
lines changed

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const int FIRMWARE_VERSION_MINOR = 3;
4242
#include "settings.h"
4343

4444
#define MAX_CPU_CORES 2
45-
#define IDLE_COUNT_PER_SECOND 196289
45+
#define IDLE_COUNT_PER_SECOND 1000
4646
#define IDLE_TIME_DISPLAY_SECONDS 5
4747
#define MAX_IDLE_TIME_COUNT (IDLE_TIME_DISPLAY_SECONDS * IDLE_COUNT_PER_SECOND)
4848
#define MILLISECONDS_IN_A_SECOND 1000
@@ -425,9 +425,8 @@ unsigned long systemTestDisplayTime = 0; //Timestamp for swapping the graphic du
425425
uint8_t systemTestDisplayNumber = 0; //Tracks which test screen we're looking at
426426
unsigned long rtcWaitTime = 0; //At poweron, we give the RTC a few seconds to update during PointPerfect Key checking
427427

428-
uint32_t cpuIdleCount[MAX_CPU_CORES];
429428
TaskHandle_t idleTaskHandle[MAX_CPU_CORES];
430-
uint32_t cpuLastIdleDisplayTime;
429+
uint32_t max_idle_count = MAX_IDLE_TIME_COUNT;
431430

432431
uint64_t uptime;
433432
uint32_t previousMilliseconds;
@@ -438,14 +437,11 @@ void setup()
438437
{
439438
Serial.begin(115200); //UART0 for programming and debugging
440439

440+
beginIdleTasks();
441+
441442
Wire.begin(); //Start I2C on core 1
442443
//Wire.setClock(400000);
443444

444-
//Initialize the CPU idle time counts
445-
for (int index = 0; index < MAX_CPU_CORES; index++)
446-
cpuIdleCount[index] = 0;
447-
cpuLastIdleDisplayTime = millis();
448-
449445
beginDisplay(); //Start display first to be able to display any errors
450446

451447
beginGNSS(); //Connect to GNSS to get module type
@@ -483,8 +479,6 @@ void setup()
483479
log_d("Boot time: %d", millis());
484480

485481
danceLEDs(); //Turn on LEDs like a car dashboard
486-
487-
beginIdleTasks();
488482
}
489483

490484
void loop()
@@ -526,49 +520,10 @@ void loop()
526520
//Convert current system time to minutes. This is used in F9PSerialReadTask()/updateLogs() to see if we are within max log window.
527521
systemTime_minutes = millis() / 1000L / 60;
528522

529-
//Display the CPU idle time
530-
if (settings.enablePrintIdleTime)
531-
printIdleTimes();
532-
533-
//Monitor the days in uptime
534-
currentMilliseconds = millis();
535-
uptime = (uptime & 0xffffffff00000000ull) | currentMilliseconds;
536-
if (currentMilliseconds < previousMilliseconds)
537-
uptime += 0x100000000ull;
538-
previousMilliseconds = currentMilliseconds;
539-
540523
//A small delay prevents panic if no other I2C or functions are called
541524
delay(10);
542525
}
543526

544-
//Print the CPU idle times
545-
void printIdleTimes()
546-
{
547-
uint32_t idleCount[MAX_CPU_CORES];
548-
int index;
549-
550-
//Determine if it is time to print the CPU idle times
551-
if ((millis() - cpuLastIdleDisplayTime) >= (IDLE_TIME_DISPLAY_SECONDS * 1000))
552-
{
553-
//Get the idle times
554-
cpuLastIdleDisplayTime = millis();
555-
for (index = 0; index < MAX_CPU_CORES; index++)
556-
{
557-
idleCount[index] = cpuIdleCount[index];
558-
cpuIdleCount[index] = 0;
559-
}
560-
561-
//Display the idle times
562-
for (int index = 0; index < MAX_CPU_CORES; index++)
563-
Serial.printf("CPU %d idle time: %d%% (%d/%d)\r\n", index,
564-
idleCount[index] * 100 / MAX_IDLE_TIME_COUNT,
565-
idleCount[index], MAX_IDLE_TIME_COUNT);
566-
567-
//Print the task count
568-
Serial.printf("%d Tasks\r\n", uxTaskGetNumberOfTasks());
569-
}
570-
}
571-
572527
//Create or close files as needed (startup or as user changes settings)
573528
//Push new data to log as needed
574529
void updateLogs()

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -584,27 +584,50 @@ void ButtonCheckTask(void *e)
584584

585585
void idleTask(void *e)
586586
{
587+
int cpu = xPortGetCoreID();
588+
uint32_t idleCount = 0;
589+
uint32_t lastDisplayIdleTime = 0;
587590
uint32_t lastStackPrintTime = 0;
588591

589592
while (1)
590593
{
591-
if (settings.enablePrintIdleTime)
594+
//Increment a count during the idle time
595+
idleCount++;
596+
597+
//Determine if it is time to print the CPU idle times
598+
if ((millis() - lastDisplayIdleTime) >= (IDLE_TIME_DISPLAY_SECONDS * 1000))
592599
{
593-
//Increment a count during the idle time
594-
cpuIdleCount[xPortGetCoreID()]++;
600+
lastDisplayIdleTime = millis();
601+
602+
//Get the idle time
603+
if (idleCount > max_idle_count)
604+
max_idle_count = idleCount;
605+
606+
//Display the idle times
607+
if (settings.enablePrintIdleTime) {
608+
Serial.printf("CPU %d idle time: %d%% (%d/%d)\r\n", cpu,
609+
idleCount * 100 / max_idle_count,
610+
idleCount, max_idle_count);
611+
612+
//Print the task count
613+
if (cpu)
614+
Serial.printf("%d Tasks\r\n", uxTaskGetNumberOfTasks());
615+
}
595616

596-
//Let other same priority tasks run
597-
yield();
617+
//Restart the idle count for the next display time
618+
idleCount = 0;
598619
}
599-
else
600-
delay(1000);
601620

602621
//Display the high water mark if requested
603-
if ((settings.enableTaskReports == true) && ((millis() - lastStackPrintTime) >= 1000))
622+
if ((settings.enableTaskReports == true)
623+
&& ((millis() - lastStackPrintTime) >= (IDLE_TIME_DISPLAY_SECONDS * 1000)))
604624
{
605625
lastStackPrintTime = millis();
606626
Serial.printf("idleTask %d High watermark: %d\n\r",
607627
xPortGetCoreID(), uxTaskGetStackHighWaterMark(NULL));
608628
}
629+
630+
//Let other same priority tasks run
631+
taskYIELD();
609632
}
610633
}

0 commit comments

Comments
 (0)