nes-proj/examples/cc2530dk/blink-hello.c

65 lines
1.7 KiB
C

/* This is a very simple hello_world program.
* It aims to demonstrate the co-existence of two processes:
* One of them prints a hello world message and the other blinks the LEDs
*
* It is largely based on hello_world of the original sensinode port
*
* Author: George Oikonomou - <oikonomou@users.sourceforge.net>
*/
#include "contiki.h"
#include "dev/leds.h"
#include <stdio.h> /* For printf() */
/*---------------------------------------------------------------------------*/
static struct etimer et_hello;
static struct etimer et_blink;
static uint16_t count;
static uint8_t blinks;
/*---------------------------------------------------------------------------*/
PROCESS(hello_world_process, "Hello world process");
PROCESS(blink_process, "LED blink process");
AUTOSTART_PROCESSES(&hello_world_process, &blink_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data)
{
PROCESS_BEGIN();
etimer_set(&et_hello, CLOCK_SECOND * 4);
count = 0;
while(1) {
PROCESS_WAIT_EVENT();
if(ev == PROCESS_EVENT_TIMER) {
printf("Sensor says #%u\n", count);
count++;
etimer_reset(&et_hello);
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(blink_process, ev, data)
{
PROCESS_BEGIN();
blinks = 0;
while(1) {
etimer_set(&et_blink, CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
leds_off(LEDS_ALL);
leds_on(blinks & LEDS_ALL);
blinks++;
printf("Blink... (state %0.2X)\n", leds_get());
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/