Monday, February 19th 2018, 2:34am UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Date of registration: Oct 22nd 2010

Posts: 3

1

Friday, October 22nd 2010, 9:13pm

RX600 C++ with embOS

The RX600 HEW IDE supports a C++ capable compiler. I would like to use C++ for some simple C++ objects. Nothing major like design patterns, but I can use some concepts.

I'll probably configure the app with no std_exceptions and no stream IO (it looked a bit code heavy in my initial test)

The question is, can I use embOS seamlessly in a C++ build environment, or will I have to provide wrappers for everything?

Will I need a source distribution or just a binary?

SEGGER - Til

Super Moderator

Date of registration: Nov 14th 2007

Posts: 264

2

Monday, October 25th 2010, 9:32am

Hello,

you can use embOS of course with C++, you don't need the source code version, the object version is enough.

If you like you can download the embOS RX HEW trial version from our website. It has no functional limitation, so you could test by yourself that it works with C++.

If you have any further question you are invited to contact us directly.

Regards,
Til

Date of registration: Oct 22nd 2010

Posts: 3

3

Tuesday, January 4th 2011, 5:57pm

Several issues

I tried to create a C++ project with a resetprg.cpp and the system crashes so I reverted to the "C" version and added the C++ initializer call. Global C++ object constructors are called via _CALL_INIT() in resetprg.c. This works ok, but it is not optimal. I would like to have classes inherit from a simple lock class but since global C++ objects are initialized before the RTOS, it fails. I tried moving OS_InitKern() and the other startups into PowerOn_Reset_PC() but there are obviously stack issues as it crashes with ErrCode 0xA4.

I finaly got it to work with this code in resetprg.c, but I am not sure if it is proper. I also am not sure about how one would write a C++ object which as a "extern C" thread function and how the thread would know about the objects "this" pointer. I assume that is the reason for OS_CREATETASKEX.

I really need an example with YRDKRX62N C++ project. Simple blinky lights will do.



Source code

1
2
3
4
5
6
7
8
9
10
HardwareSetup();        // Use Hardware Setup
  nop();
set_psw(PSW_init);
 // OS_IncDI();                      /* Initially disable interrupts  */
  OS_InitKern();                   /* Initialize OS                 */
  OS_InitHW();                     /* Initialize Hardware for OS    */
  BSP_Init();                      /* Initialize LED ports          */
  
  _CALL_INIT();         // Remove the comment when you use global class object
//  set_psw(PSW_init);        // Set Ubit & Ibit for PSW


Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Lock {
public:
 Lock();
 ~Lock();
 void lock();
 void unlock();
 bool trylock();
private:
// OS_RSEMA mutex;
};
//#include RTOS files
#include "Lock.hpp"
 Lock::Lock() {
//  OS_CREATERSEMA(mutex);
 }
    
 Lock::~Lock() {
//  OS_DeleteRSema(mutex)
 }
   
 void Lock::lock() {
//  OS_Use(mutex);
 }
   
 void Lock::unlock() {
//  OS_Unuse(mutex);
 }
   
 bool Lock::trylock() {
//  if(OS_Request(mutex))
//   return true;
  return false;
 }

Date of registration: Oct 22nd 2010

Posts: 3

4

Tuesday, January 4th 2011, 8:34pm

Ok, figured it out. I do need to know if the changes to resetprg.c are acceptable?

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
OS_STACKPTR int StackMP[128];
OS_TASK TCBMP;
class thread
{
public:
 thread();
 ~thread() {};
 int Get() { return myint;};
private:
 int myint;
} Thread1;
extern "C" {
void MPTask(void * context) {
 class thread * mythis = (class thread *)context;
  while (1) {
    BSP_ToggleLED(mythis->Get());
    OS_Delay (100);
  }
}
}
thread::thread()
{
 myint = 2;
 OS_CREATETASK_EX(&TCBMP, "MP Task", MPTask,  75, StackMP, this);
}