How to start a c-function in another cog
Hi,
in the help-file of flexprop, it says:
_cogstart_C
int _cogstart_C(void (*func)(void *), void *arg, void *stack_base, uint32_t stack_size)
Starts C code in another COG. func is the address of a C function which expects one argument, and which will run in another COG (cpu core). arg is the argument to pass to the function for this invocation. stack_base is the base address of a block of memory to use for the stack. stack_size is the size in bytes of the memory.
I don't know, what a 'void *arg' is. My code does crash invoking:
char stack1[2000];
int dummy;
....
main {
...
_cogstart_C(MC6809Exec(),&dummy,&stack1[0],2000);
....
}
Here: https://forums.parallax.com/discussion/172036/catalina/p4
it's just:
_cogstart_C(func, arg, stack_base, stack_size);
But that does crash too.
Where can I find a working example?
Many thanks!
Edit: Even more confusing:
_cogstart_C(MC6809Exec(),dummy,2000,stack1);
gives
error: Expected pointer to stack as last parameter to coginit/cogid
Comments
Cog program example:
Mike
Thanks, Mike!
Now found out via experiment:
works.
So @Eric: would you like to update the Help file and include an example?
Specified stack size will be in bytes I'd think. The usual way to handle such is:
_cogstart_C(MC6809Exec,dummy,stack1,sizeof(stack1));
Oh, the crash was because
MC6809Exec()
, with the brackets, tries to call that function, rather than passing its address to thecogstart()
.@"Christof Eb." Thank you for the feedback, I will add some examples to the docs.
_cogstart_C
is provided for compatiblity with other C compiilers (like Catalina and PropGCC). If you're just using FlexC, then_builtin_cogstart
is the easiest method to start a function in another COG. It's a special macro unique to FlexC, and the first argument is just the function call you want to happen in another COG, and the second is that starting address of the stack: