rbutil: Add quessing of the Drive letter via Windows API, also restructuring for...
[kugel-rb.git] / apps / debug_menu.c
blob691e9f50701f4742638540b6c0d3bbf5f8124c7e
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 char* dbg_menu_getname(int item, void * data, char *buffer);
92 static bool dbg_list(char *title, int count, int selection_size,
93 int (*action_callback)(int btn, struct gui_synclist *lists),
94 char* (*dbg_getname)(int item, void * data, char *buffer))
96 struct gui_synclist lists;
97 int action;
99 gui_synclist_init(&lists, dbg_getname, NULL, false, selection_size);
100 gui_synclist_set_title(&lists, title, NOICON);
101 gui_synclist_set_icon_callback(&lists, NULL);
102 gui_synclist_set_nb_items(&lists, count*selection_size);
103 if (dbg_getname != dbg_menu_getname)
104 gui_synclist_hide_selection_marker(&lists, true);
105 action_signalscreenchange();
106 gui_synclist_draw(&lists);
107 while(1)
109 gui_syncstatusbar_draw(&statusbars, true);
110 action = get_action(CONTEXT_STD, HZ/5);
111 if (gui_synclist_do_button(&lists, action, LIST_WRAP_UNLESS_HELD))
112 gui_synclist_draw(&lists);
113 if (action_callback)
114 action = action_callback(action, &lists);
115 if (action == ACTION_STD_CANCEL)
116 break;
117 else if(default_event_handler(action) == SYS_USB_CONNECTED)
118 return true;
120 action_signalscreenchange();
121 return false;
123 /*---------------------------------------------------*/
124 /* SPECIAL DEBUG STUFF */
125 /*---------------------------------------------------*/
126 extern struct thread_entry threads[MAXTHREADS];
129 #ifndef SIMULATOR
130 static char thread_status_char(int status)
132 switch (status)
134 case STATE_RUNNING : return 'R';
135 case STATE_BLOCKED : return 'B';
136 case STATE_SLEEPING : return 'S';
137 case STATE_BLOCKED_W_TMO: return 'T';
140 return '?';
142 #if NUM_CORES > 1
143 #define IF_COP2(...) __VA_ARGS__
144 #else
145 #define IF_COP2(...)
146 #endif
147 static char* threads_getname(int selected_item, void * data, char *buffer)
149 (void)data;
150 struct thread_entry *thread = NULL;
151 int status, usage;
152 thread = &threads[selected_item];
154 if (thread->name == NULL)
156 snprintf(buffer, MAX_PATH, "%2d: ---", selected_item);
157 return buffer;
160 usage = thread_stack_usage(thread);
161 status = thread_get_status(thread);
162 #ifdef HAVE_PRIORITY_SCHEDULING
163 snprintf(buffer, MAX_PATH, "%2d: " IF_COP2("(%d) ") "%c%c %d %2d%% %s",
164 selected_item,
165 IF_COP2(thread->core,)
166 (status == STATE_RUNNING) ? '*' : ' ',
167 thread_status_char(status),
168 thread->priority,
169 usage, thread->name);
170 #else
171 snprintf(buffer, MAX_PATH, "%2d: " IF_COP2("(%d) ") "%c%c %2d%% %s",
172 selected_item,
173 IF_COP2(thread->core,)
174 (status == STATE_RUNNING) ? '*' : ' ',
175 thread_status_char(status),
176 usage, thread->name);
177 #endif
178 return buffer;
180 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
182 #ifdef ROCKBOX_HAS_LOGF
183 if (action == ACTION_STD_OK)
185 struct thread_entry *thread = &threads[gui_synclist_get_sel_pos(lists)];
186 if (thread->name != NULL)
187 remove_thread(thread);
189 #endif
190 gui_synclist_draw(lists);
191 return action;
193 /* Test code!!! */
194 static bool dbg_os(void)
196 return dbg_list(IF_COP2("Core and ") "Stack usage:", MAXTHREADS, 1,
197 dbg_threads_action_callback, threads_getname);
199 #endif /* !SIMULATOR */
201 #ifdef HAVE_LCD_BITMAP
202 #if CONFIG_CODEC != SWCODEC
203 #ifndef SIMULATOR
204 static bool dbg_audio_thread(void)
206 char buf[32];
207 struct audio_debug d;
209 lcd_setmargins(0, 0);
210 lcd_setfont(FONT_SYSFIXED);
212 while(1)
214 if (action_userabort(HZ/5))
215 return false;
217 audio_get_debugdata(&d);
219 lcd_clear_display();
221 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
222 lcd_puts(0, 0, buf);
223 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
224 lcd_puts(0, 1, buf);
225 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
226 lcd_puts(0, 2, buf);
227 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
228 lcd_puts(0, 3, buf);
229 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
230 lcd_puts(0, 4, buf);
231 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
232 lcd_puts(0, 5, buf);
234 /* Playable space left */
235 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
236 d.playable_space, HORIZONTAL);
238 /* Show the watermark limit */
239 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
240 d.low_watermark_level, HORIZONTAL);
242 snprintf(buf, sizeof(buf), "wm: %x - %x",
243 d.low_watermark_level, d.lowest_watermark_level);
244 lcd_puts(0, 7, buf);
246 lcd_update();
248 return false;
250 #endif /* !SIMULATOR */
251 #else /* CONFIG_CODEC == SWCODEC */
252 extern size_t filebuflen;
253 /* This is a size_t, but call it a long so it puts a - when it's bad. */
255 static unsigned int ticks, boost_ticks;
257 static void dbg_audio_task(void)
259 #ifndef SIMULATOR
260 if(FREQ > CPUFREQ_NORMAL)
261 boost_ticks++;
262 #endif
264 ticks++;
267 static bool dbg_audio_thread(void)
269 char buf[32];
270 int button;
271 int line;
272 bool done = false;
273 size_t bufused;
274 size_t bufsize = pcmbuf_get_bufsize();
275 int pcmbufdescs = pcmbuf_descs();
277 ticks = boost_ticks = 0;
279 tick_add_task(dbg_audio_task);
281 lcd_setmargins(0, 0);
282 lcd_setfont(FONT_SYSFIXED);
283 while(!done)
285 button = get_action(CONTEXT_STD,HZ/5);
286 switch(button)
288 case ACTION_STD_NEXT:
289 audio_next();
290 break;
291 case ACTION_STD_PREV:
292 audio_prev();
293 break;
294 case ACTION_STD_CANCEL:
295 done = true;
296 break;
298 action_signalscreenchange();
299 line = 0;
301 lcd_clear_display();
303 bufused = bufsize - pcmbuf_free();
305 snprintf(buf, sizeof(buf), "pcm: %7ld/%7ld", (long) bufused, (long) bufsize);
306 lcd_puts(0, line++, buf);
308 /* Playable space left */
309 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6, bufsize, 0, bufused, HORIZONTAL);
310 line++;
312 snprintf(buf, sizeof(buf), "codec: %8ld/%8ld", audio_filebufused(), (long) filebuflen);
313 lcd_puts(0, line++, buf);
315 /* Playable space left */
316 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6, filebuflen, 0,
317 audio_filebufused(), HORIZONTAL);
318 line++;
320 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
321 lcd_puts(0, line++, buf);
323 #ifndef SIMULATOR
324 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
325 (int)((FREQ + 500000) / 1000000));
326 lcd_puts(0, line++, buf);
327 #endif
329 if (ticks > 0)
331 snprintf(buf, sizeof(buf), "boost ratio: %3d%%",
332 boost_ticks * 100 / ticks);
333 lcd_puts(0, line++, buf);
336 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
337 pcmbuf_used_descs(), pcmbufdescs);
338 lcd_puts(0, line++, buf);
340 lcd_update();
343 tick_remove_task(dbg_audio_task);
345 return false;
347 #endif /* CONFIG_CODEC */
348 #endif /* HAVE_LCD_BITMAP */
351 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
352 /* Tool function to read the flash manufacturer and type, if available.
353 Only chips which could be reprogrammed in system will return values.
354 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
355 /* In IRAM to avoid problems when running directly from Flash */
356 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
357 unsigned addr1, unsigned addr2)
358 ICODE_ATTR __attribute__((noinline));
359 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
360 unsigned addr1, unsigned addr2)
363 unsigned not_manu, not_id; /* read values before switching to ID mode */
364 unsigned manu, id; /* read values when in ID mode */
366 #if CONFIG_CPU == SH7034
367 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
368 #elif defined(CPU_COLDFIRE)
369 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
370 #endif
371 int old_level; /* saved interrupt level */
373 not_manu = flash[0]; /* read the normal content */
374 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
376 /* disable interrupts, prevent any stray flash access */
377 old_level = set_irq_level(HIGHEST_IRQ_LEVEL);
379 flash[addr1] = 0xAA; /* enter command mode */
380 flash[addr2] = 0x55;
381 flash[addr1] = 0x90; /* ID command */
382 /* Atmel wants 20ms pause here */
383 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
385 manu = flash[0]; /* read the IDs */
386 id = flash[1];
388 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
389 /* Atmel wants 20ms pause here */
390 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
392 set_irq_level(old_level); /* enable interrupts again */
394 /* I assume success if the obtained values are different from
395 the normal flash content. This is not perfectly bulletproof, they
396 could theoretically be the same by chance, causing us to fail. */
397 if (not_manu != manu || not_id != id) /* a value has changed */
399 *p_manufacturer = manu; /* return the results */
400 *p_device = id;
401 return true; /* success */
403 return false; /* fail */
405 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
407 #ifndef SIMULATOR
408 #ifdef HAVE_LCD_BITMAP
409 static bool dbg_hw_info(void)
411 #if CONFIG_CPU == SH7034
412 char buf[32];
413 int bitmask = HW_MASK;
414 int rom_version = ROM_VERSION;
415 unsigned manu, id; /* flash IDs */
416 bool got_id; /* flag if we managed to get the flash IDs */
417 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
418 bool has_bootrom; /* flag for boot ROM present */
419 int oldmode; /* saved memory guard mode */
421 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
423 /* get flash ROM type */
424 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
425 if (!got_id)
426 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
428 /* check if the boot ROM area is a flash mirror */
429 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
430 if (has_bootrom) /* if ROM and Flash different */
432 /* calculate CRC16 checksum of boot ROM */
433 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
436 system_memory_guard(oldmode); /* re-enable memory guard */
438 lcd_setmargins(0, 0);
439 lcd_setfont(FONT_SYSFIXED);
440 lcd_clear_display();
442 lcd_puts(0, 0, "[Hardware info]");
444 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
445 lcd_puts(0, 1, buf);
447 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
448 lcd_puts(0, 2, buf);
450 if (got_id)
451 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
452 else
453 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
454 lcd_puts(0, 3, buf);
456 if (has_bootrom)
458 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
459 snprintf(buf, 32, "Boot ROM: V1");
460 else
461 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
463 else
465 snprintf(buf, 32, "Boot ROM: none");
467 lcd_puts(0, 4, buf);
469 lcd_update();
471 while(1)
473 if (action_userabort(TIMEOUT_BLOCK))
474 return false;
476 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
477 char buf[32];
478 unsigned manu, id; /* flash IDs */
479 int got_id; /* flag if we managed to get the flash IDs */
480 int oldmode; /* saved memory guard mode */
481 int line = 0;
483 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
485 /* get flash ROM type */
486 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
487 if (!got_id)
488 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
490 system_memory_guard(oldmode); /* re-enable memory guard */
492 lcd_setmargins(0, 0);
493 lcd_setfont(FONT_SYSFIXED);
494 lcd_clear_display();
496 lcd_puts(0, line++, "[Hardware info]");
498 if (got_id)
499 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
500 else
501 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
502 lcd_puts(0, line++, buf);
504 #ifdef IAUDIO_X5
506 struct ds2411_id id;
508 lcd_puts(0, ++line, "Serial Number:");
510 got_id = ds2411_read_id(&id);
512 if (got_id == DS2411_OK)
514 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
515 lcd_puts(0, ++line, buf);
516 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
517 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
518 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
519 lcd_puts(0, ++line, buf);
520 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
522 else
524 snprintf(buf, 32, "READ ERR=%d", got_id);
527 lcd_puts(0, ++line, buf);
529 #endif
531 lcd_update();
533 while(1)
535 if (action_userabort(TIMEOUT_BLOCK))
536 return false;
538 #elif CONFIG_CPU == PP5020
539 char buf[32];
540 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
541 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
542 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
543 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
545 lcd_setmargins(0, 0);
546 lcd_setfont(FONT_SYSFIXED);
547 lcd_clear_display();
549 lcd_puts(0, 0, "[Hardware info]");
551 snprintf(buf, sizeof(buf), "HW rev: 0x%08x", ipod_hw_rev);
552 lcd_puts(0, 1, buf);
554 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
555 lcd_puts(0, 2, buf);
556 lcd_update();
558 while(1)
560 if (action_userabort(TIMEOUT_BLOCK))
561 return false;
563 #endif /* CONFIG_CPU */
564 return false;
566 #else /* !HAVE_LCD_BITMAP */
567 static bool dbg_hw_info(void)
569 char buf[32];
570 int button;
571 int currval = 0;
572 int rom_version = ROM_VERSION;
573 unsigned manu, id; /* flash IDs */
574 bool got_id; /* flag if we managed to get the flash IDs */
575 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
576 bool has_bootrom; /* flag for boot ROM present */
577 int oldmode; /* saved memory guard mode */
579 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
581 /* get flash ROM type */
582 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
583 if (!got_id)
584 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
586 /* check if the boot ROM area is a flash mirror */
587 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
588 if (has_bootrom) /* if ROM and Flash different */
590 /* calculate CRC16 checksum of boot ROM */
591 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
594 system_memory_guard(oldmode); /* re-enable memory guard */
596 lcd_clear_display();
598 lcd_puts(0, 0, "[HW Info]");
599 while(1)
601 switch(currval)
603 case 0:
604 snprintf(buf, 32, "ROM: %d.%02d",
605 rom_version/100, rom_version%100);
606 break;
607 case 1:
608 if (got_id)
609 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
610 else
611 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
612 break;
613 case 2:
614 if (has_bootrom)
616 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
617 snprintf(buf, 32, "BootROM: V1");
618 else if (rom_crc == 0x358099E8)
619 snprintf(buf, 32, "BootROM: V2");
620 /* alternative boot ROM found in one single player so far */
621 else
622 snprintf(buf, 32, "R: %08x", rom_crc);
624 else
625 snprintf(buf, 32, "BootROM: no");
628 lcd_puts(0, 1, buf);
629 lcd_update();
631 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
633 switch(button)
635 case ACTION_STD_CANCEL:
636 action_signalscreenchange();
637 return false;
639 case ACTION_SETTINGS_DEC:
640 currval--;
641 if(currval < 0)
642 currval = 2;
643 break;
645 case ACTION_SETTINGS_INC:
646 currval++;
647 if(currval > 2)
648 currval = 0;
649 break;
652 return false;
654 #endif /* !HAVE_LCD_BITMAP */
655 #endif /* !SIMULATOR */
657 #ifndef SIMULATOR
658 static char* dbg_partitions_getname(int selected_item, void * data, char *buffer)
660 (void)data;
661 int partition = selected_item/2;
662 struct partinfo* p = disk_partinfo(partition);
663 if (selected_item%2)
665 snprintf(buffer, MAX_PATH, " T:%x %ld MB", p->type, p->size / 2048);
667 else
669 snprintf(buffer, MAX_PATH, "P%d: S:%lx", partition, p->start);
671 return buffer;
674 bool dbg_partitions(void)
676 return dbg_list("Partition Info", 4, 2,
677 NULL, dbg_partitions_getname);
679 #endif
681 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
682 static bool dbg_spdif(void)
684 char buf[128];
685 int line;
686 unsigned int control;
687 int x;
688 char *s;
689 int category;
690 int generation;
691 unsigned int interruptstat;
692 bool valnogood, symbolerr, parityerr;
693 bool done = false;
694 bool spdif_src_on;
695 int spdif_source = spdif_get_output_source(&spdif_src_on);
696 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
698 lcd_setmargins(0, 0);
699 lcd_clear_display();
700 lcd_setfont(FONT_SYSFIXED);
702 #ifdef HAVE_SPDIF_POWER
703 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
704 #endif
706 while (!done)
708 line = 0;
710 control = EBU1RCVCCHANNEL1;
711 interruptstat = INTERRUPTSTAT;
712 INTERRUPTCLEAR = 0x03c00000;
714 valnogood = (interruptstat & 0x01000000)?true:false;
715 symbolerr = (interruptstat & 0x00800000)?true:false;
716 parityerr = (interruptstat & 0x00400000)?true:false;
718 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
719 valnogood?"--":"OK",
720 symbolerr?"--":"OK",
721 parityerr?"--":"OK");
722 lcd_puts(0, line++, buf);
724 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
725 lcd_puts(0, line++, buf);
727 line++;
729 x = control >> 31;
730 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
731 x, x?"Professional":"Consumer");
732 lcd_puts(0, line++, buf);
734 x = (control >> 30) & 1;
735 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
736 x, x?"Non-PCM":"PCM");
737 lcd_puts(0, line++, buf);
739 x = (control >> 29) & 1;
740 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
741 x, x?"Permitted":"Inhibited");
742 lcd_puts(0, line++, buf);
744 x = (control >> 27) & 7;
745 switch(x)
747 case 0:
748 s = "None";
749 break;
750 case 1:
751 s = "50/15us";
752 break;
753 default:
754 s = "Reserved";
755 break;
757 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
758 lcd_puts(0, line++, buf);
760 x = (control >> 24) & 3;
761 snprintf(buf, sizeof(buf), "Mode: %d", x);
762 lcd_puts(0, line++, buf);
764 category = (control >> 17) & 127;
765 switch(category)
767 case 0x00:
768 s = "General";
769 break;
770 case 0x40:
771 s = "Audio CD";
772 break;
773 default:
774 s = "Unknown";
776 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
777 lcd_puts(0, line++, buf);
779 x = (control >> 16) & 1;
780 generation = x;
781 if(((category & 0x70) == 0x10) ||
782 ((category & 0x70) == 0x40) ||
783 ((category & 0x78) == 0x38))
785 generation = !generation;
787 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
788 x, generation?"Original":"No ind.");
789 lcd_puts(0, line++, buf);
791 x = (control >> 12) & 15;
792 snprintf(buf, sizeof(buf), "Source: %d", x);
793 lcd_puts(0, line++, buf);
795 x = (control >> 8) & 15;
796 switch(x)
798 case 0:
799 s = "Unspecified";
800 break;
801 case 8:
802 s = "A (Left)";
803 break;
804 case 4:
805 s = "B (Right)";
806 break;
807 default:
808 s = "";
809 break;
811 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
812 lcd_puts(0, line++, buf);
814 x = (control >> 4) & 15;
815 switch(x)
817 case 0:
818 s = "44.1kHz";
819 break;
820 case 0x4:
821 s = "48kHz";
822 break;
823 case 0xc:
824 s = "32kHz";
825 break;
827 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
828 lcd_puts(0, line++, buf);
830 x = (control >> 2) & 3;
831 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
832 lcd_puts(0, line++, buf);
833 line++;
835 #ifndef SIMULATOR
836 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
837 spdif_measure_frequency());
838 lcd_puts(0, line++, buf);
839 #endif
841 lcd_update();
843 if (action_userabort(HZ/10))
844 break;
847 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
849 #ifdef HAVE_SPDIF_POWER
850 spdif_power_enable(global_settings.spdif_enable);
851 #endif
853 return false;
855 #endif /* CPU_COLDFIRE */
857 #ifndef SIMULATOR
858 #ifdef HAVE_LCD_BITMAP
859 /* button definitions */
860 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
861 (CONFIG_KEYPAD == IRIVER_H300_PAD)
862 # define DEBUG_CANCEL BUTTON_OFF
864 #elif CONFIG_KEYPAD == RECORDER_PAD
865 # define DEBUG_CANCEL BUTTON_OFF
867 #elif CONFIG_KEYPAD == ONDIO_PAD
868 # define DEBUG_CANCEL BUTTON_MENU
870 #elif (CONFIG_KEYPAD == IPOD_3G_PAD) || \
871 (CONFIG_KEYPAD == IPOD_4G_PAD)
872 # define DEBUG_CANCEL BUTTON_MENU
874 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
875 # define DEBUG_CANCEL BUTTON_PLAY
877 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
878 # define DEBUG_CANCEL BUTTON_REC
880 #elif CONFIG_KEYPAD == GIGABEAT_PAD
881 # define DEBUG_CANCEL BUTTON_A
883 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
884 # define DEBUG_CANCEL BUTTON_REW
886 #elif CONFIG_KEYPAD == SANSA_E200_PAD
887 # define DEBUG_CANCEL BUTTON_LEFT
888 #endif /* key definitios */
890 /* Test code!!! */
891 bool dbg_ports(void)
893 #if CONFIG_CPU == SH7034
894 unsigned short porta;
895 unsigned short portb;
896 unsigned char portc;
897 char buf[32];
898 int adc_battery_voltage, adc_battery_level;
900 lcd_setfont(FONT_SYSFIXED);
901 lcd_setmargins(0, 0);
902 lcd_clear_display();
904 while(1)
906 porta = PADR;
907 portb = PBDR;
908 portc = PCDR;
910 snprintf(buf, 32, "PADR: %04x", porta);
911 lcd_puts(0, 0, buf);
912 snprintf(buf, 32, "PBDR: %04x", portb);
913 lcd_puts(0, 1, buf);
915 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
916 lcd_puts(0, 2, buf);
917 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
918 lcd_puts(0, 3, buf);
919 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
920 lcd_puts(0, 4, buf);
921 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
922 lcd_puts(0, 5, buf);
924 battery_read_info(NULL, &adc_battery_voltage,
925 &adc_battery_level);
926 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100,
927 adc_battery_voltage % 100, adc_battery_level);
928 lcd_puts(0, 6, buf);
930 lcd_update();
931 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
932 return false;
934 #elif defined(CPU_COLDFIRE)
935 unsigned int gpio_out;
936 unsigned int gpio1_out;
937 unsigned int gpio_read;
938 unsigned int gpio1_read;
939 unsigned int gpio_function;
940 unsigned int gpio1_function;
941 unsigned int gpio_enable;
942 unsigned int gpio1_enable;
943 int adc_buttons, adc_remote;
944 int adc_battery, adc_battery_voltage, adc_battery_level;
945 char buf[128];
946 int line;
948 lcd_setmargins(0, 0);
949 lcd_clear_display();
950 lcd_setfont(FONT_SYSFIXED);
952 while(1)
954 line = 0;
955 gpio_read = GPIO_READ;
956 gpio1_read = GPIO1_READ;
957 gpio_out = GPIO_OUT;
958 gpio1_out = GPIO1_OUT;
959 gpio_function = GPIO_FUNCTION;
960 gpio1_function = GPIO1_FUNCTION;
961 gpio_enable = GPIO_ENABLE;
962 gpio1_enable = GPIO1_ENABLE;
964 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
965 lcd_puts(0, line++, buf);
966 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
967 lcd_puts(0, line++, buf);
968 snprintf(buf, sizeof(buf), "GPIO_FUNCTION: %08x", gpio_function);
969 lcd_puts(0, line++, buf);
970 snprintf(buf, sizeof(buf), "GPIO_ENABLE: %08x", gpio_enable);
971 lcd_puts(0, line++, buf);
973 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
974 lcd_puts(0, line++, buf);
975 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
976 lcd_puts(0, line++, buf);
977 snprintf(buf, sizeof(buf), "GPIO1_FUNCTION: %08x", gpio1_function);
978 lcd_puts(0, line++, buf);
979 snprintf(buf, sizeof(buf), "GPIO1_ENABLE: %08x", gpio1_enable);
980 lcd_puts(0, line++, buf);
982 adc_buttons = adc_read(ADC_BUTTONS);
983 adc_remote = adc_read(ADC_REMOTE);
984 battery_read_info(&adc_battery, &adc_battery_voltage,
985 &adc_battery_level);
986 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
987 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
988 button_scan_enabled() ? '+' : '-', adc_buttons);
989 #else
990 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
991 #endif
992 lcd_puts(0, line++, buf);
993 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
994 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
995 remote_detect() ? '+' : '-', adc_remote);
996 #else
997 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
998 #endif
1000 lcd_puts(0, line++, buf);
1001 snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_battery);
1002 lcd_puts(0, line++, buf);
1003 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1004 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1005 adc_read(ADC_REMOTEDETECT));
1006 lcd_puts(0, line++, buf);
1007 #endif
1009 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100,
1010 adc_battery_voltage % 100, adc_battery_level);
1011 lcd_puts(0, line++, buf);
1013 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1014 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1015 lcd_puts(0, line++, buf);
1016 #endif
1018 lcd_update();
1019 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1020 return false;
1023 #elif CONFIG_CPU == PP5020 || CONFIG_CPU == PP5024
1025 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1026 unsigned int gpio_e, gpio_f, gpio_g, gpio_h;
1027 unsigned int gpio_i, gpio_j, gpio_k, gpio_l;
1029 char buf[128];
1030 int line;
1032 lcd_setmargins(0, 0);
1033 lcd_clear_display();
1034 lcd_setfont(FONT_SYSFIXED);
1036 while(1)
1038 gpio_a = GPIOA_INPUT_VAL;
1039 gpio_b = GPIOB_INPUT_VAL;
1040 gpio_c = GPIOC_INPUT_VAL;
1042 gpio_g = GPIOG_INPUT_VAL;
1043 gpio_h = GPIOH_INPUT_VAL;
1044 gpio_i = GPIOI_INPUT_VAL;
1046 line = 0;
1047 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_G: %02x", gpio_a, gpio_g);
1048 lcd_puts(0, line++, buf);
1049 snprintf(buf, sizeof(buf), "GPIO_B: %02x GPIO_H: %02x", gpio_b, gpio_h);
1050 lcd_puts(0, line++, buf);
1051 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_I: %02x", gpio_c, gpio_i);
1052 lcd_puts(0, line++, buf);
1053 line++;
1055 gpio_d = GPIOD_INPUT_VAL;
1056 gpio_e = GPIOE_INPUT_VAL;
1057 gpio_f = GPIOF_INPUT_VAL;
1059 gpio_j = GPIOJ_INPUT_VAL;
1060 gpio_k = GPIOK_INPUT_VAL;
1061 gpio_l = GPIOL_INPUT_VAL;
1063 snprintf(buf, sizeof(buf), "GPIO_D: %02x GPIO_J: %02x", gpio_d, gpio_j);
1064 lcd_puts(0, line++, buf);
1065 snprintf(buf, sizeof(buf), "GPIO_E: %02x GPIO_K: %02x", gpio_e, gpio_k);
1066 lcd_puts(0, line++, buf);
1067 snprintf(buf, sizeof(buf), "GPIO_F: %02x GPIO_L: %02x", gpio_f, gpio_l);
1068 lcd_puts(0, line++, buf);
1069 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1070 line++;
1071 snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_read(ADC_BATTERY));
1072 lcd_puts(0, line++, buf);
1073 snprintf(buf, sizeof(buf), "ADC_UNKNOWN_1: %02x", adc_read(ADC_UNKNOWN_1));
1074 lcd_puts(0, line++, buf);
1075 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_read(ADC_REMOTE));
1076 lcd_puts(0, line++, buf);
1077 snprintf(buf, sizeof(buf), "ADC_SCROLLPAD: %02x", adc_read(ADC_SCROLLPAD));
1078 lcd_puts(0, line++, buf);
1079 #elif defined(SANSA_E200)
1080 line++;
1081 snprintf(buf, sizeof(buf), "ADC_BVDD: %02x", adc_read(ADC_BVDD));
1082 lcd_puts(0, line++, buf);
1083 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %02x", adc_read(ADC_RTCSUP));
1084 lcd_puts(0, line++, buf);
1085 snprintf(buf, sizeof(buf), "ADC_UVDD: %02x", adc_read(ADC_UVDD));
1086 lcd_puts(0, line++, buf);
1087 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %02x", adc_read(ADC_CHG_IN));
1088 lcd_puts(0, line++, buf);
1089 snprintf(buf, sizeof(buf), "ADC_CVDD: %02x", adc_read(ADC_CVDD));
1090 lcd_puts(0, line++, buf);
1091 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %02x", adc_read(ADC_BATTEMP));
1092 lcd_puts(0, line++, buf);
1093 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %02x", adc_read(ADC_MICSUP1));
1094 lcd_puts(0, line++, buf);
1095 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %02x", adc_read(ADC_MICSUP2));
1096 lcd_puts(0, line++, buf);
1097 snprintf(buf, sizeof(buf), "ADC_VBE1: %02x", adc_read(ADC_VBE1));
1098 lcd_puts(0, line++, buf);
1099 snprintf(buf, sizeof(buf), "ADC_VBE2: %02x", adc_read(ADC_VBE2));
1100 lcd_puts(0, line++, buf);
1101 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1: %02x", adc_read(ADC_I_MICSUP1));
1102 lcd_puts(0, line++, buf);
1103 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2: %02x", adc_read(ADC_I_MICSUP2));
1104 lcd_puts(0, line++, buf);
1105 snprintf(buf, sizeof(buf), "ADC_VBAT: %02x", adc_read(ADC_VBAT));
1106 lcd_puts(0, line++, buf);
1107 #endif
1108 lcd_update();
1109 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1110 return false;
1113 #elif CONFIG_CPU == PP5002
1114 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1116 char buf[128];
1117 int line;
1119 lcd_setmargins(0, 0);
1120 lcd_clear_display();
1121 lcd_setfont(FONT_SYSFIXED);
1123 while(1)
1125 gpio_a = GPIOA_INPUT_VAL;
1126 gpio_b = GPIOB_INPUT_VAL;
1127 gpio_c = GPIOC_INPUT_VAL;
1128 gpio_d = GPIOD_INPUT_VAL;
1130 line = 0;
1131 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x", gpio_a, gpio_b);
1132 lcd_puts(0, line++, buf);
1133 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x", gpio_c, gpio_d);
1134 lcd_puts(0, line++, buf);
1136 lcd_update();
1137 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1138 return false;
1140 #elif CONFIG_CPU == S3C2440
1141 char buf[50];
1142 int line;
1144 lcd_setmargins(0, 0);
1145 lcd_clear_display();
1146 lcd_setfont(FONT_SYSFIXED);
1148 while(1)
1150 line = 0;
1151 snprintf(buf, sizeof(buf), "[Ports and Registers]"); lcd_puts(0, line++, buf);
1153 snprintf(buf, sizeof(buf), "GPACON: %08x GPBCON: %08x", GPACON, GPBCON); lcd_puts(0, line++, buf);
1154 snprintf(buf, sizeof(buf), "GPADAT: %08x GPBDAT: %08x", GPADAT, GPBDAT); lcd_puts(0, line++, buf);
1155 snprintf(buf, sizeof(buf), "GPAUP: %08x GPBUP: %08x", 0, GPBUP); lcd_puts(0, line++, buf);
1156 snprintf(buf, sizeof(buf), "GPCCON: %08x GPDCON: %08x", GPCCON, GPDCON); lcd_puts(0, line++, buf);
1157 snprintf(buf, sizeof(buf), "GPCDAT: %08x GPDDAT: %08x", GPCDAT, GPDDAT); lcd_puts(0, line++, buf);
1158 snprintf(buf, sizeof(buf), "GPCUP: %08x GPDUP: %08x", GPCUP, GPDUP); lcd_puts(0, line++, buf);
1160 snprintf(buf, sizeof(buf), "GPCCON: %08x GPDCON: %08x", GPCCON, GPDCON); lcd_puts(0, line++, buf);
1161 snprintf(buf, sizeof(buf), "GPCDAT: %08x GPDDAT: %08x", GPCDAT, GPDDAT); lcd_puts(0, line++, buf);
1162 snprintf(buf, sizeof(buf), "GPCUP: %08x GPDUP: %08x", GPCUP, GPDUP); lcd_puts(0, line++, buf);
1164 snprintf(buf, sizeof(buf), "GPECON: %08x GPFCON: %08x", GPECON, GPFCON); lcd_puts(0, line++, buf);
1165 snprintf(buf, sizeof(buf), "GPEDAT: %08x GPFDAT: %08x", GPEDAT, GPFDAT); lcd_puts(0, line++, buf);
1166 snprintf(buf, sizeof(buf), "GPEUP: %08x GPFUP: %08x", GPEUP, GPFUP); lcd_puts(0, line++, buf);
1168 snprintf(buf, sizeof(buf), "GPGCON: %08x GPHCON: %08x", GPGCON, GPHCON); lcd_puts(0, line++, buf);
1169 snprintf(buf, sizeof(buf), "GPGDAT: %08x GPHDAT: %08x", GPGDAT, GPHDAT); lcd_puts(0, line++, buf);
1170 snprintf(buf, sizeof(buf), "GPGUP: %08x GPHUP: %08x", GPGUP, GPHUP); lcd_puts(0, line++, buf);
1172 snprintf(buf, sizeof(buf), "GPJCON: %08x", GPJCON); lcd_puts(0, line++, buf);
1173 snprintf(buf, sizeof(buf), "GPJDAT: %08x", GPJDAT); lcd_puts(0, line++, buf);
1174 snprintf(buf, sizeof(buf), "GPJUP: %08x", GPJUP); lcd_puts(0, line++, buf);
1176 line++;
1178 snprintf(buf, sizeof(buf), "SRCPND: %08x INTMOD: %08x", SRCPND, INTMOD); lcd_puts(0, line++, buf);
1179 snprintf(buf, sizeof(buf), "INTMSK: %08x INTPND: %08x", INTMSK, INTPND); lcd_puts(0, line++, buf);
1180 snprintf(buf, sizeof(buf), "CLKCON: %08x CLKSLOW: %08x", CLKCON, CLKSLOW); lcd_puts(0, line++, buf);
1181 lcd_update();
1182 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1183 return false;
1185 #endif /* CPU */
1186 return false;
1188 #else /* !HAVE_LCD_BITMAP */
1189 bool dbg_ports(void)
1191 unsigned short porta;
1192 unsigned short portb;
1193 unsigned char portc;
1194 char buf[32];
1195 int button;
1196 int adc_battery_voltage;
1197 int currval = 0;
1199 lcd_clear_display();
1201 while(1)
1203 porta = PADR;
1204 portb = PBDR;
1205 portc = PCDR;
1207 switch(currval)
1209 case 0:
1210 snprintf(buf, 32, "PADR: %04x", porta);
1211 break;
1212 case 1:
1213 snprintf(buf, 32, "PBDR: %04x", portb);
1214 break;
1215 case 2:
1216 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1217 break;
1218 case 3:
1219 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1220 break;
1221 case 4:
1222 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1223 break;
1224 case 5:
1225 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1226 break;
1227 case 6:
1228 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1229 break;
1230 case 7:
1231 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1232 break;
1233 case 8:
1234 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1235 break;
1236 case 9:
1237 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1238 break;
1239 break;
1241 lcd_puts(0, 0, buf);
1243 battery_read_info(NULL, &adc_battery_voltage, NULL);
1244 snprintf(buf, 32, "Batt: %d.%02dV", adc_battery_voltage / 100,
1245 adc_battery_voltage % 100);
1246 lcd_puts(0, 1, buf);
1247 lcd_update();
1249 button = get_action(CONTEXT_SETTINGS,HZ/5);
1251 switch(button)
1253 case ACTION_STD_CANCEL:
1254 action_signalscreenchange();
1255 return false;
1257 case ACTION_SETTINGS_DEC:
1258 currval--;
1259 if(currval < 0)
1260 currval = 9;
1261 break;
1263 case ACTION_SETTINGS_INC:
1264 currval++;
1265 if(currval > 9)
1266 currval = 0;
1267 break;
1270 return false;
1272 #endif /* !HAVE_LCD_BITMAP */
1273 #endif /* !SIMULATOR */
1275 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1276 static bool dbg_cpufreq(void)
1278 char buf[128];
1279 int line;
1280 int button;
1282 #ifdef HAVE_LCD_BITMAP
1283 lcd_setmargins(0, 0);
1284 lcd_setfont(FONT_SYSFIXED);
1285 #endif
1286 lcd_clear_display();
1288 while(1)
1290 line = 0;
1292 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1293 lcd_puts(0, line++, buf);
1295 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1296 lcd_puts(0, line++, buf);
1298 lcd_update();
1299 button = get_action(CONTEXT_STD,HZ/10);
1301 switch(button)
1303 case ACTION_STD_PREV:
1304 cpu_boost(true);
1305 break;
1307 case ACTION_STD_NEXT:
1308 cpu_boost(false);
1309 break;
1311 case ACTION_STD_OK:
1312 while (get_cpu_boost_counter() > 0)
1313 cpu_boost(false);
1314 set_cpu_frequency(CPUFREQ_DEFAULT);
1315 break;
1317 case ACTION_STD_CANCEL:
1318 action_signalscreenchange();
1319 return false;
1323 return false;
1325 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1327 #ifndef SIMULATOR
1328 #ifdef HAVE_LCD_BITMAP
1330 * view_battery() shows a automatically scaled graph of the battery voltage
1331 * over time. Usable for estimating battery life / charging rate.
1332 * The power_history array is updated in power_thread of powermgmt.c.
1335 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1336 #define BAT_YSPACE (LCD_HEIGHT - 20)
1338 static bool view_battery(void)
1340 int view = 0;
1341 int i, x, y;
1342 unsigned short maxv, minv;
1343 char buf[32];
1345 lcd_setmargins(0, 0);
1346 lcd_setfont(FONT_SYSFIXED);
1348 while(1)
1350 lcd_clear_display();
1351 switch (view) {
1352 case 0: /* voltage history graph */
1353 /* Find maximum and minimum voltage for scaling */
1354 maxv = 0;
1355 minv = 65535;
1356 for (i = 0; i < BAT_LAST_VAL; i++) {
1357 if (power_history[i] > maxv)
1358 maxv = power_history[i];
1359 if (power_history[i] && (power_history[i] < minv))
1361 minv = power_history[i];
1365 if ((minv < 1) || (minv >= 65535))
1366 minv = 1;
1367 if (maxv < 2)
1368 maxv = 2;
1369 if (minv == maxv)
1370 maxv < 65535 ? maxv++ : minv--;
1372 snprintf(buf, 30, "Battery %d.%02d", power_history[0] / 100,
1373 power_history[0] % 100);
1374 lcd_puts(0, 0, buf);
1375 snprintf(buf, 30, "scale %d.%02d-%d.%02d V",
1376 minv / 100, minv % 100, maxv / 100, maxv % 100);
1377 lcd_puts(0, 1, buf);
1379 x = 0;
1380 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1381 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1382 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1383 lcd_vline(x, LCD_HEIGHT-1, 20);
1384 lcd_set_drawmode(DRMODE_SOLID);
1385 lcd_vline(x, LCD_HEIGHT-1,
1386 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1387 x++;
1390 break;
1392 case 1: /* status: */
1393 lcd_puts(0, 0, "Power status:");
1395 battery_read_info(NULL, &y, NULL);
1396 snprintf(buf, 30, "Battery: %d.%02d V", y / 100, y % 100);
1397 lcd_puts(0, 1, buf);
1398 #ifdef ADC_EXT_POWER
1399 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000;
1400 snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100);
1401 lcd_puts(0, 2, buf);
1402 #endif
1403 #if CONFIG_CHARGING
1404 #if CONFIG_CHARGING == CHARGING_CONTROL
1405 snprintf(buf, 30, "Chgr: %s %s",
1406 charger_inserted() ? "present" : "absent",
1407 charger_enabled ? "on" : "off");
1408 lcd_puts(0, 3, buf);
1409 snprintf(buf, 30, "short delta: %d", short_delta);
1410 lcd_puts(0, 5, buf);
1411 snprintf(buf, 30, "long delta: %d", long_delta);
1412 lcd_puts(0, 6, buf);
1413 lcd_puts(0, 7, power_message);
1414 snprintf(buf, 30, "USB Inserted: %s",
1415 usb_inserted() ? "yes" : "no");
1416 lcd_puts(0, 8, buf);
1417 #if defined IRIVER_H300_SERIES
1418 snprintf(buf, 30, "USB Charging Enabled: %s",
1419 usb_charging_enabled() ? "yes" : "no");
1420 lcd_puts(0, 9, buf);
1421 #endif
1422 #else /* CONFIG_CHARGING != CHARGING_CONTROL */
1423 #if defined IPOD_NANO || defined IPOD_VIDEO
1424 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1425 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1426 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1427 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1428 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1430 snprintf(buf, 30, "USB pwr: %s",
1431 usb_pwr ? "present" : "absent");
1432 lcd_puts(0, 3, buf);
1433 snprintf(buf, 30, "EXT pwr: %s",
1434 ext_pwr ? "present" : "absent");
1435 lcd_puts(0, 4, buf);
1436 snprintf(buf, 30, "Battery: %s",
1437 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1438 lcd_puts(0, 5, buf);
1439 snprintf(buf, 30, "Dock mode: %s",
1440 dock ? "enabled" : "disabled");
1441 lcd_puts(0, 6, buf);
1442 snprintf(buf, 30, "Headphone: %s",
1443 headphone ? "connected" : "disconnected");
1444 lcd_puts(0, 7, buf);
1445 #else
1446 snprintf(buf, 30, "Charger: %s",
1447 charger_inserted() ? "present" : "absent");
1448 lcd_puts(0, 3, buf);
1449 #endif
1450 #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1451 #endif /* CONFIG_CHARGING */
1452 break;
1454 case 2: /* voltage deltas: */
1455 lcd_puts(0, 0, "Voltage deltas:");
1457 for (i = 0; i <= 6; i++) {
1458 y = power_history[i] - power_history[i+i];
1459 snprintf(buf, 30, "-%d min: %s%d.%02d V", i,
1460 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 100,
1461 ((y < 0) ? y * -1 : y ) % 100);
1462 lcd_puts(0, i+1, buf);
1464 break;
1466 case 3: /* remaining time estimation: */
1468 #if CONFIG_CHARGING == CHARGING_CONTROL
1469 snprintf(buf, 30, "charge_state: %d", charge_state);
1470 lcd_puts(0, 0, buf);
1472 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1473 lcd_puts(0, 1, buf);
1475 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1476 lcd_puts(0, 2, buf);
1478 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1479 lcd_puts(0, 3, buf);
1481 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1482 lcd_puts(0, 4, buf);
1483 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
1485 snprintf(buf, 30, "Last PwrHist: %d.%02d V",
1486 power_history[0] / 100,
1487 power_history[0] % 100);
1488 lcd_puts(0, 5, buf);
1490 snprintf(buf, 30, "battery level: %d%%", battery_level());
1491 lcd_puts(0, 6, buf);
1493 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1494 lcd_puts(0, 7, buf);
1495 break;
1498 lcd_update();
1500 switch(get_action(CONTEXT_SETTINGS,HZ/2))
1502 case ACTION_SETTINGS_DEC:
1503 if (view)
1504 view--;
1505 break;
1507 case ACTION_SETTINGS_INC:
1508 if (view < 3)
1509 view++;
1510 break;
1512 case ACTION_STD_CANCEL:
1513 action_signalscreenchange();
1514 return false;
1517 return false;
1520 #endif /* HAVE_LCD_BITMAP */
1521 #endif
1523 #ifndef SIMULATOR
1524 #ifdef HAVE_MMC
1525 static bool dbg_mmc_info(void)
1527 bool done = false;
1528 int currval = 0;
1529 int line;
1530 tCardInfo *card;
1531 unsigned char pbuf[32], pbuf2[32];
1532 unsigned char card_name[7];
1534 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1535 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1536 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1537 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1538 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1539 "3.1-3.31", "4.0" };
1541 card_name[6] = '\0';
1543 lcd_setmargins(0, 0);
1544 lcd_setfont(FONT_SYSFIXED);
1546 while (!done)
1548 card = mmc_card_info(currval / 2);
1550 line = 0;
1551 lcd_clear_display();
1552 snprintf(pbuf, sizeof(pbuf), "[MMC%d p%d]", currval / 2,
1553 (currval % 2) + 1);
1554 lcd_puts(0, line++, pbuf);
1556 if (card->initialized)
1558 if (!(currval % 2)) /* General info */
1560 int temp;
1562 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1563 snprintf(pbuf, sizeof(pbuf), "%s Rev %d.%d", card_name,
1564 (int) mmc_extract_bits(card->cid, 72, 4),
1565 (int) mmc_extract_bits(card->cid, 76, 4));
1566 lcd_puts(0, line++, pbuf);
1567 snprintf(pbuf, sizeof(pbuf), "Prod: %d/%d",
1568 (int) mmc_extract_bits(card->cid, 112, 4),
1569 (int) mmc_extract_bits(card->cid, 116, 4) + 1997);
1570 lcd_puts(0, line++, pbuf);
1571 snprintf(pbuf, sizeof(pbuf), "Ser#: 0x%08lx",
1572 mmc_extract_bits(card->cid, 80, 32));
1573 lcd_puts(0, line++, pbuf);
1574 snprintf(pbuf, sizeof(pbuf), "M=%02x, O=%04x",
1575 (int) mmc_extract_bits(card->cid, 0, 8),
1576 (int) mmc_extract_bits(card->cid, 8, 16));
1577 lcd_puts(0, line++, pbuf);
1578 temp = mmc_extract_bits(card->csd, 2, 4);
1579 snprintf(pbuf, sizeof(pbuf), "MMC v%s", temp < 5 ?
1580 spec_vers[temp] : "?.?");
1581 lcd_puts(0, line++, pbuf);
1582 snprintf(pbuf, sizeof(pbuf), "Blocks: 0x%06lx", card->numblocks);
1583 lcd_puts(0, line++, pbuf);
1584 snprintf(pbuf, sizeof(pbuf), "Blksz.: %d P:%c%c", card->blocksize,
1585 mmc_extract_bits(card->csd, 48, 1) ? 'R' : '-',
1586 mmc_extract_bits(card->csd, 106, 1) ? 'W' : '-');
1587 lcd_puts(0, line++, pbuf);
1589 else /* Technical details */
1591 output_dyn_value(pbuf2, sizeof pbuf2, card->speed / 1000,
1592 kbit_units, false);
1593 snprintf(pbuf, sizeof pbuf, "Speed: %s", pbuf2);
1594 lcd_puts(0, line++, pbuf);
1596 output_dyn_value(pbuf2, sizeof pbuf2, card->tsac,
1597 nsec_units, false);
1598 snprintf(pbuf, sizeof pbuf, "Tsac: %s", pbuf2);
1599 lcd_puts(0, line++, pbuf);
1601 snprintf(pbuf, sizeof(pbuf), "Nsac: %d clk", card->nsac);
1602 lcd_puts(0, line++, pbuf);
1603 snprintf(pbuf, sizeof(pbuf), "R2W: *%d", card->r2w_factor);
1604 lcd_puts(0, line++, pbuf);
1605 snprintf(pbuf, sizeof(pbuf), "IRmax: %d..%d mA",
1606 i_vmin[mmc_extract_bits(card->csd, 66, 3)],
1607 i_vmax[mmc_extract_bits(card->csd, 69, 3)]);
1608 lcd_puts(0, line++, pbuf);
1609 snprintf(pbuf, sizeof(pbuf), "IWmax: %d..%d mA",
1610 i_vmin[mmc_extract_bits(card->csd, 72, 3)],
1611 i_vmax[mmc_extract_bits(card->csd, 75, 3)]);
1612 lcd_puts(0, line++, pbuf);
1615 else
1616 lcd_puts(0, line++, "Not found!");
1618 lcd_update();
1620 switch (get_action(CONTEXT_SETTINGS,HZ/2))
1622 case ACTION_STD_CANCEL:
1623 done = true;
1624 break;
1626 case ACTION_SETTINGS_DEC:
1627 currval--;
1628 if (currval < 0)
1629 currval = 3;
1630 break;
1632 case ACTION_SETTINGS_INC:
1633 currval++;
1634 if (currval > 3)
1635 currval = 0;
1636 break;
1639 action_signalscreenchange();
1640 return false;
1642 #else /* !HAVE_MMC */
1643 static bool dbg_disk_info(void)
1645 char buf[128];
1646 bool done = false;
1647 int i;
1648 int page = 0;
1649 const int max_page = 11;
1650 unsigned short* identify_info = ata_get_identify();
1651 bool timing_info_present = false;
1652 char pio3[2], pio4[2];
1654 lcd_setmargins(0, 0);
1656 while(!done)
1658 int y=0;
1659 int key;
1660 lcd_clear_display();
1661 #ifdef HAVE_LCD_BITMAP
1662 lcd_puts(0, y++, "Disk info:");
1663 y++;
1664 #endif
1666 switch (page) {
1667 case 0:
1668 for (i=0; i < 20; i++)
1669 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1670 buf[40]=0;
1671 /* kill trailing space */
1672 for (i=39; i && buf[i]==' '; i--)
1673 buf[i] = 0;
1674 lcd_puts(0, y++, "Model");
1675 lcd_puts_scroll(0, y++, buf);
1676 break;
1678 case 1:
1679 for (i=0; i < 4; i++)
1680 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1681 buf[8]=0;
1682 lcd_puts(0, y++, "Firmware");
1683 lcd_puts(0, y++, buf);
1684 break;
1686 case 2:
1687 snprintf(buf, sizeof buf, "%ld MB",
1688 ((unsigned long)identify_info[61] << 16 |
1689 (unsigned long)identify_info[60]) / 2048 );
1690 lcd_puts(0, y++, "Size");
1691 lcd_puts(0, y++, buf);
1692 break;
1694 case 3: {
1695 unsigned long free;
1696 fat_size( IF_MV2(0,) NULL, &free );
1697 snprintf(buf, sizeof buf, "%ld MB", free / 1024 );
1698 lcd_puts(0, y++, "Free");
1699 lcd_puts(0, y++, buf);
1700 break;
1703 case 4:
1704 snprintf(buf, sizeof buf, "%d ms", ata_spinup_time * (1000/HZ));
1705 lcd_puts(0, y++, "Spinup time");
1706 lcd_puts(0, y++, buf);
1707 break;
1709 case 5:
1710 i = identify_info[83] & (1<<3);
1711 lcd_puts(0, y++, "Power mgmt:");
1712 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1713 break;
1715 case 6:
1716 i = identify_info[83] & (1<<9);
1717 lcd_puts(0, y++, "Noise mgmt:");
1718 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1719 break;
1721 case 7:
1722 i = identify_info[82] & (1<<6);
1723 lcd_puts(0, y++, "Read-ahead:");
1724 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1725 break;
1727 case 8:
1728 timing_info_present = identify_info[53] & (1<<1);
1729 if(timing_info_present) {
1730 pio3[1] = 0;
1731 pio4[1] = 0;
1732 lcd_puts(0, y++, "PIO modes:");
1733 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1734 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1735 snprintf(buf, 128, "0 1 2 %s %s", pio3, pio4);
1736 lcd_puts(0, y++, buf);
1737 } else {
1738 lcd_puts(0, y++, "No PIO mode info");
1740 break;
1742 case 9:
1743 timing_info_present = identify_info[53] & (1<<1);
1744 if(timing_info_present) {
1745 lcd_puts(0, y++, "Cycle times");
1746 snprintf(buf, 128, "%dns/%dns",
1747 identify_info[67],
1748 identify_info[68]);
1749 lcd_puts(0, y++, buf);
1750 } else {
1751 lcd_puts(0, y++, "No timing info");
1753 break;
1755 case 10:
1756 timing_info_present = identify_info[53] & (1<<1);
1757 if(timing_info_present) {
1758 i = identify_info[49] & (1<<11);
1759 snprintf(buf, 128, "IORDY support: %s", i ? "yes" : "no");
1760 lcd_puts(0, y++, buf);
1761 i = identify_info[49] & (1<<10);
1762 snprintf(buf, 128, "IORDY disable: %s", i ? "yes" : "no");
1763 lcd_puts(0, y++, buf);
1764 } else {
1765 lcd_puts(0, y++, "No timing info");
1767 break;
1769 case 11:
1770 lcd_puts(0, y++, "Cluster size");
1771 snprintf(buf, 128, "%d bytes", fat_get_cluster_size(IF_MV(0)));
1772 lcd_puts(0, y++, buf);
1773 break;
1775 lcd_update();
1777 /* Wait for a key to be pushed */
1778 key = get_action(CONTEXT_SETTINGS,HZ/5);
1779 switch(key) {
1780 case ACTION_STD_CANCEL:
1781 done = true;
1782 break;
1784 case ACTION_SETTINGS_DEC:
1785 if (--page < 0)
1786 page = max_page;
1787 break;
1789 case ACTION_SETTINGS_INC:
1790 if (++page > max_page)
1791 page = 0;
1792 break;
1794 lcd_stop_scroll();
1796 action_signalscreenchange();
1797 return false;
1799 #endif /* !HAVE_MMC */
1800 #endif /* !SIMULATOR */
1802 #ifdef HAVE_DIRCACHE
1803 static bool dbg_dircache_info(void)
1805 bool done = false;
1806 int line;
1807 char buf[32];
1809 lcd_setmargins(0, 0);
1810 lcd_setfont(FONT_SYSFIXED);
1812 while (!done)
1814 line = 0;
1816 lcd_clear_display();
1817 snprintf(buf, sizeof(buf), "Cache initialized: %s",
1818 dircache_is_enabled() ? "Yes" : "No");
1819 lcd_puts(0, line++, buf);
1821 snprintf(buf, sizeof(buf), "Cache size: %d B",
1822 dircache_get_cache_size());
1823 lcd_puts(0, line++, buf);
1825 snprintf(buf, sizeof(buf), "Last size: %d B",
1826 global_status.dircache_size);
1827 lcd_puts(0, line++, buf);
1829 snprintf(buf, sizeof(buf), "Limit: %d B", DIRCACHE_LIMIT);
1830 lcd_puts(0, line++, buf);
1832 snprintf(buf, sizeof(buf), "Reserve: %d/%d B",
1833 dircache_get_reserve_used(), DIRCACHE_RESERVE);
1834 lcd_puts(0, line++, buf);
1836 snprintf(buf, sizeof(buf), "Scanning took: %d s",
1837 dircache_get_build_ticks() / HZ);
1838 lcd_puts(0, line++, buf);
1840 snprintf(buf, sizeof(buf), "Entry count: %d",
1841 dircache_get_entry_count());
1842 lcd_puts(0, line++, buf);
1844 lcd_update();
1846 if (action_userabort(HZ/2))
1847 return false;
1850 return false;
1853 #endif /* HAVE_DIRCACHE */
1855 #ifdef HAVE_LCD_BITMAP
1856 #ifdef HAVE_TAGCACHE
1857 static bool dbg_tagcache_info(void)
1859 bool done = false;
1860 int line;
1861 char buf[32];
1862 struct tagcache_stat *stat;
1864 lcd_setmargins(0, 0);
1865 lcd_setfont(FONT_SYSFIXED);
1867 while (!done)
1869 line = 0;
1871 lcd_clear_display();
1872 stat = tagcache_get_stat();
1873 snprintf(buf, sizeof(buf), "Initialized: %s", stat->initialized ? "Yes" : "No");
1874 lcd_puts(0, line++, buf);
1875 snprintf(buf, sizeof(buf), "DB Ready: %s", stat->ready ? "Yes" : "No");
1876 lcd_puts(0, line++, buf);
1877 snprintf(buf, sizeof(buf), "RAM Cache: %s", stat->ramcache ? "Yes" : "No");
1878 lcd_puts(0, line++, buf);
1879 snprintf(buf, sizeof(buf), "RAM: %d/%d B",
1880 stat->ramcache_used, stat->ramcache_allocated);
1881 lcd_puts(0, line++, buf);
1882 snprintf(buf, sizeof(buf), "Progress: %d%% (%d entries)",
1883 stat->progress, stat->processed_entries);
1884 lcd_puts(0, line++, buf);
1885 snprintf(buf, sizeof(buf), "Commit step: %d", stat->commit_step);
1886 lcd_puts(0, line++, buf);
1887 snprintf(buf, sizeof(buf), "Commit delayed: %s",
1888 stat->commit_delayed ? "Yes" : "No");
1889 lcd_puts(0, line++, buf);
1891 lcd_update();
1893 if (action_userabort(HZ/2))
1894 return false;
1897 return false;
1899 #endif
1900 #endif
1902 #if CONFIG_CPU == SH7034
1903 static bool dbg_save_roms(void)
1905 int fd;
1906 int oldmode = system_memory_guard(MEMGUARD_NONE);
1908 fd = creat("/internal_rom_0000-FFFF.bin");
1909 if(fd >= 0)
1911 write(fd, (void *)0, 0x10000);
1912 close(fd);
1915 fd = creat("/internal_rom_2000000-203FFFF.bin");
1916 if(fd >= 0)
1918 write(fd, (void *)0x2000000, 0x40000);
1919 close(fd);
1922 system_memory_guard(oldmode);
1923 return false;
1925 #elif defined CPU_COLDFIRE
1926 static bool dbg_save_roms(void)
1928 int fd;
1929 int oldmode = system_memory_guard(MEMGUARD_NONE);
1931 #if defined(IRIVER_H100_SERIES)
1932 fd = creat("/internal_rom_000000-1FFFFF.bin");
1933 #elif defined(IRIVER_H300_SERIES)
1934 fd = creat("/internal_rom_000000-3FFFFF.bin");
1935 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5)
1936 fd = creat("/internal_rom_000000-3FFFFF.bin");
1937 #endif
1938 if(fd >= 0)
1940 write(fd, (void *)0, FLASH_SIZE);
1941 close(fd);
1943 system_memory_guard(oldmode);
1945 #ifdef HAVE_EEPROM
1946 fd = creat("/internal_eeprom.bin");
1947 if (fd >= 0)
1949 int old_irq_level;
1950 char buf[EEPROM_SIZE];
1951 int err;
1953 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
1955 err = eeprom_24cxx_read(0, buf, sizeof buf);
1956 if (err)
1957 gui_syncsplash(HZ*3, "Eeprom read failure (%d)",err);
1958 else
1960 write(fd, buf, sizeof buf);
1963 set_irq_level(old_irq_level);
1965 close(fd);
1967 #endif
1969 return false;
1971 #elif defined(CPU_PP) && !defined(SANSA_E200)
1972 static bool dbg_save_roms(void)
1974 int fd;
1976 fd = creat("/internal_rom_000000-0FFFFF.bin");
1977 if(fd >= 0)
1979 write(fd, (void *)0x20000000, FLASH_SIZE);
1980 close(fd);
1983 return false;
1985 #endif /* CPU */
1987 #ifndef SIMULATOR
1988 #if CONFIG_TUNER
1989 static bool dbg_fm_radio(void)
1991 char buf[32];
1992 bool fm_detected;
1994 lcd_setmargins(0, 0);
1996 fm_detected = radio_hardware_present();
1998 while(1)
2000 int row = 0;
2002 lcd_clear_display();
2004 snprintf(buf, sizeof buf, "HW detected: %s", fm_detected?"yes":"no");
2005 lcd_puts(0, row++, buf);
2006 #if (CONFIG_TUNER & LV24020LP)
2007 if (fm_detected)
2009 snprintf(buf, sizeof buf, "CTRL_STAT: %02X",
2010 sanyo_get(RADIO_ALL) );
2011 lcd_puts(0, row++, buf);
2013 snprintf(buf, sizeof buf, "RADIO_STAT: %02X",
2014 sanyo_get(RADIO_REG_STAT));
2015 lcd_puts(0, row++, buf);
2017 snprintf(buf, sizeof buf, "MSS_FM: %d kHz",
2018 (sanyo_get(RADIO_MSS_FM) ) );
2019 lcd_puts(0, row++, buf);
2021 snprintf(buf, sizeof buf, "MSS_IF: %d Hz",
2022 (sanyo_get(RADIO_MSS_IF) ) );
2023 lcd_puts(0, row++, buf);
2025 snprintf(buf, sizeof buf, "MSS_SD: %d Hz",
2026 (sanyo_get(RADIO_MSS_SD) ) );
2027 lcd_puts(0, row++, buf);
2029 snprintf(buf, sizeof buf, "if_set: %d Hz",
2030 (sanyo_get(RADIO_IF_SET) ) );
2031 lcd_puts(0, row++, buf);
2033 snprintf(buf, sizeof buf, "sd_set: %d Hz",
2034 (sanyo_get(RADIO_SD_SET) ) );
2035 lcd_puts(0, row++, buf);
2037 #endif
2038 #if (CONFIG_TUNER & S1A0903X01)
2039 snprintf(buf, sizeof buf, "Samsung regs: %08X",
2040 samsung_get(RADIO_ALL));
2041 lcd_puts(0, row++, buf);
2042 #endif
2043 #if (CONFIG_TUNER & TEA5767)
2045 struct philips_dbg_info info;
2046 philips_dbg_info(&info);
2048 snprintf(buf, sizeof buf, "Philips regs:");
2049 lcd_puts(0, row++, buf);
2051 snprintf(buf, sizeof buf, " Read: %02X %02X %02X %02X %02X",
2052 (unsigned)info.read_regs[0], (unsigned)info.read_regs[1],
2053 (unsigned)info.read_regs[2], (unsigned)info.read_regs[3],
2054 (unsigned)info.read_regs[4]);
2055 lcd_puts(0, row++, buf);
2057 snprintf(buf, sizeof buf, " Write: %02X %02X %02X %02X %02X",
2058 (unsigned)info.write_regs[0], (unsigned)info.write_regs[1],
2059 (unsigned)info.write_regs[2], (unsigned)info.write_regs[3],
2060 (unsigned)info.write_regs[4]);
2061 lcd_puts(0, row++, buf);
2063 #endif
2064 lcd_update();
2066 if (action_userabort(HZ))
2067 return false;
2069 return false;
2071 #endif /* CONFIG_TUNER */
2072 #endif /* !SIMULATOR */
2074 #ifdef HAVE_LCD_BITMAP
2075 extern bool do_screendump_instead_of_usb;
2077 static bool dbg_screendump(void)
2079 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2080 gui_syncsplash(HZ, "Screendump %s",
2081 do_screendump_instead_of_usb?"enabled":"disabled");
2082 return false;
2084 #endif /* HAVE_LCD_BITMAP */
2086 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2087 static bool dbg_set_memory_guard(void)
2089 static const struct opt_items names[MAXMEMGUARD] = {
2090 { "None", -1 },
2091 { "Flash ROM writes", -1 },
2092 { "Zero area (all)", -1 }
2094 int mode = system_memory_guard(MEMGUARD_KEEP);
2096 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2097 system_memory_guard(mode);
2099 return false;
2101 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2103 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2105 extern volatile bool lcd_poweroff;
2107 static bool dbg_lcd_power_off(void)
2109 lcd_setmargins(0, 0);
2111 while(1)
2113 int button;
2115 lcd_clear_display();
2116 lcd_puts(0, 0, "LCD Power Off");
2117 if(lcd_poweroff)
2118 lcd_puts(1, 1, "Yes");
2119 else
2120 lcd_puts(1, 1, "No");
2122 lcd_update();
2124 button = get_action(CONTEXT_STD,HZ/5);
2125 switch(button)
2127 case ACTION_STD_PREV:
2128 case ACTION_STD_NEXT:
2129 lcd_poweroff = !lcd_poweroff;
2130 break;
2131 case ACTION_STD_OK:
2132 case ACTION_STD_CANCEL:
2133 action_signalscreenchange();
2134 return false;
2135 default:
2136 sleep(HZ/10);
2137 break;
2140 return false;
2142 #endif
2144 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2145 static bool dbg_write_eeprom(void)
2147 int fd;
2148 int rc;
2149 int old_irq_level;
2150 char buf[EEPROM_SIZE];
2151 int err;
2153 fd = open("/internal_eeprom.bin", O_RDONLY);
2155 if (fd >= 0)
2157 rc = read(fd, buf, EEPROM_SIZE);
2159 if(rc == EEPROM_SIZE)
2161 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
2163 err = eeprom_24cxx_write(0, buf, sizeof buf);
2164 if (err)
2165 gui_syncsplash(HZ*3, "Eeprom write failure (%d)",err);
2166 else
2167 gui_syncsplash(HZ*3, "Eeprom written successfully");
2169 set_irq_level(old_irq_level);
2171 else
2173 gui_syncsplash(HZ*3, "File read error (%d)",rc);
2175 close(fd);
2177 else
2179 gui_syncsplash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2182 return false;
2184 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2185 #ifdef CPU_BOOST_LOGGING
2186 static bool cpu_boost_log(void)
2188 int i = 0,j=0;
2189 int count = cpu_boost_log_getcount();
2190 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2191 char *str;
2192 bool done;
2193 lcd_setmargins(0, 0);
2194 lcd_setfont(FONT_SYSFIXED);
2195 str = cpu_boost_log_getlog_first();
2196 while (i < count)
2198 lcd_clear_display();
2199 for(j=0; j<lines; j++,i++)
2201 if (!str)
2202 str = cpu_boost_log_getlog_next();
2203 if (str)
2205 lcd_puts(0, j,str);
2207 str = NULL;
2209 lcd_update();
2210 done = false;
2211 action_signalscreenchange();
2212 while (!done)
2214 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2216 case ACTION_STD_OK:
2217 case ACTION_STD_PREV:
2218 case ACTION_STD_NEXT:
2219 done = true;
2220 break;
2221 case ACTION_STD_CANCEL:
2222 i = count;
2223 done = true;
2224 break;
2228 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2229 lcd_setfont(FONT_UI);
2230 action_signalscreenchange();
2231 return false;
2233 #endif
2237 /****** The menu *********/
2238 struct the_menu_item {
2239 unsigned char *desc; /* string or ID */
2240 bool (*function) (void); /* return true if USB was connected */
2242 static const struct the_menu_item menuitems[] = {
2243 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2244 { "LCD Power Off", dbg_lcd_power_off },
2245 #endif
2246 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2247 (defined(CPU_PP) && !defined(SANSA_E200))
2248 { "Dump ROM contents", dbg_save_roms },
2249 #endif
2250 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) || CONFIG_CPU == S3C2440
2251 { "View I/O ports", dbg_ports },
2252 #endif
2253 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2254 { "CPU frequency", dbg_cpufreq },
2255 #endif
2256 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2257 { "S/PDIF analyzer", dbg_spdif },
2258 #endif
2259 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2260 { "Catch mem accesses", dbg_set_memory_guard },
2261 #endif
2262 #ifndef SIMULATOR
2263 { "View OS stacks", dbg_os },
2264 #endif
2265 #ifdef HAVE_LCD_BITMAP
2266 #ifndef SIMULATOR
2267 { "View battery", view_battery },
2268 #endif
2269 { "Screendump", dbg_screendump },
2270 #endif
2271 #ifndef SIMULATOR
2272 { "View HW info", dbg_hw_info },
2273 #endif
2274 #ifndef SIMULATOR
2275 { "View partitions", dbg_partitions },
2276 #endif
2277 #ifndef SIMULATOR
2278 #ifdef HAVE_MMC
2279 { "View MMC info", dbg_mmc_info },
2280 #else
2281 { "View disk info", dbg_disk_info },
2282 #endif
2283 #endif
2284 #ifdef HAVE_DIRCACHE
2285 { "View dircache info", dbg_dircache_info },
2286 #endif
2287 #ifdef HAVE_LCD_BITMAP
2288 #ifdef HAVE_TAGCACHE
2289 { "View database info", dbg_tagcache_info },
2290 #endif
2291 #if CONFIG_CODEC == SWCODEC || !defined(SIMULATOR)
2292 { "View audio thread", dbg_audio_thread },
2293 #endif
2294 #ifdef PM_DEBUG
2295 { "pm histogram", peak_meter_histogram},
2296 #endif /* PM_DEBUG */
2297 #endif /* HAVE_LCD_BITMAP */
2298 #ifndef SIMULATOR
2299 #if CONFIG_TUNER
2300 { "FM Radio", dbg_fm_radio },
2301 #endif
2302 #endif
2303 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2304 { "Write back EEPROM", dbg_write_eeprom },
2305 #endif
2306 #ifdef ROCKBOX_HAS_LOGF
2307 {"logf", logfdisplay },
2308 {"logfdump", logfdump },
2309 #endif
2310 #ifdef CPU_BOOST_LOGGING
2311 {"cpu_boost log",cpu_boost_log},
2312 #endif
2314 static int menu_action_callback(int btn, struct gui_synclist *lists)
2316 if (btn == ACTION_STD_OK)
2318 menuitems[gui_synclist_get_sel_pos(lists)].function();
2319 gui_synclist_draw(lists);
2321 return btn;
2323 static char* dbg_menu_getname(int item, void * data, char *buffer)
2325 (void)data; (void)buffer;
2326 return menuitems[item].desc;
2328 bool debug_menu(void)
2330 dbg_list("Debug Menu",ARRAYLEN(menuitems) , 1,
2331 menu_action_callback,
2332 dbg_menu_getname);
2333 return false;