Contiki 2.5
contiki-rcb-main.c
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 #include <avr/pgmspace.h>
35 #include <avr/fuse.h>
36 #include <avr/eeprom.h>
37 #include <stdio.h>
38 
39 #include "lib/mmem.h"
40 #include "loader/symbols-def.h"
41 #include "loader/symtab.h"
42 
43 #if RF230BB //radio driver using contiki core mac
44 #include "radio/rf230bb/rf230bb.h"
45 #include "net/mac/frame802154.h"
46 #include "net/mac/framer-802154.h"
47 #include "net/sicslowpan.h"
48 #else //radio driver using Atmel/Cisco 802.15.4'ish MAC
49 #include <stdbool.h>
50 #include "mac.h"
51 #include "sicslowmac.h"
52 #include "sicslowpan.h"
53 #include "ieee-15-4-manager.h"
54 #endif /*RF230BB*/
55 
56 #include "contiki.h"
57 #include "contiki-net.h"
58 #include "contiki-lib.h"
59 
60 #include "dev/rs232.h"
61 #include "dev/serial-line.h"
62 #include "dev/slip.h"
63 
64 
65 #include "sicslowmac.h"
66 
67 FUSES =
68  {
69  .low = 0xe2,
70  .high = 0x99,
71  .extended = 0xff,
72  };
73 
74 PROCESS(rcb_leds, "RCB leds process");
75 
76 #if RF230BB
77 PROCINIT(&etimer_process, &tcpip_process, &rcb_leds);
78 #else
79 PROCINIT(&etimer_process, &mac_process, &tcpip_process, &rcb_leds);
80 #endif
81 
82 /* Put default MAC address in EEPROM */
83 uint8_t mac_address[8] EEMEM = {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55};
84 
85 #define LED1 (1<<PE2)
86 #define LED2 (1<<PE3)
87 #define LED3 (1<<PE4)
88 
89 #define LEDOff(x) (PORTE |= (x))
90 #define LEDOn(x) (PORTE &= ~(x))
91 
92 
93 void
94 init_lowlevel(void)
95 {
96  /* Second rs232 port for debugging */
97  rs232_init(RS232_PORT_1, USART_BAUD_57600,
98  USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
99 
100  /* Redirect stdout to second port */
101  rs232_redirect_stdout(RS232_PORT_1);
102 
103  DDRE |= LED1 | LED2 | LED3;
104 }
105 
106 
107 static struct etimer et;
108 PROCESS_THREAD(rcb_leds, ev, data)
109 {
110  u8_t error;
111 
112  PROCESS_BEGIN();
113 
114  if((error = icmp6_new(NULL)) == 0) {
115  while(1) {
116  PROCESS_YIELD();
117 
118 #if UIP_CONF_IPV6
119  if (ev == ICMP6_ECHO_REQUEST) {
120 #else
121  if (1) {
122 #endif
123  LEDOn(LED2);
124  etimer_set(&et, CLOCK_SECOND/10);
125  } else {
126  LEDOff(LED2);
127  }
128  }
129  }
130  PROCESS_END();
131 }
132 
133 
134 int
135 main(void)
136 {
137  //calibrate_rc_osc_32k(); //CO: Had to comment this out
138 
139  /* Initialize hardware */
140  init_lowlevel();
141 
142  /* Clock */
143  clock_init();
144 
145  LEDOff(LED1 | LED2);
146 
147  /* Process subsystem */
148  process_init();
149 
150  /* Register initial processes */
151  procinit_init();
152 
153  /* Autostart processes */
154  autostart_start(autostart_processes);
155 
156  printf_P(PSTR("\n********BOOTING CONTIKI*********\n"));
157 
158  printf_P(PSTR("System online.\n"));
159 
160  /* Main scheduler loop */
161  while(1) {
162  process_run();
163  }
164 
165  return 0;
166 }