Factor out the duplicate code from bufadvance in rebuffer_handle()
[Rockbox.git] / apps / debug_menu.c
blobde4022675860d13f8733eadc5ef9763ee5522d62
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 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
79 #include "spdif.h"
80 #endif
81 #endif
82 #ifdef IRIVER_H300_SERIES
83 #include "pcf50606.h" /* for pcf50606_read */
84 #endif
85 #ifdef IAUDIO_X5
86 #include "ds2411.h"
87 #endif
88 #include "hwcompat.h"
90 /*---------------------------------------------------*/
91 /* SPECIAL DEBUG STUFF */
92 /*---------------------------------------------------*/
93 extern struct thread_entry threads[MAXTHREADS];
95 static char thread_status_char(unsigned status)
97 static const char thread_status_chars[THREAD_NUM_STATES+1] =
99 [0 ... THREAD_NUM_STATES] = '?',
100 [STATE_RUNNING] = 'R',
101 [STATE_BLOCKED] = 'B',
102 [STATE_SLEEPING] = 'S',
103 [STATE_BLOCKED_W_TMO] = 'T',
104 [STATE_FROZEN] = 'F',
105 [STATE_KILLED] = 'K',
108 #if NUM_CORES > 1
109 if (status == STATE_BUSY) /* Not a state index */
110 return '.';
111 #endif
113 if (status > THREAD_NUM_STATES)
114 status = THREAD_NUM_STATES;
116 return thread_status_chars[status];
119 static char* threads_getname(int selected_item, void * data, char *buffer)
121 (void)data;
122 char name[32];
123 struct thread_entry *thread = NULL;
124 unsigned status;
125 int usage;
127 #if NUM_CORES > 1
128 if (selected_item < (int)NUM_CORES)
130 usage = idle_stack_usage(selected_item);
131 snprintf(buffer, MAX_PATH, "Idle (%d): %2d%%", selected_item, usage);
132 return buffer;
135 selected_item -= NUM_CORES;
136 #endif
138 thread = &threads[selected_item];
139 status = thread_get_status(thread);
141 if (status == STATE_KILLED)
143 snprintf(buffer, MAX_PATH, "%2d: ---", selected_item);
144 return buffer;
147 thread_get_name(name, 32, thread);
148 usage = thread_stack_usage(thread);
150 snprintf(buffer, MAX_PATH,
151 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d ") "%2d%% %s",
152 selected_item,
153 IF_COP(thread->core,)
154 (status == STATE_RUNNING) ? '*' : ' ',
155 thread_status_char(status),
156 IF_PRIO(thread->priority,)
157 usage, name);
159 return buffer;
161 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
163 (void)lists;
164 #ifdef ROCKBOX_HAS_LOGF
165 if (action == ACTION_STD_OK)
167 int selpos = gui_synclist_get_sel_pos(lists);
168 #if NUM_CORES > 1
169 if (selpos >= NUM_CORES)
170 remove_thread(&threads[selpos - NUM_CORES]);
171 #else
172 remove_thread(&threads[selpos]);
173 #endif
174 return ACTION_REDRAW;
176 #endif /* ROCKBOX_HAS_LOGF */
177 return action;
179 /* Test code!!! */
180 static bool dbg_os(void)
182 struct simplelist_info info;
183 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
184 #if NUM_CORES == 1
185 MAXTHREADS,
186 #else
187 MAXTHREADS+NUM_CORES,
188 #endif
189 NULL);
190 #ifndef ROCKBOX_HAS_LOGF
191 info.hide_selection = true;
192 #endif
193 info.action_callback = dbg_threads_action_callback;
194 info.get_name = threads_getname;
195 return simplelist_show_list(&info);
198 #ifdef HAVE_LCD_BITMAP
199 #if CONFIG_CODEC != SWCODEC
200 #ifndef SIMULATOR
201 static bool dbg_audio_thread(void)
203 char buf[32];
204 struct audio_debug d;
206 lcd_setmargins(0, 0);
207 lcd_setfont(FONT_SYSFIXED);
209 while(1)
211 if (action_userabort(HZ/5))
212 return false;
214 audio_get_debugdata(&d);
216 lcd_clear_display();
218 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
219 lcd_puts(0, 0, buf);
220 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
221 lcd_puts(0, 1, buf);
222 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
223 lcd_puts(0, 2, buf);
224 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
225 lcd_puts(0, 3, buf);
226 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
227 lcd_puts(0, 4, buf);
228 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
229 lcd_puts(0, 5, buf);
231 /* Playable space left */
232 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
233 d.playable_space, HORIZONTAL);
235 /* Show the watermark limit */
236 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
237 d.low_watermark_level, HORIZONTAL);
239 snprintf(buf, sizeof(buf), "wm: %x - %x",
240 d.low_watermark_level, d.lowest_watermark_level);
241 lcd_puts(0, 7, buf);
243 lcd_update();
245 return false;
247 #endif /* !SIMULATOR */
248 #else /* CONFIG_CODEC == SWCODEC */
249 extern size_t filebuflen;
250 /* This is a size_t, but call it a long so it puts a - when it's bad. */
252 static unsigned int ticks, boost_ticks;
254 static void dbg_audio_task(void)
256 #ifndef SIMULATOR
257 if(FREQ > CPUFREQ_NORMAL)
258 boost_ticks++;
259 #endif
261 ticks++;
264 static bool dbg_audio_thread(void)
266 char buf[32];
267 int button;
268 int line;
269 bool done = false;
270 size_t bufused;
271 size_t bufsize = pcmbuf_get_bufsize();
272 int pcmbufdescs = pcmbuf_descs();
274 ticks = boost_ticks = 0;
276 tick_add_task(dbg_audio_task);
278 lcd_setmargins(0, 0);
279 lcd_setfont(FONT_SYSFIXED);
280 while(!done)
282 button = get_action(CONTEXT_STD,HZ/5);
283 switch(button)
285 case ACTION_STD_NEXT:
286 audio_next();
287 break;
288 case ACTION_STD_PREV:
289 audio_prev();
290 break;
291 case ACTION_STD_CANCEL:
292 done = true;
293 break;
295 line = 0;
296 lcd_clear_display();
298 bufused = bufsize - pcmbuf_free();
300 snprintf(buf, sizeof(buf), "pcm: %7ld/%7ld", (long) bufused, (long) bufsize);
301 lcd_puts(0, line++, buf);
303 /* Playable space left */
304 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6, bufsize, 0, bufused, HORIZONTAL);
305 line++;
307 snprintf(buf, sizeof(buf), "codec: %8ld/%8ld", audio_filebufused(), (long) filebuflen);
308 lcd_puts(0, line++, buf);
310 /* Playable space left */
311 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6, filebuflen, 0,
312 audio_filebufused(), HORIZONTAL);
313 line++;
315 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
316 lcd_puts(0, line++, buf);
318 #ifndef SIMULATOR
319 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
320 (int)((FREQ + 500000) / 1000000));
321 lcd_puts(0, line++, buf);
322 #endif
324 if (ticks > 0)
326 snprintf(buf, sizeof(buf), "boost ratio: %3d%%",
327 boost_ticks * 100 / ticks);
328 lcd_puts(0, line++, buf);
331 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
332 pcmbuf_used_descs(), pcmbufdescs);
333 lcd_puts(0, line++, buf);
335 lcd_update();
338 tick_remove_task(dbg_audio_task);
340 return false;
342 #endif /* CONFIG_CODEC */
343 #endif /* HAVE_LCD_BITMAP */
346 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
347 /* Tool function to read the flash manufacturer and type, if available.
348 Only chips which could be reprogrammed in system will return values.
349 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
350 /* In IRAM to avoid problems when running directly from Flash */
351 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
352 unsigned addr1, unsigned addr2)
353 ICODE_ATTR __attribute__((noinline));
354 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
355 unsigned addr1, unsigned addr2)
358 unsigned not_manu, not_id; /* read values before switching to ID mode */
359 unsigned manu, id; /* read values when in ID mode */
361 #if CONFIG_CPU == SH7034
362 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
363 #elif defined(CPU_COLDFIRE)
364 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
365 #endif
366 int old_level; /* saved interrupt level */
368 not_manu = flash[0]; /* read the normal content */
369 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
371 /* disable interrupts, prevent any stray flash access */
372 old_level = set_irq_level(HIGHEST_IRQ_LEVEL);
374 flash[addr1] = 0xAA; /* enter command mode */
375 flash[addr2] = 0x55;
376 flash[addr1] = 0x90; /* ID command */
377 /* Atmel wants 20ms pause here */
378 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
380 manu = flash[0]; /* read the IDs */
381 id = flash[1];
383 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
384 /* Atmel wants 20ms pause here */
385 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
387 set_irq_level(old_level); /* enable interrupts again */
389 /* I assume success if the obtained values are different from
390 the normal flash content. This is not perfectly bulletproof, they
391 could theoretically be the same by chance, causing us to fail. */
392 if (not_manu != manu || not_id != id) /* a value has changed */
394 *p_manufacturer = manu; /* return the results */
395 *p_device = id;
396 return true; /* success */
398 return false; /* fail */
400 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
402 #ifndef SIMULATOR
403 #ifdef CPU_PP
404 static int perfcheck(void)
406 int result;
408 asm (
409 "mrs r2, CPSR \n"
410 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
411 "msr CPSR_c, r0 \n"
412 "mov %[res], #0 \n"
413 "ldr r0, [%[timr]] \n"
414 "add r0, r0, %[tmo] \n"
415 "1: \n"
416 "add %[res], %[res], #1 \n"
417 "ldr r1, [%[timr]] \n"
418 "cmp r1, r0 \n"
419 "bmi 1b \n"
420 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
422 [res]"=&r"(result)
424 [timr]"r"(&USEC_TIMER),
425 [tmo]"r"(
426 #if CONFIG_CPU == PP5002
427 16000
428 #else /* PP5020/5022/5024 */
429 10226
430 #endif
433 "r0", "r1", "r2"
435 return result;
437 #endif
439 #ifdef HAVE_LCD_BITMAP
440 static bool dbg_hw_info(void)
442 #if CONFIG_CPU == SH7034
443 char buf[32];
444 int bitmask = HW_MASK;
445 int rom_version = ROM_VERSION;
446 unsigned manu, id; /* flash IDs */
447 bool got_id; /* flag if we managed to get the flash IDs */
448 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
449 bool has_bootrom; /* flag for boot ROM present */
450 int oldmode; /* saved memory guard mode */
452 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
454 /* get flash ROM type */
455 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
456 if (!got_id)
457 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
459 /* check if the boot ROM area is a flash mirror */
460 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
461 if (has_bootrom) /* if ROM and Flash different */
463 /* calculate CRC16 checksum of boot ROM */
464 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
467 system_memory_guard(oldmode); /* re-enable memory guard */
469 lcd_setmargins(0, 0);
470 lcd_setfont(FONT_SYSFIXED);
471 lcd_clear_display();
473 lcd_puts(0, 0, "[Hardware info]");
475 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
476 lcd_puts(0, 1, buf);
478 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
479 lcd_puts(0, 2, buf);
481 if (got_id)
482 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
483 else
484 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
485 lcd_puts(0, 3, buf);
487 if (has_bootrom)
489 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
490 snprintf(buf, 32, "Boot ROM: V1");
491 else
492 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
494 else
496 snprintf(buf, 32, "Boot ROM: none");
498 lcd_puts(0, 4, buf);
500 lcd_update();
502 while (!(action_userabort(TIMEOUT_BLOCK)));
504 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
505 char buf[32];
506 unsigned manu, id; /* flash IDs */
507 int got_id; /* flag if we managed to get the flash IDs */
508 int oldmode; /* saved memory guard mode */
509 int line = 0;
511 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
513 /* get flash ROM type */
514 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
515 if (!got_id)
516 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
518 system_memory_guard(oldmode); /* re-enable memory guard */
520 lcd_setmargins(0, 0);
521 lcd_setfont(FONT_SYSFIXED);
522 lcd_clear_display();
524 lcd_puts(0, line++, "[Hardware info]");
526 if (got_id)
527 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
528 else
529 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
530 lcd_puts(0, line++, buf);
532 #ifdef IAUDIO_X5
534 struct ds2411_id id;
536 lcd_puts(0, ++line, "Serial Number:");
538 got_id = ds2411_read_id(&id);
540 if (got_id == DS2411_OK)
542 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
543 lcd_puts(0, ++line, buf);
544 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
545 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
546 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
547 lcd_puts(0, ++line, buf);
548 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
550 else
552 snprintf(buf, 32, "READ ERR=%d", got_id);
555 lcd_puts(0, ++line, buf);
557 #endif
559 lcd_update();
561 while (!(action_userabort(TIMEOUT_BLOCK)));
563 #elif defined(CPU_PP502x)
564 int line = 0;
565 char buf[32];
566 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
567 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
568 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
569 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
571 lcd_setmargins(0, 0);
572 lcd_setfont(FONT_SYSFIXED);
573 lcd_clear_display();
575 lcd_puts(0, line++, "[Hardware info]");
577 #ifdef IPOD_ARCH
578 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
579 lcd_puts(0, line++, buf);
580 #endif
582 #ifdef IPOD_COLOR
583 extern int lcd_type; /* Defined in lcd-colornano.c */
585 snprintf(buf, sizeof(buf), "LCD type: %d", lcd_type);
586 lcd_puts(0, line++, buf);
587 #endif
589 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
590 lcd_puts(0, line++, buf);
592 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
593 lcd_puts(0, line++, buf);
595 lcd_update();
597 while (!(action_userabort(TIMEOUT_BLOCK)));
599 #elif CONFIG_CPU == PP5002
600 int line = 0;
601 char buf[32];
603 lcd_setmargins(0, 0);
604 lcd_setfont(FONT_SYSFIXED);
605 lcd_clear_display();
607 lcd_puts(0, line++, "[Hardware info]");
609 #ifdef IPOD_ARCH
610 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
611 lcd_puts(0, line++, buf);
612 #endif
614 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
615 lcd_puts(0, line++, buf);
617 lcd_update();
619 while (!(action_userabort(TIMEOUT_BLOCK)));
621 #endif /* CONFIG_CPU */
622 return false;
624 #else /* !HAVE_LCD_BITMAP */
625 static bool dbg_hw_info(void)
627 char buf[32];
628 int button;
629 int currval = 0;
630 int rom_version = ROM_VERSION;
631 unsigned manu, id; /* flash IDs */
632 bool got_id; /* flag if we managed to get the flash IDs */
633 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
634 bool has_bootrom; /* flag for boot ROM present */
635 int oldmode; /* saved memory guard mode */
637 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
639 /* get flash ROM type */
640 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
641 if (!got_id)
642 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
644 /* check if the boot ROM area is a flash mirror */
645 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
646 if (has_bootrom) /* if ROM and Flash different */
648 /* calculate CRC16 checksum of boot ROM */
649 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
652 system_memory_guard(oldmode); /* re-enable memory guard */
654 lcd_clear_display();
656 lcd_puts(0, 0, "[HW Info]");
657 while(1)
659 switch(currval)
661 case 0:
662 snprintf(buf, 32, "ROM: %d.%02d",
663 rom_version/100, rom_version%100);
664 break;
665 case 1:
666 if (got_id)
667 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
668 else
669 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
670 break;
671 case 2:
672 if (has_bootrom)
674 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
675 snprintf(buf, 32, "BootROM: V1");
676 else if (rom_crc == 0x358099E8)
677 snprintf(buf, 32, "BootROM: V2");
678 /* alternative boot ROM found in one single player so far */
679 else
680 snprintf(buf, 32, "R: %08x", rom_crc);
682 else
683 snprintf(buf, 32, "BootROM: no");
686 lcd_puts(0, 1, buf);
687 lcd_update();
689 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
691 switch(button)
693 case ACTION_STD_CANCEL:
694 return false;
696 case ACTION_SETTINGS_DEC:
697 currval--;
698 if(currval < 0)
699 currval = 2;
700 break;
702 case ACTION_SETTINGS_INC:
703 currval++;
704 if(currval > 2)
705 currval = 0;
706 break;
709 return false;
711 #endif /* !HAVE_LCD_BITMAP */
712 #endif /* !SIMULATOR */
714 #ifndef SIMULATOR
715 static char* dbg_partitions_getname(int selected_item, void * data, char *buffer)
717 (void)data;
718 int partition = selected_item/2;
719 struct partinfo* p = disk_partinfo(partition);
720 if (selected_item%2)
722 snprintf(buffer, MAX_PATH, " T:%x %ld MB", p->type, p->size / 2048);
724 else
726 snprintf(buffer, MAX_PATH, "P%d: S:%lx", partition, p->start);
728 return buffer;
731 bool dbg_partitions(void)
733 struct simplelist_info info;
734 simplelist_info_init(&info, "Partition Info", 4, NULL);
735 info.selection_size = 2;
736 info.hide_selection = true;
737 info.get_name = dbg_partitions_getname;
738 return simplelist_show_list(&info);
740 #endif
742 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
743 static bool dbg_spdif(void)
745 char buf[128];
746 int line;
747 unsigned int control;
748 int x;
749 char *s;
750 int category;
751 int generation;
752 unsigned int interruptstat;
753 bool valnogood, symbolerr, parityerr;
754 bool done = false;
755 bool spdif_src_on;
756 int spdif_source = spdif_get_output_source(&spdif_src_on);
757 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
759 lcd_setmargins(0, 0);
760 lcd_clear_display();
761 lcd_setfont(FONT_SYSFIXED);
763 #ifdef HAVE_SPDIF_POWER
764 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
765 #endif
767 while (!done)
769 line = 0;
771 control = EBU1RCVCCHANNEL1;
772 interruptstat = INTERRUPTSTAT;
773 INTERRUPTCLEAR = 0x03c00000;
775 valnogood = (interruptstat & 0x01000000)?true:false;
776 symbolerr = (interruptstat & 0x00800000)?true:false;
777 parityerr = (interruptstat & 0x00400000)?true:false;
779 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
780 valnogood?"--":"OK",
781 symbolerr?"--":"OK",
782 parityerr?"--":"OK");
783 lcd_puts(0, line++, buf);
785 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
786 lcd_puts(0, line++, buf);
788 line++;
790 x = control >> 31;
791 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
792 x, x?"Professional":"Consumer");
793 lcd_puts(0, line++, buf);
795 x = (control >> 30) & 1;
796 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
797 x, x?"Non-PCM":"PCM");
798 lcd_puts(0, line++, buf);
800 x = (control >> 29) & 1;
801 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
802 x, x?"Permitted":"Inhibited");
803 lcd_puts(0, line++, buf);
805 x = (control >> 27) & 7;
806 switch(x)
808 case 0:
809 s = "None";
810 break;
811 case 1:
812 s = "50/15us";
813 break;
814 default:
815 s = "Reserved";
816 break;
818 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
819 lcd_puts(0, line++, buf);
821 x = (control >> 24) & 3;
822 snprintf(buf, sizeof(buf), "Mode: %d", x);
823 lcd_puts(0, line++, buf);
825 category = (control >> 17) & 127;
826 switch(category)
828 case 0x00:
829 s = "General";
830 break;
831 case 0x40:
832 s = "Audio CD";
833 break;
834 default:
835 s = "Unknown";
837 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
838 lcd_puts(0, line++, buf);
840 x = (control >> 16) & 1;
841 generation = x;
842 if(((category & 0x70) == 0x10) ||
843 ((category & 0x70) == 0x40) ||
844 ((category & 0x78) == 0x38))
846 generation = !generation;
848 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
849 x, generation?"Original":"No ind.");
850 lcd_puts(0, line++, buf);
852 x = (control >> 12) & 15;
853 snprintf(buf, sizeof(buf), "Source: %d", x);
854 lcd_puts(0, line++, buf);
856 x = (control >> 8) & 15;
857 switch(x)
859 case 0:
860 s = "Unspecified";
861 break;
862 case 8:
863 s = "A (Left)";
864 break;
865 case 4:
866 s = "B (Right)";
867 break;
868 default:
869 s = "";
870 break;
872 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
873 lcd_puts(0, line++, buf);
875 x = (control >> 4) & 15;
876 switch(x)
878 case 0:
879 s = "44.1kHz";
880 break;
881 case 0x4:
882 s = "48kHz";
883 break;
884 case 0xc:
885 s = "32kHz";
886 break;
888 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
889 lcd_puts(0, line++, buf);
891 x = (control >> 2) & 3;
892 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
893 lcd_puts(0, line++, buf);
894 line++;
896 #ifndef SIMULATOR
897 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
898 spdif_measure_frequency());
899 lcd_puts(0, line++, buf);
900 #endif
902 lcd_update();
904 if (action_userabort(HZ/10))
905 break;
908 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
910 #ifdef HAVE_SPDIF_POWER
911 spdif_power_enable(global_settings.spdif_enable);
912 #endif
914 return false;
916 #endif /* CPU_COLDFIRE */
918 #ifndef SIMULATOR
919 #ifdef HAVE_LCD_BITMAP
920 /* button definitions */
921 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
922 (CONFIG_KEYPAD == IRIVER_H300_PAD)
923 # define DEBUG_CANCEL BUTTON_OFF
925 #elif CONFIG_KEYPAD == RECORDER_PAD
926 # define DEBUG_CANCEL BUTTON_OFF
928 #elif CONFIG_KEYPAD == ONDIO_PAD
929 # define DEBUG_CANCEL BUTTON_MENU
931 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
932 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
933 (CONFIG_KEYPAD == IPOD_4G_PAD)
934 # define DEBUG_CANCEL BUTTON_MENU
936 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
937 # define DEBUG_CANCEL BUTTON_PLAY
939 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
940 # define DEBUG_CANCEL BUTTON_REC
942 #elif CONFIG_KEYPAD == GIGABEAT_PAD
943 # define DEBUG_CANCEL BUTTON_A
945 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
946 # define DEBUG_CANCEL BUTTON_REW
948 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
949 (CONFIG_KEYPAD == SANSA_C200_PAD)
950 # define DEBUG_CANCEL BUTTON_LEFT
951 #endif /* key definitios */
953 /* Test code!!! */
954 bool dbg_ports(void)
956 #if CONFIG_CPU == SH7034
957 unsigned short porta;
958 unsigned short portb;
959 unsigned char portc;
960 char buf[32];
961 int adc_battery_voltage, adc_battery_level;
963 lcd_setfont(FONT_SYSFIXED);
964 lcd_setmargins(0, 0);
965 lcd_clear_display();
967 while(1)
969 porta = PADR;
970 portb = PBDR;
971 portc = PCDR;
973 snprintf(buf, 32, "PADR: %04x", porta);
974 lcd_puts(0, 0, buf);
975 snprintf(buf, 32, "PBDR: %04x", portb);
976 lcd_puts(0, 1, buf);
978 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
979 lcd_puts(0, 2, buf);
980 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
981 lcd_puts(0, 3, buf);
982 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
983 lcd_puts(0, 4, buf);
984 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
985 lcd_puts(0, 5, buf);
987 battery_read_info(&adc_battery_voltage, &adc_battery_level);
988 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
989 adc_battery_voltage % 1000, adc_battery_level);
990 lcd_puts(0, 6, buf);
992 lcd_update();
993 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
994 return false;
996 #elif defined(CPU_COLDFIRE)
997 unsigned int gpio_out;
998 unsigned int gpio1_out;
999 unsigned int gpio_read;
1000 unsigned int gpio1_read;
1001 unsigned int gpio_function;
1002 unsigned int gpio1_function;
1003 unsigned int gpio_enable;
1004 unsigned int gpio1_enable;
1005 int adc_buttons, adc_remote;
1006 int adc_battery_voltage, adc_battery_level;
1007 char buf[128];
1008 int line;
1010 lcd_setmargins(0, 0);
1011 lcd_clear_display();
1012 lcd_setfont(FONT_SYSFIXED);
1014 while(1)
1016 line = 0;
1017 gpio_read = GPIO_READ;
1018 gpio1_read = GPIO1_READ;
1019 gpio_out = GPIO_OUT;
1020 gpio1_out = GPIO1_OUT;
1021 gpio_function = GPIO_FUNCTION;
1022 gpio1_function = GPIO1_FUNCTION;
1023 gpio_enable = GPIO_ENABLE;
1024 gpio1_enable = GPIO1_ENABLE;
1026 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1027 lcd_puts(0, line++, buf);
1028 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1029 lcd_puts(0, line++, buf);
1030 snprintf(buf, sizeof(buf), "GPIO_FUNCTION: %08x", gpio_function);
1031 lcd_puts(0, line++, buf);
1032 snprintf(buf, sizeof(buf), "GPIO_ENABLE: %08x", gpio_enable);
1033 lcd_puts(0, line++, buf);
1035 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1036 lcd_puts(0, line++, buf);
1037 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1038 lcd_puts(0, line++, buf);
1039 snprintf(buf, sizeof(buf), "GPIO1_FUNCTION: %08x", gpio1_function);
1040 lcd_puts(0, line++, buf);
1041 snprintf(buf, sizeof(buf), "GPIO1_ENABLE: %08x", gpio1_enable);
1042 lcd_puts(0, line++, buf);
1044 adc_buttons = adc_read(ADC_BUTTONS);
1045 adc_remote = adc_read(ADC_REMOTE);
1046 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1047 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1048 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1049 button_scan_enabled() ? '+' : '-', adc_buttons);
1050 #else
1051 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1052 #endif
1053 lcd_puts(0, line++, buf);
1054 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1055 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1056 remote_detect() ? '+' : '-', adc_remote);
1057 #else
1058 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1059 #endif
1060 lcd_puts(0, line++, buf);
1061 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1062 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1063 adc_read(ADC_REMOTEDETECT));
1064 lcd_puts(0, line++, buf);
1065 #endif
1067 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1068 adc_battery_voltage % 1000, adc_battery_level);
1069 lcd_puts(0, line++, buf);
1071 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1072 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1073 lcd_puts(0, line++, buf);
1074 #endif
1076 lcd_update();
1077 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1078 return false;
1081 #elif defined(CPU_PP502x)
1083 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1084 unsigned int gpio_e, gpio_f, gpio_g, gpio_h;
1085 unsigned int gpio_i, gpio_j, gpio_k, gpio_l;
1087 char buf[128];
1088 int line;
1090 lcd_setmargins(0, 0);
1091 lcd_clear_display();
1092 lcd_setfont(FONT_SYSFIXED);
1094 while(1)
1096 gpio_a = GPIOA_INPUT_VAL;
1097 gpio_b = GPIOB_INPUT_VAL;
1098 gpio_c = GPIOC_INPUT_VAL;
1100 gpio_g = GPIOG_INPUT_VAL;
1101 gpio_h = GPIOH_INPUT_VAL;
1102 gpio_i = GPIOI_INPUT_VAL;
1104 line = 0;
1105 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_G: %02x", gpio_a, gpio_g);
1106 lcd_puts(0, line++, buf);
1107 snprintf(buf, sizeof(buf), "GPIO_B: %02x GPIO_H: %02x", gpio_b, gpio_h);
1108 lcd_puts(0, line++, buf);
1109 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_I: %02x", gpio_c, gpio_i);
1110 lcd_puts(0, line++, buf);
1112 gpio_d = GPIOD_INPUT_VAL;
1113 gpio_e = GPIOE_INPUT_VAL;
1114 gpio_f = GPIOF_INPUT_VAL;
1116 gpio_j = GPIOJ_INPUT_VAL;
1117 gpio_k = GPIOK_INPUT_VAL;
1118 gpio_l = GPIOL_INPUT_VAL;
1120 snprintf(buf, sizeof(buf), "GPIO_D: %02x GPIO_J: %02x", gpio_d, gpio_j);
1121 lcd_puts(0, line++, buf);
1122 snprintf(buf, sizeof(buf), "GPIO_E: %02x GPIO_K: %02x", gpio_e, gpio_k);
1123 lcd_puts(0, line++, buf);
1124 snprintf(buf, sizeof(buf), "GPIO_F: %02x GPIO_L: %02x", gpio_f, gpio_l);
1125 lcd_puts(0, line++, buf);
1126 line++;
1128 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1129 lcd_puts(0, line++, buf);
1130 snprintf(buf, sizeof(buf), "CLOCK_SRC: %08lx", CLOCK_SOURCE);
1131 lcd_puts(0, line++, buf);
1132 snprintf(buf, sizeof(buf), "CLCD_CLK_SRC: %08lx", CLCD_CLOCK_SRC);
1133 lcd_puts(0, line++, buf);
1134 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1135 lcd_puts(0, line++, buf);
1136 snprintf(buf, sizeof(buf), "PLL_STATUS: %08lx", PLL_STATUS);
1137 lcd_puts(0, line++, buf);
1138 snprintf(buf, sizeof(buf), "DEV_TIMING1: %08lx", DEV_TIMING1);
1139 lcd_puts(0, line++, buf);
1141 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1142 line++;
1143 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x", adc_read(ADC_BATTERY),
1144 adc_read(ADC_UNKNOWN_1));
1145 lcd_puts(0, line++, buf);
1146 snprintf(buf, sizeof(buf), "REM: %03x PAD: %03x", adc_read(ADC_REMOTE),
1147 adc_read(ADC_SCROLLPAD));
1148 lcd_puts(0, line++, buf);
1149 #elif defined(SANSA_E200)
1150 line++;
1151 snprintf(buf, sizeof(buf), "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1152 lcd_puts(0, line++, buf);
1153 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1154 lcd_puts(0, line++, buf);
1155 snprintf(buf, sizeof(buf), "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1156 lcd_puts(0, line++, buf);
1157 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1158 lcd_puts(0, line++, buf);
1159 snprintf(buf, sizeof(buf), "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1160 lcd_puts(0, line++, buf);
1161 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1162 lcd_puts(0, line++, buf);
1163 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1164 lcd_puts(0, line++, buf);
1165 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1166 lcd_puts(0, line++, buf);
1167 snprintf(buf, sizeof(buf), "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1168 lcd_puts(0, line++, buf);
1169 snprintf(buf, sizeof(buf), "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1170 lcd_puts(0, line++, buf);
1171 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1172 lcd_puts(0, line++, buf);
1173 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1174 lcd_puts(0, line++, buf);
1175 snprintf(buf, sizeof(buf), "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1176 lcd_puts(0, line++, buf);
1177 #endif
1178 lcd_update();
1179 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1180 return false;
1183 #elif CONFIG_CPU == PP5002
1184 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1186 char buf[128];
1187 int line;
1189 lcd_setmargins(0, 0);
1190 lcd_clear_display();
1191 lcd_setfont(FONT_SYSFIXED);
1193 while(1)
1195 gpio_a = GPIOA_INPUT_VAL;
1196 gpio_b = GPIOB_INPUT_VAL;
1197 gpio_c = GPIOC_INPUT_VAL;
1198 gpio_d = GPIOD_INPUT_VAL;
1200 line = 0;
1201 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x", gpio_a, gpio_b);
1202 lcd_puts(0, line++, buf);
1203 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x", gpio_c, gpio_d);
1204 lcd_puts(0, line++, buf);
1206 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1207 lcd_puts(0, line++, buf);
1208 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1209 lcd_puts(0, line++, buf);
1210 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1211 lcd_puts(0, line++, buf);
1212 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1213 lcd_puts(0, line++, buf);
1214 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1215 lcd_puts(0, line++, buf);
1216 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1217 lcd_puts(0, line++, buf);
1218 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1219 lcd_puts(0, line++, buf);
1220 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1221 lcd_puts(0, line++, buf);
1223 lcd_update();
1224 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1225 return false;
1227 #elif CONFIG_CPU == S3C2440
1228 char buf[50];
1229 int line;
1231 lcd_setmargins(0, 0);
1232 lcd_clear_display();
1233 lcd_setfont(FONT_SYSFIXED);
1235 while(1)
1237 line = 0;
1238 snprintf(buf, sizeof(buf), "[Ports and Registers]"); lcd_puts(0, line++, buf);
1240 snprintf(buf, sizeof(buf), "GPACON: %08x GPBCON: %08x", GPACON, GPBCON); lcd_puts(0, line++, buf);
1241 snprintf(buf, sizeof(buf), "GPADAT: %08x GPBDAT: %08x", GPADAT, GPBDAT); lcd_puts(0, line++, buf);
1242 snprintf(buf, sizeof(buf), "GPAUP: %08x GPBUP: %08x", 0, GPBUP); lcd_puts(0, line++, buf);
1243 snprintf(buf, sizeof(buf), "GPCCON: %08x GPDCON: %08x", GPCCON, GPDCON); lcd_puts(0, line++, buf);
1244 snprintf(buf, sizeof(buf), "GPCDAT: %08x GPDDAT: %08x", GPCDAT, GPDDAT); lcd_puts(0, line++, buf);
1245 snprintf(buf, sizeof(buf), "GPCUP: %08x GPDUP: %08x", GPCUP, GPDUP); lcd_puts(0, line++, buf);
1247 snprintf(buf, sizeof(buf), "GPCCON: %08x GPDCON: %08x", GPCCON, GPDCON); lcd_puts(0, line++, buf);
1248 snprintf(buf, sizeof(buf), "GPCDAT: %08x GPDDAT: %08x", GPCDAT, GPDDAT); lcd_puts(0, line++, buf);
1249 snprintf(buf, sizeof(buf), "GPCUP: %08x GPDUP: %08x", GPCUP, GPDUP); lcd_puts(0, line++, buf);
1251 snprintf(buf, sizeof(buf), "GPECON: %08x GPFCON: %08x", GPECON, GPFCON); lcd_puts(0, line++, buf);
1252 snprintf(buf, sizeof(buf), "GPEDAT: %08x GPFDAT: %08x", GPEDAT, GPFDAT); lcd_puts(0, line++, buf);
1253 snprintf(buf, sizeof(buf), "GPEUP: %08x GPFUP: %08x", GPEUP, GPFUP); lcd_puts(0, line++, buf);
1255 snprintf(buf, sizeof(buf), "GPGCON: %08x GPHCON: %08x", GPGCON, GPHCON); lcd_puts(0, line++, buf);
1256 snprintf(buf, sizeof(buf), "GPGDAT: %08x GPHDAT: %08x", GPGDAT, GPHDAT); lcd_puts(0, line++, buf);
1257 snprintf(buf, sizeof(buf), "GPGUP: %08x GPHUP: %08x", GPGUP, GPHUP); lcd_puts(0, line++, buf);
1259 snprintf(buf, sizeof(buf), "GPJCON: %08x", GPJCON); lcd_puts(0, line++, buf);
1260 snprintf(buf, sizeof(buf), "GPJDAT: %08x", GPJDAT); lcd_puts(0, line++, buf);
1261 snprintf(buf, sizeof(buf), "GPJUP: %08x", GPJUP); lcd_puts(0, line++, buf);
1263 line++;
1265 snprintf(buf, sizeof(buf), "SRCPND: %08x INTMOD: %08x", SRCPND, INTMOD); lcd_puts(0, line++, buf);
1266 snprintf(buf, sizeof(buf), "INTMSK: %08x INTPND: %08x", INTMSK, INTPND); lcd_puts(0, line++, buf);
1267 snprintf(buf, sizeof(buf), "CLKCON: %08x CLKSLOW: %08x", CLKCON, CLKSLOW); lcd_puts(0, line++, buf);
1268 snprintf(buf, sizeof(buf), "MPLLCON: %08x UPLLCON: %08x", MPLLCON, UPLLCON); lcd_puts(0, line++, buf);
1269 snprintf(buf, sizeof(buf), "CLKDIVN: %08x", CLKDIVN); lcd_puts(0, line++, buf);
1271 lcd_update();
1272 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1273 return false;
1275 #endif /* CPU */
1276 return false;
1278 #else /* !HAVE_LCD_BITMAP */
1279 bool dbg_ports(void)
1281 unsigned short porta;
1282 unsigned short portb;
1283 unsigned char portc;
1284 char buf[32];
1285 int button;
1286 int adc_battery_voltage;
1287 int currval = 0;
1289 lcd_clear_display();
1291 while(1)
1293 porta = PADR;
1294 portb = PBDR;
1295 portc = PCDR;
1297 switch(currval)
1299 case 0:
1300 snprintf(buf, 32, "PADR: %04x", porta);
1301 break;
1302 case 1:
1303 snprintf(buf, 32, "PBDR: %04x", portb);
1304 break;
1305 case 2:
1306 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1307 break;
1308 case 3:
1309 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1310 break;
1311 case 4:
1312 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1313 break;
1314 case 5:
1315 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1316 break;
1317 case 6:
1318 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1319 break;
1320 case 7:
1321 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1322 break;
1323 case 8:
1324 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1325 break;
1326 case 9:
1327 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1328 break;
1329 break;
1331 lcd_puts(0, 0, buf);
1333 battery_read_info(&adc_battery_voltage, NULL);
1334 snprintf(buf, 32, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1335 adc_battery_voltage % 1000);
1336 lcd_puts(0, 1, buf);
1337 lcd_update();
1339 button = get_action(CONTEXT_SETTINGS,HZ/5);
1341 switch(button)
1343 case ACTION_STD_CANCEL:
1344 return false;
1346 case ACTION_SETTINGS_DEC:
1347 currval--;
1348 if(currval < 0)
1349 currval = 9;
1350 break;
1352 case ACTION_SETTINGS_INC:
1353 currval++;
1354 if(currval > 9)
1355 currval = 0;
1356 break;
1359 return false;
1361 #endif /* !HAVE_LCD_BITMAP */
1362 #endif /* !SIMULATOR */
1364 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1365 static bool dbg_cpufreq(void)
1367 char buf[128];
1368 int line;
1369 int button;
1371 #ifdef HAVE_LCD_BITMAP
1372 lcd_setmargins(0, 0);
1373 lcd_setfont(FONT_SYSFIXED);
1374 #endif
1375 lcd_clear_display();
1377 while(1)
1379 line = 0;
1381 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1382 lcd_puts(0, line++, buf);
1384 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1385 lcd_puts(0, line++, buf);
1387 lcd_update();
1388 button = get_action(CONTEXT_STD,HZ/10);
1390 switch(button)
1392 case ACTION_STD_PREV:
1393 cpu_boost(true);
1394 break;
1396 case ACTION_STD_NEXT:
1397 cpu_boost(false);
1398 break;
1400 case ACTION_STD_OK:
1401 while (get_cpu_boost_counter() > 0)
1402 cpu_boost(false);
1403 set_cpu_frequency(CPUFREQ_DEFAULT);
1404 break;
1406 case ACTION_STD_CANCEL:
1407 return false;
1411 return false;
1413 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1415 #ifndef SIMULATOR
1416 #ifdef HAVE_LCD_BITMAP
1418 * view_battery() shows a automatically scaled graph of the battery voltage
1419 * over time. Usable for estimating battery life / charging rate.
1420 * The power_history array is updated in power_thread of powermgmt.c.
1423 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1424 #define BAT_YSPACE (LCD_HEIGHT - 20)
1426 static bool view_battery(void)
1428 int view = 0;
1429 int i, x, y;
1430 unsigned short maxv, minv;
1431 char buf[32];
1433 lcd_setmargins(0, 0);
1434 lcd_setfont(FONT_SYSFIXED);
1436 while(1)
1438 lcd_clear_display();
1439 switch (view) {
1440 case 0: /* voltage history graph */
1441 /* Find maximum and minimum voltage for scaling */
1442 minv = power_history[0];
1443 maxv = minv + 1;
1444 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1445 if (power_history[i] > maxv)
1446 maxv = power_history[i];
1447 if (power_history[i] < minv)
1448 minv = power_history[i];
1451 snprintf(buf, 30, "Battery %d.%03d", power_history[0] / 1000,
1452 power_history[0] % 1000);
1453 lcd_puts(0, 0, buf);
1454 snprintf(buf, 30, "scale %d.%03d-%d.%03dV",
1455 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1456 lcd_puts(0, 1, buf);
1458 x = 0;
1459 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1460 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1461 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1462 lcd_vline(x, LCD_HEIGHT-1, 20);
1463 lcd_set_drawmode(DRMODE_SOLID);
1464 lcd_vline(x, LCD_HEIGHT-1,
1465 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1466 x++;
1469 break;
1471 case 1: /* status: */
1472 lcd_puts(0, 0, "Power status:");
1474 battery_read_info(&y, NULL);
1475 snprintf(buf, 30, "Battery: %d.%03d V", y / 1000, y % 1000);
1476 lcd_puts(0, 1, buf);
1477 #ifdef ADC_EXT_POWER
1478 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1479 snprintf(buf, 30, "External: %d.%03d V", y / 1000, y % 1000);
1480 lcd_puts(0, 2, buf);
1481 #endif
1482 #if CONFIG_CHARGING
1483 #if CONFIG_CHARGING == CHARGING_CONTROL
1484 snprintf(buf, 30, "Chgr: %s %s",
1485 charger_inserted() ? "present" : "absent",
1486 charger_enabled ? "on" : "off");
1487 lcd_puts(0, 3, buf);
1488 snprintf(buf, 30, "short delta: %d", short_delta);
1489 lcd_puts(0, 5, buf);
1490 snprintf(buf, 30, "long delta: %d", long_delta);
1491 lcd_puts(0, 6, buf);
1492 lcd_puts(0, 7, power_message);
1493 snprintf(buf, 30, "USB Inserted: %s",
1494 usb_inserted() ? "yes" : "no");
1495 lcd_puts(0, 8, buf);
1496 #if defined IRIVER_H300_SERIES
1497 snprintf(buf, 30, "USB Charging Enabled: %s",
1498 usb_charging_enabled() ? "yes" : "no");
1499 lcd_puts(0, 9, buf);
1500 #endif
1501 #else /* CONFIG_CHARGING != CHARGING_CONTROL */
1502 #if defined IPOD_NANO || defined IPOD_VIDEO
1503 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1504 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1505 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1506 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1507 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1509 snprintf(buf, 30, "USB pwr: %s",
1510 usb_pwr ? "present" : "absent");
1511 lcd_puts(0, 3, buf);
1512 snprintf(buf, 30, "EXT pwr: %s",
1513 ext_pwr ? "present" : "absent");
1514 lcd_puts(0, 4, buf);
1515 snprintf(buf, 30, "Battery: %s",
1516 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1517 lcd_puts(0, 5, buf);
1518 snprintf(buf, 30, "Dock mode: %s",
1519 dock ? "enabled" : "disabled");
1520 lcd_puts(0, 6, buf);
1521 snprintf(buf, 30, "Headphone: %s",
1522 headphone ? "connected" : "disconnected");
1523 lcd_puts(0, 7, buf);
1524 #else
1525 snprintf(buf, 30, "Charger: %s",
1526 charger_inserted() ? "present" : "absent");
1527 lcd_puts(0, 3, buf);
1528 #endif
1529 #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1530 #endif /* CONFIG_CHARGING */
1531 break;
1533 case 2: /* voltage deltas: */
1534 lcd_puts(0, 0, "Voltage deltas:");
1536 for (i = 0; i <= 6; i++) {
1537 y = power_history[i] - power_history[i+1];
1538 snprintf(buf, 30, "-%d min: %s%d.%03d V", i,
1539 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1540 ((y < 0) ? y * -1 : y ) % 1000);
1541 lcd_puts(0, i+1, buf);
1543 break;
1545 case 3: /* remaining time estimation: */
1547 #if CONFIG_CHARGING == CHARGING_CONTROL
1548 snprintf(buf, 30, "charge_state: %d", charge_state);
1549 lcd_puts(0, 0, buf);
1551 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1552 lcd_puts(0, 1, buf);
1554 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1555 lcd_puts(0, 2, buf);
1557 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1558 lcd_puts(0, 3, buf);
1560 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1561 lcd_puts(0, 4, buf);
1562 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
1564 snprintf(buf, 30, "Last PwrHist: %d.%03dV",
1565 power_history[0] / 1000,
1566 power_history[0] % 1000);
1567 lcd_puts(0, 5, buf);
1569 snprintf(buf, 30, "battery level: %d%%", battery_level());
1570 lcd_puts(0, 6, buf);
1572 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1573 lcd_puts(0, 7, buf);
1574 break;
1577 lcd_update();
1579 switch(get_action(CONTEXT_SETTINGS,HZ/2))
1581 case ACTION_SETTINGS_DEC:
1582 if (view)
1583 view--;
1584 break;
1586 case ACTION_SETTINGS_INC:
1587 if (view < 3)
1588 view++;
1589 break;
1591 case ACTION_STD_CANCEL:
1592 return false;
1595 return false;
1598 #endif /* HAVE_LCD_BITMAP */
1599 #endif
1601 #ifndef SIMULATOR
1602 #if defined(HAVE_MMC) || defined(HAVE_HOTSWAP)
1603 #if defined(HAVE_MMC)
1604 #define CARDTYPE "MMC"
1605 #else
1606 #define CARDTYPE "microSD"
1607 #endif
1608 static int disk_callback(int btn, struct gui_synclist *lists)
1610 tCardInfo *card;
1611 int *cardnum = (int*)lists->gui_list[SCREEN_MAIN].data;
1612 unsigned char card_name[7];
1613 unsigned char pbuf[32];
1614 char *title = lists->gui_list[SCREEN_MAIN].title;
1615 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1616 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1617 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1618 static const unsigned char *nsec_units[] = { "ns", "�s", "ms" };
1619 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1620 "3.1-3.31", "4.0" };
1621 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1623 if (btn == ACTION_STD_OK)
1625 *cardnum ^= 0x1; /* change cards */
1628 simplelist_set_line_count(0);
1630 card = card_get_info(*cardnum);
1632 if (card->initialized > 0)
1634 card_name[6] = '\0';
1635 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1636 simplelist_addline(SIMPLELIST_ADD_LINE,
1637 "%s Rev %d.%d", card_name,
1638 (int) card_extract_bits(card->cid, 72, 4),
1639 (int) card_extract_bits(card->cid, 76, 4));
1640 simplelist_addline(SIMPLELIST_ADD_LINE,
1641 "Prod: %d/%d",
1642 (int) card_extract_bits(card->cid, 112, 4),
1643 (int) card_extract_bits(card->cid, 116, 4) + 1997);
1644 simplelist_addline(SIMPLELIST_ADD_LINE,
1645 "Ser#: 0x%08lx",
1646 card_extract_bits(card->cid, 80, 32));
1647 simplelist_addline(SIMPLELIST_ADD_LINE,
1648 "M=%02x, O=%04x",
1649 (int) card_extract_bits(card->cid, 0, 8),
1650 (int) card_extract_bits(card->cid, 8, 16));
1651 int temp = card_extract_bits(card->csd, 2, 4);
1652 simplelist_addline(SIMPLELIST_ADD_LINE,
1653 CARDTYPE " v%s", temp < 5 ?
1654 spec_vers[temp] : "?.?");
1655 simplelist_addline(SIMPLELIST_ADD_LINE,
1656 "Blocks: 0x%06lx", card->numblocks);
1657 simplelist_addline(SIMPLELIST_ADD_LINE,
1658 "Blksz.: %d P:%c%c", card->blocksize,
1659 card_extract_bits(card->csd, 48, 1) ? 'R' : '-',
1660 card_extract_bits(card->csd, 106, 1) ? 'W' : '-');
1661 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1662 kbit_units, false);
1663 simplelist_addline(SIMPLELIST_ADD_LINE,
1664 "Speed: %s", pbuf);
1665 output_dyn_value(pbuf, sizeof pbuf, card->tsac,
1666 nsec_units, false);
1667 simplelist_addline(SIMPLELIST_ADD_LINE,
1668 "Tsac: %s", pbuf);
1669 simplelist_addline(SIMPLELIST_ADD_LINE,
1670 "Nsac: %d clk", card->nsac);
1671 simplelist_addline(SIMPLELIST_ADD_LINE,
1672 "R2W: *%d", card->r2w_factor);
1673 simplelist_addline(SIMPLELIST_ADD_LINE,
1674 "IRmax: %d..%d mA",
1675 i_vmin[card_extract_bits(card->csd, 66, 3)],
1676 i_vmax[card_extract_bits(card->csd, 69, 3)]);
1677 simplelist_addline(SIMPLELIST_ADD_LINE,
1678 "IWmax: %d..%d mA",
1679 i_vmin[card_extract_bits(card->csd, 72, 3)],
1680 i_vmax[card_extract_bits(card->csd, 75, 3)]);
1682 else if (card->initialized == 0)
1684 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1686 #ifndef HAVE_MMC
1687 else /* card->initialized < 0 */
1689 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1691 #endif
1692 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1693 gui_synclist_set_title(lists, title, Icon_NOICON);
1694 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1695 gui_synclist_select_item(lists, 0);
1696 btn = ACTION_REDRAW;
1698 return btn;
1700 #else /* !defined(HAVE_MMC) && !defined(HAVE_HOTSWAP) */
1701 static int disk_callback(int btn, struct gui_synclist *lists)
1703 (void)lists;
1704 int i;
1705 char buf[128];
1706 unsigned short* identify_info = ata_get_identify();
1707 bool timing_info_present = false;
1708 (void)btn;
1710 simplelist_set_line_count(0);
1712 for (i=0; i < 20; i++)
1713 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1714 buf[40]=0;
1715 /* kill trailing space */
1716 for (i=39; i && buf[i]==' '; i--)
1717 buf[i] = 0;
1718 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1719 for (i=0; i < 4; i++)
1720 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1721 buf[8]=0;
1722 simplelist_addline(SIMPLELIST_ADD_LINE,
1723 "Firmware: %s", buf);
1724 snprintf(buf, sizeof buf, "%ld MB",
1725 ((unsigned long)identify_info[61] << 16 |
1726 (unsigned long)identify_info[60]) / 2048 );
1727 simplelist_addline(SIMPLELIST_ADD_LINE,
1728 "Size: %s", buf);
1729 unsigned long free;
1730 fat_size( IF_MV2(0,) NULL, &free );
1731 simplelist_addline(SIMPLELIST_ADD_LINE,
1732 "Free: %ld MB", free / 1024);
1733 simplelist_addline(SIMPLELIST_ADD_LINE,
1734 "Spinup time: %d ms", ata_spinup_time * (1000/HZ));
1735 i = identify_info[83] & (1<<3);
1736 simplelist_addline(SIMPLELIST_ADD_LINE,
1737 "Power mgmt: %s", i ? "enabled" : "unsupported");
1738 i = identify_info[83] & (1<<9);
1739 simplelist_addline(SIMPLELIST_ADD_LINE,
1740 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1741 i = identify_info[82] & (1<<6);
1742 simplelist_addline(SIMPLELIST_ADD_LINE,
1743 "Read-ahead: %s", i ? "enabled" : "unsupported");
1744 timing_info_present = identify_info[53] & (1<<1);
1745 if(timing_info_present) {
1746 char pio3[2], pio4[2];pio3[1] = 0;
1747 pio4[1] = 0;
1748 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1749 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1750 simplelist_addline(SIMPLELIST_ADD_LINE,
1751 "PIO modes: 0 1 2 %s %s", pio3, pio4);
1753 else {
1754 simplelist_addline(SIMPLELIST_ADD_LINE,
1755 "No PIO mode info");
1757 timing_info_present = identify_info[53] & (1<<1);
1758 if(timing_info_present) {
1759 simplelist_addline(SIMPLELIST_ADD_LINE,
1760 "Cycle times %dns/%dns",
1761 identify_info[67],
1762 identify_info[68] );
1763 } else {
1764 simplelist_addline(SIMPLELIST_ADD_LINE,
1765 "No timing info");
1767 timing_info_present = identify_info[53] & (1<<1);
1768 if(timing_info_present) {
1769 i = identify_info[49] & (1<<11);
1770 simplelist_addline(SIMPLELIST_ADD_LINE,
1771 "IORDY support: %s", i ? "yes" : "no");
1772 i = identify_info[49] & (1<<10);
1773 simplelist_addline(SIMPLELIST_ADD_LINE,
1774 "IORDY disable: %s", i ? "yes" : "no");
1775 } else {
1776 simplelist_addline(SIMPLELIST_ADD_LINE,
1777 "No timing info");
1779 simplelist_addline(SIMPLELIST_ADD_LINE,
1780 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1781 return btn;
1783 #endif /* !defined(HAVE_MMC) && !defined(HAVE_HOTSWAP) */
1784 static bool dbg_disk_info(void)
1786 struct simplelist_info info;
1787 simplelist_info_init(&info, "Disk Info", 1, NULL);
1788 #if defined(HAVE_MMC) || defined(HAVE_HOTSWAP)
1789 char title[16];
1790 int card = 0;
1791 info.callback_data = (void*)&card;
1792 info.title = title;
1793 #endif
1794 info.action_callback = disk_callback;
1795 info.hide_selection = true;
1796 return simplelist_show_list(&info);
1798 #endif /* !SIMULATOR */
1800 #ifdef HAVE_DIRCACHE
1801 static int dircache_callback(int btn, struct gui_synclist *lists)
1803 (void)btn; (void)lists;
1804 simplelist_set_line_count(0);
1805 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
1806 dircache_is_enabled() ? "Yes" : "No");
1807 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
1808 dircache_get_cache_size());
1809 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
1810 global_status.dircache_size);
1811 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
1812 DIRCACHE_LIMIT);
1813 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
1814 dircache_get_reserve_used(), DIRCACHE_RESERVE);
1815 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
1816 dircache_get_build_ticks() / HZ);
1817 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
1818 dircache_get_entry_count());
1819 return btn;
1822 static bool dbg_dircache_info(void)
1824 struct simplelist_info info;
1825 simplelist_info_init(&info, "Dircache Info", 7, NULL);
1826 info.action_callback = dircache_callback;
1827 info.hide_selection = true;
1828 return simplelist_show_list(&info);
1831 #endif /* HAVE_DIRCACHE */
1833 #ifdef HAVE_TAGCACHE
1834 static int database_callback(int btn, struct gui_synclist *lists)
1836 (void)lists;
1837 struct tagcache_stat *stat = tagcache_get_stat();
1838 static bool synced = false;
1840 simplelist_set_line_count(0);
1842 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
1843 stat->initialized ? "Yes" : "No");
1844 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
1845 stat->ready ? "Yes" : "No");
1846 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
1847 stat->ramcache ? "Yes" : "No");
1848 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
1849 stat->ramcache_used, stat->ramcache_allocated);
1850 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
1851 stat->progress, stat->processed_entries);
1852 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
1853 stat->curentry ? stat->curentry : "---");
1854 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
1855 stat->commit_step);
1856 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
1857 stat->commit_delayed ? "Yes" : "No");
1860 if (synced)
1862 synced = false;
1863 tagcache_screensync_event();
1866 if (!btn && stat->curentry)
1868 synced = true;
1869 return ACTION_REDRAW;
1872 if (btn == ACTION_STD_CANCEL)
1873 tagcache_screensync_enable(false);
1875 return btn;
1877 static bool dbg_tagcache_info(void)
1879 struct simplelist_info info;
1880 simplelist_info_init(&info, "Database Info", 8, NULL);
1881 info.action_callback = database_callback;
1882 info.hide_selection = true;
1883 info.timeout = TIMEOUT_NOBLOCK;
1884 tagcache_screensync_enable(true);
1885 return simplelist_show_list(&info);
1887 #endif
1889 #if CONFIG_CPU == SH7034
1890 static bool dbg_save_roms(void)
1892 int fd;
1893 int oldmode = system_memory_guard(MEMGUARD_NONE);
1895 fd = creat("/internal_rom_0000-FFFF.bin");
1896 if(fd >= 0)
1898 write(fd, (void *)0, 0x10000);
1899 close(fd);
1902 fd = creat("/internal_rom_2000000-203FFFF.bin");
1903 if(fd >= 0)
1905 write(fd, (void *)0x2000000, 0x40000);
1906 close(fd);
1909 system_memory_guard(oldmode);
1910 return false;
1912 #elif defined CPU_COLDFIRE
1913 static bool dbg_save_roms(void)
1915 int fd;
1916 int oldmode = system_memory_guard(MEMGUARD_NONE);
1918 #if defined(IRIVER_H100_SERIES)
1919 fd = creat("/internal_rom_000000-1FFFFF.bin");
1920 #elif defined(IRIVER_H300_SERIES)
1921 fd = creat("/internal_rom_000000-3FFFFF.bin");
1922 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5)
1923 fd = creat("/internal_rom_000000-3FFFFF.bin");
1924 #endif
1925 if(fd >= 0)
1927 write(fd, (void *)0, FLASH_SIZE);
1928 close(fd);
1930 system_memory_guard(oldmode);
1932 #ifdef HAVE_EEPROM
1933 fd = creat("/internal_eeprom.bin");
1934 if (fd >= 0)
1936 int old_irq_level;
1937 char buf[EEPROM_SIZE];
1938 int err;
1940 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
1942 err = eeprom_24cxx_read(0, buf, sizeof buf);
1943 if (err)
1944 gui_syncsplash(HZ*3, "Eeprom read failure (%d)",err);
1945 else
1947 write(fd, buf, sizeof buf);
1950 set_irq_level(old_irq_level);
1952 close(fd);
1954 #endif
1956 return false;
1958 #elif defined(CPU_PP) && !(defined(SANSA_E200) || defined(SANSA_C200))
1959 static bool dbg_save_roms(void)
1961 int fd;
1963 fd = creat("/internal_rom_000000-0FFFFF.bin");
1964 if(fd >= 0)
1966 write(fd, (void *)0x20000000, FLASH_SIZE);
1967 close(fd);
1970 return false;
1972 #endif /* CPU */
1974 #ifndef SIMULATOR
1975 #if CONFIG_TUNER
1976 static int radio_callback(int btn, struct gui_synclist *lists)
1978 (void)lists;
1979 if (btn == ACTION_STD_CANCEL)
1980 return btn;
1981 simplelist_set_line_count(1);
1983 #if (CONFIG_TUNER & LV24020LP)
1984 simplelist_addline(SIMPLELIST_ADD_LINE,
1985 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
1986 simplelist_addline(SIMPLELIST_ADD_LINE,
1987 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
1988 simplelist_addline(SIMPLELIST_ADD_LINE,
1989 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
1990 simplelist_addline(SIMPLELIST_ADD_LINE,
1991 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
1992 simplelist_addline(SIMPLELIST_ADD_LINE,
1993 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
1994 simplelist_addline(SIMPLELIST_ADD_LINE,
1995 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
1996 simplelist_addline(SIMPLELIST_ADD_LINE,
1997 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
1998 #endif
1999 #if (CONFIG_TUNER & S1A0903X01)
2000 simplelist_addline(SIMPLELIST_ADD_LINE,
2001 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2002 /* This one doesn't return dynamic data atm */
2003 #endif
2004 #if (CONFIG_TUNER & TEA5767)
2005 struct tea5767_dbg_info nfo;
2006 tea5767_dbg_info(&nfo);
2007 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2008 simplelist_addline(SIMPLELIST_ADD_LINE,
2009 " Read: %02X %02X %02X %02X %02X",
2010 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2011 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2012 (unsigned)nfo.read_regs[4]);
2013 simplelist_addline(SIMPLELIST_ADD_LINE,
2014 " Write: %02X %02X %02X %02X %02X",
2015 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2016 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2017 (unsigned)nfo.write_regs[4]);
2018 #endif
2019 return ACTION_REDRAW;
2021 static bool dbg_fm_radio(void)
2023 struct simplelist_info info;
2024 simplelist_info_init(&info, "FM Radio", 1, NULL);
2025 simplelist_set_line_count(0);
2026 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2027 radio_hardware_present() ? "yes" : "no");
2029 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2030 info.hide_selection = true;
2031 return simplelist_show_list(&info);
2033 #endif /* CONFIG_TUNER */
2034 #endif /* !SIMULATOR */
2036 #ifdef HAVE_LCD_BITMAP
2037 extern bool do_screendump_instead_of_usb;
2039 static bool dbg_screendump(void)
2041 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2042 gui_syncsplash(HZ, "Screendump %s",
2043 do_screendump_instead_of_usb?"enabled":"disabled");
2044 return false;
2046 #endif /* HAVE_LCD_BITMAP */
2048 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2049 static bool dbg_set_memory_guard(void)
2051 static const struct opt_items names[MAXMEMGUARD] = {
2052 { "None", -1 },
2053 { "Flash ROM writes", -1 },
2054 { "Zero area (all)", -1 }
2056 int mode = system_memory_guard(MEMGUARD_KEEP);
2058 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2059 system_memory_guard(mode);
2061 return false;
2063 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2065 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2067 extern volatile bool lcd_poweroff;
2069 static bool dbg_lcd_power_off(void)
2071 lcd_setmargins(0, 0);
2073 while(1)
2075 int button;
2077 lcd_clear_display();
2078 lcd_puts(0, 0, "LCD Power Off");
2079 if(lcd_poweroff)
2080 lcd_puts(1, 1, "Yes");
2081 else
2082 lcd_puts(1, 1, "No");
2084 lcd_update();
2086 button = get_action(CONTEXT_STD,HZ/5);
2087 switch(button)
2089 case ACTION_STD_PREV:
2090 case ACTION_STD_NEXT:
2091 lcd_poweroff = !lcd_poweroff;
2092 break;
2093 case ACTION_STD_OK:
2094 case ACTION_STD_CANCEL:
2095 return false;
2096 default:
2097 sleep(HZ/10);
2098 break;
2101 return false;
2103 #endif
2105 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2106 static bool dbg_write_eeprom(void)
2108 int fd;
2109 int rc;
2110 int old_irq_level;
2111 char buf[EEPROM_SIZE];
2112 int err;
2114 fd = open("/internal_eeprom.bin", O_RDONLY);
2116 if (fd >= 0)
2118 rc = read(fd, buf, EEPROM_SIZE);
2120 if(rc == EEPROM_SIZE)
2122 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
2124 err = eeprom_24cxx_write(0, buf, sizeof buf);
2125 if (err)
2126 gui_syncsplash(HZ*3, "Eeprom write failure (%d)",err);
2127 else
2128 gui_syncsplash(HZ*3, "Eeprom written successfully");
2130 set_irq_level(old_irq_level);
2132 else
2134 gui_syncsplash(HZ*3, "File read error (%d)",rc);
2136 close(fd);
2138 else
2140 gui_syncsplash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2143 return false;
2145 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2146 #ifdef CPU_BOOST_LOGGING
2147 static bool cpu_boost_log(void)
2149 int i = 0,j=0;
2150 int count = cpu_boost_log_getcount();
2151 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2152 char *str;
2153 bool done;
2154 lcd_setmargins(0, 0);
2155 lcd_setfont(FONT_SYSFIXED);
2156 str = cpu_boost_log_getlog_first();
2157 while (i < count)
2159 lcd_clear_display();
2160 for(j=0; j<lines; j++,i++)
2162 if (!str)
2163 str = cpu_boost_log_getlog_next();
2164 if (str)
2166 lcd_puts(0, j,str);
2168 str = NULL;
2170 lcd_update();
2171 done = false;
2172 while (!done)
2174 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2176 case ACTION_STD_OK:
2177 case ACTION_STD_PREV:
2178 case ACTION_STD_NEXT:
2179 done = true;
2180 break;
2181 case ACTION_STD_CANCEL:
2182 i = count;
2183 done = true;
2184 break;
2188 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2189 lcd_setfont(FONT_UI);
2190 return false;
2192 #endif
2196 /****** The menu *********/
2197 struct the_menu_item {
2198 unsigned char *desc; /* string or ID */
2199 bool (*function) (void); /* return true if USB was connected */
2201 static const struct the_menu_item menuitems[] = {
2202 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2203 { "LCD Power Off", dbg_lcd_power_off },
2204 #endif
2205 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2206 (defined(CPU_PP) && !(defined(SANSA_E200) || defined(SANSA_C200)))
2207 { "Dump ROM contents", dbg_save_roms },
2208 #endif
2209 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) || CONFIG_CPU == S3C2440
2210 { "View I/O ports", dbg_ports },
2211 #endif
2212 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2213 { "CPU frequency", dbg_cpufreq },
2214 #endif
2215 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2216 { "S/PDIF analyzer", dbg_spdif },
2217 #endif
2218 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2219 { "Catch mem accesses", dbg_set_memory_guard },
2220 #endif
2221 { "View OS stacks", dbg_os },
2222 #ifdef HAVE_LCD_BITMAP
2223 #ifndef SIMULATOR
2224 { "View battery", view_battery },
2225 #endif
2226 { "Screendump", dbg_screendump },
2227 #endif
2228 #ifndef SIMULATOR
2229 { "View HW info", dbg_hw_info },
2230 #endif
2231 #ifndef SIMULATOR
2232 { "View partitions", dbg_partitions },
2233 #endif
2234 #ifndef SIMULATOR
2235 { "View disk info", dbg_disk_info },
2236 #endif
2237 #ifdef HAVE_DIRCACHE
2238 { "View dircache info", dbg_dircache_info },
2239 #endif
2240 #ifdef HAVE_TAGCACHE
2241 { "View database info", dbg_tagcache_info },
2242 #endif
2243 #ifdef HAVE_LCD_BITMAP
2244 #if CONFIG_CODEC == SWCODEC || !defined(SIMULATOR)
2245 { "View audio thread", dbg_audio_thread },
2246 #endif
2247 #ifdef PM_DEBUG
2248 { "pm histogram", peak_meter_histogram},
2249 #endif /* PM_DEBUG */
2250 #endif /* HAVE_LCD_BITMAP */
2251 #ifndef SIMULATOR
2252 #if CONFIG_TUNER
2253 { "FM Radio", dbg_fm_radio },
2254 #endif
2255 #endif
2256 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2257 { "Write back EEPROM", dbg_write_eeprom },
2258 #endif
2259 #ifdef ROCKBOX_HAS_LOGF
2260 {"logf", logfdisplay },
2261 {"logfdump", logfdump },
2262 #endif
2263 #ifdef CPU_BOOST_LOGGING
2264 {"cpu_boost log",cpu_boost_log},
2265 #endif
2267 static int menu_action_callback(int btn, struct gui_synclist *lists)
2269 if (btn == ACTION_STD_OK)
2271 menuitems[gui_synclist_get_sel_pos(lists)].function();
2272 btn = ACTION_REDRAW;
2274 return btn;
2276 static char* dbg_menu_getname(int item, void * data, char *buffer)
2278 (void)data; (void)buffer;
2279 return menuitems[item].desc;
2281 bool debug_menu(void)
2283 struct simplelist_info info;
2285 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2286 info.action_callback = menu_action_callback;
2287 info.get_name = dbg_menu_getname;
2289 return simplelist_show_list(&info);