Update several codec Makefiles so that the codec libs build again on Coldfire targets...
[Rockbox.git] / apps / debug_menu.c
blob47a2042eff62f3c3b8f0429bb615028b75950c09
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 #ifdef CONFIG_TUNER
64 #include "tuner.h"
65 #include "radio.h"
66 #endif
67 #endif
69 #ifdef HAVE_LCD_BITMAP
70 #include "widgets.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 #endif
79 #ifdef IAUDIO_X5
80 #include "lcd-remote-target.h"
81 #endif
83 /*---------------------------------------------------*/
84 /* SPECIAL DEBUG STUFF */
85 /*---------------------------------------------------*/
86 extern char ata_device;
87 extern int ata_io_address;
88 extern struct core_entry cores[NUM_CORES];
90 char thread_status_char(int status)
92 switch (status)
94 case STATE_RUNNING : return 'R';
95 case STATE_BLOCKED : return 'B';
96 case STATE_SLEEPING : return 'S';
97 case STATE_BLOCKED_W_TMO: return 'T';
100 return '?';
102 #ifndef SIMULATOR
103 #ifdef HAVE_LCD_BITMAP
104 /* Test code!!! */
105 bool dbg_os(void)
107 struct thread_entry *thread;
108 char buf[32];
109 int i;
110 int usage;
111 int status;
112 #if NUM_CORES > 1
113 unsigned int core;
114 int line;
115 #endif
117 lcd_setmargins(0, 0);
118 lcd_setfont(FONT_SYSFIXED);
119 lcd_clear_display();
121 while(1)
123 #if 0 /* Enable to simulate UI lag. */
124 int _x;
125 for (_x = 0; _x < 1000000L; _x++) ;
126 #endif
127 #if NUM_CORES > 1
128 lcd_puts(0, 0, "Core and stack usage:");
129 line = 0;
130 for(core = 0; core < NUM_CORES; core++)
132 for(i = 0; i < MAXTHREADS; i++)
134 thread = &cores[core].threads[i];
135 if (thread->name == NULL)
136 continue;
138 usage = thread_stack_usage(thread);
139 status = thread_get_status(thread);
141 snprintf(buf, 32, "(%d) %c%c %d %s: %d%%", core,
142 (status == STATE_RUNNING) ? '*' : ' ',
143 thread_status_char(status),
144 cores[CURRENT_CORE].threads[i].priority,
145 cores[core].threads[i].name, usage);
146 lcd_puts(0, ++line, buf);
149 #else
150 lcd_puts(0, 0, "Stack usage:");
151 for(i = 0; i < MAXTHREADS; i++)
153 thread = &cores[CURRENT_CORE].threads[i];
154 if (thread->name == NULL)
155 continue;
157 usage = thread_stack_usage(thread);
158 status = thread_get_status(thread);
159 # ifdef HAVE_PRIORITY_SCHEDULING
160 snprintf(buf, 32, "%c%c %d %s: %d%%",
161 (status == STATE_RUNNING) ? '*' : ' ',
162 thread_status_char(status),
163 cores[CURRENT_CORE].threads[i].priority,
164 cores[CURRENT_CORE].threads[i].name, usage);
165 # else
166 snprintf(buf, 32, "%c%c %s: %d%%",
167 (status == STATE_RUNNING) ? '*' : ' ',
168 (status == STATE_BLOCKED) ? 'B' : ' ',
169 cores[CURRENT_CORE].threads[i].name, usage);
170 # endif
171 lcd_puts(0, 1+i, buf);
173 #endif
175 lcd_update();
177 if (action_userabort(HZ/10))
178 return false;
180 return false;
182 #else /* !HAVE_LCD_BITMAP */
183 bool dbg_os(void)
185 char buf[32];
186 int button;
187 int usage;
188 int currval = 0;
190 lcd_clear_display();
192 while(1)
194 lcd_puts(0, 0, "Stack usage");
196 /* Only Archos Player uses this - so assume a single core */
197 usage = thread_stack_usage(&cores[CPU].threads[currval]);
198 snprintf(buf, 32, "%d: %d%% ", currval, usage);
199 lcd_puts(0, 1, buf);
201 button = get_action(CONTEXT_SETTINGS,HZ/10);
203 switch(button)
205 case ACTION_STD_CANCEL:
206 action_signalscreenchange();
207 return false;
209 case ACTION_SETTINGS_DEC:
210 currval--;
211 if(currval < 0)
212 currval = MAXTHREADS-1;
213 break;
215 case ACTION_SETTINGS_INC:
216 currval++;
217 if(currval > MAXTHREADS-1)
218 currval = 0;
219 break;
222 return false;
224 #endif /* !HAVE_LCD_BITMAP */
225 #endif /* !SIMULATOR */
226 #ifdef HAVE_LCD_BITMAP
227 #if CONFIG_CODEC != SWCODEC
228 #ifndef SIMULATOR
229 bool dbg_audio_thread(void)
231 char buf[32];
232 struct audio_debug d;
234 lcd_setmargins(0, 0);
235 lcd_setfont(FONT_SYSFIXED);
237 while(1)
239 if (action_userabort(HZ/5))
240 return false;
242 audio_get_debugdata(&d);
244 lcd_clear_display();
246 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
247 lcd_puts(0, 0, buf);
248 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
249 lcd_puts(0, 1, buf);
250 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
251 lcd_puts(0, 2, buf);
252 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
253 lcd_puts(0, 3, buf);
254 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
255 lcd_puts(0, 4, buf);
256 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
257 lcd_puts(0, 5, buf);
259 /* Playable space left */
260 scrollbar(0, 6*8, 112, 4, d.audiobuflen, 0,
261 d.playable_space, HORIZONTAL);
263 /* Show the watermark limit */
264 scrollbar(0, 6*8+4, 112, 4, d.audiobuflen, 0,
265 d.low_watermark_level, HORIZONTAL);
267 snprintf(buf, sizeof(buf), "wm: %x - %x",
268 d.low_watermark_level, d.lowest_watermark_level);
269 lcd_puts(0, 7, buf);
271 lcd_update();
273 return false;
275 #endif /* !SIMULATOR */
276 #else /* CONFIG_CODEC == SWCODEC */
277 extern size_t filebuflen;
278 /* This is a size_t, but call it a long so it puts a - when it's bad. */
280 static unsigned int ticks, boost_ticks;
282 void dbg_audio_task(void)
284 #ifndef SIMULATOR
285 if(FREQ > CPUFREQ_NORMAL)
286 boost_ticks++;
287 #endif
289 ticks++;
292 bool dbg_audio_thread(void)
294 char buf[32];
295 int button;
296 int line;
297 bool done = false;
298 size_t bufused;
299 size_t bufsize = pcmbuf_get_bufsize();
300 int pcmbufdescs = pcmbuf_descs();
302 ticks = boost_ticks = 0;
304 tick_add_task(dbg_audio_task);
306 lcd_setmargins(0, 0);
307 lcd_setfont(FONT_SYSFIXED);
308 while(!done)
310 button = get_action(CONTEXT_STD,HZ/5);
311 switch(button)
313 case ACTION_STD_NEXT:
314 audio_next();
315 break;
316 case ACTION_STD_PREV:
317 audio_prev();
318 break;
319 case ACTION_STD_CANCEL:
320 done = true;
321 break;
323 action_signalscreenchange();
324 line = 0;
326 lcd_clear_display();
328 bufused = bufsize - pcmbuf_free();
330 snprintf(buf, sizeof(buf), "pcm: %7ld/%7ld", (long) bufused, (long) bufsize);
331 lcd_puts(0, line++, buf);
333 /* Playable space left */
334 scrollbar(0, line*8, LCD_WIDTH, 6, bufsize, 0, bufused, HORIZONTAL);
335 line++;
337 snprintf(buf, sizeof(buf), "codec: %8ld/%8ld", audio_filebufused(), (long) filebuflen);
338 lcd_puts(0, line++, buf);
340 /* Playable space left */
341 scrollbar(0, line*8, LCD_WIDTH, 6, filebuflen, 0,
342 audio_filebufused(), HORIZONTAL);
343 line++;
345 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
346 lcd_puts(0, line++, buf);
348 #ifndef SIMULATOR
349 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
350 (int)((FREQ + 500000) / 1000000));
351 lcd_puts(0, line++, buf);
352 #endif
354 snprintf(buf, sizeof(buf), "boost ratio: %3d%%",
355 boost_ticks * 100 / ticks);
356 lcd_puts(0, line++, buf);
358 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
359 pcmbuf_used_descs(), pcmbufdescs);
360 lcd_puts(0, line++, buf);
362 lcd_update();
365 tick_remove_task(dbg_audio_task);
367 return false;
369 #endif /* CONFIG_CODEC */
370 #endif /* HAVE_LCD_BITMAP */
373 #if CONFIG_CPU == TCC730
374 static unsigned flash_word_temp IDATA_ATTR;
376 static void flash_write_word(unsigned addr, unsigned value) ICODE_ATTR;
377 static void flash_write_word(unsigned addr, unsigned value) {
378 flash_word_temp = value;
380 long extAddr = (long)addr << 1;
381 ddma_transfer(1, 1, &flash_word_temp, extAddr, 2);
384 static unsigned flash_read_word(unsigned addr) ICODE_ATTR;
385 static unsigned flash_read_word(unsigned addr) {
386 long extAddr = (long)addr << 1;
387 ddma_transfer(1, 1, &flash_word_temp, extAddr, 2);
388 return flash_word_temp;
391 #endif
393 #ifndef SIMULATOR
394 /* Tool function to read the flash manufacturer and type, if available.
395 Only chips which could be reprogrammed in system will return values.
396 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
397 /* In IRAM to avoid problems when running directly from Flash */
398 bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
399 unsigned addr1, unsigned addr2)
400 ICODE_ATTR;
401 bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
402 unsigned addr1, unsigned addr2)
405 #if (CONFIG_CPU == PP5002) || (CONFIG_CPU == PP5020)
406 /* TODO: Implement for iPod */
407 (void)p_manufacturer;
408 (void)p_device;
409 (void)addr1;
410 (void)addr2;
411 #elif CONFIG_CPU == PNX0101
412 /* TODO: Implement for iFP7xx */
413 (void)p_manufacturer;
414 (void)p_device;
415 (void)addr1;
416 (void)addr2;
417 #elif CONFIG_CPU == S3C2440
418 /* TODO: Implement for Gigabeat */
419 (void)p_manufacturer;
420 (void)p_device;
421 (void)addr1;
422 (void)addr2;
423 #else
424 unsigned not_manu, not_id; /* read values before switching to ID mode */
425 unsigned manu, id; /* read values when in ID mode */
426 #if CONFIG_CPU == TCC730
427 #define FLASH(addr) (flash_read_word(addr))
428 #define SET_FLASH(addr, val) (flash_write_word((addr), (val)))
430 #else /* memory mapped */
431 #if CONFIG_CPU == SH7034
432 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
433 #elif defined(CPU_COLDFIRE)
434 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
435 #endif
436 #define FLASH(addr) (flash[addr])
437 #define SET_FLASH(addr, val) (flash[addr] = val)
438 #endif
439 int old_level; /* saved interrupt level */
441 not_manu = FLASH(0); /* read the normal content */
442 not_id = FLASH(1); /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
444 /* disable interrupts, prevent any stray flash access */
445 old_level = set_irq_level(HIGHEST_IRQ_LEVEL);
447 SET_FLASH(addr1, 0xAA); /* enter command mode */
448 SET_FLASH(addr2, 0x55);
449 SET_FLASH(addr1, 0x90); /* ID command */
450 /* Atmel wants 20ms pause here */
451 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
453 manu = FLASH(0); /* read the IDs */
454 id = FLASH(1);
456 SET_FLASH(0, 0xF0); /* reset flash (back to normal read mode) */
457 /* Atmel wants 20ms pause here */
458 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
460 set_irq_level(old_level); /* enable interrupts again */
462 /* I assume success if the obtained values are different from
463 the normal flash content. This is not perfectly bulletproof, they
464 could theoretically be the same by chance, causing us to fail. */
465 if (not_manu != manu || not_id != id) /* a value has changed */
467 *p_manufacturer = manu; /* return the results */
468 *p_device = id;
469 return true; /* success */
471 #endif
472 return false; /* fail */
474 #endif /* !SIMULATOR */
476 #ifndef SIMULATOR
477 #ifdef HAVE_LCD_BITMAP
478 bool dbg_hw_info(void)
480 #if CONFIG_CPU == SH7034
481 char buf[32];
482 int usb_polarity;
483 int pr_polarity;
484 int bitmask = *(unsigned short*)0x20000fc;
485 int rom_version = *(unsigned short*)0x20000fe;
486 unsigned manu, id; /* flash IDs */
487 bool got_id; /* flag if we managed to get the flash IDs */
488 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
489 bool has_bootrom; /* flag for boot ROM present */
490 int oldmode; /* saved memory guard mode */
492 #ifdef USB_ENABLE_ONDIOSTYLE
493 if(PADRL & 0x20)
494 #else
495 if(PADRH & 0x04)
496 #endif
497 usb_polarity = 0; /* Negative */
498 else
499 usb_polarity = 1; /* Positive */
501 if(PADRH & 0x08)
502 pr_polarity = 0; /* Negative */
503 else
504 pr_polarity = 1; /* Positive */
506 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
508 /* get flash ROM type */
509 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
510 if (!got_id)
511 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
513 /* check if the boot ROM area is a flash mirror */
514 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
515 if (has_bootrom) /* if ROM and Flash different */
517 /* calculate CRC16 checksum of boot ROM */
518 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
521 system_memory_guard(oldmode); /* re-enable memory guard */
523 lcd_setmargins(0, 0);
524 lcd_setfont(FONT_SYSFIXED);
525 lcd_clear_display();
527 lcd_puts(0, 0, "[Hardware info]");
529 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
530 lcd_puts(0, 1, buf);
532 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
533 lcd_puts(0, 2, buf);
535 snprintf(buf, 32, "USB: %s", usb_polarity?"positive":"negative");
536 lcd_puts(0, 3, buf);
538 snprintf(buf, 32, "PR: %s", pr_polarity?"positive":"negative");
539 lcd_puts(0, 4, buf);
541 if (got_id)
542 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
543 else
544 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
545 lcd_puts(0, 5, buf);
547 if (has_bootrom)
549 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
550 snprintf(buf, 32, "Boot ROM: V1");
551 else
552 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
554 else
556 snprintf(buf, 32, "Boot ROM: none");
558 lcd_puts(0, 6, buf);
560 #ifndef HAVE_MMC /* have ATA */
561 snprintf(buf, 32, "ATA: 0x%x,%s", ata_io_address,
562 ata_device ? "slave":"master");
563 lcd_puts(0, 7, buf);
564 #endif
565 lcd_update();
567 while(1)
569 if (action_userabort(TIMEOUT_BLOCK))
570 return false;
572 #elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
573 char buf[32];
574 unsigned manu, id; /* flash IDs */
575 bool got_id; /* flag if we managed to get the flash IDs */
576 int oldmode; /* saved memory guard mode */
578 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
580 /* get flash ROM type */
581 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
582 if (!got_id)
583 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
585 system_memory_guard(oldmode); /* re-enable memory guard */
587 lcd_setmargins(0, 0);
588 lcd_setfont(FONT_SYSFIXED);
589 lcd_clear_display();
591 lcd_puts(0, 0, "[Hardware info]");
593 if (got_id)
594 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
595 else
596 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
597 lcd_puts(0, 1, buf);
599 lcd_update();
601 while(1)
603 if (action_userabort(TIMEOUT_BLOCK))
604 return false;
606 #elif CONFIG_CPU == PP5020
607 char buf[32];
609 lcd_setmargins(0, 0);
610 lcd_setfont(FONT_SYSFIXED);
611 lcd_clear_display();
613 lcd_puts(0, 0, "[Hardware info]");
615 snprintf(buf, sizeof(buf), "HW rev: 0x%08x", ipod_hw_rev);
616 lcd_puts(0, 1, 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 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 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;
805 lcd_setmargins(0, 0);
806 lcd_clear_display();
807 lcd_setfont(FONT_SYSFIXED);
808 #ifdef HAVE_SPDIF_POWER
809 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
810 #endif
811 PHASECONFIG = 0x34; /* Gain = 3*2^13, source = EBUIN */
813 while (!done)
815 line = 0;
817 control = EBU1RCVCCHANNEL1;
818 interruptstat = INTERRUPTSTAT;
819 INTERRUPTCLEAR = 0x03c00000;
821 valnogood = (interruptstat & 0x01000000)?true:false;
822 symbolerr = (interruptstat & 0x00800000)?true:false;
823 parityerr = (interruptstat & 0x00400000)?true:false;
825 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
826 valnogood?"--":"OK",
827 symbolerr?"--":"OK",
828 parityerr?"--":"OK");
829 lcd_puts(0, line++, buf);
831 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
832 lcd_puts(0, line++, buf);
834 line++;
836 x = control >> 31;
837 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
838 x, x?"Professional":"Consumer");
839 lcd_puts(0, line++, buf);
841 x = (control >> 30) & 1;
842 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
843 x, x?"Non-PCM":"PCM");
844 lcd_puts(0, line++, buf);
846 x = (control >> 29) & 1;
847 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
848 x, x?"Permitted":"Inhibited");
849 lcd_puts(0, line++, buf);
851 x = (control >> 27) & 7;
852 switch(x)
854 case 0:
855 s = "None";
856 break;
857 case 1:
858 s = "50/15us";
859 break;
860 default:
861 s = "Reserved";
862 break;
864 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
865 lcd_puts(0, line++, buf);
867 x = (control >> 24) & 3;
868 snprintf(buf, sizeof(buf), "Mode: %d", x);
869 lcd_puts(0, line++, buf);
871 category = (control >> 17) & 127;
872 switch(category)
874 case 0x00:
875 s = "General";
876 break;
877 case 0x40:
878 s = "Audio CD";
879 break;
880 default:
881 s = "Unknown";
883 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
884 lcd_puts(0, line++, buf);
886 x = (control >> 16) & 1;
887 generation = x;
888 if(((category & 0x70) == 0x10) ||
889 ((category & 0x70) == 0x40) ||
890 ((category & 0x78) == 0x38))
892 generation = !generation;
894 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
895 x, generation?"Original":"No ind.");
896 lcd_puts(0, line++, buf);
898 x = (control >> 12) & 15;
899 snprintf(buf, sizeof(buf), "Source: %d", x);
900 lcd_puts(0, line++, buf);
902 x = (control >> 8) & 15;
903 switch(x)
905 case 0:
906 s = "Unspecified";
907 break;
908 case 8:
909 s = "A (Left)";
910 break;
911 case 4:
912 s = "B (Right)";
913 break;
914 default:
915 s = "";
916 break;
918 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
919 lcd_puts(0, line++, buf);
921 x = (control >> 4) & 15;
922 switch(x)
924 case 0:
925 s = "44.1kHz";
926 break;
927 case 0x4:
928 s = "48kHz";
929 break;
930 case 0xc:
931 s = "32kHz";
932 break;
934 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
935 lcd_puts(0, line++, buf);
937 x = (control >> 2) & 3;
938 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
939 lcd_puts(0, line++, buf);
940 line++;
942 #ifndef SIMULATOR
943 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
944 (long)((long long)FREQMEAS*CPU_FREQ/((1 << 15)*3*(1 << 13))/128));
945 lcd_puts(0, line++, buf);
946 #endif
948 lcd_update();
950 if (action_userabort(HZ/10))
951 return false;
953 #ifdef HAVE_SPDIF_POWER
954 spdif_power_enable(global_settings.spdif_enable);
955 #endif
957 return false;
959 #endif /* CPU_COLDFIRE */
961 #ifndef SIMULATOR
962 #ifdef HAVE_LCD_BITMAP
963 /* Test code!!! */
964 bool dbg_ports(void)
966 #if CONFIG_CPU == SH7034
967 unsigned short porta;
968 unsigned short portb;
969 unsigned char portc;
970 char buf[32];
971 int adc_battery_voltage, adc_battery_level;
973 lcd_setfont(FONT_SYSFIXED);
974 lcd_setmargins(0, 0);
975 lcd_clear_display();
977 while(1)
979 porta = PADR;
980 portb = PBDR;
981 portc = PCDR;
983 snprintf(buf, 32, "PADR: %04x", porta);
984 lcd_puts(0, 0, buf);
985 snprintf(buf, 32, "PBDR: %04x", portb);
986 lcd_puts(0, 1, buf);
988 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
989 lcd_puts(0, 2, buf);
990 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
991 lcd_puts(0, 3, buf);
992 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
993 lcd_puts(0, 4, buf);
994 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
995 lcd_puts(0, 5, buf);
997 battery_read_info(NULL, &adc_battery_voltage,
998 &adc_battery_level);
999 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100,
1000 adc_battery_voltage % 100, adc_battery_level);
1001 lcd_puts(0, 6, buf);
1002 #ifndef HAVE_MMC /* have ATA */
1003 snprintf(buf, 32, "ATA: %s, 0x%x",
1004 ata_device?"slave":"master", ata_io_address);
1005 lcd_puts(0, 7, buf);
1006 #endif
1007 lcd_update();
1008 if (action_userabort(HZ/10))
1009 return false;
1011 #elif defined(CPU_COLDFIRE)
1012 unsigned int gpio_out;
1013 unsigned int gpio1_out;
1014 unsigned int gpio_read;
1015 unsigned int gpio1_read;
1016 unsigned int gpio_function;
1017 unsigned int gpio1_function;
1018 unsigned int gpio_enable;
1019 unsigned int gpio1_enable;
1020 int adc_buttons, adc_remote;
1021 int adc_battery, adc_battery_voltage, adc_battery_level;
1022 char buf[128];
1023 int line;
1025 lcd_setmargins(0, 0);
1026 lcd_clear_display();
1027 lcd_setfont(FONT_SYSFIXED);
1029 while(1)
1031 line = 0;
1032 gpio_read = GPIO_READ;
1033 gpio1_read = GPIO1_READ;
1034 gpio_out = GPIO_OUT;
1035 gpio1_out = GPIO1_OUT;
1036 gpio_function = GPIO_FUNCTION;
1037 gpio1_function = GPIO1_FUNCTION;
1038 gpio_enable = GPIO_ENABLE;
1039 gpio1_enable = GPIO1_ENABLE;
1041 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
1042 lcd_puts(0, line++, buf);
1043 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
1044 lcd_puts(0, line++, buf);
1045 snprintf(buf, sizeof(buf), "GPIO_FUNCTION: %08x", gpio_function);
1046 lcd_puts(0, line++, buf);
1047 snprintf(buf, sizeof(buf), "GPIO_ENABLE: %08x", gpio_enable);
1048 lcd_puts(0, line++, buf);
1050 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
1051 lcd_puts(0, line++, buf);
1052 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
1053 lcd_puts(0, line++, buf);
1054 snprintf(buf, sizeof(buf), "GPIO1_FUNCTION: %08x", gpio1_function);
1055 lcd_puts(0, line++, buf);
1056 snprintf(buf, sizeof(buf), "GPIO1_ENABLE: %08x", gpio1_enable);
1057 lcd_puts(0, line++, buf);
1059 adc_buttons = adc_read(ADC_BUTTONS);
1060 adc_remote = adc_read(ADC_REMOTE);
1061 battery_read_info(&adc_battery, &adc_battery_voltage,
1062 &adc_battery_level);
1063 #if defined(IAUDIO_X5) || defined(IRIVER_H300_SERIES)
1064 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
1065 button_scan_enabled() ? '+' : '-', adc_buttons);
1066 #else
1067 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1068 #endif
1069 lcd_puts(0, line++, buf);
1070 #ifdef IAUDIO_X5
1071 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1072 remote_detect() ? '+' : '-', adc_remote);
1073 #else
1074 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
1075 #endif
1077 lcd_puts(0, line++, buf);
1078 snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_battery);
1079 lcd_puts(0, line++, buf);
1080 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1081 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1082 adc_read(ADC_REMOTEDETECT));
1083 lcd_puts(0, line++, buf);
1084 #endif
1086 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100,
1087 adc_battery_voltage % 100, adc_battery_level);
1088 lcd_puts(0, line++, buf);
1090 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
1091 snprintf(buf, sizeof(buf), "remotetype:: %d", remote_type());
1092 lcd_puts(0, line++, buf);
1093 #endif
1095 lcd_update();
1096 if (action_userabort(HZ/10))
1097 return false;
1100 #elif CONFIG_CPU == PP5020
1102 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1103 unsigned int gpio_e, gpio_f, gpio_g, gpio_h;
1104 unsigned int gpio_i, gpio_j, gpio_k, gpio_l;
1106 char buf[128];
1107 int line;
1109 lcd_setmargins(0, 0);
1110 lcd_clear_display();
1111 lcd_setfont(FONT_SYSFIXED);
1113 while(1)
1115 gpio_a = GPIOA_INPUT_VAL;
1116 gpio_b = GPIOB_INPUT_VAL;
1117 gpio_c = GPIOC_INPUT_VAL;
1119 gpio_g = GPIOG_INPUT_VAL;
1120 gpio_h = GPIOH_INPUT_VAL;
1121 gpio_i = GPIOI_INPUT_VAL;
1123 line = 0;
1124 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_G: %02x", gpio_a, gpio_g);
1125 lcd_puts(0, line++, buf);
1126 snprintf(buf, sizeof(buf), "GPIO_B: %02x GPIO_H: %02x", gpio_b, gpio_h);
1127 lcd_puts(0, line++, buf);
1128 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_I: %02x", gpio_c, gpio_i);
1129 lcd_puts(0, line++, buf);
1130 line++;
1132 gpio_d = GPIOD_INPUT_VAL;
1133 gpio_e = GPIOE_INPUT_VAL;
1134 gpio_f = GPIOF_INPUT_VAL;
1136 gpio_j = GPIOJ_INPUT_VAL;
1137 gpio_k = GPIOK_INPUT_VAL;
1138 gpio_l = GPIOL_INPUT_VAL;
1140 snprintf(buf, sizeof(buf), "GPIO_D: %02x GPIO_J: %02x", gpio_d, gpio_j);
1141 lcd_puts(0, line++, buf);
1142 snprintf(buf, sizeof(buf), "GPIO_E: %02x GPIO_K: %02x", gpio_e, gpio_k);
1143 lcd_puts(0, line++, buf);
1144 snprintf(buf, sizeof(buf), "GPIO_F: %02x GPIO_L: %02x", gpio_f, gpio_l);
1145 lcd_puts(0, line++, buf);
1146 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1147 line++;
1148 snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_read(ADC_BATTERY));
1149 lcd_puts(0, line++, buf);
1150 snprintf(buf, sizeof(buf), "ADC_UNKNOWN_1: %02x", adc_read(ADC_UNKNOWN_1));
1151 lcd_puts(0, line++, buf);
1152 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_read(ADC_REMOTE));
1153 lcd_puts(0, line++, buf);
1154 snprintf(buf, sizeof(buf), "ADC_SCROLLPAD: %02x", adc_read(ADC_SCROLLPAD));
1155 lcd_puts(0, line++, buf);
1156 #endif
1157 lcd_update();
1158 if (action_userabort(HZ/10))
1159 return false;
1162 #elif CONFIG_CPU == PP5002
1163 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1165 char buf[128];
1166 int line;
1168 lcd_setmargins(0, 0);
1169 lcd_clear_display();
1170 lcd_setfont(FONT_SYSFIXED);
1172 while(1)
1174 gpio_a = GPIOA_INPUT_VAL;
1175 gpio_b = GPIOB_INPUT_VAL;
1176 gpio_c = GPIOC_INPUT_VAL;
1177 gpio_d = GPIOD_INPUT_VAL;
1179 line = 0;
1180 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x", gpio_a, gpio_b);
1181 lcd_puts(0, line++, buf);
1182 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x", gpio_c, gpio_d);
1183 lcd_puts(0, line++, buf);
1185 lcd_update();
1186 if (action_userabort(HZ/10))
1187 return false;
1189 #endif /* CPU */
1190 return false;
1192 #else /* !HAVE_LCD_BITMAP */
1193 bool dbg_ports(void)
1195 unsigned short porta;
1196 unsigned short portb;
1197 unsigned char portc;
1198 char buf[32];
1199 int button;
1200 int adc_battery_voltage;
1201 int currval = 0;
1203 lcd_clear_display();
1205 while(1)
1207 porta = PADR;
1208 portb = PBDR;
1209 portc = PCDR;
1211 switch(currval)
1213 case 0:
1214 snprintf(buf, 32, "PADR: %04x ", porta);
1215 break;
1216 case 1:
1217 snprintf(buf, 32, "PBDR: %04x ", portb);
1218 break;
1219 case 2:
1220 snprintf(buf, 32, "AN0: %03x ", adc_read(0));
1221 break;
1222 case 3:
1223 snprintf(buf, 32, "AN1: %03x ", adc_read(1));
1224 break;
1225 case 4:
1226 snprintf(buf, 32, "AN2: %03x ", adc_read(2));
1227 break;
1228 case 5:
1229 snprintf(buf, 32, "AN3: %03x ", adc_read(3));
1230 break;
1231 case 6:
1232 snprintf(buf, 32, "AN4: %03x ", adc_read(4));
1233 break;
1234 case 7:
1235 snprintf(buf, 32, "AN5: %03x ", adc_read(5));
1236 break;
1237 case 8:
1238 snprintf(buf, 32, "AN6: %03x ", adc_read(6));
1239 break;
1240 case 9:
1241 snprintf(buf, 32, "AN7: %03x ", adc_read(7));
1242 break;
1243 case 10:
1244 snprintf(buf, 32, "%s, 0x%x ",
1245 ata_device?"slv":"mst", ata_io_address);
1246 break;
1248 lcd_puts(0, 0, buf);
1250 battery_read_info(NULL, &adc_battery_voltage, NULL);
1251 snprintf(buf, 32, "Batt: %d.%02dV", adc_battery_voltage / 100,
1252 adc_battery_voltage % 100);
1253 lcd_puts(0, 1, buf);
1255 button = get_action(CONTEXT_SETTINGS,HZ/5);
1257 switch(button)
1259 case ACTION_STD_CANCEL:
1260 action_signalscreenchange();
1261 return false;
1263 case ACTION_SETTINGS_DEC:
1264 currval--;
1265 if(currval < 0)
1266 currval = 10;
1267 break;
1269 case ACTION_SETTINGS_INC:
1270 currval++;
1271 if(currval > 10)
1272 currval = 0;
1273 break;
1276 return false;
1278 #endif /* !HAVE_LCD_BITMAP */
1279 #endif /* !SIMULATOR */
1281 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
1282 bool dbg_cpufreq(void)
1284 char buf[128];
1285 int line;
1286 int button;
1288 #ifdef HAVE_LCD_BITMAP
1289 lcd_setmargins(0, 0);
1290 lcd_setfont(FONT_SYSFIXED);
1291 #endif
1292 lcd_clear_display();
1294 while(1)
1296 line = 0;
1298 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1299 lcd_puts(0, line++, buf);
1301 #ifdef CPU_BOOST_TRACKING
1302 snprintf(buf, sizeof(buf), "boost_counter: %d %s", get_cpu_boost_counter(), get_cpu_boost_tracker());
1303 #else
1304 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
1305 #endif
1306 lcd_puts(0, line++, buf);
1308 lcd_update();
1309 button = get_action(CONTEXT_STD,HZ/10);
1311 switch(button)
1313 case ACTION_STD_PREV:
1314 cpu_boost_id(true, CPUBOOSTID_DEBUGMENU_MANUAL);
1315 break;
1317 case ACTION_STD_NEXT:
1318 cpu_boost_id(false, CPUBOOSTID_DEBUGMENU_MANUAL);
1319 break;
1321 case ACTION_STD_OK:
1322 while (get_cpu_boost_counter() > 0)
1323 cpu_boost_id(false, CPUBOOSTID_DEBUGMENU_MANUAL);
1324 break;
1326 case ACTION_STD_CANCEL:
1327 action_signalscreenchange();
1328 return false;
1332 return false;
1334 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
1336 #ifndef SIMULATOR
1337 #ifdef HAVE_LCD_BITMAP
1339 * view_battery() shows a automatically scaled graph of the battery voltage
1340 * over time. Usable for estimating battery life / charging rate.
1341 * The power_history array is updated in power_thread of powermgmt.c.
1344 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
1345 #define BAT_YSPACE (LCD_HEIGHT - 20)
1347 bool view_battery(void)
1349 int view = 0;
1350 int i, x, y;
1351 unsigned short maxv, minv;
1352 char buf[32];
1354 lcd_setmargins(0, 0);
1355 lcd_setfont(FONT_SYSFIXED);
1357 while(1)
1359 switch (view) {
1360 case 0: /* voltage history graph */
1361 /* Find maximum and minimum voltage for scaling */
1362 maxv = 0;
1363 minv = 65535;
1364 for (i = 0; i < BAT_LAST_VAL; i++) {
1365 if (power_history[i] > maxv)
1366 maxv = power_history[i];
1367 if (power_history[i] && (power_history[i] < minv))
1369 minv = power_history[i];
1373 if ((minv < 1) || (minv >= 65535))
1374 minv = 1;
1375 if (maxv < 2)
1376 maxv = 2;
1377 if (minv == maxv)
1378 maxv < 65535 ? maxv++ : minv--;
1380 lcd_clear_display();
1381 snprintf(buf, 30, "Battery %d.%02d", power_history[0] / 100,
1382 power_history[0] % 100);
1383 lcd_puts(0, 0, buf);
1384 snprintf(buf, 30, "scale %d.%02d-%d.%02d V",
1385 minv / 100, minv % 100, maxv / 100, maxv % 100);
1386 lcd_puts(0, 1, buf);
1388 x = 0;
1389 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
1390 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
1391 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
1392 lcd_vline(x, LCD_HEIGHT-1, 20);
1393 lcd_set_drawmode(DRMODE_SOLID);
1394 lcd_vline(x, LCD_HEIGHT-1,
1395 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
1396 x++;
1399 break;
1401 case 1: /* status: */
1402 lcd_clear_display();
1403 lcd_puts(0, 0, "Power status:");
1405 battery_read_info(NULL, &y, NULL);
1406 snprintf(buf, 30, "Battery: %d.%02d V", y / 100, y % 100);
1407 lcd_puts(0, 1, buf);
1408 #ifdef ADC_EXT_POWER
1409 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000;
1410 snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100);
1411 lcd_puts(0, 2, buf);
1412 #endif
1413 #ifdef CONFIG_CHARGING
1414 #if CONFIG_CHARGING == CHARGING_CONTROL
1415 snprintf(buf, 30, "Chgr: %s %s",
1416 charger_inserted() ? "present" : "absent",
1417 charger_enabled ? "on" : "off");
1418 lcd_puts(0, 3, buf);
1419 snprintf(buf, 30, "short delta: %d", short_delta);
1420 lcd_puts(0, 5, buf);
1421 snprintf(buf, 30, "long delta: %d", long_delta);
1422 lcd_puts(0, 6, buf);
1423 lcd_puts(0, 7, power_message);
1424 #else /* CONFIG_CHARGING != CHARGING_CONTROL */
1425 #if defined IPOD_NANO || defined IPOD_VIDEO
1426 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1427 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1428 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1429 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1430 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1432 snprintf(buf, 30, "USB pwr: %s",
1433 usb_pwr ? "present" : "absent");
1434 lcd_puts(0, 3, buf);
1435 snprintf(buf, 30, "EXT pwr: %s",
1436 ext_pwr ? "present" : "absent");
1437 lcd_puts(0, 4, buf);
1438 snprintf(buf, 30, "Battery: %s",
1439 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
1440 lcd_puts(0, 5, buf);
1441 snprintf(buf, 30, "Dock mode: %s",
1442 dock ? "enabled" : "disabled");
1443 lcd_puts(0, 6, buf);
1444 snprintf(buf, 30, "Headphone: %s",
1445 headphone ? "connected" : "disconnected");
1446 lcd_puts(0, 7, buf);
1447 #else
1448 snprintf(buf, 30, "Charger: %s",
1449 charger_inserted() ? "present" : "absent");
1450 lcd_puts(0, 3, buf);
1451 #endif
1452 #endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1453 #endif /* CONFIG_CHARGING */
1454 break;
1456 case 2: /* voltage deltas: */
1457 lcd_clear_display();
1458 lcd_puts(0, 0, "Voltage deltas:");
1460 for (i = 0; i <= 6; i++) {
1461 y = power_history[i] - power_history[i+i];
1462 snprintf(buf, 30, "-%d min: %s%d.%02d V", i,
1463 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 100,
1464 ((y < 0) ? y * -1 : y ) % 100);
1465 lcd_puts(0, i+1, buf);
1467 break;
1469 case 3: /* remaining time estimation: */
1470 lcd_clear_display();
1472 #if CONFIG_CHARGING == CHARGING_CONTROL
1473 snprintf(buf, 30, "charge_state: %d", charge_state);
1474 lcd_puts(0, 0, buf);
1476 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1477 lcd_puts(0, 1, buf);
1479 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
1480 lcd_puts(0, 2, buf);
1482 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1483 lcd_puts(0, 3, buf);
1485 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1486 lcd_puts(0, 4, buf);
1487 #endif /* CONFIG_CHARGING == CHARGING_CONTROL */
1489 snprintf(buf, 30, "Last PwrHist: %d.%02d V",
1490 power_history[0] / 100,
1491 power_history[0] % 100);
1492 lcd_puts(0, 5, buf);
1494 snprintf(buf, 30, "battery level: %d%%", battery_level());
1495 lcd_puts(0, 6, buf);
1497 snprintf(buf, 30, "Est. remain: %d m", battery_time());
1498 lcd_puts(0, 7, buf);
1499 break;
1502 lcd_update();
1504 switch(get_action(CONTEXT_SETTINGS,HZ/2))
1506 case ACTION_SETTINGS_DEC:
1507 if (view)
1508 view--;
1509 break;
1511 case ACTION_SETTINGS_INC:
1512 if (view < 3)
1513 view++;
1514 break;
1516 case ACTION_STD_CANCEL:
1517 action_signalscreenchange();
1518 return false;
1521 return false;
1524 #endif /* HAVE_LCD_BITMAP */
1525 #endif
1527 static bool view_runtime(void)
1529 char s[32];
1530 bool done = false;
1531 int state = 1;
1533 while(!done)
1535 int y=0;
1536 int t;
1537 int key;
1538 lcd_clear_display();
1539 #ifdef HAVE_LCD_BITMAP
1540 lcd_puts(0, y++, "Running time:");
1541 y++;
1542 #endif
1544 if (state & 1) {
1545 #ifdef CONFIG_CHARGING
1546 if (charger_inserted()
1547 #ifdef HAVE_USB_POWER
1548 || usb_powered()
1549 #endif
1552 global_settings.runtime = 0;
1554 else
1555 #endif
1557 global_settings.runtime += ((current_tick - lasttime) / HZ);
1559 lasttime = current_tick;
1561 t = global_settings.runtime;
1562 lcd_puts(0, y++, "Current time");
1564 else {
1565 t = global_settings.topruntime;
1566 lcd_puts(0, y++, "Top time");
1569 snprintf(s, sizeof(s), "%dh %dm %ds",
1570 t / 3600, (t % 3600) / 60, t % 60);
1571 lcd_puts(0, y++, s);
1572 lcd_update();
1574 /* Wait for a key to be pushed */
1575 key = get_action(CONTEXT_SETTINGS,HZ);
1576 switch(key) {
1577 case ACTION_STD_CANCEL:
1578 done = true;
1579 break;
1581 case ACTION_SETTINGS_INC:
1582 case ACTION_SETTINGS_DEC:
1583 if (state == 1)
1584 state = 2;
1585 else
1586 state = 1;
1587 break;
1589 case ACTION_STD_OK:
1590 lcd_clear_display();
1591 /*NOTE: this needs to be changed to sync splash! */
1592 lcd_puts(0,0,"Clear time?");
1593 lcd_puts(0,1,"PLAY = Yes");
1594 lcd_update();
1595 while (1) {
1596 key = get_action(CONTEXT_STD,TIMEOUT_BLOCK);
1597 if ( key == ACTION_STD_OK ) {
1598 if ( state == 1 )
1599 global_settings.runtime = 0;
1600 else
1601 global_settings.topruntime = 0;
1602 break;
1605 break;
1608 action_signalscreenchange();
1609 return false;
1612 #ifndef SIMULATOR
1613 #ifdef HAVE_MMC
1614 bool dbg_mmc_info(void)
1616 bool done = false;
1617 int currval = 0;
1618 int line;
1619 tCardInfo *card;
1620 unsigned char pbuf[32], pbuf2[32];
1621 unsigned char card_name[7];
1623 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1624 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1625 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1626 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
1627 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1628 "3.1-3.31", "4.0" };
1630 card_name[6] = '\0';
1632 lcd_setmargins(0, 0);
1633 lcd_setfont(FONT_SYSFIXED);
1635 while (!done)
1637 card = mmc_card_info(currval / 2);
1639 line = 0;
1640 lcd_clear_display();
1641 snprintf(pbuf, sizeof(pbuf), "[MMC%d p%d]", currval / 2,
1642 (currval % 2) + 1);
1643 lcd_puts(0, line++, pbuf);
1645 if (card->initialized)
1647 if (!(currval % 2)) /* General info */
1649 int temp;
1651 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1652 snprintf(pbuf, sizeof(pbuf), "%s Rev %d.%d", card_name,
1653 (int) mmc_extract_bits(card->cid, 72, 4),
1654 (int) mmc_extract_bits(card->cid, 76, 4));
1655 lcd_puts(0, line++, pbuf);
1656 snprintf(pbuf, sizeof(pbuf), "Prod: %d/%d",
1657 (int) mmc_extract_bits(card->cid, 112, 4),
1658 (int) mmc_extract_bits(card->cid, 116, 4) + 1997);
1659 lcd_puts(0, line++, pbuf);
1660 snprintf(pbuf, sizeof(pbuf), "Ser#: 0x%08lx",
1661 mmc_extract_bits(card->cid, 80, 32));
1662 lcd_puts(0, line++, pbuf);
1663 snprintf(pbuf, sizeof(pbuf), "M=%02x, O=%04x",
1664 (int) mmc_extract_bits(card->cid, 0, 8),
1665 (int) mmc_extract_bits(card->cid, 8, 16));
1666 lcd_puts(0, line++, pbuf);
1667 temp = mmc_extract_bits(card->csd, 2, 4);
1668 snprintf(pbuf, sizeof(pbuf), "MMC v%s", temp < 5 ?
1669 spec_vers[temp] : "?.?");
1670 lcd_puts(0, line++, pbuf);
1671 snprintf(pbuf, sizeof(pbuf), "Blocks: 0x%06lx", card->numblocks);
1672 lcd_puts(0, line++, pbuf);
1673 snprintf(pbuf, sizeof(pbuf), "Blksz.: %d P:%c%c", card->blocksize,
1674 mmc_extract_bits(card->csd, 48, 1) ? 'R' : '-',
1675 mmc_extract_bits(card->csd, 106, 1) ? 'W' : '-');
1676 lcd_puts(0, line++, pbuf);
1678 else /* Technical details */
1680 output_dyn_value(pbuf2, sizeof pbuf2, card->speed / 1000,
1681 kbit_units, false);
1682 snprintf(pbuf, sizeof pbuf, "Speed: %s", pbuf2);
1683 lcd_puts(0, line++, pbuf);
1685 output_dyn_value(pbuf2, sizeof pbuf2, card->tsac,
1686 nsec_units, false);
1687 snprintf(pbuf, sizeof pbuf, "Tsac: %s", pbuf2);
1688 lcd_puts(0, line++, pbuf);
1690 snprintf(pbuf, sizeof(pbuf), "Nsac: %d clk", card->nsac);
1691 lcd_puts(0, line++, pbuf);
1692 snprintf(pbuf, sizeof(pbuf), "R2W: *%d", card->r2w_factor);
1693 lcd_puts(0, line++, pbuf);
1694 snprintf(pbuf, sizeof(pbuf), "IRmax: %d..%d mA",
1695 i_vmin[mmc_extract_bits(card->csd, 66, 3)],
1696 i_vmax[mmc_extract_bits(card->csd, 69, 3)]);
1697 lcd_puts(0, line++, pbuf);
1698 snprintf(pbuf, sizeof(pbuf), "IWmax: %d..%d mA",
1699 i_vmin[mmc_extract_bits(card->csd, 72, 3)],
1700 i_vmax[mmc_extract_bits(card->csd, 75, 3)]);
1701 lcd_puts(0, line++, pbuf);
1704 else
1705 lcd_puts(0, line++, "Not found!");
1707 lcd_update();
1709 switch (get_action(CONTEXT_SETTINGS,HZ/2))
1711 case ACTION_STD_CANCEL:
1712 done = true;
1713 break;
1715 case ACTION_SETTINGS_DEC:
1716 currval--;
1717 if (currval < 0)
1718 currval = 3;
1719 break;
1721 case ACTION_SETTINGS_INC:
1722 currval++;
1723 if (currval > 3)
1724 currval = 0;
1725 break;
1728 action_signalscreenchange();
1729 return false;
1731 #else /* !HAVE_MMC */
1732 static bool dbg_disk_info(void)
1734 char buf[128];
1735 bool done = false;
1736 int i;
1737 int page = 0;
1738 const int max_page = 11;
1739 unsigned short* identify_info = ata_get_identify();
1740 bool timing_info_present = false;
1741 char pio3[2], pio4[2];
1743 #ifdef HAVE_LCD_BITMAP
1744 lcd_setmargins(0, 0);
1745 #endif
1747 while(!done)
1749 int y=0;
1750 int key;
1751 lcd_clear_display();
1752 #ifdef HAVE_LCD_BITMAP
1753 lcd_puts(0, y++, "Disk info:");
1754 y++;
1755 #endif
1757 switch (page) {
1758 case 0:
1759 for (i=0; i < 20; i++)
1760 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1761 buf[40]=0;
1762 /* kill trailing space */
1763 for (i=39; i && buf[i]==' '; i--)
1764 buf[i] = 0;
1765 lcd_puts(0, y++, "Model");
1766 lcd_puts_scroll(0, y++, buf);
1767 break;
1769 case 1:
1770 for (i=0; i < 4; i++)
1771 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1772 buf[8]=0;
1773 lcd_puts(0, y++, "Firmware");
1774 lcd_puts(0, y++, buf);
1775 break;
1777 case 2:
1778 snprintf(buf, sizeof buf, "%ld MB",
1779 ((unsigned long)identify_info[61] << 16 |
1780 (unsigned long)identify_info[60]) / 2048 );
1781 lcd_puts(0, y++, "Size");
1782 lcd_puts(0, y++, buf);
1783 break;
1785 case 3: {
1786 unsigned long free;
1787 fat_size( IF_MV2(0,) NULL, &free );
1788 snprintf(buf, sizeof buf, "%ld MB", free / 1024 );
1789 lcd_puts(0, y++, "Free");
1790 lcd_puts(0, y++, buf);
1791 break;
1794 case 4:
1795 snprintf(buf, sizeof buf, "%d ms", ata_spinup_time * (1000/HZ));
1796 lcd_puts(0, y++, "Spinup time");
1797 lcd_puts(0, y++, buf);
1798 break;
1800 case 5:
1801 i = identify_info[83] & (1<<3);
1802 lcd_puts(0, y++, "Power mgmt:");
1803 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1804 break;
1806 case 6:
1807 i = identify_info[83] & (1<<9);
1808 lcd_puts(0, y++, "Noise mgmt:");
1809 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1810 break;
1812 case 7:
1813 i = identify_info[82] & (1<<6);
1814 lcd_puts(0, y++, "Read-ahead:");
1815 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1816 break;
1818 case 8:
1819 timing_info_present = identify_info[53] & (1<<1);
1820 if(timing_info_present) {
1821 pio3[1] = 0;
1822 pio4[1] = 0;
1823 lcd_puts(0, y++, "PIO modes:");
1824 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1825 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1826 snprintf(buf, 128, "0 1 2 %s %s", pio3, pio4);
1827 lcd_puts(0, y++, buf);
1828 } else {
1829 lcd_puts(0, y++, "No PIO mode info");
1831 break;
1833 case 9:
1834 timing_info_present = identify_info[53] & (1<<1);
1835 if(timing_info_present) {
1836 lcd_puts(0, y++, "Cycle times");
1837 snprintf(buf, 128, "%dns/%dns",
1838 identify_info[67],
1839 identify_info[68]);
1840 lcd_puts(0, y++, buf);
1841 } else {
1842 lcd_puts(0, y++, "No timing info");
1844 break;
1846 case 10:
1847 timing_info_present = identify_info[53] & (1<<1);
1848 if(timing_info_present) {
1849 i = identify_info[49] & (1<<11);
1850 snprintf(buf, 128, "IORDY support: %s", i ? "yes" : "no");
1851 lcd_puts(0, y++, buf);
1852 i = identify_info[49] & (1<<10);
1853 snprintf(buf, 128, "IORDY disable: %s", i ? "yes" : "no");
1854 lcd_puts(0, y++, buf);
1855 } else {
1856 lcd_puts(0, y++, "No timing info");
1858 break;
1860 case 11:
1861 lcd_puts(0, y++, "Cluster size");
1862 snprintf(buf, 128, "%d bytes", fat_get_cluster_size(IF_MV(0)));
1863 lcd_puts(0, y++, buf);
1864 break;
1866 lcd_update();
1868 /* Wait for a key to be pushed */
1869 key = get_action(CONTEXT_SETTINGS,HZ/5);
1870 switch(key) {
1871 case ACTION_STD_CANCEL:
1872 done = true;
1873 break;
1875 case ACTION_SETTINGS_DEC:
1876 if (--page < 0)
1877 page = max_page;
1878 break;
1880 case ACTION_SETTINGS_INC:
1881 if (++page > max_page)
1882 page = 0;
1883 break;
1885 lcd_stop_scroll();
1887 action_signalscreenchange();
1888 return false;
1890 #endif /* !HAVE_MMC */
1891 #endif /* !SIMULATOR */
1893 #ifdef HAVE_DIRCACHE
1894 static bool dbg_dircache_info(void)
1896 bool done = false;
1897 int line;
1898 char buf[32];
1900 lcd_setmargins(0, 0);
1901 lcd_setfont(FONT_SYSFIXED);
1903 while (!done)
1905 line = 0;
1907 lcd_clear_display();
1908 snprintf(buf, sizeof(buf), "Cache initialized: %s",
1909 dircache_is_enabled() ? "Yes" : "No");
1910 lcd_puts(0, line++, buf);
1912 snprintf(buf, sizeof(buf), "Cache size: %d B",
1913 dircache_get_cache_size());
1914 lcd_puts(0, line++, buf);
1916 snprintf(buf, sizeof(buf), "Last size: %d B",
1917 global_settings.dircache_size);
1918 lcd_puts(0, line++, buf);
1920 snprintf(buf, sizeof(buf), "Limit: %d B", DIRCACHE_LIMIT);
1921 lcd_puts(0, line++, buf);
1923 snprintf(buf, sizeof(buf), "Reserve: %d/%d B",
1924 dircache_get_reserve_used(), DIRCACHE_RESERVE);
1925 lcd_puts(0, line++, buf);
1927 snprintf(buf, sizeof(buf), "Scanning took: %d s",
1928 dircache_get_build_ticks() / HZ);
1929 lcd_puts(0, line++, buf);
1931 snprintf(buf, sizeof(buf), "Entry count: %d",
1932 dircache_get_entry_count());
1933 lcd_puts(0, line++, buf);
1935 lcd_update();
1937 if (action_userabort(HZ/2))
1938 return false;
1941 return false;
1944 #endif /* HAVE_DIRCACHE */
1946 #ifdef HAVE_LCD_BITMAP
1947 #ifdef HAVE_TAGCACHE
1948 static bool dbg_tagcache_info(void)
1950 bool done = false;
1951 int line;
1952 char buf[32];
1953 struct tagcache_stat *stat;
1955 lcd_setmargins(0, 0);
1956 lcd_setfont(FONT_SYSFIXED);
1958 while (!done)
1960 line = 0;
1962 lcd_clear_display();
1963 stat = tagcache_get_stat();
1964 snprintf(buf, sizeof(buf), "Initialized: %s", stat->initialized ? "Yes" : "No");
1965 lcd_puts(0, line++, buf);
1966 snprintf(buf, sizeof(buf), "DB Ready: %s", stat->ready ? "Yes" : "No");
1967 lcd_puts(0, line++, buf);
1968 snprintf(buf, sizeof(buf), "RAM Cache: %s", stat->ramcache ? "Yes" : "No");
1969 lcd_puts(0, line++, buf);
1970 snprintf(buf, sizeof(buf), "RAM: %d/%d B",
1971 stat->ramcache_used, stat->ramcache_allocated);
1972 lcd_puts(0, line++, buf);
1973 snprintf(buf, sizeof(buf), "Progress: %d%% (%d entries)",
1974 stat->progress, stat->processed_entries);
1975 lcd_puts(0, line++, buf);
1976 snprintf(buf, sizeof(buf), "Commit step: %d", stat->commit_step);
1977 lcd_puts(0, line++, buf);
1978 snprintf(buf, sizeof(buf), "Commit delayed: %s",
1979 stat->commit_delayed ? "Yes" : "No");
1980 lcd_puts(0, line++, buf);
1982 lcd_update();
1984 if (action_userabort(HZ/2))
1985 return false;
1988 return false;
1990 #endif
1991 #endif
1993 #if CONFIG_CPU == SH7034
1994 bool dbg_save_roms(void)
1996 int fd;
1997 int oldmode = system_memory_guard(MEMGUARD_NONE);
1999 fd = creat("/internal_rom_0000-FFFF.bin", O_WRONLY);
2000 if(fd >= 0)
2002 write(fd, (void *)0, 0x10000);
2003 close(fd);
2006 fd = creat("/internal_rom_2000000-203FFFF.bin", O_WRONLY);
2007 if(fd >= 0)
2009 write(fd, (void *)0x2000000, 0x40000);
2010 close(fd);
2013 system_memory_guard(oldmode);
2014 return false;
2016 #elif defined CPU_COLDFIRE
2017 bool dbg_save_roms(void)
2019 int fd;
2020 int oldmode = system_memory_guard(MEMGUARD_NONE);
2022 #if defined(IRIVER_H100_SERIES)
2023 fd = creat("/internal_rom_000000-1FFFFF.bin", O_WRONLY);
2024 #elif defined(IRIVER_H300_SERIES)
2025 fd = creat("/internal_rom_000000-3FFFFF.bin", O_WRONLY);
2026 #elif defined(IAUDIO_X5)
2027 fd = creat("/internal_rom_000000-3FFFFF.bin", O_WRONLY);
2028 #endif
2029 if(fd >= 0)
2031 write(fd, (void *)0, FLASH_SIZE);
2032 close(fd);
2034 system_memory_guard(oldmode);
2036 #ifdef HAVE_EEPROM
2037 fd = creat("/internal_eeprom.bin", O_WRONLY);
2038 if (fd >= 0)
2040 int old_irq_level;
2041 char buf[EEPROM_SIZE];
2042 int err;
2044 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
2046 err = eeprom_24cxx_read(0, buf, sizeof buf);
2047 if (err)
2048 gui_syncsplash(HZ*3, true, "Eeprom read failure (%d)",err);
2049 else
2051 write(fd, buf, sizeof buf);
2054 set_irq_level(old_irq_level);
2056 close(fd);
2058 #endif
2060 return false;
2062 #endif /* CPU */
2064 #ifndef SIMULATOR
2065 #ifdef CONFIG_TUNER
2066 bool dbg_fm_radio(void)
2068 char buf[32];
2069 bool fm_detected;
2071 #ifdef HAVE_LCD_BITMAP
2072 lcd_setmargins(0, 0);
2073 #endif
2075 while(1)
2077 int row = 0;
2078 unsigned long regs;
2080 lcd_clear_display();
2081 fm_detected = radio_hardware_present();
2083 snprintf(buf, sizeof buf, "HW detected: %s", fm_detected?"yes":"no");
2084 lcd_puts(0, row++, buf);
2086 #if (CONFIG_TUNER & S1A0903X01)
2087 regs = samsung_get(RADIO_ALL);
2088 snprintf(buf, sizeof buf, "Samsung regs: %08lx", regs);
2089 lcd_puts(0, row++, buf);
2090 #endif
2091 #if (CONFIG_TUNER & TEA5767)
2092 regs = philips_get(RADIO_ALL);
2093 snprintf(buf, sizeof buf, "Philips regs: %08lx", regs);
2094 lcd_puts(0, row++, buf);
2095 #endif
2097 lcd_update();
2099 if (action_userabort(HZ))
2100 return false;
2102 return false;
2104 #endif /* CONFIG_TUNER */
2105 #endif /* !SIMULATOR */
2107 #ifdef HAVE_LCD_BITMAP
2108 extern bool do_screendump_instead_of_usb;
2110 bool dbg_screendump(void)
2112 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
2113 gui_syncsplash(HZ, true, "Screendump %s",
2114 do_screendump_instead_of_usb?"enabled":"disabled");
2115 return false;
2117 #endif /* HAVE_LCD_BITMAP */
2119 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2120 bool dbg_set_memory_guard(void)
2122 static const struct opt_items names[MAXMEMGUARD] = {
2123 { "None", -1 },
2124 { "Flash ROM writes", -1 },
2125 { "Zero area (all)", -1 }
2127 int mode = system_memory_guard(MEMGUARD_KEEP);
2129 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
2130 system_memory_guard(mode);
2132 return false;
2134 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
2136 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2137 bool dbg_write_eeprom(void)
2139 int fd;
2140 int rc;
2141 int old_irq_level;
2142 char buf[EEPROM_SIZE];
2143 int err;
2145 fd = open("/internal_eeprom.bin", O_RDONLY);
2147 if (fd >= 0)
2149 rc = read(fd, buf, EEPROM_SIZE);
2151 if(rc == EEPROM_SIZE)
2153 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
2155 err = eeprom_24cxx_write(0, buf, sizeof buf);
2156 if (err)
2157 gui_syncsplash(HZ*3, true, "Eeprom write failure (%d)",err);
2158 else
2159 gui_syncsplash(HZ*3, true, "Eeprom written successfully");
2161 set_irq_level(old_irq_level);
2163 else
2165 gui_syncsplash(HZ*3, true, "File read error (%d)",rc);
2167 close(fd);
2169 else
2171 gui_syncsplash(HZ*3, true, "Failed to open 'internal_eeprom.bin'");
2174 return false;
2176 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
2178 bool debug_menu(void)
2180 int m;
2181 bool result;
2183 static const struct menu_item items[] = {
2184 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2185 { "Dump ROM contents", dbg_save_roms },
2186 #endif
2187 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP)
2188 { "View I/O ports", dbg_ports },
2189 #endif
2190 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2191 { "CPU frequency", dbg_cpufreq },
2192 #endif
2193 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2194 { "S/PDIF analyzer", dbg_spdif },
2195 #endif
2196 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2197 { "Catch mem accesses", dbg_set_memory_guard },
2198 #endif
2199 #ifndef SIMULATOR
2200 { "View OS stacks", dbg_os },
2201 #endif
2202 #ifdef HAVE_LCD_BITMAP
2203 #ifndef SIMULATOR
2204 { "View battery", view_battery },
2205 #endif
2206 { "Screendump", dbg_screendump },
2207 #endif
2208 #ifndef SIMULATOR
2209 { "View HW info", dbg_hw_info },
2210 #endif
2211 #ifndef SIMULATOR
2212 { "View partitions", dbg_partitions },
2213 #endif
2214 #ifndef SIMULATOR
2215 #ifdef HAVE_MMC
2216 { "View MMC info", dbg_mmc_info },
2217 #else
2218 { "View disk info", dbg_disk_info },
2219 #endif
2220 #endif
2221 #ifdef HAVE_DIRCACHE
2222 { "View dircache info", dbg_dircache_info },
2223 #endif
2224 #ifdef HAVE_LCD_BITMAP
2225 #ifdef HAVE_TAGCACHE
2226 { "View tagcache info", dbg_tagcache_info },
2227 #endif
2228 #if CONFIG_CODEC == SWCODEC || !defined(SIMULATOR)
2229 { "View audio thread", dbg_audio_thread },
2230 #endif
2231 #ifdef PM_DEBUG
2232 { "pm histogram", peak_meter_histogram},
2233 #endif /* PM_DEBUG */
2234 #endif /* HAVE_LCD_BITMAP */
2235 { "View runtime", view_runtime },
2236 #ifndef SIMULATOR
2237 #ifdef CONFIG_TUNER
2238 { "FM Radio", dbg_fm_radio },
2239 #endif
2240 #endif
2241 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2242 { "Write back EEPROM", dbg_write_eeprom },
2243 #endif
2244 #ifdef ROCKBOX_HAS_LOGF
2245 {"logf", logfdisplay },
2246 {"logfdump", logfdump },
2247 #endif
2250 m=menu_init( items, sizeof items / sizeof(struct menu_item), NULL,
2251 NULL, NULL, NULL);
2252 result = menu_run(m);
2253 menu_exit(m);
2255 return result;