Buffered port

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
yugandhar
Junior Member
Posts: 7
Joined: Wed Aug 31, 2011 9:13 am

Buffered port

Post by yugandhar »

Hai all,

I am using XK-1A development board. I written following code in my XC program.



out buffered port:8 data = XS1_PORT_1A;
out port clk = XS1_PORT_1B;

clock CLK = XS1_CLKBLK_1;

char DAT[10];

int main(void)
{
configure_clock_rate(CLK, 100, 100);
configure_port_clock_output(clk, CLK);
configure_out_port(data, CLK, 0);
start_clock(CLK);

for(int i=0; i<20; i++) {
data = DAT;
}
}



In above program i want to stop clock after sending all 20 bytes. How can i know buffer is empty.

Thankyou
Yugandhar


ale500
Respected Member
Posts: 259
Joined: Thu Sep 16, 2010 9:15 am

Post by ale500 »

In the case the peripheral you are using does not have a "chip select" or strobe signal to indicate when data and clock are valid, you may need to stop the clock...

I find several options, you can use stop_port(port p),
You can use setc R0, CTRL_PORT_DATAPORT with the port number in register R0 (from assembler),
or its equivalent from C void set_port_mode_data(void port p)

there are probably others...

With regard to the buffered port, you can use the function sync(void port p) to wait for all the databits to be outputted.

If you surround your code between the code tags (press the button "code" just above the message input text box when you write it) :). It will be nicely formatted (in case the formatting, i.e. indentation is there!).
User avatar
yugandhar
Junior Member
Posts: 7
Joined: Wed Aug 31, 2011 9:13 am

Post by yugandhar »

Thankyou for ur reply.

I had a problem with stop_port.

out buffered port:8 X = XS1_PORT_1A;
out port CK = XS1_PORT_1C;
out port ready = XS1_PORT_1B;
clock clk = XS1_CLKBLK_1;

int main()
{
ready <: 0;

configure_clock_rate(clk, 100, 4);
configure_port_clock_output(CK, clk);
configure_out_port_strobed_master(X, ready, clk, 1);
start_clock(clk);

stop_port(X);
start_port(X);

ready <: 1;
X <: 0xAA;
ready <: 0;

return 1;
}

For above program i am getting output on port X, but its not when ready = 1. For first few bits ready = 1 and then ready became 0. Why ??
User avatar
Paolomio
Experienced Member
Posts: 64
Joined: Tue Oct 05, 2010 7:33 pm

Post by Paolomio »

Use partout() to send partial words to a buffered port...sync() can be used to wait until the partial output is complete.

Paul
User avatar
matrix
Active Member
Posts: 62
Joined: Sat Sep 17, 2011 12:05 pm

Post by matrix »

@yugandhar

Well, your code will crash because your array DAT[10]
is too small for your iteration loop. :lol:

I modified your code, try to run it in the simulator. I can help you out
there if you have questions how to do it, in the IDE there is also
a good tutorial about the simulator.

Once you have it up and running, examine the waveforms of data and clk.

Now change configure_clock_rate(CLK, 100, 100) to configure_clock_rate(CLK, 100, 8),
compile and run the simulator again.

You will discover then that you have some extra clock cycles at start and end of transmission,
because the XC code is not fast enough to handle this properly.

Matrix

Code: Select all

# include <xs1.h>

out buffered port:8 data = XS1_PORT_1A;
out port clk = XS1_PORT_1B;
clock CLK = XS1_CLKBLK_1;


int main(void)
{

 configure_clock_rate(CLK, 100, 100);
 configure_port_clock_output(clk, CLK);
 configure_out_port(data, CLK, 0);
 start_clock(CLK);

 for(int i=0; i<20; i++)
 {
 data<:0xaa;
 sync(data);
 }
 stop_clock(CLK);


while(1);
return(0);
}