http://sourceforge.net/projects/freertos/forums/forum/382005/topic/3778071 Resulting article by Richard Damon:
http://interactive.freertos.org/entries/223648-using-freertos-with-c Hi,
I’m trying to understand, how the code in the mentioned article works. This is way beyond anything I learned about C++ in school or books, so my current understanding is still a bit shaky. I’d be glad to put it on solid ground with your kind help.
class myclass {
public:
void taskfun();
} obj;
extern "C" void taskfunwrapper(void* parm) {
(static_cast<myclass*>(parm))->taskfun();
}
xTaskCreate(&taskfunwrapper, (const signed char*)"taskname", stackDepth, &obj, prioriry, NULL);
I couldn’t find anything about the way obj is defined, but I assume it’s similar to structs some sort of name, referring to this class. When creating the task, this name is passed as parameter to the handler which uses it to call the method in question.
What I don’t understand: Where do the instances of myclass come into play? How can I create several tasks with the same method but from different instances?
Or is obj already an instance of myclass? Would I then miss obj and pass on this instead of &obj in xTaskCreate? I believe Richard’s task-class does it this way.
Would the same trick be possible with ISRs? (probably not since one can’t pass parameters to them)Why is there a referencing-operator (&) with the taskname in xTaskCreate while there usually doesn’t have to be one? (Background: I’d like to have tasks as member methods and start/create them with the constructor of this very class.)