Cleanup in buflib:
[kugel-rb.git] / apps / debug_menu.c
blobfb8575ec625047032cea45d77785bc8429a81e90
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Heikki Hannikainen
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <stdbool.h>
26 #include <string.h>
27 #include "lcd.h"
28 #include "menu.h"
29 #include "debug_menu.h"
30 #include "kernel.h"
31 #include "structec.h"
32 #include "action.h"
33 #include "debug.h"
34 #include "thread.h"
35 #include "powermgmt.h"
36 #include "system.h"
37 #include "font.h"
38 #include "audio.h"
39 #include "mp3_playback.h"
40 #include "settings.h"
41 #include "list.h"
42 #include "statusbar.h"
43 #include "dir.h"
44 #include "panic.h"
45 #include "screens.h"
46 #include "misc.h"
47 #include "splash.h"
48 #include "dircache.h"
49 #include "viewport.h"
50 #ifdef HAVE_TAGCACHE
51 #include "tagcache.h"
52 #endif
53 #include "lcd-remote.h"
54 #include "crc32.h"
55 #include "logf.h"
56 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
57 #include "disk.h"
58 #include "adc.h"
59 #include "power.h"
60 #include "usb.h"
61 #include "rtc.h"
62 #include "storage.h"
63 #include "fat.h"
64 #include "eeprom_24cxx.h"
65 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
66 #include "sdmmc.h"
67 #endif
68 #if (CONFIG_STORAGE & STORAGE_ATA)
69 #include "ata.h"
70 #endif
71 #if CONFIG_TUNER
72 #include "tuner.h"
73 #include "radio.h"
74 #endif
75 #endif
77 #ifdef HAVE_LCD_BITMAP
78 #include "scrollbar.h"
79 #include "peakmeter.h"
80 #endif
81 #include "logfdisp.h"
82 #include "core_alloc.h"
83 #if CONFIG_CODEC == SWCODEC
84 #include "pcmbuf.h"
85 #include "buffering.h"
86 #include "playback.h"
87 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
88 #include "spdif.h"
89 #endif
90 #endif
91 #ifdef IRIVER_H300_SERIES
92 #include "pcf50606.h" /* for pcf50606_read */
93 #endif
94 #ifdef IAUDIO_X5
95 #include "ds2411.h"
96 #endif
97 #include "hwcompat.h"
98 #include "button.h"
99 #if CONFIG_RTC == RTC_PCF50605
100 #include "pcf50605.h"
101 #endif
102 #include "appevents.h"
103 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
104 #include "debug-target.h"
105 #endif
107 #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) \
108 || (CONFIG_CPU == AS3525 && defined(CONFIG_CHARGING)) \
109 || CONFIG_CPU == AS3525v2
110 #include "ascodec.h"
111 #include "as3514.h"
112 #endif
114 #ifdef IPOD_NANO2G
115 #include "pmu-target.h"
116 #endif
118 #ifdef HAVE_USBSTACK
119 #include "usb_core.h"
120 #endif
122 #if defined(IPOD_ACCESSORY_PROTOCOL)
123 #include "iap.h"
124 #endif
126 /*---------------------------------------------------*/
127 /* SPECIAL DEBUG STUFF */
128 /*---------------------------------------------------*/
129 extern struct thread_entry threads[MAXTHREADS];
131 static char thread_status_char(unsigned status)
133 static const char thread_status_chars[THREAD_NUM_STATES+1] =
135 [0 ... THREAD_NUM_STATES] = '?',
136 [STATE_RUNNING] = 'R',
137 [STATE_BLOCKED] = 'B',
138 [STATE_SLEEPING] = 'S',
139 [STATE_BLOCKED_W_TMO] = 'T',
140 [STATE_FROZEN] = 'F',
141 [STATE_KILLED] = 'K',
144 if (status > THREAD_NUM_STATES)
145 status = THREAD_NUM_STATES;
147 return thread_status_chars[status];
150 static const char* threads_getname(int selected_item, void *data,
151 char *buffer, size_t buffer_len)
153 (void)data;
154 struct thread_entry *thread;
155 char name[32];
157 #if NUM_CORES > 1
158 if (selected_item < (int)NUM_CORES)
160 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
161 idle_stack_usage(selected_item));
162 return buffer;
165 selected_item -= NUM_CORES;
166 #endif
168 thread = &threads[selected_item];
170 if (thread->state == STATE_KILLED)
172 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
173 return buffer;
176 thread_get_name(name, 32, thread);
178 snprintf(buffer, buffer_len,
179 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
180 selected_item,
181 IF_COP(thread->core,)
182 #ifdef HAVE_SCHEDULER_BOOSTCTRL
183 (thread->cpu_boost) ? '+' :
184 #endif
185 ((thread->state == STATE_RUNNING) ? '*' : ' '),
186 thread_status_char(thread->state),
187 IF_PRIO(thread->base_priority, thread->priority, )
188 thread_stack_usage(thread), name);
190 return buffer;
193 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
195 (void)lists;
196 #ifdef ROCKBOX_HAS_LOGF
197 if (action == ACTION_STD_OK)
199 int selpos = gui_synclist_get_sel_pos(lists);
200 #if NUM_CORES > 1
201 if (selpos >= NUM_CORES)
202 remove_thread(threads[selpos - NUM_CORES].id);
203 #else
204 remove_thread(threads[selpos].id);
205 #endif
206 return ACTION_REDRAW;
208 #endif /* ROCKBOX_HAS_LOGF */
209 if (action == ACTION_NONE)
210 action = ACTION_REDRAW;
211 return action;
213 /* Test code!!! */
214 static bool dbg_os(void)
216 struct simplelist_info info;
217 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
218 #if NUM_CORES == 1
219 MAXTHREADS,
220 #else
221 MAXTHREADS+NUM_CORES,
222 #endif
223 NULL);
224 #ifndef ROCKBOX_HAS_LOGF
225 info.hide_selection = true;
226 info.scroll_all = true;
227 #endif
228 info.action_callback = dbg_threads_action_callback;
229 info.get_name = threads_getname;
230 return simplelist_show_list(&info);
233 #ifdef HAVE_LCD_BITMAP
234 #if CONFIG_CODEC != SWCODEC
235 #ifndef SIMULATOR
236 static bool dbg_audio_thread(void)
238 struct audio_debug d;
240 lcd_setfont(FONT_SYSFIXED);
242 while(1)
244 if (action_userabort(HZ/5))
245 return false;
247 audio_get_debugdata(&d);
249 lcd_clear_display();
251 lcd_putsf(0, 0, "read: %x", d.audiobuf_read);
252 lcd_putsf(0, 1, "write: %x", d.audiobuf_write);
253 lcd_putsf(0, 2, "swap: %x", d.audiobuf_swapwrite);
254 lcd_putsf(0, 3, "playing: %d", d.playing);
255 lcd_putsf(0, 4, "playable: %x", d.playable_space);
256 lcd_putsf(0, 5, "unswapped: %x", d.unswapped_space);
258 /* Playable space left */
259 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
260 d.playable_space, HORIZONTAL);
262 /* Show the watermark limit */
263 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
264 d.low_watermark_level, HORIZONTAL);
266 lcd_putsf(0, 7, "wm: %x - %x",
267 d.low_watermark_level, d.lowest_watermark_level);
269 lcd_update();
271 lcd_setfont(FONT_UI);
272 return false;
274 #endif /* !SIMULATOR */
275 #else /* CONFIG_CODEC == SWCODEC */
276 static unsigned int ticks, freq_sum;
277 #ifndef CPU_MULTI_FREQUENCY
278 static unsigned int boost_ticks;
279 #endif
281 static void dbg_audio_task(void)
283 #ifdef CPUFREQ_NORMAL
284 #ifndef CPU_MULTI_FREQUENCY
285 if(FREQ > CPUFREQ_NORMAL)
286 boost_ticks++;
287 #endif
288 freq_sum += FREQ/1000000; /* in MHz */
289 #endif
290 ticks++;
293 static bool dbg_buffering_thread(void)
295 int button;
296 int line, i;
297 bool done = false;
298 size_t bufused;
299 size_t bufsize = pcmbuf_get_bufsize();
300 int pcmbufdescs = pcmbuf_descs();
301 struct buffering_debug d;
302 size_t filebuflen = audio_get_filebuflen();
303 /* This is a size_t, but call it a long so it puts a - when it's bad. */
305 #ifndef CPU_MULTI_FREQUENCY
306 boost_ticks = 0;
307 #endif
308 ticks = freq_sum = 0;
310 tick_add_task(dbg_audio_task);
312 FOR_NB_SCREENS(i)
313 screens[i].setfont(FONT_SYSFIXED);
315 while(!done)
317 button = get_action(CONTEXT_STD,HZ/5);
318 switch(button)
320 case ACTION_STD_NEXT:
321 audio_next();
322 break;
323 case ACTION_STD_PREV:
324 audio_prev();
325 break;
326 case ACTION_STD_CANCEL:
327 done = true;
328 break;
331 buffering_get_debugdata(&d);
332 bufused = bufsize - pcmbuf_free();
334 FOR_NB_SCREENS(i)
336 line = 0;
337 screens[i].clear_display();
340 screens[i].putsf(0, line++, "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
342 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
343 bufsize, 0, bufused, HORIZONTAL);
344 line++;
346 screens[i].putsf(0, line++, "alloc: %6ld/%ld", audio_filebufused(),
347 (long) filebuflen);
349 #if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
350 if (screens[i].lcdheight > 80)
352 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
353 filebuflen, 0, audio_filebufused(), HORIZONTAL);
354 line++;
356 screens[i].putsf(0, line++, "real: %6ld/%ld", (long)d.buffered_data,
357 (long)filebuflen);
359 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
360 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
361 line++;
363 #endif
365 screens[i].putsf(0, line++, "usefl: %6ld/%ld", (long)(d.useful_data),
366 (long)filebuflen);
368 #if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
369 if (screens[i].lcdheight > 80)
371 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
372 filebuflen, 0, d.useful_data, HORIZONTAL);
373 line++;
375 #endif
377 screens[i].putsf(0, line++, "data_rem: %ld", (long)d.data_rem);
379 screens[i].putsf(0, line++, "track count: %2d", audio_track_count());
381 screens[i].putsf(0, line++, "handle count: %d", (int)d.num_handles);
383 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
384 screens[i].putsf(0, line++, "cpu freq: %3dMHz",
385 (int)((FREQ + 500000) / 1000000));
386 #endif
388 if (ticks > 0)
390 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
391 #ifdef CPU_MULTI_FREQUENCY
392 int boostquota = (avgclock * 100 - CPUFREQ_NORMAL/1000) /
393 ((CPUFREQ_MAX - CPUFREQ_NORMAL) / 1000000); /* in 0.1 % */
394 #else
395 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
396 #endif
397 screens[i].putsf(0, line++, "boost:%3d.%d%% (%d.%dMHz)",
398 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
401 screens[i].putsf(0, line++, "pcmbufdesc: %2d/%2d",
402 pcmbuf_used_descs(), pcmbufdescs);
403 screens[i].putsf(0, line++, "watermark: %6d",
404 (int)(d.watermark));
406 screens[i].update();
410 tick_remove_task(dbg_audio_task);
412 FOR_NB_SCREENS(i)
413 screens[i].setfont(FONT_UI);
415 return false;
417 #endif /* CONFIG_CODEC */
418 #endif /* HAVE_LCD_BITMAP */
420 static const char* bf_getname(int selected_item, void *data,
421 char *buffer, size_t buffer_len)
423 (void)data;
424 core_print_block_at(selected_item, buffer, buffer_len);
425 return buffer;
428 static bool dbg_buflib_allocs(void)
430 struct simplelist_info info;
431 simplelist_info_init(&info, "mem allocs", core_get_num_blocks(), NULL);
432 info.get_name = bf_getname;
433 return simplelist_show_list(&info);
436 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
437 static const char* dbg_partitions_getname(int selected_item, void *data,
438 char *buffer, size_t buffer_len)
440 (void)data;
441 int partition = selected_item/2;
442 struct partinfo* p = disk_partinfo(partition);
443 if (selected_item%2)
445 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / ( 2048 / ( SECTOR_SIZE / 512 )));
447 else
449 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
451 return buffer;
454 bool dbg_partitions(void)
456 struct simplelist_info info;
457 simplelist_info_init(&info, "Partition Info", 4, NULL);
458 info.selection_size = 2;
459 info.hide_selection = true;
460 info.scroll_all = true;
461 info.get_name = dbg_partitions_getname;
462 return simplelist_show_list(&info);
464 #endif /* PLATFORM_NATIVE */
466 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
467 static bool dbg_spdif(void)
469 int line;
470 unsigned int control;
471 int x;
472 char *s;
473 int category;
474 int generation;
475 unsigned int interruptstat;
476 bool valnogood, symbolerr, parityerr;
477 bool done = false;
478 bool spdif_src_on;
479 int spdif_source = spdif_get_output_source(&spdif_src_on);
480 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
482 lcd_clear_display();
483 lcd_setfont(FONT_SYSFIXED);
485 #ifdef HAVE_SPDIF_POWER
486 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
487 #endif
489 while (!done)
491 line = 0;
493 control = EBU1RCVCCHANNEL1;
494 interruptstat = INTERRUPTSTAT;
495 INTERRUPTCLEAR = 0x03c00000;
497 valnogood = (interruptstat & 0x01000000)?true:false;
498 symbolerr = (interruptstat & 0x00800000)?true:false;
499 parityerr = (interruptstat & 0x00400000)?true:false;
501 lcd_putsf(0, line++, "Val: %s Sym: %s Par: %s",
502 valnogood?"--":"OK",
503 symbolerr?"--":"OK",
504 parityerr?"--":"OK");
506 lcd_putsf(0, line++, "Status word: %08x", (int)control);
508 line++;
510 x = control >> 31;
511 lcd_putsf(0, line++, "PRO: %d (%s)",
512 x, x?"Professional":"Consumer");
514 x = (control >> 30) & 1;
515 lcd_putsf(0, line++, "Audio: %d (%s)",
516 x, x?"Non-PCM":"PCM");
518 x = (control >> 29) & 1;
519 lcd_putsf(0, line++, "Copy: %d (%s)",
520 x, x?"Permitted":"Inhibited");
522 x = (control >> 27) & 7;
523 switch(x)
525 case 0:
526 s = "None";
527 break;
528 case 1:
529 s = "50/15us";
530 break;
531 default:
532 s = "Reserved";
533 break;
535 lcd_putsf(0, line++, "Preemphasis: %d (%s)", x, s);
537 x = (control >> 24) & 3;
538 lcd_putsf(0, line++, "Mode: %d", x);
540 category = (control >> 17) & 127;
541 switch(category)
543 case 0x00:
544 s = "General";
545 break;
546 case 0x40:
547 s = "Audio CD";
548 break;
549 default:
550 s = "Unknown";
552 lcd_putsf(0, line++, "Category: 0x%02x (%s)", category, s);
554 x = (control >> 16) & 1;
555 generation = x;
556 if(((category & 0x70) == 0x10) ||
557 ((category & 0x70) == 0x40) ||
558 ((category & 0x78) == 0x38))
560 generation = !generation;
562 lcd_putsf(0, line++, "Generation: %d (%s)",
563 x, generation?"Original":"No ind.");
565 x = (control >> 12) & 15;
566 lcd_putsf(0, line++, "Source: %d", x);
569 x = (control >> 8) & 15;
570 switch(x)
572 case 0:
573 s = "Unspecified";
574 break;
575 case 8:
576 s = "A (Left)";
577 break;
578 case 4:
579 s = "B (Right)";
580 break;
581 default:
582 s = "";
583 break;
585 lcd_putsf(0, line++, "Channel: %d (%s)", x, s);
587 x = (control >> 4) & 15;
588 switch(x)
590 case 0:
591 s = "44.1kHz";
592 break;
593 case 0x4:
594 s = "48kHz";
595 break;
596 case 0xc:
597 s = "32kHz";
598 break;
600 lcd_putsf(0, line++, "Frequency: %d (%s)", x, s);
602 x = (control >> 2) & 3;
603 lcd_putsf(0, line++, "Clock accuracy: %d", x);
604 line++;
606 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
607 lcd_putsf(0, line++, "Measured freq: %ldHz",
608 spdif_measure_frequency());
609 #endif
611 lcd_update();
613 if (action_userabort(HZ/10))
614 break;
617 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
619 #ifdef HAVE_SPDIF_POWER
620 spdif_power_enable(global_settings.spdif_enable);
621 #endif
623 lcd_setfont(FONT_UI);
624 return false;
626 #endif /* CPU_COLDFIRE */
628 #if (CONFIG_RTC == RTC_PCF50605) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
629 static bool dbg_pcf(void)
631 int line;
633 #ifdef HAVE_LCD_BITMAP
634 lcd_setfont(FONT_SYSFIXED);
635 #endif
636 lcd_clear_display();
638 while(1)
640 line = 0;
642 lcd_putsf(0, line++, "DCDC1: %02x", pcf50605_read(0x1b));
643 lcd_putsf(0, line++, "DCDC2: %02x", pcf50605_read(0x1c));
644 lcd_putsf(0, line++, "DCDC3: %02x", pcf50605_read(0x1d));
645 lcd_putsf(0, line++, "DCDC4: %02x", pcf50605_read(0x1e));
646 lcd_putsf(0, line++, "DCDEC1: %02x", pcf50605_read(0x1f));
647 lcd_putsf(0, line++, "DCDEC2: %02x", pcf50605_read(0x20));
648 lcd_putsf(0, line++, "DCUDC1: %02x", pcf50605_read(0x21));
649 lcd_putsf(0, line++, "DCUDC2: %02x", pcf50605_read(0x22));
650 lcd_putsf(0, line++, "IOREGC: %02x", pcf50605_read(0x23));
651 lcd_putsf(0, line++, "D1REGC: %02x", pcf50605_read(0x24));
652 lcd_putsf(0, line++, "D2REGC: %02x", pcf50605_read(0x25));
653 lcd_putsf(0, line++, "D3REGC: %02x", pcf50605_read(0x26));
654 lcd_putsf(0, line++, "LPREG1: %02x", pcf50605_read(0x27));
655 lcd_update();
656 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
658 lcd_setfont(FONT_UI);
659 return false;
663 lcd_setfont(FONT_UI);
664 return false;
666 #endif
668 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
669 static bool dbg_cpufreq(void)
671 int line;
672 int button;
674 #ifdef HAVE_LCD_BITMAP
675 lcd_setfont(FONT_SYSFIXED);
676 #endif
677 lcd_clear_display();
679 while(1)
681 line = 0;
683 lcd_putsf(0, line++, "Frequency: %ld", FREQ);
684 lcd_putsf(0, line++, "boost_counter: %d", get_cpu_boost_counter());
686 lcd_update();
687 button = get_action(CONTEXT_STD,HZ/10);
689 switch(button)
691 case ACTION_STD_PREV:
692 cpu_boost(true);
693 break;
695 case ACTION_STD_NEXT:
696 cpu_boost(false);
697 break;
699 case ACTION_STD_OK:
700 while (get_cpu_boost_counter() > 0)
701 cpu_boost(false);
702 set_cpu_frequency(CPUFREQ_DEFAULT);
703 break;
705 case ACTION_STD_CANCEL:
706 lcd_setfont(FONT_UI);
707 return false;
710 lcd_setfont(FONT_UI);
711 return false;
713 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
715 #if defined(HAVE_TSC2100) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
716 #include "tsc2100.h"
717 static const char* tsc2100_debug_getname(int selected_item, void * data,
718 char *buffer, size_t buffer_len)
720 int *page = (int*)data;
721 bool reserved = false;
722 switch (*page)
724 case 0:
725 if ((selected_item > 0x0a) ||
726 (selected_item == 0x04) ||
727 (selected_item == 0x08))
728 reserved = true;
729 break;
730 case 1:
731 if ((selected_item > 0x05) ||
732 (selected_item == 0x02))
733 reserved = true;
734 break;
735 case 2:
736 if (selected_item > 0x1e)
737 reserved = true;
738 break;
740 if (reserved)
741 snprintf(buffer, buffer_len, "%02x: RSVD", selected_item);
742 else
743 snprintf(buffer, buffer_len, "%02x: %04x", selected_item,
744 tsc2100_readreg(*page, selected_item)&0xffff);
745 return buffer;
747 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
749 int *page = (int*)lists->data;
750 if (action == ACTION_STD_OK)
752 *page = (*page+1)%3;
753 snprintf(lists->title, 32,
754 "tsc2100 registers - Page %d", *page);
755 return ACTION_REDRAW;
757 return action;
759 static bool tsc2100_debug(void)
761 int page = 0;
762 char title[32] = "tsc2100 registers - Page 0";
763 struct simplelist_info info;
764 simplelist_info_init(&info, title, 32, &page);
765 info.timeout = HZ/100;
766 info.get_name = tsc2100_debug_getname;
767 info.action_callback= tsc2100debug_action_callback;
768 return simplelist_show_list(&info);
770 #endif
771 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
772 #ifdef HAVE_LCD_BITMAP
774 * view_battery() shows a automatically scaled graph of the battery voltage
775 * over time. Usable for estimating battery life / charging rate.
776 * The power_history array is updated in power_thread of powermgmt.c.
779 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
780 #define BAT_YSPACE (LCD_HEIGHT - 20)
783 static bool view_battery(void)
785 int view = 0;
786 int i, x, y, y1, y2, grid, graph;
787 unsigned short maxv, minv;
789 lcd_setfont(FONT_SYSFIXED);
791 while(1)
793 lcd_clear_display();
794 switch (view) {
795 case 0: /* voltage history graph */
796 /* Find maximum and minimum voltage for scaling */
797 minv = power_history[0];
798 maxv = minv + 1;
799 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
800 if (power_history[i] > maxv)
801 maxv = power_history[i];
802 if (power_history[i] < minv)
803 minv = power_history[i];
806 /* adjust grid scale */
807 if ((maxv - minv) > 50)
808 grid = 50;
809 else
810 grid = 5;
812 /* print header */
813 lcd_putsf(0, 0, "battery %d.%03dV", power_history[0] / 1000,
814 power_history[0] % 1000);
815 lcd_putsf(0, 1, "%d.%03d-%d.%03dV (%2dmV)",
816 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000,
817 grid);
819 i = 1;
820 while ((y = (minv - (minv % grid)+i*grid)) < maxv)
822 graph = ((y-minv)*BAT_YSPACE)/(maxv-minv);
823 graph = LCD_HEIGHT-1 - graph;
825 /* draw dotted horizontal grid line */
826 for (x=0; x<LCD_WIDTH;x=x+2)
827 lcd_drawpixel(x,graph);
829 i++;
832 x = 0;
833 /* draw plot of power history
834 * skip empty entries
836 for (i = BAT_LAST_VAL - 1; i > 0; i--)
838 if (power_history[i] && power_history[i-1])
840 y1 = (power_history[i] - minv) * BAT_YSPACE /
841 (maxv - minv);
842 y1 = MIN(MAX(LCD_HEIGHT-1 - y1, 20),
843 LCD_HEIGHT-1);
844 y2 = (power_history[i-1] - minv) * BAT_YSPACE /
845 (maxv - minv);
846 y2 = MIN(MAX(LCD_HEIGHT-1 - y2, 20),
847 LCD_HEIGHT-1);
849 lcd_set_drawmode(DRMODE_SOLID);
851 /* make line thicker */
852 lcd_drawline(((x*LCD_WIDTH)/(BAT_LAST_VAL)),
853 y1,
854 (((x+1)*LCD_WIDTH)/(BAT_LAST_VAL)),
855 y2);
856 lcd_drawline(((x*LCD_WIDTH)/(BAT_LAST_VAL))+1,
857 y1+1,
858 (((x+1)*LCD_WIDTH)/(BAT_LAST_VAL))+1,
859 y2+1);
860 x++;
863 break;
865 case 1: /* status: */
866 #if CONFIG_CHARGING >= CHARGING_MONITOR
867 lcd_putsf(0, 0, "Pwr status: %s",
868 charging_state() ? "charging" : "discharging");
869 #else
870 lcd_puts(0, 0, "Power status:");
871 #endif
872 battery_read_info(&y, NULL);
873 lcd_putsf(0, 1, "Battery: %d.%03d V", y / 1000, y % 1000);
874 #ifdef ADC_EXT_POWER
875 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
876 lcd_putsf(0, 2, "External: %d.%03d V", y / 1000, y % 1000);
877 #endif
878 #if CONFIG_CHARGING
879 #if defined ARCHOS_RECORDER
880 lcd_putsf(0, 3, "Chgr: %s %s",
881 charger_inserted() ? "present" : "absent",
882 charger_enabled() ? "on" : "off");
883 lcd_putsf(0, 5, "short delta: %d", short_delta);
884 lcd_putsf(0, 6, "long delta: %d", long_delta);
885 lcd_puts(0, 7, power_message);
886 lcd_putsf(0, 8, "USB Inserted: %s",
887 usb_inserted() ? "yes" : "no");
888 #elif defined IPOD_NANO || defined IPOD_VIDEO
889 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
890 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
891 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
892 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
893 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
895 lcd_putsf(0, 3, "USB pwr: %s",
896 usb_pwr ? "present" : "absent");
897 lcd_putsf(0, 4, "EXT pwr: %s",
898 ext_pwr ? "present" : "absent");
899 lcd_putsf(0, 5, "Battery: %s",
900 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
901 lcd_putsf(0, 6, "Dock mode: %s",
902 dock ? "enabled" : "disabled");
903 lcd_putsf(0, 7, "Headphone: %s",
904 headphone ? "connected" : "disconnected");
905 #ifdef IPOD_VIDEO
906 if(probed_ramsize == 64)
907 x = (adc_read(ADC_4066_ISTAT) * 2400) / (1024 * 2);
908 else
909 #endif
910 x = (adc_read(ADC_4066_ISTAT) * 2400) / (1024 * 3);
911 lcd_putsf(0, 8, "Ibat: %d mA", x);
912 lcd_putsf(0, 9, "Vbat * Ibat: %d mW", x * y / 1000);
913 #elif defined TOSHIBA_GIGABEAT_S
914 int line = 3;
915 unsigned int st;
917 static const unsigned char * const chrgstate_strings[] =
919 "Disabled",
920 "Error",
921 "Discharging",
922 "Precharge",
923 "Constant Voltage",
924 "Constant Current",
925 "<unknown>",
928 lcd_putsf(0, line++, "Charger: %s",
929 charger_inserted() ? "present" : "absent");
931 st = power_input_status() &
932 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
933 lcd_putsf(0, line++, "%s%s",
934 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
935 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
937 y = ARRAYLEN(chrgstate_strings) - 1;
939 switch (charge_state)
941 case CHARGE_STATE_DISABLED: y--;
942 case CHARGE_STATE_ERROR: y--;
943 case DISCHARGING: y--;
944 case TRICKLE: y--;
945 case TOPOFF: y--;
946 case CHARGING: y--;
947 default:;
950 lcd_putsf(0, line++, "State: %s", chrgstate_strings[y]);
952 lcd_putsf(0, line++, "Battery Switch: %s",
953 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
955 y = chrgraw_adc_voltage();
956 lcd_putsf(0, line++, "CHRGRAW: %d.%03d V",
957 y / 1000, y % 1000);
959 y = application_supply_adc_voltage();
960 lcd_putsf(0, line++, "BP : %d.%03d V",
961 y / 1000, y % 1000);
963 y = battery_adc_charge_current();
964 if (y < 0) x = '-', y = -y;
965 else x = ' ';
966 lcd_putsf(0, line++, "CHRGISN:%c%d mA", x, y);
968 y = cccv_regulator_dissipation();
969 lcd_putsf(0, line++, "P CCCV : %d mW", y);
971 y = battery_charge_current();
972 if (y < 0) x = '-', y = -y;
973 else x = ' ';
974 lcd_putsf(0, line++, "I Charge:%c%d mA", x, y);
976 y = battery_adc_temp();
978 if (y != INT_MIN) {
979 lcd_putsf(0, line++, "T Battery: %dC (%dF)", y,
980 (9*y + 160) / 5);
981 } else {
982 /* Conversion disabled */
983 lcd_puts(0, line++, "T Battery: ?");
986 #elif defined(SANSA_E200) || defined(SANSA_C200) || CONFIG_CPU == AS3525 || \
987 CONFIG_CPU == AS3525v2
988 static const char * const chrgstate_strings[] =
990 [CHARGE_STATE_DISABLED - CHARGE_STATE_DISABLED]= "Disabled",
991 [CHARGE_STATE_ERROR - CHARGE_STATE_DISABLED] = "Error",
992 [DISCHARGING - CHARGE_STATE_DISABLED] = "Discharging",
993 [CHARGING - CHARGE_STATE_DISABLED] = "Charging",
995 const char *str = NULL;
997 lcd_putsf(0, 3, "Charger: %s",
998 charger_inserted() ? "present" : "absent");
1000 y = charge_state - CHARGE_STATE_DISABLED;
1001 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1002 str = chrgstate_strings[y];
1004 lcd_putsf(0, 4, "State: %s",
1005 str ? str : "<unknown>");
1007 lcd_putsf(0, 5, "CHARGER: %02X", ascodec_read_charger());
1008 #elif defined(IPOD_NANO2G)
1009 y = pmu_read_battery_voltage();
1010 lcd_putsf(17, 1, "RAW: %d.%03d V", y / 1000, y % 1000);
1011 y = pmu_read_battery_current();
1012 lcd_putsf(0, 2, "Battery current: %d mA", y);
1013 lcd_putsf(0, 3, "PWRCON: %08x %08x", PWRCON, PWRCONEXT);
1014 lcd_putsf(0, 4, "CLKCON: %08x %03x %03x", CLKCON, CLKCON2, CLKCON3);
1015 lcd_putsf(0, 5, "PLL: %06x %06x %06x", PLL0PMS, PLL1PMS, PLL2PMS);
1016 x = pmu_read(0x1b) & 0xf;
1017 y = pmu_read(0x1a) * 25 + 625;
1018 lcd_putsf(0, 6, "AUTO: %x / %d mV", x, y);
1019 x = pmu_read(0x1f) & 0xf;
1020 y = pmu_read(0x1e) * 25 + 625;
1021 lcd_putsf(0, 7, "DOWN1: %x / %d mV", x, y);
1022 x = pmu_read(0x23) & 0xf;
1023 y = pmu_read(0x22) * 25 + 625;
1024 lcd_putsf(0, 8, "DOWN2: %x / %d mV", x, y);
1025 x = pmu_read(0x27) & 0xf;
1026 y = pmu_read(0x26) * 100 + 900;
1027 lcd_putsf(0, 9, "MEMLDO: %x / %d mV", x, y);
1028 for (i = 0; i < 6; i++)
1030 x = pmu_read(0x2e + (i << 1)) & 0xf;
1031 y = pmu_read(0x2d + (i << 1)) * 100 + 900;
1032 lcd_putsf(0, 10 + i, "LDO%d: %x / %d mV", i + 1, x, y);
1034 #else
1035 lcd_putsf(0, 3, "Charger: %s",
1036 charger_inserted() ? "present" : "absent");
1037 #endif /* target type */
1038 #endif /* CONFIG_CHARGING */
1039 break;
1041 case 2: /* voltage deltas: */
1042 lcd_puts(0, 0, "Voltage deltas:");
1044 for (i = 0; i <= 6; i++) {
1045 y = power_history[i] - power_history[i+1];
1046 lcd_putsf(0, i+1, "-%d min: %s%d.%03d V", i,
1047 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1048 ((y < 0) ? y * -1 : y ) % 1000);
1050 break;
1052 case 3: /* remaining time estimation: */
1054 #ifdef ARCHOS_RECORDER
1055 lcd_putsf(0, 0, "charge_state: %d", charge_state);
1057 lcd_putsf(0, 1, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1059 lcd_putsf(0, 2, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1061 lcd_putsf(0, 3, "P=%2d I=%2d", pid_p, pid_i);
1063 lcd_putsf(0, 4, "Trickle sec: %d/60", trickle_sec);
1064 #endif /* ARCHOS_RECORDER */
1066 lcd_putsf(0, 5, "Last PwrHist: %d.%03dV",
1067 power_history[0] / 1000,
1068 power_history[0] % 1000);
1070 lcd_putsf(0, 6, "battery level: %d%%", battery_level());
1072 lcd_putsf(0, 7, "Est. remain: %d m", battery_time());
1073 break;
1076 lcd_update();
1078 switch(get_action(CONTEXT_STD,HZ/2))
1080 case ACTION_STD_PREV:
1081 if (view)
1082 view--;
1083 break;
1085 case ACTION_STD_NEXT:
1086 if (view < 3)
1087 view++;
1088 break;
1090 case ACTION_STD_CANCEL:
1091 lcd_setfont(FONT_UI);
1092 return false;
1095 lcd_setfont(FONT_UI);
1096 return false;
1099 #endif /* HAVE_LCD_BITMAP */
1100 #endif
1102 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
1103 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1105 #if (CONFIG_STORAGE & STORAGE_MMC)
1106 #define CARDTYPE "MMC"
1107 #elif (CONFIG_STORAGE & STORAGE_SD)
1108 #define CARDTYPE "microSD"
1109 #endif
1111 static int disk_callback(int btn, struct gui_synclist *lists)
1113 tCardInfo *card;
1114 int *cardnum = (int*)lists->data;
1115 unsigned char card_name[6];
1116 unsigned char pbuf[32];
1117 char *title = lists->title;
1118 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1119 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1120 static const unsigned char * const kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1121 static const unsigned char * const nsec_units[] = { "ns", "µs", "ms" };
1122 #if (CONFIG_STORAGE & STORAGE_MMC)
1123 static const char * const mmc_spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1124 "3.1-3.31", "4.0" };
1125 #endif
1127 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1129 #ifdef HAVE_HOTSWAP
1130 if (btn == ACTION_STD_OK)
1132 *cardnum ^= 0x1; /* change cards */
1134 #endif
1136 simplelist_set_line_count(0);
1138 card = card_get_info(*cardnum);
1140 if (card->initialized > 0)
1142 unsigned i;
1143 for (i=0; i<sizeof(card_name); i++)
1145 card_name[i] = card_extract_bits(card->cid, (103-8*i), 8);
1147 strlcpy(card_name, card_name, sizeof(card_name));
1148 simplelist_addline(SIMPLELIST_ADD_LINE,
1149 "%s Rev %d.%d", card_name,
1150 (int) card_extract_bits(card->cid, 63, 4),
1151 (int) card_extract_bits(card->cid, 59, 4));
1152 simplelist_addline(SIMPLELIST_ADD_LINE,
1153 "Prod: %d/%d",
1154 #if (CONFIG_STORAGE & STORAGE_SD)
1155 (int) card_extract_bits(card->cid, 11, 4),
1156 (int) card_extract_bits(card->cid, 19, 8) + 2000
1157 #elif (CONFIG_STORAGE & STORAGE_MMC)
1158 (int) card_extract_bits(card->cid, 15, 4),
1159 (int) card_extract_bits(card->cid, 11, 4) + 1997
1160 #endif
1162 simplelist_addline(SIMPLELIST_ADD_LINE,
1163 #if (CONFIG_STORAGE & STORAGE_SD)
1164 "Ser#: 0x%08lx",
1165 card_extract_bits(card->cid, 55, 32)
1166 #elif (CONFIG_STORAGE & STORAGE_MMC)
1167 "Ser#: 0x%04lx",
1168 card_extract_bits(card->cid, 47, 16)
1169 #endif
1172 simplelist_addline(SIMPLELIST_ADD_LINE, "M=%02x, "
1173 #if (CONFIG_STORAGE & STORAGE_SD)
1174 "O=%c%c",
1175 (int) card_extract_bits(card->cid, 127, 8),
1176 card_extract_bits(card->cid, 119, 8),
1177 card_extract_bits(card->cid, 111, 8)
1178 #elif (CONFIG_STORAGE & STORAGE_MMC)
1179 "O=%04x",
1180 (int) card_extract_bits(card->cid, 127, 8),
1181 (int) card_extract_bits(card->cid, 119, 16)
1182 #endif
1185 #if (CONFIG_STORAGE & STORAGE_MMC)
1186 int temp = card_extract_bits(card->csd, 125, 4);
1187 simplelist_addline(SIMPLELIST_ADD_LINE,
1188 "MMC v%s", temp < 5 ?
1189 mmc_spec_vers[temp] : "?.?");
1190 #endif
1191 simplelist_addline(SIMPLELIST_ADD_LINE,
1192 "Blocks: 0x%08lx", card->numblocks);
1193 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1194 kbit_units, false);
1195 simplelist_addline(SIMPLELIST_ADD_LINE,
1196 "Speed: %s", pbuf);
1197 output_dyn_value(pbuf, sizeof pbuf, card->taac,
1198 nsec_units, false);
1199 simplelist_addline(SIMPLELIST_ADD_LINE,
1200 "Taac: %s", pbuf);
1201 simplelist_addline(SIMPLELIST_ADD_LINE,
1202 "Nsac: %d clk", card->nsac);
1203 simplelist_addline(SIMPLELIST_ADD_LINE,
1204 "R2W: *%d", card->r2w_factor);
1205 #if (CONFIG_STORAGE & STORAGE_SD)
1206 int csd_structure = card_extract_bits(card->csd, 127, 2);
1207 if (csd_structure == 0) /* CSD version 1.0 */
1208 #endif
1210 simplelist_addline(SIMPLELIST_ADD_LINE,
1211 "IRmax: %d..%d mA",
1212 i_vmin[card_extract_bits(card->csd, 61, 3)],
1213 i_vmax[card_extract_bits(card->csd, 58, 3)]);
1214 simplelist_addline(SIMPLELIST_ADD_LINE,
1215 "IWmax: %d..%d mA",
1216 i_vmin[card_extract_bits(card->csd, 55, 3)],
1217 i_vmax[card_extract_bits(card->csd, 52, 3)]);
1220 else if (card->initialized == 0)
1222 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1224 #if (CONFIG_STORAGE & STORAGE_SD)
1225 else /* card->initialized < 0 */
1227 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1229 #endif
1230 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1231 gui_synclist_set_title(lists, title, Icon_NOICON);
1232 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1233 gui_synclist_select_item(lists, 0);
1234 btn = ACTION_REDRAW;
1236 return btn;
1238 #elif (CONFIG_STORAGE & STORAGE_ATA)
1239 static int disk_callback(int btn, struct gui_synclist *lists)
1241 (void)lists;
1242 int i;
1243 char buf[128];
1244 unsigned short* identify_info = ata_get_identify();
1245 bool timing_info_present = false;
1246 (void)btn;
1248 simplelist_set_line_count(0);
1250 for (i=0; i < 20; i++)
1251 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1252 buf[40]=0;
1253 /* kill trailing space */
1254 for (i=39; i && buf[i]==' '; i--)
1255 buf[i] = 0;
1256 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1257 for (i=0; i < 4; i++)
1258 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1259 buf[8]=0;
1260 simplelist_addline(SIMPLELIST_ADD_LINE,
1261 "Firmware: %s", buf);
1262 snprintf(buf, sizeof buf, "%ld MB",
1263 ((unsigned long)identify_info[61] << 16 |
1264 (unsigned long)identify_info[60]) / 2048 );
1265 simplelist_addline(SIMPLELIST_ADD_LINE,
1266 "Size: %s", buf);
1267 unsigned long free;
1268 fat_size( IF_MV2(0,) NULL, &free );
1269 simplelist_addline(SIMPLELIST_ADD_LINE,
1270 "Free: %ld MB", free / 1024);
1271 simplelist_addline(SIMPLELIST_ADD_LINE,
1272 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
1273 i = identify_info[83] & (1<<3);
1274 simplelist_addline(SIMPLELIST_ADD_LINE,
1275 "Power mgmt: %s", i ? "enabled" : "unsupported");
1276 i = identify_info[83] & (1<<9);
1277 simplelist_addline(SIMPLELIST_ADD_LINE,
1278 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1279 i = identify_info[82] & (1<<6);
1280 simplelist_addline(SIMPLELIST_ADD_LINE,
1281 "Read-ahead: %s", i ? "enabled" : "unsupported");
1282 timing_info_present = identify_info[53] & (1<<1);
1283 if(timing_info_present) {
1284 char pio3[2], pio4[2];pio3[1] = 0;
1285 pio4[1] = 0;
1286 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1287 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1288 simplelist_addline(SIMPLELIST_ADD_LINE,
1289 "PIO modes: 0 1 2 %s %s", pio3, pio4);
1291 else {
1292 simplelist_addline(SIMPLELIST_ADD_LINE,
1293 "No PIO mode info");
1295 timing_info_present = identify_info[53] & (1<<1);
1296 if(timing_info_present) {
1297 simplelist_addline(SIMPLELIST_ADD_LINE,
1298 "Cycle times %dns/%dns",
1299 identify_info[67],
1300 identify_info[68] );
1301 } else {
1302 simplelist_addline(SIMPLELIST_ADD_LINE,
1303 "No timing info");
1305 int sector_size = 512;
1306 if((identify_info[106] & 0xe000) == 0x6000)
1307 sector_size *= BIT_N(identify_info[106] & 0x000f);
1308 simplelist_addline(SIMPLELIST_ADD_LINE,
1309 "Physical sector size: %d", sector_size);
1310 #ifdef HAVE_ATA_DMA
1311 if (identify_info[63] & (1<<0)) {
1312 char mdma0[2], mdma1[2], mdma2[2];
1313 mdma0[1] = mdma1[1] = mdma2[1] = 0;
1314 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
1315 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
1316 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
1317 simplelist_addline(SIMPLELIST_ADD_LINE,
1318 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
1319 simplelist_addline(SIMPLELIST_ADD_LINE,
1320 "MDMA Cycle times %dns/%dns",
1321 identify_info[65],
1322 identify_info[66] );
1324 else {
1325 simplelist_addline(SIMPLELIST_ADD_LINE,
1326 "No MDMA mode info");
1328 if (identify_info[53] & (1<<2)) {
1329 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2], udma6[2];
1330 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = udma6[1] = 0;
1331 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
1332 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
1333 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
1334 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
1335 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
1336 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
1337 udma6[0] = (identify_info[88] & (1<<6)) ? '6' : 0;
1338 simplelist_addline(SIMPLELIST_ADD_LINE,
1339 "UDMA modes: %s %s %s %s %s %s %s", udma0, udma1, udma2,
1340 udma3, udma4, udma5, udma6);
1342 else {
1343 simplelist_addline(SIMPLELIST_ADD_LINE,
1344 "No UDMA mode info");
1346 #endif /* HAVE_ATA_DMA */
1347 timing_info_present = identify_info[53] & (1<<1);
1348 if(timing_info_present) {
1349 i = identify_info[49] & (1<<11);
1350 simplelist_addline(SIMPLELIST_ADD_LINE,
1351 "IORDY support: %s", i ? "yes" : "no");
1352 i = identify_info[49] & (1<<10);
1353 simplelist_addline(SIMPLELIST_ADD_LINE,
1354 "IORDY disable: %s", i ? "yes" : "no");
1355 } else {
1356 simplelist_addline(SIMPLELIST_ADD_LINE,
1357 "No timing info");
1359 simplelist_addline(SIMPLELIST_ADD_LINE,
1360 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1361 #ifdef HAVE_ATA_DMA
1362 i = ata_get_dma_mode();
1363 if (i == 0) {
1364 simplelist_addline(SIMPLELIST_ADD_LINE,
1365 "DMA not enabled");
1366 } else {
1367 simplelist_addline(SIMPLELIST_ADD_LINE,
1368 "DMA mode: %s %c",
1369 (i & 0x40) ? "UDMA" : "MDMA",
1370 '0' + (i & 7));
1372 #endif /* HAVE_ATA_DMA */
1373 return btn;
1375 #else /* No SD, MMC or ATA */
1376 static int disk_callback(int btn, struct gui_synclist *lists)
1378 (void)btn;
1379 (void)lists;
1380 struct storage_info info;
1381 storage_get_info(0,&info);
1382 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
1383 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
1384 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
1385 simplelist_addline(SIMPLELIST_ADD_LINE,
1386 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
1387 unsigned long free;
1388 fat_size( IF_MV2(0,) NULL, &free );
1389 simplelist_addline(SIMPLELIST_ADD_LINE,
1390 "Free: %ld MB", free / 1024);
1391 simplelist_addline(SIMPLELIST_ADD_LINE,
1392 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1393 return btn;
1395 #endif
1397 #if (CONFIG_STORAGE & STORAGE_ATA)
1398 static bool dbg_identify_info(void)
1400 int fd = creat("/identify_info.bin", 0666);
1401 if(fd >= 0)
1403 #ifdef ROCKBOX_LITTLE_ENDIAN
1404 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
1405 #else
1406 write(fd, ata_get_identify(), SECTOR_SIZE);
1407 #endif
1408 close(fd);
1410 return false;
1412 #endif
1414 static bool dbg_disk_info(void)
1416 struct simplelist_info info;
1417 simplelist_info_init(&info, "Disk Info", 1, NULL);
1418 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1419 char title[16];
1420 int card = 0;
1421 info.callback_data = (void*)&card;
1422 info.title = title;
1423 #endif
1424 info.action_callback = disk_callback;
1425 info.hide_selection = true;
1426 info.scroll_all = true;
1427 return simplelist_show_list(&info);
1429 #endif /* PLATFORM_NATIVE */
1431 #ifdef HAVE_DIRCACHE
1432 static int dircache_callback(int btn, struct gui_synclist *lists)
1434 (void)btn; (void)lists;
1435 simplelist_set_line_count(0);
1436 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
1437 dircache_is_enabled() ? "Yes" : "No");
1438 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
1439 dircache_get_cache_size());
1440 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
1441 global_status.dircache_size);
1442 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
1443 DIRCACHE_LIMIT);
1444 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
1445 dircache_get_reserve_used(), DIRCACHE_RESERVE);
1446 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
1447 dircache_get_build_ticks() / HZ);
1448 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
1449 dircache_get_entry_count());
1450 return btn;
1453 static bool dbg_dircache_info(void)
1455 struct simplelist_info info;
1456 simplelist_info_init(&info, "Dircache Info", 7, NULL);
1457 info.action_callback = dircache_callback;
1458 info.hide_selection = true;
1459 info.scroll_all = true;
1460 return simplelist_show_list(&info);
1463 #endif /* HAVE_DIRCACHE */
1465 #ifdef HAVE_TAGCACHE
1466 static int database_callback(int btn, struct gui_synclist *lists)
1468 (void)lists;
1469 struct tagcache_stat *stat = tagcache_get_stat();
1470 static bool synced = false;
1472 simplelist_set_line_count(0);
1474 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
1475 stat->initialized ? "Yes" : "No");
1476 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
1477 stat->ready ? "Yes" : "No");
1478 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
1479 stat->ramcache ? "Yes" : "No");
1480 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
1481 stat->ramcache_used, stat->ramcache_allocated);
1482 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
1483 stat->progress, stat->processed_entries);
1484 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
1485 stat->curentry ? stat->curentry : "---");
1486 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
1487 stat->commit_step);
1488 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
1489 stat->commit_delayed ? "Yes" : "No");
1491 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
1492 stat->queue_length);
1494 if (synced)
1496 synced = false;
1497 tagcache_screensync_event();
1500 if (!btn && stat->curentry)
1502 synced = true;
1503 return ACTION_REDRAW;
1506 if (btn == ACTION_STD_CANCEL)
1507 tagcache_screensync_enable(false);
1509 return btn;
1511 static bool dbg_tagcache_info(void)
1513 struct simplelist_info info;
1514 simplelist_info_init(&info, "Database Info", 8, NULL);
1515 info.action_callback = database_callback;
1516 info.hide_selection = true;
1517 info.scroll_all = true;
1519 /* Don't do nonblock here, must give enough processing time
1520 for tagcache thread. */
1521 /* info.timeout = TIMEOUT_NOBLOCK; */
1522 info.timeout = 1;
1523 tagcache_screensync_enable(true);
1524 return simplelist_show_list(&info);
1526 #endif
1528 #if CONFIG_CPU == SH7034
1529 static bool dbg_save_roms(void)
1531 int fd;
1532 int oldmode = system_memory_guard(MEMGUARD_NONE);
1534 fd = creat("/internal_rom_0000-FFFF.bin", 0666);
1535 if(fd >= 0)
1537 write(fd, (void *)0, 0x10000);
1538 close(fd);
1541 fd = creat("/internal_rom_2000000-203FFFF.bin", 0666);
1542 if(fd >= 0)
1544 write(fd, (void *)0x2000000, 0x40000);
1545 close(fd);
1548 system_memory_guard(oldmode);
1549 return false;
1551 #elif defined CPU_COLDFIRE
1552 static bool dbg_save_roms(void)
1554 int fd;
1555 int oldmode = system_memory_guard(MEMGUARD_NONE);
1557 #if defined(IRIVER_H100_SERIES)
1558 fd = creat("/internal_rom_000000-1FFFFF.bin", 0666);
1559 #elif defined(IRIVER_H300_SERIES)
1560 fd = creat("/internal_rom_000000-3FFFFF.bin", 0666);
1561 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
1562 fd = creat("/internal_rom_000000-3FFFFF.bin", 0666);
1563 #elif defined(MPIO_HD200) || defined(MPIO_HD300)
1564 fd = creat("/internal_rom_000000-1FFFFF.bin", 0666);
1565 #endif
1566 if(fd >= 0)
1568 write(fd, (void *)0, FLASH_SIZE);
1569 close(fd);
1571 system_memory_guard(oldmode);
1573 #ifdef HAVE_EEPROM
1574 fd = creat("/internal_eeprom.bin", 0666);
1575 if (fd >= 0)
1577 int old_irq_level;
1578 char buf[EEPROM_SIZE];
1579 int err;
1581 old_irq_level = disable_irq_save();
1583 err = eeprom_24cxx_read(0, buf, sizeof buf);
1585 restore_irq(old_irq_level);
1587 if (err)
1588 splashf(HZ*3, "Eeprom read failure (%d)", err);
1589 else
1591 write(fd, buf, sizeof buf);
1594 close(fd);
1596 #endif
1598 return false;
1600 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
1601 static bool dbg_save_roms(void)
1603 int fd;
1605 fd = creat("/internal_rom_000000-0FFFFF.bin", 0666);
1606 if(fd >= 0)
1608 write(fd, (void *)0x20000000, FLASH_SIZE);
1609 close(fd);
1612 return false;
1614 #elif CONFIG_CPU == IMX31L
1615 static bool dbg_save_roms(void)
1617 int fd;
1619 fd = creat("/flash_rom_A0000000-A01FFFFF.bin", 0666);
1620 if (fd >= 0)
1622 write(fd, (void*)0xa0000000, FLASH_SIZE);
1623 close(fd);
1626 return false;
1628 #elif defined(CPU_TCC780X)
1629 static bool dbg_save_roms(void)
1631 int fd;
1633 fd = creat("/eeprom_E0000000-E0001FFF.bin", 0666);
1634 if (fd >= 0)
1636 write(fd, (void*)0xe0000000, 0x2000);
1637 close(fd);
1640 return false;
1642 #endif /* CPU */
1644 #ifndef SIMULATOR
1645 #if CONFIG_TUNER
1647 #ifdef CONFIG_TUNER_MULTI
1648 static int tuner_type = 0;
1649 #define IF_TUNER_TYPE(type) if(tuner_type==type)
1650 #else
1651 #define IF_TUNER_TYPE(type)
1652 #endif
1654 static int radio_callback(int btn, struct gui_synclist *lists)
1656 (void)lists;
1657 if (btn == ACTION_STD_CANCEL)
1658 return btn;
1659 simplelist_set_line_count(1);
1661 #if (CONFIG_TUNER & LV24020LP)
1662 simplelist_addline(SIMPLELIST_ADD_LINE,
1663 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
1664 simplelist_addline(SIMPLELIST_ADD_LINE,
1665 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
1666 simplelist_addline(SIMPLELIST_ADD_LINE,
1667 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
1668 simplelist_addline(SIMPLELIST_ADD_LINE,
1669 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
1670 simplelist_addline(SIMPLELIST_ADD_LINE,
1671 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
1672 simplelist_addline(SIMPLELIST_ADD_LINE,
1673 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
1674 simplelist_addline(SIMPLELIST_ADD_LINE,
1675 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
1676 #endif /* LV24020LP */
1677 #if (CONFIG_TUNER & S1A0903X01)
1678 simplelist_addline(SIMPLELIST_ADD_LINE,
1679 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
1680 /* This one doesn't return dynamic data atm */
1681 #endif /* S1A0903X01 */
1682 #if (CONFIG_TUNER & TEA5767)
1683 struct tea5767_dbg_info nfo;
1684 tea5767_dbg_info(&nfo);
1685 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
1686 simplelist_addline(SIMPLELIST_ADD_LINE,
1687 " Read: %02X %02X %02X %02X %02X",
1688 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
1689 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
1690 (unsigned)nfo.read_regs[4]);
1691 simplelist_addline(SIMPLELIST_ADD_LINE,
1692 " Write: %02X %02X %02X %02X %02X",
1693 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
1694 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
1695 (unsigned)nfo.write_regs[4]);
1696 #endif /* TEA5767 */
1697 #if (CONFIG_TUNER & SI4700)
1698 IF_TUNER_TYPE(SI4700)
1700 struct si4700_dbg_info nfo;
1701 int i;
1702 si4700_dbg_info(&nfo);
1703 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
1704 for (i = 0; i < 16; i += 4) {
1705 simplelist_addline(SIMPLELIST_ADD_LINE,"%02X: %04X %04X %04X %04X",
1706 i, nfo.regs[i], nfo.regs[i+1], nfo.regs[i+2], nfo.regs[i+3]);
1709 #endif /* SI4700 */
1710 #if (CONFIG_TUNER & RDA5802)
1711 IF_TUNER_TYPE(RDA5802)
1713 struct rda5802_dbg_info nfo;
1714 int i;
1715 rda5802_dbg_info(&nfo);
1716 simplelist_addline(SIMPLELIST_ADD_LINE, "RDA5802 regs:");
1717 for (i = 0; i < 16; i += 4) {
1718 simplelist_addline(SIMPLELIST_ADD_LINE,"%02X: %04X %04X %04X %04X",
1719 i, nfo.regs[i], nfo.regs[i+1], nfo.regs[i+2], nfo.regs[i+3]);
1722 #endif /* RDA55802 */
1723 return ACTION_REDRAW;
1725 static bool dbg_fm_radio(void)
1727 struct simplelist_info info;
1728 #ifdef CONFIG_TUNER_MULTI
1729 tuner_type = tuner_detect_type();
1730 #endif
1731 info.scroll_all = true;
1732 simplelist_info_init(&info, "FM Radio", 1, NULL);
1733 simplelist_set_line_count(0);
1734 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
1735 radio_hardware_present() ? "yes" : "no");
1737 info.action_callback = radio_hardware_present()?radio_callback : NULL;
1738 info.hide_selection = true;
1739 return simplelist_show_list(&info);
1741 #endif /* CONFIG_TUNER */
1742 #endif /* !SIMULATOR */
1744 #ifdef HAVE_LCD_BITMAP
1745 extern bool do_screendump_instead_of_usb;
1747 static bool dbg_screendump(void)
1749 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
1750 splashf(HZ, "Screendump %s",
1751 do_screendump_instead_of_usb?"enabled":"disabled");
1752 return false;
1754 #endif /* HAVE_LCD_BITMAP */
1756 extern bool write_metadata_log;
1758 static bool dbg_metadatalog(void)
1760 write_metadata_log = !write_metadata_log;
1761 splashf(HZ, "Metadata log %s",
1762 write_metadata_log?"enabled":"disabled");
1763 return false;
1766 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
1767 static bool dbg_set_memory_guard(void)
1769 static const struct opt_items names[MAXMEMGUARD] = {
1770 { "None", -1 },
1771 { "Flash ROM writes", -1 },
1772 { "Zero area (all)", -1 }
1774 int mode = system_memory_guard(MEMGUARD_KEEP);
1776 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
1777 system_memory_guard(mode);
1779 return false;
1781 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
1783 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
1784 static bool dbg_write_eeprom(void)
1786 int fd;
1787 int rc;
1788 int old_irq_level;
1789 char buf[EEPROM_SIZE];
1790 int err;
1792 fd = open("/internal_eeprom.bin", O_RDONLY);
1794 if (fd >= 0)
1796 rc = read(fd, buf, EEPROM_SIZE);
1798 if(rc == EEPROM_SIZE)
1800 old_irq_level = disable_irq_save();
1802 err = eeprom_24cxx_write(0, buf, sizeof buf);
1803 if (err)
1804 splashf(HZ*3, "Eeprom write failure (%d)", err);
1805 else
1806 splash(HZ*3, "Eeprom written successfully");
1808 restore_irq(old_irq_level);
1810 else
1812 splashf(HZ*3, "File read error (%d)",rc);
1814 close(fd);
1816 else
1818 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
1821 return false;
1823 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
1824 #ifdef CPU_BOOST_LOGGING
1825 static bool cpu_boost_log(void)
1827 int i = 0,j=0;
1828 int count = cpu_boost_log_getcount();
1829 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
1830 char *str;
1831 bool done;
1832 lcd_setfont(FONT_SYSFIXED);
1833 str = cpu_boost_log_getlog_first();
1834 while (i < count)
1836 lcd_clear_display();
1837 for(j=0; j<lines; j++,i++)
1839 if (!str)
1840 str = cpu_boost_log_getlog_next();
1841 if (str)
1843 if(strlen(str) > LCD_WIDTH/SYSFONT_WIDTH)
1844 lcd_puts_scroll(0, j, str);
1845 else
1846 lcd_puts(0, j,str);
1848 str = NULL;
1850 lcd_update();
1851 done = false;
1852 while (!done)
1854 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
1856 case ACTION_STD_OK:
1857 case ACTION_STD_PREV:
1858 case ACTION_STD_NEXT:
1859 done = true;
1860 break;
1861 case ACTION_STD_CANCEL:
1862 i = count;
1863 done = true;
1864 break;
1868 lcd_stop_scroll();
1869 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
1870 lcd_setfont(FONT_UI);
1871 return false;
1873 #endif
1875 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) \
1876 && !defined(IPOD_MINI) && !defined(SIMULATOR))
1877 extern bool wheel_is_touched;
1878 extern int old_wheel_value;
1879 extern int new_wheel_value;
1880 extern int wheel_delta;
1881 extern unsigned int accumulated_wheel_delta;
1882 extern unsigned int wheel_velocity;
1884 static bool dbg_scrollwheel(void)
1886 unsigned int speed;
1888 lcd_setfont(FONT_SYSFIXED);
1890 while (1)
1892 if (action_userabort(HZ/10))
1893 break;
1895 lcd_clear_display();
1897 /* show internal variables of scrollwheel driver */
1898 lcd_putsf(0, 0, "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
1899 lcd_putsf(0, 1, "new position: %2d", new_wheel_value);
1900 lcd_putsf(0, 2, "old position: %2d", old_wheel_value);
1901 lcd_putsf(0, 3, "wheel delta: %2d", wheel_delta);
1902 lcd_putsf(0, 4, "accumulated delta: %2d", accumulated_wheel_delta);
1903 lcd_putsf(0, 5, "velo [deg/s]: %4d", (int)wheel_velocity);
1905 /* show effective accelerated scrollspeed */
1906 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
1907 lcd_putsf(0, 6, "accel. speed: %4d", speed);
1909 lcd_update();
1911 lcd_setfont(FONT_UI);
1912 return false;
1914 #endif
1916 #if defined (HAVE_USBSTACK)
1918 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
1919 static bool toggle_usb_core_driver(int driver, char *msg)
1921 bool enabled = !usb_core_driver_enabled(driver);
1923 usb_core_enable_driver(driver,enabled);
1924 splashf(HZ, "%s %s", msg, enabled?"enabled":"disabled");
1926 return false;
1929 static bool toggle_usb_serial(void)
1931 return toggle_usb_core_driver(USB_DRIVER_SERIAL,"USB Serial");
1933 #endif
1935 #endif
1937 #if CONFIG_USBOTG == USBOTG_ISP1583
1938 extern int dbg_usb_num_items(void);
1939 extern const char* dbg_usb_item(int selected_item, void *data,
1940 char *buffer, size_t buffer_len);
1942 static int isp1583_action_callback(int action, struct gui_synclist *lists)
1944 (void)lists;
1945 if (action == ACTION_NONE)
1946 action = ACTION_REDRAW;
1947 return action;
1950 static bool dbg_isp1583(void)
1952 struct simplelist_info isp1583;
1953 isp1583.scroll_all = true;
1954 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
1955 isp1583.timeout = HZ/100;
1956 isp1583.hide_selection = true;
1957 isp1583.get_name = dbg_usb_item;
1958 isp1583.action_callback = isp1583_action_callback;
1959 return simplelist_show_list(&isp1583);
1961 #endif
1963 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
1964 extern int pic_dbg_num_items(void);
1965 extern const char* pic_dbg_item(int selected_item, void *data,
1966 char *buffer, size_t buffer_len);
1968 static int pic_action_callback(int action, struct gui_synclist *lists)
1970 (void)lists;
1971 if (action == ACTION_NONE)
1972 action = ACTION_REDRAW;
1973 return action;
1976 static bool dbg_pic(void)
1978 struct simplelist_info pic;
1979 pic.scroll_all = true;
1980 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
1981 pic.timeout = HZ/100;
1982 pic.hide_selection = true;
1983 pic.get_name = pic_dbg_item;
1984 pic.action_callback = pic_action_callback;
1985 return simplelist_show_list(&pic);
1987 #endif
1990 /****** The menu *********/
1991 struct the_menu_item {
1992 unsigned char *desc; /* string or ID */
1993 bool (*function) (void); /* return true if USB was connected */
1995 static const struct the_menu_item menuitems[] = {
1996 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
1997 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)) || \
1998 CONFIG_CPU == IMX31L || defined(CPU_TCC780X)
1999 { "Dump ROM contents", dbg_save_roms },
2000 #endif
2001 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2002 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 \
2003 || CONFIG_CPU == DM320 || defined(CPU_S5L870X) || CONFIG_CPU == AS3525v2
2004 { "View I/O ports", dbg_ports },
2005 #endif
2006 #if (CONFIG_RTC == RTC_PCF50605) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
2007 { "View PCF registers", dbg_pcf },
2008 #endif
2009 #if defined(HAVE_TSC2100) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
2010 { "TSC2100 debug", tsc2100_debug },
2011 #endif
2012 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2013 { "CPU frequency", dbg_cpufreq },
2014 #endif
2015 #if CONFIG_CPU == IMX31L
2016 { "DVFS/DPTC", __dbg_dvfs_dptc },
2017 #endif
2018 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2019 { "S/PDIF analyzer", dbg_spdif },
2020 #endif
2021 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2022 { "Catch mem accesses", dbg_set_memory_guard },
2023 #endif
2024 { "View OS stacks", dbg_os },
2025 #ifdef HAVE_LCD_BITMAP
2026 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2027 { "View battery", view_battery },
2028 #endif
2029 { "Screendump", dbg_screendump },
2030 #endif
2031 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2032 { "View HW info", dbg_hw_info },
2033 #endif
2034 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2035 { "View partitions", dbg_partitions },
2036 #endif
2037 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2038 { "View disk info", dbg_disk_info },
2039 #if (CONFIG_STORAGE & STORAGE_ATA)
2040 { "Dump ATA identify info", dbg_identify_info},
2041 #endif
2042 #endif
2043 { "Metadata log", dbg_metadatalog },
2044 #ifdef HAVE_DIRCACHE
2045 { "View dircache info", dbg_dircache_info },
2046 #endif
2047 #ifdef HAVE_TAGCACHE
2048 { "View database info", dbg_tagcache_info },
2049 #endif
2050 #ifdef HAVE_LCD_BITMAP
2051 #if CONFIG_CODEC == SWCODEC
2052 { "View buffering thread", dbg_buffering_thread },
2053 #elif !defined(SIMULATOR)
2054 { "View audio thread", dbg_audio_thread },
2055 #endif
2056 #ifdef PM_DEBUG
2057 { "pm histogram", peak_meter_histogram},
2058 #endif /* PM_DEBUG */
2059 #endif /* HAVE_LCD_BITMAP */
2060 { "View buflib allocs", dbg_buflib_allocs },
2061 #ifndef SIMULATOR
2062 #if CONFIG_TUNER
2063 { "FM Radio", dbg_fm_radio },
2064 #endif
2065 #endif
2066 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2067 { "Write back EEPROM", dbg_write_eeprom },
2068 #endif
2069 #if CONFIG_USBOTG == USBOTG_ISP1583
2070 { "View ISP1583 info", dbg_isp1583 },
2071 #endif
2072 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2073 { "View PIC info", dbg_pic },
2074 #endif
2075 #ifdef ROCKBOX_HAS_LOGF
2076 {"Show Log File", logfdisplay },
2077 {"Dump Log File", logfdump },
2078 #endif
2079 #if defined(HAVE_USBSTACK)
2080 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2081 {"USB Serial driver (logf)", toggle_usb_serial },
2082 #endif
2083 #endif /* HAVE_USBSTACK */
2084 #ifdef CPU_BOOST_LOGGING
2085 {"cpu_boost log",cpu_boost_log},
2086 #endif
2087 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) \
2088 && !defined(IPOD_MINI) && !defined(SIMULATOR))
2089 {"Debug scrollwheel", dbg_scrollwheel },
2090 #endif
2092 static int menu_action_callback(int btn, struct gui_synclist *lists)
2094 int i;
2095 if (btn == ACTION_STD_OK)
2097 FOR_NB_SCREENS(i)
2098 viewportmanager_theme_enable(i, false, NULL);
2099 menuitems[gui_synclist_get_sel_pos(lists)].function();
2100 btn = ACTION_REDRAW;
2101 FOR_NB_SCREENS(i)
2102 viewportmanager_theme_undo(i, false);
2104 return btn;
2107 static const char* dbg_menu_getname(int item, void * data,
2108 char *buffer, size_t buffer_len)
2110 (void)data; (void)buffer; (void)buffer_len;
2111 return menuitems[item].desc;
2114 bool debug_menu(void)
2116 struct simplelist_info info;
2118 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2119 info.action_callback = menu_action_callback;
2120 info.get_name = dbg_menu_getname;
2121 return simplelist_show_list(&info);