User definable UI viewport, to be able to restrict the UI into a viewport for all...
[kugel-rb/myfork.git] / apps / debug_menu.c
blobea53d445fd25b3b7616ead1c28921c9c67c9be9b
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 #include "debug-target.h"
108 #endif
110 #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) \
111 || defined(SANSA_CLIP) || defined(SANSA_FUZE)
112 #include "ascodec.h"
113 #include "as3514.h"
114 #endif
116 #ifdef HAVE_USBSTACK
117 #include "usb_core.h"
118 #endif
120 /*---------------------------------------------------*/
121 /* SPECIAL DEBUG STUFF */
122 /*---------------------------------------------------*/
123 extern struct thread_entry threads[MAXTHREADS];
125 static char thread_status_char(unsigned status)
127 static const char thread_status_chars[THREAD_NUM_STATES+1] =
129 [0 ... THREAD_NUM_STATES] = '?',
130 [STATE_RUNNING] = 'R',
131 [STATE_BLOCKED] = 'B',
132 [STATE_SLEEPING] = 'S',
133 [STATE_BLOCKED_W_TMO] = 'T',
134 [STATE_FROZEN] = 'F',
135 [STATE_KILLED] = 'K',
138 if (status > THREAD_NUM_STATES)
139 status = THREAD_NUM_STATES;
141 return thread_status_chars[status];
144 static char* threads_getname(int selected_item, void *data,
145 char *buffer, size_t buffer_len)
147 (void)data;
148 struct thread_entry *thread;
149 char name[32];
151 #if NUM_CORES > 1
152 if (selected_item < (int)NUM_CORES)
154 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
155 idle_stack_usage(selected_item));
156 return buffer;
159 selected_item -= NUM_CORES;
160 #endif
162 thread = &threads[selected_item];
164 if (thread->state == STATE_KILLED)
166 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
167 return buffer;
170 thread_get_name(name, 32, thread);
172 snprintf(buffer, buffer_len,
173 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
174 selected_item,
175 IF_COP(thread->core,)
176 #ifdef HAVE_SCHEDULER_BOOSTCTRL
177 (thread->cpu_boost) ? '+' :
178 #endif
179 ((thread->state == STATE_RUNNING) ? '*' : ' '),
180 thread_status_char(thread->state),
181 IF_PRIO(thread->base_priority, thread->priority, )
182 thread_stack_usage(thread), name);
184 return buffer;
186 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
188 (void)lists;
189 #ifdef ROCKBOX_HAS_LOGF
190 if (action == ACTION_STD_OK)
192 int selpos = gui_synclist_get_sel_pos(lists);
193 #if NUM_CORES > 1
194 if (selpos >= NUM_CORES)
195 remove_thread(threads[selpos - NUM_CORES].id);
196 #else
197 remove_thread(threads[selpos].id);
198 #endif
199 return ACTION_REDRAW;
201 #endif /* ROCKBOX_HAS_LOGF */
202 if (action == ACTION_NONE)
203 action = ACTION_REDRAW;
204 return action;
206 /* Test code!!! */
207 static bool dbg_os(void)
209 struct simplelist_info info;
210 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
211 #if NUM_CORES == 1
212 MAXTHREADS,
213 #else
214 MAXTHREADS+NUM_CORES,
215 #endif
216 NULL);
217 #ifndef ROCKBOX_HAS_LOGF
218 info.hide_selection = true;
219 info.scroll_all = true;
220 #endif
221 info.action_callback = dbg_threads_action_callback;
222 info.get_name = threads_getname;
223 return simplelist_show_list(&info);
226 #ifdef HAVE_LCD_BITMAP
227 #if CONFIG_CODEC != SWCODEC
228 #ifndef SIMULATOR
229 static bool dbg_audio_thread(void)
231 char buf[32];
232 struct audio_debug d;
234 lcd_setfont(FONT_SYSFIXED);
236 while(1)
238 if (action_userabort(HZ/5))
239 return false;
241 audio_get_debugdata(&d);
243 lcd_clear_display();
245 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
246 lcd_puts(0, 0, buf);
247 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
248 lcd_puts(0, 1, buf);
249 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
250 lcd_puts(0, 2, buf);
251 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
252 lcd_puts(0, 3, buf);
253 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
254 lcd_puts(0, 4, buf);
255 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
256 lcd_puts(0, 5, buf);
258 /* Playable space left */
259 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
260 d.playable_space, HORIZONTAL);
262 /* Show the watermark limit */
263 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
264 d.low_watermark_level, HORIZONTAL);
266 snprintf(buf, sizeof(buf), "wm: %x - %x",
267 d.low_watermark_level, d.lowest_watermark_level);
268 lcd_puts(0, 7, buf);
270 lcd_update();
272 lcd_setfont(FONT_UI);
273 return false;
275 #endif /* !SIMULATOR */
276 #else /* CONFIG_CODEC == SWCODEC */
277 extern size_t filebuflen;
278 /* This is a size_t, but call it a long so it puts a - when it's bad. */
280 static unsigned int ticks, boost_ticks, freq_sum;
282 static void dbg_audio_task(void)
284 #ifndef SIMULATOR
285 if(FREQ > CPUFREQ_NORMAL)
286 boost_ticks++;
287 freq_sum += FREQ/1000000; /* in MHz */
288 #endif
289 ticks++;
292 static bool dbg_buffering_thread(void)
294 char buf[32];
295 int button;
296 int line;
297 bool done = false;
298 size_t bufused;
299 size_t bufsize = pcmbuf_get_bufsize();
300 int pcmbufdescs = pcmbuf_descs();
301 struct buffering_debug d;
303 ticks = boost_ticks = freq_sum = 0;
305 tick_add_task(dbg_audio_task);
307 lcd_setfont(FONT_SYSFIXED);
308 while(!done)
310 button = get_action(CONTEXT_STD,HZ/5);
311 switch(button)
313 case ACTION_STD_NEXT:
314 audio_next();
315 break;
316 case ACTION_STD_PREV:
317 audio_prev();
318 break;
319 case ACTION_STD_CANCEL:
320 done = true;
321 break;
324 buffering_get_debugdata(&d);
326 line = 0;
327 lcd_clear_display();
329 bufused = bufsize - pcmbuf_free();
331 snprintf(buf, sizeof(buf), "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
332 lcd_puts(0, line++, buf);
334 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
335 bufsize, 0, bufused, HORIZONTAL);
336 line++;
338 snprintf(buf, sizeof(buf), "alloc: %6ld/%ld", audio_filebufused(),
339 (long) filebuflen);
340 lcd_puts(0, line++, buf);
342 #if LCD_HEIGHT > 80
343 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
344 filebuflen, 0, audio_filebufused(), HORIZONTAL);
345 line++;
347 snprintf(buf, sizeof(buf), "real: %6ld/%ld", (long)d.buffered_data,
348 (long)filebuflen);
349 lcd_puts(0, line++, buf);
351 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
352 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
353 line++;
354 #endif
356 snprintf(buf, sizeof(buf), "usefl: %6ld/%ld", (long)(d.useful_data),
357 (long)filebuflen);
358 lcd_puts(0, line++, buf);
360 #if LCD_HEIGHT > 80
361 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
362 filebuflen, 0, d.useful_data, HORIZONTAL);
363 line++;
364 #endif
366 snprintf(buf, sizeof(buf), "data_rem: %ld", (long)d.data_rem);
367 lcd_puts(0, line++, buf);
369 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
370 lcd_puts(0, line++, buf);
372 snprintf(buf, sizeof(buf), "handle count: %d", (int)d.num_handles);
373 lcd_puts(0, line++, buf);
375 #ifndef SIMULATOR
376 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
377 (int)((FREQ + 500000) / 1000000));
378 lcd_puts(0, line++, buf);
379 #endif
381 if (ticks > 0)
383 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
384 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
385 snprintf(buf, sizeof(buf), "boost:%3d.%d%% (%d.%dMHz)",
386 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
387 lcd_puts(0, line++, buf);
390 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
391 pcmbuf_used_descs(), pcmbufdescs);
392 lcd_puts(0, line++, buf);
393 snprintf(buf, sizeof(buf), "watermark: %6d",
394 (int)(d.watermark));
395 lcd_puts(0, line++, buf);
397 lcd_update();
400 tick_remove_task(dbg_audio_task);
401 lcd_setfont(FONT_UI);
403 return false;
405 #endif /* CONFIG_CODEC */
406 #endif /* HAVE_LCD_BITMAP */
409 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
410 /* Tool function to read the flash manufacturer and type, if available.
411 Only chips which could be reprogrammed in system will return values.
412 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
413 /* In IRAM to avoid problems when running directly from Flash */
414 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
415 unsigned addr1, unsigned addr2)
416 ICODE_ATTR __attribute__((noinline));
417 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
418 unsigned addr1, unsigned addr2)
421 unsigned not_manu, not_id; /* read values before switching to ID mode */
422 unsigned manu, id; /* read values when in ID mode */
424 #if CONFIG_CPU == SH7034
425 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
426 #elif defined(CPU_COLDFIRE)
427 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
428 #endif
429 int old_level; /* saved interrupt level */
431 not_manu = flash[0]; /* read the normal content */
432 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
434 /* disable interrupts, prevent any stray flash access */
435 old_level = disable_irq_save();
437 flash[addr1] = 0xAA; /* enter command mode */
438 flash[addr2] = 0x55;
439 flash[addr1] = 0x90; /* ID command */
440 /* Atmel wants 20ms pause here */
441 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
443 manu = flash[0]; /* read the IDs */
444 id = flash[1];
446 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
447 /* Atmel wants 20ms pause here */
448 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
450 restore_irq(old_level); /* enable interrupts again */
452 /* I assume success if the obtained values are different from
453 the normal flash content. This is not perfectly bulletproof, they
454 could theoretically be the same by chance, causing us to fail. */
455 if (not_manu != manu || not_id != id) /* a value has changed */
457 *p_manufacturer = manu; /* return the results */
458 *p_device = id;
459 return true; /* success */
461 return false; /* fail */
463 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
465 #ifndef SIMULATOR
466 #ifdef CPU_PP
467 static int perfcheck(void)
469 int result;
471 asm (
472 "mrs r2, CPSR \n"
473 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
474 "msr CPSR_c, r0 \n"
475 "mov %[res], #0 \n"
476 "ldr r0, [%[timr]] \n"
477 "add r0, r0, %[tmo] \n"
478 "1: \n"
479 "add %[res], %[res], #1 \n"
480 "ldr r1, [%[timr]] \n"
481 "cmp r1, r0 \n"
482 "bmi 1b \n"
483 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
485 [res]"=&r"(result)
487 [timr]"r"(&USEC_TIMER),
488 [tmo]"r"(
489 #if CONFIG_CPU == PP5002
490 16000
491 #else /* PP5020/5022/5024 */
492 10226
493 #endif
496 "r0", "r1", "r2"
498 return result;
500 #endif
502 #ifdef HAVE_LCD_BITMAP
503 static bool dbg_hw_info(void)
505 #if CONFIG_CPU == SH7034
506 char buf[32];
507 int bitmask = HW_MASK;
508 int rom_version = ROM_VERSION;
509 unsigned manu, id; /* flash IDs */
510 bool got_id; /* flag if we managed to get the flash IDs */
511 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
512 bool has_bootrom; /* flag for boot ROM present */
513 int oldmode; /* saved memory guard mode */
515 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
517 /* get flash ROM type */
518 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
519 if (!got_id)
520 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
522 /* check if the boot ROM area is a flash mirror */
523 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
524 if (has_bootrom) /* if ROM and Flash different */
526 /* calculate CRC16 checksum of boot ROM */
527 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
530 system_memory_guard(oldmode); /* re-enable memory guard */
532 lcd_setfont(FONT_SYSFIXED);
533 lcd_clear_display();
535 lcd_puts(0, 0, "[Hardware info]");
537 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
538 lcd_puts(0, 1, buf);
540 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
541 lcd_puts(0, 2, buf);
543 if (got_id)
544 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
545 else
546 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
547 lcd_puts(0, 3, buf);
549 if (has_bootrom)
551 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
552 snprintf(buf, 32, "Boot ROM: V1");
553 else
554 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
556 else
558 snprintf(buf, 32, "Boot ROM: none");
560 lcd_puts(0, 4, buf);
562 lcd_update();
564 while (!(action_userabort(TIMEOUT_BLOCK)));
566 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
567 char buf[32];
568 unsigned manu, id; /* flash IDs */
569 int got_id; /* flag if we managed to get the flash IDs */
570 int oldmode; /* saved memory guard mode */
571 int line = 0;
573 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
575 /* get flash ROM type */
576 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
577 if (!got_id)
578 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
580 system_memory_guard(oldmode); /* re-enable memory guard */
582 lcd_setfont(FONT_SYSFIXED);
583 lcd_clear_display();
585 lcd_puts(0, line++, "[Hardware info]");
587 if (got_id)
588 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
589 else
590 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
591 lcd_puts(0, line++, buf);
593 #ifdef IAUDIO_X5
595 struct ds2411_id id;
597 lcd_puts(0, ++line, "Serial Number:");
599 got_id = ds2411_read_id(&id);
601 if (got_id == DS2411_OK)
603 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
604 lcd_puts(0, ++line, buf);
605 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
606 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
607 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
608 lcd_puts(0, ++line, buf);
609 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
611 else
613 snprintf(buf, 32, "READ ERR=%d", got_id);
616 lcd_puts(0, ++line, buf);
618 #endif
620 lcd_update();
622 while (!(action_userabort(TIMEOUT_BLOCK)));
624 #elif defined(CPU_PP502x)
625 int line = 0;
626 char buf[32];
627 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
628 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
629 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
630 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
632 lcd_setfont(FONT_SYSFIXED);
633 lcd_clear_display();
635 lcd_puts(0, line++, "[Hardware info]");
637 #ifdef IPOD_ARCH
638 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
639 lcd_puts(0, line++, buf);
640 #endif
642 #ifdef IPOD_COLOR
643 extern int lcd_type; /* Defined in lcd-colornano.c */
645 snprintf(buf, sizeof(buf), "LCD type: %d", lcd_type);
646 lcd_puts(0, line++, buf);
647 #endif
649 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
650 lcd_puts(0, line++, buf);
652 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
653 lcd_puts(0, line++, buf);
655 lcd_update();
657 while (!(action_userabort(TIMEOUT_BLOCK)));
659 #elif CONFIG_CPU == PP5002
660 int line = 0;
661 char buf[32];
662 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
663 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
664 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
665 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
668 lcd_setfont(FONT_SYSFIXED);
669 lcd_clear_display();
671 lcd_puts(0, line++, "[Hardware info]");
673 #ifdef IPOD_ARCH
674 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
675 lcd_puts(0, line++, buf);
676 #endif
678 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
679 lcd_puts(0, line++, buf);
681 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
682 lcd_puts(0, line++, buf);
684 lcd_update();
686 while (!(action_userabort(TIMEOUT_BLOCK)));
688 #else
689 /* Define this function in your target tree */
690 return __dbg_hw_info();
691 #endif /* CONFIG_CPU */
692 lcd_setfont(FONT_UI);
693 return false;
695 #else /* !HAVE_LCD_BITMAP */
696 static bool dbg_hw_info(void)
698 char buf[32];
699 int button;
700 int currval = 0;
701 int rom_version = ROM_VERSION;
702 unsigned manu, id; /* flash IDs */
703 bool got_id; /* flag if we managed to get the flash IDs */
704 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
705 bool has_bootrom; /* flag for boot ROM present */
706 int oldmode; /* saved memory guard mode */
708 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
710 /* get flash ROM type */
711 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
712 if (!got_id)
713 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
715 /* check if the boot ROM area is a flash mirror */
716 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
717 if (has_bootrom) /* if ROM and Flash different */
719 /* calculate CRC16 checksum of boot ROM */
720 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
723 system_memory_guard(oldmode); /* re-enable memory guard */
725 lcd_clear_display();
727 lcd_puts(0, 0, "[HW Info]");
728 while(1)
730 switch(currval)
732 case 0:
733 snprintf(buf, 32, "ROM: %d.%02d",
734 rom_version/100, rom_version%100);
735 break;
736 case 1:
737 if (got_id)
738 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
739 else
740 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
741 break;
742 case 2:
743 if (has_bootrom)
745 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
746 snprintf(buf, 32, "BootROM: V1");
747 else if (rom_crc == 0x358099E8)
748 snprintf(buf, 32, "BootROM: V2");
749 /* alternative boot ROM found in one single player so far */
750 else
751 snprintf(buf, 32, "R: %08x", rom_crc);
753 else
754 snprintf(buf, 32, "BootROM: no");
757 lcd_puts(0, 1, buf);
758 lcd_update();
760 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
762 switch(button)
764 case ACTION_STD_CANCEL:
765 return false;
767 case ACTION_SETTINGS_DEC:
768 currval--;
769 if(currval < 0)
770 currval = 2;
771 break;
773 case ACTION_SETTINGS_INC:
774 currval++;
775 if(currval > 2)
776 currval = 0;
777 break;
780 return false;
782 #endif /* !HAVE_LCD_BITMAP */
783 #endif /* !SIMULATOR */
785 #ifndef SIMULATOR
786 static char* dbg_partitions_getname(int selected_item, void *data,
787 char *buffer, size_t buffer_len)
789 (void)data;
790 int partition = selected_item/2;
791 struct partinfo* p = disk_partinfo(partition);
792 if (selected_item%2)
794 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / 2048);
796 else
798 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
800 return buffer;
803 bool dbg_partitions(void)
805 struct simplelist_info info;
806 simplelist_info_init(&info, "Partition Info", 4, NULL);
807 info.selection_size = 2;
808 info.hide_selection = true;
809 info.scroll_all = true;
810 info.get_name = dbg_partitions_getname;
811 return simplelist_show_list(&info);
813 #endif
815 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
816 static bool dbg_spdif(void)
818 char buf[128];
819 int line;
820 unsigned int control;
821 int x;
822 char *s;
823 int category;
824 int generation;
825 unsigned int interruptstat;
826 bool valnogood, symbolerr, parityerr;
827 bool done = false;
828 bool spdif_src_on;
829 int spdif_source = spdif_get_output_source(&spdif_src_on);
830 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
832 lcd_clear_display();
833 lcd_setfont(FONT_SYSFIXED);
835 #ifdef HAVE_SPDIF_POWER
836 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
837 #endif
839 while (!done)
841 line = 0;
843 control = EBU1RCVCCHANNEL1;
844 interruptstat = INTERRUPTSTAT;
845 INTERRUPTCLEAR = 0x03c00000;
847 valnogood = (interruptstat & 0x01000000)?true:false;
848 symbolerr = (interruptstat & 0x00800000)?true:false;
849 parityerr = (interruptstat & 0x00400000)?true:false;
851 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
852 valnogood?"--":"OK",
853 symbolerr?"--":"OK",
854 parityerr?"--":"OK");
855 lcd_puts(0, line++, buf);
857 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
858 lcd_puts(0, line++, buf);
860 line++;
862 x = control >> 31;
863 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
864 x, x?"Professional":"Consumer");
865 lcd_puts(0, line++, buf);
867 x = (control >> 30) & 1;
868 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
869 x, x?"Non-PCM":"PCM");
870 lcd_puts(0, line++, buf);
872 x = (control >> 29) & 1;
873 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
874 x, x?"Permitted":"Inhibited");
875 lcd_puts(0, line++, buf);
877 x = (control >> 27) & 7;
878 switch(x)
880 case 0:
881 s = "None";
882 break;
883 case 1:
884 s = "50/15us";
885 break;
886 default:
887 s = "Reserved";
888 break;
890 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
891 lcd_puts(0, line++, buf);
893 x = (control >> 24) & 3;
894 snprintf(buf, sizeof(buf), "Mode: %d", x);
895 lcd_puts(0, line++, buf);
897 category = (control >> 17) & 127;
898 switch(category)
900 case 0x00:
901 s = "General";
902 break;
903 case 0x40:
904 s = "Audio CD";
905 break;
906 default:
907 s = "Unknown";
909 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
910 lcd_puts(0, line++, buf);
912 x = (control >> 16) & 1;
913 generation = x;
914 if(((category & 0x70) == 0x10) ||
915 ((category & 0x70) == 0x40) ||
916 ((category & 0x78) == 0x38))
918 generation = !generation;
920 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
921 x, generation?"Original":"No ind.");
922 lcd_puts(0, line++, buf);
924 x = (control >> 12) & 15;
925 snprintf(buf, sizeof(buf), "Source: %d", x);
926 lcd_puts(0, line++, buf);
928 x = (control >> 8) & 15;
929 switch(x)
931 case 0:
932 s = "Unspecified";
933 break;
934 case 8:
935 s = "A (Left)";
936 break;
937 case 4:
938 s = "B (Right)";
939 break;
940 default:
941 s = "";
942 break;
944 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
945 lcd_puts(0, line++, buf);
947 x = (control >> 4) & 15;
948 switch(x)
950 case 0:
951 s = "44.1kHz";
952 break;
953 case 0x4:
954 s = "48kHz";
955 break;
956 case 0xc:
957 s = "32kHz";
958 break;
960 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
961 lcd_puts(0, line++, buf);
963 x = (control >> 2) & 3;
964 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
965 lcd_puts(0, line++, buf);
966 line++;
968 #ifndef SIMULATOR
969 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
970 spdif_measure_frequency());
971 lcd_puts(0, line++, buf);
972 #endif
974 lcd_update();
976 if (action_userabort(HZ/10))
977 break;
980 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
982 #ifdef HAVE_SPDIF_POWER
983 spdif_power_enable(global_settings.spdif_enable);
984 #endif
986 lcd_setfont(FONT_UI);
987 return false;
989 #endif /* CPU_COLDFIRE */
991 #ifndef SIMULATOR
992 #ifdef HAVE_LCD_BITMAP
993 /* button definitions */
994 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
995 (CONFIG_KEYPAD == IRIVER_H300_PAD)
996 # define DEBUG_CANCEL BUTTON_OFF
998 #elif CONFIG_KEYPAD == RECORDER_PAD
999 # define DEBUG_CANCEL BUTTON_OFF
1001 #elif CONFIG_KEYPAD == ONDIO_PAD
1002 # define DEBUG_CANCEL BUTTON_MENU
1004 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
1005 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
1006 (CONFIG_KEYPAD == IPOD_4G_PAD)
1007 # define DEBUG_CANCEL BUTTON_MENU
1009 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
1010 # define DEBUG_CANCEL BUTTON_PLAY
1012 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
1013 # define DEBUG_CANCEL BUTTON_REC
1015 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1016 # define DEBUG_CANCEL BUTTON_RC_REC
1018 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
1019 # define DEBUG_CANCEL BUTTON_REW
1021 #elif (CONFIG_KEYPAD == MROBE100_PAD)
1022 # define DEBUG_CANCEL BUTTON_MENU
1024 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
1025 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
1026 (CONFIG_KEYPAD == SANSA_FUZE_PAD)
1027 # define DEBUG_CANCEL BUTTON_LEFT
1029 /* This is temporary until the SA9200 touchpad works */
1030 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) || \
1031 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD)
1032 # define DEBUG_CANCEL BUTTON_POWER
1034 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
1035 # define DEBUG_CANCEL BUTTON_PLAY
1037 #endif /* key definitions */
1039 /* Test code!!! */
1040 bool dbg_ports(void)
1042 #if CONFIG_CPU == SH7034
1043 char buf[32];
1044 int adc_battery_voltage, adc_battery_level;
1046 lcd_setfont(FONT_SYSFIXED);
1047 lcd_clear_display();
1049 while(1)
1051 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1052 lcd_puts(0, 0, buf);
1053 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1054 lcd_puts(0, 1, buf);
1056 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1057 lcd_puts(0, 2, buf);
1058 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1059 lcd_puts(0, 3, buf);
1060 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1061 lcd_puts(0, 4, buf);
1062 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1063 lcd_puts(0, 5, buf);
1065 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1066 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1067 adc_battery_voltage % 1000, adc_battery_level);
1068 lcd_puts(0, 6, buf);
1070 lcd_update();
1071 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1073 lcd_setfont(FONT_UI);
1074 return false;
1077 #elif defined(CPU_COLDFIRE)
1078 unsigned int gpio_out;
1079 unsigned int gpio1_out;
1080 unsigned int gpio_read;
1081 unsigned int gpio1_read;
1082 unsigned int gpio_function;
1083 unsigned int gpio1_function;
1084 unsigned int gpio_enable;
1085 unsigned int gpio1_enable;
1086 int adc_buttons, adc_remote;
1087 int adc_battery_voltage, adc_battery_level;
1088 char buf[128];
1089 int line;
1091 lcd_clear_display();
1092 lcd_setfont(FONT_SYSFIXED);
1094 while(1)
1096 line = 0;
1097 gpio_read = GPIO_READ;
1098 gpio1_read = GPIO1_READ;
1099 gpio_out = GPIO_OUT;
1100 gpio1_out = GPIO1_OUT;
1101 gpio_function = GPIO_FUNCTION;
1102 gpio1_function = GPIO1_FUNCTION;
1103 gpio_enable = GPIO_ENABLE;
1104 gpio1_enable = GPIO1_ENABLE;
1106 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1107 lcd_puts(0, line++, buf);
1108 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1109 lcd_puts(0, line++, buf);
1110 snprintf(buf, sizeof(buf), "GPIO_FUNC: %08x", gpio_function);
1111 lcd_puts(0, line++, buf);
1112 snprintf(buf, sizeof(buf), "GPIO_ENA: %08x", gpio_enable);
1113 lcd_puts(0, line++, buf);
1115 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1116 lcd_puts(0, line++, buf);
1117 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1118 lcd_puts(0, line++, buf);
1119 snprintf(buf, sizeof(buf), "GPIO1_FUNC: %08x", gpio1_function);
1120 lcd_puts(0, line++, buf);
1121 snprintf(buf, sizeof(buf), "GPIO1_ENA: %08x", gpio1_enable);
1122 lcd_puts(0, line++, buf);
1124 adc_buttons = adc_read(ADC_BUTTONS);
1125 adc_remote = adc_read(ADC_REMOTE);
1126 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1127 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1128 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1129 button_scan_enabled() ? '+' : '-', adc_buttons);
1130 #else
1131 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1132 #endif
1133 lcd_puts(0, line++, buf);
1134 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1135 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1136 remote_detect() ? '+' : '-', adc_remote);
1137 #else
1138 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1139 #endif
1140 lcd_puts(0, line++, buf);
1141 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1142 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1143 adc_read(ADC_REMOTEDETECT));
1144 lcd_puts(0, line++, buf);
1145 #endif
1147 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1148 adc_battery_voltage % 1000, adc_battery_level);
1149 lcd_puts(0, line++, buf);
1151 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1152 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1153 lcd_puts(0, line++, buf);
1154 #endif
1156 lcd_update();
1157 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1159 lcd_setfont(FONT_UI);
1160 return false;
1164 #elif defined(CPU_PP502x)
1166 char buf[128];
1167 int line;
1169 lcd_clear_display();
1170 lcd_setfont(FONT_SYSFIXED);
1172 while(1)
1174 line = 0;
1175 lcd_puts(0, line++, "GPIO STATES:");
1176 snprintf(buf, sizeof(buf), "A: %02x E: %02x I: %02x",
1177 (unsigned int)GPIOA_INPUT_VAL,
1178 (unsigned int)GPIOE_INPUT_VAL,
1179 (unsigned int)GPIOI_INPUT_VAL);
1180 lcd_puts(0, line++, buf);
1181 snprintf(buf, sizeof(buf), "B: %02x F: %02x J: %02x",
1182 (unsigned int)GPIOB_INPUT_VAL,
1183 (unsigned int)GPIOF_INPUT_VAL,
1184 (unsigned int)GPIOJ_INPUT_VAL);
1185 lcd_puts(0, line++, buf);
1186 snprintf(buf, sizeof(buf), "C: %02x G: %02x K: %02x",
1187 (unsigned int)GPIOC_INPUT_VAL,
1188 (unsigned int)GPIOG_INPUT_VAL,
1189 (unsigned int)GPIOK_INPUT_VAL);
1190 lcd_puts(0, line++, buf);
1191 snprintf(buf, sizeof(buf), "D: %02x H: %02x L: %02x",
1192 (unsigned int)GPIOD_INPUT_VAL,
1193 (unsigned int)GPIOH_INPUT_VAL,
1194 (unsigned int)GPIOL_INPUT_VAL);
1195 lcd_puts(0, line++, buf);
1196 line++;
1197 snprintf(buf, sizeof(buf), "GPO32_VAL: %08lx", GPO32_VAL);
1198 lcd_puts(0, line++, buf);
1199 snprintf(buf, sizeof(buf), "GPO32_EN: %08lx", GPO32_ENABLE);
1200 lcd_puts(0, line++, buf);
1201 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1202 lcd_puts(0, line++, buf);
1203 snprintf(buf, sizeof(buf), "DEV_EN2: %08lx", DEV_EN2);
1204 lcd_puts(0, line++, buf);
1205 snprintf(buf, sizeof(buf), "DEV_EN3: %08lx", inl(0x60006044));
1206 lcd_puts(0, line++, buf); /* to be verified */
1207 snprintf(buf, sizeof(buf), "DEV_INIT1: %08lx", DEV_INIT1);
1208 lcd_puts(0, line++, buf);
1209 snprintf(buf, sizeof(buf), "DEV_INIT2: %08lx", DEV_INIT2);
1210 lcd_puts(0, line++, buf);
1211 #ifdef ADC_ACCESSORY
1212 snprintf(buf, sizeof(buf), "ACCESSORY: %d", adc_read(ADC_ACCESSORY));
1213 lcd_puts(0, line++, buf);
1214 #endif
1216 #if defined(IPOD_ACCESSORY_PROTOCOL)
1217 extern unsigned char serbuf[];
1218 snprintf(buf, sizeof(buf), "IAP PACKET: %02x %02x %02x %02x %02x %02x %02x %02x",
1219 serbuf[0], serbuf[1], serbuf[2], serbuf[3], serbuf[4], serbuf[5],
1220 serbuf[6], serbuf[7]);
1221 lcd_puts(0, line++, buf);
1222 #endif
1224 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1225 line++;
1226 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1227 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1228 lcd_puts(0, line++, buf);
1229 snprintf(buf, sizeof(buf), "REM: %03x PAD: %03x",
1230 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1231 lcd_puts(0, line++, buf);
1232 #elif defined(PHILIPS_HDD1630)
1233 line++;
1234 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1235 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1236 lcd_puts(0, line++, buf);
1237 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1238 snprintf(buf, sizeof(buf), "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1239 lcd_puts(0, line++, buf);
1240 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1241 lcd_puts(0, line++, buf);
1242 snprintf(buf, sizeof(buf), "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1243 lcd_puts(0, line++, buf);
1244 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1245 lcd_puts(0, line++, buf);
1246 snprintf(buf, sizeof(buf), "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1247 lcd_puts(0, line++, buf);
1248 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1249 lcd_puts(0, line++, buf);
1250 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1251 lcd_puts(0, line++, buf);
1252 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1253 lcd_puts(0, line++, buf);
1254 snprintf(buf, sizeof(buf), "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1255 lcd_puts(0, line++, buf);
1256 snprintf(buf, sizeof(buf), "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1257 lcd_puts(0, line++, buf);
1258 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1259 lcd_puts(0, line++, buf);
1260 #if !defined(PHILIPS_SA9200)
1261 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1262 lcd_puts(0, line++, buf);
1263 snprintf(buf, sizeof(buf), "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1264 lcd_puts(0, line++, buf);
1265 #endif
1266 #endif
1267 lcd_update();
1268 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1270 lcd_setfont(FONT_UI);
1271 return false;
1275 #elif CONFIG_CPU == PP5002
1276 char buf[128];
1277 int line;
1279 lcd_clear_display();
1280 lcd_setfont(FONT_SYSFIXED);
1282 while(1)
1284 line = 0;
1285 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x",
1286 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1287 lcd_puts(0, line++, buf);
1288 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x",
1289 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1290 lcd_puts(0, line++, buf);
1292 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1293 lcd_puts(0, line++, buf);
1294 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1295 lcd_puts(0, line++, buf);
1296 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1297 lcd_puts(0, line++, buf);
1298 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1299 lcd_puts(0, line++, buf);
1300 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1301 lcd_puts(0, line++, buf);
1302 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1303 lcd_puts(0, line++, buf);
1304 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1305 lcd_puts(0, line++, buf);
1306 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1307 lcd_puts(0, line++, buf);
1309 lcd_update();
1310 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1312 lcd_setfont(FONT_UI);
1313 return false;
1316 lcd_setfont(FONT_UI);
1317 #else
1318 return __dbg_ports();
1319 #endif /* CPU */
1320 return false;
1322 #else /* !HAVE_LCD_BITMAP */
1323 bool dbg_ports(void)
1325 char buf[32];
1326 int button;
1327 int adc_battery_voltage;
1328 int currval = 0;
1330 lcd_clear_display();
1332 while(1)
1334 switch(currval)
1336 case 0:
1337 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1338 break;
1339 case 1:
1340 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1341 break;
1342 case 2:
1343 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1344 break;
1345 case 3:
1346 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1347 break;
1348 case 4:
1349 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1350 break;
1351 case 5:
1352 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1353 break;
1354 case 6:
1355 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1356 break;
1357 case 7:
1358 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1359 break;
1360 case 8:
1361 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1362 break;
1363 case 9:
1364 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1365 break;
1367 lcd_puts(0, 0, buf);
1369 battery_read_info(&adc_battery_voltage, NULL);
1370 snprintf(buf, 32, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1371 adc_battery_voltage % 1000);
1372 lcd_puts(0, 1, buf);
1373 lcd_update();
1375 button = get_action(CONTEXT_SETTINGS,HZ/5);
1377 switch(button)
1379 case ACTION_STD_CANCEL:
1380 return false;
1382 case ACTION_SETTINGS_DEC:
1383 currval--;
1384 if(currval < 0)
1385 currval = 9;
1386 break;
1388 case ACTION_SETTINGS_INC:
1389 currval++;
1390 if(currval > 9)
1391 currval = 0;
1392 break;
1395 return false;
1397 #endif /* !HAVE_LCD_BITMAP */
1398 #endif /* !SIMULATOR */
1400 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1401 static bool dbg_pcf(void)
1403 char buf[128];
1404 int line;
1406 #ifdef HAVE_LCD_BITMAP
1407 lcd_setfont(FONT_SYSFIXED);
1408 #endif
1409 lcd_clear_display();
1411 while(1)
1413 line = 0;
1415 snprintf(buf, sizeof(buf), "DCDC1: %02x", pcf50605_read(0x1b));
1416 lcd_puts(0, line++, buf);
1417 snprintf(buf, sizeof(buf), "DCDC2: %02x", pcf50605_read(0x1c));
1418 lcd_puts(0, line++, buf);
1419 snprintf(buf, sizeof(buf), "DCDC3: %02x", pcf50605_read(0x1d));
1420 lcd_puts(0, line++, buf);
1421 snprintf(buf, sizeof(buf), "DCDC4: %02x", pcf50605_read(0x1e));
1422 lcd_puts(0, line++, buf);
1423 snprintf(buf, sizeof(buf), "DCDEC1: %02x", pcf50605_read(0x1f));
1424 lcd_puts(0, line++, buf);
1425 snprintf(buf, sizeof(buf), "DCDEC2: %02x", pcf50605_read(0x20));
1426 lcd_puts(0, line++, buf);
1427 snprintf(buf, sizeof(buf), "DCUDC1: %02x", pcf50605_read(0x21));
1428 lcd_puts(0, line++, buf);
1429 snprintf(buf, sizeof(buf), "DCUDC2: %02x", pcf50605_read(0x22));
1430 lcd_puts(0, line++, buf);
1431 snprintf(buf, sizeof(buf), "IOREGC: %02x", pcf50605_read(0x23));
1432 lcd_puts(0, line++, buf);
1433 snprintf(buf, sizeof(buf), "D1REGC: %02x", pcf50605_read(0x24));
1434 lcd_puts(0, line++, buf);
1435 snprintf(buf, sizeof(buf), "D2REGC: %02x", pcf50605_read(0x25));
1436 lcd_puts(0, line++, buf);
1437 snprintf(buf, sizeof(buf), "D3REGC: %02x", pcf50605_read(0x26));
1438 lcd_puts(0, line++, buf);
1439 snprintf(buf, sizeof(buf), "LPREG1: %02x", pcf50605_read(0x27));
1440 lcd_puts(0, line++, buf);
1442 lcd_update();
1443 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1445 lcd_setfont(FONT_UI);
1446 return false;
1450 lcd_setfont(FONT_UI);
1451 return false;
1453 #endif
1455 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1456 static bool dbg_cpufreq(void)
1458 char buf[128];
1459 int line;
1460 int button;
1462 #ifdef HAVE_LCD_BITMAP
1463 lcd_setfont(FONT_SYSFIXED);
1464 #endif
1465 lcd_clear_display();
1467 while(1)
1469 line = 0;
1471 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1472 lcd_puts(0, line++, buf);
1474 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1475 lcd_puts(0, line++, buf);
1477 lcd_update();
1478 button = get_action(CONTEXT_STD,HZ/10);
1480 switch(button)
1482 case ACTION_STD_PREV:
1483 cpu_boost(true);
1484 break;
1486 case ACTION_STD_NEXT:
1487 cpu_boost(false);
1488 break;
1490 case ACTION_STD_OK:
1491 while (get_cpu_boost_counter() > 0)
1492 cpu_boost(false);
1493 set_cpu_frequency(CPUFREQ_DEFAULT);
1494 break;
1496 case ACTION_STD_CANCEL:
1497 lcd_setfont(FONT_UI);
1498 return false;
1501 lcd_setfont(FONT_UI);
1502 return false;
1504 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1506 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1507 #include "tsc2100.h"
1508 static char *itob(int n, int len)
1510 static char binary[64];
1511 int i,j;
1512 for (i=1, j=0;i<=len;i++)
1514 binary[j++] = n&(1<<(len-i))?'1':'0';
1515 if (i%4 == 0)
1516 binary[j++] = ' ';
1518 binary[j] = '\0';
1519 return binary;
1521 static char* tsc2100_debug_getname(int selected_item, void * data,
1522 char *buffer, size_t buffer_len)
1524 int *page = (int*)data;
1525 bool reserved = false;
1526 switch (*page)
1528 case 0:
1529 if ((selected_item > 0x0a) ||
1530 (selected_item == 0x04) ||
1531 (selected_item == 0x08))
1532 reserved = true;
1533 break;
1534 case 1:
1535 if ((selected_item > 0x05) ||
1536 (selected_item == 0x02))
1537 reserved = true;
1538 break;
1539 case 2:
1540 if (selected_item > 0x1e)
1541 reserved = true;
1542 break;
1544 if (reserved)
1545 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1546 else
1547 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1548 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1549 return buffer;
1551 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1553 int *page = (int*)lists->data;
1554 if (action == ACTION_STD_OK)
1556 *page = (*page+1)%3;
1557 snprintf(lists->title, 32,
1558 "tsc2100 registers - Page %d", *page);
1559 return ACTION_REDRAW;
1561 return action;
1563 static bool tsc2100_debug(void)
1565 int page = 0;
1566 char title[32] = "tsc2100 registers - Page 0";
1567 struct simplelist_info info;
1568 simplelist_info_init(&info, title, 32, &page);
1569 info.timeout = HZ/100;
1570 info.get_name = tsc2100_debug_getname;
1571 info.action_callback= tsc2100debug_action_callback;
1572 return simplelist_show_list(&info);
1574 #endif
1575 #ifndef SIMULATOR
1576 #ifdef HAVE_LCD_BITMAP
1578 * view_battery() shows a automatically scaled graph of the battery voltage
1579 * over time. Usable for estimating battery life / charging rate.
1580 * The power_history array is updated in power_thread of powermgmt.c.
1583 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1584 #define BAT_YSPACE (LCD_HEIGHT - 20)
1586 static bool view_battery(void)
1588 int view = 0;
1589 int i, x, y;
1590 unsigned short maxv, minv;
1591 char buf[32];
1593 lcd_setfont(FONT_SYSFIXED);
1595 while(1)
1597 lcd_clear_display();
1598 switch (view) {
1599 case 0: /* voltage history graph */
1600 /* Find maximum and minimum voltage for scaling */
1601 minv = power_history[0];
1602 maxv = minv + 1;
1603 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1604 if (power_history[i] > maxv)
1605 maxv = power_history[i];
1606 if (power_history[i] < minv)
1607 minv = power_history[i];
1610 snprintf(buf, 30, "Battery %d.%03d", power_history[0] / 1000,
1611 power_history[0] % 1000);
1612 lcd_puts(0, 0, buf);
1613 snprintf(buf, 30, "scale %d.%03d-%d.%03dV",
1614 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1615 lcd_puts(0, 1, buf);
1617 x = 0;
1618 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1619 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1620 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1621 lcd_vline(x, LCD_HEIGHT-1, 20);
1622 lcd_set_drawmode(DRMODE_SOLID);
1623 lcd_vline(x, LCD_HEIGHT-1,
1624 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1625 x++;
1628 break;
1630 case 1: /* status: */
1631 lcd_puts(0, 0, "Power status:");
1633 battery_read_info(&y, NULL);
1634 snprintf(buf, 30, "Battery: %d.%03d V", y / 1000, y % 1000);
1635 lcd_puts(0, 1, buf);
1636 #ifdef ADC_EXT_POWER
1637 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1638 snprintf(buf, 30, "External: %d.%03d V", y / 1000, y % 1000);
1639 lcd_puts(0, 2, buf);
1640 #endif
1641 #if CONFIG_CHARGING
1642 #if defined ARCHOS_RECORDER
1643 snprintf(buf, 30, "Chgr: %s %s",
1644 charger_inserted() ? "present" : "absent",
1645 charger_enabled() ? "on" : "off");
1646 lcd_puts(0, 3, buf);
1647 snprintf(buf, 30, "short delta: %d", short_delta);
1648 lcd_puts(0, 5, buf);
1649 snprintf(buf, 30, "long delta: %d", long_delta);
1650 lcd_puts(0, 6, buf);
1651 lcd_puts(0, 7, power_message);
1652 snprintf(buf, 30, "USB Inserted: %s",
1653 usb_inserted() ? "yes" : "no");
1654 lcd_puts(0, 8, buf);
1655 #elif defined IRIVER_H300_SERIES
1656 snprintf(buf, 30, "USB Charging Enabled: %s",
1657 usb_charging_enabled() ? "yes" : "no");
1658 lcd_puts(0, 9, buf);
1659 #elif defined IPOD_NANO || defined IPOD_VIDEO
1660 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1661 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1662 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1663 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1664 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1666 snprintf(buf, 30, "USB pwr: %s",
1667 usb_pwr ? "present" : "absent");
1668 lcd_puts(0, 3, buf);
1669 snprintf(buf, 30, "EXT pwr: %s",
1670 ext_pwr ? "present" : "absent");
1671 lcd_puts(0, 4, buf);
1672 snprintf(buf, 30, "Battery: %s",
1673 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1674 lcd_puts(0, 5, buf);
1675 snprintf(buf, 30, "Dock mode: %s",
1676 dock ? "enabled" : "disabled");
1677 lcd_puts(0, 6, buf);
1678 snprintf(buf, 30, "Headphone: %s",
1679 headphone ? "connected" : "disconnected");
1680 lcd_puts(0, 7, buf);
1681 #elif defined TOSHIBA_GIGABEAT_S
1682 int line = 3;
1683 unsigned int st;
1685 static const unsigned char * const chrgstate_strings[] =
1687 "Disabled",
1688 "Error",
1689 "Discharging",
1690 "Precharge",
1691 "Constant Voltage",
1692 "Constant Current",
1693 "<unknown>",
1696 snprintf(buf, 30, "Charger: %s",
1697 charger_inserted() ? "present" : "absent");
1698 lcd_puts(0, line++, buf);
1700 st = power_input_status() &
1701 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1702 snprintf(buf, 30, "%s%s",
1703 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1704 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1705 lcd_puts(0, line++, buf);
1707 snprintf(buf, 30, "IUSB Max: %d", usb_allowed_current());
1708 lcd_puts(0, line++, buf);
1710 y = ARRAYLEN(chrgstate_strings) - 1;
1712 switch (charge_state)
1714 case CHARGE_STATE_DISABLED: y--;
1715 case CHARGE_STATE_ERROR: y--;
1716 case DISCHARGING: y--;
1717 case TRICKLE: y--;
1718 case TOPOFF: y--;
1719 case CHARGING: y--;
1720 default:;
1723 snprintf(buf, 30, "State: %s", chrgstate_strings[y]);
1724 lcd_puts(0, line++, buf);
1726 snprintf(buf, 30, "Battery Switch: %s",
1727 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1728 lcd_puts(0, line++, buf);
1730 y = chrgraw_adc_voltage();
1731 snprintf(buf, 30, "CHRGRAW: %d.%03d V",
1732 y / 1000, y % 1000);
1733 lcd_puts(0, line++, buf);
1735 y = application_supply_adc_voltage();
1736 snprintf(buf, 30, "BP : %d.%03d V",
1737 y / 1000, y % 1000);
1738 lcd_puts(0, line++, buf);
1740 y = battery_adc_charge_current();
1741 if (y < 0) x = '-', y = -y;
1742 else x = ' ';
1743 snprintf(buf, 30, "CHRGISN:%c%d mA", x, y);
1744 lcd_puts(0, line++, buf);
1746 y = cccv_regulator_dissipation();
1747 snprintf(buf, 30, "P CCCV : %d mW", y);
1748 lcd_puts(0, line++, buf);
1750 y = battery_charge_current();
1751 if (y < 0) x = '-', y = -y;
1752 else x = ' ';
1753 snprintf(buf, 30, "I Charge:%c%d mA", x, y);
1754 lcd_puts(0, line++, buf);
1756 y = battery_adc_temp();
1758 if (y != INT_MIN) {
1759 snprintf(buf, 30, "T Battery: %dC (%dF)", y,
1760 (9*y + 160) / 5);
1761 } else {
1762 /* Conversion disabled */
1763 snprintf(buf, 30, "T Battery: ?");
1766 lcd_puts(0, line++, buf);
1767 #elif defined(SANSA_E200) || defined(SANSA_C200) || defined(SANSA_CLIP) || defined(SANSA_FUZE)
1768 const int first = CHARGE_STATE_DISABLED;
1769 static const char * const chrgstate_strings[] =
1771 [CHARGE_STATE_DISABLED-first] = "Disabled",
1772 [CHARGE_STATE_ERROR-first] = "Error",
1773 [DISCHARGING-first] = "Discharging",
1774 [CHARGING-first] = "Charging",
1776 const char *str = NULL;
1778 snprintf(buf, 30, "Charger: %s",
1779 charger_inserted() ? "present" : "absent");
1780 lcd_puts(0, 3, buf);
1782 y = charge_state - first;
1783 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1784 str = chrgstate_strings[y];
1786 snprintf(buf, sizeof(buf), "State: %s",
1787 str ? str : "<unknown>");
1788 lcd_puts(0, 4, buf);
1790 snprintf(buf, sizeof(buf), "CHARGER: %02X",
1791 ascodec_read(AS3514_CHARGER));
1792 lcd_puts(0, 5, buf);
1793 #else
1794 snprintf(buf, 30, "Charger: %s",
1795 charger_inserted() ? "present" : "absent");
1796 lcd_puts(0, 3, buf);
1797 #endif /* target type */
1798 #endif /* CONFIG_CHARGING */
1799 break;
1801 case 2: /* voltage deltas: */
1802 lcd_puts(0, 0, "Voltage deltas:");
1804 for (i = 0; i <= 6; i++) {
1805 y = power_history[i] - power_history[i+1];
1806 snprintf(buf, 30, "-%d min: %s%d.%03d V", i,
1807 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1808 ((y < 0) ? y * -1 : y ) % 1000);
1809 lcd_puts(0, i+1, buf);
1811 break;
1813 case 3: /* remaining time estimation: */
1815 #ifdef ARCHOS_RECORDER
1816 snprintf(buf, 30, "charge_state: %d", charge_state);
1817 lcd_puts(0, 0, buf);
1819 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1820 lcd_puts(0, 1, buf);
1822 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1823 lcd_puts(0, 2, buf);
1825 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1826 lcd_puts(0, 3, buf);
1828 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1829 lcd_puts(0, 4, buf);
1830 #endif /* ARCHOS_RECORDER */
1832 snprintf(buf, 30, "Last PwrHist: %d.%03dV",
1833 power_history[0] / 1000,
1834 power_history[0] % 1000);
1835 lcd_puts(0, 5, buf);
1837 snprintf(buf, 30, "battery level: %d%%", battery_level());
1838 lcd_puts(0, 6, buf);
1840 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1841 lcd_puts(0, 7, buf);
1842 break;
1845 lcd_update();
1847 switch(get_action(CONTEXT_STD,HZ/2))
1849 case ACTION_STD_PREV:
1850 if (view)
1851 view--;
1852 break;
1854 case ACTION_STD_NEXT:
1855 if (view < 3)
1856 view++;
1857 break;
1859 case ACTION_STD_CANCEL:
1860 lcd_setfont(FONT_UI);
1861 return false;
1864 lcd_setfont(FONT_UI);
1865 return false;
1868 #endif /* HAVE_LCD_BITMAP */
1869 #endif
1871 #ifndef SIMULATOR
1872 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1874 #if (CONFIG_STORAGE & STORAGE_MMC)
1875 #define CARDTYPE "MMC"
1876 #elif (CONFIG_STORAGE & STORAGE_SD)
1877 #define CARDTYPE "microSD"
1878 #endif
1880 static int disk_callback(int btn, struct gui_synclist *lists)
1882 tCardInfo *card;
1883 int *cardnum = (int*)lists->data;
1884 unsigned char card_name[7];
1885 unsigned char pbuf[32];
1886 char *title = lists->title;
1887 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1888 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1889 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1890 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1891 #if (CONFIG_STORAGE & STORAGE_MMC)
1892 static const char *mmc_spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1893 "3.1-3.31", "4.0" };
1894 #endif
1896 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1898 #ifdef HAVE_HOTSWAP
1899 if (btn == ACTION_STD_OK)
1901 *cardnum ^= 0x1; /* change cards */
1903 #endif
1905 simplelist_set_line_count(0);
1907 card = card_get_info(*cardnum);
1909 if (card->initialized > 0)
1911 strlcpy(card_name, ((unsigned char*)card->cid) + 3, sizeof(card_name));
1912 simplelist_addline(SIMPLELIST_ADD_LINE,
1913 "%s Rev %d.%d", card_name,
1914 (int) card_extract_bits(card->cid, 55, 4),
1915 (int) card_extract_bits(card->cid, 51, 4));
1916 simplelist_addline(SIMPLELIST_ADD_LINE,
1917 "Prod: %d/%d",
1918 #if (CONFIG_STORAGE & STORAGE_SD)
1919 (int) card_extract_bits(card->cid, 11, 3),
1920 (int) card_extract_bits(card->cid, 19, 8) + 2000
1921 #elif (CONFIG_STORAGE & STORAGE_MMC)
1922 (int) card_extract_bits(card->cid, 15, 4),
1923 (int) card_extract_bits(card->cid, 11, 4) + 1997
1924 #endif
1926 simplelist_addline(SIMPLELIST_ADD_LINE,
1927 #if (CONFIG_STORAGE & STORAGE_SD)
1928 "Ser#: 0x%08lx",
1929 card_extract_bits(card->cid, 55, 32)
1930 #elif (CONFIG_STORAGE & STORAGE_MMC)
1931 "Ser#: 0x%04lx",
1932 card_extract_bits(card->cid, 47, 16)
1933 #endif
1936 simplelist_addline(SIMPLELIST_ADD_LINE, "M=%02x, "
1937 #if (CONFIG_STORAGE & STORAGE_SD)
1938 "O=%c%c",
1939 (int) card_extract_bits(card->cid, 127, 8),
1940 card_extract_bits(card->cid, 119, 8),
1941 card_extract_bits(card->cid, 111, 8)
1942 #elif (CONFIG_STORAGE & STORAGE_MMC)
1943 "O=%04x",
1944 (int) card_extract_bits(card->cid, 127, 8),
1945 (int) card_extract_bits(card->cid, 119, 16)
1946 #endif
1949 #if (CONFIG_STORAGE & STORAGE_MMC)
1950 int temp = card_extract_bits(card->csd, 125, 4);
1951 simplelist_addline(SIMPLELIST_ADD_LINE,
1952 "MMC v%s", temp < 5 ?
1953 mmc_spec_vers[temp] : "?.?");
1954 #endif
1955 simplelist_addline(SIMPLELIST_ADD_LINE,
1956 "Blocks: 0x%08lx", card->numblocks);
1957 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1958 kbit_units, false);
1959 simplelist_addline(SIMPLELIST_ADD_LINE,
1960 "Speed: %s", pbuf);
1961 output_dyn_value(pbuf, sizeof pbuf, card->taac,
1962 nsec_units, false);
1963 simplelist_addline(SIMPLELIST_ADD_LINE,
1964 "Taac: %s", pbuf);
1965 simplelist_addline(SIMPLELIST_ADD_LINE,
1966 "Nsac: %d clk", card->nsac);
1967 simplelist_addline(SIMPLELIST_ADD_LINE,
1968 "R2W: *%d", card->r2w_factor);
1969 simplelist_addline(SIMPLELIST_ADD_LINE,
1970 "IRmax: %d..%d mA",
1971 i_vmin[card_extract_bits(card->csd, 61, 3)],
1972 i_vmax[card_extract_bits(card->csd, 58, 3)]);
1973 simplelist_addline(SIMPLELIST_ADD_LINE,
1974 "IWmax: %d..%d mA",
1975 i_vmin[card_extract_bits(card->csd, 55, 3)],
1976 i_vmax[card_extract_bits(card->csd, 52, 3)]);
1978 else if (card->initialized == 0)
1980 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1982 #if (CONFIG_STORAGE & STORAGE_SD)
1983 else /* card->initialized < 0 */
1985 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1987 #endif
1988 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1989 gui_synclist_set_title(lists, title, Icon_NOICON);
1990 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1991 gui_synclist_select_item(lists, 0);
1992 btn = ACTION_REDRAW;
1994 return btn;
1996 #elif (CONFIG_STORAGE & STORAGE_ATA)
1997 static int disk_callback(int btn, struct gui_synclist *lists)
1999 (void)lists;
2000 int i;
2001 char buf[128];
2002 unsigned short* identify_info = ata_get_identify();
2003 bool timing_info_present = false;
2004 (void)btn;
2006 simplelist_set_line_count(0);
2008 for (i=0; i < 20; i++)
2009 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
2010 buf[40]=0;
2011 /* kill trailing space */
2012 for (i=39; i && buf[i]==' '; i--)
2013 buf[i] = 0;
2014 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
2015 for (i=0; i < 4; i++)
2016 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
2017 buf[8]=0;
2018 simplelist_addline(SIMPLELIST_ADD_LINE,
2019 "Firmware: %s", buf);
2020 snprintf(buf, sizeof buf, "%ld MB",
2021 ((unsigned long)identify_info[61] << 16 |
2022 (unsigned long)identify_info[60]) / 2048 );
2023 simplelist_addline(SIMPLELIST_ADD_LINE,
2024 "Size: %s", buf);
2025 unsigned long free;
2026 fat_size( IF_MV2(0,) NULL, &free );
2027 simplelist_addline(SIMPLELIST_ADD_LINE,
2028 "Free: %ld MB", free / 1024);
2029 simplelist_addline(SIMPLELIST_ADD_LINE,
2030 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
2031 i = identify_info[83] & (1<<3);
2032 simplelist_addline(SIMPLELIST_ADD_LINE,
2033 "Power mgmt: %s", i ? "enabled" : "unsupported");
2034 i = identify_info[83] & (1<<9);
2035 simplelist_addline(SIMPLELIST_ADD_LINE,
2036 "Noise mgmt: %s", i ? "enabled" : "unsupported");
2037 i = identify_info[82] & (1<<6);
2038 simplelist_addline(SIMPLELIST_ADD_LINE,
2039 "Read-ahead: %s", i ? "enabled" : "unsupported");
2040 timing_info_present = identify_info[53] & (1<<1);
2041 if(timing_info_present) {
2042 char pio3[2], pio4[2];pio3[1] = 0;
2043 pio4[1] = 0;
2044 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
2045 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
2046 simplelist_addline(SIMPLELIST_ADD_LINE,
2047 "PIO modes: 0 1 2 %s %s", pio3, pio4);
2049 else {
2050 simplelist_addline(SIMPLELIST_ADD_LINE,
2051 "No PIO mode info");
2053 timing_info_present = identify_info[53] & (1<<1);
2054 if(timing_info_present) {
2055 simplelist_addline(SIMPLELIST_ADD_LINE,
2056 "Cycle times %dns/%dns",
2057 identify_info[67],
2058 identify_info[68] );
2059 } else {
2060 simplelist_addline(SIMPLELIST_ADD_LINE,
2061 "No timing info");
2063 #ifdef HAVE_ATA_DMA
2064 if (identify_info[63] & (1<<0)) {
2065 char mdma0[2], mdma1[2], mdma2[2];
2066 mdma0[1] = mdma1[1] = mdma2[1] = 0;
2067 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
2068 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
2069 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
2070 simplelist_addline(SIMPLELIST_ADD_LINE,
2071 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
2072 simplelist_addline(SIMPLELIST_ADD_LINE,
2073 "MDMA Cycle times %dns/%dns",
2074 identify_info[65],
2075 identify_info[66] );
2077 else {
2078 simplelist_addline(SIMPLELIST_ADD_LINE,
2079 "No MDMA mode info");
2081 if (identify_info[53] & (1<<2)) {
2082 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2], udma6[2];
2083 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = udma6[1] = 0;
2084 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
2085 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
2086 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
2087 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
2088 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
2089 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
2090 udma6[0] = (identify_info[88] & (1<<6)) ? '6' : 0;
2091 simplelist_addline(SIMPLELIST_ADD_LINE,
2092 "UDMA modes: %s %s %s %s %s %s %s", udma0, udma1, udma2,
2093 udma3, udma4, udma5, udma6);
2095 else {
2096 simplelist_addline(SIMPLELIST_ADD_LINE,
2097 "No UDMA mode info");
2099 #endif /* HAVE_ATA_DMA */
2100 timing_info_present = identify_info[53] & (1<<1);
2101 if(timing_info_present) {
2102 i = identify_info[49] & (1<<11);
2103 simplelist_addline(SIMPLELIST_ADD_LINE,
2104 "IORDY support: %s", i ? "yes" : "no");
2105 i = identify_info[49] & (1<<10);
2106 simplelist_addline(SIMPLELIST_ADD_LINE,
2107 "IORDY disable: %s", i ? "yes" : "no");
2108 } else {
2109 simplelist_addline(SIMPLELIST_ADD_LINE,
2110 "No timing info");
2112 simplelist_addline(SIMPLELIST_ADD_LINE,
2113 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2114 #ifdef HAVE_ATA_DMA
2115 i = ata_get_dma_mode();
2116 if (i == 0) {
2117 simplelist_addline(SIMPLELIST_ADD_LINE,
2118 "DMA not enabled");
2119 } else {
2120 simplelist_addline(SIMPLELIST_ADD_LINE,
2121 "DMA mode: %s %c",
2122 (i & 0x40) ? "UDMA" : "MDMA",
2123 '0' + (i & 7));
2125 #endif /* HAVE_ATA_DMA */
2126 return btn;
2128 #else /* No SD, MMC or ATA */
2129 static int disk_callback(int btn, struct gui_synclist *lists)
2131 (void)btn;
2132 (void)lists;
2133 struct storage_info info;
2134 storage_get_info(0,&info);
2135 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
2136 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
2137 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
2138 simplelist_addline(SIMPLELIST_ADD_LINE,
2139 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
2140 unsigned long free;
2141 fat_size( IF_MV2(0,) NULL, &free );
2142 simplelist_addline(SIMPLELIST_ADD_LINE,
2143 "Free: %ld MB", free / 1024);
2144 simplelist_addline(SIMPLELIST_ADD_LINE,
2145 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2146 return btn;
2148 #endif
2150 #if (CONFIG_STORAGE & STORAGE_ATA)
2151 static bool dbg_identify_info(void)
2153 int fd = creat("/identify_info.bin");
2154 if(fd >= 0)
2156 #ifdef ROCKBOX_LITTLE_ENDIAN
2157 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
2158 #else
2159 write(fd, ata_get_identify(), SECTOR_SIZE);
2160 #endif
2161 close(fd);
2163 return false;
2165 #endif
2167 static bool dbg_disk_info(void)
2169 struct simplelist_info info;
2170 simplelist_info_init(&info, "Disk Info", 1, NULL);
2171 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
2172 char title[16];
2173 int card = 0;
2174 info.callback_data = (void*)&card;
2175 info.title = title;
2176 #endif
2177 info.action_callback = disk_callback;
2178 info.hide_selection = true;
2179 info.scroll_all = true;
2180 return simplelist_show_list(&info);
2182 #endif /* !SIMULATOR */
2184 #ifdef HAVE_DIRCACHE
2185 static int dircache_callback(int btn, struct gui_synclist *lists)
2187 (void)btn; (void)lists;
2188 simplelist_set_line_count(0);
2189 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
2190 dircache_is_enabled() ? "Yes" : "No");
2191 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
2192 dircache_get_cache_size());
2193 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
2194 global_status.dircache_size);
2195 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
2196 DIRCACHE_LIMIT);
2197 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
2198 dircache_get_reserve_used(), DIRCACHE_RESERVE);
2199 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2200 dircache_get_build_ticks() / HZ);
2201 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2202 dircache_get_entry_count());
2203 return btn;
2206 static bool dbg_dircache_info(void)
2208 struct simplelist_info info;
2209 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2210 info.action_callback = dircache_callback;
2211 info.hide_selection = true;
2212 info.scroll_all = true;
2213 return simplelist_show_list(&info);
2216 #endif /* HAVE_DIRCACHE */
2218 #ifdef HAVE_TAGCACHE
2219 static int database_callback(int btn, struct gui_synclist *lists)
2221 (void)lists;
2222 struct tagcache_stat *stat = tagcache_get_stat();
2223 static bool synced = false;
2225 simplelist_set_line_count(0);
2227 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2228 stat->initialized ? "Yes" : "No");
2229 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2230 stat->ready ? "Yes" : "No");
2231 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2232 stat->ramcache ? "Yes" : "No");
2233 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2234 stat->ramcache_used, stat->ramcache_allocated);
2235 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2236 stat->progress, stat->processed_entries);
2237 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2238 stat->curentry ? stat->curentry : "---");
2239 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2240 stat->commit_step);
2241 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2242 stat->commit_delayed ? "Yes" : "No");
2244 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2245 stat->queue_length);
2247 if (synced)
2249 synced = false;
2250 tagcache_screensync_event();
2253 if (!btn && stat->curentry)
2255 synced = true;
2256 return ACTION_REDRAW;
2259 if (btn == ACTION_STD_CANCEL)
2260 tagcache_screensync_enable(false);
2262 return btn;
2264 static bool dbg_tagcache_info(void)
2266 struct simplelist_info info;
2267 simplelist_info_init(&info, "Database Info", 8, NULL);
2268 info.action_callback = database_callback;
2269 info.hide_selection = true;
2270 info.scroll_all = true;
2272 /* Don't do nonblock here, must give enough processing time
2273 for tagcache thread. */
2274 /* info.timeout = TIMEOUT_NOBLOCK; */
2275 info.timeout = 1;
2276 tagcache_screensync_enable(true);
2277 return simplelist_show_list(&info);
2279 #endif
2281 #if CONFIG_CPU == SH7034
2282 static bool dbg_save_roms(void)
2284 int fd;
2285 int oldmode = system_memory_guard(MEMGUARD_NONE);
2287 fd = creat("/internal_rom_0000-FFFF.bin");
2288 if(fd >= 0)
2290 write(fd, (void *)0, 0x10000);
2291 close(fd);
2294 fd = creat("/internal_rom_2000000-203FFFF.bin");
2295 if(fd >= 0)
2297 write(fd, (void *)0x2000000, 0x40000);
2298 close(fd);
2301 system_memory_guard(oldmode);
2302 return false;
2304 #elif defined CPU_COLDFIRE
2305 static bool dbg_save_roms(void)
2307 int fd;
2308 int oldmode = system_memory_guard(MEMGUARD_NONE);
2310 #if defined(IRIVER_H100_SERIES)
2311 fd = creat("/internal_rom_000000-1FFFFF.bin");
2312 #elif defined(IRIVER_H300_SERIES)
2313 fd = creat("/internal_rom_000000-3FFFFF.bin");
2314 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2315 fd = creat("/internal_rom_000000-3FFFFF.bin");
2316 #endif
2317 if(fd >= 0)
2319 write(fd, (void *)0, FLASH_SIZE);
2320 close(fd);
2322 system_memory_guard(oldmode);
2324 #ifdef HAVE_EEPROM
2325 fd = creat("/internal_eeprom.bin");
2326 if (fd >= 0)
2328 int old_irq_level;
2329 char buf[EEPROM_SIZE];
2330 int err;
2332 old_irq_level = disable_irq_save();
2334 err = eeprom_24cxx_read(0, buf, sizeof buf);
2336 restore_irq(old_irq_level);
2338 if (err)
2339 splashf(HZ*3, "Eeprom read failure (%d)", err);
2340 else
2342 write(fd, buf, sizeof buf);
2345 close(fd);
2347 #endif
2349 return false;
2351 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
2352 static bool dbg_save_roms(void)
2354 int fd;
2356 fd = creat("/internal_rom_000000-0FFFFF.bin");
2357 if(fd >= 0)
2359 write(fd, (void *)0x20000000, FLASH_SIZE);
2360 close(fd);
2363 return false;
2365 #endif /* CPU */
2367 #ifndef SIMULATOR
2368 #if CONFIG_TUNER
2369 static int radio_callback(int btn, struct gui_synclist *lists)
2371 (void)lists;
2372 if (btn == ACTION_STD_CANCEL)
2373 return btn;
2374 simplelist_set_line_count(1);
2376 #if (CONFIG_TUNER & LV24020LP)
2377 simplelist_addline(SIMPLELIST_ADD_LINE,
2378 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2379 simplelist_addline(SIMPLELIST_ADD_LINE,
2380 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2381 simplelist_addline(SIMPLELIST_ADD_LINE,
2382 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2383 simplelist_addline(SIMPLELIST_ADD_LINE,
2384 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2385 simplelist_addline(SIMPLELIST_ADD_LINE,
2386 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2387 simplelist_addline(SIMPLELIST_ADD_LINE,
2388 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2389 simplelist_addline(SIMPLELIST_ADD_LINE,
2390 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2391 #endif /* LV24020LP */
2392 #if (CONFIG_TUNER & S1A0903X01)
2393 simplelist_addline(SIMPLELIST_ADD_LINE,
2394 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2395 /* This one doesn't return dynamic data atm */
2396 #endif /* S1A0903X01 */
2397 #if (CONFIG_TUNER & TEA5767)
2398 struct tea5767_dbg_info nfo;
2399 tea5767_dbg_info(&nfo);
2400 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2401 simplelist_addline(SIMPLELIST_ADD_LINE,
2402 " Read: %02X %02X %02X %02X %02X",
2403 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2404 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2405 (unsigned)nfo.read_regs[4]);
2406 simplelist_addline(SIMPLELIST_ADD_LINE,
2407 " Write: %02X %02X %02X %02X %02X",
2408 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2409 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2410 (unsigned)nfo.write_regs[4]);
2411 #endif /* TEA5767 */
2412 #if (CONFIG_TUNER & SI4700)
2413 struct si4700_dbg_info nfo;
2414 si4700_dbg_info(&nfo);
2415 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
2416 /* Registers */
2417 simplelist_addline(SIMPLELIST_ADD_LINE,
2418 "%04X %04X %04X %04X",
2419 (unsigned)nfo.regs[0], (unsigned)nfo.regs[1],
2420 (unsigned)nfo.regs[2], (unsigned)nfo.regs[3]);
2421 simplelist_addline(SIMPLELIST_ADD_LINE,
2422 "%04X %04X %04X %04X",
2423 (unsigned)nfo.regs[4], (unsigned)nfo.regs[5],
2424 (unsigned)nfo.regs[6], (unsigned)nfo.regs[7]);
2425 simplelist_addline(SIMPLELIST_ADD_LINE,
2426 "%04X %04X %04X %04X",
2427 (unsigned)nfo.regs[8], (unsigned)nfo.regs[9],
2428 (unsigned)nfo.regs[10], (unsigned)nfo.regs[11]);
2429 simplelist_addline(SIMPLELIST_ADD_LINE,
2430 "%04X %04X %04X %04X",
2431 (unsigned)nfo.regs[12], (unsigned)nfo.regs[13],
2432 (unsigned)nfo.regs[14], (unsigned)nfo.regs[15]);
2433 #endif /* SI4700 */
2434 return ACTION_REDRAW;
2436 static bool dbg_fm_radio(void)
2438 struct simplelist_info info;
2439 info.scroll_all = true;
2440 simplelist_info_init(&info, "FM Radio", 1, NULL);
2441 simplelist_set_line_count(0);
2442 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2443 radio_hardware_present() ? "yes" : "no");
2445 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2446 info.hide_selection = true;
2447 return simplelist_show_list(&info);
2449 #endif /* CONFIG_TUNER */
2450 #endif /* !SIMULATOR */
2452 #ifdef HAVE_LCD_BITMAP
2453 extern bool do_screendump_instead_of_usb;
2455 static bool dbg_screendump(void)
2457 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2458 splashf(HZ, "Screendump %s",
2459 do_screendump_instead_of_usb?"enabled":"disabled");
2460 return false;
2462 #endif /* HAVE_LCD_BITMAP */
2464 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2465 static bool dbg_set_memory_guard(void)
2467 static const struct opt_items names[MAXMEMGUARD] = {
2468 { "None", -1 },
2469 { "Flash ROM writes", -1 },
2470 { "Zero area (all)", -1 }
2472 int mode = system_memory_guard(MEMGUARD_KEEP);
2474 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2475 system_memory_guard(mode);
2477 return false;
2479 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2481 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2482 static bool dbg_write_eeprom(void)
2484 int fd;
2485 int rc;
2486 int old_irq_level;
2487 char buf[EEPROM_SIZE];
2488 int err;
2490 fd = open("/internal_eeprom.bin", O_RDONLY);
2492 if (fd >= 0)
2494 rc = read(fd, buf, EEPROM_SIZE);
2496 if(rc == EEPROM_SIZE)
2498 old_irq_level = disable_irq_save();
2500 err = eeprom_24cxx_write(0, buf, sizeof buf);
2501 if (err)
2502 splashf(HZ*3, "Eeprom write failure (%d)", err);
2503 else
2504 splash(HZ*3, "Eeprom written successfully");
2506 restore_irq(old_irq_level);
2508 else
2510 splashf(HZ*3, "File read error (%d)",rc);
2512 close(fd);
2514 else
2516 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2519 return false;
2521 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2522 #ifdef CPU_BOOST_LOGGING
2523 static bool cpu_boost_log(void)
2525 int i = 0,j=0;
2526 int count = cpu_boost_log_getcount();
2527 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2528 char *str;
2529 bool done;
2530 lcd_setfont(FONT_SYSFIXED);
2531 str = cpu_boost_log_getlog_first();
2532 while (i < count)
2534 lcd_clear_display();
2535 for(j=0; j<lines; j++,i++)
2537 if (!str)
2538 str = cpu_boost_log_getlog_next();
2539 if (str)
2541 if(strlen(str) > LCD_WIDTH/SYSFONT_WIDTH)
2542 lcd_puts_scroll(0, j, str);
2543 else
2544 lcd_puts(0, j,str);
2546 str = NULL;
2548 lcd_update();
2549 done = false;
2550 while (!done)
2552 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2554 case ACTION_STD_OK:
2555 case ACTION_STD_PREV:
2556 case ACTION_STD_NEXT:
2557 done = true;
2558 break;
2559 case ACTION_STD_CANCEL:
2560 i = count;
2561 done = true;
2562 break;
2566 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2567 lcd_setfont(FONT_UI);
2568 return false;
2570 #endif
2572 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2573 extern bool wheel_is_touched;
2574 extern int old_wheel_value;
2575 extern int new_wheel_value;
2576 extern int wheel_delta;
2577 extern unsigned int accumulated_wheel_delta;
2578 extern unsigned int wheel_velocity;
2580 static bool dbg_scrollwheel(void)
2582 char buf[64];
2583 unsigned int speed;
2585 lcd_setfont(FONT_SYSFIXED);
2587 while (1)
2589 if (action_userabort(HZ/10))
2590 break;
2592 lcd_clear_display();
2594 /* show internal variables of scrollwheel driver */
2595 snprintf(buf, sizeof(buf), "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2596 lcd_puts(0, 0, buf);
2597 snprintf(buf, sizeof(buf), "new position: %2d", new_wheel_value);
2598 lcd_puts(0, 1, buf);
2599 snprintf(buf, sizeof(buf), "old position: %2d", old_wheel_value);
2600 lcd_puts(0, 2, buf);
2601 snprintf(buf, sizeof(buf), "wheel delta: %2d", wheel_delta);
2602 lcd_puts(0, 3, buf);
2603 snprintf(buf, sizeof(buf), "accumulated delta: %2d", accumulated_wheel_delta);
2604 lcd_puts(0, 4, buf);
2605 snprintf(buf, sizeof(buf), "velo [deg/s]: %4d", (int)wheel_velocity);
2606 lcd_puts(0, 5, buf);
2608 /* show effective accelerated scrollspeed */
2609 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2610 snprintf(buf, sizeof(buf), "accel. speed: %4d", speed);
2611 lcd_puts(0, 6, buf);
2613 lcd_update();
2615 lcd_setfont(FONT_UI);
2616 return false;
2618 #endif
2620 #if defined (HAVE_USBSTACK)
2622 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2623 static bool toggle_usb_core_driver(int driver, char *msg)
2625 bool enabled = !usb_core_driver_enabled(driver);
2627 usb_core_enable_driver(driver,enabled);
2628 splashf(HZ, "%s %s", msg, enabled?"enabled":"disabled");
2630 return false;
2633 static bool toggle_usb_serial(void)
2635 return toggle_usb_core_driver(USB_DRIVER_SERIAL,"USB Serial");
2637 #endif
2639 #endif
2641 #if CONFIG_USBOTG == USBOTG_ISP1583
2642 extern int dbg_usb_num_items(void);
2643 extern char* dbg_usb_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2645 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2647 (void)lists;
2648 if (action == ACTION_NONE)
2649 action = ACTION_REDRAW;
2650 return action;
2653 static bool dbg_isp1583(void)
2655 struct simplelist_info isp1583;
2656 isp1583.scroll_all = true;
2657 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2658 isp1583.timeout = HZ/100;
2659 isp1583.hide_selection = true;
2660 isp1583.get_name = dbg_usb_item;
2661 isp1583.action_callback = isp1583_action_callback;
2662 return simplelist_show_list(&isp1583);
2664 #endif
2666 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2667 extern int pic_dbg_num_items(void);
2668 extern char* pic_dbg_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2670 static int pic_action_callback(int action, struct gui_synclist *lists)
2672 (void)lists;
2673 if (action == ACTION_NONE)
2674 action = ACTION_REDRAW;
2675 return action;
2678 static bool dbg_pic(void)
2680 struct simplelist_info pic;
2681 pic.scroll_all = true;
2682 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2683 pic.timeout = HZ/100;
2684 pic.hide_selection = true;
2685 pic.get_name = pic_dbg_item;
2686 pic.action_callback = pic_action_callback;
2687 return simplelist_show_list(&pic);
2689 #endif
2692 /****** The menu *********/
2693 struct the_menu_item {
2694 unsigned char *desc; /* string or ID */
2695 bool (*function) (void); /* return true if USB was connected */
2697 static const struct the_menu_item menuitems[] = {
2698 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2699 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD))
2700 { "Dump ROM contents", dbg_save_roms },
2701 #endif
2702 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2703 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 \
2704 || CONFIG_CPU == DM320
2705 { "View I/O ports", dbg_ports },
2706 #endif
2707 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2708 { "View PCF registers", dbg_pcf },
2709 #endif
2710 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2711 { "TSC2100 debug", tsc2100_debug },
2712 #endif
2713 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2714 { "CPU frequency", dbg_cpufreq },
2715 #endif
2716 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2717 { "S/PDIF analyzer", dbg_spdif },
2718 #endif
2719 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2720 { "Catch mem accesses", dbg_set_memory_guard },
2721 #endif
2722 { "View OS stacks", dbg_os },
2723 #ifdef HAVE_LCD_BITMAP
2724 #ifndef SIMULATOR
2725 { "View battery", view_battery },
2726 #endif
2727 { "Screendump", dbg_screendump },
2728 #endif
2729 #ifndef SIMULATOR
2730 { "View HW info", dbg_hw_info },
2731 #endif
2732 #ifndef SIMULATOR
2733 { "View partitions", dbg_partitions },
2734 #endif
2735 #ifndef SIMULATOR
2736 { "View disk info", dbg_disk_info },
2737 #if (CONFIG_STORAGE & STORAGE_ATA)
2738 { "Dump ATA identify info", dbg_identify_info},
2739 #endif
2740 #endif
2741 #ifdef HAVE_DIRCACHE
2742 { "View dircache info", dbg_dircache_info },
2743 #endif
2744 #ifdef HAVE_TAGCACHE
2745 { "View database info", dbg_tagcache_info },
2746 #endif
2747 #ifdef HAVE_LCD_BITMAP
2748 #if CONFIG_CODEC == SWCODEC
2749 { "View buffering thread", dbg_buffering_thread },
2750 #elif !defined(SIMULATOR)
2751 { "View audio thread", dbg_audio_thread },
2752 #endif
2753 #ifdef PM_DEBUG
2754 { "pm histogram", peak_meter_histogram},
2755 #endif /* PM_DEBUG */
2756 #endif /* HAVE_LCD_BITMAP */
2757 #ifndef SIMULATOR
2758 #if CONFIG_TUNER
2759 { "FM Radio", dbg_fm_radio },
2760 #endif
2761 #endif
2762 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2763 { "Write back EEPROM", dbg_write_eeprom },
2764 #endif
2765 #if CONFIG_USBOTG == USBOTG_ISP1583
2766 { "View ISP1583 info", dbg_isp1583 },
2767 #endif
2768 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2769 { "View PIC info", dbg_pic },
2770 #endif
2771 #ifdef ROCKBOX_HAS_LOGF
2772 {"logf", logfdisplay },
2773 {"logfdump", logfdump },
2774 #endif
2775 #if defined(HAVE_USBSTACK)
2776 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2777 {"USB Serial driver (logf)", toggle_usb_serial },
2778 #endif
2779 #endif /* HAVE_USBSTACK */
2780 #ifdef CPU_BOOST_LOGGING
2781 {"cpu_boost log",cpu_boost_log},
2782 #endif
2783 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2784 {"Debug scrollwheel", dbg_scrollwheel },
2785 #endif
2787 static int menu_action_callback(int btn, struct gui_synclist *lists)
2789 if (btn == ACTION_STD_OK)
2791 int oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL);
2792 menuitems[gui_synclist_get_sel_pos(lists)].function();
2793 btn = ACTION_REDRAW;
2794 send_event(GUI_EVENT_REFRESH, NULL);
2795 viewportmanager_set_statusbar(oldbars);
2797 return btn;
2799 static char* dbg_menu_getname(int item, void * data,
2800 char *buffer, size_t buffer_len)
2802 (void)data; (void)buffer; (void)buffer_len;
2803 return menuitems[item].desc;
2805 bool debug_menu(void)
2807 struct simplelist_info info;
2809 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2810 info.action_callback = menu_action_callback;
2811 info.get_name = dbg_menu_getname;
2812 return simplelist_show_list(&info);