Contiki 2.6

contiki-iris-main.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009, University of Colombo School of Computing
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 
00035 /**
00036  * \file
00037  *         Main file of the MICAz port.
00038  *
00039  * \author
00040  *         Kasun Hewage <kasun.ch@gmail.com>
00041  */
00042 
00043 #include <stdio.h>
00044 #include <avr/pgmspace.h>
00045 
00046 #include "contiki.h"
00047 #include "contiki-lib.h"
00048 #include "net/rime.h"
00049 #include "dev/leds.h"
00050 #include "dev/rs232.h"
00051 #include "dev/watchdog.h"
00052 #include "dev/slip.h"
00053 
00054 #include "init-net.h"
00055 #include "dev/ds2401.h"
00056 #include "node-id.h"
00057 
00058 /*---------------------------------------------------------------------------*/
00059 void
00060 init_usart(void)
00061 {
00062   /* First rs232 port for debugging */
00063   rs232_init(RS232_PORT_0, USART_BAUD_115200,
00064              USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
00065 
00066 #if WITH_UIP || WITH_UIP6
00067   slip_arch_init(USART_BAUD_115200);
00068 #else
00069   rs232_redirect_stdout(RS232_PORT_0);
00070 #endif /* WITH_UIP */
00071 
00072 }
00073 /*---------------------------------------------------------------------------*/
00074 int
00075 main(void)
00076 {
00077 
00078   leds_init();
00079 
00080   leds_on(LEDS_RED);
00081 
00082   /* Initialize USART */
00083   init_usart();
00084   
00085   /* Clock */
00086   clock_init();
00087 
00088   leds_on(LEDS_GREEN);
00089 
00090   ds2401_init();
00091   
00092   node_id_restore();
00093 
00094   random_init(ds2401_id[0] + node_id);
00095 
00096   rtimer_init();
00097 
00098   /* Process subsystem */
00099   process_init();
00100 
00101   process_start(&etimer_process, NULL);
00102 
00103   ctimer_init();
00104 
00105   leds_on(LEDS_YELLOW);
00106   
00107   init_net();
00108   
00109   printf_P(PSTR(CONTIKI_VERSION_STRING " started. Node id %u\n"), node_id);
00110 
00111   leds_off(LEDS_ALL);
00112 
00113   /* Autostart processes */
00114   autostart_start(autostart_processes);
00115 
00116   mmem_init();
00117   /* Main scheduler loop */
00118   do {
00119 
00120     process_run();
00121 
00122   }while(1);
00123 
00124   return 0;
00125 }