convert the tagcache, database and radio debug screens to nice lists
[Rockbox.git] / apps / debug_menu.c
blobf7b022dbb35536558a64ebdc822b75bf717544cc
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 "pcm_playback.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 #if defined(HAVE_DIRCACHE) || defined(HAVE_TAGCACHE) || CONFIG_TUNER
92 #define MAX_DEBUG_MESSAGES 8
93 #define DEBUG_MSG_LEN 32
94 char debug_list_messages[MAX_DEBUG_MESSAGES][DEBUG_MSG_LEN];
95 static char* dbg_listmessage_getname(int item, void * data, char *buffer)
97 (void)buffer; (void)data;
98 return debug_list_messages[item];
100 #endif
102 static char* dbg_menu_getname(int item, void * data, char *buffer);
103 static bool dbg_list(char *title, int count, int selection_size,
104 int (*action_callback)(int btn, struct gui_synclist *lists),
105 char* (*dbg_getname)(int item, void * data, char *buffer))
107 struct gui_synclist lists;
108 int action;
110 gui_synclist_init(&lists, dbg_getname, NULL, false, selection_size);
111 gui_synclist_set_title(&lists, title, NOICON);
112 gui_synclist_set_icon_callback(&lists, NULL);
113 gui_synclist_set_nb_items(&lists, count*selection_size);
114 if (dbg_getname != dbg_menu_getname)
115 gui_synclist_hide_selection_marker(&lists, true);
116 action_signalscreenchange();
117 gui_synclist_draw(&lists);
118 while(1)
120 gui_syncstatusbar_draw(&statusbars, true);
121 action = get_action(CONTEXT_STD, HZ/5);
122 if (gui_synclist_do_button(&lists, action, LIST_WRAP_UNLESS_HELD))
123 continue;
124 if (action_callback)
125 action = action_callback(action, &lists);
126 if (action == ACTION_STD_CANCEL)
127 break;
128 else if(default_event_handler(action) == SYS_USB_CONNECTED)
129 return true;
131 action_signalscreenchange();
132 return false;
134 /*---------------------------------------------------*/
135 /* SPECIAL DEBUG STUFF */
136 /*---------------------------------------------------*/
137 extern struct thread_entry threads[MAXTHREADS];
140 #ifndef SIMULATOR
141 static char thread_status_char(int status)
143 switch (status)
145 case STATE_RUNNING : return 'R';
146 case STATE_BLOCKED : return 'B';
147 case STATE_SLEEPING : return 'S';
148 case STATE_BLOCKED_W_TMO: return 'T';
151 return '?';
153 #if NUM_CORES > 1
154 #define IF_COP2(...) __VA_ARGS__
155 #else
156 #define IF_COP2(...)
157 #endif
158 static char* threads_getname(int selected_item, void * data, char *buffer)
160 (void)data;
161 struct thread_entry *thread = NULL;
162 int status, usage;
163 thread = &threads[selected_item];
165 if (thread->name == NULL)
167 snprintf(buffer, MAX_PATH, "%2d: ---", selected_item);
168 return buffer;
171 usage = thread_stack_usage(thread);
172 status = thread_get_status(thread);
173 #ifdef HAVE_PRIORITY_SCHEDULING
174 snprintf(buffer, MAX_PATH, "%2d: " IF_COP2("(%d) ") "%c%c %d %2d%% %s",
175 selected_item,
176 IF_COP2(thread->core,)
177 (status == STATE_RUNNING) ? '*' : ' ',
178 thread_status_char(status),
179 thread->priority,
180 usage, thread->name);
181 #else
182 snprintf(buffer, MAX_PATH, "%2d: " IF_COP2("(%d) ") "%c%c %2d%% %s",
183 selected_item,
184 IF_COP2(thread->core,)
185 (status == STATE_RUNNING) ? '*' : ' ',
186 thread_status_char(status),
187 usage, thread->name);
188 #endif
189 return buffer;
191 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
193 #ifdef ROCKBOX_HAS_LOGF
194 if (action == ACTION_STD_OK)
196 struct thread_entry *thread = &threads[gui_synclist_get_sel_pos(lists)];
197 if (thread->name != NULL)
198 remove_thread(thread);
200 #endif
201 gui_synclist_draw(lists);
202 return action;
204 /* Test code!!! */
205 static bool dbg_os(void)
207 return dbg_list(IF_COP2("Core and ") "Stack usage:", MAXTHREADS, 1,
208 dbg_threads_action_callback, threads_getname);
210 #endif /* !SIMULATOR */
212 #ifdef HAVE_LCD_BITMAP
213 #if CONFIG_CODEC != SWCODEC
214 #ifndef SIMULATOR
215 static bool dbg_audio_thread(void)
217 char buf[32];
218 struct audio_debug d;
220 lcd_setmargins(0, 0);
221 lcd_setfont(FONT_SYSFIXED);
223 while(1)
225 if (action_userabort(HZ/5))
226 return false;
228 audio_get_debugdata(&d);
230 lcd_clear_display();
232 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
233 lcd_puts(0, 0, buf);
234 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
235 lcd_puts(0, 1, buf);
236 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
237 lcd_puts(0, 2, buf);
238 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
239 lcd_puts(0, 3, buf);
240 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
241 lcd_puts(0, 4, buf);
242 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
243 lcd_puts(0, 5, buf);
245 /* Playable space left */
246 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
247 d.playable_space, HORIZONTAL);
249 /* Show the watermark limit */
250 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
251 d.low_watermark_level, HORIZONTAL);
253 snprintf(buf, sizeof(buf), "wm: %x - %x",
254 d.low_watermark_level, d.lowest_watermark_level);
255 lcd_puts(0, 7, buf);
257 lcd_update();
259 return false;
261 #endif /* !SIMULATOR */
262 #else /* CONFIG_CODEC == SWCODEC */
263 extern size_t filebuflen;
264 /* This is a size_t, but call it a long so it puts a - when it's bad. */
266 static unsigned int ticks, boost_ticks;
268 static void dbg_audio_task(void)
270 #ifndef SIMULATOR
271 if(FREQ > CPUFREQ_NORMAL)
272 boost_ticks++;
273 #endif
275 ticks++;
278 static bool dbg_audio_thread(void)
280 char buf[32];
281 int button;
282 int line;
283 bool done = false;
284 size_t bufused;
285 size_t bufsize = pcmbuf_get_bufsize();
286 int pcmbufdescs = pcmbuf_descs();
288 ticks = boost_ticks = 0;
290 tick_add_task(dbg_audio_task);
292 lcd_setmargins(0, 0);
293 lcd_setfont(FONT_SYSFIXED);
294 while(!done)
296 button = get_action(CONTEXT_STD,HZ/5);
297 switch(button)
299 case ACTION_STD_NEXT:
300 audio_next();
301 break;
302 case ACTION_STD_PREV:
303 audio_prev();
304 break;
305 case ACTION_STD_CANCEL:
306 done = true;
307 break;
309 action_signalscreenchange();
310 line = 0;
312 lcd_clear_display();
314 bufused = bufsize - pcmbuf_free();
316 snprintf(buf, sizeof(buf), "pcm: %7ld/%7ld", (long) bufused, (long) bufsize);
317 lcd_puts(0, line++, buf);
319 /* Playable space left */
320 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6, bufsize, 0, bufused, HORIZONTAL);
321 line++;
323 snprintf(buf, sizeof(buf), "codec: %8ld/%8ld", audio_filebufused(), (long) filebuflen);
324 lcd_puts(0, line++, buf);
326 /* Playable space left */
327 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6, filebuflen, 0,
328 audio_filebufused(), HORIZONTAL);
329 line++;
331 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
332 lcd_puts(0, line++, buf);
334 #ifndef SIMULATOR
335 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
336 (int)((FREQ + 500000) / 1000000));
337 lcd_puts(0, line++, buf);
338 #endif
340 if (ticks > 0)
342 snprintf(buf, sizeof(buf), "boost ratio: %3d%%",
343 boost_ticks * 100 / ticks);
344 lcd_puts(0, line++, buf);
347 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
348 pcmbuf_used_descs(), pcmbufdescs);
349 lcd_puts(0, line++, buf);
351 lcd_update();
354 tick_remove_task(dbg_audio_task);
356 return false;
358 #endif /* CONFIG_CODEC */
359 #endif /* HAVE_LCD_BITMAP */
362 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
363 /* Tool function to read the flash manufacturer and type, if available.
364 Only chips which could be reprogrammed in system will return values.
365 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
366 /* In IRAM to avoid problems when running directly from Flash */
367 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
368 unsigned addr1, unsigned addr2)
369 ICODE_ATTR __attribute__((noinline));
370 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
371 unsigned addr1, unsigned addr2)
374 unsigned not_manu, not_id; /* read values before switching to ID mode */
375 unsigned manu, id; /* read values when in ID mode */
377 #if CONFIG_CPU == SH7034
378 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
379 #elif defined(CPU_COLDFIRE)
380 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
381 #endif
382 int old_level; /* saved interrupt level */
384 not_manu = flash[0]; /* read the normal content */
385 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
387 /* disable interrupts, prevent any stray flash access */
388 old_level = set_irq_level(HIGHEST_IRQ_LEVEL);
390 flash[addr1] = 0xAA; /* enter command mode */
391 flash[addr2] = 0x55;
392 flash[addr1] = 0x90; /* ID command */
393 /* Atmel wants 20ms pause here */
394 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
396 manu = flash[0]; /* read the IDs */
397 id = flash[1];
399 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
400 /* Atmel wants 20ms pause here */
401 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
403 set_irq_level(old_level); /* enable interrupts again */
405 /* I assume success if the obtained values are different from
406 the normal flash content. This is not perfectly bulletproof, they
407 could theoretically be the same by chance, causing us to fail. */
408 if (not_manu != manu || not_id != id) /* a value has changed */
410 *p_manufacturer = manu; /* return the results */
411 *p_device = id;
412 return true; /* success */
414 return false; /* fail */
416 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
418 #ifndef SIMULATOR
419 #ifdef CPU_PP
420 static int perfcheck(void)
422 int result;
424 asm (
425 "mrs r2, CPSR \n"
426 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
427 "msr CPSR_c, r0 \n"
428 "mov %[res], #0 \n"
429 "ldr r0, [%[timr]] \n"
430 "add r0, r0, %[tmo] \n"
431 "1: \n"
432 "add %[res], %[res], #1 \n"
433 "ldr r1, [%[timr]] \n"
434 "cmp r1, r0 \n"
435 "bmi 1b \n"
436 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
438 [res]"=&r"(result)
440 [timr]"r"(&USEC_TIMER),
441 [tmo]"r"(
442 #if CONFIG_CPU == PP5002
443 16000
444 #else /* PP5020/5022/5024 */
445 10226
446 #endif
449 "r0", "r1", "r2"
451 return result;
453 #endif
455 #ifdef HAVE_LCD_BITMAP
456 static bool dbg_hw_info(void)
458 #if CONFIG_CPU == SH7034
459 char buf[32];
460 int bitmask = HW_MASK;
461 int rom_version = ROM_VERSION;
462 unsigned manu, id; /* flash IDs */
463 bool got_id; /* flag if we managed to get the flash IDs */
464 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
465 bool has_bootrom; /* flag for boot ROM present */
466 int oldmode; /* saved memory guard mode */
468 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
470 /* get flash ROM type */
471 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
472 if (!got_id)
473 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
475 /* check if the boot ROM area is a flash mirror */
476 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
477 if (has_bootrom) /* if ROM and Flash different */
479 /* calculate CRC16 checksum of boot ROM */
480 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
483 system_memory_guard(oldmode); /* re-enable memory guard */
485 lcd_setmargins(0, 0);
486 lcd_setfont(FONT_SYSFIXED);
487 lcd_clear_display();
489 lcd_puts(0, 0, "[Hardware info]");
491 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
492 lcd_puts(0, 1, buf);
494 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
495 lcd_puts(0, 2, buf);
497 if (got_id)
498 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
499 else
500 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
501 lcd_puts(0, 3, buf);
503 if (has_bootrom)
505 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
506 snprintf(buf, 32, "Boot ROM: V1");
507 else
508 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
510 else
512 snprintf(buf, 32, "Boot ROM: none");
514 lcd_puts(0, 4, buf);
516 lcd_update();
518 while(1)
520 if (action_userabort(TIMEOUT_BLOCK))
521 return false;
523 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
524 char buf[32];
525 unsigned manu, id; /* flash IDs */
526 int got_id; /* flag if we managed to get the flash IDs */
527 int oldmode; /* saved memory guard mode */
528 int line = 0;
530 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
532 /* get flash ROM type */
533 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
534 if (!got_id)
535 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
537 system_memory_guard(oldmode); /* re-enable memory guard */
539 lcd_setmargins(0, 0);
540 lcd_setfont(FONT_SYSFIXED);
541 lcd_clear_display();
543 lcd_puts(0, line++, "[Hardware info]");
545 if (got_id)
546 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
547 else
548 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
549 lcd_puts(0, line++, buf);
551 #ifdef IAUDIO_X5
553 struct ds2411_id id;
555 lcd_puts(0, ++line, "Serial Number:");
557 got_id = ds2411_read_id(&id);
559 if (got_id == DS2411_OK)
561 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
562 lcd_puts(0, ++line, buf);
563 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
564 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
565 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
566 lcd_puts(0, ++line, buf);
567 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
569 else
571 snprintf(buf, 32, "READ ERR=%d", got_id);
574 lcd_puts(0, ++line, buf);
576 #endif
578 lcd_update();
580 while(1)
582 if (action_userabort(TIMEOUT_BLOCK))
583 return false;
585 #elif defined(CPU_PP502x)
586 char buf[32];
587 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
588 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
589 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
590 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
592 lcd_setmargins(0, 0);
593 lcd_setfont(FONT_SYSFIXED);
594 lcd_clear_display();
596 lcd_puts(0, 0, "[Hardware info]");
598 snprintf(buf, sizeof(buf), "HW rev: 0x%08x", ipod_hw_rev);
599 lcd_puts(0, 1, buf);
601 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
602 lcd_puts(0, 2, buf);
604 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
605 lcd_puts(0, 3, buf);
607 lcd_update();
609 while(1)
611 if (action_userabort(TIMEOUT_BLOCK))
612 return false;
614 #endif /* CONFIG_CPU */
615 return false;
617 #else /* !HAVE_LCD_BITMAP */
618 static bool dbg_hw_info(void)
620 char buf[32];
621 int button;
622 int currval = 0;
623 int rom_version = ROM_VERSION;
624 unsigned manu, id; /* flash IDs */
625 bool got_id; /* flag if we managed to get the flash IDs */
626 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
627 bool has_bootrom; /* flag for boot ROM present */
628 int oldmode; /* saved memory guard mode */
630 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
632 /* get flash ROM type */
633 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
634 if (!got_id)
635 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
637 /* check if the boot ROM area is a flash mirror */
638 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
639 if (has_bootrom) /* if ROM and Flash different */
641 /* calculate CRC16 checksum of boot ROM */
642 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
645 system_memory_guard(oldmode); /* re-enable memory guard */
647 lcd_clear_display();
649 lcd_puts(0, 0, "[HW Info]");
650 while(1)
652 switch(currval)
654 case 0:
655 snprintf(buf, 32, "ROM: %d.%02d",
656 rom_version/100, rom_version%100);
657 break;
658 case 1:
659 if (got_id)
660 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
661 else
662 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
663 break;
664 case 2:
665 if (has_bootrom)
667 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
668 snprintf(buf, 32, "BootROM: V1");
669 else if (rom_crc == 0x358099E8)
670 snprintf(buf, 32, "BootROM: V2");
671 /* alternative boot ROM found in one single player so far */
672 else
673 snprintf(buf, 32, "R: %08x", rom_crc);
675 else
676 snprintf(buf, 32, "BootROM: no");
679 lcd_puts(0, 1, buf);
680 lcd_update();
682 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
684 switch(button)
686 case ACTION_STD_CANCEL:
687 action_signalscreenchange();
688 return false;
690 case ACTION_SETTINGS_DEC:
691 currval--;
692 if(currval < 0)
693 currval = 2;
694 break;
696 case ACTION_SETTINGS_INC:
697 currval++;
698 if(currval > 2)
699 currval = 0;
700 break;
703 return false;
705 #endif /* !HAVE_LCD_BITMAP */
706 #endif /* !SIMULATOR */
708 #ifndef SIMULATOR
709 static char* dbg_partitions_getname(int selected_item, void * data, char *buffer)
711 (void)data;
712 int partition = selected_item/2;
713 struct partinfo* p = disk_partinfo(partition);
714 if (selected_item%2)
716 snprintf(buffer, MAX_PATH, " T:%x %ld MB", p->type, p->size / 2048);
718 else
720 snprintf(buffer, MAX_PATH, "P%d: S:%lx", partition, p->start);
722 return buffer;
725 bool dbg_partitions(void)
727 return dbg_list("Partition Info", 4, 2,
728 NULL, dbg_partitions_getname);
730 #endif
732 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
733 static bool dbg_spdif(void)
735 char buf[128];
736 int line;
737 unsigned int control;
738 int x;
739 char *s;
740 int category;
741 int generation;
742 unsigned int interruptstat;
743 bool valnogood, symbolerr, parityerr;
744 bool done = false;
745 bool spdif_src_on;
746 int spdif_source = spdif_get_output_source(&spdif_src_on);
747 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
749 lcd_setmargins(0, 0);
750 lcd_clear_display();
751 lcd_setfont(FONT_SYSFIXED);
753 #ifdef HAVE_SPDIF_POWER
754 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
755 #endif
757 while (!done)
759 line = 0;
761 control = EBU1RCVCCHANNEL1;
762 interruptstat = INTERRUPTSTAT;
763 INTERRUPTCLEAR = 0x03c00000;
765 valnogood = (interruptstat & 0x01000000)?true:false;
766 symbolerr = (interruptstat & 0x00800000)?true:false;
767 parityerr = (interruptstat & 0x00400000)?true:false;
769 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
770 valnogood?"--":"OK",
771 symbolerr?"--":"OK",
772 parityerr?"--":"OK");
773 lcd_puts(0, line++, buf);
775 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
776 lcd_puts(0, line++, buf);
778 line++;
780 x = control >> 31;
781 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
782 x, x?"Professional":"Consumer");
783 lcd_puts(0, line++, buf);
785 x = (control >> 30) & 1;
786 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
787 x, x?"Non-PCM":"PCM");
788 lcd_puts(0, line++, buf);
790 x = (control >> 29) & 1;
791 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
792 x, x?"Permitted":"Inhibited");
793 lcd_puts(0, line++, buf);
795 x = (control >> 27) & 7;
796 switch(x)
798 case 0:
799 s = "None";
800 break;
801 case 1:
802 s = "50/15us";
803 break;
804 default:
805 s = "Reserved";
806 break;
808 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
809 lcd_puts(0, line++, buf);
811 x = (control >> 24) & 3;
812 snprintf(buf, sizeof(buf), "Mode: %d", x);
813 lcd_puts(0, line++, buf);
815 category = (control >> 17) & 127;
816 switch(category)
818 case 0x00:
819 s = "General";
820 break;
821 case 0x40:
822 s = "Audio CD";
823 break;
824 default:
825 s = "Unknown";
827 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
828 lcd_puts(0, line++, buf);
830 x = (control >> 16) & 1;
831 generation = x;
832 if(((category & 0x70) == 0x10) ||
833 ((category & 0x70) == 0x40) ||
834 ((category & 0x78) == 0x38))
836 generation = !generation;
838 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
839 x, generation?"Original":"No ind.");
840 lcd_puts(0, line++, buf);
842 x = (control >> 12) & 15;
843 snprintf(buf, sizeof(buf), "Source: %d", x);
844 lcd_puts(0, line++, buf);
846 x = (control >> 8) & 15;
847 switch(x)
849 case 0:
850 s = "Unspecified";
851 break;
852 case 8:
853 s = "A (Left)";
854 break;
855 case 4:
856 s = "B (Right)";
857 break;
858 default:
859 s = "";
860 break;
862 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
863 lcd_puts(0, line++, buf);
865 x = (control >> 4) & 15;
866 switch(x)
868 case 0:
869 s = "44.1kHz";
870 break;
871 case 0x4:
872 s = "48kHz";
873 break;
874 case 0xc:
875 s = "32kHz";
876 break;
878 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
879 lcd_puts(0, line++, buf);
881 x = (control >> 2) & 3;
882 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
883 lcd_puts(0, line++, buf);
884 line++;
886 #ifndef SIMULATOR
887 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
888 spdif_measure_frequency());
889 lcd_puts(0, line++, buf);
890 #endif
892 lcd_update();
894 if (action_userabort(HZ/10))
895 break;
898 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
900 #ifdef HAVE_SPDIF_POWER
901 spdif_power_enable(global_settings.spdif_enable);
902 #endif
904 return false;
906 #endif /* CPU_COLDFIRE */
908 #ifndef SIMULATOR
909 #ifdef HAVE_LCD_BITMAP
910 /* button definitions */
911 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
912 (CONFIG_KEYPAD == IRIVER_H300_PAD)
913 # define DEBUG_CANCEL BUTTON_OFF
915 #elif CONFIG_KEYPAD == RECORDER_PAD
916 # define DEBUG_CANCEL BUTTON_OFF
918 #elif CONFIG_KEYPAD == ONDIO_PAD
919 # define DEBUG_CANCEL BUTTON_MENU
921 #elif (CONFIG_KEYPAD == IPOD_3G_PAD) || \
922 (CONFIG_KEYPAD == IPOD_4G_PAD)
923 # define DEBUG_CANCEL BUTTON_MENU
925 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
926 # define DEBUG_CANCEL BUTTON_PLAY
928 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
929 # define DEBUG_CANCEL BUTTON_REC
931 #elif CONFIG_KEYPAD == GIGABEAT_PAD
932 # define DEBUG_CANCEL BUTTON_A
934 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
935 # define DEBUG_CANCEL BUTTON_REW
937 #elif CONFIG_KEYPAD == SANSA_E200_PAD
938 # define DEBUG_CANCEL BUTTON_LEFT
939 #endif /* key definitios */
941 /* Test code!!! */
942 bool dbg_ports(void)
944 #if CONFIG_CPU == SH7034
945 unsigned short porta;
946 unsigned short portb;
947 unsigned char portc;
948 char buf[32];
949 int adc_battery_voltage, adc_battery_level;
951 lcd_setfont(FONT_SYSFIXED);
952 lcd_setmargins(0, 0);
953 lcd_clear_display();
955 while(1)
957 porta = PADR;
958 portb = PBDR;
959 portc = PCDR;
961 snprintf(buf, 32, "PADR: %04x", porta);
962 lcd_puts(0, 0, buf);
963 snprintf(buf, 32, "PBDR: %04x", portb);
964 lcd_puts(0, 1, buf);
966 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
967 lcd_puts(0, 2, buf);
968 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
969 lcd_puts(0, 3, buf);
970 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
971 lcd_puts(0, 4, buf);
972 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
973 lcd_puts(0, 5, buf);
975 battery_read_info(NULL, &adc_battery_voltage,
976 &adc_battery_level);
977 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100,
978 adc_battery_voltage % 100, adc_battery_level);
979 lcd_puts(0, 6, buf);
981 lcd_update();
982 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
983 return false;
985 #elif defined(CPU_COLDFIRE)
986 unsigned int gpio_out;
987 unsigned int gpio1_out;
988 unsigned int gpio_read;
989 unsigned int gpio1_read;
990 unsigned int gpio_function;
991 unsigned int gpio1_function;
992 unsigned int gpio_enable;
993 unsigned int gpio1_enable;
994 int adc_buttons, adc_remote;
995 int adc_battery, adc_battery_voltage, adc_battery_level;
996 char buf[128];
997 int line;
999 lcd_setmargins(0, 0);
1000 lcd_clear_display();
1001 lcd_setfont(FONT_SYSFIXED);
1003 while(1)
1005 line = 0;
1006 gpio_read = GPIO_READ;
1007 gpio1_read = GPIO1_READ;
1008 gpio_out = GPIO_OUT;
1009 gpio1_out = GPIO1_OUT;
1010 gpio_function = GPIO_FUNCTION;
1011 gpio1_function = GPIO1_FUNCTION;
1012 gpio_enable = GPIO_ENABLE;
1013 gpio1_enable = GPIO1_ENABLE;
1015 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1016 lcd_puts(0, line++, buf);
1017 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1018 lcd_puts(0, line++, buf);
1019 snprintf(buf, sizeof(buf), "GPIO_FUNCTION: %08x", gpio_function);
1020 lcd_puts(0, line++, buf);
1021 snprintf(buf, sizeof(buf), "GPIO_ENABLE: %08x", gpio_enable);
1022 lcd_puts(0, line++, buf);
1024 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1025 lcd_puts(0, line++, buf);
1026 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1027 lcd_puts(0, line++, buf);
1028 snprintf(buf, sizeof(buf), "GPIO1_FUNCTION: %08x", gpio1_function);
1029 lcd_puts(0, line++, buf);
1030 snprintf(buf, sizeof(buf), "GPIO1_ENABLE: %08x", gpio1_enable);
1031 lcd_puts(0, line++, buf);
1033 adc_buttons = adc_read(ADC_BUTTONS);
1034 adc_remote = adc_read(ADC_REMOTE);
1035 battery_read_info(&adc_battery, &adc_battery_voltage,
1036 &adc_battery_level);
1037 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1038 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1039 button_scan_enabled() ? '+' : '-', adc_buttons);
1040 #else
1041 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1042 #endif
1043 lcd_puts(0, line++, buf);
1044 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1045 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1046 remote_detect() ? '+' : '-', adc_remote);
1047 #else
1048 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1049 #endif
1051 lcd_puts(0, line++, buf);
1052 snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_battery);
1053 lcd_puts(0, line++, buf);
1054 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1055 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1056 adc_read(ADC_REMOTEDETECT));
1057 lcd_puts(0, line++, buf);
1058 #endif
1060 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100,
1061 adc_battery_voltage % 100, adc_battery_level);
1062 lcd_puts(0, line++, buf);
1064 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1065 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1066 lcd_puts(0, line++, buf);
1067 #endif
1069 lcd_update();
1070 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1071 return false;
1074 #elif defined(CPU_PP502x)
1076 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1077 unsigned int gpio_e, gpio_f, gpio_g, gpio_h;
1078 unsigned int gpio_i, gpio_j, gpio_k, gpio_l;
1080 char buf[128];
1081 int line;
1083 lcd_setmargins(0, 0);
1084 lcd_clear_display();
1085 lcd_setfont(FONT_SYSFIXED);
1087 while(1)
1089 gpio_a = GPIOA_INPUT_VAL;
1090 gpio_b = GPIOB_INPUT_VAL;
1091 gpio_c = GPIOC_INPUT_VAL;
1093 gpio_g = GPIOG_INPUT_VAL;
1094 gpio_h = GPIOH_INPUT_VAL;
1095 gpio_i = GPIOI_INPUT_VAL;
1097 line = 0;
1098 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_G: %02x", gpio_a, gpio_g);
1099 lcd_puts(0, line++, buf);
1100 snprintf(buf, sizeof(buf), "GPIO_B: %02x GPIO_H: %02x", gpio_b, gpio_h);
1101 lcd_puts(0, line++, buf);
1102 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_I: %02x", gpio_c, gpio_i);
1103 lcd_puts(0, line++, buf);
1105 gpio_d = GPIOD_INPUT_VAL;
1106 gpio_e = GPIOE_INPUT_VAL;
1107 gpio_f = GPIOF_INPUT_VAL;
1109 gpio_j = GPIOJ_INPUT_VAL;
1110 gpio_k = GPIOK_INPUT_VAL;
1111 gpio_l = GPIOL_INPUT_VAL;
1113 snprintf(buf, sizeof(buf), "GPIO_D: %02x GPIO_J: %02x", gpio_d, gpio_j);
1114 lcd_puts(0, line++, buf);
1115 snprintf(buf, sizeof(buf), "GPIO_E: %02x GPIO_K: %02x", gpio_e, gpio_k);
1116 lcd_puts(0, line++, buf);
1117 snprintf(buf, sizeof(buf), "GPIO_F: %02x GPIO_L: %02x", gpio_f, gpio_l);
1118 lcd_puts(0, line++, buf);
1119 line++;
1121 snprintf(buf, sizeof(buf), "CLOCK_SRC: %08lx", inl(0x60006020));
1122 lcd_puts(0, line++, buf);
1123 snprintf(buf, sizeof(buf), "CLOCK_0x2C: %08lx", inl(0x6000602c));
1124 lcd_puts(0, line++, buf);
1125 snprintf(buf, sizeof(buf), "CLOCK_0xA0: %08lx", inl(0x600060a0));
1126 lcd_puts(0, line++, buf);
1127 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", inl(0x60006034));
1128 lcd_puts(0, line++, buf);
1129 snprintf(buf, sizeof(buf), "PLL_STATUS: %08lx", inl(0x6000603c));
1130 lcd_puts(0, line++, buf);
1131 snprintf(buf, sizeof(buf), "DEV_0x34: %08lx", inl(0x70000034));
1132 lcd_puts(0, line++, buf);
1134 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1135 line++;
1136 snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_read(ADC_BATTERY));
1137 lcd_puts(0, line++, buf);
1138 snprintf(buf, sizeof(buf), "ADC_UNKNOWN_1: %02x", adc_read(ADC_UNKNOWN_1));
1139 lcd_puts(0, line++, buf);
1140 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_read(ADC_REMOTE));
1141 lcd_puts(0, line++, buf);
1142 snprintf(buf, sizeof(buf), "ADC_SCROLLPAD: %02x", adc_read(ADC_SCROLLPAD));
1143 lcd_puts(0, line++, buf);
1144 #elif defined(SANSA_E200)
1145 line++;
1146 snprintf(buf, sizeof(buf), "ADC_BVDD: %02x", adc_read(ADC_BVDD));
1147 lcd_puts(0, line++, buf);
1148 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %02x", adc_read(ADC_RTCSUP));
1149 lcd_puts(0, line++, buf);
1150 snprintf(buf, sizeof(buf), "ADC_UVDD: %02x", adc_read(ADC_UVDD));
1151 lcd_puts(0, line++, buf);
1152 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %02x", adc_read(ADC_CHG_IN));
1153 lcd_puts(0, line++, buf);
1154 snprintf(buf, sizeof(buf), "ADC_CVDD: %02x", adc_read(ADC_CVDD));
1155 lcd_puts(0, line++, buf);
1156 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %02x", adc_read(ADC_BATTEMP));
1157 lcd_puts(0, line++, buf);
1158 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %02x", adc_read(ADC_MICSUP1));
1159 lcd_puts(0, line++, buf);
1160 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %02x", adc_read(ADC_MICSUP2));
1161 lcd_puts(0, line++, buf);
1162 snprintf(buf, sizeof(buf), "ADC_VBE1: %02x", adc_read(ADC_VBE1));
1163 lcd_puts(0, line++, buf);
1164 snprintf(buf, sizeof(buf), "ADC_VBE2: %02x", adc_read(ADC_VBE2));
1165 lcd_puts(0, line++, buf);
1166 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1: %02x", adc_read(ADC_I_MICSUP1));
1167 lcd_puts(0, line++, buf);
1168 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2: %02x", adc_read(ADC_I_MICSUP2));
1169 lcd_puts(0, line++, buf);
1170 snprintf(buf, sizeof(buf), "ADC_VBAT: %02x", adc_read(ADC_VBAT));
1171 lcd_puts(0, line++, buf);
1172 #endif
1173 lcd_update();
1174 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1175 return false;
1178 #elif CONFIG_CPU == PP5002
1179 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1181 char buf[128];
1182 int line;
1184 lcd_setmargins(0, 0);
1185 lcd_clear_display();
1186 lcd_setfont(FONT_SYSFIXED);
1188 while(1)
1190 gpio_a = GPIOA_INPUT_VAL;
1191 gpio_b = GPIOB_INPUT_VAL;
1192 gpio_c = GPIOC_INPUT_VAL;
1193 gpio_d = GPIOD_INPUT_VAL;
1195 line = 0;
1196 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x", gpio_a, gpio_b);
1197 lcd_puts(0, line++, buf);
1198 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x", gpio_c, gpio_d);
1199 lcd_puts(0, line++, buf);
1201 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1202 lcd_puts(0, line++, buf);
1203 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1204 lcd_puts(0, line++, buf);
1205 snprintf(buf, sizeof(buf), "CLOCK_DIV: %08lx", CLOCK_DIV);
1206 lcd_puts(0, line++, buf);
1207 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1208 lcd_puts(0, line++, buf);
1209 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1210 lcd_puts(0, line++, buf);
1211 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1212 lcd_puts(0, line++, buf);
1213 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1214 lcd_puts(0, line++, buf);
1215 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
1216 lcd_puts(0, line++, buf);
1218 lcd_update();
1219 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1220 return false;
1222 #elif CONFIG_CPU == S3C2440
1223 char buf[50];
1224 int line;
1226 lcd_setmargins(0, 0);
1227 lcd_clear_display();
1228 lcd_setfont(FONT_SYSFIXED);
1230 while(1)
1232 line = 0;
1233 snprintf(buf, sizeof(buf), "[Ports and Registers]"); lcd_puts(0, line++, buf);
1235 snprintf(buf, sizeof(buf), "GPACON: %08x GPBCON: %08x", GPACON, GPBCON); lcd_puts(0, line++, buf);
1236 snprintf(buf, sizeof(buf), "GPADAT: %08x GPBDAT: %08x", GPADAT, GPBDAT); lcd_puts(0, line++, buf);
1237 snprintf(buf, sizeof(buf), "GPAUP: %08x GPBUP: %08x", 0, GPBUP); lcd_puts(0, line++, buf);
1238 snprintf(buf, sizeof(buf), "GPCCON: %08x GPDCON: %08x", GPCCON, GPDCON); lcd_puts(0, line++, buf);
1239 snprintf(buf, sizeof(buf), "GPCDAT: %08x GPDDAT: %08x", GPCDAT, GPDDAT); lcd_puts(0, line++, buf);
1240 snprintf(buf, sizeof(buf), "GPCUP: %08x GPDUP: %08x", GPCUP, GPDUP); lcd_puts(0, line++, buf);
1242 snprintf(buf, sizeof(buf), "GPCCON: %08x GPDCON: %08x", GPCCON, GPDCON); lcd_puts(0, line++, buf);
1243 snprintf(buf, sizeof(buf), "GPCDAT: %08x GPDDAT: %08x", GPCDAT, GPDDAT); lcd_puts(0, line++, buf);
1244 snprintf(buf, sizeof(buf), "GPCUP: %08x GPDUP: %08x", GPCUP, GPDUP); lcd_puts(0, line++, buf);
1246 snprintf(buf, sizeof(buf), "GPECON: %08x GPFCON: %08x", GPECON, GPFCON); lcd_puts(0, line++, buf);
1247 snprintf(buf, sizeof(buf), "GPEDAT: %08x GPFDAT: %08x", GPEDAT, GPFDAT); lcd_puts(0, line++, buf);
1248 snprintf(buf, sizeof(buf), "GPEUP: %08x GPFUP: %08x", GPEUP, GPFUP); lcd_puts(0, line++, buf);
1250 snprintf(buf, sizeof(buf), "GPGCON: %08x GPHCON: %08x", GPGCON, GPHCON); lcd_puts(0, line++, buf);
1251 snprintf(buf, sizeof(buf), "GPGDAT: %08x GPHDAT: %08x", GPGDAT, GPHDAT); lcd_puts(0, line++, buf);
1252 snprintf(buf, sizeof(buf), "GPGUP: %08x GPHUP: %08x", GPGUP, GPHUP); lcd_puts(0, line++, buf);
1254 snprintf(buf, sizeof(buf), "GPJCON: %08x", GPJCON); lcd_puts(0, line++, buf);
1255 snprintf(buf, sizeof(buf), "GPJDAT: %08x", GPJDAT); lcd_puts(0, line++, buf);
1256 snprintf(buf, sizeof(buf), "GPJUP: %08x", GPJUP); lcd_puts(0, line++, buf);
1258 line++;
1260 snprintf(buf, sizeof(buf), "SRCPND: %08x INTMOD: %08x", SRCPND, INTMOD); lcd_puts(0, line++, buf);
1261 snprintf(buf, sizeof(buf), "INTMSK: %08x INTPND: %08x", INTMSK, INTPND); lcd_puts(0, line++, buf);
1262 snprintf(buf, sizeof(buf), "CLKCON: %08x CLKSLOW: %08x", CLKCON, CLKSLOW); lcd_puts(0, line++, buf);
1263 snprintf(buf, sizeof(buf), "MPLLCON: %08x UPLLCON: %08x", MPLLCON, UPLLCON); lcd_puts(0, line++, buf);
1264 snprintf(buf, sizeof(buf), "CLKDIVN: %08x", CLKDIVN); lcd_puts(0, line++, buf);
1266 lcd_update();
1267 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1268 return false;
1270 #endif /* CPU */
1271 return false;
1273 #else /* !HAVE_LCD_BITMAP */
1274 bool dbg_ports(void)
1276 unsigned short porta;
1277 unsigned short portb;
1278 unsigned char portc;
1279 char buf[32];
1280 int button;
1281 int adc_battery_voltage;
1282 int currval = 0;
1284 lcd_clear_display();
1286 while(1)
1288 porta = PADR;
1289 portb = PBDR;
1290 portc = PCDR;
1292 switch(currval)
1294 case 0:
1295 snprintf(buf, 32, "PADR: %04x", porta);
1296 break;
1297 case 1:
1298 snprintf(buf, 32, "PBDR: %04x", portb);
1299 break;
1300 case 2:
1301 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1302 break;
1303 case 3:
1304 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1305 break;
1306 case 4:
1307 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1308 break;
1309 case 5:
1310 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1311 break;
1312 case 6:
1313 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1314 break;
1315 case 7:
1316 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1317 break;
1318 case 8:
1319 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1320 break;
1321 case 9:
1322 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1323 break;
1324 break;
1326 lcd_puts(0, 0, buf);
1328 battery_read_info(NULL, &adc_battery_voltage, NULL);
1329 snprintf(buf, 32, "Batt: %d.%02dV", adc_battery_voltage / 100,
1330 adc_battery_voltage % 100);
1331 lcd_puts(0, 1, buf);
1332 lcd_update();
1334 button = get_action(CONTEXT_SETTINGS,HZ/5);
1336 switch(button)
1338 case ACTION_STD_CANCEL:
1339 action_signalscreenchange();
1340 return false;
1342 case ACTION_SETTINGS_DEC:
1343 currval--;
1344 if(currval < 0)
1345 currval = 9;
1346 break;
1348 case ACTION_SETTINGS_INC:
1349 currval++;
1350 if(currval > 9)
1351 currval = 0;
1352 break;
1355 return false;
1357 #endif /* !HAVE_LCD_BITMAP */
1358 #endif /* !SIMULATOR */
1360 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1361 static bool dbg_cpufreq(void)
1363 char buf[128];
1364 int line;
1365 int button;
1367 #ifdef HAVE_LCD_BITMAP
1368 lcd_setmargins(0, 0);
1369 lcd_setfont(FONT_SYSFIXED);
1370 #endif
1371 lcd_clear_display();
1373 while(1)
1375 line = 0;
1377 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1378 lcd_puts(0, line++, buf);
1380 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1381 lcd_puts(0, line++, buf);
1383 lcd_update();
1384 button = get_action(CONTEXT_STD,HZ/10);
1386 switch(button)
1388 case ACTION_STD_PREV:
1389 cpu_boost(true);
1390 break;
1392 case ACTION_STD_NEXT:
1393 cpu_boost(false);
1394 break;
1396 case ACTION_STD_OK:
1397 while (get_cpu_boost_counter() > 0)
1398 cpu_boost(false);
1399 set_cpu_frequency(CPUFREQ_DEFAULT);
1400 break;
1402 case ACTION_STD_CANCEL:
1403 action_signalscreenchange();
1404 return false;
1408 return false;
1410 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1412 #ifndef SIMULATOR
1413 #ifdef HAVE_LCD_BITMAP
1415 * view_battery() shows a automatically scaled graph of the battery voltage
1416 * over time. Usable for estimating battery life / charging rate.
1417 * The power_history array is updated in power_thread of powermgmt.c.
1420 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1421 #define BAT_YSPACE (LCD_HEIGHT - 20)
1423 static bool view_battery(void)
1425 int view = 0;
1426 int i, x, y;
1427 unsigned short maxv, minv;
1428 char buf[32];
1430 lcd_setmargins(0, 0);
1431 lcd_setfont(FONT_SYSFIXED);
1433 while(1)
1435 lcd_clear_display();
1436 switch (view) {
1437 case 0: /* voltage history graph */
1438 /* Find maximum and minimum voltage for scaling */
1439 maxv = 0;
1440 minv = 65535;
1441 for (i = 0; i < BAT_LAST_VAL; i++) {
1442 if (power_history[i] > maxv)
1443 maxv = power_history[i];
1444 if (power_history[i] && (power_history[i] < minv))
1446 minv = power_history[i];
1450 if ((minv < 1) || (minv >= 65535))
1451 minv = 1;
1452 if (maxv < 2)
1453 maxv = 2;
1454 if (minv == maxv)
1455 maxv < 65535 ? maxv++ : minv--;
1457 snprintf(buf, 30, "Battery %d.%02d", power_history[0] / 100,
1458 power_history[0] % 100);
1459 lcd_puts(0, 0, buf);
1460 snprintf(buf, 30, "scale %d.%02d-%d.%02d V",
1461 minv / 100, minv % 100, maxv / 100, maxv % 100);
1462 lcd_puts(0, 1, buf);
1464 x = 0;
1465 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1466 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1467 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1468 lcd_vline(x, LCD_HEIGHT-1, 20);
1469 lcd_set_drawmode(DRMODE_SOLID);
1470 lcd_vline(x, LCD_HEIGHT-1,
1471 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1472 x++;
1475 break;
1477 case 1: /* status: */
1478 lcd_puts(0, 0, "Power status:");
1480 battery_read_info(NULL, &y, NULL);
1481 snprintf(buf, 30, "Battery: %d.%02d V", y / 100, y % 100);
1482 lcd_puts(0, 1, buf);
1483 #ifdef ADC_EXT_POWER
1484 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000;
1485 snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100);
1486 lcd_puts(0, 2, buf);
1487 #endif
1488 #if CONFIG_CHARGING
1489 #if CONFIG_CHARGING == CHARGING_CONTROL
1490 snprintf(buf, 30, "Chgr: %s %s",
1491 charger_inserted() ? "present" : "absent",
1492 charger_enabled ? "on" : "off");
1493 lcd_puts(0, 3, buf);
1494 snprintf(buf, 30, "short delta: %d", short_delta);
1495 lcd_puts(0, 5, buf);
1496 snprintf(buf, 30, "long delta: %d", long_delta);
1497 lcd_puts(0, 6, buf);
1498 lcd_puts(0, 7, power_message);
1499 snprintf(buf, 30, "USB Inserted: %s",
1500 usb_inserted() ? "yes" : "no");
1501 lcd_puts(0, 8, buf);
1502 #if defined IRIVER_H300_SERIES
1503 snprintf(buf, 30, "USB Charging Enabled: %s",
1504 usb_charging_enabled() ? "yes" : "no");
1505 lcd_puts(0, 9, buf);
1506 #endif
1507 #else /* CONFIG_CHARGING != CHARGING_CONTROL */
1508 #if defined IPOD_NANO || defined IPOD_VIDEO
1509 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1510 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1511 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1512 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1513 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1515 snprintf(buf, 30, "USB pwr: %s",
1516 usb_pwr ? "present" : "absent");
1517 lcd_puts(0, 3, buf);
1518 snprintf(buf, 30, "EXT pwr: %s",
1519 ext_pwr ? "present" : "absent");
1520 lcd_puts(0, 4, buf);
1521 snprintf(buf, 30, "Battery: %s",
1522 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1523 lcd_puts(0, 5, buf);
1524 snprintf(buf, 30, "Dock mode: %s",
1525 dock ? "enabled" : "disabled");
1526 lcd_puts(0, 6, buf);
1527 snprintf(buf, 30, "Headphone: %s",
1528 headphone ? "connected" : "disconnected");
1529 lcd_puts(0, 7, buf);
1530 #else
1531 snprintf(buf, 30, "Charger: %s",
1532 charger_inserted() ? "present" : "absent");
1533 lcd_puts(0, 3, buf);
1534 #endif
1535 #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1536 #endif /* CONFIG_CHARGING */
1537 break;
1539 case 2: /* voltage deltas: */
1540 lcd_puts(0, 0, "Voltage deltas:");
1542 for (i = 0; i <= 6; i++) {
1543 y = power_history[i] - power_history[i+i];
1544 snprintf(buf, 30, "-%d min: %s%d.%02d V", i,
1545 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 100,
1546 ((y < 0) ? y * -1 : y ) % 100);
1547 lcd_puts(0, i+1, buf);
1549 break;
1551 case 3: /* remaining time estimation: */
1553 #if CONFIG_CHARGING == CHARGING_CONTROL
1554 snprintf(buf, 30, "charge_state: %d", charge_state);
1555 lcd_puts(0, 0, buf);
1557 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1558 lcd_puts(0, 1, buf);
1560 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1561 lcd_puts(0, 2, buf);
1563 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1564 lcd_puts(0, 3, buf);
1566 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1567 lcd_puts(0, 4, buf);
1568 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
1570 snprintf(buf, 30, "Last PwrHist: %d.%02d V",
1571 power_history[0] / 100,
1572 power_history[0] % 100);
1573 lcd_puts(0, 5, buf);
1575 snprintf(buf, 30, "battery level: %d%%", battery_level());
1576 lcd_puts(0, 6, buf);
1578 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1579 lcd_puts(0, 7, buf);
1580 break;
1583 lcd_update();
1585 switch(get_action(CONTEXT_SETTINGS,HZ/2))
1587 case ACTION_SETTINGS_DEC:
1588 if (view)
1589 view--;
1590 break;
1592 case ACTION_SETTINGS_INC:
1593 if (view < 3)
1594 view++;
1595 break;
1597 case ACTION_STD_CANCEL:
1598 action_signalscreenchange();
1599 return false;
1602 return false;
1605 #endif /* HAVE_LCD_BITMAP */
1606 #endif
1608 #ifndef SIMULATOR
1609 #if defined(HAVE_MMC) || defined(HAVE_HOTSWAP)
1610 static bool dbg_card_info(void)
1612 bool done = false;
1613 int currval = 0;
1614 int line;
1615 tCardInfo *card;
1616 unsigned char pbuf[32], pbuf2[32];
1617 unsigned char card_name[7];
1619 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1620 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1621 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1622 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1623 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1624 "3.1-3.31", "4.0" };
1626 card_name[6] = '\0';
1628 lcd_setmargins(0, 0);
1629 lcd_setfont(FONT_SYSFIXED);
1631 while (!done)
1633 card = card_get_info(currval / 2);
1635 line = 0;
1636 lcd_clear_display();
1637 snprintf(pbuf, sizeof(pbuf), "[MMC%d p%d]", currval / 2,
1638 (currval % 2) + 1);
1639 lcd_puts(0, line++, pbuf);
1641 if (card->initialized)
1643 if (!(currval % 2)) /* General info */
1645 int temp;
1647 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1648 snprintf(pbuf, sizeof(pbuf), "%s Rev %d.%d", card_name,
1649 (int) card_extract_bits(card->cid, 72, 4),
1650 (int) card_extract_bits(card->cid, 76, 4));
1651 lcd_puts(0, line++, pbuf);
1652 snprintf(pbuf, sizeof(pbuf), "Prod: %d/%d",
1653 (int) card_extract_bits(card->cid, 112, 4),
1654 (int) card_extract_bits(card->cid, 116, 4) + 1997);
1655 lcd_puts(0, line++, pbuf);
1656 snprintf(pbuf, sizeof(pbuf), "Ser#: 0x%08lx",
1657 card_extract_bits(card->cid, 80, 32));
1658 lcd_puts(0, line++, pbuf);
1659 snprintf(pbuf, sizeof(pbuf), "M=%02x, O=%04x",
1660 (int) card_extract_bits(card->cid, 0, 8),
1661 (int) card_extract_bits(card->cid, 8, 16));
1662 lcd_puts(0, line++, pbuf);
1663 temp = card_extract_bits(card->csd, 2, 4);
1664 snprintf(pbuf, sizeof(pbuf), "MMC v%s", temp < 5 ?
1665 spec_vers[temp] : "?.?");
1666 lcd_puts(0, line++, pbuf);
1667 snprintf(pbuf, sizeof(pbuf), "Blocks: 0x%06lx", card->numblocks);
1668 lcd_puts(0, line++, pbuf);
1669 snprintf(pbuf, sizeof(pbuf), "Blksz.: %d P:%c%c", card->blocksize,
1670 card_extract_bits(card->csd, 48, 1) ? 'R' : '-',
1671 card_extract_bits(card->csd, 106, 1) ? 'W' : '-');
1672 lcd_puts(0, line++, pbuf);
1674 else /* Technical details */
1676 output_dyn_value(pbuf2, sizeof pbuf2, card->speed / 1000,
1677 kbit_units, false);
1678 snprintf(pbuf, sizeof pbuf, "Speed: %s", pbuf2);
1679 lcd_puts(0, line++, pbuf);
1681 output_dyn_value(pbuf2, sizeof pbuf2, card->tsac,
1682 nsec_units, false);
1683 snprintf(pbuf, sizeof pbuf, "Tsac: %s", pbuf2);
1684 lcd_puts(0, line++, pbuf);
1686 snprintf(pbuf, sizeof(pbuf), "Nsac: %d clk", card->nsac);
1687 lcd_puts(0, line++, pbuf);
1688 snprintf(pbuf, sizeof(pbuf), "R2W: *%d", card->r2w_factor);
1689 lcd_puts(0, line++, pbuf);
1690 snprintf(pbuf, sizeof(pbuf), "IRmax: %d..%d mA",
1691 i_vmin[card_extract_bits(card->csd, 66, 3)],
1692 i_vmax[card_extract_bits(card->csd, 69, 3)]);
1693 lcd_puts(0, line++, pbuf);
1694 snprintf(pbuf, sizeof(pbuf), "IWmax: %d..%d mA",
1695 i_vmin[card_extract_bits(card->csd, 72, 3)],
1696 i_vmax[card_extract_bits(card->csd, 75, 3)]);
1697 lcd_puts(0, line++, pbuf);
1700 else
1701 lcd_puts(0, line++, "Not found!");
1703 lcd_update();
1705 switch (get_action(CONTEXT_SETTINGS,HZ/2))
1707 case ACTION_STD_CANCEL:
1708 done = true;
1709 break;
1711 case ACTION_SETTINGS_DEC:
1712 currval--;
1713 if (currval < 0)
1714 currval = 3;
1715 break;
1717 case ACTION_SETTINGS_INC:
1718 currval++;
1719 if (currval > 3)
1720 currval = 0;
1721 break;
1724 action_signalscreenchange();
1725 return false;
1727 #else /* !defined(HAVE_MMC) && !defined(HAVE_HOTSWAP) */
1728 static bool dbg_disk_info(void)
1730 char buf[128];
1731 bool done = false;
1732 int i;
1733 int page = 0;
1734 const int max_page = 11;
1735 unsigned short* identify_info = ata_get_identify();
1736 bool timing_info_present = false;
1737 char pio3[2], pio4[2];
1739 lcd_setmargins(0, 0);
1741 while(!done)
1743 int y=0;
1744 int key;
1745 lcd_clear_display();
1746 #ifdef HAVE_LCD_BITMAP
1747 lcd_puts(0, y++, "Disk info:");
1748 y++;
1749 #endif
1751 switch (page) {
1752 case 0:
1753 for (i=0; i < 20; i++)
1754 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1755 buf[40]=0;
1756 /* kill trailing space */
1757 for (i=39; i && buf[i]==' '; i--)
1758 buf[i] = 0;
1759 lcd_puts(0, y++, "Model");
1760 lcd_puts_scroll(0, y++, buf);
1761 break;
1763 case 1:
1764 for (i=0; i < 4; i++)
1765 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1766 buf[8]=0;
1767 lcd_puts(0, y++, "Firmware");
1768 lcd_puts(0, y++, buf);
1769 break;
1771 case 2:
1772 snprintf(buf, sizeof buf, "%ld MB",
1773 ((unsigned long)identify_info[61] << 16 |
1774 (unsigned long)identify_info[60]) / 2048 );
1775 lcd_puts(0, y++, "Size");
1776 lcd_puts(0, y++, buf);
1777 break;
1779 case 3: {
1780 unsigned long free;
1781 fat_size( IF_MV2(0,) NULL, &free );
1782 snprintf(buf, sizeof buf, "%ld MB", free / 1024 );
1783 lcd_puts(0, y++, "Free");
1784 lcd_puts(0, y++, buf);
1785 break;
1788 case 4:
1789 snprintf(buf, sizeof buf, "%d ms", ata_spinup_time * (1000/HZ));
1790 lcd_puts(0, y++, "Spinup time");
1791 lcd_puts(0, y++, buf);
1792 break;
1794 case 5:
1795 i = identify_info[83] & (1<<3);
1796 lcd_puts(0, y++, "Power mgmt:");
1797 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1798 break;
1800 case 6:
1801 i = identify_info[83] & (1<<9);
1802 lcd_puts(0, y++, "Noise mgmt:");
1803 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1804 break;
1806 case 7:
1807 i = identify_info[82] & (1<<6);
1808 lcd_puts(0, y++, "Read-ahead:");
1809 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1810 break;
1812 case 8:
1813 timing_info_present = identify_info[53] & (1<<1);
1814 if(timing_info_present) {
1815 pio3[1] = 0;
1816 pio4[1] = 0;
1817 lcd_puts(0, y++, "PIO modes:");
1818 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1819 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1820 snprintf(buf, 128, "0 1 2 %s %s", pio3, pio4);
1821 lcd_puts(0, y++, buf);
1822 } else {
1823 lcd_puts(0, y++, "No PIO mode info");
1825 break;
1827 case 9:
1828 timing_info_present = identify_info[53] & (1<<1);
1829 if(timing_info_present) {
1830 lcd_puts(0, y++, "Cycle times");
1831 snprintf(buf, 128, "%dns/%dns",
1832 identify_info[67],
1833 identify_info[68]);
1834 lcd_puts(0, y++, buf);
1835 } else {
1836 lcd_puts(0, y++, "No timing info");
1838 break;
1840 case 10:
1841 timing_info_present = identify_info[53] & (1<<1);
1842 if(timing_info_present) {
1843 i = identify_info[49] & (1<<11);
1844 snprintf(buf, 128, "IORDY support: %s", i ? "yes" : "no");
1845 lcd_puts(0, y++, buf);
1846 i = identify_info[49] & (1<<10);
1847 snprintf(buf, 128, "IORDY disable: %s", i ? "yes" : "no");
1848 lcd_puts(0, y++, buf);
1849 } else {
1850 lcd_puts(0, y++, "No timing info");
1852 break;
1854 case 11:
1855 lcd_puts(0, y++, "Cluster size");
1856 snprintf(buf, 128, "%d bytes", fat_get_cluster_size(IF_MV(0)));
1857 lcd_puts(0, y++, buf);
1858 break;
1860 lcd_update();
1862 /* Wait for a key to be pushed */
1863 key = get_action(CONTEXT_SETTINGS,HZ/5);
1864 switch(key) {
1865 case ACTION_STD_CANCEL:
1866 done = true;
1867 break;
1869 case ACTION_SETTINGS_DEC:
1870 if (--page < 0)
1871 page = max_page;
1872 break;
1874 case ACTION_SETTINGS_INC:
1875 if (++page > max_page)
1876 page = 0;
1877 break;
1879 lcd_stop_scroll();
1881 action_signalscreenchange();
1882 return false;
1884 #endif /* !defined(HAVE_MMC) && !defined(HAVE_HOTSWAP) */
1885 #endif /* !SIMULATOR */
1887 #ifdef HAVE_DIRCACHE
1888 static int dircache_callback(int btn, struct gui_synclist *lists)
1890 (void)btn; (void)lists;
1891 snprintf(debug_list_messages[0], DEBUG_MSG_LEN, "Cache initialized: %s",
1892 dircache_is_enabled() ? "Yes" : "No");
1893 snprintf(debug_list_messages[1], DEBUG_MSG_LEN, "Cache size: %d B",
1894 dircache_get_cache_size());
1895 snprintf(debug_list_messages[2], DEBUG_MSG_LEN, "Last size: %d B",
1896 global_status.dircache_size);
1897 snprintf(debug_list_messages[3], DEBUG_MSG_LEN, "Limit: %d B",
1898 DIRCACHE_LIMIT);
1899 snprintf(debug_list_messages[4], DEBUG_MSG_LEN, "Reserve: %d/%d B",
1900 dircache_get_reserve_used(), DIRCACHE_RESERVE);
1901 snprintf(debug_list_messages[5], DEBUG_MSG_LEN, "Scanning took: %d s",
1902 dircache_get_build_ticks() / HZ);
1903 snprintf(debug_list_messages[6], DEBUG_MSG_LEN, "Entry count: %d",
1904 dircache_get_entry_count());
1905 return btn;
1908 static bool dbg_dircache_info(void)
1910 dircache_callback(0,0);
1911 dbg_list("Dircache Info",7, 1, dircache_callback, dbg_listmessage_getname);
1912 return false;
1915 #endif /* HAVE_DIRCACHE */
1917 #ifdef HAVE_TAGCACHE
1918 static int database_callback(int btn, struct gui_synclist *lists)
1920 (void)btn; (void)lists;
1921 struct tagcache_stat *stat = tagcache_get_stat();
1922 snprintf(debug_list_messages[0], DEBUG_MSG_LEN, "Initialized: %s",
1923 stat->initialized ? "Yes" : "No");
1924 snprintf(debug_list_messages[1], DEBUG_MSG_LEN, "DB Ready: %s",
1925 stat->ready ? "Yes" : "No");
1926 snprintf(debug_list_messages[2], DEBUG_MSG_LEN, "RAM Cache: %s",
1927 stat->ramcache ? "Yes" : "No");
1928 snprintf(debug_list_messages[3], DEBUG_MSG_LEN, "RAM: %d/%d B",
1929 stat->ramcache_used, stat->ramcache_allocated);
1930 snprintf(debug_list_messages[4], DEBUG_MSG_LEN, "Progress: %d%% (%d entries)",
1931 stat->progress, stat->processed_entries);
1932 snprintf(debug_list_messages[5], DEBUG_MSG_LEN, "Commit step: %d",
1933 stat->commit_step);
1934 snprintf(debug_list_messages[6], DEBUG_MSG_LEN, "Commit delayed: %s",
1935 stat->commit_delayed ? "Yes" : "No");
1936 return btn;
1938 static bool dbg_tagcache_info(void)
1940 database_callback(0,0);
1941 dbg_list("Database Info",7, 1, database_callback, dbg_listmessage_getname);
1942 return false;
1944 #endif
1946 #if CONFIG_CPU == SH7034
1947 static bool dbg_save_roms(void)
1949 int fd;
1950 int oldmode = system_memory_guard(MEMGUARD_NONE);
1952 fd = creat("/internal_rom_0000-FFFF.bin");
1953 if(fd >= 0)
1955 write(fd, (void *)0, 0x10000);
1956 close(fd);
1959 fd = creat("/internal_rom_2000000-203FFFF.bin");
1960 if(fd >= 0)
1962 write(fd, (void *)0x2000000, 0x40000);
1963 close(fd);
1966 system_memory_guard(oldmode);
1967 return false;
1969 #elif defined CPU_COLDFIRE
1970 static bool dbg_save_roms(void)
1972 int fd;
1973 int oldmode = system_memory_guard(MEMGUARD_NONE);
1975 #if defined(IRIVER_H100_SERIES)
1976 fd = creat("/internal_rom_000000-1FFFFF.bin");
1977 #elif defined(IRIVER_H300_SERIES)
1978 fd = creat("/internal_rom_000000-3FFFFF.bin");
1979 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5)
1980 fd = creat("/internal_rom_000000-3FFFFF.bin");
1981 #endif
1982 if(fd >= 0)
1984 write(fd, (void *)0, FLASH_SIZE);
1985 close(fd);
1987 system_memory_guard(oldmode);
1989 #ifdef HAVE_EEPROM
1990 fd = creat("/internal_eeprom.bin");
1991 if (fd >= 0)
1993 int old_irq_level;
1994 char buf[EEPROM_SIZE];
1995 int err;
1997 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
1999 err = eeprom_24cxx_read(0, buf, sizeof buf);
2000 if (err)
2001 gui_syncsplash(HZ*3, "Eeprom read failure (%d)",err);
2002 else
2004 write(fd, buf, sizeof buf);
2007 set_irq_level(old_irq_level);
2009 close(fd);
2011 #endif
2013 return false;
2015 #elif defined(CPU_PP) && !defined(SANSA_E200)
2016 static bool dbg_save_roms(void)
2018 int fd;
2020 fd = creat("/internal_rom_000000-0FFFFF.bin");
2021 if(fd >= 0)
2023 write(fd, (void *)0x20000000, FLASH_SIZE);
2024 close(fd);
2027 return false;
2029 #endif /* CPU */
2031 #ifndef SIMULATOR
2032 #if CONFIG_TUNER
2033 int radio_lines = 0;
2034 static int radio_callback(int btn, struct gui_synclist *lists)
2036 (void)btn; (void)lists;
2037 if (radio_hardware_present())
2039 snprintf(debug_list_messages[radio_lines++], DEBUG_MSG_LEN,
2040 "HW detected: yes");
2041 #if (CONFIG_TUNER & LV24020LP)
2042 snprintf(debug_list_messages[radio_lines++], DEBUG_MSG_LEN,
2043 "CTRL_STAT: %02X", sanyo_get(RADIO_ALL) );
2044 snprintf(debug_list_messages[radio_lines++], DEBUG_MSG_LEN,
2045 "RADIO_STAT: %02X", sanyo_get(RADIO_REG_STAT));
2046 snprintf(debug_list_messages[radio_lines++], DEBUG_MSG_LEN,
2047 "MSS_FM: %d kHz", sanyo_get(RADIO_MSS_FM) );
2048 snprintf(debug_list_messages[radio_lines++], DEBUG_MSG_LEN,
2049 "MSS_IF: %d Hz", (sanyo_get(RADIO_MSS_IF) ) );
2050 snprintf(debug_list_messages[radio_lines++], DEBUG_MSG_LEN,
2051 "MSS_SD: %d Hz", (sanyo_get(RADIO_MSS_SD) ) );
2052 snprintf(debug_list_messages[radio_lines++], DEBUG_MSG_LEN,
2053 "if_set: %d Hz", (sanyo_get(RADIO_IF_SET) ) );
2054 snprintf(debug_list_messages[radio_lines++], DEBUG_MSG_LEN,
2055 "sd_set: %d Hz", (sanyo_get(RADIO_SD_SET) ) );
2056 #endif
2057 #if (CONFIG_TUNER & S1A0903X01)
2058 snprintf(debug_list_messages[radio_lines++], DEBUG_MSG_LEN,
2059 "Samsung regs: %08X", samsung_get(RADIO_ALL));
2060 #endif
2061 #if (CONFIG_TUNER & TEA5767)
2062 struct philips_dbg_info info;
2063 philips_dbg_info(&info);
2064 snprintf(debug_list_messages[radio_lines++], DEBUG_MSG_LEN, "Philips regs:");
2065 snprintf(debug_list_messages[radio_lines++], DEBUG_MSG_LEN,
2066 " Read: %02X %02X %02X %02X %02X",
2067 (unsigned)info.read_regs[0], (unsigned)info.read_regs[1],
2068 (unsigned)info.read_regs[2], (unsigned)info.read_regs[3],
2069 (unsigned)info.read_regs[4]);
2070 snprintf(debug_list_messages[radio_lines++], DEBUG_MSG_LEN,
2071 " Write: %02X %02X %02X %02X %02X",
2072 (unsigned)info.write_regs[0], (unsigned)info.write_regs[1],
2073 (unsigned)info.write_regs[2], (unsigned)info.write_regs[3],
2074 (unsigned)info.write_regs[4]);
2075 #endif
2077 else
2078 snprintf(debug_list_messages[radio_lines++], DEBUG_MSG_LEN, "HW detected: no");
2079 return btn;
2081 static bool dbg_fm_radio(void)
2083 radio_callback(0,0);
2084 dbg_list("FM Radio",radio_lines, 1,
2085 radio_callback, dbg_listmessage_getname);
2086 return false;
2088 #endif /* CONFIG_TUNER */
2089 #endif /* !SIMULATOR */
2091 #ifdef HAVE_LCD_BITMAP
2092 extern bool do_screendump_instead_of_usb;
2094 static bool dbg_screendump(void)
2096 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2097 gui_syncsplash(HZ, "Screendump %s",
2098 do_screendump_instead_of_usb?"enabled":"disabled");
2099 return false;
2101 #endif /* HAVE_LCD_BITMAP */
2103 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2104 static bool dbg_set_memory_guard(void)
2106 static const struct opt_items names[MAXMEMGUARD] = {
2107 { "None", -1 },
2108 { "Flash ROM writes", -1 },
2109 { "Zero area (all)", -1 }
2111 int mode = system_memory_guard(MEMGUARD_KEEP);
2113 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2114 system_memory_guard(mode);
2116 return false;
2118 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2120 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2122 extern volatile bool lcd_poweroff;
2124 static bool dbg_lcd_power_off(void)
2126 lcd_setmargins(0, 0);
2128 while(1)
2130 int button;
2132 lcd_clear_display();
2133 lcd_puts(0, 0, "LCD Power Off");
2134 if(lcd_poweroff)
2135 lcd_puts(1, 1, "Yes");
2136 else
2137 lcd_puts(1, 1, "No");
2139 lcd_update();
2141 button = get_action(CONTEXT_STD,HZ/5);
2142 switch(button)
2144 case ACTION_STD_PREV:
2145 case ACTION_STD_NEXT:
2146 lcd_poweroff = !lcd_poweroff;
2147 break;
2148 case ACTION_STD_OK:
2149 case ACTION_STD_CANCEL:
2150 action_signalscreenchange();
2151 return false;
2152 default:
2153 sleep(HZ/10);
2154 break;
2157 return false;
2159 #endif
2161 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2162 static bool dbg_write_eeprom(void)
2164 int fd;
2165 int rc;
2166 int old_irq_level;
2167 char buf[EEPROM_SIZE];
2168 int err;
2170 fd = open("/internal_eeprom.bin", O_RDONLY);
2172 if (fd >= 0)
2174 rc = read(fd, buf, EEPROM_SIZE);
2176 if(rc == EEPROM_SIZE)
2178 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
2180 err = eeprom_24cxx_write(0, buf, sizeof buf);
2181 if (err)
2182 gui_syncsplash(HZ*3, "Eeprom write failure (%d)",err);
2183 else
2184 gui_syncsplash(HZ*3, "Eeprom written successfully");
2186 set_irq_level(old_irq_level);
2188 else
2190 gui_syncsplash(HZ*3, "File read error (%d)",rc);
2192 close(fd);
2194 else
2196 gui_syncsplash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2199 return false;
2201 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2202 #ifdef CPU_BOOST_LOGGING
2203 static bool cpu_boost_log(void)
2205 int i = 0,j=0;
2206 int count = cpu_boost_log_getcount();
2207 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2208 char *str;
2209 bool done;
2210 lcd_setmargins(0, 0);
2211 lcd_setfont(FONT_SYSFIXED);
2212 str = cpu_boost_log_getlog_first();
2213 while (i < count)
2215 lcd_clear_display();
2216 for(j=0; j<lines; j++,i++)
2218 if (!str)
2219 str = cpu_boost_log_getlog_next();
2220 if (str)
2222 lcd_puts(0, j,str);
2224 str = NULL;
2226 lcd_update();
2227 done = false;
2228 action_signalscreenchange();
2229 while (!done)
2231 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2233 case ACTION_STD_OK:
2234 case ACTION_STD_PREV:
2235 case ACTION_STD_NEXT:
2236 done = true;
2237 break;
2238 case ACTION_STD_CANCEL:
2239 i = count;
2240 done = true;
2241 break;
2245 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2246 lcd_setfont(FONT_UI);
2247 action_signalscreenchange();
2248 return false;
2250 #endif
2254 /****** The menu *********/
2255 struct the_menu_item {
2256 unsigned char *desc; /* string or ID */
2257 bool (*function) (void); /* return true if USB was connected */
2259 static const struct the_menu_item menuitems[] = {
2260 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2261 { "LCD Power Off", dbg_lcd_power_off },
2262 #endif
2263 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2264 (defined(CPU_PP) && !defined(SANSA_E200))
2265 { "Dump ROM contents", dbg_save_roms },
2266 #endif
2267 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) || CONFIG_CPU == S3C2440
2268 { "View I/O ports", dbg_ports },
2269 #endif
2270 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2271 { "CPU frequency", dbg_cpufreq },
2272 #endif
2273 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2274 { "S/PDIF analyzer", dbg_spdif },
2275 #endif
2276 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2277 { "Catch mem accesses", dbg_set_memory_guard },
2278 #endif
2279 #ifndef SIMULATOR
2280 { "View OS stacks", dbg_os },
2281 #endif
2282 #ifdef HAVE_LCD_BITMAP
2283 #ifndef SIMULATOR
2284 { "View battery", view_battery },
2285 #endif
2286 { "Screendump", dbg_screendump },
2287 #endif
2288 #ifndef SIMULATOR
2289 { "View HW info", dbg_hw_info },
2290 #endif
2291 #ifndef SIMULATOR
2292 { "View partitions", dbg_partitions },
2293 #endif
2294 #ifndef SIMULATOR
2295 #if defined(HAVE_MMC)
2296 { "View MMC info", dbg_card_info },
2297 #elif defined(HAVE_HOTSWAP)
2298 { "View microSD info", dbg_card_info },
2299 #else
2300 { "View disk info", dbg_disk_info },
2301 #endif
2302 #endif
2303 #ifdef HAVE_DIRCACHE
2304 { "View dircache info", dbg_dircache_info },
2305 #endif
2306 #ifdef HAVE_TAGCACHE
2307 { "View database info", dbg_tagcache_info },
2308 #endif
2309 #ifdef HAVE_LCD_BITMAP
2310 #if CONFIG_CODEC == SWCODEC || !defined(SIMULATOR)
2311 { "View audio thread", dbg_audio_thread },
2312 #endif
2313 #ifdef PM_DEBUG
2314 { "pm histogram", peak_meter_histogram},
2315 #endif /* PM_DEBUG */
2316 #endif /* HAVE_LCD_BITMAP */
2317 #ifndef SIMULATOR
2318 #if CONFIG_TUNER
2319 { "FM Radio", dbg_fm_radio },
2320 #endif
2321 #endif
2322 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2323 { "Write back EEPROM", dbg_write_eeprom },
2324 #endif
2325 #ifdef ROCKBOX_HAS_LOGF
2326 {"logf", logfdisplay },
2327 {"logfdump", logfdump },
2328 #endif
2329 #ifdef CPU_BOOST_LOGGING
2330 {"cpu_boost log",cpu_boost_log},
2331 #endif
2333 static int menu_action_callback(int btn, struct gui_synclist *lists)
2335 if (btn == ACTION_STD_OK)
2337 menuitems[gui_synclist_get_sel_pos(lists)].function();
2338 gui_synclist_draw(lists);
2340 return btn;
2342 static char* dbg_menu_getname(int item, void * data, char *buffer)
2344 (void)data; (void)buffer;
2345 return menuitems[item].desc;
2347 bool debug_menu(void)
2349 dbg_list("Debug Menu",ARRAYLEN(menuitems) , 1,
2350 menu_action_callback,
2351 dbg_menu_getname);
2352 return false;