How to import port state from Tile 1 to a Tile 0 function ?

If you have a simple question and just want an answer.
MisterQ
Member++
Posts: 21
Joined: Thu Jan 05, 2017 3:35 pm

How to import port state from Tile 1 to a Tile 0 function ?

Post by MisterQ »

Respected Colleauges,

I use a Multichannel Audio Board (XK-AUDIO-216-MC). If I use XMOS Reference Audio 2.0 software, almost all GPIO pins on the Tile 0 are used in software and can not be used for something else (about 8 left), and I need a 16 GPIO Port. Such a port can be used on the Tile 1 and it is a XS1_PORT_16A.

But, if I try to read this port which is on the Tile 1, from the function which is on the Tile 0 I got an error Program received signal ET_ILLEGAL_RESOURCE, Resource exception. because I try to manage port from a function executed on a different Tile.

Can somebody please post here concrete example how to read ports on the Tile 1 from the function on the Tile 0, with assigning read values to a variables used in Tile 0 tasks?

Regards,
Dragan
Last edited by MisterQ on Sun Jan 15, 2017 12:00 pm, edited 3 times in total.


User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am

Post by mon2 »

Hi Dragan. Although not a concrete example, 2 steps are required:

a) since the I/O is on Tile[1], you will need apply a task for the Read GPIO on Tile[1].

b) to transfer the values of this GPIO read task on Tile[1] to a task on Tile[0], you will need to establish a communication channel between the cores.

The following details should be suitable for your request:

https://www.xmos.com/published/how-comm ... rent-tiles
MisterQ
Member++
Posts: 21
Joined: Thu Jan 05, 2017 3:35 pm

Post by MisterQ »

> Although not a concrete example, 2 steps are required:

No, the way you are suggesting, violates parallel usage rules.

I need to transfer a variable with port status to the existing variable samplesIn_0 which is already used in two parallel tasks in the reference software. So, I must not open a new (third) task because I am violating parallel usage rules, and I must not change task (function) properties to allow channeling, because then transfer of an ADC values to USB endpoints do not function.

The only way, as far as I know, is to read ports inside the function

Code: Select all

static inline unsigned DoSampleTransfer(chanend c_out, const int readBuffNo, const unsigned underflowWord)
in the audio.xc file (what I am successfully doing with Tile 0 ports reading).

Have somebody succeeded to channel this particular function with some other task?
Or, is somebody is willing to try to edit this particular function in XMOS USB Audio 2.0 Reference Software to help with that?

It is partially discussed in one of my previous topics: Multi-channel Audio - How to add data to an audio stream?

Regards,
Dragan
Gothmag
XCore Addict
Posts: 129
Joined: Wed May 11, 2016 3:50 pm

Post by Gothmag »

I'm not sure why it violates parallel usage. The standard way to access ports in a task from a tile that it doesn't run on is to create a task to read/write the data on the tile that owns the ports. You can't directly access ports from other tiles.
MisterQ
Member++
Posts: 21
Joined: Thu Jan 05, 2017 3:35 pm

Post by MisterQ »

> I'm not sure why it violates parallel usage.

Because when you try to assign values to variable samplesIn_0 which is used in other two tasks, you will get an error.
If you try same code with a local variable, code is compiling without errors.

Code with channeling:

Code: Select all

on tile[1] : in port Test_INPUTS = XS1_PORT_4D;

void Tile_1_Read_Local_Ports (chanend c) {
    int Value;
    Test_INPUTS :> Value;
    c <: Value;
}

void Tile_0_Read_Remote_Ports (chanend c) {
    unsigned Value;
    c :> Value;          // <<< Compile OK
    c :> samplesIn_0[8]; // <<< Compile with ERROR !!!
}

int main()
{
    chan c;
    par
    {
        on tile[1] : Tile_1_Read_Local_Ports(c);
        on tile[0] : Tile_0_Read_Remote_Ports(c);
    }
}
Debugger Errors listing:

Code: Select all

C:/Files/xTIME/USB_Audio_Software/sc_usb_audio/module_usb_audio/main.xc:578:5: error: use of `usage.anon.5' violates parallel usage rules
    par
    ^~~
C:/Files/xTIME/USB_Audio_Software/sc_usb_audio/module_usb_audio/audio.xc:307:32: note: object used here
                outuint(c_out, samplesIn_0[i]);
                               ^~~~~~~~~~~~~~
C:\Program Files (x86)\XMOS\xTIMEcomposer\Community_14.2.4\target/include\xs1.h:968:67: note: expanded from macro 'outuint'
#define outuint(c, val)                     __builtin_out_uint(c, val)
                                                                  ^
  called by usage.anon.10
  called by audio
  called by usb_audio_io
C:/Files/xTIME/USB_Audio_Software/sc_usb_audio/module_usb_audio/audio.xc:245:10: note: object used here (bytes 32..36)
    c :> samplesIn_0[8];
         ^~~~~~~~~~~~~~
I need to assign values to samplesIn_0[8] and samplesIn_0[9] variables, to transfer data to the audio USB endpoint.

Does somebody know how to solve this? XMOS stuff?

Regards,
Dragan
User avatar
larry
Respected Member
Posts: 275
Joined: Fri Mar 12, 2010 6:03 pm

Post by larry »

Why not bring ADC values via a new channel to the audio task? In there, you take the ADC values and write them into your sample data as required.
MisterQ
Member++
Posts: 21
Joined: Thu Jan 05, 2017 3:35 pm

Post by MisterQ »

>Why not bring ADC values via a new channel to the audio task?

Nice. But how? Aren't they also used in two tasks? Can you write this example lines of code?

Regards,
Dragan
User avatar
larry
Respected Member
Posts: 275
Joined: Fri Mar 12, 2010 6:03 pm

Post by larry »

I am thinking something like this:

Code: Select all

par {
  on tile[0]: adc(c_adc)
  on tile[1]: audio(c_adc, c_out)
}
where

Code: Select all

 void adc(c_adc)
{
     // produce sample
     c_adc <: sample
}
and

Code: Select all

static unsigned samplesIn[]
void audio(c_adc, c_out) {
     c_adc :> sample
     samplesIn[i] = sample
}
While samplesOut is shared between tasks so has unsafe pointers to it, samplesIn is only read/written by the audio task, so should be safe to write to.
MisterQ
Member++
Posts: 21
Joined: Thu Jan 05, 2017 3:35 pm

Post by MisterQ »

> I am thinking something like this:

From your example it is not clear from which function in the XMOS Audio 2.0 Reference software to read and where to write ADC values. ADC values has 8 values, and we are speaking about 9th and 10th USB audio channels.

Also, audio(...) function already exist on the Tile 0 in the audio.xc file.

Can you try your example code in the Audio 2.0 Reference Software and then post example, because it is not as simple, as it looks.

Main problem is to assign values to a samplesIn_0[8] and samplesIn_0[9]. Try first to assign anything to those variables, because without that data will not be sent to the USB Audio Stream.

Regards,
Dragan