Shop OBEX P1 Docs P2 Docs Learn Events
While loop problem starting new cog — Parallax Forums

While loop problem starting new cog

spinbobspinbob Posts: 27
edited 2013-06-13 14:31 in Learn with BlocklyProp
First a few details. Program written in spin, converted to C with spin2cpp. 12K of code compiles without errors. Our unit (custom PCB) has a display on a I2C bus that I use for feedback as to code running. Here is the problem:
In the Main() I do this:
Init a new cog to gather data which is in another C file. In the new cog I init a couple variables then sit in a while(1) loop reading the A/D and storing values. This is where the trouble lies. If I remove the while loop then the rest of the code in my Main works fine but with the while loop in place the unit hangs up, no display. All this code runs fine in it's spin form.
Thanks

Comments

  • SawmillerSawmiller Posts: 276
    edited 2013-06-13 11:58
    Would it be better for the new cog to store in global variables?
    Don't know but if you looking for those variables' got to pass them somehow
  • spinbobspinbob Posts: 27
    edited 2013-06-13 12:07
    At this point I'm not even using the variables. Here is some code to view, this is new cog code. My main will only run if the while loop is commented out. It must be something to do with the cog not starting correctly.

    int32_t Spin_Start()
    {
    thisobj.Cog = (cognew(Spin_Main(), (int32_t)(&thisobj.Stack)) + 1);
    return 0;
    }


    int32_t Spin_Main()
    {
    thisobj.K1 = 2;

    while (1) {

    // Spin_Calculate();
    }
    return 0;
    }
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-06-13 13:15
    I don't think spin2cpp supports a cognew/coginit of Spin methods. If you look at the readme file that comes with spin2cpp it lists that as one of the limitations. It does support cognew/coginit for PASM cogs.
  • SawmillerSawmiller Posts: 276
    edited 2013-06-13 13:30
    there are some methods in propeller.h i think
    c:/propgcc/propeller-elf/include
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-06-13 13:43
    @Sawmiller, propeller.h contains definitions for intrinsic functions and registers.

    @spinbob, you will have to re-write your spin program to run a PASM cog instead of a Spin cog. Or you could modify the generated C++ code to use pthread_create instead of cognew.
  • spinbobspinbob Posts: 27
    edited 2013-06-13 14:31
    I will look into all these. I compiled this into C. The spin converter generated this code so does it not understand because I didn't use the correct switches? I only used --ccode. Thanks. I'm off to read more of the manual.
Sign In or Register to comment.