Make TTS name conversion functions static members.
[Rockbox.git] / apps / debug_menu.c
blobcc93b298b2b5e6d28d1f64518fba078e98bc2d84
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Heikki Hannikainen
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "config.h"
21 #include <stdio.h>
22 #include <stdbool.h>
23 #include <string.h>
24 #include "lcd.h"
25 #include "menu.h"
26 #include "debug_menu.h"
27 #include "kernel.h"
28 #include "sprintf.h"
29 #include "action.h"
30 #include "debug.h"
31 #include "thread.h"
32 #include "powermgmt.h"
33 #include "system.h"
34 #include "font.h"
35 #include "audio.h"
36 #include "mp3_playback.h"
37 #include "settings.h"
38 #include "list.h"
39 #include "statusbar.h"
40 #include "dir.h"
41 #include "panic.h"
42 #include "screens.h"
43 #include "misc.h"
44 #include "splash.h"
45 #include "dircache.h"
46 #ifdef HAVE_TAGCACHE
47 #include "tagcache.h"
48 #endif
49 #include "lcd-remote.h"
50 #include "crc32.h"
51 #include "logf.h"
52 #ifndef SIMULATOR
53 #include "disk.h"
54 #include "adc.h"
55 #include "power.h"
56 #include "usb.h"
57 #include "rtc.h"
58 #include "ata.h"
59 #include "fat.h"
60 #include "mas.h"
61 #include "eeprom_24cxx.h"
62 #if defined(HAVE_MMC) || defined(HAVE_HOTSWAP)
63 #include "ata_mmc.h"
64 #endif
65 #if CONFIG_TUNER
66 #include "tuner.h"
67 #include "radio.h"
68 #endif
69 #endif
71 #ifdef HAVE_LCD_BITMAP
72 #include "scrollbar.h"
73 #include "peakmeter.h"
74 #endif
75 #include "logfdisp.h"
76 #if CONFIG_CODEC == SWCODEC
77 #include "pcmbuf.h"
78 #include "buffering.h"
79 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
80 #include "spdif.h"
81 #endif
82 #endif
83 #ifdef IRIVER_H300_SERIES
84 #include "pcf50606.h" /* for pcf50606_read */
85 #endif
86 #ifdef IAUDIO_X5
87 #include "ds2411.h"
88 #endif
89 #include "hwcompat.h"
90 #include "button.h"
91 #if CONFIG_RTC == RTC_PCF50605
92 #include "pcf50605.h"
93 #endif
95 #if CONFIG_CPU == DM320 || CONFIG_CPU == S3C2440
96 #include "debug-target.h"
97 #endif
99 /*---------------------------------------------------*/
100 /* SPECIAL DEBUG STUFF */
101 /*---------------------------------------------------*/
102 extern struct thread_entry threads[MAXTHREADS];
104 static char thread_status_char(unsigned status)
106 static const char thread_status_chars[THREAD_NUM_STATES+1] =
108 [0 ... THREAD_NUM_STATES] = '?',
109 [STATE_RUNNING] = 'R',
110 [STATE_BLOCKED] = 'B',
111 [STATE_SLEEPING] = 'S',
112 [STATE_BLOCKED_W_TMO] = 'T',
113 [STATE_FROZEN] = 'F',
114 [STATE_KILLED] = 'K',
117 #if NUM_CORES > 1
118 if (status == STATE_BUSY) /* Not a state index */
119 return '.';
120 #endif
122 if (status > THREAD_NUM_STATES)
123 status = THREAD_NUM_STATES;
125 return thread_status_chars[status];
128 static char* threads_getname(int selected_item, void * data, char *buffer)
130 (void)data;
131 struct thread_entry *thread;
132 char name[32];
134 #if NUM_CORES > 1
135 if (selected_item < (int)NUM_CORES)
137 snprintf(buffer, MAX_PATH, "Idle (%d): %2d%%", selected_item,
138 idle_stack_usage(selected_item));
139 return buffer;
142 selected_item -= NUM_CORES;
143 #endif
145 thread = &threads[selected_item];
147 if (thread->state == STATE_KILLED)
149 snprintf(buffer, MAX_PATH, "%2d: ---", selected_item);
150 return buffer;
153 thread_get_name(name, 32, thread);
155 snprintf(buffer, MAX_PATH,
156 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d ") "%2d%% %s",
157 selected_item,
158 IF_COP(thread->core,)
159 #ifdef HAVE_SCHEDULER_BOOSTCTRL
160 (thread->boosted) ? '+' :
161 #endif
162 ((thread->state == STATE_RUNNING) ? '*' : ' '),
163 thread_status_char(thread->state),
164 IF_PRIO(thread->priority,)
165 thread_stack_usage(thread), name);
167 return buffer;
169 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
171 (void)lists;
172 #ifdef ROCKBOX_HAS_LOGF
173 if (action == ACTION_STD_OK)
175 int selpos = gui_synclist_get_sel_pos(lists);
176 #if NUM_CORES > 1
177 if (selpos >= NUM_CORES)
178 remove_thread(&threads[selpos - NUM_CORES]);
179 #else
180 remove_thread(&threads[selpos]);
181 #endif
182 return ACTION_REDRAW;
184 #endif /* ROCKBOX_HAS_LOGF */
185 return action;
187 /* Test code!!! */
188 static bool dbg_os(void)
190 struct simplelist_info info;
191 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
192 #if NUM_CORES == 1
193 MAXTHREADS,
194 #else
195 MAXTHREADS+NUM_CORES,
196 #endif
197 NULL);
198 #ifndef ROCKBOX_HAS_LOGF
199 info.hide_selection = true;
200 #endif
201 info.action_callback = dbg_threads_action_callback;
202 info.get_name = threads_getname;
203 return simplelist_show_list(&info);
206 #ifdef HAVE_LCD_BITMAP
207 #if CONFIG_CODEC != SWCODEC
208 #ifndef SIMULATOR
209 static bool dbg_audio_thread(void)
211 char buf[32];
212 struct audio_debug d;
214 lcd_setmargins(0, 0);
215 lcd_setfont(FONT_SYSFIXED);
217 while(1)
219 if (action_userabort(HZ/5))
220 return false;
222 audio_get_debugdata(&d);
224 lcd_clear_display();
226 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
227 lcd_puts(0, 0, buf);
228 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
229 lcd_puts(0, 1, buf);
230 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
231 lcd_puts(0, 2, buf);
232 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
233 lcd_puts(0, 3, buf);
234 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
235 lcd_puts(0, 4, buf);
236 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
237 lcd_puts(0, 5, buf);
239 /* Playable space left */
240 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
241 d.playable_space, HORIZONTAL);
243 /* Show the watermark limit */
244 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
245 d.low_watermark_level, HORIZONTAL);
247 snprintf(buf, sizeof(buf), "wm: %x - %x",
248 d.low_watermark_level, d.lowest_watermark_level);
249 lcd_puts(0, 7, buf);
251 lcd_update();
253 return false;
255 #endif /* !SIMULATOR */
256 #else /* CONFIG_CODEC == SWCODEC */
257 extern size_t filebuflen;
258 /* This is a size_t, but call it a long so it puts a - when it's bad. */
260 static unsigned int ticks, boost_ticks;
262 static void dbg_audio_task(void)
264 #ifndef SIMULATOR
265 if(FREQ > CPUFREQ_NORMAL)
266 boost_ticks++;
267 #endif
269 ticks++;
272 static bool dbg_buffering_thread(void)
274 char buf[32];
275 int button;
276 int line;
277 bool done = false;
278 size_t bufused;
279 size_t bufsize = pcmbuf_get_bufsize();
280 int pcmbufdescs = pcmbuf_descs();
281 struct buffering_debug d;
283 ticks = boost_ticks = 0;
285 tick_add_task(dbg_audio_task);
287 lcd_setmargins(0, 0);
288 lcd_setfont(FONT_SYSFIXED);
289 while(!done)
291 button = get_action(CONTEXT_STD,HZ/5);
292 switch(button)
294 case ACTION_STD_NEXT:
295 audio_next();
296 break;
297 case ACTION_STD_PREV:
298 audio_prev();
299 break;
300 case ACTION_STD_CANCEL:
301 done = true;
302 break;
305 buffering_get_debugdata(&d);
307 line = 0;
308 lcd_clear_display();
310 bufused = bufsize - pcmbuf_free();
312 snprintf(buf, sizeof(buf), "pcm: %7ld/%7ld", (long) bufused, (long) bufsize);
313 lcd_puts(0, line++, buf);
315 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
316 bufsize, 0, bufused, HORIZONTAL);
317 line++;
319 snprintf(buf, sizeof(buf), "alloc: %8ld/%8ld", audio_filebufused(),
320 (long) filebuflen);
321 lcd_puts(0, line++, buf);
323 #if LCD_HEIGHT > 80
324 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
325 filebuflen, 0, audio_filebufused(), HORIZONTAL);
326 line++;
328 snprintf(buf, sizeof(buf), "real: %8ld/%8ld", (long)d.buffered_data,
329 (long)filebuflen);
330 lcd_puts(0, line++, buf);
332 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
333 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
334 line++;
335 #endif
337 snprintf(buf, sizeof(buf), "usefl: %8ld/%8ld", (long)(d.useful_data),
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, d.useful_data, HORIZONTAL);
344 line++;
345 #endif
347 snprintf(buf, sizeof(buf), "data_rem: %ld", (long)d.data_rem);
348 lcd_puts(0, line++, buf);
350 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
351 lcd_puts(0, line++, buf);
353 snprintf(buf, sizeof(buf), "handle count: %d", (int)d.num_handles);
354 lcd_puts(0, line++, buf);
356 #ifndef SIMULATOR
357 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
358 (int)((FREQ + 500000) / 1000000));
359 lcd_puts(0, line++, buf);
360 #endif
362 if (ticks > 0)
364 snprintf(buf, sizeof(buf), "boost ratio: %3d%%",
365 boost_ticks * 100 / ticks);
366 lcd_puts(0, line++, buf);
369 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
370 pcmbuf_used_descs(), pcmbufdescs);
371 lcd_puts(0, line++, buf);
373 lcd_update();
376 tick_remove_task(dbg_audio_task);
378 return false;
380 #endif /* CONFIG_CODEC */
381 #endif /* HAVE_LCD_BITMAP */
384 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
385 /* Tool function to read the flash manufacturer and type, if available.
386 Only chips which could be reprogrammed in system will return values.
387 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
388 /* In IRAM to avoid problems when running directly from Flash */
389 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
390 unsigned addr1, unsigned addr2)
391 ICODE_ATTR __attribute__((noinline));
392 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
393 unsigned addr1, unsigned addr2)
396 unsigned not_manu, not_id; /* read values before switching to ID mode */
397 unsigned manu, id; /* read values when in ID mode */
399 #if CONFIG_CPU == SH7034
400 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
401 #elif defined(CPU_COLDFIRE)
402 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
403 #endif
404 int old_level; /* saved interrupt level */
406 not_manu = flash[0]; /* read the normal content */
407 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
409 /* disable interrupts, prevent any stray flash access */
410 old_level = set_irq_level(HIGHEST_IRQ_LEVEL);
412 flash[addr1] = 0xAA; /* enter command mode */
413 flash[addr2] = 0x55;
414 flash[addr1] = 0x90; /* ID command */
415 /* Atmel wants 20ms pause here */
416 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
418 manu = flash[0]; /* read the IDs */
419 id = flash[1];
421 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
422 /* Atmel wants 20ms pause here */
423 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
425 set_irq_level(old_level); /* enable interrupts again */
427 /* I assume success if the obtained values are different from
428 the normal flash content. This is not perfectly bulletproof, they
429 could theoretically be the same by chance, causing us to fail. */
430 if (not_manu != manu || not_id != id) /* a value has changed */
432 *p_manufacturer = manu; /* return the results */
433 *p_device = id;
434 return true; /* success */
436 return false; /* fail */
438 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
440 #ifndef SIMULATOR
441 #ifdef CPU_PP
442 static int perfcheck(void)
444 int result;
446 asm (
447 "mrs r2, CPSR \n"
448 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
449 "msr CPSR_c, r0 \n"
450 "mov %[res], #0 \n"
451 "ldr r0, [%[timr]] \n"
452 "add r0, r0, %[tmo] \n"
453 "1: \n"
454 "add %[res], %[res], #1 \n"
455 "ldr r1, [%[timr]] \n"
456 "cmp r1, r0 \n"
457 "bmi 1b \n"
458 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
460 [res]"=&r"(result)
462 [timr]"r"(&USEC_TIMER),
463 [tmo]"r"(
464 #if CONFIG_CPU == PP5002
465 16000
466 #else /* PP5020/5022/5024 */
467 10226
468 #endif
471 "r0", "r1", "r2"
473 return result;
475 #endif
477 #ifdef HAVE_LCD_BITMAP
478 static bool dbg_hw_info(void)
480 #if CONFIG_CPU == SH7034
481 char buf[32];
482 int bitmask = HW_MASK;
483 int rom_version = ROM_VERSION;
484 unsigned manu, id; /* flash IDs */
485 bool got_id; /* flag if we managed to get the flash IDs */
486 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
487 bool has_bootrom; /* flag for boot ROM present */
488 int oldmode; /* saved memory guard mode */
490 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
492 /* get flash ROM type */
493 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
494 if (!got_id)
495 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
497 /* check if the boot ROM area is a flash mirror */
498 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
499 if (has_bootrom) /* if ROM and Flash different */
501 /* calculate CRC16 checksum of boot ROM */
502 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
505 system_memory_guard(oldmode); /* re-enable memory guard */
507 lcd_setmargins(0, 0);
508 lcd_setfont(FONT_SYSFIXED);
509 lcd_clear_display();
511 lcd_puts(0, 0, "[Hardware info]");
513 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
514 lcd_puts(0, 1, buf);
516 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
517 lcd_puts(0, 2, buf);
519 if (got_id)
520 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
521 else
522 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
523 lcd_puts(0, 3, buf);
525 if (has_bootrom)
527 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
528 snprintf(buf, 32, "Boot ROM: V1");
529 else
530 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
532 else
534 snprintf(buf, 32, "Boot ROM: none");
536 lcd_puts(0, 4, buf);
538 lcd_update();
540 while (!(action_userabort(TIMEOUT_BLOCK)));
542 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
543 char buf[32];
544 unsigned manu, id; /* flash IDs */
545 int got_id; /* flag if we managed to get the flash IDs */
546 int oldmode; /* saved memory guard mode */
547 int line = 0;
549 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
551 /* get flash ROM type */
552 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
553 if (!got_id)
554 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
556 system_memory_guard(oldmode); /* re-enable memory guard */
558 lcd_setmargins(0, 0);
559 lcd_setfont(FONT_SYSFIXED);
560 lcd_clear_display();
562 lcd_puts(0, line++, "[Hardware info]");
564 if (got_id)
565 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
566 else
567 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
568 lcd_puts(0, line++, buf);
570 #ifdef IAUDIO_X5
572 struct ds2411_id id;
574 lcd_puts(0, ++line, "Serial Number:");
576 got_id = ds2411_read_id(&id);
578 if (got_id == DS2411_OK)
580 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
581 lcd_puts(0, ++line, buf);
582 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
583 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
584 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
585 lcd_puts(0, ++line, buf);
586 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
588 else
590 snprintf(buf, 32, "READ ERR=%d", got_id);
593 lcd_puts(0, ++line, buf);
595 #endif
597 lcd_update();
599 while (!(action_userabort(TIMEOUT_BLOCK)));
601 #elif defined(CPU_PP502x)
602 int line = 0;
603 char buf[32];
604 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
605 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
606 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
607 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
609 lcd_setmargins(0, 0);
610 lcd_setfont(FONT_SYSFIXED);
611 lcd_clear_display();
613 lcd_puts(0, line++, "[Hardware info]");
615 #ifdef IPOD_ARCH
616 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
617 lcd_puts(0, line++, buf);
618 #endif
620 #ifdef IPOD_COLOR
621 extern int lcd_type; /* Defined in lcd-colornano.c */
623 snprintf(buf, sizeof(buf), "LCD type: %d", lcd_type);
624 lcd_puts(0, line++, buf);
625 #endif
627 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
628 lcd_puts(0, line++, buf);
630 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
631 lcd_puts(0, line++, buf);
633 lcd_update();
635 while (!(action_userabort(TIMEOUT_BLOCK)));
637 #elif CONFIG_CPU == PP5002
638 int line = 0;
639 char buf[32];
640 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
641 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
642 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
643 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
646 lcd_setmargins(0, 0);
647 lcd_setfont(FONT_SYSFIXED);
648 lcd_clear_display();
650 lcd_puts(0, line++, "[Hardware info]");
652 #ifdef IPOD_ARCH
653 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
654 lcd_puts(0, line++, buf);
655 #endif
657 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
658 lcd_puts(0, line++, buf);
660 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
661 lcd_puts(0, line++, buf);
663 lcd_update();
665 while (!(action_userabort(TIMEOUT_BLOCK)));
666 #else
667 /* Define this function in your target tree */
668 return __dbg_hw_info();
669 #endif /* CONFIG_CPU */
670 return false;
672 #else /* !HAVE_LCD_BITMAP */
673 static bool dbg_hw_info(void)
675 char buf[32];
676 int button;
677 int currval = 0;
678 int rom_version = ROM_VERSION;
679 unsigned manu, id; /* flash IDs */
680 bool got_id; /* flag if we managed to get the flash IDs */
681 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
682 bool has_bootrom; /* flag for boot ROM present */
683 int oldmode; /* saved memory guard mode */
685 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
687 /* get flash ROM type */
688 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
689 if (!got_id)
690 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
692 /* check if the boot ROM area is a flash mirror */
693 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
694 if (has_bootrom) /* if ROM and Flash different */
696 /* calculate CRC16 checksum of boot ROM */
697 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
700 system_memory_guard(oldmode); /* re-enable memory guard */
702 lcd_clear_display();
704 lcd_puts(0, 0, "[HW Info]");
705 while(1)
707 switch(currval)
709 case 0:
710 snprintf(buf, 32, "ROM: %d.%02d",
711 rom_version/100, rom_version%100);
712 break;
713 case 1:
714 if (got_id)
715 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
716 else
717 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
718 break;
719 case 2:
720 if (has_bootrom)
722 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
723 snprintf(buf, 32, "BootROM: V1");
724 else if (rom_crc == 0x358099E8)
725 snprintf(buf, 32, "BootROM: V2");
726 /* alternative boot ROM found in one single player so far */
727 else
728 snprintf(buf, 32, "R: %08x", rom_crc);
730 else
731 snprintf(buf, 32, "BootROM: no");
734 lcd_puts(0, 1, buf);
735 lcd_update();
737 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
739 switch(button)
741 case ACTION_STD_CANCEL:
742 return false;
744 case ACTION_SETTINGS_DEC:
745 currval--;
746 if(currval < 0)
747 currval = 2;
748 break;
750 case ACTION_SETTINGS_INC:
751 currval++;
752 if(currval > 2)
753 currval = 0;
754 break;
757 return false;
759 #endif /* !HAVE_LCD_BITMAP */
760 #endif /* !SIMULATOR */
762 #ifndef SIMULATOR
763 static char* dbg_partitions_getname(int selected_item, void * data, char *buffer)
765 (void)data;
766 int partition = selected_item/2;
767 struct partinfo* p = disk_partinfo(partition);
768 if (selected_item%2)
770 snprintf(buffer, MAX_PATH, " T:%x %ld MB", p->type, p->size / 2048);
772 else
774 snprintf(buffer, MAX_PATH, "P%d: S:%lx", partition, p->start);
776 return buffer;
779 bool dbg_partitions(void)
781 struct simplelist_info info;
782 simplelist_info_init(&info, "Partition Info", 4, NULL);
783 info.selection_size = 2;
784 info.hide_selection = 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 char buf[128];
794 int line;
795 unsigned int control;
796 int x;
797 char *s;
798 int category;
799 int generation;
800 unsigned int interruptstat;
801 bool valnogood, symbolerr, parityerr;
802 bool done = false;
803 bool spdif_src_on;
804 int spdif_source = spdif_get_output_source(&spdif_src_on);
805 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
807 lcd_setmargins(0, 0);
808 lcd_clear_display();
809 lcd_setfont(FONT_SYSFIXED);
811 #ifdef HAVE_SPDIF_POWER
812 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
813 #endif
815 while (!done)
817 line = 0;
819 control = EBU1RCVCCHANNEL1;
820 interruptstat = INTERRUPTSTAT;
821 INTERRUPTCLEAR = 0x03c00000;
823 valnogood = (interruptstat & 0x01000000)?true:false;
824 symbolerr = (interruptstat & 0x00800000)?true:false;
825 parityerr = (interruptstat & 0x00400000)?true:false;
827 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
828 valnogood?"--":"OK",
829 symbolerr?"--":"OK",
830 parityerr?"--":"OK");
831 lcd_puts(0, line++, buf);
833 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
834 lcd_puts(0, line++, buf);
836 line++;
838 x = control >> 31;
839 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
840 x, x?"Professional":"Consumer");
841 lcd_puts(0, line++, buf);
843 x = (control >> 30) & 1;
844 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
845 x, x?"Non-PCM":"PCM");
846 lcd_puts(0, line++, buf);
848 x = (control >> 29) & 1;
849 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
850 x, x?"Permitted":"Inhibited");
851 lcd_puts(0, line++, buf);
853 x = (control >> 27) & 7;
854 switch(x)
856 case 0:
857 s = "None";
858 break;
859 case 1:
860 s = "50/15us";
861 break;
862 default:
863 s = "Reserved";
864 break;
866 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
867 lcd_puts(0, line++, buf);
869 x = (control >> 24) & 3;
870 snprintf(buf, sizeof(buf), "Mode: %d", x);
871 lcd_puts(0, line++, buf);
873 category = (control >> 17) & 127;
874 switch(category)
876 case 0x00:
877 s = "General";
878 break;
879 case 0x40:
880 s = "Audio CD";
881 break;
882 default:
883 s = "Unknown";
885 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
886 lcd_puts(0, line++, buf);
888 x = (control >> 16) & 1;
889 generation = x;
890 if(((category & 0x70) == 0x10) ||
891 ((category & 0x70) == 0x40) ||
892 ((category & 0x78) == 0x38))
894 generation = !generation;
896 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
897 x, generation?"Original":"No ind.");
898 lcd_puts(0, line++, buf);
900 x = (control >> 12) & 15;
901 snprintf(buf, sizeof(buf), "Source: %d", x);
902 lcd_puts(0, line++, buf);
904 x = (control >> 8) & 15;
905 switch(x)
907 case 0:
908 s = "Unspecified";
909 break;
910 case 8:
911 s = "A (Left)";
912 break;
913 case 4:
914 s = "B (Right)";
915 break;
916 default:
917 s = "";
918 break;
920 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
921 lcd_puts(0, line++, buf);
923 x = (control >> 4) & 15;
924 switch(x)
926 case 0:
927 s = "44.1kHz";
928 break;
929 case 0x4:
930 s = "48kHz";
931 break;
932 case 0xc:
933 s = "32kHz";
934 break;
936 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
937 lcd_puts(0, line++, buf);
939 x = (control >> 2) & 3;
940 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
941 lcd_puts(0, line++, buf);
942 line++;
944 #ifndef SIMULATOR
945 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
946 spdif_measure_frequency());
947 lcd_puts(0, line++, buf);
948 #endif
950 lcd_update();
952 if (action_userabort(HZ/10))
953 break;
956 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
958 #ifdef HAVE_SPDIF_POWER
959 spdif_power_enable(global_settings.spdif_enable);
960 #endif
962 return false;
964 #endif /* CPU_COLDFIRE */
966 #ifndef SIMULATOR
967 #ifdef HAVE_LCD_BITMAP
968 /* button definitions */
969 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
970 (CONFIG_KEYPAD == IRIVER_H300_PAD)
971 # define DEBUG_CANCEL BUTTON_OFF
973 #elif CONFIG_KEYPAD == RECORDER_PAD
974 # define DEBUG_CANCEL BUTTON_OFF
976 #elif CONFIG_KEYPAD == ONDIO_PAD
977 # define DEBUG_CANCEL BUTTON_MENU
979 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
980 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
981 (CONFIG_KEYPAD == IPOD_4G_PAD)
982 # define DEBUG_CANCEL BUTTON_MENU
984 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
985 # define DEBUG_CANCEL BUTTON_PLAY
987 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
988 # define DEBUG_CANCEL BUTTON_REC
990 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD) || \
991 (CONFIG_KEYPAD == MROBE100_PAD)
992 # define DEBUG_CANCEL BUTTON_REW
994 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
995 (CONFIG_KEYPAD == SANSA_C200_PAD)
996 # define DEBUG_CANCEL BUTTON_LEFT
997 #endif /* key definitions */
999 /* Test code!!! */
1000 bool dbg_ports(void)
1002 #if CONFIG_CPU == SH7034
1003 unsigned short porta;
1004 unsigned short portb;
1005 unsigned char portc;
1006 char buf[32];
1007 int adc_battery_voltage, adc_battery_level;
1009 lcd_setfont(FONT_SYSFIXED);
1010 lcd_setmargins(0, 0);
1011 lcd_clear_display();
1013 while(1)
1015 porta = PADR;
1016 portb = PBDR;
1017 portc = PCDR;
1019 snprintf(buf, 32, "PADR: %04x", porta);
1020 lcd_puts(0, 0, buf);
1021 snprintf(buf, 32, "PBDR: %04x", portb);
1022 lcd_puts(0, 1, buf);
1024 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1025 lcd_puts(0, 2, buf);
1026 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1027 lcd_puts(0, 3, buf);
1028 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1029 lcd_puts(0, 4, buf);
1030 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1031 lcd_puts(0, 5, buf);
1033 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1034 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1035 adc_battery_voltage % 1000, adc_battery_level);
1036 lcd_puts(0, 6, buf);
1038 lcd_update();
1039 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1040 return false;
1042 #elif defined(CPU_COLDFIRE)
1043 unsigned int gpio_out;
1044 unsigned int gpio1_out;
1045 unsigned int gpio_read;
1046 unsigned int gpio1_read;
1047 unsigned int gpio_function;
1048 unsigned int gpio1_function;
1049 unsigned int gpio_enable;
1050 unsigned int gpio1_enable;
1051 int adc_buttons, adc_remote;
1052 int adc_battery_voltage, adc_battery_level;
1053 char buf[128];
1054 int line;
1056 lcd_setmargins(0, 0);
1057 lcd_clear_display();
1058 lcd_setfont(FONT_SYSFIXED);
1060 while(1)
1062 line = 0;
1063 gpio_read = GPIO_READ;
1064 gpio1_read = GPIO1_READ;
1065 gpio_out = GPIO_OUT;
1066 gpio1_out = GPIO1_OUT;
1067 gpio_function = GPIO_FUNCTION;
1068 gpio1_function = GPIO1_FUNCTION;
1069 gpio_enable = GPIO_ENABLE;
1070 gpio1_enable = GPIO1_ENABLE;
1072 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1073 lcd_puts(0, line++, buf);
1074 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1075 lcd_puts(0, line++, buf);
1076 snprintf(buf, sizeof(buf), "GPIO_FUNCTION: %08x", gpio_function);
1077 lcd_puts(0, line++, buf);
1078 snprintf(buf, sizeof(buf), "GPIO_ENABLE: %08x", gpio_enable);
1079 lcd_puts(0, line++, buf);
1081 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1082 lcd_puts(0, line++, buf);
1083 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1084 lcd_puts(0, line++, buf);
1085 snprintf(buf, sizeof(buf), "GPIO1_FUNCTION: %08x", gpio1_function);
1086 lcd_puts(0, line++, buf);
1087 snprintf(buf, sizeof(buf), "GPIO1_ENABLE: %08x", gpio1_enable);
1088 lcd_puts(0, line++, buf);
1090 adc_buttons = adc_read(ADC_BUTTONS);
1091 adc_remote = adc_read(ADC_REMOTE);
1092 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1093 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1094 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1095 button_scan_enabled() ? '+' : '-', adc_buttons);
1096 #else
1097 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1098 #endif
1099 lcd_puts(0, line++, buf);
1100 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1101 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1102 remote_detect() ? '+' : '-', adc_remote);
1103 #else
1104 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1105 #endif
1106 lcd_puts(0, line++, buf);
1107 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1108 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1109 adc_read(ADC_REMOTEDETECT));
1110 lcd_puts(0, line++, buf);
1111 #endif
1113 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1114 adc_battery_voltage % 1000, adc_battery_level);
1115 lcd_puts(0, line++, buf);
1117 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1118 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1119 lcd_puts(0, line++, buf);
1120 #endif
1122 lcd_update();
1123 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1124 return false;
1127 #elif defined(CPU_PP502x)
1129 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1130 unsigned int gpio_e, gpio_f, gpio_g, gpio_h;
1131 unsigned int gpio_i, gpio_j, gpio_k, gpio_l;
1133 char buf[128];
1134 int line;
1136 lcd_setmargins(0, 0);
1137 lcd_clear_display();
1138 lcd_setfont(FONT_SYSFIXED);
1140 while(1)
1142 gpio_a = GPIOA_INPUT_VAL;
1143 gpio_b = GPIOB_INPUT_VAL;
1144 gpio_c = GPIOC_INPUT_VAL;
1145 gpio_d = GPIOD_INPUT_VAL;
1146 gpio_e = GPIOE_INPUT_VAL;
1147 gpio_f = GPIOF_INPUT_VAL;
1148 gpio_g = GPIOG_INPUT_VAL;
1149 gpio_h = GPIOH_INPUT_VAL;
1150 gpio_i = GPIOI_INPUT_VAL;
1151 gpio_j = GPIOJ_INPUT_VAL;
1152 gpio_k = GPIOK_INPUT_VAL;
1153 gpio_l = GPIOL_INPUT_VAL;
1155 line = 0;
1156 snprintf(buf, sizeof(buf), "GPIO STATES:");
1157 lcd_puts(0, line++, buf);
1158 snprintf(buf, sizeof(buf), "A: %02x E: %02x I: %02x",
1159 gpio_a, gpio_e, gpio_i);
1160 lcd_puts(0, line++, buf);
1161 snprintf(buf, sizeof(buf), "B: %02x F: %02x J: %02x",
1162 gpio_b, gpio_f, gpio_j);
1163 lcd_puts(0, line++, buf);
1164 snprintf(buf, sizeof(buf), "C: %02x G: %02x K: %02x",
1165 gpio_c, gpio_g, gpio_k);
1166 lcd_puts(0, line++, buf);
1167 snprintf(buf, sizeof(buf), "D: %02x H: %02x L: %02x",
1168 gpio_d, gpio_h, gpio_l);
1169 lcd_puts(0, line++, buf);
1170 line++;
1172 snprintf(buf, sizeof(buf), "GPO32_VAL: %08lx", GPO32_VAL);
1173 lcd_puts(0, line++, buf);
1174 snprintf(buf, sizeof(buf), "GPO32_EN: %08lx", GPO32_ENABLE);
1175 lcd_puts(0, line++, buf);
1176 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1177 lcd_puts(0, line++, buf);
1178 snprintf(buf, sizeof(buf), "DEV_EN2: %08lx", DEV_EN2);
1179 lcd_puts(0, line++, buf);
1180 snprintf(buf, sizeof(buf), "DEV_EN3: %08lx", inl(0x60006044));
1181 lcd_puts(0, line++, buf); /* to be verified */
1182 snprintf(buf, sizeof(buf), "DEV_INIT1: %08lx", DEV_INIT1);
1183 lcd_puts(0, line++, buf);
1184 snprintf(buf, sizeof(buf), "DEV_INIT2: %08lx", DEV_INIT2);
1185 lcd_puts(0, line++, buf);
1187 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1188 line++;
1189 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x", adc_read(ADC_BATTERY),
1190 adc_read(ADC_UNKNOWN_1));
1191 lcd_puts(0, line++, buf);
1192 snprintf(buf, sizeof(buf), "REM: %03x PAD: %03x", adc_read(ADC_REMOTE),
1193 adc_read(ADC_SCROLLPAD));
1194 lcd_puts(0, line++, buf);
1195 #elif defined(SANSA_E200)
1196 line++;
1197 snprintf(buf, sizeof(buf), "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1198 lcd_puts(0, line++, buf);
1199 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1200 lcd_puts(0, line++, buf);
1201 snprintf(buf, sizeof(buf), "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1202 lcd_puts(0, line++, buf);
1203 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1204 lcd_puts(0, line++, buf);
1205 snprintf(buf, sizeof(buf), "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1206 lcd_puts(0, line++, buf);
1207 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1208 lcd_puts(0, line++, buf);
1209 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1210 lcd_puts(0, line++, buf);
1211 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1212 lcd_puts(0, line++, buf);
1213 snprintf(buf, sizeof(buf), "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1214 lcd_puts(0, line++, buf);
1215 snprintf(buf, sizeof(buf), "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1216 lcd_puts(0, line++, buf);
1217 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1218 lcd_puts(0, line++, buf);
1219 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1220 lcd_puts(0, line++, buf);
1221 snprintf(buf, sizeof(buf), "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1222 lcd_puts(0, line++, buf);
1223 #endif
1224 lcd_update();
1225 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1226 return false;
1229 #elif CONFIG_CPU == PP5002
1230 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1232 char buf[128];
1233 int line;
1235 lcd_setmargins(0, 0);
1236 lcd_clear_display();
1237 lcd_setfont(FONT_SYSFIXED);
1239 while(1)
1241 gpio_a = GPIOA_INPUT_VAL;
1242 gpio_b = GPIOB_INPUT_VAL;
1243 gpio_c = GPIOC_INPUT_VAL;
1244 gpio_d = GPIOD_INPUT_VAL;
1246 line = 0;
1247 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x", gpio_a, gpio_b);
1248 lcd_puts(0, line++, buf);
1249 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x", gpio_c, gpio_d);
1250 lcd_puts(0, line++, buf);
1252 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1253 lcd_puts(0, line++, buf);
1254 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1255 lcd_puts(0, line++, buf);
1256 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1257 lcd_puts(0, line++, buf);
1258 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1259 lcd_puts(0, line++, buf);
1260 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1261 lcd_puts(0, line++, buf);
1262 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1263 lcd_puts(0, line++, buf);
1264 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1265 lcd_puts(0, line++, buf);
1266 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1267 lcd_puts(0, line++, buf);
1269 lcd_update();
1270 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1271 return false;
1273 #else
1274 return __dbg_ports();
1275 #endif /* CPU */
1276 return false;
1278 #else /* !HAVE_LCD_BITMAP */
1279 bool dbg_ports(void)
1281 unsigned short porta;
1282 unsigned short portb;
1283 unsigned char portc;
1284 char buf[32];
1285 int button;
1286 int adc_battery_voltage;
1287 int currval = 0;
1289 lcd_clear_display();
1291 while(1)
1293 porta = PADR;
1294 portb = PBDR;
1295 portc = PCDR;
1297 switch(currval)
1299 case 0:
1300 snprintf(buf, 32, "PADR: %04x", porta);
1301 break;
1302 case 1:
1303 snprintf(buf, 32, "PBDR: %04x", portb);
1304 break;
1305 case 2:
1306 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1307 break;
1308 case 3:
1309 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1310 break;
1311 case 4:
1312 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1313 break;
1314 case 5:
1315 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1316 break;
1317 case 6:
1318 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1319 break;
1320 case 7:
1321 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1322 break;
1323 case 8:
1324 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1325 break;
1326 case 9:
1327 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1328 break;
1329 break;
1331 lcd_puts(0, 0, buf);
1333 battery_read_info(&adc_battery_voltage, NULL);
1334 snprintf(buf, 32, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1335 adc_battery_voltage % 1000);
1336 lcd_puts(0, 1, buf);
1337 lcd_update();
1339 button = get_action(CONTEXT_SETTINGS,HZ/5);
1341 switch(button)
1343 case ACTION_STD_CANCEL:
1344 return false;
1346 case ACTION_SETTINGS_DEC:
1347 currval--;
1348 if(currval < 0)
1349 currval = 9;
1350 break;
1352 case ACTION_SETTINGS_INC:
1353 currval++;
1354 if(currval > 9)
1355 currval = 0;
1356 break;
1359 return false;
1361 #endif /* !HAVE_LCD_BITMAP */
1362 #endif /* !SIMULATOR */
1364 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1365 static bool dbg_pcf(void)
1367 char buf[128];
1368 int line;
1370 #ifdef HAVE_LCD_BITMAP
1371 lcd_setmargins(0, 0);
1372 lcd_setfont(FONT_SYSFIXED);
1373 #endif
1374 lcd_clear_display();
1376 while(1)
1378 line = 0;
1380 snprintf(buf, sizeof(buf), "DCDC1: %02x", pcf50605_read(0x1b));
1381 lcd_puts(0, line++, buf);
1382 snprintf(buf, sizeof(buf), "DCDC2: %02x", pcf50605_read(0x1c));
1383 lcd_puts(0, line++, buf);
1384 snprintf(buf, sizeof(buf), "DCDC3: %02x", pcf50605_read(0x1d));
1385 lcd_puts(0, line++, buf);
1386 snprintf(buf, sizeof(buf), "DCDC4: %02x", pcf50605_read(0x1e));
1387 lcd_puts(0, line++, buf);
1388 snprintf(buf, sizeof(buf), "DCDEC1: %02x", pcf50605_read(0x1f));
1389 lcd_puts(0, line++, buf);
1390 snprintf(buf, sizeof(buf), "DCDEC2: %02x", pcf50605_read(0x20));
1391 lcd_puts(0, line++, buf);
1392 snprintf(buf, sizeof(buf), "DCUDC1: %02x", pcf50605_read(0x21));
1393 lcd_puts(0, line++, buf);
1394 snprintf(buf, sizeof(buf), "DCUDC2: %02x", pcf50605_read(0x22));
1395 lcd_puts(0, line++, buf);
1396 snprintf(buf, sizeof(buf), "IOREGC: %02x", pcf50605_read(0x23));
1397 lcd_puts(0, line++, buf);
1398 snprintf(buf, sizeof(buf), "D1REGC: %02x", pcf50605_read(0x24));
1399 lcd_puts(0, line++, buf);
1400 snprintf(buf, sizeof(buf), "D2REGC: %02x", pcf50605_read(0x25));
1401 lcd_puts(0, line++, buf);
1402 snprintf(buf, sizeof(buf), "D3REGC: %02x", pcf50605_read(0x26));
1403 lcd_puts(0, line++, buf);
1404 snprintf(buf, sizeof(buf), "LPREG1: %02x", pcf50605_read(0x27));
1405 lcd_puts(0, line++, buf);
1407 lcd_update();
1408 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1410 return false;
1414 return false;
1416 #endif
1418 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1419 static bool dbg_cpufreq(void)
1421 char buf[128];
1422 int line;
1423 int button;
1425 #ifdef HAVE_LCD_BITMAP
1426 lcd_setmargins(0, 0);
1427 lcd_setfont(FONT_SYSFIXED);
1428 #endif
1429 lcd_clear_display();
1431 while(1)
1433 line = 0;
1435 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1436 lcd_puts(0, line++, buf);
1438 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1439 lcd_puts(0, line++, buf);
1441 lcd_update();
1442 button = get_action(CONTEXT_STD,HZ/10);
1444 switch(button)
1446 case ACTION_STD_PREV:
1447 cpu_boost(true);
1448 break;
1450 case ACTION_STD_NEXT:
1451 cpu_boost(false);
1452 break;
1454 case ACTION_STD_OK:
1455 while (get_cpu_boost_counter() > 0)
1456 cpu_boost(false);
1457 set_cpu_frequency(CPUFREQ_DEFAULT);
1458 break;
1460 case ACTION_STD_CANCEL:
1461 return false;
1465 return false;
1467 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1469 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1470 #include "tsc2100.h"
1471 char *itob(int n, int len)
1473 static char binary[64];
1474 int i,j;
1475 for (i=1, j=0;i<=len;i++)
1477 binary[j++] = n&(1<<(len-i))?'1':'0';
1478 if (i%4 == 0)
1479 binary[j++] = ' ';
1481 binary[j] = '\0';
1482 return binary;
1484 static char* tsc2100_debug_getname(int selected_item, void * data, char *buffer)
1486 int *page = (int*)data;
1487 bool reserved = false;
1488 switch (*page)
1490 case 0:
1491 if ((selected_item > 0x0a) ||
1492 (selected_item == 0x04) ||
1493 (selected_item == 0x08))
1494 reserved = true;
1495 break;
1496 case 1:
1497 if ((selected_item > 0x05) ||
1498 (selected_item == 0x02))
1499 reserved = true;
1500 break;
1501 case 2:
1502 if (selected_item > 0x1e)
1503 reserved = true;
1504 break;
1506 if (reserved)
1507 snprintf(buffer, MAX_PATH, "%02x: RESERVED", selected_item);
1508 else
1509 snprintf(buffer, MAX_PATH, "%02x: %s", selected_item,
1510 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1511 return buffer;
1513 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1515 int *page = (int*)lists->data;
1516 if (action == ACTION_STD_OK)
1518 *page = (*page+1)%3;
1519 snprintf(lists->title, 32,
1520 "tsc2100 registers - Page %d", *page);
1521 return ACTION_REDRAW;
1523 return action;
1525 bool tsc2100_debug(void)
1527 int page = 0;
1528 char title[32] = "tsc2100 registers - Page 0";
1529 struct simplelist_info info;
1530 simplelist_info_init(&info, title, 32, &page);
1531 info.timeout = HZ/100;
1532 info.get_name = tsc2100_debug_getname;
1533 info.action_callback= tsc2100debug_action_callback;
1534 return simplelist_show_list(&info);
1536 #endif
1537 #ifndef SIMULATOR
1538 #ifdef HAVE_LCD_BITMAP
1540 * view_battery() shows a automatically scaled graph of the battery voltage
1541 * over time. Usable for estimating battery life / charging rate.
1542 * The power_history array is updated in power_thread of powermgmt.c.
1545 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1546 #define BAT_YSPACE (LCD_HEIGHT - 20)
1548 static bool view_battery(void)
1550 int view = 0;
1551 int i, x, y;
1552 unsigned short maxv, minv;
1553 char buf[32];
1555 lcd_setmargins(0, 0);
1556 lcd_setfont(FONT_SYSFIXED);
1558 while(1)
1560 lcd_clear_display();
1561 switch (view) {
1562 case 0: /* voltage history graph */
1563 /* Find maximum and minimum voltage for scaling */
1564 minv = power_history[0];
1565 maxv = minv + 1;
1566 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1567 if (power_history[i] > maxv)
1568 maxv = power_history[i];
1569 if (power_history[i] < minv)
1570 minv = power_history[i];
1573 snprintf(buf, 30, "Battery %d.%03d", power_history[0] / 1000,
1574 power_history[0] % 1000);
1575 lcd_puts(0, 0, buf);
1576 snprintf(buf, 30, "scale %d.%03d-%d.%03dV",
1577 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1578 lcd_puts(0, 1, buf);
1580 x = 0;
1581 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1582 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1583 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1584 lcd_vline(x, LCD_HEIGHT-1, 20);
1585 lcd_set_drawmode(DRMODE_SOLID);
1586 lcd_vline(x, LCD_HEIGHT-1,
1587 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1588 x++;
1591 break;
1593 case 1: /* status: */
1594 lcd_puts(0, 0, "Power status:");
1596 battery_read_info(&y, NULL);
1597 snprintf(buf, 30, "Battery: %d.%03d V", y / 1000, y % 1000);
1598 lcd_puts(0, 1, buf);
1599 #ifdef ADC_EXT_POWER
1600 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1601 snprintf(buf, 30, "External: %d.%03d V", y / 1000, y % 1000);
1602 lcd_puts(0, 2, buf);
1603 #endif
1604 #if CONFIG_CHARGING
1605 #if CONFIG_CHARGING == CHARGING_CONTROL
1606 snprintf(buf, 30, "Chgr: %s %s",
1607 charger_inserted() ? "present" : "absent",
1608 charger_enabled ? "on" : "off");
1609 lcd_puts(0, 3, buf);
1610 snprintf(buf, 30, "short delta: %d", short_delta);
1611 lcd_puts(0, 5, buf);
1612 snprintf(buf, 30, "long delta: %d", long_delta);
1613 lcd_puts(0, 6, buf);
1614 lcd_puts(0, 7, power_message);
1615 snprintf(buf, 30, "USB Inserted: %s",
1616 usb_inserted() ? "yes" : "no");
1617 lcd_puts(0, 8, buf);
1618 #if defined IRIVER_H300_SERIES
1619 snprintf(buf, 30, "USB Charging Enabled: %s",
1620 usb_charging_enabled() ? "yes" : "no");
1621 lcd_puts(0, 9, buf);
1622 #endif
1623 #else /* CONFIG_CHARGING != CHARGING_CONTROL */
1624 #if defined IPOD_NANO || defined IPOD_VIDEO
1625 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1626 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1627 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1628 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1629 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1631 snprintf(buf, 30, "USB pwr: %s",
1632 usb_pwr ? "present" : "absent");
1633 lcd_puts(0, 3, buf);
1634 snprintf(buf, 30, "EXT pwr: %s",
1635 ext_pwr ? "present" : "absent");
1636 lcd_puts(0, 4, buf);
1637 snprintf(buf, 30, "Battery: %s",
1638 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1639 lcd_puts(0, 5, buf);
1640 snprintf(buf, 30, "Dock mode: %s",
1641 dock ? "enabled" : "disabled");
1642 lcd_puts(0, 6, buf);
1643 snprintf(buf, 30, "Headphone: %s",
1644 headphone ? "connected" : "disconnected");
1645 lcd_puts(0, 7, buf);
1646 #else
1647 snprintf(buf, 30, "Charger: %s",
1648 charger_inserted() ? "present" : "absent");
1649 lcd_puts(0, 3, buf);
1650 #endif
1651 #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1652 #endif /* CONFIG_CHARGING */
1653 break;
1655 case 2: /* voltage deltas: */
1656 lcd_puts(0, 0, "Voltage deltas:");
1658 for (i = 0; i <= 6; i++) {
1659 y = power_history[i] - power_history[i+1];
1660 snprintf(buf, 30, "-%d min: %s%d.%03d V", i,
1661 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1662 ((y < 0) ? y * -1 : y ) % 1000);
1663 lcd_puts(0, i+1, buf);
1665 break;
1667 case 3: /* remaining time estimation: */
1669 #if CONFIG_CHARGING == CHARGING_CONTROL
1670 snprintf(buf, 30, "charge_state: %d", charge_state);
1671 lcd_puts(0, 0, buf);
1673 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1674 lcd_puts(0, 1, buf);
1676 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1677 lcd_puts(0, 2, buf);
1679 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1680 lcd_puts(0, 3, buf);
1682 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1683 lcd_puts(0, 4, buf);
1684 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
1686 snprintf(buf, 30, "Last PwrHist: %d.%03dV",
1687 power_history[0] / 1000,
1688 power_history[0] % 1000);
1689 lcd_puts(0, 5, buf);
1691 snprintf(buf, 30, "battery level: %d%%", battery_level());
1692 lcd_puts(0, 6, buf);
1694 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1695 lcd_puts(0, 7, buf);
1696 break;
1699 lcd_update();
1701 switch(get_action(CONTEXT_SETTINGS,HZ/2))
1703 case ACTION_SETTINGS_DEC:
1704 if (view)
1705 view--;
1706 break;
1708 case ACTION_SETTINGS_INC:
1709 if (view < 3)
1710 view++;
1711 break;
1713 case ACTION_STD_CANCEL:
1714 return false;
1717 return false;
1720 #endif /* HAVE_LCD_BITMAP */
1721 #endif
1723 #ifndef SIMULATOR
1724 #if defined(HAVE_MMC) || defined(HAVE_HOTSWAP)
1725 #if defined(HAVE_MMC)
1726 #define CARDTYPE "MMC"
1727 #else
1728 #define CARDTYPE "microSD"
1729 #endif
1730 static int disk_callback(int btn, struct gui_synclist *lists)
1732 tCardInfo *card;
1733 int *cardnum = (int*)lists->data;
1734 unsigned char card_name[7];
1735 unsigned char pbuf[32];
1736 char *title = lists->title;
1737 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1738 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1739 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1740 static const unsigned char *nsec_units[] = { "ns", "�s", "ms" };
1741 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1742 "3.1-3.31", "4.0" };
1743 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1745 if (btn == ACTION_STD_OK)
1747 *cardnum ^= 0x1; /* change cards */
1750 simplelist_set_line_count(0);
1752 card = card_get_info(*cardnum);
1754 if (card->initialized > 0)
1756 card_name[6] = '\0';
1757 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1758 simplelist_addline(SIMPLELIST_ADD_LINE,
1759 "%s Rev %d.%d", card_name,
1760 (int) card_extract_bits(card->cid, 72, 4),
1761 (int) card_extract_bits(card->cid, 76, 4));
1762 simplelist_addline(SIMPLELIST_ADD_LINE,
1763 "Prod: %d/%d",
1764 (int) card_extract_bits(card->cid, 112, 4),
1765 (int) card_extract_bits(card->cid, 116, 4) + 1997);
1766 simplelist_addline(SIMPLELIST_ADD_LINE,
1767 "Ser#: 0x%08lx",
1768 card_extract_bits(card->cid, 80, 32));
1769 simplelist_addline(SIMPLELIST_ADD_LINE,
1770 "M=%02x, O=%04x",
1771 (int) card_extract_bits(card->cid, 0, 8),
1772 (int) card_extract_bits(card->cid, 8, 16));
1773 int temp = card_extract_bits(card->csd, 2, 4);
1774 simplelist_addline(SIMPLELIST_ADD_LINE,
1775 CARDTYPE " v%s", temp < 5 ?
1776 spec_vers[temp] : "?.?");
1777 simplelist_addline(SIMPLELIST_ADD_LINE,
1778 "Blocks: 0x%06lx", card->numblocks);
1779 simplelist_addline(SIMPLELIST_ADD_LINE,
1780 "Blksz.: %d P:%c%c", card->blocksize,
1781 card_extract_bits(card->csd, 48, 1) ? 'R' : '-',
1782 card_extract_bits(card->csd, 106, 1) ? 'W' : '-');
1783 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1784 kbit_units, false);
1785 simplelist_addline(SIMPLELIST_ADD_LINE,
1786 "Speed: %s", pbuf);
1787 output_dyn_value(pbuf, sizeof pbuf, card->tsac,
1788 nsec_units, false);
1789 simplelist_addline(SIMPLELIST_ADD_LINE,
1790 "Tsac: %s", pbuf);
1791 simplelist_addline(SIMPLELIST_ADD_LINE,
1792 "Nsac: %d clk", card->nsac);
1793 simplelist_addline(SIMPLELIST_ADD_LINE,
1794 "R2W: *%d", card->r2w_factor);
1795 simplelist_addline(SIMPLELIST_ADD_LINE,
1796 "IRmax: %d..%d mA",
1797 i_vmin[card_extract_bits(card->csd, 66, 3)],
1798 i_vmax[card_extract_bits(card->csd, 69, 3)]);
1799 simplelist_addline(SIMPLELIST_ADD_LINE,
1800 "IWmax: %d..%d mA",
1801 i_vmin[card_extract_bits(card->csd, 72, 3)],
1802 i_vmax[card_extract_bits(card->csd, 75, 3)]);
1804 else if (card->initialized == 0)
1806 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1808 #ifndef HAVE_MMC
1809 else /* card->initialized < 0 */
1811 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1813 #endif
1814 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1815 gui_synclist_set_title(lists, title, Icon_NOICON);
1816 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1817 gui_synclist_select_item(lists, 0);
1818 btn = ACTION_REDRAW;
1820 return btn;
1822 #else /* !defined(HAVE_MMC) && !defined(HAVE_HOTSWAP) */
1823 static int disk_callback(int btn, struct gui_synclist *lists)
1825 (void)lists;
1826 int i;
1827 char buf[128];
1828 unsigned short* identify_info = ata_get_identify();
1829 bool timing_info_present = false;
1830 (void)btn;
1832 simplelist_set_line_count(0);
1834 for (i=0; i < 20; i++)
1835 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1836 buf[40]=0;
1837 /* kill trailing space */
1838 for (i=39; i && buf[i]==' '; i--)
1839 buf[i] = 0;
1840 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1841 for (i=0; i < 4; i++)
1842 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1843 buf[8]=0;
1844 simplelist_addline(SIMPLELIST_ADD_LINE,
1845 "Firmware: %s", buf);
1846 snprintf(buf, sizeof buf, "%ld MB",
1847 ((unsigned long)identify_info[61] << 16 |
1848 (unsigned long)identify_info[60]) / 2048 );
1849 simplelist_addline(SIMPLELIST_ADD_LINE,
1850 "Size: %s", buf);
1851 unsigned long free;
1852 fat_size( IF_MV2(0,) NULL, &free );
1853 simplelist_addline(SIMPLELIST_ADD_LINE,
1854 "Free: %ld MB", free / 1024);
1855 simplelist_addline(SIMPLELIST_ADD_LINE,
1856 "Spinup time: %d ms", ata_spinup_time * (1000/HZ));
1857 i = identify_info[83] & (1<<3);
1858 simplelist_addline(SIMPLELIST_ADD_LINE,
1859 "Power mgmt: %s", i ? "enabled" : "unsupported");
1860 i = identify_info[83] & (1<<9);
1861 simplelist_addline(SIMPLELIST_ADD_LINE,
1862 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1863 i = identify_info[82] & (1<<6);
1864 simplelist_addline(SIMPLELIST_ADD_LINE,
1865 "Read-ahead: %s", i ? "enabled" : "unsupported");
1866 timing_info_present = identify_info[53] & (1<<1);
1867 if(timing_info_present) {
1868 char pio3[2], pio4[2];pio3[1] = 0;
1869 pio4[1] = 0;
1870 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1871 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1872 simplelist_addline(SIMPLELIST_ADD_LINE,
1873 "PIO modes: 0 1 2 %s %s", pio3, pio4);
1875 else {
1876 simplelist_addline(SIMPLELIST_ADD_LINE,
1877 "No PIO mode info");
1879 timing_info_present = identify_info[53] & (1<<1);
1880 if(timing_info_present) {
1881 simplelist_addline(SIMPLELIST_ADD_LINE,
1882 "Cycle times %dns/%dns",
1883 identify_info[67],
1884 identify_info[68] );
1885 } else {
1886 simplelist_addline(SIMPLELIST_ADD_LINE,
1887 "No timing info");
1889 timing_info_present = identify_info[53] & (1<<1);
1890 if(timing_info_present) {
1891 i = identify_info[49] & (1<<11);
1892 simplelist_addline(SIMPLELIST_ADD_LINE,
1893 "IORDY support: %s", i ? "yes" : "no");
1894 i = identify_info[49] & (1<<10);
1895 simplelist_addline(SIMPLELIST_ADD_LINE,
1896 "IORDY disable: %s", i ? "yes" : "no");
1897 } else {
1898 simplelist_addline(SIMPLELIST_ADD_LINE,
1899 "No timing info");
1901 simplelist_addline(SIMPLELIST_ADD_LINE,
1902 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1903 return btn;
1905 #endif /* !defined(HAVE_MMC) && !defined(HAVE_HOTSWAP) */
1906 static bool dbg_disk_info(void)
1908 struct simplelist_info info;
1909 simplelist_info_init(&info, "Disk Info", 1, NULL);
1910 #if defined(HAVE_MMC) || defined(HAVE_HOTSWAP)
1911 char title[16];
1912 int card = 0;
1913 info.callback_data = (void*)&card;
1914 info.title = title;
1915 #endif
1916 info.action_callback = disk_callback;
1917 info.hide_selection = true;
1918 return simplelist_show_list(&info);
1920 #endif /* !SIMULATOR */
1922 #ifdef HAVE_DIRCACHE
1923 static int dircache_callback(int btn, struct gui_synclist *lists)
1925 (void)btn; (void)lists;
1926 simplelist_set_line_count(0);
1927 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
1928 dircache_is_enabled() ? "Yes" : "No");
1929 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
1930 dircache_get_cache_size());
1931 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
1932 global_status.dircache_size);
1933 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
1934 DIRCACHE_LIMIT);
1935 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
1936 dircache_get_reserve_used(), DIRCACHE_RESERVE);
1937 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
1938 dircache_get_build_ticks() / HZ);
1939 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
1940 dircache_get_entry_count());
1941 return btn;
1944 static bool dbg_dircache_info(void)
1946 struct simplelist_info info;
1947 simplelist_info_init(&info, "Dircache Info", 7, NULL);
1948 info.action_callback = dircache_callback;
1949 info.hide_selection = true;
1950 return simplelist_show_list(&info);
1953 #endif /* HAVE_DIRCACHE */
1955 #ifdef HAVE_TAGCACHE
1956 static int database_callback(int btn, struct gui_synclist *lists)
1958 (void)lists;
1959 struct tagcache_stat *stat = tagcache_get_stat();
1960 static bool synced = false;
1962 simplelist_set_line_count(0);
1964 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
1965 stat->initialized ? "Yes" : "No");
1966 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
1967 stat->ready ? "Yes" : "No");
1968 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
1969 stat->ramcache ? "Yes" : "No");
1970 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
1971 stat->ramcache_used, stat->ramcache_allocated);
1972 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
1973 stat->progress, stat->processed_entries);
1974 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
1975 stat->curentry ? stat->curentry : "---");
1976 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
1977 stat->commit_step);
1978 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
1979 stat->commit_delayed ? "Yes" : "No");
1982 if (synced)
1984 synced = false;
1985 tagcache_screensync_event();
1988 if (!btn && stat->curentry)
1990 synced = true;
1991 return ACTION_REDRAW;
1994 if (btn == ACTION_STD_CANCEL)
1995 tagcache_screensync_enable(false);
1997 return btn;
1999 static bool dbg_tagcache_info(void)
2001 struct simplelist_info info;
2002 simplelist_info_init(&info, "Database Info", 8, NULL);
2003 info.action_callback = database_callback;
2004 info.hide_selection = true;
2005 info.timeout = TIMEOUT_NOBLOCK;
2006 tagcache_screensync_enable(true);
2007 return simplelist_show_list(&info);
2009 #endif
2011 #if CONFIG_CPU == SH7034
2012 static bool dbg_save_roms(void)
2014 int fd;
2015 int oldmode = system_memory_guard(MEMGUARD_NONE);
2017 fd = creat("/internal_rom_0000-FFFF.bin");
2018 if(fd >= 0)
2020 write(fd, (void *)0, 0x10000);
2021 close(fd);
2024 fd = creat("/internal_rom_2000000-203FFFF.bin");
2025 if(fd >= 0)
2027 write(fd, (void *)0x2000000, 0x40000);
2028 close(fd);
2031 system_memory_guard(oldmode);
2032 return false;
2034 #elif defined CPU_COLDFIRE
2035 static bool dbg_save_roms(void)
2037 int fd;
2038 int oldmode = system_memory_guard(MEMGUARD_NONE);
2040 #if defined(IRIVER_H100_SERIES)
2041 fd = creat("/internal_rom_000000-1FFFFF.bin");
2042 #elif defined(IRIVER_H300_SERIES)
2043 fd = creat("/internal_rom_000000-3FFFFF.bin");
2044 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5)
2045 fd = creat("/internal_rom_000000-3FFFFF.bin");
2046 #endif
2047 if(fd >= 0)
2049 write(fd, (void *)0, FLASH_SIZE);
2050 close(fd);
2052 system_memory_guard(oldmode);
2054 #ifdef HAVE_EEPROM
2055 fd = creat("/internal_eeprom.bin");
2056 if (fd >= 0)
2058 int old_irq_level;
2059 char buf[EEPROM_SIZE];
2060 int err;
2062 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
2064 err = eeprom_24cxx_read(0, buf, sizeof buf);
2065 if (err)
2066 gui_syncsplash(HZ*3, "Eeprom read failure (%d)",err);
2067 else
2069 write(fd, buf, sizeof buf);
2072 set_irq_level(old_irq_level);
2074 close(fd);
2076 #endif
2078 return false;
2080 #elif defined(CPU_PP) && !(defined(SANSA_E200) || defined(SANSA_C200))
2081 static bool dbg_save_roms(void)
2083 int fd;
2085 fd = creat("/internal_rom_000000-0FFFFF.bin");
2086 if(fd >= 0)
2088 write(fd, (void *)0x20000000, FLASH_SIZE);
2089 close(fd);
2092 return false;
2094 #endif /* CPU */
2096 #ifndef SIMULATOR
2097 #if CONFIG_TUNER
2098 static int radio_callback(int btn, struct gui_synclist *lists)
2100 (void)lists;
2101 if (btn == ACTION_STD_CANCEL)
2102 return btn;
2103 simplelist_set_line_count(1);
2105 #if (CONFIG_TUNER & LV24020LP)
2106 simplelist_addline(SIMPLELIST_ADD_LINE,
2107 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2108 simplelist_addline(SIMPLELIST_ADD_LINE,
2109 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2110 simplelist_addline(SIMPLELIST_ADD_LINE,
2111 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2112 simplelist_addline(SIMPLELIST_ADD_LINE,
2113 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2114 simplelist_addline(SIMPLELIST_ADD_LINE,
2115 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2116 simplelist_addline(SIMPLELIST_ADD_LINE,
2117 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2118 simplelist_addline(SIMPLELIST_ADD_LINE,
2119 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2120 #endif
2121 #if (CONFIG_TUNER & S1A0903X01)
2122 simplelist_addline(SIMPLELIST_ADD_LINE,
2123 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2124 /* This one doesn't return dynamic data atm */
2125 #endif
2126 #if (CONFIG_TUNER & TEA5767)
2127 struct tea5767_dbg_info nfo;
2128 tea5767_dbg_info(&nfo);
2129 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2130 simplelist_addline(SIMPLELIST_ADD_LINE,
2131 " Read: %02X %02X %02X %02X %02X",
2132 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2133 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2134 (unsigned)nfo.read_regs[4]);
2135 simplelist_addline(SIMPLELIST_ADD_LINE,
2136 " Write: %02X %02X %02X %02X %02X",
2137 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2138 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2139 (unsigned)nfo.write_regs[4]);
2140 #endif
2141 return ACTION_REDRAW;
2143 static bool dbg_fm_radio(void)
2145 struct simplelist_info info;
2146 simplelist_info_init(&info, "FM Radio", 1, NULL);
2147 simplelist_set_line_count(0);
2148 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2149 radio_hardware_present() ? "yes" : "no");
2151 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2152 info.hide_selection = true;
2153 return simplelist_show_list(&info);
2155 #endif /* CONFIG_TUNER */
2156 #endif /* !SIMULATOR */
2158 #ifdef HAVE_LCD_BITMAP
2159 extern bool do_screendump_instead_of_usb;
2161 static bool dbg_screendump(void)
2163 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2164 gui_syncsplash(HZ, "Screendump %s",
2165 do_screendump_instead_of_usb?"enabled":"disabled");
2166 return false;
2168 #endif /* HAVE_LCD_BITMAP */
2170 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2171 static bool dbg_set_memory_guard(void)
2173 static const struct opt_items names[MAXMEMGUARD] = {
2174 { "None", -1 },
2175 { "Flash ROM writes", -1 },
2176 { "Zero area (all)", -1 }
2178 int mode = system_memory_guard(MEMGUARD_KEEP);
2180 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2181 system_memory_guard(mode);
2183 return false;
2185 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2187 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2189 extern volatile bool lcd_poweroff;
2191 static bool dbg_lcd_power_off(void)
2193 lcd_setmargins(0, 0);
2195 while(1)
2197 int button;
2199 lcd_clear_display();
2200 lcd_puts(0, 0, "LCD Power Off");
2201 if(lcd_poweroff)
2202 lcd_puts(1, 1, "Yes");
2203 else
2204 lcd_puts(1, 1, "No");
2206 lcd_update();
2208 button = get_action(CONTEXT_STD,HZ/5);
2209 switch(button)
2211 case ACTION_STD_PREV:
2212 case ACTION_STD_NEXT:
2213 lcd_poweroff = !lcd_poweroff;
2214 break;
2215 case ACTION_STD_OK:
2216 case ACTION_STD_CANCEL:
2217 return false;
2218 default:
2219 sleep(HZ/10);
2220 break;
2223 return false;
2225 #endif
2227 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2228 static bool dbg_write_eeprom(void)
2230 int fd;
2231 int rc;
2232 int old_irq_level;
2233 char buf[EEPROM_SIZE];
2234 int err;
2236 fd = open("/internal_eeprom.bin", O_RDONLY);
2238 if (fd >= 0)
2240 rc = read(fd, buf, EEPROM_SIZE);
2242 if(rc == EEPROM_SIZE)
2244 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
2246 err = eeprom_24cxx_write(0, buf, sizeof buf);
2247 if (err)
2248 gui_syncsplash(HZ*3, "Eeprom write failure (%d)",err);
2249 else
2250 gui_syncsplash(HZ*3, "Eeprom written successfully");
2252 set_irq_level(old_irq_level);
2254 else
2256 gui_syncsplash(HZ*3, "File read error (%d)",rc);
2258 close(fd);
2260 else
2262 gui_syncsplash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2265 return false;
2267 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2268 #ifdef CPU_BOOST_LOGGING
2269 static bool cpu_boost_log(void)
2271 int i = 0,j=0;
2272 int count = cpu_boost_log_getcount();
2273 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2274 char *str;
2275 bool done;
2276 lcd_setmargins(0, 0);
2277 lcd_setfont(FONT_SYSFIXED);
2278 str = cpu_boost_log_getlog_first();
2279 while (i < count)
2281 lcd_clear_display();
2282 for(j=0; j<lines; j++,i++)
2284 if (!str)
2285 str = cpu_boost_log_getlog_next();
2286 if (str)
2288 lcd_puts(0, j,str);
2290 str = NULL;
2292 lcd_update();
2293 done = false;
2294 while (!done)
2296 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2298 case ACTION_STD_OK:
2299 case ACTION_STD_PREV:
2300 case ACTION_STD_NEXT:
2301 done = true;
2302 break;
2303 case ACTION_STD_CANCEL:
2304 i = count;
2305 done = true;
2306 break;
2310 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2311 lcd_setfont(FONT_UI);
2312 return false;
2314 #endif
2316 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2317 extern bool wheel_is_touched;
2318 extern int old_wheel_value;
2319 extern int new_wheel_value;
2320 extern int wheel_delta;
2321 extern unsigned int accumulated_wheel_delta;
2322 extern unsigned int wheel_velocity;
2324 static bool dbg_scrollwheel(void)
2326 char buf[64];
2327 unsigned int speed;
2329 lcd_setmargins(0, 0);
2330 lcd_setfont(FONT_SYSFIXED);
2332 while (1)
2334 if (action_userabort(HZ/10))
2335 return false;
2337 lcd_clear_display();
2339 /* show internal variables of scrollwheel driver */
2340 snprintf(buf, sizeof(buf), "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2341 lcd_puts(0, 0, buf);
2342 snprintf(buf, sizeof(buf), "new position: %2d", new_wheel_value);
2343 lcd_puts(0, 1, buf);
2344 snprintf(buf, sizeof(buf), "old position: %2d", old_wheel_value);
2345 lcd_puts(0, 2, buf);
2346 snprintf(buf, sizeof(buf), "wheel delta: %2d", wheel_delta);
2347 lcd_puts(0, 3, buf);
2348 snprintf(buf, sizeof(buf), "accumulated delta: %2d", accumulated_wheel_delta);
2349 lcd_puts(0, 4, buf);
2350 snprintf(buf, sizeof(buf), "velo [deg/s]: %4d", (int)wheel_velocity);
2351 lcd_puts(0, 5, buf);
2353 /* show effective accelerated scrollspeed */
2354 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2355 snprintf(buf, sizeof(buf), "accel. speed: %4d", speed);
2356 lcd_puts(0, 6, buf);
2358 lcd_update();
2360 return false;
2362 #endif
2365 /****** The menu *********/
2366 struct the_menu_item {
2367 unsigned char *desc; /* string or ID */
2368 bool (*function) (void); /* return true if USB was connected */
2370 static const struct the_menu_item menuitems[] = {
2371 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2372 { "LCD Power Off", dbg_lcd_power_off },
2373 #endif
2374 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2375 (defined(CPU_PP) && !(defined(SANSA_E200) || defined(SANSA_C200)))
2376 { "Dump ROM contents", dbg_save_roms },
2377 #endif
2378 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) || CONFIG_CPU == S3C2440
2379 { "View I/O ports", dbg_ports },
2380 #endif
2381 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2382 { "View PCF registers", dbg_pcf },
2383 #endif
2384 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2385 { "TSC2100 debug", tsc2100_debug },
2386 #endif
2387 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2388 { "CPU frequency", dbg_cpufreq },
2389 #endif
2390 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2391 { "S/PDIF analyzer", dbg_spdif },
2392 #endif
2393 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2394 { "Catch mem accesses", dbg_set_memory_guard },
2395 #endif
2396 { "View OS stacks", dbg_os },
2397 #ifdef HAVE_LCD_BITMAP
2398 #ifndef SIMULATOR
2399 { "View battery", view_battery },
2400 #endif
2401 { "Screendump", dbg_screendump },
2402 #endif
2403 #ifndef SIMULATOR
2404 { "View HW info", dbg_hw_info },
2405 #endif
2406 #ifndef SIMULATOR
2407 { "View partitions", dbg_partitions },
2408 #endif
2409 #ifndef SIMULATOR
2410 { "View disk info", dbg_disk_info },
2411 #endif
2412 #ifdef HAVE_DIRCACHE
2413 { "View dircache info", dbg_dircache_info },
2414 #endif
2415 #ifdef HAVE_TAGCACHE
2416 { "View database info", dbg_tagcache_info },
2417 #endif
2418 #ifdef HAVE_LCD_BITMAP
2419 #if CONFIG_CODEC == SWCODEC
2420 { "View buffering thread", dbg_buffering_thread },
2421 #elif !defined(SIMULATOR)
2422 { "View audio thread", dbg_audio_thread },
2423 #endif
2424 #ifdef PM_DEBUG
2425 { "pm histogram", peak_meter_histogram},
2426 #endif /* PM_DEBUG */
2427 #endif /* HAVE_LCD_BITMAP */
2428 #ifndef SIMULATOR
2429 #if CONFIG_TUNER
2430 { "FM Radio", dbg_fm_radio },
2431 #endif
2432 #endif
2433 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2434 { "Write back EEPROM", dbg_write_eeprom },
2435 #endif
2436 #ifdef ROCKBOX_HAS_LOGF
2437 {"logf", logfdisplay },
2438 {"logfdump", logfdump },
2439 #endif
2440 #ifdef CPU_BOOST_LOGGING
2441 {"cpu_boost log",cpu_boost_log},
2442 #endif
2443 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2444 {"Debug scrollwheel", dbg_scrollwheel},
2445 #endif
2447 static int menu_action_callback(int btn, struct gui_synclist *lists)
2449 if (btn == ACTION_STD_OK)
2451 menuitems[gui_synclist_get_sel_pos(lists)].function();
2452 btn = ACTION_REDRAW;
2454 return btn;
2456 static char* dbg_menu_getname(int item, void * data, char *buffer)
2458 (void)data; (void)buffer;
2459 return menuitems[item].desc;
2461 bool debug_menu(void)
2463 struct simplelist_info info;
2465 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2466 info.action_callback = menu_action_callback;
2467 info.get_name = dbg_menu_getname;
2469 return simplelist_show_list(&info);