Better endianness handling, removed some leftovers
[kugel-rb.git] / apps / debug_menu.c
blob48e67b575b95292c75434841db88dc3d61af2269
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
90 #ifndef SIMULATOR
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 #endif /* SIMULATOR */
121 /*---------------------------------------------------*/
122 /* SPECIAL DEBUG STUFF */
123 /*---------------------------------------------------*/
124 extern int ata_device;
125 extern int ata_io_address;
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 snprintf(buf, sizeof(buf), "boost ratio: %3d%%",
330 boost_ticks * 100 / ticks);
331 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)) && !defined(SIMULATOR)
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) && !SIMULATOR */
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 usb_polarity;
411 int pr_polarity;
412 int bitmask = *(unsigned short*)0x20000fc;
413 int rom_version = *(unsigned short*)0x20000fe;
414 unsigned manu, id; /* flash IDs */
415 bool got_id; /* flag if we managed to get the flash IDs */
416 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
417 bool has_bootrom; /* flag for boot ROM present */
418 int oldmode; /* saved memory guard mode */
420 #ifdef USB_ENABLE_ONDIOSTYLE
421 if(PADRL & 0x20)
422 #else
423 if(PADRH & 0x04)
424 #endif
425 usb_polarity = 0; /* Negative */
426 else
427 usb_polarity = 1; /* Positive */
429 if(PADRH & 0x08)
430 pr_polarity = 0; /* Negative */
431 else
432 pr_polarity = 1; /* Positive */
434 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
436 /* get flash ROM type */
437 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
438 if (!got_id)
439 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
441 /* check if the boot ROM area is a flash mirror */
442 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
443 if (has_bootrom) /* if ROM and Flash different */
445 /* calculate CRC16 checksum of boot ROM */
446 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
449 system_memory_guard(oldmode); /* re-enable memory guard */
451 lcd_setmargins(0, 0);
452 lcd_setfont(FONT_SYSFIXED);
453 lcd_clear_display();
455 lcd_puts(0, 0, "[Hardware info]");
457 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
458 lcd_puts(0, 1, buf);
460 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
461 lcd_puts(0, 2, buf);
463 snprintf(buf, 32, "USB: %s", usb_polarity?"positive":"negative");
464 lcd_puts(0, 3, buf);
466 snprintf(buf, 32, "PR: %s", pr_polarity?"positive":"negative");
467 lcd_puts(0, 4, buf);
469 if (got_id)
470 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
471 else
472 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
473 lcd_puts(0, 5, buf);
475 if (has_bootrom)
477 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
478 snprintf(buf, 32, "Boot ROM: V1");
479 else
480 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
482 else
484 snprintf(buf, 32, "Boot ROM: none");
486 lcd_puts(0, 6, buf);
488 #ifndef HAVE_MMC /* have ATA */
489 snprintf(buf, 32, "ATA: 0x%x,%s", ata_io_address,
490 ata_device ? "slave":"master");
491 lcd_puts(0, 7, buf);
492 #endif
493 lcd_update();
495 while(1)
497 if (action_userabort(TIMEOUT_BLOCK))
498 return false;
500 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
501 char buf[32];
502 unsigned manu, id; /* flash IDs */
503 int got_id; /* flag if we managed to get the flash IDs */
504 int oldmode; /* saved memory guard mode */
505 int line = 0;
507 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
509 /* get flash ROM type */
510 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
511 if (!got_id)
512 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
514 system_memory_guard(oldmode); /* re-enable memory guard */
516 lcd_setmargins(0, 0);
517 lcd_setfont(FONT_SYSFIXED);
518 lcd_clear_display();
520 lcd_puts(0, line++, "[Hardware info]");
522 if (got_id)
523 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
524 else
525 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
526 lcd_puts(0, line++, buf);
528 #ifdef IAUDIO_X5
530 struct ds2411_id id;
532 lcd_puts(0, ++line, "Serial Number:");
534 got_id = ds2411_read_id(&id);
536 if (got_id == DS2411_OK)
538 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
539 lcd_puts(0, ++line, buf);
540 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
541 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
542 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
543 lcd_puts(0, ++line, buf);
544 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
546 else
548 snprintf(buf, 32, "READ ERR=%d", got_id);
551 lcd_puts(0, ++line, buf);
553 #endif
555 lcd_update();
557 while(1)
559 if (action_userabort(TIMEOUT_BLOCK))
560 return false;
562 #elif CONFIG_CPU == PP5020
563 char buf[32];
564 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
565 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
566 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
567 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
569 lcd_setmargins(0, 0);
570 lcd_setfont(FONT_SYSFIXED);
571 lcd_clear_display();
573 lcd_puts(0, 0, "[Hardware info]");
575 snprintf(buf, sizeof(buf), "HW rev: 0x%08x", ipod_hw_rev);
576 lcd_puts(0, 1, buf);
578 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
579 lcd_puts(0, 2, buf);
580 lcd_update();
582 while(1)
584 if (action_userabort(TIMEOUT_BLOCK))
585 return false;
587 #endif /* CONFIG_CPU */
588 return false;
590 #else /* !HAVE_LCD_BITMAP */
591 static bool dbg_hw_info(void)
593 char buf[32];
594 int button;
595 int currval = 0;
596 int usb_polarity;
597 int bitmask = *(unsigned short*)0x20000fc;
598 int rom_version = *(unsigned short*)0x20000fe;
599 unsigned manu, id; /* flash IDs */
600 bool got_id; /* flag if we managed to get the flash IDs */
601 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
602 bool has_bootrom; /* flag for boot ROM present */
603 int oldmode; /* saved memory guard mode */
605 if(PADRH & 0x04)
606 usb_polarity = 0; /* Negative */
607 else
608 usb_polarity = 1; /* Positive */
610 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
612 /* get flash ROM type */
613 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
614 if (!got_id)
615 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
617 /* check if the boot ROM area is a flash mirror */
618 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
619 if (has_bootrom) /* if ROM and Flash different */
621 /* calculate CRC16 checksum of boot ROM */
622 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
625 system_memory_guard(oldmode); /* re-enable memory guard */
627 lcd_clear_display();
629 lcd_puts(0, 0, "[HW Info]");
630 while(1)
632 switch(currval)
634 case 0:
635 snprintf(buf, 32, "ROM: %d.%02d",
636 rom_version/100, rom_version%100);
637 break;
638 case 1:
639 snprintf(buf, 32, "USB: %s",
640 usb_polarity?"pos":"neg");
641 break;
642 case 2:
643 snprintf(buf, 32, "ATA: 0x%x%s",
644 ata_io_address, ata_device ? "s":"m");
645 break;
646 case 3:
647 snprintf(buf, 32, "Mask: %04x", bitmask);
648 break;
649 case 4:
650 if (got_id)
651 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
652 else
653 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
654 break;
655 case 5:
656 if (has_bootrom)
658 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
659 snprintf(buf, 32, "BootROM: V1");
660 else if (rom_crc == 0x358099E8)
661 snprintf(buf, 32, "BootROM: V2");
662 /* alternative boot ROM found in one single player so far */
663 else
664 snprintf(buf, 32, "R: %08x", rom_crc);
666 else
667 snprintf(buf, 32, "BootROM: no");
670 lcd_puts(0, 1, buf);
671 lcd_update();
673 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
675 switch(button)
677 case ACTION_STD_CANCEL:
678 action_signalscreenchange();
679 return false;
681 case ACTION_SETTINGS_DEC:
682 currval--;
683 if(currval < 0)
684 currval = 5;
685 break;
687 case ACTION_SETTINGS_INC:
688 currval++;
689 if(currval > 5)
690 currval = 0;
691 break;
694 return false;
696 #endif /* !HAVE_LCD_BITMAP */
697 #endif /* !SIMULATOR */
699 #ifndef SIMULATOR
700 static char* dbg_partitions_getname(int selected_item, void * data, char *buffer)
702 (void)data;
703 int partition = selected_item/2;
704 struct partinfo* p = disk_partinfo(partition);
705 if (selected_item%2)
707 snprintf(buffer, MAX_PATH, "T:%x %ld MB", p->type, p->size / 2048);
709 else
711 snprintf(buffer, MAX_PATH, "P%d: S:%lx", partition, p->start);
713 return buffer;
716 bool dbg_partitions(void)
718 return dbg_list("Partition Info", 4, 2,
719 NULL, dbg_partitions_getname);
721 #endif
723 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
724 static bool dbg_spdif(void)
726 char buf[128];
727 int line;
728 unsigned int control;
729 int x;
730 char *s;
731 int category;
732 int generation;
733 unsigned int interruptstat;
734 bool valnogood, symbolerr, parityerr;
735 bool done = false;
736 bool spdif_src_on;
737 int spdif_source = spdif_get_output_source(&spdif_src_on);
738 spdif_set_output_source(AUDIO_SRC_SPDIF, true);
740 lcd_setmargins(0, 0);
741 lcd_clear_display();
742 lcd_setfont(FONT_SYSFIXED);
744 #ifdef HAVE_SPDIF_POWER
745 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
746 #endif
748 while (!done)
750 line = 0;
752 control = EBU1RCVCCHANNEL1;
753 interruptstat = INTERRUPTSTAT;
754 INTERRUPTCLEAR = 0x03c00000;
756 valnogood = (interruptstat & 0x01000000)?true:false;
757 symbolerr = (interruptstat & 0x00800000)?true:false;
758 parityerr = (interruptstat & 0x00400000)?true:false;
760 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
761 valnogood?"--":"OK",
762 symbolerr?"--":"OK",
763 parityerr?"--":"OK");
764 lcd_puts(0, line++, buf);
766 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
767 lcd_puts(0, line++, buf);
769 line++;
771 x = control >> 31;
772 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
773 x, x?"Professional":"Consumer");
774 lcd_puts(0, line++, buf);
776 x = (control >> 30) & 1;
777 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
778 x, x?"Non-PCM":"PCM");
779 lcd_puts(0, line++, buf);
781 x = (control >> 29) & 1;
782 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
783 x, x?"Permitted":"Inhibited");
784 lcd_puts(0, line++, buf);
786 x = (control >> 27) & 7;
787 switch(x)
789 case 0:
790 s = "None";
791 break;
792 case 1:
793 s = "50/15us";
794 break;
795 default:
796 s = "Reserved";
797 break;
799 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
800 lcd_puts(0, line++, buf);
802 x = (control >> 24) & 3;
803 snprintf(buf, sizeof(buf), "Mode: %d", x);
804 lcd_puts(0, line++, buf);
806 category = (control >> 17) & 127;
807 switch(category)
809 case 0x00:
810 s = "General";
811 break;
812 case 0x40:
813 s = "Audio CD";
814 break;
815 default:
816 s = "Unknown";
818 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
819 lcd_puts(0, line++, buf);
821 x = (control >> 16) & 1;
822 generation = x;
823 if(((category & 0x70) == 0x10) ||
824 ((category & 0x70) == 0x40) ||
825 ((category & 0x78) == 0x38))
827 generation = !generation;
829 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
830 x, generation?"Original":"No ind.");
831 lcd_puts(0, line++, buf);
833 x = (control >> 12) & 15;
834 snprintf(buf, sizeof(buf), "Source: %d", x);
835 lcd_puts(0, line++, buf);
837 x = (control >> 8) & 15;
838 switch(x)
840 case 0:
841 s = "Unspecified";
842 break;
843 case 8:
844 s = "A (Left)";
845 break;
846 case 4:
847 s = "B (Right)";
848 break;
849 default:
850 s = "";
851 break;
853 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
854 lcd_puts(0, line++, buf);
856 x = (control >> 4) & 15;
857 switch(x)
859 case 0:
860 s = "44.1kHz";
861 break;
862 case 0x4:
863 s = "48kHz";
864 break;
865 case 0xc:
866 s = "32kHz";
867 break;
869 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
870 lcd_puts(0, line++, buf);
872 x = (control >> 2) & 3;
873 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
874 lcd_puts(0, line++, buf);
875 line++;
877 #ifndef SIMULATOR
878 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
879 spdif_measure_frequency());
880 lcd_puts(0, line++, buf);
881 #endif
883 lcd_update();
885 if (action_userabort(HZ/10))
886 break;
889 spdif_set_output_source(spdif_source, spdif_src_on);
891 #ifdef HAVE_SPDIF_POWER
892 spdif_power_enable(global_settings.spdif_enable);
893 #endif
895 return false;
897 #endif /* CPU_COLDFIRE */
899 #ifndef SIMULATOR
900 #ifdef HAVE_LCD_BITMAP
901 /* button definitions */
902 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
903 (CONFIG_KEYPAD == IRIVER_H300_PAD)
904 # define DEBUG_CANCEL BUTTON_OFF
906 #elif CONFIG_KEYPAD == RECORDER_PAD
907 # define DEBUG_CANCEL BUTTON_OFF
909 #elif CONFIG_KEYPAD == ONDIO_PAD
910 # define DEBUG_CANCEL BUTTON_MENU
912 #elif (CONFIG_KEYPAD == IPOD_3G_PAD) || \
913 (CONFIG_KEYPAD == IPOD_4G_PAD)
914 # define DEBUG_CANCEL BUTTON_MENU
916 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
917 # define DEBUG_CANCEL BUTTON_PLAY
919 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
920 # define DEBUG_CANCEL BUTTON_REC
922 #elif CONFIG_KEYPAD == GIGABEAT_PAD
923 # define DEBUG_CANCEL BUTTON_A
925 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
926 # define DEBUG_CANCEL BUTTON_REW
928 #elif CONFIG_KEYPAD == SANSA_E200_PAD
929 # define DEBUG_CANCEL BUTTON_LEFT
930 #endif /* key definitios */
932 /* Test code!!! */
933 bool dbg_ports(void)
935 #if CONFIG_CPU == SH7034
936 unsigned short porta;
937 unsigned short portb;
938 unsigned char portc;
939 char buf[32];
940 int adc_battery_voltage, adc_battery_level;
942 lcd_setfont(FONT_SYSFIXED);
943 lcd_setmargins(0, 0);
944 lcd_clear_display();
946 while(1)
948 porta = PADR;
949 portb = PBDR;
950 portc = PCDR;
952 snprintf(buf, 32, "PADR: %04x", porta);
953 lcd_puts(0, 0, buf);
954 snprintf(buf, 32, "PBDR: %04x", portb);
955 lcd_puts(0, 1, buf);
957 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
958 lcd_puts(0, 2, buf);
959 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
960 lcd_puts(0, 3, buf);
961 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
962 lcd_puts(0, 4, buf);
963 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
964 lcd_puts(0, 5, buf);
966 battery_read_info(NULL, &adc_battery_voltage,
967 &adc_battery_level);
968 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100,
969 adc_battery_voltage % 100, adc_battery_level);
970 lcd_puts(0, 6, buf);
971 #ifndef HAVE_MMC /* have ATA */
972 snprintf(buf, 32, "ATA: %s, 0x%x",
973 ata_device?"slave":"master", ata_io_address);
974 lcd_puts(0, 7, buf);
975 #endif
976 lcd_update();
977 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
978 return false;
980 #elif defined(CPU_COLDFIRE)
981 unsigned int gpio_out;
982 unsigned int gpio1_out;
983 unsigned int gpio_read;
984 unsigned int gpio1_read;
985 unsigned int gpio_function;
986 unsigned int gpio1_function;
987 unsigned int gpio_enable;
988 unsigned int gpio1_enable;
989 int adc_buttons, adc_remote;
990 int adc_battery, adc_battery_voltage, adc_battery_level;
991 char buf[128];
992 int line;
994 lcd_setmargins(0, 0);
995 lcd_clear_display();
996 lcd_setfont(FONT_SYSFIXED);
998 while(1)
1000 line = 0;
1001 gpio_read = GPIO_READ;
1002 gpio1_read = GPIO1_READ;
1003 gpio_out = GPIO_OUT;
1004 gpio1_out = GPIO1_OUT;
1005 gpio_function = GPIO_FUNCTION;
1006 gpio1_function = GPIO1_FUNCTION;
1007 gpio_enable = GPIO_ENABLE;
1008 gpio1_enable = GPIO1_ENABLE;
1010 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1011 lcd_puts(0, line++, buf);
1012 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1013 lcd_puts(0, line++, buf);
1014 snprintf(buf, sizeof(buf), "GPIO_FUNCTION: %08x", gpio_function);
1015 lcd_puts(0, line++, buf);
1016 snprintf(buf, sizeof(buf), "GPIO_ENABLE: %08x", gpio_enable);
1017 lcd_puts(0, line++, buf);
1019 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1020 lcd_puts(0, line++, buf);
1021 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1022 lcd_puts(0, line++, buf);
1023 snprintf(buf, sizeof(buf), "GPIO1_FUNCTION: %08x", gpio1_function);
1024 lcd_puts(0, line++, buf);
1025 snprintf(buf, sizeof(buf), "GPIO1_ENABLE: %08x", gpio1_enable);
1026 lcd_puts(0, line++, buf);
1028 adc_buttons = adc_read(ADC_BUTTONS);
1029 adc_remote = adc_read(ADC_REMOTE);
1030 battery_read_info(&adc_battery, &adc_battery_voltage,
1031 &adc_battery_level);
1032 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1033 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1034 button_scan_enabled() ? '+' : '-', adc_buttons);
1035 #else
1036 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1037 #endif
1038 lcd_puts(0, line++, buf);
1039 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1040 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1041 remote_detect() ? '+' : '-', adc_remote);
1042 #else
1043 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1044 #endif
1046 lcd_puts(0, line++, buf);
1047 snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_battery);
1048 lcd_puts(0, line++, buf);
1049 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1050 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1051 adc_read(ADC_REMOTEDETECT));
1052 lcd_puts(0, line++, buf);
1053 #endif
1055 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100,
1056 adc_battery_voltage % 100, adc_battery_level);
1057 lcd_puts(0, line++, buf);
1059 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1060 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1061 lcd_puts(0, line++, buf);
1062 #endif
1064 lcd_update();
1065 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1066 return false;
1069 #elif CONFIG_CPU == PP5020 || CONFIG_CPU == PP5024
1071 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1072 unsigned int gpio_e, gpio_f, gpio_g, gpio_h;
1073 unsigned int gpio_i, gpio_j, gpio_k, gpio_l;
1075 char buf[128];
1076 int line;
1078 lcd_setmargins(0, 0);
1079 lcd_clear_display();
1080 lcd_setfont(FONT_SYSFIXED);
1082 while(1)
1084 gpio_a = GPIOA_INPUT_VAL;
1085 gpio_b = GPIOB_INPUT_VAL;
1086 gpio_c = GPIOC_INPUT_VAL;
1088 gpio_g = GPIOG_INPUT_VAL;
1089 gpio_h = GPIOH_INPUT_VAL;
1090 gpio_i = GPIOI_INPUT_VAL;
1092 line = 0;
1093 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_G: %02x", gpio_a, gpio_g);
1094 lcd_puts(0, line++, buf);
1095 snprintf(buf, sizeof(buf), "GPIO_B: %02x GPIO_H: %02x", gpio_b, gpio_h);
1096 lcd_puts(0, line++, buf);
1097 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_I: %02x", gpio_c, gpio_i);
1098 lcd_puts(0, line++, buf);
1099 line++;
1101 gpio_d = GPIOD_INPUT_VAL;
1102 gpio_e = GPIOE_INPUT_VAL;
1103 gpio_f = GPIOF_INPUT_VAL;
1105 gpio_j = GPIOJ_INPUT_VAL;
1106 gpio_k = GPIOK_INPUT_VAL;
1107 gpio_l = GPIOL_INPUT_VAL;
1109 snprintf(buf, sizeof(buf), "GPIO_D: %02x GPIO_J: %02x", gpio_d, gpio_j);
1110 lcd_puts(0, line++, buf);
1111 snprintf(buf, sizeof(buf), "GPIO_E: %02x GPIO_K: %02x", gpio_e, gpio_k);
1112 lcd_puts(0, line++, buf);
1113 snprintf(buf, sizeof(buf), "GPIO_F: %02x GPIO_L: %02x", gpio_f, gpio_l);
1114 lcd_puts(0, line++, buf);
1115 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1116 line++;
1117 snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_read(ADC_BATTERY));
1118 lcd_puts(0, line++, buf);
1119 snprintf(buf, sizeof(buf), "ADC_UNKNOWN_1: %02x", adc_read(ADC_UNKNOWN_1));
1120 lcd_puts(0, line++, buf);
1121 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_read(ADC_REMOTE));
1122 lcd_puts(0, line++, buf);
1123 snprintf(buf, sizeof(buf), "ADC_SCROLLPAD: %02x", adc_read(ADC_SCROLLPAD));
1124 lcd_puts(0, line++, buf);
1125 #elif defined(SANSA_E200)
1126 line++;
1127 snprintf(buf, sizeof(buf), "ADC_BVDD: %02x", adc_read(ADC_BVDD));
1128 lcd_puts(0, line++, buf);
1129 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %02x", adc_read(ADC_RTCSUP));
1130 lcd_puts(0, line++, buf);
1131 snprintf(buf, sizeof(buf), "ADC_UVDD: %02x", adc_read(ADC_UVDD));
1132 lcd_puts(0, line++, buf);
1133 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %02x", adc_read(ADC_CHG_IN));
1134 lcd_puts(0, line++, buf);
1135 snprintf(buf, sizeof(buf), "ADC_CVDD: %02x", adc_read(ADC_CVDD));
1136 lcd_puts(0, line++, buf);
1137 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %02x", adc_read(ADC_BATTEMP));
1138 lcd_puts(0, line++, buf);
1139 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %02x", adc_read(ADC_MICSUP1));
1140 lcd_puts(0, line++, buf);
1141 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %02x", adc_read(ADC_MICSUP2));
1142 lcd_puts(0, line++, buf);
1143 snprintf(buf, sizeof(buf), "ADC_VBE1: %02x", adc_read(ADC_VBE1));
1144 lcd_puts(0, line++, buf);
1145 snprintf(buf, sizeof(buf), "ADC_VBE2: %02x", adc_read(ADC_VBE2));
1146 lcd_puts(0, line++, buf);
1147 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1: %02x", adc_read(ADC_I_MICSUP1));
1148 lcd_puts(0, line++, buf);
1149 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2: %02x", adc_read(ADC_I_MICSUP2));
1150 lcd_puts(0, line++, buf);
1151 snprintf(buf, sizeof(buf), "ADC_VBAT: %02x", adc_read(ADC_VBAT));
1152 lcd_puts(0, line++, buf);
1153 #endif
1154 lcd_update();
1155 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1156 return false;
1159 #elif CONFIG_CPU == PP5002
1160 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1162 char buf[128];
1163 int line;
1165 lcd_setmargins(0, 0);
1166 lcd_clear_display();
1167 lcd_setfont(FONT_SYSFIXED);
1169 while(1)
1171 gpio_a = GPIOA_INPUT_VAL;
1172 gpio_b = GPIOB_INPUT_VAL;
1173 gpio_c = GPIOC_INPUT_VAL;
1174 gpio_d = GPIOD_INPUT_VAL;
1176 line = 0;
1177 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x", gpio_a, gpio_b);
1178 lcd_puts(0, line++, buf);
1179 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x", gpio_c, gpio_d);
1180 lcd_puts(0, line++, buf);
1182 lcd_update();
1183 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1184 return false;
1186 #endif /* CPU */
1187 return false;
1189 #else /* !HAVE_LCD_BITMAP */
1190 bool dbg_ports(void)
1192 unsigned short porta;
1193 unsigned short portb;
1194 unsigned char portc;
1195 char buf[32];
1196 int button;
1197 int adc_battery_voltage;
1198 int currval = 0;
1200 lcd_clear_display();
1202 while(1)
1204 porta = PADR;
1205 portb = PBDR;
1206 portc = PCDR;
1208 switch(currval)
1210 case 0:
1211 snprintf(buf, 32, "PADR: %04x ", porta);
1212 break;
1213 case 1:
1214 snprintf(buf, 32, "PBDR: %04x ", portb);
1215 break;
1216 case 2:
1217 snprintf(buf, 32, "AN0: %03x ", adc_read(0));
1218 break;
1219 case 3:
1220 snprintf(buf, 32, "AN1: %03x ", adc_read(1));
1221 break;
1222 case 4:
1223 snprintf(buf, 32, "AN2: %03x ", adc_read(2));
1224 break;
1225 case 5:
1226 snprintf(buf, 32, "AN3: %03x ", adc_read(3));
1227 break;
1228 case 6:
1229 snprintf(buf, 32, "AN4: %03x ", adc_read(4));
1230 break;
1231 case 7:
1232 snprintf(buf, 32, "AN5: %03x ", adc_read(5));
1233 break;
1234 case 8:
1235 snprintf(buf, 32, "AN6: %03x ", adc_read(6));
1236 break;
1237 case 9:
1238 snprintf(buf, 32, "AN7: %03x ", adc_read(7));
1239 break;
1240 case 10:
1241 snprintf(buf, 32, "%s, 0x%x ",
1242 ata_device?"slv":"mst", ata_io_address);
1243 break;
1245 lcd_puts(0, 0, buf);
1247 battery_read_info(NULL, &adc_battery_voltage, NULL);
1248 snprintf(buf, 32, "Batt: %d.%02dV", adc_battery_voltage / 100,
1249 adc_battery_voltage % 100);
1250 lcd_puts(0, 1, buf);
1251 lcd_update();
1253 button = get_action(CONTEXT_SETTINGS,HZ/5);
1255 switch(button)
1257 case ACTION_STD_CANCEL:
1258 action_signalscreenchange();
1259 return false;
1261 case ACTION_SETTINGS_DEC:
1262 currval--;
1263 if(currval < 0)
1264 currval = 10;
1265 break;
1267 case ACTION_SETTINGS_INC:
1268 currval++;
1269 if(currval > 10)
1270 currval = 0;
1271 break;
1274 return false;
1276 #endif /* !HAVE_LCD_BITMAP */
1277 #endif /* !SIMULATOR */
1279 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1280 static bool dbg_cpufreq(void)
1282 char buf[128];
1283 int line;
1284 int button;
1286 #ifdef HAVE_LCD_BITMAP
1287 lcd_setmargins(0, 0);
1288 lcd_setfont(FONT_SYSFIXED);
1289 #endif
1290 lcd_clear_display();
1292 while(1)
1294 line = 0;
1296 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1297 lcd_puts(0, line++, buf);
1299 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1300 lcd_puts(0, line++, buf);
1302 lcd_update();
1303 button = get_action(CONTEXT_STD,HZ/10);
1305 switch(button)
1307 case ACTION_STD_PREV:
1308 cpu_boost(true);
1309 break;
1311 case ACTION_STD_NEXT:
1312 cpu_boost(false);
1313 break;
1315 case ACTION_STD_OK:
1316 while (get_cpu_boost_counter() > 0)
1317 cpu_boost(false);
1318 set_cpu_frequency(CPUFREQ_DEFAULT);
1319 break;
1321 case ACTION_STD_CANCEL:
1322 action_signalscreenchange();
1323 return false;
1327 return false;
1329 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1331 #ifndef SIMULATOR
1332 #ifdef HAVE_LCD_BITMAP
1334 * view_battery() shows a automatically scaled graph of the battery voltage
1335 * over time. Usable for estimating battery life / charging rate.
1336 * The power_history array is updated in power_thread of powermgmt.c.
1339 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1340 #define BAT_YSPACE (LCD_HEIGHT - 20)
1342 static bool view_battery(void)
1344 int view = 0;
1345 int i, x, y;
1346 unsigned short maxv, minv;
1347 char buf[32];
1349 lcd_setmargins(0, 0);
1350 lcd_setfont(FONT_SYSFIXED);
1352 while(1)
1354 lcd_clear_display();
1355 switch (view) {
1356 case 0: /* voltage history graph */
1357 /* Find maximum and minimum voltage for scaling */
1358 maxv = 0;
1359 minv = 65535;
1360 for (i = 0; i < BAT_LAST_VAL; i++) {
1361 if (power_history[i] > maxv)
1362 maxv = power_history[i];
1363 if (power_history[i] && (power_history[i] < minv))
1365 minv = power_history[i];
1369 if ((minv < 1) || (minv >= 65535))
1370 minv = 1;
1371 if (maxv < 2)
1372 maxv = 2;
1373 if (minv == maxv)
1374 maxv < 65535 ? maxv++ : minv--;
1376 snprintf(buf, 30, "Battery %d.%02d", power_history[0] / 100,
1377 power_history[0] % 100);
1378 lcd_puts(0, 0, buf);
1379 snprintf(buf, 30, "scale %d.%02d-%d.%02d V",
1380 minv / 100, minv % 100, maxv / 100, maxv % 100);
1381 lcd_puts(0, 1, buf);
1383 x = 0;
1384 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1385 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1386 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1387 lcd_vline(x, LCD_HEIGHT-1, 20);
1388 lcd_set_drawmode(DRMODE_SOLID);
1389 lcd_vline(x, LCD_HEIGHT-1,
1390 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1391 x++;
1394 break;
1396 case 1: /* status: */
1397 lcd_puts(0, 0, "Power status:");
1399 battery_read_info(NULL, &y, NULL);
1400 snprintf(buf, 30, "Battery: %d.%02d V", y / 100, y % 100);
1401 lcd_puts(0, 1, buf);
1402 #ifdef ADC_EXT_POWER
1403 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000;
1404 snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100);
1405 lcd_puts(0, 2, buf);
1406 #endif
1407 #if CONFIG_CHARGING
1408 #if CONFIG_CHARGING == CHARGING_CONTROL
1409 snprintf(buf, 30, "Chgr: %s %s",
1410 charger_inserted() ? "present" : "absent",
1411 charger_enabled ? "on" : "off");
1412 lcd_puts(0, 3, buf);
1413 snprintf(buf, 30, "short delta: %d", short_delta);
1414 lcd_puts(0, 5, buf);
1415 snprintf(buf, 30, "long delta: %d", long_delta);
1416 lcd_puts(0, 6, buf);
1417 lcd_puts(0, 7, power_message);
1418 snprintf(buf, 30, "USB Inserted: %s",
1419 usb_inserted() ? "yes" : "no");
1420 lcd_puts(0, 8, buf);
1421 #if defined IRIVER_H300_SERIES
1422 snprintf(buf, 30, "USB Charging Enabled: %s",
1423 usb_charging_enabled() ? "yes" : "no");
1424 lcd_puts(0, 9, buf);
1425 #endif
1426 #else /* CONFIG_CHARGING != CHARGING_CONTROL */
1427 #if defined IPOD_NANO || defined IPOD_VIDEO
1428 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1429 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1430 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1431 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1432 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1434 snprintf(buf, 30, "USB pwr: %s",
1435 usb_pwr ? "present" : "absent");
1436 lcd_puts(0, 3, buf);
1437 snprintf(buf, 30, "EXT pwr: %s",
1438 ext_pwr ? "present" : "absent");
1439 lcd_puts(0, 4, buf);
1440 snprintf(buf, 30, "Battery: %s",
1441 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1442 lcd_puts(0, 5, buf);
1443 snprintf(buf, 30, "Dock mode: %s",
1444 dock ? "enabled" : "disabled");
1445 lcd_puts(0, 6, buf);
1446 snprintf(buf, 30, "Headphone: %s",
1447 headphone ? "connected" : "disconnected");
1448 lcd_puts(0, 7, buf);
1449 #else
1450 snprintf(buf, 30, "Charger: %s",
1451 charger_inserted() ? "present" : "absent");
1452 lcd_puts(0, 3, buf);
1453 #endif
1454 #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1455 #endif /* CONFIG_CHARGING */
1456 break;
1458 case 2: /* voltage deltas: */
1459 lcd_puts(0, 0, "Voltage deltas:");
1461 for (i = 0; i <= 6; i++) {
1462 y = power_history[i] - power_history[i+i];
1463 snprintf(buf, 30, "-%d min: %s%d.%02d V", i,
1464 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 100,
1465 ((y < 0) ? y * -1 : y ) % 100);
1466 lcd_puts(0, i+1, buf);
1468 break;
1470 case 3: /* remaining time estimation: */
1472 #if CONFIG_CHARGING == CHARGING_CONTROL
1473 snprintf(buf, 30, "charge_state: %d", charge_state);
1474 lcd_puts(0, 0, buf);
1476 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1477 lcd_puts(0, 1, buf);
1479 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1480 lcd_puts(0, 2, buf);
1482 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1483 lcd_puts(0, 3, buf);
1485 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1486 lcd_puts(0, 4, buf);
1487 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
1489 snprintf(buf, 30, "Last PwrHist: %d.%02d V",
1490 power_history[0] / 100,
1491 power_history[0] % 100);
1492 lcd_puts(0, 5, buf);
1494 snprintf(buf, 30, "battery level: %d%%", battery_level());
1495 lcd_puts(0, 6, buf);
1497 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1498 lcd_puts(0, 7, buf);
1499 break;
1502 lcd_update();
1504 switch(get_action(CONTEXT_SETTINGS,HZ/2))
1506 case ACTION_SETTINGS_DEC:
1507 if (view)
1508 view--;
1509 break;
1511 case ACTION_SETTINGS_INC:
1512 if (view < 3)
1513 view++;
1514 break;
1516 case ACTION_STD_CANCEL:
1517 action_signalscreenchange();
1518 return false;
1521 return false;
1524 #endif /* HAVE_LCD_BITMAP */
1525 #endif
1527 #ifndef SIMULATOR
1528 #ifdef HAVE_MMC
1529 static bool dbg_mmc_info(void)
1531 bool done = false;
1532 int currval = 0;
1533 int line;
1534 tCardInfo *card;
1535 unsigned char pbuf[32], pbuf2[32];
1536 unsigned char card_name[7];
1538 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1539 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1540 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1541 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1542 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1543 "3.1-3.31", "4.0" };
1545 card_name[6] = '\0';
1547 lcd_setmargins(0, 0);
1548 lcd_setfont(FONT_SYSFIXED);
1550 while (!done)
1552 card = mmc_card_info(currval / 2);
1554 line = 0;
1555 lcd_clear_display();
1556 snprintf(pbuf, sizeof(pbuf), "[MMC%d p%d]", currval / 2,
1557 (currval % 2) + 1);
1558 lcd_puts(0, line++, pbuf);
1560 if (card->initialized)
1562 if (!(currval % 2)) /* General info */
1564 int temp;
1566 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1567 snprintf(pbuf, sizeof(pbuf), "%s Rev %d.%d", card_name,
1568 (int) mmc_extract_bits(card->cid, 72, 4),
1569 (int) mmc_extract_bits(card->cid, 76, 4));
1570 lcd_puts(0, line++, pbuf);
1571 snprintf(pbuf, sizeof(pbuf), "Prod: %d/%d",
1572 (int) mmc_extract_bits(card->cid, 112, 4),
1573 (int) mmc_extract_bits(card->cid, 116, 4) + 1997);
1574 lcd_puts(0, line++, pbuf);
1575 snprintf(pbuf, sizeof(pbuf), "Ser#: 0x%08lx",
1576 mmc_extract_bits(card->cid, 80, 32));
1577 lcd_puts(0, line++, pbuf);
1578 snprintf(pbuf, sizeof(pbuf), "M=%02x, O=%04x",
1579 (int) mmc_extract_bits(card->cid, 0, 8),
1580 (int) mmc_extract_bits(card->cid, 8, 16));
1581 lcd_puts(0, line++, pbuf);
1582 temp = mmc_extract_bits(card->csd, 2, 4);
1583 snprintf(pbuf, sizeof(pbuf), "MMC v%s", temp < 5 ?
1584 spec_vers[temp] : "?.?");
1585 lcd_puts(0, line++, pbuf);
1586 snprintf(pbuf, sizeof(pbuf), "Blocks: 0x%06lx", card->numblocks);
1587 lcd_puts(0, line++, pbuf);
1588 snprintf(pbuf, sizeof(pbuf), "Blksz.: %d P:%c%c", card->blocksize,
1589 mmc_extract_bits(card->csd, 48, 1) ? 'R' : '-',
1590 mmc_extract_bits(card->csd, 106, 1) ? 'W' : '-');
1591 lcd_puts(0, line++, pbuf);
1593 else /* Technical details */
1595 output_dyn_value(pbuf2, sizeof pbuf2, card->speed / 1000,
1596 kbit_units, false);
1597 snprintf(pbuf, sizeof pbuf, "Speed: %s", pbuf2);
1598 lcd_puts(0, line++, pbuf);
1600 output_dyn_value(pbuf2, sizeof pbuf2, card->tsac,
1601 nsec_units, false);
1602 snprintf(pbuf, sizeof pbuf, "Tsac: %s", pbuf2);
1603 lcd_puts(0, line++, pbuf);
1605 snprintf(pbuf, sizeof(pbuf), "Nsac: %d clk", card->nsac);
1606 lcd_puts(0, line++, pbuf);
1607 snprintf(pbuf, sizeof(pbuf), "R2W: *%d", card->r2w_factor);
1608 lcd_puts(0, line++, pbuf);
1609 snprintf(pbuf, sizeof(pbuf), "IRmax: %d..%d mA",
1610 i_vmin[mmc_extract_bits(card->csd, 66, 3)],
1611 i_vmax[mmc_extract_bits(card->csd, 69, 3)]);
1612 lcd_puts(0, line++, pbuf);
1613 snprintf(pbuf, sizeof(pbuf), "IWmax: %d..%d mA",
1614 i_vmin[mmc_extract_bits(card->csd, 72, 3)],
1615 i_vmax[mmc_extract_bits(card->csd, 75, 3)]);
1616 lcd_puts(0, line++, pbuf);
1619 else
1620 lcd_puts(0, line++, "Not found!");
1622 lcd_update();
1624 switch (get_action(CONTEXT_SETTINGS,HZ/2))
1626 case ACTION_STD_CANCEL:
1627 done = true;
1628 break;
1630 case ACTION_SETTINGS_DEC:
1631 currval--;
1632 if (currval < 0)
1633 currval = 3;
1634 break;
1636 case ACTION_SETTINGS_INC:
1637 currval++;
1638 if (currval > 3)
1639 currval = 0;
1640 break;
1643 action_signalscreenchange();
1644 return false;
1646 #else /* !HAVE_MMC */
1647 static bool dbg_disk_info(void)
1649 char buf[128];
1650 bool done = false;
1651 int i;
1652 int page = 0;
1653 const int max_page = 11;
1654 unsigned short* identify_info = ata_get_identify();
1655 bool timing_info_present = false;
1656 char pio3[2], pio4[2];
1658 lcd_setmargins(0, 0);
1660 while(!done)
1662 int y=0;
1663 int key;
1664 lcd_clear_display();
1665 #ifdef HAVE_LCD_BITMAP
1666 lcd_puts(0, y++, "Disk info:");
1667 y++;
1668 #endif
1670 switch (page) {
1671 case 0:
1672 for (i=0; i < 20; i++)
1673 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1674 buf[40]=0;
1675 /* kill trailing space */
1676 for (i=39; i && buf[i]==' '; i--)
1677 buf[i] = 0;
1678 lcd_puts(0, y++, "Model");
1679 lcd_puts_scroll(0, y++, buf);
1680 break;
1682 case 1:
1683 for (i=0; i < 4; i++)
1684 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1685 buf[8]=0;
1686 lcd_puts(0, y++, "Firmware");
1687 lcd_puts(0, y++, buf);
1688 break;
1690 case 2:
1691 snprintf(buf, sizeof buf, "%ld MB",
1692 ((unsigned long)identify_info[61] << 16 |
1693 (unsigned long)identify_info[60]) / 2048 );
1694 lcd_puts(0, y++, "Size");
1695 lcd_puts(0, y++, buf);
1696 break;
1698 case 3: {
1699 unsigned long free;
1700 fat_size( IF_MV2(0,) NULL, &free );
1701 snprintf(buf, sizeof buf, "%ld MB", free / 1024 );
1702 lcd_puts(0, y++, "Free");
1703 lcd_puts(0, y++, buf);
1704 break;
1707 case 4:
1708 snprintf(buf, sizeof buf, "%d ms", ata_spinup_time * (1000/HZ));
1709 lcd_puts(0, y++, "Spinup time");
1710 lcd_puts(0, y++, buf);
1711 break;
1713 case 5:
1714 i = identify_info[83] & (1<<3);
1715 lcd_puts(0, y++, "Power mgmt:");
1716 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1717 break;
1719 case 6:
1720 i = identify_info[83] & (1<<9);
1721 lcd_puts(0, y++, "Noise mgmt:");
1722 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1723 break;
1725 case 7:
1726 i = identify_info[82] & (1<<6);
1727 lcd_puts(0, y++, "Read-ahead:");
1728 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1729 break;
1731 case 8:
1732 timing_info_present = identify_info[53] & (1<<1);
1733 if(timing_info_present) {
1734 pio3[1] = 0;
1735 pio4[1] = 0;
1736 lcd_puts(0, y++, "PIO modes:");
1737 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1738 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1739 snprintf(buf, 128, "0 1 2 %s %s", pio3, pio4);
1740 lcd_puts(0, y++, buf);
1741 } else {
1742 lcd_puts(0, y++, "No PIO mode info");
1744 break;
1746 case 9:
1747 timing_info_present = identify_info[53] & (1<<1);
1748 if(timing_info_present) {
1749 lcd_puts(0, y++, "Cycle times");
1750 snprintf(buf, 128, "%dns/%dns",
1751 identify_info[67],
1752 identify_info[68]);
1753 lcd_puts(0, y++, buf);
1754 } else {
1755 lcd_puts(0, y++, "No timing info");
1757 break;
1759 case 10:
1760 timing_info_present = identify_info[53] & (1<<1);
1761 if(timing_info_present) {
1762 i = identify_info[49] & (1<<11);
1763 snprintf(buf, 128, "IORDY support: %s", i ? "yes" : "no");
1764 lcd_puts(0, y++, buf);
1765 i = identify_info[49] & (1<<10);
1766 snprintf(buf, 128, "IORDY disable: %s", i ? "yes" : "no");
1767 lcd_puts(0, y++, buf);
1768 } else {
1769 lcd_puts(0, y++, "No timing info");
1771 break;
1773 case 11:
1774 lcd_puts(0, y++, "Cluster size");
1775 snprintf(buf, 128, "%d bytes", fat_get_cluster_size(IF_MV(0)));
1776 lcd_puts(0, y++, buf);
1777 break;
1779 lcd_update();
1781 /* Wait for a key to be pushed */
1782 key = get_action(CONTEXT_SETTINGS,HZ/5);
1783 switch(key) {
1784 case ACTION_STD_CANCEL:
1785 done = true;
1786 break;
1788 case ACTION_SETTINGS_DEC:
1789 if (--page < 0)
1790 page = max_page;
1791 break;
1793 case ACTION_SETTINGS_INC:
1794 if (++page > max_page)
1795 page = 0;
1796 break;
1798 lcd_stop_scroll();
1800 action_signalscreenchange();
1801 return false;
1803 #endif /* !HAVE_MMC */
1804 #endif /* !SIMULATOR */
1806 #ifdef HAVE_DIRCACHE
1807 static bool dbg_dircache_info(void)
1809 bool done = false;
1810 int line;
1811 char buf[32];
1813 lcd_setmargins(0, 0);
1814 lcd_setfont(FONT_SYSFIXED);
1816 while (!done)
1818 line = 0;
1820 lcd_clear_display();
1821 snprintf(buf, sizeof(buf), "Cache initialized: %s",
1822 dircache_is_enabled() ? "Yes" : "No");
1823 lcd_puts(0, line++, buf);
1825 snprintf(buf, sizeof(buf), "Cache size: %d B",
1826 dircache_get_cache_size());
1827 lcd_puts(0, line++, buf);
1829 snprintf(buf, sizeof(buf), "Last size: %d B",
1830 global_status.dircache_size);
1831 lcd_puts(0, line++, buf);
1833 snprintf(buf, sizeof(buf), "Limit: %d B", DIRCACHE_LIMIT);
1834 lcd_puts(0, line++, buf);
1836 snprintf(buf, sizeof(buf), "Reserve: %d/%d B",
1837 dircache_get_reserve_used(), DIRCACHE_RESERVE);
1838 lcd_puts(0, line++, buf);
1840 snprintf(buf, sizeof(buf), "Scanning took: %d s",
1841 dircache_get_build_ticks() / HZ);
1842 lcd_puts(0, line++, buf);
1844 snprintf(buf, sizeof(buf), "Entry count: %d",
1845 dircache_get_entry_count());
1846 lcd_puts(0, line++, buf);
1848 lcd_update();
1850 if (action_userabort(HZ/2))
1851 return false;
1854 return false;
1857 #endif /* HAVE_DIRCACHE */
1859 #ifdef HAVE_LCD_BITMAP
1860 #ifdef HAVE_TAGCACHE
1861 static bool dbg_tagcache_info(void)
1863 bool done = false;
1864 int line;
1865 char buf[32];
1866 struct tagcache_stat *stat;
1868 lcd_setmargins(0, 0);
1869 lcd_setfont(FONT_SYSFIXED);
1871 while (!done)
1873 line = 0;
1875 lcd_clear_display();
1876 stat = tagcache_get_stat();
1877 snprintf(buf, sizeof(buf), "Initialized: %s", stat->initialized ? "Yes" : "No");
1878 lcd_puts(0, line++, buf);
1879 snprintf(buf, sizeof(buf), "DB Ready: %s", stat->ready ? "Yes" : "No");
1880 lcd_puts(0, line++, buf);
1881 snprintf(buf, sizeof(buf), "RAM Cache: %s", stat->ramcache ? "Yes" : "No");
1882 lcd_puts(0, line++, buf);
1883 snprintf(buf, sizeof(buf), "RAM: %d/%d B",
1884 stat->ramcache_used, stat->ramcache_allocated);
1885 lcd_puts(0, line++, buf);
1886 snprintf(buf, sizeof(buf), "Progress: %d%% (%d entries)",
1887 stat->progress, stat->processed_entries);
1888 lcd_puts(0, line++, buf);
1889 snprintf(buf, sizeof(buf), "Commit step: %d", stat->commit_step);
1890 lcd_puts(0, line++, buf);
1891 snprintf(buf, sizeof(buf), "Commit delayed: %s",
1892 stat->commit_delayed ? "Yes" : "No");
1893 lcd_puts(0, line++, buf);
1895 lcd_update();
1897 if (action_userabort(HZ/2))
1898 return false;
1901 return false;
1903 #endif
1904 #endif
1906 #if CONFIG_CPU == SH7034
1907 static bool dbg_save_roms(void)
1909 int fd;
1910 int oldmode = system_memory_guard(MEMGUARD_NONE);
1912 fd = creat("/internal_rom_0000-FFFF.bin");
1913 if(fd >= 0)
1915 write(fd, (void *)0, 0x10000);
1916 close(fd);
1919 fd = creat("/internal_rom_2000000-203FFFF.bin");
1920 if(fd >= 0)
1922 write(fd, (void *)0x2000000, 0x40000);
1923 close(fd);
1926 system_memory_guard(oldmode);
1927 return false;
1929 #elif defined CPU_COLDFIRE
1930 static bool dbg_save_roms(void)
1932 int fd;
1933 int oldmode = system_memory_guard(MEMGUARD_NONE);
1935 #if defined(IRIVER_H100_SERIES)
1936 fd = creat("/internal_rom_000000-1FFFFF.bin");
1937 #elif defined(IRIVER_H300_SERIES)
1938 fd = creat("/internal_rom_000000-3FFFFF.bin");
1939 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5)
1940 fd = creat("/internal_rom_000000-3FFFFF.bin");
1941 #endif
1942 if(fd >= 0)
1944 write(fd, (void *)0, FLASH_SIZE);
1945 close(fd);
1947 system_memory_guard(oldmode);
1949 #ifdef HAVE_EEPROM
1950 fd = creat("/internal_eeprom.bin");
1951 if (fd >= 0)
1953 int old_irq_level;
1954 char buf[EEPROM_SIZE];
1955 int err;
1957 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
1959 err = eeprom_24cxx_read(0, buf, sizeof buf);
1960 if (err)
1961 gui_syncsplash(HZ*3, "Eeprom read failure (%d)",err);
1962 else
1964 write(fd, buf, sizeof buf);
1967 set_irq_level(old_irq_level);
1969 close(fd);
1971 #endif
1973 return false;
1975 #elif defined(CPU_PP) && !defined(SANSA_E200)
1976 static bool dbg_save_roms(void)
1978 int fd;
1980 fd = creat("/internal_rom_000000-0FFFFF.bin");
1981 if(fd >= 0)
1983 write(fd, (void *)0x20000000, FLASH_SIZE);
1984 close(fd);
1987 return false;
1989 #endif /* CPU */
1991 #ifndef SIMULATOR
1992 #if CONFIG_TUNER
1993 static bool dbg_fm_radio(void)
1995 char buf[32];
1996 bool fm_detected;
1998 lcd_setmargins(0, 0);
2000 while(1)
2002 int row = 0;
2004 lcd_clear_display();
2005 fm_detected = radio_hardware_present();
2007 snprintf(buf, sizeof buf, "HW detected: %s", fm_detected?"yes":"no");
2008 lcd_puts(0, row++, buf);
2010 #if (CONFIG_TUNER & S1A0903X01)
2011 snprintf(buf, sizeof buf, "Samsung regs: %08X",
2012 samsung_get(RADIO_ALL));
2013 lcd_puts(0, row++, buf);
2014 #endif
2015 #if (CONFIG_TUNER & TEA5767)
2017 struct philips_dbg_info info;
2018 philips_dbg_info(&info);
2020 snprintf(buf, sizeof buf, "Philips regs:");
2021 lcd_puts(0, row++, buf);
2023 snprintf(buf, sizeof buf, " Read: %02X %02X %02X %02X %02X",
2024 (unsigned)info.read_regs[0], (unsigned)info.read_regs[1],
2025 (unsigned)info.read_regs[2], (unsigned)info.read_regs[3],
2026 (unsigned)info.read_regs[4]);
2027 lcd_puts(0, row++, buf);
2029 snprintf(buf, sizeof buf, " Write: %02X %02X %02X %02X %02X",
2030 (unsigned)info.write_regs[0], (unsigned)info.write_regs[1],
2031 (unsigned)info.write_regs[2], (unsigned)info.write_regs[3],
2032 (unsigned)info.write_regs[4]);
2033 lcd_puts(0, row++, buf);
2035 #endif
2036 lcd_update();
2038 if (action_userabort(HZ))
2039 return false;
2041 return false;
2043 #endif /* CONFIG_TUNER */
2044 #endif /* !SIMULATOR */
2046 #ifdef HAVE_LCD_BITMAP
2047 extern bool do_screendump_instead_of_usb;
2049 static bool dbg_screendump(void)
2051 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2052 gui_syncsplash(HZ, "Screendump %s",
2053 do_screendump_instead_of_usb?"enabled":"disabled");
2054 return false;
2056 #endif /* HAVE_LCD_BITMAP */
2058 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2059 static bool dbg_set_memory_guard(void)
2061 static const struct opt_items names[MAXMEMGUARD] = {
2062 { "None", -1 },
2063 { "Flash ROM writes", -1 },
2064 { "Zero area (all)", -1 }
2066 int mode = system_memory_guard(MEMGUARD_KEEP);
2068 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2069 system_memory_guard(mode);
2071 return false;
2073 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2075 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2077 extern volatile bool lcd_poweroff;
2079 static bool dbg_lcd_power_off(void)
2081 lcd_setmargins(0, 0);
2083 while(1)
2085 int button;
2087 lcd_clear_display();
2088 lcd_puts(0, 0, "LCD Power Off");
2089 if(lcd_poweroff)
2090 lcd_puts(1, 1, "Yes");
2091 else
2092 lcd_puts(1, 1, "No");
2094 lcd_update();
2096 button = get_action(CONTEXT_STD,HZ/5);
2097 switch(button)
2099 case ACTION_STD_PREV:
2100 case ACTION_STD_NEXT:
2101 lcd_poweroff = !lcd_poweroff;
2102 break;
2103 case ACTION_STD_OK:
2104 case ACTION_STD_CANCEL:
2105 action_signalscreenchange();
2106 return false;
2107 default:
2108 sleep(HZ/10);
2109 break;
2112 return false;
2115 #include "backlight-target.h"
2117 static bool dbg_buttonlights(void)
2119 unsigned short mode_changed = 1, mode = 0;
2120 enum buttonlight_selection which_led = BUTTONLIGHT_LED_ALL;
2121 unsigned short brightness = DEFAULT_BRIGHTNESS_SETTING;
2123 lcd_setmargins(0, 0);
2124 for (;;)
2126 int button;
2128 if (mode_changed)
2130 lcd_clear_display();
2131 lcd_puts(0, 0, "Button light support");
2132 lcd_puts(0, 1, "Press UP for mode change");
2133 lcd_puts(0, 2, "Press DOWN for buttonlight selection");
2135 switch (mode)
2137 case 0:
2138 lcd_puts(1, 3, "Off");
2139 __buttonlight_mode(BUTTONLIGHT_OFF, which_led, brightness);
2140 break;
2142 case 1:
2143 lcd_puts(1, 3, "On - Set to brightness");
2144 __buttonlight_mode(BUTTONLIGHT_ON, which_led, brightness);
2145 break;
2147 case 2:
2148 lcd_puts(1, 3, "Faint - Always on at lowest brightness");
2149 __buttonlight_mode(BUTTONLIGHT_FAINT, which_led, brightness);
2150 break;
2152 case 3:
2153 lcd_puts(1, 3, "Flicker on disk access");
2154 __buttonlight_mode(BUTTONLIGHT_FLICKER, which_led, brightness);
2155 break;
2157 case 4:
2158 lcd_puts(1, 3, "Solid on disk access");
2159 __buttonlight_mode(BUTTONLIGHT_SIGNAL, which_led, brightness);
2160 break;
2162 case 5:
2163 lcd_puts(1, 3, "Follows backlight");
2164 __buttonlight_mode(BUTTONLIGHT_FOLLOW, which_led, brightness);
2165 break;
2167 case 6:
2168 lcd_puts(1, 3, "Shows 'battery charging'");
2169 __buttonlight_mode(BUTTONLIGHT_CHARGING, which_led, brightness);
2170 break;
2173 mode_changed = 0;
2174 lcd_update();
2179 /* does nothing unless in flicker mode */
2180 /* the parameter sets the brightness */
2181 __buttonlight_trigger();
2182 button = get_action(CONTEXT_STD,HZ/5);
2183 switch(button)
2185 case ACTION_STD_PREV:
2186 if (++mode > 6) mode = 0;
2187 mode_changed = 1;
2188 break;
2190 case ACTION_STD_NEXT:
2191 if (which_led == BUTTONLIGHT_LED_ALL)
2193 which_led = BUTTONLIGHT_LED_MENU;
2195 else
2197 which_led = BUTTONLIGHT_LED_ALL;
2199 mode_changed = 1;
2201 break;
2204 case ACTION_STD_OK:
2205 case ACTION_STD_CANCEL:
2206 action_signalscreenchange();
2207 return false;
2209 default:
2210 sleep(HZ/10);
2211 break;
2214 return false;
2220 #endif
2222 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2223 static bool dbg_write_eeprom(void)
2225 int fd;
2226 int rc;
2227 int old_irq_level;
2228 char buf[EEPROM_SIZE];
2229 int err;
2231 fd = open("/internal_eeprom.bin", O_RDONLY);
2233 if (fd >= 0)
2235 rc = read(fd, buf, EEPROM_SIZE);
2237 if(rc == EEPROM_SIZE)
2239 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
2241 err = eeprom_24cxx_write(0, buf, sizeof buf);
2242 if (err)
2243 gui_syncsplash(HZ*3, "Eeprom write failure (%d)",err);
2244 else
2245 gui_syncsplash(HZ*3, "Eeprom written successfully");
2247 set_irq_level(old_irq_level);
2249 else
2251 gui_syncsplash(HZ*3, "File read error (%d)",rc);
2253 close(fd);
2255 else
2257 gui_syncsplash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2260 return false;
2262 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2263 #ifdef CPU_BOOST_LOGGING
2264 static bool cpu_boost_log(void)
2266 int i = 0,j=0;
2267 int count = cpu_boost_log_getcount();
2268 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2269 char *str;
2270 bool done;
2271 lcd_setmargins(0, 0);
2272 lcd_setfont(FONT_SYSFIXED);
2273 str = cpu_boost_log_getlog_first();
2274 while (i < count)
2276 lcd_clear_display();
2277 for(j=0; j<lines; j++,i++)
2279 if (!str)
2280 str = cpu_boost_log_getlog_next();
2281 if (str)
2283 lcd_puts(0, j,str);
2285 str = NULL;
2287 lcd_update();
2288 done = false;
2289 action_signalscreenchange();
2290 while (!done)
2292 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2294 case ACTION_STD_OK:
2295 case ACTION_STD_PREV:
2296 case ACTION_STD_NEXT:
2297 done = true;
2298 break;
2299 case ACTION_STD_CANCEL:
2300 i = count;
2301 done = true;
2302 break;
2306 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2307 lcd_setfont(FONT_UI);
2308 action_signalscreenchange();
2309 return false;
2311 #endif
2312 bool debug_menu(void)
2314 int m;
2315 bool result;
2317 static const struct menu_item items[] = {
2318 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2319 { "LCD Power Off", dbg_lcd_power_off },
2320 { "Button Light modes", dbg_buttonlights },
2322 #endif
2323 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2324 (defined(CPU_PP) && !defined(SANSA_E200))
2325 { "Dump ROM contents", dbg_save_roms },
2326 #endif
2327 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP)
2328 { "View I/O ports", dbg_ports },
2329 #endif
2330 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2331 { "CPU frequency", dbg_cpufreq },
2332 #endif
2333 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2334 { "S/PDIF analyzer", dbg_spdif },
2335 #endif
2336 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2337 { "Catch mem accesses", dbg_set_memory_guard },
2338 #endif
2339 #ifndef SIMULATOR
2340 { "View OS stacks", dbg_os },
2341 #endif
2342 #ifdef HAVE_LCD_BITMAP
2343 #ifndef SIMULATOR
2344 { "View battery", view_battery },
2345 #endif
2346 { "Screendump", dbg_screendump },
2347 #endif
2348 #ifndef SIMULATOR
2349 { "View HW info", dbg_hw_info },
2350 #endif
2351 #ifndef SIMULATOR
2352 { "View partitions", dbg_partitions },
2353 #endif
2354 #ifndef SIMULATOR
2355 #ifdef HAVE_MMC
2356 { "View MMC info", dbg_mmc_info },
2357 #else
2358 { "View disk info", dbg_disk_info },
2359 #endif
2360 #endif
2361 #ifdef HAVE_DIRCACHE
2362 { "View dircache info", dbg_dircache_info },
2363 #endif
2364 #ifdef HAVE_LCD_BITMAP
2365 #ifdef HAVE_TAGCACHE
2366 { "View database info", dbg_tagcache_info },
2367 #endif
2368 #if CONFIG_CODEC == SWCODEC || !defined(SIMULATOR)
2369 { "View audio thread", dbg_audio_thread },
2370 #endif
2371 #ifdef PM_DEBUG
2372 { "pm histogram", peak_meter_histogram},
2373 #endif /* PM_DEBUG */
2374 #endif /* HAVE_LCD_BITMAP */
2375 #ifndef SIMULATOR
2376 #if CONFIG_TUNER
2377 { "FM Radio", dbg_fm_radio },
2378 #endif
2379 #endif
2380 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2381 { "Write back EEPROM", dbg_write_eeprom },
2382 #endif
2383 #ifdef ROCKBOX_HAS_LOGF
2384 {"logf", logfdisplay },
2385 {"logfdump", logfdump },
2386 #endif
2387 #ifdef CPU_BOOST_LOGGING
2388 {"cpu_boost log",cpu_boost_log},
2389 #endif
2392 m=menu_init( items, sizeof items / sizeof(struct menu_item), NULL,
2393 "Debug Menu", NULL, NULL);
2394 result = menu_run(m);
2395 menu_exit(m);
2397 return result;