Attempt to fix yellow on sims (can't reproduce on my system).
[kugel-rb.git] / apps / debug_menu.c
blob6c6ed08596389b8050afb98c3a5e66b634e132e2
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 || CONFIG_CPU == JZ4732
106 #include "debug-target.h"
107 #endif
109 #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) \
110 || defined(SANSA_CLIP)
111 #include "ascodec.h"
112 #include "as3514.h"
113 #endif
115 #if defined(HAVE_USBSTACK)
116 #include "usb_core.h"
117 #endif
119 /*---------------------------------------------------*/
120 /* SPECIAL DEBUG STUFF */
121 /*---------------------------------------------------*/
122 extern struct thread_entry threads[MAXTHREADS];
124 static char thread_status_char(unsigned status)
126 static const char thread_status_chars[THREAD_NUM_STATES+1] =
128 [0 ... THREAD_NUM_STATES] = '?',
129 [STATE_RUNNING] = 'R',
130 [STATE_BLOCKED] = 'B',
131 [STATE_SLEEPING] = 'S',
132 [STATE_BLOCKED_W_TMO] = 'T',
133 [STATE_FROZEN] = 'F',
134 [STATE_KILLED] = 'K',
137 if (status > THREAD_NUM_STATES)
138 status = THREAD_NUM_STATES;
140 return thread_status_chars[status];
143 static char* threads_getname(int selected_item, void *data,
144 char *buffer, size_t buffer_len)
146 (void)data;
147 struct thread_entry *thread;
148 char name[32];
150 #if NUM_CORES > 1
151 if (selected_item < (int)NUM_CORES)
153 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
154 idle_stack_usage(selected_item));
155 return buffer;
158 selected_item -= NUM_CORES;
159 #endif
161 thread = &threads[selected_item];
163 if (thread->state == STATE_KILLED)
165 snprintf(buffer, buffer_len, "%2d: ---", selected_item);
166 return buffer;
169 thread_get_name(name, 32, thread);
171 snprintf(buffer, buffer_len,
172 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
173 selected_item,
174 IF_COP(thread->core,)
175 #ifdef HAVE_SCHEDULER_BOOSTCTRL
176 (thread->cpu_boost) ? '+' :
177 #endif
178 ((thread->state == STATE_RUNNING) ? '*' : ' '),
179 thread_status_char(thread->state),
180 IF_PRIO(thread->base_priority, thread->priority, )
181 thread_stack_usage(thread), name);
183 return buffer;
185 static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
187 (void)lists;
188 #ifdef ROCKBOX_HAS_LOGF
189 if (action == ACTION_STD_OK)
191 int selpos = gui_synclist_get_sel_pos(lists);
192 #if NUM_CORES > 1
193 if (selpos >= NUM_CORES)
194 remove_thread(&threads[selpos - NUM_CORES]);
195 #else
196 remove_thread(&threads[selpos]);
197 #endif
198 return ACTION_REDRAW;
200 #endif /* ROCKBOX_HAS_LOGF */
201 if (action == ACTION_NONE)
202 action = ACTION_REDRAW;
203 return action;
205 /* Test code!!! */
206 static bool dbg_os(void)
208 struct simplelist_info info;
209 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
210 #if NUM_CORES == 1
211 MAXTHREADS,
212 #else
213 MAXTHREADS+NUM_CORES,
214 #endif
215 NULL);
216 #ifndef ROCKBOX_HAS_LOGF
217 info.hide_selection = true;
218 info.scroll_all = true;
219 #endif
220 info.action_callback = dbg_threads_action_callback;
221 info.get_name = threads_getname;
222 return simplelist_show_list(&info);
225 #ifdef HAVE_LCD_BITMAP
226 #if CONFIG_CODEC != SWCODEC
227 #ifndef SIMULATOR
228 static bool dbg_audio_thread(void)
230 char buf[32];
231 struct audio_debug d;
233 lcd_setfont(FONT_SYSFIXED);
235 while(1)
237 if (action_userabort(HZ/5))
238 return false;
240 audio_get_debugdata(&d);
242 lcd_clear_display();
244 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
245 lcd_puts(0, 0, buf);
246 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
247 lcd_puts(0, 1, buf);
248 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
249 lcd_puts(0, 2, buf);
250 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
251 lcd_puts(0, 3, buf);
252 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
253 lcd_puts(0, 4, buf);
254 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
255 lcd_puts(0, 5, buf);
257 /* Playable space left */
258 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
259 d.playable_space, HORIZONTAL);
261 /* Show the watermark limit */
262 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
263 d.low_watermark_level, HORIZONTAL);
265 snprintf(buf, sizeof(buf), "wm: %x - %x",
266 d.low_watermark_level, d.lowest_watermark_level);
267 lcd_puts(0, 7, buf);
269 lcd_update();
271 lcd_setfont(FONT_UI);
272 return false;
274 #endif /* !SIMULATOR */
275 #else /* CONFIG_CODEC == SWCODEC */
276 extern size_t filebuflen;
277 /* This is a size_t, but call it a long so it puts a - when it's bad. */
279 static unsigned int ticks, boost_ticks, freq_sum;
281 static void dbg_audio_task(void)
283 #ifndef SIMULATOR
284 if(FREQ > CPUFREQ_NORMAL)
285 boost_ticks++;
286 freq_sum += FREQ/1000000; /* in MHz */
287 #endif
288 ticks++;
291 static bool dbg_buffering_thread(void)
293 char buf[32];
294 int button;
295 int line;
296 bool done = false;
297 size_t bufused;
298 size_t bufsize = pcmbuf_get_bufsize();
299 int pcmbufdescs = pcmbuf_descs();
300 struct buffering_debug d;
302 ticks = boost_ticks = freq_sum = 0;
304 tick_add_task(dbg_audio_task);
306 lcd_setfont(FONT_SYSFIXED);
307 while(!done)
309 button = get_action(CONTEXT_STD,HZ/5);
310 switch(button)
312 case ACTION_STD_NEXT:
313 audio_next();
314 break;
315 case ACTION_STD_PREV:
316 audio_prev();
317 break;
318 case ACTION_STD_CANCEL:
319 done = true;
320 break;
323 buffering_get_debugdata(&d);
325 line = 0;
326 lcd_clear_display();
328 bufused = bufsize - pcmbuf_free();
330 snprintf(buf, sizeof(buf), "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
331 lcd_puts(0, line++, buf);
333 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
334 bufsize, 0, bufused, HORIZONTAL);
335 line++;
337 snprintf(buf, sizeof(buf), "alloc: %6ld/%ld", audio_filebufused(),
338 (long) filebuflen);
339 lcd_puts(0, line++, buf);
341 #if LCD_HEIGHT > 80
342 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
343 filebuflen, 0, audio_filebufused(), HORIZONTAL);
344 line++;
346 snprintf(buf, sizeof(buf), "real: %6ld/%ld", (long)d.buffered_data,
347 (long)filebuflen);
348 lcd_puts(0, line++, buf);
350 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
351 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
352 line++;
353 #endif
355 snprintf(buf, sizeof(buf), "usefl: %6ld/%ld", (long)(d.useful_data),
356 (long)filebuflen);
357 lcd_puts(0, line++, buf);
359 #if LCD_HEIGHT > 80
360 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6,
361 filebuflen, 0, d.useful_data, HORIZONTAL);
362 line++;
363 #endif
365 snprintf(buf, sizeof(buf), "data_rem: %ld", (long)d.data_rem);
366 lcd_puts(0, line++, buf);
368 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
369 lcd_puts(0, line++, buf);
371 snprintf(buf, sizeof(buf), "handle count: %d", (int)d.num_handles);
372 lcd_puts(0, line++, buf);
374 #ifndef SIMULATOR
375 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
376 (int)((FREQ + 500000) / 1000000));
377 lcd_puts(0, line++, buf);
378 #endif
380 if (ticks > 0)
382 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
383 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
384 snprintf(buf, sizeof(buf), "boost:%3d.%d%% (%d.%dMHz)",
385 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
386 lcd_puts(0, line++, buf);
389 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
390 pcmbuf_used_descs(), pcmbufdescs);
391 lcd_puts(0, line++, buf);
392 snprintf(buf, sizeof(buf), "watermark: %6d",
393 (int)(d.watermark));
394 lcd_puts(0, line++, buf);
396 lcd_update();
399 tick_remove_task(dbg_audio_task);
400 lcd_setfont(FONT_UI);
402 return false;
404 #endif /* CONFIG_CODEC */
405 #endif /* HAVE_LCD_BITMAP */
408 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE))
409 /* Tool function to read the flash manufacturer and type, if available.
410 Only chips which could be reprogrammed in system will return values.
411 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
412 /* In IRAM to avoid problems when running directly from Flash */
413 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
414 unsigned addr1, unsigned addr2)
415 ICODE_ATTR __attribute__((noinline));
416 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
417 unsigned addr1, unsigned addr2)
420 unsigned not_manu, not_id; /* read values before switching to ID mode */
421 unsigned manu, id; /* read values when in ID mode */
423 #if CONFIG_CPU == SH7034
424 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
425 #elif defined(CPU_COLDFIRE)
426 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
427 #endif
428 int old_level; /* saved interrupt level */
430 not_manu = flash[0]; /* read the normal content */
431 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
433 /* disable interrupts, prevent any stray flash access */
434 old_level = disable_irq_save();
436 flash[addr1] = 0xAA; /* enter command mode */
437 flash[addr2] = 0x55;
438 flash[addr1] = 0x90; /* ID command */
439 /* Atmel wants 20ms pause here */
440 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
442 manu = flash[0]; /* read the IDs */
443 id = flash[1];
445 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
446 /* Atmel wants 20ms pause here */
447 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
449 restore_irq(old_level); /* enable interrupts again */
451 /* I assume success if the obtained values are different from
452 the normal flash content. This is not perfectly bulletproof, they
453 could theoretically be the same by chance, causing us to fail. */
454 if (not_manu != manu || not_id != id) /* a value has changed */
456 *p_manufacturer = manu; /* return the results */
457 *p_device = id;
458 return true; /* success */
460 return false; /* fail */
462 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) */
464 #ifndef SIMULATOR
465 #ifdef CPU_PP
466 static int perfcheck(void)
468 int result;
470 asm (
471 "mrs r2, CPSR \n"
472 "orr r0, r2, #0xc0 \n" /* disable IRQ and FIQ */
473 "msr CPSR_c, r0 \n"
474 "mov %[res], #0 \n"
475 "ldr r0, [%[timr]] \n"
476 "add r0, r0, %[tmo] \n"
477 "1: \n"
478 "add %[res], %[res], #1 \n"
479 "ldr r1, [%[timr]] \n"
480 "cmp r1, r0 \n"
481 "bmi 1b \n"
482 "msr CPSR_c, r2 \n" /* reset IRQ and FIQ state */
484 [res]"=&r"(result)
486 [timr]"r"(&USEC_TIMER),
487 [tmo]"r"(
488 #if CONFIG_CPU == PP5002
489 16000
490 #else /* PP5020/5022/5024 */
491 10226
492 #endif
495 "r0", "r1", "r2"
497 return result;
499 #endif
501 #ifdef HAVE_LCD_BITMAP
502 static bool dbg_hw_info(void)
504 #if CONFIG_CPU == SH7034
505 char buf[32];
506 int bitmask = HW_MASK;
507 int rom_version = ROM_VERSION;
508 unsigned manu, id; /* flash IDs */
509 bool got_id; /* flag if we managed to get the flash IDs */
510 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
511 bool has_bootrom; /* flag for boot ROM present */
512 int oldmode; /* saved memory guard mode */
514 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
516 /* get flash ROM type */
517 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
518 if (!got_id)
519 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
521 /* check if the boot ROM area is a flash mirror */
522 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
523 if (has_bootrom) /* if ROM and Flash different */
525 /* calculate CRC16 checksum of boot ROM */
526 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
529 system_memory_guard(oldmode); /* re-enable memory guard */
531 lcd_setfont(FONT_SYSFIXED);
532 lcd_clear_display();
534 lcd_puts(0, 0, "[Hardware info]");
536 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
537 lcd_puts(0, 1, buf);
539 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
540 lcd_puts(0, 2, buf);
542 if (got_id)
543 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
544 else
545 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
546 lcd_puts(0, 3, buf);
548 if (has_bootrom)
550 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
551 snprintf(buf, 32, "Boot ROM: V1");
552 else
553 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
555 else
557 snprintf(buf, 32, "Boot ROM: none");
559 lcd_puts(0, 4, buf);
561 lcd_update();
563 while (!(action_userabort(TIMEOUT_BLOCK)));
565 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
566 char buf[32];
567 unsigned manu, id; /* flash IDs */
568 int got_id; /* flag if we managed to get the flash IDs */
569 int oldmode; /* saved memory guard mode */
570 int line = 0;
572 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
574 /* get flash ROM type */
575 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
576 if (!got_id)
577 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
579 system_memory_guard(oldmode); /* re-enable memory guard */
581 lcd_setfont(FONT_SYSFIXED);
582 lcd_clear_display();
584 lcd_puts(0, line++, "[Hardware info]");
586 if (got_id)
587 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
588 else
589 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
590 lcd_puts(0, line++, buf);
592 #ifdef IAUDIO_X5
594 struct ds2411_id id;
596 lcd_puts(0, ++line, "Serial Number:");
598 got_id = ds2411_read_id(&id);
600 if (got_id == DS2411_OK)
602 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
603 lcd_puts(0, ++line, buf);
604 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
605 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
606 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
607 lcd_puts(0, ++line, buf);
608 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
610 else
612 snprintf(buf, 32, "READ ERR=%d", got_id);
615 lcd_puts(0, ++line, buf);
617 #endif
619 lcd_update();
621 while (!(action_userabort(TIMEOUT_BLOCK)));
623 #elif defined(CPU_PP502x)
624 int line = 0;
625 char buf[32];
626 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
627 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
628 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
629 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
631 lcd_setfont(FONT_SYSFIXED);
632 lcd_clear_display();
634 lcd_puts(0, line++, "[Hardware info]");
636 #ifdef IPOD_ARCH
637 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
638 lcd_puts(0, line++, buf);
639 #endif
641 #ifdef IPOD_COLOR
642 extern int lcd_type; /* Defined in lcd-colornano.c */
644 snprintf(buf, sizeof(buf), "LCD type: %d", lcd_type);
645 lcd_puts(0, line++, buf);
646 #endif
648 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
649 lcd_puts(0, line++, buf);
651 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
652 lcd_puts(0, line++, buf);
654 lcd_update();
656 while (!(action_userabort(TIMEOUT_BLOCK)));
658 #elif CONFIG_CPU == PP5002
659 int line = 0;
660 char buf[32];
661 char pp_version[] = { (PP_VER4 >> 8) & 0xff, PP_VER4 & 0xff,
662 (PP_VER3 >> 8) & 0xff, PP_VER3 & 0xff,
663 (PP_VER2 >> 8) & 0xff, PP_VER2 & 0xff,
664 (PP_VER1 >> 8) & 0xff, PP_VER1 & 0xff, '\0' };
667 lcd_setfont(FONT_SYSFIXED);
668 lcd_clear_display();
670 lcd_puts(0, line++, "[Hardware info]");
672 #ifdef IPOD_ARCH
673 snprintf(buf, sizeof(buf), "HW rev: 0x%08lx", IPOD_HW_REVISION);
674 lcd_puts(0, line++, buf);
675 #endif
677 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
678 lcd_puts(0, line++, buf);
680 snprintf(buf, sizeof(buf), "Est. clock (kHz): %d", perfcheck());
681 lcd_puts(0, line++, buf);
683 lcd_update();
685 while (!(action_userabort(TIMEOUT_BLOCK)));
687 #else
688 /* Define this function in your target tree */
689 return __dbg_hw_info();
690 #endif /* CONFIG_CPU */
691 lcd_setfont(FONT_UI);
692 return false;
694 #else /* !HAVE_LCD_BITMAP */
695 static bool dbg_hw_info(void)
697 char buf[32];
698 int button;
699 int currval = 0;
700 int rom_version = ROM_VERSION;
701 unsigned manu, id; /* flash IDs */
702 bool got_id; /* flag if we managed to get the flash IDs */
703 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
704 bool has_bootrom; /* flag for boot ROM present */
705 int oldmode; /* saved memory guard mode */
707 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
709 /* get flash ROM type */
710 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
711 if (!got_id)
712 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
714 /* check if the boot ROM area is a flash mirror */
715 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
716 if (has_bootrom) /* if ROM and Flash different */
718 /* calculate CRC16 checksum of boot ROM */
719 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
722 system_memory_guard(oldmode); /* re-enable memory guard */
724 lcd_clear_display();
726 lcd_puts(0, 0, "[HW Info]");
727 while(1)
729 switch(currval)
731 case 0:
732 snprintf(buf, 32, "ROM: %d.%02d",
733 rom_version/100, rom_version%100);
734 break;
735 case 1:
736 if (got_id)
737 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
738 else
739 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
740 break;
741 case 2:
742 if (has_bootrom)
744 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
745 snprintf(buf, 32, "BootROM: V1");
746 else if (rom_crc == 0x358099E8)
747 snprintf(buf, 32, "BootROM: V2");
748 /* alternative boot ROM found in one single player so far */
749 else
750 snprintf(buf, 32, "R: %08x", rom_crc);
752 else
753 snprintf(buf, 32, "BootROM: no");
756 lcd_puts(0, 1, buf);
757 lcd_update();
759 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
761 switch(button)
763 case ACTION_STD_CANCEL:
764 return false;
766 case ACTION_SETTINGS_DEC:
767 currval--;
768 if(currval < 0)
769 currval = 2;
770 break;
772 case ACTION_SETTINGS_INC:
773 currval++;
774 if(currval > 2)
775 currval = 0;
776 break;
779 return false;
781 #endif /* !HAVE_LCD_BITMAP */
782 #endif /* !SIMULATOR */
784 #ifndef SIMULATOR
785 static char* dbg_partitions_getname(int selected_item, void *data,
786 char *buffer, size_t buffer_len)
788 (void)data;
789 int partition = selected_item/2;
790 struct partinfo* p = disk_partinfo(partition);
791 if (selected_item%2)
793 snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / 2048);
795 else
797 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
799 return buffer;
802 bool dbg_partitions(void)
804 struct simplelist_info info;
805 simplelist_info_init(&info, "Partition Info", 4, NULL);
806 info.selection_size = 2;
807 info.hide_selection = true;
808 info.scroll_all = true;
809 info.get_name = dbg_partitions_getname;
810 return simplelist_show_list(&info);
812 #endif
814 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
815 static bool dbg_spdif(void)
817 char buf[128];
818 int line;
819 unsigned int control;
820 int x;
821 char *s;
822 int category;
823 int generation;
824 unsigned int interruptstat;
825 bool valnogood, symbolerr, parityerr;
826 bool done = false;
827 bool spdif_src_on;
828 int spdif_source = spdif_get_output_source(&spdif_src_on);
829 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
831 lcd_clear_display();
832 lcd_setfont(FONT_SYSFIXED);
834 #ifdef HAVE_SPDIF_POWER
835 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
836 #endif
838 while (!done)
840 line = 0;
842 control = EBU1RCVCCHANNEL1;
843 interruptstat = INTERRUPTSTAT;
844 INTERRUPTCLEAR = 0x03c00000;
846 valnogood = (interruptstat & 0x01000000)?true:false;
847 symbolerr = (interruptstat & 0x00800000)?true:false;
848 parityerr = (interruptstat & 0x00400000)?true:false;
850 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
851 valnogood?"--":"OK",
852 symbolerr?"--":"OK",
853 parityerr?"--":"OK");
854 lcd_puts(0, line++, buf);
856 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
857 lcd_puts(0, line++, buf);
859 line++;
861 x = control >> 31;
862 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
863 x, x?"Professional":"Consumer");
864 lcd_puts(0, line++, buf);
866 x = (control >> 30) & 1;
867 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
868 x, x?"Non-PCM":"PCM");
869 lcd_puts(0, line++, buf);
871 x = (control >> 29) & 1;
872 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
873 x, x?"Permitted":"Inhibited");
874 lcd_puts(0, line++, buf);
876 x = (control >> 27) & 7;
877 switch(x)
879 case 0:
880 s = "None";
881 break;
882 case 1:
883 s = "50/15us";
884 break;
885 default:
886 s = "Reserved";
887 break;
889 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
890 lcd_puts(0, line++, buf);
892 x = (control >> 24) & 3;
893 snprintf(buf, sizeof(buf), "Mode: %d", x);
894 lcd_puts(0, line++, buf);
896 category = (control >> 17) & 127;
897 switch(category)
899 case 0x00:
900 s = "General";
901 break;
902 case 0x40:
903 s = "Audio CD";
904 break;
905 default:
906 s = "Unknown";
908 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
909 lcd_puts(0, line++, buf);
911 x = (control >> 16) & 1;
912 generation = x;
913 if(((category & 0x70) == 0x10) ||
914 ((category & 0x70) == 0x40) ||
915 ((category & 0x78) == 0x38))
917 generation = !generation;
919 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
920 x, generation?"Original":"No ind.");
921 lcd_puts(0, line++, buf);
923 x = (control >> 12) & 15;
924 snprintf(buf, sizeof(buf), "Source: %d", x);
925 lcd_puts(0, line++, buf);
927 x = (control >> 8) & 15;
928 switch(x)
930 case 0:
931 s = "Unspecified";
932 break;
933 case 8:
934 s = "A (Left)";
935 break;
936 case 4:
937 s = "B (Right)";
938 break;
939 default:
940 s = "";
941 break;
943 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
944 lcd_puts(0, line++, buf);
946 x = (control >> 4) & 15;
947 switch(x)
949 case 0:
950 s = "44.1kHz";
951 break;
952 case 0x4:
953 s = "48kHz";
954 break;
955 case 0xc:
956 s = "32kHz";
957 break;
959 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
960 lcd_puts(0, line++, buf);
962 x = (control >> 2) & 3;
963 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
964 lcd_puts(0, line++, buf);
965 line++;
967 #ifndef SIMULATOR
968 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
969 spdif_measure_frequency());
970 lcd_puts(0, line++, buf);
971 #endif
973 lcd_update();
975 if (action_userabort(HZ/10))
976 break;
979 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
981 #ifdef HAVE_SPDIF_POWER
982 spdif_power_enable(global_settings.spdif_enable);
983 #endif
985 lcd_setfont(FONT_UI);
986 return false;
988 #endif /* CPU_COLDFIRE */
990 #ifndef SIMULATOR
991 #ifdef HAVE_LCD_BITMAP
992 /* button definitions */
993 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
994 (CONFIG_KEYPAD == IRIVER_H300_PAD)
995 # define DEBUG_CANCEL BUTTON_OFF
997 #elif CONFIG_KEYPAD == RECORDER_PAD
998 # define DEBUG_CANCEL BUTTON_OFF
1000 #elif CONFIG_KEYPAD == ONDIO_PAD
1001 # define DEBUG_CANCEL BUTTON_MENU
1003 #elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || \
1004 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
1005 (CONFIG_KEYPAD == IPOD_4G_PAD)
1006 # define DEBUG_CANCEL BUTTON_MENU
1008 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
1009 # define DEBUG_CANCEL BUTTON_PLAY
1011 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
1012 # define DEBUG_CANCEL BUTTON_REC
1014 #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD)
1015 # define DEBUG_CANCEL BUTTON_RC_REC
1017 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
1018 # define DEBUG_CANCEL BUTTON_REW
1020 #elif (CONFIG_KEYPAD == MROBE100_PAD)
1021 # define DEBUG_CANCEL BUTTON_MENU
1023 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
1024 (CONFIG_KEYPAD == SANSA_C200_PAD)
1025 # define DEBUG_CANCEL BUTTON_LEFT
1027 /* This is temporary until the SA9200 touchpad works */
1028 #elif (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) || \
1029 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD)
1030 # define DEBUG_CANCEL BUTTON_POWER
1032 #endif /* key definitions */
1034 /* Test code!!! */
1035 bool dbg_ports(void)
1037 #if CONFIG_CPU == SH7034
1038 char buf[32];
1039 int adc_battery_voltage, adc_battery_level;
1041 lcd_setfont(FONT_SYSFIXED);
1042 lcd_clear_display();
1044 while(1)
1046 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1047 lcd_puts(0, 0, buf);
1048 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1049 lcd_puts(0, 1, buf);
1051 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1052 lcd_puts(0, 2, buf);
1053 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1054 lcd_puts(0, 3, buf);
1055 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1056 lcd_puts(0, 4, buf);
1057 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1058 lcd_puts(0, 5, buf);
1060 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1061 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1062 adc_battery_voltage % 1000, adc_battery_level);
1063 lcd_puts(0, 6, buf);
1065 lcd_update();
1066 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1068 lcd_setfont(FONT_UI);
1069 return false;
1072 #elif defined(CPU_COLDFIRE)
1073 unsigned int gpio_out;
1074 unsigned int gpio1_out;
1075 unsigned int gpio_read;
1076 unsigned int gpio1_read;
1077 unsigned int gpio_function;
1078 unsigned int gpio1_function;
1079 unsigned int gpio_enable;
1080 unsigned int gpio1_enable;
1081 int adc_buttons, adc_remote;
1082 int adc_battery_voltage, adc_battery_level;
1083 char buf[128];
1084 int line;
1086 lcd_clear_display();
1087 lcd_setfont(FONT_SYSFIXED);
1089 while(1)
1091 line = 0;
1092 gpio_read = GPIO_READ;
1093 gpio1_read = GPIO1_READ;
1094 gpio_out = GPIO_OUT;
1095 gpio1_out = GPIO1_OUT;
1096 gpio_function = GPIO_FUNCTION;
1097 gpio1_function = GPIO1_FUNCTION;
1098 gpio_enable = GPIO_ENABLE;
1099 gpio1_enable = GPIO1_ENABLE;
1101 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1102 lcd_puts(0, line++, buf);
1103 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1104 lcd_puts(0, line++, buf);
1105 snprintf(buf, sizeof(buf), "GPIO_FUNC: %08x", gpio_function);
1106 lcd_puts(0, line++, buf);
1107 snprintf(buf, sizeof(buf), "GPIO_ENA: %08x", gpio_enable);
1108 lcd_puts(0, line++, buf);
1110 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1111 lcd_puts(0, line++, buf);
1112 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1113 lcd_puts(0, line++, buf);
1114 snprintf(buf, sizeof(buf), "GPIO1_FUNC: %08x", gpio1_function);
1115 lcd_puts(0, line++, buf);
1116 snprintf(buf, sizeof(buf), "GPIO1_ENA: %08x", gpio1_enable);
1117 lcd_puts(0, line++, buf);
1119 adc_buttons = adc_read(ADC_BUTTONS);
1120 adc_remote = adc_read(ADC_REMOTE);
1121 battery_read_info(&adc_battery_voltage, &adc_battery_level);
1122 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1123 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1124 button_scan_enabled() ? '+' : '-', adc_buttons);
1125 #else
1126 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1127 #endif
1128 lcd_puts(0, line++, buf);
1129 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1130 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1131 remote_detect() ? '+' : '-', adc_remote);
1132 #else
1133 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1134 #endif
1135 lcd_puts(0, line++, buf);
1136 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1137 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1138 adc_read(ADC_REMOTEDETECT));
1139 lcd_puts(0, line++, buf);
1140 #endif
1142 snprintf(buf, 32, "Batt: %d.%03dV %d%% ", adc_battery_voltage / 1000,
1143 adc_battery_voltage % 1000, adc_battery_level);
1144 lcd_puts(0, line++, buf);
1146 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1147 snprintf(buf, sizeof(buf), "remotetype: %d", remote_type());
1148 lcd_puts(0, line++, buf);
1149 #endif
1151 lcd_update();
1152 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1154 lcd_setfont(FONT_UI);
1155 return false;
1159 #elif defined(CPU_PP502x)
1161 char buf[128];
1162 int line;
1164 lcd_clear_display();
1165 lcd_setfont(FONT_SYSFIXED);
1167 while(1)
1169 line = 0;
1170 lcd_puts(0, line++, "GPIO STATES:");
1171 snprintf(buf, sizeof(buf), "A: %02x E: %02x I: %02x",
1172 (unsigned int)GPIOA_INPUT_VAL,
1173 (unsigned int)GPIOE_INPUT_VAL,
1174 (unsigned int)GPIOI_INPUT_VAL);
1175 lcd_puts(0, line++, buf);
1176 snprintf(buf, sizeof(buf), "B: %02x F: %02x J: %02x",
1177 (unsigned int)GPIOB_INPUT_VAL,
1178 (unsigned int)GPIOF_INPUT_VAL,
1179 (unsigned int)GPIOJ_INPUT_VAL);
1180 lcd_puts(0, line++, buf);
1181 snprintf(buf, sizeof(buf), "C: %02x G: %02x K: %02x",
1182 (unsigned int)GPIOC_INPUT_VAL,
1183 (unsigned int)GPIOG_INPUT_VAL,
1184 (unsigned int)GPIOK_INPUT_VAL);
1185 lcd_puts(0, line++, buf);
1186 snprintf(buf, sizeof(buf), "D: %02x H: %02x L: %02x",
1187 (unsigned int)GPIOD_INPUT_VAL,
1188 (unsigned int)GPIOH_INPUT_VAL,
1189 (unsigned int)GPIOL_INPUT_VAL);
1190 lcd_puts(0, line++, buf);
1191 line++;
1192 snprintf(buf, sizeof(buf), "GPO32_VAL: %08lx", GPO32_VAL);
1193 lcd_puts(0, line++, buf);
1194 snprintf(buf, sizeof(buf), "GPO32_EN: %08lx", GPO32_ENABLE);
1195 lcd_puts(0, line++, buf);
1196 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1197 lcd_puts(0, line++, buf);
1198 snprintf(buf, sizeof(buf), "DEV_EN2: %08lx", DEV_EN2);
1199 lcd_puts(0, line++, buf);
1200 snprintf(buf, sizeof(buf), "DEV_EN3: %08lx", inl(0x60006044));
1201 lcd_puts(0, line++, buf); /* to be verified */
1202 snprintf(buf, sizeof(buf), "DEV_INIT1: %08lx", DEV_INIT1);
1203 lcd_puts(0, line++, buf);
1204 snprintf(buf, sizeof(buf), "DEV_INIT2: %08lx", DEV_INIT2);
1205 lcd_puts(0, line++, buf);
1206 #ifdef ADC_ACCESSORY
1207 snprintf(buf, sizeof(buf), "ACCESSORY: %d", adc_read(ADC_ACCESSORY));
1208 lcd_puts(0, line++, buf);
1209 #endif
1211 #if defined(IPOD_ACCESSORY_PROTOCOL)
1212 extern unsigned char serbuf[];
1213 snprintf(buf, sizeof(buf), "IAP PACKET: %02x %02x %02x %02x %02x %02x %02x %02x",
1214 serbuf[0], serbuf[1], serbuf[2], serbuf[3], serbuf[4], serbuf[5],
1215 serbuf[6], serbuf[7]);
1216 lcd_puts(0, line++, buf);
1217 #endif
1219 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1220 line++;
1221 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1222 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1223 lcd_puts(0, line++, buf);
1224 snprintf(buf, sizeof(buf), "REM: %03x PAD: %03x",
1225 adc_read(ADC_REMOTE), adc_read(ADC_SCROLLPAD));
1226 lcd_puts(0, line++, buf);
1227 #elif defined(PHILIPS_HDD1630)
1228 line++;
1229 snprintf(buf, sizeof(buf), "BATT: %03x UNK1: %03x",
1230 adc_read(ADC_BATTERY), adc_read(ADC_UNKNOWN_1));
1231 lcd_puts(0, line++, buf);
1232 #elif defined(SANSA_E200) || defined(PHILIPS_SA9200)
1233 snprintf(buf, sizeof(buf), "ADC_BVDD: %4d", adc_read(ADC_BVDD));
1234 lcd_puts(0, line++, buf);
1235 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %4d", adc_read(ADC_RTCSUP));
1236 lcd_puts(0, line++, buf);
1237 snprintf(buf, sizeof(buf), "ADC_UVDD: %4d", adc_read(ADC_UVDD));
1238 lcd_puts(0, line++, buf);
1239 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %4d", adc_read(ADC_CHG_IN));
1240 lcd_puts(0, line++, buf);
1241 snprintf(buf, sizeof(buf), "ADC_CVDD: %4d", adc_read(ADC_CVDD));
1242 lcd_puts(0, line++, buf);
1243 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %4d", adc_read(ADC_BATTEMP));
1244 lcd_puts(0, line++, buf);
1245 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %4d", adc_read(ADC_MICSUP1));
1246 lcd_puts(0, line++, buf);
1247 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %4d", adc_read(ADC_MICSUP2));
1248 lcd_puts(0, line++, buf);
1249 snprintf(buf, sizeof(buf), "ADC_VBE1: %4d", adc_read(ADC_VBE1));
1250 lcd_puts(0, line++, buf);
1251 snprintf(buf, sizeof(buf), "ADC_VBE2: %4d", adc_read(ADC_VBE2));
1252 lcd_puts(0, line++, buf);
1253 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1:%4d", adc_read(ADC_I_MICSUP1));
1254 lcd_puts(0, line++, buf);
1255 #if !defined(PHILIPS_SA9200)
1256 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2:%4d", adc_read(ADC_I_MICSUP2));
1257 lcd_puts(0, line++, buf);
1258 snprintf(buf, sizeof(buf), "ADC_VBAT: %4d", adc_read(ADC_VBAT));
1259 lcd_puts(0, line++, buf);
1260 #endif
1261 #endif
1262 lcd_update();
1263 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1265 lcd_setfont(FONT_UI);
1266 return false;
1270 #elif CONFIG_CPU == PP5002
1271 char buf[128];
1272 int line;
1274 lcd_clear_display();
1275 lcd_setfont(FONT_SYSFIXED);
1277 while(1)
1279 line = 0;
1280 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x",
1281 (unsigned int)GPIOA_INPUT_VAL, (unsigned int)GPIOB_INPUT_VAL);
1282 lcd_puts(0, line++, buf);
1283 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x",
1284 (unsigned int)GPIOC_INPUT_VAL, (unsigned int)GPIOD_INPUT_VAL);
1285 lcd_puts(0, line++, buf);
1287 snprintf(buf, sizeof(buf), "DEV_EN: %08lx", DEV_EN);
1288 lcd_puts(0, line++, buf);
1289 snprintf(buf, sizeof(buf), "CLOCK_ENABLE: %08lx", CLOCK_ENABLE);
1290 lcd_puts(0, line++, buf);
1291 snprintf(buf, sizeof(buf), "CLOCK_SOURCE: %08lx", CLOCK_SOURCE);
1292 lcd_puts(0, line++, buf);
1293 snprintf(buf, sizeof(buf), "PLL_CONTROL: %08lx", PLL_CONTROL);
1294 lcd_puts(0, line++, buf);
1295 snprintf(buf, sizeof(buf), "PLL_DIV: %08lx", PLL_DIV);
1296 lcd_puts(0, line++, buf);
1297 snprintf(buf, sizeof(buf), "PLL_MULT: %08lx", PLL_MULT);
1298 lcd_puts(0, line++, buf);
1299 snprintf(buf, sizeof(buf), "TIMING1_CTL: %08lx", TIMING1_CTL);
1300 lcd_puts(0, line++, buf);
1301 snprintf(buf, sizeof(buf), "TIMING2_CTL: %08lx", TIMING2_CTL);
1302 lcd_puts(0, line++, buf);
1304 lcd_update();
1305 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1307 lcd_setfont(FONT_UI);
1308 return false;
1311 lcd_setfont(FONT_UI);
1312 #else
1313 return __dbg_ports();
1314 #endif /* CPU */
1315 return false;
1317 #else /* !HAVE_LCD_BITMAP */
1318 bool dbg_ports(void)
1320 char buf[32];
1321 int button;
1322 int adc_battery_voltage;
1323 int currval = 0;
1325 lcd_clear_display();
1327 while(1)
1329 switch(currval)
1331 case 0:
1332 snprintf(buf, 32, "PADR: %04x", (unsigned short)PADR);
1333 break;
1334 case 1:
1335 snprintf(buf, 32, "PBDR: %04x", (unsigned short)PBDR);
1336 break;
1337 case 2:
1338 snprintf(buf, 32, "AN0: %03x", adc_read(0));
1339 break;
1340 case 3:
1341 snprintf(buf, 32, "AN1: %03x", adc_read(1));
1342 break;
1343 case 4:
1344 snprintf(buf, 32, "AN2: %03x", adc_read(2));
1345 break;
1346 case 5:
1347 snprintf(buf, 32, "AN3: %03x", adc_read(3));
1348 break;
1349 case 6:
1350 snprintf(buf, 32, "AN4: %03x", adc_read(4));
1351 break;
1352 case 7:
1353 snprintf(buf, 32, "AN5: %03x", adc_read(5));
1354 break;
1355 case 8:
1356 snprintf(buf, 32, "AN6: %03x", adc_read(6));
1357 break;
1358 case 9:
1359 snprintf(buf, 32, "AN7: %03x", adc_read(7));
1360 break;
1362 lcd_puts(0, 0, buf);
1364 battery_read_info(&adc_battery_voltage, NULL);
1365 snprintf(buf, 32, "Batt: %d.%03dV", adc_battery_voltage / 1000,
1366 adc_battery_voltage % 1000);
1367 lcd_puts(0, 1, buf);
1368 lcd_update();
1370 button = get_action(CONTEXT_SETTINGS,HZ/5);
1372 switch(button)
1374 case ACTION_STD_CANCEL:
1375 return false;
1377 case ACTION_SETTINGS_DEC:
1378 currval--;
1379 if(currval < 0)
1380 currval = 9;
1381 break;
1383 case ACTION_SETTINGS_INC:
1384 currval++;
1385 if(currval > 9)
1386 currval = 0;
1387 break;
1390 return false;
1392 #endif /* !HAVE_LCD_BITMAP */
1393 #endif /* !SIMULATOR */
1395 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
1396 static bool dbg_pcf(void)
1398 char buf[128];
1399 int line;
1401 #ifdef HAVE_LCD_BITMAP
1402 lcd_setfont(FONT_SYSFIXED);
1403 #endif
1404 lcd_clear_display();
1406 while(1)
1408 line = 0;
1410 snprintf(buf, sizeof(buf), "DCDC1: %02x", pcf50605_read(0x1b));
1411 lcd_puts(0, line++, buf);
1412 snprintf(buf, sizeof(buf), "DCDC2: %02x", pcf50605_read(0x1c));
1413 lcd_puts(0, line++, buf);
1414 snprintf(buf, sizeof(buf), "DCDC3: %02x", pcf50605_read(0x1d));
1415 lcd_puts(0, line++, buf);
1416 snprintf(buf, sizeof(buf), "DCDC4: %02x", pcf50605_read(0x1e));
1417 lcd_puts(0, line++, buf);
1418 snprintf(buf, sizeof(buf), "DCDEC1: %02x", pcf50605_read(0x1f));
1419 lcd_puts(0, line++, buf);
1420 snprintf(buf, sizeof(buf), "DCDEC2: %02x", pcf50605_read(0x20));
1421 lcd_puts(0, line++, buf);
1422 snprintf(buf, sizeof(buf), "DCUDC1: %02x", pcf50605_read(0x21));
1423 lcd_puts(0, line++, buf);
1424 snprintf(buf, sizeof(buf), "DCUDC2: %02x", pcf50605_read(0x22));
1425 lcd_puts(0, line++, buf);
1426 snprintf(buf, sizeof(buf), "IOREGC: %02x", pcf50605_read(0x23));
1427 lcd_puts(0, line++, buf);
1428 snprintf(buf, sizeof(buf), "D1REGC: %02x", pcf50605_read(0x24));
1429 lcd_puts(0, line++, buf);
1430 snprintf(buf, sizeof(buf), "D2REGC: %02x", pcf50605_read(0x25));
1431 lcd_puts(0, line++, buf);
1432 snprintf(buf, sizeof(buf), "D3REGC: %02x", pcf50605_read(0x26));
1433 lcd_puts(0, line++, buf);
1434 snprintf(buf, sizeof(buf), "LPREG1: %02x", pcf50605_read(0x27));
1435 lcd_puts(0, line++, buf);
1437 lcd_update();
1438 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1440 lcd_setfont(FONT_UI);
1441 return false;
1445 lcd_setfont(FONT_UI);
1446 return false;
1448 #endif
1450 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1451 static bool dbg_cpufreq(void)
1453 char buf[128];
1454 int line;
1455 int button;
1457 #ifdef HAVE_LCD_BITMAP
1458 lcd_setfont(FONT_SYSFIXED);
1459 #endif
1460 lcd_clear_display();
1462 while(1)
1464 line = 0;
1466 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1467 lcd_puts(0, line++, buf);
1469 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1470 lcd_puts(0, line++, buf);
1472 lcd_update();
1473 button = get_action(CONTEXT_STD,HZ/10);
1475 switch(button)
1477 case ACTION_STD_PREV:
1478 cpu_boost(true);
1479 break;
1481 case ACTION_STD_NEXT:
1482 cpu_boost(false);
1483 break;
1485 case ACTION_STD_OK:
1486 while (get_cpu_boost_counter() > 0)
1487 cpu_boost(false);
1488 set_cpu_frequency(CPUFREQ_DEFAULT);
1489 break;
1491 case ACTION_STD_CANCEL:
1492 lcd_setfont(FONT_UI);
1493 return false;
1496 lcd_setfont(FONT_UI);
1497 return false;
1499 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1501 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
1502 #include "tsc2100.h"
1503 static char *itob(int n, int len)
1505 static char binary[64];
1506 int i,j;
1507 for (i=1, j=0;i<=len;i++)
1509 binary[j++] = n&(1<<(len-i))?'1':'0';
1510 if (i%4 == 0)
1511 binary[j++] = ' ';
1513 binary[j] = '\0';
1514 return binary;
1516 static char* tsc2100_debug_getname(int selected_item, void * data,
1517 char *buffer, size_t buffer_len)
1519 int *page = (int*)data;
1520 bool reserved = false;
1521 switch (*page)
1523 case 0:
1524 if ((selected_item > 0x0a) ||
1525 (selected_item == 0x04) ||
1526 (selected_item == 0x08))
1527 reserved = true;
1528 break;
1529 case 1:
1530 if ((selected_item > 0x05) ||
1531 (selected_item == 0x02))
1532 reserved = true;
1533 break;
1534 case 2:
1535 if (selected_item > 0x1e)
1536 reserved = true;
1537 break;
1539 if (reserved)
1540 snprintf(buffer, buffer_len, "%02x: RESERVED", selected_item);
1541 else
1542 snprintf(buffer, buffer_len, "%02x: %s", selected_item,
1543 itob(tsc2100_readreg(*page, selected_item)&0xffff,16));
1544 return buffer;
1546 static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
1548 int *page = (int*)lists->data;
1549 if (action == ACTION_STD_OK)
1551 *page = (*page+1)%3;
1552 snprintf(lists->title, 32,
1553 "tsc2100 registers - Page %d", *page);
1554 return ACTION_REDRAW;
1556 return action;
1558 static bool tsc2100_debug(void)
1560 int page = 0;
1561 char title[32] = "tsc2100 registers - Page 0";
1562 struct simplelist_info info;
1563 simplelist_info_init(&info, title, 32, &page);
1564 info.timeout = HZ/100;
1565 info.get_name = tsc2100_debug_getname;
1566 info.action_callback= tsc2100debug_action_callback;
1567 return simplelist_show_list(&info);
1569 #endif
1570 #ifndef SIMULATOR
1571 #ifdef HAVE_LCD_BITMAP
1573 * view_battery() shows a automatically scaled graph of the battery voltage
1574 * over time. Usable for estimating battery life / charging rate.
1575 * The power_history array is updated in power_thread of powermgmt.c.
1578 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1579 #define BAT_YSPACE (LCD_HEIGHT - 20)
1581 static bool view_battery(void)
1583 int view = 0;
1584 int i, x, y;
1585 unsigned short maxv, minv;
1586 char buf[32];
1588 lcd_setfont(FONT_SYSFIXED);
1590 while(1)
1592 lcd_clear_display();
1593 switch (view) {
1594 case 0: /* voltage history graph */
1595 /* Find maximum and minimum voltage for scaling */
1596 minv = power_history[0];
1597 maxv = minv + 1;
1598 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
1599 if (power_history[i] > maxv)
1600 maxv = power_history[i];
1601 if (power_history[i] < minv)
1602 minv = power_history[i];
1605 snprintf(buf, 30, "Battery %d.%03d", power_history[0] / 1000,
1606 power_history[0] % 1000);
1607 lcd_puts(0, 0, buf);
1608 snprintf(buf, 30, "scale %d.%03d-%d.%03dV",
1609 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000);
1610 lcd_puts(0, 1, buf);
1612 x = 0;
1613 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1614 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1615 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1616 lcd_vline(x, LCD_HEIGHT-1, 20);
1617 lcd_set_drawmode(DRMODE_SOLID);
1618 lcd_vline(x, LCD_HEIGHT-1,
1619 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1620 x++;
1623 break;
1625 case 1: /* status: */
1626 lcd_puts(0, 0, "Power status:");
1628 battery_read_info(&y, NULL);
1629 snprintf(buf, 30, "Battery: %d.%03d V", y / 1000, y % 1000);
1630 lcd_puts(0, 1, buf);
1631 #ifdef ADC_EXT_POWER
1632 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
1633 snprintf(buf, 30, "External: %d.%03d V", y / 1000, y % 1000);
1634 lcd_puts(0, 2, buf);
1635 #endif
1636 #if CONFIG_CHARGING
1637 #if defined ARCHOS_RECORDER
1638 snprintf(buf, 30, "Chgr: %s %s",
1639 charger_inserted() ? "present" : "absent",
1640 charger_enabled() ? "on" : "off");
1641 lcd_puts(0, 3, buf);
1642 snprintf(buf, 30, "short delta: %d", short_delta);
1643 lcd_puts(0, 5, buf);
1644 snprintf(buf, 30, "long delta: %d", long_delta);
1645 lcd_puts(0, 6, buf);
1646 lcd_puts(0, 7, power_message);
1647 snprintf(buf, 30, "USB Inserted: %s",
1648 usb_inserted() ? "yes" : "no");
1649 lcd_puts(0, 8, buf);
1650 #elif defined IRIVER_H300_SERIES
1651 snprintf(buf, 30, "USB Charging Enabled: %s",
1652 usb_charging_enabled() ? "yes" : "no");
1653 lcd_puts(0, 9, buf);
1654 #elif defined IPOD_NANO || defined IPOD_VIDEO
1655 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1656 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1657 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1658 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1659 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1661 snprintf(buf, 30, "USB pwr: %s",
1662 usb_pwr ? "present" : "absent");
1663 lcd_puts(0, 3, buf);
1664 snprintf(buf, 30, "EXT pwr: %s",
1665 ext_pwr ? "present" : "absent");
1666 lcd_puts(0, 4, buf);
1667 snprintf(buf, 30, "Battery: %s",
1668 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1669 lcd_puts(0, 5, buf);
1670 snprintf(buf, 30, "Dock mode: %s",
1671 dock ? "enabled" : "disabled");
1672 lcd_puts(0, 6, buf);
1673 snprintf(buf, 30, "Headphone: %s",
1674 headphone ? "connected" : "disconnected");
1675 lcd_puts(0, 7, buf);
1676 #elif defined TOSHIBA_GIGABEAT_S
1677 int line = 3;
1678 unsigned int st;
1680 static const unsigned char * const chrgstate_strings[] =
1682 "Disabled",
1683 "Error",
1684 "Discharging",
1685 "Precharge",
1686 "Constant Voltage",
1687 "Constant Current",
1688 "<unknown>",
1691 snprintf(buf, 30, "Charger: %s",
1692 charger_inserted() ? "present" : "absent");
1693 lcd_puts(0, line++, buf);
1695 st = power_input_status() &
1696 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
1697 snprintf(buf, 30, "%s%s",
1698 (st & POWER_INPUT_MAIN_CHARGER) ? " Main" : "",
1699 (st & POWER_INPUT_USB_CHARGER) ? " USB" : "");
1700 lcd_puts(0, line++, buf);
1702 snprintf(buf, 30, "IUSB Max: %d", usb_allowed_current());
1703 lcd_puts(0, line++, buf);
1705 y = ARRAYLEN(chrgstate_strings) - 1;
1707 switch (charge_state)
1709 case CHARGE_STATE_DISABLED: y--;
1710 case CHARGE_STATE_ERROR: y--;
1711 case DISCHARGING: y--;
1712 case TRICKLE: y--;
1713 case TOPOFF: y--;
1714 case CHARGING: y--;
1715 default:;
1718 snprintf(buf, 30, "State: %s", chrgstate_strings[y]);
1719 lcd_puts(0, line++, buf);
1721 snprintf(buf, 30, "Battery Switch: %s",
1722 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
1723 lcd_puts(0, line++, buf);
1725 y = chrgraw_adc_voltage();
1726 snprintf(buf, 30, "CHRGRAW: %d.%03d V",
1727 y / 1000, y % 1000);
1728 lcd_puts(0, line++, buf);
1730 y = application_supply_adc_voltage();
1731 snprintf(buf, 30, "BP : %d.%03d V",
1732 y / 1000, y % 1000);
1733 lcd_puts(0, line++, buf);
1735 y = battery_adc_charge_current();
1736 if (y < 0) x = '-', y = -y;
1737 else x = ' ';
1738 snprintf(buf, 30, "CHRGISN:%c%d mA", x, y);
1739 lcd_puts(0, line++, buf);
1741 y = cccv_regulator_dissipation();
1742 snprintf(buf, 30, "P CCCV : %d mW", y);
1743 lcd_puts(0, line++, buf);
1745 y = battery_charge_current();
1746 if (y < 0) x = '-', y = -y;
1747 else x = ' ';
1748 snprintf(buf, 30, "I Charge:%c%d mA", x, y);
1749 lcd_puts(0, line++, buf);
1751 y = battery_adc_temp();
1753 if (y != INT_MIN) {
1754 snprintf(buf, 30, "T Battery: %dC (%dF)", y,
1755 (9*y + 160) / 5);
1756 } else {
1757 /* Conversion disabled */
1758 snprintf(buf, 30, "T Battery: ?");
1761 lcd_puts(0, line++, buf);
1762 #elif defined(SANSA_E200) || defined(SANSA_C200) || defined(SANSA_CLIP)
1763 const int first = CHARGE_STATE_DISABLED;
1764 static const char * const chrgstate_strings[] =
1766 [CHARGE_STATE_DISABLED-first] = "Disabled",
1767 [CHARGE_STATE_ERROR-first] = "Error",
1768 [DISCHARGING-first] = "Discharging",
1769 [CHARGING-first] = "Charging",
1771 const char *str = NULL;
1773 snprintf(buf, 30, "Charger: %s",
1774 charger_inserted() ? "present" : "absent");
1775 lcd_puts(0, 3, buf);
1777 y = charge_state - first;
1778 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1779 str = chrgstate_strings[y];
1781 snprintf(buf, sizeof(buf), "State: %s",
1782 str ? str : "<unknown>");
1783 lcd_puts(0, 4, buf);
1785 snprintf(buf, sizeof(buf), "CHARGER: %02X",
1786 ascodec_read(AS3514_CHARGER));
1787 lcd_puts(0, 5, buf);
1788 #else
1789 snprintf(buf, 30, "Charger: %s",
1790 charger_inserted() ? "present" : "absent");
1791 lcd_puts(0, 3, buf);
1792 #endif /* target type */
1793 #endif /* CONFIG_CHARGING */
1794 break;
1796 case 2: /* voltage deltas: */
1797 lcd_puts(0, 0, "Voltage deltas:");
1799 for (i = 0; i <= 6; i++) {
1800 y = power_history[i] - power_history[i+1];
1801 snprintf(buf, 30, "-%d min: %s%d.%03d V", i,
1802 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 1000,
1803 ((y < 0) ? y * -1 : y ) % 1000);
1804 lcd_puts(0, i+1, buf);
1806 break;
1808 case 3: /* remaining time estimation: */
1810 #ifdef ARCHOS_RECORDER
1811 snprintf(buf, 30, "charge_state: %d", charge_state);
1812 lcd_puts(0, 0, buf);
1814 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1815 lcd_puts(0, 1, buf);
1817 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1818 lcd_puts(0, 2, buf);
1820 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1821 lcd_puts(0, 3, buf);
1823 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1824 lcd_puts(0, 4, buf);
1825 #endif /* ARCHOS_RECORDER */
1827 snprintf(buf, 30, "Last PwrHist: %d.%03dV",
1828 power_history[0] / 1000,
1829 power_history[0] % 1000);
1830 lcd_puts(0, 5, buf);
1832 snprintf(buf, 30, "battery level: %d%%", battery_level());
1833 lcd_puts(0, 6, buf);
1835 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1836 lcd_puts(0, 7, buf);
1837 break;
1840 lcd_update();
1842 switch(get_action(CONTEXT_STD,HZ/2))
1844 case ACTION_STD_PREV:
1845 if (view)
1846 view--;
1847 break;
1849 case ACTION_STD_NEXT:
1850 if (view < 3)
1851 view++;
1852 break;
1854 case ACTION_STD_CANCEL:
1855 lcd_setfont(FONT_UI);
1856 return false;
1859 lcd_setfont(FONT_UI);
1860 return false;
1863 #endif /* HAVE_LCD_BITMAP */
1864 #endif
1866 #ifndef SIMULATOR
1867 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1869 #if (CONFIG_STORAGE & STORAGE_MMC)
1870 #define CARDTYPE "MMC"
1871 #elif (CONFIG_STORAGE & STORAGE_SD)
1872 #define CARDTYPE "microSD"
1873 #endif
1875 static int disk_callback(int btn, struct gui_synclist *lists)
1877 tCardInfo *card;
1878 int *cardnum = (int*)lists->data;
1879 unsigned char card_name[7];
1880 unsigned char pbuf[32];
1881 char *title = lists->title;
1882 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1883 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1884 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1885 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1886 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1887 "3.1-3.31", "4.0" };
1888 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
1890 #ifdef HAVE_HOTSWAP
1891 if (btn == ACTION_STD_OK)
1893 *cardnum ^= 0x1; /* change cards */
1895 #endif
1897 simplelist_set_line_count(0);
1899 card = card_get_info(*cardnum);
1901 if (card->initialized > 0)
1903 card_name[6] = '\0';
1904 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1905 simplelist_addline(SIMPLELIST_ADD_LINE,
1906 "%s Rev %d.%d", card_name,
1907 (int) card_extract_bits(card->cid, 72, 4),
1908 (int) card_extract_bits(card->cid, 76, 4));
1909 simplelist_addline(SIMPLELIST_ADD_LINE,
1910 "Prod: %d/%d",
1911 (int) card_extract_bits(card->cid, 112, 4),
1912 (int) card_extract_bits(card->cid, 116, 4) + 1997);
1913 simplelist_addline(SIMPLELIST_ADD_LINE,
1914 "Ser#: 0x%08lx",
1915 card_extract_bits(card->cid, 80, 32));
1916 simplelist_addline(SIMPLELIST_ADD_LINE,
1917 "M=%02x, O=%04x",
1918 (int) card_extract_bits(card->cid, 0, 8),
1919 (int) card_extract_bits(card->cid, 8, 16));
1920 int temp = card_extract_bits(card->csd, 2, 4);
1921 simplelist_addline(SIMPLELIST_ADD_LINE,
1922 CARDTYPE " v%s", temp < 5 ?
1923 spec_vers[temp] : "?.?");
1924 simplelist_addline(SIMPLELIST_ADD_LINE,
1925 "Blocks: 0x%08lx", card->numblocks);
1926 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
1927 kbit_units, false);
1928 simplelist_addline(SIMPLELIST_ADD_LINE,
1929 "Speed: %s", pbuf);
1930 output_dyn_value(pbuf, sizeof pbuf, card->tsac,
1931 nsec_units, false);
1932 simplelist_addline(SIMPLELIST_ADD_LINE,
1933 "Tsac: %s", pbuf);
1934 simplelist_addline(SIMPLELIST_ADD_LINE,
1935 "Nsac: %d clk", card->nsac);
1936 simplelist_addline(SIMPLELIST_ADD_LINE,
1937 "R2W: *%d", card->r2w_factor);
1938 simplelist_addline(SIMPLELIST_ADD_LINE,
1939 "IRmax: %d..%d mA",
1940 i_vmin[card_extract_bits(card->csd, 66, 3)],
1941 i_vmax[card_extract_bits(card->csd, 69, 3)]);
1942 simplelist_addline(SIMPLELIST_ADD_LINE,
1943 "IWmax: %d..%d mA",
1944 i_vmin[card_extract_bits(card->csd, 72, 3)],
1945 i_vmax[card_extract_bits(card->csd, 75, 3)]);
1947 else if (card->initialized == 0)
1949 simplelist_addline(SIMPLELIST_ADD_LINE, "Not Found!");
1951 #if (CONFIG_STORAGE & STORAGE_SD)
1952 else /* card->initialized < 0 */
1954 simplelist_addline(SIMPLELIST_ADD_LINE, "Init Error! (%d)", card->initialized);
1956 #endif
1957 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1958 gui_synclist_set_title(lists, title, Icon_NOICON);
1959 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1960 gui_synclist_select_item(lists, 0);
1961 btn = ACTION_REDRAW;
1963 return btn;
1965 #elif (CONFIG_STORAGE & STORAGE_ATA)
1966 static int disk_callback(int btn, struct gui_synclist *lists)
1968 (void)lists;
1969 int i;
1970 char buf[128];
1971 unsigned short* identify_info = ata_get_identify();
1972 bool timing_info_present = false;
1973 (void)btn;
1975 simplelist_set_line_count(0);
1977 for (i=0; i < 20; i++)
1978 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1979 buf[40]=0;
1980 /* kill trailing space */
1981 for (i=39; i && buf[i]==' '; i--)
1982 buf[i] = 0;
1983 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", buf);
1984 for (i=0; i < 4; i++)
1985 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1986 buf[8]=0;
1987 simplelist_addline(SIMPLELIST_ADD_LINE,
1988 "Firmware: %s", buf);
1989 snprintf(buf, sizeof buf, "%ld MB",
1990 ((unsigned long)identify_info[61] << 16 |
1991 (unsigned long)identify_info[60]) / 2048 );
1992 simplelist_addline(SIMPLELIST_ADD_LINE,
1993 "Size: %s", buf);
1994 unsigned long free;
1995 fat_size( IF_MV2(0,) NULL, &free );
1996 simplelist_addline(SIMPLELIST_ADD_LINE,
1997 "Free: %ld MB", free / 1024);
1998 simplelist_addline(SIMPLELIST_ADD_LINE,
1999 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
2000 i = identify_info[83] & (1<<3);
2001 simplelist_addline(SIMPLELIST_ADD_LINE,
2002 "Power mgmt: %s", i ? "enabled" : "unsupported");
2003 i = identify_info[83] & (1<<9);
2004 simplelist_addline(SIMPLELIST_ADD_LINE,
2005 "Noise mgmt: %s", i ? "enabled" : "unsupported");
2006 i = identify_info[82] & (1<<6);
2007 simplelist_addline(SIMPLELIST_ADD_LINE,
2008 "Read-ahead: %s", i ? "enabled" : "unsupported");
2009 timing_info_present = identify_info[53] & (1<<1);
2010 if(timing_info_present) {
2011 char pio3[2], pio4[2];pio3[1] = 0;
2012 pio4[1] = 0;
2013 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
2014 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
2015 simplelist_addline(SIMPLELIST_ADD_LINE,
2016 "PIO modes: 0 1 2 %s %s", pio3, pio4);
2018 else {
2019 simplelist_addline(SIMPLELIST_ADD_LINE,
2020 "No PIO mode info");
2022 timing_info_present = identify_info[53] & (1<<1);
2023 if(timing_info_present) {
2024 simplelist_addline(SIMPLELIST_ADD_LINE,
2025 "Cycle times %dns/%dns",
2026 identify_info[67],
2027 identify_info[68] );
2028 } else {
2029 simplelist_addline(SIMPLELIST_ADD_LINE,
2030 "No timing info");
2032 #ifdef HAVE_ATA_DMA
2033 if (identify_info[63] & (1<<0)) {
2034 char mdma0[2], mdma1[2], mdma2[2];
2035 mdma0[1] = mdma1[1] = mdma2[1] = 0;
2036 mdma0[0] = (identify_info[63] & (1<<0)) ? '0' : 0;
2037 mdma1[0] = (identify_info[63] & (1<<1)) ? '1' : 0;
2038 mdma2[0] = (identify_info[63] & (1<<2)) ? '2' : 0;
2039 simplelist_addline(SIMPLELIST_ADD_LINE,
2040 "MDMA modes: %s %s %s", mdma0, mdma1, mdma2);
2041 simplelist_addline(SIMPLELIST_ADD_LINE,
2042 "MDMA Cycle times %dns/%dns",
2043 identify_info[65],
2044 identify_info[66] );
2046 else {
2047 simplelist_addline(SIMPLELIST_ADD_LINE,
2048 "No MDMA mode info");
2050 if (identify_info[53] & (1<<2)) {
2051 char udma0[2], udma1[2], udma2[2], udma3[2], udma4[2], udma5[2], udma6[2];
2052 udma0[1] = udma1[1] = udma2[1] = udma3[1] = udma4[1] = udma5[1] = udma6[1] = 0;
2053 udma0[0] = (identify_info[88] & (1<<0)) ? '0' : 0;
2054 udma1[0] = (identify_info[88] & (1<<1)) ? '1' : 0;
2055 udma2[0] = (identify_info[88] & (1<<2)) ? '2' : 0;
2056 udma3[0] = (identify_info[88] & (1<<3)) ? '3' : 0;
2057 udma4[0] = (identify_info[88] & (1<<4)) ? '4' : 0;
2058 udma5[0] = (identify_info[88] & (1<<5)) ? '5' : 0;
2059 udma6[0] = (identify_info[88] & (1<<6)) ? '6' : 0;
2060 simplelist_addline(SIMPLELIST_ADD_LINE,
2061 "UDMA modes: %s %s %s %s %s %s %s", udma0, udma1, udma2,
2062 udma3, udma4, udma5, udma6);
2064 else {
2065 simplelist_addline(SIMPLELIST_ADD_LINE,
2066 "No UDMA mode info");
2068 #endif /* HAVE_ATA_DMA */
2069 timing_info_present = identify_info[53] & (1<<1);
2070 if(timing_info_present) {
2071 i = identify_info[49] & (1<<11);
2072 simplelist_addline(SIMPLELIST_ADD_LINE,
2073 "IORDY support: %s", i ? "yes" : "no");
2074 i = identify_info[49] & (1<<10);
2075 simplelist_addline(SIMPLELIST_ADD_LINE,
2076 "IORDY disable: %s", i ? "yes" : "no");
2077 } else {
2078 simplelist_addline(SIMPLELIST_ADD_LINE,
2079 "No timing info");
2081 simplelist_addline(SIMPLELIST_ADD_LINE,
2082 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2083 #ifdef HAVE_ATA_DMA
2084 i = ata_get_dma_mode();
2085 if (i == 0) {
2086 simplelist_addline(SIMPLELIST_ADD_LINE,
2087 "DMA not enabled");
2088 } else {
2089 simplelist_addline(SIMPLELIST_ADD_LINE,
2090 "DMA mode: %s %c",
2091 (i & 0x40) ? "UDMA" : "MDMA",
2092 '0' + (i & 7));
2094 #endif /* HAVE_ATA_DMA */
2095 return btn;
2097 #else /* No SD, MMC or ATA */
2098 static int disk_callback(int btn, struct gui_synclist *lists)
2100 (void)btn;
2101 (void)lists;
2102 struct storage_info info;
2103 storage_get_info(0,&info);
2104 simplelist_addline(SIMPLELIST_ADD_LINE, "Vendor: %s", info.vendor);
2105 simplelist_addline(SIMPLELIST_ADD_LINE, "Model: %s", info.product);
2106 simplelist_addline(SIMPLELIST_ADD_LINE, "Firmware: %s", info.revision);
2107 simplelist_addline(SIMPLELIST_ADD_LINE,
2108 "Size: %ld MB", info.num_sectors*(info.sector_size/512)/2024);
2109 unsigned long free;
2110 fat_size( IF_MV2(0,) NULL, &free );
2111 simplelist_addline(SIMPLELIST_ADD_LINE,
2112 "Free: %ld MB", free / 1024);
2113 simplelist_addline(SIMPLELIST_ADD_LINE,
2114 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
2115 return btn;
2117 #endif
2119 #if (CONFIG_STORAGE & STORAGE_ATA)
2120 static bool dbg_identify_info(void)
2122 int fd = creat("/identify_info.bin");
2123 if(fd >= 0)
2125 #ifdef ROCKBOX_LITTLE_ENDIAN
2126 ecwrite(fd, ata_get_identify(), SECTOR_SIZE/2, "s", true);
2127 #else
2128 write(fd, ata_get_identify(), SECTOR_SIZE);
2129 #endif
2130 close(fd);
2132 return false;
2134 #endif
2136 static bool dbg_disk_info(void)
2138 struct simplelist_info info;
2139 simplelist_info_init(&info, "Disk Info", 1, NULL);
2140 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
2141 char title[16];
2142 int card = 0;
2143 info.callback_data = (void*)&card;
2144 info.title = title;
2145 #endif
2146 info.action_callback = disk_callback;
2147 info.hide_selection = true;
2148 info.scroll_all = true;
2149 return simplelist_show_list(&info);
2151 #endif /* !SIMULATOR */
2153 #ifdef HAVE_DIRCACHE
2154 static int dircache_callback(int btn, struct gui_synclist *lists)
2156 (void)btn; (void)lists;
2157 simplelist_set_line_count(0);
2158 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache initialized: %s",
2159 dircache_is_enabled() ? "Yes" : "No");
2160 simplelist_addline(SIMPLELIST_ADD_LINE, "Cache size: %d B",
2161 dircache_get_cache_size());
2162 simplelist_addline(SIMPLELIST_ADD_LINE, "Last size: %d B",
2163 global_status.dircache_size);
2164 simplelist_addline(SIMPLELIST_ADD_LINE, "Limit: %d B",
2165 DIRCACHE_LIMIT);
2166 simplelist_addline(SIMPLELIST_ADD_LINE, "Reserve: %d/%d B",
2167 dircache_get_reserve_used(), DIRCACHE_RESERVE);
2168 simplelist_addline(SIMPLELIST_ADD_LINE, "Scanning took: %d s",
2169 dircache_get_build_ticks() / HZ);
2170 simplelist_addline(SIMPLELIST_ADD_LINE, "Entry count: %d",
2171 dircache_get_entry_count());
2172 return btn;
2175 static bool dbg_dircache_info(void)
2177 struct simplelist_info info;
2178 simplelist_info_init(&info, "Dircache Info", 7, NULL);
2179 info.action_callback = dircache_callback;
2180 info.hide_selection = true;
2181 info.scroll_all = true;
2182 return simplelist_show_list(&info);
2185 #endif /* HAVE_DIRCACHE */
2187 #ifdef HAVE_TAGCACHE
2188 static int database_callback(int btn, struct gui_synclist *lists)
2190 (void)lists;
2191 struct tagcache_stat *stat = tagcache_get_stat();
2192 static bool synced = false;
2194 simplelist_set_line_count(0);
2196 simplelist_addline(SIMPLELIST_ADD_LINE, "Initialized: %s",
2197 stat->initialized ? "Yes" : "No");
2198 simplelist_addline(SIMPLELIST_ADD_LINE, "DB Ready: %s",
2199 stat->ready ? "Yes" : "No");
2200 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM Cache: %s",
2201 stat->ramcache ? "Yes" : "No");
2202 simplelist_addline(SIMPLELIST_ADD_LINE, "RAM: %d/%d B",
2203 stat->ramcache_used, stat->ramcache_allocated);
2204 simplelist_addline(SIMPLELIST_ADD_LINE, "Progress: %d%% (%d entries)",
2205 stat->progress, stat->processed_entries);
2206 simplelist_addline(SIMPLELIST_ADD_LINE, "Curfile: %s",
2207 stat->curentry ? stat->curentry : "---");
2208 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit step: %d",
2209 stat->commit_step);
2210 simplelist_addline(SIMPLELIST_ADD_LINE, "Commit delayed: %s",
2211 stat->commit_delayed ? "Yes" : "No");
2213 simplelist_addline(SIMPLELIST_ADD_LINE, "Queue length: %d",
2214 stat->queue_length);
2216 if (synced)
2218 synced = false;
2219 tagcache_screensync_event();
2222 if (!btn && stat->curentry)
2224 synced = true;
2225 return ACTION_REDRAW;
2228 if (btn == ACTION_STD_CANCEL)
2229 tagcache_screensync_enable(false);
2231 return btn;
2233 static bool dbg_tagcache_info(void)
2235 struct simplelist_info info;
2236 simplelist_info_init(&info, "Database Info", 8, NULL);
2237 info.action_callback = database_callback;
2238 info.hide_selection = true;
2239 info.scroll_all = true;
2241 /* Don't do nonblock here, must give enough processing time
2242 for tagcache thread. */
2243 /* info.timeout = TIMEOUT_NOBLOCK; */
2244 info.timeout = 1;
2245 tagcache_screensync_enable(true);
2246 return simplelist_show_list(&info);
2248 #endif
2250 #if CONFIG_CPU == SH7034
2251 static bool dbg_save_roms(void)
2253 int fd;
2254 int oldmode = system_memory_guard(MEMGUARD_NONE);
2256 fd = creat("/internal_rom_0000-FFFF.bin");
2257 if(fd >= 0)
2259 write(fd, (void *)0, 0x10000);
2260 close(fd);
2263 fd = creat("/internal_rom_2000000-203FFFF.bin");
2264 if(fd >= 0)
2266 write(fd, (void *)0x2000000, 0x40000);
2267 close(fd);
2270 system_memory_guard(oldmode);
2271 return false;
2273 #elif defined CPU_COLDFIRE
2274 static bool dbg_save_roms(void)
2276 int fd;
2277 int oldmode = system_memory_guard(MEMGUARD_NONE);
2279 #if defined(IRIVER_H100_SERIES)
2280 fd = creat("/internal_rom_000000-1FFFFF.bin");
2281 #elif defined(IRIVER_H300_SERIES)
2282 fd = creat("/internal_rom_000000-3FFFFF.bin");
2283 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
2284 fd = creat("/internal_rom_000000-3FFFFF.bin");
2285 #endif
2286 if(fd >= 0)
2288 write(fd, (void *)0, FLASH_SIZE);
2289 close(fd);
2291 system_memory_guard(oldmode);
2293 #ifdef HAVE_EEPROM
2294 fd = creat("/internal_eeprom.bin");
2295 if (fd >= 0)
2297 int old_irq_level;
2298 char buf[EEPROM_SIZE];
2299 int err;
2301 old_irq_level = disable_irq_save();
2303 err = eeprom_24cxx_read(0, buf, sizeof buf);
2305 restore_irq(old_irq_level);
2307 if (err)
2308 splashf(HZ*3, "Eeprom read failure (%d)", err);
2309 else
2311 write(fd, buf, sizeof buf);
2314 close(fd);
2316 #endif
2318 return false;
2320 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
2321 static bool dbg_save_roms(void)
2323 int fd;
2325 fd = creat("/internal_rom_000000-0FFFFF.bin");
2326 if(fd >= 0)
2328 write(fd, (void *)0x20000000, FLASH_SIZE);
2329 close(fd);
2332 return false;
2334 #endif /* CPU */
2336 #ifndef SIMULATOR
2337 #if CONFIG_TUNER
2338 static int radio_callback(int btn, struct gui_synclist *lists)
2340 (void)lists;
2341 if (btn == ACTION_STD_CANCEL)
2342 return btn;
2343 simplelist_set_line_count(1);
2345 #if (CONFIG_TUNER & LV24020LP)
2346 simplelist_addline(SIMPLELIST_ADD_LINE,
2347 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT) );
2348 simplelist_addline(SIMPLELIST_ADD_LINE,
2349 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT) );
2350 simplelist_addline(SIMPLELIST_ADD_LINE,
2351 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM) );
2352 simplelist_addline(SIMPLELIST_ADD_LINE,
2353 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF) );
2354 simplelist_addline(SIMPLELIST_ADD_LINE,
2355 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD) );
2356 simplelist_addline(SIMPLELIST_ADD_LINE,
2357 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET) );
2358 simplelist_addline(SIMPLELIST_ADD_LINE,
2359 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET) );
2360 #endif /* LV24020LP */
2361 #if (CONFIG_TUNER & S1A0903X01)
2362 simplelist_addline(SIMPLELIST_ADD_LINE,
2363 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL));
2364 /* This one doesn't return dynamic data atm */
2365 #endif /* S1A0903X01 */
2366 #if (CONFIG_TUNER & TEA5767)
2367 struct tea5767_dbg_info nfo;
2368 tea5767_dbg_info(&nfo);
2369 simplelist_addline(SIMPLELIST_ADD_LINE, "Philips regs:");
2370 simplelist_addline(SIMPLELIST_ADD_LINE,
2371 " Read: %02X %02X %02X %02X %02X",
2372 (unsigned)nfo.read_regs[0], (unsigned)nfo.read_regs[1],
2373 (unsigned)nfo.read_regs[2], (unsigned)nfo.read_regs[3],
2374 (unsigned)nfo.read_regs[4]);
2375 simplelist_addline(SIMPLELIST_ADD_LINE,
2376 " Write: %02X %02X %02X %02X %02X",
2377 (unsigned)nfo.write_regs[0], (unsigned)nfo.write_regs[1],
2378 (unsigned)nfo.write_regs[2], (unsigned)nfo.write_regs[3],
2379 (unsigned)nfo.write_regs[4]);
2380 #endif /* TEA5767 */
2381 #if (CONFIG_TUNER & SI4700)
2382 struct si4700_dbg_info nfo;
2383 si4700_dbg_info(&nfo);
2384 simplelist_addline(SIMPLELIST_ADD_LINE, "SI4700 regs:");
2385 /* Registers */
2386 simplelist_addline(SIMPLELIST_ADD_LINE,
2387 "%04X %04X %04X %04X",
2388 (unsigned)nfo.regs[0], (unsigned)nfo.regs[1],
2389 (unsigned)nfo.regs[2], (unsigned)nfo.regs[3]);
2390 simplelist_addline(SIMPLELIST_ADD_LINE,
2391 "%04X %04X %04X %04X",
2392 (unsigned)nfo.regs[4], (unsigned)nfo.regs[5],
2393 (unsigned)nfo.regs[6], (unsigned)nfo.regs[7]);
2394 simplelist_addline(SIMPLELIST_ADD_LINE,
2395 "%04X %04X %04X %04X",
2396 (unsigned)nfo.regs[8], (unsigned)nfo.regs[9],
2397 (unsigned)nfo.regs[10], (unsigned)nfo.regs[11]);
2398 simplelist_addline(SIMPLELIST_ADD_LINE,
2399 "%04X %04X %04X %04X",
2400 (unsigned)nfo.regs[12], (unsigned)nfo.regs[13],
2401 (unsigned)nfo.regs[14], (unsigned)nfo.regs[15]);
2402 #endif /* SI4700 */
2403 return ACTION_REDRAW;
2405 static bool dbg_fm_radio(void)
2407 struct simplelist_info info;
2408 info.scroll_all = true;
2409 simplelist_info_init(&info, "FM Radio", 1, NULL);
2410 simplelist_set_line_count(0);
2411 simplelist_addline(SIMPLELIST_ADD_LINE, "HW detected: %s",
2412 radio_hardware_present() ? "yes" : "no");
2414 info.action_callback = radio_hardware_present()?radio_callback : NULL;
2415 info.hide_selection = true;
2416 return simplelist_show_list(&info);
2418 #endif /* CONFIG_TUNER */
2419 #endif /* !SIMULATOR */
2421 #ifdef HAVE_LCD_BITMAP
2422 extern bool do_screendump_instead_of_usb;
2424 static bool dbg_screendump(void)
2426 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2427 splashf(HZ, "Screendump %s",
2428 do_screendump_instead_of_usb?"enabled":"disabled");
2429 return false;
2431 #endif /* HAVE_LCD_BITMAP */
2433 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2434 static bool dbg_set_memory_guard(void)
2436 static const struct opt_items names[MAXMEMGUARD] = {
2437 { "None", -1 },
2438 { "Flash ROM writes", -1 },
2439 { "Zero area (all)", -1 }
2441 int mode = system_memory_guard(MEMGUARD_KEEP);
2443 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2444 system_memory_guard(mode);
2446 return false;
2448 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2450 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2451 static bool dbg_write_eeprom(void)
2453 int fd;
2454 int rc;
2455 int old_irq_level;
2456 char buf[EEPROM_SIZE];
2457 int err;
2459 fd = open("/internal_eeprom.bin", O_RDONLY);
2461 if (fd >= 0)
2463 rc = read(fd, buf, EEPROM_SIZE);
2465 if(rc == EEPROM_SIZE)
2467 old_irq_level = disable_irq_save();
2469 err = eeprom_24cxx_write(0, buf, sizeof buf);
2470 if (err)
2471 splashf(HZ*3, "Eeprom write failure (%d)", err);
2472 else
2473 splash(HZ*3, "Eeprom written successfully");
2475 restore_irq(old_irq_level);
2477 else
2479 splashf(HZ*3, "File read error (%d)",rc);
2481 close(fd);
2483 else
2485 splash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2488 return false;
2490 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2491 #ifdef CPU_BOOST_LOGGING
2492 static bool cpu_boost_log(void)
2494 int i = 0,j=0;
2495 int count = cpu_boost_log_getcount();
2496 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2497 char *str;
2498 bool done;
2499 lcd_setfont(FONT_SYSFIXED);
2500 str = cpu_boost_log_getlog_first();
2501 while (i < count)
2503 lcd_clear_display();
2504 for(j=0; j<lines; j++,i++)
2506 if (!str)
2507 str = cpu_boost_log_getlog_next();
2508 if (str)
2510 lcd_puts(0, j,str);
2512 str = NULL;
2514 lcd_update();
2515 done = false;
2516 while (!done)
2518 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2520 case ACTION_STD_OK:
2521 case ACTION_STD_PREV:
2522 case ACTION_STD_NEXT:
2523 done = true;
2524 break;
2525 case ACTION_STD_CANCEL:
2526 i = count;
2527 done = true;
2528 break;
2532 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2533 lcd_setfont(FONT_UI);
2534 return false;
2536 #endif
2538 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2539 extern bool wheel_is_touched;
2540 extern int old_wheel_value;
2541 extern int new_wheel_value;
2542 extern int wheel_delta;
2543 extern unsigned int accumulated_wheel_delta;
2544 extern unsigned int wheel_velocity;
2546 static bool dbg_scrollwheel(void)
2548 char buf[64];
2549 unsigned int speed;
2551 lcd_setfont(FONT_SYSFIXED);
2553 while (1)
2555 if (action_userabort(HZ/10))
2556 break;
2558 lcd_clear_display();
2560 /* show internal variables of scrollwheel driver */
2561 snprintf(buf, sizeof(buf), "wheel touched: %s", (wheel_is_touched) ? "true" : "false");
2562 lcd_puts(0, 0, buf);
2563 snprintf(buf, sizeof(buf), "new position: %2d", new_wheel_value);
2564 lcd_puts(0, 1, buf);
2565 snprintf(buf, sizeof(buf), "old position: %2d", old_wheel_value);
2566 lcd_puts(0, 2, buf);
2567 snprintf(buf, sizeof(buf), "wheel delta: %2d", wheel_delta);
2568 lcd_puts(0, 3, buf);
2569 snprintf(buf, sizeof(buf), "accumulated delta: %2d", accumulated_wheel_delta);
2570 lcd_puts(0, 4, buf);
2571 snprintf(buf, sizeof(buf), "velo [deg/s]: %4d", (int)wheel_velocity);
2572 lcd_puts(0, 5, buf);
2574 /* show effective accelerated scrollspeed */
2575 speed = button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity);
2576 snprintf(buf, sizeof(buf), "accel. speed: %4d", speed);
2577 lcd_puts(0, 6, buf);
2579 lcd_update();
2581 lcd_setfont(FONT_UI);
2582 return false;
2584 #endif
2586 #if defined (HAVE_USBSTACK) \
2587 && (defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL) || defined(USB_HID))
2588 static bool toggle_usb_core_driver(int driver, char *msg)
2590 bool enabled = !usb_core_driver_enabled(driver);
2592 usb_core_enable_driver(driver,enabled);
2593 splashf(HZ, "%s %s", msg, enabled?"enabled":"disabled");
2595 return false;
2597 #if 0 && defined(USB_STORAGE)
2598 static bool toggle_usb_mass_storage(void)
2600 return toggle_usb_core_driver(USB_DRIVER_MASS_STORAGE,"USB Mass Storage");
2602 #endif
2604 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2605 static bool toggle_usb_serial(void)
2607 return toggle_usb_core_driver(USB_DRIVER_SERIAL,"USB Serial");
2609 #endif
2611 #if defined(USB_HID)
2612 static bool toggle_usb_hid(void)
2614 return toggle_usb_core_driver(USB_DRIVER_HID, "USB HID");
2616 #endif
2617 #endif
2619 #if CONFIG_USBOTG == USBOTG_ISP1583
2620 extern int dbg_usb_num_items(void);
2621 extern char* dbg_usb_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2623 static int isp1583_action_callback(int action, struct gui_synclist *lists)
2625 (void)lists;
2626 if (action == ACTION_NONE)
2627 action = ACTION_REDRAW;
2628 return action;
2631 static bool dbg_isp1583(void)
2633 struct simplelist_info isp1583;
2634 isp1583.scroll_all = true;
2635 simplelist_info_init(&isp1583, "ISP1583", dbg_usb_num_items(), NULL);
2636 isp1583.timeout = HZ/100;
2637 isp1583.hide_selection = true;
2638 isp1583.get_name = dbg_usb_item;
2639 isp1583.action_callback = isp1583_action_callback;
2640 return simplelist_show_list(&isp1583);
2642 #endif
2644 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2645 extern int pic_dbg_num_items(void);
2646 extern char* pic_dbg_item(int selected_item, void *data, char *buffer, size_t buffer_len);
2648 static int pic_action_callback(int action, struct gui_synclist *lists)
2650 (void)lists;
2651 if (action == ACTION_NONE)
2652 action = ACTION_REDRAW;
2653 return action;
2656 static bool dbg_pic(void)
2658 struct simplelist_info pic;
2659 pic.scroll_all = true;
2660 simplelist_info_init(&pic, "PIC", pic_dbg_num_items(), NULL);
2661 pic.timeout = HZ/100;
2662 pic.hide_selection = true;
2663 pic.get_name = pic_dbg_item;
2664 pic.action_callback = pic_action_callback;
2665 return simplelist_show_list(&pic);
2667 #endif
2670 /****** The menu *********/
2671 struct the_menu_item {
2672 unsigned char *desc; /* string or ID */
2673 bool (*function) (void); /* return true if USB was connected */
2675 static const struct the_menu_item menuitems[] = {
2676 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2677 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD))
2678 { "Dump ROM contents", dbg_save_roms },
2679 #endif
2680 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2681 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 \
2682 || CONFIG_CPU == DM320
2683 { "View I/O ports", dbg_ports },
2684 #endif
2685 #if (CONFIG_RTC == RTC_PCF50605) && !defined(SIMULATOR)
2686 { "View PCF registers", dbg_pcf },
2687 #endif
2688 #if defined(HAVE_TSC2100) && !defined(SIMULATOR)
2689 { "TSC2100 debug", tsc2100_debug },
2690 #endif
2691 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2692 { "CPU frequency", dbg_cpufreq },
2693 #endif
2694 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2695 { "S/PDIF analyzer", dbg_spdif },
2696 #endif
2697 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2698 { "Catch mem accesses", dbg_set_memory_guard },
2699 #endif
2700 { "View OS stacks", dbg_os },
2701 #ifdef HAVE_LCD_BITMAP
2702 #ifndef SIMULATOR
2703 { "View battery", view_battery },
2704 #endif
2705 { "Screendump", dbg_screendump },
2706 #endif
2707 #ifndef SIMULATOR
2708 { "View HW info", dbg_hw_info },
2709 #endif
2710 #ifndef SIMULATOR
2711 { "View partitions", dbg_partitions },
2712 #endif
2713 #ifndef SIMULATOR
2714 { "View disk info", dbg_disk_info },
2715 #if (CONFIG_STORAGE & STORAGE_ATA)
2716 { "Dump ATA identify info", dbg_identify_info},
2717 #endif
2718 #endif
2719 #ifdef HAVE_DIRCACHE
2720 { "View dircache info", dbg_dircache_info },
2721 #endif
2722 #ifdef HAVE_TAGCACHE
2723 { "View database info", dbg_tagcache_info },
2724 #endif
2725 #ifdef HAVE_LCD_BITMAP
2726 #if CONFIG_CODEC == SWCODEC
2727 { "View buffering thread", dbg_buffering_thread },
2728 #elif !defined(SIMULATOR)
2729 { "View audio thread", dbg_audio_thread },
2730 #endif
2731 #ifdef PM_DEBUG
2732 { "pm histogram", peak_meter_histogram},
2733 #endif /* PM_DEBUG */
2734 #endif /* HAVE_LCD_BITMAP */
2735 #ifndef SIMULATOR
2736 #if CONFIG_TUNER
2737 { "FM Radio", dbg_fm_radio },
2738 #endif
2739 #endif
2740 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2741 { "Write back EEPROM", dbg_write_eeprom },
2742 #endif
2743 #if CONFIG_USBOTG == USBOTG_ISP1583
2744 { "View ISP1583 info", dbg_isp1583 },
2745 #endif
2746 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2747 { "View PIC info", dbg_pic },
2748 #endif
2749 #ifdef ROCKBOX_HAS_LOGF
2750 {"logf", logfdisplay },
2751 {"logfdump", logfdump },
2752 #endif
2753 #if defined(HAVE_USBSTACK)
2754 #if 0 && defined(USB_STORAGE)
2755 {"USB Mass-Storage driver", toggle_usb_mass_storage },
2756 #endif
2757 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL)
2758 {"USB Serial driver (logf)", toggle_usb_serial },
2759 #endif
2760 #if defined(USB_HID)
2761 {"USB HID driver", toggle_usb_hid },
2762 #endif
2763 #endif /* HAVE_USBSTACK */
2764 #ifdef CPU_BOOST_LOGGING
2765 {"cpu_boost log",cpu_boost_log},
2766 #endif
2767 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) && !defined(SIMULATOR))
2768 {"Debug scrollwheel", dbg_scrollwheel },
2769 #endif
2771 static int menu_action_callback(int btn, struct gui_synclist *lists)
2773 if (btn == ACTION_STD_OK)
2775 int oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL);
2776 menuitems[gui_synclist_get_sel_pos(lists)].function();
2777 btn = ACTION_REDRAW;
2778 viewportmanager_set_statusbar(oldbars);
2780 return btn;
2782 static char* dbg_menu_getname(int item, void * data,
2783 char *buffer, size_t buffer_len)
2785 (void)data; (void)buffer; (void)buffer_len;
2786 return menuitems[item].desc;
2788 bool debug_menu(void)
2790 struct simplelist_info info;
2792 simplelist_info_init(&info, "Debug Menu", ARRAYLEN(menuitems), NULL);
2793 info.action_callback = menu_action_callback;
2794 info.get_name = dbg_menu_getname;
2795 return simplelist_show_list(&info);