background image

XK-1A Development Board Tutorial

I N T H I S D O C U M E N T

·

Introduction

·

Illuminate an LED

·

Flash an LED

·

Flash and cycle LEDs at different rates

·

Run tasks concurrently

·

What to read next

1

Introduction

The XK-1A is a low-cost development board based on the XMOS XS1-L1 device. It

includes a single L1, four LEDs, two press-buttons, SPI flash memory, two 16-way
IDC connectors and an XSYS debugging interface.

This tutorial shows you how to write some simple XC programs that control and

respond to the XK-1A board components. In this tutorial you learn how to:

·

illuminate the LEDs

·

flash the LEDs at a fixed rate

·

flash the LEDs in sequence

·

respond to a button press

·

connect multiple boards together

2

Illuminate an LED

This part of the tutorial shows you how to illuminate an LED on your XK-1A, using

an XC port and an output statement.

2.1

Create a project

2.2

Add the application code

The program below illuminates an LED on an XK-1A.

# i n c l u d e < xs1 . h >

out p o r t led = X S 1 _ P O R T _ 4 F ;

Publication Date: 2012/11/8

Document Number: X7366A

XMOS © 2012, All Rights Reserved

Summary of Contents for XK-1A

Page 1: ...how to write some simple XC programs that control and respond to the XK 1A board components In this tutorial you learn how to illuminate the LEDs flash the LEDs at a fixed rate flash the LEDs in sequence respond to a button press connect multiple boards together 2 Illuminate an LED This part of the tutorial shows you how to illuminate an LED on your XK 1A using an XC port and an output statement 2...

Page 2: ...de Take a look at the code in the editor The declaration out port led XS1_PORT_4F declares an output port named led which refers to the 4 bit port 4F On the XK 1A the I O pins of port 4F are connected to the LEDs labeled LED0 LED1 LED2 and LED3 Show image of port map XS1_PORT_4F 1 LED0 LED1 LED2 LED3 BUT1 BUT2 XS1_PORT_4F 0 XS1_PORT_4F 2 XS1_PORT_1L XS1_PORT_1K XS1_PORT_4F 3 XS1 L1 X7366A ...

Page 3: ...ts the program from terminating which ensures that the LED remains illuminated 2 4 Build and run your project To build and run your project follow these steps 1 In the Project Explorer click your project to select it and then choose the menu option Project Build Project The XDE displays its progress in the Console When the build is complete the XDE adds the compiled binary file to the subfolder bi...

Page 4: ...ed 9 On your XK 1A verify that LED0 is illuminated yellow 10 In the Console click the Terminate button to stop your application running 2 5 Exercise To complete this part of the tutorial perform the following steps 1 Modify your application so that it illuminates all four LEDs Show a tip You should change the value output to the port led so that all four LEDs are driven high Show a sample answer i...

Page 5: ...1_PORT_4F int main void timer tmr unsigned isOn 1 unsigned t tmr t while 1 led isOn t FLASH_PERIOD tmr when timerafter t void isOn isOn return 0 Copy and paste the code into your project and then choose File Save to save your changes to file 3 3 Examine the code Take a look at the code in the editor The declaration timer tmr declares a variable named tmr and allocates an available hardware timer T...

Page 6: ...ow reminder Follow these steps 3 Choose Run Run Configurations 4 In the Run Configurations dialog in the left panel double click XCore Appli cation 5 In the right panel in Name enter the name flash 6 In Project ensure that your project is displayed If not click Browse to open the Project Selection dialog select your project and then click OK 7 As there are now two applications in your project the ...

Page 7: ... build and run just click the Run button The XDE launches the Run Configuration you most recently selected 7 On your XK 1A verify that LED0 is flashing on off at half the rate it was flashing previously and then click the Terminate button to stop your application running 3 6 Exercise To complete this part of the tutorial perform the following steps 1 Modify your flashing LED application so that bo...

Page 8: ...flashing at different speeds and then click the Terminate button to stop your application running 4 Flash and cycle LEDs at different rates This part of the tutorial shows you how to flash an LED while cycling it along the LEDs on your XK 1A 4 1 Create an application The program below inputs from one of two timers in a loop include xs1 h define FLASH_PERIOD 10000000 define CYCLE_PERIOD 50000000 ou...

Page 9: ...the an input on either tmrF or tmrC to become ready It then performs the selected input and executes any code after it up until the keyword break If more than one input becomes ready at the same time only one is executed in a single iteration of the loop the other input is selected on the following iteration 4 3 Exercise 1 To complete this part of the tutorial perform the following tasks 1 Modify ...

Page 10: ...y errors are reported in the Console double click an error to locate it in the editor fix the error and then re build your application 4 Choose Run Run Configurations 5 In the Run Configurations dialog in the left panel double click XCore Appli cation 6 In the right panel in Name enter a name for the Run Configuration 7 In Project ensure that your project is displayed If not click Browse to open t...

Page 11: ...nt that responds to Button 1 being pressed by displaying the string pressed on the console and then waits for Button 1 to be released and displays the string released Note that Button 1 drives a 1 bit port high Pressing the button causes it to stop driving the port and releasing results in it driving again You can test for these conditions using the input condition pinseq 0 and pinseq 1 Show image...

Page 12: ...quals 1 and then call printf again to display the second message Show a sample answer include xs1 h include stdio h define FLASH_PERIOD 10000000 define CYCLE_PERIOD 50000000 out port led XS1_PORT_4F in port but1 XS1_PORT_1K int main void unsigned ledOn 1 unsigned ledVal 1 timer tmrF tmrC unsigned timeF timeC tmrF timeF tmrC timeC while 1 select case tmrF when timerafter timeF void ledOn ledOn if l...

Page 13: ...ning 5 Run tasks concurrently This part of the tutorial shows you how to run tasks concurrently on different threads using the XC par statement and channel communication 5 1 Create a project The program below creates two concurrent threads which run two separate tasks independently of each other include xs1 h include stdio h define FLASH_PERIOD 10000000 define CYCLE_PERIOD 50000000 out port led XS...

Page 14: ...n main the two statements inside the braces of the par are run concurrently the current thread allocates a new hardware thread the current thread then runs the function flashLEDs4bitPort and the new thread runs the function respondToButton The L1 device has a total of eight available hardware threads To complete this part of the tutorial perform the following tasks 1 Build your project create a ne...

Page 15: ...f a channel It uses the XC output statement to output the value 1 to a receiving thread The function rcv declares a channel end parameter cin and uses the XC input statement to input a value to the local variable x The function main declares a channel c The locations of its two channel ends are established through its use in two statements of the par 5 4 Exercise 1 To complete this part of the tut...

Page 16: ... Show a sample answer include xs1 h include stdio h define FLASH_PERIOD 10000000 define CYCLE_PERIOD 50000000 out port led XS1_PORT_4F in port but1 XS1_PORT_1K void flashLEDs4bitPort out port led chanend c int flashPeriod int cyclePeriod Code to flash 4 LEDs connected to a 4 bit port in a cycle unsigned ledOn 1 unsigned ledVal 1 unsigned direction 0 timer tmrF tmrC unsigned timeF timeC tmrF timeF ...

Page 17: ...ut1 c return 0 4 Run your application A flashing LED should cycle between the four LEDs on one of the XK 1As 5 On your XK 1A verify that pressing and releasing button BUT1 causes the flashing LED to change direction and then click the Terminate button to stop your project running 5 5 Exercise 2 This part of the tutorial shows you how to put ports and threads on different processor cores It require...

Page 18: ...ations Declaration core stdcore 2 Declaration Declarations Packages Package Id P1 Type XS1 L1A TQ128 Nodes Node Id Master Type XS1 L1A InPackageId 0 Oscillator 20 MHz SystemFrequency 400 MHz Boot Source Location SPI bootFlash Bootee NodeId Slave Core 0 Boot Core Number 0 Reference stdcore 0 Port Location XS1_PORT_1A Name PORT_SPI_MISO Port Location XS1_PORT_1B Name PORT_SPI_SS Port Location XS1_PO...

Page 19: ...pand your new file to reveal the header file platform h and expand this header to reveal the symbols stdcore 0 and stdcore 1 These symbols name the two processor cores for your new target which can be referred to in your XC application 9 In your XC source file change the header include file xs1 h to platform h 10 Modify the declaration of the port led to place it on the first core as shown below o...

Page 20: ...the board refer to the XK 1A Hardware Manual1 For more information on programming in XC see Programming XC on XMOS Devices2 Copyright 2012 All Rights Reserved Xmos Ltd is the owner or licensee of this design code or Information collectively the Information and is providing it to you AS IS with no warranty of any kind express or implied and shall have no liability in relation to its use Xmos Ltd ma...

Reviews: