Contiki 2.5
contiki-main.c
1 /*
2  * Copyright (c) 2002, Adam Dunkels.
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
11  * copyright notice, this list of conditions and the following
12  * disclaimer in the documentation and/or other materials provided
13  * with the distribution.
14  * 3. The name of the author may not be used to endorse or promote
15  * products derived from this software without specific prior
16  * written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * This file is part of the Contiki OS
31  *
32  * $Id: contiki-main.c,v 1.14 2011/01/21 14:19:57 nvt-se Exp $
33  *
34  */
35 
36 #include <stdio.h>
37 #include <unistd.h>
38 #include <sys/select.h>
39 
40 #include "contiki.h"
41 #include "net/netstack.h"
42 
43 #include "dev/serial-line.h"
44 
45 #include "net/uip.h"
46 
47 #include "dev/button-sensor.h"
48 #include "dev/pir-sensor.h"
49 #include "dev/vib-sensor.h"
50 
51 PROCINIT(&etimer_process, &tcpip_process);
52 
53 SENSORS(&pir_sensor, &vib_sensor, &button_sensor);
54 
55 /*---------------------------------------------------------------------------*/
56 int
57 main(void)
58 {
59  printf("Starting Contiki\n");
60  process_init();
61  ctimer_init();
62 
63  netstack_init();
64 
65  procinit_init();
66 
67  serial_line_init();
68 
69  autostart_start(autostart_processes);
70 
71 
72  /* Make standard output unbuffered. */
73  setvbuf(stdout, (char *)NULL, _IONBF, 0);
74 
75  while(1) {
76  fd_set fds;
77  int n;
78  struct timeval tv;
79 
80  n = process_run();
81 
82  tv.tv_sec = 0;
83  tv.tv_usec = 1;
84 
85  FD_ZERO(&fds);
86  FD_SET(STDIN_FILENO, &fds);
87  if(select(1, &fds, NULL, NULL, &tv) < 0) {
88  perror("select");
89  } else if(FD_ISSET(STDIN_FILENO, &fds)) {
90  char c;
91  if(read(STDIN_FILENO, &c, 1) > 0) {
92  serial_line_input_byte(c);
93  }
94  }
95 
97  }
98 
99  return 0;
100 }
101 /*---------------------------------------------------------------------------*/
102 void
103 log_message(char *m1, char *m2)
104 {
105  printf("%s%s\n", m1, m2);
106 }
107 /*---------------------------------------------------------------------------*/
108 void
109 uip_log(char *m)
110 {
111  printf("%s\n", m);
112 }
113 /*---------------------------------------------------------------------------*/