Page 1 of 1

Pin in select case hidden by too short pulse? Is one solution a buffered port?

Posted: Mon Mar 19, 2018 11:44 am
by aclassifier
I have a case like this, in a select. I wait for a pin change on a 1-bit port called p_spi_irq:

Code: Select all

case p_spi_irq when pinsneq(spi_irq_current_val) :> spi_irq_current_val:
However, it was never taken. I think the reason was that all pin changes happened while the task was not in the select.

When I moved this to a separate task which listened for that pin (same code) then it it was picked up. It then signalled on a channel that then replaced the code line above. It was of course also only taken when the code evaluated the select.

Could I have used a buffered input port for this and kept the original code (and saved a thread and a two chanends)? I can't find the exact code pattern in 6.9 Using a buffered port in XMOS-Programming-Guide-_documentation_F. If yes, how would the code be?-)

Re: Pin in select case hidden by too short pulse? Is one solution a buffered port?

Posted: Tue Mar 20, 2018 11:36 am
by Ross
Using an extra task is the safest way to do this. The purpose of buffered ports is not to patch up things like this.

You can put all your "pin" code in this task - buffer the data or similar - and then offload to a processing task - this would be a fairly standard pattern.

Re: Pin in select case hidden by too short pulse? Is one solution a buffered port?

Posted: Tue Mar 20, 2018 5:14 pm
by aclassifier
Thank you, Ross! I just saw that there is buffering in lib_spi, and I know that I am short of chanends etc.

That being said Ross, it could easily well have been the purpose of, or an aspect of, an(other) type of buffered channel to "store the pin change x" in the channel while the task was away from the select. It would have saved chanends and tasks. So I need, in addition to

Code: Select all

void pinseq(unsigned val);
void pinsneq(unsigned val);
void pinseq_at(unsigned val, unsigned time);
I would want something like these:

Code: Select all

void pinsoxeq(unsigned val); // also triggers if signal has been val but is not any more 
void pinsoxneq(unsigned val); // also triggers if signal has been neq but is not any more 
void pinsoxeq_at(unsigned val, unsigned time); // also triggers if signal has been eq but is not any more 
The added ox in there is for offline transition x. The code may want to read the present value of the pin when the select is taken.

These ox-calls should not require any chanends, threads or even clock or clock blocks. And no helping pin, either. Just that.

Wake me up. I just had a dream. It was a green place with bountiful channels and threads..