Giter VIP home page Giter VIP logo

freertoshelpers's Introduction

Header only, FreeRTOS based set of tools that allows running deferred tasks in a single-threaded environment.

Usage

FreeRTOSHelpers::setImmediate

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

FreeRTOSHelpers::setTimeout

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

FreeRTOSHelpers::setInterval

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
...

FreeRTOSHelpers::Function

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.

FreeRTOSHelpers::ConditionVariable

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
...

freertoshelpers's People

Contributors

auntan avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.