From 0e9220716ee16092b6817b420655073a85f58aaf Mon Sep 17 00:00:00 2001 From: zdshelby Date: Tue, 8 Sep 2009 19:47:50 +0000 Subject: [PATCH] Initial commit of examples for the Sensinode/cc2430 platform. --- examples/sensinode/Makefile | 9 +++++ examples/sensinode/README | 39 +++++++++++++++++++ examples/sensinode/clock_test.c | 67 ++++++++++++++++++++++++++++++++ examples/sensinode/hello_world.c | 23 +++++++++++ examples/sensinode/rf_test_rx.c | 60 ++++++++++++++++++++++++++++ examples/sensinode/rf_test_tx.c | 50 ++++++++++++++++++++++++ 6 files changed, 248 insertions(+) create mode 100644 examples/sensinode/Makefile create mode 100644 examples/sensinode/README create mode 100644 examples/sensinode/clock_test.c create mode 100644 examples/sensinode/hello_world.c create mode 100644 examples/sensinode/rf_test_rx.c create mode 100644 examples/sensinode/rf_test_tx.c diff --git a/examples/sensinode/Makefile b/examples/sensinode/Makefile new file mode 100644 index 000000000..bf9ab1686 --- /dev/null +++ b/examples/sensinode/Makefile @@ -0,0 +1,9 @@ +ifndef TARGET +TARGET=sensinode +endif + +CONTIKI_PROJECT = hello_world clock_test rime_test rf_test_rx rf_test_tx +all: $(CONTIKI_PROJECT) + +CONTIKI = ../.. +include $(CONTIKI)/Makefile.include diff --git a/examples/sensinode/README b/examples/sensinode/README new file mode 100644 index 000000000..a9bac42e1 --- /dev/null +++ b/examples/sensinode/README @@ -0,0 +1,39 @@ +Sensinode platform example and test applications + - by Zach Shelby (zach@sensinode.com) + +This directory contains example and test applications for +Sensinode CC2430 based devices. By default it is set to use the +sensinode platform: + +/platform/sensinode +/cpu/cc2430 + +To build an application: + +make [app_name] +make hello_world + +To build and upload an application using the Sensinode nano_programmer +included under /tools (default /dev/ttyUSB0): + +make [app_name].upload +make hello_world.upload + +To dump the serial port output (default /dev/ttyUSB0): + +make sensinode.serialdump + +To configure the hardware model, you can include a make option e.g. for +the N601 (N100 is assumed by default): + +make hello_world DEFINES=MODEL_N601 + +These make options are defined in /platform/sensinode/Makefile.sensinode + +Descriptions of applications: + +hello_world A simple hello world app. +clock_test Test and example of sys/clock.h related features. +rf_test_tx Test for transmitting packets +rf_test_rc Test for receiving packets + \ No newline at end of file diff --git a/examples/sensinode/clock_test.c b/examples/sensinode/clock_test.c new file mode 100644 index 000000000..758b4d040 --- /dev/null +++ b/examples/sensinode/clock_test.c @@ -0,0 +1,67 @@ +/** + * \file + * Tests related to clocks and timers + * \author + * Zach Shelby + */ + +#include "contiki.h" +#include "sys/clock.h" +#include "dev/bus.h" +#include "dev/leds.h" +#include /* For printf() */ +/*---------------------------------------------------------------------------*/ +PROCESS(clock_test_process, "Clock test process"); +AUTOSTART_PROCESSES(&clock_test_process); +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(clock_test_process, ev, data) +{ + static struct etimer et; + static clock_time_t count, start_count, end_count, diff; + static unsigned long sec; + static u8_t i; + + PROCESS_BEGIN(); + + printf("Clock delay test (10 x (10,000xi) cycles):\n"); + i = 1; + while(i < 6) { + start_count = clock_time(); + clock_delay(10000*i); + end_count = clock_time(); + diff = end_count-start_count; + printf("Delayed %u = %u ticks = ~%u ms\n", 10000*i, diff, diff*8 ); + i++; + } + + printf("Clock tick and etimer test (10 x 1s):\n"); + i = 0; + while(i < 10) { + etimer_set(&et, CLOCK_SECOND); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + etimer_reset(&et); + + count = clock_time(); + printf("%u ticks\n", count); + + leds_toggle(LEDS_RED); + i++; + } + + printf("Clock seconds test (10 x 5s):\n"); + i = 0; + while(i < 10) { + etimer_set(&et, 5 * CLOCK_SECOND); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + etimer_reset(&et); + + sec = clock_seconds(); + printf("%u seconds\n", (u16_t) sec); + + leds_toggle(LEDS_GREEN); + i++; + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/hello_world.c b/examples/sensinode/hello_world.c new file mode 100644 index 000000000..ec3d2c3d6 --- /dev/null +++ b/examples/sensinode/hello_world.c @@ -0,0 +1,23 @@ +/** + * \file + * Basic hello world example + * \author + * Zach Shelby + */ + +#include "contiki.h" +#include /* For printf() */ +/*---------------------------------------------------------------------------*/ +PROCESS(hello_world_process, "Hello world process"); +AUTOSTART_PROCESSES(&hello_world_process); +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(hello_world_process, ev, data) +{ + + PROCESS_BEGIN(); + + printf("Hello World!\n"); + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/rf_test_rx.c b/examples/sensinode/rf_test_rx.c new file mode 100644 index 000000000..4d816f845 --- /dev/null +++ b/examples/sensinode/rf_test_rx.c @@ -0,0 +1,60 @@ +/** + * \file + * RF test suite, receiver + * \author + * Zach Shelby + */ + +#include "contiki.h" +#include "net/rime.h" +#include /* For printf() */ +/*---------------------------------------------------------------------------*/ +PROCESS(rf_test_process, "RF test RX process"); +AUTOSTART_PROCESSES(&rf_test_process); + +static struct etimer et; +static struct broadcast_conn bc; +static const struct broadcast_callbacks broadcast_callbacks = {recv_bc}; +static struct unicast_conn uc; +static const struct unicast_callbacks unicast_callbacks = {recv_uc}; + +static void +recv_bc(struct broadcast_conn *c, rimeaddr_t *from) +{ + printf("broadcast from %02x.%02x len = %d buf = %s\n", + from->u8[0], + from->u8[1], + packetbuf_datalen(), + (char *)packetbuf_dataptr()); +} + +static void +recv_uc(struct unicast_conn *c, rimeaddr_t *from) +{ + printf("unicast from %02x.%02x len = %d buf = %s\n", + from->u8[0], + from->u8[1], + packetbuf_datalen(), + (char *)packetbuf_dataptr()); +} + +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(rf_test_process, ev, data) +{ + + PROCESS_BEGIN(); + + printf("\nStarting CC2430 RF test suite...\n"); + + broadcast_open(&bc, 128, &broadcast_callbacks); + unicast_open(&uc, 128, &unicast_callbacks); + + while(1) { + etimer_set(&et, CLOCK_SECOND); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + etimer_reset(&et); + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/rf_test_tx.c b/examples/sensinode/rf_test_tx.c new file mode 100644 index 000000000..d2ed92cdb --- /dev/null +++ b/examples/sensinode/rf_test_tx.c @@ -0,0 +1,50 @@ +/** + * \file + * RF test suite, transmitter + * \author + * Zach Shelby + */ + +#include "contiki.h" +#include "net/rime.h" +#include /* For printf() */ +/*---------------------------------------------------------------------------*/ +PROCESS(rf_test_process, "RF test TX process"); +AUTOSTART_PROCESSES(&rf_test_process); + +static struct etimer et; +static struct broadcast_conn bc; +static struct unicast_conn uc; +rimeaddr_t addr; + +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(rf_test_process, ev, data) +{ + + PROCESS_BEGIN(); + + printf("\nStarting CC2430 RF test suite...\n"); + + broadcast_open(&bc, 128, 0); + unicast_open(&uc, 128, 0); + + while(1) { + etimer_set(&et, CLOCK_SECOND); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + etimer_reset(&et); + + printf("Sending broadcast packet\n"); + packetbuf_copyfrom("Hello everyone", 14); + broadcast_send(&bc); + + // TODO: Fix, freezes on unicast_send() + // printf("Sending unicast packet\n"); + // addr.u8[0] = 0; + // addr.u8[1] = 2; + // packetbuf_copyfrom("Hello you", 9); + // unicast_send(&uc, &addr); + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/