Shop OBEX P1 Docs P2 Docs Learn Events
Where is cog_run defined? (Working with P1 in c program) — Parallax Forums

Where is cog_run defined? (Working with P1 in c program)

In Simple IDE I can run a C program and use a cog_run command.
Trying the same program from Visual Source Code environment I get a cog_run unrecognized compiler error. I've looked through simpletools.h and everything it #includes also.
I'd swear I have everything available in my path, but I keep getting that error. As a test I put my own little .h file in the path and called a definition from it, so the path works.
Also, I can't actually see where in any of those files that cog_run is defined. Even cog.h doesn't seem to include anything I'd recognize as code.
I'd think there'd be something like this on the forum somewhere but I didn't find it after a few tries.

Comments

  • According to the documentation it's in simpletools.h (help, simple library reference, simpletools).

    So in Learn, Simple Libraries, Utility, libsimpletools, source.
    int *cog_run(void (*function)(void *par), int stacksize)
    {
      int *addr;
      addr = malloc(stacksize += 4 + 176 + (stacksize * 4));
      *addr = 1 + cogstart(function, NULL, addr + 4, stacksize - 4);
      if(*addr == 0)
      {
        free(addr);
        return (int*) 0;
      }
      return addr;  
    }
    

    Mike
  • Well, it's not in my simpletools.h, so I went through it all again and I discovered text in there that says " SimpleIDE compatible header file for FlexC" so now I have a sinking feeling that the FlexC is a kludged, semi-compatible collection of almost OK but not reliable replacements. I'll have to look into this some more and figure out what to do. Maybe I can ditch all their includes and switch back to the actual Parallax files so I can depend on things working. What's the point of having a C language collection for a Propeller if it doesn't support running code in cogs? There must be something I'm missing, but it's clearly not a direct replacement for the real code. What a disappointment.
    I tried adding that code into my simpletools.h and I get errors from incompatible pointer types but my code at least finds it and starts to compile, so probably there's some other code missing or incorrect in that file or some other include file in my collection from FlexC. Maybe I can find newer files, or ?
    Thanks for the clue that let me find this.
  • So it looks like maybe you're supposed to use cogstart() in FlexC and cog_run() doesn't exsist, even though that's the method that's used in SimpleIDE ??
    More research required. Clearly I'm missing some basic understanding of how Parallax is dealing with, or not dealing with, programming in C and what tools a person is supposed to use.
    I'm very disappointed so far.
  • jlastofka wrote: »
    Well, it's not in my simpletools.h, so I went through it all again and I discovered text in there that says " SimpleIDE compatible header file for FlexC" so now I have a sinking feeling that the FlexC is a kludged, semi-compatible collection of almost OK but not reliable replacements.
    That's really not a helpful attitude. The simpletools libraries and files use a whole bunch of non-standard GCC extensions, so they won't work in any of the other C compilers for the propeller (Catalina, FlexC, etc.). Basically they're tied to SimpleIDE. Some volunteers have made an effort to support some of simpletools on FlexC, and I for one am grateful for their efforts. But if you really want 100% compatibility with SimpleIDE you will have to use SimpleIDE.
    What's the point of having a C language collection for a Propeller if it doesn't support running code in cogs?

    Of course FlexC supports running code in cogs! Have you read the documentation? Or looked at any of the C samples in the FlexProp distribution? The _cogstart() function (which is standard across compilers) does this:
    ```
    int cogstart(void (*func)(void *), void *arg, void *stack, size_tstacksize);
    ```
    Starts the C function `func` with argument `arg` in another COG, using `stack` as its stack. Returns the COG started, or -1 on failure.
    

    See for example flexprop/samples/Multi-Language/mandelbrot.c.
  • jlastofka wrote: »
    So it looks like maybe you're supposed to use cogstart() in FlexC and cog_run() doesn't exsist, even though that's the method that's used in SimpleIDE ??
    More research required. Clearly I'm missing some basic understanding of how Parallax is dealing with, or not dealing with, programming in C and what tools a person is supposed to use.
    I'm very disappointed so far.

    Parallax DOES NOT officially support C on the Propeller 2. On the Propeller 1 their official product is SImpleIDE (based on propeller-gcc). So don't blame them for problems with FlexC and Visual Studio, which are neither of them Parallax products.

  • @jlastofka , why don't you use the code for cog_run that iseries posted? Since FlexC is a work in progress you will probably encounter several features that are in other compilers, but not yet in FlexC.
  • ersmith wrote: »
    jlastofka wrote: »
    So it looks like maybe you're supposed to use cogstart() in FlexC and cog_run() doesn't exsist, even though that's the method that's used in SimpleIDE ??
    More research required. Clearly I'm missing some basic understanding of how Parallax is dealing with, or not dealing with, programming in C and what tools a person is supposed to use.
    I'm very disappointed so far.

    Parallax DOES NOT officially support C on the Propeller 2. On the Propeller 1 their official product is SImpleIDE (based on propeller-gcc). So don't blame them for problems with FlexC and Visual Studio, which are neither of them Parallax products.

    Also, nothing is stopping anyone from using propeller-gcc in Visual Studio. The opposite even, VSC supports all the GCC-isms and none of the FlexC-isms.

  • I thought you were using simpleIDE and not flexprop.

    Yes, I changed my cog_run to _cogstart(function, params, stack, 40) where stack is "int stack[44]; " and params is NULL.

    Mike
  • Thanks for the tips and I'll look into them. It's confusing to sort out a working combination. My goal is to program my P2 board when it arrives soon, in addition to the P1. I learned SimpleIDE doesn't support P2, so I worked on setting up Visual Studio Code (first time using it) to work with the FlexProp compiler and loader. I had it working nicely on some examples. Then I tried bringing in a SimpleIDE program from a couple years ago to work with cog_run in it and wouldn't work (it used to) so I'm working on tat. I found cogstart and put that in but needed something else with it I think. Turns out the simpletools.h I had from FlexProp is different from the SimpleIDE one and I had to learn about that. Now I'm finding that simpletools.h has a couple of #includes in it (cog.h and sys/sd.h) that I can't find in either the SimpleIDE files or the FlexProp files. I don't understand how SimpleIDE compiles and runs without failing on those two #includes, but trying to run it through the FlexProp tools I'm calling from VSC does not work, nor does it work through FlexGUI either of course (same tools).
    I tried using the cog_run code that iseries provided earlier and couldn't make it work. I forget exactly, but I think it needed some other #includes or something. I see he's kindly provided a modification, which I'll try.
    I didn't mean to sound blaming or unappreciative of community supported tools or help. It's just exasperating to have to wade through so many stumbling blocks. I really want to like the P1 and P2 chips, but I'm having a hard time lining up a coherent set of tools for programming. I did spend a long time reading through the listings I had for simpletools.h and the #includes it called while searching out this stuff so I was surprised that iseries had it. That's when I discovered the FlexProp version was different. It was mentioned to use the gcc compiler. What about libraries to support cogs, etc? Another thing to think about or collect from somewhere. It goes on and on.
    I contrast this with using an Arduino where there's a nice integrated cross platform IDE and it just works. Probably one of the reasons they're so popular. I know the P1/P2 is a lot more capable and I want to use it. It's just a LOT of effort to get the software tools set up. I've done a fair amount of programming here and there over the years, but I've never had to get into this level of patching together the underlying tools, so it's a learning experience.
    Looking at this another way: I have my Mac and in a few days will have a P2 board in addition to my P1 board in a little robot now. I'd be willing to start over on choice of programming tools. Any recommendations?
  • jlastofka wrote: »
    I'd be willing to start over on choice of programming tools. Any recommendations?

    The Flex stuff is a good option on P2 if you want to write C. Also supports directly including spin/spin2 objects, which is very handy.

    You do it like this:
    struct __using("SimpleSerial.spin") my_serial;
    

    jlastofka wrote: »
    Now I'm finding that simpletools.h has a couple of #includes in it (cog.h and sys/sd.h) that I can't find in either the SimpleIDE files or the FlexProp files.

    I can see both of these files in my FlexC include directory, you must be looking in the wrong directory.

    Either way, you don't really need anything other than propeller.h / propeller2.h

    jlastofka wrote: »
    Turns out the simpletools.h I had from FlexProp is different from the SimpleIDE one and I had to learn about that.

    Never mix the default headers that come with different compilers. No good will come of it. Always keep them in a separate directories from each other and your own headers.
  • Sorry if I stepped on toes. I think I got misled by starting with the working examples I had from previous SimpleIDE use. Seems like I was trying to make that work by "fixing" missing stuff in the current tools. Now getting confused by help and advice with many variations in relation to my end goal. I'm going to reset and look into Spin and a new copy of FlexProp. I wanted C because I've used that forever with other microcontrollers and PIC chips. What looked like a kludge to me was because of a lack of understanding of Parallax haven given up on C. Seems amazing to me but it's not my call so I'll just deal with it. Seems like Spin is the way to have official software covering all the chip features. That's my plan now unless someone wants to correct me, or scold me, or poke fun or whatever:-)
  • Nah, all is well.

    Spin in FlexProp vs C in FlexProp isn't a huge difference, it all feeds into the same backend and has mostly the same built-in hardware functions and as said, you can mix the languages in any desired combination.

    The compare like this:

    Spin/Spin2:
    + most existing libraries are in Spin
    + seamlessly integrates data definitions and assembly code
    + has lots of useful (if at times odd) operators
    - light on language features: No structures, no dynamic allocation of objects, no typing, and many more. FlexSpin provides some useful extensions though.
    C:
    + Well known language (duh)
    + has structs and typing in general
    + FlexC supports some C++ features
    - FlexC isn't fully C standard compilant
  • Dave HeinDave Hein Posts: 6,347
    edited 2021-01-09 21:39
    jlastofka wrote: »
    ...What looked like a kludge to me was because of a lack of understanding of Parallax haven given up on C. Seems amazing to me but it's not my call so I'll just deal with it. Seems like Spin is the way to have official software covering all the chip features. That's my plan now unless someone wants to correct me, or scold me, or poke fun or whatever:-)
    I've always felt that Parallax should be more proactive in developing C tools. The simple matter is that Parallax can't afford the time or money to do it. They spent a few million dollars to develop the P2, and now they have to get some return on investment before they afford spending money on tools development. Personally, I think that Eric's approach with FlexProp is the way of the future for them. I'm amazed at the way he's been able to seamlessly integrate Spin, C, Basic and Pasm together.

  • I'm now using FlexProp with Spin on my P1 board and I'll have fun learning a new language. I'm sorry I didn't understand the Parallax / C / FlexProp relationship earlier. It's very fortunate we have the FlexProp tool. I see there's a Patreon to look into.

    If it helps anyone I have two things to offer. I wanted to run the Flex tools in Visual Studio Code and there's an issue with the Mac Gatekeeper protection. I couldn't see a system way to approve the files so I wrote a 4 line Python program to binary copy the files and then there's a simple UNIX command to make the file executable. After that the compiler and loader work from VSC. It works on a personal machine but couldn't (at least shouldn't) be distributed afterward. I also have a nice little workflow and key bindings set up in VSC. my name with a dot in the middle at Gmail if you want any details, but I suppose you guys have it figured out already.

    I'm surprised how quickly I got around the gatekeeper. I'm a retired engineer but maybe should have been a computer hacker:-)

    Jeff Lastofka
  • jlastofka,

    Since you are new to the Propeller start with the Propeller C tutorial which uses SimpleIDE.
    https://learn.parallax.com/tutorials/series/propeller-c-basics-and-projects

    If you have any questions feel free to ask as there are a number of C gurus.

    Here is a very useful link:
    https://learn.parallax.com/support/C/propeller-c-reference
  • Actually I'm not all that new to the Propeller or C. My last use of the Propeller was probably two years ago and a couple things seem to have changed since then, plus I was trying to get new tools set up. The combination was throwing me off and I got lost. If I were going to stick with C for this I'd go back over some of the introduction to get reoriented, but I've decided to switch over to Spin as it's pretty apparent that's where the real support is. Perhaps I'll want to mix in some assembly and C, as that appears to be fairly easy to do and I like trying things, but I think for basic robotics Spin should be fine. It's nice to have an offer of help, though. Thanks.
  • ersmithersmith Posts: 6,052
    edited 2021-01-10 02:35
    @jlastofka: yes, the situation with C on the Prop2 is very frustrating right now. Part of this is that it's still very early days for the P2 and the documentation is still being written. Parallax is a small company and I guess they only have resources to support a few sets of tools, and they've chosen to throw their support behind Spin2 and MicroPython. Perhaps if the P2 becomes more successful they'll be able to add some official C support to the mix. In the meantime we in the community are trying to do what we can.

    Sorry if I seemed a bit touchy earlier. You did have a good point about cog_run not being implemented in the FlexC simpletools implementation. It's not a difficult function to implement, so I've added that and the related cog_* functions to the current (github) version of FlexC.

    Thanks,
    Eric
  • jlastofka,

    Actually there hasn't been much Spin support since Propeller C was introduced to serve the Education market, but that has switched to BlockyProp.

    Spin and Assembly are native to the Propeller so that's the bulk of the code base although finding code can be frustrating since ObEx (Object Exchange) is gone.

    Your best using the Propeller Tool for Spin as a number of Objects and Demos come with it.
    For learning Spin I found the Propeller Education Kit textbook to be the best resource though it doesn't show how to use CONstants other than for setting the clock speed until near the end.

    You will also need the Propeller Manual which documents both Spin and PASM (Propeller Assembly).

    Use Propeller Tool 1.3.2 since you are using the P1 (All other versions include P2 support).
    https://www1.parallax.com/downloads/propeller-tool-software-windows-spin-assembly

    Propeller Education kit Text and Code are under Downloads
    https://www1.parallax.com/product/122-32305

    Propeller Manual
    https://www1.parallax.com/sites/default/files/downloads/P8X32A-Web-PropellerManual-v1.2.pdf
  • No worries. Things look worse in plain text. My "explanation" of being confused could have been taken as an actual attack on someone. I was lucky people here didn't get riled by it.

    I'll try Spin for a while, with your tools and VSCode plus a UNIX shell file. I'm not handling spaces in filenames yet. And I hard code in the .c or .spin for now. P2 hopefully Monday.

    I do Python, C++ and Swift in iCloud folders for desktop and laptop access, but there's a "~" in the path name and I think your tools didn't allow that, so I'm working locally for now. Is that an easy thing to add some time, or awkward? in there --> /Users/jefflastofka/Library/Mobile Documents/com~apple~CloudDocs/Programming/Swift
  • jlastofka wrote: »
    I do Python, C++ and Swift in iCloud folders for desktop and laptop access, but there's a "~" in the path name and I think your tools didn't allow that, so I'm working locally for now. Is that an easy thing to add some time, or awkward? in there --> /Users/jefflastofka/Library/Mobile Documents/com~apple~CloudDocs/Programming/Swift

    I just tried on Linux and ~ in file names seems to work fine there. Maybe it's a Mac shell thing? What kinds of problems are you having?
  • oops. It was the space in "Mobile Documents" and not the ~ messing with the UNIX shell. I know that trick but forget where it works and where it doesn't. Maybe screwing it up in front of the whole world this time will make me remember it:-)

    I also signed up for your Patreon this morning. Not a huge amount, but I have a lot of hobbies, so ....
  • jlastofka wrote: »
    oops. It was the space in "Mobile Documents" and not the ~ messing with the UNIX shell. I know that trick but forget where it works and where it doesn't. Maybe screwing it up in front of the whole world this time will make me remember it:-)

    I also signed up for your Patreon this morning. Not a huge amount, but I have a lot of hobbies, so ....

    Thanks, Jeff!

    The problem with spaces in file names is Mac specific, I think, and arises because of the osascript in mac_terminal.sh. I don't know how to re-quote the arguments to osascript. You may be able to avoid it in Visual Studio by running loadp2 directly with all the arguments properly quoted.
  • A backslash escape character in front of the space: /Mobile\ Documents/ works everywhere I've normally needed it to. I just sometimes forget. I've taken to eliminating spaces most everywhere since I've been playing with UNIX so much at the command line on the Mac. The Visual Studio setup I have has been working great for me.
Sign In or Register to comment.