this is a simple led blink example, which unfortunately hangs and does not work:
one tasks blinks via a timer, the other should update the delay value. (btw: is there something to get proper milliseconds?)
Code: Select all
#include <platform.h>
#include <xs1.h>
#include <stdio.h>
port led = XS1_PORT_1F;
void blink_led(chanend c) {
timer t;
unsigned time_now;
unsigned time_last = 0;
int delay = 1000000;
led <: 0;
int state = 0;
while (1) {
select {
case c :> delay:
printf("Updated delay: %d\n", delay);
break;
default:
continue;
}
t :> time_now;
if (time_now - time_last >= delay){
time_last = time_now;
state = state^1; // toggle
led <: state;
}
}
}
void read_delay(chanend c) {
int delay;
while (1) {
printf("Enter delay: ");
scanf("%d", &delay);
c <: delay;
}
}
int main( void ) {
chan c;
par {
blink_led(c);
read_delay(c);
}
return 0;
}