adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 1 | /* |
adamdunkels | dd5717c | 2004-08-09 21:42:43 +0000 | [diff] [blame] | 2 | * Copyright (c) 2002-2004, Adam Dunkels. |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 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 |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
adamdunkels | dd5717c | 2004-08-09 21:42:43 +0000 | [diff] [blame] | 14 | * 3. The name of the author may not be used to endorse or promote |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 15 | * 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 | * |
adamdunkels | dd5717c | 2004-08-09 21:42:43 +0000 | [diff] [blame] | 30 | * This file is part of the Contiki operating system |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 31 | * |
adamdunkels | a292235 | 2004-09-18 20:35:37 +0000 | [diff] [blame] | 32 | * $Id: main.c,v 1.17 2004/09/18 20:35:37 adamdunkels Exp $ |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 33 | * |
| 34 | */ |
| 35 | |
adamdunkels | dd5717c | 2004-08-09 21:42:43 +0000 | [diff] [blame] | 36 | #include "contiki.h" |
| 37 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 38 | #include "ctk.h" |
| 39 | #include "ctk-draw.h" |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 40 | #include "ek.h" |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 41 | |
adamdunkels | 80d1db0 | 2003-04-08 19:11:19 +0000 | [diff] [blame] | 42 | #include "program-handler.h" |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 43 | |
adamdunkels | fcd7b48 | 2004-02-24 09:52:54 +0000 | [diff] [blame] | 44 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 45 | #include "uip.h" |
| 46 | #include "uip_arp.h" |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 47 | |
adamdunkels | 7cde609 | 2003-08-24 22:35:22 +0000 | [diff] [blame] | 48 | #include "resolv.h" |
| 49 | |
adamdunkels | 243e1f7 | 2003-08-06 23:13:06 +0000 | [diff] [blame] | 50 | #include "configedit-dsc.h" |
adamdunkels | b410708 | 2003-04-18 00:13:42 +0000 | [diff] [blame] | 51 | #include "directory-dsc.h" |
adamdunkels | d4d6dde | 2003-08-05 13:54:50 +0000 | [diff] [blame] | 52 | #include "processes-dsc.h" |
adamdunkels | 179f718 | 2003-04-17 18:59:05 +0000 | [diff] [blame] | 53 | |
adamdunkels | dd5717c | 2004-08-09 21:42:43 +0000 | [diff] [blame] | 54 | #include "cfs-cbm.h" |
adamdunkels | 36a8128 | 2003-08-04 00:14:03 +0000 | [diff] [blame] | 55 | |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 56 | #include "clock.h" |
| 57 | |
adamdunkels | 36a8128 | 2003-08-04 00:14:03 +0000 | [diff] [blame] | 58 | #include <cbm.h> |
| 59 | |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 60 | unsigned char |
| 61 | uip_fw_forward(void) |
| 62 | { |
| 63 | return 0; |
| 64 | } |
| 65 | void |
| 66 | uip_fw_periodic(void) |
| 67 | { |
| 68 | return; |
| 69 | } |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 70 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | dd5717c | 2004-08-09 21:42:43 +0000 | [diff] [blame] | 71 | EK_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 | /*-----------------------------------------------------------------------------------*/ |
| 80 | EK_PROCESS(init, "Init", EK_PRIO_LOWEST, |
| 81 | eventhandler, NULL, NULL); |
| 82 | /*-----------------------------------------------------------------------------------*/ |
| 83 | void |
| 84 | log_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 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 98 | clock_time_t |
| 99 | clock_time(void) |
adamdunkels | 7cdff29 | 2004-02-16 21:21:46 +0000 | [diff] [blame] | 100 | { |
| 101 | return clock(); |
| 102 | } |
| 103 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | b082c09 | 2004-06-08 11:47:18 +0000 | [diff] [blame] | 104 | void |
| 105 | main(void) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 106 | { |
adamdunkels | f829332 | 2004-09-12 13:13:00 +0000 | [diff] [blame] | 107 | |
adamdunkels | dd5717c | 2004-08-09 21:42:43 +0000 | [diff] [blame] | 108 | log_message("Starting ", CONTIKI_VERSION_STRING); |
adamdunkels | 36a8128 | 2003-08-04 00:14:03 +0000 | [diff] [blame] | 109 | |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 110 | ek_init(); |
adamdunkels | 4f7b6f2 | 2004-09-12 13:19:04 +0000 | [diff] [blame] | 111 | |
| 112 | ek_start(&init); |
| 113 | |
adamdunkels | dd5717c | 2004-08-09 21:42:43 +0000 | [diff] [blame] | 114 | log_message(": TCP/IP", ""); |
| 115 | |
| 116 | tcpip_init(NULL); |
adamdunkels | 243e1f7 | 2003-08-06 23:13:06 +0000 | [diff] [blame] | 117 | |
adamdunkels | 7c73065 | 2004-09-12 07:26:58 +0000 | [diff] [blame] | 118 | resolv_init(NULL); |
adamdunkels | dd5717c | 2004-08-09 21:42:43 +0000 | [diff] [blame] | 119 | |
| 120 | log_message(": CTK GUI", ""); |
| 121 | ctk_init(); |
| 122 | |
| 123 | log_message(": Initial filesystem", ""); |
| 124 | cfs_init_init(NULL); |
| 125 | |
adamdunkels | 80d1db0 | 2003-04-08 19:11:19 +0000 | [diff] [blame] | 126 | program_handler_init(); |
adamdunkels | 0b9424e | 2003-07-30 23:11:47 +0000 | [diff] [blame] | 127 | |
adamdunkels | b410708 | 2003-04-18 00:13:42 +0000 | [diff] [blame] | 128 | program_handler_add(&directory_dsc, "Directory", 1); |
adamdunkels | 243e1f7 | 2003-08-06 23:13:06 +0000 | [diff] [blame] | 129 | program_handler_add(&configedit_dsc, "Configuration", 1); |
adamdunkels | d4d6dde | 2003-08-05 13:54:50 +0000 | [diff] [blame] | 130 | program_handler_add(&processes_dsc, "Processes", 1); |
adamdunkels | f829332 | 2004-09-12 13:13:00 +0000 | [diff] [blame] | 131 | |
adamdunkels | dd5717c | 2004-08-09 21:42:43 +0000 | [diff] [blame] | 132 | |
| 133 | log_message("Starting process scheduling", ""); |
adamdunkels | f829332 | 2004-09-12 13:13:00 +0000 | [diff] [blame] | 134 | |
| 135 | while(1) { |
| 136 | if(ek_run() == 0) { |
| 137 | program_handler_load("welcome.prg", NULL); |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | |
adamdunkels | dd5717c | 2004-08-09 21:42:43 +0000 | [diff] [blame] | 142 | |
adamdunkels | 0a08fda | 2004-07-04 18:33:07 +0000 | [diff] [blame] | 143 | while(1) { |
| 144 | ek_run(); |
| 145 | } |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 146 | } |
| 147 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | f66fcd2 | 2004-09-12 07:34:49 +0000 | [diff] [blame] | 148 | void |
adamdunkels | 7c73065 | 2004-09-12 07:26:58 +0000 | [diff] [blame] | 149 | reset(void) |
| 150 | { |
| 151 | asm("lda #$36"); |
| 152 | asm("sta $01"); |
| 153 | asm("jmp $fce2"); |
adamdunkels | f66fcd2 | 2004-09-12 07:34:49 +0000 | [diff] [blame] | 154 | } |
adamdunkels | 7c73065 | 2004-09-12 07:26:58 +0000 | [diff] [blame] | 155 | |