Header only, FreeRTOS based set of tools that allows running deferred tasks in a single-threaded environment.
Callback will be delayed and queued by the scheduler.
#include <include/freertoshelpers.hpp>
int main() {
FreeRTOSHelpers::setImmediate([](){
printf("world\n");
});
printf("hello\n")
// FreeRTOS scheduler must be run
vTaskStartScheduler();
}
Output:
hello
world
Callback will be called by the scheduler after a period of time.
#include <include/freertoshelpers.hpp>
int main() {
FreeRTOSHelpers::setTimeout(1000, [](){
printf("brave\n");
});
FreeRTOSHelpers::setTimeout(2000, [](){
printf("world");
});
printf("hello\n")
// FreeRTOS scheduler must be run
vTaskStartScheduler();
}
Output:
[00.000] hello
[01.000] brave
[02.000] world
Callback will be called by the scheduler every n milliseconds.
#include <include/freertoshelpers.hpp>
int main() {
FreeRTOSHelpers::setInterval(1000, [](){
printf("world\n");
});
printf("hello\n")
// FreeRTOS scheduler must be run
vTaskStartScheduler();
}
Output:
[00.000] hello
[01.000] world
[02.000] world
[03.000] world
...
std::function replacement using local storage instead of heap allocation.
#include <include/freertoshelpers.hpp>
int main() {
FreeRTOSHelpers::Function f0 = [](){
printf("hello\n");
};
FreeRTOSHelpers::Function f1 = [](){
printf("world\n");
};
f0();
f1();
}
Output:
hello
world
The maximum size of capture variables is defined by FreeRTOSHelpers::FUNCTION_MAX_SIZE.
FreeRTOS based std::condition_variable
#include <include/freertoshelpers.hpp>
FreeRTOSHelpers::ConditionVariable cv;
void otherThread( ){
while (true) {
cv.wait();
printf("world\n");
}
}
int main() {
FreeRTOSHelpers::setInterval(1000, [](){
printf("hello\n");
cv.notify();
});
// FreeRTOS scheduler must be run
vTaskStartScheduler();
}
Output:
[01.000] hello
[01.000] world
[02.000] hello
[02.000] world
[03.000] hello
[03.000] world
...