woops... fix the header and bump the plugin API
[kugel-rb.git] / apps / debug_menu.c
blob92eb245249f486d2c40dbeae4f2219d079bfd9e7
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Heikki Hannikainen
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <stdbool.h>
26 #include <string.h>
27 #include "lcd.h"
28 #include "menu.h"
29 #include "debug_menu.h"
30 #include "kernel.h"
31 #include "sprintf.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 "dircache.h"
50 #include "viewport.h"
51 #ifdef HAVE_TAGCACHE
52 #include "tagcache.h"
53 #endif
54 #include "lcd-remote.h"
55 #include "crc32.h"
56 #include "logf.h"
57 #ifndef SIMULATOR
58 #include "disk.h"
59 #include "adc.h"
60 #include "power.h"
61 #include "usb.h"
62 #include "rtc.h"
63 #include "storage.h"
64 #include "fat.h"
65 #include "mas.h"
66 #include "eeprom_24cxx.h"
67 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
68 #include "hotswap.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 #if CONFIG_CODEC == SWCODEC
85 #include "pcmbuf.h"
86 #include "buffering.h"
87 #include "playback.h"
88 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
89 #include "spdif.h"
90 #endif
91 #endif
92 #ifdef IRIVER_H300_SERIES
93 #include "pcf50606.h" /* for pcf50606_read */
94 #endif
95 #ifdef IAUDIO_X5
96 #include "ds2411.h"
97 #endif
98 #include "hwcompat.h"
99 #include "button.h"
100 #if CONFIG_RTC == RTC_PCF50605
101 #include "pcf50605.h"
102 #endif
104 #if CONFIG_CPU == DM320 || CONFIG_CPU == S3C2440 || CONFIG_CPU == TCC7801 \
105 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525
106 #include "debug-target.h"
107 #endif
109 #if defined(SANSA_E200) || defined(PHILIPS_SA9200)
110 #include "ascodec.h"
111 #include "as3514.h"
112 #endif
114 #if defined(HAVE_USBSTACK)
115 #include "usb_core.h"
116 #endif
117 #ifdef USB_STORAGE
118 #include "usbstack/usb_storage.h"
119 #endif
121 /*---------------------------------------------------*/
122 /* SPECIAL DEBUG STUFF */
123 /*---------------------------------------------------*/
124 extern struct thread_entry threads[MAXTHREADS];
126 static char thread_status_char(unsigned status)
128 static const char thread_status_chars[THREAD_NUM_STATES+1] =
130 [0 ... THREAD_NUM_STATES] = '?',
131 [STATE_RUNNING] = 'R',
132 [STATE_BLOCKED] = 'B',
133 [STATE_SLEEPING] = 'S',
134 [STATE_BLOCKED_W_TMO] = 'T',
135 [STATE_FROZEN] = 'F',
136 [STATE_KILLED] = 'K',
139 if (status > THREAD_NUM_STATES)
140 status = THREAD_NUM_STATES;
142 return thread_status_chars[status];
145 static char* threads_getname(int selected_item, void *data,
146 char *buffer, size_t buffer_len)
148 (void)data;
149 struct thread_entry *thread;
150 char name[32];
152 #if NUM_CORES > 1
153 if (selected_item < (int)NUM_CORES)
155 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
156 idle_stack_usage(selected_item));
157 return buffer;
160 selected_item -= NUM_CORES;
161 #endif
163 thread = &threads[selected_item];
165 if (thread->state == STATE_KILLED)
167 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
168 return buffer;
171 thread_get_name(name, 32, thread);
173 snprintf(buffer, buffer_len,
174 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
175 selected_item,
176 IF_COP(thread->core,)
177 #ifdef HAVE_SCHEDULER_BOOSTCTRL
178 (thread->cpu_boost) ? '+' :
179 #endif
180 ((thread->state == STATE_RUNNING) ? '*' : ' '),
181 thread_status_char(thread->state),
182 IF_PRIO(thread->base_priority, thread->priority, )
183 thread_stack_usage(thread), name);
185 return buffer;
187 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
189 (void)lists;
190 #ifdef ROCKBOX_HAS_LOGF
191 if (action == ACTION_STD_OK)
193 int selpos = gui_synclist_get_sel_pos(lists);
194 #if NUM_CORES > 1
195 if (selpos >= NUM_CORES)
196 remove_thread(&threads[selpos - NUM_CORES]);
197 #else
198 remove_thread(&threads[selpos]);
199 #endif
200 return ACTION_REDRAW;
202 #endif /* ROCKBOX_HAS_LOGF */
203 if (action == ACTION_NONE)
204 action = ACTION_REDRAW;
205 return action;
207 /* Test code!!! */
208 static bool dbg_os(void)
210 struct simplelist_info info;
211 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
212 #if NUM_CORES == 1
213 MAXTHREADS,
214 #else
215 MAXTHREADS+NUM_CORES,
216 #endif
217 NULL);
218 #ifndef ROCKBOX_HAS_LOGF
219 info.hide_selection = true;
220 info.scroll_all = true;
221 #endif
222 info.action_callback = dbg_threads_action_callback;
223 info.get_name = threads_getname;
224 return simplelist_show_list(&info);
227 #ifdef HAVE_LCD_BITMAP
228 #if CONFIG_CODEC != SWCODEC
229 #ifndef SIMULATOR
230 static bool dbg_audio_thread(void)
232 char buf[32];
233 struct audio_debug d;
235 lcd_setfont(FONT_SYSFIXED);
236 viewportmanager_set_statusbar(false);
238 while(1)
240 if (action_userabort(HZ/5))
241 return false;
243 audio_get_debugdata(&d);
245 lcd_clear_display();
247 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
248 lcd_puts(0, 0, buf);
249 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
250 lcd_puts(0, 1, buf);
251 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
252 lcd_puts(0, 2, buf);
253 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
254 lcd_puts(0, 3, buf);
255 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
256 lcd_puts(0, 4, buf);
257 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
258 lcd_puts(0, 5, buf);
260 /* Playable space left */
261 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
262 d.playable_space, HORIZONTAL);
264 /* Show the watermark limit */
265 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
266 d.low_watermark_level, HORIZONTAL);
268 snprintf(buf, sizeof(buf), "wm: %x - %x",
269 d.low_watermark_level, d.lowest_watermark_level);
270 lcd_puts(0, 7, buf);
272 lcd_update();
274 viewportmanager_set_statusbar(true);
275 return false;
277 #endif /* !SIMULATOR */
278 #else /* CONFIG_CODEC == SWCODEC */
279 extern size_t filebuflen;
280 /* This is a size_t, but call it a long so it puts a - when it's bad. */
282 static unsigned int ticks, boost_ticks, freq_sum;
284 static void dbg_audio_task(void)
286 #ifndef SIMULATOR
287 if(FREQ > CPUFREQ_NORMAL)
288 boost_ticks++;
289 freq_sum += FREQ/1000000; /* in MHz */
290 #endif
291 ticks++;
294 static bool dbg_buffering_thread(void)
296 char buf[32];
297 int button;
298 int line;
299 bool done = false;
300 size_t bufused;
301 size_t bufsize = pcmbuf_get_bufsize();
302 int pcmbufdescs = pcmbuf_descs();
303 struct buffering_debug d;
305 ticks = boost_ticks = freq_sum = 0;
307 tick_add_task(dbg_audio_task);
309 lcd_setfont(FONT_SYSFIXED);
310 viewportmanager_set_statusbar(false);
311 while(!done)
313 button = get_action(CONTEXT_STD,HZ/5);
314 switch(button)
316 case ACTION_STD_NEXT:
317 audio_next();
318 break;
319 case ACTION_STD_PREV:
320 audio_prev();
321 break;
322 case ACTION_STD_CANCEL:
323 done = true;
324 break;
327 buffering_get_debugdata(&d);
329 line = 0;
330 lcd_clear_display();
332 bufused = bufsize - pcmbuf_free();
334 snprintf(buf, sizeof(buf), "pcm: %7ld/%7ld", (long) bufused, (long) bufsize);
335 lcd_puts(0, line++, buf);
337 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
338 bufsize, 0, bufused, HORIZONTAL);
339 line++;
341 snprintf(buf, sizeof(buf), "alloc: %8ld/%8ld", audio_filebufused(),
342 (long) filebuflen);
343 lcd_puts(0, line++, buf);
345 #if LCD_HEIGHT > 80
346 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
347 filebuflen, 0, audio_filebufused(), HORIZONTAL);
348 line++;
350 snprintf(buf, sizeof(buf), "real: %8ld/%8ld", (long)d.buffered_data,
351 (long)filebuflen);
352 lcd_puts(0, line++, buf);
354 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
355 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
356 line++;
357 #endif
359 snprintf(buf, sizeof(buf), "usefl: %8ld/%8ld", (long)(d.useful_data),
360 (long)filebuflen);
361 lcd_puts(0, line++, buf);
363 #if LCD_HEIGHT > 80
364 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
365 filebuflen, 0, d.useful_data, HORIZONTAL);
366 line++;
367 #endif
369 snprintf(buf, sizeof(buf), "data_rem: %ld", (long)d.data_rem);
370 lcd_puts(0, line++, buf);
372 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
373 lcd_puts(0, line++, buf);
375 snprintf(buf, sizeof(buf), "handle count: %d", (int)d.num_handles);
376 lcd_puts(0, line++, buf);
378 #ifndef SIMULATOR
379 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
380 (int)((FREQ + 500000) / 1000000));
381 lcd_puts(0, line++, buf);
382 #endif
384 if (ticks > 0)
386 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
387 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
388 snprintf(buf, sizeof(buf), "boost ratio: %3d.%d%% (%2d.%dMHz)",
389 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
390 lcd_puts(0, line++, buf);
393 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
394 pcmbuf_used_descs(), pcmbufdescs);
395 lcd_puts(0, line++, buf);
397 lcd_update();
400 tick_remove_task(dbg_audio_task);
401 viewportmanager_set_statusbar(true);
403 return false;
405 #endif /* CONFIG_CODEC */
406 #endif /* HAVE_LCD_BITMAP */
409 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
410 /* Tool function to read the flash manufacturer and type, if available.
411 Only chips which could be reprogrammed in system will return values.
412 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
413 /* In IRAM to avoid problems when running directly from Flash */
414 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
415 unsigned addr1, unsigned addr2)
416 ICODE_ATTR __attribute__((noinline));
417 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
418 unsigned addr1, unsigned addr2)
421 unsigned not_manu, not_id; /* read values before switching to ID mode */
422 unsigned manu, id; /* read values when in ID mode */
424 #if CONFIG_CPU == SH7034
425 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
426 #elif defined(CPU_COLDFIRE)
427 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
428 #endif
429 int old_level; /* saved interrupt level */
431 not_manu = flash[0]; /* read the normal content */
432 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
434 /* disable interrupts, prevent any stray flash access */
435 old_level = disable_irq_save();
437 flash[addr1] = 0xAA; /* enter command mode */
438 flash[addr2] = 0x55;
439 flash[addr1] = 0x90; /* ID command */
440 /* Atmel wants 20ms pause here */
441 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
443 manu = flash[0]; /* read the IDs */
444 id = flash[1];
446 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
447 /* Atmel wants 20ms pause here */
448 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
450 restore_irq(old_level); /* enable interrupts again */
452 /* I assume success if the obtained values are different from
453 the normal flash content. This is not perfectly bulletproof, they
454 could theoretically be the same by chance, causing us to fail. */
455 if (not_manu != manu || not_id != id) /* a value has changed */
457 *p_manufacturer = manu; /* return the results */
458 *p_device = id;
459 return true; /* success */
461 return false; /* fail */
463 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
465 #ifndef SIMULATOR
466 #ifdef CPU_PP
467 static int perfcheck(void)
469 int result;
471 asm (
472 "mrs r2, CPSR \n"
473 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
474 "msr CPSR_c, r0 \n"
475 "mov %[res], #0 \n"
476 "ldr r0, [%[timr]] \n"
477 "add r0, r0, %[tmo] \n"
478 "1: \n"
479 "add %[res], %[res], #1 \n"
480 "ldr r1, [%[timr]] \n"
481 "cmp r1, r0 \n"
482 "bmi 1b \n"
483 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
485 [res]"=&r"(result)
487 [timr]"r"(&USEC_TIMER),
488 [tmo]"r"(
489 #if CONFIG_CPU == PP5002
490 16000
491 #else /* PP5020/5022/5024 */
492 10226
493 #endif
496 "r0", "r1", "r2"
498 return result;
500 #endif
502 #ifdef HAVE_LCD_BITMAP
503 static bool dbg_hw_info(void)
505 #if CONFIG_CPU == SH7034
506 char buf[32];
507 int bitmask = HW_MASK;
508 int rom_version = ROM_VERSION;
509 unsigned manu, id; /* flash IDs */
510 bool got_id; /* flag if we managed to get the flash IDs */
511 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
512 bool has_bootrom; /* flag for boot ROM present */
513 int oldmode; /* saved memory guard mode */
515 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
517 /* get flash ROM type */
518 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
519 if (!got_id)
520 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
522 /* check if the boot ROM area is a flash mirror */
523 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
524 if (has_bootrom) /* if ROM and Flash different */
526 /* calculate CRC16 checksum of boot ROM */
527 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
530 system_memory_guard(oldmode); /* re-enable memory guard */
532 lcd_setfont(FONT_SYSFIXED);
533 lcd_clear_display();
534 viewportmanager_set_statusbar(false);
536 lcd_puts(0, 0, "[Hardware info]");
538 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
539 lcd_puts(0, 1, buf);
541 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
542 lcd_puts(0, 2, buf);
544 if (got_id)
545 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
546 else
547 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
548 lcd_puts(0, 3, buf);
550 if (has_bootrom)
552 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
553 snprintf(buf, 32, "Boot ROM: V1");
554 else
555 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
557 else
559 snprintf(buf, 32, "Boot ROM: none");
561 lcd_puts(0, 4, buf);
563 lcd_update();
565 while (!(action_userabort(TIMEOUT_BLOCK)));
567 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
568 char buf[32];
569 unsigned manu, id; /* flash IDs */
570 int got_id; /* flag if we managed to get the flash IDs */
571 int oldmode; /* saved memory guard mode */
572 int line = 0;
573 viewportmanager_set_statusbar(false);
575 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
577 /* get flash ROM type */
578 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
579 if (!got_id)
580 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
582 system_memory_guard(oldmode); /* re-enable memory guard */
584 lcd_setfont(FONT_SYSFIXED);
585 lcd_clear_display();
587 lcd_puts(0, line++, "[Hardware info]");
589 if (got_id)
590 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
591 else
592 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
593 lcd_puts(0, line++, buf);
595 #ifdef IAUDIO_X5
597 struct ds2411_id id;
599 lcd_puts(0, ++line, "Serial Number:");
601 got_id = ds2411_read_id(&id);
603 if (got_id == DS2411_OK)
605 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
606 lcd_puts(0, ++line, buf);
607 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
608 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
609 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
610 lcd_puts(0, ++line, buf);
611 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
613 else
615 snprintf(buf, 32, "READ ERR=%d", got_id);
618 lcd_puts(0, ++line, buf);
620 #endif
622 lcd_update();
624 while (!(action_userabort(TIMEOUT_BLOCK)));
626 #elif defined(CPU_PP502x)
627 int line = 0;
628 char buf[32];
629 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
630 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
631 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
632 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
634 lcd_setfont(FONT_SYSFIXED);
635 lcd_clear_display();
636 viewportmanager_set_statusbar(false);
638 lcd_puts(0, line++, "[Hardware info]");
640 #ifdef IPOD_ARCH
641 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
642 lcd_puts(0, line++, buf);
643 #endif
645 #ifdef IPOD_COLOR
646 extern int lcd_type; /* Defined in lcd-colornano.c */
648 snprintf(buf, sizeof(buf), "LCD type: %d", lcd_type);
649 lcd_puts(0, line++, buf);
650 #endif
652 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
653 lcd_puts(0, line++, buf);
655 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
656 lcd_puts(0, line++, buf);
658 lcd_update();
660 while (!(action_userabort(TIMEOUT_BLOCK)));
662 #elif CONFIG_CPU == PP5002
663 int line = 0;
664 char buf[32];
665 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
666 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
667 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
668 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
671 lcd_setfont(FONT_SYSFIXED);
672 lcd_clear_display();
674 lcd_puts(0, line++, "[Hardware info]");
676 #ifdef IPOD_ARCH
677 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
678 lcd_puts(0, line++, buf);
679 #endif
681 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
682 lcd_puts(0, line++, buf);
684 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
685 lcd_puts(0, line++, buf);
687 lcd_update();
689 while (!(action_userabort(TIMEOUT_BLOCK)));
691 #else
692 /* Define this function in your target tree */
693 return __dbg_hw_info();
694 #endif /* CONFIG_CPU */
695 viewportmanager_set_statusbar(true);
696 return false;
698 #else /* !HAVE_LCD_BITMAP */
699 static bool dbg_hw_info(void)
701 char buf[32];
702 int button;
703 int currval = 0;
704 int rom_version = ROM_VERSION;
705 unsigned manu, id; /* flash IDs */
706 bool got_id; /* flag if we managed to get the flash IDs */
707 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
708 bool has_bootrom; /* flag for boot ROM present */
709 int oldmode; /* saved memory guard mode */
711 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
713 /* get flash ROM type */
714 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
715 if (!got_id)
716 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
718 /* check if the boot ROM area is a flash mirror */
719 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
720 if (has_bootrom) /* if ROM and Flash different */
722 /* calculate CRC16 checksum of boot ROM */
723 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
726 system_memory_guard(oldmode); /* re-enable memory guard */
728 lcd_clear_display();
730 lcd_puts(0, 0, "[HW Info]");
731 while(1)
733 switch(currval)
735 case 0:
736 snprintf(buf, 32, "ROM: %d.%02d",
737 rom_version/100, rom_version%100);
738 break;
739 case 1:
740 if (got_id)
741 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
742 else
743 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
744 break;
745 case 2:
746 if (has_bootrom)
748 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
749 snprintf(buf, 32, "BootROM: V1");
750 else if (rom_crc == 0x358099E8)
751 snprintf(buf, 32, "BootROM: V2");
752 /* alternative boot ROM found in one single player so far */
753 else
754 snprintf(buf, 32, "R: %08x", rom_crc);
756 else
757 snprintf(buf, 32, "BootROM: no");
760 lcd_puts(0, 1, buf);
761 lcd_update();
763 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
765 switch(button)
767 case ACTION_STD_CANCEL:
768 return false;
770 case ACTION_SETTINGS_DEC:
771 currval--;
772 if(currval < 0)
773 currval = 2;
774 break;
776 case ACTION_SETTINGS_INC:
777 currval++;
778 if(currval > 2)
779 currval = 0;
780 break;
783 return false;
785 #endif /* !HAVE_LCD_BITMAP */
786 #endif /* !SIMULATOR */
788 #ifndef SIMULATOR
789 static char* dbg_partitions_getname(int selected_item, void *data,
790 char *buffer, size_t buffer_len)
792 (void)data;
793 int partition = selected_item/2;
794 struct partinfo* p = disk_partinfo(partition);
795 if (selected_item%2)
797 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / 2048);
799 else
801 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
803 return buffer;
806 bool dbg_partitions(void)
808 struct simplelist_info info;
809 simplelist_info_init(&info, "Partition Info", 4, NULL);
810 info.selection_size = 2;
811 info.hide_selection = true;
812 info.scroll_all = true;
813 info.get_name = dbg_partitions_getname;
814 return simplelist_show_list(&info);
816 #endif
818 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
819 static bool dbg_spdif(void)
821 char buf[128];
822 int line;
823 unsigned int control;
824 int x;
825 char *s;
826 int category;
827 int generation;
828 unsigned int interruptstat;
829 bool valnogood, symbolerr, parityerr;
830 bool done = false;
831 bool spdif_src_on;
832 int spdif_source = spdif_get_output_source(&spdif_src_on);
833 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
835 lcd_clear_display();
836 lcd_setfont(FONT_SYSFIXED);
837 viewportmanager_set_statusbar(false);
839 #ifdef HAVE_SPDIF_POWER
840 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
841 #endif
843 while (!done)
845 line = 0;
847 control = EBU1RCVCCHANNEL1;
848 interruptstat = INTERRUPTSTAT;
849 INTERRUPTCLEAR = 0x03c00000;
851 valnogood = (interruptstat & 0x01000000)?true:false;
852 symbolerr = (interruptstat & 0x00800000)?true:false;
853 parityerr = (interruptstat & 0x00400000)?true:false;
855 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
856 valnogood?"--":"OK",
857 symbolerr?"--":"OK",
858 parityerr?"--":"OK");
859 lcd_puts(0, line++, buf);
861 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
862 lcd_puts(0, line++, buf);
864 line++;
866 x = control >> 31;
867 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
868 x, x?"Professional":"Consumer");
869 lcd_puts(0, line++, buf);
871 x = (control >> 30) & 1;
872 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
873 x, x?"Non-PCM":"PCM");
874 lcd_puts(0, line++, buf);
876 x = (control >> 29) & 1;
877 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
878 x, x?"Permitted":"Inhibited");
879 lcd_puts(0, line++, buf);
881 x = (control >> 27) & 7;
882 switch(x)
884 case 0:
885 s = "None";
886 break;
887 case 1:
888 s = "50/15us";
889 break;
890 default:
891 s = "Reserved";
892 break;
894 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
895 lcd_puts(0, line++, buf);
897 x = (control >> 24) & 3;
898 snprintf(buf, sizeof(buf), "Mode: %d", x);
899 lcd_puts(0, line++, buf);
901 category = (control >> 17) & 127;
902 switch(category)
904 case 0x00:
905 s = "General";
906 break;
907 case 0x40:
908 s = "Audio CD";
909 break;
910 default:
911 s = "Unknown";
913 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
914 lcd_puts(0, line++, buf);
916 x = (control >> 16) & 1;
917 generation = x;
918 if(((category & 0x70) == 0x10) ||
919 ((category & 0x70) == 0x40) ||
920 ((category & 0x78) == 0x38))
922 generation = !generation;
924 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
925 x, generation?"Original":"No ind.");
926 lcd_puts(0, line++, buf);
928 x = (control >> 12) & 15;
929 snprintf(buf, sizeof(buf), "Source: %d", x);
930 lcd_puts(0, line++, buf);
932 x = (control >> 8) & 15;
933 switch(x)
935 case 0:
936 s = "Unspecified";
937 break;
938 case 8:
939 s = "A (Left)";
940 break;
941 case 4:
942 s = "B (Right)";
943 break;
944 default:
945 s = "";
946 break;
948 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
949 lcd_puts(0, line++, buf);
951 x = (control >> 4) & 15;
952 switch(x)
954 case 0:
955 s = "44.1kHz";
956 break;
957 case 0x4:
958 s = "48kHz";
959 break;
960 case 0xc:
961 s = "32kHz";
962 break;
964 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
965 lcd_puts(0, line++, buf);
967 x = (control >> 2) & 3;
968 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
969 lcd_puts(0, line++, buf);
970 line++;
972 #ifndef SIMULATOR
973 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
974 spdif_measure_frequency());
975 lcd_puts(0, line++, buf);
976 #endif
978 lcd_update();
980 if (action_userabort(HZ/10))
981 break;
984 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
986 #ifdef HAVE_SPDIF_POWER
987 spdif_power_enable(global_settings.spdif_enable);
988 #endif
990 viewportmanager_set_statusbar(true);
991 return false;
993 #endif /* CPU_COLDFIRE */
995 #ifndef SIMULATOR
996 #ifdef HAVE_LCD_BITMAP
997 /* button definitions */
998 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
999 (CONFIG_KEYPAD == IRIVER_H300_PAD)
1000 # define DEBUG_CANCEL BUTTON_OFF
1002 #elif CONFIG_KEYPAD == RECORDER_PAD
1003 # define DEBUG_CANCEL BUTTON_OFF
1005 #elif CONFIG_KEYPAD == ONDIO_PAD
1006 # define DEBUG_CANCEL BUTTON_MENU
1008 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
1009 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
1010 (CONFIG_KEYPAD == IPOD_4G_PAD)
1011 # define DEBUG_CANCEL BUTTON_MENU
1013 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
1014 # define DEBUG_CANCEL BUTTON_PLAY
1016 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
1017 # define DEBUG_CANCEL BUTTON_REC
1019 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1020 # define DEBUG_CANCEL BUTTON_RC_REC
1022 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
1023 # define DEBUG_CANCEL BUTTON_REW
1025 #elif (CONFIG_KEYPAD == MROBE100_PAD)
1026 # define DEBUG_CANCEL BUTTON_MENU
1028 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
1029 (CONFIG_KEYPAD == SANSA_C200_PAD)
1030 # define DEBUG_CANCEL BUTTON_LEFT
1032 /* This is temporary until the SA9200 touchpad works */
1033 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) || \
1034 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD)
1035 # define DEBUG_CANCEL BUTTON_POWER
1037 #endif /* key definitions */
1039 /* Test code!!! */
1040 bool dbg_ports(void)
1042 #if CONFIG_CPU == SH7034
1043 char buf[32];
1044 int adc_battery_voltage, adc_battery_level;
1046 lcd_setfont(FONT_SYSFIXED);
1047 lcd_clear_display();
1048 viewportmanager_set_statusbar(false);
1050 while(1)
1052 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1053 lcd_puts(0, 0, buf);
1054 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1055 lcd_puts(0, 1, buf);
1057 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1058 lcd_puts(0, 2, buf);
1059 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1060 lcd_puts(0, 3, buf);
1061 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1062 lcd_puts(0, 4, buf);
1063 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1064 lcd_puts(0, 5, buf);
1066 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1067 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1068 adc_battery_voltage % 1000, adc_battery_level);
1069 lcd_puts(0, 6, buf);
1071 lcd_update();
1072 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1074 viewportmanager_set_statusbar(true);
1075 return false;
1078 #elif defined(CPU_COLDFIRE)
1079 unsigned int gpio_out;
1080 unsigned int gpio1_out;
1081 unsigned int gpio_read;
1082 unsigned int gpio1_read;
1083 unsigned int gpio_function;
1084 unsigned int gpio1_function;
1085 unsigned int gpio_enable;
1086 unsigned int gpio1_enable;
1087 int adc_buttons, adc_remote;
1088 int adc_battery_voltage, adc_battery_level;
1089 char buf[128];
1090 int line;
1092 lcd_clear_display();
1093 lcd_setfont(FONT_SYSFIXED);
1094 viewportmanager_set_statusbar(false);
1096 while(1)
1098 line = 0;
1099 gpio_read = GPIO_READ;
1100 gpio1_read = GPIO1_READ;
1101 gpio_out = GPIO_OUT;
1102 gpio1_out = GPIO1_OUT;
1103 gpio_function = GPIO_FUNCTION;
1104 gpio1_function = GPIO1_FUNCTION;
1105 gpio_enable = GPIO_ENABLE;
1106 gpio1_enable = GPIO1_ENABLE;
1108 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1109 lcd_puts(0, line++, buf);
1110 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1111 lcd_puts(0, line++, buf);
1112 snprintf(buf, sizeof(buf), "GPIO_FUNC: %08x", gpio_function);
1113 lcd_puts(0, line++, buf);
1114 snprintf(buf, sizeof(buf), "GPIO_ENA: %08x", gpio_enable);
1115 lcd_puts(0, line++, buf);
1117 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1118 lcd_puts(0, line++, buf);
1119 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1120 lcd_puts(0, line++, buf);
1121 snprintf(buf, sizeof(buf), "GPIO1_FUNC: %08x", gpio1_function);
1122 lcd_puts(0, line++, buf);
1123 snprintf(buf, sizeof(buf), "GPIO1_ENA: %08x", gpio1_enable);
1124 lcd_puts(0, line++, buf);
1126 adc_buttons = adc_read(ADC_BUTTONS);
1127 adc_remote = adc_read(ADC_REMOTE);
1128 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1129 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1130 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1131 button_scan_enabled() ? '+' : '-', adc_buttons);
1132 #else
1133 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1134 #endif
1135 lcd_puts(0, line++, buf);
1136 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1137 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1138 remote_detect() ? '+' : '-', adc_remote);
1139 #else
1140 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1141 #endif
1142 lcd_puts(0, line++, buf);
1143 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1144 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1145 adc_read(ADC_REMOTEDETECT));
1146 lcd_puts(0, line++, buf);
1147 #endif
1149 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1150 adc_battery_voltage % 1000, adc_battery_level);
1151 lcd_puts(0, line++, buf);
1153 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1154 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1155 lcd_puts(0, line++, buf);
1156 #endif
1158 lcd_update();
1159 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1161 viewportmanager_set_statusbar(true);
1162 return false;
1166 #elif defined(CPU_PP502x)
1168 char buf[128];
1169 int line;
1171 lcd_clear_display();
1172 lcd_setfont(FONT_SYSFIXED);
1173 viewportmanager_set_statusbar(false);
1175 while(1)
1177 line = 0;
1178 lcd_puts(0, line++, "GPIO STATES:");
1179 snprintf(buf, sizeof(buf), "A: %02x E: %02x I: %02x",
1180 (unsigned int)GPIOA_INPUT_VAL,
1181 (unsigned int)GPIOE_INPUT_VAL,
1182 (unsigned int)GPIOI_INPUT_VAL);
1183 lcd_puts(0, line++, buf);
1184 snprintf(buf, sizeof(buf), "B: %02x F: %02x J: %02x",
1185 (unsigned int)GPIOB_INPUT_VAL,
1186 (unsigned int)GPIOF_INPUT_VAL,
1187 (unsigned int)GPIOJ_INPUT_VAL);
1188 lcd_puts(0, line++, buf);
1189 snprintf(buf, sizeof(buf), "C: %02x G: %02x K: %02x",
1190 (unsigned int)GPIOC_INPUT_VAL,
1191 (unsigned int)GPIOG_INPUT_VAL,
1192 (unsigned int)GPIOK_INPUT_VAL);
1193 lcd_puts(0, line++, buf);
1194 snprintf(buf, sizeof(buf), "D: %02x H: %02x L: %02x",
1195 (unsigned int)GPIOD_INPUT_VAL,
1196 (unsigned int)GPIOH_INPUT_VAL,
1197 (unsigned int)GPIOL_INPUT_VAL);
1198 lcd_puts(0, line++, buf);
1199 line++;
1200 snprintf(buf, sizeof(buf), "GPO32_VAL: %08lx", GPO32_VAL);
1201 lcd_puts(0, line++, buf);
1202 snprintf(buf, sizeof(buf), "GPO32_EN: %08lx", GPO32_ENABLE);
1203 lcd_puts(0, line++, buf);
1204 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1205 lcd_puts(0, line++, buf);
1206 snprintf(buf, sizeof(buf), "DEV_EN2: %08lx", DEV_EN2);
1207 lcd_puts(0, line++, buf);
1208 snprintf(buf, sizeof(buf), "DEV_EN3: %08lx", inl(0x60006044));
1209 lcd_puts(0, line++, buf); /* to be verified */
1210 snprintf(buf, sizeof(buf), "DEV_INIT1: %08lx", DEV_INIT1);
1211 lcd_puts(0, line++, buf);
1212 snprintf(buf, sizeof(buf), "DEV_INIT2: %08lx", DEV_INIT2);
1213 lcd_puts(0, line++, buf);
1214 #ifdef ADC_ACCESSORY
1215 snprintf(buf, sizeof(buf), "ACCESSORY: %d", adc_read(ADC_ACCESSORY));
1216 lcd_puts(0, line++, buf);
1217 #endif
1219 #if defined(IPOD_ACCESSORY_PROTOCOL)
1220 extern unsigned char serbuf[];
1221 snprintf(buf, sizeof(buf), "IAP PACKET: %02x %02x %02x %02x %02x %02x %02x %02x",
1222 serbuf[0], serbuf[1], serbuf[2], serbuf[3], serbuf[4], serbuf[5],
1223 serbuf[6], serbuf[7]);
1224 lcd_puts(0, line++, buf);
1225 #endif
1227 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1228 line++;
1229 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1230 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1231 lcd_puts(0, line++, buf);
1232 snprintf(buf, sizeof(buf), "REM: %03x PAD: %03x",
1233 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1234 lcd_puts(0, line++, buf);
1235 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1236 snprintf(buf, sizeof(buf), "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1237 lcd_puts(0, line++, buf);
1238 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1239 lcd_puts(0, line++, buf);
1240 snprintf(buf, sizeof(buf), "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1241 lcd_puts(0, line++, buf);
1242 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1243 lcd_puts(0, line++, buf);
1244 snprintf(buf, sizeof(buf), "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1245 lcd_puts(0, line++, buf);
1246 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1247 lcd_puts(0, line++, buf);
1248 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1249 lcd_puts(0, line++, buf);
1250 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1251 lcd_puts(0, line++, buf);
1252 snprintf(buf, sizeof(buf), "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1253 lcd_puts(0, line++, buf);
1254 snprintf(buf, sizeof(buf), "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1255 lcd_puts(0, line++, buf);
1256 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1257 lcd_puts(0, line++, buf);
1258 #if !defined(PHILIPS_SA9200)
1259 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1260 lcd_puts(0, line++, buf);
1261 snprintf(buf, sizeof(buf), "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1262 lcd_puts(0, line++, buf);
1263 snprintf(buf, sizeof(buf), "CHARGER: %02X/%02X",
1264 ascodec_read(AS3514_CHARGER),
1265 ascodec_read(AS3514_IRQ_ENRD0));
1266 lcd_puts(0, line++, buf);
1267 #endif
1268 #endif
1269 lcd_update();
1270 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1272 viewportmanager_set_statusbar(true);
1273 return false;
1277 #elif CONFIG_CPU == PP5002
1278 char buf[128];
1279 int line;
1281 lcd_clear_display();
1282 lcd_setfont(FONT_SYSFIXED);
1283 viewportmanager_set_statusbar(false);
1285 while(1)
1287 line = 0;
1288 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x",
1289 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1290 lcd_puts(0, line++, buf);
1291 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x",
1292 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1293 lcd_puts(0, line++, buf);
1295 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1296 lcd_puts(0, line++, buf);
1297 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1298 lcd_puts(0, line++, buf);
1299 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1300 lcd_puts(0, line++, buf);
1301 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1302 lcd_puts(0, line++, buf);
1303 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1304 lcd_puts(0, line++, buf);
1305 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1306 lcd_puts(0, line++, buf);
1307 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1308 lcd_puts(0, line++, buf);
1309 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1310 lcd_puts(0, line++, buf);
1312 lcd_update();
1313 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1315 viewportmanager_set_statusbar(true);
1316 return false;
1319 viewportmanager_set_statusbar(true);
1320 #else
1321 return __dbg_ports();
1322 #endif /* CPU */
1323 return false;
1325 #else /* !HAVE_LCD_BITMAP */
1326 bool dbg_ports(void)
1328 char buf[32];
1329 int button;
1330 int adc_battery_voltage;
1331 int currval = 0;
1333 lcd_clear_display();
1334 viewportmanager_set_statusbar(false);
1336 while(1)
1338 switch(currval)
1340 case 0:
1341 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1342 break;
1343 case 1:
1344 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1345 break;
1346 case 2:
1347 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1348 break;
1349 case 3:
1350 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1351 break;
1352 case 4:
1353 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1354 break;
1355 case 5:
1356 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1357 break;
1358 case 6:
1359 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1360 break;
1361 case 7:
1362 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1363 break;
1364 case 8:
1365 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1366 break;
1367 case 9:
1368 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1369 break;
1371 lcd_puts(0, 0, buf);
1373 battery_read_info(&adc_battery_voltage, NULL);
1374 snprintf(buf, 32, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1375 adc_battery_voltage % 1000);
1376 lcd_puts(0, 1, buf);
1377 lcd_update();
1379 button = get_action(CONTEXT_SETTINGS,HZ/5);
1381 switch(button)
1383 case ACTION_STD_CANCEL:
1384 return false;
1386 case ACTION_SETTINGS_DEC:
1387 currval--;
1388 if(currval < 0)
1389 currval = 9;
1390 break;
1392 case ACTION_SETTINGS_INC:
1393 currval++;
1394 if(currval > 9)
1395 currval = 0;
1396 break;
1399 viewportmanager_set_statusbar(true);
1400 return false;
1402 #endif /* !HAVE_LCD_BITMAP */
1403 #endif /* !SIMULATOR */
1405 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1406 static bool dbg_pcf(void)
1408 char buf[128];
1409 int line;
1411 #ifdef HAVE_LCD_BITMAP
1412 lcd_setfont(FONT_SYSFIXED);
1413 #endif
1414 lcd_clear_display();
1415 viewportmanager_set_statusbar(false);
1417 while(1)
1419 line = 0;
1421 snprintf(buf, sizeof(buf), "DCDC1: %02x", pcf50605_read(0x1b));
1422 lcd_puts(0, line++, buf);
1423 snprintf(buf, sizeof(buf), "DCDC2: %02x", pcf50605_read(0x1c));
1424 lcd_puts(0, line++, buf);
1425 snprintf(buf, sizeof(buf), "DCDC3: %02x", pcf50605_read(0x1d));
1426 lcd_puts(0, line++, buf);
1427 snprintf(buf, sizeof(buf), "DCDC4: %02x", pcf50605_read(0x1e));
1428 lcd_puts(0, line++, buf);
1429 snprintf(buf, sizeof(buf), "DCDEC1: %02x", pcf50605_read(0x1f));
1430 lcd_puts(0, line++, buf);
1431 snprintf(buf, sizeof(buf), "DCDEC2: %02x", pcf50605_read(0x20));
1432 lcd_puts(0, line++, buf);
1433 snprintf(buf, sizeof(buf), "DCUDC1: %02x", pcf50605_read(0x21));
1434 lcd_puts(0, line++, buf);
1435 snprintf(buf, sizeof(buf), "DCUDC2: %02x", pcf50605_read(0x22));
1436 lcd_puts(0, line++, buf);
1437 snprintf(buf, sizeof(buf), "IOREGC: %02x", pcf50605_read(0x23));
1438 lcd_puts(0, line++, buf);
1439 snprintf(buf, sizeof(buf), "D1REGC: %02x", pcf50605_read(0x24));
1440 lcd_puts(0, line++, buf);
1441 snprintf(buf, sizeof(buf), "D2REGC: %02x", pcf50605_read(0x25));
1442 lcd_puts(0, line++, buf);
1443 snprintf(buf, sizeof(buf), "D3REGC: %02x", pcf50605_read(0x26));
1444 lcd_puts(0, line++, buf);
1445 snprintf(buf, sizeof(buf), "LPREG1: %02x", pcf50605_read(0x27));
1446 lcd_puts(0, line++, buf);
1448 lcd_update();
1449 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1451 viewportmanager_set_statusbar(true);
1452 return false;
1456 viewportmanager_set_statusbar(true);
1457 return false;
1459 #endif
1461 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1462 static bool dbg_cpufreq(void)
1464 char buf[128];
1465 int line;
1466 int button;
1468 #ifdef HAVE_LCD_BITMAP
1469 lcd_setfont(FONT_SYSFIXED);
1470 #endif
1471 lcd_clear_display();
1472 viewportmanager_set_statusbar(false);
1474 while(1)
1476 line = 0;
1478 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1479 lcd_puts(0, line++, buf);
1481 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1482 lcd_puts(0, line++, buf);
1484 lcd_update();
1485 button = get_action(CONTEXT_STD,HZ/10);
1487 switch(button)
1489 case ACTION_STD_PREV:
1490 cpu_boost(true);
1491 break;
1493 case ACTION_STD_NEXT:
1494 cpu_boost(false);
1495 break;
1497 case ACTION_STD_OK:
1498 while (get_cpu_boost_counter() > 0)
1499 cpu_boost(false);
1500 set_cpu_frequency(CPUFREQ_DEFAULT);
1501 break;
1503 case ACTION_STD_CANCEL:
1504 viewportmanager_set_statusbar(true);
1505 return false;
1508 viewportmanager_set_statusbar(true);
1509 return false;
1511 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1513 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1514 #include "tsc2100.h"
1515 static char *itob(int n, int len)
1517 static char binary[64];
1518 int i,j;
1519 for (i=1, j=0;i<=len;i++)
1521 binary[j++] = n&(1<<(len-i))?'1':'0';
1522 if (i%4 == 0)
1523 binary[j++] = ' ';
1525 binary[j] = '\0';
1526 return binary;
1528 static char* tsc2100_debug_getname(int selected_item, void * data,
1529 char *buffer, size_t buffer_len)
1531 int *page = (int*)data;
1532 bool reserved = false;
1533 switch (*page)
1535 case 0:
1536 if ((selected_item > 0x0a) ||
1537 (selected_item == 0x04) ||
1538 (selected_item == 0x08))
1539 reserved = true;
1540 break;
1541 case 1:
1542 if ((selected_item > 0x05) ||
1543 (selected_item == 0x02))
1544 reserved = true;
1545 break;
1546 case 2:
1547 if (selected_item > 0x1e)
1548 reserved = true;
1549 break;
1551 if (reserved)
1552 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1553 else
1554 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1555 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1556 return buffer;
1558 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1560 int *page = (int*)lists->data;
1561 if (action == ACTION_STD_OK)
1563 *page = (*page+1)%3;
1564 snprintf(lists->title, 32,
1565 "tsc2100 registers - Page %d", *page);
1566 return ACTION_REDRAW;
1568 return action;
1570 static bool tsc2100_debug(void)
1572 int page = 0;
1573 char title[32] = "tsc2100 registers - Page 0";
1574 struct simplelist_info info;
1575 simplelist_info_init(&info, title, 32, &page);
1576 info.timeout = HZ/100;
1577 info.get_name = tsc2100_debug_getname;
1578 info.action_callback= tsc2100debug_action_callback;
1579 return simplelist_show_list(&info);
1581 #endif
1582 #ifndef SIMULATOR
1583 #ifdef HAVE_LCD_BITMAP
1585 * view_battery() shows a automatically scaled graph of the battery voltage
1586 * over time. Usable for estimating battery life / charging rate.
1587 * The power_history array is updated in power_thread of powermgmt.c.
1590 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1591 #define BAT_YSPACE (LCD_HEIGHT - 20)
1593 static bool view_battery(void)
1595 int view = 0;
1596 int i, x, y;
1597 unsigned short maxv, minv;
1598 char buf[32];
1600 lcd_setfont(FONT_SYSFIXED);
1601 viewportmanager_set_statusbar(false);
1603 while(1)
1605 lcd_clear_display();
1606 switch (view) {
1607 case 0: /* voltage history graph */
1608 /* Find maximum and minimum voltage for scaling */
1609 minv = power_history[0];
1610 maxv = minv + 1;
1611 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1612 if (power_history[i] > maxv)
1613 maxv = power_history[i];
1614 if (power_history[i] < minv)
1615 minv = power_history[i];
1618 snprintf(buf, 30, "Battery %d.%03d", power_history[0] / 1000,
1619 power_history[0] % 1000);
1620 lcd_puts(0, 0, buf);
1621 snprintf(buf, 30, "scale %d.%03d-%d.%03dV",
1622 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1623 lcd_puts(0, 1, buf);
1625 x = 0;
1626 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1627 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1628 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1629 lcd_vline(x, LCD_HEIGHT-1, 20);
1630 lcd_set_drawmode(DRMODE_SOLID);
1631 lcd_vline(x, LCD_HEIGHT-1,
1632 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1633 x++;
1636 break;
1638 case 1: /* status: */
1639 lcd_puts(0, 0, "Power status:");
1641 battery_read_info(&y, NULL);
1642 snprintf(buf, 30, "Battery: %d.%03d V", y / 1000, y % 1000);
1643 lcd_puts(0, 1, buf);
1644 #ifdef ADC_EXT_POWER
1645 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1646 snprintf(buf, 30, "External: %d.%03d V", y / 1000, y % 1000);
1647 lcd_puts(0, 2, buf);
1648 #endif
1649 #if CONFIG_CHARGING
1650 #if defined ARCHOS_RECORDER
1651 snprintf(buf, 30, "Chgr: %s %s",
1652 charger_inserted() ? "present" : "absent",
1653 charger_enabled() ? "on" : "off");
1654 lcd_puts(0, 3, buf);
1655 snprintf(buf, 30, "short delta: %d", short_delta);
1656 lcd_puts(0, 5, buf);
1657 snprintf(buf, 30, "long delta: %d", long_delta);
1658 lcd_puts(0, 6, buf);
1659 lcd_puts(0, 7, power_message);
1660 snprintf(buf, 30, "USB Inserted: %s",
1661 usb_inserted() ? "yes" : "no");
1662 lcd_puts(0, 8, buf);
1663 #elif defined IRIVER_H300_SERIES
1664 snprintf(buf, 30, "USB Charging Enabled: %s",
1665 usb_charging_enabled() ? "yes" : "no");
1666 lcd_puts(0, 9, buf);
1667 #elif defined IPOD_NANO || defined IPOD_VIDEO
1668 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1669 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1670 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1671 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1672 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1674 snprintf(buf, 30, "USB pwr: %s",
1675 usb_pwr ? "present" : "absent");
1676 lcd_puts(0, 3, buf);
1677 snprintf(buf, 30, "EXT pwr: %s",
1678 ext_pwr ? "present" : "absent");
1679 lcd_puts(0, 4, buf);
1680 snprintf(buf, 30, "Battery: %s",
1681 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1682 lcd_puts(0, 5, buf);
1683 snprintf(buf, 30, "Dock mode: %s",
1684 dock ? "enabled" : "disabled");
1685 lcd_puts(0, 6, buf);
1686 snprintf(buf, 30, "Headphone: %s",
1687 headphone ? "connected" : "disconnected");
1688 lcd_puts(0, 7, buf);
1689 #elif defined TOSHIBA_GIGABEAT_S
1690 int line = 3;
1691 unsigned int st;
1693 static const unsigned char * const chrgstate_strings[] =
1695 "Disabled",
1696 "Error",
1697 "Discharging",
1698 "Precharge",
1699 "Constant Voltage",
1700 "Constant Current",
1701 "<unknown>",
1704 snprintf(buf, 30, "Charger: %s",
1705 charger_inserted() ? "present" : "absent");
1706 lcd_puts(0, line++, buf);
1708 st = power_input_status() &
1709 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1710 snprintf(buf, 30, "%s%s",
1711 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1712 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1713 lcd_puts(0, line++, buf);
1715 snprintf(buf, 30, "IUSB Max: %d", usb_allowed_current());
1716 lcd_puts(0, line++, buf);
1718 y = ARRAYLEN(chrgstate_strings) - 1;
1720 switch (charge_state)
1722 case CHARGE_STATE_DISABLED: y--;
1723 case CHARGE_STATE_ERROR: y--;
1724 case DISCHARGING: y--;
1725 case TRICKLE: y--;
1726 case TOPOFF: y--;
1727 case CHARGING: y--;
1728 default:;
1731 snprintf(buf, 30, "State: %s", chrgstate_strings[y]);
1732 lcd_puts(0, line++, buf);
1734 snprintf(buf, 30, "Battery Switch: %s",
1735 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1736 lcd_puts(0, line++, buf);
1738 y = chrgraw_adc_voltage();
1739 snprintf(buf, 30, "CHRGRAW: %d.%03d V",
1740 y / 1000, y % 1000);
1741 lcd_puts(0, line++, buf);
1743 y = application_supply_adc_voltage();
1744 snprintf(buf, 30, "BP : %d.%03d V",
1745 y / 1000, y % 1000);
1746 lcd_puts(0, line++, buf);
1748 y = battery_adc_charge_current();
1749 if (y < 0) x = '-', y = -y;
1750 else x = ' ';
1751 snprintf(buf, 30, "CHRGISN:%c%d mA", x, y);
1752 lcd_puts(0, line++, buf);
1754 y = cccv_regulator_dissipation();
1755 snprintf(buf, 30, "P CCCV : %d mW", y);
1756 lcd_puts(0, line++, buf);
1758 y = battery_charge_current();
1759 if (y < 0) x = '-', y = -y;
1760 else x = ' ';
1761 snprintf(buf, 30, "I Charge:%c%d mA", x, y);
1762 lcd_puts(0, line++, buf);
1764 y = battery_adc_temp();
1766 if (y != INT_MIN) {
1767 snprintf(buf, 30, "T Battery: %dC (%dF)", y,
1768 (9*y + 160) / 5);
1769 } else {
1770 /* Conversion disabled */
1771 snprintf(buf, 30, "T Battery: ?");
1774 lcd_puts(0, line++, buf);
1775 #else
1776 snprintf(buf, 30, "Charger: %s",
1777 charger_inserted() ? "present" : "absent");
1778 lcd_puts(0, 3, buf);
1779 #endif /* target type */
1780 #endif /* CONFIG_CHARGING */
1781 break;
1783 case 2: /* voltage deltas: */
1784 lcd_puts(0, 0, "Voltage deltas:");
1786 for (i = 0; i <= 6; i++) {
1787 y = power_history[i] - power_history[i+1];
1788 snprintf(buf, 30, "-%d min: %s%d.%03d V", i,
1789 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1790 ((y < 0) ? y * -1 : y ) % 1000);
1791 lcd_puts(0, i+1, buf);
1793 break;
1795 case 3: /* remaining time estimation: */
1797 #ifdef ARCHOS_RECORDER
1798 snprintf(buf, 30, "charge_state: %d", charge_state);
1799 lcd_puts(0, 0, buf);
1801 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1802 lcd_puts(0, 1, buf);
1804 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1805 lcd_puts(0, 2, buf);
1807 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1808 lcd_puts(0, 3, buf);
1810 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1811 lcd_puts(0, 4, buf);
1812 #endif /* ARCHOS_RECORDER */
1814 snprintf(buf, 30, "Last PwrHist: %d.%03dV",
1815 power_history[0] / 1000,
1816 power_history[0] % 1000);
1817 lcd_puts(0, 5, buf);
1819 snprintf(buf, 30, "battery level: %d%%", battery_level());
1820 lcd_puts(0, 6, buf);
1822 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1823 lcd_puts(0, 7, buf);
1824 break;
1827 lcd_update();
1829 switch(get_action(CONTEXT_STD,HZ/2))
1831 case ACTION_STD_PREV:
1832 if (view)
1833 view--;
1834 break;
1836 case ACTION_STD_NEXT:
1837 if (view < 3)
1838 view++;
1839 break;
1841 case ACTION_STD_CANCEL:
1842 viewportmanager_set_statusbar(true);
1843 return false;
1846 viewportmanager_set_statusbar(true);
1847 return false;
1850 #endif /* HAVE_LCD_BITMAP */
1851 #endif
1853 #ifndef SIMULATOR
1854 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1856 #if (CONFIG_STORAGE & STORAGE_MMC)
1857 #define CARDTYPE "MMC"
1858 #elif (CONFIG_STORAGE & STORAGE_SD)
1859 #define CARDTYPE "microSD"
1860 #endif
1862 static int disk_callback(int btn, struct gui_synclist *lists)
1864 tCardInfo *card;
1865 int *cardnum = (int*)lists->data;
1866 unsigned char card_name[7];
1867 unsigned char pbuf[32];
1868 char *title = lists->title;
1869 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1870 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1871 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1872 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1873 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1874 "3.1-3.31", "4.0" };
1875 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1877 #ifdef HAVE_HOTSWAP
1878 if (btn == ACTION_STD_OK)
1880 *cardnum ^= 0x1; /* change cards */
1882 #endif
1884 simplelist_set_line_count(0);
1886 card = card_get_info(*cardnum);
1888 if (card->initialized > 0)
1890 card_name[6] = '\0';
1891 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1892 simplelist_addline(SIMPLELIST_ADD_LINE,
1893 "%s Rev %d.%d", card_name,
1894 (int) card_extract_bits(card->cid, 72, 4),
1895 (int) card_extract_bits(card->cid, 76, 4));
1896 simplelist_addline(SIMPLELIST_ADD_LINE,
1897 "Prod: %d/%d",
1898 (int) card_extract_bits(card->cid, 112, 4),
1899 (int) card_extract_bits(card->cid, 116, 4) + 1997);
1900 simplelist_addline(SIMPLELIST_ADD_LINE,
1901 "Ser#: 0x%08lx",
1902 card_extract_bits(card->cid, 80, 32));
1903 simplelist_addline(SIMPLELIST_ADD_LINE,
1904 "M=%02x, O=%04x",
1905 (int) card_extract_bits(card->cid, 0, 8),
1906 (int) card_extract_bits(card->cid, 8, 16));
1907 int temp = card_extract_bits(card->csd, 2, 4);
1908 simplelist_addline(SIMPLELIST_ADD_LINE,
1909 CARDTYPE " v%s", temp < 5 ?
1910 spec_vers[temp] : "?.?");
1911 simplelist_addline(SIMPLELIST_ADD_LINE,
1912 "Blocks: 0x%08lx", card->numblocks);
1913 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1914 kbit_units, false);
1915 simplelist_addline(SIMPLELIST_ADD_LINE,
1916 "Speed: %s", pbuf);
1917 output_dyn_value(pbuf, sizeof pbuf, card->tsac,
1918 nsec_units, false);
1919 simplelist_addline(SIMPLELIST_ADD_LINE,
1920 "Tsac: %s", pbuf);
1921 simplelist_addline(SIMPLELIST_ADD_LINE,
1922 "Nsac: %d clk", card->nsac);
1923 simplelist_addline(SIMPLELIST_ADD_LINE,
1924 "R2W: *%d", card->r2w_factor);
1925 simplelist_addline(SIMPLELIST_ADD_LINE,
1926 "IRmax: %d..%d mA",
1927 i_vmin[card_extract_bits(card->csd, 66, 3)],
1928 i_vmax[card_extract_bits(card->csd, 69, 3)]);
1929 simplelist_addline(SIMPLELIST_ADD_LINE,
1930 "IWmax: %d..%d mA",
1931 i_vmin[card_extract_bits(card->csd, 72, 3)],
1932 i_vmax[card_extract_bits(card->csd, 75, 3)]);
1934 else if (card->initialized == 0)
1936 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1938 #if (CONFIG_STORAGE & STORAGE_SD)
1939 else /* card->initialized < 0 */
1941 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1943 #endif
1944 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1945 gui_synclist_set_title(lists, title, Icon_NOICON);
1946 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1947 gui_synclist_select_item(lists, 0);
1948 btn = ACTION_REDRAW;
1950 return btn;
1952 #elif (CONFIG_STORAGE & STORAGE_ATA)
1953 static int disk_callback(int btn, struct gui_synclist *lists)
1955 (void)lists;
1956 int i;
1957 char buf[128];
1958 unsigned short* identify_info = ata_get_identify();
1959 bool timing_info_present = false;
1960 (void)btn;
1962 simplelist_set_line_count(0);
1964 for (i=0; i < 20; i++)
1965 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1966 buf[40]=0;
1967 /* kill trailing space */
1968 for (i=39; i && buf[i]==' '; i--)
1969 buf[i] = 0;
1970 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1971 for (i=0; i < 4; i++)
1972 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1973 buf[8]=0;
1974 simplelist_addline(SIMPLELIST_ADD_LINE,
1975 "Firmware: %s", buf);
1976 snprintf(buf, sizeof buf, "%ld MB",
1977 ((unsigned long)identify_info[61] << 16 |
1978 (unsigned long)identify_info[60]) / 2048 );
1979 simplelist_addline(SIMPLELIST_ADD_LINE,
1980 "Size: %s", buf);
1981 unsigned long free;
1982 fat_size( IF_MV2(0,) NULL, &free );
1983 simplelist_addline(SIMPLELIST_ADD_LINE,
1984 "Free: %ld MB", free / 1024);
1985 simplelist_addline(SIMPLELIST_ADD_LINE,
1986 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
1987 i = identify_info[83] & (1<<3);
1988 simplelist_addline(SIMPLELIST_ADD_LINE,
1989 "Power mgmt: %s", i ? "enabled" : "unsupported");
1990 i = identify_info[83] & (1<<9);
1991 simplelist_addline(SIMPLELIST_ADD_LINE,
1992 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1993 i = identify_info[82] & (1<<6);
1994 simplelist_addline(SIMPLELIST_ADD_LINE,
1995 "Read-ahead: %s", i ? "enabled" : "unsupported");
1996 timing_info_present = identify_info[53] & (1<<1);
1997 if(timing_info_present) {
1998 char pio3[2], pio4[2];pio3[1] = 0;
1999 pio4[1] = 0;
2000 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
2001 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
2002 simplelist_addline(SIMPLELIST_ADD_LINE,
2003 "PIO modes: 0 1 2 %s %s", pio3, pio4);
2005 else {
2006 simplelist_addline(SIMPLELIST_ADD_LINE,
2007 "No PIO mode info");
2009 timing_info_present = identify_info[53] & (1<<1);
2010 if(timing_info_present) {
2011 simplelist_addline(SIMPLELIST_ADD_LINE,
2012 "Cycle times %dns/%dns",
2013 identify_info[67],
2014 identify_info[68] );
2015 } else {
2016 simplelist_addline(SIMPLELIST_ADD_LINE,
2017 "No timing info");
2019 #if defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S)
2020 if (identify_info[63] & (1<<0)) {
2021 char mdma0[2], mdma1[2], mdma2[2];
2022 mdma0[1] = mdma1[1] = mdma2[1] = 0;
2023 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
2024 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
2025 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
2026 simplelist_addline(SIMPLELIST_ADD_LINE,
2027 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
2028 simplelist_addline(SIMPLELIST_ADD_LINE,
2029 "MDMA Cycle times %dns/%dns",
2030 identify_info[65],
2031 identify_info[66] );
2033 else {
2034 simplelist_addline(SIMPLELIST_ADD_LINE,
2035 "No MDMA mode info");
2037 if (identify_info[88] & (1<<0)) {
2038 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2];
2039 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = 0;
2040 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
2041 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
2042 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
2043 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
2044 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
2045 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
2046 simplelist_addline(SIMPLELIST_ADD_LINE,
2047 "UDMA modes: %s %s %s %s %s %s", udma0, udma1, udma2,
2048 udma3, udma4, udma5);
2050 else {
2051 simplelist_addline(SIMPLELIST_ADD_LINE,
2052 "No UDMA mode info");
2054 #endif /* defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S) */
2055 timing_info_present = identify_info[53] & (1<<1);
2056 if(timing_info_present) {
2057 i = identify_info[49] & (1<<11);
2058 simplelist_addline(SIMPLELIST_ADD_LINE,
2059 "IORDY support: %s", i ? "yes" : "no");
2060 i = identify_info[49] & (1<<10);
2061 simplelist_addline(SIMPLELIST_ADD_LINE,
2062 "IORDY disable: %s", i ? "yes" : "no");
2063 } else {
2064 simplelist_addline(SIMPLELIST_ADD_LINE,
2065 "No timing info");
2067 simplelist_addline(SIMPLELIST_ADD_LINE,
2068 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2069 return btn;
2071 #else /* No SD, MMC or ATA */
2072 static int disk_callback(int btn, struct gui_synclist *lists)
2074 (void)btn;
2075 (void)lists;
2076 struct storage_info info;
2077 storage_get_info(0,&info);
2078 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
2079 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
2080 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
2081 simplelist_addline(SIMPLELIST_ADD_LINE,
2082 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
2083 unsigned long free;
2084 fat_size( IF_MV2(0,) NULL, &free );
2085 simplelist_addline(SIMPLELIST_ADD_LINE,
2086 "Free: %ld MB", free / 1024);
2087 simplelist_addline(SIMPLELIST_ADD_LINE,
2088 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2089 return btn;
2091 #endif
2093 #if (CONFIG_STORAGE & STORAGE_ATA)
2094 static bool dbg_identify_info(void)
2096 int fd = creat("/identify_info.bin");
2097 if(fd >= 0)
2099 #ifdef ROCKBOX_LITTLE_ENDIAN
2100 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
2101 #else
2102 write(fd, ata_get_identify(), SECTOR_SIZE);
2103 #endif
2104 close(fd);
2106 return false;
2108 #endif
2110 static bool dbg_disk_info(void)
2112 struct simplelist_info info;
2113 simplelist_info_init(&info, "Disk Info", 1, NULL);
2114 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
2115 char title[16];
2116 int card = 0;
2117 info.callback_data = (void*)&card;
2118 info.title = title;
2119 #endif
2120 info.action_callback = disk_callback;
2121 info.hide_selection = true;
2122 info.scroll_all = true;
2123 return simplelist_show_list(&info);
2125 #endif /* !SIMULATOR */
2127 #ifdef HAVE_DIRCACHE
2128 static int dircache_callback(int btn, struct gui_synclist *lists)
2130 (void)btn; (void)lists;
2131 simplelist_set_line_count(0);
2132 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
2133 dircache_is_enabled() ? "Yes" : "No");
2134 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
2135 dircache_get_cache_size());
2136 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
2137 global_status.dircache_size);
2138 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
2139 DIRCACHE_LIMIT);
2140 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
2141 dircache_get_reserve_used(), DIRCACHE_RESERVE);
2142 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2143 dircache_get_build_ticks() / HZ);
2144 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2145 dircache_get_entry_count());
2146 return btn;
2149 static bool dbg_dircache_info(void)
2151 struct simplelist_info info;
2152 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2153 info.action_callback = dircache_callback;
2154 info.hide_selection = true;
2155 info.scroll_all = true;
2156 return simplelist_show_list(&info);
2159 #endif /* HAVE_DIRCACHE */
2161 #ifdef HAVE_TAGCACHE
2162 static int database_callback(int btn, struct gui_synclist *lists)
2164 (void)lists;
2165 struct tagcache_stat *stat = tagcache_get_stat();
2166 static bool synced = false;
2168 simplelist_set_line_count(0);
2170 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2171 stat->initialized ? "Yes" : "No");
2172 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2173 stat->ready ? "Yes" : "No");
2174 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2175 stat->ramcache ? "Yes" : "No");
2176 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2177 stat->ramcache_used, stat->ramcache_allocated);
2178 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2179 stat->progress, stat->processed_entries);
2180 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2181 stat->curentry ? stat->curentry : "---");
2182 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2183 stat->commit_step);
2184 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2185 stat->commit_delayed ? "Yes" : "No");
2187 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2188 stat->queue_length);
2190 if (synced)
2192 synced = false;
2193 tagcache_screensync_event();
2196 if (!btn && stat->curentry)
2198 synced = true;
2199 return ACTION_REDRAW;
2202 if (btn == ACTION_STD_CANCEL)
2203 tagcache_screensync_enable(false);
2205 return btn;
2207 static bool dbg_tagcache_info(void)
2209 struct simplelist_info info;
2210 simplelist_info_init(&info, "Database Info", 8, NULL);
2211 info.action_callback = database_callback;
2212 info.hide_selection = true;
2213 info.scroll_all = true;
2215 /* Don't do nonblock here, must give enough processing time
2216 for tagcache thread. */
2217 /* info.timeout = TIMEOUT_NOBLOCK; */
2218 info.timeout = 1;
2219 tagcache_screensync_enable(true);
2220 return simplelist_show_list(&info);
2222 #endif
2224 #if CONFIG_CPU == SH7034
2225 static bool dbg_save_roms(void)
2227 int fd;
2228 int oldmode = system_memory_guard(MEMGUARD_NONE);
2230 fd = creat("/internal_rom_0000-FFFF.bin");
2231 if(fd >= 0)
2233 write(fd, (void *)0, 0x10000);
2234 close(fd);
2237 fd = creat("/internal_rom_2000000-203FFFF.bin");
2238 if(fd >= 0)
2240 write(fd, (void *)0x2000000, 0x40000);
2241 close(fd);
2244 system_memory_guard(oldmode);
2245 return false;
2247 #elif defined CPU_COLDFIRE
2248 static bool dbg_save_roms(void)
2250 int fd;
2251 int oldmode = system_memory_guard(MEMGUARD_NONE);
2253 #if defined(IRIVER_H100_SERIES)
2254 fd = creat("/internal_rom_000000-1FFFFF.bin");
2255 #elif defined(IRIVER_H300_SERIES)
2256 fd = creat("/internal_rom_000000-3FFFFF.bin");
2257 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2258 fd = creat("/internal_rom_000000-3FFFFF.bin");
2259 #endif
2260 if(fd >= 0)
2262 write(fd, (void *)0, FLASH_SIZE);
2263 close(fd);
2265 system_memory_guard(oldmode);
2267 #ifdef HAVE_EEPROM
2268 fd = creat("/internal_eeprom.bin");
2269 if (fd >= 0)
2271 int old_irq_level;
2272 char buf[EEPROM_SIZE];
2273 int err;
2275 old_irq_level = disable_irq_save();
2277 err = eeprom_24cxx_read(0, buf, sizeof buf);
2279 restore_irq(old_irq_level);
2281 if (err)
2282 splashf(HZ*3, "Eeprom read failure (%d)", err);
2283 else
2285 write(fd, buf, sizeof buf);
2288 close(fd);
2290 #endif
2292 return false;
2294 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
2295 static bool dbg_save_roms(void)
2297 int fd;
2299 fd = creat("/internal_rom_000000-0FFFFF.bin");
2300 if(fd >= 0)
2302 write(fd, (void *)0x20000000, FLASH_SIZE);
2303 close(fd);
2306 return false;
2308 #endif /* CPU */
2310 #ifndef SIMULATOR
2311 #if CONFIG_TUNER
2312 static int radio_callback(int btn, struct gui_synclist *lists)
2314 (void)lists;
2315 if (btn == ACTION_STD_CANCEL)
2316 return btn;
2317 simplelist_set_line_count(1);
2319 #if (CONFIG_TUNER & LV24020LP)
2320 simplelist_addline(SIMPLELIST_ADD_LINE,
2321 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2322 simplelist_addline(SIMPLELIST_ADD_LINE,
2323 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2324 simplelist_addline(SIMPLELIST_ADD_LINE,
2325 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2326 simplelist_addline(SIMPLELIST_ADD_LINE,
2327 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2328 simplelist_addline(SIMPLELIST_ADD_LINE,
2329 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2330 simplelist_addline(SIMPLELIST_ADD_LINE,
2331 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2332 simplelist_addline(SIMPLELIST_ADD_LINE,
2333 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2334 #endif /* LV24020LP */
2335 #if (CONFIG_TUNER & S1A0903X01)
2336 simplelist_addline(SIMPLELIST_ADD_LINE,
2337 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2338 /* This one doesn't return dynamic data atm */
2339 #endif /* S1A0903X01 */
2340 #if (CONFIG_TUNER & TEA5767)
2341 struct tea5767_dbg_info nfo;
2342 tea5767_dbg_info(&nfo);
2343 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2344 simplelist_addline(SIMPLELIST_ADD_LINE,
2345 " Read: %02X %02X %02X %02X %02X",
2346 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2347 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2348 (unsigned)nfo.read_regs[4]);
2349 simplelist_addline(SIMPLELIST_ADD_LINE,
2350 " Write: %02X %02X %02X %02X %02X",
2351 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2352 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2353 (unsigned)nfo.write_regs[4]);
2354 #endif /* TEA5767 */
2355 #if (CONFIG_TUNER & SI4700)
2356 struct si4700_dbg_info nfo;
2357 si4700_dbg_info(&nfo);
2358 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
2359 /* Registers */
2360 simplelist_addline(SIMPLELIST_ADD_LINE,
2361 "%04X %04X %04X %04X",
2362 (unsigned)nfo.regs[0], (unsigned)nfo.regs[1],
2363 (unsigned)nfo.regs[2], (unsigned)nfo.regs[3]);
2364 simplelist_addline(SIMPLELIST_ADD_LINE,
2365 "%04X %04X %04X %04X",
2366 (unsigned)nfo.regs[4], (unsigned)nfo.regs[5],
2367 (unsigned)nfo.regs[6], (unsigned)nfo.regs[7]);
2368 simplelist_addline(SIMPLELIST_ADD_LINE,
2369 "%04X %04X %04X %04X",
2370 (unsigned)nfo.regs[8], (unsigned)nfo.regs[9],
2371 (unsigned)nfo.regs[10], (unsigned)nfo.regs[11]);
2372 simplelist_addline(SIMPLELIST_ADD_LINE,
2373 "%04X %04X %04X %04X",
2374 (unsigned)nfo.regs[12], (unsigned)nfo.regs[13],
2375 (unsigned)nfo.regs[14], (unsigned)nfo.regs[15]);
2376 #endif /* SI4700 */
2377 return ACTION_REDRAW;
2379 static bool dbg_fm_radio(void)
2381 struct simplelist_info info;
2382 info.scroll_all = true;
2383 simplelist_info_init(&info, "FM Radio", 1, NULL);
2384 simplelist_set_line_count(0);
2385 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2386 radio_hardware_present() ? "yes" : "no");
2388 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2389 info.hide_selection = true;
2390 return simplelist_show_list(&info);
2392 #endif /* CONFIG_TUNER */
2393 #endif /* !SIMULATOR */
2395 #ifdef HAVE_LCD_BITMAP
2396 extern bool do_screendump_instead_of_usb;
2398 static bool dbg_screendump(void)
2400 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2401 splashf(HZ, "Screendump %s",
2402 do_screendump_instead_of_usb?"enabled":"disabled");
2403 return false;
2405 #endif /* HAVE_LCD_BITMAP */
2407 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2408 static bool dbg_set_memory_guard(void)
2410 static const struct opt_items names[MAXMEMGUARD] = {
2411 { "None", -1 },
2412 { "Flash ROM writes", -1 },
2413 { "Zero area (all)", -1 }
2415 int mode = system_memory_guard(MEMGUARD_KEEP);
2417 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2418 system_memory_guard(mode);
2420 return false;
2422 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2424 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2425 static bool dbg_write_eeprom(void)
2427 int fd;
2428 int rc;
2429 int old_irq_level;
2430 char buf[EEPROM_SIZE];
2431 int err;
2433 fd = open("/internal_eeprom.bin", O_RDONLY);
2435 if (fd >= 0)
2437 rc = read(fd, buf, EEPROM_SIZE);
2439 if(rc == EEPROM_SIZE)
2441 old_irq_level = disable_irq_save();
2443 err = eeprom_24cxx_write(0, buf, sizeof buf);
2444 if (err)
2445 splashf(HZ*3, "Eeprom write failure (%d)", err);
2446 else
2447 splash(HZ*3, "Eeprom written successfully");
2449 restore_irq(old_irq_level);
2451 else
2453 splashf(HZ*3, "File read error (%d)",rc);
2455 close(fd);
2457 else
2459 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2462 return false;
2464 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2465 #ifdef CPU_BOOST_LOGGING
2466 static bool cpu_boost_log(void)
2468 int i = 0,j=0;
2469 int count = cpu_boost_log_getcount();
2470 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2471 char *str;
2472 bool done;
2473 lcd_setfont(FONT_SYSFIXED);
2474 str = cpu_boost_log_getlog_first();
2475 viewportmanager_set_statusbar(false);
2476 while (i < count)
2478 lcd_clear_display();
2479 for(j=0; j<lines; j++,i++)
2481 if (!str)
2482 str = cpu_boost_log_getlog_next();
2483 if (str)
2485 lcd_puts(0, j,str);
2487 str = NULL;
2489 lcd_update();
2490 done = false;
2491 while (!done)
2493 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2495 case ACTION_STD_OK:
2496 case ACTION_STD_PREV:
2497 case ACTION_STD_NEXT:
2498 done = true;
2499 break;
2500 case ACTION_STD_CANCEL:
2501 i = count;
2502 done = true;
2503 break;
2507 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2508 lcd_setfont(FONT_UI);
2509 viewportmanager_set_statusbar(true);
2510 return false;
2512 #endif
2514 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2515 extern bool wheel_is_touched;
2516 extern int old_wheel_value;
2517 extern int new_wheel_value;
2518 extern int wheel_delta;
2519 extern unsigned int accumulated_wheel_delta;
2520 extern unsigned int wheel_velocity;
2522 static bool dbg_scrollwheel(void)
2524 char buf[64];
2525 unsigned int speed;
2527 lcd_setfont(FONT_SYSFIXED);
2528 viewportmanager_set_statusbar(false);
2530 while (1)
2532 if (action_userabort(HZ/10))
2533 break;
2535 lcd_clear_display();
2537 /* show internal variables of scrollwheel driver */
2538 snprintf(buf, sizeof(buf), "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2539 lcd_puts(0, 0, buf);
2540 snprintf(buf, sizeof(buf), "new position: %2d", new_wheel_value);
2541 lcd_puts(0, 1, buf);
2542 snprintf(buf, sizeof(buf), "old position: %2d", old_wheel_value);
2543 lcd_puts(0, 2, buf);
2544 snprintf(buf, sizeof(buf), "wheel delta: %2d", wheel_delta);
2545 lcd_puts(0, 3, buf);
2546 snprintf(buf, sizeof(buf), "accumulated delta: %2d", accumulated_wheel_delta);
2547 lcd_puts(0, 4, buf);
2548 snprintf(buf, sizeof(buf), "velo [deg/s]: %4d", (int)wheel_velocity);
2549 lcd_puts(0, 5, buf);
2551 /* show effective accelerated scrollspeed */
2552 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2553 snprintf(buf, sizeof(buf), "accel. speed: %4d", speed);
2554 lcd_puts(0, 6, buf);
2556 lcd_update();
2558 viewportmanager_set_statusbar(true);
2559 return false;
2561 #endif
2563 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2564 static bool logf_usb_serial(void)
2566 bool serial_enabled = !usb_core_driver_enabled(USB_DRIVER_SERIAL);
2567 usb_core_enable_driver(USB_DRIVER_SERIAL,serial_enabled);
2568 splashf(HZ, "USB logf %s",
2569 serial_enabled?"enabled":"disabled");
2570 return false;
2572 #endif
2574 #if defined(HAVE_USBSTACK) && defined(USB_STORAGE)
2575 static bool usb_reconnect(void)
2577 splash(HZ, "Reconnect mass storage");
2578 usb_storage_reconnect();
2579 return false;
2581 #endif
2583 #if CONFIG_USBOTG == USBOTG_ISP1583
2584 extern int dbg_usb_num_items(void);
2585 extern char* dbg_usb_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2587 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2589 (void)lists;
2590 if (action == ACTION_NONE)
2591 action = ACTION_REDRAW;
2592 return action;
2595 static bool dbg_isp1583(void)
2597 struct simplelist_info isp1583;
2598 isp1583.scroll_all = true;
2599 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2600 isp1583.timeout = HZ/100;
2601 isp1583.hide_selection = true;
2602 isp1583.get_name = dbg_usb_item;
2603 isp1583.action_callback = isp1583_action_callback;
2604 return simplelist_show_list(&isp1583);
2606 #endif
2608 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2609 extern int pic_dbg_num_items(void);
2610 extern char* pic_dbg_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2612 static int pic_action_callback(int action, struct gui_synclist *lists)
2614 (void)lists;
2615 if (action == ACTION_NONE)
2616 action = ACTION_REDRAW;
2617 return action;
2620 static bool dbg_pic(void)
2622 struct simplelist_info pic;
2623 pic.scroll_all = true;
2624 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2625 pic.timeout = HZ/100;
2626 pic.hide_selection = true;
2627 pic.get_name = pic_dbg_item;
2628 pic.action_callback = pic_action_callback;
2629 return simplelist_show_list(&pic);
2631 #endif
2634 /****** The menu *********/
2635 struct the_menu_item {
2636 unsigned char *desc; /* string or ID */
2637 bool (*function) (void); /* return true if USB was connected */
2639 static const struct the_menu_item menuitems[] = {
2640 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2641 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD))
2642 { "Dump ROM contents", dbg_save_roms },
2643 #endif
2644 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2645 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L
2646 { "View I/O ports", dbg_ports },
2647 #endif
2648 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2649 { "View PCF registers", dbg_pcf },
2650 #endif
2651 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2652 { "TSC2100 debug", tsc2100_debug },
2653 #endif
2654 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2655 { "CPU frequency", dbg_cpufreq },
2656 #endif
2657 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2658 { "S/PDIF analyzer", dbg_spdif },
2659 #endif
2660 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2661 { "Catch mem accesses", dbg_set_memory_guard },
2662 #endif
2663 { "View OS stacks", dbg_os },
2664 #ifdef HAVE_LCD_BITMAP
2665 #ifndef SIMULATOR
2666 { "View battery", view_battery },
2667 #endif
2668 { "Screendump", dbg_screendump },
2669 #endif
2670 #ifndef SIMULATOR
2671 { "View HW info", dbg_hw_info },
2672 #endif
2673 #ifndef SIMULATOR
2674 { "View partitions", dbg_partitions },
2675 #endif
2676 #ifndef SIMULATOR
2677 { "View disk info", dbg_disk_info },
2678 #if (CONFIG_STORAGE & STORAGE_ATA)
2679 { "Dump ATA identify info", dbg_identify_info},
2680 #endif
2681 #endif
2682 #ifdef HAVE_DIRCACHE
2683 { "View dircache info", dbg_dircache_info },
2684 #endif
2685 #ifdef HAVE_TAGCACHE
2686 { "View database info", dbg_tagcache_info },
2687 #endif
2688 #ifdef HAVE_LCD_BITMAP
2689 #if CONFIG_CODEC == SWCODEC
2690 { "View buffering thread", dbg_buffering_thread },
2691 #elif !defined(SIMULATOR)
2692 { "View audio thread", dbg_audio_thread },
2693 #endif
2694 #ifdef PM_DEBUG
2695 { "pm histogram", peak_meter_histogram},
2696 #endif /* PM_DEBUG */
2697 #endif /* HAVE_LCD_BITMAP */
2698 #ifndef SIMULATOR
2699 #if CONFIG_TUNER
2700 { "FM Radio", dbg_fm_radio },
2701 #endif
2702 #endif
2703 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2704 { "Write back EEPROM", dbg_write_eeprom },
2705 #endif
2706 #if CONFIG_USBOTG == USBOTG_ISP1583
2707 { "View ISP1583 info", dbg_isp1583 },
2708 #endif
2709 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2710 { "View PIC info", dbg_pic },
2711 #endif
2712 #ifdef ROCKBOX_HAS_LOGF
2713 {"logf", logfdisplay },
2714 {"logfdump", logfdump },
2715 #endif
2716 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2717 {"logf over usb",logf_usb_serial },
2718 #endif
2719 #if defined(HAVE_USBSTACK) && defined(USB_STORAGE)
2720 {"reconnect usb storage",usb_reconnect},
2721 #endif
2722 #ifdef CPU_BOOST_LOGGING
2723 {"cpu_boost log",cpu_boost_log},
2724 #endif
2725 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2726 {"Debug scrollwheel", dbg_scrollwheel},
2727 #endif
2729 static int menu_action_callback(int btn, struct gui_synclist *lists)
2731 if (btn == ACTION_STD_OK)
2733 menuitems[gui_synclist_get_sel_pos(lists)].function();
2734 btn = ACTION_REDRAW;
2736 return btn;
2738 static char* dbg_menu_getname(int item, void * data,
2739 char *buffer, size_t buffer_len)
2741 (void)data; (void)buffer; (void)buffer_len;
2742 return menuitems[item].desc;
2744 bool debug_menu(void)
2746 struct simplelist_info info;
2748 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2749 info.action_callback = menu_action_callback;
2750 info.get_name = dbg_menu_getname;
2752 return simplelist_show_list(&info);