New platform: TI cc2530 Development Kit
This commits adds support for TI's SmartRF05 Eval. Board with cc2530 EMs Some initial support for cc2531 USB dongles
This commit is contained in:
parent
b7674c3636
commit
ad256e5014
68 changed files with 6824 additions and 0 deletions
52
platform/cc2530dk/Makefile.cc2530dk
Normal file
52
platform/cc2530dk/Makefile.cc2530dk
Normal file
|
@ -0,0 +1,52 @@
|
|||
# cc2530dk platform makefile
|
||||
|
||||
ifndef CONTIKI
|
||||
$(error CONTIKI not defined! You must specify where CONTIKI resides!)
|
||||
endif
|
||||
|
||||
CONTIKI_TARGET_DIRS = . dev
|
||||
CONTIKI_TARGET_MAIN = $(addprefix $(OBJECTDIR)/,contiki-main.rel)
|
||||
|
||||
CONTIKI_TARGET_SOURCEFILES = contiki-main.c
|
||||
CONTIKI_TARGET_SOURCEFILES += leds.c leds-arch.c
|
||||
CONTIKI_TARGET_SOURCEFILES += sensors.c smartrf-sensors.c
|
||||
CONTIKI_TARGET_SOURCEFILES += button-sensor.c adc-sensor.c smartrf-sensors.c
|
||||
CONTIKI_TARGET_SOURCEFILES += serial-line.c slip-arch.c slip.c #serial-flash.c
|
||||
CONTIKI_TARGET_SOURCEFILES += putchar.c debug.c
|
||||
|
||||
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
|
||||
|
||||
CLEAN += *.cc2530dk
|
||||
|
||||
ifdef UIP_CONF_IPV6
|
||||
CONTIKI_TARGET_SOURCEFILES += viztool.c
|
||||
endif
|
||||
|
||||
FORCE:
|
||||
|
||||
# .sensinode target so we can behave similar to other targets
|
||||
%.$(TARGET): %.hex FORCE
|
||||
cp $< $(<:.hex=.$(TARGET))
|
||||
@echo "\nReport"
|
||||
@echo "==============="
|
||||
@echo 'Code footprint:'
|
||||
@echo 'Area Addr Size' \
|
||||
' Decimal'
|
||||
@echo '---------------------------------- -------- --------' \
|
||||
' --------'
|
||||
@echo -n 'HOME,CSEG,CONST,XINIT,GS* $(HOME_START) '
|
||||
@egrep ',CODE\)' $(<:.hex=.map) | egrep -v '(^BANK[1-9][^=])' | uniq | \
|
||||
awk '{ SUM += $$5 } END { printf "%08X = %8d", SUM, SUM }'
|
||||
@echo '. bytes (REL,CON,CODE)'
|
||||
@egrep '(^BANK[1-9][^=])' $(<:.hex=.map) | uniq | sort
|
||||
@egrep -A 5 'Other memory' $(<:.hex=.mem)
|
||||
|
||||
%.upload: %.hex
|
||||
$(PROG) -P $<
|
||||
|
||||
sensinode.serialdump:
|
||||
$(SERIALDUMP)
|
||||
|
||||
### Define the CPU directory
|
||||
CONTIKI_CPU=$(CONTIKI)/cpu/cc253x
|
||||
include $(CONTIKI_CPU)/Makefile.cc253x
|
225
platform/cc2530dk/contiki-conf.h
Normal file
225
platform/cc2530dk/contiki-conf.h
Normal file
|
@ -0,0 +1,225 @@
|
|||
#ifndef __CONTIKI_CONF_H__
|
||||
#define __CONTIKI_CONF_H__
|
||||
|
||||
#include "8051def.h"
|
||||
#include "sys/cc.h"
|
||||
#include <string.h>
|
||||
|
||||
/* Include Project Specific conf */
|
||||
#ifdef PROJECT_CONF_H
|
||||
#include "project-conf.h"
|
||||
#endif /* PROJECT_CONF_H */
|
||||
|
||||
/* Time type. */
|
||||
typedef unsigned short clock_time_t;
|
||||
|
||||
/* Defines tick counts for a second. */
|
||||
#define CLOCK_CONF_SECOND 128
|
||||
|
||||
/* Energest Module */
|
||||
#ifndef ENERGEST_CONF_ON
|
||||
#define ENERGEST_CONF_ON 0
|
||||
#endif
|
||||
|
||||
/* Verbose Startup? Turning this off saves plenty of bytes of CODE in HOME */
|
||||
#define STARTUP_CONF_VERBOSE 0
|
||||
|
||||
/* More CODE space savings by turning off process names */
|
||||
#define PROCESS_CONF_NO_PROCESS_NAMES 1
|
||||
|
||||
/*
|
||||
* USARTs:
|
||||
* SmartRF RS232 -> USART0 / Alternative 1 (UART)
|
||||
* SmartRF LCD -> USART1 / Alternative 2 (SPI)
|
||||
*/
|
||||
#define UART_ON_USART 0
|
||||
|
||||
#define UART1_CONF_ENABLE 0
|
||||
|
||||
#ifndef UART0_CONF_ENABLE
|
||||
#define UART0_CONF_ENABLE 1
|
||||
#endif
|
||||
#ifndef UART0_CONF_WITH_INPUT
|
||||
#define UART0_CONF_WITH_INPUT 0
|
||||
#endif
|
||||
|
||||
#ifndef UART0_CONF_HIGH_SPEED
|
||||
#define UART0_CONF_HIGH_SPEED 0
|
||||
#endif
|
||||
|
||||
/* Are we a SLIP bridge? */
|
||||
#if SLIP_ARCH_CONF_ENABLE
|
||||
/* Make sure the UART is enabled, with interrupts */
|
||||
#undef UART0_CONF_ENABLE
|
||||
#undef UART0_CONF_WITH_INPUT
|
||||
#define UART0_CONF_ENABLE 1
|
||||
#define UART0_CONF_WITH_INPUT 1
|
||||
#define UIP_FALLBACK_INTERFACE slip_interface
|
||||
#endif
|
||||
|
||||
/* Output all captured frames over the UART in hexdump format */
|
||||
#ifndef CC2530_RF_CONF_HEXDUMP
|
||||
#define CC2530_RF_CONF_HEXDUMP 0
|
||||
#endif
|
||||
|
||||
#if CC2530_RF_CONF_HEXDUMP
|
||||
/* We need UART1 output */
|
||||
#undef UART_ZERO_CONF_ENABLE
|
||||
#define UART_ZERO_CONF_ENABLE 1
|
||||
#endif
|
||||
|
||||
/* Code Shortcuts */
|
||||
/*
|
||||
* When set, the RF driver is no longer a contiki process and the RX ISR is
|
||||
* disabled. Instead of polling the radio process when data arrives, we
|
||||
* periodically check for data by directly invoking the driver from main()
|
||||
|
||||
* When set, this directive also configures the following bypasses:
|
||||
* - process_post_synch() in tcpip_input() (we call packet_input())
|
||||
* - process_post_synch() in tcpip_uipcall (we call the relevant pthread)
|
||||
* - mac_call_sent_callback() is replaced with sent() in various places
|
||||
*
|
||||
* These are good things to do, we reduce stack usage, RAM size and code size
|
||||
*/
|
||||
#define SHORTCUTS_CONF_NETSTACK 1
|
||||
|
||||
/*
|
||||
* Sensors
|
||||
* It is harmless to #define XYZ 1
|
||||
* even if the sensor is not present on our device
|
||||
*/
|
||||
#ifndef BUTTON_SENSOR_CONF_ON
|
||||
#define BUTTON_SENSOR_CONF_ON 1 /* Buttons */
|
||||
#endif
|
||||
/* ADC - Turning this off will disable everything below */
|
||||
#ifndef ADC_SENSOR_CONF_ON
|
||||
#define ADC_SENSOR_CONF_ON 1
|
||||
#endif
|
||||
#define TEMP_SENSOR_CONF_ON 1 /* Temperature */
|
||||
#define VDD_SENSOR_CONF_ON 1 /* Supply Voltage */
|
||||
#define BATTERY_SENSOR_CONF_ON 0 /* Battery */
|
||||
|
||||
/* Low Power Modes - We only support PM0/Idle and PM1 */
|
||||
#ifndef LPM_CONF_MODE
|
||||
#define LPM_CONF_MODE 0 /* 0: no LPM, 1: MCU IDLE, 2: Drop to PM1 */
|
||||
#endif
|
||||
|
||||
/* Some files include leds.h before us */
|
||||
#undef LEDS_YELLOW
|
||||
#undef LEDS_RED
|
||||
#define LEDS_YELLOW 4
|
||||
#define LEDS_RED 2
|
||||
|
||||
/* DMA Configuration */
|
||||
#ifndef DMA_CONF_ON
|
||||
#define DMA_CONF_ON 0
|
||||
#endif
|
||||
|
||||
/* Viztool on by default for IPv6 builds */
|
||||
#if UIP_CONF_IPV6
|
||||
#ifndef VIZTOOL_CONF_ON
|
||||
#define VIZTOOL_CONF_ON 1
|
||||
#endif /* VIZTOOL_CONF_ON */
|
||||
#endif /* UIP_CONF_IPV6 */
|
||||
|
||||
/* Network Stack */
|
||||
#if UIP_CONF_IPV6
|
||||
#define NETSTACK_CONF_NETWORK sicslowpan_driver
|
||||
#else
|
||||
#define NETSTACK_CONF_NETWORK rime_driver
|
||||
#endif
|
||||
|
||||
#ifndef NETSTACK_CONF_MAC
|
||||
#define NETSTACK_CONF_MAC csma_driver
|
||||
#endif
|
||||
|
||||
#ifndef NETSTACK_CONF_RDC
|
||||
#define NETSTACK_CONF_RDC nullrdc_driver
|
||||
#define NULLRDC_802154_AUTOACK 1
|
||||
#define NULLRDC_802154_AUTOACK_HW 1
|
||||
#endif
|
||||
|
||||
#ifndef NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE
|
||||
#define NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE 8
|
||||
#endif
|
||||
|
||||
#define NETSTACK_CONF_FRAMER framer_802154
|
||||
#define NETSTACK_CONF_RADIO cc2530_rf_driver
|
||||
|
||||
/* RF Config */
|
||||
#define IEEE802154_CONF_PANID 0x5449 /* TI */
|
||||
|
||||
#ifndef CC2530_RF_CONF_CHANNEL
|
||||
#define CC2530_RF_CONF_CHANNEL 25
|
||||
#endif /* CC2530_RF_CONF_CHANNEL */
|
||||
|
||||
#ifndef CC2530_RF_CONF_AUTOACK
|
||||
#define CC2530_RF_CONF_AUTOACK 1
|
||||
#endif /* CC2530_CONF_AUTOACK */
|
||||
|
||||
#if UIP_CONF_IPV6
|
||||
/* Addresses, Sizes and Interfaces */
|
||||
/* 8-byte addresses here, 2 otherwise */
|
||||
#define RIMEADDR_CONF_SIZE 8
|
||||
#define UIP_CONF_LL_802154 1
|
||||
#define UIP_CONF_LLH_LEN 0
|
||||
#define UIP_CONF_NETIF_MAX_ADDRESSES 3
|
||||
|
||||
/* TCP, UDP, ICMP */
|
||||
#define UIP_CONF_TCP 0
|
||||
#define UIP_CONF_UDP 1
|
||||
#define UIP_CONF_UDP_CHECKSUMS 1
|
||||
|
||||
/* ND and Routing */
|
||||
#define UIP_CONF_ROUTER 1
|
||||
#define UIP_CONF_IPV6_RPL 1
|
||||
#define UIP_CONF_ND6_SEND_RA 0
|
||||
#define UIP_CONF_IP_FORWARD 0
|
||||
#define RPL_CONF_STATS 0
|
||||
#define RPL_CONF_MAX_DAG_ENTRIES 1
|
||||
#ifndef RPL_CONF_OF
|
||||
#define RPL_CONF_OF rpl_of_etx
|
||||
#endif
|
||||
|
||||
#define UIP_CONF_ND6_REACHABLE_TIME 600000
|
||||
#define UIP_CONF_ND6_RETRANS_TIMER 10000
|
||||
|
||||
#ifndef UIP_CONF_DS6_NBR_NBU
|
||||
#define UIP_CONF_DS6_NBR_NBU 4 /* Handle n Neighbors */
|
||||
#endif
|
||||
#ifndef UIP_CONF_DS6_ROUTE_NBU
|
||||
#define UIP_CONF_DS6_ROUTE_NBU 4 /* Handle n Routes */
|
||||
#endif
|
||||
|
||||
/* uIP */
|
||||
#define UIP_CONF_BUFFER_SIZE 240
|
||||
#define UIP_CONF_IPV6_QUEUE_PKT 0
|
||||
#define UIP_CONF_IPV6_CHECKS 1
|
||||
#define UIP_CONF_IPV6_REASSEMBLY 0
|
||||
|
||||
/* 6lowpan */
|
||||
#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06
|
||||
#ifndef SICSLOWPAN_CONF_FRAG
|
||||
#define SICSLOWPAN_CONF_FRAG 0 /* About 2KB of CODE if 1 */
|
||||
#endif
|
||||
#define SICSLOWPAN_CONF_MAXAGE 8
|
||||
|
||||
/* Define our IPv6 prefixes/contexts here */
|
||||
#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 1
|
||||
#define SICSLOWPAN_CONF_ADDR_CONTEXT_0 { \
|
||||
addr_contexts[0].prefix[0] = 0xaa; \
|
||||
addr_contexts[0].prefix[1] = 0xaa; \
|
||||
}
|
||||
|
||||
#define MAC_CONF_CHANNEL_CHECK_RATE 8
|
||||
#define QUEUEBUF_CONF_NUM 6
|
||||
|
||||
#else /* UIP_CONF_IPV6 */
|
||||
/* Network setup for non-IPv6 (rime). */
|
||||
#define UIP_CONF_IP_FORWARD 1
|
||||
#define UIP_CONF_BUFFER_SIZE 108
|
||||
#define RIME_CONF_NO_POLITE_ANNOUCEMENTS 0
|
||||
#define QUEUEBUF_CONF_NUM 8
|
||||
#endif /* UIP_CONF_IPV6 */
|
||||
|
||||
#endif /* __CONTIKI_CONF_H__ */
|
333
platform/cc2530dk/contiki-main.c
Normal file
333
platform/cc2530dk/contiki-main.c
Normal file
|
@ -0,0 +1,333 @@
|
|||
#include "contiki.h"
|
||||
#include "soc.h"
|
||||
#include "sys/clock.h"
|
||||
#include "sys/autostart.h"
|
||||
#include "dev/serial-line.h"
|
||||
#include "dev/slip.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/uart0.h"
|
||||
#include "dev/dma.h"
|
||||
#include "dev/cc2530-rf.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include "dev/clock-isr.h"
|
||||
#include "dev/lpm.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/adc-sensor.h"
|
||||
#include "dev/leds-arch.h"
|
||||
#include "net/rime.h"
|
||||
#include "net/netstack.h"
|
||||
#include "net/mac/frame802154.h"
|
||||
#include "debug.h"
|
||||
#include "cc253x.h"
|
||||
#include "sfr-bits.h"
|
||||
#include "contiki-lib.h"
|
||||
#include "contiki-net.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if VIZTOOL_CONF_ON
|
||||
PROCESS_NAME(viztool_process);
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef STARTUP_CONF_VERBOSE
|
||||
#define STARTUP_VERBOSE STARTUP_CONF_VERBOSE
|
||||
#else
|
||||
#define STARTUP_VERBOSE 0
|
||||
#endif
|
||||
|
||||
#if STARTUP_VERBOSE
|
||||
#define PUTSTRING(...) putstring(__VA_ARGS__)
|
||||
#define PUTHEX(...) puthex(__VA_ARGS__)
|
||||
#define PUTBIN(...) putbin(__VA_ARGS__)
|
||||
#define PUTCHAR(...) putchar(__VA_ARGS__)
|
||||
#else
|
||||
#define PUTSTRING(...) do {} while(0)
|
||||
#define PUTHEX(...) do {} while(0)
|
||||
#define PUTBIN(...) do {} while(0)
|
||||
#define PUTCHAR(...) do {} while(0)
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern rimeaddr_t rimeaddr_node_addr;
|
||||
static __data int r;
|
||||
static __data int len;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if ENERGEST_CONF_ON
|
||||
static unsigned long irq_energest = 0;
|
||||
#define ENERGEST_IRQ_SAVE(a) do { \
|
||||
a = energest_type_time(ENERGEST_TYPE_IRQ); } while(0)
|
||||
#define ENERGEST_IRQ_RESTORE(a) do { \
|
||||
energest_type_set(ENERGEST_TYPE_IRQ, a); } while(0)
|
||||
#else
|
||||
#define ENERGEST_IRQ_SAVE(a) do {} while(0)
|
||||
#define ENERGEST_IRQ_RESTORE(a) do {} while(0)
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
fade(int l)
|
||||
{
|
||||
volatile int i, a;
|
||||
int k, j;
|
||||
for(k = 0; k < 400; ++k) {
|
||||
j = k > 200? 400 - k: k;
|
||||
|
||||
leds_on(l);
|
||||
for(i = 0; i < j; ++i) {
|
||||
a = i;
|
||||
}
|
||||
leds_off(l);
|
||||
for(i = 0; i < 200 - j; ++i) {
|
||||
a = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
set_rime_addr(void)
|
||||
{
|
||||
uint8_t *addr_long = NULL;
|
||||
uint16_t addr_short = 0;
|
||||
char i;
|
||||
|
||||
__xdata unsigned char * macp = &X_IEEE_ADDR;
|
||||
|
||||
PUTSTRING("Rime is 0x");
|
||||
PUTHEX(sizeof(rimeaddr_t));
|
||||
PUTSTRING(" bytes long\n");
|
||||
|
||||
PUTSTRING("Reading MAC from Info Page\n");
|
||||
|
||||
for(i = (RIMEADDR_SIZE - 1); i >= 0; --i) {
|
||||
rimeaddr_node_addr.u8[i] = *macp;
|
||||
macp++;
|
||||
}
|
||||
|
||||
/* Now the address is stored MSB first */
|
||||
#if STARTUP_VERBOSE
|
||||
PUTSTRING("Rime configured with address ");
|
||||
for(i = 0; i < RIMEADDR_SIZE - 1; i++) {
|
||||
PUTHEX(rimeaddr_node_addr.u8[i]);
|
||||
PUTCHAR(':');
|
||||
}
|
||||
PUTHEX(rimeaddr_node_addr.u8[i]);
|
||||
PUTCHAR('\n');
|
||||
#endif
|
||||
|
||||
cc2530_rf_set_addr(IEEE802154_PANID);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
/* Hardware initialization */
|
||||
clock_init();
|
||||
soc_init();
|
||||
rtimer_init();
|
||||
|
||||
/* Init LEDs here */
|
||||
leds_init();
|
||||
leds_off(LEDS_ALL);
|
||||
fade(LEDS_GREEN);
|
||||
|
||||
/* initialize process manager. */
|
||||
process_init();
|
||||
|
||||
/* Init UART */
|
||||
uart0_init();
|
||||
|
||||
#if DMA_ON
|
||||
dma_init();
|
||||
#endif
|
||||
|
||||
#if SLIP_ARCH_CONF_ENABLE
|
||||
slip_arch_init(0);
|
||||
#else
|
||||
uart0_set_input(serial_line_input_byte);
|
||||
serial_line_init();
|
||||
#endif
|
||||
fade(LEDS_RED);
|
||||
|
||||
PUTSTRING("##########################################\n");
|
||||
putstring(CONTIKI_VERSION_STRING "\n");
|
||||
putstring("TI SmartRF05 EB\n");
|
||||
switch(CHIPID) {
|
||||
case 0xA5:
|
||||
putstring("cc2530");
|
||||
break;
|
||||
case 0xB5:
|
||||
putstring("cc2531");
|
||||
break;
|
||||
case 0x95:
|
||||
putstring("cc2533");
|
||||
break;
|
||||
case 0x8D:
|
||||
putstring("cc2540");
|
||||
break;
|
||||
}
|
||||
|
||||
putstring("-F");
|
||||
switch(CHIPINFO0 & 0x70) {
|
||||
case 0x40:
|
||||
putstring("256, ");
|
||||
break;
|
||||
case 0x30:
|
||||
putstring("128, ");
|
||||
break;
|
||||
case 0x20:
|
||||
putstring("64, ");
|
||||
break;
|
||||
case 0x10:
|
||||
putstring("32, ");
|
||||
break;
|
||||
}
|
||||
puthex(CHIPINFO1 + 1);
|
||||
putstring("KB SRAM\n");
|
||||
|
||||
PUTSTRING("\nSDCC Build:\n");
|
||||
#if STARTUP_VERBOSE
|
||||
#ifdef HAVE_SDCC_BANKING
|
||||
PUTSTRING(" With Banking.\n");
|
||||
#endif /* HAVE_SDCC_BANKING */
|
||||
#ifdef SDCC_MODEL_LARGE
|
||||
PUTSTRING(" --model-large\n");
|
||||
#endif /* SDCC_MODEL_LARGE */
|
||||
#ifdef SDCC_MODEL_HUGE
|
||||
PUTSTRING(" --model-huge\n");
|
||||
#endif /* SDCC_MODEL_HUGE */
|
||||
#ifdef SDCC_STACK_AUTO
|
||||
PUTSTRING(" --stack-auto\n");
|
||||
#endif /* SDCC_STACK_AUTO */
|
||||
|
||||
PUTCHAR('\n');
|
||||
|
||||
PUTSTRING(" Net: ");
|
||||
PUTSTRING(NETSTACK_NETWORK.name);
|
||||
PUTCHAR('\n');
|
||||
PUTSTRING(" MAC: ");
|
||||
PUTSTRING(NETSTACK_MAC.name);
|
||||
PUTCHAR('\n');
|
||||
PUTSTRING(" RDC: ");
|
||||
PUTSTRING(NETSTACK_RDC.name);
|
||||
PUTCHAR('\n');
|
||||
|
||||
PUTSTRING("##########################################\n");
|
||||
#endif
|
||||
|
||||
watchdog_init();
|
||||
|
||||
/* Initialise the H/W RNG engine. */
|
||||
random_init(0);
|
||||
|
||||
/* start services */
|
||||
process_start(&etimer_process, NULL);
|
||||
ctimer_init();
|
||||
|
||||
/* initialize the netstack */
|
||||
netstack_init();
|
||||
set_rime_addr();
|
||||
|
||||
#if BUTTON_SENSOR_ON || ADC_SENSOR_ON
|
||||
process_start(&sensors_process, NULL);
|
||||
BUTTON_SENSOR_ACTIVATE();
|
||||
ADC_SENSOR_ACTIVATE();
|
||||
#endif
|
||||
|
||||
#if UIP_CONF_IPV6
|
||||
memcpy(&uip_lladdr.addr, &rimeaddr_node_addr, sizeof(uip_lladdr.addr));
|
||||
queuebuf_init();
|
||||
process_start(&tcpip_process, NULL);
|
||||
#endif /* UIP_CONF_IPV6 */
|
||||
|
||||
#if VIZTOOL_CONF_ON
|
||||
process_start(&viztool_process, NULL);
|
||||
#endif
|
||||
|
||||
energest_init();
|
||||
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
||||
|
||||
autostart_start(autostart_processes);
|
||||
|
||||
watchdog_start();
|
||||
|
||||
fade(LEDS_YELLOW);
|
||||
|
||||
while(1) {
|
||||
do {
|
||||
/* Reset watchdog and handle polls and events */
|
||||
watchdog_periodic();
|
||||
r = process_run();
|
||||
} while(r > 0);
|
||||
#if SHORTCUTS_CONF_NETSTACK
|
||||
len = NETSTACK_RADIO.pending_packet();
|
||||
if(len) {
|
||||
packetbuf_clear();
|
||||
len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE);
|
||||
if(len > 0) {
|
||||
packetbuf_set_datalen(len);
|
||||
NETSTACK_RDC.input();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LPM_MODE
|
||||
#if (LPM_MODE==LPM_MODE_PM2)
|
||||
SLEEP &= ~OSC_PD; /* Make sure both HS OSCs are on */
|
||||
while(!(SLEEP & HFRC_STB)); /* Wait for RCOSC to be stable */
|
||||
CLKCON |= OSC; /* Switch to the RCOSC */
|
||||
while(!(CLKCON & OSC)); /* Wait till it's happened */
|
||||
SLEEP |= OSC_PD; /* Turn the other one off */
|
||||
#endif /* LPM_MODE==LPM_MODE_PM2 */
|
||||
|
||||
/*
|
||||
* Set MCU IDLE or Drop to PM1. Any interrupt will take us out of LPM
|
||||
* Sleep Timer will wake us up in no more than 7.8ms (max idle interval)
|
||||
*/
|
||||
SLEEPCMD = (SLEEPCMD & 0xFC) | (LPM_MODE - 1);
|
||||
|
||||
#if (LPM_MODE==LPM_MODE_PM2)
|
||||
/*
|
||||
* Wait 3 NOPs. Either an interrupt occurred and SLEEP.MODE was cleared or
|
||||
* no interrupt occurred and we can safely power down
|
||||
*/
|
||||
__asm
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
__endasm;
|
||||
|
||||
if(SLEEPCMD & SLEEP_MODE0) {
|
||||
#endif /* LPM_MODE==LPM_MODE_PM2 */
|
||||
|
||||
ENERGEST_OFF(ENERGEST_TYPE_CPU);
|
||||
ENERGEST_ON(ENERGEST_TYPE_LPM);
|
||||
|
||||
/* We are only interested in IRQ energest while idle or in LPM */
|
||||
ENERGEST_IRQ_RESTORE(irq_energest);
|
||||
|
||||
/* Go IDLE or Enter PM1 */
|
||||
PCON |= PCON_IDLE;
|
||||
|
||||
/* First instruction upon exiting PM1 must be a NOP */
|
||||
__asm
|
||||
nop
|
||||
__endasm;
|
||||
|
||||
/* Remember energest IRQ for next pass */
|
||||
ENERGEST_IRQ_SAVE(irq_energest);
|
||||
|
||||
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
||||
ENERGEST_OFF(ENERGEST_TYPE_LPM);
|
||||
|
||||
#if (LPM_MODE==LPM_MODE_PM2)
|
||||
SLEEPCMD &= ~SLEEP_OSC_PD; /* Make sure both HS OSCs are on */
|
||||
while(!(SLEEPCMD & SLEEP_XOSC_STB)); /* Wait for XOSC to be stable */
|
||||
CLKCONCMD &= ~CLKCONCMD_OSC; /* Switch to the XOSC */
|
||||
/*
|
||||
* On occasion the XOSC is reported stable when in reality it's not.
|
||||
* We need to wait for a safeguard of 64us or more before selecting it
|
||||
*/
|
||||
clock_delay(10);
|
||||
while(CLKCONCMD & CLKCONCMD_OSC); /* Wait till it's happened */
|
||||
}
|
||||
#endif /* LPM_MODE==LPM_MODE_PM2 */
|
||||
#endif /* LPM_MODE */
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
42
platform/cc2530dk/debug.c
Normal file
42
platform/cc2530dk/debug.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* \file
|
||||
*
|
||||
* Definition of some debugging functions.
|
||||
*
|
||||
* putstring() and puthex() are from msp430/watchdog.c
|
||||
*
|
||||
* \author
|
||||
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#include "8051def.h"
|
||||
#include "debug.h"
|
||||
|
||||
static const char hexconv[] = "0123456789abcdef";
|
||||
static const char binconv[] = "01";
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
putstring(char *s)
|
||||
{
|
||||
while(*s) {
|
||||
putchar(*s++);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
puthex(uint8_t c)
|
||||
{
|
||||
putchar(hexconv[c >> 4]);
|
||||
putchar(hexconv[c & 0x0f]);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
putbin(uint8_t c)
|
||||
{
|
||||
unsigned char i = 0x80;
|
||||
while(i) {
|
||||
putchar(binconv[(c & i) != 0]);
|
||||
i >>= 1;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
54
platform/cc2530dk/debug.h
Normal file
54
platform/cc2530dk/debug.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Header file for debugging functions used by the sensinode port.
|
||||
*
|
||||
* putstring() and puthex() are from msp430/watchdog.c
|
||||
*
|
||||
* \author
|
||||
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#ifndef __DEBUG_H__
|
||||
#define __DEBUG_H__
|
||||
|
||||
#include "8051def.h"
|
||||
#include "dev/uart1.h"
|
||||
|
||||
void putchar(char c);
|
||||
void putstring(char *s);
|
||||
void puthex(uint8_t c);
|
||||
void putbin(uint8_t c);
|
||||
|
||||
#endif /* __DEBUG_H__ */
|
123
platform/cc2530dk/dev/adc-sensor.c
Normal file
123
platform/cc2530dk/dev/adc-sensor.c
Normal file
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright (c) 2011, George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* ADC sensor module for TI SmartRF05EB devices.
|
||||
*
|
||||
* \author
|
||||
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
*/
|
||||
#include "sfr-bits.h"
|
||||
#include "cc253x.h"
|
||||
#include "adc-sensor.h"
|
||||
|
||||
#if ADC_SENSOR_ON
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
uint16_t reading;
|
||||
/*
|
||||
* For single-shot AD conversions, we may only write to ADCCON3[3:0] once
|
||||
* (This write triggers the conversion). We thus use the variable 'command'
|
||||
* to store intermediate steps (reference, decimation rate, input channel)
|
||||
*/
|
||||
uint8_t command;
|
||||
|
||||
/* 1.25V ref, max decimation rate */
|
||||
command = ADCCON3_EDIV1 | ADCCON3_EDIV0;
|
||||
|
||||
/* Clear the Interrupt Flag */
|
||||
ADCIF = 0;
|
||||
|
||||
/* Depending on the desired reading, append the input bits to 'command' and
|
||||
* enable the corresponding input channel in ADCCFG if necessary */
|
||||
switch(type) {
|
||||
#if TEMP_SENSOR_ON
|
||||
case ADC_SENSOR_TYPE_TEMP:
|
||||
command |= ADCCON3_ECH3 | ADCCON3_ECH2 | ADCCON3_ECH1;
|
||||
break;
|
||||
#endif
|
||||
#if VDD_SENSOR_ON
|
||||
case ADC_SENSOR_TYPE_VDD:
|
||||
command |= ADCCON3_ECH3 | ADCCON3_ECH2 | ADCCON3_ECH1 | ADCCON3_ECH0;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
/* If the sensor is not present or disabled in conf, return -1 */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Writing in bits 3:0 of ADCCON3 will trigger a single conversion */
|
||||
ADCCON3 = command;
|
||||
|
||||
/*
|
||||
* When the conversion is complete, the ADC interrupt flag is set. We don't
|
||||
* use an ISR here, we just wait on the flag and clear it afterwards.
|
||||
*/
|
||||
while(!ADCIF);
|
||||
|
||||
/* Clear the Interrupt Flag */
|
||||
ADCIF = 0;
|
||||
|
||||
reading = ADCL;
|
||||
reading |= (((uint8_t) ADCH) << 8);
|
||||
/* 12-bit decimation rate: 4 LS bits are noise */
|
||||
reading >>= 4;
|
||||
|
||||
return reading;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
#if TEMP_SENSOR_ON
|
||||
/* Connect temperature sensor to the SoC */
|
||||
ATEST = 1;
|
||||
TR0 = 1;
|
||||
#endif
|
||||
APCFG = 0; /* Disables Input Channels */
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(adc_sensor, ADC_SENSOR, value, configure, status);
|
||||
#endif /* ADC_SENSOR_ON */
|
82
platform/cc2530dk/dev/adc-sensor.h
Normal file
82
platform/cc2530dk/dev/adc-sensor.h
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (c) 2011, George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Header file for ADC sensors on the SmartRF05EB.
|
||||
*
|
||||
* Sensors will be off by default, unless turned on explicitly
|
||||
* in contiki-conf.h
|
||||
*
|
||||
* \author
|
||||
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#ifndef __ADC_SENSOR_H__
|
||||
#define __ADC_SENSOR_H__
|
||||
|
||||
#include "cc253x.h"
|
||||
#include "contiki-conf.h"
|
||||
#include "lib/sensors.h"
|
||||
|
||||
/* ADC Sensor Types */
|
||||
#define ADC_SENSOR "ADC"
|
||||
|
||||
#define ADC_SENSOR_TYPE_TEMP 0
|
||||
#define ADC_SENSOR_TYPE_VDD 4
|
||||
|
||||
#ifdef ADC_SENSOR_CONF_ON
|
||||
#define ADC_SENSOR_ON ADC_SENSOR_CONF_ON
|
||||
#endif /* ADC_SENSOR_CONF_ON */
|
||||
|
||||
#if ADC_SENSOR_ON
|
||||
extern const struct sensors_sensor adc_sensor;
|
||||
#define ADC_SENSOR_ACTIVATE() adc_sensor.configure(SENSORS_ACTIVE, 1)
|
||||
#else
|
||||
#define ADC_SENSOR_ACTIVATE()
|
||||
#endif /* ADC_SENSOR_ON */
|
||||
|
||||
/* Battery - SmartRF stuff */
|
||||
#ifdef BATTERY_SENSOR_CONF_ON
|
||||
#define BATTERY_SENSOR_ON BATTERY_SENSOR_CONF_ON
|
||||
#endif /* BATTERY_SENSOR_CONF_ON */
|
||||
|
||||
/* Temperature - Available on all devices */
|
||||
#ifdef TEMP_SENSOR_CONF_ON
|
||||
#define TEMP_SENSOR_ON TEMP_SENSOR_CONF_ON
|
||||
#endif /* TEMP_SENSOR_CONF_ON */
|
||||
|
||||
/* Supply Voltage (VDD / 3) - Available on all devices*/
|
||||
#ifdef VDD_SENSOR_CONF_ON
|
||||
#define VDD_SENSOR_ON VDD_SENSOR_CONF_ON
|
||||
#endif /* VDD_SENSOR_CONF_ON */
|
||||
|
||||
#endif /* __ADC_SENSOR_H__ */
|
105
platform/cc2530dk/dev/button-sensor.c
Normal file
105
platform/cc2530dk/dev/button-sensor.c
Normal file
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains ISRs: Keep it in the HOME bank.
|
||||
*/
|
||||
#include "dev/port.h"
|
||||
#include "dev/button-sensor.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if BUTTON_SENSOR_ON
|
||||
static __data struct timer debouncetimer;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
int value(int type)
|
||||
{
|
||||
return BUTTON_READ() || !timer_expired(&debouncetimer);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
int status(int type)
|
||||
{
|
||||
switch (type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return BUTTON_IRQ_ENABLED();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
int configure(int type, int value)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
P0INP |= 2; /* Tri-state */
|
||||
BUTTON_IRQ_ON_PRESS();
|
||||
BUTTON_FUNC_GPIO();
|
||||
BUTTON_DIR_INPUT();
|
||||
return 1;
|
||||
case SENSORS_ACTIVE:
|
||||
if(value) {
|
||||
if(!BUTTON_IRQ_ENABLED()) {
|
||||
timer_set(&debouncetimer, 0);
|
||||
BUTTON_IRQ_FLAG_OFF();
|
||||
BUTTON_IRQ_ENABLE();
|
||||
}
|
||||
} else {
|
||||
BUTTON_IRQ_DISABLE();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
port_0_isr(void) __interrupt(P0INT_VECTOR)
|
||||
{
|
||||
EA = 0;
|
||||
ENERGEST_ON(ENERGEST_TYPE_IRQ);
|
||||
|
||||
/* This ISR is for the entire port. Check if the interrupt was caused by our
|
||||
* button's pin. */
|
||||
if(BUTTON_IRQ_CHECK()) {
|
||||
if(timer_expired(&debouncetimer)) {
|
||||
timer_set(&debouncetimer, CLOCK_SECOND / 8);
|
||||
sensors_changed(&button_sensor);
|
||||
}
|
||||
}
|
||||
|
||||
BUTTON_IRQ_FLAG_OFF();
|
||||
|
||||
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
|
||||
EA = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR, value, configure, status);
|
||||
#endif /* BUTTON_SENSOR_ON */
|
80
platform/cc2530dk/dev/button-sensor.h
Normal file
80
platform/cc2530dk/dev/button-sensor.h
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2011, George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Override core/dev/button-sensor.h
|
||||
*
|
||||
* \author
|
||||
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#ifndef __BUTTON_SENSOR_H__
|
||||
#define __BUTTON_SENSOR_H__
|
||||
|
||||
#include "contiki-conf.h"
|
||||
#include "lib/sensors.h"
|
||||
|
||||
#define BUTTON_PORT 0
|
||||
#define BUTTON_PIN 1
|
||||
|
||||
#define BUTTON_SENSOR "Button"
|
||||
|
||||
/*
|
||||
* SmartRF Buttons
|
||||
* B1: P0_1, B2: Not Connected
|
||||
*/
|
||||
#ifdef BUTTON_SENSOR_CONF_ON
|
||||
#define BUTTON_SENSOR_ON BUTTON_SENSOR_CONF_ON
|
||||
#endif /* BUTTON_SENSOR_CONF_ON */
|
||||
|
||||
#if BUTTON_SENSOR_ON
|
||||
extern const struct sensors_sensor button_sensor;
|
||||
/* Button 1: P0_1 - Port 0 ISR needed */
|
||||
void port_0_isr(void) __interrupt(P0INT_VECTOR);
|
||||
#define BUTTON_SENSOR_ACTIVATE() button_sensor.configure(SENSORS_ACTIVE, 1)
|
||||
#else
|
||||
#define BUTTON_SENSOR_ACTIVATE()
|
||||
#endif /* BUTTON_SENSOR_ON */
|
||||
|
||||
/* Define macros for button 1 */
|
||||
#define BUTTON_READ() PORT_READ(BUTTON_PORT, BUTTON_PIN)
|
||||
#define BUTTON_FUNC_GPIO() PORT_FUNC_GPIO(BUTTON_PORT, BUTTON_PIN)
|
||||
#define BUTTON_DIR_INPUT() PORT_DIR_INPUT(BUTTON_PORT, BUTTON_PIN)
|
||||
#define BUTTON_IRQ_ENABLED() PORT_IRQ_ENABLED(BUTTON_PORT, BUTTON_PIN)
|
||||
#define BUTTON_IRQ_CHECK() PORT_IRQ_CHECK(BUTTON_PORT, BUTTON_PIN)
|
||||
#define BUTTON_IRQ_ENABLE() PORT_IRQ_ENABLE(BUTTON_PORT, BUTTON_PIN)
|
||||
#define BUTTON_IRQ_DISABLE() PORT_IRQ_DISABLE(BUTTON_PORT, BUTTON_PIN)
|
||||
#define BUTTON_IRQ_FLAG_OFF() PORT_IRQ_FLAG_OFF(BUTTON_PORT, BUTTON_PIN)
|
||||
#define BUTTON_IRQ_ON_PRESS() PORT_IRQ_EDGE_RISE(BUTTON_PORT, BUTTON_PIN)
|
||||
#define BUTTON_IRQ_ON_RELEASE() PORT_IRQ_EDGE_FALL(BUTTON_PORT, BUTTON_PIN)
|
||||
|
||||
#endif /* __BUTTON_SENSOR_H__ */
|
87
platform/cc2530dk/dev/leds-arch.c
Normal file
87
platform/cc2530dk/dev/leds-arch.c
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (c) 2011, George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Platform-specific led driver for the TI SmartRF05 Eval. Board.
|
||||
*
|
||||
* \author
|
||||
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
*/
|
||||
#include "contiki-conf.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/leds-arch.h"
|
||||
#include "cc253x.h"
|
||||
|
||||
/*
|
||||
* LEDS
|
||||
* 1: P1_0
|
||||
* 2: P1_1
|
||||
* 3: P1_4
|
||||
* 4: P0_1 (LED4 shares port/pin with B1 and is currently unused)
|
||||
*/
|
||||
|
||||
/* H/W Connections */
|
||||
#define LED1_PIN P1_0
|
||||
#define LED2_PIN P1_1
|
||||
#define LED3_PIN P1_4
|
||||
|
||||
/* P0DIR and P0SEL masks */
|
||||
#define LED1_MASK 0x01
|
||||
#define LED2_MASK 0x02
|
||||
#define LED3_MASK 0x10
|
||||
#define LED4_MASK 0x02
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
leds_arch_init(void)
|
||||
{
|
||||
P1SEL &= ~(LED1_MASK | LED2_MASK | LED3_MASK);
|
||||
P1DIR |= (LED1_MASK | LED2_MASK | LED3_MASK);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
unsigned char
|
||||
leds_arch_get(void)
|
||||
{
|
||||
unsigned char v;
|
||||
|
||||
v = (unsigned char) (LED1_PIN | (LED2_PIN << 1) | (LED3_PIN << 2));
|
||||
|
||||
return v;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
leds_arch_set(unsigned char leds)
|
||||
{
|
||||
LED1_PIN = leds & 0x01;
|
||||
LED2_PIN = (leds & 0x02) >> 1;
|
||||
LED3_PIN = (leds & 0x04) >> 2;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
53
platform/cc2530dk/dev/leds-arch.h
Normal file
53
platform/cc2530dk/dev/leds-arch.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2011, George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Header file for platform-specific led functionality
|
||||
*
|
||||
* \author
|
||||
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __LEDS_ARCH_H__
|
||||
#define __LEDS_ARCH_H__
|
||||
|
||||
#include "dev/port.h"
|
||||
|
||||
/* Led 4 on the SmartRF05EB is multiplexed with Button 1 on P0_1 */
|
||||
#define LED4_READ() PORT_READ(LED4_PORT, LED4_PIN)
|
||||
#define LED4_WRITE(v) PORT_WRITE(LED4_PORT, LED4_PIN, v)
|
||||
#define LED4_FUNC_GPIO() PORT_FUNC_GPIO(LED4_PORT, LED4_PIN)
|
||||
#define LED4_DIR_INPUT() PORT_DIR_INPUT(LED4_PORT, LED4_PIN)
|
||||
#define LED4_DIR_OUTPUT() PORT_DIR_OUTPUT(LED4_PORT, LED4_PIN)
|
||||
|
||||
#endif /* __LEDS_ARCH_H__ */
|
50
platform/cc2530dk/dev/slip-arch.c
Normal file
50
platform/cc2530dk/dev/slip-arch.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)$Id: slip_uart1.c,v 1.8 2008/02/03 20:59:35 adamdunkels Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
* Machine dependent cc2530eb SLIP routines for UART1.
|
||||
*/
|
||||
|
||||
#include "dev/slip.h"
|
||||
#include "dev/uart0.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
slip_arch_writeb(unsigned char c)
|
||||
{
|
||||
uart0_writeb(c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
slip_arch_init(unsigned long ubr)
|
||||
{
|
||||
uart0_set_input(slip_input_byte);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
54
platform/cc2530dk/dev/smartrf-sensors.c
Normal file
54
platform/cc2530dk/dev/smartrf-sensors.c
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2011, George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Data structures for SmartRF05EB sensing elements
|
||||
*
|
||||
* \author
|
||||
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/adc-sensor.h"
|
||||
#include "sys/energest.h"
|
||||
|
||||
const struct sensors_sensor *sensors[] = {
|
||||
#if ADC_SENSOR_ON
|
||||
&adc_sensor,
|
||||
#endif
|
||||
#if BUTTON_SENSOR_ON
|
||||
&button_sensor,
|
||||
#endif
|
||||
0
|
||||
};
|
||||
|
||||
unsigned char sensors_flags[(sizeof(sensors) / sizeof(struct sensors_sensor *))];
|
38
platform/cc2530dk/putchar.c
Normal file
38
platform/cc2530dk/putchar.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* \file
|
||||
* hardware-specific putchar() routine for TI SmartRF05EB
|
||||
*
|
||||
* \author
|
||||
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#include "contiki-conf.h"
|
||||
#include "dev/uart0.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
putchar(char c)
|
||||
{
|
||||
#if SLIP_ARCH_CONF_ENABLE
|
||||
#define SLIP_END 0300
|
||||
static char debug_frame = 0;
|
||||
|
||||
if(!debug_frame) { /* Start of debug output */
|
||||
uart0_writeb(SLIP_END);
|
||||
uart0_writeb('\r'); /* Type debug line == '\r' */
|
||||
debug_frame = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
uart0_writeb((char)c);
|
||||
|
||||
#if SLIP_ARCH_CONF_ENABLE
|
||||
/*
|
||||
* Line buffered output, a newline marks the end of debug output and
|
||||
* implicitly flushes debug output.
|
||||
*/
|
||||
if(c == '\n') {
|
||||
uart0_writeb(SLIP_END);
|
||||
debug_frame = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
13
platform/cc2530dk/segment.rules
Normal file
13
platform/cc2530dk/segment.rules
Normal file
|
@ -0,0 +1,13 @@
|
|||
# segment.rules - platform
|
||||
|
||||
# segment.rules file for platform code
|
||||
# Please see cpu/cc2430/segment.rules for more info on code segments
|
||||
# and for rules of thumb on what to do and what not to do
|
||||
|
||||
# Keep main() in HOME
|
||||
HOME contiki-main.c
|
||||
|
||||
# Files with ISRs must be in HOME
|
||||
HOME button-sensor.c
|
||||
|
||||
# segment.rules - platform - end
|
298
platform/cc2530dk/viztool.c
Normal file
298
platform/cc2530dk/viztool.c
Normal file
|
@ -0,0 +1,298 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Loughborough University - Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Small UDP app used to retrieve neighbor cache and routing table
|
||||
* entries and send them to an external endpoint
|
||||
*
|
||||
* \author
|
||||
* George Oikonomou - <oikonomou@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "contiki-lib.h"
|
||||
#include "contiki-net.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
|
||||
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
||||
|
||||
#ifndef VIZTOOL_MAX_PAYLOAD_LEN
|
||||
#define VIZTOOL_MAX_PAYLOAD_LEN 60
|
||||
#endif
|
||||
|
||||
static struct uip_udp_conn *server_conn;
|
||||
static unsigned char buf[VIZTOOL_MAX_PAYLOAD_LEN];
|
||||
static int8_t len;
|
||||
|
||||
#define VIZTOOL_UDP_PORT 60001
|
||||
|
||||
/* Request Bits */
|
||||
#define REQUEST_TYPE_ND 1
|
||||
#define REQUEST_TYPE_RT 2
|
||||
#define REQUEST_TYPE_DRT 3
|
||||
#define REQUEST_TYPE_ADDR 4
|
||||
#define REQUEST_TYPE_TOTALS 0xFF
|
||||
|
||||
extern uip_ds6_netif_t uip_ds6_if;
|
||||
extern uip_ds6_route_t uip_ds6_routing_table[UIP_DS6_ROUTE_NB];
|
||||
extern uip_ds6_nbr_t uip_ds6_nbr_cache[UIP_DS6_NBR_NB];
|
||||
extern uip_ds6_defrt_t uip_ds6_defrt_list[UIP_DS6_DEFRT_NB];
|
||||
extern u16_t uip_len;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t
|
||||
process_request()
|
||||
{
|
||||
uint8_t len;
|
||||
uint8_t count; /* How many did we pack? */
|
||||
uint8_t i;
|
||||
uint8_t left;
|
||||
uint8_t entry_size;
|
||||
|
||||
left = VIZTOOL_MAX_PAYLOAD_LEN - 1;
|
||||
len = 2; /* start filling the buffer from position [2] */
|
||||
count = 0;
|
||||
if(buf[0] == REQUEST_TYPE_ND) {
|
||||
/* Neighbors */
|
||||
PRINTF("Neighbors\n");
|
||||
for(i = buf[1]; i < UIP_DS6_NBR_NB; i++) {
|
||||
if(uip_ds6_nbr_cache[i].isused) {
|
||||
entry_size = sizeof(i) + sizeof(uip_ipaddr_t) + sizeof(uip_lladdr_t)
|
||||
+ sizeof(uip_ds6_nbr_cache[i].state);
|
||||
PRINTF("%02u: ", i);
|
||||
PRINT6ADDR(&uip_ds6_nbr_cache[i].ipaddr);
|
||||
PRINTF(" - ");
|
||||
PRINTLLADDR(&uip_ds6_nbr_cache[i].lladdr);
|
||||
PRINTF(" - %u\n", uip_ds6_nbr_cache[i].state);
|
||||
|
||||
memcpy(buf + len, &i, sizeof(i));
|
||||
len += sizeof(i);
|
||||
memcpy(buf + len, &uip_ds6_nbr_cache[i].ipaddr, sizeof(uip_ipaddr_t));
|
||||
len += sizeof(uip_ipaddr_t);
|
||||
memcpy(buf + len, &uip_ds6_nbr_cache[i].lladdr, sizeof(uip_lladdr_t));
|
||||
len += sizeof(uip_lladdr_t);
|
||||
memcpy(buf + len, &uip_ds6_nbr_cache[i].state,
|
||||
sizeof(uip_ds6_nbr_cache[i].state));
|
||||
len += sizeof(uip_ds6_nbr_cache[i].state);
|
||||
|
||||
count++;
|
||||
left -= entry_size;
|
||||
|
||||
if(left < entry_size) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(buf[0] == REQUEST_TYPE_RT) {
|
||||
uint32_t flip = 0;
|
||||
PRINTF("Routing table\n");
|
||||
for(i = buf[1]; i < UIP_DS6_ROUTE_NB; i++) {
|
||||
if(uip_ds6_routing_table[i].isused) {
|
||||
entry_size = sizeof(i) + sizeof(uip_ds6_routing_table[i].ipaddr)
|
||||
+ sizeof(uip_ds6_routing_table[i].length)
|
||||
+ sizeof(uip_ds6_routing_table[i].metric)
|
||||
+ sizeof(uip_ds6_routing_table[i].nexthop)
|
||||
+ sizeof(uip_ds6_routing_table[i].state.lifetime)
|
||||
+ sizeof(uip_ds6_routing_table[i].state.learned_from);
|
||||
|
||||
memcpy(buf + len, &i, sizeof(i));
|
||||
len += sizeof(i);
|
||||
memcpy(buf + len, &uip_ds6_routing_table[i].ipaddr,
|
||||
sizeof(uip_ds6_routing_table[i].ipaddr));
|
||||
len += sizeof(uip_ds6_routing_table[i].ipaddr);
|
||||
memcpy(buf + len, &uip_ds6_routing_table[i].length,
|
||||
sizeof(uip_ds6_routing_table[i].length));
|
||||
len += sizeof(uip_ds6_routing_table[i].length);
|
||||
memcpy(buf + len, &uip_ds6_routing_table[i].metric,
|
||||
sizeof(uip_ds6_routing_table[i].metric));
|
||||
len += sizeof(uip_ds6_routing_table[i].metric);
|
||||
memcpy(buf + len, &uip_ds6_routing_table[i].nexthop,
|
||||
sizeof(uip_ds6_routing_table[i].nexthop));
|
||||
len += sizeof(uip_ds6_routing_table[i].nexthop);
|
||||
|
||||
PRINT6ADDR(&uip_ds6_routing_table[i].ipaddr);
|
||||
PRINTF(" - %02x", uip_ds6_routing_table[i].length);
|
||||
PRINTF(" - %02x", uip_ds6_routing_table[i].metric);
|
||||
PRINTF(" - ");
|
||||
PRINT6ADDR(&uip_ds6_routing_table[i].nexthop);
|
||||
|
||||
flip = uip_htonl(uip_ds6_routing_table[i].state.lifetime);
|
||||
memcpy(buf + len, &flip, sizeof(flip));
|
||||
len += sizeof(flip);
|
||||
PRINTF(" - %08lx", uip_ds6_routing_table[i].state.lifetime);
|
||||
|
||||
memcpy(buf + len, &uip_ds6_routing_table[i].state.learned_from,
|
||||
sizeof(uip_ds6_routing_table[i].state.learned_from));
|
||||
len += sizeof(uip_ds6_routing_table[i].state.learned_from);
|
||||
|
||||
PRINTF(" - %02x [%u]\n", uip_ds6_routing_table[i].state.learned_from,
|
||||
entry_size);
|
||||
|
||||
count++;
|
||||
left -= entry_size;
|
||||
|
||||
if(left < entry_size) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (buf[0] == REQUEST_TYPE_DRT) {
|
||||
uint32_t flip = 0;
|
||||
PRINTF("Default Routes\n");
|
||||
for(i = buf[1]; i < UIP_DS6_DEFRT_NB; i++) {
|
||||
if(uip_ds6_defrt_list[i].isused) {
|
||||
entry_size = sizeof(i) + sizeof(uip_ds6_defrt_list[i].ipaddr)
|
||||
+ sizeof(uip_ds6_defrt_list[i].isinfinite);
|
||||
|
||||
memcpy(buf + len, &i, sizeof(i));
|
||||
len += sizeof(i);
|
||||
memcpy(buf + len, &uip_ds6_defrt_list[i].ipaddr,
|
||||
sizeof(uip_ds6_defrt_list[i].ipaddr));
|
||||
len += sizeof(uip_ds6_defrt_list[i].ipaddr);
|
||||
memcpy(buf + len, &uip_ds6_defrt_list[i].isinfinite,
|
||||
sizeof(uip_ds6_defrt_list[i].isinfinite));
|
||||
len += sizeof(uip_ds6_defrt_list[i].isinfinite);
|
||||
|
||||
PRINT6ADDR(&uip_ds6_defrt_list[i].ipaddr);
|
||||
PRINTF(" - %u\n", uip_ds6_defrt_list[i].isinfinite);
|
||||
count++;
|
||||
left -= entry_size;
|
||||
|
||||
if(left < entry_size) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (buf[0] == REQUEST_TYPE_ADDR) {
|
||||
PRINTF("Unicast Addresses\n");
|
||||
for(i = buf[1]; i < UIP_DS6_ADDR_NB; i++) {
|
||||
if(uip_ds6_if.addr_list[i].isused) {
|
||||
entry_size = sizeof(i) + sizeof(uip_ds6_if.addr_list[i].ipaddr);
|
||||
|
||||
memcpy(buf + len, &i, sizeof(i));
|
||||
len += sizeof(i);
|
||||
memcpy(buf + len, &uip_ds6_if.addr_list[i].ipaddr,
|
||||
sizeof(uip_ds6_if.addr_list[i].ipaddr));
|
||||
len += sizeof(uip_ds6_if.addr_list[i].ipaddr);
|
||||
|
||||
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
|
||||
PRINTF("\n");
|
||||
count++;
|
||||
left -= entry_size;
|
||||
|
||||
if(left < entry_size) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (buf[0] == REQUEST_TYPE_TOTALS) {
|
||||
memset(&buf[2], 0, 4);
|
||||
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
||||
if(uip_ds6_if.addr_list[i].isused) {
|
||||
buf[2]++;
|
||||
}
|
||||
}
|
||||
for(i = 0; i < UIP_DS6_NBR_NB; i++) {
|
||||
if(uip_ds6_nbr_cache[i].isused) {
|
||||
buf[3]++;
|
||||
}
|
||||
}
|
||||
for(i = 0; i < UIP_DS6_ROUTE_NB; i++) {
|
||||
if(uip_ds6_routing_table[i].isused) {
|
||||
buf[4]++;
|
||||
}
|
||||
}
|
||||
for(i = 0; i < UIP_DS6_DEFRT_NB; i++) {
|
||||
if(uip_ds6_defrt_list[i].isused) {
|
||||
buf[5]++;
|
||||
}
|
||||
}
|
||||
len += 4;
|
||||
count = 4;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
buf[1] = count;
|
||||
return len;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(viztool_process, "Network Visualization Tool Process");
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
tcpip_handler(void)
|
||||
{
|
||||
if(uip_newdata()) {
|
||||
memset(buf, 0, VIZTOOL_MAX_PAYLOAD_LEN);
|
||||
|
||||
PRINTF("%u bytes from [", uip_datalen());
|
||||
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
||||
PRINTF("]:%u\n", UIP_HTONS(UIP_UDP_BUF->srcport));
|
||||
|
||||
memcpy(buf, uip_appdata, uip_datalen());
|
||||
|
||||
len = process_request();
|
||||
if(len) {
|
||||
server_conn->rport = UIP_UDP_BUF->srcport;
|
||||
uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr);
|
||||
uip_udp_packet_send(server_conn, buf, len);
|
||||
PRINTF("Sent %u bytes\n", len);
|
||||
}
|
||||
|
||||
/* Restore server connection to allow data from any node */
|
||||
uip_create_unspecified(&server_conn->ripaddr);
|
||||
server_conn->rport = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(viztool_process, ev, data)
|
||||
{
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
server_conn = udp_new(NULL, UIP_HTONS(0), NULL);
|
||||
udp_bind(server_conn, UIP_HTONS(VIZTOOL_UDP_PORT));
|
||||
|
||||
while(1) {
|
||||
PROCESS_YIELD();
|
||||
if(ev == tcpip_event) {
|
||||
tcpip_handler();
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
Loading…
Add table
Add a link
Reference in a new issue