XC (programming language)
XC | |
---|---|
Paradigm | concurrent, parallel, distributed, multi-core, real time, imperative |
First appeared | 2005 |
Typing discipline | strong, static |
Filename extensions | .xc |
Website | http://www.xmos.com/published/programming-xc-xmos-devices |
Major implementations | |
xcc | |
Influenced by | |
C, Occam, CSP |
The XC Programming Language is a computer programming language developed in 2005 by Douglas Watt and David May at XMOS.
XC is an imperative programming language, based on the features for parallelism and communication in occam, and the syntax and sequential features of C.[1] It was designed to exploit the XMOS XCore processor architecture[2] and provides primitive features the correspond to the various architectrual resources provided, in particular: channel ends, threads, locks, ports and timers.
In combination with XCore processors, XC is used to build embedded systems with levels of IO, real-time performance and computational capability usually attributed to FPGAs or ASIC devices.
Introduction
The XC version of the Hello World program is identical to that of C's:
#include <stdio.h>
main ( void ) {
printf ( "Hello, world!\n" );
}
XC permits explicit parallelism, as well as parallel replication:
#include <platform.h>
on stdcore [0] : out port tx = XS1_PORT_1A;
on stdcore [0] : in port rx = XS1_PORT_1B;
on stdcore [1] : out port lcdData = XS1_PORT_32A;
on stdcore [2] : in port keys = XS1_PORT_8B
int main ( void ) {
par {
on stdcore [0] : uartTX ( tx );
on stdcore [0] : uartRX ( rx );
on stdcore [1] : lcdDrive ( lcdData );
on stdcore [2] : kbListen ( keys );
}
}
Concurrent processes can communicate using channels:
#include <platform.h>
on stdcore [0] : out port tx = XS1_PORT_1A;
on stdcore [1] : in port keys = XS1_PORT_8B;
void uartTX ( chanend dataIn , port tx ) {
char data ;
while (1) {
dataIn :> data ;
transmitByte ( tx , data );
}
}
void kbListen ( chanend c , port keys ) {
char data ;
while (1) {
data = waitForKeyStroke ( keys );
c <: data ;
}
}
int main ( void ) {
chan c ;
par {
on stdcore [0] : uartTX (c , tx ); // Thread X
on stdcore [1] : kbListen (c , keys ); // Thread Y
}
}
More unconventionally, XC includes ports, which can be used to directly control hardware pins:
#include <xs1.h>
out port p = XS1_PORT_1A;
int main ( void ) {
p <: 1;
p <: 0;
}
Historical influences
The design of XC was heavily influenced by the Occam programming language, which first introduced channel communication, alternation, ports and timers. Occam was developed by David May and built on the Communicating Sequential Processes formalism, a process algebra developed by Tony Hoare.
References
- ^ Douglas R. Watt. Programming XC on XMOS Devices (PDF). XMOS Limited. ISBN 978-1-907361-03-6. Retrieved 2012-03-01.
- ^ David May. The XMOS XS1 Architecture (PDF). ISBN 1-907361-01-4. Retrieved 2012-03-01.