Fix reds. No need for #ifdef to save buttons anymore.
[maemo-rb.git] / apps / debug_menu.c
bloba249a9be9aa92b9b14abdffc819f6b578d8a5414
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"
107 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
108 #include "debug-target.h"
109 #endif
111 #if defined(HAVE_AS3514) && defined(CONFIG_CHARGING)
112 #include "ascodec.h"
113 #endif
115 #ifdef IPOD_NANO2G
116 #include "pmu-target.h"
117 #endif
119 #ifdef HAVE_USBSTACK
120 #include "usb_core.h"
121 #endif
123 #if defined(IPOD_ACCESSORY_PROTOCOL)
124 #include "iap.h"
125 #endif
127 /*---------------------------------------------------*/
128 /* SPECIAL DEBUG STUFF */
129 /*---------------------------------------------------*/
130 extern struct thread_entry threads[MAXTHREADS];
132 static char thread_status_char(unsigned status)
134 static const char thread_status_chars[THREAD_NUM_STATES+1] =
136 [0 ... THREAD_NUM_STATES] = '?',
137 [STATE_RUNNING] = 'R',
138 [STATE_BLOCKED] = 'B',
139 [STATE_SLEEPING] = 'S',
140 [STATE_BLOCKED_W_TMO] = 'T',
141 [STATE_FROZEN] = 'F',
142 [STATE_KILLED] = 'K',
145 if (status > THREAD_NUM_STATES)
146 status = THREAD_NUM_STATES;
148 return thread_status_chars[status];
151 static const char* threads_getname(int selected_item, void *data,
152 char *buffer, size_t buffer_len)
154 (void)data;
155 struct thread_entry *thread;
156 char name[32];
158 #if NUM_CORES > 1
159 if (selected_item < (int)NUM_CORES)
161 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
162 idle_stack_usage(selected_item));
163 return buffer;
166 selected_item -= NUM_CORES;
167 #endif
169 thread = &threads[selected_item];
171 if (thread->state == STATE_KILLED)
173 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
174 return buffer;
177 thread_get_name(name, 32, thread);
179 snprintf(buffer, buffer_len,
180 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
181 selected_item,
182 IF_COP(thread->core,)
183 #ifdef HAVE_SCHEDULER_BOOSTCTRL
184 (thread->cpu_boost) ? '+' :
185 #endif
186 ((thread->state == STATE_RUNNING) ? '*' : ' '),
187 thread_status_char(thread->state),
188 IF_PRIO(thread->base_priority, thread->priority, )
189 thread_stack_usage(thread), name);
191 return buffer;
194 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
196 (void)lists;
197 #ifdef ROCKBOX_HAS_LOGF
198 if (action == ACTION_STD_OK)
200 int selpos = gui_synclist_get_sel_pos(lists);
201 #if NUM_CORES > 1
202 if (selpos >= NUM_CORES)
203 remove_thread(threads[selpos - NUM_CORES].id);
204 #else
205 remove_thread(threads[selpos].id);
206 #endif
207 return ACTION_REDRAW;
209 #endif /* ROCKBOX_HAS_LOGF */
210 if (action == ACTION_NONE)
211 action = ACTION_REDRAW;
212 return action;
214 /* Test code!!! */
215 static bool dbg_os(void)
217 struct simplelist_info info;
218 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
219 #if NUM_CORES == 1
220 MAXTHREADS,
221 #else
222 MAXTHREADS+NUM_CORES,
223 #endif
224 NULL);
225 #ifndef ROCKBOX_HAS_LOGF
226 info.hide_selection = true;
227 info.scroll_all = true;
228 #endif
229 info.action_callback = dbg_threads_action_callback;
230 info.get_name = threads_getname;
231 return simplelist_show_list(&info);
234 #ifdef __linux__
235 #include "cpuinfo-linux.h"
237 #define MAX_STATES 16
238 static struct time_state states[MAX_STATES];
240 static const char* get_cpuinfo(int selected_item, void *data,
241 char *buffer, size_t buffer_len)
243 (void)data;(void)buffer_len;
244 const char* text;
245 long time, diff;
246 struct cpuusage us;
247 static struct cpuusage last_us;
248 int state_count = *(int*)data;
250 if (cpuusage_linux(&us) != 0)
251 return NULL;
253 switch(selected_item)
255 case 0:
256 diff = abs(last_us.usage - us.usage);
257 sprintf(buffer, "Usage: %ld.%02ld%% (%c %ld.%02ld)",
258 us.usage/100, us.usage%100,
259 (us.usage >= last_us.usage) ? '+':'-',
260 diff/100, diff%100);
261 last_us.usage = us.usage;
262 return buffer;
263 case 1:
264 text = "User";
265 time = us.utime;
266 diff = us.utime - last_us.utime;
267 last_us.utime = us.utime;
268 break;
269 case 2:
270 text = "Sys";
271 time = us.stime;
272 diff = us.stime - last_us.stime;
273 last_us.stime = us.stime;
274 break;
275 case 3:
276 text = "Real";
277 time = us.rtime;
278 diff = us.rtime - last_us.rtime;
279 last_us.rtime = us.rtime;
280 break;
281 case 4:
282 return "*** Per CPU freq stats ***";
283 default:
285 int cpu = (selected_item - 5) / (state_count + 1);
286 int cpu_line = (selected_item - 5) % (state_count + 1);
287 int freq1 = frequency_linux(cpu, false);
288 int freq2 = frequency_linux(cpu, true);
289 if (cpu_line == 0)
291 sprintf(buffer, " CPU%d: Cur/Scal freq: %d/%d MHz", cpu,
292 freq1 > 0 ? freq1/1000 : -1,
293 freq2 > 0 ? freq2/1000 : -1);
295 else
297 cpustatetimes_linux(cpu, states, ARRAYLEN(states));
298 snprintf(buffer, buffer_len, " %ld %ld",
299 states[cpu_line-1].frequency,
300 states[cpu_line-1].time);
302 return buffer;
305 sprintf(buffer, "%s: %ld.%02lds (+ %ld.%02ld)", text,
306 time / us.hz, time % us.hz,
307 diff / us.hz, diff % us.hz);
308 return buffer;
311 static int cpuinfo_cb(int action, struct gui_synclist *lists)
313 (void)lists;
314 if (action == ACTION_NONE)
315 action = ACTION_REDRAW;
316 return action;
319 static bool dbg_cpuinfo(void)
321 struct simplelist_info info;
322 int cpu_count = MAX(cpucount_linux(), 1);
323 int state_count = cpustatetimes_linux(0, states, ARRAYLEN(states));
324 printf("%s(): %d %d\n", __func__, cpu_count, state_count);
325 simplelist_info_init(&info, "CPU info:", 5 + cpu_count*(state_count+1), &state_count);
326 info.get_name = get_cpuinfo;
327 info.action_callback = cpuinfo_cb;
328 info.timeout = HZ;
329 info.hide_selection = true;
330 info.scroll_all = true;
331 return simplelist_show_list(&info);
334 #endif
336 #ifdef HAVE_LCD_BITMAP
337 #if CONFIG_CODEC != SWCODEC
338 #ifndef SIMULATOR
339 static bool dbg_audio_thread(void)
341 struct audio_debug d;
343 lcd_setfont(FONT_SYSFIXED);
345 while(1)
347 if (action_userabort(HZ/5))
348 return false;
350 audio_get_debugdata(&d);
352 lcd_clear_display();
354 lcd_putsf(0, 0, "read: %x", d.audiobuf_read);
355 lcd_putsf(0, 1, "write: %x", d.audiobuf_write);
356 lcd_putsf(0, 2, "swap: %x", d.audiobuf_swapwrite);
357 lcd_putsf(0, 3, "playing: %d", d.playing);
358 lcd_putsf(0, 4, "playable: %x", d.playable_space);
359 lcd_putsf(0, 5, "unswapped: %x", d.unswapped_space);
361 /* Playable space left */
362 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
363 d.playable_space, HORIZONTAL);
365 /* Show the watermark limit */
366 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
367 d.low_watermark_level, HORIZONTAL);
369 lcd_putsf(0, 7, "wm: %x - %x",
370 d.low_watermark_level, d.lowest_watermark_level);
372 lcd_update();
374 lcd_setfont(FONT_UI);
375 return false;
377 #endif /* !SIMULATOR */
378 #else /* CONFIG_CODEC == SWCODEC */
379 static unsigned int ticks, freq_sum;
380 #ifndef CPU_MULTI_FREQUENCY
381 static unsigned int boost_ticks;
382 #endif
384 static void dbg_audio_task(void)
386 #ifdef CPUFREQ_NORMAL
387 #ifndef CPU_MULTI_FREQUENCY
388 if(FREQ > CPUFREQ_NORMAL)
389 boost_ticks++;
390 #endif
391 freq_sum += FREQ/1000000; /* in MHz */
392 #endif
393 ticks++;
396 static bool dbg_buffering_thread(void)
398 int button;
399 int line;
400 bool done = false;
401 size_t bufused;
402 size_t bufsize = pcmbuf_get_bufsize();
403 int pcmbufdescs = pcmbuf_descs();
404 struct buffering_debug d;
405 size_t filebuflen = audio_get_filebuflen();
406 /* This is a size_t, but call it a long so it puts a - when it's bad. */
408 #ifndef CPU_MULTI_FREQUENCY
409 boost_ticks = 0;
410 #endif
411 ticks = freq_sum = 0;
413 tick_add_task(dbg_audio_task);
415 FOR_NB_SCREENS(i)
416 screens[i].setfont(FONT_SYSFIXED);
418 while(!done)
420 button = get_action(CONTEXT_STD,HZ/5);
421 switch(button)
423 case ACTION_STD_NEXT:
424 audio_next();
425 break;
426 case ACTION_STD_PREV:
427 audio_prev();
428 break;
429 case ACTION_STD_CANCEL:
430 done = true;
431 break;
434 buffering_get_debugdata(&d);
435 bufused = bufsize - pcmbuf_free();
437 FOR_NB_SCREENS(i)
439 line = 0;
440 screens[i].clear_display();
443 screens[i].putsf(0, line++, "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
445 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
446 bufsize, 0, bufused, HORIZONTAL);
447 line++;
449 screens[i].putsf(0, line++, "alloc: %6ld/%ld", audio_filebufused(),
450 (long) filebuflen);
452 #if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
453 if (screens[i].lcdheight > 80)
455 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
456 filebuflen, 0, audio_filebufused(), HORIZONTAL);
457 line++;
459 screens[i].putsf(0, line++, "real: %6ld/%ld", (long)d.buffered_data,
460 (long)filebuflen);
462 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
463 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
464 line++;
466 #endif
468 screens[i].putsf(0, line++, "usefl: %6ld/%ld", (long)(d.useful_data),
469 (long)filebuflen);
471 #if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
472 if (screens[i].lcdheight > 80)
474 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
475 filebuflen, 0, d.useful_data, HORIZONTAL);
476 line++;
478 #endif
480 screens[i].putsf(0, line++, "data_rem: %ld", (long)d.data_rem);
482 screens[i].putsf(0, line++, "track count: %2d", audio_track_count());
484 screens[i].putsf(0, line++, "handle count: %d", (int)d.num_handles);
486 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
487 screens[i].putsf(0, line++, "cpu freq: %3dMHz",
488 (int)((FREQ + 500000) / 1000000));
489 #endif
491 if (ticks > 0)
493 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
494 #ifdef CPU_MULTI_FREQUENCY
495 int boostquota = (avgclock * 100 - CPUFREQ_NORMAL/1000) /
496 ((CPUFREQ_MAX - CPUFREQ_NORMAL) / 1000000); /* in 0.1 % */
497 #else
498 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
499 #endif
500 screens[i].putsf(0, line++, "boost:%3d.%d%% (%d.%dMHz)",
501 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
504 screens[i].putsf(0, line++, "pcmbufdesc: %2d/%2d",
505 pcmbuf_used_descs(), pcmbufdescs);
506 screens[i].putsf(0, line++, "watermark: %6d",
507 (int)(d.watermark));
509 screens[i].update();
513 tick_remove_task(dbg_audio_task);
515 FOR_NB_SCREENS(i)
516 screens[i].setfont(FONT_UI);
518 return false;
520 #endif /* CONFIG_CODEC */
521 #endif /* HAVE_LCD_BITMAP */
523 static const char* bf_getname(int selected_item, void *data,
524 char *buffer, size_t buffer_len)
526 (void)data;
527 core_print_block_at(selected_item, buffer, buffer_len);
528 return buffer;
531 static int bf_action_cb(int action, struct gui_synclist* list)
533 if (action == ACTION_STD_OK)
535 if (gui_synclist_get_sel_pos(list) == 0 && core_test_free())
537 splash(HZ, "Freed test handle. New alloc should trigger compact");
539 else
541 splash(HZ/1, "Attempting a 64k allocation");
542 int handle = core_alloc("test", 64<<10);
543 splash(HZ/2, (handle > 0) ? "Success":"Fail");
544 /* for some reason simplelist doesn't allow adding items here if
545 * info.get_name is given, so use normal list api */
546 gui_synclist_set_nb_items(list, core_get_num_blocks());
547 if (handle > 0)
548 core_free(handle);
550 action = ACTION_REDRAW;
552 else if (action == ACTION_NONE)
553 action = ACTION_REDRAW;
554 return action;
557 static bool dbg_buflib_allocs(void)
559 struct simplelist_info info;
560 simplelist_info_init(&info, "mem allocs", core_get_num_blocks(), NULL);
561 info.get_name = bf_getname;
562 info.action_callback = bf_action_cb;
563 info.timeout = TIMEOUT_BLOCK;
564 return simplelist_show_list(&info);
567 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
568 static const char* dbg_partitions_getname(int selected_item, void *data,
569 char *buffer, size_t buffer_len)
571 (void)data;
572 int partition = selected_item/2;
573 struct partinfo* p = disk_partinfo(partition);
574 if (selected_item%2)
576 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / ( 2048 / ( SECTOR_SIZE / 512 )));
578 else
580 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
582 return buffer;
585 static bool dbg_partitions(void)
587 struct simplelist_info info;
588 simplelist_info_init(&info, "Partition Info", 4, NULL);
589 info.selection_size = 2;
590 info.hide_selection = true;
591 info.scroll_all = true;
592 info.get_name = dbg_partitions_getname;
593 return simplelist_show_list(&info);
595 #endif /* PLATFORM_NATIVE */
597 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
598 static bool dbg_spdif(void)
600 int line;
601 unsigned int control;
602 int x;
603 char *s;
604 int category;
605 int generation;
606 unsigned int interruptstat;
607 bool valnogood, symbolerr, parityerr;
608 bool done = false;
609 bool spdif_src_on;
610 int spdif_source = spdif_get_output_source(&spdif_src_on);
611 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
613 lcd_clear_display();
614 lcd_setfont(FONT_SYSFIXED);
616 #ifdef HAVE_SPDIF_POWER
617 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
618 #endif
620 while (!done)
622 line = 0;
624 control = EBU1RCVCCHANNEL1;
625 interruptstat = INTERRUPTSTAT;
626 INTERRUPTCLEAR = 0x03c00000;
628 valnogood = (interruptstat & 0x01000000)?true:false;
629 symbolerr = (interruptstat & 0x00800000)?true:false;
630 parityerr = (interruptstat & 0x00400000)?true:false;
632 lcd_putsf(0, line++, "Val: %s Sym: %s Par: %s",
633 valnogood?"--":"OK",
634 symbolerr?"--":"OK",
635 parityerr?"--":"OK");
637 lcd_putsf(0, line++, "Status word: %08x", (int)control);
639 line++;
641 x = control >> 31;
642 lcd_putsf(0, line++, "PRO: %d (%s)",
643 x, x?"Professional":"Consumer");
645 x = (control >> 30) & 1;
646 lcd_putsf(0, line++, "Audio: %d (%s)",
647 x, x?"Non-PCM":"PCM");
649 x = (control >> 29) & 1;
650 lcd_putsf(0, line++, "Copy: %d (%s)",
651 x, x?"Permitted":"Inhibited");
653 x = (control >> 27) & 7;
654 switch(x)
656 case 0:
657 s = "None";
658 break;
659 case 1:
660 s = "50/15us";
661 break;
662 default:
663 s = "Reserved";
664 break;
666 lcd_putsf(0, line++, "Preemphasis: %d (%s)", x, s);
668 x = (control >> 24) & 3;
669 lcd_putsf(0, line++, "Mode: %d", x);
671 category = (control >> 17) & 127;
672 switch(category)
674 case 0x00:
675 s = "General";
676 break;
677 case 0x40:
678 s = "Audio CD";
679 break;
680 default:
681 s = "Unknown";
683 lcd_putsf(0, line++, "Category: 0x%02x (%s)", category, s);
685 x = (control >> 16) & 1;
686 generation = x;
687 if(((category & 0x70) == 0x10) ||
688 ((category & 0x70) == 0x40) ||
689 ((category & 0x78) == 0x38))
691 generation = !generation;
693 lcd_putsf(0, line++, "Generation: %d (%s)",
694 x, generation?"Original":"No ind.");
696 x = (control >> 12) & 15;
697 lcd_putsf(0, line++, "Source: %d", x);
700 x = (control >> 8) & 15;
701 switch(x)
703 case 0:
704 s = "Unspecified";
705 break;
706 case 8:
707 s = "A (Left)";
708 break;
709 case 4:
710 s = "B (Right)";
711 break;
712 default:
713 s = "";
714 break;
716 lcd_putsf(0, line++, "Channel: %d (%s)", x, s);
718 x = (control >> 4) & 15;
719 switch(x)
721 case 0:
722 s = "44.1kHz";
723 break;
724 case 0x4:
725 s = "48kHz";
726 break;
727 case 0xc:
728 s = "32kHz";
729 break;
731 lcd_putsf(0, line++, "Frequency: %d (%s)", x, s);
733 x = (control >> 2) & 3;
734 lcd_putsf(0, line++, "Clock accuracy: %d", x);
735 line++;
737 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
738 lcd_putsf(0, line++, "Measured freq: %ldHz",
739 spdif_measure_frequency());
740 #endif
742 lcd_update();
744 if (action_userabort(HZ/10))
745 break;
748 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
750 #ifdef HAVE_SPDIF_POWER
751 spdif_power_enable(global_settings.spdif_enable);
752 #endif
754 lcd_setfont(FONT_UI);
755 return false;
757 #endif /* CPU_COLDFIRE */
759 #if (CONFIG_RTC == RTC_PCF50605) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
760 static bool dbg_pcf(void)
762 int line;
764 #ifdef HAVE_LCD_BITMAP
765 lcd_setfont(FONT_SYSFIXED);
766 #endif
767 lcd_clear_display();
769 while(1)
771 line = 0;
773 lcd_putsf(0, line++, "DCDC1: %02x", pcf50605_read(0x1b));
774 lcd_putsf(0, line++, "DCDC2: %02x", pcf50605_read(0x1c));
775 lcd_putsf(0, line++, "DCDC3: %02x", pcf50605_read(0x1d));
776 lcd_putsf(0, line++, "DCDC4: %02x", pcf50605_read(0x1e));
777 lcd_putsf(0, line++, "DCDEC1: %02x", pcf50605_read(0x1f));
778 lcd_putsf(0, line++, "DCDEC2: %02x", pcf50605_read(0x20));
779 lcd_putsf(0, line++, "DCUDC1: %02x", pcf50605_read(0x21));
780 lcd_putsf(0, line++, "DCUDC2: %02x", pcf50605_read(0x22));
781 lcd_putsf(0, line++, "IOREGC: %02x", pcf50605_read(0x23));
782 lcd_putsf(0, line++, "D1REGC: %02x", pcf50605_read(0x24));
783 lcd_putsf(0, line++, "D2REGC: %02x", pcf50605_read(0x25));
784 lcd_putsf(0, line++, "D3REGC: %02x", pcf50605_read(0x26));
785 lcd_putsf(0, line++, "LPREG1: %02x", pcf50605_read(0x27));
786 lcd_update();
787 if (action_userabort(HZ/10))
789 lcd_setfont(FONT_UI);
790 return false;
794 lcd_setfont(FONT_UI);
795 return false;
797 #endif
799 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
800 static bool dbg_cpufreq(void)
802 int line;
803 int button;
805 #ifdef HAVE_LCD_BITMAP
806 lcd_setfont(FONT_SYSFIXED);
807 #endif
808 lcd_clear_display();
810 while(1)
812 line = 0;
814 lcd_putsf(0, line++, "Frequency: %ld", FREQ);
815 lcd_putsf(0, line++, "boost_counter: %d", get_cpu_boost_counter());
817 lcd_update();
818 button = get_action(CONTEXT_STD,HZ/10);
820 switch(button)
822 case ACTION_STD_PREV:
823 cpu_boost(true);
824 break;
826 case ACTION_STD_NEXT:
827 cpu_boost(false);
828 break;
830 case ACTION_STD_OK:
831 while (get_cpu_boost_counter() > 0)
832 cpu_boost(false);
833 set_cpu_frequency(CPUFREQ_DEFAULT);
834 break;
836 case ACTION_STD_CANCEL:
837 lcd_setfont(FONT_UI);
838 return false;
841 lcd_setfont(FONT_UI);
842 return false;
844 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
846 #if defined(HAVE_TSC2100) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
847 #include "tsc2100.h"
848 static const char* tsc2100_debug_getname(int selected_item, void * data,
849 char *buffer, size_t buffer_len)
851 int *page = (int*)data;
852 bool reserved = false;
853 switch (*page)
855 case 0:
856 if ((selected_item > 0x0a) ||
857 (selected_item == 0x04) ||
858 (selected_item == 0x08))
859 reserved = true;
860 break;
861 case 1:
862 if ((selected_item > 0x05) ||
863 (selected_item == 0x02))
864 reserved = true;
865 break;
866 case 2:
867 if (selected_item > 0x1e)
868 reserved = true;
869 break;
871 if (reserved)
872 snprintf(buffer, buffer_len, "%02x: RSVD", selected_item);
873 else
874 snprintf(buffer, buffer_len, "%02x: %04x", selected_item,
875 tsc2100_readreg(*page, selected_item)&0xffff);
876 return buffer;
878 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
880 int *page = (int*)lists->data;
881 if (action == ACTION_STD_OK)
883 *page = (*page+1)%3;
884 snprintf(lists->title, 32,
885 "tsc2100 registers - Page %d", *page);
886 return ACTION_REDRAW;
888 return action;
890 static bool tsc2100_debug(void)
892 int page = 0;
893 char title[32] = "tsc2100 registers - Page 0";
894 struct simplelist_info info;
895 simplelist_info_init(&info, title, 32, &page);
896 info.timeout = HZ/100;
897 info.get_name = tsc2100_debug_getname;
898 info.action_callback= tsc2100debug_action_callback;
899 return simplelist_show_list(&info);
901 #endif
902 #if (CONFIG_BATTERY_MEASURE != 0) && defined(HAVE_LCD_BITMAP) && !defined(SIMULATOR)
904 * view_battery() shows a automatically scaled graph of the battery voltage
905 * over time. Usable for estimating battery life / charging rate.
906 * The power_history array is updated in power_thread of powermgmt.c.
909 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
910 #define BAT_TSPACE 20
911 #define BAT_YSPACE (LCD_HEIGHT - BAT_TSPACE)
914 static bool view_battery(void)
916 int view = 0;
917 int i, x, y, z, y1, y2, grid, graph;
918 unsigned short maxv, minv;
920 lcd_setfont(FONT_SYSFIXED);
922 while(1)
924 lcd_clear_display();
925 switch (view) {
926 case 0: /* voltage history graph */
927 /* Find maximum and minimum voltage for scaling */
928 minv = power_history[0];
929 maxv = minv + 1;
930 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
931 if (power_history[i] > maxv)
932 maxv = power_history[i];
933 if (power_history[i] < minv)
934 minv = power_history[i];
936 /* print header */
937 #if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
938 /* adjust grid scale */
939 if ((maxv - minv) > 50)
940 grid = 50;
941 else
942 grid = 5;
944 lcd_putsf(0, 0, "battery %d.%03dV", power_history[0] / 1000,
945 power_history[0] % 1000);
946 lcd_putsf(0, 1, "%d.%03d-%d.%03dV (%2dmV)",
947 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000,
948 grid);
949 #elif (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE)
950 /* adjust grid scale */
951 if ((maxv - minv) > 10)
952 grid = 10;
953 else
954 grid = 1;
955 lcd_putsf(0, 0, "battery %d%%", power_history[0]);
956 lcd_putsf(0, 1, "%d%%-%d%% (%d %%)", minv, maxv, grid);
957 #endif
959 i = 1;
960 while ((y = (minv - (minv % grid)+i*grid)) < maxv)
962 graph = ((y-minv)*BAT_YSPACE)/(maxv-minv);
963 graph = LCD_HEIGHT-1 - graph;
965 /* draw dotted horizontal grid line */
966 for (x=0; x<LCD_WIDTH;x=x+2)
967 lcd_drawpixel(x,graph);
969 i++;
972 x = 0;
973 /* draw plot of power history
974 * skip empty entries
976 for (i = BAT_LAST_VAL - 1; i > 0; i--)
978 if (power_history[i] && power_history[i-1])
980 y1 = (power_history[i] - minv) * BAT_YSPACE /
981 (maxv - minv);
982 y1 = MIN(MAX(LCD_HEIGHT-1 - y1, BAT_TSPACE),
983 LCD_HEIGHT-1);
984 y2 = (power_history[i-1] - minv) * BAT_YSPACE /
985 (maxv - minv);
986 y2 = MIN(MAX(LCD_HEIGHT-1 - y2, BAT_TSPACE),
987 LCD_HEIGHT-1);
989 lcd_set_drawmode(DRMODE_SOLID);
991 /* make line thicker */
992 lcd_drawline(((x*LCD_WIDTH)/(BAT_LAST_VAL)),
993 y1,
994 (((x+1)*LCD_WIDTH)/(BAT_LAST_VAL)),
995 y2);
996 lcd_drawline(((x*LCD_WIDTH)/(BAT_LAST_VAL))+1,
997 y1+1,
998 (((x+1)*LCD_WIDTH)/(BAT_LAST_VAL))+1,
999 y2+1);
1000 x++;
1003 break;
1005 case 1: /* status: */
1006 #if CONFIG_CHARGING >= CHARGING_MONITOR
1007 lcd_putsf(0, 0, "Pwr status: %s",
1008 charging_state() ? "charging" : "discharging");
1009 #else
1010 lcd_puts(0, 0, "Power status: unknown");
1011 #endif
1012 battery_read_info(&y, &z);
1013 if (y > 0)
1014 lcd_putsf(0, 1, "Battery: %d.%03d V (%d %%)", y / 1000, y % 1000, z);
1015 else if (z > 0)
1016 lcd_putsf(0, 1, "Battery: %d %%", z);
1017 #ifdef ADC_EXT_POWER
1018 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1019 lcd_putsf(0, 2, "External: %d.%03d V", y / 1000, y % 1000);
1020 #endif
1021 #if CONFIG_CHARGING
1022 #if defined ARCHOS_RECORDER
1023 lcd_putsf(0, 3, "Chgr: %s %s",
1024 charger_inserted() ? "present" : "absent",
1025 charger_enabled() ? "on" : "off");
1026 lcd_putsf(0, 5, "short delta: %d", short_delta);
1027 lcd_putsf(0, 6, "long delta: %d", long_delta);
1028 lcd_puts(0, 7, power_message);
1029 lcd_putsf(0, 8, "USB Inserted: %s",
1030 usb_inserted() ? "yes" : "no");
1031 #elif defined IPOD_NANO || defined IPOD_VIDEO
1032 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1033 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1034 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1035 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1036 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1038 lcd_putsf(0, 3, "USB pwr: %s",
1039 usb_pwr ? "present" : "absent");
1040 lcd_putsf(0, 4, "EXT pwr: %s",
1041 ext_pwr ? "present" : "absent");
1042 lcd_putsf(0, 5, "Battery: %s",
1043 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1044 lcd_putsf(0, 6, "Dock mode: %s",
1045 dock ? "enabled" : "disabled");
1046 lcd_putsf(0, 7, "Headphone: %s",
1047 headphone ? "connected" : "disconnected");
1048 #ifdef IPOD_VIDEO
1049 if(probed_ramsize == 64)
1050 x = (adc_read(ADC_4066_ISTAT) * 2400) / (1024 * 2);
1051 else
1052 #endif
1053 x = (adc_read(ADC_4066_ISTAT) * 2400) / (1024 * 3);
1054 lcd_putsf(0, 8, "Ibat: %d mA", x);
1055 lcd_putsf(0, 9, "Vbat * Ibat: %d mW", x * y / 1000);
1056 #elif defined TOSHIBA_GIGABEAT_S
1057 int line = 3;
1058 unsigned int st;
1060 static const unsigned char * const chrgstate_strings[] =
1062 "Disabled",
1063 "Error",
1064 "Discharging",
1065 "Precharge",
1066 "Constant Voltage",
1067 "Constant Current",
1068 "<unknown>",
1071 lcd_putsf(0, line++, "Charger: %s",
1072 charger_inserted() ? "present" : "absent");
1074 st = power_input_status() &
1075 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1076 lcd_putsf(0, line++, "%s%s",
1077 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1078 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1080 y = ARRAYLEN(chrgstate_strings) - 1;
1082 switch (charge_state)
1084 case CHARGE_STATE_DISABLED: y--;
1085 case CHARGE_STATE_ERROR: y--;
1086 case DISCHARGING: y--;
1087 case TRICKLE: y--;
1088 case TOPOFF: y--;
1089 case CHARGING: y--;
1090 default:;
1093 lcd_putsf(0, line++, "State: %s", chrgstate_strings[y]);
1095 lcd_putsf(0, line++, "Battery Switch: %s",
1096 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1098 y = chrgraw_adc_voltage();
1099 lcd_putsf(0, line++, "CHRGRAW: %d.%03d V",
1100 y / 1000, y % 1000);
1102 y = application_supply_adc_voltage();
1103 lcd_putsf(0, line++, "BP : %d.%03d V",
1104 y / 1000, y % 1000);
1106 y = battery_adc_charge_current();
1107 if (y < 0) x = '-', y = -y;
1108 else x = ' ';
1109 lcd_putsf(0, line++, "CHRGISN:%c%d mA", x, y);
1111 y = cccv_regulator_dissipation();
1112 lcd_putsf(0, line++, "P CCCV : %d mW", y);
1114 y = battery_charge_current();
1115 if (y < 0) x = '-', y = -y;
1116 else x = ' ';
1117 lcd_putsf(0, line++, "I Charge:%c%d mA", x, y);
1119 y = battery_adc_temp();
1121 if (y != INT_MIN) {
1122 lcd_putsf(0, line++, "T Battery: %dC (%dF)", y,
1123 (9*y + 160) / 5);
1124 } else {
1125 /* Conversion disabled */
1126 lcd_puts(0, line++, "T Battery: ?");
1129 #elif defined(HAVE_AS3514) && defined(CONFIG_CHARGING)
1130 static const char * const chrgstate_strings[] =
1132 [CHARGE_STATE_DISABLED - CHARGE_STATE_DISABLED]= "Disabled",
1133 [CHARGE_STATE_ERROR - CHARGE_STATE_DISABLED] = "Error",
1134 [DISCHARGING - CHARGE_STATE_DISABLED] = "Discharging",
1135 [CHARGING - CHARGE_STATE_DISABLED] = "Charging",
1137 const char *str = NULL;
1139 lcd_putsf(0, 3, "Charger: %s",
1140 charger_inserted() ? "present" : "absent");
1142 y = charge_state - CHARGE_STATE_DISABLED;
1143 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1144 str = chrgstate_strings[y];
1146 lcd_putsf(0, 4, "State: %s",
1147 str ? str : "<unknown>");
1149 lcd_putsf(0, 5, "CHARGER: %02X", ascodec_read_charger());
1150 #elif defined(IPOD_NANO2G)
1151 y = pmu_read_battery_voltage();
1152 lcd_putsf(17, 1, "RAW: %d.%03d V", y / 1000, y % 1000);
1153 y = pmu_read_battery_current();
1154 lcd_putsf(0, 2, "Battery current: %d mA", y);
1155 lcd_putsf(0, 3, "PWRCON: %08x %08x", PWRCON, PWRCONEXT);
1156 lcd_putsf(0, 4, "CLKCON: %08x %03x %03x", CLKCON, CLKCON2, CLKCON3);
1157 lcd_putsf(0, 5, "PLL: %06x %06x %06x", PLL0PMS, PLL1PMS, PLL2PMS);
1158 x = pmu_read(0x1b) & 0xf;
1159 y = pmu_read(0x1a) * 25 + 625;
1160 lcd_putsf(0, 6, "AUTO: %x / %d mV", x, y);
1161 x = pmu_read(0x1f) & 0xf;
1162 y = pmu_read(0x1e) * 25 + 625;
1163 lcd_putsf(0, 7, "DOWN1: %x / %d mV", x, y);
1164 x = pmu_read(0x23) & 0xf;
1165 y = pmu_read(0x22) * 25 + 625;
1166 lcd_putsf(0, 8, "DOWN2: %x / %d mV", x, y);
1167 x = pmu_read(0x27) & 0xf;
1168 y = pmu_read(0x26) * 100 + 900;
1169 lcd_putsf(0, 9, "MEMLDO: %x / %d mV", x, y);
1170 for (i = 0; i < 6; i++)
1172 x = pmu_read(0x2e + (i << 1)) & 0xf;
1173 y = pmu_read(0x2d + (i << 1)) * 100 + 900;
1174 lcd_putsf(0, 10 + i, "LDO%d: %x / %d mV", i + 1, x, y);
1176 #else
1177 lcd_putsf(0, 3, "Charger: %s",
1178 charger_inserted() ? "present" : "absent");
1179 #endif /* target type */
1180 #endif /* CONFIG_CHARGING */
1181 break;
1182 case 2: /* voltage deltas: */
1183 #if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
1184 lcd_puts(0, 0, "Voltage deltas:");
1185 for (i = 0; i < POWER_HISTORY_LEN-1; i++) {
1186 y = power_history[i] - power_history[i+1];
1187 lcd_putsf(0, i+1, "-%d min: %c%d.%03d V", i,
1188 (y < 0) ? '-' : ' ', ((y < 0) ? y * -1 : y) / 1000,
1189 ((y < 0) ? y * -1 : y ) % 1000);
1191 #elif (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE)
1192 lcd_puts(0, 0, "Percentage deltas:");
1193 for (i = 0; i < POWER_HISTORY_LEN-1; i++) {
1194 y = power_history[i] - power_history[i+1];
1195 lcd_putsf(0, i+1, "-%d min: %c%d%%", i,
1196 (y < 0) ? '-' : ' ', ((y < 0) ? y * -1 : y));
1198 #endif
1199 break;
1201 case 3: /* remaining time estimation: */
1203 #ifdef ARCHOS_RECORDER
1204 lcd_putsf(0, 0, "charge_state: %d", charge_state);
1206 lcd_putsf(0, 1, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1208 lcd_putsf(0, 2, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1210 lcd_putsf(0, 3, "P=%2d I=%2d", pid_p, pid_i);
1212 lcd_putsf(0, 4, "Trickle sec: %d/60", trickle_sec);
1213 #endif /* ARCHOS_RECORDER */
1215 #if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
1216 lcd_putsf(0, 5, "Last PwrHist: %d.%03dV",
1217 power_history[0] / 1000,
1218 power_history[0] % 1000);
1219 #endif
1221 lcd_putsf(0, 6, "battery level: %d%%", battery_level());
1223 int time_left = battery_time();
1224 if (time_left >= 0)
1225 lcd_putsf(0, 7, "Est. remain: %d m", time_left);
1226 else
1227 lcd_puts(0, 7, "Estimation n/a");
1228 break;
1231 lcd_update();
1233 switch(get_action(CONTEXT_STD,HZ/2))
1235 case ACTION_STD_PREV:
1236 if (view)
1237 view--;
1238 break;
1240 case ACTION_STD_NEXT:
1241 if (view < 3)
1242 view++;
1243 break;
1245 case ACTION_STD_CANCEL:
1246 lcd_setfont(FONT_UI);
1247 return false;
1250 lcd_setfont(FONT_UI);
1251 return false;
1254 #endif /* (CONFIG_BATTERY_MEASURE != 0) && HAVE_LCD_BITMAP */
1256 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
1257 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1259 #if (CONFIG_STORAGE & STORAGE_MMC)
1260 #define CARDTYPE "MMC"
1261 #elif (CONFIG_STORAGE & STORAGE_SD)
1262 #define CARDTYPE "microSD"
1263 #endif
1265 static int disk_callback(int btn, struct gui_synclist *lists)
1267 tCardInfo *card;
1268 int *cardnum = (int*)lists->data;
1269 unsigned char card_name[6];
1270 unsigned char pbuf[32];
1271 char *title = lists->title;
1272 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1273 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1274 static const unsigned char * const kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1275 static const unsigned char * const nsec_units[] = { "ns", "µs", "ms" };
1276 #if (CONFIG_STORAGE & STORAGE_MMC)
1277 static const char * const mmc_spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1278 "3.1-3.31", "4.0" };
1279 #endif
1281 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1283 #ifdef HAVE_HOTSWAP
1284 if (btn == ACTION_STD_OK)
1286 *cardnum ^= 0x1; /* change cards */
1288 #endif
1290 simplelist_set_line_count(0);
1292 card = card_get_info(*cardnum);
1294 if (card->initialized > 0)
1296 unsigned i;
1297 for (i=0; i<sizeof(card_name); i++)
1299 card_name[i] = card_extract_bits(card->cid, (103-8*i), 8);
1301 strlcpy(card_name, card_name, sizeof(card_name));
1302 simplelist_addline(SIMPLELIST_ADD_LINE,
1303 "%s Rev %d.%d", card_name,
1304 (int) card_extract_bits(card->cid, 63, 4),
1305 (int) card_extract_bits(card->cid, 59, 4));
1306 simplelist_addline(SIMPLELIST_ADD_LINE,
1307 "Prod: %d/%d",
1308 #if (CONFIG_STORAGE & STORAGE_SD)
1309 (int) card_extract_bits(card->cid, 11, 4),
1310 (int) card_extract_bits(card->cid, 19, 8) + 2000
1311 #elif (CONFIG_STORAGE & STORAGE_MMC)
1312 (int) card_extract_bits(card->cid, 15, 4),
1313 (int) card_extract_bits(card->cid, 11, 4) + 1997
1314 #endif
1316 simplelist_addline(SIMPLELIST_ADD_LINE,
1317 #if (CONFIG_STORAGE & STORAGE_SD)
1318 "Ser#: 0x%08lx",
1319 card_extract_bits(card->cid, 55, 32)
1320 #elif (CONFIG_STORAGE & STORAGE_MMC)
1321 "Ser#: 0x%04lx",
1322 card_extract_bits(card->cid, 47, 16)
1323 #endif
1326 simplelist_addline(SIMPLELIST_ADD_LINE, "M=%02x, "
1327 #if (CONFIG_STORAGE & STORAGE_SD)
1328 "O=%c%c",
1329 (int) card_extract_bits(card->cid, 127, 8),
1330 card_extract_bits(card->cid, 119, 8),
1331 card_extract_bits(card->cid, 111, 8)
1332 #elif (CONFIG_STORAGE & STORAGE_MMC)
1333 "O=%04x",
1334 (int) card_extract_bits(card->cid, 127, 8),
1335 (int) card_extract_bits(card->cid, 119, 16)
1336 #endif
1339 #if (CONFIG_STORAGE & STORAGE_MMC)
1340 int temp = card_extract_bits(card->csd, 125, 4);
1341 simplelist_addline(SIMPLELIST_ADD_LINE,
1342 "MMC v%s", temp < 5 ?
1343 mmc_spec_vers[temp] : "?.?");
1344 #endif
1345 simplelist_addline(SIMPLELIST_ADD_LINE,
1346 "Blocks: 0x%08lx", card->numblocks);
1347 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1348 kbit_units, false);
1349 simplelist_addline(SIMPLELIST_ADD_LINE,
1350 "Speed: %s", pbuf);
1351 output_dyn_value(pbuf, sizeof pbuf, card->taac,
1352 nsec_units, false);
1353 simplelist_addline(SIMPLELIST_ADD_LINE,
1354 "Taac: %s", pbuf);
1355 simplelist_addline(SIMPLELIST_ADD_LINE,
1356 "Nsac: %d clk", card->nsac);
1357 simplelist_addline(SIMPLELIST_ADD_LINE,
1358 "R2W: *%d", card->r2w_factor);
1359 #if (CONFIG_STORAGE & STORAGE_SD)
1360 int csd_structure = card_extract_bits(card->csd, 127, 2);
1361 if (csd_structure == 0) /* CSD version 1.0 */
1362 #endif
1364 simplelist_addline(SIMPLELIST_ADD_LINE,
1365 "IRmax: %d..%d mA",
1366 i_vmin[card_extract_bits(card->csd, 61, 3)],
1367 i_vmax[card_extract_bits(card->csd, 58, 3)]);
1368 simplelist_addline(SIMPLELIST_ADD_LINE,
1369 "IWmax: %d..%d mA",
1370 i_vmin[card_extract_bits(card->csd, 55, 3)],
1371 i_vmax[card_extract_bits(card->csd, 52, 3)]);
1374 else if (card->initialized == 0)
1376 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1378 #if (CONFIG_STORAGE & STORAGE_SD)
1379 else /* card->initialized < 0 */
1381 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1383 #endif
1384 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1385 gui_synclist_set_title(lists, title, Icon_NOICON);
1386 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1387 gui_synclist_select_item(lists, 0);
1388 btn = ACTION_REDRAW;
1390 return btn;
1392 #elif (CONFIG_STORAGE & STORAGE_ATA)
1393 static int disk_callback(int btn, struct gui_synclist *lists)
1395 (void)lists;
1396 int i;
1397 char buf[128];
1398 unsigned short* identify_info = ata_get_identify();
1399 bool timing_info_present = false;
1400 (void)btn;
1402 simplelist_set_line_count(0);
1404 for (i=0; i < 20; i++)
1405 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1406 buf[40]=0;
1407 /* kill trailing space */
1408 for (i=39; i && buf[i]==' '; i--)
1409 buf[i] = 0;
1410 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1411 for (i=0; i < 4; i++)
1412 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1413 buf[8]=0;
1414 simplelist_addline(SIMPLELIST_ADD_LINE,
1415 "Firmware: %s", buf);
1416 snprintf(buf, sizeof buf, "%ld MB",
1417 ((unsigned long)identify_info[61] << 16 |
1418 (unsigned long)identify_info[60]) / 2048 );
1419 simplelist_addline(SIMPLELIST_ADD_LINE,
1420 "Size: %s", buf);
1421 unsigned long free;
1422 fat_size( IF_MV2(0,) NULL, &free );
1423 simplelist_addline(SIMPLELIST_ADD_LINE,
1424 "Free: %ld MB", free / 1024);
1425 simplelist_addline(SIMPLELIST_ADD_LINE,
1426 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
1427 i = identify_info[83] & (1<<3);
1428 simplelist_addline(SIMPLELIST_ADD_LINE,
1429 "Power mgmt: %s", i ? "enabled" : "unsupported");
1430 i = identify_info[83] & (1<<9);
1431 simplelist_addline(SIMPLELIST_ADD_LINE,
1432 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1433 i = identify_info[82] & (1<<6);
1434 simplelist_addline(SIMPLELIST_ADD_LINE,
1435 "Read-ahead: %s", i ? "enabled" : "unsupported");
1436 timing_info_present = identify_info[53] & (1<<1);
1437 if(timing_info_present) {
1438 char pio3[2], pio4[2];pio3[1] = 0;
1439 pio4[1] = 0;
1440 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1441 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1442 simplelist_addline(SIMPLELIST_ADD_LINE,
1443 "PIO modes: 0 1 2 %s %s", pio3, pio4);
1445 else {
1446 simplelist_addline(SIMPLELIST_ADD_LINE,
1447 "No PIO mode info");
1449 timing_info_present = identify_info[53] & (1<<1);
1450 if(timing_info_present) {
1451 simplelist_addline(SIMPLELIST_ADD_LINE,
1452 "Cycle times %dns/%dns",
1453 identify_info[67],
1454 identify_info[68] );
1455 } else {
1456 simplelist_addline(SIMPLELIST_ADD_LINE,
1457 "No timing info");
1459 int sector_size = 512;
1460 if((identify_info[106] & 0xe000) == 0x6000)
1461 sector_size *= BIT_N(identify_info[106] & 0x000f);
1462 simplelist_addline(SIMPLELIST_ADD_LINE,
1463 "Physical sector size: %d", sector_size);
1464 #ifdef HAVE_ATA_DMA
1465 if (identify_info[63] & (1<<0)) {
1466 char mdma0[2], mdma1[2], mdma2[2];
1467 mdma0[1] = mdma1[1] = mdma2[1] = 0;
1468 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
1469 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
1470 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
1471 simplelist_addline(SIMPLELIST_ADD_LINE,
1472 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
1473 simplelist_addline(SIMPLELIST_ADD_LINE,
1474 "MDMA Cycle times %dns/%dns",
1475 identify_info[65],
1476 identify_info[66] );
1478 else {
1479 simplelist_addline(SIMPLELIST_ADD_LINE,
1480 "No MDMA mode info");
1482 if (identify_info[53] & (1<<2)) {
1483 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2], udma6[2];
1484 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = udma6[1] = 0;
1485 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
1486 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
1487 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
1488 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
1489 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
1490 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
1491 udma6[0] = (identify_info[88] & (1<<6)) ? '6' : 0;
1492 simplelist_addline(SIMPLELIST_ADD_LINE,
1493 "UDMA modes: %s %s %s %s %s %s %s", udma0, udma1, udma2,
1494 udma3, udma4, udma5, udma6);
1496 else {
1497 simplelist_addline(SIMPLELIST_ADD_LINE,
1498 "No UDMA mode info");
1500 #endif /* HAVE_ATA_DMA */
1501 timing_info_present = identify_info[53] & (1<<1);
1502 if(timing_info_present) {
1503 i = identify_info[49] & (1<<11);
1504 simplelist_addline(SIMPLELIST_ADD_LINE,
1505 "IORDY support: %s", i ? "yes" : "no");
1506 i = identify_info[49] & (1<<10);
1507 simplelist_addline(SIMPLELIST_ADD_LINE,
1508 "IORDY disable: %s", i ? "yes" : "no");
1509 } else {
1510 simplelist_addline(SIMPLELIST_ADD_LINE,
1511 "No timing info");
1513 simplelist_addline(SIMPLELIST_ADD_LINE,
1514 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1515 #ifdef HAVE_ATA_DMA
1516 i = ata_get_dma_mode();
1517 if (i == 0) {
1518 simplelist_addline(SIMPLELIST_ADD_LINE,
1519 "DMA not enabled");
1520 } else {
1521 simplelist_addline(SIMPLELIST_ADD_LINE,
1522 "DMA mode: %s %c",
1523 (i & 0x40) ? "UDMA" : "MDMA",
1524 '0' + (i & 7));
1526 #endif /* HAVE_ATA_DMA */
1527 return btn;
1529 #else /* No SD, MMC or ATA */
1530 static int disk_callback(int btn, struct gui_synclist *lists)
1532 (void)lists;
1533 struct storage_info info;
1534 storage_get_info(0,&info);
1535 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
1536 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
1537 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
1538 simplelist_addline(SIMPLELIST_ADD_LINE,
1539 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
1540 unsigned long free;
1541 fat_size( IF_MV2(0,) NULL, &free );
1542 simplelist_addline(SIMPLELIST_ADD_LINE,
1543 "Free: %ld MB", free / 1024);
1544 simplelist_addline(SIMPLELIST_ADD_LINE,
1545 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1546 return btn;
1548 #endif
1550 #if (CONFIG_STORAGE & STORAGE_ATA)
1551 static bool dbg_identify_info(void)
1553 int fd = creat("/identify_info.bin", 0666);
1554 if(fd >= 0)
1556 #ifdef ROCKBOX_LITTLE_ENDIAN
1557 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
1558 #else
1559 write(fd, ata_get_identify(), SECTOR_SIZE);
1560 #endif
1561 close(fd);
1563 return false;
1565 #endif
1567 static bool dbg_disk_info(void)
1569 struct simplelist_info info;
1570 simplelist_info_init(&info, "Disk Info", 1, NULL);
1571 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1572 char title[16];
1573 int card = 0;
1574 info.callback_data = (void*)&card;
1575 info.title = title;
1576 #endif
1577 info.action_callback = disk_callback;
1578 info.hide_selection = true;
1579 info.scroll_all = true;
1580 return simplelist_show_list(&info);
1582 #endif /* PLATFORM_NATIVE */
1584 #ifdef HAVE_DIRCACHE
1585 static int dircache_callback(int btn, struct gui_synclist *lists)
1587 (void)lists;
1588 simplelist_set_line_count(0);
1589 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
1590 dircache_is_enabled() ? "Yes" : "No");
1591 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
1592 dircache_get_cache_size());
1593 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
1594 global_status.dircache_size);
1595 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
1596 DIRCACHE_LIMIT);
1597 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
1598 dircache_get_reserve_used(), DIRCACHE_RESERVE);
1599 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
1600 dircache_get_build_ticks() / HZ);
1601 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
1602 dircache_get_entry_count());
1603 return btn;
1606 static bool dbg_dircache_info(void)
1608 struct simplelist_info info;
1609 simplelist_info_init(&info, "Dircache Info", 7, NULL);
1610 info.action_callback = dircache_callback;
1611 info.hide_selection = true;
1612 info.scroll_all = true;
1613 return simplelist_show_list(&info);
1616 #endif /* HAVE_DIRCACHE */
1618 #ifdef HAVE_TAGCACHE
1619 static int database_callback(int btn, struct gui_synclist *lists)
1621 (void)lists;
1622 struct tagcache_stat *stat = tagcache_get_stat();
1623 static bool synced = false;
1625 simplelist_set_line_count(0);
1627 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
1628 stat->initialized ? "Yes" : "No");
1629 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
1630 stat->ready ? "Yes" : "No");
1631 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
1632 stat->ramcache ? "Yes" : "No");
1633 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
1634 stat->ramcache_used, stat->ramcache_allocated);
1635 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
1636 stat->progress, stat->processed_entries);
1637 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
1638 stat->curentry ? stat->curentry : "---");
1639 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
1640 stat->commit_step);
1641 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
1642 stat->commit_delayed ? "Yes" : "No");
1644 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
1645 stat->queue_length);
1647 if (synced)
1649 synced = false;
1650 tagcache_screensync_event();
1653 if (!btn && stat->curentry)
1655 synced = true;
1656 return ACTION_REDRAW;
1659 if (btn == ACTION_STD_CANCEL)
1660 tagcache_screensync_enable(false);
1662 return btn;
1664 static bool dbg_tagcache_info(void)
1666 struct simplelist_info info;
1667 simplelist_info_init(&info, "Database Info", 8, NULL);
1668 info.action_callback = database_callback;
1669 info.hide_selection = true;
1670 info.scroll_all = true;
1672 /* Don't do nonblock here, must give enough processing time
1673 for tagcache thread. */
1674 /* info.timeout = TIMEOUT_NOBLOCK; */
1675 info.timeout = 1;
1676 tagcache_screensync_enable(true);
1677 return simplelist_show_list(&info);
1679 #endif
1681 #if CONFIG_CPU == SH7034
1682 static bool dbg_save_roms(void)
1684 int fd;
1685 int oldmode = system_memory_guard(MEMGUARD_NONE);
1687 fd = creat("/internal_rom_0000-FFFF.bin", 0666);
1688 if(fd >= 0)
1690 write(fd, (void *)0, 0x10000);
1691 close(fd);
1694 fd = creat("/internal_rom_2000000-203FFFF.bin", 0666);
1695 if(fd >= 0)
1697 write(fd, (void *)0x2000000, 0x40000);
1698 close(fd);
1701 system_memory_guard(oldmode);
1702 return false;
1704 #elif defined CPU_COLDFIRE
1705 static bool dbg_save_roms(void)
1707 int fd;
1708 int oldmode = system_memory_guard(MEMGUARD_NONE);
1710 #if defined(IRIVER_H100_SERIES)
1711 fd = creat("/internal_rom_000000-1FFFFF.bin", 0666);
1712 #elif defined(IRIVER_H300_SERIES)
1713 fd = creat("/internal_rom_000000-3FFFFF.bin", 0666);
1714 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
1715 fd = creat("/internal_rom_000000-3FFFFF.bin", 0666);
1716 #elif defined(MPIO_HD200) || defined(MPIO_HD300)
1717 fd = creat("/internal_rom_000000-1FFFFF.bin", 0666);
1718 #endif
1719 if(fd >= 0)
1721 write(fd, (void *)0, FLASH_SIZE);
1722 close(fd);
1724 system_memory_guard(oldmode);
1726 #ifdef HAVE_EEPROM
1727 fd = creat("/internal_eeprom.bin", 0666);
1728 if (fd >= 0)
1730 int old_irq_level;
1731 char buf[EEPROM_SIZE];
1732 int err;
1734 old_irq_level = disable_irq_save();
1736 err = eeprom_24cxx_read(0, buf, sizeof buf);
1738 restore_irq(old_irq_level);
1740 if (err)
1741 splashf(HZ*3, "Eeprom read failure (%d)", err);
1742 else
1744 write(fd, buf, sizeof buf);
1747 close(fd);
1749 #endif
1751 return false;
1753 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
1754 static bool dbg_save_roms(void)
1756 int fd = creat("/internal_rom_000000-0FFFFF.bin", 0666);
1757 if(fd >= 0)
1759 write(fd, (void *)0x20000000, FLASH_SIZE);
1760 close(fd);
1763 return false;
1765 #elif CONFIG_CPU == IMX31L
1766 static bool dbg_save_roms(void)
1768 int fd = creat("/flash_rom_A0000000-A01FFFFF.bin", 0666);
1769 if (fd >= 0)
1771 write(fd, (void*)0xa0000000, FLASH_SIZE);
1772 close(fd);
1775 return false;
1777 #elif defined(CPU_TCC780X)
1778 static bool dbg_save_roms(void)
1780 int fd = creat("/eeprom_E0000000-E0001FFF.bin", 0666);
1781 if (fd >= 0)
1783 write(fd, (void*)0xe0000000, 0x2000);
1784 close(fd);
1787 return false;
1789 #endif /* CPU */
1791 #ifndef SIMULATOR
1792 #if CONFIG_TUNER
1794 #ifdef CONFIG_TUNER_MULTI
1795 static int tuner_type = 0;
1796 #define IF_TUNER_TYPE(type) if(tuner_type==type)
1797 #else
1798 #define IF_TUNER_TYPE(type)
1799 #endif
1801 static int radio_callback(int btn, struct gui_synclist *lists)
1803 (void)lists;
1804 if (btn == ACTION_STD_CANCEL)
1805 return btn;
1806 simplelist_set_line_count(1);
1808 #if (CONFIG_TUNER & LV24020LP)
1809 simplelist_addline(SIMPLELIST_ADD_LINE,
1810 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
1811 simplelist_addline(SIMPLELIST_ADD_LINE,
1812 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
1813 simplelist_addline(SIMPLELIST_ADD_LINE,
1814 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
1815 simplelist_addline(SIMPLELIST_ADD_LINE,
1816 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
1817 simplelist_addline(SIMPLELIST_ADD_LINE,
1818 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
1819 simplelist_addline(SIMPLELIST_ADD_LINE,
1820 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
1821 simplelist_addline(SIMPLELIST_ADD_LINE,
1822 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
1823 #endif /* LV24020LP */
1824 #if (CONFIG_TUNER & S1A0903X01)
1825 simplelist_addline(SIMPLELIST_ADD_LINE,
1826 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
1827 /* This one doesn't return dynamic data atm */
1828 #endif /* S1A0903X01 */
1829 #if (CONFIG_TUNER & TEA5767)
1830 struct tea5767_dbg_info nfo;
1831 tea5767_dbg_info(&nfo);
1832 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
1833 simplelist_addline(SIMPLELIST_ADD_LINE,
1834 " Read: %02X %02X %02X %02X %02X",
1835 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
1836 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
1837 (unsigned)nfo.read_regs[4]);
1838 simplelist_addline(SIMPLELIST_ADD_LINE,
1839 " Write: %02X %02X %02X %02X %02X",
1840 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
1841 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
1842 (unsigned)nfo.write_regs[4]);
1843 #endif /* TEA5767 */
1844 #if (CONFIG_TUNER & SI4700)
1845 IF_TUNER_TYPE(SI4700)
1847 struct si4700_dbg_info nfo;
1848 si4700_dbg_info(&nfo);
1849 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
1850 for (int i = 0; i < 16; i += 4) {
1851 simplelist_addline(SIMPLELIST_ADD_LINE,"%02X: %04X %04X %04X %04X",
1852 i, nfo.regs[i], nfo.regs[i+1], nfo.regs[i+2], nfo.regs[i+3]);
1854 #ifdef HAVE_RDS_CAP
1855 simplelist_addline(SIMPLELIST_ADD_LINE, "");
1856 simplelist_addline(SIMPLELIST_ADD_LINE, "RDS Info:");
1857 simplelist_addline(SIMPLELIST_ADD_LINE,
1858 si4700_get_rds_info(RADIO_RDS_NAME));
1860 simplelist_addline(SIMPLELIST_ADD_LINE,
1861 si4700_get_rds_info(RADIO_RDS_TEXT));
1862 #endif
1864 #endif /* SI4700 */
1865 #if (CONFIG_TUNER & RDA5802)
1866 IF_TUNER_TYPE(RDA5802)
1868 struct rda5802_dbg_info nfo;
1869 rda5802_dbg_info(&nfo);
1870 simplelist_addline(SIMPLELIST_ADD_LINE, "RDA5802 regs:");
1871 for (int i = 0; i < 16; i += 4) {
1872 simplelist_addline(SIMPLELIST_ADD_LINE,"%02X: %04X %04X %04X %04X",
1873 i, nfo.regs[i], nfo.regs[i+1], nfo.regs[i+2], nfo.regs[i+3]);
1876 #endif /* RDA55802 */
1877 return ACTION_REDRAW;
1879 static bool dbg_fm_radio(void)
1881 struct simplelist_info info;
1882 #ifdef CONFIG_TUNER_MULTI
1883 tuner_type = tuner_detect_type();
1884 #endif
1885 info.scroll_all = true;
1886 simplelist_info_init(&info, "FM Radio", 1, NULL);
1887 simplelist_set_line_count(0);
1888 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
1889 radio_hardware_present() ? "yes" : "no");
1891 info.action_callback = radio_hardware_present()?radio_callback : NULL;
1892 info.hide_selection = true;
1893 return simplelist_show_list(&info);
1895 #endif /* CONFIG_TUNER */
1896 #endif /* !SIMULATOR */
1898 #if defined(HAVE_LCD_BITMAP) && !defined(APPLICATION)
1899 extern bool do_screendump_instead_of_usb;
1901 static bool dbg_screendump(void)
1903 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
1904 splashf(HZ, "Screendump %sabled", do_screendump_instead_of_usb?"en":"dis");
1905 return false;
1907 #endif /* HAVE_LCD_BITMAP */
1909 extern bool write_metadata_log;
1911 static bool dbg_metadatalog(void)
1913 write_metadata_log = !write_metadata_log;
1914 splashf(HZ, "Metadata log %sabled", write_metadata_log ? "en" : "dis");
1915 return false;
1918 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
1919 static bool dbg_set_memory_guard(void)
1921 static const struct opt_items names[MAXMEMGUARD] = {
1922 { "None", -1 },
1923 { "Flash ROM writes", -1 },
1924 { "Zero area (all)", -1 }
1926 int mode = system_memory_guard(MEMGUARD_KEEP);
1928 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
1929 system_memory_guard(mode);
1931 return false;
1933 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
1935 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
1936 static bool dbg_write_eeprom(void)
1938 int fd = open("/internal_eeprom.bin", O_RDONLY);
1940 if (fd >= 0)
1942 char buf[EEPROM_SIZE];
1943 int rc = read(fd, buf, EEPROM_SIZE);
1945 if(rc == EEPROM_SIZE)
1947 int old_irq_level = disable_irq_save();
1949 int err = eeprom_24cxx_write(0, buf, sizeof buf);
1950 if (err)
1951 splashf(HZ*3, "Eeprom write failure (%d)", err);
1952 else
1953 splash(HZ*3, "Eeprom written successfully");
1955 restore_irq(old_irq_level);
1957 else
1959 splashf(HZ*3, "File read error (%d)",rc);
1961 close(fd);
1963 else
1965 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
1968 return false;
1970 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
1971 #ifdef CPU_BOOST_LOGGING
1972 static bool cpu_boost_log(void)
1974 int count = cpu_boost_log_getcount();
1975 char *str = cpu_boost_log_getlog_first();
1976 bool done;
1977 lcd_setfont(FONT_SYSFIXED);
1978 for (int i = 0; i < count ;)
1980 lcd_clear_display();
1981 for(int j=0; j<LCD_HEIGHT/SYSFONT_HEIGHT; j++,i++)
1983 if (!str)
1984 str = cpu_boost_log_getlog_next();
1985 if (str)
1987 if(strlen(str) > LCD_WIDTH/SYSFONT_WIDTH)
1988 lcd_puts_scroll(0, j, str);
1989 else
1990 lcd_puts(0, j,str);
1992 str = NULL;
1994 lcd_update();
1995 done = false;
1996 while (!done)
1998 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2000 case ACTION_STD_OK:
2001 case ACTION_STD_PREV:
2002 case ACTION_STD_NEXT:
2003 done = true;
2004 break;
2005 case ACTION_STD_CANCEL:
2006 i = count;
2007 done = true;
2008 break;
2012 lcd_stop_scroll();
2013 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2014 lcd_setfont(FONT_UI);
2015 return false;
2017 #endif
2019 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) \
2020 && !defined(IPOD_MINI) && !defined(SIMULATOR))
2021 extern bool wheel_is_touched;
2022 extern int old_wheel_value;
2023 extern int new_wheel_value;
2024 extern int wheel_delta;
2025 extern unsigned int accumulated_wheel_delta;
2026 extern unsigned int wheel_velocity;
2028 static bool dbg_scrollwheel(void)
2030 lcd_setfont(FONT_SYSFIXED);
2032 while (1)
2034 if (action_userabort(HZ/10))
2035 break;
2037 lcd_clear_display();
2039 /* show internal variables of scrollwheel driver */
2040 lcd_putsf(0, 0, "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2041 lcd_putsf(0, 1, "new position: %2d", new_wheel_value);
2042 lcd_putsf(0, 2, "old position: %2d", old_wheel_value);
2043 lcd_putsf(0, 3, "wheel delta: %2d", wheel_delta);
2044 lcd_putsf(0, 4, "accumulated delta: %2d", accumulated_wheel_delta);
2045 lcd_putsf(0, 5, "velo [deg/s]: %4d", (int)wheel_velocity);
2047 /* show effective accelerated scrollspeed */
2048 lcd_putsf(0, 6, "accel. speed: %4d",
2049 button_apply_acceleration((1<<31)|(1<<24)|wheel_velocity) );
2051 lcd_update();
2053 lcd_setfont(FONT_UI);
2054 return false;
2056 #endif
2058 #ifdef HAVE_USBSTACK
2059 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2060 static bool toggle_usb_serial(void)
2062 bool enabled = !usb_core_driver_enabled(USB_DRIVER_SERIAL);
2064 usb_core_enable_driver(USB_DRIVER_SERIAL, enabled);
2065 splashf(HZ, "USB Serial %sabled", enabled ? "en" : "dis");
2067 return false;
2069 #endif
2070 #endif
2072 #if CONFIG_USBOTG == USBOTG_ISP1583
2073 extern int dbg_usb_num_items(void);
2074 extern const char* dbg_usb_item(int selected_item, void *data,
2075 char *buffer, size_t buffer_len);
2077 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2079 (void)lists;
2080 if (action == ACTION_NONE)
2081 action = ACTION_REDRAW;
2082 return action;
2085 static bool dbg_isp1583(void)
2087 struct simplelist_info isp1583;
2088 isp1583.scroll_all = true;
2089 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2090 isp1583.timeout = HZ/100;
2091 isp1583.hide_selection = true;
2092 isp1583.get_name = dbg_usb_item;
2093 isp1583.action_callback = isp1583_action_callback;
2094 return simplelist_show_list(&isp1583);
2096 #endif
2098 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2099 extern int pic_dbg_num_items(void);
2100 extern const char* pic_dbg_item(int selected_item, void *data,
2101 char *buffer, size_t buffer_len);
2103 static int pic_action_callback(int action, struct gui_synclist *lists)
2105 (void)lists;
2106 if (action == ACTION_NONE)
2107 action = ACTION_REDRAW;
2108 return action;
2111 static bool dbg_pic(void)
2113 struct simplelist_info pic;
2114 pic.scroll_all = true;
2115 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2116 pic.timeout = HZ/100;
2117 pic.hide_selection = true;
2118 pic.get_name = pic_dbg_item;
2119 pic.action_callback = pic_action_callback;
2120 return simplelist_show_list(&pic);
2122 #endif
2125 /****** The menu *********/
2126 static const struct {
2127 unsigned char *desc; /* string or ID */
2128 bool (*function) (void); /* return true if USB was connected */
2129 } menuitems[] = {
2130 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2131 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)) || \
2132 CONFIG_CPU == IMX31L || defined(CPU_TCC780X)
2133 { "Dump ROM contents", dbg_save_roms },
2134 #endif
2135 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2136 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 \
2137 || CONFIG_CPU == DM320 || defined(CPU_S5L870X) || CONFIG_CPU == AS3525v2 \
2138 || CONFIG_CPU == RK27XX
2139 { "View I/O ports", dbg_ports },
2140 #endif
2141 #if (CONFIG_RTC == RTC_PCF50605) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
2142 { "View PCF registers", dbg_pcf },
2143 #endif
2144 #if defined(HAVE_TSC2100) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
2145 { "TSC2100 debug", tsc2100_debug },
2146 #endif
2147 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2148 { "CPU frequency", dbg_cpufreq },
2149 #endif
2150 #if CONFIG_CPU == IMX31L
2151 { "DVFS/DPTC", __dbg_dvfs_dptc },
2152 #endif
2153 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2154 { "S/PDIF analyzer", dbg_spdif },
2155 #endif
2156 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2157 { "Catch mem accesses", dbg_set_memory_guard },
2158 #endif
2159 { "View OS stacks", dbg_os },
2160 #ifdef __linux__
2161 { "View CPU stats", dbg_cpuinfo },
2162 #endif
2163 #ifdef HAVE_LCD_BITMAP
2164 #if (CONFIG_BATTERY_MEASURE != 0) && !defined(SIMULATOR)
2165 { "View battery", view_battery },
2166 #endif
2167 #ifndef APPLICATION
2168 { "Screendump", dbg_screendump },
2169 #endif
2170 #endif
2171 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2172 { "View HW info", dbg_hw_info },
2173 #endif
2174 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2175 { "View partitions", dbg_partitions },
2176 #endif
2177 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2178 { "View disk info", dbg_disk_info },
2179 #if (CONFIG_STORAGE & STORAGE_ATA)
2180 { "Dump ATA identify info", dbg_identify_info},
2181 #endif
2182 #endif
2183 { "Metadata log", dbg_metadatalog },
2184 #ifdef HAVE_DIRCACHE
2185 { "View dircache info", dbg_dircache_info },
2186 #endif
2187 #ifdef HAVE_TAGCACHE
2188 { "View database info", dbg_tagcache_info },
2189 #endif
2190 #ifdef HAVE_LCD_BITMAP
2191 #if CONFIG_CODEC == SWCODEC
2192 { "View buffering thread", dbg_buffering_thread },
2193 #elif !defined(SIMULATOR)
2194 { "View audio thread", dbg_audio_thread },
2195 #endif
2196 #ifdef PM_DEBUG
2197 { "pm histogram", peak_meter_histogram},
2198 #endif /* PM_DEBUG */
2199 #endif /* HAVE_LCD_BITMAP */
2200 { "View buflib allocs", dbg_buflib_allocs },
2201 #ifndef SIMULATOR
2202 #if CONFIG_TUNER
2203 { "FM Radio", dbg_fm_radio },
2204 #endif
2205 #endif
2206 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2207 { "Write back EEPROM", dbg_write_eeprom },
2208 #endif
2209 #if CONFIG_USBOTG == USBOTG_ISP1583
2210 { "View ISP1583 info", dbg_isp1583 },
2211 #endif
2212 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2213 { "View PIC info", dbg_pic },
2214 #endif
2215 #ifdef ROCKBOX_HAS_LOGF
2216 {"Show Log File", logfdisplay },
2217 {"Dump Log File", logfdump },
2218 #endif
2219 #if defined(HAVE_USBSTACK)
2220 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2221 {"USB Serial driver (logf)", toggle_usb_serial },
2222 #endif
2223 #endif /* HAVE_USBSTACK */
2224 #ifdef CPU_BOOST_LOGGING
2225 {"cpu_boost log",cpu_boost_log},
2226 #endif
2227 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) \
2228 && !defined(IPOD_MINI) && !defined(SIMULATOR))
2229 {"Debug scrollwheel", dbg_scrollwheel },
2230 #endif
2233 static int menu_action_callback(int btn, struct gui_synclist *lists)
2235 int selection = gui_synclist_get_sel_pos(lists);
2236 if (btn == ACTION_STD_OK)
2238 FOR_NB_SCREENS(i)
2239 viewportmanager_theme_enable(i, false, NULL);
2240 menuitems[selection].function();
2241 btn = ACTION_REDRAW;
2242 FOR_NB_SCREENS(i)
2243 viewportmanager_theme_undo(i, false);
2245 else if (btn == ACTION_STD_CONTEXT)
2247 MENUITEM_STRINGLIST(menu_items, "Debug Menu", NULL, ID2P(LANG_ADD_TO_FAVES));
2248 if (do_menu(&menu_items, NULL, NULL, false) == 0)
2249 shortcuts_add(SHORTCUT_DEBUGITEM, menuitems[selection].desc);
2250 return ACTION_STD_CANCEL;
2252 return btn;
2255 static const char* menu_get_name(int item, void * data,
2256 char *buffer, size_t buffer_len)
2258 (void)data; (void)buffer; (void)buffer_len;
2259 return menuitems[item].desc;
2262 bool debug_menu(void)
2264 struct simplelist_info info;
2266 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2267 info.action_callback = menu_action_callback;
2268 info.get_name = menu_get_name;
2269 return simplelist_show_list(&info);
2272 bool run_debug_screen(char* screen)
2274 for (unsigned i=0; i<ARRAYLEN(menuitems); i++)
2275 if (!strcmp(screen, menuitems[i].desc))
2277 FOR_NB_SCREENS(j)
2278 viewportmanager_theme_enable(j, false, NULL);
2279 menuitems[i].function();
2280 FOR_NB_SCREENS(j)
2281 viewportmanager_theme_undo(j, false);
2282 return true;
2285 return false;