I'm a bit desperate with the XMOS. Hope somebody could show me the end of the tunnel.
I basically have two tasks, one is sampling and integrating data (19.68MHz sampling rate, 12 bit values, 24 samples are summed up), the other is consuming it. Somehow that does not work and I can't debug it properly with XSCOPE.I fear that the interface call takes too long and that some samples are lost.
In the code below 16 sums are collected and send over the interface at once as an array of data.
The behaviour that I would expect is that I see the consuming task to increment the counter variable integrals_idx in steps of 16 and then overflows to 0 again. I would expect to get a new_integrals call every 19.68MHz / 24/ 16 = 51.25kHz.
In XScope I would expect to see a constantly increasing counter. But I only see connect is ok and triggering and no data at all. When I set breakpoints at the xscope _int statements, I can see that the xscope_int are called.
Code: Select all
interface bitstream_integral_interface {
void new_integrals(uint32_t data[]);
};
Code: Select all
#define MAXIMAL_INTEGRALS_LENGTH (1024)
#define INTEGRAL_LENGTH 16
#define SAMPLING_MASK 0x0FFF
#define SUM_SAMPLE\
adc_data @ count++ :> sample;\
sum+=(sample&SAMPLING_MASK);
void task_sampling(in port adc_dco, in buffered port:16 adc_data,
clock clk_adc, client interface bitstream_integral_interface bitstream_integral,
server interface init_interface init)
{
/* ADC clock, ADC data ready on rising edge of DCO */
configure_clock_src (clk_adc , adc_dco );
configure_in_port_no_ready (adc_data , clk_adc );
start_clock (clk_adc);
set_core_high_priority_on();
int count=0;
uint16_t sample;
uint32_t sum=0;
uint32_t integrals[INTEGRAL_LENGTH];
int pos=0;
while(1)
{
sum=0;
/* sample 24 x */
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
SUM_SAMPLE;
integrals[pos++]=sum;
pos&=(INTEGRAL_LENGTH-1);
if(!pos)
{
bitstream_integral.new_integrals(integrals);
xscope_int(XSCOPE_SAMPLING, count);
}
}
}
Code: Select all
void task_bitstream(server interface bitstream_integral_interface bitstream_integral,
server interface control_bitstream_interface control_bitstream,
client interface control_rx_interface control_rx)
{
xscope_enable();
uint32_t integrals[MAXIMAL_INTEGRALS_LENGTH];
int integrals_idx=0;
debug_printf("starting bitstream\n");
while(1)
{
select {
case bitstream_integral.new_integrals(uint32_t data[]):
//memcpy(&integrals[integrals_idx], data, INTEGRAL_LENGTH*sizeof(uint32_t));
integrals_idx+=INTEGRAL_LENGTH;
integrals_idx&=(MAXIMAL_INTEGRALS_LENGTH-1);
xscope_int(XSCOPE_BITSTREAM, integrals_idx);
break;
}
}
}
Best Dani