Add a slot to set the progress bar value and a member to hide it.
[Rockbox.git] / apps / debug_menu.c
blob313a2aacace537a14e07e9b383b71f653a5a4fa9
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Heikki Hannikainen
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "config.h"
21 #include <stdio.h>
22 #include <stdbool.h>
23 #include <string.h>
24 #include "lcd.h"
25 #include "menu.h"
26 #include "debug_menu.h"
27 #include "kernel.h"
28 #include "sprintf.h"
29 #include "structec.h"
30 #include "action.h"
31 #include "debug.h"
32 #include "thread.h"
33 #include "powermgmt.h"
34 #include "system.h"
35 #include "font.h"
36 #include "audio.h"
37 #include "mp3_playback.h"
38 #include "settings.h"
39 #include "list.h"
40 #include "statusbar.h"
41 #include "dir.h"
42 #include "panic.h"
43 #include "screens.h"
44 #include "misc.h"
45 #include "splash.h"
46 #include "dircache.h"
47 #ifdef HAVE_TAGCACHE
48 #include "tagcache.h"
49 #endif
50 #include "lcd-remote.h"
51 #include "crc32.h"
52 #include "logf.h"
53 #ifndef SIMULATOR
54 #include "disk.h"
55 #include "adc.h"
56 #include "power.h"
57 #include "usb.h"
58 #include "rtc.h"
59 #include "ata.h"
60 #include "fat.h"
61 #include "mas.h"
62 #include "eeprom_24cxx.h"
63 #if defined(HAVE_MMC) || defined(HAVE_ATA_SD)
64 #include "hotswap.h"
65 #endif
66 #if CONFIG_TUNER
67 #include "tuner.h"
68 #include "radio.h"
69 #endif
70 #endif
72 #ifdef HAVE_LCD_BITMAP
73 #include "scrollbar.h"
74 #include "peakmeter.h"
75 #endif
76 #include "logfdisp.h"
77 #if CONFIG_CODEC == SWCODEC
78 #include "pcmbuf.h"
79 #include "buffering.h"
80 #include "playback.h"
81 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
82 #include "spdif.h"
83 #endif
84 #endif
85 #ifdef IRIVER_H300_SERIES
86 #include "pcf50606.h" /* for pcf50606_read */
87 #endif
88 #ifdef IAUDIO_X5
89 #include "ds2411.h"
90 #endif
91 #include "hwcompat.h"
92 #include "button.h"
93 #if CONFIG_RTC == RTC_PCF50605
94 #include "pcf50605.h"
95 #endif
97 #if CONFIG_CPU == DM320 || CONFIG_CPU == S3C2440 || CONFIG_CPU == TCC7801 \
98 || CONFIG_CPU == IMX31L
99 #include "debug-target.h"
100 #endif
102 #if defined(SANSA_E200) || defined(PHILIPS_SA9200)
103 #include "i2c-pp.h"
104 #include "as3514.h"
105 #endif
107 #if defined(HAVE_USBSTACK)
108 #include "usb_core.h"
109 #endif
110 #ifdef USB_STORAGE
111 #include "../firmware/usbstack/usb_storage.h"
112 #endif
114 /*---------------------------------------------------*/
115 /* SPECIAL DEBUG STUFF */
116 /*---------------------------------------------------*/
117 extern struct thread_entry threads[MAXTHREADS];
119 static char thread_status_char(unsigned status)
121 static const char thread_status_chars[THREAD_NUM_STATES+1] =
123 [0 ... THREAD_NUM_STATES] = '?',
124 [STATE_RUNNING] = 'R',
125 [STATE_BLOCKED] = 'B',
126 [STATE_SLEEPING] = 'S',
127 [STATE_BLOCKED_W_TMO] = 'T',
128 [STATE_FROZEN] = 'F',
129 [STATE_KILLED] = 'K',
132 if (status > THREAD_NUM_STATES)
133 status = THREAD_NUM_STATES;
135 return thread_status_chars[status];
138 static char* threads_getname(int selected_item, void *data,
139 char *buffer, size_t buffer_len)
141 (void)data;
142 struct thread_entry *thread;
143 char name[32];
145 #if NUM_CORES > 1
146 if (selected_item < (int)NUM_CORES)
148 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
149 idle_stack_usage(selected_item));
150 return buffer;
153 selected_item -= NUM_CORES;
154 #endif
156 thread = &threads[selected_item];
158 if (thread->state == STATE_KILLED)
160 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
161 return buffer;
164 thread_get_name(name, 32, thread);
166 snprintf(buffer, buffer_len,
167 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
168 selected_item,
169 IF_COP(thread->core,)
170 #ifdef HAVE_SCHEDULER_BOOSTCTRL
171 (thread->cpu_boost) ? '+' :
172 #endif
173 ((thread->state == STATE_RUNNING) ? '*' : ' '),
174 thread_status_char(thread->state),
175 IF_PRIO(thread->base_priority, thread->priority, )
176 thread_stack_usage(thread), name);
178 return buffer;
180 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
182 (void)lists;
183 #ifdef ROCKBOX_HAS_LOGF
184 if (action == ACTION_STD_OK)
186 int selpos = gui_synclist_get_sel_pos(lists);
187 #if NUM_CORES > 1
188 if (selpos >= NUM_CORES)
189 remove_thread(&threads[selpos - NUM_CORES]);
190 #else
191 remove_thread(&threads[selpos]);
192 #endif
193 return ACTION_REDRAW;
195 #endif /* ROCKBOX_HAS_LOGF */
196 if (action == ACTION_NONE)
197 action = ACTION_REDRAW;
198 return action;
200 /* Test code!!! */
201 static bool dbg_os(void)
203 struct simplelist_info info;
204 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
205 #if NUM_CORES == 1
206 MAXTHREADS,
207 #else
208 MAXTHREADS+NUM_CORES,
209 #endif
210 NULL);
211 #ifndef ROCKBOX_HAS_LOGF
212 info.hide_selection = true;
213 info.scroll_all = true;
214 #endif
215 info.action_callback = dbg_threads_action_callback;
216 info.get_name = threads_getname;
217 return simplelist_show_list(&info);
220 #ifdef HAVE_LCD_BITMAP
221 #if CONFIG_CODEC != SWCODEC
222 #ifndef SIMULATOR
223 static bool dbg_audio_thread(void)
225 char buf[32];
226 struct audio_debug d;
228 lcd_setmargins(0, 0);
229 lcd_setfont(FONT_SYSFIXED);
231 while(1)
233 if (action_userabort(HZ/5))
234 return false;
236 audio_get_debugdata(&d);
238 lcd_clear_display();
240 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
241 lcd_puts(0, 0, buf);
242 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
243 lcd_puts(0, 1, buf);
244 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
245 lcd_puts(0, 2, buf);
246 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
247 lcd_puts(0, 3, buf);
248 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
249 lcd_puts(0, 4, buf);
250 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
251 lcd_puts(0, 5, buf);
253 /* Playable space left */
254 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
255 d.playable_space, HORIZONTAL);
257 /* Show the watermark limit */
258 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
259 d.low_watermark_level, HORIZONTAL);
261 snprintf(buf, sizeof(buf), "wm: %x - %x",
262 d.low_watermark_level, d.lowest_watermark_level);
263 lcd_puts(0, 7, buf);
265 lcd_update();
267 return false;
269 #endif /* !SIMULATOR */
270 #else /* CONFIG_CODEC == SWCODEC */
271 extern size_t filebuflen;
272 /* This is a size_t, but call it a long so it puts a - when it's bad. */
274 static unsigned int ticks, boost_ticks, freq_sum;
276 static void dbg_audio_task(void)
278 #ifndef SIMULATOR
279 if(FREQ > CPUFREQ_NORMAL)
280 boost_ticks++;
281 freq_sum += FREQ/1000000; /* in MHz */
282 #endif
283 ticks++;
286 static bool dbg_buffering_thread(void)
288 char buf[32];
289 int button;
290 int line;
291 bool done = false;
292 size_t bufused;
293 size_t bufsize = pcmbuf_get_bufsize();
294 int pcmbufdescs = pcmbuf_descs();
295 struct buffering_debug d;
297 ticks = boost_ticks = freq_sum = 0;
299 tick_add_task(dbg_audio_task);
301 lcd_setmargins(0, 0);
302 lcd_setfont(FONT_SYSFIXED);
303 while(!done)
305 button = get_action(CONTEXT_STD,HZ/5);
306 switch(button)
308 case ACTION_STD_NEXT:
309 audio_next();
310 break;
311 case ACTION_STD_PREV:
312 audio_prev();
313 break;
314 case ACTION_STD_CANCEL:
315 done = true;
316 break;
319 buffering_get_debugdata(&d);
321 line = 0;
322 lcd_clear_display();
324 bufused = bufsize - pcmbuf_free();
326 snprintf(buf, sizeof(buf), "pcm: %7ld/%7ld", (long) bufused, (long) bufsize);
327 lcd_puts(0, line++, buf);
329 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
330 bufsize, 0, bufused, HORIZONTAL);
331 line++;
333 snprintf(buf, sizeof(buf), "alloc: %8ld/%8ld", audio_filebufused(),
334 (long) filebuflen);
335 lcd_puts(0, line++, buf);
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 snprintf(buf, sizeof(buf), "real: %8ld/%8ld", (long)d.buffered_data,
343 (long)filebuflen);
344 lcd_puts(0, line++, buf);
346 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
347 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
348 line++;
349 #endif
351 snprintf(buf, sizeof(buf), "usefl: %8ld/%8ld", (long)(d.useful_data),
352 (long)filebuflen);
353 lcd_puts(0, line++, buf);
355 #if LCD_HEIGHT > 80
356 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
357 filebuflen, 0, d.useful_data, HORIZONTAL);
358 line++;
359 #endif
361 snprintf(buf, sizeof(buf), "data_rem: %ld", (long)d.data_rem);
362 lcd_puts(0, line++, buf);
364 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
365 lcd_puts(0, line++, buf);
367 snprintf(buf, sizeof(buf), "handle count: %d", (int)d.num_handles);
368 lcd_puts(0, line++, buf);
370 #ifndef SIMULATOR
371 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
372 (int)((FREQ + 500000) / 1000000));
373 lcd_puts(0, line++, buf);
374 #endif
376 if (ticks > 0)
378 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
379 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
380 snprintf(buf, sizeof(buf), "boost ratio: %3d.%d%% (%2d.%dMHz)",
381 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
382 lcd_puts(0, line++, buf);
385 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
386 pcmbuf_used_descs(), pcmbufdescs);
387 lcd_puts(0, line++, buf);
389 lcd_update();
392 tick_remove_task(dbg_audio_task);
394 return false;
396 #endif /* CONFIG_CODEC */
397 #endif /* HAVE_LCD_BITMAP */
400 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
401 /* Tool function to read the flash manufacturer and type, if available.
402 Only chips which could be reprogrammed in system will return values.
403 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
404 /* In IRAM to avoid problems when running directly from Flash */
405 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
406 unsigned addr1, unsigned addr2)
407 ICODE_ATTR __attribute__((noinline));
408 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
409 unsigned addr1, unsigned addr2)
412 unsigned not_manu, not_id; /* read values before switching to ID mode */
413 unsigned manu, id; /* read values when in ID mode */
415 #if CONFIG_CPU == SH7034
416 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
417 #elif defined(CPU_COLDFIRE)
418 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
419 #endif
420 int old_level; /* saved interrupt level */
422 not_manu = flash[0]; /* read the normal content */
423 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
425 /* disable interrupts, prevent any stray flash access */
426 old_level = disable_irq_save();
428 flash[addr1] = 0xAA; /* enter command mode */
429 flash[addr2] = 0x55;
430 flash[addr1] = 0x90; /* ID command */
431 /* Atmel wants 20ms pause here */
432 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
434 manu = flash[0]; /* read the IDs */
435 id = flash[1];
437 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
438 /* Atmel wants 20ms pause here */
439 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
441 restore_irq(old_level); /* enable interrupts again */
443 /* I assume success if the obtained values are different from
444 the normal flash content. This is not perfectly bulletproof, they
445 could theoretically be the same by chance, causing us to fail. */
446 if (not_manu != manu || not_id != id) /* a value has changed */
448 *p_manufacturer = manu; /* return the results */
449 *p_device = id;
450 return true; /* success */
452 return false; /* fail */
454 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
456 #ifndef SIMULATOR
457 #ifdef CPU_PP
458 static int perfcheck(void)
460 int result;
462 asm (
463 "mrs r2, CPSR \n"
464 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
465 "msr CPSR_c, r0 \n"
466 "mov %[res], #0 \n"
467 "ldr r0, [%[timr]] \n"
468 "add r0, r0, %[tmo] \n"
469 "1: \n"
470 "add %[res], %[res], #1 \n"
471 "ldr r1, [%[timr]] \n"
472 "cmp r1, r0 \n"
473 "bmi 1b \n"
474 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
476 [res]"=&r"(result)
478 [timr]"r"(&USEC_TIMER),
479 [tmo]"r"(
480 #if CONFIG_CPU == PP5002
481 16000
482 #else /* PP5020/5022/5024 */
483 10226
484 #endif
487 "r0", "r1", "r2"
489 return result;
491 #endif
493 #ifdef HAVE_LCD_BITMAP
494 static bool dbg_hw_info(void)
496 #if CONFIG_CPU == SH7034
497 char buf[32];
498 int bitmask = HW_MASK;
499 int rom_version = ROM_VERSION;
500 unsigned manu, id; /* flash IDs */
501 bool got_id; /* flag if we managed to get the flash IDs */
502 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
503 bool has_bootrom; /* flag for boot ROM present */
504 int oldmode; /* saved memory guard mode */
506 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
508 /* get flash ROM type */
509 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
510 if (!got_id)
511 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
513 /* check if the boot ROM area is a flash mirror */
514 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
515 if (has_bootrom) /* if ROM and Flash different */
517 /* calculate CRC16 checksum of boot ROM */
518 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
521 system_memory_guard(oldmode); /* re-enable memory guard */
523 lcd_setmargins(0, 0);
524 lcd_setfont(FONT_SYSFIXED);
525 lcd_clear_display();
527 lcd_puts(0, 0, "[Hardware info]");
529 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
530 lcd_puts(0, 1, buf);
532 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
533 lcd_puts(0, 2, buf);
535 if (got_id)
536 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
537 else
538 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
539 lcd_puts(0, 3, buf);
541 if (has_bootrom)
543 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
544 snprintf(buf, 32, "Boot ROM: V1");
545 else
546 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
548 else
550 snprintf(buf, 32, "Boot ROM: none");
552 lcd_puts(0, 4, buf);
554 lcd_update();
556 while (!(action_userabort(TIMEOUT_BLOCK)));
558 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
559 char buf[32];
560 unsigned manu, id; /* flash IDs */
561 int got_id; /* flag if we managed to get the flash IDs */
562 int oldmode; /* saved memory guard mode */
563 int line = 0;
565 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
567 /* get flash ROM type */
568 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
569 if (!got_id)
570 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
572 system_memory_guard(oldmode); /* re-enable memory guard */
574 lcd_setmargins(0, 0);
575 lcd_setfont(FONT_SYSFIXED);
576 lcd_clear_display();
578 lcd_puts(0, line++, "[Hardware info]");
580 if (got_id)
581 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
582 else
583 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
584 lcd_puts(0, line++, buf);
586 #ifdef IAUDIO_X5
588 struct ds2411_id id;
590 lcd_puts(0, ++line, "Serial Number:");
592 got_id = ds2411_read_id(&id);
594 if (got_id == DS2411_OK)
596 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
597 lcd_puts(0, ++line, buf);
598 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
599 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
600 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
601 lcd_puts(0, ++line, buf);
602 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
604 else
606 snprintf(buf, 32, "READ ERR=%d", got_id);
609 lcd_puts(0, ++line, buf);
611 #endif
613 lcd_update();
615 while (!(action_userabort(TIMEOUT_BLOCK)));
617 #elif defined(CPU_PP502x)
618 int line = 0;
619 char buf[32];
620 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
621 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
622 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
623 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
625 lcd_setmargins(0, 0);
626 lcd_setfont(FONT_SYSFIXED);
627 lcd_clear_display();
629 lcd_puts(0, line++, "[Hardware info]");
631 #ifdef IPOD_ARCH
632 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
633 lcd_puts(0, line++, buf);
634 #endif
636 #ifdef IPOD_COLOR
637 extern int lcd_type; /* Defined in lcd-colornano.c */
639 snprintf(buf, sizeof(buf), "LCD type: %d", lcd_type);
640 lcd_puts(0, line++, buf);
641 #endif
643 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
644 lcd_puts(0, line++, buf);
646 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
647 lcd_puts(0, line++, buf);
649 lcd_update();
651 while (!(action_userabort(TIMEOUT_BLOCK)));
653 #elif CONFIG_CPU == PP5002
654 int line = 0;
655 char buf[32];
656 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
657 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
658 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
659 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
662 lcd_setmargins(0, 0);
663 lcd_setfont(FONT_SYSFIXED);
664 lcd_clear_display();
666 lcd_puts(0, line++, "[Hardware info]");
668 #ifdef IPOD_ARCH
669 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
670 lcd_puts(0, line++, buf);
671 #endif
673 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
674 lcd_puts(0, line++, buf);
676 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
677 lcd_puts(0, line++, buf);
679 lcd_update();
681 while (!(action_userabort(TIMEOUT_BLOCK)));
682 #else
683 /* Define this function in your target tree */
684 return __dbg_hw_info();
685 #endif /* CONFIG_CPU */
686 return false;
688 #else /* !HAVE_LCD_BITMAP */
689 static bool dbg_hw_info(void)
691 char buf[32];
692 int button;
693 int currval = 0;
694 int rom_version = ROM_VERSION;
695 unsigned manu, id; /* flash IDs */
696 bool got_id; /* flag if we managed to get the flash IDs */
697 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
698 bool has_bootrom; /* flag for boot ROM present */
699 int oldmode; /* saved memory guard mode */
701 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
703 /* get flash ROM type */
704 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
705 if (!got_id)
706 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
708 /* check if the boot ROM area is a flash mirror */
709 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
710 if (has_bootrom) /* if ROM and Flash different */
712 /* calculate CRC16 checksum of boot ROM */
713 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
716 system_memory_guard(oldmode); /* re-enable memory guard */
718 lcd_clear_display();
720 lcd_puts(0, 0, "[HW Info]");
721 while(1)
723 switch(currval)
725 case 0:
726 snprintf(buf, 32, "ROM: %d.%02d",
727 rom_version/100, rom_version%100);
728 break;
729 case 1:
730 if (got_id)
731 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
732 else
733 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
734 break;
735 case 2:
736 if (has_bootrom)
738 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
739 snprintf(buf, 32, "BootROM: V1");
740 else if (rom_crc == 0x358099E8)
741 snprintf(buf, 32, "BootROM: V2");
742 /* alternative boot ROM found in one single player so far */
743 else
744 snprintf(buf, 32, "R: %08x", rom_crc);
746 else
747 snprintf(buf, 32, "BootROM: no");
750 lcd_puts(0, 1, buf);
751 lcd_update();
753 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
755 switch(button)
757 case ACTION_STD_CANCEL:
758 return false;
760 case ACTION_SETTINGS_DEC:
761 currval--;
762 if(currval < 0)
763 currval = 2;
764 break;
766 case ACTION_SETTINGS_INC:
767 currval++;
768 if(currval > 2)
769 currval = 0;
770 break;
773 return false;
775 #endif /* !HAVE_LCD_BITMAP */
776 #endif /* !SIMULATOR */
778 #ifndef SIMULATOR
779 static char* dbg_partitions_getname(int selected_item, void *data,
780 char *buffer, size_t buffer_len)
782 (void)data;
783 int partition = selected_item/2;
784 struct partinfo* p = disk_partinfo(partition);
785 if (selected_item%2)
787 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / 2048);
789 else
791 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
793 return buffer;
796 bool dbg_partitions(void)
798 struct simplelist_info info;
799 simplelist_info_init(&info, "Partition Info", 4, NULL);
800 info.selection_size = 2;
801 info.hide_selection = true;
802 info.scroll_all = true;
803 info.get_name = dbg_partitions_getname;
804 return simplelist_show_list(&info);
806 #endif
808 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
809 static bool dbg_spdif(void)
811 char buf[128];
812 int line;
813 unsigned int control;
814 int x;
815 char *s;
816 int category;
817 int generation;
818 unsigned int interruptstat;
819 bool valnogood, symbolerr, parityerr;
820 bool done = false;
821 bool spdif_src_on;
822 int spdif_source = spdif_get_output_source(&spdif_src_on);
823 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
825 lcd_setmargins(0, 0);
826 lcd_clear_display();
827 lcd_setfont(FONT_SYSFIXED);
829 #ifdef HAVE_SPDIF_POWER
830 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
831 #endif
833 while (!done)
835 line = 0;
837 control = EBU1RCVCCHANNEL1;
838 interruptstat = INTERRUPTSTAT;
839 INTERRUPTCLEAR = 0x03c00000;
841 valnogood = (interruptstat & 0x01000000)?true:false;
842 symbolerr = (interruptstat & 0x00800000)?true:false;
843 parityerr = (interruptstat & 0x00400000)?true:false;
845 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
846 valnogood?"--":"OK",
847 symbolerr?"--":"OK",
848 parityerr?"--":"OK");
849 lcd_puts(0, line++, buf);
851 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
852 lcd_puts(0, line++, buf);
854 line++;
856 x = control >> 31;
857 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
858 x, x?"Professional":"Consumer");
859 lcd_puts(0, line++, buf);
861 x = (control >> 30) & 1;
862 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
863 x, x?"Non-PCM":"PCM");
864 lcd_puts(0, line++, buf);
866 x = (control >> 29) & 1;
867 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
868 x, x?"Permitted":"Inhibited");
869 lcd_puts(0, line++, buf);
871 x = (control >> 27) & 7;
872 switch(x)
874 case 0:
875 s = "None";
876 break;
877 case 1:
878 s = "50/15us";
879 break;
880 default:
881 s = "Reserved";
882 break;
884 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
885 lcd_puts(0, line++, buf);
887 x = (control >> 24) & 3;
888 snprintf(buf, sizeof(buf), "Mode: %d", x);
889 lcd_puts(0, line++, buf);
891 category = (control >> 17) & 127;
892 switch(category)
894 case 0x00:
895 s = "General";
896 break;
897 case 0x40:
898 s = "Audio CD";
899 break;
900 default:
901 s = "Unknown";
903 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
904 lcd_puts(0, line++, buf);
906 x = (control >> 16) & 1;
907 generation = x;
908 if(((category & 0x70) == 0x10) ||
909 ((category & 0x70) == 0x40) ||
910 ((category & 0x78) == 0x38))
912 generation = !generation;
914 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
915 x, generation?"Original":"No ind.");
916 lcd_puts(0, line++, buf);
918 x = (control >> 12) & 15;
919 snprintf(buf, sizeof(buf), "Source: %d", x);
920 lcd_puts(0, line++, buf);
922 x = (control >> 8) & 15;
923 switch(x)
925 case 0:
926 s = "Unspecified";
927 break;
928 case 8:
929 s = "A (Left)";
930 break;
931 case 4:
932 s = "B (Right)";
933 break;
934 default:
935 s = "";
936 break;
938 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
939 lcd_puts(0, line++, buf);
941 x = (control >> 4) & 15;
942 switch(x)
944 case 0:
945 s = "44.1kHz";
946 break;
947 case 0x4:
948 s = "48kHz";
949 break;
950 case 0xc:
951 s = "32kHz";
952 break;
954 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
955 lcd_puts(0, line++, buf);
957 x = (control >> 2) & 3;
958 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
959 lcd_puts(0, line++, buf);
960 line++;
962 #ifndef SIMULATOR
963 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
964 spdif_measure_frequency());
965 lcd_puts(0, line++, buf);
966 #endif
968 lcd_update();
970 if (action_userabort(HZ/10))
971 break;
974 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
976 #ifdef HAVE_SPDIF_POWER
977 spdif_power_enable(global_settings.spdif_enable);
978 #endif
980 return false;
982 #endif /* CPU_COLDFIRE */
984 #ifndef SIMULATOR
985 #ifdef HAVE_LCD_BITMAP
986 /* button definitions */
987 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
988 (CONFIG_KEYPAD == IRIVER_H300_PAD)
989 # define DEBUG_CANCEL BUTTON_OFF
991 #elif CONFIG_KEYPAD == RECORDER_PAD
992 # define DEBUG_CANCEL BUTTON_OFF
994 #elif CONFIG_KEYPAD == ONDIO_PAD
995 # define DEBUG_CANCEL BUTTON_MENU
997 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
998 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
999 (CONFIG_KEYPAD == IPOD_4G_PAD)
1000 # define DEBUG_CANCEL BUTTON_MENU
1002 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
1003 # define DEBUG_CANCEL BUTTON_PLAY
1005 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
1006 # define DEBUG_CANCEL BUTTON_REC
1008 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1009 # define DEBUG_CANCEL BUTTON_RC_REC
1011 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
1012 # define DEBUG_CANCEL BUTTON_REW
1014 #elif (CONFIG_KEYPAD == MROBE100_PAD)
1015 # define DEBUG_CANCEL BUTTON_MENU
1017 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
1018 (CONFIG_KEYPAD == SANSA_C200_PAD)
1019 # define DEBUG_CANCEL BUTTON_LEFT
1021 /* This is temporary until the SA9200 touchpad works */
1022 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD)
1023 # define DEBUG_CANCEL BUTTON_POWER
1025 #endif /* key definitions */
1027 /* Test code!!! */
1028 bool dbg_ports(void)
1030 #if CONFIG_CPU == SH7034
1031 char buf[32];
1032 int adc_battery_voltage, adc_battery_level;
1034 lcd_setfont(FONT_SYSFIXED);
1035 lcd_setmargins(0, 0);
1036 lcd_clear_display();
1038 while(1)
1040 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1041 lcd_puts(0, 0, buf);
1042 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1043 lcd_puts(0, 1, buf);
1045 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1046 lcd_puts(0, 2, buf);
1047 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1048 lcd_puts(0, 3, buf);
1049 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1050 lcd_puts(0, 4, buf);
1051 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1052 lcd_puts(0, 5, buf);
1054 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1055 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1056 adc_battery_voltage % 1000, adc_battery_level);
1057 lcd_puts(0, 6, buf);
1059 lcd_update();
1060 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1061 return false;
1063 #elif defined(CPU_COLDFIRE)
1064 unsigned int gpio_out;
1065 unsigned int gpio1_out;
1066 unsigned int gpio_read;
1067 unsigned int gpio1_read;
1068 unsigned int gpio_function;
1069 unsigned int gpio1_function;
1070 unsigned int gpio_enable;
1071 unsigned int gpio1_enable;
1072 int adc_buttons, adc_remote;
1073 int adc_battery_voltage, adc_battery_level;
1074 char buf[128];
1075 int line;
1077 lcd_setmargins(0, 0);
1078 lcd_clear_display();
1079 lcd_setfont(FONT_SYSFIXED);
1081 while(1)
1083 line = 0;
1084 gpio_read = GPIO_READ;
1085 gpio1_read = GPIO1_READ;
1086 gpio_out = GPIO_OUT;
1087 gpio1_out = GPIO1_OUT;
1088 gpio_function = GPIO_FUNCTION;
1089 gpio1_function = GPIO1_FUNCTION;
1090 gpio_enable = GPIO_ENABLE;
1091 gpio1_enable = GPIO1_ENABLE;
1093 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1094 lcd_puts(0, line++, buf);
1095 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1096 lcd_puts(0, line++, buf);
1097 snprintf(buf, sizeof(buf), "GPIO_FUNC: %08x", gpio_function);
1098 lcd_puts(0, line++, buf);
1099 snprintf(buf, sizeof(buf), "GPIO_ENA: %08x", gpio_enable);
1100 lcd_puts(0, line++, buf);
1102 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1103 lcd_puts(0, line++, buf);
1104 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1105 lcd_puts(0, line++, buf);
1106 snprintf(buf, sizeof(buf), "GPIO1_FUNC: %08x", gpio1_function);
1107 lcd_puts(0, line++, buf);
1108 snprintf(buf, sizeof(buf), "GPIO1_ENA: %08x", gpio1_enable);
1109 lcd_puts(0, line++, buf);
1111 adc_buttons = adc_read(ADC_BUTTONS);
1112 adc_remote = adc_read(ADC_REMOTE);
1113 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1114 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1115 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1116 button_scan_enabled() ? '+' : '-', adc_buttons);
1117 #else
1118 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1119 #endif
1120 lcd_puts(0, line++, buf);
1121 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1122 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1123 remote_detect() ? '+' : '-', adc_remote);
1124 #else
1125 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1126 #endif
1127 lcd_puts(0, line++, buf);
1128 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1129 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1130 adc_read(ADC_REMOTEDETECT));
1131 lcd_puts(0, line++, buf);
1132 #endif
1134 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1135 adc_battery_voltage % 1000, adc_battery_level);
1136 lcd_puts(0, line++, buf);
1138 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1139 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1140 lcd_puts(0, line++, buf);
1141 #endif
1143 lcd_update();
1144 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1145 return false;
1148 #elif defined(CPU_PP502x)
1150 char buf[128];
1151 int line;
1153 lcd_setmargins(0, 0);
1154 lcd_clear_display();
1155 lcd_setfont(FONT_SYSFIXED);
1157 while(1)
1159 line = 0;
1160 lcd_puts(0, line++, "GPIO STATES:");
1161 snprintf(buf, sizeof(buf), "A: %02x E: %02x I: %02x",
1162 (unsigned int)GPIOA_INPUT_VAL,
1163 (unsigned int)GPIOE_INPUT_VAL,
1164 (unsigned int)GPIOI_INPUT_VAL);
1165 lcd_puts(0, line++, buf);
1166 snprintf(buf, sizeof(buf), "B: %02x F: %02x J: %02x",
1167 (unsigned int)GPIOB_INPUT_VAL,
1168 (unsigned int)GPIOF_INPUT_VAL,
1169 (unsigned int)GPIOJ_INPUT_VAL);
1170 lcd_puts(0, line++, buf);
1171 snprintf(buf, sizeof(buf), "C: %02x G: %02x K: %02x",
1172 (unsigned int)GPIOC_INPUT_VAL,
1173 (unsigned int)GPIOG_INPUT_VAL,
1174 (unsigned int)GPIOK_INPUT_VAL);
1175 lcd_puts(0, line++, buf);
1176 snprintf(buf, sizeof(buf), "D: %02x H: %02x L: %02x",
1177 (unsigned int)GPIOD_INPUT_VAL,
1178 (unsigned int)GPIOH_INPUT_VAL,
1179 (unsigned int)GPIOL_INPUT_VAL);
1180 lcd_puts(0, line++, buf);
1181 line++;
1182 snprintf(buf, sizeof(buf), "GPO32_VAL: %08lx", GPO32_VAL);
1183 lcd_puts(0, line++, buf);
1184 snprintf(buf, sizeof(buf), "GPO32_EN: %08lx", GPO32_ENABLE);
1185 lcd_puts(0, line++, buf);
1186 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1187 lcd_puts(0, line++, buf);
1188 snprintf(buf, sizeof(buf), "DEV_EN2: %08lx", DEV_EN2);
1189 lcd_puts(0, line++, buf);
1190 snprintf(buf, sizeof(buf), "DEV_EN3: %08lx", inl(0x60006044));
1191 lcd_puts(0, line++, buf); /* to be verified */
1192 snprintf(buf, sizeof(buf), "DEV_INIT1: %08lx", DEV_INIT1);
1193 lcd_puts(0, line++, buf);
1194 snprintf(buf, sizeof(buf), "DEV_INIT2: %08lx", DEV_INIT2);
1195 lcd_puts(0, line++, buf);
1197 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1198 line++;
1199 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1200 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1201 lcd_puts(0, line++, buf);
1202 snprintf(buf, sizeof(buf), "REM: %03x PAD: %03x",
1203 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1204 lcd_puts(0, line++, buf);
1205 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1206 snprintf(buf, sizeof(buf), "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1207 lcd_puts(0, line++, buf);
1208 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1209 lcd_puts(0, line++, buf);
1210 snprintf(buf, sizeof(buf), "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1211 lcd_puts(0, line++, buf);
1212 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1213 lcd_puts(0, line++, buf);
1214 snprintf(buf, sizeof(buf), "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1215 lcd_puts(0, line++, buf);
1216 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1217 lcd_puts(0, line++, buf);
1218 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1219 lcd_puts(0, line++, buf);
1220 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1221 lcd_puts(0, line++, buf);
1222 snprintf(buf, sizeof(buf), "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1223 lcd_puts(0, line++, buf);
1224 snprintf(buf, sizeof(buf), "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1225 lcd_puts(0, line++, buf);
1226 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1227 lcd_puts(0, line++, buf);
1228 #if !defined(PHILIPS_SA9200)
1229 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1230 lcd_puts(0, line++, buf);
1231 snprintf(buf, sizeof(buf), "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1232 lcd_puts(0, line++, buf);
1233 snprintf(buf, sizeof(buf), "CHARGER: %02X/%02X", i2c_readbyte(AS3514_I2C_ADDR, AS3514_CHARGER), i2c_readbyte(AS3514_I2C_ADDR, AS3514_IRQ_ENRD0));
1234 lcd_puts(0, line++, buf);
1235 #endif
1236 #endif
1237 lcd_update();
1238 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1239 return false;
1242 #elif CONFIG_CPU == PP5002
1243 char buf[128];
1244 int line;
1246 lcd_setmargins(0, 0);
1247 lcd_clear_display();
1248 lcd_setfont(FONT_SYSFIXED);
1250 while(1)
1252 line = 0;
1253 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x",
1254 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1255 lcd_puts(0, line++, buf);
1256 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x",
1257 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1258 lcd_puts(0, line++, buf);
1260 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1261 lcd_puts(0, line++, buf);
1262 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1263 lcd_puts(0, line++, buf);
1264 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1265 lcd_puts(0, line++, buf);
1266 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1267 lcd_puts(0, line++, buf);
1268 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1269 lcd_puts(0, line++, buf);
1270 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1271 lcd_puts(0, line++, buf);
1272 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1273 lcd_puts(0, line++, buf);
1274 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1275 lcd_puts(0, line++, buf);
1277 lcd_update();
1278 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1279 return false;
1281 #else
1282 return __dbg_ports();
1283 #endif /* CPU */
1284 return false;
1286 #else /* !HAVE_LCD_BITMAP */
1287 bool dbg_ports(void)
1289 char buf[32];
1290 int button;
1291 int adc_battery_voltage;
1292 int currval = 0;
1294 lcd_clear_display();
1296 while(1)
1298 switch(currval)
1300 case 0:
1301 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1302 break;
1303 case 1:
1304 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1305 break;
1306 case 2:
1307 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1308 break;
1309 case 3:
1310 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1311 break;
1312 case 4:
1313 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1314 break;
1315 case 5:
1316 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1317 break;
1318 case 6:
1319 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1320 break;
1321 case 7:
1322 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1323 break;
1324 case 8:
1325 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1326 break;
1327 case 9:
1328 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1329 break;
1330 break;
1332 lcd_puts(0, 0, buf);
1334 battery_read_info(&adc_battery_voltage, NULL);
1335 snprintf(buf, 32, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1336 adc_battery_voltage % 1000);
1337 lcd_puts(0, 1, buf);
1338 lcd_update();
1340 button = get_action(CONTEXT_SETTINGS,HZ/5);
1342 switch(button)
1344 case ACTION_STD_CANCEL:
1345 return false;
1347 case ACTION_SETTINGS_DEC:
1348 currval--;
1349 if(currval < 0)
1350 currval = 9;
1351 break;
1353 case ACTION_SETTINGS_INC:
1354 currval++;
1355 if(currval > 9)
1356 currval = 0;
1357 break;
1360 return false;
1362 #endif /* !HAVE_LCD_BITMAP */
1363 #endif /* !SIMULATOR */
1365 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1366 static bool dbg_pcf(void)
1368 char buf[128];
1369 int line;
1371 #ifdef HAVE_LCD_BITMAP
1372 lcd_setmargins(0, 0);
1373 lcd_setfont(FONT_SYSFIXED);
1374 #endif
1375 lcd_clear_display();
1377 while(1)
1379 line = 0;
1381 snprintf(buf, sizeof(buf), "DCDC1: %02x", pcf50605_read(0x1b));
1382 lcd_puts(0, line++, buf);
1383 snprintf(buf, sizeof(buf), "DCDC2: %02x", pcf50605_read(0x1c));
1384 lcd_puts(0, line++, buf);
1385 snprintf(buf, sizeof(buf), "DCDC3: %02x", pcf50605_read(0x1d));
1386 lcd_puts(0, line++, buf);
1387 snprintf(buf, sizeof(buf), "DCDC4: %02x", pcf50605_read(0x1e));
1388 lcd_puts(0, line++, buf);
1389 snprintf(buf, sizeof(buf), "DCDEC1: %02x", pcf50605_read(0x1f));
1390 lcd_puts(0, line++, buf);
1391 snprintf(buf, sizeof(buf), "DCDEC2: %02x", pcf50605_read(0x20));
1392 lcd_puts(0, line++, buf);
1393 snprintf(buf, sizeof(buf), "DCUDC1: %02x", pcf50605_read(0x21));
1394 lcd_puts(0, line++, buf);
1395 snprintf(buf, sizeof(buf), "DCUDC2: %02x", pcf50605_read(0x22));
1396 lcd_puts(0, line++, buf);
1397 snprintf(buf, sizeof(buf), "IOREGC: %02x", pcf50605_read(0x23));
1398 lcd_puts(0, line++, buf);
1399 snprintf(buf, sizeof(buf), "D1REGC: %02x", pcf50605_read(0x24));
1400 lcd_puts(0, line++, buf);
1401 snprintf(buf, sizeof(buf), "D2REGC: %02x", pcf50605_read(0x25));
1402 lcd_puts(0, line++, buf);
1403 snprintf(buf, sizeof(buf), "D3REGC: %02x", pcf50605_read(0x26));
1404 lcd_puts(0, line++, buf);
1405 snprintf(buf, sizeof(buf), "LPREG1: %02x", pcf50605_read(0x27));
1406 lcd_puts(0, line++, buf);
1408 lcd_update();
1409 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1411 return false;
1415 return false;
1417 #endif
1419 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1420 static bool dbg_cpufreq(void)
1422 char buf[128];
1423 int line;
1424 int button;
1426 #ifdef HAVE_LCD_BITMAP
1427 lcd_setmargins(0, 0);
1428 lcd_setfont(FONT_SYSFIXED);
1429 #endif
1430 lcd_clear_display();
1432 while(1)
1434 line = 0;
1436 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1437 lcd_puts(0, line++, buf);
1439 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1440 lcd_puts(0, line++, buf);
1442 lcd_update();
1443 button = get_action(CONTEXT_STD,HZ/10);
1445 switch(button)
1447 case ACTION_STD_PREV:
1448 cpu_boost(true);
1449 break;
1451 case ACTION_STD_NEXT:
1452 cpu_boost(false);
1453 break;
1455 case ACTION_STD_OK:
1456 while (get_cpu_boost_counter() > 0)
1457 cpu_boost(false);
1458 set_cpu_frequency(CPUFREQ_DEFAULT);
1459 break;
1461 case ACTION_STD_CANCEL:
1462 return false;
1466 return false;
1468 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1470 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1471 #include "tsc2100.h"
1472 char *itob(int n, int len)
1474 static char binary[64];
1475 int i,j;
1476 for (i=1, j=0;i<=len;i++)
1478 binary[j++] = n&(1<<(len-i))?'1':'0';
1479 if (i%4 == 0)
1480 binary[j++] = ' ';
1482 binary[j] = '\0';
1483 return binary;
1485 static char* tsc2100_debug_getname(int selected_item, void * data,
1486 char *buffer, size_t buffer_len)
1488 int *page = (int*)data;
1489 bool reserved = false;
1490 switch (*page)
1492 case 0:
1493 if ((selected_item > 0x0a) ||
1494 (selected_item == 0x04) ||
1495 (selected_item == 0x08))
1496 reserved = true;
1497 break;
1498 case 1:
1499 if ((selected_item > 0x05) ||
1500 (selected_item == 0x02))
1501 reserved = true;
1502 break;
1503 case 2:
1504 if (selected_item > 0x1e)
1505 reserved = true;
1506 break;
1508 if (reserved)
1509 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1510 else
1511 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1512 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1513 return buffer;
1515 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1517 int *page = (int*)lists->data;
1518 if (action == ACTION_STD_OK)
1520 *page = (*page+1)%3;
1521 snprintf(lists->title, 32,
1522 "tsc2100 registers - Page %d", *page);
1523 return ACTION_REDRAW;
1525 return action;
1527 bool tsc2100_debug(void)
1529 int page = 0;
1530 char title[32] = "tsc2100 registers - Page 0";
1531 struct simplelist_info info;
1532 simplelist_info_init(&info, title, 32, &page);
1533 info.timeout = HZ/100;
1534 info.get_name = tsc2100_debug_getname;
1535 info.action_callback= tsc2100debug_action_callback;
1536 return simplelist_show_list(&info);
1538 #endif
1539 #ifndef SIMULATOR
1540 #ifdef HAVE_LCD_BITMAP
1542 * view_battery() shows a automatically scaled graph of the battery voltage
1543 * over time. Usable for estimating battery life / charging rate.
1544 * The power_history array is updated in power_thread of powermgmt.c.
1547 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1548 #define BAT_YSPACE (LCD_HEIGHT - 20)
1550 static bool view_battery(void)
1552 int view = 0;
1553 int i, x, y;
1554 unsigned short maxv, minv;
1555 char buf[32];
1557 lcd_setmargins(0, 0);
1558 lcd_setfont(FONT_SYSFIXED);
1560 while(1)
1562 lcd_clear_display();
1563 switch (view) {
1564 case 0: /* voltage history graph */
1565 /* Find maximum and minimum voltage for scaling */
1566 minv = power_history[0];
1567 maxv = minv + 1;
1568 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1569 if (power_history[i] > maxv)
1570 maxv = power_history[i];
1571 if (power_history[i] < minv)
1572 minv = power_history[i];
1575 snprintf(buf, 30, "Battery %d.%03d", power_history[0] / 1000,
1576 power_history[0] % 1000);
1577 lcd_puts(0, 0, buf);
1578 snprintf(buf, 30, "scale %d.%03d-%d.%03dV",
1579 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1580 lcd_puts(0, 1, buf);
1582 x = 0;
1583 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1584 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1585 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1586 lcd_vline(x, LCD_HEIGHT-1, 20);
1587 lcd_set_drawmode(DRMODE_SOLID);
1588 lcd_vline(x, LCD_HEIGHT-1,
1589 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1590 x++;
1593 break;
1595 case 1: /* status: */
1596 lcd_puts(0, 0, "Power status:");
1598 battery_read_info(&y, NULL);
1599 snprintf(buf, 30, "Battery: %d.%03d V", y / 1000, y % 1000);
1600 lcd_puts(0, 1, buf);
1601 #ifdef ADC_EXT_POWER
1602 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1603 snprintf(buf, 30, "External: %d.%03d V", y / 1000, y % 1000);
1604 lcd_puts(0, 2, buf);
1605 #endif
1606 #if CONFIG_CHARGING
1607 #if CONFIG_CHARGING == CHARGING_CONTROL
1608 snprintf(buf, 30, "Chgr: %s %s",
1609 charger_inserted() ? "present" : "absent",
1610 charger_enabled ? "on" : "off");
1611 lcd_puts(0, 3, buf);
1612 snprintf(buf, 30, "short delta: %d", short_delta);
1613 lcd_puts(0, 5, buf);
1614 snprintf(buf, 30, "long delta: %d", long_delta);
1615 lcd_puts(0, 6, buf);
1616 lcd_puts(0, 7, power_message);
1617 snprintf(buf, 30, "USB Inserted: %s",
1618 usb_inserted() ? "yes" : "no");
1619 lcd_puts(0, 8, buf);
1620 #if defined IRIVER_H300_SERIES
1621 snprintf(buf, 30, "USB Charging Enabled: %s",
1622 usb_charging_enabled() ? "yes" : "no");
1623 lcd_puts(0, 9, buf);
1624 #endif
1625 #else /* CONFIG_CHARGING != CHARGING_CONTROL */
1626 #if defined IPOD_NANO || defined IPOD_VIDEO
1627 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1628 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1629 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1630 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1631 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1633 snprintf(buf, 30, "USB pwr: %s",
1634 usb_pwr ? "present" : "absent");
1635 lcd_puts(0, 3, buf);
1636 snprintf(buf, 30, "EXT pwr: %s",
1637 ext_pwr ? "present" : "absent");
1638 lcd_puts(0, 4, buf);
1639 snprintf(buf, 30, "Battery: %s",
1640 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1641 lcd_puts(0, 5, buf);
1642 snprintf(buf, 30, "Dock mode: %s",
1643 dock ? "enabled" : "disabled");
1644 lcd_puts(0, 6, buf);
1645 snprintf(buf, 30, "Headphone: %s",
1646 headphone ? "connected" : "disconnected");
1647 lcd_puts(0, 7, buf);
1648 #else
1649 snprintf(buf, 30, "Charger: %s",
1650 charger_inserted() ? "present" : "absent");
1651 lcd_puts(0, 3, buf);
1652 #endif
1653 #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1654 #endif /* CONFIG_CHARGING */
1655 break;
1657 case 2: /* voltage deltas: */
1658 lcd_puts(0, 0, "Voltage deltas:");
1660 for (i = 0; i <= 6; i++) {
1661 y = power_history[i] - power_history[i+1];
1662 snprintf(buf, 30, "-%d min: %s%d.%03d V", i,
1663 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1664 ((y < 0) ? y * -1 : y ) % 1000);
1665 lcd_puts(0, i+1, buf);
1667 break;
1669 case 3: /* remaining time estimation: */
1671 #if CONFIG_CHARGING == CHARGING_CONTROL
1672 snprintf(buf, 30, "charge_state: %d", charge_state);
1673 lcd_puts(0, 0, buf);
1675 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1676 lcd_puts(0, 1, buf);
1678 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1679 lcd_puts(0, 2, buf);
1681 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1682 lcd_puts(0, 3, buf);
1684 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1685 lcd_puts(0, 4, buf);
1686 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
1688 snprintf(buf, 30, "Last PwrHist: %d.%03dV",
1689 power_history[0] / 1000,
1690 power_history[0] % 1000);
1691 lcd_puts(0, 5, buf);
1693 snprintf(buf, 30, "battery level: %d%%", battery_level());
1694 lcd_puts(0, 6, buf);
1696 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1697 lcd_puts(0, 7, buf);
1698 break;
1701 lcd_update();
1703 switch(get_action(CONTEXT_STD,HZ/2))
1705 case ACTION_STD_PREV:
1706 if (view)
1707 view--;
1708 break;
1710 case ACTION_STD_NEXT:
1711 if (view < 3)
1712 view++;
1713 break;
1715 case ACTION_STD_CANCEL:
1716 return false;
1719 return false;
1722 #endif /* HAVE_LCD_BITMAP */
1723 #endif
1725 #ifndef SIMULATOR
1726 #if defined(HAVE_MMC) || defined(HAVE_ATA_SD)
1727 #if defined(HAVE_MMC)
1728 #define CARDTYPE "MMC"
1729 #else
1730 #define CARDTYPE "microSD"
1731 #endif
1732 static int disk_callback(int btn, struct gui_synclist *lists)
1734 tCardInfo *card;
1735 int *cardnum = (int*)lists->data;
1736 unsigned char card_name[7];
1737 unsigned char pbuf[32];
1738 char *title = lists->title;
1739 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1740 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1741 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1742 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1743 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1744 "3.1-3.31", "4.0" };
1745 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1747 #ifdef HAVE_HOTSWAP
1748 if (btn == ACTION_STD_OK)
1750 *cardnum ^= 0x1; /* change cards */
1752 #endif
1754 simplelist_set_line_count(0);
1756 card = card_get_info(*cardnum);
1758 if (card->initialized > 0)
1760 card_name[6] = '\0';
1761 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1762 simplelist_addline(SIMPLELIST_ADD_LINE,
1763 "%s Rev %d.%d", card_name,
1764 (int) card_extract_bits(card->cid, 72, 4),
1765 (int) card_extract_bits(card->cid, 76, 4));
1766 simplelist_addline(SIMPLELIST_ADD_LINE,
1767 "Prod: %d/%d",
1768 (int) card_extract_bits(card->cid, 112, 4),
1769 (int) card_extract_bits(card->cid, 116, 4) + 1997);
1770 simplelist_addline(SIMPLELIST_ADD_LINE,
1771 "Ser#: 0x%08lx",
1772 card_extract_bits(card->cid, 80, 32));
1773 simplelist_addline(SIMPLELIST_ADD_LINE,
1774 "M=%02x, O=%04x",
1775 (int) card_extract_bits(card->cid, 0, 8),
1776 (int) card_extract_bits(card->cid, 8, 16));
1777 int temp = card_extract_bits(card->csd, 2, 4);
1778 simplelist_addline(SIMPLELIST_ADD_LINE,
1779 CARDTYPE " v%s", temp < 5 ?
1780 spec_vers[temp] : "?.?");
1781 simplelist_addline(SIMPLELIST_ADD_LINE,
1782 "Blocks: 0x%06lx", card->numblocks);
1783 simplelist_addline(SIMPLELIST_ADD_LINE,
1784 "Blksz.: %d P:%c%c", card->blocksize,
1785 card_extract_bits(card->csd, 48, 1) ? 'R' : '-',
1786 card_extract_bits(card->csd, 106, 1) ? 'W' : '-');
1787 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1788 kbit_units, false);
1789 simplelist_addline(SIMPLELIST_ADD_LINE,
1790 "Speed: %s", pbuf);
1791 output_dyn_value(pbuf, sizeof pbuf, card->tsac,
1792 nsec_units, false);
1793 simplelist_addline(SIMPLELIST_ADD_LINE,
1794 "Tsac: %s", pbuf);
1795 simplelist_addline(SIMPLELIST_ADD_LINE,
1796 "Nsac: %d clk", card->nsac);
1797 simplelist_addline(SIMPLELIST_ADD_LINE,
1798 "R2W: *%d", card->r2w_factor);
1799 simplelist_addline(SIMPLELIST_ADD_LINE,
1800 "IRmax: %d..%d mA",
1801 i_vmin[card_extract_bits(card->csd, 66, 3)],
1802 i_vmax[card_extract_bits(card->csd, 69, 3)]);
1803 simplelist_addline(SIMPLELIST_ADD_LINE,
1804 "IWmax: %d..%d mA",
1805 i_vmin[card_extract_bits(card->csd, 72, 3)],
1806 i_vmax[card_extract_bits(card->csd, 75, 3)]);
1808 else if (card->initialized == 0)
1810 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1812 #ifndef HAVE_MMC
1813 else /* card->initialized < 0 */
1815 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1817 #endif
1818 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1819 gui_synclist_set_title(lists, title, Icon_NOICON);
1820 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1821 gui_synclist_select_item(lists, 0);
1822 btn = ACTION_REDRAW;
1824 return btn;
1826 #else /* !defined(HAVE_MMC) && !defined(HAVE_ATA_SD) */
1827 static int disk_callback(int btn, struct gui_synclist *lists)
1829 (void)lists;
1830 int i;
1831 char buf[128];
1832 unsigned short* identify_info = ata_get_identify();
1833 bool timing_info_present = false;
1834 (void)btn;
1836 simplelist_set_line_count(0);
1838 for (i=0; i < 20; i++)
1839 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1840 buf[40]=0;
1841 /* kill trailing space */
1842 for (i=39; i && buf[i]==' '; i--)
1843 buf[i] = 0;
1844 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1845 for (i=0; i < 4; i++)
1846 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1847 buf[8]=0;
1848 simplelist_addline(SIMPLELIST_ADD_LINE,
1849 "Firmware: %s", buf);
1850 snprintf(buf, sizeof buf, "%ld MB",
1851 ((unsigned long)identify_info[61] << 16 |
1852 (unsigned long)identify_info[60]) / 2048 );
1853 simplelist_addline(SIMPLELIST_ADD_LINE,
1854 "Size: %s", buf);
1855 unsigned long free;
1856 fat_size( IF_MV2(0,) NULL, &free );
1857 simplelist_addline(SIMPLELIST_ADD_LINE,
1858 "Free: %ld MB", free / 1024);
1859 simplelist_addline(SIMPLELIST_ADD_LINE,
1860 "Spinup time: %d ms", ata_spinup_time * (1000/HZ));
1861 i = identify_info[83] & (1<<3);
1862 simplelist_addline(SIMPLELIST_ADD_LINE,
1863 "Power mgmt: %s", i ? "enabled" : "unsupported");
1864 i = identify_info[83] & (1<<9);
1865 simplelist_addline(SIMPLELIST_ADD_LINE,
1866 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1867 i = identify_info[82] & (1<<6);
1868 simplelist_addline(SIMPLELIST_ADD_LINE,
1869 "Read-ahead: %s", i ? "enabled" : "unsupported");
1870 timing_info_present = identify_info[53] & (1<<1);
1871 if(timing_info_present) {
1872 char pio3[2], pio4[2];pio3[1] = 0;
1873 pio4[1] = 0;
1874 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1875 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1876 simplelist_addline(SIMPLELIST_ADD_LINE,
1877 "PIO modes: 0 1 2 %s %s", pio3, pio4);
1879 else {
1880 simplelist_addline(SIMPLELIST_ADD_LINE,
1881 "No PIO mode info");
1883 timing_info_present = identify_info[53] & (1<<1);
1884 if(timing_info_present) {
1885 simplelist_addline(SIMPLELIST_ADD_LINE,
1886 "Cycle times %dns/%dns",
1887 identify_info[67],
1888 identify_info[68] );
1889 } else {
1890 simplelist_addline(SIMPLELIST_ADD_LINE,
1891 "No timing info");
1893 #if defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S)
1894 if (identify_info[63] & (1<<0)) {
1895 char mdma0[2], mdma1[2], mdma2[2];
1896 mdma0[1] = mdma1[1] = mdma2[1] = 0;
1897 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
1898 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
1899 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
1900 simplelist_addline(SIMPLELIST_ADD_LINE,
1901 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
1902 simplelist_addline(SIMPLELIST_ADD_LINE,
1903 "MDMA Cycle times %dns/%dns",
1904 identify_info[65],
1905 identify_info[66] );
1907 else {
1908 simplelist_addline(SIMPLELIST_ADD_LINE,
1909 "No MDMA mode info");
1911 if (identify_info[88] & (1<<0)) {
1912 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2];
1913 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = 0;
1914 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
1915 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
1916 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
1917 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
1918 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
1919 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
1920 simplelist_addline(SIMPLELIST_ADD_LINE,
1921 "UDMA modes: %s %s %s %s %s %s", udma0, udma1, udma2,
1922 udma3, udma4, udma5);
1924 else {
1925 simplelist_addline(SIMPLELIST_ADD_LINE,
1926 "No UDMA mode info");
1928 #endif /* defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S) */
1929 timing_info_present = identify_info[53] & (1<<1);
1930 if(timing_info_present) {
1931 i = identify_info[49] & (1<<11);
1932 simplelist_addline(SIMPLELIST_ADD_LINE,
1933 "IORDY support: %s", i ? "yes" : "no");
1934 i = identify_info[49] & (1<<10);
1935 simplelist_addline(SIMPLELIST_ADD_LINE,
1936 "IORDY disable: %s", i ? "yes" : "no");
1937 } else {
1938 simplelist_addline(SIMPLELIST_ADD_LINE,
1939 "No timing info");
1941 simplelist_addline(SIMPLELIST_ADD_LINE,
1942 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1943 return btn;
1946 static bool dbg_identify_info(void)
1948 int fd = creat("/identify_info.bin");
1949 if(fd >= 0)
1951 #ifdef ROCKBOX_LITTLE_ENDIAN
1952 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
1953 #else
1954 write(fd, ata_get_identify(), SECTOR_SIZE);
1955 #endif
1956 close(fd);
1958 return false;
1960 #endif /* !defined(HAVE_MMC) && !defined(HAVE_ATA_SD) */
1962 static bool dbg_disk_info(void)
1964 struct simplelist_info info;
1965 simplelist_info_init(&info, "Disk Info", 1, NULL);
1966 #if defined(HAVE_MMC) || defined(HAVE_ATA_SD)
1967 char title[16];
1968 int card = 0;
1969 info.callback_data = (void*)&card;
1970 info.title = title;
1971 #endif
1972 info.action_callback = disk_callback;
1973 info.hide_selection = true;
1974 info.scroll_all = true;
1975 return simplelist_show_list(&info);
1977 #endif /* !SIMULATOR */
1979 #ifdef HAVE_DIRCACHE
1980 static int dircache_callback(int btn, struct gui_synclist *lists)
1982 (void)btn; (void)lists;
1983 simplelist_set_line_count(0);
1984 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
1985 dircache_is_enabled() ? "Yes" : "No");
1986 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
1987 dircache_get_cache_size());
1988 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
1989 global_status.dircache_size);
1990 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
1991 DIRCACHE_LIMIT);
1992 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
1993 dircache_get_reserve_used(), DIRCACHE_RESERVE);
1994 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
1995 dircache_get_build_ticks() / HZ);
1996 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
1997 dircache_get_entry_count());
1998 return btn;
2001 static bool dbg_dircache_info(void)
2003 struct simplelist_info info;
2004 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2005 info.action_callback = dircache_callback;
2006 info.hide_selection = true;
2007 info.scroll_all = true;
2008 return simplelist_show_list(&info);
2011 #endif /* HAVE_DIRCACHE */
2013 #ifdef HAVE_TAGCACHE
2014 static int database_callback(int btn, struct gui_synclist *lists)
2016 (void)lists;
2017 struct tagcache_stat *stat = tagcache_get_stat();
2018 static bool synced = false;
2020 simplelist_set_line_count(0);
2022 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2023 stat->initialized ? "Yes" : "No");
2024 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2025 stat->ready ? "Yes" : "No");
2026 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2027 stat->ramcache ? "Yes" : "No");
2028 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2029 stat->ramcache_used, stat->ramcache_allocated);
2030 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2031 stat->progress, stat->processed_entries);
2032 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2033 stat->curentry ? stat->curentry : "---");
2034 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2035 stat->commit_step);
2036 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2037 stat->commit_delayed ? "Yes" : "No");
2039 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2040 stat->queue_length);
2042 if (synced)
2044 synced = false;
2045 tagcache_screensync_event();
2048 if (!btn && stat->curentry)
2050 synced = true;
2051 return ACTION_REDRAW;
2054 if (btn == ACTION_STD_CANCEL)
2055 tagcache_screensync_enable(false);
2057 return btn;
2059 static bool dbg_tagcache_info(void)
2061 struct simplelist_info info;
2062 simplelist_info_init(&info, "Database Info", 8, NULL);
2063 info.action_callback = database_callback;
2064 info.hide_selection = true;
2065 info.scroll_all = true;
2067 /* Don't do nonblock here, must give enough processing time
2068 for tagcache thread. */
2069 /* info.timeout = TIMEOUT_NOBLOCK; */
2070 info.timeout = 1;
2071 tagcache_screensync_enable(true);
2072 return simplelist_show_list(&info);
2074 #endif
2076 #if CONFIG_CPU == SH7034
2077 static bool dbg_save_roms(void)
2079 int fd;
2080 int oldmode = system_memory_guard(MEMGUARD_NONE);
2082 fd = creat("/internal_rom_0000-FFFF.bin");
2083 if(fd >= 0)
2085 write(fd, (void *)0, 0x10000);
2086 close(fd);
2089 fd = creat("/internal_rom_2000000-203FFFF.bin");
2090 if(fd >= 0)
2092 write(fd, (void *)0x2000000, 0x40000);
2093 close(fd);
2096 system_memory_guard(oldmode);
2097 return false;
2099 #elif defined CPU_COLDFIRE
2100 static bool dbg_save_roms(void)
2102 int fd;
2103 int oldmode = system_memory_guard(MEMGUARD_NONE);
2105 #if defined(IRIVER_H100_SERIES)
2106 fd = creat("/internal_rom_000000-1FFFFF.bin");
2107 #elif defined(IRIVER_H300_SERIES)
2108 fd = creat("/internal_rom_000000-3FFFFF.bin");
2109 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2110 fd = creat("/internal_rom_000000-3FFFFF.bin");
2111 #endif
2112 if(fd >= 0)
2114 write(fd, (void *)0, FLASH_SIZE);
2115 close(fd);
2117 system_memory_guard(oldmode);
2119 #ifdef HAVE_EEPROM
2120 fd = creat("/internal_eeprom.bin");
2121 if (fd >= 0)
2123 int old_irq_level;
2124 char buf[EEPROM_SIZE];
2125 int err;
2127 old_irq_level = disable_irq_save();
2129 err = eeprom_24cxx_read(0, buf, sizeof buf);
2131 restore_irq(old_irq_level);
2133 if (err)
2134 gui_syncsplash(HZ*3, "Eeprom read failure (%d)",err);
2135 else
2137 write(fd, buf, sizeof buf);
2140 close(fd);
2142 #endif
2144 return false;
2146 #elif defined(CPU_PP) && !defined(HAVE_ATA_SD)
2147 static bool dbg_save_roms(void)
2149 int fd;
2151 fd = creat("/internal_rom_000000-0FFFFF.bin");
2152 if(fd >= 0)
2154 write(fd, (void *)0x20000000, FLASH_SIZE);
2155 close(fd);
2158 return false;
2160 #endif /* CPU */
2162 #ifndef SIMULATOR
2163 #if CONFIG_TUNER
2164 static int radio_callback(int btn, struct gui_synclist *lists)
2166 (void)lists;
2167 if (btn == ACTION_STD_CANCEL)
2168 return btn;
2169 simplelist_set_line_count(1);
2171 #if (CONFIG_TUNER & LV24020LP)
2172 simplelist_addline(SIMPLELIST_ADD_LINE,
2173 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2174 simplelist_addline(SIMPLELIST_ADD_LINE,
2175 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2176 simplelist_addline(SIMPLELIST_ADD_LINE,
2177 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2178 simplelist_addline(SIMPLELIST_ADD_LINE,
2179 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2180 simplelist_addline(SIMPLELIST_ADD_LINE,
2181 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2182 simplelist_addline(SIMPLELIST_ADD_LINE,
2183 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2184 simplelist_addline(SIMPLELIST_ADD_LINE,
2185 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2186 #endif
2187 #if (CONFIG_TUNER & S1A0903X01)
2188 simplelist_addline(SIMPLELIST_ADD_LINE,
2189 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2190 /* This one doesn't return dynamic data atm */
2191 #endif
2192 #if (CONFIG_TUNER & TEA5767)
2193 struct tea5767_dbg_info nfo;
2194 tea5767_dbg_info(&nfo);
2195 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2196 simplelist_addline(SIMPLELIST_ADD_LINE,
2197 " Read: %02X %02X %02X %02X %02X",
2198 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2199 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2200 (unsigned)nfo.read_regs[4]);
2201 simplelist_addline(SIMPLELIST_ADD_LINE,
2202 " Write: %02X %02X %02X %02X %02X",
2203 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2204 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2205 (unsigned)nfo.write_regs[4]);
2206 #endif
2207 return ACTION_REDRAW;
2209 static bool dbg_fm_radio(void)
2211 struct simplelist_info info;
2212 info.scroll_all = true;
2213 simplelist_info_init(&info, "FM Radio", 1, NULL);
2214 simplelist_set_line_count(0);
2215 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2216 radio_hardware_present() ? "yes" : "no");
2218 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2219 info.hide_selection = true;
2220 return simplelist_show_list(&info);
2222 #endif /* CONFIG_TUNER */
2223 #endif /* !SIMULATOR */
2225 #ifdef HAVE_LCD_BITMAP
2226 extern bool do_screendump_instead_of_usb;
2228 static bool dbg_screendump(void)
2230 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2231 gui_syncsplash(HZ, "Screendump %s",
2232 do_screendump_instead_of_usb?"enabled":"disabled");
2233 return false;
2235 #endif /* HAVE_LCD_BITMAP */
2237 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2238 static bool dbg_set_memory_guard(void)
2240 static const struct opt_items names[MAXMEMGUARD] = {
2241 { "None", -1 },
2242 { "Flash ROM writes", -1 },
2243 { "Zero area (all)", -1 }
2245 int mode = system_memory_guard(MEMGUARD_KEEP);
2247 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2248 system_memory_guard(mode);
2250 return false;
2252 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2254 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2255 static bool dbg_write_eeprom(void)
2257 int fd;
2258 int rc;
2259 int old_irq_level;
2260 char buf[EEPROM_SIZE];
2261 int err;
2263 fd = open("/internal_eeprom.bin", O_RDONLY);
2265 if (fd >= 0)
2267 rc = read(fd, buf, EEPROM_SIZE);
2269 if(rc == EEPROM_SIZE)
2271 old_irq_level = disable_irq_save();
2273 err = eeprom_24cxx_write(0, buf, sizeof buf);
2274 if (err)
2275 gui_syncsplash(HZ*3, "Eeprom write failure (%d)",err);
2276 else
2277 gui_syncsplash(HZ*3, "Eeprom written successfully");
2279 restore_irq(old_irq_level);
2281 else
2283 gui_syncsplash(HZ*3, "File read error (%d)",rc);
2285 close(fd);
2287 else
2289 gui_syncsplash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2292 return false;
2294 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2295 #ifdef CPU_BOOST_LOGGING
2296 static bool cpu_boost_log(void)
2298 int i = 0,j=0;
2299 int count = cpu_boost_log_getcount();
2300 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2301 char *str;
2302 bool done;
2303 lcd_setmargins(0, 0);
2304 lcd_setfont(FONT_SYSFIXED);
2305 str = cpu_boost_log_getlog_first();
2306 while (i < count)
2308 lcd_clear_display();
2309 for(j=0; j<lines; j++,i++)
2311 if (!str)
2312 str = cpu_boost_log_getlog_next();
2313 if (str)
2315 lcd_puts(0, j,str);
2317 str = NULL;
2319 lcd_update();
2320 done = false;
2321 while (!done)
2323 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2325 case ACTION_STD_OK:
2326 case ACTION_STD_PREV:
2327 case ACTION_STD_NEXT:
2328 done = true;
2329 break;
2330 case ACTION_STD_CANCEL:
2331 i = count;
2332 done = true;
2333 break;
2337 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2338 lcd_setfont(FONT_UI);
2339 return false;
2341 #endif
2343 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2344 extern bool wheel_is_touched;
2345 extern int old_wheel_value;
2346 extern int new_wheel_value;
2347 extern int wheel_delta;
2348 extern unsigned int accumulated_wheel_delta;
2349 extern unsigned int wheel_velocity;
2351 static bool dbg_scrollwheel(void)
2353 char buf[64];
2354 unsigned int speed;
2356 lcd_setmargins(0, 0);
2357 lcd_setfont(FONT_SYSFIXED);
2359 while (1)
2361 if (action_userabort(HZ/10))
2362 return false;
2364 lcd_clear_display();
2366 /* show internal variables of scrollwheel driver */
2367 snprintf(buf, sizeof(buf), "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2368 lcd_puts(0, 0, buf);
2369 snprintf(buf, sizeof(buf), "new position: %2d", new_wheel_value);
2370 lcd_puts(0, 1, buf);
2371 snprintf(buf, sizeof(buf), "old position: %2d", old_wheel_value);
2372 lcd_puts(0, 2, buf);
2373 snprintf(buf, sizeof(buf), "wheel delta: %2d", wheel_delta);
2374 lcd_puts(0, 3, buf);
2375 snprintf(buf, sizeof(buf), "accumulated delta: %2d", accumulated_wheel_delta);
2376 lcd_puts(0, 4, buf);
2377 snprintf(buf, sizeof(buf), "velo [deg/s]: %4d", (int)wheel_velocity);
2378 lcd_puts(0, 5, buf);
2380 /* show effective accelerated scrollspeed */
2381 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2382 snprintf(buf, sizeof(buf), "accel. speed: %4d", speed);
2383 lcd_puts(0, 6, buf);
2385 lcd_update();
2387 return false;
2389 #endif
2391 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2392 static bool logf_usb_serial(void)
2394 bool serial_enabled = !usb_core_driver_enabled(USB_DRIVER_SERIAL);
2395 usb_core_enable_driver(USB_DRIVER_SERIAL,serial_enabled);
2396 gui_syncsplash(HZ, "USB logf %s",
2397 serial_enabled?"enabled":"disabled");
2398 return false;
2400 #endif
2402 #if defined(HAVE_USBSTACK) && defined(USB_STORAGE)
2403 static bool usb_reconnect(void)
2405 gui_syncsplash(HZ, "Reconnect mass storage");
2406 usb_storage_reconnect();
2407 return false;
2409 #endif
2411 #if CONFIG_USBOTG == USBOTG_ISP1583
2412 extern int dbg_usb_num_items(void);
2413 extern char* dbg_usb_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2415 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2417 (void)lists;
2418 if (action == ACTION_NONE)
2419 action = ACTION_REDRAW;
2420 return action;
2423 static bool dbg_isp1583(void)
2425 struct simplelist_info isp1583;
2426 isp1583.scroll_all = true;
2427 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2428 isp1583.timeout = HZ/100;
2429 isp1583.hide_selection = true;
2430 isp1583.get_name = dbg_usb_item;
2431 isp1583.action_callback = isp1583_action_callback;
2432 return simplelist_show_list(&isp1583);
2434 #endif
2436 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2437 extern int pic_dbg_num_items(void);
2438 extern char* pic_dbg_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2440 static int pic_action_callback(int action, struct gui_synclist *lists)
2442 (void)lists;
2443 if (action == ACTION_NONE)
2444 action = ACTION_REDRAW;
2445 return action;
2448 static bool dbg_pic(void)
2450 struct simplelist_info pic;
2451 pic.scroll_all = true;
2452 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2453 pic.timeout = HZ/100;
2454 pic.hide_selection = true;
2455 pic.get_name = pic_dbg_item;
2456 pic.action_callback = pic_action_callback;
2457 return simplelist_show_list(&pic);
2459 #endif
2462 /****** The menu *********/
2463 struct the_menu_item {
2464 unsigned char *desc; /* string or ID */
2465 bool (*function) (void); /* return true if USB was connected */
2467 static const struct the_menu_item menuitems[] = {
2468 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2469 (defined(CPU_PP) && !defined(HAVE_ATA_SD))
2470 { "Dump ROM contents", dbg_save_roms },
2471 #endif
2472 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2473 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L
2474 { "View I/O ports", dbg_ports },
2475 #endif
2476 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2477 { "View PCF registers", dbg_pcf },
2478 #endif
2479 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2480 { "TSC2100 debug", tsc2100_debug },
2481 #endif
2482 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2483 { "CPU frequency", dbg_cpufreq },
2484 #endif
2485 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2486 { "S/PDIF analyzer", dbg_spdif },
2487 #endif
2488 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2489 { "Catch mem accesses", dbg_set_memory_guard },
2490 #endif
2491 { "View OS stacks", dbg_os },
2492 #ifdef HAVE_LCD_BITMAP
2493 #ifndef SIMULATOR
2494 { "View battery", view_battery },
2495 #endif
2496 { "Screendump", dbg_screendump },
2497 #endif
2498 #ifndef SIMULATOR
2499 { "View HW info", dbg_hw_info },
2500 #endif
2501 #ifndef SIMULATOR
2502 { "View partitions", dbg_partitions },
2503 #endif
2504 #ifndef SIMULATOR
2505 { "View disk info", dbg_disk_info },
2506 #if !defined(HAVE_MMC) && !defined(HAVE_ATA_SD)
2507 { "Dump ATA identify info", dbg_identify_info},
2508 #endif
2509 #endif
2510 #ifdef HAVE_DIRCACHE
2511 { "View dircache info", dbg_dircache_info },
2512 #endif
2513 #ifdef HAVE_TAGCACHE
2514 { "View database info", dbg_tagcache_info },
2515 #endif
2516 #ifdef HAVE_LCD_BITMAP
2517 #if CONFIG_CODEC == SWCODEC
2518 { "View buffering thread", dbg_buffering_thread },
2519 #elif !defined(SIMULATOR)
2520 { "View audio thread", dbg_audio_thread },
2521 #endif
2522 #ifdef PM_DEBUG
2523 { "pm histogram", peak_meter_histogram},
2524 #endif /* PM_DEBUG */
2525 #endif /* HAVE_LCD_BITMAP */
2526 #ifndef SIMULATOR
2527 #if CONFIG_TUNER
2528 { "FM Radio", dbg_fm_radio },
2529 #endif
2530 #endif
2531 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2532 { "Write back EEPROM", dbg_write_eeprom },
2533 #endif
2534 #if CONFIG_USBOTG == USBOTG_ISP1583
2535 { "View ISP1583 info", dbg_isp1583 },
2536 #endif
2537 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2538 { "View PIC info", dbg_pic },
2539 #endif
2540 #ifdef ROCKBOX_HAS_LOGF
2541 {"logf", logfdisplay },
2542 {"logfdump", logfdump },
2543 #endif
2544 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2545 {"logf over usb",logf_usb_serial },
2546 #endif
2547 #if defined(HAVE_USBSTACK) && defined(USB_STORAGE)
2548 {"reconnect usb storage",usb_reconnect},
2549 #endif
2550 #ifdef CPU_BOOST_LOGGING
2551 {"cpu_boost log",cpu_boost_log},
2552 #endif
2553 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2554 {"Debug scrollwheel", dbg_scrollwheel},
2555 #endif
2557 static int menu_action_callback(int btn, struct gui_synclist *lists)
2559 if (btn == ACTION_STD_OK)
2561 menuitems[gui_synclist_get_sel_pos(lists)].function();
2562 btn = ACTION_REDRAW;
2564 return btn;
2566 static char* dbg_menu_getname(int item, void * data,
2567 char *buffer, size_t buffer_len)
2569 (void)data; (void)buffer; (void)buffer_len;
2570 return menuitems[item].desc;
2572 bool debug_menu(void)
2574 struct simplelist_info info;
2576 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2577 info.action_callback = menu_action_callback;
2578 info.get_name = dbg_menu_getname;
2580 return simplelist_show_list(&info);