Author Topic: FreeRTOS C++ Utility Library  (Read 2529 times)

0 Members and 1 Guest are viewing this topic.

Offline rouninTopic starter

  • Regular Contributor
  • *
  • Posts: 131
  • Country: us
FreeRTOS C++ Utility Library
« on: December 22, 2018, 11:08:44 pm »
I decided to post a small C++ wrapper & utility library for FreeRTOS - https://github.com/jacobschloss/freertos_cpp_util

It is mostly a wrapper around the C API, with one slightly fancier object pool - https://github.com/jacobschloss/freertos_cpp_util/tree/master/include/freertos_cpp_util/object_pool. The object pool uses placement new to allow constructors to be called, unlike the usual freertos queues which require POD / C style data. I've found it useful as a way to wait for high-level things to be available, like DMA buffers, that can benefit from in-place construction.

It has some c++11 features where useful, like converting between a templated std::chrono::duration<Rep,Period> and rtos ticks automatically for timeouts in queue, mutex, pool operations, and trying to make a std::mutex compatible mutex class so std::unique_lock and std::lock_guard can be used for scoped/RAII lock and unlock.

This particular incarnation hasn't had much runtime yet, mostly re-written from memory in one sitting from other wrappers I've written in the past. I'll start using this version though, so it will be getting some testing / more features as I need them. This is mainly intended for micro-controllers with maybe ~100kB sram, the template code and virtual function calls add a few extra kB of flash and few extra stack frames. It hasn't been an issue for me, but I've only targeted large microcontrollers / small application processors in the past.
« Last Edit: December 22, 2018, 11:15:02 pm by rounin »
 
The following users thanked this post: hans, FlyingDutch

Offline rouninTopic starter

  • Regular Contributor
  • *
  • Posts: 131
  • Country: us
Re: FreeRTOS C++ Utility Library
« Reply #1 on: December 30, 2018, 04:24:02 am »
Another higher level feature: Condition Variables

I've wanted condition variables for a long time, and took the approach in this paper from ms reasearch since FreeRTOS does not have a built-in way to atomically unlock a semaphore and suspend a task, or atomically switch which object you are waiting on. Basically, there is a LIFO for waiters and a per task binary semaphore, and it can emulate what is better done directly in the scheduler.

I just started playing with it, seems to be working but haven't really stressed it yet. Apparently there have been posts since 2010 on the FreeRTOS forum asking for them and the response was "why would you want those"....  :-// I think they make stream handling code much more readable, but I am a fan of C++11 style predicates and function objects.

The paper is pretty neat. Nice bit of OS implementation history, very readable.

« Last Edit: December 30, 2018, 04:44:07 am by rounin »
 
The following users thanked this post: hans


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->