Mixed model - impressions and question
ypapelis
Posts: 99
I have been using the propeller for over three years now, have written tons of Spin and Pasm programs and even though I am a C/C++ guy, never got around to using Catalina because it seemed so awkward and never had the need for larger size programs in the propeller. I finally decided to give propgcc a try and I am absolutely impressed with the capabilities it brings to the prop. Great job, propgcc team! In particular, I love the idea of being able to write C and have it run in COG mode; for simple bit manipulations as typical in device drivers, the compiler output is pretty darn close to hand wirtten PASM and I think that except for special cases, PASM programming could become obsolete!
In any case, my primary interest is mixed LMM COG mode, as most of my projects use a mix of SPIN and pasm. I saw the mixed mode toggle demo(cog_c_toggle) and had some questions, most of which I have some answer but want to confirm that my understanding is correct, so I would appreciate a direct response:
1) Is a makefile required for building the project, or does the .side file contain all the build instructions?
2) what is the difference between 'Add File Copy' and 'Add File Link' in the project manager?
3) In the second argument of the cognew() function, should there always be a stack at the top of the structure? Is that the stack used for function calls within the cog code?
4) For finding the name of the code that goes in a COG (passed to the cognew function), Is there a better way than generating a map file and looking it up? Is it always _load_start_MYFUNCTION_cog ?
4) what is the best way to check the size of a cog function to make sure it stays within the size allowed for COG memory?
Again, great job, can't wait to use this for my upcoming projects!
-YP
In any case, my primary interest is mixed LMM COG mode, as most of my projects use a mix of SPIN and pasm. I saw the mixed mode toggle demo(cog_c_toggle) and had some questions, most of which I have some answer but want to confirm that my understanding is correct, so I would appreciate a direct response:
1) Is a makefile required for building the project, or does the .side file contain all the build instructions?
2) what is the difference between 'Add File Copy' and 'Add File Link' in the project manager?
3) In the second argument of the cognew() function, should there always be a stack at the top of the structure? Is that the stack used for function calls within the cog code?
4) For finding the name of the code that goes in a COG (passed to the cognew function), Is there a better way than generating a map file and looking it up? Is it always _load_start_MYFUNCTION_cog ?
4) what is the best way to check the size of a cog function to make sure it stays within the size allowed for COG memory?
Again, great job, can't wait to use this for my upcoming projects!
-YP
Comments
You don't need a Makefile, a .side file is enough.
If you use "Add File Copy", the file is copied to the same directory as the .side file and the .side file is made to refer to the copied file; if you use "Add File Link", it just uses the file that you point at. If the file is already in the same directory as the .side file, I think it doesn't make a difference which one you use.
The memory in front of the PAR pointer (i.e. negative offset) is used as stack, but only if the compiler runs out of pseudo-registers. The registers r0-r14 are stores in the first locations of cog memory, where they overlap/overwrite the initialization code. Whether the stack is actually used, depends on your code: If your call level is not very deep and you don't need many registers, it probably won't be used at all because the compiler will just use registers to store parameters and locals. The only way to know for sure is to inspect the Assembler code. Or you could add some lines to your code to inspect ((unsigned *)PAR)[n] for n=-1, -2, -3 etc. The stack will grow from the top down (index -1 is written first, then -2, -3 etc).
The name is always _load_start_FILENAME_cog (where FILENAME is the base name of the .cogc file). Note, the function name in the cogc that gets called first should have the void main(void *) or void main(void) prototype, otherwise you'll get a weird fatal error message from the linker that kinda makes it look as if your code is too big to fit. I think this is because the linker will try to let the initialization code jump to your program's main( ) function instead of your cog's main( ) function, and the program main( ) is in another memory segment in the executable.
The compiler will generate an error if it's too big, but otherwise the only way to check the size is to inspect the Assembly output by right-clicking the file in SIDE and selecting "Show Assembly". By the way, when using a .cogc module you're not limited to one function; you can use as many functions as you want, as long as they will fit in a cog.
===Jac
Regards
Jac! Thanks for giving such a great detailed response.
There is also a brief wiki page on using COG mode. Anyone is welcome to add comments for improving the wiki content.
COGC mode can be difficult. Providing a stack, using function/variable type modifiers, and limiting function call depth helps.
--Steve
===Jac
Hi Jac, PM me your google login email. I'll add you to the documentation contributors list.
Thanks
===Jac