Add a option to skip length which lets you skip 5s before the end of a song, which...
[kugel-rb.git] / apps / debug_menu.c
blob988684372386b1c12e312fbcfe9107f596254eb9
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Heikki Hannikainen
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <stdbool.h>
26 #include <string.h>
27 #include "lcd.h"
28 #include "menu.h"
29 #include "debug_menu.h"
30 #include "kernel.h"
31 #include "sprintf.h"
32 #include "structec.h"
33 #include "action.h"
34 #include "debug.h"
35 #include "thread.h"
36 #include "powermgmt.h"
37 #include "system.h"
38 #include "font.h"
39 #include "audio.h"
40 #include "mp3_playback.h"
41 #include "settings.h"
42 #include "list.h"
43 #include "statusbar.h"
44 #include "dir.h"
45 #include "panic.h"
46 #include "screens.h"
47 #include "misc.h"
48 #include "splash.h"
49 #include "dircache.h"
50 #include "viewport.h"
51 #ifdef HAVE_TAGCACHE
52 #include "tagcache.h"
53 #endif
54 #include "lcd-remote.h"
55 #include "crc32.h"
56 #include "logf.h"
57 #ifndef SIMULATOR
58 #include "disk.h"
59 #include "adc.h"
60 #include "power.h"
61 #include "usb.h"
62 #include "rtc.h"
63 #include "storage.h"
64 #include "fat.h"
65 #include "mas.h"
66 #include "eeprom_24cxx.h"
67 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
68 #include "hotswap.h"
69 #endif
70 #if (CONFIG_STORAGE & STORAGE_ATA)
71 #include "ata.h"
72 #endif
73 #if CONFIG_TUNER
74 #include "tuner.h"
75 #include "radio.h"
76 #endif
77 #endif
79 #ifdef HAVE_LCD_BITMAP
80 #include "scrollbar.h"
81 #include "peakmeter.h"
82 #endif
83 #include "logfdisp.h"
84 #if CONFIG_CODEC == SWCODEC
85 #include "pcmbuf.h"
86 #include "buffering.h"
87 #include "playback.h"
88 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
89 #include "spdif.h"
90 #endif
91 #endif
92 #ifdef IRIVER_H300_SERIES
93 #include "pcf50606.h" /* for pcf50606_read */
94 #endif
95 #ifdef IAUDIO_X5
96 #include "ds2411.h"
97 #endif
98 #include "hwcompat.h"
99 #include "button.h"
100 #if CONFIG_RTC == RTC_PCF50605
101 #include "pcf50605.h"
102 #endif
103 #include "appevents.h"
105 #if CONFIG_CPU == DM320 || CONFIG_CPU == S3C2440 || CONFIG_CPU == TCC7801 \
106 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 || CONFIG_CPU == JZ4732 \
107 || defined(CPU_S5L870X)
108 #include "debug-target.h"
109 #endif
111 #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) \
112 || defined(SANSA_CLIP) || defined(SANSA_FUZE)
113 #include "ascodec.h"
114 #include "as3514.h"
115 #endif
117 #ifdef IPOD_NANO2G
118 #include "pmu-target.h"
119 #endif
121 #ifdef HAVE_USBSTACK
122 #include "usb_core.h"
123 #endif
125 /* wrapper function to format a string and print it */
126 void debug_printf(int y, const unsigned char *fmt, ...)
128 va_list ap;
129 char buf[128];
130 va_start(ap, fmt);
131 vsnprintf(buf, sizeof (buf), fmt, ap);
132 va_end(ap);
133 lcd_puts(0, y, buf);
136 /*---------------------------------------------------*/
137 /* SPECIAL DEBUG STUFF */
138 /*---------------------------------------------------*/
139 extern struct thread_entry threads[MAXTHREADS];
141 static char thread_status_char(unsigned status)
143 static const char thread_status_chars[THREAD_NUM_STATES+1] =
145 [0 ... THREAD_NUM_STATES] = '?',
146 [STATE_RUNNING] = 'R',
147 [STATE_BLOCKED] = 'B',
148 [STATE_SLEEPING] = 'S',
149 [STATE_BLOCKED_W_TMO] = 'T',
150 [STATE_FROZEN] = 'F',
151 [STATE_KILLED] = 'K',
154 if (status > THREAD_NUM_STATES)
155 status = THREAD_NUM_STATES;
157 return thread_status_chars[status];
160 static const char* threads_getname(int selected_item, void *data,
161 char *buffer, size_t buffer_len)
163 (void)data;
164 struct thread_entry *thread;
165 char name[32];
167 #if NUM_CORES > 1
168 if (selected_item < (int)NUM_CORES)
170 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
171 idle_stack_usage(selected_item));
172 return buffer;
175 selected_item -= NUM_CORES;
176 #endif
178 thread = &threads[selected_item];
180 if (thread->state == STATE_KILLED)
182 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
183 return buffer;
186 thread_get_name(name, 32, thread);
188 snprintf(buffer, buffer_len,
189 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
190 selected_item,
191 IF_COP(thread->core,)
192 #ifdef HAVE_SCHEDULER_BOOSTCTRL
193 (thread->cpu_boost) ? '+' :
194 #endif
195 ((thread->state == STATE_RUNNING) ? '*' : ' '),
196 thread_status_char(thread->state),
197 IF_PRIO(thread->base_priority, thread->priority, )
198 thread_stack_usage(thread), name);
200 return buffer;
203 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
205 (void)lists;
206 #ifdef ROCKBOX_HAS_LOGF
207 if (action == ACTION_STD_OK)
209 int selpos = gui_synclist_get_sel_pos(lists);
210 #if NUM_CORES > 1
211 if (selpos >= NUM_CORES)
212 remove_thread(threads[selpos - NUM_CORES].id);
213 #else
214 remove_thread(threads[selpos].id);
215 #endif
216 return ACTION_REDRAW;
218 #endif /* ROCKBOX_HAS_LOGF */
219 if (action == ACTION_NONE)
220 action = ACTION_REDRAW;
221 return action;
223 /* Test code!!! */
224 static bool dbg_os(void)
226 struct simplelist_info info;
227 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
228 #if NUM_CORES == 1
229 MAXTHREADS,
230 #else
231 MAXTHREADS+NUM_CORES,
232 #endif
233 NULL);
234 #ifndef ROCKBOX_HAS_LOGF
235 info.hide_selection = true;
236 info.scroll_all = true;
237 #endif
238 info.action_callback = dbg_threads_action_callback;
239 info.get_name = threads_getname;
240 return simplelist_show_list(&info);
243 #ifdef HAVE_LCD_BITMAP
244 #if CONFIG_CODEC != SWCODEC
245 #ifndef SIMULATOR
246 static bool dbg_audio_thread(void)
248 struct audio_debug d;
250 lcd_setfont(FONT_SYSFIXED);
252 while(1)
254 if (action_userabort(HZ/5))
255 return false;
257 audio_get_debugdata(&d);
259 lcd_clear_display();
261 debug_printf(0, "read: %x", d.audiobuf_read);
262 debug_printf(1, "write: %x", d.audiobuf_write);
263 debug_printf(2, "swap: %x", d.audiobuf_swapwrite);
264 debug_printf(3, "playing: %d", d.playing);
265 debug_printf(4, "playable: %x", d.playable_space);
266 debug_printf(5, "unswapped: %x", d.unswapped_space);
268 /* Playable space left */
269 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
270 d.playable_space, HORIZONTAL);
272 /* Show the watermark limit */
273 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
274 d.low_watermark_level, HORIZONTAL);
276 debug_printf(7, "wm: %x - %x",
277 d.low_watermark_level, d.lowest_watermark_level);
279 lcd_update();
281 lcd_setfont(FONT_UI);
282 return false;
284 #endif /* !SIMULATOR */
285 #else /* CONFIG_CODEC == SWCODEC */
286 extern size_t filebuflen;
287 /* This is a size_t, but call it a long so it puts a - when it's bad. */
289 static unsigned int ticks, boost_ticks, freq_sum;
291 static void dbg_audio_task(void)
293 #ifndef SIMULATOR
294 if(FREQ > CPUFREQ_NORMAL)
295 boost_ticks++;
296 freq_sum += FREQ/1000000; /* in MHz */
297 #endif
298 ticks++;
301 static bool dbg_buffering_thread(void)
303 int button;
304 int line;
305 bool done = false;
306 size_t bufused;
307 size_t bufsize = pcmbuf_get_bufsize();
308 int pcmbufdescs = pcmbuf_descs();
309 struct buffering_debug d;
311 ticks = boost_ticks = freq_sum = 0;
313 tick_add_task(dbg_audio_task);
315 lcd_setfont(FONT_SYSFIXED);
316 while(!done)
318 button = get_action(CONTEXT_STD,HZ/5);
319 switch(button)
321 case ACTION_STD_NEXT:
322 audio_next();
323 break;
324 case ACTION_STD_PREV:
325 audio_prev();
326 break;
327 case ACTION_STD_CANCEL:
328 done = true;
329 break;
332 buffering_get_debugdata(&d);
334 line = 0;
335 lcd_clear_display();
337 bufused = bufsize - pcmbuf_free();
339 debug_printf(line++, "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
341 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
342 bufsize, 0, bufused, HORIZONTAL);
343 line++;
345 debug_printf(line++, "alloc: %6ld/%ld", audio_filebufused(),
346 (long) filebuflen);
348 #if LCD_HEIGHT > 80
349 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
350 filebuflen, 0, audio_filebufused(), HORIZONTAL);
351 line++;
353 debug_printf(line++, "real: %6ld/%ld", (long)d.buffered_data,
354 (long)filebuflen);
356 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
357 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
358 line++;
359 #endif
361 debug_printf(line++, "usefl: %6ld/%ld", (long)(d.useful_data),
362 (long)filebuflen);
364 #if LCD_HEIGHT > 80
365 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
366 filebuflen, 0, d.useful_data, HORIZONTAL);
367 line++;
368 #endif
370 debug_printf(line++, "data_rem: %ld", (long)d.data_rem);
372 debug_printf(line++, "track count: %2d", audio_track_count());
374 debug_printf(line++, "handle count: %d", (int)d.num_handles);
376 #ifndef SIMULATOR
377 debug_printf(line++, "cpu freq: %3dMHz",
378 (int)((FREQ + 500000) / 1000000));
379 #endif
381 if (ticks > 0)
383 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
384 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
385 debug_printf(line++, "boost:%3d.%d%% (%d.%dMHz)",
386 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
389 debug_printf(line++, "pcmbufdesc: %2d/%2d",
390 pcmbuf_used_descs(), pcmbufdescs);
391 debug_printf(line++, "watermark: %6d",
392 (int)(d.watermark));
394 lcd_update();
397 tick_remove_task(dbg_audio_task);
398 lcd_setfont(FONT_UI);
400 return false;
402 #endif /* CONFIG_CODEC */
403 #endif /* HAVE_LCD_BITMAP */
406 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
407 /* Tool function to read the flash manufacturer and type, if available.
408 Only chips which could be reprogrammed in system will return values.
409 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
410 /* In IRAM to avoid problems when running directly from Flash */
411 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
412 unsigned addr1, unsigned addr2)
413 ICODE_ATTR __attribute__((noinline));
414 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
415 unsigned addr1, unsigned addr2)
418 unsigned not_manu, not_id; /* read values before switching to ID mode */
419 unsigned manu, id; /* read values when in ID mode */
421 #if CONFIG_CPU == SH7034
422 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
423 #elif defined(CPU_COLDFIRE)
424 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
425 #endif
426 int old_level; /* saved interrupt level */
428 not_manu = flash[0]; /* read the normal content */
429 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
431 /* disable interrupts, prevent any stray flash access */
432 old_level = disable_irq_save();
434 flash[addr1] = 0xAA; /* enter command mode */
435 flash[addr2] = 0x55;
436 flash[addr1] = 0x90; /* ID command */
437 /* Atmel wants 20ms pause here */
438 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
440 manu = flash[0]; /* read the IDs */
441 id = flash[1];
443 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
444 /* Atmel wants 20ms pause here */
445 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
447 restore_irq(old_level); /* enable interrupts again */
449 /* I assume success if the obtained values are different from
450 the normal flash content. This is not perfectly bulletproof, they
451 could theoretically be the same by chance, causing us to fail. */
452 if (not_manu != manu || not_id != id) /* a value has changed */
454 *p_manufacturer = manu; /* return the results */
455 *p_device = id;
456 return true; /* success */
458 return false; /* fail */
460 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
462 #ifndef SIMULATOR
463 #ifdef CPU_PP
464 static int perfcheck(void)
466 int result;
468 asm (
469 "mrs r2, CPSR \n"
470 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
471 "msr CPSR_c, r0 \n"
472 "mov %[res], #0 \n"
473 "ldr r0, [%[timr]] \n"
474 "add r0, r0, %[tmo] \n"
475 "1: \n"
476 "add %[res], %[res], #1 \n"
477 "ldr r1, [%[timr]] \n"
478 "cmp r1, r0 \n"
479 "bmi 1b \n"
480 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
482 [res]"=&r"(result)
484 [timr]"r"(&USEC_TIMER),
485 [tmo]"r"(
486 #if CONFIG_CPU == PP5002
487 16000
488 #else /* PP5020/5022/5024 */
489 10226
490 #endif
493 "r0", "r1", "r2"
495 return result;
497 #endif
499 #ifdef HAVE_LCD_BITMAP
500 static bool dbg_hw_info(void)
502 #if CONFIG_CPU == SH7034
503 int bitmask = HW_MASK;
504 int rom_version = ROM_VERSION;
505 unsigned manu, id; /* flash IDs */
506 bool got_id; /* flag if we managed to get the flash IDs */
507 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
508 bool has_bootrom; /* flag for boot ROM present */
509 int oldmode; /* saved memory guard mode */
511 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
513 /* get flash ROM type */
514 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
515 if (!got_id)
516 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
518 /* check if the boot ROM area is a flash mirror */
519 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
520 if (has_bootrom) /* if ROM and Flash different */
522 /* calculate CRC16 checksum of boot ROM */
523 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
526 system_memory_guard(oldmode); /* re-enable memory guard */
528 lcd_setfont(FONT_SYSFIXED);
529 lcd_clear_display();
531 lcd_puts(0, 0, "[Hardware info]");
533 debug_printf(1, "ROM: %d.%02d", rom_version/100, rom_version%100);
535 debug_printf(2, "Mask: 0x%04x", bitmask);
537 if (got_id)
538 debug_printf(3, "Flash: M=%02x D=%02x", manu, id);
539 else
540 lcd_puts(0, 3, "Flash: M=?? D=??"); /* unknown, sorry */
542 if (has_bootrom)
544 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
545 lcd_puts(0, 4, "Boot ROM: V1");
546 else
547 debug_printf(4, "ROMcrc: 0x%08x", rom_crc);
549 else
551 lcd_puts(0, 4, "Boot ROM: none");
554 lcd_update();
556 while (!(action_userabort(TIMEOUT_BLOCK)));
558 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
559 unsigned manu, id; /* flash IDs */
560 int got_id; /* flag if we managed to get the flash IDs */
561 int oldmode; /* saved memory guard mode */
562 int line = 0;
564 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
566 /* get flash ROM type */
567 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
568 if (!got_id)
569 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
571 system_memory_guard(oldmode); /* re-enable memory guard */
573 lcd_setfont(FONT_SYSFIXED);
574 lcd_clear_display();
576 lcd_puts(0, line++, "[Hardware info]");
578 if (got_id)
579 debug_printf(line++, "Flash: M=%04x D=%04x", manu, id);
580 else
581 lcd_puts(0, line++, "Flash: M=???? D=????"); /* unknown, sorry */
583 #ifdef IAUDIO_X5
585 struct ds2411_id id;
587 lcd_puts(0, ++line, "Serial Number:");
589 got_id = ds2411_read_id(&id);
591 if (got_id == DS2411_OK)
593 debug_printf(++line, " FC=%02x", (unsigned)id.family_code);
594 debug_printf(++line, " ID=%02X %02X %02X %02X %02X %02X",
595 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
596 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
597 debug_printf(++line, " CRC=%02X", (unsigned)id.crc);
599 else
601 debug_printf(++line, "READ ERR=%d", got_id);
604 #endif
606 lcd_update();
608 while (!(action_userabort(TIMEOUT_BLOCK)));
610 #elif defined(CPU_PP502x)
611 int line = 0;
612 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
613 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
614 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
615 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
617 lcd_setfont(FONT_SYSFIXED);
618 lcd_clear_display();
620 lcd_puts(0, line++, "[Hardware info]");
622 #ifdef IPOD_ARCH
623 debug_printf(line++, "HW rev: 0x%08lx", IPOD_HW_REVISION);
624 #endif
626 #ifdef IPOD_COLOR
627 extern int lcd_type; /* Defined in lcd-colornano.c */
629 debug_printf(line++, "LCD type: %d", lcd_type);
630 #endif
632 debug_printf(line++, "PP version: %s", pp_version);
634 debug_printf(line++, "Est. clock (kHz): %d", perfcheck());
636 lcd_update();
638 while (!(action_userabort(TIMEOUT_BLOCK)));
640 #elif CONFIG_CPU == PP5002
641 int line = 0;
642 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
643 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
644 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
645 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
648 lcd_setfont(FONT_SYSFIXED);
649 lcd_clear_display();
651 lcd_puts(0, line++, "[Hardware info]");
653 #ifdef IPOD_ARCH
654 debug_printf(line++, "HW rev: 0x%08lx", IPOD_HW_REVISION);
655 #endif
657 debug_printf(line++, "PP version: %s", pp_version);
659 debug_printf(line++, "Est. clock (kHz): %d", perfcheck());
661 lcd_update();
663 while (!(action_userabort(TIMEOUT_BLOCK)));
665 #else
666 /* Define this function in your target tree */
667 return __dbg_hw_info();
668 #endif /* CONFIG_CPU */
669 lcd_setfont(FONT_UI);
670 return false;
672 #else /* !HAVE_LCD_BITMAP */
673 static bool dbg_hw_info(void)
675 int button;
676 int currval = 0;
677 int rom_version = ROM_VERSION;
678 unsigned manu, id; /* flash IDs */
679 bool got_id; /* flag if we managed to get the flash IDs */
680 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
681 bool has_bootrom; /* flag for boot ROM present */
682 int oldmode; /* saved memory guard mode */
684 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
686 /* get flash ROM type */
687 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
688 if (!got_id)
689 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
691 /* check if the boot ROM area is a flash mirror */
692 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
693 if (has_bootrom) /* if ROM and Flash different */
695 /* calculate CRC16 checksum of boot ROM */
696 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
699 system_memory_guard(oldmode); /* re-enable memory guard */
701 lcd_clear_display();
703 lcd_puts(0, 0, "[HW Info]");
704 while(1)
706 switch(currval)
708 case 0:
709 debug_printf(1, "ROM: %d.%02d",
710 rom_version/100, rom_version%100);
711 break;
712 case 1:
713 if (got_id)
714 debug_printf(1, "Flash:%02x,%02x", manu, id);
715 else
716 lcd_puts(0, 1, "Flash:??,??"); /* unknown, sorry */
717 break;
718 case 2:
719 if (has_bootrom)
721 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
722 lcd_puts(0, 1, "BootROM: V1");
723 else if (rom_crc == 0x358099E8)
724 lcd_puts(0, 1, "BootROM: V2");
725 /* alternative boot ROM found in one single player so far */
726 else
727 debug_printf(1, "R: %08x", rom_crc);
729 else
730 lcd_puts(0, 1, "BootROM: no");
733 lcd_update();
735 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
737 switch(button)
739 case ACTION_STD_CANCEL:
740 return false;
742 case ACTION_SETTINGS_DEC:
743 currval--;
744 if(currval < 0)
745 currval = 2;
746 break;
748 case ACTION_SETTINGS_INC:
749 currval++;
750 if(currval > 2)
751 currval = 0;
752 break;
755 return false;
757 #endif /* !HAVE_LCD_BITMAP */
758 #endif /* !SIMULATOR */
760 #ifndef SIMULATOR
761 static const char* dbg_partitions_getname(int selected_item, void *data,
762 char *buffer, size_t buffer_len)
764 (void)data;
765 int partition = selected_item/2;
766 struct partinfo* p = disk_partinfo(partition);
767 if (selected_item%2)
769 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / 2048);
771 else
773 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
775 return buffer;
778 bool dbg_partitions(void)
780 struct simplelist_info info;
781 simplelist_info_init(&info, "Partition Info", 4, NULL);
782 info.selection_size = 2;
783 info.hide_selection = true;
784 info.scroll_all = true;
785 info.get_name = dbg_partitions_getname;
786 return simplelist_show_list(&info);
788 #endif
790 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
791 static bool dbg_spdif(void)
793 int line;
794 unsigned int control;
795 int x;
796 char *s;
797 int category;
798 int generation;
799 unsigned int interruptstat;
800 bool valnogood, symbolerr, parityerr;
801 bool done = false;
802 bool spdif_src_on;
803 int spdif_source = spdif_get_output_source(&spdif_src_on);
804 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
806 lcd_clear_display();
807 lcd_setfont(FONT_SYSFIXED);
809 #ifdef HAVE_SPDIF_POWER
810 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
811 #endif
813 while (!done)
815 line = 0;
817 control = EBU1RCVCCHANNEL1;
818 interruptstat = INTERRUPTSTAT;
819 INTERRUPTCLEAR = 0x03c00000;
821 valnogood = (interruptstat & 0x01000000)?true:false;
822 symbolerr = (interruptstat & 0x00800000)?true:false;
823 parityerr = (interruptstat & 0x00400000)?true:false;
825 debug_printf(line++, "Val: %s Sym: %s Par: %s",
826 valnogood?"--":"OK",
827 symbolerr?"--":"OK",
828 parityerr?"--":"OK");
830 debug_printf(line++, "Status word: %08x", (int)control);
832 line++;
834 x = control >> 31;
835 debug_printf(line++, "PRO: %d (%s)",
836 x, x?"Professional":"Consumer");
838 x = (control >> 30) & 1;
839 debug_printf(line++, "Audio: %d (%s)",
840 x, x?"Non-PCM":"PCM");
842 x = (control >> 29) & 1;
843 debug_printf(line++, "Copy: %d (%s)",
844 x, x?"Permitted":"Inhibited");
846 x = (control >> 27) & 7;
847 switch(x)
849 case 0:
850 s = "None";
851 break;
852 case 1:
853 s = "50/15us";
854 break;
855 default:
856 s = "Reserved";
857 break;
859 debug_printf(line++, "Preemphasis: %d (%s)", x, s);
861 x = (control >> 24) & 3;
862 debug_printf(line++, "Mode: %d", x);
864 category = (control >> 17) & 127;
865 switch(category)
867 case 0x00:
868 s = "General";
869 break;
870 case 0x40:
871 s = "Audio CD";
872 break;
873 default:
874 s = "Unknown";
876 debug_printf(line++, "Category: 0x%02x (%s)", category, s);
878 x = (control >> 16) & 1;
879 generation = x;
880 if(((category & 0x70) == 0x10) ||
881 ((category & 0x70) == 0x40) ||
882 ((category & 0x78) == 0x38))
884 generation = !generation;
886 debug_printf(line++, "Generation: %d (%s)",
887 x, generation?"Original":"No ind.");
889 x = (control >> 12) & 15;
890 debug_printf(line++, "Source: %d", x);
893 x = (control >> 8) & 15;
894 switch(x)
896 case 0:
897 s = "Unspecified";
898 break;
899 case 8:
900 s = "A (Left)";
901 break;
902 case 4:
903 s = "B (Right)";
904 break;
905 default:
906 s = "";
907 break;
909 debug_printf(line++, "Channel: %d (%s)", x, s);
911 x = (control >> 4) & 15;
912 switch(x)
914 case 0:
915 s = "44.1kHz";
916 break;
917 case 0x4:
918 s = "48kHz";
919 break;
920 case 0xc:
921 s = "32kHz";
922 break;
924 debug_printf(line++, "Frequency: %d (%s)", x, s);
926 x = (control >> 2) & 3;
927 debug_printf(line++, "Clock accuracy: %d", x);
928 line++;
930 #ifndef SIMULATOR
931 debug_printf(line++, "Measured freq: %ldHz",
932 spdif_measure_frequency());
933 #endif
935 lcd_update();
937 if (action_userabort(HZ/10))
938 break;
941 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
943 #ifdef HAVE_SPDIF_POWER
944 spdif_power_enable(global_settings.spdif_enable);
945 #endif
947 lcd_setfont(FONT_UI);
948 return false;
950 #endif /* CPU_COLDFIRE */
952 #ifndef SIMULATOR
953 #ifdef HAVE_LCD_BITMAP
954 /* button definitions */
955 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
956 (CONFIG_KEYPAD == IRIVER_H300_PAD)
957 # define DEBUG_CANCEL BUTTON_OFF
959 #elif CONFIG_KEYPAD == RECORDER_PAD
960 # define DEBUG_CANCEL BUTTON_OFF
962 #elif CONFIG_KEYPAD == ONDIO_PAD
963 # define DEBUG_CANCEL BUTTON_MENU
965 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
966 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
967 (CONFIG_KEYPAD == IPOD_4G_PAD)
968 # define DEBUG_CANCEL BUTTON_MENU
970 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
971 # define DEBUG_CANCEL BUTTON_PLAY
973 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
974 # define DEBUG_CANCEL BUTTON_REC
976 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
977 # define DEBUG_CANCEL BUTTON_RC_REC
979 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
980 # define DEBUG_CANCEL BUTTON_REW
982 #elif (CONFIG_KEYPAD == MROBE100_PAD)
983 # define DEBUG_CANCEL BUTTON_MENU
985 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
986 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
987 (CONFIG_KEYPAD == SANSA_FUZE_PAD)
988 # define DEBUG_CANCEL BUTTON_LEFT
990 /* This is temporary until the SA9200 touchpad works */
991 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) || \
992 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD)
993 # define DEBUG_CANCEL BUTTON_POWER
995 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
996 # define DEBUG_CANCEL BUTTON_PLAY
998 #endif /* key definitions */
1000 /* Test code!!! */
1001 bool dbg_ports(void)
1003 #if CONFIG_CPU == SH7034
1004 int adc_battery_voltage, adc_battery_level;
1006 lcd_setfont(FONT_SYSFIXED);
1007 lcd_clear_display();
1009 while(1)
1011 debug_printf(0, "PADR: %04x", (unsigned short)PADR);
1012 debug_printf(1, "PBDR: %04x", (unsigned short)PBDR);
1014 debug_printf(2, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1015 debug_printf(3, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1016 debug_printf(4, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1017 debug_printf(5, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1019 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1020 debug_printf(6, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1021 adc_battery_voltage % 1000, adc_battery_level);
1023 lcd_update();
1024 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1026 lcd_setfont(FONT_UI);
1027 return false;
1030 #elif defined(CPU_COLDFIRE)
1031 unsigned int gpio_out;
1032 unsigned int gpio1_out;
1033 unsigned int gpio_read;
1034 unsigned int gpio1_read;
1035 unsigned int gpio_function;
1036 unsigned int gpio1_function;
1037 unsigned int gpio_enable;
1038 unsigned int gpio1_enable;
1039 int adc_buttons, adc_remote;
1040 int adc_battery_voltage, adc_battery_level;
1041 int line;
1043 lcd_clear_display();
1044 lcd_setfont(FONT_SYSFIXED);
1046 while(1)
1048 line = 0;
1049 gpio_read = GPIO_READ;
1050 gpio1_read = GPIO1_READ;
1051 gpio_out = GPIO_OUT;
1052 gpio1_out = GPIO1_OUT;
1053 gpio_function = GPIO_FUNCTION;
1054 gpio1_function = GPIO1_FUNCTION;
1055 gpio_enable = GPIO_ENABLE;
1056 gpio1_enable = GPIO1_ENABLE;
1058 debug_printf(line++, "GPIO_READ: %08x", gpio_read);
1059 debug_printf(line++, "GPIO_OUT: %08x", gpio_out);
1060 debug_printf(line++, "GPIO_FUNC: %08x", gpio_function);
1061 debug_printf(line++, "GPIO_ENA: %08x", gpio_enable);
1063 debug_printf(line++, "GPIO1_READ: %08x", gpio1_read);
1064 debug_printf(line++, "GPIO1_OUT: %08x", gpio1_out);
1065 debug_printf(line++, "GPIO1_FUNC: %08x", gpio1_function);
1066 debug_printf(line++, "GPIO1_ENA: %08x", gpio1_enable);
1068 adc_buttons = adc_read(ADC_BUTTONS);
1069 adc_remote = adc_read(ADC_REMOTE);
1070 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1071 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1072 debug_printf(line++, "ADC_BUTTONS (%c): %02x",
1073 button_scan_enabled() ? '+' : '-', adc_buttons);
1074 #else
1075 debug_printf(line++, "ADC_BUTTONS: %02x", adc_buttons);
1076 #endif
1077 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1078 debug_printf(line++, "ADC_REMOTE (%c): %02x",
1079 remote_detect() ? '+' : '-', adc_remote);
1080 #else
1081 debug_printf(line++, "ADC_REMOTE: %02x", adc_remote);
1082 #endif
1083 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1084 debug_printf(line++, "ADC_REMOTEDETECT: %02x",
1085 adc_read(ADC_REMOTEDETECT));
1086 #endif
1088 debug_printf(line++, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1089 adc_battery_voltage % 1000, adc_battery_level);
1091 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1092 debug_printf(line++, "remotetype: %d", remote_type());
1093 #endif
1095 lcd_update();
1096 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1098 lcd_setfont(FONT_UI);
1099 return false;
1103 #elif defined(CPU_PP502x)
1104 int line;
1106 lcd_clear_display();
1107 lcd_setfont(FONT_SYSFIXED);
1109 while(1)
1111 line = 0;
1112 lcd_puts(0, line++, "GPIO STATES:");
1113 debug_printf(line++, "A: %02x E: %02x I: %02x",
1114 (unsigned int)GPIOA_INPUT_VAL,
1115 (unsigned int)GPIOE_INPUT_VAL,
1116 (unsigned int)GPIOI_INPUT_VAL);
1117 debug_printf(line++, "B: %02x F: %02x J: %02x",
1118 (unsigned int)GPIOB_INPUT_VAL,
1119 (unsigned int)GPIOF_INPUT_VAL,
1120 (unsigned int)GPIOJ_INPUT_VAL);
1121 debug_printf(line++, "C: %02x G: %02x K: %02x",
1122 (unsigned int)GPIOC_INPUT_VAL,
1123 (unsigned int)GPIOG_INPUT_VAL,
1124 (unsigned int)GPIOK_INPUT_VAL);
1125 debug_printf(line++, "D: %02x H: %02x L: %02x",
1126 (unsigned int)GPIOD_INPUT_VAL,
1127 (unsigned int)GPIOH_INPUT_VAL,
1128 (unsigned int)GPIOL_INPUT_VAL);
1129 line++;
1130 debug_printf(line++, "GPO32_VAL: %08lx", GPO32_VAL);
1131 debug_printf(line++, "GPO32_EN: %08lx", GPO32_ENABLE);
1132 debug_printf(line++, "DEV_EN: %08lx", DEV_EN);
1133 debug_printf(line++, "DEV_EN2: %08lx", DEV_EN2);
1134 debug_printf(line++, "DEV_EN3: %08lx", inl(0x60006044)); /* to be verified */
1135 debug_printf(line++, "DEV_INIT1: %08lx", DEV_INIT1);
1136 debug_printf(line++, "DEV_INIT2: %08lx", DEV_INIT2);
1137 #ifdef ADC_ACCESSORY
1138 debug_printf(line++, "ACCESSORY: %d", adc_read(ADC_ACCESSORY));
1139 #endif
1141 #if defined(IPOD_ACCESSORY_PROTOCOL)
1142 extern unsigned char serbuf[];
1143 debug_printf(line++, "IAP PACKET: %02x %02x %02x %02x %02x %02x %02x %02x",
1144 serbuf[0], serbuf[1], serbuf[2], serbuf[3], serbuf[4], serbuf[5],
1145 serbuf[6], serbuf[7]);
1146 #endif
1148 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1149 line++;
1150 debug_printf(line++, "BATT: %03x UNK1: %03x",
1151 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1152 debug_printf(line++, "REM: %03x PAD: %03x",
1153 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1154 #elif defined(PHILIPS_HDD1630)
1155 line++;
1156 debug_printf(line++, "BATT: %03x UNK1: %03x",
1157 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1158 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1159 debug_printf(line++, "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1160 debug_printf(line++, "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1161 debug_printf(line++, "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1162 debug_printf(line++, "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1163 debug_printf(line++, "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1164 debug_printf(line++, "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1165 debug_printf(line++, "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1166 debug_printf(line++, "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1167 debug_printf(line++, "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1168 debug_printf(line++, "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1169 debug_printf(line++, "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1170 #if !defined(PHILIPS_SA9200)
1171 debug_printf(line++, "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1172 debug_printf(line++, "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1173 #endif
1174 #endif
1175 lcd_update();
1176 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1178 lcd_setfont(FONT_UI);
1179 return false;
1183 #elif CONFIG_CPU == PP5002
1184 int line;
1186 lcd_clear_display();
1187 lcd_setfont(FONT_SYSFIXED);
1189 while(1)
1191 line = 0;
1192 debug_printf(line++, "GPIO_A: %02x GPIO_B: %02x",
1193 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1194 debug_printf(line++, "GPIO_C: %02x GPIO_D: %02x",
1195 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1197 debug_printf(line++, "DEV_EN: %08lx", DEV_EN);
1198 debug_printf(line++, "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1199 debug_printf(line++, "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1200 debug_printf(line++, "PLL_CONTROL: %08lx", PLL_CONTROL);
1201 debug_printf(line++, "PLL_DIV: %08lx", PLL_DIV);
1202 debug_printf(line++, "PLL_MULT: %08lx", PLL_MULT);
1203 debug_printf(line++, "TIMING1_CTL: %08lx", TIMING1_CTL);
1204 debug_printf(line++, "TIMING2_CTL: %08lx", TIMING2_CTL);
1206 lcd_update();
1207 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1209 lcd_setfont(FONT_UI);
1210 return false;
1213 lcd_setfont(FONT_UI);
1214 #else
1215 return __dbg_ports();
1216 #endif /* CPU */
1217 return false;
1219 #else /* !HAVE_LCD_BITMAP */
1220 bool dbg_ports(void)
1222 char buf[32];
1223 int button;
1224 int adc_battery_voltage;
1225 int currval = 0;
1227 lcd_clear_display();
1229 while(1)
1231 switch(currval)
1233 case 0:
1234 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1235 break;
1236 case 1:
1237 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1238 break;
1239 case 2:
1240 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1241 break;
1242 case 3:
1243 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1244 break;
1245 case 4:
1246 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1247 break;
1248 case 5:
1249 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1250 break;
1251 case 6:
1252 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1253 break;
1254 case 7:
1255 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1256 break;
1257 case 8:
1258 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1259 break;
1260 case 9:
1261 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1262 break;
1264 lcd_puts(0, 0, buf);
1266 battery_read_info(&adc_battery_voltage, NULL);
1267 debug_printf(1, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1268 adc_battery_voltage % 1000);
1269 lcd_update();
1271 button = get_action(CONTEXT_SETTINGS,HZ/5);
1273 switch(button)
1275 case ACTION_STD_CANCEL:
1276 return false;
1278 case ACTION_SETTINGS_DEC:
1279 currval--;
1280 if(currval < 0)
1281 currval = 9;
1282 break;
1284 case ACTION_SETTINGS_INC:
1285 currval++;
1286 if(currval > 9)
1287 currval = 0;
1288 break;
1291 return false;
1293 #endif /* !HAVE_LCD_BITMAP */
1294 #endif /* !SIMULATOR */
1296 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1297 static bool dbg_pcf(void)
1299 int line;
1301 #ifdef HAVE_LCD_BITMAP
1302 lcd_setfont(FONT_SYSFIXED);
1303 #endif
1304 lcd_clear_display();
1306 while(1)
1308 line = 0;
1310 debug_printf(line++, "DCDC1: %02x", pcf50605_read(0x1b));
1311 debug_printf(line++, "DCDC2: %02x", pcf50605_read(0x1c));
1312 debug_printf(line++, "DCDC3: %02x", pcf50605_read(0x1d));
1313 debug_printf(line++, "DCDC4: %02x", pcf50605_read(0x1e));
1314 debug_printf(line++, "DCDEC1: %02x", pcf50605_read(0x1f));
1315 debug_printf(line++, "DCDEC2: %02x", pcf50605_read(0x20));
1316 debug_printf(line++, "DCUDC1: %02x", pcf50605_read(0x21));
1317 debug_printf(line++, "DCUDC2: %02x", pcf50605_read(0x22));
1318 debug_printf(line++, "IOREGC: %02x", pcf50605_read(0x23));
1319 debug_printf(line++, "D1REGC: %02x", pcf50605_read(0x24));
1320 debug_printf(line++, "D2REGC: %02x", pcf50605_read(0x25));
1321 debug_printf(line++, "D3REGC: %02x", pcf50605_read(0x26));
1322 debug_printf(line++, "LPREG1: %02x", pcf50605_read(0x27));
1323 lcd_update();
1324 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1326 lcd_setfont(FONT_UI);
1327 return false;
1331 lcd_setfont(FONT_UI);
1332 return false;
1334 #endif
1336 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1337 static bool dbg_cpufreq(void)
1339 int line;
1340 int button;
1342 #ifdef HAVE_LCD_BITMAP
1343 lcd_setfont(FONT_SYSFIXED);
1344 #endif
1345 lcd_clear_display();
1347 while(1)
1349 line = 0;
1351 debug_printf(line++, "Frequency: %ld", FREQ);
1352 debug_printf(line++, "boost_counter: %d", get_cpu_boost_counter());
1354 lcd_update();
1355 button = get_action(CONTEXT_STD,HZ/10);
1357 switch(button)
1359 case ACTION_STD_PREV:
1360 cpu_boost(true);
1361 break;
1363 case ACTION_STD_NEXT:
1364 cpu_boost(false);
1365 break;
1367 case ACTION_STD_OK:
1368 while (get_cpu_boost_counter() > 0)
1369 cpu_boost(false);
1370 set_cpu_frequency(CPUFREQ_DEFAULT);
1371 break;
1373 case ACTION_STD_CANCEL:
1374 lcd_setfont(FONT_UI);
1375 return false;
1378 lcd_setfont(FONT_UI);
1379 return false;
1381 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1383 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1384 #include "tsc2100.h"
1385 static char *itob(int n, int len)
1387 static char binary[64];
1388 int i,j;
1389 for (i=1, j=0;i<=len;i++)
1391 binary[j++] = n&(1<<(len-i))?'1':'0';
1392 if (i%4 == 0)
1393 binary[j++] = ' ';
1395 binary[j] = '\0';
1396 return binary;
1399 static const char* tsc2100_debug_getname(int selected_item, void * data,
1400 char *buffer, size_t buffer_len)
1402 int *page = (int*)data;
1403 bool reserved = false;
1404 switch (*page)
1406 case 0:
1407 if ((selected_item > 0x0a) ||
1408 (selected_item == 0x04) ||
1409 (selected_item == 0x08))
1410 reserved = true;
1411 break;
1412 case 1:
1413 if ((selected_item > 0x05) ||
1414 (selected_item == 0x02))
1415 reserved = true;
1416 break;
1417 case 2:
1418 if (selected_item > 0x1e)
1419 reserved = true;
1420 break;
1422 if (reserved)
1423 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1424 else
1425 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1426 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1427 return buffer;
1429 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1431 int *page = (int*)lists->data;
1432 if (action == ACTION_STD_OK)
1434 *page = (*page+1)%3;
1435 snprintf(lists->title, 32,
1436 "tsc2100 registers - Page %d", *page);
1437 return ACTION_REDRAW;
1439 return action;
1441 static bool tsc2100_debug(void)
1443 int page = 0;
1444 char title[32] = "tsc2100 registers - Page 0";
1445 struct simplelist_info info;
1446 simplelist_info_init(&info, title, 32, &page);
1447 info.timeout = HZ/100;
1448 info.get_name = tsc2100_debug_getname;
1449 info.action_callback= tsc2100debug_action_callback;
1450 return simplelist_show_list(&info);
1452 #endif
1453 #ifndef SIMULATOR
1454 #ifdef HAVE_LCD_BITMAP
1456 * view_battery() shows a automatically scaled graph of the battery voltage
1457 * over time. Usable for estimating battery life / charging rate.
1458 * The power_history array is updated in power_thread of powermgmt.c.
1461 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1462 #define BAT_YSPACE (LCD_HEIGHT - 20)
1464 static bool view_battery(void)
1466 int view = 0;
1467 int i, x, y;
1468 unsigned short maxv, minv;
1470 lcd_setfont(FONT_SYSFIXED);
1472 while(1)
1474 lcd_clear_display();
1475 switch (view) {
1476 case 0: /* voltage history graph */
1477 /* Find maximum and minimum voltage for scaling */
1478 minv = power_history[0];
1479 maxv = minv + 1;
1480 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1481 if (power_history[i] > maxv)
1482 maxv = power_history[i];
1483 if (power_history[i] < minv)
1484 minv = power_history[i];
1487 debug_printf(0, "Battery %d.%03d", power_history[0] / 1000,
1488 power_history[0] % 1000);
1489 debug_printf(1, "scale %d.%03d-%d.%03dV",
1490 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1492 x = 0;
1493 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1494 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1495 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1496 lcd_vline(x, LCD_HEIGHT-1, 20);
1497 lcd_set_drawmode(DRMODE_SOLID);
1498 lcd_vline(x, LCD_HEIGHT-1,
1499 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1500 x++;
1503 break;
1505 case 1: /* status: */
1506 lcd_puts(0, 0, "Power status:");
1508 battery_read_info(&y, NULL);
1509 debug_printf(1, "Battery: %d.%03d V", y / 1000, y % 1000);
1510 #ifdef ADC_EXT_POWER
1511 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1512 debug_printf(2, "External: %d.%03d V", y / 1000, y % 1000);
1513 #endif
1514 #if CONFIG_CHARGING
1515 #if defined ARCHOS_RECORDER
1516 debug_printf(3, "Chgr: %s %s",
1517 charger_inserted() ? "present" : "absent",
1518 charger_enabled() ? "on" : "off");
1519 debug_printf(5, "short delta: %d", short_delta);
1520 debug_printf(6, "long delta: %d", long_delta);
1521 lcd_puts(0, 7, power_message);
1522 debug_printf(8, "USB Inserted: %s",
1523 usb_inserted() ? "yes" : "no");
1524 #elif defined IRIVER_H300_SERIES
1525 debug_printf(9, "USB Charging Enabled: %s",
1526 usb_charging_enabled() ? "yes" : "no");
1527 #elif defined IPOD_NANO || defined IPOD_VIDEO
1528 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1529 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1530 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1531 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1532 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1534 debug_printf(3, "USB pwr: %s",
1535 usb_pwr ? "present" : "absent");
1536 debug_printf(4, "EXT pwr: %s",
1537 ext_pwr ? "present" : "absent");
1538 debug_printf(5, "Battery: %s",
1539 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1540 debug_printf(6, "Dock mode: %s",
1541 dock ? "enabled" : "disabled");
1542 debug_printf(7, "Headphone: %s",
1543 headphone ? "connected" : "disconnected");
1544 #elif defined TOSHIBA_GIGABEAT_S
1545 int line = 3;
1546 unsigned int st;
1548 static const unsigned char * const chrgstate_strings[] =
1550 "Disabled",
1551 "Error",
1552 "Discharging",
1553 "Precharge",
1554 "Constant Voltage",
1555 "Constant Current",
1556 "<unknown>",
1559 debug_printf(line++, "Charger: %s",
1560 charger_inserted() ? "present" : "absent");
1562 st = power_input_status() &
1563 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1564 debug_printf(line++, "%s%s",
1565 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1566 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1568 debug_printf(line++, "IUSB Max: %d", usb_allowed_current());
1570 y = ARRAYLEN(chrgstate_strings) - 1;
1572 switch (charge_state)
1574 case CHARGE_STATE_DISABLED: y--;
1575 case CHARGE_STATE_ERROR: y--;
1576 case DISCHARGING: y--;
1577 case TRICKLE: y--;
1578 case TOPOFF: y--;
1579 case CHARGING: y--;
1580 default:;
1583 debug_printf(line++, "State: %s", chrgstate_strings[y]);
1585 debug_printf(line++, "Battery Switch: %s",
1586 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1588 y = chrgraw_adc_voltage();
1589 debug_printf(line++, "CHRGRAW: %d.%03d V",
1590 y / 1000, y % 1000);
1592 y = application_supply_adc_voltage();
1593 debug_printf(line++, "BP : %d.%03d V",
1594 y / 1000, y % 1000);
1596 y = battery_adc_charge_current();
1597 if (y < 0) x = '-', y = -y;
1598 else x = ' ';
1599 debug_printf(line++, "CHRGISN:%c%d mA", x, y);
1601 y = cccv_regulator_dissipation();
1602 debug_printf(line++, "P CCCV : %d mW", y);
1604 y = battery_charge_current();
1605 if (y < 0) x = '-', y = -y;
1606 else x = ' ';
1607 debug_printf(line++, "I Charge:%c%d mA", x, y);
1609 y = battery_adc_temp();
1611 if (y != INT_MIN) {
1612 debug_printf(line++, "T Battery: %dC (%dF)", y,
1613 (9*y + 160) / 5);
1614 } else {
1615 /* Conversion disabled */
1616 lcd_puts(0, line++, "T Battery: ?");
1619 #elif defined(SANSA_E200) || defined(SANSA_C200) || defined(SANSA_CLIP) || defined(SANSA_FUZE)
1620 const int first = CHARGE_STATE_DISABLED;
1621 static const char * const chrgstate_strings[] =
1623 [CHARGE_STATE_DISABLED-first] = "Disabled",
1624 [CHARGE_STATE_ERROR-first] = "Error",
1625 [DISCHARGING-first] = "Discharging",
1626 [CHARGING-first] = "Charging",
1628 const char *str = NULL;
1630 debug_printf(3, "Charger: %s",
1631 charger_inserted() ? "present" : "absent");
1633 y = charge_state - first;
1634 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1635 str = chrgstate_strings[y];
1637 debug_printf(4, "State: %s",
1638 str ? str : "<unknown>");
1640 debug_printf(5, "CHARGER: %02X",
1641 ascodec_read(AS3514_CHARGER));
1642 #elif defined(IPOD_NANO2G)
1643 y = pmu_read_battery_current();
1644 debug_printf(2, "Battery current: %d mA", y);
1645 #else
1646 debug_printf(3, "Charger: %s",
1647 charger_inserted() ? "present" : "absent");
1648 #endif /* target type */
1649 #endif /* CONFIG_CHARGING */
1650 break;
1652 case 2: /* voltage deltas: */
1653 lcd_puts(0, 0, "Voltage deltas:");
1655 for (i = 0; i <= 6; i++) {
1656 y = power_history[i] - power_history[i+1];
1657 debug_printf(i+1, "-%d min: %s%d.%03d V", i,
1658 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1659 ((y < 0) ? y * -1 : y ) % 1000);
1661 break;
1663 case 3: /* remaining time estimation: */
1665 #ifdef ARCHOS_RECORDER
1666 debug_printf(0, "charge_state: %d", charge_state);
1668 debug_printf(1, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1670 debug_printf(2, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1672 debug_printf(3, "P=%2d I=%2d", pid_p, pid_i);
1674 debug_printf(4, "Trickle sec: %d/60", trickle_sec);
1675 #endif /* ARCHOS_RECORDER */
1677 debug_printf(5, "Last PwrHist: %d.%03dV",
1678 power_history[0] / 1000,
1679 power_history[0] % 1000);
1681 debug_printf(6, "battery level: %d%%", battery_level());
1683 debug_printf(7, "Est. remain: %d m", battery_time());
1684 break;
1687 lcd_update();
1689 switch(get_action(CONTEXT_STD,HZ/2))
1691 case ACTION_STD_PREV:
1692 if (view)
1693 view--;
1694 break;
1696 case ACTION_STD_NEXT:
1697 if (view < 3)
1698 view++;
1699 break;
1701 case ACTION_STD_CANCEL:
1702 lcd_setfont(FONT_UI);
1703 return false;
1706 lcd_setfont(FONT_UI);
1707 return false;
1710 #endif /* HAVE_LCD_BITMAP */
1711 #endif
1713 #ifndef SIMULATOR
1714 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1716 #if (CONFIG_STORAGE & STORAGE_MMC)
1717 #define CARDTYPE "MMC"
1718 #elif (CONFIG_STORAGE & STORAGE_SD)
1719 #define CARDTYPE "microSD"
1720 #endif
1722 static int disk_callback(int btn, struct gui_synclist *lists)
1724 tCardInfo *card;
1725 int *cardnum = (int*)lists->data;
1726 unsigned char card_name[7];
1727 unsigned char pbuf[32];
1728 char *title = lists->title;
1729 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1730 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1731 static const unsigned char * const kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1732 static const unsigned char * const nsec_units[] = { "ns", "µs", "ms" };
1733 #if (CONFIG_STORAGE & STORAGE_MMC)
1734 static const char * const mmc_spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1735 "3.1-3.31", "4.0" };
1736 #endif
1738 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1740 #ifdef HAVE_HOTSWAP
1741 if (btn == ACTION_STD_OK)
1743 *cardnum ^= 0x1; /* change cards */
1745 #endif
1747 simplelist_set_line_count(0);
1749 card = card_get_info(*cardnum);
1751 if (card->initialized > 0)
1753 strlcpy(card_name, ((unsigned char*)card->cid) + 3, sizeof(card_name));
1754 simplelist_addline(SIMPLELIST_ADD_LINE,
1755 "%s Rev %d.%d", card_name,
1756 (int) card_extract_bits(card->cid, 55, 4),
1757 (int) card_extract_bits(card->cid, 51, 4));
1758 simplelist_addline(SIMPLELIST_ADD_LINE,
1759 "Prod: %d/%d",
1760 #if (CONFIG_STORAGE & STORAGE_SD)
1761 (int) card_extract_bits(card->cid, 11, 3),
1762 (int) card_extract_bits(card->cid, 19, 8) + 2000
1763 #elif (CONFIG_STORAGE & STORAGE_MMC)
1764 (int) card_extract_bits(card->cid, 15, 4),
1765 (int) card_extract_bits(card->cid, 11, 4) + 1997
1766 #endif
1768 simplelist_addline(SIMPLELIST_ADD_LINE,
1769 #if (CONFIG_STORAGE & STORAGE_SD)
1770 "Ser#: 0x%08lx",
1771 card_extract_bits(card->cid, 55, 32)
1772 #elif (CONFIG_STORAGE & STORAGE_MMC)
1773 "Ser#: 0x%04lx",
1774 card_extract_bits(card->cid, 47, 16)
1775 #endif
1778 simplelist_addline(SIMPLELIST_ADD_LINE, "M=%02x, "
1779 #if (CONFIG_STORAGE & STORAGE_SD)
1780 "O=%c%c",
1781 (int) card_extract_bits(card->cid, 127, 8),
1782 card_extract_bits(card->cid, 119, 8),
1783 card_extract_bits(card->cid, 111, 8)
1784 #elif (CONFIG_STORAGE & STORAGE_MMC)
1785 "O=%04x",
1786 (int) card_extract_bits(card->cid, 127, 8),
1787 (int) card_extract_bits(card->cid, 119, 16)
1788 #endif
1791 #if (CONFIG_STORAGE & STORAGE_MMC)
1792 int temp = card_extract_bits(card->csd, 125, 4);
1793 simplelist_addline(SIMPLELIST_ADD_LINE,
1794 "MMC v%s", temp < 5 ?
1795 mmc_spec_vers[temp] : "?.?");
1796 #endif
1797 simplelist_addline(SIMPLELIST_ADD_LINE,
1798 "Blocks: 0x%08lx", card->numblocks);
1799 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1800 kbit_units, false);
1801 simplelist_addline(SIMPLELIST_ADD_LINE,
1802 "Speed: %s", pbuf);
1803 output_dyn_value(pbuf, sizeof pbuf, card->taac,
1804 nsec_units, false);
1805 simplelist_addline(SIMPLELIST_ADD_LINE,
1806 "Taac: %s", pbuf);
1807 simplelist_addline(SIMPLELIST_ADD_LINE,
1808 "Nsac: %d clk", card->nsac);
1809 simplelist_addline(SIMPLELIST_ADD_LINE,
1810 "R2W: *%d", card->r2w_factor);
1811 simplelist_addline(SIMPLELIST_ADD_LINE,
1812 "IRmax: %d..%d mA",
1813 i_vmin[card_extract_bits(card->csd, 61, 3)],
1814 i_vmax[card_extract_bits(card->csd, 58, 3)]);
1815 simplelist_addline(SIMPLELIST_ADD_LINE,
1816 "IWmax: %d..%d mA",
1817 i_vmin[card_extract_bits(card->csd, 55, 3)],
1818 i_vmax[card_extract_bits(card->csd, 52, 3)]);
1820 else if (card->initialized == 0)
1822 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1824 #if (CONFIG_STORAGE & STORAGE_SD)
1825 else /* card->initialized < 0 */
1827 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1829 #endif
1830 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1831 gui_synclist_set_title(lists, title, Icon_NOICON);
1832 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1833 gui_synclist_select_item(lists, 0);
1834 btn = ACTION_REDRAW;
1836 return btn;
1838 #elif (CONFIG_STORAGE & STORAGE_ATA)
1839 static int disk_callback(int btn, struct gui_synclist *lists)
1841 (void)lists;
1842 int i;
1843 char buf[128];
1844 unsigned short* identify_info = ata_get_identify();
1845 bool timing_info_present = false;
1846 (void)btn;
1848 simplelist_set_line_count(0);
1850 for (i=0; i < 20; i++)
1851 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1852 buf[40]=0;
1853 /* kill trailing space */
1854 for (i=39; i && buf[i]==' '; i--)
1855 buf[i] = 0;
1856 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1857 for (i=0; i < 4; i++)
1858 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1859 buf[8]=0;
1860 simplelist_addline(SIMPLELIST_ADD_LINE,
1861 "Firmware: %s", buf);
1862 snprintf(buf, sizeof buf, "%ld MB",
1863 ((unsigned long)identify_info[61] << 16 |
1864 (unsigned long)identify_info[60]) / 2048 );
1865 simplelist_addline(SIMPLELIST_ADD_LINE,
1866 "Size: %s", buf);
1867 unsigned long free;
1868 fat_size( IF_MV2(0,) NULL, &free );
1869 simplelist_addline(SIMPLELIST_ADD_LINE,
1870 "Free: %ld MB", free / 1024);
1871 simplelist_addline(SIMPLELIST_ADD_LINE,
1872 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
1873 i = identify_info[83] & (1<<3);
1874 simplelist_addline(SIMPLELIST_ADD_LINE,
1875 "Power mgmt: %s", i ? "enabled" : "unsupported");
1876 i = identify_info[83] & (1<<9);
1877 simplelist_addline(SIMPLELIST_ADD_LINE,
1878 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1879 i = identify_info[82] & (1<<6);
1880 simplelist_addline(SIMPLELIST_ADD_LINE,
1881 "Read-ahead: %s", i ? "enabled" : "unsupported");
1882 timing_info_present = identify_info[53] & (1<<1);
1883 if(timing_info_present) {
1884 char pio3[2], pio4[2];pio3[1] = 0;
1885 pio4[1] = 0;
1886 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1887 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1888 simplelist_addline(SIMPLELIST_ADD_LINE,
1889 "PIO modes: 0 1 2 %s %s", pio3, pio4);
1891 else {
1892 simplelist_addline(SIMPLELIST_ADD_LINE,
1893 "No PIO mode info");
1895 timing_info_present = identify_info[53] & (1<<1);
1896 if(timing_info_present) {
1897 simplelist_addline(SIMPLELIST_ADD_LINE,
1898 "Cycle times %dns/%dns",
1899 identify_info[67],
1900 identify_info[68] );
1901 } else {
1902 simplelist_addline(SIMPLELIST_ADD_LINE,
1903 "No timing info");
1905 #ifdef HAVE_ATA_DMA
1906 if (identify_info[63] & (1<<0)) {
1907 char mdma0[2], mdma1[2], mdma2[2];
1908 mdma0[1] = mdma1[1] = mdma2[1] = 0;
1909 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
1910 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
1911 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
1912 simplelist_addline(SIMPLELIST_ADD_LINE,
1913 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
1914 simplelist_addline(SIMPLELIST_ADD_LINE,
1915 "MDMA Cycle times %dns/%dns",
1916 identify_info[65],
1917 identify_info[66] );
1919 else {
1920 simplelist_addline(SIMPLELIST_ADD_LINE,
1921 "No MDMA mode info");
1923 if (identify_info[53] & (1<<2)) {
1924 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2], udma6[2];
1925 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = udma6[1] = 0;
1926 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
1927 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
1928 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
1929 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
1930 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
1931 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
1932 udma6[0] = (identify_info[88] & (1<<6)) ? '6' : 0;
1933 simplelist_addline(SIMPLELIST_ADD_LINE,
1934 "UDMA modes: %s %s %s %s %s %s %s", udma0, udma1, udma2,
1935 udma3, udma4, udma5, udma6);
1937 else {
1938 simplelist_addline(SIMPLELIST_ADD_LINE,
1939 "No UDMA mode info");
1941 #endif /* HAVE_ATA_DMA */
1942 timing_info_present = identify_info[53] & (1<<1);
1943 if(timing_info_present) {
1944 i = identify_info[49] & (1<<11);
1945 simplelist_addline(SIMPLELIST_ADD_LINE,
1946 "IORDY support: %s", i ? "yes" : "no");
1947 i = identify_info[49] & (1<<10);
1948 simplelist_addline(SIMPLELIST_ADD_LINE,
1949 "IORDY disable: %s", i ? "yes" : "no");
1950 } else {
1951 simplelist_addline(SIMPLELIST_ADD_LINE,
1952 "No timing info");
1954 simplelist_addline(SIMPLELIST_ADD_LINE,
1955 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1956 #ifdef HAVE_ATA_DMA
1957 i = ata_get_dma_mode();
1958 if (i == 0) {
1959 simplelist_addline(SIMPLELIST_ADD_LINE,
1960 "DMA not enabled");
1961 } else {
1962 simplelist_addline(SIMPLELIST_ADD_LINE,
1963 "DMA mode: %s %c",
1964 (i & 0x40) ? "UDMA" : "MDMA",
1965 '0' + (i & 7));
1967 #endif /* HAVE_ATA_DMA */
1968 return btn;
1970 #else /* No SD, MMC or ATA */
1971 static int disk_callback(int btn, struct gui_synclist *lists)
1973 (void)btn;
1974 (void)lists;
1975 struct storage_info info;
1976 storage_get_info(0,&info);
1977 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
1978 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
1979 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
1980 simplelist_addline(SIMPLELIST_ADD_LINE,
1981 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
1982 unsigned long free;
1983 fat_size( IF_MV2(0,) NULL, &free );
1984 simplelist_addline(SIMPLELIST_ADD_LINE,
1985 "Free: %ld MB", free / 1024);
1986 simplelist_addline(SIMPLELIST_ADD_LINE,
1987 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1988 return btn;
1990 #endif
1992 #if (CONFIG_STORAGE & STORAGE_ATA)
1993 static bool dbg_identify_info(void)
1995 int fd = creat("/identify_info.bin");
1996 if(fd >= 0)
1998 #ifdef ROCKBOX_LITTLE_ENDIAN
1999 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
2000 #else
2001 write(fd, ata_get_identify(), SECTOR_SIZE);
2002 #endif
2003 close(fd);
2005 return false;
2007 #endif
2009 static bool dbg_disk_info(void)
2011 struct simplelist_info info;
2012 simplelist_info_init(&info, "Disk Info", 1, NULL);
2013 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
2014 char title[16];
2015 int card = 0;
2016 info.callback_data = (void*)&card;
2017 info.title = title;
2018 #endif
2019 info.action_callback = disk_callback;
2020 info.hide_selection = true;
2021 info.scroll_all = true;
2022 return simplelist_show_list(&info);
2024 #endif /* !SIMULATOR */
2026 #ifdef HAVE_DIRCACHE
2027 static int dircache_callback(int btn, struct gui_synclist *lists)
2029 (void)btn; (void)lists;
2030 simplelist_set_line_count(0);
2031 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
2032 dircache_is_enabled() ? "Yes" : "No");
2033 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
2034 dircache_get_cache_size());
2035 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
2036 global_status.dircache_size);
2037 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
2038 DIRCACHE_LIMIT);
2039 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
2040 dircache_get_reserve_used(), DIRCACHE_RESERVE);
2041 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2042 dircache_get_build_ticks() / HZ);
2043 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2044 dircache_get_entry_count());
2045 return btn;
2048 static bool dbg_dircache_info(void)
2050 struct simplelist_info info;
2051 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2052 info.action_callback = dircache_callback;
2053 info.hide_selection = true;
2054 info.scroll_all = true;
2055 return simplelist_show_list(&info);
2058 #endif /* HAVE_DIRCACHE */
2060 #ifdef HAVE_TAGCACHE
2061 static int database_callback(int btn, struct gui_synclist *lists)
2063 (void)lists;
2064 struct tagcache_stat *stat = tagcache_get_stat();
2065 static bool synced = false;
2067 simplelist_set_line_count(0);
2069 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2070 stat->initialized ? "Yes" : "No");
2071 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2072 stat->ready ? "Yes" : "No");
2073 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2074 stat->ramcache ? "Yes" : "No");
2075 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2076 stat->ramcache_used, stat->ramcache_allocated);
2077 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2078 stat->progress, stat->processed_entries);
2079 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2080 stat->curentry ? stat->curentry : "---");
2081 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2082 stat->commit_step);
2083 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2084 stat->commit_delayed ? "Yes" : "No");
2086 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2087 stat->queue_length);
2089 if (synced)
2091 synced = false;
2092 tagcache_screensync_event();
2095 if (!btn && stat->curentry)
2097 synced = true;
2098 return ACTION_REDRAW;
2101 if (btn == ACTION_STD_CANCEL)
2102 tagcache_screensync_enable(false);
2104 return btn;
2106 static bool dbg_tagcache_info(void)
2108 struct simplelist_info info;
2109 simplelist_info_init(&info, "Database Info", 8, NULL);
2110 info.action_callback = database_callback;
2111 info.hide_selection = true;
2112 info.scroll_all = true;
2114 /* Don't do nonblock here, must give enough processing time
2115 for tagcache thread. */
2116 /* info.timeout = TIMEOUT_NOBLOCK; */
2117 info.timeout = 1;
2118 tagcache_screensync_enable(true);
2119 return simplelist_show_list(&info);
2121 #endif
2123 #if CONFIG_CPU == SH7034
2124 static bool dbg_save_roms(void)
2126 int fd;
2127 int oldmode = system_memory_guard(MEMGUARD_NONE);
2129 fd = creat("/internal_rom_0000-FFFF.bin");
2130 if(fd >= 0)
2132 write(fd, (void *)0, 0x10000);
2133 close(fd);
2136 fd = creat("/internal_rom_2000000-203FFFF.bin");
2137 if(fd >= 0)
2139 write(fd, (void *)0x2000000, 0x40000);
2140 close(fd);
2143 system_memory_guard(oldmode);
2144 return false;
2146 #elif defined CPU_COLDFIRE
2147 static bool dbg_save_roms(void)
2149 int fd;
2150 int oldmode = system_memory_guard(MEMGUARD_NONE);
2152 #if defined(IRIVER_H100_SERIES)
2153 fd = creat("/internal_rom_000000-1FFFFF.bin");
2154 #elif defined(IRIVER_H300_SERIES)
2155 fd = creat("/internal_rom_000000-3FFFFF.bin");
2156 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2157 fd = creat("/internal_rom_000000-3FFFFF.bin");
2158 #endif
2159 if(fd >= 0)
2161 write(fd, (void *)0, FLASH_SIZE);
2162 close(fd);
2164 system_memory_guard(oldmode);
2166 #ifdef HAVE_EEPROM
2167 fd = creat("/internal_eeprom.bin");
2168 if (fd >= 0)
2170 int old_irq_level;
2171 char buf[EEPROM_SIZE];
2172 int err;
2174 old_irq_level = disable_irq_save();
2176 err = eeprom_24cxx_read(0, buf, sizeof buf);
2178 restore_irq(old_irq_level);
2180 if (err)
2181 splashf(HZ*3, "Eeprom read failure (%d)", err);
2182 else
2184 write(fd, buf, sizeof buf);
2187 close(fd);
2189 #endif
2191 return false;
2193 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
2194 static bool dbg_save_roms(void)
2196 int fd;
2198 fd = creat("/internal_rom_000000-0FFFFF.bin");
2199 if(fd >= 0)
2201 write(fd, (void *)0x20000000, FLASH_SIZE);
2202 close(fd);
2205 return false;
2207 #elif CONFIG_CPU == IMX31L
2208 static bool dbg_save_roms(void)
2210 int fd;
2212 fd = creat("/flash_rom_A0000000-A01FFFFF.bin");
2213 if (fd >= 0)
2215 write(fd, (void*)0xa0000000, FLASH_SIZE);
2216 close(fd);
2219 return false;
2221 #endif /* CPU */
2223 #ifndef SIMULATOR
2224 #if CONFIG_TUNER
2225 static int radio_callback(int btn, struct gui_synclist *lists)
2227 (void)lists;
2228 if (btn == ACTION_STD_CANCEL)
2229 return btn;
2230 simplelist_set_line_count(1);
2232 #if (CONFIG_TUNER & LV24020LP)
2233 simplelist_addline(SIMPLELIST_ADD_LINE,
2234 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2235 simplelist_addline(SIMPLELIST_ADD_LINE,
2236 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2237 simplelist_addline(SIMPLELIST_ADD_LINE,
2238 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2239 simplelist_addline(SIMPLELIST_ADD_LINE,
2240 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2241 simplelist_addline(SIMPLELIST_ADD_LINE,
2242 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2243 simplelist_addline(SIMPLELIST_ADD_LINE,
2244 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2245 simplelist_addline(SIMPLELIST_ADD_LINE,
2246 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2247 #endif /* LV24020LP */
2248 #if (CONFIG_TUNER & S1A0903X01)
2249 simplelist_addline(SIMPLELIST_ADD_LINE,
2250 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2251 /* This one doesn't return dynamic data atm */
2252 #endif /* S1A0903X01 */
2253 #if (CONFIG_TUNER & TEA5767)
2254 struct tea5767_dbg_info nfo;
2255 tea5767_dbg_info(&nfo);
2256 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2257 simplelist_addline(SIMPLELIST_ADD_LINE,
2258 " Read: %02X %02X %02X %02X %02X",
2259 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2260 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2261 (unsigned)nfo.read_regs[4]);
2262 simplelist_addline(SIMPLELIST_ADD_LINE,
2263 " Write: %02X %02X %02X %02X %02X",
2264 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2265 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2266 (unsigned)nfo.write_regs[4]);
2267 #endif /* TEA5767 */
2268 #if (CONFIG_TUNER & SI4700)
2269 struct si4700_dbg_info nfo;
2270 si4700_dbg_info(&nfo);
2271 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
2272 /* Registers */
2273 simplelist_addline(SIMPLELIST_ADD_LINE,
2274 "%04X %04X %04X %04X",
2275 (unsigned)nfo.regs[0], (unsigned)nfo.regs[1],
2276 (unsigned)nfo.regs[2], (unsigned)nfo.regs[3]);
2277 simplelist_addline(SIMPLELIST_ADD_LINE,
2278 "%04X %04X %04X %04X",
2279 (unsigned)nfo.regs[4], (unsigned)nfo.regs[5],
2280 (unsigned)nfo.regs[6], (unsigned)nfo.regs[7]);
2281 simplelist_addline(SIMPLELIST_ADD_LINE,
2282 "%04X %04X %04X %04X",
2283 (unsigned)nfo.regs[8], (unsigned)nfo.regs[9],
2284 (unsigned)nfo.regs[10], (unsigned)nfo.regs[11]);
2285 simplelist_addline(SIMPLELIST_ADD_LINE,
2286 "%04X %04X %04X %04X",
2287 (unsigned)nfo.regs[12], (unsigned)nfo.regs[13],
2288 (unsigned)nfo.regs[14], (unsigned)nfo.regs[15]);
2289 #endif /* SI4700 */
2290 return ACTION_REDRAW;
2292 static bool dbg_fm_radio(void)
2294 struct simplelist_info info;
2295 info.scroll_all = true;
2296 simplelist_info_init(&info, "FM Radio", 1, NULL);
2297 simplelist_set_line_count(0);
2298 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2299 radio_hardware_present() ? "yes" : "no");
2301 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2302 info.hide_selection = true;
2303 return simplelist_show_list(&info);
2305 #endif /* CONFIG_TUNER */
2306 #endif /* !SIMULATOR */
2308 #ifdef HAVE_LCD_BITMAP
2309 extern bool do_screendump_instead_of_usb;
2311 static bool dbg_screendump(void)
2313 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2314 splashf(HZ, "Screendump %s",
2315 do_screendump_instead_of_usb?"enabled":"disabled");
2316 return false;
2318 #endif /* HAVE_LCD_BITMAP */
2320 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2321 static bool dbg_set_memory_guard(void)
2323 static const struct opt_items names[MAXMEMGUARD] = {
2324 { "None", -1 },
2325 { "Flash ROM writes", -1 },
2326 { "Zero area (all)", -1 }
2328 int mode = system_memory_guard(MEMGUARD_KEEP);
2330 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2331 system_memory_guard(mode);
2333 return false;
2335 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2337 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2338 static bool dbg_write_eeprom(void)
2340 int fd;
2341 int rc;
2342 int old_irq_level;
2343 char buf[EEPROM_SIZE];
2344 int err;
2346 fd = open("/internal_eeprom.bin", O_RDONLY);
2348 if (fd >= 0)
2350 rc = read(fd, buf, EEPROM_SIZE);
2352 if(rc == EEPROM_SIZE)
2354 old_irq_level = disable_irq_save();
2356 err = eeprom_24cxx_write(0, buf, sizeof buf);
2357 if (err)
2358 splashf(HZ*3, "Eeprom write failure (%d)", err);
2359 else
2360 splash(HZ*3, "Eeprom written successfully");
2362 restore_irq(old_irq_level);
2364 else
2366 splashf(HZ*3, "File read error (%d)",rc);
2368 close(fd);
2370 else
2372 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2375 return false;
2377 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2378 #ifdef CPU_BOOST_LOGGING
2379 static bool cpu_boost_log(void)
2381 int i = 0,j=0;
2382 int count = cpu_boost_log_getcount();
2383 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2384 char *str;
2385 bool done;
2386 lcd_setfont(FONT_SYSFIXED);
2387 str = cpu_boost_log_getlog_first();
2388 while (i < count)
2390 lcd_clear_display();
2391 for(j=0; j<lines; j++,i++)
2393 if (!str)
2394 str = cpu_boost_log_getlog_next();
2395 if (str)
2397 if(strlen(str) > LCD_WIDTH/SYSFONT_WIDTH)
2398 lcd_puts_scroll(0, j, str);
2399 else
2400 lcd_puts(0, j,str);
2402 str = NULL;
2404 lcd_update();
2405 done = false;
2406 while (!done)
2408 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2410 case ACTION_STD_OK:
2411 case ACTION_STD_PREV:
2412 case ACTION_STD_NEXT:
2413 done = true;
2414 break;
2415 case ACTION_STD_CANCEL:
2416 i = count;
2417 done = true;
2418 break;
2422 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2423 lcd_setfont(FONT_UI);
2424 return false;
2426 #endif
2428 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2429 extern bool wheel_is_touched;
2430 extern int old_wheel_value;
2431 extern int new_wheel_value;
2432 extern int wheel_delta;
2433 extern unsigned int accumulated_wheel_delta;
2434 extern unsigned int wheel_velocity;
2436 static bool dbg_scrollwheel(void)
2438 unsigned int speed;
2440 lcd_setfont(FONT_SYSFIXED);
2442 while (1)
2444 if (action_userabort(HZ/10))
2445 break;
2447 lcd_clear_display();
2449 /* show internal variables of scrollwheel driver */
2450 debug_printf(0, "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2451 debug_printf(1, "new position: %2d", new_wheel_value);
2452 debug_printf(2, "old position: %2d", old_wheel_value);
2453 debug_printf(3, "wheel delta: %2d", wheel_delta);
2454 debug_printf(4, "accumulated delta: %2d", accumulated_wheel_delta);
2455 debug_printf(5, "velo [deg/s]: %4d", (int)wheel_velocity);
2457 /* show effective accelerated scrollspeed */
2458 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2459 debug_printf(6, "accel. speed: %4d", speed);
2461 lcd_update();
2463 lcd_setfont(FONT_UI);
2464 return false;
2466 #endif
2468 #if defined (HAVE_USBSTACK)
2470 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2471 static bool toggle_usb_core_driver(int driver, char *msg)
2473 bool enabled = !usb_core_driver_enabled(driver);
2475 usb_core_enable_driver(driver,enabled);
2476 splashf(HZ, "%s %s", msg, enabled?"enabled":"disabled");
2478 return false;
2481 static bool toggle_usb_serial(void)
2483 return toggle_usb_core_driver(USB_DRIVER_SERIAL,"USB Serial");
2485 #endif
2487 #endif
2489 #if CONFIG_USBOTG == USBOTG_ISP1583
2490 extern int dbg_usb_num_items(void);
2491 extern const char* dbg_usb_item(int selected_item, void *data,
2492 char *buffer, size_t buffer_len);
2494 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2496 (void)lists;
2497 if (action == ACTION_NONE)
2498 action = ACTION_REDRAW;
2499 return action;
2502 static bool dbg_isp1583(void)
2504 struct simplelist_info isp1583;
2505 isp1583.scroll_all = true;
2506 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2507 isp1583.timeout = HZ/100;
2508 isp1583.hide_selection = true;
2509 isp1583.get_name = dbg_usb_item;
2510 isp1583.action_callback = isp1583_action_callback;
2511 return simplelist_show_list(&isp1583);
2513 #endif
2515 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2516 extern int pic_dbg_num_items(void);
2517 extern const char* pic_dbg_item(int selected_item, void *data,
2518 char *buffer, size_t buffer_len);
2520 static int pic_action_callback(int action, struct gui_synclist *lists)
2522 (void)lists;
2523 if (action == ACTION_NONE)
2524 action = ACTION_REDRAW;
2525 return action;
2528 static bool dbg_pic(void)
2530 struct simplelist_info pic;
2531 pic.scroll_all = true;
2532 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2533 pic.timeout = HZ/100;
2534 pic.hide_selection = true;
2535 pic.get_name = pic_dbg_item;
2536 pic.action_callback = pic_action_callback;
2537 return simplelist_show_list(&pic);
2539 #endif
2542 /****** The menu *********/
2543 struct the_menu_item {
2544 unsigned char *desc; /* string or ID */
2545 bool (*function) (void); /* return true if USB was connected */
2547 static const struct the_menu_item menuitems[] = {
2548 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2549 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)) || \
2550 CONFIG_CPU == IMX31L
2551 { "Dump ROM contents", dbg_save_roms },
2552 #endif
2553 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2554 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 \
2555 || CONFIG_CPU == DM320 || defined(CPU_S5L870X)
2556 { "View I/O ports", dbg_ports },
2557 #endif
2558 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2559 { "View PCF registers", dbg_pcf },
2560 #endif
2561 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2562 { "TSC2100 debug", tsc2100_debug },
2563 #endif
2564 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2565 { "CPU frequency", dbg_cpufreq },
2566 #endif
2567 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2568 { "S/PDIF analyzer", dbg_spdif },
2569 #endif
2570 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2571 { "Catch mem accesses", dbg_set_memory_guard },
2572 #endif
2573 { "View OS stacks", dbg_os },
2574 #ifdef HAVE_LCD_BITMAP
2575 #ifndef SIMULATOR
2576 { "View battery", view_battery },
2577 #endif
2578 { "Screendump", dbg_screendump },
2579 #endif
2580 #ifndef SIMULATOR
2581 { "View HW info", dbg_hw_info },
2582 #endif
2583 #ifndef SIMULATOR
2584 { "View partitions", dbg_partitions },
2585 #endif
2586 #ifndef SIMULATOR
2587 { "View disk info", dbg_disk_info },
2588 #if (CONFIG_STORAGE & STORAGE_ATA)
2589 { "Dump ATA identify info", dbg_identify_info},
2590 #endif
2591 #endif
2592 #ifdef HAVE_DIRCACHE
2593 { "View dircache info", dbg_dircache_info },
2594 #endif
2595 #ifdef HAVE_TAGCACHE
2596 { "View database info", dbg_tagcache_info },
2597 #endif
2598 #ifdef HAVE_LCD_BITMAP
2599 #if CONFIG_CODEC == SWCODEC
2600 { "View buffering thread", dbg_buffering_thread },
2601 #elif !defined(SIMULATOR)
2602 { "View audio thread", dbg_audio_thread },
2603 #endif
2604 #ifdef PM_DEBUG
2605 { "pm histogram", peak_meter_histogram},
2606 #endif /* PM_DEBUG */
2607 #endif /* HAVE_LCD_BITMAP */
2608 #ifndef SIMULATOR
2609 #if CONFIG_TUNER
2610 { "FM Radio", dbg_fm_radio },
2611 #endif
2612 #endif
2613 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2614 { "Write back EEPROM", dbg_write_eeprom },
2615 #endif
2616 #if CONFIG_USBOTG == USBOTG_ISP1583
2617 { "View ISP1583 info", dbg_isp1583 },
2618 #endif
2619 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2620 { "View PIC info", dbg_pic },
2621 #endif
2622 #ifdef ROCKBOX_HAS_LOGF
2623 {"logf", logfdisplay },
2624 {"logfdump", logfdump },
2625 #endif
2626 #if defined(HAVE_USBSTACK)
2627 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2628 {"USB Serial driver (logf)", toggle_usb_serial },
2629 #endif
2630 #endif /* HAVE_USBSTACK */
2631 #ifdef CPU_BOOST_LOGGING
2632 {"cpu_boost log",cpu_boost_log},
2633 #endif
2634 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2635 {"Debug scrollwheel", dbg_scrollwheel },
2636 #endif
2638 static int menu_action_callback(int btn, struct gui_synclist *lists)
2640 if (btn == ACTION_STD_OK)
2642 int oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL);
2643 menuitems[gui_synclist_get_sel_pos(lists)].function();
2644 btn = ACTION_REDRAW;
2645 send_event(GUI_EVENT_REFRESH, NULL);
2646 viewportmanager_set_statusbar(oldbars);
2648 return btn;
2651 static const char* dbg_menu_getname(int item, void * data,
2652 char *buffer, size_t buffer_len)
2654 (void)data; (void)buffer; (void)buffer_len;
2655 return menuitems[item].desc;
2658 bool debug_menu(void)
2660 struct simplelist_info info;
2662 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2663 info.action_callback = menu_action_callback;
2664 info.get_name = dbg_menu_getname;
2665 return simplelist_show_list(&info);