35 #include "dev/ds2411/ds2411.h"
39 #include "dev/uart1.h"
40 #include "dev/watchdog.h"
42 #include "lib/random.h"
46 #if NETSTACK_CONF_WITH_IPV6
52 #include "sys/node-id.h"
59 #ifndef UIP_ROUTER_MODULE
60 #ifdef UIP_CONF_ROUTER_MODULE
61 #define UIP_ROUTER_MODULE UIP_CONF_ROUTER_MODULE
63 #define UIP_ROUTER_MODULE rimeroute
67 extern const struct uip_router UIP_ROUTER_MODULE;
70 #if DCOSYNCH_CONF_ENABLED
71 static struct timer mgt_timer;
73 extern int msp430_dco_required;
75 #ifndef NETSTACK_CONF_WITH_IPV4
76 #define NETSTACK_CONF_WITH_IPV4 0
79 #if NETSTACK_CONF_WITH_IPV4
82 #include "net/ipv4/uip-fw-drv.h"
87 {
UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)};
91 #define UIP_OVER_MESH_CHANNEL 8
92 #if NETSTACK_CONF_WITH_IPV4
93 static uint8_t is_gateway;
96 #ifdef EXPERIMENT_SETUP
97 #include "experiment-setup.h"
102 #define PRINTF(...) printf(__VA_ARGS__)
107 void init_platform(
void);
112 force_float_inclusion()
114 extern int __fixsfsi;
115 extern int __floatsisf;
119 return __fixsfsi + __floatsisf + __mulsf3 + __subsf3;
128 force_inclusion(
int d1,
int d2)
130 snprintf(
NULL, 0,
"%d", d1 % d2);
140 memset(&addr, 0,
sizeof(linkaddr_t));
141 #if NETSTACK_CONF_WITH_IPV6
142 memcpy(addr.u8, ds2411_id,
sizeof(addr.u8));
145 for(i = 0; i <
sizeof(linkaddr_t); ++i) {
146 addr.u8[i] = ds2411_id[7 - i];
149 addr.u8[0] = node_id & 0xff;
150 addr.u8[1] = node_id >> 8;
154 PRINTF(
"Rime started with address ");
155 for(i = 0; i <
sizeof(addr.u8) - 1; i++) {
156 PRINTF(
"%d.", addr.u8[i]);
158 PRINTF(
"%d\n", addr.u8[i]);
161 #if !PROCESS_CONF_NO_PROCESS_NAMES
163 print_processes(
struct process *
const processes[])
167 while(*processes !=
NULL) {
168 printf(
" '%s'", (*processes)->name);
175 #if NETSTACK_CONF_WITH_IPV4
181 PRINTF(
"%d.%d: making myself the IP network gateway.\n\n",
183 PRINTF(
"IPv4 address of the gateway: %d.%d.%d.%d\n\n",
186 uip_over_mesh_make_announced_gateway();
192 #if WITH_TINYOS_AUTO_IDS
193 uint16_t TOS_NODE_ID = 0x1234;
194 uint16_t TOS_LOCAL_ADDRESS = 0x1234;
197 main(
int argc,
char **argv)
216 ds2411_id[2] &= 0xfe;
230 ENERGEST_ON(ENERGEST_TYPE_CPU);
232 #if WITH_TINYOS_AUTO_IDS
233 node_id = TOS_NODE_ID;
240 #ifdef IEEE_802154_MAC_ADDRESS
242 uint8_t ieee[] = IEEE_802154_MAC_ADDRESS;
243 memcpy(ds2411_id, ieee,
sizeof(
uip_lladdr.addr));
244 ds2411_id[7] = node_id & 0xff;
259 #if NETSTACK_CONF_WITH_IPV4
274 memset(longaddr, 0,
sizeof(longaddr));
276 PRINTF(
"MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
277 longaddr[0], longaddr[1], longaddr[2], longaddr[3],
278 longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
280 cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
283 PRINTF(CONTIKI_VERSION_STRING
" started. ");
285 PRINTF(
"Node id is set to %u.\n", node_id);
287 PRINTF(
"Node id is not set.\n");
294 #if NETSTACK_CONF_WITH_IPV6
304 NETSTACK_LLSEC.init();
305 NETSTACK_NETWORK.init();
307 PRINTF(
"%s %s %s, channel check rate %lu Hz, radio channel %u, CCA threshold %i\n",
308 NETSTACK_LLSEC.name, NETSTACK_MAC.name, NETSTACK_RDC.name,
309 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
310 NETSTACK_RDC.channel_check_interval()),
312 CC2420_CONF_CCA_THRESH);
317 PRINTF(
"Tentative link-local IPv6 address ");
321 lladdr = uip_ds6_get_link_local(-1);
322 for(i = 0; i < 7; ++i) {
323 PRINTF(
"%02x%02x:", lladdr->ipaddr.u8[i * 2],
324 lladdr->ipaddr.u8[i * 2 + 1]);
326 PRINTF(
"%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
330 if(!UIP_CONF_IPV6_RPL) {
333 uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
336 PRINTF(
"Tentative global IPv6 address ");
337 for(i = 0; i < 7; ++i) {
339 ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
342 ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
348 NETSTACK_LLSEC.init();
349 NETSTACK_NETWORK.init();
351 PRINTF(
"%s %s %s, channel check rate %lu Hz, radio channel %u\n",
352 NETSTACK_LLSEC.name, NETSTACK_MAC.name, NETSTACK_RDC.name,
353 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
354 NETSTACK_RDC.channel_check_interval()),
355 CC2420_CONF_CHANNEL);
358 #if !NETSTACK_CONF_WITH_IPV4 && !NETSTACK_CONF_WITH_IPV6
363 leds_off(LEDS_GREEN);
365 #if TIMESYNCH_CONF_ENABLED
370 #if NETSTACK_CONF_WITH_IPV4
378 uip_ipaddr_t hostaddr,
netmask;
389 uip_over_mesh_set_net(&hostaddr, &netmask);
391 uip_over_mesh_set_gateway_netif(&slipif);
393 uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
394 PRINTF(
"uIP started with IP address %d.%d.%d.%d\n",
401 #if !PROCESS_CONF_NO_PROCESS_NAMES
402 print_processes(autostart_processes);
404 autostart_start(autostart_processes);
409 #if DCOSYNCH_CONF_ENABLED
430 static unsigned long irq_energest = 0;
432 #if DCOSYNCH_CONF_ENABLED
438 #if CC2420_CONF_SFD_TIMESTAMPS
439 cc2420_arch_sfd_init();
445 ENERGEST_SWITCH(ENERGEST_TYPE_CPU, ENERGEST_TYPE_LPM);
449 energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
452 if (msp430_dco_required) {
453 _BIS_SR(GIE | CPUOFF);
455 _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF);
465 irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
468 ENERGEST_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU);
477 log_message(
char *m1,
char *m2)
479 printf(
"%s%s\n", m1, m2);
void uip_log(char *msg)
Print out a uIP log message.
#define uip_sethostaddr(addr)
Set the IP address of this host.
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
void timer_reset(struct timer *t)
Reset the timer with the same interval.
#define uip_ipaddr(addr, addr0, addr1, addr2, addr3)
Construct an IP address from four bytes.
void timesynch_set_authority_level(int level)
Set the authority level of the current time.
static uip_ds6_addr_t * addr
Pointer to a router list entry.
uint8_t slip_send(void)
Send an IP packet from the uIP buffer with SLIP.
Header file for IPv6-related data structures.
void uart1_init(unsigned long ubr)
Initalize the RS232 port.
void timer_set(struct timer *t, clock_time_t interval)
Set a timer.
uip_ipaddr_t ipaddr
The IP address of this interface.
void random_init(unsigned short seed)
Seed the cc2538 random number generator.
void watchdog_stop(void)
Stops the WDT such that it won't timeout and cause MCU reset.
Header file for tunnelling uIP over Rime mesh
void clock_init(void)
Initialize the clock library.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
int process_run(void)
Run the system once - call poll handlers and process one event.
Unicast address structure.
void slip_arch_init(unsigned long ubr)
Initalize the RS232 port and the SLIP driver.
void slip_set_input_callback(void(*c)(void))
Set a function to be called when there is activity on the SLIP interface; used for detecting if a nod...
uip_ipaddr_t netmask
The netmask of the interface.
Header file for the Rime stack
#define uip_setnetmask(addr)
Set the netmask.
#define NULL
The null pointer.
#define uip_ipaddr_to_quad(a)
Convert an IP address to four bytes separated by commas.
802.15.4 frame creation and parsing functions
uIP packet forwarding header file.
void linkaddr_set_node_addr(linkaddr_t *t)
Set the address of the current node.
#define UIP_FW_NETIF(ip1, ip2, ip3, ip4, nm1, nm2, nm3, nm4, outputfunc)
Instantiating macro for a uIP network interface.
void watchdog_periodic(void)
Writes the WDT clear sequence.
#define ADDR_TENTATIVE
Possible states for the an address (RFC 4862)
#define CLOCK_SECOND
A second, measured in system clock time.
#define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7)
Construct an IPv6 address from eight 16-bit words.
Header file for the uIP TCP/IP stack.
void process_start(struct process *p, process_data_t data)
Start a process.
Header for the Coffee file system.
uip_ds6_addr_t * uip_ds6_addr_add(uip_ipaddr_t *ipaddr, unsigned long vlifetime, uint8_t type)
Add a unicast address to the interface.
Header file for module for automatically starting and exiting a list of processes.
void timesynch_init(void)
Initialize the timesynch module.
void rtimer_init(void)
Initialize the real-time scheduler.
Generic serial I/O process header filer.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
void uip_init(void)
uIP initialization function.
int process_nevents(void)
Number of events waiting to be processed.
void process_init(void)
Initialize the process module.
void ctimer_init(void)
Initialize the callback timer library.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a Rime address.
linkaddr_t linkaddr_node_addr
The Rime address of the node.
Coffee architecture-dependent header for the Tmote Sky platform.
int serial_line_input_byte(unsigned char c)
Get one byte of input from the serial driver.
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
Include file for the Contiki low-layer network stack (NETSTACK)
void uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr)
set the last 64 bits of an IP address based on the MAC address
void uip_fw_default(struct uip_fw_netif *netif)
Register a default network interface.
int timer_expired(struct timer *t)
Check if a timer has expired.
Representation of a uIP network interface.