blob: 0332ee3669ce1145d7c48076f91bee80ebddc635 [file] [log] [blame]
adamdunkelsa4ed8472003-04-10 07:25:26 +00001/*
oliverschmidt9e652ff2004-07-11 12:24:52 +00002 * Copyright (c) 2004, Adam Dunkels.
adamdunkelsa4ed8472003-04-10 07:25:26 +00003 * 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. All advertising materials mentioning features or use of this
15 * software must display the following acknowledgement:
16 * This product includes software developed by Adam Dunkels.
17 * 4. The name of the author may not be used to endorse or promote
18 * products derived from this software without specific prior
19 * written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 * This file is part of the Contiki desktop environment
34 *
oliverschmidte31aaa92006-06-28 23:10:43 +000035 * $Id: main.c,v 1.18 2006/06/28 23:10:43 oliverschmidt Exp $
adamdunkelsa4ed8472003-04-10 07:25:26 +000036 *
37 */
38
oliverschmidt33d8fad2006-05-18 16:20:08 +000039#include <string.h>
40
adamdunkelsa4ed8472003-04-10 07:25:26 +000041#include "ctk.h"
42#include "ctk-draw.h"
oliverschmidt9e652ff2004-07-11 12:24:52 +000043#include "ek.h"
adamdunkelsa4ed8472003-04-10 07:25:26 +000044
adamdunkelsa4ed8472003-04-10 07:25:26 +000045#include "program-handler.h"
46
oliverschmidt3cf3d302004-06-08 20:28:33 +000047#include "uip.h"
48#include "uip_arp.h"
49
50#include "resolv.h"
51
oliverschmidt63e299e2005-05-06 22:38:17 +000052#include "www-dsc.h"
oliverschmidt7ca33552005-05-05 00:14:16 +000053#include "email-dsc.h"
oliverschmidt18f390a2005-04-19 23:00:00 +000054#include "ftp-dsc.h"
oliverschmidt63e299e2005-05-06 22:38:17 +000055#include "directory-dsc.h"
oliverschmidt3cf3d302004-06-08 20:28:33 +000056
oliverschmidt9e652ff2004-07-11 12:24:52 +000057#include "clock.h"
oliverschmidt274cb0e2005-05-16 21:18:47 +000058#include "clock-arch.h"
oliverschmidt2fa33232005-01-26 21:33:29 +000059
oliverschmidtba6f5902006-05-29 21:07:53 +000060#if CTK_CONF_MOUSE_SUPPORT
61#define TICK_COUNT 2800
62#else
63#define TICK_COUNT 4200
64#endif
65
oliverschmidt2fa33232005-01-26 21:33:29 +000066unsigned char lanslot;
oliverschmidte31aaa92006-06-28 23:10:43 +000067unsigned char prefixok;
oliverschmidt2fa33232005-01-26 21:33:29 +000068
oliverschmidtd9f33142005-02-17 22:45:02 +000069#pragma bssseg(push, "UIPBUF");
70u8_t uip_buf[UIP_BUFSIZE + 2];
71#pragma bssseg(pop);
72
adamdunkelsa4ed8472003-04-10 07:25:26 +000073/*-----------------------------------------------------------------------------------*/
oliverschmidt9e652ff2004-07-11 12:24:52 +000074unsigned char
75uip_fw_forward(void)
adamdunkelsa4ed8472003-04-10 07:25:26 +000076{
oliverschmidt9e652ff2004-07-11 12:24:52 +000077 return 0;
78}
79/*-----------------------------------------------------------------------------------*/
80void
81uip_fw_periodic(void)
82{
83 return;
84}
85/*-----------------------------------------------------------------------------------*/
oliverschmidt76872e82004-12-26 14:13:34 +000086EK_EVENTHANDLER(eventhandler, ev, data)
87{
88 switch(ev) {
89 case EK_EVENT_INIT:
90 program_handler_load("config.prg", NULL);
91 break;
92 }
93}
94/*-----------------------------------------------------------------------------------*/
95EK_PROCESS(init, "Init", EK_PRIO_LOWEST,
96 eventhandler, NULL, NULL);
97/*-----------------------------------------------------------------------------------*/
oliverschmidt9e652ff2004-07-11 12:24:52 +000098clock_time_t
99clock_time(void)
100{
oliverschmidt274cb0e2005-05-16 21:18:47 +0000101 static clock_time_t count, clock;
oliverschmidt9e652ff2004-07-11 12:24:52 +0000102
oliverschmidt274cb0e2005-05-16 21:18:47 +0000103 count += tick;
104
oliverschmidtba6f5902006-05-29 21:07:53 +0000105 if(count == TICK_COUNT) {
oliverschmidt274cb0e2005-05-16 21:18:47 +0000106 count = 0;
107 ++clock;
108 }
109
110 return clock;
oliverschmidt3cf3d302004-06-08 20:28:33 +0000111}
112/*-----------------------------------------------------------------------------------*/
oliverschmidt98d158b2006-05-18 16:31:58 +0000113#define STACK_SIZE 0
114#if STACK_SIZE
115#include <conio.h>
116#include <stdlib.h>
117void
118stack_size(void)
119{
120 static unsigned char *c;
121 static unsigned int s;
122 c = (unsigned char *)(0xBF00 - STACK_SIZE);
123 while(*c++ == 0xA2) {
124 }
125 s = (unsigned char *)0xBF00 - c;
126 clrscr();
127 cputc('0' + s / 100 % 10);
128 cputc('0' + s / 10 % 10);
129 cputc('0' + s % 10);
130 cgetc();
131}
132#endif /* STACK_SIZE */
133/*-----------------------------------------------------------------------------------*/
oliverschmidt3cf3d302004-06-08 20:28:33 +0000134void
oliverschmidt33d8fad2006-05-18 16:20:08 +0000135#ifdef __APPLE2__
oliverschmidt3cf3d302004-06-08 20:28:33 +0000136main(void)
oliverschmidt33d8fad2006-05-18 16:20:08 +0000137#else /* __APPLE2__ */
138main(int argc, char *argv[])
139#endif /* __APPLE2__ */
oliverschmidt3cf3d302004-06-08 20:28:33 +0000140{
oliverschmidt98d158b2006-05-18 16:31:58 +0000141
142#if STACK_SIZE
143 memset((void *)(0xBF00 - STACK_SIZE),
144 0xA2, STACK_SIZE - (0xBF00 - *(unsigned int *)0x80) - 10);
145 atexit(stack_size);
146#endif /* STACK_SIZE */
147
oliverschmidt9e652ff2004-07-11 12:24:52 +0000148 ek_init();
oliverschmidt76872e82004-12-26 14:13:34 +0000149 ek_start(&init);
150
oliverschmidt9e652ff2004-07-11 12:24:52 +0000151 tcpip_init(NULL);
oliverschmidt76872e82004-12-26 14:13:34 +0000152 resolv_init(NULL);
oliverschmidt3cf3d302004-06-08 20:28:33 +0000153
adamdunkelsa4ed8472003-04-10 07:25:26 +0000154 ctk_init();
oliverschmidt3cf3d302004-06-08 20:28:33 +0000155
adamdunkelsa4ed8472003-04-10 07:25:26 +0000156 program_handler_init();
adamdunkelsa4ed8472003-04-10 07:25:26 +0000157
oliverschmidt63e299e2005-05-06 22:38:17 +0000158 program_handler_add(&www_dsc, "Web browser", 1);
159 program_handler_add(&email_dsc, "E-mail", 1);
160 program_handler_add(&ftp_dsc, "FTP client", 1);
161 program_handler_add(&directory_dsc, "Directory", 1);
adamdunkelsa4ed8472003-04-10 07:25:26 +0000162
oliverschmidt76872e82004-12-26 14:13:34 +0000163 while(1) {
164 if(ek_run() == 0) {
oliverschmidt33d8fad2006-05-18 16:20:08 +0000165
166#ifdef __APPLE2__
167
oliverschmidt76872e82004-12-26 14:13:34 +0000168 program_handler_load("welcome.prg", NULL);
oliverschmidt33d8fad2006-05-18 16:20:08 +0000169
170#else /* __APPLE2__ */
171
172 static char *startup;
173 static char *slash;
174
175 if(argc == 1) {
176 startup = "welcome.prg";
177 } else {
178 startup = argv[1];
179 while(slash = strchr(startup, '/')) {
180 startup = slash + 1;
181 }
182 }
183 program_handler_load(startup, NULL);
184
185#endif /* __APPLE2__ */
186
oliverschmidt76872e82004-12-26 14:13:34 +0000187 break;
188 }
189 }
oliverschmidt9e652ff2004-07-11 12:24:52 +0000190 while(1) {
191 ek_run();
192 }
adamdunkelsa4ed8472003-04-10 07:25:26 +0000193}
194/*-----------------------------------------------------------------------------------*/