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 ****************************************************************************/
27 #include "debug_menu.h"
37 #include "powermgmt.h"
42 #include "mp3_playback.h"
49 #ifdef HAVE_LCD_BITMAP
51 #include "peakmeter.h"
57 /*---------------------------------------------------*/
58 /* SPECIAL DEBUG STUFF */
59 /*---------------------------------------------------*/
60 extern int ata_device
;
61 extern int ata_io_address
;
62 extern int num_threads
;
63 extern char *thread_name
[];
65 #ifdef HAVE_LCD_BITMAP
74 #ifdef HAVE_LCD_BITMAP
81 lcd_puts(0, 0, "Stack usage:");
82 for(i
= 0; i
< num_threads
;i
++)
84 usage
= thread_stack_usage(i
);
85 snprintf(buf
, 32, "%s: %d%%", thread_name
[i
], usage
);
86 lcd_puts(0, 1+i
, buf
);
91 button
= button_get_w_tmo(HZ
/10);
112 #ifdef HAVE_LCD_BITMAP
113 lcd_setmargins(0, 0);
119 lcd_puts(0, 0, "Stack usage");
121 usage
= thread_stack_usage(currval
);
122 snprintf(buf
, 32, "%d: %d%% ", currval
, usage
);
125 button
= button_get_w_tmo(HZ
/10);
135 currval
= num_threads
-1;
140 if(currval
> num_threads
-1)
149 #ifdef HAVE_LCD_BITMAP
150 bool dbg_mpeg_thread(void)
157 lcd_setmargins(0, 0);
161 button
= button_get_w_tmo(HZ
/5);
164 case BUTTON_OFF
| BUTTON_REL
:
168 mpeg_get_debugdata(&d
);
172 snprintf(buf
, sizeof(buf
), "read: %x", d
.mp3buf_read
);
174 snprintf(buf
, sizeof(buf
), "write: %x", d
.mp3buf_write
);
176 snprintf(buf
, sizeof(buf
), "swap: %x", d
.mp3buf_swapwrite
);
178 snprintf(buf
, sizeof(buf
), "playing: %d", d
.playing
);
180 snprintf(buf
, sizeof(buf
), "playable: %x", d
.playable_space
);
182 snprintf(buf
, sizeof(buf
), "unswapped: %x", d
.unswapped_space
);
185 percent
= d
.playable_space
* 100 / d
.mp3buflen
;
186 progressbar(0, 6*8, 112, 4, percent
, Grow_Right
);
188 percent
= d
.low_watermark_level
* 100 / d
.mp3buflen
;
189 progressbar(0, 6*8+4, 112, 4, percent
, Grow_Right
);
191 snprintf(buf
, sizeof(buf
), "wm: %x - %x",
192 d
.low_watermark_level
, d
.lowest_watermark_level
);
202 /* Tool function to calculate a CRC16 across some buffer */
203 unsigned short crc_16(unsigned char* buf
, unsigned len
)
205 /* CCITT standard polynomial 0x1021 */
206 static const unsigned short crc16_lookup
[16] =
207 { /* lookup table for 4 bits at a time is affordable */
208 0x0000, 0x1021, 0x2042, 0x3063,
209 0x4084, 0x50A5, 0x60C6, 0x70E7,
210 0x8108, 0x9129, 0xA14A, 0xB16B,
211 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF
213 unsigned short crc16
= 0xFFFF; /* initialise to 0xFFFF (CCITT specification) */
219 byte
= *buf
++; /* get one byte of data */
221 /* upper nibble of our data */
222 t
= crc16
>> 12; /* extract the 4 most significant bits */
223 t
^= byte
>> 4; /* XOR in 4 bits of the data into the extracted bits */
224 crc16
<<= 4; /* shift the CRC Register left 4 bits */
225 crc16
^= crc16_lookup
[t
]; /* do the table lookup and XOR the result */
227 /* lower nibble of our data */
228 t
= crc16
>> 12; /* extract the 4 most significant bits */
229 t
^= byte
& 0x0F; /* XOR in 4 bits of the data into the extracted bits */
230 crc16
<<= 4; /* shift the CRC Register left 4 bits */
231 crc16
^= crc16_lookup
[t
]; /* do the table lookup and XOR the result */
239 /* Tool function to read the flash manufacturer and type, if available.
240 Only chips which could be reprogrammed in system will return values.
241 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
242 bool dbg_flash_id(unsigned* p_manufacturer
, unsigned* p_device
, unsigned addr1
, unsigned addr2
)
244 unsigned not_manu
, not_id
; /* read values before switching to ID mode */
245 unsigned manu
, id
; /* read values when in ID mode */
246 volatile unsigned char* flash
= (unsigned char*)0x2000000; /* flash mapping */
248 not_manu
= flash
[0]; /* read the normal content */
249 not_id
= flash
[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
251 flash
[addr1
] = 0xAA; /* enter command mode */
253 flash
[addr1
] = 0x90; /* ID command */
254 sleep(HZ
/50); /* Atmel wants 20ms pause here */
256 manu
= flash
[0]; /* read the IDs */
259 flash
[0] = 0xF0; /* reset flash (back to normal read mode) */
260 sleep(HZ
/50); /* Atmel wants 20ms pause here */
262 /* I assume success if the obtained values are different from
263 the normal flash content. This is not perfectly bulletproof, they
264 could theoretically be the same by chance, causing us to fail. */
265 if (not_manu
!= manu
|| not_id
!= id
) /* a value has changed */
267 *p_manufacturer
= manu
; /* return the results */
269 return true; /* success */
271 return false; /* fail */
275 #ifdef HAVE_LCD_BITMAP
276 bool dbg_hw_info(void)
282 int bitmask
= *(unsigned short*)0x20000fc;
283 int rom_version
= *(unsigned short*)0x20000fe;
284 unsigned manu
, id
; /* flash IDs */
285 bool got_id
; /* flag if we managed to get the flash IDs */
286 unsigned rom_crc
= 0xFFFF; /* CRC16 of the boot ROM */
287 bool has_bootrom
; /* flag for boot ROM present */
290 usb_polarity
= 0; /* Negative */
292 usb_polarity
= 1; /* Positive */
295 pr_polarity
= 0; /* Negative */
297 pr_polarity
= 1; /* Positive */
299 /* get flash ROM type */
300 got_id
= dbg_flash_id(&manu
, &id
, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
302 got_id
= dbg_flash_id(&manu
, &id
, 0x555, 0x2AA); /* try AMD, Macronix */
304 /* check if the boot ROM area is a flash mirror */
305 has_bootrom
= (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
306 if (has_bootrom
) /* if ROM and Flash different */
308 /* calculate CRC16 checksum of boot ROM */
309 rom_crc
= crc_16((unsigned char*)0x0000, 64*1024);
312 lcd_setmargins(0, 0);
313 lcd_setfont(FONT_SYSFIXED
);
316 lcd_puts(0, 0, "[Hardware info]");
318 snprintf(buf
, 32, "ROM: %d.%02d", rom_version
/100, rom_version
%100);
321 snprintf(buf
, 32, "Mask: 0x%04x", bitmask
);
324 snprintf(buf
, 32, "USB: %s", usb_polarity
?"positive":"negative");
327 snprintf(buf
, 32, "ATA: 0x%x,%s", ata_io_address
,
328 ata_device
? "slave":"master");
331 snprintf(buf
, 32, "PR: %s", pr_polarity
?"positive":"negative");
335 snprintf(buf
, 32, "Flash: M=%02x D=%02x", manu
, id
);
337 snprintf(buf
, 32, "Flash: M=?? D=??"); /* unknown, sorry */
342 snprintf(buf
, 32-3, "ROM CRC: 0x%04x", rom_crc
);
343 if (rom_crc
== 0x222F) /* known Version 1 */
348 snprintf(buf
, 32, "Boot ROM: none");
356 button
= button_get(true);
357 if(button
== (BUTTON_OFF
| BUTTON_REL
))
364 bool dbg_hw_info(void)
370 int bitmask
= *(unsigned short*)0x20000fc;
371 int rom_version
= *(unsigned short*)0x20000fe;
372 unsigned manu
, id
; /* flash IDs */
373 bool got_id
; /* flag if we managed to get the flash IDs */
374 unsigned rom_crc
= 0xFFFF; /* CRC16 of the boot ROM */
375 bool has_bootrom
; /* flag for boot ROM present */
378 usb_polarity
= 0; /* Negative */
380 usb_polarity
= 1; /* Positive */
382 /* get flash ROM type */
383 got_id
= dbg_flash_id(&manu
, &id
, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
385 got_id
= dbg_flash_id(&manu
, &id
, 0x555, 0x2AA); /* try AMD, Macronix */
387 /* check if the boot ROM area is a flash mirror */
388 has_bootrom
= (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
389 if (has_bootrom
) /* if ROM and Flash different */
391 /* calculate CRC16 checksum of boot ROM */
392 rom_crc
= crc_16((unsigned char*)0x0000, 64*1024);
397 lcd_puts(0, 0, "[HW Info]");
403 snprintf(buf
, 32, "ROM: %d.%02d",
404 rom_version
/100, rom_version
%100);
407 snprintf(buf
, 32, "USB: %s",
408 usb_polarity
?"pos":"neg");
411 snprintf(buf
, 32, "ATA: 0x%x%s",
412 ata_io_address
, ata_device
? "s":"m");
415 snprintf(buf
, 32, "Mask: %04x", bitmask
);
419 snprintf(buf
, 32, "Flash:%02x,%02x", manu
, id
);
421 snprintf(buf
, 32, "Flash:??,??"); /* unknown, sorry */
425 snprintf(buf
, 32, "RomCRC:%04x", rom_crc
);
427 snprintf(buf
, 32, "BootROM: no");
433 button
= button_get(true);
457 bool dbg_partitions(void)
462 lcd_puts(0, 0, "Partition");
463 lcd_puts(0, 1, "list");
471 struct partinfo
* p
= disk_partinfo(partition
);
474 snprintf(buf
, sizeof buf
, "P%d: S:%x", partition
, p
->start
);
476 snprintf(buf
, sizeof buf
, "T:%x %d MB", p
->type
, p
->size
/ 2048);
480 button
= button_get(true);
484 #ifdef HAVE_RECORDER_KEYPAD
491 #ifdef HAVE_RECORDER_KEYPAD
500 #ifdef HAVE_RECORDER_KEYPAD
509 case SYS_USB_CONNECTED
:
517 #ifdef HAVE_LCD_BITMAP
521 unsigned short porta
;
522 unsigned short portb
;
527 int batt_int
, batt_frac
;
529 #ifdef HAVE_LCD_BITMAP
530 lcd_setmargins(0, 0);
540 snprintf(buf
, 32, "PADR: %04x", porta
);
542 snprintf(buf
, 32, "PBDR: %04x", portb
);
545 snprintf(buf
, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
547 snprintf(buf
, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
549 snprintf(buf
, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
551 snprintf(buf
, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
554 battery_voltage
= (adc_read(ADC_UNREG_POWER
) * BATTERY_SCALE_FACTOR
) / 10000;
555 batt_int
= battery_voltage
/ 100;
556 batt_frac
= battery_voltage
% 100;
558 snprintf(buf
, 32, "Batt: %d.%02dV %d%% ", batt_int
, batt_frac
,
562 snprintf(buf
, 32, "ATA: %s, 0x%x",
563 ata_device
?"slave":"master", ata_io_address
);
567 button
= button_get_w_tmo(HZ
/10);
571 case BUTTON_OFF
| BUTTON_REL
:
580 unsigned short porta
;
581 unsigned short portb
;
586 int batt_int
, batt_frac
;
589 #ifdef HAVE_LCD_BITMAP
590 lcd_setmargins(0, 0);
603 snprintf(buf
, 32, "PADR: %04x ", porta
);
606 snprintf(buf
, 32, "PBDR: %04x ", portb
);
609 snprintf(buf
, 32, "AN0: %03x ", adc_read(0));
612 snprintf(buf
, 32, "AN1: %03x ", adc_read(1));
615 snprintf(buf
, 32, "AN2: %03x ", adc_read(2));
618 snprintf(buf
, 32, "AN3: %03x ", adc_read(3));
621 snprintf(buf
, 32, "AN4: %03x ", adc_read(4));
624 snprintf(buf
, 32, "AN5: %03x ", adc_read(5));
627 snprintf(buf
, 32, "AN6: %03x ", adc_read(6));
630 snprintf(buf
, 32, "AN7: %03x ", adc_read(7));
633 snprintf(buf
, 32, "%s, 0x%x ",
634 ata_device
?"slv":"mst", ata_io_address
);
639 battery_voltage
= (adc_read(ADC_UNREG_POWER
) *
640 BATTERY_SCALE_FACTOR
) / 10000;
641 batt_int
= battery_voltage
/ 100;
642 batt_frac
= battery_voltage
% 100;
644 snprintf(buf
, 32, "Batt: %d.%02dV", batt_int
, batt_frac
);
647 button
= button_get_w_tmo(HZ
/5);
651 case BUTTON_STOP
| BUTTON_REL
:
672 /* Read RTC RAM contents and display them */
676 unsigned char addr
= 0, r
, c
;
680 #ifdef HAVE_LCD_BITMAP
681 lcd_setmargins(0, 0);
684 lcd_puts(0, 0, "RTC read:");
688 for (r
= 0; r
< 4; r
++) {
689 snprintf(buf
, 10, "0x%02x: ", addr
+ r
*4);
690 for (c
= 0; c
<= 3; c
++) {
691 i
= rtc_read(addr
+ r
*4 + c
);
692 snprintf(buf
+ 6 + c
*2, 3, "%02x", i
);
694 lcd_puts(1, r
+1, buf
);
699 button
= button_get_w_tmo(HZ
/2);
704 if (addr
< 63-16) { addr
+= 16; }
707 if (addr
) { addr
-= 16; }
710 /* clear the user RAM space */
711 for (c
= 0; c
<= 43; c
++)
712 rtc_write(0x14 + c
, 0);
714 case BUTTON_OFF
| BUTTON_REL
:
715 case BUTTON_LEFT
| BUTTON_REL
:
728 #ifdef HAVE_LCD_CHARCELLS
733 /* Read MAS registers and display them */
737 unsigned int addr
= 0, r
, i
;
739 #ifdef HAVE_LCD_BITMAP
740 lcd_setmargins(0, 0);
743 lcd_puts(0, 0, "MAS register read:");
747 for (r
= 0; r
< NUMROWS
; r
++) {
748 i
= mas_readreg(addr
+ r
);
749 snprintf(buf
, 30, "%02x %08x", addr
+ r
, i
);
750 lcd_puts(0, r
+1, buf
);
755 switch(button_get_w_tmo(HZ
/16))
757 #ifdef HAVE_RECORDER_KEYPAD
764 #ifdef HAVE_RECORDER_KEYPAD
772 #ifdef HAVE_RECORDER_KEYPAD
784 bool dbg_mas_codec(void)
787 unsigned int addr
= 0, r
, i
;
789 #ifdef HAVE_LCD_BITMAP
790 lcd_setmargins(0, 0);
793 lcd_puts(0, 0, "MAS codec reg read:");
797 for (r
= 0; r
< 4; r
++) {
798 i
= mas_codec_readreg(addr
+ r
);
799 snprintf(buf
, 30, "0x%02x: %08x", addr
+ r
, i
);
800 lcd_puts(1, r
+1, buf
);
805 switch(button_get_w_tmo(HZ
/16))
811 if (addr
) { addr
-= 4; }
813 case BUTTON_LEFT
| BUTTON_REL
:
814 case BUTTON_OFF
| BUTTON_REL
:
822 #ifdef HAVE_LCD_BITMAP
824 * view_battery() shows a automatically scaled graph of the battery voltage
825 * over time. Usable for estimating battery life / charging rate.
826 * The power_history array is updated in power_thread of powermgmt.c.
829 #define BAT_FIRST_VAL MAX(POWER_HISTORY_LEN - LCD_WIDTH - 1, 0)
830 #define BAT_YSPACE (LCD_HEIGHT - 20)
832 bool view_battery(void)
839 #ifdef HAVE_LCD_BITMAP
840 lcd_setmargins(0, 0);
845 case 0: /* voltage history graph */
846 /* Find maximum and minimum voltage for scaling */
848 for (i
= BAT_FIRST_VAL
; i
< POWER_HISTORY_LEN
; i
++) {
849 if (power_history
[i
] > maxv
)
850 maxv
= power_history
[i
];
851 if ((minv
== 0) || ((power_history
[i
]) &&
852 (power_history
[i
] < minv
)) )
854 minv
= power_history
[i
];
864 lcd_puts(0, 0, "Battery voltage:");
865 snprintf(buf
, 30, "scale %d.%02d-%d.%02d V",
866 minv
/ 100, minv
% 100, maxv
/ 100, maxv
% 100);
870 for (i
= BAT_FIRST_VAL
+1; i
< POWER_HISTORY_LEN
; i
++) {
871 y
= (power_history
[i
] - minv
) * BAT_YSPACE
/ (maxv
- minv
);
872 lcd_clearline(x
, LCD_HEIGHT
-1, x
, 20);
873 lcd_drawline(x
, LCD_HEIGHT
-1, x
,
874 MIN(MAX(LCD_HEIGHT
-1 - y
, 20), LCD_HEIGHT
-1));
880 case 1: /* status: */
882 lcd_puts(0, 0, "Power status:");
884 y
= (adc_read(ADC_UNREG_POWER
) * BATTERY_SCALE_FACTOR
) / 10000;
885 snprintf(buf
, 30, "Battery: %d.%02d V", y
/ 100, y
% 100);
887 y
= (adc_read(ADC_EXT_POWER
) * EXT_SCALE_FACTOR
) / 10000;
888 snprintf(buf
, 30, "External: %d.%02d V", y
/ 100, y
% 100);
890 snprintf(buf
, 30, "Charger: %s",
891 charger_inserted() ? "present" : "absent");
893 #ifdef HAVE_CHARGE_CTRL
894 snprintf(buf
, 30, "Charging: %s",
895 charger_enabled
? "yes" : "no");
898 y
= ( power_history
[POWER_HISTORY_LEN
-1] * 100
899 + power_history
[POWER_HISTORY_LEN
-2] * 100
900 - power_history
[POWER_HISTORY_LEN
-1-CHARGE_END_NEGD
+1] * 100
901 - power_history
[POWER_HISTORY_LEN
-1-CHARGE_END_NEGD
] * 100 )
902 / CHARGE_END_NEGD
/ 2;
904 snprintf(buf
, 30, "short delta: %d", y
);
907 y
= ( power_history
[POWER_HISTORY_LEN
-1] * 100
908 + power_history
[POWER_HISTORY_LEN
-2] * 100
909 - power_history
[POWER_HISTORY_LEN
-1-CHARGE_END_ZEROD
+1] * 100
910 - power_history
[POWER_HISTORY_LEN
-1-CHARGE_END_ZEROD
] * 100 )
911 / CHARGE_END_ZEROD
/ 2;
913 snprintf(buf
, 30, "long delta: %d", y
);
916 #ifdef HAVE_CHARGE_CTRL
917 lcd_puts(0, 7, power_message
);
921 case 2: /* voltage deltas: */
923 lcd_puts(0, 0, "Voltage deltas:");
925 for (i
= 0; i
<= 6; i
++) {
926 y
= power_history
[POWER_HISTORY_LEN
-1-i
] -
927 power_history
[POWER_HISTORY_LEN
-1-i
-1];
928 snprintf(buf
, 30, "-%d min: %s%d.%02d V", i
,
929 (y
< 0) ? "-" : "", ((y
< 0) ? y
* -1 : y
) / 100,
930 ((y
< 0) ? y
* -1 : y
) % 100);
931 lcd_puts(0, i
+1, buf
);
935 case 3: /* remeining time estimation: */
938 #ifdef HAVE_CHARGE_CTRL
939 snprintf(buf
, 30, "charge_state: %d", charge_state
);
942 snprintf(buf
, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min
);
945 snprintf(buf
, 30, "Lev.at cycle start: %d%%", powermgmt_last_cycle_level
);
949 snprintf(buf
, 30, "Last PwrHist val: %d.%02d V",
950 power_history
[POWER_HISTORY_LEN
-1] / 100,
951 power_history
[POWER_HISTORY_LEN
-1] % 100);
954 snprintf(buf
, 30, "battery level: %d%%", battery_level());
957 snprintf(buf
, 30, "Est. remaining: %d m", battery_time());
960 #ifdef HAVE_CHARGE_CTRL
961 snprintf(buf
, 30, "Trickle sec: %d/60", trickle_sec
);
969 switch(button_get_w_tmo(HZ
/2))
981 case BUTTON_LEFT
| BUTTON_REL
:
982 case BUTTON_OFF
| BUTTON_REL
:
992 bool dbg_mas_info(void)
998 unsigned long pll48
, pll44
, config
;
1001 #ifdef HAVE_LCD_BITMAP
1002 lcd_setmargins(0, 0);
1009 mas_readmem(MAS_BANK_D1
, 0xff7, &val
, 1);
1010 lcd_puts(0, 0, "Design Code");
1011 snprintf(buf
, 32, "%05x ", val
);
1014 lcd_puts(0, 0, "DC/DC mode ");
1015 snprintf(buf
, 32, "8e: %05x ", mas_readreg(0x8e) & 0xfffff);
1018 lcd_puts(0, 0, "Mute/Bypass");
1019 snprintf(buf
, 32, "aa: %05x ", mas_readreg(0xaa) & 0xfffff);
1022 lcd_puts(0, 0, "PIOData ");
1023 snprintf(buf
, 32, "ed: %05x ", mas_readreg(0xed) & 0xfffff);
1026 lcd_puts(0, 0, "Startup Cfg");
1027 snprintf(buf
, 32, "e6: %05x ", mas_readreg(0xe6) & 0xfffff);
1030 lcd_puts(0, 0, "KPrescale ");
1031 snprintf(buf
, 32, "e7: %05x ", mas_readreg(0xe7) & 0xfffff);
1034 lcd_puts(0, 0, "KBass ");
1035 snprintf(buf
, 32, "6b: %05x ", mas_readreg(0x6b) & 0xfffff);
1038 lcd_puts(0, 0, "KTreble ");
1039 snprintf(buf
, 32, "6f: %05x ", mas_readreg(0x6f) & 0xfffff);
1042 mas_readmem(MAS_BANK_D0
, 0x300, &val
, 1);
1043 lcd_puts(0, 0, "Frame Count");
1044 snprintf(buf
, 32, "0/300: %04x", val
& 0xffff);
1047 mas_readmem(MAS_BANK_D0
, 0x301, &val
, 1);
1048 lcd_puts(0, 0, "Status1 ");
1049 snprintf(buf
, 32, "0/301: %04x", val
& 0xffff);
1052 mas_readmem(MAS_BANK_D0
, 0x302, &val
, 1);
1053 lcd_puts(0, 0, "Status2 ");
1054 snprintf(buf
, 32, "0/302: %04x", val
& 0xffff);
1057 mas_readmem(MAS_BANK_D0
, 0x303, &val
, 1);
1058 lcd_puts(0, 0, "CRC Count ");
1059 snprintf(buf
, 32, "0/303: %04x", val
& 0xffff);
1062 mas_readmem(MAS_BANK_D0
, 0x36d, &val
, 1);
1063 lcd_puts(0, 0, "PLLOffset48");
1064 snprintf(buf
, 32, "0/36d %05x", val
& 0xfffff);
1067 mas_readmem(MAS_BANK_D0
, 0x32d, &val
, 1);
1068 lcd_puts(0, 0, "PLLOffset48");
1069 snprintf(buf
, 32, "0/32d %05x", val
& 0xfffff);
1072 mas_readmem(MAS_BANK_D0
, 0x36e, &val
, 1);
1073 lcd_puts(0, 0, "PLLOffset44");
1074 snprintf(buf
, 32, "0/36e %05x", val
& 0xfffff);
1077 mas_readmem(MAS_BANK_D0
, 0x32e, &val
, 1);
1078 lcd_puts(0, 0, "PLLOffset44");
1079 snprintf(buf
, 32, "0/32e %05x", val
& 0xfffff);
1082 mas_readmem(MAS_BANK_D0
, 0x36f, &val
, 1);
1083 lcd_puts(0, 0, "OutputConf ");
1084 snprintf(buf
, 32, "0/36f %05x", val
& 0xfffff);
1087 mas_readmem(MAS_BANK_D0
, 0x32f, &val
, 1);
1088 lcd_puts(0, 0, "OutputConf ");
1089 snprintf(buf
, 32, "0/32f %05x", val
& 0xfffff);
1092 mas_readmem(MAS_BANK_D1
, 0x7f8, &val
, 1);
1093 lcd_puts(0, 0, "LL Gain ");
1094 snprintf(buf
, 32, "1/7f8 %05x", val
& 0xfffff);
1097 mas_readmem(MAS_BANK_D1
, 0x7f9, &val
, 1);
1098 lcd_puts(0, 0, "LR Gain ");
1099 snprintf(buf
, 32, "1/7f9 %05x", val
& 0xfffff);
1102 mas_readmem(MAS_BANK_D1
, 0x7fa, &val
, 1);
1103 lcd_puts(0, 0, "RL Gain ");
1104 snprintf(buf
, 32, "1/7fa %05x", val
& 0xfffff);
1107 mas_readmem(MAS_BANK_D1
, 0x7fb, &val
, 1);
1108 lcd_puts(0, 0, "RR Gain ");
1109 snprintf(buf
, 32, "1/7fb %05x", val
& 0xfffff);
1112 lcd_puts(0, 0, "L Trailbits");
1113 snprintf(buf
, 32, "c5: %05x ", mas_readreg(0xc5) & 0xfffff);
1116 lcd_puts(0, 0, "R Trailbits");
1117 snprintf(buf
, 32, "c6: %05x ", mas_readreg(0xc6) & 0xfffff);
1120 lcd_puts(0, 1, buf
);
1122 button
= button_get_w_tmo(HZ
/5);
1140 pll_toggle
= !pll_toggle
;
1143 /* 14.31818 MHz crystal */
1150 /* 14.725 MHz crystal */
1155 mas_writemem(MAS_BANK_D0
, 0x32d, &pll48
, 1);
1156 mas_writemem(MAS_BANK_D0
, 0x32e, &pll44
, 1);
1157 mas_writemem(MAS_BANK_D0
, 0x32f, &config
, 1);
1166 static bool view_runtime(void)
1177 lcd_clear_display();
1178 #ifdef HAVE_LCD_BITMAP
1179 lcd_puts(0, y
++, "Running time:");
1184 if (charger_inserted())
1186 global_settings
.runtime
= 0;
1190 global_settings
.runtime
+= ((current_tick
- lasttime
) / HZ
);
1192 lasttime
= current_tick
;
1194 t
= global_settings
.runtime
;
1195 lcd_puts(0, y
++, "Current time");
1198 t
= global_settings
.topruntime
;
1199 lcd_puts(0, y
++, "Top time");
1202 snprintf(s
, sizeof(s
), "%dh %dm %ds",
1203 t
/ 3600, (t
% 3600) / 60, t
% 60);
1204 lcd_puts(0, y
++, s
);
1207 /* Wait for a key to be pushed */
1208 key
= button_get_w_tmo(HZ
);
1210 #if defined(HAVE_PLAYER_KEYPAD) || defined(HAVE_NEO_KEYPAD)
1211 case BUTTON_STOP
| BUTTON_REL
:
1212 #elif HAVE_RECORDER_KEYPAD
1213 case BUTTON_OFF
| BUTTON_REL
:
1227 lcd_clear_display();
1228 lcd_puts(0,0,"Clear time?");
1229 lcd_puts(0,1,"PLAY = Yes");
1232 key
= button_get_w_tmo(HZ
*10);
1233 if ( key
& BUTTON_REL
)
1235 if ( key
== BUTTON_PLAY
) {
1237 global_settings
.runtime
= 0;
1239 global_settings
.topruntime
= 0;
1250 static bool dbg_disk_info(void)
1256 const int max_page
= 11;
1257 unsigned short* identify_info
= ata_get_identify();
1258 bool timing_info_present
= false;
1259 char pio3
[2], pio4
[2];
1261 #ifdef HAVE_LCD_BITMAP
1262 lcd_setmargins(0, 0);
1269 lcd_clear_display();
1270 #ifdef HAVE_LCD_BITMAP
1271 lcd_puts(0, y
++, "Disk info:");
1277 for (i
=0; i
< 20; i
++)
1278 ((unsigned short*)buf
)[i
]=identify_info
[i
+27];
1280 /* kill trailing space */
1281 for (i
=39; i
&& buf
[i
]==' '; i
--)
1283 lcd_puts(0, y
++, "Model");
1284 lcd_puts_scroll(0, y
++, buf
);
1288 for (i
=0; i
< 4; i
++)
1289 ((unsigned short*)buf
)[i
]=identify_info
[i
+23];
1291 lcd_puts(0, y
++, "Firmware");
1292 lcd_puts(0, y
++, buf
);
1296 snprintf(buf
, sizeof buf
, "%d MB",
1297 ((unsigned)identify_info
[61] << 16 |
1298 (unsigned)identify_info
[60]) / 2048 );
1299 lcd_puts(0, y
++, "Size");
1300 lcd_puts(0, y
++, buf
);
1305 fat_size( NULL
, &free
);
1306 snprintf(buf
, sizeof buf
, "%d MB", free
/ 1024 );
1307 lcd_puts(0, y
++, "Free");
1308 lcd_puts(0, y
++, buf
);
1313 snprintf(buf
, sizeof buf
, "%d ms", ata_spinup_time
* (1000/HZ
));
1314 lcd_puts(0, y
++, "Spinup time");
1315 lcd_puts(0, y
++, buf
);
1319 i
= identify_info
[83] & (1<<3);
1320 lcd_puts(0, y
++, "Power mgmt:");
1321 lcd_puts(0, y
++, i
? "enabled" : "unsupported");
1325 i
= identify_info
[83] & (1<<9);
1326 lcd_puts(0, y
++, "Noise mgmt:");
1327 lcd_puts(0, y
++, i
? "enabled" : "unsupported");
1331 i
= identify_info
[82] & (1<<6);
1332 lcd_puts(0, y
++, "Read-ahead:");
1333 lcd_puts(0, y
++, i
? "enabled" : "unsupported");
1337 timing_info_present
= identify_info
[53] & (1<<1);
1338 if(timing_info_present
) {
1341 lcd_puts(0, y
++, "PIO modes:");
1342 pio3
[0] = (identify_info
[64] & (1<<0)) ? '3' : 0;
1343 pio4
[0] = (identify_info
[64] & (1<<1)) ? '4' : 0;
1344 snprintf(buf
, 128, "0 1 2 %s %s", pio3
, pio4
);
1345 lcd_puts(0, y
++, buf
);
1347 lcd_puts(0, y
++, "No PIO mode info");
1352 timing_info_present
= identify_info
[53] & (1<<1);
1353 if(timing_info_present
) {
1354 lcd_puts(0, y
++, "Cycle times");
1355 snprintf(buf
, 128, "%dns/%dns",
1358 lcd_puts(0, y
++, buf
);
1360 lcd_puts(0, y
++, "No timing info");
1365 timing_info_present
= identify_info
[53] & (1<<1);
1366 if(timing_info_present
) {
1367 i
= identify_info
[49] & (1<<11);
1368 snprintf(buf
, 128, "IORDY support: %s", i
? "yes" : "no");
1369 lcd_puts(0, y
++, buf
);
1370 i
= identify_info
[49] & (1<<10);
1371 snprintf(buf
, 128, "IORDY disable: %s", i
? "yes" : "no");
1372 lcd_puts(0, y
++, buf
);
1374 lcd_puts(0, y
++, "No timing info");
1379 lcd_puts(0, y
++, "Cluster size");
1380 snprintf(buf
, 128, "%d bytes", fat_get_cluster_size());
1381 lcd_puts(0, y
++, buf
);
1386 /* Wait for a key to be pushed */
1387 key
= button_get_w_tmo(HZ
*5);
1389 #if defined(HAVE_PLAYER_KEYPAD) || defined(HAVE_NEO_KEYPAD)
1390 case BUTTON_STOP
| BUTTON_REL
:
1392 case BUTTON_OFF
| BUTTON_REL
:
1403 if (++page
> max_page
)
1409 mpeg_stop(); /* stop playback, to avoid disk access */
1410 lcd_clear_display();
1411 lcd_puts(0,0,"Scanning");
1412 lcd_puts(0,1,"disk...");
1424 bool dbg_save_roms(void)
1428 fd
= creat("/internal_rom_0000-FFFF.bin", O_WRONLY
);
1431 write(fd
, (void *)0, 0x10000);
1435 fd
= creat("/internal_rom_2000000-203FFFF.bin", O_WRONLY
);
1438 write(fd
, (void *)0x2000000, 0x40000);
1446 extern int debug_fm_detection
;
1448 bool dbg_fm_radio(void)
1454 #ifdef HAVE_LCD_BITMAP
1455 lcd_setmargins(0, 0);
1460 lcd_clear_display();
1461 fm_detected
= radio_hardware_present();
1463 snprintf(buf
, sizeof buf
, "HW detected: %s", fm_detected
?"yes":"no");
1464 lcd_puts(0, 0, buf
);
1465 snprintf(buf
, sizeof buf
, "Result: %08x", debug_fm_detection
);
1466 lcd_puts(0, 1, buf
);
1469 button
= button_get(true);
1473 #ifdef HAVE_RECORDER_KEYPAD
1485 static bool dbg_sound(void)
1490 long ll
, lr
, rr
, rl
;
1492 #ifdef HAVE_MAS3587F
1497 #ifdef HAVE_LCD_BITMAP
1498 lcd_setmargins(0, 0);
1507 #ifdef HAVE_MAS3587F
1508 /* Set the MDB to the Archos "flat" setting, but not activated */
1509 mas_codec_writereg(MAS_REG_KMDB_STR
, 0);
1510 mas_codec_writereg(MAS_REG_KMDB_HAR
, 0x3000);
1511 mas_codec_writereg(MAS_REG_KMDB_FC
, 0x0600);
1512 mas_codec_writereg(MAS_REG_KMDB_SWITCH
, 0);
1519 #ifdef HAVE_MAS3587F
1520 superbass
= mas_codec_readreg(MAS_REG_KLOUDNESS
) & 0x0004;
1523 lcd_clear_display();
1524 d
= 200 - ll
* 100 / 0x80000;
1526 snprintf(buf
, sizeof buf
, "LL: -%d.%02d (%05x)", i
, d
% 100, ll
);
1527 lcd_puts(0, 0, buf
);
1529 d
= - lr
* 100 / 0x80000;
1531 snprintf(buf
, sizeof buf
, "LR: -%d.%02d (%05x)", i
, d
% 100,
1533 lcd_puts(0, 1, buf
);
1535 #ifdef HAVE_MAS3587F
1537 lcd_puts(0, 2, "Super Bass");
1541 /* Wait for a key to be pushed */
1542 button
= button_get(true);
1544 #if defined(HAVE_PLAYER_KEYPAD) || defined(HAVE_NEO_KEYPAD)
1545 case BUTTON_STOP
| BUTTON_REL
:
1547 case BUTTON_OFF
| BUTTON_REL
:
1553 case BUTTON_LEFT
| BUTTON_REPEAT
:
1565 case BUTTON_RIGHT
| BUTTON_REPEAT
:
1577 if(set
) /* This means that the current config is the
1579 mpeg_sound_set(SOUND_CHANNELS
, MPEG_SOUND_STEREO
);
1584 #ifdef HAVE_MAS3587F
1586 val
= mas_codec_readreg(MAS_REG_KLOUDNESS
);
1588 mas_codec_writereg(MAS_REG_KLOUDNESS
, val
);
1590 mas_codec_writereg(MAS_REG_KMDB_SWITCH
, 0x0902);
1592 mas_codec_writereg(MAS_REG_KMDB_SWITCH
, 0);
1598 #ifdef HAVE_MAS3587F
1599 mas_writemem(MAS_BANK_D0
, 0x7fc, &ll
, 1); /* LL */
1600 mas_writemem(MAS_BANK_D0
, 0x7fd, &lr
, 1); /* LR */
1601 mas_writemem(MAS_BANK_D0
, 0x7fe, &rl
, 1); /* RL */
1602 mas_writemem(MAS_BANK_D0
, 0x7ff, &rr
, 1); /* RR */
1604 mas_writemem(MAS_BANK_D1
, 0x7f8, &ll
, 1); /* LL */
1605 mas_writemem(MAS_BANK_D1
, 0x7f9, &lr
, 1); /* LR */
1606 mas_writemem(MAS_BANK_D1
, 0x7fa, &rl
, 1); /* RL */
1607 mas_writemem(MAS_BANK_D1
, 0x7fb, &rr
, 1); /* RR */
1615 bool debug_menu(void)
1620 struct menu_item items
[] = {
1621 { "Dump ROM contents", -1, dbg_save_roms
},
1622 { "View I/O ports", -1, dbg_ports
},
1623 #ifdef HAVE_LCD_BITMAP
1625 { "View/clr RTC RAM", -1, dbg_rtc
},
1626 #endif /* HAVE_RTC */
1627 #endif /* HAVE_LCD_BITMAP */
1628 { "View OS stacks", -1, dbg_os
},
1629 #ifdef HAVE_MAS3507D
1630 { "View MAS info", -1, dbg_mas_info
},
1632 { "View MAS regs", -1, dbg_mas
},
1633 #ifdef HAVE_MAS3587F
1634 { "View MAS codec", -1, dbg_mas_codec
},
1636 #ifdef HAVE_LCD_BITMAP
1637 { "View battery", -1, view_battery
},
1639 { "View HW info", -1, dbg_hw_info
},
1640 { "View partitions", -1, dbg_partitions
},
1641 { "View disk info", -1, dbg_disk_info
},
1642 #ifdef HAVE_LCD_BITMAP
1643 { "View mpeg thread", -1, dbg_mpeg_thread
},
1645 { "pm histogram", -1, peak_meter_histogram
},
1646 #endif /* PM_DEBUG */
1647 #endif /* HAVE_LCD_BITMAP */
1648 { "View runtime", -1, view_runtime
},
1650 { "FM Radio", -1, dbg_fm_radio
},
1652 { "Sound test", -1, dbg_sound
},
1655 m
=menu_init( items
, sizeof items
/ sizeof(struct menu_item
), NULL
,
1657 result
= menu_run(m
);
1663 #endif /* SIMULATOR */