Minor tweaks to compile on win32.
[kugel-rb.git] / apps / main.c
blobcc270ba1369c2795df23ac969cd07973bd5d1de9
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Björn Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "config.h"
21 #if defined(IRIVER_H100) && !defined(SIMULATOR)
22 #include "thread.h"
23 #include "cpu.h"
25 unsigned long test_thread_stack[0x1000];
27 void yield(void)
29 switch_thread();
30 wake_up_thread();
33 void test_thread(void)
35 while(1)
37 GPIO1_OUT ^= 0x00020000;
38 yield();
42 int main(void)
44 int i;
46 init_threads();
48 create_thread(test_thread, test_thread_stack,
49 sizeof(test_thread_stack), "Test thread");
51 GPIO1_FUNCTION |= 0x00020000;
52 GPIO1_ENABLE |= 0x00020000;
54 while(1) {
55 for(i = 0;i < 10000;i++) {}
56 yield();
60 #else
61 #include "ata.h"
62 #include "disk.h"
63 #include "fat.h"
64 #include "lcd.h"
65 #include "rtc.h"
66 #include "debug.h"
67 #include "led.h"
68 #include "kernel.h"
69 #include "button.h"
70 #include "tree.h"
71 #include "panic.h"
72 #include "menu.h"
73 #include "system.h"
74 #include "usb.h"
75 #include "powermgmt.h"
76 #include "adc.h"
77 #include "i2c.h"
78 #ifndef DEBUG
79 #include "serial.h"
80 #endif
81 #include "mpeg.h"
82 #include "mp3_playback.h"
83 #include "main_menu.h"
84 #include "thread.h"
85 #include "settings.h"
86 #include "backlight.h"
87 #include "status.h"
88 #include "debug_menu.h"
89 #include "version.h"
90 #include "sprintf.h"
91 #include "font.h"
92 #include "language.h"
93 #include "wps-display.h"
94 #include "playlist.h"
95 #include "buffer.h"
96 #include "rolo.h"
97 #include "screens.h"
98 #include "power.h"
99 #include "talk.h"
100 #include "plugin.h"
101 #ifdef CONFIG_TUNER
102 #include "radio.h"
103 #endif
104 #ifdef HAVE_MMC
105 #include "ata_mmc.h"
106 #endif
108 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
110 const char appsversion[]=APPSVERSION;
112 void init(void);
114 void app_main(void)
116 init();
117 browse_root();
120 #ifdef SIMULATOR
122 void init(void)
124 init_threads();
125 buffer_init();
126 lcd_init();
127 font_init();
128 show_logo();
129 settings_reset();
130 settings_calc_config_sector();
131 settings_load(SETTINGS_ALL);
132 settings_apply();
133 sleep(HZ/2);
134 tree_init();
135 playlist_init();
136 mp3_init( global_settings.volume,
137 global_settings.bass,
138 global_settings.treble,
139 global_settings.balance,
140 global_settings.loudness,
141 global_settings.avc,
142 global_settings.channel_config,
143 global_settings.stereo_width,
144 global_settings.mdb_strength,
145 global_settings.mdb_harmonics,
146 global_settings.mdb_center,
147 global_settings.mdb_shape,
148 global_settings.mdb_enable,
149 global_settings.superbass);
150 mpeg_init();
151 while (button_get(false) != 0)
152 ; /* Empty the keyboard buffer */
155 #else
157 void init(void)
159 int rc;
160 /* if nobody initialized ATA before, I consider this a cold start */
161 bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */
163 system_init();
164 kernel_init();
166 buffer_init();
168 settings_reset();
170 lcd_init();
172 font_init();
173 show_logo();
175 set_irq_level(0);
176 #ifdef DEBUG
177 debug_init();
178 #else
179 #ifndef HAVE_MMC /* FIXME: This is also necessary for debug builds
180 * (do debug builds on the Ondio make sense?) */
181 serial_setup();
182 #endif
183 #endif
185 i2c_init();
187 #ifdef HAVE_RTC
188 rtc_init();
189 settings_load(SETTINGS_RTC); /* early load parts of global_settings */
190 #endif
192 adc_init();
194 usb_init();
196 backlight_init();
198 button_init();
200 powermgmt_init();
202 #ifdef CONFIG_TUNER
203 radio_init();
204 #endif
206 #ifdef HAVE_CHARGING
207 if (coldstart && charger_inserted()
208 && !global_settings.car_adapter_mode
209 #ifdef ATA_POWER_PLAYERSTYLE
210 && !ide_powered() /* relies on probing result from bootloader */
211 #endif
214 rc = charging_screen(); /* display a "charging" screen */
215 if (rc == 1 || rc == 2) /* charger removed or "Off/Stop" pressed */
216 power_off();
217 /* "On" pressed or USB connected: proceed */
218 show_logo(); /* again, to provide better visual feedback */
220 #else
221 (void)coldstart;
222 #endif
224 rc = ata_init();
225 if(rc)
227 #ifdef HAVE_LCD_BITMAP
228 char str[32];
229 lcd_clear_display();
230 snprintf(str, 31, "ATA error: %d", rc);
231 lcd_puts(0, 1, str);
232 lcd_puts(0, 3, "Press ON to debug");
233 lcd_update();
234 while(!(button_get(true) & BUTTON_REL));
235 dbg_ports();
236 #endif
237 panicf("ata: %d", rc);
240 usb_start_monitoring();
242 /* FixMe: the same kind of mounting happens in usb.c, share the code. */
243 rc = disk_mount_all();
244 if (rc<=0)
246 lcd_clear_display();
247 lcd_puts(0, 0, "No partition");
248 lcd_puts(0, 1, "found.");
249 #ifdef HAVE_LCD_BITMAP
250 lcd_puts(0, 2, "Insert USB cable");
251 lcd_puts(0, 3, "and fix it.");
252 lcd_update();
253 #endif
254 while(button_get(true) != SYS_USB_CONNECTED) {};
255 usb_screen();
256 system_reboot();
259 settings_calc_config_sector();
260 settings_load(SETTINGS_ALL);
261 settings_apply();
263 status_init();
264 playlist_init();
265 tree_init();
267 /* No buffer allocation (see buffer.c) may take place after the call to
268 mpeg_init() since the mpeg thread takes the rest of the buffer space */
269 mp3_init( global_settings.volume,
270 global_settings.bass,
271 global_settings.treble,
272 global_settings.balance,
273 global_settings.loudness,
274 global_settings.avc,
275 global_settings.channel_config,
276 global_settings.stereo_width,
277 global_settings.mdb_strength,
278 global_settings.mdb_harmonics,
279 global_settings.mdb_center,
280 global_settings.mdb_shape,
281 global_settings.mdb_enable,
282 global_settings.superbass);
283 mpeg_init();
284 talk_init();
286 #ifdef AUTOROCK
287 if (!usb_detect())
289 int fd;
290 static const char filename[] = PLUGIN_DIR "/autostart.rock";
292 fd = open(filename, O_RDONLY);
293 if(fd >= 0) /* no complaint if it doesn't exit */
295 close(fd);
296 plugin_load((char*)filename, NULL); /* start if it does */
299 #endif /* #ifdef AUTOROCK */
302 int main(void)
304 app_main();
306 while(1) {
307 led(true); sleep(HZ/10);
308 led(false); sleep(HZ/10);
310 return 0;
312 #endif
313 #endif