Add effective clockrate for realtime decoding to the displayed results of test_codec...
[kugel-rb.git] / apps / debug_menu.c
blob479ca349953dd2eaa77433cfb36501c8f1454bc3
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 <stdlib.h>
22 #include <stdio.h>
23 #include <stdbool.h>
24 #include <string.h>
25 #include "lcd.h"
26 #include "menu.h"
27 #include "debug_menu.h"
28 #include "kernel.h"
29 #include "sprintf.h"
30 #include "structec.h"
31 #include "action.h"
32 #include "debug.h"
33 #include "thread.h"
34 #include "powermgmt.h"
35 #include "system.h"
36 #include "font.h"
37 #include "audio.h"
38 #include "mp3_playback.h"
39 #include "settings.h"
40 #include "list.h"
41 #include "statusbar.h"
42 #include "dir.h"
43 #include "panic.h"
44 #include "screens.h"
45 #include "misc.h"
46 #include "splash.h"
47 #include "dircache.h"
48 #ifdef HAVE_TAGCACHE
49 #include "tagcache.h"
50 #endif
51 #include "lcd-remote.h"
52 #include "crc32.h"
53 #include "logf.h"
54 #ifndef SIMULATOR
55 #include "disk.h"
56 #include "adc.h"
57 #include "power.h"
58 #include "usb.h"
59 #include "rtc.h"
60 #include "ata.h"
61 #include "fat.h"
62 #include "mas.h"
63 #include "eeprom_24cxx.h"
64 #if defined(HAVE_MMC) || defined(HAVE_ATA_SD)
65 #include "hotswap.h"
66 #endif
67 #if CONFIG_TUNER
68 #include "tuner.h"
69 #include "radio.h"
70 #endif
71 #endif
73 #ifdef HAVE_LCD_BITMAP
74 #include "scrollbar.h"
75 #include "peakmeter.h"
76 #endif
77 #include "logfdisp.h"
78 #if CONFIG_CODEC == SWCODEC
79 #include "pcmbuf.h"
80 #include "buffering.h"
81 #include "playback.h"
82 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
83 #include "spdif.h"
84 #endif
85 #endif
86 #ifdef IRIVER_H300_SERIES
87 #include "pcf50606.h" /* for pcf50606_read */
88 #endif
89 #ifdef IAUDIO_X5
90 #include "ds2411.h"
91 #endif
92 #include "hwcompat.h"
93 #include "button.h"
94 #if CONFIG_RTC == RTC_PCF50605
95 #include "pcf50605.h"
96 #endif
98 #if CONFIG_CPU == DM320 || CONFIG_CPU == S3C2440 || CONFIG_CPU == TCC7801 \
99 || CONFIG_CPU == IMX31L
100 #include "debug-target.h"
101 #endif
103 #if defined(SANSA_E200) || defined(PHILIPS_SA9200)
104 #include "i2c-pp.h"
105 #include "as3514.h"
106 #endif
108 #if defined(HAVE_USBSTACK)
109 #include "usb_core.h"
110 #endif
111 #ifdef USB_STORAGE
112 #include "../firmware/usbstack/usb_storage.h"
113 #endif
115 /*---------------------------------------------------*/
116 /* SPECIAL DEBUG STUFF */
117 /*---------------------------------------------------*/
118 extern struct thread_entry threads[MAXTHREADS];
120 static char thread_status_char(unsigned status)
122 static const char thread_status_chars[THREAD_NUM_STATES+1] =
124 [0 ... THREAD_NUM_STATES] = '?',
125 [STATE_RUNNING] = 'R',
126 [STATE_BLOCKED] = 'B',
127 [STATE_SLEEPING] = 'S',
128 [STATE_BLOCKED_W_TMO] = 'T',
129 [STATE_FROZEN] = 'F',
130 [STATE_KILLED] = 'K',
133 if (status > THREAD_NUM_STATES)
134 status = THREAD_NUM_STATES;
136 return thread_status_chars[status];
139 static char* threads_getname(int selected_item, void *data,
140 char *buffer, size_t buffer_len)
142 (void)data;
143 struct thread_entry *thread;
144 char name[32];
146 #if NUM_CORES > 1
147 if (selected_item < (int)NUM_CORES)
149 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
150 idle_stack_usage(selected_item));
151 return buffer;
154 selected_item -= NUM_CORES;
155 #endif
157 thread = &threads[selected_item];
159 if (thread->state == STATE_KILLED)
161 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
162 return buffer;
165 thread_get_name(name, 32, thread);
167 snprintf(buffer, buffer_len,
168 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
169 selected_item,
170 IF_COP(thread->core,)
171 #ifdef HAVE_SCHEDULER_BOOSTCTRL
172 (thread->cpu_boost) ? '+' :
173 #endif
174 ((thread->state == STATE_RUNNING) ? '*' : ' '),
175 thread_status_char(thread->state),
176 IF_PRIO(thread->base_priority, thread->priority, )
177 thread_stack_usage(thread), name);
179 return buffer;
181 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
183 (void)lists;
184 #ifdef ROCKBOX_HAS_LOGF
185 if (action == ACTION_STD_OK)
187 int selpos = gui_synclist_get_sel_pos(lists);
188 #if NUM_CORES > 1
189 if (selpos >= NUM_CORES)
190 remove_thread(&threads[selpos - NUM_CORES]);
191 #else
192 remove_thread(&threads[selpos]);
193 #endif
194 return ACTION_REDRAW;
196 #endif /* ROCKBOX_HAS_LOGF */
197 if (action == ACTION_NONE)
198 action = ACTION_REDRAW;
199 return action;
201 /* Test code!!! */
202 static bool dbg_os(void)
204 struct simplelist_info info;
205 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
206 #if NUM_CORES == 1
207 MAXTHREADS,
208 #else
209 MAXTHREADS+NUM_CORES,
210 #endif
211 NULL);
212 #ifndef ROCKBOX_HAS_LOGF
213 info.hide_selection = true;
214 info.scroll_all = true;
215 #endif
216 info.action_callback = dbg_threads_action_callback;
217 info.get_name = threads_getname;
218 return simplelist_show_list(&info);
221 #ifdef HAVE_LCD_BITMAP
222 #if CONFIG_CODEC != SWCODEC
223 #ifndef SIMULATOR
224 static bool dbg_audio_thread(void)
226 char buf[32];
227 struct audio_debug d;
229 lcd_setmargins(0, 0);
230 lcd_setfont(FONT_SYSFIXED);
232 while(1)
234 if (action_userabort(HZ/5))
235 return false;
237 audio_get_debugdata(&d);
239 lcd_clear_display();
241 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
242 lcd_puts(0, 0, buf);
243 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
244 lcd_puts(0, 1, buf);
245 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
246 lcd_puts(0, 2, buf);
247 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
248 lcd_puts(0, 3, buf);
249 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
250 lcd_puts(0, 4, buf);
251 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
252 lcd_puts(0, 5, buf);
254 /* Playable space left */
255 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
256 d.playable_space, HORIZONTAL);
258 /* Show the watermark limit */
259 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
260 d.low_watermark_level, HORIZONTAL);
262 snprintf(buf, sizeof(buf), "wm: %x - %x",
263 d.low_watermark_level, d.lowest_watermark_level);
264 lcd_puts(0, 7, buf);
266 lcd_update();
268 return false;
270 #endif /* !SIMULATOR */
271 #else /* CONFIG_CODEC == SWCODEC */
272 extern size_t filebuflen;
273 /* This is a size_t, but call it a long so it puts a - when it's bad. */
275 static unsigned int ticks, boost_ticks, freq_sum;
277 static void dbg_audio_task(void)
279 #ifndef SIMULATOR
280 if(FREQ > CPUFREQ_NORMAL)
281 boost_ticks++;
282 freq_sum += FREQ/1000000; /* in MHz */
283 #endif
284 ticks++;
287 static bool dbg_buffering_thread(void)
289 char buf[32];
290 int button;
291 int line;
292 bool done = false;
293 size_t bufused;
294 size_t bufsize = pcmbuf_get_bufsize();
295 int pcmbufdescs = pcmbuf_descs();
296 struct buffering_debug d;
298 ticks = boost_ticks = freq_sum = 0;
300 tick_add_task(dbg_audio_task);
302 lcd_setmargins(0, 0);
303 lcd_setfont(FONT_SYSFIXED);
304 while(!done)
306 button = get_action(CONTEXT_STD,HZ/5);
307 switch(button)
309 case ACTION_STD_NEXT:
310 audio_next();
311 break;
312 case ACTION_STD_PREV:
313 audio_prev();
314 break;
315 case ACTION_STD_CANCEL:
316 done = true;
317 break;
320 buffering_get_debugdata(&d);
322 line = 0;
323 lcd_clear_display();
325 bufused = bufsize - pcmbuf_free();
327 snprintf(buf, sizeof(buf), "pcm: %7ld/%7ld", (long) bufused, (long) bufsize);
328 lcd_puts(0, line++, buf);
330 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
331 bufsize, 0, bufused, HORIZONTAL);
332 line++;
334 snprintf(buf, sizeof(buf), "alloc: %8ld/%8ld", audio_filebufused(),
335 (long) filebuflen);
336 lcd_puts(0, line++, buf);
338 #if LCD_HEIGHT > 80
339 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
340 filebuflen, 0, audio_filebufused(), HORIZONTAL);
341 line++;
343 snprintf(buf, sizeof(buf), "real: %8ld/%8ld", (long)d.buffered_data,
344 (long)filebuflen);
345 lcd_puts(0, line++, buf);
347 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
348 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
349 line++;
350 #endif
352 snprintf(buf, sizeof(buf), "usefl: %8ld/%8ld", (long)(d.useful_data),
353 (long)filebuflen);
354 lcd_puts(0, line++, buf);
356 #if LCD_HEIGHT > 80
357 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
358 filebuflen, 0, d.useful_data, HORIZONTAL);
359 line++;
360 #endif
362 snprintf(buf, sizeof(buf), "data_rem: %ld", (long)d.data_rem);
363 lcd_puts(0, line++, buf);
365 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
366 lcd_puts(0, line++, buf);
368 snprintf(buf, sizeof(buf), "handle count: %d", (int)d.num_handles);
369 lcd_puts(0, line++, buf);
371 #ifndef SIMULATOR
372 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
373 (int)((FREQ + 500000) / 1000000));
374 lcd_puts(0, line++, buf);
375 #endif
377 if (ticks > 0)
379 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
380 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
381 snprintf(buf, sizeof(buf), "boost ratio: %3d.%d%% (%2d.%dMHz)",
382 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
383 lcd_puts(0, line++, buf);
386 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
387 pcmbuf_used_descs(), pcmbufdescs);
388 lcd_puts(0, line++, buf);
390 lcd_update();
393 tick_remove_task(dbg_audio_task);
395 return false;
397 #endif /* CONFIG_CODEC */
398 #endif /* HAVE_LCD_BITMAP */
401 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
402 /* Tool function to read the flash manufacturer and type, if available.
403 Only chips which could be reprogrammed in system will return values.
404 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
405 /* In IRAM to avoid problems when running directly from Flash */
406 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
407 unsigned addr1, unsigned addr2)
408 ICODE_ATTR __attribute__((noinline));
409 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
410 unsigned addr1, unsigned addr2)
413 unsigned not_manu, not_id; /* read values before switching to ID mode */
414 unsigned manu, id; /* read values when in ID mode */
416 #if CONFIG_CPU == SH7034
417 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
418 #elif defined(CPU_COLDFIRE)
419 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
420 #endif
421 int old_level; /* saved interrupt level */
423 not_manu = flash[0]; /* read the normal content */
424 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
426 /* disable interrupts, prevent any stray flash access */
427 old_level = disable_irq_save();
429 flash[addr1] = 0xAA; /* enter command mode */
430 flash[addr2] = 0x55;
431 flash[addr1] = 0x90; /* ID command */
432 /* Atmel wants 20ms pause here */
433 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
435 manu = flash[0]; /* read the IDs */
436 id = flash[1];
438 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
439 /* Atmel wants 20ms pause here */
440 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
442 restore_irq(old_level); /* enable interrupts again */
444 /* I assume success if the obtained values are different from
445 the normal flash content. This is not perfectly bulletproof, they
446 could theoretically be the same by chance, causing us to fail. */
447 if (not_manu != manu || not_id != id) /* a value has changed */
449 *p_manufacturer = manu; /* return the results */
450 *p_device = id;
451 return true; /* success */
453 return false; /* fail */
455 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
457 #ifndef SIMULATOR
458 #ifdef CPU_PP
459 static int perfcheck(void)
461 int result;
463 asm (
464 "mrs r2, CPSR \n"
465 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
466 "msr CPSR_c, r0 \n"
467 "mov %[res], #0 \n"
468 "ldr r0, [%[timr]] \n"
469 "add r0, r0, %[tmo] \n"
470 "1: \n"
471 "add %[res], %[res], #1 \n"
472 "ldr r1, [%[timr]] \n"
473 "cmp r1, r0 \n"
474 "bmi 1b \n"
475 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
477 [res]"=&r"(result)
479 [timr]"r"(&USEC_TIMER),
480 [tmo]"r"(
481 #if CONFIG_CPU == PP5002
482 16000
483 #else /* PP5020/5022/5024 */
484 10226
485 #endif
488 "r0", "r1", "r2"
490 return result;
492 #endif
494 #ifdef HAVE_LCD_BITMAP
495 static bool dbg_hw_info(void)
497 #if CONFIG_CPU == SH7034
498 char buf[32];
499 int bitmask = HW_MASK;
500 int rom_version = ROM_VERSION;
501 unsigned manu, id; /* flash IDs */
502 bool got_id; /* flag if we managed to get the flash IDs */
503 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
504 bool has_bootrom; /* flag for boot ROM present */
505 int oldmode; /* saved memory guard mode */
507 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
509 /* get flash ROM type */
510 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
511 if (!got_id)
512 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
514 /* check if the boot ROM area is a flash mirror */
515 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
516 if (has_bootrom) /* if ROM and Flash different */
518 /* calculate CRC16 checksum of boot ROM */
519 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
522 system_memory_guard(oldmode); /* re-enable memory guard */
524 lcd_setmargins(0, 0);
525 lcd_setfont(FONT_SYSFIXED);
526 lcd_clear_display();
528 lcd_puts(0, 0, "[Hardware info]");
530 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
531 lcd_puts(0, 1, buf);
533 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
534 lcd_puts(0, 2, buf);
536 if (got_id)
537 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
538 else
539 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
540 lcd_puts(0, 3, buf);
542 if (has_bootrom)
544 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
545 snprintf(buf, 32, "Boot ROM: V1");
546 else
547 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
549 else
551 snprintf(buf, 32, "Boot ROM: none");
553 lcd_puts(0, 4, buf);
555 lcd_update();
557 while (!(action_userabort(TIMEOUT_BLOCK)));
559 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
560 char buf[32];
561 unsigned manu, id; /* flash IDs */
562 int got_id; /* flag if we managed to get the flash IDs */
563 int oldmode; /* saved memory guard mode */
564 int line = 0;
566 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
568 /* get flash ROM type */
569 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
570 if (!got_id)
571 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
573 system_memory_guard(oldmode); /* re-enable memory guard */
575 lcd_setmargins(0, 0);
576 lcd_setfont(FONT_SYSFIXED);
577 lcd_clear_display();
579 lcd_puts(0, line++, "[Hardware info]");
581 if (got_id)
582 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
583 else
584 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
585 lcd_puts(0, line++, buf);
587 #ifdef IAUDIO_X5
589 struct ds2411_id id;
591 lcd_puts(0, ++line, "Serial Number:");
593 got_id = ds2411_read_id(&id);
595 if (got_id == DS2411_OK)
597 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
598 lcd_puts(0, ++line, buf);
599 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
600 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
601 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
602 lcd_puts(0, ++line, buf);
603 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
605 else
607 snprintf(buf, 32, "READ ERR=%d", got_id);
610 lcd_puts(0, ++line, buf);
612 #endif
614 lcd_update();
616 while (!(action_userabort(TIMEOUT_BLOCK)));
618 #elif defined(CPU_PP502x)
619 int line = 0;
620 char buf[32];
621 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
622 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
623 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
624 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
626 lcd_setmargins(0, 0);
627 lcd_setfont(FONT_SYSFIXED);
628 lcd_clear_display();
630 lcd_puts(0, line++, "[Hardware info]");
632 #ifdef IPOD_ARCH
633 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
634 lcd_puts(0, line++, buf);
635 #endif
637 #ifdef IPOD_COLOR
638 extern int lcd_type; /* Defined in lcd-colornano.c */
640 snprintf(buf, sizeof(buf), "LCD type: %d", lcd_type);
641 lcd_puts(0, line++, buf);
642 #endif
644 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
645 lcd_puts(0, line++, buf);
647 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
648 lcd_puts(0, line++, buf);
650 lcd_update();
652 while (!(action_userabort(TIMEOUT_BLOCK)));
654 #elif CONFIG_CPU == PP5002
655 int line = 0;
656 char buf[32];
657 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
658 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
659 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
660 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
663 lcd_setmargins(0, 0);
664 lcd_setfont(FONT_SYSFIXED);
665 lcd_clear_display();
667 lcd_puts(0, line++, "[Hardware info]");
669 #ifdef IPOD_ARCH
670 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
671 lcd_puts(0, line++, buf);
672 #endif
674 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
675 lcd_puts(0, line++, buf);
677 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
678 lcd_puts(0, line++, buf);
680 lcd_update();
682 while (!(action_userabort(TIMEOUT_BLOCK)));
683 #else
684 /* Define this function in your target tree */
685 return __dbg_hw_info();
686 #endif /* CONFIG_CPU */
687 return false;
689 #else /* !HAVE_LCD_BITMAP */
690 static bool dbg_hw_info(void)
692 char buf[32];
693 int button;
694 int currval = 0;
695 int rom_version = ROM_VERSION;
696 unsigned manu, id; /* flash IDs */
697 bool got_id; /* flag if we managed to get the flash IDs */
698 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
699 bool has_bootrom; /* flag for boot ROM present */
700 int oldmode; /* saved memory guard mode */
702 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
704 /* get flash ROM type */
705 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
706 if (!got_id)
707 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
709 /* check if the boot ROM area is a flash mirror */
710 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
711 if (has_bootrom) /* if ROM and Flash different */
713 /* calculate CRC16 checksum of boot ROM */
714 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
717 system_memory_guard(oldmode); /* re-enable memory guard */
719 lcd_clear_display();
721 lcd_puts(0, 0, "[HW Info]");
722 while(1)
724 switch(currval)
726 case 0:
727 snprintf(buf, 32, "ROM: %d.%02d",
728 rom_version/100, rom_version%100);
729 break;
730 case 1:
731 if (got_id)
732 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
733 else
734 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
735 break;
736 case 2:
737 if (has_bootrom)
739 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
740 snprintf(buf, 32, "BootROM: V1");
741 else if (rom_crc == 0x358099E8)
742 snprintf(buf, 32, "BootROM: V2");
743 /* alternative boot ROM found in one single player so far */
744 else
745 snprintf(buf, 32, "R: %08x", rom_crc);
747 else
748 snprintf(buf, 32, "BootROM: no");
751 lcd_puts(0, 1, buf);
752 lcd_update();
754 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
756 switch(button)
758 case ACTION_STD_CANCEL:
759 return false;
761 case ACTION_SETTINGS_DEC:
762 currval--;
763 if(currval < 0)
764 currval = 2;
765 break;
767 case ACTION_SETTINGS_INC:
768 currval++;
769 if(currval > 2)
770 currval = 0;
771 break;
774 return false;
776 #endif /* !HAVE_LCD_BITMAP */
777 #endif /* !SIMULATOR */
779 #ifndef SIMULATOR
780 static char* dbg_partitions_getname(int selected_item, void *data,
781 char *buffer, size_t buffer_len)
783 (void)data;
784 int partition = selected_item/2;
785 struct partinfo* p = disk_partinfo(partition);
786 if (selected_item%2)
788 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / 2048);
790 else
792 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
794 return buffer;
797 bool dbg_partitions(void)
799 struct simplelist_info info;
800 simplelist_info_init(&info, "Partition Info", 4, NULL);
801 info.selection_size = 2;
802 info.hide_selection = true;
803 info.scroll_all = true;
804 info.get_name = dbg_partitions_getname;
805 return simplelist_show_list(&info);
807 #endif
809 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
810 static bool dbg_spdif(void)
812 char buf[128];
813 int line;
814 unsigned int control;
815 int x;
816 char *s;
817 int category;
818 int generation;
819 unsigned int interruptstat;
820 bool valnogood, symbolerr, parityerr;
821 bool done = false;
822 bool spdif_src_on;
823 int spdif_source = spdif_get_output_source(&spdif_src_on);
824 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
826 lcd_setmargins(0, 0);
827 lcd_clear_display();
828 lcd_setfont(FONT_SYSFIXED);
830 #ifdef HAVE_SPDIF_POWER
831 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
832 #endif
834 while (!done)
836 line = 0;
838 control = EBU1RCVCCHANNEL1;
839 interruptstat = INTERRUPTSTAT;
840 INTERRUPTCLEAR = 0x03c00000;
842 valnogood = (interruptstat & 0x01000000)?true:false;
843 symbolerr = (interruptstat & 0x00800000)?true:false;
844 parityerr = (interruptstat & 0x00400000)?true:false;
846 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
847 valnogood?"--":"OK",
848 symbolerr?"--":"OK",
849 parityerr?"--":"OK");
850 lcd_puts(0, line++, buf);
852 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
853 lcd_puts(0, line++, buf);
855 line++;
857 x = control >> 31;
858 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
859 x, x?"Professional":"Consumer");
860 lcd_puts(0, line++, buf);
862 x = (control >> 30) & 1;
863 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
864 x, x?"Non-PCM":"PCM");
865 lcd_puts(0, line++, buf);
867 x = (control >> 29) & 1;
868 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
869 x, x?"Permitted":"Inhibited");
870 lcd_puts(0, line++, buf);
872 x = (control >> 27) & 7;
873 switch(x)
875 case 0:
876 s = "None";
877 break;
878 case 1:
879 s = "50/15us";
880 break;
881 default:
882 s = "Reserved";
883 break;
885 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
886 lcd_puts(0, line++, buf);
888 x = (control >> 24) & 3;
889 snprintf(buf, sizeof(buf), "Mode: %d", x);
890 lcd_puts(0, line++, buf);
892 category = (control >> 17) & 127;
893 switch(category)
895 case 0x00:
896 s = "General";
897 break;
898 case 0x40:
899 s = "Audio CD";
900 break;
901 default:
902 s = "Unknown";
904 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
905 lcd_puts(0, line++, buf);
907 x = (control >> 16) & 1;
908 generation = x;
909 if(((category & 0x70) == 0x10) ||
910 ((category & 0x70) == 0x40) ||
911 ((category & 0x78) == 0x38))
913 generation = !generation;
915 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
916 x, generation?"Original":"No ind.");
917 lcd_puts(0, line++, buf);
919 x = (control >> 12) & 15;
920 snprintf(buf, sizeof(buf), "Source: %d", x);
921 lcd_puts(0, line++, buf);
923 x = (control >> 8) & 15;
924 switch(x)
926 case 0:
927 s = "Unspecified";
928 break;
929 case 8:
930 s = "A (Left)";
931 break;
932 case 4:
933 s = "B (Right)";
934 break;
935 default:
936 s = "";
937 break;
939 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
940 lcd_puts(0, line++, buf);
942 x = (control >> 4) & 15;
943 switch(x)
945 case 0:
946 s = "44.1kHz";
947 break;
948 case 0x4:
949 s = "48kHz";
950 break;
951 case 0xc:
952 s = "32kHz";
953 break;
955 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
956 lcd_puts(0, line++, buf);
958 x = (control >> 2) & 3;
959 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
960 lcd_puts(0, line++, buf);
961 line++;
963 #ifndef SIMULATOR
964 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
965 spdif_measure_frequency());
966 lcd_puts(0, line++, buf);
967 #endif
969 lcd_update();
971 if (action_userabort(HZ/10))
972 break;
975 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
977 #ifdef HAVE_SPDIF_POWER
978 spdif_power_enable(global_settings.spdif_enable);
979 #endif
981 return false;
983 #endif /* CPU_COLDFIRE */
985 #ifndef SIMULATOR
986 #ifdef HAVE_LCD_BITMAP
987 /* button definitions */
988 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
989 (CONFIG_KEYPAD == IRIVER_H300_PAD)
990 # define DEBUG_CANCEL BUTTON_OFF
992 #elif CONFIG_KEYPAD == RECORDER_PAD
993 # define DEBUG_CANCEL BUTTON_OFF
995 #elif CONFIG_KEYPAD == ONDIO_PAD
996 # define DEBUG_CANCEL BUTTON_MENU
998 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
999 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
1000 (CONFIG_KEYPAD == IPOD_4G_PAD)
1001 # define DEBUG_CANCEL BUTTON_MENU
1003 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
1004 # define DEBUG_CANCEL BUTTON_PLAY
1006 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
1007 # define DEBUG_CANCEL BUTTON_REC
1009 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1010 # define DEBUG_CANCEL BUTTON_RC_REC
1012 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
1013 # define DEBUG_CANCEL BUTTON_REW
1015 #elif (CONFIG_KEYPAD == MROBE100_PAD)
1016 # define DEBUG_CANCEL BUTTON_MENU
1018 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
1019 (CONFIG_KEYPAD == SANSA_C200_PAD)
1020 # define DEBUG_CANCEL BUTTON_LEFT
1022 /* This is temporary until the SA9200 touchpad works */
1023 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD)
1024 # define DEBUG_CANCEL BUTTON_POWER
1026 #endif /* key definitions */
1028 /* Test code!!! */
1029 bool dbg_ports(void)
1031 #if CONFIG_CPU == SH7034
1032 char buf[32];
1033 int adc_battery_voltage, adc_battery_level;
1035 lcd_setfont(FONT_SYSFIXED);
1036 lcd_setmargins(0, 0);
1037 lcd_clear_display();
1039 while(1)
1041 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1042 lcd_puts(0, 0, buf);
1043 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1044 lcd_puts(0, 1, buf);
1046 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1047 lcd_puts(0, 2, buf);
1048 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1049 lcd_puts(0, 3, buf);
1050 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1051 lcd_puts(0, 4, buf);
1052 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1053 lcd_puts(0, 5, buf);
1055 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1056 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1057 adc_battery_voltage % 1000, adc_battery_level);
1058 lcd_puts(0, 6, buf);
1060 lcd_update();
1061 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1062 return false;
1064 #elif defined(CPU_COLDFIRE)
1065 unsigned int gpio_out;
1066 unsigned int gpio1_out;
1067 unsigned int gpio_read;
1068 unsigned int gpio1_read;
1069 unsigned int gpio_function;
1070 unsigned int gpio1_function;
1071 unsigned int gpio_enable;
1072 unsigned int gpio1_enable;
1073 int adc_buttons, adc_remote;
1074 int adc_battery_voltage, adc_battery_level;
1075 char buf[128];
1076 int line;
1078 lcd_setmargins(0, 0);
1079 lcd_clear_display();
1080 lcd_setfont(FONT_SYSFIXED);
1082 while(1)
1084 line = 0;
1085 gpio_read = GPIO_READ;
1086 gpio1_read = GPIO1_READ;
1087 gpio_out = GPIO_OUT;
1088 gpio1_out = GPIO1_OUT;
1089 gpio_function = GPIO_FUNCTION;
1090 gpio1_function = GPIO1_FUNCTION;
1091 gpio_enable = GPIO_ENABLE;
1092 gpio1_enable = GPIO1_ENABLE;
1094 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1095 lcd_puts(0, line++, buf);
1096 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1097 lcd_puts(0, line++, buf);
1098 snprintf(buf, sizeof(buf), "GPIO_FUNC: %08x", gpio_function);
1099 lcd_puts(0, line++, buf);
1100 snprintf(buf, sizeof(buf), "GPIO_ENA: %08x", gpio_enable);
1101 lcd_puts(0, line++, buf);
1103 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1104 lcd_puts(0, line++, buf);
1105 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1106 lcd_puts(0, line++, buf);
1107 snprintf(buf, sizeof(buf), "GPIO1_FUNC: %08x", gpio1_function);
1108 lcd_puts(0, line++, buf);
1109 snprintf(buf, sizeof(buf), "GPIO1_ENA: %08x", gpio1_enable);
1110 lcd_puts(0, line++, buf);
1112 adc_buttons = adc_read(ADC_BUTTONS);
1113 adc_remote = adc_read(ADC_REMOTE);
1114 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1115 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1116 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1117 button_scan_enabled() ? '+' : '-', adc_buttons);
1118 #else
1119 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1120 #endif
1121 lcd_puts(0, line++, buf);
1122 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1123 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1124 remote_detect() ? '+' : '-', adc_remote);
1125 #else
1126 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1127 #endif
1128 lcd_puts(0, line++, buf);
1129 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1130 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1131 adc_read(ADC_REMOTEDETECT));
1132 lcd_puts(0, line++, buf);
1133 #endif
1135 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1136 adc_battery_voltage % 1000, adc_battery_level);
1137 lcd_puts(0, line++, buf);
1139 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1140 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1141 lcd_puts(0, line++, buf);
1142 #endif
1144 lcd_update();
1145 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1146 return false;
1149 #elif defined(CPU_PP502x)
1151 char buf[128];
1152 int line;
1154 lcd_setmargins(0, 0);
1155 lcd_clear_display();
1156 lcd_setfont(FONT_SYSFIXED);
1158 while(1)
1160 line = 0;
1161 lcd_puts(0, line++, "GPIO STATES:");
1162 snprintf(buf, sizeof(buf), "A: %02x E: %02x I: %02x",
1163 (unsigned int)GPIOA_INPUT_VAL,
1164 (unsigned int)GPIOE_INPUT_VAL,
1165 (unsigned int)GPIOI_INPUT_VAL);
1166 lcd_puts(0, line++, buf);
1167 snprintf(buf, sizeof(buf), "B: %02x F: %02x J: %02x",
1168 (unsigned int)GPIOB_INPUT_VAL,
1169 (unsigned int)GPIOF_INPUT_VAL,
1170 (unsigned int)GPIOJ_INPUT_VAL);
1171 lcd_puts(0, line++, buf);
1172 snprintf(buf, sizeof(buf), "C: %02x G: %02x K: %02x",
1173 (unsigned int)GPIOC_INPUT_VAL,
1174 (unsigned int)GPIOG_INPUT_VAL,
1175 (unsigned int)GPIOK_INPUT_VAL);
1176 lcd_puts(0, line++, buf);
1177 snprintf(buf, sizeof(buf), "D: %02x H: %02x L: %02x",
1178 (unsigned int)GPIOD_INPUT_VAL,
1179 (unsigned int)GPIOH_INPUT_VAL,
1180 (unsigned int)GPIOL_INPUT_VAL);
1181 lcd_puts(0, line++, buf);
1182 line++;
1183 snprintf(buf, sizeof(buf), "GPO32_VAL: %08lx", GPO32_VAL);
1184 lcd_puts(0, line++, buf);
1185 snprintf(buf, sizeof(buf), "GPO32_EN: %08lx", GPO32_ENABLE);
1186 lcd_puts(0, line++, buf);
1187 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1188 lcd_puts(0, line++, buf);
1189 snprintf(buf, sizeof(buf), "DEV_EN2: %08lx", DEV_EN2);
1190 lcd_puts(0, line++, buf);
1191 snprintf(buf, sizeof(buf), "DEV_EN3: %08lx", inl(0x60006044));
1192 lcd_puts(0, line++, buf); /* to be verified */
1193 snprintf(buf, sizeof(buf), "DEV_INIT1: %08lx", DEV_INIT1);
1194 lcd_puts(0, line++, buf);
1195 snprintf(buf, sizeof(buf), "DEV_INIT2: %08lx", DEV_INIT2);
1196 lcd_puts(0, line++, buf);
1197 #ifdef ADC_ACCESSORY
1198 snprintf(buf, sizeof(buf), "ACCESSORY: %d", adc_read(ADC_ACCESSORY));
1199 lcd_puts(0, line++, buf);
1200 #endif
1202 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1203 line++;
1204 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1205 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1206 lcd_puts(0, line++, buf);
1207 snprintf(buf, sizeof(buf), "REM: %03x PAD: %03x",
1208 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1209 lcd_puts(0, line++, buf);
1210 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1211 snprintf(buf, sizeof(buf), "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1212 lcd_puts(0, line++, buf);
1213 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1214 lcd_puts(0, line++, buf);
1215 snprintf(buf, sizeof(buf), "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1216 lcd_puts(0, line++, buf);
1217 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1218 lcd_puts(0, line++, buf);
1219 snprintf(buf, sizeof(buf), "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1220 lcd_puts(0, line++, buf);
1221 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1222 lcd_puts(0, line++, buf);
1223 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1224 lcd_puts(0, line++, buf);
1225 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1226 lcd_puts(0, line++, buf);
1227 snprintf(buf, sizeof(buf), "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1228 lcd_puts(0, line++, buf);
1229 snprintf(buf, sizeof(buf), "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1230 lcd_puts(0, line++, buf);
1231 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1232 lcd_puts(0, line++, buf);
1233 #if !defined(PHILIPS_SA9200)
1234 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1235 lcd_puts(0, line++, buf);
1236 snprintf(buf, sizeof(buf), "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1237 lcd_puts(0, line++, buf);
1238 snprintf(buf, sizeof(buf), "CHARGER: %02X/%02X", i2c_readbyte(AS3514_I2C_ADDR, AS3514_CHARGER), i2c_readbyte(AS3514_I2C_ADDR, AS3514_IRQ_ENRD0));
1239 lcd_puts(0, line++, buf);
1240 #endif
1241 #endif
1242 lcd_update();
1243 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1244 return false;
1247 #elif CONFIG_CPU == PP5002
1248 char buf[128];
1249 int line;
1251 lcd_setmargins(0, 0);
1252 lcd_clear_display();
1253 lcd_setfont(FONT_SYSFIXED);
1255 while(1)
1257 line = 0;
1258 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x",
1259 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1260 lcd_puts(0, line++, buf);
1261 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x",
1262 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1263 lcd_puts(0, line++, buf);
1265 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1266 lcd_puts(0, line++, buf);
1267 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1268 lcd_puts(0, line++, buf);
1269 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1270 lcd_puts(0, line++, buf);
1271 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1272 lcd_puts(0, line++, buf);
1273 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1274 lcd_puts(0, line++, buf);
1275 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1276 lcd_puts(0, line++, buf);
1277 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1278 lcd_puts(0, line++, buf);
1279 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1280 lcd_puts(0, line++, buf);
1282 lcd_update();
1283 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1284 return false;
1286 #else
1287 return __dbg_ports();
1288 #endif /* CPU */
1289 return false;
1291 #else /* !HAVE_LCD_BITMAP */
1292 bool dbg_ports(void)
1294 char buf[32];
1295 int button;
1296 int adc_battery_voltage;
1297 int currval = 0;
1299 lcd_clear_display();
1301 while(1)
1303 switch(currval)
1305 case 0:
1306 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1307 break;
1308 case 1:
1309 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1310 break;
1311 case 2:
1312 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1313 break;
1314 case 3:
1315 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1316 break;
1317 case 4:
1318 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1319 break;
1320 case 5:
1321 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1322 break;
1323 case 6:
1324 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1325 break;
1326 case 7:
1327 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1328 break;
1329 case 8:
1330 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1331 break;
1332 case 9:
1333 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1334 break;
1335 break;
1337 lcd_puts(0, 0, buf);
1339 battery_read_info(&adc_battery_voltage, NULL);
1340 snprintf(buf, 32, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1341 adc_battery_voltage % 1000);
1342 lcd_puts(0, 1, buf);
1343 lcd_update();
1345 button = get_action(CONTEXT_SETTINGS,HZ/5);
1347 switch(button)
1349 case ACTION_STD_CANCEL:
1350 return false;
1352 case ACTION_SETTINGS_DEC:
1353 currval--;
1354 if(currval < 0)
1355 currval = 9;
1356 break;
1358 case ACTION_SETTINGS_INC:
1359 currval++;
1360 if(currval > 9)
1361 currval = 0;
1362 break;
1365 return false;
1367 #endif /* !HAVE_LCD_BITMAP */
1368 #endif /* !SIMULATOR */
1370 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1371 static bool dbg_pcf(void)
1373 char buf[128];
1374 int line;
1376 #ifdef HAVE_LCD_BITMAP
1377 lcd_setmargins(0, 0);
1378 lcd_setfont(FONT_SYSFIXED);
1379 #endif
1380 lcd_clear_display();
1382 while(1)
1384 line = 0;
1386 snprintf(buf, sizeof(buf), "DCDC1: %02x", pcf50605_read(0x1b));
1387 lcd_puts(0, line++, buf);
1388 snprintf(buf, sizeof(buf), "DCDC2: %02x", pcf50605_read(0x1c));
1389 lcd_puts(0, line++, buf);
1390 snprintf(buf, sizeof(buf), "DCDC3: %02x", pcf50605_read(0x1d));
1391 lcd_puts(0, line++, buf);
1392 snprintf(buf, sizeof(buf), "DCDC4: %02x", pcf50605_read(0x1e));
1393 lcd_puts(0, line++, buf);
1394 snprintf(buf, sizeof(buf), "DCDEC1: %02x", pcf50605_read(0x1f));
1395 lcd_puts(0, line++, buf);
1396 snprintf(buf, sizeof(buf), "DCDEC2: %02x", pcf50605_read(0x20));
1397 lcd_puts(0, line++, buf);
1398 snprintf(buf, sizeof(buf), "DCUDC1: %02x", pcf50605_read(0x21));
1399 lcd_puts(0, line++, buf);
1400 snprintf(buf, sizeof(buf), "DCUDC2: %02x", pcf50605_read(0x22));
1401 lcd_puts(0, line++, buf);
1402 snprintf(buf, sizeof(buf), "IOREGC: %02x", pcf50605_read(0x23));
1403 lcd_puts(0, line++, buf);
1404 snprintf(buf, sizeof(buf), "D1REGC: %02x", pcf50605_read(0x24));
1405 lcd_puts(0, line++, buf);
1406 snprintf(buf, sizeof(buf), "D2REGC: %02x", pcf50605_read(0x25));
1407 lcd_puts(0, line++, buf);
1408 snprintf(buf, sizeof(buf), "D3REGC: %02x", pcf50605_read(0x26));
1409 lcd_puts(0, line++, buf);
1410 snprintf(buf, sizeof(buf), "LPREG1: %02x", pcf50605_read(0x27));
1411 lcd_puts(0, line++, buf);
1413 lcd_update();
1414 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1416 return false;
1420 return false;
1422 #endif
1424 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1425 static bool dbg_cpufreq(void)
1427 char buf[128];
1428 int line;
1429 int button;
1431 #ifdef HAVE_LCD_BITMAP
1432 lcd_setmargins(0, 0);
1433 lcd_setfont(FONT_SYSFIXED);
1434 #endif
1435 lcd_clear_display();
1437 while(1)
1439 line = 0;
1441 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1442 lcd_puts(0, line++, buf);
1444 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1445 lcd_puts(0, line++, buf);
1447 lcd_update();
1448 button = get_action(CONTEXT_STD,HZ/10);
1450 switch(button)
1452 case ACTION_STD_PREV:
1453 cpu_boost(true);
1454 break;
1456 case ACTION_STD_NEXT:
1457 cpu_boost(false);
1458 break;
1460 case ACTION_STD_OK:
1461 while (get_cpu_boost_counter() > 0)
1462 cpu_boost(false);
1463 set_cpu_frequency(CPUFREQ_DEFAULT);
1464 break;
1466 case ACTION_STD_CANCEL:
1467 return false;
1471 return false;
1473 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1475 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1476 #include "tsc2100.h"
1477 char *itob(int n, int len)
1479 static char binary[64];
1480 int i,j;
1481 for (i=1, j=0;i<=len;i++)
1483 binary[j++] = n&(1<<(len-i))?'1':'0';
1484 if (i%4 == 0)
1485 binary[j++] = ' ';
1487 binary[j] = '\0';
1488 return binary;
1490 static char* tsc2100_debug_getname(int selected_item, void * data,
1491 char *buffer, size_t buffer_len)
1493 int *page = (int*)data;
1494 bool reserved = false;
1495 switch (*page)
1497 case 0:
1498 if ((selected_item > 0x0a) ||
1499 (selected_item == 0x04) ||
1500 (selected_item == 0x08))
1501 reserved = true;
1502 break;
1503 case 1:
1504 if ((selected_item > 0x05) ||
1505 (selected_item == 0x02))
1506 reserved = true;
1507 break;
1508 case 2:
1509 if (selected_item > 0x1e)
1510 reserved = true;
1511 break;
1513 if (reserved)
1514 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1515 else
1516 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1517 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1518 return buffer;
1520 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1522 int *page = (int*)lists->data;
1523 if (action == ACTION_STD_OK)
1525 *page = (*page+1)%3;
1526 snprintf(lists->title, 32,
1527 "tsc2100 registers - Page %d", *page);
1528 return ACTION_REDRAW;
1530 return action;
1532 bool tsc2100_debug(void)
1534 int page = 0;
1535 char title[32] = "tsc2100 registers - Page 0";
1536 struct simplelist_info info;
1537 simplelist_info_init(&info, title, 32, &page);
1538 info.timeout = HZ/100;
1539 info.get_name = tsc2100_debug_getname;
1540 info.action_callback= tsc2100debug_action_callback;
1541 return simplelist_show_list(&info);
1543 #endif
1544 #ifndef SIMULATOR
1545 #ifdef HAVE_LCD_BITMAP
1547 * view_battery() shows a automatically scaled graph of the battery voltage
1548 * over time. Usable for estimating battery life / charging rate.
1549 * The power_history array is updated in power_thread of powermgmt.c.
1552 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1553 #define BAT_YSPACE (LCD_HEIGHT - 20)
1555 static bool view_battery(void)
1557 int view = 0;
1558 int i, x, y;
1559 unsigned short maxv, minv;
1560 char buf[32];
1562 lcd_setmargins(0, 0);
1563 lcd_setfont(FONT_SYSFIXED);
1565 while(1)
1567 lcd_clear_display();
1568 switch (view) {
1569 case 0: /* voltage history graph */
1570 /* Find maximum and minimum voltage for scaling */
1571 minv = power_history[0];
1572 maxv = minv + 1;
1573 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1574 if (power_history[i] > maxv)
1575 maxv = power_history[i];
1576 if (power_history[i] < minv)
1577 minv = power_history[i];
1580 snprintf(buf, 30, "Battery %d.%03d", power_history[0] / 1000,
1581 power_history[0] % 1000);
1582 lcd_puts(0, 0, buf);
1583 snprintf(buf, 30, "scale %d.%03d-%d.%03dV",
1584 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1585 lcd_puts(0, 1, buf);
1587 x = 0;
1588 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1589 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1590 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1591 lcd_vline(x, LCD_HEIGHT-1, 20);
1592 lcd_set_drawmode(DRMODE_SOLID);
1593 lcd_vline(x, LCD_HEIGHT-1,
1594 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1595 x++;
1598 break;
1600 case 1: /* status: */
1601 lcd_puts(0, 0, "Power status:");
1603 battery_read_info(&y, NULL);
1604 snprintf(buf, 30, "Battery: %d.%03d V", y / 1000, y % 1000);
1605 lcd_puts(0, 1, buf);
1606 #ifdef ADC_EXT_POWER
1607 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1608 snprintf(buf, 30, "External: %d.%03d V", y / 1000, y % 1000);
1609 lcd_puts(0, 2, buf);
1610 #endif
1611 #if CONFIG_CHARGING
1612 #if CONFIG_CHARGING == CHARGING_CONTROL
1613 snprintf(buf, 30, "Chgr: %s %s",
1614 charger_inserted() ? "present" : "absent",
1615 charger_enabled ? "on" : "off");
1616 lcd_puts(0, 3, buf);
1617 snprintf(buf, 30, "short delta: %d", short_delta);
1618 lcd_puts(0, 5, buf);
1619 snprintf(buf, 30, "long delta: %d", long_delta);
1620 lcd_puts(0, 6, buf);
1621 lcd_puts(0, 7, power_message);
1622 snprintf(buf, 30, "USB Inserted: %s",
1623 usb_inserted() ? "yes" : "no");
1624 lcd_puts(0, 8, buf);
1625 #if defined IRIVER_H300_SERIES
1626 snprintf(buf, 30, "USB Charging Enabled: %s",
1627 usb_charging_enabled() ? "yes" : "no");
1628 lcd_puts(0, 9, buf);
1629 #endif
1630 #else /* CONFIG_CHARGING != CHARGING_CONTROL */
1631 #if defined IPOD_NANO || defined IPOD_VIDEO
1632 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1633 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1634 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1635 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1636 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1638 snprintf(buf, 30, "USB pwr: %s",
1639 usb_pwr ? "present" : "absent");
1640 lcd_puts(0, 3, buf);
1641 snprintf(buf, 30, "EXT pwr: %s",
1642 ext_pwr ? "present" : "absent");
1643 lcd_puts(0, 4, buf);
1644 snprintf(buf, 30, "Battery: %s",
1645 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1646 lcd_puts(0, 5, buf);
1647 snprintf(buf, 30, "Dock mode: %s",
1648 dock ? "enabled" : "disabled");
1649 lcd_puts(0, 6, buf);
1650 snprintf(buf, 30, "Headphone: %s",
1651 headphone ? "connected" : "disconnected");
1652 lcd_puts(0, 7, buf);
1653 #else
1654 snprintf(buf, 30, "Charger: %s",
1655 charger_inserted() ? "present" : "absent");
1656 lcd_puts(0, 3, buf);
1657 #if defined TOSHIBA_GIGABEAT_S
1658 y = battery_adc_charge_current();
1659 x = y < 0 ? '-' : ' ';
1660 y = abs(y);
1661 snprintf(buf, 30, "I Charge:%c%d.%03d A", (char)x, y / 1000, y % 1000);
1662 lcd_puts(0, 4, buf);
1664 y = battery_adc_temp();
1665 snprintf(buf, 30, "T Battery: %dC (%dF)", y, (9*y + 160) / 5);
1666 lcd_puts(0, 5, buf);
1667 #endif /* defined TOSHIBA_GIGABEAT_S */
1668 #endif /* defined IPOD_NANO || defined IPOD_VIDEO */
1669 #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1670 #endif /* CONFIG_CHARGING */
1671 break;
1673 case 2: /* voltage deltas: */
1674 lcd_puts(0, 0, "Voltage deltas:");
1676 for (i = 0; i <= 6; i++) {
1677 y = power_history[i] - power_history[i+1];
1678 snprintf(buf, 30, "-%d min: %s%d.%03d V", i,
1679 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1680 ((y < 0) ? y * -1 : y ) % 1000);
1681 lcd_puts(0, i+1, buf);
1683 break;
1685 case 3: /* remaining time estimation: */
1687 #if CONFIG_CHARGING == CHARGING_CONTROL
1688 snprintf(buf, 30, "charge_state: %d", charge_state);
1689 lcd_puts(0, 0, buf);
1691 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1692 lcd_puts(0, 1, buf);
1694 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1695 lcd_puts(0, 2, buf);
1697 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1698 lcd_puts(0, 3, buf);
1700 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1701 lcd_puts(0, 4, buf);
1702 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
1704 snprintf(buf, 30, "Last PwrHist: %d.%03dV",
1705 power_history[0] / 1000,
1706 power_history[0] % 1000);
1707 lcd_puts(0, 5, buf);
1709 snprintf(buf, 30, "battery level: %d%%", battery_level());
1710 lcd_puts(0, 6, buf);
1712 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1713 lcd_puts(0, 7, buf);
1714 break;
1717 lcd_update();
1719 switch(get_action(CONTEXT_STD,HZ/2))
1721 case ACTION_STD_PREV:
1722 if (view)
1723 view--;
1724 break;
1726 case ACTION_STD_NEXT:
1727 if (view < 3)
1728 view++;
1729 break;
1731 case ACTION_STD_CANCEL:
1732 return false;
1735 return false;
1738 #endif /* HAVE_LCD_BITMAP */
1739 #endif
1741 #ifndef SIMULATOR
1742 #if defined(HAVE_MMC) || defined(HAVE_ATA_SD)
1743 #if defined(HAVE_MMC)
1744 #define CARDTYPE "MMC"
1745 #else
1746 #define CARDTYPE "microSD"
1747 #endif
1748 static int disk_callback(int btn, struct gui_synclist *lists)
1750 tCardInfo *card;
1751 int *cardnum = (int*)lists->data;
1752 unsigned char card_name[7];
1753 unsigned char pbuf[32];
1754 char *title = lists->title;
1755 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1756 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1757 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1758 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1759 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1760 "3.1-3.31", "4.0" };
1761 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1763 #ifdef HAVE_HOTSWAP
1764 if (btn == ACTION_STD_OK)
1766 *cardnum ^= 0x1; /* change cards */
1768 #endif
1770 simplelist_set_line_count(0);
1772 card = card_get_info(*cardnum);
1774 if (card->initialized > 0)
1776 card_name[6] = '\0';
1777 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1778 simplelist_addline(SIMPLELIST_ADD_LINE,
1779 "%s Rev %d.%d", card_name,
1780 (int) card_extract_bits(card->cid, 72, 4),
1781 (int) card_extract_bits(card->cid, 76, 4));
1782 simplelist_addline(SIMPLELIST_ADD_LINE,
1783 "Prod: %d/%d",
1784 (int) card_extract_bits(card->cid, 112, 4),
1785 (int) card_extract_bits(card->cid, 116, 4) + 1997);
1786 simplelist_addline(SIMPLELIST_ADD_LINE,
1787 "Ser#: 0x%08lx",
1788 card_extract_bits(card->cid, 80, 32));
1789 simplelist_addline(SIMPLELIST_ADD_LINE,
1790 "M=%02x, O=%04x",
1791 (int) card_extract_bits(card->cid, 0, 8),
1792 (int) card_extract_bits(card->cid, 8, 16));
1793 int temp = card_extract_bits(card->csd, 2, 4);
1794 simplelist_addline(SIMPLELIST_ADD_LINE,
1795 CARDTYPE " v%s", temp < 5 ?
1796 spec_vers[temp] : "?.?");
1797 simplelist_addline(SIMPLELIST_ADD_LINE,
1798 "Blocks: 0x%06lx", card->numblocks);
1799 simplelist_addline(SIMPLELIST_ADD_LINE,
1800 "Blksz.: %d P:%c%c", card->blocksize,
1801 card_extract_bits(card->csd, 48, 1) ? 'R' : '-',
1802 card_extract_bits(card->csd, 106, 1) ? 'W' : '-');
1803 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1804 kbit_units, false);
1805 simplelist_addline(SIMPLELIST_ADD_LINE,
1806 "Speed: %s", pbuf);
1807 output_dyn_value(pbuf, sizeof pbuf, card->tsac,
1808 nsec_units, false);
1809 simplelist_addline(SIMPLELIST_ADD_LINE,
1810 "Tsac: %s", pbuf);
1811 simplelist_addline(SIMPLELIST_ADD_LINE,
1812 "Nsac: %d clk", card->nsac);
1813 simplelist_addline(SIMPLELIST_ADD_LINE,
1814 "R2W: *%d", card->r2w_factor);
1815 simplelist_addline(SIMPLELIST_ADD_LINE,
1816 "IRmax: %d..%d mA",
1817 i_vmin[card_extract_bits(card->csd, 66, 3)],
1818 i_vmax[card_extract_bits(card->csd, 69, 3)]);
1819 simplelist_addline(SIMPLELIST_ADD_LINE,
1820 "IWmax: %d..%d mA",
1821 i_vmin[card_extract_bits(card->csd, 72, 3)],
1822 i_vmax[card_extract_bits(card->csd, 75, 3)]);
1824 else if (card->initialized == 0)
1826 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1828 #ifndef HAVE_MMC
1829 else /* card->initialized < 0 */
1831 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1833 #endif
1834 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1835 gui_synclist_set_title(lists, title, Icon_NOICON);
1836 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1837 gui_synclist_select_item(lists, 0);
1838 btn = ACTION_REDRAW;
1840 return btn;
1842 #else /* !defined(HAVE_MMC) && !defined(HAVE_ATA_SD) */
1843 static int disk_callback(int btn, struct gui_synclist *lists)
1845 (void)lists;
1846 int i;
1847 char buf[128];
1848 unsigned short* identify_info = ata_get_identify();
1849 bool timing_info_present = false;
1850 (void)btn;
1852 simplelist_set_line_count(0);
1854 for (i=0; i < 20; i++)
1855 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1856 buf[40]=0;
1857 /* kill trailing space */
1858 for (i=39; i && buf[i]==' '; i--)
1859 buf[i] = 0;
1860 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1861 for (i=0; i < 4; i++)
1862 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1863 buf[8]=0;
1864 simplelist_addline(SIMPLELIST_ADD_LINE,
1865 "Firmware: %s", buf);
1866 snprintf(buf, sizeof buf, "%ld MB",
1867 ((unsigned long)identify_info[61] << 16 |
1868 (unsigned long)identify_info[60]) / 2048 );
1869 simplelist_addline(SIMPLELIST_ADD_LINE,
1870 "Size: %s", buf);
1871 unsigned long free;
1872 fat_size( IF_MV2(0,) NULL, &free );
1873 simplelist_addline(SIMPLELIST_ADD_LINE,
1874 "Free: %ld MB", free / 1024);
1875 simplelist_addline(SIMPLELIST_ADD_LINE,
1876 "Spinup time: %d ms", ata_spinup_time * (1000/HZ));
1877 i = identify_info[83] & (1<<3);
1878 simplelist_addline(SIMPLELIST_ADD_LINE,
1879 "Power mgmt: %s", i ? "enabled" : "unsupported");
1880 i = identify_info[83] & (1<<9);
1881 simplelist_addline(SIMPLELIST_ADD_LINE,
1882 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1883 i = identify_info[82] & (1<<6);
1884 simplelist_addline(SIMPLELIST_ADD_LINE,
1885 "Read-ahead: %s", i ? "enabled" : "unsupported");
1886 timing_info_present = identify_info[53] & (1<<1);
1887 if(timing_info_present) {
1888 char pio3[2], pio4[2];pio3[1] = 0;
1889 pio4[1] = 0;
1890 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1891 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1892 simplelist_addline(SIMPLELIST_ADD_LINE,
1893 "PIO modes: 0 1 2 %s %s", pio3, pio4);
1895 else {
1896 simplelist_addline(SIMPLELIST_ADD_LINE,
1897 "No PIO mode info");
1899 timing_info_present = identify_info[53] & (1<<1);
1900 if(timing_info_present) {
1901 simplelist_addline(SIMPLELIST_ADD_LINE,
1902 "Cycle times %dns/%dns",
1903 identify_info[67],
1904 identify_info[68] );
1905 } else {
1906 simplelist_addline(SIMPLELIST_ADD_LINE,
1907 "No timing info");
1909 #if defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S)
1910 if (identify_info[63] & (1<<0)) {
1911 char mdma0[2], mdma1[2], mdma2[2];
1912 mdma0[1] = mdma1[1] = mdma2[1] = 0;
1913 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
1914 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
1915 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
1916 simplelist_addline(SIMPLELIST_ADD_LINE,
1917 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
1918 simplelist_addline(SIMPLELIST_ADD_LINE,
1919 "MDMA Cycle times %dns/%dns",
1920 identify_info[65],
1921 identify_info[66] );
1923 else {
1924 simplelist_addline(SIMPLELIST_ADD_LINE,
1925 "No MDMA mode info");
1927 if (identify_info[88] & (1<<0)) {
1928 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2];
1929 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = 0;
1930 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
1931 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
1932 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
1933 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
1934 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
1935 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
1936 simplelist_addline(SIMPLELIST_ADD_LINE,
1937 "UDMA modes: %s %s %s %s %s %s", udma0, udma1, udma2,
1938 udma3, udma4, udma5);
1940 else {
1941 simplelist_addline(SIMPLELIST_ADD_LINE,
1942 "No UDMA mode info");
1944 #endif /* defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S) */
1945 timing_info_present = identify_info[53] & (1<<1);
1946 if(timing_info_present) {
1947 i = identify_info[49] & (1<<11);
1948 simplelist_addline(SIMPLELIST_ADD_LINE,
1949 "IORDY support: %s", i ? "yes" : "no");
1950 i = identify_info[49] & (1<<10);
1951 simplelist_addline(SIMPLELIST_ADD_LINE,
1952 "IORDY disable: %s", i ? "yes" : "no");
1953 } else {
1954 simplelist_addline(SIMPLELIST_ADD_LINE,
1955 "No timing info");
1957 simplelist_addline(SIMPLELIST_ADD_LINE,
1958 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1959 return btn;
1962 static bool dbg_identify_info(void)
1964 int fd = creat("/identify_info.bin");
1965 if(fd >= 0)
1967 #ifdef ROCKBOX_LITTLE_ENDIAN
1968 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
1969 #else
1970 write(fd, ata_get_identify(), SECTOR_SIZE);
1971 #endif
1972 close(fd);
1974 return false;
1976 #endif /* !defined(HAVE_MMC) && !defined(HAVE_ATA_SD) */
1978 static bool dbg_disk_info(void)
1980 struct simplelist_info info;
1981 simplelist_info_init(&info, "Disk Info", 1, NULL);
1982 #if defined(HAVE_MMC) || defined(HAVE_ATA_SD)
1983 char title[16];
1984 int card = 0;
1985 info.callback_data = (void*)&card;
1986 info.title = title;
1987 #endif
1988 info.action_callback = disk_callback;
1989 info.hide_selection = true;
1990 info.scroll_all = true;
1991 return simplelist_show_list(&info);
1993 #endif /* !SIMULATOR */
1995 #ifdef HAVE_DIRCACHE
1996 static int dircache_callback(int btn, struct gui_synclist *lists)
1998 (void)btn; (void)lists;
1999 simplelist_set_line_count(0);
2000 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
2001 dircache_is_enabled() ? "Yes" : "No");
2002 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
2003 dircache_get_cache_size());
2004 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
2005 global_status.dircache_size);
2006 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
2007 DIRCACHE_LIMIT);
2008 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
2009 dircache_get_reserve_used(), DIRCACHE_RESERVE);
2010 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2011 dircache_get_build_ticks() / HZ);
2012 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2013 dircache_get_entry_count());
2014 return btn;
2017 static bool dbg_dircache_info(void)
2019 struct simplelist_info info;
2020 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2021 info.action_callback = dircache_callback;
2022 info.hide_selection = true;
2023 info.scroll_all = true;
2024 return simplelist_show_list(&info);
2027 #endif /* HAVE_DIRCACHE */
2029 #ifdef HAVE_TAGCACHE
2030 static int database_callback(int btn, struct gui_synclist *lists)
2032 (void)lists;
2033 struct tagcache_stat *stat = tagcache_get_stat();
2034 static bool synced = false;
2036 simplelist_set_line_count(0);
2038 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2039 stat->initialized ? "Yes" : "No");
2040 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2041 stat->ready ? "Yes" : "No");
2042 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2043 stat->ramcache ? "Yes" : "No");
2044 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2045 stat->ramcache_used, stat->ramcache_allocated);
2046 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2047 stat->progress, stat->processed_entries);
2048 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2049 stat->curentry ? stat->curentry : "---");
2050 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2051 stat->commit_step);
2052 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2053 stat->commit_delayed ? "Yes" : "No");
2055 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2056 stat->queue_length);
2058 if (synced)
2060 synced = false;
2061 tagcache_screensync_event();
2064 if (!btn && stat->curentry)
2066 synced = true;
2067 return ACTION_REDRAW;
2070 if (btn == ACTION_STD_CANCEL)
2071 tagcache_screensync_enable(false);
2073 return btn;
2075 static bool dbg_tagcache_info(void)
2077 struct simplelist_info info;
2078 simplelist_info_init(&info, "Database Info", 8, NULL);
2079 info.action_callback = database_callback;
2080 info.hide_selection = true;
2081 info.scroll_all = true;
2083 /* Don't do nonblock here, must give enough processing time
2084 for tagcache thread. */
2085 /* info.timeout = TIMEOUT_NOBLOCK; */
2086 info.timeout = 1;
2087 tagcache_screensync_enable(true);
2088 return simplelist_show_list(&info);
2090 #endif
2092 #if CONFIG_CPU == SH7034
2093 static bool dbg_save_roms(void)
2095 int fd;
2096 int oldmode = system_memory_guard(MEMGUARD_NONE);
2098 fd = creat("/internal_rom_0000-FFFF.bin");
2099 if(fd >= 0)
2101 write(fd, (void *)0, 0x10000);
2102 close(fd);
2105 fd = creat("/internal_rom_2000000-203FFFF.bin");
2106 if(fd >= 0)
2108 write(fd, (void *)0x2000000, 0x40000);
2109 close(fd);
2112 system_memory_guard(oldmode);
2113 return false;
2115 #elif defined CPU_COLDFIRE
2116 static bool dbg_save_roms(void)
2118 int fd;
2119 int oldmode = system_memory_guard(MEMGUARD_NONE);
2121 #if defined(IRIVER_H100_SERIES)
2122 fd = creat("/internal_rom_000000-1FFFFF.bin");
2123 #elif defined(IRIVER_H300_SERIES)
2124 fd = creat("/internal_rom_000000-3FFFFF.bin");
2125 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2126 fd = creat("/internal_rom_000000-3FFFFF.bin");
2127 #endif
2128 if(fd >= 0)
2130 write(fd, (void *)0, FLASH_SIZE);
2131 close(fd);
2133 system_memory_guard(oldmode);
2135 #ifdef HAVE_EEPROM
2136 fd = creat("/internal_eeprom.bin");
2137 if (fd >= 0)
2139 int old_irq_level;
2140 char buf[EEPROM_SIZE];
2141 int err;
2143 old_irq_level = disable_irq_save();
2145 err = eeprom_24cxx_read(0, buf, sizeof buf);
2147 restore_irq(old_irq_level);
2149 if (err)
2150 gui_syncsplash(HZ*3, "Eeprom read failure (%d)",err);
2151 else
2153 write(fd, buf, sizeof buf);
2156 close(fd);
2158 #endif
2160 return false;
2162 #elif defined(CPU_PP) && !defined(HAVE_ATA_SD)
2163 static bool dbg_save_roms(void)
2165 int fd;
2167 fd = creat("/internal_rom_000000-0FFFFF.bin");
2168 if(fd >= 0)
2170 write(fd, (void *)0x20000000, FLASH_SIZE);
2171 close(fd);
2174 return false;
2176 #endif /* CPU */
2178 #ifndef SIMULATOR
2179 #if CONFIG_TUNER
2180 static int radio_callback(int btn, struct gui_synclist *lists)
2182 (void)lists;
2183 if (btn == ACTION_STD_CANCEL)
2184 return btn;
2185 simplelist_set_line_count(1);
2187 #if (CONFIG_TUNER & LV24020LP)
2188 simplelist_addline(SIMPLELIST_ADD_LINE,
2189 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2190 simplelist_addline(SIMPLELIST_ADD_LINE,
2191 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2192 simplelist_addline(SIMPLELIST_ADD_LINE,
2193 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2194 simplelist_addline(SIMPLELIST_ADD_LINE,
2195 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2196 simplelist_addline(SIMPLELIST_ADD_LINE,
2197 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2198 simplelist_addline(SIMPLELIST_ADD_LINE,
2199 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2200 simplelist_addline(SIMPLELIST_ADD_LINE,
2201 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2202 #endif
2203 #if (CONFIG_TUNER & S1A0903X01)
2204 simplelist_addline(SIMPLELIST_ADD_LINE,
2205 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2206 /* This one doesn't return dynamic data atm */
2207 #endif
2208 #if (CONFIG_TUNER & TEA5767)
2209 struct tea5767_dbg_info nfo;
2210 tea5767_dbg_info(&nfo);
2211 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2212 simplelist_addline(SIMPLELIST_ADD_LINE,
2213 " Read: %02X %02X %02X %02X %02X",
2214 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2215 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2216 (unsigned)nfo.read_regs[4]);
2217 simplelist_addline(SIMPLELIST_ADD_LINE,
2218 " Write: %02X %02X %02X %02X %02X",
2219 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2220 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2221 (unsigned)nfo.write_regs[4]);
2222 #endif
2223 return ACTION_REDRAW;
2225 static bool dbg_fm_radio(void)
2227 struct simplelist_info info;
2228 info.scroll_all = true;
2229 simplelist_info_init(&info, "FM Radio", 1, NULL);
2230 simplelist_set_line_count(0);
2231 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2232 radio_hardware_present() ? "yes" : "no");
2234 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2235 info.hide_selection = true;
2236 return simplelist_show_list(&info);
2238 #endif /* CONFIG_TUNER */
2239 #endif /* !SIMULATOR */
2241 #ifdef HAVE_LCD_BITMAP
2242 extern bool do_screendump_instead_of_usb;
2244 static bool dbg_screendump(void)
2246 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2247 gui_syncsplash(HZ, "Screendump %s",
2248 do_screendump_instead_of_usb?"enabled":"disabled");
2249 return false;
2251 #endif /* HAVE_LCD_BITMAP */
2253 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2254 static bool dbg_set_memory_guard(void)
2256 static const struct opt_items names[MAXMEMGUARD] = {
2257 { "None", -1 },
2258 { "Flash ROM writes", -1 },
2259 { "Zero area (all)", -1 }
2261 int mode = system_memory_guard(MEMGUARD_KEEP);
2263 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2264 system_memory_guard(mode);
2266 return false;
2268 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2270 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2271 static bool dbg_write_eeprom(void)
2273 int fd;
2274 int rc;
2275 int old_irq_level;
2276 char buf[EEPROM_SIZE];
2277 int err;
2279 fd = open("/internal_eeprom.bin", O_RDONLY);
2281 if (fd >= 0)
2283 rc = read(fd, buf, EEPROM_SIZE);
2285 if(rc == EEPROM_SIZE)
2287 old_irq_level = disable_irq_save();
2289 err = eeprom_24cxx_write(0, buf, sizeof buf);
2290 if (err)
2291 gui_syncsplash(HZ*3, "Eeprom write failure (%d)",err);
2292 else
2293 gui_syncsplash(HZ*3, "Eeprom written successfully");
2295 restore_irq(old_irq_level);
2297 else
2299 gui_syncsplash(HZ*3, "File read error (%d)",rc);
2301 close(fd);
2303 else
2305 gui_syncsplash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2308 return false;
2310 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2311 #ifdef CPU_BOOST_LOGGING
2312 static bool cpu_boost_log(void)
2314 int i = 0,j=0;
2315 int count = cpu_boost_log_getcount();
2316 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2317 char *str;
2318 bool done;
2319 lcd_setmargins(0, 0);
2320 lcd_setfont(FONT_SYSFIXED);
2321 str = cpu_boost_log_getlog_first();
2322 while (i < count)
2324 lcd_clear_display();
2325 for(j=0; j<lines; j++,i++)
2327 if (!str)
2328 str = cpu_boost_log_getlog_next();
2329 if (str)
2331 lcd_puts(0, j,str);
2333 str = NULL;
2335 lcd_update();
2336 done = false;
2337 while (!done)
2339 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2341 case ACTION_STD_OK:
2342 case ACTION_STD_PREV:
2343 case ACTION_STD_NEXT:
2344 done = true;
2345 break;
2346 case ACTION_STD_CANCEL:
2347 i = count;
2348 done = true;
2349 break;
2353 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2354 lcd_setfont(FONT_UI);
2355 return false;
2357 #endif
2359 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2360 extern bool wheel_is_touched;
2361 extern int old_wheel_value;
2362 extern int new_wheel_value;
2363 extern int wheel_delta;
2364 extern unsigned int accumulated_wheel_delta;
2365 extern unsigned int wheel_velocity;
2367 static bool dbg_scrollwheel(void)
2369 char buf[64];
2370 unsigned int speed;
2372 lcd_setmargins(0, 0);
2373 lcd_setfont(FONT_SYSFIXED);
2375 while (1)
2377 if (action_userabort(HZ/10))
2378 return false;
2380 lcd_clear_display();
2382 /* show internal variables of scrollwheel driver */
2383 snprintf(buf, sizeof(buf), "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2384 lcd_puts(0, 0, buf);
2385 snprintf(buf, sizeof(buf), "new position: %2d", new_wheel_value);
2386 lcd_puts(0, 1, buf);
2387 snprintf(buf, sizeof(buf), "old position: %2d", old_wheel_value);
2388 lcd_puts(0, 2, buf);
2389 snprintf(buf, sizeof(buf), "wheel delta: %2d", wheel_delta);
2390 lcd_puts(0, 3, buf);
2391 snprintf(buf, sizeof(buf), "accumulated delta: %2d", accumulated_wheel_delta);
2392 lcd_puts(0, 4, buf);
2393 snprintf(buf, sizeof(buf), "velo [deg/s]: %4d", (int)wheel_velocity);
2394 lcd_puts(0, 5, buf);
2396 /* show effective accelerated scrollspeed */
2397 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2398 snprintf(buf, sizeof(buf), "accel. speed: %4d", speed);
2399 lcd_puts(0, 6, buf);
2401 lcd_update();
2403 return false;
2405 #endif
2407 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2408 static bool logf_usb_serial(void)
2410 bool serial_enabled = !usb_core_driver_enabled(USB_DRIVER_SERIAL);
2411 usb_core_enable_driver(USB_DRIVER_SERIAL,serial_enabled);
2412 gui_syncsplash(HZ, "USB logf %s",
2413 serial_enabled?"enabled":"disabled");
2414 return false;
2416 #endif
2418 #if defined(HAVE_USBSTACK) && defined(USB_STORAGE)
2419 static bool usb_reconnect(void)
2421 gui_syncsplash(HZ, "Reconnect mass storage");
2422 usb_storage_reconnect();
2423 return false;
2425 #endif
2427 #if CONFIG_USBOTG == USBOTG_ISP1583
2428 extern int dbg_usb_num_items(void);
2429 extern char* dbg_usb_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2431 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2433 (void)lists;
2434 if (action == ACTION_NONE)
2435 action = ACTION_REDRAW;
2436 return action;
2439 static bool dbg_isp1583(void)
2441 struct simplelist_info isp1583;
2442 isp1583.scroll_all = true;
2443 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2444 isp1583.timeout = HZ/100;
2445 isp1583.hide_selection = true;
2446 isp1583.get_name = dbg_usb_item;
2447 isp1583.action_callback = isp1583_action_callback;
2448 return simplelist_show_list(&isp1583);
2450 #endif
2452 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2453 extern int pic_dbg_num_items(void);
2454 extern char* pic_dbg_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2456 static int pic_action_callback(int action, struct gui_synclist *lists)
2458 (void)lists;
2459 if (action == ACTION_NONE)
2460 action = ACTION_REDRAW;
2461 return action;
2464 static bool dbg_pic(void)
2466 struct simplelist_info pic;
2467 pic.scroll_all = true;
2468 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2469 pic.timeout = HZ/100;
2470 pic.hide_selection = true;
2471 pic.get_name = pic_dbg_item;
2472 pic.action_callback = pic_action_callback;
2473 return simplelist_show_list(&pic);
2475 #endif
2478 /****** The menu *********/
2479 struct the_menu_item {
2480 unsigned char *desc; /* string or ID */
2481 bool (*function) (void); /* return true if USB was connected */
2483 static const struct the_menu_item menuitems[] = {
2484 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2485 (defined(CPU_PP) && !defined(HAVE_ATA_SD))
2486 { "Dump ROM contents", dbg_save_roms },
2487 #endif
2488 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2489 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L
2490 { "View I/O ports", dbg_ports },
2491 #endif
2492 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2493 { "View PCF registers", dbg_pcf },
2494 #endif
2495 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2496 { "TSC2100 debug", tsc2100_debug },
2497 #endif
2498 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2499 { "CPU frequency", dbg_cpufreq },
2500 #endif
2501 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2502 { "S/PDIF analyzer", dbg_spdif },
2503 #endif
2504 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2505 { "Catch mem accesses", dbg_set_memory_guard },
2506 #endif
2507 { "View OS stacks", dbg_os },
2508 #ifdef HAVE_LCD_BITMAP
2509 #ifndef SIMULATOR
2510 { "View battery", view_battery },
2511 #endif
2512 { "Screendump", dbg_screendump },
2513 #endif
2514 #ifndef SIMULATOR
2515 { "View HW info", dbg_hw_info },
2516 #endif
2517 #ifndef SIMULATOR
2518 { "View partitions", dbg_partitions },
2519 #endif
2520 #ifndef SIMULATOR
2521 { "View disk info", dbg_disk_info },
2522 #if !defined(HAVE_MMC) && !defined(HAVE_ATA_SD)
2523 { "Dump ATA identify info", dbg_identify_info},
2524 #endif
2525 #endif
2526 #ifdef HAVE_DIRCACHE
2527 { "View dircache info", dbg_dircache_info },
2528 #endif
2529 #ifdef HAVE_TAGCACHE
2530 { "View database info", dbg_tagcache_info },
2531 #endif
2532 #ifdef HAVE_LCD_BITMAP
2533 #if CONFIG_CODEC == SWCODEC
2534 { "View buffering thread", dbg_buffering_thread },
2535 #elif !defined(SIMULATOR)
2536 { "View audio thread", dbg_audio_thread },
2537 #endif
2538 #ifdef PM_DEBUG
2539 { "pm histogram", peak_meter_histogram},
2540 #endif /* PM_DEBUG */
2541 #endif /* HAVE_LCD_BITMAP */
2542 #ifndef SIMULATOR
2543 #if CONFIG_TUNER
2544 { "FM Radio", dbg_fm_radio },
2545 #endif
2546 #endif
2547 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2548 { "Write back EEPROM", dbg_write_eeprom },
2549 #endif
2550 #if CONFIG_USBOTG == USBOTG_ISP1583
2551 { "View ISP1583 info", dbg_isp1583 },
2552 #endif
2553 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2554 { "View PIC info", dbg_pic },
2555 #endif
2556 #ifdef ROCKBOX_HAS_LOGF
2557 {"logf", logfdisplay },
2558 {"logfdump", logfdump },
2559 #endif
2560 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2561 {"logf over usb",logf_usb_serial },
2562 #endif
2563 #if defined(HAVE_USBSTACK) && defined(USB_STORAGE)
2564 {"reconnect usb storage",usb_reconnect},
2565 #endif
2566 #ifdef CPU_BOOST_LOGGING
2567 {"cpu_boost log",cpu_boost_log},
2568 #endif
2569 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2570 {"Debug scrollwheel", dbg_scrollwheel},
2571 #endif
2573 static int menu_action_callback(int btn, struct gui_synclist *lists)
2575 if (btn == ACTION_STD_OK)
2577 menuitems[gui_synclist_get_sel_pos(lists)].function();
2578 btn = ACTION_REDRAW;
2580 return btn;
2582 static char* dbg_menu_getname(int item, void * data,
2583 char *buffer, size_t buffer_len)
2585 (void)data; (void)buffer; (void)buffer_len;
2586 return menuitems[item].desc;
2588 bool debug_menu(void)
2590 struct simplelist_info info;
2592 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2593 info.action_callback = menu_action_callback;
2594 info.get_name = dbg_menu_getname;
2596 return simplelist_show_list(&info);