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
60 lcd_puts(0, 0, "Stack usage:");
61 for(i
= 0; i
< num_threads
;i
++)
63 usage
= thread_stack_usage(i
);
64 snprintf(buf
, 32, "%s: %d%%", thread_name
[i
], usage
);
65 lcd_puts(0, 1+i
, buf
);
71 button
= button_get(false);
93 lcd_puts(0, 0, "Stack usage");
95 usage
= thread_stack_usage(currval
);
96 snprintf(buf
, 32, "%d: %d%% ", currval
, usage
);
101 button
= button_get(false);
111 currval
= num_threads
-1;
116 if(currval
> num_threads
-1)
124 #ifdef HAVE_LCD_BITMAP
128 unsigned short porta
;
129 unsigned short portb
;
134 int batt_int
, batt_frac
;
135 bool charge_status
= false;
136 bool ide_status
= true;
146 snprintf(buf
, 32, "PADR: %04x", porta
);
148 snprintf(buf
, 32, "PBDR: %04x", portb
);
151 snprintf(buf
, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
153 snprintf(buf
, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
155 snprintf(buf
, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
157 snprintf(buf
, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
160 battery_voltage
= (adc_read(ADC_UNREG_POWER
) * BATTERY_SCALE_FACTOR
) / 10000;
161 batt_int
= battery_voltage
/ 100;
162 batt_frac
= battery_voltage
% 100;
164 snprintf(buf
, 32, "Batt: %d.%02dV %d%% ", batt_int
, batt_frac
,
168 snprintf(buf
, 32, "ATA: %s, 0x%x",
169 ata_device
?"slave":"master", ata_io_address
);
175 button
= button_get(false);
180 charge_status
= charge_status
?false:true;
181 charger_enable(charge_status
);
185 ide_status
= ide_status
?false:true;
186 ide_power_enable(ide_status
);
191 charger_enable(false);
192 ide_power_enable(true);
200 unsigned short porta
;
201 unsigned short portb
;
206 int batt_int
, batt_frac
;
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);
290 /* Read RTC RAM contents and display them */
294 unsigned char addr
= 0, r
, c
;
299 lcd_puts(0, 0, "RTC read:");
303 for (r
= 0; r
< 4; r
++) {
304 snprintf(buf
, 10, "0x%02x: ", addr
+ r
*4);
305 for (c
= 0; c
<= 3; c
++) {
306 i
= rtc_read(addr
+ r
*4 + c
);
307 snprintf(buf
+ 6 + c
*2, 3, "%02x", i
);
309 lcd_puts(1, r
+1, buf
);
315 button
= button_get(false);
320 if (addr
< 63-16) { addr
+= 16; }
323 if (addr
) { addr
-= 16; }
326 /* clear the user RAM space */
327 for (c
= 0; c
<= 43; c
++)
328 rtc_write(0x18 + c
, 0);
343 #ifdef HAVE_LCD_CHARCELLS
348 /* Read MAS registers and display them */
352 unsigned int addr
= 0, r
, i
;
355 lcd_puts(0, 0, "MAS register read:");
359 for (r
= 0; r
< NUMROWS
; r
++) {
360 i
= mas_readreg(addr
+ r
);
361 snprintf(buf
, 30, "%02x %08x", addr
+ r
, i
);
362 lcd_puts(0, r
+1, buf
);
368 switch(button_get(false))
370 #ifdef HAVE_RECORDER_KEYPAD
377 #ifdef HAVE_RECORDER_KEYPAD
385 #ifdef HAVE_RECORDER_KEYPAD
396 void dbg_mas_codec(void)
399 unsigned int addr
= 0, r
, i
;
402 lcd_puts(0, 0, "MAS codec reg read:");
406 for (r
= 0; r
< 4; r
++) {
407 i
= mas_codec_readreg(addr
+ r
);
408 snprintf(buf
, 30, "0x%02x: %08x", addr
+ r
, i
);
409 lcd_puts(1, r
+1, buf
);
415 switch(button_get(false))
421 if (addr
) { addr
-= 4; }
430 #ifdef HAVE_LCD_BITMAP
432 * view_battery() shows a automatically scaled graph of the battery voltage
433 * over time. Usable for estimating battery life / charging rate.
434 * The power_history array is updated in power_thread of powermgmt.c.
437 #define BAT_FIRST_VAL MAX(POWER_HISTORY_LEN - LCD_WIDTH - 1, 0)
438 #define BAT_YSPACE (LCD_HEIGHT - 20)
440 void view_battery(void)
450 case 0: /* voltage history graph */
451 /* Find maximum and minimum voltage for scaling */
453 for (i
= BAT_FIRST_VAL
; i
< POWER_HISTORY_LEN
; i
++) {
454 if (power_history
[i
] > maxv
)
455 maxv
= power_history
[i
];
456 if ((minv
== 0) || ((power_history
[i
]) &&
457 (power_history
[i
] < minv
)) )
459 minv
= power_history
[i
];
469 lcd_puts(0, 0, "Battery voltage:");
470 snprintf(buf
, 30, "scale %d.%02d-%d.%02d V",
471 minv
/ 100, minv
% 100, maxv
/ 100, maxv
% 100);
475 for (i
= BAT_FIRST_VAL
+1; i
< POWER_HISTORY_LEN
; i
++) {
476 y
= (power_history
[i
] - minv
) * BAT_YSPACE
/ (maxv
- minv
);
477 lcd_clearline(x
, LCD_HEIGHT
-1, x
, 20);
478 lcd_drawline(x
, LCD_HEIGHT
-1, x
,
479 MIN(MAX(LCD_HEIGHT
-1 - y
, 20), LCD_HEIGHT
-1));
485 case 1: /* status: */
487 lcd_puts(0, 0, "Power status:");
489 y
= (adc_read(ADC_UNREG_POWER
) * BATTERY_SCALE_FACTOR
) / 10000;
490 snprintf(buf
, 30, "Battery: %d.%02d V", y
/ 100, y
% 100);
492 y
= (adc_read(ADC_EXT_POWER
) * EXT_SCALE_FACTOR
) / 10000;
493 snprintf(buf
, 30, "External: %d.%02d V", y
/ 100, y
% 100);
495 snprintf(buf
, 30, "Charger: %s",
496 charger_inserted() ? "present" : "absent");
498 #ifdef HAVE_CHARGE_CTRL
499 snprintf(buf
, 30, "Charging: %s",
500 charger_enabled
? "yes" : "no");
503 y
= ( power_history
[POWER_HISTORY_LEN
-1] * 100
504 - power_history
[POWER_HISTORY_LEN
-1-CHARGE_END_NEGD
] * 100 )
507 snprintf(buf
, 30, "short delta: %d", y
);
510 y
= ( power_history
[POWER_HISTORY_LEN
-1] * 100
511 - power_history
[POWER_HISTORY_LEN
-1-CHARGE_END_ZEROD
] * 100 )
514 snprintf(buf
, 30, "long delta: %d", y
);
517 #ifdef HAVE_CHARGE_CTRL
518 lcd_puts(0, 7, power_message
);
522 case 2: /* voltage deltas: */
524 lcd_puts(0, 0, "Voltage deltas:");
526 for (i
= 0; i
<= 6; i
++) {
527 y
= power_history
[POWER_HISTORY_LEN
-1-i
] -
528 power_history
[POWER_HISTORY_LEN
-1-i
-1];
529 snprintf(buf
, 30, "-%d min: %s%d.%02d V", i
,
530 (y
< 0) ? "-" : "", ((y
< 0) ? y
* -1 : y
) / 100,
531 ((y
< 0) ? y
* -1 : y
) % 100);
532 lcd_puts(0, i
+1, buf
);
540 switch(button_get(false))
562 void dbg_mas_info(void)
568 unsigned long pll48
, pll44
, config
;
576 mas_readmem(MAS_BANK_D1
, 0xff7, &val
, 1);
577 lcd_puts(0, 0, "Design Code");
578 snprintf(buf
, 32, "%05x ", val
);
581 lcd_puts(0, 0, "DC/DC mode ");
582 snprintf(buf
, 32, "8e: %05x ", mas_readreg(0x8e) & 0xfffff);
585 lcd_puts(0, 0, "Mute/Bypass");
586 snprintf(buf
, 32, "aa: %05x ", mas_readreg(0xaa) & 0xfffff);
589 lcd_puts(0, 0, "PIOData ");
590 snprintf(buf
, 32, "ed: %05x ", mas_readreg(0xed) & 0xfffff);
593 lcd_puts(0, 0, "Startup Cfg");
594 snprintf(buf
, 32, "e6: %05x ", mas_readreg(0xe6) & 0xfffff);
597 lcd_puts(0, 0, "KPrescale ");
598 snprintf(buf
, 32, "e7: %05x ", mas_readreg(0xe7) & 0xfffff);
601 lcd_puts(0, 0, "KBass ");
602 snprintf(buf
, 32, "6b: %05x ", mas_readreg(0x6b) & 0xfffff);
605 lcd_puts(0, 0, "KTreble ");
606 snprintf(buf
, 32, "6f: %05x ", mas_readreg(0x6f) & 0xfffff);
609 mas_readmem(MAS_BANK_D0
, 0x300, &val
, 1);
610 lcd_puts(0, 0, "Frame Count");
611 snprintf(buf
, 32, "0/300: %04x", val
& 0xffff);
614 mas_readmem(MAS_BANK_D0
, 0x301, &val
, 1);
615 lcd_puts(0, 0, "Status1 ");
616 snprintf(buf
, 32, "0/301: %04x", val
& 0xffff);
619 mas_readmem(MAS_BANK_D0
, 0x302, &val
, 1);
620 lcd_puts(0, 0, "Status2 ");
621 snprintf(buf
, 32, "0/302: %04x", val
& 0xffff);
624 mas_readmem(MAS_BANK_D0
, 0x303, &val
, 1);
625 lcd_puts(0, 0, "CRC Count ");
626 snprintf(buf
, 32, "0/303: %04x", val
& 0xffff);
629 mas_readmem(MAS_BANK_D0
, 0x36d, &val
, 1);
630 lcd_puts(0, 0, "PLLOffset48");
631 snprintf(buf
, 32, "0/36d %05x", val
& 0xfffff);
634 mas_readmem(MAS_BANK_D0
, 0x32d, &val
, 1);
635 lcd_puts(0, 0, "PLLOffset48");
636 snprintf(buf
, 32, "0/32d %05x", val
& 0xfffff);
639 mas_readmem(MAS_BANK_D0
, 0x36e, &val
, 1);
640 lcd_puts(0, 0, "PLLOffset44");
641 snprintf(buf
, 32, "0/36e %05x", val
& 0xfffff);
644 mas_readmem(MAS_BANK_D0
, 0x32e, &val
, 1);
645 lcd_puts(0, 0, "PLLOffset44");
646 snprintf(buf
, 32, "0/32e %05x", val
& 0xfffff);
649 mas_readmem(MAS_BANK_D0
, 0x36f, &val
, 1);
650 lcd_puts(0, 0, "OutputConf ");
651 snprintf(buf
, 32, "0/36f %05x", val
& 0xfffff);
654 mas_readmem(MAS_BANK_D0
, 0x32f, &val
, 1);
655 lcd_puts(0, 0, "OutputConf ");
656 snprintf(buf
, 32, "0/32f %05x", val
& 0xfffff);
659 mas_readmem(MAS_BANK_D1
, 0x7f8, &val
, 1);
660 lcd_puts(0, 0, "LL Gain ");
661 snprintf(buf
, 32, "1/7f8 %05x", val
& 0xfffff);
664 mas_readmem(MAS_BANK_D1
, 0x7f9, &val
, 1);
665 lcd_puts(0, 0, "LR Gain ");
666 snprintf(buf
, 32, "1/7f9 %05x", val
& 0xfffff);
669 mas_readmem(MAS_BANK_D1
, 0x7fa, &val
, 1);
670 lcd_puts(0, 0, "RL Gain ");
671 snprintf(buf
, 32, "1/7fa %05x", val
& 0xfffff);
674 mas_readmem(MAS_BANK_D1
, 0x7fb, &val
, 1);
675 lcd_puts(0, 0, "RR Gain ");
676 snprintf(buf
, 32, "1/7fb %05x", val
& 0xfffff);
679 lcd_puts(0, 0, "L Trailbits");
680 snprintf(buf
, 32, "c5: %05x ", mas_readreg(0xc5) & 0xfffff);
683 lcd_puts(0, 0, "R Trailbits");
684 snprintf(buf
, 32, "c6: %05x ", mas_readreg(0xc6) & 0xfffff);
689 button
= button_get_w_tmo(HZ
/5);
707 pll_toggle
= !pll_toggle
;
710 /* 14.31818 MHz crystal */
717 /* 14.725 MHz crystal */
722 mas_writemem(MAS_BANK_D0
, 0x32d, &pll48
, 1);
723 mas_writemem(MAS_BANK_D0
, 0x32e, &pll44
, 1);
724 mas_writemem(MAS_BANK_D0
, 0x32f, &config
, 1);
732 void debug_menu(void)
736 struct menu_items items
[] = {
737 { "View I/O ports", dbg_ports
},
738 #ifdef HAVE_LCD_BITMAP
740 { "View/clr RTC RAM", dbg_rtc
},
741 #endif /* HAVE_RTC */
742 #endif /* HAVE_LCD_BITMAP */
743 { "View OS stacks", dbg_os
},
745 { "View MAS info", dbg_mas_info
},
747 { "View MAS regs", dbg_mas
},
749 { "View MAS codec", dbg_mas_codec
},
751 #ifdef HAVE_LCD_BITMAP
752 { "View battery", view_battery
},
756 m
=menu_init( items
, sizeof items
/ sizeof(struct menu_items
) );
761 #endif /* SIMULATOR */