fix touchscreen errors
[kugel-rb.git] / apps / debug_menu.c
blobca069076183f84d71809722453c9a5e302400366
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 "structec.h"
32 #include "action.h"
33 #include "debug.h"
34 #include "thread.h"
35 #include "powermgmt.h"
36 #include "system.h"
37 #include "font.h"
38 #include "audio.h"
39 #include "mp3_playback.h"
40 #include "settings.h"
41 #include "list.h"
42 #include "statusbar.h"
43 #include "dir.h"
44 #include "panic.h"
45 #include "screens.h"
46 #include "misc.h"
47 #include "splash.h"
48 #include "dircache.h"
49 #include "viewport.h"
50 #ifdef HAVE_TAGCACHE
51 #include "tagcache.h"
52 #endif
53 #include "lcd-remote.h"
54 #include "crc32.h"
55 #include "logf.h"
56 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
57 #include "disk.h"
58 #include "adc.h"
59 #include "power.h"
60 #include "usb.h"
61 #include "rtc.h"
62 #include "storage.h"
63 #include "fat.h"
64 #include "mas.h"
65 #include "eeprom_24cxx.h"
66 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
67 #include "sdmmc.h"
68 #endif
69 #if (CONFIG_STORAGE & STORAGE_ATA)
70 #include "ata.h"
71 #endif
72 #if CONFIG_TUNER
73 #include "tuner.h"
74 #include "radio.h"
75 #endif
76 #endif
78 #ifdef HAVE_LCD_BITMAP
79 #include "scrollbar.h"
80 #include "peakmeter.h"
81 #endif
82 #include "logfdisp.h"
83 #if CONFIG_CODEC == SWCODEC
84 #include "pcmbuf.h"
85 #include "buffering.h"
86 #include "playback.h"
87 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
88 #include "spdif.h"
89 #endif
90 #endif
91 #ifdef IRIVER_H300_SERIES
92 #include "pcf50606.h" /* for pcf50606_read */
93 #endif
94 #ifdef IAUDIO_X5
95 #include "ds2411.h"
96 #endif
97 #include "hwcompat.h"
98 #include "button.h"
99 #if CONFIG_RTC == RTC_PCF50605
100 #include "pcf50605.h"
101 #endif
102 #include "appevents.h"
104 #if CONFIG_CPU == DM320 || CONFIG_CPU == S3C2440 || CONFIG_CPU == TCC7801 \
105 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 || CONFIG_CPU == JZ4732 \
106 || defined(CPU_S5L870X) || CONFIG_CPU == AS3525v2
107 #include "debug-target.h"
108 #endif
110 #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) \
111 || (CONFIG_CPU == AS3525 && defined(CONFIG_CHARGING)) \
112 || CONFIG_CPU == AS3525v2
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 #ifdef CPUFREQ_NORMAL
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, i;
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 FOR_NB_SCREENS(i)
304 screens[i].setfont(FONT_SYSFIXED);
306 while(!done)
308 button = get_action(CONTEXT_STD,HZ/5);
309 switch(button)
311 case ACTION_STD_NEXT:
312 audio_next();
313 break;
314 case ACTION_STD_PREV:
315 audio_prev();
316 break;
317 case ACTION_STD_CANCEL:
318 done = true;
319 break;
322 buffering_get_debugdata(&d);
323 bufused = bufsize - pcmbuf_free();
325 FOR_NB_SCREENS(i)
327 line = 0;
328 screens[i].clear_display();
331 screens[i].putsf(0, line++, "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
333 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
334 bufsize, 0, bufused, HORIZONTAL);
335 line++;
337 screens[i].putsf(0, line++, "alloc: %6ld/%ld", audio_filebufused(),
338 (long) filebuflen);
340 #if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
341 if (screens[i].lcdheight > 80)
343 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
344 filebuflen, 0, audio_filebufused(), HORIZONTAL);
345 line++;
347 screens[i].putsf(0, line++, "real: %6ld/%ld", (long)d.buffered_data,
348 (long)filebuflen);
350 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
351 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
352 line++;
354 #endif
356 screens[i].putsf(0, line++, "usefl: %6ld/%ld", (long)(d.useful_data),
357 (long)filebuflen);
359 #if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
360 if (screens[i].lcdheight > 80)
362 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
363 filebuflen, 0, d.useful_data, HORIZONTAL);
364 line++;
366 #endif
368 screens[i].putsf(0, line++, "data_rem: %ld", (long)d.data_rem);
370 screens[i].putsf(0, line++, "track count: %2d", audio_track_count());
372 screens[i].putsf(0, line++, "handle count: %d", (int)d.num_handles);
374 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
375 screens[i].putsf(0, line++, "cpu freq: %3dMHz",
376 (int)((FREQ + 500000) / 1000000));
377 #endif
379 if (ticks > 0)
381 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
382 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
383 screens[i].putsf(0, line++, "boost:%3d.%d%% (%d.%dMHz)",
384 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
387 screens[i].putsf(0, line++, "pcmbufdesc: %2d/%2d",
388 pcmbuf_used_descs(), pcmbufdescs);
389 screens[i].putsf(0, line++, "watermark: %6d",
390 (int)(d.watermark));
392 screens[i].update();
396 tick_remove_task(dbg_audio_task);
398 FOR_NB_SCREENS(i)
399 screens[i].setfont(FONT_UI);
401 return false;
403 #endif /* CONFIG_CODEC */
404 #endif /* HAVE_LCD_BITMAP */
407 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
408 /* Tool function to read the flash manufacturer and type, if available.
409 Only chips which could be reprogrammed in system will return values.
410 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
411 /* In IRAM to avoid problems when running directly from Flash */
412 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
413 unsigned addr1, unsigned addr2)
414 ICODE_ATTR __attribute__((noinline));
415 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
416 unsigned addr1, unsigned addr2)
419 unsigned not_manu, not_id; /* read values before switching to ID mode */
420 unsigned manu, id; /* read values when in ID mode */
422 #if CONFIG_CPU == SH7034
423 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
424 #elif defined(CPU_COLDFIRE)
425 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
426 #endif
427 int old_level; /* saved interrupt level */
429 not_manu = flash[0]; /* read the normal content */
430 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
432 /* disable interrupts, prevent any stray flash access */
433 old_level = disable_irq_save();
435 flash[addr1] = 0xAA; /* enter command mode */
436 flash[addr2] = 0x55;
437 flash[addr1] = 0x90; /* ID command */
438 /* Atmel wants 20ms pause here */
439 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
441 manu = flash[0]; /* read the IDs */
442 id = flash[1];
444 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
445 /* Atmel wants 20ms pause here */
446 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
448 restore_irq(old_level); /* enable interrupts again */
450 /* I assume success if the obtained values are different from
451 the normal flash content. This is not perfectly bulletproof, they
452 could theoretically be the same by chance, causing us to fail. */
453 if (not_manu != manu || not_id != id) /* a value has changed */
455 *p_manufacturer = manu; /* return the results */
456 *p_device = id;
457 return true; /* success */
459 return false; /* fail */
461 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
463 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
464 #ifdef CPU_PP
465 static int perfcheck(void)
467 int result;
469 asm (
470 "mrs r2, CPSR \n"
471 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
472 "msr CPSR_c, r0 \n"
473 "mov %[res], #0 \n"
474 "ldr r0, [%[timr]] \n"
475 "add r0, r0, %[tmo] \n"
476 "1: \n"
477 "add %[res], %[res], #1 \n"
478 "ldr r1, [%[timr]] \n"
479 "cmp r1, r0 \n"
480 "bmi 1b \n"
481 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
483 [res]"=&r"(result)
485 [timr]"r"(&USEC_TIMER),
486 [tmo]"r"(
487 #if CONFIG_CPU == PP5002
488 16000
489 #else /* PP5020/5022/5024 */
490 10226
491 #endif
494 "r0", "r1", "r2"
496 return result;
498 #endif
500 #ifdef HAVE_LCD_BITMAP
501 static bool dbg_hw_info(void)
503 #if CONFIG_CPU == SH7034
504 int bitmask = HW_MASK;
505 int rom_version = ROM_VERSION;
506 unsigned manu, id; /* flash IDs */
507 bool got_id; /* flag if we managed to get the flash IDs */
508 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
509 bool has_bootrom; /* flag for boot ROM present */
510 int oldmode; /* saved memory guard mode */
512 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
514 /* get flash ROM type */
515 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
516 if (!got_id)
517 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
519 /* check if the boot ROM area is a flash mirror */
520 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
521 if (has_bootrom) /* if ROM and Flash different */
523 /* calculate CRC16 checksum of boot ROM */
524 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
527 system_memory_guard(oldmode); /* re-enable memory guard */
529 lcd_setfont(FONT_SYSFIXED);
530 lcd_clear_display();
532 lcd_puts(0, 0, "[Hardware info]");
534 lcd_putsf(0, 1, "ROM: %d.%02d", rom_version/100, rom_version%100);
536 lcd_putsf(0, 2, "Mask: 0x%04x", bitmask);
538 if (got_id)
539 lcd_putsf(0, 3, "Flash: M=%02x D=%02x", manu, id);
540 else
541 lcd_puts(0, 3, "Flash: M=?? D=??"); /* unknown, sorry */
543 if (has_bootrom)
545 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
546 lcd_puts(0, 4, "Boot ROM: V1");
547 else
548 lcd_putsf(0, 4, "ROMcrc: 0x%08x", rom_crc);
550 else
552 lcd_puts(0, 4, "Boot ROM: none");
555 lcd_update();
557 while (!(action_userabort(TIMEOUT_BLOCK)));
559 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
560 unsigned manu, id; /* flash IDs */
561 int got_id; /* flag if we managed to get the flash IDs */
562 int oldmode; /* saved memory guard mode */
563 int line = 0;
565 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
567 /* get flash ROM type */
568 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
569 if (!got_id)
570 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
572 system_memory_guard(oldmode); /* re-enable memory guard */
574 lcd_setfont(FONT_SYSFIXED);
575 lcd_clear_display();
577 lcd_puts(0, line++, "[Hardware info]");
579 if (got_id)
580 lcd_putsf(0, line++, "Flash: M=%04x D=%04x", manu, id);
581 else
582 lcd_puts(0, line++, "Flash: M=???? D=????"); /* unknown, sorry */
584 #ifdef IAUDIO_X5
586 struct ds2411_id id;
588 lcd_puts(0, ++line, "Serial Number:");
590 got_id = ds2411_read_id(&id);
592 if (got_id == DS2411_OK)
594 lcd_putsf(0, ++line, " FC=%02x", (unsigned)id.family_code);
595 lcd_putsf(0, ++line, " ID=%02X %02X %02X %02X %02X %02X",
596 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
597 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
598 lcd_putsf(0, ++line, " CRC=%02X", (unsigned)id.crc);
600 else
602 lcd_putsf(0, ++line, "READ ERR=%d", got_id);
605 #endif
607 lcd_update();
609 while (!(action_userabort(TIMEOUT_BLOCK)));
611 #elif defined(CPU_PP502x)
612 int line = 0;
613 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
614 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
615 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
616 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
618 lcd_setfont(FONT_SYSFIXED);
619 lcd_clear_display();
621 lcd_puts(0, line++, "[Hardware info]");
623 #ifdef IPOD_ARCH
624 lcd_putsf(0, line++, "HW rev: 0x%08lx", IPOD_HW_REVISION);
625 #endif
627 #ifdef IPOD_COLOR
628 extern int lcd_type; /* Defined in lcd-colornano.c */
630 lcd_putsf(0, line++, "LCD type: %d", lcd_type);
631 #endif
633 lcd_putsf(0, line++, "PP version: %s", pp_version);
635 lcd_putsf(0, line++, "Est. clock (kHz): %d", perfcheck());
637 lcd_update();
639 while (!(action_userabort(TIMEOUT_BLOCK)));
641 #elif CONFIG_CPU == PP5002
642 int line = 0;
643 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
644 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
645 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
646 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
649 lcd_setfont(FONT_SYSFIXED);
650 lcd_clear_display();
652 lcd_puts(0, line++, "[Hardware info]");
654 #ifdef IPOD_ARCH
655 lcd_putsf(0, line++, "HW rev: 0x%08lx", IPOD_HW_REVISION);
656 #endif
658 lcd_putsf(0, line++, "PP version: %s", pp_version);
660 lcd_putsf(0, line++, "Est. clock (kHz): %d", perfcheck());
662 lcd_update();
664 while (!(action_userabort(TIMEOUT_BLOCK)));
666 #else
667 /* Define this function in your target tree */
668 return __dbg_hw_info();
669 #endif /* CONFIG_CPU */
670 lcd_setfont(FONT_UI);
671 return false;
673 #else /* !HAVE_LCD_BITMAP */
674 static bool dbg_hw_info(void)
676 int button;
677 int currval = 0;
678 int rom_version = ROM_VERSION;
679 unsigned manu, id; /* flash IDs */
680 bool got_id; /* flag if we managed to get the flash IDs */
681 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
682 bool has_bootrom; /* flag for boot ROM present */
683 int oldmode; /* saved memory guard mode */
685 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
687 /* get flash ROM type */
688 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
689 if (!got_id)
690 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
692 /* check if the boot ROM area is a flash mirror */
693 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
694 if (has_bootrom) /* if ROM and Flash different */
696 /* calculate CRC16 checksum of boot ROM */
697 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
700 system_memory_guard(oldmode); /* re-enable memory guard */
702 lcd_clear_display();
704 lcd_puts(0, 0, "[HW Info]");
705 while(1)
707 switch(currval)
709 case 0:
710 lcd_putsf(0, 1, "ROM: %d.%02d",
711 rom_version/100, rom_version%100);
712 break;
713 case 1:
714 if (got_id)
715 lcd_putsf(0, 1, "Flash:%02x,%02x", manu, id);
716 else
717 lcd_puts(0, 1, "Flash:??,??"); /* unknown, sorry */
718 break;
719 case 2:
720 if (has_bootrom)
722 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
723 lcd_puts(0, 1, "BootROM: V1");
724 else if (rom_crc == 0x358099E8)
725 lcd_puts(0, 1, "BootROM: V2");
726 /* alternative boot ROM found in one single player so far */
727 else
728 lcd_putsf(0, 1, "R: %08x", rom_crc);
730 else
731 lcd_puts(0, 1, "BootROM: no");
734 lcd_update();
736 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
738 switch(button)
740 case ACTION_STD_CANCEL:
741 return false;
743 case ACTION_SETTINGS_DEC:
744 currval--;
745 if(currval < 0)
746 currval = 2;
747 break;
749 case ACTION_SETTINGS_INC:
750 currval++;
751 if(currval > 2)
752 currval = 0;
753 break;
756 return false;
758 #endif /* !HAVE_LCD_BITMAP */
759 #endif /* PLATFORM_NATIVE */
761 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
762 static const char* dbg_partitions_getname(int selected_item, void *data,
763 char *buffer, size_t buffer_len)
765 (void)data;
766 int partition = selected_item/2;
767 struct partinfo* p = disk_partinfo(partition);
768 if (selected_item%2)
770 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / ( 2048 / ( SECTOR_SIZE / 512 )));
772 else
774 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
776 return buffer;
779 bool dbg_partitions(void)
781 struct simplelist_info info;
782 simplelist_info_init(&info, "Partition Info", 4, NULL);
783 info.selection_size = 2;
784 info.hide_selection = true;
785 info.scroll_all = true;
786 info.get_name = dbg_partitions_getname;
787 return simplelist_show_list(&info);
789 #endif /* PLATFORM_NATIVE */
791 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
792 static bool dbg_spdif(void)
794 int line;
795 unsigned int control;
796 int x;
797 char *s;
798 int category;
799 int generation;
800 unsigned int interruptstat;
801 bool valnogood, symbolerr, parityerr;
802 bool done = false;
803 bool spdif_src_on;
804 int spdif_source = spdif_get_output_source(&spdif_src_on);
805 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
807 lcd_clear_display();
808 lcd_setfont(FONT_SYSFIXED);
810 #ifdef HAVE_SPDIF_POWER
811 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
812 #endif
814 while (!done)
816 line = 0;
818 control = EBU1RCVCCHANNEL1;
819 interruptstat = INTERRUPTSTAT;
820 INTERRUPTCLEAR = 0x03c00000;
822 valnogood = (interruptstat & 0x01000000)?true:false;
823 symbolerr = (interruptstat & 0x00800000)?true:false;
824 parityerr = (interruptstat & 0x00400000)?true:false;
826 lcd_putsf(0, line++, "Val: %s Sym: %s Par: %s",
827 valnogood?"--":"OK",
828 symbolerr?"--":"OK",
829 parityerr?"--":"OK");
831 lcd_putsf(0, line++, "Status word: %08x", (int)control);
833 line++;
835 x = control >> 31;
836 lcd_putsf(0, line++, "PRO: %d (%s)",
837 x, x?"Professional":"Consumer");
839 x = (control >> 30) & 1;
840 lcd_putsf(0, line++, "Audio: %d (%s)",
841 x, x?"Non-PCM":"PCM");
843 x = (control >> 29) & 1;
844 lcd_putsf(0, line++, "Copy: %d (%s)",
845 x, x?"Permitted":"Inhibited");
847 x = (control >> 27) & 7;
848 switch(x)
850 case 0:
851 s = "None";
852 break;
853 case 1:
854 s = "50/15us";
855 break;
856 default:
857 s = "Reserved";
858 break;
860 lcd_putsf(0, line++, "Preemphasis: %d (%s)", x, s);
862 x = (control >> 24) & 3;
863 lcd_putsf(0, line++, "Mode: %d", x);
865 category = (control >> 17) & 127;
866 switch(category)
868 case 0x00:
869 s = "General";
870 break;
871 case 0x40:
872 s = "Audio CD";
873 break;
874 default:
875 s = "Unknown";
877 lcd_putsf(0, line++, "Category: 0x%02x (%s)", category, s);
879 x = (control >> 16) & 1;
880 generation = x;
881 if(((category & 0x70) == 0x10) ||
882 ((category & 0x70) == 0x40) ||
883 ((category & 0x78) == 0x38))
885 generation = !generation;
887 lcd_putsf(0, line++, "Generation: %d (%s)",
888 x, generation?"Original":"No ind.");
890 x = (control >> 12) & 15;
891 lcd_putsf(0, line++, "Source: %d", x);
894 x = (control >> 8) & 15;
895 switch(x)
897 case 0:
898 s = "Unspecified";
899 break;
900 case 8:
901 s = "A (Left)";
902 break;
903 case 4:
904 s = "B (Right)";
905 break;
906 default:
907 s = "";
908 break;
910 lcd_putsf(0, line++, "Channel: %d (%s)", x, s);
912 x = (control >> 4) & 15;
913 switch(x)
915 case 0:
916 s = "44.1kHz";
917 break;
918 case 0x4:
919 s = "48kHz";
920 break;
921 case 0xc:
922 s = "32kHz";
923 break;
925 lcd_putsf(0, line++, "Frequency: %d (%s)", x, s);
927 x = (control >> 2) & 3;
928 lcd_putsf(0, line++, "Clock accuracy: %d", x);
929 line++;
931 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
932 lcd_putsf(0, line++, "Measured freq: %ldHz",
933 spdif_measure_frequency());
934 #endif
936 lcd_update();
938 if (action_userabort(HZ/10))
939 break;
942 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
944 #ifdef HAVE_SPDIF_POWER
945 spdif_power_enable(global_settings.spdif_enable);
946 #endif
948 lcd_setfont(FONT_UI);
949 return false;
951 #endif /* CPU_COLDFIRE */
953 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
954 #ifdef HAVE_LCD_BITMAP
955 /* button definitions */
956 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
957 (CONFIG_KEYPAD == IRIVER_H300_PAD)
958 # define DEBUG_CANCEL BUTTON_OFF
960 #elif CONFIG_KEYPAD == RECORDER_PAD
961 # define DEBUG_CANCEL BUTTON_OFF
963 #elif CONFIG_KEYPAD == ONDIO_PAD
964 # define DEBUG_CANCEL BUTTON_MENU
966 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
967 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
968 (CONFIG_KEYPAD == IPOD_4G_PAD)
969 # define DEBUG_CANCEL BUTTON_MENU
971 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
972 # define DEBUG_CANCEL BUTTON_PLAY
974 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
975 # define DEBUG_CANCEL BUTTON_REC
977 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
978 # define DEBUG_CANCEL BUTTON_RC_REC
980 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
981 # define DEBUG_CANCEL BUTTON_REW
983 #elif (CONFIG_KEYPAD == MROBE100_PAD)
984 # define DEBUG_CANCEL BUTTON_MENU
986 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
987 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
988 (CONFIG_KEYPAD == SANSA_FUZE_PAD)
989 # define DEBUG_CANCEL BUTTON_LEFT
991 /* This is temporary until the SA9200 touchpad works */
992 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) || \
993 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD) || \
994 (CONFIG_KEYPAD == PHILIPS_HDD6330_PAD)
995 # define DEBUG_CANCEL BUTTON_POWER
997 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
998 # define DEBUG_CANCEL BUTTON_PLAY
1000 #elif (CONFIG_KEYPAD == PBELL_VIBE500_PAD)
1001 # define DEBUG_CANCEL BUTTON_CANCEL
1003 #elif (CONFIG_KEYPAD == MPIO_HD200_PAD)
1004 # define DEBUG_CANCEL BUTTON_REC
1006 #endif /* key definitions */
1008 /* Test code!!! */
1009 bool dbg_ports(void)
1011 #if CONFIG_CPU == SH7034
1012 int adc_battery_voltage, adc_battery_level;
1014 lcd_setfont(FONT_SYSFIXED);
1015 lcd_clear_display();
1017 while(1)
1019 lcd_putsf(0, 0, "PADR: %04x", (unsigned short)PADR);
1020 lcd_putsf(0, 1, "PBDR: %04x", (unsigned short)PBDR);
1022 lcd_putsf(0, 2, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1023 lcd_putsf(0, 3, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1024 lcd_putsf(0, 4, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1025 lcd_putsf(0, 5, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1027 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1028 lcd_putsf(0, 6, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1029 adc_battery_voltage % 1000, adc_battery_level);
1031 lcd_update();
1032 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1034 lcd_setfont(FONT_UI);
1035 return false;
1038 #elif defined(CPU_COLDFIRE)
1039 unsigned int gpio_out;
1040 unsigned int gpio1_out;
1041 unsigned int gpio_read;
1042 unsigned int gpio1_read;
1043 unsigned int gpio_function;
1044 unsigned int gpio1_function;
1045 unsigned int gpio_enable;
1046 unsigned int gpio1_enable;
1047 int adc_buttons, adc_remote;
1048 int adc_battery_voltage, adc_battery_level;
1049 int line;
1051 lcd_clear_display();
1052 lcd_setfont(FONT_SYSFIXED);
1054 while(1)
1056 line = 0;
1057 gpio_read = GPIO_READ;
1058 gpio1_read = GPIO1_READ;
1059 gpio_out = GPIO_OUT;
1060 gpio1_out = GPIO1_OUT;
1061 gpio_function = GPIO_FUNCTION;
1062 gpio1_function = GPIO1_FUNCTION;
1063 gpio_enable = GPIO_ENABLE;
1064 gpio1_enable = GPIO1_ENABLE;
1066 lcd_putsf(0, line++, "GPIO_READ: %08x", gpio_read);
1067 lcd_putsf(0, line++, "GPIO_OUT: %08x", gpio_out);
1068 lcd_putsf(0, line++, "GPIO_FUNC: %08x", gpio_function);
1069 lcd_putsf(0, line++, "GPIO_ENA: %08x", gpio_enable);
1071 lcd_putsf(0, line++, "GPIO1_READ: %08x", gpio1_read);
1072 lcd_putsf(0, line++, "GPIO1_OUT: %08x", gpio1_out);
1073 lcd_putsf(0, line++, "GPIO1_FUNC: %08x", gpio1_function);
1074 lcd_putsf(0, line++, "GPIO1_ENA: %08x", gpio1_enable);
1076 adc_buttons = adc_read(ADC_BUTTONS);
1077 adc_remote = adc_read(ADC_REMOTE);
1078 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1079 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1080 lcd_putsf(0, line++, "ADC_BUTTONS (%c): %02x",
1081 button_scan_enabled() ? '+' : '-', adc_buttons);
1082 #else
1083 lcd_putsf(0, line++, "ADC_BUTTONS: %02x", adc_buttons);
1084 #endif
1085 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1086 lcd_putsf(0, line++, "ADC_REMOTE (%c): %02x",
1087 remote_detect() ? '+' : '-', adc_remote);
1088 #else
1089 lcd_putsf(0, line++, "ADC_REMOTE: %02x", adc_remote);
1090 #endif
1091 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1092 lcd_putsf(0, line++, "ADC_REMOTEDETECT: %02x",
1093 adc_read(ADC_REMOTEDETECT));
1094 #endif
1096 lcd_putsf(0, line++, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1097 adc_battery_voltage % 1000, adc_battery_level);
1099 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1100 lcd_putsf(0, line++, "remotetype: %d", remote_type());
1101 #endif
1103 lcd_update();
1104 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1106 lcd_setfont(FONT_UI);
1107 return false;
1111 #elif defined(CPU_PP502x)
1112 int line;
1114 lcd_clear_display();
1115 lcd_setfont(FONT_SYSFIXED);
1117 while(1)
1119 line = 0;
1120 #if (LCD_HEIGHT >= 176) /* Only for displays with appropriate height. */
1121 lcd_puts(0, line++, "GPIO ENABLE: GPIO OUTPUT ENABLE:");
1122 lcd_putsf(0, line++, "A: %02x E: %02x I: %02x A: %02x E: %02x I: %02x",
1123 (unsigned int)GPIOA_ENABLE,
1124 (unsigned int)GPIOE_ENABLE,
1125 (unsigned int)GPIOI_ENABLE,
1126 (unsigned int)GPIOA_OUTPUT_EN,
1127 (unsigned int)GPIOE_OUTPUT_EN,
1128 (unsigned int)GPIOI_OUTPUT_EN);
1129 lcd_putsf(0, line++, "B: %02x F: %02x J: %02x B: %02x F: %02x J: %02x",
1130 (unsigned int)GPIOB_ENABLE,
1131 (unsigned int)GPIOF_ENABLE,
1132 (unsigned int)GPIOJ_ENABLE,
1133 (unsigned int)GPIOB_OUTPUT_EN,
1134 (unsigned int)GPIOF_OUTPUT_EN,
1135 (unsigned int)GPIOJ_OUTPUT_EN);
1136 lcd_putsf(0, line++, "C: %02x G: %02x K: %02x C: %02x G: %02x K: %02x",
1137 (unsigned int)GPIOC_ENABLE,
1138 (unsigned int)GPIOG_ENABLE,
1139 (unsigned int)GPIOK_ENABLE,
1140 (unsigned int)GPIOC_OUTPUT_EN,
1141 (unsigned int)GPIOG_OUTPUT_EN,
1142 (unsigned int)GPIOK_OUTPUT_EN);
1143 lcd_putsf(0, line++, "D: %02x H: %02x L: %02x D: %02x H: %02x L: %02x",
1144 (unsigned int)GPIOD_ENABLE,
1145 (unsigned int)GPIOH_ENABLE,
1146 (unsigned int)GPIOL_ENABLE,
1147 (unsigned int)GPIOD_OUTPUT_EN,
1148 (unsigned int)GPIOH_OUTPUT_EN,
1149 (unsigned int)GPIOL_OUTPUT_EN);
1150 line++;
1151 #endif
1152 lcd_puts(0, line++, "GPIO INPUT VAL:");
1153 lcd_putsf(0, line++, "A: %02x E: %02x I: %02x",
1154 (unsigned int)GPIOA_INPUT_VAL,
1155 (unsigned int)GPIOE_INPUT_VAL,
1156 (unsigned int)GPIOI_INPUT_VAL);
1157 lcd_putsf(0, line++, "B: %02x F: %02x J: %02x",
1158 (unsigned int)GPIOB_INPUT_VAL,
1159 (unsigned int)GPIOF_INPUT_VAL,
1160 (unsigned int)GPIOJ_INPUT_VAL);
1161 lcd_putsf(0, line++, "C: %02x G: %02x K: %02x",
1162 (unsigned int)GPIOC_INPUT_VAL,
1163 (unsigned int)GPIOG_INPUT_VAL,
1164 (unsigned int)GPIOK_INPUT_VAL);
1165 lcd_putsf(0, line++, "D: %02x H: %02x L: %02x",
1166 (unsigned int)GPIOD_INPUT_VAL,
1167 (unsigned int)GPIOH_INPUT_VAL,
1168 (unsigned int)GPIOL_INPUT_VAL);
1169 line++;
1170 lcd_putsf(0, line++, "GPO32_VAL: %08lx", GPO32_VAL);
1171 lcd_putsf(0, line++, "GPO32_EN: %08lx", GPO32_ENABLE);
1172 lcd_putsf(0, line++, "DEV_EN: %08lx", DEV_EN);
1173 lcd_putsf(0, line++, "DEV_EN2: %08lx", DEV_EN2);
1174 lcd_putsf(0, line++, "DEV_EN3: %08lx", inl(0x60006044)); /* to be verified */
1175 lcd_putsf(0, line++, "DEV_INIT1: %08lx", DEV_INIT1);
1176 lcd_putsf(0, line++, "DEV_INIT2: %08lx", DEV_INIT2);
1177 #ifdef ADC_ACCESSORY
1178 lcd_putsf(0, line++, "ACCESSORY: %d", adc_read(ADC_ACCESSORY));
1179 #endif
1180 #ifdef IPOD_VIDEO
1181 lcd_putsf(0, line++, "4066_ISTAT: %d", adc_read(ADC_4066_ISTAT));
1182 #endif
1184 #if defined(IPOD_ACCESSORY_PROTOCOL)
1185 extern unsigned char serbuf[];
1186 lcd_putsf(0, line++, "IAP PACKET: %02x %02x %02x %02x %02x %02x %02x %02x",
1187 serbuf[0], serbuf[1], serbuf[2], serbuf[3], serbuf[4], serbuf[5],
1188 serbuf[6], serbuf[7]);
1189 #endif
1191 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1192 line++;
1193 lcd_putsf(0, line++, "BATT: %03x UNK1: %03x",
1194 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1195 lcd_putsf(0, line++, "REM: %03x PAD: %03x",
1196 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1197 #elif defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330)
1198 line++;
1199 lcd_putsf(0, line++, "BATT: %03x UNK1: %03x",
1200 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1201 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1202 lcd_putsf(0, line++, "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1203 lcd_putsf(0, line++, "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1204 lcd_putsf(0, line++, "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1205 lcd_putsf(0, line++, "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1206 lcd_putsf(0, line++, "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1207 lcd_putsf(0, line++, "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1208 lcd_putsf(0, line++, "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1209 lcd_putsf(0, line++, "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1210 lcd_putsf(0, line++, "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1211 lcd_putsf(0, line++, "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1212 lcd_putsf(0, line++, "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1213 #if !defined(PHILIPS_SA9200)
1214 lcd_putsf(0, line++, "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1215 lcd_putsf(0, line++, "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1216 #endif
1217 #endif
1218 lcd_update();
1219 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1221 lcd_setfont(FONT_UI);
1222 return false;
1226 #elif CONFIG_CPU == PP5002
1227 int line;
1229 lcd_clear_display();
1230 lcd_setfont(FONT_SYSFIXED);
1232 while(1)
1234 line = 0;
1235 lcd_putsf(0, line++, "GPIO_A: %02x GPIO_B: %02x",
1236 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1237 lcd_putsf(0, line++, "GPIO_C: %02x GPIO_D: %02x",
1238 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1240 lcd_putsf(0, line++, "DEV_EN: %08lx", DEV_EN);
1241 lcd_putsf(0, line++, "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1242 lcd_putsf(0, line++, "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1243 lcd_putsf(0, line++, "PLL_CONTROL: %08lx", PLL_CONTROL);
1244 lcd_putsf(0, line++, "PLL_DIV: %08lx", PLL_DIV);
1245 lcd_putsf(0, line++, "PLL_MULT: %08lx", PLL_MULT);
1246 lcd_putsf(0, line++, "TIMING1_CTL: %08lx", TIMING1_CTL);
1247 lcd_putsf(0, line++, "TIMING2_CTL: %08lx", TIMING2_CTL);
1249 lcd_update();
1250 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1252 lcd_setfont(FONT_UI);
1253 return false;
1256 lcd_setfont(FONT_UI);
1257 #else
1258 return __dbg_ports();
1259 #endif /* CPU */
1260 return false;
1262 #else /* !HAVE_LCD_BITMAP */
1263 bool dbg_ports(void)
1265 char buf[32];
1266 int button;
1267 int adc_battery_voltage;
1268 int currval = 0;
1270 lcd_clear_display();
1272 while(1)
1274 switch(currval)
1276 case 0:
1277 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1278 break;
1279 case 1:
1280 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1281 break;
1282 case 2:
1283 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1284 break;
1285 case 3:
1286 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1287 break;
1288 case 4:
1289 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1290 break;
1291 case 5:
1292 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1293 break;
1294 case 6:
1295 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1296 break;
1297 case 7:
1298 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1299 break;
1300 case 8:
1301 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1302 break;
1303 case 9:
1304 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1305 break;
1307 lcd_puts(0, 0, buf);
1309 battery_read_info(&adc_battery_voltage, NULL);
1310 lcd_putsf(0, 1, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1311 adc_battery_voltage % 1000);
1312 lcd_update();
1314 button = get_action(CONTEXT_SETTINGS,HZ/5);
1316 switch(button)
1318 case ACTION_STD_CANCEL:
1319 return false;
1321 case ACTION_SETTINGS_DEC:
1322 currval--;
1323 if(currval < 0)
1324 currval = 9;
1325 break;
1327 case ACTION_SETTINGS_INC:
1328 currval++;
1329 if(currval > 9)
1330 currval = 0;
1331 break;
1334 return false;
1336 #endif /* !HAVE_LCD_BITMAP */
1337 #endif /* PLATFORM_NATIVE */
1339 #if (CONFIG_RTC == RTC_PCF50605) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
1340 static bool dbg_pcf(void)
1342 int line;
1344 #ifdef HAVE_LCD_BITMAP
1345 lcd_setfont(FONT_SYSFIXED);
1346 #endif
1347 lcd_clear_display();
1349 while(1)
1351 line = 0;
1353 lcd_putsf(0, line++, "DCDC1: %02x", pcf50605_read(0x1b));
1354 lcd_putsf(0, line++, "DCDC2: %02x", pcf50605_read(0x1c));
1355 lcd_putsf(0, line++, "DCDC3: %02x", pcf50605_read(0x1d));
1356 lcd_putsf(0, line++, "DCDC4: %02x", pcf50605_read(0x1e));
1357 lcd_putsf(0, line++, "DCDEC1: %02x", pcf50605_read(0x1f));
1358 lcd_putsf(0, line++, "DCDEC2: %02x", pcf50605_read(0x20));
1359 lcd_putsf(0, line++, "DCUDC1: %02x", pcf50605_read(0x21));
1360 lcd_putsf(0, line++, "DCUDC2: %02x", pcf50605_read(0x22));
1361 lcd_putsf(0, line++, "IOREGC: %02x", pcf50605_read(0x23));
1362 lcd_putsf(0, line++, "D1REGC: %02x", pcf50605_read(0x24));
1363 lcd_putsf(0, line++, "D2REGC: %02x", pcf50605_read(0x25));
1364 lcd_putsf(0, line++, "D3REGC: %02x", pcf50605_read(0x26));
1365 lcd_putsf(0, line++, "LPREG1: %02x", pcf50605_read(0x27));
1366 lcd_update();
1367 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1369 lcd_setfont(FONT_UI);
1370 return false;
1374 lcd_setfont(FONT_UI);
1375 return false;
1377 #endif
1379 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1380 static bool dbg_cpufreq(void)
1382 int line;
1383 int button;
1385 #ifdef HAVE_LCD_BITMAP
1386 lcd_setfont(FONT_SYSFIXED);
1387 #endif
1388 lcd_clear_display();
1390 while(1)
1392 line = 0;
1394 lcd_putsf(0, line++, "Frequency: %ld", FREQ);
1395 lcd_putsf(0, line++, "boost_counter: %d", get_cpu_boost_counter());
1397 lcd_update();
1398 button = get_action(CONTEXT_STD,HZ/10);
1400 switch(button)
1402 case ACTION_STD_PREV:
1403 cpu_boost(true);
1404 break;
1406 case ACTION_STD_NEXT:
1407 cpu_boost(false);
1408 break;
1410 case ACTION_STD_OK:
1411 while (get_cpu_boost_counter() > 0)
1412 cpu_boost(false);
1413 set_cpu_frequency(CPUFREQ_DEFAULT);
1414 break;
1416 case ACTION_STD_CANCEL:
1417 lcd_setfont(FONT_UI);
1418 return false;
1421 lcd_setfont(FONT_UI);
1422 return false;
1424 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1426 #if defined(HAVE_TSC2100) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
1427 #include "tsc2100.h"
1428 static char *itob(int n, int len)
1430 static char binary[64];
1431 int i,j;
1432 for (i=1, j=0;i<=len;i++)
1434 binary[j++] = n&(1<<(len-i))?'1':'0';
1435 if (i%4 == 0)
1436 binary[j++] = ' ';
1438 binary[j] = '\0';
1439 return binary;
1442 static const char* tsc2100_debug_getname(int selected_item, void * data,
1443 char *buffer, size_t buffer_len)
1445 int *page = (int*)data;
1446 bool reserved = false;
1447 switch (*page)
1449 case 0:
1450 if ((selected_item > 0x0a) ||
1451 (selected_item == 0x04) ||
1452 (selected_item == 0x08))
1453 reserved = true;
1454 break;
1455 case 1:
1456 if ((selected_item > 0x05) ||
1457 (selected_item == 0x02))
1458 reserved = true;
1459 break;
1460 case 2:
1461 if (selected_item > 0x1e)
1462 reserved = true;
1463 break;
1465 if (reserved)
1466 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1467 else
1468 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1469 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1470 return buffer;
1472 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1474 int *page = (int*)lists->data;
1475 if (action == ACTION_STD_OK)
1477 *page = (*page+1)%3;
1478 snprintf(lists->title, 32,
1479 "tsc2100 registers - Page %d", *page);
1480 return ACTION_REDRAW;
1482 return action;
1484 static bool tsc2100_debug(void)
1486 int page = 0;
1487 char title[32] = "tsc2100 registers - Page 0";
1488 struct simplelist_info info;
1489 simplelist_info_init(&info, title, 32, &page);
1490 info.timeout = HZ/100;
1491 info.get_name = tsc2100_debug_getname;
1492 info.action_callback= tsc2100debug_action_callback;
1493 return simplelist_show_list(&info);
1495 #endif
1496 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
1497 #ifdef HAVE_LCD_BITMAP
1499 * view_battery() shows a automatically scaled graph of the battery voltage
1500 * over time. Usable for estimating battery life / charging rate.
1501 * The power_history array is updated in power_thread of powermgmt.c.
1504 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1505 #define BAT_YSPACE (LCD_HEIGHT - 20)
1508 static bool view_battery(void)
1510 int view = 0;
1511 int i, x, y, y1, y2, grid, graph;
1512 unsigned short maxv, minv;
1514 lcd_setfont(FONT_SYSFIXED);
1516 while(1)
1518 lcd_clear_display();
1519 switch (view) {
1520 case 0: /* voltage history graph */
1521 /* Find maximum and minimum voltage for scaling */
1522 minv = power_history[0];
1523 maxv = minv + 1;
1524 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1525 if (power_history[i] > maxv)
1526 maxv = power_history[i];
1527 if (power_history[i] < minv)
1528 minv = power_history[i];
1531 /* adjust grid scale */
1532 if ((maxv - minv) > 50)
1533 grid = 50;
1534 else
1535 grid = 5;
1537 /* print header */
1538 lcd_putsf(0, 0, "battery %d.%03dV", power_history[0] / 1000,
1539 power_history[0] % 1000);
1540 lcd_putsf(0, 1, "%d.%03d-%d.%03dV (%2dmV)",
1541 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000,
1542 grid);
1544 i = 1;
1545 while ((y = (minv - (minv % grid)+i*grid)) < maxv)
1547 graph = ((y-minv)*BAT_YSPACE)/(maxv-minv);
1548 graph = LCD_HEIGHT-1 - graph;
1550 /* draw dotted horizontal grid line */
1551 for (x=0; x<LCD_WIDTH;x=x+2)
1552 lcd_drawpixel(x,graph);
1554 i++;
1557 x = 0;
1558 /* draw plot of power history
1559 * skip empty entries
1561 for (i = BAT_LAST_VAL - 1; i > 0; i--)
1563 if (power_history[i] && power_history[i-1])
1565 y1 = (power_history[i] - minv) * BAT_YSPACE /
1566 (maxv - minv);
1567 y1 = MIN(MAX(LCD_HEIGHT-1 - y1, 20),
1568 LCD_HEIGHT-1);
1569 y2 = (power_history[i-1] - minv) * BAT_YSPACE /
1570 (maxv - minv);
1571 y2 = MIN(MAX(LCD_HEIGHT-1 - y2, 20),
1572 LCD_HEIGHT-1);
1574 lcd_set_drawmode(DRMODE_SOLID);
1576 /* make line thicker */
1577 lcd_drawline(((x*LCD_WIDTH)/(BAT_LAST_VAL)),
1578 y1,
1579 (((x+1)*LCD_WIDTH)/(BAT_LAST_VAL)),
1580 y2);
1581 lcd_drawline(((x*LCD_WIDTH)/(BAT_LAST_VAL))+1,
1582 y1+1,
1583 (((x+1)*LCD_WIDTH)/(BAT_LAST_VAL))+1,
1584 y2+1);
1585 x++;
1588 break;
1590 case 1: /* status: */
1591 #if CONFIG_CHARGING >= CHARGING_MONITOR
1592 lcd_putsf(0, 0, "Pwr status: %s",
1593 charging_state() ? "charging" : "discharging");
1594 #else
1595 lcd_puts(0, 0, "Power status:");
1596 #endif
1597 battery_read_info(&y, NULL);
1598 lcd_putsf(0, 1, "Battery: %d.%03d V", y / 1000, y % 1000);
1599 #ifdef ADC_EXT_POWER
1600 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1601 lcd_putsf(0, 2, "External: %d.%03d V", y / 1000, y % 1000);
1602 #endif
1603 #if CONFIG_CHARGING
1604 #if defined ARCHOS_RECORDER
1605 lcd_putsf(0, 3, "Chgr: %s %s",
1606 charger_inserted() ? "present" : "absent",
1607 charger_enabled() ? "on" : "off");
1608 lcd_putsf(0, 5, "short delta: %d", short_delta);
1609 lcd_putsf(0, 6, "long delta: %d", long_delta);
1610 lcd_puts(0, 7, power_message);
1611 lcd_putsf(0, 8, "USB Inserted: %s",
1612 usb_inserted() ? "yes" : "no");
1613 #elif defined IPOD_NANO || defined IPOD_VIDEO
1614 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1615 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1616 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1617 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1618 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1620 lcd_putsf(0, 3, "USB pwr: %s",
1621 usb_pwr ? "present" : "absent");
1622 lcd_putsf(0, 4, "EXT pwr: %s",
1623 ext_pwr ? "present" : "absent");
1624 lcd_putsf(0, 5, "Battery: %s",
1625 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1626 lcd_putsf(0, 6, "Dock mode: %s",
1627 dock ? "enabled" : "disabled");
1628 lcd_putsf(0, 7, "Headphone: %s",
1629 headphone ? "connected" : "disconnected");
1630 #ifdef IPOD_VIDEO
1631 x = (adc_read(ADC_4066_ISTAT) * 2400) /
1632 #if MEM == 64
1633 (1024 * 2);
1634 #else
1635 (1024 * 3);
1636 #endif
1637 lcd_putsf(0, 8, "Ibat: %d mA", x);
1638 lcd_putsf(0, 9, "Vbat * Ibat: %d mW", x * y / 1000);
1639 #endif
1640 #elif defined TOSHIBA_GIGABEAT_S
1641 int line = 3;
1642 unsigned int st;
1644 static const unsigned char * const chrgstate_strings[] =
1646 "Disabled",
1647 "Error",
1648 "Discharging",
1649 "Precharge",
1650 "Constant Voltage",
1651 "Constant Current",
1652 "<unknown>",
1655 lcd_putsf(0, line++, "Charger: %s",
1656 charger_inserted() ? "present" : "absent");
1658 st = power_input_status() &
1659 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1660 lcd_putsf(0, line++, "%s%s",
1661 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1662 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1664 y = ARRAYLEN(chrgstate_strings) - 1;
1666 switch (charge_state)
1668 case CHARGE_STATE_DISABLED: y--;
1669 case CHARGE_STATE_ERROR: y--;
1670 case DISCHARGING: y--;
1671 case TRICKLE: y--;
1672 case TOPOFF: y--;
1673 case CHARGING: y--;
1674 default:;
1677 lcd_putsf(0, line++, "State: %s", chrgstate_strings[y]);
1679 lcd_putsf(0, line++, "Battery Switch: %s",
1680 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1682 y = chrgraw_adc_voltage();
1683 lcd_putsf(0, line++, "CHRGRAW: %d.%03d V",
1684 y / 1000, y % 1000);
1686 y = application_supply_adc_voltage();
1687 lcd_putsf(0, line++, "BP : %d.%03d V",
1688 y / 1000, y % 1000);
1690 y = battery_adc_charge_current();
1691 if (y < 0) x = '-', y = -y;
1692 else x = ' ';
1693 lcd_putsf(0, line++, "CHRGISN:%c%d mA", x, y);
1695 y = cccv_regulator_dissipation();
1696 lcd_putsf(0, line++, "P CCCV : %d mW", y);
1698 y = battery_charge_current();
1699 if (y < 0) x = '-', y = -y;
1700 else x = ' ';
1701 lcd_putsf(0, line++, "I Charge:%c%d mA", x, y);
1703 y = battery_adc_temp();
1705 if (y != INT_MIN) {
1706 lcd_putsf(0, line++, "T Battery: %dC (%dF)", y,
1707 (9*y + 160) / 5);
1708 } else {
1709 /* Conversion disabled */
1710 lcd_puts(0, line++, "T Battery: ?");
1713 #elif defined(SANSA_E200) || defined(SANSA_C200) || CONFIG_CPU == AS3525 || \
1714 CONFIG_CPU == AS3525v2
1715 static const char * const chrgstate_strings[] =
1717 [CHARGE_STATE_DISABLED - CHARGE_STATE_DISABLED]= "Disabled",
1718 [CHARGE_STATE_ERROR - CHARGE_STATE_DISABLED] = "Error",
1719 [DISCHARGING - CHARGE_STATE_DISABLED] = "Discharging",
1720 [CHARGING - CHARGE_STATE_DISABLED] = "Charging",
1722 const char *str = NULL;
1724 lcd_putsf(0, 3, "Charger: %s",
1725 charger_inserted() ? "present" : "absent");
1727 y = charge_state - CHARGE_STATE_DISABLED;
1728 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1729 str = chrgstate_strings[y];
1731 lcd_putsf(0, 4, "State: %s",
1732 str ? str : "<unknown>");
1734 lcd_putsf(0, 5, "CHARGER: %02X", ascodec_read_charger());
1735 #elif defined(IPOD_NANO2G)
1736 y = pmu_read_battery_voltage();
1737 lcd_putsf(17, 1, "RAW: %d.%03d V", y / 1000, y % 1000);
1738 y = pmu_read_battery_current();
1739 lcd_putsf(0, 2, "Battery current: %d mA", y);
1740 lcd_putsf(0, 3, "PWRCON: %8x", PWRCON);
1741 lcd_putsf(0, 4, "PWRCONEXT: %8x", PWRCONEXT);
1742 x = pmu_read(0x1b) & 0xf;
1743 y = pmu_read(0x1a) * 25 + 625;
1744 lcd_putsf(0, 5, "AUTO: %x / %d mV", x, y);
1745 x = pmu_read(0x1f) & 0xf;
1746 y = pmu_read(0x1e) * 25 + 625;
1747 lcd_putsf(0, 6, "DOWN1: %x / %d mV", x, y);
1748 x = pmu_read(0x23) & 0xf;
1749 y = pmu_read(0x22) * 25 + 625;
1750 lcd_putsf(0, 7, "DOWN2: %x / %d mV", x, y);
1751 x = pmu_read(0x27) & 0xf;
1752 y = pmu_read(0x26) * 100 + 900;
1753 lcd_putsf(0, 8, "MEMLDO: %x / %d mV", x, y);
1754 for (i = 0; i < 6; i++)
1756 x = pmu_read(0x2e + (i << 1)) & 0xf;
1757 y = pmu_read(0x2d + (i << 1)) * 100 + 900;
1758 lcd_putsf(0, 9 + i, "LDO%d: %x / %d mV", i + 1, x, y);
1760 lcd_putsf(0, 15, "CLKCON: %8x", CLKCON);
1761 lcd_putsf(17, 15, "PLL0: %6x", PLL0PMS);
1762 #else
1763 lcd_putsf(0, 3, "Charger: %s",
1764 charger_inserted() ? "present" : "absent");
1765 #endif /* target type */
1766 #endif /* CONFIG_CHARGING */
1767 break;
1769 case 2: /* voltage deltas: */
1770 lcd_puts(0, 0, "Voltage deltas:");
1772 for (i = 0; i <= 6; i++) {
1773 y = power_history[i] - power_history[i+1];
1774 lcd_putsf(0, i+1, "-%d min: %s%d.%03d V", i,
1775 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1776 ((y < 0) ? y * -1 : y ) % 1000);
1778 break;
1780 case 3: /* remaining time estimation: */
1782 #ifdef ARCHOS_RECORDER
1783 lcd_putsf(0, 0, "charge_state: %d", charge_state);
1785 lcd_putsf(0, 1, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1787 lcd_putsf(0, 2, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1789 lcd_putsf(0, 3, "P=%2d I=%2d", pid_p, pid_i);
1791 lcd_putsf(0, 4, "Trickle sec: %d/60", trickle_sec);
1792 #endif /* ARCHOS_RECORDER */
1794 lcd_putsf(0, 5, "Last PwrHist: %d.%03dV",
1795 power_history[0] / 1000,
1796 power_history[0] % 1000);
1798 lcd_putsf(0, 6, "battery level: %d%%", battery_level());
1800 lcd_putsf(0, 7, "Est. remain: %d m", battery_time());
1801 break;
1804 lcd_update();
1806 switch(get_action(CONTEXT_STD,HZ/2))
1808 case ACTION_STD_PREV:
1809 if (view)
1810 view--;
1811 break;
1813 case ACTION_STD_NEXT:
1814 if (view < 3)
1815 view++;
1816 break;
1818 case ACTION_STD_CANCEL:
1819 lcd_setfont(FONT_UI);
1820 return false;
1823 lcd_setfont(FONT_UI);
1824 return false;
1827 #endif /* HAVE_LCD_BITMAP */
1828 #endif
1830 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
1831 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1833 #if (CONFIG_STORAGE & STORAGE_MMC)
1834 #define CARDTYPE "MMC"
1835 #elif (CONFIG_STORAGE & STORAGE_SD)
1836 #define CARDTYPE "microSD"
1837 #endif
1839 static int disk_callback(int btn, struct gui_synclist *lists)
1841 tCardInfo *card;
1842 int *cardnum = (int*)lists->data;
1843 unsigned char card_name[6];
1844 unsigned char pbuf[32];
1845 char *title = lists->title;
1846 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1847 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1848 static const unsigned char * const kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1849 static const unsigned char * const nsec_units[] = { "ns", "µs", "ms" };
1850 #if (CONFIG_STORAGE & STORAGE_MMC)
1851 static const char * const mmc_spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1852 "3.1-3.31", "4.0" };
1853 #endif
1855 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1857 #ifdef HAVE_HOTSWAP
1858 if (btn == ACTION_STD_OK)
1860 *cardnum ^= 0x1; /* change cards */
1862 #endif
1864 simplelist_set_line_count(0);
1866 card = card_get_info(*cardnum);
1868 if (card->initialized > 0)
1870 unsigned i;
1871 for (i=0; i<sizeof(card_name); i++)
1873 card_name[i] = card_extract_bits(card->cid, (103-8*i), 8);
1875 strlcpy(card_name, card_name, sizeof(card_name));
1876 simplelist_addline(SIMPLELIST_ADD_LINE,
1877 "%s Rev %d.%d", card_name,
1878 (int) card_extract_bits(card->cid, 63, 4),
1879 (int) card_extract_bits(card->cid, 59, 4));
1880 simplelist_addline(SIMPLELIST_ADD_LINE,
1881 "Prod: %d/%d",
1882 #if (CONFIG_STORAGE & STORAGE_SD)
1883 (int) card_extract_bits(card->cid, 11, 4),
1884 (int) card_extract_bits(card->cid, 19, 8) + 2000
1885 #elif (CONFIG_STORAGE & STORAGE_MMC)
1886 (int) card_extract_bits(card->cid, 15, 4),
1887 (int) card_extract_bits(card->cid, 11, 4) + 1997
1888 #endif
1890 simplelist_addline(SIMPLELIST_ADD_LINE,
1891 #if (CONFIG_STORAGE & STORAGE_SD)
1892 "Ser#: 0x%08lx",
1893 card_extract_bits(card->cid, 55, 32)
1894 #elif (CONFIG_STORAGE & STORAGE_MMC)
1895 "Ser#: 0x%04lx",
1896 card_extract_bits(card->cid, 47, 16)
1897 #endif
1900 simplelist_addline(SIMPLELIST_ADD_LINE, "M=%02x, "
1901 #if (CONFIG_STORAGE & STORAGE_SD)
1902 "O=%c%c",
1903 (int) card_extract_bits(card->cid, 127, 8),
1904 card_extract_bits(card->cid, 119, 8),
1905 card_extract_bits(card->cid, 111, 8)
1906 #elif (CONFIG_STORAGE & STORAGE_MMC)
1907 "O=%04x",
1908 (int) card_extract_bits(card->cid, 127, 8),
1909 (int) card_extract_bits(card->cid, 119, 16)
1910 #endif
1913 #if (CONFIG_STORAGE & STORAGE_MMC)
1914 int temp = card_extract_bits(card->csd, 125, 4);
1915 simplelist_addline(SIMPLELIST_ADD_LINE,
1916 "MMC v%s", temp < 5 ?
1917 mmc_spec_vers[temp] : "?.?");
1918 #endif
1919 simplelist_addline(SIMPLELIST_ADD_LINE,
1920 "Blocks: 0x%08lx", card->numblocks);
1921 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1922 kbit_units, false);
1923 simplelist_addline(SIMPLELIST_ADD_LINE,
1924 "Speed: %s", pbuf);
1925 output_dyn_value(pbuf, sizeof pbuf, card->taac,
1926 nsec_units, false);
1927 simplelist_addline(SIMPLELIST_ADD_LINE,
1928 "Taac: %s", pbuf);
1929 simplelist_addline(SIMPLELIST_ADD_LINE,
1930 "Nsac: %d clk", card->nsac);
1931 simplelist_addline(SIMPLELIST_ADD_LINE,
1932 "R2W: *%d", card->r2w_factor);
1933 simplelist_addline(SIMPLELIST_ADD_LINE,
1934 "IRmax: %d..%d mA",
1935 i_vmin[card_extract_bits(card->csd, 61, 3)],
1936 i_vmax[card_extract_bits(card->csd, 58, 3)]);
1937 simplelist_addline(SIMPLELIST_ADD_LINE,
1938 "IWmax: %d..%d mA",
1939 i_vmin[card_extract_bits(card->csd, 55, 3)],
1940 i_vmax[card_extract_bits(card->csd, 52, 3)]);
1942 else if (card->initialized == 0)
1944 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1946 #if (CONFIG_STORAGE & STORAGE_SD)
1947 else /* card->initialized < 0 */
1949 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1951 #endif
1952 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1953 gui_synclist_set_title(lists, title, Icon_NOICON);
1954 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1955 gui_synclist_select_item(lists, 0);
1956 btn = ACTION_REDRAW;
1958 return btn;
1960 #elif (CONFIG_STORAGE & STORAGE_ATA)
1961 static int disk_callback(int btn, struct gui_synclist *lists)
1963 (void)lists;
1964 int i;
1965 char buf[128];
1966 unsigned short* identify_info = ata_get_identify();
1967 bool timing_info_present = false;
1968 (void)btn;
1970 simplelist_set_line_count(0);
1972 for (i=0; i < 20; i++)
1973 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1974 buf[40]=0;
1975 /* kill trailing space */
1976 for (i=39; i && buf[i]==' '; i--)
1977 buf[i] = 0;
1978 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1979 for (i=0; i < 4; i++)
1980 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1981 buf[8]=0;
1982 simplelist_addline(SIMPLELIST_ADD_LINE,
1983 "Firmware: %s", buf);
1984 snprintf(buf, sizeof buf, "%ld MB",
1985 ((unsigned long)identify_info[61] << 16 |
1986 (unsigned long)identify_info[60]) / 2048 );
1987 simplelist_addline(SIMPLELIST_ADD_LINE,
1988 "Size: %s", buf);
1989 unsigned long free;
1990 fat_size( IF_MV2(0,) NULL, &free );
1991 simplelist_addline(SIMPLELIST_ADD_LINE,
1992 "Free: %ld MB", free / 1024);
1993 simplelist_addline(SIMPLELIST_ADD_LINE,
1994 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
1995 i = identify_info[83] & (1<<3);
1996 simplelist_addline(SIMPLELIST_ADD_LINE,
1997 "Power mgmt: %s", i ? "enabled" : "unsupported");
1998 i = identify_info[83] & (1<<9);
1999 simplelist_addline(SIMPLELIST_ADD_LINE,
2000 "Noise mgmt: %s", i ? "enabled" : "unsupported");
2001 i = identify_info[82] & (1<<6);
2002 simplelist_addline(SIMPLELIST_ADD_LINE,
2003 "Read-ahead: %s", i ? "enabled" : "unsupported");
2004 timing_info_present = identify_info[53] & (1<<1);
2005 if(timing_info_present) {
2006 char pio3[2], pio4[2];pio3[1] = 0;
2007 pio4[1] = 0;
2008 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
2009 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
2010 simplelist_addline(SIMPLELIST_ADD_LINE,
2011 "PIO modes: 0 1 2 %s %s", pio3, pio4);
2013 else {
2014 simplelist_addline(SIMPLELIST_ADD_LINE,
2015 "No PIO mode info");
2017 timing_info_present = identify_info[53] & (1<<1);
2018 if(timing_info_present) {
2019 simplelist_addline(SIMPLELIST_ADD_LINE,
2020 "Cycle times %dns/%dns",
2021 identify_info[67],
2022 identify_info[68] );
2023 } else {
2024 simplelist_addline(SIMPLELIST_ADD_LINE,
2025 "No timing info");
2027 int sector_size = 512;
2028 if((identify_info[106] & 0xe000) == 0x6000)
2029 sector_size *= BIT_N(identify_info[106] & 0x000f);
2030 simplelist_addline(SIMPLELIST_ADD_LINE,
2031 "Physical sector size: %d", sector_size);
2032 #ifdef HAVE_ATA_DMA
2033 if (identify_info[63] & (1<<0)) {
2034 char mdma0[2], mdma1[2], mdma2[2];
2035 mdma0[1] = mdma1[1] = mdma2[1] = 0;
2036 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
2037 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
2038 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
2039 simplelist_addline(SIMPLELIST_ADD_LINE,
2040 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
2041 simplelist_addline(SIMPLELIST_ADD_LINE,
2042 "MDMA Cycle times %dns/%dns",
2043 identify_info[65],
2044 identify_info[66] );
2046 else {
2047 simplelist_addline(SIMPLELIST_ADD_LINE,
2048 "No MDMA mode info");
2050 if (identify_info[53] & (1<<2)) {
2051 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2], udma6[2];
2052 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = udma6[1] = 0;
2053 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
2054 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
2055 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
2056 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
2057 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
2058 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
2059 udma6[0] = (identify_info[88] & (1<<6)) ? '6' : 0;
2060 simplelist_addline(SIMPLELIST_ADD_LINE,
2061 "UDMA modes: %s %s %s %s %s %s %s", udma0, udma1, udma2,
2062 udma3, udma4, udma5, udma6);
2064 else {
2065 simplelist_addline(SIMPLELIST_ADD_LINE,
2066 "No UDMA mode info");
2068 #endif /* HAVE_ATA_DMA */
2069 timing_info_present = identify_info[53] & (1<<1);
2070 if(timing_info_present) {
2071 i = identify_info[49] & (1<<11);
2072 simplelist_addline(SIMPLELIST_ADD_LINE,
2073 "IORDY support: %s", i ? "yes" : "no");
2074 i = identify_info[49] & (1<<10);
2075 simplelist_addline(SIMPLELIST_ADD_LINE,
2076 "IORDY disable: %s", i ? "yes" : "no");
2077 } else {
2078 simplelist_addline(SIMPLELIST_ADD_LINE,
2079 "No timing info");
2081 simplelist_addline(SIMPLELIST_ADD_LINE,
2082 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2083 #ifdef HAVE_ATA_DMA
2084 i = ata_get_dma_mode();
2085 if (i == 0) {
2086 simplelist_addline(SIMPLELIST_ADD_LINE,
2087 "DMA not enabled");
2088 } else {
2089 simplelist_addline(SIMPLELIST_ADD_LINE,
2090 "DMA mode: %s %c",
2091 (i & 0x40) ? "UDMA" : "MDMA",
2092 '0' + (i & 7));
2094 #endif /* HAVE_ATA_DMA */
2095 return btn;
2097 #else /* No SD, MMC or ATA */
2098 static int disk_callback(int btn, struct gui_synclist *lists)
2100 (void)btn;
2101 (void)lists;
2102 struct storage_info info;
2103 storage_get_info(0,&info);
2104 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
2105 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
2106 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
2107 simplelist_addline(SIMPLELIST_ADD_LINE,
2108 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
2109 unsigned long free;
2110 fat_size( IF_MV2(0,) NULL, &free );
2111 simplelist_addline(SIMPLELIST_ADD_LINE,
2112 "Free: %ld MB", free / 1024);
2113 simplelist_addline(SIMPLELIST_ADD_LINE,
2114 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2115 return btn;
2117 #endif
2119 #if (CONFIG_STORAGE & STORAGE_ATA)
2120 static bool dbg_identify_info(void)
2122 int fd = creat("/identify_info.bin", 0666);
2123 if(fd >= 0)
2125 #ifdef ROCKBOX_LITTLE_ENDIAN
2126 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
2127 #else
2128 write(fd, ata_get_identify(), SECTOR_SIZE);
2129 #endif
2130 close(fd);
2132 return false;
2134 #endif
2136 static bool dbg_disk_info(void)
2138 struct simplelist_info info;
2139 simplelist_info_init(&info, "Disk Info", 1, NULL);
2140 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
2141 char title[16];
2142 int card = 0;
2143 info.callback_data = (void*)&card;
2144 info.title = title;
2145 #endif
2146 info.action_callback = disk_callback;
2147 info.hide_selection = true;
2148 info.scroll_all = true;
2149 return simplelist_show_list(&info);
2151 #endif /* PLATFORM_NATIVE */
2153 #ifdef HAVE_DIRCACHE
2154 static int dircache_callback(int btn, struct gui_synclist *lists)
2156 (void)btn; (void)lists;
2157 simplelist_set_line_count(0);
2158 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
2159 dircache_is_enabled() ? "Yes" : "No");
2160 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
2161 dircache_get_cache_size());
2162 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
2163 global_status.dircache_size);
2164 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
2165 DIRCACHE_LIMIT);
2166 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
2167 dircache_get_reserve_used(), DIRCACHE_RESERVE);
2168 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2169 dircache_get_build_ticks() / HZ);
2170 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2171 dircache_get_entry_count());
2172 return btn;
2175 static bool dbg_dircache_info(void)
2177 struct simplelist_info info;
2178 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2179 info.action_callback = dircache_callback;
2180 info.hide_selection = true;
2181 info.scroll_all = true;
2182 return simplelist_show_list(&info);
2185 #endif /* HAVE_DIRCACHE */
2187 #ifdef HAVE_TAGCACHE
2188 static int database_callback(int btn, struct gui_synclist *lists)
2190 (void)lists;
2191 struct tagcache_stat *stat = tagcache_get_stat();
2192 static bool synced = false;
2194 simplelist_set_line_count(0);
2196 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2197 stat->initialized ? "Yes" : "No");
2198 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2199 stat->ready ? "Yes" : "No");
2200 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2201 stat->ramcache ? "Yes" : "No");
2202 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2203 stat->ramcache_used, stat->ramcache_allocated);
2204 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2205 stat->progress, stat->processed_entries);
2206 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2207 stat->curentry ? stat->curentry : "---");
2208 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2209 stat->commit_step);
2210 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2211 stat->commit_delayed ? "Yes" : "No");
2213 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2214 stat->queue_length);
2216 if (synced)
2218 synced = false;
2219 tagcache_screensync_event();
2222 if (!btn && stat->curentry)
2224 synced = true;
2225 return ACTION_REDRAW;
2228 if (btn == ACTION_STD_CANCEL)
2229 tagcache_screensync_enable(false);
2231 return btn;
2233 static bool dbg_tagcache_info(void)
2235 struct simplelist_info info;
2236 simplelist_info_init(&info, "Database Info", 8, NULL);
2237 info.action_callback = database_callback;
2238 info.hide_selection = true;
2239 info.scroll_all = true;
2241 /* Don't do nonblock here, must give enough processing time
2242 for tagcache thread. */
2243 /* info.timeout = TIMEOUT_NOBLOCK; */
2244 info.timeout = 1;
2245 tagcache_screensync_enable(true);
2246 return simplelist_show_list(&info);
2248 #endif
2250 #if CONFIG_CPU == SH7034
2251 static bool dbg_save_roms(void)
2253 int fd;
2254 int oldmode = system_memory_guard(MEMGUARD_NONE);
2256 fd = creat("/internal_rom_0000-FFFF.bin", 0666);
2257 if(fd >= 0)
2259 write(fd, (void *)0, 0x10000);
2260 close(fd);
2263 fd = creat("/internal_rom_2000000-203FFFF.bin", 0666);
2264 if(fd >= 0)
2266 write(fd, (void *)0x2000000, 0x40000);
2267 close(fd);
2270 system_memory_guard(oldmode);
2271 return false;
2273 #elif defined CPU_COLDFIRE
2274 static bool dbg_save_roms(void)
2276 int fd;
2277 int oldmode = system_memory_guard(MEMGUARD_NONE);
2279 #if defined(IRIVER_H100_SERIES)
2280 fd = creat("/internal_rom_000000-1FFFFF.bin", 0666);
2281 #elif defined(IRIVER_H300_SERIES)
2282 fd = creat("/internal_rom_000000-3FFFFF.bin", 0666);
2283 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2284 fd = creat("/internal_rom_000000-3FFFFF.bin", 0666);
2285 #elif defined(MPIO_HD200)
2286 fd = creat("/internal_rom_000000-1FFFFF.bin", 0666);
2287 #endif
2288 if(fd >= 0)
2290 write(fd, (void *)0, FLASH_SIZE);
2291 close(fd);
2293 system_memory_guard(oldmode);
2295 #ifdef HAVE_EEPROM
2296 fd = creat("/internal_eeprom.bin", 0666);
2297 if (fd >= 0)
2299 int old_irq_level;
2300 char buf[EEPROM_SIZE];
2301 int err;
2303 old_irq_level = disable_irq_save();
2305 err = eeprom_24cxx_read(0, buf, sizeof buf);
2307 restore_irq(old_irq_level);
2309 if (err)
2310 splashf(HZ*3, "Eeprom read failure (%d)", err);
2311 else
2313 write(fd, buf, sizeof buf);
2316 close(fd);
2318 #endif
2320 return false;
2322 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
2323 static bool dbg_save_roms(void)
2325 int fd;
2327 fd = creat("/internal_rom_000000-0FFFFF.bin", 0666);
2328 if(fd >= 0)
2330 write(fd, (void *)0x20000000, FLASH_SIZE);
2331 close(fd);
2334 return false;
2336 #elif CONFIG_CPU == IMX31L
2337 static bool dbg_save_roms(void)
2339 int fd;
2341 fd = creat("/flash_rom_A0000000-A01FFFFF.bin", 0666);
2342 if (fd >= 0)
2344 write(fd, (void*)0xa0000000, FLASH_SIZE);
2345 close(fd);
2348 return false;
2350 #elif defined(CPU_TCC780X)
2351 static bool dbg_save_roms(void)
2353 int fd;
2355 fd = creat("/eeprom_E0000000-E0001FFF.bin", 0666);
2356 if (fd >= 0)
2358 write(fd, (void*)0xe0000000, 0x2000);
2359 close(fd);
2362 return false;
2364 #endif /* CPU */
2366 #ifndef SIMULATOR
2367 #if CONFIG_TUNER
2369 #ifdef CONFIG_TUNER_MULTI
2370 static int tuner_type = 0;
2371 #define IF_TUNER_TYPE(type) if(tuner_type==type)
2372 #else
2373 #define IF_TUNER_TYPE(type)
2374 #endif
2376 static int radio_callback(int btn, struct gui_synclist *lists)
2378 (void)lists;
2379 if (btn == ACTION_STD_CANCEL)
2380 return btn;
2381 simplelist_set_line_count(1);
2383 #if (CONFIG_TUNER & LV24020LP)
2384 simplelist_addline(SIMPLELIST_ADD_LINE,
2385 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2386 simplelist_addline(SIMPLELIST_ADD_LINE,
2387 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2388 simplelist_addline(SIMPLELIST_ADD_LINE,
2389 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2390 simplelist_addline(SIMPLELIST_ADD_LINE,
2391 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2392 simplelist_addline(SIMPLELIST_ADD_LINE,
2393 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2394 simplelist_addline(SIMPLELIST_ADD_LINE,
2395 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2396 simplelist_addline(SIMPLELIST_ADD_LINE,
2397 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2398 #endif /* LV24020LP */
2399 #if (CONFIG_TUNER & S1A0903X01)
2400 simplelist_addline(SIMPLELIST_ADD_LINE,
2401 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2402 /* This one doesn't return dynamic data atm */
2403 #endif /* S1A0903X01 */
2404 #if (CONFIG_TUNER & TEA5767)
2405 struct tea5767_dbg_info nfo;
2406 tea5767_dbg_info(&nfo);
2407 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2408 simplelist_addline(SIMPLELIST_ADD_LINE,
2409 " Read: %02X %02X %02X %02X %02X",
2410 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2411 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2412 (unsigned)nfo.read_regs[4]);
2413 simplelist_addline(SIMPLELIST_ADD_LINE,
2414 " Write: %02X %02X %02X %02X %02X",
2415 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2416 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2417 (unsigned)nfo.write_regs[4]);
2418 #endif /* TEA5767 */
2419 #if (CONFIG_TUNER & SI4700)
2420 IF_TUNER_TYPE(SI4700)
2422 struct si4700_dbg_info nfo;
2423 int i;
2424 si4700_dbg_info(&nfo);
2425 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
2426 for (i = 0; i < 16; i += 4) {
2427 simplelist_addline(SIMPLELIST_ADD_LINE,"%02X: %04X %04X %04X %04X",
2428 i, nfo.regs[i], nfo.regs[i+1], nfo.regs[i+2], nfo.regs[i+3]);
2431 #endif /* SI4700 */
2432 #if (CONFIG_TUNER & RDA5802)
2433 IF_TUNER_TYPE(RDA5802)
2435 struct rda5802_dbg_info nfo;
2436 int i;
2437 rda5802_dbg_info(&nfo);
2438 simplelist_addline(SIMPLELIST_ADD_LINE, "RDA5802 regs:");
2439 for (i = 0; i < 16; i += 4) {
2440 simplelist_addline(SIMPLELIST_ADD_LINE,"%02X: %04X %04X %04X %04X",
2441 i, nfo.regs[i], nfo.regs[i+1], nfo.regs[i+2], nfo.regs[i+3]);
2444 #endif /* RDA55802 */
2445 return ACTION_REDRAW;
2447 static bool dbg_fm_radio(void)
2449 struct simplelist_info info;
2450 #ifdef CONFIG_TUNER_MULTI
2451 tuner_type = tuner_detect_type();
2452 #endif
2453 info.scroll_all = true;
2454 simplelist_info_init(&info, "FM Radio", 1, NULL);
2455 simplelist_set_line_count(0);
2456 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2457 radio_hardware_present() ? "yes" : "no");
2459 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2460 info.hide_selection = true;
2461 return simplelist_show_list(&info);
2463 #endif /* CONFIG_TUNER */
2464 #endif /* !SIMULATOR */
2466 #ifdef HAVE_LCD_BITMAP
2467 extern bool do_screendump_instead_of_usb;
2469 static bool dbg_screendump(void)
2471 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2472 splashf(HZ, "Screendump %s",
2473 do_screendump_instead_of_usb?"enabled":"disabled");
2474 return false;
2476 #endif /* HAVE_LCD_BITMAP */
2478 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2479 static bool dbg_set_memory_guard(void)
2481 static const struct opt_items names[MAXMEMGUARD] = {
2482 { "None", -1 },
2483 { "Flash ROM writes", -1 },
2484 { "Zero area (all)", -1 }
2486 int mode = system_memory_guard(MEMGUARD_KEEP);
2488 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2489 system_memory_guard(mode);
2491 return false;
2493 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2495 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2496 static bool dbg_write_eeprom(void)
2498 int fd;
2499 int rc;
2500 int old_irq_level;
2501 char buf[EEPROM_SIZE];
2502 int err;
2504 fd = open("/internal_eeprom.bin", O_RDONLY);
2506 if (fd >= 0)
2508 rc = read(fd, buf, EEPROM_SIZE);
2510 if(rc == EEPROM_SIZE)
2512 old_irq_level = disable_irq_save();
2514 err = eeprom_24cxx_write(0, buf, sizeof buf);
2515 if (err)
2516 splashf(HZ*3, "Eeprom write failure (%d)", err);
2517 else
2518 splash(HZ*3, "Eeprom written successfully");
2520 restore_irq(old_irq_level);
2522 else
2524 splashf(HZ*3, "File read error (%d)",rc);
2526 close(fd);
2528 else
2530 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2533 return false;
2535 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2536 #ifdef CPU_BOOST_LOGGING
2537 static bool cpu_boost_log(void)
2539 int i = 0,j=0;
2540 int count = cpu_boost_log_getcount();
2541 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2542 char *str;
2543 bool done;
2544 lcd_setfont(FONT_SYSFIXED);
2545 str = cpu_boost_log_getlog_first();
2546 while (i < count)
2548 lcd_clear_display();
2549 for(j=0; j<lines; j++,i++)
2551 if (!str)
2552 str = cpu_boost_log_getlog_next();
2553 if (str)
2555 if(strlen(str) > LCD_WIDTH/SYSFONT_WIDTH)
2556 lcd_puts_scroll(0, j, str);
2557 else
2558 lcd_puts(0, j,str);
2560 str = NULL;
2562 lcd_update();
2563 done = false;
2564 while (!done)
2566 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2568 case ACTION_STD_OK:
2569 case ACTION_STD_PREV:
2570 case ACTION_STD_NEXT:
2571 done = true;
2572 break;
2573 case ACTION_STD_CANCEL:
2574 i = count;
2575 done = true;
2576 break;
2580 lcd_stop_scroll();
2581 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2582 lcd_setfont(FONT_UI);
2583 return false;
2585 #endif
2587 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2588 extern bool wheel_is_touched;
2589 extern int old_wheel_value;
2590 extern int new_wheel_value;
2591 extern int wheel_delta;
2592 extern unsigned int accumulated_wheel_delta;
2593 extern unsigned int wheel_velocity;
2595 static bool dbg_scrollwheel(void)
2597 unsigned int speed;
2599 lcd_setfont(FONT_SYSFIXED);
2601 while (1)
2603 if (action_userabort(HZ/10))
2604 break;
2606 lcd_clear_display();
2608 /* show internal variables of scrollwheel driver */
2609 lcd_putsf(0, 0, "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2610 lcd_putsf(0, 1, "new position: %2d", new_wheel_value);
2611 lcd_putsf(0, 2, "old position: %2d", old_wheel_value);
2612 lcd_putsf(0, 3, "wheel delta: %2d", wheel_delta);
2613 lcd_putsf(0, 4, "accumulated delta: %2d", accumulated_wheel_delta);
2614 lcd_putsf(0, 5, "velo [deg/s]: %4d", (int)wheel_velocity);
2616 /* show effective accelerated scrollspeed */
2617 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2618 lcd_putsf(0, 6, "accel. speed: %4d", speed);
2620 lcd_update();
2622 lcd_setfont(FONT_UI);
2623 return false;
2625 #endif
2627 #if defined (HAVE_USBSTACK)
2629 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2630 static bool toggle_usb_core_driver(int driver, char *msg)
2632 bool enabled = !usb_core_driver_enabled(driver);
2634 usb_core_enable_driver(driver,enabled);
2635 splashf(HZ, "%s %s", msg, enabled?"enabled":"disabled");
2637 return false;
2640 static bool toggle_usb_serial(void)
2642 return toggle_usb_core_driver(USB_DRIVER_SERIAL,"USB Serial");
2644 #endif
2646 #endif
2648 #if CONFIG_USBOTG == USBOTG_ISP1583
2649 extern int dbg_usb_num_items(void);
2650 extern const char* dbg_usb_item(int selected_item, void *data,
2651 char *buffer, size_t buffer_len);
2653 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2655 (void)lists;
2656 if (action == ACTION_NONE)
2657 action = ACTION_REDRAW;
2658 return action;
2661 static bool dbg_isp1583(void)
2663 struct simplelist_info isp1583;
2664 isp1583.scroll_all = true;
2665 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2666 isp1583.timeout = HZ/100;
2667 isp1583.hide_selection = true;
2668 isp1583.get_name = dbg_usb_item;
2669 isp1583.action_callback = isp1583_action_callback;
2670 return simplelist_show_list(&isp1583);
2672 #endif
2674 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2675 extern int pic_dbg_num_items(void);
2676 extern const char* pic_dbg_item(int selected_item, void *data,
2677 char *buffer, size_t buffer_len);
2679 static int pic_action_callback(int action, struct gui_synclist *lists)
2681 (void)lists;
2682 if (action == ACTION_NONE)
2683 action = ACTION_REDRAW;
2684 return action;
2687 static bool dbg_pic(void)
2689 struct simplelist_info pic;
2690 pic.scroll_all = true;
2691 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2692 pic.timeout = HZ/100;
2693 pic.hide_selection = true;
2694 pic.get_name = pic_dbg_item;
2695 pic.action_callback = pic_action_callback;
2696 return simplelist_show_list(&pic);
2698 #endif
2701 /****** The menu *********/
2702 struct the_menu_item {
2703 unsigned char *desc; /* string or ID */
2704 bool (*function) (void); /* return true if USB was connected */
2706 static const struct the_menu_item menuitems[] = {
2707 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2708 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)) || \
2709 CONFIG_CPU == IMX31L || defined(CPU_TCC780X)
2710 { "Dump ROM contents", dbg_save_roms },
2711 #endif
2712 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2713 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 \
2714 || CONFIG_CPU == DM320 || defined(CPU_S5L870X) || CONFIG_CPU == AS3525v2
2715 { "View I/O ports", dbg_ports },
2716 #endif
2717 #if (CONFIG_RTC == RTC_PCF50605) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
2718 { "View PCF registers", dbg_pcf },
2719 #endif
2720 #if defined(HAVE_TSC2100) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
2721 { "TSC2100 debug", tsc2100_debug },
2722 #endif
2723 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2724 { "CPU frequency", dbg_cpufreq },
2725 #endif
2726 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2727 { "S/PDIF analyzer", dbg_spdif },
2728 #endif
2729 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2730 { "Catch mem accesses", dbg_set_memory_guard },
2731 #endif
2732 { "View OS stacks", dbg_os },
2733 #ifdef HAVE_LCD_BITMAP
2734 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2735 { "View battery", view_battery },
2736 #endif
2737 { "Screendump", dbg_screendump },
2738 #endif
2739 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2740 { "View HW info", dbg_hw_info },
2741 #endif
2742 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2743 { "View partitions", dbg_partitions },
2744 #endif
2745 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2746 { "View disk info", dbg_disk_info },
2747 #if (CONFIG_STORAGE & STORAGE_ATA)
2748 { "Dump ATA identify info", dbg_identify_info},
2749 #endif
2750 #endif
2751 #ifdef HAVE_DIRCACHE
2752 { "View dircache info", dbg_dircache_info },
2753 #endif
2754 #ifdef HAVE_TAGCACHE
2755 { "View database info", dbg_tagcache_info },
2756 #endif
2757 #ifdef HAVE_LCD_BITMAP
2758 #if CONFIG_CODEC == SWCODEC
2759 { "View buffering thread", dbg_buffering_thread },
2760 #elif !defined(SIMULATOR)
2761 { "View audio thread", dbg_audio_thread },
2762 #endif
2763 #ifdef PM_DEBUG
2764 { "pm histogram", peak_meter_histogram},
2765 #endif /* PM_DEBUG */
2766 #endif /* HAVE_LCD_BITMAP */
2767 #ifndef SIMULATOR
2768 #if CONFIG_TUNER
2769 { "FM Radio", dbg_fm_radio },
2770 #endif
2771 #endif
2772 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2773 { "Write back EEPROM", dbg_write_eeprom },
2774 #endif
2775 #if CONFIG_USBOTG == USBOTG_ISP1583
2776 { "View ISP1583 info", dbg_isp1583 },
2777 #endif
2778 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2779 { "View PIC info", dbg_pic },
2780 #endif
2781 #ifdef ROCKBOX_HAS_LOGF
2782 {"Show Log File", logfdisplay },
2783 {"Dump Log File", logfdump },
2784 #endif
2785 #if defined(HAVE_USBSTACK)
2786 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2787 {"USB Serial driver (logf)", toggle_usb_serial },
2788 #endif
2789 #endif /* HAVE_USBSTACK */
2790 #ifdef CPU_BOOST_LOGGING
2791 {"cpu_boost log",cpu_boost_log},
2792 #endif
2793 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2794 {"Debug scrollwheel", dbg_scrollwheel },
2795 #endif
2797 static int menu_action_callback(int btn, struct gui_synclist *lists)
2799 int i;
2800 if (btn == ACTION_STD_OK)
2802 FOR_NB_SCREENS(i)
2803 viewportmanager_theme_enable(i, false, NULL);
2804 menuitems[gui_synclist_get_sel_pos(lists)].function();
2805 btn = ACTION_REDRAW;
2806 FOR_NB_SCREENS(i)
2807 viewportmanager_theme_undo(i, false);
2809 return btn;
2812 static const char* dbg_menu_getname(int item, void * data,
2813 char *buffer, size_t buffer_len)
2815 (void)data; (void)buffer; (void)buffer_len;
2816 return menuitems[item].desc;
2819 bool debug_menu(void)
2821 struct simplelist_info info;
2823 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2824 info.action_callback = menu_action_callback;
2825 info.get_name = dbg_menu_getname;
2826 return simplelist_show_list(&info);