Sansa Fuzev2: Add mkamsboot and dualboot support. The bootloader doesn't work, but...
[kugel-rb.git] / apps / debug_menu.c
blobc45aace60b3d2853ad1a45b578a654eac8140bfa
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Heikki Hannikainen
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <stdbool.h>
26 #include <string.h>
27 #include "lcd.h"
28 #include "menu.h"
29 #include "debug_menu.h"
30 #include "kernel.h"
31 #include "sprintf.h"
32 #include "structec.h"
33 #include "action.h"
34 #include "debug.h"
35 #include "thread.h"
36 #include "powermgmt.h"
37 #include "system.h"
38 #include "font.h"
39 #include "audio.h"
40 #include "mp3_playback.h"
41 #include "settings.h"
42 #include "list.h"
43 #include "statusbar.h"
44 #include "dir.h"
45 #include "panic.h"
46 #include "screens.h"
47 #include "misc.h"
48 #include "splash.h"
49 #include "dircache.h"
50 #include "viewport.h"
51 #ifdef HAVE_TAGCACHE
52 #include "tagcache.h"
53 #endif
54 #include "lcd-remote.h"
55 #include "crc32.h"
56 #include "logf.h"
57 #ifndef SIMULATOR
58 #include "disk.h"
59 #include "adc.h"
60 #include "power.h"
61 #include "usb.h"
62 #include "rtc.h"
63 #include "storage.h"
64 #include "fat.h"
65 #include "mas.h"
66 #include "eeprom_24cxx.h"
67 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
68 #include "hotswap.h"
69 #endif
70 #if (CONFIG_STORAGE & STORAGE_ATA)
71 #include "ata.h"
72 #endif
73 #if CONFIG_TUNER
74 #include "tuner.h"
75 #include "radio.h"
76 #endif
77 #endif
79 #ifdef HAVE_LCD_BITMAP
80 #include "scrollbar.h"
81 #include "peakmeter.h"
82 #endif
83 #include "logfdisp.h"
84 #if CONFIG_CODEC == SWCODEC
85 #include "pcmbuf.h"
86 #include "buffering.h"
87 #include "playback.h"
88 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
89 #include "spdif.h"
90 #endif
91 #endif
92 #ifdef IRIVER_H300_SERIES
93 #include "pcf50606.h" /* for pcf50606_read */
94 #endif
95 #ifdef IAUDIO_X5
96 #include "ds2411.h"
97 #endif
98 #include "hwcompat.h"
99 #include "button.h"
100 #if CONFIG_RTC == RTC_PCF50605
101 #include "pcf50605.h"
102 #endif
103 #include "appevents.h"
105 #if CONFIG_CPU == DM320 || CONFIG_CPU == S3C2440 || CONFIG_CPU == TCC7801 \
106 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 || CONFIG_CPU == JZ4732 \
107 || defined(CPU_S5L870X) || CONFIG_CPU == AS3525v2
108 #include "debug-target.h"
109 #endif
111 #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) \
112 || defined(SANSA_CLIP) || defined(SANSA_FUZE) || defined(SANSA_C200V2)
113 #include "ascodec.h"
114 #include "as3514.h"
115 #endif
117 #ifdef IPOD_NANO2G
118 #include "pmu-target.h"
119 #endif
121 #ifdef HAVE_USBSTACK
122 #include "usb_core.h"
123 #endif
125 /*---------------------------------------------------*/
126 /* SPECIAL DEBUG STUFF */
127 /*---------------------------------------------------*/
128 extern struct thread_entry threads[MAXTHREADS];
130 static char thread_status_char(unsigned status)
132 static const char thread_status_chars[THREAD_NUM_STATES+1] =
134 [0 ... THREAD_NUM_STATES] = '?',
135 [STATE_RUNNING] = 'R',
136 [STATE_BLOCKED] = 'B',
137 [STATE_SLEEPING] = 'S',
138 [STATE_BLOCKED_W_TMO] = 'T',
139 [STATE_FROZEN] = 'F',
140 [STATE_KILLED] = 'K',
143 if (status > THREAD_NUM_STATES)
144 status = THREAD_NUM_STATES;
146 return thread_status_chars[status];
149 static const char* threads_getname(int selected_item, void *data,
150 char *buffer, size_t buffer_len)
152 (void)data;
153 struct thread_entry *thread;
154 char name[32];
156 #if NUM_CORES > 1
157 if (selected_item < (int)NUM_CORES)
159 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
160 idle_stack_usage(selected_item));
161 return buffer;
164 selected_item -= NUM_CORES;
165 #endif
167 thread = &threads[selected_item];
169 if (thread->state == STATE_KILLED)
171 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
172 return buffer;
175 thread_get_name(name, 32, thread);
177 snprintf(buffer, buffer_len,
178 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
179 selected_item,
180 IF_COP(thread->core,)
181 #ifdef HAVE_SCHEDULER_BOOSTCTRL
182 (thread->cpu_boost) ? '+' :
183 #endif
184 ((thread->state == STATE_RUNNING) ? '*' : ' '),
185 thread_status_char(thread->state),
186 IF_PRIO(thread->base_priority, thread->priority, )
187 thread_stack_usage(thread), name);
189 return buffer;
192 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
194 (void)lists;
195 #ifdef ROCKBOX_HAS_LOGF
196 if (action == ACTION_STD_OK)
198 int selpos = gui_synclist_get_sel_pos(lists);
199 #if NUM_CORES > 1
200 if (selpos >= NUM_CORES)
201 remove_thread(threads[selpos - NUM_CORES].id);
202 #else
203 remove_thread(threads[selpos].id);
204 #endif
205 return ACTION_REDRAW;
207 #endif /* ROCKBOX_HAS_LOGF */
208 if (action == ACTION_NONE)
209 action = ACTION_REDRAW;
210 return action;
212 /* Test code!!! */
213 static bool dbg_os(void)
215 struct simplelist_info info;
216 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
217 #if NUM_CORES == 1
218 MAXTHREADS,
219 #else
220 MAXTHREADS+NUM_CORES,
221 #endif
222 NULL);
223 #ifndef ROCKBOX_HAS_LOGF
224 info.hide_selection = true;
225 info.scroll_all = true;
226 #endif
227 info.action_callback = dbg_threads_action_callback;
228 info.get_name = threads_getname;
229 return simplelist_show_list(&info);
232 #ifdef HAVE_LCD_BITMAP
233 #if CONFIG_CODEC != SWCODEC
234 #ifndef SIMULATOR
235 static bool dbg_audio_thread(void)
237 struct audio_debug d;
239 lcd_setfont(FONT_SYSFIXED);
241 while(1)
243 if (action_userabort(HZ/5))
244 return false;
246 audio_get_debugdata(&d);
248 lcd_clear_display();
250 lcd_putsf(0, 0, "read: %x", d.audiobuf_read);
251 lcd_putsf(0, 1, "write: %x", d.audiobuf_write);
252 lcd_putsf(0, 2, "swap: %x", d.audiobuf_swapwrite);
253 lcd_putsf(0, 3, "playing: %d", d.playing);
254 lcd_putsf(0, 4, "playable: %x", d.playable_space);
255 lcd_putsf(0, 5, "unswapped: %x", d.unswapped_space);
257 /* Playable space left */
258 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
259 d.playable_space, HORIZONTAL);
261 /* Show the watermark limit */
262 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
263 d.low_watermark_level, HORIZONTAL);
265 lcd_putsf(0, 7, "wm: %x - %x",
266 d.low_watermark_level, d.lowest_watermark_level);
268 lcd_update();
270 lcd_setfont(FONT_UI);
271 return false;
273 #endif /* !SIMULATOR */
274 #else /* CONFIG_CODEC == SWCODEC */
275 static unsigned int ticks, boost_ticks, freq_sum;
277 static void dbg_audio_task(void)
279 #ifndef SIMULATOR
280 if(FREQ > CPUFREQ_NORMAL)
281 boost_ticks++;
282 freq_sum += FREQ/1000000; /* in MHz */
283 #endif
284 ticks++;
287 static bool dbg_buffering_thread(void)
289 int button;
290 int line;
291 bool done = false;
292 size_t bufused;
293 size_t bufsize = pcmbuf_get_bufsize();
294 int pcmbufdescs = pcmbuf_descs();
295 struct buffering_debug d;
296 size_t filebuflen = audio_get_filebuflen();
297 /* This is a size_t, but call it a long so it puts a - when it's bad. */
299 ticks = boost_ticks = freq_sum = 0;
301 tick_add_task(dbg_audio_task);
303 lcd_setfont(FONT_SYSFIXED);
304 while(!done)
306 button = get_action(CONTEXT_STD,HZ/5);
307 switch(button)
309 case ACTION_STD_NEXT:
310 audio_next();
311 break;
312 case ACTION_STD_PREV:
313 audio_prev();
314 break;
315 case ACTION_STD_CANCEL:
316 done = true;
317 break;
320 buffering_get_debugdata(&d);
322 line = 0;
323 lcd_clear_display();
325 bufused = bufsize - pcmbuf_free();
327 lcd_putsf(0, line++, "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
329 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
330 bufsize, 0, bufused, HORIZONTAL);
331 line++;
333 lcd_putsf(0, line++, "alloc: %6ld/%ld", audio_filebufused(),
334 (long) filebuflen);
336 #if LCD_HEIGHT > 80
337 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
338 filebuflen, 0, audio_filebufused(), HORIZONTAL);
339 line++;
341 lcd_putsf(0, line++, "real: %6ld/%ld", (long)d.buffered_data,
342 (long)filebuflen);
344 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
345 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
346 line++;
347 #endif
349 lcd_putsf(0, line++, "usefl: %6ld/%ld", (long)(d.useful_data),
350 (long)filebuflen);
352 #if LCD_HEIGHT > 80
353 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
354 filebuflen, 0, d.useful_data, HORIZONTAL);
355 line++;
356 #endif
358 lcd_putsf(0, line++, "data_rem: %ld", (long)d.data_rem);
360 lcd_putsf(0, line++, "track count: %2d", audio_track_count());
362 lcd_putsf(0, line++, "handle count: %d", (int)d.num_handles);
364 #ifndef SIMULATOR
365 lcd_putsf(0, line++, "cpu freq: %3dMHz",
366 (int)((FREQ + 500000) / 1000000));
367 #endif
369 if (ticks > 0)
371 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
372 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
373 lcd_putsf(0, line++, "boost:%3d.%d%% (%d.%dMHz)",
374 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
377 lcd_putsf(0, line++, "pcmbufdesc: %2d/%2d",
378 pcmbuf_used_descs(), pcmbufdescs);
379 lcd_putsf(0, line++, "watermark: %6d",
380 (int)(d.watermark));
382 lcd_update();
385 tick_remove_task(dbg_audio_task);
386 lcd_setfont(FONT_UI);
388 return false;
390 #endif /* CONFIG_CODEC */
391 #endif /* HAVE_LCD_BITMAP */
394 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
395 /* Tool function to read the flash manufacturer and type, if available.
396 Only chips which could be reprogrammed in system will return values.
397 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
398 /* In IRAM to avoid problems when running directly from Flash */
399 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
400 unsigned addr1, unsigned addr2)
401 ICODE_ATTR __attribute__((noinline));
402 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
403 unsigned addr1, unsigned addr2)
406 unsigned not_manu, not_id; /* read values before switching to ID mode */
407 unsigned manu, id; /* read values when in ID mode */
409 #if CONFIG_CPU == SH7034
410 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
411 #elif defined(CPU_COLDFIRE)
412 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
413 #endif
414 int old_level; /* saved interrupt level */
416 not_manu = flash[0]; /* read the normal content */
417 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
419 /* disable interrupts, prevent any stray flash access */
420 old_level = disable_irq_save();
422 flash[addr1] = 0xAA; /* enter command mode */
423 flash[addr2] = 0x55;
424 flash[addr1] = 0x90; /* ID command */
425 /* Atmel wants 20ms pause here */
426 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
428 manu = flash[0]; /* read the IDs */
429 id = flash[1];
431 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
432 /* Atmel wants 20ms pause here */
433 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
435 restore_irq(old_level); /* enable interrupts again */
437 /* I assume success if the obtained values are different from
438 the normal flash content. This is not perfectly bulletproof, they
439 could theoretically be the same by chance, causing us to fail. */
440 if (not_manu != manu || not_id != id) /* a value has changed */
442 *p_manufacturer = manu; /* return the results */
443 *p_device = id;
444 return true; /* success */
446 return false; /* fail */
448 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
450 #ifndef SIMULATOR
451 #ifdef CPU_PP
452 static int perfcheck(void)
454 int result;
456 asm (
457 "mrs r2, CPSR \n"
458 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
459 "msr CPSR_c, r0 \n"
460 "mov %[res], #0 \n"
461 "ldr r0, [%[timr]] \n"
462 "add r0, r0, %[tmo] \n"
463 "1: \n"
464 "add %[res], %[res], #1 \n"
465 "ldr r1, [%[timr]] \n"
466 "cmp r1, r0 \n"
467 "bmi 1b \n"
468 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
470 [res]"=&r"(result)
472 [timr]"r"(&USEC_TIMER),
473 [tmo]"r"(
474 #if CONFIG_CPU == PP5002
475 16000
476 #else /* PP5020/5022/5024 */
477 10226
478 #endif
481 "r0", "r1", "r2"
483 return result;
485 #endif
487 #ifdef HAVE_LCD_BITMAP
488 static bool dbg_hw_info(void)
490 #if CONFIG_CPU == SH7034
491 int bitmask = HW_MASK;
492 int rom_version = ROM_VERSION;
493 unsigned manu, id; /* flash IDs */
494 bool got_id; /* flag if we managed to get the flash IDs */
495 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
496 bool has_bootrom; /* flag for boot ROM present */
497 int oldmode; /* saved memory guard mode */
499 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
501 /* get flash ROM type */
502 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
503 if (!got_id)
504 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
506 /* check if the boot ROM area is a flash mirror */
507 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
508 if (has_bootrom) /* if ROM and Flash different */
510 /* calculate CRC16 checksum of boot ROM */
511 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
514 system_memory_guard(oldmode); /* re-enable memory guard */
516 lcd_setfont(FONT_SYSFIXED);
517 lcd_clear_display();
519 lcd_puts(0, 0, "[Hardware info]");
521 lcd_putsf(0, 1, "ROM: %d.%02d", rom_version/100, rom_version%100);
523 lcd_putsf(0, 2, "Mask: 0x%04x", bitmask);
525 if (got_id)
526 lcd_putsf(0, 3, "Flash: M=%02x D=%02x", manu, id);
527 else
528 lcd_puts(0, 3, "Flash: M=?? D=??"); /* unknown, sorry */
530 if (has_bootrom)
532 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
533 lcd_puts(0, 4, "Boot ROM: V1");
534 else
535 lcd_putsf(0, 4, "ROMcrc: 0x%08x", rom_crc);
537 else
539 lcd_puts(0, 4, "Boot ROM: none");
542 lcd_update();
544 while (!(action_userabort(TIMEOUT_BLOCK)));
546 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
547 unsigned manu, id; /* flash IDs */
548 int got_id; /* flag if we managed to get the flash IDs */
549 int oldmode; /* saved memory guard mode */
550 int line = 0;
552 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
554 /* get flash ROM type */
555 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
556 if (!got_id)
557 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
559 system_memory_guard(oldmode); /* re-enable memory guard */
561 lcd_setfont(FONT_SYSFIXED);
562 lcd_clear_display();
564 lcd_puts(0, line++, "[Hardware info]");
566 if (got_id)
567 lcd_putsf(0, line++, "Flash: M=%04x D=%04x", manu, id);
568 else
569 lcd_puts(0, line++, "Flash: M=???? D=????"); /* unknown, sorry */
571 #ifdef IAUDIO_X5
573 struct ds2411_id id;
575 lcd_puts(0, ++line, "Serial Number:");
577 got_id = ds2411_read_id(&id);
579 if (got_id == DS2411_OK)
581 lcd_putsf(0, ++line, " FC=%02x", (unsigned)id.family_code);
582 lcd_putsf(0, ++line, " ID=%02X %02X %02X %02X %02X %02X",
583 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
584 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
585 lcd_putsf(0, ++line, " CRC=%02X", (unsigned)id.crc);
587 else
589 lcd_putsf(0, ++line, "READ ERR=%d", got_id);
592 #endif
594 lcd_update();
596 while (!(action_userabort(TIMEOUT_BLOCK)));
598 #elif defined(CPU_PP502x)
599 int line = 0;
600 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
601 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
602 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
603 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
605 lcd_setfont(FONT_SYSFIXED);
606 lcd_clear_display();
608 lcd_puts(0, line++, "[Hardware info]");
610 #ifdef IPOD_ARCH
611 lcd_putsf(0, line++, "HW rev: 0x%08lx", IPOD_HW_REVISION);
612 #endif
614 #ifdef IPOD_COLOR
615 extern int lcd_type; /* Defined in lcd-colornano.c */
617 lcd_putsf(0, line++, "LCD type: %d", lcd_type);
618 #endif
620 lcd_putsf(0, line++, "PP version: %s", pp_version);
622 lcd_putsf(0, line++, "Est. clock (kHz): %d", perfcheck());
624 lcd_update();
626 while (!(action_userabort(TIMEOUT_BLOCK)));
628 #elif CONFIG_CPU == PP5002
629 int line = 0;
630 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
631 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
632 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
633 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
636 lcd_setfont(FONT_SYSFIXED);
637 lcd_clear_display();
639 lcd_puts(0, line++, "[Hardware info]");
641 #ifdef IPOD_ARCH
642 lcd_putsf(0, line++, "HW rev: 0x%08lx", IPOD_HW_REVISION);
643 #endif
645 lcd_putsf(0, line++, "PP version: %s", pp_version);
647 lcd_putsf(0, line++, "Est. clock (kHz): %d", perfcheck());
649 lcd_update();
651 while (!(action_userabort(TIMEOUT_BLOCK)));
653 #else
654 /* Define this function in your target tree */
655 return __dbg_hw_info();
656 #endif /* CONFIG_CPU */
657 lcd_setfont(FONT_UI);
658 return false;
660 #else /* !HAVE_LCD_BITMAP */
661 static bool dbg_hw_info(void)
663 int button;
664 int currval = 0;
665 int rom_version = ROM_VERSION;
666 unsigned manu, id; /* flash IDs */
667 bool got_id; /* flag if we managed to get the flash IDs */
668 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
669 bool has_bootrom; /* flag for boot ROM present */
670 int oldmode; /* saved memory guard mode */
672 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
674 /* get flash ROM type */
675 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
676 if (!got_id)
677 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
679 /* check if the boot ROM area is a flash mirror */
680 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
681 if (has_bootrom) /* if ROM and Flash different */
683 /* calculate CRC16 checksum of boot ROM */
684 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
687 system_memory_guard(oldmode); /* re-enable memory guard */
689 lcd_clear_display();
691 lcd_puts(0, 0, "[HW Info]");
692 while(1)
694 switch(currval)
696 case 0:
697 lcd_putsf(0, 1, "ROM: %d.%02d",
698 rom_version/100, rom_version%100);
699 break;
700 case 1:
701 if (got_id)
702 lcd_putsf(0, 1, "Flash:%02x,%02x", manu, id);
703 else
704 lcd_puts(0, 1, "Flash:??,??"); /* unknown, sorry */
705 break;
706 case 2:
707 if (has_bootrom)
709 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
710 lcd_puts(0, 1, "BootROM: V1");
711 else if (rom_crc == 0x358099E8)
712 lcd_puts(0, 1, "BootROM: V2");
713 /* alternative boot ROM found in one single player so far */
714 else
715 lcd_putsf(0, 1, "R: %08x", rom_crc);
717 else
718 lcd_puts(0, 1, "BootROM: no");
721 lcd_update();
723 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
725 switch(button)
727 case ACTION_STD_CANCEL:
728 return false;
730 case ACTION_SETTINGS_DEC:
731 currval--;
732 if(currval < 0)
733 currval = 2;
734 break;
736 case ACTION_SETTINGS_INC:
737 currval++;
738 if(currval > 2)
739 currval = 0;
740 break;
743 return false;
745 #endif /* !HAVE_LCD_BITMAP */
746 #endif /* !SIMULATOR */
748 #ifndef SIMULATOR
749 static const char* dbg_partitions_getname(int selected_item, void *data,
750 char *buffer, size_t buffer_len)
752 (void)data;
753 int partition = selected_item/2;
754 struct partinfo* p = disk_partinfo(partition);
755 if (selected_item%2)
757 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / ( 2048 / ( SECTOR_SIZE / 512 )));
759 else
761 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
763 return buffer;
766 bool dbg_partitions(void)
768 struct simplelist_info info;
769 simplelist_info_init(&info, "Partition Info", 4, NULL);
770 info.selection_size = 2;
771 info.hide_selection = true;
772 info.scroll_all = true;
773 info.get_name = dbg_partitions_getname;
774 return simplelist_show_list(&info);
776 #endif
778 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
779 static bool dbg_spdif(void)
781 int line;
782 unsigned int control;
783 int x;
784 char *s;
785 int category;
786 int generation;
787 unsigned int interruptstat;
788 bool valnogood, symbolerr, parityerr;
789 bool done = false;
790 bool spdif_src_on;
791 int spdif_source = spdif_get_output_source(&spdif_src_on);
792 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
794 lcd_clear_display();
795 lcd_setfont(FONT_SYSFIXED);
797 #ifdef HAVE_SPDIF_POWER
798 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
799 #endif
801 while (!done)
803 line = 0;
805 control = EBU1RCVCCHANNEL1;
806 interruptstat = INTERRUPTSTAT;
807 INTERRUPTCLEAR = 0x03c00000;
809 valnogood = (interruptstat & 0x01000000)?true:false;
810 symbolerr = (interruptstat & 0x00800000)?true:false;
811 parityerr = (interruptstat & 0x00400000)?true:false;
813 lcd_putsf(0, line++, "Val: %s Sym: %s Par: %s",
814 valnogood?"--":"OK",
815 symbolerr?"--":"OK",
816 parityerr?"--":"OK");
818 lcd_putsf(0, line++, "Status word: %08x", (int)control);
820 line++;
822 x = control >> 31;
823 lcd_putsf(0, line++, "PRO: %d (%s)",
824 x, x?"Professional":"Consumer");
826 x = (control >> 30) & 1;
827 lcd_putsf(0, line++, "Audio: %d (%s)",
828 x, x?"Non-PCM":"PCM");
830 x = (control >> 29) & 1;
831 lcd_putsf(0, line++, "Copy: %d (%s)",
832 x, x?"Permitted":"Inhibited");
834 x = (control >> 27) & 7;
835 switch(x)
837 case 0:
838 s = "None";
839 break;
840 case 1:
841 s = "50/15us";
842 break;
843 default:
844 s = "Reserved";
845 break;
847 lcd_putsf(0, line++, "Preemphasis: %d (%s)", x, s);
849 x = (control >> 24) & 3;
850 lcd_putsf(0, line++, "Mode: %d", x);
852 category = (control >> 17) & 127;
853 switch(category)
855 case 0x00:
856 s = "General";
857 break;
858 case 0x40:
859 s = "Audio CD";
860 break;
861 default:
862 s = "Unknown";
864 lcd_putsf(0, line++, "Category: 0x%02x (%s)", category, s);
866 x = (control >> 16) & 1;
867 generation = x;
868 if(((category & 0x70) == 0x10) ||
869 ((category & 0x70) == 0x40) ||
870 ((category & 0x78) == 0x38))
872 generation = !generation;
874 lcd_putsf(0, line++, "Generation: %d (%s)",
875 x, generation?"Original":"No ind.");
877 x = (control >> 12) & 15;
878 lcd_putsf(0, line++, "Source: %d", x);
881 x = (control >> 8) & 15;
882 switch(x)
884 case 0:
885 s = "Unspecified";
886 break;
887 case 8:
888 s = "A (Left)";
889 break;
890 case 4:
891 s = "B (Right)";
892 break;
893 default:
894 s = "";
895 break;
897 lcd_putsf(0, line++, "Channel: %d (%s)", x, s);
899 x = (control >> 4) & 15;
900 switch(x)
902 case 0:
903 s = "44.1kHz";
904 break;
905 case 0x4:
906 s = "48kHz";
907 break;
908 case 0xc:
909 s = "32kHz";
910 break;
912 lcd_putsf(0, line++, "Frequency: %d (%s)", x, s);
914 x = (control >> 2) & 3;
915 lcd_putsf(0, line++, "Clock accuracy: %d", x);
916 line++;
918 #ifndef SIMULATOR
919 lcd_putsf(0, line++, "Measured freq: %ldHz",
920 spdif_measure_frequency());
921 #endif
923 lcd_update();
925 if (action_userabort(HZ/10))
926 break;
929 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
931 #ifdef HAVE_SPDIF_POWER
932 spdif_power_enable(global_settings.spdif_enable);
933 #endif
935 lcd_setfont(FONT_UI);
936 return false;
938 #endif /* CPU_COLDFIRE */
940 #ifndef SIMULATOR
941 #ifdef HAVE_LCD_BITMAP
942 /* button definitions */
943 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
944 (CONFIG_KEYPAD == IRIVER_H300_PAD)
945 # define DEBUG_CANCEL BUTTON_OFF
947 #elif CONFIG_KEYPAD == RECORDER_PAD
948 # define DEBUG_CANCEL BUTTON_OFF
950 #elif CONFIG_KEYPAD == ONDIO_PAD
951 # define DEBUG_CANCEL BUTTON_MENU
953 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
954 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
955 (CONFIG_KEYPAD == IPOD_4G_PAD)
956 # define DEBUG_CANCEL BUTTON_MENU
958 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
959 # define DEBUG_CANCEL BUTTON_PLAY
961 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
962 # define DEBUG_CANCEL BUTTON_REC
964 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
965 # define DEBUG_CANCEL BUTTON_RC_REC
967 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
968 # define DEBUG_CANCEL BUTTON_REW
970 #elif (CONFIG_KEYPAD == MROBE100_PAD)
971 # define DEBUG_CANCEL BUTTON_MENU
973 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
974 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
975 (CONFIG_KEYPAD == SANSA_FUZE_PAD)
976 # define DEBUG_CANCEL BUTTON_LEFT
978 /* This is temporary until the SA9200 touchpad works */
979 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) || \
980 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD) || \
981 (CONFIG_KEYPAD == PHILIPS_HDD6330_PAD)
982 # define DEBUG_CANCEL BUTTON_POWER
984 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
985 # define DEBUG_CANCEL BUTTON_PLAY
987 #elif (CONFIG_KEYPAD == PBELL_VIBE500_PAD)
988 # define DEBUG_CANCEL BUTTON_CANCEL
990 #endif /* key definitions */
992 /* Test code!!! */
993 bool dbg_ports(void)
995 #if CONFIG_CPU == SH7034
996 int adc_battery_voltage, adc_battery_level;
998 lcd_setfont(FONT_SYSFIXED);
999 lcd_clear_display();
1001 while(1)
1003 lcd_putsf(0, 0, "PADR: %04x", (unsigned short)PADR);
1004 lcd_putsf(0, 1, "PBDR: %04x", (unsigned short)PBDR);
1006 lcd_putsf(0, 2, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1007 lcd_putsf(0, 3, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1008 lcd_putsf(0, 4, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1009 lcd_putsf(0, 5, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1011 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1012 lcd_putsf(0, 6, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1013 adc_battery_voltage % 1000, adc_battery_level);
1015 lcd_update();
1016 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1018 lcd_setfont(FONT_UI);
1019 return false;
1022 #elif defined(CPU_COLDFIRE)
1023 unsigned int gpio_out;
1024 unsigned int gpio1_out;
1025 unsigned int gpio_read;
1026 unsigned int gpio1_read;
1027 unsigned int gpio_function;
1028 unsigned int gpio1_function;
1029 unsigned int gpio_enable;
1030 unsigned int gpio1_enable;
1031 int adc_buttons, adc_remote;
1032 int adc_battery_voltage, adc_battery_level;
1033 int line;
1035 lcd_clear_display();
1036 lcd_setfont(FONT_SYSFIXED);
1038 while(1)
1040 line = 0;
1041 gpio_read = GPIO_READ;
1042 gpio1_read = GPIO1_READ;
1043 gpio_out = GPIO_OUT;
1044 gpio1_out = GPIO1_OUT;
1045 gpio_function = GPIO_FUNCTION;
1046 gpio1_function = GPIO1_FUNCTION;
1047 gpio_enable = GPIO_ENABLE;
1048 gpio1_enable = GPIO1_ENABLE;
1050 lcd_putsf(0, line++, "GPIO_READ: %08x", gpio_read);
1051 lcd_putsf(0, line++, "GPIO_OUT: %08x", gpio_out);
1052 lcd_putsf(0, line++, "GPIO_FUNC: %08x", gpio_function);
1053 lcd_putsf(0, line++, "GPIO_ENA: %08x", gpio_enable);
1055 lcd_putsf(0, line++, "GPIO1_READ: %08x", gpio1_read);
1056 lcd_putsf(0, line++, "GPIO1_OUT: %08x", gpio1_out);
1057 lcd_putsf(0, line++, "GPIO1_FUNC: %08x", gpio1_function);
1058 lcd_putsf(0, line++, "GPIO1_ENA: %08x", gpio1_enable);
1060 adc_buttons = adc_read(ADC_BUTTONS);
1061 adc_remote = adc_read(ADC_REMOTE);
1062 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1063 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1064 lcd_putsf(0, line++, "ADC_BUTTONS (%c): %02x",
1065 button_scan_enabled() ? '+' : '-', adc_buttons);
1066 #else
1067 lcd_putsf(0, line++, "ADC_BUTTONS: %02x", adc_buttons);
1068 #endif
1069 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1070 lcd_putsf(0, line++, "ADC_REMOTE (%c): %02x",
1071 remote_detect() ? '+' : '-', adc_remote);
1072 #else
1073 lcd_putsf(0, line++, "ADC_REMOTE: %02x", adc_remote);
1074 #endif
1075 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1076 lcd_putsf(0, line++, "ADC_REMOTEDETECT: %02x",
1077 adc_read(ADC_REMOTEDETECT));
1078 #endif
1080 lcd_putsf(0, line++, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1081 adc_battery_voltage % 1000, adc_battery_level);
1083 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1084 lcd_putsf(0, line++, "remotetype: %d", remote_type());
1085 #endif
1087 lcd_update();
1088 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1090 lcd_setfont(FONT_UI);
1091 return false;
1095 #elif defined(CPU_PP502x)
1096 int line;
1098 lcd_clear_display();
1099 lcd_setfont(FONT_SYSFIXED);
1101 while(1)
1103 line = 0;
1104 lcd_puts(0, line++, "GPIO STATES:");
1105 lcd_putsf(0, line++, "A: %02x E: %02x I: %02x",
1106 (unsigned int)GPIOA_INPUT_VAL,
1107 (unsigned int)GPIOE_INPUT_VAL,
1108 (unsigned int)GPIOI_INPUT_VAL);
1109 lcd_putsf(0, line++, "B: %02x F: %02x J: %02x",
1110 (unsigned int)GPIOB_INPUT_VAL,
1111 (unsigned int)GPIOF_INPUT_VAL,
1112 (unsigned int)GPIOJ_INPUT_VAL);
1113 lcd_putsf(0, line++, "C: %02x G: %02x K: %02x",
1114 (unsigned int)GPIOC_INPUT_VAL,
1115 (unsigned int)GPIOG_INPUT_VAL,
1116 (unsigned int)GPIOK_INPUT_VAL);
1117 lcd_putsf(0, line++, "D: %02x H: %02x L: %02x",
1118 (unsigned int)GPIOD_INPUT_VAL,
1119 (unsigned int)GPIOH_INPUT_VAL,
1120 (unsigned int)GPIOL_INPUT_VAL);
1121 line++;
1122 lcd_putsf(0, line++, "GPO32_VAL: %08lx", GPO32_VAL);
1123 lcd_putsf(0, line++, "GPO32_EN: %08lx", GPO32_ENABLE);
1124 lcd_putsf(0, line++, "DEV_EN: %08lx", DEV_EN);
1125 lcd_putsf(0, line++, "DEV_EN2: %08lx", DEV_EN2);
1126 lcd_putsf(0, line++, "DEV_EN3: %08lx", inl(0x60006044)); /* to be verified */
1127 lcd_putsf(0, line++, "DEV_INIT1: %08lx", DEV_INIT1);
1128 lcd_putsf(0, line++, "DEV_INIT2: %08lx", DEV_INIT2);
1129 #ifdef ADC_ACCESSORY
1130 lcd_putsf(0, line++, "ACCESSORY: %d", adc_read(ADC_ACCESSORY));
1131 #endif
1132 #ifdef IPOD_VIDEO
1133 lcd_putsf(0, line++, "4066_ISTAT: %d", adc_read(ADC_4066_ISTAT));
1134 #endif
1136 #if defined(IPOD_ACCESSORY_PROTOCOL)
1137 extern unsigned char serbuf[];
1138 lcd_putsf(0, line++, "IAP PACKET: %02x %02x %02x %02x %02x %02x %02x %02x",
1139 serbuf[0], serbuf[1], serbuf[2], serbuf[3], serbuf[4], serbuf[5],
1140 serbuf[6], serbuf[7]);
1141 #endif
1143 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1144 line++;
1145 lcd_putsf(0, line++, "BATT: %03x UNK1: %03x",
1146 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1147 lcd_putsf(0, line++, "REM: %03x PAD: %03x",
1148 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1149 #elif defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330)
1150 line++;
1151 lcd_putsf(0, line++, "BATT: %03x UNK1: %03x",
1152 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1153 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1154 lcd_putsf(0, line++, "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1155 lcd_putsf(0, line++, "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1156 lcd_putsf(0, line++, "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1157 lcd_putsf(0, line++, "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1158 lcd_putsf(0, line++, "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1159 lcd_putsf(0, line++, "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1160 lcd_putsf(0, line++, "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1161 lcd_putsf(0, line++, "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1162 lcd_putsf(0, line++, "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1163 lcd_putsf(0, line++, "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1164 lcd_putsf(0, line++, "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1165 #if !defined(PHILIPS_SA9200)
1166 lcd_putsf(0, line++, "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1167 lcd_putsf(0, line++, "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1168 #endif
1169 #endif
1170 lcd_update();
1171 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1173 lcd_setfont(FONT_UI);
1174 return false;
1178 #elif CONFIG_CPU == PP5002
1179 int line;
1181 lcd_clear_display();
1182 lcd_setfont(FONT_SYSFIXED);
1184 while(1)
1186 line = 0;
1187 lcd_putsf(0, line++, "GPIO_A: %02x GPIO_B: %02x",
1188 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1189 lcd_putsf(0, line++, "GPIO_C: %02x GPIO_D: %02x",
1190 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1192 lcd_putsf(0, line++, "DEV_EN: %08lx", DEV_EN);
1193 lcd_putsf(0, line++, "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1194 lcd_putsf(0, line++, "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1195 lcd_putsf(0, line++, "PLL_CONTROL: %08lx", PLL_CONTROL);
1196 lcd_putsf(0, line++, "PLL_DIV: %08lx", PLL_DIV);
1197 lcd_putsf(0, line++, "PLL_MULT: %08lx", PLL_MULT);
1198 lcd_putsf(0, line++, "TIMING1_CTL: %08lx", TIMING1_CTL);
1199 lcd_putsf(0, line++, "TIMING2_CTL: %08lx", TIMING2_CTL);
1201 lcd_update();
1202 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1204 lcd_setfont(FONT_UI);
1205 return false;
1208 lcd_setfont(FONT_UI);
1209 #else
1210 return __dbg_ports();
1211 #endif /* CPU */
1212 return false;
1214 #else /* !HAVE_LCD_BITMAP */
1215 bool dbg_ports(void)
1217 char buf[32];
1218 int button;
1219 int adc_battery_voltage;
1220 int currval = 0;
1222 lcd_clear_display();
1224 while(1)
1226 switch(currval)
1228 case 0:
1229 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1230 break;
1231 case 1:
1232 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1233 break;
1234 case 2:
1235 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1236 break;
1237 case 3:
1238 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1239 break;
1240 case 4:
1241 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1242 break;
1243 case 5:
1244 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1245 break;
1246 case 6:
1247 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1248 break;
1249 case 7:
1250 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1251 break;
1252 case 8:
1253 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1254 break;
1255 case 9:
1256 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1257 break;
1259 lcd_puts(0, 0, buf);
1261 battery_read_info(&adc_battery_voltage, NULL);
1262 lcd_putsf(0, 1, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1263 adc_battery_voltage % 1000);
1264 lcd_update();
1266 button = get_action(CONTEXT_SETTINGS,HZ/5);
1268 switch(button)
1270 case ACTION_STD_CANCEL:
1271 return false;
1273 case ACTION_SETTINGS_DEC:
1274 currval--;
1275 if(currval < 0)
1276 currval = 9;
1277 break;
1279 case ACTION_SETTINGS_INC:
1280 currval++;
1281 if(currval > 9)
1282 currval = 0;
1283 break;
1286 return false;
1288 #endif /* !HAVE_LCD_BITMAP */
1289 #endif /* !SIMULATOR */
1291 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1292 static bool dbg_pcf(void)
1294 int line;
1296 #ifdef HAVE_LCD_BITMAP
1297 lcd_setfont(FONT_SYSFIXED);
1298 #endif
1299 lcd_clear_display();
1301 while(1)
1303 line = 0;
1305 lcd_putsf(0, line++, "DCDC1: %02x", pcf50605_read(0x1b));
1306 lcd_putsf(0, line++, "DCDC2: %02x", pcf50605_read(0x1c));
1307 lcd_putsf(0, line++, "DCDC3: %02x", pcf50605_read(0x1d));
1308 lcd_putsf(0, line++, "DCDC4: %02x", pcf50605_read(0x1e));
1309 lcd_putsf(0, line++, "DCDEC1: %02x", pcf50605_read(0x1f));
1310 lcd_putsf(0, line++, "DCDEC2: %02x", pcf50605_read(0x20));
1311 lcd_putsf(0, line++, "DCUDC1: %02x", pcf50605_read(0x21));
1312 lcd_putsf(0, line++, "DCUDC2: %02x", pcf50605_read(0x22));
1313 lcd_putsf(0, line++, "IOREGC: %02x", pcf50605_read(0x23));
1314 lcd_putsf(0, line++, "D1REGC: %02x", pcf50605_read(0x24));
1315 lcd_putsf(0, line++, "D2REGC: %02x", pcf50605_read(0x25));
1316 lcd_putsf(0, line++, "D3REGC: %02x", pcf50605_read(0x26));
1317 lcd_putsf(0, line++, "LPREG1: %02x", pcf50605_read(0x27));
1318 lcd_update();
1319 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1321 lcd_setfont(FONT_UI);
1322 return false;
1326 lcd_setfont(FONT_UI);
1327 return false;
1329 #endif
1331 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1332 static bool dbg_cpufreq(void)
1334 int line;
1335 int button;
1337 #ifdef HAVE_LCD_BITMAP
1338 lcd_setfont(FONT_SYSFIXED);
1339 #endif
1340 lcd_clear_display();
1342 while(1)
1344 line = 0;
1346 lcd_putsf(0, line++, "Frequency: %ld", FREQ);
1347 lcd_putsf(0, line++, "boost_counter: %d", get_cpu_boost_counter());
1349 lcd_update();
1350 button = get_action(CONTEXT_STD,HZ/10);
1352 switch(button)
1354 case ACTION_STD_PREV:
1355 cpu_boost(true);
1356 break;
1358 case ACTION_STD_NEXT:
1359 cpu_boost(false);
1360 break;
1362 case ACTION_STD_OK:
1363 while (get_cpu_boost_counter() > 0)
1364 cpu_boost(false);
1365 set_cpu_frequency(CPUFREQ_DEFAULT);
1366 break;
1368 case ACTION_STD_CANCEL:
1369 lcd_setfont(FONT_UI);
1370 return false;
1373 lcd_setfont(FONT_UI);
1374 return false;
1376 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1378 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1379 #include "tsc2100.h"
1380 static char *itob(int n, int len)
1382 static char binary[64];
1383 int i,j;
1384 for (i=1, j=0;i<=len;i++)
1386 binary[j++] = n&(1<<(len-i))?'1':'0';
1387 if (i%4 == 0)
1388 binary[j++] = ' ';
1390 binary[j] = '\0';
1391 return binary;
1394 static const char* tsc2100_debug_getname(int selected_item, void * data,
1395 char *buffer, size_t buffer_len)
1397 int *page = (int*)data;
1398 bool reserved = false;
1399 switch (*page)
1401 case 0:
1402 if ((selected_item > 0x0a) ||
1403 (selected_item == 0x04) ||
1404 (selected_item == 0x08))
1405 reserved = true;
1406 break;
1407 case 1:
1408 if ((selected_item > 0x05) ||
1409 (selected_item == 0x02))
1410 reserved = true;
1411 break;
1412 case 2:
1413 if (selected_item > 0x1e)
1414 reserved = true;
1415 break;
1417 if (reserved)
1418 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1419 else
1420 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1421 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1422 return buffer;
1424 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1426 int *page = (int*)lists->data;
1427 if (action == ACTION_STD_OK)
1429 *page = (*page+1)%3;
1430 snprintf(lists->title, 32,
1431 "tsc2100 registers - Page %d", *page);
1432 return ACTION_REDRAW;
1434 return action;
1436 static bool tsc2100_debug(void)
1438 int page = 0;
1439 char title[32] = "tsc2100 registers - Page 0";
1440 struct simplelist_info info;
1441 simplelist_info_init(&info, title, 32, &page);
1442 info.timeout = HZ/100;
1443 info.get_name = tsc2100_debug_getname;
1444 info.action_callback= tsc2100debug_action_callback;
1445 return simplelist_show_list(&info);
1447 #endif
1448 #ifndef SIMULATOR
1449 #ifdef HAVE_LCD_BITMAP
1451 * view_battery() shows a automatically scaled graph of the battery voltage
1452 * over time. Usable for estimating battery life / charging rate.
1453 * The power_history array is updated in power_thread of powermgmt.c.
1456 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1457 #define BAT_YSPACE (LCD_HEIGHT - 20)
1459 static bool view_battery(void)
1461 int view = 0;
1462 int i, x, y;
1463 unsigned short maxv, minv;
1465 lcd_setfont(FONT_SYSFIXED);
1467 while(1)
1469 lcd_clear_display();
1470 switch (view) {
1471 case 0: /* voltage history graph */
1472 /* Find maximum and minimum voltage for scaling */
1473 minv = power_history[0];
1474 maxv = minv + 1;
1475 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1476 if (power_history[i] > maxv)
1477 maxv = power_history[i];
1478 if (power_history[i] < minv)
1479 minv = power_history[i];
1482 lcd_putsf(0, 0, "Battery %d.%03d", power_history[0] / 1000,
1483 power_history[0] % 1000);
1484 lcd_putsf(0, 1, "scale %d.%03d-%d.%03dV",
1485 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1487 x = 0;
1488 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1489 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1490 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1491 lcd_vline(x, LCD_HEIGHT-1, 20);
1492 lcd_set_drawmode(DRMODE_SOLID);
1493 lcd_vline(x, LCD_HEIGHT-1,
1494 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1495 x++;
1498 break;
1500 case 1: /* status: */
1501 lcd_puts(0, 0, "Power status:");
1503 battery_read_info(&y, NULL);
1504 lcd_putsf(0, 1, "Battery: %d.%03d V", y / 1000, y % 1000);
1505 #ifdef ADC_EXT_POWER
1506 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1507 lcd_putsf(0, 2, "External: %d.%03d V", y / 1000, y % 1000);
1508 #endif
1509 #if CONFIG_CHARGING
1510 #if defined ARCHOS_RECORDER
1511 lcd_putsf(0, 3, "Chgr: %s %s",
1512 charger_inserted() ? "present" : "absent",
1513 charger_enabled() ? "on" : "off");
1514 lcd_putsf(0, 5, "short delta: %d", short_delta);
1515 lcd_putsf(0, 6, "long delta: %d", long_delta);
1516 lcd_puts(0, 7, power_message);
1517 lcd_putsf(0, 8, "USB Inserted: %s",
1518 usb_inserted() ? "yes" : "no");
1519 #elif defined IRIVER_H300_SERIES
1520 lcd_putsf(0, 9, "USB Charging Enabled: %s",
1521 usb_charging_enabled() ? "yes" : "no");
1522 #elif defined IPOD_NANO || defined IPOD_VIDEO
1523 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1524 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1525 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1526 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1527 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1529 lcd_putsf(0, 3, "USB pwr: %s",
1530 usb_pwr ? "present" : "absent");
1531 lcd_putsf(0, 4, "EXT pwr: %s",
1532 ext_pwr ? "present" : "absent");
1533 lcd_putsf(0, 5, "Battery: %s",
1534 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1535 lcd_putsf(0, 6, "Dock mode: %s",
1536 dock ? "enabled" : "disabled");
1537 lcd_putsf(0, 7, "Headphone: %s",
1538 headphone ? "connected" : "disconnected");
1539 #ifdef IPOD_VIDEO
1540 x = (adc_read(ADC_4066_ISTAT) * 2400) /
1541 #if MEM == 64
1542 (1024 * 2);
1543 #else
1544 (1024 * 3);
1545 #endif
1546 lcd_putsf(0, 8, "Ibat: %d mA", x);
1547 lcd_putsf(0, 9, "Vbat * Ibat: %d mW", x * y / 1000);
1548 #endif
1549 #elif defined TOSHIBA_GIGABEAT_S
1550 int line = 3;
1551 unsigned int st;
1553 static const unsigned char * const chrgstate_strings[] =
1555 "Disabled",
1556 "Error",
1557 "Discharging",
1558 "Precharge",
1559 "Constant Voltage",
1560 "Constant Current",
1561 "<unknown>",
1564 lcd_putsf(0, line++, "Charger: %s",
1565 charger_inserted() ? "present" : "absent");
1567 st = power_input_status() &
1568 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1569 lcd_putsf(0, line++, "%s%s",
1570 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1571 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1573 lcd_putsf(0, line++, "IUSB Max: %d", usb_allowed_current());
1575 y = ARRAYLEN(chrgstate_strings) - 1;
1577 switch (charge_state)
1579 case CHARGE_STATE_DISABLED: y--;
1580 case CHARGE_STATE_ERROR: y--;
1581 case DISCHARGING: y--;
1582 case TRICKLE: y--;
1583 case TOPOFF: y--;
1584 case CHARGING: y--;
1585 default:;
1588 lcd_putsf(0, line++, "State: %s", chrgstate_strings[y]);
1590 lcd_putsf(0, line++, "Battery Switch: %s",
1591 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1593 y = chrgraw_adc_voltage();
1594 lcd_putsf(0, line++, "CHRGRAW: %d.%03d V",
1595 y / 1000, y % 1000);
1597 y = application_supply_adc_voltage();
1598 lcd_putsf(0, line++, "BP : %d.%03d V",
1599 y / 1000, y % 1000);
1601 y = battery_adc_charge_current();
1602 if (y < 0) x = '-', y = -y;
1603 else x = ' ';
1604 lcd_putsf(0, line++, "CHRGISN:%c%d mA", x, y);
1606 y = cccv_regulator_dissipation();
1607 lcd_putsf(0, line++, "P CCCV : %d mW", y);
1609 y = battery_charge_current();
1610 if (y < 0) x = '-', y = -y;
1611 else x = ' ';
1612 lcd_putsf(0, line++, "I Charge:%c%d mA", x, y);
1614 y = battery_adc_temp();
1616 if (y != INT_MIN) {
1617 lcd_putsf(0, line++, "T Battery: %dC (%dF)", y,
1618 (9*y + 160) / 5);
1619 } else {
1620 /* Conversion disabled */
1621 lcd_puts(0, line++, "T Battery: ?");
1624 #elif defined(SANSA_E200) || defined(SANSA_C200) || defined(SANSA_CLIP) || \
1625 defined(SANSA_FUZE) || defined (SANSA_C200V2)
1626 const int first = CHARGE_STATE_DISABLED;
1627 static const char * const chrgstate_strings[] =
1629 [CHARGE_STATE_DISABLED-first] = "Disabled",
1630 [CHARGE_STATE_ERROR-first] = "Error",
1631 [DISCHARGING-first] = "Discharging",
1632 [CHARGING-first] = "Charging",
1634 const char *str = NULL;
1636 lcd_putsf(0, 3, "Charger: %s",
1637 charger_inserted() ? "present" : "absent");
1639 y = charge_state - first;
1640 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1641 str = chrgstate_strings[y];
1643 lcd_putsf(0, 4, "State: %s",
1644 str ? str : "<unknown>");
1646 lcd_putsf(0, 5, "CHARGER: %02X",
1647 ascodec_read(AS3514_CHARGER));
1648 #elif defined(IPOD_NANO2G)
1649 y = pmu_read_battery_current();
1650 lcd_putsf(0, 2, "Battery current: %d mA", y);
1651 lcd_putsf(0, 3, "PWRCON: %8x", PWRCON);
1652 lcd_putsf(0, 4, "PWRCONEXT: %8x", PWRCONEXT);
1653 x = pmu_read(0x1b) & 0xf;
1654 y = pmu_read(0x1a) * 25 + 625;
1655 lcd_putsf(0, 5, "AUTO: %x / %d mV", x, y);
1656 x = pmu_read(0x1f) & 0xf;
1657 y = pmu_read(0x1e) * 25 + 625;
1658 lcd_putsf(0, 6, "DOWN1: %x / %d mV", x, y);
1659 x = pmu_read(0x23) & 0xf;
1660 y = pmu_read(0x22) * 25 + 625;
1661 lcd_putsf(0, 7, "DOWN2: %x / %d mV", x, y);
1662 x = pmu_read(0x27) & 0xf;
1663 y = pmu_read(0x26) * 100 + 900;
1664 lcd_putsf(0, 8, "MEMLDO: %x / %d mV", x, y);
1665 for (i = 0; i < 6; i++)
1667 x = pmu_read(0x2e + (i << 1)) & 0xf;
1668 y = pmu_read(0x2d + (i << 1)) * 100 + 900;
1669 lcd_putsf(0, 9 + i, "LDO%d: %x / %d mV", i + 1, x, y);
1671 lcd_putsf(0, 15, "CLKCON: %8x", CLKCON);
1672 lcd_putsf(17, 15, "PLL0: %6x", PLL0PMS);
1673 #else
1674 lcd_putsf(0, 3, "Charger: %s",
1675 charger_inserted() ? "present" : "absent");
1676 #endif /* target type */
1677 #endif /* CONFIG_CHARGING */
1678 break;
1680 case 2: /* voltage deltas: */
1681 lcd_puts(0, 0, "Voltage deltas:");
1683 for (i = 0; i <= 6; i++) {
1684 y = power_history[i] - power_history[i+1];
1685 lcd_putsf(0, i+1, "-%d min: %s%d.%03d V", i,
1686 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1687 ((y < 0) ? y * -1 : y ) % 1000);
1689 break;
1691 case 3: /* remaining time estimation: */
1693 #ifdef ARCHOS_RECORDER
1694 lcd_putsf(0, 0, "charge_state: %d", charge_state);
1696 lcd_putsf(0, 1, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1698 lcd_putsf(0, 2, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1700 lcd_putsf(0, 3, "P=%2d I=%2d", pid_p, pid_i);
1702 lcd_putsf(0, 4, "Trickle sec: %d/60", trickle_sec);
1703 #endif /* ARCHOS_RECORDER */
1705 lcd_putsf(0, 5, "Last PwrHist: %d.%03dV",
1706 power_history[0] / 1000,
1707 power_history[0] % 1000);
1709 lcd_putsf(0, 6, "battery level: %d%%", battery_level());
1711 lcd_putsf(0, 7, "Est. remain: %d m", battery_time());
1712 break;
1715 lcd_update();
1717 switch(get_action(CONTEXT_STD,HZ/2))
1719 case ACTION_STD_PREV:
1720 if (view)
1721 view--;
1722 break;
1724 case ACTION_STD_NEXT:
1725 if (view < 3)
1726 view++;
1727 break;
1729 case ACTION_STD_CANCEL:
1730 lcd_setfont(FONT_UI);
1731 return false;
1734 lcd_setfont(FONT_UI);
1735 return false;
1738 #endif /* HAVE_LCD_BITMAP */
1739 #endif
1741 #ifndef SIMULATOR
1742 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1744 #if (CONFIG_STORAGE & STORAGE_MMC)
1745 #define CARDTYPE "MMC"
1746 #elif (CONFIG_STORAGE & STORAGE_SD)
1747 #define CARDTYPE "microSD"
1748 #endif
1750 static int disk_callback(int btn, struct gui_synclist *lists)
1752 tCardInfo *card;
1753 int *cardnum = (int*)lists->data;
1754 unsigned char card_name[6];
1755 unsigned char pbuf[32];
1756 char *title = lists->title;
1757 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1758 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1759 static const unsigned char * const kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1760 static const unsigned char * const nsec_units[] = { "ns", "µs", "ms" };
1761 #if (CONFIG_STORAGE & STORAGE_MMC)
1762 static const char * const mmc_spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1763 "3.1-3.31", "4.0" };
1764 #endif
1766 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1768 #ifdef HAVE_HOTSWAP
1769 if (btn == ACTION_STD_OK)
1771 *cardnum ^= 0x1; /* change cards */
1773 #endif
1775 simplelist_set_line_count(0);
1777 card = card_get_info(*cardnum);
1779 if (card->initialized > 0)
1781 unsigned i;
1782 for (i=0; i<sizeof(card_name); i++)
1784 card_name[i] = card_extract_bits(card->cid, (103-8*i), 8);
1786 strlcpy(card_name, card_name, sizeof(card_name));
1787 simplelist_addline(SIMPLELIST_ADD_LINE,
1788 "%s Rev %d.%d", card_name,
1789 (int) card_extract_bits(card->cid, 63, 4),
1790 (int) card_extract_bits(card->cid, 59, 4));
1791 simplelist_addline(SIMPLELIST_ADD_LINE,
1792 "Prod: %d/%d",
1793 #if (CONFIG_STORAGE & STORAGE_SD)
1794 (int) card_extract_bits(card->cid, 11, 4),
1795 (int) card_extract_bits(card->cid, 19, 8) + 2000
1796 #elif (CONFIG_STORAGE & STORAGE_MMC)
1797 (int) card_extract_bits(card->cid, 15, 4),
1798 (int) card_extract_bits(card->cid, 11, 4) + 1997
1799 #endif
1801 simplelist_addline(SIMPLELIST_ADD_LINE,
1802 #if (CONFIG_STORAGE & STORAGE_SD)
1803 "Ser#: 0x%08lx",
1804 card_extract_bits(card->cid, 55, 32)
1805 #elif (CONFIG_STORAGE & STORAGE_MMC)
1806 "Ser#: 0x%04lx",
1807 card_extract_bits(card->cid, 47, 16)
1808 #endif
1811 simplelist_addline(SIMPLELIST_ADD_LINE, "M=%02x, "
1812 #if (CONFIG_STORAGE & STORAGE_SD)
1813 "O=%c%c",
1814 (int) card_extract_bits(card->cid, 127, 8),
1815 card_extract_bits(card->cid, 119, 8),
1816 card_extract_bits(card->cid, 111, 8)
1817 #elif (CONFIG_STORAGE & STORAGE_MMC)
1818 "O=%04x",
1819 (int) card_extract_bits(card->cid, 127, 8),
1820 (int) card_extract_bits(card->cid, 119, 16)
1821 #endif
1824 #if (CONFIG_STORAGE & STORAGE_MMC)
1825 int temp = card_extract_bits(card->csd, 125, 4);
1826 simplelist_addline(SIMPLELIST_ADD_LINE,
1827 "MMC v%s", temp < 5 ?
1828 mmc_spec_vers[temp] : "?.?");
1829 #endif
1830 simplelist_addline(SIMPLELIST_ADD_LINE,
1831 "Blocks: 0x%08lx", card->numblocks);
1832 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1833 kbit_units, false);
1834 simplelist_addline(SIMPLELIST_ADD_LINE,
1835 "Speed: %s", pbuf);
1836 output_dyn_value(pbuf, sizeof pbuf, card->taac,
1837 nsec_units, false);
1838 simplelist_addline(SIMPLELIST_ADD_LINE,
1839 "Taac: %s", pbuf);
1840 simplelist_addline(SIMPLELIST_ADD_LINE,
1841 "Nsac: %d clk", card->nsac);
1842 simplelist_addline(SIMPLELIST_ADD_LINE,
1843 "R2W: *%d", card->r2w_factor);
1844 simplelist_addline(SIMPLELIST_ADD_LINE,
1845 "IRmax: %d..%d mA",
1846 i_vmin[card_extract_bits(card->csd, 61, 3)],
1847 i_vmax[card_extract_bits(card->csd, 58, 3)]);
1848 simplelist_addline(SIMPLELIST_ADD_LINE,
1849 "IWmax: %d..%d mA",
1850 i_vmin[card_extract_bits(card->csd, 55, 3)],
1851 i_vmax[card_extract_bits(card->csd, 52, 3)]);
1853 else if (card->initialized == 0)
1855 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1857 #if (CONFIG_STORAGE & STORAGE_SD)
1858 else /* card->initialized < 0 */
1860 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1862 #endif
1863 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1864 gui_synclist_set_title(lists, title, Icon_NOICON);
1865 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1866 gui_synclist_select_item(lists, 0);
1867 btn = ACTION_REDRAW;
1869 return btn;
1871 #elif (CONFIG_STORAGE & STORAGE_ATA)
1872 static int disk_callback(int btn, struct gui_synclist *lists)
1874 (void)lists;
1875 int i;
1876 char buf[128];
1877 unsigned short* identify_info = ata_get_identify();
1878 bool timing_info_present = false;
1879 (void)btn;
1881 simplelist_set_line_count(0);
1883 for (i=0; i < 20; i++)
1884 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1885 buf[40]=0;
1886 /* kill trailing space */
1887 for (i=39; i && buf[i]==' '; i--)
1888 buf[i] = 0;
1889 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1890 for (i=0; i < 4; i++)
1891 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1892 buf[8]=0;
1893 simplelist_addline(SIMPLELIST_ADD_LINE,
1894 "Firmware: %s", buf);
1895 snprintf(buf, sizeof buf, "%ld MB",
1896 ((unsigned long)identify_info[61] << 16 |
1897 (unsigned long)identify_info[60]) / 2048 );
1898 simplelist_addline(SIMPLELIST_ADD_LINE,
1899 "Size: %s", buf);
1900 unsigned long free;
1901 fat_size( IF_MV2(0,) NULL, &free );
1902 simplelist_addline(SIMPLELIST_ADD_LINE,
1903 "Free: %ld MB", free / 1024);
1904 simplelist_addline(SIMPLELIST_ADD_LINE,
1905 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
1906 i = identify_info[83] & (1<<3);
1907 simplelist_addline(SIMPLELIST_ADD_LINE,
1908 "Power mgmt: %s", i ? "enabled" : "unsupported");
1909 i = identify_info[83] & (1<<9);
1910 simplelist_addline(SIMPLELIST_ADD_LINE,
1911 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1912 i = identify_info[82] & (1<<6);
1913 simplelist_addline(SIMPLELIST_ADD_LINE,
1914 "Read-ahead: %s", i ? "enabled" : "unsupported");
1915 timing_info_present = identify_info[53] & (1<<1);
1916 if(timing_info_present) {
1917 char pio3[2], pio4[2];pio3[1] = 0;
1918 pio4[1] = 0;
1919 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1920 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1921 simplelist_addline(SIMPLELIST_ADD_LINE,
1922 "PIO modes: 0 1 2 %s %s", pio3, pio4);
1924 else {
1925 simplelist_addline(SIMPLELIST_ADD_LINE,
1926 "No PIO mode info");
1928 timing_info_present = identify_info[53] & (1<<1);
1929 if(timing_info_present) {
1930 simplelist_addline(SIMPLELIST_ADD_LINE,
1931 "Cycle times %dns/%dns",
1932 identify_info[67],
1933 identify_info[68] );
1934 } else {
1935 simplelist_addline(SIMPLELIST_ADD_LINE,
1936 "No timing info");
1938 #ifdef HAVE_ATA_DMA
1939 if (identify_info[63] & (1<<0)) {
1940 char mdma0[2], mdma1[2], mdma2[2];
1941 mdma0[1] = mdma1[1] = mdma2[1] = 0;
1942 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
1943 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
1944 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
1945 simplelist_addline(SIMPLELIST_ADD_LINE,
1946 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
1947 simplelist_addline(SIMPLELIST_ADD_LINE,
1948 "MDMA Cycle times %dns/%dns",
1949 identify_info[65],
1950 identify_info[66] );
1952 else {
1953 simplelist_addline(SIMPLELIST_ADD_LINE,
1954 "No MDMA mode info");
1956 if (identify_info[53] & (1<<2)) {
1957 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2], udma6[2];
1958 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = udma6[1] = 0;
1959 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
1960 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
1961 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
1962 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
1963 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
1964 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
1965 udma6[0] = (identify_info[88] & (1<<6)) ? '6' : 0;
1966 simplelist_addline(SIMPLELIST_ADD_LINE,
1967 "UDMA modes: %s %s %s %s %s %s %s", udma0, udma1, udma2,
1968 udma3, udma4, udma5, udma6);
1970 else {
1971 simplelist_addline(SIMPLELIST_ADD_LINE,
1972 "No UDMA mode info");
1974 #endif /* HAVE_ATA_DMA */
1975 timing_info_present = identify_info[53] & (1<<1);
1976 if(timing_info_present) {
1977 i = identify_info[49] & (1<<11);
1978 simplelist_addline(SIMPLELIST_ADD_LINE,
1979 "IORDY support: %s", i ? "yes" : "no");
1980 i = identify_info[49] & (1<<10);
1981 simplelist_addline(SIMPLELIST_ADD_LINE,
1982 "IORDY disable: %s", i ? "yes" : "no");
1983 } else {
1984 simplelist_addline(SIMPLELIST_ADD_LINE,
1985 "No timing info");
1987 simplelist_addline(SIMPLELIST_ADD_LINE,
1988 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1989 #ifdef HAVE_ATA_DMA
1990 i = ata_get_dma_mode();
1991 if (i == 0) {
1992 simplelist_addline(SIMPLELIST_ADD_LINE,
1993 "DMA not enabled");
1994 } else {
1995 simplelist_addline(SIMPLELIST_ADD_LINE,
1996 "DMA mode: %s %c",
1997 (i & 0x40) ? "UDMA" : "MDMA",
1998 '0' + (i & 7));
2000 #endif /* HAVE_ATA_DMA */
2001 return btn;
2003 #else /* No SD, MMC or ATA */
2004 static int disk_callback(int btn, struct gui_synclist *lists)
2006 (void)btn;
2007 (void)lists;
2008 struct storage_info info;
2009 storage_get_info(0,&info);
2010 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
2011 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
2012 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
2013 simplelist_addline(SIMPLELIST_ADD_LINE,
2014 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
2015 unsigned long free;
2016 fat_size( IF_MV2(0,) NULL, &free );
2017 simplelist_addline(SIMPLELIST_ADD_LINE,
2018 "Free: %ld MB", free / 1024);
2019 simplelist_addline(SIMPLELIST_ADD_LINE,
2020 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2021 return btn;
2023 #endif
2025 #if (CONFIG_STORAGE & STORAGE_ATA)
2026 static bool dbg_identify_info(void)
2028 int fd = creat("/identify_info.bin");
2029 if(fd >= 0)
2031 #ifdef ROCKBOX_LITTLE_ENDIAN
2032 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
2033 #else
2034 write(fd, ata_get_identify(), SECTOR_SIZE);
2035 #endif
2036 close(fd);
2038 return false;
2040 #endif
2042 static bool dbg_disk_info(void)
2044 struct simplelist_info info;
2045 simplelist_info_init(&info, "Disk Info", 1, NULL);
2046 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
2047 char title[16];
2048 int card = 0;
2049 info.callback_data = (void*)&card;
2050 info.title = title;
2051 #endif
2052 info.action_callback = disk_callback;
2053 info.hide_selection = true;
2054 info.scroll_all = true;
2055 return simplelist_show_list(&info);
2057 #endif /* !SIMULATOR */
2059 #ifdef HAVE_DIRCACHE
2060 static int dircache_callback(int btn, struct gui_synclist *lists)
2062 (void)btn; (void)lists;
2063 simplelist_set_line_count(0);
2064 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
2065 dircache_is_enabled() ? "Yes" : "No");
2066 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
2067 dircache_get_cache_size());
2068 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
2069 global_status.dircache_size);
2070 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
2071 DIRCACHE_LIMIT);
2072 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
2073 dircache_get_reserve_used(), DIRCACHE_RESERVE);
2074 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2075 dircache_get_build_ticks() / HZ);
2076 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2077 dircache_get_entry_count());
2078 return btn;
2081 static bool dbg_dircache_info(void)
2083 struct simplelist_info info;
2084 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2085 info.action_callback = dircache_callback;
2086 info.hide_selection = true;
2087 info.scroll_all = true;
2088 return simplelist_show_list(&info);
2091 #endif /* HAVE_DIRCACHE */
2093 #ifdef HAVE_TAGCACHE
2094 static int database_callback(int btn, struct gui_synclist *lists)
2096 (void)lists;
2097 struct tagcache_stat *stat = tagcache_get_stat();
2098 static bool synced = false;
2100 simplelist_set_line_count(0);
2102 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2103 stat->initialized ? "Yes" : "No");
2104 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2105 stat->ready ? "Yes" : "No");
2106 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2107 stat->ramcache ? "Yes" : "No");
2108 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2109 stat->ramcache_used, stat->ramcache_allocated);
2110 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2111 stat->progress, stat->processed_entries);
2112 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2113 stat->curentry ? stat->curentry : "---");
2114 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2115 stat->commit_step);
2116 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2117 stat->commit_delayed ? "Yes" : "No");
2119 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2120 stat->queue_length);
2122 if (synced)
2124 synced = false;
2125 tagcache_screensync_event();
2128 if (!btn && stat->curentry)
2130 synced = true;
2131 return ACTION_REDRAW;
2134 if (btn == ACTION_STD_CANCEL)
2135 tagcache_screensync_enable(false);
2137 return btn;
2139 static bool dbg_tagcache_info(void)
2141 struct simplelist_info info;
2142 simplelist_info_init(&info, "Database Info", 8, NULL);
2143 info.action_callback = database_callback;
2144 info.hide_selection = true;
2145 info.scroll_all = true;
2147 /* Don't do nonblock here, must give enough processing time
2148 for tagcache thread. */
2149 /* info.timeout = TIMEOUT_NOBLOCK; */
2150 info.timeout = 1;
2151 tagcache_screensync_enable(true);
2152 return simplelist_show_list(&info);
2154 #endif
2156 #if CONFIG_CPU == SH7034
2157 static bool dbg_save_roms(void)
2159 int fd;
2160 int oldmode = system_memory_guard(MEMGUARD_NONE);
2162 fd = creat("/internal_rom_0000-FFFF.bin");
2163 if(fd >= 0)
2165 write(fd, (void *)0, 0x10000);
2166 close(fd);
2169 fd = creat("/internal_rom_2000000-203FFFF.bin");
2170 if(fd >= 0)
2172 write(fd, (void *)0x2000000, 0x40000);
2173 close(fd);
2176 system_memory_guard(oldmode);
2177 return false;
2179 #elif defined CPU_COLDFIRE
2180 static bool dbg_save_roms(void)
2182 int fd;
2183 int oldmode = system_memory_guard(MEMGUARD_NONE);
2185 #if defined(IRIVER_H100_SERIES)
2186 fd = creat("/internal_rom_000000-1FFFFF.bin");
2187 #elif defined(IRIVER_H300_SERIES)
2188 fd = creat("/internal_rom_000000-3FFFFF.bin");
2189 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2190 fd = creat("/internal_rom_000000-3FFFFF.bin");
2191 #endif
2192 if(fd >= 0)
2194 write(fd, (void *)0, FLASH_SIZE);
2195 close(fd);
2197 system_memory_guard(oldmode);
2199 #ifdef HAVE_EEPROM
2200 fd = creat("/internal_eeprom.bin");
2201 if (fd >= 0)
2203 int old_irq_level;
2204 char buf[EEPROM_SIZE];
2205 int err;
2207 old_irq_level = disable_irq_save();
2209 err = eeprom_24cxx_read(0, buf, sizeof buf);
2211 restore_irq(old_irq_level);
2213 if (err)
2214 splashf(HZ*3, "Eeprom read failure (%d)", err);
2215 else
2217 write(fd, buf, sizeof buf);
2220 close(fd);
2222 #endif
2224 return false;
2226 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
2227 static bool dbg_save_roms(void)
2229 int fd;
2231 fd = creat("/internal_rom_000000-0FFFFF.bin");
2232 if(fd >= 0)
2234 write(fd, (void *)0x20000000, FLASH_SIZE);
2235 close(fd);
2238 return false;
2240 #elif CONFIG_CPU == IMX31L
2241 static bool dbg_save_roms(void)
2243 int fd;
2245 fd = creat("/flash_rom_A0000000-A01FFFFF.bin");
2246 if (fd >= 0)
2248 write(fd, (void*)0xa0000000, FLASH_SIZE);
2249 close(fd);
2252 return false;
2254 #elif defined(CPU_TCC780X)
2255 static bool dbg_save_roms(void)
2257 int fd;
2259 fd = creat("/eeprom_E0000000-E0001FFF.bin");
2260 if (fd >= 0)
2262 write(fd, (void*)0xe0000000, 0x2000);
2263 close(fd);
2266 return false;
2268 #endif /* CPU */
2270 #ifndef SIMULATOR
2271 #if CONFIG_TUNER
2272 static int radio_callback(int btn, struct gui_synclist *lists)
2274 (void)lists;
2275 if (btn == ACTION_STD_CANCEL)
2276 return btn;
2277 simplelist_set_line_count(1);
2279 #if (CONFIG_TUNER & LV24020LP)
2280 simplelist_addline(SIMPLELIST_ADD_LINE,
2281 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2282 simplelist_addline(SIMPLELIST_ADD_LINE,
2283 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2284 simplelist_addline(SIMPLELIST_ADD_LINE,
2285 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2286 simplelist_addline(SIMPLELIST_ADD_LINE,
2287 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2288 simplelist_addline(SIMPLELIST_ADD_LINE,
2289 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2290 simplelist_addline(SIMPLELIST_ADD_LINE,
2291 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2292 simplelist_addline(SIMPLELIST_ADD_LINE,
2293 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2294 #endif /* LV24020LP */
2295 #if (CONFIG_TUNER & S1A0903X01)
2296 simplelist_addline(SIMPLELIST_ADD_LINE,
2297 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2298 /* This one doesn't return dynamic data atm */
2299 #endif /* S1A0903X01 */
2300 #if (CONFIG_TUNER & TEA5767)
2301 struct tea5767_dbg_info nfo;
2302 tea5767_dbg_info(&nfo);
2303 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2304 simplelist_addline(SIMPLELIST_ADD_LINE,
2305 " Read: %02X %02X %02X %02X %02X",
2306 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2307 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2308 (unsigned)nfo.read_regs[4]);
2309 simplelist_addline(SIMPLELIST_ADD_LINE,
2310 " Write: %02X %02X %02X %02X %02X",
2311 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2312 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2313 (unsigned)nfo.write_regs[4]);
2314 #endif /* TEA5767 */
2315 #if (CONFIG_TUNER & SI4700)
2316 struct si4700_dbg_info nfo;
2317 si4700_dbg_info(&nfo);
2318 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
2319 /* Registers */
2320 simplelist_addline(SIMPLELIST_ADD_LINE,
2321 "%04X %04X %04X %04X",
2322 (unsigned)nfo.regs[0], (unsigned)nfo.regs[1],
2323 (unsigned)nfo.regs[2], (unsigned)nfo.regs[3]);
2324 simplelist_addline(SIMPLELIST_ADD_LINE,
2325 "%04X %04X %04X %04X",
2326 (unsigned)nfo.regs[4], (unsigned)nfo.regs[5],
2327 (unsigned)nfo.regs[6], (unsigned)nfo.regs[7]);
2328 simplelist_addline(SIMPLELIST_ADD_LINE,
2329 "%04X %04X %04X %04X",
2330 (unsigned)nfo.regs[8], (unsigned)nfo.regs[9],
2331 (unsigned)nfo.regs[10], (unsigned)nfo.regs[11]);
2332 simplelist_addline(SIMPLELIST_ADD_LINE,
2333 "%04X %04X %04X %04X",
2334 (unsigned)nfo.regs[12], (unsigned)nfo.regs[13],
2335 (unsigned)nfo.regs[14], (unsigned)nfo.regs[15]);
2336 #endif /* SI4700 */
2337 return ACTION_REDRAW;
2339 static bool dbg_fm_radio(void)
2341 struct simplelist_info info;
2342 info.scroll_all = true;
2343 simplelist_info_init(&info, "FM Radio", 1, NULL);
2344 simplelist_set_line_count(0);
2345 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2346 radio_hardware_present() ? "yes" : "no");
2348 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2349 info.hide_selection = true;
2350 return simplelist_show_list(&info);
2352 #endif /* CONFIG_TUNER */
2353 #endif /* !SIMULATOR */
2355 #ifdef HAVE_LCD_BITMAP
2356 extern bool do_screendump_instead_of_usb;
2358 static bool dbg_screendump(void)
2360 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2361 splashf(HZ, "Screendump %s",
2362 do_screendump_instead_of_usb?"enabled":"disabled");
2363 return false;
2365 #endif /* HAVE_LCD_BITMAP */
2367 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2368 static bool dbg_set_memory_guard(void)
2370 static const struct opt_items names[MAXMEMGUARD] = {
2371 { "None", -1 },
2372 { "Flash ROM writes", -1 },
2373 { "Zero area (all)", -1 }
2375 int mode = system_memory_guard(MEMGUARD_KEEP);
2377 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2378 system_memory_guard(mode);
2380 return false;
2382 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2384 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2385 static bool dbg_write_eeprom(void)
2387 int fd;
2388 int rc;
2389 int old_irq_level;
2390 char buf[EEPROM_SIZE];
2391 int err;
2393 fd = open("/internal_eeprom.bin", O_RDONLY);
2395 if (fd >= 0)
2397 rc = read(fd, buf, EEPROM_SIZE);
2399 if(rc == EEPROM_SIZE)
2401 old_irq_level = disable_irq_save();
2403 err = eeprom_24cxx_write(0, buf, sizeof buf);
2404 if (err)
2405 splashf(HZ*3, "Eeprom write failure (%d)", err);
2406 else
2407 splash(HZ*3, "Eeprom written successfully");
2409 restore_irq(old_irq_level);
2411 else
2413 splashf(HZ*3, "File read error (%d)",rc);
2415 close(fd);
2417 else
2419 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2422 return false;
2424 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2425 #ifdef CPU_BOOST_LOGGING
2426 static bool cpu_boost_log(void)
2428 int i = 0,j=0;
2429 int count = cpu_boost_log_getcount();
2430 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2431 char *str;
2432 bool done;
2433 lcd_setfont(FONT_SYSFIXED);
2434 str = cpu_boost_log_getlog_first();
2435 while (i < count)
2437 lcd_clear_display();
2438 for(j=0; j<lines; j++,i++)
2440 if (!str)
2441 str = cpu_boost_log_getlog_next();
2442 if (str)
2444 if(strlen(str) > LCD_WIDTH/SYSFONT_WIDTH)
2445 lcd_puts_scroll(0, j, str);
2446 else
2447 lcd_puts(0, j,str);
2449 str = NULL;
2451 lcd_update();
2452 done = false;
2453 while (!done)
2455 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2457 case ACTION_STD_OK:
2458 case ACTION_STD_PREV:
2459 case ACTION_STD_NEXT:
2460 done = true;
2461 break;
2462 case ACTION_STD_CANCEL:
2463 i = count;
2464 done = true;
2465 break;
2469 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2470 lcd_setfont(FONT_UI);
2471 return false;
2473 #endif
2475 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2476 extern bool wheel_is_touched;
2477 extern int old_wheel_value;
2478 extern int new_wheel_value;
2479 extern int wheel_delta;
2480 extern unsigned int accumulated_wheel_delta;
2481 extern unsigned int wheel_velocity;
2483 static bool dbg_scrollwheel(void)
2485 unsigned int speed;
2487 lcd_setfont(FONT_SYSFIXED);
2489 while (1)
2491 if (action_userabort(HZ/10))
2492 break;
2494 lcd_clear_display();
2496 /* show internal variables of scrollwheel driver */
2497 lcd_putsf(0, 0, "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2498 lcd_putsf(0, 1, "new position: %2d", new_wheel_value);
2499 lcd_putsf(0, 2, "old position: %2d", old_wheel_value);
2500 lcd_putsf(0, 3, "wheel delta: %2d", wheel_delta);
2501 lcd_putsf(0, 4, "accumulated delta: %2d", accumulated_wheel_delta);
2502 lcd_putsf(0, 5, "velo [deg/s]: %4d", (int)wheel_velocity);
2504 /* show effective accelerated scrollspeed */
2505 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2506 lcd_putsf(0, 6, "accel. speed: %4d", speed);
2508 lcd_update();
2510 lcd_setfont(FONT_UI);
2511 return false;
2513 #endif
2515 #if defined (HAVE_USBSTACK)
2517 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2518 static bool toggle_usb_core_driver(int driver, char *msg)
2520 bool enabled = !usb_core_driver_enabled(driver);
2522 usb_core_enable_driver(driver,enabled);
2523 splashf(HZ, "%s %s", msg, enabled?"enabled":"disabled");
2525 return false;
2528 static bool toggle_usb_serial(void)
2530 return toggle_usb_core_driver(USB_DRIVER_SERIAL,"USB Serial");
2532 #endif
2534 #endif
2536 #if CONFIG_USBOTG == USBOTG_ISP1583
2537 extern int dbg_usb_num_items(void);
2538 extern const char* dbg_usb_item(int selected_item, void *data,
2539 char *buffer, size_t buffer_len);
2541 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2543 (void)lists;
2544 if (action == ACTION_NONE)
2545 action = ACTION_REDRAW;
2546 return action;
2549 static bool dbg_isp1583(void)
2551 struct simplelist_info isp1583;
2552 isp1583.scroll_all = true;
2553 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2554 isp1583.timeout = HZ/100;
2555 isp1583.hide_selection = true;
2556 isp1583.get_name = dbg_usb_item;
2557 isp1583.action_callback = isp1583_action_callback;
2558 return simplelist_show_list(&isp1583);
2560 #endif
2562 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2563 extern int pic_dbg_num_items(void);
2564 extern const char* pic_dbg_item(int selected_item, void *data,
2565 char *buffer, size_t buffer_len);
2567 static int pic_action_callback(int action, struct gui_synclist *lists)
2569 (void)lists;
2570 if (action == ACTION_NONE)
2571 action = ACTION_REDRAW;
2572 return action;
2575 static bool dbg_pic(void)
2577 struct simplelist_info pic;
2578 pic.scroll_all = true;
2579 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2580 pic.timeout = HZ/100;
2581 pic.hide_selection = true;
2582 pic.get_name = pic_dbg_item;
2583 pic.action_callback = pic_action_callback;
2584 return simplelist_show_list(&pic);
2586 #endif
2589 /****** The menu *********/
2590 struct the_menu_item {
2591 unsigned char *desc; /* string or ID */
2592 bool (*function) (void); /* return true if USB was connected */
2594 static const struct the_menu_item menuitems[] = {
2595 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2596 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)) || \
2597 CONFIG_CPU == IMX31L || defined(CPU_TCC780X)
2598 { "Dump ROM contents", dbg_save_roms },
2599 #endif
2600 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2601 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 \
2602 || CONFIG_CPU == DM320 || defined(CPU_S5L870X) || CONFIG_CPU == AS3525v2
2603 { "View I/O ports", dbg_ports },
2604 #endif
2605 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2606 { "View PCF registers", dbg_pcf },
2607 #endif
2608 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2609 { "TSC2100 debug", tsc2100_debug },
2610 #endif
2611 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2612 { "CPU frequency", dbg_cpufreq },
2613 #endif
2614 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2615 { "S/PDIF analyzer", dbg_spdif },
2616 #endif
2617 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2618 { "Catch mem accesses", dbg_set_memory_guard },
2619 #endif
2620 { "View OS stacks", dbg_os },
2621 #ifdef HAVE_LCD_BITMAP
2622 #ifndef SIMULATOR
2623 { "View battery", view_battery },
2624 #endif
2625 { "Screendump", dbg_screendump },
2626 #endif
2627 #ifndef SIMULATOR
2628 { "View HW info", dbg_hw_info },
2629 #endif
2630 #ifndef SIMULATOR
2631 { "View partitions", dbg_partitions },
2632 #endif
2633 #ifndef SIMULATOR
2634 { "View disk info", dbg_disk_info },
2635 #if (CONFIG_STORAGE & STORAGE_ATA)
2636 { "Dump ATA identify info", dbg_identify_info},
2637 #endif
2638 #endif
2639 #ifdef HAVE_DIRCACHE
2640 { "View dircache info", dbg_dircache_info },
2641 #endif
2642 #ifdef HAVE_TAGCACHE
2643 { "View database info", dbg_tagcache_info },
2644 #endif
2645 #ifdef HAVE_LCD_BITMAP
2646 #if CONFIG_CODEC == SWCODEC
2647 { "View buffering thread", dbg_buffering_thread },
2648 #elif !defined(SIMULATOR)
2649 { "View audio thread", dbg_audio_thread },
2650 #endif
2651 #ifdef PM_DEBUG
2652 { "pm histogram", peak_meter_histogram},
2653 #endif /* PM_DEBUG */
2654 #endif /* HAVE_LCD_BITMAP */
2655 #ifndef SIMULATOR
2656 #if CONFIG_TUNER
2657 { "FM Radio", dbg_fm_radio },
2658 #endif
2659 #endif
2660 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2661 { "Write back EEPROM", dbg_write_eeprom },
2662 #endif
2663 #if CONFIG_USBOTG == USBOTG_ISP1583
2664 { "View ISP1583 info", dbg_isp1583 },
2665 #endif
2666 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2667 { "View PIC info", dbg_pic },
2668 #endif
2669 #ifdef ROCKBOX_HAS_LOGF
2670 {"Show Log File", logfdisplay },
2671 {"Dump Log File", logfdump },
2672 #endif
2673 #if defined(HAVE_USBSTACK)
2674 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2675 {"USB Serial driver (logf)", toggle_usb_serial },
2676 #endif
2677 #endif /* HAVE_USBSTACK */
2678 #ifdef CPU_BOOST_LOGGING
2679 {"cpu_boost log",cpu_boost_log},
2680 #endif
2681 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2682 {"Debug scrollwheel", dbg_scrollwheel },
2683 #endif
2685 static int menu_action_callback(int btn, struct gui_synclist *lists)
2687 int i;
2688 if (btn == ACTION_STD_OK)
2690 FOR_NB_SCREENS(i)
2691 viewportmanager_theme_enable(i, false, NULL);
2692 menuitems[gui_synclist_get_sel_pos(lists)].function();
2693 btn = ACTION_REDRAW;
2694 FOR_NB_SCREENS(i)
2695 viewportmanager_theme_undo(i, false);
2697 return btn;
2700 static const char* dbg_menu_getname(int item, void * data,
2701 char *buffer, size_t buffer_len)
2703 (void)data; (void)buffer; (void)buffer_len;
2704 return menuitems[item].desc;
2707 bool debug_menu(void)
2709 struct simplelist_info info;
2711 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2712 info.action_callback = menu_action_callback;
2713 info.get_name = dbg_menu_getname;
2714 return simplelist_show_list(&info);