Port Counter Event

Technical questions regarding the XTC tools and programming with XMOS.
shaw
Experienced Member
Posts: 64
Joined: Fri Mar 25, 2011 12:36 am

Port Counter Event

Post by shaw »

Hi,

What is the correct method to read a buffered/clocked port counter, and then block while waiting for X cycles of the clock to expire. Then Unblock and continue normal execution. Something like this.
----
buffered out port:32 p_bclk = XS1_PORT_1B;
in port inClock = XS1_PORT_1C;
clock clk = XS1_CLKBLK_1;
unsigned int count = 0;

int function_name(void)
{
...
configure_clock_src(clk, inClock);
configure_out_port_no_ready(p_bckl, clk, 0);
start_clock(clk);

// READ PORT count, but I don't want to write a 0 (or a 1) to the port, as part of the count read
p_bclk <: 0 @ count;

count += 3;
// Block for 3 clock cycles, then resume execution. Not sure of the best way to use XC to do this.
...
}

I appreciate the help,
User avatar
Ross
Verified
XCore Legend
Posts: 1183
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

Code: Select all

p_bclk <: 0 @ count;
For the above, XC will block until the output completes then get the timestamp. If you just want the timestamp with out a port input/output you would have to use some inline assembly to access the getts instruction, e.g:

Code: Select all

asm volatile(" getts %0, res[%1]" : "=r" (time_stamp) : "r" (p_bclk));
You can then do your timed output using this value as normal, this will block until completed.

Code: Select all

p_bclk @ time_stamp + 3 <: 0
Technical Director @ XMOS. Opinions expressed are my own
shaw
Experienced Member
Posts: 64
Joined: Fri Mar 25, 2011 12:36 am

Post by shaw »

got it, thanks