Hello,
I have got a little problem in XC and cannot figure out how to solve it effectively.
I'm using an L1/128, and I have to wait for a condition on port to execute a defined function.
Waiting for some condition on a Port is easily handled by while pinseq(n)/pinsneq(n) where n is the port value.
The problem with this solution is that pinseq(nn)/pinsneq(nn) does wait for a DEFINED condition (or reverse cond) to happen!!!
My problem:
I want to detect any pin change, it means I don't know final state, I need to wait for any pin change to start my function.
is there any technique to do it in an effective way? actually I'm using cascaded tests but this means my processor will keep active while the pinseq/pinsneq has the advantage of putting the mcu in a low power mode.
Regards
Port state change detection
-
- XCore Addict
- Posts: 228
- Joined: Thu Jan 27, 2011 3:30 pm
- Location: Argenteuil - France
-
- Experienced Member
- Posts: 104
- Joined: Fri Dec 11, 2009 8:29 pm
octal wrote: My problem:
I want to detect any pin change, it means I don't know final state, I need to wait for any pin change to start my function.
is there any technique to do it in an effective way?
The pinseq/pinsneq can take a variable as an argument. The following code waits for a change in pin value by sampling on the pin and then setting the condition to be anything but what it just sampled:
Code: Select all
#include <xs1.h>
void wait_for_change(port p) {
int x;
p :> x;
p when pinsneq(x) :> x;
return;
}
Dave
-
- XCore Addict
- Posts: 228
- Joined: Thu Jan 27, 2011 3:30 pm
- Location: Argenteuil - France
Hi Davelacey,
sorry I explained very badly my problem :oops:
What I want to detect is the change of pins state regarding a certain mask. What I can't do is OR-ing two or more final states.
For example I want to exec my function (code) right after having either 0b11111011 or 0b11111111.
I mean starting from any state, I want to exec my code when I have any situation that conforms to 0b11111x11 (x being either 1 or 0).
I want to be able to define any (composition of) mask in the style 0b11xx1x11 for example and have the system execute my code right after the input conforms this mask.
What could be the best solution?
sorry I explained very badly my problem :oops:
What I want to detect is the change of pins state regarding a certain mask. What I can't do is OR-ing two or more final states.
For example I want to exec my function (code) right after having either 0b11111011 or 0b11111111.
I mean starting from any state, I want to exec my code when I have any situation that conforms to 0b11111x11 (x being either 1 or 0).
I want to be able to define any (composition of) mask in the style 0b11xx1x11 for example and have the system execute my code right after the input conforms this mask.
What could be the best solution?
-
- Active Member
- Posts: 38
- Joined: Tue Jul 13, 2010 2:57 pm
I'm not really an expert on XMOS (jet 8-) ) but think (as studied from the instruction behaviour) that you can only specify an "exact" match as being met or no - pinseq(x) or pinsneq(x)
Depending on the use-case (are you doing the select/case in an (infinite loop?)) my suggestion would be something like this
depending on the requirements you could change the value of lastState in the case block as needed.
If you have no loop... well, than you should make one ;)
this loop should repeat the select/case until your exact condition are met.
I hope this makes sense....
regards,
mculibrk
Depending on the use-case (are you doing the select/case in an (infinite loop?)) my suggestion would be something like this
Code: Select all
unsigned lastState, newState;
lastState = peek(PORT);
while(1) {
select {
case PORT when pinsneq(lastState) :> newState:
if (newState & lastState == REQUIRED_STATE) {
do_what_you_need();
}
break;
}
}
If you have no loop... well, than you should make one ;)
this loop should repeat the select/case until your exact condition are met.
I hope this makes sense....
regards,
mculibrk