Small Fun Demos

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
Gravis
Experienced Member
Posts: 75
Joined: Thu Feb 02, 2012 3:32 pm

Small Fun Demos

Post by Gravis »

I figured it would be nice for new people to have small non-boring demos to use on a dev board without additional hardware, so I'm posting my own demo. It's not much code and shows an example of using channels.

Please post your own simple/fun demos. :)


description: this small demo for the XC-1A dev board that just makes it look like an LED is moving in a circle.

Code: Select all

#include <platform.h>

#define DELAY 2500000

on stdcore [0] : out port cled0 = PORT_CLOCKLED_0; // 3 LEDs on core 0
on stdcore [1] : out port cled1 = PORT_CLOCKLED_1; // 3 LEDs on core 1
on stdcore [2] : out port cled2 = PORT_CLOCKLED_2; // 3 LEDs on core 2
on stdcore [3] : out port cled3 = PORT_CLOCKLED_3; // 3 LEDs on core 3

on stdcore [0] : out port cledR = PORT_CLOCKLED_SELR;

void LEDring (chanend current, chanend next, out port led)
{
	timer tmr;
	unsigned tmp;

	while(1) // wait for messages forever
	{
		select
		{
			case current :> tmp: // wait for message from another core
			{
				tmr :> tmp; // get current time

				led <: 0b00010000; tmr when timerafter (tmp +  DELAY     ) :> void; // activate LED 1 and wait
				led <: 0b00100000; tmr when timerafter (tmp + (DELAY * 2)) :> void; // activate LED 2 and wait
				led <: 0b01000000; tmr when timerafter (tmp + (DELAY * 3)) :> void; // activate LED 3 and wait

				next <: 1; // send message to activate next core
				led <: 0; // turn off all LEDs on this core
				break;
			}
		}
	}
}

void main(void)
{
	chan leds[4];
	par
	{
		on stdcore [0]: { cledR <: 1; //  enable red LEDs
							 LEDring (leds[0], leds[1], cled0); }
		on stdcore [1]: LEDring (leds[1], leds[2], cled1);
		on stdcore [2]: LEDring (leds[2], leds[3], cled2);
		on stdcore [3]: { leds[0] <: 1; // start
							 LEDring (leds[3], leds[0], cled3); }
	}
}
You do not have the required permissions to view the files attached to this post.


User avatar
phalt
Respected Member
Posts: 298
Joined: Thu May 12, 2011 11:14 am

Post by phalt »

That's cool Gravis.

Maybe you could add your tutorial to the wiki here?

It'd be great to get some more community tutorials that differ from the standard few and teach a few different things.