Contiki 2.6

contiki-micaz-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     rs232_redirect_stdout(RS232_PORT_0);
00069 #else
00070   rs232_redirect_stdout(RS232_PORT_0);
00071 #endif /* WITH_UIP */
00072 
00073 }
00074 /*---------------------------------------------------------------------------*/
00075 int
00076 main(void)
00077 {
00078 
00079   leds_init();
00080 
00081   leds_on(LEDS_RED);
00082 
00083   /* Initialize USART */
00084   init_usart();
00085   
00086   /* Clock */
00087   clock_init();
00088 
00089   leds_on(LEDS_GREEN);
00090 
00091   ds2401_init();
00092   
00093   node_id_restore();
00094 
00095   random_init(ds2401_id[0] + node_id);
00096 
00097   rtimer_init();
00098 
00099   /* Process subsystem */
00100   process_init();
00101 
00102   process_start(&etimer_process, NULL);
00103 
00104   ctimer_init();
00105 
00106   leds_on(LEDS_YELLOW);
00107 
00108   init_net();
00109   
00110   printf_P(PSTR(CONTIKI_VERSION_STRING " started. Node id %u\n"), node_id);
00111 
00112   leds_off(LEDS_ALL);
00113 
00114   /* Autostart processes */
00115   autostart_start(autostart_processes);
00116 
00117   /* Main scheduler loop */
00118   do {
00119 
00120     process_run();
00121 
00122   }while(1);
00123 
00124   return 0;
00125 }