blob: 8b1906cfa55997a0431d2c6a83dbd29721225c3a [file] [log] [blame]
adamdunkels7e4982c2003-03-19 16:26:18 +00001/*
adamdunkelsdd5717c2004-08-09 21:42:43 +00002 * Copyright (c) 2002-2004, Adam Dunkels.
adamdunkels7e4982c2003-03-19 16:26:18 +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.
adamdunkelsdd5717c2004-08-09 21:42:43 +000014 * 3. The name of the author may not be used to endorse or promote
adamdunkels7e4982c2003-03-19 16:26:18 +000015 * products derived from this software without specific prior
16 * written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
adamdunkelsdd5717c2004-08-09 21:42:43 +000030 * This file is part of the Contiki operating system
adamdunkels7e4982c2003-03-19 16:26:18 +000031 *
adamdunkelsa2922352004-09-18 20:35:37 +000032 * $Id: main.c,v 1.17 2004/09/18 20:35:37 adamdunkels Exp $
adamdunkels7e4982c2003-03-19 16:26:18 +000033 *
34 */
35
adamdunkelsdd5717c2004-08-09 21:42:43 +000036#include "contiki.h"
37
adamdunkels7e4982c2003-03-19 16:26:18 +000038#include "ctk.h"
39#include "ctk-draw.h"
adamdunkels0a08fda2004-07-04 18:33:07 +000040#include "ek.h"
adamdunkels7e4982c2003-03-19 16:26:18 +000041
adamdunkels80d1db02003-04-08 19:11:19 +000042#include "program-handler.h"
adamdunkels7e4982c2003-03-19 16:26:18 +000043
adamdunkelsfcd7b482004-02-24 09:52:54 +000044
adamdunkels7e4982c2003-03-19 16:26:18 +000045#include "uip.h"
46#include "uip_arp.h"
adamdunkels7e4982c2003-03-19 16:26:18 +000047
adamdunkels7cde6092003-08-24 22:35:22 +000048#include "resolv.h"
49
adamdunkels243e1f72003-08-06 23:13:06 +000050#include "configedit-dsc.h"
adamdunkelsb4107082003-04-18 00:13:42 +000051#include "directory-dsc.h"
adamdunkelsd4d6dde2003-08-05 13:54:50 +000052#include "processes-dsc.h"
adamdunkels179f7182003-04-17 18:59:05 +000053
adamdunkelsdd5717c2004-08-09 21:42:43 +000054#include "cfs-cbm.h"
adamdunkels36a81282003-08-04 00:14:03 +000055
adamdunkels0a08fda2004-07-04 18:33:07 +000056#include "clock.h"
57
adamdunkels36a81282003-08-04 00:14:03 +000058#include <cbm.h>
59
adamdunkels0a08fda2004-07-04 18:33:07 +000060unsigned char
61uip_fw_forward(void)
62{
63 return 0;
64}
65void
66uip_fw_periodic(void)
67{
68 return;
69}
adamdunkels7e4982c2003-03-19 16:26:18 +000070/*-----------------------------------------------------------------------------------*/
adamdunkelsdd5717c2004-08-09 21:42:43 +000071EK_EVENTHANDLER(eventhandler, ev, data)
72{
73 switch(ev) {
74 case EK_EVENT_INIT:
75 program_handler_load("config.prg", NULL);
76 break;
77 }
78}
79/*-----------------------------------------------------------------------------------*/
80EK_PROCESS(init, "Init", EK_PRIO_LOWEST,
81 eventhandler, NULL, NULL);
82/*-----------------------------------------------------------------------------------*/
83void
84log_message(char *part1, char *part2)
85{
86 while(*part1 != 0) {
87 cbm_k_bsout(*part1++);
88 }
89
90 while(*part2 != 0) {
91 cbm_k_bsout(*part2++);
92 }
93
94
95 cbm_k_bsout('\n');
96}
97/*-----------------------------------------------------------------------------------*/
adamdunkels0a08fda2004-07-04 18:33:07 +000098clock_time_t
99clock_time(void)
adamdunkels7cdff292004-02-16 21:21:46 +0000100{
101 return clock();
102}
103/*-----------------------------------------------------------------------------------*/
adamdunkelsb082c092004-06-08 11:47:18 +0000104void
105main(void)
adamdunkels7e4982c2003-03-19 16:26:18 +0000106{
adamdunkelsf8293322004-09-12 13:13:00 +0000107
adamdunkelsdd5717c2004-08-09 21:42:43 +0000108 log_message("Starting ", CONTIKI_VERSION_STRING);
adamdunkels36a81282003-08-04 00:14:03 +0000109
adamdunkels0a08fda2004-07-04 18:33:07 +0000110 ek_init();
adamdunkels4f7b6f22004-09-12 13:19:04 +0000111
112 ek_start(&init);
113
adamdunkelsdd5717c2004-08-09 21:42:43 +0000114 log_message(": TCP/IP", "");
115
116 tcpip_init(NULL);
adamdunkels243e1f72003-08-06 23:13:06 +0000117
adamdunkels7c730652004-09-12 07:26:58 +0000118 resolv_init(NULL);
adamdunkelsdd5717c2004-08-09 21:42:43 +0000119
120 log_message(": CTK GUI", "");
121 ctk_init();
122
123 log_message(": Initial filesystem", "");
124 cfs_init_init(NULL);
125
adamdunkels80d1db02003-04-08 19:11:19 +0000126 program_handler_init();
adamdunkels0b9424e2003-07-30 23:11:47 +0000127
adamdunkelsb4107082003-04-18 00:13:42 +0000128 program_handler_add(&directory_dsc, "Directory", 1);
adamdunkels243e1f72003-08-06 23:13:06 +0000129 program_handler_add(&configedit_dsc, "Configuration", 1);
adamdunkelsd4d6dde2003-08-05 13:54:50 +0000130 program_handler_add(&processes_dsc, "Processes", 1);
adamdunkelsf8293322004-09-12 13:13:00 +0000131
adamdunkelsdd5717c2004-08-09 21:42:43 +0000132
133 log_message("Starting process scheduling", "");
adamdunkelsf8293322004-09-12 13:13:00 +0000134
135 while(1) {
136 if(ek_run() == 0) {
137 program_handler_load("welcome.prg", NULL);
138 break;
139 }
140 }
141
adamdunkelsdd5717c2004-08-09 21:42:43 +0000142
adamdunkels0a08fda2004-07-04 18:33:07 +0000143 while(1) {
144 ek_run();
145 }
adamdunkels7e4982c2003-03-19 16:26:18 +0000146}
147/*-----------------------------------------------------------------------------------*/
adamdunkelsf66fcd22004-09-12 07:34:49 +0000148void
adamdunkels7c730652004-09-12 07:26:58 +0000149reset(void)
150{
151 asm("lda #$36");
152 asm("sta $01");
153 asm("jmp $fce2");
adamdunkelsf66fcd22004-09-12 07:34:49 +0000154}
adamdunkels7c730652004-09-12 07:26:58 +0000155