Contiki 3.x
contiki-raven-main.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006, Technical University of Munich
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  * @(#)$$
32  */
33 
34 /**
35  * \file
36  * Contiki 2.4 kernel for Jackdaw USB stick
37  *
38  * \author
39  * Simon Barner <barner@in.tum.de>
40  * David Kopf <dak664@embarqmail.com>
41  */
42 
43 #define DEBUG 0
44 #if DEBUG
45 #define PRINTD(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
46 #else
47 #define PRINTD(...)
48 #endif
49 
50 #include <avr/pgmspace.h>
51 #include <avr/fuse.h>
52 #include <avr/eeprom.h>
53 #include <avr/wdt.h>
54 #include <util/delay.h>
55 #include <stdio.h>
56 #include <string.h>
57 
58 #include "lib/mmem.h"
59 #include "loader/symbols-def.h"
60 #include "loader/symtab.h"
61 
62 #include "contiki.h"
63 #include "contiki-net.h"
64 #include "contiki-lib.h"
65 #include "contiki-raven.h"
66 
67 /* Set ANNOUNCE to send boot messages to USB or RS232 serial port */
68 #define ANNOUNCE 1
69 
70 /* But only if a serial port exists */
71 #if USB_CONF_SERIAL||USB_CONF_RS232
72 #define PRINTA(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
73 #else
74 #define PRINTA(...)
75 #endif
76 
77 #include "usb_task.h"
78 #if USB_CONF_SERIAL
79 #include "cdc_task.h"
80 #endif
81 #if USB_CONF_RS232
82 #include "dev/rs232.h"
83 #endif
84 
85 #include "rndis/rndis_task.h"
86 #if USB_CONF_STORAGE
87 #include "storage/storage_task.h"
88 #endif
89 
90 #include "dev/watchdog.h"
91 #include "dev/usb/usb_drv.h"
92 
93 #if JACKDAW_CONF_USE_SETTINGS
94 #include "settings.h"
95 #endif
96 
97 #if RF230BB //radio driver using contiki core mac
98 #include "radio/rf230bb/rf230bb.h"
99 #include "net/mac/frame802154.h"
100 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
101 linkaddr_t macLongAddr;
102 #define tmp_addr macLongAddr
103 #else //legacy radio driver using Atmel/Cisco 802.15.4'ish MAC
104 #include <stdbool.h>
105 #include "mac.h"
106 #include "sicslowmac.h"
107 #include "sicslowpan.h"
108 #include "ieee-15-4-manager.h"
109 #endif /* RF230BB */
110 
111 /* Test rtimers, also useful for pings, time stamps, routes, stack monitor */
112 #define TESTRTIMER 0
113 #if TESTRTIMER
114 #define PINGS 0
115 #define STAMPS 60
116 #define ROUTES 120
117 #define STACKMONITOR 600
118 uint8_t rtimerflag=1;
119 uint16_t rtime;
120 struct rtimer rt;
121 void rtimercycle(void) {rtimerflag=1;}
122 #endif /* TESTRTIMER */
123 
124 #if UIP_CONF_IPV6_RPL
125 /*---------------------------------------------------------------------------*/
126 /*--------------------------------- RPL ----------------------------------*/
127 /*---------------------------------------------------------------------------*/
128 /* TODO: Put rpl code into another file, once it stabilizes */
129 /* Set up fallback interface links to direct stack tcpip output to ethernet */
130 static void
131 init(void)
132 {
133 }
134 void mac_LowpanToEthernet(void);
135 static int
136 output(void)
137 {
138 // if(uip_ipaddr_cmp(&last_sender, &UIP_IP_BUF->srcipaddr)) {
139  /* Do not bounce packets back over USB if the packet was received from USB */
140 // PRINTA("JACKDAW router: Destination off-link but no route\n");
141  // } else {
142  PRINTD("SUT: %u\n", uip_len);
143  mac_LowpanToEthernet(); //bounceback trap is done in lowpanToEthernet
144 // }
145  return 0;
146 }
147 const struct uip_fallback_interface rpl_interface = {
148  init, output
149 };
150 
151 #if RPL_BORDER_ROUTER
152 #include "net/rpl/rpl.h"
153 
154 // avr-objdump --section .bss -x ravenusbstick.elf
155 const uint16_t dag_id[] PROGMEM = {0x1111, 0x1100, 0, 0, 0, 0, 0, 0x0011};
156 
157 PROCESS(border_router_process, "RPL Border Router");
158 PROCESS_THREAD(border_router_process, ev, data)
159 {
160 
161  PROCESS_BEGIN();
162 
163  PROCESS_PAUSE();
164 
165 { rpl_dag_t *dag;
166  char buf[sizeof(dag_id)];
167  memcpy_P(buf,dag_id,sizeof(dag_id));
168  dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)buf);
169 
170 /* Assign separate addresses to the jackdaw uip stack and the host network interface, but with the same prefix */
171 /* E.g. bbbb::200 to the jackdaw and bbbb::1 to the host network interface with $ip -6 address add bbbb::1/64 dev usb0 */
172 /* Otherwise the host will trap packets intended for the jackdaw, just as the jackdaw will trap RF packets intended for the host */
173 /* $ifconfig usb0 -arp on Ubuntu to skip the neighbor solicitations. Add explicit neighbors on other OSs */
174  if(dag != NULL) {
175  PRINTD("created a new RPL dag\n");
176 
177 #if UIP_CONF_ROUTER_RECEIVE_RA
178 //Contiki stack will shut down until assigned an address from the interface RA
179 //Currently this requires changes in the core rpl-icmp6.c to pass the link-local RA broadcast
180 
181 #else
182  uip_ip6addr_t ipaddr;
183  uip_ip6addr(&ipaddr, 0xbbbb, 0, 0, 0, 0, 0, 0, 0x200);
184  uip_ds6_addr_add(&ipaddr, 0, ADDR_MANUAL);
185  rpl_set_prefix(dag, &ipaddr, 64);
186 #endif
187  }
188 }
189  /* The border router runs with a 100% duty cycle in order to ensure high
190  packet reception rates. */
191  // NETSTACK_MAC.off(1);
192 
193  while(1) {
194  PROCESS_YIELD();
195  /* Local and global dag repair can be done from the jackdaw menu */
196 
197  }
198 
199  PROCESS_END();
200 }
201 #endif /* RPL_BORDER_ROUTER */
202 
203 #endif /* UIP_CONF_IPV6_RPL */
204 
205 /*-------------------------------------------------------------------------*/
206 /*----------------------Configuration of the .elf file---------------------*/
207 #if 1
208 /* The proper way to set the signature is */
209 #include <avr/signature.h>
210 #else
211 /* Older avr-gcc's may not define the needed SIGNATURE bytes. Do it manually if you get an error */
212 typedef struct {const unsigned char B2;const unsigned char B1;const unsigned char B0;} __signature_t;
213 #define SIGNATURE __signature_t __signature __attribute__((section (".signature")))
214 SIGNATURE = {
215  .B2 = 0x82,//SIGNATURE_2, //AT90USB128x
216  .B1 = 0x97,//SIGNATURE_1, //128KB flash
217  .B0 = 0x1E,//SIGNATURE_0, //Atmel
218 };
219 #endif
220 
221 FUSES ={.low = 0xde, .high = 0x99, .extended = 0xff,};
222 
223 /* Save the default settings into program flash memory */
224 const uint8_t default_mac_address[8] PROGMEM = {0x02, 0x12, 0x13, 0xff, 0xfe, 0x14, 0x15, 0x16};
225 #ifdef CHANNEL_802_15_4
226 const uint8_t default_channel PROGMEM = CHANNEL_802_15_4;
227 #else
228 const uint8_t default_channel PROGMEM = 26;
229 #endif
230 #ifdef IEEE802154_PANID
231 const uint16_t default_panid PROGMEM = IEEE802154_PANID;
232 #else
233 const uint16_t default_panid PROGMEM = 0xABCD;
234 #endif
235 #ifdef IEEE802154_PANADDR
236 const uint16_t default_panaddr PROGMEM = IEEE802154_PANID;
237 #else
238 const uint16_t default_panaddr PROGMEM = 0;
239 #endif
240 #ifdef RF230_MAX_TX_POWER
241 const uint8_t default_txpower PROGMEM = RF230_MAX_TX_POWER;
242 #else
243 const uint8_t default_txpower PROGMEM = 0;
244 #endif
245 
246 #if JACKDAW_CONF_RANDOM_MAC
247 #include "rng.h"
248 static void
249 generate_new_eui64(uint8_t eui64[8]) {
250  eui64[0] = 0x02;
251  eui64[1] = rng_get_uint8();
252  eui64[2] = rng_get_uint8();
253  eui64[3] = 0xFF;
254  eui64[4] = 0xFE;
255  eui64[5] = rng_get_uint8();
256  eui64[6] = rng_get_uint8();
257  eui64[7] = rng_get_uint8();
258 }
259 #endif /* JACKDAW_CONF_RANDOM_MAC */
260 
261 #if !JACKDAW_CONF_USE_SETTINGS
262 /****************************No settings manager*****************************/
263 /* If not using the settings manager, put the default values into EEMEM
264  * These can be manually changed and kept over program reflash.
265  * The channel and bit complement are used to check EEMEM integrity,
266  * If corrupt all values will be rewritten with the default flash values.
267  * To make this work, get the channel before anything else.
268  */
269 
270 uint8_t eemem_mac_address[8] EEMEM = {0x02, 0x12, 0x13, 0xff, 0xfe, 0x14, 0x15, 0x16};
271 #ifdef CHANNEL_802_15_4
272 uint8_t eemem_channel[2] EEMEM = {CHANNEL_802_15_4, ~CHANNEL_802_15_4};
273 #else
274 uint8_t eemem_channel[2] EMEM = {26, ~26};
275 #endif
276 #ifdef IEEE802154_PANID
277 uint16_t eemem_panid EEMEM = IEEE802154_PANID;
278 #else
279 uint16_t eemem_panid EEMEM = 0xABCD;
280 #endif
281 #ifdef IEEE802154_PANADDR
282 uint16_t eemem_panaddr EEMEM = IEEE802154_PANADDR;
283 #else
284 uint16_t eemem_panaddr EEMEM = 0;
285 #endif
286 #ifdef RF230_MAX_TX_POWER
287 uint8_t eemem_txpower EEMEM = RF230_MAX_TX_POWER;
288 #else
289 uint8_t eemem_txpower EEMEM = 0;
290 #endif
291 static uint8_t get_channel_from_eeprom() {
292  uint8_t x[2];
293  *(uint16_t *)x = eeprom_read_word ((uint16_t *)&eemem_channel);
294  if((uint8_t)x[0]!=(uint8_t)~x[1]) {//~x[1] can promote comparison to 16 bit
295 /* Verification fails, rewrite everything */
296  uint8_t mac[8];
297 #if JACKDAW_CONF_RANDOM_MAC
298  PRINTA("Generating random MAC address.\n");
299  generate_new_eui64(&mac);
300 #else
301  {uint8_t i; for (i=0;i<8;i++) mac[i] = pgm_read_byte_near(default_mac_address+i);}
302 #endif
303  eeprom_write_block(&mac, &eemem_mac_address, 8);
304  eeprom_write_word(&eemem_panid , pgm_read_word_near(&default_panid));
305  eeprom_write_word(&eemem_panaddr, pgm_read_word_near(&default_panaddr));
306  eeprom_write_byte(&eemem_txpower, pgm_read_byte_near(&default_txpower));
307  x[0] = pgm_read_byte_near(&default_channel);
308  x[1]= ~x[0];
309  eeprom_write_word((uint16_t *)&eemem_channel, *(uint16_t *)x);
310  }
311  return x[0];
312 }
313 static bool get_eui64_from_eeprom(uint8_t macptr[8]) {
314  eeprom_read_block ((void *)macptr, &eemem_mac_address, 8);
315  return macptr[0]!=0xFF;
316 }
317 static uint16_t get_panid_from_eeprom(void) {
318  return eeprom_read_word(&eemem_panid);
319 }
320 static uint16_t get_panaddr_from_eeprom(void) {
321  return eeprom_read_word (&eemem_panaddr);
322 }
323 static uint8_t get_txpower_from_eeprom(void)
324 {
325  return eeprom_read_byte(&eemem_txpower);
326 }
327 
328 #else /* !JACKDAW_CONF_USE_SETTINGS */
329 /******************************Settings manager******************************/
330 static uint8_t get_channel_from_eeprom() {
331  uint8_t x = settings_get_uint8(SETTINGS_KEY_CHANNEL, 0);
332  if(!x) x = pgm_read_byte_near(&default_channel);
333  return x;
334 }
335 static bool get_eui64_from_eeprom(uint8_t macptr[8]) {
336  size_t size = 8;
337  if(settings_get(SETTINGS_KEY_EUI64, 0, (unsigned char*)macptr, &size)==SETTINGS_STATUS_OK) {
338  PRINTD("<=Get EEPROM MAC address.\n");
339  return true;
340  }
341 #if JACKDAW_CONF_RANDOM_MAC
342  PRINTA("--Generating random MAC address.\n");
343  generate_new_eui64(macptr);
344 #else
345  {uint8_t i;for (i=0;i<8;i++) macptr[i] = pgm_read_byte_near(default_mac_address+i);}
346 #endif
347  settings_add(SETTINGS_KEY_EUI64,(unsigned char*)macptr,8);
348  PRINTA("->Set EEPROM MAC address.\n");
349  return true;
350 }
351 static uint16_t get_panid_from_eeprom(void) {
352  uint16_t x;
354  x = settings_get_uint16(SETTINGS_KEY_PAN_ID,0);
355  PRINTD("<-Get EEPROM PAN ID of %04x.\n",x);
356  } else {
357  x=pgm_read_word_near(&default_panid);
358  if (settings_add_uint16(SETTINGS_KEY_PAN_ID,x)==SETTINGS_STATUS_OK) {
359  PRINTA("->Set EEPROM PAN ID to %04x.\n",x);
360  }
361  }
362  return x;
363 }
364 static uint16_t get_panaddr_from_eeprom(void) {
365  uint16_t x;
367  x = settings_get_uint16(SETTINGS_KEY_PAN_ADDR,0);
368  PRINTD("<-Get EEPROM PAN address of %04x.\n",x);
369  } else {
370  x=pgm_read_word_near(&default_panaddr);
371  if (settings_add_uint16(SETTINGS_KEY_PAN_ADDR,x)==SETTINGS_STATUS_OK) {
372  PRINTA("->Set EEPROM PAN address to %04x.\n",x);
373  }
374  }
375  return x;
376 }
377 static uint8_t get_txpower_from_eeprom(void) {
378  uint8_t x;
380  x = settings_get_uint8(SETTINGS_KEY_TXPOWER,0);
381  PRINTD("<-Get EEPROM tx power of %d. (0=max)\n",x);
382  } else {
383  x=pgm_read_byte_near(&default_txpower);
384  if (settings_add_uint8(SETTINGS_KEY_TXPOWER,x)==SETTINGS_STATUS_OK) {
385  PRINTA("->Set EEPROM tx power of %d. (0=max)\n",x);
386  }
387  }
388  return x;
389 }
390 #endif /* !JACKDAW_CONF_USE_SETTINGS */
391 
392 /*-------------------------------------------------------------------------*/
393 /*-----------------------------Low level initialization--------------------*/
394 static void initialize(void) {
395 
396  watchdog_init();
397  watchdog_start();
398 
399 #if CONFIG_STACK_MONITOR
400  /* Simple stack pointer highwater monitor. The 'm' command in cdc_task.c
401  * looks for the first overwritten magic number.
402  */
403 {
404 extern uint16_t __bss_end;
405 uint16_t p=(uint16_t)&__bss_end;
406  do {
407  *(uint16_t *)p = 0x4242;
408  p+=100;
409  } while (p<SP-100); //don't overwrite our own stack
410 }
411 #endif
412 
413  /* Initialize hardware */
414  // Checks for "finger", jumps to DFU if present.
415  init_lowlevel();
416 
417  /* Clock */
418  clock_init();
419 
420  /* Leds are referred to by number to prevent any possible confusion :) */
421  /* Led0 Blue Led1 Red Led2 Green Led3 Yellow */
422  Leds_init();
423  Led1_on();
424 
425 /* Get a random (or probably different) seed for the 802.15.4 packet sequence number.
426  * Some layers will ignore duplicates found in a history (e.g. Contikimac)
427  * causing the initial packets to be ignored after a short-cycle restart.
428  */
429  ADMUX =0x1E; //Select AREF as reference, measure 1.1 volt bandgap reference.
430  ADCSRA=1<<ADEN; //Enable ADC, not free running, interrupt disabled, fastest clock
431  ADCSRA|=1<<ADSC; //Start conversion
432  while (ADCSRA&(1<<ADSC)); //Wait till done
433  PRINTD("ADC=%d\n",ADC);
434  random_init(ADC);
435  ADCSRA=0; //Disable ADC
436 
437 #if USB_CONF_RS232
438  /* Use rs232 port for serial out (tx, rx, gnd are the three pads behind jackdaw leds */
439  rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
440  /* Redirect stdout to second port */
441  rs232_redirect_stdout(RS232_PORT_0);
442 #if ANNOUNCE
443  PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);
444 #endif
445 #endif
446 
447  /* rtimer init needed for low power protocols */
448  rtimer_init();
449 
450  /* Process subsystem. */
451  process_init();
452 
453  /* etimer process must be started before USB or ctimer init */
454  process_start(&etimer_process, NULL);
455 
456  Led2_on();
457  /* Now we can start USB enumeration */
458  process_start(&usb_process, NULL);
459 
460  /* Start CDC enumeration, bearing in mind that it may fail */
461  /* Hopefully we'll get a stdout for startup messages, if we don't already */
462 #if USB_CONF_SERIAL
463  process_start(&cdc_process, NULL);
464 {unsigned short i;
465  for (i=0;i<65535;i++) {
466  process_run();
468  if (stdout) break;
469  }
470 #if !USB_CONF_RS232
471  PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);
472 #endif
473 }
474 #endif
475  if (!stdout) Led3_on();
476 
477 #if RF230BB
478 #if JACKDAW_CONF_USE_SETTINGS
479  PRINTA("Settings manager will be used.\n");
480 #else
481 {uint8_t x[2];
482  *(uint16_t *)x = eeprom_read_word((uint16_t *)&eemem_channel);
483  if((uint8_t)x[0]!=(uint8_t)~x[1]) {
484  PRINTA("Invalid EEPROM settings detected. Rewriting with default values.\n");
485  get_channel_from_eeprom();
486  }
487 }
488 #endif
489 
490  ctimer_init();
491  /* Start radio and radio receive process */
492  /* Note this starts RF230 process, so must be done after process_init */
493  NETSTACK_RADIO.init();
494 
495  /* Set addresses BEFORE starting tcpip process */
496 
497  memset(&tmp_addr, 0, sizeof(linkaddr_t));
498 
499  if(get_eui64_from_eeprom(tmp_addr.u8));
500 
501  //Fix MAC address
502  init_net();
503 
504 #if NETSTACK_CONF_WITH_IPV6
505  memcpy(&uip_lladdr.addr, &tmp_addr.u8, 8);
506 #endif
507 
508  rf230_set_pan_addr(
509  get_panid_from_eeprom(),
510  get_panaddr_from_eeprom(),
511  (uint8_t *)&tmp_addr.u8
512  );
513 
514  rf230_set_channel(get_channel_from_eeprom());
515  rf230_set_txpower(get_txpower_from_eeprom());
516 
517  linkaddr_set_node_addr(&tmp_addr);
518 
519  /* Initialize stack protocols */
520  queuebuf_init();
521  NETSTACK_RDC.init();
522  NETSTACK_MAC.init();
523  NETSTACK_NETWORK.init();
524 
525 #if ANNOUNCE
526  PRINTA("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r",tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]);
527  PRINTA("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel());
528  if (NETSTACK_RDC.channel_check_interval) {
529  unsigned short tmp;
530  tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\
531  NETSTACK_RDC.channel_check_interval());
532  if (tmp<65535) PRINTA(", check rate %u Hz",tmp);
533  }
534  PRINTA("\n");
535 #endif
536 
537 #if UIP_CONF_IPV6_RPL
538 #if RPL_BORDER_ROUTER
539  process_start(&tcpip_process, NULL);
540  process_start(&border_router_process, NULL);
541  PRINTD ("RPL Border Router Started\n");
542 #else
543  process_start(&tcpip_process, NULL);
544  PRINTD ("RPL Started\n");
545 #endif
546 #if RPL_HTTPD_SERVER
547  extern struct process httpd_process;
548  process_start(&httpd_process, NULL);
549  PRINTD ("Webserver Started\n");
550 #endif
551 #endif /* UIP_CONF_IPV6_RPL */
552 
553 #else /* RF230BB */
554 /* The order of starting these is important! */
555  process_start(&mac_process, NULL);
556 #if NETSTACK_CONF_WITH_IPV6 || NETSTACK_CONF_WITH_IPV4
557  process_start(&tcpip_process, NULL);
558 #endif
559 #endif /* RF230BB */
560 
561  /* Start ethernet network and storage process */
562  process_start(&usb_eth_process, NULL);
563 #if USB_CONF_STORAGE
564  process_start(&storage_process, NULL);
565 #endif
566 
567  /* Autostart other processes */
568  /* There are none in the default build so autostart_processes will be unresolved in the link. */
569  /* The AUTOSTART_PROCESSES macro which defines it can only be used in the .co module. */
570  /* See /examples/ravenusbstick/ravenusb.c for an autostart template. */
571 #if 0
572  autostart_start(autostart_processes);
573 #endif
574 
575 #if ANNOUNCE
576 #if USB_CONF_RS232
577  PRINTA("Online.\n");
578 #else
579  PRINTA("Online. Type ? for Jackdaw menu.\n");
580 #endif
581 #endif
582 
583 Leds_off();
584 }
585 
586 /*-------------------------------------------------------------------------*/
587 /*---------------------------------Main Routine----------------------------*/
588 int
589 main(void)
590 {
591  /* GCC depends on register r1 set to 0 (?) */
592  asm volatile ("clr r1");
593 
594  /* Initialize in a subroutine to maximize stack space */
595  initialize();
596 
597 #if DEBUG
598 {struct process *p;
599  for(p = PROCESS_LIST();p != NULL; p = ((struct process *)p->next)) {
600  PRINTA("Process=%p Thread=%p Name=\"%s\" \n",p,p->thread,PROCESS_NAME_STRING(p));
601  }
602 }
603 #endif
604 
605  while(1) {
606  process_run();
607 
609 
610 /* Print rssi of all received packets, useful for range testing */
611 #ifdef RF230_MIN_RX_POWER
612  uint8_t lastprint;
613  if (rf230_last_rssi != lastprint) { //can be set in halbb.c interrupt routine
614  PRINTA("%u ",rf230_last_rssi);
615  lastprint=rf230_last_rssi;
616  }
617 #endif
618 
619 #if 0
620 /* Clock.c can trigger a periodic PLL calibration in the RF230BB driver.
621  * This can show when that happens.
622  */
623  extern uint8_t rf230_calibrated;
624  if (rf230_calibrated) {
625  PRINTA("\nRF230 calibrated!\n");
626  rf230_calibrated=0;
627  }
628 #endif
629 
630 #if TESTRTIMER
631 /* Timeout can be increased up to 8 seconds maximum.
632  * A one second cycle is convenient for triggering the various debug printouts.
633  * The triggers are staggered to avoid printing everything at once.
634  * My Jackdaw is 4% slow.
635  */
636  if (rtimerflag) {
637  rtimer_set(&rt, RTIMER_NOW()+ RTIMER_ARCH_SECOND*1UL, 1,(void *) rtimercycle, NULL);
638  rtimerflag=0;
639 
640 #if STAMPS
641 if ((rtime%STAMPS)==0) {
642  PRINTA("%us ",rtime);
643  if (rtime%STAMPS*10) PRINTA("\n");
644 }
645 #endif
646  rtime+=1;
647 
648 #if PINGS && UIP_CONF_IPV6_RPL
649 extern void raven_ping6(void);
650 if ((rtime%PINGS)==1) {
651  PRINTA("**Ping\n");
652  raven_ping6();
653 }
654 #endif
655 
656 #if ROUTES && UIP_CONF_IPV6_RPL
657 if ((rtime%ROUTES)==2) {
658 
660 
661  uint8_t i,j;
663 
664  PRINTA("\nAddresses [%u max]\n",UIP_DS6_ADDR_NB);
665  for (i=0;i<UIP_DS6_ADDR_NB;i++) {
666  if (uip_ds6_if.addr_list[i].isused) {
667  uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr);
668  PRINTA("\n");
669  }
670  }
671  PRINTA("\nNeighbors [%u max]\n",NBR_TABLE_MAX_NEIGHBORS);
672 
673  for(nbr = nbr_table_head(ds6_neighbors);
674  nbr != NULL;
675  nbr = nbr_table_next(ds6_neighbors, nbr)) {
676  uip_debug_ipaddr_print(&nbr->ipaddr);
677  PRINTA("\n");
678  j=0;
679  }
680  if (j) PRINTA(" <none>");
681  PRINTA("\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
682  uip_ds6_route_t *r;
683  for(r = uip_ds6_route_head();
684  r != NULL;
685  r = uip_ds6_route_next(r)) {
686  if(r->isused) {
687  uip_debug_ipaddr_print(&r->ipaddr);
688  PRINTA("/%u (via ", r->length);
689  uip_debug_ipaddr_print(uip_ds6_route_nexthop(r));
690  // if(r->state.lifetime < 600) {
691  PRINTA(") %lus\n", r->state.lifetime);
692  // } else {
693  // PRINTA(")\n");
694  // }
695  j=0;
696  }
697  }
698  if (j) PRINTA(" <none>");
699  PRINTA("\n---------\n");
700 }
701 #endif
702 
703 #if STACKMONITOR && CONFIG_STACK_MONITOR
704 if ((rtime%STACKMONITOR)==3) {
705  extern uint16_t __bss_end;
706  uint16_t p=(uint16_t)&__bss_end;
707  do {
708  if (*(uint16_t *)p != 0x4242) {
709  PRINTA("Never-used stack > %d bytes\n",p-(uint16_t)&__bss_end);
710  break;
711  }
712  p+=100;
713  } while (p<RAMEND-10);
714 }
715 #endif
716 
717  }
718 #endif /* TESTRTIMER */
719 
720 //Use with RF230BB DEBUGFLOW to show path through driver
721 #if RF230BB&&0
722 extern uint8_t debugflowsize,debugflow[]; //in rf230bb.c
723  if (debugflowsize) {
724  debugflow[debugflowsize]=0;
725  PRINTA("%s",debugflow);
726  debugflowsize=0;
727  }
728 #endif
729 
730  }
731  return 0;
732 }
This file contains the USB driver routines.
settings_status_t settings_get(settings_key_t key, uint8_t index, uint8_t *value, settings_length_t *value_size)
Fetches the value associated with the given key.
uip_len
The length of the packet in the uip_buf buffer.
Definition: tcp_loader.c:75
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
Definition: uip-nd6.c:129
#define SETTINGS_KEY_PAN_ADDR
Definition: settings.h:122
settings_status_t settings_add(settings_key_t key, const uint8_t *value, settings_length_t value_size)
Adds the given key-value pair to the end of the settings store.
MAC driver header file
#define RTIMER_NOW()
Get the current clock time.
Definition: rtimer.h:135
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
Header file for the managed memory allocator
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Definition: process.h:273
Settings Manager.
void random_init(unsigned short seed)
Seed the cc2538 random number generator.
Definition: random.c:41
This file contains radio driver code.
void clock_init(void)
Initialize the clock library.
Definition: clock.c:76
#define SETTINGS_KEY_EUI64
EUI64 Address, 8 bytes.
Definition: settings.h:117
Example glue code between the existing MAC code and the Contiki mac interface.
An entry in the nbr cache.
Definition: uip-ds6-nbr.h:70
#define SETTINGS_KEY_PAN_ID
Definition: settings.h:121
int process_run(void)
Run the system once - call poll handlers and process one event.
Definition: process.c:302
Interface structure (contains all the interface variables)
Definition: uip-ds6.h:242
This file manages the CDC task for the virtual COM port.
#define NULL
The null pointer.
static uip_ds6_nbr_t * nbr
Pointer to llao option in uip_buf.
Definition: uip-nd6.c:122
802.15.4 frame creation and parsing functions
#define PROCESS_YIELD()
Yield the currently running process.
Definition: process.h:164
void rs232_init(void)
Initialize the RS232 module.
Definition: rs232.c:51
int rtimer_set(struct rtimer *rtimer, rtimer_clock_t time, rtimer_clock_t duration, rtimer_callback_t func, void *ptr)
Post a real-time task.
Definition: rtimer.c:67
This file manages the RNDIS task.
void linkaddr_set_node_addr(linkaddr_t *t)
Set the address of the current node.
Definition: linkaddr.c:72
void watchdog_periodic(void)
Writes the WDT clear sequence.
Definition: watchdog.c:64
uint8_t settings_check(settings_key_t key, uint8_t index)
Checks to see if the given key exists.
#define CLOCK_SECOND
A second, measured in system clock time.
Definition: clock.h:82
This file manages the USB task either device/host or both.
#define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7)
Construct an IPv6 address from eight 16-bit words.
Definition: uip.h:970
#define SETTINGS_KEY_CHANNEL
Definition: settings.h:119
void process_start(struct process *p, process_data_t data)
Start a process.
Definition: process.c:99
int main(void)
This is main...
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.
Definition: uip-ds6.c:326
void rtimer_init(void)
Initialize the real-time scheduler.
Definition: rtimer.c:61
void watchdog_init(void)
Copyright (c) 2014, Analog Devices, Inc.
Definition: watchdog.c:42
static uint8_t output(const uip_lladdr_t *localdest)
Take an IP packet and format it to be sent on an 802.15.4 network using 6lowpan.
Definition: sicslowpan.c:1275
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
Definition: uip.c:118
void process_init(void)
Initialize the process module.
Definition: process.c:208
void ctimer_init(void)
Initialize the callback timer library.
Definition: ctimer.c:91
uip_ds6_netif_t uip_ds6_if
The single interface.
Definition: uip-ds6.c:71
Representation of a real-time task.
Definition: rtimer.h:86
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
Definition: watchdog.c:49
Header file for the 6lowpan implementation (RFC4944 and draft-hui-6lowpan-hc-01) ...
An entry in the routing table.
#define PROCESS_PAUSE()
Yield the process for a short while.
Definition: process.h:221
void mac_LowpanToEthernet(void)
Take a packet received over the 802.15.4 link, and send it out over ethernet, performing any translat...
uint64_t macLongAddr
Our own long address.
Definition: mac.c:145
#define SETTINGS_KEY_TXPOWER
Definition: settings.h:120
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120