Contiki 2.6

contiki-rcb-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 
00039 #include "lib/mmem.h"
00040 #include "loader/symbols-def.h"
00041 #include "loader/symtab.h"
00042 
00043 #if RF230BB           //radio driver using contiki core mac
00044 #include "radio/rf230bb/rf230bb.h"
00045 #include "net/mac/frame802154.h"
00046 #include "net/mac/framer-802154.h"
00047 #include "net/sicslowpan.h"
00048 #else                 //radio driver using Atmel/Cisco 802.15.4'ish MAC
00049 #include <stdbool.h>
00050 #include "mac.h"
00051 #include "sicslowmac.h"
00052 #include "sicslowpan.h"
00053 #include "ieee-15-4-manager.h"
00054 #endif /*RF230BB*/
00055 
00056 #include "contiki.h"
00057 #include "contiki-net.h"
00058 #include "contiki-lib.h"
00059 
00060 #include "dev/rs232.h"
00061 #include "dev/serial-line.h"
00062 #include "dev/slip.h"
00063 
00064 
00065 #include "sicslowmac.h"
00066 
00067 FUSES =
00068         {
00069                 .low = 0xe2,
00070                 .high = 0x99,
00071                 .extended = 0xff,
00072         };
00073         
00074 PROCESS(rcb_leds, "RCB leds process");
00075 
00076 #if RF230BB
00077 PROCINIT(&etimer_process, &tcpip_process, &rcb_leds);
00078 #else
00079 PROCINIT(&etimer_process, &mac_process, &tcpip_process, &rcb_leds);
00080 #endif
00081 
00082 /* Put default MAC address in EEPROM */
00083 uint8_t mac_address[8] EEMEM = {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55};
00084 
00085 #define LED1 (1<<PE2)
00086 #define LED2 (1<<PE3)
00087 #define LED3 (1<<PE4)
00088 
00089 #define LEDOff(x) (PORTE |= (x))
00090 #define LEDOn(x) (PORTE &= ~(x))
00091 
00092 
00093 void
00094 init_lowlevel(void)
00095 {
00096   /* Second rs232 port for debugging */
00097   rs232_init(RS232_PORT_1, USART_BAUD_57600,
00098              USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
00099 
00100   /* Redirect stdout to second port */
00101   rs232_redirect_stdout(RS232_PORT_1);
00102   
00103   DDRE |= LED1 | LED2 | LED3;
00104 }
00105 
00106 
00107 static struct etimer et;
00108 PROCESS_THREAD(rcb_leds, ev, data)
00109 {
00110   uint8_t error;
00111 
00112   PROCESS_BEGIN();
00113   
00114   if((error = icmp6_new(NULL)) == 0) {
00115     while(1) {
00116       PROCESS_YIELD();
00117       
00118 #if UIP_CONF_IPV6         
00119           if (ev == ICMP6_ECHO_REQUEST) {
00120 #else
00121                 if (1) {
00122 #endif        
00123                 LEDOn(LED2);
00124                 etimer_set(&et, CLOCK_SECOND/10);
00125           } else {
00126                 LEDOff(LED2);
00127           }
00128     }
00129   }
00130   PROCESS_END();
00131 }
00132 
00133 
00134 int
00135 main(void)
00136 {
00137   //calibrate_rc_osc_32k(); //CO: Had to comment this out
00138 
00139   /* Initialize hardware */
00140   init_lowlevel();
00141 
00142   /* Clock */
00143   clock_init();
00144 
00145   LEDOff(LED1 | LED2);
00146 
00147   /* Process subsystem */
00148   process_init();
00149 
00150   /* Register initial processes */
00151   procinit_init();
00152 
00153   /* Autostart processes */
00154   autostart_start(autostart_processes);
00155   
00156   printf_P(PSTR("\n********BOOTING CONTIKI*********\n"));
00157 
00158   printf_P(PSTR("System online.\n"));
00159 
00160   /* Main scheduler loop */
00161   while(1) {
00162     process_run();
00163   }
00164 
00165   return 0;
00166 }