Using software timers with lambda's

Bascy65
Posts: 5
Joined: Tue Dec 26, 2017 2:32 pm

Using software timers with lambda's

Postby Bascy65 » Mon Aug 29, 2022 11:18 am

In my project I'm creating a scheduler that can schedule "random" actions using xTimerCreate method to create a software timer. I'm using software timers as I don't need very high accuracy and using interrupts would make things more complex than needed.

The xTimerCreate method has a parameter for a callback function but I would like to specify a lambda to be executed when the timer fires.

Code: Select all

TimerHandle_t xTimerCreate( const char * const pcTimerName,
  const TickType_t xTimerPeriodInTicks,
  const UBaseType_t uxAutoReload,
  void * const pvTimerID,
  TimerCallbackFunction_t pxCallbackFunction 
 )
 
 with TimerCallbackFunction defined as void vCallbackFunction( TimerHandle_t xTimer )
  
The pvTimerID parameter is a untyped void pointer which can point to anything, so it might be possible to specify the lambda here and use the callback function to retrieve and execute that.

How would I do that?

Who is online

Users browsing this forum: Baidu [Spider] and 34 guests