PropGCC equivalent of someVar := long[someAddress]?
JonnyMac
Posts: 9,565
As I stumble around PropGCC I found a bit of code that looks like this
I'm assuming that an address can be passed in *par -- how can I extract that like I would with long[parVal] in Spin?
void blinker(void *par)
{
while(1) {
high(26);
pause(1000);
low(26);
pause(1000);
}
}
I'm assuming that an address can be passed in *par -- how can I extract that like I would with long[parVal] in Spin?

Comments
In my code, I usually define a struct to hold all the data I want to pass via par, and then pass a pointer to that struct in.
I use the C++ feature of PropGCC, and that's a really handy way to pass an entire object to the new cog. I use it like this:
main.cpp:
void MyClassCogRunner(void * parameter) { MyClass::Configuration * temp = (MyClass::Configuration *) parameter; RecordFile(*temp); waitcnt(CLKFREQ / 10 + CNT); //Let everything settle down cogstop(cogid()); } ... ... <elsewhere...> ... MyClass::Configuration config; config.unitNumber = unitNumber; config.timestamp = CNT; cogstart(MyClassCogRunner, &config, myclassStack, stacksize);MyClass.h:
class MyClass { public: struct Configuration { int unitNumber; int timestamp; }; <class functions> }The problem with cogstart for C++ is that C++ class members have an implicit *this, which is lost with the cogstart. So, you have to cogstart a little runner function.
volatile int ledarray[] = { 26, 1000 }; // must be volatile so optimizer doesn't throw code away int bstack[50]; void blinker(void *par) ; void main(void) { cogstart(blinker, ledarray, bstack, sizeof(bstack)); } void blinker(void *par) { int *array = (int*) par; while(1) { high(array[0]); pause(array[1]); low(array[0]); pause(array[1]); } }The only difference is you need to cast void *par. As long as you always agree on the type (like in spin), it can be anything including a pointer to a structure, a pointer to a pointer, a pointer to an array, or single number.
This line "int ledarray = { 26, 1000 };"
should be "volatile int ledarray[] = { 26, 1000 };"
Sorry, I'm a little sick this weekend.
Using volatile says: "Look compiler, I don't care if you think what I'm doing with ledarray is wasteful. Do what I want."
int ledarray[] needs brackets [] to declare it an array. The brackets can have a number. I.E. int ledarray[2] = { 26, 1000 };