xC: handling server interface array

Technical questions regarding the XTC tools and programming with XMOS.
Endre
Active Member
Posts: 38
Joined: Fri Jan 01, 2016 10:13 am

xC: handling server interface array

Post by Endre »

Hi,

In a task function I'd like to serve an array of server interfaces (server interface ComIf comIf[]).

In a "select" block I try to do it with the following "case" statement:

Code: Select all

case(int i = 0; i < COM_RX_CHANNELS; i++) readCharEnabled[i] && rxDesc[i].buf.items => comIf[i].readChar() -> char ch:
But I get this error:

Code: Select all

error: complex select case replicators over interface cases are not supported
Is there any other way to do it?
Why does this limitation exist?


User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

Endre wrote:Hi,

In a task function I'd like to serve an array of server interfaces (server interface ComIf comIf[]).

In a "select" block I try to do it with the following "case" statement:

Code: Select all

case(int i = 0; i < COM_RX_CHANNELS; i++) readCharEnabled[i] && rxDesc[i].buf.items => comIf[i].readChar() -> char ch:
But I get this error:

Code: Select all

error: complex select case replicators over interface cases are not supported
Is there any other way to do it?
Why does this limitation exist?
Strangely the i2c_master code in lib_I2c does not generate this error, yet has rather complex replicated case including guards on an interface server implementation.

I recall having this error before and instead refactored my select case using this form 'case MyInterface[int i].MyFunction()...' It might be an option worth exploring..

regards
Al
Endre
Active Member
Posts: 38
Joined: Fri Jan 01, 2016 10:13 am

Post by Endre »

Folknology wrote: Strangely the i2c_master code in lib_I2c does not generate this error, yet has rather complex replicated case including guards on an interface server implementation.
Yes, I see. So I guess in my code there are errors which are not directly related to "complex replicated case including guards on an interface server implementation", but xC exits with the misleading "error: complex select case replicators over interface cases are not supported" message.

Thanks for your investigation!
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

Hmmm - yes your replicated guarded case construct looks fine so that does look like a compiler limitation.

One obvious (if messy) workaround could be:

Code: Select all

#if COM_RX_CHANNELS > 0
case readCharEnabled[0] && rxDesc[0].buf.items => comIf[0].readChar() -> char ch:
#endif

#if COM_RX_CHANNELS > 1
case readCharEnabled[1] && rxDesc[1].buf.items => comIf[1].readChar() -> char ch:
#endif

...

Endre
Active Member
Posts: 38
Joined: Fri Jan 01, 2016 10:13 am

Post by Endre »

Thanks for the hint.

For avoiding code multiplication I have tried to use a select function.

Code: Select all

static inline select receiverCases(
    RxDesc & rxDesc,
    boolean & readEnabled,
    boolean & availableEnabled,
    boolean & defaultEnabled,
    server interface ComRxIf rxIf
) {
    case (readEnabled && rxDesc.buf.items) => rxIf.read() -> char ch:
        CharBuffer_get(rxDesc.buf, ch);
        if (rxDesc.read >= 64) {
            // yield
            rxDesc.read = 0;
            readEnabled = FALSE;
            defaultEnabled = TRUE;
        } else {
            ++rxDesc.read;
        }
        break;
    case availableEnabled => rxIf.available() -> uint res:
        availableEnabled = FALSE;
        defaultEnabled = TRUE;
        res = rxDesc.buf.items;
        break;
}
And to call it from "select"

Code: Select all

 while (TRUE) {
            select {
                // --- receive
                case receiverCases(rxDesc[0], readEnabled[0], availableEnabled[0], defaultEnabled, rxIf[0]);
In this case the compilation crashes in a late phase:

Code: Select all

Compiling Com.xc
xcc1: terminated due to internal unrecoverable error
For bug reporting instructions, please see:
http://www.xmos.com/support
xmake[1]: *** [.build/src//Com.xc.o] Error 1
xmake: *** [bin//USB_PWM.xe] Error 2
Is it possible to open and track bugs for XMOS tools?
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

Hi Endre,

Could I bother you to capture the failing command line so I can recreate the issue?

Please could you alter your makefile flags to include "-v -save-temps"
I am interested in the '.build/src/Com.xi' file, the '.build/pca.xml' file (if there is one) and the final 'xcc1llvm ....' command line that fails.

cheers
robert
Endre
Active Member
Posts: 38
Joined: Fri Jan 01, 2016 10:13 am

Post by Endre »

robertxmos wrote: I am interested in the '.build/src/Com.xi' file, the '.build/pca.xml' file (if there is one) and the final 'xcc1llvm ....' command line that fails.

Code: Select all

Compiling Com.xc
 "/home/endre/Prg/XMOS/xTIMEcomposer/Community_14.1.2/libexec/xcc1llvm" -E -march=xs1b "-I../." "-I.././inc" "-I.././src" "-I/home/endre/Prg/workspace.XMOS/lib_usb" "-I/home/endre/Prg/workspace.XMOS/lib_usb/api" "-I/home/endre/Prg/workspace.XMOS/lib_usb/doc" "-I/home/endre/Prg/workspace.XMOS/lib_usb/doc/pdf" "-I/home/endre/Prg/workspace.XMOS/lib_usb/src" "-I/home/endre/Prg/workspace.XMOS/lib_usb/src/endpoint0" "-I/home/endre/Prg/workspace.XMOS/lib_usb/src/experimental" "-I/home/endre/Prg/workspace.XMOS/lib_usb/src/experimental/dfu" "-I/home/endre/Prg/workspace.XMOS/lib_usb/src/experimental/endpoint0" "-I/home/endre/Prg/workspace.XMOS/lib_usb/src/lowlevel" "-I/home/endre/Prg/workspace.XMOS/lib_usb/xudlib" "-I/home/endre/Prg/workspace.XMOS/lib_usb/xudlib/glx_support" "-I/home/endre/Prg/workspace.XMOS/lib_usb/xudlib/included" "-I/home/endre/Prg/workspace.XMOS/lib_logging" "-I/home/endre/Prg/workspace.XMOS/lib_logging/api" "-I/home/endre/Prg/workspace.XMOS/lib_logging/doc" "-I/home/endre/Prg/workspace.XMOS/lib_logging/doc/pdf" "-I/home/endre/Prg/workspace.XMOS/lib_logging/src" "-I/home/endre/Prg/workspace.XMOS/lib_xassert" "-I/home/endre/Prg/workspace.XMOS/lib_xassert/api" "-I/home/endre/Prg/workspace.XMOS/lib_xassert/doc" "-I/home/endre/Prg/workspace.XMOS/lib_xassert/doc/pdf" "-I/home/endre/Prg/workspace.XMOS/lib_xassert/src" "-I/home/endre/Prg/workspace.XMOS/lib_gpio" "-I/home/endre/Prg/workspace.XMOS/lib_gpio/api" "-I/home/endre/Prg/workspace.XMOS/lib_gpio/doc" "-I/home/endre/Prg/workspace.XMOS/lib_gpio/doc/pdf" "-I/home/endre/Prg/workspace.XMOS/lib_gpio/src" "-Wall" "-DXUD_SERIES_SUPPORT=XUD_U_SERIES" "-DCONFIG=Default"  -isystem "/home/endre/Prg/XMOS/xTIMEcomposer/Community_14.1.2/target/include/xc" -isystem "/home/endre/Prg/XMOS/xTIMEcomposer/Community_14.1.2/target/include" -isystem "/home/endre/Prg/XMOS/xTIMEcomposer/Community_14.1.2/target/include/clang" -D__xcore__ -D__XS1B__ -D__XS1_L__ -DXCC_VERSION_YEAR=14 -DXCC_VERSION_MONTH=1 -DXCC_VERSION_MAJOR=1401 -DXCC_VERSION_MINOR=1 -D__XCC_HAVE_FLOAT__ "-D_PLATFORM_INCLUDE_FILE=\"/home/endre/Prg/Repos/XMOS/USB_PWM/.build/SLICEKIT-U16.h\"" "-D_XSCOPE_PROBES_INCLUDE_FILE=\"/home/endre/Prg/Repos/XMOS/USB_PWM/.build/xscope_probes.h\"" -o "Com.xi" "../src/Com.xc"
 "/home/endre/Prg/XMOS/xTIMEcomposer/Community_14.1.2/libexec/xcc1llvm" "-I../." "-I.././inc" "-I.././src" "-I/home/endre/Prg/workspace.XMOS/lib_usb" "-I/home/endre/Prg/workspace.XMOS/lib_usb/api" "-I/home/endre/Prg/workspace.XMOS/lib_usb/doc" "-I/home/endre/Prg/workspace.XMOS/lib_usb/doc/pdf" "-I/home/endre/Prg/workspace.XMOS/lib_usb/src" "-I/home/endre/Prg/workspace.XMOS/lib_usb/src/endpoint0" "-I/home/endre/Prg/workspace.XMOS/lib_usb/src/experimental" "-I/home/endre/Prg/workspace.XMOS/lib_usb/src/experimental/dfu" "-I/home/endre/Prg/workspace.XMOS/lib_usb/src/experimental/endpoint0" "-I/home/endre/Prg/workspace.XMOS/lib_usb/src/lowlevel" "-I/home/endre/Prg/workspace.XMOS/lib_usb/xudlib" "-I/home/endre/Prg/workspace.XMOS/lib_usb/xudlib/glx_support" "-I/home/endre/Prg/workspace.XMOS/lib_usb/xudlib/included" "-I/home/endre/Prg/workspace.XMOS/lib_logging" "-I/home/endre/Prg/workspace.XMOS/lib_logging/api" "-I/home/endre/Prg/workspace.XMOS/lib_logging/doc" "-I/home/endre/Prg/workspace.XMOS/lib_logging/doc/pdf" "-I/home/endre/Prg/workspace.XMOS/lib_logging/src" "-I/home/endre/Prg/workspace.XMOS/lib_xassert" "-I/home/endre/Prg/workspace.XMOS/lib_xassert/api" "-I/home/endre/Prg/workspace.XMOS/lib_xassert/doc" "-I/home/endre/Prg/workspace.XMOS/lib_xassert/doc/pdf" "-I/home/endre/Prg/workspace.XMOS/lib_xassert/src" "-I/home/endre/Prg/workspace.XMOS/lib_gpio" "-I/home/endre/Prg/workspace.XMOS/lib_gpio/api" "-I/home/endre/Prg/workspace.XMOS/lib_gpio/doc" "-I/home/endre/Prg/workspace.XMOS/lib_gpio/doc/pdf" "-I/home/endre/Prg/workspace.XMOS/lib_gpio/src" "-Wall" "-DXUD_SERIES_SUPPORT=XUD_U_SERIES" "-DCONFIG=Default"  -isystem "/home/endre/Prg/XMOS/xTIMEcomposer/Community_14.1.2/target/include/xc" -isystem "/home/endre/Prg/XMOS/xTIMEcomposer/Community_14.1.2/target/include" -isystem "/home/endre/Prg/XMOS/xTIMEcomposer/Community_14.1.2/target/include/clang"  -D__xcore__ -D__XS1B__ -D__XS1_L__ -DXCC_VERSION_YEAR=14 -DXCC_VERSION_MONTH=1 -DXCC_VERSION_MAJOR=1401 -DXCC_VERSION_MINOR=1 -D__XCC_HAVE_FLOAT__ "-D_PLATFORM_INCLUDE_FILE=\"/home/endre/Prg/Repos/XMOS/USB_PWM/.build/SLICEKIT-U16.h\"" "-D_XSCOPE_PROBES_INCLUDE_FILE=\"/home/endre/Prg/Repos/XMOS/USB_PWM/.build/xscope_probes.h\"" "-quiet" "-Wall" "-O2" "-g" "-version" "-analysis" ".././.build/pca.xml" -march=xs1b -o "Com.s" "../src/Com.xc"
xcc1: terminated due to internal unrecoverable error
You do not have the required permissions to view the files attached to this post.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

I'm curious is the 'static inline' actually required, I have assumed in the past that select functions get the equivalent of inlining in XC's select case assembly structures, although I haven't checked out the assembly produced in such a case (no pun intended) for many years. I would be fascinated to see if this was the case or not and if there was any advantage to using 'inline'.

regards
Al
Endre
Active Member
Posts: 38
Joined: Fri Jan 01, 2016 10:13 am

Post by Endre »

Hi,

Removing "static inline" doesn't seem to change anything.
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

Hi Endre,

There seems to be a bug in handling the exponent, I'll need to investigate further.
A work around is not to use one!
// case tmr when __builtin_timer_after(now + (100e6/100000)) :> now:
case tmr when __builtin_timer_after(now + (1000)) :> now:

robert