Using ports with replicators

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
User avatar
Jamie
Experienced Member
Posts: 99
Joined: Mon Dec 14, 2009 1:01 pm

Using ports with replicators

Postby Jamie » Tue Mar 09, 2010 10:51 am

Using a replicated par statement means you cannot pass any port arguments to contained functions as xc doesn't yet allow you to construct port arrays. It must be possible to bypass this with a bit of assembly though. In particular I have tried something along the lines of

Code: Select all

led:
    entsp 0
    // r0: port, r1: value
    out res[r0], r1
    retsp 0
Although this causes an ET_ILLEGAL_RESOURCE exception when run with a replicatior (in this case for the XMP-64, where the led is port 1E on cores 0, 4, 8, ...)

Code: Select all

void led(int outPort, int value);

void run(int number) {
    unsigned outPort = (unsigned) XS1_PORT_1E;
    if(number % 4 == 0)
        led(outPort, 1);
    while(1) {}
}

int main() {

    chan c[64];

    par (int i=0; i<64; i++) {
        on stdcore[i] : run(i);
    }
    return 0;
}
Which I presume is because I'm not initialising the port, which the manual mentions you need to do with the SETC instruciton, but I'm not sure exactly how to do this. Can anyone shed any light on this?

Cheers,

Jamie
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Postby richard » Tue Mar 09, 2010 12:39 pm

Jamie wrote:Using a replicated par statement means you cannot pass any port arguments to contained functions as xc doesn't yet allow you to construct port arrays.
XC does allow port arrays (and structures containing ports). For example:

Code: Select all

#include <platform.h>

port p[] = {
  on stdcore[0]: XS1_PORT_1A,
  on stdcore[1]: XS1_PORT_1A,
};

void f(port p) { }

int main() {
  par {
    on stdcore[0]: f(p[0]);
    on stdcore[1]: f(p[1]);
  }
}
It does not support using replicators to build initialisers.
Which I presume is because I'm not initialising the port, which the manual mentions you need to do with the SETC instruciton, but I'm not sure exactly how to do this. Can anyone shed any light on this?
The set_port_use_on() function (defined in xs1.h) can be used to turn on a port and reset its state. The port will configured to match its type.

The equivalent of set_port_use_on() is performed on every port declared in XC before running main(). If the port is declared outside XC then you can manually call set_port_use_on().
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Postby Bianco » Tue Mar 09, 2010 2:11 pm

A small assembly tip:

Code: Select all

entsp 0
will do nothing because the operand is zero (see the XMOS arch document).
So you can ommit this instruction. The retsp instruction is still needed though.
User avatar
Jamie
Experienced Member
Posts: 99
Joined: Mon Dec 14, 2009 1:01 pm

Postby Jamie » Wed Mar 10, 2010 10:52 am

Thanks Richard, I didn't realise you could construct port arrays like that. It works a treat :)

Who is online

Users browsing this forum: No registered users and 1 guest