Fuze: Change the button to mark possibilities from a select+up combo to just select...
[kugel-rb.git] / apps / debug_menu.c
blob1ea27b4f752dad9cfcfd7307578a767d3d16937f
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
103 #include "appevents.h"
105 #if CONFIG_CPU == DM320 || CONFIG_CPU == S3C2440 || CONFIG_CPU == TCC7801 \
106 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 || CONFIG_CPU == JZ4732 \
107 || defined(CPU_S5L870X)
108 #include "debug-target.h"
109 #endif
111 #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) \
112 || defined(SANSA_CLIP) || defined(SANSA_FUZE)
113 #include "ascodec.h"
114 #include "as3514.h"
115 #endif
117 #ifdef IPOD_NANO2G
118 #include "pmu-target.h"
119 #endif
121 #ifdef HAVE_USBSTACK
122 #include "usb_core.h"
123 #endif
125 /*---------------------------------------------------*/
126 /* SPECIAL DEBUG STUFF */
127 /*---------------------------------------------------*/
128 extern struct thread_entry threads[MAXTHREADS];
130 static char thread_status_char(unsigned status)
132 static const char thread_status_chars[THREAD_NUM_STATES+1] =
134 [0 ... THREAD_NUM_STATES] = '?',
135 [STATE_RUNNING] = 'R',
136 [STATE_BLOCKED] = 'B',
137 [STATE_SLEEPING] = 'S',
138 [STATE_BLOCKED_W_TMO] = 'T',
139 [STATE_FROZEN] = 'F',
140 [STATE_KILLED] = 'K',
143 if (status > THREAD_NUM_STATES)
144 status = THREAD_NUM_STATES;
146 return thread_status_chars[status];
149 static const char* threads_getname(int selected_item, void *data,
150 char *buffer, size_t buffer_len)
152 (void)data;
153 struct thread_entry *thread;
154 char name[32];
156 #if NUM_CORES > 1
157 if (selected_item < (int)NUM_CORES)
159 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
160 idle_stack_usage(selected_item));
161 return buffer;
164 selected_item -= NUM_CORES;
165 #endif
167 thread = &threads[selected_item];
169 if (thread->state == STATE_KILLED)
171 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
172 return buffer;
175 thread_get_name(name, 32, thread);
177 snprintf(buffer, buffer_len,
178 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
179 selected_item,
180 IF_COP(thread->core,)
181 #ifdef HAVE_SCHEDULER_BOOSTCTRL
182 (thread->cpu_boost) ? '+' :
183 #endif
184 ((thread->state == STATE_RUNNING) ? '*' : ' '),
185 thread_status_char(thread->state),
186 IF_PRIO(thread->base_priority, thread->priority, )
187 thread_stack_usage(thread), name);
189 return buffer;
192 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
194 (void)lists;
195 #ifdef ROCKBOX_HAS_LOGF
196 if (action == ACTION_STD_OK)
198 int selpos = gui_synclist_get_sel_pos(lists);
199 #if NUM_CORES > 1
200 if (selpos >= NUM_CORES)
201 remove_thread(threads[selpos - NUM_CORES].id);
202 #else
203 remove_thread(threads[selpos].id);
204 #endif
205 return ACTION_REDRAW;
207 #endif /* ROCKBOX_HAS_LOGF */
208 if (action == ACTION_NONE)
209 action = ACTION_REDRAW;
210 return action;
212 /* Test code!!! */
213 static bool dbg_os(void)
215 struct simplelist_info info;
216 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
217 #if NUM_CORES == 1
218 MAXTHREADS,
219 #else
220 MAXTHREADS+NUM_CORES,
221 #endif
222 NULL);
223 #ifndef ROCKBOX_HAS_LOGF
224 info.hide_selection = true;
225 info.scroll_all = true;
226 #endif
227 info.action_callback = dbg_threads_action_callback;
228 info.get_name = threads_getname;
229 return simplelist_show_list(&info);
232 #ifdef HAVE_LCD_BITMAP
233 #if CONFIG_CODEC != SWCODEC
234 #ifndef SIMULATOR
235 static bool dbg_audio_thread(void)
237 char buf[32];
238 struct audio_debug d;
240 lcd_setfont(FONT_SYSFIXED);
242 while(1)
244 if (action_userabort(HZ/5))
245 return false;
247 audio_get_debugdata(&d);
249 lcd_clear_display();
251 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
252 lcd_puts(0, 0, buf);
253 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
254 lcd_puts(0, 1, buf);
255 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
256 lcd_puts(0, 2, buf);
257 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
258 lcd_puts(0, 3, buf);
259 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
260 lcd_puts(0, 4, buf);
261 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
262 lcd_puts(0, 5, buf);
264 /* Playable space left */
265 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
266 d.playable_space, HORIZONTAL);
268 /* Show the watermark limit */
269 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
270 d.low_watermark_level, HORIZONTAL);
272 snprintf(buf, sizeof(buf), "wm: %x - %x",
273 d.low_watermark_level, d.lowest_watermark_level);
274 lcd_puts(0, 7, buf);
276 lcd_update();
278 lcd_setfont(FONT_UI);
279 return false;
281 #endif /* !SIMULATOR */
282 #else /* CONFIG_CODEC == SWCODEC */
283 extern size_t filebuflen;
284 /* This is a size_t, but call it a long so it puts a - when it's bad. */
286 static unsigned int ticks, boost_ticks, freq_sum;
288 static void dbg_audio_task(void)
290 #ifndef SIMULATOR
291 if(FREQ > CPUFREQ_NORMAL)
292 boost_ticks++;
293 freq_sum += FREQ/1000000; /* in MHz */
294 #endif
295 ticks++;
298 static bool dbg_buffering_thread(void)
300 char buf[32];
301 int button;
302 int line;
303 bool done = false;
304 size_t bufused;
305 size_t bufsize = pcmbuf_get_bufsize();
306 int pcmbufdescs = pcmbuf_descs();
307 struct buffering_debug d;
309 ticks = boost_ticks = freq_sum = 0;
311 tick_add_task(dbg_audio_task);
313 lcd_setfont(FONT_SYSFIXED);
314 while(!done)
316 button = get_action(CONTEXT_STD,HZ/5);
317 switch(button)
319 case ACTION_STD_NEXT:
320 audio_next();
321 break;
322 case ACTION_STD_PREV:
323 audio_prev();
324 break;
325 case ACTION_STD_CANCEL:
326 done = true;
327 break;
330 buffering_get_debugdata(&d);
332 line = 0;
333 lcd_clear_display();
335 bufused = bufsize - pcmbuf_free();
337 snprintf(buf, sizeof(buf), "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
338 lcd_puts(0, line++, buf);
340 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
341 bufsize, 0, bufused, HORIZONTAL);
342 line++;
344 snprintf(buf, sizeof(buf), "alloc: %6ld/%ld", audio_filebufused(),
345 (long) filebuflen);
346 lcd_puts(0, line++, buf);
348 #if LCD_HEIGHT > 80
349 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
350 filebuflen, 0, audio_filebufused(), HORIZONTAL);
351 line++;
353 snprintf(buf, sizeof(buf), "real: %6ld/%ld", (long)d.buffered_data,
354 (long)filebuflen);
355 lcd_puts(0, line++, buf);
357 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
358 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
359 line++;
360 #endif
362 snprintf(buf, sizeof(buf), "usefl: %6ld/%ld", (long)(d.useful_data),
363 (long)filebuflen);
364 lcd_puts(0, line++, buf);
366 #if LCD_HEIGHT > 80
367 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
368 filebuflen, 0, d.useful_data, HORIZONTAL);
369 line++;
370 #endif
372 snprintf(buf, sizeof(buf), "data_rem: %ld", (long)d.data_rem);
373 lcd_puts(0, line++, buf);
375 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
376 lcd_puts(0, line++, buf);
378 snprintf(buf, sizeof(buf), "handle count: %d", (int)d.num_handles);
379 lcd_puts(0, line++, buf);
381 #ifndef SIMULATOR
382 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
383 (int)((FREQ + 500000) / 1000000));
384 lcd_puts(0, line++, buf);
385 #endif
387 if (ticks > 0)
389 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
390 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
391 snprintf(buf, sizeof(buf), "boost:%3d.%d%% (%d.%dMHz)",
392 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
393 lcd_puts(0, line++, buf);
396 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
397 pcmbuf_used_descs(), pcmbufdescs);
398 lcd_puts(0, line++, buf);
399 snprintf(buf, sizeof(buf), "watermark: %6d",
400 (int)(d.watermark));
401 lcd_puts(0, line++, buf);
403 lcd_update();
406 tick_remove_task(dbg_audio_task);
407 lcd_setfont(FONT_UI);
409 return false;
411 #endif /* CONFIG_CODEC */
412 #endif /* HAVE_LCD_BITMAP */
415 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
416 /* Tool function to read the flash manufacturer and type, if available.
417 Only chips which could be reprogrammed in system will return values.
418 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
419 /* In IRAM to avoid problems when running directly from Flash */
420 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
421 unsigned addr1, unsigned addr2)
422 ICODE_ATTR __attribute__((noinline));
423 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
424 unsigned addr1, unsigned addr2)
427 unsigned not_manu, not_id; /* read values before switching to ID mode */
428 unsigned manu, id; /* read values when in ID mode */
430 #if CONFIG_CPU == SH7034
431 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
432 #elif defined(CPU_COLDFIRE)
433 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
434 #endif
435 int old_level; /* saved interrupt level */
437 not_manu = flash[0]; /* read the normal content */
438 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
440 /* disable interrupts, prevent any stray flash access */
441 old_level = disable_irq_save();
443 flash[addr1] = 0xAA; /* enter command mode */
444 flash[addr2] = 0x55;
445 flash[addr1] = 0x90; /* ID command */
446 /* Atmel wants 20ms pause here */
447 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
449 manu = flash[0]; /* read the IDs */
450 id = flash[1];
452 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
453 /* Atmel wants 20ms pause here */
454 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
456 restore_irq(old_level); /* enable interrupts again */
458 /* I assume success if the obtained values are different from
459 the normal flash content. This is not perfectly bulletproof, they
460 could theoretically be the same by chance, causing us to fail. */
461 if (not_manu != manu || not_id != id) /* a value has changed */
463 *p_manufacturer = manu; /* return the results */
464 *p_device = id;
465 return true; /* success */
467 return false; /* fail */
469 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
471 #ifndef SIMULATOR
472 #ifdef CPU_PP
473 static int perfcheck(void)
475 int result;
477 asm (
478 "mrs r2, CPSR \n"
479 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
480 "msr CPSR_c, r0 \n"
481 "mov %[res], #0 \n"
482 "ldr r0, [%[timr]] \n"
483 "add r0, r0, %[tmo] \n"
484 "1: \n"
485 "add %[res], %[res], #1 \n"
486 "ldr r1, [%[timr]] \n"
487 "cmp r1, r0 \n"
488 "bmi 1b \n"
489 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
491 [res]"=&r"(result)
493 [timr]"r"(&USEC_TIMER),
494 [tmo]"r"(
495 #if CONFIG_CPU == PP5002
496 16000
497 #else /* PP5020/5022/5024 */
498 10226
499 #endif
502 "r0", "r1", "r2"
504 return result;
506 #endif
508 #ifdef HAVE_LCD_BITMAP
509 static bool dbg_hw_info(void)
511 #if CONFIG_CPU == SH7034
512 char buf[32];
513 int bitmask = HW_MASK;
514 int rom_version = ROM_VERSION;
515 unsigned manu, id; /* flash IDs */
516 bool got_id; /* flag if we managed to get the flash IDs */
517 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
518 bool has_bootrom; /* flag for boot ROM present */
519 int oldmode; /* saved memory guard mode */
521 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
523 /* get flash ROM type */
524 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
525 if (!got_id)
526 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
528 /* check if the boot ROM area is a flash mirror */
529 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
530 if (has_bootrom) /* if ROM and Flash different */
532 /* calculate CRC16 checksum of boot ROM */
533 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
536 system_memory_guard(oldmode); /* re-enable memory guard */
538 lcd_setfont(FONT_SYSFIXED);
539 lcd_clear_display();
541 lcd_puts(0, 0, "[Hardware info]");
543 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
544 lcd_puts(0, 1, buf);
546 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
547 lcd_puts(0, 2, buf);
549 if (got_id)
550 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
551 else
552 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
553 lcd_puts(0, 3, buf);
555 if (has_bootrom)
557 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
558 snprintf(buf, 32, "Boot ROM: V1");
559 else
560 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
562 else
564 snprintf(buf, 32, "Boot ROM: none");
566 lcd_puts(0, 4, buf);
568 lcd_update();
570 while (!(action_userabort(TIMEOUT_BLOCK)));
572 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
573 char buf[32];
574 unsigned manu, id; /* flash IDs */
575 int got_id; /* flag if we managed to get the flash IDs */
576 int oldmode; /* saved memory guard mode */
577 int line = 0;
579 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
581 /* get flash ROM type */
582 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
583 if (!got_id)
584 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
586 system_memory_guard(oldmode); /* re-enable memory guard */
588 lcd_setfont(FONT_SYSFIXED);
589 lcd_clear_display();
591 lcd_puts(0, line++, "[Hardware info]");
593 if (got_id)
594 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
595 else
596 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
597 lcd_puts(0, line++, buf);
599 #ifdef IAUDIO_X5
601 struct ds2411_id id;
603 lcd_puts(0, ++line, "Serial Number:");
605 got_id = ds2411_read_id(&id);
607 if (got_id == DS2411_OK)
609 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
610 lcd_puts(0, ++line, buf);
611 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
612 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
613 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
614 lcd_puts(0, ++line, buf);
615 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
617 else
619 snprintf(buf, 32, "READ ERR=%d", got_id);
622 lcd_puts(0, ++line, buf);
624 #endif
626 lcd_update();
628 while (!(action_userabort(TIMEOUT_BLOCK)));
630 #elif defined(CPU_PP502x)
631 int line = 0;
632 char buf[32];
633 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
634 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
635 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
636 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
638 lcd_setfont(FONT_SYSFIXED);
639 lcd_clear_display();
641 lcd_puts(0, line++, "[Hardware info]");
643 #ifdef IPOD_ARCH
644 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
645 lcd_puts(0, line++, buf);
646 #endif
648 #ifdef IPOD_COLOR
649 extern int lcd_type; /* Defined in lcd-colornano.c */
651 snprintf(buf, sizeof(buf), "LCD type: %d", lcd_type);
652 lcd_puts(0, line++, buf);
653 #endif
655 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
656 lcd_puts(0, line++, buf);
658 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
659 lcd_puts(0, line++, buf);
661 lcd_update();
663 while (!(action_userabort(TIMEOUT_BLOCK)));
665 #elif CONFIG_CPU == PP5002
666 int line = 0;
667 char buf[32];
668 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
669 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
670 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
671 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
674 lcd_setfont(FONT_SYSFIXED);
675 lcd_clear_display();
677 lcd_puts(0, line++, "[Hardware info]");
679 #ifdef IPOD_ARCH
680 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
681 lcd_puts(0, line++, buf);
682 #endif
684 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
685 lcd_puts(0, line++, buf);
687 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
688 lcd_puts(0, line++, buf);
690 lcd_update();
692 while (!(action_userabort(TIMEOUT_BLOCK)));
694 #else
695 /* Define this function in your target tree */
696 return __dbg_hw_info();
697 #endif /* CONFIG_CPU */
698 lcd_setfont(FONT_UI);
699 return false;
701 #else /* !HAVE_LCD_BITMAP */
702 static bool dbg_hw_info(void)
704 char buf[32];
705 int button;
706 int currval = 0;
707 int rom_version = ROM_VERSION;
708 unsigned manu, id; /* flash IDs */
709 bool got_id; /* flag if we managed to get the flash IDs */
710 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
711 bool has_bootrom; /* flag for boot ROM present */
712 int oldmode; /* saved memory guard mode */
714 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
716 /* get flash ROM type */
717 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
718 if (!got_id)
719 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
721 /* check if the boot ROM area is a flash mirror */
722 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
723 if (has_bootrom) /* if ROM and Flash different */
725 /* calculate CRC16 checksum of boot ROM */
726 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
729 system_memory_guard(oldmode); /* re-enable memory guard */
731 lcd_clear_display();
733 lcd_puts(0, 0, "[HW Info]");
734 while(1)
736 switch(currval)
738 case 0:
739 snprintf(buf, 32, "ROM: %d.%02d",
740 rom_version/100, rom_version%100);
741 break;
742 case 1:
743 if (got_id)
744 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
745 else
746 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
747 break;
748 case 2:
749 if (has_bootrom)
751 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
752 snprintf(buf, 32, "BootROM: V1");
753 else if (rom_crc == 0x358099E8)
754 snprintf(buf, 32, "BootROM: V2");
755 /* alternative boot ROM found in one single player so far */
756 else
757 snprintf(buf, 32, "R: %08x", rom_crc);
759 else
760 snprintf(buf, 32, "BootROM: no");
763 lcd_puts(0, 1, buf);
764 lcd_update();
766 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
768 switch(button)
770 case ACTION_STD_CANCEL:
771 return false;
773 case ACTION_SETTINGS_DEC:
774 currval--;
775 if(currval < 0)
776 currval = 2;
777 break;
779 case ACTION_SETTINGS_INC:
780 currval++;
781 if(currval > 2)
782 currval = 0;
783 break;
786 return false;
788 #endif /* !HAVE_LCD_BITMAP */
789 #endif /* !SIMULATOR */
791 #ifndef SIMULATOR
792 static const char* dbg_partitions_getname(int selected_item, void *data,
793 char *buffer, size_t buffer_len)
795 (void)data;
796 int partition = selected_item/2;
797 struct partinfo* p = disk_partinfo(partition);
798 if (selected_item%2)
800 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / 2048);
802 else
804 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
806 return buffer;
809 bool dbg_partitions(void)
811 struct simplelist_info info;
812 simplelist_info_init(&info, "Partition Info", 4, NULL);
813 info.selection_size = 2;
814 info.hide_selection = true;
815 info.scroll_all = true;
816 info.get_name = dbg_partitions_getname;
817 return simplelist_show_list(&info);
819 #endif
821 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
822 static bool dbg_spdif(void)
824 char buf[128];
825 int line;
826 unsigned int control;
827 int x;
828 char *s;
829 int category;
830 int generation;
831 unsigned int interruptstat;
832 bool valnogood, symbolerr, parityerr;
833 bool done = false;
834 bool spdif_src_on;
835 int spdif_source = spdif_get_output_source(&spdif_src_on);
836 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
838 lcd_clear_display();
839 lcd_setfont(FONT_SYSFIXED);
841 #ifdef HAVE_SPDIF_POWER
842 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
843 #endif
845 while (!done)
847 line = 0;
849 control = EBU1RCVCCHANNEL1;
850 interruptstat = INTERRUPTSTAT;
851 INTERRUPTCLEAR = 0x03c00000;
853 valnogood = (interruptstat & 0x01000000)?true:false;
854 symbolerr = (interruptstat & 0x00800000)?true:false;
855 parityerr = (interruptstat & 0x00400000)?true:false;
857 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
858 valnogood?"--":"OK",
859 symbolerr?"--":"OK",
860 parityerr?"--":"OK");
861 lcd_puts(0, line++, buf);
863 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
864 lcd_puts(0, line++, buf);
866 line++;
868 x = control >> 31;
869 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
870 x, x?"Professional":"Consumer");
871 lcd_puts(0, line++, buf);
873 x = (control >> 30) & 1;
874 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
875 x, x?"Non-PCM":"PCM");
876 lcd_puts(0, line++, buf);
878 x = (control >> 29) & 1;
879 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
880 x, x?"Permitted":"Inhibited");
881 lcd_puts(0, line++, buf);
883 x = (control >> 27) & 7;
884 switch(x)
886 case 0:
887 s = "None";
888 break;
889 case 1:
890 s = "50/15us";
891 break;
892 default:
893 s = "Reserved";
894 break;
896 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
897 lcd_puts(0, line++, buf);
899 x = (control >> 24) & 3;
900 snprintf(buf, sizeof(buf), "Mode: %d", x);
901 lcd_puts(0, line++, buf);
903 category = (control >> 17) & 127;
904 switch(category)
906 case 0x00:
907 s = "General";
908 break;
909 case 0x40:
910 s = "Audio CD";
911 break;
912 default:
913 s = "Unknown";
915 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
916 lcd_puts(0, line++, buf);
918 x = (control >> 16) & 1;
919 generation = x;
920 if(((category & 0x70) == 0x10) ||
921 ((category & 0x70) == 0x40) ||
922 ((category & 0x78) == 0x38))
924 generation = !generation;
926 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
927 x, generation?"Original":"No ind.");
928 lcd_puts(0, line++, buf);
930 x = (control >> 12) & 15;
931 snprintf(buf, sizeof(buf), "Source: %d", x);
932 lcd_puts(0, line++, buf);
934 x = (control >> 8) & 15;
935 switch(x)
937 case 0:
938 s = "Unspecified";
939 break;
940 case 8:
941 s = "A (Left)";
942 break;
943 case 4:
944 s = "B (Right)";
945 break;
946 default:
947 s = "";
948 break;
950 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
951 lcd_puts(0, line++, buf);
953 x = (control >> 4) & 15;
954 switch(x)
956 case 0:
957 s = "44.1kHz";
958 break;
959 case 0x4:
960 s = "48kHz";
961 break;
962 case 0xc:
963 s = "32kHz";
964 break;
966 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
967 lcd_puts(0, line++, buf);
969 x = (control >> 2) & 3;
970 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
971 lcd_puts(0, line++, buf);
972 line++;
974 #ifndef SIMULATOR
975 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
976 spdif_measure_frequency());
977 lcd_puts(0, line++, buf);
978 #endif
980 lcd_update();
982 if (action_userabort(HZ/10))
983 break;
986 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
988 #ifdef HAVE_SPDIF_POWER
989 spdif_power_enable(global_settings.spdif_enable);
990 #endif
992 lcd_setfont(FONT_UI);
993 return false;
995 #endif /* CPU_COLDFIRE */
997 #ifndef SIMULATOR
998 #ifdef HAVE_LCD_BITMAP
999 /* button definitions */
1000 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
1001 (CONFIG_KEYPAD == IRIVER_H300_PAD)
1002 # define DEBUG_CANCEL BUTTON_OFF
1004 #elif CONFIG_KEYPAD == RECORDER_PAD
1005 # define DEBUG_CANCEL BUTTON_OFF
1007 #elif CONFIG_KEYPAD == ONDIO_PAD
1008 # define DEBUG_CANCEL BUTTON_MENU
1010 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
1011 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
1012 (CONFIG_KEYPAD == IPOD_4G_PAD)
1013 # define DEBUG_CANCEL BUTTON_MENU
1015 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
1016 # define DEBUG_CANCEL BUTTON_PLAY
1018 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
1019 # define DEBUG_CANCEL BUTTON_REC
1021 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1022 # define DEBUG_CANCEL BUTTON_RC_REC
1024 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
1025 # define DEBUG_CANCEL BUTTON_REW
1027 #elif (CONFIG_KEYPAD == MROBE100_PAD)
1028 # define DEBUG_CANCEL BUTTON_MENU
1030 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
1031 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
1032 (CONFIG_KEYPAD == SANSA_FUZE_PAD)
1033 # define DEBUG_CANCEL BUTTON_LEFT
1035 /* This is temporary until the SA9200 touchpad works */
1036 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) || \
1037 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD)
1038 # define DEBUG_CANCEL BUTTON_POWER
1040 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
1041 # define DEBUG_CANCEL BUTTON_PLAY
1043 #endif /* key definitions */
1045 /* Test code!!! */
1046 bool dbg_ports(void)
1048 #if CONFIG_CPU == SH7034
1049 char buf[32];
1050 int adc_battery_voltage, adc_battery_level;
1052 lcd_setfont(FONT_SYSFIXED);
1053 lcd_clear_display();
1055 while(1)
1057 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1058 lcd_puts(0, 0, buf);
1059 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1060 lcd_puts(0, 1, buf);
1062 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1063 lcd_puts(0, 2, buf);
1064 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1065 lcd_puts(0, 3, buf);
1066 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1067 lcd_puts(0, 4, buf);
1068 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1069 lcd_puts(0, 5, buf);
1071 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1072 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1073 adc_battery_voltage % 1000, adc_battery_level);
1074 lcd_puts(0, 6, buf);
1076 lcd_update();
1077 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1079 lcd_setfont(FONT_UI);
1080 return false;
1083 #elif defined(CPU_COLDFIRE)
1084 unsigned int gpio_out;
1085 unsigned int gpio1_out;
1086 unsigned int gpio_read;
1087 unsigned int gpio1_read;
1088 unsigned int gpio_function;
1089 unsigned int gpio1_function;
1090 unsigned int gpio_enable;
1091 unsigned int gpio1_enable;
1092 int adc_buttons, adc_remote;
1093 int adc_battery_voltage, adc_battery_level;
1094 char buf[128];
1095 int line;
1097 lcd_clear_display();
1098 lcd_setfont(FONT_SYSFIXED);
1100 while(1)
1102 line = 0;
1103 gpio_read = GPIO_READ;
1104 gpio1_read = GPIO1_READ;
1105 gpio_out = GPIO_OUT;
1106 gpio1_out = GPIO1_OUT;
1107 gpio_function = GPIO_FUNCTION;
1108 gpio1_function = GPIO1_FUNCTION;
1109 gpio_enable = GPIO_ENABLE;
1110 gpio1_enable = GPIO1_ENABLE;
1112 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1113 lcd_puts(0, line++, buf);
1114 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1115 lcd_puts(0, line++, buf);
1116 snprintf(buf, sizeof(buf), "GPIO_FUNC: %08x", gpio_function);
1117 lcd_puts(0, line++, buf);
1118 snprintf(buf, sizeof(buf), "GPIO_ENA: %08x", gpio_enable);
1119 lcd_puts(0, line++, buf);
1121 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1122 lcd_puts(0, line++, buf);
1123 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1124 lcd_puts(0, line++, buf);
1125 snprintf(buf, sizeof(buf), "GPIO1_FUNC: %08x", gpio1_function);
1126 lcd_puts(0, line++, buf);
1127 snprintf(buf, sizeof(buf), "GPIO1_ENA: %08x", gpio1_enable);
1128 lcd_puts(0, line++, buf);
1130 adc_buttons = adc_read(ADC_BUTTONS);
1131 adc_remote = adc_read(ADC_REMOTE);
1132 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1133 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1134 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1135 button_scan_enabled() ? '+' : '-', adc_buttons);
1136 #else
1137 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1138 #endif
1139 lcd_puts(0, line++, buf);
1140 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1141 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1142 remote_detect() ? '+' : '-', adc_remote);
1143 #else
1144 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1145 #endif
1146 lcd_puts(0, line++, buf);
1147 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1148 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1149 adc_read(ADC_REMOTEDETECT));
1150 lcd_puts(0, line++, buf);
1151 #endif
1153 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1154 adc_battery_voltage % 1000, adc_battery_level);
1155 lcd_puts(0, line++, buf);
1157 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1158 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1159 lcd_puts(0, line++, buf);
1160 #endif
1162 lcd_update();
1163 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1165 lcd_setfont(FONT_UI);
1166 return false;
1170 #elif defined(CPU_PP502x)
1172 char buf[128];
1173 int line;
1175 lcd_clear_display();
1176 lcd_setfont(FONT_SYSFIXED);
1178 while(1)
1180 line = 0;
1181 lcd_puts(0, line++, "GPIO STATES:");
1182 snprintf(buf, sizeof(buf), "A: %02x E: %02x I: %02x",
1183 (unsigned int)GPIOA_INPUT_VAL,
1184 (unsigned int)GPIOE_INPUT_VAL,
1185 (unsigned int)GPIOI_INPUT_VAL);
1186 lcd_puts(0, line++, buf);
1187 snprintf(buf, sizeof(buf), "B: %02x F: %02x J: %02x",
1188 (unsigned int)GPIOB_INPUT_VAL,
1189 (unsigned int)GPIOF_INPUT_VAL,
1190 (unsigned int)GPIOJ_INPUT_VAL);
1191 lcd_puts(0, line++, buf);
1192 snprintf(buf, sizeof(buf), "C: %02x G: %02x K: %02x",
1193 (unsigned int)GPIOC_INPUT_VAL,
1194 (unsigned int)GPIOG_INPUT_VAL,
1195 (unsigned int)GPIOK_INPUT_VAL);
1196 lcd_puts(0, line++, buf);
1197 snprintf(buf, sizeof(buf), "D: %02x H: %02x L: %02x",
1198 (unsigned int)GPIOD_INPUT_VAL,
1199 (unsigned int)GPIOH_INPUT_VAL,
1200 (unsigned int)GPIOL_INPUT_VAL);
1201 lcd_puts(0, line++, buf);
1202 line++;
1203 snprintf(buf, sizeof(buf), "GPO32_VAL: %08lx", GPO32_VAL);
1204 lcd_puts(0, line++, buf);
1205 snprintf(buf, sizeof(buf), "GPO32_EN: %08lx", GPO32_ENABLE);
1206 lcd_puts(0, line++, buf);
1207 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1208 lcd_puts(0, line++, buf);
1209 snprintf(buf, sizeof(buf), "DEV_EN2: %08lx", DEV_EN2);
1210 lcd_puts(0, line++, buf);
1211 snprintf(buf, sizeof(buf), "DEV_EN3: %08lx", inl(0x60006044));
1212 lcd_puts(0, line++, buf); /* to be verified */
1213 snprintf(buf, sizeof(buf), "DEV_INIT1: %08lx", DEV_INIT1);
1214 lcd_puts(0, line++, buf);
1215 snprintf(buf, sizeof(buf), "DEV_INIT2: %08lx", DEV_INIT2);
1216 lcd_puts(0, line++, buf);
1217 #ifdef ADC_ACCESSORY
1218 snprintf(buf, sizeof(buf), "ACCESSORY: %d", adc_read(ADC_ACCESSORY));
1219 lcd_puts(0, line++, buf);
1220 #endif
1222 #if defined(IPOD_ACCESSORY_PROTOCOL)
1223 extern unsigned char serbuf[];
1224 snprintf(buf, sizeof(buf), "IAP PACKET: %02x %02x %02x %02x %02x %02x %02x %02x",
1225 serbuf[0], serbuf[1], serbuf[2], serbuf[3], serbuf[4], serbuf[5],
1226 serbuf[6], serbuf[7]);
1227 lcd_puts(0, line++, buf);
1228 #endif
1230 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1231 line++;
1232 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1233 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1234 lcd_puts(0, line++, buf);
1235 snprintf(buf, sizeof(buf), "REM: %03x PAD: %03x",
1236 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1237 lcd_puts(0, line++, buf);
1238 #elif defined(PHILIPS_HDD1630)
1239 line++;
1240 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1241 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1242 lcd_puts(0, line++, buf);
1243 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1244 snprintf(buf, sizeof(buf), "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1245 lcd_puts(0, line++, buf);
1246 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1247 lcd_puts(0, line++, buf);
1248 snprintf(buf, sizeof(buf), "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1249 lcd_puts(0, line++, buf);
1250 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1251 lcd_puts(0, line++, buf);
1252 snprintf(buf, sizeof(buf), "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1253 lcd_puts(0, line++, buf);
1254 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1255 lcd_puts(0, line++, buf);
1256 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1257 lcd_puts(0, line++, buf);
1258 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1259 lcd_puts(0, line++, buf);
1260 snprintf(buf, sizeof(buf), "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1261 lcd_puts(0, line++, buf);
1262 snprintf(buf, sizeof(buf), "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1263 lcd_puts(0, line++, buf);
1264 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1265 lcd_puts(0, line++, buf);
1266 #if !defined(PHILIPS_SA9200)
1267 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1268 lcd_puts(0, line++, buf);
1269 snprintf(buf, sizeof(buf), "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1270 lcd_puts(0, line++, buf);
1271 #endif
1272 #endif
1273 lcd_update();
1274 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1276 lcd_setfont(FONT_UI);
1277 return false;
1281 #elif CONFIG_CPU == PP5002
1282 char buf[128];
1283 int line;
1285 lcd_clear_display();
1286 lcd_setfont(FONT_SYSFIXED);
1288 while(1)
1290 line = 0;
1291 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x",
1292 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1293 lcd_puts(0, line++, buf);
1294 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x",
1295 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1296 lcd_puts(0, line++, buf);
1298 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1299 lcd_puts(0, line++, buf);
1300 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1301 lcd_puts(0, line++, buf);
1302 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1303 lcd_puts(0, line++, buf);
1304 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1305 lcd_puts(0, line++, buf);
1306 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1307 lcd_puts(0, line++, buf);
1308 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1309 lcd_puts(0, line++, buf);
1310 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1311 lcd_puts(0, line++, buf);
1312 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1313 lcd_puts(0, line++, buf);
1315 lcd_update();
1316 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1318 lcd_setfont(FONT_UI);
1319 return false;
1322 lcd_setfont(FONT_UI);
1323 #else
1324 return __dbg_ports();
1325 #endif /* CPU */
1326 return false;
1328 #else /* !HAVE_LCD_BITMAP */
1329 bool dbg_ports(void)
1331 char buf[32];
1332 int button;
1333 int adc_battery_voltage;
1334 int currval = 0;
1336 lcd_clear_display();
1338 while(1)
1340 switch(currval)
1342 case 0:
1343 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1344 break;
1345 case 1:
1346 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1347 break;
1348 case 2:
1349 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1350 break;
1351 case 3:
1352 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1353 break;
1354 case 4:
1355 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1356 break;
1357 case 5:
1358 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1359 break;
1360 case 6:
1361 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1362 break;
1363 case 7:
1364 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1365 break;
1366 case 8:
1367 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1368 break;
1369 case 9:
1370 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1371 break;
1373 lcd_puts(0, 0, buf);
1375 battery_read_info(&adc_battery_voltage, NULL);
1376 snprintf(buf, 32, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1377 adc_battery_voltage % 1000);
1378 lcd_puts(0, 1, buf);
1379 lcd_update();
1381 button = get_action(CONTEXT_SETTINGS,HZ/5);
1383 switch(button)
1385 case ACTION_STD_CANCEL:
1386 return false;
1388 case ACTION_SETTINGS_DEC:
1389 currval--;
1390 if(currval < 0)
1391 currval = 9;
1392 break;
1394 case ACTION_SETTINGS_INC:
1395 currval++;
1396 if(currval > 9)
1397 currval = 0;
1398 break;
1401 return false;
1403 #endif /* !HAVE_LCD_BITMAP */
1404 #endif /* !SIMULATOR */
1406 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1407 static bool dbg_pcf(void)
1409 char buf[128];
1410 int line;
1412 #ifdef HAVE_LCD_BITMAP
1413 lcd_setfont(FONT_SYSFIXED);
1414 #endif
1415 lcd_clear_display();
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 lcd_setfont(FONT_UI);
1452 return false;
1456 lcd_setfont(FONT_UI);
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();
1473 while(1)
1475 line = 0;
1477 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1478 lcd_puts(0, line++, buf);
1480 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1481 lcd_puts(0, line++, buf);
1483 lcd_update();
1484 button = get_action(CONTEXT_STD,HZ/10);
1486 switch(button)
1488 case ACTION_STD_PREV:
1489 cpu_boost(true);
1490 break;
1492 case ACTION_STD_NEXT:
1493 cpu_boost(false);
1494 break;
1496 case ACTION_STD_OK:
1497 while (get_cpu_boost_counter() > 0)
1498 cpu_boost(false);
1499 set_cpu_frequency(CPUFREQ_DEFAULT);
1500 break;
1502 case ACTION_STD_CANCEL:
1503 lcd_setfont(FONT_UI);
1504 return false;
1507 lcd_setfont(FONT_UI);
1508 return false;
1510 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1512 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1513 #include "tsc2100.h"
1514 static char *itob(int n, int len)
1516 static char binary[64];
1517 int i,j;
1518 for (i=1, j=0;i<=len;i++)
1520 binary[j++] = n&(1<<(len-i))?'1':'0';
1521 if (i%4 == 0)
1522 binary[j++] = ' ';
1524 binary[j] = '\0';
1525 return binary;
1528 static const 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);
1602 while(1)
1604 lcd_clear_display();
1605 switch (view) {
1606 case 0: /* voltage history graph */
1607 /* Find maximum and minimum voltage for scaling */
1608 minv = power_history[0];
1609 maxv = minv + 1;
1610 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1611 if (power_history[i] > maxv)
1612 maxv = power_history[i];
1613 if (power_history[i] < minv)
1614 minv = power_history[i];
1617 snprintf(buf, 30, "Battery %d.%03d", power_history[0] / 1000,
1618 power_history[0] % 1000);
1619 lcd_puts(0, 0, buf);
1620 snprintf(buf, 30, "scale %d.%03d-%d.%03dV",
1621 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1622 lcd_puts(0, 1, buf);
1624 x = 0;
1625 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1626 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1627 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1628 lcd_vline(x, LCD_HEIGHT-1, 20);
1629 lcd_set_drawmode(DRMODE_SOLID);
1630 lcd_vline(x, LCD_HEIGHT-1,
1631 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1632 x++;
1635 break;
1637 case 1: /* status: */
1638 lcd_puts(0, 0, "Power status:");
1640 battery_read_info(&y, NULL);
1641 snprintf(buf, 30, "Battery: %d.%03d V", y / 1000, y % 1000);
1642 lcd_puts(0, 1, buf);
1643 #ifdef ADC_EXT_POWER
1644 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1645 snprintf(buf, 30, "External: %d.%03d V", y / 1000, y % 1000);
1646 lcd_puts(0, 2, buf);
1647 #endif
1648 #if CONFIG_CHARGING
1649 #if defined ARCHOS_RECORDER
1650 snprintf(buf, 30, "Chgr: %s %s",
1651 charger_inserted() ? "present" : "absent",
1652 charger_enabled() ? "on" : "off");
1653 lcd_puts(0, 3, buf);
1654 snprintf(buf, 30, "short delta: %d", short_delta);
1655 lcd_puts(0, 5, buf);
1656 snprintf(buf, 30, "long delta: %d", long_delta);
1657 lcd_puts(0, 6, buf);
1658 lcd_puts(0, 7, power_message);
1659 snprintf(buf, 30, "USB Inserted: %s",
1660 usb_inserted() ? "yes" : "no");
1661 lcd_puts(0, 8, buf);
1662 #elif defined IRIVER_H300_SERIES
1663 snprintf(buf, 30, "USB Charging Enabled: %s",
1664 usb_charging_enabled() ? "yes" : "no");
1665 lcd_puts(0, 9, buf);
1666 #elif defined IPOD_NANO || defined IPOD_VIDEO
1667 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1668 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1669 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1670 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1671 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1673 snprintf(buf, 30, "USB pwr: %s",
1674 usb_pwr ? "present" : "absent");
1675 lcd_puts(0, 3, buf);
1676 snprintf(buf, 30, "EXT pwr: %s",
1677 ext_pwr ? "present" : "absent");
1678 lcd_puts(0, 4, buf);
1679 snprintf(buf, 30, "Battery: %s",
1680 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1681 lcd_puts(0, 5, buf);
1682 snprintf(buf, 30, "Dock mode: %s",
1683 dock ? "enabled" : "disabled");
1684 lcd_puts(0, 6, buf);
1685 snprintf(buf, 30, "Headphone: %s",
1686 headphone ? "connected" : "disconnected");
1687 lcd_puts(0, 7, buf);
1688 #elif defined TOSHIBA_GIGABEAT_S
1689 int line = 3;
1690 unsigned int st;
1692 static const unsigned char * const chrgstate_strings[] =
1694 "Disabled",
1695 "Error",
1696 "Discharging",
1697 "Precharge",
1698 "Constant Voltage",
1699 "Constant Current",
1700 "<unknown>",
1703 snprintf(buf, 30, "Charger: %s",
1704 charger_inserted() ? "present" : "absent");
1705 lcd_puts(0, line++, buf);
1707 st = power_input_status() &
1708 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1709 snprintf(buf, 30, "%s%s",
1710 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1711 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1712 lcd_puts(0, line++, buf);
1714 snprintf(buf, 30, "IUSB Max: %d", usb_allowed_current());
1715 lcd_puts(0, line++, buf);
1717 y = ARRAYLEN(chrgstate_strings) - 1;
1719 switch (charge_state)
1721 case CHARGE_STATE_DISABLED: y--;
1722 case CHARGE_STATE_ERROR: y--;
1723 case DISCHARGING: y--;
1724 case TRICKLE: y--;
1725 case TOPOFF: y--;
1726 case CHARGING: y--;
1727 default:;
1730 snprintf(buf, 30, "State: %s", chrgstate_strings[y]);
1731 lcd_puts(0, line++, buf);
1733 snprintf(buf, 30, "Battery Switch: %s",
1734 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1735 lcd_puts(0, line++, buf);
1737 y = chrgraw_adc_voltage();
1738 snprintf(buf, 30, "CHRGRAW: %d.%03d V",
1739 y / 1000, y % 1000);
1740 lcd_puts(0, line++, buf);
1742 y = application_supply_adc_voltage();
1743 snprintf(buf, 30, "BP : %d.%03d V",
1744 y / 1000, y % 1000);
1745 lcd_puts(0, line++, buf);
1747 y = battery_adc_charge_current();
1748 if (y < 0) x = '-', y = -y;
1749 else x = ' ';
1750 snprintf(buf, 30, "CHRGISN:%c%d mA", x, y);
1751 lcd_puts(0, line++, buf);
1753 y = cccv_regulator_dissipation();
1754 snprintf(buf, 30, "P CCCV : %d mW", y);
1755 lcd_puts(0, line++, buf);
1757 y = battery_charge_current();
1758 if (y < 0) x = '-', y = -y;
1759 else x = ' ';
1760 snprintf(buf, 30, "I Charge:%c%d mA", x, y);
1761 lcd_puts(0, line++, buf);
1763 y = battery_adc_temp();
1765 if (y != INT_MIN) {
1766 snprintf(buf, 30, "T Battery: %dC (%dF)", y,
1767 (9*y + 160) / 5);
1768 } else {
1769 /* Conversion disabled */
1770 snprintf(buf, 30, "T Battery: ?");
1773 lcd_puts(0, line++, buf);
1774 #elif defined(SANSA_E200) || defined(SANSA_C200) || defined(SANSA_CLIP) || defined(SANSA_FUZE)
1775 const int first = CHARGE_STATE_DISABLED;
1776 static const char * const chrgstate_strings[] =
1778 [CHARGE_STATE_DISABLED-first] = "Disabled",
1779 [CHARGE_STATE_ERROR-first] = "Error",
1780 [DISCHARGING-first] = "Discharging",
1781 [CHARGING-first] = "Charging",
1783 const char *str = NULL;
1785 snprintf(buf, 30, "Charger: %s",
1786 charger_inserted() ? "present" : "absent");
1787 lcd_puts(0, 3, buf);
1789 y = charge_state - first;
1790 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1791 str = chrgstate_strings[y];
1793 snprintf(buf, sizeof(buf), "State: %s",
1794 str ? str : "<unknown>");
1795 lcd_puts(0, 4, buf);
1797 snprintf(buf, sizeof(buf), "CHARGER: %02X",
1798 ascodec_read(AS3514_CHARGER));
1799 lcd_puts(0, 5, buf);
1800 #elif defined(IPOD_NANO2G)
1801 y = pmu_read_battery_current();
1802 snprintf(buf, 30, "Battery current: %d mA", y);
1803 lcd_puts(0, 2, buf);
1804 #else
1805 snprintf(buf, 30, "Charger: %s",
1806 charger_inserted() ? "present" : "absent");
1807 lcd_puts(0, 3, buf);
1808 #endif /* target type */
1809 #endif /* CONFIG_CHARGING */
1810 break;
1812 case 2: /* voltage deltas: */
1813 lcd_puts(0, 0, "Voltage deltas:");
1815 for (i = 0; i <= 6; i++) {
1816 y = power_history[i] - power_history[i+1];
1817 snprintf(buf, 30, "-%d min: %s%d.%03d V", i,
1818 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1819 ((y < 0) ? y * -1 : y ) % 1000);
1820 lcd_puts(0, i+1, buf);
1822 break;
1824 case 3: /* remaining time estimation: */
1826 #ifdef ARCHOS_RECORDER
1827 snprintf(buf, 30, "charge_state: %d", charge_state);
1828 lcd_puts(0, 0, buf);
1830 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1831 lcd_puts(0, 1, buf);
1833 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1834 lcd_puts(0, 2, buf);
1836 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1837 lcd_puts(0, 3, buf);
1839 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1840 lcd_puts(0, 4, buf);
1841 #endif /* ARCHOS_RECORDER */
1843 snprintf(buf, 30, "Last PwrHist: %d.%03dV",
1844 power_history[0] / 1000,
1845 power_history[0] % 1000);
1846 lcd_puts(0, 5, buf);
1848 snprintf(buf, 30, "battery level: %d%%", battery_level());
1849 lcd_puts(0, 6, buf);
1851 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1852 lcd_puts(0, 7, buf);
1853 break;
1856 lcd_update();
1858 switch(get_action(CONTEXT_STD,HZ/2))
1860 case ACTION_STD_PREV:
1861 if (view)
1862 view--;
1863 break;
1865 case ACTION_STD_NEXT:
1866 if (view < 3)
1867 view++;
1868 break;
1870 case ACTION_STD_CANCEL:
1871 lcd_setfont(FONT_UI);
1872 return false;
1875 lcd_setfont(FONT_UI);
1876 return false;
1879 #endif /* HAVE_LCD_BITMAP */
1880 #endif
1882 #ifndef SIMULATOR
1883 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1885 #if (CONFIG_STORAGE & STORAGE_MMC)
1886 #define CARDTYPE "MMC"
1887 #elif (CONFIG_STORAGE & STORAGE_SD)
1888 #define CARDTYPE "microSD"
1889 #endif
1891 static int disk_callback(int btn, struct gui_synclist *lists)
1893 tCardInfo *card;
1894 int *cardnum = (int*)lists->data;
1895 unsigned char card_name[7];
1896 unsigned char pbuf[32];
1897 char *title = lists->title;
1898 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1899 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1900 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1901 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1902 #if (CONFIG_STORAGE & STORAGE_MMC)
1903 static const char *mmc_spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1904 "3.1-3.31", "4.0" };
1905 #endif
1907 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1909 #ifdef HAVE_HOTSWAP
1910 if (btn == ACTION_STD_OK)
1912 *cardnum ^= 0x1; /* change cards */
1914 #endif
1916 simplelist_set_line_count(0);
1918 card = card_get_info(*cardnum);
1920 if (card->initialized > 0)
1922 strlcpy(card_name, ((unsigned char*)card->cid) + 3, sizeof(card_name));
1923 simplelist_addline(SIMPLELIST_ADD_LINE,
1924 "%s Rev %d.%d", card_name,
1925 (int) card_extract_bits(card->cid, 55, 4),
1926 (int) card_extract_bits(card->cid, 51, 4));
1927 simplelist_addline(SIMPLELIST_ADD_LINE,
1928 "Prod: %d/%d",
1929 #if (CONFIG_STORAGE & STORAGE_SD)
1930 (int) card_extract_bits(card->cid, 11, 3),
1931 (int) card_extract_bits(card->cid, 19, 8) + 2000
1932 #elif (CONFIG_STORAGE & STORAGE_MMC)
1933 (int) card_extract_bits(card->cid, 15, 4),
1934 (int) card_extract_bits(card->cid, 11, 4) + 1997
1935 #endif
1937 simplelist_addline(SIMPLELIST_ADD_LINE,
1938 #if (CONFIG_STORAGE & STORAGE_SD)
1939 "Ser#: 0x%08lx",
1940 card_extract_bits(card->cid, 55, 32)
1941 #elif (CONFIG_STORAGE & STORAGE_MMC)
1942 "Ser#: 0x%04lx",
1943 card_extract_bits(card->cid, 47, 16)
1944 #endif
1947 simplelist_addline(SIMPLELIST_ADD_LINE, "M=%02x, "
1948 #if (CONFIG_STORAGE & STORAGE_SD)
1949 "O=%c%c",
1950 (int) card_extract_bits(card->cid, 127, 8),
1951 card_extract_bits(card->cid, 119, 8),
1952 card_extract_bits(card->cid, 111, 8)
1953 #elif (CONFIG_STORAGE & STORAGE_MMC)
1954 "O=%04x",
1955 (int) card_extract_bits(card->cid, 127, 8),
1956 (int) card_extract_bits(card->cid, 119, 16)
1957 #endif
1960 #if (CONFIG_STORAGE & STORAGE_MMC)
1961 int temp = card_extract_bits(card->csd, 125, 4);
1962 simplelist_addline(SIMPLELIST_ADD_LINE,
1963 "MMC v%s", temp < 5 ?
1964 mmc_spec_vers[temp] : "?.?");
1965 #endif
1966 simplelist_addline(SIMPLELIST_ADD_LINE,
1967 "Blocks: 0x%08lx", card->numblocks);
1968 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1969 kbit_units, false);
1970 simplelist_addline(SIMPLELIST_ADD_LINE,
1971 "Speed: %s", pbuf);
1972 output_dyn_value(pbuf, sizeof pbuf, card->taac,
1973 nsec_units, false);
1974 simplelist_addline(SIMPLELIST_ADD_LINE,
1975 "Taac: %s", pbuf);
1976 simplelist_addline(SIMPLELIST_ADD_LINE,
1977 "Nsac: %d clk", card->nsac);
1978 simplelist_addline(SIMPLELIST_ADD_LINE,
1979 "R2W: *%d", card->r2w_factor);
1980 simplelist_addline(SIMPLELIST_ADD_LINE,
1981 "IRmax: %d..%d mA",
1982 i_vmin[card_extract_bits(card->csd, 61, 3)],
1983 i_vmax[card_extract_bits(card->csd, 58, 3)]);
1984 simplelist_addline(SIMPLELIST_ADD_LINE,
1985 "IWmax: %d..%d mA",
1986 i_vmin[card_extract_bits(card->csd, 55, 3)],
1987 i_vmax[card_extract_bits(card->csd, 52, 3)]);
1989 else if (card->initialized == 0)
1991 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1993 #if (CONFIG_STORAGE & STORAGE_SD)
1994 else /* card->initialized < 0 */
1996 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1998 #endif
1999 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
2000 gui_synclist_set_title(lists, title, Icon_NOICON);
2001 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
2002 gui_synclist_select_item(lists, 0);
2003 btn = ACTION_REDRAW;
2005 return btn;
2007 #elif (CONFIG_STORAGE & STORAGE_ATA)
2008 static int disk_callback(int btn, struct gui_synclist *lists)
2010 (void)lists;
2011 int i;
2012 char buf[128];
2013 unsigned short* identify_info = ata_get_identify();
2014 bool timing_info_present = false;
2015 (void)btn;
2017 simplelist_set_line_count(0);
2019 for (i=0; i < 20; i++)
2020 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
2021 buf[40]=0;
2022 /* kill trailing space */
2023 for (i=39; i && buf[i]==' '; i--)
2024 buf[i] = 0;
2025 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
2026 for (i=0; i < 4; i++)
2027 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
2028 buf[8]=0;
2029 simplelist_addline(SIMPLELIST_ADD_LINE,
2030 "Firmware: %s", buf);
2031 snprintf(buf, sizeof buf, "%ld MB",
2032 ((unsigned long)identify_info[61] << 16 |
2033 (unsigned long)identify_info[60]) / 2048 );
2034 simplelist_addline(SIMPLELIST_ADD_LINE,
2035 "Size: %s", buf);
2036 unsigned long free;
2037 fat_size( IF_MV2(0,) NULL, &free );
2038 simplelist_addline(SIMPLELIST_ADD_LINE,
2039 "Free: %ld MB", free / 1024);
2040 simplelist_addline(SIMPLELIST_ADD_LINE,
2041 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
2042 i = identify_info[83] & (1<<3);
2043 simplelist_addline(SIMPLELIST_ADD_LINE,
2044 "Power mgmt: %s", i ? "enabled" : "unsupported");
2045 i = identify_info[83] & (1<<9);
2046 simplelist_addline(SIMPLELIST_ADD_LINE,
2047 "Noise mgmt: %s", i ? "enabled" : "unsupported");
2048 i = identify_info[82] & (1<<6);
2049 simplelist_addline(SIMPLELIST_ADD_LINE,
2050 "Read-ahead: %s", i ? "enabled" : "unsupported");
2051 timing_info_present = identify_info[53] & (1<<1);
2052 if(timing_info_present) {
2053 char pio3[2], pio4[2];pio3[1] = 0;
2054 pio4[1] = 0;
2055 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
2056 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
2057 simplelist_addline(SIMPLELIST_ADD_LINE,
2058 "PIO modes: 0 1 2 %s %s", pio3, pio4);
2060 else {
2061 simplelist_addline(SIMPLELIST_ADD_LINE,
2062 "No PIO mode info");
2064 timing_info_present = identify_info[53] & (1<<1);
2065 if(timing_info_present) {
2066 simplelist_addline(SIMPLELIST_ADD_LINE,
2067 "Cycle times %dns/%dns",
2068 identify_info[67],
2069 identify_info[68] );
2070 } else {
2071 simplelist_addline(SIMPLELIST_ADD_LINE,
2072 "No timing info");
2074 #ifdef HAVE_ATA_DMA
2075 if (identify_info[63] & (1<<0)) {
2076 char mdma0[2], mdma1[2], mdma2[2];
2077 mdma0[1] = mdma1[1] = mdma2[1] = 0;
2078 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
2079 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
2080 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
2081 simplelist_addline(SIMPLELIST_ADD_LINE,
2082 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
2083 simplelist_addline(SIMPLELIST_ADD_LINE,
2084 "MDMA Cycle times %dns/%dns",
2085 identify_info[65],
2086 identify_info[66] );
2088 else {
2089 simplelist_addline(SIMPLELIST_ADD_LINE,
2090 "No MDMA mode info");
2092 if (identify_info[53] & (1<<2)) {
2093 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2], udma6[2];
2094 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = udma6[1] = 0;
2095 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
2096 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
2097 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
2098 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
2099 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
2100 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
2101 udma6[0] = (identify_info[88] & (1<<6)) ? '6' : 0;
2102 simplelist_addline(SIMPLELIST_ADD_LINE,
2103 "UDMA modes: %s %s %s %s %s %s %s", udma0, udma1, udma2,
2104 udma3, udma4, udma5, udma6);
2106 else {
2107 simplelist_addline(SIMPLELIST_ADD_LINE,
2108 "No UDMA mode info");
2110 #endif /* HAVE_ATA_DMA */
2111 timing_info_present = identify_info[53] & (1<<1);
2112 if(timing_info_present) {
2113 i = identify_info[49] & (1<<11);
2114 simplelist_addline(SIMPLELIST_ADD_LINE,
2115 "IORDY support: %s", i ? "yes" : "no");
2116 i = identify_info[49] & (1<<10);
2117 simplelist_addline(SIMPLELIST_ADD_LINE,
2118 "IORDY disable: %s", i ? "yes" : "no");
2119 } else {
2120 simplelist_addline(SIMPLELIST_ADD_LINE,
2121 "No timing info");
2123 simplelist_addline(SIMPLELIST_ADD_LINE,
2124 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2125 #ifdef HAVE_ATA_DMA
2126 i = ata_get_dma_mode();
2127 if (i == 0) {
2128 simplelist_addline(SIMPLELIST_ADD_LINE,
2129 "DMA not enabled");
2130 } else {
2131 simplelist_addline(SIMPLELIST_ADD_LINE,
2132 "DMA mode: %s %c",
2133 (i & 0x40) ? "UDMA" : "MDMA",
2134 '0' + (i & 7));
2136 #endif /* HAVE_ATA_DMA */
2137 return btn;
2139 #else /* No SD, MMC or ATA */
2140 static int disk_callback(int btn, struct gui_synclist *lists)
2142 (void)btn;
2143 (void)lists;
2144 struct storage_info info;
2145 storage_get_info(0,&info);
2146 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
2147 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
2148 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
2149 simplelist_addline(SIMPLELIST_ADD_LINE,
2150 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
2151 unsigned long free;
2152 fat_size( IF_MV2(0,) NULL, &free );
2153 simplelist_addline(SIMPLELIST_ADD_LINE,
2154 "Free: %ld MB", free / 1024);
2155 simplelist_addline(SIMPLELIST_ADD_LINE,
2156 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2157 return btn;
2159 #endif
2161 #if (CONFIG_STORAGE & STORAGE_ATA)
2162 static bool dbg_identify_info(void)
2164 int fd = creat("/identify_info.bin");
2165 if(fd >= 0)
2167 #ifdef ROCKBOX_LITTLE_ENDIAN
2168 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
2169 #else
2170 write(fd, ata_get_identify(), SECTOR_SIZE);
2171 #endif
2172 close(fd);
2174 return false;
2176 #endif
2178 static bool dbg_disk_info(void)
2180 struct simplelist_info info;
2181 simplelist_info_init(&info, "Disk Info", 1, NULL);
2182 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
2183 char title[16];
2184 int card = 0;
2185 info.callback_data = (void*)&card;
2186 info.title = title;
2187 #endif
2188 info.action_callback = disk_callback;
2189 info.hide_selection = true;
2190 info.scroll_all = true;
2191 return simplelist_show_list(&info);
2193 #endif /* !SIMULATOR */
2195 #ifdef HAVE_DIRCACHE
2196 static int dircache_callback(int btn, struct gui_synclist *lists)
2198 (void)btn; (void)lists;
2199 simplelist_set_line_count(0);
2200 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
2201 dircache_is_enabled() ? "Yes" : "No");
2202 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
2203 dircache_get_cache_size());
2204 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
2205 global_status.dircache_size);
2206 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
2207 DIRCACHE_LIMIT);
2208 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
2209 dircache_get_reserve_used(), DIRCACHE_RESERVE);
2210 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2211 dircache_get_build_ticks() / HZ);
2212 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2213 dircache_get_entry_count());
2214 return btn;
2217 static bool dbg_dircache_info(void)
2219 struct simplelist_info info;
2220 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2221 info.action_callback = dircache_callback;
2222 info.hide_selection = true;
2223 info.scroll_all = true;
2224 return simplelist_show_list(&info);
2227 #endif /* HAVE_DIRCACHE */
2229 #ifdef HAVE_TAGCACHE
2230 static int database_callback(int btn, struct gui_synclist *lists)
2232 (void)lists;
2233 struct tagcache_stat *stat = tagcache_get_stat();
2234 static bool synced = false;
2236 simplelist_set_line_count(0);
2238 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2239 stat->initialized ? "Yes" : "No");
2240 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2241 stat->ready ? "Yes" : "No");
2242 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2243 stat->ramcache ? "Yes" : "No");
2244 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2245 stat->ramcache_used, stat->ramcache_allocated);
2246 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2247 stat->progress, stat->processed_entries);
2248 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2249 stat->curentry ? stat->curentry : "---");
2250 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2251 stat->commit_step);
2252 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2253 stat->commit_delayed ? "Yes" : "No");
2255 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2256 stat->queue_length);
2258 if (synced)
2260 synced = false;
2261 tagcache_screensync_event();
2264 if (!btn && stat->curentry)
2266 synced = true;
2267 return ACTION_REDRAW;
2270 if (btn == ACTION_STD_CANCEL)
2271 tagcache_screensync_enable(false);
2273 return btn;
2275 static bool dbg_tagcache_info(void)
2277 struct simplelist_info info;
2278 simplelist_info_init(&info, "Database Info", 8, NULL);
2279 info.action_callback = database_callback;
2280 info.hide_selection = true;
2281 info.scroll_all = true;
2283 /* Don't do nonblock here, must give enough processing time
2284 for tagcache thread. */
2285 /* info.timeout = TIMEOUT_NOBLOCK; */
2286 info.timeout = 1;
2287 tagcache_screensync_enable(true);
2288 return simplelist_show_list(&info);
2290 #endif
2292 #if CONFIG_CPU == SH7034
2293 static bool dbg_save_roms(void)
2295 int fd;
2296 int oldmode = system_memory_guard(MEMGUARD_NONE);
2298 fd = creat("/internal_rom_0000-FFFF.bin");
2299 if(fd >= 0)
2301 write(fd, (void *)0, 0x10000);
2302 close(fd);
2305 fd = creat("/internal_rom_2000000-203FFFF.bin");
2306 if(fd >= 0)
2308 write(fd, (void *)0x2000000, 0x40000);
2309 close(fd);
2312 system_memory_guard(oldmode);
2313 return false;
2315 #elif defined CPU_COLDFIRE
2316 static bool dbg_save_roms(void)
2318 int fd;
2319 int oldmode = system_memory_guard(MEMGUARD_NONE);
2321 #if defined(IRIVER_H100_SERIES)
2322 fd = creat("/internal_rom_000000-1FFFFF.bin");
2323 #elif defined(IRIVER_H300_SERIES)
2324 fd = creat("/internal_rom_000000-3FFFFF.bin");
2325 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2326 fd = creat("/internal_rom_000000-3FFFFF.bin");
2327 #endif
2328 if(fd >= 0)
2330 write(fd, (void *)0, FLASH_SIZE);
2331 close(fd);
2333 system_memory_guard(oldmode);
2335 #ifdef HAVE_EEPROM
2336 fd = creat("/internal_eeprom.bin");
2337 if (fd >= 0)
2339 int old_irq_level;
2340 char buf[EEPROM_SIZE];
2341 int err;
2343 old_irq_level = disable_irq_save();
2345 err = eeprom_24cxx_read(0, buf, sizeof buf);
2347 restore_irq(old_irq_level);
2349 if (err)
2350 splashf(HZ*3, "Eeprom read failure (%d)", err);
2351 else
2353 write(fd, buf, sizeof buf);
2356 close(fd);
2358 #endif
2360 return false;
2362 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
2363 static bool dbg_save_roms(void)
2365 int fd;
2367 fd = creat("/internal_rom_000000-0FFFFF.bin");
2368 if(fd >= 0)
2370 write(fd, (void *)0x20000000, FLASH_SIZE);
2371 close(fd);
2374 return false;
2376 #endif /* CPU */
2378 #ifndef SIMULATOR
2379 #if CONFIG_TUNER
2380 static int radio_callback(int btn, struct gui_synclist *lists)
2382 (void)lists;
2383 if (btn == ACTION_STD_CANCEL)
2384 return btn;
2385 simplelist_set_line_count(1);
2387 #if (CONFIG_TUNER & LV24020LP)
2388 simplelist_addline(SIMPLELIST_ADD_LINE,
2389 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2390 simplelist_addline(SIMPLELIST_ADD_LINE,
2391 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2392 simplelist_addline(SIMPLELIST_ADD_LINE,
2393 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2394 simplelist_addline(SIMPLELIST_ADD_LINE,
2395 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2396 simplelist_addline(SIMPLELIST_ADD_LINE,
2397 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2398 simplelist_addline(SIMPLELIST_ADD_LINE,
2399 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2400 simplelist_addline(SIMPLELIST_ADD_LINE,
2401 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2402 #endif /* LV24020LP */
2403 #if (CONFIG_TUNER & S1A0903X01)
2404 simplelist_addline(SIMPLELIST_ADD_LINE,
2405 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2406 /* This one doesn't return dynamic data atm */
2407 #endif /* S1A0903X01 */
2408 #if (CONFIG_TUNER & TEA5767)
2409 struct tea5767_dbg_info nfo;
2410 tea5767_dbg_info(&nfo);
2411 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2412 simplelist_addline(SIMPLELIST_ADD_LINE,
2413 " Read: %02X %02X %02X %02X %02X",
2414 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2415 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2416 (unsigned)nfo.read_regs[4]);
2417 simplelist_addline(SIMPLELIST_ADD_LINE,
2418 " Write: %02X %02X %02X %02X %02X",
2419 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2420 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2421 (unsigned)nfo.write_regs[4]);
2422 #endif /* TEA5767 */
2423 #if (CONFIG_TUNER & SI4700)
2424 struct si4700_dbg_info nfo;
2425 si4700_dbg_info(&nfo);
2426 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
2427 /* Registers */
2428 simplelist_addline(SIMPLELIST_ADD_LINE,
2429 "%04X %04X %04X %04X",
2430 (unsigned)nfo.regs[0], (unsigned)nfo.regs[1],
2431 (unsigned)nfo.regs[2], (unsigned)nfo.regs[3]);
2432 simplelist_addline(SIMPLELIST_ADD_LINE,
2433 "%04X %04X %04X %04X",
2434 (unsigned)nfo.regs[4], (unsigned)nfo.regs[5],
2435 (unsigned)nfo.regs[6], (unsigned)nfo.regs[7]);
2436 simplelist_addline(SIMPLELIST_ADD_LINE,
2437 "%04X %04X %04X %04X",
2438 (unsigned)nfo.regs[8], (unsigned)nfo.regs[9],
2439 (unsigned)nfo.regs[10], (unsigned)nfo.regs[11]);
2440 simplelist_addline(SIMPLELIST_ADD_LINE,
2441 "%04X %04X %04X %04X",
2442 (unsigned)nfo.regs[12], (unsigned)nfo.regs[13],
2443 (unsigned)nfo.regs[14], (unsigned)nfo.regs[15]);
2444 #endif /* SI4700 */
2445 return ACTION_REDRAW;
2447 static bool dbg_fm_radio(void)
2449 struct simplelist_info info;
2450 info.scroll_all = true;
2451 simplelist_info_init(&info, "FM Radio", 1, NULL);
2452 simplelist_set_line_count(0);
2453 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2454 radio_hardware_present() ? "yes" : "no");
2456 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2457 info.hide_selection = true;
2458 return simplelist_show_list(&info);
2460 #endif /* CONFIG_TUNER */
2461 #endif /* !SIMULATOR */
2463 #ifdef HAVE_LCD_BITMAP
2464 extern bool do_screendump_instead_of_usb;
2466 static bool dbg_screendump(void)
2468 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2469 splashf(HZ, "Screendump %s",
2470 do_screendump_instead_of_usb?"enabled":"disabled");
2471 return false;
2473 #endif /* HAVE_LCD_BITMAP */
2475 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2476 static bool dbg_set_memory_guard(void)
2478 static const struct opt_items names[MAXMEMGUARD] = {
2479 { "None", -1 },
2480 { "Flash ROM writes", -1 },
2481 { "Zero area (all)", -1 }
2483 int mode = system_memory_guard(MEMGUARD_KEEP);
2485 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2486 system_memory_guard(mode);
2488 return false;
2490 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2492 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2493 static bool dbg_write_eeprom(void)
2495 int fd;
2496 int rc;
2497 int old_irq_level;
2498 char buf[EEPROM_SIZE];
2499 int err;
2501 fd = open("/internal_eeprom.bin", O_RDONLY);
2503 if (fd >= 0)
2505 rc = read(fd, buf, EEPROM_SIZE);
2507 if(rc == EEPROM_SIZE)
2509 old_irq_level = disable_irq_save();
2511 err = eeprom_24cxx_write(0, buf, sizeof buf);
2512 if (err)
2513 splashf(HZ*3, "Eeprom write failure (%d)", err);
2514 else
2515 splash(HZ*3, "Eeprom written successfully");
2517 restore_irq(old_irq_level);
2519 else
2521 splashf(HZ*3, "File read error (%d)",rc);
2523 close(fd);
2525 else
2527 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2530 return false;
2532 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2533 #ifdef CPU_BOOST_LOGGING
2534 static bool cpu_boost_log(void)
2536 int i = 0,j=0;
2537 int count = cpu_boost_log_getcount();
2538 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2539 char *str;
2540 bool done;
2541 lcd_setfont(FONT_SYSFIXED);
2542 str = cpu_boost_log_getlog_first();
2543 while (i < count)
2545 lcd_clear_display();
2546 for(j=0; j<lines; j++,i++)
2548 if (!str)
2549 str = cpu_boost_log_getlog_next();
2550 if (str)
2552 if(strlen(str) > LCD_WIDTH/SYSFONT_WIDTH)
2553 lcd_puts_scroll(0, j, str);
2554 else
2555 lcd_puts(0, j,str);
2557 str = NULL;
2559 lcd_update();
2560 done = false;
2561 while (!done)
2563 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2565 case ACTION_STD_OK:
2566 case ACTION_STD_PREV:
2567 case ACTION_STD_NEXT:
2568 done = true;
2569 break;
2570 case ACTION_STD_CANCEL:
2571 i = count;
2572 done = true;
2573 break;
2577 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2578 lcd_setfont(FONT_UI);
2579 return false;
2581 #endif
2583 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2584 extern bool wheel_is_touched;
2585 extern int old_wheel_value;
2586 extern int new_wheel_value;
2587 extern int wheel_delta;
2588 extern unsigned int accumulated_wheel_delta;
2589 extern unsigned int wheel_velocity;
2591 static bool dbg_scrollwheel(void)
2593 char buf[64];
2594 unsigned int speed;
2596 lcd_setfont(FONT_SYSFIXED);
2598 while (1)
2600 if (action_userabort(HZ/10))
2601 break;
2603 lcd_clear_display();
2605 /* show internal variables of scrollwheel driver */
2606 snprintf(buf, sizeof(buf), "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2607 lcd_puts(0, 0, buf);
2608 snprintf(buf, sizeof(buf), "new position: %2d", new_wheel_value);
2609 lcd_puts(0, 1, buf);
2610 snprintf(buf, sizeof(buf), "old position: %2d", old_wheel_value);
2611 lcd_puts(0, 2, buf);
2612 snprintf(buf, sizeof(buf), "wheel delta: %2d", wheel_delta);
2613 lcd_puts(0, 3, buf);
2614 snprintf(buf, sizeof(buf), "accumulated delta: %2d", accumulated_wheel_delta);
2615 lcd_puts(0, 4, buf);
2616 snprintf(buf, sizeof(buf), "velo [deg/s]: %4d", (int)wheel_velocity);
2617 lcd_puts(0, 5, buf);
2619 /* show effective accelerated scrollspeed */
2620 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2621 snprintf(buf, sizeof(buf), "accel. speed: %4d", speed);
2622 lcd_puts(0, 6, buf);
2624 lcd_update();
2626 lcd_setfont(FONT_UI);
2627 return false;
2629 #endif
2631 #if defined (HAVE_USBSTACK)
2633 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2634 static bool toggle_usb_core_driver(int driver, char *msg)
2636 bool enabled = !usb_core_driver_enabled(driver);
2638 usb_core_enable_driver(driver,enabled);
2639 splashf(HZ, "%s %s", msg, enabled?"enabled":"disabled");
2641 return false;
2644 static bool toggle_usb_serial(void)
2646 return toggle_usb_core_driver(USB_DRIVER_SERIAL,"USB Serial");
2648 #endif
2650 #endif
2652 #if CONFIG_USBOTG == USBOTG_ISP1583
2653 extern int dbg_usb_num_items(void);
2654 extern const char* dbg_usb_item(int selected_item, void *data,
2655 char *buffer, size_t buffer_len);
2657 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2659 (void)lists;
2660 if (action == ACTION_NONE)
2661 action = ACTION_REDRAW;
2662 return action;
2665 static bool dbg_isp1583(void)
2667 struct simplelist_info isp1583;
2668 isp1583.scroll_all = true;
2669 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2670 isp1583.timeout = HZ/100;
2671 isp1583.hide_selection = true;
2672 isp1583.get_name = dbg_usb_item;
2673 isp1583.action_callback = isp1583_action_callback;
2674 return simplelist_show_list(&isp1583);
2676 #endif
2678 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2679 extern int pic_dbg_num_items(void);
2680 extern const char* pic_dbg_item(int selected_item, void *data,
2681 char *buffer, size_t buffer_len);
2683 static int pic_action_callback(int action, struct gui_synclist *lists)
2685 (void)lists;
2686 if (action == ACTION_NONE)
2687 action = ACTION_REDRAW;
2688 return action;
2691 static bool dbg_pic(void)
2693 struct simplelist_info pic;
2694 pic.scroll_all = true;
2695 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2696 pic.timeout = HZ/100;
2697 pic.hide_selection = true;
2698 pic.get_name = pic_dbg_item;
2699 pic.action_callback = pic_action_callback;
2700 return simplelist_show_list(&pic);
2702 #endif
2705 /****** The menu *********/
2706 struct the_menu_item {
2707 unsigned char *desc; /* string or ID */
2708 bool (*function) (void); /* return true if USB was connected */
2710 static const struct the_menu_item menuitems[] = {
2711 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2712 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD))
2713 { "Dump ROM contents", dbg_save_roms },
2714 #endif
2715 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2716 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 \
2717 || CONFIG_CPU == DM320 || defined(CPU_S5L870X)
2718 { "View I/O ports", dbg_ports },
2719 #endif
2720 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2721 { "View PCF registers", dbg_pcf },
2722 #endif
2723 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2724 { "TSC2100 debug", tsc2100_debug },
2725 #endif
2726 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2727 { "CPU frequency", dbg_cpufreq },
2728 #endif
2729 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2730 { "S/PDIF analyzer", dbg_spdif },
2731 #endif
2732 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2733 { "Catch mem accesses", dbg_set_memory_guard },
2734 #endif
2735 { "View OS stacks", dbg_os },
2736 #ifdef HAVE_LCD_BITMAP
2737 #ifndef SIMULATOR
2738 { "View battery", view_battery },
2739 #endif
2740 { "Screendump", dbg_screendump },
2741 #endif
2742 #ifndef SIMULATOR
2743 { "View HW info", dbg_hw_info },
2744 #endif
2745 #ifndef SIMULATOR
2746 { "View partitions", dbg_partitions },
2747 #endif
2748 #ifndef SIMULATOR
2749 { "View disk info", dbg_disk_info },
2750 #if (CONFIG_STORAGE & STORAGE_ATA)
2751 { "Dump ATA identify info", dbg_identify_info},
2752 #endif
2753 #endif
2754 #ifdef HAVE_DIRCACHE
2755 { "View dircache info", dbg_dircache_info },
2756 #endif
2757 #ifdef HAVE_TAGCACHE
2758 { "View database info", dbg_tagcache_info },
2759 #endif
2760 #ifdef HAVE_LCD_BITMAP
2761 #if CONFIG_CODEC == SWCODEC
2762 { "View buffering thread", dbg_buffering_thread },
2763 #elif !defined(SIMULATOR)
2764 { "View audio thread", dbg_audio_thread },
2765 #endif
2766 #ifdef PM_DEBUG
2767 { "pm histogram", peak_meter_histogram},
2768 #endif /* PM_DEBUG */
2769 #endif /* HAVE_LCD_BITMAP */
2770 #ifndef SIMULATOR
2771 #if CONFIG_TUNER
2772 { "FM Radio", dbg_fm_radio },
2773 #endif
2774 #endif
2775 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2776 { "Write back EEPROM", dbg_write_eeprom },
2777 #endif
2778 #if CONFIG_USBOTG == USBOTG_ISP1583
2779 { "View ISP1583 info", dbg_isp1583 },
2780 #endif
2781 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2782 { "View PIC info", dbg_pic },
2783 #endif
2784 #ifdef ROCKBOX_HAS_LOGF
2785 {"logf", logfdisplay },
2786 {"logfdump", logfdump },
2787 #endif
2788 #if defined(HAVE_USBSTACK)
2789 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2790 {"USB Serial driver (logf)", toggle_usb_serial },
2791 #endif
2792 #endif /* HAVE_USBSTACK */
2793 #ifdef CPU_BOOST_LOGGING
2794 {"cpu_boost log",cpu_boost_log},
2795 #endif
2796 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2797 {"Debug scrollwheel", dbg_scrollwheel },
2798 #endif
2800 static int menu_action_callback(int btn, struct gui_synclist *lists)
2802 if (btn == ACTION_STD_OK)
2804 int oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL);
2805 menuitems[gui_synclist_get_sel_pos(lists)].function();
2806 btn = ACTION_REDRAW;
2807 send_event(GUI_EVENT_REFRESH, NULL);
2808 viewportmanager_set_statusbar(oldbars);
2810 return btn;
2813 static const char* dbg_menu_getname(int item, void * data,
2814 char *buffer, size_t buffer_len)
2816 (void)data; (void)buffer; (void)buffer_len;
2817 return menuitems[item].desc;
2820 bool debug_menu(void)
2822 struct simplelist_info info;
2824 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2825 info.action_callback = menu_action_callback;
2826 info.get_name = dbg_menu_getname;
2827 return simplelist_show_list(&info);