Check if the file could be modified, error if not.
[Rockbox.git] / apps / main.c
blob537c3da4dcd693dbd330e8c4c6dccad0a7557679
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 #include "ata.h"
22 #include "disk.h"
23 #include "fat.h"
24 #include "lcd.h"
25 #include "rtc.h"
26 #include "debug.h"
27 #include "led.h"
28 #include "kernel.h"
29 #include "button.h"
30 #include "tree.h"
31 #include "panic.h"
32 #include "menu.h"
33 #include "system.h"
34 #include "usb.h"
35 #include "powermgmt.h"
36 #include "adc.h"
37 #include "i2c.h"
38 #ifndef DEBUG
39 #include "serial.h"
40 #endif
41 #include "audio.h"
42 #include "mp3_playback.h"
43 #include "main_menu.h"
44 #include "thread.h"
45 #include "settings.h"
46 #include "backlight.h"
47 #include "status.h"
48 #include "debug_menu.h"
49 #include "version.h"
50 #include "sprintf.h"
51 #include "font.h"
52 #include "language.h"
53 #include "wps-display.h"
54 #include "playlist.h"
55 #include "buffer.h"
56 #include "rolo.h"
57 #include "screens.h"
58 #include "power.h"
59 #include "talk.h"
60 #include "plugin.h"
61 #include "misc.h"
63 #if (CONFIG_HWCODEC == MASNONE)
64 #include "pcm_playback.h"
65 #endif
67 #ifdef CONFIG_TUNER
68 #include "radio.h"
69 #endif
70 #ifdef HAVE_MMC
71 #include "ata_mmc.h"
72 #endif
74 #ifdef HAVE_REMOTE_LCD
75 #include "lcd-remote.h"
76 #endif
78 /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
80 const char appsversion[]=APPSVERSION;
82 void init(void);
84 void app_main(void)
86 init();
87 browse_root();
90 #ifdef SIMULATOR
92 void init(void)
94 init_threads();
95 buffer_init();
96 lcd_init();
97 font_init();
98 show_logo();
99 lang_init();
100 settings_reset();
101 settings_calc_config_sector();
102 settings_load(SETTINGS_ALL);
103 settings_apply();
104 sleep(HZ/2);
105 tree_init();
106 playlist_init();
107 mp3_init( global_settings.volume,
108 global_settings.bass,
109 global_settings.treble,
110 global_settings.balance,
111 global_settings.loudness,
112 global_settings.avc,
113 global_settings.channel_config,
114 global_settings.stereo_width,
115 global_settings.mdb_strength,
116 global_settings.mdb_harmonics,
117 global_settings.mdb_center,
118 global_settings.mdb_shape,
119 global_settings.mdb_enable,
120 global_settings.superbass);
121 audio_init();
122 button_clear_queue(); /* Empty the keyboard buffer */
125 #else
127 void init(void)
129 int rc;
130 bool mounted = false;
131 #if defined(HAVE_CHARGING) && (CONFIG_CPU == SH7034)
132 /* if nobody initialized ATA before, I consider this a cold start */
133 bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */
134 #endif
135 system_init();
136 kernel_init();
138 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
139 set_cpu_frequency(CPUFREQ_NORMAL);
140 #endif
142 buffer_init();
144 settings_reset();
146 lcd_init();
148 #ifdef HAVE_REMOTE_LCD
149 lcd_remote_init();
150 #endif
152 font_init();
153 show_logo();
154 lang_init();
156 set_irq_level(0);
157 #ifdef DEBUG
158 debug_init();
159 #else
160 #ifndef HAVE_MMC /* FIXME: This is also necessary for debug builds
161 * (do debug builds on the Ondio make sense?) */
162 serial_setup();
163 #endif
164 #endif
166 i2c_init();
168 #ifdef HAVE_RTC
169 rtc_init();
170 settings_load(SETTINGS_RTC); /* early load parts of global_settings */
171 #endif
173 adc_init();
175 usb_init();
177 backlight_init();
179 button_init();
181 powermgmt_init();
183 #ifdef CONFIG_TUNER
184 radio_init();
185 #endif
187 #if defined(HAVE_CHARGING) && (CONFIG_CPU == SH7034)
188 if (coldstart && charger_inserted()
189 && !global_settings.car_adapter_mode
190 #ifdef ATA_POWER_PLAYERSTYLE
191 && !ide_powered() /* relies on probing result from bootloader */
192 #endif
195 rc = charging_screen(); /* display a "charging" screen */
196 if (rc == 1 || rc == 2) /* charger removed or "Off/Stop" pressed */
197 power_off();
198 /* "On" pressed or USB connected: proceed */
199 show_logo(); /* again, to provide better visual feedback */
201 #endif
203 rc = ata_init();
204 if(rc)
206 #ifdef HAVE_LCD_BITMAP
207 char str[32];
208 lcd_clear_display();
209 snprintf(str, 31, "ATA error: %d", rc);
210 lcd_puts(0, 1, str);
211 lcd_puts(0, 3, "Press ON to debug");
212 lcd_update();
213 while(!(button_get(true) & BUTTON_REL));
214 dbg_ports();
215 #endif
216 panicf("ata: %d", rc);
219 usb_start_monitoring();
220 while (usb_detect())
221 { /* enter USB mode early, before trying to mount */
222 if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED)
223 #ifdef HAVE_MMC
224 if (!mmc_touched() || (mmc_remove_request() == SYS_MMC_EXTRACTED))
225 #endif
227 usb_screen();
228 mounted = true; /* mounting done @ end of USB mode */
232 if (!mounted)
234 rc = disk_mount_all();
235 if (rc<=0)
237 lcd_clear_display();
238 lcd_puts(0, 0, "No partition");
239 lcd_puts(0, 1, "found.");
240 #ifdef HAVE_LCD_BITMAP
241 lcd_puts(0, 2, "Insert USB cable");
242 lcd_puts(0, 3, "and fix it.");
243 lcd_update();
244 #endif
245 while(button_get(true) != SYS_USB_CONNECTED) {};
246 usb_screen();
247 system_reboot();
251 settings_calc_config_sector();
252 settings_load(SETTINGS_ALL);
253 settings_apply();
255 status_init();
256 playlist_init();
257 tree_init();
259 /* No buffer allocation (see buffer.c) may take place after the call to
260 audio_init() since the mpeg thread takes the rest of the buffer space */
261 mp3_init( global_settings.volume,
262 global_settings.bass,
263 global_settings.treble,
264 global_settings.balance,
265 global_settings.loudness,
266 global_settings.avc,
267 global_settings.channel_config,
268 global_settings.stereo_width,
269 global_settings.mdb_strength,
270 global_settings.mdb_harmonics,
271 global_settings.mdb_center,
272 global_settings.mdb_shape,
273 global_settings.mdb_enable,
274 global_settings.superbass);
275 audio_init();
276 talk_init();
278 #ifdef AUTOROCK
279 if (!usb_detect())
281 int fd;
282 static const char filename[] = PLUGIN_DIR "/autostart.rock";
284 fd = open(filename, O_RDONLY);
285 if(fd >= 0) /* no complaint if it doesn't exit */
287 close(fd);
288 plugin_load((char*)filename, NULL); /* start if it does */
291 #endif /* #ifdef AUTOROCK */
293 #if (CONFIG_HWCODEC == MASNONE)
294 pcm_init();
295 #endif
296 #ifdef HAVE_CHARGING
297 car_adapter_mode_init();
298 #endif
301 int main(void)
303 app_main();
305 while(1) {
306 led(true); sleep(HZ/10);
307 led(false); sleep(HZ/10);
309 return 0;
311 #endif