April 2025

Beware of some freertos examples (for esp32)

Freertos is now in version 3.x and some of my examples from before covid is written for version 2.x  (3.x didnt exist I imagine)

An example below

Mod code for https://jensd.dk/doc/freertos/src/freertos-esp32/rt-esp32-code2/rt-esp32-ecg-timerfifobuffer01/rt-esp32-ecg-timerfifobuffer01.ino

 


void IRAM_ATTR onTimer() {
  static int sampleVal = 0, sampleVal_1 = 0;

  // FAKE PART
  sampleVal_1 = sampleVal;
  sampleVal = getECG(); // analogRead ;-)


  // REAL PART
  portENTER_CRITICAL_ISR(&timerMux); // for dataprotection on dual core

  bufPutOverWrite(sampleVal);

  portEXIT_CRITICAL_ISR(&timerMux);
}

/* setup timer on ISR just above
    variable timerMicroSecCount set timer speed
    Can be used for sampling
*/

const int timerMicroSecCount = 10000;  // 1e6 = 1 sec

void startCyclicTimerISR()
{

  timer = timerBegin(1000000);//0, 80, true);  // timer no 0 out of 4(0,1,2,3) divide 80 MHz timer with 80 -> 1 MHz timer
  timerAttachInterrupt(timer, &onTimer); //, true);
  timerAlarm(timer, timerMicroSecCount, true, 0);
}
