Onda VX747: make backlight setting range from 1->16 instead of 0->15
[kugel-rb.git] / apps / debug_menu.c
blobbb6dd1033a16020be02935e7abe7751d1adf7434
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Heikki Hannikainen
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <stdbool.h>
26 #include <string.h>
27 #include "lcd.h"
28 #include "menu.h"
29 #include "debug_menu.h"
30 #include "kernel.h"
31 #include "sprintf.h"
32 #include "structec.h"
33 #include "action.h"
34 #include "debug.h"
35 #include "thread.h"
36 #include "powermgmt.h"
37 #include "system.h"
38 #include "font.h"
39 #include "audio.h"
40 #include "mp3_playback.h"
41 #include "settings.h"
42 #include "list.h"
43 #include "statusbar.h"
44 #include "dir.h"
45 #include "panic.h"
46 #include "screens.h"
47 #include "misc.h"
48 #include "splash.h"
49 #include "dircache.h"
50 #include "viewport.h"
51 #ifdef HAVE_TAGCACHE
52 #include "tagcache.h"
53 #endif
54 #include "lcd-remote.h"
55 #include "crc32.h"
56 #include "logf.h"
57 #ifndef SIMULATOR
58 #include "disk.h"
59 #include "adc.h"
60 #include "power.h"
61 #include "usb.h"
62 #include "rtc.h"
63 #include "storage.h"
64 #include "fat.h"
65 #include "mas.h"
66 #include "eeprom_24cxx.h"
67 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
68 #include "hotswap.h"
69 #endif
70 #if (CONFIG_STORAGE & STORAGE_ATA)
71 #include "ata.h"
72 #endif
73 #if CONFIG_TUNER
74 #include "tuner.h"
75 #include "radio.h"
76 #endif
77 #endif
79 #ifdef HAVE_LCD_BITMAP
80 #include "scrollbar.h"
81 #include "peakmeter.h"
82 #endif
83 #include "logfdisp.h"
84 #if CONFIG_CODEC == SWCODEC
85 #include "pcmbuf.h"
86 #include "buffering.h"
87 #include "playback.h"
88 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
89 #include "spdif.h"
90 #endif
91 #endif
92 #ifdef IRIVER_H300_SERIES
93 #include "pcf50606.h" /* for pcf50606_read */
94 #endif
95 #ifdef IAUDIO_X5
96 #include "ds2411.h"
97 #endif
98 #include "hwcompat.h"
99 #include "button.h"
100 #if CONFIG_RTC == RTC_PCF50605
101 #include "pcf50605.h"
102 #endif
104 #if CONFIG_CPU == DM320 || CONFIG_CPU == S3C2440 || CONFIG_CPU == TCC7801 \
105 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 || CONFIG_CPU == JZ4732
106 #include "debug-target.h"
107 #endif
109 #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) \
110 || defined(SANSA_CLIP) || defined(SANSA_FUZE)
111 #include "ascodec.h"
112 #include "as3514.h"
113 #endif
115 #ifdef HAVE_USBSTACK
116 #include "usb_core.h"
117 #ifdef USB_ENABLE_HID
118 #include "usbstack/usb_hid.h"
119 #endif
120 #endif
122 /*---------------------------------------------------*/
123 /* SPECIAL DEBUG STUFF */
124 /*---------------------------------------------------*/
125 extern struct thread_entry threads[MAXTHREADS];
127 static char thread_status_char(unsigned status)
129 static const char thread_status_chars[THREAD_NUM_STATES+1] =
131 [0 ... THREAD_NUM_STATES] = '?',
132 [STATE_RUNNING] = 'R',
133 [STATE_BLOCKED] = 'B',
134 [STATE_SLEEPING] = 'S',
135 [STATE_BLOCKED_W_TMO] = 'T',
136 [STATE_FROZEN] = 'F',
137 [STATE_KILLED] = 'K',
140 if (status > THREAD_NUM_STATES)
141 status = THREAD_NUM_STATES;
143 return thread_status_chars[status];
146 static char* threads_getname(int selected_item, void *data,
147 char *buffer, size_t buffer_len)
149 (void)data;
150 struct thread_entry *thread;
151 char name[32];
153 #if NUM_CORES > 1
154 if (selected_item < (int)NUM_CORES)
156 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
157 idle_stack_usage(selected_item));
158 return buffer;
161 selected_item -= NUM_CORES;
162 #endif
164 thread = &threads[selected_item];
166 if (thread->state == STATE_KILLED)
168 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
169 return buffer;
172 thread_get_name(name, 32, thread);
174 snprintf(buffer, buffer_len,
175 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
176 selected_item,
177 IF_COP(thread->core,)
178 #ifdef HAVE_SCHEDULER_BOOSTCTRL
179 (thread->cpu_boost) ? '+' :
180 #endif
181 ((thread->state == STATE_RUNNING) ? '*' : ' '),
182 thread_status_char(thread->state),
183 IF_PRIO(thread->base_priority, thread->priority, )
184 thread_stack_usage(thread), name);
186 return buffer;
188 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
190 (void)lists;
191 #ifdef ROCKBOX_HAS_LOGF
192 if (action == ACTION_STD_OK)
194 int selpos = gui_synclist_get_sel_pos(lists);
195 #if NUM_CORES > 1
196 if (selpos >= NUM_CORES)
197 remove_thread(threads[selpos - NUM_CORES].id);
198 #else
199 remove_thread(&threads[selpos]);
200 #endif
201 return ACTION_REDRAW;
203 #endif /* ROCKBOX_HAS_LOGF */
204 if (action == ACTION_NONE)
205 action = ACTION_REDRAW;
206 return action;
208 /* Test code!!! */
209 static bool dbg_os(void)
211 struct simplelist_info info;
212 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
213 #if NUM_CORES == 1
214 MAXTHREADS,
215 #else
216 MAXTHREADS+NUM_CORES,
217 #endif
218 NULL);
219 #ifndef ROCKBOX_HAS_LOGF
220 info.hide_selection = true;
221 info.scroll_all = true;
222 #endif
223 info.action_callback = dbg_threads_action_callback;
224 info.get_name = threads_getname;
225 return simplelist_show_list(&info);
228 #ifdef HAVE_LCD_BITMAP
229 #if CONFIG_CODEC != SWCODEC
230 #ifndef SIMULATOR
231 static bool dbg_audio_thread(void)
233 char buf[32];
234 struct audio_debug d;
236 lcd_setfont(FONT_SYSFIXED);
238 while(1)
240 if (action_userabort(HZ/5))
241 return false;
243 audio_get_debugdata(&d);
245 lcd_clear_display();
247 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
248 lcd_puts(0, 0, buf);
249 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
250 lcd_puts(0, 1, buf);
251 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
252 lcd_puts(0, 2, buf);
253 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
254 lcd_puts(0, 3, buf);
255 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
256 lcd_puts(0, 4, buf);
257 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
258 lcd_puts(0, 5, buf);
260 /* Playable space left */
261 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
262 d.playable_space, HORIZONTAL);
264 /* Show the watermark limit */
265 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
266 d.low_watermark_level, HORIZONTAL);
268 snprintf(buf, sizeof(buf), "wm: %x - %x",
269 d.low_watermark_level, d.lowest_watermark_level);
270 lcd_puts(0, 7, buf);
272 lcd_update();
274 lcd_setfont(FONT_UI);
275 return false;
277 #endif /* !SIMULATOR */
278 #else /* CONFIG_CODEC == SWCODEC */
279 extern size_t filebuflen;
280 /* This is a size_t, but call it a long so it puts a - when it's bad. */
282 static unsigned int ticks, boost_ticks, freq_sum;
284 static void dbg_audio_task(void)
286 #ifndef SIMULATOR
287 if(FREQ > CPUFREQ_NORMAL)
288 boost_ticks++;
289 freq_sum += FREQ/1000000; /* in MHz */
290 #endif
291 ticks++;
294 static bool dbg_buffering_thread(void)
296 char buf[32];
297 int button;
298 int line;
299 bool done = false;
300 size_t bufused;
301 size_t bufsize = pcmbuf_get_bufsize();
302 int pcmbufdescs = pcmbuf_descs();
303 struct buffering_debug d;
305 ticks = boost_ticks = freq_sum = 0;
307 tick_add_task(dbg_audio_task);
309 lcd_setfont(FONT_SYSFIXED);
310 while(!done)
312 button = get_action(CONTEXT_STD,HZ/5);
313 switch(button)
315 case ACTION_STD_NEXT:
316 audio_next();
317 break;
318 case ACTION_STD_PREV:
319 audio_prev();
320 break;
321 case ACTION_STD_CANCEL:
322 done = true;
323 break;
326 buffering_get_debugdata(&d);
328 line = 0;
329 lcd_clear_display();
331 bufused = bufsize - pcmbuf_free();
333 snprintf(buf, sizeof(buf), "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
334 lcd_puts(0, line++, buf);
336 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
337 bufsize, 0, bufused, HORIZONTAL);
338 line++;
340 snprintf(buf, sizeof(buf), "alloc: %6ld/%ld", audio_filebufused(),
341 (long) filebuflen);
342 lcd_puts(0, line++, buf);
344 #if LCD_HEIGHT > 80
345 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
346 filebuflen, 0, audio_filebufused(), HORIZONTAL);
347 line++;
349 snprintf(buf, sizeof(buf), "real: %6ld/%ld", (long)d.buffered_data,
350 (long)filebuflen);
351 lcd_puts(0, line++, buf);
353 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
354 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
355 line++;
356 #endif
358 snprintf(buf, sizeof(buf), "usefl: %6ld/%ld", (long)(d.useful_data),
359 (long)filebuflen);
360 lcd_puts(0, line++, buf);
362 #if LCD_HEIGHT > 80
363 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
364 filebuflen, 0, d.useful_data, HORIZONTAL);
365 line++;
366 #endif
368 snprintf(buf, sizeof(buf), "data_rem: %ld", (long)d.data_rem);
369 lcd_puts(0, line++, buf);
371 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
372 lcd_puts(0, line++, buf);
374 snprintf(buf, sizeof(buf), "handle count: %d", (int)d.num_handles);
375 lcd_puts(0, line++, buf);
377 #ifndef SIMULATOR
378 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
379 (int)((FREQ + 500000) / 1000000));
380 lcd_puts(0, line++, buf);
381 #endif
383 if (ticks > 0)
385 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
386 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
387 snprintf(buf, sizeof(buf), "boost:%3d.%d%% (%d.%dMHz)",
388 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
389 lcd_puts(0, line++, buf);
392 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
393 pcmbuf_used_descs(), pcmbufdescs);
394 lcd_puts(0, line++, buf);
395 snprintf(buf, sizeof(buf), "watermark: %6d",
396 (int)(d.watermark));
397 lcd_puts(0, line++, buf);
399 lcd_update();
402 tick_remove_task(dbg_audio_task);
403 lcd_setfont(FONT_UI);
405 return false;
407 #endif /* CONFIG_CODEC */
408 #endif /* HAVE_LCD_BITMAP */
411 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
412 /* Tool function to read the flash manufacturer and type, if available.
413 Only chips which could be reprogrammed in system will return values.
414 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
415 /* In IRAM to avoid problems when running directly from Flash */
416 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
417 unsigned addr1, unsigned addr2)
418 ICODE_ATTR __attribute__((noinline));
419 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
420 unsigned addr1, unsigned addr2)
423 unsigned not_manu, not_id; /* read values before switching to ID mode */
424 unsigned manu, id; /* read values when in ID mode */
426 #if CONFIG_CPU == SH7034
427 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
428 #elif defined(CPU_COLDFIRE)
429 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
430 #endif
431 int old_level; /* saved interrupt level */
433 not_manu = flash[0]; /* read the normal content */
434 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
436 /* disable interrupts, prevent any stray flash access */
437 old_level = disable_irq_save();
439 flash[addr1] = 0xAA; /* enter command mode */
440 flash[addr2] = 0x55;
441 flash[addr1] = 0x90; /* ID command */
442 /* Atmel wants 20ms pause here */
443 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
445 manu = flash[0]; /* read the IDs */
446 id = flash[1];
448 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
449 /* Atmel wants 20ms pause here */
450 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
452 restore_irq(old_level); /* enable interrupts again */
454 /* I assume success if the obtained values are different from
455 the normal flash content. This is not perfectly bulletproof, they
456 could theoretically be the same by chance, causing us to fail. */
457 if (not_manu != manu || not_id != id) /* a value has changed */
459 *p_manufacturer = manu; /* return the results */
460 *p_device = id;
461 return true; /* success */
463 return false; /* fail */
465 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
467 #ifndef SIMULATOR
468 #ifdef CPU_PP
469 static int perfcheck(void)
471 int result;
473 asm (
474 "mrs r2, CPSR \n"
475 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
476 "msr CPSR_c, r0 \n"
477 "mov %[res], #0 \n"
478 "ldr r0, [%[timr]] \n"
479 "add r0, r0, %[tmo] \n"
480 "1: \n"
481 "add %[res], %[res], #1 \n"
482 "ldr r1, [%[timr]] \n"
483 "cmp r1, r0 \n"
484 "bmi 1b \n"
485 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
487 [res]"=&r"(result)
489 [timr]"r"(&USEC_TIMER),
490 [tmo]"r"(
491 #if CONFIG_CPU == PP5002
492 16000
493 #else /* PP5020/5022/5024 */
494 10226
495 #endif
498 "r0", "r1", "r2"
500 return result;
502 #endif
504 #ifdef HAVE_LCD_BITMAP
505 static bool dbg_hw_info(void)
507 #if CONFIG_CPU == SH7034
508 char buf[32];
509 int bitmask = HW_MASK;
510 int rom_version = ROM_VERSION;
511 unsigned manu, id; /* flash IDs */
512 bool got_id; /* flag if we managed to get the flash IDs */
513 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
514 bool has_bootrom; /* flag for boot ROM present */
515 int oldmode; /* saved memory guard mode */
517 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
519 /* get flash ROM type */
520 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
521 if (!got_id)
522 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
524 /* check if the boot ROM area is a flash mirror */
525 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
526 if (has_bootrom) /* if ROM and Flash different */
528 /* calculate CRC16 checksum of boot ROM */
529 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
532 system_memory_guard(oldmode); /* re-enable memory guard */
534 lcd_setfont(FONT_SYSFIXED);
535 lcd_clear_display();
537 lcd_puts(0, 0, "[Hardware info]");
539 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
540 lcd_puts(0, 1, buf);
542 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
543 lcd_puts(0, 2, buf);
545 if (got_id)
546 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
547 else
548 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
549 lcd_puts(0, 3, buf);
551 if (has_bootrom)
553 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
554 snprintf(buf, 32, "Boot ROM: V1");
555 else
556 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
558 else
560 snprintf(buf, 32, "Boot ROM: none");
562 lcd_puts(0, 4, buf);
564 lcd_update();
566 while (!(action_userabort(TIMEOUT_BLOCK)));
568 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
569 char buf[32];
570 unsigned manu, id; /* flash IDs */
571 int got_id; /* flag if we managed to get the flash IDs */
572 int oldmode; /* saved memory guard mode */
573 int line = 0;
575 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
577 /* get flash ROM type */
578 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
579 if (!got_id)
580 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
582 system_memory_guard(oldmode); /* re-enable memory guard */
584 lcd_setfont(FONT_SYSFIXED);
585 lcd_clear_display();
587 lcd_puts(0, line++, "[Hardware info]");
589 if (got_id)
590 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
591 else
592 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
593 lcd_puts(0, line++, buf);
595 #ifdef IAUDIO_X5
597 struct ds2411_id id;
599 lcd_puts(0, ++line, "Serial Number:");
601 got_id = ds2411_read_id(&id);
603 if (got_id == DS2411_OK)
605 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
606 lcd_puts(0, ++line, buf);
607 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
608 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
609 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
610 lcd_puts(0, ++line, buf);
611 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
613 else
615 snprintf(buf, 32, "READ ERR=%d", got_id);
618 lcd_puts(0, ++line, buf);
620 #endif
622 lcd_update();
624 while (!(action_userabort(TIMEOUT_BLOCK)));
626 #elif defined(CPU_PP502x)
627 int line = 0;
628 char buf[32];
629 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
630 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
631 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
632 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
634 lcd_setfont(FONT_SYSFIXED);
635 lcd_clear_display();
637 lcd_puts(0, line++, "[Hardware info]");
639 #ifdef IPOD_ARCH
640 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
641 lcd_puts(0, line++, buf);
642 #endif
644 #ifdef IPOD_COLOR
645 extern int lcd_type; /* Defined in lcd-colornano.c */
647 snprintf(buf, sizeof(buf), "LCD type: %d", lcd_type);
648 lcd_puts(0, line++, buf);
649 #endif
651 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
652 lcd_puts(0, line++, buf);
654 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
655 lcd_puts(0, line++, buf);
657 lcd_update();
659 while (!(action_userabort(TIMEOUT_BLOCK)));
661 #elif CONFIG_CPU == PP5002
662 int line = 0;
663 char buf[32];
664 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
665 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
666 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
667 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
670 lcd_setfont(FONT_SYSFIXED);
671 lcd_clear_display();
673 lcd_puts(0, line++, "[Hardware info]");
675 #ifdef IPOD_ARCH
676 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
677 lcd_puts(0, line++, buf);
678 #endif
680 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
681 lcd_puts(0, line++, buf);
683 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
684 lcd_puts(0, line++, buf);
686 lcd_update();
688 while (!(action_userabort(TIMEOUT_BLOCK)));
690 #else
691 /* Define this function in your target tree */
692 return __dbg_hw_info();
693 #endif /* CONFIG_CPU */
694 lcd_setfont(FONT_UI);
695 return false;
697 #else /* !HAVE_LCD_BITMAP */
698 static bool dbg_hw_info(void)
700 char buf[32];
701 int button;
702 int currval = 0;
703 int rom_version = ROM_VERSION;
704 unsigned manu, id; /* flash IDs */
705 bool got_id; /* flag if we managed to get the flash IDs */
706 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
707 bool has_bootrom; /* flag for boot ROM present */
708 int oldmode; /* saved memory guard mode */
710 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
712 /* get flash ROM type */
713 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
714 if (!got_id)
715 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
717 /* check if the boot ROM area is a flash mirror */
718 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
719 if (has_bootrom) /* if ROM and Flash different */
721 /* calculate CRC16 checksum of boot ROM */
722 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
725 system_memory_guard(oldmode); /* re-enable memory guard */
727 lcd_clear_display();
729 lcd_puts(0, 0, "[HW Info]");
730 while(1)
732 switch(currval)
734 case 0:
735 snprintf(buf, 32, "ROM: %d.%02d",
736 rom_version/100, rom_version%100);
737 break;
738 case 1:
739 if (got_id)
740 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
741 else
742 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
743 break;
744 case 2:
745 if (has_bootrom)
747 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
748 snprintf(buf, 32, "BootROM: V1");
749 else if (rom_crc == 0x358099E8)
750 snprintf(buf, 32, "BootROM: V2");
751 /* alternative boot ROM found in one single player so far */
752 else
753 snprintf(buf, 32, "R: %08x", rom_crc);
755 else
756 snprintf(buf, 32, "BootROM: no");
759 lcd_puts(0, 1, buf);
760 lcd_update();
762 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
764 switch(button)
766 case ACTION_STD_CANCEL:
767 return false;
769 case ACTION_SETTINGS_DEC:
770 currval--;
771 if(currval < 0)
772 currval = 2;
773 break;
775 case ACTION_SETTINGS_INC:
776 currval++;
777 if(currval > 2)
778 currval = 0;
779 break;
782 return false;
784 #endif /* !HAVE_LCD_BITMAP */
785 #endif /* !SIMULATOR */
787 #ifndef SIMULATOR
788 static char* dbg_partitions_getname(int selected_item, void *data,
789 char *buffer, size_t buffer_len)
791 (void)data;
792 int partition = selected_item/2;
793 struct partinfo* p = disk_partinfo(partition);
794 if (selected_item%2)
796 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / 2048);
798 else
800 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
802 return buffer;
805 bool dbg_partitions(void)
807 struct simplelist_info info;
808 simplelist_info_init(&info, "Partition Info", 4, NULL);
809 info.selection_size = 2;
810 info.hide_selection = true;
811 info.scroll_all = true;
812 info.get_name = dbg_partitions_getname;
813 return simplelist_show_list(&info);
815 #endif
817 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
818 static bool dbg_spdif(void)
820 char buf[128];
821 int line;
822 unsigned int control;
823 int x;
824 char *s;
825 int category;
826 int generation;
827 unsigned int interruptstat;
828 bool valnogood, symbolerr, parityerr;
829 bool done = false;
830 bool spdif_src_on;
831 int spdif_source = spdif_get_output_source(&spdif_src_on);
832 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
834 lcd_clear_display();
835 lcd_setfont(FONT_SYSFIXED);
837 #ifdef HAVE_SPDIF_POWER
838 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
839 #endif
841 while (!done)
843 line = 0;
845 control = EBU1RCVCCHANNEL1;
846 interruptstat = INTERRUPTSTAT;
847 INTERRUPTCLEAR = 0x03c00000;
849 valnogood = (interruptstat & 0x01000000)?true:false;
850 symbolerr = (interruptstat & 0x00800000)?true:false;
851 parityerr = (interruptstat & 0x00400000)?true:false;
853 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
854 valnogood?"--":"OK",
855 symbolerr?"--":"OK",
856 parityerr?"--":"OK");
857 lcd_puts(0, line++, buf);
859 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
860 lcd_puts(0, line++, buf);
862 line++;
864 x = control >> 31;
865 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
866 x, x?"Professional":"Consumer");
867 lcd_puts(0, line++, buf);
869 x = (control >> 30) & 1;
870 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
871 x, x?"Non-PCM":"PCM");
872 lcd_puts(0, line++, buf);
874 x = (control >> 29) & 1;
875 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
876 x, x?"Permitted":"Inhibited");
877 lcd_puts(0, line++, buf);
879 x = (control >> 27) & 7;
880 switch(x)
882 case 0:
883 s = "None";
884 break;
885 case 1:
886 s = "50/15us";
887 break;
888 default:
889 s = "Reserved";
890 break;
892 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
893 lcd_puts(0, line++, buf);
895 x = (control >> 24) & 3;
896 snprintf(buf, sizeof(buf), "Mode: %d", x);
897 lcd_puts(0, line++, buf);
899 category = (control >> 17) & 127;
900 switch(category)
902 case 0x00:
903 s = "General";
904 break;
905 case 0x40:
906 s = "Audio CD";
907 break;
908 default:
909 s = "Unknown";
911 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
912 lcd_puts(0, line++, buf);
914 x = (control >> 16) & 1;
915 generation = x;
916 if(((category & 0x70) == 0x10) ||
917 ((category & 0x70) == 0x40) ||
918 ((category & 0x78) == 0x38))
920 generation = !generation;
922 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
923 x, generation?"Original":"No ind.");
924 lcd_puts(0, line++, buf);
926 x = (control >> 12) & 15;
927 snprintf(buf, sizeof(buf), "Source: %d", x);
928 lcd_puts(0, line++, buf);
930 x = (control >> 8) & 15;
931 switch(x)
933 case 0:
934 s = "Unspecified";
935 break;
936 case 8:
937 s = "A (Left)";
938 break;
939 case 4:
940 s = "B (Right)";
941 break;
942 default:
943 s = "";
944 break;
946 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
947 lcd_puts(0, line++, buf);
949 x = (control >> 4) & 15;
950 switch(x)
952 case 0:
953 s = "44.1kHz";
954 break;
955 case 0x4:
956 s = "48kHz";
957 break;
958 case 0xc:
959 s = "32kHz";
960 break;
962 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
963 lcd_puts(0, line++, buf);
965 x = (control >> 2) & 3;
966 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
967 lcd_puts(0, line++, buf);
968 line++;
970 #ifndef SIMULATOR
971 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
972 spdif_measure_frequency());
973 lcd_puts(0, line++, buf);
974 #endif
976 lcd_update();
978 if (action_userabort(HZ/10))
979 break;
982 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
984 #ifdef HAVE_SPDIF_POWER
985 spdif_power_enable(global_settings.spdif_enable);
986 #endif
988 lcd_setfont(FONT_UI);
989 return false;
991 #endif /* CPU_COLDFIRE */
993 #ifndef SIMULATOR
994 #ifdef HAVE_LCD_BITMAP
995 /* button definitions */
996 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
997 (CONFIG_KEYPAD == IRIVER_H300_PAD)
998 # define DEBUG_CANCEL BUTTON_OFF
1000 #elif CONFIG_KEYPAD == RECORDER_PAD
1001 # define DEBUG_CANCEL BUTTON_OFF
1003 #elif CONFIG_KEYPAD == ONDIO_PAD
1004 # define DEBUG_CANCEL BUTTON_MENU
1006 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
1007 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
1008 (CONFIG_KEYPAD == IPOD_4G_PAD)
1009 # define DEBUG_CANCEL BUTTON_MENU
1011 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
1012 # define DEBUG_CANCEL BUTTON_PLAY
1014 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
1015 # define DEBUG_CANCEL BUTTON_REC
1017 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1018 # define DEBUG_CANCEL BUTTON_RC_REC
1020 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
1021 # define DEBUG_CANCEL BUTTON_REW
1023 #elif (CONFIG_KEYPAD == MROBE100_PAD)
1024 # define DEBUG_CANCEL BUTTON_MENU
1026 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
1027 (CONFIG_KEYPAD == SANSA_C200_PAD)
1028 # define DEBUG_CANCEL BUTTON_LEFT
1030 /* This is temporary until the SA9200 touchpad works */
1031 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) || \
1032 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD)
1033 # define DEBUG_CANCEL BUTTON_POWER
1035 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
1036 # define DEBUG_CANCEL BUTTON_PLAY
1038 #endif /* key definitions */
1040 /* Test code!!! */
1041 bool dbg_ports(void)
1043 #if CONFIG_CPU == SH7034
1044 char buf[32];
1045 int adc_battery_voltage, adc_battery_level;
1047 lcd_setfont(FONT_SYSFIXED);
1048 lcd_clear_display();
1050 while(1)
1052 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1053 lcd_puts(0, 0, buf);
1054 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1055 lcd_puts(0, 1, buf);
1057 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1058 lcd_puts(0, 2, buf);
1059 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1060 lcd_puts(0, 3, buf);
1061 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1062 lcd_puts(0, 4, buf);
1063 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1064 lcd_puts(0, 5, buf);
1066 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1067 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1068 adc_battery_voltage % 1000, adc_battery_level);
1069 lcd_puts(0, 6, buf);
1071 lcd_update();
1072 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1074 lcd_setfont(FONT_UI);
1075 return false;
1078 #elif defined(CPU_COLDFIRE)
1079 unsigned int gpio_out;
1080 unsigned int gpio1_out;
1081 unsigned int gpio_read;
1082 unsigned int gpio1_read;
1083 unsigned int gpio_function;
1084 unsigned int gpio1_function;
1085 unsigned int gpio_enable;
1086 unsigned int gpio1_enable;
1087 int adc_buttons, adc_remote;
1088 int adc_battery_voltage, adc_battery_level;
1089 char buf[128];
1090 int line;
1092 lcd_clear_display();
1093 lcd_setfont(FONT_SYSFIXED);
1095 while(1)
1097 line = 0;
1098 gpio_read = GPIO_READ;
1099 gpio1_read = GPIO1_READ;
1100 gpio_out = GPIO_OUT;
1101 gpio1_out = GPIO1_OUT;
1102 gpio_function = GPIO_FUNCTION;
1103 gpio1_function = GPIO1_FUNCTION;
1104 gpio_enable = GPIO_ENABLE;
1105 gpio1_enable = GPIO1_ENABLE;
1107 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1108 lcd_puts(0, line++, buf);
1109 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1110 lcd_puts(0, line++, buf);
1111 snprintf(buf, sizeof(buf), "GPIO_FUNC: %08x", gpio_function);
1112 lcd_puts(0, line++, buf);
1113 snprintf(buf, sizeof(buf), "GPIO_ENA: %08x", gpio_enable);
1114 lcd_puts(0, line++, buf);
1116 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1117 lcd_puts(0, line++, buf);
1118 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1119 lcd_puts(0, line++, buf);
1120 snprintf(buf, sizeof(buf), "GPIO1_FUNC: %08x", gpio1_function);
1121 lcd_puts(0, line++, buf);
1122 snprintf(buf, sizeof(buf), "GPIO1_ENA: %08x", gpio1_enable);
1123 lcd_puts(0, line++, buf);
1125 adc_buttons = adc_read(ADC_BUTTONS);
1126 adc_remote = adc_read(ADC_REMOTE);
1127 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1128 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1129 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1130 button_scan_enabled() ? '+' : '-', adc_buttons);
1131 #else
1132 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1133 #endif
1134 lcd_puts(0, line++, buf);
1135 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1136 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1137 remote_detect() ? '+' : '-', adc_remote);
1138 #else
1139 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1140 #endif
1141 lcd_puts(0, line++, buf);
1142 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1143 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1144 adc_read(ADC_REMOTEDETECT));
1145 lcd_puts(0, line++, buf);
1146 #endif
1148 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1149 adc_battery_voltage % 1000, adc_battery_level);
1150 lcd_puts(0, line++, buf);
1152 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1153 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1154 lcd_puts(0, line++, buf);
1155 #endif
1157 lcd_update();
1158 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1160 lcd_setfont(FONT_UI);
1161 return false;
1165 #elif defined(CPU_PP502x)
1167 char buf[128];
1168 int line;
1170 lcd_clear_display();
1171 lcd_setfont(FONT_SYSFIXED);
1173 while(1)
1175 line = 0;
1176 lcd_puts(0, line++, "GPIO STATES:");
1177 snprintf(buf, sizeof(buf), "A: %02x E: %02x I: %02x",
1178 (unsigned int)GPIOA_INPUT_VAL,
1179 (unsigned int)GPIOE_INPUT_VAL,
1180 (unsigned int)GPIOI_INPUT_VAL);
1181 lcd_puts(0, line++, buf);
1182 snprintf(buf, sizeof(buf), "B: %02x F: %02x J: %02x",
1183 (unsigned int)GPIOB_INPUT_VAL,
1184 (unsigned int)GPIOF_INPUT_VAL,
1185 (unsigned int)GPIOJ_INPUT_VAL);
1186 lcd_puts(0, line++, buf);
1187 snprintf(buf, sizeof(buf), "C: %02x G: %02x K: %02x",
1188 (unsigned int)GPIOC_INPUT_VAL,
1189 (unsigned int)GPIOG_INPUT_VAL,
1190 (unsigned int)GPIOK_INPUT_VAL);
1191 lcd_puts(0, line++, buf);
1192 snprintf(buf, sizeof(buf), "D: %02x H: %02x L: %02x",
1193 (unsigned int)GPIOD_INPUT_VAL,
1194 (unsigned int)GPIOH_INPUT_VAL,
1195 (unsigned int)GPIOL_INPUT_VAL);
1196 lcd_puts(0, line++, buf);
1197 line++;
1198 snprintf(buf, sizeof(buf), "GPO32_VAL: %08lx", GPO32_VAL);
1199 lcd_puts(0, line++, buf);
1200 snprintf(buf, sizeof(buf), "GPO32_EN: %08lx", GPO32_ENABLE);
1201 lcd_puts(0, line++, buf);
1202 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1203 lcd_puts(0, line++, buf);
1204 snprintf(buf, sizeof(buf), "DEV_EN2: %08lx", DEV_EN2);
1205 lcd_puts(0, line++, buf);
1206 snprintf(buf, sizeof(buf), "DEV_EN3: %08lx", inl(0x60006044));
1207 lcd_puts(0, line++, buf); /* to be verified */
1208 snprintf(buf, sizeof(buf), "DEV_INIT1: %08lx", DEV_INIT1);
1209 lcd_puts(0, line++, buf);
1210 snprintf(buf, sizeof(buf), "DEV_INIT2: %08lx", DEV_INIT2);
1211 lcd_puts(0, line++, buf);
1212 #ifdef ADC_ACCESSORY
1213 snprintf(buf, sizeof(buf), "ACCESSORY: %d", adc_read(ADC_ACCESSORY));
1214 lcd_puts(0, line++, buf);
1215 #endif
1217 #if defined(IPOD_ACCESSORY_PROTOCOL)
1218 extern unsigned char serbuf[];
1219 snprintf(buf, sizeof(buf), "IAP PACKET: %02x %02x %02x %02x %02x %02x %02x %02x",
1220 serbuf[0], serbuf[1], serbuf[2], serbuf[3], serbuf[4], serbuf[5],
1221 serbuf[6], serbuf[7]);
1222 lcd_puts(0, line++, buf);
1223 #endif
1225 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1226 line++;
1227 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1228 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1229 lcd_puts(0, line++, buf);
1230 snprintf(buf, sizeof(buf), "REM: %03x PAD: %03x",
1231 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1232 lcd_puts(0, line++, buf);
1233 #elif defined(PHILIPS_HDD1630)
1234 line++;
1235 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1236 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1237 lcd_puts(0, line++, buf);
1238 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1239 snprintf(buf, sizeof(buf), "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1240 lcd_puts(0, line++, buf);
1241 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1242 lcd_puts(0, line++, buf);
1243 snprintf(buf, sizeof(buf), "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1244 lcd_puts(0, line++, buf);
1245 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1246 lcd_puts(0, line++, buf);
1247 snprintf(buf, sizeof(buf), "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1248 lcd_puts(0, line++, buf);
1249 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1250 lcd_puts(0, line++, buf);
1251 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1252 lcd_puts(0, line++, buf);
1253 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1254 lcd_puts(0, line++, buf);
1255 snprintf(buf, sizeof(buf), "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1256 lcd_puts(0, line++, buf);
1257 snprintf(buf, sizeof(buf), "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1258 lcd_puts(0, line++, buf);
1259 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1260 lcd_puts(0, line++, buf);
1261 #if !defined(PHILIPS_SA9200)
1262 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1263 lcd_puts(0, line++, buf);
1264 snprintf(buf, sizeof(buf), "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1265 lcd_puts(0, line++, buf);
1266 #endif
1267 #endif
1268 lcd_update();
1269 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1271 lcd_setfont(FONT_UI);
1272 return false;
1276 #elif CONFIG_CPU == PP5002
1277 char buf[128];
1278 int line;
1280 lcd_clear_display();
1281 lcd_setfont(FONT_SYSFIXED);
1283 while(1)
1285 line = 0;
1286 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x",
1287 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1288 lcd_puts(0, line++, buf);
1289 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x",
1290 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1291 lcd_puts(0, line++, buf);
1293 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1294 lcd_puts(0, line++, buf);
1295 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1296 lcd_puts(0, line++, buf);
1297 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1298 lcd_puts(0, line++, buf);
1299 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1300 lcd_puts(0, line++, buf);
1301 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1302 lcd_puts(0, line++, buf);
1303 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1304 lcd_puts(0, line++, buf);
1305 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1306 lcd_puts(0, line++, buf);
1307 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1308 lcd_puts(0, line++, buf);
1310 lcd_update();
1311 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1313 lcd_setfont(FONT_UI);
1314 return false;
1317 lcd_setfont(FONT_UI);
1318 #else
1319 return __dbg_ports();
1320 #endif /* CPU */
1321 return false;
1323 #else /* !HAVE_LCD_BITMAP */
1324 bool dbg_ports(void)
1326 char buf[32];
1327 int button;
1328 int adc_battery_voltage;
1329 int currval = 0;
1331 lcd_clear_display();
1333 while(1)
1335 switch(currval)
1337 case 0:
1338 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1339 break;
1340 case 1:
1341 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1342 break;
1343 case 2:
1344 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1345 break;
1346 case 3:
1347 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1348 break;
1349 case 4:
1350 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1351 break;
1352 case 5:
1353 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1354 break;
1355 case 6:
1356 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1357 break;
1358 case 7:
1359 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1360 break;
1361 case 8:
1362 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1363 break;
1364 case 9:
1365 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1366 break;
1368 lcd_puts(0, 0, buf);
1370 battery_read_info(&adc_battery_voltage, NULL);
1371 snprintf(buf, 32, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1372 adc_battery_voltage % 1000);
1373 lcd_puts(0, 1, buf);
1374 lcd_update();
1376 button = get_action(CONTEXT_SETTINGS,HZ/5);
1378 switch(button)
1380 case ACTION_STD_CANCEL:
1381 return false;
1383 case ACTION_SETTINGS_DEC:
1384 currval--;
1385 if(currval < 0)
1386 currval = 9;
1387 break;
1389 case ACTION_SETTINGS_INC:
1390 currval++;
1391 if(currval > 9)
1392 currval = 0;
1393 break;
1396 return false;
1398 #endif /* !HAVE_LCD_BITMAP */
1399 #endif /* !SIMULATOR */
1401 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1402 static bool dbg_pcf(void)
1404 char buf[128];
1405 int line;
1407 #ifdef HAVE_LCD_BITMAP
1408 lcd_setfont(FONT_SYSFIXED);
1409 #endif
1410 lcd_clear_display();
1412 while(1)
1414 line = 0;
1416 snprintf(buf, sizeof(buf), "DCDC1: %02x", pcf50605_read(0x1b));
1417 lcd_puts(0, line++, buf);
1418 snprintf(buf, sizeof(buf), "DCDC2: %02x", pcf50605_read(0x1c));
1419 lcd_puts(0, line++, buf);
1420 snprintf(buf, sizeof(buf), "DCDC3: %02x", pcf50605_read(0x1d));
1421 lcd_puts(0, line++, buf);
1422 snprintf(buf, sizeof(buf), "DCDC4: %02x", pcf50605_read(0x1e));
1423 lcd_puts(0, line++, buf);
1424 snprintf(buf, sizeof(buf), "DCDEC1: %02x", pcf50605_read(0x1f));
1425 lcd_puts(0, line++, buf);
1426 snprintf(buf, sizeof(buf), "DCDEC2: %02x", pcf50605_read(0x20));
1427 lcd_puts(0, line++, buf);
1428 snprintf(buf, sizeof(buf), "DCUDC1: %02x", pcf50605_read(0x21));
1429 lcd_puts(0, line++, buf);
1430 snprintf(buf, sizeof(buf), "DCUDC2: %02x", pcf50605_read(0x22));
1431 lcd_puts(0, line++, buf);
1432 snprintf(buf, sizeof(buf), "IOREGC: %02x", pcf50605_read(0x23));
1433 lcd_puts(0, line++, buf);
1434 snprintf(buf, sizeof(buf), "D1REGC: %02x", pcf50605_read(0x24));
1435 lcd_puts(0, line++, buf);
1436 snprintf(buf, sizeof(buf), "D2REGC: %02x", pcf50605_read(0x25));
1437 lcd_puts(0, line++, buf);
1438 snprintf(buf, sizeof(buf), "D3REGC: %02x", pcf50605_read(0x26));
1439 lcd_puts(0, line++, buf);
1440 snprintf(buf, sizeof(buf), "LPREG1: %02x", pcf50605_read(0x27));
1441 lcd_puts(0, line++, buf);
1443 lcd_update();
1444 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1446 lcd_setfont(FONT_UI);
1447 return false;
1451 lcd_setfont(FONT_UI);
1452 return false;
1454 #endif
1456 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1457 static bool dbg_cpufreq(void)
1459 char buf[128];
1460 int line;
1461 int button;
1463 #ifdef HAVE_LCD_BITMAP
1464 lcd_setfont(FONT_SYSFIXED);
1465 #endif
1466 lcd_clear_display();
1468 while(1)
1470 line = 0;
1472 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1473 lcd_puts(0, line++, buf);
1475 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1476 lcd_puts(0, line++, buf);
1478 lcd_update();
1479 button = get_action(CONTEXT_STD,HZ/10);
1481 switch(button)
1483 case ACTION_STD_PREV:
1484 cpu_boost(true);
1485 break;
1487 case ACTION_STD_NEXT:
1488 cpu_boost(false);
1489 break;
1491 case ACTION_STD_OK:
1492 while (get_cpu_boost_counter() > 0)
1493 cpu_boost(false);
1494 set_cpu_frequency(CPUFREQ_DEFAULT);
1495 break;
1497 case ACTION_STD_CANCEL:
1498 lcd_setfont(FONT_UI);
1499 return false;
1502 lcd_setfont(FONT_UI);
1503 return false;
1505 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1507 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1508 #include "tsc2100.h"
1509 static char *itob(int n, int len)
1511 static char binary[64];
1512 int i,j;
1513 for (i=1, j=0;i<=len;i++)
1515 binary[j++] = n&(1<<(len-i))?'1':'0';
1516 if (i%4 == 0)
1517 binary[j++] = ' ';
1519 binary[j] = '\0';
1520 return binary;
1522 static char* tsc2100_debug_getname(int selected_item, void * data,
1523 char *buffer, size_t buffer_len)
1525 int *page = (int*)data;
1526 bool reserved = false;
1527 switch (*page)
1529 case 0:
1530 if ((selected_item > 0x0a) ||
1531 (selected_item == 0x04) ||
1532 (selected_item == 0x08))
1533 reserved = true;
1534 break;
1535 case 1:
1536 if ((selected_item > 0x05) ||
1537 (selected_item == 0x02))
1538 reserved = true;
1539 break;
1540 case 2:
1541 if (selected_item > 0x1e)
1542 reserved = true;
1543 break;
1545 if (reserved)
1546 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1547 else
1548 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1549 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1550 return buffer;
1552 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1554 int *page = (int*)lists->data;
1555 if (action == ACTION_STD_OK)
1557 *page = (*page+1)%3;
1558 snprintf(lists->title, 32,
1559 "tsc2100 registers - Page %d", *page);
1560 return ACTION_REDRAW;
1562 return action;
1564 static bool tsc2100_debug(void)
1566 int page = 0;
1567 char title[32] = "tsc2100 registers - Page 0";
1568 struct simplelist_info info;
1569 simplelist_info_init(&info, title, 32, &page);
1570 info.timeout = HZ/100;
1571 info.get_name = tsc2100_debug_getname;
1572 info.action_callback= tsc2100debug_action_callback;
1573 return simplelist_show_list(&info);
1575 #endif
1576 #ifndef SIMULATOR
1577 #ifdef HAVE_LCD_BITMAP
1579 * view_battery() shows a automatically scaled graph of the battery voltage
1580 * over time. Usable for estimating battery life / charging rate.
1581 * The power_history array is updated in power_thread of powermgmt.c.
1584 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1585 #define BAT_YSPACE (LCD_HEIGHT - 20)
1587 static bool view_battery(void)
1589 int view = 0;
1590 int i, x, y;
1591 unsigned short maxv, minv;
1592 char buf[32];
1594 lcd_setfont(FONT_SYSFIXED);
1596 while(1)
1598 lcd_clear_display();
1599 switch (view) {
1600 case 0: /* voltage history graph */
1601 /* Find maximum and minimum voltage for scaling */
1602 minv = power_history[0];
1603 maxv = minv + 1;
1604 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1605 if (power_history[i] > maxv)
1606 maxv = power_history[i];
1607 if (power_history[i] < minv)
1608 minv = power_history[i];
1611 snprintf(buf, 30, "Battery %d.%03d", power_history[0] / 1000,
1612 power_history[0] % 1000);
1613 lcd_puts(0, 0, buf);
1614 snprintf(buf, 30, "scale %d.%03d-%d.%03dV",
1615 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1616 lcd_puts(0, 1, buf);
1618 x = 0;
1619 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1620 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1621 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1622 lcd_vline(x, LCD_HEIGHT-1, 20);
1623 lcd_set_drawmode(DRMODE_SOLID);
1624 lcd_vline(x, LCD_HEIGHT-1,
1625 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1626 x++;
1629 break;
1631 case 1: /* status: */
1632 lcd_puts(0, 0, "Power status:");
1634 battery_read_info(&y, NULL);
1635 snprintf(buf, 30, "Battery: %d.%03d V", y / 1000, y % 1000);
1636 lcd_puts(0, 1, buf);
1637 #ifdef ADC_EXT_POWER
1638 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1639 snprintf(buf, 30, "External: %d.%03d V", y / 1000, y % 1000);
1640 lcd_puts(0, 2, buf);
1641 #endif
1642 #if CONFIG_CHARGING
1643 #if defined ARCHOS_RECORDER
1644 snprintf(buf, 30, "Chgr: %s %s",
1645 charger_inserted() ? "present" : "absent",
1646 charger_enabled() ? "on" : "off");
1647 lcd_puts(0, 3, buf);
1648 snprintf(buf, 30, "short delta: %d", short_delta);
1649 lcd_puts(0, 5, buf);
1650 snprintf(buf, 30, "long delta: %d", long_delta);
1651 lcd_puts(0, 6, buf);
1652 lcd_puts(0, 7, power_message);
1653 snprintf(buf, 30, "USB Inserted: %s",
1654 usb_inserted() ? "yes" : "no");
1655 lcd_puts(0, 8, buf);
1656 #elif defined IRIVER_H300_SERIES
1657 snprintf(buf, 30, "USB Charging Enabled: %s",
1658 usb_charging_enabled() ? "yes" : "no");
1659 lcd_puts(0, 9, buf);
1660 #elif defined IPOD_NANO || defined IPOD_VIDEO
1661 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1662 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1663 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1664 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1665 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1667 snprintf(buf, 30, "USB pwr: %s",
1668 usb_pwr ? "present" : "absent");
1669 lcd_puts(0, 3, buf);
1670 snprintf(buf, 30, "EXT pwr: %s",
1671 ext_pwr ? "present" : "absent");
1672 lcd_puts(0, 4, buf);
1673 snprintf(buf, 30, "Battery: %s",
1674 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1675 lcd_puts(0, 5, buf);
1676 snprintf(buf, 30, "Dock mode: %s",
1677 dock ? "enabled" : "disabled");
1678 lcd_puts(0, 6, buf);
1679 snprintf(buf, 30, "Headphone: %s",
1680 headphone ? "connected" : "disconnected");
1681 lcd_puts(0, 7, buf);
1682 #elif defined TOSHIBA_GIGABEAT_S
1683 int line = 3;
1684 unsigned int st;
1686 static const unsigned char * const chrgstate_strings[] =
1688 "Disabled",
1689 "Error",
1690 "Discharging",
1691 "Precharge",
1692 "Constant Voltage",
1693 "Constant Current",
1694 "<unknown>",
1697 snprintf(buf, 30, "Charger: %s",
1698 charger_inserted() ? "present" : "absent");
1699 lcd_puts(0, line++, buf);
1701 st = power_input_status() &
1702 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1703 snprintf(buf, 30, "%s%s",
1704 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1705 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1706 lcd_puts(0, line++, buf);
1708 snprintf(buf, 30, "IUSB Max: %d", usb_allowed_current());
1709 lcd_puts(0, line++, buf);
1711 y = ARRAYLEN(chrgstate_strings) - 1;
1713 switch (charge_state)
1715 case CHARGE_STATE_DISABLED: y--;
1716 case CHARGE_STATE_ERROR: y--;
1717 case DISCHARGING: y--;
1718 case TRICKLE: y--;
1719 case TOPOFF: y--;
1720 case CHARGING: y--;
1721 default:;
1724 snprintf(buf, 30, "State: %s", chrgstate_strings[y]);
1725 lcd_puts(0, line++, buf);
1727 snprintf(buf, 30, "Battery Switch: %s",
1728 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1729 lcd_puts(0, line++, buf);
1731 y = chrgraw_adc_voltage();
1732 snprintf(buf, 30, "CHRGRAW: %d.%03d V",
1733 y / 1000, y % 1000);
1734 lcd_puts(0, line++, buf);
1736 y = application_supply_adc_voltage();
1737 snprintf(buf, 30, "BP : %d.%03d V",
1738 y / 1000, y % 1000);
1739 lcd_puts(0, line++, buf);
1741 y = battery_adc_charge_current();
1742 if (y < 0) x = '-', y = -y;
1743 else x = ' ';
1744 snprintf(buf, 30, "CHRGISN:%c%d mA", x, y);
1745 lcd_puts(0, line++, buf);
1747 y = cccv_regulator_dissipation();
1748 snprintf(buf, 30, "P CCCV : %d mW", y);
1749 lcd_puts(0, line++, buf);
1751 y = battery_charge_current();
1752 if (y < 0) x = '-', y = -y;
1753 else x = ' ';
1754 snprintf(buf, 30, "I Charge:%c%d mA", x, y);
1755 lcd_puts(0, line++, buf);
1757 y = battery_adc_temp();
1759 if (y != INT_MIN) {
1760 snprintf(buf, 30, "T Battery: %dC (%dF)", y,
1761 (9*y + 160) / 5);
1762 } else {
1763 /* Conversion disabled */
1764 snprintf(buf, 30, "T Battery: ?");
1767 lcd_puts(0, line++, buf);
1768 #elif defined(SANSA_E200) || defined(SANSA_C200) || defined(SANSA_CLIP) || defined(SANSA_FUZE)
1769 const int first = CHARGE_STATE_DISABLED;
1770 static const char * const chrgstate_strings[] =
1772 [CHARGE_STATE_DISABLED-first] = "Disabled",
1773 [CHARGE_STATE_ERROR-first] = "Error",
1774 [DISCHARGING-first] = "Discharging",
1775 [CHARGING-first] = "Charging",
1777 const char *str = NULL;
1779 snprintf(buf, 30, "Charger: %s",
1780 charger_inserted() ? "present" : "absent");
1781 lcd_puts(0, 3, buf);
1783 y = charge_state - first;
1784 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1785 str = chrgstate_strings[y];
1787 snprintf(buf, sizeof(buf), "State: %s",
1788 str ? str : "<unknown>");
1789 lcd_puts(0, 4, buf);
1791 snprintf(buf, sizeof(buf), "CHARGER: %02X",
1792 ascodec_read(AS3514_CHARGER));
1793 lcd_puts(0, 5, buf);
1794 #else
1795 snprintf(buf, 30, "Charger: %s",
1796 charger_inserted() ? "present" : "absent");
1797 lcd_puts(0, 3, buf);
1798 #endif /* target type */
1799 #endif /* CONFIG_CHARGING */
1800 break;
1802 case 2: /* voltage deltas: */
1803 lcd_puts(0, 0, "Voltage deltas:");
1805 for (i = 0; i <= 6; i++) {
1806 y = power_history[i] - power_history[i+1];
1807 snprintf(buf, 30, "-%d min: %s%d.%03d V", i,
1808 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1809 ((y < 0) ? y * -1 : y ) % 1000);
1810 lcd_puts(0, i+1, buf);
1812 break;
1814 case 3: /* remaining time estimation: */
1816 #ifdef ARCHOS_RECORDER
1817 snprintf(buf, 30, "charge_state: %d", charge_state);
1818 lcd_puts(0, 0, buf);
1820 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1821 lcd_puts(0, 1, buf);
1823 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1824 lcd_puts(0, 2, buf);
1826 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1827 lcd_puts(0, 3, buf);
1829 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1830 lcd_puts(0, 4, buf);
1831 #endif /* ARCHOS_RECORDER */
1833 snprintf(buf, 30, "Last PwrHist: %d.%03dV",
1834 power_history[0] / 1000,
1835 power_history[0] % 1000);
1836 lcd_puts(0, 5, buf);
1838 snprintf(buf, 30, "battery level: %d%%", battery_level());
1839 lcd_puts(0, 6, buf);
1841 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1842 lcd_puts(0, 7, buf);
1843 break;
1846 lcd_update();
1848 switch(get_action(CONTEXT_STD,HZ/2))
1850 case ACTION_STD_PREV:
1851 if (view)
1852 view--;
1853 break;
1855 case ACTION_STD_NEXT:
1856 if (view < 3)
1857 view++;
1858 break;
1860 case ACTION_STD_CANCEL:
1861 lcd_setfont(FONT_UI);
1862 return false;
1865 lcd_setfont(FONT_UI);
1866 return false;
1869 #endif /* HAVE_LCD_BITMAP */
1870 #endif
1872 #ifndef SIMULATOR
1873 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1875 #if (CONFIG_STORAGE & STORAGE_MMC)
1876 #define CARDTYPE "MMC"
1877 #elif (CONFIG_STORAGE & STORAGE_SD)
1878 #define CARDTYPE "microSD"
1879 #endif
1881 static int disk_callback(int btn, struct gui_synclist *lists)
1883 tCardInfo *card;
1884 int *cardnum = (int*)lists->data;
1885 unsigned char card_name[7];
1886 unsigned char pbuf[32];
1887 char *title = lists->title;
1888 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1889 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1890 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1891 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1892 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1893 "3.1-3.31", "4.0" };
1894 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1896 #ifdef HAVE_HOTSWAP
1897 if (btn == ACTION_STD_OK)
1899 *cardnum ^= 0x1; /* change cards */
1901 #endif
1903 simplelist_set_line_count(0);
1905 card = card_get_info(*cardnum);
1907 if (card->initialized > 0)
1909 card_name[6] = '\0';
1910 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1911 simplelist_addline(SIMPLELIST_ADD_LINE,
1912 "%s Rev %d.%d", card_name,
1913 (int) card_extract_bits(card->cid, 72, 4),
1914 (int) card_extract_bits(card->cid, 76, 4));
1915 simplelist_addline(SIMPLELIST_ADD_LINE,
1916 "Prod: %d/%d",
1917 (int) card_extract_bits(card->cid, 112, 4),
1918 (int) card_extract_bits(card->cid, 116, 4) + 1997);
1919 simplelist_addline(SIMPLELIST_ADD_LINE,
1920 "Ser#: 0x%08lx",
1921 card_extract_bits(card->cid, 80, 32));
1922 simplelist_addline(SIMPLELIST_ADD_LINE,
1923 "M=%02x, O=%04x",
1924 (int) card_extract_bits(card->cid, 0, 8),
1925 (int) card_extract_bits(card->cid, 8, 16));
1926 int temp = card_extract_bits(card->csd, 2, 4);
1927 simplelist_addline(SIMPLELIST_ADD_LINE,
1928 CARDTYPE " v%s", temp < 5 ?
1929 spec_vers[temp] : "?.?");
1930 simplelist_addline(SIMPLELIST_ADD_LINE,
1931 "Blocks: 0x%08lx", card->numblocks);
1932 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1933 kbit_units, false);
1934 simplelist_addline(SIMPLELIST_ADD_LINE,
1935 "Speed: %s", pbuf);
1936 output_dyn_value(pbuf, sizeof pbuf, card->tsac,
1937 nsec_units, false);
1938 simplelist_addline(SIMPLELIST_ADD_LINE,
1939 "Tsac: %s", pbuf);
1940 simplelist_addline(SIMPLELIST_ADD_LINE,
1941 "Nsac: %d clk", card->nsac);
1942 simplelist_addline(SIMPLELIST_ADD_LINE,
1943 "R2W: *%d", card->r2w_factor);
1944 simplelist_addline(SIMPLELIST_ADD_LINE,
1945 "IRmax: %d..%d mA",
1946 i_vmin[card_extract_bits(card->csd, 66, 3)],
1947 i_vmax[card_extract_bits(card->csd, 69, 3)]);
1948 simplelist_addline(SIMPLELIST_ADD_LINE,
1949 "IWmax: %d..%d mA",
1950 i_vmin[card_extract_bits(card->csd, 72, 3)],
1951 i_vmax[card_extract_bits(card->csd, 75, 3)]);
1953 else if (card->initialized == 0)
1955 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1957 #if (CONFIG_STORAGE & STORAGE_SD)
1958 else /* card->initialized < 0 */
1960 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1962 #endif
1963 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1964 gui_synclist_set_title(lists, title, Icon_NOICON);
1965 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1966 gui_synclist_select_item(lists, 0);
1967 btn = ACTION_REDRAW;
1969 return btn;
1971 #elif (CONFIG_STORAGE & STORAGE_ATA)
1972 static int disk_callback(int btn, struct gui_synclist *lists)
1974 (void)lists;
1975 int i;
1976 char buf[128];
1977 unsigned short* identify_info = ata_get_identify();
1978 bool timing_info_present = false;
1979 (void)btn;
1981 simplelist_set_line_count(0);
1983 for (i=0; i < 20; i++)
1984 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1985 buf[40]=0;
1986 /* kill trailing space */
1987 for (i=39; i && buf[i]==' '; i--)
1988 buf[i] = 0;
1989 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1990 for (i=0; i < 4; i++)
1991 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1992 buf[8]=0;
1993 simplelist_addline(SIMPLELIST_ADD_LINE,
1994 "Firmware: %s", buf);
1995 snprintf(buf, sizeof buf, "%ld MB",
1996 ((unsigned long)identify_info[61] << 16 |
1997 (unsigned long)identify_info[60]) / 2048 );
1998 simplelist_addline(SIMPLELIST_ADD_LINE,
1999 "Size: %s", buf);
2000 unsigned long free;
2001 fat_size( IF_MV2(0,) NULL, &free );
2002 simplelist_addline(SIMPLELIST_ADD_LINE,
2003 "Free: %ld MB", free / 1024);
2004 simplelist_addline(SIMPLELIST_ADD_LINE,
2005 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
2006 i = identify_info[83] & (1<<3);
2007 simplelist_addline(SIMPLELIST_ADD_LINE,
2008 "Power mgmt: %s", i ? "enabled" : "unsupported");
2009 i = identify_info[83] & (1<<9);
2010 simplelist_addline(SIMPLELIST_ADD_LINE,
2011 "Noise mgmt: %s", i ? "enabled" : "unsupported");
2012 i = identify_info[82] & (1<<6);
2013 simplelist_addline(SIMPLELIST_ADD_LINE,
2014 "Read-ahead: %s", i ? "enabled" : "unsupported");
2015 timing_info_present = identify_info[53] & (1<<1);
2016 if(timing_info_present) {
2017 char pio3[2], pio4[2];pio3[1] = 0;
2018 pio4[1] = 0;
2019 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
2020 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
2021 simplelist_addline(SIMPLELIST_ADD_LINE,
2022 "PIO modes: 0 1 2 %s %s", pio3, pio4);
2024 else {
2025 simplelist_addline(SIMPLELIST_ADD_LINE,
2026 "No PIO mode info");
2028 timing_info_present = identify_info[53] & (1<<1);
2029 if(timing_info_present) {
2030 simplelist_addline(SIMPLELIST_ADD_LINE,
2031 "Cycle times %dns/%dns",
2032 identify_info[67],
2033 identify_info[68] );
2034 } else {
2035 simplelist_addline(SIMPLELIST_ADD_LINE,
2036 "No timing info");
2038 #ifdef HAVE_ATA_DMA
2039 if (identify_info[63] & (1<<0)) {
2040 char mdma0[2], mdma1[2], mdma2[2];
2041 mdma0[1] = mdma1[1] = mdma2[1] = 0;
2042 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
2043 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
2044 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
2045 simplelist_addline(SIMPLELIST_ADD_LINE,
2046 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
2047 simplelist_addline(SIMPLELIST_ADD_LINE,
2048 "MDMA Cycle times %dns/%dns",
2049 identify_info[65],
2050 identify_info[66] );
2052 else {
2053 simplelist_addline(SIMPLELIST_ADD_LINE,
2054 "No MDMA mode info");
2056 if (identify_info[53] & (1<<2)) {
2057 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2], udma6[2];
2058 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = udma6[1] = 0;
2059 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
2060 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
2061 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
2062 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
2063 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
2064 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
2065 udma6[0] = (identify_info[88] & (1<<6)) ? '6' : 0;
2066 simplelist_addline(SIMPLELIST_ADD_LINE,
2067 "UDMA modes: %s %s %s %s %s %s %s", udma0, udma1, udma2,
2068 udma3, udma4, udma5, udma6);
2070 else {
2071 simplelist_addline(SIMPLELIST_ADD_LINE,
2072 "No UDMA mode info");
2074 #endif /* HAVE_ATA_DMA */
2075 timing_info_present = identify_info[53] & (1<<1);
2076 if(timing_info_present) {
2077 i = identify_info[49] & (1<<11);
2078 simplelist_addline(SIMPLELIST_ADD_LINE,
2079 "IORDY support: %s", i ? "yes" : "no");
2080 i = identify_info[49] & (1<<10);
2081 simplelist_addline(SIMPLELIST_ADD_LINE,
2082 "IORDY disable: %s", i ? "yes" : "no");
2083 } else {
2084 simplelist_addline(SIMPLELIST_ADD_LINE,
2085 "No timing info");
2087 simplelist_addline(SIMPLELIST_ADD_LINE,
2088 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2089 #ifdef HAVE_ATA_DMA
2090 i = ata_get_dma_mode();
2091 if (i == 0) {
2092 simplelist_addline(SIMPLELIST_ADD_LINE,
2093 "DMA not enabled");
2094 } else {
2095 simplelist_addline(SIMPLELIST_ADD_LINE,
2096 "DMA mode: %s %c",
2097 (i & 0x40) ? "UDMA" : "MDMA",
2098 '0' + (i & 7));
2100 #endif /* HAVE_ATA_DMA */
2101 return btn;
2103 #else /* No SD, MMC or ATA */
2104 static int disk_callback(int btn, struct gui_synclist *lists)
2106 (void)btn;
2107 (void)lists;
2108 struct storage_info info;
2109 storage_get_info(0,&info);
2110 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
2111 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
2112 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
2113 simplelist_addline(SIMPLELIST_ADD_LINE,
2114 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
2115 unsigned long free;
2116 fat_size( IF_MV2(0,) NULL, &free );
2117 simplelist_addline(SIMPLELIST_ADD_LINE,
2118 "Free: %ld MB", free / 1024);
2119 simplelist_addline(SIMPLELIST_ADD_LINE,
2120 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2121 return btn;
2123 #endif
2125 #if (CONFIG_STORAGE & STORAGE_ATA)
2126 static bool dbg_identify_info(void)
2128 int fd = creat("/identify_info.bin");
2129 if(fd >= 0)
2131 #ifdef ROCKBOX_LITTLE_ENDIAN
2132 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
2133 #else
2134 write(fd, ata_get_identify(), SECTOR_SIZE);
2135 #endif
2136 close(fd);
2138 return false;
2140 #endif
2142 static bool dbg_disk_info(void)
2144 struct simplelist_info info;
2145 simplelist_info_init(&info, "Disk Info", 1, NULL);
2146 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
2147 char title[16];
2148 int card = 0;
2149 info.callback_data = (void*)&card;
2150 info.title = title;
2151 #endif
2152 info.action_callback = disk_callback;
2153 info.hide_selection = true;
2154 info.scroll_all = true;
2155 return simplelist_show_list(&info);
2157 #endif /* !SIMULATOR */
2159 #ifdef HAVE_DIRCACHE
2160 static int dircache_callback(int btn, struct gui_synclist *lists)
2162 (void)btn; (void)lists;
2163 simplelist_set_line_count(0);
2164 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
2165 dircache_is_enabled() ? "Yes" : "No");
2166 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
2167 dircache_get_cache_size());
2168 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
2169 global_status.dircache_size);
2170 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
2171 DIRCACHE_LIMIT);
2172 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
2173 dircache_get_reserve_used(), DIRCACHE_RESERVE);
2174 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2175 dircache_get_build_ticks() / HZ);
2176 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2177 dircache_get_entry_count());
2178 return btn;
2181 static bool dbg_dircache_info(void)
2183 struct simplelist_info info;
2184 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2185 info.action_callback = dircache_callback;
2186 info.hide_selection = true;
2187 info.scroll_all = true;
2188 return simplelist_show_list(&info);
2191 #endif /* HAVE_DIRCACHE */
2193 #ifdef HAVE_TAGCACHE
2194 static int database_callback(int btn, struct gui_synclist *lists)
2196 (void)lists;
2197 struct tagcache_stat *stat = tagcache_get_stat();
2198 static bool synced = false;
2200 simplelist_set_line_count(0);
2202 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2203 stat->initialized ? "Yes" : "No");
2204 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2205 stat->ready ? "Yes" : "No");
2206 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2207 stat->ramcache ? "Yes" : "No");
2208 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2209 stat->ramcache_used, stat->ramcache_allocated);
2210 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2211 stat->progress, stat->processed_entries);
2212 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2213 stat->curentry ? stat->curentry : "---");
2214 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2215 stat->commit_step);
2216 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2217 stat->commit_delayed ? "Yes" : "No");
2219 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2220 stat->queue_length);
2222 if (synced)
2224 synced = false;
2225 tagcache_screensync_event();
2228 if (!btn && stat->curentry)
2230 synced = true;
2231 return ACTION_REDRAW;
2234 if (btn == ACTION_STD_CANCEL)
2235 tagcache_screensync_enable(false);
2237 return btn;
2239 static bool dbg_tagcache_info(void)
2241 struct simplelist_info info;
2242 simplelist_info_init(&info, "Database Info", 8, NULL);
2243 info.action_callback = database_callback;
2244 info.hide_selection = true;
2245 info.scroll_all = true;
2247 /* Don't do nonblock here, must give enough processing time
2248 for tagcache thread. */
2249 /* info.timeout = TIMEOUT_NOBLOCK; */
2250 info.timeout = 1;
2251 tagcache_screensync_enable(true);
2252 return simplelist_show_list(&info);
2254 #endif
2256 #if CONFIG_CPU == SH7034
2257 static bool dbg_save_roms(void)
2259 int fd;
2260 int oldmode = system_memory_guard(MEMGUARD_NONE);
2262 fd = creat("/internal_rom_0000-FFFF.bin");
2263 if(fd >= 0)
2265 write(fd, (void *)0, 0x10000);
2266 close(fd);
2269 fd = creat("/internal_rom_2000000-203FFFF.bin");
2270 if(fd >= 0)
2272 write(fd, (void *)0x2000000, 0x40000);
2273 close(fd);
2276 system_memory_guard(oldmode);
2277 return false;
2279 #elif defined CPU_COLDFIRE
2280 static bool dbg_save_roms(void)
2282 int fd;
2283 int oldmode = system_memory_guard(MEMGUARD_NONE);
2285 #if defined(IRIVER_H100_SERIES)
2286 fd = creat("/internal_rom_000000-1FFFFF.bin");
2287 #elif defined(IRIVER_H300_SERIES)
2288 fd = creat("/internal_rom_000000-3FFFFF.bin");
2289 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2290 fd = creat("/internal_rom_000000-3FFFFF.bin");
2291 #endif
2292 if(fd >= 0)
2294 write(fd, (void *)0, FLASH_SIZE);
2295 close(fd);
2297 system_memory_guard(oldmode);
2299 #ifdef HAVE_EEPROM
2300 fd = creat("/internal_eeprom.bin");
2301 if (fd >= 0)
2303 int old_irq_level;
2304 char buf[EEPROM_SIZE];
2305 int err;
2307 old_irq_level = disable_irq_save();
2309 err = eeprom_24cxx_read(0, buf, sizeof buf);
2311 restore_irq(old_irq_level);
2313 if (err)
2314 splashf(HZ*3, "Eeprom read failure (%d)", err);
2315 else
2317 write(fd, buf, sizeof buf);
2320 close(fd);
2322 #endif
2324 return false;
2326 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
2327 static bool dbg_save_roms(void)
2329 int fd;
2331 fd = creat("/internal_rom_000000-0FFFFF.bin");
2332 if(fd >= 0)
2334 write(fd, (void *)0x20000000, FLASH_SIZE);
2335 close(fd);
2338 return false;
2340 #endif /* CPU */
2342 #ifndef SIMULATOR
2343 #if CONFIG_TUNER
2344 static int radio_callback(int btn, struct gui_synclist *lists)
2346 (void)lists;
2347 if (btn == ACTION_STD_CANCEL)
2348 return btn;
2349 simplelist_set_line_count(1);
2351 #if (CONFIG_TUNER & LV24020LP)
2352 simplelist_addline(SIMPLELIST_ADD_LINE,
2353 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2354 simplelist_addline(SIMPLELIST_ADD_LINE,
2355 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2356 simplelist_addline(SIMPLELIST_ADD_LINE,
2357 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2358 simplelist_addline(SIMPLELIST_ADD_LINE,
2359 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2360 simplelist_addline(SIMPLELIST_ADD_LINE,
2361 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2362 simplelist_addline(SIMPLELIST_ADD_LINE,
2363 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2364 simplelist_addline(SIMPLELIST_ADD_LINE,
2365 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2366 #endif /* LV24020LP */
2367 #if (CONFIG_TUNER & S1A0903X01)
2368 simplelist_addline(SIMPLELIST_ADD_LINE,
2369 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2370 /* This one doesn't return dynamic data atm */
2371 #endif /* S1A0903X01 */
2372 #if (CONFIG_TUNER & TEA5767)
2373 struct tea5767_dbg_info nfo;
2374 tea5767_dbg_info(&nfo);
2375 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2376 simplelist_addline(SIMPLELIST_ADD_LINE,
2377 " Read: %02X %02X %02X %02X %02X",
2378 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2379 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2380 (unsigned)nfo.read_regs[4]);
2381 simplelist_addline(SIMPLELIST_ADD_LINE,
2382 " Write: %02X %02X %02X %02X %02X",
2383 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2384 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2385 (unsigned)nfo.write_regs[4]);
2386 #endif /* TEA5767 */
2387 #if (CONFIG_TUNER & SI4700)
2388 struct si4700_dbg_info nfo;
2389 si4700_dbg_info(&nfo);
2390 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
2391 /* Registers */
2392 simplelist_addline(SIMPLELIST_ADD_LINE,
2393 "%04X %04X %04X %04X",
2394 (unsigned)nfo.regs[0], (unsigned)nfo.regs[1],
2395 (unsigned)nfo.regs[2], (unsigned)nfo.regs[3]);
2396 simplelist_addline(SIMPLELIST_ADD_LINE,
2397 "%04X %04X %04X %04X",
2398 (unsigned)nfo.regs[4], (unsigned)nfo.regs[5],
2399 (unsigned)nfo.regs[6], (unsigned)nfo.regs[7]);
2400 simplelist_addline(SIMPLELIST_ADD_LINE,
2401 "%04X %04X %04X %04X",
2402 (unsigned)nfo.regs[8], (unsigned)nfo.regs[9],
2403 (unsigned)nfo.regs[10], (unsigned)nfo.regs[11]);
2404 simplelist_addline(SIMPLELIST_ADD_LINE,
2405 "%04X %04X %04X %04X",
2406 (unsigned)nfo.regs[12], (unsigned)nfo.regs[13],
2407 (unsigned)nfo.regs[14], (unsigned)nfo.regs[15]);
2408 #endif /* SI4700 */
2409 return ACTION_REDRAW;
2411 static bool dbg_fm_radio(void)
2413 struct simplelist_info info;
2414 info.scroll_all = true;
2415 simplelist_info_init(&info, "FM Radio", 1, NULL);
2416 simplelist_set_line_count(0);
2417 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2418 radio_hardware_present() ? "yes" : "no");
2420 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2421 info.hide_selection = true;
2422 return simplelist_show_list(&info);
2424 #endif /* CONFIG_TUNER */
2425 #endif /* !SIMULATOR */
2427 #ifdef HAVE_LCD_BITMAP
2428 extern bool do_screendump_instead_of_usb;
2430 static bool dbg_screendump(void)
2432 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2433 splashf(HZ, "Screendump %s",
2434 do_screendump_instead_of_usb?"enabled":"disabled");
2435 return false;
2437 #endif /* HAVE_LCD_BITMAP */
2439 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2440 static bool dbg_set_memory_guard(void)
2442 static const struct opt_items names[MAXMEMGUARD] = {
2443 { "None", -1 },
2444 { "Flash ROM writes", -1 },
2445 { "Zero area (all)", -1 }
2447 int mode = system_memory_guard(MEMGUARD_KEEP);
2449 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2450 system_memory_guard(mode);
2452 return false;
2454 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2456 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2457 static bool dbg_write_eeprom(void)
2459 int fd;
2460 int rc;
2461 int old_irq_level;
2462 char buf[EEPROM_SIZE];
2463 int err;
2465 fd = open("/internal_eeprom.bin", O_RDONLY);
2467 if (fd >= 0)
2469 rc = read(fd, buf, EEPROM_SIZE);
2471 if(rc == EEPROM_SIZE)
2473 old_irq_level = disable_irq_save();
2475 err = eeprom_24cxx_write(0, buf, sizeof buf);
2476 if (err)
2477 splashf(HZ*3, "Eeprom write failure (%d)", err);
2478 else
2479 splash(HZ*3, "Eeprom written successfully");
2481 restore_irq(old_irq_level);
2483 else
2485 splashf(HZ*3, "File read error (%d)",rc);
2487 close(fd);
2489 else
2491 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2494 return false;
2496 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2497 #ifdef CPU_BOOST_LOGGING
2498 static bool cpu_boost_log(void)
2500 int i = 0,j=0;
2501 int count = cpu_boost_log_getcount();
2502 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2503 char *str;
2504 bool done;
2505 lcd_setfont(FONT_SYSFIXED);
2506 str = cpu_boost_log_getlog_first();
2507 while (i < count)
2509 lcd_clear_display();
2510 for(j=0; j<lines; j++,i++)
2512 if (!str)
2513 str = cpu_boost_log_getlog_next();
2514 if (str)
2516 lcd_puts(0, j,str);
2518 str = NULL;
2520 lcd_update();
2521 done = false;
2522 while (!done)
2524 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2526 case ACTION_STD_OK:
2527 case ACTION_STD_PREV:
2528 case ACTION_STD_NEXT:
2529 done = true;
2530 break;
2531 case ACTION_STD_CANCEL:
2532 i = count;
2533 done = true;
2534 break;
2538 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2539 lcd_setfont(FONT_UI);
2540 return false;
2542 #endif
2544 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2545 extern bool wheel_is_touched;
2546 extern int old_wheel_value;
2547 extern int new_wheel_value;
2548 extern int wheel_delta;
2549 extern unsigned int accumulated_wheel_delta;
2550 extern unsigned int wheel_velocity;
2552 static bool dbg_scrollwheel(void)
2554 char buf[64];
2555 unsigned int speed;
2557 lcd_setfont(FONT_SYSFIXED);
2559 while (1)
2561 if (action_userabort(HZ/10))
2562 break;
2564 lcd_clear_display();
2566 /* show internal variables of scrollwheel driver */
2567 snprintf(buf, sizeof(buf), "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2568 lcd_puts(0, 0, buf);
2569 snprintf(buf, sizeof(buf), "new position: %2d", new_wheel_value);
2570 lcd_puts(0, 1, buf);
2571 snprintf(buf, sizeof(buf), "old position: %2d", old_wheel_value);
2572 lcd_puts(0, 2, buf);
2573 snprintf(buf, sizeof(buf), "wheel delta: %2d", wheel_delta);
2574 lcd_puts(0, 3, buf);
2575 snprintf(buf, sizeof(buf), "accumulated delta: %2d", accumulated_wheel_delta);
2576 lcd_puts(0, 4, buf);
2577 snprintf(buf, sizeof(buf), "velo [deg/s]: %4d", (int)wheel_velocity);
2578 lcd_puts(0, 5, buf);
2580 /* show effective accelerated scrollspeed */
2581 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2582 snprintf(buf, sizeof(buf), "accel. speed: %4d", speed);
2583 lcd_puts(0, 6, buf);
2585 lcd_update();
2587 lcd_setfont(FONT_UI);
2588 return false;
2590 #endif
2592 #if defined (HAVE_USBSTACK)
2594 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2595 static bool toggle_usb_core_driver(int driver, char *msg)
2597 bool enabled = !usb_core_driver_enabled(driver);
2599 usb_core_enable_driver(driver,enabled);
2600 splashf(HZ, "%s %s", msg, enabled?"enabled":"disabled");
2602 return false;
2605 static bool toggle_usb_serial(void)
2607 return toggle_usb_core_driver(USB_DRIVER_SERIAL,"USB Serial");
2609 #endif
2611 #ifdef USB_ENABLE_HID
2612 static bool hid_send_cmd(consumer_usage_page_t cmd, char *msg)
2614 (void)msg;
2616 if (!usb_core_driver_enabled(USB_DRIVER_HID)) {
2617 splashf(HZ, "Send failed. Driver is disabled");
2618 return false;
2621 usb_hid_send_consumer_usage(cmd);
2622 logf("Sent %s command", msg);
2624 return false;
2626 static bool usb_hid_send_play_pause(void)
2628 return hid_send_cmd(PLAY_PAUSE, "Play/Pause");
2630 static bool usb_hid_send_stop(void)
2632 return hid_send_cmd(STOP, "Stop");
2634 static bool usb_hid_send_scan_previous_track(void)
2636 return hid_send_cmd(SCAN_PREVIOUS_TRACK, "Scan previous track");
2638 static bool usb_hid_send_scan_next_track(void)
2640 return hid_send_cmd(SCAN_NEXT_TRACK, "Scan next track");
2642 static bool usb_hid_send_mute(void)
2644 return hid_send_cmd(MUTE, "Mute");
2646 static bool usb_hid_send_volume_decrement(void)
2648 return hid_send_cmd(VOLUME_DECREMENT, "Vol Down");
2650 static bool usb_hid_send_volume_increment(void)
2652 return hid_send_cmd(VOLUME_INCREMENT, "Vol Up");
2654 #endif
2655 #endif
2657 #if CONFIG_USBOTG == USBOTG_ISP1583
2658 extern int dbg_usb_num_items(void);
2659 extern char* dbg_usb_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2661 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2663 (void)lists;
2664 if (action == ACTION_NONE)
2665 action = ACTION_REDRAW;
2666 return action;
2669 static bool dbg_isp1583(void)
2671 struct simplelist_info isp1583;
2672 isp1583.scroll_all = true;
2673 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2674 isp1583.timeout = HZ/100;
2675 isp1583.hide_selection = true;
2676 isp1583.get_name = dbg_usb_item;
2677 isp1583.action_callback = isp1583_action_callback;
2678 return simplelist_show_list(&isp1583);
2680 #endif
2682 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2683 extern int pic_dbg_num_items(void);
2684 extern char* pic_dbg_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2686 static int pic_action_callback(int action, struct gui_synclist *lists)
2688 (void)lists;
2689 if (action == ACTION_NONE)
2690 action = ACTION_REDRAW;
2691 return action;
2694 static bool dbg_pic(void)
2696 struct simplelist_info pic;
2697 pic.scroll_all = true;
2698 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2699 pic.timeout = HZ/100;
2700 pic.hide_selection = true;
2701 pic.get_name = pic_dbg_item;
2702 pic.action_callback = pic_action_callback;
2703 return simplelist_show_list(&pic);
2705 #endif
2708 /****** The menu *********/
2709 struct the_menu_item {
2710 unsigned char *desc; /* string or ID */
2711 bool (*function) (void); /* return true if USB was connected */
2713 static const struct the_menu_item menuitems[] = {
2714 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2715 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD))
2716 { "Dump ROM contents", dbg_save_roms },
2717 #endif
2718 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2719 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 \
2720 || CONFIG_CPU == DM320
2721 { "View I/O ports", dbg_ports },
2722 #endif
2723 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2724 { "View PCF registers", dbg_pcf },
2725 #endif
2726 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2727 { "TSC2100 debug", tsc2100_debug },
2728 #endif
2729 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2730 { "CPU frequency", dbg_cpufreq },
2731 #endif
2732 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2733 { "S/PDIF analyzer", dbg_spdif },
2734 #endif
2735 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2736 { "Catch mem accesses", dbg_set_memory_guard },
2737 #endif
2738 { "View OS stacks", dbg_os },
2739 #ifdef HAVE_LCD_BITMAP
2740 #ifndef SIMULATOR
2741 { "View battery", view_battery },
2742 #endif
2743 { "Screendump", dbg_screendump },
2744 #endif
2745 #ifndef SIMULATOR
2746 { "View HW info", dbg_hw_info },
2747 #endif
2748 #ifndef SIMULATOR
2749 { "View partitions", dbg_partitions },
2750 #endif
2751 #ifndef SIMULATOR
2752 { "View disk info", dbg_disk_info },
2753 #if (CONFIG_STORAGE & STORAGE_ATA)
2754 { "Dump ATA identify info", dbg_identify_info},
2755 #endif
2756 #endif
2757 #ifdef HAVE_DIRCACHE
2758 { "View dircache info", dbg_dircache_info },
2759 #endif
2760 #ifdef HAVE_TAGCACHE
2761 { "View database info", dbg_tagcache_info },
2762 #endif
2763 #ifdef HAVE_LCD_BITMAP
2764 #if CONFIG_CODEC == SWCODEC
2765 { "View buffering thread", dbg_buffering_thread },
2766 #elif !defined(SIMULATOR)
2767 { "View audio thread", dbg_audio_thread },
2768 #endif
2769 #ifdef PM_DEBUG
2770 { "pm histogram", peak_meter_histogram},
2771 #endif /* PM_DEBUG */
2772 #endif /* HAVE_LCD_BITMAP */
2773 #ifndef SIMULATOR
2774 #if CONFIG_TUNER
2775 { "FM Radio", dbg_fm_radio },
2776 #endif
2777 #endif
2778 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2779 { "Write back EEPROM", dbg_write_eeprom },
2780 #endif
2781 #if CONFIG_USBOTG == USBOTG_ISP1583
2782 { "View ISP1583 info", dbg_isp1583 },
2783 #endif
2784 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2785 { "View PIC info", dbg_pic },
2786 #endif
2787 #ifdef ROCKBOX_HAS_LOGF
2788 {"logf", logfdisplay },
2789 {"logfdump", logfdump },
2790 #endif
2791 #if defined(HAVE_USBSTACK)
2792 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2793 {"USB Serial driver (logf)", toggle_usb_serial },
2794 #endif
2795 #if defined(USB_ENABLE_HID)
2796 {"USB HID play/pause", usb_hid_send_play_pause },
2797 {"USB HID stop", usb_hid_send_stop },
2798 {"USB HID prev track", usb_hid_send_scan_previous_track },
2799 {"USB HID next track", usb_hid_send_scan_next_track },
2800 {"USB HID mute", usb_hid_send_mute },
2801 {"USB HID vol down", usb_hid_send_volume_decrement },
2802 {"USB HID vol up", usb_hid_send_volume_increment },
2803 #endif
2804 #endif /* HAVE_USBSTACK */
2805 #ifdef CPU_BOOST_LOGGING
2806 {"cpu_boost log",cpu_boost_log},
2807 #endif
2808 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2809 {"Debug scrollwheel", dbg_scrollwheel },
2810 #endif
2812 static int menu_action_callback(int btn, struct gui_synclist *lists)
2814 if (btn == ACTION_STD_OK)
2816 int oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL);
2817 menuitems[gui_synclist_get_sel_pos(lists)].function();
2818 btn = ACTION_REDRAW;
2819 viewportmanager_set_statusbar(oldbars);
2821 return btn;
2823 static char* dbg_menu_getname(int item, void * data,
2824 char *buffer, size_t buffer_len)
2826 (void)data; (void)buffer; (void)buffer_len;
2827 return menuitems[item].desc;
2829 bool debug_menu(void)
2831 struct simplelist_info info;
2833 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2834 info.action_callback = menu_action_callback;
2835 info.get_name = dbg_menu_getname;
2836 return simplelist_show_list(&info);