Add state signalisation via blipping GPIO17

This commit is contained in:
2025-01-30 18:06:56 +01:00
parent dea3d1307a
commit b57e955dc2
3 changed files with 247 additions and 8 deletions

View File

@ -42,9 +42,9 @@ void stress_task(void *pvParameters) {
void setup() {
Serial.begin(115200);
while (!Serial) {
;
}
// while (!Serial) {
// ;
// }
uint32_t Freq = getCpuFrequencyMhz();
Serial.print("CPU Freq = ");
Serial.print(Freq);
@ -87,6 +87,17 @@ void setup() {
Serial.end();
}
void blip_io(int times) {
constexpr int ioPin = 17;
pinMode(ioPin, OUTPUT);
for(int i = 0; i<times; i++) {
digitalWrite(ioPin,1);
delay(1);
digitalWrite(ioPin,0);
delay(1);
}
}
/*
* A function that prints to serial, setting up the serial peripheral beforehand, and shutting it down afterwards.
* Do not use this on a regular basis, as it is probably very slow. It is useful for not having the serial peripheral
@ -96,10 +107,6 @@ void setup() {
*/
void setupAndCleanupSerialPrint(char *str) {
Serial.begin(115200);
while (!Serial) {
;
;
}
delay(10);
Serial.print(str);
delay(10);
@ -111,6 +118,7 @@ void setupAndCleanupSerialPrint(char *str) {
void loop() {
// Alternate between 20 Seconds at 100% CPU load, no artificial load but not sleeping, and normal behaviour (light sleep when there is nothing to do).
setupAndCleanupSerialPrint("Beginning stress phase\n");
blip_io(1);
TaskHandle_t core0StressTask = NULL;
TaskHandle_t core1StressTask = NULL;
xTaskCreatePinnedToCore(stress_task, "CPU0Stress", 4096, NULL, 1, &core0StressTask, 0);
@ -123,12 +131,14 @@ void loop() {
vTaskDelete(core1StressTask);
// Now disable light sleep
setupAndCleanupSerialPrint("Beginning idle with power management disabled\n");
blip_io(2);
esp_pm_lock_acquire(cpuFreqLock);
esp_pm_lock_acquire(apbFreqLock);
esp_pm_lock_acquire(lightSleepLock);
vTaskDelay(pdMS_TO_TICKS(cycleTime));
// Restore auto light sleep and dynamic frequency scaling
setupAndCleanupSerialPrint("Beginning idle with power management reenabled\n");
blip_io(3);
esp_pm_lock_release(cpuFreqLock);
esp_pm_lock_release(apbFreqLock);
esp_pm_lock_release(lightSleepLock);