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 extern char __text_hi, __etext_hi; 00065 00066 #if defined(CONF_DSOUND) && defined(CONF_ON_OFF_SOUND) 00067 static const note_t on_sound[]={{PITCH_G4, 1}, {PITCH_G5, 1}, {PITCH_END, 0}}; 00068 static const note_t off_sound[]={{PITCH_C4, 1}, {PITCH_C3, 1}, {PITCH_END, 0}}; 00069 #endif 00070 00072 // 00073 // Functions 00074 // 00076 00077 extern int main(int argc, char **argv); 00078 00079 #if defined(CONF_DSOUND) && defined(CONF_ON_OFF_SOUND) 00080 static void onOffSound(const note_t *snd) { 00081 dsound_set_duration(40); 00082 dsound_play(snd); 00083 } 00084 #endif 00085 00087 extern inline void show_on(void) { 00088 cls(); 00089 00090 #ifdef CONF_ASCII 00091 cputs("ON"); 00092 #else 00093 #ifdef CONF_CONIO 00094 cputc_native_4(0x38); 00095 cputc_native_3(0x3d); 00096 cputc_native_2(0x7c); 00097 cputc_native_1(0x7e); 00098 cputc_native_0(0x6d); 00099 #else 00100 lcd_digit(1); 00101 #endif 00102 #endif 00103 #ifndef CONF_LCD_REFRESH 00104 lcd_refresh(); 00105 #endif 00106 #if defined(CONF_DSOUND) && defined(CONF_ON_OFF_SOUND) 00107 onOffSound(on_sound); 00108 #endif 00109 delay(250); 00110 #if defined(CONF_DSOUND) && defined(CONF_ON_OFF_SOUND) 00111 dsound_set_duration(DSOUND_DEFAULT_16th_ms); 00112 #endif 00113 } 00114 00116 extern inline void show_off(void) { 00117 cls(); 00118 00119 #ifdef CONF_ASCII 00120 cputs("OFF"); 00121 #else 00122 #ifdef CONF_CONIO 00123 cputc_native_4(0x7e); 00124 cputc_native_3(0x1d); 00125 cputc_native_2(0x1d); 00126 #else 00127 lcd_digit(0); 00128 #endif 00129 #endif 00130 #ifndef CONF_LCD_REFRESH 00131 lcd_refresh(); 00132 #endif 00133 #if defined(CONF_DSOUND) && defined(CONF_ON_OFF_SOUND) 00134 onOffSound(off_sound); 00135 #endif 00136 } 00137 00138 00140 00142 void kmain(void) __attribute__((noreturn)); 00143 void kmain(void) 00144 { 00145 int reset_after_shutdown=0; 00146 #ifdef CONF_DKEY 00147 int c; 00148 #endif 00149 00150 /* Install the text.hi segment in the correct place. The 00151 * firmware loader puts it in the bss segment, we copy it 00152 * to it's final location. 00153 */ 00154 memcpy(&__text_hi, &__bss, &__etext_hi - &__text_hi); 00155 00156 reset_vector = rom_reset_vector; 00157 00158 /* Turn off motor, since writing to hitext manipulates motors */ 00159 motor_controller = 0; 00160 00161 memset(&__bss, 0, &__bss_end - &__bss); 00162 00163 #ifdef CONF_MM 00164 mm_init(); 00165 #endif 00166 00167 while (1) { 00168 power_init(); 00169 00170 #ifdef CONF_AUTOSHUTOFF 00171 shutoff_init(); 00172 #endif 00173 00174 lcd_init(); 00175 00176 #ifdef CONF_DSOUND 00177 dsound_init(); 00178 #endif 00179 #ifdef CONF_TIME 00180 systime_init(); 00181 #endif 00182 #ifdef CONF_DSENSOR 00183 ds_init(); 00184 #endif 00185 #ifdef CONF_DMOTOR 00186 dm_init(); 00187 #endif 00188 #ifdef CONF_LNP 00189 lnp_init(); 00190 lnp_logical_init(); 00191 #endif 00192 #ifdef CONF_TM 00193 tm_init(); 00194 #endif 00195 #ifdef CONF_PROGRAM 00196 program_init(); 00197 #endif 00198 00199 show_on(); 00200 00201 // wait till power key released 00202 // 00203 #ifdef CONF_DKEY 00204 dkey_multi=KEY_ANY; 00205 while((c=dkey_multi) & KEY_ONOFF); 00206 #else 00207 while (PRESSED(dbutton(), BUTTON_ONOFF)); 00208 delay(100); 00209 #endif 00210 00211 cls(); 00212 #ifndef CONF_PROGRAM 00213 lcd_show(man_run); 00214 #ifndef CONF_LCD_REFRESH 00215 lcd_refresh(); 00216 #endif 00217 #endif 00218 00219 // run app 00220 // 00221 #ifdef CONF_TM 00222 # ifndef CONF_PROGRAM 00223 execi(&main,0,0,PRIO_NORMAL,DEFAULT_STACK_SIZE); 00224 # endif 00225 tm_start(); 00226 #else 00227 main(0, (void*)0); 00228 #endif 00229 00230 show_off(); 00231 00232 // ON/OFF + PROGRAM -> erase firmware 00233 #ifdef CONF_DKEY 00234 while((c=dkey_multi) & KEY_ONOFF) 00235 if(c&KEY_PRGM) 00236 reset_after_shutdown=1; 00237 #else 00238 while (PRESSED(dbutton(), BUTTON_ONOFF)) 00239 if (PRESSED(dbutton(), BUTTON_PROGRAM)) 00240 reset_after_shutdown=1; 00241 #endif 00242 00243 #ifdef CONF_PROGRAM 00244 program_shutdown(); 00245 #endif 00246 #ifdef CONF_LNP 00247 lnp_logical_shutdown(); 00248 #endif 00249 #ifdef CONF_DMOTOR 00250 dm_shutdown(); 00251 #endif 00252 #ifdef CONF_DSENSOR 00253 ds_shutdown(); 00254 #endif 00255 #ifdef CONF_TIME 00256 systime_shutdown(); 00257 #endif 00258 00259 if (reset_after_shutdown) 00260 rom_reset(); 00261 00262 lcd_clear(); 00263 lcd_power_off(); 00264 00265 power_off(); 00266 } 00267 }
brickOS is released under the
Mozilla Public License.
Original code copyright 1998-2002 by the authors. |