Add params.c to Raven and sync with 128rfa1 contiki-conf.h
Contikimac works with mcu sleep on both platforms.
This commit is contained in:
parent
65032c4d35
commit
3612fdff5b
|
@ -74,13 +74,12 @@ unsigned long clock_seconds(void);
|
|||
|
||||
/* Michael Hartman's atmega128rfa1 board has an external 32768Hz crystal connected to TOSC1 and 2 pins similar to the Raven 1284p */
|
||||
/* and theoretically can use TIMER2 with it to keep time. Else TIMER0 is used. */
|
||||
/* The sleep timer in raven-lcd.c also uses the crystal and adds a TIMER2 interrupt routine if not already define by clock.c */
|
||||
/* This has not been tested yet */
|
||||
/* The sleep timer requires the crystal and adds a TIMER2 interrupt routine if not already define by clock.c */
|
||||
#define AVR_CONF_USE32KCRYSTAL 0
|
||||
|
||||
/* Michael Hartman's protobyte board has LED on PORTE1, can be used for pings and radio on indication */
|
||||
/* However it requires disabling UART0. */
|
||||
#define RF230BB_CONF_LEDONPORTE1 1
|
||||
/* Michael Hartman's protobyte board has LED on PORTE1, used for radio on indication */
|
||||
/* However this results in disabling UART0. */
|
||||
#define RF230BB_CONF_LEDONPORTE1 0
|
||||
|
||||
/* COM port to be used for SLIP connection. This is usually UART0, but see above */
|
||||
#if RF230BB_CONF_LEDONPORTE1
|
||||
|
@ -96,47 +95,60 @@ unsigned long clock_seconds(void);
|
|||
/* Starting address for code received via the codeprop facility. Not tested on Raven */
|
||||
//#define EEPROMFS_ADDR_CODEPROP 0x8000
|
||||
|
||||
/* Logging adds 200 bytes to program size. RS232 output slows down webserver. */
|
||||
//#define LOG_CONF_ENABLED 1
|
||||
|
||||
/* RADIOSTATS is used in rf230bb, clock.c and the webserver cgi to report radio usage */
|
||||
/* It has less overhead than ENERGEST */
|
||||
#define RADIOSTATS 1
|
||||
|
||||
/* More extensive stats */
|
||||
/* More extensive stats, via main loop printfs or webserver status pages */
|
||||
#define ENERGEST_CONF_ON 1
|
||||
|
||||
/* Possible watchdog timeouts depend on mcu. Default is WDTO_2S. -1 Disables the watchdog. */
|
||||
/* Available watchdog timeouts depend on mcu. Default is WDTO_2S. -1 Disables the watchdog. */
|
||||
/* AVR Studio simulator tends to reboot due to clocking the WD 8 times too fast */
|
||||
//#define WATCHDOG_CONF_TIMEOUT -1
|
||||
|
||||
/* Debugflow macro, useful for tracing path through mac and radio interrupts */
|
||||
//#define DEBUGFLOWSIZE 128
|
||||
|
||||
/* Network setup. The new NETSTACK interface requires RF230BB (as does ip4) */
|
||||
#if RF230BB
|
||||
#undef PACKETBUF_CONF_HDR_SIZE //Use the packetbuf default for header size
|
||||
#else
|
||||
#define PACKETBUF_CONF_HDR_SIZE 0 //RF230 combined driver/mac handles headers internally
|
||||
#endif /*RF230BB */
|
||||
|
||||
/* Define MAX_*X_POWER to reduce tx power and ignore weak rx packets for testing a miniature multihop network.
|
||||
* Leave undefined for full power and sensitivity.
|
||||
* tx=0 (3dbm, default) to 15 (-17.2dbm)
|
||||
* RF230_CONF_AUTOACK sets the extended mode using the energy-detect register with rx=0 (-91dBm) to 84 (-7dBm)
|
||||
* else the rssi register is used having range 0 (91dBm) to 28 (-10dBm)
|
||||
* For simplicity RF230_MIN_RX_POWER is based on the energy-detect value and divided by 3 when autoack is not set.
|
||||
* On the RF230 a reduced rx power threshold will not prevent autoack if enabled and requested.
|
||||
* These numbers applied to both Raven and Jackdaw give a maximum communication distance of about 15 cm
|
||||
* and a 10 meter range to a full-sensitivity RF230 sniffer.
|
||||
#define RF230_MAX_TX_POWER 15
|
||||
#define RF230_MIN_RX_POWER 30
|
||||
*/
|
||||
/* The rf231 and atmega128rfa1 can use an rssi threshold for triggering rx_busy that saves 0.5ma in rx mode */
|
||||
/* 1 - 15 maps into -90 to -48 dBm; the register is written with RF230_MIN_RX_POWER/6 + 1. Undefine for -100dBm sensitivity */
|
||||
//#define RF230_MIN_RX_POWER 0
|
||||
|
||||
/* Network setup */
|
||||
/* TX routine passes the cca/ack result in the return parameter */
|
||||
#define RDC_CONF_HARDWARE_ACK 1
|
||||
/* TX routine does automatic cca and optional backoff */
|
||||
#define RDC_CONF_HARDWARE_CSMA 1
|
||||
/* Allow MCU sleeping between channel checks */
|
||||
#define RDC_CONF_MCU_SLEEP 1
|
||||
|
||||
#if UIP_CONF_IPV6
|
||||
#define RIMEADDR_CONF_SIZE 8
|
||||
#define UIP_CONF_ICMP6 1
|
||||
#define UIP_CONF_UDP 1
|
||||
#define UIP_CONF_TCP 1
|
||||
//#define UIP_CONF_IPV6_RPL 0
|
||||
#define NETSTACK_CONF_NETWORK sicslowpan_driver
|
||||
#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06
|
||||
#else
|
||||
/* ip4 should build but is largely untested */
|
||||
#define RIMEADDR_CONF_SIZE 2
|
||||
#define NETSTACK_CONF_NETWORK rime_driver
|
||||
#endif /* UIP_CONF_IPV6 */
|
||||
|
||||
/* See uip-ds6.h */
|
||||
#define UIP_CONF_DS6_NBR_NBU 20
|
||||
#define UIP_CONF_DS6_DEFRT_NBU 2
|
||||
#define UIP_CONF_DS6_PREFIX_NBU 3
|
||||
#define UIP_CONF_DS6_ROUTE_NBU 20
|
||||
#define UIP_CONF_DS6_ADDR_NBU 3
|
||||
#define UIP_CONF_DS6_MADDR_NBU 0
|
||||
#define UIP_CONF_DS6_AADDR_NBU 0
|
||||
#endif
|
||||
|
||||
#define UIP_CONF_LL_802154 1
|
||||
#define UIP_CONF_LLH_LEN 0
|
||||
|
@ -149,30 +161,10 @@ unsigned long clock_seconds(void);
|
|||
#define SICSLOWPAN_CONF_ADDR_CONTEXT_1 {addr_contexts[1].prefix[0]=0xbb;addr_contexts[1].prefix[1]=0xbb;}
|
||||
#define SICSLOWPAN_CONF_ADDR_CONTEXT_2 {addr_contexts[2].prefix[0]=0x20;addr_contexts[2].prefix[1]=0x01;addr_contexts[2].prefix[2]=0x49;addr_contexts[2].prefix[3]=0x78,addr_contexts[2].prefix[4]=0x1d;addr_contexts[2].prefix[5]=0xb1;}
|
||||
|
||||
/* 211 bytes per queue buffer */
|
||||
#define QUEUEBUF_CONF_NUM 8
|
||||
|
||||
/* 54 bytes per queue ref buffer */
|
||||
#define QUEUEBUF_CONF_REF_NUM 2
|
||||
|
||||
/* Take the default TCP maximum segment size for efficiency and simpler wireshark captures */
|
||||
/* Use this to prevent 6LowPAN fragmentation (whether or not fragmentation is enabled) */
|
||||
//#define UIP_CONF_TCP_MSS 48
|
||||
|
||||
/* 30 bytes per TCP connection */
|
||||
/* 6LoWPAN does not do well with concurrent TCP streams, as new browser GETs collide with packets coming */
|
||||
/* from previous GETs, causing decreased throughput, retransmissions, and timeouts. Increase to study this. */
|
||||
/* ACKs to other ports become interleaved with computation-intensive GETs, so ACKs are particularly missed. */
|
||||
/* Increasing the number of packet receive buffers in RAM helps to keep ACKs from being lost */
|
||||
|
||||
#define UIP_CONF_MAX_CONNECTIONS 4
|
||||
|
||||
/* 2 bytes per TCP listening port */
|
||||
#define UIP_CONF_MAX_LISTENPORTS 4
|
||||
|
||||
/* 25 bytes per UDP connection */
|
||||
#define UIP_CONF_UDP_CONNS 10
|
||||
|
||||
#define UIP_CONF_IP_FORWARD 0
|
||||
#define UIP_CONF_FWCACHE_SIZE 0
|
||||
|
||||
|
@ -206,23 +198,74 @@ unsigned long clock_seconds(void);
|
|||
/* How long to wait before terminating an idle TCP connection. Smaller to allow faster sleep. Default is 120 seconds */
|
||||
/* If wait is too short the connection can be reset as a result of multiple fragment reassembly timeouts */
|
||||
#define UIP_CONF_WAIT_TIMEOUT 20
|
||||
/* 211 bytes per queue buffer */
|
||||
#define QUEUEBUF_CONF_NUM 8
|
||||
/* 54 bytes per queue ref buffer */
|
||||
#define QUEUEBUF_CONF_REF_NUM 2
|
||||
/* Allocate remaining RAM as desired */
|
||||
/* 30 bytes per TCP connection */
|
||||
/* 6LoWPAN does not do well with concurrent TCP streams, as new browser GETs collide with packets coming */
|
||||
/* from previous GETs, causing decreased throughput, retransmissions, and timeouts. Increase to study this. */
|
||||
/* ACKs to other ports become interleaved with computation-intensive GETs, so ACKs are particularly missed. */
|
||||
/* Increasing the number of packet receive buffers in RAM helps to keep ACKs from being lost */
|
||||
#define UIP_CONF_MAX_CONNECTIONS 4
|
||||
/* 2 bytes per TCP listening port */
|
||||
#define UIP_CONF_MAX_LISTENPORTS 4
|
||||
/* 25 bytes per UDP connection */
|
||||
#define UIP_CONF_UDP_CONNS 10
|
||||
/* See uip-ds6.h */
|
||||
#define UIP_CONF_DS6_NBR_NBU 20
|
||||
#define UIP_CONF_DS6_DEFRT_NBU 2
|
||||
#define UIP_CONF_DS6_PREFIX_NBU 3
|
||||
#define UIP_CONF_DS6_ROUTE_NBU 20
|
||||
#define UIP_CONF_DS6_ADDR_NBU 3
|
||||
#define UIP_CONF_DS6_MADDR_NBU 0
|
||||
#define UIP_CONF_DS6_AADDR_NBU 0
|
||||
|
||||
|
||||
#elif 1 /* Contiki-mac radio cycling */
|
||||
#define NETSTACK_CONF_MAC nullmac_driver
|
||||
//#define NETSTACK_CONF_MAC csma_driver
|
||||
//#define NETSTACK_CONF_MAC nullmac_driver
|
||||
/* csma needed for burst mode at present. Webserver won't work without it */
|
||||
#define NETSTACK_CONF_MAC csma_driver
|
||||
#define NETSTACK_CONF_RDC contikimac_driver
|
||||
/* Default is two CCA separated by 500 usec */
|
||||
#define NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE 8
|
||||
/* Wireshark won't decode with the header, but padded packets will fail ipv6 checksum */
|
||||
#define CONTIKIMAC_CONF_WITH_CONTIKIMAC_HEADER 0
|
||||
/* So without the header this needed for RPL mesh to form */
|
||||
#define CONTIKIMAC_CONF_SHORTEST_PACKET_SIZE 43-18 //multicast RPL DIS length
|
||||
/* Not tested much yet */
|
||||
#define WITH_PHASE_OPTIMIZATION 0
|
||||
#define CONTIKIMAC_CONF_COMPOWER 1
|
||||
#define RIMESTATS_CONF_ON 1
|
||||
#define NETSTACK_CONF_FRAMER framer_802154
|
||||
#define NETSTACK_CONF_RADIO rf230_driver
|
||||
#define CHANNEL_802_15_4 26
|
||||
/* The radio needs to interrupt during an rtimer interrupt */
|
||||
#define RTIMER_CONF_NESTED_INTERRUPTS 1
|
||||
#define RF230_CONF_AUTOACK 1
|
||||
/* A 0 here means non-extended mode; 1 means extended mode with no retry, >1 for retrys */
|
||||
#define RF230_CONF_AUTORETRIES 1
|
||||
/* A 0 here means no cca; 1 means extended mode with cca but no retry, >1 for backoff retrys */
|
||||
#define RF230_CONF_CSMARETRIES 1
|
||||
#define CONTIKIMAC_CONF_RADIO_ALWAYS_ON 0
|
||||
#define SICSLOWPAN_CONF_FRAG 1
|
||||
#define SICSLOWPAN_CONF_MAXAGE 3
|
||||
#define NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE 8
|
||||
/* 211 bytes per queue buffer. Contikimac burst mode needs 15 for a 1280 byte MTU */
|
||||
#define QUEUEBUF_CONF_NUM 15
|
||||
/* 54 bytes per queue ref buffer */
|
||||
#define QUEUEBUF_CONF_REF_NUM 2
|
||||
/* Allocate remaining RAM. Not much left due to queuebuf increase */
|
||||
#define UIP_CONF_MAX_CONNECTIONS 2
|
||||
#define UIP_CONF_MAX_LISTENPORTS 4
|
||||
#define UIP_CONF_UDP_CONNS 5
|
||||
#define UIP_CONF_DS6_NBR_NBU 4
|
||||
#define UIP_CONF_DS6_DEFRT_NBU 2
|
||||
#define UIP_CONF_DS6_PREFIX_NBU 3
|
||||
#define UIP_CONF_DS6_ROUTE_NBU 4
|
||||
#define UIP_CONF_DS6_ADDR_NBU 3
|
||||
#define UIP_CONF_DS6_MADDR_NBU 0
|
||||
#define UIP_CONF_DS6_AADDR_NBU 0
|
||||
|
||||
|
||||
#elif 1 /* cx-mac radio cycling */
|
||||
/* RF230 does clear-channel assessment in extended mode (autoretries>0) */
|
||||
|
@ -241,7 +284,21 @@ unsigned long clock_seconds(void);
|
|||
#define SICSLOWPAN_CONF_MAXAGE 3
|
||||
#define CXMAC_CONF_ANNOUNCEMENTS 0
|
||||
#define NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE 8
|
||||
|
||||
/* 211 bytes per queue buffer. Burst mode will need 15 for a 1280 byte MTU */
|
||||
#define QUEUEBUF_CONF_NUM 15
|
||||
/* 54 bytes per queue ref buffer */
|
||||
#define QUEUEBUF_CONF_REF_NUM 2
|
||||
/* Allocate remaining RAM. Not much left due to queuebuf increase */
|
||||
#define UIP_CONF_MAX_CONNECTIONS 2
|
||||
#define UIP_CONF_MAX_LISTENPORTS 4
|
||||
#define UIP_CONF_UDP_CONNS 5
|
||||
#define UIP_CONF_DS6_NBR_NBU 4
|
||||
#define UIP_CONF_DS6_DEFRT_NBU 2
|
||||
#define UIP_CONF_DS6_PREFIX_NBU 3
|
||||
#define UIP_CONF_DS6_ROUTE_NBU 4
|
||||
#define UIP_CONF_DS6_ADDR_NBU 3
|
||||
#define UIP_CONF_DS6_MADDR_NBU 0
|
||||
#define UIP_CONF_DS6_AADDR_NBU 0
|
||||
//Below gives 10% duty cycle, undef for default 5%
|
||||
//#define CXMAC_CONF_ON_TIME (RTIMER_ARCH_SECOND / 80)
|
||||
//Below gives 50% duty cycle
|
||||
|
@ -251,34 +308,16 @@ unsigned long clock_seconds(void);
|
|||
#error Network configuration not specified!
|
||||
#endif /* Network setup */
|
||||
|
||||
/* Logging adds 200 bytes to program size */
|
||||
#define LOG_CONF_ENABLED 1
|
||||
|
||||
/* ************************************************************************** */
|
||||
//#pragma mark RPL Settings
|
||||
/* ************************************************************************** */
|
||||
#if UIP_CONF_IPV6_RPL
|
||||
|
||||
/* Define MAX_*X_POWER to reduce tx power and ignore weak rx packets for testing a miniature multihop network.
|
||||
* Leave undefined for full power and sensitivity.
|
||||
* tx=0 (3dbm, default) to 15 (-17.2dbm)
|
||||
* RF230_CONF_AUTOACK sets the extended mode using the energy-detect register with rx=0 (-91dBm) to 84 (-7dBm)
|
||||
* else the rssi register is used having range 0 (91dBm) to 28 (-10dBm)
|
||||
* For simplicity RF230_MIN_RX_POWER is based on the energy-detect value and divided by 3 when autoack is not set.
|
||||
* On the RF230 a reduced rx power threshold will not prevent autoack if enabled and requested.
|
||||
* These numbers applied to both Raven and Jackdaw give a maximum communication distance of about 15 cm
|
||||
* and a 10 meter range to a full-sensitivity RF230 sniffer.
|
||||
#define RF230_MAX_TX_POWER 15
|
||||
#define RF230_MIN_RX_POWER 30
|
||||
*/
|
||||
|
||||
#define UIP_CONF_ROUTER 1
|
||||
#define UIP_CONF_ND6_SEND_RA 0
|
||||
#define UIP_CONF_ND6_REACHABLE_TIME 600000
|
||||
#define UIP_CONF_ND6_RETRANS_TIMER 10000
|
||||
|
||||
#undef UIP_CONF_UDP_CONNS
|
||||
#define UIP_CONF_UDP_CONNS 12
|
||||
/* For slow slip connections, to prevent buffer overruns */
|
||||
//#define UIP_CONF_RECEIVE_WINDOW 300
|
||||
#undef UIP_CONF_FWCACHE_SIZE
|
||||
|
@ -297,5 +336,6 @@ unsigned long clock_seconds(void);
|
|||
/* PROJECT_CONF_H might be defined in the project Makefile */
|
||||
#ifdef PROJECT_CONF_H
|
||||
#include PROJECT_CONF_H
|
||||
#endif /* PROJECT_CONF_H */
|
||||
#endif
|
||||
|
||||
#endif /* __CONTIKI_CONF_H__ */
|
||||
|
|
|
@ -2,7 +2,7 @@ CONTIKI_TARGET_DIRS = . apps net loader
|
|||
|
||||
CONTIKI_CORE=contiki-raven-main
|
||||
CONTIKI_TARGET_MAIN = ${CONTIKI_CORE}.o
|
||||
CONTIKI_TARGET_SOURCEFILES += contiki-raven-main.c contiki-raven-default-init-net.c
|
||||
CONTIKI_TARGET_SOURCEFILES += contiki-raven-main.c params.c
|
||||
#The avr cpu makefile will also add these files if COFFEE_FILES is specified.
|
||||
#CONTIKI_TARGET_SOURCEFILES += cfs-coffee.c cfs-coffee-arch.c
|
||||
#Needed for slip
|
||||
|
|
|
@ -102,11 +102,7 @@ unsigned long clock_seconds(void);
|
|||
#define RADIOSTATS 1
|
||||
|
||||
/* More extensive stats */
|
||||
#define ENERGEST_CONF_ON 0
|
||||
|
||||
/* Use settings manager to save configuration in EEPROM */
|
||||
/* Adds ~1700 bytes to progmem */
|
||||
#define CONTIKI_CONF_SETTINGS_MANAGER 1
|
||||
#define ENERGEST_CONF_ON 1
|
||||
|
||||
/* Possible watchdog timeouts depend on mcu. Default is WDTO_2S. -1 Disables the watchdog. */
|
||||
/* AVR Studio simulator tends to reboot due to clocking the WD 8 times too fast */
|
||||
|
@ -115,9 +111,31 @@ unsigned long clock_seconds(void);
|
|||
/* Debugflow macro, useful for tracing path through mac and radio interrupts */
|
||||
//#define DEBUGFLOWSIZE 128
|
||||
|
||||
/* Define MAX_*X_POWER to reduce tx power and ignore weak rx packets for testing a miniature multihop network.
|
||||
* Leave undefined for full power and sensitivity.
|
||||
* tx=0 (3dbm, default) to 15 (-17.2dbm)
|
||||
* RF230_CONF_AUTOACK sets the extended mode using the energy-detect register with rx=0 (-91dBm) to 84 (-7dBm)
|
||||
* else the rssi register is used having range 0 (91dBm) to 28 (-10dBm)
|
||||
* For simplicity RF230_MIN_RX_POWER is based on the energy-detect value and divided by 3 when autoack is not set.
|
||||
* On the RF230 a reduced rx power threshold will not prevent autoack if enabled and requested.
|
||||
* These numbers applied to both Raven and Jackdaw give a maximum communication distance of about 15 cm
|
||||
* and a 10 meter range to a full-sensitivity RF230 sniffer.
|
||||
#define RF230_MAX_TX_POWER 15
|
||||
#define RF230_MIN_RX_POWER 30
|
||||
*/
|
||||
/* The rf231 and atmega128rfa1 can use an rssi threshold for triggering rx_busy that saves 0.5ma in rx mode */
|
||||
/* 1 - 15 maps into -90 to -48 dBm; the register is written with RF230_MIN_RX_POWER/6 + 1. Undefine for -100dBm sensitivity */
|
||||
//#define RF230_MIN_RX_POWER 0
|
||||
|
||||
/* Network setup. The new NETSTACK interface requires RF230BB (as does ip4) */
|
||||
#if RF230BB
|
||||
#undef PACKETBUF_CONF_HDR_SIZE //Use the packetbuf default for header size
|
||||
/* TX routine passes the cca/ack result in the return parameter */
|
||||
#define RDC_CONF_HARDWARE_ACK 1
|
||||
/* TX routine does automatic cca and optional backoff */
|
||||
#define RDC_CONF_HARDWARE_CSMA 1
|
||||
/* Allow MCU sleeping between channel checks */
|
||||
#define RDC_CONF_MCU_SLEEP 1
|
||||
#else
|
||||
#define PACKETBUF_CONF_HDR_SIZE 0 //RF230 combined driver/mac handles headers internally
|
||||
#endif /*RF230BB */
|
||||
|
@ -136,15 +154,6 @@ unsigned long clock_seconds(void);
|
|||
#define NETSTACK_CONF_NETWORK rime_driver
|
||||
#endif /* UIP_CONF_IPV6 */
|
||||
|
||||
/* See uip-ds6.h */
|
||||
#define UIP_CONF_DS6_NBR_NBU 20
|
||||
#define UIP_CONF_DS6_DEFRT_NBU 2
|
||||
#define UIP_CONF_DS6_PREFIX_NBU 3
|
||||
#define UIP_CONF_DS6_ROUTE_NBU 20
|
||||
#define UIP_CONF_DS6_ADDR_NBU 3
|
||||
#define UIP_CONF_DS6_MADDR_NBU 0
|
||||
#define UIP_CONF_DS6_AADDR_NBU 0
|
||||
|
||||
#define UIP_CONF_LL_802154 1
|
||||
#define UIP_CONF_LLH_LEN 0
|
||||
|
||||
|
@ -156,27 +165,10 @@ unsigned long clock_seconds(void);
|
|||
#define SICSLOWPAN_CONF_ADDR_CONTEXT_1 {addr_contexts[1].prefix[0]=0xbb;addr_contexts[1].prefix[1]=0xbb;}
|
||||
#define SICSLOWPAN_CONF_ADDR_CONTEXT_2 {addr_contexts[2].prefix[0]=0x20;addr_contexts[2].prefix[1]=0x01;addr_contexts[2].prefix[2]=0x49;addr_contexts[2].prefix[3]=0x78,addr_contexts[2].prefix[4]=0x1d;addr_contexts[2].prefix[5]=0xb1;}
|
||||
|
||||
/* 211 bytes per queue buffer */
|
||||
#define QUEUEBUF_CONF_NUM 8
|
||||
|
||||
/* 54 bytes per queue ref buffer */
|
||||
#define QUEUEBUF_CONF_REF_NUM 2
|
||||
|
||||
/* Take the default TCP maximum segment size for efficiency and simpler wireshark captures */
|
||||
/* Use this to prevent 6LowPAN fragmentation (whether or not fragmentation is enabled) */
|
||||
//#define UIP_CONF_TCP_MSS 48
|
||||
|
||||
/* 30 bytes per TCP connection */
|
||||
/* 6LoWPAN does not do well with concurrent TCP streams, as new browser GETs collide with packets coming */
|
||||
/* from previous GETs, causing decreased throughput, retransmissions, and timeouts. Increase to study this. */
|
||||
#define UIP_CONF_MAX_CONNECTIONS 1
|
||||
|
||||
/* 2 bytes per TCP listening port */
|
||||
#define UIP_CONF_MAX_LISTENPORTS 1
|
||||
|
||||
/* 25 bytes per UDP connection */
|
||||
#define UIP_CONF_UDP_CONNS 10
|
||||
|
||||
#define UIP_CONF_IP_FORWARD 0
|
||||
#define UIP_CONF_FWCACHE_SIZE 0
|
||||
|
||||
|
@ -188,7 +180,6 @@ unsigned long clock_seconds(void);
|
|||
#define UIP_CONF_TCP_SPLIT 1
|
||||
#define UIP_CONF_DHCP_LIGHT 1
|
||||
|
||||
|
||||
#if 1 /* No radio cycling */
|
||||
|
||||
#define NETSTACK_CONF_MAC nullmac_driver
|
||||
|
@ -214,23 +205,72 @@ unsigned long clock_seconds(void);
|
|||
#define SICSLOWPAN_CONF_MAXAGE 3
|
||||
/* How long to wait before terminating an idle TCP connection. Smaller to allow faster sleep. Default is 120 seconds */
|
||||
#define UIP_CONF_WAIT_TIMEOUT 5
|
||||
/* 211 bytes per queue buffer */
|
||||
#define QUEUEBUF_CONF_NUM 8
|
||||
/* 54 bytes per queue ref buffer */
|
||||
#define QUEUEBUF_CONF_REF_NUM 2
|
||||
/* Allocate remaining RAM as desired */
|
||||
/* 30 bytes per TCP connection */
|
||||
/* 6LoWPAN does not do well with concurrent TCP streams, as new browser GETs collide with packets coming */
|
||||
/* from previous GETs, causing decreased throughput, retransmissions, and timeouts. Increase to study this. */
|
||||
/* ACKs to other ports become interleaved with computation-intensive GETs, so ACKs are particularly missed. */
|
||||
/* Increasing the number of packet receive buffers in RAM helps to keep ACKs from being lost */
|
||||
#define UIP_CONF_MAX_CONNECTIONS 4
|
||||
/* 2 bytes per TCP listening port */
|
||||
#define UIP_CONF_MAX_LISTENPORTS 4
|
||||
/* 25 bytes per UDP connection */
|
||||
#define UIP_CONF_UDP_CONNS 10
|
||||
/* See uip-ds6.h */
|
||||
#define UIP_CONF_DS6_NBR_NBU 20
|
||||
#define UIP_CONF_DS6_DEFRT_NBU 2
|
||||
#define UIP_CONF_DS6_PREFIX_NBU 3
|
||||
#define UIP_CONF_DS6_ROUTE_NBU 20
|
||||
#define UIP_CONF_DS6_ADDR_NBU 3
|
||||
#define UIP_CONF_DS6_MADDR_NBU 0
|
||||
#define UIP_CONF_DS6_AADDR_NBU 0
|
||||
|
||||
#elif 1 /* Contiki-mac radio cycling */
|
||||
#define NETSTACK_CONF_MAC nullmac_driver
|
||||
//#define NETSTACK_CONF_MAC csma_driver
|
||||
//#define NETSTACK_CONF_MAC nullmac_driver
|
||||
/* csma needed for burst mode at present. Webserver won't work without it */
|
||||
#define NETSTACK_CONF_MAC csma_driver
|
||||
#define NETSTACK_CONF_RDC contikimac_driver
|
||||
/* Default is two CCA separated by 500 usec */
|
||||
#define NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE 8
|
||||
/* Wireshark won't decode with the header, but padded packets will fail ipv6 checksum */
|
||||
#define CONTIKIMAC_CONF_WITH_CONTIKIMAC_HEADER 0
|
||||
/* So without the header this needed for RPL mesh to form */
|
||||
#define CONTIKIMAC_CONF_SHORTEST_PACKET_SIZE 43-18 //multicast RPL DIS length
|
||||
/* Not tested much yet */
|
||||
#define WITH_PHASE_OPTIMIZATION 0
|
||||
#define CONTIKIMAC_CONF_COMPOWER 1
|
||||
#define RIMESTATS_CONF_ON 1
|
||||
#define NETSTACK_CONF_FRAMER framer_802154
|
||||
#define NETSTACK_CONF_RADIO rf230_driver
|
||||
#define CHANNEL_802_15_4 26
|
||||
/* The radio needs to interrupt during an rtimer interrupt */
|
||||
#define RTIMER_CONF_NESTED_INTERRUPTS 1
|
||||
#define RF230_CONF_AUTOACK 1
|
||||
/* A 0 here means non-extended mode; 1 means extended mode with no retry, >1 for retrys */
|
||||
#define RF230_CONF_AUTORETRIES 1
|
||||
/* A 0 here means no cca; 1 means extended mode with cca but no retry, >1 for backoff retrys */
|
||||
#define RF230_CONF_CSMARETRIES 1
|
||||
#define CONTIKIMAC_CONF_RADIO_ALWAYS_ON 0
|
||||
#define SICSLOWPAN_CONF_FRAG 1
|
||||
#define SICSLOWPAN_CONF_MAXAGE 3
|
||||
#define NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE 8
|
||||
/* 211 bytes per queue buffer. Contikimac burst mode needs 15 for a 1280 byte MTU */
|
||||
#define QUEUEBUF_CONF_NUM 15
|
||||
/* 54 bytes per queue ref buffer */
|
||||
#define QUEUEBUF_CONF_REF_NUM 2
|
||||
/* Allocate remaining RAM. Not much left due to queuebuf increase */
|
||||
#define UIP_CONF_MAX_CONNECTIONS 2
|
||||
#define UIP_CONF_MAX_LISTENPORTS 4
|
||||
#define UIP_CONF_UDP_CONNS 5
|
||||
#define UIP_CONF_DS6_NBR_NBU 4
|
||||
#define UIP_CONF_DS6_DEFRT_NBU 2
|
||||
#define UIP_CONF_DS6_PREFIX_NBU 3
|
||||
#define UIP_CONF_DS6_ROUTE_NBU 4
|
||||
#define UIP_CONF_DS6_ADDR_NBU 3
|
||||
#define UIP_CONF_DS6_MADDR_NBU 0
|
||||
#define UIP_CONF_DS6_AADDR_NBU 0
|
||||
|
||||
#elif 1 /* cx-mac radio cycling */
|
||||
/* RF230 does clear-channel assessment in extended mode (autoretries>0) */
|
||||
|
@ -249,12 +289,27 @@ unsigned long clock_seconds(void);
|
|||
#define SICSLOWPAN_CONF_MAXAGE 3
|
||||
#define CXMAC_CONF_ANNOUNCEMENTS 0
|
||||
#define NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE 8
|
||||
|
||||
/* 211 bytes per queue buffer. Burst mode will need 15 for a 1280 byte MTU */
|
||||
#define QUEUEBUF_CONF_NUM 15
|
||||
/* 54 bytes per queue ref buffer */
|
||||
#define QUEUEBUF_CONF_REF_NUM 2
|
||||
/* Allocate remaining RAM. Not much left due to queuebuf increase */
|
||||
#define UIP_CONF_MAX_CONNECTIONS 2
|
||||
#define UIP_CONF_MAX_LISTENPORTS 4
|
||||
#define UIP_CONF_UDP_CONNS 5
|
||||
#define UIP_CONF_DS6_NBR_NBU 4
|
||||
#define UIP_CONF_DS6_DEFRT_NBU 2
|
||||
#define UIP_CONF_DS6_PREFIX_NBU 3
|
||||
#define UIP_CONF_DS6_ROUTE_NBU 4
|
||||
#define UIP_CONF_DS6_ADDR_NBU 3
|
||||
#define UIP_CONF_DS6_MADDR_NBU 0
|
||||
#define UIP_CONF_DS6_AADDR_NBU 0
|
||||
//Below gives 10% duty cycle, undef for default 5%
|
||||
//#define CXMAC_CONF_ON_TIME (RTIMER_ARCH_SECOND / 80)
|
||||
//Below gives 50% duty cycle
|
||||
//#define CXMAC_CONF_ON_TIME (RTIMER_ARCH_SECOND / 16)
|
||||
|
||||
|
||||
#else
|
||||
#error Network configuration not specified!
|
||||
#endif /* Network setup */
|
||||
|
@ -267,26 +322,12 @@ unsigned long clock_seconds(void);
|
|||
/* ************************************************************************** */
|
||||
#if UIP_CONF_IPV6_RPL
|
||||
|
||||
/* Define MAX_*X_POWER to reduce tx power and ignore weak rx packets for testing a miniature multihop network.
|
||||
* Leave undefined for full power and sensitivity.
|
||||
* tx=0 (3dbm, default) to 15 (-17.2dbm)
|
||||
* RF230_CONF_AUTOACK sets the extended mode using the energy-detect register with rx=0 (-91dBm) to 84 (-7dBm)
|
||||
* else the rssi register is used having range 0 (91dBm) to 28 (-10dBm)
|
||||
* For simplicity RF230_MIN_RX_POWER is based on the energy-detect value and divided by 3 when autoack is not set.
|
||||
* On the RF230 a reduced rx power threshold will not prevent autoack if enabled and requested.
|
||||
* These numbers applied to both Raven and Jackdaw give a maximum communication distance of about 15 cm
|
||||
* and a 10 meter range to a full-sensitivity RF230 sniffer.
|
||||
#define RF230_MAX_TX_POWER 15
|
||||
#define RF230_MIN_RX_POWER 30
|
||||
*/
|
||||
|
||||
#define UIP_CONF_ROUTER 1
|
||||
#define UIP_CONF_ND6_SEND_RA 0
|
||||
#define UIP_CONF_ND6_REACHABLE_TIME 600000
|
||||
#define UIP_CONF_ND6_RETRANS_TIMER 10000
|
||||
|
||||
#undef UIP_CONF_UDP_CONNS
|
||||
#define UIP_CONF_UDP_CONNS 12
|
||||
/* For slow slip connections, to prevent buffer overruns */
|
||||
//#define UIP_CONF_RECEIVE_WINDOW 300
|
||||
#undef UIP_CONF_FWCACHE_SIZE
|
||||
#define UIP_CONF_FWCACHE_SIZE 30
|
||||
#define UIP_CONF_BROADCAST 1
|
||||
|
|
|
@ -47,8 +47,9 @@
|
|||
#endif
|
||||
|
||||
/* Track interrupt flow through mac, rdc and radio driver */
|
||||
//#define DEBUGFLOWSIZE 64
|
||||
#if DEBUGFLOWSIZE
|
||||
uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE];
|
||||
unsigned char debugflowsize,debugflow[DEBUGFLOWSIZE];
|
||||
#define DEBUGFLOW(c) if (debugflowsize<(DEBUGFLOWSIZE-1)) debugflow[debugflowsize++]=c
|
||||
#else
|
||||
#define DEBUGFLOW(c)
|
||||
|
@ -64,6 +65,7 @@ uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE];
|
|||
#include "loader/symbols-def.h"
|
||||
#include "loader/symtab.h"
|
||||
|
||||
#include "params.h"
|
||||
#if RF230BB //radio driver using contiki core mac
|
||||
#include "radio/rf230bb/rf230bb.h"
|
||||
#include "net/mac/frame802154.h"
|
||||
|
@ -125,10 +127,6 @@ void rtimercycle(void) {rtimerflag=1;}
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#if WITH_NODE_ID
|
||||
uint16_t node_id;
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
/*----------------------Configuration of the .elf file---------------------*/
|
||||
#if 1
|
||||
|
@ -148,62 +146,12 @@ SIGNATURE = {
|
|||
/* JTAG, SPI enabled, Internal RC osc, Boot flash size 4K, 6CK+65msec delay, brownout disabled */
|
||||
FUSES ={.low = 0xe2, .high = 0x99, .extended = 0xff,};
|
||||
|
||||
/* Put the default settings into program flash memory */
|
||||
/* Webserver builds can set some defaults in httpd-fsdata.c via makefsdata.h */
|
||||
#if AVR_WEBSERVER
|
||||
extern uint8_t default_mac_address[8];
|
||||
extern uint8_t default_server_name[16];
|
||||
extern uint8_t default_domain_name[30];
|
||||
#else
|
||||
#ifdef MAC_ADDRESS
|
||||
uint8_t default_mac_address[8] PROGMEM = MAC_ADDRESS;
|
||||
#else
|
||||
uint8_t default_mac_address[8] PROGMEM = {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55};
|
||||
#endif
|
||||
#ifdef SERVER_NAME
|
||||
uint8_t default_server_name[16] PROGMEM = SERVER_NAME;
|
||||
#else
|
||||
uint8_t default_server_name[16] PROGMEM = "Raven_webserver";
|
||||
#endif
|
||||
#ifdef DOMAIN_NAME
|
||||
uint8_t default_domain_name[30] PROGMEM = DOMAIN_NAME
|
||||
#else
|
||||
uint8_t default_domain_name[30] PROGMEM = "localhost";
|
||||
#endif
|
||||
#endif /* AVR_WEBSERVER */
|
||||
|
||||
#ifdef NODE_ID
|
||||
uint16_t default_nodeid PROGMEM = NODEID;
|
||||
#else
|
||||
uint16_t default_nodeid PROGMEM = 0;
|
||||
#endif
|
||||
#ifdef CHANNEL_802_15_4
|
||||
uint8_t default_channel PROGMEM = CHANNEL_802_15_4;
|
||||
#else
|
||||
uint8_t default_channel PROGMEM = 26;
|
||||
#endif
|
||||
#ifdef IEEE802154_PANID
|
||||
uint16_t default_panid PROGMEM = IEEE802154_PANID;
|
||||
#else
|
||||
uint16_t default_panid PROGMEM = 0xABCD;
|
||||
#endif
|
||||
#ifdef IEEE802154_PANADDR
|
||||
uint16_t default_panaddr PROGMEM = IEEE802154_PANID;
|
||||
#else
|
||||
uint16_t default_panaddr PROGMEM = 0;
|
||||
#endif
|
||||
#ifdef RF230_MAX_TX_POWER
|
||||
uint8_t default_txpower PROGMEM = RF230_MAX_TX_POWER;
|
||||
#else
|
||||
uint8_t default_txpower PROGMEM = 0;
|
||||
#endif
|
||||
|
||||
/* Get a pseudo random number using the ADC */
|
||||
static uint8_t
|
||||
uint8_t
|
||||
rng_get_uint8(void) {
|
||||
uint8_t i,j;
|
||||
ADCSRA=1<<ADEN; //Enable ADC, not free running, interrupt disabled, fastest clock
|
||||
for (i=0;i<4;i++) {
|
||||
for (i=0,j=0;i<4;i++) {
|
||||
ADMUX = 0; //toggle reference to increase noise
|
||||
ADMUX =0x1E; //Select AREF as reference, measure 1.1 volt bandgap reference.
|
||||
ADCSRA|=1<<ADSC; //Start conversion
|
||||
|
@ -215,231 +163,23 @@ uint8_t i,j;
|
|||
return j;
|
||||
}
|
||||
|
||||
#if CONTIKI_CONF_RANDOM_MAC
|
||||
static void
|
||||
generate_new_eui64(uint8_t eui64[8]) {
|
||||
eui64[0] = 0x02;
|
||||
eui64[1] = rng_get_uint8();
|
||||
eui64[2] = rng_get_uint8();
|
||||
eui64[3] = 0xFF;
|
||||
eui64[4] = 0xFE;
|
||||
eui64[5] = rng_get_uint8();
|
||||
eui64[6] = rng_get_uint8();
|
||||
eui64[7] = rng_get_uint8();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONTIKI_CONF_SETTINGS_MANAGER
|
||||
/****************************No settings manager*****************************/
|
||||
/* If not using the settings manager, put the default values into EEMEM
|
||||
* These can be manually changed and kept over program reflash.
|
||||
* The channel and bit complement are used to check EEMEM integrity,
|
||||
* If corrupt all values will be rewritten with the default flash values.
|
||||
* To make this work, get the channel before anything else.
|
||||
*/
|
||||
#if AVR_WEBSERVER
|
||||
extern uint8_t eemem_mac_address[8]; //These are defined in httpd-fsdata.c via makefsdata.h
|
||||
extern uint8_t eemem_server_name[16];
|
||||
extern uint8_t eemem_domain_name[30];
|
||||
#else
|
||||
#ifdef MAC_ADDRESS
|
||||
uint8_t eemem_mac_address[8] EEMEM = MAC_ADDRESS;
|
||||
#else
|
||||
uint8_t eemem_mac_address[8] EEMEM = {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55};
|
||||
#endif
|
||||
#ifdef SERVER_NAME
|
||||
uint8_t eemem_server_name[16] EEMEM = SERVER_NAME;
|
||||
#else
|
||||
uint8_t eemem_server_name[16] EEMEM = "Raven_webserver";
|
||||
#endif
|
||||
#ifdef DOMAIN_NAME
|
||||
uint8_t eemem_domain_name[30] EEMEM = DOMAIN_NAME
|
||||
#else
|
||||
uint8_t eemem_domain_name[30] EEMEM = "localhost";
|
||||
#endif
|
||||
#endif /*AVR_WEBSERVER */
|
||||
|
||||
#ifdef NODE_ID
|
||||
uint16_t eemem_nodeid EEMEM = NODEID;
|
||||
#else
|
||||
uint16_t eemem_nodeid EEMEM = 0;
|
||||
#endif
|
||||
#ifdef CHANNEL_802_15_4
|
||||
uint8_t eemem_channel[2] EEMEM = {CHANNEL_802_15_4, ~CHANNEL_802_15_4};
|
||||
#else
|
||||
uint8_t eemem_channel[2] EMEM = {26, ~26};
|
||||
#endif
|
||||
#ifdef IEEE802154_PANID
|
||||
uint16_t eemem_panid EEMEM = IEEE802154_PANID;
|
||||
#else
|
||||
uint16_t eemem_panid EEMEM = 0xABCD;
|
||||
#endif
|
||||
#ifdef IEEE802154_PANADDR
|
||||
uint16_t eemem_panaddr EEMEM = IEEE802154_PANADDR;
|
||||
#else
|
||||
uint16_t eemem_panaddr EEMEM = 0;
|
||||
#endif
|
||||
#ifdef RF230_MAX_TX_POWER
|
||||
uint8_t eemem_txpower EEMEM = RF230_MAX_TX_POWER;
|
||||
#else
|
||||
uint8_t eemem_txpower EEMEM = 0;
|
||||
#endif
|
||||
|
||||
static uint8_t
|
||||
get_channel_from_eeprom() {
|
||||
uint8_t x[2];
|
||||
*(uint16_t *)x = eeprom_read_word ((uint16_t *)&eemem_channel);
|
||||
/* Don't return an invalid channel number */
|
||||
if( (x[0]<11) || (x[0] > 26)) x[1]=x[0];
|
||||
/* Do exclusive or test on the two values read */
|
||||
if((uint8_t)x[0]!=(uint8_t)~x[1]) {//~x[1] can promote comparison to 16 bit
|
||||
/* Verification fails, rewrite everything */
|
||||
uint8_t i,buffer[32];
|
||||
PRINTD("EEPROM is corrupt, rewriting with defaults.\n");
|
||||
#if CONTIKI_CONF_RANDOM_MAC
|
||||
PRINTA("Generating random MAC address.\n");
|
||||
generate_new_eui64(&buffer);
|
||||
#else
|
||||
for (i=0;i<sizeof(default_mac_address);i++) buffer[i] = pgm_read_byte_near(default_mac_address+i);
|
||||
#endif
|
||||
cli();
|
||||
eeprom_write_block(&buffer, &eemem_mac_address, sizeof(eemem_mac_address));
|
||||
for (i=0;i<sizeof(default_server_name);i++) buffer[i] = pgm_read_byte_near(default_server_name+i);
|
||||
eeprom_write_block(&buffer, &eemem_server_name, sizeof(eemem_server_name));
|
||||
for (i=0;i<sizeof(default_domain_name);i++) buffer[i] = pgm_read_byte_near(default_domain_name+i);
|
||||
eeprom_write_block(&buffer, &eemem_domain_name, sizeof(eemem_domain_name));
|
||||
eeprom_write_word(&eemem_panid , pgm_read_word_near(&default_panid));
|
||||
eeprom_write_word(&eemem_panaddr, pgm_read_word_near(&default_panaddr));
|
||||
eeprom_write_byte(&eemem_txpower, pgm_read_byte_near(&default_txpower));
|
||||
eeprom_write_word(&eemem_nodeid, pgm_read_word_near(&default_nodeid));
|
||||
x[0] = pgm_read_byte_near(&default_channel);
|
||||
x[1]= ~x[0];
|
||||
eeprom_write_word((uint16_t *)&eemem_channel, *(uint16_t *)x);
|
||||
sei();
|
||||
}
|
||||
/* Always returns a valid channel */
|
||||
return x[0];
|
||||
}
|
||||
static bool
|
||||
get_eui64_from_eeprom(uint8_t macptr[sizeof(rimeaddr_t)]) {
|
||||
cli();
|
||||
eeprom_read_block ((void *)macptr, &eemem_mac_address, sizeof(rimeaddr_t));
|
||||
sei();
|
||||
return macptr[0]!=0xFF;
|
||||
}
|
||||
static uint16_t
|
||||
get_panid_from_eeprom(void) {
|
||||
return eeprom_read_word(&eemem_panid);
|
||||
}
|
||||
static uint16_t
|
||||
get_panaddr_from_eeprom(void) {
|
||||
return eeprom_read_word (&eemem_panaddr);
|
||||
}
|
||||
static uint8_t
|
||||
get_txpower_from_eeprom(void)
|
||||
{
|
||||
return eeprom_read_byte(&eemem_txpower);
|
||||
}
|
||||
|
||||
#else /* !CONTIKI_CONF_SETTINGS_MANAGER */
|
||||
/******************************Settings manager******************************/
|
||||
#include "settings.h"
|
||||
/* Disable the settings add routines to reduce eeprom wear during testing */
|
||||
#if 0
|
||||
#define settings_add(...) 0
|
||||
#define settings_add_uint8(...) 0
|
||||
#define settings_add_uint16(...) 0
|
||||
#endif
|
||||
|
||||
#if AVR_WEBSERVER
|
||||
extern uint8_t eemem_mac_address[8]; //These are defined in httpd-fsdata.c via makefsdata.h
|
||||
extern uint8_t eemem_server_name[16];
|
||||
extern uint8_t eemem_domain_name[30];
|
||||
#endif
|
||||
|
||||
static uint8_t
|
||||
get_channel_from_eeprom() {
|
||||
uint8_t x;
|
||||
size_t size = 1;
|
||||
if (settings_get(SETTINGS_KEY_CHANNEL, 0,(unsigned char*)&x, &size) == SETTINGS_STATUS_OK) {
|
||||
if ((x<11) || (x>26)) {
|
||||
PRINTF("Unusual RF channel %u in EEPROM\n",x);
|
||||
}
|
||||
PRINTD("<=Get RF channel %u.\n",x);
|
||||
} else {
|
||||
x = pgm_read_byte_near(&default_channel);
|
||||
if (settings_add_uint8(SETTINGS_KEY_CHANNEL,x ) == SETTINGS_STATUS_OK) {
|
||||
PRINTD("->Set EEPROM RF channel to %d.\n",x);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
static bool
|
||||
get_eui64_from_eeprom(uint8_t macptr[8]) {
|
||||
size_t size = sizeof(rimeaddr_t);
|
||||
if(settings_get(SETTINGS_KEY_EUI64, 0, (unsigned char*)macptr, &size) == SETTINGS_STATUS_OK) {
|
||||
PRINTD("<=Get MAC address.\n");
|
||||
return true;
|
||||
}
|
||||
#if CONTIKI_CONF_RANDOM_MAC
|
||||
PRINTD("--Generating random MAC address.\n");
|
||||
generate_new_eui64(macptr);
|
||||
#else
|
||||
{uint8_t i;for (i=0;i<8;i++) macptr[i] = pgm_read_byte_near(default_mac_address+i);}
|
||||
#endif
|
||||
if (settings_add(SETTINGS_KEY_EUI64,(unsigned char*)macptr,8)) {
|
||||
PRINTD("->Set EEPROM MAC address.\n");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static uint16_t
|
||||
get_panid_from_eeprom(void) {
|
||||
uint16_t x;
|
||||
size_t size = 2;
|
||||
if (settings_get(SETTINGS_KEY_PAN_ID, 0,(unsigned char*)&x, &size) == SETTINGS_STATUS_OK) {
|
||||
PRINTD("<-Get PAN ID of %04x.\n",x);
|
||||
} else {
|
||||
x=pgm_read_word_near(&default_panid);
|
||||
if (settings_add_uint16(SETTINGS_KEY_PAN_ID,x)==SETTINGS_STATUS_OK) {
|
||||
PRINTD("->Set EEPROM PAN ID to %04x.\n",x);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
static uint16_t
|
||||
get_panaddr_from_eeprom(void) {
|
||||
uint16_t x;
|
||||
size_t size = 2;
|
||||
if (settings_get(SETTINGS_KEY_PAN_ADDR, 0,(unsigned char*)&x, &size) == SETTINGS_STATUS_OK) {
|
||||
PRINTD("<-Get PAN address of %04x.\n",x);
|
||||
} else {
|
||||
x=pgm_read_word_near(&default_panaddr);
|
||||
if (settings_add_uint16(SETTINGS_KEY_PAN_ADDR,x)==SETTINGS_STATUS_OK) {
|
||||
PRINTD("->Set EEPROM PAN address to %04x.\n",x);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
static uint8_t
|
||||
get_txpower_from_eeprom(void) {
|
||||
uint8_t x;
|
||||
size_t size = 1;
|
||||
if (settings_get(SETTINGS_KEY_TXPOWER, 0,(unsigned char*)&x, &size) == SETTINGS_STATUS_OK) {
|
||||
PRINTD("<-Get tx power of %d. (0=max)\n",x);
|
||||
} else {
|
||||
x=pgm_read_byte_near(&default_txpower);
|
||||
if (settings_add_uint8(SETTINGS_KEY_TXPOWER,x)==SETTINGS_STATUS_OK) {
|
||||
PRINTD("->Set EEPROM tx power of %d. (0=max)\n",x);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
#endif /* CONTIKI_CONF_SETTINGS_MANAGER */
|
||||
|
||||
/*-------------------------Low level initialization------------------------*/
|
||||
/*------Done in a subroutine to keep main routine stack usage small--------*/
|
||||
void initialize(void)
|
||||
{
|
||||
/* A jtag or brownout reset of the mcu tristates the RF230 control pins while
|
||||
* it is in operation, which can result in a mulfunctioning condition when the
|
||||
* radio is later re-initialized.
|
||||
* This manifests as an incorrectly computed hardware FCS checksum.
|
||||
* Setting up the pins as soon as possible after mcu reset seems to fix this.
|
||||
* Additionally, hold the radio in reset to prevent premature rx interrupts.
|
||||
*/
|
||||
#if RF230BB
|
||||
#include "radio/rf230bb/hal.h"
|
||||
hal_init();
|
||||
hal_set_rst_low();
|
||||
#endif
|
||||
|
||||
watchdog_init();
|
||||
watchdog_start();
|
||||
|
||||
|
@ -448,14 +188,25 @@ void initialize(void)
|
|||
rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
||||
/* Set input handler for 3290 port */
|
||||
rs232_set_input(0,raven_lcd_serial_input);
|
||||
#else
|
||||
/* Generic or slip connection on uart0 */
|
||||
rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
||||
#endif
|
||||
|
||||
/* Second rs232 port for debugging */
|
||||
/* Second rs232 port for debugging or slip alternative */
|
||||
rs232_init(RS232_PORT_1, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
||||
/* Redirect stdout to second port */
|
||||
rs232_redirect_stdout(RS232_PORT_1);
|
||||
clock_init();
|
||||
|
||||
PRINTD("\n\nChecking MCUSR...\n");
|
||||
if(MCUSR & (1<<PORF )) PRINTD("Power-on reset.\n");
|
||||
if(MCUSR & (1<<EXTRF)) PRINTD("External reset!\n");
|
||||
if(MCUSR & (1<<BORF )) PRINTD("Brownout reset!\n");
|
||||
if(MCUSR & (1<<WDRF )) PRINTD("Watchdog reset!\n");
|
||||
if(MCUSR & (1<<JTRF )) PRINTD("JTAG reset!\n");
|
||||
MCUSR = 0;
|
||||
|
||||
#if STACKMONITOR
|
||||
/* Simple stack pointer highwater monitor. Checks for magic numbers in the main
|
||||
* loop. In conjuction with PERIODICPRINTS, never-used stack will be printed
|
||||
|
@ -471,12 +222,7 @@ uint16_t p=(uint16_t)&__bss_end;
|
|||
}
|
||||
#endif
|
||||
|
||||
/* Get a random (or probably different) seed for the 802.15.4 packet sequence number.
|
||||
* Some layers will ignore duplicates found in a history (e.g. Contikimac)
|
||||
* causing the initial packets to be ignored after a short-cycle restart.
|
||||
*/
|
||||
random_init(rng_get_uint8());
|
||||
|
||||
/* Calibrate internal mcu clock against external 32768Hz watch crystal */
|
||||
#define CONF_CALIBRATE_OSCCAL 0
|
||||
#if CONF_CALIBRATE_OSCCAL
|
||||
void calibrate_rc_osc_32k();
|
||||
|
@ -512,20 +258,23 @@ uint8_t i;
|
|||
/* Start radio and radio receive process */
|
||||
NETSTACK_RADIO.init();
|
||||
|
||||
/* Get a random seed for the 802.15.4 packet sequence number.
|
||||
* Some layers will ignore duplicates found in a history (e.g. Contikimac)
|
||||
* causing the initial packets to be ignored after a short-cycle restart.
|
||||
*/
|
||||
random_init(rng_get_uint8());
|
||||
|
||||
/* Set addresses BEFORE starting tcpip process */
|
||||
|
||||
rimeaddr_t addr;
|
||||
// memset(&addr, 0, sizeof(rimeaddr_t));
|
||||
get_eui64_from_eeprom(addr.u8);
|
||||
if (params_get_eui64(addr.u8)) {
|
||||
PRINTA("Random EUI64 address generated\n");
|
||||
}
|
||||
|
||||
#if UIP_CONF_IPV6
|
||||
memcpy(&uip_lladdr.addr, &addr.u8, sizeof(rimeaddr_t));
|
||||
rimeaddr_set_node_addr(&addr);
|
||||
rf230_set_pan_addr(
|
||||
get_panid_from_eeprom(),
|
||||
get_panaddr_from_eeprom(),
|
||||
(uint8_t *)&addr.u8
|
||||
);
|
||||
rf230_set_pan_addr(params_get_panid(),params_get_panaddr(),(uint8_t *)&addr.u8);
|
||||
#elif WITH_NODE_ID
|
||||
node_id=get_panaddr_from_eeprom();
|
||||
addr.u8[1]=node_id&0xff;
|
||||
|
@ -533,24 +282,16 @@ uint8_t i;
|
|||
PRINTA("Node ID from eeprom: %X\n",node_id);
|
||||
uint16_t inv_node_id=((node_id&0xff00)>>8)+((node_id&0xff)<<8); // change order of bytes for rf23x
|
||||
rimeaddr_set_node_addr(&addr);
|
||||
rf230_set_pan_addr(
|
||||
get_panid_from_eeprom(),
|
||||
inv_node_id,
|
||||
NULL
|
||||
);
|
||||
rf230_set_pan_addr(params_get_panid(),inv_node_id,NULL);
|
||||
#else
|
||||
rimeaddr_set_node_addr(&addr);
|
||||
rf230_set_pan_addr(
|
||||
get_panid_from_eeprom(),
|
||||
get_panaddr_from_eeprom(),
|
||||
(uint8_t *)&addr.u8
|
||||
);
|
||||
rf230_set_pan_addr(params_get_panid(),params_get_panaddr(),(uint8_t *)&addr.u8);
|
||||
#endif
|
||||
rf230_set_channel(get_channel_from_eeprom());
|
||||
rf230_set_txpower(get_txpower_from_eeprom());
|
||||
rf230_set_channel(params_get_channel());
|
||||
rf230_set_txpower(params_get_txpower());
|
||||
|
||||
#if UIP_CONF_IPV6
|
||||
PRINTA("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);
|
||||
PRINTA("EUI-64 MAC: %x-%x-%x-%x-%x-%x-%x-%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);
|
||||
#else
|
||||
PRINTA("MAC address ");
|
||||
uint8_t i;
|
||||
|
@ -567,22 +308,15 @@ uint8_t i;
|
|||
NETSTACK_NETWORK.init();
|
||||
|
||||
#if ANNOUNCE_BOOT
|
||||
PRINTA("%s %s, channel %u power %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel()),rf230_get_txpower();
|
||||
if (NETSTACK_RDC.channel_check_interval) {//function pointer is zero for sicslowmac
|
||||
unsigned short tmp;
|
||||
tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\
|
||||
NETSTACK_RDC.channel_check_interval());
|
||||
if (tmp<65535) PRINTA(", check rate %u Hz",tmp);
|
||||
}
|
||||
PRINTA("\n");
|
||||
|
||||
PRINTA("%s %s, channel %u , check rate %u Hz tx power %u\n",NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel(),
|
||||
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:NETSTACK_RDC.channel_check_interval()),
|
||||
rf230_get_txpower());
|
||||
#if UIP_CONF_IPV6_RPL
|
||||
PRINTA("RPL Enabled\n");
|
||||
#endif
|
||||
#if UIP_CONF_ROUTER
|
||||
PRINTA("Routing Enabled\n");
|
||||
#endif
|
||||
|
||||
#endif /* ANNOUNCE_BOOT */
|
||||
|
||||
// rime_init(rime_udp_init(NULL));
|
||||
|
@ -604,9 +338,6 @@ uint8_t i;
|
|||
/* Autostart other processes */
|
||||
autostart_start(autostart_processes);
|
||||
|
||||
//Give ourselves a prefix
|
||||
// init_net();
|
||||
|
||||
/*---If using coffee file system create initial web content if necessary---*/
|
||||
#if COFFEE_FILES
|
||||
int fa = cfs_open( "/index.html", CFS_READ);
|
||||
|
@ -650,12 +381,10 @@ uint8_t i;
|
|||
}
|
||||
cli();
|
||||
eeprom_read_block (buf,eemem_server_name, sizeof(eemem_server_name));
|
||||
eeprom_read_block (buf,eemem_domain_name, sizeof(eemem_domain_name));
|
||||
sei();
|
||||
buf[sizeof(eemem_server_name)]=0;
|
||||
PRINTA("%s",buf);
|
||||
cli();
|
||||
eeprom_read_block (buf,eemem_domain_name, sizeof(eemem_domain_name));
|
||||
sei();
|
||||
buf[sizeof(eemem_domain_name)]=0;
|
||||
size=httpd_fs_get_size();
|
||||
#ifndef COFFEE_FILES
|
||||
|
@ -735,6 +464,7 @@ main(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
/* Set DEBUGFLOWSIZE in contiki-conf.h to track path through MAC, RDC, and RADIO */
|
||||
#if DEBUGFLOWSIZE
|
||||
if (debugflowsize) {
|
||||
debugflow[debugflowsize]=0;
|
||||
|
@ -743,8 +473,6 @@ main(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
watchdog_periodic();
|
||||
|
||||
#if PERIODICPRINTS
|
||||
#if TESTRTIMER
|
||||
/* Timeout can be increased up to 8 seconds maximum.
|
||||
|
@ -763,7 +491,7 @@ main(void)
|
|||
if ((clocktime%STAMPS)==0) {
|
||||
#if ENERGEST_CONF_ON
|
||||
#include "lib/print-stats.h"
|
||||
print_stats();
|
||||
// print_stats();
|
||||
#elif RADIOSTATS
|
||||
extern volatile unsigned long radioontime;
|
||||
PRINTF("%u(%u)s\n",clocktime,radioontime);
|
||||
|
|
264
platform/avr-raven/params.c
Normal file
264
platform/avr-raven/params.c
Normal file
|
@ -0,0 +1,264 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 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.
|
||||
*
|
||||
*/
|
||||
#define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
|
||||
|
||||
#define DEBUG 1
|
||||
#if DEBUG
|
||||
#define PRINTD(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
|
||||
#else
|
||||
#define PRINTD(...)
|
||||
#endif
|
||||
|
||||
#include "contiki.h"
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/eeprom.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if AVR_WEBSERVER
|
||||
//#include "httpd-fs.h"
|
||||
//#include "httpd-cgi.h"
|
||||
#endif
|
||||
|
||||
#include "contiki-net.h"
|
||||
#include "params.h"
|
||||
|
||||
#if WITH_NODE_ID
|
||||
uint16_t node_id;
|
||||
#endif
|
||||
|
||||
#if CONTIKI_CONF_RANDOM_MAC
|
||||
extern uint8_t rng_get_uint8(void);
|
||||
static void
|
||||
generate_new_eui64(uint8_t eui64[8]) {
|
||||
eui64[0] = 0x02;
|
||||
eui64[1] = rng_get_uint8();
|
||||
eui64[2] = rng_get_uint8();
|
||||
eui64[3] = 0xFF;
|
||||
eui64[4] = 0xFE;
|
||||
eui64[5] = rng_get_uint8();
|
||||
eui64[6] = rng_get_uint8();
|
||||
eui64[7] = rng_get_uint8();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if AVR_WEBSERVER
|
||||
/* Webserver builds can set these in httpd-fsdata.c via makefsdata.h */
|
||||
extern uint8_t default_mac_address[8];
|
||||
extern uint8_t default_server_name[16];
|
||||
extern uint8_t default_domain_name[30];
|
||||
#else
|
||||
uint8_t default_mac_address[8] PROGMEM = PARAMS_EUI64ADDR;
|
||||
uint8_t default_server_name[] PROGMEM = PARAMS_SERVERNAME;
|
||||
uint8_t default_domain_name[] PROGMEM = PARAMS_DOMAINNAME;
|
||||
#endif
|
||||
|
||||
#if PARAMETER_STORAGE==0
|
||||
/* 0 Hard coded, minmal program and eeprom usage. */
|
||||
uint8_t
|
||||
params_get_eui64(uint8_t *eui64) {
|
||||
#if CONTIKI_CONF_RANDOM_MAC
|
||||
PRINTD("Generating random EUI64 MAC\n");
|
||||
generate_new_eui64(eui64);
|
||||
return 1;
|
||||
#else
|
||||
uint8_t i;
|
||||
for (i=0;i<sizeof(default_mac_address);i++) eui64[i] = pgm_read_byte_near(default_mac_address+i);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#elif PARAMETER_STORAGE==1
|
||||
/* 1 Stored in fixed eeprom locations, rewritten from flash if corrupt.
|
||||
* They can be manually changed and kept over program reflash.
|
||||
* The channel and bit complement are used to check EEMEM integrity,
|
||||
* If corrupt all values will be rewritten with the default flash values.
|
||||
* To make this work, get the channel before anything else.
|
||||
*/
|
||||
#if !AVR_WEBSERVER
|
||||
uint8_t eemem_mac_address[] EEMEM = PARAMS_EUI64ADDR;
|
||||
uint8_t eemem_server_name[] EEMEM = PARAMS_SERVERNAME;
|
||||
uint8_t eemem_domain_name[] EEMEM = PARAMS_DOMAINNAME;
|
||||
#endif /*AVR_WEBSERVER */
|
||||
|
||||
uint16_t eemem_nodeid EEMEM = PARAMS_NODEID;
|
||||
uint8_t eemem_channel[2] EEMEM = {PARAMS_CHANNEL, ~PARAMS_CHANNEL};
|
||||
uint16_t eemem_panid EEMEM = PARAMS_PANID;
|
||||
uint16_t eemem_panaddr EEMEM = PARAMS_PANADDR;
|
||||
uint8_t eemem_txpower EEMEM = PARAMS_TXPOWER;
|
||||
|
||||
#if CONTIKI_CONF_RANDOM_MAC
|
||||
static uint8_t randomeui64;
|
||||
#endif
|
||||
|
||||
uint8_t
|
||||
params_get_channel(void) {
|
||||
uint8_t x[2];
|
||||
*(uint16_t *)x = eeprom_read_word ((uint16_t *)&eemem_channel);
|
||||
/* Don't return an invalid channel number */
|
||||
if( (x[0]<11) || (x[0] > 26)) x[1]=x[0];
|
||||
/* Do exclusive or test on the two values read */
|
||||
if((uint8_t)x[0]!=(uint8_t)~x[1]) {//~x[1] can promote comparison to 16 bit
|
||||
/* Verification fails, rewrite everything */
|
||||
uint8_t i,buffer[32];
|
||||
PRINTD("EEPROM is corrupt, rewriting with defaults.\n");
|
||||
#if CONTIKI_CONF_RANDOM_MAC
|
||||
PRINTD("Generating random EUI64 MAC\n");
|
||||
generate_new_eui64(&buffer);
|
||||
randomeui64=1;
|
||||
#else
|
||||
for (i=0;i<sizeof(default_mac_address);i++) buffer[i] = pgm_read_byte_near(default_mac_address+i);
|
||||
#endif
|
||||
/* eeprom_write_block should not be interrupted */
|
||||
cli();
|
||||
eeprom_write_block(&buffer, &eemem_mac_address, sizeof(eemem_mac_address));
|
||||
for (i=0;i<sizeof(default_server_name);i++) buffer[i] = pgm_read_byte_near(default_server_name+i);
|
||||
eeprom_write_block(&buffer, &eemem_server_name, sizeof(eemem_server_name));
|
||||
for (i=0;i<sizeof(default_domain_name);i++) buffer[i] = pgm_read_byte_near(default_domain_name+i);
|
||||
eeprom_write_block(&buffer, &eemem_domain_name, sizeof(eemem_domain_name));
|
||||
eeprom_write_word(&eemem_panid , PARAMS_PANID);
|
||||
eeprom_write_word(&eemem_panaddr, PARAMS_PANADDR);
|
||||
eeprom_write_byte(&eemem_txpower, PARAMS_TXPOWER);
|
||||
eeprom_write_word(&eemem_nodeid, PARAMS_NODEID);
|
||||
x[0] = PARAMS_CHANNEL;
|
||||
x[1]= ~x[0];
|
||||
eeprom_write_word((uint16_t *)&eemem_channel, *(uint16_t *)x);
|
||||
sei();
|
||||
}
|
||||
/* Always returns a valid channel */
|
||||
return x[0];
|
||||
}
|
||||
uint8_t
|
||||
params_get_eui64(uint8_t *eui64) {
|
||||
cli();
|
||||
eeprom_read_block ((void *)eui64, &eemem_mac_address, sizeof(rimeaddr_t));
|
||||
sei();
|
||||
#if CONTIKI_CONF_RANDOM_MAC
|
||||
return randomeui64;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
uint16_t
|
||||
params_get_panid(void) {
|
||||
return eeprom_read_word(&eemem_panid);
|
||||
}
|
||||
uint16_t
|
||||
params_get_panaddr(void) {
|
||||
return eeprom_read_word (&eemem_panaddr);
|
||||
}
|
||||
uint8_t
|
||||
params_get_txpower(void)
|
||||
{
|
||||
return eeprom_read_byte(&eemem_txpower);
|
||||
}
|
||||
|
||||
#else /* CONTIKI_CONF_SETTINGS_MANAGER */
|
||||
|
||||
uint8_t
|
||||
params_get_channel() {
|
||||
uint8_t x;
|
||||
size_t size = 1;
|
||||
if (settings_get(SETTINGS_KEY_CHANNEL, 0,(unsigned char*)&x, &size) == SETTINGS_STATUS_OK) {
|
||||
PRINTD("<-Get RF channel %u\n",x);
|
||||
} else {
|
||||
x = PARAMS_CHANNEL;
|
||||
if (settings_add_uint8(SETTINGS_KEY_CHANNEL,x ) == SETTINGS_STATUS_OK) {
|
||||
PRINTD("->Set EEPROM RF channel to %d\n",x);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
uint8_t
|
||||
params_get_eui64(uint8_t *eui64) {
|
||||
size_t size = sizeof(rimeaddr_t);
|
||||
if(settings_get(SETTINGS_KEY_EUI64, 0, (unsigned char*)eui64, &size) == SETTINGS_STATUS_OK) {
|
||||
PRINTD("<-Get EUI64 MAC\n");
|
||||
return 0;
|
||||
}
|
||||
#if CONTIKI_CONF_RANDOM_MAC
|
||||
PRINTD("Generating random EUI64 MAC\n");
|
||||
generate_new_eui64(eui64);
|
||||
#else
|
||||
{uint8_t i;for (i=0;i<8;i++) eui64[i] = pgm_read_byte_near(default_mac_address+i);} //test this
|
||||
#endif
|
||||
if (settings_add(SETTINGS_KEY_EUI64,(unsigned char*)eui64,8) == SETTINGS_STATUS_OK) {
|
||||
PRINTD("->Set EEPROM MAC address\n");
|
||||
}
|
||||
#if CONTIKI_CONF_RANDOM_MAC
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
uint16_t
|
||||
params_get_panid(void) {
|
||||
uint16_t x;
|
||||
size_t size = 2;
|
||||
if (settings_get(SETTINGS_KEY_PAN_ID, 0,(unsigned char*)&x, &size) == SETTINGS_STATUS_OK) {
|
||||
PRINTD("<-Get PAN ID of %04x\n",x);
|
||||
} else {
|
||||
x=PARAMS_PANID;
|
||||
if (settings_add_uint16(SETTINGS_KEY_PAN_ID,x)==SETTINGS_STATUS_OK) {
|
||||
PRINTD("->Set EEPROM PAN ID to %04x\n",x);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
uint16_t
|
||||
params_get_panaddr(void) {
|
||||
uint16_t x;
|
||||
size_t size = 2;
|
||||
if (settings_get(SETTINGS_KEY_PAN_ADDR, 0,(unsigned char*)&x, &size) == SETTINGS_STATUS_OK) {
|
||||
PRINTD("<-Get PAN address of %04x\n",x);
|
||||
} else {
|
||||
x=PARAMS_PANADDR;
|
||||
if (settings_add_uint16(SETTINGS_KEY_PAN_ADDR,x)==SETTINGS_STATUS_OK) {
|
||||
PRINTD("->Set EEPROM PAN address to %04x\n",x);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
uint8_t
|
||||
params_get_txpower(void) {
|
||||
uint8_t x;
|
||||
size_t size = 1;
|
||||
if (settings_get(SETTINGS_KEY_TXPOWER, 0,(unsigned char*)&x, &size) == SETTINGS_STATUS_OK) {
|
||||
PRINTD("<-Get tx power of %d (0=max)\n",x);
|
||||
} else {
|
||||
x=PARAMS_TXPOWER;
|
||||
if (settings_add_uint8(SETTINGS_KEY_TXPOWER,x)==SETTINGS_STATUS_OK) {
|
||||
PRINTD("->Set EEPROM tx power of %d (0=max)\n",x);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
#endif /* CONTIKI_CONF_SETTINGS_MANAGER */
|
112
platform/avr-raven/params.h
Normal file
112
platform/avr-raven/params.h
Normal file
|
@ -0,0 +1,112 @@
|
|||
#ifndef __PARAMS_H__
|
||||
#define __PARAMS_H__
|
||||
/* PARAMETER_STORAGE =
|
||||
* 0 Hard coded, minmal program and eeprom usage.
|
||||
* 1 Stored in fixed eeprom locations, rewritten from flash if corrupt.
|
||||
* This allows parameter changes using a hardware programmer or custom application code.
|
||||
* Corruption test is based on channel verify so get the channel before anything else!
|
||||
* 2 Obtained from eeprom using the general settings manager and read from program flash if not present.
|
||||
* Useful for for testing builds without wearing out flash memory.
|
||||
* 3 Obtained from eeprom using the settings manager and rewritten from flash if not present.
|
||||
* This ensures all parameters are present in upper eeprom flash.
|
||||
*
|
||||
* Note the parameters in this file can be changed without forcing a complete rebuild.
|
||||
*/
|
||||
//#define PARAMETER_STORAGE 0
|
||||
//#define PARAMETER_STORAGE 1 //+476
|
||||
//#define PARAMETER_STORAGE 2 //+2045
|
||||
//#define PARAMETER_STORAGE 3 //+2144
|
||||
|
||||
//#define CONTIKI_CONF_SETTINGS_MANAGER 1
|
||||
//#define CONTIKI_CONF_RANDOM_MAC 1 //adds 78 bytes
|
||||
|
||||
#if CONTIKI_CONF_SETTINGS_MANAGER
|
||||
#define PARAMETER_STORAGE 2
|
||||
#else
|
||||
#define PARAMETER_STORAGE 1
|
||||
#endif
|
||||
|
||||
/* Include settings.h, then dummy out the write routines */
|
||||
#include "settings.h"
|
||||
#if PARAMETER_STORAGE==2
|
||||
#define settings_add(...) 0
|
||||
#define settings_add_uint8(...) 0
|
||||
#define settings_add_uint16(...) 0
|
||||
#endif
|
||||
|
||||
#if AVR_WEBSERVER
|
||||
/* Webserver builds can set some defaults in httpd-fsdata.c via makefsdata.h */
|
||||
extern uint8_t eemem_mac_address[8];
|
||||
extern uint8_t eemem_server_name[16];
|
||||
extern uint8_t eemem_domain_name[30];
|
||||
#endif
|
||||
|
||||
#ifdef SERVER_NAME
|
||||
#define PARAMS_SERVERNAME SERVER_NAME
|
||||
#else
|
||||
#define PARAMS_SERVERNAME "Raven_webserver"
|
||||
#endif
|
||||
#ifdef DOMAIN_NAME
|
||||
#define PARAMS_DOMAINNAME DOMAIN_NAME
|
||||
#else
|
||||
#define PARAMS_DOMAINNAME "localhost"
|
||||
#endif
|
||||
#ifdef NODE_ID
|
||||
#define PARAMS_NODEID NODE_ID
|
||||
#else
|
||||
#define PARAMS_NODEID 0
|
||||
#endif
|
||||
#ifdef CHANNEL_802_15_4
|
||||
#define PARAMS_CHANNEL CHANNEL_802_15_4
|
||||
#else
|
||||
#define PARAMS_CHANNEL 26
|
||||
#endif
|
||||
#ifdef IEEE802154_PANID
|
||||
#define PARAMS_PANID IEEE802154_PANID
|
||||
#else
|
||||
#define PARAMS_PANID 0xABCD
|
||||
#endif
|
||||
#ifdef IEEE802154_PANADDR
|
||||
#define PARAMS_PANADDR IEEE802154_PANADDR
|
||||
#else
|
||||
#define PARAMS_PANADDR 0
|
||||
#endif
|
||||
#ifdef RF230_MAX_TX_POWER
|
||||
#define PARAMS_TXPOWER RF230_MAX_TX_POWER
|
||||
#else
|
||||
#define PARAMS_TXPOWER 0
|
||||
#endif
|
||||
#ifdef EUI64_ADDRESS
|
||||
#define PARAMS_EUI64ADDR EUI64_ADDRESS
|
||||
#else
|
||||
/* This form of of EUI64 mac allows full 6LoWPAN header compression from mac address */
|
||||
#if UIP_CONF_LL_802154
|
||||
//#define PARAMS_EUI64ADDR {0x02, 0xNN, 0xNN, 0xNN, 0xNN, 0xNN, 0xNN, 0xNN}
|
||||
#define PARAMS_EUI64ADDR {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55};
|
||||
#else
|
||||
//#define PARAMS_EUI64ADDR {0x02, 0xNN, 0xNN, 0xff, 0xfe, 0xNN, 0xNN, 0xNN}
|
||||
#define PARAMS_EUI64ADDR {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55};
|
||||
#endif
|
||||
/* This form of of EUI64 mac allows 16 bit 6LoWPAN header compression on multihops */
|
||||
//#define PARAMS_EUI64ADDR {0x02, 0x00, 0x00, 0xff, 0xfe, 0x00, 0xNN, 0xNN}
|
||||
#endif
|
||||
|
||||
uint8_t params_get_eui64(uint8_t *eui64);
|
||||
#if PARAMETER_STORAGE==0
|
||||
/* Hard coded program flash parameters */
|
||||
#define params_get_servername(...)
|
||||
#define params_get_nodeid(...) PARAMS_NODEID
|
||||
#define params_get_channel(...) PARAMS_CHANNEL
|
||||
#define params_get_panid(...) PARAMS_PANID
|
||||
#define params_get_panaddr(...) PARAMS_PANADDR
|
||||
#define params_get_txpower(...) PARAMS_TXPOWER
|
||||
#else
|
||||
/* Parameters stored in eeprom */
|
||||
uint16_t params_get_nodeid(void);
|
||||
uint8_t params_get_channel(void);
|
||||
uint16_t params_get_panid(void);
|
||||
uint16_t params_get_panaddr(void);
|
||||
uint8_t params_get_txpower(void);
|
||||
#endif
|
||||
|
||||
#endif /* __PARAMS_H__ */
|
Loading…
Reference in a new issue