I am new to the XMOS environment and I am trying to get my feet wet. I think there is something I am failing to understand about channels. I am running two function simultaneously; one to measure the frequency of a button being pressed, while the other will request the frequency and print it. However, when I run the code it blocks and a<:1 and never enters the 1st case. What am I doing wrong? Thank you for your help.
Cheers,
Wowden
Code: Select all
/*test code*/
#include <platform.h>
#include <print.h>
void chopFreq( chanend chopI, chanend chopO, in port chop_ind);
void bar(chanend a, chanend b, in port B);
on stdcore [0]: in port But1 = PORT_BUTTON_A;
on stdcore [0]: in port But2 = PORT_BUTTON_B;
int main(void)
{ chan a,b;
par{
chopFreq(a,b, But1);
bar(a,b, But2);
}
return '0';
}
void chopFreq(chanend chopI, chanend chopO, in port chop_ind)
{ timer t;
int garbage=0;
unsigned time1;
unsigned time2;
unsigned freq=-1;
int state;
int count=0;
t:>time1;
while(1){
select{
case chopI :> garbage :
chopO <: freq;
break;
default:
chop_ind :> state ;
if(state==14){
count++;
chop_ind when pinseq(15):>void;
}
break;
}
if(count ==10){
t:>time2;
count=0;
freq=(time2-time1)/1000000;
t:>time1;
}
}
}
void bar(chanend b,chanend a, in port B){
int temp=1;
while(1){
B when pinseq(14) :> void;
a <: 1;
b :> temp;
printint(temp);
};
}