Fix sansa c200 battery type comment.
[kugel-rb.git] / apps / debug_menu.c
blobb2144e2169f1a28f8a5a7a27934b8f3fb0e48a2d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Heikki Hannikainen
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <stdbool.h>
26 #include <string.h>
27 #include "lcd.h"
28 #include "menu.h"
29 #include "debug_menu.h"
30 #include "kernel.h"
31 #include "sprintf.h"
32 #include "structec.h"
33 #include "action.h"
34 #include "debug.h"
35 #include "thread.h"
36 #include "powermgmt.h"
37 #include "system.h"
38 #include "font.h"
39 #include "audio.h"
40 #include "mp3_playback.h"
41 #include "settings.h"
42 #include "list.h"
43 #include "statusbar.h"
44 #include "dir.h"
45 #include "panic.h"
46 #include "screens.h"
47 #include "misc.h"
48 #include "splash.h"
49 #include "dircache.h"
50 #ifdef HAVE_TAGCACHE
51 #include "tagcache.h"
52 #endif
53 #include "lcd-remote.h"
54 #include "crc32.h"
55 #include "logf.h"
56 #ifndef SIMULATOR
57 #include "disk.h"
58 #include "adc.h"
59 #include "power.h"
60 #include "usb.h"
61 #include "rtc.h"
62 #include "ata.h"
63 #include "fat.h"
64 #include "mas.h"
65 #include "eeprom_24cxx.h"
66 #if defined(HAVE_MMC) || defined(HAVE_ATA_SD)
67 #include "hotswap.h"
68 #endif
69 #if CONFIG_TUNER
70 #include "tuner.h"
71 #include "radio.h"
72 #endif
73 #endif
75 #ifdef HAVE_LCD_BITMAP
76 #include "scrollbar.h"
77 #include "peakmeter.h"
78 #endif
79 #include "logfdisp.h"
80 #if CONFIG_CODEC == SWCODEC
81 #include "pcmbuf.h"
82 #include "buffering.h"
83 #include "playback.h"
84 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
85 #include "spdif.h"
86 #endif
87 #endif
88 #ifdef IRIVER_H300_SERIES
89 #include "pcf50606.h" /* for pcf50606_read */
90 #endif
91 #ifdef IAUDIO_X5
92 #include "ds2411.h"
93 #endif
94 #include "hwcompat.h"
95 #include "button.h"
96 #if CONFIG_RTC == RTC_PCF50605
97 #include "pcf50605.h"
98 #endif
100 #if CONFIG_CPU == DM320 || CONFIG_CPU == S3C2440 || CONFIG_CPU == TCC7801 \
101 || CONFIG_CPU == IMX31L
102 #include "debug-target.h"
103 #endif
105 #if defined(SANSA_E200) || defined(PHILIPS_SA9200)
106 #include "i2c-pp.h"
107 #include "as3514.h"
108 #endif
110 #if defined(HAVE_USBSTACK)
111 #include "usb_core.h"
112 #endif
113 #ifdef USB_STORAGE
114 #include "../firmware/usbstack/usb_storage.h"
115 #endif
117 /*---------------------------------------------------*/
118 /* SPECIAL DEBUG STUFF */
119 /*---------------------------------------------------*/
120 extern struct thread_entry threads[MAXTHREADS];
122 static char thread_status_char(unsigned status)
124 static const char thread_status_chars[THREAD_NUM_STATES+1] =
126 [0 ... THREAD_NUM_STATES] = '?',
127 [STATE_RUNNING] = 'R',
128 [STATE_BLOCKED] = 'B',
129 [STATE_SLEEPING] = 'S',
130 [STATE_BLOCKED_W_TMO] = 'T',
131 [STATE_FROZEN] = 'F',
132 [STATE_KILLED] = 'K',
135 if (status > THREAD_NUM_STATES)
136 status = THREAD_NUM_STATES;
138 return thread_status_chars[status];
141 static char* threads_getname(int selected_item, void *data,
142 char *buffer, size_t buffer_len)
144 (void)data;
145 struct thread_entry *thread;
146 char name[32];
148 #if NUM_CORES > 1
149 if (selected_item < (int)NUM_CORES)
151 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
152 idle_stack_usage(selected_item));
153 return buffer;
156 selected_item -= NUM_CORES;
157 #endif
159 thread = &threads[selected_item];
161 if (thread->state == STATE_KILLED)
163 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
164 return buffer;
167 thread_get_name(name, 32, thread);
169 snprintf(buffer, buffer_len,
170 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
171 selected_item,
172 IF_COP(thread->core,)
173 #ifdef HAVE_SCHEDULER_BOOSTCTRL
174 (thread->cpu_boost) ? '+' :
175 #endif
176 ((thread->state == STATE_RUNNING) ? '*' : ' '),
177 thread_status_char(thread->state),
178 IF_PRIO(thread->base_priority, thread->priority, )
179 thread_stack_usage(thread), name);
181 return buffer;
183 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
185 (void)lists;
186 #ifdef ROCKBOX_HAS_LOGF
187 if (action == ACTION_STD_OK)
189 int selpos = gui_synclist_get_sel_pos(lists);
190 #if NUM_CORES > 1
191 if (selpos >= NUM_CORES)
192 remove_thread(&threads[selpos - NUM_CORES]);
193 #else
194 remove_thread(&threads[selpos]);
195 #endif
196 return ACTION_REDRAW;
198 #endif /* ROCKBOX_HAS_LOGF */
199 if (action == ACTION_NONE)
200 action = ACTION_REDRAW;
201 return action;
203 /* Test code!!! */
204 static bool dbg_os(void)
206 struct simplelist_info info;
207 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
208 #if NUM_CORES == 1
209 MAXTHREADS,
210 #else
211 MAXTHREADS+NUM_CORES,
212 #endif
213 NULL);
214 #ifndef ROCKBOX_HAS_LOGF
215 info.hide_selection = true;
216 info.scroll_all = true;
217 #endif
218 info.action_callback = dbg_threads_action_callback;
219 info.get_name = threads_getname;
220 return simplelist_show_list(&info);
223 #ifdef HAVE_LCD_BITMAP
224 #if CONFIG_CODEC != SWCODEC
225 #ifndef SIMULATOR
226 static bool dbg_audio_thread(void)
228 char buf[32];
229 struct audio_debug d;
231 lcd_setfont(FONT_SYSFIXED);
233 while(1)
235 if (action_userabort(HZ/5))
236 return false;
238 audio_get_debugdata(&d);
240 lcd_clear_display();
242 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
243 lcd_puts(0, 0, buf);
244 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
245 lcd_puts(0, 1, buf);
246 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
247 lcd_puts(0, 2, buf);
248 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
249 lcd_puts(0, 3, buf);
250 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
251 lcd_puts(0, 4, buf);
252 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
253 lcd_puts(0, 5, buf);
255 /* Playable space left */
256 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
257 d.playable_space, HORIZONTAL);
259 /* Show the watermark limit */
260 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
261 d.low_watermark_level, HORIZONTAL);
263 snprintf(buf, sizeof(buf), "wm: %x - %x",
264 d.low_watermark_level, d.lowest_watermark_level);
265 lcd_puts(0, 7, buf);
267 lcd_update();
269 return false;
271 #endif /* !SIMULATOR */
272 #else /* CONFIG_CODEC == SWCODEC */
273 extern size_t filebuflen;
274 /* This is a size_t, but call it a long so it puts a - when it's bad. */
276 static unsigned int ticks, boost_ticks, freq_sum;
278 static void dbg_audio_task(void)
280 #ifndef SIMULATOR
281 if(FREQ > CPUFREQ_NORMAL)
282 boost_ticks++;
283 freq_sum += FREQ/1000000; /* in MHz */
284 #endif
285 ticks++;
288 static bool dbg_buffering_thread(void)
290 char buf[32];
291 int button;
292 int line;
293 bool done = false;
294 size_t bufused;
295 size_t bufsize = pcmbuf_get_bufsize();
296 int pcmbufdescs = pcmbuf_descs();
297 struct buffering_debug d;
299 ticks = boost_ticks = freq_sum = 0;
301 tick_add_task(dbg_audio_task);
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_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_setfont(FONT_SYSFIXED);
575 lcd_clear_display();
577 lcd_puts(0, line++, "[Hardware info]");
579 if (got_id)
580 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
581 else
582 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
583 lcd_puts(0, line++, buf);
585 #ifdef IAUDIO_X5
587 struct ds2411_id id;
589 lcd_puts(0, ++line, "Serial Number:");
591 got_id = ds2411_read_id(&id);
593 if (got_id == DS2411_OK)
595 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
596 lcd_puts(0, ++line, buf);
597 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
598 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
599 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
600 lcd_puts(0, ++line, buf);
601 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
603 else
605 snprintf(buf, 32, "READ ERR=%d", got_id);
608 lcd_puts(0, ++line, buf);
610 #endif
612 lcd_update();
614 while (!(action_userabort(TIMEOUT_BLOCK)));
616 #elif defined(CPU_PP502x)
617 int line = 0;
618 char buf[32];
619 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
620 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
621 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
622 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
624 lcd_setfont(FONT_SYSFIXED);
625 lcd_clear_display();
627 lcd_puts(0, line++, "[Hardware info]");
629 #ifdef IPOD_ARCH
630 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
631 lcd_puts(0, line++, buf);
632 #endif
634 #ifdef IPOD_COLOR
635 extern int lcd_type; /* Defined in lcd-colornano.c */
637 snprintf(buf, sizeof(buf), "LCD type: %d", lcd_type);
638 lcd_puts(0, line++, buf);
639 #endif
641 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
642 lcd_puts(0, line++, buf);
644 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
645 lcd_puts(0, line++, buf);
647 lcd_update();
649 while (!(action_userabort(TIMEOUT_BLOCK)));
651 #elif CONFIG_CPU == PP5002
652 int line = 0;
653 char buf[32];
654 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
655 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
656 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
657 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
660 lcd_setfont(FONT_SYSFIXED);
661 lcd_clear_display();
663 lcd_puts(0, line++, "[Hardware info]");
665 #ifdef IPOD_ARCH
666 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
667 lcd_puts(0, line++, buf);
668 #endif
670 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
671 lcd_puts(0, line++, buf);
673 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
674 lcd_puts(0, line++, buf);
676 lcd_update();
678 while (!(action_userabort(TIMEOUT_BLOCK)));
679 #else
680 /* Define this function in your target tree */
681 return __dbg_hw_info();
682 #endif /* CONFIG_CPU */
683 return false;
685 #else /* !HAVE_LCD_BITMAP */
686 static bool dbg_hw_info(void)
688 char buf[32];
689 int button;
690 int currval = 0;
691 int rom_version = ROM_VERSION;
692 unsigned manu, id; /* flash IDs */
693 bool got_id; /* flag if we managed to get the flash IDs */
694 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
695 bool has_bootrom; /* flag for boot ROM present */
696 int oldmode; /* saved memory guard mode */
698 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
700 /* get flash ROM type */
701 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
702 if (!got_id)
703 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
705 /* check if the boot ROM area is a flash mirror */
706 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
707 if (has_bootrom) /* if ROM and Flash different */
709 /* calculate CRC16 checksum of boot ROM */
710 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
713 system_memory_guard(oldmode); /* re-enable memory guard */
715 lcd_clear_display();
717 lcd_puts(0, 0, "[HW Info]");
718 while(1)
720 switch(currval)
722 case 0:
723 snprintf(buf, 32, "ROM: %d.%02d",
724 rom_version/100, rom_version%100);
725 break;
726 case 1:
727 if (got_id)
728 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
729 else
730 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
731 break;
732 case 2:
733 if (has_bootrom)
735 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
736 snprintf(buf, 32, "BootROM: V1");
737 else if (rom_crc == 0x358099E8)
738 snprintf(buf, 32, "BootROM: V2");
739 /* alternative boot ROM found in one single player so far */
740 else
741 snprintf(buf, 32, "R: %08x", rom_crc);
743 else
744 snprintf(buf, 32, "BootROM: no");
747 lcd_puts(0, 1, buf);
748 lcd_update();
750 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
752 switch(button)
754 case ACTION_STD_CANCEL:
755 return false;
757 case ACTION_SETTINGS_DEC:
758 currval--;
759 if(currval < 0)
760 currval = 2;
761 break;
763 case ACTION_SETTINGS_INC:
764 currval++;
765 if(currval > 2)
766 currval = 0;
767 break;
770 return false;
772 #endif /* !HAVE_LCD_BITMAP */
773 #endif /* !SIMULATOR */
775 #ifndef SIMULATOR
776 static char* dbg_partitions_getname(int selected_item, void *data,
777 char *buffer, size_t buffer_len)
779 (void)data;
780 int partition = selected_item/2;
781 struct partinfo* p = disk_partinfo(partition);
782 if (selected_item%2)
784 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / 2048);
786 else
788 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
790 return buffer;
793 bool dbg_partitions(void)
795 struct simplelist_info info;
796 simplelist_info_init(&info, "Partition Info", 4, NULL);
797 info.selection_size = 2;
798 info.hide_selection = true;
799 info.scroll_all = true;
800 info.get_name = dbg_partitions_getname;
801 return simplelist_show_list(&info);
803 #endif
805 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
806 static bool dbg_spdif(void)
808 char buf[128];
809 int line;
810 unsigned int control;
811 int x;
812 char *s;
813 int category;
814 int generation;
815 unsigned int interruptstat;
816 bool valnogood, symbolerr, parityerr;
817 bool done = false;
818 bool spdif_src_on;
819 int spdif_source = spdif_get_output_source(&spdif_src_on);
820 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
822 lcd_clear_display();
823 lcd_setfont(FONT_SYSFIXED);
825 #ifdef HAVE_SPDIF_POWER
826 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
827 #endif
829 while (!done)
831 line = 0;
833 control = EBU1RCVCCHANNEL1;
834 interruptstat = INTERRUPTSTAT;
835 INTERRUPTCLEAR = 0x03c00000;
837 valnogood = (interruptstat & 0x01000000)?true:false;
838 symbolerr = (interruptstat & 0x00800000)?true:false;
839 parityerr = (interruptstat & 0x00400000)?true:false;
841 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
842 valnogood?"--":"OK",
843 symbolerr?"--":"OK",
844 parityerr?"--":"OK");
845 lcd_puts(0, line++, buf);
847 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
848 lcd_puts(0, line++, buf);
850 line++;
852 x = control >> 31;
853 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
854 x, x?"Professional":"Consumer");
855 lcd_puts(0, line++, buf);
857 x = (control >> 30) & 1;
858 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
859 x, x?"Non-PCM":"PCM");
860 lcd_puts(0, line++, buf);
862 x = (control >> 29) & 1;
863 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
864 x, x?"Permitted":"Inhibited");
865 lcd_puts(0, line++, buf);
867 x = (control >> 27) & 7;
868 switch(x)
870 case 0:
871 s = "None";
872 break;
873 case 1:
874 s = "50/15us";
875 break;
876 default:
877 s = "Reserved";
878 break;
880 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
881 lcd_puts(0, line++, buf);
883 x = (control >> 24) & 3;
884 snprintf(buf, sizeof(buf), "Mode: %d", x);
885 lcd_puts(0, line++, buf);
887 category = (control >> 17) & 127;
888 switch(category)
890 case 0x00:
891 s = "General";
892 break;
893 case 0x40:
894 s = "Audio CD";
895 break;
896 default:
897 s = "Unknown";
899 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
900 lcd_puts(0, line++, buf);
902 x = (control >> 16) & 1;
903 generation = x;
904 if(((category & 0x70) == 0x10) ||
905 ((category & 0x70) == 0x40) ||
906 ((category & 0x78) == 0x38))
908 generation = !generation;
910 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
911 x, generation?"Original":"No ind.");
912 lcd_puts(0, line++, buf);
914 x = (control >> 12) & 15;
915 snprintf(buf, sizeof(buf), "Source: %d", x);
916 lcd_puts(0, line++, buf);
918 x = (control >> 8) & 15;
919 switch(x)
921 case 0:
922 s = "Unspecified";
923 break;
924 case 8:
925 s = "A (Left)";
926 break;
927 case 4:
928 s = "B (Right)";
929 break;
930 default:
931 s = "";
932 break;
934 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
935 lcd_puts(0, line++, buf);
937 x = (control >> 4) & 15;
938 switch(x)
940 case 0:
941 s = "44.1kHz";
942 break;
943 case 0x4:
944 s = "48kHz";
945 break;
946 case 0xc:
947 s = "32kHz";
948 break;
950 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
951 lcd_puts(0, line++, buf);
953 x = (control >> 2) & 3;
954 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
955 lcd_puts(0, line++, buf);
956 line++;
958 #ifndef SIMULATOR
959 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
960 spdif_measure_frequency());
961 lcd_puts(0, line++, buf);
962 #endif
964 lcd_update();
966 if (action_userabort(HZ/10))
967 break;
970 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
972 #ifdef HAVE_SPDIF_POWER
973 spdif_power_enable(global_settings.spdif_enable);
974 #endif
976 return false;
978 #endif /* CPU_COLDFIRE */
980 #ifndef SIMULATOR
981 #ifdef HAVE_LCD_BITMAP
982 /* button definitions */
983 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
984 (CONFIG_KEYPAD == IRIVER_H300_PAD)
985 # define DEBUG_CANCEL BUTTON_OFF
987 #elif CONFIG_KEYPAD == RECORDER_PAD
988 # define DEBUG_CANCEL BUTTON_OFF
990 #elif CONFIG_KEYPAD == ONDIO_PAD
991 # define DEBUG_CANCEL BUTTON_MENU
993 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
994 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
995 (CONFIG_KEYPAD == IPOD_4G_PAD)
996 # define DEBUG_CANCEL BUTTON_MENU
998 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
999 # define DEBUG_CANCEL BUTTON_PLAY
1001 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
1002 # define DEBUG_CANCEL BUTTON_REC
1004 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1005 # define DEBUG_CANCEL BUTTON_RC_REC
1007 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
1008 # define DEBUG_CANCEL BUTTON_REW
1010 #elif (CONFIG_KEYPAD == MROBE100_PAD)
1011 # define DEBUG_CANCEL BUTTON_MENU
1013 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
1014 (CONFIG_KEYPAD == SANSA_C200_PAD)
1015 # define DEBUG_CANCEL BUTTON_LEFT
1017 /* This is temporary until the SA9200 touchpad works */
1018 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) || \
1019 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD)
1020 # define DEBUG_CANCEL BUTTON_POWER
1022 #endif /* key definitions */
1024 /* Test code!!! */
1025 bool dbg_ports(void)
1027 #if CONFIG_CPU == SH7034
1028 char buf[32];
1029 int adc_battery_voltage, adc_battery_level;
1031 lcd_setfont(FONT_SYSFIXED);
1032 lcd_clear_display();
1034 while(1)
1036 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1037 lcd_puts(0, 0, buf);
1038 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1039 lcd_puts(0, 1, buf);
1041 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1042 lcd_puts(0, 2, buf);
1043 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1044 lcd_puts(0, 3, buf);
1045 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1046 lcd_puts(0, 4, buf);
1047 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1048 lcd_puts(0, 5, buf);
1050 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1051 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1052 adc_battery_voltage % 1000, adc_battery_level);
1053 lcd_puts(0, 6, buf);
1055 lcd_update();
1056 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1057 return false;
1059 #elif defined(CPU_COLDFIRE)
1060 unsigned int gpio_out;
1061 unsigned int gpio1_out;
1062 unsigned int gpio_read;
1063 unsigned int gpio1_read;
1064 unsigned int gpio_function;
1065 unsigned int gpio1_function;
1066 unsigned int gpio_enable;
1067 unsigned int gpio1_enable;
1068 int adc_buttons, adc_remote;
1069 int adc_battery_voltage, adc_battery_level;
1070 char buf[128];
1071 int line;
1073 lcd_clear_display();
1074 lcd_setfont(FONT_SYSFIXED);
1076 while(1)
1078 line = 0;
1079 gpio_read = GPIO_READ;
1080 gpio1_read = GPIO1_READ;
1081 gpio_out = GPIO_OUT;
1082 gpio1_out = GPIO1_OUT;
1083 gpio_function = GPIO_FUNCTION;
1084 gpio1_function = GPIO1_FUNCTION;
1085 gpio_enable = GPIO_ENABLE;
1086 gpio1_enable = GPIO1_ENABLE;
1088 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1089 lcd_puts(0, line++, buf);
1090 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1091 lcd_puts(0, line++, buf);
1092 snprintf(buf, sizeof(buf), "GPIO_FUNC: %08x", gpio_function);
1093 lcd_puts(0, line++, buf);
1094 snprintf(buf, sizeof(buf), "GPIO_ENA: %08x", gpio_enable);
1095 lcd_puts(0, line++, buf);
1097 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1098 lcd_puts(0, line++, buf);
1099 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1100 lcd_puts(0, line++, buf);
1101 snprintf(buf, sizeof(buf), "GPIO1_FUNC: %08x", gpio1_function);
1102 lcd_puts(0, line++, buf);
1103 snprintf(buf, sizeof(buf), "GPIO1_ENA: %08x", gpio1_enable);
1104 lcd_puts(0, line++, buf);
1106 adc_buttons = adc_read(ADC_BUTTONS);
1107 adc_remote = adc_read(ADC_REMOTE);
1108 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1109 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1110 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1111 button_scan_enabled() ? '+' : '-', adc_buttons);
1112 #else
1113 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1114 #endif
1115 lcd_puts(0, line++, buf);
1116 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1117 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1118 remote_detect() ? '+' : '-', adc_remote);
1119 #else
1120 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1121 #endif
1122 lcd_puts(0, line++, buf);
1123 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1124 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1125 adc_read(ADC_REMOTEDETECT));
1126 lcd_puts(0, line++, buf);
1127 #endif
1129 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1130 adc_battery_voltage % 1000, adc_battery_level);
1131 lcd_puts(0, line++, buf);
1133 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1134 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1135 lcd_puts(0, line++, buf);
1136 #endif
1138 lcd_update();
1139 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1140 return false;
1143 #elif defined(CPU_PP502x)
1145 char buf[128];
1146 int line;
1148 lcd_clear_display();
1149 lcd_setfont(FONT_SYSFIXED);
1151 while(1)
1153 line = 0;
1154 lcd_puts(0, line++, "GPIO STATES:");
1155 snprintf(buf, sizeof(buf), "A: %02x E: %02x I: %02x",
1156 (unsigned int)GPIOA_INPUT_VAL,
1157 (unsigned int)GPIOE_INPUT_VAL,
1158 (unsigned int)GPIOI_INPUT_VAL);
1159 lcd_puts(0, line++, buf);
1160 snprintf(buf, sizeof(buf), "B: %02x F: %02x J: %02x",
1161 (unsigned int)GPIOB_INPUT_VAL,
1162 (unsigned int)GPIOF_INPUT_VAL,
1163 (unsigned int)GPIOJ_INPUT_VAL);
1164 lcd_puts(0, line++, buf);
1165 snprintf(buf, sizeof(buf), "C: %02x G: %02x K: %02x",
1166 (unsigned int)GPIOC_INPUT_VAL,
1167 (unsigned int)GPIOG_INPUT_VAL,
1168 (unsigned int)GPIOK_INPUT_VAL);
1169 lcd_puts(0, line++, buf);
1170 snprintf(buf, sizeof(buf), "D: %02x H: %02x L: %02x",
1171 (unsigned int)GPIOD_INPUT_VAL,
1172 (unsigned int)GPIOH_INPUT_VAL,
1173 (unsigned int)GPIOL_INPUT_VAL);
1174 lcd_puts(0, line++, buf);
1175 line++;
1176 snprintf(buf, sizeof(buf), "GPO32_VAL: %08lx", GPO32_VAL);
1177 lcd_puts(0, line++, buf);
1178 snprintf(buf, sizeof(buf), "GPO32_EN: %08lx", GPO32_ENABLE);
1179 lcd_puts(0, line++, buf);
1180 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1181 lcd_puts(0, line++, buf);
1182 snprintf(buf, sizeof(buf), "DEV_EN2: %08lx", DEV_EN2);
1183 lcd_puts(0, line++, buf);
1184 snprintf(buf, sizeof(buf), "DEV_EN3: %08lx", inl(0x60006044));
1185 lcd_puts(0, line++, buf); /* to be verified */
1186 snprintf(buf, sizeof(buf), "DEV_INIT1: %08lx", DEV_INIT1);
1187 lcd_puts(0, line++, buf);
1188 snprintf(buf, sizeof(buf), "DEV_INIT2: %08lx", DEV_INIT2);
1189 lcd_puts(0, line++, buf);
1190 #ifdef ADC_ACCESSORY
1191 snprintf(buf, sizeof(buf), "ACCESSORY: %d", adc_read(ADC_ACCESSORY));
1192 lcd_puts(0, line++, buf);
1193 #endif
1195 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1196 line++;
1197 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1198 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1199 lcd_puts(0, line++, buf);
1200 snprintf(buf, sizeof(buf), "REM: %03x PAD: %03x",
1201 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1202 lcd_puts(0, line++, buf);
1203 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1204 snprintf(buf, sizeof(buf), "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1205 lcd_puts(0, line++, buf);
1206 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1207 lcd_puts(0, line++, buf);
1208 snprintf(buf, sizeof(buf), "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1209 lcd_puts(0, line++, buf);
1210 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1211 lcd_puts(0, line++, buf);
1212 snprintf(buf, sizeof(buf), "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1213 lcd_puts(0, line++, buf);
1214 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1215 lcd_puts(0, line++, buf);
1216 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1217 lcd_puts(0, line++, buf);
1218 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1219 lcd_puts(0, line++, buf);
1220 snprintf(buf, sizeof(buf), "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1221 lcd_puts(0, line++, buf);
1222 snprintf(buf, sizeof(buf), "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1223 lcd_puts(0, line++, buf);
1224 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1225 lcd_puts(0, line++, buf);
1226 #if !defined(PHILIPS_SA9200)
1227 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1228 lcd_puts(0, line++, buf);
1229 snprintf(buf, sizeof(buf), "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1230 lcd_puts(0, line++, buf);
1231 snprintf(buf, sizeof(buf), "CHARGER: %02X/%02X", i2c_readbyte(AS3514_I2C_ADDR, AS3514_CHARGER), i2c_readbyte(AS3514_I2C_ADDR, AS3514_IRQ_ENRD0));
1232 lcd_puts(0, line++, buf);
1233 #endif
1234 #endif
1235 lcd_update();
1236 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1237 return false;
1240 #elif CONFIG_CPU == PP5002
1241 char buf[128];
1242 int line;
1244 lcd_clear_display();
1245 lcd_setfont(FONT_SYSFIXED);
1247 while(1)
1249 line = 0;
1250 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x",
1251 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1252 lcd_puts(0, line++, buf);
1253 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x",
1254 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1255 lcd_puts(0, line++, buf);
1257 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1258 lcd_puts(0, line++, buf);
1259 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1260 lcd_puts(0, line++, buf);
1261 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1262 lcd_puts(0, line++, buf);
1263 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1264 lcd_puts(0, line++, buf);
1265 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1266 lcd_puts(0, line++, buf);
1267 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1268 lcd_puts(0, line++, buf);
1269 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1270 lcd_puts(0, line++, buf);
1271 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1272 lcd_puts(0, line++, buf);
1274 lcd_update();
1275 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1276 return false;
1278 #else
1279 return __dbg_ports();
1280 #endif /* CPU */
1281 return false;
1283 #else /* !HAVE_LCD_BITMAP */
1284 bool dbg_ports(void)
1286 char buf[32];
1287 int button;
1288 int adc_battery_voltage;
1289 int currval = 0;
1291 lcd_clear_display();
1293 while(1)
1295 switch(currval)
1297 case 0:
1298 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1299 break;
1300 case 1:
1301 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1302 break;
1303 case 2:
1304 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1305 break;
1306 case 3:
1307 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1308 break;
1309 case 4:
1310 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1311 break;
1312 case 5:
1313 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1314 break;
1315 case 6:
1316 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1317 break;
1318 case 7:
1319 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1320 break;
1321 case 8:
1322 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1323 break;
1324 case 9:
1325 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1326 break;
1327 break;
1329 lcd_puts(0, 0, buf);
1331 battery_read_info(&adc_battery_voltage, NULL);
1332 snprintf(buf, 32, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1333 adc_battery_voltage % 1000);
1334 lcd_puts(0, 1, buf);
1335 lcd_update();
1337 button = get_action(CONTEXT_SETTINGS,HZ/5);
1339 switch(button)
1341 case ACTION_STD_CANCEL:
1342 return false;
1344 case ACTION_SETTINGS_DEC:
1345 currval--;
1346 if(currval < 0)
1347 currval = 9;
1348 break;
1350 case ACTION_SETTINGS_INC:
1351 currval++;
1352 if(currval > 9)
1353 currval = 0;
1354 break;
1357 return false;
1359 #endif /* !HAVE_LCD_BITMAP */
1360 #endif /* !SIMULATOR */
1362 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1363 static bool dbg_pcf(void)
1365 char buf[128];
1366 int line;
1368 #ifdef HAVE_LCD_BITMAP
1369 lcd_setfont(FONT_SYSFIXED);
1370 #endif
1371 lcd_clear_display();
1373 while(1)
1375 line = 0;
1377 snprintf(buf, sizeof(buf), "DCDC1: %02x", pcf50605_read(0x1b));
1378 lcd_puts(0, line++, buf);
1379 snprintf(buf, sizeof(buf), "DCDC2: %02x", pcf50605_read(0x1c));
1380 lcd_puts(0, line++, buf);
1381 snprintf(buf, sizeof(buf), "DCDC3: %02x", pcf50605_read(0x1d));
1382 lcd_puts(0, line++, buf);
1383 snprintf(buf, sizeof(buf), "DCDC4: %02x", pcf50605_read(0x1e));
1384 lcd_puts(0, line++, buf);
1385 snprintf(buf, sizeof(buf), "DCDEC1: %02x", pcf50605_read(0x1f));
1386 lcd_puts(0, line++, buf);
1387 snprintf(buf, sizeof(buf), "DCDEC2: %02x", pcf50605_read(0x20));
1388 lcd_puts(0, line++, buf);
1389 snprintf(buf, sizeof(buf), "DCUDC1: %02x", pcf50605_read(0x21));
1390 lcd_puts(0, line++, buf);
1391 snprintf(buf, sizeof(buf), "DCUDC2: %02x", pcf50605_read(0x22));
1392 lcd_puts(0, line++, buf);
1393 snprintf(buf, sizeof(buf), "IOREGC: %02x", pcf50605_read(0x23));
1394 lcd_puts(0, line++, buf);
1395 snprintf(buf, sizeof(buf), "D1REGC: %02x", pcf50605_read(0x24));
1396 lcd_puts(0, line++, buf);
1397 snprintf(buf, sizeof(buf), "D2REGC: %02x", pcf50605_read(0x25));
1398 lcd_puts(0, line++, buf);
1399 snprintf(buf, sizeof(buf), "D3REGC: %02x", pcf50605_read(0x26));
1400 lcd_puts(0, line++, buf);
1401 snprintf(buf, sizeof(buf), "LPREG1: %02x", pcf50605_read(0x27));
1402 lcd_puts(0, line++, buf);
1404 lcd_update();
1405 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1407 return false;
1411 return false;
1413 #endif
1415 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1416 static bool dbg_cpufreq(void)
1418 char buf[128];
1419 int line;
1420 int button;
1422 #ifdef HAVE_LCD_BITMAP
1423 lcd_setfont(FONT_SYSFIXED);
1424 #endif
1425 lcd_clear_display();
1427 while(1)
1429 line = 0;
1431 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1432 lcd_puts(0, line++, buf);
1434 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1435 lcd_puts(0, line++, buf);
1437 lcd_update();
1438 button = get_action(CONTEXT_STD,HZ/10);
1440 switch(button)
1442 case ACTION_STD_PREV:
1443 cpu_boost(true);
1444 break;
1446 case ACTION_STD_NEXT:
1447 cpu_boost(false);
1448 break;
1450 case ACTION_STD_OK:
1451 while (get_cpu_boost_counter() > 0)
1452 cpu_boost(false);
1453 set_cpu_frequency(CPUFREQ_DEFAULT);
1454 break;
1456 case ACTION_STD_CANCEL:
1457 return false;
1461 return false;
1463 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1465 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1466 #include "tsc2100.h"
1467 char *itob(int n, int len)
1469 static char binary[64];
1470 int i,j;
1471 for (i=1, j=0;i<=len;i++)
1473 binary[j++] = n&(1<<(len-i))?'1':'0';
1474 if (i%4 == 0)
1475 binary[j++] = ' ';
1477 binary[j] = '\0';
1478 return binary;
1480 static char* tsc2100_debug_getname(int selected_item, void * data,
1481 char *buffer, size_t buffer_len)
1483 int *page = (int*)data;
1484 bool reserved = false;
1485 switch (*page)
1487 case 0:
1488 if ((selected_item > 0x0a) ||
1489 (selected_item == 0x04) ||
1490 (selected_item == 0x08))
1491 reserved = true;
1492 break;
1493 case 1:
1494 if ((selected_item > 0x05) ||
1495 (selected_item == 0x02))
1496 reserved = true;
1497 break;
1498 case 2:
1499 if (selected_item > 0x1e)
1500 reserved = true;
1501 break;
1503 if (reserved)
1504 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1505 else
1506 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1507 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1508 return buffer;
1510 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1512 int *page = (int*)lists->data;
1513 if (action == ACTION_STD_OK)
1515 *page = (*page+1)%3;
1516 snprintf(lists->title, 32,
1517 "tsc2100 registers - Page %d", *page);
1518 return ACTION_REDRAW;
1520 return action;
1522 bool tsc2100_debug(void)
1524 int page = 0;
1525 char title[32] = "tsc2100 registers - Page 0";
1526 struct simplelist_info info;
1527 simplelist_info_init(&info, title, 32, &page);
1528 info.timeout = HZ/100;
1529 info.get_name = tsc2100_debug_getname;
1530 info.action_callback= tsc2100debug_action_callback;
1531 return simplelist_show_list(&info);
1533 #endif
1534 #ifndef SIMULATOR
1535 #ifdef HAVE_LCD_BITMAP
1537 * view_battery() shows a automatically scaled graph of the battery voltage
1538 * over time. Usable for estimating battery life / charging rate.
1539 * The power_history array is updated in power_thread of powermgmt.c.
1542 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1543 #define BAT_YSPACE (LCD_HEIGHT - 20)
1545 static bool view_battery(void)
1547 int view = 0;
1548 int i, x, y;
1549 unsigned short maxv, minv;
1550 char buf[32];
1552 lcd_setfont(FONT_SYSFIXED);
1554 while(1)
1556 lcd_clear_display();
1557 switch (view) {
1558 case 0: /* voltage history graph */
1559 /* Find maximum and minimum voltage for scaling */
1560 minv = power_history[0];
1561 maxv = minv + 1;
1562 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1563 if (power_history[i] > maxv)
1564 maxv = power_history[i];
1565 if (power_history[i] < minv)
1566 minv = power_history[i];
1569 snprintf(buf, 30, "Battery %d.%03d", power_history[0] / 1000,
1570 power_history[0] % 1000);
1571 lcd_puts(0, 0, buf);
1572 snprintf(buf, 30, "scale %d.%03d-%d.%03dV",
1573 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1574 lcd_puts(0, 1, buf);
1576 x = 0;
1577 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1578 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1579 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1580 lcd_vline(x, LCD_HEIGHT-1, 20);
1581 lcd_set_drawmode(DRMODE_SOLID);
1582 lcd_vline(x, LCD_HEIGHT-1,
1583 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1584 x++;
1587 break;
1589 case 1: /* status: */
1590 lcd_puts(0, 0, "Power status:");
1592 battery_read_info(&y, NULL);
1593 snprintf(buf, 30, "Battery: %d.%03d V", y / 1000, y % 1000);
1594 lcd_puts(0, 1, buf);
1595 #ifdef ADC_EXT_POWER
1596 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1597 snprintf(buf, 30, "External: %d.%03d V", y / 1000, y % 1000);
1598 lcd_puts(0, 2, buf);
1599 #endif
1600 #if CONFIG_CHARGING
1601 #if CONFIG_CHARGING == CHARGING_CONTROL
1602 snprintf(buf, 30, "Chgr: %s %s",
1603 charger_inserted() ? "present" : "absent",
1604 charger_enabled ? "on" : "off");
1605 lcd_puts(0, 3, buf);
1606 snprintf(buf, 30, "short delta: %d", short_delta);
1607 lcd_puts(0, 5, buf);
1608 snprintf(buf, 30, "long delta: %d", long_delta);
1609 lcd_puts(0, 6, buf);
1610 lcd_puts(0, 7, power_message);
1611 snprintf(buf, 30, "USB Inserted: %s",
1612 usb_inserted() ? "yes" : "no");
1613 lcd_puts(0, 8, buf);
1614 #if defined IRIVER_H300_SERIES
1615 snprintf(buf, 30, "USB Charging Enabled: %s",
1616 usb_charging_enabled() ? "yes" : "no");
1617 lcd_puts(0, 9, buf);
1618 #endif
1619 #else /* CONFIG_CHARGING != CHARGING_CONTROL */
1620 #if defined IPOD_NANO || defined IPOD_VIDEO
1621 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1622 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1623 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1624 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1625 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1627 snprintf(buf, 30, "USB pwr: %s",
1628 usb_pwr ? "present" : "absent");
1629 lcd_puts(0, 3, buf);
1630 snprintf(buf, 30, "EXT pwr: %s",
1631 ext_pwr ? "present" : "absent");
1632 lcd_puts(0, 4, buf);
1633 snprintf(buf, 30, "Battery: %s",
1634 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1635 lcd_puts(0, 5, buf);
1636 snprintf(buf, 30, "Dock mode: %s",
1637 dock ? "enabled" : "disabled");
1638 lcd_puts(0, 6, buf);
1639 snprintf(buf, 30, "Headphone: %s",
1640 headphone ? "connected" : "disconnected");
1641 lcd_puts(0, 7, buf);
1642 #else
1643 snprintf(buf, 30, "Charger: %s",
1644 charger_inserted() ? "present" : "absent");
1645 lcd_puts(0, 3, buf);
1646 #if defined TOSHIBA_GIGABEAT_S
1647 y = battery_adc_charge_current();
1648 x = y < 0 ? '-' : ' ';
1649 y = abs(y);
1650 snprintf(buf, 30, "I Charge:%c%d.%03d A", (char)x, y / 1000, y % 1000);
1651 lcd_puts(0, 4, buf);
1653 y = battery_adc_temp();
1654 snprintf(buf, 30, "T Battery: %dC (%dF)", y, (9*y + 160) / 5);
1655 lcd_puts(0, 5, buf);
1656 #endif /* defined TOSHIBA_GIGABEAT_S */
1657 #endif /* defined IPOD_NANO || defined IPOD_VIDEO */
1658 #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1659 #endif /* CONFIG_CHARGING */
1660 break;
1662 case 2: /* voltage deltas: */
1663 lcd_puts(0, 0, "Voltage deltas:");
1665 for (i = 0; i <= 6; i++) {
1666 y = power_history[i] - power_history[i+1];
1667 snprintf(buf, 30, "-%d min: %s%d.%03d V", i,
1668 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1669 ((y < 0) ? y * -1 : y ) % 1000);
1670 lcd_puts(0, i+1, buf);
1672 break;
1674 case 3: /* remaining time estimation: */
1676 #if CONFIG_CHARGING == CHARGING_CONTROL
1677 snprintf(buf, 30, "charge_state: %d", charge_state);
1678 lcd_puts(0, 0, buf);
1680 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1681 lcd_puts(0, 1, buf);
1683 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1684 lcd_puts(0, 2, buf);
1686 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1687 lcd_puts(0, 3, buf);
1689 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1690 lcd_puts(0, 4, buf);
1691 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
1693 snprintf(buf, 30, "Last PwrHist: %d.%03dV",
1694 power_history[0] / 1000,
1695 power_history[0] % 1000);
1696 lcd_puts(0, 5, buf);
1698 snprintf(buf, 30, "battery level: %d%%", battery_level());
1699 lcd_puts(0, 6, buf);
1701 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1702 lcd_puts(0, 7, buf);
1703 break;
1706 lcd_update();
1708 switch(get_action(CONTEXT_STD,HZ/2))
1710 case ACTION_STD_PREV:
1711 if (view)
1712 view--;
1713 break;
1715 case ACTION_STD_NEXT:
1716 if (view < 3)
1717 view++;
1718 break;
1720 case ACTION_STD_CANCEL:
1721 return false;
1724 return false;
1727 #endif /* HAVE_LCD_BITMAP */
1728 #endif
1730 #ifndef SIMULATOR
1731 #if defined(HAVE_MMC) || defined(HAVE_ATA_SD)
1732 #if defined(HAVE_MMC)
1733 #define CARDTYPE "MMC"
1734 #else
1735 #define CARDTYPE "microSD"
1736 #endif
1737 static int disk_callback(int btn, struct gui_synclist *lists)
1739 tCardInfo *card;
1740 int *cardnum = (int*)lists->data;
1741 unsigned char card_name[7];
1742 unsigned char pbuf[32];
1743 char *title = lists->title;
1744 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1745 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1746 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1747 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1748 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1749 "3.1-3.31", "4.0" };
1750 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1752 #ifdef HAVE_HOTSWAP
1753 if (btn == ACTION_STD_OK)
1755 *cardnum ^= 0x1; /* change cards */
1757 #endif
1759 simplelist_set_line_count(0);
1761 card = card_get_info(*cardnum);
1763 if (card->initialized > 0)
1765 card_name[6] = '\0';
1766 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1767 simplelist_addline(SIMPLELIST_ADD_LINE,
1768 "%s Rev %d.%d", card_name,
1769 (int) card_extract_bits(card->cid, 72, 4),
1770 (int) card_extract_bits(card->cid, 76, 4));
1771 simplelist_addline(SIMPLELIST_ADD_LINE,
1772 "Prod: %d/%d",
1773 (int) card_extract_bits(card->cid, 112, 4),
1774 (int) card_extract_bits(card->cid, 116, 4) + 1997);
1775 simplelist_addline(SIMPLELIST_ADD_LINE,
1776 "Ser#: 0x%08lx",
1777 card_extract_bits(card->cid, 80, 32));
1778 simplelist_addline(SIMPLELIST_ADD_LINE,
1779 "M=%02x, O=%04x",
1780 (int) card_extract_bits(card->cid, 0, 8),
1781 (int) card_extract_bits(card->cid, 8, 16));
1782 int temp = card_extract_bits(card->csd, 2, 4);
1783 simplelist_addline(SIMPLELIST_ADD_LINE,
1784 CARDTYPE " v%s", temp < 5 ?
1785 spec_vers[temp] : "?.?");
1786 simplelist_addline(SIMPLELIST_ADD_LINE,
1787 "Blocks: 0x%06lx", card->numblocks);
1788 simplelist_addline(SIMPLELIST_ADD_LINE,
1789 "Blksz.: %d P:%c%c", card->blocksize,
1790 card_extract_bits(card->csd, 48, 1) ? 'R' : '-',
1791 card_extract_bits(card->csd, 106, 1) ? 'W' : '-');
1792 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1793 kbit_units, false);
1794 simplelist_addline(SIMPLELIST_ADD_LINE,
1795 "Speed: %s", pbuf);
1796 output_dyn_value(pbuf, sizeof pbuf, card->tsac,
1797 nsec_units, false);
1798 simplelist_addline(SIMPLELIST_ADD_LINE,
1799 "Tsac: %s", pbuf);
1800 simplelist_addline(SIMPLELIST_ADD_LINE,
1801 "Nsac: %d clk", card->nsac);
1802 simplelist_addline(SIMPLELIST_ADD_LINE,
1803 "R2W: *%d", card->r2w_factor);
1804 simplelist_addline(SIMPLELIST_ADD_LINE,
1805 "IRmax: %d..%d mA",
1806 i_vmin[card_extract_bits(card->csd, 66, 3)],
1807 i_vmax[card_extract_bits(card->csd, 69, 3)]);
1808 simplelist_addline(SIMPLELIST_ADD_LINE,
1809 "IWmax: %d..%d mA",
1810 i_vmin[card_extract_bits(card->csd, 72, 3)],
1811 i_vmax[card_extract_bits(card->csd, 75, 3)]);
1813 else if (card->initialized == 0)
1815 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1817 #ifndef HAVE_MMC
1818 else /* card->initialized < 0 */
1820 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1822 #endif
1823 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1824 gui_synclist_set_title(lists, title, Icon_NOICON);
1825 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1826 gui_synclist_select_item(lists, 0);
1827 btn = ACTION_REDRAW;
1829 return btn;
1831 #else /* !defined(HAVE_MMC) && !defined(HAVE_ATA_SD) */
1832 static int disk_callback(int btn, struct gui_synclist *lists)
1834 (void)lists;
1835 int i;
1836 char buf[128];
1837 unsigned short* identify_info = ata_get_identify();
1838 bool timing_info_present = false;
1839 (void)btn;
1841 simplelist_set_line_count(0);
1843 for (i=0; i < 20; i++)
1844 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1845 buf[40]=0;
1846 /* kill trailing space */
1847 for (i=39; i && buf[i]==' '; i--)
1848 buf[i] = 0;
1849 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1850 for (i=0; i < 4; i++)
1851 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1852 buf[8]=0;
1853 simplelist_addline(SIMPLELIST_ADD_LINE,
1854 "Firmware: %s", buf);
1855 snprintf(buf, sizeof buf, "%ld MB",
1856 ((unsigned long)identify_info[61] << 16 |
1857 (unsigned long)identify_info[60]) / 2048 );
1858 simplelist_addline(SIMPLELIST_ADD_LINE,
1859 "Size: %s", buf);
1860 unsigned long free;
1861 fat_size( IF_MV2(0,) NULL, &free );
1862 simplelist_addline(SIMPLELIST_ADD_LINE,
1863 "Free: %ld MB", free / 1024);
1864 simplelist_addline(SIMPLELIST_ADD_LINE,
1865 "Spinup time: %d ms", ata_spinup_time * (1000/HZ));
1866 i = identify_info[83] & (1<<3);
1867 simplelist_addline(SIMPLELIST_ADD_LINE,
1868 "Power mgmt: %s", i ? "enabled" : "unsupported");
1869 i = identify_info[83] & (1<<9);
1870 simplelist_addline(SIMPLELIST_ADD_LINE,
1871 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1872 i = identify_info[82] & (1<<6);
1873 simplelist_addline(SIMPLELIST_ADD_LINE,
1874 "Read-ahead: %s", i ? "enabled" : "unsupported");
1875 timing_info_present = identify_info[53] & (1<<1);
1876 if(timing_info_present) {
1877 char pio3[2], pio4[2];pio3[1] = 0;
1878 pio4[1] = 0;
1879 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1880 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1881 simplelist_addline(SIMPLELIST_ADD_LINE,
1882 "PIO modes: 0 1 2 %s %s", pio3, pio4);
1884 else {
1885 simplelist_addline(SIMPLELIST_ADD_LINE,
1886 "No PIO mode info");
1888 timing_info_present = identify_info[53] & (1<<1);
1889 if(timing_info_present) {
1890 simplelist_addline(SIMPLELIST_ADD_LINE,
1891 "Cycle times %dns/%dns",
1892 identify_info[67],
1893 identify_info[68] );
1894 } else {
1895 simplelist_addline(SIMPLELIST_ADD_LINE,
1896 "No timing info");
1898 #if defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S)
1899 if (identify_info[63] & (1<<0)) {
1900 char mdma0[2], mdma1[2], mdma2[2];
1901 mdma0[1] = mdma1[1] = mdma2[1] = 0;
1902 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
1903 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
1904 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
1905 simplelist_addline(SIMPLELIST_ADD_LINE,
1906 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
1907 simplelist_addline(SIMPLELIST_ADD_LINE,
1908 "MDMA Cycle times %dns/%dns",
1909 identify_info[65],
1910 identify_info[66] );
1912 else {
1913 simplelist_addline(SIMPLELIST_ADD_LINE,
1914 "No MDMA mode info");
1916 if (identify_info[88] & (1<<0)) {
1917 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2];
1918 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = 0;
1919 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
1920 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
1921 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
1922 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
1923 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
1924 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
1925 simplelist_addline(SIMPLELIST_ADD_LINE,
1926 "UDMA modes: %s %s %s %s %s %s", udma0, udma1, udma2,
1927 udma3, udma4, udma5);
1929 else {
1930 simplelist_addline(SIMPLELIST_ADD_LINE,
1931 "No UDMA mode info");
1933 #endif /* defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S) */
1934 timing_info_present = identify_info[53] & (1<<1);
1935 if(timing_info_present) {
1936 i = identify_info[49] & (1<<11);
1937 simplelist_addline(SIMPLELIST_ADD_LINE,
1938 "IORDY support: %s", i ? "yes" : "no");
1939 i = identify_info[49] & (1<<10);
1940 simplelist_addline(SIMPLELIST_ADD_LINE,
1941 "IORDY disable: %s", i ? "yes" : "no");
1942 } else {
1943 simplelist_addline(SIMPLELIST_ADD_LINE,
1944 "No timing info");
1946 simplelist_addline(SIMPLELIST_ADD_LINE,
1947 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1948 return btn;
1951 static bool dbg_identify_info(void)
1953 int fd = creat("/identify_info.bin");
1954 if(fd >= 0)
1956 #ifdef ROCKBOX_LITTLE_ENDIAN
1957 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
1958 #else
1959 write(fd, ata_get_identify(), SECTOR_SIZE);
1960 #endif
1961 close(fd);
1963 return false;
1965 #endif /* !defined(HAVE_MMC) && !defined(HAVE_ATA_SD) */
1967 static bool dbg_disk_info(void)
1969 struct simplelist_info info;
1970 simplelist_info_init(&info, "Disk Info", 1, NULL);
1971 #if defined(HAVE_MMC) || defined(HAVE_ATA_SD)
1972 char title[16];
1973 int card = 0;
1974 info.callback_data = (void*)&card;
1975 info.title = title;
1976 #endif
1977 info.action_callback = disk_callback;
1978 info.hide_selection = true;
1979 info.scroll_all = true;
1980 return simplelist_show_list(&info);
1982 #endif /* !SIMULATOR */
1984 #ifdef HAVE_DIRCACHE
1985 static int dircache_callback(int btn, struct gui_synclist *lists)
1987 (void)btn; (void)lists;
1988 simplelist_set_line_count(0);
1989 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
1990 dircache_is_enabled() ? "Yes" : "No");
1991 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
1992 dircache_get_cache_size());
1993 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
1994 global_status.dircache_size);
1995 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
1996 DIRCACHE_LIMIT);
1997 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
1998 dircache_get_reserve_used(), DIRCACHE_RESERVE);
1999 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2000 dircache_get_build_ticks() / HZ);
2001 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2002 dircache_get_entry_count());
2003 return btn;
2006 static bool dbg_dircache_info(void)
2008 struct simplelist_info info;
2009 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2010 info.action_callback = dircache_callback;
2011 info.hide_selection = true;
2012 info.scroll_all = true;
2013 return simplelist_show_list(&info);
2016 #endif /* HAVE_DIRCACHE */
2018 #ifdef HAVE_TAGCACHE
2019 static int database_callback(int btn, struct gui_synclist *lists)
2021 (void)lists;
2022 struct tagcache_stat *stat = tagcache_get_stat();
2023 static bool synced = false;
2025 simplelist_set_line_count(0);
2027 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2028 stat->initialized ? "Yes" : "No");
2029 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2030 stat->ready ? "Yes" : "No");
2031 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2032 stat->ramcache ? "Yes" : "No");
2033 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2034 stat->ramcache_used, stat->ramcache_allocated);
2035 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2036 stat->progress, stat->processed_entries);
2037 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2038 stat->curentry ? stat->curentry : "---");
2039 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2040 stat->commit_step);
2041 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2042 stat->commit_delayed ? "Yes" : "No");
2044 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2045 stat->queue_length);
2047 if (synced)
2049 synced = false;
2050 tagcache_screensync_event();
2053 if (!btn && stat->curentry)
2055 synced = true;
2056 return ACTION_REDRAW;
2059 if (btn == ACTION_STD_CANCEL)
2060 tagcache_screensync_enable(false);
2062 return btn;
2064 static bool dbg_tagcache_info(void)
2066 struct simplelist_info info;
2067 simplelist_info_init(&info, "Database Info", 8, NULL);
2068 info.action_callback = database_callback;
2069 info.hide_selection = true;
2070 info.scroll_all = true;
2072 /* Don't do nonblock here, must give enough processing time
2073 for tagcache thread. */
2074 /* info.timeout = TIMEOUT_NOBLOCK; */
2075 info.timeout = 1;
2076 tagcache_screensync_enable(true);
2077 return simplelist_show_list(&info);
2079 #endif
2081 #if CONFIG_CPU == SH7034
2082 static bool dbg_save_roms(void)
2084 int fd;
2085 int oldmode = system_memory_guard(MEMGUARD_NONE);
2087 fd = creat("/internal_rom_0000-FFFF.bin");
2088 if(fd >= 0)
2090 write(fd, (void *)0, 0x10000);
2091 close(fd);
2094 fd = creat("/internal_rom_2000000-203FFFF.bin");
2095 if(fd >= 0)
2097 write(fd, (void *)0x2000000, 0x40000);
2098 close(fd);
2101 system_memory_guard(oldmode);
2102 return false;
2104 #elif defined CPU_COLDFIRE
2105 static bool dbg_save_roms(void)
2107 int fd;
2108 int oldmode = system_memory_guard(MEMGUARD_NONE);
2110 #if defined(IRIVER_H100_SERIES)
2111 fd = creat("/internal_rom_000000-1FFFFF.bin");
2112 #elif defined(IRIVER_H300_SERIES)
2113 fd = creat("/internal_rom_000000-3FFFFF.bin");
2114 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2115 fd = creat("/internal_rom_000000-3FFFFF.bin");
2116 #endif
2117 if(fd >= 0)
2119 write(fd, (void *)0, FLASH_SIZE);
2120 close(fd);
2122 system_memory_guard(oldmode);
2124 #ifdef HAVE_EEPROM
2125 fd = creat("/internal_eeprom.bin");
2126 if (fd >= 0)
2128 int old_irq_level;
2129 char buf[EEPROM_SIZE];
2130 int err;
2132 old_irq_level = disable_irq_save();
2134 err = eeprom_24cxx_read(0, buf, sizeof buf);
2136 restore_irq(old_irq_level);
2138 if (err)
2139 gui_syncsplash(HZ*3, "Eeprom read failure (%d)",err);
2140 else
2142 write(fd, buf, sizeof buf);
2145 close(fd);
2147 #endif
2149 return false;
2151 #elif defined(CPU_PP) && !defined(HAVE_ATA_SD)
2152 static bool dbg_save_roms(void)
2154 int fd;
2156 fd = creat("/internal_rom_000000-0FFFFF.bin");
2157 if(fd >= 0)
2159 write(fd, (void *)0x20000000, FLASH_SIZE);
2160 close(fd);
2163 return false;
2165 #endif /* CPU */
2167 #ifndef SIMULATOR
2168 #if CONFIG_TUNER
2169 static int radio_callback(int btn, struct gui_synclist *lists)
2171 (void)lists;
2172 if (btn == ACTION_STD_CANCEL)
2173 return btn;
2174 simplelist_set_line_count(1);
2176 #if (CONFIG_TUNER & LV24020LP)
2177 simplelist_addline(SIMPLELIST_ADD_LINE,
2178 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2179 simplelist_addline(SIMPLELIST_ADD_LINE,
2180 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2181 simplelist_addline(SIMPLELIST_ADD_LINE,
2182 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2183 simplelist_addline(SIMPLELIST_ADD_LINE,
2184 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2185 simplelist_addline(SIMPLELIST_ADD_LINE,
2186 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2187 simplelist_addline(SIMPLELIST_ADD_LINE,
2188 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2189 simplelist_addline(SIMPLELIST_ADD_LINE,
2190 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2191 #endif
2192 #if (CONFIG_TUNER & S1A0903X01)
2193 simplelist_addline(SIMPLELIST_ADD_LINE,
2194 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2195 /* This one doesn't return dynamic data atm */
2196 #endif
2197 #if (CONFIG_TUNER & TEA5767)
2198 struct tea5767_dbg_info nfo;
2199 tea5767_dbg_info(&nfo);
2200 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2201 simplelist_addline(SIMPLELIST_ADD_LINE,
2202 " Read: %02X %02X %02X %02X %02X",
2203 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2204 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2205 (unsigned)nfo.read_regs[4]);
2206 simplelist_addline(SIMPLELIST_ADD_LINE,
2207 " Write: %02X %02X %02X %02X %02X",
2208 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2209 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2210 (unsigned)nfo.write_regs[4]);
2211 #endif
2212 return ACTION_REDRAW;
2214 static bool dbg_fm_radio(void)
2216 struct simplelist_info info;
2217 info.scroll_all = true;
2218 simplelist_info_init(&info, "FM Radio", 1, NULL);
2219 simplelist_set_line_count(0);
2220 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2221 radio_hardware_present() ? "yes" : "no");
2223 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2224 info.hide_selection = true;
2225 return simplelist_show_list(&info);
2227 #endif /* CONFIG_TUNER */
2228 #endif /* !SIMULATOR */
2230 #ifdef HAVE_LCD_BITMAP
2231 extern bool do_screendump_instead_of_usb;
2233 static bool dbg_screendump(void)
2235 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2236 gui_syncsplash(HZ, "Screendump %s",
2237 do_screendump_instead_of_usb?"enabled":"disabled");
2238 return false;
2240 #endif /* HAVE_LCD_BITMAP */
2242 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2243 static bool dbg_set_memory_guard(void)
2245 static const struct opt_items names[MAXMEMGUARD] = {
2246 { "None", -1 },
2247 { "Flash ROM writes", -1 },
2248 { "Zero area (all)", -1 }
2250 int mode = system_memory_guard(MEMGUARD_KEEP);
2252 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2253 system_memory_guard(mode);
2255 return false;
2257 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2259 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2260 static bool dbg_write_eeprom(void)
2262 int fd;
2263 int rc;
2264 int old_irq_level;
2265 char buf[EEPROM_SIZE];
2266 int err;
2268 fd = open("/internal_eeprom.bin", O_RDONLY);
2270 if (fd >= 0)
2272 rc = read(fd, buf, EEPROM_SIZE);
2274 if(rc == EEPROM_SIZE)
2276 old_irq_level = disable_irq_save();
2278 err = eeprom_24cxx_write(0, buf, sizeof buf);
2279 if (err)
2280 gui_syncsplash(HZ*3, "Eeprom write failure (%d)",err);
2281 else
2282 gui_syncsplash(HZ*3, "Eeprom written successfully");
2284 restore_irq(old_irq_level);
2286 else
2288 gui_syncsplash(HZ*3, "File read error (%d)",rc);
2290 close(fd);
2292 else
2294 gui_syncsplash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2297 return false;
2299 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2300 #ifdef CPU_BOOST_LOGGING
2301 static bool cpu_boost_log(void)
2303 int i = 0,j=0;
2304 int count = cpu_boost_log_getcount();
2305 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2306 char *str;
2307 bool done;
2308 lcd_setfont(FONT_SYSFIXED);
2309 str = cpu_boost_log_getlog_first();
2310 while (i < count)
2312 lcd_clear_display();
2313 for(j=0; j<lines; j++,i++)
2315 if (!str)
2316 str = cpu_boost_log_getlog_next();
2317 if (str)
2319 lcd_puts(0, j,str);
2321 str = NULL;
2323 lcd_update();
2324 done = false;
2325 while (!done)
2327 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2329 case ACTION_STD_OK:
2330 case ACTION_STD_PREV:
2331 case ACTION_STD_NEXT:
2332 done = true;
2333 break;
2334 case ACTION_STD_CANCEL:
2335 i = count;
2336 done = true;
2337 break;
2341 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2342 lcd_setfont(FONT_UI);
2343 return false;
2345 #endif
2347 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2348 extern bool wheel_is_touched;
2349 extern int old_wheel_value;
2350 extern int new_wheel_value;
2351 extern int wheel_delta;
2352 extern unsigned int accumulated_wheel_delta;
2353 extern unsigned int wheel_velocity;
2355 static bool dbg_scrollwheel(void)
2357 char buf[64];
2358 unsigned int speed;
2360 lcd_setfont(FONT_SYSFIXED);
2362 while (1)
2364 if (action_userabort(HZ/10))
2365 return false;
2367 lcd_clear_display();
2369 /* show internal variables of scrollwheel driver */
2370 snprintf(buf, sizeof(buf), "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2371 lcd_puts(0, 0, buf);
2372 snprintf(buf, sizeof(buf), "new position: %2d", new_wheel_value);
2373 lcd_puts(0, 1, buf);
2374 snprintf(buf, sizeof(buf), "old position: %2d", old_wheel_value);
2375 lcd_puts(0, 2, buf);
2376 snprintf(buf, sizeof(buf), "wheel delta: %2d", wheel_delta);
2377 lcd_puts(0, 3, buf);
2378 snprintf(buf, sizeof(buf), "accumulated delta: %2d", accumulated_wheel_delta);
2379 lcd_puts(0, 4, buf);
2380 snprintf(buf, sizeof(buf), "velo [deg/s]: %4d", (int)wheel_velocity);
2381 lcd_puts(0, 5, buf);
2383 /* show effective accelerated scrollspeed */
2384 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2385 snprintf(buf, sizeof(buf), "accel. speed: %4d", speed);
2386 lcd_puts(0, 6, buf);
2388 lcd_update();
2390 return false;
2392 #endif
2394 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2395 static bool logf_usb_serial(void)
2397 bool serial_enabled = !usb_core_driver_enabled(USB_DRIVER_SERIAL);
2398 usb_core_enable_driver(USB_DRIVER_SERIAL,serial_enabled);
2399 gui_syncsplash(HZ, "USB logf %s",
2400 serial_enabled?"enabled":"disabled");
2401 return false;
2403 #endif
2405 #if defined(HAVE_USBSTACK) && defined(USB_STORAGE)
2406 static bool usb_reconnect(void)
2408 gui_syncsplash(HZ, "Reconnect mass storage");
2409 usb_storage_reconnect();
2410 return false;
2412 #endif
2414 #if CONFIG_USBOTG == USBOTG_ISP1583
2415 extern int dbg_usb_num_items(void);
2416 extern char* dbg_usb_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2418 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2420 (void)lists;
2421 if (action == ACTION_NONE)
2422 action = ACTION_REDRAW;
2423 return action;
2426 static bool dbg_isp1583(void)
2428 struct simplelist_info isp1583;
2429 isp1583.scroll_all = true;
2430 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2431 isp1583.timeout = HZ/100;
2432 isp1583.hide_selection = true;
2433 isp1583.get_name = dbg_usb_item;
2434 isp1583.action_callback = isp1583_action_callback;
2435 return simplelist_show_list(&isp1583);
2437 #endif
2439 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2440 extern int pic_dbg_num_items(void);
2441 extern char* pic_dbg_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2443 static int pic_action_callback(int action, struct gui_synclist *lists)
2445 (void)lists;
2446 if (action == ACTION_NONE)
2447 action = ACTION_REDRAW;
2448 return action;
2451 static bool dbg_pic(void)
2453 struct simplelist_info pic;
2454 pic.scroll_all = true;
2455 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2456 pic.timeout = HZ/100;
2457 pic.hide_selection = true;
2458 pic.get_name = pic_dbg_item;
2459 pic.action_callback = pic_action_callback;
2460 return simplelist_show_list(&pic);
2462 #endif
2465 /****** The menu *********/
2466 struct the_menu_item {
2467 unsigned char *desc; /* string or ID */
2468 bool (*function) (void); /* return true if USB was connected */
2470 static const struct the_menu_item menuitems[] = {
2471 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2472 (defined(CPU_PP) && !defined(HAVE_ATA_SD))
2473 { "Dump ROM contents", dbg_save_roms },
2474 #endif
2475 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2476 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L
2477 { "View I/O ports", dbg_ports },
2478 #endif
2479 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2480 { "View PCF registers", dbg_pcf },
2481 #endif
2482 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2483 { "TSC2100 debug", tsc2100_debug },
2484 #endif
2485 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2486 { "CPU frequency", dbg_cpufreq },
2487 #endif
2488 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2489 { "S/PDIF analyzer", dbg_spdif },
2490 #endif
2491 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2492 { "Catch mem accesses", dbg_set_memory_guard },
2493 #endif
2494 { "View OS stacks", dbg_os },
2495 #ifdef HAVE_LCD_BITMAP
2496 #ifndef SIMULATOR
2497 { "View battery", view_battery },
2498 #endif
2499 { "Screendump", dbg_screendump },
2500 #endif
2501 #ifndef SIMULATOR
2502 { "View HW info", dbg_hw_info },
2503 #endif
2504 #ifndef SIMULATOR
2505 { "View partitions", dbg_partitions },
2506 #endif
2507 #ifndef SIMULATOR
2508 { "View disk info", dbg_disk_info },
2509 #if !defined(HAVE_MMC) && !defined(HAVE_ATA_SD)
2510 { "Dump ATA identify info", dbg_identify_info},
2511 #endif
2512 #endif
2513 #ifdef HAVE_DIRCACHE
2514 { "View dircache info", dbg_dircache_info },
2515 #endif
2516 #ifdef HAVE_TAGCACHE
2517 { "View database info", dbg_tagcache_info },
2518 #endif
2519 #ifdef HAVE_LCD_BITMAP
2520 #if CONFIG_CODEC == SWCODEC
2521 { "View buffering thread", dbg_buffering_thread },
2522 #elif !defined(SIMULATOR)
2523 { "View audio thread", dbg_audio_thread },
2524 #endif
2525 #ifdef PM_DEBUG
2526 { "pm histogram", peak_meter_histogram},
2527 #endif /* PM_DEBUG */
2528 #endif /* HAVE_LCD_BITMAP */
2529 #ifndef SIMULATOR
2530 #if CONFIG_TUNER
2531 { "FM Radio", dbg_fm_radio },
2532 #endif
2533 #endif
2534 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2535 { "Write back EEPROM", dbg_write_eeprom },
2536 #endif
2537 #if CONFIG_USBOTG == USBOTG_ISP1583
2538 { "View ISP1583 info", dbg_isp1583 },
2539 #endif
2540 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2541 { "View PIC info", dbg_pic },
2542 #endif
2543 #ifdef ROCKBOX_HAS_LOGF
2544 {"logf", logfdisplay },
2545 {"logfdump", logfdump },
2546 #endif
2547 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2548 {"logf over usb",logf_usb_serial },
2549 #endif
2550 #if defined(HAVE_USBSTACK) && defined(USB_STORAGE)
2551 {"reconnect usb storage",usb_reconnect},
2552 #endif
2553 #ifdef CPU_BOOST_LOGGING
2554 {"cpu_boost log",cpu_boost_log},
2555 #endif
2556 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2557 {"Debug scrollwheel", dbg_scrollwheel},
2558 #endif
2560 static int menu_action_callback(int btn, struct gui_synclist *lists)
2562 if (btn == ACTION_STD_OK)
2564 menuitems[gui_synclist_get_sel_pos(lists)].function();
2565 btn = ACTION_REDRAW;
2567 return btn;
2569 static char* dbg_menu_getname(int item, void * data,
2570 char *buffer, size_t buffer_len)
2572 (void)data; (void)buffer; (void)buffer_len;
2573 return menuitems[item].desc;
2575 bool debug_menu(void)
2577 struct simplelist_info info;
2579 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2580 info.action_callback = menu_action_callback;
2581 info.get_name = dbg_menu_getname;
2583 return simplelist_show_list(&info);