contiki-main.c

00001 /*
00002  * Copyright (c) 2002, Adam Dunkels.
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
00011  *    copyright notice, this list of conditions and the following
00012  *    disclaimer in the documentation and/or other materials provided
00013  *    with the distribution.
00014  * 3. The name of the author may not be used to endorse or promote
00015  *    products derived from this software without specific prior
00016  *    written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
00019  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00020  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00022  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00023  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00024  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00027  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  * This file is part of the Contiki OS
00031  *
00032  * $Id: contiki-main.c,v 1.14 2011/01/21 14:19:57 nvt-se Exp $
00033  *
00034  */
00035 
00036 #include <stdio.h>
00037 #include <unistd.h>
00038 #include <sys/select.h>
00039 
00040 #include "contiki.h"
00041 #include "net/netstack.h"
00042 
00043 #include "dev/serial-line.h"
00044 
00045 #include "net/uip.h"
00046 
00047 #include "dev/button-sensor.h"
00048 #include "dev/pir-sensor.h"
00049 #include "dev/vib-sensor.h"
00050 
00051 PROCINIT(&etimer_process, &tcpip_process);
00052 
00053 SENSORS(&pir_sensor, &vib_sensor, &button_sensor);
00054 
00055 /*---------------------------------------------------------------------------*/
00056 int
00057 main(void)
00058 {
00059   printf("Starting Contiki\n");
00060   process_init();
00061   ctimer_init();
00062 
00063   netstack_init();
00064   
00065   procinit_init();
00066 
00067   serial_line_init();
00068   
00069   autostart_start(autostart_processes);
00070 
00071   
00072   /* Make standard output unbuffered. */
00073   setvbuf(stdout, (char *)NULL, _IONBF, 0);
00074   
00075   while(1) {
00076     fd_set fds;
00077     int n;
00078     struct timeval tv;
00079     
00080     n = process_run();
00081 
00082     tv.tv_sec = 0;
00083     tv.tv_usec = 1;
00084 
00085     FD_ZERO(&fds);
00086     FD_SET(STDIN_FILENO, &fds);
00087     if(select(1, &fds, NULL, NULL, &tv) < 0) {
00088       perror("select");
00089     } else if(FD_ISSET(STDIN_FILENO, &fds)) {
00090       char c;
00091       if(read(STDIN_FILENO, &c, 1) > 0) {
00092         serial_line_input_byte(c);
00093       }
00094     }
00095     
00096     etimer_request_poll();
00097   }
00098   
00099   return 0;
00100 }
00101 /*---------------------------------------------------------------------------*/
00102 void
00103 log_message(char *m1, char *m2)
00104 {
00105   printf("%s%s\n", m1, m2);
00106 }
00107 /*---------------------------------------------------------------------------*/
00108 void
00109 uip_log(char *m)
00110 {
00111   printf("%s\n", m);
00112 }
00113 /*---------------------------------------------------------------------------*/

Generated on Mon Apr 11 14:23:41 2011 for Contiki 2.5 by  doxygen 1.6.1