removed entry for status bar
[kugel-rb.git] / apps / debug_menu.c
blob252c3e20d503abb359cb4c8217305db4eb1d4035
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
20 #include "config.h"
21 #ifndef SIMULATOR
22 #include <stdio.h>
23 #include <stdbool.h>
24 #include "lcd.h"
25 #include "menu.h"
26 #include "debug_menu.h"
27 #include "kernel.h"
28 #include "sprintf.h"
29 #include "button.h"
30 #include "adc.h"
31 #include "mas.h"
32 #include "power.h"
33 #include "rtc.h"
34 #include "debug.h"
35 #include "thread.h"
36 #include "powermgmt.h"
37 #include "system.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
48 /* Test code!!! */
49 void dbg_os(void)
51 char buf[32];
52 int button;
53 int i;
54 int usage;
56 lcd_clear_display();
58 while(1)
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);
68 lcd_update();
69 sleep(HZ/10);
71 button = button_get(false);
73 switch(button)
75 case BUTTON_OFF:
76 case BUTTON_LEFT:
77 return;
81 #else
82 void dbg_os(void)
84 char buf[32];
85 int button;
86 int usage;
87 int currval = 0;
89 lcd_clear_display();
91 while(1)
93 lcd_puts(0, 0, "Stack usage");
95 usage = thread_stack_usage(currval);
96 snprintf(buf, 32, "%d: %d%% ", currval, usage);
97 lcd_puts(0, 1, buf);
99 sleep(HZ/10);
101 button = button_get(false);
103 switch(button)
105 case BUTTON_STOP:
106 return;
108 case BUTTON_LEFT:
109 currval--;
110 if(currval < 0)
111 currval = num_threads-1;
112 break;
114 case BUTTON_RIGHT:
115 currval++;
116 if(currval > num_threads-1)
117 currval = 0;
118 break;
122 #endif
124 #ifdef HAVE_LCD_BITMAP
125 /* Test code!!! */
126 void dbg_ports(void)
128 unsigned short porta;
129 unsigned short portb;
130 unsigned char portc;
131 char buf[32];
132 int button;
133 int battery_voltage;
134 int batt_int, batt_frac;
135 bool charge_status = false;
136 bool ide_status = true;
138 lcd_clear_display();
140 while(1)
142 porta = PADR;
143 portb = PBDR;
144 portc = PCDR;
146 snprintf(buf, 32, "PADR: %04x", porta);
147 lcd_puts(0, 0, buf);
148 snprintf(buf, 32, "PBDR: %04x", portb);
149 lcd_puts(0, 1, buf);
151 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
152 lcd_puts(0, 2, buf);
153 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
154 lcd_puts(0, 3, buf);
155 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
156 lcd_puts(0, 4, buf);
157 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
158 lcd_puts(0, 5, buf);
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,
165 battery_level());
166 lcd_puts(0, 6, buf);
168 snprintf(buf, 32, "ATA: %s, 0x%x",
169 ata_device?"slave":"master", ata_io_address);
170 lcd_puts(0, 7, buf);
172 lcd_update();
173 sleep(HZ/10);
175 button = button_get(false);
177 switch(button)
179 case BUTTON_ON:
180 charge_status = charge_status?false:true;
181 charger_enable(charge_status);
182 break;
184 case BUTTON_UP:
185 ide_status = ide_status?false:true;
186 ide_power_enable(ide_status);
187 break;
189 case BUTTON_OFF:
190 case BUTTON_LEFT:
191 charger_enable(false);
192 ide_power_enable(true);
193 return;
197 #else
198 void dbg_ports(void)
200 unsigned short porta;
201 unsigned short portb;
202 unsigned char portc;
203 char buf[32];
204 int button;
205 int battery_voltage;
206 int batt_int, batt_frac;
207 int currval = 0;
209 lcd_clear_display();
211 while(1)
213 porta = PADR;
214 portb = PBDR;
215 portc = PCDR;
217 switch(currval)
219 case 0:
220 snprintf(buf, 32, "PADR: %04x ", porta);
221 break;
222 case 1:
223 snprintf(buf, 32, "PBDR: %04x ", portb);
224 break;
225 case 2:
226 snprintf(buf, 32, "AN0: %03x ", adc_read(0));
227 break;
228 case 3:
229 snprintf(buf, 32, "AN1: %03x ", adc_read(1));
230 break;
231 case 4:
232 snprintf(buf, 32, "AN2: %03x ", adc_read(2));
233 break;
234 case 5:
235 snprintf(buf, 32, "AN3: %03x ", adc_read(3));
236 break;
237 case 6:
238 snprintf(buf, 32, "AN4: %03x ", adc_read(4));
239 break;
240 case 7:
241 snprintf(buf, 32, "AN5: %03x ", adc_read(5));
242 break;
243 case 8:
244 snprintf(buf, 32, "AN6: %03x ", adc_read(6));
245 break;
246 case 9:
247 snprintf(buf, 32, "AN7: %03x ", adc_read(7));
248 break;
249 case 10:
250 snprintf(buf, 32, "%s, 0x%x ",
251 ata_device?"slv":"mst", ata_io_address);
252 break;
254 lcd_puts(0, 0, buf);
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);
262 lcd_puts(0, 1, buf);
264 sleep(HZ/5);
266 button = button_get(false);
268 switch(button)
270 case BUTTON_STOP:
271 return;
273 case BUTTON_LEFT:
274 currval--;
275 if(currval < 0)
276 currval = 10;
277 break;
279 case BUTTON_RIGHT:
280 currval++;
281 if(currval > 10)
282 currval = 0;
283 break;
287 #endif
289 #ifdef HAVE_RTC
290 /* Read RTC RAM contents and display them */
291 void dbg_rtc(void)
293 char buf[32];
294 unsigned char addr = 0, r, c;
295 int i;
296 int button;
298 lcd_clear_display();
299 lcd_puts(0, 0, "RTC read:");
301 while(1)
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);
312 lcd_update();
313 sleep(HZ/2);
315 button = button_get(false);
317 switch(button)
319 case BUTTON_DOWN:
320 if (addr < 63-16) { addr += 16; }
321 break;
322 case BUTTON_UP:
323 if (addr) { addr -= 16; }
324 break;
325 case BUTTON_F2:
326 /* clear the user RAM space */
327 for (c = 0; c <= 43; c++)
328 rtc_write(0x18 + c, 0);
329 break;
330 case BUTTON_OFF:
331 case BUTTON_LEFT:
332 return;
336 #else
337 void dbg_rtc(void)
339 return;
341 #endif
343 #ifdef HAVE_LCD_CHARCELLS
344 #define NUMROWS 1
345 #else
346 #define NUMROWS 4
347 #endif
348 /* Read MAS registers and display them */
349 void dbg_mas(void)
351 char buf[32];
352 unsigned int addr = 0, r, i;
354 lcd_clear_display();
355 lcd_puts(0, 0, "MAS register read:");
357 while(1)
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);
365 lcd_update();
366 sleep(HZ/16);
368 switch(button_get(false))
370 #ifdef HAVE_RECORDER_KEYPAD
371 case BUTTON_DOWN:
372 #else
373 case BUTTON_RIGHT:
374 #endif
375 addr += NUMROWS;
376 break;
377 #ifdef HAVE_RECORDER_KEYPAD
378 case BUTTON_UP:
379 #else
380 case BUTTON_LEFT:
381 #endif
382 if(addr)
383 addr -= NUMROWS;
384 break;
385 #ifdef HAVE_RECORDER_KEYPAD
386 case BUTTON_LEFT:
387 #else
388 case BUTTON_DOWN:
389 #endif
390 return;
395 #ifdef HAVE_MAS3587F
396 void dbg_mas_codec(void)
398 char buf[32];
399 unsigned int addr = 0, r, i;
401 lcd_clear_display();
402 lcd_puts(0, 0, "MAS codec reg read:");
404 while(1)
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);
412 lcd_update();
413 sleep(HZ/16);
415 switch(button_get(false))
417 case BUTTON_DOWN:
418 addr += 4;
419 break;
420 case BUTTON_UP:
421 if (addr) { addr -= 4; }
422 break;
423 case BUTTON_LEFT:
424 return;
428 #endif
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)
442 int view = 0;
443 int i, x, y;
444 int maxv, minv;
445 char buf[32];
447 while(1)
449 switch (view) {
450 case 0: /* voltage history graph */
451 /* Find maximum and minimum voltage for scaling */
452 maxv = minv = 0;
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];
463 if (minv < 1)
464 minv = 1;
465 if (maxv < 2)
466 maxv = 2;
468 lcd_clear_display();
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);
472 lcd_puts(0, 1, buf);
474 x = 0;
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));
480 x++;
483 break;
485 case 1: /* status: */
486 lcd_clear_display();
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);
491 lcd_puts(0, 1, buf);
492 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000;
493 snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100);
494 lcd_puts(0, 2, buf);
495 snprintf(buf, 30, "Charger: %s",
496 charger_inserted() ? "present" : "absent");
497 lcd_puts(0, 3, buf);
498 #ifdef HAVE_CHARGE_CTRL
499 snprintf(buf, 30, "Charging: %s",
500 charger_enabled ? "yes" : "no");
501 lcd_puts(0, 4, buf);
502 #endif
503 y = ( power_history[POWER_HISTORY_LEN-1] * 100
504 - power_history[POWER_HISTORY_LEN-1-CHARGE_END_NEGD] * 100 )
505 / CHARGE_END_NEGD;
507 snprintf(buf, 30, "short delta: %d", y);
508 lcd_puts(0, 5, buf);
510 y = ( power_history[POWER_HISTORY_LEN-1] * 100
511 - power_history[POWER_HISTORY_LEN-1-CHARGE_END_ZEROD] * 100 )
512 / CHARGE_END_ZEROD;
514 snprintf(buf, 30, "long delta: %d", y);
515 lcd_puts(0, 6, buf);
517 #ifdef HAVE_CHARGE_CTRL
518 lcd_puts(0, 7, power_message);
519 #endif
520 break;
522 case 2: /* voltage deltas: */
523 lcd_clear_display();
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);
534 break;
537 lcd_update();
538 sleep(HZ/2);
540 switch(button_get(false))
542 case BUTTON_UP:
543 if (view)
544 view--;
545 break;
547 case BUTTON_DOWN:
548 if (view < 2)
549 view++;
550 break;
552 case BUTTON_LEFT:
553 case BUTTON_OFF:
554 return;
559 #endif
561 #ifdef HAVE_MAS3507D
562 void dbg_mas_info(void)
564 int button;
565 char buf[32];
566 int currval = 0;
567 unsigned long val;
568 unsigned long pll48, pll44, config;
569 int pll_toggle = 0;
571 while(1)
573 switch(currval)
575 case 0:
576 mas_readmem(MAS_BANK_D1, 0xff7, &val, 1);
577 lcd_puts(0, 0, "Design Code");
578 snprintf(buf, 32, "%05x ", val);
579 break;
580 case 1:
581 lcd_puts(0, 0, "DC/DC mode ");
582 snprintf(buf, 32, "8e: %05x ", mas_readreg(0x8e) & 0xfffff);
583 break;
584 case 2:
585 lcd_puts(0, 0, "Mute/Bypass");
586 snprintf(buf, 32, "aa: %05x ", mas_readreg(0xaa) & 0xfffff);
587 break;
588 case 3:
589 lcd_puts(0, 0, "PIOData ");
590 snprintf(buf, 32, "ed: %05x ", mas_readreg(0xed) & 0xfffff);
591 break;
592 case 4:
593 lcd_puts(0, 0, "Startup Cfg");
594 snprintf(buf, 32, "e6: %05x ", mas_readreg(0xe6) & 0xfffff);
595 break;
596 case 5:
597 lcd_puts(0, 0, "KPrescale ");
598 snprintf(buf, 32, "e7: %05x ", mas_readreg(0xe7) & 0xfffff);
599 break;
600 case 6:
601 lcd_puts(0, 0, "KBass ");
602 snprintf(buf, 32, "6b: %05x ", mas_readreg(0x6b) & 0xfffff);
603 break;
604 case 7:
605 lcd_puts(0, 0, "KTreble ");
606 snprintf(buf, 32, "6f: %05x ", mas_readreg(0x6f) & 0xfffff);
607 break;
608 case 8:
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);
612 break;
613 case 9:
614 mas_readmem(MAS_BANK_D0, 0x301, &val, 1);
615 lcd_puts(0, 0, "Status1 ");
616 snprintf(buf, 32, "0/301: %04x", val & 0xffff);
617 break;
618 case 10:
619 mas_readmem(MAS_BANK_D0, 0x302, &val, 1);
620 lcd_puts(0, 0, "Status2 ");
621 snprintf(buf, 32, "0/302: %04x", val & 0xffff);
622 break;
623 case 11:
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);
627 break;
628 case 12:
629 mas_readmem(MAS_BANK_D0, 0x36d, &val, 1);
630 lcd_puts(0, 0, "PLLOffset48");
631 snprintf(buf, 32, "0/36d %05x", val & 0xfffff);
632 break;
633 case 13:
634 mas_readmem(MAS_BANK_D0, 0x32d, &val, 1);
635 lcd_puts(0, 0, "PLLOffset48");
636 snprintf(buf, 32, "0/32d %05x", val & 0xfffff);
637 break;
638 case 14:
639 mas_readmem(MAS_BANK_D0, 0x36e, &val, 1);
640 lcd_puts(0, 0, "PLLOffset44");
641 snprintf(buf, 32, "0/36e %05x", val & 0xfffff);
642 break;
643 case 15:
644 mas_readmem(MAS_BANK_D0, 0x32e, &val, 1);
645 lcd_puts(0, 0, "PLLOffset44");
646 snprintf(buf, 32, "0/32e %05x", val & 0xfffff);
647 break;
648 case 16:
649 mas_readmem(MAS_BANK_D0, 0x36f, &val, 1);
650 lcd_puts(0, 0, "OutputConf ");
651 snprintf(buf, 32, "0/36f %05x", val & 0xfffff);
652 break;
653 case 17:
654 mas_readmem(MAS_BANK_D0, 0x32f, &val, 1);
655 lcd_puts(0, 0, "OutputConf ");
656 snprintf(buf, 32, "0/32f %05x", val & 0xfffff);
657 break;
658 case 18:
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);
662 break;
663 case 19:
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);
667 break;
668 case 20:
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);
672 break;
673 case 21:
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);
677 break;
678 case 22:
679 lcd_puts(0, 0, "L Trailbits");
680 snprintf(buf, 32, "c5: %05x ", mas_readreg(0xc5) & 0xfffff);
681 break;
682 case 23:
683 lcd_puts(0, 0, "R Trailbits");
684 snprintf(buf, 32, "c6: %05x ", mas_readreg(0xc6) & 0xfffff);
685 break;
687 lcd_puts(0, 1, buf);
689 button = button_get_w_tmo(HZ/5);
690 switch(button)
692 case BUTTON_STOP:
693 return;
695 case BUTTON_LEFT:
696 currval--;
697 if(currval < 0)
698 currval = 23;
699 break;
701 case BUTTON_RIGHT:
702 currval++;
703 if(currval > 23)
704 currval = 0;
705 break;
706 case BUTTON_PLAY:
707 pll_toggle = !pll_toggle;
708 if(pll_toggle)
710 /* 14.31818 MHz crystal */
711 pll48 = 0x5d9d0;
712 pll44 = 0xfffceceb;
713 config = 0;
715 else
717 /* 14.725 MHz crystal */
718 pll48 = 0x2d0de;
719 pll44 = 0xfffa2319;
720 config = 0;
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);
725 mas_run(0x475);
726 break;
730 #endif
732 void debug_menu(void)
734 int m;
736 struct menu_items items[] = {
737 { "View I/O ports", dbg_ports },
738 #ifdef HAVE_LCD_BITMAP
739 #ifdef HAVE_RTC
740 { "View/clr RTC RAM", dbg_rtc },
741 #endif /* HAVE_RTC */
742 #endif /* HAVE_LCD_BITMAP */
743 { "View OS stacks", dbg_os },
744 #ifdef HAVE_MAS3507D
745 { "View MAS info", dbg_mas_info },
746 #endif
747 { "View MAS regs", dbg_mas },
748 #ifdef HAVE_MAS3587F
749 { "View MAS codec", dbg_mas_codec },
750 #endif
751 #ifdef HAVE_LCD_BITMAP
752 { "View battery", view_battery },
753 #endif
756 m=menu_init( items, sizeof items / sizeof(struct menu_items) );
757 menu_run(m);
758 menu_exit(m);
761 #endif /* SIMULATOR */