blob: e012c350d47eef3dd7f7932112af7fd52be57c3a [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 *
oliverschmidt33d8fad2006-05-18 16:20:08 +000035 * $Id: main.c,v 1.14 2006/05/18 16:20:08 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/*-----------------------------------------------------------------------------------*/
106void
oliverschmidt33d8fad2006-05-18 16:20:08 +0000107#ifdef __APPLE2__
oliverschmidt3cf3d302004-06-08 20:28:33 +0000108main(void)
oliverschmidt33d8fad2006-05-18 16:20:08 +0000109#else /* __APPLE2__ */
110main(int argc, char *argv[])
111#endif /* __APPLE2__ */
oliverschmidt3cf3d302004-06-08 20:28:33 +0000112{
oliverschmidt9e652ff2004-07-11 12:24:52 +0000113 ek_init();
oliverschmidt76872e82004-12-26 14:13:34 +0000114 ek_start(&init);
115
oliverschmidt9e652ff2004-07-11 12:24:52 +0000116 tcpip_init(NULL);
oliverschmidt76872e82004-12-26 14:13:34 +0000117 resolv_init(NULL);
oliverschmidt3cf3d302004-06-08 20:28:33 +0000118
adamdunkelsa4ed8472003-04-10 07:25:26 +0000119 ctk_init();
oliverschmidt3cf3d302004-06-08 20:28:33 +0000120
adamdunkelsa4ed8472003-04-10 07:25:26 +0000121 program_handler_init();
adamdunkelsa4ed8472003-04-10 07:25:26 +0000122
oliverschmidt63e299e2005-05-06 22:38:17 +0000123 program_handler_add(&www_dsc, "Web browser", 1);
124 program_handler_add(&email_dsc, "E-mail", 1);
125 program_handler_add(&ftp_dsc, "FTP client", 1);
126 program_handler_add(&directory_dsc, "Directory", 1);
adamdunkelsa4ed8472003-04-10 07:25:26 +0000127
oliverschmidt76872e82004-12-26 14:13:34 +0000128 while(1) {
129 if(ek_run() == 0) {
oliverschmidt33d8fad2006-05-18 16:20:08 +0000130
131#ifdef __APPLE2__
132
oliverschmidt76872e82004-12-26 14:13:34 +0000133 program_handler_load("welcome.prg", NULL);
oliverschmidt33d8fad2006-05-18 16:20:08 +0000134
135#else /* __APPLE2__ */
136
137 static char *startup;
138 static char *slash;
139
140 if(argc == 1) {
141 startup = "welcome.prg";
142 } else {
143 startup = argv[1];
144 while(slash = strchr(startup, '/')) {
145 startup = slash + 1;
146 }
147 }
148 program_handler_load(startup, NULL);
149
150#endif /* __APPLE2__ */
151
oliverschmidt76872e82004-12-26 14:13:34 +0000152 break;
153 }
154 }
oliverschmidt9e652ff2004-07-11 12:24:52 +0000155 while(1) {
156 ek_run();
157 }
adamdunkelsa4ed8472003-04-10 07:25:26 +0000158}
159/*-----------------------------------------------------------------------------------*/