1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Heikki Hannikainen
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
29 #include "debug_menu.h"
36 #include "powermgmt.h"
40 #include "mp3_playback.h"
43 #include "statusbar.h"
53 #include "lcd-remote.h"
65 #include "eeprom_24cxx.h"
66 #if defined(HAVE_MMC) || defined(HAVE_ATA_SD)
75 #ifdef HAVE_LCD_BITMAP
76 #include "scrollbar.h"
77 #include "peakmeter.h"
80 #if CONFIG_CODEC == SWCODEC
82 #include "buffering.h"
84 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
88 #ifdef IRIVER_H300_SERIES
89 #include "pcf50606.h" /* for pcf50606_read */
96 #if CONFIG_RTC == RTC_PCF50605
100 #if CONFIG_CPU == DM320 || CONFIG_CPU == S3C2440 || CONFIG_CPU == TCC7801 \
101 || CONFIG_CPU == IMX31L
102 #include "debug-target.h"
105 #if defined(SANSA_E200) || defined(PHILIPS_SA9200)
110 #if defined(HAVE_USBSTACK)
111 #include "usb_core.h"
114 #include "../firmware/usbstack/usb_storage.h"
117 /*---------------------------------------------------*/
118 /* SPECIAL DEBUG STUFF */
119 /*---------------------------------------------------*/
120 extern struct thread_entry threads
[MAXTHREADS
];
122 static char thread_status_char(unsigned status
)
124 static const char thread_status_chars
[THREAD_NUM_STATES
+1] =
126 [0 ... THREAD_NUM_STATES
] = '?',
127 [STATE_RUNNING
] = 'R',
128 [STATE_BLOCKED
] = 'B',
129 [STATE_SLEEPING
] = 'S',
130 [STATE_BLOCKED_W_TMO
] = 'T',
131 [STATE_FROZEN
] = 'F',
132 [STATE_KILLED
] = 'K',
135 if (status
> THREAD_NUM_STATES
)
136 status
= THREAD_NUM_STATES
;
138 return thread_status_chars
[status
];
141 static char* threads_getname(int selected_item
, void *data
,
142 char *buffer
, size_t buffer_len
)
145 struct thread_entry
*thread
;
149 if (selected_item
< (int)NUM_CORES
)
151 snprintf(buffer
, buffer_len
, "Idle (%d): %2d%%", selected_item
,
152 idle_stack_usage(selected_item
));
156 selected_item
-= NUM_CORES
;
159 thread
= &threads
[selected_item
];
161 if (thread
->state
== STATE_KILLED
)
163 snprintf(buffer
, buffer_len
, "%2d: ---", selected_item
);
167 thread_get_name(name
, 32, thread
);
169 snprintf(buffer
, buffer_len
,
170 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
172 IF_COP(thread
->core
,)
173 #ifdef HAVE_SCHEDULER_BOOSTCTRL
174 (thread
->cpu_boost
) ? '+' :
176 ((thread
->state
== STATE_RUNNING
) ? '*' : ' '),
177 thread_status_char(thread
->state
),
178 IF_PRIO(thread
->base_priority
, thread
->priority
, )
179 thread_stack_usage(thread
), name
);
183 static int dbg_threads_action_callback(int action
, struct gui_synclist
*lists
)
186 #ifdef ROCKBOX_HAS_LOGF
187 if (action
== ACTION_STD_OK
)
189 int selpos
= gui_synclist_get_sel_pos(lists
);
191 if (selpos
>= NUM_CORES
)
192 remove_thread(&threads
[selpos
- NUM_CORES
]);
194 remove_thread(&threads
[selpos
]);
196 return ACTION_REDRAW
;
198 #endif /* ROCKBOX_HAS_LOGF */
199 if (action
== ACTION_NONE
)
200 action
= ACTION_REDRAW
;
204 static bool dbg_os(void)
206 struct simplelist_info info
;
207 simplelist_info_init(&info
, IF_COP("Core and ") "Stack usage:",
211 MAXTHREADS
+NUM_CORES
,
214 #ifndef ROCKBOX_HAS_LOGF
215 info
.hide_selection
= true;
216 info
.scroll_all
= true;
218 info
.action_callback
= dbg_threads_action_callback
;
219 info
.get_name
= threads_getname
;
220 return simplelist_show_list(&info
);
223 #ifdef HAVE_LCD_BITMAP
224 #if CONFIG_CODEC != SWCODEC
226 static bool dbg_audio_thread(void)
229 struct audio_debug d
;
231 lcd_setfont(FONT_SYSFIXED
);
235 if (action_userabort(HZ
/5))
238 audio_get_debugdata(&d
);
242 snprintf(buf
, sizeof(buf
), "read: %x", d
.audiobuf_read
);
244 snprintf(buf
, sizeof(buf
), "write: %x", d
.audiobuf_write
);
246 snprintf(buf
, sizeof(buf
), "swap: %x", d
.audiobuf_swapwrite
);
248 snprintf(buf
, sizeof(buf
), "playing: %d", d
.playing
);
250 snprintf(buf
, sizeof(buf
), "playable: %x", d
.playable_space
);
252 snprintf(buf
, sizeof(buf
), "unswapped: %x", d
.unswapped_space
);
255 /* Playable space left */
256 gui_scrollbar_draw(&screens
[SCREEN_MAIN
],0, 6*8, 112, 4, d
.audiobuflen
, 0,
257 d
.playable_space
, HORIZONTAL
);
259 /* Show the watermark limit */
260 gui_scrollbar_draw(&screens
[SCREEN_MAIN
],0, 6*8+4, 112, 4, d
.audiobuflen
, 0,
261 d
.low_watermark_level
, HORIZONTAL
);
263 snprintf(buf
, sizeof(buf
), "wm: %x - %x",
264 d
.low_watermark_level
, d
.lowest_watermark_level
);
271 #endif /* !SIMULATOR */
272 #else /* CONFIG_CODEC == SWCODEC */
273 extern size_t filebuflen
;
274 /* This is a size_t, but call it a long so it puts a - when it's bad. */
276 static unsigned int ticks
, boost_ticks
, freq_sum
;
278 static void dbg_audio_task(void)
281 if(FREQ
> CPUFREQ_NORMAL
)
283 freq_sum
+= FREQ
/1000000; /* in MHz */
288 static bool dbg_buffering_thread(void)
295 size_t bufsize
= pcmbuf_get_bufsize();
296 int pcmbufdescs
= pcmbuf_descs();
297 struct buffering_debug d
;
299 ticks
= boost_ticks
= freq_sum
= 0;
301 tick_add_task(dbg_audio_task
);
303 lcd_setfont(FONT_SYSFIXED
);
306 button
= get_action(CONTEXT_STD
,HZ
/5);
309 case ACTION_STD_NEXT
:
312 case ACTION_STD_PREV
:
315 case ACTION_STD_CANCEL
:
320 buffering_get_debugdata(&d
);
325 bufused
= bufsize
- pcmbuf_free();
327 snprintf(buf
, sizeof(buf
), "pcm: %7ld/%7ld", (long) bufused
, (long) bufsize
);
328 lcd_puts(0, line
++, buf
);
330 gui_scrollbar_draw(&screens
[SCREEN_MAIN
],0, line
*8, LCD_WIDTH
, 6,
331 bufsize
, 0, bufused
, HORIZONTAL
);
334 snprintf(buf
, sizeof(buf
), "alloc: %8ld/%8ld", audio_filebufused(),
336 lcd_puts(0, line
++, buf
);
339 gui_scrollbar_draw(&screens
[SCREEN_MAIN
],0, line
*8, LCD_WIDTH
, 6,
340 filebuflen
, 0, audio_filebufused(), HORIZONTAL
);
343 snprintf(buf
, sizeof(buf
), "real: %8ld/%8ld", (long)d
.buffered_data
,
345 lcd_puts(0, line
++, buf
);
347 gui_scrollbar_draw(&screens
[SCREEN_MAIN
],0, line
*8, LCD_WIDTH
, 6,
348 filebuflen
, 0, (long)d
.buffered_data
, HORIZONTAL
);
352 snprintf(buf
, sizeof(buf
), "usefl: %8ld/%8ld", (long)(d
.useful_data
),
354 lcd_puts(0, line
++, buf
);
357 gui_scrollbar_draw(&screens
[SCREEN_MAIN
],0, line
*8, LCD_WIDTH
, 6,
358 filebuflen
, 0, d
.useful_data
, HORIZONTAL
);
362 snprintf(buf
, sizeof(buf
), "data_rem: %ld", (long)d
.data_rem
);
363 lcd_puts(0, line
++, buf
);
365 snprintf(buf
, sizeof(buf
), "track count: %2d", audio_track_count());
366 lcd_puts(0, line
++, buf
);
368 snprintf(buf
, sizeof(buf
), "handle count: %d", (int)d
.num_handles
);
369 lcd_puts(0, line
++, buf
);
372 snprintf(buf
, sizeof(buf
), "cpu freq: %3dMHz",
373 (int)((FREQ
+ 500000) / 1000000));
374 lcd_puts(0, line
++, buf
);
379 int boostquota
= boost_ticks
* 1000 / ticks
; /* in 0.1 % */
380 int avgclock
= freq_sum
* 10 / ticks
; /* in 100 kHz */
381 snprintf(buf
, sizeof(buf
), "boost ratio: %3d.%d%% (%2d.%dMHz)",
382 boostquota
/10, boostquota
%10, avgclock
/10, avgclock
%10);
383 lcd_puts(0, line
++, buf
);
386 snprintf(buf
, sizeof(buf
), "pcmbufdesc: %2d/%2d",
387 pcmbuf_used_descs(), pcmbufdescs
);
388 lcd_puts(0, line
++, buf
);
393 tick_remove_task(dbg_audio_task
);
397 #endif /* CONFIG_CODEC */
398 #endif /* HAVE_LCD_BITMAP */
401 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
402 /* Tool function to read the flash manufacturer and type, if available.
403 Only chips which could be reprogrammed in system will return values.
404 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
405 /* In IRAM to avoid problems when running directly from Flash */
406 static bool dbg_flash_id(unsigned* p_manufacturer
, unsigned* p_device
,
407 unsigned addr1
, unsigned addr2
)
408 ICODE_ATTR
__attribute__((noinline
));
409 static bool dbg_flash_id(unsigned* p_manufacturer
, unsigned* p_device
,
410 unsigned addr1
, unsigned addr2
)
413 unsigned not_manu
, not_id
; /* read values before switching to ID mode */
414 unsigned manu
, id
; /* read values when in ID mode */
416 #if CONFIG_CPU == SH7034
417 volatile unsigned char* flash
= (unsigned char*)0x2000000; /* flash mapping */
418 #elif defined(CPU_COLDFIRE)
419 volatile unsigned short* flash
= (unsigned short*)0; /* flash mapping */
421 int old_level
; /* saved interrupt level */
423 not_manu
= flash
[0]; /* read the normal content */
424 not_id
= flash
[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
426 /* disable interrupts, prevent any stray flash access */
427 old_level
= disable_irq_save();
429 flash
[addr1
] = 0xAA; /* enter command mode */
431 flash
[addr1
] = 0x90; /* ID command */
432 /* Atmel wants 20ms pause here */
433 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
435 manu
= flash
[0]; /* read the IDs */
438 flash
[0] = 0xF0; /* reset flash (back to normal read mode) */
439 /* Atmel wants 20ms pause here */
440 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
442 restore_irq(old_level
); /* enable interrupts again */
444 /* I assume success if the obtained values are different from
445 the normal flash content. This is not perfectly bulletproof, they
446 could theoretically be the same by chance, causing us to fail. */
447 if (not_manu
!= manu
|| not_id
!= id
) /* a value has changed */
449 *p_manufacturer
= manu
; /* return the results */
451 return true; /* success */
453 return false; /* fail */
455 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
459 static int perfcheck(void)
465 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
468 "ldr r0, [%[timr]] \n"
469 "add r0, r0, %[tmo] \n"
471 "add %[res], %[res], #1 \n"
472 "ldr r1, [%[timr]] \n"
475 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
479 [timr
]"r"(&USEC_TIMER
),
481 #if CONFIG_CPU == PP5002
483 #else /* PP5020/5022/5024 */
494 #ifdef HAVE_LCD_BITMAP
495 static bool dbg_hw_info(void)
497 #if CONFIG_CPU == SH7034
499 int bitmask
= HW_MASK
;
500 int rom_version
= ROM_VERSION
;
501 unsigned manu
, id
; /* flash IDs */
502 bool got_id
; /* flag if we managed to get the flash IDs */
503 unsigned rom_crc
= 0xffffffff; /* CRC32 of the boot ROM */
504 bool has_bootrom
; /* flag for boot ROM present */
505 int oldmode
; /* saved memory guard mode */
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 */
512 got_id
= dbg_flash_id(&manu
, &id
, 0x555, 0x2AA); /* try AMD, Macronix */
514 /* check if the boot ROM area is a flash mirror */
515 has_bootrom
= (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
516 if (has_bootrom
) /* if ROM and Flash different */
518 /* calculate CRC16 checksum of boot ROM */
519 rom_crc
= crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
522 system_memory_guard(oldmode
); /* re-enable memory guard */
524 lcd_setfont(FONT_SYSFIXED
);
527 lcd_puts(0, 0, "[Hardware info]");
529 snprintf(buf
, 32, "ROM: %d.%02d", rom_version
/100, rom_version
%100);
532 snprintf(buf
, 32, "Mask: 0x%04x", bitmask
);
536 snprintf(buf
, 32, "Flash: M=%02x D=%02x", manu
, id
);
538 snprintf(buf
, 32, "Flash: M=?? D=??"); /* unknown, sorry */
543 if (rom_crc
== 0x56DBA4EE) /* known Version 1 */
544 snprintf(buf
, 32, "Boot ROM: V1");
546 snprintf(buf
, 32, "ROMcrc: 0x%08x", rom_crc
);
550 snprintf(buf
, 32, "Boot ROM: none");
556 while (!(action_userabort(TIMEOUT_BLOCK
)));
558 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
560 unsigned manu
, id
; /* flash IDs */
561 int got_id
; /* flag if we managed to get the flash IDs */
562 int oldmode
; /* saved memory guard mode */
565 oldmode
= system_memory_guard(MEMGUARD_NONE
); /* disable memory guard */
567 /* get flash ROM type */
568 got_id
= dbg_flash_id(&manu
, &id
, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
570 got_id
= dbg_flash_id(&manu
, &id
, 0x555, 0x2AA); /* try AMD, Macronix */
572 system_memory_guard(oldmode
); /* re-enable memory guard */
574 lcd_setfont(FONT_SYSFIXED
);
577 lcd_puts(0, line
++, "[Hardware info]");
580 snprintf(buf
, 32, "Flash: M=%04x D=%04x", manu
, id
);
582 snprintf(buf
, 32, "Flash: M=???? D=????"); /* unknown, sorry */
583 lcd_puts(0, line
++, buf
);
589 lcd_puts(0, ++line
, "Serial Number:");
591 got_id
= ds2411_read_id(&id
);
593 if (got_id
== DS2411_OK
)
595 snprintf(buf
, 32, " FC=%02x", (unsigned)id
.family_code
);
596 lcd_puts(0, ++line
, buf
);
597 snprintf(buf
, 32, " ID=%02X %02X %02X %02X %02X %02X",
598 (unsigned)id
.uid
[0], (unsigned)id
.uid
[1], (unsigned)id
.uid
[2],
599 (unsigned)id
.uid
[3], (unsigned)id
.uid
[4], (unsigned)id
.uid
[5]);
600 lcd_puts(0, ++line
, buf
);
601 snprintf(buf
, 32, " CRC=%02X", (unsigned)id
.crc
);
605 snprintf(buf
, 32, "READ ERR=%d", got_id
);
608 lcd_puts(0, ++line
, buf
);
614 while (!(action_userabort(TIMEOUT_BLOCK
)));
616 #elif defined(CPU_PP502x)
619 char pp_version
[] = { (PP_VER2
>> 24) & 0xff, (PP_VER2
>> 16) & 0xff,
620 (PP_VER2
>> 8) & 0xff, (PP_VER2
) & 0xff,
621 (PP_VER1
>> 24) & 0xff, (PP_VER1
>> 16) & 0xff,
622 (PP_VER1
>> 8) & 0xff, (PP_VER1
) & 0xff, '\0' };
624 lcd_setfont(FONT_SYSFIXED
);
627 lcd_puts(0, line
++, "[Hardware info]");
630 snprintf(buf
, sizeof(buf
), "HW rev: 0x%08lx", IPOD_HW_REVISION
);
631 lcd_puts(0, line
++, buf
);
635 extern int lcd_type
; /* Defined in lcd-colornano.c */
637 snprintf(buf
, sizeof(buf
), "LCD type: %d", lcd_type
);
638 lcd_puts(0, line
++, buf
);
641 snprintf(buf
, sizeof(buf
), "PP version: %s", pp_version
);
642 lcd_puts(0, line
++, buf
);
644 snprintf(buf
, sizeof(buf
), "Est. clock (kHz): %d", perfcheck());
645 lcd_puts(0, line
++, buf
);
649 while (!(action_userabort(TIMEOUT_BLOCK
)));
651 #elif CONFIG_CPU == PP5002
654 char pp_version
[] = { (PP_VER4
>> 8) & 0xff, PP_VER4
& 0xff,
655 (PP_VER3
>> 8) & 0xff, PP_VER3
& 0xff,
656 (PP_VER2
>> 8) & 0xff, PP_VER2
& 0xff,
657 (PP_VER1
>> 8) & 0xff, PP_VER1
& 0xff, '\0' };
660 lcd_setfont(FONT_SYSFIXED
);
663 lcd_puts(0, line
++, "[Hardware info]");
666 snprintf(buf
, sizeof(buf
), "HW rev: 0x%08lx", IPOD_HW_REVISION
);
667 lcd_puts(0, line
++, buf
);
670 snprintf(buf
, sizeof(buf
), "PP version: %s", pp_version
);
671 lcd_puts(0, line
++, buf
);
673 snprintf(buf
, sizeof(buf
), "Est. clock (kHz): %d", perfcheck());
674 lcd_puts(0, line
++, buf
);
678 while (!(action_userabort(TIMEOUT_BLOCK
)));
680 /* Define this function in your target tree */
681 return __dbg_hw_info();
682 #endif /* CONFIG_CPU */
685 #else /* !HAVE_LCD_BITMAP */
686 static bool dbg_hw_info(void)
691 int rom_version
= ROM_VERSION
;
692 unsigned manu
, id
; /* flash IDs */
693 bool got_id
; /* flag if we managed to get the flash IDs */
694 unsigned rom_crc
= 0xffffffff; /* CRC32 of the boot ROM */
695 bool has_bootrom
; /* flag for boot ROM present */
696 int oldmode
; /* saved memory guard mode */
698 oldmode
= system_memory_guard(MEMGUARD_NONE
); /* disable memory guard */
700 /* get flash ROM type */
701 got_id
= dbg_flash_id(&manu
, &id
, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
703 got_id
= dbg_flash_id(&manu
, &id
, 0x555, 0x2AA); /* try AMD, Macronix */
705 /* check if the boot ROM area is a flash mirror */
706 has_bootrom
= (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
707 if (has_bootrom
) /* if ROM and Flash different */
709 /* calculate CRC16 checksum of boot ROM */
710 rom_crc
= crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
713 system_memory_guard(oldmode
); /* re-enable memory guard */
717 lcd_puts(0, 0, "[HW Info]");
723 snprintf(buf
, 32, "ROM: %d.%02d",
724 rom_version
/100, rom_version
%100);
728 snprintf(buf
, 32, "Flash:%02x,%02x", manu
, id
);
730 snprintf(buf
, 32, "Flash:??,??"); /* unknown, sorry */
735 if (rom_crc
== 0x56DBA4EE) /* known Version 1 */
736 snprintf(buf
, 32, "BootROM: V1");
737 else if (rom_crc
== 0x358099E8)
738 snprintf(buf
, 32, "BootROM: V2");
739 /* alternative boot ROM found in one single player so far */
741 snprintf(buf
, 32, "R: %08x", rom_crc
);
744 snprintf(buf
, 32, "BootROM: no");
750 button
= get_action(CONTEXT_SETTINGS
,TIMEOUT_BLOCK
);
754 case ACTION_STD_CANCEL
:
757 case ACTION_SETTINGS_DEC
:
763 case ACTION_SETTINGS_INC
:
772 #endif /* !HAVE_LCD_BITMAP */
773 #endif /* !SIMULATOR */
776 static char* dbg_partitions_getname(int selected_item
, void *data
,
777 char *buffer
, size_t buffer_len
)
780 int partition
= selected_item
/2;
781 struct partinfo
* p
= disk_partinfo(partition
);
784 snprintf(buffer
, buffer_len
, " T:%x %ld MB", p
->type
, p
->size
/ 2048);
788 snprintf(buffer
, buffer_len
, "P%d: S:%lx", partition
, p
->start
);
793 bool dbg_partitions(void)
795 struct simplelist_info info
;
796 simplelist_info_init(&info
, "Partition Info", 4, NULL
);
797 info
.selection_size
= 2;
798 info
.hide_selection
= true;
799 info
.scroll_all
= true;
800 info
.get_name
= dbg_partitions_getname
;
801 return simplelist_show_list(&info
);
805 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
806 static bool dbg_spdif(void)
810 unsigned int control
;
815 unsigned int interruptstat
;
816 bool valnogood
, symbolerr
, parityerr
;
819 int spdif_source
= spdif_get_output_source(&spdif_src_on
);
820 spdif_set_output_source(AUDIO_SRC_SPDIF
IF_SPDIF_POWER_(, true));
823 lcd_setfont(FONT_SYSFIXED
);
825 #ifdef HAVE_SPDIF_POWER
826 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
833 control
= EBU1RCVCCHANNEL1
;
834 interruptstat
= INTERRUPTSTAT
;
835 INTERRUPTCLEAR
= 0x03c00000;
837 valnogood
= (interruptstat
& 0x01000000)?true:false;
838 symbolerr
= (interruptstat
& 0x00800000)?true:false;
839 parityerr
= (interruptstat
& 0x00400000)?true:false;
841 snprintf(buf
, sizeof(buf
), "Val: %s Sym: %s Par: %s",
844 parityerr
?"--":"OK");
845 lcd_puts(0, line
++, buf
);
847 snprintf(buf
, sizeof(buf
), "Status word: %08x", (int)control
);
848 lcd_puts(0, line
++, buf
);
853 snprintf(buf
, sizeof(buf
), "PRO: %d (%s)",
854 x
, x
?"Professional":"Consumer");
855 lcd_puts(0, line
++, buf
);
857 x
= (control
>> 30) & 1;
858 snprintf(buf
, sizeof(buf
), "Audio: %d (%s)",
859 x
, x
?"Non-PCM":"PCM");
860 lcd_puts(0, line
++, buf
);
862 x
= (control
>> 29) & 1;
863 snprintf(buf
, sizeof(buf
), "Copy: %d (%s)",
864 x
, x
?"Permitted":"Inhibited");
865 lcd_puts(0, line
++, buf
);
867 x
= (control
>> 27) & 7;
880 snprintf(buf
, sizeof(buf
), "Preemphasis: %d (%s)", x
, s
);
881 lcd_puts(0, line
++, buf
);
883 x
= (control
>> 24) & 3;
884 snprintf(buf
, sizeof(buf
), "Mode: %d", x
);
885 lcd_puts(0, line
++, buf
);
887 category
= (control
>> 17) & 127;
899 snprintf(buf
, sizeof(buf
), "Category: 0x%02x (%s)", category
, s
);
900 lcd_puts(0, line
++, buf
);
902 x
= (control
>> 16) & 1;
904 if(((category
& 0x70) == 0x10) ||
905 ((category
& 0x70) == 0x40) ||
906 ((category
& 0x78) == 0x38))
908 generation
= !generation
;
910 snprintf(buf
, sizeof(buf
), "Generation: %d (%s)",
911 x
, generation
?"Original":"No ind.");
912 lcd_puts(0, line
++, buf
);
914 x
= (control
>> 12) & 15;
915 snprintf(buf
, sizeof(buf
), "Source: %d", x
);
916 lcd_puts(0, line
++, buf
);
918 x
= (control
>> 8) & 15;
934 snprintf(buf
, sizeof(buf
), "Channel: %d (%s)", x
, s
);
935 lcd_puts(0, line
++, buf
);
937 x
= (control
>> 4) & 15;
950 snprintf(buf
, sizeof(buf
), "Frequency: %d (%s)", x
, s
);
951 lcd_puts(0, line
++, buf
);
953 x
= (control
>> 2) & 3;
954 snprintf(buf
, sizeof(buf
), "Clock accuracy: %d", x
);
955 lcd_puts(0, line
++, buf
);
959 snprintf(buf
, sizeof(buf
), "Measured freq: %ldHz",
960 spdif_measure_frequency());
961 lcd_puts(0, line
++, buf
);
966 if (action_userabort(HZ
/10))
970 spdif_set_output_source(spdif_source
IF_SPDIF_POWER_(, spdif_src_on
));
972 #ifdef HAVE_SPDIF_POWER
973 spdif_power_enable(global_settings
.spdif_enable
);
978 #endif /* CPU_COLDFIRE */
981 #ifdef HAVE_LCD_BITMAP
982 /* button definitions */
983 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
984 (CONFIG_KEYPAD == IRIVER_H300_PAD)
985 # define DEBUG_CANCEL BUTTON_OFF
987 #elif CONFIG_KEYPAD == RECORDER_PAD
988 # define DEBUG_CANCEL BUTTON_OFF
990 #elif CONFIG_KEYPAD == ONDIO_PAD
991 # define DEBUG_CANCEL BUTTON_MENU
993 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
994 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
995 (CONFIG_KEYPAD == IPOD_4G_PAD)
996 # define DEBUG_CANCEL BUTTON_MENU
998 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
999 # define DEBUG_CANCEL BUTTON_PLAY
1001 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
1002 # define DEBUG_CANCEL BUTTON_REC
1004 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1005 # define DEBUG_CANCEL BUTTON_RC_REC
1007 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
1008 # define DEBUG_CANCEL BUTTON_REW
1010 #elif (CONFIG_KEYPAD == MROBE100_PAD)
1011 # define DEBUG_CANCEL BUTTON_MENU
1013 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
1014 (CONFIG_KEYPAD == SANSA_C200_PAD)
1015 # define DEBUG_CANCEL BUTTON_LEFT
1017 /* This is temporary until the SA9200 touchpad works */
1018 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) || \
1019 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD)
1020 # define DEBUG_CANCEL BUTTON_POWER
1022 #endif /* key definitions */
1025 bool dbg_ports(void)
1027 #if CONFIG_CPU == SH7034
1029 int adc_battery_voltage
, adc_battery_level
;
1031 lcd_setfont(FONT_SYSFIXED
);
1032 lcd_clear_display();
1036 snprintf(buf
, 32, "PADR: %04x", (unsigned short)PADR
);
1037 lcd_puts(0, 0, buf
);
1038 snprintf(buf
, 32, "PBDR: %04x", (unsigned short)PBDR
);
1039 lcd_puts(0, 1, buf
);
1041 snprintf(buf
, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1042 lcd_puts(0, 2, buf
);
1043 snprintf(buf
, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1044 lcd_puts(0, 3, buf
);
1045 snprintf(buf
, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1046 lcd_puts(0, 4, buf
);
1047 snprintf(buf
, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1048 lcd_puts(0, 5, buf
);
1050 battery_read_info(&adc_battery_voltage
, &adc_battery_level
);
1051 snprintf(buf
, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage
/ 1000,
1052 adc_battery_voltage
% 1000, adc_battery_level
);
1053 lcd_puts(0, 6, buf
);
1056 if (button_get_w_tmo(HZ
/10) == (DEBUG_CANCEL
|BUTTON_REL
))
1059 #elif defined(CPU_COLDFIRE)
1060 unsigned int gpio_out
;
1061 unsigned int gpio1_out
;
1062 unsigned int gpio_read
;
1063 unsigned int gpio1_read
;
1064 unsigned int gpio_function
;
1065 unsigned int gpio1_function
;
1066 unsigned int gpio_enable
;
1067 unsigned int gpio1_enable
;
1068 int adc_buttons
, adc_remote
;
1069 int adc_battery_voltage
, adc_battery_level
;
1073 lcd_clear_display();
1074 lcd_setfont(FONT_SYSFIXED
);
1079 gpio_read
= GPIO_READ
;
1080 gpio1_read
= GPIO1_READ
;
1081 gpio_out
= GPIO_OUT
;
1082 gpio1_out
= GPIO1_OUT
;
1083 gpio_function
= GPIO_FUNCTION
;
1084 gpio1_function
= GPIO1_FUNCTION
;
1085 gpio_enable
= GPIO_ENABLE
;
1086 gpio1_enable
= GPIO1_ENABLE
;
1088 snprintf(buf
, sizeof(buf
), "GPIO_READ: %08x", gpio_read
);
1089 lcd_puts(0, line
++, buf
);
1090 snprintf(buf
, sizeof(buf
), "GPIO_OUT: %08x", gpio_out
);
1091 lcd_puts(0, line
++, buf
);
1092 snprintf(buf
, sizeof(buf
), "GPIO_FUNC: %08x", gpio_function
);
1093 lcd_puts(0, line
++, buf
);
1094 snprintf(buf
, sizeof(buf
), "GPIO_ENA: %08x", gpio_enable
);
1095 lcd_puts(0, line
++, buf
);
1097 snprintf(buf
, sizeof(buf
), "GPIO1_READ: %08x", gpio1_read
);
1098 lcd_puts(0, line
++, buf
);
1099 snprintf(buf
, sizeof(buf
), "GPIO1_OUT: %08x", gpio1_out
);
1100 lcd_puts(0, line
++, buf
);
1101 snprintf(buf
, sizeof(buf
), "GPIO1_FUNC: %08x", gpio1_function
);
1102 lcd_puts(0, line
++, buf
);
1103 snprintf(buf
, sizeof(buf
), "GPIO1_ENA: %08x", gpio1_enable
);
1104 lcd_puts(0, line
++, buf
);
1106 adc_buttons
= adc_read(ADC_BUTTONS
);
1107 adc_remote
= adc_read(ADC_REMOTE
);
1108 battery_read_info(&adc_battery_voltage
, &adc_battery_level
);
1109 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1110 snprintf(buf
, sizeof(buf
), "ADC_BUTTONS (%c): %02x",
1111 button_scan_enabled() ? '+' : '-', adc_buttons
);
1113 snprintf(buf
, sizeof(buf
), "ADC_BUTTONS: %02x", adc_buttons
);
1115 lcd_puts(0, line
++, buf
);
1116 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1117 snprintf(buf
, sizeof(buf
), "ADC_REMOTE (%c): %02x",
1118 remote_detect() ? '+' : '-', adc_remote
);
1120 snprintf(buf
, sizeof(buf
), "ADC_REMOTE: %02x", adc_remote
);
1122 lcd_puts(0, line
++, buf
);
1123 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1124 snprintf(buf
, sizeof(buf
), "ADC_REMOTEDETECT: %02x",
1125 adc_read(ADC_REMOTEDETECT
));
1126 lcd_puts(0, line
++, buf
);
1129 snprintf(buf
, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage
/ 1000,
1130 adc_battery_voltage
% 1000, adc_battery_level
);
1131 lcd_puts(0, line
++, buf
);
1133 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1134 snprintf(buf
, sizeof(buf
), "remotetype: %d", remote_type());
1135 lcd_puts(0, line
++, buf
);
1139 if (button_get_w_tmo(HZ
/10) == (DEBUG_CANCEL
|BUTTON_REL
))
1143 #elif defined(CPU_PP502x)
1148 lcd_clear_display();
1149 lcd_setfont(FONT_SYSFIXED
);
1154 lcd_puts(0, line
++, "GPIO STATES:");
1155 snprintf(buf
, sizeof(buf
), "A: %02x E: %02x I: %02x",
1156 (unsigned int)GPIOA_INPUT_VAL
,
1157 (unsigned int)GPIOE_INPUT_VAL
,
1158 (unsigned int)GPIOI_INPUT_VAL
);
1159 lcd_puts(0, line
++, buf
);
1160 snprintf(buf
, sizeof(buf
), "B: %02x F: %02x J: %02x",
1161 (unsigned int)GPIOB_INPUT_VAL
,
1162 (unsigned int)GPIOF_INPUT_VAL
,
1163 (unsigned int)GPIOJ_INPUT_VAL
);
1164 lcd_puts(0, line
++, buf
);
1165 snprintf(buf
, sizeof(buf
), "C: %02x G: %02x K: %02x",
1166 (unsigned int)GPIOC_INPUT_VAL
,
1167 (unsigned int)GPIOG_INPUT_VAL
,
1168 (unsigned int)GPIOK_INPUT_VAL
);
1169 lcd_puts(0, line
++, buf
);
1170 snprintf(buf
, sizeof(buf
), "D: %02x H: %02x L: %02x",
1171 (unsigned int)GPIOD_INPUT_VAL
,
1172 (unsigned int)GPIOH_INPUT_VAL
,
1173 (unsigned int)GPIOL_INPUT_VAL
);
1174 lcd_puts(0, line
++, buf
);
1176 snprintf(buf
, sizeof(buf
), "GPO32_VAL: %08lx", GPO32_VAL
);
1177 lcd_puts(0, line
++, buf
);
1178 snprintf(buf
, sizeof(buf
), "GPO32_EN: %08lx", GPO32_ENABLE
);
1179 lcd_puts(0, line
++, buf
);
1180 snprintf(buf
, sizeof(buf
), "DEV_EN: %08lx", DEV_EN
);
1181 lcd_puts(0, line
++, buf
);
1182 snprintf(buf
, sizeof(buf
), "DEV_EN2: %08lx", DEV_EN2
);
1183 lcd_puts(0, line
++, buf
);
1184 snprintf(buf
, sizeof(buf
), "DEV_EN3: %08lx", inl(0x60006044));
1185 lcd_puts(0, line
++, buf
); /* to be verified */
1186 snprintf(buf
, sizeof(buf
), "DEV_INIT1: %08lx", DEV_INIT1
);
1187 lcd_puts(0, line
++, buf
);
1188 snprintf(buf
, sizeof(buf
), "DEV_INIT2: %08lx", DEV_INIT2
);
1189 lcd_puts(0, line
++, buf
);
1190 #ifdef ADC_ACCESSORY
1191 snprintf(buf
, sizeof(buf
), "ACCESSORY: %d", adc_read(ADC_ACCESSORY
));
1192 lcd_puts(0, line
++, buf
);
1195 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1197 snprintf(buf
, sizeof(buf
), "BATT: %03x UNK1: %03x",
1198 adc_read(ADC_BATTERY
), adc_read(ADC_UNKNOWN_1
));
1199 lcd_puts(0, line
++, buf
);
1200 snprintf(buf
, sizeof(buf
), "REM: %03x PAD: %03x",
1201 adc_read(ADC_REMOTE
), adc_read(ADC_SCROLLPAD
));
1202 lcd_puts(0, line
++, buf
);
1203 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1204 snprintf(buf
, sizeof(buf
), "ADC_BVDD: %4d", adc_read(ADC_BVDD
));
1205 lcd_puts(0, line
++, buf
);
1206 snprintf(buf
, sizeof(buf
), "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP
));
1207 lcd_puts(0, line
++, buf
);
1208 snprintf(buf
, sizeof(buf
), "ADC_UVDD: %4d", adc_read(ADC_UVDD
));
1209 lcd_puts(0, line
++, buf
);
1210 snprintf(buf
, sizeof(buf
), "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN
));
1211 lcd_puts(0, line
++, buf
);
1212 snprintf(buf
, sizeof(buf
), "ADC_CVDD: %4d", adc_read(ADC_CVDD
));
1213 lcd_puts(0, line
++, buf
);
1214 snprintf(buf
, sizeof(buf
), "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP
));
1215 lcd_puts(0, line
++, buf
);
1216 snprintf(buf
, sizeof(buf
), "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1
));
1217 lcd_puts(0, line
++, buf
);
1218 snprintf(buf
, sizeof(buf
), "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2
));
1219 lcd_puts(0, line
++, buf
);
1220 snprintf(buf
, sizeof(buf
), "ADC_VBE1: %4d", adc_read(ADC_VBE1
));
1221 lcd_puts(0, line
++, buf
);
1222 snprintf(buf
, sizeof(buf
), "ADC_VBE2: %4d", adc_read(ADC_VBE2
));
1223 lcd_puts(0, line
++, buf
);
1224 snprintf(buf
, sizeof(buf
), "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1
));
1225 lcd_puts(0, line
++, buf
);
1226 #if !defined(PHILIPS_SA9200)
1227 snprintf(buf
, sizeof(buf
), "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2
));
1228 lcd_puts(0, line
++, buf
);
1229 snprintf(buf
, sizeof(buf
), "ADC_VBAT: %4d", adc_read(ADC_VBAT
));
1230 lcd_puts(0, line
++, buf
);
1231 snprintf(buf
, sizeof(buf
), "CHARGER: %02X/%02X", i2c_readbyte(AS3514_I2C_ADDR
, AS3514_CHARGER
), i2c_readbyte(AS3514_I2C_ADDR
, AS3514_IRQ_ENRD0
));
1232 lcd_puts(0, line
++, buf
);
1236 if (button_get_w_tmo(HZ
/10) == (DEBUG_CANCEL
|BUTTON_REL
))
1240 #elif CONFIG_CPU == PP5002
1244 lcd_clear_display();
1245 lcd_setfont(FONT_SYSFIXED
);
1250 snprintf(buf
, sizeof(buf
), "GPIO_A: %02x GPIO_B: %02x",
1251 (unsigned int)GPIOA_INPUT_VAL
, (unsigned int)GPIOB_INPUT_VAL
);
1252 lcd_puts(0, line
++, buf
);
1253 snprintf(buf
, sizeof(buf
), "GPIO_C: %02x GPIO_D: %02x",
1254 (unsigned int)GPIOC_INPUT_VAL
, (unsigned int)GPIOD_INPUT_VAL
);
1255 lcd_puts(0, line
++, buf
);
1257 snprintf(buf
, sizeof(buf
), "DEV_EN: %08lx", DEV_EN
);
1258 lcd_puts(0, line
++, buf
);
1259 snprintf(buf
, sizeof(buf
), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE
);
1260 lcd_puts(0, line
++, buf
);
1261 snprintf(buf
, sizeof(buf
), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE
);
1262 lcd_puts(0, line
++, buf
);
1263 snprintf(buf
, sizeof(buf
), "PLL_CONTROL: %08lx", PLL_CONTROL
);
1264 lcd_puts(0, line
++, buf
);
1265 snprintf(buf
, sizeof(buf
), "PLL_DIV: %08lx", PLL_DIV
);
1266 lcd_puts(0, line
++, buf
);
1267 snprintf(buf
, sizeof(buf
), "PLL_MULT: %08lx", PLL_MULT
);
1268 lcd_puts(0, line
++, buf
);
1269 snprintf(buf
, sizeof(buf
), "TIMING1_CTL: %08lx", TIMING1_CTL
);
1270 lcd_puts(0, line
++, buf
);
1271 snprintf(buf
, sizeof(buf
), "TIMING2_CTL: %08lx", TIMING2_CTL
);
1272 lcd_puts(0, line
++, buf
);
1275 if (button_get_w_tmo(HZ
/10) == (DEBUG_CANCEL
|BUTTON_REL
))
1279 return __dbg_ports();
1283 #else /* !HAVE_LCD_BITMAP */
1284 bool dbg_ports(void)
1288 int adc_battery_voltage
;
1291 lcd_clear_display();
1298 snprintf(buf
, 32, "PADR: %04x", (unsigned short)PADR
);
1301 snprintf(buf
, 32, "PBDR: %04x", (unsigned short)PBDR
);
1304 snprintf(buf
, 32, "AN0: %03x", adc_read(0));
1307 snprintf(buf
, 32, "AN1: %03x", adc_read(1));
1310 snprintf(buf
, 32, "AN2: %03x", adc_read(2));
1313 snprintf(buf
, 32, "AN3: %03x", adc_read(3));
1316 snprintf(buf
, 32, "AN4: %03x", adc_read(4));
1319 snprintf(buf
, 32, "AN5: %03x", adc_read(5));
1322 snprintf(buf
, 32, "AN6: %03x", adc_read(6));
1325 snprintf(buf
, 32, "AN7: %03x", adc_read(7));
1329 lcd_puts(0, 0, buf
);
1331 battery_read_info(&adc_battery_voltage
, NULL
);
1332 snprintf(buf
, 32, "Batt: %d.%03dV", adc_battery_voltage
/ 1000,
1333 adc_battery_voltage
% 1000);
1334 lcd_puts(0, 1, buf
);
1337 button
= get_action(CONTEXT_SETTINGS
,HZ
/5);
1341 case ACTION_STD_CANCEL
:
1344 case ACTION_SETTINGS_DEC
:
1350 case ACTION_SETTINGS_INC
:
1359 #endif /* !HAVE_LCD_BITMAP */
1360 #endif /* !SIMULATOR */
1362 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1363 static bool dbg_pcf(void)
1368 #ifdef HAVE_LCD_BITMAP
1369 lcd_setfont(FONT_SYSFIXED
);
1371 lcd_clear_display();
1377 snprintf(buf
, sizeof(buf
), "DCDC1: %02x", pcf50605_read(0x1b));
1378 lcd_puts(0, line
++, buf
);
1379 snprintf(buf
, sizeof(buf
), "DCDC2: %02x", pcf50605_read(0x1c));
1380 lcd_puts(0, line
++, buf
);
1381 snprintf(buf
, sizeof(buf
), "DCDC3: %02x", pcf50605_read(0x1d));
1382 lcd_puts(0, line
++, buf
);
1383 snprintf(buf
, sizeof(buf
), "DCDC4: %02x", pcf50605_read(0x1e));
1384 lcd_puts(0, line
++, buf
);
1385 snprintf(buf
, sizeof(buf
), "DCDEC1: %02x", pcf50605_read(0x1f));
1386 lcd_puts(0, line
++, buf
);
1387 snprintf(buf
, sizeof(buf
), "DCDEC2: %02x", pcf50605_read(0x20));
1388 lcd_puts(0, line
++, buf
);
1389 snprintf(buf
, sizeof(buf
), "DCUDC1: %02x", pcf50605_read(0x21));
1390 lcd_puts(0, line
++, buf
);
1391 snprintf(buf
, sizeof(buf
), "DCUDC2: %02x", pcf50605_read(0x22));
1392 lcd_puts(0, line
++, buf
);
1393 snprintf(buf
, sizeof(buf
), "IOREGC: %02x", pcf50605_read(0x23));
1394 lcd_puts(0, line
++, buf
);
1395 snprintf(buf
, sizeof(buf
), "D1REGC: %02x", pcf50605_read(0x24));
1396 lcd_puts(0, line
++, buf
);
1397 snprintf(buf
, sizeof(buf
), "D2REGC: %02x", pcf50605_read(0x25));
1398 lcd_puts(0, line
++, buf
);
1399 snprintf(buf
, sizeof(buf
), "D3REGC: %02x", pcf50605_read(0x26));
1400 lcd_puts(0, line
++, buf
);
1401 snprintf(buf
, sizeof(buf
), "LPREG1: %02x", pcf50605_read(0x27));
1402 lcd_puts(0, line
++, buf
);
1405 if (button_get_w_tmo(HZ
/10) == (DEBUG_CANCEL
|BUTTON_REL
))
1415 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1416 static bool dbg_cpufreq(void)
1422 #ifdef HAVE_LCD_BITMAP
1423 lcd_setfont(FONT_SYSFIXED
);
1425 lcd_clear_display();
1431 snprintf(buf
, sizeof(buf
), "Frequency: %ld", FREQ
);
1432 lcd_puts(0, line
++, buf
);
1434 snprintf(buf
, sizeof(buf
), "boost_counter: %d", get_cpu_boost_counter());
1435 lcd_puts(0, line
++, buf
);
1438 button
= get_action(CONTEXT_STD
,HZ
/10);
1442 case ACTION_STD_PREV
:
1446 case ACTION_STD_NEXT
:
1451 while (get_cpu_boost_counter() > 0)
1453 set_cpu_frequency(CPUFREQ_DEFAULT
);
1456 case ACTION_STD_CANCEL
:
1463 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1465 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1466 #include "tsc2100.h"
1467 char *itob(int n
, int len
)
1469 static char binary
[64];
1471 for (i
=1, j
=0;i
<=len
;i
++)
1473 binary
[j
++] = n
&(1<<(len
-i
))?'1':'0';
1480 static char* tsc2100_debug_getname(int selected_item
, void * data
,
1481 char *buffer
, size_t buffer_len
)
1483 int *page
= (int*)data
;
1484 bool reserved
= false;
1488 if ((selected_item
> 0x0a) ||
1489 (selected_item
== 0x04) ||
1490 (selected_item
== 0x08))
1494 if ((selected_item
> 0x05) ||
1495 (selected_item
== 0x02))
1499 if (selected_item
> 0x1e)
1504 snprintf(buffer
, buffer_len
, "%02x: RESERVED", selected_item
);
1506 snprintf(buffer
, buffer_len
, "%02x: %s", selected_item
,
1507 itob(tsc2100_readreg(*page
, selected_item
)&0xffff,16));
1510 static int tsc2100debug_action_callback(int action
, struct gui_synclist
*lists
)
1512 int *page
= (int*)lists
->data
;
1513 if (action
== ACTION_STD_OK
)
1515 *page
= (*page
+1)%3;
1516 snprintf(lists
->title
, 32,
1517 "tsc2100 registers - Page %d", *page
);
1518 return ACTION_REDRAW
;
1522 bool tsc2100_debug(void)
1525 char title
[32] = "tsc2100 registers - Page 0";
1526 struct simplelist_info info
;
1527 simplelist_info_init(&info
, title
, 32, &page
);
1528 info
.timeout
= HZ
/100;
1529 info
.get_name
= tsc2100_debug_getname
;
1530 info
.action_callback
= tsc2100debug_action_callback
;
1531 return simplelist_show_list(&info
);
1535 #ifdef HAVE_LCD_BITMAP
1537 * view_battery() shows a automatically scaled graph of the battery voltage
1538 * over time. Usable for estimating battery life / charging rate.
1539 * The power_history array is updated in power_thread of powermgmt.c.
1542 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1543 #define BAT_YSPACE (LCD_HEIGHT - 20)
1545 static bool view_battery(void)
1549 unsigned short maxv
, minv
;
1552 lcd_setfont(FONT_SYSFIXED
);
1556 lcd_clear_display();
1558 case 0: /* voltage history graph */
1559 /* Find maximum and minimum voltage for scaling */
1560 minv
= power_history
[0];
1562 for (i
= 1; i
< BAT_LAST_VAL
&& power_history
[i
]; i
++) {
1563 if (power_history
[i
] > maxv
)
1564 maxv
= power_history
[i
];
1565 if (power_history
[i
] < minv
)
1566 minv
= power_history
[i
];
1569 snprintf(buf
, 30, "Battery %d.%03d", power_history
[0] / 1000,
1570 power_history
[0] % 1000);
1571 lcd_puts(0, 0, buf
);
1572 snprintf(buf
, 30, "scale %d.%03d-%d.%03dV",
1573 minv
/ 1000, minv
% 1000, maxv
/ 1000, maxv
% 1000);
1574 lcd_puts(0, 1, buf
);
1577 for (i
= BAT_LAST_VAL
- 1; i
>= 0; i
--) {
1578 y
= (power_history
[i
] - minv
) * BAT_YSPACE
/ (maxv
- minv
);
1579 lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
1580 lcd_vline(x
, LCD_HEIGHT
-1, 20);
1581 lcd_set_drawmode(DRMODE_SOLID
);
1582 lcd_vline(x
, LCD_HEIGHT
-1,
1583 MIN(MAX(LCD_HEIGHT
-1 - y
, 20), LCD_HEIGHT
-1));
1589 case 1: /* status: */
1590 lcd_puts(0, 0, "Power status:");
1592 battery_read_info(&y
, NULL
);
1593 snprintf(buf
, 30, "Battery: %d.%03d V", y
/ 1000, y
% 1000);
1594 lcd_puts(0, 1, buf
);
1595 #ifdef ADC_EXT_POWER
1596 y
= (adc_read(ADC_EXT_POWER
) * EXT_SCALE_FACTOR
) / 1000;
1597 snprintf(buf
, 30, "External: %d.%03d V", y
/ 1000, y
% 1000);
1598 lcd_puts(0, 2, buf
);
1601 #if CONFIG_CHARGING == CHARGING_CONTROL
1602 snprintf(buf
, 30, "Chgr: %s %s",
1603 charger_inserted() ? "present" : "absent",
1604 charger_enabled
? "on" : "off");
1605 lcd_puts(0, 3, buf
);
1606 snprintf(buf
, 30, "short delta: %d", short_delta
);
1607 lcd_puts(0, 5, buf
);
1608 snprintf(buf
, 30, "long delta: %d", long_delta
);
1609 lcd_puts(0, 6, buf
);
1610 lcd_puts(0, 7, power_message
);
1611 snprintf(buf
, 30, "USB Inserted: %s",
1612 usb_inserted() ? "yes" : "no");
1613 lcd_puts(0, 8, buf
);
1614 #if defined IRIVER_H300_SERIES
1615 snprintf(buf
, 30, "USB Charging Enabled: %s",
1616 usb_charging_enabled() ? "yes" : "no");
1617 lcd_puts(0, 9, buf
);
1619 #else /* CONFIG_CHARGING != CHARGING_CONTROL */
1620 #if defined IPOD_NANO || defined IPOD_VIDEO
1621 int usb_pwr
= (GPIOL_INPUT_VAL
& 0x10)?true:false;
1622 int ext_pwr
= (GPIOL_INPUT_VAL
& 0x08)?false:true;
1623 int dock
= (GPIOA_INPUT_VAL
& 0x10)?true:false;
1624 int charging
= (GPIOB_INPUT_VAL
& 0x01)?false:true;
1625 int headphone
= (GPIOA_INPUT_VAL
& 0x80)?true:false;
1627 snprintf(buf
, 30, "USB pwr: %s",
1628 usb_pwr
? "present" : "absent");
1629 lcd_puts(0, 3, buf
);
1630 snprintf(buf
, 30, "EXT pwr: %s",
1631 ext_pwr
? "present" : "absent");
1632 lcd_puts(0, 4, buf
);
1633 snprintf(buf
, 30, "Battery: %s",
1634 charging
? "charging" : (usb_pwr
||ext_pwr
) ? "charged" : "discharging");
1635 lcd_puts(0, 5, buf
);
1636 snprintf(buf
, 30, "Dock mode: %s",
1637 dock
? "enabled" : "disabled");
1638 lcd_puts(0, 6, buf
);
1639 snprintf(buf
, 30, "Headphone: %s",
1640 headphone
? "connected" : "disconnected");
1641 lcd_puts(0, 7, buf
);
1643 snprintf(buf
, 30, "Charger: %s",
1644 charger_inserted() ? "present" : "absent");
1645 lcd_puts(0, 3, buf
);
1646 #if defined TOSHIBA_GIGABEAT_S
1647 y
= battery_adc_charge_current();
1648 x
= y
< 0 ? '-' : ' ';
1650 snprintf(buf
, 30, "I Charge:%c%d.%03d A", (char)x
, y
/ 1000, y
% 1000);
1651 lcd_puts(0, 4, buf
);
1653 y
= battery_adc_temp();
1654 snprintf(buf
, 30, "T Battery: %dC (%dF)", y
, (9*y
+ 160) / 5);
1655 lcd_puts(0, 5, buf
);
1656 #endif /* defined TOSHIBA_GIGABEAT_S */
1657 #endif /* defined IPOD_NANO || defined IPOD_VIDEO */
1658 #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1659 #endif /* CONFIG_CHARGING */
1662 case 2: /* voltage deltas: */
1663 lcd_puts(0, 0, "Voltage deltas:");
1665 for (i
= 0; i
<= 6; i
++) {
1666 y
= power_history
[i
] - power_history
[i
+1];
1667 snprintf(buf
, 30, "-%d min: %s%d.%03d V", i
,
1668 (y
< 0) ? "-" : "", ((y
< 0) ? y
* -1 : y
) / 1000,
1669 ((y
< 0) ? y
* -1 : y
) % 1000);
1670 lcd_puts(0, i
+1, buf
);
1674 case 3: /* remaining time estimation: */
1676 #if CONFIG_CHARGING == CHARGING_CONTROL
1677 snprintf(buf
, 30, "charge_state: %d", charge_state
);
1678 lcd_puts(0, 0, buf
);
1680 snprintf(buf
, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min
);
1681 lcd_puts(0, 1, buf
);
1683 snprintf(buf
, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level
);
1684 lcd_puts(0, 2, buf
);
1686 snprintf(buf
, 30, "P=%2d I=%2d", pid_p
, pid_i
);
1687 lcd_puts(0, 3, buf
);
1689 snprintf(buf
, 30, "Trickle sec: %d/60", trickle_sec
);
1690 lcd_puts(0, 4, buf
);
1691 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
1693 snprintf(buf
, 30, "Last PwrHist: %d.%03dV",
1694 power_history
[0] / 1000,
1695 power_history
[0] % 1000);
1696 lcd_puts(0, 5, buf
);
1698 snprintf(buf
, 30, "battery level: %d%%", battery_level());
1699 lcd_puts(0, 6, buf
);
1701 snprintf(buf
, 30, "Est. remain: %d m", battery_time());
1702 lcd_puts(0, 7, buf
);
1708 switch(get_action(CONTEXT_STD
,HZ
/2))
1710 case ACTION_STD_PREV
:
1715 case ACTION_STD_NEXT
:
1720 case ACTION_STD_CANCEL
:
1727 #endif /* HAVE_LCD_BITMAP */
1731 #if defined(HAVE_MMC) || defined(HAVE_ATA_SD)
1732 #if defined(HAVE_MMC)
1733 #define CARDTYPE "MMC"
1735 #define CARDTYPE "microSD"
1737 static int disk_callback(int btn
, struct gui_synclist
*lists
)
1740 int *cardnum
= (int*)lists
->data
;
1741 unsigned char card_name
[7];
1742 unsigned char pbuf
[32];
1743 char *title
= lists
->title
;
1744 static const unsigned char i_vmin
[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1745 static const unsigned char i_vmax
[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1746 static const unsigned char *kbit_units
[] = { "kBit/s", "MBit/s", "GBit/s" };
1747 static const unsigned char *nsec_units
[] = { "ns", "µs", "ms" };
1748 static const char *spec_vers
[] = { "1.0-1.2", "1.4", "2.0-2.2",
1749 "3.1-3.31", "4.0" };
1750 if ((btn
== ACTION_STD_OK
) || (btn
== SYS_FS_CHANGED
) || (btn
== ACTION_REDRAW
))
1753 if (btn
== ACTION_STD_OK
)
1755 *cardnum
^= 0x1; /* change cards */
1759 simplelist_set_line_count(0);
1761 card
= card_get_info(*cardnum
);
1763 if (card
->initialized
> 0)
1765 card_name
[6] = '\0';
1766 strncpy(card_name
, ((unsigned char*)card
->cid
) + 3, 6);
1767 simplelist_addline(SIMPLELIST_ADD_LINE
,
1768 "%s Rev %d.%d", card_name
,
1769 (int) card_extract_bits(card
->cid
, 72, 4),
1770 (int) card_extract_bits(card
->cid
, 76, 4));
1771 simplelist_addline(SIMPLELIST_ADD_LINE
,
1773 (int) card_extract_bits(card
->cid
, 112, 4),
1774 (int) card_extract_bits(card
->cid
, 116, 4) + 1997);
1775 simplelist_addline(SIMPLELIST_ADD_LINE
,
1777 card_extract_bits(card
->cid
, 80, 32));
1778 simplelist_addline(SIMPLELIST_ADD_LINE
,
1780 (int) card_extract_bits(card
->cid
, 0, 8),
1781 (int) card_extract_bits(card
->cid
, 8, 16));
1782 int temp
= card_extract_bits(card
->csd
, 2, 4);
1783 simplelist_addline(SIMPLELIST_ADD_LINE
,
1784 CARDTYPE
" v%s", temp
< 5 ?
1785 spec_vers
[temp
] : "?.?");
1786 simplelist_addline(SIMPLELIST_ADD_LINE
,
1787 "Blocks: 0x%06lx", card
->numblocks
);
1788 simplelist_addline(SIMPLELIST_ADD_LINE
,
1789 "Blksz.: %d P:%c%c", card
->blocksize
,
1790 card_extract_bits(card
->csd
, 48, 1) ? 'R' : '-',
1791 card_extract_bits(card
->csd
, 106, 1) ? 'W' : '-');
1792 output_dyn_value(pbuf
, sizeof pbuf
, card
->speed
/ 1000,
1794 simplelist_addline(SIMPLELIST_ADD_LINE
,
1796 output_dyn_value(pbuf
, sizeof pbuf
, card
->tsac
,
1798 simplelist_addline(SIMPLELIST_ADD_LINE
,
1800 simplelist_addline(SIMPLELIST_ADD_LINE
,
1801 "Nsac: %d clk", card
->nsac
);
1802 simplelist_addline(SIMPLELIST_ADD_LINE
,
1803 "R2W: *%d", card
->r2w_factor
);
1804 simplelist_addline(SIMPLELIST_ADD_LINE
,
1806 i_vmin
[card_extract_bits(card
->csd
, 66, 3)],
1807 i_vmax
[card_extract_bits(card
->csd
, 69, 3)]);
1808 simplelist_addline(SIMPLELIST_ADD_LINE
,
1810 i_vmin
[card_extract_bits(card
->csd
, 72, 3)],
1811 i_vmax
[card_extract_bits(card
->csd
, 75, 3)]);
1813 else if (card
->initialized
== 0)
1815 simplelist_addline(SIMPLELIST_ADD_LINE
, "Not Found!");
1818 else /* card->initialized < 0 */
1820 simplelist_addline(SIMPLELIST_ADD_LINE
, "Init Error! (%d)", card
->initialized
);
1823 snprintf(title
, 16, "[" CARDTYPE
" %d]", *cardnum
);
1824 gui_synclist_set_title(lists
, title
, Icon_NOICON
);
1825 gui_synclist_set_nb_items(lists
, simplelist_get_line_count());
1826 gui_synclist_select_item(lists
, 0);
1827 btn
= ACTION_REDRAW
;
1831 #else /* !defined(HAVE_MMC) && !defined(HAVE_ATA_SD) */
1832 static int disk_callback(int btn
, struct gui_synclist
*lists
)
1837 unsigned short* identify_info
= ata_get_identify();
1838 bool timing_info_present
= false;
1841 simplelist_set_line_count(0);
1843 for (i
=0; i
< 20; i
++)
1844 ((unsigned short*)buf
)[i
]=htobe16(identify_info
[i
+27]);
1846 /* kill trailing space */
1847 for (i
=39; i
&& buf
[i
]==' '; i
--)
1849 simplelist_addline(SIMPLELIST_ADD_LINE
, "Model: %s", buf
);
1850 for (i
=0; i
< 4; i
++)
1851 ((unsigned short*)buf
)[i
]=htobe16(identify_info
[i
+23]);
1853 simplelist_addline(SIMPLELIST_ADD_LINE
,
1854 "Firmware: %s", buf
);
1855 snprintf(buf
, sizeof buf
, "%ld MB",
1856 ((unsigned long)identify_info
[61] << 16 |
1857 (unsigned long)identify_info
[60]) / 2048 );
1858 simplelist_addline(SIMPLELIST_ADD_LINE
,
1861 fat_size( IF_MV2(0,) NULL
, &free
);
1862 simplelist_addline(SIMPLELIST_ADD_LINE
,
1863 "Free: %ld MB", free
/ 1024);
1864 simplelist_addline(SIMPLELIST_ADD_LINE
,
1865 "Spinup time: %d ms", ata_spinup_time
* (1000/HZ
));
1866 i
= identify_info
[83] & (1<<3);
1867 simplelist_addline(SIMPLELIST_ADD_LINE
,
1868 "Power mgmt: %s", i
? "enabled" : "unsupported");
1869 i
= identify_info
[83] & (1<<9);
1870 simplelist_addline(SIMPLELIST_ADD_LINE
,
1871 "Noise mgmt: %s", i
? "enabled" : "unsupported");
1872 i
= identify_info
[82] & (1<<6);
1873 simplelist_addline(SIMPLELIST_ADD_LINE
,
1874 "Read-ahead: %s", i
? "enabled" : "unsupported");
1875 timing_info_present
= identify_info
[53] & (1<<1);
1876 if(timing_info_present
) {
1877 char pio3
[2], pio4
[2];pio3
[1] = 0;
1879 pio3
[0] = (identify_info
[64] & (1<<0)) ? '3' : 0;
1880 pio4
[0] = (identify_info
[64] & (1<<1)) ? '4' : 0;
1881 simplelist_addline(SIMPLELIST_ADD_LINE
,
1882 "PIO modes: 0 1 2 %s %s", pio3
, pio4
);
1885 simplelist_addline(SIMPLELIST_ADD_LINE
,
1886 "No PIO mode info");
1888 timing_info_present
= identify_info
[53] & (1<<1);
1889 if(timing_info_present
) {
1890 simplelist_addline(SIMPLELIST_ADD_LINE
,
1891 "Cycle times %dns/%dns",
1893 identify_info
[68] );
1895 simplelist_addline(SIMPLELIST_ADD_LINE
,
1898 #if defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S)
1899 if (identify_info
[63] & (1<<0)) {
1900 char mdma0
[2], mdma1
[2], mdma2
[2];
1901 mdma0
[1] = mdma1
[1] = mdma2
[1] = 0;
1902 mdma0
[0] = (identify_info
[63] & (1<<0)) ? '0' : 0;
1903 mdma1
[0] = (identify_info
[63] & (1<<1)) ? '1' : 0;
1904 mdma2
[0] = (identify_info
[63] & (1<<2)) ? '2' : 0;
1905 simplelist_addline(SIMPLELIST_ADD_LINE
,
1906 "MDMA modes: %s %s %s", mdma0
, mdma1
, mdma2
);
1907 simplelist_addline(SIMPLELIST_ADD_LINE
,
1908 "MDMA Cycle times %dns/%dns",
1910 identify_info
[66] );
1913 simplelist_addline(SIMPLELIST_ADD_LINE
,
1914 "No MDMA mode info");
1916 if (identify_info
[88] & (1<<0)) {
1917 char udma0
[2], udma1
[2], udma2
[2], udma3
[2], udma4
[2], udma5
[2];
1918 udma0
[1] = udma1
[1] = udma2
[1] = udma3
[1] = udma4
[1] = udma5
[1] = 0;
1919 udma0
[0] = (identify_info
[88] & (1<<0)) ? '0' : 0;
1920 udma1
[0] = (identify_info
[88] & (1<<1)) ? '1' : 0;
1921 udma2
[0] = (identify_info
[88] & (1<<2)) ? '2' : 0;
1922 udma3
[0] = (identify_info
[88] & (1<<3)) ? '3' : 0;
1923 udma4
[0] = (identify_info
[88] & (1<<4)) ? '4' : 0;
1924 udma5
[0] = (identify_info
[88] & (1<<5)) ? '5' : 0;
1925 simplelist_addline(SIMPLELIST_ADD_LINE
,
1926 "UDMA modes: %s %s %s %s %s %s", udma0
, udma1
, udma2
,
1927 udma3
, udma4
, udma5
);
1930 simplelist_addline(SIMPLELIST_ADD_LINE
,
1931 "No UDMA mode info");
1933 #endif /* defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S) */
1934 timing_info_present
= identify_info
[53] & (1<<1);
1935 if(timing_info_present
) {
1936 i
= identify_info
[49] & (1<<11);
1937 simplelist_addline(SIMPLELIST_ADD_LINE
,
1938 "IORDY support: %s", i
? "yes" : "no");
1939 i
= identify_info
[49] & (1<<10);
1940 simplelist_addline(SIMPLELIST_ADD_LINE
,
1941 "IORDY disable: %s", i
? "yes" : "no");
1943 simplelist_addline(SIMPLELIST_ADD_LINE
,
1946 simplelist_addline(SIMPLELIST_ADD_LINE
,
1947 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1951 static bool dbg_identify_info(void)
1953 int fd
= creat("/identify_info.bin");
1956 #ifdef ROCKBOX_LITTLE_ENDIAN
1957 ecwrite(fd
, ata_get_identify(), SECTOR_SIZE
/2, "s", true);
1959 write(fd
, ata_get_identify(), SECTOR_SIZE
);
1965 #endif /* !defined(HAVE_MMC) && !defined(HAVE_ATA_SD) */
1967 static bool dbg_disk_info(void)
1969 struct simplelist_info info
;
1970 simplelist_info_init(&info
, "Disk Info", 1, NULL
);
1971 #if defined(HAVE_MMC) || defined(HAVE_ATA_SD)
1974 info
.callback_data
= (void*)&card
;
1977 info
.action_callback
= disk_callback
;
1978 info
.hide_selection
= true;
1979 info
.scroll_all
= true;
1980 return simplelist_show_list(&info
);
1982 #endif /* !SIMULATOR */
1984 #ifdef HAVE_DIRCACHE
1985 static int dircache_callback(int btn
, struct gui_synclist
*lists
)
1987 (void)btn
; (void)lists
;
1988 simplelist_set_line_count(0);
1989 simplelist_addline(SIMPLELIST_ADD_LINE
, "Cache initialized: %s",
1990 dircache_is_enabled() ? "Yes" : "No");
1991 simplelist_addline(SIMPLELIST_ADD_LINE
, "Cache size: %d B",
1992 dircache_get_cache_size());
1993 simplelist_addline(SIMPLELIST_ADD_LINE
, "Last size: %d B",
1994 global_status
.dircache_size
);
1995 simplelist_addline(SIMPLELIST_ADD_LINE
, "Limit: %d B",
1997 simplelist_addline(SIMPLELIST_ADD_LINE
, "Reserve: %d/%d B",
1998 dircache_get_reserve_used(), DIRCACHE_RESERVE
);
1999 simplelist_addline(SIMPLELIST_ADD_LINE
, "Scanning took: %d s",
2000 dircache_get_build_ticks() / HZ
);
2001 simplelist_addline(SIMPLELIST_ADD_LINE
, "Entry count: %d",
2002 dircache_get_entry_count());
2006 static bool dbg_dircache_info(void)
2008 struct simplelist_info info
;
2009 simplelist_info_init(&info
, "Dircache Info", 7, NULL
);
2010 info
.action_callback
= dircache_callback
;
2011 info
.hide_selection
= true;
2012 info
.scroll_all
= true;
2013 return simplelist_show_list(&info
);
2016 #endif /* HAVE_DIRCACHE */
2018 #ifdef HAVE_TAGCACHE
2019 static int database_callback(int btn
, struct gui_synclist
*lists
)
2022 struct tagcache_stat
*stat
= tagcache_get_stat();
2023 static bool synced
= false;
2025 simplelist_set_line_count(0);
2027 simplelist_addline(SIMPLELIST_ADD_LINE
, "Initialized: %s",
2028 stat
->initialized
? "Yes" : "No");
2029 simplelist_addline(SIMPLELIST_ADD_LINE
, "DB Ready: %s",
2030 stat
->ready
? "Yes" : "No");
2031 simplelist_addline(SIMPLELIST_ADD_LINE
, "RAM Cache: %s",
2032 stat
->ramcache
? "Yes" : "No");
2033 simplelist_addline(SIMPLELIST_ADD_LINE
, "RAM: %d/%d B",
2034 stat
->ramcache_used
, stat
->ramcache_allocated
);
2035 simplelist_addline(SIMPLELIST_ADD_LINE
, "Progress: %d%% (%d entries)",
2036 stat
->progress
, stat
->processed_entries
);
2037 simplelist_addline(SIMPLELIST_ADD_LINE
, "Curfile: %s",
2038 stat
->curentry
? stat
->curentry
: "---");
2039 simplelist_addline(SIMPLELIST_ADD_LINE
, "Commit step: %d",
2041 simplelist_addline(SIMPLELIST_ADD_LINE
, "Commit delayed: %s",
2042 stat
->commit_delayed
? "Yes" : "No");
2044 simplelist_addline(SIMPLELIST_ADD_LINE
, "Queue length: %d",
2045 stat
->queue_length
);
2050 tagcache_screensync_event();
2053 if (!btn
&& stat
->curentry
)
2056 return ACTION_REDRAW
;
2059 if (btn
== ACTION_STD_CANCEL
)
2060 tagcache_screensync_enable(false);
2064 static bool dbg_tagcache_info(void)
2066 struct simplelist_info info
;
2067 simplelist_info_init(&info
, "Database Info", 8, NULL
);
2068 info
.action_callback
= database_callback
;
2069 info
.hide_selection
= true;
2070 info
.scroll_all
= true;
2072 /* Don't do nonblock here, must give enough processing time
2073 for tagcache thread. */
2074 /* info.timeout = TIMEOUT_NOBLOCK; */
2076 tagcache_screensync_enable(true);
2077 return simplelist_show_list(&info
);
2081 #if CONFIG_CPU == SH7034
2082 static bool dbg_save_roms(void)
2085 int oldmode
= system_memory_guard(MEMGUARD_NONE
);
2087 fd
= creat("/internal_rom_0000-FFFF.bin");
2090 write(fd
, (void *)0, 0x10000);
2094 fd
= creat("/internal_rom_2000000-203FFFF.bin");
2097 write(fd
, (void *)0x2000000, 0x40000);
2101 system_memory_guard(oldmode
);
2104 #elif defined CPU_COLDFIRE
2105 static bool dbg_save_roms(void)
2108 int oldmode
= system_memory_guard(MEMGUARD_NONE
);
2110 #if defined(IRIVER_H100_SERIES)
2111 fd
= creat("/internal_rom_000000-1FFFFF.bin");
2112 #elif defined(IRIVER_H300_SERIES)
2113 fd
= creat("/internal_rom_000000-3FFFFF.bin");
2114 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2115 fd
= creat("/internal_rom_000000-3FFFFF.bin");
2119 write(fd
, (void *)0, FLASH_SIZE
);
2122 system_memory_guard(oldmode
);
2125 fd
= creat("/internal_eeprom.bin");
2129 char buf
[EEPROM_SIZE
];
2132 old_irq_level
= disable_irq_save();
2134 err
= eeprom_24cxx_read(0, buf
, sizeof buf
);
2136 restore_irq(old_irq_level
);
2139 gui_syncsplash(HZ
*3, "Eeprom read failure (%d)",err
);
2142 write(fd
, buf
, sizeof buf
);
2151 #elif defined(CPU_PP) && !defined(HAVE_ATA_SD)
2152 static bool dbg_save_roms(void)
2156 fd
= creat("/internal_rom_000000-0FFFFF.bin");
2159 write(fd
, (void *)0x20000000, FLASH_SIZE
);
2169 static int radio_callback(int btn
, struct gui_synclist
*lists
)
2172 if (btn
== ACTION_STD_CANCEL
)
2174 simplelist_set_line_count(1);
2176 #if (CONFIG_TUNER & LV24020LP)
2177 simplelist_addline(SIMPLELIST_ADD_LINE
,
2178 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT
) );
2179 simplelist_addline(SIMPLELIST_ADD_LINE
,
2180 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT
) );
2181 simplelist_addline(SIMPLELIST_ADD_LINE
,
2182 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM
) );
2183 simplelist_addline(SIMPLELIST_ADD_LINE
,
2184 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF
) );
2185 simplelist_addline(SIMPLELIST_ADD_LINE
,
2186 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD
) );
2187 simplelist_addline(SIMPLELIST_ADD_LINE
,
2188 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET
) );
2189 simplelist_addline(SIMPLELIST_ADD_LINE
,
2190 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET
) );
2192 #if (CONFIG_TUNER & S1A0903X01)
2193 simplelist_addline(SIMPLELIST_ADD_LINE
,
2194 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL
));
2195 /* This one doesn't return dynamic data atm */
2197 #if (CONFIG_TUNER & TEA5767)
2198 struct tea5767_dbg_info nfo
;
2199 tea5767_dbg_info(&nfo
);
2200 simplelist_addline(SIMPLELIST_ADD_LINE
, "Philips regs:");
2201 simplelist_addline(SIMPLELIST_ADD_LINE
,
2202 " Read: %02X %02X %02X %02X %02X",
2203 (unsigned)nfo
.read_regs
[0], (unsigned)nfo
.read_regs
[1],
2204 (unsigned)nfo
.read_regs
[2], (unsigned)nfo
.read_regs
[3],
2205 (unsigned)nfo
.read_regs
[4]);
2206 simplelist_addline(SIMPLELIST_ADD_LINE
,
2207 " Write: %02X %02X %02X %02X %02X",
2208 (unsigned)nfo
.write_regs
[0], (unsigned)nfo
.write_regs
[1],
2209 (unsigned)nfo
.write_regs
[2], (unsigned)nfo
.write_regs
[3],
2210 (unsigned)nfo
.write_regs
[4]);
2212 return ACTION_REDRAW
;
2214 static bool dbg_fm_radio(void)
2216 struct simplelist_info info
;
2217 info
.scroll_all
= true;
2218 simplelist_info_init(&info
, "FM Radio", 1, NULL
);
2219 simplelist_set_line_count(0);
2220 simplelist_addline(SIMPLELIST_ADD_LINE
, "HW detected: %s",
2221 radio_hardware_present() ? "yes" : "no");
2223 info
.action_callback
= radio_hardware_present()?radio_callback
: NULL
;
2224 info
.hide_selection
= true;
2225 return simplelist_show_list(&info
);
2227 #endif /* CONFIG_TUNER */
2228 #endif /* !SIMULATOR */
2230 #ifdef HAVE_LCD_BITMAP
2231 extern bool do_screendump_instead_of_usb
;
2233 static bool dbg_screendump(void)
2235 do_screendump_instead_of_usb
= !do_screendump_instead_of_usb
;
2236 gui_syncsplash(HZ
, "Screendump %s",
2237 do_screendump_instead_of_usb
?"enabled":"disabled");
2240 #endif /* HAVE_LCD_BITMAP */
2242 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2243 static bool dbg_set_memory_guard(void)
2245 static const struct opt_items names
[MAXMEMGUARD
] = {
2247 { "Flash ROM writes", -1 },
2248 { "Zero area (all)", -1 }
2250 int mode
= system_memory_guard(MEMGUARD_KEEP
);
2252 set_option( "Catch mem accesses", &mode
, INT
, names
, MAXMEMGUARD
, NULL
);
2253 system_memory_guard(mode
);
2257 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2259 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2260 static bool dbg_write_eeprom(void)
2265 char buf
[EEPROM_SIZE
];
2268 fd
= open("/internal_eeprom.bin", O_RDONLY
);
2272 rc
= read(fd
, buf
, EEPROM_SIZE
);
2274 if(rc
== EEPROM_SIZE
)
2276 old_irq_level
= disable_irq_save();
2278 err
= eeprom_24cxx_write(0, buf
, sizeof buf
);
2280 gui_syncsplash(HZ
*3, "Eeprom write failure (%d)",err
);
2282 gui_syncsplash(HZ
*3, "Eeprom written successfully");
2284 restore_irq(old_irq_level
);
2288 gui_syncsplash(HZ
*3, "File read error (%d)",rc
);
2294 gui_syncsplash(HZ
*3, "Failed to open 'internal_eeprom.bin'");
2299 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2300 #ifdef CPU_BOOST_LOGGING
2301 static bool cpu_boost_log(void)
2304 int count
= cpu_boost_log_getcount();
2305 int lines
= LCD_HEIGHT
/SYSFONT_HEIGHT
;
2308 lcd_setfont(FONT_SYSFIXED
);
2309 str
= cpu_boost_log_getlog_first();
2312 lcd_clear_display();
2313 for(j
=0; j
<lines
; j
++,i
++)
2316 str
= cpu_boost_log_getlog_next();
2327 switch(get_action(CONTEXT_STD
,TIMEOUT_BLOCK
))
2330 case ACTION_STD_PREV
:
2331 case ACTION_STD_NEXT
:
2334 case ACTION_STD_CANCEL
:
2341 get_action(CONTEXT_STD
,TIMEOUT_BLOCK
);
2342 lcd_setfont(FONT_UI
);
2347 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2348 extern bool wheel_is_touched
;
2349 extern int old_wheel_value
;
2350 extern int new_wheel_value
;
2351 extern int wheel_delta
;
2352 extern unsigned int accumulated_wheel_delta
;
2353 extern unsigned int wheel_velocity
;
2355 static bool dbg_scrollwheel(void)
2360 lcd_setfont(FONT_SYSFIXED
);
2364 if (action_userabort(HZ
/10))
2367 lcd_clear_display();
2369 /* show internal variables of scrollwheel driver */
2370 snprintf(buf
, sizeof(buf
), "wheel touched: %s", (wheel_is_touched
) ? "true" : "false");
2371 lcd_puts(0, 0, buf
);
2372 snprintf(buf
, sizeof(buf
), "new position: %2d", new_wheel_value
);
2373 lcd_puts(0, 1, buf
);
2374 snprintf(buf
, sizeof(buf
), "old position: %2d", old_wheel_value
);
2375 lcd_puts(0, 2, buf
);
2376 snprintf(buf
, sizeof(buf
), "wheel delta: %2d", wheel_delta
);
2377 lcd_puts(0, 3, buf
);
2378 snprintf(buf
, sizeof(buf
), "accumulated delta: %2d", accumulated_wheel_delta
);
2379 lcd_puts(0, 4, buf
);
2380 snprintf(buf
, sizeof(buf
), "velo [deg/s]: %4d", (int)wheel_velocity
);
2381 lcd_puts(0, 5, buf
);
2383 /* show effective accelerated scrollspeed */
2384 speed
= button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity
);
2385 snprintf(buf
, sizeof(buf
), "accel. speed: %4d", speed
);
2386 lcd_puts(0, 6, buf
);
2394 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2395 static bool logf_usb_serial(void)
2397 bool serial_enabled
= !usb_core_driver_enabled(USB_DRIVER_SERIAL
);
2398 usb_core_enable_driver(USB_DRIVER_SERIAL
,serial_enabled
);
2399 gui_syncsplash(HZ
, "USB logf %s",
2400 serial_enabled
?"enabled":"disabled");
2405 #if defined(HAVE_USBSTACK) && defined(USB_STORAGE)
2406 static bool usb_reconnect(void)
2408 gui_syncsplash(HZ
, "Reconnect mass storage");
2409 usb_storage_reconnect();
2414 #if CONFIG_USBOTG == USBOTG_ISP1583
2415 extern int dbg_usb_num_items(void);
2416 extern char* dbg_usb_item(int selected_item
, void *data
, char *buffer
, size_t buffer_len
);
2418 static int isp1583_action_callback(int action
, struct gui_synclist
*lists
)
2421 if (action
== ACTION_NONE
)
2422 action
= ACTION_REDRAW
;
2426 static bool dbg_isp1583(void)
2428 struct simplelist_info isp1583
;
2429 isp1583
.scroll_all
= true;
2430 simplelist_info_init(&isp1583
, "ISP1583", dbg_usb_num_items(), NULL
);
2431 isp1583
.timeout
= HZ
/100;
2432 isp1583
.hide_selection
= true;
2433 isp1583
.get_name
= dbg_usb_item
;
2434 isp1583
.action_callback
= isp1583_action_callback
;
2435 return simplelist_show_list(&isp1583
);
2439 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2440 extern int pic_dbg_num_items(void);
2441 extern char* pic_dbg_item(int selected_item
, void *data
, char *buffer
, size_t buffer_len
);
2443 static int pic_action_callback(int action
, struct gui_synclist
*lists
)
2446 if (action
== ACTION_NONE
)
2447 action
= ACTION_REDRAW
;
2451 static bool dbg_pic(void)
2453 struct simplelist_info pic
;
2454 pic
.scroll_all
= true;
2455 simplelist_info_init(&pic
, "PIC", pic_dbg_num_items(), NULL
);
2456 pic
.timeout
= HZ
/100;
2457 pic
.hide_selection
= true;
2458 pic
.get_name
= pic_dbg_item
;
2459 pic
.action_callback
= pic_action_callback
;
2460 return simplelist_show_list(&pic
);
2465 /****** The menu *********/
2466 struct the_menu_item
{
2467 unsigned char *desc
; /* string or ID */
2468 bool (*function
) (void); /* return true if USB was connected */
2470 static const struct the_menu_item menuitems
[] = {
2471 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2472 (defined(CPU_PP) && !defined(HAVE_ATA_SD))
2473 { "Dump ROM contents", dbg_save_roms
},
2475 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2476 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L
2477 { "View I/O ports", dbg_ports
},
2479 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2480 { "View PCF registers", dbg_pcf
},
2482 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2483 { "TSC2100 debug", tsc2100_debug
},
2485 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2486 { "CPU frequency", dbg_cpufreq
},
2488 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2489 { "S/PDIF analyzer", dbg_spdif
},
2491 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2492 { "Catch mem accesses", dbg_set_memory_guard
},
2494 { "View OS stacks", dbg_os
},
2495 #ifdef HAVE_LCD_BITMAP
2497 { "View battery", view_battery
},
2499 { "Screendump", dbg_screendump
},
2502 { "View HW info", dbg_hw_info
},
2505 { "View partitions", dbg_partitions
},
2508 { "View disk info", dbg_disk_info
},
2509 #if !defined(HAVE_MMC) && !defined(HAVE_ATA_SD)
2510 { "Dump ATA identify info", dbg_identify_info
},
2513 #ifdef HAVE_DIRCACHE
2514 { "View dircache info", dbg_dircache_info
},
2516 #ifdef HAVE_TAGCACHE
2517 { "View database info", dbg_tagcache_info
},
2519 #ifdef HAVE_LCD_BITMAP
2520 #if CONFIG_CODEC == SWCODEC
2521 { "View buffering thread", dbg_buffering_thread
},
2522 #elif !defined(SIMULATOR)
2523 { "View audio thread", dbg_audio_thread
},
2526 { "pm histogram", peak_meter_histogram
},
2527 #endif /* PM_DEBUG */
2528 #endif /* HAVE_LCD_BITMAP */
2531 { "FM Radio", dbg_fm_radio
},
2534 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2535 { "Write back EEPROM", dbg_write_eeprom
},
2537 #if CONFIG_USBOTG == USBOTG_ISP1583
2538 { "View ISP1583 info", dbg_isp1583
},
2540 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2541 { "View PIC info", dbg_pic
},
2543 #ifdef ROCKBOX_HAS_LOGF
2544 {"logf", logfdisplay
},
2545 {"logfdump", logfdump
},
2547 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2548 {"logf over usb",logf_usb_serial
},
2550 #if defined(HAVE_USBSTACK) && defined(USB_STORAGE)
2551 {"reconnect usb storage",usb_reconnect
},
2553 #ifdef CPU_BOOST_LOGGING
2554 {"cpu_boost log",cpu_boost_log
},
2556 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2557 {"Debug scrollwheel", dbg_scrollwheel
},
2560 static int menu_action_callback(int btn
, struct gui_synclist
*lists
)
2562 if (btn
== ACTION_STD_OK
)
2564 menuitems
[gui_synclist_get_sel_pos(lists
)].function();
2565 btn
= ACTION_REDRAW
;
2569 static char* dbg_menu_getname(int item
, void * data
,
2570 char *buffer
, size_t buffer_len
)
2572 (void)data
; (void)buffer
; (void)buffer_len
;
2573 return menuitems
[item
].desc
;
2575 bool debug_menu(void)
2577 struct simplelist_info info
;
2579 simplelist_info_init(&info
, "Debug Menu", ARRAYLEN(menuitems
), NULL
);
2580 info
.action_callback
= menu_action_callback
;
2581 info
.get_name
= dbg_menu_getname
;
2583 return simplelist_show_list(&info
);