Hello! I'm trying out FreeRTOS on ESP32 and I wrote this code:
Service.h
#ifndef Service_H
#define Service_H
#include <Arduino.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/timers.h"
class Service
{
public:
Service(const char* ServiceName, uint32_t TickRate);
void ServiceInit();
void DoWork();
void Stop();
static void vTimerCallback(TimerHandle_t TimerHandle);
TimerHandle_t gWorkTimer;
private:
uint32_t gTickRate;
const char* gServiceName;
};
#endif
Service.cpp
#include "Service.h"
Service::Service(const char* ServiceName, uint32_t TickRate)
{
this->gTickRate = TickRate;
this->gServiceName = ServiceName;
}
void Service::ServiceInit()
{
Serial.println("init");
this->gWorkTimer = xTimerCreate(this->gServiceName, pdMS_TO_TICKS(this->gTickRate), pdTRUE, (void*)0, &vTimerCallback);
}
void Service::DoWork()
{
}
void Service::Stop()
{
}
void Service::vTimerCallback(TimerHandle_t TimerHandle)
{
Serial.println("...");
}
Main.ino:
#include "Service.h"
void setup() {
Serial.begin(115200);
Serial.println("setup");
Service* s = new Service("dummy", 2000);
s->ServiceInit();
while(1) {}
}
void loop() {
}
When it runs, timer never gets to vTimerCallback function ("..." never gets printed):
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13864
load:0x40080400,len:3608
entry 0x400805f0
setup
init
Does someone know what could be wrong?
Best regards,
Luka