Need help with startcog in LMM mode c++
Anubispod
Posts: 42
Hi here is my my code what i want to get to run in c++.
So to explain a bit , i have 2 spin files what i have run trough spin2cpp and got 4 new files
See attachments i converted it with --main to make the MPU6050_Demo as main file to run from .
All works well till i get to the point to start the loop from MPU6050_XS in a new cog like i do in spin .
My spin code works well i get in the cog 150 reads of sensor data per sec and stored in the buffer
But i would like to get it to run in gcc to see if it makes speed difference
Best regards Oliver. R
So to explain a bit , i have 2 spin files what i have run trough spin2cpp and got 4 new files
See attachments i converted it with --main to make the MPU6050_Demo as main file to run from .
All works well till i get to the point to start the loop from MPU6050_XS in a new cog like i do in spin .
My spin code works well i get in the cog 150 reads of sensor data per sec and stored in the buffer
But i would like to get it to run in gcc to see if it makes speed difference
int32_t MPU6050_XS::Start_loop(void) { int pin =0; int foo= 0; int stacksize = sizeof(_thread_state_t)+sizeof(int)*3; int *stack = (int*) malloc(stacksize); int cog = cogstart(&MPU6050_XS::Loop, (void*) pin, stack, stacksize); return 0; }
int32_t MPU6050_XS::Loop(int32_t Ptr) { int32_t _parm__0000[4]; _parm__0000[0] = Ptr; while (1) { _parm__0000[1] = _i2cack; if (I2cstarted == -1) { I2cstart(); _parm__0000[1] = ((_parm__0000[1] << 1) | I2cwrite((0xd0 | 0x0), 8)); _parm__0000[1] = ((_parm__0000[1] << 1) | I2cwrite((Ra_accel_xout_h << 24), 0)); I2cstart(); _parm__0000[1] = ((_parm__0000[1] << 1) | I2cwrite((0xd0 | 0x1), 8)); _parm__0000[2] = 0; _parm__0000[3] = 13; { int32_t _idx__0001; _idx__0001 = _parm__0000[3]; do { ((uint8_t *)(int32_t)(&_parm__0000[0]))[_parm__0000[2]] = I2cread(_i2cack); (_parm__0000[2]++); _idx__0001 = (_idx__0001 + -1); } while (_idx__0001 >= 1); } ((uint8_t *)(int32_t)(&_parm__0000[0]))[_parm__0000[2]] = I2cread(_i2cnak); I2cstop(); } else { _parm__0000[1] = _i2cnak; } Lastackbit = _parm__0000[1]; } return 0; }Error log
int32_t MPU6050_XS::Loop(int32_t Ptr) { int32_t _parm__0000[4]; _parm__0000[0] = Ptr; while (1) { _parm__0000[1] = _i2cack; if (I2cstarted == -1) { I2cstart(); _parm__0000[1] = ((_parm__0000[1] << 1) | I2cwrite((0xd0 | 0x0), 8)); _parm__0000[1] = ((_parm__0000[1] << 1) | I2cwrite((Ra_accel_xout_h << 24), 0)); I2cstart(); _parm__0000[1] = ((_parm__0000[1] << 1) | I2cwrite((0xd0 | 0x1), 8)); _parm__0000[2] = 0; _parm__0000[3] = 13; { int32_t _idx__0001; _idx__0001 = _parm__0000[3]; do { ((uint8_t *)(int32_t)(&_parm__0000[0]))[_parm__0000[2]] = I2cread(_i2cack); (_parm__0000[2]++); _idx__0001 = (_idx__0001 + -1); } while (_idx__0001 >= 1); } ((uint8_t *)(int32_t)(&_parm__0000[0]))[_parm__0000[2]] = I2cread(_i2cnak); I2cstop(); } else { _parm__0000[1] = _i2cnak; } Lastackbit = _parm__0000[1]; } return 0; }
Best regards Oliver. R
Comments
I don't think it needs to be static, at least if you are compiling with g++. But it reminds me: I think the function prototype should be something like:
You should also include a cogstop(cogid()) as the very last line of the function, otherwise your cog will keep running (waiting) and take up resources.
Yes, I think you're right Steve. If it isn't static then there's an implicit first argument (the "this" pointer) which the cogstart function won't set up correctly.
Eric
I have rewritten the spin code from the loop i wanted to run in the cog to pasm and now the spin2cpp did a better job.
So for other on the hunt for a starting point for the MPU6050 can look at those files. i included spin_pasm and c++ for c just shoot it trough the spin2cpp and it works.
Best regards
Oliver.R
Yes.
That's probably true for functions that terminate. It never occurred to me.
I've updated propeller-gcc cogstart page entry. https://sites.google.com/site/propellergcc/documentation/libraries/propeller-h-library?pli=1#TOC-cogstart
Thanks!
Well, I checked, and here is what I have:
1. A "void functionName(void * param)" function, in the global namespace
2. The propeller-elf-g++ compiler
3. Called cogstart from the main() function.
4. It seems to work.
I don't know if there is an implicit "this" pointer, however. And I haven't tried putting the cogstart'd function in a class, so it may be an issue there. I'd be interested to hear if it is.
Is that sites.google.com page generated from a C/C++ source file, or is it edited directly from the sites.google.com editor? I don't want to add additions to it if it's generated from source.
ps: I've also added an FAQ related to cogstart.
Most of the propeller.h page was generated using Doxygen and fixed up by hand. The code was created first and pasted into a google text gadget. You can click on the properties to bring up a regular text editor on the site.
Thanks for working on the FAQ. It has lots of good info in it.
I should have been clearer -- the "static" is necessary only for class members. Global functions will be fine without it (there's no "this" for a global function). But class members will need to be "static", which for a class indicates that it behaves the same for all objects.