Add beastpatcher download location to the Gigabeat S manual, and add dual-boot bootlo...
[kugel-rb.git] / apps / debug_menu.c
bloba0b285ae7980b029a1e8745199de4b21ecd6eefa
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 || defined(CPU_S5L870X)
108 #include "debug-target.h"
109 #endif
111 #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) \
112 || defined(SANSA_CLIP) || defined(SANSA_FUZE)
113 #include "ascodec.h"
114 #include "as3514.h"
115 #endif
117 #ifdef IPOD_NANO2G
118 #include "pmu-target.h"
119 #endif
121 #ifdef HAVE_USBSTACK
122 #include "usb_core.h"
123 #endif
125 /*---------------------------------------------------*/
126 /* SPECIAL DEBUG STUFF */
127 /*---------------------------------------------------*/
128 extern struct thread_entry threads[MAXTHREADS];
130 static char thread_status_char(unsigned status)
132 static const char thread_status_chars[THREAD_NUM_STATES+1] =
134 [0 ... THREAD_NUM_STATES] = '?',
135 [STATE_RUNNING] = 'R',
136 [STATE_BLOCKED] = 'B',
137 [STATE_SLEEPING] = 'S',
138 [STATE_BLOCKED_W_TMO] = 'T',
139 [STATE_FROZEN] = 'F',
140 [STATE_KILLED] = 'K',
143 if (status > THREAD_NUM_STATES)
144 status = THREAD_NUM_STATES;
146 return thread_status_chars[status];
149 static const char* threads_getname(int selected_item, void *data,
150 char *buffer, size_t buffer_len)
152 (void)data;
153 struct thread_entry *thread;
154 char name[32];
156 #if NUM_CORES > 1
157 if (selected_item < (int)NUM_CORES)
159 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
160 idle_stack_usage(selected_item));
161 return buffer;
164 selected_item -= NUM_CORES;
165 #endif
167 thread = &threads[selected_item];
169 if (thread->state == STATE_KILLED)
171 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
172 return buffer;
175 thread_get_name(name, 32, thread);
177 snprintf(buffer, buffer_len,
178 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
179 selected_item,
180 IF_COP(thread->core,)
181 #ifdef HAVE_SCHEDULER_BOOSTCTRL
182 (thread->cpu_boost) ? '+' :
183 #endif
184 ((thread->state == STATE_RUNNING) ? '*' : ' '),
185 thread_status_char(thread->state),
186 IF_PRIO(thread->base_priority, thread->priority, )
187 thread_stack_usage(thread), name);
189 return buffer;
192 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
194 (void)lists;
195 #ifdef ROCKBOX_HAS_LOGF
196 if (action == ACTION_STD_OK)
198 int selpos = gui_synclist_get_sel_pos(lists);
199 #if NUM_CORES > 1
200 if (selpos >= NUM_CORES)
201 remove_thread(threads[selpos - NUM_CORES].id);
202 #else
203 remove_thread(threads[selpos].id);
204 #endif
205 return ACTION_REDRAW;
207 #endif /* ROCKBOX_HAS_LOGF */
208 if (action == ACTION_NONE)
209 action = ACTION_REDRAW;
210 return action;
212 /* Test code!!! */
213 static bool dbg_os(void)
215 struct simplelist_info info;
216 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
217 #if NUM_CORES == 1
218 MAXTHREADS,
219 #else
220 MAXTHREADS+NUM_CORES,
221 #endif
222 NULL);
223 #ifndef ROCKBOX_HAS_LOGF
224 info.hide_selection = true;
225 info.scroll_all = true;
226 #endif
227 info.action_callback = dbg_threads_action_callback;
228 info.get_name = threads_getname;
229 return simplelist_show_list(&info);
232 #ifdef HAVE_LCD_BITMAP
233 #if CONFIG_CODEC != SWCODEC
234 #ifndef SIMULATOR
235 static bool dbg_audio_thread(void)
237 struct audio_debug d;
239 lcd_setfont(FONT_SYSFIXED);
241 while(1)
243 if (action_userabort(HZ/5))
244 return false;
246 audio_get_debugdata(&d);
248 lcd_clear_display();
250 lcd_putsf(0, 0, "read: %x", d.audiobuf_read);
251 lcd_putsf(0, 1, "write: %x", d.audiobuf_write);
252 lcd_putsf(0, 2, "swap: %x", d.audiobuf_swapwrite);
253 lcd_putsf(0, 3, "playing: %d", d.playing);
254 lcd_putsf(0, 4, "playable: %x", d.playable_space);
255 lcd_putsf(0, 5, "unswapped: %x", d.unswapped_space);
257 /* Playable space left */
258 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
259 d.playable_space, HORIZONTAL);
261 /* Show the watermark limit */
262 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
263 d.low_watermark_level, HORIZONTAL);
265 lcd_putsf(0, 7, "wm: %x - %x",
266 d.low_watermark_level, d.lowest_watermark_level);
268 lcd_update();
270 lcd_setfont(FONT_UI);
271 return false;
273 #endif /* !SIMULATOR */
274 #else /* CONFIG_CODEC == SWCODEC */
275 extern size_t filebuflen;
276 /* This is a size_t, but call it a long so it puts a - when it's bad. */
278 static unsigned int ticks, boost_ticks, freq_sum;
280 static void dbg_audio_task(void)
282 #ifndef SIMULATOR
283 if(FREQ > CPUFREQ_NORMAL)
284 boost_ticks++;
285 freq_sum += FREQ/1000000; /* in MHz */
286 #endif
287 ticks++;
290 static bool dbg_buffering_thread(void)
292 int button;
293 int line;
294 bool done = false;
295 size_t bufused;
296 size_t bufsize = pcmbuf_get_bufsize();
297 int pcmbufdescs = pcmbuf_descs();
298 struct buffering_debug d;
300 ticks = boost_ticks = freq_sum = 0;
302 tick_add_task(dbg_audio_task);
304 lcd_setfont(FONT_SYSFIXED);
305 while(!done)
307 button = get_action(CONTEXT_STD,HZ/5);
308 switch(button)
310 case ACTION_STD_NEXT:
311 audio_next();
312 break;
313 case ACTION_STD_PREV:
314 audio_prev();
315 break;
316 case ACTION_STD_CANCEL:
317 done = true;
318 break;
321 buffering_get_debugdata(&d);
323 line = 0;
324 lcd_clear_display();
326 bufused = bufsize - pcmbuf_free();
328 lcd_putsf(0, line++, "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
330 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
331 bufsize, 0, bufused, HORIZONTAL);
332 line++;
334 lcd_putsf(0, line++, "alloc: %6ld/%ld", audio_filebufused(),
335 (long) filebuflen);
337 #if LCD_HEIGHT > 80
338 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
339 filebuflen, 0, audio_filebufused(), HORIZONTAL);
340 line++;
342 lcd_putsf(0, line++, "real: %6ld/%ld", (long)d.buffered_data,
343 (long)filebuflen);
345 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
346 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
347 line++;
348 #endif
350 lcd_putsf(0, line++, "usefl: %6ld/%ld", (long)(d.useful_data),
351 (long)filebuflen);
353 #if LCD_HEIGHT > 80
354 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
355 filebuflen, 0, d.useful_data, HORIZONTAL);
356 line++;
357 #endif
359 lcd_putsf(0, line++, "data_rem: %ld", (long)d.data_rem);
361 lcd_putsf(0, line++, "track count: %2d", audio_track_count());
363 lcd_putsf(0, line++, "handle count: %d", (int)d.num_handles);
365 #ifndef SIMULATOR
366 lcd_putsf(0, line++, "cpu freq: %3dMHz",
367 (int)((FREQ + 500000) / 1000000));
368 #endif
370 if (ticks > 0)
372 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
373 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
374 lcd_putsf(0, line++, "boost:%3d.%d%% (%d.%dMHz)",
375 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
378 lcd_putsf(0, line++, "pcmbufdesc: %2d/%2d",
379 pcmbuf_used_descs(), pcmbufdescs);
380 lcd_putsf(0, line++, "watermark: %6d",
381 (int)(d.watermark));
383 lcd_update();
386 tick_remove_task(dbg_audio_task);
387 lcd_setfont(FONT_UI);
389 return false;
391 #endif /* CONFIG_CODEC */
392 #endif /* HAVE_LCD_BITMAP */
395 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
396 /* Tool function to read the flash manufacturer and type, if available.
397 Only chips which could be reprogrammed in system will return values.
398 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
399 /* In IRAM to avoid problems when running directly from Flash */
400 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
401 unsigned addr1, unsigned addr2)
402 ICODE_ATTR __attribute__((noinline));
403 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
404 unsigned addr1, unsigned addr2)
407 unsigned not_manu, not_id; /* read values before switching to ID mode */
408 unsigned manu, id; /* read values when in ID mode */
410 #if CONFIG_CPU == SH7034
411 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
412 #elif defined(CPU_COLDFIRE)
413 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
414 #endif
415 int old_level; /* saved interrupt level */
417 not_manu = flash[0]; /* read the normal content */
418 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
420 /* disable interrupts, prevent any stray flash access */
421 old_level = disable_irq_save();
423 flash[addr1] = 0xAA; /* enter command mode */
424 flash[addr2] = 0x55;
425 flash[addr1] = 0x90; /* ID command */
426 /* Atmel wants 20ms pause here */
427 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
429 manu = flash[0]; /* read the IDs */
430 id = flash[1];
432 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
433 /* Atmel wants 20ms pause here */
434 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
436 restore_irq(old_level); /* enable interrupts again */
438 /* I assume success if the obtained values are different from
439 the normal flash content. This is not perfectly bulletproof, they
440 could theoretically be the same by chance, causing us to fail. */
441 if (not_manu != manu || not_id != id) /* a value has changed */
443 *p_manufacturer = manu; /* return the results */
444 *p_device = id;
445 return true; /* success */
447 return false; /* fail */
449 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
451 #ifndef SIMULATOR
452 #ifdef CPU_PP
453 static int perfcheck(void)
455 int result;
457 asm (
458 "mrs r2, CPSR \n"
459 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
460 "msr CPSR_c, r0 \n"
461 "mov %[res], #0 \n"
462 "ldr r0, [%[timr]] \n"
463 "add r0, r0, %[tmo] \n"
464 "1: \n"
465 "add %[res], %[res], #1 \n"
466 "ldr r1, [%[timr]] \n"
467 "cmp r1, r0 \n"
468 "bmi 1b \n"
469 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
471 [res]"=&r"(result)
473 [timr]"r"(&USEC_TIMER),
474 [tmo]"r"(
475 #if CONFIG_CPU == PP5002
476 16000
477 #else /* PP5020/5022/5024 */
478 10226
479 #endif
482 "r0", "r1", "r2"
484 return result;
486 #endif
488 #ifdef HAVE_LCD_BITMAP
489 static bool dbg_hw_info(void)
491 #if CONFIG_CPU == SH7034
492 int bitmask = HW_MASK;
493 int rom_version = ROM_VERSION;
494 unsigned manu, id; /* flash IDs */
495 bool got_id; /* flag if we managed to get the flash IDs */
496 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
497 bool has_bootrom; /* flag for boot ROM present */
498 int oldmode; /* saved memory guard mode */
500 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
502 /* get flash ROM type */
503 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
504 if (!got_id)
505 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
507 /* check if the boot ROM area is a flash mirror */
508 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
509 if (has_bootrom) /* if ROM and Flash different */
511 /* calculate CRC16 checksum of boot ROM */
512 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
515 system_memory_guard(oldmode); /* re-enable memory guard */
517 lcd_setfont(FONT_SYSFIXED);
518 lcd_clear_display();
520 lcd_puts(0, 0, "[Hardware info]");
522 lcd_putsf(0, 1, "ROM: %d.%02d", rom_version/100, rom_version%100);
524 lcd_putsf(0, 2, "Mask: 0x%04x", bitmask);
526 if (got_id)
527 lcd_putsf(0, 3, "Flash: M=%02x D=%02x", manu, id);
528 else
529 lcd_puts(0, 3, "Flash: M=?? D=??"); /* unknown, sorry */
531 if (has_bootrom)
533 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
534 lcd_puts(0, 4, "Boot ROM: V1");
535 else
536 lcd_putsf(0, 4, "ROMcrc: 0x%08x", rom_crc);
538 else
540 lcd_puts(0, 4, "Boot ROM: none");
543 lcd_update();
545 while (!(action_userabort(TIMEOUT_BLOCK)));
547 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
548 unsigned manu, id; /* flash IDs */
549 int got_id; /* flag if we managed to get the flash IDs */
550 int oldmode; /* saved memory guard mode */
551 int line = 0;
553 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
555 /* get flash ROM type */
556 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
557 if (!got_id)
558 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
560 system_memory_guard(oldmode); /* re-enable memory guard */
562 lcd_setfont(FONT_SYSFIXED);
563 lcd_clear_display();
565 lcd_puts(0, line++, "[Hardware info]");
567 if (got_id)
568 lcd_putsf(0, line++, "Flash: M=%04x D=%04x", manu, id);
569 else
570 lcd_puts(0, line++, "Flash: M=???? D=????"); /* unknown, sorry */
572 #ifdef IAUDIO_X5
574 struct ds2411_id id;
576 lcd_puts(0, ++line, "Serial Number:");
578 got_id = ds2411_read_id(&id);
580 if (got_id == DS2411_OK)
582 lcd_putsf(0, ++line, " FC=%02x", (unsigned)id.family_code);
583 lcd_putsf(0, ++line, " ID=%02X %02X %02X %02X %02X %02X",
584 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
585 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
586 lcd_putsf(0, ++line, " CRC=%02X", (unsigned)id.crc);
588 else
590 lcd_putsf(0, ++line, "READ ERR=%d", got_id);
593 #endif
595 lcd_update();
597 while (!(action_userabort(TIMEOUT_BLOCK)));
599 #elif defined(CPU_PP502x)
600 int line = 0;
601 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
602 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
603 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
604 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
606 lcd_setfont(FONT_SYSFIXED);
607 lcd_clear_display();
609 lcd_puts(0, line++, "[Hardware info]");
611 #ifdef IPOD_ARCH
612 lcd_putsf(0, line++, "HW rev: 0x%08lx", IPOD_HW_REVISION);
613 #endif
615 #ifdef IPOD_COLOR
616 extern int lcd_type; /* Defined in lcd-colornano.c */
618 lcd_putsf(0, line++, "LCD type: %d", lcd_type);
619 #endif
621 lcd_putsf(0, line++, "PP version: %s", pp_version);
623 lcd_putsf(0, line++, "Est. clock (kHz): %d", perfcheck());
625 lcd_update();
627 while (!(action_userabort(TIMEOUT_BLOCK)));
629 #elif CONFIG_CPU == PP5002
630 int line = 0;
631 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
632 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
633 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
634 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
637 lcd_setfont(FONT_SYSFIXED);
638 lcd_clear_display();
640 lcd_puts(0, line++, "[Hardware info]");
642 #ifdef IPOD_ARCH
643 lcd_putsf(0, line++, "HW rev: 0x%08lx", IPOD_HW_REVISION);
644 #endif
646 lcd_putsf(0, line++, "PP version: %s", pp_version);
648 lcd_putsf(0, line++, "Est. clock (kHz): %d", perfcheck());
650 lcd_update();
652 while (!(action_userabort(TIMEOUT_BLOCK)));
654 #else
655 /* Define this function in your target tree */
656 return __dbg_hw_info();
657 #endif /* CONFIG_CPU */
658 lcd_setfont(FONT_UI);
659 return false;
661 #else /* !HAVE_LCD_BITMAP */
662 static bool dbg_hw_info(void)
664 int button;
665 int currval = 0;
666 int rom_version = ROM_VERSION;
667 unsigned manu, id; /* flash IDs */
668 bool got_id; /* flag if we managed to get the flash IDs */
669 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
670 bool has_bootrom; /* flag for boot ROM present */
671 int oldmode; /* saved memory guard mode */
673 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
675 /* get flash ROM type */
676 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
677 if (!got_id)
678 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
680 /* check if the boot ROM area is a flash mirror */
681 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
682 if (has_bootrom) /* if ROM and Flash different */
684 /* calculate CRC16 checksum of boot ROM */
685 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
688 system_memory_guard(oldmode); /* re-enable memory guard */
690 lcd_clear_display();
692 lcd_puts(0, 0, "[HW Info]");
693 while(1)
695 switch(currval)
697 case 0:
698 lcd_putsf(0, 1, "ROM: %d.%02d",
699 rom_version/100, rom_version%100);
700 break;
701 case 1:
702 if (got_id)
703 lcd_putsf(0, 1, "Flash:%02x,%02x", manu, id);
704 else
705 lcd_puts(0, 1, "Flash:??,??"); /* unknown, sorry */
706 break;
707 case 2:
708 if (has_bootrom)
710 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
711 lcd_puts(0, 1, "BootROM: V1");
712 else if (rom_crc == 0x358099E8)
713 lcd_puts(0, 1, "BootROM: V2");
714 /* alternative boot ROM found in one single player so far */
715 else
716 lcd_putsf(0, 1, "R: %08x", rom_crc);
718 else
719 lcd_puts(0, 1, "BootROM: no");
722 lcd_update();
724 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
726 switch(button)
728 case ACTION_STD_CANCEL:
729 return false;
731 case ACTION_SETTINGS_DEC:
732 currval--;
733 if(currval < 0)
734 currval = 2;
735 break;
737 case ACTION_SETTINGS_INC:
738 currval++;
739 if(currval > 2)
740 currval = 0;
741 break;
744 return false;
746 #endif /* !HAVE_LCD_BITMAP */
747 #endif /* !SIMULATOR */
749 #ifndef SIMULATOR
750 static const char* dbg_partitions_getname(int selected_item, void *data,
751 char *buffer, size_t buffer_len)
753 (void)data;
754 int partition = selected_item/2;
755 struct partinfo* p = disk_partinfo(partition);
756 if (selected_item%2)
758 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / 2048);
760 else
762 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
764 return buffer;
767 bool dbg_partitions(void)
769 struct simplelist_info info;
770 simplelist_info_init(&info, "Partition Info", 4, NULL);
771 info.selection_size = 2;
772 info.hide_selection = true;
773 info.scroll_all = true;
774 info.get_name = dbg_partitions_getname;
775 return simplelist_show_list(&info);
777 #endif
779 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
780 static bool dbg_spdif(void)
782 int line;
783 unsigned int control;
784 int x;
785 char *s;
786 int category;
787 int generation;
788 unsigned int interruptstat;
789 bool valnogood, symbolerr, parityerr;
790 bool done = false;
791 bool spdif_src_on;
792 int spdif_source = spdif_get_output_source(&spdif_src_on);
793 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
795 lcd_clear_display();
796 lcd_setfont(FONT_SYSFIXED);
798 #ifdef HAVE_SPDIF_POWER
799 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
800 #endif
802 while (!done)
804 line = 0;
806 control = EBU1RCVCCHANNEL1;
807 interruptstat = INTERRUPTSTAT;
808 INTERRUPTCLEAR = 0x03c00000;
810 valnogood = (interruptstat & 0x01000000)?true:false;
811 symbolerr = (interruptstat & 0x00800000)?true:false;
812 parityerr = (interruptstat & 0x00400000)?true:false;
814 lcd_putsf(0, line++, "Val: %s Sym: %s Par: %s",
815 valnogood?"--":"OK",
816 symbolerr?"--":"OK",
817 parityerr?"--":"OK");
819 lcd_putsf(0, line++, "Status word: %08x", (int)control);
821 line++;
823 x = control >> 31;
824 lcd_putsf(0, line++, "PRO: %d (%s)",
825 x, x?"Professional":"Consumer");
827 x = (control >> 30) & 1;
828 lcd_putsf(0, line++, "Audio: %d (%s)",
829 x, x?"Non-PCM":"PCM");
831 x = (control >> 29) & 1;
832 lcd_putsf(0, line++, "Copy: %d (%s)",
833 x, x?"Permitted":"Inhibited");
835 x = (control >> 27) & 7;
836 switch(x)
838 case 0:
839 s = "None";
840 break;
841 case 1:
842 s = "50/15us";
843 break;
844 default:
845 s = "Reserved";
846 break;
848 lcd_putsf(0, line++, "Preemphasis: %d (%s)", x, s);
850 x = (control >> 24) & 3;
851 lcd_putsf(0, line++, "Mode: %d", x);
853 category = (control >> 17) & 127;
854 switch(category)
856 case 0x00:
857 s = "General";
858 break;
859 case 0x40:
860 s = "Audio CD";
861 break;
862 default:
863 s = "Unknown";
865 lcd_putsf(0, line++, "Category: 0x%02x (%s)", category, s);
867 x = (control >> 16) & 1;
868 generation = x;
869 if(((category & 0x70) == 0x10) ||
870 ((category & 0x70) == 0x40) ||
871 ((category & 0x78) == 0x38))
873 generation = !generation;
875 lcd_putsf(0, line++, "Generation: %d (%s)",
876 x, generation?"Original":"No ind.");
878 x = (control >> 12) & 15;
879 lcd_putsf(0, line++, "Source: %d", x);
882 x = (control >> 8) & 15;
883 switch(x)
885 case 0:
886 s = "Unspecified";
887 break;
888 case 8:
889 s = "A (Left)";
890 break;
891 case 4:
892 s = "B (Right)";
893 break;
894 default:
895 s = "";
896 break;
898 lcd_putsf(0, line++, "Channel: %d (%s)", x, s);
900 x = (control >> 4) & 15;
901 switch(x)
903 case 0:
904 s = "44.1kHz";
905 break;
906 case 0x4:
907 s = "48kHz";
908 break;
909 case 0xc:
910 s = "32kHz";
911 break;
913 lcd_putsf(0, line++, "Frequency: %d (%s)", x, s);
915 x = (control >> 2) & 3;
916 lcd_putsf(0, line++, "Clock accuracy: %d", x);
917 line++;
919 #ifndef SIMULATOR
920 lcd_putsf(0, line++, "Measured freq: %ldHz",
921 spdif_measure_frequency());
922 #endif
924 lcd_update();
926 if (action_userabort(HZ/10))
927 break;
930 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
932 #ifdef HAVE_SPDIF_POWER
933 spdif_power_enable(global_settings.spdif_enable);
934 #endif
936 lcd_setfont(FONT_UI);
937 return false;
939 #endif /* CPU_COLDFIRE */
941 #ifndef SIMULATOR
942 #ifdef HAVE_LCD_BITMAP
943 /* button definitions */
944 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
945 (CONFIG_KEYPAD == IRIVER_H300_PAD)
946 # define DEBUG_CANCEL BUTTON_OFF
948 #elif CONFIG_KEYPAD == RECORDER_PAD
949 # define DEBUG_CANCEL BUTTON_OFF
951 #elif CONFIG_KEYPAD == ONDIO_PAD
952 # define DEBUG_CANCEL BUTTON_MENU
954 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
955 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
956 (CONFIG_KEYPAD == IPOD_4G_PAD)
957 # define DEBUG_CANCEL BUTTON_MENU
959 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
960 # define DEBUG_CANCEL BUTTON_PLAY
962 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
963 # define DEBUG_CANCEL BUTTON_REC
965 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
966 # define DEBUG_CANCEL BUTTON_RC_REC
968 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
969 # define DEBUG_CANCEL BUTTON_REW
971 #elif (CONFIG_KEYPAD == MROBE100_PAD)
972 # define DEBUG_CANCEL BUTTON_MENU
974 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
975 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
976 (CONFIG_KEYPAD == SANSA_FUZE_PAD)
977 # define DEBUG_CANCEL BUTTON_LEFT
979 /* This is temporary until the SA9200 touchpad works */
980 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) || \
981 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD)
982 # define DEBUG_CANCEL BUTTON_POWER
984 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
985 # define DEBUG_CANCEL BUTTON_PLAY
987 #endif /* key definitions */
989 /* Test code!!! */
990 bool dbg_ports(void)
992 #if CONFIG_CPU == SH7034
993 int adc_battery_voltage, adc_battery_level;
995 lcd_setfont(FONT_SYSFIXED);
996 lcd_clear_display();
998 while(1)
1000 lcd_putsf(0, 0, "PADR: %04x", (unsigned short)PADR);
1001 lcd_putsf(0, 1, "PBDR: %04x", (unsigned short)PBDR);
1003 lcd_putsf(0, 2, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1004 lcd_putsf(0, 3, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1005 lcd_putsf(0, 4, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1006 lcd_putsf(0, 5, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1008 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1009 lcd_putsf(0, 6, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1010 adc_battery_voltage % 1000, adc_battery_level);
1012 lcd_update();
1013 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1015 lcd_setfont(FONT_UI);
1016 return false;
1019 #elif defined(CPU_COLDFIRE)
1020 unsigned int gpio_out;
1021 unsigned int gpio1_out;
1022 unsigned int gpio_read;
1023 unsigned int gpio1_read;
1024 unsigned int gpio_function;
1025 unsigned int gpio1_function;
1026 unsigned int gpio_enable;
1027 unsigned int gpio1_enable;
1028 int adc_buttons, adc_remote;
1029 int adc_battery_voltage, adc_battery_level;
1030 int line;
1032 lcd_clear_display();
1033 lcd_setfont(FONT_SYSFIXED);
1035 while(1)
1037 line = 0;
1038 gpio_read = GPIO_READ;
1039 gpio1_read = GPIO1_READ;
1040 gpio_out = GPIO_OUT;
1041 gpio1_out = GPIO1_OUT;
1042 gpio_function = GPIO_FUNCTION;
1043 gpio1_function = GPIO1_FUNCTION;
1044 gpio_enable = GPIO_ENABLE;
1045 gpio1_enable = GPIO1_ENABLE;
1047 lcd_putsf(0, line++, "GPIO_READ: %08x", gpio_read);
1048 lcd_putsf(0, line++, "GPIO_OUT: %08x", gpio_out);
1049 lcd_putsf(0, line++, "GPIO_FUNC: %08x", gpio_function);
1050 lcd_putsf(0, line++, "GPIO_ENA: %08x", gpio_enable);
1052 lcd_putsf(0, line++, "GPIO1_READ: %08x", gpio1_read);
1053 lcd_putsf(0, line++, "GPIO1_OUT: %08x", gpio1_out);
1054 lcd_putsf(0, line++, "GPIO1_FUNC: %08x", gpio1_function);
1055 lcd_putsf(0, line++, "GPIO1_ENA: %08x", gpio1_enable);
1057 adc_buttons = adc_read(ADC_BUTTONS);
1058 adc_remote = adc_read(ADC_REMOTE);
1059 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1060 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1061 lcd_putsf(0, line++, "ADC_BUTTONS (%c): %02x",
1062 button_scan_enabled() ? '+' : '-', adc_buttons);
1063 #else
1064 lcd_putsf(0, line++, "ADC_BUTTONS: %02x", adc_buttons);
1065 #endif
1066 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1067 lcd_putsf(0, line++, "ADC_REMOTE (%c): %02x",
1068 remote_detect() ? '+' : '-', adc_remote);
1069 #else
1070 lcd_putsf(0, line++, "ADC_REMOTE: %02x", adc_remote);
1071 #endif
1072 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1073 lcd_putsf(0, line++, "ADC_REMOTEDETECT: %02x",
1074 adc_read(ADC_REMOTEDETECT));
1075 #endif
1077 lcd_putsf(0, line++, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1078 adc_battery_voltage % 1000, adc_battery_level);
1080 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1081 lcd_putsf(0, line++, "remotetype: %d", remote_type());
1082 #endif
1084 lcd_update();
1085 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1087 lcd_setfont(FONT_UI);
1088 return false;
1092 #elif defined(CPU_PP502x)
1093 int line;
1095 lcd_clear_display();
1096 lcd_setfont(FONT_SYSFIXED);
1098 while(1)
1100 line = 0;
1101 lcd_puts(0, line++, "GPIO STATES:");
1102 lcd_putsf(0, line++, "A: %02x E: %02x I: %02x",
1103 (unsigned int)GPIOA_INPUT_VAL,
1104 (unsigned int)GPIOE_INPUT_VAL,
1105 (unsigned int)GPIOI_INPUT_VAL);
1106 lcd_putsf(0, line++, "B: %02x F: %02x J: %02x",
1107 (unsigned int)GPIOB_INPUT_VAL,
1108 (unsigned int)GPIOF_INPUT_VAL,
1109 (unsigned int)GPIOJ_INPUT_VAL);
1110 lcd_putsf(0, line++, "C: %02x G: %02x K: %02x",
1111 (unsigned int)GPIOC_INPUT_VAL,
1112 (unsigned int)GPIOG_INPUT_VAL,
1113 (unsigned int)GPIOK_INPUT_VAL);
1114 lcd_putsf(0, line++, "D: %02x H: %02x L: %02x",
1115 (unsigned int)GPIOD_INPUT_VAL,
1116 (unsigned int)GPIOH_INPUT_VAL,
1117 (unsigned int)GPIOL_INPUT_VAL);
1118 line++;
1119 lcd_putsf(0, line++, "GPO32_VAL: %08lx", GPO32_VAL);
1120 lcd_putsf(0, line++, "GPO32_EN: %08lx", GPO32_ENABLE);
1121 lcd_putsf(0, line++, "DEV_EN: %08lx", DEV_EN);
1122 lcd_putsf(0, line++, "DEV_EN2: %08lx", DEV_EN2);
1123 lcd_putsf(0, line++, "DEV_EN3: %08lx", inl(0x60006044)); /* to be verified */
1124 lcd_putsf(0, line++, "DEV_INIT1: %08lx", DEV_INIT1);
1125 lcd_putsf(0, line++, "DEV_INIT2: %08lx", DEV_INIT2);
1126 #ifdef ADC_ACCESSORY
1127 lcd_putsf(0, line++, "ACCESSORY: %d", adc_read(ADC_ACCESSORY));
1128 #endif
1130 #if defined(IPOD_ACCESSORY_PROTOCOL)
1131 extern unsigned char serbuf[];
1132 lcd_putsf(0, line++, "IAP PACKET: %02x %02x %02x %02x %02x %02x %02x %02x",
1133 serbuf[0], serbuf[1], serbuf[2], serbuf[3], serbuf[4], serbuf[5],
1134 serbuf[6], serbuf[7]);
1135 #endif
1137 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1138 line++;
1139 lcd_putsf(0, line++, "BATT: %03x UNK1: %03x",
1140 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1141 lcd_putsf(0, line++, "REM: %03x PAD: %03x",
1142 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1143 #elif defined(PHILIPS_HDD1630)
1144 line++;
1145 lcd_putsf(0, line++, "BATT: %03x UNK1: %03x",
1146 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1147 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1148 lcd_putsf(0, line++, "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1149 lcd_putsf(0, line++, "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1150 lcd_putsf(0, line++, "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1151 lcd_putsf(0, line++, "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1152 lcd_putsf(0, line++, "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1153 lcd_putsf(0, line++, "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1154 lcd_putsf(0, line++, "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1155 lcd_putsf(0, line++, "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1156 lcd_putsf(0, line++, "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1157 lcd_putsf(0, line++, "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1158 lcd_putsf(0, line++, "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1159 #if !defined(PHILIPS_SA9200)
1160 lcd_putsf(0, line++, "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1161 lcd_putsf(0, line++, "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1162 #endif
1163 #endif
1164 lcd_update();
1165 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1167 lcd_setfont(FONT_UI);
1168 return false;
1172 #elif CONFIG_CPU == PP5002
1173 int line;
1175 lcd_clear_display();
1176 lcd_setfont(FONT_SYSFIXED);
1178 while(1)
1180 line = 0;
1181 lcd_putsf(0, line++, "GPIO_A: %02x GPIO_B: %02x",
1182 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1183 lcd_putsf(0, line++, "GPIO_C: %02x GPIO_D: %02x",
1184 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1186 lcd_putsf(0, line++, "DEV_EN: %08lx", DEV_EN);
1187 lcd_putsf(0, line++, "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1188 lcd_putsf(0, line++, "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1189 lcd_putsf(0, line++, "PLL_CONTROL: %08lx", PLL_CONTROL);
1190 lcd_putsf(0, line++, "PLL_DIV: %08lx", PLL_DIV);
1191 lcd_putsf(0, line++, "PLL_MULT: %08lx", PLL_MULT);
1192 lcd_putsf(0, line++, "TIMING1_CTL: %08lx", TIMING1_CTL);
1193 lcd_putsf(0, line++, "TIMING2_CTL: %08lx", TIMING2_CTL);
1195 lcd_update();
1196 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1198 lcd_setfont(FONT_UI);
1199 return false;
1202 lcd_setfont(FONT_UI);
1203 #else
1204 return __dbg_ports();
1205 #endif /* CPU */
1206 return false;
1208 #else /* !HAVE_LCD_BITMAP */
1209 bool dbg_ports(void)
1211 char buf[32];
1212 int button;
1213 int adc_battery_voltage;
1214 int currval = 0;
1216 lcd_clear_display();
1218 while(1)
1220 switch(currval)
1222 case 0:
1223 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1224 break;
1225 case 1:
1226 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1227 break;
1228 case 2:
1229 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1230 break;
1231 case 3:
1232 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1233 break;
1234 case 4:
1235 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1236 break;
1237 case 5:
1238 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1239 break;
1240 case 6:
1241 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1242 break;
1243 case 7:
1244 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1245 break;
1246 case 8:
1247 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1248 break;
1249 case 9:
1250 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1251 break;
1253 lcd_puts(0, 0, buf);
1255 battery_read_info(&adc_battery_voltage, NULL);
1256 lcd_putsf(0, 1, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1257 adc_battery_voltage % 1000);
1258 lcd_update();
1260 button = get_action(CONTEXT_SETTINGS,HZ/5);
1262 switch(button)
1264 case ACTION_STD_CANCEL:
1265 return false;
1267 case ACTION_SETTINGS_DEC:
1268 currval--;
1269 if(currval < 0)
1270 currval = 9;
1271 break;
1273 case ACTION_SETTINGS_INC:
1274 currval++;
1275 if(currval > 9)
1276 currval = 0;
1277 break;
1280 return false;
1282 #endif /* !HAVE_LCD_BITMAP */
1283 #endif /* !SIMULATOR */
1285 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1286 static bool dbg_pcf(void)
1288 int line;
1290 #ifdef HAVE_LCD_BITMAP
1291 lcd_setfont(FONT_SYSFIXED);
1292 #endif
1293 lcd_clear_display();
1295 while(1)
1297 line = 0;
1299 lcd_putsf(0, line++, "DCDC1: %02x", pcf50605_read(0x1b));
1300 lcd_putsf(0, line++, "DCDC2: %02x", pcf50605_read(0x1c));
1301 lcd_putsf(0, line++, "DCDC3: %02x", pcf50605_read(0x1d));
1302 lcd_putsf(0, line++, "DCDC4: %02x", pcf50605_read(0x1e));
1303 lcd_putsf(0, line++, "DCDEC1: %02x", pcf50605_read(0x1f));
1304 lcd_putsf(0, line++, "DCDEC2: %02x", pcf50605_read(0x20));
1305 lcd_putsf(0, line++, "DCUDC1: %02x", pcf50605_read(0x21));
1306 lcd_putsf(0, line++, "DCUDC2: %02x", pcf50605_read(0x22));
1307 lcd_putsf(0, line++, "IOREGC: %02x", pcf50605_read(0x23));
1308 lcd_putsf(0, line++, "D1REGC: %02x", pcf50605_read(0x24));
1309 lcd_putsf(0, line++, "D2REGC: %02x", pcf50605_read(0x25));
1310 lcd_putsf(0, line++, "D3REGC: %02x", pcf50605_read(0x26));
1311 lcd_putsf(0, line++, "LPREG1: %02x", pcf50605_read(0x27));
1312 lcd_update();
1313 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1315 lcd_setfont(FONT_UI);
1316 return false;
1320 lcd_setfont(FONT_UI);
1321 return false;
1323 #endif
1325 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1326 static bool dbg_cpufreq(void)
1328 int line;
1329 int button;
1331 #ifdef HAVE_LCD_BITMAP
1332 lcd_setfont(FONT_SYSFIXED);
1333 #endif
1334 lcd_clear_display();
1336 while(1)
1338 line = 0;
1340 lcd_putsf(0, line++, "Frequency: %ld", FREQ);
1341 lcd_putsf(0, line++, "boost_counter: %d", get_cpu_boost_counter());
1343 lcd_update();
1344 button = get_action(CONTEXT_STD,HZ/10);
1346 switch(button)
1348 case ACTION_STD_PREV:
1349 cpu_boost(true);
1350 break;
1352 case ACTION_STD_NEXT:
1353 cpu_boost(false);
1354 break;
1356 case ACTION_STD_OK:
1357 while (get_cpu_boost_counter() > 0)
1358 cpu_boost(false);
1359 set_cpu_frequency(CPUFREQ_DEFAULT);
1360 break;
1362 case ACTION_STD_CANCEL:
1363 lcd_setfont(FONT_UI);
1364 return false;
1367 lcd_setfont(FONT_UI);
1368 return false;
1370 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1372 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1373 #include "tsc2100.h"
1374 static char *itob(int n, int len)
1376 static char binary[64];
1377 int i,j;
1378 for (i=1, j=0;i<=len;i++)
1380 binary[j++] = n&(1<<(len-i))?'1':'0';
1381 if (i%4 == 0)
1382 binary[j++] = ' ';
1384 binary[j] = '\0';
1385 return binary;
1388 static const char* tsc2100_debug_getname(int selected_item, void * data,
1389 char *buffer, size_t buffer_len)
1391 int *page = (int*)data;
1392 bool reserved = false;
1393 switch (*page)
1395 case 0:
1396 if ((selected_item > 0x0a) ||
1397 (selected_item == 0x04) ||
1398 (selected_item == 0x08))
1399 reserved = true;
1400 break;
1401 case 1:
1402 if ((selected_item > 0x05) ||
1403 (selected_item == 0x02))
1404 reserved = true;
1405 break;
1406 case 2:
1407 if (selected_item > 0x1e)
1408 reserved = true;
1409 break;
1411 if (reserved)
1412 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1413 else
1414 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1415 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1416 return buffer;
1418 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1420 int *page = (int*)lists->data;
1421 if (action == ACTION_STD_OK)
1423 *page = (*page+1)%3;
1424 snprintf(lists->title, 32,
1425 "tsc2100 registers - Page %d", *page);
1426 return ACTION_REDRAW;
1428 return action;
1430 static bool tsc2100_debug(void)
1432 int page = 0;
1433 char title[32] = "tsc2100 registers - Page 0";
1434 struct simplelist_info info;
1435 simplelist_info_init(&info, title, 32, &page);
1436 info.timeout = HZ/100;
1437 info.get_name = tsc2100_debug_getname;
1438 info.action_callback= tsc2100debug_action_callback;
1439 return simplelist_show_list(&info);
1441 #endif
1442 #ifndef SIMULATOR
1443 #ifdef HAVE_LCD_BITMAP
1445 * view_battery() shows a automatically scaled graph of the battery voltage
1446 * over time. Usable for estimating battery life / charging rate.
1447 * The power_history array is updated in power_thread of powermgmt.c.
1450 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1451 #define BAT_YSPACE (LCD_HEIGHT - 20)
1453 static bool view_battery(void)
1455 int view = 0;
1456 int i, x, y;
1457 unsigned short maxv, minv;
1459 lcd_setfont(FONT_SYSFIXED);
1461 while(1)
1463 lcd_clear_display();
1464 switch (view) {
1465 case 0: /* voltage history graph */
1466 /* Find maximum and minimum voltage for scaling */
1467 minv = power_history[0];
1468 maxv = minv + 1;
1469 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1470 if (power_history[i] > maxv)
1471 maxv = power_history[i];
1472 if (power_history[i] < minv)
1473 minv = power_history[i];
1476 lcd_putsf(0, 0, "Battery %d.%03d", power_history[0] / 1000,
1477 power_history[0] % 1000);
1478 lcd_putsf(0, 1, "scale %d.%03d-%d.%03dV",
1479 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1481 x = 0;
1482 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1483 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1484 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1485 lcd_vline(x, LCD_HEIGHT-1, 20);
1486 lcd_set_drawmode(DRMODE_SOLID);
1487 lcd_vline(x, LCD_HEIGHT-1,
1488 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1489 x++;
1492 break;
1494 case 1: /* status: */
1495 lcd_puts(0, 0, "Power status:");
1497 battery_read_info(&y, NULL);
1498 lcd_putsf(0, 1, "Battery: %d.%03d V", y / 1000, y % 1000);
1499 #ifdef ADC_EXT_POWER
1500 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1501 lcd_putsf(0, 2, "External: %d.%03d V", y / 1000, y % 1000);
1502 #endif
1503 #if CONFIG_CHARGING
1504 #if defined ARCHOS_RECORDER
1505 lcd_putsf(0, 3, "Chgr: %s %s",
1506 charger_inserted() ? "present" : "absent",
1507 charger_enabled() ? "on" : "off");
1508 lcd_putsf(0, 5, "short delta: %d", short_delta);
1509 lcd_putsf(0, 6, "long delta: %d", long_delta);
1510 lcd_puts(0, 7, power_message);
1511 lcd_putsf(0, 8, "USB Inserted: %s",
1512 usb_inserted() ? "yes" : "no");
1513 #elif defined IRIVER_H300_SERIES
1514 lcd_putsf(0, 9, "USB Charging Enabled: %s",
1515 usb_charging_enabled() ? "yes" : "no");
1516 #elif defined IPOD_NANO || defined IPOD_VIDEO
1517 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1518 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1519 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1520 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1521 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1523 lcd_putsf(0, 3, "USB pwr: %s",
1524 usb_pwr ? "present" : "absent");
1525 lcd_putsf(0, 4, "EXT pwr: %s",
1526 ext_pwr ? "present" : "absent");
1527 lcd_putsf(0, 5, "Battery: %s",
1528 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1529 lcd_putsf(0, 6, "Dock mode: %s",
1530 dock ? "enabled" : "disabled");
1531 lcd_putsf(0, 7, "Headphone: %s",
1532 headphone ? "connected" : "disconnected");
1533 #elif defined TOSHIBA_GIGABEAT_S
1534 int line = 3;
1535 unsigned int st;
1537 static const unsigned char * const chrgstate_strings[] =
1539 "Disabled",
1540 "Error",
1541 "Discharging",
1542 "Precharge",
1543 "Constant Voltage",
1544 "Constant Current",
1545 "<unknown>",
1548 lcd_putsf(0, line++, "Charger: %s",
1549 charger_inserted() ? "present" : "absent");
1551 st = power_input_status() &
1552 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1553 lcd_putsf(0, line++, "%s%s",
1554 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1555 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1557 lcd_putsf(0, line++, "IUSB Max: %d", usb_allowed_current());
1559 y = ARRAYLEN(chrgstate_strings) - 1;
1561 switch (charge_state)
1563 case CHARGE_STATE_DISABLED: y--;
1564 case CHARGE_STATE_ERROR: y--;
1565 case DISCHARGING: y--;
1566 case TRICKLE: y--;
1567 case TOPOFF: y--;
1568 case CHARGING: y--;
1569 default:;
1572 lcd_putsf(0, line++, "State: %s", chrgstate_strings[y]);
1574 lcd_putsf(0, line++, "Battery Switch: %s",
1575 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1577 y = chrgraw_adc_voltage();
1578 lcd_putsf(0, line++, "CHRGRAW: %d.%03d V",
1579 y / 1000, y % 1000);
1581 y = application_supply_adc_voltage();
1582 lcd_putsf(0, line++, "BP : %d.%03d V",
1583 y / 1000, y % 1000);
1585 y = battery_adc_charge_current();
1586 if (y < 0) x = '-', y = -y;
1587 else x = ' ';
1588 lcd_putsf(0, line++, "CHRGISN:%c%d mA", x, y);
1590 y = cccv_regulator_dissipation();
1591 lcd_putsf(0, line++, "P CCCV : %d mW", y);
1593 y = battery_charge_current();
1594 if (y < 0) x = '-', y = -y;
1595 else x = ' ';
1596 lcd_putsf(0, line++, "I Charge:%c%d mA", x, y);
1598 y = battery_adc_temp();
1600 if (y != INT_MIN) {
1601 lcd_putsf(0, line++, "T Battery: %dC (%dF)", y,
1602 (9*y + 160) / 5);
1603 } else {
1604 /* Conversion disabled */
1605 lcd_puts(0, line++, "T Battery: ?");
1608 #elif defined(SANSA_E200) || defined(SANSA_C200) || defined(SANSA_CLIP) || defined(SANSA_FUZE)
1609 const int first = CHARGE_STATE_DISABLED;
1610 static const char * const chrgstate_strings[] =
1612 [CHARGE_STATE_DISABLED-first] = "Disabled",
1613 [CHARGE_STATE_ERROR-first] = "Error",
1614 [DISCHARGING-first] = "Discharging",
1615 [CHARGING-first] = "Charging",
1617 const char *str = NULL;
1619 lcd_putsf(0, 3, "Charger: %s",
1620 charger_inserted() ? "present" : "absent");
1622 y = charge_state - first;
1623 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1624 str = chrgstate_strings[y];
1626 lcd_putsf(0, 4, "State: %s",
1627 str ? str : "<unknown>");
1629 lcd_putsf(0, 5, "CHARGER: %02X",
1630 ascodec_read(AS3514_CHARGER));
1631 #elif defined(IPOD_NANO2G)
1632 y = pmu_read_battery_current();
1633 lcd_putsf(0, 2, "Battery current: %d mA", y);
1634 #else
1635 lcd_putsf(0, 3, "Charger: %s",
1636 charger_inserted() ? "present" : "absent");
1637 #endif /* target type */
1638 #endif /* CONFIG_CHARGING */
1639 break;
1641 case 2: /* voltage deltas: */
1642 lcd_puts(0, 0, "Voltage deltas:");
1644 for (i = 0; i <= 6; i++) {
1645 y = power_history[i] - power_history[i+1];
1646 lcd_putsf(0, i+1, "-%d min: %s%d.%03d V", i,
1647 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1648 ((y < 0) ? y * -1 : y ) % 1000);
1650 break;
1652 case 3: /* remaining time estimation: */
1654 #ifdef ARCHOS_RECORDER
1655 lcd_putsf(0, 0, "charge_state: %d", charge_state);
1657 lcd_putsf(0, 1, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1659 lcd_putsf(0, 2, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1661 lcd_putsf(0, 3, "P=%2d I=%2d", pid_p, pid_i);
1663 lcd_putsf(0, 4, "Trickle sec: %d/60", trickle_sec);
1664 #endif /* ARCHOS_RECORDER */
1666 lcd_putsf(0, 5, "Last PwrHist: %d.%03dV",
1667 power_history[0] / 1000,
1668 power_history[0] % 1000);
1670 lcd_putsf(0, 6, "battery level: %d%%", battery_level());
1672 lcd_putsf(0, 7, "Est. remain: %d m", battery_time());
1673 break;
1676 lcd_update();
1678 switch(get_action(CONTEXT_STD,HZ/2))
1680 case ACTION_STD_PREV:
1681 if (view)
1682 view--;
1683 break;
1685 case ACTION_STD_NEXT:
1686 if (view < 3)
1687 view++;
1688 break;
1690 case ACTION_STD_CANCEL:
1691 lcd_setfont(FONT_UI);
1692 return false;
1695 lcd_setfont(FONT_UI);
1696 return false;
1699 #endif /* HAVE_LCD_BITMAP */
1700 #endif
1702 #ifndef SIMULATOR
1703 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1705 #if (CONFIG_STORAGE & STORAGE_MMC)
1706 #define CARDTYPE "MMC"
1707 #elif (CONFIG_STORAGE & STORAGE_SD)
1708 #define CARDTYPE "microSD"
1709 #endif
1711 static int disk_callback(int btn, struct gui_synclist *lists)
1713 tCardInfo *card;
1714 int *cardnum = (int*)lists->data;
1715 unsigned char card_name[7];
1716 unsigned char pbuf[32];
1717 char *title = lists->title;
1718 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1719 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1720 static const unsigned char * const kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1721 static const unsigned char * const nsec_units[] = { "ns", "µs", "ms" };
1722 #if (CONFIG_STORAGE & STORAGE_MMC)
1723 static const char * const mmc_spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1724 "3.1-3.31", "4.0" };
1725 #endif
1727 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1729 #ifdef HAVE_HOTSWAP
1730 if (btn == ACTION_STD_OK)
1732 *cardnum ^= 0x1; /* change cards */
1734 #endif
1736 simplelist_set_line_count(0);
1738 card = card_get_info(*cardnum);
1740 if (card->initialized > 0)
1742 strlcpy(card_name, ((unsigned char*)card->cid) + 3, sizeof(card_name));
1743 simplelist_addline(SIMPLELIST_ADD_LINE,
1744 "%s Rev %d.%d", card_name,
1745 (int) card_extract_bits(card->cid, 55, 4),
1746 (int) card_extract_bits(card->cid, 51, 4));
1747 simplelist_addline(SIMPLELIST_ADD_LINE,
1748 "Prod: %d/%d",
1749 #if (CONFIG_STORAGE & STORAGE_SD)
1750 (int) card_extract_bits(card->cid, 11, 3),
1751 (int) card_extract_bits(card->cid, 19, 8) + 2000
1752 #elif (CONFIG_STORAGE & STORAGE_MMC)
1753 (int) card_extract_bits(card->cid, 15, 4),
1754 (int) card_extract_bits(card->cid, 11, 4) + 1997
1755 #endif
1757 simplelist_addline(SIMPLELIST_ADD_LINE,
1758 #if (CONFIG_STORAGE & STORAGE_SD)
1759 "Ser#: 0x%08lx",
1760 card_extract_bits(card->cid, 55, 32)
1761 #elif (CONFIG_STORAGE & STORAGE_MMC)
1762 "Ser#: 0x%04lx",
1763 card_extract_bits(card->cid, 47, 16)
1764 #endif
1767 simplelist_addline(SIMPLELIST_ADD_LINE, "M=%02x, "
1768 #if (CONFIG_STORAGE & STORAGE_SD)
1769 "O=%c%c",
1770 (int) card_extract_bits(card->cid, 127, 8),
1771 card_extract_bits(card->cid, 119, 8),
1772 card_extract_bits(card->cid, 111, 8)
1773 #elif (CONFIG_STORAGE & STORAGE_MMC)
1774 "O=%04x",
1775 (int) card_extract_bits(card->cid, 127, 8),
1776 (int) card_extract_bits(card->cid, 119, 16)
1777 #endif
1780 #if (CONFIG_STORAGE & STORAGE_MMC)
1781 int temp = card_extract_bits(card->csd, 125, 4);
1782 simplelist_addline(SIMPLELIST_ADD_LINE,
1783 "MMC v%s", temp < 5 ?
1784 mmc_spec_vers[temp] : "?.?");
1785 #endif
1786 simplelist_addline(SIMPLELIST_ADD_LINE,
1787 "Blocks: 0x%08lx", card->numblocks);
1788 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1789 kbit_units, false);
1790 simplelist_addline(SIMPLELIST_ADD_LINE,
1791 "Speed: %s", pbuf);
1792 output_dyn_value(pbuf, sizeof pbuf, card->taac,
1793 nsec_units, false);
1794 simplelist_addline(SIMPLELIST_ADD_LINE,
1795 "Taac: %s", pbuf);
1796 simplelist_addline(SIMPLELIST_ADD_LINE,
1797 "Nsac: %d clk", card->nsac);
1798 simplelist_addline(SIMPLELIST_ADD_LINE,
1799 "R2W: *%d", card->r2w_factor);
1800 simplelist_addline(SIMPLELIST_ADD_LINE,
1801 "IRmax: %d..%d mA",
1802 i_vmin[card_extract_bits(card->csd, 61, 3)],
1803 i_vmax[card_extract_bits(card->csd, 58, 3)]);
1804 simplelist_addline(SIMPLELIST_ADD_LINE,
1805 "IWmax: %d..%d mA",
1806 i_vmin[card_extract_bits(card->csd, 55, 3)],
1807 i_vmax[card_extract_bits(card->csd, 52, 3)]);
1809 else if (card->initialized == 0)
1811 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1813 #if (CONFIG_STORAGE & STORAGE_SD)
1814 else /* card->initialized < 0 */
1816 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1818 #endif
1819 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1820 gui_synclist_set_title(lists, title, Icon_NOICON);
1821 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1822 gui_synclist_select_item(lists, 0);
1823 btn = ACTION_REDRAW;
1825 return btn;
1827 #elif (CONFIG_STORAGE & STORAGE_ATA)
1828 static int disk_callback(int btn, struct gui_synclist *lists)
1830 (void)lists;
1831 int i;
1832 char buf[128];
1833 unsigned short* identify_info = ata_get_identify();
1834 bool timing_info_present = false;
1835 (void)btn;
1837 simplelist_set_line_count(0);
1839 for (i=0; i < 20; i++)
1840 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1841 buf[40]=0;
1842 /* kill trailing space */
1843 for (i=39; i && buf[i]==' '; i--)
1844 buf[i] = 0;
1845 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1846 for (i=0; i < 4; i++)
1847 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1848 buf[8]=0;
1849 simplelist_addline(SIMPLELIST_ADD_LINE,
1850 "Firmware: %s", buf);
1851 snprintf(buf, sizeof buf, "%ld MB",
1852 ((unsigned long)identify_info[61] << 16 |
1853 (unsigned long)identify_info[60]) / 2048 );
1854 simplelist_addline(SIMPLELIST_ADD_LINE,
1855 "Size: %s", buf);
1856 unsigned long free;
1857 fat_size( IF_MV2(0,) NULL, &free );
1858 simplelist_addline(SIMPLELIST_ADD_LINE,
1859 "Free: %ld MB", free / 1024);
1860 simplelist_addline(SIMPLELIST_ADD_LINE,
1861 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
1862 i = identify_info[83] & (1<<3);
1863 simplelist_addline(SIMPLELIST_ADD_LINE,
1864 "Power mgmt: %s", i ? "enabled" : "unsupported");
1865 i = identify_info[83] & (1<<9);
1866 simplelist_addline(SIMPLELIST_ADD_LINE,
1867 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1868 i = identify_info[82] & (1<<6);
1869 simplelist_addline(SIMPLELIST_ADD_LINE,
1870 "Read-ahead: %s", i ? "enabled" : "unsupported");
1871 timing_info_present = identify_info[53] & (1<<1);
1872 if(timing_info_present) {
1873 char pio3[2], pio4[2];pio3[1] = 0;
1874 pio4[1] = 0;
1875 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1876 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1877 simplelist_addline(SIMPLELIST_ADD_LINE,
1878 "PIO modes: 0 1 2 %s %s", pio3, pio4);
1880 else {
1881 simplelist_addline(SIMPLELIST_ADD_LINE,
1882 "No PIO mode info");
1884 timing_info_present = identify_info[53] & (1<<1);
1885 if(timing_info_present) {
1886 simplelist_addline(SIMPLELIST_ADD_LINE,
1887 "Cycle times %dns/%dns",
1888 identify_info[67],
1889 identify_info[68] );
1890 } else {
1891 simplelist_addline(SIMPLELIST_ADD_LINE,
1892 "No timing info");
1894 #ifdef HAVE_ATA_DMA
1895 if (identify_info[63] & (1<<0)) {
1896 char mdma0[2], mdma1[2], mdma2[2];
1897 mdma0[1] = mdma1[1] = mdma2[1] = 0;
1898 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
1899 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
1900 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
1901 simplelist_addline(SIMPLELIST_ADD_LINE,
1902 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
1903 simplelist_addline(SIMPLELIST_ADD_LINE,
1904 "MDMA Cycle times %dns/%dns",
1905 identify_info[65],
1906 identify_info[66] );
1908 else {
1909 simplelist_addline(SIMPLELIST_ADD_LINE,
1910 "No MDMA mode info");
1912 if (identify_info[53] & (1<<2)) {
1913 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2], udma6[2];
1914 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = udma6[1] = 0;
1915 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
1916 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
1917 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
1918 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
1919 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
1920 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
1921 udma6[0] = (identify_info[88] & (1<<6)) ? '6' : 0;
1922 simplelist_addline(SIMPLELIST_ADD_LINE,
1923 "UDMA modes: %s %s %s %s %s %s %s", udma0, udma1, udma2,
1924 udma3, udma4, udma5, udma6);
1926 else {
1927 simplelist_addline(SIMPLELIST_ADD_LINE,
1928 "No UDMA mode info");
1930 #endif /* HAVE_ATA_DMA */
1931 timing_info_present = identify_info[53] & (1<<1);
1932 if(timing_info_present) {
1933 i = identify_info[49] & (1<<11);
1934 simplelist_addline(SIMPLELIST_ADD_LINE,
1935 "IORDY support: %s", i ? "yes" : "no");
1936 i = identify_info[49] & (1<<10);
1937 simplelist_addline(SIMPLELIST_ADD_LINE,
1938 "IORDY disable: %s", i ? "yes" : "no");
1939 } else {
1940 simplelist_addline(SIMPLELIST_ADD_LINE,
1941 "No timing info");
1943 simplelist_addline(SIMPLELIST_ADD_LINE,
1944 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1945 #ifdef HAVE_ATA_DMA
1946 i = ata_get_dma_mode();
1947 if (i == 0) {
1948 simplelist_addline(SIMPLELIST_ADD_LINE,
1949 "DMA not enabled");
1950 } else {
1951 simplelist_addline(SIMPLELIST_ADD_LINE,
1952 "DMA mode: %s %c",
1953 (i & 0x40) ? "UDMA" : "MDMA",
1954 '0' + (i & 7));
1956 #endif /* HAVE_ATA_DMA */
1957 return btn;
1959 #else /* No SD, MMC or ATA */
1960 static int disk_callback(int btn, struct gui_synclist *lists)
1962 (void)btn;
1963 (void)lists;
1964 struct storage_info info;
1965 storage_get_info(0,&info);
1966 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
1967 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
1968 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
1969 simplelist_addline(SIMPLELIST_ADD_LINE,
1970 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
1971 unsigned long free;
1972 fat_size( IF_MV2(0,) NULL, &free );
1973 simplelist_addline(SIMPLELIST_ADD_LINE,
1974 "Free: %ld MB", free / 1024);
1975 simplelist_addline(SIMPLELIST_ADD_LINE,
1976 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1977 return btn;
1979 #endif
1981 #if (CONFIG_STORAGE & STORAGE_ATA)
1982 static bool dbg_identify_info(void)
1984 int fd = creat("/identify_info.bin");
1985 if(fd >= 0)
1987 #ifdef ROCKBOX_LITTLE_ENDIAN
1988 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
1989 #else
1990 write(fd, ata_get_identify(), SECTOR_SIZE);
1991 #endif
1992 close(fd);
1994 return false;
1996 #endif
1998 static bool dbg_disk_info(void)
2000 struct simplelist_info info;
2001 simplelist_info_init(&info, "Disk Info", 1, NULL);
2002 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
2003 char title[16];
2004 int card = 0;
2005 info.callback_data = (void*)&card;
2006 info.title = title;
2007 #endif
2008 info.action_callback = disk_callback;
2009 info.hide_selection = true;
2010 info.scroll_all = true;
2011 return simplelist_show_list(&info);
2013 #endif /* !SIMULATOR */
2015 #ifdef HAVE_DIRCACHE
2016 static int dircache_callback(int btn, struct gui_synclist *lists)
2018 (void)btn; (void)lists;
2019 simplelist_set_line_count(0);
2020 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
2021 dircache_is_enabled() ? "Yes" : "No");
2022 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
2023 dircache_get_cache_size());
2024 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
2025 global_status.dircache_size);
2026 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
2027 DIRCACHE_LIMIT);
2028 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
2029 dircache_get_reserve_used(), DIRCACHE_RESERVE);
2030 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2031 dircache_get_build_ticks() / HZ);
2032 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2033 dircache_get_entry_count());
2034 return btn;
2037 static bool dbg_dircache_info(void)
2039 struct simplelist_info info;
2040 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2041 info.action_callback = dircache_callback;
2042 info.hide_selection = true;
2043 info.scroll_all = true;
2044 return simplelist_show_list(&info);
2047 #endif /* HAVE_DIRCACHE */
2049 #ifdef HAVE_TAGCACHE
2050 static int database_callback(int btn, struct gui_synclist *lists)
2052 (void)lists;
2053 struct tagcache_stat *stat = tagcache_get_stat();
2054 static bool synced = false;
2056 simplelist_set_line_count(0);
2058 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2059 stat->initialized ? "Yes" : "No");
2060 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2061 stat->ready ? "Yes" : "No");
2062 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2063 stat->ramcache ? "Yes" : "No");
2064 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2065 stat->ramcache_used, stat->ramcache_allocated);
2066 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2067 stat->progress, stat->processed_entries);
2068 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2069 stat->curentry ? stat->curentry : "---");
2070 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2071 stat->commit_step);
2072 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2073 stat->commit_delayed ? "Yes" : "No");
2075 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2076 stat->queue_length);
2078 if (synced)
2080 synced = false;
2081 tagcache_screensync_event();
2084 if (!btn && stat->curentry)
2086 synced = true;
2087 return ACTION_REDRAW;
2090 if (btn == ACTION_STD_CANCEL)
2091 tagcache_screensync_enable(false);
2093 return btn;
2095 static bool dbg_tagcache_info(void)
2097 struct simplelist_info info;
2098 simplelist_info_init(&info, "Database Info", 8, NULL);
2099 info.action_callback = database_callback;
2100 info.hide_selection = true;
2101 info.scroll_all = true;
2103 /* Don't do nonblock here, must give enough processing time
2104 for tagcache thread. */
2105 /* info.timeout = TIMEOUT_NOBLOCK; */
2106 info.timeout = 1;
2107 tagcache_screensync_enable(true);
2108 return simplelist_show_list(&info);
2110 #endif
2112 #if CONFIG_CPU == SH7034
2113 static bool dbg_save_roms(void)
2115 int fd;
2116 int oldmode = system_memory_guard(MEMGUARD_NONE);
2118 fd = creat("/internal_rom_0000-FFFF.bin");
2119 if(fd >= 0)
2121 write(fd, (void *)0, 0x10000);
2122 close(fd);
2125 fd = creat("/internal_rom_2000000-203FFFF.bin");
2126 if(fd >= 0)
2128 write(fd, (void *)0x2000000, 0x40000);
2129 close(fd);
2132 system_memory_guard(oldmode);
2133 return false;
2135 #elif defined CPU_COLDFIRE
2136 static bool dbg_save_roms(void)
2138 int fd;
2139 int oldmode = system_memory_guard(MEMGUARD_NONE);
2141 #if defined(IRIVER_H100_SERIES)
2142 fd = creat("/internal_rom_000000-1FFFFF.bin");
2143 #elif defined(IRIVER_H300_SERIES)
2144 fd = creat("/internal_rom_000000-3FFFFF.bin");
2145 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2146 fd = creat("/internal_rom_000000-3FFFFF.bin");
2147 #endif
2148 if(fd >= 0)
2150 write(fd, (void *)0, FLASH_SIZE);
2151 close(fd);
2153 system_memory_guard(oldmode);
2155 #ifdef HAVE_EEPROM
2156 fd = creat("/internal_eeprom.bin");
2157 if (fd >= 0)
2159 int old_irq_level;
2160 char buf[EEPROM_SIZE];
2161 int err;
2163 old_irq_level = disable_irq_save();
2165 err = eeprom_24cxx_read(0, buf, sizeof buf);
2167 restore_irq(old_irq_level);
2169 if (err)
2170 splashf(HZ*3, "Eeprom read failure (%d)", err);
2171 else
2173 write(fd, buf, sizeof buf);
2176 close(fd);
2178 #endif
2180 return false;
2182 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
2183 static bool dbg_save_roms(void)
2185 int fd;
2187 fd = creat("/internal_rom_000000-0FFFFF.bin");
2188 if(fd >= 0)
2190 write(fd, (void *)0x20000000, FLASH_SIZE);
2191 close(fd);
2194 return false;
2196 #elif CONFIG_CPU == IMX31L
2197 static bool dbg_save_roms(void)
2199 int fd;
2201 fd = creat("/flash_rom_A0000000-A01FFFFF.bin");
2202 if (fd >= 0)
2204 write(fd, (void*)0xa0000000, FLASH_SIZE);
2205 close(fd);
2208 return false;
2210 #endif /* CPU */
2212 #ifndef SIMULATOR
2213 #if CONFIG_TUNER
2214 static int radio_callback(int btn, struct gui_synclist *lists)
2216 (void)lists;
2217 if (btn == ACTION_STD_CANCEL)
2218 return btn;
2219 simplelist_set_line_count(1);
2221 #if (CONFIG_TUNER & LV24020LP)
2222 simplelist_addline(SIMPLELIST_ADD_LINE,
2223 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2224 simplelist_addline(SIMPLELIST_ADD_LINE,
2225 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2226 simplelist_addline(SIMPLELIST_ADD_LINE,
2227 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2228 simplelist_addline(SIMPLELIST_ADD_LINE,
2229 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2230 simplelist_addline(SIMPLELIST_ADD_LINE,
2231 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2232 simplelist_addline(SIMPLELIST_ADD_LINE,
2233 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2234 simplelist_addline(SIMPLELIST_ADD_LINE,
2235 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2236 #endif /* LV24020LP */
2237 #if (CONFIG_TUNER & S1A0903X01)
2238 simplelist_addline(SIMPLELIST_ADD_LINE,
2239 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2240 /* This one doesn't return dynamic data atm */
2241 #endif /* S1A0903X01 */
2242 #if (CONFIG_TUNER & TEA5767)
2243 struct tea5767_dbg_info nfo;
2244 tea5767_dbg_info(&nfo);
2245 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2246 simplelist_addline(SIMPLELIST_ADD_LINE,
2247 " Read: %02X %02X %02X %02X %02X",
2248 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2249 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2250 (unsigned)nfo.read_regs[4]);
2251 simplelist_addline(SIMPLELIST_ADD_LINE,
2252 " Write: %02X %02X %02X %02X %02X",
2253 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2254 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2255 (unsigned)nfo.write_regs[4]);
2256 #endif /* TEA5767 */
2257 #if (CONFIG_TUNER & SI4700)
2258 struct si4700_dbg_info nfo;
2259 si4700_dbg_info(&nfo);
2260 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
2261 /* Registers */
2262 simplelist_addline(SIMPLELIST_ADD_LINE,
2263 "%04X %04X %04X %04X",
2264 (unsigned)nfo.regs[0], (unsigned)nfo.regs[1],
2265 (unsigned)nfo.regs[2], (unsigned)nfo.regs[3]);
2266 simplelist_addline(SIMPLELIST_ADD_LINE,
2267 "%04X %04X %04X %04X",
2268 (unsigned)nfo.regs[4], (unsigned)nfo.regs[5],
2269 (unsigned)nfo.regs[6], (unsigned)nfo.regs[7]);
2270 simplelist_addline(SIMPLELIST_ADD_LINE,
2271 "%04X %04X %04X %04X",
2272 (unsigned)nfo.regs[8], (unsigned)nfo.regs[9],
2273 (unsigned)nfo.regs[10], (unsigned)nfo.regs[11]);
2274 simplelist_addline(SIMPLELIST_ADD_LINE,
2275 "%04X %04X %04X %04X",
2276 (unsigned)nfo.regs[12], (unsigned)nfo.regs[13],
2277 (unsigned)nfo.regs[14], (unsigned)nfo.regs[15]);
2278 #endif /* SI4700 */
2279 return ACTION_REDRAW;
2281 static bool dbg_fm_radio(void)
2283 struct simplelist_info info;
2284 info.scroll_all = true;
2285 simplelist_info_init(&info, "FM Radio", 1, NULL);
2286 simplelist_set_line_count(0);
2287 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2288 radio_hardware_present() ? "yes" : "no");
2290 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2291 info.hide_selection = true;
2292 return simplelist_show_list(&info);
2294 #endif /* CONFIG_TUNER */
2295 #endif /* !SIMULATOR */
2297 #ifdef HAVE_LCD_BITMAP
2298 extern bool do_screendump_instead_of_usb;
2300 static bool dbg_screendump(void)
2302 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2303 splashf(HZ, "Screendump %s",
2304 do_screendump_instead_of_usb?"enabled":"disabled");
2305 return false;
2307 #endif /* HAVE_LCD_BITMAP */
2309 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2310 static bool dbg_set_memory_guard(void)
2312 static const struct opt_items names[MAXMEMGUARD] = {
2313 { "None", -1 },
2314 { "Flash ROM writes", -1 },
2315 { "Zero area (all)", -1 }
2317 int mode = system_memory_guard(MEMGUARD_KEEP);
2319 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2320 system_memory_guard(mode);
2322 return false;
2324 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2326 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2327 static bool dbg_write_eeprom(void)
2329 int fd;
2330 int rc;
2331 int old_irq_level;
2332 char buf[EEPROM_SIZE];
2333 int err;
2335 fd = open("/internal_eeprom.bin", O_RDONLY);
2337 if (fd >= 0)
2339 rc = read(fd, buf, EEPROM_SIZE);
2341 if(rc == EEPROM_SIZE)
2343 old_irq_level = disable_irq_save();
2345 err = eeprom_24cxx_write(0, buf, sizeof buf);
2346 if (err)
2347 splashf(HZ*3, "Eeprom write failure (%d)", err);
2348 else
2349 splash(HZ*3, "Eeprom written successfully");
2351 restore_irq(old_irq_level);
2353 else
2355 splashf(HZ*3, "File read error (%d)",rc);
2357 close(fd);
2359 else
2361 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2364 return false;
2366 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2367 #ifdef CPU_BOOST_LOGGING
2368 static bool cpu_boost_log(void)
2370 int i = 0,j=0;
2371 int count = cpu_boost_log_getcount();
2372 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2373 char *str;
2374 bool done;
2375 lcd_setfont(FONT_SYSFIXED);
2376 str = cpu_boost_log_getlog_first();
2377 while (i < count)
2379 lcd_clear_display();
2380 for(j=0; j<lines; j++,i++)
2382 if (!str)
2383 str = cpu_boost_log_getlog_next();
2384 if (str)
2386 if(strlen(str) > LCD_WIDTH/SYSFONT_WIDTH)
2387 lcd_puts_scroll(0, j, str);
2388 else
2389 lcd_puts(0, j,str);
2391 str = NULL;
2393 lcd_update();
2394 done = false;
2395 while (!done)
2397 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2399 case ACTION_STD_OK:
2400 case ACTION_STD_PREV:
2401 case ACTION_STD_NEXT:
2402 done = true;
2403 break;
2404 case ACTION_STD_CANCEL:
2405 i = count;
2406 done = true;
2407 break;
2411 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2412 lcd_setfont(FONT_UI);
2413 return false;
2415 #endif
2417 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2418 extern bool wheel_is_touched;
2419 extern int old_wheel_value;
2420 extern int new_wheel_value;
2421 extern int wheel_delta;
2422 extern unsigned int accumulated_wheel_delta;
2423 extern unsigned int wheel_velocity;
2425 static bool dbg_scrollwheel(void)
2427 unsigned int speed;
2429 lcd_setfont(FONT_SYSFIXED);
2431 while (1)
2433 if (action_userabort(HZ/10))
2434 break;
2436 lcd_clear_display();
2438 /* show internal variables of scrollwheel driver */
2439 lcd_putsf(0, 0, "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2440 lcd_putsf(0, 1, "new position: %2d", new_wheel_value);
2441 lcd_putsf(0, 2, "old position: %2d", old_wheel_value);
2442 lcd_putsf(0, 3, "wheel delta: %2d", wheel_delta);
2443 lcd_putsf(0, 4, "accumulated delta: %2d", accumulated_wheel_delta);
2444 lcd_putsf(0, 5, "velo [deg/s]: %4d", (int)wheel_velocity);
2446 /* show effective accelerated scrollspeed */
2447 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2448 lcd_putsf(0, 6, "accel. speed: %4d", speed);
2450 lcd_update();
2452 lcd_setfont(FONT_UI);
2453 return false;
2455 #endif
2457 #if defined (HAVE_USBSTACK)
2459 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2460 static bool toggle_usb_core_driver(int driver, char *msg)
2462 bool enabled = !usb_core_driver_enabled(driver);
2464 usb_core_enable_driver(driver,enabled);
2465 splashf(HZ, "%s %s", msg, enabled?"enabled":"disabled");
2467 return false;
2470 static bool toggle_usb_serial(void)
2472 return toggle_usb_core_driver(USB_DRIVER_SERIAL,"USB Serial");
2474 #endif
2476 #endif
2478 #if CONFIG_USBOTG == USBOTG_ISP1583
2479 extern int dbg_usb_num_items(void);
2480 extern const char* dbg_usb_item(int selected_item, void *data,
2481 char *buffer, size_t buffer_len);
2483 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2485 (void)lists;
2486 if (action == ACTION_NONE)
2487 action = ACTION_REDRAW;
2488 return action;
2491 static bool dbg_isp1583(void)
2493 struct simplelist_info isp1583;
2494 isp1583.scroll_all = true;
2495 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2496 isp1583.timeout = HZ/100;
2497 isp1583.hide_selection = true;
2498 isp1583.get_name = dbg_usb_item;
2499 isp1583.action_callback = isp1583_action_callback;
2500 return simplelist_show_list(&isp1583);
2502 #endif
2504 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2505 extern int pic_dbg_num_items(void);
2506 extern const char* pic_dbg_item(int selected_item, void *data,
2507 char *buffer, size_t buffer_len);
2509 static int pic_action_callback(int action, struct gui_synclist *lists)
2511 (void)lists;
2512 if (action == ACTION_NONE)
2513 action = ACTION_REDRAW;
2514 return action;
2517 static bool dbg_pic(void)
2519 struct simplelist_info pic;
2520 pic.scroll_all = true;
2521 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2522 pic.timeout = HZ/100;
2523 pic.hide_selection = true;
2524 pic.get_name = pic_dbg_item;
2525 pic.action_callback = pic_action_callback;
2526 return simplelist_show_list(&pic);
2528 #endif
2531 /****** The menu *********/
2532 struct the_menu_item {
2533 unsigned char *desc; /* string or ID */
2534 bool (*function) (void); /* return true if USB was connected */
2536 static const struct the_menu_item menuitems[] = {
2537 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2538 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)) || \
2539 CONFIG_CPU == IMX31L
2540 { "Dump ROM contents", dbg_save_roms },
2541 #endif
2542 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2543 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 \
2544 || CONFIG_CPU == DM320 || defined(CPU_S5L870X)
2545 { "View I/O ports", dbg_ports },
2546 #endif
2547 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2548 { "View PCF registers", dbg_pcf },
2549 #endif
2550 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2551 { "TSC2100 debug", tsc2100_debug },
2552 #endif
2553 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2554 { "CPU frequency", dbg_cpufreq },
2555 #endif
2556 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2557 { "S/PDIF analyzer", dbg_spdif },
2558 #endif
2559 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2560 { "Catch mem accesses", dbg_set_memory_guard },
2561 #endif
2562 { "View OS stacks", dbg_os },
2563 #ifdef HAVE_LCD_BITMAP
2564 #ifndef SIMULATOR
2565 { "View battery", view_battery },
2566 #endif
2567 { "Screendump", dbg_screendump },
2568 #endif
2569 #ifndef SIMULATOR
2570 { "View HW info", dbg_hw_info },
2571 #endif
2572 #ifndef SIMULATOR
2573 { "View partitions", dbg_partitions },
2574 #endif
2575 #ifndef SIMULATOR
2576 { "View disk info", dbg_disk_info },
2577 #if (CONFIG_STORAGE & STORAGE_ATA)
2578 { "Dump ATA identify info", dbg_identify_info},
2579 #endif
2580 #endif
2581 #ifdef HAVE_DIRCACHE
2582 { "View dircache info", dbg_dircache_info },
2583 #endif
2584 #ifdef HAVE_TAGCACHE
2585 { "View database info", dbg_tagcache_info },
2586 #endif
2587 #ifdef HAVE_LCD_BITMAP
2588 #if CONFIG_CODEC == SWCODEC
2589 { "View buffering thread", dbg_buffering_thread },
2590 #elif !defined(SIMULATOR)
2591 { "View audio thread", dbg_audio_thread },
2592 #endif
2593 #ifdef PM_DEBUG
2594 { "pm histogram", peak_meter_histogram},
2595 #endif /* PM_DEBUG */
2596 #endif /* HAVE_LCD_BITMAP */
2597 #ifndef SIMULATOR
2598 #if CONFIG_TUNER
2599 { "FM Radio", dbg_fm_radio },
2600 #endif
2601 #endif
2602 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2603 { "Write back EEPROM", dbg_write_eeprom },
2604 #endif
2605 #if CONFIG_USBOTG == USBOTG_ISP1583
2606 { "View ISP1583 info", dbg_isp1583 },
2607 #endif
2608 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2609 { "View PIC info", dbg_pic },
2610 #endif
2611 #ifdef ROCKBOX_HAS_LOGF
2612 {"logf", logfdisplay },
2613 {"logfdump", logfdump },
2614 #endif
2615 #if defined(HAVE_USBSTACK)
2616 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2617 {"USB Serial driver (logf)", toggle_usb_serial },
2618 #endif
2619 #endif /* HAVE_USBSTACK */
2620 #ifdef CPU_BOOST_LOGGING
2621 {"cpu_boost log",cpu_boost_log},
2622 #endif
2623 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2624 {"Debug scrollwheel", dbg_scrollwheel },
2625 #endif
2627 static int menu_action_callback(int btn, struct gui_synclist *lists)
2629 if (btn == ACTION_STD_OK)
2631 int oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL);
2632 menuitems[gui_synclist_get_sel_pos(lists)].function();
2633 btn = ACTION_REDRAW;
2634 send_event(GUI_EVENT_REFRESH, NULL);
2635 viewportmanager_set_statusbar(oldbars);
2637 return btn;
2640 static const char* dbg_menu_getname(int item, void * data,
2641 char *buffer, size_t buffer_len)
2643 (void)data; (void)buffer; (void)buffer_len;
2644 return menuitems[item].desc;
2647 bool debug_menu(void)
2649 struct simplelist_info info;
2651 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2652 info.action_callback = menu_action_callback;
2653 info.get_name = dbg_menu_getname;
2654 return simplelist_show_list(&info);