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"
36 #include "powermgmt.h"
39 /*---------------------------------------------------*/
40 /* SPECIAL DEBUG STUFF */
41 /*---------------------------------------------------*/
42 extern int ata_device
;
43 extern int ata_io_address
;
44 extern int num_threads
;
45 extern char *thread_name
[];
47 #ifdef HAVE_LCD_BITMAP
56 #ifdef HAVE_LCD_BITMAP
63 lcd_puts(0, 0, "Stack usage:");
64 for(i
= 0; i
< num_threads
;i
++)
66 usage
= thread_stack_usage(i
);
67 snprintf(buf
, 32, "%s: %d%%", thread_name
[i
], usage
);
68 lcd_puts(0, 1+i
, buf
);
74 button
= button_get(false);
93 #ifdef HAVE_LCD_BITMAP
100 lcd_puts(0, 0, "Stack usage");
102 usage
= thread_stack_usage(currval
);
103 snprintf(buf
, 32, "%d: %d%% ", currval
, usage
);
108 button
= button_get(false);
118 currval
= num_threads
-1;
123 if(currval
> num_threads
-1)
132 #ifdef HAVE_LCD_BITMAP
136 unsigned short porta
;
137 unsigned short portb
;
142 int batt_int
, batt_frac
;
144 #ifdef HAVE_LCD_BITMAP
145 lcd_setmargins(0, 0);
155 snprintf(buf
, 32, "PADR: %04x", porta
);
157 snprintf(buf
, 32, "PBDR: %04x", portb
);
160 snprintf(buf
, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
162 snprintf(buf
, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
164 snprintf(buf
, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
166 snprintf(buf
, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
169 battery_voltage
= (adc_read(ADC_UNREG_POWER
) * BATTERY_SCALE_FACTOR
) / 10000;
170 batt_int
= battery_voltage
/ 100;
171 batt_frac
= battery_voltage
% 100;
173 snprintf(buf
, 32, "Batt: %d.%02dV %d%% ", batt_int
, batt_frac
,
177 snprintf(buf
, 32, "ATA: %s, 0x%x",
178 ata_device
?"slave":"master", ata_io_address
);
184 button
= button_get(false);
197 unsigned short porta
;
198 unsigned short portb
;
203 int batt_int
, batt_frac
;
206 #ifdef HAVE_LCD_BITMAP
207 lcd_setmargins(0, 0);
220 snprintf(buf
, 32, "PADR: %04x ", porta
);
223 snprintf(buf
, 32, "PBDR: %04x ", portb
);
226 snprintf(buf
, 32, "AN0: %03x ", adc_read(0));
229 snprintf(buf
, 32, "AN1: %03x ", adc_read(1));
232 snprintf(buf
, 32, "AN2: %03x ", adc_read(2));
235 snprintf(buf
, 32, "AN3: %03x ", adc_read(3));
238 snprintf(buf
, 32, "AN4: %03x ", adc_read(4));
241 snprintf(buf
, 32, "AN5: %03x ", adc_read(5));
244 snprintf(buf
, 32, "AN6: %03x ", adc_read(6));
247 snprintf(buf
, 32, "AN7: %03x ", adc_read(7));
250 snprintf(buf
, 32, "%s, 0x%x ",
251 ata_device
?"slv":"mst", ata_io_address
);
256 battery_voltage
= (adc_read(ADC_UNREG_POWER
) *
257 BATTERY_SCALE_FACTOR
) / 10000;
258 batt_int
= battery_voltage
/ 100;
259 batt_frac
= battery_voltage
% 100;
261 snprintf(buf
, 32, "Batt: %d.%02dV", batt_int
, batt_frac
);
266 button
= button_get(false);
291 /* Read RTC RAM contents and display them */
295 unsigned char addr
= 0, r
, c
;
299 #ifdef HAVE_LCD_BITMAP
300 lcd_setmargins(0, 0);
303 lcd_puts(0, 0, "RTC read:");
307 for (r
= 0; r
< 4; r
++) {
308 snprintf(buf
, 10, "0x%02x: ", addr
+ r
*4);
309 for (c
= 0; c
<= 3; c
++) {
310 i
= rtc_read(addr
+ r
*4 + c
);
311 snprintf(buf
+ 6 + c
*2, 3, "%02x", i
);
313 lcd_puts(1, r
+1, buf
);
319 button
= button_get(false);
324 if (addr
< 63-16) { addr
+= 16; }
327 if (addr
) { addr
-= 16; }
330 /* clear the user RAM space */
331 for (c
= 0; c
<= 43; c
++)
332 rtc_write(0x14 + c
, 0);
348 #ifdef HAVE_LCD_CHARCELLS
353 /* Read MAS registers and display them */
357 unsigned int addr
= 0, r
, i
;
359 #ifdef HAVE_LCD_BITMAP
360 lcd_setmargins(0, 0);
363 lcd_puts(0, 0, "MAS register read:");
367 for (r
= 0; r
< NUMROWS
; r
++) {
368 i
= mas_readreg(addr
+ r
);
369 snprintf(buf
, 30, "%02x %08x", addr
+ r
, i
);
370 lcd_puts(0, r
+1, buf
);
376 switch(button_get(false))
378 #ifdef HAVE_RECORDER_KEYPAD
385 #ifdef HAVE_RECORDER_KEYPAD
393 #ifdef HAVE_RECORDER_KEYPAD
405 Menu
dbg_mas_codec(void)
408 unsigned int addr
= 0, r
, i
;
410 #ifdef HAVE_LCD_BITMAP
411 lcd_setmargins(0, 0);
414 lcd_puts(0, 0, "MAS codec reg read:");
418 for (r
= 0; r
< 4; r
++) {
419 i
= mas_codec_readreg(addr
+ r
);
420 snprintf(buf
, 30, "0x%02x: %08x", addr
+ r
, i
);
421 lcd_puts(1, r
+1, buf
);
427 switch(button_get(false))
433 if (addr
) { addr
-= 4; }
443 #ifdef HAVE_LCD_BITMAP
445 * view_battery() shows a automatically scaled graph of the battery voltage
446 * over time. Usable for estimating battery life / charging rate.
447 * The power_history array is updated in power_thread of powermgmt.c.
450 #define BAT_FIRST_VAL MAX(POWER_HISTORY_LEN - LCD_WIDTH - 1, 0)
451 #define BAT_YSPACE (LCD_HEIGHT - 20)
453 Menu
view_battery(void)
460 #ifdef HAVE_LCD_BITMAP
461 lcd_setmargins(0, 0);
466 case 0: /* voltage history graph */
467 /* Find maximum and minimum voltage for scaling */
469 for (i
= BAT_FIRST_VAL
; i
< POWER_HISTORY_LEN
; i
++) {
470 if (power_history
[i
] > maxv
)
471 maxv
= power_history
[i
];
472 if ((minv
== 0) || ((power_history
[i
]) &&
473 (power_history
[i
] < minv
)) )
475 minv
= power_history
[i
];
485 lcd_puts(0, 0, "Battery voltage:");
486 snprintf(buf
, 30, "scale %d.%02d-%d.%02d V",
487 minv
/ 100, minv
% 100, maxv
/ 100, maxv
% 100);
491 for (i
= BAT_FIRST_VAL
+1; i
< POWER_HISTORY_LEN
; i
++) {
492 y
= (power_history
[i
] - minv
) * BAT_YSPACE
/ (maxv
- minv
);
493 lcd_clearline(x
, LCD_HEIGHT
-1, x
, 20);
494 lcd_drawline(x
, LCD_HEIGHT
-1, x
,
495 MIN(MAX(LCD_HEIGHT
-1 - y
, 20), LCD_HEIGHT
-1));
501 case 1: /* status: */
503 lcd_puts(0, 0, "Power status:");
505 y
= (adc_read(ADC_UNREG_POWER
) * BATTERY_SCALE_FACTOR
) / 10000;
506 snprintf(buf
, 30, "Battery: %d.%02d V", y
/ 100, y
% 100);
508 y
= (adc_read(ADC_EXT_POWER
) * EXT_SCALE_FACTOR
) / 10000;
509 snprintf(buf
, 30, "External: %d.%02d V", y
/ 100, y
% 100);
511 snprintf(buf
, 30, "Charger: %s",
512 charger_inserted() ? "present" : "absent");
514 #ifdef HAVE_CHARGE_CTRL
515 snprintf(buf
, 30, "Charging: %s",
516 charger_enabled
? "yes" : "no");
519 y
= ( power_history
[POWER_HISTORY_LEN
-1] * 100
520 + power_history
[POWER_HISTORY_LEN
-2] * 100
521 - power_history
[POWER_HISTORY_LEN
-1-CHARGE_END_NEGD
+1] * 100
522 - power_history
[POWER_HISTORY_LEN
-1-CHARGE_END_NEGD
] * 100 )
523 / CHARGE_END_NEGD
/ 2;
525 snprintf(buf
, 30, "short delta: %d", y
);
528 y
= ( power_history
[POWER_HISTORY_LEN
-1] * 100
529 + power_history
[POWER_HISTORY_LEN
-2] * 100
530 - power_history
[POWER_HISTORY_LEN
-1-CHARGE_END_ZEROD
+1] * 100
531 - power_history
[POWER_HISTORY_LEN
-1-CHARGE_END_ZEROD
] * 100 )
532 / CHARGE_END_ZEROD
/ 2;
534 snprintf(buf
, 30, "long delta: %d", y
);
537 #ifdef HAVE_CHARGE_CTRL
538 lcd_puts(0, 7, power_message
);
542 case 2: /* voltage deltas: */
544 lcd_puts(0, 0, "Voltage deltas:");
546 for (i
= 0; i
<= 6; i
++) {
547 y
= power_history
[POWER_HISTORY_LEN
-1-i
] -
548 power_history
[POWER_HISTORY_LEN
-1-i
-1];
549 snprintf(buf
, 30, "-%d min: %s%d.%02d V", i
,
550 (y
< 0) ? "-" : "", ((y
< 0) ? y
* -1 : y
) / 100,
551 ((y
< 0) ? y
* -1 : y
) % 100);
552 lcd_puts(0, i
+1, buf
);
560 switch(button_get(false))
583 Menu
dbg_mas_info(void)
589 unsigned long pll48
, pll44
, config
;
592 #ifdef HAVE_LCD_BITMAP
593 lcd_setmargins(0, 0);
600 mas_readmem(MAS_BANK_D1
, 0xff7, &val
, 1);
601 lcd_puts(0, 0, "Design Code");
602 snprintf(buf
, 32, "%05x ", val
);
605 lcd_puts(0, 0, "DC/DC mode ");
606 snprintf(buf
, 32, "8e: %05x ", mas_readreg(0x8e) & 0xfffff);
609 lcd_puts(0, 0, "Mute/Bypass");
610 snprintf(buf
, 32, "aa: %05x ", mas_readreg(0xaa) & 0xfffff);
613 lcd_puts(0, 0, "PIOData ");
614 snprintf(buf
, 32, "ed: %05x ", mas_readreg(0xed) & 0xfffff);
617 lcd_puts(0, 0, "Startup Cfg");
618 snprintf(buf
, 32, "e6: %05x ", mas_readreg(0xe6) & 0xfffff);
621 lcd_puts(0, 0, "KPrescale ");
622 snprintf(buf
, 32, "e7: %05x ", mas_readreg(0xe7) & 0xfffff);
625 lcd_puts(0, 0, "KBass ");
626 snprintf(buf
, 32, "6b: %05x ", mas_readreg(0x6b) & 0xfffff);
629 lcd_puts(0, 0, "KTreble ");
630 snprintf(buf
, 32, "6f: %05x ", mas_readreg(0x6f) & 0xfffff);
633 mas_readmem(MAS_BANK_D0
, 0x300, &val
, 1);
634 lcd_puts(0, 0, "Frame Count");
635 snprintf(buf
, 32, "0/300: %04x", val
& 0xffff);
638 mas_readmem(MAS_BANK_D0
, 0x301, &val
, 1);
639 lcd_puts(0, 0, "Status1 ");
640 snprintf(buf
, 32, "0/301: %04x", val
& 0xffff);
643 mas_readmem(MAS_BANK_D0
, 0x302, &val
, 1);
644 lcd_puts(0, 0, "Status2 ");
645 snprintf(buf
, 32, "0/302: %04x", val
& 0xffff);
648 mas_readmem(MAS_BANK_D0
, 0x303, &val
, 1);
649 lcd_puts(0, 0, "CRC Count ");
650 snprintf(buf
, 32, "0/303: %04x", val
& 0xffff);
653 mas_readmem(MAS_BANK_D0
, 0x36d, &val
, 1);
654 lcd_puts(0, 0, "PLLOffset48");
655 snprintf(buf
, 32, "0/36d %05x", val
& 0xfffff);
658 mas_readmem(MAS_BANK_D0
, 0x32d, &val
, 1);
659 lcd_puts(0, 0, "PLLOffset48");
660 snprintf(buf
, 32, "0/32d %05x", val
& 0xfffff);
663 mas_readmem(MAS_BANK_D0
, 0x36e, &val
, 1);
664 lcd_puts(0, 0, "PLLOffset44");
665 snprintf(buf
, 32, "0/36e %05x", val
& 0xfffff);
668 mas_readmem(MAS_BANK_D0
, 0x32e, &val
, 1);
669 lcd_puts(0, 0, "PLLOffset44");
670 snprintf(buf
, 32, "0/32e %05x", val
& 0xfffff);
673 mas_readmem(MAS_BANK_D0
, 0x36f, &val
, 1);
674 lcd_puts(0, 0, "OutputConf ");
675 snprintf(buf
, 32, "0/36f %05x", val
& 0xfffff);
678 mas_readmem(MAS_BANK_D0
, 0x32f, &val
, 1);
679 lcd_puts(0, 0, "OutputConf ");
680 snprintf(buf
, 32, "0/32f %05x", val
& 0xfffff);
683 mas_readmem(MAS_BANK_D1
, 0x7f8, &val
, 1);
684 lcd_puts(0, 0, "LL Gain ");
685 snprintf(buf
, 32, "1/7f8 %05x", val
& 0xfffff);
688 mas_readmem(MAS_BANK_D1
, 0x7f9, &val
, 1);
689 lcd_puts(0, 0, "LR Gain ");
690 snprintf(buf
, 32, "1/7f9 %05x", val
& 0xfffff);
693 mas_readmem(MAS_BANK_D1
, 0x7fa, &val
, 1);
694 lcd_puts(0, 0, "RL Gain ");
695 snprintf(buf
, 32, "1/7fa %05x", val
& 0xfffff);
698 mas_readmem(MAS_BANK_D1
, 0x7fb, &val
, 1);
699 lcd_puts(0, 0, "RR Gain ");
700 snprintf(buf
, 32, "1/7fb %05x", val
& 0xfffff);
703 lcd_puts(0, 0, "L Trailbits");
704 snprintf(buf
, 32, "c5: %05x ", mas_readreg(0xc5) & 0xfffff);
707 lcd_puts(0, 0, "R Trailbits");
708 snprintf(buf
, 32, "c6: %05x ", mas_readreg(0xc6) & 0xfffff);
713 button
= button_get_w_tmo(HZ
/5);
731 pll_toggle
= !pll_toggle
;
734 /* 14.31818 MHz crystal */
741 /* 14.725 MHz crystal */
746 mas_writemem(MAS_BANK_D0
, 0x32d, &pll48
, 1);
747 mas_writemem(MAS_BANK_D0
, 0x32e, &pll44
, 1);
748 mas_writemem(MAS_BANK_D0
, 0x32f, &config
, 1);
757 Menu
debug_menu(void)
762 struct menu_items items
[] = {
763 { "View I/O ports", dbg_ports
},
764 #ifdef HAVE_LCD_BITMAP
766 { "View/clr RTC RAM", dbg_rtc
},
767 #endif /* HAVE_RTC */
768 #endif /* HAVE_LCD_BITMAP */
769 { "View OS stacks", dbg_os
},
771 { "View MAS info", dbg_mas_info
},
773 { "View MAS regs", dbg_mas
},
775 { "View MAS codec", dbg_mas_codec
},
777 #ifdef HAVE_LCD_BITMAP
778 { "View battery", view_battery
},
782 m
=menu_init( items
, sizeof items
/ sizeof(struct menu_items
) );
783 result
= menu_run(m
);
789 #endif /* SIMULATOR */