input from buffered port

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
ENGHK
Member++
Posts: 16
Joined: Fri Feb 19, 2010 7:03 am

input from buffered port

Postby ENGHK » Fri Feb 26, 2010 3:06 am

Hello, can anyone help me to find out what's the matter with my program? I am now trying to sample some data signal from an external board (provides the clock and data signal).

Code: Select all


#include <xs1.h>
#include <stdio.h>
#include <platform.h>
on stdcore[1]: in buffered port:32 in32P = XS1_PORT_1D ;
on stdcore[1]: in port INCLK = XS1_PORT_1A ;
on stdcore[1]: in port CS = XS1_PORT_1B ;
on stdcore[1]: clock clk = XS1_CLKBLK_1 ;

int main ( void ) {
	  par
	  { 
		   on stdcore[1]:
	   {  configure_clock_src (clk , INCLK );	
         	set_port_inv(CS);      	
        	configure_in_port_strobed_slave (in32P , CS , clk );
   	       start_clock (clk );
                int z ;
   	              
			   while(1)
			   {   printf("wait\n");
				   in32P:32   :>  z ;
				   printf("z is in hex = %x, 1\n",z);       
			   }
	   }
}
The result just shows 2 input. However. I have input a lot of 32-bit data(not a single 32-bit signal data) .I don't know the reason why the ""in32P:32 :> z "" cannot continously input and save into z and then print out the value of z. Please help.

///////////////////////////////// result from my 9.9.2
wait
z is in hex = 7bb57df7, 1
wait
z is in hex = ffffffff, 1
wait
/////////////////////////////////
User avatar
Woody
XCore Addict
Posts: 165
Joined: Wed Feb 10, 2010 2:32 pm

Postby Woody » Fri Feb 26, 2010 10:05 am

When you print something, all of the threads are paused and the debugger starts the slow task of outputting the data. It may well be that you are missing most of the data because the thread is trying to print.

Why not have a large array and fill that with the input data. When the array is full, print the whole array at one go.

Something along the lines of:

Code: Select all

#define INPUT_BUFFER_SIZE 64
unsigned inputBuffer[INPUT_BUFFER_SIZE];

for (int i = 0; i < INPUT_BUFFER_SIZE; i++)
{
  in32P :> inputBuffer[i];
}
for (int i = 0; i < INPUT_BUFFER_SIZE; i++)
{
  printf("%x\n",inputBuffer[i]);
}
ENGHK
Member++
Posts: 16
Joined: Fri Feb 19, 2010 7:03 am

Postby ENGHK » Fri Feb 26, 2010 11:56 am

thank you so much. But i have now a new question. Now I try to output a high and low to out port when I get the first 32 bit data. But the result is that i can only get the first two 32 bit data. That means I still cannot retrieve all the data. Please see the attached photo. How can I do and why ?

Code: Select all

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

on stdcore[1]: in buffered port:32 in32P = XS1_PORT_1D ;
on stdcore[1]: in port INCLK = XS1_PORT_1A ;
on stdcore[1]: in port CS = XS1_PORT_1B ;
on stdcore[1]: out port OP = XS1_PORT_1C ;
on stdcore[1]: out port OP2 = XS1_PORT_1E ;
on stdcore[1]: clock clk = XS1_CLKBLK_1 ;

int main ( void ) {
	   par
	  { 
	      on stdcore[1]:
	    {   int treated;	        
	     	configure_clock_src (clk , INCLK );	
	      	set_port_inv(CS);      	
	     	configure_in_port_strobed_slave (in32P , CS , clk );
	    	start_clock (clk );

	    		while(1){	
        select
        {
    case	in32P :> z :
	    {	if (z==0x7fd75bbb)
        	OP<:1;
        	OP<:0;
        	OP<:1;
                OP<:0;
        }
	     else
	    {
OP2<:1;
OP2<:0;
OP2<:1;
OP2<:0;      		    	            		    	                	    	            		    OP<:0;
	   }
	    break;
	    	            }
	    	            }
	    	}	    	            
	    }
}
}
You do not have the required permissions to view the files attached to this post.
User avatar
Woody
XCore Addict
Posts: 165
Joined: Wed Feb 10, 2010 2:32 pm

Postby Woody » Fri Feb 26, 2010 5:12 pm

Nothing immediately springs out at me.

OP and OP2 are both be clocked by the ref clock, so there should be lots of time to toggle them before the next in32P data becomes available. Is CS asserted throughout? Which signal is that?

Who is online

Users browsing this forum: No registered users and 1 guest