Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

kernel/kmain.c

Go to the documentation of this file.
00001 
00006 /*
00007  *  The contents of this file are subject to the Mozilla Public License
00008  *  Version 1.0 (the "License"); you may not use this file except in
00009  *  compliance with the License. You may obtain a copy of the License at
00010  *  http://www.mozilla.org/MPL/
00011  *
00012  *  Software distributed under the License is distributed on an "AS IS"
00013  *  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
00014  *  License for the specific language governing rights and limitations
00015  *  under the License.
00016  *
00017  *  The Original Code is legOS code, released October 17, 1999.
00018  *
00019  *  The Initial Developer of the Original Code is Markus L. Noga.
00020  *  Portions created by Markus L. Noga are Copyright (C) 1999
00021  *  Markus L. Noga. All Rights Reserved.
00022  *
00023  *  Contributor(s): Markus L. Noga <markus@noga.de>
00024  *                  Kekoa Proudfoot <kekoa@graphics.stanford.edu>
00025  *                  Lou Sortman <lou (at) sunsite (dot) unc (dot) edu>
00026  */
00027 
00028 #include <sys/mm.h>
00029 #include <sys/time.h>
00030 #include <sys/tm.h>
00031 #include <sys/irq.h>
00032 #include <sys/lcd.h>
00033 #include <sys/dsensor.h>
00034 #include <sys/dmotor.h>
00035 #include <sys/dsound.h>
00036 #include <sys/lnp.h>
00037 #include <sys/lnp-logical.h>
00038 #include <sys/program.h>
00039 #ifdef CONF_AUTOSHUTOFF
00040 #include <sys/timeout.h>
00041 #endif
00042 #include <rom/system.h>
00043 
00044 #include <dbutton.h>
00045 
00046 #include <string.h>
00047 #include <conio.h>
00048 #include <unistd.h>
00050 //
00051 // Variables
00052 //
00054 
00056 
00058 unsigned char *firmware_string = "Do you byte, when I knock?";
00059 
00060 extern char __bss;              
00061 extern char __bss_end;  
00062 
00064 //
00065 // Functions
00066 //
00068 
00069 extern int main(int argc, char **argv);     
00070 
00071 
00073 extern inline void show_on(void) {
00074   cls();
00075 
00076 #ifdef CONF_ASCII
00077   cputs("ON");
00078 #else
00079 #ifdef CONF_CONIO
00080   cputc_native_4(0x38);
00081   cputc_native_3(0x3d);
00082   cputc_native_2(0x7c);
00083   cputc_native_1(0x7e);
00084   cputc_native_0(0x6d);
00085 #else
00086   lcd_digit(1);
00087 #endif
00088 #endif
00089 #ifndef CONF_LCD_REFRESH
00090   lcd_refresh();
00091 #endif
00092   delay(250);
00093 }
00094 
00096 extern inline void show_off(void) {
00097   cls();
00098 
00099 #ifdef CONF_ASCII
00100   cputs("OFF");
00101 #else
00102 #ifdef CONF_CONIO
00103   cputc_native_4(0x7e);
00104   cputc_native_3(0x1d);
00105   cputc_native_2(0x1d);
00106 #else
00107   lcd_digit(0);
00108 #endif
00109 #endif
00110 #ifndef CONF_LCD_REFRESH
00111   lcd_refresh();
00112 #endif
00113 }
00114 
00115 
00117 
00119 void kmain(void) __attribute__((noreturn));
00120 void kmain(void)
00121 {
00122   int reset_after_shutdown=0;
00123 #ifdef CONF_DKEY
00124   int c;
00125 #endif
00126 
00127   reset_vector = rom_reset_vector;
00128   memset(&__bss, 0, &__bss_end - &__bss);
00129 
00130 #ifdef CONF_MM
00131   mm_init();
00132 #endif
00133 
00134   while (1) {
00135     power_init();
00136 
00137 #ifdef CONF_AUTOSHUTOFF
00138     shutoff_init();
00139 #endif
00140 
00141     lcd_init();
00142 
00143 #ifdef CONF_DSOUND
00144     dsound_init();
00145 #endif
00146 #ifdef CONF_TIME
00147     systime_init();
00148 #endif
00149 #ifdef CONF_DSENSOR
00150     ds_init();
00151 #endif
00152 #ifdef CONF_DMOTOR
00153     dm_init();
00154 #endif
00155 #ifdef CONF_LNP
00156     lnp_init();
00157     lnp_logical_init();
00158 #endif
00159 #ifdef CONF_TM
00160     tm_init();
00161 #endif
00162 #ifdef CONF_PROGRAM
00163     program_init();
00164 #endif
00165 
00166     show_on();
00167 
00168     // wait till power key released
00169     //
00170 #ifdef CONF_DKEY
00171     dkey_multi=KEY_ANY;
00172     while((c=dkey_multi) & KEY_ONOFF);
00173 #else
00174     while (PRESSED(dbutton(), BUTTON_ONOFF));
00175     delay(100);
00176 #endif
00177 
00178     cls();
00179 #ifndef CONF_PROGRAM
00180     lcd_show(man_run);
00181 #ifndef CONF_LCD_REFRESH
00182     lcd_refresh();
00183 #endif
00184 #endif
00185 
00186     // run app
00187     //
00188 #ifdef CONF_TM
00189 #ifndef CONF_PROGRAM
00190     execi(&main,0,0,PRIO_NORMAL,DEFAULT_STACK_SIZE);
00191 #endif
00192     tm_start();
00193 #else
00194     main(0,0);
00195 #endif
00196 
00197     show_off();
00198 
00199     // ON/OFF + PROGRAM -> erase firmware
00200 #ifdef CONF_DKEY
00201     while((c=dkey_multi) & KEY_ONOFF)
00202       if(c&KEY_PRGM)
00203         reset_after_shutdown=1;
00204 #else
00205     while (PRESSED(dbutton(), BUTTON_ONOFF))
00206       if (PRESSED(dbutton(), BUTTON_PROGRAM))
00207         reset_after_shutdown=1;
00208 #endif
00209 
00210 #ifdef CONF_PROGRAM
00211     program_shutdown();
00212 #endif
00213 #ifdef CONF_LNP
00214     lnp_logical_shutdown();
00215 #endif
00216 #ifdef CONF_DMOTOR
00217     dm_shutdown();
00218 #endif
00219 #ifdef CONF_DSENSOR
00220     ds_shutdown();
00221 #endif
00222 #ifdef CONF_TIME
00223     systime_shutdown();
00224 #endif
00225 
00226     if (reset_after_shutdown)
00227       rom_reset();
00228 
00229     lcd_clear();
00230     lcd_power_off();
00231 
00232     power_off();
00233   }
00234 }

brickOS is released under the Mozilla Public License.
Original code copyright 1998-2002 by the authors.

Generated on Sat Jul 26 23:54:51 2003 for brickOS Kernel Developer by doxygen 1.3.2