Contiki 2.5
contiki-micaz-main.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, University of Colombo School of Computing
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
16  *
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
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  * @(#)$$
32  */
33 
34 
35 /**
36  * \file
37  * Main file of the MICAz port.
38  *
39  * \author
40  * Kasun Hewage <kasun.ch@gmail.com>
41  */
42 
43 #include <stdio.h>
44 #include <avr/pgmspace.h>
45 
46 #include "contiki.h"
47 #include "contiki-lib.h"
48 #include "net/rime.h"
49 #include "dev/leds.h"
50 #include "dev/rs232.h"
51 #include "dev/watchdog.h"
52 #include "dev/slip.h"
53 
54 #include "init-net.h"
55 #include "dev/ds2401.h"
56 #include "node-id.h"
57 
58 /*---------------------------------------------------------------------------*/
59 void
60 init_usart(void)
61 {
62  /* First rs232 port for debugging */
63  rs232_init(RS232_PORT_0, USART_BAUD_115200,
64  USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
65 
66 #if WITH_UIP || WITH_UIP6
67  slip_arch_init(USART_BAUD_115200);
68 #else
69  rs232_redirect_stdout(RS232_PORT_0);
70 #endif /* WITH_UIP */
71 
72 }
73 /*---------------------------------------------------------------------------*/
74 int
75 main(void)
76 {
77 
78  leds_init();
79 
80  leds_on(LEDS_RED);
81 
82  /* Initialize USART */
83  init_usart();
84 
85  /* Clock */
86  clock_init();
87 
88  leds_on(LEDS_GREEN);
89 
90  ds2401_init();
91 
92  node_id_restore();
93 
94  random_init(ds2401_id[0] + node_id);
95 
96  rtimer_init();
97 
98  /* Process subsystem */
99  process_init();
100 
101  process_start(&etimer_process, NULL);
102 
103  ctimer_init();
104 
105  leds_on(LEDS_YELLOW);
106 
107  init_net();
108 
109  printf_P(PSTR(CONTIKI_VERSION_STRING " started. Node id %u\n"), node_id);
110 
111  leds_off(LEDS_ALL);
112 
113  /* Autostart processes */
114  autostart_start(autostart_processes);
115 
116  /* Main scheduler loop */
117  do {
118 
119  process_run();
120 
121  }while(1);
122 
123  return 0;
124 }