1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
26 #include "debug_menu.h"
32 #include "powermgmt.h"
36 #include "mp3_playback.h"
47 #include "lcd-remote.h"
59 #include "eeprom_24cxx.h"
69 #ifdef HAVE_LCD_BITMAP
71 #include "peakmeter.h"
74 #if CONFIG_CODEC == SWCODEC
76 #include "pcm_playback.h"
80 #include "lcd-remote-target.h"
83 /*---------------------------------------------------*/
84 /* SPECIAL DEBUG STUFF */
85 /*---------------------------------------------------*/
86 extern char ata_device
;
87 extern int ata_io_address
;
88 extern struct core_entry cores
[NUM_CORES
];
90 char thread_status_char(int status
)
94 case STATE_RUNNING
: return 'R';
95 case STATE_BLOCKED
: return 'B';
96 case STATE_SLEEPING
: return 'S';
97 case STATE_BLOCKED_W_TMO
: return 'T';
103 #ifdef HAVE_LCD_BITMAP
107 struct thread_entry
*thread
;
117 lcd_setmargins(0, 0);
118 lcd_setfont(FONT_SYSFIXED
);
123 #if 0 /* Enable to simulate UI lag. */
125 for (_x
= 0; _x
< 1000000L; _x
++) ;
128 lcd_puts(0, 0, "Core and stack usage:");
130 for(core
= 0; core
< NUM_CORES
; core
++)
132 for(i
= 0; i
< MAXTHREADS
; i
++)
134 thread
= &cores
[core
].threads
[i
];
135 if (thread
->name
== NULL
)
138 usage
= thread_stack_usage(thread
);
139 status
= thread_get_status(thread
);
141 snprintf(buf
, 32, "(%d) %c%c %d %s: %d%%", core
,
142 (status
== STATE_RUNNING
) ? '*' : ' ',
143 thread_status_char(status
),
144 cores
[CURRENT_CORE
].threads
[i
].priority
,
145 cores
[core
].threads
[i
].name
, usage
);
146 lcd_puts(0, ++line
, buf
);
150 lcd_puts(0, 0, "Stack usage:");
151 for(i
= 0; i
< MAXTHREADS
; i
++)
153 thread
= &cores
[CURRENT_CORE
].threads
[i
];
154 if (thread
->name
== NULL
)
157 usage
= thread_stack_usage(thread
);
158 status
= thread_get_status(thread
);
159 # ifdef HAVE_PRIORITY_SCHEDULING
160 snprintf(buf
, 32, "%c%c %d %s: %d%%",
161 (status
== STATE_RUNNING
) ? '*' : ' ',
162 thread_status_char(status
),
163 cores
[CURRENT_CORE
].threads
[i
].priority
,
164 cores
[CURRENT_CORE
].threads
[i
].name
, usage
);
166 snprintf(buf
, 32, "%c%c %s: %d%%",
167 (status
== STATE_RUNNING
) ? '*' : ' ',
168 (status
== STATE_BLOCKED
) ? 'B' : ' ',
169 cores
[CURRENT_CORE
].threads
[i
].name
, usage
);
171 lcd_puts(0, 1+i
, buf
);
177 if (action_userabort(HZ
/10))
182 #else /* !HAVE_LCD_BITMAP */
194 lcd_puts(0, 0, "Stack usage");
196 /* Only Archos Player uses this - so assume a single core */
197 usage
= thread_stack_usage(&cores
[CPU
].threads
[currval
]);
198 snprintf(buf
, 32, "%d: %d%% ", currval
, usage
);
201 button
= get_action(CONTEXT_SETTINGS
,HZ
/10);
205 case ACTION_STD_CANCEL
:
206 action_signalscreenchange();
209 case ACTION_SETTINGS_DEC
:
212 currval
= MAXTHREADS
-1;
215 case ACTION_SETTINGS_INC
:
217 if(currval
> MAXTHREADS
-1)
224 #endif /* !HAVE_LCD_BITMAP */
225 #endif /* !SIMULATOR */
226 #ifdef HAVE_LCD_BITMAP
227 #if CONFIG_CODEC != SWCODEC
229 bool dbg_audio_thread(void)
232 struct audio_debug d
;
234 lcd_setmargins(0, 0);
235 lcd_setfont(FONT_SYSFIXED
);
239 if (action_userabort(HZ
/5))
242 audio_get_debugdata(&d
);
246 snprintf(buf
, sizeof(buf
), "read: %x", d
.audiobuf_read
);
248 snprintf(buf
, sizeof(buf
), "write: %x", d
.audiobuf_write
);
250 snprintf(buf
, sizeof(buf
), "swap: %x", d
.audiobuf_swapwrite
);
252 snprintf(buf
, sizeof(buf
), "playing: %d", d
.playing
);
254 snprintf(buf
, sizeof(buf
), "playable: %x", d
.playable_space
);
256 snprintf(buf
, sizeof(buf
), "unswapped: %x", d
.unswapped_space
);
259 /* Playable space left */
260 scrollbar(0, 6*8, 112, 4, d
.audiobuflen
, 0,
261 d
.playable_space
, HORIZONTAL
);
263 /* Show the watermark limit */
264 scrollbar(0, 6*8+4, 112, 4, d
.audiobuflen
, 0,
265 d
.low_watermark_level
, HORIZONTAL
);
267 snprintf(buf
, sizeof(buf
), "wm: %x - %x",
268 d
.low_watermark_level
, d
.lowest_watermark_level
);
275 #endif /* !SIMULATOR */
276 #else /* CONFIG_CODEC == SWCODEC */
277 extern size_t filebuflen
;
278 /* This is a size_t, but call it a long so it puts a - when it's bad. */
280 static unsigned int ticks
, boost_ticks
;
282 void dbg_audio_task(void)
285 if(FREQ
> CPUFREQ_NORMAL
)
292 bool dbg_audio_thread(void)
299 size_t bufsize
= pcmbuf_get_bufsize();
300 int pcmbufdescs
= pcmbuf_descs();
302 ticks
= boost_ticks
= 0;
304 tick_add_task(dbg_audio_task
);
306 lcd_setmargins(0, 0);
307 lcd_setfont(FONT_SYSFIXED
);
310 button
= get_action(CONTEXT_STD
,HZ
/5);
313 case ACTION_STD_NEXT
:
316 case ACTION_STD_PREV
:
319 case ACTION_STD_CANCEL
:
323 action_signalscreenchange();
328 bufused
= bufsize
- pcmbuf_free();
330 snprintf(buf
, sizeof(buf
), "pcm: %7ld/%7ld", (long) bufused
, (long) bufsize
);
331 lcd_puts(0, line
++, buf
);
333 /* Playable space left */
334 scrollbar(0, line
*8, LCD_WIDTH
, 6, bufsize
, 0, bufused
, HORIZONTAL
);
337 snprintf(buf
, sizeof(buf
), "codec: %8ld/%8ld", audio_filebufused(), (long) filebuflen
);
338 lcd_puts(0, line
++, buf
);
340 /* Playable space left */
341 scrollbar(0, line
*8, LCD_WIDTH
, 6, filebuflen
, 0,
342 audio_filebufused(), HORIZONTAL
);
345 snprintf(buf
, sizeof(buf
), "track count: %2d", audio_track_count());
346 lcd_puts(0, line
++, buf
);
349 snprintf(buf
, sizeof(buf
), "cpu freq: %3dMHz",
350 (int)((FREQ
+ 500000) / 1000000));
351 lcd_puts(0, line
++, buf
);
354 snprintf(buf
, sizeof(buf
), "boost ratio: %3d%%",
355 boost_ticks
* 100 / ticks
);
356 lcd_puts(0, line
++, buf
);
358 snprintf(buf
, sizeof(buf
), "pcmbufdesc: %2d/%2d",
359 pcmbuf_used_descs(), pcmbufdescs
);
360 lcd_puts(0, line
++, buf
);
365 tick_remove_task(dbg_audio_task
);
369 #endif /* CONFIG_CODEC */
370 #endif /* HAVE_LCD_BITMAP */
373 #if CONFIG_CPU == TCC730
374 static unsigned flash_word_temp IDATA_ATTR
;
376 static void flash_write_word(unsigned addr
, unsigned value
) ICODE_ATTR
;
377 static void flash_write_word(unsigned addr
, unsigned value
) {
378 flash_word_temp
= value
;
380 long extAddr
= (long)addr
<< 1;
381 ddma_transfer(1, 1, &flash_word_temp
, extAddr
, 2);
384 static unsigned flash_read_word(unsigned addr
) ICODE_ATTR
;
385 static unsigned flash_read_word(unsigned addr
) {
386 long extAddr
= (long)addr
<< 1;
387 ddma_transfer(1, 1, &flash_word_temp
, extAddr
, 2);
388 return flash_word_temp
;
394 /* Tool function to read the flash manufacturer and type, if available.
395 Only chips which could be reprogrammed in system will return values.
396 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
397 /* In IRAM to avoid problems when running directly from Flash */
398 bool dbg_flash_id(unsigned* p_manufacturer
, unsigned* p_device
,
399 unsigned addr1
, unsigned addr2
)
401 bool dbg_flash_id(unsigned* p_manufacturer
, unsigned* p_device
,
402 unsigned addr1
, unsigned addr2
)
405 #if (CONFIG_CPU == PP5002) || (CONFIG_CPU == PP5020)
406 /* TODO: Implement for iPod */
407 (void)p_manufacturer
;
411 #elif CONFIG_CPU == PNX0101
412 /* TODO: Implement for iFP7xx */
413 (void)p_manufacturer
;
417 #elif CONFIG_CPU == S3C2440
418 /* TODO: Implement for Gigabeat */
419 (void)p_manufacturer
;
424 unsigned not_manu
, not_id
; /* read values before switching to ID mode */
425 unsigned manu
, id
; /* read values when in ID mode */
426 #if CONFIG_CPU == TCC730
427 #define FLASH(addr) (flash_read_word(addr))
428 #define SET_FLASH(addr, val) (flash_write_word((addr), (val)))
430 #else /* memory mapped */
431 #if CONFIG_CPU == SH7034
432 volatile unsigned char* flash
= (unsigned char*)0x2000000; /* flash mapping */
433 #elif defined(CPU_COLDFIRE)
434 volatile unsigned short* flash
= (unsigned short*)0; /* flash mapping */
436 #define FLASH(addr) (flash[addr])
437 #define SET_FLASH(addr, val) (flash[addr] = val)
439 int old_level
; /* saved interrupt level */
441 not_manu
= FLASH(0); /* read the normal content */
442 not_id
= FLASH(1); /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
444 /* disable interrupts, prevent any stray flash access */
445 old_level
= set_irq_level(HIGHEST_IRQ_LEVEL
);
447 SET_FLASH(addr1
, 0xAA); /* enter command mode */
448 SET_FLASH(addr2
, 0x55);
449 SET_FLASH(addr1
, 0x90); /* ID command */
450 /* Atmel wants 20ms pause here */
451 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
453 manu
= FLASH(0); /* read the IDs */
456 SET_FLASH(0, 0xF0); /* reset flash (back to normal read mode) */
457 /* Atmel wants 20ms pause here */
458 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
460 set_irq_level(old_level
); /* enable interrupts again */
462 /* I assume success if the obtained values are different from
463 the normal flash content. This is not perfectly bulletproof, they
464 could theoretically be the same by chance, causing us to fail. */
465 if (not_manu
!= manu
|| not_id
!= id
) /* a value has changed */
467 *p_manufacturer
= manu
; /* return the results */
469 return true; /* success */
472 return false; /* fail */
474 #endif /* !SIMULATOR */
477 #ifdef HAVE_LCD_BITMAP
478 bool dbg_hw_info(void)
480 #if CONFIG_CPU == SH7034
484 int bitmask
= *(unsigned short*)0x20000fc;
485 int rom_version
= *(unsigned short*)0x20000fe;
486 unsigned manu
, id
; /* flash IDs */
487 bool got_id
; /* flag if we managed to get the flash IDs */
488 unsigned rom_crc
= 0xffffffff; /* CRC32 of the boot ROM */
489 bool has_bootrom
; /* flag for boot ROM present */
490 int oldmode
; /* saved memory guard mode */
492 #ifdef USB_ENABLE_ONDIOSTYLE
497 usb_polarity
= 0; /* Negative */
499 usb_polarity
= 1; /* Positive */
502 pr_polarity
= 0; /* Negative */
504 pr_polarity
= 1; /* Positive */
506 oldmode
= system_memory_guard(MEMGUARD_NONE
); /* disable memory guard */
508 /* get flash ROM type */
509 got_id
= dbg_flash_id(&manu
, &id
, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
511 got_id
= dbg_flash_id(&manu
, &id
, 0x555, 0x2AA); /* try AMD, Macronix */
513 /* check if the boot ROM area is a flash mirror */
514 has_bootrom
= (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
515 if (has_bootrom
) /* if ROM and Flash different */
517 /* calculate CRC16 checksum of boot ROM */
518 rom_crc
= crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
521 system_memory_guard(oldmode
); /* re-enable memory guard */
523 lcd_setmargins(0, 0);
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
);
535 snprintf(buf
, 32, "USB: %s", usb_polarity
?"positive":"negative");
538 snprintf(buf
, 32, "PR: %s", pr_polarity
?"positive":"negative");
542 snprintf(buf
, 32, "Flash: M=%02x D=%02x", manu
, id
);
544 snprintf(buf
, 32, "Flash: M=?? D=??"); /* unknown, sorry */
549 if (rom_crc
== 0x56DBA4EE) /* known Version 1 */
550 snprintf(buf
, 32, "Boot ROM: V1");
552 snprintf(buf
, 32, "ROMcrc: 0x%08x", rom_crc
);
556 snprintf(buf
, 32, "Boot ROM: none");
560 #ifndef HAVE_MMC /* have ATA */
561 snprintf(buf
, 32, "ATA: 0x%x,%s", ata_io_address
,
562 ata_device
? "slave":"master");
569 if (action_userabort(TIMEOUT_BLOCK
))
572 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
574 unsigned manu
, id
; /* flash IDs */
575 bool got_id
; /* flag if we managed to get the flash IDs */
576 int oldmode
; /* saved memory guard mode */
578 oldmode
= system_memory_guard(MEMGUARD_NONE
); /* disable memory guard */
580 /* get flash ROM type */
581 got_id
= dbg_flash_id(&manu
, &id
, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
583 got_id
= dbg_flash_id(&manu
, &id
, 0x555, 0x2AA); /* try AMD, Macronix */
585 system_memory_guard(oldmode
); /* re-enable memory guard */
587 lcd_setmargins(0, 0);
588 lcd_setfont(FONT_SYSFIXED
);
591 lcd_puts(0, 0, "[Hardware info]");
594 snprintf(buf
, 32, "Flash: M=%04x D=%04x", manu
, id
);
596 snprintf(buf
, 32, "Flash: M=???? D=????"); /* unknown, sorry */
603 if (action_userabort(TIMEOUT_BLOCK
))
606 #elif CONFIG_CPU == PP5020
609 lcd_setmargins(0, 0);
610 lcd_setfont(FONT_SYSFIXED
);
613 lcd_puts(0, 0, "[Hardware info]");
615 snprintf(buf
, sizeof(buf
), "HW rev: 0x%08x", ipod_hw_rev
);
622 if (action_userabort(TIMEOUT_BLOCK
))
625 #endif /* CONFIG_CPU */
628 #else /* !HAVE_LCD_BITMAP */
629 bool dbg_hw_info(void)
635 int bitmask
= *(unsigned short*)0x20000fc;
636 int rom_version
= *(unsigned short*)0x20000fe;
637 unsigned manu
, id
; /* flash IDs */
638 bool got_id
; /* flag if we managed to get the flash IDs */
639 unsigned rom_crc
= 0xffffffff; /* CRC32 of the boot ROM */
640 bool has_bootrom
; /* flag for boot ROM present */
641 int oldmode
; /* saved memory guard mode */
644 usb_polarity
= 0; /* Negative */
646 usb_polarity
= 1; /* Positive */
648 oldmode
= system_memory_guard(MEMGUARD_NONE
); /* disable memory guard */
650 /* get flash ROM type */
651 got_id
= dbg_flash_id(&manu
, &id
, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
653 got_id
= dbg_flash_id(&manu
, &id
, 0x555, 0x2AA); /* try AMD, Macronix */
655 /* check if the boot ROM area is a flash mirror */
656 has_bootrom
= (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
657 if (has_bootrom
) /* if ROM and Flash different */
659 /* calculate CRC16 checksum of boot ROM */
660 rom_crc
= crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
663 system_memory_guard(oldmode
); /* re-enable memory guard */
667 lcd_puts(0, 0, "[HW Info]");
673 snprintf(buf
, 32, "ROM: %d.%02d",
674 rom_version
/100, rom_version
%100);
677 snprintf(buf
, 32, "USB: %s",
678 usb_polarity
?"pos":"neg");
681 snprintf(buf
, 32, "ATA: 0x%x%s",
682 ata_io_address
, ata_device
? "s":"m");
685 snprintf(buf
, 32, "Mask: %04x", bitmask
);
689 snprintf(buf
, 32, "Flash:%02x,%02x", manu
, id
);
691 snprintf(buf
, 32, "Flash:??,??"); /* unknown, sorry */
696 if (rom_crc
== 0x56DBA4EE) /* known Version 1 */
697 snprintf(buf
, 32, "BootROM: V1");
698 else if (rom_crc
== 0x358099E8)
699 snprintf(buf
, 32, "BootROM: V2");
700 /* alternative boot ROM found in one single player so far */
702 snprintf(buf
, 32, "R: %08x", rom_crc
);
705 snprintf(buf
, 32, "BootROM: no");
711 button
= get_action(CONTEXT_SETTINGS
,TIMEOUT_BLOCK
);
715 case ACTION_STD_CANCEL
:
716 action_signalscreenchange();
719 case ACTION_SETTINGS_DEC
:
725 case ACTION_SETTINGS_INC
:
734 #endif /* !HAVE_LCD_BITMAP */
735 #endif /* !SIMULATOR */
738 bool dbg_partitions(void)
743 lcd_puts(0, 0, "Partition");
744 lcd_puts(0, 1, "list");
752 struct partinfo
* p
= disk_partinfo(partition
);
755 snprintf(buf
, sizeof buf
, "P%d: S:%lx", partition
, p
->start
);
757 snprintf(buf
, sizeof buf
, "T:%x %ld MB", p
->type
, p
->size
/ 2048);
761 button
= get_action(CONTEXT_SETTINGS
,TIMEOUT_BLOCK
);
765 case ACTION_STD_CANCEL
:
766 action_signalscreenchange();
769 case ACTION_SETTINGS_DEC
:
775 case ACTION_SETTINGS_INC
:
782 if(default_event_handler(button
) == SYS_USB_CONNECTED
)
791 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
796 unsigned int control
;
801 unsigned int interruptstat
;
802 bool valnogood
, symbolerr
, parityerr
;
805 lcd_setmargins(0, 0);
807 lcd_setfont(FONT_SYSFIXED
);
808 #ifdef HAVE_SPDIF_POWER
809 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
811 PHASECONFIG
= 0x34; /* Gain = 3*2^13, source = EBUIN */
817 control
= EBU1RCVCCHANNEL1
;
818 interruptstat
= INTERRUPTSTAT
;
819 INTERRUPTCLEAR
= 0x03c00000;
821 valnogood
= (interruptstat
& 0x01000000)?true:false;
822 symbolerr
= (interruptstat
& 0x00800000)?true:false;
823 parityerr
= (interruptstat
& 0x00400000)?true:false;
825 snprintf(buf
, sizeof(buf
), "Val: %s Sym: %s Par: %s",
828 parityerr
?"--":"OK");
829 lcd_puts(0, line
++, buf
);
831 snprintf(buf
, sizeof(buf
), "Status word: %08x", (int)control
);
832 lcd_puts(0, line
++, buf
);
837 snprintf(buf
, sizeof(buf
), "PRO: %d (%s)",
838 x
, x
?"Professional":"Consumer");
839 lcd_puts(0, line
++, buf
);
841 x
= (control
>> 30) & 1;
842 snprintf(buf
, sizeof(buf
), "Audio: %d (%s)",
843 x
, x
?"Non-PCM":"PCM");
844 lcd_puts(0, line
++, buf
);
846 x
= (control
>> 29) & 1;
847 snprintf(buf
, sizeof(buf
), "Copy: %d (%s)",
848 x
, x
?"Permitted":"Inhibited");
849 lcd_puts(0, line
++, buf
);
851 x
= (control
>> 27) & 7;
864 snprintf(buf
, sizeof(buf
), "Preemphasis: %d (%s)", x
, s
);
865 lcd_puts(0, line
++, buf
);
867 x
= (control
>> 24) & 3;
868 snprintf(buf
, sizeof(buf
), "Mode: %d", x
);
869 lcd_puts(0, line
++, buf
);
871 category
= (control
>> 17) & 127;
883 snprintf(buf
, sizeof(buf
), "Category: 0x%02x (%s)", category
, s
);
884 lcd_puts(0, line
++, buf
);
886 x
= (control
>> 16) & 1;
888 if(((category
& 0x70) == 0x10) ||
889 ((category
& 0x70) == 0x40) ||
890 ((category
& 0x78) == 0x38))
892 generation
= !generation
;
894 snprintf(buf
, sizeof(buf
), "Generation: %d (%s)",
895 x
, generation
?"Original":"No ind.");
896 lcd_puts(0, line
++, buf
);
898 x
= (control
>> 12) & 15;
899 snprintf(buf
, sizeof(buf
), "Source: %d", x
);
900 lcd_puts(0, line
++, buf
);
902 x
= (control
>> 8) & 15;
918 snprintf(buf
, sizeof(buf
), "Channel: %d (%s)", x
, s
);
919 lcd_puts(0, line
++, buf
);
921 x
= (control
>> 4) & 15;
934 snprintf(buf
, sizeof(buf
), "Frequency: %d (%s)", x
, s
);
935 lcd_puts(0, line
++, buf
);
937 x
= (control
>> 2) & 3;
938 snprintf(buf
, sizeof(buf
), "Clock accuracy: %d", x
);
939 lcd_puts(0, line
++, buf
);
943 snprintf(buf
, sizeof(buf
), "Measured freq: %ldHz",
944 (long)((long long)FREQMEAS
*CPU_FREQ
/((1 << 15)*3*(1 << 13))/128));
945 lcd_puts(0, line
++, buf
);
950 if (action_userabort(HZ
/10))
953 #ifdef HAVE_SPDIF_POWER
954 spdif_power_enable(global_settings
.spdif_enable
);
959 #endif /* CPU_COLDFIRE */
962 #ifdef HAVE_LCD_BITMAP
966 #if CONFIG_CPU == SH7034
967 unsigned short porta
;
968 unsigned short portb
;
971 int adc_battery_voltage
, adc_battery_level
;
973 lcd_setfont(FONT_SYSFIXED
);
974 lcd_setmargins(0, 0);
983 snprintf(buf
, 32, "PADR: %04x", porta
);
985 snprintf(buf
, 32, "PBDR: %04x", portb
);
988 snprintf(buf
, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
990 snprintf(buf
, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
992 snprintf(buf
, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
994 snprintf(buf
, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
997 battery_read_info(NULL
, &adc_battery_voltage
,
999 snprintf(buf
, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage
/ 100,
1000 adc_battery_voltage
% 100, adc_battery_level
);
1001 lcd_puts(0, 6, buf
);
1002 #ifndef HAVE_MMC /* have ATA */
1003 snprintf(buf
, 32, "ATA: %s, 0x%x",
1004 ata_device
?"slave":"master", ata_io_address
);
1005 lcd_puts(0, 7, buf
);
1008 if (action_userabort(HZ
/10))
1011 #elif defined(CPU_COLDFIRE)
1012 unsigned int gpio_out
;
1013 unsigned int gpio1_out
;
1014 unsigned int gpio_read
;
1015 unsigned int gpio1_read
;
1016 unsigned int gpio_function
;
1017 unsigned int gpio1_function
;
1018 unsigned int gpio_enable
;
1019 unsigned int gpio1_enable
;
1020 int adc_buttons
, adc_remote
;
1021 int adc_battery
, adc_battery_voltage
, adc_battery_level
;
1025 lcd_setmargins(0, 0);
1026 lcd_clear_display();
1027 lcd_setfont(FONT_SYSFIXED
);
1032 gpio_read
= GPIO_READ
;
1033 gpio1_read
= GPIO1_READ
;
1034 gpio_out
= GPIO_OUT
;
1035 gpio1_out
= GPIO1_OUT
;
1036 gpio_function
= GPIO_FUNCTION
;
1037 gpio1_function
= GPIO1_FUNCTION
;
1038 gpio_enable
= GPIO_ENABLE
;
1039 gpio1_enable
= GPIO1_ENABLE
;
1041 snprintf(buf
, sizeof(buf
), "GPIO_READ: %08x", gpio_read
);
1042 lcd_puts(0, line
++, buf
);
1043 snprintf(buf
, sizeof(buf
), "GPIO_OUT: %08x", gpio_out
);
1044 lcd_puts(0, line
++, buf
);
1045 snprintf(buf
, sizeof(buf
), "GPIO_FUNCTION: %08x", gpio_function
);
1046 lcd_puts(0, line
++, buf
);
1047 snprintf(buf
, sizeof(buf
), "GPIO_ENABLE: %08x", gpio_enable
);
1048 lcd_puts(0, line
++, buf
);
1050 snprintf(buf
, sizeof(buf
), "GPIO1_READ: %08x", gpio1_read
);
1051 lcd_puts(0, line
++, buf
);
1052 snprintf(buf
, sizeof(buf
), "GPIO1_OUT: %08x", gpio1_out
);
1053 lcd_puts(0, line
++, buf
);
1054 snprintf(buf
, sizeof(buf
), "GPIO1_FUNCTION: %08x", gpio1_function
);
1055 lcd_puts(0, line
++, buf
);
1056 snprintf(buf
, sizeof(buf
), "GPIO1_ENABLE: %08x", gpio1_enable
);
1057 lcd_puts(0, line
++, buf
);
1059 adc_buttons
= adc_read(ADC_BUTTONS
);
1060 adc_remote
= adc_read(ADC_REMOTE
);
1061 battery_read_info(&adc_battery
, &adc_battery_voltage
,
1062 &adc_battery_level
);
1063 #if defined(IAUDIO_X5) || defined(IRIVER_H300_SERIES)
1064 snprintf(buf
, sizeof(buf
), "ADC_BUTTONS (%c): %02x",
1065 button_scan_enabled() ? '+' : '-', adc_buttons
);
1067 snprintf(buf
, sizeof(buf
), "ADC_BUTTONS: %02x", adc_buttons
);
1069 lcd_puts(0, line
++, buf
);
1071 snprintf(buf
, sizeof(buf
), "ADC_REMOTE (%c): %02x",
1072 remote_detect() ? '+' : '-', adc_remote
);
1074 snprintf(buf
, sizeof(buf
), "ADC_REMOTE: %02x", adc_remote
);
1077 lcd_puts(0, line
++, buf
);
1078 snprintf(buf
, sizeof(buf
), "ADC_BATTERY: %02x", adc_battery
);
1079 lcd_puts(0, line
++, buf
);
1080 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1081 snprintf(buf
, sizeof(buf
), "ADC_REMOTEDETECT: %02x",
1082 adc_read(ADC_REMOTEDETECT
));
1083 lcd_puts(0, line
++, buf
);
1086 snprintf(buf
, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage
/ 100,
1087 adc_battery_voltage
% 100, adc_battery_level
);
1088 lcd_puts(0, line
++, buf
);
1090 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1091 snprintf(buf
, sizeof(buf
), "remotetype:: %d", remote_type());
1092 lcd_puts(0, line
++, buf
);
1096 if (action_userabort(HZ
/10))
1100 #elif CONFIG_CPU == PP5020
1102 unsigned int gpio_a
, gpio_b
, gpio_c
, gpio_d
;
1103 unsigned int gpio_e
, gpio_f
, gpio_g
, gpio_h
;
1104 unsigned int gpio_i
, gpio_j
, gpio_k
, gpio_l
;
1109 lcd_setmargins(0, 0);
1110 lcd_clear_display();
1111 lcd_setfont(FONT_SYSFIXED
);
1115 gpio_a
= GPIOA_INPUT_VAL
;
1116 gpio_b
= GPIOB_INPUT_VAL
;
1117 gpio_c
= GPIOC_INPUT_VAL
;
1119 gpio_g
= GPIOG_INPUT_VAL
;
1120 gpio_h
= GPIOH_INPUT_VAL
;
1121 gpio_i
= GPIOI_INPUT_VAL
;
1124 snprintf(buf
, sizeof(buf
), "GPIO_A: %02x GPIO_G: %02x", gpio_a
, gpio_g
);
1125 lcd_puts(0, line
++, buf
);
1126 snprintf(buf
, sizeof(buf
), "GPIO_B: %02x GPIO_H: %02x", gpio_b
, gpio_h
);
1127 lcd_puts(0, line
++, buf
);
1128 snprintf(buf
, sizeof(buf
), "GPIO_C: %02x GPIO_I: %02x", gpio_c
, gpio_i
);
1129 lcd_puts(0, line
++, buf
);
1132 gpio_d
= GPIOD_INPUT_VAL
;
1133 gpio_e
= GPIOE_INPUT_VAL
;
1134 gpio_f
= GPIOF_INPUT_VAL
;
1136 gpio_j
= GPIOJ_INPUT_VAL
;
1137 gpio_k
= GPIOK_INPUT_VAL
;
1138 gpio_l
= GPIOL_INPUT_VAL
;
1140 snprintf(buf
, sizeof(buf
), "GPIO_D: %02x GPIO_J: %02x", gpio_d
, gpio_j
);
1141 lcd_puts(0, line
++, buf
);
1142 snprintf(buf
, sizeof(buf
), "GPIO_E: %02x GPIO_K: %02x", gpio_e
, gpio_k
);
1143 lcd_puts(0, line
++, buf
);
1144 snprintf(buf
, sizeof(buf
), "GPIO_F: %02x GPIO_L: %02x", gpio_f
, gpio_l
);
1145 lcd_puts(0, line
++, buf
);
1146 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1148 snprintf(buf
, sizeof(buf
), "ADC_BATTERY: %02x", adc_read(ADC_BATTERY
));
1149 lcd_puts(0, line
++, buf
);
1150 snprintf(buf
, sizeof(buf
), "ADC_UNKNOWN_1: %02x", adc_read(ADC_UNKNOWN_1
));
1151 lcd_puts(0, line
++, buf
);
1152 snprintf(buf
, sizeof(buf
), "ADC_REMOTE: %02x", adc_read(ADC_REMOTE
));
1153 lcd_puts(0, line
++, buf
);
1154 snprintf(buf
, sizeof(buf
), "ADC_SCROLLPAD: %02x", adc_read(ADC_SCROLLPAD
));
1155 lcd_puts(0, line
++, buf
);
1158 if (action_userabort(HZ
/10))
1162 #elif CONFIG_CPU == PP5002
1163 unsigned int gpio_a
, gpio_b
, gpio_c
, gpio_d
;
1168 lcd_setmargins(0, 0);
1169 lcd_clear_display();
1170 lcd_setfont(FONT_SYSFIXED
);
1174 gpio_a
= GPIOA_INPUT_VAL
;
1175 gpio_b
= GPIOB_INPUT_VAL
;
1176 gpio_c
= GPIOC_INPUT_VAL
;
1177 gpio_d
= GPIOD_INPUT_VAL
;
1180 snprintf(buf
, sizeof(buf
), "GPIO_A: %02x GPIO_B: %02x", gpio_a
, gpio_b
);
1181 lcd_puts(0, line
++, buf
);
1182 snprintf(buf
, sizeof(buf
), "GPIO_C: %02x GPIO_D: %02x", gpio_c
, gpio_d
);
1183 lcd_puts(0, line
++, buf
);
1186 if (action_userabort(HZ
/10))
1192 #else /* !HAVE_LCD_BITMAP */
1193 bool dbg_ports(void)
1195 unsigned short porta
;
1196 unsigned short portb
;
1197 unsigned char portc
;
1200 int adc_battery_voltage
;
1203 lcd_clear_display();
1214 snprintf(buf
, 32, "PADR: %04x ", porta
);
1217 snprintf(buf
, 32, "PBDR: %04x ", portb
);
1220 snprintf(buf
, 32, "AN0: %03x ", adc_read(0));
1223 snprintf(buf
, 32, "AN1: %03x ", adc_read(1));
1226 snprintf(buf
, 32, "AN2: %03x ", adc_read(2));
1229 snprintf(buf
, 32, "AN3: %03x ", adc_read(3));
1232 snprintf(buf
, 32, "AN4: %03x ", adc_read(4));
1235 snprintf(buf
, 32, "AN5: %03x ", adc_read(5));
1238 snprintf(buf
, 32, "AN6: %03x ", adc_read(6));
1241 snprintf(buf
, 32, "AN7: %03x ", adc_read(7));
1244 snprintf(buf
, 32, "%s, 0x%x ",
1245 ata_device
?"slv":"mst", ata_io_address
);
1248 lcd_puts(0, 0, buf
);
1250 battery_read_info(NULL
, &adc_battery_voltage
, NULL
);
1251 snprintf(buf
, 32, "Batt: %d.%02dV", adc_battery_voltage
/ 100,
1252 adc_battery_voltage
% 100);
1253 lcd_puts(0, 1, buf
);
1255 button
= get_action(CONTEXT_SETTINGS
,HZ
/5);
1259 case ACTION_STD_CANCEL
:
1260 action_signalscreenchange();
1263 case ACTION_SETTINGS_DEC
:
1269 case ACTION_SETTINGS_INC
:
1278 #endif /* !HAVE_LCD_BITMAP */
1279 #endif /* !SIMULATOR */
1281 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1282 bool dbg_cpufreq(void)
1288 #ifdef HAVE_LCD_BITMAP
1289 lcd_setmargins(0, 0);
1290 lcd_setfont(FONT_SYSFIXED
);
1292 lcd_clear_display();
1298 snprintf(buf
, sizeof(buf
), "Frequency: %ld", FREQ
);
1299 lcd_puts(0, line
++, buf
);
1301 #ifdef CPU_BOOST_TRACKING
1302 snprintf(buf
, sizeof(buf
), "boost_counter: %d %s", get_cpu_boost_counter(), get_cpu_boost_tracker());
1304 snprintf(buf
, sizeof(buf
), "boost_counter: %d", get_cpu_boost_counter());
1306 lcd_puts(0, line
++, buf
);
1309 button
= get_action(CONTEXT_STD
,HZ
/10);
1313 case ACTION_STD_PREV
:
1314 cpu_boost_id(true, CPUBOOSTID_DEBUGMENU_MANUAL
);
1317 case ACTION_STD_NEXT
:
1318 cpu_boost_id(false, CPUBOOSTID_DEBUGMENU_MANUAL
);
1322 while (get_cpu_boost_counter() > 0)
1323 cpu_boost_id(false, CPUBOOSTID_DEBUGMENU_MANUAL
);
1326 case ACTION_STD_CANCEL
:
1327 action_signalscreenchange();
1334 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1337 #ifdef HAVE_LCD_BITMAP
1339 * view_battery() shows a automatically scaled graph of the battery voltage
1340 * over time. Usable for estimating battery life / charging rate.
1341 * The power_history array is updated in power_thread of powermgmt.c.
1344 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1345 #define BAT_YSPACE (LCD_HEIGHT - 20)
1347 bool view_battery(void)
1351 unsigned short maxv
, minv
;
1354 lcd_setmargins(0, 0);
1355 lcd_setfont(FONT_SYSFIXED
);
1360 case 0: /* voltage history graph */
1361 /* Find maximum and minimum voltage for scaling */
1364 for (i
= 0; i
< BAT_LAST_VAL
; i
++) {
1365 if (power_history
[i
] > maxv
)
1366 maxv
= power_history
[i
];
1367 if (power_history
[i
] && (power_history
[i
] < minv
))
1369 minv
= power_history
[i
];
1373 if ((minv
< 1) || (minv
>= 65535))
1378 maxv
< 65535 ? maxv
++ : minv
--;
1380 lcd_clear_display();
1381 snprintf(buf
, 30, "Battery %d.%02d", power_history
[0] / 100,
1382 power_history
[0] % 100);
1383 lcd_puts(0, 0, buf
);
1384 snprintf(buf
, 30, "scale %d.%02d-%d.%02d V",
1385 minv
/ 100, minv
% 100, maxv
/ 100, maxv
% 100);
1386 lcd_puts(0, 1, buf
);
1389 for (i
= BAT_LAST_VAL
- 1; i
>= 0; i
--) {
1390 y
= (power_history
[i
] - minv
) * BAT_YSPACE
/ (maxv
- minv
);
1391 lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
1392 lcd_vline(x
, LCD_HEIGHT
-1, 20);
1393 lcd_set_drawmode(DRMODE_SOLID
);
1394 lcd_vline(x
, LCD_HEIGHT
-1,
1395 MIN(MAX(LCD_HEIGHT
-1 - y
, 20), LCD_HEIGHT
-1));
1401 case 1: /* status: */
1402 lcd_clear_display();
1403 lcd_puts(0, 0, "Power status:");
1405 battery_read_info(NULL
, &y
, NULL
);
1406 snprintf(buf
, 30, "Battery: %d.%02d V", y
/ 100, y
% 100);
1407 lcd_puts(0, 1, buf
);
1408 #ifdef ADC_EXT_POWER
1409 y
= (adc_read(ADC_EXT_POWER
) * EXT_SCALE_FACTOR
) / 10000;
1410 snprintf(buf
, 30, "External: %d.%02d V", y
/ 100, y
% 100);
1411 lcd_puts(0, 2, buf
);
1413 #ifdef CONFIG_CHARGING
1414 #if CONFIG_CHARGING == CHARGING_CONTROL
1415 snprintf(buf
, 30, "Chgr: %s %s",
1416 charger_inserted() ? "present" : "absent",
1417 charger_enabled
? "on" : "off");
1418 lcd_puts(0, 3, buf
);
1419 snprintf(buf
, 30, "short delta: %d", short_delta
);
1420 lcd_puts(0, 5, buf
);
1421 snprintf(buf
, 30, "long delta: %d", long_delta
);
1422 lcd_puts(0, 6, buf
);
1423 lcd_puts(0, 7, power_message
);
1424 #else /* CONFIG_CHARGING != CHARGING_CONTROL */
1425 #if defined IPOD_NANO || defined IPOD_VIDEO
1426 int usb_pwr
= (GPIOL_INPUT_VAL
& 0x10)?true:false;
1427 int ext_pwr
= (GPIOL_INPUT_VAL
& 0x08)?false:true;
1428 int dock
= (GPIOA_INPUT_VAL
& 0x10)?true:false;
1429 int charging
= (GPIOB_INPUT_VAL
& 0x01)?false:true;
1430 int headphone
= (GPIOA_INPUT_VAL
& 0x80)?true:false;
1432 snprintf(buf
, 30, "USB pwr: %s",
1433 usb_pwr
? "present" : "absent");
1434 lcd_puts(0, 3, buf
);
1435 snprintf(buf
, 30, "EXT pwr: %s",
1436 ext_pwr
? "present" : "absent");
1437 lcd_puts(0, 4, buf
);
1438 snprintf(buf
, 30, "Battery: %s",
1439 charging
? "charging" : (usb_pwr
||ext_pwr
) ? "charged" : "discharging");
1440 lcd_puts(0, 5, buf
);
1441 snprintf(buf
, 30, "Dock mode: %s",
1442 dock
? "enabled" : "disabled");
1443 lcd_puts(0, 6, buf
);
1444 snprintf(buf
, 30, "Headphone: %s",
1445 headphone
? "connected" : "disconnected");
1446 lcd_puts(0, 7, buf
);
1448 snprintf(buf
, 30, "Charger: %s",
1449 charger_inserted() ? "present" : "absent");
1450 lcd_puts(0, 3, buf
);
1452 #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1453 #endif /* CONFIG_CHARGING */
1456 case 2: /* voltage deltas: */
1457 lcd_clear_display();
1458 lcd_puts(0, 0, "Voltage deltas:");
1460 for (i
= 0; i
<= 6; i
++) {
1461 y
= power_history
[i
] - power_history
[i
+i
];
1462 snprintf(buf
, 30, "-%d min: %s%d.%02d V", i
,
1463 (y
< 0) ? "-" : "", ((y
< 0) ? y
* -1 : y
) / 100,
1464 ((y
< 0) ? y
* -1 : y
) % 100);
1465 lcd_puts(0, i
+1, buf
);
1469 case 3: /* remaining time estimation: */
1470 lcd_clear_display();
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
);
1504 switch(get_action(CONTEXT_SETTINGS
,HZ
/2))
1506 case ACTION_SETTINGS_DEC
:
1511 case ACTION_SETTINGS_INC
:
1516 case ACTION_STD_CANCEL
:
1517 action_signalscreenchange();
1524 #endif /* HAVE_LCD_BITMAP */
1527 static bool view_runtime(void)
1538 lcd_clear_display();
1539 #ifdef HAVE_LCD_BITMAP
1540 lcd_puts(0, y
++, "Running time:");
1545 #ifdef CONFIG_CHARGING
1546 if (charger_inserted()
1547 #ifdef HAVE_USB_POWER
1552 global_settings
.runtime
= 0;
1557 global_settings
.runtime
+= ((current_tick
- lasttime
) / HZ
);
1559 lasttime
= current_tick
;
1561 t
= global_settings
.runtime
;
1562 lcd_puts(0, y
++, "Current time");
1565 t
= global_settings
.topruntime
;
1566 lcd_puts(0, y
++, "Top time");
1569 snprintf(s
, sizeof(s
), "%dh %dm %ds",
1570 t
/ 3600, (t
% 3600) / 60, t
% 60);
1571 lcd_puts(0, y
++, s
);
1574 /* Wait for a key to be pushed */
1575 key
= get_action(CONTEXT_SETTINGS
,HZ
);
1577 case ACTION_STD_CANCEL
:
1581 case ACTION_SETTINGS_INC
:
1582 case ACTION_SETTINGS_DEC
:
1590 lcd_clear_display();
1591 /*NOTE: this needs to be changed to sync splash! */
1592 lcd_puts(0,0,"Clear time?");
1593 lcd_puts(0,1,"PLAY = Yes");
1596 key
= get_action(CONTEXT_STD
,TIMEOUT_BLOCK
);
1597 if ( key
== ACTION_STD_OK
) {
1599 global_settings
.runtime
= 0;
1601 global_settings
.topruntime
= 0;
1608 action_signalscreenchange();
1614 bool dbg_mmc_info(void)
1620 unsigned char pbuf
[32], pbuf2
[32];
1621 unsigned char card_name
[7];
1623 static const unsigned char i_vmin
[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1624 static const unsigned char i_vmax
[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1625 static const unsigned char *kbit_units
[] = { "kBit/s", "MBit/s", "GBit/s" };
1626 static const unsigned char *nsec_units
[] = { "ns", "µs", "ms" };
1627 static const char *spec_vers
[] = { "1.0-1.2", "1.4", "2.0-2.2",
1628 "3.1-3.31", "4.0" };
1630 card_name
[6] = '\0';
1632 lcd_setmargins(0, 0);
1633 lcd_setfont(FONT_SYSFIXED
);
1637 card
= mmc_card_info(currval
/ 2);
1640 lcd_clear_display();
1641 snprintf(pbuf
, sizeof(pbuf
), "[MMC%d p%d]", currval
/ 2,
1643 lcd_puts(0, line
++, pbuf
);
1645 if (card
->initialized
)
1647 if (!(currval
% 2)) /* General info */
1651 strncpy(card_name
, ((unsigned char*)card
->cid
) + 3, 6);
1652 snprintf(pbuf
, sizeof(pbuf
), "%s Rev %d.%d", card_name
,
1653 (int) mmc_extract_bits(card
->cid
, 72, 4),
1654 (int) mmc_extract_bits(card
->cid
, 76, 4));
1655 lcd_puts(0, line
++, pbuf
);
1656 snprintf(pbuf
, sizeof(pbuf
), "Prod: %d/%d",
1657 (int) mmc_extract_bits(card
->cid
, 112, 4),
1658 (int) mmc_extract_bits(card
->cid
, 116, 4) + 1997);
1659 lcd_puts(0, line
++, pbuf
);
1660 snprintf(pbuf
, sizeof(pbuf
), "Ser#: 0x%08lx",
1661 mmc_extract_bits(card
->cid
, 80, 32));
1662 lcd_puts(0, line
++, pbuf
);
1663 snprintf(pbuf
, sizeof(pbuf
), "M=%02x, O=%04x",
1664 (int) mmc_extract_bits(card
->cid
, 0, 8),
1665 (int) mmc_extract_bits(card
->cid
, 8, 16));
1666 lcd_puts(0, line
++, pbuf
);
1667 temp
= mmc_extract_bits(card
->csd
, 2, 4);
1668 snprintf(pbuf
, sizeof(pbuf
), "MMC v%s", temp
< 5 ?
1669 spec_vers
[temp
] : "?.?");
1670 lcd_puts(0, line
++, pbuf
);
1671 snprintf(pbuf
, sizeof(pbuf
), "Blocks: 0x%06lx", card
->numblocks
);
1672 lcd_puts(0, line
++, pbuf
);
1673 snprintf(pbuf
, sizeof(pbuf
), "Blksz.: %d P:%c%c", card
->blocksize
,
1674 mmc_extract_bits(card
->csd
, 48, 1) ? 'R' : '-',
1675 mmc_extract_bits(card
->csd
, 106, 1) ? 'W' : '-');
1676 lcd_puts(0, line
++, pbuf
);
1678 else /* Technical details */
1680 output_dyn_value(pbuf2
, sizeof pbuf2
, card
->speed
/ 1000,
1682 snprintf(pbuf
, sizeof pbuf
, "Speed: %s", pbuf2
);
1683 lcd_puts(0, line
++, pbuf
);
1685 output_dyn_value(pbuf2
, sizeof pbuf2
, card
->tsac
,
1687 snprintf(pbuf
, sizeof pbuf
, "Tsac: %s", pbuf2
);
1688 lcd_puts(0, line
++, pbuf
);
1690 snprintf(pbuf
, sizeof(pbuf
), "Nsac: %d clk", card
->nsac
);
1691 lcd_puts(0, line
++, pbuf
);
1692 snprintf(pbuf
, sizeof(pbuf
), "R2W: *%d", card
->r2w_factor
);
1693 lcd_puts(0, line
++, pbuf
);
1694 snprintf(pbuf
, sizeof(pbuf
), "IRmax: %d..%d mA",
1695 i_vmin
[mmc_extract_bits(card
->csd
, 66, 3)],
1696 i_vmax
[mmc_extract_bits(card
->csd
, 69, 3)]);
1697 lcd_puts(0, line
++, pbuf
);
1698 snprintf(pbuf
, sizeof(pbuf
), "IWmax: %d..%d mA",
1699 i_vmin
[mmc_extract_bits(card
->csd
, 72, 3)],
1700 i_vmax
[mmc_extract_bits(card
->csd
, 75, 3)]);
1701 lcd_puts(0, line
++, pbuf
);
1705 lcd_puts(0, line
++, "Not found!");
1709 switch (get_action(CONTEXT_SETTINGS
,HZ
/2))
1711 case ACTION_STD_CANCEL
:
1715 case ACTION_SETTINGS_DEC
:
1721 case ACTION_SETTINGS_INC
:
1728 action_signalscreenchange();
1731 #else /* !HAVE_MMC */
1732 static bool dbg_disk_info(void)
1738 const int max_page
= 11;
1739 unsigned short* identify_info
= ata_get_identify();
1740 bool timing_info_present
= false;
1741 char pio3
[2], pio4
[2];
1743 #ifdef HAVE_LCD_BITMAP
1744 lcd_setmargins(0, 0);
1751 lcd_clear_display();
1752 #ifdef HAVE_LCD_BITMAP
1753 lcd_puts(0, y
++, "Disk info:");
1759 for (i
=0; i
< 20; i
++)
1760 ((unsigned short*)buf
)[i
]=htobe16(identify_info
[i
+27]);
1762 /* kill trailing space */
1763 for (i
=39; i
&& buf
[i
]==' '; i
--)
1765 lcd_puts(0, y
++, "Model");
1766 lcd_puts_scroll(0, y
++, buf
);
1770 for (i
=0; i
< 4; i
++)
1771 ((unsigned short*)buf
)[i
]=htobe16(identify_info
[i
+23]);
1773 lcd_puts(0, y
++, "Firmware");
1774 lcd_puts(0, y
++, buf
);
1778 snprintf(buf
, sizeof buf
, "%ld MB",
1779 ((unsigned long)identify_info
[61] << 16 |
1780 (unsigned long)identify_info
[60]) / 2048 );
1781 lcd_puts(0, y
++, "Size");
1782 lcd_puts(0, y
++, buf
);
1787 fat_size( IF_MV2(0,) NULL
, &free
);
1788 snprintf(buf
, sizeof buf
, "%ld MB", free
/ 1024 );
1789 lcd_puts(0, y
++, "Free");
1790 lcd_puts(0, y
++, buf
);
1795 snprintf(buf
, sizeof buf
, "%d ms", ata_spinup_time
* (1000/HZ
));
1796 lcd_puts(0, y
++, "Spinup time");
1797 lcd_puts(0, y
++, buf
);
1801 i
= identify_info
[83] & (1<<3);
1802 lcd_puts(0, y
++, "Power mgmt:");
1803 lcd_puts(0, y
++, i
? "enabled" : "unsupported");
1807 i
= identify_info
[83] & (1<<9);
1808 lcd_puts(0, y
++, "Noise mgmt:");
1809 lcd_puts(0, y
++, i
? "enabled" : "unsupported");
1813 i
= identify_info
[82] & (1<<6);
1814 lcd_puts(0, y
++, "Read-ahead:");
1815 lcd_puts(0, y
++, i
? "enabled" : "unsupported");
1819 timing_info_present
= identify_info
[53] & (1<<1);
1820 if(timing_info_present
) {
1823 lcd_puts(0, y
++, "PIO modes:");
1824 pio3
[0] = (identify_info
[64] & (1<<0)) ? '3' : 0;
1825 pio4
[0] = (identify_info
[64] & (1<<1)) ? '4' : 0;
1826 snprintf(buf
, 128, "0 1 2 %s %s", pio3
, pio4
);
1827 lcd_puts(0, y
++, buf
);
1829 lcd_puts(0, y
++, "No PIO mode info");
1834 timing_info_present
= identify_info
[53] & (1<<1);
1835 if(timing_info_present
) {
1836 lcd_puts(0, y
++, "Cycle times");
1837 snprintf(buf
, 128, "%dns/%dns",
1840 lcd_puts(0, y
++, buf
);
1842 lcd_puts(0, y
++, "No timing info");
1847 timing_info_present
= identify_info
[53] & (1<<1);
1848 if(timing_info_present
) {
1849 i
= identify_info
[49] & (1<<11);
1850 snprintf(buf
, 128, "IORDY support: %s", i
? "yes" : "no");
1851 lcd_puts(0, y
++, buf
);
1852 i
= identify_info
[49] & (1<<10);
1853 snprintf(buf
, 128, "IORDY disable: %s", i
? "yes" : "no");
1854 lcd_puts(0, y
++, buf
);
1856 lcd_puts(0, y
++, "No timing info");
1861 lcd_puts(0, y
++, "Cluster size");
1862 snprintf(buf
, 128, "%d bytes", fat_get_cluster_size(IF_MV(0)));
1863 lcd_puts(0, y
++, buf
);
1868 /* Wait for a key to be pushed */
1869 key
= get_action(CONTEXT_SETTINGS
,HZ
/5);
1871 case ACTION_STD_CANCEL
:
1875 case ACTION_SETTINGS_DEC
:
1880 case ACTION_SETTINGS_INC
:
1881 if (++page
> max_page
)
1887 action_signalscreenchange();
1890 #endif /* !HAVE_MMC */
1891 #endif /* !SIMULATOR */
1893 #ifdef HAVE_DIRCACHE
1894 static bool dbg_dircache_info(void)
1900 lcd_setmargins(0, 0);
1901 lcd_setfont(FONT_SYSFIXED
);
1907 lcd_clear_display();
1908 snprintf(buf
, sizeof(buf
), "Cache initialized: %s",
1909 dircache_is_enabled() ? "Yes" : "No");
1910 lcd_puts(0, line
++, buf
);
1912 snprintf(buf
, sizeof(buf
), "Cache size: %d B",
1913 dircache_get_cache_size());
1914 lcd_puts(0, line
++, buf
);
1916 snprintf(buf
, sizeof(buf
), "Last size: %d B",
1917 global_settings
.dircache_size
);
1918 lcd_puts(0, line
++, buf
);
1920 snprintf(buf
, sizeof(buf
), "Limit: %d B", DIRCACHE_LIMIT
);
1921 lcd_puts(0, line
++, buf
);
1923 snprintf(buf
, sizeof(buf
), "Reserve: %d/%d B",
1924 dircache_get_reserve_used(), DIRCACHE_RESERVE
);
1925 lcd_puts(0, line
++, buf
);
1927 snprintf(buf
, sizeof(buf
), "Scanning took: %d s",
1928 dircache_get_build_ticks() / HZ
);
1929 lcd_puts(0, line
++, buf
);
1931 snprintf(buf
, sizeof(buf
), "Entry count: %d",
1932 dircache_get_entry_count());
1933 lcd_puts(0, line
++, buf
);
1937 if (action_userabort(HZ
/2))
1944 #endif /* HAVE_DIRCACHE */
1946 #ifdef HAVE_LCD_BITMAP
1947 #ifdef HAVE_TAGCACHE
1948 static bool dbg_tagcache_info(void)
1953 struct tagcache_stat
*stat
;
1955 lcd_setmargins(0, 0);
1956 lcd_setfont(FONT_SYSFIXED
);
1962 lcd_clear_display();
1963 stat
= tagcache_get_stat();
1964 snprintf(buf
, sizeof(buf
), "Initialized: %s", stat
->initialized
? "Yes" : "No");
1965 lcd_puts(0, line
++, buf
);
1966 snprintf(buf
, sizeof(buf
), "DB Ready: %s", stat
->ready
? "Yes" : "No");
1967 lcd_puts(0, line
++, buf
);
1968 snprintf(buf
, sizeof(buf
), "RAM Cache: %s", stat
->ramcache
? "Yes" : "No");
1969 lcd_puts(0, line
++, buf
);
1970 snprintf(buf
, sizeof(buf
), "RAM: %d/%d B",
1971 stat
->ramcache_used
, stat
->ramcache_allocated
);
1972 lcd_puts(0, line
++, buf
);
1973 snprintf(buf
, sizeof(buf
), "Progress: %d%% (%d entries)",
1974 stat
->progress
, stat
->processed_entries
);
1975 lcd_puts(0, line
++, buf
);
1976 snprintf(buf
, sizeof(buf
), "Commit step: %d", stat
->commit_step
);
1977 lcd_puts(0, line
++, buf
);
1978 snprintf(buf
, sizeof(buf
), "Commit delayed: %s",
1979 stat
->commit_delayed
? "Yes" : "No");
1980 lcd_puts(0, line
++, buf
);
1984 if (action_userabort(HZ
/2))
1993 #if CONFIG_CPU == SH7034
1994 bool dbg_save_roms(void)
1997 int oldmode
= system_memory_guard(MEMGUARD_NONE
);
1999 fd
= creat("/internal_rom_0000-FFFF.bin", O_WRONLY
);
2002 write(fd
, (void *)0, 0x10000);
2006 fd
= creat("/internal_rom_2000000-203FFFF.bin", O_WRONLY
);
2009 write(fd
, (void *)0x2000000, 0x40000);
2013 system_memory_guard(oldmode
);
2016 #elif defined CPU_COLDFIRE
2017 bool dbg_save_roms(void)
2020 int oldmode
= system_memory_guard(MEMGUARD_NONE
);
2022 #if defined(IRIVER_H100_SERIES)
2023 fd
= creat("/internal_rom_000000-1FFFFF.bin", O_WRONLY
);
2024 #elif defined(IRIVER_H300_SERIES)
2025 fd
= creat("/internal_rom_000000-3FFFFF.bin", O_WRONLY
);
2026 #elif defined(IAUDIO_X5)
2027 fd
= creat("/internal_rom_000000-3FFFFF.bin", O_WRONLY
);
2031 write(fd
, (void *)0, FLASH_SIZE
);
2034 system_memory_guard(oldmode
);
2037 fd
= creat("/internal_eeprom.bin", O_WRONLY
);
2041 char buf
[EEPROM_SIZE
];
2044 old_irq_level
= set_irq_level(HIGHEST_IRQ_LEVEL
);
2046 err
= eeprom_24cxx_read(0, buf
, sizeof buf
);
2048 gui_syncsplash(HZ
*3, true, "Eeprom read failure (%d)",err
);
2051 write(fd
, buf
, sizeof buf
);
2054 set_irq_level(old_irq_level
);
2066 bool dbg_fm_radio(void)
2071 #ifdef HAVE_LCD_BITMAP
2072 lcd_setmargins(0, 0);
2080 lcd_clear_display();
2081 fm_detected
= radio_hardware_present();
2083 snprintf(buf
, sizeof buf
, "HW detected: %s", fm_detected
?"yes":"no");
2084 lcd_puts(0, row
++, buf
);
2086 #if (CONFIG_TUNER & S1A0903X01)
2087 regs
= samsung_get(RADIO_ALL
);
2088 snprintf(buf
, sizeof buf
, "Samsung regs: %08lx", regs
);
2089 lcd_puts(0, row
++, buf
);
2091 #if (CONFIG_TUNER & TEA5767)
2092 regs
= philips_get(RADIO_ALL
);
2093 snprintf(buf
, sizeof buf
, "Philips regs: %08lx", regs
);
2094 lcd_puts(0, row
++, buf
);
2099 if (action_userabort(HZ
))
2104 #endif /* CONFIG_TUNER */
2105 #endif /* !SIMULATOR */
2107 #ifdef HAVE_LCD_BITMAP
2108 extern bool do_screendump_instead_of_usb
;
2110 bool dbg_screendump(void)
2112 do_screendump_instead_of_usb
= !do_screendump_instead_of_usb
;
2113 gui_syncsplash(HZ
, true, "Screendump %s",
2114 do_screendump_instead_of_usb
?"enabled":"disabled");
2117 #endif /* HAVE_LCD_BITMAP */
2119 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2120 bool dbg_set_memory_guard(void)
2122 static const struct opt_items names
[MAXMEMGUARD
] = {
2124 { "Flash ROM writes", -1 },
2125 { "Zero area (all)", -1 }
2127 int mode
= system_memory_guard(MEMGUARD_KEEP
);
2129 set_option( "Catch mem accesses", &mode
, INT
, names
, MAXMEMGUARD
, NULL
);
2130 system_memory_guard(mode
);
2134 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2136 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2137 bool dbg_write_eeprom(void)
2142 char buf
[EEPROM_SIZE
];
2145 fd
= open("/internal_eeprom.bin", O_RDONLY
);
2149 rc
= read(fd
, buf
, EEPROM_SIZE
);
2151 if(rc
== EEPROM_SIZE
)
2153 old_irq_level
= set_irq_level(HIGHEST_IRQ_LEVEL
);
2155 err
= eeprom_24cxx_write(0, buf
, sizeof buf
);
2157 gui_syncsplash(HZ
*3, true, "Eeprom write failure (%d)",err
);
2159 gui_syncsplash(HZ
*3, true, "Eeprom written successfully");
2161 set_irq_level(old_irq_level
);
2165 gui_syncsplash(HZ
*3, true, "File read error (%d)",rc
);
2171 gui_syncsplash(HZ
*3, true, "Failed to open 'internal_eeprom.bin'");
2176 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2178 bool debug_menu(void)
2183 static const struct menu_item items
[] = {
2184 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2185 { "Dump ROM contents", dbg_save_roms
},
2187 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP)
2188 { "View I/O ports", dbg_ports
},
2190 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2191 { "CPU frequency", dbg_cpufreq
},
2193 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2194 { "S/PDIF analyzer", dbg_spdif
},
2196 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2197 { "Catch mem accesses", dbg_set_memory_guard
},
2200 { "View OS stacks", dbg_os
},
2202 #ifdef HAVE_LCD_BITMAP
2204 { "View battery", view_battery
},
2206 { "Screendump", dbg_screendump
},
2209 { "View HW info", dbg_hw_info
},
2212 { "View partitions", dbg_partitions
},
2216 { "View MMC info", dbg_mmc_info
},
2218 { "View disk info", dbg_disk_info
},
2221 #ifdef HAVE_DIRCACHE
2222 { "View dircache info", dbg_dircache_info
},
2224 #ifdef HAVE_LCD_BITMAP
2225 #ifdef HAVE_TAGCACHE
2226 { "View tagcache info", dbg_tagcache_info
},
2228 #if CONFIG_CODEC == SWCODEC || !defined(SIMULATOR)
2229 { "View audio thread", dbg_audio_thread
},
2232 { "pm histogram", peak_meter_histogram
},
2233 #endif /* PM_DEBUG */
2234 #endif /* HAVE_LCD_BITMAP */
2235 { "View runtime", view_runtime
},
2238 { "FM Radio", dbg_fm_radio
},
2241 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2242 { "Write back EEPROM", dbg_write_eeprom
},
2244 #ifdef ROCKBOX_HAS_LOGF
2245 {"logf", logfdisplay
},
2246 {"logfdump", logfdump
},
2250 m
=menu_init( items
, sizeof items
/ sizeof(struct menu_item
), NULL
,
2252 result
= menu_run(m
);