That test plugin was forgotten in the make system overhaul.
[kugel-rb.git] / apps / debug_menu.c
blob0db0e5a47175f307206d8d60d8e4228c9ab64381
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 "storage.h"
63 #include "fat.h"
64 #include "mas.h"
65 #include "eeprom_24cxx.h"
66 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
67 #include "hotswap.h"
68 #endif
69 #if (CONFIG_STORAGE & STORAGE_ATA)
70 #include "ata.h"
71 #endif
72 #if CONFIG_TUNER
73 #include "tuner.h"
74 #include "radio.h"
75 #endif
76 #endif
78 #ifdef HAVE_LCD_BITMAP
79 #include "scrollbar.h"
80 #include "peakmeter.h"
81 #endif
82 #include "logfdisp.h"
83 #if CONFIG_CODEC == SWCODEC
84 #include "pcmbuf.h"
85 #include "buffering.h"
86 #include "playback.h"
87 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
88 #include "spdif.h"
89 #endif
90 #endif
91 #ifdef IRIVER_H300_SERIES
92 #include "pcf50606.h" /* for pcf50606_read */
93 #endif
94 #ifdef IAUDIO_X5
95 #include "ds2411.h"
96 #endif
97 #include "hwcompat.h"
98 #include "button.h"
99 #if CONFIG_RTC == RTC_PCF50605
100 #include "pcf50605.h"
101 #endif
103 #if CONFIG_CPU == DM320 || CONFIG_CPU == S3C2440 || CONFIG_CPU == TCC7801 \
104 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525
105 #include "debug-target.h"
106 #endif
108 #if defined(SANSA_E200) || defined(PHILIPS_SA9200)
109 #include "ascodec.h"
110 #include "as3514.h"
111 #endif
113 #if defined(HAVE_USBSTACK)
114 #include "usb_core.h"
115 #endif
116 #ifdef USB_STORAGE
117 #include "usbstack/usb_storage.h"
118 #endif
120 /*---------------------------------------------------*/
121 /* SPECIAL DEBUG STUFF */
122 /*---------------------------------------------------*/
123 extern struct thread_entry threads[MAXTHREADS];
125 static char thread_status_char(unsigned status)
127 static const char thread_status_chars[THREAD_NUM_STATES+1] =
129 [0 ... THREAD_NUM_STATES] = '?',
130 [STATE_RUNNING] = 'R',
131 [STATE_BLOCKED] = 'B',
132 [STATE_SLEEPING] = 'S',
133 [STATE_BLOCKED_W_TMO] = 'T',
134 [STATE_FROZEN] = 'F',
135 [STATE_KILLED] = 'K',
138 if (status > THREAD_NUM_STATES)
139 status = THREAD_NUM_STATES;
141 return thread_status_chars[status];
144 static char* threads_getname(int selected_item, void *data,
145 char *buffer, size_t buffer_len)
147 (void)data;
148 struct thread_entry *thread;
149 char name[32];
151 #if NUM_CORES > 1
152 if (selected_item < (int)NUM_CORES)
154 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
155 idle_stack_usage(selected_item));
156 return buffer;
159 selected_item -= NUM_CORES;
160 #endif
162 thread = &threads[selected_item];
164 if (thread->state == STATE_KILLED)
166 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
167 return buffer;
170 thread_get_name(name, 32, thread);
172 snprintf(buffer, buffer_len,
173 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
174 selected_item,
175 IF_COP(thread->core,)
176 #ifdef HAVE_SCHEDULER_BOOSTCTRL
177 (thread->cpu_boost) ? '+' :
178 #endif
179 ((thread->state == STATE_RUNNING) ? '*' : ' '),
180 thread_status_char(thread->state),
181 IF_PRIO(thread->base_priority, thread->priority, )
182 thread_stack_usage(thread), name);
184 return buffer;
186 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
188 (void)lists;
189 #ifdef ROCKBOX_HAS_LOGF
190 if (action == ACTION_STD_OK)
192 int selpos = gui_synclist_get_sel_pos(lists);
193 #if NUM_CORES > 1
194 if (selpos >= NUM_CORES)
195 remove_thread(&threads[selpos - NUM_CORES]);
196 #else
197 remove_thread(&threads[selpos]);
198 #endif
199 return ACTION_REDRAW;
201 #endif /* ROCKBOX_HAS_LOGF */
202 if (action == ACTION_NONE)
203 action = ACTION_REDRAW;
204 return action;
206 /* Test code!!! */
207 static bool dbg_os(void)
209 struct simplelist_info info;
210 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
211 #if NUM_CORES == 1
212 MAXTHREADS,
213 #else
214 MAXTHREADS+NUM_CORES,
215 #endif
216 NULL);
217 #ifndef ROCKBOX_HAS_LOGF
218 info.hide_selection = true;
219 info.scroll_all = true;
220 #endif
221 info.action_callback = dbg_threads_action_callback;
222 info.get_name = threads_getname;
223 return simplelist_show_list(&info);
226 #ifdef HAVE_LCD_BITMAP
227 #if CONFIG_CODEC != SWCODEC
228 #ifndef SIMULATOR
229 static bool dbg_audio_thread(void)
231 char buf[32];
232 struct audio_debug d;
234 lcd_setfont(FONT_SYSFIXED);
236 while(1)
238 if (action_userabort(HZ/5))
239 return false;
241 audio_get_debugdata(&d);
243 lcd_clear_display();
245 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
246 lcd_puts(0, 0, buf);
247 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
248 lcd_puts(0, 1, buf);
249 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
250 lcd_puts(0, 2, buf);
251 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
252 lcd_puts(0, 3, buf);
253 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
254 lcd_puts(0, 4, buf);
255 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
256 lcd_puts(0, 5, buf);
258 /* Playable space left */
259 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
260 d.playable_space, HORIZONTAL);
262 /* Show the watermark limit */
263 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
264 d.low_watermark_level, HORIZONTAL);
266 snprintf(buf, sizeof(buf), "wm: %x - %x",
267 d.low_watermark_level, d.lowest_watermark_level);
268 lcd_puts(0, 7, buf);
270 lcd_update();
272 return false;
274 #endif /* !SIMULATOR */
275 #else /* CONFIG_CODEC == SWCODEC */
276 extern size_t filebuflen;
277 /* This is a size_t, but call it a long so it puts a - when it's bad. */
279 static unsigned int ticks, boost_ticks, freq_sum;
281 static void dbg_audio_task(void)
283 #ifndef SIMULATOR
284 if(FREQ > CPUFREQ_NORMAL)
285 boost_ticks++;
286 freq_sum += FREQ/1000000; /* in MHz */
287 #endif
288 ticks++;
291 static bool dbg_buffering_thread(void)
293 char buf[32];
294 int button;
295 int line;
296 bool done = false;
297 size_t bufused;
298 size_t bufsize = pcmbuf_get_bufsize();
299 int pcmbufdescs = pcmbuf_descs();
300 struct buffering_debug d;
302 ticks = boost_ticks = freq_sum = 0;
304 tick_add_task(dbg_audio_task);
306 lcd_setfont(FONT_SYSFIXED);
307 while(!done)
309 button = get_action(CONTEXT_STD,HZ/5);
310 switch(button)
312 case ACTION_STD_NEXT:
313 audio_next();
314 break;
315 case ACTION_STD_PREV:
316 audio_prev();
317 break;
318 case ACTION_STD_CANCEL:
319 done = true;
320 break;
323 buffering_get_debugdata(&d);
325 line = 0;
326 lcd_clear_display();
328 bufused = bufsize - pcmbuf_free();
330 snprintf(buf, sizeof(buf), "pcm: %7ld/%7ld", (long) bufused, (long) bufsize);
331 lcd_puts(0, line++, buf);
333 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
334 bufsize, 0, bufused, HORIZONTAL);
335 line++;
337 snprintf(buf, sizeof(buf), "alloc: %8ld/%8ld", audio_filebufused(),
338 (long) filebuflen);
339 lcd_puts(0, line++, buf);
341 #if LCD_HEIGHT > 80
342 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
343 filebuflen, 0, audio_filebufused(), HORIZONTAL);
344 line++;
346 snprintf(buf, sizeof(buf), "real: %8ld/%8ld", (long)d.buffered_data,
347 (long)filebuflen);
348 lcd_puts(0, line++, buf);
350 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
351 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
352 line++;
353 #endif
355 snprintf(buf, sizeof(buf), "usefl: %8ld/%8ld", (long)(d.useful_data),
356 (long)filebuflen);
357 lcd_puts(0, line++, buf);
359 #if LCD_HEIGHT > 80
360 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
361 filebuflen, 0, d.useful_data, HORIZONTAL);
362 line++;
363 #endif
365 snprintf(buf, sizeof(buf), "data_rem: %ld", (long)d.data_rem);
366 lcd_puts(0, line++, buf);
368 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
369 lcd_puts(0, line++, buf);
371 snprintf(buf, sizeof(buf), "handle count: %d", (int)d.num_handles);
372 lcd_puts(0, line++, buf);
374 #ifndef SIMULATOR
375 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
376 (int)((FREQ + 500000) / 1000000));
377 lcd_puts(0, line++, buf);
378 #endif
380 if (ticks > 0)
382 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
383 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
384 snprintf(buf, sizeof(buf), "boost ratio: %3d.%d%% (%2d.%dMHz)",
385 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
386 lcd_puts(0, line++, buf);
389 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
390 pcmbuf_used_descs(), pcmbufdescs);
391 lcd_puts(0, line++, buf);
393 lcd_update();
396 tick_remove_task(dbg_audio_task);
398 return false;
400 #endif /* CONFIG_CODEC */
401 #endif /* HAVE_LCD_BITMAP */
404 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
405 /* Tool function to read the flash manufacturer and type, if available.
406 Only chips which could be reprogrammed in system will return values.
407 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
408 /* In IRAM to avoid problems when running directly from Flash */
409 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
410 unsigned addr1, unsigned addr2)
411 ICODE_ATTR __attribute__((noinline));
412 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
413 unsigned addr1, unsigned addr2)
416 unsigned not_manu, not_id; /* read values before switching to ID mode */
417 unsigned manu, id; /* read values when in ID mode */
419 #if CONFIG_CPU == SH7034
420 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
421 #elif defined(CPU_COLDFIRE)
422 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
423 #endif
424 int old_level; /* saved interrupt level */
426 not_manu = flash[0]; /* read the normal content */
427 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
429 /* disable interrupts, prevent any stray flash access */
430 old_level = disable_irq_save();
432 flash[addr1] = 0xAA; /* enter command mode */
433 flash[addr2] = 0x55;
434 flash[addr1] = 0x90; /* ID command */
435 /* Atmel wants 20ms pause here */
436 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
438 manu = flash[0]; /* read the IDs */
439 id = flash[1];
441 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
442 /* Atmel wants 20ms pause here */
443 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
445 restore_irq(old_level); /* enable interrupts again */
447 /* I assume success if the obtained values are different from
448 the normal flash content. This is not perfectly bulletproof, they
449 could theoretically be the same by chance, causing us to fail. */
450 if (not_manu != manu || not_id != id) /* a value has changed */
452 *p_manufacturer = manu; /* return the results */
453 *p_device = id;
454 return true; /* success */
456 return false; /* fail */
458 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
460 #ifndef SIMULATOR
461 #ifdef CPU_PP
462 static int perfcheck(void)
464 int result;
466 asm (
467 "mrs r2, CPSR \n"
468 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
469 "msr CPSR_c, r0 \n"
470 "mov %[res], #0 \n"
471 "ldr r0, [%[timr]] \n"
472 "add r0, r0, %[tmo] \n"
473 "1: \n"
474 "add %[res], %[res], #1 \n"
475 "ldr r1, [%[timr]] \n"
476 "cmp r1, r0 \n"
477 "bmi 1b \n"
478 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
480 [res]"=&r"(result)
482 [timr]"r"(&USEC_TIMER),
483 [tmo]"r"(
484 #if CONFIG_CPU == PP5002
485 16000
486 #else /* PP5020/5022/5024 */
487 10226
488 #endif
491 "r0", "r1", "r2"
493 return result;
495 #endif
497 #ifdef HAVE_LCD_BITMAP
498 static bool dbg_hw_info(void)
500 #if CONFIG_CPU == SH7034
501 char buf[32];
502 int bitmask = HW_MASK;
503 int rom_version = ROM_VERSION;
504 unsigned manu, id; /* flash IDs */
505 bool got_id; /* flag if we managed to get the flash IDs */
506 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
507 bool has_bootrom; /* flag for boot ROM present */
508 int oldmode; /* saved memory guard mode */
510 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
512 /* get flash ROM type */
513 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
514 if (!got_id)
515 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
517 /* check if the boot ROM area is a flash mirror */
518 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
519 if (has_bootrom) /* if ROM and Flash different */
521 /* calculate CRC16 checksum of boot ROM */
522 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
525 system_memory_guard(oldmode); /* re-enable memory guard */
527 lcd_setfont(FONT_SYSFIXED);
528 lcd_clear_display();
530 lcd_puts(0, 0, "[Hardware info]");
532 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
533 lcd_puts(0, 1, buf);
535 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
536 lcd_puts(0, 2, buf);
538 if (got_id)
539 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
540 else
541 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
542 lcd_puts(0, 3, buf);
544 if (has_bootrom)
546 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
547 snprintf(buf, 32, "Boot ROM: V1");
548 else
549 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
551 else
553 snprintf(buf, 32, "Boot ROM: none");
555 lcd_puts(0, 4, buf);
557 lcd_update();
559 while (!(action_userabort(TIMEOUT_BLOCK)));
561 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
562 char buf[32];
563 unsigned manu, id; /* flash IDs */
564 int got_id; /* flag if we managed to get the flash IDs */
565 int oldmode; /* saved memory guard mode */
566 int line = 0;
568 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
570 /* get flash ROM type */
571 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
572 if (!got_id)
573 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
575 system_memory_guard(oldmode); /* re-enable memory guard */
577 lcd_setfont(FONT_SYSFIXED);
578 lcd_clear_display();
580 lcd_puts(0, line++, "[Hardware info]");
582 if (got_id)
583 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
584 else
585 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
586 lcd_puts(0, line++, buf);
588 #ifdef IAUDIO_X5
590 struct ds2411_id id;
592 lcd_puts(0, ++line, "Serial Number:");
594 got_id = ds2411_read_id(&id);
596 if (got_id == DS2411_OK)
598 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
599 lcd_puts(0, ++line, buf);
600 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
601 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
602 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
603 lcd_puts(0, ++line, buf);
604 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
606 else
608 snprintf(buf, 32, "READ ERR=%d", got_id);
611 lcd_puts(0, ++line, buf);
613 #endif
615 lcd_update();
617 while (!(action_userabort(TIMEOUT_BLOCK)));
619 #elif defined(CPU_PP502x)
620 int line = 0;
621 char buf[32];
622 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
623 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
624 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
625 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\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_setfont(FONT_SYSFIXED);
664 lcd_clear_display();
666 lcd_puts(0, line++, "[Hardware info]");
668 #ifdef IPOD_ARCH
669 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
670 lcd_puts(0, line++, buf);
671 #endif
673 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
674 lcd_puts(0, line++, buf);
676 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
677 lcd_puts(0, line++, buf);
679 lcd_update();
681 while (!(action_userabort(TIMEOUT_BLOCK)));
682 #else
683 /* Define this function in your target tree */
684 return __dbg_hw_info();
685 #endif /* CONFIG_CPU */
686 return false;
688 #else /* !HAVE_LCD_BITMAP */
689 static bool dbg_hw_info(void)
691 char buf[32];
692 int button;
693 int currval = 0;
694 int rom_version = ROM_VERSION;
695 unsigned manu, id; /* flash IDs */
696 bool got_id; /* flag if we managed to get the flash IDs */
697 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
698 bool has_bootrom; /* flag for boot ROM present */
699 int oldmode; /* saved memory guard mode */
701 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
703 /* get flash ROM type */
704 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
705 if (!got_id)
706 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
708 /* check if the boot ROM area is a flash mirror */
709 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
710 if (has_bootrom) /* if ROM and Flash different */
712 /* calculate CRC16 checksum of boot ROM */
713 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
716 system_memory_guard(oldmode); /* re-enable memory guard */
718 lcd_clear_display();
720 lcd_puts(0, 0, "[HW Info]");
721 while(1)
723 switch(currval)
725 case 0:
726 snprintf(buf, 32, "ROM: %d.%02d",
727 rom_version/100, rom_version%100);
728 break;
729 case 1:
730 if (got_id)
731 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
732 else
733 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
734 break;
735 case 2:
736 if (has_bootrom)
738 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
739 snprintf(buf, 32, "BootROM: V1");
740 else if (rom_crc == 0x358099E8)
741 snprintf(buf, 32, "BootROM: V2");
742 /* alternative boot ROM found in one single player so far */
743 else
744 snprintf(buf, 32, "R: %08x", rom_crc);
746 else
747 snprintf(buf, 32, "BootROM: no");
750 lcd_puts(0, 1, buf);
751 lcd_update();
753 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
755 switch(button)
757 case ACTION_STD_CANCEL:
758 return false;
760 case ACTION_SETTINGS_DEC:
761 currval--;
762 if(currval < 0)
763 currval = 2;
764 break;
766 case ACTION_SETTINGS_INC:
767 currval++;
768 if(currval > 2)
769 currval = 0;
770 break;
773 return false;
775 #endif /* !HAVE_LCD_BITMAP */
776 #endif /* !SIMULATOR */
778 #ifndef SIMULATOR
779 static char* dbg_partitions_getname(int selected_item, void *data,
780 char *buffer, size_t buffer_len)
782 (void)data;
783 int partition = selected_item/2;
784 struct partinfo* p = disk_partinfo(partition);
785 if (selected_item%2)
787 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / 2048);
789 else
791 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
793 return buffer;
796 bool dbg_partitions(void)
798 struct simplelist_info info;
799 simplelist_info_init(&info, "Partition Info", 4, NULL);
800 info.selection_size = 2;
801 info.hide_selection = true;
802 info.scroll_all = true;
803 info.get_name = dbg_partitions_getname;
804 return simplelist_show_list(&info);
806 #endif
808 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
809 static bool dbg_spdif(void)
811 char buf[128];
812 int line;
813 unsigned int control;
814 int x;
815 char *s;
816 int category;
817 int generation;
818 unsigned int interruptstat;
819 bool valnogood, symbolerr, parityerr;
820 bool done = false;
821 bool spdif_src_on;
822 int spdif_source = spdif_get_output_source(&spdif_src_on);
823 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
825 lcd_clear_display();
826 lcd_setfont(FONT_SYSFIXED);
828 #ifdef HAVE_SPDIF_POWER
829 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
830 #endif
832 while (!done)
834 line = 0;
836 control = EBU1RCVCCHANNEL1;
837 interruptstat = INTERRUPTSTAT;
838 INTERRUPTCLEAR = 0x03c00000;
840 valnogood = (interruptstat & 0x01000000)?true:false;
841 symbolerr = (interruptstat & 0x00800000)?true:false;
842 parityerr = (interruptstat & 0x00400000)?true:false;
844 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
845 valnogood?"--":"OK",
846 symbolerr?"--":"OK",
847 parityerr?"--":"OK");
848 lcd_puts(0, line++, buf);
850 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
851 lcd_puts(0, line++, buf);
853 line++;
855 x = control >> 31;
856 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
857 x, x?"Professional":"Consumer");
858 lcd_puts(0, line++, buf);
860 x = (control >> 30) & 1;
861 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
862 x, x?"Non-PCM":"PCM");
863 lcd_puts(0, line++, buf);
865 x = (control >> 29) & 1;
866 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
867 x, x?"Permitted":"Inhibited");
868 lcd_puts(0, line++, buf);
870 x = (control >> 27) & 7;
871 switch(x)
873 case 0:
874 s = "None";
875 break;
876 case 1:
877 s = "50/15us";
878 break;
879 default:
880 s = "Reserved";
881 break;
883 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
884 lcd_puts(0, line++, buf);
886 x = (control >> 24) & 3;
887 snprintf(buf, sizeof(buf), "Mode: %d", x);
888 lcd_puts(0, line++, buf);
890 category = (control >> 17) & 127;
891 switch(category)
893 case 0x00:
894 s = "General";
895 break;
896 case 0x40:
897 s = "Audio CD";
898 break;
899 default:
900 s = "Unknown";
902 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
903 lcd_puts(0, line++, buf);
905 x = (control >> 16) & 1;
906 generation = x;
907 if(((category & 0x70) == 0x10) ||
908 ((category & 0x70) == 0x40) ||
909 ((category & 0x78) == 0x38))
911 generation = !generation;
913 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
914 x, generation?"Original":"No ind.");
915 lcd_puts(0, line++, buf);
917 x = (control >> 12) & 15;
918 snprintf(buf, sizeof(buf), "Source: %d", x);
919 lcd_puts(0, line++, buf);
921 x = (control >> 8) & 15;
922 switch(x)
924 case 0:
925 s = "Unspecified";
926 break;
927 case 8:
928 s = "A (Left)";
929 break;
930 case 4:
931 s = "B (Right)";
932 break;
933 default:
934 s = "";
935 break;
937 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
938 lcd_puts(0, line++, buf);
940 x = (control >> 4) & 15;
941 switch(x)
943 case 0:
944 s = "44.1kHz";
945 break;
946 case 0x4:
947 s = "48kHz";
948 break;
949 case 0xc:
950 s = "32kHz";
951 break;
953 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
954 lcd_puts(0, line++, buf);
956 x = (control >> 2) & 3;
957 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
958 lcd_puts(0, line++, buf);
959 line++;
961 #ifndef SIMULATOR
962 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
963 spdif_measure_frequency());
964 lcd_puts(0, line++, buf);
965 #endif
967 lcd_update();
969 if (action_userabort(HZ/10))
970 break;
973 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
975 #ifdef HAVE_SPDIF_POWER
976 spdif_power_enable(global_settings.spdif_enable);
977 #endif
979 return false;
981 #endif /* CPU_COLDFIRE */
983 #ifndef SIMULATOR
984 #ifdef HAVE_LCD_BITMAP
985 /* button definitions */
986 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
987 (CONFIG_KEYPAD == IRIVER_H300_PAD)
988 # define DEBUG_CANCEL BUTTON_OFF
990 #elif CONFIG_KEYPAD == RECORDER_PAD
991 # define DEBUG_CANCEL BUTTON_OFF
993 #elif CONFIG_KEYPAD == ONDIO_PAD
994 # define DEBUG_CANCEL BUTTON_MENU
996 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
997 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
998 (CONFIG_KEYPAD == IPOD_4G_PAD)
999 # define DEBUG_CANCEL BUTTON_MENU
1001 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
1002 # define DEBUG_CANCEL BUTTON_PLAY
1004 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
1005 # define DEBUG_CANCEL BUTTON_REC
1007 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1008 # define DEBUG_CANCEL BUTTON_RC_REC
1010 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
1011 # define DEBUG_CANCEL BUTTON_REW
1013 #elif (CONFIG_KEYPAD == MROBE100_PAD)
1014 # define DEBUG_CANCEL BUTTON_MENU
1016 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
1017 (CONFIG_KEYPAD == SANSA_C200_PAD)
1018 # define DEBUG_CANCEL BUTTON_LEFT
1020 /* This is temporary until the SA9200 touchpad works */
1021 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) || \
1022 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD)
1023 # define DEBUG_CANCEL BUTTON_POWER
1025 #endif /* key definitions */
1027 /* Test code!!! */
1028 bool dbg_ports(void)
1030 #if CONFIG_CPU == SH7034
1031 char buf[32];
1032 int adc_battery_voltage, adc_battery_level;
1034 lcd_setfont(FONT_SYSFIXED);
1035 lcd_clear_display();
1037 while(1)
1039 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1040 lcd_puts(0, 0, buf);
1041 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1042 lcd_puts(0, 1, buf);
1044 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1045 lcd_puts(0, 2, buf);
1046 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1047 lcd_puts(0, 3, buf);
1048 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1049 lcd_puts(0, 4, buf);
1050 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1051 lcd_puts(0, 5, buf);
1053 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1054 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1055 adc_battery_voltage % 1000, adc_battery_level);
1056 lcd_puts(0, 6, buf);
1058 lcd_update();
1059 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1060 return false;
1062 #elif defined(CPU_COLDFIRE)
1063 unsigned int gpio_out;
1064 unsigned int gpio1_out;
1065 unsigned int gpio_read;
1066 unsigned int gpio1_read;
1067 unsigned int gpio_function;
1068 unsigned int gpio1_function;
1069 unsigned int gpio_enable;
1070 unsigned int gpio1_enable;
1071 int adc_buttons, adc_remote;
1072 int adc_battery_voltage, adc_battery_level;
1073 char buf[128];
1074 int line;
1076 lcd_clear_display();
1077 lcd_setfont(FONT_SYSFIXED);
1079 while(1)
1081 line = 0;
1082 gpio_read = GPIO_READ;
1083 gpio1_read = GPIO1_READ;
1084 gpio_out = GPIO_OUT;
1085 gpio1_out = GPIO1_OUT;
1086 gpio_function = GPIO_FUNCTION;
1087 gpio1_function = GPIO1_FUNCTION;
1088 gpio_enable = GPIO_ENABLE;
1089 gpio1_enable = GPIO1_ENABLE;
1091 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1092 lcd_puts(0, line++, buf);
1093 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1094 lcd_puts(0, line++, buf);
1095 snprintf(buf, sizeof(buf), "GPIO_FUNC: %08x", gpio_function);
1096 lcd_puts(0, line++, buf);
1097 snprintf(buf, sizeof(buf), "GPIO_ENA: %08x", gpio_enable);
1098 lcd_puts(0, line++, buf);
1100 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1101 lcd_puts(0, line++, buf);
1102 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1103 lcd_puts(0, line++, buf);
1104 snprintf(buf, sizeof(buf), "GPIO1_FUNC: %08x", gpio1_function);
1105 lcd_puts(0, line++, buf);
1106 snprintf(buf, sizeof(buf), "GPIO1_ENA: %08x", gpio1_enable);
1107 lcd_puts(0, line++, buf);
1109 adc_buttons = adc_read(ADC_BUTTONS);
1110 adc_remote = adc_read(ADC_REMOTE);
1111 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1112 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1113 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1114 button_scan_enabled() ? '+' : '-', adc_buttons);
1115 #else
1116 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1117 #endif
1118 lcd_puts(0, line++, buf);
1119 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1120 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1121 remote_detect() ? '+' : '-', adc_remote);
1122 #else
1123 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1124 #endif
1125 lcd_puts(0, line++, buf);
1126 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1127 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1128 adc_read(ADC_REMOTEDETECT));
1129 lcd_puts(0, line++, buf);
1130 #endif
1132 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1133 adc_battery_voltage % 1000, adc_battery_level);
1134 lcd_puts(0, line++, buf);
1136 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1137 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1138 lcd_puts(0, line++, buf);
1139 #endif
1141 lcd_update();
1142 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1143 return false;
1146 #elif defined(CPU_PP502x)
1148 char buf[128];
1149 int line;
1151 lcd_clear_display();
1152 lcd_setfont(FONT_SYSFIXED);
1154 while(1)
1156 line = 0;
1157 lcd_puts(0, line++, "GPIO STATES:");
1158 snprintf(buf, sizeof(buf), "A: %02x E: %02x I: %02x",
1159 (unsigned int)GPIOA_INPUT_VAL,
1160 (unsigned int)GPIOE_INPUT_VAL,
1161 (unsigned int)GPIOI_INPUT_VAL);
1162 lcd_puts(0, line++, buf);
1163 snprintf(buf, sizeof(buf), "B: %02x F: %02x J: %02x",
1164 (unsigned int)GPIOB_INPUT_VAL,
1165 (unsigned int)GPIOF_INPUT_VAL,
1166 (unsigned int)GPIOJ_INPUT_VAL);
1167 lcd_puts(0, line++, buf);
1168 snprintf(buf, sizeof(buf), "C: %02x G: %02x K: %02x",
1169 (unsigned int)GPIOC_INPUT_VAL,
1170 (unsigned int)GPIOG_INPUT_VAL,
1171 (unsigned int)GPIOK_INPUT_VAL);
1172 lcd_puts(0, line++, buf);
1173 snprintf(buf, sizeof(buf), "D: %02x H: %02x L: %02x",
1174 (unsigned int)GPIOD_INPUT_VAL,
1175 (unsigned int)GPIOH_INPUT_VAL,
1176 (unsigned int)GPIOL_INPUT_VAL);
1177 lcd_puts(0, line++, buf);
1178 line++;
1179 snprintf(buf, sizeof(buf), "GPO32_VAL: %08lx", GPO32_VAL);
1180 lcd_puts(0, line++, buf);
1181 snprintf(buf, sizeof(buf), "GPO32_EN: %08lx", GPO32_ENABLE);
1182 lcd_puts(0, line++, buf);
1183 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1184 lcd_puts(0, line++, buf);
1185 snprintf(buf, sizeof(buf), "DEV_EN2: %08lx", DEV_EN2);
1186 lcd_puts(0, line++, buf);
1187 snprintf(buf, sizeof(buf), "DEV_EN3: %08lx", inl(0x60006044));
1188 lcd_puts(0, line++, buf); /* to be verified */
1189 snprintf(buf, sizeof(buf), "DEV_INIT1: %08lx", DEV_INIT1);
1190 lcd_puts(0, line++, buf);
1191 snprintf(buf, sizeof(buf), "DEV_INIT2: %08lx", DEV_INIT2);
1192 lcd_puts(0, line++, buf);
1193 #ifdef ADC_ACCESSORY
1194 snprintf(buf, sizeof(buf), "ACCESSORY: %d", adc_read(ADC_ACCESSORY));
1195 lcd_puts(0, line++, buf);
1196 #endif
1198 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1199 line++;
1200 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1201 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1202 lcd_puts(0, line++, buf);
1203 snprintf(buf, sizeof(buf), "REM: %03x PAD: %03x",
1204 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1205 lcd_puts(0, line++, buf);
1206 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1207 snprintf(buf, sizeof(buf), "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1208 lcd_puts(0, line++, buf);
1209 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1210 lcd_puts(0, line++, buf);
1211 snprintf(buf, sizeof(buf), "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1212 lcd_puts(0, line++, buf);
1213 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1214 lcd_puts(0, line++, buf);
1215 snprintf(buf, sizeof(buf), "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1216 lcd_puts(0, line++, buf);
1217 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1218 lcd_puts(0, line++, buf);
1219 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1220 lcd_puts(0, line++, buf);
1221 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1222 lcd_puts(0, line++, buf);
1223 snprintf(buf, sizeof(buf), "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1224 lcd_puts(0, line++, buf);
1225 snprintf(buf, sizeof(buf), "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1226 lcd_puts(0, line++, buf);
1227 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1228 lcd_puts(0, line++, buf);
1229 #if !defined(PHILIPS_SA9200)
1230 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1231 lcd_puts(0, line++, buf);
1232 snprintf(buf, sizeof(buf), "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1233 lcd_puts(0, line++, buf);
1234 snprintf(buf, sizeof(buf), "CHARGER: %02X/%02X",
1235 ascodec_read(AS3514_CHARGER),
1236 ascodec_read(AS3514_IRQ_ENRD0));
1237 lcd_puts(0, line++, buf);
1238 #endif
1239 #endif
1240 lcd_update();
1241 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1242 return false;
1245 #elif CONFIG_CPU == PP5002
1246 char buf[128];
1247 int line;
1249 lcd_clear_display();
1250 lcd_setfont(FONT_SYSFIXED);
1252 while(1)
1254 line = 0;
1255 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x",
1256 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1257 lcd_puts(0, line++, buf);
1258 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x",
1259 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1260 lcd_puts(0, line++, buf);
1262 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1263 lcd_puts(0, line++, buf);
1264 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1265 lcd_puts(0, line++, buf);
1266 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1267 lcd_puts(0, line++, buf);
1268 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1269 lcd_puts(0, line++, buf);
1270 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1271 lcd_puts(0, line++, buf);
1272 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1273 lcd_puts(0, line++, buf);
1274 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1275 lcd_puts(0, line++, buf);
1276 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1277 lcd_puts(0, line++, buf);
1279 lcd_update();
1280 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1281 return false;
1283 #else
1284 return __dbg_ports();
1285 #endif /* CPU */
1286 return false;
1288 #else /* !HAVE_LCD_BITMAP */
1289 bool dbg_ports(void)
1291 char buf[32];
1292 int button;
1293 int adc_battery_voltage;
1294 int currval = 0;
1296 lcd_clear_display();
1298 while(1)
1300 switch(currval)
1302 case 0:
1303 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1304 break;
1305 case 1:
1306 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1307 break;
1308 case 2:
1309 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1310 break;
1311 case 3:
1312 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1313 break;
1314 case 4:
1315 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1316 break;
1317 case 5:
1318 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1319 break;
1320 case 6:
1321 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1322 break;
1323 case 7:
1324 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1325 break;
1326 case 8:
1327 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1328 break;
1329 case 9:
1330 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1331 break;
1332 break;
1334 lcd_puts(0, 0, buf);
1336 battery_read_info(&adc_battery_voltage, NULL);
1337 snprintf(buf, 32, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1338 adc_battery_voltage % 1000);
1339 lcd_puts(0, 1, buf);
1340 lcd_update();
1342 button = get_action(CONTEXT_SETTINGS,HZ/5);
1344 switch(button)
1346 case ACTION_STD_CANCEL:
1347 return false;
1349 case ACTION_SETTINGS_DEC:
1350 currval--;
1351 if(currval < 0)
1352 currval = 9;
1353 break;
1355 case ACTION_SETTINGS_INC:
1356 currval++;
1357 if(currval > 9)
1358 currval = 0;
1359 break;
1362 return false;
1364 #endif /* !HAVE_LCD_BITMAP */
1365 #endif /* !SIMULATOR */
1367 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1368 static bool dbg_pcf(void)
1370 char buf[128];
1371 int line;
1373 #ifdef HAVE_LCD_BITMAP
1374 lcd_setfont(FONT_SYSFIXED);
1375 #endif
1376 lcd_clear_display();
1378 while(1)
1380 line = 0;
1382 snprintf(buf, sizeof(buf), "DCDC1: %02x", pcf50605_read(0x1b));
1383 lcd_puts(0, line++, buf);
1384 snprintf(buf, sizeof(buf), "DCDC2: %02x", pcf50605_read(0x1c));
1385 lcd_puts(0, line++, buf);
1386 snprintf(buf, sizeof(buf), "DCDC3: %02x", pcf50605_read(0x1d));
1387 lcd_puts(0, line++, buf);
1388 snprintf(buf, sizeof(buf), "DCDC4: %02x", pcf50605_read(0x1e));
1389 lcd_puts(0, line++, buf);
1390 snprintf(buf, sizeof(buf), "DCDEC1: %02x", pcf50605_read(0x1f));
1391 lcd_puts(0, line++, buf);
1392 snprintf(buf, sizeof(buf), "DCDEC2: %02x", pcf50605_read(0x20));
1393 lcd_puts(0, line++, buf);
1394 snprintf(buf, sizeof(buf), "DCUDC1: %02x", pcf50605_read(0x21));
1395 lcd_puts(0, line++, buf);
1396 snprintf(buf, sizeof(buf), "DCUDC2: %02x", pcf50605_read(0x22));
1397 lcd_puts(0, line++, buf);
1398 snprintf(buf, sizeof(buf), "IOREGC: %02x", pcf50605_read(0x23));
1399 lcd_puts(0, line++, buf);
1400 snprintf(buf, sizeof(buf), "D1REGC: %02x", pcf50605_read(0x24));
1401 lcd_puts(0, line++, buf);
1402 snprintf(buf, sizeof(buf), "D2REGC: %02x", pcf50605_read(0x25));
1403 lcd_puts(0, line++, buf);
1404 snprintf(buf, sizeof(buf), "D3REGC: %02x", pcf50605_read(0x26));
1405 lcd_puts(0, line++, buf);
1406 snprintf(buf, sizeof(buf), "LPREG1: %02x", pcf50605_read(0x27));
1407 lcd_puts(0, line++, buf);
1409 lcd_update();
1410 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1412 return false;
1416 return false;
1418 #endif
1420 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1421 static bool dbg_cpufreq(void)
1423 char buf[128];
1424 int line;
1425 int button;
1427 #ifdef HAVE_LCD_BITMAP
1428 lcd_setfont(FONT_SYSFIXED);
1429 #endif
1430 lcd_clear_display();
1432 while(1)
1434 line = 0;
1436 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1437 lcd_puts(0, line++, buf);
1439 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1440 lcd_puts(0, line++, buf);
1442 lcd_update();
1443 button = get_action(CONTEXT_STD,HZ/10);
1445 switch(button)
1447 case ACTION_STD_PREV:
1448 cpu_boost(true);
1449 break;
1451 case ACTION_STD_NEXT:
1452 cpu_boost(false);
1453 break;
1455 case ACTION_STD_OK:
1456 while (get_cpu_boost_counter() > 0)
1457 cpu_boost(false);
1458 set_cpu_frequency(CPUFREQ_DEFAULT);
1459 break;
1461 case ACTION_STD_CANCEL:
1462 return false;
1466 return false;
1468 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1470 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1471 #include "tsc2100.h"
1472 static char *itob(int n, int len)
1474 static char binary[64];
1475 int i,j;
1476 for (i=1, j=0;i<=len;i++)
1478 binary[j++] = n&(1<<(len-i))?'1':'0';
1479 if (i%4 == 0)
1480 binary[j++] = ' ';
1482 binary[j] = '\0';
1483 return binary;
1485 static char* tsc2100_debug_getname(int selected_item, void * data,
1486 char *buffer, size_t buffer_len)
1488 int *page = (int*)data;
1489 bool reserved = false;
1490 switch (*page)
1492 case 0:
1493 if ((selected_item > 0x0a) ||
1494 (selected_item == 0x04) ||
1495 (selected_item == 0x08))
1496 reserved = true;
1497 break;
1498 case 1:
1499 if ((selected_item > 0x05) ||
1500 (selected_item == 0x02))
1501 reserved = true;
1502 break;
1503 case 2:
1504 if (selected_item > 0x1e)
1505 reserved = true;
1506 break;
1508 if (reserved)
1509 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1510 else
1511 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1512 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1513 return buffer;
1515 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1517 int *page = (int*)lists->data;
1518 if (action == ACTION_STD_OK)
1520 *page = (*page+1)%3;
1521 snprintf(lists->title, 32,
1522 "tsc2100 registers - Page %d", *page);
1523 return ACTION_REDRAW;
1525 return action;
1527 static bool tsc2100_debug(void)
1529 int page = 0;
1530 char title[32] = "tsc2100 registers - Page 0";
1531 struct simplelist_info info;
1532 simplelist_info_init(&info, title, 32, &page);
1533 info.timeout = HZ/100;
1534 info.get_name = tsc2100_debug_getname;
1535 info.action_callback= tsc2100debug_action_callback;
1536 return simplelist_show_list(&info);
1538 #endif
1539 #ifndef SIMULATOR
1540 #ifdef HAVE_LCD_BITMAP
1542 * view_battery() shows a automatically scaled graph of the battery voltage
1543 * over time. Usable for estimating battery life / charging rate.
1544 * The power_history array is updated in power_thread of powermgmt.c.
1547 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1548 #define BAT_YSPACE (LCD_HEIGHT - 20)
1550 static bool view_battery(void)
1552 int view = 0;
1553 int i, x, y;
1554 unsigned short maxv, minv;
1555 char buf[32];
1557 lcd_setfont(FONT_SYSFIXED);
1559 while(1)
1561 lcd_clear_display();
1562 switch (view) {
1563 case 0: /* voltage history graph */
1564 /* Find maximum and minimum voltage for scaling */
1565 minv = power_history[0];
1566 maxv = minv + 1;
1567 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1568 if (power_history[i] > maxv)
1569 maxv = power_history[i];
1570 if (power_history[i] < minv)
1571 minv = power_history[i];
1574 snprintf(buf, 30, "Battery %d.%03d", power_history[0] / 1000,
1575 power_history[0] % 1000);
1576 lcd_puts(0, 0, buf);
1577 snprintf(buf, 30, "scale %d.%03d-%d.%03dV",
1578 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1579 lcd_puts(0, 1, buf);
1581 x = 0;
1582 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1583 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1584 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1585 lcd_vline(x, LCD_HEIGHT-1, 20);
1586 lcd_set_drawmode(DRMODE_SOLID);
1587 lcd_vline(x, LCD_HEIGHT-1,
1588 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1589 x++;
1592 break;
1594 case 1: /* status: */
1595 lcd_puts(0, 0, "Power status:");
1597 battery_read_info(&y, NULL);
1598 snprintf(buf, 30, "Battery: %d.%03d V", y / 1000, y % 1000);
1599 lcd_puts(0, 1, buf);
1600 #ifdef ADC_EXT_POWER
1601 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1602 snprintf(buf, 30, "External: %d.%03d V", y / 1000, y % 1000);
1603 lcd_puts(0, 2, buf);
1604 #endif
1605 #if CONFIG_CHARGING
1606 #if CONFIG_CHARGING == CHARGING_CONTROL
1607 snprintf(buf, 30, "Chgr: %s %s",
1608 charger_inserted() ? "present" : "absent",
1609 charger_enabled ? "on" : "off");
1610 lcd_puts(0, 3, buf);
1611 snprintf(buf, 30, "short delta: %d", short_delta);
1612 lcd_puts(0, 5, buf);
1613 snprintf(buf, 30, "long delta: %d", long_delta);
1614 lcd_puts(0, 6, buf);
1615 lcd_puts(0, 7, power_message);
1616 snprintf(buf, 30, "USB Inserted: %s",
1617 usb_inserted() ? "yes" : "no");
1618 lcd_puts(0, 8, buf);
1619 #if defined IRIVER_H300_SERIES
1620 snprintf(buf, 30, "USB Charging Enabled: %s",
1621 usb_charging_enabled() ? "yes" : "no");
1622 lcd_puts(0, 9, buf);
1623 #endif
1624 #else /* CONFIG_CHARGING != CHARGING_CONTROL */
1625 #if defined IPOD_NANO || defined IPOD_VIDEO
1626 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1627 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1628 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1629 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1630 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1632 snprintf(buf, 30, "USB pwr: %s",
1633 usb_pwr ? "present" : "absent");
1634 lcd_puts(0, 3, buf);
1635 snprintf(buf, 30, "EXT pwr: %s",
1636 ext_pwr ? "present" : "absent");
1637 lcd_puts(0, 4, buf);
1638 snprintf(buf, 30, "Battery: %s",
1639 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1640 lcd_puts(0, 5, buf);
1641 snprintf(buf, 30, "Dock mode: %s",
1642 dock ? "enabled" : "disabled");
1643 lcd_puts(0, 6, buf);
1644 snprintf(buf, 30, "Headphone: %s",
1645 headphone ? "connected" : "disconnected");
1646 lcd_puts(0, 7, buf);
1647 #else
1648 snprintf(buf, 30, "Charger: %s",
1649 charger_inserted() ? "present" : "absent");
1650 lcd_puts(0, 3, buf);
1651 #if defined TOSHIBA_GIGABEAT_S
1652 y = battery_adc_charge_current();
1653 x = y < 0 ? '-' : ' ';
1654 y = abs(y);
1655 snprintf(buf, 30, "I Charge:%c%d.%03d A", (char)x, y / 1000, y % 1000);
1656 lcd_puts(0, 4, buf);
1658 y = battery_adc_temp();
1659 snprintf(buf, 30, "T Battery: %dC (%dF)", y, (9*y + 160) / 5);
1660 lcd_puts(0, 5, buf);
1661 #endif /* defined TOSHIBA_GIGABEAT_S */
1662 #endif /* defined IPOD_NANO || defined IPOD_VIDEO */
1663 #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1664 #endif /* CONFIG_CHARGING */
1665 break;
1667 case 2: /* voltage deltas: */
1668 lcd_puts(0, 0, "Voltage deltas:");
1670 for (i = 0; i <= 6; i++) {
1671 y = power_history[i] - power_history[i+1];
1672 snprintf(buf, 30, "-%d min: %s%d.%03d V", i,
1673 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1674 ((y < 0) ? y * -1 : y ) % 1000);
1675 lcd_puts(0, i+1, buf);
1677 break;
1679 case 3: /* remaining time estimation: */
1681 #if CONFIG_CHARGING == CHARGING_CONTROL
1682 snprintf(buf, 30, "charge_state: %d", charge_state);
1683 lcd_puts(0, 0, buf);
1685 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1686 lcd_puts(0, 1, buf);
1688 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1689 lcd_puts(0, 2, buf);
1691 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1692 lcd_puts(0, 3, buf);
1694 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1695 lcd_puts(0, 4, buf);
1696 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
1698 snprintf(buf, 30, "Last PwrHist: %d.%03dV",
1699 power_history[0] / 1000,
1700 power_history[0] % 1000);
1701 lcd_puts(0, 5, buf);
1703 snprintf(buf, 30, "battery level: %d%%", battery_level());
1704 lcd_puts(0, 6, buf);
1706 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1707 lcd_puts(0, 7, buf);
1708 break;
1711 lcd_update();
1713 switch(get_action(CONTEXT_STD,HZ/2))
1715 case ACTION_STD_PREV:
1716 if (view)
1717 view--;
1718 break;
1720 case ACTION_STD_NEXT:
1721 if (view < 3)
1722 view++;
1723 break;
1725 case ACTION_STD_CANCEL:
1726 return false;
1729 return false;
1732 #endif /* HAVE_LCD_BITMAP */
1733 #endif
1735 #ifndef SIMULATOR
1736 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1738 #if (CONFIG_STORAGE & STORAGE_MMC)
1739 #define CARDTYPE "MMC"
1740 #elif (CONFIG_STORAGE & STORAGE_SD)
1741 #define CARDTYPE "microSD"
1742 #endif
1744 static int disk_callback(int btn, struct gui_synclist *lists)
1746 tCardInfo *card;
1747 int *cardnum = (int*)lists->data;
1748 unsigned char card_name[7];
1749 unsigned char pbuf[32];
1750 char *title = lists->title;
1751 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1752 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1753 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1754 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1755 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1756 "3.1-3.31", "4.0" };
1757 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1759 #ifdef HAVE_HOTSWAP
1760 if (btn == ACTION_STD_OK)
1762 *cardnum ^= 0x1; /* change cards */
1764 #endif
1766 simplelist_set_line_count(0);
1768 card = card_get_info(*cardnum);
1770 if (card->initialized > 0)
1772 card_name[6] = '\0';
1773 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1774 simplelist_addline(SIMPLELIST_ADD_LINE,
1775 "%s Rev %d.%d", card_name,
1776 (int) card_extract_bits(card->cid, 72, 4),
1777 (int) card_extract_bits(card->cid, 76, 4));
1778 simplelist_addline(SIMPLELIST_ADD_LINE,
1779 "Prod: %d/%d",
1780 (int) card_extract_bits(card->cid, 112, 4),
1781 (int) card_extract_bits(card->cid, 116, 4) + 1997);
1782 simplelist_addline(SIMPLELIST_ADD_LINE,
1783 "Ser#: 0x%08lx",
1784 card_extract_bits(card->cid, 80, 32));
1785 simplelist_addline(SIMPLELIST_ADD_LINE,
1786 "M=%02x, O=%04x",
1787 (int) card_extract_bits(card->cid, 0, 8),
1788 (int) card_extract_bits(card->cid, 8, 16));
1789 int temp = card_extract_bits(card->csd, 2, 4);
1790 simplelist_addline(SIMPLELIST_ADD_LINE,
1791 CARDTYPE " v%s", temp < 5 ?
1792 spec_vers[temp] : "?.?");
1793 simplelist_addline(SIMPLELIST_ADD_LINE,
1794 "Blocks: 0x%08lx", card->numblocks);
1795 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1796 kbit_units, false);
1797 simplelist_addline(SIMPLELIST_ADD_LINE,
1798 "Speed: %s", pbuf);
1799 output_dyn_value(pbuf, sizeof pbuf, card->tsac,
1800 nsec_units, false);
1801 simplelist_addline(SIMPLELIST_ADD_LINE,
1802 "Tsac: %s", pbuf);
1803 simplelist_addline(SIMPLELIST_ADD_LINE,
1804 "Nsac: %d clk", card->nsac);
1805 simplelist_addline(SIMPLELIST_ADD_LINE,
1806 "R2W: *%d", card->r2w_factor);
1807 simplelist_addline(SIMPLELIST_ADD_LINE,
1808 "IRmax: %d..%d mA",
1809 i_vmin[card_extract_bits(card->csd, 66, 3)],
1810 i_vmax[card_extract_bits(card->csd, 69, 3)]);
1811 simplelist_addline(SIMPLELIST_ADD_LINE,
1812 "IWmax: %d..%d mA",
1813 i_vmin[card_extract_bits(card->csd, 72, 3)],
1814 i_vmax[card_extract_bits(card->csd, 75, 3)]);
1816 else if (card->initialized == 0)
1818 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1820 #if (CONFIG_STORAGE & STORAGE_SD)
1821 else /* card->initialized < 0 */
1823 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1825 #endif
1826 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1827 gui_synclist_set_title(lists, title, Icon_NOICON);
1828 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1829 gui_synclist_select_item(lists, 0);
1830 btn = ACTION_REDRAW;
1832 return btn;
1834 #elif (CONFIG_STORAGE & STORAGE_ATA)
1835 static int disk_callback(int btn, struct gui_synclist *lists)
1837 (void)lists;
1838 int i;
1839 char buf[128];
1840 unsigned short* identify_info = ata_get_identify();
1841 bool timing_info_present = false;
1842 (void)btn;
1844 simplelist_set_line_count(0);
1846 for (i=0; i < 20; i++)
1847 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1848 buf[40]=0;
1849 /* kill trailing space */
1850 for (i=39; i && buf[i]==' '; i--)
1851 buf[i] = 0;
1852 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1853 for (i=0; i < 4; i++)
1854 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1855 buf[8]=0;
1856 simplelist_addline(SIMPLELIST_ADD_LINE,
1857 "Firmware: %s", buf);
1858 snprintf(buf, sizeof buf, "%ld MB",
1859 ((unsigned long)identify_info[61] << 16 |
1860 (unsigned long)identify_info[60]) / 2048 );
1861 simplelist_addline(SIMPLELIST_ADD_LINE,
1862 "Size: %s", buf);
1863 unsigned long free;
1864 fat_size( IF_MV2(0,) NULL, &free );
1865 simplelist_addline(SIMPLELIST_ADD_LINE,
1866 "Free: %ld MB", free / 1024);
1867 simplelist_addline(SIMPLELIST_ADD_LINE,
1868 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
1869 i = identify_info[83] & (1<<3);
1870 simplelist_addline(SIMPLELIST_ADD_LINE,
1871 "Power mgmt: %s", i ? "enabled" : "unsupported");
1872 i = identify_info[83] & (1<<9);
1873 simplelist_addline(SIMPLELIST_ADD_LINE,
1874 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1875 i = identify_info[82] & (1<<6);
1876 simplelist_addline(SIMPLELIST_ADD_LINE,
1877 "Read-ahead: %s", i ? "enabled" : "unsupported");
1878 timing_info_present = identify_info[53] & (1<<1);
1879 if(timing_info_present) {
1880 char pio3[2], pio4[2];pio3[1] = 0;
1881 pio4[1] = 0;
1882 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1883 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1884 simplelist_addline(SIMPLELIST_ADD_LINE,
1885 "PIO modes: 0 1 2 %s %s", pio3, pio4);
1887 else {
1888 simplelist_addline(SIMPLELIST_ADD_LINE,
1889 "No PIO mode info");
1891 timing_info_present = identify_info[53] & (1<<1);
1892 if(timing_info_present) {
1893 simplelist_addline(SIMPLELIST_ADD_LINE,
1894 "Cycle times %dns/%dns",
1895 identify_info[67],
1896 identify_info[68] );
1897 } else {
1898 simplelist_addline(SIMPLELIST_ADD_LINE,
1899 "No timing info");
1901 #if defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S)
1902 if (identify_info[63] & (1<<0)) {
1903 char mdma0[2], mdma1[2], mdma2[2];
1904 mdma0[1] = mdma1[1] = mdma2[1] = 0;
1905 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
1906 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
1907 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
1908 simplelist_addline(SIMPLELIST_ADD_LINE,
1909 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
1910 simplelist_addline(SIMPLELIST_ADD_LINE,
1911 "MDMA Cycle times %dns/%dns",
1912 identify_info[65],
1913 identify_info[66] );
1915 else {
1916 simplelist_addline(SIMPLELIST_ADD_LINE,
1917 "No MDMA mode info");
1919 if (identify_info[88] & (1<<0)) {
1920 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2];
1921 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = 0;
1922 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
1923 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
1924 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
1925 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
1926 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
1927 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
1928 simplelist_addline(SIMPLELIST_ADD_LINE,
1929 "UDMA modes: %s %s %s %s %s %s", udma0, udma1, udma2,
1930 udma3, udma4, udma5);
1932 else {
1933 simplelist_addline(SIMPLELIST_ADD_LINE,
1934 "No UDMA mode info");
1936 #endif /* defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S) */
1937 timing_info_present = identify_info[53] & (1<<1);
1938 if(timing_info_present) {
1939 i = identify_info[49] & (1<<11);
1940 simplelist_addline(SIMPLELIST_ADD_LINE,
1941 "IORDY support: %s", i ? "yes" : "no");
1942 i = identify_info[49] & (1<<10);
1943 simplelist_addline(SIMPLELIST_ADD_LINE,
1944 "IORDY disable: %s", i ? "yes" : "no");
1945 } else {
1946 simplelist_addline(SIMPLELIST_ADD_LINE,
1947 "No timing info");
1949 simplelist_addline(SIMPLELIST_ADD_LINE,
1950 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1951 return btn;
1953 #else /* No SD, MMC or ATA */
1954 static int disk_callback(int btn, struct gui_synclist *lists)
1956 (void)btn;
1957 (void)lists;
1958 struct storage_info info;
1959 storage_get_info(0,&info);
1960 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
1961 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
1962 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
1963 simplelist_addline(SIMPLELIST_ADD_LINE,
1964 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
1965 unsigned long free;
1966 fat_size( IF_MV2(0,) NULL, &free );
1967 simplelist_addline(SIMPLELIST_ADD_LINE,
1968 "Free: %ld MB", free / 1024);
1969 simplelist_addline(SIMPLELIST_ADD_LINE,
1970 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1971 return btn;
1973 #endif
1975 #if (CONFIG_STORAGE & STORAGE_ATA)
1976 static bool dbg_identify_info(void)
1978 int fd = creat("/identify_info.bin");
1979 if(fd >= 0)
1981 #ifdef ROCKBOX_LITTLE_ENDIAN
1982 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
1983 #else
1984 write(fd, ata_get_identify(), SECTOR_SIZE);
1985 #endif
1986 close(fd);
1988 return false;
1990 #endif
1992 static bool dbg_disk_info(void)
1994 struct simplelist_info info;
1995 simplelist_info_init(&info, "Disk Info", 1, NULL);
1996 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1997 char title[16];
1998 int card = 0;
1999 info.callback_data = (void*)&card;
2000 info.title = title;
2001 #endif
2002 info.action_callback = disk_callback;
2003 info.hide_selection = true;
2004 info.scroll_all = true;
2005 return simplelist_show_list(&info);
2007 #endif /* !SIMULATOR */
2009 #ifdef HAVE_DIRCACHE
2010 static int dircache_callback(int btn, struct gui_synclist *lists)
2012 (void)btn; (void)lists;
2013 simplelist_set_line_count(0);
2014 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
2015 dircache_is_enabled() ? "Yes" : "No");
2016 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
2017 dircache_get_cache_size());
2018 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
2019 global_status.dircache_size);
2020 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
2021 DIRCACHE_LIMIT);
2022 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
2023 dircache_get_reserve_used(), DIRCACHE_RESERVE);
2024 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2025 dircache_get_build_ticks() / HZ);
2026 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2027 dircache_get_entry_count());
2028 return btn;
2031 static bool dbg_dircache_info(void)
2033 struct simplelist_info info;
2034 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2035 info.action_callback = dircache_callback;
2036 info.hide_selection = true;
2037 info.scroll_all = true;
2038 return simplelist_show_list(&info);
2041 #endif /* HAVE_DIRCACHE */
2043 #ifdef HAVE_TAGCACHE
2044 static int database_callback(int btn, struct gui_synclist *lists)
2046 (void)lists;
2047 struct tagcache_stat *stat = tagcache_get_stat();
2048 static bool synced = false;
2050 simplelist_set_line_count(0);
2052 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2053 stat->initialized ? "Yes" : "No");
2054 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2055 stat->ready ? "Yes" : "No");
2056 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2057 stat->ramcache ? "Yes" : "No");
2058 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2059 stat->ramcache_used, stat->ramcache_allocated);
2060 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2061 stat->progress, stat->processed_entries);
2062 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2063 stat->curentry ? stat->curentry : "---");
2064 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2065 stat->commit_step);
2066 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2067 stat->commit_delayed ? "Yes" : "No");
2069 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2070 stat->queue_length);
2072 if (synced)
2074 synced = false;
2075 tagcache_screensync_event();
2078 if (!btn && stat->curentry)
2080 synced = true;
2081 return ACTION_REDRAW;
2084 if (btn == ACTION_STD_CANCEL)
2085 tagcache_screensync_enable(false);
2087 return btn;
2089 static bool dbg_tagcache_info(void)
2091 struct simplelist_info info;
2092 simplelist_info_init(&info, "Database Info", 8, NULL);
2093 info.action_callback = database_callback;
2094 info.hide_selection = true;
2095 info.scroll_all = true;
2097 /* Don't do nonblock here, must give enough processing time
2098 for tagcache thread. */
2099 /* info.timeout = TIMEOUT_NOBLOCK; */
2100 info.timeout = 1;
2101 tagcache_screensync_enable(true);
2102 return simplelist_show_list(&info);
2104 #endif
2106 #if CONFIG_CPU == SH7034
2107 static bool dbg_save_roms(void)
2109 int fd;
2110 int oldmode = system_memory_guard(MEMGUARD_NONE);
2112 fd = creat("/internal_rom_0000-FFFF.bin");
2113 if(fd >= 0)
2115 write(fd, (void *)0, 0x10000);
2116 close(fd);
2119 fd = creat("/internal_rom_2000000-203FFFF.bin");
2120 if(fd >= 0)
2122 write(fd, (void *)0x2000000, 0x40000);
2123 close(fd);
2126 system_memory_guard(oldmode);
2127 return false;
2129 #elif defined CPU_COLDFIRE
2130 static bool dbg_save_roms(void)
2132 int fd;
2133 int oldmode = system_memory_guard(MEMGUARD_NONE);
2135 #if defined(IRIVER_H100_SERIES)
2136 fd = creat("/internal_rom_000000-1FFFFF.bin");
2137 #elif defined(IRIVER_H300_SERIES)
2138 fd = creat("/internal_rom_000000-3FFFFF.bin");
2139 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2140 fd = creat("/internal_rom_000000-3FFFFF.bin");
2141 #endif
2142 if(fd >= 0)
2144 write(fd, (void *)0, FLASH_SIZE);
2145 close(fd);
2147 system_memory_guard(oldmode);
2149 #ifdef HAVE_EEPROM
2150 fd = creat("/internal_eeprom.bin");
2151 if (fd >= 0)
2153 int old_irq_level;
2154 char buf[EEPROM_SIZE];
2155 int err;
2157 old_irq_level = disable_irq_save();
2159 err = eeprom_24cxx_read(0, buf, sizeof buf);
2161 restore_irq(old_irq_level);
2163 if (err)
2164 splashf(HZ*3, "Eeprom read failure (%d)", err);
2165 else
2167 write(fd, buf, sizeof buf);
2170 close(fd);
2172 #endif
2174 return false;
2176 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
2177 static bool dbg_save_roms(void)
2179 int fd;
2181 fd = creat("/internal_rom_000000-0FFFFF.bin");
2182 if(fd >= 0)
2184 write(fd, (void *)0x20000000, FLASH_SIZE);
2185 close(fd);
2188 return false;
2190 #endif /* CPU */
2192 #ifndef SIMULATOR
2193 #if CONFIG_TUNER
2194 static int radio_callback(int btn, struct gui_synclist *lists)
2196 (void)lists;
2197 if (btn == ACTION_STD_CANCEL)
2198 return btn;
2199 simplelist_set_line_count(1);
2201 #if (CONFIG_TUNER & LV24020LP)
2202 simplelist_addline(SIMPLELIST_ADD_LINE,
2203 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2204 simplelist_addline(SIMPLELIST_ADD_LINE,
2205 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2206 simplelist_addline(SIMPLELIST_ADD_LINE,
2207 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2208 simplelist_addline(SIMPLELIST_ADD_LINE,
2209 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2210 simplelist_addline(SIMPLELIST_ADD_LINE,
2211 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2212 simplelist_addline(SIMPLELIST_ADD_LINE,
2213 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2214 simplelist_addline(SIMPLELIST_ADD_LINE,
2215 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2216 #endif
2217 #if (CONFIG_TUNER & S1A0903X01)
2218 simplelist_addline(SIMPLELIST_ADD_LINE,
2219 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2220 /* This one doesn't return dynamic data atm */
2221 #endif
2222 #if (CONFIG_TUNER & TEA5767)
2223 struct tea5767_dbg_info nfo;
2224 tea5767_dbg_info(&nfo);
2225 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2226 simplelist_addline(SIMPLELIST_ADD_LINE,
2227 " Read: %02X %02X %02X %02X %02X",
2228 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2229 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2230 (unsigned)nfo.read_regs[4]);
2231 simplelist_addline(SIMPLELIST_ADD_LINE,
2232 " Write: %02X %02X %02X %02X %02X",
2233 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2234 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2235 (unsigned)nfo.write_regs[4]);
2236 #endif
2237 return ACTION_REDRAW;
2239 static bool dbg_fm_radio(void)
2241 struct simplelist_info info;
2242 info.scroll_all = true;
2243 simplelist_info_init(&info, "FM Radio", 1, NULL);
2244 simplelist_set_line_count(0);
2245 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2246 radio_hardware_present() ? "yes" : "no");
2248 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2249 info.hide_selection = true;
2250 return simplelist_show_list(&info);
2252 #endif /* CONFIG_TUNER */
2253 #endif /* !SIMULATOR */
2255 #ifdef HAVE_LCD_BITMAP
2256 extern bool do_screendump_instead_of_usb;
2258 static bool dbg_screendump(void)
2260 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2261 splashf(HZ, "Screendump %s",
2262 do_screendump_instead_of_usb?"enabled":"disabled");
2263 return false;
2265 #endif /* HAVE_LCD_BITMAP */
2267 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2268 static bool dbg_set_memory_guard(void)
2270 static const struct opt_items names[MAXMEMGUARD] = {
2271 { "None", -1 },
2272 { "Flash ROM writes", -1 },
2273 { "Zero area (all)", -1 }
2275 int mode = system_memory_guard(MEMGUARD_KEEP);
2277 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2278 system_memory_guard(mode);
2280 return false;
2282 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2284 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2285 static bool dbg_write_eeprom(void)
2287 int fd;
2288 int rc;
2289 int old_irq_level;
2290 char buf[EEPROM_SIZE];
2291 int err;
2293 fd = open("/internal_eeprom.bin", O_RDONLY);
2295 if (fd >= 0)
2297 rc = read(fd, buf, EEPROM_SIZE);
2299 if(rc == EEPROM_SIZE)
2301 old_irq_level = disable_irq_save();
2303 err = eeprom_24cxx_write(0, buf, sizeof buf);
2304 if (err)
2305 splashf(HZ*3, "Eeprom write failure (%d)", err);
2306 else
2307 splash(HZ*3, "Eeprom written successfully");
2309 restore_irq(old_irq_level);
2311 else
2313 splashf(HZ*3, "File read error (%d)",rc);
2315 close(fd);
2317 else
2319 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2322 return false;
2324 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2325 #ifdef CPU_BOOST_LOGGING
2326 static bool cpu_boost_log(void)
2328 int i = 0,j=0;
2329 int count = cpu_boost_log_getcount();
2330 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2331 char *str;
2332 bool done;
2333 lcd_setfont(FONT_SYSFIXED);
2334 str = cpu_boost_log_getlog_first();
2335 while (i < count)
2337 lcd_clear_display();
2338 for(j=0; j<lines; j++,i++)
2340 if (!str)
2341 str = cpu_boost_log_getlog_next();
2342 if (str)
2344 lcd_puts(0, j,str);
2346 str = NULL;
2348 lcd_update();
2349 done = false;
2350 while (!done)
2352 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2354 case ACTION_STD_OK:
2355 case ACTION_STD_PREV:
2356 case ACTION_STD_NEXT:
2357 done = true;
2358 break;
2359 case ACTION_STD_CANCEL:
2360 i = count;
2361 done = true;
2362 break;
2366 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2367 lcd_setfont(FONT_UI);
2368 return false;
2370 #endif
2372 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2373 extern bool wheel_is_touched;
2374 extern int old_wheel_value;
2375 extern int new_wheel_value;
2376 extern int wheel_delta;
2377 extern unsigned int accumulated_wheel_delta;
2378 extern unsigned int wheel_velocity;
2380 static bool dbg_scrollwheel(void)
2382 char buf[64];
2383 unsigned int speed;
2385 lcd_setfont(FONT_SYSFIXED);
2387 while (1)
2389 if (action_userabort(HZ/10))
2390 return false;
2392 lcd_clear_display();
2394 /* show internal variables of scrollwheel driver */
2395 snprintf(buf, sizeof(buf), "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2396 lcd_puts(0, 0, buf);
2397 snprintf(buf, sizeof(buf), "new position: %2d", new_wheel_value);
2398 lcd_puts(0, 1, buf);
2399 snprintf(buf, sizeof(buf), "old position: %2d", old_wheel_value);
2400 lcd_puts(0, 2, buf);
2401 snprintf(buf, sizeof(buf), "wheel delta: %2d", wheel_delta);
2402 lcd_puts(0, 3, buf);
2403 snprintf(buf, sizeof(buf), "accumulated delta: %2d", accumulated_wheel_delta);
2404 lcd_puts(0, 4, buf);
2405 snprintf(buf, sizeof(buf), "velo [deg/s]: %4d", (int)wheel_velocity);
2406 lcd_puts(0, 5, buf);
2408 /* show effective accelerated scrollspeed */
2409 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2410 snprintf(buf, sizeof(buf), "accel. speed: %4d", speed);
2411 lcd_puts(0, 6, buf);
2413 lcd_update();
2415 return false;
2417 #endif
2419 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2420 static bool logf_usb_serial(void)
2422 bool serial_enabled = !usb_core_driver_enabled(USB_DRIVER_SERIAL);
2423 usb_core_enable_driver(USB_DRIVER_SERIAL,serial_enabled);
2424 splashf(HZ, "USB logf %s",
2425 serial_enabled?"enabled":"disabled");
2426 return false;
2428 #endif
2430 #if defined(HAVE_USBSTACK) && defined(USB_STORAGE)
2431 static bool usb_reconnect(void)
2433 splash(HZ, "Reconnect mass storage");
2434 usb_storage_reconnect();
2435 return false;
2437 #endif
2439 #if CONFIG_USBOTG == USBOTG_ISP1583
2440 extern int dbg_usb_num_items(void);
2441 extern char* dbg_usb_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2443 static int isp1583_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_isp1583(void)
2453 struct simplelist_info isp1583;
2454 isp1583.scroll_all = true;
2455 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2456 isp1583.timeout = HZ/100;
2457 isp1583.hide_selection = true;
2458 isp1583.get_name = dbg_usb_item;
2459 isp1583.action_callback = isp1583_action_callback;
2460 return simplelist_show_list(&isp1583);
2462 #endif
2464 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2465 extern int pic_dbg_num_items(void);
2466 extern char* pic_dbg_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2468 static int pic_action_callback(int action, struct gui_synclist *lists)
2470 (void)lists;
2471 if (action == ACTION_NONE)
2472 action = ACTION_REDRAW;
2473 return action;
2476 static bool dbg_pic(void)
2478 struct simplelist_info pic;
2479 pic.scroll_all = true;
2480 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2481 pic.timeout = HZ/100;
2482 pic.hide_selection = true;
2483 pic.get_name = pic_dbg_item;
2484 pic.action_callback = pic_action_callback;
2485 return simplelist_show_list(&pic);
2487 #endif
2490 /****** The menu *********/
2491 struct the_menu_item {
2492 unsigned char *desc; /* string or ID */
2493 bool (*function) (void); /* return true if USB was connected */
2495 static const struct the_menu_item menuitems[] = {
2496 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2497 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD))
2498 { "Dump ROM contents", dbg_save_roms },
2499 #endif
2500 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2501 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L
2502 { "View I/O ports", dbg_ports },
2503 #endif
2504 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2505 { "View PCF registers", dbg_pcf },
2506 #endif
2507 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2508 { "TSC2100 debug", tsc2100_debug },
2509 #endif
2510 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2511 { "CPU frequency", dbg_cpufreq },
2512 #endif
2513 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2514 { "S/PDIF analyzer", dbg_spdif },
2515 #endif
2516 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2517 { "Catch mem accesses", dbg_set_memory_guard },
2518 #endif
2519 { "View OS stacks", dbg_os },
2520 #ifdef HAVE_LCD_BITMAP
2521 #ifndef SIMULATOR
2522 { "View battery", view_battery },
2523 #endif
2524 { "Screendump", dbg_screendump },
2525 #endif
2526 #ifndef SIMULATOR
2527 { "View HW info", dbg_hw_info },
2528 #endif
2529 #ifndef SIMULATOR
2530 { "View partitions", dbg_partitions },
2531 #endif
2532 #ifndef SIMULATOR
2533 { "View disk info", dbg_disk_info },
2534 #if (CONFIG_STORAGE & STORAGE_ATA)
2535 { "Dump ATA identify info", dbg_identify_info},
2536 #endif
2537 #endif
2538 #ifdef HAVE_DIRCACHE
2539 { "View dircache info", dbg_dircache_info },
2540 #endif
2541 #ifdef HAVE_TAGCACHE
2542 { "View database info", dbg_tagcache_info },
2543 #endif
2544 #ifdef HAVE_LCD_BITMAP
2545 #if CONFIG_CODEC == SWCODEC
2546 { "View buffering thread", dbg_buffering_thread },
2547 #elif !defined(SIMULATOR)
2548 { "View audio thread", dbg_audio_thread },
2549 #endif
2550 #ifdef PM_DEBUG
2551 { "pm histogram", peak_meter_histogram},
2552 #endif /* PM_DEBUG */
2553 #endif /* HAVE_LCD_BITMAP */
2554 #ifndef SIMULATOR
2555 #if CONFIG_TUNER
2556 { "FM Radio", dbg_fm_radio },
2557 #endif
2558 #endif
2559 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2560 { "Write back EEPROM", dbg_write_eeprom },
2561 #endif
2562 #if CONFIG_USBOTG == USBOTG_ISP1583
2563 { "View ISP1583 info", dbg_isp1583 },
2564 #endif
2565 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2566 { "View PIC info", dbg_pic },
2567 #endif
2568 #ifdef ROCKBOX_HAS_LOGF
2569 {"logf", logfdisplay },
2570 {"logfdump", logfdump },
2571 #endif
2572 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2573 {"logf over usb",logf_usb_serial },
2574 #endif
2575 #if defined(HAVE_USBSTACK) && defined(USB_STORAGE)
2576 {"reconnect usb storage",usb_reconnect},
2577 #endif
2578 #ifdef CPU_BOOST_LOGGING
2579 {"cpu_boost log",cpu_boost_log},
2580 #endif
2581 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2582 {"Debug scrollwheel", dbg_scrollwheel},
2583 #endif
2585 static int menu_action_callback(int btn, struct gui_synclist *lists)
2587 if (btn == ACTION_STD_OK)
2589 menuitems[gui_synclist_get_sel_pos(lists)].function();
2590 btn = ACTION_REDRAW;
2592 return btn;
2594 static char* dbg_menu_getname(int item, void * data,
2595 char *buffer, size_t buffer_len)
2597 (void)data; (void)buffer; (void)buffer_len;
2598 return menuitems[item].desc;
2600 bool debug_menu(void)
2602 struct simplelist_info info;
2604 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2605 info.action_callback = menu_action_callback;
2606 info.get_name = dbg_menu_getname;
2608 return simplelist_show_list(&info);