cog_run
pilot0315
Posts: 908
I am attempting to run my gps driver in a second cog. Starting small by sending the raw sentances or parsing out a single portion. The compliler gives me errors saying that it discards the volatile qualifier for the variable so as to work between cogs. The only examples I can find about passing data between the cogs is in the learn files using a single int. Anybody got any Ideas??
Thanks
Thanks
Comments
The way you'd normally do this is to have a buffer that the cog works with that it then transfers to another that the main code uses, and a signal variable of some kind to tell the main code that the values are ready. *That* variable would be declared volatile.
I've modified your code to demonstrate how I'd do it. (I haven't compiled this)
http://stackoverflow.com/questions/4437527/why-do-we-use-volatile-keyword-in-c
In short, if you have the same variable accessed from two different cogs, that variable should be marked as volatile (unless it is a constant).
Compilers generally assume your code is a single thread, so only one function can access anything at a time. This means within a single function, they can load a value into a register, then use it from that register for the duration of the function. If another thread can change that variable this will obviously break, so that's what volatile is used for.
Thanks
g++ and gcc both compile C++ code, but they will use the file extension to determine the language. You can override with -xc++ though if you don't want to rename your file from *.c to *.cpp
It will if you #include <stdbool.h>.
(Or you can compile in C++ mode, as others have suggested.)
while( dataReady == true ) {
;
}
Project Directory: F:/GPS WORKS IN C/
SimpleIDE Version 1.0.2
C:/Users/martin/Documents/SimpleIDE/Learn/Simple Libraries/
C:/Users/martin/Documents/SimpleIDE/ Updated on: 2015-11-21
propeller-elf-gcc.exe -v GCC 4.6.1 (propellergcc_v1_0_0_2408)
propeller-elf-c++ -I . -L . -I C:/Users/martin/Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools -L C:/Users/martin/Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/cmm/ -I C:/Users/martin/Documents/SimpleIDE/Learn/Simple Libraries/Text Devices/libsimpletext -L C:/Users/martin/Documents/SimpleIDE/Learn/Simple Libraries/Text Devices/libsimpletext/cmm/ -I C:/Users/martin/Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c -L C:/Users/martin/Documents/SimpleIDE/Learn/Simple Libraries/Protocol/libsimplei2c/cmm/ -I C:/Users/martin/Documents/SimpleIDE/Learn/Simple Libraries/Text Devices/libfdserial -L C:/Users/martin/Documents/SimpleIDE/Learn/Simple Libraries/Text Devices/libfdserial/cmm/ -o cmm/plain gps 2 (1).elf -Os -mcmm -m32bit-doubles -fno-exceptions -fno-rtti -std=c99 plain gps 2 (1).c -lm -lsimpletools -lsimpletext -lsimplei2c -lfdserial -lm -lsimpletools -lsimpletext -lsimplei2c -lm -lsimpletools -lsimpletext -lm -lsimpletools -lm
cc1plus.exe: warning: command line option '-std=c99' is valid for C/ObjC but not for C++ [enabled by default]
plain gps 2 (1).c: In function 'int main()':
plain gps 2 (1).c:49:30: error: invalid conversion from 'void (*)()' to 'void (*)(void*)' [-fpermissive]
C:/Users/martin/Documents/SimpleIDE/Learn/Simple Libraries/Utility/libsimpletools/simpletools.h:1404:6: error: initializing argument 1 of 'int* cog_run(void (*)(void*), int)' [-fpermissive]
plain gps 2 (1).c: In function 'void getdata2()':
plain gps 2 (1).c:94:18: error: invalid conversion from 'volatile char*' to 'const char*' [-fpermissive]
c:\program files (x86)\simpleide\propeller-gcc\bin\../lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/include/string.h:14:8: error: initializing argument 2 of 'char* strcpy(char*, const char*)' [-fpermissive]
plain gps 2 (1).c:97:34: error: invalid conversion from 'char' to 'char*' [-fpermissive]
c:\program files (x86)\simpleide\propeller-gcc\bin\../lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/include/string.h:14:8: error: initializing argument 1 of 'char* strcpy(char*, const char*)' [-fpermissive]
plain gps 2 (1).c: In function 'void print_data()':
plain gps 2 (1).c:119:11: warning: unknown escape sequence: '\N' [enabled by default]
Done. Build Failed!
Click error or warning messages above to debug.
If you want, you can try PropWare's Runnable class. It does not require any other dependencies from PropWare, so it's very easy to add to your project.
Here's an example using it to blink pin 16 in a separate cog, while the first cog runs a basic print routine. This example of course uses PropWare's Pin class, but PropWare::Runnable will work just as well with any of the libraries from Simple
Full source for PropWare::Runnable in Git.
And a shortened copy/paste version without comments:
If you wanted to use more of the PropWare libraries, you can use them in SimpleIDE via the instructions at the top of this page.
Place it in the same folder as your .cpp and .side files.
It's not a bug. I'm afraid I don't have time this instant to dig up the link to other forum threads that explain the steps, but you search you around you can find other people that have asked how to enable "project view".
- Go to Tools -> Properties
- Click the "View mode" check box on the "General" tab
- Click Ok
- Go to Tools -> Set Project View
It does actually. It's just very well hidden. I think they hid it so well to ensure folks didn't accidentally make the IDE complex/confusing.