In this example we will compile, simulate and run a single source file application
- create a new dir called example1 and navigate to that dir.
- save the below code in a file called example.xc in the newly created dir
Code: Select all
#include <platform.h> #include <stdio.h> on tile[0] : out port led = XS1_PORT_1A; void counting_task() { timer t; unsigned ctime; unsigned count = 0; t :> ctime; while (1) { printf("count: %u\n", count); count++; t when timerafter(ctime + 50000000) :> ctime; } } void led_task() { timer t; unsigned ctime; t :> ctime; while (1) { t when timerafter(ctime + 25000000) :> ctime; led <: 0; t when timerafter(ctime + 25000000) :> ctime; led <: 1; } } int main(void) { par { on tile[0] : counting_task(); on tile[0] : led_task(); } return 0; }
- Let's use the command line tools! On windows start the "xTIME Composer Command Prompt" and a cmd prompt will appear.
On OS X and Linux, open a new terminal window, navigate to xTIME Composer installation root dir (on OS X in /Applications/XMOS... on Linux wherever you extracted the tools), then run 'source SetEnv.sh'. - Navigate back to the example1 dir.
- Compile the source file: 'xcc -target=STARTKIT -O2 -report -o example.xe example.xc', (build for target STARTKIT, optimization level 2, report constraints check, output binary example.xe).
- Simulate the application: 'xsim example.xe', you will see 'count: 0', if you are really patient you will see more print statements. It takes a while because succeeding print statements are millions of cycles apart due to the timer delay. You can use Control+C to stop the simulation. Try the simulation again with instruction trace: 'xsim -t example.xe'. Observe that the instruction trace stops after a while, this is because both logical cores are blocked waiting for a timer event. Again if you are patient you will see it continue after some time. The simulation in the command line tools is particular useful to examinate crashing programs and studying program behaviour at the instruction level. Port toggling etcetera can also be captured but it is more convenient to use the simulator from the xTIME Composer Studio in combination with the waveform viewer.
- Check if the startKIT is detected: 'xrun -l'
- Run the application on the startKIT. 'xrun --io example.xe'. The --io flag instructs the debugger to stay attached, this enables us to print to the console.
In this example we will build, run and flash an application example from github.
- Create a new dir called example2.
- Save the following dirs from https://github.com/xcore/sw_startkit_examples to example2: app_absolute, module_startkit_gpio. You can do this by cloning the repository using a git client and copy the dirs or use the download zip function at the right side.
- Save the following dir from https://github.com/xcore/sc_capacitive_sensing to example2: module_capacitive_sensing. example2 now should contain the following sub dirs: app_absolute, module_startkit_gpio, module_capacitive_sensing.
- Navigate to example2/app_absolute.
- Build the project: run 'xmake' or 'xmake all'.
- Navigate to example2/app_absolute/bin
- Run on the startkit: 'xrun --io app_absolute.xe'
- Flash the application to the boot flash: 'xflash app_absolute.xe'. (Do not make the mistake to use xburn instead of xflash, xburn is used to burn the One Time Programmable memory).
The command line tools are documented in the xTIME Composer Studio user guide