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

IAR & static_cast<>

Posted by Thomas on June 4, 2008
I'm trying to use FreeRTOS together with C++.

I'm using IAR AVR compiler.

All of FreeRTOS source files are compiled using the C compiler and my own code using Extended Embedded C++ compiler. All the code are compiled and linked togther without errors.

Inspired by a richard_damon post I've made a Runable class, see below.

Running my code I get an RStack warning (JTAGICE mkII)
Wed Jun 04 11:49:06 2008: Target reset
Wed Jun 04 11:49:16 2008: Program exit reached.
Wed Jun 04 11:49:17 2008: The stack 'RStack' is filled to 100% (32 bytes used out of 32). The warning threshold is set to 90.%

I've traced it down to being this static_cast causing the trouble.

(static_cast<Runable*>(parm))->Run();

If I comment the static_cast and uncomment the loop causing a led to flash everything works fine.

I have tried the same code using winavr c++ compiler and it works. Using the winavr compiler I compile everything using the c++ compiler. Therefore I have to change some cast here and there in the FreeRTOS code in order to satisfy the c++ compiler. When using IAR I can compile a "clean" FreeRTOS (without changing anything) using C compiler and my own code using C++. My guess is that its the reason for my troubles.

Can someone give me an explanation or even a way to fix it?

/Thomas

// runable.c

#include "runable.h"

//*****************************************************
Runable::Runable(unsigned priority, unsigned stacksize)
{
#if INCLUDE_vTaskDelayUntil
lastWakeTime = NULL;
#endif
xTaskCreate(&run, "", stacksize, this, priority, &handle);
}

//*****************
Runable::~Runable()
{
#if INCLUDE_vTaskDelete
vTaskDelete(handle);
#endif
}

#if INCLUDE_vTaskSuspend

//*********************
void Runable::Suspend()
{
vTaskSuspend(handle);
}

//********************
void Runable::Resume()
{
vTaskResume(handle);
}

#endif

#if INCLUDE_vTaskDelay

//*************************************
void Runable::Sleep(portTickType delay)
{
vTaskDelay(delay);
}

#endif

#if INCLUDE_vTaskDelayUntil

//**********************************************
void Runable::SleepUntil(portTickType increment)
{
if (lastWakeTime == NULL)
lastWakeTime = xTaskGetTickCount();
vTaskDelayUntil(&lastWakeTime, increment);
}

#endif

//***************************
void Runable::run(void* parm)
{
(static_cast<Runable*>(parm))->Run();
/*
for(;;)
{
PORTA = (PORTA & ~0x01) | (~PORTA & 0x01);

vTaskDelay( 100 );
}
*/
}

RE: IAR & static_cast<>

Posted by Richard on June 5, 2008
So the problem seems to be when linking C with C++ code. Is this correct? Can you compile the whole thing as C++ as when using the WinAVR compiler?

Regards.

RE: IAR & static_cast<>

Posted by Thomas on June 9, 2008
I managed to figure it out. I had some errors in my port causing the stack to be currupt.


[ 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