Checkwps: give wps_screen an initial value
[kugel-rb.git] / apps / debug_menu.c
blob6307a5028360900d3695a9472cf0e0a50fcd4a6a
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Heikki Hannikainen
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <stdbool.h>
26 #include <string.h>
27 #include "lcd.h"
28 #include "menu.h"
29 #include "debug_menu.h"
30 #include "kernel.h"
31 #include "sprintf.h"
32 #include "structec.h"
33 #include "action.h"
34 #include "debug.h"
35 #include "thread.h"
36 #include "powermgmt.h"
37 #include "system.h"
38 #include "font.h"
39 #include "audio.h"
40 #include "mp3_playback.h"
41 #include "settings.h"
42 #include "list.h"
43 #include "statusbar.h"
44 #include "dir.h"
45 #include "panic.h"
46 #include "screens.h"
47 #include "misc.h"
48 #include "splash.h"
49 #include "dircache.h"
50 #include "viewport.h"
51 #ifdef HAVE_TAGCACHE
52 #include "tagcache.h"
53 #endif
54 #include "lcd-remote.h"
55 #include "crc32.h"
56 #include "logf.h"
57 #ifndef SIMULATOR
58 #include "disk.h"
59 #include "adc.h"
60 #include "power.h"
61 #include "usb.h"
62 #include "rtc.h"
63 #include "storage.h"
64 #include "fat.h"
65 #include "mas.h"
66 #include "eeprom_24cxx.h"
67 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
68 #include "hotswap.h"
69 #endif
70 #if (CONFIG_STORAGE & STORAGE_ATA)
71 #include "ata.h"
72 #endif
73 #if CONFIG_TUNER
74 #include "tuner.h"
75 #include "radio.h"
76 #endif
77 #endif
79 #ifdef HAVE_LCD_BITMAP
80 #include "scrollbar.h"
81 #include "peakmeter.h"
82 #endif
83 #include "logfdisp.h"
84 #if CONFIG_CODEC == SWCODEC
85 #include "pcmbuf.h"
86 #include "buffering.h"
87 #include "playback.h"
88 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
89 #include "spdif.h"
90 #endif
91 #endif
92 #ifdef IRIVER_H300_SERIES
93 #include "pcf50606.h" /* for pcf50606_read */
94 #endif
95 #ifdef IAUDIO_X5
96 #include "ds2411.h"
97 #endif
98 #include "hwcompat.h"
99 #include "button.h"
100 #if CONFIG_RTC == RTC_PCF50605
101 #include "pcf50605.h"
102 #endif
103 #include "appevents.h"
105 #if CONFIG_CPU == DM320 || CONFIG_CPU == S3C2440 || CONFIG_CPU == TCC7801 \
106 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 || CONFIG_CPU == JZ4732
107 #include "debug-target.h"
108 #endif
110 #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) \
111 || defined(SANSA_CLIP) || defined(SANSA_FUZE)
112 #include "ascodec.h"
113 #include "as3514.h"
114 #endif
116 #ifdef HAVE_USBSTACK
117 #include "usb_core.h"
118 #endif
120 /*---------------------------------------------------*/
121 /* SPECIAL DEBUG STUFF */
122 /*---------------------------------------------------*/
123 extern struct thread_entry threads[MAXTHREADS];
125 static char thread_status_char(unsigned status)
127 static const char thread_status_chars[THREAD_NUM_STATES+1] =
129 [0 ... THREAD_NUM_STATES] = '?',
130 [STATE_RUNNING] = 'R',
131 [STATE_BLOCKED] = 'B',
132 [STATE_SLEEPING] = 'S',
133 [STATE_BLOCKED_W_TMO] = 'T',
134 [STATE_FROZEN] = 'F',
135 [STATE_KILLED] = 'K',
138 if (status > THREAD_NUM_STATES)
139 status = THREAD_NUM_STATES;
141 return thread_status_chars[status];
144 static const char* threads_getname(int selected_item, void *data,
145 char *buffer, size_t buffer_len)
147 (void)data;
148 struct thread_entry *thread;
149 char name[32];
151 #if NUM_CORES > 1
152 if (selected_item < (int)NUM_CORES)
154 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
155 idle_stack_usage(selected_item));
156 return buffer;
159 selected_item -= NUM_CORES;
160 #endif
162 thread = &threads[selected_item];
164 if (thread->state == STATE_KILLED)
166 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
167 return buffer;
170 thread_get_name(name, 32, thread);
172 snprintf(buffer, buffer_len,
173 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
174 selected_item,
175 IF_COP(thread->core,)
176 #ifdef HAVE_SCHEDULER_BOOSTCTRL
177 (thread->cpu_boost) ? '+' :
178 #endif
179 ((thread->state == STATE_RUNNING) ? '*' : ' '),
180 thread_status_char(thread->state),
181 IF_PRIO(thread->base_priority, thread->priority, )
182 thread_stack_usage(thread), name);
184 return buffer;
187 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
189 (void)lists;
190 #ifdef ROCKBOX_HAS_LOGF
191 if (action == ACTION_STD_OK)
193 int selpos = gui_synclist_get_sel_pos(lists);
194 #if NUM_CORES > 1
195 if (selpos >= NUM_CORES)
196 remove_thread(threads[selpos - NUM_CORES].id);
197 #else
198 remove_thread(threads[selpos].id);
199 #endif
200 return ACTION_REDRAW;
202 #endif /* ROCKBOX_HAS_LOGF */
203 if (action == ACTION_NONE)
204 action = ACTION_REDRAW;
205 return action;
207 /* Test code!!! */
208 static bool dbg_os(void)
210 struct simplelist_info info;
211 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
212 #if NUM_CORES == 1
213 MAXTHREADS,
214 #else
215 MAXTHREADS+NUM_CORES,
216 #endif
217 NULL);
218 #ifndef ROCKBOX_HAS_LOGF
219 info.hide_selection = true;
220 info.scroll_all = true;
221 #endif
222 info.action_callback = dbg_threads_action_callback;
223 info.get_name = threads_getname;
224 return simplelist_show_list(&info);
227 #ifdef HAVE_LCD_BITMAP
228 #if CONFIG_CODEC != SWCODEC
229 #ifndef SIMULATOR
230 static bool dbg_audio_thread(void)
232 char buf[32];
233 struct audio_debug d;
235 lcd_setfont(FONT_SYSFIXED);
237 while(1)
239 if (action_userabort(HZ/5))
240 return false;
242 audio_get_debugdata(&d);
244 lcd_clear_display();
246 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
247 lcd_puts(0, 0, buf);
248 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
249 lcd_puts(0, 1, buf);
250 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
251 lcd_puts(0, 2, buf);
252 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
253 lcd_puts(0, 3, buf);
254 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
255 lcd_puts(0, 4, buf);
256 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
257 lcd_puts(0, 5, buf);
259 /* Playable space left */
260 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
261 d.playable_space, HORIZONTAL);
263 /* Show the watermark limit */
264 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
265 d.low_watermark_level, HORIZONTAL);
267 snprintf(buf, sizeof(buf), "wm: %x - %x",
268 d.low_watermark_level, d.lowest_watermark_level);
269 lcd_puts(0, 7, buf);
271 lcd_update();
273 lcd_setfont(FONT_UI);
274 return false;
276 #endif /* !SIMULATOR */
277 #else /* CONFIG_CODEC == SWCODEC */
278 extern size_t filebuflen;
279 /* This is a size_t, but call it a long so it puts a - when it's bad. */
281 static unsigned int ticks, boost_ticks, freq_sum;
283 static void dbg_audio_task(void)
285 #ifndef SIMULATOR
286 if(FREQ > CPUFREQ_NORMAL)
287 boost_ticks++;
288 freq_sum += FREQ/1000000; /* in MHz */
289 #endif
290 ticks++;
293 static bool dbg_buffering_thread(void)
295 char buf[32];
296 int button;
297 int line;
298 bool done = false;
299 size_t bufused;
300 size_t bufsize = pcmbuf_get_bufsize();
301 int pcmbufdescs = pcmbuf_descs();
302 struct buffering_debug d;
304 ticks = boost_ticks = freq_sum = 0;
306 tick_add_task(dbg_audio_task);
308 lcd_setfont(FONT_SYSFIXED);
309 while(!done)
311 button = get_action(CONTEXT_STD,HZ/5);
312 switch(button)
314 case ACTION_STD_NEXT:
315 audio_next();
316 break;
317 case ACTION_STD_PREV:
318 audio_prev();
319 break;
320 case ACTION_STD_CANCEL:
321 done = true;
322 break;
325 buffering_get_debugdata(&d);
327 line = 0;
328 lcd_clear_display();
330 bufused = bufsize - pcmbuf_free();
332 snprintf(buf, sizeof(buf), "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
333 lcd_puts(0, line++, buf);
335 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
336 bufsize, 0, bufused, HORIZONTAL);
337 line++;
339 snprintf(buf, sizeof(buf), "alloc: %6ld/%ld", audio_filebufused(),
340 (long) filebuflen);
341 lcd_puts(0, line++, buf);
343 #if LCD_HEIGHT > 80
344 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
345 filebuflen, 0, audio_filebufused(), HORIZONTAL);
346 line++;
348 snprintf(buf, sizeof(buf), "real: %6ld/%ld", (long)d.buffered_data,
349 (long)filebuflen);
350 lcd_puts(0, line++, buf);
352 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
353 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
354 line++;
355 #endif
357 snprintf(buf, sizeof(buf), "usefl: %6ld/%ld", (long)(d.useful_data),
358 (long)filebuflen);
359 lcd_puts(0, line++, buf);
361 #if LCD_HEIGHT > 80
362 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
363 filebuflen, 0, d.useful_data, HORIZONTAL);
364 line++;
365 #endif
367 snprintf(buf, sizeof(buf), "data_rem: %ld", (long)d.data_rem);
368 lcd_puts(0, line++, buf);
370 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
371 lcd_puts(0, line++, buf);
373 snprintf(buf, sizeof(buf), "handle count: %d", (int)d.num_handles);
374 lcd_puts(0, line++, buf);
376 #ifndef SIMULATOR
377 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
378 (int)((FREQ + 500000) / 1000000));
379 lcd_puts(0, line++, buf);
380 #endif
382 if (ticks > 0)
384 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
385 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
386 snprintf(buf, sizeof(buf), "boost:%3d.%d%% (%d.%dMHz)",
387 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
388 lcd_puts(0, line++, buf);
391 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
392 pcmbuf_used_descs(), pcmbufdescs);
393 lcd_puts(0, line++, buf);
394 snprintf(buf, sizeof(buf), "watermark: %6d",
395 (int)(d.watermark));
396 lcd_puts(0, line++, buf);
398 lcd_update();
401 tick_remove_task(dbg_audio_task);
402 lcd_setfont(FONT_UI);
404 return false;
406 #endif /* CONFIG_CODEC */
407 #endif /* HAVE_LCD_BITMAP */
410 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
411 /* Tool function to read the flash manufacturer and type, if available.
412 Only chips which could be reprogrammed in system will return values.
413 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
414 /* In IRAM to avoid problems when running directly from Flash */
415 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
416 unsigned addr1, unsigned addr2)
417 ICODE_ATTR __attribute__((noinline));
418 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
419 unsigned addr1, unsigned addr2)
422 unsigned not_manu, not_id; /* read values before switching to ID mode */
423 unsigned manu, id; /* read values when in ID mode */
425 #if CONFIG_CPU == SH7034
426 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
427 #elif defined(CPU_COLDFIRE)
428 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
429 #endif
430 int old_level; /* saved interrupt level */
432 not_manu = flash[0]; /* read the normal content */
433 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
435 /* disable interrupts, prevent any stray flash access */
436 old_level = disable_irq_save();
438 flash[addr1] = 0xAA; /* enter command mode */
439 flash[addr2] = 0x55;
440 flash[addr1] = 0x90; /* ID command */
441 /* Atmel wants 20ms pause here */
442 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
444 manu = flash[0]; /* read the IDs */
445 id = flash[1];
447 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
448 /* Atmel wants 20ms pause here */
449 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
451 restore_irq(old_level); /* enable interrupts again */
453 /* I assume success if the obtained values are different from
454 the normal flash content. This is not perfectly bulletproof, they
455 could theoretically be the same by chance, causing us to fail. */
456 if (not_manu != manu || not_id != id) /* a value has changed */
458 *p_manufacturer = manu; /* return the results */
459 *p_device = id;
460 return true; /* success */
462 return false; /* fail */
464 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
466 #ifndef SIMULATOR
467 #ifdef CPU_PP
468 static int perfcheck(void)
470 int result;
472 asm (
473 "mrs r2, CPSR \n"
474 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
475 "msr CPSR_c, r0 \n"
476 "mov %[res], #0 \n"
477 "ldr r0, [%[timr]] \n"
478 "add r0, r0, %[tmo] \n"
479 "1: \n"
480 "add %[res], %[res], #1 \n"
481 "ldr r1, [%[timr]] \n"
482 "cmp r1, r0 \n"
483 "bmi 1b \n"
484 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
486 [res]"=&r"(result)
488 [timr]"r"(&USEC_TIMER),
489 [tmo]"r"(
490 #if CONFIG_CPU == PP5002
491 16000
492 #else /* PP5020/5022/5024 */
493 10226
494 #endif
497 "r0", "r1", "r2"
499 return result;
501 #endif
503 #ifdef HAVE_LCD_BITMAP
504 static bool dbg_hw_info(void)
506 #if CONFIG_CPU == SH7034
507 char buf[32];
508 int bitmask = HW_MASK;
509 int rom_version = ROM_VERSION;
510 unsigned manu, id; /* flash IDs */
511 bool got_id; /* flag if we managed to get the flash IDs */
512 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
513 bool has_bootrom; /* flag for boot ROM present */
514 int oldmode; /* saved memory guard mode */
516 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
518 /* get flash ROM type */
519 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
520 if (!got_id)
521 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
523 /* check if the boot ROM area is a flash mirror */
524 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
525 if (has_bootrom) /* if ROM and Flash different */
527 /* calculate CRC16 checksum of boot ROM */
528 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
531 system_memory_guard(oldmode); /* re-enable memory guard */
533 lcd_setfont(FONT_SYSFIXED);
534 lcd_clear_display();
536 lcd_puts(0, 0, "[Hardware info]");
538 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
539 lcd_puts(0, 1, buf);
541 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
542 lcd_puts(0, 2, buf);
544 if (got_id)
545 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
546 else
547 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
548 lcd_puts(0, 3, buf);
550 if (has_bootrom)
552 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
553 snprintf(buf, 32, "Boot ROM: V1");
554 else
555 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
557 else
559 snprintf(buf, 32, "Boot ROM: none");
561 lcd_puts(0, 4, buf);
563 lcd_update();
565 while (!(action_userabort(TIMEOUT_BLOCK)));
567 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
568 char buf[32];
569 unsigned manu, id; /* flash IDs */
570 int got_id; /* flag if we managed to get the flash IDs */
571 int oldmode; /* saved memory guard mode */
572 int line = 0;
574 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
576 /* get flash ROM type */
577 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
578 if (!got_id)
579 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
581 system_memory_guard(oldmode); /* re-enable memory guard */
583 lcd_setfont(FONT_SYSFIXED);
584 lcd_clear_display();
586 lcd_puts(0, line++, "[Hardware info]");
588 if (got_id)
589 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
590 else
591 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
592 lcd_puts(0, line++, buf);
594 #ifdef IAUDIO_X5
596 struct ds2411_id id;
598 lcd_puts(0, ++line, "Serial Number:");
600 got_id = ds2411_read_id(&id);
602 if (got_id == DS2411_OK)
604 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
605 lcd_puts(0, ++line, buf);
606 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
607 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
608 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
609 lcd_puts(0, ++line, buf);
610 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
612 else
614 snprintf(buf, 32, "READ ERR=%d", got_id);
617 lcd_puts(0, ++line, buf);
619 #endif
621 lcd_update();
623 while (!(action_userabort(TIMEOUT_BLOCK)));
625 #elif defined(CPU_PP502x)
626 int line = 0;
627 char buf[32];
628 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
629 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
630 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
631 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
633 lcd_setfont(FONT_SYSFIXED);
634 lcd_clear_display();
636 lcd_puts(0, line++, "[Hardware info]");
638 #ifdef IPOD_ARCH
639 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
640 lcd_puts(0, line++, buf);
641 #endif
643 #ifdef IPOD_COLOR
644 extern int lcd_type; /* Defined in lcd-colornano.c */
646 snprintf(buf, sizeof(buf), "LCD type: %d", lcd_type);
647 lcd_puts(0, line++, buf);
648 #endif
650 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
651 lcd_puts(0, line++, buf);
653 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
654 lcd_puts(0, line++, buf);
656 lcd_update();
658 while (!(action_userabort(TIMEOUT_BLOCK)));
660 #elif CONFIG_CPU == PP5002
661 int line = 0;
662 char buf[32];
663 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
664 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
665 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
666 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
669 lcd_setfont(FONT_SYSFIXED);
670 lcd_clear_display();
672 lcd_puts(0, line++, "[Hardware info]");
674 #ifdef IPOD_ARCH
675 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
676 lcd_puts(0, line++, buf);
677 #endif
679 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
680 lcd_puts(0, line++, buf);
682 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
683 lcd_puts(0, line++, buf);
685 lcd_update();
687 while (!(action_userabort(TIMEOUT_BLOCK)));
689 #else
690 /* Define this function in your target tree */
691 return __dbg_hw_info();
692 #endif /* CONFIG_CPU */
693 lcd_setfont(FONT_UI);
694 return false;
696 #else /* !HAVE_LCD_BITMAP */
697 static bool dbg_hw_info(void)
699 char buf[32];
700 int button;
701 int currval = 0;
702 int rom_version = ROM_VERSION;
703 unsigned manu, id; /* flash IDs */
704 bool got_id; /* flag if we managed to get the flash IDs */
705 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
706 bool has_bootrom; /* flag for boot ROM present */
707 int oldmode; /* saved memory guard mode */
709 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
711 /* get flash ROM type */
712 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
713 if (!got_id)
714 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
716 /* check if the boot ROM area is a flash mirror */
717 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
718 if (has_bootrom) /* if ROM and Flash different */
720 /* calculate CRC16 checksum of boot ROM */
721 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
724 system_memory_guard(oldmode); /* re-enable memory guard */
726 lcd_clear_display();
728 lcd_puts(0, 0, "[HW Info]");
729 while(1)
731 switch(currval)
733 case 0:
734 snprintf(buf, 32, "ROM: %d.%02d",
735 rom_version/100, rom_version%100);
736 break;
737 case 1:
738 if (got_id)
739 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
740 else
741 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
742 break;
743 case 2:
744 if (has_bootrom)
746 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
747 snprintf(buf, 32, "BootROM: V1");
748 else if (rom_crc == 0x358099E8)
749 snprintf(buf, 32, "BootROM: V2");
750 /* alternative boot ROM found in one single player so far */
751 else
752 snprintf(buf, 32, "R: %08x", rom_crc);
754 else
755 snprintf(buf, 32, "BootROM: no");
758 lcd_puts(0, 1, buf);
759 lcd_update();
761 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
763 switch(button)
765 case ACTION_STD_CANCEL:
766 return false;
768 case ACTION_SETTINGS_DEC:
769 currval--;
770 if(currval < 0)
771 currval = 2;
772 break;
774 case ACTION_SETTINGS_INC:
775 currval++;
776 if(currval > 2)
777 currval = 0;
778 break;
781 return false;
783 #endif /* !HAVE_LCD_BITMAP */
784 #endif /* !SIMULATOR */
786 #ifndef SIMULATOR
787 static const char* dbg_partitions_getname(int selected_item, void *data,
788 char *buffer, size_t buffer_len)
790 (void)data;
791 int partition = selected_item/2;
792 struct partinfo* p = disk_partinfo(partition);
793 if (selected_item%2)
795 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / 2048);
797 else
799 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
801 return buffer;
804 bool dbg_partitions(void)
806 struct simplelist_info info;
807 simplelist_info_init(&info, "Partition Info", 4, NULL);
808 info.selection_size = 2;
809 info.hide_selection = true;
810 info.scroll_all = true;
811 info.get_name = dbg_partitions_getname;
812 return simplelist_show_list(&info);
814 #endif
816 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
817 static bool dbg_spdif(void)
819 char buf[128];
820 int line;
821 unsigned int control;
822 int x;
823 char *s;
824 int category;
825 int generation;
826 unsigned int interruptstat;
827 bool valnogood, symbolerr, parityerr;
828 bool done = false;
829 bool spdif_src_on;
830 int spdif_source = spdif_get_output_source(&spdif_src_on);
831 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
833 lcd_clear_display();
834 lcd_setfont(FONT_SYSFIXED);
836 #ifdef HAVE_SPDIF_POWER
837 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
838 #endif
840 while (!done)
842 line = 0;
844 control = EBU1RCVCCHANNEL1;
845 interruptstat = INTERRUPTSTAT;
846 INTERRUPTCLEAR = 0x03c00000;
848 valnogood = (interruptstat & 0x01000000)?true:false;
849 symbolerr = (interruptstat & 0x00800000)?true:false;
850 parityerr = (interruptstat & 0x00400000)?true:false;
852 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
853 valnogood?"--":"OK",
854 symbolerr?"--":"OK",
855 parityerr?"--":"OK");
856 lcd_puts(0, line++, buf);
858 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
859 lcd_puts(0, line++, buf);
861 line++;
863 x = control >> 31;
864 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
865 x, x?"Professional":"Consumer");
866 lcd_puts(0, line++, buf);
868 x = (control >> 30) & 1;
869 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
870 x, x?"Non-PCM":"PCM");
871 lcd_puts(0, line++, buf);
873 x = (control >> 29) & 1;
874 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
875 x, x?"Permitted":"Inhibited");
876 lcd_puts(0, line++, buf);
878 x = (control >> 27) & 7;
879 switch(x)
881 case 0:
882 s = "None";
883 break;
884 case 1:
885 s = "50/15us";
886 break;
887 default:
888 s = "Reserved";
889 break;
891 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
892 lcd_puts(0, line++, buf);
894 x = (control >> 24) & 3;
895 snprintf(buf, sizeof(buf), "Mode: %d", x);
896 lcd_puts(0, line++, buf);
898 category = (control >> 17) & 127;
899 switch(category)
901 case 0x00:
902 s = "General";
903 break;
904 case 0x40:
905 s = "Audio CD";
906 break;
907 default:
908 s = "Unknown";
910 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
911 lcd_puts(0, line++, buf);
913 x = (control >> 16) & 1;
914 generation = x;
915 if(((category & 0x70) == 0x10) ||
916 ((category & 0x70) == 0x40) ||
917 ((category & 0x78) == 0x38))
919 generation = !generation;
921 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
922 x, generation?"Original":"No ind.");
923 lcd_puts(0, line++, buf);
925 x = (control >> 12) & 15;
926 snprintf(buf, sizeof(buf), "Source: %d", x);
927 lcd_puts(0, line++, buf);
929 x = (control >> 8) & 15;
930 switch(x)
932 case 0:
933 s = "Unspecified";
934 break;
935 case 8:
936 s = "A (Left)";
937 break;
938 case 4:
939 s = "B (Right)";
940 break;
941 default:
942 s = "";
943 break;
945 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
946 lcd_puts(0, line++, buf);
948 x = (control >> 4) & 15;
949 switch(x)
951 case 0:
952 s = "44.1kHz";
953 break;
954 case 0x4:
955 s = "48kHz";
956 break;
957 case 0xc:
958 s = "32kHz";
959 break;
961 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
962 lcd_puts(0, line++, buf);
964 x = (control >> 2) & 3;
965 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
966 lcd_puts(0, line++, buf);
967 line++;
969 #ifndef SIMULATOR
970 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
971 spdif_measure_frequency());
972 lcd_puts(0, line++, buf);
973 #endif
975 lcd_update();
977 if (action_userabort(HZ/10))
978 break;
981 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
983 #ifdef HAVE_SPDIF_POWER
984 spdif_power_enable(global_settings.spdif_enable);
985 #endif
987 lcd_setfont(FONT_UI);
988 return false;
990 #endif /* CPU_COLDFIRE */
992 #ifndef SIMULATOR
993 #ifdef HAVE_LCD_BITMAP
994 /* button definitions */
995 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
996 (CONFIG_KEYPAD == IRIVER_H300_PAD)
997 # define DEBUG_CANCEL BUTTON_OFF
999 #elif CONFIG_KEYPAD == RECORDER_PAD
1000 # define DEBUG_CANCEL BUTTON_OFF
1002 #elif CONFIG_KEYPAD == ONDIO_PAD
1003 # define DEBUG_CANCEL BUTTON_MENU
1005 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
1006 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
1007 (CONFIG_KEYPAD == IPOD_4G_PAD)
1008 # define DEBUG_CANCEL BUTTON_MENU
1010 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
1011 # define DEBUG_CANCEL BUTTON_PLAY
1013 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
1014 # define DEBUG_CANCEL BUTTON_REC
1016 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1017 # define DEBUG_CANCEL BUTTON_RC_REC
1019 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
1020 # define DEBUG_CANCEL BUTTON_REW
1022 #elif (CONFIG_KEYPAD == MROBE100_PAD)
1023 # define DEBUG_CANCEL BUTTON_MENU
1025 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
1026 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
1027 (CONFIG_KEYPAD == SANSA_FUZE_PAD)
1028 # define DEBUG_CANCEL BUTTON_LEFT
1030 /* This is temporary until the SA9200 touchpad works */
1031 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) || \
1032 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD)
1033 # define DEBUG_CANCEL BUTTON_POWER
1035 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
1036 # define DEBUG_CANCEL BUTTON_PLAY
1038 #endif /* key definitions */
1040 /* Test code!!! */
1041 bool dbg_ports(void)
1043 #if CONFIG_CPU == SH7034
1044 char buf[32];
1045 int adc_battery_voltage, adc_battery_level;
1047 lcd_setfont(FONT_SYSFIXED);
1048 lcd_clear_display();
1050 while(1)
1052 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1053 lcd_puts(0, 0, buf);
1054 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1055 lcd_puts(0, 1, buf);
1057 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1058 lcd_puts(0, 2, buf);
1059 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1060 lcd_puts(0, 3, buf);
1061 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1062 lcd_puts(0, 4, buf);
1063 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1064 lcd_puts(0, 5, buf);
1066 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1067 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1068 adc_battery_voltage % 1000, adc_battery_level);
1069 lcd_puts(0, 6, buf);
1071 lcd_update();
1072 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1074 lcd_setfont(FONT_UI);
1075 return false;
1078 #elif defined(CPU_COLDFIRE)
1079 unsigned int gpio_out;
1080 unsigned int gpio1_out;
1081 unsigned int gpio_read;
1082 unsigned int gpio1_read;
1083 unsigned int gpio_function;
1084 unsigned int gpio1_function;
1085 unsigned int gpio_enable;
1086 unsigned int gpio1_enable;
1087 int adc_buttons, adc_remote;
1088 int adc_battery_voltage, adc_battery_level;
1089 char buf[128];
1090 int line;
1092 lcd_clear_display();
1093 lcd_setfont(FONT_SYSFIXED);
1095 while(1)
1097 line = 0;
1098 gpio_read = GPIO_READ;
1099 gpio1_read = GPIO1_READ;
1100 gpio_out = GPIO_OUT;
1101 gpio1_out = GPIO1_OUT;
1102 gpio_function = GPIO_FUNCTION;
1103 gpio1_function = GPIO1_FUNCTION;
1104 gpio_enable = GPIO_ENABLE;
1105 gpio1_enable = GPIO1_ENABLE;
1107 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1108 lcd_puts(0, line++, buf);
1109 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1110 lcd_puts(0, line++, buf);
1111 snprintf(buf, sizeof(buf), "GPIO_FUNC: %08x", gpio_function);
1112 lcd_puts(0, line++, buf);
1113 snprintf(buf, sizeof(buf), "GPIO_ENA: %08x", gpio_enable);
1114 lcd_puts(0, line++, buf);
1116 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1117 lcd_puts(0, line++, buf);
1118 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1119 lcd_puts(0, line++, buf);
1120 snprintf(buf, sizeof(buf), "GPIO1_FUNC: %08x", gpio1_function);
1121 lcd_puts(0, line++, buf);
1122 snprintf(buf, sizeof(buf), "GPIO1_ENA: %08x", gpio1_enable);
1123 lcd_puts(0, line++, buf);
1125 adc_buttons = adc_read(ADC_BUTTONS);
1126 adc_remote = adc_read(ADC_REMOTE);
1127 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1128 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1129 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1130 button_scan_enabled() ? '+' : '-', adc_buttons);
1131 #else
1132 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1133 #endif
1134 lcd_puts(0, line++, buf);
1135 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1136 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1137 remote_detect() ? '+' : '-', adc_remote);
1138 #else
1139 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1140 #endif
1141 lcd_puts(0, line++, buf);
1142 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1143 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1144 adc_read(ADC_REMOTEDETECT));
1145 lcd_puts(0, line++, buf);
1146 #endif
1148 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1149 adc_battery_voltage % 1000, adc_battery_level);
1150 lcd_puts(0, line++, buf);
1152 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1153 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1154 lcd_puts(0, line++, buf);
1155 #endif
1157 lcd_update();
1158 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1160 lcd_setfont(FONT_UI);
1161 return false;
1165 #elif defined(CPU_PP502x)
1167 char buf[128];
1168 int line;
1170 lcd_clear_display();
1171 lcd_setfont(FONT_SYSFIXED);
1173 while(1)
1175 line = 0;
1176 lcd_puts(0, line++, "GPIO STATES:");
1177 snprintf(buf, sizeof(buf), "A: %02x E: %02x I: %02x",
1178 (unsigned int)GPIOA_INPUT_VAL,
1179 (unsigned int)GPIOE_INPUT_VAL,
1180 (unsigned int)GPIOI_INPUT_VAL);
1181 lcd_puts(0, line++, buf);
1182 snprintf(buf, sizeof(buf), "B: %02x F: %02x J: %02x",
1183 (unsigned int)GPIOB_INPUT_VAL,
1184 (unsigned int)GPIOF_INPUT_VAL,
1185 (unsigned int)GPIOJ_INPUT_VAL);
1186 lcd_puts(0, line++, buf);
1187 snprintf(buf, sizeof(buf), "C: %02x G: %02x K: %02x",
1188 (unsigned int)GPIOC_INPUT_VAL,
1189 (unsigned int)GPIOG_INPUT_VAL,
1190 (unsigned int)GPIOK_INPUT_VAL);
1191 lcd_puts(0, line++, buf);
1192 snprintf(buf, sizeof(buf), "D: %02x H: %02x L: %02x",
1193 (unsigned int)GPIOD_INPUT_VAL,
1194 (unsigned int)GPIOH_INPUT_VAL,
1195 (unsigned int)GPIOL_INPUT_VAL);
1196 lcd_puts(0, line++, buf);
1197 line++;
1198 snprintf(buf, sizeof(buf), "GPO32_VAL: %08lx", GPO32_VAL);
1199 lcd_puts(0, line++, buf);
1200 snprintf(buf, sizeof(buf), "GPO32_EN: %08lx", GPO32_ENABLE);
1201 lcd_puts(0, line++, buf);
1202 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1203 lcd_puts(0, line++, buf);
1204 snprintf(buf, sizeof(buf), "DEV_EN2: %08lx", DEV_EN2);
1205 lcd_puts(0, line++, buf);
1206 snprintf(buf, sizeof(buf), "DEV_EN3: %08lx", inl(0x60006044));
1207 lcd_puts(0, line++, buf); /* to be verified */
1208 snprintf(buf, sizeof(buf), "DEV_INIT1: %08lx", DEV_INIT1);
1209 lcd_puts(0, line++, buf);
1210 snprintf(buf, sizeof(buf), "DEV_INIT2: %08lx", DEV_INIT2);
1211 lcd_puts(0, line++, buf);
1212 #ifdef ADC_ACCESSORY
1213 snprintf(buf, sizeof(buf), "ACCESSORY: %d", adc_read(ADC_ACCESSORY));
1214 lcd_puts(0, line++, buf);
1215 #endif
1217 #if defined(IPOD_ACCESSORY_PROTOCOL)
1218 extern unsigned char serbuf[];
1219 snprintf(buf, sizeof(buf), "IAP PACKET: %02x %02x %02x %02x %02x %02x %02x %02x",
1220 serbuf[0], serbuf[1], serbuf[2], serbuf[3], serbuf[4], serbuf[5],
1221 serbuf[6], serbuf[7]);
1222 lcd_puts(0, line++, buf);
1223 #endif
1225 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1226 line++;
1227 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1228 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1229 lcd_puts(0, line++, buf);
1230 snprintf(buf, sizeof(buf), "REM: %03x PAD: %03x",
1231 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1232 lcd_puts(0, line++, buf);
1233 #elif defined(PHILIPS_HDD1630)
1234 line++;
1235 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1236 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1237 lcd_puts(0, line++, buf);
1238 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1239 snprintf(buf, sizeof(buf), "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1240 lcd_puts(0, line++, buf);
1241 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1242 lcd_puts(0, line++, buf);
1243 snprintf(buf, sizeof(buf), "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1244 lcd_puts(0, line++, buf);
1245 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1246 lcd_puts(0, line++, buf);
1247 snprintf(buf, sizeof(buf), "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1248 lcd_puts(0, line++, buf);
1249 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1250 lcd_puts(0, line++, buf);
1251 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1252 lcd_puts(0, line++, buf);
1253 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1254 lcd_puts(0, line++, buf);
1255 snprintf(buf, sizeof(buf), "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1256 lcd_puts(0, line++, buf);
1257 snprintf(buf, sizeof(buf), "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1258 lcd_puts(0, line++, buf);
1259 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1260 lcd_puts(0, line++, buf);
1261 #if !defined(PHILIPS_SA9200)
1262 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1263 lcd_puts(0, line++, buf);
1264 snprintf(buf, sizeof(buf), "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1265 lcd_puts(0, line++, buf);
1266 #endif
1267 #endif
1268 lcd_update();
1269 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1271 lcd_setfont(FONT_UI);
1272 return false;
1276 #elif CONFIG_CPU == PP5002
1277 char buf[128];
1278 int line;
1280 lcd_clear_display();
1281 lcd_setfont(FONT_SYSFIXED);
1283 while(1)
1285 line = 0;
1286 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x",
1287 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1288 lcd_puts(0, line++, buf);
1289 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x",
1290 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1291 lcd_puts(0, line++, buf);
1293 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1294 lcd_puts(0, line++, buf);
1295 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1296 lcd_puts(0, line++, buf);
1297 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1298 lcd_puts(0, line++, buf);
1299 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1300 lcd_puts(0, line++, buf);
1301 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1302 lcd_puts(0, line++, buf);
1303 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1304 lcd_puts(0, line++, buf);
1305 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1306 lcd_puts(0, line++, buf);
1307 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1308 lcd_puts(0, line++, buf);
1310 lcd_update();
1311 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1313 lcd_setfont(FONT_UI);
1314 return false;
1317 lcd_setfont(FONT_UI);
1318 #else
1319 return __dbg_ports();
1320 #endif /* CPU */
1321 return false;
1323 #else /* !HAVE_LCD_BITMAP */
1324 bool dbg_ports(void)
1326 char buf[32];
1327 int button;
1328 int adc_battery_voltage;
1329 int currval = 0;
1331 lcd_clear_display();
1333 while(1)
1335 switch(currval)
1337 case 0:
1338 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1339 break;
1340 case 1:
1341 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1342 break;
1343 case 2:
1344 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1345 break;
1346 case 3:
1347 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1348 break;
1349 case 4:
1350 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1351 break;
1352 case 5:
1353 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1354 break;
1355 case 6:
1356 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1357 break;
1358 case 7:
1359 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1360 break;
1361 case 8:
1362 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1363 break;
1364 case 9:
1365 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1366 break;
1368 lcd_puts(0, 0, buf);
1370 battery_read_info(&adc_battery_voltage, NULL);
1371 snprintf(buf, 32, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1372 adc_battery_voltage % 1000);
1373 lcd_puts(0, 1, buf);
1374 lcd_update();
1376 button = get_action(CONTEXT_SETTINGS,HZ/5);
1378 switch(button)
1380 case ACTION_STD_CANCEL:
1381 return false;
1383 case ACTION_SETTINGS_DEC:
1384 currval--;
1385 if(currval < 0)
1386 currval = 9;
1387 break;
1389 case ACTION_SETTINGS_INC:
1390 currval++;
1391 if(currval > 9)
1392 currval = 0;
1393 break;
1396 return false;
1398 #endif /* !HAVE_LCD_BITMAP */
1399 #endif /* !SIMULATOR */
1401 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1402 static bool dbg_pcf(void)
1404 char buf[128];
1405 int line;
1407 #ifdef HAVE_LCD_BITMAP
1408 lcd_setfont(FONT_SYSFIXED);
1409 #endif
1410 lcd_clear_display();
1412 while(1)
1414 line = 0;
1416 snprintf(buf, sizeof(buf), "DCDC1: %02x", pcf50605_read(0x1b));
1417 lcd_puts(0, line++, buf);
1418 snprintf(buf, sizeof(buf), "DCDC2: %02x", pcf50605_read(0x1c));
1419 lcd_puts(0, line++, buf);
1420 snprintf(buf, sizeof(buf), "DCDC3: %02x", pcf50605_read(0x1d));
1421 lcd_puts(0, line++, buf);
1422 snprintf(buf, sizeof(buf), "DCDC4: %02x", pcf50605_read(0x1e));
1423 lcd_puts(0, line++, buf);
1424 snprintf(buf, sizeof(buf), "DCDEC1: %02x", pcf50605_read(0x1f));
1425 lcd_puts(0, line++, buf);
1426 snprintf(buf, sizeof(buf), "DCDEC2: %02x", pcf50605_read(0x20));
1427 lcd_puts(0, line++, buf);
1428 snprintf(buf, sizeof(buf), "DCUDC1: %02x", pcf50605_read(0x21));
1429 lcd_puts(0, line++, buf);
1430 snprintf(buf, sizeof(buf), "DCUDC2: %02x", pcf50605_read(0x22));
1431 lcd_puts(0, line++, buf);
1432 snprintf(buf, sizeof(buf), "IOREGC: %02x", pcf50605_read(0x23));
1433 lcd_puts(0, line++, buf);
1434 snprintf(buf, sizeof(buf), "D1REGC: %02x", pcf50605_read(0x24));
1435 lcd_puts(0, line++, buf);
1436 snprintf(buf, sizeof(buf), "D2REGC: %02x", pcf50605_read(0x25));
1437 lcd_puts(0, line++, buf);
1438 snprintf(buf, sizeof(buf), "D3REGC: %02x", pcf50605_read(0x26));
1439 lcd_puts(0, line++, buf);
1440 snprintf(buf, sizeof(buf), "LPREG1: %02x", pcf50605_read(0x27));
1441 lcd_puts(0, line++, buf);
1443 lcd_update();
1444 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1446 lcd_setfont(FONT_UI);
1447 return false;
1451 lcd_setfont(FONT_UI);
1452 return false;
1454 #endif
1456 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1457 static bool dbg_cpufreq(void)
1459 char buf[128];
1460 int line;
1461 int button;
1463 #ifdef HAVE_LCD_BITMAP
1464 lcd_setfont(FONT_SYSFIXED);
1465 #endif
1466 lcd_clear_display();
1468 while(1)
1470 line = 0;
1472 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1473 lcd_puts(0, line++, buf);
1475 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1476 lcd_puts(0, line++, buf);
1478 lcd_update();
1479 button = get_action(CONTEXT_STD,HZ/10);
1481 switch(button)
1483 case ACTION_STD_PREV:
1484 cpu_boost(true);
1485 break;
1487 case ACTION_STD_NEXT:
1488 cpu_boost(false);
1489 break;
1491 case ACTION_STD_OK:
1492 while (get_cpu_boost_counter() > 0)
1493 cpu_boost(false);
1494 set_cpu_frequency(CPUFREQ_DEFAULT);
1495 break;
1497 case ACTION_STD_CANCEL:
1498 lcd_setfont(FONT_UI);
1499 return false;
1502 lcd_setfont(FONT_UI);
1503 return false;
1505 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1507 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1508 #include "tsc2100.h"
1509 static char *itob(int n, int len)
1511 static char binary[64];
1512 int i,j;
1513 for (i=1, j=0;i<=len;i++)
1515 binary[j++] = n&(1<<(len-i))?'1':'0';
1516 if (i%4 == 0)
1517 binary[j++] = ' ';
1519 binary[j] = '\0';
1520 return binary;
1523 static const char* tsc2100_debug_getname(int selected_item, void * data,
1524 char *buffer, size_t buffer_len)
1526 int *page = (int*)data;
1527 bool reserved = false;
1528 switch (*page)
1530 case 0:
1531 if ((selected_item > 0x0a) ||
1532 (selected_item == 0x04) ||
1533 (selected_item == 0x08))
1534 reserved = true;
1535 break;
1536 case 1:
1537 if ((selected_item > 0x05) ||
1538 (selected_item == 0x02))
1539 reserved = true;
1540 break;
1541 case 2:
1542 if (selected_item > 0x1e)
1543 reserved = true;
1544 break;
1546 if (reserved)
1547 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1548 else
1549 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1550 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1551 return buffer;
1553 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1555 int *page = (int*)lists->data;
1556 if (action == ACTION_STD_OK)
1558 *page = (*page+1)%3;
1559 snprintf(lists->title, 32,
1560 "tsc2100 registers - Page %d", *page);
1561 return ACTION_REDRAW;
1563 return action;
1565 static bool tsc2100_debug(void)
1567 int page = 0;
1568 char title[32] = "tsc2100 registers - Page 0";
1569 struct simplelist_info info;
1570 simplelist_info_init(&info, title, 32, &page);
1571 info.timeout = HZ/100;
1572 info.get_name = tsc2100_debug_getname;
1573 info.action_callback= tsc2100debug_action_callback;
1574 return simplelist_show_list(&info);
1576 #endif
1577 #ifndef SIMULATOR
1578 #ifdef HAVE_LCD_BITMAP
1580 * view_battery() shows a automatically scaled graph of the battery voltage
1581 * over time. Usable for estimating battery life / charging rate.
1582 * The power_history array is updated in power_thread of powermgmt.c.
1585 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1586 #define BAT_YSPACE (LCD_HEIGHT - 20)
1588 static bool view_battery(void)
1590 int view = 0;
1591 int i, x, y;
1592 unsigned short maxv, minv;
1593 char buf[32];
1595 lcd_setfont(FONT_SYSFIXED);
1597 while(1)
1599 lcd_clear_display();
1600 switch (view) {
1601 case 0: /* voltage history graph */
1602 /* Find maximum and minimum voltage for scaling */
1603 minv = power_history[0];
1604 maxv = minv + 1;
1605 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1606 if (power_history[i] > maxv)
1607 maxv = power_history[i];
1608 if (power_history[i] < minv)
1609 minv = power_history[i];
1612 snprintf(buf, 30, "Battery %d.%03d", power_history[0] / 1000,
1613 power_history[0] % 1000);
1614 lcd_puts(0, 0, buf);
1615 snprintf(buf, 30, "scale %d.%03d-%d.%03dV",
1616 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1617 lcd_puts(0, 1, buf);
1619 x = 0;
1620 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1621 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1622 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1623 lcd_vline(x, LCD_HEIGHT-1, 20);
1624 lcd_set_drawmode(DRMODE_SOLID);
1625 lcd_vline(x, LCD_HEIGHT-1,
1626 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1627 x++;
1630 break;
1632 case 1: /* status: */
1633 lcd_puts(0, 0, "Power status:");
1635 battery_read_info(&y, NULL);
1636 snprintf(buf, 30, "Battery: %d.%03d V", y / 1000, y % 1000);
1637 lcd_puts(0, 1, buf);
1638 #ifdef ADC_EXT_POWER
1639 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1640 snprintf(buf, 30, "External: %d.%03d V", y / 1000, y % 1000);
1641 lcd_puts(0, 2, buf);
1642 #endif
1643 #if CONFIG_CHARGING
1644 #if defined ARCHOS_RECORDER
1645 snprintf(buf, 30, "Chgr: %s %s",
1646 charger_inserted() ? "present" : "absent",
1647 charger_enabled() ? "on" : "off");
1648 lcd_puts(0, 3, buf);
1649 snprintf(buf, 30, "short delta: %d", short_delta);
1650 lcd_puts(0, 5, buf);
1651 snprintf(buf, 30, "long delta: %d", long_delta);
1652 lcd_puts(0, 6, buf);
1653 lcd_puts(0, 7, power_message);
1654 snprintf(buf, 30, "USB Inserted: %s",
1655 usb_inserted() ? "yes" : "no");
1656 lcd_puts(0, 8, buf);
1657 #elif defined IRIVER_H300_SERIES
1658 snprintf(buf, 30, "USB Charging Enabled: %s",
1659 usb_charging_enabled() ? "yes" : "no");
1660 lcd_puts(0, 9, buf);
1661 #elif defined IPOD_NANO || defined IPOD_VIDEO
1662 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1663 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1664 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1665 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1666 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1668 snprintf(buf, 30, "USB pwr: %s",
1669 usb_pwr ? "present" : "absent");
1670 lcd_puts(0, 3, buf);
1671 snprintf(buf, 30, "EXT pwr: %s",
1672 ext_pwr ? "present" : "absent");
1673 lcd_puts(0, 4, buf);
1674 snprintf(buf, 30, "Battery: %s",
1675 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1676 lcd_puts(0, 5, buf);
1677 snprintf(buf, 30, "Dock mode: %s",
1678 dock ? "enabled" : "disabled");
1679 lcd_puts(0, 6, buf);
1680 snprintf(buf, 30, "Headphone: %s",
1681 headphone ? "connected" : "disconnected");
1682 lcd_puts(0, 7, buf);
1683 #elif defined TOSHIBA_GIGABEAT_S
1684 int line = 3;
1685 unsigned int st;
1687 static const unsigned char * const chrgstate_strings[] =
1689 "Disabled",
1690 "Error",
1691 "Discharging",
1692 "Precharge",
1693 "Constant Voltage",
1694 "Constant Current",
1695 "<unknown>",
1698 snprintf(buf, 30, "Charger: %s",
1699 charger_inserted() ? "present" : "absent");
1700 lcd_puts(0, line++, buf);
1702 st = power_input_status() &
1703 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1704 snprintf(buf, 30, "%s%s",
1705 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1706 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1707 lcd_puts(0, line++, buf);
1709 snprintf(buf, 30, "IUSB Max: %d", usb_allowed_current());
1710 lcd_puts(0, line++, buf);
1712 y = ARRAYLEN(chrgstate_strings) - 1;
1714 switch (charge_state)
1716 case CHARGE_STATE_DISABLED: y--;
1717 case CHARGE_STATE_ERROR: y--;
1718 case DISCHARGING: y--;
1719 case TRICKLE: y--;
1720 case TOPOFF: y--;
1721 case CHARGING: y--;
1722 default:;
1725 snprintf(buf, 30, "State: %s", chrgstate_strings[y]);
1726 lcd_puts(0, line++, buf);
1728 snprintf(buf, 30, "Battery Switch: %s",
1729 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1730 lcd_puts(0, line++, buf);
1732 y = chrgraw_adc_voltage();
1733 snprintf(buf, 30, "CHRGRAW: %d.%03d V",
1734 y / 1000, y % 1000);
1735 lcd_puts(0, line++, buf);
1737 y = application_supply_adc_voltage();
1738 snprintf(buf, 30, "BP : %d.%03d V",
1739 y / 1000, y % 1000);
1740 lcd_puts(0, line++, buf);
1742 y = battery_adc_charge_current();
1743 if (y < 0) x = '-', y = -y;
1744 else x = ' ';
1745 snprintf(buf, 30, "CHRGISN:%c%d mA", x, y);
1746 lcd_puts(0, line++, buf);
1748 y = cccv_regulator_dissipation();
1749 snprintf(buf, 30, "P CCCV : %d mW", y);
1750 lcd_puts(0, line++, buf);
1752 y = battery_charge_current();
1753 if (y < 0) x = '-', y = -y;
1754 else x = ' ';
1755 snprintf(buf, 30, "I Charge:%c%d mA", x, y);
1756 lcd_puts(0, line++, buf);
1758 y = battery_adc_temp();
1760 if (y != INT_MIN) {
1761 snprintf(buf, 30, "T Battery: %dC (%dF)", y,
1762 (9*y + 160) / 5);
1763 } else {
1764 /* Conversion disabled */
1765 snprintf(buf, 30, "T Battery: ?");
1768 lcd_puts(0, line++, buf);
1769 #elif defined(SANSA_E200) || defined(SANSA_C200) || defined(SANSA_CLIP) || defined(SANSA_FUZE)
1770 const int first = CHARGE_STATE_DISABLED;
1771 static const char * const chrgstate_strings[] =
1773 [CHARGE_STATE_DISABLED-first] = "Disabled",
1774 [CHARGE_STATE_ERROR-first] = "Error",
1775 [DISCHARGING-first] = "Discharging",
1776 [CHARGING-first] = "Charging",
1778 const char *str = NULL;
1780 snprintf(buf, 30, "Charger: %s",
1781 charger_inserted() ? "present" : "absent");
1782 lcd_puts(0, 3, buf);
1784 y = charge_state - first;
1785 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1786 str = chrgstate_strings[y];
1788 snprintf(buf, sizeof(buf), "State: %s",
1789 str ? str : "<unknown>");
1790 lcd_puts(0, 4, buf);
1792 snprintf(buf, sizeof(buf), "CHARGER: %02X",
1793 ascodec_read(AS3514_CHARGER));
1794 lcd_puts(0, 5, buf);
1795 #else
1796 snprintf(buf, 30, "Charger: %s",
1797 charger_inserted() ? "present" : "absent");
1798 lcd_puts(0, 3, buf);
1799 #endif /* target type */
1800 #endif /* CONFIG_CHARGING */
1801 break;
1803 case 2: /* voltage deltas: */
1804 lcd_puts(0, 0, "Voltage deltas:");
1806 for (i = 0; i <= 6; i++) {
1807 y = power_history[i] - power_history[i+1];
1808 snprintf(buf, 30, "-%d min: %s%d.%03d V", i,
1809 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1810 ((y < 0) ? y * -1 : y ) % 1000);
1811 lcd_puts(0, i+1, buf);
1813 break;
1815 case 3: /* remaining time estimation: */
1817 #ifdef ARCHOS_RECORDER
1818 snprintf(buf, 30, "charge_state: %d", charge_state);
1819 lcd_puts(0, 0, buf);
1821 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1822 lcd_puts(0, 1, buf);
1824 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1825 lcd_puts(0, 2, buf);
1827 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1828 lcd_puts(0, 3, buf);
1830 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1831 lcd_puts(0, 4, buf);
1832 #endif /* ARCHOS_RECORDER */
1834 snprintf(buf, 30, "Last PwrHist: %d.%03dV",
1835 power_history[0] / 1000,
1836 power_history[0] % 1000);
1837 lcd_puts(0, 5, buf);
1839 snprintf(buf, 30, "battery level: %d%%", battery_level());
1840 lcd_puts(0, 6, buf);
1842 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1843 lcd_puts(0, 7, buf);
1844 break;
1847 lcd_update();
1849 switch(get_action(CONTEXT_STD,HZ/2))
1851 case ACTION_STD_PREV:
1852 if (view)
1853 view--;
1854 break;
1856 case ACTION_STD_NEXT:
1857 if (view < 3)
1858 view++;
1859 break;
1861 case ACTION_STD_CANCEL:
1862 lcd_setfont(FONT_UI);
1863 return false;
1866 lcd_setfont(FONT_UI);
1867 return false;
1870 #endif /* HAVE_LCD_BITMAP */
1871 #endif
1873 #ifndef SIMULATOR
1874 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1876 #if (CONFIG_STORAGE & STORAGE_MMC)
1877 #define CARDTYPE "MMC"
1878 #elif (CONFIG_STORAGE & STORAGE_SD)
1879 #define CARDTYPE "microSD"
1880 #endif
1882 static int disk_callback(int btn, struct gui_synclist *lists)
1884 tCardInfo *card;
1885 int *cardnum = (int*)lists->data;
1886 unsigned char card_name[7];
1887 unsigned char pbuf[32];
1888 char *title = lists->title;
1889 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1890 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1891 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1892 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1893 #if (CONFIG_STORAGE & STORAGE_MMC)
1894 static const char *mmc_spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1895 "3.1-3.31", "4.0" };
1896 #endif
1898 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1900 #ifdef HAVE_HOTSWAP
1901 if (btn == ACTION_STD_OK)
1903 *cardnum ^= 0x1; /* change cards */
1905 #endif
1907 simplelist_set_line_count(0);
1909 card = card_get_info(*cardnum);
1911 if (card->initialized > 0)
1913 strlcpy(card_name, ((unsigned char*)card->cid) + 3, sizeof(card_name));
1914 simplelist_addline(SIMPLELIST_ADD_LINE,
1915 "%s Rev %d.%d", card_name,
1916 (int) card_extract_bits(card->cid, 55, 4),
1917 (int) card_extract_bits(card->cid, 51, 4));
1918 simplelist_addline(SIMPLELIST_ADD_LINE,
1919 "Prod: %d/%d",
1920 #if (CONFIG_STORAGE & STORAGE_SD)
1921 (int) card_extract_bits(card->cid, 11, 3),
1922 (int) card_extract_bits(card->cid, 19, 8) + 2000
1923 #elif (CONFIG_STORAGE & STORAGE_MMC)
1924 (int) card_extract_bits(card->cid, 15, 4),
1925 (int) card_extract_bits(card->cid, 11, 4) + 1997
1926 #endif
1928 simplelist_addline(SIMPLELIST_ADD_LINE,
1929 #if (CONFIG_STORAGE & STORAGE_SD)
1930 "Ser#: 0x%08lx",
1931 card_extract_bits(card->cid, 55, 32)
1932 #elif (CONFIG_STORAGE & STORAGE_MMC)
1933 "Ser#: 0x%04lx",
1934 card_extract_bits(card->cid, 47, 16)
1935 #endif
1938 simplelist_addline(SIMPLELIST_ADD_LINE, "M=%02x, "
1939 #if (CONFIG_STORAGE & STORAGE_SD)
1940 "O=%c%c",
1941 (int) card_extract_bits(card->cid, 127, 8),
1942 card_extract_bits(card->cid, 119, 8),
1943 card_extract_bits(card->cid, 111, 8)
1944 #elif (CONFIG_STORAGE & STORAGE_MMC)
1945 "O=%04x",
1946 (int) card_extract_bits(card->cid, 127, 8),
1947 (int) card_extract_bits(card->cid, 119, 16)
1948 #endif
1951 #if (CONFIG_STORAGE & STORAGE_MMC)
1952 int temp = card_extract_bits(card->csd, 125, 4);
1953 simplelist_addline(SIMPLELIST_ADD_LINE,
1954 "MMC v%s", temp < 5 ?
1955 mmc_spec_vers[temp] : "?.?");
1956 #endif
1957 simplelist_addline(SIMPLELIST_ADD_LINE,
1958 "Blocks: 0x%08lx", card->numblocks);
1959 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1960 kbit_units, false);
1961 simplelist_addline(SIMPLELIST_ADD_LINE,
1962 "Speed: %s", pbuf);
1963 output_dyn_value(pbuf, sizeof pbuf, card->taac,
1964 nsec_units, false);
1965 simplelist_addline(SIMPLELIST_ADD_LINE,
1966 "Taac: %s", pbuf);
1967 simplelist_addline(SIMPLELIST_ADD_LINE,
1968 "Nsac: %d clk", card->nsac);
1969 simplelist_addline(SIMPLELIST_ADD_LINE,
1970 "R2W: *%d", card->r2w_factor);
1971 simplelist_addline(SIMPLELIST_ADD_LINE,
1972 "IRmax: %d..%d mA",
1973 i_vmin[card_extract_bits(card->csd, 61, 3)],
1974 i_vmax[card_extract_bits(card->csd, 58, 3)]);
1975 simplelist_addline(SIMPLELIST_ADD_LINE,
1976 "IWmax: %d..%d mA",
1977 i_vmin[card_extract_bits(card->csd, 55, 3)],
1978 i_vmax[card_extract_bits(card->csd, 52, 3)]);
1980 else if (card->initialized == 0)
1982 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1984 #if (CONFIG_STORAGE & STORAGE_SD)
1985 else /* card->initialized < 0 */
1987 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1989 #endif
1990 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1991 gui_synclist_set_title(lists, title, Icon_NOICON);
1992 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1993 gui_synclist_select_item(lists, 0);
1994 btn = ACTION_REDRAW;
1996 return btn;
1998 #elif (CONFIG_STORAGE & STORAGE_ATA)
1999 static int disk_callback(int btn, struct gui_synclist *lists)
2001 (void)lists;
2002 int i;
2003 char buf[128];
2004 unsigned short* identify_info = ata_get_identify();
2005 bool timing_info_present = false;
2006 (void)btn;
2008 simplelist_set_line_count(0);
2010 for (i=0; i < 20; i++)
2011 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
2012 buf[40]=0;
2013 /* kill trailing space */
2014 for (i=39; i && buf[i]==' '; i--)
2015 buf[i] = 0;
2016 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
2017 for (i=0; i < 4; i++)
2018 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
2019 buf[8]=0;
2020 simplelist_addline(SIMPLELIST_ADD_LINE,
2021 "Firmware: %s", buf);
2022 snprintf(buf, sizeof buf, "%ld MB",
2023 ((unsigned long)identify_info[61] << 16 |
2024 (unsigned long)identify_info[60]) / 2048 );
2025 simplelist_addline(SIMPLELIST_ADD_LINE,
2026 "Size: %s", buf);
2027 unsigned long free;
2028 fat_size( IF_MV2(0,) NULL, &free );
2029 simplelist_addline(SIMPLELIST_ADD_LINE,
2030 "Free: %ld MB", free / 1024);
2031 simplelist_addline(SIMPLELIST_ADD_LINE,
2032 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
2033 i = identify_info[83] & (1<<3);
2034 simplelist_addline(SIMPLELIST_ADD_LINE,
2035 "Power mgmt: %s", i ? "enabled" : "unsupported");
2036 i = identify_info[83] & (1<<9);
2037 simplelist_addline(SIMPLELIST_ADD_LINE,
2038 "Noise mgmt: %s", i ? "enabled" : "unsupported");
2039 i = identify_info[82] & (1<<6);
2040 simplelist_addline(SIMPLELIST_ADD_LINE,
2041 "Read-ahead: %s", i ? "enabled" : "unsupported");
2042 timing_info_present = identify_info[53] & (1<<1);
2043 if(timing_info_present) {
2044 char pio3[2], pio4[2];pio3[1] = 0;
2045 pio4[1] = 0;
2046 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
2047 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
2048 simplelist_addline(SIMPLELIST_ADD_LINE,
2049 "PIO modes: 0 1 2 %s %s", pio3, pio4);
2051 else {
2052 simplelist_addline(SIMPLELIST_ADD_LINE,
2053 "No PIO mode info");
2055 timing_info_present = identify_info[53] & (1<<1);
2056 if(timing_info_present) {
2057 simplelist_addline(SIMPLELIST_ADD_LINE,
2058 "Cycle times %dns/%dns",
2059 identify_info[67],
2060 identify_info[68] );
2061 } else {
2062 simplelist_addline(SIMPLELIST_ADD_LINE,
2063 "No timing info");
2065 #ifdef HAVE_ATA_DMA
2066 if (identify_info[63] & (1<<0)) {
2067 char mdma0[2], mdma1[2], mdma2[2];
2068 mdma0[1] = mdma1[1] = mdma2[1] = 0;
2069 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
2070 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
2071 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
2072 simplelist_addline(SIMPLELIST_ADD_LINE,
2073 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
2074 simplelist_addline(SIMPLELIST_ADD_LINE,
2075 "MDMA Cycle times %dns/%dns",
2076 identify_info[65],
2077 identify_info[66] );
2079 else {
2080 simplelist_addline(SIMPLELIST_ADD_LINE,
2081 "No MDMA mode info");
2083 if (identify_info[53] & (1<<2)) {
2084 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2], udma6[2];
2085 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = udma6[1] = 0;
2086 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
2087 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
2088 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
2089 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
2090 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
2091 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
2092 udma6[0] = (identify_info[88] & (1<<6)) ? '6' : 0;
2093 simplelist_addline(SIMPLELIST_ADD_LINE,
2094 "UDMA modes: %s %s %s %s %s %s %s", udma0, udma1, udma2,
2095 udma3, udma4, udma5, udma6);
2097 else {
2098 simplelist_addline(SIMPLELIST_ADD_LINE,
2099 "No UDMA mode info");
2101 #endif /* HAVE_ATA_DMA */
2102 timing_info_present = identify_info[53] & (1<<1);
2103 if(timing_info_present) {
2104 i = identify_info[49] & (1<<11);
2105 simplelist_addline(SIMPLELIST_ADD_LINE,
2106 "IORDY support: %s", i ? "yes" : "no");
2107 i = identify_info[49] & (1<<10);
2108 simplelist_addline(SIMPLELIST_ADD_LINE,
2109 "IORDY disable: %s", i ? "yes" : "no");
2110 } else {
2111 simplelist_addline(SIMPLELIST_ADD_LINE,
2112 "No timing info");
2114 simplelist_addline(SIMPLELIST_ADD_LINE,
2115 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2116 #ifdef HAVE_ATA_DMA
2117 i = ata_get_dma_mode();
2118 if (i == 0) {
2119 simplelist_addline(SIMPLELIST_ADD_LINE,
2120 "DMA not enabled");
2121 } else {
2122 simplelist_addline(SIMPLELIST_ADD_LINE,
2123 "DMA mode: %s %c",
2124 (i & 0x40) ? "UDMA" : "MDMA",
2125 '0' + (i & 7));
2127 #endif /* HAVE_ATA_DMA */
2128 return btn;
2130 #else /* No SD, MMC or ATA */
2131 static int disk_callback(int btn, struct gui_synclist *lists)
2133 (void)btn;
2134 (void)lists;
2135 struct storage_info info;
2136 storage_get_info(0,&info);
2137 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
2138 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
2139 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
2140 simplelist_addline(SIMPLELIST_ADD_LINE,
2141 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
2142 unsigned long free;
2143 fat_size( IF_MV2(0,) NULL, &free );
2144 simplelist_addline(SIMPLELIST_ADD_LINE,
2145 "Free: %ld MB", free / 1024);
2146 simplelist_addline(SIMPLELIST_ADD_LINE,
2147 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2148 return btn;
2150 #endif
2152 #if (CONFIG_STORAGE & STORAGE_ATA)
2153 static bool dbg_identify_info(void)
2155 int fd = creat("/identify_info.bin");
2156 if(fd >= 0)
2158 #ifdef ROCKBOX_LITTLE_ENDIAN
2159 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
2160 #else
2161 write(fd, ata_get_identify(), SECTOR_SIZE);
2162 #endif
2163 close(fd);
2165 return false;
2167 #endif
2169 static bool dbg_disk_info(void)
2171 struct simplelist_info info;
2172 simplelist_info_init(&info, "Disk Info", 1, NULL);
2173 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
2174 char title[16];
2175 int card = 0;
2176 info.callback_data = (void*)&card;
2177 info.title = title;
2178 #endif
2179 info.action_callback = disk_callback;
2180 info.hide_selection = true;
2181 info.scroll_all = true;
2182 return simplelist_show_list(&info);
2184 #endif /* !SIMULATOR */
2186 #ifdef HAVE_DIRCACHE
2187 static int dircache_callback(int btn, struct gui_synclist *lists)
2189 (void)btn; (void)lists;
2190 simplelist_set_line_count(0);
2191 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
2192 dircache_is_enabled() ? "Yes" : "No");
2193 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
2194 dircache_get_cache_size());
2195 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
2196 global_status.dircache_size);
2197 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
2198 DIRCACHE_LIMIT);
2199 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
2200 dircache_get_reserve_used(), DIRCACHE_RESERVE);
2201 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2202 dircache_get_build_ticks() / HZ);
2203 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2204 dircache_get_entry_count());
2205 return btn;
2208 static bool dbg_dircache_info(void)
2210 struct simplelist_info info;
2211 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2212 info.action_callback = dircache_callback;
2213 info.hide_selection = true;
2214 info.scroll_all = true;
2215 return simplelist_show_list(&info);
2218 #endif /* HAVE_DIRCACHE */
2220 #ifdef HAVE_TAGCACHE
2221 static int database_callback(int btn, struct gui_synclist *lists)
2223 (void)lists;
2224 struct tagcache_stat *stat = tagcache_get_stat();
2225 static bool synced = false;
2227 simplelist_set_line_count(0);
2229 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2230 stat->initialized ? "Yes" : "No");
2231 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2232 stat->ready ? "Yes" : "No");
2233 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2234 stat->ramcache ? "Yes" : "No");
2235 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2236 stat->ramcache_used, stat->ramcache_allocated);
2237 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2238 stat->progress, stat->processed_entries);
2239 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2240 stat->curentry ? stat->curentry : "---");
2241 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2242 stat->commit_step);
2243 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2244 stat->commit_delayed ? "Yes" : "No");
2246 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2247 stat->queue_length);
2249 if (synced)
2251 synced = false;
2252 tagcache_screensync_event();
2255 if (!btn && stat->curentry)
2257 synced = true;
2258 return ACTION_REDRAW;
2261 if (btn == ACTION_STD_CANCEL)
2262 tagcache_screensync_enable(false);
2264 return btn;
2266 static bool dbg_tagcache_info(void)
2268 struct simplelist_info info;
2269 simplelist_info_init(&info, "Database Info", 8, NULL);
2270 info.action_callback = database_callback;
2271 info.hide_selection = true;
2272 info.scroll_all = true;
2274 /* Don't do nonblock here, must give enough processing time
2275 for tagcache thread. */
2276 /* info.timeout = TIMEOUT_NOBLOCK; */
2277 info.timeout = 1;
2278 tagcache_screensync_enable(true);
2279 return simplelist_show_list(&info);
2281 #endif
2283 #if CONFIG_CPU == SH7034
2284 static bool dbg_save_roms(void)
2286 int fd;
2287 int oldmode = system_memory_guard(MEMGUARD_NONE);
2289 fd = creat("/internal_rom_0000-FFFF.bin");
2290 if(fd >= 0)
2292 write(fd, (void *)0, 0x10000);
2293 close(fd);
2296 fd = creat("/internal_rom_2000000-203FFFF.bin");
2297 if(fd >= 0)
2299 write(fd, (void *)0x2000000, 0x40000);
2300 close(fd);
2303 system_memory_guard(oldmode);
2304 return false;
2306 #elif defined CPU_COLDFIRE
2307 static bool dbg_save_roms(void)
2309 int fd;
2310 int oldmode = system_memory_guard(MEMGUARD_NONE);
2312 #if defined(IRIVER_H100_SERIES)
2313 fd = creat("/internal_rom_000000-1FFFFF.bin");
2314 #elif defined(IRIVER_H300_SERIES)
2315 fd = creat("/internal_rom_000000-3FFFFF.bin");
2316 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2317 fd = creat("/internal_rom_000000-3FFFFF.bin");
2318 #endif
2319 if(fd >= 0)
2321 write(fd, (void *)0, FLASH_SIZE);
2322 close(fd);
2324 system_memory_guard(oldmode);
2326 #ifdef HAVE_EEPROM
2327 fd = creat("/internal_eeprom.bin");
2328 if (fd >= 0)
2330 int old_irq_level;
2331 char buf[EEPROM_SIZE];
2332 int err;
2334 old_irq_level = disable_irq_save();
2336 err = eeprom_24cxx_read(0, buf, sizeof buf);
2338 restore_irq(old_irq_level);
2340 if (err)
2341 splashf(HZ*3, "Eeprom read failure (%d)", err);
2342 else
2344 write(fd, buf, sizeof buf);
2347 close(fd);
2349 #endif
2351 return false;
2353 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
2354 static bool dbg_save_roms(void)
2356 int fd;
2358 fd = creat("/internal_rom_000000-0FFFFF.bin");
2359 if(fd >= 0)
2361 write(fd, (void *)0x20000000, FLASH_SIZE);
2362 close(fd);
2365 return false;
2367 #endif /* CPU */
2369 #ifndef SIMULATOR
2370 #if CONFIG_TUNER
2371 static int radio_callback(int btn, struct gui_synclist *lists)
2373 (void)lists;
2374 if (btn == ACTION_STD_CANCEL)
2375 return btn;
2376 simplelist_set_line_count(1);
2378 #if (CONFIG_TUNER & LV24020LP)
2379 simplelist_addline(SIMPLELIST_ADD_LINE,
2380 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2381 simplelist_addline(SIMPLELIST_ADD_LINE,
2382 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2383 simplelist_addline(SIMPLELIST_ADD_LINE,
2384 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2385 simplelist_addline(SIMPLELIST_ADD_LINE,
2386 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2387 simplelist_addline(SIMPLELIST_ADD_LINE,
2388 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2389 simplelist_addline(SIMPLELIST_ADD_LINE,
2390 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2391 simplelist_addline(SIMPLELIST_ADD_LINE,
2392 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2393 #endif /* LV24020LP */
2394 #if (CONFIG_TUNER & S1A0903X01)
2395 simplelist_addline(SIMPLELIST_ADD_LINE,
2396 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2397 /* This one doesn't return dynamic data atm */
2398 #endif /* S1A0903X01 */
2399 #if (CONFIG_TUNER & TEA5767)
2400 struct tea5767_dbg_info nfo;
2401 tea5767_dbg_info(&nfo);
2402 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2403 simplelist_addline(SIMPLELIST_ADD_LINE,
2404 " Read: %02X %02X %02X %02X %02X",
2405 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2406 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2407 (unsigned)nfo.read_regs[4]);
2408 simplelist_addline(SIMPLELIST_ADD_LINE,
2409 " Write: %02X %02X %02X %02X %02X",
2410 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2411 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2412 (unsigned)nfo.write_regs[4]);
2413 #endif /* TEA5767 */
2414 #if (CONFIG_TUNER & SI4700)
2415 struct si4700_dbg_info nfo;
2416 si4700_dbg_info(&nfo);
2417 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
2418 /* Registers */
2419 simplelist_addline(SIMPLELIST_ADD_LINE,
2420 "%04X %04X %04X %04X",
2421 (unsigned)nfo.regs[0], (unsigned)nfo.regs[1],
2422 (unsigned)nfo.regs[2], (unsigned)nfo.regs[3]);
2423 simplelist_addline(SIMPLELIST_ADD_LINE,
2424 "%04X %04X %04X %04X",
2425 (unsigned)nfo.regs[4], (unsigned)nfo.regs[5],
2426 (unsigned)nfo.regs[6], (unsigned)nfo.regs[7]);
2427 simplelist_addline(SIMPLELIST_ADD_LINE,
2428 "%04X %04X %04X %04X",
2429 (unsigned)nfo.regs[8], (unsigned)nfo.regs[9],
2430 (unsigned)nfo.regs[10], (unsigned)nfo.regs[11]);
2431 simplelist_addline(SIMPLELIST_ADD_LINE,
2432 "%04X %04X %04X %04X",
2433 (unsigned)nfo.regs[12], (unsigned)nfo.regs[13],
2434 (unsigned)nfo.regs[14], (unsigned)nfo.regs[15]);
2435 #endif /* SI4700 */
2436 return ACTION_REDRAW;
2438 static bool dbg_fm_radio(void)
2440 struct simplelist_info info;
2441 info.scroll_all = true;
2442 simplelist_info_init(&info, "FM Radio", 1, NULL);
2443 simplelist_set_line_count(0);
2444 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2445 radio_hardware_present() ? "yes" : "no");
2447 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2448 info.hide_selection = true;
2449 return simplelist_show_list(&info);
2451 #endif /* CONFIG_TUNER */
2452 #endif /* !SIMULATOR */
2454 #ifdef HAVE_LCD_BITMAP
2455 extern bool do_screendump_instead_of_usb;
2457 static bool dbg_screendump(void)
2459 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2460 splashf(HZ, "Screendump %s",
2461 do_screendump_instead_of_usb?"enabled":"disabled");
2462 return false;
2464 #endif /* HAVE_LCD_BITMAP */
2466 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2467 static bool dbg_set_memory_guard(void)
2469 static const struct opt_items names[MAXMEMGUARD] = {
2470 { "None", -1 },
2471 { "Flash ROM writes", -1 },
2472 { "Zero area (all)", -1 }
2474 int mode = system_memory_guard(MEMGUARD_KEEP);
2476 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2477 system_memory_guard(mode);
2479 return false;
2481 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2483 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2484 static bool dbg_write_eeprom(void)
2486 int fd;
2487 int rc;
2488 int old_irq_level;
2489 char buf[EEPROM_SIZE];
2490 int err;
2492 fd = open("/internal_eeprom.bin", O_RDONLY);
2494 if (fd >= 0)
2496 rc = read(fd, buf, EEPROM_SIZE);
2498 if(rc == EEPROM_SIZE)
2500 old_irq_level = disable_irq_save();
2502 err = eeprom_24cxx_write(0, buf, sizeof buf);
2503 if (err)
2504 splashf(HZ*3, "Eeprom write failure (%d)", err);
2505 else
2506 splash(HZ*3, "Eeprom written successfully");
2508 restore_irq(old_irq_level);
2510 else
2512 splashf(HZ*3, "File read error (%d)",rc);
2514 close(fd);
2516 else
2518 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2521 return false;
2523 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2524 #ifdef CPU_BOOST_LOGGING
2525 static bool cpu_boost_log(void)
2527 int i = 0,j=0;
2528 int count = cpu_boost_log_getcount();
2529 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2530 char *str;
2531 bool done;
2532 lcd_setfont(FONT_SYSFIXED);
2533 str = cpu_boost_log_getlog_first();
2534 while (i < count)
2536 lcd_clear_display();
2537 for(j=0; j<lines; j++,i++)
2539 if (!str)
2540 str = cpu_boost_log_getlog_next();
2541 if (str)
2543 if(strlen(str) > LCD_WIDTH/SYSFONT_WIDTH)
2544 lcd_puts_scroll(0, j, str);
2545 else
2546 lcd_puts(0, j,str);
2548 str = NULL;
2550 lcd_update();
2551 done = false;
2552 while (!done)
2554 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2556 case ACTION_STD_OK:
2557 case ACTION_STD_PREV:
2558 case ACTION_STD_NEXT:
2559 done = true;
2560 break;
2561 case ACTION_STD_CANCEL:
2562 i = count;
2563 done = true;
2564 break;
2568 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2569 lcd_setfont(FONT_UI);
2570 return false;
2572 #endif
2574 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2575 extern bool wheel_is_touched;
2576 extern int old_wheel_value;
2577 extern int new_wheel_value;
2578 extern int wheel_delta;
2579 extern unsigned int accumulated_wheel_delta;
2580 extern unsigned int wheel_velocity;
2582 static bool dbg_scrollwheel(void)
2584 char buf[64];
2585 unsigned int speed;
2587 lcd_setfont(FONT_SYSFIXED);
2589 while (1)
2591 if (action_userabort(HZ/10))
2592 break;
2594 lcd_clear_display();
2596 /* show internal variables of scrollwheel driver */
2597 snprintf(buf, sizeof(buf), "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2598 lcd_puts(0, 0, buf);
2599 snprintf(buf, sizeof(buf), "new position: %2d", new_wheel_value);
2600 lcd_puts(0, 1, buf);
2601 snprintf(buf, sizeof(buf), "old position: %2d", old_wheel_value);
2602 lcd_puts(0, 2, buf);
2603 snprintf(buf, sizeof(buf), "wheel delta: %2d", wheel_delta);
2604 lcd_puts(0, 3, buf);
2605 snprintf(buf, sizeof(buf), "accumulated delta: %2d", accumulated_wheel_delta);
2606 lcd_puts(0, 4, buf);
2607 snprintf(buf, sizeof(buf), "velo [deg/s]: %4d", (int)wheel_velocity);
2608 lcd_puts(0, 5, buf);
2610 /* show effective accelerated scrollspeed */
2611 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2612 snprintf(buf, sizeof(buf), "accel. speed: %4d", speed);
2613 lcd_puts(0, 6, buf);
2615 lcd_update();
2617 lcd_setfont(FONT_UI);
2618 return false;
2620 #endif
2622 #if defined (HAVE_USBSTACK)
2624 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2625 static bool toggle_usb_core_driver(int driver, char *msg)
2627 bool enabled = !usb_core_driver_enabled(driver);
2629 usb_core_enable_driver(driver,enabled);
2630 splashf(HZ, "%s %s", msg, enabled?"enabled":"disabled");
2632 return false;
2635 static bool toggle_usb_serial(void)
2637 return toggle_usb_core_driver(USB_DRIVER_SERIAL,"USB Serial");
2639 #endif
2641 #endif
2643 #if CONFIG_USBOTG == USBOTG_ISP1583
2644 extern int dbg_usb_num_items(void);
2645 extern const char* dbg_usb_item(int selected_item, void *data,
2646 char *buffer, size_t buffer_len);
2648 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2650 (void)lists;
2651 if (action == ACTION_NONE)
2652 action = ACTION_REDRAW;
2653 return action;
2656 static bool dbg_isp1583(void)
2658 struct simplelist_info isp1583;
2659 isp1583.scroll_all = true;
2660 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2661 isp1583.timeout = HZ/100;
2662 isp1583.hide_selection = true;
2663 isp1583.get_name = dbg_usb_item;
2664 isp1583.action_callback = isp1583_action_callback;
2665 return simplelist_show_list(&isp1583);
2667 #endif
2669 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2670 extern int pic_dbg_num_items(void);
2671 extern const char* pic_dbg_item(int selected_item, void *data,
2672 char *buffer, size_t buffer_len);
2674 static int pic_action_callback(int action, struct gui_synclist *lists)
2676 (void)lists;
2677 if (action == ACTION_NONE)
2678 action = ACTION_REDRAW;
2679 return action;
2682 static bool dbg_pic(void)
2684 struct simplelist_info pic;
2685 pic.scroll_all = true;
2686 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2687 pic.timeout = HZ/100;
2688 pic.hide_selection = true;
2689 pic.get_name = pic_dbg_item;
2690 pic.action_callback = pic_action_callback;
2691 return simplelist_show_list(&pic);
2693 #endif
2696 /****** The menu *********/
2697 struct the_menu_item {
2698 unsigned char *desc; /* string or ID */
2699 bool (*function) (void); /* return true if USB was connected */
2701 static const struct the_menu_item menuitems[] = {
2702 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2703 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD))
2704 { "Dump ROM contents", dbg_save_roms },
2705 #endif
2706 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2707 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 \
2708 || CONFIG_CPU == DM320
2709 { "View I/O ports", dbg_ports },
2710 #endif
2711 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2712 { "View PCF registers", dbg_pcf },
2713 #endif
2714 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2715 { "TSC2100 debug", tsc2100_debug },
2716 #endif
2717 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2718 { "CPU frequency", dbg_cpufreq },
2719 #endif
2720 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2721 { "S/PDIF analyzer", dbg_spdif },
2722 #endif
2723 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2724 { "Catch mem accesses", dbg_set_memory_guard },
2725 #endif
2726 { "View OS stacks", dbg_os },
2727 #ifdef HAVE_LCD_BITMAP
2728 #ifndef SIMULATOR
2729 { "View battery", view_battery },
2730 #endif
2731 { "Screendump", dbg_screendump },
2732 #endif
2733 #ifndef SIMULATOR
2734 { "View HW info", dbg_hw_info },
2735 #endif
2736 #ifndef SIMULATOR
2737 { "View partitions", dbg_partitions },
2738 #endif
2739 #ifndef SIMULATOR
2740 { "View disk info", dbg_disk_info },
2741 #if (CONFIG_STORAGE & STORAGE_ATA)
2742 { "Dump ATA identify info", dbg_identify_info},
2743 #endif
2744 #endif
2745 #ifdef HAVE_DIRCACHE
2746 { "View dircache info", dbg_dircache_info },
2747 #endif
2748 #ifdef HAVE_TAGCACHE
2749 { "View database info", dbg_tagcache_info },
2750 #endif
2751 #ifdef HAVE_LCD_BITMAP
2752 #if CONFIG_CODEC == SWCODEC
2753 { "View buffering thread", dbg_buffering_thread },
2754 #elif !defined(SIMULATOR)
2755 { "View audio thread", dbg_audio_thread },
2756 #endif
2757 #ifdef PM_DEBUG
2758 { "pm histogram", peak_meter_histogram},
2759 #endif /* PM_DEBUG */
2760 #endif /* HAVE_LCD_BITMAP */
2761 #ifndef SIMULATOR
2762 #if CONFIG_TUNER
2763 { "FM Radio", dbg_fm_radio },
2764 #endif
2765 #endif
2766 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2767 { "Write back EEPROM", dbg_write_eeprom },
2768 #endif
2769 #if CONFIG_USBOTG == USBOTG_ISP1583
2770 { "View ISP1583 info", dbg_isp1583 },
2771 #endif
2772 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2773 { "View PIC info", dbg_pic },
2774 #endif
2775 #ifdef ROCKBOX_HAS_LOGF
2776 {"logf", logfdisplay },
2777 {"logfdump", logfdump },
2778 #endif
2779 #if defined(HAVE_USBSTACK)
2780 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2781 {"USB Serial driver (logf)", toggle_usb_serial },
2782 #endif
2783 #endif /* HAVE_USBSTACK */
2784 #ifdef CPU_BOOST_LOGGING
2785 {"cpu_boost log",cpu_boost_log},
2786 #endif
2787 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2788 {"Debug scrollwheel", dbg_scrollwheel },
2789 #endif
2791 static int menu_action_callback(int btn, struct gui_synclist *lists)
2793 if (btn == ACTION_STD_OK)
2795 int oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL);
2796 menuitems[gui_synclist_get_sel_pos(lists)].function();
2797 btn = ACTION_REDRAW;
2798 send_event(GUI_EVENT_REFRESH, NULL);
2799 viewportmanager_set_statusbar(oldbars);
2801 return btn;
2804 static const char* dbg_menu_getname(int item, void * data,
2805 char *buffer, size_t buffer_len)
2807 (void)data; (void)buffer; (void)buffer_len;
2808 return menuitems[item].desc;
2811 bool debug_menu(void)
2813 struct simplelist_info info;
2815 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2816 info.action_callback = menu_action_callback;
2817 info.get_name = dbg_menu_getname;
2818 return simplelist_show_list(&info);