Initial commit of examples for the Sensinode/cc2430 platform.
This commit is contained in:
parent
bdce08d39d
commit
0e9220716e
9
examples/sensinode/Makefile
Normal file
9
examples/sensinode/Makefile
Normal file
|
@ -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
|
39
examples/sensinode/README
Normal file
39
examples/sensinode/README
Normal file
|
@ -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
|
||||
|
67
examples/sensinode/clock_test.c
Normal file
67
examples/sensinode/clock_test.c
Normal file
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* \file
|
||||
* Tests related to clocks and timers
|
||||
* \author
|
||||
* Zach Shelby <zach@sensinode.com>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "sys/clock.h"
|
||||
#include "dev/bus.h"
|
||||
#include "dev/leds.h"
|
||||
#include <stdio.h> /* 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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
23
examples/sensinode/hello_world.c
Normal file
23
examples/sensinode/hello_world.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
* \file
|
||||
* Basic hello world example
|
||||
* \author
|
||||
* Zach Shelby <zach@sensinode.com>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include <stdio.h> /* 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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
60
examples/sensinode/rf_test_rx.c
Normal file
60
examples/sensinode/rf_test_rx.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
* \file
|
||||
* RF test suite, receiver
|
||||
* \author
|
||||
* Zach Shelby <zach@sensinode.com>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "net/rime.h"
|
||||
#include <stdio.h> /* 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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
50
examples/sensinode/rf_test_tx.c
Normal file
50
examples/sensinode/rf_test_tx.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* \file
|
||||
* RF test suite, transmitter
|
||||
* \author
|
||||
* Zach Shelby <zach@sensinode.com>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "net/rime.h"
|
||||
#include <stdio.h> /* 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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
Loading…
Reference in a new issue