XC is C plus X

Started 7April2017, updated 18April2017

This page is in group Technology and is a blog note trying to scribble down some info about the XMOS XC language that I haven’t found elsewhere. I love it. But, alas, XC appears as C plus unknown X. I’ll help finding min(X). Also see My XMOS notes about the rest of what I have from this universe.

The xTIMEcomposer would build from C and C++ in addition to XC sources. Only the additions for XC are handled here.

Disclaimers: Standard disclaimer (here). Extra disclaimer: take this as face value. This note is about the xTIMEcomposer as seen from a user only. There may be errors or misunderstandings. Please mail me or comment if you find any.

XC == xC

XMOS also calls the language xC with lower-case c [8]. There are excellent manuals, see References (below). But I started this note to fill in the holes that I didn’t find any patches for.

Reserved words

I have not been able to find an updated list in any of the XMOS documentation (I haven’t found any with client defined in a reserved words list, only by usage, in the References list). Here’s a suggestion. Some may not be a reserved word (like pinsneq?), some are operators (like :>) – and I may have missed some:



I show some messages that appear as I code doing all my excellent errors. It’s impossible, I hope (even for me) to end up with exhastive lists this way. Only XMOS could do that. I don’t think the  Open Source Licence Agreements code suffices [9]. I have not included obvious messages like lint-like errors.

The alphabetical lists reveal some of the powerful machinery under the hood. I have below added the xTIMEcomposer version at the end of the informal descriptions. History: (14.2.4) April2017. The lists will not be re-checked for each new version.

Error messages concerning concurrency

The list only handles messages associated with tasks and concurrency [7].

  • error: call makes alias in function `My_Client’ 
    → Same channel is used twice in parameter list (14.2.4)
  • error: combinable function cannot have interface array argument of unknown size
    → Array as [] is “unkown” (14.2.4)
  • error: combinable function must end in a `while(1){select{..}}’ or combined `par’ statement
    → Code after break statement of last case of select when [[combinable]]. Cannot combine selects from such tasks. Observe that code is not allowed in any of the starred positions: `while(1){select{..}*}*' (14.2.4)
  • error: components of multi-tile par must have `on’ specifier or call a service
    → One cannot spread around with on tile and core and not using them just like that (14.2.4)
  • error: declaration statement in ‘par’ statement 
    → A block starting with a par must only contain calls to tasks, not declarations (14.2.4)
  • error: main select in combinable function cannot have default case
    → If it did it couldn’t merge the select loops (14.2.4)
  • error: [[notification]] attribute can only be used on slave functions
    → Don’t forget slave here and usage: [[notification]] slave void notify(void); (14.2.4)
  • error: only local variables of type chan or interface are allowed in a multi-tile main
    → Even if it’s probably not really a multi-tile (I only referred to tile[0]) then main with par does not allow any variables such as int etc. (Reported to XMOS. Better with multi-core?) (14.2.4)
  • error: pattern variable cannot be used with array of unknown size
    → Standard replicated select case works only on an interface array of known size. Unkown size array [] is allowed as param since if its's not [[combinable]] (14.2.4)
  • error: select case has guard without [[independent_guard]] case attribute or [[guarded]] interface function attribute
    → Interface method not tagged as [[guarded]] while there is a boolean guard in the code (14.2.4)
  • error: select on notification within combinable function select case
    → Nested select in a task that is tagged as [[combinable]] (14.2.4)
  • error: slave modifier without [[notification]] attribute is not supported
    → Interface method not tagged as [[notification]] while the slave (server) code does contain a notfication. Needed to ensure atomicity of session command→notification→read
    → (But what about this?) (14.2.4)
  • error: source array smaller than destination for argument 1 of `some_Sśerver’
    → A server hasn’t got the necessary clients, as declared in the server declaration. I think they must be declared at compile time (which I like) (14.2.4)
  • error: statement placed on a core must be call to combinable function
    → There is one hardware thread per logical core. If (more than) one task is placed on a core the select loops will be merged (so must be [[combinable]]) into one select loop that’s owned by that HW thread. Remove the red (example): on tile[0].core[4]: (14.2.4)
  • error: `some_channel’ used in more than two parallel statements (byte range 4..8)
    → Message is fine. The opposite (“not used in two”) is a warning (see below). Last part is explained here. (14.2.4)
  • xmap: Error: Symbol inP_button_center is a duplicate port declaration.
    → Aliasing of two names on the same port is not allowed (14.2.4)

Warning messages concerning concurrency

  • warning: `some_interface’ not used in two parallel statements (byte range 4..8)
    → Message is fine. The opposite (“used in more than two”) is an error (see above). Last part is explained here. (14.2.4)

No liveness analysis

The compiler will help you avoid deadlocks by trying to enforce correct patterns, seen by the error messages above.

However, it will not do liveness analysis and detect deadlock (or livelock). I have seen it allow me to input and output on the same chanend in the same task without any complaints. I will investigate more. Theoretically the channel could have changed direction, but I don’t know if that’s legal xC. Later: It is. See first code example below.

Off-piste code examples

Chan syntax confusion

How many syntactical combinations could we possible have for the same semantics? Here are the ones I have had to relate to over the years. Channels are named “ch”:

occam ch ! value // output
ch ? value // input
Two single-letter tokens (direction), ch left
go/golang ch <- value // output
value <- ch // input
One two-letter token, same way, ch sided (direction)
xC ch <: value; // output
ch :> value; // input
Two two-letter tokens (direction), different ways, ch left

Using a chanend in both directions

Rather unusual xC. Only chan. No use of interface. No select! Still, quite possible. Give and take it’s almost occam. Press to open code in text fold:

The code: Using a chanend in both directions

void My_Server (chanend c_in, chanend c_out) {
    int value;
    while(1) {
        c_in :> value; // Input
        debug_printf ("    My_Server   _ %u\n", value);
        c_out <: value; // Output
        debug_printf ("    My_Server   X %u\n", value);

void My_PingPong (chanend c_in_out) {
    int value;
    while(1) {
        c_in_out :> value; // Input
        debug_printf ("    My_PingPong _ %u\n", value);
        c_in_out <: value; // Output
        debug_printf ("    My_PingPong Y %u\n", value);


void My_Client (chanend c_out, chanend c_in, chanend c_out_in) {
    int value = 0;
    while(1) {
        debug_printf ("My_Client       X %u\n", value);
        c_out <: value;    // Output
        c_in :> value;     // Input
        debug_printf ("  My_Client     Y %u\n", value);
        c_out_in <: value; // Output
        c_out_in :> value; // Input (Change dir: deadlock caught by run-time)
        debug_printf ("  My_Client     Z %u\n", value);

int main(void) {
    chan c_over;
    chan c_back;
    chan c_pingpong;
    par {
        My_Server   (c_over, c_back);
        My_PingPong (c_pingpong);
        My_Client   (c_over, c_back, c_pingpong);
    return 0;
/* Simulator (same if I run with startKIT HW)
My_Client       X 0
    My_Server   _ 0
  My_Client     Y 1
    My_Server   X 1
    My_PingPong _ 1
  My_Client     Z 2
    My_PingPong Y 2
My_Client       X 2
    My_Server   _ 2
  My_Client     Y 3
    My_Server   X 3
    My_PingPong _ 3
  My_Client     Z 4
    My_PingPong Y 4
My_Client       X 4
    My_Server   _ 4
  My_Client     Y 5
    My_Server   X 5
    My_PingPong _ 5
  My_Client     Z 6
    My_PingPong Y 6

Constraint check for tile[0]:
  Cores available:            8,   used:          3 .  OKAY
  Timers available:          10,   used:          3 .  OKAY
  Chanends available:        32,   used:          6 .  OKAY
  Memory available:       65536,   used:      12716 .  OKAY
    (Stack: 4608, Code: 7314, Data: 794)
Constraints checks PASSED.
Build Complete

As you see by the log, it works: a chanend may be used in any direction. If I build this code with two chanends (instead of one as in the example) for My_PingPong then I get the exact same behaviour as with one chanend. Of course it would add up to two more chanends used, one at each end of the channel. But bear in mind that the actual usage is always important to avoid deadlocks, no less with one chanend than with two. Each end has to agree on the direction of the next transmission. The compiler will not give any error message on wrong usage.

If I can save two chanends by “reuse”, why doesn’t the tool do this automatically? When I do a clean ping-pong type sequence from a client to a server and back, like in the example, and I had declared a channel in each direction, the tool could have optimised and used only one channel for it? And saved two chanends.

However, if I change direction on the last input in My_Client to do an output instead then the deadlock then it is caught at run-time (this may also happen if I type direction wrongly in some standard usage example) :

tile[0] core[1] (Suspended: Signal 'ET_ILLEGAL_RESOURCE' received. Description: Resource exception.) 
        3 My_PingPong() xc_test_2.xc:38 0x00010104 
        2 main_task_My_PingPong_1() xc_test_2.xc:63 0x000101b8 
        1 __start_core() 0x00010fb2

In other words, a chanend is bidirectional, just like a chan in go/golang and a rendezvous in Ada. And, I should say, CSP, since it’s only a shared state where all parts wait standing still, and data may be moved in any direction at the synchronisation point. (It’s the implementation of the ALT in occam, and it being a multi-core distributed memory architecture that didn’t make occam’s chan bidirectional. And didn’t open for output guards.) A channel is a permission to do anything with some data that, at the synchronisation point, is shared. Also see Calculating number of chanends

The log above also is an exercise in how the scheduling is done. At first sight it may look wrong, but value is incremented and a complete round is not compromised. It works.

I have shown this code at XMOS XCore discussion forum here. Interesting response there!

Replicated select

See xC code showing use of replicated select in blog note Channels and rendezvous vs. safety-critical systems.

Side notes


Wiki-refs: XC. Many of these are also referenced in :

  1. XMOS Programming Guide (version E, Oct 09, 2014), see https://www.xmos.com/support/xkits?subcategory=Starter%20Kits&product=17441&component=17653&version=latest
  2. XC Reference Manual, 2008/07/16, by Douglas WATT Richard OSBORNE David MAY (VERSION 8.7), see https://www.xmos.com/download/public/XC-Reference-Manual(8.7-[Y-M]).pdf. Old, can’t even find reserved words “server” or “client” there
  3. XC Specification, see http://www.xmos.com/xc-specification. Old, can’t even find reserved words “server” or “client” there
  4. XS1 Ports: use and specification, see https://www.xmos.com/zh/download/public/XS1-Ports-Specification(X1373A).pdf
  5. Introduction to XS1 ports, see https://www.xmos.com/download/public/Introduction-to-XS1-ports%28X2738B%29.pdf
  6. The XMOS XS1 Architecture by David May. Copyright © 2009 by XMOS Limited. ISBN: 978-1-907361-01-2 (PBK), ISBN: 978-1-907361-04-3 Published by XMOS Limited, see https://www.xmos.com/download/public/The-XMOS-XS1-Architecture%281.0%29.pdf
  7. Parallel tasks and communication, XMOS, see https://www.xmos.com/published/xmos-programming-guide?version=B&page=23
  8. Introduction to Programming XMOS Device, see https://www.xmos.com/support/tools/programming?component=18344
  9. xTIMEcomposer source code base, see https://www.xmos.com/support/tools/source. I downloaded all the repositories and found no hit for a message like “slave modifier without”, so I wouldn’t know where to find the error messages. The answer is probably here: “Some of the xTIMEcomposer Development Tools have been developed under Open Source Licence Agreements. The source for these tools is available for download to satisfy appropriate licence terms.”
Email this to someoneShare on FacebookTweet about this on TwitterShare on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *


* Copy This Password *

* Type Or Paste Password Here *

9,242 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>