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 <string.h>
36 
37 #include "contiki-net.h"
38 #include "ctk/ctk.h"
39 #include "sys/log.h"
40 #include "lib/config.h"
41 #include "net/ethernet-drv.h"
42 
43 #if WITH_GUI
44 #define CTK_PROCESS &ctk_process,
45 #else /* WITH_GUI */
46 #define CTK_PROCESS
47 #endif /* WITH_GUI */
48 
49 #if WITH_DNS
50 #define RESOLV_PROCESS ,&resolv_process
51 #else /* WITH_DNS */
52 #define RESOLV_PROCESS
53 #endif /* WITH_DNS */
54 
55 PROCINIT(&etimer_process,
56  CTK_PROCESS
57  &tcpip_process
58  RESOLV_PROCESS);
59 
60 static struct ethernet_config *ethernet_config;
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  videomode(VIDEOMODE_80COL);
83 
84  process_init();
85 
86 #if 1
87  ethernet_config = config_read("contiki.cfg");
88 #else
89  {
90  static struct ethernet_config config = {0xDE08, "cs8900a.eth"};
91  uip_ipaddr_t addr;
92 
93  uip_ipaddr(&addr, 192,168,0,128);
94  uip_sethostaddr(&addr);
95 
96  uip_ipaddr(&addr, 255,255,255,0);
97  uip_setnetmask(&addr);
98 
99  uip_ipaddr(&addr, 192,168,0,1);
100  uip_setdraddr(&addr);
101 
102  uip_ipaddr(&addr, 192,168,0,1);
103  resolv_conf(&addr);
104 
105  ethernet_config = &config;
106  }
107 #endif
108 
109 #if (WITH_GUI && WITH_MOUSE)
110  {
111  static const uint8_t mouse_sprite[64] = {
112  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
113  0x00, 0x0F, 0xE0, 0x00, 0x0F, 0xC0, 0x00, 0x0F,
114  0x80, 0x00, 0x0F, 0xC0, 0x00, 0x0D, 0xE0, 0x00,
115  0x08, 0xF0, 0x00, 0x00, 0x78, 0x00, 0x00, 0x3C,
116  0x00, 0x00, 0x1E, 0x00, 0x00, 0x0F, 0x00, 0x00,
117  0x07, 0x80, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00,
118  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
119  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
120 
121  memcpy((void*)0x0E00, mouse_sprite, sizeof(mouse_sprite));
122  *(uint8_t*)0x07F8 = 0x0E00 / 64;
123  VIC.spr0_color = COLOR_WHITE;
124  }
125 #endif /* WITH_GUI && WITH_MOUSE */
126 
127  procinit_init();
128 
129  process_start((struct process *)&ethernet_process, (void *)ethernet_config);
130 
131  autostart_start(autostart_processes);
132 
133  log_message("Contiki up and running ...", "");
134 
135  while(1) {
136 
137  process_run();
138 
140  }
141 }
142 /*-----------------------------------------------------------------------------------*/
#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.