Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

Lib with conditional compiling...

Posted by ulmus on February 22, 2012
I have some library i want conditionaly compile: with or without freertos.
What is the best defined const in FreeRTOS to use with '#ifdef xxxxx' statement?

#ifdef INC_FREERTOS_H
or something else?


RE: Lib with conditional compiling...

Posted by Richard Damon on February 22, 2012
You are going to have to add some define to tell you source code if you want to use FreeRTOS or not. The issues is that you will want to conditionally include the needed FreeRTOS headers based on this. This of course means you will need to build two versions of your library (one with and one without this define) and link to the appropriate version.

Otherwise you are going to run into a chicken and egg issue, to try and test a FreeRTOS define, you will have to know if you need to include the FreeRTOS headers before you have included the headers that would define the symbol. The only way to do that would be to use some compiler option to force the inclusion of the base FreeRTOS header at the start of your program. It is probably better to add the define in your compiler config (something like -DFREERTOS) than to force the header inclusion.

It is generally impossible to have the library check at link time to see if the rest of the program is using a software package and somehow "automagically" change the code of the library based on this, you need to pre-generate the different versions of the library, then there MAY be a way to select which library to use, or you need to change which library is specifed in the link options.

RE: Lib with conditional compiling...

Posted by ulmus on February 22, 2012
I was not so clear i'd wanted to. When i was saying 'library' i was thinking about source library (*.c, *.h files), not precompiled library.

RE: Lib with conditional compiling...

Posted by Richard Damon on February 22, 2012
If you have .c files, it does't really make a difference. Each .c file is generally compiled independently, so it can not tell if the FreeRTOS files are being used by other .c files. You are still going to need to add some define in the compliers configuration to tell it that you are using FreeRTOS or not. If your library is a "pure header" library (which is unusual in C, it means ALL operations need to be with inline functions, and any globals needed will need to be setup by the user) then you could require it to be include after the include of FreeRTOS.h and detect the INC_FREERTOS_H define, but that could lead to interesting problems if the user make a mistake and puts it before the include.

An older style of using FreeRTOS was to define a variable in the compiler (with a forced define) to indicate which port to use, and you could use that to select. The more recent standard is to just put the appropriate port directory on the include path, which won't help you. That is why I suggest you select for yourself a configuration define to allow you to detect if you are going to use FreeRTOS or not.

The other option is to use a "porting" layer. If you can define your library based on some generic interface, and then have a porting .h/.c file(s) that define that interface to the environment you are targeting to. You then do like FreeRTOS and add the appropriate sub directory to the include path, and maybe need to add the appropriate myport.c to your project. (this assumes that your design doesn't radically differ based on targeted environment, although since that myport.h would include FreeRTOS.h if you were using FreeRTOS, you could then check for INC_FREERTOS_H being defined.

RE: Lib with conditional compiling...

Posted by ulmus on February 22, 2012
Many thanks!
I decided to use my own '#define ' in my lib header file, it would be easier and cleaner to use.
The most diferences in compiling library using frrertos or not, is about using mutexes and semaphores instead of using bit flags and loops.


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




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists