Unify the way functions are called from menus.
[Rockbox.git] / apps / debug_menu.c
blob2b0381fef5f8fd6868d09be2fa13335b9d8c40aa
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Heikki Hannikainen
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "config.h"
21 #include <stdio.h>
22 #include <stdbool.h>
23 #include <string.h>
24 #include "lcd.h"
25 #include "menu.h"
26 #include "debug_menu.h"
27 #include "kernel.h"
28 #include "sprintf.h"
29 #include "action.h"
30 #include "debug.h"
31 #include "thread.h"
32 #include "powermgmt.h"
33 #include "system.h"
34 #include "font.h"
35 #include "audio.h"
36 #include "mp3_playback.h"
37 #include "settings.h"
38 #include "dir.h"
39 #include "panic.h"
40 #include "screens.h"
41 #include "misc.h"
42 #include "splash.h"
43 #include "dircache.h"
44 #ifdef HAVE_TAGCACHE
45 #include "tagcache.h"
46 #endif
47 #include "lcd-remote.h"
48 #include "crc32.h"
49 #include "logf.h"
50 #ifndef SIMULATOR
51 #include "disk.h"
52 #include "adc.h"
53 #include "power.h"
54 #include "usb.h"
55 #include "rtc.h"
56 #include "ata.h"
57 #include "fat.h"
58 #include "mas.h"
59 #include "eeprom_24cxx.h"
60 #ifdef HAVE_MMC
61 #include "ata_mmc.h"
62 #endif
63 #if CONFIG_TUNER
64 #include "tuner.h"
65 #include "radio.h"
66 #endif
67 #endif
69 #ifdef HAVE_LCD_BITMAP
70 #include "scrollbar.h"
71 #include "peakmeter.h"
72 #endif
73 #include "logfdisp.h"
74 #if CONFIG_CODEC == SWCODEC
75 #include "pcmbuf.h"
76 #include "pcm_playback.h"
77 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
78 #include "spdif.h"
79 #endif
80 #endif
81 #ifdef IRIVER_H300_SERIES
82 #include "pcf50606.h" /* for pcf50606_read */
83 #endif
84 #ifdef IAUDIO_X5
85 #include "ds2411.h"
86 #endif
88 /*---------------------------------------------------*/
89 /* SPECIAL DEBUG STUFF */
90 /*---------------------------------------------------*/
91 extern int ata_device;
92 extern int ata_io_address;
93 extern struct core_entry cores[NUM_CORES];
95 #ifndef SIMULATOR
96 #ifdef HAVE_LCD_BITMAP
97 static char thread_status_char(int status)
99 switch (status)
101 case STATE_RUNNING : return 'R';
102 case STATE_BLOCKED : return 'B';
103 case STATE_SLEEPING : return 'S';
104 case STATE_BLOCKED_W_TMO: return 'T';
107 return '?';
110 /* Test code!!! */
111 static bool dbg_os(void)
113 struct thread_entry *thread;
114 char buf[32];
115 int i;
116 int usage;
117 int status;
118 #if NUM_CORES > 1
119 unsigned int core;
120 int line;
121 #endif
123 lcd_setmargins(0, 0);
124 lcd_setfont(FONT_SYSFIXED);
125 lcd_clear_display();
127 while(1)
129 #if 0 /* Enable to simulate UI lag. */
130 int _x;
131 for (_x = 0; _x < 1000000L; _x++) ;
132 #endif
133 #if NUM_CORES > 1
134 lcd_puts(0, 0, "Core and stack usage:");
135 line = 0;
136 for(core = 0; core < NUM_CORES; core++)
138 for(i = 0; i < MAXTHREADS; i++)
140 thread = &cores[core].threads[i];
141 if (thread->name == NULL)
142 continue;
144 usage = thread_stack_usage(thread);
145 status = thread_get_status(thread);
147 # ifdef HAVE_PRIORITY_SCHEDULING
148 snprintf(buf, 32, "(%d) %c%c %d %s: %d%%", core,
149 (status == STATE_RUNNING) ? '*' : ' ',
150 thread_status_char(status),
151 cores[CURRENT_CORE].threads[i].priority,
152 cores[core].threads[i].name, usage);
153 # else
154 snprintf(buf, 32, "(%d) %c%c %s: %d%%", core,
155 (status == STATE_RUNNING) ? '*' : ' ',
156 thread_status_char(status),
157 cores[core].threads[i].name, usage);
158 # endif
159 lcd_puts(0, ++line, buf);
162 #else
163 lcd_puts(0, 0, "Stack usage:");
164 for(i = 0; i < MAXTHREADS; i++)
166 thread = &cores[CURRENT_CORE].threads[i];
167 if (thread->name == NULL)
168 continue;
170 usage = thread_stack_usage(thread);
171 status = thread_get_status(thread);
172 # ifdef HAVE_PRIORITY_SCHEDULING
173 snprintf(buf, 32, "%c%c %d %s: %d%%",
174 (status == STATE_RUNNING) ? '*' : ' ',
175 thread_status_char(status),
176 cores[CURRENT_CORE].threads[i].priority,
177 cores[CURRENT_CORE].threads[i].name, usage);
178 # else
179 snprintf(buf, 32, "%c%c %s: %d%%",
180 (status == STATE_RUNNING) ? '*' : ' ',
181 thread_status_char(status),
182 cores[CURRENT_CORE].threads[i].name, usage);
183 # endif
184 lcd_puts(0, 1+i, buf);
186 #endif
188 lcd_update();
190 if (action_userabort(HZ/10))
191 return false;
193 return false;
195 #else /* !HAVE_LCD_BITMAP */
196 static bool dbg_os(void)
198 char buf[32];
199 int button;
200 int usage;
201 int currval = 0;
203 lcd_clear_display();
205 while(1)
207 lcd_puts(0, 0, "Stack usage");
209 /* Only Archos Player uses this - so assume a single core */
210 usage = thread_stack_usage(&cores[CPU].threads[currval]);
211 snprintf(buf, 32, "%d: %d%% ", currval, usage);
212 lcd_puts(0, 1, buf);
214 button = get_action(CONTEXT_SETTINGS,HZ/10);
216 switch(button)
218 case ACTION_STD_CANCEL:
219 action_signalscreenchange();
220 return false;
222 case ACTION_SETTINGS_DEC:
223 currval--;
224 if(currval < 0)
225 currval = MAXTHREADS-1;
226 break;
228 case ACTION_SETTINGS_INC:
229 currval++;
230 if(currval > MAXTHREADS-1)
231 currval = 0;
232 break;
235 return false;
237 #endif /* !HAVE_LCD_BITMAP */
238 #endif /* !SIMULATOR */
239 #ifdef HAVE_LCD_BITMAP
240 #if CONFIG_CODEC != SWCODEC
241 #ifndef SIMULATOR
242 static bool dbg_audio_thread(void)
244 char buf[32];
245 struct audio_debug d;
247 lcd_setmargins(0, 0);
248 lcd_setfont(FONT_SYSFIXED);
250 while(1)
252 if (action_userabort(HZ/5))
253 return false;
255 audio_get_debugdata(&d);
257 lcd_clear_display();
259 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
260 lcd_puts(0, 0, buf);
261 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
262 lcd_puts(0, 1, buf);
263 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
264 lcd_puts(0, 2, buf);
265 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
266 lcd_puts(0, 3, buf);
267 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
268 lcd_puts(0, 4, buf);
269 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
270 lcd_puts(0, 5, buf);
272 /* Playable space left */
273 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
274 d.playable_space, HORIZONTAL);
276 /* Show the watermark limit */
277 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
278 d.low_watermark_level, HORIZONTAL);
280 snprintf(buf, sizeof(buf), "wm: %x - %x",
281 d.low_watermark_level, d.lowest_watermark_level);
282 lcd_puts(0, 7, buf);
284 lcd_update();
286 return false;
288 #endif /* !SIMULATOR */
289 #else /* CONFIG_CODEC == SWCODEC */
290 extern size_t filebuflen;
291 /* This is a size_t, but call it a long so it puts a - when it's bad. */
293 static unsigned int ticks, boost_ticks;
295 static void dbg_audio_task(void)
297 #ifndef SIMULATOR
298 if(FREQ > CPUFREQ_NORMAL)
299 boost_ticks++;
300 #endif
302 ticks++;
305 static bool dbg_audio_thread(void)
307 char buf[32];
308 int button;
309 int line;
310 bool done = false;
311 size_t bufused;
312 size_t bufsize = pcmbuf_get_bufsize();
313 int pcmbufdescs = pcmbuf_descs();
315 ticks = boost_ticks = 0;
317 tick_add_task(dbg_audio_task);
319 lcd_setmargins(0, 0);
320 lcd_setfont(FONT_SYSFIXED);
321 while(!done)
323 button = get_action(CONTEXT_STD,HZ/5);
324 switch(button)
326 case ACTION_STD_NEXT:
327 audio_next();
328 break;
329 case ACTION_STD_PREV:
330 audio_prev();
331 break;
332 case ACTION_STD_CANCEL:
333 done = true;
334 break;
336 action_signalscreenchange();
337 line = 0;
339 lcd_clear_display();
341 bufused = bufsize - pcmbuf_free();
343 snprintf(buf, sizeof(buf), "pcm: %7ld/%7ld", (long) bufused, (long) bufsize);
344 lcd_puts(0, line++, buf);
346 /* Playable space left */
347 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6, bufsize, 0, bufused, HORIZONTAL);
348 line++;
350 snprintf(buf, sizeof(buf), "codec: %8ld/%8ld", audio_filebufused(), (long) filebuflen);
351 lcd_puts(0, line++, buf);
353 /* Playable space left */
354 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6, filebuflen, 0,
355 audio_filebufused(), HORIZONTAL);
356 line++;
358 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
359 lcd_puts(0, line++, buf);
361 #ifndef SIMULATOR
362 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
363 (int)((FREQ + 500000) / 1000000));
364 lcd_puts(0, line++, buf);
365 #endif
367 snprintf(buf, sizeof(buf), "boost ratio: %3d%%",
368 boost_ticks * 100 / ticks);
369 lcd_puts(0, line++, buf);
371 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
372 pcmbuf_used_descs(), pcmbufdescs);
373 lcd_puts(0, line++, buf);
375 lcd_update();
378 tick_remove_task(dbg_audio_task);
380 return false;
382 #endif /* CONFIG_CODEC */
383 #endif /* HAVE_LCD_BITMAP */
386 #if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)) && !defined(SIMULATOR)
387 /* Tool function to read the flash manufacturer and type, if available.
388 Only chips which could be reprogrammed in system will return values.
389 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
390 /* In IRAM to avoid problems when running directly from Flash */
391 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
392 unsigned addr1, unsigned addr2)
393 ICODE_ATTR __attribute__((noinline));
394 static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
395 unsigned addr1, unsigned addr2)
398 unsigned not_manu, not_id; /* read values before switching to ID mode */
399 unsigned manu, id; /* read values when in ID mode */
401 #if CONFIG_CPU == SH7034
402 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
403 #elif defined(CPU_COLDFIRE)
404 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
405 #endif
406 int old_level; /* saved interrupt level */
408 not_manu = flash[0]; /* read the normal content */
409 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
411 /* disable interrupts, prevent any stray flash access */
412 old_level = set_irq_level(HIGHEST_IRQ_LEVEL);
414 flash[addr1] = 0xAA; /* enter command mode */
415 flash[addr2] = 0x55;
416 flash[addr1] = 0x90; /* ID command */
417 /* Atmel wants 20ms pause here */
418 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
420 manu = flash[0]; /* read the IDs */
421 id = flash[1];
423 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
424 /* Atmel wants 20ms pause here */
425 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
427 set_irq_level(old_level); /* enable interrupts again */
429 /* I assume success if the obtained values are different from
430 the normal flash content. This is not perfectly bulletproof, they
431 could theoretically be the same by chance, causing us to fail. */
432 if (not_manu != manu || not_id != id) /* a value has changed */
434 *p_manufacturer = manu; /* return the results */
435 *p_device = id;
436 return true; /* success */
438 return false; /* fail */
440 #endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) && !SIMULATOR */
442 #ifndef SIMULATOR
443 #ifdef HAVE_LCD_BITMAP
444 static bool dbg_hw_info(void)
446 #if CONFIG_CPU == SH7034
447 char buf[32];
448 int usb_polarity;
449 int pr_polarity;
450 int bitmask = *(unsigned short*)0x20000fc;
451 int rom_version = *(unsigned short*)0x20000fe;
452 unsigned manu, id; /* flash IDs */
453 bool got_id; /* flag if we managed to get the flash IDs */
454 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
455 bool has_bootrom; /* flag for boot ROM present */
456 int oldmode; /* saved memory guard mode */
458 #ifdef USB_ENABLE_ONDIOSTYLE
459 if(PADRL & 0x20)
460 #else
461 if(PADRH & 0x04)
462 #endif
463 usb_polarity = 0; /* Negative */
464 else
465 usb_polarity = 1; /* Positive */
467 if(PADRH & 0x08)
468 pr_polarity = 0; /* Negative */
469 else
470 pr_polarity = 1; /* Positive */
472 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
474 /* get flash ROM type */
475 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
476 if (!got_id)
477 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
479 /* check if the boot ROM area is a flash mirror */
480 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
481 if (has_bootrom) /* if ROM and Flash different */
483 /* calculate CRC16 checksum of boot ROM */
484 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
487 system_memory_guard(oldmode); /* re-enable memory guard */
489 lcd_setmargins(0, 0);
490 lcd_setfont(FONT_SYSFIXED);
491 lcd_clear_display();
493 lcd_puts(0, 0, "[Hardware info]");
495 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
496 lcd_puts(0, 1, buf);
498 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
499 lcd_puts(0, 2, buf);
501 snprintf(buf, 32, "USB: %s", usb_polarity?"positive":"negative");
502 lcd_puts(0, 3, buf);
504 snprintf(buf, 32, "PR: %s", pr_polarity?"positive":"negative");
505 lcd_puts(0, 4, buf);
507 if (got_id)
508 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
509 else
510 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
511 lcd_puts(0, 5, buf);
513 if (has_bootrom)
515 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
516 snprintf(buf, 32, "Boot ROM: V1");
517 else
518 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
520 else
522 snprintf(buf, 32, "Boot ROM: none");
524 lcd_puts(0, 6, buf);
526 #ifndef HAVE_MMC /* have ATA */
527 snprintf(buf, 32, "ATA: 0x%x,%s", ata_io_address,
528 ata_device ? "slave":"master");
529 lcd_puts(0, 7, buf);
530 #endif
531 lcd_update();
533 while(1)
535 if (action_userabort(TIMEOUT_BLOCK))
536 return false;
538 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
539 char buf[32];
540 unsigned manu, id; /* flash IDs */
541 int got_id; /* flag if we managed to get the flash IDs */
542 int oldmode; /* saved memory guard mode */
543 int line = 0;
545 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
547 /* get flash ROM type */
548 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
549 if (!got_id)
550 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
552 system_memory_guard(oldmode); /* re-enable memory guard */
554 lcd_setmargins(0, 0);
555 lcd_setfont(FONT_SYSFIXED);
556 lcd_clear_display();
558 lcd_puts(0, line++, "[Hardware info]");
560 if (got_id)
561 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
562 else
563 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
564 lcd_puts(0, line++, buf);
566 #ifdef IAUDIO_X5
568 struct ds2411_id id;
570 lcd_puts(0, ++line, "Serial Number:");
572 got_id = ds2411_read_id(&id);
574 if (got_id == DS2411_OK)
576 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
577 lcd_puts(0, ++line, buf);
578 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
579 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
580 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
581 lcd_puts(0, ++line, buf);
582 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
584 else
586 snprintf(buf, 32, "READ ERR=%d", got_id);
589 lcd_puts(0, ++line, buf);
591 #endif
593 lcd_update();
595 while(1)
597 if (action_userabort(TIMEOUT_BLOCK))
598 return false;
600 #elif CONFIG_CPU == PP5020
601 char buf[32];
602 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
603 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
604 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
605 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
607 lcd_setmargins(0, 0);
608 lcd_setfont(FONT_SYSFIXED);
609 lcd_clear_display();
611 lcd_puts(0, 0, "[Hardware info]");
613 snprintf(buf, sizeof(buf), "HW rev: 0x%08x", ipod_hw_rev);
614 lcd_puts(0, 1, buf);
616 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
617 lcd_puts(0, 2, buf);
618 lcd_update();
620 while(1)
622 if (action_userabort(TIMEOUT_BLOCK))
623 return false;
625 #endif /* CONFIG_CPU */
626 return false;
628 #else /* !HAVE_LCD_BITMAP */
629 static bool dbg_hw_info(void)
631 char buf[32];
632 int button;
633 int currval = 0;
634 int usb_polarity;
635 int bitmask = *(unsigned short*)0x20000fc;
636 int rom_version = *(unsigned short*)0x20000fe;
637 unsigned manu, id; /* flash IDs */
638 bool got_id; /* flag if we managed to get the flash IDs */
639 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
640 bool has_bootrom; /* flag for boot ROM present */
641 int oldmode; /* saved memory guard mode */
643 if(PADRH & 0x04)
644 usb_polarity = 0; /* Negative */
645 else
646 usb_polarity = 1; /* Positive */
648 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
650 /* get flash ROM type */
651 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
652 if (!got_id)
653 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
655 /* check if the boot ROM area is a flash mirror */
656 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
657 if (has_bootrom) /* if ROM and Flash different */
659 /* calculate CRC16 checksum of boot ROM */
660 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
663 system_memory_guard(oldmode); /* re-enable memory guard */
665 lcd_clear_display();
667 lcd_puts(0, 0, "[HW Info]");
668 while(1)
670 switch(currval)
672 case 0:
673 snprintf(buf, 32, "ROM: %d.%02d",
674 rom_version/100, rom_version%100);
675 break;
676 case 1:
677 snprintf(buf, 32, "USB: %s",
678 usb_polarity?"pos":"neg");
679 break;
680 case 2:
681 snprintf(buf, 32, "ATA: 0x%x%s",
682 ata_io_address, ata_device ? "s":"m");
683 break;
684 case 3:
685 snprintf(buf, 32, "Mask: %04x", bitmask);
686 break;
687 case 4:
688 if (got_id)
689 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
690 else
691 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
692 break;
693 case 5:
694 if (has_bootrom)
696 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
697 snprintf(buf, 32, "BootROM: V1");
698 else if (rom_crc == 0x358099E8)
699 snprintf(buf, 32, "BootROM: V2");
700 /* alternative boot ROM found in one single player so far */
701 else
702 snprintf(buf, 32, "R: %08x", rom_crc);
704 else
705 snprintf(buf, 32, "BootROM: no");
708 lcd_puts(0, 1, buf);
709 lcd_update();
711 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
713 switch(button)
715 case ACTION_STD_CANCEL:
716 action_signalscreenchange();
717 return false;
719 case ACTION_SETTINGS_DEC:
720 currval--;
721 if(currval < 0)
722 currval = 5;
723 break;
725 case ACTION_SETTINGS_INC:
726 currval++;
727 if(currval > 5)
728 currval = 0;
729 break;
732 return false;
734 #endif /* !HAVE_LCD_BITMAP */
735 #endif /* !SIMULATOR */
737 #ifndef SIMULATOR
738 bool dbg_partitions(void)
740 int partition=0;
742 lcd_clear_display();
743 lcd_puts(0, 0, "Partition");
744 lcd_puts(0, 1, "list");
745 lcd_update();
746 sleep(HZ/2);
748 while(1)
750 char buf[32];
751 int button;
752 struct partinfo* p = disk_partinfo(partition);
754 lcd_clear_display();
755 snprintf(buf, sizeof buf, "P%d: S:%lx", partition, p->start);
756 lcd_puts(0, 0, buf);
757 snprintf(buf, sizeof buf, "T:%x %ld MB", p->type, p->size / 2048);
758 lcd_puts(0, 1, buf);
759 lcd_update();
761 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
763 switch(button)
765 case ACTION_STD_CANCEL:
766 action_signalscreenchange();
767 return false;
769 case ACTION_SETTINGS_DEC:
770 partition--;
771 if (partition < 0)
772 partition = 3;
773 break;
775 case ACTION_SETTINGS_INC:
776 partition++;
777 if (partition > 3)
778 partition = 0;
779 break;
781 default:
782 if(default_event_handler(button) == SYS_USB_CONNECTED)
783 return true;
784 break;
787 return false;
789 #endif
791 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
792 static bool dbg_spdif(void)
794 char buf[128];
795 int line;
796 unsigned int control;
797 int x;
798 char *s;
799 int category;
800 int generation;
801 unsigned int interruptstat;
802 bool valnogood, symbolerr, parityerr;
803 bool done = false;
804 bool spdif_src_on;
805 int spdif_source = spdif_get_output_source(&spdif_src_on);
806 spdif_set_output_source(AUDIO_SRC_SPDIF, true);
808 lcd_setmargins(0, 0);
809 lcd_clear_display();
810 lcd_setfont(FONT_SYSFIXED);
812 #ifdef HAVE_SPDIF_POWER
813 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
814 #endif
816 while (!done)
818 line = 0;
820 control = EBU1RCVCCHANNEL1;
821 interruptstat = INTERRUPTSTAT;
822 INTERRUPTCLEAR = 0x03c00000;
824 valnogood = (interruptstat & 0x01000000)?true:false;
825 symbolerr = (interruptstat & 0x00800000)?true:false;
826 parityerr = (interruptstat & 0x00400000)?true:false;
828 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
829 valnogood?"--":"OK",
830 symbolerr?"--":"OK",
831 parityerr?"--":"OK");
832 lcd_puts(0, line++, buf);
834 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
835 lcd_puts(0, line++, buf);
837 line++;
839 x = control >> 31;
840 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
841 x, x?"Professional":"Consumer");
842 lcd_puts(0, line++, buf);
844 x = (control >> 30) & 1;
845 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
846 x, x?"Non-PCM":"PCM");
847 lcd_puts(0, line++, buf);
849 x = (control >> 29) & 1;
850 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
851 x, x?"Permitted":"Inhibited");
852 lcd_puts(0, line++, buf);
854 x = (control >> 27) & 7;
855 switch(x)
857 case 0:
858 s = "None";
859 break;
860 case 1:
861 s = "50/15us";
862 break;
863 default:
864 s = "Reserved";
865 break;
867 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
868 lcd_puts(0, line++, buf);
870 x = (control >> 24) & 3;
871 snprintf(buf, sizeof(buf), "Mode: %d", x);
872 lcd_puts(0, line++, buf);
874 category = (control >> 17) & 127;
875 switch(category)
877 case 0x00:
878 s = "General";
879 break;
880 case 0x40:
881 s = "Audio CD";
882 break;
883 default:
884 s = "Unknown";
886 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
887 lcd_puts(0, line++, buf);
889 x = (control >> 16) & 1;
890 generation = x;
891 if(((category & 0x70) == 0x10) ||
892 ((category & 0x70) == 0x40) ||
893 ((category & 0x78) == 0x38))
895 generation = !generation;
897 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
898 x, generation?"Original":"No ind.");
899 lcd_puts(0, line++, buf);
901 x = (control >> 12) & 15;
902 snprintf(buf, sizeof(buf), "Source: %d", x);
903 lcd_puts(0, line++, buf);
905 x = (control >> 8) & 15;
906 switch(x)
908 case 0:
909 s = "Unspecified";
910 break;
911 case 8:
912 s = "A (Left)";
913 break;
914 case 4:
915 s = "B (Right)";
916 break;
917 default:
918 s = "";
919 break;
921 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
922 lcd_puts(0, line++, buf);
924 x = (control >> 4) & 15;
925 switch(x)
927 case 0:
928 s = "44.1kHz";
929 break;
930 case 0x4:
931 s = "48kHz";
932 break;
933 case 0xc:
934 s = "32kHz";
935 break;
937 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
938 lcd_puts(0, line++, buf);
940 x = (control >> 2) & 3;
941 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
942 lcd_puts(0, line++, buf);
943 line++;
945 #ifndef SIMULATOR
946 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
947 spdif_measure_frequency());
948 lcd_puts(0, line++, buf);
949 #endif
951 lcd_update();
953 if (action_userabort(HZ/10))
954 break;
957 spdif_set_output_source(spdif_source, spdif_src_on);
959 #ifdef HAVE_SPDIF_POWER
960 spdif_power_enable(global_settings.spdif_enable);
961 #endif
963 return false;
965 #endif /* CPU_COLDFIRE */
967 #ifndef SIMULATOR
968 #ifdef HAVE_LCD_BITMAP
969 /* button definitions */
970 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
971 (CONFIG_KEYPAD == IRIVER_H300_PAD)
972 # define DEBUG_CANCEL BUTTON_OFF
974 #elif CONFIG_KEYPAD == RECORDER_PAD
975 # define DEBUG_CANCEL BUTTON_OFF
977 #elif CONFIG_KEYPAD == ONDIO_PAD
978 # define DEBUG_CANCEL BUTTON_MENU
980 #elif (CONFIG_KEYPAD == IPOD_3G_PAD) || \
981 (CONFIG_KEYPAD == IPOD_4G_PAD)
982 # define DEBUG_CANCEL BUTTON_MENU
984 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
985 # define DEBUG_CANCEL BUTTON_PLAY
987 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
988 # define DEBUG_CANCEL BUTTON_REC
990 #elif CONFIG_KEYPAD == GIGABEAT_PAD
991 # define DEBUG_CANCEL BUTTON_A
993 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
994 # define DEBUG_CANCEL BUTTON_REW
996 #elif CONFIG_KEYPAD == SANSA_E200_PAD
997 # define DEBUG_CANCEL BUTTON_LEFT
998 #endif /* key definitios */
1000 /* Test code!!! */
1001 bool dbg_ports(void)
1003 #if CONFIG_CPU == SH7034
1004 unsigned short porta;
1005 unsigned short portb;
1006 unsigned char portc;
1007 char buf[32];
1008 int adc_battery_voltage, adc_battery_level;
1010 lcd_setfont(FONT_SYSFIXED);
1011 lcd_setmargins(0, 0);
1012 lcd_clear_display();
1014 while(1)
1016 porta = PADR;
1017 portb = PBDR;
1018 portc = PCDR;
1020 snprintf(buf, 32, "PADR: %04x", porta);
1021 lcd_puts(0, 0, buf);
1022 snprintf(buf, 32, "PBDR: %04x", portb);
1023 lcd_puts(0, 1, buf);
1025 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1026 lcd_puts(0, 2, buf);
1027 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1028 lcd_puts(0, 3, buf);
1029 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1030 lcd_puts(0, 4, buf);
1031 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1032 lcd_puts(0, 5, buf);
1034 battery_read_info(NULL, &adc_battery_voltage,
1035 &adc_battery_level);
1036 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100,
1037 adc_battery_voltage % 100, adc_battery_level);
1038 lcd_puts(0, 6, buf);
1039 #ifndef HAVE_MMC /* have ATA */
1040 snprintf(buf, 32, "ATA: %s, 0x%x",
1041 ata_device?"slave":"master", ata_io_address);
1042 lcd_puts(0, 7, buf);
1043 #endif
1044 lcd_update();
1045 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1046 return false;
1048 #elif defined(CPU_COLDFIRE)
1049 unsigned int gpio_out;
1050 unsigned int gpio1_out;
1051 unsigned int gpio_read;
1052 unsigned int gpio1_read;
1053 unsigned int gpio_function;
1054 unsigned int gpio1_function;
1055 unsigned int gpio_enable;
1056 unsigned int gpio1_enable;
1057 int adc_buttons, adc_remote;
1058 int adc_battery, adc_battery_voltage, adc_battery_level;
1059 char buf[128];
1060 int line;
1062 lcd_setmargins(0, 0);
1063 lcd_clear_display();
1064 lcd_setfont(FONT_SYSFIXED);
1066 while(1)
1068 line = 0;
1069 gpio_read = GPIO_READ;
1070 gpio1_read = GPIO1_READ;
1071 gpio_out = GPIO_OUT;
1072 gpio1_out = GPIO1_OUT;
1073 gpio_function = GPIO_FUNCTION;
1074 gpio1_function = GPIO1_FUNCTION;
1075 gpio_enable = GPIO_ENABLE;
1076 gpio1_enable = GPIO1_ENABLE;
1078 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1079 lcd_puts(0, line++, buf);
1080 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1081 lcd_puts(0, line++, buf);
1082 snprintf(buf, sizeof(buf), "GPIO_FUNCTION: %08x", gpio_function);
1083 lcd_puts(0, line++, buf);
1084 snprintf(buf, sizeof(buf), "GPIO_ENABLE: %08x", gpio_enable);
1085 lcd_puts(0, line++, buf);
1087 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1088 lcd_puts(0, line++, buf);
1089 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1090 lcd_puts(0, line++, buf);
1091 snprintf(buf, sizeof(buf), "GPIO1_FUNCTION: %08x", gpio1_function);
1092 lcd_puts(0, line++, buf);
1093 snprintf(buf, sizeof(buf), "GPIO1_ENABLE: %08x", gpio1_enable);
1094 lcd_puts(0, line++, buf);
1096 adc_buttons = adc_read(ADC_BUTTONS);
1097 adc_remote = adc_read(ADC_REMOTE);
1098 battery_read_info(&adc_battery, &adc_battery_voltage,
1099 &adc_battery_level);
1100 #if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
1101 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1102 button_scan_enabled() ? '+' : '-', adc_buttons);
1103 #else
1104 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1105 #endif
1106 lcd_puts(0, line++, buf);
1107 #if defined(IAUDIO_X5) || defined(IAUDIO_M5)
1108 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1109 remote_detect() ? '+' : '-', adc_remote);
1110 #else
1111 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1112 #endif
1114 lcd_puts(0, line++, buf);
1115 snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_battery);
1116 lcd_puts(0, line++, buf);
1117 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1118 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1119 adc_read(ADC_REMOTEDETECT));
1120 lcd_puts(0, line++, buf);
1121 #endif
1123 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100,
1124 adc_battery_voltage % 100, adc_battery_level);
1125 lcd_puts(0, line++, buf);
1127 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1128 snprintf(buf, sizeof(buf), "remotetype:: %d", remote_type());
1129 lcd_puts(0, line++, buf);
1130 #endif
1132 lcd_update();
1133 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1134 return false;
1137 #elif CONFIG_CPU == PP5020 || CONFIG_CPU == PP5024
1139 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1140 unsigned int gpio_e, gpio_f, gpio_g, gpio_h;
1141 unsigned int gpio_i, gpio_j, gpio_k, gpio_l;
1143 char buf[128];
1144 int line;
1146 lcd_setmargins(0, 0);
1147 lcd_clear_display();
1148 lcd_setfont(FONT_SYSFIXED);
1150 while(1)
1152 gpio_a = GPIOA_INPUT_VAL;
1153 gpio_b = GPIOB_INPUT_VAL;
1154 gpio_c = GPIOC_INPUT_VAL;
1156 gpio_g = GPIOG_INPUT_VAL;
1157 gpio_h = GPIOH_INPUT_VAL;
1158 gpio_i = GPIOI_INPUT_VAL;
1160 line = 0;
1161 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_G: %02x", gpio_a, gpio_g);
1162 lcd_puts(0, line++, buf);
1163 snprintf(buf, sizeof(buf), "GPIO_B: %02x GPIO_H: %02x", gpio_b, gpio_h);
1164 lcd_puts(0, line++, buf);
1165 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_I: %02x", gpio_c, gpio_i);
1166 lcd_puts(0, line++, buf);
1167 line++;
1169 gpio_d = GPIOD_INPUT_VAL;
1170 gpio_e = GPIOE_INPUT_VAL;
1171 gpio_f = GPIOF_INPUT_VAL;
1173 gpio_j = GPIOJ_INPUT_VAL;
1174 gpio_k = GPIOK_INPUT_VAL;
1175 gpio_l = GPIOL_INPUT_VAL;
1177 snprintf(buf, sizeof(buf), "GPIO_D: %02x GPIO_J: %02x", gpio_d, gpio_j);
1178 lcd_puts(0, line++, buf);
1179 snprintf(buf, sizeof(buf), "GPIO_E: %02x GPIO_K: %02x", gpio_e, gpio_k);
1180 lcd_puts(0, line++, buf);
1181 snprintf(buf, sizeof(buf), "GPIO_F: %02x GPIO_L: %02x", gpio_f, gpio_l);
1182 lcd_puts(0, line++, buf);
1183 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1184 line++;
1185 snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_read(ADC_BATTERY));
1186 lcd_puts(0, line++, buf);
1187 snprintf(buf, sizeof(buf), "ADC_UNKNOWN_1: %02x", adc_read(ADC_UNKNOWN_1));
1188 lcd_puts(0, line++, buf);
1189 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_read(ADC_REMOTE));
1190 lcd_puts(0, line++, buf);
1191 snprintf(buf, sizeof(buf), "ADC_SCROLLPAD: %02x", adc_read(ADC_SCROLLPAD));
1192 lcd_puts(0, line++, buf);
1193 #elif defined(SANSA_E200)
1194 line++;
1195 snprintf(buf, sizeof(buf), "ADC_BVDD: %02x", adc_read(ADC_BVDD));
1196 lcd_puts(0, line++, buf);
1197 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %02x", adc_read(ADC_RTCSUP));
1198 lcd_puts(0, line++, buf);
1199 snprintf(buf, sizeof(buf), "ADC_UVDD: %02x", adc_read(ADC_UVDD));
1200 lcd_puts(0, line++, buf);
1201 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %02x", adc_read(ADC_CHG_IN));
1202 lcd_puts(0, line++, buf);
1203 snprintf(buf, sizeof(buf), "ADC_CVDD: %02x", adc_read(ADC_CVDD));
1204 lcd_puts(0, line++, buf);
1205 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %02x", adc_read(ADC_BATTEMP));
1206 lcd_puts(0, line++, buf);
1207 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %02x", adc_read(ADC_MICSUP1));
1208 lcd_puts(0, line++, buf);
1209 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %02x", adc_read(ADC_MICSUP2));
1210 lcd_puts(0, line++, buf);
1211 snprintf(buf, sizeof(buf), "ADC_VBE1: %02x", adc_read(ADC_VBE1));
1212 lcd_puts(0, line++, buf);
1213 snprintf(buf, sizeof(buf), "ADC_VBE2: %02x", adc_read(ADC_VBE2));
1214 lcd_puts(0, line++, buf);
1215 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1: %02x", adc_read(ADC_I_MICSUP1));
1216 lcd_puts(0, line++, buf);
1217 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2: %02x", adc_read(ADC_I_MICSUP2));
1218 lcd_puts(0, line++, buf);
1219 snprintf(buf, sizeof(buf), "ADC_VBAT: %02x", adc_read(ADC_VBAT));
1220 lcd_puts(0, line++, buf);
1221 #endif
1222 lcd_update();
1223 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1224 return false;
1227 #elif CONFIG_CPU == PP5002
1228 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1230 char buf[128];
1231 int line;
1233 lcd_setmargins(0, 0);
1234 lcd_clear_display();
1235 lcd_setfont(FONT_SYSFIXED);
1237 while(1)
1239 gpio_a = GPIOA_INPUT_VAL;
1240 gpio_b = GPIOB_INPUT_VAL;
1241 gpio_c = GPIOC_INPUT_VAL;
1242 gpio_d = GPIOD_INPUT_VAL;
1244 line = 0;
1245 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x", gpio_a, gpio_b);
1246 lcd_puts(0, line++, buf);
1247 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x", gpio_c, gpio_d);
1248 lcd_puts(0, line++, buf);
1250 lcd_update();
1251 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
1252 return false;
1254 #endif /* CPU */
1255 return false;
1257 #else /* !HAVE_LCD_BITMAP */
1258 bool dbg_ports(void)
1260 unsigned short porta;
1261 unsigned short portb;
1262 unsigned char portc;
1263 char buf[32];
1264 int button;
1265 int adc_battery_voltage;
1266 int currval = 0;
1268 lcd_clear_display();
1270 while(1)
1272 porta = PADR;
1273 portb = PBDR;
1274 portc = PCDR;
1276 switch(currval)
1278 case 0:
1279 snprintf(buf, 32, "PADR: %04x ", porta);
1280 break;
1281 case 1:
1282 snprintf(buf, 32, "PBDR: %04x ", portb);
1283 break;
1284 case 2:
1285 snprintf(buf, 32, "AN0: %03x ", adc_read(0));
1286 break;
1287 case 3:
1288 snprintf(buf, 32, "AN1: %03x ", adc_read(1));
1289 break;
1290 case 4:
1291 snprintf(buf, 32, "AN2: %03x ", adc_read(2));
1292 break;
1293 case 5:
1294 snprintf(buf, 32, "AN3: %03x ", adc_read(3));
1295 break;
1296 case 6:
1297 snprintf(buf, 32, "AN4: %03x ", adc_read(4));
1298 break;
1299 case 7:
1300 snprintf(buf, 32, "AN5: %03x ", adc_read(5));
1301 break;
1302 case 8:
1303 snprintf(buf, 32, "AN6: %03x ", adc_read(6));
1304 break;
1305 case 9:
1306 snprintf(buf, 32, "AN7: %03x ", adc_read(7));
1307 break;
1308 case 10:
1309 snprintf(buf, 32, "%s, 0x%x ",
1310 ata_device?"slv":"mst", ata_io_address);
1311 break;
1313 lcd_puts(0, 0, buf);
1315 battery_read_info(NULL, &adc_battery_voltage, NULL);
1316 snprintf(buf, 32, "Batt: %d.%02dV", adc_battery_voltage / 100,
1317 adc_battery_voltage % 100);
1318 lcd_puts(0, 1, buf);
1320 button = get_action(CONTEXT_SETTINGS,HZ/5);
1322 switch(button)
1324 case ACTION_STD_CANCEL:
1325 action_signalscreenchange();
1326 return false;
1328 case ACTION_SETTINGS_DEC:
1329 currval--;
1330 if(currval < 0)
1331 currval = 10;
1332 break;
1334 case ACTION_SETTINGS_INC:
1335 currval++;
1336 if(currval > 10)
1337 currval = 0;
1338 break;
1341 return false;
1343 #endif /* !HAVE_LCD_BITMAP */
1344 #endif /* !SIMULATOR */
1346 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1347 static bool dbg_cpufreq(void)
1349 char buf[128];
1350 int line;
1351 int button;
1353 #ifdef HAVE_LCD_BITMAP
1354 lcd_setmargins(0, 0);
1355 lcd_setfont(FONT_SYSFIXED);
1356 #endif
1357 lcd_clear_display();
1359 while(1)
1361 line = 0;
1363 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1364 lcd_puts(0, line++, buf);
1366 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1367 lcd_puts(0, line++, buf);
1369 lcd_update();
1370 button = get_action(CONTEXT_STD,HZ/10);
1372 switch(button)
1374 case ACTION_STD_PREV:
1375 cpu_boost(true);
1376 break;
1378 case ACTION_STD_NEXT:
1379 cpu_boost(false);
1380 break;
1382 case ACTION_STD_OK:
1383 while (get_cpu_boost_counter() > 0)
1384 cpu_boost(false);
1385 set_cpu_frequency(CPUFREQ_DEFAULT);
1386 break;
1388 case ACTION_STD_CANCEL:
1389 action_signalscreenchange();
1390 return false;
1394 return false;
1396 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1398 #ifndef SIMULATOR
1399 #ifdef HAVE_LCD_BITMAP
1401 * view_battery() shows a automatically scaled graph of the battery voltage
1402 * over time. Usable for estimating battery life / charging rate.
1403 * The power_history array is updated in power_thread of powermgmt.c.
1406 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1407 #define BAT_YSPACE (LCD_HEIGHT - 20)
1409 static bool view_battery(void)
1411 int view = 0;
1412 int i, x, y;
1413 unsigned short maxv, minv;
1414 char buf[32];
1416 lcd_setmargins(0, 0);
1417 lcd_setfont(FONT_SYSFIXED);
1419 while(1)
1421 switch (view) {
1422 case 0: /* voltage history graph */
1423 /* Find maximum and minimum voltage for scaling */
1424 maxv = 0;
1425 minv = 65535;
1426 for (i = 0; i < BAT_LAST_VAL; i++) {
1427 if (power_history[i] > maxv)
1428 maxv = power_history[i];
1429 if (power_history[i] && (power_history[i] < minv))
1431 minv = power_history[i];
1435 if ((minv < 1) || (minv >= 65535))
1436 minv = 1;
1437 if (maxv < 2)
1438 maxv = 2;
1439 if (minv == maxv)
1440 maxv < 65535 ? maxv++ : minv--;
1442 lcd_clear_display();
1443 snprintf(buf, 30, "Battery %d.%02d", power_history[0] / 100,
1444 power_history[0] % 100);
1445 lcd_puts(0, 0, buf);
1446 snprintf(buf, 30, "scale %d.%02d-%d.%02d V",
1447 minv / 100, minv % 100, maxv / 100, maxv % 100);
1448 lcd_puts(0, 1, buf);
1450 x = 0;
1451 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1452 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1453 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1454 lcd_vline(x, LCD_HEIGHT-1, 20);
1455 lcd_set_drawmode(DRMODE_SOLID);
1456 lcd_vline(x, LCD_HEIGHT-1,
1457 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1458 x++;
1461 break;
1463 case 1: /* status: */
1464 lcd_clear_display();
1465 lcd_puts(0, 0, "Power status:");
1467 battery_read_info(NULL, &y, NULL);
1468 snprintf(buf, 30, "Battery: %d.%02d V", y / 100, y % 100);
1469 lcd_puts(0, 1, buf);
1470 #ifdef ADC_EXT_POWER
1471 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000;
1472 snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100);
1473 lcd_puts(0, 2, buf);
1474 #endif
1475 #if CONFIG_CHARGING
1476 #if CONFIG_CHARGING == CHARGING_CONTROL
1477 snprintf(buf, 30, "Chgr: %s %s",
1478 charger_inserted() ? "present" : "absent",
1479 charger_enabled ? "on" : "off");
1480 lcd_puts(0, 3, buf);
1481 snprintf(buf, 30, "short delta: %d", short_delta);
1482 lcd_puts(0, 5, buf);
1483 snprintf(buf, 30, "long delta: %d", long_delta);
1484 lcd_puts(0, 6, buf);
1485 lcd_puts(0, 7, power_message);
1486 snprintf(buf, 30, "USB Inserted: %s",
1487 usb_inserted() ? "yes" : "no");
1488 lcd_puts(0, 8, buf);
1489 #if defined IRIVER_H300_SERIES
1490 snprintf(buf, 30, "USB Charging Enabled: %s",
1491 usb_charging_enabled() ? "yes" : "no");
1492 lcd_puts(0, 9, buf);
1493 #endif
1494 #else /* CONFIG_CHARGING != CHARGING_CONTROL */
1495 #if defined IPOD_NANO || defined IPOD_VIDEO
1496 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1497 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1498 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1499 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1500 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1502 snprintf(buf, 30, "USB pwr: %s",
1503 usb_pwr ? "present" : "absent");
1504 lcd_puts(0, 3, buf);
1505 snprintf(buf, 30, "EXT pwr: %s",
1506 ext_pwr ? "present" : "absent");
1507 lcd_puts(0, 4, buf);
1508 snprintf(buf, 30, "Battery: %s",
1509 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1510 lcd_puts(0, 5, buf);
1511 snprintf(buf, 30, "Dock mode: %s",
1512 dock ? "enabled" : "disabled");
1513 lcd_puts(0, 6, buf);
1514 snprintf(buf, 30, "Headphone: %s",
1515 headphone ? "connected" : "disconnected");
1516 lcd_puts(0, 7, buf);
1517 #else
1518 snprintf(buf, 30, "Charger: %s",
1519 charger_inserted() ? "present" : "absent");
1520 lcd_puts(0, 3, buf);
1521 #endif
1522 #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1523 #endif /* CONFIG_CHARGING */
1524 break;
1526 case 2: /* voltage deltas: */
1527 lcd_clear_display();
1528 lcd_puts(0, 0, "Voltage deltas:");
1530 for (i = 0; i <= 6; i++) {
1531 y = power_history[i] - power_history[i+i];
1532 snprintf(buf, 30, "-%d min: %s%d.%02d V", i,
1533 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 100,
1534 ((y < 0) ? y * -1 : y ) % 100);
1535 lcd_puts(0, i+1, buf);
1537 break;
1539 case 3: /* remaining time estimation: */
1540 lcd_clear_display();
1542 #if CONFIG_CHARGING == CHARGING_CONTROL
1543 snprintf(buf, 30, "charge_state: %d", charge_state);
1544 lcd_puts(0, 0, buf);
1546 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1547 lcd_puts(0, 1, buf);
1549 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1550 lcd_puts(0, 2, buf);
1552 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1553 lcd_puts(0, 3, buf);
1555 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1556 lcd_puts(0, 4, buf);
1557 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
1559 snprintf(buf, 30, "Last PwrHist: %d.%02d V",
1560 power_history[0] / 100,
1561 power_history[0] % 100);
1562 lcd_puts(0, 5, buf);
1564 snprintf(buf, 30, "battery level: %d%%", battery_level());
1565 lcd_puts(0, 6, buf);
1567 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1568 lcd_puts(0, 7, buf);
1569 break;
1572 lcd_update();
1574 switch(get_action(CONTEXT_SETTINGS,HZ/2))
1576 case ACTION_SETTINGS_DEC:
1577 if (view)
1578 view--;
1579 break;
1581 case ACTION_SETTINGS_INC:
1582 if (view < 3)
1583 view++;
1584 break;
1586 case ACTION_STD_CANCEL:
1587 action_signalscreenchange();
1588 return false;
1591 return false;
1594 #endif /* HAVE_LCD_BITMAP */
1595 #endif
1597 #ifndef SIMULATOR
1598 #ifdef HAVE_MMC
1599 static bool dbg_mmc_info(void)
1601 bool done = false;
1602 int currval = 0;
1603 int line;
1604 tCardInfo *card;
1605 unsigned char pbuf[32], pbuf2[32];
1606 unsigned char card_name[7];
1608 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1609 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1610 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1611 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1612 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1613 "3.1-3.31", "4.0" };
1615 card_name[6] = '\0';
1617 lcd_setmargins(0, 0);
1618 lcd_setfont(FONT_SYSFIXED);
1620 while (!done)
1622 card = mmc_card_info(currval / 2);
1624 line = 0;
1625 lcd_clear_display();
1626 snprintf(pbuf, sizeof(pbuf), "[MMC%d p%d]", currval / 2,
1627 (currval % 2) + 1);
1628 lcd_puts(0, line++, pbuf);
1630 if (card->initialized)
1632 if (!(currval % 2)) /* General info */
1634 int temp;
1636 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1637 snprintf(pbuf, sizeof(pbuf), "%s Rev %d.%d", card_name,
1638 (int) mmc_extract_bits(card->cid, 72, 4),
1639 (int) mmc_extract_bits(card->cid, 76, 4));
1640 lcd_puts(0, line++, pbuf);
1641 snprintf(pbuf, sizeof(pbuf), "Prod: %d/%d",
1642 (int) mmc_extract_bits(card->cid, 112, 4),
1643 (int) mmc_extract_bits(card->cid, 116, 4) + 1997);
1644 lcd_puts(0, line++, pbuf);
1645 snprintf(pbuf, sizeof(pbuf), "Ser#: 0x%08lx",
1646 mmc_extract_bits(card->cid, 80, 32));
1647 lcd_puts(0, line++, pbuf);
1648 snprintf(pbuf, sizeof(pbuf), "M=%02x, O=%04x",
1649 (int) mmc_extract_bits(card->cid, 0, 8),
1650 (int) mmc_extract_bits(card->cid, 8, 16));
1651 lcd_puts(0, line++, pbuf);
1652 temp = mmc_extract_bits(card->csd, 2, 4);
1653 snprintf(pbuf, sizeof(pbuf), "MMC v%s", temp < 5 ?
1654 spec_vers[temp] : "?.?");
1655 lcd_puts(0, line++, pbuf);
1656 snprintf(pbuf, sizeof(pbuf), "Blocks: 0x%06lx", card->numblocks);
1657 lcd_puts(0, line++, pbuf);
1658 snprintf(pbuf, sizeof(pbuf), "Blksz.: %d P:%c%c", card->blocksize,
1659 mmc_extract_bits(card->csd, 48, 1) ? 'R' : '-',
1660 mmc_extract_bits(card->csd, 106, 1) ? 'W' : '-');
1661 lcd_puts(0, line++, pbuf);
1663 else /* Technical details */
1665 output_dyn_value(pbuf2, sizeof pbuf2, card->speed / 1000,
1666 kbit_units, false);
1667 snprintf(pbuf, sizeof pbuf, "Speed: %s", pbuf2);
1668 lcd_puts(0, line++, pbuf);
1670 output_dyn_value(pbuf2, sizeof pbuf2, card->tsac,
1671 nsec_units, false);
1672 snprintf(pbuf, sizeof pbuf, "Tsac: %s", pbuf2);
1673 lcd_puts(0, line++, pbuf);
1675 snprintf(pbuf, sizeof(pbuf), "Nsac: %d clk", card->nsac);
1676 lcd_puts(0, line++, pbuf);
1677 snprintf(pbuf, sizeof(pbuf), "R2W: *%d", card->r2w_factor);
1678 lcd_puts(0, line++, pbuf);
1679 snprintf(pbuf, sizeof(pbuf), "IRmax: %d..%d mA",
1680 i_vmin[mmc_extract_bits(card->csd, 66, 3)],
1681 i_vmax[mmc_extract_bits(card->csd, 69, 3)]);
1682 lcd_puts(0, line++, pbuf);
1683 snprintf(pbuf, sizeof(pbuf), "IWmax: %d..%d mA",
1684 i_vmin[mmc_extract_bits(card->csd, 72, 3)],
1685 i_vmax[mmc_extract_bits(card->csd, 75, 3)]);
1686 lcd_puts(0, line++, pbuf);
1689 else
1690 lcd_puts(0, line++, "Not found!");
1692 lcd_update();
1694 switch (get_action(CONTEXT_SETTINGS,HZ/2))
1696 case ACTION_STD_CANCEL:
1697 done = true;
1698 break;
1700 case ACTION_SETTINGS_DEC:
1701 currval--;
1702 if (currval < 0)
1703 currval = 3;
1704 break;
1706 case ACTION_SETTINGS_INC:
1707 currval++;
1708 if (currval > 3)
1709 currval = 0;
1710 break;
1713 action_signalscreenchange();
1714 return false;
1716 #else /* !HAVE_MMC */
1717 static bool dbg_disk_info(void)
1719 char buf[128];
1720 bool done = false;
1721 int i;
1722 int page = 0;
1723 const int max_page = 11;
1724 unsigned short* identify_info = ata_get_identify();
1725 bool timing_info_present = false;
1726 char pio3[2], pio4[2];
1728 #ifdef HAVE_LCD_BITMAP
1729 lcd_setmargins(0, 0);
1730 #endif
1732 while(!done)
1734 int y=0;
1735 int key;
1736 lcd_clear_display();
1737 #ifdef HAVE_LCD_BITMAP
1738 lcd_puts(0, y++, "Disk info:");
1739 y++;
1740 #endif
1742 switch (page) {
1743 case 0:
1744 for (i=0; i < 20; i++)
1745 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1746 buf[40]=0;
1747 /* kill trailing space */
1748 for (i=39; i && buf[i]==' '; i--)
1749 buf[i] = 0;
1750 lcd_puts(0, y++, "Model");
1751 lcd_puts_scroll(0, y++, buf);
1752 break;
1754 case 1:
1755 for (i=0; i < 4; i++)
1756 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1757 buf[8]=0;
1758 lcd_puts(0, y++, "Firmware");
1759 lcd_puts(0, y++, buf);
1760 break;
1762 case 2:
1763 snprintf(buf, sizeof buf, "%ld MB",
1764 ((unsigned long)identify_info[61] << 16 |
1765 (unsigned long)identify_info[60]) / 2048 );
1766 lcd_puts(0, y++, "Size");
1767 lcd_puts(0, y++, buf);
1768 break;
1770 case 3: {
1771 unsigned long free;
1772 fat_size( IF_MV2(0,) NULL, &free );
1773 snprintf(buf, sizeof buf, "%ld MB", free / 1024 );
1774 lcd_puts(0, y++, "Free");
1775 lcd_puts(0, y++, buf);
1776 break;
1779 case 4:
1780 snprintf(buf, sizeof buf, "%d ms", ata_spinup_time * (1000/HZ));
1781 lcd_puts(0, y++, "Spinup time");
1782 lcd_puts(0, y++, buf);
1783 break;
1785 case 5:
1786 i = identify_info[83] & (1<<3);
1787 lcd_puts(0, y++, "Power mgmt:");
1788 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1789 break;
1791 case 6:
1792 i = identify_info[83] & (1<<9);
1793 lcd_puts(0, y++, "Noise mgmt:");
1794 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1795 break;
1797 case 7:
1798 i = identify_info[82] & (1<<6);
1799 lcd_puts(0, y++, "Read-ahead:");
1800 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1801 break;
1803 case 8:
1804 timing_info_present = identify_info[53] & (1<<1);
1805 if(timing_info_present) {
1806 pio3[1] = 0;
1807 pio4[1] = 0;
1808 lcd_puts(0, y++, "PIO modes:");
1809 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1810 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1811 snprintf(buf, 128, "0 1 2 %s %s", pio3, pio4);
1812 lcd_puts(0, y++, buf);
1813 } else {
1814 lcd_puts(0, y++, "No PIO mode info");
1816 break;
1818 case 9:
1819 timing_info_present = identify_info[53] & (1<<1);
1820 if(timing_info_present) {
1821 lcd_puts(0, y++, "Cycle times");
1822 snprintf(buf, 128, "%dns/%dns",
1823 identify_info[67],
1824 identify_info[68]);
1825 lcd_puts(0, y++, buf);
1826 } else {
1827 lcd_puts(0, y++, "No timing info");
1829 break;
1831 case 10:
1832 timing_info_present = identify_info[53] & (1<<1);
1833 if(timing_info_present) {
1834 i = identify_info[49] & (1<<11);
1835 snprintf(buf, 128, "IORDY support: %s", i ? "yes" : "no");
1836 lcd_puts(0, y++, buf);
1837 i = identify_info[49] & (1<<10);
1838 snprintf(buf, 128, "IORDY disable: %s", i ? "yes" : "no");
1839 lcd_puts(0, y++, buf);
1840 } else {
1841 lcd_puts(0, y++, "No timing info");
1843 break;
1845 case 11:
1846 lcd_puts(0, y++, "Cluster size");
1847 snprintf(buf, 128, "%d bytes", fat_get_cluster_size(IF_MV(0)));
1848 lcd_puts(0, y++, buf);
1849 break;
1851 lcd_update();
1853 /* Wait for a key to be pushed */
1854 key = get_action(CONTEXT_SETTINGS,HZ/5);
1855 switch(key) {
1856 case ACTION_STD_CANCEL:
1857 done = true;
1858 break;
1860 case ACTION_SETTINGS_DEC:
1861 if (--page < 0)
1862 page = max_page;
1863 break;
1865 case ACTION_SETTINGS_INC:
1866 if (++page > max_page)
1867 page = 0;
1868 break;
1870 lcd_stop_scroll();
1872 action_signalscreenchange();
1873 return false;
1875 #endif /* !HAVE_MMC */
1876 #endif /* !SIMULATOR */
1878 #ifdef HAVE_DIRCACHE
1879 static bool dbg_dircache_info(void)
1881 bool done = false;
1882 int line;
1883 char buf[32];
1885 lcd_setmargins(0, 0);
1886 lcd_setfont(FONT_SYSFIXED);
1888 while (!done)
1890 line = 0;
1892 lcd_clear_display();
1893 snprintf(buf, sizeof(buf), "Cache initialized: %s",
1894 dircache_is_enabled() ? "Yes" : "No");
1895 lcd_puts(0, line++, buf);
1897 snprintf(buf, sizeof(buf), "Cache size: %d B",
1898 dircache_get_cache_size());
1899 lcd_puts(0, line++, buf);
1901 snprintf(buf, sizeof(buf), "Last size: %d B",
1902 global_status.dircache_size);
1903 lcd_puts(0, line++, buf);
1905 snprintf(buf, sizeof(buf), "Limit: %d B", DIRCACHE_LIMIT);
1906 lcd_puts(0, line++, buf);
1908 snprintf(buf, sizeof(buf), "Reserve: %d/%d B",
1909 dircache_get_reserve_used(), DIRCACHE_RESERVE);
1910 lcd_puts(0, line++, buf);
1912 snprintf(buf, sizeof(buf), "Scanning took: %d s",
1913 dircache_get_build_ticks() / HZ);
1914 lcd_puts(0, line++, buf);
1916 snprintf(buf, sizeof(buf), "Entry count: %d",
1917 dircache_get_entry_count());
1918 lcd_puts(0, line++, buf);
1920 lcd_update();
1922 if (action_userabort(HZ/2))
1923 return false;
1926 return false;
1929 #endif /* HAVE_DIRCACHE */
1931 #ifdef HAVE_LCD_BITMAP
1932 #ifdef HAVE_TAGCACHE
1933 static bool dbg_tagcache_info(void)
1935 bool done = false;
1936 int line;
1937 char buf[32];
1938 struct tagcache_stat *stat;
1940 lcd_setmargins(0, 0);
1941 lcd_setfont(FONT_SYSFIXED);
1943 while (!done)
1945 line = 0;
1947 lcd_clear_display();
1948 stat = tagcache_get_stat();
1949 snprintf(buf, sizeof(buf), "Initialized: %s", stat->initialized ? "Yes" : "No");
1950 lcd_puts(0, line++, buf);
1951 snprintf(buf, sizeof(buf), "DB Ready: %s", stat->ready ? "Yes" : "No");
1952 lcd_puts(0, line++, buf);
1953 snprintf(buf, sizeof(buf), "RAM Cache: %s", stat->ramcache ? "Yes" : "No");
1954 lcd_puts(0, line++, buf);
1955 snprintf(buf, sizeof(buf), "RAM: %d/%d B",
1956 stat->ramcache_used, stat->ramcache_allocated);
1957 lcd_puts(0, line++, buf);
1958 snprintf(buf, sizeof(buf), "Progress: %d%% (%d entries)",
1959 stat->progress, stat->processed_entries);
1960 lcd_puts(0, line++, buf);
1961 snprintf(buf, sizeof(buf), "Commit step: %d", stat->commit_step);
1962 lcd_puts(0, line++, buf);
1963 snprintf(buf, sizeof(buf), "Commit delayed: %s",
1964 stat->commit_delayed ? "Yes" : "No");
1965 lcd_puts(0, line++, buf);
1967 lcd_update();
1969 if (action_userabort(HZ/2))
1970 return false;
1973 return false;
1975 #endif
1976 #endif
1978 #if CONFIG_CPU == SH7034
1979 static bool dbg_save_roms(void)
1981 int fd;
1982 int oldmode = system_memory_guard(MEMGUARD_NONE);
1984 fd = creat("/internal_rom_0000-FFFF.bin");
1985 if(fd >= 0)
1987 write(fd, (void *)0, 0x10000);
1988 close(fd);
1991 fd = creat("/internal_rom_2000000-203FFFF.bin");
1992 if(fd >= 0)
1994 write(fd, (void *)0x2000000, 0x40000);
1995 close(fd);
1998 system_memory_guard(oldmode);
1999 return false;
2001 #elif defined CPU_COLDFIRE
2002 static bool dbg_save_roms(void)
2004 int fd;
2005 int oldmode = system_memory_guard(MEMGUARD_NONE);
2007 #if defined(IRIVER_H100_SERIES)
2008 fd = creat("/internal_rom_000000-1FFFFF.bin");
2009 #elif defined(IRIVER_H300_SERIES)
2010 fd = creat("/internal_rom_000000-3FFFFF.bin");
2011 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5)
2012 fd = creat("/internal_rom_000000-3FFFFF.bin");
2013 #endif
2014 if(fd >= 0)
2016 write(fd, (void *)0, FLASH_SIZE);
2017 close(fd);
2019 system_memory_guard(oldmode);
2021 #ifdef HAVE_EEPROM
2022 fd = creat("/internal_eeprom.bin");
2023 if (fd >= 0)
2025 int old_irq_level;
2026 char buf[EEPROM_SIZE];
2027 int err;
2029 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
2031 err = eeprom_24cxx_read(0, buf, sizeof buf);
2032 if (err)
2033 gui_syncsplash(HZ*3, "Eeprom read failure (%d)",err);
2034 else
2036 write(fd, buf, sizeof buf);
2039 set_irq_level(old_irq_level);
2041 close(fd);
2043 #endif
2045 return false;
2047 #elif defined(CPU_PP) && !defined(SANSA_E200)
2048 static bool dbg_save_roms(void)
2050 int fd;
2052 fd = creat("/internal_rom_000000-0FFFFF.bin");
2053 if(fd >= 0)
2055 write(fd, (void *)0x20000000, FLASH_SIZE);
2056 close(fd);
2059 return false;
2061 #endif /* CPU */
2063 #ifndef SIMULATOR
2064 #if CONFIG_TUNER
2065 static bool dbg_fm_radio(void)
2067 char buf[32];
2068 bool fm_detected;
2070 #ifdef HAVE_LCD_BITMAP
2071 lcd_setmargins(0, 0);
2072 #endif
2074 while(1)
2076 int row = 0;
2078 lcd_clear_display();
2079 fm_detected = radio_hardware_present();
2081 snprintf(buf, sizeof buf, "HW detected: %s", fm_detected?"yes":"no");
2082 lcd_puts(0, row++, buf);
2084 #if (CONFIG_TUNER & S1A0903X01)
2085 snprintf(buf, sizeof buf, "Samsung regs: %08X",
2086 samsung_get(RADIO_ALL));
2087 lcd_puts(0, row++, buf);
2088 #endif
2089 #if (CONFIG_TUNER & TEA5767)
2091 struct philips_dbg_info info;
2092 philips_dbg_info(&info);
2094 snprintf(buf, sizeof buf, "Philips regs:");
2095 lcd_puts(0, row++, buf);
2097 snprintf(buf, sizeof buf, " Read: %02X %02X %02X %02X %02X",
2098 (unsigned)info.read_regs[0], (unsigned)info.read_regs[1],
2099 (unsigned)info.read_regs[2], (unsigned)info.read_regs[3],
2100 (unsigned)info.read_regs[4]);
2101 lcd_puts(0, row++, buf);
2103 snprintf(buf, sizeof buf, " Write: %02X %02X %02X %02X %02X",
2104 (unsigned)info.write_regs[0], (unsigned)info.write_regs[1],
2105 (unsigned)info.write_regs[2], (unsigned)info.write_regs[3],
2106 (unsigned)info.write_regs[4]);
2107 lcd_puts(0, row++, buf);
2109 #endif
2110 lcd_update();
2112 if (action_userabort(HZ))
2113 return false;
2115 return false;
2117 #endif /* CONFIG_TUNER */
2118 #endif /* !SIMULATOR */
2120 #ifdef HAVE_LCD_BITMAP
2121 extern bool do_screendump_instead_of_usb;
2123 static bool dbg_screendump(void)
2125 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2126 gui_syncsplash(HZ, "Screendump %s",
2127 do_screendump_instead_of_usb?"enabled":"disabled");
2128 return false;
2130 #endif /* HAVE_LCD_BITMAP */
2132 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2133 static bool dbg_set_memory_guard(void)
2135 static const struct opt_items names[MAXMEMGUARD] = {
2136 { "None", -1 },
2137 { "Flash ROM writes", -1 },
2138 { "Zero area (all)", -1 }
2140 int mode = system_memory_guard(MEMGUARD_KEEP);
2142 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2143 system_memory_guard(mode);
2145 return false;
2147 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2149 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2151 extern volatile bool lcd_poweroff;
2153 static bool dbg_lcd_power_off(void)
2155 lcd_setmargins(0, 0);
2157 while(1)
2159 int button;
2161 lcd_clear_display();
2162 lcd_puts(0, 0, "LCD Power Off");
2163 if(lcd_poweroff)
2164 lcd_puts(1, 1, "Yes");
2165 else
2166 lcd_puts(1, 1, "No");
2168 lcd_update();
2170 button = get_action(CONTEXT_STD,HZ/5);
2171 switch(button)
2173 case ACTION_STD_PREV:
2174 case ACTION_STD_NEXT:
2175 lcd_poweroff = !lcd_poweroff;
2176 break;
2177 case ACTION_STD_OK:
2178 case ACTION_STD_CANCEL:
2179 action_signalscreenchange();
2180 return false;
2181 default:
2182 sleep(HZ/10);
2183 break;
2186 return false;
2189 #include "backlight-target.h"
2191 static bool dbg_buttonlights(void)
2193 unsigned short mode_changed = 1, mode = 0;
2194 enum buttonlight_selection which_led = BUTTONLIGHT_LED_ALL;
2195 unsigned short brightness = DEFAULT_BRIGHTNESS_SETTING;
2197 lcd_setmargins(0, 0);
2198 for (;;)
2200 int button;
2202 if (mode_changed)
2204 lcd_clear_display();
2205 lcd_puts(0, 0, "Button light support");
2206 lcd_puts(0, 1, "Press UP for mode change");
2207 lcd_puts(0, 2, "Press DOWN for buttonlight selection");
2209 switch (mode)
2211 case 0:
2212 lcd_puts(1, 3, "Off");
2213 __buttonlight_mode(BUTTONLIGHT_OFF, which_led, brightness);
2214 break;
2216 case 1:
2217 lcd_puts(1, 3, "On - Set to brightness");
2218 __buttonlight_mode(BUTTONLIGHT_ON, which_led, brightness);
2219 break;
2221 case 2:
2222 lcd_puts(1, 3, "Faint - Always on at lowest brightness");
2223 __buttonlight_mode(BUTTONLIGHT_FAINT, which_led, brightness);
2224 break;
2226 case 3:
2227 lcd_puts(1, 3, "Flicker on disk access");
2228 __buttonlight_mode(BUTTONLIGHT_FLICKER, which_led, brightness);
2229 break;
2231 case 4:
2232 lcd_puts(1, 3, "Solid on disk access");
2233 __buttonlight_mode(BUTTONLIGHT_SIGNAL, which_led, brightness);
2234 break;
2236 case 5:
2237 lcd_puts(1, 3, "Follows backlight");
2238 __buttonlight_mode(BUTTONLIGHT_FOLLOW, which_led, brightness);
2239 break;
2241 case 6:
2242 lcd_puts(1, 3, "Shows 'battery charging'");
2243 __buttonlight_mode(BUTTONLIGHT_CHARGING, which_led, brightness);
2244 break;
2247 mode_changed = 0;
2248 lcd_update();
2253 /* does nothing unless in flicker mode */
2254 /* the parameter sets the brightness */
2255 __buttonlight_trigger();
2256 button = get_action(CONTEXT_STD,HZ/5);
2257 switch(button)
2259 case ACTION_STD_PREV:
2260 if (++mode > 6) mode = 0;
2261 mode_changed = 1;
2262 break;
2264 case ACTION_STD_NEXT:
2265 if (which_led == BUTTONLIGHT_LED_ALL)
2267 which_led = BUTTONLIGHT_LED_MENU;
2269 else
2271 which_led = BUTTONLIGHT_LED_ALL;
2273 mode_changed = 1;
2275 break;
2278 case ACTION_STD_OK:
2279 case ACTION_STD_CANCEL:
2280 action_signalscreenchange();
2281 return false;
2283 default:
2284 sleep(HZ/10);
2285 break;
2288 return false;
2294 #endif
2296 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2297 static bool dbg_write_eeprom(void)
2299 int fd;
2300 int rc;
2301 int old_irq_level;
2302 char buf[EEPROM_SIZE];
2303 int err;
2305 fd = open("/internal_eeprom.bin", O_RDONLY);
2307 if (fd >= 0)
2309 rc = read(fd, buf, EEPROM_SIZE);
2311 if(rc == EEPROM_SIZE)
2313 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
2315 err = eeprom_24cxx_write(0, buf, sizeof buf);
2316 if (err)
2317 gui_syncsplash(HZ*3, "Eeprom write failure (%d)",err);
2318 else
2319 gui_syncsplash(HZ*3, "Eeprom written successfully");
2321 set_irq_level(old_irq_level);
2323 else
2325 gui_syncsplash(HZ*3, "File read error (%d)",rc);
2327 close(fd);
2329 else
2331 gui_syncsplash(HZ*3, "Failed to open 'internal_eeprom.bin'");
2334 return false;
2336 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2337 #ifdef CPU_BOOST_LOGGING
2338 static bool cpu_boost_log(void)
2340 int i = 0,j=0;
2341 int count = cpu_boost_log_getcount();
2342 int lines = LCD_HEIGHT/SYSFONT_HEIGHT;
2343 char *str;
2344 bool done;
2345 lcd_setmargins(0, 0);
2346 lcd_setfont(FONT_SYSFIXED);
2347 str = cpu_boost_log_getlog_first();
2348 while (i < count)
2350 lcd_clear_display();
2351 for(j=0; j<lines; j++,i++)
2353 if (!str)
2354 str = cpu_boost_log_getlog_next();
2355 if (str)
2357 lcd_puts(0, j,str);
2359 str = NULL;
2361 lcd_update();
2362 done = false;
2363 action_signalscreenchange();
2364 while (!done)
2366 switch(get_action(CONTEXT_STD,TIMEOUT_BLOCK))
2368 case ACTION_STD_OK:
2369 case ACTION_STD_PREV:
2370 case ACTION_STD_NEXT:
2371 done = true;
2372 break;
2373 case ACTION_STD_CANCEL:
2374 i = count;
2375 done = true;
2376 break;
2380 get_action(CONTEXT_STD,TIMEOUT_BLOCK);
2381 lcd_setfont(FONT_UI);
2382 action_signalscreenchange();
2383 return false;
2385 #endif
2386 bool debug_menu(void)
2388 int m;
2389 bool result;
2391 static const struct menu_item items[] = {
2392 #if defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR)
2393 { "LCD Power Off", dbg_lcd_power_off },
2394 { "Button Light modes", dbg_buttonlights },
2396 #endif
2397 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
2398 (defined(CPU_PP) && !defined(SANSA_E200))
2399 { "Dump ROM contents", dbg_save_roms },
2400 #endif
2401 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP)
2402 { "View I/O ports", dbg_ports },
2403 #endif
2404 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2405 { "CPU frequency", dbg_cpufreq },
2406 #endif
2407 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2408 { "S/PDIF analyzer", dbg_spdif },
2409 #endif
2410 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2411 { "Catch mem accesses", dbg_set_memory_guard },
2412 #endif
2413 #ifndef SIMULATOR
2414 { "View OS stacks", dbg_os },
2415 #endif
2416 #ifdef HAVE_LCD_BITMAP
2417 #ifndef SIMULATOR
2418 { "View battery", view_battery },
2419 #endif
2420 { "Screendump", dbg_screendump },
2421 #endif
2422 #ifndef SIMULATOR
2423 { "View HW info", dbg_hw_info },
2424 #endif
2425 #ifndef SIMULATOR
2426 { "View partitions", dbg_partitions },
2427 #endif
2428 #ifndef SIMULATOR
2429 #ifdef HAVE_MMC
2430 { "View MMC info", dbg_mmc_info },
2431 #else
2432 { "View disk info", dbg_disk_info },
2433 #endif
2434 #endif
2435 #ifdef HAVE_DIRCACHE
2436 { "View dircache info", dbg_dircache_info },
2437 #endif
2438 #ifdef HAVE_LCD_BITMAP
2439 #ifdef HAVE_TAGCACHE
2440 { "View database info", dbg_tagcache_info },
2441 #endif
2442 #if CONFIG_CODEC == SWCODEC || !defined(SIMULATOR)
2443 { "View audio thread", dbg_audio_thread },
2444 #endif
2445 #ifdef PM_DEBUG
2446 { "pm histogram", peak_meter_histogram},
2447 #endif /* PM_DEBUG */
2448 #endif /* HAVE_LCD_BITMAP */
2449 #ifndef SIMULATOR
2450 #if CONFIG_TUNER
2451 { "FM Radio", dbg_fm_radio },
2452 #endif
2453 #endif
2454 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2455 { "Write back EEPROM", dbg_write_eeprom },
2456 #endif
2457 #ifdef ROCKBOX_HAS_LOGF
2458 {"logf", logfdisplay },
2459 {"logfdump", logfdump },
2460 #endif
2461 #ifdef CPU_BOOST_LOGGING
2462 {"cpu_boost log",cpu_boost_log},
2463 #endif
2466 m=menu_init( items, sizeof items / sizeof(struct menu_item), NULL,
2467 NULL, NULL, NULL);
2468 result = menu_run(m);
2469 menu_exit(m);
2471 return result;