Multiple Cogs accessing I/O pins
hacktorious
Posts: 72
I'm writing a C program on a prop and am trying to figure out the best way to use multiple cogs.
I was attempting to access an IO pin in a second cog via cogstart.
In main I set a pin as an input and all is well, I can access it in main. However, if I have another method being started with cogstart I cannot create an input on a different I/O and access it. It seems I have to create the input in main as a global then access it from the other cog. Does this sound correct?
Here is a hybrid pseudo code example:
void some_method(void);
main {
static volatile int input_x;
execute cogstart for some_method here
while(1){
input_x= input(22);
}
}
void some_method(void){
while(1){
if input_x is on do something
}
}
I was attempting to access an IO pin in a second cog via cogstart.
In main I set a pin as an input and all is well, I can access it in main. However, if I have another method being started with cogstart I cannot create an input on a different I/O and access it. It seems I have to create the input in main as a global then access it from the other cog. Does this sound correct?
Here is a hybrid pseudo code example:
void some_method(void);
main {
static volatile int input_x;
execute cogstart for some_method here
while(1){
input_x= input(22);
}
}
void some_method(void){
while(1){
if input_x is on do something
}
}
Comments
https://sites.google.com/site/propellergcc/documentation/libraries/propeller-h-library#TOC-cogstart
In general I make it a practice to only use an I/O pin from a single cog. I have the other cogs set flags to indicate if an I/O pin should be changed so the cog "in charge" of that particular I/O pin can make the needed changes.
BTW, if you edit your post and choose "Go Advanced" it will let you edit the subject.
While you can edit the subject, you can't edit which forum the post is in. This thread was posted to the wrong forum but only moderators can move threads.
Thanks. Your right, its in the wrong forum. Sorry.
Only one cog with a flag sounds like a good idea.
Unfortunately this was not helpful. DIRA, INA and OUTA do absolutely nothing when attempting to use cogstart. Maybe I'm doing something wrong, but compared it to the spin stuff and it doesn't seem to work. Here is what I tried:
main
cogstart
some_method()
DIRA |= 0 << 21; //set to input
while(1){
if(INA |= (1 << 21))
//Do something....
}
Is there a better example which uses an INA somewhere? I cannot seem to find much. Thanks.
Yes, that may be it. Thanks.
What is the difference between using the above or just the input(21) method? Input seems a lot cleaner.
Gotcha... Thanks. Nice signature by the way!