I recently observed some strange behavior that I can't quite explain. I am trying to send some 16bit data over a streaming channel to a buffer core. This buffer subsequently talks to the USB core which sends data back to my computer. The following test code represents the beginning of the signal chain. Note: the configuration char isn't relevant for this example. I have also rolled back from the timestamped I/O version of this code to a simple processor intensive bit-banging implementation.
Code: Select all
case ADC.RUN(char cfg):
/* */
configure_clock_ref(acq_clk, 100);
start_clock(acq_clk);
unsigned short buffer;
unsigned short tmp;
unsigned short result;
for(int i =0; i< 256; i++){
p_busy when pinseq(1):> void;
p_busy when pinseq(0):> void; //trigger signaling data is ready to grab
tmp=0;
buffer=0;
result=0;
for(char i=0; i< 16; i++){
p_sck <: 1;
p_sdo :> tmp;
buffer = (result <<1) | tmp; //manually get each bit and place into the result variable.
p_sck <: 0;
result = buffer;
}
c_data <: result;
}
stop_clock(acq_clk);
break;
I have tried the following,
result = byterev(buffer); -> It looks like the buffer gets promoted to an int since I get all 0's back. To test this, I do a byterev() operation and shift the result back into the lower 16bits of the resulting int32 before transmitting as shown in the following line.
result = byterev(buffer)>>16;
Here, data looks more a little more reasonable...However, the result is clearly discontinuous for some values. In the attached screenshot, I have applied an offset to show the effect of bit discontinuity. See attached. Removing the offset results in a wrong, but continuous time domain result. Next: result = bitrev(byterev) >>16; Returns all zeros.
This is the first time i've had trouble sending data over channels. For instance, I can read back configuration information sent from the host to the device without trouble. The issues seems to be in the way that the data is packed or transmitted at the device end.
I'm sincerely hoping someone might be able to explain the bit/byte structure of data sent via channels so that I can pack it correctly.
Thanks,
Kyle