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