Where is cog_run defined? (Working with P1 in c program)
jlastofka
Posts: 35
in Propeller 1
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.
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
So in Learn, Simple Libraries, Utility, libsimpletools, source.
Mike
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.
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.
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:
See for example flexprop/samples/Multi-Language/mandelbrot.c.
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.
Yes, I changed my cog_run to _cogstart(function, params, stack, 40) where stack is "int stack[44]; " and params is NULL.
Mike
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?
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:
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
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.
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
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
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
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
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
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
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?
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.