This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

HalCoGen C++

Other Parts Discussed in Thread: HALCOGEN, TMS570LS0432

Hi!

I would like to use HalCoGen (04.02) and CCS 6.0.1 tools to make a c++ appliation.

When looking at the generated code it gives the impression it works with c++ because  there are "#ifdef __cplusplus" in the code. But it's very inconsitant. Some generated files are missing the 

#ifdef __cplusplus
extern "C" {
#endif

....

#ifdef __cplusplus
}
#endif

I also found that some files (adc.h) is missing closing "}" at the end because the final #ifdef __cplusplus is missing:

#ifdef __cplusplus

}

#endif

It's also very anoying that the pragmas isn't compatible with c++, the HalCoHen team has to make each pragma compatible by adding something like

#ifdef __cplusplus

#pragma INTERRUPT(IRQ)

#else

#pragma INTERRUPT(phantomInterrupt, IRQ)

#endif

OR add USER CODE BEGIN/END around each pragma so that users can modify the pragmas so that they won't be overwritten the next time the code is generated. 

Another problem is when the generated c files are renamed to cpp. HalCoGen needs to check also for cpp files. If I rename a .c file to .cpp I would like HalCoGen to look for the .cpp file before creating a new .c file.

I intend to use the generated HalCoGen code in a IEC61508 SIL application. The generated code has to compile without errors to give the HalCoGen some credibillity to be used in safety-critical development.

PLEASE make a working example (application note would be great) of how to best add c++ to a project using HalCoGen. Both with and without FreeRTOS (there are some fixes to be made in the FreeRTOS port as well I belive). I found others on this forum also having trouble.

Best Regards

Henrik Liljedahl

  • After several trivial fixes to make the code c++ compatible I now have three compilation errors in sys_startup.c I need help with:

    1.sys_startup.c line 582: main(); -> Type #392 function "main" may not be called or have its address taken

    2.sys_startup.c line 80: extern void exit(int);->unresolved symbol exit(int)

    3.sys_startup.c line 75: extern void __TI_auto_init(void);->unresolved symbol __TI_auto_init()


    I believe there is more work fundamental work that needs to be done on the sys_startup to make it work with c++? According to compilation error 1 above, sys_startup can't/is not allowed to call main(). I don't know how to fix this, please help.


    Best Regards

    Henrik Liljedahl
  • To my surprise only making the sys_main a cpp file I now manage to include c++ code from there. I keept the c style void main(void), but doesn't it has to be c++ style "int main()" ?

    I'm a little worried because of what I read at: http://www.parashift.com/c++-faq/overview-mixing-langs.html

    Will everything get initialized and libraries correct anyway?

    Best Regards

    Henrik Liljedahl
  • Hi Henrik,

    I have asked the HALCoGen team to reply to your queries. Thank you very much for your patience.

    Regards,
    Sunil
  • Any news from the HalCoGen team?

    Regards

    Henrik

  • Hi Henrik,

    HALCoGen Team is planning for a Patch release 2nd week of Feb. The issue will be addressed in this release. Thanks!

  • Hi Henrik,

    Why would you want to rename C files to cpp, not use it as C files, itself. All your application files can be in C++, this means only the header file support should be sufficient right? How does this impact the Safety Application development? I was under assumption that C was heavily recommended and not C++ for safety application.

    HALCoGen team committed for all header files to support c++ switching, so that it can be included in the C++ source files. The ADC header file bug fix is done. Sorry but in near future no C++ source files will be supported from HALCoGen. This was never a requirement for the HALCoGen from the beginning except to support header files.
  • Ok, but as I understad you only fixed the adc.h? But what about all the rest. There will be many more compilation errors. Fixing all anoying pragmas would be a start...

    Table C1. IEC 61508-7 says c++ HR SIL4 included!

    My actual problem is I don't know how to initialize c++. I don't know how to do that from c code. I can't make it work. static are not initialized and other problems. All examples I've seen the sys_main (void main file) is ALWAYS in c++.

    Please give me some guidance on how to write my application i c++ alongside HalCoGen genrated code. A simple "hello World" example would get me started. Thanks!

  • Hi Henrik,

    If I understand you need a sample CCS project , that has the application in C++( main file), but use HALCoGen generated files.
    Give me a days time. I will try to put together an project, I have not done this one too, but I will find some help.
  • A CCS/HalCoGen c++ example would be very much appreciated!
  • Hi Henrik,

    4370.RM42_Blinky_cpp.zip

    Attached is a simple RM42x Blinky code generated using HALCoGen 4.02.00.  I added a folder named Source_cpp where I have put a simple main cpp app, which toggles the pin GIOA2, which is connected to LED in the RM42x Launchpad...  Hope it Helps.... 

    Excuse my C++ coding... This is my first C++ code... :) 

  • Thank you for the sample project. It does look a lot like mine. The only problem is that my code doesn't work. Have you made changes to any properties for the ccs project?

    There are some diffrences. My code is for TMS570 and FreeRTOS is included.

    I can't even allocate memory. I try to call:

    Rectangle* rect0 = new Rectangle();

    What happens is when the malloc function is called found in arm_5.19\lib\src\memory.c

    it then makes calls to

    static void minsert(PACKET *ptr)

    on the second call @line 260 memory.c

    it get "Attempted to read past the end of memory at 0x100000000"

    I've tried to use the FreeRTOS heap by including the following lines, but still standard malloc is called:

    #define malloc(size) pvPortMalloc(size)
    #define free(ptr) pvPortFree(ptr)

    I don't know how to make the "new" use FreeRTOS malloc. Any suggestions?

    I have set my heap size to 0x2000. Should be enough...

    Also static is not initialized, maybe got something to do with the heap I don't know. If I add a static to your class it won't get initialized:

    int Rectangle::area (void)
    {
    static int counter = 50;
    counter++;
    return(width * height);
    }

    Maybe I will have to make a clean project and add one thing at a time to find out what's wrong.

    Best Regards

    Henrik Liljedahl
  • I've now made several new projects (both RM32 launchpad and TMS570 launchpad) and as soon as I create a new TMS570LS0432 _FreeRTOS project there are problems. Can you please try make a c++ out of a HalCoGen TMS570LS0432 _FreeRTOS project and dynamically allocate the Rectangle "Rectangle* rect = new Rectangle();" if you can make it work I would very much like to know how you did!