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