Fix a few bugs with the classic way of scrolling (dpad).
[kugel-rb.git] / apps / debug_menu.c
blob2497b17826a3c1587cdd2dc1e447fb214149b711
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 #if defined(IPOD_ACCESSORY_PROTOCOL)
126 #include "iap.h"
127 #endif
129 /*---------------------------------------------------*/
130 /* SPECIAL DEBUG STUFF */
131 /*---------------------------------------------------*/
132 extern struct thread_entry threads[MAXTHREADS];
134 static char thread_status_char(unsigned status)
136 static const char thread_status_chars[THREAD_NUM_STATES+1] =
138 [0 ... THREAD_NUM_STATES] = '?',
139 [STATE_RUNNING] = 'R',
140 [STATE_BLOCKED] = 'B',
141 [STATE_SLEEPING] = 'S',
142 [STATE_BLOCKED_W_TMO] = 'T',
143 [STATE_FROZEN] = 'F',
144 [STATE_KILLED] = 'K',
147 if (status > THREAD_NUM_STATES)
148 status = THREAD_NUM_STATES;
150 return thread_status_chars[status];
153 static const char* threads_getname(int selected_item, void *data,
154 char *buffer, size_t buffer_len)
156 (void)data;
157 struct thread_entry *thread;
158 char name[32];
160 #if NUM_CORES > 1
161 if (selected_item < (int)NUM_CORES)
163 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
164 idle_stack_usage(selected_item));
165 return buffer;
168 selected_item -= NUM_CORES;
169 #endif
171 thread = &threads[selected_item];
173 if (thread->state == STATE_KILLED)
175 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
176 return buffer;
179 thread_get_name(name, 32, thread);
181 snprintf(buffer, buffer_len,
182 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
183 selected_item,
184 IF_COP(thread->core,)
185 #ifdef HAVE_SCHEDULER_BOOSTCTRL
186 (thread->cpu_boost) ? '+' :
187 #endif
188 ((thread->state == STATE_RUNNING) ? '*' : ' '),
189 thread_status_char(thread->state),
190 IF_PRIO(thread->base_priority, thread->priority, )
191 thread_stack_usage(thread), name);
193 return buffer;
196 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
198 (void)lists;
199 #ifdef ROCKBOX_HAS_LOGF
200 if (action == ACTION_STD_OK)
202 int selpos = gui_synclist_get_sel_pos(lists);
203 #if NUM_CORES > 1
204 if (selpos >= NUM_CORES)
205 remove_thread(threads[selpos - NUM_CORES].id);
206 #else
207 remove_thread(threads[selpos].id);
208 #endif
209 return ACTION_REDRAW;
211 #endif /* ROCKBOX_HAS_LOGF */
212 if (action == ACTION_NONE)
213 action = ACTION_REDRAW;
214 return action;
216 /* Test code!!! */
217 static bool dbg_os(void)
219 struct simplelist_info info;
220 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
221 #if NUM_CORES == 1
222 MAXTHREADS,
223 #else
224 MAXTHREADS+NUM_CORES,
225 #endif
226 NULL);
227 #ifndef ROCKBOX_HAS_LOGF
228 info.hide_selection = true;
229 info.scroll_all = true;
230 #endif
231 info.action_callback = dbg_threads_action_callback;
232 info.get_name = threads_getname;
233 return simplelist_show_list(&info);
236 #ifdef HAVE_LCD_BITMAP
237 #if CONFIG_CODEC != SWCODEC
238 #ifndef SIMULATOR
239 static bool dbg_audio_thread(void)
241 struct audio_debug d;
243 lcd_setfont(FONT_SYSFIXED);
245 while(1)
247 if (action_userabort(HZ/5))
248 return false;
250 audio_get_debugdata(&d);
252 lcd_clear_display();
254 lcd_putsf(0, 0, "read: %x", d.audiobuf_read);
255 lcd_putsf(0, 1, "write: %x", d.audiobuf_write);
256 lcd_putsf(0, 2, "swap: %x", d.audiobuf_swapwrite);
257 lcd_putsf(0, 3, "playing: %d", d.playing);
258 lcd_putsf(0, 4, "playable: %x", d.playable_space);
259 lcd_putsf(0, 5, "unswapped: %x", d.unswapped_space);
261 /* Playable space left */
262 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
263 d.playable_space, HORIZONTAL);
265 /* Show the watermark limit */
266 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
267 d.low_watermark_level, HORIZONTAL);
269 lcd_putsf(0, 7, "wm: %x - %x",
270 d.low_watermark_level, d.lowest_watermark_level);
272 lcd_update();
274 lcd_setfont(FONT_UI);
275 return false;
277 #endif /* !SIMULATOR */
278 #else /* CONFIG_CODEC == SWCODEC */
279 static unsigned int ticks, boost_ticks, freq_sum;
281 static void dbg_audio_task(void)
283 #ifdef CPUFREQ_NORMAL
284 if(FREQ > CPUFREQ_NORMAL)
285 boost_ticks++;
286 freq_sum += FREQ/1000000; /* in MHz */
287 #endif
288 ticks++;
291 static bool dbg_buffering_thread(void)
293 int button;
294 int line, i;
295 bool done = false;
296 size_t bufused;
297 size_t bufsize = pcmbuf_get_bufsize();
298 int pcmbufdescs = pcmbuf_descs();
299 struct buffering_debug d;
300 size_t filebuflen = audio_get_filebuflen();
301 /* This is a size_t, but call it a long so it puts a - when it's bad. */
303 ticks = boost_ticks = freq_sum = 0;
305 tick_add_task(dbg_audio_task);
307 FOR_NB_SCREENS(i)
308 screens[i].setfont(FONT_SYSFIXED);
310 while(!done)
312 button = get_action(CONTEXT_STD,HZ/5);
313 switch(button)
315 case ACTION_STD_NEXT:
316 audio_next();
317 break;
318 case ACTION_STD_PREV:
319 audio_prev();
320 break;
321 case ACTION_STD_CANCEL:
322 done = true;
323 break;
326 buffering_get_debugdata(&d);
327 bufused = bufsize - pcmbuf_free();
329 FOR_NB_SCREENS(i)
331 line = 0;
332 screens[i].clear_display();
335 screens[i].putsf(0, line++, "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
337 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
338 bufsize, 0, bufused, HORIZONTAL);
339 line++;
341 screens[i].putsf(0, line++, "alloc: %6ld/%ld", audio_filebufused(),
342 (long) filebuflen);
344 #if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
345 if (screens[i].lcdheight > 80)
347 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
348 filebuflen, 0, audio_filebufused(), HORIZONTAL);
349 line++;
351 screens[i].putsf(0, line++, "real: %6ld/%ld", (long)d.buffered_data,
352 (long)filebuflen);
354 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
355 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
356 line++;
358 #endif
360 screens[i].putsf(0, line++, "usefl: %6ld/%ld", (long)(d.useful_data),
361 (long)filebuflen);
363 #if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
364 if (screens[i].lcdheight > 80)
366 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
367 filebuflen, 0, d.useful_data, HORIZONTAL);
368 line++;
370 #endif
372 screens[i].putsf(0, line++, "data_rem: %ld", (long)d.data_rem);
374 screens[i].putsf(0, line++, "track count: %2d", audio_track_count());
376 screens[i].putsf(0, line++, "handle count: %d", (int)d.num_handles);
378 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
379 screens[i].putsf(0, line++, "cpu freq: %3dMHz",
380 (int)((FREQ + 500000) / 1000000));
381 #endif
383 if (ticks > 0)
385 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
386 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
387 screens[i].putsf(0, line++, "boost:%3d.%d%% (%d.%dMHz)",
388 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
391 screens[i].putsf(0, line++, "pcmbufdesc: %2d/%2d",
392 pcmbuf_used_descs(), pcmbufdescs);
393 screens[i].putsf(0, line++, "watermark: %6d",
394 (int)(d.watermark));
396 screens[i].update();
400 tick_remove_task(dbg_audio_task);
402 FOR_NB_SCREENS(i)
403 screens[i].setfont(FONT_UI);
405 return false;
407 #endif /* CONFIG_CODEC */
408 #endif /* HAVE_LCD_BITMAP */
411 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
412 /* Tool function to read the flash manufacturer and type, if available.
413 Only chips which could be reprogrammed in system will return values.
414 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
415 /* In IRAM to avoid problems when running directly from Flash */
416 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
417 unsigned addr1, unsigned addr2)
418 ICODE_ATTR __attribute__((noinline));
419 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
420 unsigned addr1, unsigned addr2)
423 unsigned not_manu, not_id; /* read values before switching to ID mode */
424 unsigned manu, id; /* read values when in ID mode */
426 #if CONFIG_CPU == SH7034
427 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
428 #elif defined(CPU_COLDFIRE)
429 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
430 #endif
431 int old_level; /* saved interrupt level */
433 not_manu = flash[0]; /* read the normal content */
434 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
436 /* disable interrupts, prevent any stray flash access */
437 old_level = disable_irq_save();
439 flash[addr1] = 0xAA; /* enter command mode */
440 flash[addr2] = 0x55;
441 flash[addr1] = 0x90; /* ID command */
442 /* Atmel wants 20ms pause here */
443 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
445 manu = flash[0]; /* read the IDs */
446 id = flash[1];
448 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
449 /* Atmel wants 20ms pause here */
450 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
452 restore_irq(old_level); /* enable interrupts again */
454 /* I assume success if the obtained values are different from
455 the normal flash content. This is not perfectly bulletproof, they
456 could theoretically be the same by chance, causing us to fail. */
457 if (not_manu != manu || not_id != id) /* a value has changed */
459 *p_manufacturer = manu; /* return the results */
460 *p_device = id;
461 return true; /* success */
463 return false; /* fail */
465 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
467 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
468 #ifdef CPU_PP
469 static int perfcheck(void)
471 int result;
473 asm (
474 "mrs r2, CPSR \n"
475 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
476 "msr CPSR_c, r0 \n"
477 "mov %[res], #0 \n"
478 "ldr r0, [%[timr]] \n"
479 "add r0, r0, %[tmo] \n"
480 "1: \n"
481 "add %[res], %[res], #1 \n"
482 "ldr r1, [%[timr]] \n"
483 "cmp r1, r0 \n"
484 "bmi 1b \n"
485 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
487 [res]"=&r"(result)
489 [timr]"r"(&USEC_TIMER),
490 [tmo]"r"(
491 #if CONFIG_CPU == PP5002
492 16000
493 #else /* PP5020/5022/5024 */
494 10226
495 #endif
498 "r0", "r1", "r2"
500 return result;
502 #endif
504 #ifdef HAVE_LCD_BITMAP
505 static bool dbg_hw_info(void)
507 #if CONFIG_CPU == SH7034
508 int bitmask = HW_MASK;
509 int rom_version = ROM_VERSION;
510 unsigned manu, id; /* flash IDs */
511 bool got_id; /* flag if we managed to get the flash IDs */
512 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
513 bool has_bootrom; /* flag for boot ROM present */
514 int oldmode; /* saved memory guard mode */
516 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
518 /* get flash ROM type */
519 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
520 if (!got_id)
521 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
523 /* check if the boot ROM area is a flash mirror */
524 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
525 if (has_bootrom) /* if ROM and Flash different */
527 /* calculate CRC16 checksum of boot ROM */
528 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
531 system_memory_guard(oldmode); /* re-enable memory guard */
533 lcd_setfont(FONT_SYSFIXED);
534 lcd_clear_display();
536 lcd_puts(0, 0, "[Hardware info]");
538 lcd_putsf(0, 1, "ROM: %d.%02d", rom_version/100, rom_version%100);
540 lcd_putsf(0, 2, "Mask: 0x%04x", bitmask);
542 if (got_id)
543 lcd_putsf(0, 3, "Flash: M=%02x D=%02x", manu, id);
544 else
545 lcd_puts(0, 3, "Flash: M=?? D=??"); /* unknown, sorry */
547 if (has_bootrom)
549 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
550 lcd_puts(0, 4, "Boot ROM: V1");
551 else
552 lcd_putsf(0, 4, "ROMcrc: 0x%08x", rom_crc);
554 else
556 lcd_puts(0, 4, "Boot ROM: none");
559 lcd_update();
561 while (!(action_userabort(TIMEOUT_BLOCK)));
563 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
564 unsigned manu, id; /* flash IDs */
565 int got_id; /* flag if we managed to get the flash IDs */
566 int oldmode; /* saved memory guard mode */
567 int line = 0;
569 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
571 /* get flash ROM type */
572 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
573 if (!got_id)
574 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
576 system_memory_guard(oldmode); /* re-enable memory guard */
578 lcd_setfont(FONT_SYSFIXED);
579 lcd_clear_display();
581 lcd_puts(0, line++, "[Hardware info]");
583 if (got_id)
584 lcd_putsf(0, line++, "Flash: M=%04x D=%04x", manu, id);
585 else
586 lcd_puts(0, line++, "Flash: M=???? D=????"); /* unknown, sorry */
588 #ifdef IAUDIO_X5
590 struct ds2411_id id;
592 lcd_puts(0, ++line, "Serial Number:");
594 got_id = ds2411_read_id(&id);
596 if (got_id == DS2411_OK)
598 lcd_putsf(0, ++line, " FC=%02x", (unsigned)id.family_code);
599 lcd_putsf(0, ++line, " ID=%02X %02X %02X %02X %02X %02X",
600 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
601 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
602 lcd_putsf(0, ++line, " CRC=%02X", (unsigned)id.crc);
604 else
606 lcd_putsf(0, ++line, "READ ERR=%d", got_id);
609 #endif
611 lcd_update();
613 while (!(action_userabort(TIMEOUT_BLOCK)));
615 #elif defined(CPU_PP502x)
616 int line = 0;
617 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
618 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
619 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
620 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
622 lcd_setfont(FONT_SYSFIXED);
623 lcd_clear_display();
625 lcd_puts(0, line++, "[Hardware info]");
627 #ifdef IPOD_ARCH
628 lcd_putsf(0, line++, "HW rev: 0x%08lx", IPOD_HW_REVISION);
629 #endif
631 #ifdef IPOD_COLOR
632 extern int lcd_type; /* Defined in lcd-colornano.c */
634 lcd_putsf(0, line++, "LCD type: %d", lcd_type);
635 #endif
637 lcd_putsf(0, line++, "PP version: %s", pp_version);
639 lcd_putsf(0, line++, "Est. clock (kHz): %d", perfcheck());
641 lcd_update();
643 while (!(action_userabort(TIMEOUT_BLOCK)));
645 #elif CONFIG_CPU == PP5002
646 int line = 0;
647 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
648 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
649 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
650 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
653 lcd_setfont(FONT_SYSFIXED);
654 lcd_clear_display();
656 lcd_puts(0, line++, "[Hardware info]");
658 #ifdef IPOD_ARCH
659 lcd_putsf(0, line++, "HW rev: 0x%08lx", IPOD_HW_REVISION);
660 #endif
662 lcd_putsf(0, line++, "PP version: %s", pp_version);
664 lcd_putsf(0, line++, "Est. clock (kHz): %d", perfcheck());
666 lcd_update();
668 while (!(action_userabort(TIMEOUT_BLOCK)));
670 #else
671 /* Define this function in your target tree */
672 return __dbg_hw_info();
673 #endif /* CONFIG_CPU */
674 lcd_setfont(FONT_UI);
675 return false;
677 #else /* !HAVE_LCD_BITMAP */
678 static bool dbg_hw_info(void)
680 int button;
681 int currval = 0;
682 int rom_version = ROM_VERSION;
683 unsigned manu, id; /* flash IDs */
684 bool got_id; /* flag if we managed to get the flash IDs */
685 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
686 bool has_bootrom; /* flag for boot ROM present */
687 int oldmode; /* saved memory guard mode */
689 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
691 /* get flash ROM type */
692 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
693 if (!got_id)
694 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
696 /* check if the boot ROM area is a flash mirror */
697 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
698 if (has_bootrom) /* if ROM and Flash different */
700 /* calculate CRC16 checksum of boot ROM */
701 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
704 system_memory_guard(oldmode); /* re-enable memory guard */
706 lcd_clear_display();
708 lcd_puts(0, 0, "[HW Info]");
709 while(1)
711 switch(currval)
713 case 0:
714 lcd_putsf(0, 1, "ROM: %d.%02d",
715 rom_version/100, rom_version%100);
716 break;
717 case 1:
718 if (got_id)
719 lcd_putsf(0, 1, "Flash:%02x,%02x", manu, id);
720 else
721 lcd_puts(0, 1, "Flash:??,??"); /* unknown, sorry */
722 break;
723 case 2:
724 if (has_bootrom)
726 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
727 lcd_puts(0, 1, "BootROM: V1");
728 else if (rom_crc == 0x358099E8)
729 lcd_puts(0, 1, "BootROM: V2");
730 /* alternative boot ROM found in one single player so far */
731 else
732 lcd_putsf(0, 1, "R: %08x", rom_crc);
734 else
735 lcd_puts(0, 1, "BootROM: no");
738 lcd_update();
740 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
742 switch(button)
744 case ACTION_STD_CANCEL:
745 return false;
747 case ACTION_SETTINGS_DEC:
748 currval--;
749 if(currval < 0)
750 currval = 2;
751 break;
753 case ACTION_SETTINGS_INC:
754 currval++;
755 if(currval > 2)
756 currval = 0;
757 break;
760 return false;
762 #endif /* !HAVE_LCD_BITMAP */
763 #endif /* PLATFORM_NATIVE */
765 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
766 static const char* dbg_partitions_getname(int selected_item, void *data,
767 char *buffer, size_t buffer_len)
769 (void)data;
770 int partition = selected_item/2;
771 struct partinfo* p = disk_partinfo(partition);
772 if (selected_item%2)
774 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / ( 2048 / ( SECTOR_SIZE / 512 )));
776 else
778 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
780 return buffer;
783 bool dbg_partitions(void)
785 struct simplelist_info info;
786 simplelist_info_init(&info, "Partition Info", 4, NULL);
787 info.selection_size = 2;
788 info.hide_selection = true;
789 info.scroll_all = true;
790 info.get_name = dbg_partitions_getname;
791 return simplelist_show_list(&info);
793 #endif /* PLATFORM_NATIVE */
795 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
796 static bool dbg_spdif(void)
798 int line;
799 unsigned int control;
800 int x;
801 char *s;
802 int category;
803 int generation;
804 unsigned int interruptstat;
805 bool valnogood, symbolerr, parityerr;
806 bool done = false;
807 bool spdif_src_on;
808 int spdif_source = spdif_get_output_source(&spdif_src_on);
809 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
811 lcd_clear_display();
812 lcd_setfont(FONT_SYSFIXED);
814 #ifdef HAVE_SPDIF_POWER
815 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
816 #endif
818 while (!done)
820 line = 0;
822 control = EBU1RCVCCHANNEL1;
823 interruptstat = INTERRUPTSTAT;
824 INTERRUPTCLEAR = 0x03c00000;
826 valnogood = (interruptstat & 0x01000000)?true:false;
827 symbolerr = (interruptstat & 0x00800000)?true:false;
828 parityerr = (interruptstat & 0x00400000)?true:false;
830 lcd_putsf(0, line++, "Val: %s Sym: %s Par: %s",
831 valnogood?"--":"OK",
832 symbolerr?"--":"OK",
833 parityerr?"--":"OK");
835 lcd_putsf(0, line++, "Status word: %08x", (int)control);
837 line++;
839 x = control >> 31;
840 lcd_putsf(0, line++, "PRO: %d (%s)",
841 x, x?"Professional":"Consumer");
843 x = (control >> 30) & 1;
844 lcd_putsf(0, line++, "Audio: %d (%s)",
845 x, x?"Non-PCM":"PCM");
847 x = (control >> 29) & 1;
848 lcd_putsf(0, line++, "Copy: %d (%s)",
849 x, x?"Permitted":"Inhibited");
851 x = (control >> 27) & 7;
852 switch(x)
854 case 0:
855 s = "None";
856 break;
857 case 1:
858 s = "50/15us";
859 break;
860 default:
861 s = "Reserved";
862 break;
864 lcd_putsf(0, line++, "Preemphasis: %d (%s)", x, s);
866 x = (control >> 24) & 3;
867 lcd_putsf(0, line++, "Mode: %d", x);
869 category = (control >> 17) & 127;
870 switch(category)
872 case 0x00:
873 s = "General";
874 break;
875 case 0x40:
876 s = "Audio CD";
877 break;
878 default:
879 s = "Unknown";
881 lcd_putsf(0, line++, "Category: 0x%02x (%s)", category, s);
883 x = (control >> 16) & 1;
884 generation = x;
885 if(((category & 0x70) == 0x10) ||
886 ((category & 0x70) == 0x40) ||
887 ((category & 0x78) == 0x38))
889 generation = !generation;
891 lcd_putsf(0, line++, "Generation: %d (%s)",
892 x, generation?"Original":"No ind.");
894 x = (control >> 12) & 15;
895 lcd_putsf(0, line++, "Source: %d", x);
898 x = (control >> 8) & 15;
899 switch(x)
901 case 0:
902 s = "Unspecified";
903 break;
904 case 8:
905 s = "A (Left)";
906 break;
907 case 4:
908 s = "B (Right)";
909 break;
910 default:
911 s = "";
912 break;
914 lcd_putsf(0, line++, "Channel: %d (%s)", x, s);
916 x = (control >> 4) & 15;
917 switch(x)
919 case 0:
920 s = "44.1kHz";
921 break;
922 case 0x4:
923 s = "48kHz";
924 break;
925 case 0xc:
926 s = "32kHz";
927 break;
929 lcd_putsf(0, line++, "Frequency: %d (%s)", x, s);
931 x = (control >> 2) & 3;
932 lcd_putsf(0, line++, "Clock accuracy: %d", x);
933 line++;
935 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
936 lcd_putsf(0, line++, "Measured freq: %ldHz",
937 spdif_measure_frequency());
938 #endif
940 lcd_update();
942 if (action_userabort(HZ/10))
943 break;
946 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
948 #ifdef HAVE_SPDIF_POWER
949 spdif_power_enable(global_settings.spdif_enable);
950 #endif
952 lcd_setfont(FONT_UI);
953 return false;
955 #endif /* CPU_COLDFIRE */
957 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
958 #ifdef HAVE_LCD_BITMAP
959 /* button definitions */
960 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
961 (CONFIG_KEYPAD == IRIVER_H300_PAD)
962 # define DEBUG_CANCEL BUTTON_OFF
964 #elif CONFIG_KEYPAD == RECORDER_PAD
965 # define DEBUG_CANCEL BUTTON_OFF
967 #elif CONFIG_KEYPAD == ONDIO_PAD
968 # define DEBUG_CANCEL BUTTON_MENU
970 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
971 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
972 (CONFIG_KEYPAD == IPOD_4G_PAD)
973 # define DEBUG_CANCEL BUTTON_MENU
975 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
976 # define DEBUG_CANCEL BUTTON_PLAY
978 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
979 # define DEBUG_CANCEL BUTTON_REC
981 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
982 # define DEBUG_CANCEL BUTTON_RC_REC
984 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
985 # define DEBUG_CANCEL BUTTON_REW
987 #elif (CONFIG_KEYPAD == MROBE100_PAD)
988 # define DEBUG_CANCEL BUTTON_MENU
990 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
991 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
992 (CONFIG_KEYPAD == SANSA_FUZE_PAD)
993 # define DEBUG_CANCEL BUTTON_LEFT
995 /* This is temporary until the SA9200 touchpad works */
996 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) || \
997 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD)
998 # define DEBUG_CANCEL BUTTON_POWER
1000 #elif (CONFIG_KEYPAD == PHILIPS_HDD6330_PAD)
1001 # define DEBUG_CANCEL BUTTON_PREV
1003 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
1004 # define DEBUG_CANCEL BUTTON_PLAY
1006 #elif (CONFIG_KEYPAD == PBELL_VIBE500_PAD)
1007 # define DEBUG_CANCEL BUTTON_CANCEL
1009 #elif (CONFIG_KEYPAD == MPIO_HD200_PAD)
1010 # define DEBUG_CANCEL BUTTON_REC
1012 #endif /* key definitions */
1014 /* Test code!!! */
1015 bool dbg_ports(void)
1017 #if CONFIG_CPU == SH7034
1018 int adc_battery_voltage, adc_battery_level;
1020 lcd_setfont(FONT_SYSFIXED);
1021 lcd_clear_display();
1023 while(1)
1025 lcd_putsf(0, 0, "PADR: %04x", (unsigned short)PADR);
1026 lcd_putsf(0, 1, "PBDR: %04x", (unsigned short)PBDR);
1028 lcd_putsf(0, 2, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1029 lcd_putsf(0, 3, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1030 lcd_putsf(0, 4, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1031 lcd_putsf(0, 5, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1033 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1034 lcd_putsf(0, 6, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1035 adc_battery_voltage % 1000, adc_battery_level);
1037 lcd_update();
1038 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1040 lcd_setfont(FONT_UI);
1041 return false;
1044 #elif defined(CPU_COLDFIRE)
1045 unsigned int gpio_out;
1046 unsigned int gpio1_out;
1047 unsigned int gpio_read;
1048 unsigned int gpio1_read;
1049 unsigned int gpio_function;
1050 unsigned int gpio1_function;
1051 unsigned int gpio_enable;
1052 unsigned int gpio1_enable;
1053 int adc_buttons, adc_remote;
1054 int adc_battery_voltage, adc_battery_level;
1055 int line;
1057 lcd_clear_display();
1058 lcd_setfont(FONT_SYSFIXED);
1060 while(1)
1062 line = 0;
1063 gpio_read = GPIO_READ;
1064 gpio1_read = GPIO1_READ;
1065 gpio_out = GPIO_OUT;
1066 gpio1_out = GPIO1_OUT;
1067 gpio_function = GPIO_FUNCTION;
1068 gpio1_function = GPIO1_FUNCTION;
1069 gpio_enable = GPIO_ENABLE;
1070 gpio1_enable = GPIO1_ENABLE;
1072 lcd_putsf(0, line++, "GPIO_READ: %08x", gpio_read);
1073 lcd_putsf(0, line++, "GPIO_OUT: %08x", gpio_out);
1074 lcd_putsf(0, line++, "GPIO_FUNC: %08x", gpio_function);
1075 lcd_putsf(0, line++, "GPIO_ENA: %08x", gpio_enable);
1077 lcd_putsf(0, line++, "GPIO1_READ: %08x", gpio1_read);
1078 lcd_putsf(0, line++, "GPIO1_OUT: %08x", gpio1_out);
1079 lcd_putsf(0, line++, "GPIO1_FUNC: %08x", gpio1_function);
1080 lcd_putsf(0, line++, "GPIO1_ENA: %08x", gpio1_enable);
1082 adc_buttons = adc_read(ADC_BUTTONS);
1083 adc_remote = adc_read(ADC_REMOTE);
1084 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1085 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1086 lcd_putsf(0, line++, "ADC_BUTTONS (%c): %02x",
1087 button_scan_enabled() ? '+' : '-', adc_buttons);
1088 #else
1089 lcd_putsf(0, line++, "ADC_BUTTONS: %02x", adc_buttons);
1090 #endif
1091 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1092 lcd_putsf(0, line++, "ADC_REMOTE (%c): %02x",
1093 remote_detect() ? '+' : '-', adc_remote);
1094 #else
1095 lcd_putsf(0, line++, "ADC_REMOTE: %02x", adc_remote);
1096 #endif
1097 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1098 lcd_putsf(0, line++, "ADC_REMOTEDETECT: %02x",
1099 adc_read(ADC_REMOTEDETECT));
1100 #endif
1102 lcd_putsf(0, line++, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1103 adc_battery_voltage % 1000, adc_battery_level);
1105 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1106 lcd_putsf(0, line++, "remotetype: %d", remote_type());
1107 #endif
1109 lcd_update();
1110 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1112 lcd_setfont(FONT_UI);
1113 return false;
1117 #elif defined(CPU_PP502x)
1118 int line;
1120 lcd_clear_display();
1121 lcd_setfont(FONT_SYSFIXED);
1123 while(1)
1125 line = 0;
1126 #if (LCD_HEIGHT >= 176) /* Only for displays with appropriate height. */
1127 lcd_puts(0, line++, "GPIO ENABLE: GPIO OUTPUT ENABLE:");
1128 lcd_putsf(0, line++, "A: %02x E: %02x I: %02x A: %02x E: %02x I: %02x",
1129 (unsigned int)GPIOA_ENABLE,
1130 (unsigned int)GPIOE_ENABLE,
1131 (unsigned int)GPIOI_ENABLE,
1132 (unsigned int)GPIOA_OUTPUT_EN,
1133 (unsigned int)GPIOE_OUTPUT_EN,
1134 (unsigned int)GPIOI_OUTPUT_EN);
1135 lcd_putsf(0, line++, "B: %02x F: %02x J: %02x B: %02x F: %02x J: %02x",
1136 (unsigned int)GPIOB_ENABLE,
1137 (unsigned int)GPIOF_ENABLE,
1138 (unsigned int)GPIOJ_ENABLE,
1139 (unsigned int)GPIOB_OUTPUT_EN,
1140 (unsigned int)GPIOF_OUTPUT_EN,
1141 (unsigned int)GPIOJ_OUTPUT_EN);
1142 lcd_putsf(0, line++, "C: %02x G: %02x K: %02x C: %02x G: %02x K: %02x",
1143 (unsigned int)GPIOC_ENABLE,
1144 (unsigned int)GPIOG_ENABLE,
1145 (unsigned int)GPIOK_ENABLE,
1146 (unsigned int)GPIOC_OUTPUT_EN,
1147 (unsigned int)GPIOG_OUTPUT_EN,
1148 (unsigned int)GPIOK_OUTPUT_EN);
1149 lcd_putsf(0, line++, "D: %02x H: %02x L: %02x D: %02x H: %02x L: %02x",
1150 (unsigned int)GPIOD_ENABLE,
1151 (unsigned int)GPIOH_ENABLE,
1152 (unsigned int)GPIOL_ENABLE,
1153 (unsigned int)GPIOD_OUTPUT_EN,
1154 (unsigned int)GPIOH_OUTPUT_EN,
1155 (unsigned int)GPIOL_OUTPUT_EN);
1156 line++;
1157 #endif
1158 lcd_puts(0, line++, "GPIO INPUT VAL:");
1159 lcd_putsf(0, line++, "A: %02x E: %02x I: %02x",
1160 (unsigned int)GPIOA_INPUT_VAL,
1161 (unsigned int)GPIOE_INPUT_VAL,
1162 (unsigned int)GPIOI_INPUT_VAL);
1163 lcd_putsf(0, line++, "B: %02x F: %02x J: %02x",
1164 (unsigned int)GPIOB_INPUT_VAL,
1165 (unsigned int)GPIOF_INPUT_VAL,
1166 (unsigned int)GPIOJ_INPUT_VAL);
1167 lcd_putsf(0, line++, "C: %02x G: %02x K: %02x",
1168 (unsigned int)GPIOC_INPUT_VAL,
1169 (unsigned int)GPIOG_INPUT_VAL,
1170 (unsigned int)GPIOK_INPUT_VAL);
1171 lcd_putsf(0, line++, "D: %02x H: %02x L: %02x",
1172 (unsigned int)GPIOD_INPUT_VAL,
1173 (unsigned int)GPIOH_INPUT_VAL,
1174 (unsigned int)GPIOL_INPUT_VAL);
1175 line++;
1176 lcd_putsf(0, line++, "GPO32_VAL: %08lx", GPO32_VAL);
1177 lcd_putsf(0, line++, "GPO32_EN: %08lx", GPO32_ENABLE);
1178 lcd_putsf(0, line++, "DEV_EN: %08lx", DEV_EN);
1179 lcd_putsf(0, line++, "DEV_EN2: %08lx", DEV_EN2);
1180 lcd_putsf(0, line++, "DEV_EN3: %08lx", inl(0x60006044)); /* to be verified */
1181 lcd_putsf(0, line++, "DEV_INIT1: %08lx", DEV_INIT1);
1182 lcd_putsf(0, line++, "DEV_INIT2: %08lx", DEV_INIT2);
1183 #ifdef ADC_ACCESSORY
1184 lcd_putsf(0, line++, "ACCESSORY: %d", adc_read(ADC_ACCESSORY));
1185 #endif
1186 #ifdef IPOD_VIDEO
1187 lcd_putsf(0, line++, "4066_ISTAT: %d", adc_read(ADC_4066_ISTAT));
1188 #endif
1190 #if defined(IPOD_ACCESSORY_PROTOCOL)
1191 const unsigned char *serbuf = iap_get_serbuf();
1192 lcd_putsf(0, line++, "IAP PACKET: %02x %02x %02x %02x %02x %02x %02x %02x",
1193 serbuf[0], serbuf[1], serbuf[2], serbuf[3], serbuf[4], serbuf[5],
1194 serbuf[6], serbuf[7]);
1195 #endif
1197 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1198 line++;
1199 lcd_putsf(0, line++, "BATT: %03x UNK1: %03x",
1200 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1201 lcd_putsf(0, line++, "REM: %03x PAD: %03x",
1202 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1203 #elif defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330)
1204 line++;
1205 lcd_putsf(0, line++, "BATT: %03x UNK1: %03x",
1206 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1207 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1208 lcd_putsf(0, line++, "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1209 lcd_putsf(0, line++, "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1210 lcd_putsf(0, line++, "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1211 lcd_putsf(0, line++, "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1212 lcd_putsf(0, line++, "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1213 lcd_putsf(0, line++, "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1214 lcd_putsf(0, line++, "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1215 lcd_putsf(0, line++, "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1216 lcd_putsf(0, line++, "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1217 lcd_putsf(0, line++, "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1218 lcd_putsf(0, line++, "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1219 #if !defined(PHILIPS_SA9200)
1220 lcd_putsf(0, line++, "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1221 lcd_putsf(0, line++, "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1222 #endif
1223 #endif
1224 lcd_update();
1225 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1227 lcd_setfont(FONT_UI);
1228 return false;
1232 #elif CONFIG_CPU == PP5002
1233 int line;
1235 lcd_clear_display();
1236 lcd_setfont(FONT_SYSFIXED);
1238 while(1)
1240 line = 0;
1241 lcd_putsf(0, line++, "GPIO_A: %02x GPIO_B: %02x",
1242 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1243 lcd_putsf(0, line++, "GPIO_C: %02x GPIO_D: %02x",
1244 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1246 lcd_putsf(0, line++, "DEV_EN: %08lx", DEV_EN);
1247 lcd_putsf(0, line++, "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1248 lcd_putsf(0, line++, "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1249 lcd_putsf(0, line++, "PLL_CONTROL: %08lx", PLL_CONTROL);
1250 lcd_putsf(0, line++, "PLL_DIV: %08lx", PLL_DIV);
1251 lcd_putsf(0, line++, "PLL_MULT: %08lx", PLL_MULT);
1252 lcd_putsf(0, line++, "TIMING1_CTL: %08lx", TIMING1_CTL);
1253 lcd_putsf(0, line++, "TIMING2_CTL: %08lx", TIMING2_CTL);
1255 lcd_update();
1256 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1258 lcd_setfont(FONT_UI);
1259 return false;
1262 lcd_setfont(FONT_UI);
1263 #else
1264 return __dbg_ports();
1265 #endif /* CPU */
1266 return false;
1268 #else /* !HAVE_LCD_BITMAP */
1269 bool dbg_ports(void)
1271 int button;
1272 int adc_battery_voltage;
1273 int currval = 0;
1275 lcd_clear_display();
1277 while(1)
1279 if (currval == 0) {
1280 lcd_putsf(0, 0, "PADR: %04x", (unsigned short)PADR);
1281 } else if (currval == 1) {
1282 lcd_putsf(0, 0, "PBDR: %04x", (unsigned short)PBDR);
1283 } else {
1284 int idx = currval - 2; /* idx < 7 */
1285 lcd_putsf(0, 0, "AN%d: %03x", idx, adc_read(idx));
1288 battery_read_info(&adc_battery_voltage, NULL);
1289 lcd_putsf(0, 1, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1290 adc_battery_voltage % 1000);
1291 lcd_update();
1293 button = get_action(CONTEXT_SETTINGS,HZ/5);
1295 switch(button)
1297 case ACTION_STD_CANCEL:
1298 return false;
1300 case ACTION_SETTINGS_DEC:
1301 currval--;
1302 if(currval < 0)
1303 currval = 9;
1304 break;
1306 case ACTION_SETTINGS_INC:
1307 currval++;
1308 if(currval > 9)
1309 currval = 0;
1310 break;
1313 return false;
1315 #endif /* !HAVE_LCD_BITMAP */
1316 #endif /* PLATFORM_NATIVE */
1318 #if (CONFIG_RTC == RTC_PCF50605) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
1319 static bool dbg_pcf(void)
1321 int line;
1323 #ifdef HAVE_LCD_BITMAP
1324 lcd_setfont(FONT_SYSFIXED);
1325 #endif
1326 lcd_clear_display();
1328 while(1)
1330 line = 0;
1332 lcd_putsf(0, line++, "DCDC1: %02x", pcf50605_read(0x1b));
1333 lcd_putsf(0, line++, "DCDC2: %02x", pcf50605_read(0x1c));
1334 lcd_putsf(0, line++, "DCDC3: %02x", pcf50605_read(0x1d));
1335 lcd_putsf(0, line++, "DCDC4: %02x", pcf50605_read(0x1e));
1336 lcd_putsf(0, line++, "DCDEC1: %02x", pcf50605_read(0x1f));
1337 lcd_putsf(0, line++, "DCDEC2: %02x", pcf50605_read(0x20));
1338 lcd_putsf(0, line++, "DCUDC1: %02x", pcf50605_read(0x21));
1339 lcd_putsf(0, line++, "DCUDC2: %02x", pcf50605_read(0x22));
1340 lcd_putsf(0, line++, "IOREGC: %02x", pcf50605_read(0x23));
1341 lcd_putsf(0, line++, "D1REGC: %02x", pcf50605_read(0x24));
1342 lcd_putsf(0, line++, "D2REGC: %02x", pcf50605_read(0x25));
1343 lcd_putsf(0, line++, "D3REGC: %02x", pcf50605_read(0x26));
1344 lcd_putsf(0, line++, "LPREG1: %02x", pcf50605_read(0x27));
1345 lcd_update();
1346 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1348 lcd_setfont(FONT_UI);
1349 return false;
1353 lcd_setfont(FONT_UI);
1354 return false;
1356 #endif
1358 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1359 static bool dbg_cpufreq(void)
1361 int line;
1362 int button;
1364 #ifdef HAVE_LCD_BITMAP
1365 lcd_setfont(FONT_SYSFIXED);
1366 #endif
1367 lcd_clear_display();
1369 while(1)
1371 line = 0;
1373 lcd_putsf(0, line++, "Frequency: %ld", FREQ);
1374 lcd_putsf(0, line++, "boost_counter: %d", get_cpu_boost_counter());
1376 lcd_update();
1377 button = get_action(CONTEXT_STD,HZ/10);
1379 switch(button)
1381 case ACTION_STD_PREV:
1382 cpu_boost(true);
1383 break;
1385 case ACTION_STD_NEXT:
1386 cpu_boost(false);
1387 break;
1389 case ACTION_STD_OK:
1390 while (get_cpu_boost_counter() > 0)
1391 cpu_boost(false);
1392 set_cpu_frequency(CPUFREQ_DEFAULT);
1393 break;
1395 case ACTION_STD_CANCEL:
1396 lcd_setfont(FONT_UI);
1397 return false;
1400 lcd_setfont(FONT_UI);
1401 return false;
1403 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1405 #if defined(HAVE_TSC2100) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
1406 #include "tsc2100.h"
1407 static char *itob(int n, int len)
1409 static char binary[64];
1410 int i,j;
1411 for (i=1, j=0;i<=len;i++)
1413 binary[j++] = n&(1<<(len-i))?'1':'0';
1414 if (i%4 == 0)
1415 binary[j++] = ' ';
1417 binary[j] = '\0';
1418 return binary;
1421 static const char* tsc2100_debug_getname(int selected_item, void * data,
1422 char *buffer, size_t buffer_len)
1424 int *page = (int*)data;
1425 bool reserved = false;
1426 switch (*page)
1428 case 0:
1429 if ((selected_item > 0x0a) ||
1430 (selected_item == 0x04) ||
1431 (selected_item == 0x08))
1432 reserved = true;
1433 break;
1434 case 1:
1435 if ((selected_item > 0x05) ||
1436 (selected_item == 0x02))
1437 reserved = true;
1438 break;
1439 case 2:
1440 if (selected_item > 0x1e)
1441 reserved = true;
1442 break;
1444 if (reserved)
1445 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1446 else
1447 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1448 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1449 return buffer;
1451 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1453 int *page = (int*)lists->data;
1454 if (action == ACTION_STD_OK)
1456 *page = (*page+1)%3;
1457 snprintf(lists->title, 32,
1458 "tsc2100 registers - Page %d", *page);
1459 return ACTION_REDRAW;
1461 return action;
1463 static bool tsc2100_debug(void)
1465 int page = 0;
1466 char title[32] = "tsc2100 registers - Page 0";
1467 struct simplelist_info info;
1468 simplelist_info_init(&info, title, 32, &page);
1469 info.timeout = HZ/100;
1470 info.get_name = tsc2100_debug_getname;
1471 info.action_callback= tsc2100debug_action_callback;
1472 return simplelist_show_list(&info);
1474 #endif
1475 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
1476 #ifdef HAVE_LCD_BITMAP
1478 * view_battery() shows a automatically scaled graph of the battery voltage
1479 * over time. Usable for estimating battery life / charging rate.
1480 * The power_history array is updated in power_thread of powermgmt.c.
1483 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1484 #define BAT_YSPACE (LCD_HEIGHT - 20)
1487 static bool view_battery(void)
1489 int view = 0;
1490 int i, x, y, y1, y2, grid, graph;
1491 unsigned short maxv, minv;
1493 lcd_setfont(FONT_SYSFIXED);
1495 while(1)
1497 lcd_clear_display();
1498 switch (view) {
1499 case 0: /* voltage history graph */
1500 /* Find maximum and minimum voltage for scaling */
1501 minv = power_history[0];
1502 maxv = minv + 1;
1503 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1504 if (power_history[i] > maxv)
1505 maxv = power_history[i];
1506 if (power_history[i] < minv)
1507 minv = power_history[i];
1510 /* adjust grid scale */
1511 if ((maxv - minv) > 50)
1512 grid = 50;
1513 else
1514 grid = 5;
1516 /* print header */
1517 lcd_putsf(0, 0, "battery %d.%03dV", power_history[0] / 1000,
1518 power_history[0] % 1000);
1519 lcd_putsf(0, 1, "%d.%03d-%d.%03dV (%2dmV)",
1520 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000,
1521 grid);
1523 i = 1;
1524 while ((y = (minv - (minv % grid)+i*grid)) < maxv)
1526 graph = ((y-minv)*BAT_YSPACE)/(maxv-minv);
1527 graph = LCD_HEIGHT-1 - graph;
1529 /* draw dotted horizontal grid line */
1530 for (x=0; x<LCD_WIDTH;x=x+2)
1531 lcd_drawpixel(x,graph);
1533 i++;
1536 x = 0;
1537 /* draw plot of power history
1538 * skip empty entries
1540 for (i = BAT_LAST_VAL - 1; i > 0; i--)
1542 if (power_history[i] && power_history[i-1])
1544 y1 = (power_history[i] - minv) * BAT_YSPACE /
1545 (maxv - minv);
1546 y1 = MIN(MAX(LCD_HEIGHT-1 - y1, 20),
1547 LCD_HEIGHT-1);
1548 y2 = (power_history[i-1] - minv) * BAT_YSPACE /
1549 (maxv - minv);
1550 y2 = MIN(MAX(LCD_HEIGHT-1 - y2, 20),
1551 LCD_HEIGHT-1);
1553 lcd_set_drawmode(DRMODE_SOLID);
1555 /* make line thicker */
1556 lcd_drawline(((x*LCD_WIDTH)/(BAT_LAST_VAL)),
1557 y1,
1558 (((x+1)*LCD_WIDTH)/(BAT_LAST_VAL)),
1559 y2);
1560 lcd_drawline(((x*LCD_WIDTH)/(BAT_LAST_VAL))+1,
1561 y1+1,
1562 (((x+1)*LCD_WIDTH)/(BAT_LAST_VAL))+1,
1563 y2+1);
1564 x++;
1567 break;
1569 case 1: /* status: */
1570 #if CONFIG_CHARGING >= CHARGING_MONITOR
1571 lcd_putsf(0, 0, "Pwr status: %s",
1572 charging_state() ? "charging" : "discharging");
1573 #else
1574 lcd_puts(0, 0, "Power status:");
1575 #endif
1576 battery_read_info(&y, NULL);
1577 lcd_putsf(0, 1, "Battery: %d.%03d V", y / 1000, y % 1000);
1578 #ifdef ADC_EXT_POWER
1579 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1580 lcd_putsf(0, 2, "External: %d.%03d V", y / 1000, y % 1000);
1581 #endif
1582 #if CONFIG_CHARGING
1583 #if defined ARCHOS_RECORDER
1584 lcd_putsf(0, 3, "Chgr: %s %s",
1585 charger_inserted() ? "present" : "absent",
1586 charger_enabled() ? "on" : "off");
1587 lcd_putsf(0, 5, "short delta: %d", short_delta);
1588 lcd_putsf(0, 6, "long delta: %d", long_delta);
1589 lcd_puts(0, 7, power_message);
1590 lcd_putsf(0, 8, "USB Inserted: %s",
1591 usb_inserted() ? "yes" : "no");
1592 #elif defined IPOD_NANO || defined IPOD_VIDEO
1593 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1594 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1595 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1596 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1597 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1599 lcd_putsf(0, 3, "USB pwr: %s",
1600 usb_pwr ? "present" : "absent");
1601 lcd_putsf(0, 4, "EXT pwr: %s",
1602 ext_pwr ? "present" : "absent");
1603 lcd_putsf(0, 5, "Battery: %s",
1604 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1605 lcd_putsf(0, 6, "Dock mode: %s",
1606 dock ? "enabled" : "disabled");
1607 lcd_putsf(0, 7, "Headphone: %s",
1608 headphone ? "connected" : "disconnected");
1609 #ifdef IPOD_VIDEO
1610 if(probed_ramsize == 64)
1611 x = (adc_read(ADC_4066_ISTAT) * 2400) / (1024 * 2);
1612 else
1613 x = (adc_read(ADC_4066_ISTAT) * 2400) / (1024 * 3);
1614 lcd_putsf(0, 8, "Ibat: %d mA", x);
1615 lcd_putsf(0, 9, "Vbat * Ibat: %d mW", x * y / 1000);
1616 #endif
1617 #elif defined TOSHIBA_GIGABEAT_S
1618 int line = 3;
1619 unsigned int st;
1621 static const unsigned char * const chrgstate_strings[] =
1623 "Disabled",
1624 "Error",
1625 "Discharging",
1626 "Precharge",
1627 "Constant Voltage",
1628 "Constant Current",
1629 "<unknown>",
1632 lcd_putsf(0, line++, "Charger: %s",
1633 charger_inserted() ? "present" : "absent");
1635 st = power_input_status() &
1636 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1637 lcd_putsf(0, line++, "%s%s",
1638 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1639 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1641 y = ARRAYLEN(chrgstate_strings) - 1;
1643 switch (charge_state)
1645 case CHARGE_STATE_DISABLED: y--;
1646 case CHARGE_STATE_ERROR: y--;
1647 case DISCHARGING: y--;
1648 case TRICKLE: y--;
1649 case TOPOFF: y--;
1650 case CHARGING: y--;
1651 default:;
1654 lcd_putsf(0, line++, "State: %s", chrgstate_strings[y]);
1656 lcd_putsf(0, line++, "Battery Switch: %s",
1657 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1659 y = chrgraw_adc_voltage();
1660 lcd_putsf(0, line++, "CHRGRAW: %d.%03d V",
1661 y / 1000, y % 1000);
1663 y = application_supply_adc_voltage();
1664 lcd_putsf(0, line++, "BP : %d.%03d V",
1665 y / 1000, y % 1000);
1667 y = battery_adc_charge_current();
1668 if (y < 0) x = '-', y = -y;
1669 else x = ' ';
1670 lcd_putsf(0, line++, "CHRGISN:%c%d mA", x, y);
1672 y = cccv_regulator_dissipation();
1673 lcd_putsf(0, line++, "P CCCV : %d mW", y);
1675 y = battery_charge_current();
1676 if (y < 0) x = '-', y = -y;
1677 else x = ' ';
1678 lcd_putsf(0, line++, "I Charge:%c%d mA", x, y);
1680 y = battery_adc_temp();
1682 if (y != INT_MIN) {
1683 lcd_putsf(0, line++, "T Battery: %dC (%dF)", y,
1684 (9*y + 160) / 5);
1685 } else {
1686 /* Conversion disabled */
1687 lcd_puts(0, line++, "T Battery: ?");
1690 #elif defined(SANSA_E200) || defined(SANSA_C200) || CONFIG_CPU == AS3525 || \
1691 CONFIG_CPU == AS3525v2
1692 static const char * const chrgstate_strings[] =
1694 [CHARGE_STATE_DISABLED - CHARGE_STATE_DISABLED]= "Disabled",
1695 [CHARGE_STATE_ERROR - CHARGE_STATE_DISABLED] = "Error",
1696 [DISCHARGING - CHARGE_STATE_DISABLED] = "Discharging",
1697 [CHARGING - CHARGE_STATE_DISABLED] = "Charging",
1699 const char *str = NULL;
1701 lcd_putsf(0, 3, "Charger: %s",
1702 charger_inserted() ? "present" : "absent");
1704 y = charge_state - CHARGE_STATE_DISABLED;
1705 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1706 str = chrgstate_strings[y];
1708 lcd_putsf(0, 4, "State: %s",
1709 str ? str : "<unknown>");
1711 lcd_putsf(0, 5, "CHARGER: %02X", ascodec_read_charger());
1712 #elif defined(IPOD_NANO2G)
1713 y = pmu_read_battery_voltage();
1714 lcd_putsf(17, 1, "RAW: %d.%03d V", y / 1000, y % 1000);
1715 y = pmu_read_battery_current();
1716 lcd_putsf(0, 2, "Battery current: %d mA", y);
1717 lcd_putsf(0, 3, "PWRCON: %8x", PWRCON);
1718 lcd_putsf(0, 4, "PWRCONEXT: %8x", PWRCONEXT);
1719 x = pmu_read(0x1b) & 0xf;
1720 y = pmu_read(0x1a) * 25 + 625;
1721 lcd_putsf(0, 5, "AUTO: %x / %d mV", x, y);
1722 x = pmu_read(0x1f) & 0xf;
1723 y = pmu_read(0x1e) * 25 + 625;
1724 lcd_putsf(0, 6, "DOWN1: %x / %d mV", x, y);
1725 x = pmu_read(0x23) & 0xf;
1726 y = pmu_read(0x22) * 25 + 625;
1727 lcd_putsf(0, 7, "DOWN2: %x / %d mV", x, y);
1728 x = pmu_read(0x27) & 0xf;
1729 y = pmu_read(0x26) * 100 + 900;
1730 lcd_putsf(0, 8, "MEMLDO: %x / %d mV", x, y);
1731 for (i = 0; i < 6; i++)
1733 x = pmu_read(0x2e + (i << 1)) & 0xf;
1734 y = pmu_read(0x2d + (i << 1)) * 100 + 900;
1735 lcd_putsf(0, 9 + i, "LDO%d: %x / %d mV", i + 1, x, y);
1737 lcd_putsf(0, 15, "CLKCON: %8x", CLKCON);
1738 lcd_putsf(17, 15, "PLL0: %6x", PLL0PMS);
1739 #else
1740 lcd_putsf(0, 3, "Charger: %s",
1741 charger_inserted() ? "present" : "absent");
1742 #endif /* target type */
1743 #endif /* CONFIG_CHARGING */
1744 break;
1746 case 2: /* voltage deltas: */
1747 lcd_puts(0, 0, "Voltage deltas:");
1749 for (i = 0; i <= 6; i++) {
1750 y = power_history[i] - power_history[i+1];
1751 lcd_putsf(0, i+1, "-%d min: %s%d.%03d V", i,
1752 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1753 ((y < 0) ? y * -1 : y ) % 1000);
1755 break;
1757 case 3: /* remaining time estimation: */
1759 #ifdef ARCHOS_RECORDER
1760 lcd_putsf(0, 0, "charge_state: %d", charge_state);
1762 lcd_putsf(0, 1, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1764 lcd_putsf(0, 2, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1766 lcd_putsf(0, 3, "P=%2d I=%2d", pid_p, pid_i);
1768 lcd_putsf(0, 4, "Trickle sec: %d/60", trickle_sec);
1769 #endif /* ARCHOS_RECORDER */
1771 lcd_putsf(0, 5, "Last PwrHist: %d.%03dV",
1772 power_history[0] / 1000,
1773 power_history[0] % 1000);
1775 lcd_putsf(0, 6, "battery level: %d%%", battery_level());
1777 lcd_putsf(0, 7, "Est. remain: %d m", battery_time());
1778 break;
1781 lcd_update();
1783 switch(get_action(CONTEXT_STD,HZ/2))
1785 case ACTION_STD_PREV:
1786 if (view)
1787 view--;
1788 break;
1790 case ACTION_STD_NEXT:
1791 if (view < 3)
1792 view++;
1793 break;
1795 case ACTION_STD_CANCEL:
1796 lcd_setfont(FONT_UI);
1797 return false;
1800 lcd_setfont(FONT_UI);
1801 return false;
1804 #endif /* HAVE_LCD_BITMAP */
1805 #endif
1807 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
1808 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1810 #if (CONFIG_STORAGE & STORAGE_MMC)
1811 #define CARDTYPE "MMC"
1812 #elif (CONFIG_STORAGE & STORAGE_SD)
1813 #define CARDTYPE "microSD"
1814 #endif
1816 static int disk_callback(int btn, struct gui_synclist *lists)
1818 tCardInfo *card;
1819 int *cardnum = (int*)lists->data;
1820 unsigned char card_name[6];
1821 unsigned char pbuf[32];
1822 char *title = lists->title;
1823 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1824 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1825 static const unsigned char * const kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1826 static const unsigned char * const nsec_units[] = { "ns", "µs", "ms" };
1827 #if (CONFIG_STORAGE & STORAGE_MMC)
1828 static const char * const mmc_spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1829 "3.1-3.31", "4.0" };
1830 #endif
1832 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1834 #ifdef HAVE_HOTSWAP
1835 if (btn == ACTION_STD_OK)
1837 *cardnum ^= 0x1; /* change cards */
1839 #endif
1841 simplelist_set_line_count(0);
1843 card = card_get_info(*cardnum);
1845 if (card->initialized > 0)
1847 unsigned i;
1848 for (i=0; i<sizeof(card_name); i++)
1850 card_name[i] = card_extract_bits(card->cid, (103-8*i), 8);
1852 strlcpy(card_name, card_name, sizeof(card_name));
1853 simplelist_addline(SIMPLELIST_ADD_LINE,
1854 "%s Rev %d.%d", card_name,
1855 (int) card_extract_bits(card->cid, 63, 4),
1856 (int) card_extract_bits(card->cid, 59, 4));
1857 simplelist_addline(SIMPLELIST_ADD_LINE,
1858 "Prod: %d/%d",
1859 #if (CONFIG_STORAGE & STORAGE_SD)
1860 (int) card_extract_bits(card->cid, 11, 4),
1861 (int) card_extract_bits(card->cid, 19, 8) + 2000
1862 #elif (CONFIG_STORAGE & STORAGE_MMC)
1863 (int) card_extract_bits(card->cid, 15, 4),
1864 (int) card_extract_bits(card->cid, 11, 4) + 1997
1865 #endif
1867 simplelist_addline(SIMPLELIST_ADD_LINE,
1868 #if (CONFIG_STORAGE & STORAGE_SD)
1869 "Ser#: 0x%08lx",
1870 card_extract_bits(card->cid, 55, 32)
1871 #elif (CONFIG_STORAGE & STORAGE_MMC)
1872 "Ser#: 0x%04lx",
1873 card_extract_bits(card->cid, 47, 16)
1874 #endif
1877 simplelist_addline(SIMPLELIST_ADD_LINE, "M=%02x, "
1878 #if (CONFIG_STORAGE & STORAGE_SD)
1879 "O=%c%c",
1880 (int) card_extract_bits(card->cid, 127, 8),
1881 card_extract_bits(card->cid, 119, 8),
1882 card_extract_bits(card->cid, 111, 8)
1883 #elif (CONFIG_STORAGE & STORAGE_MMC)
1884 "O=%04x",
1885 (int) card_extract_bits(card->cid, 127, 8),
1886 (int) card_extract_bits(card->cid, 119, 16)
1887 #endif
1890 #if (CONFIG_STORAGE & STORAGE_MMC)
1891 int temp = card_extract_bits(card->csd, 125, 4);
1892 simplelist_addline(SIMPLELIST_ADD_LINE,
1893 "MMC v%s", temp < 5 ?
1894 mmc_spec_vers[temp] : "?.?");
1895 #endif
1896 simplelist_addline(SIMPLELIST_ADD_LINE,
1897 "Blocks: 0x%08lx", card->numblocks);
1898 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1899 kbit_units, false);
1900 simplelist_addline(SIMPLELIST_ADD_LINE,
1901 "Speed: %s", pbuf);
1902 output_dyn_value(pbuf, sizeof pbuf, card->taac,
1903 nsec_units, false);
1904 simplelist_addline(SIMPLELIST_ADD_LINE,
1905 "Taac: %s", pbuf);
1906 simplelist_addline(SIMPLELIST_ADD_LINE,
1907 "Nsac: %d clk", card->nsac);
1908 simplelist_addline(SIMPLELIST_ADD_LINE,
1909 "R2W: *%d", card->r2w_factor);
1910 simplelist_addline(SIMPLELIST_ADD_LINE,
1911 "IRmax: %d..%d mA",
1912 i_vmin[card_extract_bits(card->csd, 61, 3)],
1913 i_vmax[card_extract_bits(card->csd, 58, 3)]);
1914 simplelist_addline(SIMPLELIST_ADD_LINE,
1915 "IWmax: %d..%d mA",
1916 i_vmin[card_extract_bits(card->csd, 55, 3)],
1917 i_vmax[card_extract_bits(card->csd, 52, 3)]);
1919 else if (card->initialized == 0)
1921 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1923 #if (CONFIG_STORAGE & STORAGE_SD)
1924 else /* card->initialized < 0 */
1926 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1928 #endif
1929 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1930 gui_synclist_set_title(lists, title, Icon_NOICON);
1931 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1932 gui_synclist_select_item(lists, 0);
1933 btn = ACTION_REDRAW;
1935 return btn;
1937 #elif (CONFIG_STORAGE & STORAGE_ATA)
1938 static int disk_callback(int btn, struct gui_synclist *lists)
1940 (void)lists;
1941 int i;
1942 char buf[128];
1943 unsigned short* identify_info = ata_get_identify();
1944 bool timing_info_present = false;
1945 (void)btn;
1947 simplelist_set_line_count(0);
1949 for (i=0; i < 20; i++)
1950 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1951 buf[40]=0;
1952 /* kill trailing space */
1953 for (i=39; i && buf[i]==' '; i--)
1954 buf[i] = 0;
1955 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1956 for (i=0; i < 4; i++)
1957 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1958 buf[8]=0;
1959 simplelist_addline(SIMPLELIST_ADD_LINE,
1960 "Firmware: %s", buf);
1961 snprintf(buf, sizeof buf, "%ld MB",
1962 ((unsigned long)identify_info[61] << 16 |
1963 (unsigned long)identify_info[60]) / 2048 );
1964 simplelist_addline(SIMPLELIST_ADD_LINE,
1965 "Size: %s", buf);
1966 unsigned long free;
1967 fat_size( IF_MV2(0,) NULL, &free );
1968 simplelist_addline(SIMPLELIST_ADD_LINE,
1969 "Free: %ld MB", free / 1024);
1970 simplelist_addline(SIMPLELIST_ADD_LINE,
1971 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
1972 i = identify_info[83] & (1<<3);
1973 simplelist_addline(SIMPLELIST_ADD_LINE,
1974 "Power mgmt: %s", i ? "enabled" : "unsupported");
1975 i = identify_info[83] & (1<<9);
1976 simplelist_addline(SIMPLELIST_ADD_LINE,
1977 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1978 i = identify_info[82] & (1<<6);
1979 simplelist_addline(SIMPLELIST_ADD_LINE,
1980 "Read-ahead: %s", i ? "enabled" : "unsupported");
1981 timing_info_present = identify_info[53] & (1<<1);
1982 if(timing_info_present) {
1983 char pio3[2], pio4[2];pio3[1] = 0;
1984 pio4[1] = 0;
1985 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1986 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1987 simplelist_addline(SIMPLELIST_ADD_LINE,
1988 "PIO modes: 0 1 2 %s %s", pio3, pio4);
1990 else {
1991 simplelist_addline(SIMPLELIST_ADD_LINE,
1992 "No PIO mode info");
1994 timing_info_present = identify_info[53] & (1<<1);
1995 if(timing_info_present) {
1996 simplelist_addline(SIMPLELIST_ADD_LINE,
1997 "Cycle times %dns/%dns",
1998 identify_info[67],
1999 identify_info[68] );
2000 } else {
2001 simplelist_addline(SIMPLELIST_ADD_LINE,
2002 "No timing info");
2004 int sector_size = 512;
2005 if((identify_info[106] & 0xe000) == 0x6000)
2006 sector_size *= BIT_N(identify_info[106] & 0x000f);
2007 simplelist_addline(SIMPLELIST_ADD_LINE,
2008 "Physical sector size: %d", sector_size);
2009 #ifdef HAVE_ATA_DMA
2010 if (identify_info[63] & (1<<0)) {
2011 char mdma0[2], mdma1[2], mdma2[2];
2012 mdma0[1] = mdma1[1] = mdma2[1] = 0;
2013 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
2014 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
2015 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
2016 simplelist_addline(SIMPLELIST_ADD_LINE,
2017 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
2018 simplelist_addline(SIMPLELIST_ADD_LINE,
2019 "MDMA Cycle times %dns/%dns",
2020 identify_info[65],
2021 identify_info[66] );
2023 else {
2024 simplelist_addline(SIMPLELIST_ADD_LINE,
2025 "No MDMA mode info");
2027 if (identify_info[53] & (1<<2)) {
2028 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2], udma6[2];
2029 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = udma6[1] = 0;
2030 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
2031 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
2032 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
2033 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
2034 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
2035 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
2036 udma6[0] = (identify_info[88] & (1<<6)) ? '6' : 0;
2037 simplelist_addline(SIMPLELIST_ADD_LINE,
2038 "UDMA modes: %s %s %s %s %s %s %s", udma0, udma1, udma2,
2039 udma3, udma4, udma5, udma6);
2041 else {
2042 simplelist_addline(SIMPLELIST_ADD_LINE,
2043 "No UDMA mode info");
2045 #endif /* HAVE_ATA_DMA */
2046 timing_info_present = identify_info[53] & (1<<1);
2047 if(timing_info_present) {
2048 i = identify_info[49] & (1<<11);
2049 simplelist_addline(SIMPLELIST_ADD_LINE,
2050 "IORDY support: %s", i ? "yes" : "no");
2051 i = identify_info[49] & (1<<10);
2052 simplelist_addline(SIMPLELIST_ADD_LINE,
2053 "IORDY disable: %s", i ? "yes" : "no");
2054 } else {
2055 simplelist_addline(SIMPLELIST_ADD_LINE,
2056 "No timing info");
2058 simplelist_addline(SIMPLELIST_ADD_LINE,
2059 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2060 #ifdef HAVE_ATA_DMA
2061 i = ata_get_dma_mode();
2062 if (i == 0) {
2063 simplelist_addline(SIMPLELIST_ADD_LINE,
2064 "DMA not enabled");
2065 } else {
2066 simplelist_addline(SIMPLELIST_ADD_LINE,
2067 "DMA mode: %s %c",
2068 (i & 0x40) ? "UDMA" : "MDMA",
2069 '0' + (i & 7));
2071 #endif /* HAVE_ATA_DMA */
2072 return btn;
2074 #else /* No SD, MMC or ATA */
2075 static int disk_callback(int btn, struct gui_synclist *lists)
2077 (void)btn;
2078 (void)lists;
2079 struct storage_info info;
2080 storage_get_info(0,&info);
2081 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
2082 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
2083 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
2084 simplelist_addline(SIMPLELIST_ADD_LINE,
2085 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
2086 unsigned long free;
2087 fat_size( IF_MV2(0,) NULL, &free );
2088 simplelist_addline(SIMPLELIST_ADD_LINE,
2089 "Free: %ld MB", free / 1024);
2090 simplelist_addline(SIMPLELIST_ADD_LINE,
2091 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2092 return btn;
2094 #endif
2096 #if (CONFIG_STORAGE & STORAGE_ATA)
2097 static bool dbg_identify_info(void)
2099 int fd = creat("/identify_info.bin", 0666);
2100 if(fd >= 0)
2102 #ifdef ROCKBOX_LITTLE_ENDIAN
2103 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
2104 #else
2105 write(fd, ata_get_identify(), SECTOR_SIZE);
2106 #endif
2107 close(fd);
2109 return false;
2111 #endif
2113 static bool dbg_disk_info(void)
2115 struct simplelist_info info;
2116 simplelist_info_init(&info, "Disk Info", 1, NULL);
2117 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
2118 char title[16];
2119 int card = 0;
2120 info.callback_data = (void*)&card;
2121 info.title = title;
2122 #endif
2123 info.action_callback = disk_callback;
2124 info.hide_selection = true;
2125 info.scroll_all = true;
2126 return simplelist_show_list(&info);
2128 #endif /* PLATFORM_NATIVE */
2130 #ifdef HAVE_DIRCACHE
2131 static int dircache_callback(int btn, struct gui_synclist *lists)
2133 (void)btn; (void)lists;
2134 simplelist_set_line_count(0);
2135 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
2136 dircache_is_enabled() ? "Yes" : "No");
2137 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
2138 dircache_get_cache_size());
2139 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
2140 global_status.dircache_size);
2141 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
2142 DIRCACHE_LIMIT);
2143 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
2144 dircache_get_reserve_used(), DIRCACHE_RESERVE);
2145 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2146 dircache_get_build_ticks() / HZ);
2147 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2148 dircache_get_entry_count());
2149 return btn;
2152 static bool dbg_dircache_info(void)
2154 struct simplelist_info info;
2155 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2156 info.action_callback = dircache_callback;
2157 info.hide_selection = true;
2158 info.scroll_all = true;
2159 return simplelist_show_list(&info);
2162 #endif /* HAVE_DIRCACHE */
2164 #ifdef HAVE_TAGCACHE
2165 static int database_callback(int btn, struct gui_synclist *lists)
2167 (void)lists;
2168 struct tagcache_stat *stat = tagcache_get_stat();
2169 static bool synced = false;
2171 simplelist_set_line_count(0);
2173 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2174 stat->initialized ? "Yes" : "No");
2175 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2176 stat->ready ? "Yes" : "No");
2177 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2178 stat->ramcache ? "Yes" : "No");
2179 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2180 stat->ramcache_used, stat->ramcache_allocated);
2181 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2182 stat->progress, stat->processed_entries);
2183 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2184 stat->curentry ? stat->curentry : "---");
2185 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2186 stat->commit_step);
2187 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2188 stat->commit_delayed ? "Yes" : "No");
2190 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2191 stat->queue_length);
2193 if (synced)
2195 synced = false;
2196 tagcache_screensync_event();
2199 if (!btn && stat->curentry)
2201 synced = true;
2202 return ACTION_REDRAW;
2205 if (btn == ACTION_STD_CANCEL)
2206 tagcache_screensync_enable(false);
2208 return btn;
2210 static bool dbg_tagcache_info(void)
2212 struct simplelist_info info;
2213 simplelist_info_init(&info, "Database Info", 8, NULL);
2214 info.action_callback = database_callback;
2215 info.hide_selection = true;
2216 info.scroll_all = true;
2218 /* Don't do nonblock here, must give enough processing time
2219 for tagcache thread. */
2220 /* info.timeout = TIMEOUT_NOBLOCK; */
2221 info.timeout = 1;
2222 tagcache_screensync_enable(true);
2223 return simplelist_show_list(&info);
2225 #endif
2227 #if CONFIG_CPU == SH7034
2228 static bool dbg_save_roms(void)
2230 int fd;
2231 int oldmode = system_memory_guard(MEMGUARD_NONE);
2233 fd = creat("/internal_rom_0000-FFFF.bin", 0666);
2234 if(fd >= 0)
2236 write(fd, (void *)0, 0x10000);
2237 close(fd);
2240 fd = creat("/internal_rom_2000000-203FFFF.bin", 0666);
2241 if(fd >= 0)
2243 write(fd, (void *)0x2000000, 0x40000);
2244 close(fd);
2247 system_memory_guard(oldmode);
2248 return false;
2250 #elif defined CPU_COLDFIRE
2251 static bool dbg_save_roms(void)
2253 int fd;
2254 int oldmode = system_memory_guard(MEMGUARD_NONE);
2256 #if defined(IRIVER_H100_SERIES)
2257 fd = creat("/internal_rom_000000-1FFFFF.bin", 0666);
2258 #elif defined(IRIVER_H300_SERIES)
2259 fd = creat("/internal_rom_000000-3FFFFF.bin", 0666);
2260 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2261 fd = creat("/internal_rom_000000-3FFFFF.bin", 0666);
2262 #elif defined(MPIO_HD200)
2263 fd = creat("/internal_rom_000000-1FFFFF.bin", 0666);
2264 #endif
2265 if(fd >= 0)
2267 write(fd, (void *)0, FLASH_SIZE);
2268 close(fd);
2270 system_memory_guard(oldmode);
2272 #ifdef HAVE_EEPROM
2273 fd = creat("/internal_eeprom.bin", 0666);
2274 if (fd >= 0)
2276 int old_irq_level;
2277 char buf[EEPROM_SIZE];
2278 int err;
2280 old_irq_level = disable_irq_save();
2282 err = eeprom_24cxx_read(0, buf, sizeof buf);
2284 restore_irq(old_irq_level);
2286 if (err)
2287 splashf(HZ*3, "Eeprom read failure (%d)", err);
2288 else
2290 write(fd, buf, sizeof buf);
2293 close(fd);
2295 #endif
2297 return false;
2299 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
2300 static bool dbg_save_roms(void)
2302 int fd;
2304 fd = creat("/internal_rom_000000-0FFFFF.bin", 0666);
2305 if(fd >= 0)
2307 write(fd, (void *)0x20000000, FLASH_SIZE);
2308 close(fd);
2311 return false;
2313 #elif CONFIG_CPU == IMX31L
2314 static bool dbg_save_roms(void)
2316 int fd;
2318 fd = creat("/flash_rom_A0000000-A01FFFFF.bin", 0666);
2319 if (fd >= 0)
2321 write(fd, (void*)0xa0000000, FLASH_SIZE);
2322 close(fd);
2325 return false;
2327 #elif defined(CPU_TCC780X)
2328 static bool dbg_save_roms(void)
2330 int fd;
2332 fd = creat("/eeprom_E0000000-E0001FFF.bin", 0666);
2333 if (fd >= 0)
2335 write(fd, (void*)0xe0000000, 0x2000);
2336 close(fd);
2339 return false;
2341 #endif /* CPU */
2343 #ifndef SIMULATOR
2344 #if CONFIG_TUNER
2346 #ifdef CONFIG_TUNER_MULTI
2347 static int tuner_type = 0;
2348 #define IF_TUNER_TYPE(type) if(tuner_type==type)
2349 #else
2350 #define IF_TUNER_TYPE(type)
2351 #endif
2353 static int radio_callback(int btn, struct gui_synclist *lists)
2355 (void)lists;
2356 if (btn == ACTION_STD_CANCEL)
2357 return btn;
2358 simplelist_set_line_count(1);
2360 #if (CONFIG_TUNER & LV24020LP)
2361 simplelist_addline(SIMPLELIST_ADD_LINE,
2362 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2363 simplelist_addline(SIMPLELIST_ADD_LINE,
2364 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2365 simplelist_addline(SIMPLELIST_ADD_LINE,
2366 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2367 simplelist_addline(SIMPLELIST_ADD_LINE,
2368 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2369 simplelist_addline(SIMPLELIST_ADD_LINE,
2370 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2371 simplelist_addline(SIMPLELIST_ADD_LINE,
2372 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2373 simplelist_addline(SIMPLELIST_ADD_LINE,
2374 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2375 #endif /* LV24020LP */
2376 #if (CONFIG_TUNER & S1A0903X01)
2377 simplelist_addline(SIMPLELIST_ADD_LINE,
2378 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2379 /* This one doesn't return dynamic data atm */
2380 #endif /* S1A0903X01 */
2381 #if (CONFIG_TUNER & TEA5767)
2382 struct tea5767_dbg_info nfo;
2383 tea5767_dbg_info(&nfo);
2384 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2385 simplelist_addline(SIMPLELIST_ADD_LINE,
2386 " Read: %02X %02X %02X %02X %02X",
2387 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2388 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2389 (unsigned)nfo.read_regs[4]);
2390 simplelist_addline(SIMPLELIST_ADD_LINE,
2391 " Write: %02X %02X %02X %02X %02X",
2392 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2393 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2394 (unsigned)nfo.write_regs[4]);
2395 #endif /* TEA5767 */
2396 #if (CONFIG_TUNER & SI4700)
2397 IF_TUNER_TYPE(SI4700)
2399 struct si4700_dbg_info nfo;
2400 int i;
2401 si4700_dbg_info(&nfo);
2402 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
2403 for (i = 0; i < 16; i += 4) {
2404 simplelist_addline(SIMPLELIST_ADD_LINE,"%02X: %04X %04X %04X %04X",
2405 i, nfo.regs[i], nfo.regs[i+1], nfo.regs[i+2], nfo.regs[i+3]);
2408 #endif /* SI4700 */
2409 #if (CONFIG_TUNER & RDA5802)
2410 IF_TUNER_TYPE(RDA5802)
2412 struct rda5802_dbg_info nfo;
2413 int i;
2414 rda5802_dbg_info(&nfo);
2415 simplelist_addline(SIMPLELIST_ADD_LINE, "RDA5802 regs:");
2416 for (i = 0; i < 16; i += 4) {
2417 simplelist_addline(SIMPLELIST_ADD_LINE,"%02X: %04X %04X %04X %04X",
2418 i, nfo.regs[i], nfo.regs[i+1], nfo.regs[i+2], nfo.regs[i+3]);
2421 #endif /* RDA55802 */
2422 return ACTION_REDRAW;
2424 static bool dbg_fm_radio(void)
2426 struct simplelist_info info;
2427 #ifdef CONFIG_TUNER_MULTI
2428 tuner_type = tuner_detect_type();
2429 #endif
2430 info.scroll_all = true;
2431 simplelist_info_init(&info, "FM Radio", 1, NULL);
2432 simplelist_set_line_count(0);
2433 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2434 radio_hardware_present() ? "yes" : "no");
2436 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2437 info.hide_selection = true;
2438 return simplelist_show_list(&info);
2440 #endif /* CONFIG_TUNER */
2441 #endif /* !SIMULATOR */
2443 #ifdef HAVE_LCD_BITMAP
2444 extern bool do_screendump_instead_of_usb;
2446 static bool dbg_screendump(void)
2448 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2449 splashf(HZ, "Screendump %s",
2450 do_screendump_instead_of_usb?"enabled":"disabled");
2451 return false;
2453 #endif /* HAVE_LCD_BITMAP */
2455 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2456 static bool dbg_set_memory_guard(void)
2458 static const struct opt_items names[MAXMEMGUARD] = {
2459 { "None", -1 },
2460 { "Flash ROM writes", -1 },
2461 { "Zero area (all)", -1 }
2463 int mode = system_memory_guard(MEMGUARD_KEEP);
2465 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2466 system_memory_guard(mode);
2468 return false;
2470 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2472 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2473 static bool dbg_write_eeprom(void)
2475 int fd;
2476 int rc;
2477 int old_irq_level;
2478 char buf[EEPROM_SIZE];
2479 int err;
2481 fd = open("/internal_eeprom.bin", O_RDONLY);
2483 if (fd >= 0)
2485 rc = read(fd, buf, EEPROM_SIZE);
2487 if(rc == EEPROM_SIZE)
2489 old_irq_level = disable_irq_save();
2491 err = eeprom_24cxx_write(0, buf, sizeof buf);
2492 if (err)
2493 splashf(HZ*3, "Eeprom write failure (%d)", err);
2494 else
2495 splash(HZ*3, "Eeprom written successfully");
2497 restore_irq(old_irq_level);
2499 else
2501 splashf(HZ*3, "File read error (%d)",rc);
2503 close(fd);
2505 else
2507 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2510 return false;
2512 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2513 #ifdef CPU_BOOST_LOGGING
2514 static bool cpu_boost_log(void)
2516 int i = 0,j=0;
2517 int count = cpu_boost_log_getcount();
2518 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2519 char *str;
2520 bool done;
2521 lcd_setfont(FONT_SYSFIXED);
2522 str = cpu_boost_log_getlog_first();
2523 while (i < count)
2525 lcd_clear_display();
2526 for(j=0; j<lines; j++,i++)
2528 if (!str)
2529 str = cpu_boost_log_getlog_next();
2530 if (str)
2532 if(strlen(str) > LCD_WIDTH/SYSFONT_WIDTH)
2533 lcd_puts_scroll(0, j, str);
2534 else
2535 lcd_puts(0, j,str);
2537 str = NULL;
2539 lcd_update();
2540 done = false;
2541 while (!done)
2543 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2545 case ACTION_STD_OK:
2546 case ACTION_STD_PREV:
2547 case ACTION_STD_NEXT:
2548 done = true;
2549 break;
2550 case ACTION_STD_CANCEL:
2551 i = count;
2552 done = true;
2553 break;
2557 lcd_stop_scroll();
2558 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2559 lcd_setfont(FONT_UI);
2560 return false;
2562 #endif
2564 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) \
2565 && !defined(IPOD_MINI) && !defined(SIMULATOR))
2566 extern bool wheel_is_touched;
2567 extern int old_wheel_value;
2568 extern int new_wheel_value;
2569 extern int wheel_delta;
2570 extern unsigned int accumulated_wheel_delta;
2571 extern unsigned int wheel_velocity;
2573 static bool dbg_scrollwheel(void)
2575 unsigned int speed;
2577 lcd_setfont(FONT_SYSFIXED);
2579 while (1)
2581 if (action_userabort(HZ/10))
2582 break;
2584 lcd_clear_display();
2586 /* show internal variables of scrollwheel driver */
2587 lcd_putsf(0, 0, "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2588 lcd_putsf(0, 1, "new position: %2d", new_wheel_value);
2589 lcd_putsf(0, 2, "old position: %2d", old_wheel_value);
2590 lcd_putsf(0, 3, "wheel delta: %2d", wheel_delta);
2591 lcd_putsf(0, 4, "accumulated delta: %2d", accumulated_wheel_delta);
2592 lcd_putsf(0, 5, "velo [deg/s]: %4d", (int)wheel_velocity);
2594 /* show effective accelerated scrollspeed */
2595 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2596 lcd_putsf(0, 6, "accel. speed: %4d", speed);
2598 lcd_update();
2600 lcd_setfont(FONT_UI);
2601 return false;
2603 #endif
2605 #if defined (HAVE_USBSTACK)
2607 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2608 static bool toggle_usb_core_driver(int driver, char *msg)
2610 bool enabled = !usb_core_driver_enabled(driver);
2612 usb_core_enable_driver(driver,enabled);
2613 splashf(HZ, "%s %s", msg, enabled?"enabled":"disabled");
2615 return false;
2618 static bool toggle_usb_serial(void)
2620 return toggle_usb_core_driver(USB_DRIVER_SERIAL,"USB Serial");
2622 #endif
2624 #endif
2626 #if CONFIG_USBOTG == USBOTG_ISP1583
2627 extern int dbg_usb_num_items(void);
2628 extern const char* dbg_usb_item(int selected_item, void *data,
2629 char *buffer, size_t buffer_len);
2631 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2633 (void)lists;
2634 if (action == ACTION_NONE)
2635 action = ACTION_REDRAW;
2636 return action;
2639 static bool dbg_isp1583(void)
2641 struct simplelist_info isp1583;
2642 isp1583.scroll_all = true;
2643 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2644 isp1583.timeout = HZ/100;
2645 isp1583.hide_selection = true;
2646 isp1583.get_name = dbg_usb_item;
2647 isp1583.action_callback = isp1583_action_callback;
2648 return simplelist_show_list(&isp1583);
2650 #endif
2652 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2653 extern int pic_dbg_num_items(void);
2654 extern const char* pic_dbg_item(int selected_item, void *data,
2655 char *buffer, size_t buffer_len);
2657 static int pic_action_callback(int action, struct gui_synclist *lists)
2659 (void)lists;
2660 if (action == ACTION_NONE)
2661 action = ACTION_REDRAW;
2662 return action;
2665 static bool dbg_pic(void)
2667 struct simplelist_info pic;
2668 pic.scroll_all = true;
2669 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2670 pic.timeout = HZ/100;
2671 pic.hide_selection = true;
2672 pic.get_name = pic_dbg_item;
2673 pic.action_callback = pic_action_callback;
2674 return simplelist_show_list(&pic);
2676 #endif
2679 /****** The menu *********/
2680 struct the_menu_item {
2681 unsigned char *desc; /* string or ID */
2682 bool (*function) (void); /* return true if USB was connected */
2684 static const struct the_menu_item menuitems[] = {
2685 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2686 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)) || \
2687 CONFIG_CPU == IMX31L || defined(CPU_TCC780X)
2688 { "Dump ROM contents", dbg_save_roms },
2689 #endif
2690 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2691 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 \
2692 || CONFIG_CPU == DM320 || defined(CPU_S5L870X) || CONFIG_CPU == AS3525v2
2693 { "View I/O ports", dbg_ports },
2694 #endif
2695 #if (CONFIG_RTC == RTC_PCF50605) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
2696 { "View PCF registers", dbg_pcf },
2697 #endif
2698 #if defined(HAVE_TSC2100) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
2699 { "TSC2100 debug", tsc2100_debug },
2700 #endif
2701 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2702 { "CPU frequency", dbg_cpufreq },
2703 #endif
2704 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2705 { "S/PDIF analyzer", dbg_spdif },
2706 #endif
2707 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2708 { "Catch mem accesses", dbg_set_memory_guard },
2709 #endif
2710 { "View OS stacks", dbg_os },
2711 #ifdef HAVE_LCD_BITMAP
2712 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2713 { "View battery", view_battery },
2714 #endif
2715 { "Screendump", dbg_screendump },
2716 #endif
2717 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2718 { "View HW info", dbg_hw_info },
2719 #endif
2720 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2721 { "View partitions", dbg_partitions },
2722 #endif
2723 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2724 { "View disk info", dbg_disk_info },
2725 #if (CONFIG_STORAGE & STORAGE_ATA)
2726 { "Dump ATA identify info", dbg_identify_info},
2727 #endif
2728 #endif
2729 #ifdef HAVE_DIRCACHE
2730 { "View dircache info", dbg_dircache_info },
2731 #endif
2732 #ifdef HAVE_TAGCACHE
2733 { "View database info", dbg_tagcache_info },
2734 #endif
2735 #ifdef HAVE_LCD_BITMAP
2736 #if CONFIG_CODEC == SWCODEC
2737 { "View buffering thread", dbg_buffering_thread },
2738 #elif !defined(SIMULATOR)
2739 { "View audio thread", dbg_audio_thread },
2740 #endif
2741 #ifdef PM_DEBUG
2742 { "pm histogram", peak_meter_histogram},
2743 #endif /* PM_DEBUG */
2744 #endif /* HAVE_LCD_BITMAP */
2745 #ifndef SIMULATOR
2746 #if CONFIG_TUNER
2747 { "FM Radio", dbg_fm_radio },
2748 #endif
2749 #endif
2750 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2751 { "Write back EEPROM", dbg_write_eeprom },
2752 #endif
2753 #if CONFIG_USBOTG == USBOTG_ISP1583
2754 { "View ISP1583 info", dbg_isp1583 },
2755 #endif
2756 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2757 { "View PIC info", dbg_pic },
2758 #endif
2759 #ifdef ROCKBOX_HAS_LOGF
2760 {"Show Log File", logfdisplay },
2761 {"Dump Log File", logfdump },
2762 #endif
2763 #if defined(HAVE_USBSTACK)
2764 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2765 {"USB Serial driver (logf)", toggle_usb_serial },
2766 #endif
2767 #endif /* HAVE_USBSTACK */
2768 #ifdef CPU_BOOST_LOGGING
2769 {"cpu_boost log",cpu_boost_log},
2770 #endif
2771 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) \
2772 && !defined(IPOD_MINI) && !defined(SIMULATOR))
2773 {"Debug scrollwheel", dbg_scrollwheel },
2774 #endif
2776 static int menu_action_callback(int btn, struct gui_synclist *lists)
2778 int i;
2779 if (btn == ACTION_STD_OK)
2781 FOR_NB_SCREENS(i)
2782 viewportmanager_theme_enable(i, false, NULL);
2783 menuitems[gui_synclist_get_sel_pos(lists)].function();
2784 btn = ACTION_REDRAW;
2785 FOR_NB_SCREENS(i)
2786 viewportmanager_theme_undo(i, false);
2788 return btn;
2791 static const char* dbg_menu_getname(int item, void * data,
2792 char *buffer, size_t buffer_len)
2794 (void)data; (void)buffer; (void)buffer_len;
2795 return menuitems[item].desc;
2798 bool debug_menu(void)
2800 struct simplelist_info info;
2802 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2803 info.action_callback = menu_action_callback;
2804 info.get_name = dbg_menu_getname;
2805 return simplelist_show_list(&info);