Skip to content

Commit 4cd3b27

Browse files
committed
Compute idle time differently
1 parent 69aea7e commit 4cd3b27

File tree

2 files changed

+36
-51
lines changed

2 files changed

+36
-51
lines changed

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 4 additions & 42 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

@@ -422,24 +422,20 @@ unsigned long systemTestDisplayTime = 0; //Timestamp for swapping the graphic du
422422
uint8_t systemTestDisplayNumber = 0; //Tracks which test screen we're looking at
423423
unsigned long rtcWaitTime = 0; //At poweron, we give the RTC a few seconds to update during PointPerfect Key checking
424424

425-
uint32_t cpuIdleCount[MAX_CPU_CORES];
426425
TaskHandle_t idleTaskHandle[MAX_CPU_CORES];
427-
uint32_t cpuLastIdleDisplayTime;
426+
uint32_t max_idle_count = MAX_IDLE_TIME_COUNT;
428427

429428
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
430429

431430
void setup()
432431
{
433432
Serial.begin(115200); //UART0 for programming and debugging
434433

434+
beginIdleTasks();
435+
435436
Wire.begin(); //Start I2C on core 1
436437
//Wire.setClock(400000);
437438

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-
443439
beginDisplay(); //Start display first to be able to display any errors
444440

445441
beginGNSS(); //Connect to GNSS to get module type
@@ -477,8 +473,6 @@ void setup()
477473
log_d("Boot time: %d", millis());
478474

479475
danceLEDs(); //Turn on LEDs like a car dashboard
480-
481-
beginIdleTasks();
482476
}
483477

484478
void loop()
@@ -520,42 +514,10 @@ void loop()
520514
//Convert current system time to minutes. This is used in F9PSerialReadTask()/updateLogs() to see if we are within max log window.
521515
systemTime_minutes = millis() / 1000L / 60;
522516

523-
//Display the CPU idle time
524-
if (settings.enablePrintIdleTime)
525-
printIdleTimes();
526-
527517
//A small delay prevents panic if no other I2C or functions are called
528518
delay(10);
529519
}
530520

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-
}
557-
}
558-
559521
//Create or close files as needed (startup or as user changes settings)
560522
//Push new data to log as needed
561523
void updateLogs()

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -441,27 +441,50 @@ void ButtonCheckTask(void *e)
441441

442442
void idleTask(void *e)
443443
{
444-
uint32_t lastStackPrintTime;
444+
int cpu = xPortGetCoreID();
445+
uint32_t idleCount = 0;
446+
uint32_t lastDisplayIdleTime = 0;
447+
uint32_t lastStackPrintTime = 0;
445448

446449
while (1)
447450
{
448-
if (settings.enablePrintIdleTime)
451+
//Increment a count during the idle time
452+
idleCount++;
453+
454+
//Determine if it is time to print the CPU idle times
455+
if ((millis() - lastDisplayIdleTime) >= (IDLE_TIME_DISPLAY_SECONDS * 1000))
449456
{
450-
//Increment a count during the idle time
451-
cpuIdleCount[xPortGetCoreID()]++;
457+
lastDisplayIdleTime = millis();
458+
459+
//Get the idle time
460+
if (idleCount > max_idle_count)
461+
max_idle_count = idleCount;
462+
463+
//Display the idle times
464+
if (settings.enablePrintIdleTime) {
465+
Serial.printf("CPU %d idle time: %d%% (%d/%d)\r\n", cpu,
466+
idleCount * 100 / max_idle_count,
467+
idleCount, max_idle_count);
468+
469+
//Print the task count
470+
if (cpu)
471+
Serial.printf("%d Tasks\r\n", uxTaskGetNumberOfTasks());
472+
}
452473

453-
//Let other same priority tasks run
454-
yield();
474+
//Restart the idle count for the next display time
475+
idleCount = 0;
455476
}
456-
else
457-
delay(1000);
458477

459478
//Display the high water mark if requested
460-
if ((settings.enableTaskReports == true) && ((millis() - lastStackPrintTime) >= 1000))
479+
if ((settings.enableTaskReports == true)
480+
&& ((millis() - lastStackPrintTime) >= (IDLE_TIME_DISPLAY_SECONDS * 1000)))
461481
{
462482
lastStackPrintTime = millis();
463483
Serial.printf("idleTask %d High watermark: %d\n\r",
464484
xPortGetCoreID(), uxTaskGetStackHighWaterMark(NULL));
465485
}
486+
487+
//Let other same priority tasks run
488+
taskYIELD();
466489
}
467490
}

0 commit comments

Comments
 (0)