Contiki 3.x
contiki-main.c
1 /*
2  * Copyright (c) 2006, Swedish Institute of Computer Science.
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  * Author: Oliver Schmidt <ol.sc@web.de>
32  *
33  */
34 
35 #include "contiki-net.h"
36 #include "ctk/ctk.h"
37 #include "sys/log.h"
38 #include "lib/config.h"
39 #include "net/ethernet-drv.h"
40 
41 #if WITH_GUI
42 #define CTK_PROCESS &ctk_process,
43 #else /* WITH_GUI */
44 #define CTK_PROCESS
45 #endif /* WITH_GUI */
46 
47 #if WITH_DNS
48 #define RESOLV_PROCESS ,&resolv_process
49 #else /* WITH_DNS */
50 #define RESOLV_PROCESS
51 #endif /* WITH_DNS */
52 
53 PROCINIT(&etimer_process,
54  CTK_PROCESS
55  &tcpip_process
56  RESOLV_PROCESS);
57 
58 static struct ethernet_config *ethernet_config;
59 
60 void clock_update(void);
61 
62 /*-----------------------------------------------------------------------------------*/
63 #if WITH_ARGS
64 
65 int contiki_argc;
66 char **contiki_argv;
67 
68 void
69 main(int argc, char **argv)
70 {
71  contiki_argc = argc;
72  contiki_argv = argv;
73 
74 #else /* WITH_ARGS */
75 
76 void
77 main(void)
78 {
79 
80 #endif /* WITH_ARGS */
81 
82 #if WITH_REBOOT
83  rebootafterexit();
84 #endif /* WITH_REBOOT */
85 
86  videomode(VIDEOMODE_80COL);
87 
88  process_init();
89 
90 #if 1
91  ethernet_config = config_read("contiki.cfg");
92 #else
93  {
94  static struct ethernet_config config = {0xC0B0, "cs8900a.eth"};
95  uip_ipaddr_t addr;
96 
97  uip_ipaddr(&addr, 192,168,0,128);
98  uip_sethostaddr(&addr);
99 
100  uip_ipaddr(&addr, 255,255,255,0);
101  uip_setnetmask(&addr);
102 
103  uip_ipaddr(&addr, 192,168,0,1);
104  uip_setdraddr(&addr);
105 
106  uip_ipaddr(&addr, 192,168,0,1);
107  resolv_conf(&addr);
108 
109  ethernet_config = &config;
110  }
111 #endif
112 
113  procinit_init();
114 
115  process_start((struct process *)&ethernet_process, (void *)ethernet_config);
116 
117  autostart_start(autostart_processes);
118 
119  log_message("Contiki up and running ...", "");
120 
121  while(1) {
122 
123  process_run();
124 
126 
127  clock_update();
128  }
129 }
130 /*-----------------------------------------------------------------------------------*/
#define uip_sethostaddr(addr)
Set the IP address of this host.
Definition: uip.h:195
int main(void)
This is main...
Definition: ethconfig.c:49
void process_init(void)
Initialize the process module.
Definition: process.c:208
#define uip_setdraddr(addr)
Set the default router&#39;s IP address.
Definition: uip.h:227
void etimer_request_poll(void)
Make the event timer aware that the clock has changed.
Definition: etimer.c:145
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
#define uip_ipaddr(addr, addr0, addr1, addr2, addr3)
Construct an IP address from four bytes.
Definition: uip.h:955
#define uip_setnetmask(addr)
Set the netmask.
Definition: uip.h:239
CTK header file.