contiki-avr-zigbit-main.c

00001 /*
00002  * Copyright (c) 2006, Technical University of Munich
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the Institute nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  *
00029  * This file is part of the Contiki operating system.
00030  *
00031  * @(#)$$
00032  */
00033 
00034 #include <avr/pgmspace.h>
00035 #include <avr/fuse.h>
00036 #include <avr/eeprom.h>
00037 #include <stdio.h>
00038 #include <string.h>
00039 
00040 #include "lib/mmem.h"
00041 #include "loader/symbols-def.h"
00042 #include "loader/symtab.h"
00043 
00044 #define ANNOUNCE_BOOT 0    //adds about 600 bytes to program size
00045 #define DEBUG 0
00046 #if DEBUG
00047 #define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
00048 #define PRINTSHORT(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
00049 #else
00050 #define PRINTF(...)
00051 #define PRINTSHORT(...)
00052 #endif
00053 
00054 #if RF230BB           //radio driver using contiki core mac
00055 #include "radio/rf230bb/rf230bb.h"
00056 #include "net/mac/frame802154.h"
00057 #include "net/mac/framer-802154.h"
00058 #include "net/sicslowpan.h"
00059 #else                 //radio driver using Atmel/Cisco 802.15.4'ish MAC
00060 #include <stdbool.h>
00061 #include "mac.h"
00062 #include "sicslowmac.h"
00063 #include "sicslowpan.h"
00064 #include "ieee-15-4-manager.h"
00065 #endif /*RF230BB*/
00066 
00067 #include "contiki.h"
00068 #include "contiki-net.h"
00069 #include "contiki-lib.h"
00070 
00071 #include "dev/rs232.h"
00072 #include "dev/serial-line.h"
00073 #include "dev/slip.h"
00074 
00075 #include "sicslowmac.h"
00076 
00077 FUSES =
00078         {
00079                 .low = (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0), // 0xe2,
00080                 .high = (FUSE_BOOTSZ0 /*& FUSE_BOOTSZ1*/ & FUSE_SPIEN & FUSE_JTAGEN), //0x9D,
00081                 .extended = 0xff,
00082         };
00083         
00084 #if RF230BB
00085 //PROCINIT(&etimer_process, &tcpip_process );
00086 #else
00087 PROCINIT(&etimer_process, &mac_process, &tcpip_process );
00088 #endif
00089 /* Put default MAC address in EEPROM */
00090 uint8_t mac_address[8] EEMEM = {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55};
00091 
00092 
00093 void
00094 init_lowlevel(void)
00095 {
00096 
00097   /* Second rs232 port for debugging */
00098   rs232_init(RS232_PORT_1, USART_BAUD_115200,
00099              USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
00100 
00101   /* Redirect stdout to second port */
00102   rs232_redirect_stdout(RS232_PORT_1);
00103   
00104   /* Clock */
00105   clock_init();
00106  
00107  /* rtimers needed for radio cycling */
00108   rtimer_init();
00109 
00110  /* Initialize process subsystem */
00111   process_init();
00112  /* etimers must be started before ctimer_init */
00113   process_start(&etimer_process, NULL);
00114   
00115 #if RF230BB
00116 
00117   ctimer_init();
00118   /* Start radio and radio receive process */
00119   NETSTACK_RADIO.init();
00120 
00121   /* Set addresses BEFORE starting tcpip process */
00122 
00123   rimeaddr_t addr;
00124   memset(&addr, 0, sizeof(rimeaddr_t));
00125   eeprom_read_block ((void *)&addr.u8,  &mac_address, 8);
00126  
00127 #if UIP_CONF_IPV6
00128   memcpy(&uip_lladdr.addr, &addr.u8, 8);
00129 #endif  
00130   rf230_set_pan_addr(IEEE802154_PANID, 0, (uint8_t *)&addr.u8);
00131 #ifdef CHANNEL_802_15_4
00132   rf230_set_channel(CHANNEL_802_15_4);
00133 #else
00134   rf230_set_channel(26);
00135 #endif
00136 
00137   rimeaddr_set_node_addr(&addr); 
00138 
00139   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]);
00140 
00141   /* Initialize stack protocols */
00142   queuebuf_init();
00143   NETSTACK_RDC.init();
00144   NETSTACK_MAC.init();
00145   NETSTACK_NETWORK.init();
00146 
00147 #if ANNOUNCE_BOOT
00148   printf_P(PSTR("%s %s, channel %u"),NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel());
00149   if (NETSTACK_RDC.channel_check_interval) {//function pointer is zero for sicslowmac
00150     unsigned short tmp;
00151     tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\
00152                                    NETSTACK_RDC.channel_check_interval());
00153     if (tmp<65535) printf_P(PSTR(", check rate %u Hz"),tmp);
00154   }
00155   printf_P(PSTR("\n"));
00156 #endif
00157 
00158 #if UIP_CONF_ROUTER
00159 #if ANNOUNCE_BOOT
00160   printf_P(PSTR("Routing Enabled\n"));
00161 #endif
00162   rime_init(rime_udp_init(NULL));
00163   uip_router_register(&rimeroute);
00164 #endif
00165 
00166   process_start(&tcpip_process, NULL);
00167 
00168 #else
00169 /* mac process must be started before tcpip process! */
00170   process_start(&mac_process, NULL);
00171   process_start(&tcpip_process, NULL);
00172 #endif /*RF230BB*/
00173 
00174 }
00175 
00176 
00177 int
00178 main(void)
00179 {
00180   //calibrate_rc_osc_32k(); //CO: Had to comment this out
00181 
00182   /* Initialize hardware */
00183   init_lowlevel();
00184 
00185   /* Register initial processes */
00186 //  procinit_init();
00187 
00188   /* Autostart processes */
00189   autostart_start(autostart_processes);
00190 
00191   printf_P(PSTR("\n********BOOTING CONTIKI*********\n"));
00192 
00193   printf_P(PSTR("System online.\n"));
00194 
00195   /* Main scheduler loop */
00196   while(1) {
00197     process_run();
00198   }
00199 
00200   return 0;
00201 }

Generated on Mon Apr 11 14:23:42 2011 for Contiki 2.5 by  doxygen 1.6.1