Trouble defining I2S_resources

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
User avatar
Lefty4000
Active Member
Posts: 32
Joined: Mon Nov 11, 2013 6:17 pm

Trouble defining I2S_resources

Post by Lefty4000 »

Hello,

I'm having trouble doing a simple practice in C
The I2S library from xSoftTip has a typedef struct called r_i2s

I have two clock blocks defined for it as well as buffered ports for input and output, both placed in their respective arrays. Although XTime composer community gives me an error for the initialization of both of the arrays (data_in and data_out)

I should note that I have the i2s.h and the startKIT port mapping library I made (from here):
https://github.com/funkyguy4000/XMOS-St ... _mapping.h

Code: Select all

//XS1 Clock mapping
clock MCLK_CLK      =   XS1_CLKBLK_1;
clock BCLK_CLK     =   XS1_CLKBLK_2;

in buffered port:32 ADC_DATA0 = XS1_PORT_1K;
in buffered port:32 ADC_DATA1 = XS1_PORT_1L;

out buffered port:32 DAC_DATA0 = XS1_PORT_1G;
out buffered port:32 DAC_DATA1 = XS1_PORT_1H;

int main(void){

    //Set up I2C
    //The I2C bus is only for configuring the Codec
    i2c_master_init(SCL_SDA);
    CS4270_Init(SCL_SDA);

    //Set up I2S
    in buffered port:32 data_in[2] = {ADC_DATA1, ADC_DATA0};
    out buffered port:32 data_out[2] = {DAC_DATA1, DAC_DATA0};
    streaming chanend channel_data;
    r_i2s i2s_resources = {.cb1 = MCLK_CLK, .cb2 = BCLK_CLK, .mck = MCLK, .bck = BCLK, .wck = LRCLK, .din = data_in,  .dout = data_out};


User avatar
Lefty4000
Active Member
Posts: 32
Joined: Mon Nov 11, 2013 6:17 pm

Post by Lefty4000 »

Could really use some help on this
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

You forgot to show the error messages you get?
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

xC doesn't yet support C99 style designated initializers ({ .foo = bar }). Also ports / clocks must be initialized directly with the port / clock resource ID (e.g. XS1_PORT_1L, or a port name taken from the XN file). Try declaring the i2s_resources structure as follows:

Code: Select all

r_i2s i2s_resources = {
  XS1_CLKBLK_1,
  XS1_CLKBLK_2,
  MCLK,
  LRCLK,
  { XS1_PORT_1L, XS1_PORT_1K },
  { XS1_PORT_1H, XS1_PORT_1G },
}

int main(void) {
...
If MCLK and LRCLK are not port names taken from the XN file then you should also replace those with the actual port resource identifiers.
User avatar
Lefty4000
Active Member
Posts: 32
Joined: Mon Nov 11, 2013 6:17 pm

Post by Lefty4000 »

Many apologies:
I have a much more detailed question on SO about the same thing here: http://stackoverflow.com/questions/2089 ... -resources

I've never used an XN file...I've never even heard of it.

I'll try the other way of defining things tonight and let you know how it goes
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Post by Bianco »

If it doesn't work it is advisable to look at some example code.
The code that richard gave you is how it is done in the i2s examples on github (like here).
I thought you have already been there but persisted on doing it different.

Code: Select all

streaming chanend channel_data;
This doesn't belong here. First of all chanend types can only be used as function parameters.
Then you declare a chan or streaming chan in your main function. Pass this chan variable to exactly two functions that are called using a par statement for running on different logical cores.
Now the tools knows that these two threads want to talk to each other and will set up the channel automatically.

XN files are 'XMOS Network' files. It describes the target board. This can include things like where the boot flash is located, how multiple XMOS chips are connected using xCONNECT links, what frequencies the external oscillators have etcetera but it can also contain aliases for ports.
If you use one the the XMOS development board you usually don't need to write your own XN file (a default one will be used), but when you create custom boards you often have to.
XN files are described in the xTIME Composer Studio user manual.
User avatar
Lefty4000
Active Member
Posts: 32
Joined: Mon Nov 11, 2013 6:17 pm

Post by Lefty4000 »

Persisted? No I just haven't gotten a chance to update the ticket with updated code.
Haha, I'll change it tonight, hang on!

Ohhh ok ok. I made the port mapping header file and mapped the Links that are on the startKIT in that document although I had no idea what they were. I figured it was like intra-communication between XMOS devices. Well since I intend on using a similar xmos controller on my own board, I guess I should get familiar.

Thanks for the clarification on the channels! I'll be back later tonight when you are all in bed since it seems like everybody is from europe here.
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Post by Bianco »

Lefty4000 wrote:Persisted? No I just haven't gotten a chance to update the ticket with updated code.
Haha, I'll change it tonight, hang on!

Ohhh ok ok. I made the port mapping header file and mapped the Links that are on the startKIT in that document although I had no idea what they were. I figured it was like intra-communication between XMOS devices. Well since I intend on using a similar xmos controller on my own board, I guess I should get familiar.

Thanks for the clarification on the channels! I'll be back later tonight when you are all in bed since it seems like everybody is from europe here.
Each tile is connected to a switch. This switch can connect multiple tiles on the same die together as has been done in the previous generation of XMOS chips (XS1-G) or tiles with each having a switch but on separate dies can be put in the same package and interconnected using the xCONNECT links. Of course the number of tiles that can be put in a package is limited (not in the last place for commercial reasons) so there are also external links so you can connect multiple chip packages together on one board. Systems containing multiple packages can be programmed as if it was a single chip (all you have to do is using the par statement with different indices for the different tile[], and have a custom XN file describing the system).
(You do sometimes have to take into account that the bandwidth and number of external xCONNECT links is limited)

Two prime examples that puts this to the extreme are the XMOS XMP-64 board which connects
16 quad-tile chips together (good for 64 tiles or 512 logical cores), image: http://img.hexus.net/v2/cpu/xmos/xmos_xmp64.jpg . The second example is a project from the University of Bristol which tries to connect 240 dual-tile XS1-L16 chips together. More information can be found here: http://www.cs.bris.ac.uk/Research/Micro/swallow.jsp
User avatar
Lefty4000
Active Member
Posts: 32
Joined: Mon Nov 11, 2013 6:17 pm

Post by Lefty4000 »

Yea I saw that board before! That thing is insane! And it makes me want to make one.

Now to be frank, I am quite new to the XMOS line but wouldn't it be rather inefficient to make a supercomputing platform with many cores as such with these devices? I could be entirely wrong but I would like some input because I would love to do some parallel computing, its just I don't know what do to with it in DSP applications, specifically audio processing. (I feel like I sound like a complete newb)
User avatar
Lefty4000
Active Member
Posts: 32
Joined: Mon Nov 11, 2013 6:17 pm

Post by Lefty4000 »

Alright so I tried richards suggestion and I still don't entirely understand why it doesn't work. Here is what I have:

Code: Select all

r_i2s i2s_resources = {
          XS1_CLKBLK_1,
          XS1_CLKBLK_2,
          XS1_PORT_1E,
          XS1_PORT_1I,
          {XS1_PORT_1L, XS1_PORT_1K },
          {XS1_PORT_1H, XS1_PORT_1G }
    };
And here is the exact error it shows:

Code: Select all

../src/Audio Slice with startKIT.xc:33: warning: braces around scalar initializer
../src/Audio Slice with startKIT.xc:33: warning: (near initialization for `i2s_resources.wck')
../src/Audio Slice with startKIT.xc:33: warning: excess elements in scalar initializer
../src/Audio Slice with startKIT.xc:33: warning: (near initialization for `i2s_resources.wck')
../src/Audio Slice with startKIT.xc:33: warning: excess elements in array initializer
../src/Audio Slice with startKIT.xc:33: warning: (near initialization for `i2s_resources.din')
../src/Audio Slice with startKIT.xc:33: error: uninitialized member containing port
../src/Audio Slice with startKIT.xc:33: error: (near initialization for `i2s_resources.dout')
../src/Audio Slice with startKIT.xc:33: error: local variable `i2s_resources' has type that contains a port
In file included from ../src/Audio Slice with startKIT.xc:15:
now i2s_resources.wck, i2s_resources.din, and i2s_resources.dout are the last three parameters of the i2s_resources.

Does anybody have an explanation for this?