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); }
}
}