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"
45 #include "lcd-remote.h"
57 #include "eeprom_24cxx.h"
67 #ifdef HAVE_LCD_BITMAP
69 #include "peakmeter.h"
72 #if CONFIG_CODEC == SWCODEC
74 #include "pcm_playback.h"
77 /*---------------------------------------------------*/
78 /* SPECIAL DEBUG STUFF */
79 /*---------------------------------------------------*/
80 extern char ata_device
;
81 extern int ata_io_address
;
82 extern struct core_entry cores
[NUM_CORES
];
84 char thread_status_char(int status
)
88 case STATE_RUNNING
: return 'R';
89 case STATE_BLOCKED
: return 'B';
90 case STATE_SLEEPING
: return 'S';
91 case STATE_BLOCKED_W_TMO
: return 'T';
97 #ifdef HAVE_LCD_BITMAP
101 struct thread_entry
*thread
;
111 lcd_setmargins(0, 0);
112 lcd_setfont(FONT_SYSFIXED
);
117 #if 0 /* Enable to simulate UI lag. */
119 for (_x
= 0; _x
< 1000000L; _x
++) ;
122 lcd_puts(0, 0, "Core and stack usage:");
124 for(core
= 0; core
< NUM_CORES
; core
++)
126 for(i
= 0; i
< MAXTHREADS
; i
++)
128 thread
= &cores
[core
].threads
[i
];
129 if (thread
->name
== NULL
)
132 usage
= thread_stack_usage(thread
);
133 status
= thread_get_status(thread
);
135 snprintf(buf
, 32, "(%d) %c%c %d %s: %d%%", core
,
136 (status
== STATE_RUNNING
) ? '*' : ' ',
137 thread_status_char(status
),
138 cores
[CURRENT_CORE
].threads
[i
].priority
,
139 cores
[core
].threads
[i
].name
, usage
);
140 lcd_puts(0, ++line
, buf
);
144 lcd_puts(0, 0, "Stack usage:");
145 for(i
= 0; i
< MAXTHREADS
; i
++)
147 thread
= &cores
[CURRENT_CORE
].threads
[i
];
148 if (thread
->name
== NULL
)
151 usage
= thread_stack_usage(thread
);
152 status
= thread_get_status(thread
);
153 # ifdef HAVE_PRIORITY_SCHEDULING
154 snprintf(buf
, 32, "%c%c %d %s: %d%%",
155 (status
== STATE_RUNNING
) ? '*' : ' ',
156 thread_status_char(status
),
157 cores
[CURRENT_CORE
].threads
[i
].priority
,
158 cores
[CURRENT_CORE
].threads
[i
].name
, usage
);
160 snprintf(buf
, 32, "%c%c %s: %d%%",
161 (status
== STATE_RUNNING
) ? '*' : ' ',
162 (status
== STATE_BLOCKED
) ? 'B' : ' ',
163 cores
[CURRENT_CORE
].threads
[i
].name
, usage
);
165 lcd_puts(0, 1+i
, buf
);
171 if (action_userabort(HZ
/10))
176 #else /* !HAVE_LCD_BITMAP */
188 lcd_puts(0, 0, "Stack usage");
190 /* Only Archos Player uses this - so assume a single core */
191 usage
= thread_stack_usage(&cores
[CPU
].threads
[currval
]);
192 snprintf(buf
, 32, "%d: %d%% ", currval
, usage
);
195 button
= get_action(CONTEXT_SETTINGS
,HZ
/10);
199 case ACTION_STD_CANCEL
:
200 action_signalscreenchange();
203 case ACTION_SETTINGS_DEC
:
206 currval
= MAXTHREADS
-1;
209 case ACTION_SETTINGS_INC
:
211 if(currval
> MAXTHREADS
-1)
218 #endif /* !HAVE_LCD_BITMAP */
219 #endif /* !SIMULATOR */
220 #ifdef HAVE_LCD_BITMAP
221 #if CONFIG_CODEC != SWCODEC
223 bool dbg_audio_thread(void)
226 struct audio_debug d
;
228 lcd_setmargins(0, 0);
229 lcd_setfont(FONT_SYSFIXED
);
233 if (action_userabort(HZ
/5))
236 audio_get_debugdata(&d
);
240 snprintf(buf
, sizeof(buf
), "read: %x", d
.audiobuf_read
);
242 snprintf(buf
, sizeof(buf
), "write: %x", d
.audiobuf_write
);
244 snprintf(buf
, sizeof(buf
), "swap: %x", d
.audiobuf_swapwrite
);
246 snprintf(buf
, sizeof(buf
), "playing: %d", d
.playing
);
248 snprintf(buf
, sizeof(buf
), "playable: %x", d
.playable_space
);
250 snprintf(buf
, sizeof(buf
), "unswapped: %x", d
.unswapped_space
);
253 /* Playable space left */
254 scrollbar(0, 6*8, 112, 4, d
.audiobuflen
, 0,
255 d
.playable_space
, HORIZONTAL
);
257 /* Show the watermark limit */
258 scrollbar(0, 6*8+4, 112, 4, d
.audiobuflen
, 0,
259 d
.low_watermark_level
, HORIZONTAL
);
261 snprintf(buf
, sizeof(buf
), "wm: %x - %x",
262 d
.low_watermark_level
, d
.lowest_watermark_level
);
269 #endif /* !SIMULATOR */
270 #else /* CONFIG_CODEC == SWCODEC */
271 extern size_t filebuflen
;
272 /* This is a size_t, but call it a long so it puts a - when it's bad. */
273 extern long filebufused
;
275 static unsigned int ticks
, boost_ticks
;
277 void dbg_audio_task(void)
280 if(FREQ
> CPUFREQ_NORMAL
)
287 bool dbg_audio_thread(void)
294 size_t bufsize
= pcmbuf_get_bufsize();
295 int pcmbufdescs
= pcmbuf_descs();
297 ticks
= boost_ticks
= 0;
299 tick_add_task(dbg_audio_task
);
301 lcd_setmargins(0, 0);
302 lcd_setfont(FONT_SYSFIXED
);
305 button
= get_action(CONTEXT_STD
,HZ
/5);
308 case ACTION_STD_NEXT
:
311 case ACTION_STD_PREV
:
314 case ACTION_STD_CANCEL
:
318 action_signalscreenchange();
323 bufused
= bufsize
- pcmbuf_free();
325 snprintf(buf
, sizeof(buf
), "pcm: %7ld/%7ld", (long) bufused
, (long) bufsize
);
326 lcd_puts(0, line
++, buf
);
328 /* Playable space left */
329 scrollbar(0, line
*8, LCD_WIDTH
, 6, bufsize
, 0, bufused
, HORIZONTAL
);
332 snprintf(buf
, sizeof(buf
), "codec: %8ld/%8ld", filebufused
, (long) filebuflen
);
333 lcd_puts(0, line
++, buf
);
335 /* Playable space left */
336 scrollbar(0, line
*8, LCD_WIDTH
, 6, filebuflen
, 0,
337 filebufused
, HORIZONTAL
);
340 snprintf(buf
, sizeof(buf
), "track count: %2d", audio_track_count());
341 lcd_puts(0, line
++, buf
);
344 snprintf(buf
, sizeof(buf
), "cpu freq: %3dMHz",
345 (int)((FREQ
+ 500000) / 1000000));
346 lcd_puts(0, line
++, buf
);
349 snprintf(buf
, sizeof(buf
), "boost ratio: %3d%%",
350 boost_ticks
* 100 / ticks
);
351 lcd_puts(0, line
++, buf
);
353 snprintf(buf
, sizeof(buf
), "pcmbufdesc: %2d/%2d",
354 pcmbuf_used_descs(), pcmbufdescs
);
355 lcd_puts(0, line
++, buf
);
360 tick_remove_task(dbg_audio_task
);
364 #endif /* CONFIG_CODEC */
365 #endif /* HAVE_LCD_BITMAP */
368 #if CONFIG_CPU == TCC730
369 static unsigned flash_word_temp
__attribute__ ((section (".idata")));
371 static void flash_write_word(unsigned addr
, unsigned value
) __attribute__ ((section(".icode")));
372 static void flash_write_word(unsigned addr
, unsigned value
) {
373 flash_word_temp
= value
;
375 long extAddr
= (long)addr
<< 1;
376 ddma_transfer(1, 1, &flash_word_temp
, extAddr
, 2);
379 static unsigned flash_read_word(unsigned addr
) __attribute__ ((section(".icode")));
380 static unsigned flash_read_word(unsigned addr
) {
381 long extAddr
= (long)addr
<< 1;
382 ddma_transfer(1, 1, &flash_word_temp
, extAddr
, 2);
383 return flash_word_temp
;
388 /* Tool function to read the flash manufacturer and type, if available.
389 Only chips which could be reprogrammed in system will return values.
390 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
391 /* In IRAM to avoid problems when running directly from Flash */
392 bool dbg_flash_id(unsigned* p_manufacturer
, unsigned* p_device
,
393 unsigned addr1
, unsigned addr2
)
394 __attribute__ ((section (".icode")));
395 bool dbg_flash_id(unsigned* p_manufacturer
, unsigned* p_device
,
396 unsigned addr1
, unsigned addr2
)
400 #if (CONFIG_CPU == PP5002) || (CONFIG_CPU == PP5020)
401 /* TODO: Implement for iPod */
402 (void)p_manufacturer
;
406 #elif CONFIG_CPU == PNX0101
407 /* TODO: Implement for iFP7xx */
408 (void)p_manufacturer
;
412 #elif CONFIG_CPU == S3C2440
413 /* TODO: Implement for Gigabeat */
414 (void)p_manufacturer
;
419 unsigned not_manu
, not_id
; /* read values before switching to ID mode */
420 unsigned manu
, id
; /* read values when in ID mode */
421 #if CONFIG_CPU == TCC730
422 #define FLASH(addr) (flash_read_word(addr))
423 #define SET_FLASH(addr, val) (flash_write_word((addr), (val)))
425 #else /* memory mapped */
426 #if CONFIG_CPU == SH7034
427 volatile unsigned char* flash
= (unsigned char*)0x2000000; /* flash mapping */
428 #elif defined(CPU_COLDFIRE)
429 volatile unsigned short* flash
= (unsigned short*)0; /* flash mapping */
431 #define FLASH(addr) (flash[addr])
432 #define SET_FLASH(addr, val) (flash[addr] = val)
434 int old_level
; /* saved interrupt level */
436 not_manu
= FLASH(0); /* read the normal content */
437 not_id
= FLASH(1); /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
439 /* disable interrupts, prevent any stray flash access */
440 old_level
= set_irq_level(HIGHEST_IRQ_LEVEL
);
442 SET_FLASH(addr1
, 0xAA); /* enter command mode */
443 SET_FLASH(addr2
, 0x55);
444 SET_FLASH(addr1
, 0x90); /* ID command */
445 /* Atmel wants 20ms pause here */
446 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
448 manu
= FLASH(0); /* read the IDs */
451 SET_FLASH(0, 0xF0); /* reset flash (back to normal read mode) */
452 /* Atmel wants 20ms pause here */
453 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
455 set_irq_level(old_level
); /* enable interrupts again */
457 /* I assume success if the obtained values are different from
458 the normal flash content. This is not perfectly bulletproof, they
459 could theoretically be the same by chance, causing us to fail. */
460 if (not_manu
!= manu
|| not_id
!= id
) /* a value has changed */
462 *p_manufacturer
= manu
; /* return the results */
464 return true; /* success */
468 (void) p_manufacturer
;
473 return false; /* fail */
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
;
972 int batt_int
, batt_frac
;
974 lcd_setfont(FONT_SYSFIXED
);
975 lcd_setmargins(0, 0);
984 snprintf(buf
, 32, "PADR: %04x", porta
);
986 snprintf(buf
, 32, "PBDR: %04x", portb
);
989 snprintf(buf
, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
991 snprintf(buf
, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
993 snprintf(buf
, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
995 snprintf(buf
, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
998 battery_voltage
= (adc_read(ADC_UNREG_POWER
) * BATTERY_SCALE_FACTOR
) / 10000;
999 batt_int
= battery_voltage
/ 100;
1000 batt_frac
= battery_voltage
% 100;
1002 snprintf(buf
, 32, "Batt: %d.%02dV %d%% ", batt_int
, batt_frac
,
1004 lcd_puts(0, 6, buf
);
1005 #ifndef HAVE_MMC /* have ATA */
1006 snprintf(buf
, 32, "ATA: %s, 0x%x",
1007 ata_device
?"slave":"master", ata_io_address
);
1008 lcd_puts(0, 7, buf
);
1011 if (action_userabort(HZ
/10))
1014 #elif defined(CPU_COLDFIRE)
1015 unsigned int gpio_out
;
1016 unsigned int gpio1_out
;
1017 unsigned int gpio_read
;
1018 unsigned int gpio1_read
;
1019 unsigned int gpio_function
;
1020 unsigned int gpio1_function
;
1021 unsigned int gpio_enable
;
1022 unsigned int gpio1_enable
;
1023 int adc_buttons
, adc_remote
, adc_battery
;
1024 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1025 int adc_remotedetect
;
1029 int battery_voltage
;
1030 int batt_int
, batt_frac
;
1032 lcd_setmargins(0, 0);
1033 lcd_clear_display();
1034 lcd_setfont(FONT_SYSFIXED
);
1039 gpio_read
= GPIO_READ
;
1040 gpio1_read
= GPIO1_READ
;
1041 gpio_out
= GPIO_OUT
;
1042 gpio1_out
= GPIO1_OUT
;
1043 gpio_function
= GPIO_FUNCTION
;
1044 gpio1_function
= GPIO1_FUNCTION
;
1045 gpio_enable
= GPIO_ENABLE
;
1046 gpio1_enable
= GPIO1_ENABLE
;
1048 snprintf(buf
, sizeof(buf
), "GPIO_READ: %08x", gpio_read
);
1049 lcd_puts(0, line
++, buf
);
1050 snprintf(buf
, sizeof(buf
), "GPIO_OUT: %08x", gpio_out
);
1051 lcd_puts(0, line
++, buf
);
1052 snprintf(buf
, sizeof(buf
), "GPIO_FUNCTION: %08x", gpio_function
);
1053 lcd_puts(0, line
++, buf
);
1054 snprintf(buf
, sizeof(buf
), "GPIO_ENABLE: %08x", gpio_enable
);
1055 lcd_puts(0, line
++, buf
);
1057 snprintf(buf
, sizeof(buf
), "GPIO1_READ: %08x", gpio1_read
);
1058 lcd_puts(0, line
++, buf
);
1059 snprintf(buf
, sizeof(buf
), "GPIO1_OUT: %08x", gpio1_out
);
1060 lcd_puts(0, line
++, buf
);
1061 snprintf(buf
, sizeof(buf
), "GPIO1_FUNCTION: %08x", gpio1_function
);
1062 lcd_puts(0, line
++, buf
);
1063 snprintf(buf
, sizeof(buf
), "GPIO1_ENABLE: %08x", gpio1_enable
);
1064 lcd_puts(0, line
++, buf
);
1066 adc_buttons
= adc_read(ADC_BUTTONS
);
1067 adc_remote
= adc_read(ADC_REMOTE
);
1068 adc_battery
= adc_read(ADC_BATTERY
);
1069 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1070 adc_remotedetect
= adc_read(ADC_REMOTEDETECT
);
1073 snprintf(buf
, sizeof(buf
), "ADC_BUTTONS: %02x", adc_buttons
);
1074 lcd_puts(0, line
++, buf
);
1075 snprintf(buf
, sizeof(buf
), "ADC_REMOTE: %02x", adc_remote
);
1076 lcd_puts(0, line
++, buf
);
1077 snprintf(buf
, sizeof(buf
), "ADC_BATTERY: %02x", adc_battery
);
1078 lcd_puts(0, line
++, buf
);
1079 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1080 snprintf(buf
, sizeof(buf
), "ADC_REMOTEDETECT: %02x", adc_remotedetect
);
1081 lcd_puts(0, line
++, buf
);
1084 battery_voltage
= (adc_battery
* BATTERY_SCALE_FACTOR
) / 10000;
1085 batt_int
= battery_voltage
/ 100;
1086 batt_frac
= battery_voltage
% 100;
1088 snprintf(buf
, 32, "Batt: %d.%02dV %d%% ", batt_int
, batt_frac
,
1090 lcd_puts(0, line
++, buf
);
1092 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1093 snprintf(buf
, sizeof(buf
), "remotetype:: %d", remote_type());
1094 lcd_puts(0, line
++, buf
);
1098 if (action_userabort(HZ
/10))
1102 #elif CONFIG_CPU == PP5020
1104 unsigned int gpio_a
, gpio_b
, gpio_c
, gpio_d
;
1105 unsigned int gpio_e
, gpio_f
, gpio_g
, gpio_h
;
1106 unsigned int gpio_i
, gpio_j
, gpio_k
, gpio_l
;
1111 lcd_setmargins(0, 0);
1112 lcd_clear_display();
1113 lcd_setfont(FONT_SYSFIXED
);
1117 gpio_a
= GPIOA_INPUT_VAL
;
1118 gpio_b
= GPIOB_INPUT_VAL
;
1119 gpio_c
= GPIOC_INPUT_VAL
;
1121 gpio_g
= GPIOG_INPUT_VAL
;
1122 gpio_h
= GPIOH_INPUT_VAL
;
1123 gpio_i
= GPIOI_INPUT_VAL
;
1126 snprintf(buf
, sizeof(buf
), "GPIO_A: %02x GPIO_G: %02x", gpio_a
, gpio_g
);
1127 lcd_puts(0, line
++, buf
);
1128 snprintf(buf
, sizeof(buf
), "GPIO_B: %02x GPIO_H: %02x", gpio_b
, gpio_h
);
1129 lcd_puts(0, line
++, buf
);
1130 snprintf(buf
, sizeof(buf
), "GPIO_C: %02x GPIO_I: %02x", gpio_c
, gpio_i
);
1131 lcd_puts(0, line
++, buf
);
1134 gpio_d
= GPIOD_INPUT_VAL
;
1135 gpio_e
= GPIOE_INPUT_VAL
;
1136 gpio_f
= GPIOF_INPUT_VAL
;
1138 gpio_j
= GPIOJ_INPUT_VAL
;
1139 gpio_k
= GPIOK_INPUT_VAL
;
1140 gpio_l
= GPIOL_INPUT_VAL
;
1142 snprintf(buf
, sizeof(buf
), "GPIO_D: %02x GPIO_J: %02x", gpio_d
, gpio_j
);
1143 lcd_puts(0, line
++, buf
);
1144 snprintf(buf
, sizeof(buf
), "GPIO_E: %02x GPIO_K: %02x", gpio_e
, gpio_k
);
1145 lcd_puts(0, line
++, buf
);
1146 snprintf(buf
, sizeof(buf
), "GPIO_F: %02x GPIO_L: %02x", gpio_f
, gpio_l
);
1147 lcd_puts(0, line
++, buf
);
1148 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1150 snprintf(buf
, sizeof(buf
), "ADC_BATTERY: %02x", adc_read(ADC_BATTERY
));
1151 lcd_puts(0, line
++, buf
);
1152 snprintf(buf
, sizeof(buf
), "ADC_UNKNOWN_1: %02x", adc_read(ADC_UNKNOWN_1
));
1153 lcd_puts(0, line
++, buf
);
1154 snprintf(buf
, sizeof(buf
), "ADC_REMOTE: %02x", adc_read(ADC_REMOTE
));
1155 lcd_puts(0, line
++, buf
);
1156 snprintf(buf
, sizeof(buf
), "ADC_SCROLLPAD: %02x", adc_read(ADC_SCROLLPAD
));
1157 lcd_puts(0, line
++, buf
);
1160 if (action_userabort(HZ
/10))
1167 #else /* !HAVE_LCD_BITMAP */
1168 bool dbg_ports(void)
1170 unsigned short porta
;
1171 unsigned short portb
;
1172 unsigned char portc
;
1175 int battery_voltage
;
1176 int batt_int
, batt_frac
;
1179 lcd_clear_display();
1190 snprintf(buf
, 32, "PADR: %04x ", porta
);
1193 snprintf(buf
, 32, "PBDR: %04x ", portb
);
1196 snprintf(buf
, 32, "AN0: %03x ", adc_read(0));
1199 snprintf(buf
, 32, "AN1: %03x ", adc_read(1));
1202 snprintf(buf
, 32, "AN2: %03x ", adc_read(2));
1205 snprintf(buf
, 32, "AN3: %03x ", adc_read(3));
1208 snprintf(buf
, 32, "AN4: %03x ", adc_read(4));
1211 snprintf(buf
, 32, "AN5: %03x ", adc_read(5));
1214 snprintf(buf
, 32, "AN6: %03x ", adc_read(6));
1217 snprintf(buf
, 32, "AN7: %03x ", adc_read(7));
1220 snprintf(buf
, 32, "%s, 0x%x ",
1221 ata_device
?"slv":"mst", ata_io_address
);
1224 lcd_puts(0, 0, buf
);
1226 battery_voltage
= (adc_read(ADC_UNREG_POWER
) *
1227 BATTERY_SCALE_FACTOR
) / 10000;
1228 batt_int
= battery_voltage
/ 100;
1229 batt_frac
= battery_voltage
% 100;
1231 snprintf(buf
, 32, "Batt: %d.%02dV", batt_int
, batt_frac
);
1232 lcd_puts(0, 1, buf
);
1234 button
= get_action(CONTEXT_SETTINGS
,HZ
/5);
1238 case ACTION_STD_CANCEL
:
1239 action_signalscreenchange();
1242 case ACTION_SETTINGS_DEC
:
1248 case ACTION_SETTINGS_INC
:
1257 #endif /* !HAVE_LCD_BITMAP */
1258 #endif /* !SIMULATOR */
1260 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1261 extern int boost_counter
;
1262 bool dbg_cpufreq(void)
1268 #ifdef HAVE_LCD_BITMAP
1269 lcd_setmargins(0, 0);
1270 lcd_setfont(FONT_SYSFIXED
);
1272 lcd_clear_display();
1278 snprintf(buf
, sizeof(buf
), "Frequency: %ld", FREQ
);
1279 lcd_puts(0, line
++, buf
);
1281 snprintf(buf
, sizeof(buf
), "boost_counter: %d", boost_counter
);
1282 lcd_puts(0, line
++, buf
);
1285 button
= get_action(CONTEXT_STD
,HZ
/10);
1289 case ACTION_STD_PREV
:
1292 case ACTION_STD_NEXT
:
1297 set_cpu_frequency(CPUFREQ_DEFAULT
);
1301 case ACTION_STD_CANCEL
:
1302 action_signalscreenchange();
1309 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1312 #ifdef HAVE_LCD_BITMAP
1314 * view_battery() shows a automatically scaled graph of the battery voltage
1315 * over time. Usable for estimating battery life / charging rate.
1316 * The power_history array is updated in power_thread of powermgmt.c.
1319 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1320 #define BAT_YSPACE (LCD_HEIGHT - 20)
1322 bool view_battery(void)
1326 unsigned short maxv
, minv
;
1329 lcd_setmargins(0, 0);
1330 lcd_setfont(FONT_SYSFIXED
);
1335 case 0: /* voltage history graph */
1336 /* Find maximum and minimum voltage for scaling */
1339 for (i
= 0; i
< BAT_LAST_VAL
; i
++) {
1340 if (power_history
[i
] > maxv
)
1341 maxv
= power_history
[i
];
1342 if (power_history
[i
] && (power_history
[i
] < minv
))
1344 minv
= power_history
[i
];
1348 if ((minv
< 1) || (minv
>= 65535))
1353 maxv
< 65535 ? maxv
++ : minv
--;
1355 lcd_clear_display();
1356 snprintf(buf
, 30, "Battery %d.%02d", power_history
[0] / 100,
1357 power_history
[0] % 100);
1358 lcd_puts(0, 0, buf
);
1359 snprintf(buf
, 30, "scale %d.%02d-%d.%02d V",
1360 minv
/ 100, minv
% 100, maxv
/ 100, maxv
% 100);
1361 lcd_puts(0, 1, buf
);
1364 for (i
= BAT_LAST_VAL
- 1; i
>= 0; i
--) {
1365 y
= (power_history
[i
] - minv
) * BAT_YSPACE
/ (maxv
- minv
);
1366 lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
1367 lcd_vline(x
, LCD_HEIGHT
-1, 20);
1368 lcd_set_drawmode(DRMODE_SOLID
);
1369 lcd_vline(x
, LCD_HEIGHT
-1,
1370 MIN(MAX(LCD_HEIGHT
-1 - y
, 20), LCD_HEIGHT
-1));
1376 case 1: /* status: */
1377 lcd_clear_display();
1378 lcd_puts(0, 0, "Power status:");
1380 y
= (adc_read(ADC_UNREG_POWER
) * BATTERY_SCALE_FACTOR
) / 10000;
1381 snprintf(buf
, 30, "Battery: %d.%02d V", y
/ 100, y
% 100);
1382 lcd_puts(0, 1, buf
);
1383 #ifdef ADC_EXT_POWER
1384 y
= (adc_read(ADC_EXT_POWER
) * EXT_SCALE_FACTOR
) / 10000;
1385 snprintf(buf
, 30, "External: %d.%02d V", y
/ 100, y
% 100);
1386 lcd_puts(0, 2, buf
);
1388 #ifdef CONFIG_CHARGING
1389 #if CONFIG_CHARGING == CHARGING_CONTROL
1390 snprintf(buf
, 30, "Chgr: %s %s",
1391 charger_inserted() ? "present" : "absent",
1392 charger_enabled
? "on" : "off");
1393 lcd_puts(0, 3, buf
);
1394 snprintf(buf
, 30, "short delta: %d", short_delta
);
1395 lcd_puts(0, 5, buf
);
1396 snprintf(buf
, 30, "long delta: %d", long_delta
);
1397 lcd_puts(0, 6, buf
);
1398 lcd_puts(0, 7, power_message
);
1399 #else /* CONFIG_CHARGING != CHARGING_CONTROL */
1400 #if defined IPOD_NANO || defined IPOD_VIDEO
1401 int usb_pwr
= (GPIOL_INPUT_VAL
& 0x10)?true:false;
1402 int ext_pwr
= (GPIOL_INPUT_VAL
& 0x08)?false:true;
1403 int dock
= (GPIOA_INPUT_VAL
& 0x10)?true:false;
1404 int charging
= (GPIOB_INPUT_VAL
& 0x01)?false:true;
1405 int headphone
= (GPIOA_INPUT_VAL
& 0x80)?true:false;
1407 snprintf(buf
, 30, "USB pwr: %s",
1408 usb_pwr
? "present" : "absent");
1409 lcd_puts(0, 3, buf
);
1410 snprintf(buf
, 30, "EXT pwr: %s",
1411 ext_pwr
? "present" : "absent");
1412 lcd_puts(0, 4, buf
);
1413 snprintf(buf
, 30, "Battery: %s",
1414 charging
? "charging" : (usb_pwr
||ext_pwr
) ? "charged" : "discharging");
1415 lcd_puts(0, 5, buf
);
1416 snprintf(buf
, 30, "Dock mode: %s",
1417 dock
? "enabled" : "disabled");
1418 lcd_puts(0, 6, buf
);
1419 snprintf(buf
, 30, "Headphone: %s",
1420 headphone
? "connected" : "disconnected");
1421 lcd_puts(0, 7, buf
);
1423 snprintf(buf
, 30, "Charger: %s",
1424 charger_inserted() ? "present" : "absent");
1425 lcd_puts(0, 3, buf
);
1427 #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1428 #endif /* CONFIG_CHARGING */
1431 case 2: /* voltage deltas: */
1432 lcd_clear_display();
1433 lcd_puts(0, 0, "Voltage deltas:");
1435 for (i
= 0; i
<= 6; i
++) {
1436 y
= power_history
[i
] - power_history
[i
+i
];
1437 snprintf(buf
, 30, "-%d min: %s%d.%02d V", i
,
1438 (y
< 0) ? "-" : "", ((y
< 0) ? y
* -1 : y
) / 100,
1439 ((y
< 0) ? y
* -1 : y
) % 100);
1440 lcd_puts(0, i
+1, buf
);
1444 case 3: /* remaining time estimation: */
1445 lcd_clear_display();
1447 #if CONFIG_CHARGING == CHARGING_CONTROL
1448 snprintf(buf
, 30, "charge_state: %d", charge_state
);
1449 lcd_puts(0, 0, buf
);
1451 snprintf(buf
, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min
);
1452 lcd_puts(0, 1, buf
);
1454 snprintf(buf
, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level
);
1455 lcd_puts(0, 2, buf
);
1457 snprintf(buf
, 30, "P=%2d I=%2d", pid_p
, pid_i
);
1458 lcd_puts(0, 3, buf
);
1460 snprintf(buf
, 30, "Trickle sec: %d/60", trickle_sec
);
1461 lcd_puts(0, 4, buf
);
1462 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
1464 snprintf(buf
, 30, "Last PwrHist: %d.%02d V",
1465 power_history
[0] / 100,
1466 power_history
[0] % 100);
1467 lcd_puts(0, 5, buf
);
1469 snprintf(buf
, 30, "battery level: %d%%", battery_level());
1470 lcd_puts(0, 6, buf
);
1472 snprintf(buf
, 30, "Est. remain: %d m", battery_time());
1473 lcd_puts(0, 7, buf
);
1479 switch(get_action(CONTEXT_SETTINGS
,HZ
/2))
1481 case ACTION_SETTINGS_DEC
:
1486 case ACTION_SETTINGS_INC
:
1491 case ACTION_STD_CANCEL
:
1492 action_signalscreenchange();
1499 #endif /* HAVE_LCD_BITMAP */
1502 static bool view_runtime(void)
1513 lcd_clear_display();
1514 #ifdef HAVE_LCD_BITMAP
1515 lcd_puts(0, y
++, "Running time:");
1520 #ifdef CONFIG_CHARGING
1521 if (charger_inserted()
1522 #ifdef HAVE_USB_POWER
1527 global_settings
.runtime
= 0;
1532 global_settings
.runtime
+= ((current_tick
- lasttime
) / HZ
);
1534 lasttime
= current_tick
;
1536 t
= global_settings
.runtime
;
1537 lcd_puts(0, y
++, "Current time");
1540 t
= global_settings
.topruntime
;
1541 lcd_puts(0, y
++, "Top time");
1544 snprintf(s
, sizeof(s
), "%dh %dm %ds",
1545 t
/ 3600, (t
% 3600) / 60, t
% 60);
1546 lcd_puts(0, y
++, s
);
1549 /* Wait for a key to be pushed */
1550 key
= get_action(CONTEXT_SETTINGS
,HZ
);
1552 case ACTION_STD_CANCEL
:
1556 case ACTION_SETTINGS_INC
:
1557 case ACTION_SETTINGS_DEC
:
1565 lcd_clear_display();
1566 /*NOTE: this needs to be changed to sync splash! */
1567 lcd_puts(0,0,"Clear time?");
1568 lcd_puts(0,1,"PLAY = Yes");
1571 key
= get_action(CONTEXT_STD
,TIMEOUT_BLOCK
);
1572 if ( key
== ACTION_STD_OK
) {
1574 global_settings
.runtime
= 0;
1576 global_settings
.topruntime
= 0;
1583 action_signalscreenchange();
1589 bool dbg_mmc_info(void)
1594 unsigned char pbuf
[32], pbuf2
[32];
1595 unsigned char card_name
[7];
1597 static const unsigned char i_vmin
[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1598 static const unsigned char i_vmax
[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1599 static const unsigned char *kbit_units
[] = { "kBit/s", "MBit/s", "GBit/s" };
1600 static const unsigned char *nsec_units
[] = { "ns", "µs", "ms" };
1602 card_name
[6] = '\0';
1604 lcd_setmargins(0, 0);
1605 lcd_setfont(FONT_SYSFIXED
);
1609 card
= mmc_card_info(currval
/ 2);
1611 lcd_clear_display();
1612 snprintf(pbuf
, sizeof(pbuf
), "[MMC%d p%d]", currval
/ 2,
1614 lcd_puts(0, 0, pbuf
);
1616 if (card
->initialized
)
1618 if (!(currval
% 2)) /* General info */
1620 strncpy(card_name
, ((unsigned char*)card
->cid
) + 3, 6);
1621 snprintf(pbuf
, sizeof(pbuf
), "%s Rev %d.%d", card_name
,
1622 (int) mmc_extract_bits(card
->cid
, 72, 4),
1623 (int) mmc_extract_bits(card
->cid
, 76, 4));
1624 lcd_puts(0, 1, pbuf
);
1625 snprintf(pbuf
, sizeof(pbuf
), "Prod: %d/%d",
1626 (int) mmc_extract_bits(card
->cid
, 112, 4),
1627 (int) mmc_extract_bits(card
->cid
, 116, 4) + 1997);
1628 lcd_puts(0, 2, pbuf
);
1629 snprintf(pbuf
, sizeof(pbuf
), "Ser#: 0x%08lx",
1630 mmc_extract_bits(card
->cid
, 80, 32));
1631 lcd_puts(0, 3, pbuf
);
1632 snprintf(pbuf
, sizeof(pbuf
), "M=%02x, O=%04x",
1633 (int) mmc_extract_bits(card
->cid
, 0, 8),
1634 (int) mmc_extract_bits(card
->cid
, 8, 16));
1635 lcd_puts(0, 4, pbuf
);
1636 snprintf(pbuf
, sizeof(pbuf
), "Blocks: 0x%06lx", card
->numblocks
);
1637 lcd_puts(0, 5, pbuf
);
1638 snprintf(pbuf
, sizeof(pbuf
), "Blksz.: %d", card
->blocksize
);
1639 lcd_puts(0, 6, pbuf
);
1641 else /* Technical details */
1643 output_dyn_value(pbuf2
, sizeof pbuf2
, card
->speed
/ 1000,
1645 snprintf(pbuf
, sizeof pbuf
, "Speed: %s", pbuf2
);
1646 lcd_puts(0, 1, pbuf
);
1648 output_dyn_value(pbuf2
, sizeof pbuf2
, card
->tsac
,
1650 snprintf(pbuf
, sizeof pbuf
, "Tsac: %s", pbuf2
);
1651 lcd_puts(0, 2, pbuf
);
1653 snprintf(pbuf
, sizeof(pbuf
), "Nsac: %d clk", card
->nsac
);
1654 lcd_puts(0, 3, pbuf
);
1655 snprintf(pbuf
, sizeof(pbuf
), "R2W: *%d", card
->r2w_factor
);
1656 lcd_puts(0, 4, pbuf
);
1657 snprintf(pbuf
, sizeof(pbuf
), "IRmax: %d..%d mA",
1658 i_vmin
[mmc_extract_bits(card
->csd
, 66, 3)],
1659 i_vmax
[mmc_extract_bits(card
->csd
, 69, 3)]);
1660 lcd_puts(0, 5, pbuf
);
1661 snprintf(pbuf
, sizeof(pbuf
), "IWmax: %d..%d mA",
1662 i_vmin
[mmc_extract_bits(card
->csd
, 72, 3)],
1663 i_vmax
[mmc_extract_bits(card
->csd
, 75, 3)]);
1664 lcd_puts(0, 6, pbuf
);
1668 lcd_puts(0, 1, "Not found!");
1672 switch (get_action(CONTEXT_SETTINGS
,HZ
/2))
1674 case ACTION_STD_CANCEL
:
1678 case ACTION_SETTINGS_DEC
:
1684 case ACTION_SETTINGS_INC
:
1691 action_signalscreenchange();
1694 #else /* !HAVE_MMC */
1695 static bool dbg_disk_info(void)
1701 const int max_page
= 11;
1702 unsigned short* identify_info
= ata_get_identify();
1703 bool timing_info_present
= false;
1704 char pio3
[2], pio4
[2];
1706 #ifdef HAVE_LCD_BITMAP
1707 lcd_setmargins(0, 0);
1714 lcd_clear_display();
1715 #ifdef HAVE_LCD_BITMAP
1716 lcd_puts(0, y
++, "Disk info:");
1722 for (i
=0; i
< 20; i
++)
1723 ((unsigned short*)buf
)[i
]=htobe16(identify_info
[i
+27]);
1725 /* kill trailing space */
1726 for (i
=39; i
&& buf
[i
]==' '; i
--)
1728 lcd_puts(0, y
++, "Model");
1729 lcd_puts_scroll(0, y
++, buf
);
1733 for (i
=0; i
< 4; i
++)
1734 ((unsigned short*)buf
)[i
]=htobe16(identify_info
[i
+23]);
1736 lcd_puts(0, y
++, "Firmware");
1737 lcd_puts(0, y
++, buf
);
1741 snprintf(buf
, sizeof buf
, "%ld MB",
1742 ((unsigned long)identify_info
[61] << 16 |
1743 (unsigned long)identify_info
[60]) / 2048 );
1744 lcd_puts(0, y
++, "Size");
1745 lcd_puts(0, y
++, buf
);
1750 fat_size( IF_MV2(0,) NULL
, &free
);
1751 snprintf(buf
, sizeof buf
, "%ld MB", free
/ 1024 );
1752 lcd_puts(0, y
++, "Free");
1753 lcd_puts(0, y
++, buf
);
1758 snprintf(buf
, sizeof buf
, "%d ms", ata_spinup_time
* (1000/HZ
));
1759 lcd_puts(0, y
++, "Spinup time");
1760 lcd_puts(0, y
++, buf
);
1764 i
= identify_info
[83] & (1<<3);
1765 lcd_puts(0, y
++, "Power mgmt:");
1766 lcd_puts(0, y
++, i
? "enabled" : "unsupported");
1770 i
= identify_info
[83] & (1<<9);
1771 lcd_puts(0, y
++, "Noise mgmt:");
1772 lcd_puts(0, y
++, i
? "enabled" : "unsupported");
1776 i
= identify_info
[82] & (1<<6);
1777 lcd_puts(0, y
++, "Read-ahead:");
1778 lcd_puts(0, y
++, i
? "enabled" : "unsupported");
1782 timing_info_present
= identify_info
[53] & (1<<1);
1783 if(timing_info_present
) {
1786 lcd_puts(0, y
++, "PIO modes:");
1787 pio3
[0] = (identify_info
[64] & (1<<0)) ? '3' : 0;
1788 pio4
[0] = (identify_info
[64] & (1<<1)) ? '4' : 0;
1789 snprintf(buf
, 128, "0 1 2 %s %s", pio3
, pio4
);
1790 lcd_puts(0, y
++, buf
);
1792 lcd_puts(0, y
++, "No PIO mode info");
1797 timing_info_present
= identify_info
[53] & (1<<1);
1798 if(timing_info_present
) {
1799 lcd_puts(0, y
++, "Cycle times");
1800 snprintf(buf
, 128, "%dns/%dns",
1803 lcd_puts(0, y
++, buf
);
1805 lcd_puts(0, y
++, "No timing info");
1810 timing_info_present
= identify_info
[53] & (1<<1);
1811 if(timing_info_present
) {
1812 i
= identify_info
[49] & (1<<11);
1813 snprintf(buf
, 128, "IORDY support: %s", i
? "yes" : "no");
1814 lcd_puts(0, y
++, buf
);
1815 i
= identify_info
[49] & (1<<10);
1816 snprintf(buf
, 128, "IORDY disable: %s", i
? "yes" : "no");
1817 lcd_puts(0, y
++, buf
);
1819 lcd_puts(0, y
++, "No timing info");
1824 lcd_puts(0, y
++, "Cluster size");
1825 snprintf(buf
, 128, "%d bytes", fat_get_cluster_size(IF_MV(0)));
1826 lcd_puts(0, y
++, buf
);
1831 /* Wait for a key to be pushed */
1832 key
= get_action(CONTEXT_SETTINGS
,HZ
/5);
1834 case ACTION_STD_CANCEL
:
1838 case ACTION_SETTINGS_DEC
:
1843 case ACTION_SETTINGS_INC
:
1844 if (++page
> max_page
)
1850 action_signalscreenchange();
1853 #endif /* !HAVE_MMC */
1854 #endif /* !SIMULATOR */
1856 #ifdef HAVE_DIRCACHE
1857 static bool dbg_dircache_info(void)
1863 lcd_setmargins(0, 0);
1864 lcd_setfont(FONT_SYSFIXED
);
1870 lcd_clear_display();
1871 snprintf(buf
, sizeof(buf
), "Cache initialized: %s",
1872 dircache_is_enabled() ? "Yes" : "No");
1873 lcd_puts(0, line
++, buf
);
1875 snprintf(buf
, sizeof(buf
), "Cache size: %d B",
1876 dircache_get_cache_size());
1877 lcd_puts(0, line
++, buf
);
1879 snprintf(buf
, sizeof(buf
), "Last size: %d B",
1880 global_settings
.dircache_size
);
1881 lcd_puts(0, line
++, buf
);
1883 snprintf(buf
, sizeof(buf
), "Limit: %d B", DIRCACHE_LIMIT
);
1884 lcd_puts(0, line
++, buf
);
1886 snprintf(buf
, sizeof(buf
), "Reserve: %d/%d B",
1887 dircache_get_reserve_used(), DIRCACHE_RESERVE
);
1888 lcd_puts(0, line
++, buf
);
1890 snprintf(buf
, sizeof(buf
), "Scanning took: %d s",
1891 dircache_get_build_ticks() / HZ
);
1892 lcd_puts(0, line
++, buf
);
1894 snprintf(buf
, sizeof(buf
), "Entry count: %d",
1895 dircache_get_entry_count());
1896 lcd_puts(0, line
++, buf
);
1900 if (action_userabort(HZ
/2))
1907 #endif /* HAVE_DIRCACHE */
1909 #ifdef HAVE_LCD_BITMAP
1910 static bool dbg_tagcache_info(void)
1915 struct tagcache_stat
*stat
;
1917 lcd_setmargins(0, 0);
1918 lcd_setfont(FONT_SYSFIXED
);
1924 lcd_clear_display();
1925 stat
= tagcache_get_stat();
1926 snprintf(buf
, sizeof(buf
), "Initialized: %s", stat
->initialized
? "Yes" : "No");
1927 lcd_puts(0, line
++, buf
);
1928 snprintf(buf
, sizeof(buf
), "DB Ready: %s", stat
->ready
? "Yes" : "No");
1929 lcd_puts(0, line
++, buf
);
1930 snprintf(buf
, sizeof(buf
), "RAM Cache: %s", stat
->ramcache
? "Yes" : "No");
1931 lcd_puts(0, line
++, buf
);
1932 snprintf(buf
, sizeof(buf
), "RAM: %d/%d B",
1933 stat
->ramcache_used
, stat
->ramcache_allocated
);
1934 lcd_puts(0, line
++, buf
);
1935 snprintf(buf
, sizeof(buf
), "Progress: %d%% (%d entries)",
1936 stat
->progress
, stat
->processed_entries
);
1937 lcd_puts(0, line
++, buf
);
1938 snprintf(buf
, sizeof(buf
), "Commit step: %d", stat
->commit_step
);
1939 lcd_puts(0, line
++, buf
);
1940 snprintf(buf
, sizeof(buf
), "Commit delayed: %s",
1941 stat
->commit_delayed
? "Yes" : "No");
1942 lcd_puts(0, line
++, buf
);
1946 if (action_userabort(HZ
/2))
1954 #if CONFIG_CPU == SH7034
1955 bool dbg_save_roms(void)
1958 int oldmode
= system_memory_guard(MEMGUARD_NONE
);
1960 fd
= creat("/internal_rom_0000-FFFF.bin", O_WRONLY
);
1963 write(fd
, (void *)0, 0x10000);
1967 fd
= creat("/internal_rom_2000000-203FFFF.bin", O_WRONLY
);
1970 write(fd
, (void *)0x2000000, 0x40000);
1974 system_memory_guard(oldmode
);
1977 #elif defined CPU_COLDFIRE
1978 bool dbg_save_roms(void)
1981 int oldmode
= system_memory_guard(MEMGUARD_NONE
);
1983 #if defined(IRIVER_H100_SERIES)
1984 fd
= creat("/internal_rom_000000-1FFFFF.bin", O_WRONLY
);
1985 #elif defined(IRIVER_H300_SERIES)
1986 fd
= creat("/internal_rom_000000-3FFFFF.bin", O_WRONLY
);
1987 #elif defined(IAUDIO_X5)
1988 fd
= creat("/internal_rom_000000-3FFFFF.bin", O_WRONLY
);
1992 write(fd
, (void *)0, FLASH_SIZE
);
1995 system_memory_guard(oldmode
);
1998 fd
= creat("/internal_eeprom.bin", O_WRONLY
);
2002 char buf
[EEPROM_SIZE
];
2005 old_irq_level
= set_irq_level(HIGHEST_IRQ_LEVEL
);
2007 err
= eeprom_24cxx_read(0, buf
, sizeof buf
);
2009 gui_syncsplash(HZ
*3, true, "Eeprom read failure (%d)",err
);
2012 write(fd
, buf
, sizeof buf
);
2015 set_irq_level(old_irq_level
);
2027 bool dbg_fm_radio(void)
2032 #ifdef HAVE_LCD_BITMAP
2033 lcd_setmargins(0, 0);
2041 lcd_clear_display();
2042 fm_detected
= radio_hardware_present();
2044 snprintf(buf
, sizeof buf
, "HW detected: %s", fm_detected
?"yes":"no");
2045 lcd_puts(0, row
++, buf
);
2047 #if (CONFIG_TUNER & S1A0903X01)
2048 regs
= samsung_get(RADIO_ALL
);
2049 snprintf(buf
, sizeof buf
, "Samsung regs: %08lx", regs
);
2050 lcd_puts(0, row
++, buf
);
2052 #if (CONFIG_TUNER & TEA5767)
2053 regs
= philips_get(RADIO_ALL
);
2054 snprintf(buf
, sizeof buf
, "Philips regs: %08lx", regs
);
2055 lcd_puts(0, row
++, buf
);
2060 if (action_userabort(HZ
))
2065 #endif /* CONFIG_TUNER */
2066 #endif /* !SIMULATOR */
2068 #ifdef HAVE_LCD_BITMAP
2069 extern bool do_screendump_instead_of_usb
;
2071 bool dbg_screendump(void)
2073 do_screendump_instead_of_usb
= !do_screendump_instead_of_usb
;
2074 gui_syncsplash(HZ
, true, "Screendump %s",
2075 do_screendump_instead_of_usb
?"enabled":"disabled");
2078 #endif /* HAVE_LCD_BITMAP */
2080 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2081 bool dbg_set_memory_guard(void)
2083 static const struct opt_items names
[MAXMEMGUARD
] = {
2085 { "Flash ROM writes", -1 },
2086 { "Zero area (all)", -1 }
2088 int mode
= system_memory_guard(MEMGUARD_KEEP
);
2090 set_option( "Catch mem accesses", &mode
, INT
, names
, MAXMEMGUARD
, NULL
);
2091 system_memory_guard(mode
);
2095 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2097 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2098 bool dbg_write_eeprom(void)
2103 char buf
[EEPROM_SIZE
];
2106 fd
= open("/internal_eeprom.bin", O_RDONLY
);
2110 rc
= read(fd
, buf
, EEPROM_SIZE
);
2112 if(rc
== EEPROM_SIZE
)
2114 old_irq_level
= set_irq_level(HIGHEST_IRQ_LEVEL
);
2116 err
= eeprom_24cxx_write(0, buf
, sizeof buf
);
2118 gui_syncsplash(HZ
*3, true, "Eeprom write failure (%d)",err
);
2120 gui_syncsplash(HZ
*3, true, "Eeprom written successfully");
2122 set_irq_level(old_irq_level
);
2126 gui_syncsplash(HZ
*3, true, "File read error (%d)",rc
);
2132 gui_syncsplash(HZ
*3, true, "Failed to open 'internal_eeprom.bin'");
2137 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2139 bool debug_menu(void)
2144 static const struct menu_item items
[] = {
2145 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2146 { "Dump ROM contents", dbg_save_roms
},
2148 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || (CONFIG_CPU == PP5020)
2149 { "View I/O ports", dbg_ports
},
2151 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2152 { "CPU frequency", dbg_cpufreq
},
2154 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2155 { "S/PDIF analyzer", dbg_spdif
},
2157 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2158 { "Catch mem accesses", dbg_set_memory_guard
},
2161 { "View OS stacks", dbg_os
},
2163 #ifdef HAVE_LCD_BITMAP
2165 { "View battery", view_battery
},
2167 { "Screendump", dbg_screendump
},
2170 { "View HW info", dbg_hw_info
},
2173 { "View partitions", dbg_partitions
},
2177 { "View MMC info", dbg_mmc_info
},
2179 { "View disk info", dbg_disk_info
},
2182 #ifdef HAVE_DIRCACHE
2183 { "View dircache info", dbg_dircache_info
},
2185 #ifdef HAVE_LCD_BITMAP
2186 { "View tagcache info", dbg_tagcache_info
},
2187 #if CONFIG_CODEC == SWCODEC || !defined(SIMULATOR)
2188 { "View audio thread", dbg_audio_thread
},
2191 { "pm histogram", peak_meter_histogram
},
2192 #endif /* PM_DEBUG */
2193 #endif /* HAVE_LCD_BITMAP */
2194 { "View runtime", view_runtime
},
2197 { "FM Radio", dbg_fm_radio
},
2200 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2201 { "Write back EEPROM", dbg_write_eeprom
},
2203 #ifdef ROCKBOX_HAS_LOGF
2204 {"logf", logfdisplay
},
2205 {"logfdump", logfdump
},
2209 m
=menu_init( items
, sizeof items
/ sizeof(struct menu_item
), NULL
,
2211 result
= menu_run(m
);