Add new tarball generation script.
[maemo-rb.git] / apps / debug_menu.c
blobfbf6d53fe038f2158b7729f173697042f3073703
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 #ifdef HAVE_RDS_CAP
128 #include "rds.h"
129 #endif
131 /*---------------------------------------------------*/
132 /* SPECIAL DEBUG STUFF */
133 /*---------------------------------------------------*/
134 extern struct thread_entry threads[MAXTHREADS];
136 static char thread_status_char(unsigned status)
138 static const char thread_status_chars[THREAD_NUM_STATES+1] =
140 [0 ... THREAD_NUM_STATES] = '?',
141 [STATE_RUNNING] = 'R',
142 [STATE_BLOCKED] = 'B',
143 [STATE_SLEEPING] = 'S',
144 [STATE_BLOCKED_W_TMO] = 'T',
145 [STATE_FROZEN] = 'F',
146 [STATE_KILLED] = 'K',
149 if (status > THREAD_NUM_STATES)
150 status = THREAD_NUM_STATES;
152 return thread_status_chars[status];
155 static const char* threads_getname(int selected_item, void *data,
156 char *buffer, size_t buffer_len)
158 (void)data;
159 struct thread_entry *thread;
160 char name[32];
162 #if NUM_CORES > 1
163 if (selected_item < (int)NUM_CORES)
165 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
166 idle_stack_usage(selected_item));
167 return buffer;
170 selected_item -= NUM_CORES;
171 #endif
173 thread = &threads[selected_item];
175 if (thread->state == STATE_KILLED)
177 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
178 return buffer;
181 thread_get_name(name, 32, thread);
183 snprintf(buffer, buffer_len,
184 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
185 selected_item,
186 IF_COP(thread->core,)
187 #ifdef HAVE_SCHEDULER_BOOSTCTRL
188 (thread->cpu_boost) ? '+' :
189 #endif
190 ((thread->state == STATE_RUNNING) ? '*' : ' '),
191 thread_status_char(thread->state),
192 IF_PRIO(thread->base_priority, thread->priority, )
193 thread_stack_usage(thread), name);
195 return buffer;
198 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
200 (void)lists;
201 #ifdef ROCKBOX_HAS_LOGF
202 if (action == ACTION_STD_OK)
204 int selpos = gui_synclist_get_sel_pos(lists);
205 #if NUM_CORES > 1
206 if (selpos >= NUM_CORES)
207 remove_thread(threads[selpos - NUM_CORES].id);
208 #else
209 remove_thread(threads[selpos].id);
210 #endif
211 return ACTION_REDRAW;
213 #endif /* ROCKBOX_HAS_LOGF */
214 if (action == ACTION_NONE)
215 action = ACTION_REDRAW;
216 return action;
218 /* Test code!!! */
219 static bool dbg_os(void)
221 struct simplelist_info info;
222 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
223 #if NUM_CORES == 1
224 MAXTHREADS,
225 #else
226 MAXTHREADS+NUM_CORES,
227 #endif
228 NULL);
229 #ifndef ROCKBOX_HAS_LOGF
230 info.hide_selection = true;
231 info.scroll_all = true;
232 #endif
233 info.action_callback = dbg_threads_action_callback;
234 info.get_name = threads_getname;
235 return simplelist_show_list(&info);
238 #ifdef __linux__
239 #include "cpuinfo-linux.h"
241 #define MAX_STATES 16
242 static struct time_state states[MAX_STATES];
244 static const char* get_cpuinfo(int selected_item, void *data,
245 char *buffer, size_t buffer_len)
247 (void)data;(void)buffer_len;
248 const char* text;
249 long time, diff;
250 struct cpuusage us;
251 static struct cpuusage last_us;
252 int state_count = *(int*)data;
254 if (cpuusage_linux(&us) != 0)
255 return NULL;
257 switch(selected_item)
259 case 0:
260 diff = abs(last_us.usage - us.usage);
261 sprintf(buffer, "Usage: %ld.%02ld%% (%c %ld.%02ld)",
262 us.usage/100, us.usage%100,
263 (us.usage >= last_us.usage) ? '+':'-',
264 diff/100, diff%100);
265 last_us.usage = us.usage;
266 return buffer;
267 case 1:
268 text = "User";
269 time = us.utime;
270 diff = us.utime - last_us.utime;
271 last_us.utime = us.utime;
272 break;
273 case 2:
274 text = "Sys";
275 time = us.stime;
276 diff = us.stime - last_us.stime;
277 last_us.stime = us.stime;
278 break;
279 case 3:
280 text = "Real";
281 time = us.rtime;
282 diff = us.rtime - last_us.rtime;
283 last_us.rtime = us.rtime;
284 break;
285 case 4:
286 return "*** Per CPU freq stats ***";
287 default:
289 int cpu = (selected_item - 5) / (state_count + 1);
290 int cpu_line = (selected_item - 5) % (state_count + 1);
291 int freq1 = frequency_linux(cpu, false);
292 int freq2 = frequency_linux(cpu, true);
293 if (cpu_line == 0)
295 sprintf(buffer, " CPU%d: Cur/Scal freq: %d/%d MHz", cpu,
296 freq1 > 0 ? freq1/1000 : -1,
297 freq2 > 0 ? freq2/1000 : -1);
299 else
301 cpustatetimes_linux(cpu, states, ARRAYLEN(states));
302 snprintf(buffer, buffer_len, " %ld %ld",
303 states[cpu_line-1].frequency,
304 states[cpu_line-1].time);
306 return buffer;
309 sprintf(buffer, "%s: %ld.%02lds (+ %ld.%02ld)", text,
310 time / us.hz, time % us.hz,
311 diff / us.hz, diff % us.hz);
312 return buffer;
315 static int cpuinfo_cb(int action, struct gui_synclist *lists)
317 (void)lists;
318 if (action == ACTION_NONE)
319 action = ACTION_REDRAW;
320 return action;
323 static bool dbg_cpuinfo(void)
325 struct simplelist_info info;
326 int cpu_count = MAX(cpucount_linux(), 1);
327 int state_count = cpustatetimes_linux(0, states, ARRAYLEN(states));
328 printf("%s(): %d %d\n", __func__, cpu_count, state_count);
329 simplelist_info_init(&info, "CPU info:", 5 + cpu_count*(state_count+1), &state_count);
330 info.get_name = get_cpuinfo;
331 info.action_callback = cpuinfo_cb;
332 info.timeout = HZ;
333 info.hide_selection = true;
334 info.scroll_all = true;
335 return simplelist_show_list(&info);
338 #endif
340 #ifdef HAVE_LCD_BITMAP
341 #if CONFIG_CODEC != SWCODEC
342 #ifndef SIMULATOR
343 static bool dbg_audio_thread(void)
345 struct audio_debug d;
347 lcd_setfont(FONT_SYSFIXED);
349 while(1)
351 if (action_userabort(HZ/5))
352 return false;
354 audio_get_debugdata(&d);
356 lcd_clear_display();
358 lcd_putsf(0, 0, "read: %x", d.audiobuf_read);
359 lcd_putsf(0, 1, "write: %x", d.audiobuf_write);
360 lcd_putsf(0, 2, "swap: %x", d.audiobuf_swapwrite);
361 lcd_putsf(0, 3, "playing: %d", d.playing);
362 lcd_putsf(0, 4, "playable: %x", d.playable_space);
363 lcd_putsf(0, 5, "unswapped: %x", d.unswapped_space);
365 /* Playable space left */
366 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
367 d.playable_space, HORIZONTAL);
369 /* Show the watermark limit */
370 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
371 d.low_watermark_level, HORIZONTAL);
373 lcd_putsf(0, 7, "wm: %x - %x",
374 d.low_watermark_level, d.lowest_watermark_level);
376 lcd_update();
378 lcd_setfont(FONT_UI);
379 return false;
381 #endif /* !SIMULATOR */
382 #else /* CONFIG_CODEC == SWCODEC */
383 static unsigned int ticks, freq_sum;
384 #ifndef CPU_MULTI_FREQUENCY
385 static unsigned int boost_ticks;
386 #endif
388 static void dbg_audio_task(void)
390 #ifdef CPUFREQ_NORMAL
391 #ifndef CPU_MULTI_FREQUENCY
392 if(FREQ > CPUFREQ_NORMAL)
393 boost_ticks++;
394 #endif
395 freq_sum += FREQ/1000000; /* in MHz */
396 #endif
397 ticks++;
400 static bool dbg_buffering_thread(void)
402 int button;
403 int line;
404 bool done = false;
405 size_t bufused;
406 size_t bufsize = pcmbuf_get_bufsize();
407 int pcmbufdescs = pcmbuf_descs();
408 struct buffering_debug d;
409 size_t filebuflen = audio_get_filebuflen();
410 /* This is a size_t, but call it a long so it puts a - when it's bad. */
412 #ifndef CPU_MULTI_FREQUENCY
413 boost_ticks = 0;
414 #endif
415 ticks = freq_sum = 0;
417 tick_add_task(dbg_audio_task);
419 FOR_NB_SCREENS(i)
420 screens[i].setfont(FONT_SYSFIXED);
422 while(!done)
424 button = get_action(CONTEXT_STD,HZ/5);
425 switch(button)
427 case ACTION_STD_NEXT:
428 audio_next();
429 break;
430 case ACTION_STD_PREV:
431 audio_prev();
432 break;
433 case ACTION_STD_CANCEL:
434 done = true;
435 break;
438 buffering_get_debugdata(&d);
439 bufused = bufsize - pcmbuf_free();
441 FOR_NB_SCREENS(i)
443 line = 0;
444 screens[i].clear_display();
447 screens[i].putsf(0, line++, "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
449 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
450 bufsize, 0, bufused, HORIZONTAL);
451 line++;
453 screens[i].putsf(0, line++, "alloc: %6ld/%ld", audio_filebufused(),
454 (long) filebuflen);
456 #if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
457 if (screens[i].lcdheight > 80)
459 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
460 filebuflen, 0, audio_filebufused(), HORIZONTAL);
461 line++;
463 screens[i].putsf(0, line++, "real: %6ld/%ld", (long)d.buffered_data,
464 (long)filebuflen);
466 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
467 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
468 line++;
470 #endif
472 screens[i].putsf(0, line++, "usefl: %6ld/%ld", (long)(d.useful_data),
473 (long)filebuflen);
475 #if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
476 if (screens[i].lcdheight > 80)
478 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
479 filebuflen, 0, d.useful_data, HORIZONTAL);
480 line++;
482 #endif
484 screens[i].putsf(0, line++, "data_rem: %ld", (long)d.data_rem);
486 screens[i].putsf(0, line++, "track count: %2d", audio_track_count());
488 screens[i].putsf(0, line++, "handle count: %d", (int)d.num_handles);
490 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
491 screens[i].putsf(0, line++, "cpu freq: %3dMHz",
492 (int)((FREQ + 500000) / 1000000));
493 #endif
495 if (ticks > 0)
497 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
498 #ifdef CPU_MULTI_FREQUENCY
499 int boostquota = (avgclock * 100 - CPUFREQ_NORMAL/1000) /
500 ((CPUFREQ_MAX - CPUFREQ_NORMAL) / 1000000); /* in 0.1 % */
501 #else
502 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
503 #endif
504 screens[i].putsf(0, line++, "boost:%3d.%d%% (%d.%dMHz)",
505 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
508 screens[i].putsf(0, line++, "pcmbufdesc: %2d/%2d",
509 pcmbuf_used_descs(), pcmbufdescs);
510 screens[i].putsf(0, line++, "watermark: %6d",
511 (int)(d.watermark));
513 screens[i].update();
517 tick_remove_task(dbg_audio_task);
519 FOR_NB_SCREENS(i)
520 screens[i].setfont(FONT_UI);
522 return false;
524 #endif /* CONFIG_CODEC */
525 #endif /* HAVE_LCD_BITMAP */
527 static const char* bf_getname(int selected_item, void *data,
528 char *buffer, size_t buffer_len)
530 (void)data;
531 core_print_block_at(selected_item, buffer, buffer_len);
532 return buffer;
535 static int bf_action_cb(int action, struct gui_synclist* list)
537 if (action == ACTION_STD_OK)
539 if (gui_synclist_get_sel_pos(list) == 0 && core_test_free())
541 splash(HZ, "Freed test handle. New alloc should trigger compact");
543 else
545 splash(HZ/1, "Attempting a 64k allocation");
546 int handle = core_alloc("test", 64<<10);
547 splash(HZ/2, (handle > 0) ? "Success":"Fail");
548 /* for some reason simplelist doesn't allow adding items here if
549 * info.get_name is given, so use normal list api */
550 gui_synclist_set_nb_items(list, core_get_num_blocks());
551 if (handle > 0)
552 core_free(handle);
554 action = ACTION_REDRAW;
556 else if (action == ACTION_NONE)
557 action = ACTION_REDRAW;
558 return action;
561 static bool dbg_buflib_allocs(void)
563 struct simplelist_info info;
564 simplelist_info_init(&info, "mem allocs", core_get_num_blocks(), NULL);
565 info.get_name = bf_getname;
566 info.action_callback = bf_action_cb;
567 info.timeout = TIMEOUT_BLOCK;
568 return simplelist_show_list(&info);
571 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
572 static const char* dbg_partitions_getname(int selected_item, void *data,
573 char *buffer, size_t buffer_len)
575 (void)data;
576 int partition = selected_item/2;
577 struct partinfo* p = disk_partinfo(partition);
578 if (selected_item%2)
580 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / ( 2048 / ( SECTOR_SIZE / 512 )));
582 else
584 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
586 return buffer;
589 static bool dbg_partitions(void)
591 struct simplelist_info info;
592 simplelist_info_init(&info, "Partition Info", 4, NULL);
593 info.selection_size = 2;
594 info.hide_selection = true;
595 info.scroll_all = true;
596 info.get_name = dbg_partitions_getname;
597 return simplelist_show_list(&info);
599 #endif /* PLATFORM_NATIVE */
601 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
602 static bool dbg_spdif(void)
604 int line;
605 unsigned int control;
606 int x;
607 char *s;
608 int category;
609 int generation;
610 unsigned int interruptstat;
611 bool valnogood, symbolerr, parityerr;
612 bool done = false;
613 bool spdif_src_on;
614 int spdif_source = spdif_get_output_source(&spdif_src_on);
615 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
617 lcd_clear_display();
618 lcd_setfont(FONT_SYSFIXED);
620 #ifdef HAVE_SPDIF_POWER
621 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
622 #endif
624 while (!done)
626 line = 0;
628 control = EBU1RCVCCHANNEL1;
629 interruptstat = INTERRUPTSTAT;
630 INTERRUPTCLEAR = 0x03c00000;
632 valnogood = (interruptstat & 0x01000000)?true:false;
633 symbolerr = (interruptstat & 0x00800000)?true:false;
634 parityerr = (interruptstat & 0x00400000)?true:false;
636 lcd_putsf(0, line++, "Val: %s Sym: %s Par: %s",
637 valnogood?"--":"OK",
638 symbolerr?"--":"OK",
639 parityerr?"--":"OK");
641 lcd_putsf(0, line++, "Status word: %08x", (int)control);
643 line++;
645 x = control >> 31;
646 lcd_putsf(0, line++, "PRO: %d (%s)",
647 x, x?"Professional":"Consumer");
649 x = (control >> 30) & 1;
650 lcd_putsf(0, line++, "Audio: %d (%s)",
651 x, x?"Non-PCM":"PCM");
653 x = (control >> 29) & 1;
654 lcd_putsf(0, line++, "Copy: %d (%s)",
655 x, x?"Permitted":"Inhibited");
657 x = (control >> 27) & 7;
658 switch(x)
660 case 0:
661 s = "None";
662 break;
663 case 1:
664 s = "50/15us";
665 break;
666 default:
667 s = "Reserved";
668 break;
670 lcd_putsf(0, line++, "Preemphasis: %d (%s)", x, s);
672 x = (control >> 24) & 3;
673 lcd_putsf(0, line++, "Mode: %d", x);
675 category = (control >> 17) & 127;
676 switch(category)
678 case 0x00:
679 s = "General";
680 break;
681 case 0x40:
682 s = "Audio CD";
683 break;
684 default:
685 s = "Unknown";
687 lcd_putsf(0, line++, "Category: 0x%02x (%s)", category, s);
689 x = (control >> 16) & 1;
690 generation = x;
691 if(((category & 0x70) == 0x10) ||
692 ((category & 0x70) == 0x40) ||
693 ((category & 0x78) == 0x38))
695 generation = !generation;
697 lcd_putsf(0, line++, "Generation: %d (%s)",
698 x, generation?"Original":"No ind.");
700 x = (control >> 12) & 15;
701 lcd_putsf(0, line++, "Source: %d", x);
704 x = (control >> 8) & 15;
705 switch(x)
707 case 0:
708 s = "Unspecified";
709 break;
710 case 8:
711 s = "A (Left)";
712 break;
713 case 4:
714 s = "B (Right)";
715 break;
716 default:
717 s = "";
718 break;
720 lcd_putsf(0, line++, "Channel: %d (%s)", x, s);
722 x = (control >> 4) & 15;
723 switch(x)
725 case 0:
726 s = "44.1kHz";
727 break;
728 case 0x4:
729 s = "48kHz";
730 break;
731 case 0xc:
732 s = "32kHz";
733 break;
735 lcd_putsf(0, line++, "Frequency: %d (%s)", x, s);
737 x = (control >> 2) & 3;
738 lcd_putsf(0, line++, "Clock accuracy: %d", x);
739 line++;
741 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
742 lcd_putsf(0, line++, "Measured freq: %ldHz",
743 spdif_measure_frequency());
744 #endif
746 lcd_update();
748 if (action_userabort(HZ/10))
749 break;
752 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
754 #ifdef HAVE_SPDIF_POWER
755 spdif_power_enable(global_settings.spdif_enable);
756 #endif
758 lcd_setfont(FONT_UI);
759 return false;
761 #endif /* CPU_COLDFIRE */
763 #if (CONFIG_RTC == RTC_PCF50605) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
764 static bool dbg_pcf(void)
766 int line;
768 #ifdef HAVE_LCD_BITMAP
769 lcd_setfont(FONT_SYSFIXED);
770 #endif
771 lcd_clear_display();
773 while(1)
775 line = 0;
777 lcd_putsf(0, line++, "DCDC1: %02x", pcf50605_read(0x1b));
778 lcd_putsf(0, line++, "DCDC2: %02x", pcf50605_read(0x1c));
779 lcd_putsf(0, line++, "DCDC3: %02x", pcf50605_read(0x1d));
780 lcd_putsf(0, line++, "DCDC4: %02x", pcf50605_read(0x1e));
781 lcd_putsf(0, line++, "DCDEC1: %02x", pcf50605_read(0x1f));
782 lcd_putsf(0, line++, "DCDEC2: %02x", pcf50605_read(0x20));
783 lcd_putsf(0, line++, "DCUDC1: %02x", pcf50605_read(0x21));
784 lcd_putsf(0, line++, "DCUDC2: %02x", pcf50605_read(0x22));
785 lcd_putsf(0, line++, "IOREGC: %02x", pcf50605_read(0x23));
786 lcd_putsf(0, line++, "D1REGC: %02x", pcf50605_read(0x24));
787 lcd_putsf(0, line++, "D2REGC: %02x", pcf50605_read(0x25));
788 lcd_putsf(0, line++, "D3REGC: %02x", pcf50605_read(0x26));
789 lcd_putsf(0, line++, "LPREG1: %02x", pcf50605_read(0x27));
790 lcd_update();
791 if (action_userabort(HZ/10))
793 lcd_setfont(FONT_UI);
794 return false;
798 lcd_setfont(FONT_UI);
799 return false;
801 #endif
803 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
804 static bool dbg_cpufreq(void)
806 int line;
807 int button;
809 #ifdef HAVE_LCD_BITMAP
810 lcd_setfont(FONT_SYSFIXED);
811 #endif
812 lcd_clear_display();
814 while(1)
816 line = 0;
818 lcd_putsf(0, line++, "Frequency: %ld", FREQ);
819 lcd_putsf(0, line++, "boost_counter: %d", get_cpu_boost_counter());
821 lcd_update();
822 button = get_action(CONTEXT_STD,HZ/10);
824 switch(button)
826 case ACTION_STD_PREV:
827 cpu_boost(true);
828 break;
830 case ACTION_STD_NEXT:
831 cpu_boost(false);
832 break;
834 case ACTION_STD_OK:
835 while (get_cpu_boost_counter() > 0)
836 cpu_boost(false);
837 set_cpu_frequency(CPUFREQ_DEFAULT);
838 break;
840 case ACTION_STD_CANCEL:
841 lcd_setfont(FONT_UI);
842 return false;
845 lcd_setfont(FONT_UI);
846 return false;
848 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
850 #if defined(HAVE_TSC2100) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
851 #include "tsc2100.h"
852 static const char* tsc2100_debug_getname(int selected_item, void * data,
853 char *buffer, size_t buffer_len)
855 int *page = (int*)data;
856 bool reserved = false;
857 switch (*page)
859 case 0:
860 if ((selected_item > 0x0a) ||
861 (selected_item == 0x04) ||
862 (selected_item == 0x08))
863 reserved = true;
864 break;
865 case 1:
866 if ((selected_item > 0x05) ||
867 (selected_item == 0x02))
868 reserved = true;
869 break;
870 case 2:
871 if (selected_item > 0x1e)
872 reserved = true;
873 break;
875 if (reserved)
876 snprintf(buffer, buffer_len, "%02x: RSVD", selected_item);
877 else
878 snprintf(buffer, buffer_len, "%02x: %04x", selected_item,
879 tsc2100_readreg(*page, selected_item)&0xffff);
880 return buffer;
882 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
884 int *page = (int*)lists->data;
885 if (action == ACTION_STD_OK)
887 *page = (*page+1)%3;
888 snprintf(lists->title, 32,
889 "tsc2100 registers - Page %d", *page);
890 return ACTION_REDRAW;
892 return action;
894 static bool tsc2100_debug(void)
896 int page = 0;
897 char title[32] = "tsc2100 registers - Page 0";
898 struct simplelist_info info;
899 simplelist_info_init(&info, title, 32, &page);
900 info.timeout = HZ/100;
901 info.get_name = tsc2100_debug_getname;
902 info.action_callback= tsc2100debug_action_callback;
903 return simplelist_show_list(&info);
905 #endif
906 #if (CONFIG_BATTERY_MEASURE != 0) && defined(HAVE_LCD_BITMAP) && !defined(SIMULATOR)
908 * view_battery() shows a automatically scaled graph of the battery voltage
909 * over time. Usable for estimating battery life / charging rate.
910 * The power_history array is updated in power_thread of powermgmt.c.
913 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
914 #define BAT_TSPACE 20
915 #define BAT_YSPACE (LCD_HEIGHT - BAT_TSPACE)
918 static bool view_battery(void)
920 int view = 0;
921 int i, x, y, z, y1, y2, grid, graph;
922 unsigned short maxv, minv;
924 lcd_setfont(FONT_SYSFIXED);
926 while(1)
928 lcd_clear_display();
929 switch (view) {
930 case 0: /* voltage history graph */
931 /* Find maximum and minimum voltage for scaling */
932 minv = power_history[0];
933 maxv = minv + 1;
934 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
935 if (power_history[i] > maxv)
936 maxv = power_history[i];
937 if (power_history[i] < minv)
938 minv = power_history[i];
940 /* print header */
941 #if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
942 /* adjust grid scale */
943 if ((maxv - minv) > 50)
944 grid = 50;
945 else
946 grid = 5;
948 lcd_putsf(0, 0, "battery %d.%03dV", power_history[0] / 1000,
949 power_history[0] % 1000);
950 lcd_putsf(0, 1, "%d.%03d-%d.%03dV (%2dmV)",
951 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000,
952 grid);
953 #elif (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE)
954 /* adjust grid scale */
955 if ((maxv - minv) > 10)
956 grid = 10;
957 else
958 grid = 1;
959 lcd_putsf(0, 0, "battery %d%%", power_history[0]);
960 lcd_putsf(0, 1, "%d%%-%d%% (%d %%)", minv, maxv, grid);
961 #endif
963 i = 1;
964 while ((y = (minv - (minv % grid)+i*grid)) < maxv)
966 graph = ((y-minv)*BAT_YSPACE)/(maxv-minv);
967 graph = LCD_HEIGHT-1 - graph;
969 /* draw dotted horizontal grid line */
970 for (x=0; x<LCD_WIDTH;x=x+2)
971 lcd_drawpixel(x,graph);
973 i++;
976 x = 0;
977 /* draw plot of power history
978 * skip empty entries
980 for (i = BAT_LAST_VAL - 1; i > 0; i--)
982 if (power_history[i] && power_history[i-1])
984 y1 = (power_history[i] - minv) * BAT_YSPACE /
985 (maxv - minv);
986 y1 = MIN(MAX(LCD_HEIGHT-1 - y1, BAT_TSPACE),
987 LCD_HEIGHT-1);
988 y2 = (power_history[i-1] - minv) * BAT_YSPACE /
989 (maxv - minv);
990 y2 = MIN(MAX(LCD_HEIGHT-1 - y2, BAT_TSPACE),
991 LCD_HEIGHT-1);
993 lcd_set_drawmode(DRMODE_SOLID);
995 /* make line thicker */
996 lcd_drawline(((x*LCD_WIDTH)/(BAT_LAST_VAL)),
997 y1,
998 (((x+1)*LCD_WIDTH)/(BAT_LAST_VAL)),
999 y2);
1000 lcd_drawline(((x*LCD_WIDTH)/(BAT_LAST_VAL))+1,
1001 y1+1,
1002 (((x+1)*LCD_WIDTH)/(BAT_LAST_VAL))+1,
1003 y2+1);
1004 x++;
1007 break;
1009 case 1: /* status: */
1010 #if CONFIG_CHARGING >= CHARGING_MONITOR
1011 lcd_putsf(0, 0, "Pwr status: %s",
1012 charging_state() ? "charging" : "discharging");
1013 #else
1014 lcd_puts(0, 0, "Power status: unknown");
1015 #endif
1016 battery_read_info(&y, &z);
1017 if (y > 0)
1018 lcd_putsf(0, 1, "Battery: %d.%03d V (%d %%)", y / 1000, y % 1000, z);
1019 else if (z > 0)
1020 lcd_putsf(0, 1, "Battery: %d %%", z);
1021 #ifdef ADC_EXT_POWER
1022 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1023 lcd_putsf(0, 2, "External: %d.%03d V", y / 1000, y % 1000);
1024 #endif
1025 #if CONFIG_CHARGING
1026 #if defined ARCHOS_RECORDER
1027 lcd_putsf(0, 3, "Chgr: %s %s",
1028 charger_inserted() ? "present" : "absent",
1029 charger_enabled() ? "on" : "off");
1030 lcd_putsf(0, 5, "short delta: %d", short_delta);
1031 lcd_putsf(0, 6, "long delta: %d", long_delta);
1032 lcd_puts(0, 7, power_message);
1033 lcd_putsf(0, 8, "USB Inserted: %s",
1034 usb_inserted() ? "yes" : "no");
1035 #elif defined IPOD_NANO || defined IPOD_VIDEO
1036 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1037 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1038 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1039 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1040 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1042 lcd_putsf(0, 3, "USB pwr: %s",
1043 usb_pwr ? "present" : "absent");
1044 lcd_putsf(0, 4, "EXT pwr: %s",
1045 ext_pwr ? "present" : "absent");
1046 lcd_putsf(0, 5, "Battery: %s",
1047 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1048 lcd_putsf(0, 6, "Dock mode: %s",
1049 dock ? "enabled" : "disabled");
1050 lcd_putsf(0, 7, "Headphone: %s",
1051 headphone ? "connected" : "disconnected");
1052 #ifdef IPOD_VIDEO
1053 if(probed_ramsize == 64)
1054 x = (adc_read(ADC_4066_ISTAT) * 2400) / (1024 * 2);
1055 else
1056 #endif
1057 x = (adc_read(ADC_4066_ISTAT) * 2400) / (1024 * 3);
1058 lcd_putsf(0, 8, "Ibat: %d mA", x);
1059 lcd_putsf(0, 9, "Vbat * Ibat: %d mW", x * y / 1000);
1060 #elif defined TOSHIBA_GIGABEAT_S
1061 int line = 3;
1062 unsigned int st;
1064 static const unsigned char * const chrgstate_strings[] =
1066 "Disabled",
1067 "Error",
1068 "Discharging",
1069 "Precharge",
1070 "Constant Voltage",
1071 "Constant Current",
1072 "<unknown>",
1075 lcd_putsf(0, line++, "Charger: %s",
1076 charger_inserted() ? "present" : "absent");
1078 st = power_input_status() &
1079 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1080 lcd_putsf(0, line++, "%s%s",
1081 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1082 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1084 y = ARRAYLEN(chrgstate_strings) - 1;
1086 switch (charge_state)
1088 case CHARGE_STATE_DISABLED: y--;
1089 case CHARGE_STATE_ERROR: y--;
1090 case DISCHARGING: y--;
1091 case TRICKLE: y--;
1092 case TOPOFF: y--;
1093 case CHARGING: y--;
1094 default:;
1097 lcd_putsf(0, line++, "State: %s", chrgstate_strings[y]);
1099 lcd_putsf(0, line++, "Battery Switch: %s",
1100 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1102 y = chrgraw_adc_voltage();
1103 lcd_putsf(0, line++, "CHRGRAW: %d.%03d V",
1104 y / 1000, y % 1000);
1106 y = application_supply_adc_voltage();
1107 lcd_putsf(0, line++, "BP : %d.%03d V",
1108 y / 1000, y % 1000);
1110 y = battery_adc_charge_current();
1111 if (y < 0) x = '-', y = -y;
1112 else x = ' ';
1113 lcd_putsf(0, line++, "CHRGISN:%c%d mA", x, y);
1115 y = cccv_regulator_dissipation();
1116 lcd_putsf(0, line++, "P CCCV : %d mW", y);
1118 y = battery_charge_current();
1119 if (y < 0) x = '-', y = -y;
1120 else x = ' ';
1121 lcd_putsf(0, line++, "I Charge:%c%d mA", x, y);
1123 y = battery_adc_temp();
1125 if (y != INT_MIN) {
1126 lcd_putsf(0, line++, "T Battery: %dC (%dF)", y,
1127 (9*y + 160) / 5);
1128 } else {
1129 /* Conversion disabled */
1130 lcd_puts(0, line++, "T Battery: ?");
1133 #elif defined(HAVE_AS3514) && defined(CONFIG_CHARGING)
1134 static const char * const chrgstate_strings[] =
1136 [CHARGE_STATE_DISABLED - CHARGE_STATE_DISABLED]= "Disabled",
1137 [CHARGE_STATE_ERROR - CHARGE_STATE_DISABLED] = "Error",
1138 [DISCHARGING - CHARGE_STATE_DISABLED] = "Discharging",
1139 [CHARGING - CHARGE_STATE_DISABLED] = "Charging",
1141 const char *str = NULL;
1143 lcd_putsf(0, 3, "Charger: %s",
1144 charger_inserted() ? "present" : "absent");
1146 y = charge_state - CHARGE_STATE_DISABLED;
1147 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1148 str = chrgstate_strings[y];
1150 lcd_putsf(0, 4, "State: %s",
1151 str ? str : "<unknown>");
1153 lcd_putsf(0, 5, "CHARGER: %02X", ascodec_read_charger());
1154 #elif defined(IPOD_NANO2G)
1155 y = pmu_read_battery_voltage();
1156 lcd_putsf(17, 1, "RAW: %d.%03d V", y / 1000, y % 1000);
1157 y = pmu_read_battery_current();
1158 lcd_putsf(0, 2, "Battery current: %d mA", y);
1159 lcd_putsf(0, 3, "PWRCON: %08x %08x", PWRCON, PWRCONEXT);
1160 lcd_putsf(0, 4, "CLKCON: %08x %03x %03x", CLKCON, CLKCON2, CLKCON3);
1161 lcd_putsf(0, 5, "PLL: %06x %06x %06x", PLL0PMS, PLL1PMS, PLL2PMS);
1162 x = pmu_read(0x1b) & 0xf;
1163 y = pmu_read(0x1a) * 25 + 625;
1164 lcd_putsf(0, 6, "AUTO: %x / %d mV", x, y);
1165 x = pmu_read(0x1f) & 0xf;
1166 y = pmu_read(0x1e) * 25 + 625;
1167 lcd_putsf(0, 7, "DOWN1: %x / %d mV", x, y);
1168 x = pmu_read(0x23) & 0xf;
1169 y = pmu_read(0x22) * 25 + 625;
1170 lcd_putsf(0, 8, "DOWN2: %x / %d mV", x, y);
1171 x = pmu_read(0x27) & 0xf;
1172 y = pmu_read(0x26) * 100 + 900;
1173 lcd_putsf(0, 9, "MEMLDO: %x / %d mV", x, y);
1174 for (i = 0; i < 6; i++)
1176 x = pmu_read(0x2e + (i << 1)) & 0xf;
1177 y = pmu_read(0x2d + (i << 1)) * 100 + 900;
1178 lcd_putsf(0, 10 + i, "LDO%d: %x / %d mV", i + 1, x, y);
1180 #else
1181 lcd_putsf(0, 3, "Charger: %s",
1182 charger_inserted() ? "present" : "absent");
1183 #endif /* target type */
1184 #endif /* CONFIG_CHARGING */
1185 break;
1186 case 2: /* voltage deltas: */
1187 #if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
1188 lcd_puts(0, 0, "Voltage deltas:");
1189 for (i = 0; i < POWER_HISTORY_LEN-1; i++) {
1190 y = power_history[i] - power_history[i+1];
1191 lcd_putsf(0, i+1, "-%d min: %c%d.%03d V", i,
1192 (y < 0) ? '-' : ' ', ((y < 0) ? y * -1 : y) / 1000,
1193 ((y < 0) ? y * -1 : y ) % 1000);
1195 #elif (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE)
1196 lcd_puts(0, 0, "Percentage deltas:");
1197 for (i = 0; i < POWER_HISTORY_LEN-1; i++) {
1198 y = power_history[i] - power_history[i+1];
1199 lcd_putsf(0, i+1, "-%d min: %c%d%%", i,
1200 (y < 0) ? '-' : ' ', ((y < 0) ? y * -1 : y));
1202 #endif
1203 break;
1205 case 3: /* remaining time estimation: */
1207 #ifdef ARCHOS_RECORDER
1208 lcd_putsf(0, 0, "charge_state: %d", charge_state);
1210 lcd_putsf(0, 1, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1212 lcd_putsf(0, 2, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1214 lcd_putsf(0, 3, "P=%2d I=%2d", pid_p, pid_i);
1216 lcd_putsf(0, 4, "Trickle sec: %d/60", trickle_sec);
1217 #endif /* ARCHOS_RECORDER */
1219 #if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
1220 lcd_putsf(0, 5, "Last PwrHist: %d.%03dV",
1221 power_history[0] / 1000,
1222 power_history[0] % 1000);
1223 #endif
1225 lcd_putsf(0, 6, "battery level: %d%%", battery_level());
1227 int time_left = battery_time();
1228 if (time_left >= 0)
1229 lcd_putsf(0, 7, "Est. remain: %d m", time_left);
1230 else
1231 lcd_puts(0, 7, "Estimation n/a");
1232 break;
1235 lcd_update();
1237 switch(get_action(CONTEXT_STD,HZ/2))
1239 case ACTION_STD_PREV:
1240 if (view)
1241 view--;
1242 break;
1244 case ACTION_STD_NEXT:
1245 if (view < 3)
1246 view++;
1247 break;
1249 case ACTION_STD_CANCEL:
1250 lcd_setfont(FONT_UI);
1251 return false;
1254 lcd_setfont(FONT_UI);
1255 return false;
1258 #endif /* (CONFIG_BATTERY_MEASURE != 0) && HAVE_LCD_BITMAP */
1260 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
1261 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1263 #if (CONFIG_STORAGE & STORAGE_MMC)
1264 #define CARDTYPE "MMC"
1265 #elif (CONFIG_STORAGE & STORAGE_SD)
1266 #define CARDTYPE "microSD"
1267 #endif
1269 static int disk_callback(int btn, struct gui_synclist *lists)
1271 tCardInfo *card;
1272 int *cardnum = (int*)lists->data;
1273 unsigned char card_name[6];
1274 unsigned char pbuf[32];
1275 char *title = lists->title;
1276 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1277 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1278 static const unsigned char * const kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1279 static const unsigned char * const nsec_units[] = { "ns", "µs", "ms" };
1280 #if (CONFIG_STORAGE & STORAGE_MMC)
1281 static const char * const mmc_spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1282 "3.1-3.31", "4.0" };
1283 #endif
1285 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1287 #ifdef HAVE_HOTSWAP
1288 if (btn == ACTION_STD_OK)
1290 *cardnum ^= 0x1; /* change cards */
1292 #endif
1294 simplelist_set_line_count(0);
1296 card = card_get_info(*cardnum);
1298 if (card->initialized > 0)
1300 unsigned i;
1301 for (i=0; i<sizeof(card_name); i++)
1303 card_name[i] = card_extract_bits(card->cid, (103-8*i), 8);
1305 strlcpy(card_name, card_name, sizeof(card_name));
1306 simplelist_addline(SIMPLELIST_ADD_LINE,
1307 "%s Rev %d.%d", card_name,
1308 (int) card_extract_bits(card->cid, 63, 4),
1309 (int) card_extract_bits(card->cid, 59, 4));
1310 simplelist_addline(SIMPLELIST_ADD_LINE,
1311 "Prod: %d/%d",
1312 #if (CONFIG_STORAGE & STORAGE_SD)
1313 (int) card_extract_bits(card->cid, 11, 4),
1314 (int) card_extract_bits(card->cid, 19, 8) + 2000
1315 #elif (CONFIG_STORAGE & STORAGE_MMC)
1316 (int) card_extract_bits(card->cid, 15, 4),
1317 (int) card_extract_bits(card->cid, 11, 4) + 1997
1318 #endif
1320 simplelist_addline(SIMPLELIST_ADD_LINE,
1321 #if (CONFIG_STORAGE & STORAGE_SD)
1322 "Ser#: 0x%08lx",
1323 card_extract_bits(card->cid, 55, 32)
1324 #elif (CONFIG_STORAGE & STORAGE_MMC)
1325 "Ser#: 0x%04lx",
1326 card_extract_bits(card->cid, 47, 16)
1327 #endif
1330 simplelist_addline(SIMPLELIST_ADD_LINE, "M=%02x, "
1331 #if (CONFIG_STORAGE & STORAGE_SD)
1332 "O=%c%c",
1333 (int) card_extract_bits(card->cid, 127, 8),
1334 card_extract_bits(card->cid, 119, 8),
1335 card_extract_bits(card->cid, 111, 8)
1336 #elif (CONFIG_STORAGE & STORAGE_MMC)
1337 "O=%04x",
1338 (int) card_extract_bits(card->cid, 127, 8),
1339 (int) card_extract_bits(card->cid, 119, 16)
1340 #endif
1343 #if (CONFIG_STORAGE & STORAGE_MMC)
1344 int temp = card_extract_bits(card->csd, 125, 4);
1345 simplelist_addline(SIMPLELIST_ADD_LINE,
1346 "MMC v%s", temp < 5 ?
1347 mmc_spec_vers[temp] : "?.?");
1348 #endif
1349 simplelist_addline(SIMPLELIST_ADD_LINE,
1350 "Blocks: 0x%08lx", card->numblocks);
1351 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1352 kbit_units, false);
1353 simplelist_addline(SIMPLELIST_ADD_LINE,
1354 "Speed: %s", pbuf);
1355 output_dyn_value(pbuf, sizeof pbuf, card->taac,
1356 nsec_units, false);
1357 simplelist_addline(SIMPLELIST_ADD_LINE,
1358 "Taac: %s", pbuf);
1359 simplelist_addline(SIMPLELIST_ADD_LINE,
1360 "Nsac: %d clk", card->nsac);
1361 simplelist_addline(SIMPLELIST_ADD_LINE,
1362 "R2W: *%d", card->r2w_factor);
1363 #if (CONFIG_STORAGE & STORAGE_SD)
1364 int csd_structure = card_extract_bits(card->csd, 127, 2);
1365 if (csd_structure == 0) /* CSD version 1.0 */
1366 #endif
1368 simplelist_addline(SIMPLELIST_ADD_LINE,
1369 "IRmax: %d..%d mA",
1370 i_vmin[card_extract_bits(card->csd, 61, 3)],
1371 i_vmax[card_extract_bits(card->csd, 58, 3)]);
1372 simplelist_addline(SIMPLELIST_ADD_LINE,
1373 "IWmax: %d..%d mA",
1374 i_vmin[card_extract_bits(card->csd, 55, 3)],
1375 i_vmax[card_extract_bits(card->csd, 52, 3)]);
1378 else if (card->initialized == 0)
1380 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1382 #if (CONFIG_STORAGE & STORAGE_SD)
1383 else /* card->initialized < 0 */
1385 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1387 #endif
1388 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1389 gui_synclist_set_title(lists, title, Icon_NOICON);
1390 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1391 gui_synclist_select_item(lists, 0);
1392 btn = ACTION_REDRAW;
1394 return btn;
1396 #elif (CONFIG_STORAGE & STORAGE_ATA)
1397 static int disk_callback(int btn, struct gui_synclist *lists)
1399 (void)lists;
1400 int i;
1401 char buf[128];
1402 unsigned short* identify_info = ata_get_identify();
1403 bool timing_info_present = false;
1404 (void)btn;
1406 simplelist_set_line_count(0);
1408 for (i=0; i < 20; i++)
1409 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1410 buf[40]=0;
1411 /* kill trailing space */
1412 for (i=39; i && buf[i]==' '; i--)
1413 buf[i] = 0;
1414 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1415 for (i=0; i < 4; i++)
1416 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1417 buf[8]=0;
1418 simplelist_addline(SIMPLELIST_ADD_LINE,
1419 "Firmware: %s", buf);
1420 snprintf(buf, sizeof buf, "%ld MB",
1421 ((unsigned long)identify_info[61] << 16 |
1422 (unsigned long)identify_info[60]) / 2048 );
1423 simplelist_addline(SIMPLELIST_ADD_LINE,
1424 "Size: %s", buf);
1425 unsigned long free;
1426 fat_size( IF_MV2(0,) NULL, &free );
1427 simplelist_addline(SIMPLELIST_ADD_LINE,
1428 "Free: %ld MB", free / 1024);
1429 simplelist_addline(SIMPLELIST_ADD_LINE,
1430 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
1431 i = identify_info[83] & (1<<3);
1432 simplelist_addline(SIMPLELIST_ADD_LINE,
1433 "Power mgmt: %s", i ? "enabled" : "unsupported");
1434 i = identify_info[83] & (1<<9);
1435 simplelist_addline(SIMPLELIST_ADD_LINE,
1436 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1437 i = identify_info[82] & (1<<6);
1438 simplelist_addline(SIMPLELIST_ADD_LINE,
1439 "Read-ahead: %s", i ? "enabled" : "unsupported");
1440 timing_info_present = identify_info[53] & (1<<1);
1441 if(timing_info_present) {
1442 char pio3[2], pio4[2];pio3[1] = 0;
1443 pio4[1] = 0;
1444 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1445 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1446 simplelist_addline(SIMPLELIST_ADD_LINE,
1447 "PIO modes: 0 1 2 %s %s", pio3, pio4);
1449 else {
1450 simplelist_addline(SIMPLELIST_ADD_LINE,
1451 "No PIO mode info");
1453 timing_info_present = identify_info[53] & (1<<1);
1454 if(timing_info_present) {
1455 simplelist_addline(SIMPLELIST_ADD_LINE,
1456 "Cycle times %dns/%dns",
1457 identify_info[67],
1458 identify_info[68] );
1459 } else {
1460 simplelist_addline(SIMPLELIST_ADD_LINE,
1461 "No timing info");
1463 int sector_size = 512;
1464 if((identify_info[106] & 0xe000) == 0x6000)
1465 sector_size *= BIT_N(identify_info[106] & 0x000f);
1466 simplelist_addline(SIMPLELIST_ADD_LINE,
1467 "Physical sector size: %d", sector_size);
1468 #ifdef HAVE_ATA_DMA
1469 if (identify_info[63] & (1<<0)) {
1470 char mdma0[2], mdma1[2], mdma2[2];
1471 mdma0[1] = mdma1[1] = mdma2[1] = 0;
1472 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
1473 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
1474 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
1475 simplelist_addline(SIMPLELIST_ADD_LINE,
1476 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
1477 simplelist_addline(SIMPLELIST_ADD_LINE,
1478 "MDMA Cycle times %dns/%dns",
1479 identify_info[65],
1480 identify_info[66] );
1482 else {
1483 simplelist_addline(SIMPLELIST_ADD_LINE,
1484 "No MDMA mode info");
1486 if (identify_info[53] & (1<<2)) {
1487 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2], udma6[2];
1488 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = udma6[1] = 0;
1489 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
1490 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
1491 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
1492 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
1493 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
1494 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
1495 udma6[0] = (identify_info[88] & (1<<6)) ? '6' : 0;
1496 simplelist_addline(SIMPLELIST_ADD_LINE,
1497 "UDMA modes: %s %s %s %s %s %s %s", udma0, udma1, udma2,
1498 udma3, udma4, udma5, udma6);
1500 else {
1501 simplelist_addline(SIMPLELIST_ADD_LINE,
1502 "No UDMA mode info");
1504 #endif /* HAVE_ATA_DMA */
1505 timing_info_present = identify_info[53] & (1<<1);
1506 if(timing_info_present) {
1507 i = identify_info[49] & (1<<11);
1508 simplelist_addline(SIMPLELIST_ADD_LINE,
1509 "IORDY support: %s", i ? "yes" : "no");
1510 i = identify_info[49] & (1<<10);
1511 simplelist_addline(SIMPLELIST_ADD_LINE,
1512 "IORDY disable: %s", i ? "yes" : "no");
1513 } else {
1514 simplelist_addline(SIMPLELIST_ADD_LINE,
1515 "No timing info");
1517 simplelist_addline(SIMPLELIST_ADD_LINE,
1518 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1519 #ifdef HAVE_ATA_DMA
1520 i = ata_get_dma_mode();
1521 if (i == 0) {
1522 simplelist_addline(SIMPLELIST_ADD_LINE,
1523 "DMA not enabled");
1524 } else {
1525 simplelist_addline(SIMPLELIST_ADD_LINE,
1526 "DMA mode: %s %c",
1527 (i & 0x40) ? "UDMA" : "MDMA",
1528 '0' + (i & 7));
1530 #endif /* HAVE_ATA_DMA */
1531 return btn;
1533 #else /* No SD, MMC or ATA */
1534 static int disk_callback(int btn, struct gui_synclist *lists)
1536 (void)lists;
1537 struct storage_info info;
1538 storage_get_info(0,&info);
1539 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
1540 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
1541 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
1542 simplelist_addline(SIMPLELIST_ADD_LINE,
1543 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
1544 unsigned long free;
1545 fat_size( IF_MV2(0,) NULL, &free );
1546 simplelist_addline(SIMPLELIST_ADD_LINE,
1547 "Free: %ld MB", free / 1024);
1548 simplelist_addline(SIMPLELIST_ADD_LINE,
1549 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1550 return btn;
1552 #endif
1554 #if (CONFIG_STORAGE & STORAGE_ATA)
1555 static bool dbg_identify_info(void)
1557 int fd = creat("/identify_info.bin", 0666);
1558 if(fd >= 0)
1560 #ifdef ROCKBOX_LITTLE_ENDIAN
1561 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
1562 #else
1563 write(fd, ata_get_identify(), SECTOR_SIZE);
1564 #endif
1565 close(fd);
1567 return false;
1569 #endif
1571 static bool dbg_disk_info(void)
1573 struct simplelist_info info;
1574 simplelist_info_init(&info, "Disk Info", 1, NULL);
1575 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1576 char title[16];
1577 int card = 0;
1578 info.callback_data = (void*)&card;
1579 info.title = title;
1580 #endif
1581 info.action_callback = disk_callback;
1582 info.hide_selection = true;
1583 info.scroll_all = true;
1584 return simplelist_show_list(&info);
1586 #endif /* PLATFORM_NATIVE */
1588 #ifdef HAVE_DIRCACHE
1589 static int dircache_callback(int btn, struct gui_synclist *lists)
1591 (void)lists;
1592 simplelist_set_line_count(0);
1593 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
1594 dircache_is_enabled() ? "Yes" : "No");
1595 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
1596 dircache_get_cache_size());
1597 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
1598 global_status.dircache_size);
1599 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
1600 DIRCACHE_LIMIT);
1601 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
1602 dircache_get_reserve_used(), DIRCACHE_RESERVE);
1603 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
1604 dircache_get_build_ticks() / HZ);
1605 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
1606 dircache_get_entry_count());
1607 return btn;
1610 static bool dbg_dircache_info(void)
1612 struct simplelist_info info;
1613 simplelist_info_init(&info, "Dircache Info", 7, NULL);
1614 info.action_callback = dircache_callback;
1615 info.hide_selection = true;
1616 info.scroll_all = true;
1617 return simplelist_show_list(&info);
1620 #endif /* HAVE_DIRCACHE */
1622 #ifdef HAVE_TAGCACHE
1623 static int database_callback(int btn, struct gui_synclist *lists)
1625 (void)lists;
1626 struct tagcache_stat *stat = tagcache_get_stat();
1627 static bool synced = false;
1629 simplelist_set_line_count(0);
1631 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
1632 stat->initialized ? "Yes" : "No");
1633 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
1634 stat->ready ? "Yes" : "No");
1635 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
1636 stat->ramcache ? "Yes" : "No");
1637 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
1638 stat->ramcache_used, stat->ramcache_allocated);
1639 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
1640 stat->progress, stat->processed_entries);
1641 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
1642 stat->curentry ? stat->curentry : "---");
1643 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
1644 stat->commit_step);
1645 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
1646 stat->commit_delayed ? "Yes" : "No");
1648 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
1649 stat->queue_length);
1651 if (synced)
1653 synced = false;
1654 tagcache_screensync_event();
1657 if (!btn && stat->curentry)
1659 synced = true;
1660 return ACTION_REDRAW;
1663 if (btn == ACTION_STD_CANCEL)
1664 tagcache_screensync_enable(false);
1666 return btn;
1668 static bool dbg_tagcache_info(void)
1670 struct simplelist_info info;
1671 simplelist_info_init(&info, "Database Info", 8, NULL);
1672 info.action_callback = database_callback;
1673 info.hide_selection = true;
1674 info.scroll_all = true;
1676 /* Don't do nonblock here, must give enough processing time
1677 for tagcache thread. */
1678 /* info.timeout = TIMEOUT_NOBLOCK; */
1679 info.timeout = 1;
1680 tagcache_screensync_enable(true);
1681 return simplelist_show_list(&info);
1683 #endif
1685 #if CONFIG_CPU == SH7034
1686 static bool dbg_save_roms(void)
1688 int fd;
1689 int oldmode = system_memory_guard(MEMGUARD_NONE);
1691 fd = creat("/internal_rom_0000-FFFF.bin", 0666);
1692 if(fd >= 0)
1694 write(fd, (void *)0, 0x10000);
1695 close(fd);
1698 fd = creat("/internal_rom_2000000-203FFFF.bin", 0666);
1699 if(fd >= 0)
1701 write(fd, (void *)0x2000000, 0x40000);
1702 close(fd);
1705 system_memory_guard(oldmode);
1706 return false;
1708 #elif defined CPU_COLDFIRE
1709 static bool dbg_save_roms(void)
1711 int fd;
1712 int oldmode = system_memory_guard(MEMGUARD_NONE);
1714 #if defined(IRIVER_H100_SERIES)
1715 fd = creat("/internal_rom_000000-1FFFFF.bin", 0666);
1716 #elif defined(IRIVER_H300_SERIES)
1717 fd = creat("/internal_rom_000000-3FFFFF.bin", 0666);
1718 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
1719 fd = creat("/internal_rom_000000-3FFFFF.bin", 0666);
1720 #elif defined(MPIO_HD200) || defined(MPIO_HD300)
1721 fd = creat("/internal_rom_000000-1FFFFF.bin", 0666);
1722 #endif
1723 if(fd >= 0)
1725 write(fd, (void *)0, FLASH_SIZE);
1726 close(fd);
1728 system_memory_guard(oldmode);
1730 #ifdef HAVE_EEPROM
1731 fd = creat("/internal_eeprom.bin", 0666);
1732 if (fd >= 0)
1734 int old_irq_level;
1735 char buf[EEPROM_SIZE];
1736 int err;
1738 old_irq_level = disable_irq_save();
1740 err = eeprom_24cxx_read(0, buf, sizeof buf);
1742 restore_irq(old_irq_level);
1744 if (err)
1745 splashf(HZ*3, "Eeprom read failure (%d)", err);
1746 else
1748 write(fd, buf, sizeof buf);
1751 close(fd);
1753 #endif
1755 return false;
1757 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
1758 static bool dbg_save_roms(void)
1760 int fd = creat("/internal_rom_000000-0FFFFF.bin", 0666);
1761 if(fd >= 0)
1763 write(fd, (void *)0x20000000, FLASH_SIZE);
1764 close(fd);
1767 return false;
1769 #elif CONFIG_CPU == IMX31L
1770 static bool dbg_save_roms(void)
1772 int fd = creat("/flash_rom_A0000000-A01FFFFF.bin", 0666);
1773 if (fd >= 0)
1775 write(fd, (void*)0xa0000000, FLASH_SIZE);
1776 close(fd);
1779 return false;
1781 #elif defined(CPU_TCC780X)
1782 static bool dbg_save_roms(void)
1784 int fd = creat("/eeprom_E0000000-E0001FFF.bin", 0666);
1785 if (fd >= 0)
1787 write(fd, (void*)0xe0000000, 0x2000);
1788 close(fd);
1791 return false;
1793 #endif /* CPU */
1795 #ifndef SIMULATOR
1796 #if CONFIG_TUNER
1798 #ifdef CONFIG_TUNER_MULTI
1799 static int tuner_type = 0;
1800 #define IF_TUNER_TYPE(type) if(tuner_type==type)
1801 #else
1802 #define IF_TUNER_TYPE(type)
1803 #endif
1805 static int radio_callback(int btn, struct gui_synclist *lists)
1807 (void)lists;
1808 if (btn == ACTION_STD_CANCEL)
1809 return btn;
1810 simplelist_set_line_count(1);
1812 #if (CONFIG_TUNER & LV24020LP)
1813 simplelist_addline(SIMPLELIST_ADD_LINE,
1814 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
1815 simplelist_addline(SIMPLELIST_ADD_LINE,
1816 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
1817 simplelist_addline(SIMPLELIST_ADD_LINE,
1818 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
1819 simplelist_addline(SIMPLELIST_ADD_LINE,
1820 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
1821 simplelist_addline(SIMPLELIST_ADD_LINE,
1822 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
1823 simplelist_addline(SIMPLELIST_ADD_LINE,
1824 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
1825 simplelist_addline(SIMPLELIST_ADD_LINE,
1826 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
1827 #endif /* LV24020LP */
1828 #if (CONFIG_TUNER & S1A0903X01)
1829 simplelist_addline(SIMPLELIST_ADD_LINE,
1830 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
1831 /* This one doesn't return dynamic data atm */
1832 #endif /* S1A0903X01 */
1833 #if (CONFIG_TUNER & TEA5767)
1834 struct tea5767_dbg_info nfo;
1835 tea5767_dbg_info(&nfo);
1836 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
1837 simplelist_addline(SIMPLELIST_ADD_LINE,
1838 " Read: %02X %02X %02X %02X %02X",
1839 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
1840 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
1841 (unsigned)nfo.read_regs[4]);
1842 simplelist_addline(SIMPLELIST_ADD_LINE,
1843 " Write: %02X %02X %02X %02X %02X",
1844 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
1845 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
1846 (unsigned)nfo.write_regs[4]);
1847 #endif /* TEA5767 */
1848 #if (CONFIG_TUNER & SI4700)
1849 IF_TUNER_TYPE(SI4700)
1851 struct si4700_dbg_info nfo;
1852 si4700_dbg_info(&nfo);
1853 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
1854 for (int i = 0; i < 16; i += 4) {
1855 simplelist_addline(SIMPLELIST_ADD_LINE,"%02X: %04X %04X %04X %04X",
1856 i, nfo.regs[i], nfo.regs[i+1], nfo.regs[i+2], nfo.regs[i+3]);
1859 #endif /* SI4700 */
1860 #if (CONFIG_TUNER & RDA5802)
1861 IF_TUNER_TYPE(RDA5802)
1863 struct rda5802_dbg_info nfo;
1864 rda5802_dbg_info(&nfo);
1865 simplelist_addline(SIMPLELIST_ADD_LINE, "RDA5802 regs:");
1866 for (int i = 0; i < 16; i += 4) {
1867 simplelist_addline(SIMPLELIST_ADD_LINE,"%02X: %04X %04X %04X %04X",
1868 i, nfo.regs[i], nfo.regs[i+1], nfo.regs[i+2], nfo.regs[i+3]);
1871 #endif /* RDA55802 */
1873 #ifdef HAVE_RDS_CAP
1874 simplelist_addline(SIMPLELIST_ADD_LINE, "PI:%04X PS:'%8s'",
1875 rds_get_pi(), rds_get_ps());
1876 simplelist_addline(SIMPLELIST_ADD_LINE, "RT:%s",
1877 rds_get_rt());
1878 time_t seconds = rds_get_ct();
1879 struct tm* time = gmtime(&seconds);
1880 simplelist_addline(SIMPLELIST_ADD_LINE,
1881 "CT:%4d-%02d-%02d %02d:%02d",
1882 time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
1883 time->tm_hour, time->tm_min, time->tm_sec);
1884 #endif
1885 return ACTION_REDRAW;
1887 static bool dbg_fm_radio(void)
1889 struct simplelist_info info;
1890 #ifdef CONFIG_TUNER_MULTI
1891 tuner_type = tuner_detect_type();
1892 #endif
1893 info.scroll_all = true;
1894 simplelist_info_init(&info, "FM Radio", 1, NULL);
1895 simplelist_set_line_count(0);
1896 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
1897 radio_hardware_present() ? "yes" : "no");
1899 info.action_callback = radio_hardware_present()?radio_callback : NULL;
1900 info.hide_selection = true;
1901 return simplelist_show_list(&info);
1903 #endif /* CONFIG_TUNER */
1904 #endif /* !SIMULATOR */
1906 #if defined(HAVE_LCD_BITMAP) && !defined(APPLICATION)
1907 extern bool do_screendump_instead_of_usb;
1909 static bool dbg_screendump(void)
1911 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
1912 splashf(HZ, "Screendump %sabled", do_screendump_instead_of_usb?"en":"dis");
1913 return false;
1915 #endif /* HAVE_LCD_BITMAP */
1917 extern bool write_metadata_log;
1919 static bool dbg_metadatalog(void)
1921 write_metadata_log = !write_metadata_log;
1922 splashf(HZ, "Metadata log %sabled", write_metadata_log ? "en" : "dis");
1923 return false;
1926 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
1927 static bool dbg_set_memory_guard(void)
1929 static const struct opt_items names[MAXMEMGUARD] = {
1930 { "None", -1 },
1931 { "Flash ROM writes", -1 },
1932 { "Zero area (all)", -1 }
1934 int mode = system_memory_guard(MEMGUARD_KEEP);
1936 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
1937 system_memory_guard(mode);
1939 return false;
1941 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
1943 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
1944 static bool dbg_write_eeprom(void)
1946 int fd = open("/internal_eeprom.bin", O_RDONLY);
1948 if (fd >= 0)
1950 char buf[EEPROM_SIZE];
1951 int rc = read(fd, buf, EEPROM_SIZE);
1953 if(rc == EEPROM_SIZE)
1955 int old_irq_level = disable_irq_save();
1957 int err = eeprom_24cxx_write(0, buf, sizeof buf);
1958 if (err)
1959 splashf(HZ*3, "Eeprom write failure (%d)", err);
1960 else
1961 splash(HZ*3, "Eeprom written successfully");
1963 restore_irq(old_irq_level);
1965 else
1967 splashf(HZ*3, "File read error (%d)",rc);
1969 close(fd);
1971 else
1973 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
1976 return false;
1978 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
1979 #ifdef CPU_BOOST_LOGGING
1980 static bool cpu_boost_log(void)
1982 int count = cpu_boost_log_getcount();
1983 char *str = cpu_boost_log_getlog_first();
1984 bool done;
1985 lcd_setfont(FONT_SYSFIXED);
1986 for (int i = 0; i < count ;)
1988 lcd_clear_display();
1989 for(int j=0; j<LCD_HEIGHT/SYSFONT_HEIGHT; j++,i++)
1991 if (!str)
1992 str = cpu_boost_log_getlog_next();
1993 if (str)
1995 if(strlen(str) > LCD_WIDTH/SYSFONT_WIDTH)
1996 lcd_puts_scroll(0, j, str);
1997 else
1998 lcd_puts(0, j,str);
2000 str = NULL;
2002 lcd_update();
2003 done = false;
2004 while (!done)
2006 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2008 case ACTION_STD_OK:
2009 case ACTION_STD_PREV:
2010 case ACTION_STD_NEXT:
2011 done = true;
2012 break;
2013 case ACTION_STD_CANCEL:
2014 i = count;
2015 done = true;
2016 break;
2020 lcd_stop_scroll();
2021 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2022 lcd_setfont(FONT_UI);
2023 return false;
2025 #endif
2027 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) \
2028 && !defined(IPOD_MINI) && !defined(SIMULATOR))
2029 extern bool wheel_is_touched;
2030 extern int old_wheel_value;
2031 extern int new_wheel_value;
2032 extern int wheel_delta;
2033 extern unsigned int accumulated_wheel_delta;
2034 extern unsigned int wheel_velocity;
2036 static bool dbg_scrollwheel(void)
2038 lcd_setfont(FONT_SYSFIXED);
2040 while (1)
2042 if (action_userabort(HZ/10))
2043 break;
2045 lcd_clear_display();
2047 /* show internal variables of scrollwheel driver */
2048 lcd_putsf(0, 0, "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2049 lcd_putsf(0, 1, "new position: %2d", new_wheel_value);
2050 lcd_putsf(0, 2, "old position: %2d", old_wheel_value);
2051 lcd_putsf(0, 3, "wheel delta: %2d", wheel_delta);
2052 lcd_putsf(0, 4, "accumulated delta: %2d", accumulated_wheel_delta);
2053 lcd_putsf(0, 5, "velo [deg/s]: %4d", (int)wheel_velocity);
2055 /* show effective accelerated scrollspeed */
2056 lcd_putsf(0, 6, "accel. speed: %4d",
2057 button_apply_acceleration((1<<31)|(1<<24)|wheel_velocity) );
2059 lcd_update();
2061 lcd_setfont(FONT_UI);
2062 return false;
2064 #endif
2066 #ifdef HAVE_USBSTACK
2067 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2068 static bool toggle_usb_serial(void)
2070 bool enabled = !usb_core_driver_enabled(USB_DRIVER_SERIAL);
2072 usb_core_enable_driver(USB_DRIVER_SERIAL, enabled);
2073 splashf(HZ, "USB Serial %sabled", enabled ? "en" : "dis");
2075 return false;
2077 #endif
2078 #endif
2080 #if CONFIG_USBOTG == USBOTG_ISP1583
2081 extern int dbg_usb_num_items(void);
2082 extern const char* dbg_usb_item(int selected_item, void *data,
2083 char *buffer, size_t buffer_len);
2085 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2087 (void)lists;
2088 if (action == ACTION_NONE)
2089 action = ACTION_REDRAW;
2090 return action;
2093 static bool dbg_isp1583(void)
2095 struct simplelist_info isp1583;
2096 isp1583.scroll_all = true;
2097 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2098 isp1583.timeout = HZ/100;
2099 isp1583.hide_selection = true;
2100 isp1583.get_name = dbg_usb_item;
2101 isp1583.action_callback = isp1583_action_callback;
2102 return simplelist_show_list(&isp1583);
2104 #endif
2106 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2107 extern int pic_dbg_num_items(void);
2108 extern const char* pic_dbg_item(int selected_item, void *data,
2109 char *buffer, size_t buffer_len);
2111 static int pic_action_callback(int action, struct gui_synclist *lists)
2113 (void)lists;
2114 if (action == ACTION_NONE)
2115 action = ACTION_REDRAW;
2116 return action;
2119 static bool dbg_pic(void)
2121 struct simplelist_info pic;
2122 pic.scroll_all = true;
2123 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2124 pic.timeout = HZ/100;
2125 pic.hide_selection = true;
2126 pic.get_name = pic_dbg_item;
2127 pic.action_callback = pic_action_callback;
2128 return simplelist_show_list(&pic);
2130 #endif
2133 /****** The menu *********/
2134 static const struct {
2135 unsigned char *desc; /* string or ID */
2136 bool (*function) (void); /* return true if USB was connected */
2137 } menuitems[] = {
2138 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2139 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)) || \
2140 CONFIG_CPU == IMX31L || defined(CPU_TCC780X)
2141 { "Dump ROM contents", dbg_save_roms },
2142 #endif
2143 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2144 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 \
2145 || CONFIG_CPU == DM320 || defined(CPU_S5L870X) || CONFIG_CPU == AS3525v2 \
2146 || CONFIG_CPU == RK27XX
2147 { "View I/O ports", dbg_ports },
2148 #endif
2149 #if (CONFIG_RTC == RTC_PCF50605) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
2150 { "View PCF registers", dbg_pcf },
2151 #endif
2152 #if defined(HAVE_TSC2100) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
2153 { "TSC2100 debug", tsc2100_debug },
2154 #endif
2155 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2156 { "CPU frequency", dbg_cpufreq },
2157 #endif
2158 #if CONFIG_CPU == IMX31L
2159 { "DVFS/DPTC", __dbg_dvfs_dptc },
2160 #endif
2161 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2162 { "S/PDIF analyzer", dbg_spdif },
2163 #endif
2164 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2165 { "Catch mem accesses", dbg_set_memory_guard },
2166 #endif
2167 { "View OS stacks", dbg_os },
2168 #ifdef __linux__
2169 { "View CPU stats", dbg_cpuinfo },
2170 #endif
2171 #ifdef HAVE_LCD_BITMAP
2172 #if (CONFIG_BATTERY_MEASURE != 0) && !defined(SIMULATOR)
2173 { "View battery", view_battery },
2174 #endif
2175 #ifndef APPLICATION
2176 { "Screendump", dbg_screendump },
2177 #endif
2178 #endif
2179 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2180 { "View HW info", dbg_hw_info },
2181 #endif
2182 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2183 { "View partitions", dbg_partitions },
2184 #endif
2185 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2186 { "View disk info", dbg_disk_info },
2187 #if (CONFIG_STORAGE & STORAGE_ATA)
2188 { "Dump ATA identify info", dbg_identify_info},
2189 #endif
2190 #endif
2191 { "Metadata log", dbg_metadatalog },
2192 #ifdef HAVE_DIRCACHE
2193 { "View dircache info", dbg_dircache_info },
2194 #endif
2195 #ifdef HAVE_TAGCACHE
2196 { "View database info", dbg_tagcache_info },
2197 #endif
2198 #ifdef HAVE_LCD_BITMAP
2199 #if CONFIG_CODEC == SWCODEC
2200 { "View buffering thread", dbg_buffering_thread },
2201 #elif !defined(SIMULATOR)
2202 { "View audio thread", dbg_audio_thread },
2203 #endif
2204 #ifdef PM_DEBUG
2205 { "pm histogram", peak_meter_histogram},
2206 #endif /* PM_DEBUG */
2207 #endif /* HAVE_LCD_BITMAP */
2208 { "View buflib allocs", dbg_buflib_allocs },
2209 #ifndef SIMULATOR
2210 #if CONFIG_TUNER
2211 { "FM Radio", dbg_fm_radio },
2212 #endif
2213 #endif
2214 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2215 { "Write back EEPROM", dbg_write_eeprom },
2216 #endif
2217 #if CONFIG_USBOTG == USBOTG_ISP1583
2218 { "View ISP1583 info", dbg_isp1583 },
2219 #endif
2220 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2221 { "View PIC info", dbg_pic },
2222 #endif
2223 #ifdef ROCKBOX_HAS_LOGF
2224 {"Show Log File", logfdisplay },
2225 {"Dump Log File", logfdump },
2226 #endif
2227 #if defined(HAVE_USBSTACK)
2228 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2229 {"USB Serial driver (logf)", toggle_usb_serial },
2230 #endif
2231 #endif /* HAVE_USBSTACK */
2232 #ifdef CPU_BOOST_LOGGING
2233 {"cpu_boost log",cpu_boost_log},
2234 #endif
2235 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) \
2236 && !defined(IPOD_MINI) && !defined(SIMULATOR))
2237 {"Debug scrollwheel", dbg_scrollwheel },
2238 #endif
2241 static int menu_action_callback(int btn, struct gui_synclist *lists)
2243 int selection = gui_synclist_get_sel_pos(lists);
2244 if (btn == ACTION_STD_OK)
2246 FOR_NB_SCREENS(i)
2247 viewportmanager_theme_enable(i, false, NULL);
2248 menuitems[selection].function();
2249 btn = ACTION_REDRAW;
2250 FOR_NB_SCREENS(i)
2251 viewportmanager_theme_undo(i, false);
2253 else if (btn == ACTION_STD_CONTEXT)
2255 MENUITEM_STRINGLIST(menu_items, "Debug Menu", NULL, ID2P(LANG_ADD_TO_FAVES));
2256 if (do_menu(&menu_items, NULL, NULL, false) == 0)
2257 shortcuts_add(SHORTCUT_DEBUGITEM, menuitems[selection].desc);
2258 return ACTION_STD_CANCEL;
2260 return btn;
2263 static const char* menu_get_name(int item, void * data,
2264 char *buffer, size_t buffer_len)
2266 (void)data; (void)buffer; (void)buffer_len;
2267 return menuitems[item].desc;
2270 bool debug_menu(void)
2272 struct simplelist_info info;
2274 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2275 info.action_callback = menu_action_callback;
2276 info.get_name = menu_get_name;
2277 return simplelist_show_list(&info);
2280 bool run_debug_screen(char* screen)
2282 for (unsigned i=0; i<ARRAYLEN(menuitems); i++)
2283 if (!strcmp(screen, menuitems[i].desc))
2285 FOR_NB_SCREENS(j)
2286 viewportmanager_theme_enable(j, false, NULL);
2287 menuitems[i].function();
2288 FOR_NB_SCREENS(j)
2289 viewportmanager_theme_undo(j, false);
2290 return true;
2293 return false;