2012-03-05 16:47:01 +01:00
|
|
|
/* 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
|
|
|
|
*
|
2016-01-10 16:09:31 +01:00
|
|
|
* It is largely based on hello_world of the original sensinode port
|
2012-03-05 16:47:01 +01:00
|
|
|
*
|
|
|
|
* 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);
|
2012-12-16 16:27:01 +01:00
|
|
|
count++;
|
2012-03-05 16:47:01 +01:00
|
|
|
|
|
|
|
etimer_reset(&et_hello);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PROCESS_END();
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
PROCESS_THREAD(blink_process, ev, data)
|
|
|
|
{
|
|
|
|
PROCESS_BEGIN();
|
|
|
|
|
2011-12-17 00:56:06 +01:00
|
|
|
blinks = 0;
|
|
|
|
|
2012-03-05 16:47:01 +01:00
|
|
|
while(1) {
|
|
|
|
etimer_set(&et_blink, CLOCK_SECOND);
|
|
|
|
|
|
|
|
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
|
|
|
|
|
|
|
|
leds_off(LEDS_ALL);
|
2011-12-17 00:56:06 +01:00
|
|
|
leds_on(blinks & LEDS_ALL);
|
|
|
|
blinks++;
|
2012-03-05 16:47:01 +01:00
|
|
|
printf("Blink... (state %0.2X)\n", leds_get());
|
|
|
|
}
|
|
|
|
|
|
|
|
PROCESS_END();
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|