Page 1 of 1

Software timer assigned core

Posted: Mon Mar 21, 2022 1:21 pm
by grunnels@gmail.com
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?
  1.  
  2. #define PHOTO_PIN  4
  3.  
  4. int lightLevel = 0;
  5. static const TickType_t lightDelay = 2000 / portTICK_PERIOD_MS;
  6. static TimerHandle_t lightTimer = NULL;
  7.  
  8. void setup() {
  9.  
  10.   Serial.begin(38400);
  11.   delay(1000);
  12.   Serial.println("Load timer");
  13.   lightTimer = xTimerCreate(
  14.                  "lightTimer",
  15.                  lightDelay,
  16.                  pdTRUE,
  17.                  (void *)0,
  18.                  lightTimerCallback);
  19.  
  20.   Serial.println("Start timer");
  21.   xTimerStart(lightTimer, portMAX_DELAY);
  22.   vTaskDelete(NULL);
  23. }
  24.  
  25. void lightTimerCallback(TimerHandle_t xTimer) {
  26.   Serial.print("core: ");
  27.   Serial.println(xPortGetCoreID());
  28.   lightLevel = analogRead(PHOTO_PIN);
  29.   Serial.print("lightLevel: ");
  30.   Serial.println(lightLevel);
  31. }
  32.  
  33. void loop() {
  34. }