blob: c73339aa82062890e5dd36b630d9e6a80ab67357 [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 *
oliverschmidt98d158b2006-05-18 16:31:58 +000035 * $Id: main.c,v 1.15 2006/05/18 16:31:58 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
60unsigned char lanslot;
61
oliverschmidtd9f33142005-02-17 22:45:02 +000062#pragma bssseg(push, "UIPBUF");
63u8_t uip_buf[UIP_BUFSIZE + 2];
64#pragma bssseg(pop);
65
adamdunkelsa4ed8472003-04-10 07:25:26 +000066/*-----------------------------------------------------------------------------------*/
oliverschmidt9e652ff2004-07-11 12:24:52 +000067unsigned char
68uip_fw_forward(void)
adamdunkelsa4ed8472003-04-10 07:25:26 +000069{
oliverschmidt9e652ff2004-07-11 12:24:52 +000070 return 0;
71}
72/*-----------------------------------------------------------------------------------*/
73void
74uip_fw_periodic(void)
75{
76 return;
77}
78/*-----------------------------------------------------------------------------------*/
oliverschmidt76872e82004-12-26 14:13:34 +000079EK_EVENTHANDLER(eventhandler, ev, data)
80{
81 switch(ev) {
82 case EK_EVENT_INIT:
83 program_handler_load("config.prg", NULL);
84 break;
85 }
86}
87/*-----------------------------------------------------------------------------------*/
88EK_PROCESS(init, "Init", EK_PRIO_LOWEST,
89 eventhandler, NULL, NULL);
90/*-----------------------------------------------------------------------------------*/
oliverschmidt9e652ff2004-07-11 12:24:52 +000091clock_time_t
92clock_time(void)
93{
oliverschmidt274cb0e2005-05-16 21:18:47 +000094 static clock_time_t count, clock;
oliverschmidt9e652ff2004-07-11 12:24:52 +000095
oliverschmidt274cb0e2005-05-16 21:18:47 +000096 count += tick;
97
98 if(count == 4200) {
99 count = 0;
100 ++clock;
101 }
102
103 return clock;
oliverschmidt3cf3d302004-06-08 20:28:33 +0000104}
105/*-----------------------------------------------------------------------------------*/
oliverschmidt98d158b2006-05-18 16:31:58 +0000106#define STACK_SIZE 0
107#if STACK_SIZE
108#include <conio.h>
109#include <stdlib.h>
110void
111stack_size(void)
112{
113 static unsigned char *c;
114 static unsigned int s;
115 c = (unsigned char *)(0xBF00 - STACK_SIZE);
116 while(*c++ == 0xA2) {
117 }
118 s = (unsigned char *)0xBF00 - c;
119 clrscr();
120 cputc('0' + s / 100 % 10);
121 cputc('0' + s / 10 % 10);
122 cputc('0' + s % 10);
123 cgetc();
124}
125#endif /* STACK_SIZE */
126/*-----------------------------------------------------------------------------------*/
oliverschmidt3cf3d302004-06-08 20:28:33 +0000127void
oliverschmidt33d8fad2006-05-18 16:20:08 +0000128#ifdef __APPLE2__
oliverschmidt3cf3d302004-06-08 20:28:33 +0000129main(void)
oliverschmidt33d8fad2006-05-18 16:20:08 +0000130#else /* __APPLE2__ */
131main(int argc, char *argv[])
132#endif /* __APPLE2__ */
oliverschmidt3cf3d302004-06-08 20:28:33 +0000133{
oliverschmidt98d158b2006-05-18 16:31:58 +0000134
135#if STACK_SIZE
136 memset((void *)(0xBF00 - STACK_SIZE),
137 0xA2, STACK_SIZE - (0xBF00 - *(unsigned int *)0x80) - 10);
138 atexit(stack_size);
139#endif /* STACK_SIZE */
140
oliverschmidt9e652ff2004-07-11 12:24:52 +0000141 ek_init();
oliverschmidt76872e82004-12-26 14:13:34 +0000142 ek_start(&init);
143
oliverschmidt9e652ff2004-07-11 12:24:52 +0000144 tcpip_init(NULL);
oliverschmidt76872e82004-12-26 14:13:34 +0000145 resolv_init(NULL);
oliverschmidt3cf3d302004-06-08 20:28:33 +0000146
adamdunkelsa4ed8472003-04-10 07:25:26 +0000147 ctk_init();
oliverschmidt3cf3d302004-06-08 20:28:33 +0000148
adamdunkelsa4ed8472003-04-10 07:25:26 +0000149 program_handler_init();
adamdunkelsa4ed8472003-04-10 07:25:26 +0000150
oliverschmidt63e299e2005-05-06 22:38:17 +0000151 program_handler_add(&www_dsc, "Web browser", 1);
152 program_handler_add(&email_dsc, "E-mail", 1);
153 program_handler_add(&ftp_dsc, "FTP client", 1);
154 program_handler_add(&directory_dsc, "Directory", 1);
adamdunkelsa4ed8472003-04-10 07:25:26 +0000155
oliverschmidt76872e82004-12-26 14:13:34 +0000156 while(1) {
157 if(ek_run() == 0) {
oliverschmidt33d8fad2006-05-18 16:20:08 +0000158
159#ifdef __APPLE2__
160
oliverschmidt76872e82004-12-26 14:13:34 +0000161 program_handler_load("welcome.prg", NULL);
oliverschmidt33d8fad2006-05-18 16:20:08 +0000162
163#else /* __APPLE2__ */
164
165 static char *startup;
166 static char *slash;
167
168 if(argc == 1) {
169 startup = "welcome.prg";
170 } else {
171 startup = argv[1];
172 while(slash = strchr(startup, '/')) {
173 startup = slash + 1;
174 }
175 }
176 program_handler_load(startup, NULL);
177
178#endif /* __APPLE2__ */
179
oliverschmidt76872e82004-12-26 14:13:34 +0000180 break;
181 }
182 }
oliverschmidt9e652ff2004-07-11 12:24:52 +0000183 while(1) {
184 ek_run();
185 }
adamdunkelsa4ed8472003-04-10 07:25:26 +0000186}
187/*-----------------------------------------------------------------------------------*/