How to set up port structures for library sc_i2s_slave

New to XMOS and XCore? Get started here.
User avatar
tuck1s
Active Member
Posts: 32
Joined: Thu Sep 25, 2014 1:19 am

How to set up port structures for library sc_i2s_slave

Post by tuck1s »

I've set up structures for this library as follows. For some reason the first few times I ran it I got data output, now it just gives the 'starting' message and no more data. I've got valid i2s signals going in, and -fxscope set in the build options.

Code: Select all

/*
 * Ultranet Receiver.xc
 *
 *  Created on: 11 Aug 2015
 *      Author: steve
 *
 *  Captures incoming data from I2Ss port and streams it via a channel to a debug process.
 */
#include <stdio.h>
#include <xscope.h>
#include <xs1.h>
#include <platform.h>
#include <timer.h>
#include <xclib.h>
#include "i2s_slave.h"

struct i2s_slave myports =
{
   XS1_CLKBLK_1,        // Clock Block
   XS1_PORT_1H,         // J7 pin 2 = BLCK from WM8804
   XS1_PORT_1F,         // J7 pin 1 = LRCLK from WM8804
   { XS1_PORT_1G },     // J7 pin 3 = DOUT from WM8804
   { XS1_PORT_1I },     // DOUT = dummy port
};

#define NSAMPLES 256
// Display up to n incoming samples, then wait a bit
void display_task(streaming chanend c) {
    int v[NSAMPLES], i;

    printf("Starting\n");

    for(i=0;i<NSAMPLES;i++) {
        c:> v[i];      // Receive an integer from the channel
    }
    //Now dump a block of samples
    for(i=0; i<NSAMPLES; i++) {
        printf("%08x\n", v[i]);
    }
}


// Simulate input to the channel as a sequence of incrementing integers
void gen_task(streaming chanend c) {
    int v = 0;
    while(1) {
        v++;
        c<: v;      // Output an integer to the channel
        //delay_milliseconds(1);
    }
}

int main() {
    streaming chan c, d;
    par {
            // Capture input from the i2s interface.
            i2s_slave(myports, c, d);

            display_task(c);
        }
    return 0;
}



User avatar
tuck1s
Active Member
Posts: 32
Joined: Thu Sep 25, 2014 1:19 am

Post by tuck1s »

I found the problem. The output channel (d in my example) needs to be kept full, otherwise i2s_slave blocks. For some reason I must have had stuff in my output channel that made it work the first few times.

Making the following change fixed it.

Code: Select all

int main() {
    streaming chan c, d;
    par {
            // Capture input from the i2s interface.
            i2s_slave(myports, c, d);

            display_task(c);

            // Keep the output channel full in case it causes blocking
            gen_task(d);
        }
    return 0;
}