Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

Combine FreeRTOS tasks and C++ objects

Posted by mourad7 on February 22, 2017

Hello, Actually,i try to use FreeRTOS and C++ language inside my project, but i don't know what is the best way to do this especially when i want to create and call objects ! is it by :

  • Creating object from within a task ? or
  • Create a task from within an object ( i think wrappers are needed in this case) or
  • Combine the task and boject ( 1 task correspnds to on object ) and the deletion of the one means the deletion of the other.

Thank you


Combine FreeRTOS tasks and C++ objects

Posted by heinbali01 on February 23, 2017

Hi Mourad,

Creating object from within a task ?

Objects ( instances of C++ classes ) can be created and used from within a task. In fact, after vTaskStartScheduler() has been called, all code is running from within a task. Except ISR's, who have their own life and rules.

Create a task from within an object ( i think wrappers are needed in this case)

That is also possible. Wrappers will make your code nicer, easier to read, but they're not necessary.

When creating tasks ( from within an object, or wherever ), remember that you work on an embedded project, with limited resources: limited in CPU-speed, limited in memory.

When you start a modern browser on a laptop, it will easily create 7 processes, each process will create 16 threads, and the program will allocate e.g. 37 MB of RAM.

On the contrary, an embedded HTTP-server ( from FreeRTOS+TCP ) will run in a single task and allocate KB's in stead of MB's. Well, unless your hardware has external SDRAM.

Combine the task and boject ( 1 task correspnds to on object ) and the deletion of the one means the deletion of the other.

That's a nice idea: each task (except Idle, that you do not own) is bound to an object, and when the object is deleted, its task will be terminated. In another thread about C++, yesterday, I referred to Richard Damon's C++ project I wrote that new() and delete() must be redefined in order to use task-safe allocators. These allocators are defined in one of the heap_x.c modules.

I often like the addition of C++ to embedded projects. The presence of constructors and destructors formalise important steps. Object-oriented thinking can make life easier.


Combine FreeRTOS tasks and C++ objects

Posted by mourad7 on February 23, 2017

Hi Hein,

Thank you for the explaination.I think that creating an object from within a task could be the best choice for my project.

As you said, i have a limited resources especially in term of RAM, which makes the creation of a task from within an object or linking a task to an object a little bit difficult ( knowing that i have a lot of objects to create particulary at the beginig of the program which demand a lot of memory ) aren't the best choices!

Thank you very much for your help


Combine FreeRTOS tasks and C++ objects

Posted by richarddamon on February 23, 2017

Putting your tasks into objects can be helpful to keep things organized. Certainly most objects will not have a task as part of them (have a reason to create a task). It is also quite possible to use C++ and virtually no heap (or no post-initilization heap), though it does require some discipline and knowledge of what things you need to avoid.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner