Jump to content
Sign in to follow this  
raskolnikov

Novo And C++ Compiler

Recommended Posts

I'm using the c++ compiler coupled with Novo RTOS. I have a class that has two Novo tasks as member functions as well as an interrupt that is a member function, along these lines:

 

Assume a class called foo, the following member function and task handle:

 

#define hTask1 0

 

foo::Task1()

{

// Do some excellent stuff...

}

 

 

After some initialization I have a run function like this:

 

foo::Run()

{

SysInit();

SysCreateTask(hTask1, 2, this->Task1);

SysStartTask(hTask1);

}

 

I will get the following error: [error: can't convert 'void (*)(class foo*)' to 'void (*)()'].

 

When I write the code in c and use the c compiler I don't run into these problems. There is obviously something that I don't know about the system. Perhaps Tasks cannot be member functions?

 

Any help is appreciated.

 

Thanks,

 

Matt

Share this post


Link to post
Share on other sites
...Perhaps Tasks cannot be member functions?...

 

Tasks can't be members of a class. The reason is in memory allocation for variables. Because there is no stack on PIC all memory allocation has to be done at compile time. Each task is handled as a start of a completely independent call tree. This was compiler and linker can overlay memory regions between different call trees and between different nodes on the same tree. Again this analysis is done at compile time. If class members are used as tasks that it's not known at compile time how many instances of a particular class will be created at run time (remember that if task was a class member than each instance of a class would create a new task). This means that code can't be linked because it's not possible to allocate memory for variables. Technically it would be possible to use static class members for tasks but the compiler currently does not support this.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
...Perhaps Tasks cannot be member functions?...

 

Tasks can't be members of a class. The reason is in memory allocation for variables. Because there is no stack on PIC all memory allocation has to be done at compile time. Each task is handled as a start of a completely independent call tree. This was compiler and linker can overlay memory regions between different call trees and between different nodes on the same tree. Again this analysis is done at compile time. If class members are used as tasks that it's not known at compile time how many instances of a particular class will be created at run time (remember that is task was a class member that each instance of a class would create a new task). This means that code can't be linked because it's not possible to allocate memory for variables. Technically it would be possible to use static class members for tasks but the compiler currently does not support this.

 

Regards,

Pavel

 

Pavel,

 

Thanks for the response. Will the compiler support static class members as it relates to Novo RTOS in the future? Will there eventually be support for private and protected data?

 

Best,

 

Matt

Share this post


Link to post
Share on other sites
...Perhaps Tasks cannot be member functions?...

 

Tasks can't be members of a class...

 

Thanks for the response. So I know that Tasks can't be members of a class. Inside a task can I have class objects calling their own member functions? For example, I am using some of your Serial Interface code and I have created a class called CUart with send and receive member functions CUart::send, CUart::receive. In my main function I create and start a task, Task0 that contains your Serial code. Task0() resides in the same file as main and I have forward declared the uart class. I also have Tx and Rx functions declared in the same file as main and Task0() for troubleshooting:

 

class CUart *uart;

 

void Task0()

{

 

//Send out hello string (string should fit into the tx buffer)

Tx("Ready...");

//uart->send("Ready...");

 

//This task will receive data, transform it and send back

while(1)

{

//Wait for serial data to come. This is a blocking

//call that will yield if no data is available

unsigned char data = Rx();

//unsigned char data = uart->receive();

 

//If this is lower case character convert it to upper

if(data >= 'a' && data <= 'z')

data -= 'a' - 'A';

 

//Send data back

Tx(data);

//uart->send(data);

}

}

 

void Main()

{

SysInit();

SysCreateTask...

SysStartTask...

while(1) { Sys_Yield(); }

}

 

With the uart->send() and uart->receive() uncommented and Tx() and Rx() commented out the code compiles and links fine but will not run on the microcontroller (PIC18F4685). When I comment out uart->send() and uart->receive() and uncomment Tx() and Rx() the code will run on the microcontroller and I can interface with Hyperterminal.

 

I hope there is something simple I am doing wrong, like a linker command line argument or something of that nature. Thanks for your help.

 

Matt Fisher

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×