Is it possible to cancel a timed port output ?

Technical discussions around xCORE processors (e.g. General Purpose (L/G), xCORE-USB, xCORE-Analog, xCORE-XA).
hybridalienrob
Member
Posts: 11
Joined: Thu Nov 20, 2014 9:19 pm

Is it possible to cancel a timed port output ?

Post by hybridalienrob »

If I setup a timed output on a port e.g

p @ count <: 1; // timed output

is it possible to 'cancel' that timed output and re-program the pin to output on a different clock edge ?

I'm working on a variable frequency clock generator and would like to be able to change the period of the clock on the fly, anywhere during the cycle rather than waiting till the end of the cycle like I currently do. At the moment, I have a thread which wakes on a timer to trigger the next clock transition or a chanend input of a new clock period.


User avatar
infiniteimprobability
XCore Legend
Posts: 1124
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

Yes - you can clear the buffers by calling start_port(my_port); which re-initialises the port.

For example:

Code: Select all

#include <xs1.h>
#include <timer.h>
#include <stdio.h>

#define DELAY   100 //number of 10ns ticks

out port p = XS1_PORT_1A;

int main (void){
    short port_time;

    p <: 1 @ port_time; //get timestamp
    p  @ (port_time + DELAY) <: 0; //schedule transition in DELAY ticks
    start_port(p);
    p  @ (port_time + (DELAY / 2)) <: 0; //schedule transition in DELAY/2 ticks
    delay_microseconds(2); //wait for output to happen before sim quits

    return 0;
}
Results in a falling transition at 50 ticks later, Ie. the 100 tick transition has been cancelled.

Beware though - the port timer comparison is "equals" only. If you miss the compare match (ie next transition has already passed by the time the instruction gets issued), then the output will not be shceduled until the timer wraps around again (unlike normal timers with timerafter). You may need a SW check against this.

It's a 16b counter in the port so about 655us - http://www.xcore.com/questions/2026/wha ... timers-xs1

Recommended bedtime reading - have a look through <xs1.h> and https://www.xmos.com/download/public/In ... s(1.0).pdf

There are some really nice tips and tricks in there..
User avatar
Ross
XCore Expert
Posts: 768
Joined: Thu Dec 10, 2009 9:20 pm

Post by Ross »

There is also a clrpt (Clear Port Time) instruction (page 71 of architecture manual). You can use a bit of inline asm to target it, something like the following:

Code: Select all

asm volatile("clrpt res[%0]"::"r"(portname));
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

Does CLRPT clear the port buffer? It doesn't say that anywhere
explicitly afaics, but how would it work otherwise :-)

Resetting the port is not such a great idea, for many
applications: it tristates the pins, it takes 50ns or whatever
before they can be switched to output again.
hybridalienrob
Member
Posts: 11
Joined: Thu Nov 20, 2014 9:19 pm

Post by hybridalienrob »

Thanks for your responses.

So to clarify : start_port() effectively resets the port (back to high-z) ?

Whereas CLRPT (clear port time) looks like exactly what I'm after

from https://www.xmos.com/download/public/Th ... 1.0%29.pdf
"
RPT clearporttime(p) clear port time
GETTS d timestampp get port timestamp

The CLRPT instruction can be used to cancel a timed transfer.
"
Thanks again
Rob
User avatar
infiniteimprobability
XCore Legend
Posts: 1124
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

Resetting the port is not such a great idea, for many
applications: it tristates the pins, it takes 50ns or whatever
before they can be switched to output again.
Good point - and a reminder why simulating this stuff is not always enough (you don't see high impedance states on output waves..)