Skip to content

suo235/MEROS-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MEROS++

Minimal Embedded Real-time OS written in C++

Features

  • C++ interface
  • Static memory allocation: Stack area of each task is statically allocated
  • Easy to port: Few knowledge of Assembly language required

Requirements

  • Compiler: arm-none-eabi-gcc, arm-none-eabi-g++ 4.9.3

How to port MEROS++ into your project

  1. Modify 4 functions in merospp_port.hpp

    • disable_interrupt()
    • enable_interrupt()
    • store_stack_pointer()
    • restore_stack_pointer()

    Default functions are for STM32 Cortex M4.

  2. Include merospp.hpp, then instantiate Tasks and the Scheduler

    #include "merospp.hpp"
    
    // You can derive Task class like:
    class TaskDerived : public merospp::Task
    {
        public:
        TaskDerived( const uint32_t priority, const uint32_t period, void (*callback)(void) )
        : merospp::Task( priority, period, callback )
        {
    
        }
    };
    
    void callback1()
    {
        // do something
        // DO NOT PUT INFINITE LOOP inside
    }
    void callback2()
    {
        // do something
        // DO NOT PUT INFINITE LOOP inside
    }
    
    merospp::Task t1(5, 500, callback1);  // callback1 is called every 500ms
    TaskDerived t2(4, 1000, callback2);  // callback2 is called every 1000ms
    
    // Get the instance of Scheduler
    // Stack size: 64 words for t1, 128 words for t2
    auto& scheduler = merospp::Scheduler< 64, 128 >::get_instance( t1, t2 );
  3. Place schedule() inside an interrupt handler that is called periodically

    void timer_callback()  // "HAL_TIM_PeriodElapsedCallback" for STM32
    {
        scheduler.schedule();
    }
  4. Place run() inside main()

    int main()
    {
        /* Peripheral setup start */
        
        /* Peripheral setup end */
        
        scheduler.run();
        return 0;
    }
  5. Build your project

    Please refer to CMakeLists_sample.txt for recommended compile options.

Acknowledgements

About

Minimal Embedded Real-time OS written in C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages