Fix yellows (the reds on mono are caused by this, again, stupid typo).
[kugel-rb/myfork.git] / apps / debug_menu.c
bloba4a399d61687f6a059eec4e58a08004f169a7b11
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 || CONFIG_CPU == JZ4732
106 #include "debug-target.h"
107 #endif
109 #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) \
110 || defined(SANSA_CLIP) || defined(SANSA_FUZE)
111 #include "ascodec.h"
112 #include "as3514.h"
113 #endif
115 #ifdef HAVE_USBSTACK
116 #include "usb_core.h"
117 #endif
119 /*---------------------------------------------------*/
120 /* SPECIAL DEBUG STUFF */
121 /*---------------------------------------------------*/
122 extern struct thread_entry threads[MAXTHREADS];
124 static char thread_status_char(unsigned status)
126 static const char thread_status_chars[THREAD_NUM_STATES+1] =
128 [0 ... THREAD_NUM_STATES] = '?',
129 [STATE_RUNNING] = 'R',
130 [STATE_BLOCKED] = 'B',
131 [STATE_SLEEPING] = 'S',
132 [STATE_BLOCKED_W_TMO] = 'T',
133 [STATE_FROZEN] = 'F',
134 [STATE_KILLED] = 'K',
137 if (status > THREAD_NUM_STATES)
138 status = THREAD_NUM_STATES;
140 return thread_status_chars[status];
143 static char* threads_getname(int selected_item, void *data,
144 char *buffer, size_t buffer_len)
146 (void)data;
147 struct thread_entry *thread;
148 char name[32];
150 #if NUM_CORES > 1
151 if (selected_item < (int)NUM_CORES)
153 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
154 idle_stack_usage(selected_item));
155 return buffer;
158 selected_item -= NUM_CORES;
159 #endif
161 thread = &threads[selected_item];
163 if (thread->state == STATE_KILLED)
165 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
166 return buffer;
169 thread_get_name(name, 32, thread);
171 snprintf(buffer, buffer_len,
172 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
173 selected_item,
174 IF_COP(thread->core,)
175 #ifdef HAVE_SCHEDULER_BOOSTCTRL
176 (thread->cpu_boost) ? '+' :
177 #endif
178 ((thread->state == STATE_RUNNING) ? '*' : ' '),
179 thread_status_char(thread->state),
180 IF_PRIO(thread->base_priority, thread->priority, )
181 thread_stack_usage(thread), name);
183 return buffer;
185 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
187 (void)lists;
188 #ifdef ROCKBOX_HAS_LOGF
189 if (action == ACTION_STD_OK)
191 int selpos = gui_synclist_get_sel_pos(lists);
192 #if NUM_CORES > 1
193 if (selpos >= NUM_CORES)
194 remove_thread(threads[selpos - NUM_CORES].id);
195 #else
196 remove_thread(threads[selpos].id);
197 #endif
198 return ACTION_REDRAW;
200 #endif /* ROCKBOX_HAS_LOGF */
201 if (action == ACTION_NONE)
202 action = ACTION_REDRAW;
203 return action;
205 /* Test code!!! */
206 static bool dbg_os(void)
208 struct simplelist_info info;
209 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
210 #if NUM_CORES == 1
211 MAXTHREADS,
212 #else
213 MAXTHREADS+NUM_CORES,
214 #endif
215 NULL);
216 #ifndef ROCKBOX_HAS_LOGF
217 info.hide_selection = true;
218 info.scroll_all = true;
219 #endif
220 info.action_callback = dbg_threads_action_callback;
221 info.get_name = threads_getname;
222 return simplelist_show_list(&info);
225 #ifdef HAVE_LCD_BITMAP
226 #if CONFIG_CODEC != SWCODEC
227 #ifndef SIMULATOR
228 static bool dbg_audio_thread(void)
230 char buf[32];
231 struct audio_debug d;
233 lcd_setfont(FONT_SYSFIXED);
235 while(1)
237 if (action_userabort(HZ/5))
238 return false;
240 audio_get_debugdata(&d);
242 lcd_clear_display();
244 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
245 lcd_puts(0, 0, buf);
246 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
247 lcd_puts(0, 1, buf);
248 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
249 lcd_puts(0, 2, buf);
250 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
251 lcd_puts(0, 3, buf);
252 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
253 lcd_puts(0, 4, buf);
254 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
255 lcd_puts(0, 5, buf);
257 /* Playable space left */
258 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
259 d.playable_space, HORIZONTAL);
261 /* Show the watermark limit */
262 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
263 d.low_watermark_level, HORIZONTAL);
265 snprintf(buf, sizeof(buf), "wm: %x - %x",
266 d.low_watermark_level, d.lowest_watermark_level);
267 lcd_puts(0, 7, buf);
269 lcd_update();
271 lcd_setfont(FONT_UI);
272 return false;
274 #endif /* !SIMULATOR */
275 #else /* CONFIG_CODEC == SWCODEC */
276 extern size_t filebuflen;
277 /* This is a size_t, but call it a long so it puts a - when it's bad. */
279 static unsigned int ticks, boost_ticks, freq_sum;
281 static void dbg_audio_task(void)
283 #ifndef SIMULATOR
284 if(FREQ > CPUFREQ_NORMAL)
285 boost_ticks++;
286 freq_sum += FREQ/1000000; /* in MHz */
287 #endif
288 ticks++;
291 static bool dbg_buffering_thread(void)
293 char buf[32];
294 int button;
295 int line;
296 bool done = false;
297 size_t bufused;
298 size_t bufsize = pcmbuf_get_bufsize();
299 int pcmbufdescs = pcmbuf_descs();
300 struct buffering_debug d;
302 ticks = boost_ticks = freq_sum = 0;
304 tick_add_task(dbg_audio_task);
306 lcd_setfont(FONT_SYSFIXED);
307 while(!done)
309 button = get_action(CONTEXT_STD,HZ/5);
310 switch(button)
312 case ACTION_STD_NEXT:
313 audio_next();
314 break;
315 case ACTION_STD_PREV:
316 audio_prev();
317 break;
318 case ACTION_STD_CANCEL:
319 done = true;
320 break;
323 buffering_get_debugdata(&d);
325 line = 0;
326 lcd_clear_display();
328 bufused = bufsize - pcmbuf_free();
330 snprintf(buf, sizeof(buf), "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
331 lcd_puts(0, line++, buf);
333 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
334 bufsize, 0, bufused, HORIZONTAL);
335 line++;
337 snprintf(buf, sizeof(buf), "alloc: %6ld/%ld", audio_filebufused(),
338 (long) filebuflen);
339 lcd_puts(0, line++, buf);
341 #if LCD_HEIGHT > 80
342 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
343 filebuflen, 0, audio_filebufused(), HORIZONTAL);
344 line++;
346 snprintf(buf, sizeof(buf), "real: %6ld/%ld", (long)d.buffered_data,
347 (long)filebuflen);
348 lcd_puts(0, line++, buf);
350 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
351 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
352 line++;
353 #endif
355 snprintf(buf, sizeof(buf), "usefl: %6ld/%ld", (long)(d.useful_data),
356 (long)filebuflen);
357 lcd_puts(0, line++, buf);
359 #if LCD_HEIGHT > 80
360 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
361 filebuflen, 0, d.useful_data, HORIZONTAL);
362 line++;
363 #endif
365 snprintf(buf, sizeof(buf), "data_rem: %ld", (long)d.data_rem);
366 lcd_puts(0, line++, buf);
368 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
369 lcd_puts(0, line++, buf);
371 snprintf(buf, sizeof(buf), "handle count: %d", (int)d.num_handles);
372 lcd_puts(0, line++, buf);
374 #ifndef SIMULATOR
375 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
376 (int)((FREQ + 500000) / 1000000));
377 lcd_puts(0, line++, buf);
378 #endif
380 if (ticks > 0)
382 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
383 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
384 snprintf(buf, sizeof(buf), "boost:%3d.%d%% (%d.%dMHz)",
385 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
386 lcd_puts(0, line++, buf);
389 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
390 pcmbuf_used_descs(), pcmbufdescs);
391 lcd_puts(0, line++, buf);
392 snprintf(buf, sizeof(buf), "watermark: %6d",
393 (int)(d.watermark));
394 lcd_puts(0, line++, buf);
396 lcd_update();
399 tick_remove_task(dbg_audio_task);
400 lcd_setfont(FONT_UI);
402 return false;
404 #endif /* CONFIG_CODEC */
405 #endif /* HAVE_LCD_BITMAP */
408 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
409 /* Tool function to read the flash manufacturer and type, if available.
410 Only chips which could be reprogrammed in system will return values.
411 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
412 /* In IRAM to avoid problems when running directly from Flash */
413 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
414 unsigned addr1, unsigned addr2)
415 ICODE_ATTR __attribute__((noinline));
416 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
417 unsigned addr1, unsigned addr2)
420 unsigned not_manu, not_id; /* read values before switching to ID mode */
421 unsigned manu, id; /* read values when in ID mode */
423 #if CONFIG_CPU == SH7034
424 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
425 #elif defined(CPU_COLDFIRE)
426 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
427 #endif
428 int old_level; /* saved interrupt level */
430 not_manu = flash[0]; /* read the normal content */
431 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
433 /* disable interrupts, prevent any stray flash access */
434 old_level = disable_irq_save();
436 flash[addr1] = 0xAA; /* enter command mode */
437 flash[addr2] = 0x55;
438 flash[addr1] = 0x90; /* ID command */
439 /* Atmel wants 20ms pause here */
440 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
442 manu = flash[0]; /* read the IDs */
443 id = flash[1];
445 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
446 /* Atmel wants 20ms pause here */
447 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
449 restore_irq(old_level); /* enable interrupts again */
451 /* I assume success if the obtained values are different from
452 the normal flash content. This is not perfectly bulletproof, they
453 could theoretically be the same by chance, causing us to fail. */
454 if (not_manu != manu || not_id != id) /* a value has changed */
456 *p_manufacturer = manu; /* return the results */
457 *p_device = id;
458 return true; /* success */
460 return false; /* fail */
462 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
464 #ifndef SIMULATOR
465 #ifdef CPU_PP
466 static int perfcheck(void)
468 int result;
470 asm (
471 "mrs r2, CPSR \n"
472 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
473 "msr CPSR_c, r0 \n"
474 "mov %[res], #0 \n"
475 "ldr r0, [%[timr]] \n"
476 "add r0, r0, %[tmo] \n"
477 "1: \n"
478 "add %[res], %[res], #1 \n"
479 "ldr r1, [%[timr]] \n"
480 "cmp r1, r0 \n"
481 "bmi 1b \n"
482 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
484 [res]"=&r"(result)
486 [timr]"r"(&USEC_TIMER),
487 [tmo]"r"(
488 #if CONFIG_CPU == PP5002
489 16000
490 #else /* PP5020/5022/5024 */
491 10226
492 #endif
495 "r0", "r1", "r2"
497 return result;
499 #endif
501 #ifdef HAVE_LCD_BITMAP
502 static bool dbg_hw_info(void)
504 #if CONFIG_CPU == SH7034
505 char buf[32];
506 int bitmask = HW_MASK;
507 int rom_version = ROM_VERSION;
508 unsigned manu, id; /* flash IDs */
509 bool got_id; /* flag if we managed to get the flash IDs */
510 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
511 bool has_bootrom; /* flag for boot ROM present */
512 int oldmode; /* saved memory guard mode */
514 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
516 /* get flash ROM type */
517 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
518 if (!got_id)
519 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
521 /* check if the boot ROM area is a flash mirror */
522 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
523 if (has_bootrom) /* if ROM and Flash different */
525 /* calculate CRC16 checksum of boot ROM */
526 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
529 system_memory_guard(oldmode); /* re-enable memory guard */
531 lcd_setfont(FONT_SYSFIXED);
532 lcd_clear_display();
534 lcd_puts(0, 0, "[Hardware info]");
536 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
537 lcd_puts(0, 1, buf);
539 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
540 lcd_puts(0, 2, buf);
542 if (got_id)
543 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
544 else
545 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
546 lcd_puts(0, 3, buf);
548 if (has_bootrom)
550 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
551 snprintf(buf, 32, "Boot ROM: V1");
552 else
553 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
555 else
557 snprintf(buf, 32, "Boot ROM: none");
559 lcd_puts(0, 4, buf);
561 lcd_update();
563 while (!(action_userabort(TIMEOUT_BLOCK)));
565 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
566 char buf[32];
567 unsigned manu, id; /* flash IDs */
568 int got_id; /* flag if we managed to get the flash IDs */
569 int oldmode; /* saved memory guard mode */
570 int line = 0;
572 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
574 /* get flash ROM type */
575 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
576 if (!got_id)
577 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
579 system_memory_guard(oldmode); /* re-enable memory guard */
581 lcd_setfont(FONT_SYSFIXED);
582 lcd_clear_display();
584 lcd_puts(0, line++, "[Hardware info]");
586 if (got_id)
587 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
588 else
589 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
590 lcd_puts(0, line++, buf);
592 #ifdef IAUDIO_X5
594 struct ds2411_id id;
596 lcd_puts(0, ++line, "Serial Number:");
598 got_id = ds2411_read_id(&id);
600 if (got_id == DS2411_OK)
602 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
603 lcd_puts(0, ++line, buf);
604 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
605 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
606 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
607 lcd_puts(0, ++line, buf);
608 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
610 else
612 snprintf(buf, 32, "READ ERR=%d", got_id);
615 lcd_puts(0, ++line, buf);
617 #endif
619 lcd_update();
621 while (!(action_userabort(TIMEOUT_BLOCK)));
623 #elif defined(CPU_PP502x)
624 int line = 0;
625 char buf[32];
626 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
627 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
628 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
629 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
631 lcd_setfont(FONT_SYSFIXED);
632 lcd_clear_display();
634 lcd_puts(0, line++, "[Hardware info]");
636 #ifdef IPOD_ARCH
637 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
638 lcd_puts(0, line++, buf);
639 #endif
641 #ifdef IPOD_COLOR
642 extern int lcd_type; /* Defined in lcd-colornano.c */
644 snprintf(buf, sizeof(buf), "LCD type: %d", lcd_type);
645 lcd_puts(0, line++, buf);
646 #endif
648 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
649 lcd_puts(0, line++, buf);
651 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
652 lcd_puts(0, line++, buf);
654 lcd_update();
656 while (!(action_userabort(TIMEOUT_BLOCK)));
658 #elif CONFIG_CPU == PP5002
659 int line = 0;
660 char buf[32];
661 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
662 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
663 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
664 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
667 lcd_setfont(FONT_SYSFIXED);
668 lcd_clear_display();
670 lcd_puts(0, line++, "[Hardware info]");
672 #ifdef IPOD_ARCH
673 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
674 lcd_puts(0, line++, buf);
675 #endif
677 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
678 lcd_puts(0, line++, buf);
680 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
681 lcd_puts(0, line++, buf);
683 lcd_update();
685 while (!(action_userabort(TIMEOUT_BLOCK)));
687 #else
688 /* Define this function in your target tree */
689 return __dbg_hw_info();
690 #endif /* CONFIG_CPU */
691 lcd_setfont(FONT_UI);
692 return false;
694 #else /* !HAVE_LCD_BITMAP */
695 static bool dbg_hw_info(void)
697 char buf[32];
698 int button;
699 int currval = 0;
700 int rom_version = ROM_VERSION;
701 unsigned manu, id; /* flash IDs */
702 bool got_id; /* flag if we managed to get the flash IDs */
703 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
704 bool has_bootrom; /* flag for boot ROM present */
705 int oldmode; /* saved memory guard mode */
707 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
709 /* get flash ROM type */
710 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
711 if (!got_id)
712 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
714 /* check if the boot ROM area is a flash mirror */
715 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
716 if (has_bootrom) /* if ROM and Flash different */
718 /* calculate CRC16 checksum of boot ROM */
719 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
722 system_memory_guard(oldmode); /* re-enable memory guard */
724 lcd_clear_display();
726 lcd_puts(0, 0, "[HW Info]");
727 while(1)
729 switch(currval)
731 case 0:
732 snprintf(buf, 32, "ROM: %d.%02d",
733 rom_version/100, rom_version%100);
734 break;
735 case 1:
736 if (got_id)
737 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
738 else
739 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
740 break;
741 case 2:
742 if (has_bootrom)
744 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
745 snprintf(buf, 32, "BootROM: V1");
746 else if (rom_crc == 0x358099E8)
747 snprintf(buf, 32, "BootROM: V2");
748 /* alternative boot ROM found in one single player so far */
749 else
750 snprintf(buf, 32, "R: %08x", rom_crc);
752 else
753 snprintf(buf, 32, "BootROM: no");
756 lcd_puts(0, 1, buf);
757 lcd_update();
759 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
761 switch(button)
763 case ACTION_STD_CANCEL:
764 return false;
766 case ACTION_SETTINGS_DEC:
767 currval--;
768 if(currval < 0)
769 currval = 2;
770 break;
772 case ACTION_SETTINGS_INC:
773 currval++;
774 if(currval > 2)
775 currval = 0;
776 break;
779 return false;
781 #endif /* !HAVE_LCD_BITMAP */
782 #endif /* !SIMULATOR */
784 #ifndef SIMULATOR
785 static char* dbg_partitions_getname(int selected_item, void *data,
786 char *buffer, size_t buffer_len)
788 (void)data;
789 int partition = selected_item/2;
790 struct partinfo* p = disk_partinfo(partition);
791 if (selected_item%2)
793 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / 2048);
795 else
797 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
799 return buffer;
802 bool dbg_partitions(void)
804 struct simplelist_info info;
805 simplelist_info_init(&info, "Partition Info", 4, NULL);
806 info.selection_size = 2;
807 info.hide_selection = true;
808 info.scroll_all = true;
809 info.get_name = dbg_partitions_getname;
810 return simplelist_show_list(&info);
812 #endif
814 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
815 static bool dbg_spdif(void)
817 char buf[128];
818 int line;
819 unsigned int control;
820 int x;
821 char *s;
822 int category;
823 int generation;
824 unsigned int interruptstat;
825 bool valnogood, symbolerr, parityerr;
826 bool done = false;
827 bool spdif_src_on;
828 int spdif_source = spdif_get_output_source(&spdif_src_on);
829 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
831 lcd_clear_display();
832 lcd_setfont(FONT_SYSFIXED);
834 #ifdef HAVE_SPDIF_POWER
835 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
836 #endif
838 while (!done)
840 line = 0;
842 control = EBU1RCVCCHANNEL1;
843 interruptstat = INTERRUPTSTAT;
844 INTERRUPTCLEAR = 0x03c00000;
846 valnogood = (interruptstat & 0x01000000)?true:false;
847 symbolerr = (interruptstat & 0x00800000)?true:false;
848 parityerr = (interruptstat & 0x00400000)?true:false;
850 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
851 valnogood?"--":"OK",
852 symbolerr?"--":"OK",
853 parityerr?"--":"OK");
854 lcd_puts(0, line++, buf);
856 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
857 lcd_puts(0, line++, buf);
859 line++;
861 x = control >> 31;
862 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
863 x, x?"Professional":"Consumer");
864 lcd_puts(0, line++, buf);
866 x = (control >> 30) & 1;
867 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
868 x, x?"Non-PCM":"PCM");
869 lcd_puts(0, line++, buf);
871 x = (control >> 29) & 1;
872 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
873 x, x?"Permitted":"Inhibited");
874 lcd_puts(0, line++, buf);
876 x = (control >> 27) & 7;
877 switch(x)
879 case 0:
880 s = "None";
881 break;
882 case 1:
883 s = "50/15us";
884 break;
885 default:
886 s = "Reserved";
887 break;
889 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
890 lcd_puts(0, line++, buf);
892 x = (control >> 24) & 3;
893 snprintf(buf, sizeof(buf), "Mode: %d", x);
894 lcd_puts(0, line++, buf);
896 category = (control >> 17) & 127;
897 switch(category)
899 case 0x00:
900 s = "General";
901 break;
902 case 0x40:
903 s = "Audio CD";
904 break;
905 default:
906 s = "Unknown";
908 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
909 lcd_puts(0, line++, buf);
911 x = (control >> 16) & 1;
912 generation = x;
913 if(((category & 0x70) == 0x10) ||
914 ((category & 0x70) == 0x40) ||
915 ((category & 0x78) == 0x38))
917 generation = !generation;
919 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
920 x, generation?"Original":"No ind.");
921 lcd_puts(0, line++, buf);
923 x = (control >> 12) & 15;
924 snprintf(buf, sizeof(buf), "Source: %d", x);
925 lcd_puts(0, line++, buf);
927 x = (control >> 8) & 15;
928 switch(x)
930 case 0:
931 s = "Unspecified";
932 break;
933 case 8:
934 s = "A (Left)";
935 break;
936 case 4:
937 s = "B (Right)";
938 break;
939 default:
940 s = "";
941 break;
943 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
944 lcd_puts(0, line++, buf);
946 x = (control >> 4) & 15;
947 switch(x)
949 case 0:
950 s = "44.1kHz";
951 break;
952 case 0x4:
953 s = "48kHz";
954 break;
955 case 0xc:
956 s = "32kHz";
957 break;
959 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
960 lcd_puts(0, line++, buf);
962 x = (control >> 2) & 3;
963 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
964 lcd_puts(0, line++, buf);
965 line++;
967 #ifndef SIMULATOR
968 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
969 spdif_measure_frequency());
970 lcd_puts(0, line++, buf);
971 #endif
973 lcd_update();
975 if (action_userabort(HZ/10))
976 break;
979 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
981 #ifdef HAVE_SPDIF_POWER
982 spdif_power_enable(global_settings.spdif_enable);
983 #endif
985 lcd_setfont(FONT_UI);
986 return false;
988 #endif /* CPU_COLDFIRE */
990 #ifndef SIMULATOR
991 #ifdef HAVE_LCD_BITMAP
992 /* button definitions */
993 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
994 (CONFIG_KEYPAD == IRIVER_H300_PAD)
995 # define DEBUG_CANCEL BUTTON_OFF
997 #elif CONFIG_KEYPAD == RECORDER_PAD
998 # define DEBUG_CANCEL BUTTON_OFF
1000 #elif CONFIG_KEYPAD == ONDIO_PAD
1001 # define DEBUG_CANCEL BUTTON_MENU
1003 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
1004 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
1005 (CONFIG_KEYPAD == IPOD_4G_PAD)
1006 # define DEBUG_CANCEL BUTTON_MENU
1008 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
1009 # define DEBUG_CANCEL BUTTON_PLAY
1011 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
1012 # define DEBUG_CANCEL BUTTON_REC
1014 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1015 # define DEBUG_CANCEL BUTTON_RC_REC
1017 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
1018 # define DEBUG_CANCEL BUTTON_REW
1020 #elif (CONFIG_KEYPAD == MROBE100_PAD)
1021 # define DEBUG_CANCEL BUTTON_MENU
1023 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
1024 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
1025 (CONFIG_KEYPAD == SANSA_FUZE_PAD)
1026 # define DEBUG_CANCEL BUTTON_LEFT
1028 /* This is temporary until the SA9200 touchpad works */
1029 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) || \
1030 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD)
1031 # define DEBUG_CANCEL BUTTON_POWER
1033 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
1034 # define DEBUG_CANCEL BUTTON_PLAY
1036 #endif /* key definitions */
1038 /* Test code!!! */
1039 bool dbg_ports(void)
1041 #if CONFIG_CPU == SH7034
1042 char buf[32];
1043 int adc_battery_voltage, adc_battery_level;
1045 lcd_setfont(FONT_SYSFIXED);
1046 lcd_clear_display();
1048 while(1)
1050 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1051 lcd_puts(0, 0, buf);
1052 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1053 lcd_puts(0, 1, buf);
1055 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1056 lcd_puts(0, 2, buf);
1057 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1058 lcd_puts(0, 3, buf);
1059 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1060 lcd_puts(0, 4, buf);
1061 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1062 lcd_puts(0, 5, buf);
1064 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1065 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1066 adc_battery_voltage % 1000, adc_battery_level);
1067 lcd_puts(0, 6, buf);
1069 lcd_update();
1070 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1072 lcd_setfont(FONT_UI);
1073 return false;
1076 #elif defined(CPU_COLDFIRE)
1077 unsigned int gpio_out;
1078 unsigned int gpio1_out;
1079 unsigned int gpio_read;
1080 unsigned int gpio1_read;
1081 unsigned int gpio_function;
1082 unsigned int gpio1_function;
1083 unsigned int gpio_enable;
1084 unsigned int gpio1_enable;
1085 int adc_buttons, adc_remote;
1086 int adc_battery_voltage, adc_battery_level;
1087 char buf[128];
1088 int line;
1090 lcd_clear_display();
1091 lcd_setfont(FONT_SYSFIXED);
1093 while(1)
1095 line = 0;
1096 gpio_read = GPIO_READ;
1097 gpio1_read = GPIO1_READ;
1098 gpio_out = GPIO_OUT;
1099 gpio1_out = GPIO1_OUT;
1100 gpio_function = GPIO_FUNCTION;
1101 gpio1_function = GPIO1_FUNCTION;
1102 gpio_enable = GPIO_ENABLE;
1103 gpio1_enable = GPIO1_ENABLE;
1105 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1106 lcd_puts(0, line++, buf);
1107 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1108 lcd_puts(0, line++, buf);
1109 snprintf(buf, sizeof(buf), "GPIO_FUNC: %08x", gpio_function);
1110 lcd_puts(0, line++, buf);
1111 snprintf(buf, sizeof(buf), "GPIO_ENA: %08x", gpio_enable);
1112 lcd_puts(0, line++, buf);
1114 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1115 lcd_puts(0, line++, buf);
1116 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1117 lcd_puts(0, line++, buf);
1118 snprintf(buf, sizeof(buf), "GPIO1_FUNC: %08x", gpio1_function);
1119 lcd_puts(0, line++, buf);
1120 snprintf(buf, sizeof(buf), "GPIO1_ENA: %08x", gpio1_enable);
1121 lcd_puts(0, line++, buf);
1123 adc_buttons = adc_read(ADC_BUTTONS);
1124 adc_remote = adc_read(ADC_REMOTE);
1125 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1126 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1127 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1128 button_scan_enabled() ? '+' : '-', adc_buttons);
1129 #else
1130 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1131 #endif
1132 lcd_puts(0, line++, buf);
1133 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1134 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1135 remote_detect() ? '+' : '-', adc_remote);
1136 #else
1137 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1138 #endif
1139 lcd_puts(0, line++, buf);
1140 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1141 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1142 adc_read(ADC_REMOTEDETECT));
1143 lcd_puts(0, line++, buf);
1144 #endif
1146 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1147 adc_battery_voltage % 1000, adc_battery_level);
1148 lcd_puts(0, line++, buf);
1150 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1151 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1152 lcd_puts(0, line++, buf);
1153 #endif
1155 lcd_update();
1156 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1158 lcd_setfont(FONT_UI);
1159 return false;
1163 #elif defined(CPU_PP502x)
1165 char buf[128];
1166 int line;
1168 lcd_clear_display();
1169 lcd_setfont(FONT_SYSFIXED);
1171 while(1)
1173 line = 0;
1174 lcd_puts(0, line++, "GPIO STATES:");
1175 snprintf(buf, sizeof(buf), "A: %02x E: %02x I: %02x",
1176 (unsigned int)GPIOA_INPUT_VAL,
1177 (unsigned int)GPIOE_INPUT_VAL,
1178 (unsigned int)GPIOI_INPUT_VAL);
1179 lcd_puts(0, line++, buf);
1180 snprintf(buf, sizeof(buf), "B: %02x F: %02x J: %02x",
1181 (unsigned int)GPIOB_INPUT_VAL,
1182 (unsigned int)GPIOF_INPUT_VAL,
1183 (unsigned int)GPIOJ_INPUT_VAL);
1184 lcd_puts(0, line++, buf);
1185 snprintf(buf, sizeof(buf), "C: %02x G: %02x K: %02x",
1186 (unsigned int)GPIOC_INPUT_VAL,
1187 (unsigned int)GPIOG_INPUT_VAL,
1188 (unsigned int)GPIOK_INPUT_VAL);
1189 lcd_puts(0, line++, buf);
1190 snprintf(buf, sizeof(buf), "D: %02x H: %02x L: %02x",
1191 (unsigned int)GPIOD_INPUT_VAL,
1192 (unsigned int)GPIOH_INPUT_VAL,
1193 (unsigned int)GPIOL_INPUT_VAL);
1194 lcd_puts(0, line++, buf);
1195 line++;
1196 snprintf(buf, sizeof(buf), "GPO32_VAL: %08lx", GPO32_VAL);
1197 lcd_puts(0, line++, buf);
1198 snprintf(buf, sizeof(buf), "GPO32_EN: %08lx", GPO32_ENABLE);
1199 lcd_puts(0, line++, buf);
1200 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1201 lcd_puts(0, line++, buf);
1202 snprintf(buf, sizeof(buf), "DEV_EN2: %08lx", DEV_EN2);
1203 lcd_puts(0, line++, buf);
1204 snprintf(buf, sizeof(buf), "DEV_EN3: %08lx", inl(0x60006044));
1205 lcd_puts(0, line++, buf); /* to be verified */
1206 snprintf(buf, sizeof(buf), "DEV_INIT1: %08lx", DEV_INIT1);
1207 lcd_puts(0, line++, buf);
1208 snprintf(buf, sizeof(buf), "DEV_INIT2: %08lx", DEV_INIT2);
1209 lcd_puts(0, line++, buf);
1210 #ifdef ADC_ACCESSORY
1211 snprintf(buf, sizeof(buf), "ACCESSORY: %d", adc_read(ADC_ACCESSORY));
1212 lcd_puts(0, line++, buf);
1213 #endif
1215 #if defined(IPOD_ACCESSORY_PROTOCOL)
1216 extern unsigned char serbuf[];
1217 snprintf(buf, sizeof(buf), "IAP PACKET: %02x %02x %02x %02x %02x %02x %02x %02x",
1218 serbuf[0], serbuf[1], serbuf[2], serbuf[3], serbuf[4], serbuf[5],
1219 serbuf[6], serbuf[7]);
1220 lcd_puts(0, line++, buf);
1221 #endif
1223 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1224 line++;
1225 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1226 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1227 lcd_puts(0, line++, buf);
1228 snprintf(buf, sizeof(buf), "REM: %03x PAD: %03x",
1229 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1230 lcd_puts(0, line++, buf);
1231 #elif defined(PHILIPS_HDD1630)
1232 line++;
1233 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1234 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1235 lcd_puts(0, line++, buf);
1236 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1237 snprintf(buf, sizeof(buf), "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1238 lcd_puts(0, line++, buf);
1239 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1240 lcd_puts(0, line++, buf);
1241 snprintf(buf, sizeof(buf), "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1242 lcd_puts(0, line++, buf);
1243 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1244 lcd_puts(0, line++, buf);
1245 snprintf(buf, sizeof(buf), "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1246 lcd_puts(0, line++, buf);
1247 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1248 lcd_puts(0, line++, buf);
1249 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1250 lcd_puts(0, line++, buf);
1251 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1252 lcd_puts(0, line++, buf);
1253 snprintf(buf, sizeof(buf), "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1254 lcd_puts(0, line++, buf);
1255 snprintf(buf, sizeof(buf), "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1256 lcd_puts(0, line++, buf);
1257 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1258 lcd_puts(0, line++, buf);
1259 #if !defined(PHILIPS_SA9200)
1260 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1261 lcd_puts(0, line++, buf);
1262 snprintf(buf, sizeof(buf), "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1263 lcd_puts(0, line++, buf);
1264 #endif
1265 #endif
1266 lcd_update();
1267 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1269 lcd_setfont(FONT_UI);
1270 return false;
1274 #elif CONFIG_CPU == PP5002
1275 char buf[128];
1276 int line;
1278 lcd_clear_display();
1279 lcd_setfont(FONT_SYSFIXED);
1281 while(1)
1283 line = 0;
1284 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x",
1285 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1286 lcd_puts(0, line++, buf);
1287 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x",
1288 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1289 lcd_puts(0, line++, buf);
1291 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1292 lcd_puts(0, line++, buf);
1293 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1294 lcd_puts(0, line++, buf);
1295 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1296 lcd_puts(0, line++, buf);
1297 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1298 lcd_puts(0, line++, buf);
1299 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1300 lcd_puts(0, line++, buf);
1301 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1302 lcd_puts(0, line++, buf);
1303 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1304 lcd_puts(0, line++, buf);
1305 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1306 lcd_puts(0, line++, buf);
1308 lcd_update();
1309 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1311 lcd_setfont(FONT_UI);
1312 return false;
1315 lcd_setfont(FONT_UI);
1316 #else
1317 return __dbg_ports();
1318 #endif /* CPU */
1319 return false;
1321 #else /* !HAVE_LCD_BITMAP */
1322 bool dbg_ports(void)
1324 char buf[32];
1325 int button;
1326 int adc_battery_voltage;
1327 int currval = 0;
1329 lcd_clear_display();
1331 while(1)
1333 switch(currval)
1335 case 0:
1336 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1337 break;
1338 case 1:
1339 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1340 break;
1341 case 2:
1342 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1343 break;
1344 case 3:
1345 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1346 break;
1347 case 4:
1348 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1349 break;
1350 case 5:
1351 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1352 break;
1353 case 6:
1354 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1355 break;
1356 case 7:
1357 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1358 break;
1359 case 8:
1360 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1361 break;
1362 case 9:
1363 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1364 break;
1366 lcd_puts(0, 0, buf);
1368 battery_read_info(&adc_battery_voltage, NULL);
1369 snprintf(buf, 32, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1370 adc_battery_voltage % 1000);
1371 lcd_puts(0, 1, buf);
1372 lcd_update();
1374 button = get_action(CONTEXT_SETTINGS,HZ/5);
1376 switch(button)
1378 case ACTION_STD_CANCEL:
1379 return false;
1381 case ACTION_SETTINGS_DEC:
1382 currval--;
1383 if(currval < 0)
1384 currval = 9;
1385 break;
1387 case ACTION_SETTINGS_INC:
1388 currval++;
1389 if(currval > 9)
1390 currval = 0;
1391 break;
1394 return false;
1396 #endif /* !HAVE_LCD_BITMAP */
1397 #endif /* !SIMULATOR */
1399 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1400 static bool dbg_pcf(void)
1402 char buf[128];
1403 int line;
1405 #ifdef HAVE_LCD_BITMAP
1406 lcd_setfont(FONT_SYSFIXED);
1407 #endif
1408 lcd_clear_display();
1410 while(1)
1412 line = 0;
1414 snprintf(buf, sizeof(buf), "DCDC1: %02x", pcf50605_read(0x1b));
1415 lcd_puts(0, line++, buf);
1416 snprintf(buf, sizeof(buf), "DCDC2: %02x", pcf50605_read(0x1c));
1417 lcd_puts(0, line++, buf);
1418 snprintf(buf, sizeof(buf), "DCDC3: %02x", pcf50605_read(0x1d));
1419 lcd_puts(0, line++, buf);
1420 snprintf(buf, sizeof(buf), "DCDC4: %02x", pcf50605_read(0x1e));
1421 lcd_puts(0, line++, buf);
1422 snprintf(buf, sizeof(buf), "DCDEC1: %02x", pcf50605_read(0x1f));
1423 lcd_puts(0, line++, buf);
1424 snprintf(buf, sizeof(buf), "DCDEC2: %02x", pcf50605_read(0x20));
1425 lcd_puts(0, line++, buf);
1426 snprintf(buf, sizeof(buf), "DCUDC1: %02x", pcf50605_read(0x21));
1427 lcd_puts(0, line++, buf);
1428 snprintf(buf, sizeof(buf), "DCUDC2: %02x", pcf50605_read(0x22));
1429 lcd_puts(0, line++, buf);
1430 snprintf(buf, sizeof(buf), "IOREGC: %02x", pcf50605_read(0x23));
1431 lcd_puts(0, line++, buf);
1432 snprintf(buf, sizeof(buf), "D1REGC: %02x", pcf50605_read(0x24));
1433 lcd_puts(0, line++, buf);
1434 snprintf(buf, sizeof(buf), "D2REGC: %02x", pcf50605_read(0x25));
1435 lcd_puts(0, line++, buf);
1436 snprintf(buf, sizeof(buf), "D3REGC: %02x", pcf50605_read(0x26));
1437 lcd_puts(0, line++, buf);
1438 snprintf(buf, sizeof(buf), "LPREG1: %02x", pcf50605_read(0x27));
1439 lcd_puts(0, line++, buf);
1441 lcd_update();
1442 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1444 lcd_setfont(FONT_UI);
1445 return false;
1449 lcd_setfont(FONT_UI);
1450 return false;
1452 #endif
1454 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1455 static bool dbg_cpufreq(void)
1457 char buf[128];
1458 int line;
1459 int button;
1461 #ifdef HAVE_LCD_BITMAP
1462 lcd_setfont(FONT_SYSFIXED);
1463 #endif
1464 lcd_clear_display();
1466 while(1)
1468 line = 0;
1470 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1471 lcd_puts(0, line++, buf);
1473 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1474 lcd_puts(0, line++, buf);
1476 lcd_update();
1477 button = get_action(CONTEXT_STD,HZ/10);
1479 switch(button)
1481 case ACTION_STD_PREV:
1482 cpu_boost(true);
1483 break;
1485 case ACTION_STD_NEXT:
1486 cpu_boost(false);
1487 break;
1489 case ACTION_STD_OK:
1490 while (get_cpu_boost_counter() > 0)
1491 cpu_boost(false);
1492 set_cpu_frequency(CPUFREQ_DEFAULT);
1493 break;
1495 case ACTION_STD_CANCEL:
1496 lcd_setfont(FONT_UI);
1497 return false;
1500 lcd_setfont(FONT_UI);
1501 return false;
1503 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1505 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1506 #include "tsc2100.h"
1507 static char *itob(int n, int len)
1509 static char binary[64];
1510 int i,j;
1511 for (i=1, j=0;i<=len;i++)
1513 binary[j++] = n&(1<<(len-i))?'1':'0';
1514 if (i%4 == 0)
1515 binary[j++] = ' ';
1517 binary[j] = '\0';
1518 return binary;
1520 static char* tsc2100_debug_getname(int selected_item, void * data,
1521 char *buffer, size_t buffer_len)
1523 int *page = (int*)data;
1524 bool reserved = false;
1525 switch (*page)
1527 case 0:
1528 if ((selected_item > 0x0a) ||
1529 (selected_item == 0x04) ||
1530 (selected_item == 0x08))
1531 reserved = true;
1532 break;
1533 case 1:
1534 if ((selected_item > 0x05) ||
1535 (selected_item == 0x02))
1536 reserved = true;
1537 break;
1538 case 2:
1539 if (selected_item > 0x1e)
1540 reserved = true;
1541 break;
1543 if (reserved)
1544 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1545 else
1546 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1547 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1548 return buffer;
1550 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1552 int *page = (int*)lists->data;
1553 if (action == ACTION_STD_OK)
1555 *page = (*page+1)%3;
1556 snprintf(lists->title, 32,
1557 "tsc2100 registers - Page %d", *page);
1558 return ACTION_REDRAW;
1560 return action;
1562 static bool tsc2100_debug(void)
1564 int page = 0;
1565 char title[32] = "tsc2100 registers - Page 0";
1566 struct simplelist_info info;
1567 simplelist_info_init(&info, title, 32, &page);
1568 info.timeout = HZ/100;
1569 info.get_name = tsc2100_debug_getname;
1570 info.action_callback= tsc2100debug_action_callback;
1571 return simplelist_show_list(&info);
1573 #endif
1574 #ifndef SIMULATOR
1575 #ifdef HAVE_LCD_BITMAP
1577 * view_battery() shows a automatically scaled graph of the battery voltage
1578 * over time. Usable for estimating battery life / charging rate.
1579 * The power_history array is updated in power_thread of powermgmt.c.
1582 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1583 #define BAT_YSPACE (LCD_HEIGHT - 20)
1585 static bool view_battery(void)
1587 int view = 0;
1588 int i, x, y;
1589 unsigned short maxv, minv;
1590 char buf[32];
1592 lcd_setfont(FONT_SYSFIXED);
1594 while(1)
1596 lcd_clear_display();
1597 switch (view) {
1598 case 0: /* voltage history graph */
1599 /* Find maximum and minimum voltage for scaling */
1600 minv = power_history[0];
1601 maxv = minv + 1;
1602 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1603 if (power_history[i] > maxv)
1604 maxv = power_history[i];
1605 if (power_history[i] < minv)
1606 minv = power_history[i];
1609 snprintf(buf, 30, "Battery %d.%03d", power_history[0] / 1000,
1610 power_history[0] % 1000);
1611 lcd_puts(0, 0, buf);
1612 snprintf(buf, 30, "scale %d.%03d-%d.%03dV",
1613 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1614 lcd_puts(0, 1, buf);
1616 x = 0;
1617 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1618 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1619 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1620 lcd_vline(x, LCD_HEIGHT-1, 20);
1621 lcd_set_drawmode(DRMODE_SOLID);
1622 lcd_vline(x, LCD_HEIGHT-1,
1623 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1624 x++;
1627 break;
1629 case 1: /* status: */
1630 lcd_puts(0, 0, "Power status:");
1632 battery_read_info(&y, NULL);
1633 snprintf(buf, 30, "Battery: %d.%03d V", y / 1000, y % 1000);
1634 lcd_puts(0, 1, buf);
1635 #ifdef ADC_EXT_POWER
1636 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1637 snprintf(buf, 30, "External: %d.%03d V", y / 1000, y % 1000);
1638 lcd_puts(0, 2, buf);
1639 #endif
1640 #if CONFIG_CHARGING
1641 #if defined ARCHOS_RECORDER
1642 snprintf(buf, 30, "Chgr: %s %s",
1643 charger_inserted() ? "present" : "absent",
1644 charger_enabled() ? "on" : "off");
1645 lcd_puts(0, 3, buf);
1646 snprintf(buf, 30, "short delta: %d", short_delta);
1647 lcd_puts(0, 5, buf);
1648 snprintf(buf, 30, "long delta: %d", long_delta);
1649 lcd_puts(0, 6, buf);
1650 lcd_puts(0, 7, power_message);
1651 snprintf(buf, 30, "USB Inserted: %s",
1652 usb_inserted() ? "yes" : "no");
1653 lcd_puts(0, 8, buf);
1654 #elif defined IRIVER_H300_SERIES
1655 snprintf(buf, 30, "USB Charging Enabled: %s",
1656 usb_charging_enabled() ? "yes" : "no");
1657 lcd_puts(0, 9, buf);
1658 #elif defined IPOD_NANO || defined IPOD_VIDEO
1659 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1660 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1661 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1662 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1663 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1665 snprintf(buf, 30, "USB pwr: %s",
1666 usb_pwr ? "present" : "absent");
1667 lcd_puts(0, 3, buf);
1668 snprintf(buf, 30, "EXT pwr: %s",
1669 ext_pwr ? "present" : "absent");
1670 lcd_puts(0, 4, buf);
1671 snprintf(buf, 30, "Battery: %s",
1672 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1673 lcd_puts(0, 5, buf);
1674 snprintf(buf, 30, "Dock mode: %s",
1675 dock ? "enabled" : "disabled");
1676 lcd_puts(0, 6, buf);
1677 snprintf(buf, 30, "Headphone: %s",
1678 headphone ? "connected" : "disconnected");
1679 lcd_puts(0, 7, buf);
1680 #elif defined TOSHIBA_GIGABEAT_S
1681 int line = 3;
1682 unsigned int st;
1684 static const unsigned char * const chrgstate_strings[] =
1686 "Disabled",
1687 "Error",
1688 "Discharging",
1689 "Precharge",
1690 "Constant Voltage",
1691 "Constant Current",
1692 "<unknown>",
1695 snprintf(buf, 30, "Charger: %s",
1696 charger_inserted() ? "present" : "absent");
1697 lcd_puts(0, line++, buf);
1699 st = power_input_status() &
1700 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1701 snprintf(buf, 30, "%s%s",
1702 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1703 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1704 lcd_puts(0, line++, buf);
1706 snprintf(buf, 30, "IUSB Max: %d", usb_allowed_current());
1707 lcd_puts(0, line++, buf);
1709 y = ARRAYLEN(chrgstate_strings) - 1;
1711 switch (charge_state)
1713 case CHARGE_STATE_DISABLED: y--;
1714 case CHARGE_STATE_ERROR: y--;
1715 case DISCHARGING: y--;
1716 case TRICKLE: y--;
1717 case TOPOFF: y--;
1718 case CHARGING: y--;
1719 default:;
1722 snprintf(buf, 30, "State: %s", chrgstate_strings[y]);
1723 lcd_puts(0, line++, buf);
1725 snprintf(buf, 30, "Battery Switch: %s",
1726 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1727 lcd_puts(0, line++, buf);
1729 y = chrgraw_adc_voltage();
1730 snprintf(buf, 30, "CHRGRAW: %d.%03d V",
1731 y / 1000, y % 1000);
1732 lcd_puts(0, line++, buf);
1734 y = application_supply_adc_voltage();
1735 snprintf(buf, 30, "BP : %d.%03d V",
1736 y / 1000, y % 1000);
1737 lcd_puts(0, line++, buf);
1739 y = battery_adc_charge_current();
1740 if (y < 0) x = '-', y = -y;
1741 else x = ' ';
1742 snprintf(buf, 30, "CHRGISN:%c%d mA", x, y);
1743 lcd_puts(0, line++, buf);
1745 y = cccv_regulator_dissipation();
1746 snprintf(buf, 30, "P CCCV : %d mW", y);
1747 lcd_puts(0, line++, buf);
1749 y = battery_charge_current();
1750 if (y < 0) x = '-', y = -y;
1751 else x = ' ';
1752 snprintf(buf, 30, "I Charge:%c%d mA", x, y);
1753 lcd_puts(0, line++, buf);
1755 y = battery_adc_temp();
1757 if (y != INT_MIN) {
1758 snprintf(buf, 30, "T Battery: %dC (%dF)", y,
1759 (9*y + 160) / 5);
1760 } else {
1761 /* Conversion disabled */
1762 snprintf(buf, 30, "T Battery: ?");
1765 lcd_puts(0, line++, buf);
1766 #elif defined(SANSA_E200) || defined(SANSA_C200) || defined(SANSA_CLIP) || defined(SANSA_FUZE)
1767 const int first = CHARGE_STATE_DISABLED;
1768 static const char * const chrgstate_strings[] =
1770 [CHARGE_STATE_DISABLED-first] = "Disabled",
1771 [CHARGE_STATE_ERROR-first] = "Error",
1772 [DISCHARGING-first] = "Discharging",
1773 [CHARGING-first] = "Charging",
1775 const char *str = NULL;
1777 snprintf(buf, 30, "Charger: %s",
1778 charger_inserted() ? "present" : "absent");
1779 lcd_puts(0, 3, buf);
1781 y = charge_state - first;
1782 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1783 str = chrgstate_strings[y];
1785 snprintf(buf, sizeof(buf), "State: %s",
1786 str ? str : "<unknown>");
1787 lcd_puts(0, 4, buf);
1789 snprintf(buf, sizeof(buf), "CHARGER: %02X",
1790 ascodec_read(AS3514_CHARGER));
1791 lcd_puts(0, 5, buf);
1792 #else
1793 snprintf(buf, 30, "Charger: %s",
1794 charger_inserted() ? "present" : "absent");
1795 lcd_puts(0, 3, buf);
1796 #endif /* target type */
1797 #endif /* CONFIG_CHARGING */
1798 break;
1800 case 2: /* voltage deltas: */
1801 lcd_puts(0, 0, "Voltage deltas:");
1803 for (i = 0; i <= 6; i++) {
1804 y = power_history[i] - power_history[i+1];
1805 snprintf(buf, 30, "-%d min: %s%d.%03d V", i,
1806 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1807 ((y < 0) ? y * -1 : y ) % 1000);
1808 lcd_puts(0, i+1, buf);
1810 break;
1812 case 3: /* remaining time estimation: */
1814 #ifdef ARCHOS_RECORDER
1815 snprintf(buf, 30, "charge_state: %d", charge_state);
1816 lcd_puts(0, 0, buf);
1818 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1819 lcd_puts(0, 1, buf);
1821 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1822 lcd_puts(0, 2, buf);
1824 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1825 lcd_puts(0, 3, buf);
1827 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1828 lcd_puts(0, 4, buf);
1829 #endif /* ARCHOS_RECORDER */
1831 snprintf(buf, 30, "Last PwrHist: %d.%03dV",
1832 power_history[0] / 1000,
1833 power_history[0] % 1000);
1834 lcd_puts(0, 5, buf);
1836 snprintf(buf, 30, "battery level: %d%%", battery_level());
1837 lcd_puts(0, 6, buf);
1839 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1840 lcd_puts(0, 7, buf);
1841 break;
1844 lcd_update();
1846 switch(get_action(CONTEXT_STD,HZ/2))
1848 case ACTION_STD_PREV:
1849 if (view)
1850 view--;
1851 break;
1853 case ACTION_STD_NEXT:
1854 if (view < 3)
1855 view++;
1856 break;
1858 case ACTION_STD_CANCEL:
1859 lcd_setfont(FONT_UI);
1860 return false;
1863 lcd_setfont(FONT_UI);
1864 return false;
1867 #endif /* HAVE_LCD_BITMAP */
1868 #endif
1870 #ifndef SIMULATOR
1871 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1873 #if (CONFIG_STORAGE & STORAGE_MMC)
1874 #define CARDTYPE "MMC"
1875 #elif (CONFIG_STORAGE & STORAGE_SD)
1876 #define CARDTYPE "microSD"
1877 #endif
1879 static int disk_callback(int btn, struct gui_synclist *lists)
1881 tCardInfo *card;
1882 int *cardnum = (int*)lists->data;
1883 unsigned char card_name[7];
1884 unsigned char pbuf[32];
1885 char *title = lists->title;
1886 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1887 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1888 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1889 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1890 #if (CONFIG_STORAGE & STORAGE_MMC)
1891 static const char *mmc_spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1892 "3.1-3.31", "4.0" };
1893 #endif
1895 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1897 #ifdef HAVE_HOTSWAP
1898 if (btn == ACTION_STD_OK)
1900 *cardnum ^= 0x1; /* change cards */
1902 #endif
1904 simplelist_set_line_count(0);
1906 card = card_get_info(*cardnum);
1908 if (card->initialized > 0)
1910 strlcpy(card_name, ((unsigned char*)card->cid) + 3, sizeof(card_name));
1911 simplelist_addline(SIMPLELIST_ADD_LINE,
1912 "%s Rev %d.%d", card_name,
1913 (int) card_extract_bits(card->cid, 55, 4),
1914 (int) card_extract_bits(card->cid, 51, 4));
1915 simplelist_addline(SIMPLELIST_ADD_LINE,
1916 "Prod: %d/%d",
1917 #if (CONFIG_STORAGE & STORAGE_SD)
1918 (int) card_extract_bits(card->cid, 11, 3),
1919 (int) card_extract_bits(card->cid, 19, 8) + 2000
1920 #elif (CONFIG_STORAGE & STORAGE_MMC)
1921 (int) card_extract_bits(card->cid, 15, 4),
1922 (int) card_extract_bits(card->cid, 11, 4) + 1997
1923 #endif
1925 simplelist_addline(SIMPLELIST_ADD_LINE,
1926 #if (CONFIG_STORAGE & STORAGE_SD)
1927 "Ser#: 0x%08lx",
1928 card_extract_bits(card->cid, 55, 32)
1929 #elif (CONFIG_STORAGE & STORAGE_MMC)
1930 "Ser#: 0x%04lx",
1931 card_extract_bits(card->cid, 47, 16)
1932 #endif
1935 simplelist_addline(SIMPLELIST_ADD_LINE, "M=%02x, "
1936 #if (CONFIG_STORAGE & STORAGE_SD)
1937 "O=%c%c",
1938 (int) card_extract_bits(card->cid, 127, 8),
1939 card_extract_bits(card->cid, 119, 8),
1940 card_extract_bits(card->cid, 111, 8)
1941 #elif (CONFIG_STORAGE & STORAGE_MMC)
1942 "O=%04x",
1943 (int) card_extract_bits(card->cid, 127, 8),
1944 (int) card_extract_bits(card->cid, 119, 16)
1945 #endif
1948 #if (CONFIG_STORAGE & STORAGE_MMC)
1949 int temp = card_extract_bits(card->csd, 125, 4);
1950 simplelist_addline(SIMPLELIST_ADD_LINE,
1951 "MMC v%s", temp < 5 ?
1952 mmc_spec_vers[temp] : "?.?");
1953 #endif
1954 simplelist_addline(SIMPLELIST_ADD_LINE,
1955 "Blocks: 0x%08lx", card->numblocks);
1956 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1957 kbit_units, false);
1958 simplelist_addline(SIMPLELIST_ADD_LINE,
1959 "Speed: %s", pbuf);
1960 output_dyn_value(pbuf, sizeof pbuf, card->taac,
1961 nsec_units, false);
1962 simplelist_addline(SIMPLELIST_ADD_LINE,
1963 "Taac: %s", pbuf);
1964 simplelist_addline(SIMPLELIST_ADD_LINE,
1965 "Nsac: %d clk", card->nsac);
1966 simplelist_addline(SIMPLELIST_ADD_LINE,
1967 "R2W: *%d", card->r2w_factor);
1968 simplelist_addline(SIMPLELIST_ADD_LINE,
1969 "IRmax: %d..%d mA",
1970 i_vmin[card_extract_bits(card->csd, 61, 3)],
1971 i_vmax[card_extract_bits(card->csd, 58, 3)]);
1972 simplelist_addline(SIMPLELIST_ADD_LINE,
1973 "IWmax: %d..%d mA",
1974 i_vmin[card_extract_bits(card->csd, 55, 3)],
1975 i_vmax[card_extract_bits(card->csd, 52, 3)]);
1977 else if (card->initialized == 0)
1979 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1981 #if (CONFIG_STORAGE & STORAGE_SD)
1982 else /* card->initialized < 0 */
1984 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1986 #endif
1987 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1988 gui_synclist_set_title(lists, title, Icon_NOICON);
1989 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1990 gui_synclist_select_item(lists, 0);
1991 btn = ACTION_REDRAW;
1993 return btn;
1995 #elif (CONFIG_STORAGE & STORAGE_ATA)
1996 static int disk_callback(int btn, struct gui_synclist *lists)
1998 (void)lists;
1999 int i;
2000 char buf[128];
2001 unsigned short* identify_info = ata_get_identify();
2002 bool timing_info_present = false;
2003 (void)btn;
2005 simplelist_set_line_count(0);
2007 for (i=0; i < 20; i++)
2008 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
2009 buf[40]=0;
2010 /* kill trailing space */
2011 for (i=39; i && buf[i]==' '; i--)
2012 buf[i] = 0;
2013 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
2014 for (i=0; i < 4; i++)
2015 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
2016 buf[8]=0;
2017 simplelist_addline(SIMPLELIST_ADD_LINE,
2018 "Firmware: %s", buf);
2019 snprintf(buf, sizeof buf, "%ld MB",
2020 ((unsigned long)identify_info[61] << 16 |
2021 (unsigned long)identify_info[60]) / 2048 );
2022 simplelist_addline(SIMPLELIST_ADD_LINE,
2023 "Size: %s", buf);
2024 unsigned long free;
2025 fat_size( IF_MV2(0,) NULL, &free );
2026 simplelist_addline(SIMPLELIST_ADD_LINE,
2027 "Free: %ld MB", free / 1024);
2028 simplelist_addline(SIMPLELIST_ADD_LINE,
2029 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
2030 i = identify_info[83] & (1<<3);
2031 simplelist_addline(SIMPLELIST_ADD_LINE,
2032 "Power mgmt: %s", i ? "enabled" : "unsupported");
2033 i = identify_info[83] & (1<<9);
2034 simplelist_addline(SIMPLELIST_ADD_LINE,
2035 "Noise mgmt: %s", i ? "enabled" : "unsupported");
2036 i = identify_info[82] & (1<<6);
2037 simplelist_addline(SIMPLELIST_ADD_LINE,
2038 "Read-ahead: %s", i ? "enabled" : "unsupported");
2039 timing_info_present = identify_info[53] & (1<<1);
2040 if(timing_info_present) {
2041 char pio3[2], pio4[2];pio3[1] = 0;
2042 pio4[1] = 0;
2043 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
2044 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
2045 simplelist_addline(SIMPLELIST_ADD_LINE,
2046 "PIO modes: 0 1 2 %s %s", pio3, pio4);
2048 else {
2049 simplelist_addline(SIMPLELIST_ADD_LINE,
2050 "No PIO mode info");
2052 timing_info_present = identify_info[53] & (1<<1);
2053 if(timing_info_present) {
2054 simplelist_addline(SIMPLELIST_ADD_LINE,
2055 "Cycle times %dns/%dns",
2056 identify_info[67],
2057 identify_info[68] );
2058 } else {
2059 simplelist_addline(SIMPLELIST_ADD_LINE,
2060 "No timing info");
2062 #ifdef HAVE_ATA_DMA
2063 if (identify_info[63] & (1<<0)) {
2064 char mdma0[2], mdma1[2], mdma2[2];
2065 mdma0[1] = mdma1[1] = mdma2[1] = 0;
2066 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
2067 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
2068 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
2069 simplelist_addline(SIMPLELIST_ADD_LINE,
2070 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
2071 simplelist_addline(SIMPLELIST_ADD_LINE,
2072 "MDMA Cycle times %dns/%dns",
2073 identify_info[65],
2074 identify_info[66] );
2076 else {
2077 simplelist_addline(SIMPLELIST_ADD_LINE,
2078 "No MDMA mode info");
2080 if (identify_info[53] & (1<<2)) {
2081 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2], udma6[2];
2082 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = udma6[1] = 0;
2083 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
2084 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
2085 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
2086 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
2087 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
2088 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
2089 udma6[0] = (identify_info[88] & (1<<6)) ? '6' : 0;
2090 simplelist_addline(SIMPLELIST_ADD_LINE,
2091 "UDMA modes: %s %s %s %s %s %s %s", udma0, udma1, udma2,
2092 udma3, udma4, udma5, udma6);
2094 else {
2095 simplelist_addline(SIMPLELIST_ADD_LINE,
2096 "No UDMA mode info");
2098 #endif /* HAVE_ATA_DMA */
2099 timing_info_present = identify_info[53] & (1<<1);
2100 if(timing_info_present) {
2101 i = identify_info[49] & (1<<11);
2102 simplelist_addline(SIMPLELIST_ADD_LINE,
2103 "IORDY support: %s", i ? "yes" : "no");
2104 i = identify_info[49] & (1<<10);
2105 simplelist_addline(SIMPLELIST_ADD_LINE,
2106 "IORDY disable: %s", i ? "yes" : "no");
2107 } else {
2108 simplelist_addline(SIMPLELIST_ADD_LINE,
2109 "No timing info");
2111 simplelist_addline(SIMPLELIST_ADD_LINE,
2112 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2113 #ifdef HAVE_ATA_DMA
2114 i = ata_get_dma_mode();
2115 if (i == 0) {
2116 simplelist_addline(SIMPLELIST_ADD_LINE,
2117 "DMA not enabled");
2118 } else {
2119 simplelist_addline(SIMPLELIST_ADD_LINE,
2120 "DMA mode: %s %c",
2121 (i & 0x40) ? "UDMA" : "MDMA",
2122 '0' + (i & 7));
2124 #endif /* HAVE_ATA_DMA */
2125 return btn;
2127 #else /* No SD, MMC or ATA */
2128 static int disk_callback(int btn, struct gui_synclist *lists)
2130 (void)btn;
2131 (void)lists;
2132 struct storage_info info;
2133 storage_get_info(0,&info);
2134 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
2135 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
2136 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
2137 simplelist_addline(SIMPLELIST_ADD_LINE,
2138 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
2139 unsigned long free;
2140 fat_size( IF_MV2(0,) NULL, &free );
2141 simplelist_addline(SIMPLELIST_ADD_LINE,
2142 "Free: %ld MB", free / 1024);
2143 simplelist_addline(SIMPLELIST_ADD_LINE,
2144 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2145 return btn;
2147 #endif
2149 #if (CONFIG_STORAGE & STORAGE_ATA)
2150 static bool dbg_identify_info(void)
2152 int fd = creat("/identify_info.bin");
2153 if(fd >= 0)
2155 #ifdef ROCKBOX_LITTLE_ENDIAN
2156 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
2157 #else
2158 write(fd, ata_get_identify(), SECTOR_SIZE);
2159 #endif
2160 close(fd);
2162 return false;
2164 #endif
2166 static bool dbg_disk_info(void)
2168 struct simplelist_info info;
2169 simplelist_info_init(&info, "Disk Info", 1, NULL);
2170 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
2171 char title[16];
2172 int card = 0;
2173 info.callback_data = (void*)&card;
2174 info.title = title;
2175 #endif
2176 info.action_callback = disk_callback;
2177 info.hide_selection = true;
2178 info.scroll_all = true;
2179 return simplelist_show_list(&info);
2181 #endif /* !SIMULATOR */
2183 #ifdef HAVE_DIRCACHE
2184 static int dircache_callback(int btn, struct gui_synclist *lists)
2186 (void)btn; (void)lists;
2187 simplelist_set_line_count(0);
2188 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
2189 dircache_is_enabled() ? "Yes" : "No");
2190 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
2191 dircache_get_cache_size());
2192 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
2193 global_status.dircache_size);
2194 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
2195 DIRCACHE_LIMIT);
2196 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
2197 dircache_get_reserve_used(), DIRCACHE_RESERVE);
2198 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2199 dircache_get_build_ticks() / HZ);
2200 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2201 dircache_get_entry_count());
2202 return btn;
2205 static bool dbg_dircache_info(void)
2207 struct simplelist_info info;
2208 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2209 info.action_callback = dircache_callback;
2210 info.hide_selection = true;
2211 info.scroll_all = true;
2212 return simplelist_show_list(&info);
2215 #endif /* HAVE_DIRCACHE */
2217 #ifdef HAVE_TAGCACHE
2218 static int database_callback(int btn, struct gui_synclist *lists)
2220 (void)lists;
2221 struct tagcache_stat *stat = tagcache_get_stat();
2222 static bool synced = false;
2224 simplelist_set_line_count(0);
2226 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2227 stat->initialized ? "Yes" : "No");
2228 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2229 stat->ready ? "Yes" : "No");
2230 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2231 stat->ramcache ? "Yes" : "No");
2232 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2233 stat->ramcache_used, stat->ramcache_allocated);
2234 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2235 stat->progress, stat->processed_entries);
2236 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2237 stat->curentry ? stat->curentry : "---");
2238 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2239 stat->commit_step);
2240 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2241 stat->commit_delayed ? "Yes" : "No");
2243 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2244 stat->queue_length);
2246 if (synced)
2248 synced = false;
2249 tagcache_screensync_event();
2252 if (!btn && stat->curentry)
2254 synced = true;
2255 return ACTION_REDRAW;
2258 if (btn == ACTION_STD_CANCEL)
2259 tagcache_screensync_enable(false);
2261 return btn;
2263 static bool dbg_tagcache_info(void)
2265 struct simplelist_info info;
2266 simplelist_info_init(&info, "Database Info", 8, NULL);
2267 info.action_callback = database_callback;
2268 info.hide_selection = true;
2269 info.scroll_all = true;
2271 /* Don't do nonblock here, must give enough processing time
2272 for tagcache thread. */
2273 /* info.timeout = TIMEOUT_NOBLOCK; */
2274 info.timeout = 1;
2275 tagcache_screensync_enable(true);
2276 return simplelist_show_list(&info);
2278 #endif
2280 #if CONFIG_CPU == SH7034
2281 static bool dbg_save_roms(void)
2283 int fd;
2284 int oldmode = system_memory_guard(MEMGUARD_NONE);
2286 fd = creat("/internal_rom_0000-FFFF.bin");
2287 if(fd >= 0)
2289 write(fd, (void *)0, 0x10000);
2290 close(fd);
2293 fd = creat("/internal_rom_2000000-203FFFF.bin");
2294 if(fd >= 0)
2296 write(fd, (void *)0x2000000, 0x40000);
2297 close(fd);
2300 system_memory_guard(oldmode);
2301 return false;
2303 #elif defined CPU_COLDFIRE
2304 static bool dbg_save_roms(void)
2306 int fd;
2307 int oldmode = system_memory_guard(MEMGUARD_NONE);
2309 #if defined(IRIVER_H100_SERIES)
2310 fd = creat("/internal_rom_000000-1FFFFF.bin");
2311 #elif defined(IRIVER_H300_SERIES)
2312 fd = creat("/internal_rom_000000-3FFFFF.bin");
2313 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2314 fd = creat("/internal_rom_000000-3FFFFF.bin");
2315 #endif
2316 if(fd >= 0)
2318 write(fd, (void *)0, FLASH_SIZE);
2319 close(fd);
2321 system_memory_guard(oldmode);
2323 #ifdef HAVE_EEPROM
2324 fd = creat("/internal_eeprom.bin");
2325 if (fd >= 0)
2327 int old_irq_level;
2328 char buf[EEPROM_SIZE];
2329 int err;
2331 old_irq_level = disable_irq_save();
2333 err = eeprom_24cxx_read(0, buf, sizeof buf);
2335 restore_irq(old_irq_level);
2337 if (err)
2338 splashf(HZ*3, "Eeprom read failure (%d)", err);
2339 else
2341 write(fd, buf, sizeof buf);
2344 close(fd);
2346 #endif
2348 return false;
2350 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
2351 static bool dbg_save_roms(void)
2353 int fd;
2355 fd = creat("/internal_rom_000000-0FFFFF.bin");
2356 if(fd >= 0)
2358 write(fd, (void *)0x20000000, FLASH_SIZE);
2359 close(fd);
2362 return false;
2364 #endif /* CPU */
2366 #ifndef SIMULATOR
2367 #if CONFIG_TUNER
2368 static int radio_callback(int btn, struct gui_synclist *lists)
2370 (void)lists;
2371 if (btn == ACTION_STD_CANCEL)
2372 return btn;
2373 simplelist_set_line_count(1);
2375 #if (CONFIG_TUNER & LV24020LP)
2376 simplelist_addline(SIMPLELIST_ADD_LINE,
2377 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2378 simplelist_addline(SIMPLELIST_ADD_LINE,
2379 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2380 simplelist_addline(SIMPLELIST_ADD_LINE,
2381 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2382 simplelist_addline(SIMPLELIST_ADD_LINE,
2383 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2384 simplelist_addline(SIMPLELIST_ADD_LINE,
2385 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2386 simplelist_addline(SIMPLELIST_ADD_LINE,
2387 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2388 simplelist_addline(SIMPLELIST_ADD_LINE,
2389 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2390 #endif /* LV24020LP */
2391 #if (CONFIG_TUNER & S1A0903X01)
2392 simplelist_addline(SIMPLELIST_ADD_LINE,
2393 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2394 /* This one doesn't return dynamic data atm */
2395 #endif /* S1A0903X01 */
2396 #if (CONFIG_TUNER & TEA5767)
2397 struct tea5767_dbg_info nfo;
2398 tea5767_dbg_info(&nfo);
2399 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2400 simplelist_addline(SIMPLELIST_ADD_LINE,
2401 " Read: %02X %02X %02X %02X %02X",
2402 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2403 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2404 (unsigned)nfo.read_regs[4]);
2405 simplelist_addline(SIMPLELIST_ADD_LINE,
2406 " Write: %02X %02X %02X %02X %02X",
2407 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2408 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2409 (unsigned)nfo.write_regs[4]);
2410 #endif /* TEA5767 */
2411 #if (CONFIG_TUNER & SI4700)
2412 struct si4700_dbg_info nfo;
2413 si4700_dbg_info(&nfo);
2414 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
2415 /* Registers */
2416 simplelist_addline(SIMPLELIST_ADD_LINE,
2417 "%04X %04X %04X %04X",
2418 (unsigned)nfo.regs[0], (unsigned)nfo.regs[1],
2419 (unsigned)nfo.regs[2], (unsigned)nfo.regs[3]);
2420 simplelist_addline(SIMPLELIST_ADD_LINE,
2421 "%04X %04X %04X %04X",
2422 (unsigned)nfo.regs[4], (unsigned)nfo.regs[5],
2423 (unsigned)nfo.regs[6], (unsigned)nfo.regs[7]);
2424 simplelist_addline(SIMPLELIST_ADD_LINE,
2425 "%04X %04X %04X %04X",
2426 (unsigned)nfo.regs[8], (unsigned)nfo.regs[9],
2427 (unsigned)nfo.regs[10], (unsigned)nfo.regs[11]);
2428 simplelist_addline(SIMPLELIST_ADD_LINE,
2429 "%04X %04X %04X %04X",
2430 (unsigned)nfo.regs[12], (unsigned)nfo.regs[13],
2431 (unsigned)nfo.regs[14], (unsigned)nfo.regs[15]);
2432 #endif /* SI4700 */
2433 return ACTION_REDRAW;
2435 static bool dbg_fm_radio(void)
2437 struct simplelist_info info;
2438 info.scroll_all = true;
2439 simplelist_info_init(&info, "FM Radio", 1, NULL);
2440 simplelist_set_line_count(0);
2441 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2442 radio_hardware_present() ? "yes" : "no");
2444 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2445 info.hide_selection = true;
2446 return simplelist_show_list(&info);
2448 #endif /* CONFIG_TUNER */
2449 #endif /* !SIMULATOR */
2451 #ifdef HAVE_LCD_BITMAP
2452 extern bool do_screendump_instead_of_usb;
2454 static bool dbg_screendump(void)
2456 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2457 splashf(HZ, "Screendump %s",
2458 do_screendump_instead_of_usb?"enabled":"disabled");
2459 return false;
2461 #endif /* HAVE_LCD_BITMAP */
2463 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2464 static bool dbg_set_memory_guard(void)
2466 static const struct opt_items names[MAXMEMGUARD] = {
2467 { "None", -1 },
2468 { "Flash ROM writes", -1 },
2469 { "Zero area (all)", -1 }
2471 int mode = system_memory_guard(MEMGUARD_KEEP);
2473 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2474 system_memory_guard(mode);
2476 return false;
2478 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2480 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2481 static bool dbg_write_eeprom(void)
2483 int fd;
2484 int rc;
2485 int old_irq_level;
2486 char buf[EEPROM_SIZE];
2487 int err;
2489 fd = open("/internal_eeprom.bin", O_RDONLY);
2491 if (fd >= 0)
2493 rc = read(fd, buf, EEPROM_SIZE);
2495 if(rc == EEPROM_SIZE)
2497 old_irq_level = disable_irq_save();
2499 err = eeprom_24cxx_write(0, buf, sizeof buf);
2500 if (err)
2501 splashf(HZ*3, "Eeprom write failure (%d)", err);
2502 else
2503 splash(HZ*3, "Eeprom written successfully");
2505 restore_irq(old_irq_level);
2507 else
2509 splashf(HZ*3, "File read error (%d)",rc);
2511 close(fd);
2513 else
2515 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2518 return false;
2520 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2521 #ifdef CPU_BOOST_LOGGING
2522 static bool cpu_boost_log(void)
2524 int i = 0,j=0;
2525 int count = cpu_boost_log_getcount();
2526 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2527 char *str;
2528 bool done;
2529 lcd_setfont(FONT_SYSFIXED);
2530 str = cpu_boost_log_getlog_first();
2531 while (i < count)
2533 lcd_clear_display();
2534 for(j=0; j<lines; j++,i++)
2536 if (!str)
2537 str = cpu_boost_log_getlog_next();
2538 if (str)
2540 if(strlen(str) > LCD_WIDTH/SYSFONT_WIDTH)
2541 lcd_puts_scroll(0, j, str);
2542 else
2543 lcd_puts(0, j,str);
2545 str = NULL;
2547 lcd_update();
2548 done = false;
2549 while (!done)
2551 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2553 case ACTION_STD_OK:
2554 case ACTION_STD_PREV:
2555 case ACTION_STD_NEXT:
2556 done = true;
2557 break;
2558 case ACTION_STD_CANCEL:
2559 i = count;
2560 done = true;
2561 break;
2565 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2566 lcd_setfont(FONT_UI);
2567 return false;
2569 #endif
2571 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2572 extern bool wheel_is_touched;
2573 extern int old_wheel_value;
2574 extern int new_wheel_value;
2575 extern int wheel_delta;
2576 extern unsigned int accumulated_wheel_delta;
2577 extern unsigned int wheel_velocity;
2579 static bool dbg_scrollwheel(void)
2581 char buf[64];
2582 unsigned int speed;
2584 lcd_setfont(FONT_SYSFIXED);
2586 while (1)
2588 if (action_userabort(HZ/10))
2589 break;
2591 lcd_clear_display();
2593 /* show internal variables of scrollwheel driver */
2594 snprintf(buf, sizeof(buf), "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2595 lcd_puts(0, 0, buf);
2596 snprintf(buf, sizeof(buf), "new position: %2d", new_wheel_value);
2597 lcd_puts(0, 1, buf);
2598 snprintf(buf, sizeof(buf), "old position: %2d", old_wheel_value);
2599 lcd_puts(0, 2, buf);
2600 snprintf(buf, sizeof(buf), "wheel delta: %2d", wheel_delta);
2601 lcd_puts(0, 3, buf);
2602 snprintf(buf, sizeof(buf), "accumulated delta: %2d", accumulated_wheel_delta);
2603 lcd_puts(0, 4, buf);
2604 snprintf(buf, sizeof(buf), "velo [deg/s]: %4d", (int)wheel_velocity);
2605 lcd_puts(0, 5, buf);
2607 /* show effective accelerated scrollspeed */
2608 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2609 snprintf(buf, sizeof(buf), "accel. speed: %4d", speed);
2610 lcd_puts(0, 6, buf);
2612 lcd_update();
2614 lcd_setfont(FONT_UI);
2615 return false;
2617 #endif
2619 #if defined (HAVE_USBSTACK)
2621 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2622 static bool toggle_usb_core_driver(int driver, char *msg)
2624 bool enabled = !usb_core_driver_enabled(driver);
2626 usb_core_enable_driver(driver,enabled);
2627 splashf(HZ, "%s %s", msg, enabled?"enabled":"disabled");
2629 return false;
2632 static bool toggle_usb_serial(void)
2634 return toggle_usb_core_driver(USB_DRIVER_SERIAL,"USB Serial");
2636 #endif
2638 #endif
2640 #if CONFIG_USBOTG == USBOTG_ISP1583
2641 extern int dbg_usb_num_items(void);
2642 extern char* dbg_usb_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2644 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2646 (void)lists;
2647 if (action == ACTION_NONE)
2648 action = ACTION_REDRAW;
2649 return action;
2652 static bool dbg_isp1583(void)
2654 struct simplelist_info isp1583;
2655 isp1583.scroll_all = true;
2656 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2657 isp1583.timeout = HZ/100;
2658 isp1583.hide_selection = true;
2659 isp1583.get_name = dbg_usb_item;
2660 isp1583.action_callback = isp1583_action_callback;
2661 return simplelist_show_list(&isp1583);
2663 #endif
2665 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2666 extern int pic_dbg_num_items(void);
2667 extern char* pic_dbg_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2669 static int pic_action_callback(int action, struct gui_synclist *lists)
2671 (void)lists;
2672 if (action == ACTION_NONE)
2673 action = ACTION_REDRAW;
2674 return action;
2677 static bool dbg_pic(void)
2679 struct simplelist_info pic;
2680 pic.scroll_all = true;
2681 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2682 pic.timeout = HZ/100;
2683 pic.hide_selection = true;
2684 pic.get_name = pic_dbg_item;
2685 pic.action_callback = pic_action_callback;
2686 return simplelist_show_list(&pic);
2688 #endif
2691 /****** The menu *********/
2692 struct the_menu_item {
2693 unsigned char *desc; /* string or ID */
2694 bool (*function) (void); /* return true if USB was connected */
2696 static const struct the_menu_item menuitems[] = {
2697 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2698 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD))
2699 { "Dump ROM contents", dbg_save_roms },
2700 #endif
2701 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2702 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 \
2703 || CONFIG_CPU == DM320
2704 { "View I/O ports", dbg_ports },
2705 #endif
2706 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2707 { "View PCF registers", dbg_pcf },
2708 #endif
2709 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2710 { "TSC2100 debug", tsc2100_debug },
2711 #endif
2712 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2713 { "CPU frequency", dbg_cpufreq },
2714 #endif
2715 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2716 { "S/PDIF analyzer", dbg_spdif },
2717 #endif
2718 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2719 { "Catch mem accesses", dbg_set_memory_guard },
2720 #endif
2721 { "View OS stacks", dbg_os },
2722 #ifdef HAVE_LCD_BITMAP
2723 #ifndef SIMULATOR
2724 { "View battery", view_battery },
2725 #endif
2726 { "Screendump", dbg_screendump },
2727 #endif
2728 #ifndef SIMULATOR
2729 { "View HW info", dbg_hw_info },
2730 #endif
2731 #ifndef SIMULATOR
2732 { "View partitions", dbg_partitions },
2733 #endif
2734 #ifndef SIMULATOR
2735 { "View disk info", dbg_disk_info },
2736 #if (CONFIG_STORAGE & STORAGE_ATA)
2737 { "Dump ATA identify info", dbg_identify_info},
2738 #endif
2739 #endif
2740 #ifdef HAVE_DIRCACHE
2741 { "View dircache info", dbg_dircache_info },
2742 #endif
2743 #ifdef HAVE_TAGCACHE
2744 { "View database info", dbg_tagcache_info },
2745 #endif
2746 #ifdef HAVE_LCD_BITMAP
2747 #if CONFIG_CODEC == SWCODEC
2748 { "View buffering thread", dbg_buffering_thread },
2749 #elif !defined(SIMULATOR)
2750 { "View audio thread", dbg_audio_thread },
2751 #endif
2752 #ifdef PM_DEBUG
2753 { "pm histogram", peak_meter_histogram},
2754 #endif /* PM_DEBUG */
2755 #endif /* HAVE_LCD_BITMAP */
2756 #ifndef SIMULATOR
2757 #if CONFIG_TUNER
2758 { "FM Radio", dbg_fm_radio },
2759 #endif
2760 #endif
2761 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2762 { "Write back EEPROM", dbg_write_eeprom },
2763 #endif
2764 #if CONFIG_USBOTG == USBOTG_ISP1583
2765 { "View ISP1583 info", dbg_isp1583 },
2766 #endif
2767 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2768 { "View PIC info", dbg_pic },
2769 #endif
2770 #ifdef ROCKBOX_HAS_LOGF
2771 {"logf", logfdisplay },
2772 {"logfdump", logfdump },
2773 #endif
2774 #if defined(HAVE_USBSTACK)
2775 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2776 {"USB Serial driver (logf)", toggle_usb_serial },
2777 #endif
2778 #endif /* HAVE_USBSTACK */
2779 #ifdef CPU_BOOST_LOGGING
2780 {"cpu_boost log",cpu_boost_log},
2781 #endif
2782 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2783 {"Debug scrollwheel", dbg_scrollwheel },
2784 #endif
2786 static int menu_action_callback(int btn, struct gui_synclist *lists)
2788 if (btn == ACTION_STD_OK)
2790 int oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL);
2791 menuitems[gui_synclist_get_sel_pos(lists)].function();
2792 btn = ACTION_REDRAW;
2793 viewportmanager_set_statusbar(oldbars);
2795 return btn;
2797 static char* dbg_menu_getname(int item, void * data,
2798 char *buffer, size_t buffer_len)
2800 (void)data; (void)buffer; (void)buffer_len;
2801 return menuitems[item].desc;
2803 bool debug_menu(void)
2805 struct simplelist_info info;
2807 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2808 info.action_callback = menu_action_callback;
2809 info.get_name = dbg_menu_getname;
2810 return simplelist_show_list(&info);