Calculate watermark from bitrate and harddisk spinup time.
[kugel-rb.git] / apps / debug_menu.c
blob10d69b018c43653720aa7f1384260e3b538b5400
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(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 snprintf(buf, sizeof(buf), "CHARGER: %02X/%02X",
1255 ascodec_read(AS3514_CHARGER),
1256 ascodec_read(AS3514_IRQ_ENRD0));
1257 lcd_puts(0, line++, buf);
1258 #endif
1259 #endif
1260 lcd_update();
1261 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1263 lcd_setfont(FONT_UI);
1264 return false;
1268 #elif CONFIG_CPU == PP5002
1269 char buf[128];
1270 int line;
1272 lcd_clear_display();
1273 lcd_setfont(FONT_SYSFIXED);
1275 while(1)
1277 line = 0;
1278 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x",
1279 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1280 lcd_puts(0, line++, buf);
1281 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x",
1282 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1283 lcd_puts(0, line++, buf);
1285 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1286 lcd_puts(0, line++, buf);
1287 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1288 lcd_puts(0, line++, buf);
1289 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1290 lcd_puts(0, line++, buf);
1291 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1292 lcd_puts(0, line++, buf);
1293 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1294 lcd_puts(0, line++, buf);
1295 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1296 lcd_puts(0, line++, buf);
1297 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1298 lcd_puts(0, line++, buf);
1299 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1300 lcd_puts(0, line++, buf);
1302 lcd_update();
1303 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1305 lcd_setfont(FONT_UI);
1306 return false;
1309 lcd_setfont(FONT_UI);
1310 #else
1311 return __dbg_ports();
1312 #endif /* CPU */
1313 return false;
1315 #else /* !HAVE_LCD_BITMAP */
1316 bool dbg_ports(void)
1318 char buf[32];
1319 int button;
1320 int adc_battery_voltage;
1321 int currval = 0;
1323 lcd_clear_display();
1325 while(1)
1327 switch(currval)
1329 case 0:
1330 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1331 break;
1332 case 1:
1333 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1334 break;
1335 case 2:
1336 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1337 break;
1338 case 3:
1339 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1340 break;
1341 case 4:
1342 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1343 break;
1344 case 5:
1345 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1346 break;
1347 case 6:
1348 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1349 break;
1350 case 7:
1351 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1352 break;
1353 case 8:
1354 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1355 break;
1356 case 9:
1357 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1358 break;
1360 lcd_puts(0, 0, buf);
1362 battery_read_info(&adc_battery_voltage, NULL);
1363 snprintf(buf, 32, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1364 adc_battery_voltage % 1000);
1365 lcd_puts(0, 1, buf);
1366 lcd_update();
1368 button = get_action(CONTEXT_SETTINGS,HZ/5);
1370 switch(button)
1372 case ACTION_STD_CANCEL:
1373 return false;
1375 case ACTION_SETTINGS_DEC:
1376 currval--;
1377 if(currval < 0)
1378 currval = 9;
1379 break;
1381 case ACTION_SETTINGS_INC:
1382 currval++;
1383 if(currval > 9)
1384 currval = 0;
1385 break;
1388 return false;
1390 #endif /* !HAVE_LCD_BITMAP */
1391 #endif /* !SIMULATOR */
1393 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1394 static bool dbg_pcf(void)
1396 char buf[128];
1397 int line;
1399 #ifdef HAVE_LCD_BITMAP
1400 lcd_setfont(FONT_SYSFIXED);
1401 #endif
1402 lcd_clear_display();
1404 while(1)
1406 line = 0;
1408 snprintf(buf, sizeof(buf), "DCDC1: %02x", pcf50605_read(0x1b));
1409 lcd_puts(0, line++, buf);
1410 snprintf(buf, sizeof(buf), "DCDC2: %02x", pcf50605_read(0x1c));
1411 lcd_puts(0, line++, buf);
1412 snprintf(buf, sizeof(buf), "DCDC3: %02x", pcf50605_read(0x1d));
1413 lcd_puts(0, line++, buf);
1414 snprintf(buf, sizeof(buf), "DCDC4: %02x", pcf50605_read(0x1e));
1415 lcd_puts(0, line++, buf);
1416 snprintf(buf, sizeof(buf), "DCDEC1: %02x", pcf50605_read(0x1f));
1417 lcd_puts(0, line++, buf);
1418 snprintf(buf, sizeof(buf), "DCDEC2: %02x", pcf50605_read(0x20));
1419 lcd_puts(0, line++, buf);
1420 snprintf(buf, sizeof(buf), "DCUDC1: %02x", pcf50605_read(0x21));
1421 lcd_puts(0, line++, buf);
1422 snprintf(buf, sizeof(buf), "DCUDC2: %02x", pcf50605_read(0x22));
1423 lcd_puts(0, line++, buf);
1424 snprintf(buf, sizeof(buf), "IOREGC: %02x", pcf50605_read(0x23));
1425 lcd_puts(0, line++, buf);
1426 snprintf(buf, sizeof(buf), "D1REGC: %02x", pcf50605_read(0x24));
1427 lcd_puts(0, line++, buf);
1428 snprintf(buf, sizeof(buf), "D2REGC: %02x", pcf50605_read(0x25));
1429 lcd_puts(0, line++, buf);
1430 snprintf(buf, sizeof(buf), "D3REGC: %02x", pcf50605_read(0x26));
1431 lcd_puts(0, line++, buf);
1432 snprintf(buf, sizeof(buf), "LPREG1: %02x", pcf50605_read(0x27));
1433 lcd_puts(0, line++, buf);
1435 lcd_update();
1436 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1438 lcd_setfont(FONT_UI);
1439 return false;
1443 lcd_setfont(FONT_UI);
1444 return false;
1446 #endif
1448 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1449 static bool dbg_cpufreq(void)
1451 char buf[128];
1452 int line;
1453 int button;
1455 #ifdef HAVE_LCD_BITMAP
1456 lcd_setfont(FONT_SYSFIXED);
1457 #endif
1458 lcd_clear_display();
1460 while(1)
1462 line = 0;
1464 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1465 lcd_puts(0, line++, buf);
1467 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1468 lcd_puts(0, line++, buf);
1470 lcd_update();
1471 button = get_action(CONTEXT_STD,HZ/10);
1473 switch(button)
1475 case ACTION_STD_PREV:
1476 cpu_boost(true);
1477 break;
1479 case ACTION_STD_NEXT:
1480 cpu_boost(false);
1481 break;
1483 case ACTION_STD_OK:
1484 while (get_cpu_boost_counter() > 0)
1485 cpu_boost(false);
1486 set_cpu_frequency(CPUFREQ_DEFAULT);
1487 break;
1489 case ACTION_STD_CANCEL:
1490 lcd_setfont(FONT_UI);
1491 return false;
1494 lcd_setfont(FONT_UI);
1495 return false;
1497 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1499 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1500 #include "tsc2100.h"
1501 static char *itob(int n, int len)
1503 static char binary[64];
1504 int i,j;
1505 for (i=1, j=0;i<=len;i++)
1507 binary[j++] = n&(1<<(len-i))?'1':'0';
1508 if (i%4 == 0)
1509 binary[j++] = ' ';
1511 binary[j] = '\0';
1512 return binary;
1514 static char* tsc2100_debug_getname(int selected_item, void * data,
1515 char *buffer, size_t buffer_len)
1517 int *page = (int*)data;
1518 bool reserved = false;
1519 switch (*page)
1521 case 0:
1522 if ((selected_item > 0x0a) ||
1523 (selected_item == 0x04) ||
1524 (selected_item == 0x08))
1525 reserved = true;
1526 break;
1527 case 1:
1528 if ((selected_item > 0x05) ||
1529 (selected_item == 0x02))
1530 reserved = true;
1531 break;
1532 case 2:
1533 if (selected_item > 0x1e)
1534 reserved = true;
1535 break;
1537 if (reserved)
1538 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1539 else
1540 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1541 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1542 return buffer;
1544 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1546 int *page = (int*)lists->data;
1547 if (action == ACTION_STD_OK)
1549 *page = (*page+1)%3;
1550 snprintf(lists->title, 32,
1551 "tsc2100 registers - Page %d", *page);
1552 return ACTION_REDRAW;
1554 return action;
1556 static bool tsc2100_debug(void)
1558 int page = 0;
1559 char title[32] = "tsc2100 registers - Page 0";
1560 struct simplelist_info info;
1561 simplelist_info_init(&info, title, 32, &page);
1562 info.timeout = HZ/100;
1563 info.get_name = tsc2100_debug_getname;
1564 info.action_callback= tsc2100debug_action_callback;
1565 return simplelist_show_list(&info);
1567 #endif
1568 #ifndef SIMULATOR
1569 #ifdef HAVE_LCD_BITMAP
1571 * view_battery() shows a automatically scaled graph of the battery voltage
1572 * over time. Usable for estimating battery life / charging rate.
1573 * The power_history array is updated in power_thread of powermgmt.c.
1576 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1577 #define BAT_YSPACE (LCD_HEIGHT - 20)
1579 static bool view_battery(void)
1581 int view = 0;
1582 int i, x, y;
1583 unsigned short maxv, minv;
1584 char buf[32];
1586 lcd_setfont(FONT_SYSFIXED);
1588 while(1)
1590 lcd_clear_display();
1591 switch (view) {
1592 case 0: /* voltage history graph */
1593 /* Find maximum and minimum voltage for scaling */
1594 minv = power_history[0];
1595 maxv = minv + 1;
1596 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1597 if (power_history[i] > maxv)
1598 maxv = power_history[i];
1599 if (power_history[i] < minv)
1600 minv = power_history[i];
1603 snprintf(buf, 30, "Battery %d.%03d", power_history[0] / 1000,
1604 power_history[0] % 1000);
1605 lcd_puts(0, 0, buf);
1606 snprintf(buf, 30, "scale %d.%03d-%d.%03dV",
1607 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1608 lcd_puts(0, 1, buf);
1610 x = 0;
1611 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1612 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1613 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1614 lcd_vline(x, LCD_HEIGHT-1, 20);
1615 lcd_set_drawmode(DRMODE_SOLID);
1616 lcd_vline(x, LCD_HEIGHT-1,
1617 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1618 x++;
1621 break;
1623 case 1: /* status: */
1624 lcd_puts(0, 0, "Power status:");
1626 battery_read_info(&y, NULL);
1627 snprintf(buf, 30, "Battery: %d.%03d V", y / 1000, y % 1000);
1628 lcd_puts(0, 1, buf);
1629 #ifdef ADC_EXT_POWER
1630 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1631 snprintf(buf, 30, "External: %d.%03d V", y / 1000, y % 1000);
1632 lcd_puts(0, 2, buf);
1633 #endif
1634 #if CONFIG_CHARGING
1635 #if defined ARCHOS_RECORDER
1636 snprintf(buf, 30, "Chgr: %s %s",
1637 charger_inserted() ? "present" : "absent",
1638 charger_enabled() ? "on" : "off");
1639 lcd_puts(0, 3, buf);
1640 snprintf(buf, 30, "short delta: %d", short_delta);
1641 lcd_puts(0, 5, buf);
1642 snprintf(buf, 30, "long delta: %d", long_delta);
1643 lcd_puts(0, 6, buf);
1644 lcd_puts(0, 7, power_message);
1645 snprintf(buf, 30, "USB Inserted: %s",
1646 usb_inserted() ? "yes" : "no");
1647 lcd_puts(0, 8, buf);
1648 #elif defined IRIVER_H300_SERIES
1649 snprintf(buf, 30, "USB Charging Enabled: %s",
1650 usb_charging_enabled() ? "yes" : "no");
1651 lcd_puts(0, 9, buf);
1652 #elif defined IPOD_NANO || defined IPOD_VIDEO
1653 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1654 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1655 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1656 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1657 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1659 snprintf(buf, 30, "USB pwr: %s",
1660 usb_pwr ? "present" : "absent");
1661 lcd_puts(0, 3, buf);
1662 snprintf(buf, 30, "EXT pwr: %s",
1663 ext_pwr ? "present" : "absent");
1664 lcd_puts(0, 4, buf);
1665 snprintf(buf, 30, "Battery: %s",
1666 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1667 lcd_puts(0, 5, buf);
1668 snprintf(buf, 30, "Dock mode: %s",
1669 dock ? "enabled" : "disabled");
1670 lcd_puts(0, 6, buf);
1671 snprintf(buf, 30, "Headphone: %s",
1672 headphone ? "connected" : "disconnected");
1673 lcd_puts(0, 7, buf);
1674 #elif defined TOSHIBA_GIGABEAT_S
1675 int line = 3;
1676 unsigned int st;
1678 static const unsigned char * const chrgstate_strings[] =
1680 "Disabled",
1681 "Error",
1682 "Discharging",
1683 "Precharge",
1684 "Constant Voltage",
1685 "Constant Current",
1686 "<unknown>",
1689 snprintf(buf, 30, "Charger: %s",
1690 charger_inserted() ? "present" : "absent");
1691 lcd_puts(0, line++, buf);
1693 st = power_input_status() &
1694 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1695 snprintf(buf, 30, "%s%s",
1696 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1697 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1698 lcd_puts(0, line++, buf);
1700 snprintf(buf, 30, "IUSB Max: %d", usb_allowed_current());
1701 lcd_puts(0, line++, buf);
1703 y = ARRAYLEN(chrgstate_strings) - 1;
1705 switch (charge_state)
1707 case CHARGE_STATE_DISABLED: y--;
1708 case CHARGE_STATE_ERROR: y--;
1709 case DISCHARGING: y--;
1710 case TRICKLE: y--;
1711 case TOPOFF: y--;
1712 case CHARGING: y--;
1713 default:;
1716 snprintf(buf, 30, "State: %s", chrgstate_strings[y]);
1717 lcd_puts(0, line++, buf);
1719 snprintf(buf, 30, "Battery Switch: %s",
1720 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1721 lcd_puts(0, line++, buf);
1723 y = chrgraw_adc_voltage();
1724 snprintf(buf, 30, "CHRGRAW: %d.%03d V",
1725 y / 1000, y % 1000);
1726 lcd_puts(0, line++, buf);
1728 y = application_supply_adc_voltage();
1729 snprintf(buf, 30, "BP : %d.%03d V",
1730 y / 1000, y % 1000);
1731 lcd_puts(0, line++, buf);
1733 y = battery_adc_charge_current();
1734 if (y < 0) x = '-', y = -y;
1735 else x = ' ';
1736 snprintf(buf, 30, "CHRGISN:%c%d mA", x, y);
1737 lcd_puts(0, line++, buf);
1739 y = cccv_regulator_dissipation();
1740 snprintf(buf, 30, "P CCCV : %d mW", y);
1741 lcd_puts(0, line++, buf);
1743 y = battery_charge_current();
1744 if (y < 0) x = '-', y = -y;
1745 else x = ' ';
1746 snprintf(buf, 30, "I Charge:%c%d mA", x, y);
1747 lcd_puts(0, line++, buf);
1749 y = battery_adc_temp();
1751 if (y != INT_MIN) {
1752 snprintf(buf, 30, "T Battery: %dC (%dF)", y,
1753 (9*y + 160) / 5);
1754 } else {
1755 /* Conversion disabled */
1756 snprintf(buf, 30, "T Battery: ?");
1759 lcd_puts(0, line++, buf);
1760 #else
1761 snprintf(buf, 30, "Charger: %s",
1762 charger_inserted() ? "present" : "absent");
1763 lcd_puts(0, 3, buf);
1764 #endif /* target type */
1765 #endif /* CONFIG_CHARGING */
1766 break;
1768 case 2: /* voltage deltas: */
1769 lcd_puts(0, 0, "Voltage deltas:");
1771 for (i = 0; i <= 6; i++) {
1772 y = power_history[i] - power_history[i+1];
1773 snprintf(buf, 30, "-%d min: %s%d.%03d V", i,
1774 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1775 ((y < 0) ? y * -1 : y ) % 1000);
1776 lcd_puts(0, i+1, buf);
1778 break;
1780 case 3: /* remaining time estimation: */
1782 #ifdef ARCHOS_RECORDER
1783 snprintf(buf, 30, "charge_state: %d", charge_state);
1784 lcd_puts(0, 0, buf);
1786 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1787 lcd_puts(0, 1, buf);
1789 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1790 lcd_puts(0, 2, buf);
1792 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1793 lcd_puts(0, 3, buf);
1795 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1796 lcd_puts(0, 4, buf);
1797 #endif /* ARCHOS_RECORDER */
1799 snprintf(buf, 30, "Last PwrHist: %d.%03dV",
1800 power_history[0] / 1000,
1801 power_history[0] % 1000);
1802 lcd_puts(0, 5, buf);
1804 snprintf(buf, 30, "battery level: %d%%", battery_level());
1805 lcd_puts(0, 6, buf);
1807 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1808 lcd_puts(0, 7, buf);
1809 break;
1812 lcd_update();
1814 switch(get_action(CONTEXT_STD,HZ/2))
1816 case ACTION_STD_PREV:
1817 if (view)
1818 view--;
1819 break;
1821 case ACTION_STD_NEXT:
1822 if (view < 3)
1823 view++;
1824 break;
1826 case ACTION_STD_CANCEL:
1827 lcd_setfont(FONT_UI);
1828 return false;
1831 lcd_setfont(FONT_UI);
1832 return false;
1835 #endif /* HAVE_LCD_BITMAP */
1836 #endif
1838 #ifndef SIMULATOR
1839 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1841 #if (CONFIG_STORAGE & STORAGE_MMC)
1842 #define CARDTYPE "MMC"
1843 #elif (CONFIG_STORAGE & STORAGE_SD)
1844 #define CARDTYPE "microSD"
1845 #endif
1847 static int disk_callback(int btn, struct gui_synclist *lists)
1849 tCardInfo *card;
1850 int *cardnum = (int*)lists->data;
1851 unsigned char card_name[7];
1852 unsigned char pbuf[32];
1853 char *title = lists->title;
1854 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1855 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1856 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1857 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1858 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1859 "3.1-3.31", "4.0" };
1860 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1862 #ifdef HAVE_HOTSWAP
1863 if (btn == ACTION_STD_OK)
1865 *cardnum ^= 0x1; /* change cards */
1867 #endif
1869 simplelist_set_line_count(0);
1871 card = card_get_info(*cardnum);
1873 if (card->initialized > 0)
1875 card_name[6] = '\0';
1876 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1877 simplelist_addline(SIMPLELIST_ADD_LINE,
1878 "%s Rev %d.%d", card_name,
1879 (int) card_extract_bits(card->cid, 72, 4),
1880 (int) card_extract_bits(card->cid, 76, 4));
1881 simplelist_addline(SIMPLELIST_ADD_LINE,
1882 "Prod: %d/%d",
1883 (int) card_extract_bits(card->cid, 112, 4),
1884 (int) card_extract_bits(card->cid, 116, 4) + 1997);
1885 simplelist_addline(SIMPLELIST_ADD_LINE,
1886 "Ser#: 0x%08lx",
1887 card_extract_bits(card->cid, 80, 32));
1888 simplelist_addline(SIMPLELIST_ADD_LINE,
1889 "M=%02x, O=%04x",
1890 (int) card_extract_bits(card->cid, 0, 8),
1891 (int) card_extract_bits(card->cid, 8, 16));
1892 int temp = card_extract_bits(card->csd, 2, 4);
1893 simplelist_addline(SIMPLELIST_ADD_LINE,
1894 CARDTYPE " v%s", temp < 5 ?
1895 spec_vers[temp] : "?.?");
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->tsac,
1903 nsec_units, false);
1904 simplelist_addline(SIMPLELIST_ADD_LINE,
1905 "Tsac: %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, 66, 3)],
1913 i_vmax[card_extract_bits(card->csd, 69, 3)]);
1914 simplelist_addline(SIMPLELIST_ADD_LINE,
1915 "IWmax: %d..%d mA",
1916 i_vmin[card_extract_bits(card->csd, 72, 3)],
1917 i_vmax[card_extract_bits(card->csd, 75, 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 #if defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S)
2005 if (identify_info[63] & (1<<0)) {
2006 char mdma0[2], mdma1[2], mdma2[2];
2007 mdma0[1] = mdma1[1] = mdma2[1] = 0;
2008 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
2009 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
2010 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
2011 simplelist_addline(SIMPLELIST_ADD_LINE,
2012 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
2013 simplelist_addline(SIMPLELIST_ADD_LINE,
2014 "MDMA Cycle times %dns/%dns",
2015 identify_info[65],
2016 identify_info[66] );
2018 else {
2019 simplelist_addline(SIMPLELIST_ADD_LINE,
2020 "No MDMA mode info");
2022 if (identify_info[88] & (1<<0)) {
2023 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2];
2024 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = 0;
2025 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
2026 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
2027 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
2028 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
2029 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
2030 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
2031 simplelist_addline(SIMPLELIST_ADD_LINE,
2032 "UDMA modes: %s %s %s %s %s %s", udma0, udma1, udma2,
2033 udma3, udma4, udma5);
2035 else {
2036 simplelist_addline(SIMPLELIST_ADD_LINE,
2037 "No UDMA mode info");
2039 #endif /* defined (TOSHIBA_GIGABEAT_F) || defined (TOSHIBA_GIGABEAT_S) */
2040 timing_info_present = identify_info[53] & (1<<1);
2041 if(timing_info_present) {
2042 i = identify_info[49] & (1<<11);
2043 simplelist_addline(SIMPLELIST_ADD_LINE,
2044 "IORDY support: %s", i ? "yes" : "no");
2045 i = identify_info[49] & (1<<10);
2046 simplelist_addline(SIMPLELIST_ADD_LINE,
2047 "IORDY disable: %s", i ? "yes" : "no");
2048 } else {
2049 simplelist_addline(SIMPLELIST_ADD_LINE,
2050 "No timing info");
2052 simplelist_addline(SIMPLELIST_ADD_LINE,
2053 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2054 return btn;
2056 #else /* No SD, MMC or ATA */
2057 static int disk_callback(int btn, struct gui_synclist *lists)
2059 (void)btn;
2060 (void)lists;
2061 struct storage_info info;
2062 storage_get_info(0,&info);
2063 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
2064 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
2065 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
2066 simplelist_addline(SIMPLELIST_ADD_LINE,
2067 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
2068 unsigned long free;
2069 fat_size( IF_MV2(0,) NULL, &free );
2070 simplelist_addline(SIMPLELIST_ADD_LINE,
2071 "Free: %ld MB", free / 1024);
2072 simplelist_addline(SIMPLELIST_ADD_LINE,
2073 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2074 return btn;
2076 #endif
2078 #if (CONFIG_STORAGE & STORAGE_ATA)
2079 static bool dbg_identify_info(void)
2081 int fd = creat("/identify_info.bin");
2082 if(fd >= 0)
2084 #ifdef ROCKBOX_LITTLE_ENDIAN
2085 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
2086 #else
2087 write(fd, ata_get_identify(), SECTOR_SIZE);
2088 #endif
2089 close(fd);
2091 return false;
2093 #endif
2095 static bool dbg_disk_info(void)
2097 struct simplelist_info info;
2098 simplelist_info_init(&info, "Disk Info", 1, NULL);
2099 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
2100 char title[16];
2101 int card = 0;
2102 info.callback_data = (void*)&card;
2103 info.title = title;
2104 #endif
2105 info.action_callback = disk_callback;
2106 info.hide_selection = true;
2107 info.scroll_all = true;
2108 return simplelist_show_list(&info);
2110 #endif /* !SIMULATOR */
2112 #ifdef HAVE_DIRCACHE
2113 static int dircache_callback(int btn, struct gui_synclist *lists)
2115 (void)btn; (void)lists;
2116 simplelist_set_line_count(0);
2117 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
2118 dircache_is_enabled() ? "Yes" : "No");
2119 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
2120 dircache_get_cache_size());
2121 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
2122 global_status.dircache_size);
2123 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
2124 DIRCACHE_LIMIT);
2125 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
2126 dircache_get_reserve_used(), DIRCACHE_RESERVE);
2127 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2128 dircache_get_build_ticks() / HZ);
2129 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2130 dircache_get_entry_count());
2131 return btn;
2134 static bool dbg_dircache_info(void)
2136 struct simplelist_info info;
2137 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2138 info.action_callback = dircache_callback;
2139 info.hide_selection = true;
2140 info.scroll_all = true;
2141 return simplelist_show_list(&info);
2144 #endif /* HAVE_DIRCACHE */
2146 #ifdef HAVE_TAGCACHE
2147 static int database_callback(int btn, struct gui_synclist *lists)
2149 (void)lists;
2150 struct tagcache_stat *stat = tagcache_get_stat();
2151 static bool synced = false;
2153 simplelist_set_line_count(0);
2155 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2156 stat->initialized ? "Yes" : "No");
2157 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2158 stat->ready ? "Yes" : "No");
2159 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2160 stat->ramcache ? "Yes" : "No");
2161 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2162 stat->ramcache_used, stat->ramcache_allocated);
2163 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2164 stat->progress, stat->processed_entries);
2165 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2166 stat->curentry ? stat->curentry : "---");
2167 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2168 stat->commit_step);
2169 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2170 stat->commit_delayed ? "Yes" : "No");
2172 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2173 stat->queue_length);
2175 if (synced)
2177 synced = false;
2178 tagcache_screensync_event();
2181 if (!btn && stat->curentry)
2183 synced = true;
2184 return ACTION_REDRAW;
2187 if (btn == ACTION_STD_CANCEL)
2188 tagcache_screensync_enable(false);
2190 return btn;
2192 static bool dbg_tagcache_info(void)
2194 struct simplelist_info info;
2195 simplelist_info_init(&info, "Database Info", 8, NULL);
2196 info.action_callback = database_callback;
2197 info.hide_selection = true;
2198 info.scroll_all = true;
2200 /* Don't do nonblock here, must give enough processing time
2201 for tagcache thread. */
2202 /* info.timeout = TIMEOUT_NOBLOCK; */
2203 info.timeout = 1;
2204 tagcache_screensync_enable(true);
2205 return simplelist_show_list(&info);
2207 #endif
2209 #if CONFIG_CPU == SH7034
2210 static bool dbg_save_roms(void)
2212 int fd;
2213 int oldmode = system_memory_guard(MEMGUARD_NONE);
2215 fd = creat("/internal_rom_0000-FFFF.bin");
2216 if(fd >= 0)
2218 write(fd, (void *)0, 0x10000);
2219 close(fd);
2222 fd = creat("/internal_rom_2000000-203FFFF.bin");
2223 if(fd >= 0)
2225 write(fd, (void *)0x2000000, 0x40000);
2226 close(fd);
2229 system_memory_guard(oldmode);
2230 return false;
2232 #elif defined CPU_COLDFIRE
2233 static bool dbg_save_roms(void)
2235 int fd;
2236 int oldmode = system_memory_guard(MEMGUARD_NONE);
2238 #if defined(IRIVER_H100_SERIES)
2239 fd = creat("/internal_rom_000000-1FFFFF.bin");
2240 #elif defined(IRIVER_H300_SERIES)
2241 fd = creat("/internal_rom_000000-3FFFFF.bin");
2242 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2243 fd = creat("/internal_rom_000000-3FFFFF.bin");
2244 #endif
2245 if(fd >= 0)
2247 write(fd, (void *)0, FLASH_SIZE);
2248 close(fd);
2250 system_memory_guard(oldmode);
2252 #ifdef HAVE_EEPROM
2253 fd = creat("/internal_eeprom.bin");
2254 if (fd >= 0)
2256 int old_irq_level;
2257 char buf[EEPROM_SIZE];
2258 int err;
2260 old_irq_level = disable_irq_save();
2262 err = eeprom_24cxx_read(0, buf, sizeof buf);
2264 restore_irq(old_irq_level);
2266 if (err)
2267 splashf(HZ*3, "Eeprom read failure (%d)", err);
2268 else
2270 write(fd, buf, sizeof buf);
2273 close(fd);
2275 #endif
2277 return false;
2279 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
2280 static bool dbg_save_roms(void)
2282 int fd;
2284 fd = creat("/internal_rom_000000-0FFFFF.bin");
2285 if(fd >= 0)
2287 write(fd, (void *)0x20000000, FLASH_SIZE);
2288 close(fd);
2291 return false;
2293 #endif /* CPU */
2295 #ifndef SIMULATOR
2296 #if CONFIG_TUNER
2297 static int radio_callback(int btn, struct gui_synclist *lists)
2299 (void)lists;
2300 if (btn == ACTION_STD_CANCEL)
2301 return btn;
2302 simplelist_set_line_count(1);
2304 #if (CONFIG_TUNER & LV24020LP)
2305 simplelist_addline(SIMPLELIST_ADD_LINE,
2306 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2307 simplelist_addline(SIMPLELIST_ADD_LINE,
2308 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2309 simplelist_addline(SIMPLELIST_ADD_LINE,
2310 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2311 simplelist_addline(SIMPLELIST_ADD_LINE,
2312 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2313 simplelist_addline(SIMPLELIST_ADD_LINE,
2314 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2315 simplelist_addline(SIMPLELIST_ADD_LINE,
2316 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2317 simplelist_addline(SIMPLELIST_ADD_LINE,
2318 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2319 #endif /* LV24020LP */
2320 #if (CONFIG_TUNER & S1A0903X01)
2321 simplelist_addline(SIMPLELIST_ADD_LINE,
2322 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2323 /* This one doesn't return dynamic data atm */
2324 #endif /* S1A0903X01 */
2325 #if (CONFIG_TUNER & TEA5767)
2326 struct tea5767_dbg_info nfo;
2327 tea5767_dbg_info(&nfo);
2328 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2329 simplelist_addline(SIMPLELIST_ADD_LINE,
2330 " Read: %02X %02X %02X %02X %02X",
2331 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2332 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2333 (unsigned)nfo.read_regs[4]);
2334 simplelist_addline(SIMPLELIST_ADD_LINE,
2335 " Write: %02X %02X %02X %02X %02X",
2336 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2337 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2338 (unsigned)nfo.write_regs[4]);
2339 #endif /* TEA5767 */
2340 #if (CONFIG_TUNER & SI4700)
2341 struct si4700_dbg_info nfo;
2342 si4700_dbg_info(&nfo);
2343 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
2344 /* Registers */
2345 simplelist_addline(SIMPLELIST_ADD_LINE,
2346 "%04X %04X %04X %04X",
2347 (unsigned)nfo.regs[0], (unsigned)nfo.regs[1],
2348 (unsigned)nfo.regs[2], (unsigned)nfo.regs[3]);
2349 simplelist_addline(SIMPLELIST_ADD_LINE,
2350 "%04X %04X %04X %04X",
2351 (unsigned)nfo.regs[4], (unsigned)nfo.regs[5],
2352 (unsigned)nfo.regs[6], (unsigned)nfo.regs[7]);
2353 simplelist_addline(SIMPLELIST_ADD_LINE,
2354 "%04X %04X %04X %04X",
2355 (unsigned)nfo.regs[8], (unsigned)nfo.regs[9],
2356 (unsigned)nfo.regs[10], (unsigned)nfo.regs[11]);
2357 simplelist_addline(SIMPLELIST_ADD_LINE,
2358 "%04X %04X %04X %04X",
2359 (unsigned)nfo.regs[12], (unsigned)nfo.regs[13],
2360 (unsigned)nfo.regs[14], (unsigned)nfo.regs[15]);
2361 #endif /* SI4700 */
2362 return ACTION_REDRAW;
2364 static bool dbg_fm_radio(void)
2366 struct simplelist_info info;
2367 info.scroll_all = true;
2368 simplelist_info_init(&info, "FM Radio", 1, NULL);
2369 simplelist_set_line_count(0);
2370 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2371 radio_hardware_present() ? "yes" : "no");
2373 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2374 info.hide_selection = true;
2375 return simplelist_show_list(&info);
2377 #endif /* CONFIG_TUNER */
2378 #endif /* !SIMULATOR */
2380 #ifdef HAVE_LCD_BITMAP
2381 extern bool do_screendump_instead_of_usb;
2383 static bool dbg_screendump(void)
2385 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2386 splashf(HZ, "Screendump %s",
2387 do_screendump_instead_of_usb?"enabled":"disabled");
2388 return false;
2390 #endif /* HAVE_LCD_BITMAP */
2392 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2393 static bool dbg_set_memory_guard(void)
2395 static const struct opt_items names[MAXMEMGUARD] = {
2396 { "None", -1 },
2397 { "Flash ROM writes", -1 },
2398 { "Zero area (all)", -1 }
2400 int mode = system_memory_guard(MEMGUARD_KEEP);
2402 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2403 system_memory_guard(mode);
2405 return false;
2407 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2409 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2410 static bool dbg_write_eeprom(void)
2412 int fd;
2413 int rc;
2414 int old_irq_level;
2415 char buf[EEPROM_SIZE];
2416 int err;
2418 fd = open("/internal_eeprom.bin", O_RDONLY);
2420 if (fd >= 0)
2422 rc = read(fd, buf, EEPROM_SIZE);
2424 if(rc == EEPROM_SIZE)
2426 old_irq_level = disable_irq_save();
2428 err = eeprom_24cxx_write(0, buf, sizeof buf);
2429 if (err)
2430 splashf(HZ*3, "Eeprom write failure (%d)", err);
2431 else
2432 splash(HZ*3, "Eeprom written successfully");
2434 restore_irq(old_irq_level);
2436 else
2438 splashf(HZ*3, "File read error (%d)",rc);
2440 close(fd);
2442 else
2444 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2447 return false;
2449 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2450 #ifdef CPU_BOOST_LOGGING
2451 static bool cpu_boost_log(void)
2453 int i = 0,j=0;
2454 int count = cpu_boost_log_getcount();
2455 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2456 char *str;
2457 bool done;
2458 lcd_setfont(FONT_SYSFIXED);
2459 str = cpu_boost_log_getlog_first();
2460 while (i < count)
2462 lcd_clear_display();
2463 for(j=0; j<lines; j++,i++)
2465 if (!str)
2466 str = cpu_boost_log_getlog_next();
2467 if (str)
2469 lcd_puts(0, j,str);
2471 str = NULL;
2473 lcd_update();
2474 done = false;
2475 while (!done)
2477 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2479 case ACTION_STD_OK:
2480 case ACTION_STD_PREV:
2481 case ACTION_STD_NEXT:
2482 done = true;
2483 break;
2484 case ACTION_STD_CANCEL:
2485 i = count;
2486 done = true;
2487 break;
2491 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2492 lcd_setfont(FONT_UI);
2493 return false;
2495 #endif
2497 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2498 extern bool wheel_is_touched;
2499 extern int old_wheel_value;
2500 extern int new_wheel_value;
2501 extern int wheel_delta;
2502 extern unsigned int accumulated_wheel_delta;
2503 extern unsigned int wheel_velocity;
2505 static bool dbg_scrollwheel(void)
2507 char buf[64];
2508 unsigned int speed;
2510 lcd_setfont(FONT_SYSFIXED);
2512 while (1)
2514 if (action_userabort(HZ/10))
2515 break;
2517 lcd_clear_display();
2519 /* show internal variables of scrollwheel driver */
2520 snprintf(buf, sizeof(buf), "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2521 lcd_puts(0, 0, buf);
2522 snprintf(buf, sizeof(buf), "new position: %2d", new_wheel_value);
2523 lcd_puts(0, 1, buf);
2524 snprintf(buf, sizeof(buf), "old position: %2d", old_wheel_value);
2525 lcd_puts(0, 2, buf);
2526 snprintf(buf, sizeof(buf), "wheel delta: %2d", wheel_delta);
2527 lcd_puts(0, 3, buf);
2528 snprintf(buf, sizeof(buf), "accumulated delta: %2d", accumulated_wheel_delta);
2529 lcd_puts(0, 4, buf);
2530 snprintf(buf, sizeof(buf), "velo [deg/s]: %4d", (int)wheel_velocity);
2531 lcd_puts(0, 5, buf);
2533 /* show effective accelerated scrollspeed */
2534 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2535 snprintf(buf, sizeof(buf), "accel. speed: %4d", speed);
2536 lcd_puts(0, 6, buf);
2538 lcd_update();
2540 lcd_setfont(FONT_UI);
2541 return false;
2543 #endif
2545 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2546 static bool logf_usb_serial(void)
2548 bool serial_enabled = !usb_core_driver_enabled(USB_DRIVER_SERIAL);
2549 usb_core_enable_driver(USB_DRIVER_SERIAL,serial_enabled);
2550 splashf(HZ, "USB logf %s",
2551 serial_enabled?"enabled":"disabled");
2552 return false;
2554 #endif
2556 #if defined(HAVE_USBSTACK) && defined(USB_STORAGE)
2557 static bool usb_reconnect(void)
2559 splash(HZ, "Reconnect mass storage");
2560 usb_storage_reconnect();
2561 return false;
2563 #endif
2565 #if CONFIG_USBOTG == USBOTG_ISP1583
2566 extern int dbg_usb_num_items(void);
2567 extern char* dbg_usb_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2569 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2571 (void)lists;
2572 if (action == ACTION_NONE)
2573 action = ACTION_REDRAW;
2574 return action;
2577 static bool dbg_isp1583(void)
2579 struct simplelist_info isp1583;
2580 isp1583.scroll_all = true;
2581 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2582 isp1583.timeout = HZ/100;
2583 isp1583.hide_selection = true;
2584 isp1583.get_name = dbg_usb_item;
2585 isp1583.action_callback = isp1583_action_callback;
2586 return simplelist_show_list(&isp1583);
2588 #endif
2590 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2591 extern int pic_dbg_num_items(void);
2592 extern char* pic_dbg_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2594 static int pic_action_callback(int action, struct gui_synclist *lists)
2596 (void)lists;
2597 if (action == ACTION_NONE)
2598 action = ACTION_REDRAW;
2599 return action;
2602 static bool dbg_pic(void)
2604 struct simplelist_info pic;
2605 pic.scroll_all = true;
2606 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2607 pic.timeout = HZ/100;
2608 pic.hide_selection = true;
2609 pic.get_name = pic_dbg_item;
2610 pic.action_callback = pic_action_callback;
2611 return simplelist_show_list(&pic);
2613 #endif
2616 /****** The menu *********/
2617 struct the_menu_item {
2618 unsigned char *desc; /* string or ID */
2619 bool (*function) (void); /* return true if USB was connected */
2621 static const struct the_menu_item menuitems[] = {
2622 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2623 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD))
2624 { "Dump ROM contents", dbg_save_roms },
2625 #endif
2626 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2627 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L
2628 { "View I/O ports", dbg_ports },
2629 #endif
2630 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2631 { "View PCF registers", dbg_pcf },
2632 #endif
2633 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2634 { "TSC2100 debug", tsc2100_debug },
2635 #endif
2636 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2637 { "CPU frequency", dbg_cpufreq },
2638 #endif
2639 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2640 { "S/PDIF analyzer", dbg_spdif },
2641 #endif
2642 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2643 { "Catch mem accesses", dbg_set_memory_guard },
2644 #endif
2645 { "View OS stacks", dbg_os },
2646 #ifdef HAVE_LCD_BITMAP
2647 #ifndef SIMULATOR
2648 { "View battery", view_battery },
2649 #endif
2650 { "Screendump", dbg_screendump },
2651 #endif
2652 #ifndef SIMULATOR
2653 { "View HW info", dbg_hw_info },
2654 #endif
2655 #ifndef SIMULATOR
2656 { "View partitions", dbg_partitions },
2657 #endif
2658 #ifndef SIMULATOR
2659 { "View disk info", dbg_disk_info },
2660 #if (CONFIG_STORAGE & STORAGE_ATA)
2661 { "Dump ATA identify info", dbg_identify_info},
2662 #endif
2663 #endif
2664 #ifdef HAVE_DIRCACHE
2665 { "View dircache info", dbg_dircache_info },
2666 #endif
2667 #ifdef HAVE_TAGCACHE
2668 { "View database info", dbg_tagcache_info },
2669 #endif
2670 #ifdef HAVE_LCD_BITMAP
2671 #if CONFIG_CODEC == SWCODEC
2672 { "View buffering thread", dbg_buffering_thread },
2673 #elif !defined(SIMULATOR)
2674 { "View audio thread", dbg_audio_thread },
2675 #endif
2676 #ifdef PM_DEBUG
2677 { "pm histogram", peak_meter_histogram},
2678 #endif /* PM_DEBUG */
2679 #endif /* HAVE_LCD_BITMAP */
2680 #ifndef SIMULATOR
2681 #if CONFIG_TUNER
2682 { "FM Radio", dbg_fm_radio },
2683 #endif
2684 #endif
2685 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2686 { "Write back EEPROM", dbg_write_eeprom },
2687 #endif
2688 #if CONFIG_USBOTG == USBOTG_ISP1583
2689 { "View ISP1583 info", dbg_isp1583 },
2690 #endif
2691 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2692 { "View PIC info", dbg_pic },
2693 #endif
2694 #ifdef ROCKBOX_HAS_LOGF
2695 {"logf", logfdisplay },
2696 {"logfdump", logfdump },
2697 #endif
2698 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2699 {"logf over usb",logf_usb_serial },
2700 #endif
2701 #if defined(HAVE_USBSTACK) && defined(USB_STORAGE)
2702 {"reconnect usb storage",usb_reconnect},
2703 #endif
2704 #ifdef CPU_BOOST_LOGGING
2705 {"cpu_boost log",cpu_boost_log},
2706 #endif
2707 #if (defined(HAVE_SCROLLWHEEL) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2708 {"Debug scrollwheel", dbg_scrollwheel},
2709 #endif
2711 static int menu_action_callback(int btn, struct gui_synclist *lists)
2713 if (btn == ACTION_STD_OK)
2715 bool oldbars = viewportmanager_set_statusbar(false);
2716 menuitems[gui_synclist_get_sel_pos(lists)].function();
2717 btn = ACTION_REDRAW;
2718 viewportmanager_set_statusbar(oldbars);
2720 return btn;
2722 static char* dbg_menu_getname(int item, void * data,
2723 char *buffer, size_t buffer_len)
2725 (void)data; (void)buffer; (void)buffer_len;
2726 return menuitems[item].desc;
2728 bool debug_menu(void)
2730 struct simplelist_info info;
2732 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2733 info.action_callback = menu_action_callback;
2734 info.get_name = dbg_menu_getname;
2735 return simplelist_show_list(&info);