Clip: fix font compilation
[kugel-rb.git] / apps / debug_menu.c
blobf613c0a18adbcbd27743c7f9467f00ab2866ef88
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Heikki Hannikainen
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <stdbool.h>
26 #include <string.h>
27 #include "lcd.h"
28 #include "menu.h"
29 #include "debug_menu.h"
30 #include "kernel.h"
31 #include "sprintf.h"
32 #include "structec.h"
33 #include "action.h"
34 #include "debug.h"
35 #include "thread.h"
36 #include "powermgmt.h"
37 #include "system.h"
38 #include "font.h"
39 #include "audio.h"
40 #include "mp3_playback.h"
41 #include "settings.h"
42 #include "list.h"
43 #include "statusbar.h"
44 #include "dir.h"
45 #include "panic.h"
46 #include "screens.h"
47 #include "misc.h"
48 #include "splash.h"
49 #include "dircache.h"
50 #include "viewport.h"
51 #ifdef HAVE_TAGCACHE
52 #include "tagcache.h"
53 #endif
54 #include "lcd-remote.h"
55 #include "crc32.h"
56 #include "logf.h"
57 #ifndef SIMULATOR
58 #include "disk.h"
59 #include "adc.h"
60 #include "power.h"
61 #include "usb.h"
62 #include "rtc.h"
63 #include "storage.h"
64 #include "fat.h"
65 #include "mas.h"
66 #include "eeprom_24cxx.h"
67 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
68 #include "hotswap.h"
69 #endif
70 #if (CONFIG_STORAGE & STORAGE_ATA)
71 #include "ata.h"
72 #endif
73 #if CONFIG_TUNER
74 #include "tuner.h"
75 #include "radio.h"
76 #endif
77 #endif
79 #ifdef HAVE_LCD_BITMAP
80 #include "scrollbar.h"
81 #include "peakmeter.h"
82 #endif
83 #include "logfdisp.h"
84 #if CONFIG_CODEC == SWCODEC
85 #include "pcmbuf.h"
86 #include "buffering.h"
87 #include "playback.h"
88 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
89 #include "spdif.h"
90 #endif
91 #endif
92 #ifdef IRIVER_H300_SERIES
93 #include "pcf50606.h" /* for pcf50606_read */
94 #endif
95 #ifdef IAUDIO_X5
96 #include "ds2411.h"
97 #endif
98 #include "hwcompat.h"
99 #include "button.h"
100 #if CONFIG_RTC == RTC_PCF50605
101 #include "pcf50605.h"
102 #endif
104 #if CONFIG_CPU == DM320 || CONFIG_CPU == S3C2440 || CONFIG_CPU == TCC7801 \
105 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525
106 #include "debug-target.h"
107 #endif
109 #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200)
110 #include "ascodec.h"
111 #include "as3514.h"
112 #endif
114 #if defined(HAVE_USBSTACK)
115 #include "usb_core.h"
116 #endif
117 #ifdef USB_STORAGE
118 #include "usbstack/usb_storage.h"
119 #endif
121 /*---------------------------------------------------*/
122 /* SPECIAL DEBUG STUFF */
123 /*---------------------------------------------------*/
124 extern struct thread_entry threads[MAXTHREADS];
126 static char thread_status_char(unsigned status)
128 static const char thread_status_chars[THREAD_NUM_STATES+1] =
130 [0 ... THREAD_NUM_STATES] = '?',
131 [STATE_RUNNING] = 'R',
132 [STATE_BLOCKED] = 'B',
133 [STATE_SLEEPING] = 'S',
134 [STATE_BLOCKED_W_TMO] = 'T',
135 [STATE_FROZEN] = 'F',
136 [STATE_KILLED] = 'K',
139 if (status > THREAD_NUM_STATES)
140 status = THREAD_NUM_STATES;
142 return thread_status_chars[status];
145 static char* threads_getname(int selected_item, void *data,
146 char *buffer, size_t buffer_len)
148 (void)data;
149 struct thread_entry *thread;
150 char name[32];
152 #if NUM_CORES > 1
153 if (selected_item < (int)NUM_CORES)
155 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
156 idle_stack_usage(selected_item));
157 return buffer;
160 selected_item -= NUM_CORES;
161 #endif
163 thread = &threads[selected_item];
165 if (thread->state == STATE_KILLED)
167 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
168 return buffer;
171 thread_get_name(name, 32, thread);
173 snprintf(buffer, buffer_len,
174 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
175 selected_item,
176 IF_COP(thread->core,)
177 #ifdef HAVE_SCHEDULER_BOOSTCTRL
178 (thread->cpu_boost) ? '+' :
179 #endif
180 ((thread->state == STATE_RUNNING) ? '*' : ' '),
181 thread_status_char(thread->state),
182 IF_PRIO(thread->base_priority, thread->priority, )
183 thread_stack_usage(thread), name);
185 return buffer;
187 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
189 (void)lists;
190 #ifdef ROCKBOX_HAS_LOGF
191 if (action == ACTION_STD_OK)
193 int selpos = gui_synclist_get_sel_pos(lists);
194 #if NUM_CORES > 1
195 if (selpos >= NUM_CORES)
196 remove_thread(&threads[selpos - NUM_CORES]);
197 #else
198 remove_thread(&threads[selpos]);
199 #endif
200 return ACTION_REDRAW;
202 #endif /* ROCKBOX_HAS_LOGF */
203 if (action == ACTION_NONE)
204 action = ACTION_REDRAW;
205 return action;
207 /* Test code!!! */
208 static bool dbg_os(void)
210 struct simplelist_info info;
211 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
212 #if NUM_CORES == 1
213 MAXTHREADS,
214 #else
215 MAXTHREADS+NUM_CORES,
216 #endif
217 NULL);
218 #ifndef ROCKBOX_HAS_LOGF
219 info.hide_selection = true;
220 info.scroll_all = true;
221 #endif
222 info.action_callback = dbg_threads_action_callback;
223 info.get_name = threads_getname;
224 return simplelist_show_list(&info);
227 #ifdef HAVE_LCD_BITMAP
228 #if CONFIG_CODEC != SWCODEC
229 #ifndef SIMULATOR
230 static bool dbg_audio_thread(void)
232 char buf[32];
233 struct audio_debug d;
235 lcd_setfont(FONT_SYSFIXED);
237 while(1)
239 if (action_userabort(HZ/5))
240 return false;
242 audio_get_debugdata(&d);
244 lcd_clear_display();
246 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
247 lcd_puts(0, 0, buf);
248 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
249 lcd_puts(0, 1, buf);
250 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
251 lcd_puts(0, 2, buf);
252 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
253 lcd_puts(0, 3, buf);
254 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
255 lcd_puts(0, 4, buf);
256 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
257 lcd_puts(0, 5, buf);
259 /* Playable space left */
260 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
261 d.playable_space, HORIZONTAL);
263 /* Show the watermark limit */
264 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
265 d.low_watermark_level, HORIZONTAL);
267 snprintf(buf, sizeof(buf), "wm: %x - %x",
268 d.low_watermark_level, d.lowest_watermark_level);
269 lcd_puts(0, 7, buf);
271 lcd_update();
273 lcd_setfont(FONT_UI);
274 return false;
276 #endif /* !SIMULATOR */
277 #else /* CONFIG_CODEC == SWCODEC */
278 extern size_t filebuflen;
279 /* This is a size_t, but call it a long so it puts a - when it's bad. */
281 static unsigned int ticks, boost_ticks, freq_sum;
283 static void dbg_audio_task(void)
285 #ifndef SIMULATOR
286 if(FREQ > CPUFREQ_NORMAL)
287 boost_ticks++;
288 freq_sum += FREQ/1000000; /* in MHz */
289 #endif
290 ticks++;
293 static bool dbg_buffering_thread(void)
295 char buf[32];
296 int button;
297 int line;
298 bool done = false;
299 size_t bufused;
300 size_t bufsize = pcmbuf_get_bufsize();
301 int pcmbufdescs = pcmbuf_descs();
302 struct buffering_debug d;
304 ticks = boost_ticks = freq_sum = 0;
306 tick_add_task(dbg_audio_task);
308 lcd_setfont(FONT_SYSFIXED);
309 while(!done)
311 button = get_action(CONTEXT_STD,HZ/5);
312 switch(button)
314 case ACTION_STD_NEXT:
315 audio_next();
316 break;
317 case ACTION_STD_PREV:
318 audio_prev();
319 break;
320 case ACTION_STD_CANCEL:
321 done = true;
322 break;
325 buffering_get_debugdata(&d);
327 line = 0;
328 lcd_clear_display();
330 bufused = bufsize - pcmbuf_free();
332 snprintf(buf, sizeof(buf), "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
333 lcd_puts(0, line++, buf);
335 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
336 bufsize, 0, bufused, HORIZONTAL);
337 line++;
339 snprintf(buf, sizeof(buf), "alloc: %6ld/%ld", audio_filebufused(),
340 (long) filebuflen);
341 lcd_puts(0, line++, buf);
343 #if LCD_HEIGHT > 80
344 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
345 filebuflen, 0, audio_filebufused(), HORIZONTAL);
346 line++;
348 snprintf(buf, sizeof(buf), "real: %6ld/%ld", (long)d.buffered_data,
349 (long)filebuflen);
350 lcd_puts(0, line++, buf);
352 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
353 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
354 line++;
355 #endif
357 snprintf(buf, sizeof(buf), "usefl: %6ld/%ld", (long)(d.useful_data),
358 (long)filebuflen);
359 lcd_puts(0, line++, buf);
361 #if LCD_HEIGHT > 80
362 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
363 filebuflen, 0, d.useful_data, HORIZONTAL);
364 line++;
365 #endif
367 snprintf(buf, sizeof(buf), "data_rem: %ld", (long)d.data_rem);
368 lcd_puts(0, line++, buf);
370 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
371 lcd_puts(0, line++, buf);
373 snprintf(buf, sizeof(buf), "handle count: %d", (int)d.num_handles);
374 lcd_puts(0, line++, buf);
376 #ifndef SIMULATOR
377 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
378 (int)((FREQ + 500000) / 1000000));
379 lcd_puts(0, line++, buf);
380 #endif
382 if (ticks > 0)
384 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
385 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
386 snprintf(buf, sizeof(buf), "boost:%3d.%d%% (%d.%dMHz)",
387 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
388 lcd_puts(0, line++, buf);
391 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
392 pcmbuf_used_descs(), pcmbufdescs);
393 lcd_puts(0, line++, buf);
395 lcd_update();
398 tick_remove_task(dbg_audio_task);
399 lcd_setfont(FONT_UI);
401 return false;
403 #endif /* CONFIG_CODEC */
404 #endif /* HAVE_LCD_BITMAP */
407 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
408 /* Tool function to read the flash manufacturer and type, if available.
409 Only chips which could be reprogrammed in system will return values.
410 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
411 /* In IRAM to avoid problems when running directly from Flash */
412 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
413 unsigned addr1, unsigned addr2)
414 ICODE_ATTR __attribute__((noinline));
415 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
416 unsigned addr1, unsigned addr2)
419 unsigned not_manu, not_id; /* read values before switching to ID mode */
420 unsigned manu, id; /* read values when in ID mode */
422 #if CONFIG_CPU == SH7034
423 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
424 #elif defined(CPU_COLDFIRE)
425 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
426 #endif
427 int old_level; /* saved interrupt level */
429 not_manu = flash[0]; /* read the normal content */
430 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
432 /* disable interrupts, prevent any stray flash access */
433 old_level = disable_irq_save();
435 flash[addr1] = 0xAA; /* enter command mode */
436 flash[addr2] = 0x55;
437 flash[addr1] = 0x90; /* ID command */
438 /* Atmel wants 20ms pause here */
439 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
441 manu = flash[0]; /* read the IDs */
442 id = flash[1];
444 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
445 /* Atmel wants 20ms pause here */
446 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
448 restore_irq(old_level); /* enable interrupts again */
450 /* I assume success if the obtained values are different from
451 the normal flash content. This is not perfectly bulletproof, they
452 could theoretically be the same by chance, causing us to fail. */
453 if (not_manu != manu || not_id != id) /* a value has changed */
455 *p_manufacturer = manu; /* return the results */
456 *p_device = id;
457 return true; /* success */
459 return false; /* fail */
461 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
463 #ifndef SIMULATOR
464 #ifdef CPU_PP
465 static int perfcheck(void)
467 int result;
469 asm (
470 "mrs r2, CPSR \n"
471 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
472 "msr CPSR_c, r0 \n"
473 "mov %[res], #0 \n"
474 "ldr r0, [%[timr]] \n"
475 "add r0, r0, %[tmo] \n"
476 "1: \n"
477 "add %[res], %[res], #1 \n"
478 "ldr r1, [%[timr]] \n"
479 "cmp r1, r0 \n"
480 "bmi 1b \n"
481 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
483 [res]"=&r"(result)
485 [timr]"r"(&USEC_TIMER),
486 [tmo]"r"(
487 #if CONFIG_CPU == PP5002
488 16000
489 #else /* PP5020/5022/5024 */
490 10226
491 #endif
494 "r0", "r1", "r2"
496 return result;
498 #endif
500 #ifdef HAVE_LCD_BITMAP
501 static bool dbg_hw_info(void)
503 #if CONFIG_CPU == SH7034
504 char buf[32];
505 int bitmask = HW_MASK;
506 int rom_version = ROM_VERSION;
507 unsigned manu, id; /* flash IDs */
508 bool got_id; /* flag if we managed to get the flash IDs */
509 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
510 bool has_bootrom; /* flag for boot ROM present */
511 int oldmode; /* saved memory guard mode */
513 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
515 /* get flash ROM type */
516 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
517 if (!got_id)
518 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
520 /* check if the boot ROM area is a flash mirror */
521 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
522 if (has_bootrom) /* if ROM and Flash different */
524 /* calculate CRC16 checksum of boot ROM */
525 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
528 system_memory_guard(oldmode); /* re-enable memory guard */
530 lcd_setfont(FONT_SYSFIXED);
531 lcd_clear_display();
533 lcd_puts(0, 0, "[Hardware info]");
535 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
536 lcd_puts(0, 1, buf);
538 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
539 lcd_puts(0, 2, buf);
541 if (got_id)
542 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
543 else
544 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
545 lcd_puts(0, 3, buf);
547 if (has_bootrom)
549 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
550 snprintf(buf, 32, "Boot ROM: V1");
551 else
552 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
554 else
556 snprintf(buf, 32, "Boot ROM: none");
558 lcd_puts(0, 4, buf);
560 lcd_update();
562 while (!(action_userabort(TIMEOUT_BLOCK)));
564 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
565 char buf[32];
566 unsigned manu, id; /* flash IDs */
567 int got_id; /* flag if we managed to get the flash IDs */
568 int oldmode; /* saved memory guard mode */
569 int line = 0;
571 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
573 /* get flash ROM type */
574 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
575 if (!got_id)
576 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
578 system_memory_guard(oldmode); /* re-enable memory guard */
580 lcd_setfont(FONT_SYSFIXED);
581 lcd_clear_display();
583 lcd_puts(0, line++, "[Hardware info]");
585 if (got_id)
586 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
587 else
588 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
589 lcd_puts(0, line++, buf);
591 #ifdef IAUDIO_X5
593 struct ds2411_id id;
595 lcd_puts(0, ++line, "Serial Number:");
597 got_id = ds2411_read_id(&id);
599 if (got_id == DS2411_OK)
601 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
602 lcd_puts(0, ++line, buf);
603 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
604 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
605 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
606 lcd_puts(0, ++line, buf);
607 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
609 else
611 snprintf(buf, 32, "READ ERR=%d", got_id);
614 lcd_puts(0, ++line, buf);
616 #endif
618 lcd_update();
620 while (!(action_userabort(TIMEOUT_BLOCK)));
622 #elif defined(CPU_PP502x)
623 int line = 0;
624 char buf[32];
625 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
626 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
627 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
628 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
630 lcd_setfont(FONT_SYSFIXED);
631 lcd_clear_display();
633 lcd_puts(0, line++, "[Hardware info]");
635 #ifdef IPOD_ARCH
636 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
637 lcd_puts(0, line++, buf);
638 #endif
640 #ifdef IPOD_COLOR
641 extern int lcd_type; /* Defined in lcd-colornano.c */
643 snprintf(buf, sizeof(buf), "LCD type: %d", lcd_type);
644 lcd_puts(0, line++, buf);
645 #endif
647 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
648 lcd_puts(0, line++, buf);
650 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
651 lcd_puts(0, line++, buf);
653 lcd_update();
655 while (!(action_userabort(TIMEOUT_BLOCK)));
657 #elif CONFIG_CPU == PP5002
658 int line = 0;
659 char buf[32];
660 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
661 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
662 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
663 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
666 lcd_setfont(FONT_SYSFIXED);
667 lcd_clear_display();
669 lcd_puts(0, line++, "[Hardware info]");
671 #ifdef IPOD_ARCH
672 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
673 lcd_puts(0, line++, buf);
674 #endif
676 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
677 lcd_puts(0, line++, buf);
679 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
680 lcd_puts(0, line++, buf);
682 lcd_update();
684 while (!(action_userabort(TIMEOUT_BLOCK)));
686 #else
687 /* Define this function in your target tree */
688 return __dbg_hw_info();
689 #endif /* CONFIG_CPU */
690 lcd_setfont(FONT_UI);
691 return false;
693 #else /* !HAVE_LCD_BITMAP */
694 static bool dbg_hw_info(void)
696 char buf[32];
697 int button;
698 int currval = 0;
699 int rom_version = ROM_VERSION;
700 unsigned manu, id; /* flash IDs */
701 bool got_id; /* flag if we managed to get the flash IDs */
702 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
703 bool has_bootrom; /* flag for boot ROM present */
704 int oldmode; /* saved memory guard mode */
706 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
708 /* get flash ROM type */
709 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
710 if (!got_id)
711 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
713 /* check if the boot ROM area is a flash mirror */
714 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
715 if (has_bootrom) /* if ROM and Flash different */
717 /* calculate CRC16 checksum of boot ROM */
718 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
721 system_memory_guard(oldmode); /* re-enable memory guard */
723 lcd_clear_display();
725 lcd_puts(0, 0, "[HW Info]");
726 while(1)
728 switch(currval)
730 case 0:
731 snprintf(buf, 32, "ROM: %d.%02d",
732 rom_version/100, rom_version%100);
733 break;
734 case 1:
735 if (got_id)
736 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
737 else
738 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
739 break;
740 case 2:
741 if (has_bootrom)
743 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
744 snprintf(buf, 32, "BootROM: V1");
745 else if (rom_crc == 0x358099E8)
746 snprintf(buf, 32, "BootROM: V2");
747 /* alternative boot ROM found in one single player so far */
748 else
749 snprintf(buf, 32, "R: %08x", rom_crc);
751 else
752 snprintf(buf, 32, "BootROM: no");
755 lcd_puts(0, 1, buf);
756 lcd_update();
758 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
760 switch(button)
762 case ACTION_STD_CANCEL:
763 return false;
765 case ACTION_SETTINGS_DEC:
766 currval--;
767 if(currval < 0)
768 currval = 2;
769 break;
771 case ACTION_SETTINGS_INC:
772 currval++;
773 if(currval > 2)
774 currval = 0;
775 break;
778 return false;
780 #endif /* !HAVE_LCD_BITMAP */
781 #endif /* !SIMULATOR */
783 #ifndef SIMULATOR
784 static char* dbg_partitions_getname(int selected_item, void *data,
785 char *buffer, size_t buffer_len)
787 (void)data;
788 int partition = selected_item/2;
789 struct partinfo* p = disk_partinfo(partition);
790 if (selected_item%2)
792 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / 2048);
794 else
796 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
798 return buffer;
801 bool dbg_partitions(void)
803 struct simplelist_info info;
804 simplelist_info_init(&info, "Partition Info", 4, NULL);
805 info.selection_size = 2;
806 info.hide_selection = true;
807 info.scroll_all = true;
808 info.get_name = dbg_partitions_getname;
809 return simplelist_show_list(&info);
811 #endif
813 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
814 static bool dbg_spdif(void)
816 char buf[128];
817 int line;
818 unsigned int control;
819 int x;
820 char *s;
821 int category;
822 int generation;
823 unsigned int interruptstat;
824 bool valnogood, symbolerr, parityerr;
825 bool done = false;
826 bool spdif_src_on;
827 int spdif_source = spdif_get_output_source(&spdif_src_on);
828 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
830 lcd_clear_display();
831 lcd_setfont(FONT_SYSFIXED);
833 #ifdef HAVE_SPDIF_POWER
834 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
835 #endif
837 while (!done)
839 line = 0;
841 control = EBU1RCVCCHANNEL1;
842 interruptstat = INTERRUPTSTAT;
843 INTERRUPTCLEAR = 0x03c00000;
845 valnogood = (interruptstat & 0x01000000)?true:false;
846 symbolerr = (interruptstat & 0x00800000)?true:false;
847 parityerr = (interruptstat & 0x00400000)?true:false;
849 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
850 valnogood?"--":"OK",
851 symbolerr?"--":"OK",
852 parityerr?"--":"OK");
853 lcd_puts(0, line++, buf);
855 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
856 lcd_puts(0, line++, buf);
858 line++;
860 x = control >> 31;
861 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
862 x, x?"Professional":"Consumer");
863 lcd_puts(0, line++, buf);
865 x = (control >> 30) & 1;
866 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
867 x, x?"Non-PCM":"PCM");
868 lcd_puts(0, line++, buf);
870 x = (control >> 29) & 1;
871 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
872 x, x?"Permitted":"Inhibited");
873 lcd_puts(0, line++, buf);
875 x = (control >> 27) & 7;
876 switch(x)
878 case 0:
879 s = "None";
880 break;
881 case 1:
882 s = "50/15us";
883 break;
884 default:
885 s = "Reserved";
886 break;
888 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
889 lcd_puts(0, line++, buf);
891 x = (control >> 24) & 3;
892 snprintf(buf, sizeof(buf), "Mode: %d", x);
893 lcd_puts(0, line++, buf);
895 category = (control >> 17) & 127;
896 switch(category)
898 case 0x00:
899 s = "General";
900 break;
901 case 0x40:
902 s = "Audio CD";
903 break;
904 default:
905 s = "Unknown";
907 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
908 lcd_puts(0, line++, buf);
910 x = (control >> 16) & 1;
911 generation = x;
912 if(((category & 0x70) == 0x10) ||
913 ((category & 0x70) == 0x40) ||
914 ((category & 0x78) == 0x38))
916 generation = !generation;
918 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
919 x, generation?"Original":"No ind.");
920 lcd_puts(0, line++, buf);
922 x = (control >> 12) & 15;
923 snprintf(buf, sizeof(buf), "Source: %d", x);
924 lcd_puts(0, line++, buf);
926 x = (control >> 8) & 15;
927 switch(x)
929 case 0:
930 s = "Unspecified";
931 break;
932 case 8:
933 s = "A (Left)";
934 break;
935 case 4:
936 s = "B (Right)";
937 break;
938 default:
939 s = "";
940 break;
942 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
943 lcd_puts(0, line++, buf);
945 x = (control >> 4) & 15;
946 switch(x)
948 case 0:
949 s = "44.1kHz";
950 break;
951 case 0x4:
952 s = "48kHz";
953 break;
954 case 0xc:
955 s = "32kHz";
956 break;
958 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
959 lcd_puts(0, line++, buf);
961 x = (control >> 2) & 3;
962 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
963 lcd_puts(0, line++, buf);
964 line++;
966 #ifndef SIMULATOR
967 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
968 spdif_measure_frequency());
969 lcd_puts(0, line++, buf);
970 #endif
972 lcd_update();
974 if (action_userabort(HZ/10))
975 break;
978 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
980 #ifdef HAVE_SPDIF_POWER
981 spdif_power_enable(global_settings.spdif_enable);
982 #endif
984 lcd_setfont(FONT_UI);
985 return false;
987 #endif /* CPU_COLDFIRE */
989 #ifndef SIMULATOR
990 #ifdef HAVE_LCD_BITMAP
991 /* button definitions */
992 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
993 (CONFIG_KEYPAD == IRIVER_H300_PAD)
994 # define DEBUG_CANCEL BUTTON_OFF
996 #elif CONFIG_KEYPAD == RECORDER_PAD
997 # define DEBUG_CANCEL BUTTON_OFF
999 #elif CONFIG_KEYPAD == ONDIO_PAD
1000 # define DEBUG_CANCEL BUTTON_MENU
1002 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
1003 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
1004 (CONFIG_KEYPAD == IPOD_4G_PAD)
1005 # define DEBUG_CANCEL BUTTON_MENU
1007 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
1008 # define DEBUG_CANCEL BUTTON_PLAY
1010 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
1011 # define DEBUG_CANCEL BUTTON_REC
1013 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1014 # define DEBUG_CANCEL BUTTON_RC_REC
1016 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
1017 # define DEBUG_CANCEL BUTTON_REW
1019 #elif (CONFIG_KEYPAD == MROBE100_PAD)
1020 # define DEBUG_CANCEL BUTTON_MENU
1022 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
1023 (CONFIG_KEYPAD == SANSA_C200_PAD)
1024 # define DEBUG_CANCEL BUTTON_LEFT
1026 /* This is temporary until the SA9200 touchpad works */
1027 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) || \
1028 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD)
1029 # define DEBUG_CANCEL BUTTON_POWER
1031 #endif /* key definitions */
1033 /* Test code!!! */
1034 bool dbg_ports(void)
1036 #if CONFIG_CPU == SH7034
1037 char buf[32];
1038 int adc_battery_voltage, adc_battery_level;
1040 lcd_setfont(FONT_SYSFIXED);
1041 lcd_clear_display();
1043 while(1)
1045 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1046 lcd_puts(0, 0, buf);
1047 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1048 lcd_puts(0, 1, buf);
1050 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1051 lcd_puts(0, 2, buf);
1052 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1053 lcd_puts(0, 3, buf);
1054 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1055 lcd_puts(0, 4, buf);
1056 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1057 lcd_puts(0, 5, buf);
1059 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1060 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1061 adc_battery_voltage % 1000, adc_battery_level);
1062 lcd_puts(0, 6, buf);
1064 lcd_update();
1065 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1067 lcd_setfont(FONT_UI);
1068 return false;
1071 #elif defined(CPU_COLDFIRE)
1072 unsigned int gpio_out;
1073 unsigned int gpio1_out;
1074 unsigned int gpio_read;
1075 unsigned int gpio1_read;
1076 unsigned int gpio_function;
1077 unsigned int gpio1_function;
1078 unsigned int gpio_enable;
1079 unsigned int gpio1_enable;
1080 int adc_buttons, adc_remote;
1081 int adc_battery_voltage, adc_battery_level;
1082 char buf[128];
1083 int line;
1085 lcd_clear_display();
1086 lcd_setfont(FONT_SYSFIXED);
1088 while(1)
1090 line = 0;
1091 gpio_read = GPIO_READ;
1092 gpio1_read = GPIO1_READ;
1093 gpio_out = GPIO_OUT;
1094 gpio1_out = GPIO1_OUT;
1095 gpio_function = GPIO_FUNCTION;
1096 gpio1_function = GPIO1_FUNCTION;
1097 gpio_enable = GPIO_ENABLE;
1098 gpio1_enable = GPIO1_ENABLE;
1100 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1101 lcd_puts(0, line++, buf);
1102 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1103 lcd_puts(0, line++, buf);
1104 snprintf(buf, sizeof(buf), "GPIO_FUNC: %08x", gpio_function);
1105 lcd_puts(0, line++, buf);
1106 snprintf(buf, sizeof(buf), "GPIO_ENA: %08x", gpio_enable);
1107 lcd_puts(0, line++, buf);
1109 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1110 lcd_puts(0, line++, buf);
1111 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1112 lcd_puts(0, line++, buf);
1113 snprintf(buf, sizeof(buf), "GPIO1_FUNC: %08x", gpio1_function);
1114 lcd_puts(0, line++, buf);
1115 snprintf(buf, sizeof(buf), "GPIO1_ENA: %08x", gpio1_enable);
1116 lcd_puts(0, line++, buf);
1118 adc_buttons = adc_read(ADC_BUTTONS);
1119 adc_remote = adc_read(ADC_REMOTE);
1120 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1121 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1122 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1123 button_scan_enabled() ? '+' : '-', adc_buttons);
1124 #else
1125 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1126 #endif
1127 lcd_puts(0, line++, buf);
1128 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1129 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1130 remote_detect() ? '+' : '-', adc_remote);
1131 #else
1132 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1133 #endif
1134 lcd_puts(0, line++, buf);
1135 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1136 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1137 adc_read(ADC_REMOTEDETECT));
1138 lcd_puts(0, line++, buf);
1139 #endif
1141 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1142 adc_battery_voltage % 1000, adc_battery_level);
1143 lcd_puts(0, line++, buf);
1145 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1146 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1147 lcd_puts(0, line++, buf);
1148 #endif
1150 lcd_update();
1151 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1153 lcd_setfont(FONT_UI);
1154 return false;
1158 #elif defined(CPU_PP502x)
1160 char buf[128];
1161 int line;
1163 lcd_clear_display();
1164 lcd_setfont(FONT_SYSFIXED);
1166 while(1)
1168 line = 0;
1169 lcd_puts(0, line++, "GPIO STATES:");
1170 snprintf(buf, sizeof(buf), "A: %02x E: %02x I: %02x",
1171 (unsigned int)GPIOA_INPUT_VAL,
1172 (unsigned int)GPIOE_INPUT_VAL,
1173 (unsigned int)GPIOI_INPUT_VAL);
1174 lcd_puts(0, line++, buf);
1175 snprintf(buf, sizeof(buf), "B: %02x F: %02x J: %02x",
1176 (unsigned int)GPIOB_INPUT_VAL,
1177 (unsigned int)GPIOF_INPUT_VAL,
1178 (unsigned int)GPIOJ_INPUT_VAL);
1179 lcd_puts(0, line++, buf);
1180 snprintf(buf, sizeof(buf), "C: %02x G: %02x K: %02x",
1181 (unsigned int)GPIOC_INPUT_VAL,
1182 (unsigned int)GPIOG_INPUT_VAL,
1183 (unsigned int)GPIOK_INPUT_VAL);
1184 lcd_puts(0, line++, buf);
1185 snprintf(buf, sizeof(buf), "D: %02x H: %02x L: %02x",
1186 (unsigned int)GPIOD_INPUT_VAL,
1187 (unsigned int)GPIOH_INPUT_VAL,
1188 (unsigned int)GPIOL_INPUT_VAL);
1189 lcd_puts(0, line++, buf);
1190 line++;
1191 snprintf(buf, sizeof(buf), "GPO32_VAL: %08lx", GPO32_VAL);
1192 lcd_puts(0, line++, buf);
1193 snprintf(buf, sizeof(buf), "GPO32_EN: %08lx", GPO32_ENABLE);
1194 lcd_puts(0, line++, buf);
1195 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1196 lcd_puts(0, line++, buf);
1197 snprintf(buf, sizeof(buf), "DEV_EN2: %08lx", DEV_EN2);
1198 lcd_puts(0, line++, buf);
1199 snprintf(buf, sizeof(buf), "DEV_EN3: %08lx", inl(0x60006044));
1200 lcd_puts(0, line++, buf); /* to be verified */
1201 snprintf(buf, sizeof(buf), "DEV_INIT1: %08lx", DEV_INIT1);
1202 lcd_puts(0, line++, buf);
1203 snprintf(buf, sizeof(buf), "DEV_INIT2: %08lx", DEV_INIT2);
1204 lcd_puts(0, line++, buf);
1205 #ifdef ADC_ACCESSORY
1206 snprintf(buf, sizeof(buf), "ACCESSORY: %d", adc_read(ADC_ACCESSORY));
1207 lcd_puts(0, line++, buf);
1208 #endif
1210 #if defined(IPOD_ACCESSORY_PROTOCOL)
1211 extern unsigned char serbuf[];
1212 snprintf(buf, sizeof(buf), "IAP PACKET: %02x %02x %02x %02x %02x %02x %02x %02x",
1213 serbuf[0], serbuf[1], serbuf[2], serbuf[3], serbuf[4], serbuf[5],
1214 serbuf[6], serbuf[7]);
1215 lcd_puts(0, line++, buf);
1216 #endif
1218 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1219 line++;
1220 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1221 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1222 lcd_puts(0, line++, buf);
1223 snprintf(buf, sizeof(buf), "REM: %03x PAD: %03x",
1224 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1225 lcd_puts(0, line++, buf);
1226 #elif defined(PHILIPS_HDD1630)
1227 line++;
1228 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1229 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1230 lcd_puts(0, line++, buf);
1231 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1232 snprintf(buf, sizeof(buf), "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1233 lcd_puts(0, line++, buf);
1234 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1235 lcd_puts(0, line++, buf);
1236 snprintf(buf, sizeof(buf), "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1237 lcd_puts(0, line++, buf);
1238 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1239 lcd_puts(0, line++, buf);
1240 snprintf(buf, sizeof(buf), "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1241 lcd_puts(0, line++, buf);
1242 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1243 lcd_puts(0, line++, buf);
1244 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1245 lcd_puts(0, line++, buf);
1246 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1247 lcd_puts(0, line++, buf);
1248 snprintf(buf, sizeof(buf), "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1249 lcd_puts(0, line++, buf);
1250 snprintf(buf, sizeof(buf), "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1251 lcd_puts(0, line++, buf);
1252 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1253 lcd_puts(0, line++, buf);
1254 #if !defined(PHILIPS_SA9200)
1255 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1256 lcd_puts(0, line++, buf);
1257 snprintf(buf, sizeof(buf), "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1258 lcd_puts(0, line++, buf);
1259 #endif
1260 #endif
1261 lcd_update();
1262 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1264 lcd_setfont(FONT_UI);
1265 return false;
1269 #elif CONFIG_CPU == PP5002
1270 char buf[128];
1271 int line;
1273 lcd_clear_display();
1274 lcd_setfont(FONT_SYSFIXED);
1276 while(1)
1278 line = 0;
1279 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x",
1280 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1281 lcd_puts(0, line++, buf);
1282 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x",
1283 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1284 lcd_puts(0, line++, buf);
1286 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1287 lcd_puts(0, line++, buf);
1288 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1289 lcd_puts(0, line++, buf);
1290 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1291 lcd_puts(0, line++, buf);
1292 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1293 lcd_puts(0, line++, buf);
1294 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1295 lcd_puts(0, line++, buf);
1296 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1297 lcd_puts(0, line++, buf);
1298 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1299 lcd_puts(0, line++, buf);
1300 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1301 lcd_puts(0, line++, buf);
1303 lcd_update();
1304 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1306 lcd_setfont(FONT_UI);
1307 return false;
1310 lcd_setfont(FONT_UI);
1311 #else
1312 return __dbg_ports();
1313 #endif /* CPU */
1314 return false;
1316 #else /* !HAVE_LCD_BITMAP */
1317 bool dbg_ports(void)
1319 char buf[32];
1320 int button;
1321 int adc_battery_voltage;
1322 int currval = 0;
1324 lcd_clear_display();
1326 while(1)
1328 switch(currval)
1330 case 0:
1331 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1332 break;
1333 case 1:
1334 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1335 break;
1336 case 2:
1337 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1338 break;
1339 case 3:
1340 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1341 break;
1342 case 4:
1343 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1344 break;
1345 case 5:
1346 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1347 break;
1348 case 6:
1349 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1350 break;
1351 case 7:
1352 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1353 break;
1354 case 8:
1355 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1356 break;
1357 case 9:
1358 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1359 break;
1361 lcd_puts(0, 0, buf);
1363 battery_read_info(&adc_battery_voltage, NULL);
1364 snprintf(buf, 32, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1365 adc_battery_voltage % 1000);
1366 lcd_puts(0, 1, buf);
1367 lcd_update();
1369 button = get_action(CONTEXT_SETTINGS,HZ/5);
1371 switch(button)
1373 case ACTION_STD_CANCEL:
1374 return false;
1376 case ACTION_SETTINGS_DEC:
1377 currval--;
1378 if(currval < 0)
1379 currval = 9;
1380 break;
1382 case ACTION_SETTINGS_INC:
1383 currval++;
1384 if(currval > 9)
1385 currval = 0;
1386 break;
1389 return false;
1391 #endif /* !HAVE_LCD_BITMAP */
1392 #endif /* !SIMULATOR */
1394 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1395 static bool dbg_pcf(void)
1397 char buf[128];
1398 int line;
1400 #ifdef HAVE_LCD_BITMAP
1401 lcd_setfont(FONT_SYSFIXED);
1402 #endif
1403 lcd_clear_display();
1405 while(1)
1407 line = 0;
1409 snprintf(buf, sizeof(buf), "DCDC1: %02x", pcf50605_read(0x1b));
1410 lcd_puts(0, line++, buf);
1411 snprintf(buf, sizeof(buf), "DCDC2: %02x", pcf50605_read(0x1c));
1412 lcd_puts(0, line++, buf);
1413 snprintf(buf, sizeof(buf), "DCDC3: %02x", pcf50605_read(0x1d));
1414 lcd_puts(0, line++, buf);
1415 snprintf(buf, sizeof(buf), "DCDC4: %02x", pcf50605_read(0x1e));
1416 lcd_puts(0, line++, buf);
1417 snprintf(buf, sizeof(buf), "DCDEC1: %02x", pcf50605_read(0x1f));
1418 lcd_puts(0, line++, buf);
1419 snprintf(buf, sizeof(buf), "DCDEC2: %02x", pcf50605_read(0x20));
1420 lcd_puts(0, line++, buf);
1421 snprintf(buf, sizeof(buf), "DCUDC1: %02x", pcf50605_read(0x21));
1422 lcd_puts(0, line++, buf);
1423 snprintf(buf, sizeof(buf), "DCUDC2: %02x", pcf50605_read(0x22));
1424 lcd_puts(0, line++, buf);
1425 snprintf(buf, sizeof(buf), "IOREGC: %02x", pcf50605_read(0x23));
1426 lcd_puts(0, line++, buf);
1427 snprintf(buf, sizeof(buf), "D1REGC: %02x", pcf50605_read(0x24));
1428 lcd_puts(0, line++, buf);
1429 snprintf(buf, sizeof(buf), "D2REGC: %02x", pcf50605_read(0x25));
1430 lcd_puts(0, line++, buf);
1431 snprintf(buf, sizeof(buf), "D3REGC: %02x", pcf50605_read(0x26));
1432 lcd_puts(0, line++, buf);
1433 snprintf(buf, sizeof(buf), "LPREG1: %02x", pcf50605_read(0x27));
1434 lcd_puts(0, line++, buf);
1436 lcd_update();
1437 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1439 lcd_setfont(FONT_UI);
1440 return false;
1444 lcd_setfont(FONT_UI);
1445 return false;
1447 #endif
1449 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1450 static bool dbg_cpufreq(void)
1452 char buf[128];
1453 int line;
1454 int button;
1456 #ifdef HAVE_LCD_BITMAP
1457 lcd_setfont(FONT_SYSFIXED);
1458 #endif
1459 lcd_clear_display();
1461 while(1)
1463 line = 0;
1465 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1466 lcd_puts(0, line++, buf);
1468 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1469 lcd_puts(0, line++, buf);
1471 lcd_update();
1472 button = get_action(CONTEXT_STD,HZ/10);
1474 switch(button)
1476 case ACTION_STD_PREV:
1477 cpu_boost(true);
1478 break;
1480 case ACTION_STD_NEXT:
1481 cpu_boost(false);
1482 break;
1484 case ACTION_STD_OK:
1485 while (get_cpu_boost_counter() > 0)
1486 cpu_boost(false);
1487 set_cpu_frequency(CPUFREQ_DEFAULT);
1488 break;
1490 case ACTION_STD_CANCEL:
1491 lcd_setfont(FONT_UI);
1492 return false;
1495 lcd_setfont(FONT_UI);
1496 return false;
1498 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1500 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1501 #include "tsc2100.h"
1502 static char *itob(int n, int len)
1504 static char binary[64];
1505 int i,j;
1506 for (i=1, j=0;i<=len;i++)
1508 binary[j++] = n&(1<<(len-i))?'1':'0';
1509 if (i%4 == 0)
1510 binary[j++] = ' ';
1512 binary[j] = '\0';
1513 return binary;
1515 static char* tsc2100_debug_getname(int selected_item, void * data,
1516 char *buffer, size_t buffer_len)
1518 int *page = (int*)data;
1519 bool reserved = false;
1520 switch (*page)
1522 case 0:
1523 if ((selected_item > 0x0a) ||
1524 (selected_item == 0x04) ||
1525 (selected_item == 0x08))
1526 reserved = true;
1527 break;
1528 case 1:
1529 if ((selected_item > 0x05) ||
1530 (selected_item == 0x02))
1531 reserved = true;
1532 break;
1533 case 2:
1534 if (selected_item > 0x1e)
1535 reserved = true;
1536 break;
1538 if (reserved)
1539 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1540 else
1541 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1542 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1543 return buffer;
1545 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1547 int *page = (int*)lists->data;
1548 if (action == ACTION_STD_OK)
1550 *page = (*page+1)%3;
1551 snprintf(lists->title, 32,
1552 "tsc2100 registers - Page %d", *page);
1553 return ACTION_REDRAW;
1555 return action;
1557 static bool tsc2100_debug(void)
1559 int page = 0;
1560 char title[32] = "tsc2100 registers - Page 0";
1561 struct simplelist_info info;
1562 simplelist_info_init(&info, title, 32, &page);
1563 info.timeout = HZ/100;
1564 info.get_name = tsc2100_debug_getname;
1565 info.action_callback= tsc2100debug_action_callback;
1566 return simplelist_show_list(&info);
1568 #endif
1569 #ifndef SIMULATOR
1570 #ifdef HAVE_LCD_BITMAP
1572 * view_battery() shows a automatically scaled graph of the battery voltage
1573 * over time. Usable for estimating battery life / charging rate.
1574 * The power_history array is updated in power_thread of powermgmt.c.
1577 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1578 #define BAT_YSPACE (LCD_HEIGHT - 20)
1580 static bool view_battery(void)
1582 int view = 0;
1583 int i, x, y;
1584 unsigned short maxv, minv;
1585 char buf[32];
1587 lcd_setfont(FONT_SYSFIXED);
1589 while(1)
1591 lcd_clear_display();
1592 switch (view) {
1593 case 0: /* voltage history graph */
1594 /* Find maximum and minimum voltage for scaling */
1595 minv = power_history[0];
1596 maxv = minv + 1;
1597 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1598 if (power_history[i] > maxv)
1599 maxv = power_history[i];
1600 if (power_history[i] < minv)
1601 minv = power_history[i];
1604 snprintf(buf, 30, "Battery %d.%03d", power_history[0] / 1000,
1605 power_history[0] % 1000);
1606 lcd_puts(0, 0, buf);
1607 snprintf(buf, 30, "scale %d.%03d-%d.%03dV",
1608 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1609 lcd_puts(0, 1, buf);
1611 x = 0;
1612 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1613 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1614 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1615 lcd_vline(x, LCD_HEIGHT-1, 20);
1616 lcd_set_drawmode(DRMODE_SOLID);
1617 lcd_vline(x, LCD_HEIGHT-1,
1618 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1619 x++;
1622 break;
1624 case 1: /* status: */
1625 lcd_puts(0, 0, "Power status:");
1627 battery_read_info(&y, NULL);
1628 snprintf(buf, 30, "Battery: %d.%03d V", y / 1000, y % 1000);
1629 lcd_puts(0, 1, buf);
1630 #ifdef ADC_EXT_POWER
1631 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1632 snprintf(buf, 30, "External: %d.%03d V", y / 1000, y % 1000);
1633 lcd_puts(0, 2, buf);
1634 #endif
1635 #if CONFIG_CHARGING
1636 #if defined ARCHOS_RECORDER
1637 snprintf(buf, 30, "Chgr: %s %s",
1638 charger_inserted() ? "present" : "absent",
1639 charger_enabled() ? "on" : "off");
1640 lcd_puts(0, 3, buf);
1641 snprintf(buf, 30, "short delta: %d", short_delta);
1642 lcd_puts(0, 5, buf);
1643 snprintf(buf, 30, "long delta: %d", long_delta);
1644 lcd_puts(0, 6, buf);
1645 lcd_puts(0, 7, power_message);
1646 snprintf(buf, 30, "USB Inserted: %s",
1647 usb_inserted() ? "yes" : "no");
1648 lcd_puts(0, 8, buf);
1649 #elif defined IRIVER_H300_SERIES
1650 snprintf(buf, 30, "USB Charging Enabled: %s",
1651 usb_charging_enabled() ? "yes" : "no");
1652 lcd_puts(0, 9, buf);
1653 #elif defined IPOD_NANO || defined IPOD_VIDEO
1654 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1655 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1656 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1657 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1658 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1660 snprintf(buf, 30, "USB pwr: %s",
1661 usb_pwr ? "present" : "absent");
1662 lcd_puts(0, 3, buf);
1663 snprintf(buf, 30, "EXT pwr: %s",
1664 ext_pwr ? "present" : "absent");
1665 lcd_puts(0, 4, buf);
1666 snprintf(buf, 30, "Battery: %s",
1667 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1668 lcd_puts(0, 5, buf);
1669 snprintf(buf, 30, "Dock mode: %s",
1670 dock ? "enabled" : "disabled");
1671 lcd_puts(0, 6, buf);
1672 snprintf(buf, 30, "Headphone: %s",
1673 headphone ? "connected" : "disconnected");
1674 lcd_puts(0, 7, buf);
1675 #elif defined TOSHIBA_GIGABEAT_S
1676 int line = 3;
1677 unsigned int st;
1679 static const unsigned char * const chrgstate_strings[] =
1681 "Disabled",
1682 "Error",
1683 "Discharging",
1684 "Precharge",
1685 "Constant Voltage",
1686 "Constant Current",
1687 "<unknown>",
1690 snprintf(buf, 30, "Charger: %s",
1691 charger_inserted() ? "present" : "absent");
1692 lcd_puts(0, line++, buf);
1694 st = power_input_status() &
1695 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1696 snprintf(buf, 30, "%s%s",
1697 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1698 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1699 lcd_puts(0, line++, buf);
1701 snprintf(buf, 30, "IUSB Max: %d", usb_allowed_current());
1702 lcd_puts(0, line++, buf);
1704 y = ARRAYLEN(chrgstate_strings) - 1;
1706 switch (charge_state)
1708 case CHARGE_STATE_DISABLED: y--;
1709 case CHARGE_STATE_ERROR: y--;
1710 case DISCHARGING: y--;
1711 case TRICKLE: y--;
1712 case TOPOFF: y--;
1713 case CHARGING: y--;
1714 default:;
1717 snprintf(buf, 30, "State: %s", chrgstate_strings[y]);
1718 lcd_puts(0, line++, buf);
1720 snprintf(buf, 30, "Battery Switch: %s",
1721 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1722 lcd_puts(0, line++, buf);
1724 y = chrgraw_adc_voltage();
1725 snprintf(buf, 30, "CHRGRAW: %d.%03d V",
1726 y / 1000, y % 1000);
1727 lcd_puts(0, line++, buf);
1729 y = application_supply_adc_voltage();
1730 snprintf(buf, 30, "BP : %d.%03d V",
1731 y / 1000, y % 1000);
1732 lcd_puts(0, line++, buf);
1734 y = battery_adc_charge_current();
1735 if (y < 0) x = '-', y = -y;
1736 else x = ' ';
1737 snprintf(buf, 30, "CHRGISN:%c%d mA", x, y);
1738 lcd_puts(0, line++, buf);
1740 y = cccv_regulator_dissipation();
1741 snprintf(buf, 30, "P CCCV : %d mW", y);
1742 lcd_puts(0, line++, buf);
1744 y = battery_charge_current();
1745 if (y < 0) x = '-', y = -y;
1746 else x = ' ';
1747 snprintf(buf, 30, "I Charge:%c%d mA", x, y);
1748 lcd_puts(0, line++, buf);
1750 y = battery_adc_temp();
1752 if (y != INT_MIN) {
1753 snprintf(buf, 30, "T Battery: %dC (%dF)", y,
1754 (9*y + 160) / 5);
1755 } else {
1756 /* Conversion disabled */
1757 snprintf(buf, 30, "T Battery: ?");
1760 lcd_puts(0, line++, buf);
1761 #elif defined(SANSA_E200) || defined(SANSA_C200)
1762 const int first = CHARGE_STATE_DISABLED;
1763 static const char * const chrgstate_strings[] =
1765 [CHARGE_STATE_DISABLED-first] = "Disabled",
1766 [CHARGE_STATE_ERROR-first] = "Error",
1767 [DISCHARGING-first] = "Discharging",
1768 [CHARGING-first] = "Charging",
1770 const char *str = NULL;
1772 snprintf(buf, 30, "Charger: %s",
1773 charger_inserted() ? "present" : "absent");
1774 lcd_puts(0, 3, buf);
1776 y = charge_state - first;
1777 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1778 str = chrgstate_strings[y];
1780 snprintf(buf, sizeof(buf), "State: %s",
1781 str ? str : "<unknown>");
1782 lcd_puts(0, 4, buf);
1784 snprintf(buf, sizeof(buf), "CHARGER: %02X",
1785 ascodec_read(AS3514_CHARGER));
1786 lcd_puts(0, 5, buf);
1787 #else
1788 snprintf(buf, 30, "Charger: %s",
1789 charger_inserted() ? "present" : "absent");
1790 lcd_puts(0, 3, buf);
1791 #endif /* target type */
1792 #endif /* CONFIG_CHARGING */
1793 break;
1795 case 2: /* voltage deltas: */
1796 lcd_puts(0, 0, "Voltage deltas:");
1798 for (i = 0; i <= 6; i++) {
1799 y = power_history[i] - power_history[i+1];
1800 snprintf(buf, 30, "-%d min: %s%d.%03d V", i,
1801 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1802 ((y < 0) ? y * -1 : y ) % 1000);
1803 lcd_puts(0, i+1, buf);
1805 break;
1807 case 3: /* remaining time estimation: */
1809 #ifdef ARCHOS_RECORDER
1810 snprintf(buf, 30, "charge_state: %d", charge_state);
1811 lcd_puts(0, 0, buf);
1813 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1814 lcd_puts(0, 1, buf);
1816 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1817 lcd_puts(0, 2, buf);
1819 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1820 lcd_puts(0, 3, buf);
1822 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1823 lcd_puts(0, 4, buf);
1824 #endif /* ARCHOS_RECORDER */
1826 snprintf(buf, 30, "Last PwrHist: %d.%03dV",
1827 power_history[0] / 1000,
1828 power_history[0] % 1000);
1829 lcd_puts(0, 5, buf);
1831 snprintf(buf, 30, "battery level: %d%%", battery_level());
1832 lcd_puts(0, 6, buf);
1834 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1835 lcd_puts(0, 7, buf);
1836 break;
1839 lcd_update();
1841 switch(get_action(CONTEXT_STD,HZ/2))
1843 case ACTION_STD_PREV:
1844 if (view)
1845 view--;
1846 break;
1848 case ACTION_STD_NEXT:
1849 if (view < 3)
1850 view++;
1851 break;
1853 case ACTION_STD_CANCEL:
1854 lcd_setfont(FONT_UI);
1855 return false;
1858 lcd_setfont(FONT_UI);
1859 return false;
1862 #endif /* HAVE_LCD_BITMAP */
1863 #endif
1865 #ifndef SIMULATOR
1866 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1868 #if (CONFIG_STORAGE & STORAGE_MMC)
1869 #define CARDTYPE "MMC"
1870 #elif (CONFIG_STORAGE & STORAGE_SD)
1871 #define CARDTYPE "microSD"
1872 #endif
1874 static int disk_callback(int btn, struct gui_synclist *lists)
1876 tCardInfo *card;
1877 int *cardnum = (int*)lists->data;
1878 unsigned char card_name[7];
1879 unsigned char pbuf[32];
1880 char *title = lists->title;
1881 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1882 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1883 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1884 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1885 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1886 "3.1-3.31", "4.0" };
1887 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1889 #ifdef HAVE_HOTSWAP
1890 if (btn == ACTION_STD_OK)
1892 *cardnum ^= 0x1; /* change cards */
1894 #endif
1896 simplelist_set_line_count(0);
1898 card = card_get_info(*cardnum);
1900 if (card->initialized > 0)
1902 card_name[6] = '\0';
1903 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1904 simplelist_addline(SIMPLELIST_ADD_LINE,
1905 "%s Rev %d.%d", card_name,
1906 (int) card_extract_bits(card->cid, 72, 4),
1907 (int) card_extract_bits(card->cid, 76, 4));
1908 simplelist_addline(SIMPLELIST_ADD_LINE,
1909 "Prod: %d/%d",
1910 (int) card_extract_bits(card->cid, 112, 4),
1911 (int) card_extract_bits(card->cid, 116, 4) + 1997);
1912 simplelist_addline(SIMPLELIST_ADD_LINE,
1913 "Ser#: 0x%08lx",
1914 card_extract_bits(card->cid, 80, 32));
1915 simplelist_addline(SIMPLELIST_ADD_LINE,
1916 "M=%02x, O=%04x",
1917 (int) card_extract_bits(card->cid, 0, 8),
1918 (int) card_extract_bits(card->cid, 8, 16));
1919 int temp = card_extract_bits(card->csd, 2, 4);
1920 simplelist_addline(SIMPLELIST_ADD_LINE,
1921 CARDTYPE " v%s", temp < 5 ?
1922 spec_vers[temp] : "?.?");
1923 simplelist_addline(SIMPLELIST_ADD_LINE,
1924 "Blocks: 0x%08lx", card->numblocks);
1925 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1926 kbit_units, false);
1927 simplelist_addline(SIMPLELIST_ADD_LINE,
1928 "Speed: %s", pbuf);
1929 output_dyn_value(pbuf, sizeof pbuf, card->tsac,
1930 nsec_units, false);
1931 simplelist_addline(SIMPLELIST_ADD_LINE,
1932 "Tsac: %s", pbuf);
1933 simplelist_addline(SIMPLELIST_ADD_LINE,
1934 "Nsac: %d clk", card->nsac);
1935 simplelist_addline(SIMPLELIST_ADD_LINE,
1936 "R2W: *%d", card->r2w_factor);
1937 simplelist_addline(SIMPLELIST_ADD_LINE,
1938 "IRmax: %d..%d mA",
1939 i_vmin[card_extract_bits(card->csd, 66, 3)],
1940 i_vmax[card_extract_bits(card->csd, 69, 3)]);
1941 simplelist_addline(SIMPLELIST_ADD_LINE,
1942 "IWmax: %d..%d mA",
1943 i_vmin[card_extract_bits(card->csd, 72, 3)],
1944 i_vmax[card_extract_bits(card->csd, 75, 3)]);
1946 else if (card->initialized == 0)
1948 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1950 #if (CONFIG_STORAGE & STORAGE_SD)
1951 else /* card->initialized < 0 */
1953 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1955 #endif
1956 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1957 gui_synclist_set_title(lists, title, Icon_NOICON);
1958 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1959 gui_synclist_select_item(lists, 0);
1960 btn = ACTION_REDRAW;
1962 return btn;
1964 #elif (CONFIG_STORAGE & STORAGE_ATA)
1965 static int disk_callback(int btn, struct gui_synclist *lists)
1967 (void)lists;
1968 int i;
1969 char buf[128];
1970 unsigned short* identify_info = ata_get_identify();
1971 bool timing_info_present = false;
1972 (void)btn;
1974 simplelist_set_line_count(0);
1976 for (i=0; i < 20; i++)
1977 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1978 buf[40]=0;
1979 /* kill trailing space */
1980 for (i=39; i && buf[i]==' '; i--)
1981 buf[i] = 0;
1982 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1983 for (i=0; i < 4; i++)
1984 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1985 buf[8]=0;
1986 simplelist_addline(SIMPLELIST_ADD_LINE,
1987 "Firmware: %s", buf);
1988 snprintf(buf, sizeof buf, "%ld MB",
1989 ((unsigned long)identify_info[61] << 16 |
1990 (unsigned long)identify_info[60]) / 2048 );
1991 simplelist_addline(SIMPLELIST_ADD_LINE,
1992 "Size: %s", buf);
1993 unsigned long free;
1994 fat_size( IF_MV2(0,) NULL, &free );
1995 simplelist_addline(SIMPLELIST_ADD_LINE,
1996 "Free: %ld MB", free / 1024);
1997 simplelist_addline(SIMPLELIST_ADD_LINE,
1998 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
1999 i = identify_info[83] & (1<<3);
2000 simplelist_addline(SIMPLELIST_ADD_LINE,
2001 "Power mgmt: %s", i ? "enabled" : "unsupported");
2002 i = identify_info[83] & (1<<9);
2003 simplelist_addline(SIMPLELIST_ADD_LINE,
2004 "Noise mgmt: %s", i ? "enabled" : "unsupported");
2005 i = identify_info[82] & (1<<6);
2006 simplelist_addline(SIMPLELIST_ADD_LINE,
2007 "Read-ahead: %s", i ? "enabled" : "unsupported");
2008 timing_info_present = identify_info[53] & (1<<1);
2009 if(timing_info_present) {
2010 char pio3[2], pio4[2];pio3[1] = 0;
2011 pio4[1] = 0;
2012 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
2013 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
2014 simplelist_addline(SIMPLELIST_ADD_LINE,
2015 "PIO modes: 0 1 2 %s %s", pio3, pio4);
2017 else {
2018 simplelist_addline(SIMPLELIST_ADD_LINE,
2019 "No PIO mode info");
2021 timing_info_present = identify_info[53] & (1<<1);
2022 if(timing_info_present) {
2023 simplelist_addline(SIMPLELIST_ADD_LINE,
2024 "Cycle times %dns/%dns",
2025 identify_info[67],
2026 identify_info[68] );
2027 } else {
2028 simplelist_addline(SIMPLELIST_ADD_LINE,
2029 "No timing info");
2031 #if defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S)
2032 if (identify_info[63] & (1<<0)) {
2033 char mdma0[2], mdma1[2], mdma2[2];
2034 mdma0[1] = mdma1[1] = mdma2[1] = 0;
2035 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
2036 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
2037 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
2038 simplelist_addline(SIMPLELIST_ADD_LINE,
2039 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
2040 simplelist_addline(SIMPLELIST_ADD_LINE,
2041 "MDMA Cycle times %dns/%dns",
2042 identify_info[65],
2043 identify_info[66] );
2045 else {
2046 simplelist_addline(SIMPLELIST_ADD_LINE,
2047 "No MDMA mode info");
2049 if (identify_info[88] & (1<<0)) {
2050 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2];
2051 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = 0;
2052 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
2053 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
2054 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
2055 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
2056 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
2057 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
2058 simplelist_addline(SIMPLELIST_ADD_LINE,
2059 "UDMA modes: %s %s %s %s %s %s", udma0, udma1, udma2,
2060 udma3, udma4, udma5);
2062 else {
2063 simplelist_addline(SIMPLELIST_ADD_LINE,
2064 "No UDMA mode info");
2066 #endif /* defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S) */
2067 timing_info_present = identify_info[53] & (1<<1);
2068 if(timing_info_present) {
2069 i = identify_info[49] & (1<<11);
2070 simplelist_addline(SIMPLELIST_ADD_LINE,
2071 "IORDY support: %s", i ? "yes" : "no");
2072 i = identify_info[49] & (1<<10);
2073 simplelist_addline(SIMPLELIST_ADD_LINE,
2074 "IORDY disable: %s", i ? "yes" : "no");
2075 } else {
2076 simplelist_addline(SIMPLELIST_ADD_LINE,
2077 "No timing info");
2079 simplelist_addline(SIMPLELIST_ADD_LINE,
2080 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2081 return btn;
2083 #else /* No SD, MMC or ATA */
2084 static int disk_callback(int btn, struct gui_synclist *lists)
2086 (void)btn;
2087 (void)lists;
2088 struct storage_info info;
2089 storage_get_info(0,&info);
2090 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
2091 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
2092 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
2093 simplelist_addline(SIMPLELIST_ADD_LINE,
2094 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
2095 unsigned long free;
2096 fat_size( IF_MV2(0,) NULL, &free );
2097 simplelist_addline(SIMPLELIST_ADD_LINE,
2098 "Free: %ld MB", free / 1024);
2099 simplelist_addline(SIMPLELIST_ADD_LINE,
2100 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2101 return btn;
2103 #endif
2105 #if (CONFIG_STORAGE & STORAGE_ATA)
2106 static bool dbg_identify_info(void)
2108 int fd = creat("/identify_info.bin");
2109 if(fd >= 0)
2111 #ifdef ROCKBOX_LITTLE_ENDIAN
2112 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
2113 #else
2114 write(fd, ata_get_identify(), SECTOR_SIZE);
2115 #endif
2116 close(fd);
2118 return false;
2120 #endif
2122 static bool dbg_disk_info(void)
2124 struct simplelist_info info;
2125 simplelist_info_init(&info, "Disk Info", 1, NULL);
2126 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
2127 char title[16];
2128 int card = 0;
2129 info.callback_data = (void*)&card;
2130 info.title = title;
2131 #endif
2132 info.action_callback = disk_callback;
2133 info.hide_selection = true;
2134 info.scroll_all = true;
2135 return simplelist_show_list(&info);
2137 #endif /* !SIMULATOR */
2139 #ifdef HAVE_DIRCACHE
2140 static int dircache_callback(int btn, struct gui_synclist *lists)
2142 (void)btn; (void)lists;
2143 simplelist_set_line_count(0);
2144 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
2145 dircache_is_enabled() ? "Yes" : "No");
2146 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
2147 dircache_get_cache_size());
2148 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
2149 global_status.dircache_size);
2150 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
2151 DIRCACHE_LIMIT);
2152 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
2153 dircache_get_reserve_used(), DIRCACHE_RESERVE);
2154 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2155 dircache_get_build_ticks() / HZ);
2156 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2157 dircache_get_entry_count());
2158 return btn;
2161 static bool dbg_dircache_info(void)
2163 struct simplelist_info info;
2164 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2165 info.action_callback = dircache_callback;
2166 info.hide_selection = true;
2167 info.scroll_all = true;
2168 return simplelist_show_list(&info);
2171 #endif /* HAVE_DIRCACHE */
2173 #ifdef HAVE_TAGCACHE
2174 static int database_callback(int btn, struct gui_synclist *lists)
2176 (void)lists;
2177 struct tagcache_stat *stat = tagcache_get_stat();
2178 static bool synced = false;
2180 simplelist_set_line_count(0);
2182 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2183 stat->initialized ? "Yes" : "No");
2184 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2185 stat->ready ? "Yes" : "No");
2186 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2187 stat->ramcache ? "Yes" : "No");
2188 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2189 stat->ramcache_used, stat->ramcache_allocated);
2190 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2191 stat->progress, stat->processed_entries);
2192 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2193 stat->curentry ? stat->curentry : "---");
2194 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2195 stat->commit_step);
2196 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2197 stat->commit_delayed ? "Yes" : "No");
2199 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2200 stat->queue_length);
2202 if (synced)
2204 synced = false;
2205 tagcache_screensync_event();
2208 if (!btn && stat->curentry)
2210 synced = true;
2211 return ACTION_REDRAW;
2214 if (btn == ACTION_STD_CANCEL)
2215 tagcache_screensync_enable(false);
2217 return btn;
2219 static bool dbg_tagcache_info(void)
2221 struct simplelist_info info;
2222 simplelist_info_init(&info, "Database Info", 8, NULL);
2223 info.action_callback = database_callback;
2224 info.hide_selection = true;
2225 info.scroll_all = true;
2227 /* Don't do nonblock here, must give enough processing time
2228 for tagcache thread. */
2229 /* info.timeout = TIMEOUT_NOBLOCK; */
2230 info.timeout = 1;
2231 tagcache_screensync_enable(true);
2232 return simplelist_show_list(&info);
2234 #endif
2236 #if CONFIG_CPU == SH7034
2237 static bool dbg_save_roms(void)
2239 int fd;
2240 int oldmode = system_memory_guard(MEMGUARD_NONE);
2242 fd = creat("/internal_rom_0000-FFFF.bin");
2243 if(fd >= 0)
2245 write(fd, (void *)0, 0x10000);
2246 close(fd);
2249 fd = creat("/internal_rom_2000000-203FFFF.bin");
2250 if(fd >= 0)
2252 write(fd, (void *)0x2000000, 0x40000);
2253 close(fd);
2256 system_memory_guard(oldmode);
2257 return false;
2259 #elif defined CPU_COLDFIRE
2260 static bool dbg_save_roms(void)
2262 int fd;
2263 int oldmode = system_memory_guard(MEMGUARD_NONE);
2265 #if defined(IRIVER_H100_SERIES)
2266 fd = creat("/internal_rom_000000-1FFFFF.bin");
2267 #elif defined(IRIVER_H300_SERIES)
2268 fd = creat("/internal_rom_000000-3FFFFF.bin");
2269 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2270 fd = creat("/internal_rom_000000-3FFFFF.bin");
2271 #endif
2272 if(fd >= 0)
2274 write(fd, (void *)0, FLASH_SIZE);
2275 close(fd);
2277 system_memory_guard(oldmode);
2279 #ifdef HAVE_EEPROM
2280 fd = creat("/internal_eeprom.bin");
2281 if (fd >= 0)
2283 int old_irq_level;
2284 char buf[EEPROM_SIZE];
2285 int err;
2287 old_irq_level = disable_irq_save();
2289 err = eeprom_24cxx_read(0, buf, sizeof buf);
2291 restore_irq(old_irq_level);
2293 if (err)
2294 splashf(HZ*3, "Eeprom read failure (%d)", err);
2295 else
2297 write(fd, buf, sizeof buf);
2300 close(fd);
2302 #endif
2304 return false;
2306 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
2307 static bool dbg_save_roms(void)
2309 int fd;
2311 fd = creat("/internal_rom_000000-0FFFFF.bin");
2312 if(fd >= 0)
2314 write(fd, (void *)0x20000000, FLASH_SIZE);
2315 close(fd);
2318 return false;
2320 #endif /* CPU */
2322 #ifndef SIMULATOR
2323 #if CONFIG_TUNER
2324 static int radio_callback(int btn, struct gui_synclist *lists)
2326 (void)lists;
2327 if (btn == ACTION_STD_CANCEL)
2328 return btn;
2329 simplelist_set_line_count(1);
2331 #if (CONFIG_TUNER & LV24020LP)
2332 simplelist_addline(SIMPLELIST_ADD_LINE,
2333 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2334 simplelist_addline(SIMPLELIST_ADD_LINE,
2335 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2336 simplelist_addline(SIMPLELIST_ADD_LINE,
2337 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2338 simplelist_addline(SIMPLELIST_ADD_LINE,
2339 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2340 simplelist_addline(SIMPLELIST_ADD_LINE,
2341 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2342 simplelist_addline(SIMPLELIST_ADD_LINE,
2343 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2344 simplelist_addline(SIMPLELIST_ADD_LINE,
2345 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2346 #endif /* LV24020LP */
2347 #if (CONFIG_TUNER & S1A0903X01)
2348 simplelist_addline(SIMPLELIST_ADD_LINE,
2349 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2350 /* This one doesn't return dynamic data atm */
2351 #endif /* S1A0903X01 */
2352 #if (CONFIG_TUNER & TEA5767)
2353 struct tea5767_dbg_info nfo;
2354 tea5767_dbg_info(&nfo);
2355 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2356 simplelist_addline(SIMPLELIST_ADD_LINE,
2357 " Read: %02X %02X %02X %02X %02X",
2358 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2359 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2360 (unsigned)nfo.read_regs[4]);
2361 simplelist_addline(SIMPLELIST_ADD_LINE,
2362 " Write: %02X %02X %02X %02X %02X",
2363 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2364 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2365 (unsigned)nfo.write_regs[4]);
2366 #endif /* TEA5767 */
2367 #if (CONFIG_TUNER & SI4700)
2368 struct si4700_dbg_info nfo;
2369 si4700_dbg_info(&nfo);
2370 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
2371 /* Registers */
2372 simplelist_addline(SIMPLELIST_ADD_LINE,
2373 "%04X %04X %04X %04X",
2374 (unsigned)nfo.regs[0], (unsigned)nfo.regs[1],
2375 (unsigned)nfo.regs[2], (unsigned)nfo.regs[3]);
2376 simplelist_addline(SIMPLELIST_ADD_LINE,
2377 "%04X %04X %04X %04X",
2378 (unsigned)nfo.regs[4], (unsigned)nfo.regs[5],
2379 (unsigned)nfo.regs[6], (unsigned)nfo.regs[7]);
2380 simplelist_addline(SIMPLELIST_ADD_LINE,
2381 "%04X %04X %04X %04X",
2382 (unsigned)nfo.regs[8], (unsigned)nfo.regs[9],
2383 (unsigned)nfo.regs[10], (unsigned)nfo.regs[11]);
2384 simplelist_addline(SIMPLELIST_ADD_LINE,
2385 "%04X %04X %04X %04X",
2386 (unsigned)nfo.regs[12], (unsigned)nfo.regs[13],
2387 (unsigned)nfo.regs[14], (unsigned)nfo.regs[15]);
2388 #endif /* SI4700 */
2389 return ACTION_REDRAW;
2391 static bool dbg_fm_radio(void)
2393 struct simplelist_info info;
2394 info.scroll_all = true;
2395 simplelist_info_init(&info, "FM Radio", 1, NULL);
2396 simplelist_set_line_count(0);
2397 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2398 radio_hardware_present() ? "yes" : "no");
2400 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2401 info.hide_selection = true;
2402 return simplelist_show_list(&info);
2404 #endif /* CONFIG_TUNER */
2405 #endif /* !SIMULATOR */
2407 #ifdef HAVE_LCD_BITMAP
2408 extern bool do_screendump_instead_of_usb;
2410 static bool dbg_screendump(void)
2412 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2413 splashf(HZ, "Screendump %s",
2414 do_screendump_instead_of_usb?"enabled":"disabled");
2415 return false;
2417 #endif /* HAVE_LCD_BITMAP */
2419 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2420 static bool dbg_set_memory_guard(void)
2422 static const struct opt_items names[MAXMEMGUARD] = {
2423 { "None", -1 },
2424 { "Flash ROM writes", -1 },
2425 { "Zero area (all)", -1 }
2427 int mode = system_memory_guard(MEMGUARD_KEEP);
2429 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2430 system_memory_guard(mode);
2432 return false;
2434 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2436 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2437 static bool dbg_write_eeprom(void)
2439 int fd;
2440 int rc;
2441 int old_irq_level;
2442 char buf[EEPROM_SIZE];
2443 int err;
2445 fd = open("/internal_eeprom.bin", O_RDONLY);
2447 if (fd >= 0)
2449 rc = read(fd, buf, EEPROM_SIZE);
2451 if(rc == EEPROM_SIZE)
2453 old_irq_level = disable_irq_save();
2455 err = eeprom_24cxx_write(0, buf, sizeof buf);
2456 if (err)
2457 splashf(HZ*3, "Eeprom write failure (%d)", err);
2458 else
2459 splash(HZ*3, "Eeprom written successfully");
2461 restore_irq(old_irq_level);
2463 else
2465 splashf(HZ*3, "File read error (%d)",rc);
2467 close(fd);
2469 else
2471 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2474 return false;
2476 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2477 #ifdef CPU_BOOST_LOGGING
2478 static bool cpu_boost_log(void)
2480 int i = 0,j=0;
2481 int count = cpu_boost_log_getcount();
2482 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2483 char *str;
2484 bool done;
2485 lcd_setfont(FONT_SYSFIXED);
2486 str = cpu_boost_log_getlog_first();
2487 while (i < count)
2489 lcd_clear_display();
2490 for(j=0; j<lines; j++,i++)
2492 if (!str)
2493 str = cpu_boost_log_getlog_next();
2494 if (str)
2496 lcd_puts(0, j,str);
2498 str = NULL;
2500 lcd_update();
2501 done = false;
2502 while (!done)
2504 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2506 case ACTION_STD_OK:
2507 case ACTION_STD_PREV:
2508 case ACTION_STD_NEXT:
2509 done = true;
2510 break;
2511 case ACTION_STD_CANCEL:
2512 i = count;
2513 done = true;
2514 break;
2518 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2519 lcd_setfont(FONT_UI);
2520 return false;
2522 #endif
2524 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2525 extern bool wheel_is_touched;
2526 extern int old_wheel_value;
2527 extern int new_wheel_value;
2528 extern int wheel_delta;
2529 extern unsigned int accumulated_wheel_delta;
2530 extern unsigned int wheel_velocity;
2532 static bool dbg_scrollwheel(void)
2534 char buf[64];
2535 unsigned int speed;
2537 lcd_setfont(FONT_SYSFIXED);
2539 while (1)
2541 if (action_userabort(HZ/10))
2542 break;
2544 lcd_clear_display();
2546 /* show internal variables of scrollwheel driver */
2547 snprintf(buf, sizeof(buf), "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2548 lcd_puts(0, 0, buf);
2549 snprintf(buf, sizeof(buf), "new position: %2d", new_wheel_value);
2550 lcd_puts(0, 1, buf);
2551 snprintf(buf, sizeof(buf), "old position: %2d", old_wheel_value);
2552 lcd_puts(0, 2, buf);
2553 snprintf(buf, sizeof(buf), "wheel delta: %2d", wheel_delta);
2554 lcd_puts(0, 3, buf);
2555 snprintf(buf, sizeof(buf), "accumulated delta: %2d", accumulated_wheel_delta);
2556 lcd_puts(0, 4, buf);
2557 snprintf(buf, sizeof(buf), "velo [deg/s]: %4d", (int)wheel_velocity);
2558 lcd_puts(0, 5, buf);
2560 /* show effective accelerated scrollspeed */
2561 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2562 snprintf(buf, sizeof(buf), "accel. speed: %4d", speed);
2563 lcd_puts(0, 6, buf);
2565 lcd_update();
2567 lcd_setfont(FONT_UI);
2568 return false;
2570 #endif
2572 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2573 static bool logf_usb_serial(void)
2575 bool serial_enabled = !usb_core_driver_enabled(USB_DRIVER_SERIAL);
2576 usb_core_enable_driver(USB_DRIVER_SERIAL,serial_enabled);
2577 splashf(HZ, "USB logf %s",
2578 serial_enabled?"enabled":"disabled");
2579 return false;
2581 #endif
2583 #if 0 && defined(HAVE_USBSTACK) && defined(USB_STORAGE)
2584 static bool usb_reconnect(void)
2586 splash(HZ, "Reconnect mass storage");
2587 usb_storage_reconnect();
2588 return false;
2590 #endif
2592 #if CONFIG_USBOTG == USBOTG_ISP1583
2593 extern int dbg_usb_num_items(void);
2594 extern char* dbg_usb_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2596 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2598 (void)lists;
2599 if (action == ACTION_NONE)
2600 action = ACTION_REDRAW;
2601 return action;
2604 static bool dbg_isp1583(void)
2606 struct simplelist_info isp1583;
2607 isp1583.scroll_all = true;
2608 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2609 isp1583.timeout = HZ/100;
2610 isp1583.hide_selection = true;
2611 isp1583.get_name = dbg_usb_item;
2612 isp1583.action_callback = isp1583_action_callback;
2613 return simplelist_show_list(&isp1583);
2615 #endif
2617 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2618 extern int pic_dbg_num_items(void);
2619 extern char* pic_dbg_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2621 static int pic_action_callback(int action, struct gui_synclist *lists)
2623 (void)lists;
2624 if (action == ACTION_NONE)
2625 action = ACTION_REDRAW;
2626 return action;
2629 static bool dbg_pic(void)
2631 struct simplelist_info pic;
2632 pic.scroll_all = true;
2633 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2634 pic.timeout = HZ/100;
2635 pic.hide_selection = true;
2636 pic.get_name = pic_dbg_item;
2637 pic.action_callback = pic_action_callback;
2638 return simplelist_show_list(&pic);
2640 #endif
2643 /****** The menu *********/
2644 struct the_menu_item {
2645 unsigned char *desc; /* string or ID */
2646 bool (*function) (void); /* return true if USB was connected */
2648 static const struct the_menu_item menuitems[] = {
2649 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2650 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD))
2651 { "Dump ROM contents", dbg_save_roms },
2652 #endif
2653 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2654 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L
2655 { "View I/O ports", dbg_ports },
2656 #endif
2657 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2658 { "View PCF registers", dbg_pcf },
2659 #endif
2660 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2661 { "TSC2100 debug", tsc2100_debug },
2662 #endif
2663 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2664 { "CPU frequency", dbg_cpufreq },
2665 #endif
2666 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2667 { "S/PDIF analyzer", dbg_spdif },
2668 #endif
2669 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2670 { "Catch mem accesses", dbg_set_memory_guard },
2671 #endif
2672 { "View OS stacks", dbg_os },
2673 #ifdef HAVE_LCD_BITMAP
2674 #ifndef SIMULATOR
2675 { "View battery", view_battery },
2676 #endif
2677 { "Screendump", dbg_screendump },
2678 #endif
2679 #ifndef SIMULATOR
2680 { "View HW info", dbg_hw_info },
2681 #endif
2682 #ifndef SIMULATOR
2683 { "View partitions", dbg_partitions },
2684 #endif
2685 #ifndef SIMULATOR
2686 { "View disk info", dbg_disk_info },
2687 #if (CONFIG_STORAGE & STORAGE_ATA)
2688 { "Dump ATA identify info", dbg_identify_info},
2689 #endif
2690 #endif
2691 #ifdef HAVE_DIRCACHE
2692 { "View dircache info", dbg_dircache_info },
2693 #endif
2694 #ifdef HAVE_TAGCACHE
2695 { "View database info", dbg_tagcache_info },
2696 #endif
2697 #ifdef HAVE_LCD_BITMAP
2698 #if CONFIG_CODEC == SWCODEC
2699 { "View buffering thread", dbg_buffering_thread },
2700 #elif !defined(SIMULATOR)
2701 { "View audio thread", dbg_audio_thread },
2702 #endif
2703 #ifdef PM_DEBUG
2704 { "pm histogram", peak_meter_histogram},
2705 #endif /* PM_DEBUG */
2706 #endif /* HAVE_LCD_BITMAP */
2707 #ifndef SIMULATOR
2708 #if CONFIG_TUNER
2709 { "FM Radio", dbg_fm_radio },
2710 #endif
2711 #endif
2712 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2713 { "Write back EEPROM", dbg_write_eeprom },
2714 #endif
2715 #if CONFIG_USBOTG == USBOTG_ISP1583
2716 { "View ISP1583 info", dbg_isp1583 },
2717 #endif
2718 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2719 { "View PIC info", dbg_pic },
2720 #endif
2721 #ifdef ROCKBOX_HAS_LOGF
2722 {"logf", logfdisplay },
2723 {"logfdump", logfdump },
2724 #endif
2725 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2726 {"logf over usb",logf_usb_serial },
2727 #endif
2728 #if 0 && defined(HAVE_USBSTACK) && defined(USB_STORAGE)
2729 {"reconnect usb storage",usb_reconnect},
2730 #endif
2731 #ifdef CPU_BOOST_LOGGING
2732 {"cpu_boost log",cpu_boost_log},
2733 #endif
2734 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2735 {"Debug scrollwheel", dbg_scrollwheel},
2736 #endif
2738 static int menu_action_callback(int btn, struct gui_synclist *lists)
2740 if (btn == ACTION_STD_OK)
2742 bool oldbars = viewportmanager_set_statusbar(false);
2743 menuitems[gui_synclist_get_sel_pos(lists)].function();
2744 btn = ACTION_REDRAW;
2745 viewportmanager_set_statusbar(oldbars);
2747 return btn;
2749 static char* dbg_menu_getname(int item, void * data,
2750 char *buffer, size_t buffer_len)
2752 (void)data; (void)buffer; (void)buffer_len;
2753 return menuitems[item].desc;
2755 bool debug_menu(void)
2757 struct simplelist_info info;
2759 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2760 info.action_callback = menu_action_callback;
2761 info.get_name = dbg_menu_getname;
2762 return simplelist_show_list(&info);