Contiki 3.x
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/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 "sys/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  rs232_redirect_stdout(RS232_PORT_0);
69 #else
70  rs232_redirect_stdout(RS232_PORT_0);
71 #endif /* WITH_UIP */
72 
73 }
74 /*---------------------------------------------------------------------------*/
75 int
76 main(void)
77 {
78 
79  leds_init();
80 
81  leds_on(LEDS_RED);
82 
83  /* Initialize USART */
84  init_usart();
85 
86  /* Clock */
87  clock_init();
88 
89  leds_on(LEDS_GREEN);
90 
91  ds2401_init();
92 
93  node_id_restore();
94 
95  random_init(ds2401_id[0] + node_id);
96 
97  rtimer_init();
98 
99  /* Process subsystem */
100  process_init();
101 
102  process_start(&etimer_process, NULL);
103 
104  ctimer_init();
105 
106  leds_on(LEDS_YELLOW);
107 
108  init_net();
109 
110  printf_P(PSTR(CONTIKI_VERSION_STRING " started. Node id %u\n"), node_id);
111 
112  leds_off(LEDS_ALL);
113 
114  /* Autostart processes */
115  autostart_start(autostart_processes);
116 
117  /* Main scheduler loop */
118  do {
119 
120  process_run();
121 
122  }while(1);
123 
124  return 0;
125 }
void rs232_init(void)
Initialize the RS232 module.
Definition: rs232.c:50
#define LEDS_RED
LED1 (Red) -&gt; PC0.
Definition: board.h:89
void rtimer_init(void)
Initialize the real-time scheduler.
Definition: rtimer.c:61
#define NULL
The null pointer.
void clock_init(void)
Initialize the clock library.
Definition: clock.c:76
int main(void)
This is main...
Definition: ethconfig.c:49
void process_init(void)
Initialize the process module.
Definition: process.c:208
Header file for the Rime stack
#define LEDS_YELLOW
LED2 (Yellow) -&gt; PC1.
Definition: board.h:80
#define LEDS_GREEN
LED3 (Green) -&gt; PC2.
Definition: board.h:81
void random_init(unsigned short seed)
Seed the cc2430 random number generator.
Definition: random.c:41
void ctimer_init(void)
Initialize the callback timer library.
Definition: ctimer.c:91
void process_start(struct process *p, process_data_t data)
Start a process.
Definition: process.c:99
int process_run(void)
Run the system once - call poll handlers and process one event.
Definition: process.c:302
Network initialization for the MICAz port.