Switch configuration message confusion...

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
Jamie
Experienced Member
Posts: 99
Joined: Mon Dec 14, 2009 1:01 pm

Switch configuration message confusion...

Post by Jamie »

I'm confused about the procedure for sending a switch read/write configuration messages (Sections 3.4 & 3.5 in the G system spec). Section 3.5 describes the configuration resource identifier as ([31..24] node id, [32..16] SSCTRL, [15..8] 0, [7..0] 0) but xsim complains "Unsupported configuration control token '0x00'" and with it constructed as ([31..16] node id, [15..8] SSCTRL, [7..0] 0) seems to work, although only up to 1 node/4 cores.

Also the protocol description in 3.5 omits the additional headers and footers as described in 3.4. This includes a 2 byte header identifying the switch (which I assume is just the node id?) and the SSCTRL token. A 3 byte header sent back to complete. It seems as if these extra parts should be included with inter-node configuration as opposed to the shorter version in 3.5 for intra-node configuration but its not clear...

Here's my code to write a switch register 3. 'c' is the local channel end used to communicate with the switch which is identified by 'dest'.

Code: Select all

// Write a switch configuration register
void cfgWrite(unsigned c, unsigned dest, unsigned value) {

    unsigned v;

    // Two byte header identifying dest switch
    asm("outt  res[%0], %1" :: "r"(c), "r"((dest >> 24) & 0xF));
    asm("outt  res[%0], %1" :: "r"(c), "r"((dest >> 16) & 0xF));

    // SSCTRL token
    asm("outct res[%0], %1" :: "r"(c), "r"(XS1_CT_SSCTRL));

    // WRITEC token
    asm("outct res[%0], %1" :: "r"(c), "r"(XS1_CT_WRITEC));

    // NodeId, CoreId, ChanId
    asm("outt  res[%0], %1" :: "r"(c), "r"((c >> 24) & 0xF));
    asm("outt  res[%0], %1" :: "r"(c), "r"((c >> 16) & 0xF));
    asm("outt  res[%0], %1" :: "r"(c), "r"((c >> 8) & 0xF));

    // Switch address (register 3)
    asm("outt  res[%0], %1" :: "r"(c), "r"(0));
    asm("outt  res[%0], %1" :: "r"(c), "r"(3));

    // Data to write
    asm("out res[%0], %1" :: "r"(c), "r"(value));

    // End of message
    asm("outct res[%0], " S(XS1_CT_END) :: "r"(c));

    // Receive 3 byte header
    asm("int %0, res[%1]" : "=r"(v) : "r"(c));
    asm("int %0, res[%1]" : "=r"(v) : "r"(c));
    asm("int %0, res[%1]" : "=r"(v) : "r"(c));

    // Receive acknowledgement
    asm("chkct res[%0], " S(XS1_CT_ACK) :: "r"(c));
    asm("chkct res[%0], " S(XS1_CT_END) :: "r"(c));
}
And to read:

Code: Select all

// Read a switch configuration register
unsigned cfgRead(unsigned c, unsigned dest) {

    unsigned value, v;

    // Two byte header identifying dest switch
    asm("outt  res[%0], %1" :: "r"(c), "r"((dest >> 24) & 0xF));
    asm("outt  res[%0], %1" :: "r"(c), "r"((dest >> 16) & 0xF));

    // SSCTRL token
    asm("outct res[%0], %1" :: "r"(c), "r"(XS1_CT_SSCTRL));

    // READC
    asm("outct res[%0], %1" :: "r"(c), "r"(XS1_CT_READC));

    // NodeId, CoreId, ChanId
    asm("outt  res[%0], %1" :: "r"(c), "r"((c >> 24) & 0xF));
    asm("outt  res[%0], %1" :: "r"(c), "r"((c >> 16) & 0xF));
    asm("outt  res[%0], %1" :: "r"(c), "r"((c >> 8) & 0xF));

    // Switch address (register 3)
    asm("outt  res[%0], %1" :: "r"(c), "r"(0));
    asm("outt  res[%0], %1" :: "r"(c), "r"(3));

    // End of message
    asm("outct res[%0], " S(XS1_CT_END) :: "r"(c));

    // Receive 3 byte header
    asm("int %0, res[%1]" : "=r"(v) : "r"(c));
    asm("int %0, res[%1]" : "=r"(v) : "r"(c));
    asm("int %0, res[%1]" : "=r"(v) : "r"(c));

    // Receive ACK and data
    asm("chkct res[%0], " S(XS1_CT_ACK) :: "r"(c));
    asm("in %0, res[%1]" : "=r"(value) : "r"(c));
    asm("chkct res[%0], " S(XS1_CT_END) :: "r"(c));

    return value;
}
I've probably missed the point somewhere, can anyone help?

Cheers,
Jamie


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

Post by richard »

The first three bytes identifying the destination of the packet are automatically added by the hardware at the start of the packet. Remove your first 3 outt instructions and make sure the chanend destination is set using setd to (on a XS1-G):

Code: Select all

XS1_RES_TYPE_CONFIG | (XS1_CT_SSCTRL << 8) | (node << 24)
Similarly the 3 byte header identifying the the destination of the return message will have been stripped by the time you get the reply so first token you input should be the ACK or NACK control token.

It also worth mentioning that there are library functions to do this in xs1.h (e.g. read_sswitch_reg(), write_sswitch_reg()).
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

Jamie wrote:Section 3.5 describes the configuration resource identifier as ([31..24] node id, [32..16] SSCTRL, [15..8] 0, [7..0] 0)
This seems like a bug in the XS1-G documentation. I'll check on Monday.
User avatar
Jamie
Experienced Member
Posts: 99
Joined: Mon Dec 14, 2009 1:01 pm

Post by Jamie »

Okay, thanks for clarifying that. I didn't consider that the description included the system headers as well. Apart from the confusion with the SSCTRL byte, I shouldn't have been masking off the first 4 bits of the return address bytes... All's working well now though.

Cheers,
Jamie