Add stub STFM1000 tuner driver
[maemo-rb.git] / apps / debug_menu.c
blob2762c4b79b2ccf60f3f24e370f8314e808b4cea5
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 "lang.h"
29 #include "menu.h"
30 #include "debug_menu.h"
31 #include "kernel.h"
32 #include "structec.h"
33 #include "action.h"
34 #include "debug.h"
35 #include "thread.h"
36 #include "powermgmt.h"
37 #include "system.h"
38 #include "font.h"
39 #include "audio.h"
40 #include "mp3_playback.h"
41 #include "settings.h"
42 #include "list.h"
43 #include "statusbar.h"
44 #include "dir.h"
45 #include "panic.h"
46 #include "screens.h"
47 #include "misc.h"
48 #include "splash.h"
49 #include "shortcuts.h"
50 #include "dircache.h"
51 #include "viewport.h"
52 #ifdef HAVE_TAGCACHE
53 #include "tagcache.h"
54 #endif
55 #ifdef HAVE_REMOTE_LCD
56 #include "lcd-remote.h"
57 #endif
58 #include "crc32.h"
59 #include "logf.h"
60 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
61 #include "disk.h"
62 #include "adc.h"
63 #include "usb.h"
64 #include "rtc.h"
65 #include "storage.h"
66 #include "fat.h"
67 #include "eeprom_24cxx.h"
68 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
69 #include "sdmmc.h"
70 #endif
71 #if (CONFIG_STORAGE & STORAGE_ATA)
72 #include "ata.h"
73 #endif
74 #if CONFIG_TUNER
75 #include "tuner.h"
76 #include "radio.h"
77 #endif
78 #endif
79 #include "power.h"
81 #ifdef HAVE_LCD_BITMAP
82 #include "scrollbar.h"
83 #include "peakmeter.h"
84 #endif
85 #include "logfdisp.h"
86 #include "core_alloc.h"
87 #if CONFIG_CODEC == SWCODEC
88 #include "pcmbuf.h"
89 #include "buffering.h"
90 #include "playback.h"
91 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
92 #include "spdif.h"
93 #endif
94 #endif
95 #ifdef IRIVER_H300_SERIES
96 #include "pcf50606.h" /* for pcf50606_read */
97 #endif
98 #ifdef IAUDIO_X5
99 #include "ds2411.h"
100 #endif
101 #include "hwcompat.h"
102 #include "button.h"
103 #if CONFIG_RTC == RTC_PCF50605
104 #include "pcf50605.h"
105 #endif
106 #include "appevents.h"
108 #if defined(HAVE_AS3514) && defined(CONFIG_CHARGING)
109 #include "ascodec.h"
110 #endif
112 #ifdef IPOD_NANO2G
113 #include "pmu-target.h"
114 #endif
116 #ifdef HAVE_USBSTACK
117 #include "usb_core.h"
118 #endif
120 #if defined(IPOD_ACCESSORY_PROTOCOL)
121 #include "iap.h"
122 #endif
124 #ifdef HAVE_RDS_CAP
125 #include "rds.h"
126 #endif
128 /*---------------------------------------------------*/
129 /* SPECIAL DEBUG STUFF */
130 /*---------------------------------------------------*/
131 extern struct thread_entry threads[MAXTHREADS];
133 static char thread_status_char(unsigned status)
135 static const char thread_status_chars[THREAD_NUM_STATES+1] =
137 [0 ... THREAD_NUM_STATES] = '?',
138 [STATE_RUNNING] = 'R',
139 [STATE_BLOCKED] = 'B',
140 [STATE_SLEEPING] = 'S',
141 [STATE_BLOCKED_W_TMO] = 'T',
142 [STATE_FROZEN] = 'F',
143 [STATE_KILLED] = 'K',
146 if (status > THREAD_NUM_STATES)
147 status = THREAD_NUM_STATES;
149 return thread_status_chars[status];
152 static const char* threads_getname(int selected_item, void *data,
153 char *buffer, size_t buffer_len)
155 (void)data;
156 struct thread_entry *thread;
157 char name[32];
159 #if NUM_CORES > 1
160 if (selected_item < (int)NUM_CORES)
162 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
163 idle_stack_usage(selected_item));
164 return buffer;
167 selected_item -= NUM_CORES;
168 #endif
170 thread = &threads[selected_item];
172 if (thread->state == STATE_KILLED)
174 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
175 return buffer;
178 thread_get_name(name, 32, thread);
180 snprintf(buffer, buffer_len,
181 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
182 selected_item,
183 IF_COP(thread->core,)
184 #ifdef HAVE_SCHEDULER_BOOSTCTRL
185 (thread->cpu_boost) ? '+' :
186 #endif
187 ((thread->state == STATE_RUNNING) ? '*' : ' '),
188 thread_status_char(thread->state),
189 IF_PRIO(thread->base_priority, thread->priority, )
190 thread_stack_usage(thread), name);
192 return buffer;
195 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
197 (void)lists;
198 #ifdef ROCKBOX_HAS_LOGF
199 if (action == ACTION_STD_OK)
201 int selpos = gui_synclist_get_sel_pos(lists);
202 #if NUM_CORES > 1
203 if (selpos >= NUM_CORES)
204 remove_thread(threads[selpos - NUM_CORES].id);
205 #else
206 remove_thread(threads[selpos].id);
207 #endif
208 return ACTION_REDRAW;
210 #endif /* ROCKBOX_HAS_LOGF */
211 if (action == ACTION_NONE)
212 action = ACTION_REDRAW;
213 return action;
215 /* Test code!!! */
216 static bool dbg_os(void)
218 struct simplelist_info info;
219 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
220 #if NUM_CORES == 1
221 MAXTHREADS,
222 #else
223 MAXTHREADS+NUM_CORES,
224 #endif
225 NULL);
226 #ifndef ROCKBOX_HAS_LOGF
227 info.hide_selection = true;
228 info.scroll_all = true;
229 #endif
230 info.action_callback = dbg_threads_action_callback;
231 info.get_name = threads_getname;
232 return simplelist_show_list(&info);
235 #ifdef __linux__
236 #include "cpuinfo-linux.h"
238 #define MAX_STATES 16
239 static struct time_state states[MAX_STATES];
241 static const char* get_cpuinfo(int selected_item, void *data,
242 char *buffer, size_t buffer_len)
244 (void)data;(void)buffer_len;
245 const char* text;
246 long time, diff;
247 struct cpuusage us;
248 static struct cpuusage last_us;
249 int state_count = *(int*)data;
251 if (cpuusage_linux(&us) != 0)
252 return NULL;
254 switch(selected_item)
256 case 0:
257 diff = abs(last_us.usage - us.usage);
258 sprintf(buffer, "Usage: %ld.%02ld%% (%c %ld.%02ld)",
259 us.usage/100, us.usage%100,
260 (us.usage >= last_us.usage) ? '+':'-',
261 diff/100, diff%100);
262 last_us.usage = us.usage;
263 return buffer;
264 case 1:
265 text = "User";
266 time = us.utime;
267 diff = us.utime - last_us.utime;
268 last_us.utime = us.utime;
269 break;
270 case 2:
271 text = "Sys";
272 time = us.stime;
273 diff = us.stime - last_us.stime;
274 last_us.stime = us.stime;
275 break;
276 case 3:
277 text = "Real";
278 time = us.rtime;
279 diff = us.rtime - last_us.rtime;
280 last_us.rtime = us.rtime;
281 break;
282 case 4:
283 return "*** Per CPU freq stats ***";
284 default:
286 int cpu = (selected_item - 5) / (state_count + 1);
287 int cpu_line = (selected_item - 5) % (state_count + 1);
288 int freq1 = frequency_linux(cpu, false);
289 int freq2 = frequency_linux(cpu, true);
290 if (cpu_line == 0)
292 sprintf(buffer, " CPU%d: Cur/Scal freq: %d/%d MHz", cpu,
293 freq1 > 0 ? freq1/1000 : -1,
294 freq2 > 0 ? freq2/1000 : -1);
296 else
298 cpustatetimes_linux(cpu, states, ARRAYLEN(states));
299 snprintf(buffer, buffer_len, " %ld %ld",
300 states[cpu_line-1].frequency,
301 states[cpu_line-1].time);
303 return buffer;
306 sprintf(buffer, "%s: %ld.%02lds (+ %ld.%02ld)", text,
307 time / us.hz, time % us.hz,
308 diff / us.hz, diff % us.hz);
309 return buffer;
312 static int cpuinfo_cb(int action, struct gui_synclist *lists)
314 (void)lists;
315 if (action == ACTION_NONE)
316 action = ACTION_REDRAW;
317 return action;
320 static bool dbg_cpuinfo(void)
322 struct simplelist_info info;
323 int cpu_count = MAX(cpucount_linux(), 1);
324 int state_count = cpustatetimes_linux(0, states, ARRAYLEN(states));
325 printf("%s(): %d %d\n", __func__, cpu_count, state_count);
326 simplelist_info_init(&info, "CPU info:", 5 + cpu_count*(state_count+1), &state_count);
327 info.get_name = get_cpuinfo;
328 info.action_callback = cpuinfo_cb;
329 info.timeout = HZ;
330 info.hide_selection = true;
331 info.scroll_all = true;
332 return simplelist_show_list(&info);
335 #endif
337 #ifdef HAVE_LCD_BITMAP
338 #if CONFIG_CODEC != SWCODEC
339 #ifndef SIMULATOR
340 static bool dbg_audio_thread(void)
342 struct audio_debug d;
344 lcd_setfont(FONT_SYSFIXED);
346 while(1)
348 if (action_userabort(HZ/5))
349 return false;
351 audio_get_debugdata(&d);
353 lcd_clear_display();
355 lcd_putsf(0, 0, "read: %x", d.audiobuf_read);
356 lcd_putsf(0, 1, "write: %x", d.audiobuf_write);
357 lcd_putsf(0, 2, "swap: %x", d.audiobuf_swapwrite);
358 lcd_putsf(0, 3, "playing: %d", d.playing);
359 lcd_putsf(0, 4, "playable: %x", d.playable_space);
360 lcd_putsf(0, 5, "unswapped: %x", d.unswapped_space);
362 /* Playable space left */
363 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
364 d.playable_space, HORIZONTAL);
366 /* Show the watermark limit */
367 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
368 d.low_watermark_level, HORIZONTAL);
370 lcd_putsf(0, 7, "wm: %x - %x",
371 d.low_watermark_level, d.lowest_watermark_level);
373 lcd_update();
375 lcd_setfont(FONT_UI);
376 return false;
378 #endif /* !SIMULATOR */
379 #else /* CONFIG_CODEC == SWCODEC */
380 static unsigned int ticks, freq_sum;
381 #ifndef CPU_MULTI_FREQUENCY
382 static unsigned int boost_ticks;
383 #endif
385 static void dbg_audio_task(void)
387 #ifdef CPUFREQ_NORMAL
388 #ifndef CPU_MULTI_FREQUENCY
389 if(FREQ > CPUFREQ_NORMAL)
390 boost_ticks++;
391 #endif
392 freq_sum += FREQ/1000000; /* in MHz */
393 #endif
394 ticks++;
397 static bool dbg_buffering_thread(void)
399 int button;
400 int line;
401 bool done = false;
402 size_t bufused;
403 size_t bufsize = pcmbuf_get_bufsize();
404 int pcmbufdescs = pcmbuf_descs();
405 struct buffering_debug d;
406 size_t filebuflen = audio_get_filebuflen();
407 /* This is a size_t, but call it a long so it puts a - when it's bad. */
409 #ifndef CPU_MULTI_FREQUENCY
410 boost_ticks = 0;
411 #endif
412 ticks = freq_sum = 0;
414 tick_add_task(dbg_audio_task);
416 FOR_NB_SCREENS(i)
417 screens[i].setfont(FONT_SYSFIXED);
419 while(!done)
421 button = get_action(CONTEXT_STD,HZ/5);
422 switch(button)
424 case ACTION_STD_NEXT:
425 audio_next();
426 break;
427 case ACTION_STD_PREV:
428 audio_prev();
429 break;
430 case ACTION_STD_CANCEL:
431 done = true;
432 break;
435 buffering_get_debugdata(&d);
436 bufused = bufsize - pcmbuf_free();
438 FOR_NB_SCREENS(i)
440 line = 0;
441 screens[i].clear_display();
444 screens[i].putsf(0, line++, "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
446 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
447 bufsize, 0, bufused, HORIZONTAL);
448 line++;
450 screens[i].putsf(0, line++, "alloc: %6ld/%ld", audio_filebufused(),
451 (long) filebuflen);
453 #if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
454 if (screens[i].lcdheight > 80)
456 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
457 filebuflen, 0, audio_filebufused(), HORIZONTAL);
458 line++;
460 screens[i].putsf(0, line++, "real: %6ld/%ld", (long)d.buffered_data,
461 (long)filebuflen);
463 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
464 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
465 line++;
467 #endif
469 screens[i].putsf(0, line++, "usefl: %6ld/%ld", (long)(d.useful_data),
470 (long)filebuflen);
472 #if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
473 if (screens[i].lcdheight > 80)
475 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
476 filebuflen, 0, d.useful_data, HORIZONTAL);
477 line++;
479 #endif
481 screens[i].putsf(0, line++, "data_rem: %ld", (long)d.data_rem);
483 screens[i].putsf(0, line++, "track count: %2d", audio_track_count());
485 screens[i].putsf(0, line++, "handle count: %d", (int)d.num_handles);
487 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
488 screens[i].putsf(0, line++, "cpu freq: %3dMHz",
489 (int)((FREQ + 500000) / 1000000));
490 #endif
492 if (ticks > 0)
494 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
495 #ifdef CPU_MULTI_FREQUENCY
496 int boostquota = (avgclock * 100 - CPUFREQ_NORMAL/1000) /
497 ((CPUFREQ_MAX - CPUFREQ_NORMAL) / 1000000); /* in 0.1 % */
498 #else
499 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
500 #endif
501 screens[i].putsf(0, line++, "boost:%3d.%d%% (%d.%dMHz)",
502 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
505 screens[i].putsf(0, line++, "pcmbufdesc: %2d/%2d",
506 pcmbuf_used_descs(), pcmbufdescs);
507 screens[i].putsf(0, line++, "watermark: %6d",
508 (int)(d.watermark));
510 screens[i].update();
514 tick_remove_task(dbg_audio_task);
516 FOR_NB_SCREENS(i)
517 screens[i].setfont(FONT_UI);
519 return false;
521 #endif /* CONFIG_CODEC */
522 #endif /* HAVE_LCD_BITMAP */
524 static const char* bf_getname(int selected_item, void *data,
525 char *buffer, size_t buffer_len)
527 (void)data;
528 core_print_block_at(selected_item, buffer, buffer_len);
529 return buffer;
532 static int bf_action_cb(int action, struct gui_synclist* list)
534 if (action == ACTION_STD_OK)
536 if (gui_synclist_get_sel_pos(list) == 0 && core_test_free())
538 splash(HZ, "Freed test handle. New alloc should trigger compact");
540 else
542 splash(HZ/1, "Attempting a 64k allocation");
543 int handle = core_alloc("test", 64<<10);
544 splash(HZ/2, (handle > 0) ? "Success":"Fail");
545 /* for some reason simplelist doesn't allow adding items here if
546 * info.get_name is given, so use normal list api */
547 gui_synclist_set_nb_items(list, core_get_num_blocks());
548 if (handle > 0)
549 core_free(handle);
551 action = ACTION_REDRAW;
553 else if (action == ACTION_NONE)
554 action = ACTION_REDRAW;
555 return action;
558 static bool dbg_buflib_allocs(void)
560 struct simplelist_info info;
561 simplelist_info_init(&info, "mem allocs", core_get_num_blocks(), NULL);
562 info.get_name = bf_getname;
563 info.action_callback = bf_action_cb;
564 info.timeout = TIMEOUT_BLOCK;
565 return simplelist_show_list(&info);
568 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
569 static const char* dbg_partitions_getname(int selected_item, void *data,
570 char *buffer, size_t buffer_len)
572 (void)data;
573 int partition = selected_item/2;
574 struct partinfo* p = disk_partinfo(partition);
575 if (selected_item%2)
577 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / ( 2048 / ( SECTOR_SIZE / 512 )));
579 else
581 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
583 return buffer;
586 static bool dbg_partitions(void)
588 struct simplelist_info info;
589 simplelist_info_init(&info, "Partition Info", 4, NULL);
590 info.selection_size = 2;
591 info.hide_selection = true;
592 info.scroll_all = true;
593 info.get_name = dbg_partitions_getname;
594 return simplelist_show_list(&info);
596 #endif /* PLATFORM_NATIVE */
598 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
599 static bool dbg_spdif(void)
601 int line;
602 unsigned int control;
603 int x;
604 char *s;
605 int category;
606 int generation;
607 unsigned int interruptstat;
608 bool valnogood, symbolerr, parityerr;
609 bool done = false;
610 bool spdif_src_on;
611 int spdif_source = spdif_get_output_source(&spdif_src_on);
612 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
614 lcd_clear_display();
615 lcd_setfont(FONT_SYSFIXED);
617 #ifdef HAVE_SPDIF_POWER
618 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
619 #endif
621 while (!done)
623 line = 0;
625 control = EBU1RCVCCHANNEL1;
626 interruptstat = INTERRUPTSTAT;
627 INTERRUPTCLEAR = 0x03c00000;
629 valnogood = (interruptstat & 0x01000000)?true:false;
630 symbolerr = (interruptstat & 0x00800000)?true:false;
631 parityerr = (interruptstat & 0x00400000)?true:false;
633 lcd_putsf(0, line++, "Val: %s Sym: %s Par: %s",
634 valnogood?"--":"OK",
635 symbolerr?"--":"OK",
636 parityerr?"--":"OK");
638 lcd_putsf(0, line++, "Status word: %08x", (int)control);
640 line++;
642 x = control >> 31;
643 lcd_putsf(0, line++, "PRO: %d (%s)",
644 x, x?"Professional":"Consumer");
646 x = (control >> 30) & 1;
647 lcd_putsf(0, line++, "Audio: %d (%s)",
648 x, x?"Non-PCM":"PCM");
650 x = (control >> 29) & 1;
651 lcd_putsf(0, line++, "Copy: %d (%s)",
652 x, x?"Permitted":"Inhibited");
654 x = (control >> 27) & 7;
655 switch(x)
657 case 0:
658 s = "None";
659 break;
660 case 1:
661 s = "50/15us";
662 break;
663 default:
664 s = "Reserved";
665 break;
667 lcd_putsf(0, line++, "Preemphasis: %d (%s)", x, s);
669 x = (control >> 24) & 3;
670 lcd_putsf(0, line++, "Mode: %d", x);
672 category = (control >> 17) & 127;
673 switch(category)
675 case 0x00:
676 s = "General";
677 break;
678 case 0x40:
679 s = "Audio CD";
680 break;
681 default:
682 s = "Unknown";
684 lcd_putsf(0, line++, "Category: 0x%02x (%s)", category, s);
686 x = (control >> 16) & 1;
687 generation = x;
688 if(((category & 0x70) == 0x10) ||
689 ((category & 0x70) == 0x40) ||
690 ((category & 0x78) == 0x38))
692 generation = !generation;
694 lcd_putsf(0, line++, "Generation: %d (%s)",
695 x, generation?"Original":"No ind.");
697 x = (control >> 12) & 15;
698 lcd_putsf(0, line++, "Source: %d", x);
701 x = (control >> 8) & 15;
702 switch(x)
704 case 0:
705 s = "Unspecified";
706 break;
707 case 8:
708 s = "A (Left)";
709 break;
710 case 4:
711 s = "B (Right)";
712 break;
713 default:
714 s = "";
715 break;
717 lcd_putsf(0, line++, "Channel: %d (%s)", x, s);
719 x = (control >> 4) & 15;
720 switch(x)
722 case 0:
723 s = "44.1kHz";
724 break;
725 case 0x4:
726 s = "48kHz";
727 break;
728 case 0xc:
729 s = "32kHz";
730 break;
732 lcd_putsf(0, line++, "Frequency: %d (%s)", x, s);
734 x = (control >> 2) & 3;
735 lcd_putsf(0, line++, "Clock accuracy: %d", x);
736 line++;
738 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
739 lcd_putsf(0, line++, "Measured freq: %ldHz",
740 spdif_measure_frequency());
741 #endif
743 lcd_update();
745 if (action_userabort(HZ/10))
746 break;
749 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
751 #ifdef HAVE_SPDIF_POWER
752 spdif_power_enable(global_settings.spdif_enable);
753 #endif
755 lcd_setfont(FONT_UI);
756 return false;
758 #endif /* CPU_COLDFIRE */
760 #if (CONFIG_RTC == RTC_PCF50605) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
761 static bool dbg_pcf(void)
763 int line;
765 #ifdef HAVE_LCD_BITMAP
766 lcd_setfont(FONT_SYSFIXED);
767 #endif
768 lcd_clear_display();
770 while(1)
772 line = 0;
774 lcd_putsf(0, line++, "DCDC1: %02x", pcf50605_read(0x1b));
775 lcd_putsf(0, line++, "DCDC2: %02x", pcf50605_read(0x1c));
776 lcd_putsf(0, line++, "DCDC3: %02x", pcf50605_read(0x1d));
777 lcd_putsf(0, line++, "DCDC4: %02x", pcf50605_read(0x1e));
778 lcd_putsf(0, line++, "DCDEC1: %02x", pcf50605_read(0x1f));
779 lcd_putsf(0, line++, "DCDEC2: %02x", pcf50605_read(0x20));
780 lcd_putsf(0, line++, "DCUDC1: %02x", pcf50605_read(0x21));
781 lcd_putsf(0, line++, "DCUDC2: %02x", pcf50605_read(0x22));
782 lcd_putsf(0, line++, "IOREGC: %02x", pcf50605_read(0x23));
783 lcd_putsf(0, line++, "D1REGC: %02x", pcf50605_read(0x24));
784 lcd_putsf(0, line++, "D2REGC: %02x", pcf50605_read(0x25));
785 lcd_putsf(0, line++, "D3REGC: %02x", pcf50605_read(0x26));
786 lcd_putsf(0, line++, "LPREG1: %02x", pcf50605_read(0x27));
787 lcd_update();
788 if (action_userabort(HZ/10))
790 lcd_setfont(FONT_UI);
791 return false;
795 lcd_setfont(FONT_UI);
796 return false;
798 #endif
800 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
801 static bool dbg_cpufreq(void)
803 int line;
804 int button;
806 #ifdef HAVE_LCD_BITMAP
807 lcd_setfont(FONT_SYSFIXED);
808 #endif
809 lcd_clear_display();
811 while(1)
813 line = 0;
815 lcd_putsf(0, line++, "Frequency: %ld", FREQ);
816 lcd_putsf(0, line++, "boost_counter: %d", get_cpu_boost_counter());
818 lcd_update();
819 button = get_action(CONTEXT_STD,HZ/10);
821 switch(button)
823 case ACTION_STD_PREV:
824 cpu_boost(true);
825 break;
827 case ACTION_STD_NEXT:
828 cpu_boost(false);
829 break;
831 case ACTION_STD_OK:
832 while (get_cpu_boost_counter() > 0)
833 cpu_boost(false);
834 set_cpu_frequency(CPUFREQ_DEFAULT);
835 break;
837 case ACTION_STD_CANCEL:
838 lcd_setfont(FONT_UI);
839 return false;
842 lcd_setfont(FONT_UI);
843 return false;
845 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
847 #if defined(HAVE_TSC2100) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
848 #include "tsc2100.h"
849 static const char* tsc2100_debug_getname(int selected_item, void * data,
850 char *buffer, size_t buffer_len)
852 int *page = (int*)data;
853 bool reserved = false;
854 switch (*page)
856 case 0:
857 if ((selected_item > 0x0a) ||
858 (selected_item == 0x04) ||
859 (selected_item == 0x08))
860 reserved = true;
861 break;
862 case 1:
863 if ((selected_item > 0x05) ||
864 (selected_item == 0x02))
865 reserved = true;
866 break;
867 case 2:
868 if (selected_item > 0x1e)
869 reserved = true;
870 break;
872 if (reserved)
873 snprintf(buffer, buffer_len, "%02x: RSVD", selected_item);
874 else
875 snprintf(buffer, buffer_len, "%02x: %04x", selected_item,
876 tsc2100_readreg(*page, selected_item)&0xffff);
877 return buffer;
879 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
881 int *page = (int*)lists->data;
882 if (action == ACTION_STD_OK)
884 *page = (*page+1)%3;
885 snprintf(lists->title, 32,
886 "tsc2100 registers - Page %d", *page);
887 return ACTION_REDRAW;
889 return action;
891 static bool tsc2100_debug(void)
893 int page = 0;
894 char title[32] = "tsc2100 registers - Page 0";
895 struct simplelist_info info;
896 simplelist_info_init(&info, title, 32, &page);
897 info.timeout = HZ/100;
898 info.get_name = tsc2100_debug_getname;
899 info.action_callback= tsc2100debug_action_callback;
900 return simplelist_show_list(&info);
902 #endif
903 #if (CONFIG_BATTERY_MEASURE != 0) && defined(HAVE_LCD_BITMAP) && !defined(SIMULATOR)
905 * view_battery() shows a automatically scaled graph of the battery voltage
906 * over time. Usable for estimating battery life / charging rate.
907 * The power_history array is updated in power_thread of powermgmt.c.
910 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
911 #define BAT_TSPACE 20
912 #define BAT_YSPACE (LCD_HEIGHT - BAT_TSPACE)
915 static bool view_battery(void)
917 int view = 0;
918 int i, x, y, z, y1, y2, grid, graph;
919 unsigned short maxv, minv;
921 lcd_setfont(FONT_SYSFIXED);
923 while(1)
925 lcd_clear_display();
926 switch (view) {
927 case 0: /* voltage history graph */
928 /* Find maximum and minimum voltage for scaling */
929 minv = power_history[0];
930 maxv = minv + 1;
931 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
932 if (power_history[i] > maxv)
933 maxv = power_history[i];
934 if (power_history[i] < minv)
935 minv = power_history[i];
937 /* print header */
938 #if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
939 /* adjust grid scale */
940 if ((maxv - minv) > 50)
941 grid = 50;
942 else
943 grid = 5;
945 lcd_putsf(0, 0, "battery %d.%03dV", power_history[0] / 1000,
946 power_history[0] % 1000);
947 lcd_putsf(0, 1, "%d.%03d-%d.%03dV (%2dmV)",
948 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000,
949 grid);
950 #elif (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE)
951 /* adjust grid scale */
952 if ((maxv - minv) > 10)
953 grid = 10;
954 else
955 grid = 1;
956 lcd_putsf(0, 0, "battery %d%%", power_history[0]);
957 lcd_putsf(0, 1, "%d%%-%d%% (%d %%)", minv, maxv, grid);
958 #endif
960 i = 1;
961 while ((y = (minv - (minv % grid)+i*grid)) < maxv)
963 graph = ((y-minv)*BAT_YSPACE)/(maxv-minv);
964 graph = LCD_HEIGHT-1 - graph;
966 /* draw dotted horizontal grid line */
967 for (x=0; x<LCD_WIDTH;x=x+2)
968 lcd_drawpixel(x,graph);
970 i++;
973 x = 0;
974 /* draw plot of power history
975 * skip empty entries
977 for (i = BAT_LAST_VAL - 1; i > 0; i--)
979 if (power_history[i] && power_history[i-1])
981 y1 = (power_history[i] - minv) * BAT_YSPACE /
982 (maxv - minv);
983 y1 = MIN(MAX(LCD_HEIGHT-1 - y1, BAT_TSPACE),
984 LCD_HEIGHT-1);
985 y2 = (power_history[i-1] - minv) * BAT_YSPACE /
986 (maxv - minv);
987 y2 = MIN(MAX(LCD_HEIGHT-1 - y2, BAT_TSPACE),
988 LCD_HEIGHT-1);
990 lcd_set_drawmode(DRMODE_SOLID);
992 /* make line thicker */
993 lcd_drawline(((x*LCD_WIDTH)/(BAT_LAST_VAL)),
994 y1,
995 (((x+1)*LCD_WIDTH)/(BAT_LAST_VAL)),
996 y2);
997 lcd_drawline(((x*LCD_WIDTH)/(BAT_LAST_VAL))+1,
998 y1+1,
999 (((x+1)*LCD_WIDTH)/(BAT_LAST_VAL))+1,
1000 y2+1);
1001 x++;
1004 break;
1006 case 1: /* status: */
1007 #if CONFIG_CHARGING >= CHARGING_MONITOR
1008 lcd_putsf(0, 0, "Pwr status: %s",
1009 charging_state() ? "charging" : "discharging");
1010 #else
1011 lcd_puts(0, 0, "Power status: unknown");
1012 #endif
1013 battery_read_info(&y, &z);
1014 if (y > 0)
1015 lcd_putsf(0, 1, "Battery: %d.%03d V (%d %%)", y / 1000, y % 1000, z);
1016 else if (z > 0)
1017 lcd_putsf(0, 1, "Battery: %d %%", z);
1018 #ifdef ADC_EXT_POWER
1019 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1020 lcd_putsf(0, 2, "External: %d.%03d V", y / 1000, y % 1000);
1021 #endif
1022 #if CONFIG_CHARGING
1023 #if defined ARCHOS_RECORDER
1024 lcd_putsf(0, 3, "Chgr: %s %s",
1025 charger_inserted() ? "present" : "absent",
1026 charger_enabled() ? "on" : "off");
1027 lcd_putsf(0, 5, "short delta: %d", short_delta);
1028 lcd_putsf(0, 6, "long delta: %d", long_delta);
1029 lcd_puts(0, 7, power_message);
1030 lcd_putsf(0, 8, "USB Inserted: %s",
1031 usb_inserted() ? "yes" : "no");
1032 #elif defined IPOD_NANO || defined IPOD_VIDEO
1033 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1034 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1035 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1036 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1037 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1039 lcd_putsf(0, 3, "USB pwr: %s",
1040 usb_pwr ? "present" : "absent");
1041 lcd_putsf(0, 4, "EXT pwr: %s",
1042 ext_pwr ? "present" : "absent");
1043 lcd_putsf(0, 5, "Battery: %s",
1044 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1045 lcd_putsf(0, 6, "Dock mode: %s",
1046 dock ? "enabled" : "disabled");
1047 lcd_putsf(0, 7, "Headphone: %s",
1048 headphone ? "connected" : "disconnected");
1049 #ifdef IPOD_VIDEO
1050 if(probed_ramsize == 64)
1051 x = (adc_read(ADC_4066_ISTAT) * 2400) / (1024 * 2);
1052 else
1053 #endif
1054 x = (adc_read(ADC_4066_ISTAT) * 2400) / (1024 * 3);
1055 lcd_putsf(0, 8, "Ibat: %d mA", x);
1056 lcd_putsf(0, 9, "Vbat * Ibat: %d mW", x * y / 1000);
1057 #elif defined TOSHIBA_GIGABEAT_S
1058 int line = 3;
1059 unsigned int st;
1061 static const unsigned char * const chrgstate_strings[] =
1063 "Disabled",
1064 "Error",
1065 "Discharging",
1066 "Precharge",
1067 "Constant Voltage",
1068 "Constant Current",
1069 "<unknown>",
1072 lcd_putsf(0, line++, "Charger: %s",
1073 charger_inserted() ? "present" : "absent");
1075 st = power_input_status() &
1076 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1077 lcd_putsf(0, line++, "%s%s",
1078 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1079 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1081 y = ARRAYLEN(chrgstate_strings) - 1;
1083 switch (charge_state)
1085 case CHARGE_STATE_DISABLED: y--;
1086 case CHARGE_STATE_ERROR: y--;
1087 case DISCHARGING: y--;
1088 case TRICKLE: y--;
1089 case TOPOFF: y--;
1090 case CHARGING: y--;
1091 default:;
1094 lcd_putsf(0, line++, "State: %s", chrgstate_strings[y]);
1096 lcd_putsf(0, line++, "Battery Switch: %s",
1097 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1099 y = chrgraw_adc_voltage();
1100 lcd_putsf(0, line++, "CHRGRAW: %d.%03d V",
1101 y / 1000, y % 1000);
1103 y = application_supply_adc_voltage();
1104 lcd_putsf(0, line++, "BP : %d.%03d V",
1105 y / 1000, y % 1000);
1107 y = battery_adc_charge_current();
1108 if (y < 0) x = '-', y = -y;
1109 else x = ' ';
1110 lcd_putsf(0, line++, "CHRGISN:%c%d mA", x, y);
1112 y = cccv_regulator_dissipation();
1113 lcd_putsf(0, line++, "P CCCV : %d mW", y);
1115 y = battery_charge_current();
1116 if (y < 0) x = '-', y = -y;
1117 else x = ' ';
1118 lcd_putsf(0, line++, "I Charge:%c%d mA", x, y);
1120 y = battery_adc_temp();
1122 if (y != INT_MIN) {
1123 lcd_putsf(0, line++, "T Battery: %dC (%dF)", y,
1124 (9*y + 160) / 5);
1125 } else {
1126 /* Conversion disabled */
1127 lcd_puts(0, line++, "T Battery: ?");
1130 #elif defined(HAVE_AS3514) && defined(CONFIG_CHARGING)
1131 static const char * const chrgstate_strings[] =
1133 [CHARGE_STATE_DISABLED - CHARGE_STATE_DISABLED]= "Disabled",
1134 [CHARGE_STATE_ERROR - CHARGE_STATE_DISABLED] = "Error",
1135 [DISCHARGING - CHARGE_STATE_DISABLED] = "Discharging",
1136 [CHARGING - CHARGE_STATE_DISABLED] = "Charging",
1138 const char *str = NULL;
1140 lcd_putsf(0, 3, "Charger: %s",
1141 charger_inserted() ? "present" : "absent");
1143 y = charge_state - CHARGE_STATE_DISABLED;
1144 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1145 str = chrgstate_strings[y];
1147 lcd_putsf(0, 4, "State: %s",
1148 str ? str : "<unknown>");
1150 lcd_putsf(0, 5, "CHARGER: %02X", ascodec_read_charger());
1151 #elif defined(IPOD_NANO2G)
1152 y = pmu_read_battery_voltage();
1153 lcd_putsf(17, 1, "RAW: %d.%03d V", y / 1000, y % 1000);
1154 y = pmu_read_battery_current();
1155 lcd_putsf(0, 2, "Battery current: %d mA", y);
1156 lcd_putsf(0, 3, "PWRCON: %08x %08x", PWRCON, PWRCONEXT);
1157 lcd_putsf(0, 4, "CLKCON: %08x %03x %03x", CLKCON, CLKCON2, CLKCON3);
1158 lcd_putsf(0, 5, "PLL: %06x %06x %06x", PLL0PMS, PLL1PMS, PLL2PMS);
1159 x = pmu_read(0x1b) & 0xf;
1160 y = pmu_read(0x1a) * 25 + 625;
1161 lcd_putsf(0, 6, "AUTO: %x / %d mV", x, y);
1162 x = pmu_read(0x1f) & 0xf;
1163 y = pmu_read(0x1e) * 25 + 625;
1164 lcd_putsf(0, 7, "DOWN1: %x / %d mV", x, y);
1165 x = pmu_read(0x23) & 0xf;
1166 y = pmu_read(0x22) * 25 + 625;
1167 lcd_putsf(0, 8, "DOWN2: %x / %d mV", x, y);
1168 x = pmu_read(0x27) & 0xf;
1169 y = pmu_read(0x26) * 100 + 900;
1170 lcd_putsf(0, 9, "MEMLDO: %x / %d mV", x, y);
1171 for (i = 0; i < 6; i++)
1173 x = pmu_read(0x2e + (i << 1)) & 0xf;
1174 y = pmu_read(0x2d + (i << 1)) * 100 + 900;
1175 lcd_putsf(0, 10 + i, "LDO%d: %x / %d mV", i + 1, x, y);
1177 #else
1178 lcd_putsf(0, 3, "Charger: %s",
1179 charger_inserted() ? "present" : "absent");
1180 #endif /* target type */
1181 #endif /* CONFIG_CHARGING */
1182 break;
1183 case 2: /* voltage deltas: */
1184 #if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
1185 lcd_puts(0, 0, "Voltage deltas:");
1186 for (i = 0; i < POWER_HISTORY_LEN-1; i++) {
1187 y = power_history[i] - power_history[i+1];
1188 lcd_putsf(0, i+1, "-%d min: %c%d.%03d V", i,
1189 (y < 0) ? '-' : ' ', ((y < 0) ? y * -1 : y) / 1000,
1190 ((y < 0) ? y * -1 : y ) % 1000);
1192 #elif (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE)
1193 lcd_puts(0, 0, "Percentage deltas:");
1194 for (i = 0; i < POWER_HISTORY_LEN-1; i++) {
1195 y = power_history[i] - power_history[i+1];
1196 lcd_putsf(0, i+1, "-%d min: %c%d%%", i,
1197 (y < 0) ? '-' : ' ', ((y < 0) ? y * -1 : y));
1199 #endif
1200 break;
1202 case 3: /* remaining time estimation: */
1204 #ifdef ARCHOS_RECORDER
1205 lcd_putsf(0, 0, "charge_state: %d", charge_state);
1207 lcd_putsf(0, 1, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1209 lcd_putsf(0, 2, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1211 lcd_putsf(0, 3, "P=%2d I=%2d", pid_p, pid_i);
1213 lcd_putsf(0, 4, "Trickle sec: %d/60", trickle_sec);
1214 #endif /* ARCHOS_RECORDER */
1216 #if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
1217 lcd_putsf(0, 5, "Last PwrHist: %d.%03dV",
1218 power_history[0] / 1000,
1219 power_history[0] % 1000);
1220 #endif
1222 lcd_putsf(0, 6, "battery level: %d%%", battery_level());
1224 int time_left = battery_time();
1225 if (time_left >= 0)
1226 lcd_putsf(0, 7, "Est. remain: %d m", time_left);
1227 else
1228 lcd_puts(0, 7, "Estimation n/a");
1229 break;
1232 lcd_update();
1234 switch(get_action(CONTEXT_STD,HZ/2))
1236 case ACTION_STD_PREV:
1237 if (view)
1238 view--;
1239 break;
1241 case ACTION_STD_NEXT:
1242 if (view < 3)
1243 view++;
1244 break;
1246 case ACTION_STD_CANCEL:
1247 lcd_setfont(FONT_UI);
1248 return false;
1251 lcd_setfont(FONT_UI);
1252 return false;
1255 #endif /* (CONFIG_BATTERY_MEASURE != 0) && HAVE_LCD_BITMAP */
1257 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
1258 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1260 #if (CONFIG_STORAGE & STORAGE_MMC)
1261 #define CARDTYPE "MMC"
1262 #elif (CONFIG_STORAGE & STORAGE_SD)
1263 #define CARDTYPE "microSD"
1264 #endif
1266 static int disk_callback(int btn, struct gui_synclist *lists)
1268 tCardInfo *card;
1269 int *cardnum = (int*)lists->data;
1270 unsigned char card_name[6];
1271 unsigned char pbuf[32];
1272 char *title = lists->title;
1273 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1274 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1275 static const unsigned char * const kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1276 static const unsigned char * const nsec_units[] = { "ns", "µs", "ms" };
1277 #if (CONFIG_STORAGE & STORAGE_MMC)
1278 static const char * const mmc_spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1279 "3.1-3.31", "4.0" };
1280 #endif
1282 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1284 #ifdef HAVE_HOTSWAP
1285 if (btn == ACTION_STD_OK)
1287 *cardnum ^= 0x1; /* change cards */
1289 #endif
1291 simplelist_set_line_count(0);
1293 card = card_get_info(*cardnum);
1295 if (card->initialized > 0)
1297 unsigned i;
1298 for (i=0; i<sizeof(card_name); i++)
1300 card_name[i] = card_extract_bits(card->cid, (103-8*i), 8);
1302 strlcpy(card_name, card_name, sizeof(card_name));
1303 simplelist_addline(SIMPLELIST_ADD_LINE,
1304 "%s Rev %d.%d", card_name,
1305 (int) card_extract_bits(card->cid, 63, 4),
1306 (int) card_extract_bits(card->cid, 59, 4));
1307 simplelist_addline(SIMPLELIST_ADD_LINE,
1308 "Prod: %d/%d",
1309 #if (CONFIG_STORAGE & STORAGE_SD)
1310 (int) card_extract_bits(card->cid, 11, 4),
1311 (int) card_extract_bits(card->cid, 19, 8) + 2000
1312 #elif (CONFIG_STORAGE & STORAGE_MMC)
1313 (int) card_extract_bits(card->cid, 15, 4),
1314 (int) card_extract_bits(card->cid, 11, 4) + 1997
1315 #endif
1317 simplelist_addline(SIMPLELIST_ADD_LINE,
1318 #if (CONFIG_STORAGE & STORAGE_SD)
1319 "Ser#: 0x%08lx",
1320 card_extract_bits(card->cid, 55, 32)
1321 #elif (CONFIG_STORAGE & STORAGE_MMC)
1322 "Ser#: 0x%04lx",
1323 card_extract_bits(card->cid, 47, 16)
1324 #endif
1327 simplelist_addline(SIMPLELIST_ADD_LINE, "M=%02x, "
1328 #if (CONFIG_STORAGE & STORAGE_SD)
1329 "O=%c%c",
1330 (int) card_extract_bits(card->cid, 127, 8),
1331 card_extract_bits(card->cid, 119, 8),
1332 card_extract_bits(card->cid, 111, 8)
1333 #elif (CONFIG_STORAGE & STORAGE_MMC)
1334 "O=%04x",
1335 (int) card_extract_bits(card->cid, 127, 8),
1336 (int) card_extract_bits(card->cid, 119, 16)
1337 #endif
1340 #if (CONFIG_STORAGE & STORAGE_MMC)
1341 int temp = card_extract_bits(card->csd, 125, 4);
1342 simplelist_addline(SIMPLELIST_ADD_LINE,
1343 "MMC v%s", temp < 5 ?
1344 mmc_spec_vers[temp] : "?.?");
1345 #endif
1346 simplelist_addline(SIMPLELIST_ADD_LINE,
1347 "Blocks: 0x%08lx", card->numblocks);
1348 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1349 kbit_units, false);
1350 simplelist_addline(SIMPLELIST_ADD_LINE,
1351 "Speed: %s", pbuf);
1352 output_dyn_value(pbuf, sizeof pbuf, card->taac,
1353 nsec_units, false);
1354 simplelist_addline(SIMPLELIST_ADD_LINE,
1355 "Taac: %s", pbuf);
1356 simplelist_addline(SIMPLELIST_ADD_LINE,
1357 "Nsac: %d clk", card->nsac);
1358 simplelist_addline(SIMPLELIST_ADD_LINE,
1359 "R2W: *%d", card->r2w_factor);
1360 #if (CONFIG_STORAGE & STORAGE_SD)
1361 int csd_structure = card_extract_bits(card->csd, 127, 2);
1362 if (csd_structure == 0) /* CSD version 1.0 */
1363 #endif
1365 simplelist_addline(SIMPLELIST_ADD_LINE,
1366 "IRmax: %d..%d mA",
1367 i_vmin[card_extract_bits(card->csd, 61, 3)],
1368 i_vmax[card_extract_bits(card->csd, 58, 3)]);
1369 simplelist_addline(SIMPLELIST_ADD_LINE,
1370 "IWmax: %d..%d mA",
1371 i_vmin[card_extract_bits(card->csd, 55, 3)],
1372 i_vmax[card_extract_bits(card->csd, 52, 3)]);
1375 else if (card->initialized == 0)
1377 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1379 #if (CONFIG_STORAGE & STORAGE_SD)
1380 else /* card->initialized < 0 */
1382 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1384 #endif
1385 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1386 gui_synclist_set_title(lists, title, Icon_NOICON);
1387 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1388 gui_synclist_select_item(lists, 0);
1389 btn = ACTION_REDRAW;
1391 return btn;
1393 #elif (CONFIG_STORAGE & STORAGE_ATA)
1394 static int disk_callback(int btn, struct gui_synclist *lists)
1396 (void)lists;
1397 int i;
1398 char buf[128];
1399 unsigned short* identify_info = ata_get_identify();
1400 bool timing_info_present = false;
1401 (void)btn;
1403 simplelist_set_line_count(0);
1405 for (i=0; i < 20; i++)
1406 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1407 buf[40]=0;
1408 /* kill trailing space */
1409 for (i=39; i && buf[i]==' '; i--)
1410 buf[i] = 0;
1411 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1412 for (i=0; i < 4; i++)
1413 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1414 buf[8]=0;
1415 simplelist_addline(SIMPLELIST_ADD_LINE,
1416 "Firmware: %s", buf);
1417 snprintf(buf, sizeof buf, "%ld MB",
1418 ((unsigned long)identify_info[61] << 16 |
1419 (unsigned long)identify_info[60]) / 2048 );
1420 simplelist_addline(SIMPLELIST_ADD_LINE,
1421 "Size: %s", buf);
1422 unsigned long free;
1423 fat_size( IF_MV2(0,) NULL, &free );
1424 simplelist_addline(SIMPLELIST_ADD_LINE,
1425 "Free: %ld MB", free / 1024);
1426 simplelist_addline(SIMPLELIST_ADD_LINE,
1427 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
1428 i = identify_info[83] & (1<<3);
1429 simplelist_addline(SIMPLELIST_ADD_LINE,
1430 "Power mgmt: %s", i ? "enabled" : "unsupported");
1431 i = identify_info[83] & (1<<9);
1432 simplelist_addline(SIMPLELIST_ADD_LINE,
1433 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1434 i = identify_info[82] & (1<<6);
1435 simplelist_addline(SIMPLELIST_ADD_LINE,
1436 "Read-ahead: %s", i ? "enabled" : "unsupported");
1437 timing_info_present = identify_info[53] & (1<<1);
1438 if(timing_info_present) {
1439 char pio3[2], pio4[2];pio3[1] = 0;
1440 pio4[1] = 0;
1441 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1442 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1443 simplelist_addline(SIMPLELIST_ADD_LINE,
1444 "PIO modes: 0 1 2 %s %s", pio3, pio4);
1446 else {
1447 simplelist_addline(SIMPLELIST_ADD_LINE,
1448 "No PIO mode info");
1450 timing_info_present = identify_info[53] & (1<<1);
1451 if(timing_info_present) {
1452 simplelist_addline(SIMPLELIST_ADD_LINE,
1453 "Cycle times %dns/%dns",
1454 identify_info[67],
1455 identify_info[68] );
1456 } else {
1457 simplelist_addline(SIMPLELIST_ADD_LINE,
1458 "No timing info");
1460 int sector_size = 512;
1461 if((identify_info[106] & 0xe000) == 0x6000)
1462 sector_size *= BIT_N(identify_info[106] & 0x000f);
1463 simplelist_addline(SIMPLELIST_ADD_LINE,
1464 "Physical sector size: %d", sector_size);
1465 #ifdef HAVE_ATA_DMA
1466 if (identify_info[63] & (1<<0)) {
1467 char mdma0[2], mdma1[2], mdma2[2];
1468 mdma0[1] = mdma1[1] = mdma2[1] = 0;
1469 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
1470 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
1471 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
1472 simplelist_addline(SIMPLELIST_ADD_LINE,
1473 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
1474 simplelist_addline(SIMPLELIST_ADD_LINE,
1475 "MDMA Cycle times %dns/%dns",
1476 identify_info[65],
1477 identify_info[66] );
1479 else {
1480 simplelist_addline(SIMPLELIST_ADD_LINE,
1481 "No MDMA mode info");
1483 if (identify_info[53] & (1<<2)) {
1484 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2], udma6[2];
1485 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = udma6[1] = 0;
1486 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
1487 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
1488 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
1489 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
1490 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
1491 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
1492 udma6[0] = (identify_info[88] & (1<<6)) ? '6' : 0;
1493 simplelist_addline(SIMPLELIST_ADD_LINE,
1494 "UDMA modes: %s %s %s %s %s %s %s", udma0, udma1, udma2,
1495 udma3, udma4, udma5, udma6);
1497 else {
1498 simplelist_addline(SIMPLELIST_ADD_LINE,
1499 "No UDMA mode info");
1501 #endif /* HAVE_ATA_DMA */
1502 timing_info_present = identify_info[53] & (1<<1);
1503 if(timing_info_present) {
1504 i = identify_info[49] & (1<<11);
1505 simplelist_addline(SIMPLELIST_ADD_LINE,
1506 "IORDY support: %s", i ? "yes" : "no");
1507 i = identify_info[49] & (1<<10);
1508 simplelist_addline(SIMPLELIST_ADD_LINE,
1509 "IORDY disable: %s", i ? "yes" : "no");
1510 } else {
1511 simplelist_addline(SIMPLELIST_ADD_LINE,
1512 "No timing info");
1514 simplelist_addline(SIMPLELIST_ADD_LINE,
1515 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1516 #ifdef HAVE_ATA_DMA
1517 i = ata_get_dma_mode();
1518 if (i == 0) {
1519 simplelist_addline(SIMPLELIST_ADD_LINE,
1520 "DMA not enabled");
1521 } else {
1522 simplelist_addline(SIMPLELIST_ADD_LINE,
1523 "DMA mode: %s %c",
1524 (i & 0x40) ? "UDMA" : "MDMA",
1525 '0' + (i & 7));
1527 #endif /* HAVE_ATA_DMA */
1528 return btn;
1530 #else /* No SD, MMC or ATA */
1531 static int disk_callback(int btn, struct gui_synclist *lists)
1533 (void)lists;
1534 struct storage_info info;
1535 storage_get_info(0,&info);
1536 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
1537 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
1538 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
1539 simplelist_addline(SIMPLELIST_ADD_LINE,
1540 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
1541 unsigned long free;
1542 fat_size( IF_MV2(0,) NULL, &free );
1543 simplelist_addline(SIMPLELIST_ADD_LINE,
1544 "Free: %ld MB", free / 1024);
1545 simplelist_addline(SIMPLELIST_ADD_LINE,
1546 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1547 return btn;
1549 #endif
1551 #if (CONFIG_STORAGE & STORAGE_ATA)
1552 static bool dbg_identify_info(void)
1554 int fd = creat("/identify_info.bin", 0666);
1555 if(fd >= 0)
1557 #ifdef ROCKBOX_LITTLE_ENDIAN
1558 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
1559 #else
1560 write(fd, ata_get_identify(), SECTOR_SIZE);
1561 #endif
1562 close(fd);
1564 return false;
1566 #endif
1568 static bool dbg_disk_info(void)
1570 struct simplelist_info info;
1571 simplelist_info_init(&info, "Disk Info", 1, NULL);
1572 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1573 char title[16];
1574 int card = 0;
1575 info.callback_data = (void*)&card;
1576 info.title = title;
1577 #endif
1578 info.action_callback = disk_callback;
1579 info.hide_selection = true;
1580 info.scroll_all = true;
1581 return simplelist_show_list(&info);
1583 #endif /* PLATFORM_NATIVE */
1585 #ifdef HAVE_DIRCACHE
1586 static int dircache_callback(int btn, struct gui_synclist *lists)
1588 (void)lists;
1589 simplelist_set_line_count(0);
1590 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
1591 dircache_is_enabled() ? "Yes" : "No");
1592 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
1593 dircache_get_cache_size());
1594 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
1595 global_status.dircache_size);
1596 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
1597 DIRCACHE_LIMIT);
1598 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
1599 dircache_get_reserve_used(), DIRCACHE_RESERVE);
1600 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
1601 dircache_get_build_ticks() / HZ);
1602 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
1603 dircache_get_entry_count());
1604 return btn;
1607 static bool dbg_dircache_info(void)
1609 struct simplelist_info info;
1610 simplelist_info_init(&info, "Dircache Info", 7, NULL);
1611 info.action_callback = dircache_callback;
1612 info.hide_selection = true;
1613 info.scroll_all = true;
1614 return simplelist_show_list(&info);
1617 #endif /* HAVE_DIRCACHE */
1619 #ifdef HAVE_TAGCACHE
1620 static int database_callback(int btn, struct gui_synclist *lists)
1622 (void)lists;
1623 struct tagcache_stat *stat = tagcache_get_stat();
1624 static bool synced = false;
1626 simplelist_set_line_count(0);
1628 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
1629 stat->initialized ? "Yes" : "No");
1630 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
1631 stat->ready ? "Yes" : "No");
1632 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
1633 stat->ramcache ? "Yes" : "No");
1634 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
1635 stat->ramcache_used, stat->ramcache_allocated);
1636 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
1637 stat->progress, stat->processed_entries);
1638 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
1639 stat->curentry ? stat->curentry : "---");
1640 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
1641 stat->commit_step);
1642 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
1643 stat->commit_delayed ? "Yes" : "No");
1645 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
1646 stat->queue_length);
1648 if (synced)
1650 synced = false;
1651 tagcache_screensync_event();
1654 if (!btn && stat->curentry)
1656 synced = true;
1657 return ACTION_REDRAW;
1660 if (btn == ACTION_STD_CANCEL)
1661 tagcache_screensync_enable(false);
1663 return btn;
1665 static bool dbg_tagcache_info(void)
1667 struct simplelist_info info;
1668 simplelist_info_init(&info, "Database Info", 8, NULL);
1669 info.action_callback = database_callback;
1670 info.hide_selection = true;
1671 info.scroll_all = true;
1673 /* Don't do nonblock here, must give enough processing time
1674 for tagcache thread. */
1675 /* info.timeout = TIMEOUT_NOBLOCK; */
1676 info.timeout = 1;
1677 tagcache_screensync_enable(true);
1678 return simplelist_show_list(&info);
1680 #endif
1682 #if CONFIG_CPU == SH7034
1683 static bool dbg_save_roms(void)
1685 int fd;
1686 int oldmode = system_memory_guard(MEMGUARD_NONE);
1688 fd = creat("/internal_rom_0000-FFFF.bin", 0666);
1689 if(fd >= 0)
1691 write(fd, (void *)0, 0x10000);
1692 close(fd);
1695 fd = creat("/internal_rom_2000000-203FFFF.bin", 0666);
1696 if(fd >= 0)
1698 write(fd, (void *)0x2000000, 0x40000);
1699 close(fd);
1702 system_memory_guard(oldmode);
1703 return false;
1705 #elif defined CPU_COLDFIRE
1706 static bool dbg_save_roms(void)
1708 int fd;
1709 int oldmode = system_memory_guard(MEMGUARD_NONE);
1711 #if defined(IRIVER_H100_SERIES)
1712 fd = creat("/internal_rom_000000-1FFFFF.bin", 0666);
1713 #elif defined(IRIVER_H300_SERIES)
1714 fd = creat("/internal_rom_000000-3FFFFF.bin", 0666);
1715 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
1716 fd = creat("/internal_rom_000000-3FFFFF.bin", 0666);
1717 #elif defined(MPIO_HD200) || defined(MPIO_HD300)
1718 fd = creat("/internal_rom_000000-1FFFFF.bin", 0666);
1719 #endif
1720 if(fd >= 0)
1722 write(fd, (void *)0, FLASH_SIZE);
1723 close(fd);
1725 system_memory_guard(oldmode);
1727 #ifdef HAVE_EEPROM
1728 fd = creat("/internal_eeprom.bin", 0666);
1729 if (fd >= 0)
1731 int old_irq_level;
1732 char buf[EEPROM_SIZE];
1733 int err;
1735 old_irq_level = disable_irq_save();
1737 err = eeprom_24cxx_read(0, buf, sizeof buf);
1739 restore_irq(old_irq_level);
1741 if (err)
1742 splashf(HZ*3, "Eeprom read failure (%d)", err);
1743 else
1745 write(fd, buf, sizeof buf);
1748 close(fd);
1750 #endif
1752 return false;
1754 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
1755 static bool dbg_save_roms(void)
1757 int fd = creat("/internal_rom_000000-0FFFFF.bin", 0666);
1758 if(fd >= 0)
1760 write(fd, (void *)0x20000000, FLASH_SIZE);
1761 close(fd);
1764 return false;
1766 #elif CONFIG_CPU == IMX31L
1767 bool __dbg_dvfs_dptc(void);
1768 static bool dbg_save_roms(void)
1770 int fd = creat("/flash_rom_A0000000-A01FFFFF.bin", 0666);
1771 if (fd >= 0)
1773 write(fd, (void*)0xa0000000, FLASH_SIZE);
1774 close(fd);
1777 return false;
1779 #elif defined(CPU_TCC780X)
1780 static bool dbg_save_roms(void)
1782 int fd = creat("/eeprom_E0000000-E0001FFF.bin", 0666);
1783 if (fd >= 0)
1785 write(fd, (void*)0xe0000000, 0x2000);
1786 close(fd);
1789 return false;
1791 #endif /* CPU */
1793 #ifndef SIMULATOR
1794 #if CONFIG_TUNER
1796 #ifdef CONFIG_TUNER_MULTI
1797 static int tuner_type = 0;
1798 #define IF_TUNER_TYPE(type) if(tuner_type==type)
1799 #else
1800 #define IF_TUNER_TYPE(type)
1801 #endif
1803 static int radio_callback(int btn, struct gui_synclist *lists)
1805 (void)lists;
1806 if (btn == ACTION_STD_CANCEL)
1807 return btn;
1808 simplelist_set_line_count(1);
1810 #if (CONFIG_TUNER & LV24020LP)
1811 simplelist_addline(SIMPLELIST_ADD_LINE,
1812 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
1813 simplelist_addline(SIMPLELIST_ADD_LINE,
1814 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
1815 simplelist_addline(SIMPLELIST_ADD_LINE,
1816 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
1817 simplelist_addline(SIMPLELIST_ADD_LINE,
1818 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
1819 simplelist_addline(SIMPLELIST_ADD_LINE,
1820 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
1821 simplelist_addline(SIMPLELIST_ADD_LINE,
1822 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
1823 simplelist_addline(SIMPLELIST_ADD_LINE,
1824 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
1825 #endif /* LV24020LP */
1826 #if (CONFIG_TUNER & S1A0903X01)
1827 simplelist_addline(SIMPLELIST_ADD_LINE,
1828 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
1829 /* This one doesn't return dynamic data atm */
1830 #endif /* S1A0903X01 */
1831 #if (CONFIG_TUNER & TEA5767)
1832 struct tea5767_dbg_info nfo;
1833 tea5767_dbg_info(&nfo);
1834 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
1835 simplelist_addline(SIMPLELIST_ADD_LINE,
1836 " Read: %02X %02X %02X %02X %02X",
1837 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
1838 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
1839 (unsigned)nfo.read_regs[4]);
1840 simplelist_addline(SIMPLELIST_ADD_LINE,
1841 " Write: %02X %02X %02X %02X %02X",
1842 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
1843 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
1844 (unsigned)nfo.write_regs[4]);
1845 #endif /* TEA5767 */
1846 #if (CONFIG_TUNER & SI4700)
1847 IF_TUNER_TYPE(SI4700)
1849 struct si4700_dbg_info nfo;
1850 si4700_dbg_info(&nfo);
1851 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
1852 for (int i = 0; i < 16; i += 4) {
1853 simplelist_addline(SIMPLELIST_ADD_LINE,"%02X: %04X %04X %04X %04X",
1854 i, nfo.regs[i], nfo.regs[i+1], nfo.regs[i+2], nfo.regs[i+3]);
1857 #endif /* SI4700 */
1858 #if (CONFIG_TUNER & RDA5802)
1859 IF_TUNER_TYPE(RDA5802)
1861 struct rda5802_dbg_info nfo;
1862 rda5802_dbg_info(&nfo);
1863 simplelist_addline(SIMPLELIST_ADD_LINE, "RDA5802 regs:");
1864 for (int i = 0; i < 16; i += 4) {
1865 simplelist_addline(SIMPLELIST_ADD_LINE,"%02X: %04X %04X %04X %04X",
1866 i, nfo.regs[i], nfo.regs[i+1], nfo.regs[i+2], nfo.regs[i+3]);
1869 #endif /* RDA55802 */
1871 #ifdef HAVE_RDS_CAP
1872 simplelist_addline(SIMPLELIST_ADD_LINE, "PI:%04X PS:'%8s'",
1873 rds_get_pi(), rds_get_ps());
1874 simplelist_addline(SIMPLELIST_ADD_LINE, "RT:%s",
1875 rds_get_rt());
1876 time_t seconds = rds_get_ct();
1877 struct tm* time = gmtime(&seconds);
1878 simplelist_addline(SIMPLELIST_ADD_LINE,
1879 "CT:%4d-%02d-%02d %02d:%02d",
1880 time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
1881 time->tm_hour, time->tm_min, time->tm_sec);
1882 #endif
1883 return ACTION_REDRAW;
1885 static bool dbg_fm_radio(void)
1887 struct simplelist_info info;
1888 #ifdef CONFIG_TUNER_MULTI
1889 tuner_type = tuner_detect_type();
1890 #endif
1891 info.scroll_all = true;
1892 simplelist_info_init(&info, "FM Radio", 1, NULL);
1893 simplelist_set_line_count(0);
1894 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
1895 radio_hardware_present() ? "yes" : "no");
1897 info.action_callback = radio_hardware_present()?radio_callback : NULL;
1898 info.hide_selection = true;
1899 return simplelist_show_list(&info);
1901 #endif /* CONFIG_TUNER */
1902 #endif /* !SIMULATOR */
1904 #if defined(HAVE_LCD_BITMAP) && !defined(APPLICATION)
1905 extern bool do_screendump_instead_of_usb;
1907 static bool dbg_screendump(void)
1909 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
1910 splashf(HZ, "Screendump %sabled", do_screendump_instead_of_usb?"en":"dis");
1911 return false;
1913 #endif /* HAVE_LCD_BITMAP */
1915 extern bool write_metadata_log;
1917 static bool dbg_metadatalog(void)
1919 write_metadata_log = !write_metadata_log;
1920 splashf(HZ, "Metadata log %sabled", write_metadata_log ? "en" : "dis");
1921 return false;
1924 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
1925 static bool dbg_set_memory_guard(void)
1927 static const struct opt_items names[MAXMEMGUARD] = {
1928 { "None", -1 },
1929 { "Flash ROM writes", -1 },
1930 { "Zero area (all)", -1 }
1932 int mode = system_memory_guard(MEMGUARD_KEEP);
1934 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
1935 system_memory_guard(mode);
1937 return false;
1939 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
1941 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
1942 static bool dbg_write_eeprom(void)
1944 int fd = open("/internal_eeprom.bin", O_RDONLY);
1946 if (fd >= 0)
1948 char buf[EEPROM_SIZE];
1949 int rc = read(fd, buf, EEPROM_SIZE);
1951 if(rc == EEPROM_SIZE)
1953 int old_irq_level = disable_irq_save();
1955 int err = eeprom_24cxx_write(0, buf, sizeof buf);
1956 if (err)
1957 splashf(HZ*3, "Eeprom write failure (%d)", err);
1958 else
1959 splash(HZ*3, "Eeprom written successfully");
1961 restore_irq(old_irq_level);
1963 else
1965 splashf(HZ*3, "File read error (%d)",rc);
1967 close(fd);
1969 else
1971 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
1974 return false;
1976 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
1977 #ifdef CPU_BOOST_LOGGING
1978 static bool cpu_boost_log(void)
1980 int count = cpu_boost_log_getcount();
1981 char *str = cpu_boost_log_getlog_first();
1982 bool done;
1983 lcd_setfont(FONT_SYSFIXED);
1984 for (int i = 0; i < count ;)
1986 lcd_clear_display();
1987 for(int j=0; j<LCD_HEIGHT/SYSFONT_HEIGHT; j++,i++)
1989 if (!str)
1990 str = cpu_boost_log_getlog_next();
1991 if (str)
1993 if(strlen(str) > LCD_WIDTH/SYSFONT_WIDTH)
1994 lcd_puts_scroll(0, j, str);
1995 else
1996 lcd_puts(0, j,str);
1998 str = NULL;
2000 lcd_update();
2001 done = false;
2002 while (!done)
2004 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2006 case ACTION_STD_OK:
2007 case ACTION_STD_PREV:
2008 case ACTION_STD_NEXT:
2009 done = true;
2010 break;
2011 case ACTION_STD_CANCEL:
2012 i = count;
2013 done = true;
2014 break;
2018 lcd_stop_scroll();
2019 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2020 lcd_setfont(FONT_UI);
2021 return false;
2023 #endif
2025 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) \
2026 && !defined(IPOD_MINI) && !defined(SIMULATOR))
2027 extern bool wheel_is_touched;
2028 extern int old_wheel_value;
2029 extern int new_wheel_value;
2030 extern int wheel_delta;
2031 extern unsigned int accumulated_wheel_delta;
2032 extern unsigned int wheel_velocity;
2034 static bool dbg_scrollwheel(void)
2036 lcd_setfont(FONT_SYSFIXED);
2038 while (1)
2040 if (action_userabort(HZ/10))
2041 break;
2043 lcd_clear_display();
2045 /* show internal variables of scrollwheel driver */
2046 lcd_putsf(0, 0, "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2047 lcd_putsf(0, 1, "new position: %2d", new_wheel_value);
2048 lcd_putsf(0, 2, "old position: %2d", old_wheel_value);
2049 lcd_putsf(0, 3, "wheel delta: %2d", wheel_delta);
2050 lcd_putsf(0, 4, "accumulated delta: %2d", accumulated_wheel_delta);
2051 lcd_putsf(0, 5, "velo [deg/s]: %4d", (int)wheel_velocity);
2053 /* show effective accelerated scrollspeed */
2054 lcd_putsf(0, 6, "accel. speed: %4d",
2055 button_apply_acceleration((1<<31)|(1<<24)|wheel_velocity) );
2057 lcd_update();
2059 lcd_setfont(FONT_UI);
2060 return false;
2062 #endif
2064 #ifdef HAVE_USBSTACK
2065 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2066 static bool toggle_usb_serial(void)
2068 bool enabled = !usb_core_driver_enabled(USB_DRIVER_SERIAL);
2070 usb_core_enable_driver(USB_DRIVER_SERIAL, enabled);
2071 splashf(HZ, "USB Serial %sabled", enabled ? "en" : "dis");
2073 return false;
2075 #endif
2076 #endif
2078 #if CONFIG_USBOTG == USBOTG_ISP1583
2079 extern int dbg_usb_num_items(void);
2080 extern const char* dbg_usb_item(int selected_item, void *data,
2081 char *buffer, size_t buffer_len);
2083 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2085 (void)lists;
2086 if (action == ACTION_NONE)
2087 action = ACTION_REDRAW;
2088 return action;
2091 static bool dbg_isp1583(void)
2093 struct simplelist_info isp1583;
2094 isp1583.scroll_all = true;
2095 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2096 isp1583.timeout = HZ/100;
2097 isp1583.hide_selection = true;
2098 isp1583.get_name = dbg_usb_item;
2099 isp1583.action_callback = isp1583_action_callback;
2100 return simplelist_show_list(&isp1583);
2102 #endif
2104 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2105 extern int pic_dbg_num_items(void);
2106 extern const char* pic_dbg_item(int selected_item, void *data,
2107 char *buffer, size_t buffer_len);
2109 static int pic_action_callback(int action, struct gui_synclist *lists)
2111 (void)lists;
2112 if (action == ACTION_NONE)
2113 action = ACTION_REDRAW;
2114 return action;
2117 static bool dbg_pic(void)
2119 struct simplelist_info pic;
2120 pic.scroll_all = true;
2121 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2122 pic.timeout = HZ/100;
2123 pic.hide_selection = true;
2124 pic.get_name = pic_dbg_item;
2125 pic.action_callback = pic_action_callback;
2126 return simplelist_show_list(&pic);
2128 #endif
2131 /****** The menu *********/
2132 static const struct {
2133 unsigned char *desc; /* string or ID */
2134 bool (*function) (void); /* return true if USB was connected */
2135 } menuitems[] = {
2136 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2137 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)) || \
2138 CONFIG_CPU == IMX31L || defined(CPU_TCC780X)
2139 { "Dump ROM contents", dbg_save_roms },
2140 #endif
2141 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2142 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 \
2143 || CONFIG_CPU == DM320 || defined(CPU_S5L870X) || CONFIG_CPU == AS3525v2 \
2144 || CONFIG_CPU == RK27XX
2145 { "View I/O ports", dbg_ports },
2146 #endif
2147 #if (CONFIG_RTC == RTC_PCF50605) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
2148 { "View PCF registers", dbg_pcf },
2149 #endif
2150 #if defined(HAVE_TSC2100) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
2151 { "TSC2100 debug", tsc2100_debug },
2152 #endif
2153 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2154 { "CPU frequency", dbg_cpufreq },
2155 #endif
2156 #if CONFIG_CPU == IMX31L
2157 { "DVFS/DPTC", __dbg_dvfs_dptc },
2158 #endif
2159 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2160 { "S/PDIF analyzer", dbg_spdif },
2161 #endif
2162 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2163 { "Catch mem accesses", dbg_set_memory_guard },
2164 #endif
2165 { "View OS stacks", dbg_os },
2166 #ifdef __linux__
2167 { "View CPU stats", dbg_cpuinfo },
2168 #endif
2169 #ifdef HAVE_LCD_BITMAP
2170 #if (CONFIG_BATTERY_MEASURE != 0) && !defined(SIMULATOR)
2171 { "View battery", view_battery },
2172 #endif
2173 #ifndef APPLICATION
2174 { "Screendump", dbg_screendump },
2175 #endif
2176 #endif
2177 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2178 { "View HW info", dbg_hw_info },
2179 #endif
2180 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2181 { "View partitions", dbg_partitions },
2182 #endif
2183 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2184 { "View disk info", dbg_disk_info },
2185 #if (CONFIG_STORAGE & STORAGE_ATA)
2186 { "Dump ATA identify info", dbg_identify_info},
2187 #endif
2188 #endif
2189 { "Metadata log", dbg_metadatalog },
2190 #ifdef HAVE_DIRCACHE
2191 { "View dircache info", dbg_dircache_info },
2192 #endif
2193 #ifdef HAVE_TAGCACHE
2194 { "View database info", dbg_tagcache_info },
2195 #endif
2196 #ifdef HAVE_LCD_BITMAP
2197 #if CONFIG_CODEC == SWCODEC
2198 { "View buffering thread", dbg_buffering_thread },
2199 #elif !defined(SIMULATOR)
2200 { "View audio thread", dbg_audio_thread },
2201 #endif
2202 #ifdef PM_DEBUG
2203 { "pm histogram", peak_meter_histogram},
2204 #endif /* PM_DEBUG */
2205 #endif /* HAVE_LCD_BITMAP */
2206 { "View buflib allocs", dbg_buflib_allocs },
2207 #ifndef SIMULATOR
2208 #if CONFIG_TUNER
2209 { "FM Radio", dbg_fm_radio },
2210 #endif
2211 #endif
2212 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2213 { "Write back EEPROM", dbg_write_eeprom },
2214 #endif
2215 #if CONFIG_USBOTG == USBOTG_ISP1583
2216 { "View ISP1583 info", dbg_isp1583 },
2217 #endif
2218 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2219 { "View PIC info", dbg_pic },
2220 #endif
2221 #ifdef ROCKBOX_HAS_LOGF
2222 {"Show Log File", logfdisplay },
2223 {"Dump Log File", logfdump },
2224 #endif
2225 #if defined(HAVE_USBSTACK)
2226 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2227 {"USB Serial driver (logf)", toggle_usb_serial },
2228 #endif
2229 #endif /* HAVE_USBSTACK */
2230 #ifdef CPU_BOOST_LOGGING
2231 {"cpu_boost log",cpu_boost_log},
2232 #endif
2233 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) \
2234 && !defined(IPOD_MINI) && !defined(SIMULATOR))
2235 {"Debug scrollwheel", dbg_scrollwheel },
2236 #endif
2239 static int menu_action_callback(int btn, struct gui_synclist *lists)
2241 int selection = gui_synclist_get_sel_pos(lists);
2242 if (btn == ACTION_STD_OK)
2244 FOR_NB_SCREENS(i)
2245 viewportmanager_theme_enable(i, false, NULL);
2246 menuitems[selection].function();
2247 btn = ACTION_REDRAW;
2248 FOR_NB_SCREENS(i)
2249 viewportmanager_theme_undo(i, false);
2251 else if (btn == ACTION_STD_CONTEXT)
2253 MENUITEM_STRINGLIST(menu_items, "Debug Menu", NULL, ID2P(LANG_ADD_TO_FAVES));
2254 if (do_menu(&menu_items, NULL, NULL, false) == 0)
2255 shortcuts_add(SHORTCUT_DEBUGITEM, menuitems[selection].desc);
2256 return ACTION_STD_CANCEL;
2258 return btn;
2261 static const char* menu_get_name(int item, void * data,
2262 char *buffer, size_t buffer_len)
2264 (void)data; (void)buffer; (void)buffer_len;
2265 return menuitems[item].desc;
2268 bool debug_menu(void)
2270 struct simplelist_info info;
2272 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2273 info.action_callback = menu_action_callback;
2274 info.get_name = menu_get_name;
2275 return simplelist_show_list(&info);
2278 bool run_debug_screen(char* screen)
2280 for (unsigned i=0; i<ARRAYLEN(menuitems); i++)
2281 if (!strcmp(screen, menuitems[i].desc))
2283 FOR_NB_SCREENS(j)
2284 viewportmanager_theme_enable(j, false, NULL);
2285 menuitems[i].function();
2286 FOR_NB_SCREENS(j)
2287 viewportmanager_theme_undo(j, false);
2288 return true;
2291 return false;