Read simultaneously from two different ports

If you have a simple question and just want an answer.
RValls
New User
Posts: 2
Joined: Fri Jun 05, 2015 8:21 am

Read simultaneously from two different ports

Post by RValls »

Hi everyone!

Can someone explain me (and post some code, please) how can two different ports be read simultaneously in xC?

With more details, I have one input port acting as clock of two other input ports. All of them are 1 bit ports. How can I read the data of the two ports at the same time?

All of my tests have always behavioured the same way: the uC hangs until the first read is done, and then performs the second read. This is not what I want, since I loss the data on the second port...

I think this should be done with timed inputs and so, but I cannot get it done.

Best regards and thanks for your help

Ruben

User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am

Post by mon2 »

Hi Ruben. Some ideas:

a) Use buffered ports so that you may continue to perform other tasks while the buffered port will read in the background for the depth of the port.

As an example, an 8 bit I/O port could be defined as a buffered 32 bit port which will allow for the 8 bit physical port to read 8 bits per clock cycle for 4 clocks without an overflow and without user intervention.

Use the buffered ports with the @time feature.

Apply the same @time offset for your multiple input ports to be sampled at the same time.

This should result in your multiple ports to perform the input (reading) task from the outside world only when the @time offset is reached sometime in the future but at the same time.

Example of code:

/*
 * multibit.xc
 *
 *  Created on: Jun 9, 2015
 *
 */

#include <xs1.h>

in buffered port:32 inPA     = XS1_PORT_8A;
in buffered port:32 inPB     = XS1_PORT_8B;
in port             inClock  = XS1_PORT_1A;
clock    clk     = XS1_CLKBLK_1;

int main(void) {

int count;
int sampleA, sampleB;


  configure_clock_src(clk, inClock);
  configure_in_port(inPA, clk);
  configure_in_port(inPB, clk);
  start_clock(clk);

while(1)
 {

    // timestamped input (read) -> ignore read value
    // purpose is to set count variable to the
    // port counter value
    inPA @ count :> void;

    // wish to read from 2 different ports at the
    // same time but 10 clock cycles in the future
    count += 10;

  inPA @ count :> sampleA;  ; sampleA will hold a 32 bit sample of your input data from XS1_PORT_8A
  inPB @ count :> sampleB;  ; sampleB will hold a 32 bit sample of your input data from XS1_PORT_8B
 }
}

There are other ideas you can test including the sync command such as shown here:

https://www.xmos.com/published/xc-port- ... g?secure=1

topic Synchronising Clocked I/O on Multiple Ports & use buffered ports with this sync feature to clock in data on same clock cycle. The premise here is that on the next falling edge of the clock cycle, you will initiate the sampling of your first input port and then immediately follow to do the same for your next input port. Being buffered ports, there should not be any issue with the need to wait for the first read to complete before proceeding to read from the next input port.

Some other reference and ideas worth reading:

http://www.xcore.com/questions/3238/how ... ock-two-di...

https://www.xmos.com/support/tools/prog ... component=...
see Performing I/O on specific clock edges

https://www.xmos.com/download/private/A ... m-timed-ou...

https://www.xmos.com/download/private/I ... s%28X2738B...

 

Hope this helps.