??? ???? ????
Login |
  • Why Register?
  • Download development tools
  • Create and track support tickets
  • Subscribe to resource updates
  • Access latest developer news
Register

XC-1 Tutorial (Simplified)

Development Tools:
XC-1
Version 9.9
Publication Date: 2009/10/16
Copyright © 2009 XMOS Ltd. All Rights Reserved.

XC-1 (9.9)
2/16
1

XC-1 XMOS XS1-G4 XS1-G4 16
LED JTAG
XS1-G4 XCore
400 MIPS 64 KByte
XS1-G4 ( 9)
XMOS XC [1] C
XMOS XC C

XC-1 XC
C
LED
LED
12 LED
LED
LED
UART "Hello World"

XC

XMOS Design Tools 9.7
[2]
2
LEDport<:
XC XC-1 LED
www.xmos.com

XC-1 (9.9)
3/16
XC-1 16 LED LED ( button-
LED) 12 / LED XS1-G4 ( clock-LED) LED

XC-1 button-LED
# include <platform .h>
out port bled = PORT_BUTTONLED ;
int main () {
bled <: 0x10;
while (1)
;
return 0;
}
bled
PORT_BUTTON_LEDXC-1.xn PORT_BUTTON_LED xs1.h
XS1_PORT_8D
XC
main
bled <: 0x10;
<: (0b00010000) (bled)
button-LED LED bled
button-LED
LED
out

XC-1 ( Development Tools [2] [2]

) LED
button-LED (0xf0) button-LED

12 clock-LED LED
(4A4B4C PORT_CLOCKLED_0/1/2 )
(1E 1F PORT_CLOCKLED_SELG PORT_CLOCKLED_SELR
)
PORT_CLOCKLED_0 :
www.xmos.com

XC-1 (9.9)
4/16
I
II
III
IIII
V
VI
VII
VIII
IX
X
XI
XII
X0D15 X0D20 X0D21
X0D2
X0D3
X0D8
X0D9
X0D4
X0D5
X0D6
X0D7
X0D14
PORT_CLOCKLED_2
PORT_CLOCKLED_0
PORT_CLOCKLED_1
PORT_CLOCKLED_SELG
X0D12
PORT_CLOCKLED_SELR
X0D13
1: XC-1 12 clock-LED
# include <platform .h>
out port cled0 = PORT_CLOCKLED_0 ;
out port cledG = PORT_CLOCKLED_SELG ;
out port cledR = PORT_CLOCKLED_SELR ;
int main(void) {
cledG <: 0;
// disable GREEN line
cledR <: 1;
// enable RED line
cled0 <: 0x1; // LED pattern
while (1);
return 0;
}
PORT_CLOCKLED_SELG PORT_CLOCKLED_SELR0x1
PORT_CLOCKLED_0 (IIIIVVIVII)
XC-1 VII clock-LED

12 LED

( 0xf PORT_CLOCKLED_0 PORT_CLOCKLED_1 PORT_CLOCKLED_2)
www.xmos.com

XC-1 (9.9)
5/16
3
LED timer :>
XC LED

tmr t:
timer tmr;
tmr :> t;

t += FLASH_PERIOD ;
tmr when timerafter (t) :> void;
XC
void
LEDLED

# include <platform .h>
# define FLASH_PERIOD 20000000
out port cled0 = PORT_CLOCKLED_0 ;
out port cledG = PORT_CLOCKLED_SELG ;
out port cledR = PORT_CLOCKLED_SELR ;
int main(void) {
timer tmr;
unsigned ledGreen = 1;
unsigned t;
tmr :> t;
while (1) {
cledG <:
ledGreen ;
cledR <: ! ledGreen ;
cled0 <: 0x1;
t += FLASH_PERIOD ;
tmr when timerafter (t) :> void;
ledGreen = ! ledGreen ;
}
return 0;
}
XC-1 clock-LED

LED

www.xmos.com

XC-1 (9.9)
6/16

4
LED :select
XC select XC-1 LED

select
case break
return
select timeout
select {
case tmrF when timerafter ( timeF ) :> void :
/* respond to timeout ,
* switch LED between on and off */
...
break ;
case tmrC when timerafter ( timeC ) :> void :
/* respond to timeout ,
* change which LED is flashing */
...
break ;
}
select LED cycle
# include <platform .h>
# define FLASH_PERIOD 10000000
# define CYCLE_PERIOD 60000000
out port cled0 = PORT_CLOCKLED_0 ;
out port cled1 = PORT_CLOCKLED_1 ;
out port cled2 = PORT_CLOCKLED_2 ;
out port cledG = PORT_CLOCKLED_SELG ;
out port cledR = PORT_CLOCKLED_SELR ;
int main(void) {
unsigned ledOn = 1;
unsigned ledVal = 1;
timer tmrF , tmrC;
unsigned timeF , timeC ;
www.xmos.com

XC-1
} (9.9)
7/16
tmrF :> timeF;
tmrC :> timeC;
while (1) {
select {
case tmrF when timerafter ( timeF) :> void :
ledOn = !ledOn ;
cledG <: ledOn ;
timeF += FLASH_PERIOD ;
break;
case tmrC when timerafter ( timeC) :> void :
cled0 <: ledVal ;
cled1 <: ( ledVal >> 4);
cled2 <: ( ledVal >> 8);
ledVal <<= 1;
if ( ledVal == 0 x1000 )
ledVal = 1;
timeC += CYCLE_PERIOD ;
break;
}
}
return 0;
}
XC-1 LED

5
:par
XC par
LED
XC-1
par

in
port buttons = PORT_BUTTON ;
out port speaker = PORT_SPEAKER ;
int main(void) {
par {
cycleLED (cled0 , cled1 , cled2 ,
cledG , cledR ,
FLASH_PERIOD , CYCLE_PERIOD );
buttonListener (buttons , speaker );
}
www.xmos.com

XC-1 (9.9)
8/16
return 0;
}
buttonListener
# define TDELAY
100000
# define TLENGTH 500
void buttonListener (in port b, out port spkr) {
timer tmr;
int t, isOn = 1;
while (1) {
b when pinsneq (0 xf) :> void;
tmr :> t;
for (int i=0; i< TLENGTH ; i++) {
isOn = !isOn;
t += TDELAY ;
tmr when timerafter (t) :> void;
spkr <: isOn;
}
}
}
pinsneq 0xf
for 0 1
delay
4 LED

cycleLED XC-1 LED

buttonListener

6
LED :chan chanend
XC buttonListener
LED LED
XC chan

int main(void) {
chan c;
par {
www.xmos.com

XC-1 (9.9)
9/16
cycleLED (cled0 , cled1 , cled2 ,
cledG , cledR ,
FLASH_PERIOD , CYCLE_PERIOD ,
c);
buttonListener (buttons , speaker , c);
}
return 0;
}
par
chanend
void buttonListener (in port b, out port spkr ,
chanend c);
XC
c <: 0;
0 c

buttonListener 0 c



cycleLED isGreen
select
case c :> int :
isGreen = ! isGreen ;
break ;
LED isGreen
XC-1 LED




7

UART
www.xmos.com

XC-1
/ * (9.9)
10/16
UART
2
0 1


# include <platform .h>
# define BIT_RATE 115200
# define BIT_TIME XS1_TIMER_HZ / BIT_RATE
void txByte (out port TXD , int byte );
out port TXD= PORT_UART_TX ;
int main ()
{
return 0;
}
void txByte (out port TXD , int byte) {
unsigned time;
timer t;
/* send start bit */
TXD <: 0;
time += BIT_TIME ;
t when timerafter (time) :> void;
/* send data bits */
for (int i=0; i <8; i++) {
TXD <: >> byte;
time += BIT_TIME ;


2: UART
www.xmos.com

XC-1 (9.9)
11/16
t when timerafter (time) :> void;
/* send stop bit */
TXD <: 1;
time += BIT_TIME ;
t when timerafter (time) :> void;
}
UART
# define BIT RATE 115200
# define BIT_TIME XS1 - TIMER_HZ / BIT_RATE
TXD
TXD <: 0;
time BIT_TIME

t when timerafter (time) :> time;
for

for
TXD <: >> byte;
>> ()
<: >> int
XC-1 USB USB
1
XMOS terminal listener Xlinkers 2
main "Hello World!" (PORT_UART_TX)

8
on
XC on
UART
XCore 2 (X2)
1 MAC JTAG
2http://www.xlinkers.org/tag_search?tag=uart
www.xmos.com

XC-1
} (9.9)
12/16
3
0 ( X0/PORT_BUTTON )
2 UART UART
( X2/1A )
2 UART (X2/1B)
UART 0

XC-1 4

platform.h
XS1-G4 stdcore on

# include <platform .h>
on stdcore [0] : in
port buttons = PORT_BUTTON ;
on stdcore [0] : out port speaker = PORT_SPEAKER ;
on stdcore [2] : in
port uartIn
= XS1_PORT_1A ;
on stdcore [2] : out port uartOut = XS1_PORT_1B ;
int main(void) {
chan c, d;
par {
on stdcore [0] : buttonListener (buttons , c);
on stdcore [2] : transmit (uartOut , c);
on stdcore [2] : receive (uartIn , d);
on stdcore [0] : speakerListener (d, speaker );
}
0
2
Listener
UART

c

Listener
UART
d


3: UART
www.xmos.com

XC-1 (9.9)
13/16
1B
1A
X2PortA
4: XC-1 1A
1B
return 0;
}
main on par return

6 buttonListener

: delay
transmit 7 transmitByte


receive

receiveByte
: :> >> int int
24
speakerListener

XC-1

XC-1 XC-1 XC

UART UART


www.xmos.com

XC-1 (9.9)
14/16
9
XC-1
XC-1 5
XC-1 XC-1Hardware Man-
ual [3]
XC Programming XC on XMOS Devices [4]
[2]
XS1 The XMOS XS1 Architecture [5]
:
http://www.xmos.com
http://www.xlinkers.org

[1] Douglas Watt. Programming XC on XCore XS1 Devices. Website, 2009. http://www.
xmos.com/published/xcxs1.
[2] Douglas Watt and Huw Geddes. The XMOS Tools User Guide. XMOS Limited, 2009.
http://www.xmos.com/published/xtools_en.
[3] XMOS Ltd.
XC-1 Hardware Manual.
Website, 2009.
http://www.xmos.com/
published/xc1hw.
[4] Douglas Watt. Programming XC on XMOS Devices. XMOS Limited, Sep 2009.
http://www.xmos.com/published/xc_en.
[5] David May. The XMOS XS1 Architecture. XMOS Limited, 2009. http://www.xmos.
com/published/xs1_en.
www.xmos.com

XC-1 (9.9)
15/16
XCORE2
X2PortA Header
X2PortB Header
X2D0
X2D1
X2D12
X2D13
X2D2
X2D3
X2D14
X2D15
X2D4
X2D5
X2D16
X2D17
3V3
GND
3V3
GND
X2D6
X2D7
X2D18
X2D19
X2D8
X2D9
X2D20
X2D21
X2D10
X2D11
X2D22
X2D23
XCORE0 PORT_BUTTONLED [A:D]
5V
GND
5V
GND
X2D[0:11]
X2D[12:23]
PORT_BUTTON [A:D]
XCORE0
PORT_CLOCKLED_0/1/2
X0D0
X010
X0D10
X0D11
XOD26
X0D27
PORT_SPEAKER
X0D28
PORT_UART_RX
X0D29
XS1-G4
X0D30
EE2
PORT_UART_TX
X0D31
X0D32
X0D33
X0D36
X0D37
mUSB-B
FTDI
X0D38
X0D39
DEBUG
PROTOTYPE AREA
JTAG
RST
RESET
PGOOD
CLOCK
X2D[24:35]
X2D[36:43]
PWREN#
XCORE2
3V3
PSU
20MHz
XTO
1V
X2D24
X2D25
X2D36
X2D37
X2D26
X2D27
X2D38
X2D39
5V
X2D28
X2D29
X2D40
X2D41
3V3
GND
3V3
GND
X2D30
X2D31
X2D42
X2D43
X2D32
X2D33
NC
NC
X2D34
X2D35
NC
NC
5V
GND
5V
X2PortC Header
X2PortD Header
5: XC-1
www.xmos.com

Revision History

Revision Released Formats Supported Tools
Version: 9.9-[Y-M] September 15, 2010 download N/A