2 * Copyright (c) 2006, Technical University of Munich
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
29 * This file is part of the Contiki operating system.
36 * Sample Contiki kernel for STK 501 development board
39 * Simon Barner <barner@in.tum.de
42 #include <avr/pgmspace.h>
44 #include <avr/eeprom.h>
45 #include <util/delay.h>
49 /* Set ANNOUNCE to send boot messages to USB serial port */
52 #if RF230BB //radio driver using contiki core mac
53 #include "radio/rf230bb/rf230bb.h"
54 #include "net/mac/frame802154.h"
55 #include "net/mac/framer-802154.h"
56 //#include "net/mac/framer-nullmac.h"
57 //#include "net/mac/framer.h"
58 #include "net/sicslowpan.h"
59 #include "net/uip-netif.h"
60 #include "net/mac/lpp.h"
61 //#include "dev/xmem.h"
64 #define MAC_DRIVER nullmac_driver
65 #endif /* WITH_NULLMAC */
68 #ifdef MAC_CONF_DRIVER
69 #define MAC_DRIVER MAC_CONF_DRIVER
71 #define MAC_DRIVER sicslowmac_driver
72 //#define MAC_DRIVER cxmac_driver
73 #endif /* MAC_CONF_DRIVER */
74 #endif /* MAC_DRIVER */
76 #include "net/mac/sicslowmac.h"
77 #include "net/mac/cxmac.h"
78 #else //radio driver using Atmel/Cisco 802.15.4'ish MAC
81 #include "sicslowmac.h"
82 #include "sicslowpan.h"
83 #include "ieee-15-4-manager.h"
87 #include "loader/symbols-def.h"
88 #include "loader/symtab.h"
91 #include "contiki-net.h"
92 #include "contiki-lib.h"
93 #include "contiki-raven.h"
96 #include "serial/cdc_task.h"
97 #include "rndis/rndis_task.h"
98 #include "storage/storage_task.h"
101 //#warning Experimental RF230BB radio selected
102 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
103 extern int rf230_interrupt_flag
;
104 extern uint8_t rf230processflag
;
107 #if 1 //dummy tcpip process not needed?
108 PROCESS(tcpip_process
, "tcpip dummy");
109 PROCESS_THREAD(tcpip_process
, ev
, data
)
115 tcpip_ipv6_output(void)
117 printf("tcpipipv6output");
122 /*----------------------Configuration of the .elf file---------------------*/
123 typedef struct {unsigned char B2
;unsigned char B1
;unsigned char B0
;} __signature_t
;
124 #define SIGNATURE __signature_t __signature __attribute__((section (".signature")))
126 /* Older AVR-GCCs may not define the SIGNATURE_n bytes so use explicit values */
127 .B2
= 0x82,//SIGNATURE_2, //AT90USB128x
128 .B1
= 0x97,//SIGNATURE_1, //128KB flash
129 .B0
= 0x1E,//SIGNATURE_0, //Atmel
131 FUSES
={.low
= 0xde, .high
= 0x99, .extended
= 0xff,};
133 /* Put default MAC address in EEPROM */
134 uint8_t mac_address
[8] EEMEM
= {0x02, 0x12, 0x13, 0xff, 0xfe, 0x14, 0x15, 0x16};
135 //uint8_t EEMEM mac_address[8]; //The raven webserver uses this EEMEM allocation
136 //uint8_t EEMEM server_name[16];
137 //uint8_t EEMEM domain_name[30];
140 rimeaddr_t macLongAddr
;
143 //uint8_t rtimerworks;
148 uint32_t firsttime
=0;
154 * GCC depends on register r1 set to 0.
156 asm volatile ("clr r1");
158 /* Initialize hardware */
164 /* rtimer init needed for low power protocols */
167 /* Process subsystem. */
170 /* etimer process must be started before ctimer init */
171 process_start(&etimer_process
, NULL
);
176 /* Start radio and radio receive process */
177 /* Note this starts RF230 process, so must be done after process_init */
180 /* Set addresses BEFORE starting tcpip process */
182 memset(&addr
, 0, sizeof(rimeaddr_t
));
183 AVR_ENTER_CRITICAL_REGION();
184 eeprom_read_block ((void *)&addr
.u8
, &mac_address
, 8);
185 AVR_LEAVE_CRITICAL_REGION();
186 //RNDIS needs the mac address in reverse byte order
187 macLongAddr
.u8
[0]=addr
.u8
[7];
188 macLongAddr
.u8
[1]=addr
.u8
[6];
189 macLongAddr
.u8
[2]=addr
.u8
[5];
190 macLongAddr
.u8
[3]=addr
.u8
[4];
191 macLongAddr
.u8
[4]=addr
.u8
[3];
192 macLongAddr
.u8
[5]=addr
.u8
[2];
193 macLongAddr
.u8
[6]=addr
.u8
[1];
194 macLongAddr
.u8
[7]=addr
.u8
[0];
196 memcpy(&uip_lladdr
.addr
, &addr
.u8
, 8);
197 rf230_set_pan_addr(IEEE802154_PANID
, 0, (uint8_t *)&addr
.u8
);
199 rf230_set_channel(24);
201 rimeaddr_set_node_addr(&addr
);
203 // PRINTF("MAC address %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]);
205 framer_set(&framer_802154
);
207 /* Setup X-MAC for 802.15.4 */
211 NETSTACK_NETWORK
.init();
212 // PRINTF("Driver: %s, Channel: %u\n", sicslowpan_mac->name, rf230_get_channel());
215 rime_init(rime_udp_init(NULL
));
216 uip_router_register(&rimeroute
);
223 process_start(&tcpip_process
, NULL
);
225 /* The order of starting these is important! */
226 process_start(&mac_process
, NULL
);
227 process_start(&tcpip_process
, NULL
);
232 process_start(&usb_process
, NULL
);
233 process_start(&cdc_process
, NULL
);
234 process_start(&rndis_process
, NULL
);
235 process_start(&storage_process
, NULL
);
240 /* Main scheduler loop */
250 /* Allow USB CDC to keep up with printfs */
252 if (firsttime
++==36000){
253 printf_P(PSTR("\n\n\n********BOOTING CONTIKI*********\n\r"));
255 } else if (firsttime
==44000) {
256 printf("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]);
258 } else if (firsttime
==52000) {
259 printf("Driver: %s, Channel: %u\n\r", sicslowpan_mac
->name
, rf230_get_channel());
261 } else if (firsttime
==60000) {
262 printf_P(PSTR("System online.\n\r"));
266 if (rf230processflag
) {
267 printf("**RF230 process flag %u\n\r",rf230processflag
);
270 if (rf230_interrupt_flag
) {
271 // if (rf230_interrupt_flag!=11) {
272 printf("**RF230 Interrupt %u\n\r",rf230_interrupt_flag
);
274 rf230_interrupt_flag
=0;
277 #endif /* ANNOUNCE */