Accept FS#7228 by Dagni McPhee enable pitchscreen on sansa
[Rockbox.git] / apps / debug_menu.c
blob2279a27c1341726df8e1b90ff4ed8acc845a576f
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 #ifdef HAVE_MMC
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 static bool dbg_list(char *title, int count, int selection_size,
92 int (*action_callback)(int btn, struct gui_synclist *lists),
93 char* (*dbg_getname)(int item, void * data, char *buffer))
95 struct gui_synclist lists;
96 int action;
98 gui_synclist_init(&lists, dbg_getname, NULL, false, selection_size);
99 gui_synclist_set_title(&lists, title, NOICON);
100 gui_synclist_set_icon_callback(&lists, NULL);
101 gui_synclist_set_nb_items(&lists, count*selection_size);
102 action_signalscreenchange();
103 gui_synclist_draw(&lists);
104 while(1)
106 gui_syncstatusbar_draw(&statusbars, true);
107 action = get_action(CONTEXT_STD, HZ/5);
108 if (gui_synclist_do_button(&lists, action, LIST_WRAP_UNLESS_HELD))
109 gui_synclist_draw(&lists);
110 if (action_callback)
111 action = action_callback(action, &lists);
112 if (action == ACTION_STD_CANCEL)
113 break;
114 else if(default_event_handler(action) == SYS_USB_CONNECTED)
115 return true;
117 action_signalscreenchange();
118 return false;
120 /*---------------------------------------------------*/
121 /* SPECIAL DEBUG STUFF */
122 /*---------------------------------------------------*/
123 extern struct thread_entry threads[MAXTHREADS];
126 #ifndef SIMULATOR
127 static char thread_status_char(int status)
129 switch (status)
131 case STATE_RUNNING : return 'R';
132 case STATE_BLOCKED : return 'B';
133 case STATE_SLEEPING : return 'S';
134 case STATE_BLOCKED_W_TMO: return 'T';
137 return '?';
139 #if NUM_CORES > 1
140 #define IF_COP2(...) __VA_ARGS__
141 #else
142 #define IF_COP2(...)
143 #endif
144 static char* threads_getname(int selected_item, void * data, char *buffer)
146 (void)data;
147 struct thread_entry *thread = NULL;
148 int status, usage;
149 thread = &threads[selected_item];
151 if (thread->name == NULL)
153 snprintf(buffer, MAX_PATH, "%2d: ---", selected_item);
154 return buffer;
157 usage = thread_stack_usage(thread);
158 status = thread_get_status(thread);
159 #ifdef HAVE_PRIORITY_SCHEDULING
160 snprintf(buffer, MAX_PATH, "%2d: " IF_COP2("(%d) ") "%c%c %d %2d%% %s",
161 selected_item,
162 IF_COP2(thread->core,)
163 (status == STATE_RUNNING) ? '*' : ' ',
164 thread_status_char(status),
165 thread->priority,
166 usage, thread->name);
167 #else
168 snprintf(buffer, MAX_PATH, "%2d: " IF_COP2("(%d) ") "%c%c %2d%% %s",
169 selected_item,
170 IF_COP2(thread->core,)
171 (status == STATE_RUNNING) ? '*' : ' ',
172 thread_status_char(status),
173 usage, thread->name);
174 #endif
175 return buffer;
177 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
179 #ifdef ROCKBOX_HAS_LOGF
180 if (action == ACTION_STD_OK)
182 struct thread_entry *thread = &threads[gui_synclist_get_sel_pos(lists)];
183 if (thread->name != NULL)
184 remove_thread(thread);
186 #endif
187 gui_synclist_draw(lists);
188 return action;
190 /* Test code!!! */
191 static bool dbg_os(void)
193 return dbg_list(IF_COP2("Core and ") "Stack usage:", MAXTHREADS, 1,
194 dbg_threads_action_callback, threads_getname);
196 #endif /* !SIMULATOR */
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 action_signalscreenchange();
296 line = 0;
298 lcd_clear_display();
300 bufused = bufsize - pcmbuf_free();
302 snprintf(buf, sizeof(buf), "pcm: %7ld/%7ld", (long) bufused, (long) bufsize);
303 lcd_puts(0, line++, buf);
305 /* Playable space left */
306 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6, bufsize, 0, bufused, HORIZONTAL);
307 line++;
309 snprintf(buf, sizeof(buf), "codec: %8ld/%8ld", audio_filebufused(), (long) filebuflen);
310 lcd_puts(0, line++, buf);
312 /* Playable space left */
313 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6, filebuflen, 0,
314 audio_filebufused(), HORIZONTAL);
315 line++;
317 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
318 lcd_puts(0, line++, buf);
320 #ifndef SIMULATOR
321 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
322 (int)((FREQ + 500000) / 1000000));
323 lcd_puts(0, line++, buf);
324 #endif
326 if (ticks > 0)
328 snprintf(buf, sizeof(buf), "boost ratio: %3d%%",
329 boost_ticks * 100 / ticks);
330 lcd_puts(0, line++, buf);
333 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
334 pcmbuf_used_descs(), pcmbufdescs);
335 lcd_puts(0, line++, buf);
337 lcd_update();
340 tick_remove_task(dbg_audio_task);
342 return false;
344 #endif /* CONFIG_CODEC */
345 #endif /* HAVE_LCD_BITMAP */
348 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
349 /* Tool function to read the flash manufacturer and type, if available.
350 Only chips which could be reprogrammed in system will return values.
351 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
352 /* In IRAM to avoid problems when running directly from Flash */
353 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
354 unsigned addr1, unsigned addr2)
355 ICODE_ATTR __attribute__((noinline));
356 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
357 unsigned addr1, unsigned addr2)
360 unsigned not_manu, not_id; /* read values before switching to ID mode */
361 unsigned manu, id; /* read values when in ID mode */
363 #if CONFIG_CPU == SH7034
364 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
365 #elif defined(CPU_COLDFIRE)
366 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
367 #endif
368 int old_level; /* saved interrupt level */
370 not_manu = flash[0]; /* read the normal content */
371 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
373 /* disable interrupts, prevent any stray flash access */
374 old_level = set_irq_level(HIGHEST_IRQ_LEVEL);
376 flash[addr1] = 0xAA; /* enter command mode */
377 flash[addr2] = 0x55;
378 flash[addr1] = 0x90; /* ID command */
379 /* Atmel wants 20ms pause here */
380 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
382 manu = flash[0]; /* read the IDs */
383 id = flash[1];
385 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
386 /* Atmel wants 20ms pause here */
387 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
389 set_irq_level(old_level); /* enable interrupts again */
391 /* I assume success if the obtained values are different from
392 the normal flash content. This is not perfectly bulletproof, they
393 could theoretically be the same by chance, causing us to fail. */
394 if (not_manu != manu || not_id != id) /* a value has changed */
396 *p_manufacturer = manu; /* return the results */
397 *p_device = id;
398 return true; /* success */
400 return false; /* fail */
402 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
404 #ifndef SIMULATOR
405 #ifdef HAVE_LCD_BITMAP
406 static bool dbg_hw_info(void)
408 #if CONFIG_CPU == SH7034
409 char buf[32];
410 int bitmask = HW_MASK;
411 int rom_version = ROM_VERSION;
412 unsigned manu, id; /* flash IDs */
413 bool got_id; /* flag if we managed to get the flash IDs */
414 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
415 bool has_bootrom; /* flag for boot ROM present */
416 int oldmode; /* saved memory guard mode */
418 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
420 /* get flash ROM type */
421 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
422 if (!got_id)
423 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
425 /* check if the boot ROM area is a flash mirror */
426 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
427 if (has_bootrom) /* if ROM and Flash different */
429 /* calculate CRC16 checksum of boot ROM */
430 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
433 system_memory_guard(oldmode); /* re-enable memory guard */
435 lcd_setmargins(0, 0);
436 lcd_setfont(FONT_SYSFIXED);
437 lcd_clear_display();
439 lcd_puts(0, 0, "[Hardware info]");
441 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
442 lcd_puts(0, 1, buf);
444 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
445 lcd_puts(0, 2, buf);
447 if (got_id)
448 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
449 else
450 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
451 lcd_puts(0, 3, buf);
453 if (has_bootrom)
455 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
456 snprintf(buf, 32, "Boot ROM: V1");
457 else
458 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
460 else
462 snprintf(buf, 32, "Boot ROM: none");
464 lcd_puts(0, 4, buf);
466 lcd_update();
468 while(1)
470 if (action_userabort(TIMEOUT_BLOCK))
471 return false;
473 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
474 char buf[32];
475 unsigned manu, id; /* flash IDs */
476 int got_id; /* flag if we managed to get the flash IDs */
477 int oldmode; /* saved memory guard mode */
478 int line = 0;
480 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
482 /* get flash ROM type */
483 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
484 if (!got_id)
485 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
487 system_memory_guard(oldmode); /* re-enable memory guard */
489 lcd_setmargins(0, 0);
490 lcd_setfont(FONT_SYSFIXED);
491 lcd_clear_display();
493 lcd_puts(0, line++, "[Hardware info]");
495 if (got_id)
496 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
497 else
498 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
499 lcd_puts(0, line++, buf);
501 #ifdef IAUDIO_X5
503 struct ds2411_id id;
505 lcd_puts(0, ++line, "Serial Number:");
507 got_id = ds2411_read_id(&id);
509 if (got_id == DS2411_OK)
511 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
512 lcd_puts(0, ++line, buf);
513 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
514 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
515 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
516 lcd_puts(0, ++line, buf);
517 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
519 else
521 snprintf(buf, 32, "READ ERR=%d", got_id);
524 lcd_puts(0, ++line, buf);
526 #endif
528 lcd_update();
530 while(1)
532 if (action_userabort(TIMEOUT_BLOCK))
533 return false;
535 #elif CONFIG_CPU == PP5020
536 char buf[32];
537 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
538 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
539 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
540 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
542 lcd_setmargins(0, 0);
543 lcd_setfont(FONT_SYSFIXED);
544 lcd_clear_display();
546 lcd_puts(0, 0, "[Hardware info]");
548 snprintf(buf, sizeof(buf), "HW rev: 0x%08x", ipod_hw_rev);
549 lcd_puts(0, 1, buf);
551 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
552 lcd_puts(0, 2, buf);
553 lcd_update();
555 while(1)
557 if (action_userabort(TIMEOUT_BLOCK))
558 return false;
560 #endif /* CONFIG_CPU */
561 return false;
563 #else /* !HAVE_LCD_BITMAP */
564 static bool dbg_hw_info(void)
566 char buf[32];
567 int button;
568 int currval = 0;
569 int rom_version = ROM_VERSION;
570 unsigned manu, id; /* flash IDs */
571 bool got_id; /* flag if we managed to get the flash IDs */
572 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
573 bool has_bootrom; /* flag for boot ROM present */
574 int oldmode; /* saved memory guard mode */
576 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
578 /* get flash ROM type */
579 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
580 if (!got_id)
581 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
583 /* check if the boot ROM area is a flash mirror */
584 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
585 if (has_bootrom) /* if ROM and Flash different */
587 /* calculate CRC16 checksum of boot ROM */
588 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
591 system_memory_guard(oldmode); /* re-enable memory guard */
593 lcd_clear_display();
595 lcd_puts(0, 0, "[HW Info]");
596 while(1)
598 switch(currval)
600 case 0:
601 snprintf(buf, 32, "ROM: %d.%02d",
602 rom_version/100, rom_version%100);
603 break;
604 case 1:
605 if (got_id)
606 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
607 else
608 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
609 break;
610 case 2:
611 if (has_bootrom)
613 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
614 snprintf(buf, 32, "BootROM: V1");
615 else if (rom_crc == 0x358099E8)
616 snprintf(buf, 32, "BootROM: V2");
617 /* alternative boot ROM found in one single player so far */
618 else
619 snprintf(buf, 32, "R: %08x", rom_crc);
621 else
622 snprintf(buf, 32, "BootROM: no");
625 lcd_puts(0, 1, buf);
626 lcd_update();
628 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
630 switch(button)
632 case ACTION_STD_CANCEL:
633 action_signalscreenchange();
634 return false;
636 case ACTION_SETTINGS_DEC:
637 currval--;
638 if(currval < 0)
639 currval = 2;
640 break;
642 case ACTION_SETTINGS_INC:
643 currval++;
644 if(currval > 2)
645 currval = 0;
646 break;
649 return false;
651 #endif /* !HAVE_LCD_BITMAP */
652 #endif /* !SIMULATOR */
654 #ifndef SIMULATOR
655 static char* dbg_partitions_getname(int selected_item, void * data, char *buffer)
657 (void)data;
658 int partition = selected_item/2;
659 struct partinfo* p = disk_partinfo(partition);
660 if (selected_item%2)
662 snprintf(buffer, MAX_PATH, "T:%x %ld MB", p->type, p->size / 2048);
664 else
666 snprintf(buffer, MAX_PATH, "P%d: S:%lx", partition, p->start);
668 return buffer;
671 bool dbg_partitions(void)
673 return dbg_list("Partition Info", 4, 2,
674 NULL, dbg_partitions_getname);
676 #endif
678 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
679 static bool dbg_spdif(void)
681 char buf[128];
682 int line;
683 unsigned int control;
684 int x;
685 char *s;
686 int category;
687 int generation;
688 unsigned int interruptstat;
689 bool valnogood, symbolerr, parityerr;
690 bool done = false;
691 bool spdif_src_on;
692 int spdif_source = spdif_get_output_source(&spdif_src_on);
693 spdif_set_output_source(AUDIO_SRC_SPDIF, true);
695 lcd_setmargins(0, 0);
696 lcd_clear_display();
697 lcd_setfont(FONT_SYSFIXED);
699 #ifdef HAVE_SPDIF_POWER
700 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
701 #endif
703 while (!done)
705 line = 0;
707 control = EBU1RCVCCHANNEL1;
708 interruptstat = INTERRUPTSTAT;
709 INTERRUPTCLEAR = 0x03c00000;
711 valnogood = (interruptstat & 0x01000000)?true:false;
712 symbolerr = (interruptstat & 0x00800000)?true:false;
713 parityerr = (interruptstat & 0x00400000)?true:false;
715 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
716 valnogood?"--":"OK",
717 symbolerr?"--":"OK",
718 parityerr?"--":"OK");
719 lcd_puts(0, line++, buf);
721 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
722 lcd_puts(0, line++, buf);
724 line++;
726 x = control >> 31;
727 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
728 x, x?"Professional":"Consumer");
729 lcd_puts(0, line++, buf);
731 x = (control >> 30) & 1;
732 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
733 x, x?"Non-PCM":"PCM");
734 lcd_puts(0, line++, buf);
736 x = (control >> 29) & 1;
737 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
738 x, x?"Permitted":"Inhibited");
739 lcd_puts(0, line++, buf);
741 x = (control >> 27) & 7;
742 switch(x)
744 case 0:
745 s = "None";
746 break;
747 case 1:
748 s = "50/15us";
749 break;
750 default:
751 s = "Reserved";
752 break;
754 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
755 lcd_puts(0, line++, buf);
757 x = (control >> 24) & 3;
758 snprintf(buf, sizeof(buf), "Mode: %d", x);
759 lcd_puts(0, line++, buf);
761 category = (control >> 17) & 127;
762 switch(category)
764 case 0x00:
765 s = "General";
766 break;
767 case 0x40:
768 s = "Audio CD";
769 break;
770 default:
771 s = "Unknown";
773 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
774 lcd_puts(0, line++, buf);
776 x = (control >> 16) & 1;
777 generation = x;
778 if(((category & 0x70) == 0x10) ||
779 ((category & 0x70) == 0x40) ||
780 ((category & 0x78) == 0x38))
782 generation = !generation;
784 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
785 x, generation?"Original":"No ind.");
786 lcd_puts(0, line++, buf);
788 x = (control >> 12) & 15;
789 snprintf(buf, sizeof(buf), "Source: %d", x);
790 lcd_puts(0, line++, buf);
792 x = (control >> 8) & 15;
793 switch(x)
795 case 0:
796 s = "Unspecified";
797 break;
798 case 8:
799 s = "A (Left)";
800 break;
801 case 4:
802 s = "B (Right)";
803 break;
804 default:
805 s = "";
806 break;
808 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
809 lcd_puts(0, line++, buf);
811 x = (control >> 4) & 15;
812 switch(x)
814 case 0:
815 s = "44.1kHz";
816 break;
817 case 0x4:
818 s = "48kHz";
819 break;
820 case 0xc:
821 s = "32kHz";
822 break;
824 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
825 lcd_puts(0, line++, buf);
827 x = (control >> 2) & 3;
828 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
829 lcd_puts(0, line++, buf);
830 line++;
832 #ifndef SIMULATOR
833 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
834 spdif_measure_frequency());
835 lcd_puts(0, line++, buf);
836 #endif
838 lcd_update();
840 if (action_userabort(HZ/10))
841 break;
844 spdif_set_output_source(spdif_source, spdif_src_on);
846 #ifdef HAVE_SPDIF_POWER
847 spdif_power_enable(global_settings.spdif_enable);
848 #endif
850 return false;
852 #endif /* CPU_COLDFIRE */
854 #ifndef SIMULATOR
855 #ifdef HAVE_LCD_BITMAP
856 /* button definitions */
857 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
858 (CONFIG_KEYPAD == IRIVER_H300_PAD)
859 # define DEBUG_CANCEL BUTTON_OFF
861 #elif CONFIG_KEYPAD == RECORDER_PAD
862 # define DEBUG_CANCEL BUTTON_OFF
864 #elif CONFIG_KEYPAD == ONDIO_PAD
865 # define DEBUG_CANCEL BUTTON_MENU
867 #elif (CONFIG_KEYPAD == IPOD_3G_PAD) || \
868 (CONFIG_KEYPAD == IPOD_4G_PAD)
869 # define DEBUG_CANCEL BUTTON_MENU
871 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
872 # define DEBUG_CANCEL BUTTON_PLAY
874 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
875 # define DEBUG_CANCEL BUTTON_REC
877 #elif CONFIG_KEYPAD == GIGABEAT_PAD
878 # define DEBUG_CANCEL BUTTON_A
880 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
881 # define DEBUG_CANCEL BUTTON_REW
883 #elif CONFIG_KEYPAD == SANSA_E200_PAD
884 # define DEBUG_CANCEL BUTTON_LEFT
885 #endif /* key definitios */
887 /* Test code!!! */
888 bool dbg_ports(void)
890 #if CONFIG_CPU == SH7034
891 unsigned short porta;
892 unsigned short portb;
893 unsigned char portc;
894 char buf[32];
895 int adc_battery_voltage, adc_battery_level;
897 lcd_setfont(FONT_SYSFIXED);
898 lcd_setmargins(0, 0);
899 lcd_clear_display();
901 while(1)
903 porta = PADR;
904 portb = PBDR;
905 portc = PCDR;
907 snprintf(buf, 32, "PADR: %04x", porta);
908 lcd_puts(0, 0, buf);
909 snprintf(buf, 32, "PBDR: %04x", portb);
910 lcd_puts(0, 1, buf);
912 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
913 lcd_puts(0, 2, buf);
914 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
915 lcd_puts(0, 3, buf);
916 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
917 lcd_puts(0, 4, buf);
918 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
919 lcd_puts(0, 5, buf);
921 battery_read_info(NULL, &adc_battery_voltage,
922 &adc_battery_level);
923 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100,
924 adc_battery_voltage % 100, adc_battery_level);
925 lcd_puts(0, 6, buf);
927 lcd_update();
928 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
929 return false;
931 #elif defined(CPU_COLDFIRE)
932 unsigned int gpio_out;
933 unsigned int gpio1_out;
934 unsigned int gpio_read;
935 unsigned int gpio1_read;
936 unsigned int gpio_function;
937 unsigned int gpio1_function;
938 unsigned int gpio_enable;
939 unsigned int gpio1_enable;
940 int adc_buttons, adc_remote;
941 int adc_battery, adc_battery_voltage, adc_battery_level;
942 char buf[128];
943 int line;
945 lcd_setmargins(0, 0);
946 lcd_clear_display();
947 lcd_setfont(FONT_SYSFIXED);
949 while(1)
951 line = 0;
952 gpio_read = GPIO_READ;
953 gpio1_read = GPIO1_READ;
954 gpio_out = GPIO_OUT;
955 gpio1_out = GPIO1_OUT;
956 gpio_function = GPIO_FUNCTION;
957 gpio1_function = GPIO1_FUNCTION;
958 gpio_enable = GPIO_ENABLE;
959 gpio1_enable = GPIO1_ENABLE;
961 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
962 lcd_puts(0, line++, buf);
963 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
964 lcd_puts(0, line++, buf);
965 snprintf(buf, sizeof(buf), "GPIO_FUNCTION: %08x", gpio_function);
966 lcd_puts(0, line++, buf);
967 snprintf(buf, sizeof(buf), "GPIO_ENABLE: %08x", gpio_enable);
968 lcd_puts(0, line++, buf);
970 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
971 lcd_puts(0, line++, buf);
972 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
973 lcd_puts(0, line++, buf);
974 snprintf(buf, sizeof(buf), "GPIO1_FUNCTION: %08x", gpio1_function);
975 lcd_puts(0, line++, buf);
976 snprintf(buf, sizeof(buf), "GPIO1_ENABLE: %08x", gpio1_enable);
977 lcd_puts(0, line++, buf);
979 adc_buttons = adc_read(ADC_BUTTONS);
980 adc_remote = adc_read(ADC_REMOTE);
981 battery_read_info(&adc_battery, &adc_battery_voltage,
982 &adc_battery_level);
983 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
984 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
985 button_scan_enabled() ? '+' : '-', adc_buttons);
986 #else
987 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
988 #endif
989 lcd_puts(0, line++, buf);
990 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
991 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
992 remote_detect() ? '+' : '-', adc_remote);
993 #else
994 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
995 #endif
997 lcd_puts(0, line++, buf);
998 snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_battery);
999 lcd_puts(0, line++, buf);
1000 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1001 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1002 adc_read(ADC_REMOTEDETECT));
1003 lcd_puts(0, line++, buf);
1004 #endif
1006 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100,
1007 adc_battery_voltage % 100, adc_battery_level);
1008 lcd_puts(0, line++, buf);
1010 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1011 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1012 lcd_puts(0, line++, buf);
1013 #endif
1015 lcd_update();
1016 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1017 return false;
1020 #elif CONFIG_CPU == PP5020 || CONFIG_CPU == PP5024
1022 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1023 unsigned int gpio_e, gpio_f, gpio_g, gpio_h;
1024 unsigned int gpio_i, gpio_j, gpio_k, gpio_l;
1026 char buf[128];
1027 int line;
1029 lcd_setmargins(0, 0);
1030 lcd_clear_display();
1031 lcd_setfont(FONT_SYSFIXED);
1033 while(1)
1035 gpio_a = GPIOA_INPUT_VAL;
1036 gpio_b = GPIOB_INPUT_VAL;
1037 gpio_c = GPIOC_INPUT_VAL;
1039 gpio_g = GPIOG_INPUT_VAL;
1040 gpio_h = GPIOH_INPUT_VAL;
1041 gpio_i = GPIOI_INPUT_VAL;
1043 line = 0;
1044 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_G: %02x", gpio_a, gpio_g);
1045 lcd_puts(0, line++, buf);
1046 snprintf(buf, sizeof(buf), "GPIO_B: %02x GPIO_H: %02x", gpio_b, gpio_h);
1047 lcd_puts(0, line++, buf);
1048 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_I: %02x", gpio_c, gpio_i);
1049 lcd_puts(0, line++, buf);
1050 line++;
1052 gpio_d = GPIOD_INPUT_VAL;
1053 gpio_e = GPIOE_INPUT_VAL;
1054 gpio_f = GPIOF_INPUT_VAL;
1056 gpio_j = GPIOJ_INPUT_VAL;
1057 gpio_k = GPIOK_INPUT_VAL;
1058 gpio_l = GPIOL_INPUT_VAL;
1060 snprintf(buf, sizeof(buf), "GPIO_D: %02x GPIO_J: %02x", gpio_d, gpio_j);
1061 lcd_puts(0, line++, buf);
1062 snprintf(buf, sizeof(buf), "GPIO_E: %02x GPIO_K: %02x", gpio_e, gpio_k);
1063 lcd_puts(0, line++, buf);
1064 snprintf(buf, sizeof(buf), "GPIO_F: %02x GPIO_L: %02x", gpio_f, gpio_l);
1065 lcd_puts(0, line++, buf);
1066 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1067 line++;
1068 snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_read(ADC_BATTERY));
1069 lcd_puts(0, line++, buf);
1070 snprintf(buf, sizeof(buf), "ADC_UNKNOWN_1: %02x", adc_read(ADC_UNKNOWN_1));
1071 lcd_puts(0, line++, buf);
1072 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_read(ADC_REMOTE));
1073 lcd_puts(0, line++, buf);
1074 snprintf(buf, sizeof(buf), "ADC_SCROLLPAD: %02x", adc_read(ADC_SCROLLPAD));
1075 lcd_puts(0, line++, buf);
1076 #elif defined(SANSA_E200)
1077 line++;
1078 snprintf(buf, sizeof(buf), "ADC_BVDD: %02x", adc_read(ADC_BVDD));
1079 lcd_puts(0, line++, buf);
1080 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %02x", adc_read(ADC_RTCSUP));
1081 lcd_puts(0, line++, buf);
1082 snprintf(buf, sizeof(buf), "ADC_UVDD: %02x", adc_read(ADC_UVDD));
1083 lcd_puts(0, line++, buf);
1084 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %02x", adc_read(ADC_CHG_IN));
1085 lcd_puts(0, line++, buf);
1086 snprintf(buf, sizeof(buf), "ADC_CVDD: %02x", adc_read(ADC_CVDD));
1087 lcd_puts(0, line++, buf);
1088 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %02x", adc_read(ADC_BATTEMP));
1089 lcd_puts(0, line++, buf);
1090 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %02x", adc_read(ADC_MICSUP1));
1091 lcd_puts(0, line++, buf);
1092 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %02x", adc_read(ADC_MICSUP2));
1093 lcd_puts(0, line++, buf);
1094 snprintf(buf, sizeof(buf), "ADC_VBE1: %02x", adc_read(ADC_VBE1));
1095 lcd_puts(0, line++, buf);
1096 snprintf(buf, sizeof(buf), "ADC_VBE2: %02x", adc_read(ADC_VBE2));
1097 lcd_puts(0, line++, buf);
1098 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1: %02x", adc_read(ADC_I_MICSUP1));
1099 lcd_puts(0, line++, buf);
1100 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2: %02x", adc_read(ADC_I_MICSUP2));
1101 lcd_puts(0, line++, buf);
1102 snprintf(buf, sizeof(buf), "ADC_VBAT: %02x", adc_read(ADC_VBAT));
1103 lcd_puts(0, line++, buf);
1104 #endif
1105 lcd_update();
1106 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1107 return false;
1110 #elif CONFIG_CPU == PP5002
1111 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1113 char buf[128];
1114 int line;
1116 lcd_setmargins(0, 0);
1117 lcd_clear_display();
1118 lcd_setfont(FONT_SYSFIXED);
1120 while(1)
1122 gpio_a = GPIOA_INPUT_VAL;
1123 gpio_b = GPIOB_INPUT_VAL;
1124 gpio_c = GPIOC_INPUT_VAL;
1125 gpio_d = GPIOD_INPUT_VAL;
1127 line = 0;
1128 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x", gpio_a, gpio_b);
1129 lcd_puts(0, line++, buf);
1130 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x", gpio_c, gpio_d);
1131 lcd_puts(0, line++, buf);
1133 lcd_update();
1134 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1135 return false;
1137 #elif CONFIG_CPU == S3C2440
1138 char buf[50];
1139 int line;
1141 lcd_setmargins(0, 0);
1142 lcd_clear_display();
1143 lcd_setfont(FONT_SYSFIXED);
1145 while(1)
1147 line = 0;
1148 snprintf(buf, sizeof(buf), "[Ports and Registers]"); lcd_puts(0, line++, buf);
1150 snprintf(buf, sizeof(buf), "GPACON: %08x GPBCON: %08x", GPACON, GPBCON); lcd_puts(0, line++, buf);
1151 snprintf(buf, sizeof(buf), "GPADAT: %08x GPBDAT: %08x", GPADAT, GPBDAT); lcd_puts(0, line++, buf);
1152 snprintf(buf, sizeof(buf), "GPAUP: %08x GPBUP: %08x", 0, GPBUP); lcd_puts(0, line++, buf);
1153 snprintf(buf, sizeof(buf), "GPCCON: %08x GPDCON: %08x", GPCCON, GPDCON); lcd_puts(0, line++, buf);
1154 snprintf(buf, sizeof(buf), "GPCDAT: %08x GPDDAT: %08x", GPCDAT, GPDDAT); lcd_puts(0, line++, buf);
1155 snprintf(buf, sizeof(buf), "GPCUP: %08x GPDUP: %08x", GPCUP, GPDUP); lcd_puts(0, line++, buf);
1157 snprintf(buf, sizeof(buf), "GPCCON: %08x GPDCON: %08x", GPCCON, GPDCON); lcd_puts(0, line++, buf);
1158 snprintf(buf, sizeof(buf), "GPCDAT: %08x GPDDAT: %08x", GPCDAT, GPDDAT); lcd_puts(0, line++, buf);
1159 snprintf(buf, sizeof(buf), "GPCUP: %08x GPDUP: %08x", GPCUP, GPDUP); lcd_puts(0, line++, buf);
1161 snprintf(buf, sizeof(buf), "GPECON: %08x GPFCON: %08x", GPECON, GPFCON); lcd_puts(0, line++, buf);
1162 snprintf(buf, sizeof(buf), "GPEDAT: %08x GPFDAT: %08x", GPEDAT, GPFDAT); lcd_puts(0, line++, buf);
1163 snprintf(buf, sizeof(buf), "GPEUP: %08x GPFUP: %08x", GPEUP, GPFUP); lcd_puts(0, line++, buf);
1165 snprintf(buf, sizeof(buf), "GPGCON: %08x GPHCON: %08x", GPGCON, GPHCON); lcd_puts(0, line++, buf);
1166 snprintf(buf, sizeof(buf), "GPGDAT: %08x GPHDAT: %08x", GPGDAT, GPHDAT); lcd_puts(0, line++, buf);
1167 snprintf(buf, sizeof(buf), "GPGUP: %08x GPHUP: %08x", GPGUP, GPHUP); lcd_puts(0, line++, buf);
1169 snprintf(buf, sizeof(buf), "GPJCON: %08x", GPJCON); lcd_puts(0, line++, buf);
1170 snprintf(buf, sizeof(buf), "GPJDAT: %08x", GPJDAT); lcd_puts(0, line++, buf);
1171 snprintf(buf, sizeof(buf), "GPJUP: %08x", GPJUP); lcd_puts(0, line++, buf);
1173 line++;
1175 snprintf(buf, sizeof(buf), "SRCPND: %08x INTMOD: %08x", SRCPND, INTMOD); lcd_puts(0, line++, buf);
1176 snprintf(buf, sizeof(buf), "INTMSK: %08x INTPND: %08x", INTMSK, INTPND); lcd_puts(0, line++, buf);
1177 snprintf(buf, sizeof(buf), "CLKCON: %08x CLKSLOW: %08x", CLKCON, CLKSLOW); lcd_puts(0, line++, buf);
1178 lcd_update();
1179 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1180 return false;
1182 #endif /* CPU */
1183 return false;
1185 #else /* !HAVE_LCD_BITMAP */
1186 bool dbg_ports(void)
1188 unsigned short porta;
1189 unsigned short portb;
1190 unsigned char portc;
1191 char buf[32];
1192 int button;
1193 int adc_battery_voltage;
1194 int currval = 0;
1196 lcd_clear_display();
1198 while(1)
1200 porta = PADR;
1201 portb = PBDR;
1202 portc = PCDR;
1204 switch(currval)
1206 case 0:
1207 snprintf(buf, 32, "PADR: %04x", porta);
1208 break;
1209 case 1:
1210 snprintf(buf, 32, "PBDR: %04x", portb);
1211 break;
1212 case 2:
1213 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1214 break;
1215 case 3:
1216 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1217 break;
1218 case 4:
1219 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1220 break;
1221 case 5:
1222 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1223 break;
1224 case 6:
1225 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1226 break;
1227 case 7:
1228 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1229 break;
1230 case 8:
1231 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1232 break;
1233 case 9:
1234 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1235 break;
1236 break;
1238 lcd_puts(0, 0, buf);
1240 battery_read_info(NULL, &adc_battery_voltage, NULL);
1241 snprintf(buf, 32, "Batt: %d.%02dV", adc_battery_voltage / 100,
1242 adc_battery_voltage % 100);
1243 lcd_puts(0, 1, buf);
1244 lcd_update();
1246 button = get_action(CONTEXT_SETTINGS,HZ/5);
1248 switch(button)
1250 case ACTION_STD_CANCEL:
1251 action_signalscreenchange();
1252 return false;
1254 case ACTION_SETTINGS_DEC:
1255 currval--;
1256 if(currval < 0)
1257 currval = 9;
1258 break;
1260 case ACTION_SETTINGS_INC:
1261 currval++;
1262 if(currval > 9)
1263 currval = 0;
1264 break;
1267 return false;
1269 #endif /* !HAVE_LCD_BITMAP */
1270 #endif /* !SIMULATOR */
1272 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1273 static bool dbg_cpufreq(void)
1275 char buf[128];
1276 int line;
1277 int button;
1279 #ifdef HAVE_LCD_BITMAP
1280 lcd_setmargins(0, 0);
1281 lcd_setfont(FONT_SYSFIXED);
1282 #endif
1283 lcd_clear_display();
1285 while(1)
1287 line = 0;
1289 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1290 lcd_puts(0, line++, buf);
1292 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1293 lcd_puts(0, line++, buf);
1295 lcd_update();
1296 button = get_action(CONTEXT_STD,HZ/10);
1298 switch(button)
1300 case ACTION_STD_PREV:
1301 cpu_boost(true);
1302 break;
1304 case ACTION_STD_NEXT:
1305 cpu_boost(false);
1306 break;
1308 case ACTION_STD_OK:
1309 while (get_cpu_boost_counter() > 0)
1310 cpu_boost(false);
1311 set_cpu_frequency(CPUFREQ_DEFAULT);
1312 break;
1314 case ACTION_STD_CANCEL:
1315 action_signalscreenchange();
1316 return false;
1320 return false;
1322 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1324 #ifndef SIMULATOR
1325 #ifdef HAVE_LCD_BITMAP
1327 * view_battery() shows a automatically scaled graph of the battery voltage
1328 * over time. Usable for estimating battery life / charging rate.
1329 * The power_history array is updated in power_thread of powermgmt.c.
1332 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1333 #define BAT_YSPACE (LCD_HEIGHT - 20)
1335 static bool view_battery(void)
1337 int view = 0;
1338 int i, x, y;
1339 unsigned short maxv, minv;
1340 char buf[32];
1342 lcd_setmargins(0, 0);
1343 lcd_setfont(FONT_SYSFIXED);
1345 while(1)
1347 lcd_clear_display();
1348 switch (view) {
1349 case 0: /* voltage history graph */
1350 /* Find maximum and minimum voltage for scaling */
1351 maxv = 0;
1352 minv = 65535;
1353 for (i = 0; i < BAT_LAST_VAL; i++) {
1354 if (power_history[i] > maxv)
1355 maxv = power_history[i];
1356 if (power_history[i] && (power_history[i] < minv))
1358 minv = power_history[i];
1362 if ((minv < 1) || (minv >= 65535))
1363 minv = 1;
1364 if (maxv < 2)
1365 maxv = 2;
1366 if (minv == maxv)
1367 maxv < 65535 ? maxv++ : minv--;
1369 snprintf(buf, 30, "Battery %d.%02d", power_history[0] / 100,
1370 power_history[0] % 100);
1371 lcd_puts(0, 0, buf);
1372 snprintf(buf, 30, "scale %d.%02d-%d.%02d V",
1373 minv / 100, minv % 100, maxv / 100, maxv % 100);
1374 lcd_puts(0, 1, buf);
1376 x = 0;
1377 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1378 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1379 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1380 lcd_vline(x, LCD_HEIGHT-1, 20);
1381 lcd_set_drawmode(DRMODE_SOLID);
1382 lcd_vline(x, LCD_HEIGHT-1,
1383 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1384 x++;
1387 break;
1389 case 1: /* status: */
1390 lcd_puts(0, 0, "Power status:");
1392 battery_read_info(NULL, &y, NULL);
1393 snprintf(buf, 30, "Battery: %d.%02d V", y / 100, y % 100);
1394 lcd_puts(0, 1, buf);
1395 #ifdef ADC_EXT_POWER
1396 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000;
1397 snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100);
1398 lcd_puts(0, 2, buf);
1399 #endif
1400 #if CONFIG_CHARGING
1401 #if CONFIG_CHARGING == CHARGING_CONTROL
1402 snprintf(buf, 30, "Chgr: %s %s",
1403 charger_inserted() ? "present" : "absent",
1404 charger_enabled ? "on" : "off");
1405 lcd_puts(0, 3, buf);
1406 snprintf(buf, 30, "short delta: %d", short_delta);
1407 lcd_puts(0, 5, buf);
1408 snprintf(buf, 30, "long delta: %d", long_delta);
1409 lcd_puts(0, 6, buf);
1410 lcd_puts(0, 7, power_message);
1411 snprintf(buf, 30, "USB Inserted: %s",
1412 usb_inserted() ? "yes" : "no");
1413 lcd_puts(0, 8, buf);
1414 #if defined IRIVER_H300_SERIES
1415 snprintf(buf, 30, "USB Charging Enabled: %s",
1416 usb_charging_enabled() ? "yes" : "no");
1417 lcd_puts(0, 9, buf);
1418 #endif
1419 #else /* CONFIG_CHARGING != CHARGING_CONTROL */
1420 #if defined IPOD_NANO || defined IPOD_VIDEO
1421 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1422 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1423 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1424 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1425 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1427 snprintf(buf, 30, "USB pwr: %s",
1428 usb_pwr ? "present" : "absent");
1429 lcd_puts(0, 3, buf);
1430 snprintf(buf, 30, "EXT pwr: %s",
1431 ext_pwr ? "present" : "absent");
1432 lcd_puts(0, 4, buf);
1433 snprintf(buf, 30, "Battery: %s",
1434 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1435 lcd_puts(0, 5, buf);
1436 snprintf(buf, 30, "Dock mode: %s",
1437 dock ? "enabled" : "disabled");
1438 lcd_puts(0, 6, buf);
1439 snprintf(buf, 30, "Headphone: %s",
1440 headphone ? "connected" : "disconnected");
1441 lcd_puts(0, 7, buf);
1442 #else
1443 snprintf(buf, 30, "Charger: %s",
1444 charger_inserted() ? "present" : "absent");
1445 lcd_puts(0, 3, buf);
1446 #endif
1447 #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1448 #endif /* CONFIG_CHARGING */
1449 break;
1451 case 2: /* voltage deltas: */
1452 lcd_puts(0, 0, "Voltage deltas:");
1454 for (i = 0; i <= 6; i++) {
1455 y = power_history[i] - power_history[i+i];
1456 snprintf(buf, 30, "-%d min: %s%d.%02d V", i,
1457 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 100,
1458 ((y < 0) ? y * -1 : y ) % 100);
1459 lcd_puts(0, i+1, buf);
1461 break;
1463 case 3: /* remaining time estimation: */
1465 #if CONFIG_CHARGING == CHARGING_CONTROL
1466 snprintf(buf, 30, "charge_state: %d", charge_state);
1467 lcd_puts(0, 0, buf);
1469 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1470 lcd_puts(0, 1, buf);
1472 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1473 lcd_puts(0, 2, buf);
1475 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1476 lcd_puts(0, 3, buf);
1478 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1479 lcd_puts(0, 4, buf);
1480 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
1482 snprintf(buf, 30, "Last PwrHist: %d.%02d V",
1483 power_history[0] / 100,
1484 power_history[0] % 100);
1485 lcd_puts(0, 5, buf);
1487 snprintf(buf, 30, "battery level: %d%%", battery_level());
1488 lcd_puts(0, 6, buf);
1490 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1491 lcd_puts(0, 7, buf);
1492 break;
1495 lcd_update();
1497 switch(get_action(CONTEXT_SETTINGS,HZ/2))
1499 case ACTION_SETTINGS_DEC:
1500 if (view)
1501 view--;
1502 break;
1504 case ACTION_SETTINGS_INC:
1505 if (view < 3)
1506 view++;
1507 break;
1509 case ACTION_STD_CANCEL:
1510 action_signalscreenchange();
1511 return false;
1514 return false;
1517 #endif /* HAVE_LCD_BITMAP */
1518 #endif
1520 #ifndef SIMULATOR
1521 #ifdef HAVE_MMC
1522 static bool dbg_mmc_info(void)
1524 bool done = false;
1525 int currval = 0;
1526 int line;
1527 tCardInfo *card;
1528 unsigned char pbuf[32], pbuf2[32];
1529 unsigned char card_name[7];
1531 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1532 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1533 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1534 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1535 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1536 "3.1-3.31", "4.0" };
1538 card_name[6] = '\0';
1540 lcd_setmargins(0, 0);
1541 lcd_setfont(FONT_SYSFIXED);
1543 while (!done)
1545 card = mmc_card_info(currval / 2);
1547 line = 0;
1548 lcd_clear_display();
1549 snprintf(pbuf, sizeof(pbuf), "[MMC%d p%d]", currval / 2,
1550 (currval % 2) + 1);
1551 lcd_puts(0, line++, pbuf);
1553 if (card->initialized)
1555 if (!(currval % 2)) /* General info */
1557 int temp;
1559 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1560 snprintf(pbuf, sizeof(pbuf), "%s Rev %d.%d", card_name,
1561 (int) mmc_extract_bits(card->cid, 72, 4),
1562 (int) mmc_extract_bits(card->cid, 76, 4));
1563 lcd_puts(0, line++, pbuf);
1564 snprintf(pbuf, sizeof(pbuf), "Prod: %d/%d",
1565 (int) mmc_extract_bits(card->cid, 112, 4),
1566 (int) mmc_extract_bits(card->cid, 116, 4) + 1997);
1567 lcd_puts(0, line++, pbuf);
1568 snprintf(pbuf, sizeof(pbuf), "Ser#: 0x%08lx",
1569 mmc_extract_bits(card->cid, 80, 32));
1570 lcd_puts(0, line++, pbuf);
1571 snprintf(pbuf, sizeof(pbuf), "M=%02x, O=%04x",
1572 (int) mmc_extract_bits(card->cid, 0, 8),
1573 (int) mmc_extract_bits(card->cid, 8, 16));
1574 lcd_puts(0, line++, pbuf);
1575 temp = mmc_extract_bits(card->csd, 2, 4);
1576 snprintf(pbuf, sizeof(pbuf), "MMC v%s", temp < 5 ?
1577 spec_vers[temp] : "?.?");
1578 lcd_puts(0, line++, pbuf);
1579 snprintf(pbuf, sizeof(pbuf), "Blocks: 0x%06lx", card->numblocks);
1580 lcd_puts(0, line++, pbuf);
1581 snprintf(pbuf, sizeof(pbuf), "Blksz.: %d P:%c%c", card->blocksize,
1582 mmc_extract_bits(card->csd, 48, 1) ? 'R' : '-',
1583 mmc_extract_bits(card->csd, 106, 1) ? 'W' : '-');
1584 lcd_puts(0, line++, pbuf);
1586 else /* Technical details */
1588 output_dyn_value(pbuf2, sizeof pbuf2, card->speed / 1000,
1589 kbit_units, false);
1590 snprintf(pbuf, sizeof pbuf, "Speed: %s", pbuf2);
1591 lcd_puts(0, line++, pbuf);
1593 output_dyn_value(pbuf2, sizeof pbuf2, card->tsac,
1594 nsec_units, false);
1595 snprintf(pbuf, sizeof pbuf, "Tsac: %s", pbuf2);
1596 lcd_puts(0, line++, pbuf);
1598 snprintf(pbuf, sizeof(pbuf), "Nsac: %d clk", card->nsac);
1599 lcd_puts(0, line++, pbuf);
1600 snprintf(pbuf, sizeof(pbuf), "R2W: *%d", card->r2w_factor);
1601 lcd_puts(0, line++, pbuf);
1602 snprintf(pbuf, sizeof(pbuf), "IRmax: %d..%d mA",
1603 i_vmin[mmc_extract_bits(card->csd, 66, 3)],
1604 i_vmax[mmc_extract_bits(card->csd, 69, 3)]);
1605 lcd_puts(0, line++, pbuf);
1606 snprintf(pbuf, sizeof(pbuf), "IWmax: %d..%d mA",
1607 i_vmin[mmc_extract_bits(card->csd, 72, 3)],
1608 i_vmax[mmc_extract_bits(card->csd, 75, 3)]);
1609 lcd_puts(0, line++, pbuf);
1612 else
1613 lcd_puts(0, line++, "Not found!");
1615 lcd_update();
1617 switch (get_action(CONTEXT_SETTINGS,HZ/2))
1619 case ACTION_STD_CANCEL:
1620 done = true;
1621 break;
1623 case ACTION_SETTINGS_DEC:
1624 currval--;
1625 if (currval < 0)
1626 currval = 3;
1627 break;
1629 case ACTION_SETTINGS_INC:
1630 currval++;
1631 if (currval > 3)
1632 currval = 0;
1633 break;
1636 action_signalscreenchange();
1637 return false;
1639 #else /* !HAVE_MMC */
1640 static bool dbg_disk_info(void)
1642 char buf[128];
1643 bool done = false;
1644 int i;
1645 int page = 0;
1646 const int max_page = 11;
1647 unsigned short* identify_info = ata_get_identify();
1648 bool timing_info_present = false;
1649 char pio3[2], pio4[2];
1651 lcd_setmargins(0, 0);
1653 while(!done)
1655 int y=0;
1656 int key;
1657 lcd_clear_display();
1658 #ifdef HAVE_LCD_BITMAP
1659 lcd_puts(0, y++, "Disk info:");
1660 y++;
1661 #endif
1663 switch (page) {
1664 case 0:
1665 for (i=0; i < 20; i++)
1666 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1667 buf[40]=0;
1668 /* kill trailing space */
1669 for (i=39; i && buf[i]==' '; i--)
1670 buf[i] = 0;
1671 lcd_puts(0, y++, "Model");
1672 lcd_puts_scroll(0, y++, buf);
1673 break;
1675 case 1:
1676 for (i=0; i < 4; i++)
1677 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1678 buf[8]=0;
1679 lcd_puts(0, y++, "Firmware");
1680 lcd_puts(0, y++, buf);
1681 break;
1683 case 2:
1684 snprintf(buf, sizeof buf, "%ld MB",
1685 ((unsigned long)identify_info[61] << 16 |
1686 (unsigned long)identify_info[60]) / 2048 );
1687 lcd_puts(0, y++, "Size");
1688 lcd_puts(0, y++, buf);
1689 break;
1691 case 3: {
1692 unsigned long free;
1693 fat_size( IF_MV2(0,) NULL, &free );
1694 snprintf(buf, sizeof buf, "%ld MB", free / 1024 );
1695 lcd_puts(0, y++, "Free");
1696 lcd_puts(0, y++, buf);
1697 break;
1700 case 4:
1701 snprintf(buf, sizeof buf, "%d ms", ata_spinup_time * (1000/HZ));
1702 lcd_puts(0, y++, "Spinup time");
1703 lcd_puts(0, y++, buf);
1704 break;
1706 case 5:
1707 i = identify_info[83] & (1<<3);
1708 lcd_puts(0, y++, "Power mgmt:");
1709 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1710 break;
1712 case 6:
1713 i = identify_info[83] & (1<<9);
1714 lcd_puts(0, y++, "Noise mgmt:");
1715 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1716 break;
1718 case 7:
1719 i = identify_info[82] & (1<<6);
1720 lcd_puts(0, y++, "Read-ahead:");
1721 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1722 break;
1724 case 8:
1725 timing_info_present = identify_info[53] & (1<<1);
1726 if(timing_info_present) {
1727 pio3[1] = 0;
1728 pio4[1] = 0;
1729 lcd_puts(0, y++, "PIO modes:");
1730 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1731 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1732 snprintf(buf, 128, "0 1 2 %s %s", pio3, pio4);
1733 lcd_puts(0, y++, buf);
1734 } else {
1735 lcd_puts(0, y++, "No PIO mode info");
1737 break;
1739 case 9:
1740 timing_info_present = identify_info[53] & (1<<1);
1741 if(timing_info_present) {
1742 lcd_puts(0, y++, "Cycle times");
1743 snprintf(buf, 128, "%dns/%dns",
1744 identify_info[67],
1745 identify_info[68]);
1746 lcd_puts(0, y++, buf);
1747 } else {
1748 lcd_puts(0, y++, "No timing info");
1750 break;
1752 case 10:
1753 timing_info_present = identify_info[53] & (1<<1);
1754 if(timing_info_present) {
1755 i = identify_info[49] & (1<<11);
1756 snprintf(buf, 128, "IORDY support: %s", i ? "yes" : "no");
1757 lcd_puts(0, y++, buf);
1758 i = identify_info[49] & (1<<10);
1759 snprintf(buf, 128, "IORDY disable: %s", i ? "yes" : "no");
1760 lcd_puts(0, y++, buf);
1761 } else {
1762 lcd_puts(0, y++, "No timing info");
1764 break;
1766 case 11:
1767 lcd_puts(0, y++, "Cluster size");
1768 snprintf(buf, 128, "%d bytes", fat_get_cluster_size(IF_MV(0)));
1769 lcd_puts(0, y++, buf);
1770 break;
1772 lcd_update();
1774 /* Wait for a key to be pushed */
1775 key = get_action(CONTEXT_SETTINGS,HZ/5);
1776 switch(key) {
1777 case ACTION_STD_CANCEL:
1778 done = true;
1779 break;
1781 case ACTION_SETTINGS_DEC:
1782 if (--page < 0)
1783 page = max_page;
1784 break;
1786 case ACTION_SETTINGS_INC:
1787 if (++page > max_page)
1788 page = 0;
1789 break;
1791 lcd_stop_scroll();
1793 action_signalscreenchange();
1794 return false;
1796 #endif /* !HAVE_MMC */
1797 #endif /* !SIMULATOR */
1799 #ifdef HAVE_DIRCACHE
1800 static bool dbg_dircache_info(void)
1802 bool done = false;
1803 int line;
1804 char buf[32];
1806 lcd_setmargins(0, 0);
1807 lcd_setfont(FONT_SYSFIXED);
1809 while (!done)
1811 line = 0;
1813 lcd_clear_display();
1814 snprintf(buf, sizeof(buf), "Cache initialized: %s",
1815 dircache_is_enabled() ? "Yes" : "No");
1816 lcd_puts(0, line++, buf);
1818 snprintf(buf, sizeof(buf), "Cache size: %d B",
1819 dircache_get_cache_size());
1820 lcd_puts(0, line++, buf);
1822 snprintf(buf, sizeof(buf), "Last size: %d B",
1823 global_status.dircache_size);
1824 lcd_puts(0, line++, buf);
1826 snprintf(buf, sizeof(buf), "Limit: %d B", DIRCACHE_LIMIT);
1827 lcd_puts(0, line++, buf);
1829 snprintf(buf, sizeof(buf), "Reserve: %d/%d B",
1830 dircache_get_reserve_used(), DIRCACHE_RESERVE);
1831 lcd_puts(0, line++, buf);
1833 snprintf(buf, sizeof(buf), "Scanning took: %d s",
1834 dircache_get_build_ticks() / HZ);
1835 lcd_puts(0, line++, buf);
1837 snprintf(buf, sizeof(buf), "Entry count: %d",
1838 dircache_get_entry_count());
1839 lcd_puts(0, line++, buf);
1841 lcd_update();
1843 if (action_userabort(HZ/2))
1844 return false;
1847 return false;
1850 #endif /* HAVE_DIRCACHE */
1852 #ifdef HAVE_LCD_BITMAP
1853 #ifdef HAVE_TAGCACHE
1854 static bool dbg_tagcache_info(void)
1856 bool done = false;
1857 int line;
1858 char buf[32];
1859 struct tagcache_stat *stat;
1861 lcd_setmargins(0, 0);
1862 lcd_setfont(FONT_SYSFIXED);
1864 while (!done)
1866 line = 0;
1868 lcd_clear_display();
1869 stat = tagcache_get_stat();
1870 snprintf(buf, sizeof(buf), "Initialized: %s", stat->initialized ? "Yes" : "No");
1871 lcd_puts(0, line++, buf);
1872 snprintf(buf, sizeof(buf), "DB Ready: %s", stat->ready ? "Yes" : "No");
1873 lcd_puts(0, line++, buf);
1874 snprintf(buf, sizeof(buf), "RAM Cache: %s", stat->ramcache ? "Yes" : "No");
1875 lcd_puts(0, line++, buf);
1876 snprintf(buf, sizeof(buf), "RAM: %d/%d B",
1877 stat->ramcache_used, stat->ramcache_allocated);
1878 lcd_puts(0, line++, buf);
1879 snprintf(buf, sizeof(buf), "Progress: %d%% (%d entries)",
1880 stat->progress, stat->processed_entries);
1881 lcd_puts(0, line++, buf);
1882 snprintf(buf, sizeof(buf), "Commit step: %d", stat->commit_step);
1883 lcd_puts(0, line++, buf);
1884 snprintf(buf, sizeof(buf), "Commit delayed: %s",
1885 stat->commit_delayed ? "Yes" : "No");
1886 lcd_puts(0, line++, buf);
1888 lcd_update();
1890 if (action_userabort(HZ/2))
1891 return false;
1894 return false;
1896 #endif
1897 #endif
1899 #if CONFIG_CPU == SH7034
1900 static bool dbg_save_roms(void)
1902 int fd;
1903 int oldmode = system_memory_guard(MEMGUARD_NONE);
1905 fd = creat("/internal_rom_0000-FFFF.bin");
1906 if(fd >= 0)
1908 write(fd, (void *)0, 0x10000);
1909 close(fd);
1912 fd = creat("/internal_rom_2000000-203FFFF.bin");
1913 if(fd >= 0)
1915 write(fd, (void *)0x2000000, 0x40000);
1916 close(fd);
1919 system_memory_guard(oldmode);
1920 return false;
1922 #elif defined CPU_COLDFIRE
1923 static bool dbg_save_roms(void)
1925 int fd;
1926 int oldmode = system_memory_guard(MEMGUARD_NONE);
1928 #if defined(IRIVER_H100_SERIES)
1929 fd = creat("/internal_rom_000000-1FFFFF.bin");
1930 #elif defined(IRIVER_H300_SERIES)
1931 fd = creat("/internal_rom_000000-3FFFFF.bin");
1932 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5)
1933 fd = creat("/internal_rom_000000-3FFFFF.bin");
1934 #endif
1935 if(fd >= 0)
1937 write(fd, (void *)0, FLASH_SIZE);
1938 close(fd);
1940 system_memory_guard(oldmode);
1942 #ifdef HAVE_EEPROM
1943 fd = creat("/internal_eeprom.bin");
1944 if (fd >= 0)
1946 int old_irq_level;
1947 char buf[EEPROM_SIZE];
1948 int err;
1950 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
1952 err = eeprom_24cxx_read(0, buf, sizeof buf);
1953 if (err)
1954 gui_syncsplash(HZ*3, "Eeprom read failure (%d)",err);
1955 else
1957 write(fd, buf, sizeof buf);
1960 set_irq_level(old_irq_level);
1962 close(fd);
1964 #endif
1966 return false;
1968 #elif defined(CPU_PP) && !defined(SANSA_E200)
1969 static bool dbg_save_roms(void)
1971 int fd;
1973 fd = creat("/internal_rom_000000-0FFFFF.bin");
1974 if(fd >= 0)
1976 write(fd, (void *)0x20000000, FLASH_SIZE);
1977 close(fd);
1980 return false;
1982 #endif /* CPU */
1984 #ifndef SIMULATOR
1985 #if CONFIG_TUNER
1986 static bool dbg_fm_radio(void)
1988 char buf[32];
1989 bool fm_detected;
1991 lcd_setmargins(0, 0);
1993 while(1)
1995 int row = 0;
1997 lcd_clear_display();
1998 fm_detected = radio_hardware_present();
2000 snprintf(buf, sizeof buf, "HW detected: %s", fm_detected?"yes":"no");
2001 lcd_puts(0, row++, buf);
2003 #if (CONFIG_TUNER & S1A0903X01)
2004 snprintf(buf, sizeof buf, "Samsung regs: %08X",
2005 samsung_get(RADIO_ALL));
2006 lcd_puts(0, row++, buf);
2007 #endif
2008 #if (CONFIG_TUNER & TEA5767)
2010 struct philips_dbg_info info;
2011 philips_dbg_info(&info);
2013 snprintf(buf, sizeof buf, "Philips regs:");
2014 lcd_puts(0, row++, buf);
2016 snprintf(buf, sizeof buf, " Read: %02X %02X %02X %02X %02X",
2017 (unsigned)info.read_regs[0], (unsigned)info.read_regs[1],
2018 (unsigned)info.read_regs[2], (unsigned)info.read_regs[3],
2019 (unsigned)info.read_regs[4]);
2020 lcd_puts(0, row++, buf);
2022 snprintf(buf, sizeof buf, " Write: %02X %02X %02X %02X %02X",
2023 (unsigned)info.write_regs[0], (unsigned)info.write_regs[1],
2024 (unsigned)info.write_regs[2], (unsigned)info.write_regs[3],
2025 (unsigned)info.write_regs[4]);
2026 lcd_puts(0, row++, buf);
2028 #endif
2029 lcd_update();
2031 if (action_userabort(HZ))
2032 return false;
2034 return false;
2036 #endif /* CONFIG_TUNER */
2037 #endif /* !SIMULATOR */
2039 #ifdef HAVE_LCD_BITMAP
2040 extern bool do_screendump_instead_of_usb;
2042 static bool dbg_screendump(void)
2044 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2045 gui_syncsplash(HZ, "Screendump %s",
2046 do_screendump_instead_of_usb?"enabled":"disabled");
2047 return false;
2049 #endif /* HAVE_LCD_BITMAP */
2051 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2052 static bool dbg_set_memory_guard(void)
2054 static const struct opt_items names[MAXMEMGUARD] = {
2055 { "None", -1 },
2056 { "Flash ROM writes", -1 },
2057 { "Zero area (all)", -1 }
2059 int mode = system_memory_guard(MEMGUARD_KEEP);
2061 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2062 system_memory_guard(mode);
2064 return false;
2066 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2068 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2070 extern volatile bool lcd_poweroff;
2072 static bool dbg_lcd_power_off(void)
2074 lcd_setmargins(0, 0);
2076 while(1)
2078 int button;
2080 lcd_clear_display();
2081 lcd_puts(0, 0, "LCD Power Off");
2082 if(lcd_poweroff)
2083 lcd_puts(1, 1, "Yes");
2084 else
2085 lcd_puts(1, 1, "No");
2087 lcd_update();
2089 button = get_action(CONTEXT_STD,HZ/5);
2090 switch(button)
2092 case ACTION_STD_PREV:
2093 case ACTION_STD_NEXT:
2094 lcd_poweroff = !lcd_poweroff;
2095 break;
2096 case ACTION_STD_OK:
2097 case ACTION_STD_CANCEL:
2098 action_signalscreenchange();
2099 return false;
2100 default:
2101 sleep(HZ/10);
2102 break;
2105 return false;
2107 #endif
2109 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2110 static bool dbg_write_eeprom(void)
2112 int fd;
2113 int rc;
2114 int old_irq_level;
2115 char buf[EEPROM_SIZE];
2116 int err;
2118 fd = open("/internal_eeprom.bin", O_RDONLY);
2120 if (fd >= 0)
2122 rc = read(fd, buf, EEPROM_SIZE);
2124 if(rc == EEPROM_SIZE)
2126 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
2128 err = eeprom_24cxx_write(0, buf, sizeof buf);
2129 if (err)
2130 gui_syncsplash(HZ*3, "Eeprom write failure (%d)",err);
2131 else
2132 gui_syncsplash(HZ*3, "Eeprom written successfully");
2134 set_irq_level(old_irq_level);
2136 else
2138 gui_syncsplash(HZ*3, "File read error (%d)",rc);
2140 close(fd);
2142 else
2144 gui_syncsplash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2147 return false;
2149 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2150 #ifdef CPU_BOOST_LOGGING
2151 static bool cpu_boost_log(void)
2153 int i = 0,j=0;
2154 int count = cpu_boost_log_getcount();
2155 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2156 char *str;
2157 bool done;
2158 lcd_setmargins(0, 0);
2159 lcd_setfont(FONT_SYSFIXED);
2160 str = cpu_boost_log_getlog_first();
2161 while (i < count)
2163 lcd_clear_display();
2164 for(j=0; j<lines; j++,i++)
2166 if (!str)
2167 str = cpu_boost_log_getlog_next();
2168 if (str)
2170 lcd_puts(0, j,str);
2172 str = NULL;
2174 lcd_update();
2175 done = false;
2176 action_signalscreenchange();
2177 while (!done)
2179 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2181 case ACTION_STD_OK:
2182 case ACTION_STD_PREV:
2183 case ACTION_STD_NEXT:
2184 done = true;
2185 break;
2186 case ACTION_STD_CANCEL:
2187 i = count;
2188 done = true;
2189 break;
2193 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2194 lcd_setfont(FONT_UI);
2195 action_signalscreenchange();
2196 return false;
2198 #endif
2202 /****** The menu *********/
2203 struct the_menu_item {
2204 unsigned char *desc; /* string or ID */
2205 bool (*function) (void); /* return true if USB was connected */
2207 static const struct the_menu_item menuitems[] = {
2208 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2209 { "LCD Power Off", dbg_lcd_power_off },
2210 #endif
2211 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2212 (defined(CPU_PP) && !defined(SANSA_E200))
2213 { "Dump ROM contents", dbg_save_roms },
2214 #endif
2215 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) || CONFIG_CPU == S3C2440
2216 { "View I/O ports", dbg_ports },
2217 #endif
2218 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2219 { "CPU frequency", dbg_cpufreq },
2220 #endif
2221 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2222 { "S/PDIF analyzer", dbg_spdif },
2223 #endif
2224 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2225 { "Catch mem accesses", dbg_set_memory_guard },
2226 #endif
2227 #ifndef SIMULATOR
2228 { "View OS stacks", dbg_os },
2229 #endif
2230 #ifdef HAVE_LCD_BITMAP
2231 #ifndef SIMULATOR
2232 { "View battery", view_battery },
2233 #endif
2234 { "Screendump", dbg_screendump },
2235 #endif
2236 #ifndef SIMULATOR
2237 { "View HW info", dbg_hw_info },
2238 #endif
2239 #ifndef SIMULATOR
2240 { "View partitions", dbg_partitions },
2241 #endif
2242 #ifndef SIMULATOR
2243 #ifdef HAVE_MMC
2244 { "View MMC info", dbg_mmc_info },
2245 #else
2246 { "View disk info", dbg_disk_info },
2247 #endif
2248 #endif
2249 #ifdef HAVE_DIRCACHE
2250 { "View dircache info", dbg_dircache_info },
2251 #endif
2252 #ifdef HAVE_LCD_BITMAP
2253 #ifdef HAVE_TAGCACHE
2254 { "View database info", dbg_tagcache_info },
2255 #endif
2256 #if CONFIG_CODEC == SWCODEC || !defined(SIMULATOR)
2257 { "View audio thread", dbg_audio_thread },
2258 #endif
2259 #ifdef PM_DEBUG
2260 { "pm histogram", peak_meter_histogram},
2261 #endif /* PM_DEBUG */
2262 #endif /* HAVE_LCD_BITMAP */
2263 #ifndef SIMULATOR
2264 #if CONFIG_TUNER
2265 { "FM Radio", dbg_fm_radio },
2266 #endif
2267 #endif
2268 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2269 { "Write back EEPROM", dbg_write_eeprom },
2270 #endif
2271 #ifdef ROCKBOX_HAS_LOGF
2272 {"logf", logfdisplay },
2273 {"logfdump", logfdump },
2274 #endif
2275 #ifdef CPU_BOOST_LOGGING
2276 {"cpu_boost log",cpu_boost_log},
2277 #endif
2279 static int menu_action_callback(int btn, struct gui_synclist *lists)
2281 if (btn == ACTION_STD_OK)
2283 menuitems[gui_synclist_get_sel_pos(lists)].function();
2284 gui_synclist_draw(lists);
2286 return btn;
2288 static char* dbg_menu_getname(int item, void * data, char *buffer)
2290 (void)data; (void)buffer;
2291 return menuitems[item].desc;
2293 bool debug_menu(void)
2295 dbg_list("Debug Menu",ARRAYLEN(menuitems) , 1,
2296 menu_action_callback,
2297 dbg_menu_getname);
2298 return false;