Revert "Replace yield_codec() with a call to queue_wait_w_tmo()" and the related...
[Rockbox.git] / apps / debug_menu.c
blob4dc37ef83f2e21fdfe9e4c5ba94241216facc7b2
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"
91 /*---------------------------------------------------*/
92 /* SPECIAL DEBUG STUFF */
93 /*---------------------------------------------------*/
94 extern struct thread_entry threads[MAXTHREADS];
96 static char thread_status_char(unsigned status)
98 static const char thread_status_chars[THREAD_NUM_STATES+1] =
100 [0 ... THREAD_NUM_STATES] = '?',
101 [STATE_RUNNING] = 'R',
102 [STATE_BLOCKED] = 'B',
103 [STATE_SLEEPING] = 'S',
104 [STATE_BLOCKED_W_TMO] = 'T',
105 [STATE_FROZEN] = 'F',
106 [STATE_KILLED] = 'K',
109 #if NUM_CORES > 1
110 if (status == STATE_BUSY) /* Not a state index */
111 return '.';
112 #endif
114 if (status > THREAD_NUM_STATES)
115 status = THREAD_NUM_STATES;
117 return thread_status_chars[status];
120 static char* threads_getname(int selected_item, void * data, char *buffer)
122 (void)data;
123 char name[32];
124 struct thread_entry *thread = NULL;
125 unsigned status;
126 int usage;
128 #if NUM_CORES > 1
129 if (selected_item < (int)NUM_CORES)
131 usage = idle_stack_usage(selected_item);
132 snprintf(buffer, MAX_PATH, "Idle (%d): %2d%%", selected_item, usage);
133 return buffer;
136 selected_item -= NUM_CORES;
137 #endif
139 thread = &threads[selected_item];
140 status = thread_get_status(thread);
142 if (status == STATE_KILLED)
144 snprintf(buffer, MAX_PATH, "%2d: ---", selected_item);
145 return buffer;
148 thread_get_name(name, 32, thread);
149 usage = thread_stack_usage(thread);
151 snprintf(buffer, MAX_PATH,
152 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d ") "%2d%% %s",
153 selected_item,
154 IF_COP(thread->core,)
155 (status == STATE_RUNNING) ? '*' : ' ',
156 thread_status_char(status),
157 IF_PRIO(thread->priority,)
158 usage, name);
160 return buffer;
162 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
164 (void)lists;
165 #ifdef ROCKBOX_HAS_LOGF
166 if (action == ACTION_STD_OK)
168 int selpos = gui_synclist_get_sel_pos(lists);
169 #if NUM_CORES > 1
170 if (selpos >= NUM_CORES)
171 remove_thread(&threads[selpos - NUM_CORES]);
172 #else
173 remove_thread(&threads[selpos]);
174 #endif
175 return ACTION_REDRAW;
177 #endif /* ROCKBOX_HAS_LOGF */
178 return action;
180 /* Test code!!! */
181 static bool dbg_os(void)
183 struct simplelist_info info;
184 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
185 #if NUM_CORES == 1
186 MAXTHREADS,
187 #else
188 MAXTHREADS+NUM_CORES,
189 #endif
190 NULL);
191 #ifndef ROCKBOX_HAS_LOGF
192 info.hide_selection = true;
193 #endif
194 info.action_callback = dbg_threads_action_callback;
195 info.get_name = threads_getname;
196 return simplelist_show_list(&info);
199 #ifdef HAVE_LCD_BITMAP
200 #if CONFIG_CODEC != SWCODEC
201 #ifndef SIMULATOR
202 static bool dbg_audio_thread(void)
204 char buf[32];
205 struct audio_debug d;
207 lcd_setmargins(0, 0);
208 lcd_setfont(FONT_SYSFIXED);
210 while(1)
212 if (action_userabort(HZ/5))
213 return false;
215 audio_get_debugdata(&d);
217 lcd_clear_display();
219 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
220 lcd_puts(0, 0, buf);
221 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
222 lcd_puts(0, 1, buf);
223 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
224 lcd_puts(0, 2, buf);
225 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
226 lcd_puts(0, 3, buf);
227 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
228 lcd_puts(0, 4, buf);
229 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
230 lcd_puts(0, 5, buf);
232 /* Playable space left */
233 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
234 d.playable_space, HORIZONTAL);
236 /* Show the watermark limit */
237 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
238 d.low_watermark_level, HORIZONTAL);
240 snprintf(buf, sizeof(buf), "wm: %x - %x",
241 d.low_watermark_level, d.lowest_watermark_level);
242 lcd_puts(0, 7, buf);
244 lcd_update();
246 return false;
248 #endif /* !SIMULATOR */
249 #else /* CONFIG_CODEC == SWCODEC */
250 extern size_t filebuflen;
251 /* This is a size_t, but call it a long so it puts a - when it's bad. */
253 static unsigned int ticks, boost_ticks;
255 static void dbg_audio_task(void)
257 #ifndef SIMULATOR
258 if(FREQ > CPUFREQ_NORMAL)
259 boost_ticks++;
260 #endif
262 ticks++;
265 static bool dbg_audio_thread(void)
267 char buf[32];
268 int button;
269 int line;
270 bool done = false;
271 size_t bufused;
272 size_t bufsize = pcmbuf_get_bufsize();
273 int pcmbufdescs = pcmbuf_descs();
275 ticks = boost_ticks = 0;
277 tick_add_task(dbg_audio_task);
279 lcd_setmargins(0, 0);
280 lcd_setfont(FONT_SYSFIXED);
281 while(!done)
283 button = get_action(CONTEXT_STD,HZ/5);
284 switch(button)
286 case ACTION_STD_NEXT:
287 audio_next();
288 break;
289 case ACTION_STD_PREV:
290 audio_prev();
291 break;
292 case ACTION_STD_CANCEL:
293 done = true;
294 break;
296 line = 0;
297 lcd_clear_display();
299 bufused = bufsize - pcmbuf_free();
301 snprintf(buf, sizeof(buf), "pcm: %7ld/%7ld", (long) bufused, (long) bufsize);
302 lcd_puts(0, line++, buf);
304 /* Playable space left */
305 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6, bufsize, 0, bufused, HORIZONTAL);
306 line++;
308 snprintf(buf, sizeof(buf), "codec: %8ld/%8ld", audio_filebufused(), (long) filebuflen);
309 lcd_puts(0, line++, buf);
311 /* Playable space left */
312 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6, filebuflen, 0,
313 audio_filebufused(), HORIZONTAL);
314 line++;
316 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
317 lcd_puts(0, line++, buf);
319 #ifndef SIMULATOR
320 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
321 (int)((FREQ + 500000) / 1000000));
322 lcd_puts(0, line++, buf);
323 #endif
325 if (ticks > 0)
327 snprintf(buf, sizeof(buf), "boost ratio: %3d%%",
328 boost_ticks * 100 / ticks);
329 lcd_puts(0, line++, buf);
332 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
333 pcmbuf_used_descs(), pcmbufdescs);
334 lcd_puts(0, line++, buf);
336 lcd_update();
339 tick_remove_task(dbg_audio_task);
341 return false;
344 static bool dbg_buffering_thread(void)
346 char buf[32];
347 int button;
348 int line;
349 bool done = false;
350 struct buffering_debug d;
352 lcd_setmargins(0, 0);
353 lcd_setfont(FONT_SYSFIXED);
354 while(!done)
356 button = get_action(CONTEXT_STD,HZ/5);
357 switch(button)
359 case ACTION_STD_NEXT:
360 audio_next();
361 break;
362 case ACTION_STD_PREV:
363 audio_prev();
364 break;
365 case ACTION_STD_CANCEL:
366 done = true;
367 break;
370 buffering_get_debugdata(&d);
372 line = 0;
373 lcd_clear_display();
375 snprintf(buf, sizeof(buf), "handle count: %d", (int)d.num_handles);
376 lcd_puts(0, line++, buf);
378 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count()-1);
379 lcd_puts(0, line++, buf);
381 snprintf(buf, sizeof(buf), "data_rem: %8ld", (long)d.data_rem);
382 lcd_puts(0, line++, buf);
384 snprintf(buf, sizeof(buf), "alloc: %8ld/%8ld", audio_filebufused(),
385 (long) filebuflen);
386 lcd_puts(0, line++, buf);
388 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
389 filebuflen, 0, audio_filebufused(), HORIZONTAL);
390 line++;
392 snprintf(buf, sizeof(buf), "real: %8ld/%8ld", (long)d.buffered_data,
393 (long)filebuflen);
394 lcd_puts(0, line++, buf);
396 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
397 filebuflen, 0, d.buffered_data, HORIZONTAL);
398 line++;
400 #ifndef SIMULATOR
401 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
402 (int)((FREQ + 500000) / 1000000));
403 lcd_puts(0, line++, buf);
404 #endif
406 lcd_update();
409 return false;
411 #endif /* CONFIG_CODEC */
412 #endif /* HAVE_LCD_BITMAP */
415 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
416 /* Tool function to read the flash manufacturer and type, if available.
417 Only chips which could be reprogrammed in system will return values.
418 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
419 /* In IRAM to avoid problems when running directly from Flash */
420 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
421 unsigned addr1, unsigned addr2)
422 ICODE_ATTR __attribute__((noinline));
423 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
424 unsigned addr1, unsigned addr2)
427 unsigned not_manu, not_id; /* read values before switching to ID mode */
428 unsigned manu, id; /* read values when in ID mode */
430 #if CONFIG_CPU == SH7034
431 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
432 #elif defined(CPU_COLDFIRE)
433 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
434 #endif
435 int old_level; /* saved interrupt level */
437 not_manu = flash[0]; /* read the normal content */
438 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
440 /* disable interrupts, prevent any stray flash access */
441 old_level = set_irq_level(HIGHEST_IRQ_LEVEL);
443 flash[addr1] = 0xAA; /* enter command mode */
444 flash[addr2] = 0x55;
445 flash[addr1] = 0x90; /* ID command */
446 /* Atmel wants 20ms pause here */
447 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
449 manu = flash[0]; /* read the IDs */
450 id = flash[1];
452 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
453 /* Atmel wants 20ms pause here */
454 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
456 set_irq_level(old_level); /* enable interrupts again */
458 /* I assume success if the obtained values are different from
459 the normal flash content. This is not perfectly bulletproof, they
460 could theoretically be the same by chance, causing us to fail. */
461 if (not_manu != manu || not_id != id) /* a value has changed */
463 *p_manufacturer = manu; /* return the results */
464 *p_device = id;
465 return true; /* success */
467 return false; /* fail */
469 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
471 #ifndef SIMULATOR
472 #ifdef CPU_PP
473 static int perfcheck(void)
475 int result;
477 asm (
478 "mrs r2, CPSR \n"
479 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
480 "msr CPSR_c, r0 \n"
481 "mov %[res], #0 \n"
482 "ldr r0, [%[timr]] \n"
483 "add r0, r0, %[tmo] \n"
484 "1: \n"
485 "add %[res], %[res], #1 \n"
486 "ldr r1, [%[timr]] \n"
487 "cmp r1, r0 \n"
488 "bmi 1b \n"
489 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
491 [res]"=&r"(result)
493 [timr]"r"(&USEC_TIMER),
494 [tmo]"r"(
495 #if CONFIG_CPU == PP5002
496 16000
497 #else /* PP5020/5022/5024 */
498 10226
499 #endif
502 "r0", "r1", "r2"
504 return result;
506 #endif
508 #ifdef HAVE_LCD_BITMAP
509 static bool dbg_hw_info(void)
511 #if CONFIG_CPU == SH7034
512 char buf[32];
513 int bitmask = HW_MASK;
514 int rom_version = ROM_VERSION;
515 unsigned manu, id; /* flash IDs */
516 bool got_id; /* flag if we managed to get the flash IDs */
517 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
518 bool has_bootrom; /* flag for boot ROM present */
519 int oldmode; /* saved memory guard mode */
521 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
523 /* get flash ROM type */
524 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
525 if (!got_id)
526 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
528 /* check if the boot ROM area is a flash mirror */
529 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
530 if (has_bootrom) /* if ROM and Flash different */
532 /* calculate CRC16 checksum of boot ROM */
533 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
536 system_memory_guard(oldmode); /* re-enable memory guard */
538 lcd_setmargins(0, 0);
539 lcd_setfont(FONT_SYSFIXED);
540 lcd_clear_display();
542 lcd_puts(0, 0, "[Hardware info]");
544 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
545 lcd_puts(0, 1, buf);
547 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
548 lcd_puts(0, 2, buf);
550 if (got_id)
551 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
552 else
553 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
554 lcd_puts(0, 3, buf);
556 if (has_bootrom)
558 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
559 snprintf(buf, 32, "Boot ROM: V1");
560 else
561 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
563 else
565 snprintf(buf, 32, "Boot ROM: none");
567 lcd_puts(0, 4, buf);
569 lcd_update();
571 while (!(action_userabort(TIMEOUT_BLOCK)));
573 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
574 char buf[32];
575 unsigned manu, id; /* flash IDs */
576 int got_id; /* flag if we managed to get the flash IDs */
577 int oldmode; /* saved memory guard mode */
578 int line = 0;
580 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
582 /* get flash ROM type */
583 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
584 if (!got_id)
585 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
587 system_memory_guard(oldmode); /* re-enable memory guard */
589 lcd_setmargins(0, 0);
590 lcd_setfont(FONT_SYSFIXED);
591 lcd_clear_display();
593 lcd_puts(0, line++, "[Hardware info]");
595 if (got_id)
596 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
597 else
598 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
599 lcd_puts(0, line++, buf);
601 #ifdef IAUDIO_X5
603 struct ds2411_id id;
605 lcd_puts(0, ++line, "Serial Number:");
607 got_id = ds2411_read_id(&id);
609 if (got_id == DS2411_OK)
611 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
612 lcd_puts(0, ++line, buf);
613 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
614 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
615 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
616 lcd_puts(0, ++line, buf);
617 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
619 else
621 snprintf(buf, 32, "READ ERR=%d", got_id);
624 lcd_puts(0, ++line, buf);
626 #endif
628 lcd_update();
630 while (!(action_userabort(TIMEOUT_BLOCK)));
632 #elif defined(CPU_PP502x)
633 int line = 0;
634 char buf[32];
635 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
636 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
637 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
638 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
640 lcd_setmargins(0, 0);
641 lcd_setfont(FONT_SYSFIXED);
642 lcd_clear_display();
644 lcd_puts(0, line++, "[Hardware info]");
646 #ifdef IPOD_ARCH
647 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
648 lcd_puts(0, line++, buf);
649 #endif
651 #ifdef IPOD_COLOR
652 extern int lcd_type; /* Defined in lcd-colornano.c */
654 snprintf(buf, sizeof(buf), "LCD type: %d", lcd_type);
655 lcd_puts(0, line++, buf);
656 #endif
658 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
659 lcd_puts(0, line++, buf);
661 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
662 lcd_puts(0, line++, buf);
664 lcd_update();
666 while (!(action_userabort(TIMEOUT_BLOCK)));
668 #elif CONFIG_CPU == PP5002
669 int line = 0;
670 char buf[32];
672 lcd_setmargins(0, 0);
673 lcd_setfont(FONT_SYSFIXED);
674 lcd_clear_display();
676 lcd_puts(0, line++, "[Hardware info]");
678 #ifdef IPOD_ARCH
679 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
680 lcd_puts(0, line++, buf);
681 #endif
683 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
684 lcd_puts(0, line++, buf);
686 lcd_update();
688 while (!(action_userabort(TIMEOUT_BLOCK)));
690 #endif /* CONFIG_CPU */
691 return false;
693 #else /* !HAVE_LCD_BITMAP */
694 static bool dbg_hw_info(void)
696 char buf[32];
697 int button;
698 int currval = 0;
699 int rom_version = ROM_VERSION;
700 unsigned manu, id; /* flash IDs */
701 bool got_id; /* flag if we managed to get the flash IDs */
702 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
703 bool has_bootrom; /* flag for boot ROM present */
704 int oldmode; /* saved memory guard mode */
706 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
708 /* get flash ROM type */
709 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
710 if (!got_id)
711 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
713 /* check if the boot ROM area is a flash mirror */
714 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
715 if (has_bootrom) /* if ROM and Flash different */
717 /* calculate CRC16 checksum of boot ROM */
718 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
721 system_memory_guard(oldmode); /* re-enable memory guard */
723 lcd_clear_display();
725 lcd_puts(0, 0, "[HW Info]");
726 while(1)
728 switch(currval)
730 case 0:
731 snprintf(buf, 32, "ROM: %d.%02d",
732 rom_version/100, rom_version%100);
733 break;
734 case 1:
735 if (got_id)
736 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
737 else
738 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
739 break;
740 case 2:
741 if (has_bootrom)
743 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
744 snprintf(buf, 32, "BootROM: V1");
745 else if (rom_crc == 0x358099E8)
746 snprintf(buf, 32, "BootROM: V2");
747 /* alternative boot ROM found in one single player so far */
748 else
749 snprintf(buf, 32, "R: %08x", rom_crc);
751 else
752 snprintf(buf, 32, "BootROM: no");
755 lcd_puts(0, 1, buf);
756 lcd_update();
758 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
760 switch(button)
762 case ACTION_STD_CANCEL:
763 return false;
765 case ACTION_SETTINGS_DEC:
766 currval--;
767 if(currval < 0)
768 currval = 2;
769 break;
771 case ACTION_SETTINGS_INC:
772 currval++;
773 if(currval > 2)
774 currval = 0;
775 break;
778 return false;
780 #endif /* !HAVE_LCD_BITMAP */
781 #endif /* !SIMULATOR */
783 #ifndef SIMULATOR
784 static char* dbg_partitions_getname(int selected_item, void * data, char *buffer)
786 (void)data;
787 int partition = selected_item/2;
788 struct partinfo* p = disk_partinfo(partition);
789 if (selected_item%2)
791 snprintf(buffer, MAX_PATH, " T:%x %ld MB", p->type, p->size / 2048);
793 else
795 snprintf(buffer, MAX_PATH, "P%d: S:%lx", partition, p->start);
797 return buffer;
800 bool dbg_partitions(void)
802 struct simplelist_info info;
803 simplelist_info_init(&info, "Partition Info", 4, NULL);
804 info.selection_size = 2;
805 info.hide_selection = true;
806 info.get_name = dbg_partitions_getname;
807 return simplelist_show_list(&info);
809 #endif
811 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
812 static bool dbg_spdif(void)
814 char buf[128];
815 int line;
816 unsigned int control;
817 int x;
818 char *s;
819 int category;
820 int generation;
821 unsigned int interruptstat;
822 bool valnogood, symbolerr, parityerr;
823 bool done = false;
824 bool spdif_src_on;
825 int spdif_source = spdif_get_output_source(&spdif_src_on);
826 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
828 lcd_setmargins(0, 0);
829 lcd_clear_display();
830 lcd_setfont(FONT_SYSFIXED);
832 #ifdef HAVE_SPDIF_POWER
833 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
834 #endif
836 while (!done)
838 line = 0;
840 control = EBU1RCVCCHANNEL1;
841 interruptstat = INTERRUPTSTAT;
842 INTERRUPTCLEAR = 0x03c00000;
844 valnogood = (interruptstat & 0x01000000)?true:false;
845 symbolerr = (interruptstat & 0x00800000)?true:false;
846 parityerr = (interruptstat & 0x00400000)?true:false;
848 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
849 valnogood?"--":"OK",
850 symbolerr?"--":"OK",
851 parityerr?"--":"OK");
852 lcd_puts(0, line++, buf);
854 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
855 lcd_puts(0, line++, buf);
857 line++;
859 x = control >> 31;
860 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
861 x, x?"Professional":"Consumer");
862 lcd_puts(0, line++, buf);
864 x = (control >> 30) & 1;
865 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
866 x, x?"Non-PCM":"PCM");
867 lcd_puts(0, line++, buf);
869 x = (control >> 29) & 1;
870 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
871 x, x?"Permitted":"Inhibited");
872 lcd_puts(0, line++, buf);
874 x = (control >> 27) & 7;
875 switch(x)
877 case 0:
878 s = "None";
879 break;
880 case 1:
881 s = "50/15us";
882 break;
883 default:
884 s = "Reserved";
885 break;
887 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
888 lcd_puts(0, line++, buf);
890 x = (control >> 24) & 3;
891 snprintf(buf, sizeof(buf), "Mode: %d", x);
892 lcd_puts(0, line++, buf);
894 category = (control >> 17) & 127;
895 switch(category)
897 case 0x00:
898 s = "General";
899 break;
900 case 0x40:
901 s = "Audio CD";
902 break;
903 default:
904 s = "Unknown";
906 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
907 lcd_puts(0, line++, buf);
909 x = (control >> 16) & 1;
910 generation = x;
911 if(((category & 0x70) == 0x10) ||
912 ((category & 0x70) == 0x40) ||
913 ((category & 0x78) == 0x38))
915 generation = !generation;
917 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
918 x, generation?"Original":"No ind.");
919 lcd_puts(0, line++, buf);
921 x = (control >> 12) & 15;
922 snprintf(buf, sizeof(buf), "Source: %d", x);
923 lcd_puts(0, line++, buf);
925 x = (control >> 8) & 15;
926 switch(x)
928 case 0:
929 s = "Unspecified";
930 break;
931 case 8:
932 s = "A (Left)";
933 break;
934 case 4:
935 s = "B (Right)";
936 break;
937 default:
938 s = "";
939 break;
941 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
942 lcd_puts(0, line++, buf);
944 x = (control >> 4) & 15;
945 switch(x)
947 case 0:
948 s = "44.1kHz";
949 break;
950 case 0x4:
951 s = "48kHz";
952 break;
953 case 0xc:
954 s = "32kHz";
955 break;
957 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
958 lcd_puts(0, line++, buf);
960 x = (control >> 2) & 3;
961 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
962 lcd_puts(0, line++, buf);
963 line++;
965 #ifndef SIMULATOR
966 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
967 spdif_measure_frequency());
968 lcd_puts(0, line++, buf);
969 #endif
971 lcd_update();
973 if (action_userabort(HZ/10))
974 break;
977 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
979 #ifdef HAVE_SPDIF_POWER
980 spdif_power_enable(global_settings.spdif_enable);
981 #endif
983 return false;
985 #endif /* CPU_COLDFIRE */
987 #ifndef SIMULATOR
988 #ifdef HAVE_LCD_BITMAP
989 /* button definitions */
990 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
991 (CONFIG_KEYPAD == IRIVER_H300_PAD)
992 # define DEBUG_CANCEL BUTTON_OFF
994 #elif CONFIG_KEYPAD == RECORDER_PAD
995 # define DEBUG_CANCEL BUTTON_OFF
997 #elif CONFIG_KEYPAD == ONDIO_PAD
998 # define DEBUG_CANCEL BUTTON_MENU
1000 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
1001 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
1002 (CONFIG_KEYPAD == IPOD_4G_PAD)
1003 # define DEBUG_CANCEL BUTTON_MENU
1005 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
1006 # define DEBUG_CANCEL BUTTON_PLAY
1008 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
1009 # define DEBUG_CANCEL BUTTON_REC
1011 #elif CONFIG_KEYPAD == GIGABEAT_PAD
1012 # define DEBUG_CANCEL BUTTON_A
1014 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
1015 # define DEBUG_CANCEL BUTTON_REW
1017 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
1018 (CONFIG_KEYPAD == SANSA_C200_PAD)
1019 # define DEBUG_CANCEL BUTTON_LEFT
1020 #endif /* key definitios */
1022 /* Test code!!! */
1023 bool dbg_ports(void)
1025 #if CONFIG_CPU == SH7034
1026 unsigned short porta;
1027 unsigned short portb;
1028 unsigned char portc;
1029 char buf[32];
1030 int adc_battery_voltage, adc_battery_level;
1032 lcd_setfont(FONT_SYSFIXED);
1033 lcd_setmargins(0, 0);
1034 lcd_clear_display();
1036 while(1)
1038 porta = PADR;
1039 portb = PBDR;
1040 portc = PCDR;
1042 snprintf(buf, 32, "PADR: %04x", porta);
1043 lcd_puts(0, 0, buf);
1044 snprintf(buf, 32, "PBDR: %04x", portb);
1045 lcd_puts(0, 1, buf);
1047 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1048 lcd_puts(0, 2, buf);
1049 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1050 lcd_puts(0, 3, buf);
1051 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1052 lcd_puts(0, 4, buf);
1053 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1054 lcd_puts(0, 5, buf);
1056 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1057 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1058 adc_battery_voltage % 1000, adc_battery_level);
1059 lcd_puts(0, 6, buf);
1061 lcd_update();
1062 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1063 return false;
1065 #elif defined(CPU_COLDFIRE)
1066 unsigned int gpio_out;
1067 unsigned int gpio1_out;
1068 unsigned int gpio_read;
1069 unsigned int gpio1_read;
1070 unsigned int gpio_function;
1071 unsigned int gpio1_function;
1072 unsigned int gpio_enable;
1073 unsigned int gpio1_enable;
1074 int adc_buttons, adc_remote;
1075 int adc_battery_voltage, adc_battery_level;
1076 char buf[128];
1077 int line;
1079 lcd_setmargins(0, 0);
1080 lcd_clear_display();
1081 lcd_setfont(FONT_SYSFIXED);
1083 while(1)
1085 line = 0;
1086 gpio_read = GPIO_READ;
1087 gpio1_read = GPIO1_READ;
1088 gpio_out = GPIO_OUT;
1089 gpio1_out = GPIO1_OUT;
1090 gpio_function = GPIO_FUNCTION;
1091 gpio1_function = GPIO1_FUNCTION;
1092 gpio_enable = GPIO_ENABLE;
1093 gpio1_enable = GPIO1_ENABLE;
1095 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1096 lcd_puts(0, line++, buf);
1097 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1098 lcd_puts(0, line++, buf);
1099 snprintf(buf, sizeof(buf), "GPIO_FUNCTION: %08x", gpio_function);
1100 lcd_puts(0, line++, buf);
1101 snprintf(buf, sizeof(buf), "GPIO_ENABLE: %08x", gpio_enable);
1102 lcd_puts(0, line++, buf);
1104 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1105 lcd_puts(0, line++, buf);
1106 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1107 lcd_puts(0, line++, buf);
1108 snprintf(buf, sizeof(buf), "GPIO1_FUNCTION: %08x", gpio1_function);
1109 lcd_puts(0, line++, buf);
1110 snprintf(buf, sizeof(buf), "GPIO1_ENABLE: %08x", gpio1_enable);
1111 lcd_puts(0, line++, buf);
1113 adc_buttons = adc_read(ADC_BUTTONS);
1114 adc_remote = adc_read(ADC_REMOTE);
1115 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1116 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1117 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1118 button_scan_enabled() ? '+' : '-', adc_buttons);
1119 #else
1120 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1121 #endif
1122 lcd_puts(0, line++, buf);
1123 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1124 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1125 remote_detect() ? '+' : '-', adc_remote);
1126 #else
1127 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1128 #endif
1129 lcd_puts(0, line++, buf);
1130 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1131 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1132 adc_read(ADC_REMOTEDETECT));
1133 lcd_puts(0, line++, buf);
1134 #endif
1136 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1137 adc_battery_voltage % 1000, adc_battery_level);
1138 lcd_puts(0, line++, buf);
1140 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1141 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1142 lcd_puts(0, line++, buf);
1143 #endif
1145 lcd_update();
1146 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1147 return false;
1150 #elif defined(CPU_PP502x)
1152 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1153 unsigned int gpio_e, gpio_f, gpio_g, gpio_h;
1154 unsigned int gpio_i, gpio_j, gpio_k, gpio_l;
1156 char buf[128];
1157 int line;
1159 lcd_setmargins(0, 0);
1160 lcd_clear_display();
1161 lcd_setfont(FONT_SYSFIXED);
1163 while(1)
1165 gpio_a = GPIOA_INPUT_VAL;
1166 gpio_b = GPIOB_INPUT_VAL;
1167 gpio_c = GPIOC_INPUT_VAL;
1169 gpio_g = GPIOG_INPUT_VAL;
1170 gpio_h = GPIOH_INPUT_VAL;
1171 gpio_i = GPIOI_INPUT_VAL;
1173 line = 0;
1174 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_G: %02x", gpio_a, gpio_g);
1175 lcd_puts(0, line++, buf);
1176 snprintf(buf, sizeof(buf), "GPIO_B: %02x GPIO_H: %02x", gpio_b, gpio_h);
1177 lcd_puts(0, line++, buf);
1178 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_I: %02x", gpio_c, gpio_i);
1179 lcd_puts(0, line++, buf);
1181 gpio_d = GPIOD_INPUT_VAL;
1182 gpio_e = GPIOE_INPUT_VAL;
1183 gpio_f = GPIOF_INPUT_VAL;
1185 gpio_j = GPIOJ_INPUT_VAL;
1186 gpio_k = GPIOK_INPUT_VAL;
1187 gpio_l = GPIOL_INPUT_VAL;
1189 snprintf(buf, sizeof(buf), "GPIO_D: %02x GPIO_J: %02x", gpio_d, gpio_j);
1190 lcd_puts(0, line++, buf);
1191 snprintf(buf, sizeof(buf), "GPIO_E: %02x GPIO_K: %02x", gpio_e, gpio_k);
1192 lcd_puts(0, line++, buf);
1193 snprintf(buf, sizeof(buf), "GPIO_F: %02x GPIO_L: %02x", gpio_f, gpio_l);
1194 lcd_puts(0, line++, buf);
1195 line++;
1197 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1198 lcd_puts(0, line++, buf);
1199 snprintf(buf, sizeof(buf), "CLOCK_SRC: %08lx", CLOCK_SOURCE);
1200 lcd_puts(0, line++, buf);
1201 snprintf(buf, sizeof(buf), "CLCD_CLK_SRC: %08lx", CLCD_CLOCK_SRC);
1202 lcd_puts(0, line++, buf);
1203 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1204 lcd_puts(0, line++, buf);
1205 snprintf(buf, sizeof(buf), "PLL_STATUS: %08lx", PLL_STATUS);
1206 lcd_puts(0, line++, buf);
1207 snprintf(buf, sizeof(buf), "DEV_TIMING1: %08lx", DEV_TIMING1);
1208 lcd_puts(0, line++, buf);
1210 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1211 line++;
1212 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x", adc_read(ADC_BATTERY),
1213 adc_read(ADC_UNKNOWN_1));
1214 lcd_puts(0, line++, buf);
1215 snprintf(buf, sizeof(buf), "REM: %03x PAD: %03x", adc_read(ADC_REMOTE),
1216 adc_read(ADC_SCROLLPAD));
1217 lcd_puts(0, line++, buf);
1218 #elif defined(SANSA_E200)
1219 line++;
1220 snprintf(buf, sizeof(buf), "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1221 lcd_puts(0, line++, buf);
1222 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1223 lcd_puts(0, line++, buf);
1224 snprintf(buf, sizeof(buf), "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1225 lcd_puts(0, line++, buf);
1226 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1227 lcd_puts(0, line++, buf);
1228 snprintf(buf, sizeof(buf), "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1229 lcd_puts(0, line++, buf);
1230 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1231 lcd_puts(0, line++, buf);
1232 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1233 lcd_puts(0, line++, buf);
1234 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1235 lcd_puts(0, line++, buf);
1236 snprintf(buf, sizeof(buf), "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1237 lcd_puts(0, line++, buf);
1238 snprintf(buf, sizeof(buf), "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1239 lcd_puts(0, line++, buf);
1240 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1241 lcd_puts(0, line++, buf);
1242 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1243 lcd_puts(0, line++, buf);
1244 snprintf(buf, sizeof(buf), "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1245 lcd_puts(0, line++, buf);
1246 #endif
1247 lcd_update();
1248 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1249 return false;
1252 #elif CONFIG_CPU == PP5002
1253 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1255 char buf[128];
1256 int line;
1258 lcd_setmargins(0, 0);
1259 lcd_clear_display();
1260 lcd_setfont(FONT_SYSFIXED);
1262 while(1)
1264 gpio_a = GPIOA_INPUT_VAL;
1265 gpio_b = GPIOB_INPUT_VAL;
1266 gpio_c = GPIOC_INPUT_VAL;
1267 gpio_d = GPIOD_INPUT_VAL;
1269 line = 0;
1270 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x", gpio_a, gpio_b);
1271 lcd_puts(0, line++, buf);
1272 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x", gpio_c, gpio_d);
1273 lcd_puts(0, line++, buf);
1275 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1276 lcd_puts(0, line++, buf);
1277 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1278 lcd_puts(0, line++, buf);
1279 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1280 lcd_puts(0, line++, buf);
1281 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1282 lcd_puts(0, line++, buf);
1283 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1284 lcd_puts(0, line++, buf);
1285 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1286 lcd_puts(0, line++, buf);
1287 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1288 lcd_puts(0, line++, buf);
1289 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1290 lcd_puts(0, line++, buf);
1292 lcd_update();
1293 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1294 return false;
1296 #elif CONFIG_CPU == S3C2440
1297 char buf[50];
1298 int line;
1300 lcd_setmargins(0, 0);
1301 lcd_clear_display();
1302 lcd_setfont(FONT_SYSFIXED);
1304 while(1)
1306 line = 0;
1307 snprintf(buf, sizeof(buf), "[Ports and Registers]"); lcd_puts(0, line++, buf);
1309 snprintf(buf, sizeof(buf), "GPACON: %08x GPBCON: %08x", GPACON, GPBCON); lcd_puts(0, line++, buf);
1310 snprintf(buf, sizeof(buf), "GPADAT: %08x GPBDAT: %08x", GPADAT, GPBDAT); lcd_puts(0, line++, buf);
1311 snprintf(buf, sizeof(buf), "GPAUP: %08x GPBUP: %08x", 0, GPBUP); lcd_puts(0, line++, buf);
1312 snprintf(buf, sizeof(buf), "GPCCON: %08x GPDCON: %08x", GPCCON, GPDCON); lcd_puts(0, line++, buf);
1313 snprintf(buf, sizeof(buf), "GPCDAT: %08x GPDDAT: %08x", GPCDAT, GPDDAT); lcd_puts(0, line++, buf);
1314 snprintf(buf, sizeof(buf), "GPCUP: %08x GPDUP: %08x", GPCUP, GPDUP); lcd_puts(0, line++, buf);
1316 snprintf(buf, sizeof(buf), "GPCCON: %08x GPDCON: %08x", GPCCON, GPDCON); lcd_puts(0, line++, buf);
1317 snprintf(buf, sizeof(buf), "GPCDAT: %08x GPDDAT: %08x", GPCDAT, GPDDAT); lcd_puts(0, line++, buf);
1318 snprintf(buf, sizeof(buf), "GPCUP: %08x GPDUP: %08x", GPCUP, GPDUP); lcd_puts(0, line++, buf);
1320 snprintf(buf, sizeof(buf), "GPECON: %08x GPFCON: %08x", GPECON, GPFCON); lcd_puts(0, line++, buf);
1321 snprintf(buf, sizeof(buf), "GPEDAT: %08x GPFDAT: %08x", GPEDAT, GPFDAT); lcd_puts(0, line++, buf);
1322 snprintf(buf, sizeof(buf), "GPEUP: %08x GPFUP: %08x", GPEUP, GPFUP); lcd_puts(0, line++, buf);
1324 snprintf(buf, sizeof(buf), "GPGCON: %08x GPHCON: %08x", GPGCON, GPHCON); lcd_puts(0, line++, buf);
1325 snprintf(buf, sizeof(buf), "GPGDAT: %08x GPHDAT: %08x", GPGDAT, GPHDAT); lcd_puts(0, line++, buf);
1326 snprintf(buf, sizeof(buf), "GPGUP: %08x GPHUP: %08x", GPGUP, GPHUP); lcd_puts(0, line++, buf);
1328 snprintf(buf, sizeof(buf), "GPJCON: %08x", GPJCON); lcd_puts(0, line++, buf);
1329 snprintf(buf, sizeof(buf), "GPJDAT: %08x", GPJDAT); lcd_puts(0, line++, buf);
1330 snprintf(buf, sizeof(buf), "GPJUP: %08x", GPJUP); lcd_puts(0, line++, buf);
1332 line++;
1334 snprintf(buf, sizeof(buf), "SRCPND: %08x INTMOD: %08x", SRCPND, INTMOD); lcd_puts(0, line++, buf);
1335 snprintf(buf, sizeof(buf), "INTMSK: %08x INTPND: %08x", INTMSK, INTPND); lcd_puts(0, line++, buf);
1336 snprintf(buf, sizeof(buf), "CLKCON: %08x CLKSLOW: %08x", CLKCON, CLKSLOW); lcd_puts(0, line++, buf);
1337 snprintf(buf, sizeof(buf), "MPLLCON: %08x UPLLCON: %08x", MPLLCON, UPLLCON); lcd_puts(0, line++, buf);
1338 snprintf(buf, sizeof(buf), "CLKDIVN: %08x", CLKDIVN); lcd_puts(0, line++, buf);
1340 lcd_update();
1341 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1342 return false;
1344 #endif /* CPU */
1345 return false;
1347 #else /* !HAVE_LCD_BITMAP */
1348 bool dbg_ports(void)
1350 unsigned short porta;
1351 unsigned short portb;
1352 unsigned char portc;
1353 char buf[32];
1354 int button;
1355 int adc_battery_voltage;
1356 int currval = 0;
1358 lcd_clear_display();
1360 while(1)
1362 porta = PADR;
1363 portb = PBDR;
1364 portc = PCDR;
1366 switch(currval)
1368 case 0:
1369 snprintf(buf, 32, "PADR: %04x", porta);
1370 break;
1371 case 1:
1372 snprintf(buf, 32, "PBDR: %04x", portb);
1373 break;
1374 case 2:
1375 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1376 break;
1377 case 3:
1378 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1379 break;
1380 case 4:
1381 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1382 break;
1383 case 5:
1384 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1385 break;
1386 case 6:
1387 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1388 break;
1389 case 7:
1390 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1391 break;
1392 case 8:
1393 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1394 break;
1395 case 9:
1396 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1397 break;
1398 break;
1400 lcd_puts(0, 0, buf);
1402 battery_read_info(&adc_battery_voltage, NULL);
1403 snprintf(buf, 32, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1404 adc_battery_voltage % 1000);
1405 lcd_puts(0, 1, buf);
1406 lcd_update();
1408 button = get_action(CONTEXT_SETTINGS,HZ/5);
1410 switch(button)
1412 case ACTION_STD_CANCEL:
1413 return false;
1415 case ACTION_SETTINGS_DEC:
1416 currval--;
1417 if(currval < 0)
1418 currval = 9;
1419 break;
1421 case ACTION_SETTINGS_INC:
1422 currval++;
1423 if(currval > 9)
1424 currval = 0;
1425 break;
1428 return false;
1430 #endif /* !HAVE_LCD_BITMAP */
1431 #endif /* !SIMULATOR */
1433 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1434 static bool dbg_cpufreq(void)
1436 char buf[128];
1437 int line;
1438 int button;
1440 #ifdef HAVE_LCD_BITMAP
1441 lcd_setmargins(0, 0);
1442 lcd_setfont(FONT_SYSFIXED);
1443 #endif
1444 lcd_clear_display();
1446 while(1)
1448 line = 0;
1450 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1451 lcd_puts(0, line++, buf);
1453 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1454 lcd_puts(0, line++, buf);
1456 lcd_update();
1457 button = get_action(CONTEXT_STD,HZ/10);
1459 switch(button)
1461 case ACTION_STD_PREV:
1462 cpu_boost(true);
1463 break;
1465 case ACTION_STD_NEXT:
1466 cpu_boost(false);
1467 break;
1469 case ACTION_STD_OK:
1470 while (get_cpu_boost_counter() > 0)
1471 cpu_boost(false);
1472 set_cpu_frequency(CPUFREQ_DEFAULT);
1473 break;
1475 case ACTION_STD_CANCEL:
1476 return false;
1480 return false;
1482 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1484 #ifndef SIMULATOR
1485 #ifdef HAVE_LCD_BITMAP
1487 * view_battery() shows a automatically scaled graph of the battery voltage
1488 * over time. Usable for estimating battery life / charging rate.
1489 * The power_history array is updated in power_thread of powermgmt.c.
1492 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1493 #define BAT_YSPACE (LCD_HEIGHT - 20)
1495 static bool view_battery(void)
1497 int view = 0;
1498 int i, x, y;
1499 unsigned short maxv, minv;
1500 char buf[32];
1502 lcd_setmargins(0, 0);
1503 lcd_setfont(FONT_SYSFIXED);
1505 while(1)
1507 lcd_clear_display();
1508 switch (view) {
1509 case 0: /* voltage history graph */
1510 /* Find maximum and minimum voltage for scaling */
1511 minv = power_history[0];
1512 maxv = minv + 1;
1513 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1514 if (power_history[i] > maxv)
1515 maxv = power_history[i];
1516 if (power_history[i] < minv)
1517 minv = power_history[i];
1520 snprintf(buf, 30, "Battery %d.%03d", power_history[0] / 1000,
1521 power_history[0] % 1000);
1522 lcd_puts(0, 0, buf);
1523 snprintf(buf, 30, "scale %d.%03d-%d.%03dV",
1524 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1525 lcd_puts(0, 1, buf);
1527 x = 0;
1528 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1529 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1530 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1531 lcd_vline(x, LCD_HEIGHT-1, 20);
1532 lcd_set_drawmode(DRMODE_SOLID);
1533 lcd_vline(x, LCD_HEIGHT-1,
1534 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1535 x++;
1538 break;
1540 case 1: /* status: */
1541 lcd_puts(0, 0, "Power status:");
1543 battery_read_info(&y, NULL);
1544 snprintf(buf, 30, "Battery: %d.%03d V", y / 1000, y % 1000);
1545 lcd_puts(0, 1, buf);
1546 #ifdef ADC_EXT_POWER
1547 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1548 snprintf(buf, 30, "External: %d.%03d V", y / 1000, y % 1000);
1549 lcd_puts(0, 2, buf);
1550 #endif
1551 #if CONFIG_CHARGING
1552 #if CONFIG_CHARGING == CHARGING_CONTROL
1553 snprintf(buf, 30, "Chgr: %s %s",
1554 charger_inserted() ? "present" : "absent",
1555 charger_enabled ? "on" : "off");
1556 lcd_puts(0, 3, buf);
1557 snprintf(buf, 30, "short delta: %d", short_delta);
1558 lcd_puts(0, 5, buf);
1559 snprintf(buf, 30, "long delta: %d", long_delta);
1560 lcd_puts(0, 6, buf);
1561 lcd_puts(0, 7, power_message);
1562 snprintf(buf, 30, "USB Inserted: %s",
1563 usb_inserted() ? "yes" : "no");
1564 lcd_puts(0, 8, buf);
1565 #if defined IRIVER_H300_SERIES
1566 snprintf(buf, 30, "USB Charging Enabled: %s",
1567 usb_charging_enabled() ? "yes" : "no");
1568 lcd_puts(0, 9, buf);
1569 #endif
1570 #else /* CONFIG_CHARGING != CHARGING_CONTROL */
1571 #if defined IPOD_NANO || defined IPOD_VIDEO
1572 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1573 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1574 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1575 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1576 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1578 snprintf(buf, 30, "USB pwr: %s",
1579 usb_pwr ? "present" : "absent");
1580 lcd_puts(0, 3, buf);
1581 snprintf(buf, 30, "EXT pwr: %s",
1582 ext_pwr ? "present" : "absent");
1583 lcd_puts(0, 4, buf);
1584 snprintf(buf, 30, "Battery: %s",
1585 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1586 lcd_puts(0, 5, buf);
1587 snprintf(buf, 30, "Dock mode: %s",
1588 dock ? "enabled" : "disabled");
1589 lcd_puts(0, 6, buf);
1590 snprintf(buf, 30, "Headphone: %s",
1591 headphone ? "connected" : "disconnected");
1592 lcd_puts(0, 7, buf);
1593 #else
1594 snprintf(buf, 30, "Charger: %s",
1595 charger_inserted() ? "present" : "absent");
1596 lcd_puts(0, 3, buf);
1597 #endif
1598 #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1599 #endif /* CONFIG_CHARGING */
1600 break;
1602 case 2: /* voltage deltas: */
1603 lcd_puts(0, 0, "Voltage deltas:");
1605 for (i = 0; i <= 6; i++) {
1606 y = power_history[i] - power_history[i+1];
1607 snprintf(buf, 30, "-%d min: %s%d.%03d V", i,
1608 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1609 ((y < 0) ? y * -1 : y ) % 1000);
1610 lcd_puts(0, i+1, buf);
1612 break;
1614 case 3: /* remaining time estimation: */
1616 #if CONFIG_CHARGING == CHARGING_CONTROL
1617 snprintf(buf, 30, "charge_state: %d", charge_state);
1618 lcd_puts(0, 0, buf);
1620 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1621 lcd_puts(0, 1, buf);
1623 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1624 lcd_puts(0, 2, buf);
1626 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1627 lcd_puts(0, 3, buf);
1629 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1630 lcd_puts(0, 4, buf);
1631 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
1633 snprintf(buf, 30, "Last PwrHist: %d.%03dV",
1634 power_history[0] / 1000,
1635 power_history[0] % 1000);
1636 lcd_puts(0, 5, buf);
1638 snprintf(buf, 30, "battery level: %d%%", battery_level());
1639 lcd_puts(0, 6, buf);
1641 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1642 lcd_puts(0, 7, buf);
1643 break;
1646 lcd_update();
1648 switch(get_action(CONTEXT_SETTINGS,HZ/2))
1650 case ACTION_SETTINGS_DEC:
1651 if (view)
1652 view--;
1653 break;
1655 case ACTION_SETTINGS_INC:
1656 if (view < 3)
1657 view++;
1658 break;
1660 case ACTION_STD_CANCEL:
1661 return false;
1664 return false;
1667 #endif /* HAVE_LCD_BITMAP */
1668 #endif
1670 #ifndef SIMULATOR
1671 #if defined(HAVE_MMC) || defined(HAVE_HOTSWAP)
1672 #if defined(HAVE_MMC)
1673 #define CARDTYPE "MMC"
1674 #else
1675 #define CARDTYPE "microSD"
1676 #endif
1677 static int disk_callback(int btn, struct gui_synclist *lists)
1679 tCardInfo *card;
1680 int *cardnum = (int*)lists->gui_list[SCREEN_MAIN].data;
1681 unsigned char card_name[7];
1682 unsigned char pbuf[32];
1683 char *title = lists->gui_list[SCREEN_MAIN].title;
1684 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1685 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1686 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1687 static const unsigned char *nsec_units[] = { "ns", "�s", "ms" };
1688 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1689 "3.1-3.31", "4.0" };
1690 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1692 if (btn == ACTION_STD_OK)
1694 *cardnum ^= 0x1; /* change cards */
1697 simplelist_set_line_count(0);
1699 card = card_get_info(*cardnum);
1701 if (card->initialized > 0)
1703 card_name[6] = '\0';
1704 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1705 simplelist_addline(SIMPLELIST_ADD_LINE,
1706 "%s Rev %d.%d", card_name,
1707 (int) card_extract_bits(card->cid, 72, 4),
1708 (int) card_extract_bits(card->cid, 76, 4));
1709 simplelist_addline(SIMPLELIST_ADD_LINE,
1710 "Prod: %d/%d",
1711 (int) card_extract_bits(card->cid, 112, 4),
1712 (int) card_extract_bits(card->cid, 116, 4) + 1997);
1713 simplelist_addline(SIMPLELIST_ADD_LINE,
1714 "Ser#: 0x%08lx",
1715 card_extract_bits(card->cid, 80, 32));
1716 simplelist_addline(SIMPLELIST_ADD_LINE,
1717 "M=%02x, O=%04x",
1718 (int) card_extract_bits(card->cid, 0, 8),
1719 (int) card_extract_bits(card->cid, 8, 16));
1720 int temp = card_extract_bits(card->csd, 2, 4);
1721 simplelist_addline(SIMPLELIST_ADD_LINE,
1722 CARDTYPE " v%s", temp < 5 ?
1723 spec_vers[temp] : "?.?");
1724 simplelist_addline(SIMPLELIST_ADD_LINE,
1725 "Blocks: 0x%06lx", card->numblocks);
1726 simplelist_addline(SIMPLELIST_ADD_LINE,
1727 "Blksz.: %d P:%c%c", card->blocksize,
1728 card_extract_bits(card->csd, 48, 1) ? 'R' : '-',
1729 card_extract_bits(card->csd, 106, 1) ? 'W' : '-');
1730 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1731 kbit_units, false);
1732 simplelist_addline(SIMPLELIST_ADD_LINE,
1733 "Speed: %s", pbuf);
1734 output_dyn_value(pbuf, sizeof pbuf, card->tsac,
1735 nsec_units, false);
1736 simplelist_addline(SIMPLELIST_ADD_LINE,
1737 "Tsac: %s", pbuf);
1738 simplelist_addline(SIMPLELIST_ADD_LINE,
1739 "Nsac: %d clk", card->nsac);
1740 simplelist_addline(SIMPLELIST_ADD_LINE,
1741 "R2W: *%d", card->r2w_factor);
1742 simplelist_addline(SIMPLELIST_ADD_LINE,
1743 "IRmax: %d..%d mA",
1744 i_vmin[card_extract_bits(card->csd, 66, 3)],
1745 i_vmax[card_extract_bits(card->csd, 69, 3)]);
1746 simplelist_addline(SIMPLELIST_ADD_LINE,
1747 "IWmax: %d..%d mA",
1748 i_vmin[card_extract_bits(card->csd, 72, 3)],
1749 i_vmax[card_extract_bits(card->csd, 75, 3)]);
1751 else if (card->initialized == 0)
1753 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1755 #ifndef HAVE_MMC
1756 else /* card->initialized < 0 */
1758 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1760 #endif
1761 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1762 gui_synclist_set_title(lists, title, Icon_NOICON);
1763 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1764 gui_synclist_select_item(lists, 0);
1765 btn = ACTION_REDRAW;
1767 return btn;
1769 #else /* !defined(HAVE_MMC) && !defined(HAVE_HOTSWAP) */
1770 static int disk_callback(int btn, struct gui_synclist *lists)
1772 (void)lists;
1773 int i;
1774 char buf[128];
1775 unsigned short* identify_info = ata_get_identify();
1776 bool timing_info_present = false;
1777 (void)btn;
1779 simplelist_set_line_count(0);
1781 for (i=0; i < 20; i++)
1782 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1783 buf[40]=0;
1784 /* kill trailing space */
1785 for (i=39; i && buf[i]==' '; i--)
1786 buf[i] = 0;
1787 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1788 for (i=0; i < 4; i++)
1789 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1790 buf[8]=0;
1791 simplelist_addline(SIMPLELIST_ADD_LINE,
1792 "Firmware: %s", buf);
1793 snprintf(buf, sizeof buf, "%ld MB",
1794 ((unsigned long)identify_info[61] << 16 |
1795 (unsigned long)identify_info[60]) / 2048 );
1796 simplelist_addline(SIMPLELIST_ADD_LINE,
1797 "Size: %s", buf);
1798 unsigned long free;
1799 fat_size( IF_MV2(0,) NULL, &free );
1800 simplelist_addline(SIMPLELIST_ADD_LINE,
1801 "Free: %ld MB", free / 1024);
1802 simplelist_addline(SIMPLELIST_ADD_LINE,
1803 "Spinup time: %d ms", ata_spinup_time * (1000/HZ));
1804 i = identify_info[83] & (1<<3);
1805 simplelist_addline(SIMPLELIST_ADD_LINE,
1806 "Power mgmt: %s", i ? "enabled" : "unsupported");
1807 i = identify_info[83] & (1<<9);
1808 simplelist_addline(SIMPLELIST_ADD_LINE,
1809 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1810 i = identify_info[82] & (1<<6);
1811 simplelist_addline(SIMPLELIST_ADD_LINE,
1812 "Read-ahead: %s", i ? "enabled" : "unsupported");
1813 timing_info_present = identify_info[53] & (1<<1);
1814 if(timing_info_present) {
1815 char pio3[2], pio4[2];pio3[1] = 0;
1816 pio4[1] = 0;
1817 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1818 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1819 simplelist_addline(SIMPLELIST_ADD_LINE,
1820 "PIO modes: 0 1 2 %s %s", pio3, pio4);
1822 else {
1823 simplelist_addline(SIMPLELIST_ADD_LINE,
1824 "No PIO mode info");
1826 timing_info_present = identify_info[53] & (1<<1);
1827 if(timing_info_present) {
1828 simplelist_addline(SIMPLELIST_ADD_LINE,
1829 "Cycle times %dns/%dns",
1830 identify_info[67],
1831 identify_info[68] );
1832 } else {
1833 simplelist_addline(SIMPLELIST_ADD_LINE,
1834 "No timing info");
1836 timing_info_present = identify_info[53] & (1<<1);
1837 if(timing_info_present) {
1838 i = identify_info[49] & (1<<11);
1839 simplelist_addline(SIMPLELIST_ADD_LINE,
1840 "IORDY support: %s", i ? "yes" : "no");
1841 i = identify_info[49] & (1<<10);
1842 simplelist_addline(SIMPLELIST_ADD_LINE,
1843 "IORDY disable: %s", i ? "yes" : "no");
1844 } else {
1845 simplelist_addline(SIMPLELIST_ADD_LINE,
1846 "No timing info");
1848 simplelist_addline(SIMPLELIST_ADD_LINE,
1849 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1850 return btn;
1852 #endif /* !defined(HAVE_MMC) && !defined(HAVE_HOTSWAP) */
1853 static bool dbg_disk_info(void)
1855 struct simplelist_info info;
1856 simplelist_info_init(&info, "Disk Info", 1, NULL);
1857 #if defined(HAVE_MMC) || defined(HAVE_HOTSWAP)
1858 char title[16];
1859 int card = 0;
1860 info.callback_data = (void*)&card;
1861 info.title = title;
1862 #endif
1863 info.action_callback = disk_callback;
1864 info.hide_selection = true;
1865 return simplelist_show_list(&info);
1867 #endif /* !SIMULATOR */
1869 #ifdef HAVE_DIRCACHE
1870 static int dircache_callback(int btn, struct gui_synclist *lists)
1872 (void)btn; (void)lists;
1873 simplelist_set_line_count(0);
1874 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
1875 dircache_is_enabled() ? "Yes" : "No");
1876 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
1877 dircache_get_cache_size());
1878 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
1879 global_status.dircache_size);
1880 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
1881 DIRCACHE_LIMIT);
1882 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
1883 dircache_get_reserve_used(), DIRCACHE_RESERVE);
1884 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
1885 dircache_get_build_ticks() / HZ);
1886 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
1887 dircache_get_entry_count());
1888 return btn;
1891 static bool dbg_dircache_info(void)
1893 struct simplelist_info info;
1894 simplelist_info_init(&info, "Dircache Info", 7, NULL);
1895 info.action_callback = dircache_callback;
1896 info.hide_selection = true;
1897 return simplelist_show_list(&info);
1900 #endif /* HAVE_DIRCACHE */
1902 #ifdef HAVE_TAGCACHE
1903 static int database_callback(int btn, struct gui_synclist *lists)
1905 (void)lists;
1906 struct tagcache_stat *stat = tagcache_get_stat();
1907 static bool synced = false;
1909 simplelist_set_line_count(0);
1911 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
1912 stat->initialized ? "Yes" : "No");
1913 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
1914 stat->ready ? "Yes" : "No");
1915 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
1916 stat->ramcache ? "Yes" : "No");
1917 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
1918 stat->ramcache_used, stat->ramcache_allocated);
1919 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
1920 stat->progress, stat->processed_entries);
1921 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
1922 stat->curentry ? stat->curentry : "---");
1923 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
1924 stat->commit_step);
1925 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
1926 stat->commit_delayed ? "Yes" : "No");
1929 if (synced)
1931 synced = false;
1932 tagcache_screensync_event();
1935 if (!btn && stat->curentry)
1937 synced = true;
1938 return ACTION_REDRAW;
1941 if (btn == ACTION_STD_CANCEL)
1942 tagcache_screensync_enable(false);
1944 return btn;
1946 static bool dbg_tagcache_info(void)
1948 struct simplelist_info info;
1949 simplelist_info_init(&info, "Database Info", 8, NULL);
1950 info.action_callback = database_callback;
1951 info.hide_selection = true;
1952 info.timeout = TIMEOUT_NOBLOCK;
1953 tagcache_screensync_enable(true);
1954 return simplelist_show_list(&info);
1956 #endif
1958 #if CONFIG_CPU == SH7034
1959 static bool dbg_save_roms(void)
1961 int fd;
1962 int oldmode = system_memory_guard(MEMGUARD_NONE);
1964 fd = creat("/internal_rom_0000-FFFF.bin");
1965 if(fd >= 0)
1967 write(fd, (void *)0, 0x10000);
1968 close(fd);
1971 fd = creat("/internal_rom_2000000-203FFFF.bin");
1972 if(fd >= 0)
1974 write(fd, (void *)0x2000000, 0x40000);
1975 close(fd);
1978 system_memory_guard(oldmode);
1979 return false;
1981 #elif defined CPU_COLDFIRE
1982 static bool dbg_save_roms(void)
1984 int fd;
1985 int oldmode = system_memory_guard(MEMGUARD_NONE);
1987 #if defined(IRIVER_H100_SERIES)
1988 fd = creat("/internal_rom_000000-1FFFFF.bin");
1989 #elif defined(IRIVER_H300_SERIES)
1990 fd = creat("/internal_rom_000000-3FFFFF.bin");
1991 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5)
1992 fd = creat("/internal_rom_000000-3FFFFF.bin");
1993 #endif
1994 if(fd >= 0)
1996 write(fd, (void *)0, FLASH_SIZE);
1997 close(fd);
1999 system_memory_guard(oldmode);
2001 #ifdef HAVE_EEPROM
2002 fd = creat("/internal_eeprom.bin");
2003 if (fd >= 0)
2005 int old_irq_level;
2006 char buf[EEPROM_SIZE];
2007 int err;
2009 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
2011 err = eeprom_24cxx_read(0, buf, sizeof buf);
2012 if (err)
2013 gui_syncsplash(HZ*3, "Eeprom read failure (%d)",err);
2014 else
2016 write(fd, buf, sizeof buf);
2019 set_irq_level(old_irq_level);
2021 close(fd);
2023 #endif
2025 return false;
2027 #elif defined(CPU_PP) && !(defined(SANSA_E200) || defined(SANSA_C200))
2028 static bool dbg_save_roms(void)
2030 int fd;
2032 fd = creat("/internal_rom_000000-0FFFFF.bin");
2033 if(fd >= 0)
2035 write(fd, (void *)0x20000000, FLASH_SIZE);
2036 close(fd);
2039 return false;
2041 #endif /* CPU */
2043 #ifndef SIMULATOR
2044 #if CONFIG_TUNER
2045 static int radio_callback(int btn, struct gui_synclist *lists)
2047 (void)lists;
2048 if (btn == ACTION_STD_CANCEL)
2049 return btn;
2050 simplelist_set_line_count(1);
2052 #if (CONFIG_TUNER & LV24020LP)
2053 simplelist_addline(SIMPLELIST_ADD_LINE,
2054 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2055 simplelist_addline(SIMPLELIST_ADD_LINE,
2056 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2057 simplelist_addline(SIMPLELIST_ADD_LINE,
2058 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2059 simplelist_addline(SIMPLELIST_ADD_LINE,
2060 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2061 simplelist_addline(SIMPLELIST_ADD_LINE,
2062 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2063 simplelist_addline(SIMPLELIST_ADD_LINE,
2064 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2065 simplelist_addline(SIMPLELIST_ADD_LINE,
2066 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2067 #endif
2068 #if (CONFIG_TUNER & S1A0903X01)
2069 simplelist_addline(SIMPLELIST_ADD_LINE,
2070 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2071 /* This one doesn't return dynamic data atm */
2072 #endif
2073 #if (CONFIG_TUNER & TEA5767)
2074 struct tea5767_dbg_info nfo;
2075 tea5767_dbg_info(&nfo);
2076 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2077 simplelist_addline(SIMPLELIST_ADD_LINE,
2078 " Read: %02X %02X %02X %02X %02X",
2079 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2080 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2081 (unsigned)nfo.read_regs[4]);
2082 simplelist_addline(SIMPLELIST_ADD_LINE,
2083 " Write: %02X %02X %02X %02X %02X",
2084 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2085 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2086 (unsigned)nfo.write_regs[4]);
2087 #endif
2088 return ACTION_REDRAW;
2090 static bool dbg_fm_radio(void)
2092 struct simplelist_info info;
2093 simplelist_info_init(&info, "FM Radio", 1, NULL);
2094 simplelist_set_line_count(0);
2095 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2096 radio_hardware_present() ? "yes" : "no");
2098 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2099 info.hide_selection = true;
2100 return simplelist_show_list(&info);
2102 #endif /* CONFIG_TUNER */
2103 #endif /* !SIMULATOR */
2105 #ifdef HAVE_LCD_BITMAP
2106 extern bool do_screendump_instead_of_usb;
2108 static bool dbg_screendump(void)
2110 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2111 gui_syncsplash(HZ, "Screendump %s",
2112 do_screendump_instead_of_usb?"enabled":"disabled");
2113 return false;
2115 #endif /* HAVE_LCD_BITMAP */
2117 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2118 static bool dbg_set_memory_guard(void)
2120 static const struct opt_items names[MAXMEMGUARD] = {
2121 { "None", -1 },
2122 { "Flash ROM writes", -1 },
2123 { "Zero area (all)", -1 }
2125 int mode = system_memory_guard(MEMGUARD_KEEP);
2127 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2128 system_memory_guard(mode);
2130 return false;
2132 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2134 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2136 extern volatile bool lcd_poweroff;
2138 static bool dbg_lcd_power_off(void)
2140 lcd_setmargins(0, 0);
2142 while(1)
2144 int button;
2146 lcd_clear_display();
2147 lcd_puts(0, 0, "LCD Power Off");
2148 if(lcd_poweroff)
2149 lcd_puts(1, 1, "Yes");
2150 else
2151 lcd_puts(1, 1, "No");
2153 lcd_update();
2155 button = get_action(CONTEXT_STD,HZ/5);
2156 switch(button)
2158 case ACTION_STD_PREV:
2159 case ACTION_STD_NEXT:
2160 lcd_poweroff = !lcd_poweroff;
2161 break;
2162 case ACTION_STD_OK:
2163 case ACTION_STD_CANCEL:
2164 return false;
2165 default:
2166 sleep(HZ/10);
2167 break;
2170 return false;
2172 #endif
2174 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2175 static bool dbg_write_eeprom(void)
2177 int fd;
2178 int rc;
2179 int old_irq_level;
2180 char buf[EEPROM_SIZE];
2181 int err;
2183 fd = open("/internal_eeprom.bin", O_RDONLY);
2185 if (fd >= 0)
2187 rc = read(fd, buf, EEPROM_SIZE);
2189 if(rc == EEPROM_SIZE)
2191 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
2193 err = eeprom_24cxx_write(0, buf, sizeof buf);
2194 if (err)
2195 gui_syncsplash(HZ*3, "Eeprom write failure (%d)",err);
2196 else
2197 gui_syncsplash(HZ*3, "Eeprom written successfully");
2199 set_irq_level(old_irq_level);
2201 else
2203 gui_syncsplash(HZ*3, "File read error (%d)",rc);
2205 close(fd);
2207 else
2209 gui_syncsplash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2212 return false;
2214 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2215 #ifdef CPU_BOOST_LOGGING
2216 static bool cpu_boost_log(void)
2218 int i = 0,j=0;
2219 int count = cpu_boost_log_getcount();
2220 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2221 char *str;
2222 bool done;
2223 lcd_setmargins(0, 0);
2224 lcd_setfont(FONT_SYSFIXED);
2225 str = cpu_boost_log_getlog_first();
2226 while (i < count)
2228 lcd_clear_display();
2229 for(j=0; j<lines; j++,i++)
2231 if (!str)
2232 str = cpu_boost_log_getlog_next();
2233 if (str)
2235 lcd_puts(0, j,str);
2237 str = NULL;
2239 lcd_update();
2240 done = false;
2241 while (!done)
2243 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2245 case ACTION_STD_OK:
2246 case ACTION_STD_PREV:
2247 case ACTION_STD_NEXT:
2248 done = true;
2249 break;
2250 case ACTION_STD_CANCEL:
2251 i = count;
2252 done = true;
2253 break;
2257 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2258 lcd_setfont(FONT_UI);
2259 return false;
2261 #endif
2265 /****** The menu *********/
2266 struct the_menu_item {
2267 unsigned char *desc; /* string or ID */
2268 bool (*function) (void); /* return true if USB was connected */
2270 static const struct the_menu_item menuitems[] = {
2271 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2272 { "LCD Power Off", dbg_lcd_power_off },
2273 #endif
2274 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2275 (defined(CPU_PP) && !(defined(SANSA_E200) || defined(SANSA_C200)))
2276 { "Dump ROM contents", dbg_save_roms },
2277 #endif
2278 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) || CONFIG_CPU == S3C2440
2279 { "View I/O ports", dbg_ports },
2280 #endif
2281 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2282 { "CPU frequency", dbg_cpufreq },
2283 #endif
2284 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2285 { "S/PDIF analyzer", dbg_spdif },
2286 #endif
2287 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2288 { "Catch mem accesses", dbg_set_memory_guard },
2289 #endif
2290 { "View OS stacks", dbg_os },
2291 #ifdef HAVE_LCD_BITMAP
2292 #ifndef SIMULATOR
2293 { "View battery", view_battery },
2294 #endif
2295 { "Screendump", dbg_screendump },
2296 #endif
2297 #ifndef SIMULATOR
2298 { "View HW info", dbg_hw_info },
2299 #endif
2300 #ifndef SIMULATOR
2301 { "View partitions", dbg_partitions },
2302 #endif
2303 #ifndef SIMULATOR
2304 { "View disk info", dbg_disk_info },
2305 #endif
2306 #ifdef HAVE_DIRCACHE
2307 { "View dircache info", dbg_dircache_info },
2308 #endif
2309 #ifdef HAVE_TAGCACHE
2310 { "View database info", dbg_tagcache_info },
2311 #endif
2312 #ifdef HAVE_LCD_BITMAP
2313 #if CONFIG_CODEC == SWCODEC || !defined(SIMULATOR)
2314 { "View audio thread", dbg_audio_thread },
2315 { "View buffering thread", dbg_buffering_thread },
2316 #endif
2317 #ifdef PM_DEBUG
2318 { "pm histogram", peak_meter_histogram},
2319 #endif /* PM_DEBUG */
2320 #endif /* HAVE_LCD_BITMAP */
2321 #ifndef SIMULATOR
2322 #if CONFIG_TUNER
2323 { "FM Radio", dbg_fm_radio },
2324 #endif
2325 #endif
2326 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2327 { "Write back EEPROM", dbg_write_eeprom },
2328 #endif
2329 #ifdef ROCKBOX_HAS_LOGF
2330 {"logf", logfdisplay },
2331 {"logfdump", logfdump },
2332 #endif
2333 #ifdef CPU_BOOST_LOGGING
2334 {"cpu_boost log",cpu_boost_log},
2335 #endif
2337 static int menu_action_callback(int btn, struct gui_synclist *lists)
2339 if (btn == ACTION_STD_OK)
2341 menuitems[gui_synclist_get_sel_pos(lists)].function();
2342 btn = ACTION_REDRAW;
2344 return btn;
2346 static char* dbg_menu_getname(int item, void * data, char *buffer)
2348 (void)data; (void)buffer;
2349 return menuitems[item].desc;
2351 bool debug_menu(void)
2353 struct simplelist_info info;
2355 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2356 info.action_callback = menu_action_callback;
2357 info.get_name = dbg_menu_getname;
2359 return simplelist_show_list(&info);