Software timer assigned core
Posted: Mon Mar 21, 2022 1:21 pm
Hello. In the attached code, the timer routine always executes on Core 0. Is that a guarantee? Will it always run on Core 0, or is it just because Core 0 doesn't have anything else running at this time? Also, how would I pin this routine to Core 1?
Code: Untitled.cpp Select all
#define PHOTO_PIN 4
int lightLevel = 0;
static const TickType_t lightDelay = 2000 / portTICK_PERIOD_MS;
static TimerHandle_t lightTimer = NULL;
void setup() {
Serial.begin(38400);
delay(1000);
Serial.println("Load timer");
lightTimer = xTimerCreate(
"lightTimer",
lightDelay,
pdTRUE,
(void *)0,
lightTimerCallback);
Serial.println("Start timer");
xTimerStart(lightTimer, portMAX_DELAY);
vTaskDelete(NULL);
}
void lightTimerCallback(TimerHandle_t xTimer) {
Serial.print("core: ");
Serial.println(xPortGetCoreID());
lightLevel = analogRead(PHOTO_PIN);
Serial.print("lightLevel: ");
Serial.println(lightLevel);
}
void loop() {
}