1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Heikki Hannikainen
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
29 #include "debug_menu.h"
35 #include "powermgmt.h"
39 #include "mp3_playback.h"
42 #include "statusbar.h"
53 #include "lcd-remote.h"
56 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
64 #include "eeprom_24cxx.h"
65 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
68 #if (CONFIG_STORAGE & STORAGE_ATA)
77 #ifdef HAVE_LCD_BITMAP
78 #include "scrollbar.h"
79 #include "peakmeter.h"
82 #include "core_alloc.h"
83 #if CONFIG_CODEC == SWCODEC
85 #include "buffering.h"
87 #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
91 #ifdef IRIVER_H300_SERIES
92 #include "pcf50606.h" /* for pcf50606_read */
99 #if CONFIG_RTC == RTC_PCF50605
100 #include "pcf50605.h"
102 #include "appevents.h"
103 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
104 #include "debug-target.h"
107 #if defined(SANSA_E200) || defined(SANSA_C200) || defined(PHILIPS_SA9200) \
108 || (CONFIG_CPU == AS3525 && defined(CONFIG_CHARGING)) \
109 || CONFIG_CPU == AS3525v2
115 #include "pmu-target.h"
119 #include "usb_core.h"
122 #if defined(IPOD_ACCESSORY_PROTOCOL)
126 /*---------------------------------------------------*/
127 /* SPECIAL DEBUG STUFF */
128 /*---------------------------------------------------*/
129 extern struct thread_entry threads
[MAXTHREADS
];
131 static char thread_status_char(unsigned status
)
133 static const char thread_status_chars
[THREAD_NUM_STATES
+1] =
135 [0 ... THREAD_NUM_STATES
] = '?',
136 [STATE_RUNNING
] = 'R',
137 [STATE_BLOCKED
] = 'B',
138 [STATE_SLEEPING
] = 'S',
139 [STATE_BLOCKED_W_TMO
] = 'T',
140 [STATE_FROZEN
] = 'F',
141 [STATE_KILLED
] = 'K',
144 if (status
> THREAD_NUM_STATES
)
145 status
= THREAD_NUM_STATES
;
147 return thread_status_chars
[status
];
150 static const char* threads_getname(int selected_item
, void *data
,
151 char *buffer
, size_t buffer_len
)
154 struct thread_entry
*thread
;
158 if (selected_item
< (int)NUM_CORES
)
160 snprintf(buffer
, buffer_len
, "Idle (%d): %2d%%", selected_item
,
161 idle_stack_usage(selected_item
));
165 selected_item
-= NUM_CORES
;
168 thread
= &threads
[selected_item
];
170 if (thread
->state
== STATE_KILLED
)
172 snprintf(buffer
, buffer_len
, "%2d: ---", selected_item
);
176 thread_get_name(name
, 32, thread
);
178 snprintf(buffer
, buffer_len
,
179 "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s",
181 IF_COP(thread
->core
,)
182 #ifdef HAVE_SCHEDULER_BOOSTCTRL
183 (thread
->cpu_boost
) ? '+' :
185 ((thread
->state
== STATE_RUNNING
) ? '*' : ' '),
186 thread_status_char(thread
->state
),
187 IF_PRIO(thread
->base_priority
, thread
->priority
, )
188 thread_stack_usage(thread
), name
);
193 static int dbg_threads_action_callback(int action
, struct gui_synclist
*lists
)
196 #ifdef ROCKBOX_HAS_LOGF
197 if (action
== ACTION_STD_OK
)
199 int selpos
= gui_synclist_get_sel_pos(lists
);
201 if (selpos
>= NUM_CORES
)
202 remove_thread(threads
[selpos
- NUM_CORES
].id
);
204 remove_thread(threads
[selpos
].id
);
206 return ACTION_REDRAW
;
208 #endif /* ROCKBOX_HAS_LOGF */
209 if (action
== ACTION_NONE
)
210 action
= ACTION_REDRAW
;
214 static bool dbg_os(void)
216 struct simplelist_info info
;
217 simplelist_info_init(&info
, IF_COP("Core and ") "Stack usage:",
221 MAXTHREADS
+NUM_CORES
,
224 #ifndef ROCKBOX_HAS_LOGF
225 info
.hide_selection
= true;
226 info
.scroll_all
= true;
228 info
.action_callback
= dbg_threads_action_callback
;
229 info
.get_name
= threads_getname
;
230 return simplelist_show_list(&info
);
233 #ifdef HAVE_LCD_BITMAP
234 #if CONFIG_CODEC != SWCODEC
236 static bool dbg_audio_thread(void)
238 struct audio_debug d
;
240 lcd_setfont(FONT_SYSFIXED
);
244 if (action_userabort(HZ
/5))
247 audio_get_debugdata(&d
);
251 lcd_putsf(0, 0, "read: %x", d
.audiobuf_read
);
252 lcd_putsf(0, 1, "write: %x", d
.audiobuf_write
);
253 lcd_putsf(0, 2, "swap: %x", d
.audiobuf_swapwrite
);
254 lcd_putsf(0, 3, "playing: %d", d
.playing
);
255 lcd_putsf(0, 4, "playable: %x", d
.playable_space
);
256 lcd_putsf(0, 5, "unswapped: %x", d
.unswapped_space
);
258 /* Playable space left */
259 gui_scrollbar_draw(&screens
[SCREEN_MAIN
],0, 6*8, 112, 4, d
.audiobuflen
, 0,
260 d
.playable_space
, HORIZONTAL
);
262 /* Show the watermark limit */
263 gui_scrollbar_draw(&screens
[SCREEN_MAIN
],0, 6*8+4, 112, 4, d
.audiobuflen
, 0,
264 d
.low_watermark_level
, HORIZONTAL
);
266 lcd_putsf(0, 7, "wm: %x - %x",
267 d
.low_watermark_level
, d
.lowest_watermark_level
);
271 lcd_setfont(FONT_UI
);
274 #endif /* !SIMULATOR */
275 #else /* CONFIG_CODEC == SWCODEC */
276 static unsigned int ticks
, freq_sum
;
277 #ifndef CPU_MULTI_FREQUENCY
278 static unsigned int boost_ticks
;
281 static void dbg_audio_task(void)
283 #ifdef CPUFREQ_NORMAL
284 #ifndef CPU_MULTI_FREQUENCY
285 if(FREQ
> CPUFREQ_NORMAL
)
288 freq_sum
+= FREQ
/1000000; /* in MHz */
293 static bool dbg_buffering_thread(void)
299 size_t bufsize
= pcmbuf_get_bufsize();
300 int pcmbufdescs
= pcmbuf_descs();
301 struct buffering_debug d
;
302 size_t filebuflen
= audio_get_filebuflen();
303 /* This is a size_t, but call it a long so it puts a - when it's bad. */
305 #ifndef CPU_MULTI_FREQUENCY
308 ticks
= freq_sum
= 0;
310 tick_add_task(dbg_audio_task
);
313 screens
[i
].setfont(FONT_SYSFIXED
);
317 button
= get_action(CONTEXT_STD
,HZ
/5);
320 case ACTION_STD_NEXT
:
323 case ACTION_STD_PREV
:
326 case ACTION_STD_CANCEL
:
331 buffering_get_debugdata(&d
);
332 bufused
= bufsize
- pcmbuf_free();
337 screens
[i
].clear_display();
340 screens
[i
].putsf(0, line
++, "pcm: %6ld/%ld", (long) bufused
, (long) bufsize
);
342 gui_scrollbar_draw(&screens
[i
],0, line
*8, screens
[i
].lcdwidth
, 6,
343 bufsize
, 0, bufused
, HORIZONTAL
);
346 screens
[i
].putsf(0, line
++, "alloc: %6ld/%ld", audio_filebufused(),
349 #if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
350 if (screens
[i
].lcdheight
> 80)
352 gui_scrollbar_draw(&screens
[i
],0, line
*8, screens
[i
].lcdwidth
, 6,
353 filebuflen
, 0, audio_filebufused(), HORIZONTAL
);
356 screens
[i
].putsf(0, line
++, "real: %6ld/%ld", (long)d
.buffered_data
,
359 gui_scrollbar_draw(&screens
[i
],0, line
*8, screens
[i
].lcdwidth
, 6,
360 filebuflen
, 0, (long)d
.buffered_data
, HORIZONTAL
);
365 screens
[i
].putsf(0, line
++, "usefl: %6ld/%ld", (long)(d
.useful_data
),
368 #if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
369 if (screens
[i
].lcdheight
> 80)
371 gui_scrollbar_draw(&screens
[i
],0, line
*8, screens
[i
].lcdwidth
, 6,
372 filebuflen
, 0, d
.useful_data
, HORIZONTAL
);
377 screens
[i
].putsf(0, line
++, "data_rem: %ld", (long)d
.data_rem
);
379 screens
[i
].putsf(0, line
++, "track count: %2d", audio_track_count());
381 screens
[i
].putsf(0, line
++, "handle count: %d", (int)d
.num_handles
);
383 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
384 screens
[i
].putsf(0, line
++, "cpu freq: %3dMHz",
385 (int)((FREQ
+ 500000) / 1000000));
390 int avgclock
= freq_sum
* 10 / ticks
; /* in 100 kHz */
391 #ifdef CPU_MULTI_FREQUENCY
392 int boostquota
= (avgclock
* 100 - CPUFREQ_NORMAL
/1000) /
393 ((CPUFREQ_MAX
- CPUFREQ_NORMAL
) / 1000000); /* in 0.1 % */
395 int boostquota
= boost_ticks
* 1000 / ticks
; /* in 0.1 % */
397 screens
[i
].putsf(0, line
++, "boost:%3d.%d%% (%d.%dMHz)",
398 boostquota
/10, boostquota
%10, avgclock
/10, avgclock
%10);
401 screens
[i
].putsf(0, line
++, "pcmbufdesc: %2d/%2d",
402 pcmbuf_used_descs(), pcmbufdescs
);
403 screens
[i
].putsf(0, line
++, "watermark: %6d",
410 tick_remove_task(dbg_audio_task
);
413 screens
[i
].setfont(FONT_UI
);
417 #endif /* CONFIG_CODEC */
418 #endif /* HAVE_LCD_BITMAP */
420 static const char* bf_getname(int selected_item
, void *data
,
421 char *buffer
, size_t buffer_len
)
424 core_print_block_at(selected_item
, buffer
, buffer_len
);
428 static bool dbg_buflib_allocs(void)
430 struct simplelist_info info
;
431 simplelist_info_init(&info
, "mem allocs", core_get_num_blocks(), NULL
);
432 info
.get_name
= bf_getname
;
433 return simplelist_show_list(&info
);
436 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
437 static const char* dbg_partitions_getname(int selected_item
, void *data
,
438 char *buffer
, size_t buffer_len
)
441 int partition
= selected_item
/2;
442 struct partinfo
* p
= disk_partinfo(partition
);
445 snprintf(buffer
, buffer_len
, " T:%x %ld MB", p
->type
, p
->size
/ ( 2048 / ( SECTOR_SIZE
/ 512 )));
449 snprintf(buffer
, buffer_len
, "P%d: S:%lx", partition
, p
->start
);
454 bool dbg_partitions(void)
456 struct simplelist_info info
;
457 simplelist_info_init(&info
, "Partition Info", 4, NULL
);
458 info
.selection_size
= 2;
459 info
.hide_selection
= true;
460 info
.scroll_all
= true;
461 info
.get_name
= dbg_partitions_getname
;
462 return simplelist_show_list(&info
);
464 #endif /* PLATFORM_NATIVE */
466 #if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
467 static bool dbg_spdif(void)
470 unsigned int control
;
475 unsigned int interruptstat
;
476 bool valnogood
, symbolerr
, parityerr
;
479 int spdif_source
= spdif_get_output_source(&spdif_src_on
);
480 spdif_set_output_source(AUDIO_SRC_SPDIF
IF_SPDIF_POWER_(, true));
483 lcd_setfont(FONT_SYSFIXED
);
485 #ifdef HAVE_SPDIF_POWER
486 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
493 control
= EBU1RCVCCHANNEL1
;
494 interruptstat
= INTERRUPTSTAT
;
495 INTERRUPTCLEAR
= 0x03c00000;
497 valnogood
= (interruptstat
& 0x01000000)?true:false;
498 symbolerr
= (interruptstat
& 0x00800000)?true:false;
499 parityerr
= (interruptstat
& 0x00400000)?true:false;
501 lcd_putsf(0, line
++, "Val: %s Sym: %s Par: %s",
504 parityerr
?"--":"OK");
506 lcd_putsf(0, line
++, "Status word: %08x", (int)control
);
511 lcd_putsf(0, line
++, "PRO: %d (%s)",
512 x
, x
?"Professional":"Consumer");
514 x
= (control
>> 30) & 1;
515 lcd_putsf(0, line
++, "Audio: %d (%s)",
516 x
, x
?"Non-PCM":"PCM");
518 x
= (control
>> 29) & 1;
519 lcd_putsf(0, line
++, "Copy: %d (%s)",
520 x
, x
?"Permitted":"Inhibited");
522 x
= (control
>> 27) & 7;
535 lcd_putsf(0, line
++, "Preemphasis: %d (%s)", x
, s
);
537 x
= (control
>> 24) & 3;
538 lcd_putsf(0, line
++, "Mode: %d", x
);
540 category
= (control
>> 17) & 127;
552 lcd_putsf(0, line
++, "Category: 0x%02x (%s)", category
, s
);
554 x
= (control
>> 16) & 1;
556 if(((category
& 0x70) == 0x10) ||
557 ((category
& 0x70) == 0x40) ||
558 ((category
& 0x78) == 0x38))
560 generation
= !generation
;
562 lcd_putsf(0, line
++, "Generation: %d (%s)",
563 x
, generation
?"Original":"No ind.");
565 x
= (control
>> 12) & 15;
566 lcd_putsf(0, line
++, "Source: %d", x
);
569 x
= (control
>> 8) & 15;
585 lcd_putsf(0, line
++, "Channel: %d (%s)", x
, s
);
587 x
= (control
>> 4) & 15;
600 lcd_putsf(0, line
++, "Frequency: %d (%s)", x
, s
);
602 x
= (control
>> 2) & 3;
603 lcd_putsf(0, line
++, "Clock accuracy: %d", x
);
606 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
607 lcd_putsf(0, line
++, "Measured freq: %ldHz",
608 spdif_measure_frequency());
613 if (action_userabort(HZ
/10))
617 spdif_set_output_source(spdif_source
IF_SPDIF_POWER_(, spdif_src_on
));
619 #ifdef HAVE_SPDIF_POWER
620 spdif_power_enable(global_settings
.spdif_enable
);
623 lcd_setfont(FONT_UI
);
626 #endif /* CPU_COLDFIRE */
628 #if (CONFIG_RTC == RTC_PCF50605) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
629 static bool dbg_pcf(void)
633 #ifdef HAVE_LCD_BITMAP
634 lcd_setfont(FONT_SYSFIXED
);
642 lcd_putsf(0, line
++, "DCDC1: %02x", pcf50605_read(0x1b));
643 lcd_putsf(0, line
++, "DCDC2: %02x", pcf50605_read(0x1c));
644 lcd_putsf(0, line
++, "DCDC3: %02x", pcf50605_read(0x1d));
645 lcd_putsf(0, line
++, "DCDC4: %02x", pcf50605_read(0x1e));
646 lcd_putsf(0, line
++, "DCDEC1: %02x", pcf50605_read(0x1f));
647 lcd_putsf(0, line
++, "DCDEC2: %02x", pcf50605_read(0x20));
648 lcd_putsf(0, line
++, "DCUDC1: %02x", pcf50605_read(0x21));
649 lcd_putsf(0, line
++, "DCUDC2: %02x", pcf50605_read(0x22));
650 lcd_putsf(0, line
++, "IOREGC: %02x", pcf50605_read(0x23));
651 lcd_putsf(0, line
++, "D1REGC: %02x", pcf50605_read(0x24));
652 lcd_putsf(0, line
++, "D2REGC: %02x", pcf50605_read(0x25));
653 lcd_putsf(0, line
++, "D3REGC: %02x", pcf50605_read(0x26));
654 lcd_putsf(0, line
++, "LPREG1: %02x", pcf50605_read(0x27));
656 if (button_get_w_tmo(HZ
/10) == (DEBUG_CANCEL
|BUTTON_REL
))
658 lcd_setfont(FONT_UI
);
663 lcd_setfont(FONT_UI
);
668 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
669 static bool dbg_cpufreq(void)
674 #ifdef HAVE_LCD_BITMAP
675 lcd_setfont(FONT_SYSFIXED
);
683 lcd_putsf(0, line
++, "Frequency: %ld", FREQ
);
684 lcd_putsf(0, line
++, "boost_counter: %d", get_cpu_boost_counter());
687 button
= get_action(CONTEXT_STD
,HZ
/10);
691 case ACTION_STD_PREV
:
695 case ACTION_STD_NEXT
:
700 while (get_cpu_boost_counter() > 0)
702 set_cpu_frequency(CPUFREQ_DEFAULT
);
705 case ACTION_STD_CANCEL
:
706 lcd_setfont(FONT_UI
);
710 lcd_setfont(FONT_UI
);
713 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
715 #if defined(HAVE_TSC2100) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
717 static const char* tsc2100_debug_getname(int selected_item
, void * data
,
718 char *buffer
, size_t buffer_len
)
720 int *page
= (int*)data
;
721 bool reserved
= false;
725 if ((selected_item
> 0x0a) ||
726 (selected_item
== 0x04) ||
727 (selected_item
== 0x08))
731 if ((selected_item
> 0x05) ||
732 (selected_item
== 0x02))
736 if (selected_item
> 0x1e)
741 snprintf(buffer
, buffer_len
, "%02x: RSVD", selected_item
);
743 snprintf(buffer
, buffer_len
, "%02x: %04x", selected_item
,
744 tsc2100_readreg(*page
, selected_item
)&0xffff);
747 static int tsc2100debug_action_callback(int action
, struct gui_synclist
*lists
)
749 int *page
= (int*)lists
->data
;
750 if (action
== ACTION_STD_OK
)
753 snprintf(lists
->title
, 32,
754 "tsc2100 registers - Page %d", *page
);
755 return ACTION_REDRAW
;
759 static bool tsc2100_debug(void)
762 char title
[32] = "tsc2100 registers - Page 0";
763 struct simplelist_info info
;
764 simplelist_info_init(&info
, title
, 32, &page
);
765 info
.timeout
= HZ
/100;
766 info
.get_name
= tsc2100_debug_getname
;
767 info
.action_callback
= tsc2100debug_action_callback
;
768 return simplelist_show_list(&info
);
771 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
772 #ifdef HAVE_LCD_BITMAP
774 * view_battery() shows a automatically scaled graph of the battery voltage
775 * over time. Usable for estimating battery life / charging rate.
776 * The power_history array is updated in power_thread of powermgmt.c.
779 #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
780 #define BAT_YSPACE (LCD_HEIGHT - 20)
783 static bool view_battery(void)
786 int i
, x
, y
, y1
, y2
, grid
, graph
;
787 unsigned short maxv
, minv
;
789 lcd_setfont(FONT_SYSFIXED
);
795 case 0: /* voltage history graph */
796 /* Find maximum and minimum voltage for scaling */
797 minv
= power_history
[0];
799 for (i
= 1; i
< BAT_LAST_VAL
&& power_history
[i
]; i
++) {
800 if (power_history
[i
] > maxv
)
801 maxv
= power_history
[i
];
802 if (power_history
[i
] < minv
)
803 minv
= power_history
[i
];
806 /* adjust grid scale */
807 if ((maxv
- minv
) > 50)
813 lcd_putsf(0, 0, "battery %d.%03dV", power_history
[0] / 1000,
814 power_history
[0] % 1000);
815 lcd_putsf(0, 1, "%d.%03d-%d.%03dV (%2dmV)",
816 minv
/ 1000, minv
% 1000, maxv
/ 1000, maxv
% 1000,
820 while ((y
= (minv
- (minv
% grid
)+i
*grid
)) < maxv
)
822 graph
= ((y
-minv
)*BAT_YSPACE
)/(maxv
-minv
);
823 graph
= LCD_HEIGHT
-1 - graph
;
825 /* draw dotted horizontal grid line */
826 for (x
=0; x
<LCD_WIDTH
;x
=x
+2)
827 lcd_drawpixel(x
,graph
);
833 /* draw plot of power history
836 for (i
= BAT_LAST_VAL
- 1; i
> 0; i
--)
838 if (power_history
[i
] && power_history
[i
-1])
840 y1
= (power_history
[i
] - minv
) * BAT_YSPACE
/
842 y1
= MIN(MAX(LCD_HEIGHT
-1 - y1
, 20),
844 y2
= (power_history
[i
-1] - minv
) * BAT_YSPACE
/
846 y2
= MIN(MAX(LCD_HEIGHT
-1 - y2
, 20),
849 lcd_set_drawmode(DRMODE_SOLID
);
851 /* make line thicker */
852 lcd_drawline(((x
*LCD_WIDTH
)/(BAT_LAST_VAL
)),
854 (((x
+1)*LCD_WIDTH
)/(BAT_LAST_VAL
)),
856 lcd_drawline(((x
*LCD_WIDTH
)/(BAT_LAST_VAL
))+1,
858 (((x
+1)*LCD_WIDTH
)/(BAT_LAST_VAL
))+1,
865 case 1: /* status: */
866 #if CONFIG_CHARGING >= CHARGING_MONITOR
867 lcd_putsf(0, 0, "Pwr status: %s",
868 charging_state() ? "charging" : "discharging");
870 lcd_puts(0, 0, "Power status:");
872 battery_read_info(&y
, NULL
);
873 lcd_putsf(0, 1, "Battery: %d.%03d V", y
/ 1000, y
% 1000);
875 y
= (adc_read(ADC_EXT_POWER
) * EXT_SCALE_FACTOR
) / 1000;
876 lcd_putsf(0, 2, "External: %d.%03d V", y
/ 1000, y
% 1000);
879 #if defined ARCHOS_RECORDER
880 lcd_putsf(0, 3, "Chgr: %s %s",
881 charger_inserted() ? "present" : "absent",
882 charger_enabled() ? "on" : "off");
883 lcd_putsf(0, 5, "short delta: %d", short_delta
);
884 lcd_putsf(0, 6, "long delta: %d", long_delta
);
885 lcd_puts(0, 7, power_message
);
886 lcd_putsf(0, 8, "USB Inserted: %s",
887 usb_inserted() ? "yes" : "no");
888 #elif defined IPOD_NANO || defined IPOD_VIDEO
889 int usb_pwr
= (GPIOL_INPUT_VAL
& 0x10)?true:false;
890 int ext_pwr
= (GPIOL_INPUT_VAL
& 0x08)?false:true;
891 int dock
= (GPIOA_INPUT_VAL
& 0x10)?true:false;
892 int charging
= (GPIOB_INPUT_VAL
& 0x01)?false:true;
893 int headphone
= (GPIOA_INPUT_VAL
& 0x80)?true:false;
895 lcd_putsf(0, 3, "USB pwr: %s",
896 usb_pwr
? "present" : "absent");
897 lcd_putsf(0, 4, "EXT pwr: %s",
898 ext_pwr
? "present" : "absent");
899 lcd_putsf(0, 5, "Battery: %s",
900 charging
? "charging" : (usb_pwr
||ext_pwr
) ? "charged" : "discharging");
901 lcd_putsf(0, 6, "Dock mode: %s",
902 dock
? "enabled" : "disabled");
903 lcd_putsf(0, 7, "Headphone: %s",
904 headphone
? "connected" : "disconnected");
906 if(probed_ramsize
== 64)
907 x
= (adc_read(ADC_4066_ISTAT
) * 2400) / (1024 * 2);
910 x
= (adc_read(ADC_4066_ISTAT
) * 2400) / (1024 * 3);
911 lcd_putsf(0, 8, "Ibat: %d mA", x
);
912 lcd_putsf(0, 9, "Vbat * Ibat: %d mW", x
* y
/ 1000);
913 #elif defined TOSHIBA_GIGABEAT_S
917 static const unsigned char * const chrgstate_strings
[] =
928 lcd_putsf(0, line
++, "Charger: %s",
929 charger_inserted() ? "present" : "absent");
931 st
= power_input_status() &
932 (POWER_INPUT_CHARGER
| POWER_INPUT_BATTERY
);
933 lcd_putsf(0, line
++, "%s%s",
934 (st
& POWER_INPUT_MAIN_CHARGER
) ? " Main" : "",
935 (st
& POWER_INPUT_USB_CHARGER
) ? " USB" : "");
937 y
= ARRAYLEN(chrgstate_strings
) - 1;
939 switch (charge_state
)
941 case CHARGE_STATE_DISABLED
: y
--;
942 case CHARGE_STATE_ERROR
: y
--;
943 case DISCHARGING
: y
--;
950 lcd_putsf(0, line
++, "State: %s", chrgstate_strings
[y
]);
952 lcd_putsf(0, line
++, "Battery Switch: %s",
953 (st
& POWER_INPUT_BATTERY
) ? "On" : "Off");
955 y
= chrgraw_adc_voltage();
956 lcd_putsf(0, line
++, "CHRGRAW: %d.%03d V",
959 y
= application_supply_adc_voltage();
960 lcd_putsf(0, line
++, "BP : %d.%03d V",
963 y
= battery_adc_charge_current();
964 if (y
< 0) x
= '-', y
= -y
;
966 lcd_putsf(0, line
++, "CHRGISN:%c%d mA", x
, y
);
968 y
= cccv_regulator_dissipation();
969 lcd_putsf(0, line
++, "P CCCV : %d mW", y
);
971 y
= battery_charge_current();
972 if (y
< 0) x
= '-', y
= -y
;
974 lcd_putsf(0, line
++, "I Charge:%c%d mA", x
, y
);
976 y
= battery_adc_temp();
979 lcd_putsf(0, line
++, "T Battery: %dC (%dF)", y
,
982 /* Conversion disabled */
983 lcd_puts(0, line
++, "T Battery: ?");
986 #elif defined(SANSA_E200) || defined(SANSA_C200) || CONFIG_CPU == AS3525 || \
987 CONFIG_CPU == AS3525v2
988 static const char * const chrgstate_strings
[] =
990 [CHARGE_STATE_DISABLED
- CHARGE_STATE_DISABLED
]= "Disabled",
991 [CHARGE_STATE_ERROR
- CHARGE_STATE_DISABLED
] = "Error",
992 [DISCHARGING
- CHARGE_STATE_DISABLED
] = "Discharging",
993 [CHARGING
- CHARGE_STATE_DISABLED
] = "Charging",
995 const char *str
= NULL
;
997 lcd_putsf(0, 3, "Charger: %s",
998 charger_inserted() ? "present" : "absent");
1000 y
= charge_state
- CHARGE_STATE_DISABLED
;
1001 if ((unsigned)y
< ARRAYLEN(chrgstate_strings
))
1002 str
= chrgstate_strings
[y
];
1004 lcd_putsf(0, 4, "State: %s",
1005 str
? str
: "<unknown>");
1007 lcd_putsf(0, 5, "CHARGER: %02X", ascodec_read_charger());
1008 #elif defined(IPOD_NANO2G)
1009 y
= pmu_read_battery_voltage();
1010 lcd_putsf(17, 1, "RAW: %d.%03d V", y
/ 1000, y
% 1000);
1011 y
= pmu_read_battery_current();
1012 lcd_putsf(0, 2, "Battery current: %d mA", y
);
1013 lcd_putsf(0, 3, "PWRCON: %08x %08x", PWRCON
, PWRCONEXT
);
1014 lcd_putsf(0, 4, "CLKCON: %08x %03x %03x", CLKCON
, CLKCON2
, CLKCON3
);
1015 lcd_putsf(0, 5, "PLL: %06x %06x %06x", PLL0PMS
, PLL1PMS
, PLL2PMS
);
1016 x
= pmu_read(0x1b) & 0xf;
1017 y
= pmu_read(0x1a) * 25 + 625;
1018 lcd_putsf(0, 6, "AUTO: %x / %d mV", x
, y
);
1019 x
= pmu_read(0x1f) & 0xf;
1020 y
= pmu_read(0x1e) * 25 + 625;
1021 lcd_putsf(0, 7, "DOWN1: %x / %d mV", x
, y
);
1022 x
= pmu_read(0x23) & 0xf;
1023 y
= pmu_read(0x22) * 25 + 625;
1024 lcd_putsf(0, 8, "DOWN2: %x / %d mV", x
, y
);
1025 x
= pmu_read(0x27) & 0xf;
1026 y
= pmu_read(0x26) * 100 + 900;
1027 lcd_putsf(0, 9, "MEMLDO: %x / %d mV", x
, y
);
1028 for (i
= 0; i
< 6; i
++)
1030 x
= pmu_read(0x2e + (i
<< 1)) & 0xf;
1031 y
= pmu_read(0x2d + (i
<< 1)) * 100 + 900;
1032 lcd_putsf(0, 10 + i
, "LDO%d: %x / %d mV", i
+ 1, x
, y
);
1035 lcd_putsf(0, 3, "Charger: %s",
1036 charger_inserted() ? "present" : "absent");
1037 #endif /* target type */
1038 #endif /* CONFIG_CHARGING */
1041 case 2: /* voltage deltas: */
1042 lcd_puts(0, 0, "Voltage deltas:");
1044 for (i
= 0; i
<= 6; i
++) {
1045 y
= power_history
[i
] - power_history
[i
+1];
1046 lcd_putsf(0, i
+1, "-%d min: %s%d.%03d V", i
,
1047 (y
< 0) ? "-" : "", ((y
< 0) ? y
* -1 : y
) / 1000,
1048 ((y
< 0) ? y
* -1 : y
) % 1000);
1052 case 3: /* remaining time estimation: */
1054 #ifdef ARCHOS_RECORDER
1055 lcd_putsf(0, 0, "charge_state: %d", charge_state
);
1057 lcd_putsf(0, 1, "Cycle time: %d m", powermgmt_last_cycle_startstop_min
);
1059 lcd_putsf(0, 2, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level
);
1061 lcd_putsf(0, 3, "P=%2d I=%2d", pid_p
, pid_i
);
1063 lcd_putsf(0, 4, "Trickle sec: %d/60", trickle_sec
);
1064 #endif /* ARCHOS_RECORDER */
1066 lcd_putsf(0, 5, "Last PwrHist: %d.%03dV",
1067 power_history
[0] / 1000,
1068 power_history
[0] % 1000);
1070 lcd_putsf(0, 6, "battery level: %d%%", battery_level());
1072 lcd_putsf(0, 7, "Est. remain: %d m", battery_time());
1078 switch(get_action(CONTEXT_STD
,HZ
/2))
1080 case ACTION_STD_PREV
:
1085 case ACTION_STD_NEXT
:
1090 case ACTION_STD_CANCEL
:
1091 lcd_setfont(FONT_UI
);
1095 lcd_setfont(FONT_UI
);
1099 #endif /* HAVE_LCD_BITMAP */
1102 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
1103 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1105 #if (CONFIG_STORAGE & STORAGE_MMC)
1106 #define CARDTYPE "MMC"
1107 #elif (CONFIG_STORAGE & STORAGE_SD)
1108 #define CARDTYPE "microSD"
1111 static int disk_callback(int btn
, struct gui_synclist
*lists
)
1114 int *cardnum
= (int*)lists
->data
;
1115 unsigned char card_name
[6];
1116 unsigned char pbuf
[32];
1117 char *title
= lists
->title
;
1118 static const unsigned char i_vmin
[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1119 static const unsigned char i_vmax
[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
1120 static const unsigned char * const kbit_units
[] = { "kBit/s", "MBit/s", "GBit/s" };
1121 static const unsigned char * const nsec_units
[] = { "ns", "µs", "ms" };
1122 #if (CONFIG_STORAGE & STORAGE_MMC)
1123 static const char * const mmc_spec_vers
[] = { "1.0-1.2", "1.4", "2.0-2.2",
1124 "3.1-3.31", "4.0" };
1127 if ((btn
== ACTION_STD_OK
) || (btn
== SYS_FS_CHANGED
) || (btn
== ACTION_REDRAW
))
1130 if (btn
== ACTION_STD_OK
)
1132 *cardnum
^= 0x1; /* change cards */
1136 simplelist_set_line_count(0);
1138 card
= card_get_info(*cardnum
);
1140 if (card
->initialized
> 0)
1143 for (i
=0; i
<sizeof(card_name
); i
++)
1145 card_name
[i
] = card_extract_bits(card
->cid
, (103-8*i
), 8);
1147 strlcpy(card_name
, card_name
, sizeof(card_name
));
1148 simplelist_addline(SIMPLELIST_ADD_LINE
,
1149 "%s Rev %d.%d", card_name
,
1150 (int) card_extract_bits(card
->cid
, 63, 4),
1151 (int) card_extract_bits(card
->cid
, 59, 4));
1152 simplelist_addline(SIMPLELIST_ADD_LINE
,
1154 #if (CONFIG_STORAGE & STORAGE_SD)
1155 (int) card_extract_bits(card
->cid
, 11, 4),
1156 (int) card_extract_bits(card
->cid
, 19, 8) + 2000
1157 #elif (CONFIG_STORAGE & STORAGE_MMC)
1158 (int) card_extract_bits(card
->cid
, 15, 4),
1159 (int) card_extract_bits(card
->cid
, 11, 4) + 1997
1162 simplelist_addline(SIMPLELIST_ADD_LINE
,
1163 #if (CONFIG_STORAGE & STORAGE_SD)
1165 card_extract_bits(card
->cid
, 55, 32)
1166 #elif (CONFIG_STORAGE & STORAGE_MMC)
1168 card_extract_bits(card
->cid
, 47, 16)
1172 simplelist_addline(SIMPLELIST_ADD_LINE
, "M=%02x, "
1173 #if (CONFIG_STORAGE & STORAGE_SD)
1175 (int) card_extract_bits(card
->cid
, 127, 8),
1176 card_extract_bits(card
->cid
, 119, 8),
1177 card_extract_bits(card
->cid
, 111, 8)
1178 #elif (CONFIG_STORAGE & STORAGE_MMC)
1180 (int) card_extract_bits(card
->cid
, 127, 8),
1181 (int) card_extract_bits(card
->cid
, 119, 16)
1185 #if (CONFIG_STORAGE & STORAGE_MMC)
1186 int temp
= card_extract_bits(card
->csd
, 125, 4);
1187 simplelist_addline(SIMPLELIST_ADD_LINE
,
1188 "MMC v%s", temp
< 5 ?
1189 mmc_spec_vers
[temp
] : "?.?");
1191 simplelist_addline(SIMPLELIST_ADD_LINE
,
1192 "Blocks: 0x%08lx", card
->numblocks
);
1193 output_dyn_value(pbuf
, sizeof pbuf
, card
->speed
/ 1000,
1195 simplelist_addline(SIMPLELIST_ADD_LINE
,
1197 output_dyn_value(pbuf
, sizeof pbuf
, card
->taac
,
1199 simplelist_addline(SIMPLELIST_ADD_LINE
,
1201 simplelist_addline(SIMPLELIST_ADD_LINE
,
1202 "Nsac: %d clk", card
->nsac
);
1203 simplelist_addline(SIMPLELIST_ADD_LINE
,
1204 "R2W: *%d", card
->r2w_factor
);
1205 #if (CONFIG_STORAGE & STORAGE_SD)
1206 int csd_structure
= card_extract_bits(card
->csd
, 127, 2);
1207 if (csd_structure
== 0) /* CSD version 1.0 */
1210 simplelist_addline(SIMPLELIST_ADD_LINE
,
1212 i_vmin
[card_extract_bits(card
->csd
, 61, 3)],
1213 i_vmax
[card_extract_bits(card
->csd
, 58, 3)]);
1214 simplelist_addline(SIMPLELIST_ADD_LINE
,
1216 i_vmin
[card_extract_bits(card
->csd
, 55, 3)],
1217 i_vmax
[card_extract_bits(card
->csd
, 52, 3)]);
1220 else if (card
->initialized
== 0)
1222 simplelist_addline(SIMPLELIST_ADD_LINE
, "Not Found!");
1224 #if (CONFIG_STORAGE & STORAGE_SD)
1225 else /* card->initialized < 0 */
1227 simplelist_addline(SIMPLELIST_ADD_LINE
, "Init Error! (%d)", card
->initialized
);
1230 snprintf(title
, 16, "[" CARDTYPE
" %d]", *cardnum
);
1231 gui_synclist_set_title(lists
, title
, Icon_NOICON
);
1232 gui_synclist_set_nb_items(lists
, simplelist_get_line_count());
1233 gui_synclist_select_item(lists
, 0);
1234 btn
= ACTION_REDRAW
;
1238 #elif (CONFIG_STORAGE & STORAGE_ATA)
1239 static int disk_callback(int btn
, struct gui_synclist
*lists
)
1244 unsigned short* identify_info
= ata_get_identify();
1245 bool timing_info_present
= false;
1248 simplelist_set_line_count(0);
1250 for (i
=0; i
< 20; i
++)
1251 ((unsigned short*)buf
)[i
]=htobe16(identify_info
[i
+27]);
1253 /* kill trailing space */
1254 for (i
=39; i
&& buf
[i
]==' '; i
--)
1256 simplelist_addline(SIMPLELIST_ADD_LINE
, "Model: %s", buf
);
1257 for (i
=0; i
< 4; i
++)
1258 ((unsigned short*)buf
)[i
]=htobe16(identify_info
[i
+23]);
1260 simplelist_addline(SIMPLELIST_ADD_LINE
,
1261 "Firmware: %s", buf
);
1262 snprintf(buf
, sizeof buf
, "%ld MB",
1263 ((unsigned long)identify_info
[61] << 16 |
1264 (unsigned long)identify_info
[60]) / 2048 );
1265 simplelist_addline(SIMPLELIST_ADD_LINE
,
1268 fat_size( IF_MV2(0,) NULL
, &free
);
1269 simplelist_addline(SIMPLELIST_ADD_LINE
,
1270 "Free: %ld MB", free
/ 1024);
1271 simplelist_addline(SIMPLELIST_ADD_LINE
,
1272 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ
));
1273 i
= identify_info
[83] & (1<<3);
1274 simplelist_addline(SIMPLELIST_ADD_LINE
,
1275 "Power mgmt: %s", i
? "enabled" : "unsupported");
1276 i
= identify_info
[83] & (1<<9);
1277 simplelist_addline(SIMPLELIST_ADD_LINE
,
1278 "Noise mgmt: %s", i
? "enabled" : "unsupported");
1279 i
= identify_info
[82] & (1<<6);
1280 simplelist_addline(SIMPLELIST_ADD_LINE
,
1281 "Read-ahead: %s", i
? "enabled" : "unsupported");
1282 timing_info_present
= identify_info
[53] & (1<<1);
1283 if(timing_info_present
) {
1284 char pio3
[2], pio4
[2];pio3
[1] = 0;
1286 pio3
[0] = (identify_info
[64] & (1<<0)) ? '3' : 0;
1287 pio4
[0] = (identify_info
[64] & (1<<1)) ? '4' : 0;
1288 simplelist_addline(SIMPLELIST_ADD_LINE
,
1289 "PIO modes: 0 1 2 %s %s", pio3
, pio4
);
1292 simplelist_addline(SIMPLELIST_ADD_LINE
,
1293 "No PIO mode info");
1295 timing_info_present
= identify_info
[53] & (1<<1);
1296 if(timing_info_present
) {
1297 simplelist_addline(SIMPLELIST_ADD_LINE
,
1298 "Cycle times %dns/%dns",
1300 identify_info
[68] );
1302 simplelist_addline(SIMPLELIST_ADD_LINE
,
1305 int sector_size
= 512;
1306 if((identify_info
[106] & 0xe000) == 0x6000)
1307 sector_size
*= BIT_N(identify_info
[106] & 0x000f);
1308 simplelist_addline(SIMPLELIST_ADD_LINE
,
1309 "Physical sector size: %d", sector_size
);
1311 if (identify_info
[63] & (1<<0)) {
1312 char mdma0
[2], mdma1
[2], mdma2
[2];
1313 mdma0
[1] = mdma1
[1] = mdma2
[1] = 0;
1314 mdma0
[0] = (identify_info
[63] & (1<<0)) ? '0' : 0;
1315 mdma1
[0] = (identify_info
[63] & (1<<1)) ? '1' : 0;
1316 mdma2
[0] = (identify_info
[63] & (1<<2)) ? '2' : 0;
1317 simplelist_addline(SIMPLELIST_ADD_LINE
,
1318 "MDMA modes: %s %s %s", mdma0
, mdma1
, mdma2
);
1319 simplelist_addline(SIMPLELIST_ADD_LINE
,
1320 "MDMA Cycle times %dns/%dns",
1322 identify_info
[66] );
1325 simplelist_addline(SIMPLELIST_ADD_LINE
,
1326 "No MDMA mode info");
1328 if (identify_info
[53] & (1<<2)) {
1329 char udma0
[2], udma1
[2], udma2
[2], udma3
[2], udma4
[2], udma5
[2], udma6
[2];
1330 udma0
[1] = udma1
[1] = udma2
[1] = udma3
[1] = udma4
[1] = udma5
[1] = udma6
[1] = 0;
1331 udma0
[0] = (identify_info
[88] & (1<<0)) ? '0' : 0;
1332 udma1
[0] = (identify_info
[88] & (1<<1)) ? '1' : 0;
1333 udma2
[0] = (identify_info
[88] & (1<<2)) ? '2' : 0;
1334 udma3
[0] = (identify_info
[88] & (1<<3)) ? '3' : 0;
1335 udma4
[0] = (identify_info
[88] & (1<<4)) ? '4' : 0;
1336 udma5
[0] = (identify_info
[88] & (1<<5)) ? '5' : 0;
1337 udma6
[0] = (identify_info
[88] & (1<<6)) ? '6' : 0;
1338 simplelist_addline(SIMPLELIST_ADD_LINE
,
1339 "UDMA modes: %s %s %s %s %s %s %s", udma0
, udma1
, udma2
,
1340 udma3
, udma4
, udma5
, udma6
);
1343 simplelist_addline(SIMPLELIST_ADD_LINE
,
1344 "No UDMA mode info");
1346 #endif /* HAVE_ATA_DMA */
1347 timing_info_present
= identify_info
[53] & (1<<1);
1348 if(timing_info_present
) {
1349 i
= identify_info
[49] & (1<<11);
1350 simplelist_addline(SIMPLELIST_ADD_LINE
,
1351 "IORDY support: %s", i
? "yes" : "no");
1352 i
= identify_info
[49] & (1<<10);
1353 simplelist_addline(SIMPLELIST_ADD_LINE
,
1354 "IORDY disable: %s", i
? "yes" : "no");
1356 simplelist_addline(SIMPLELIST_ADD_LINE
,
1359 simplelist_addline(SIMPLELIST_ADD_LINE
,
1360 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1362 i
= ata_get_dma_mode();
1364 simplelist_addline(SIMPLELIST_ADD_LINE
,
1367 simplelist_addline(SIMPLELIST_ADD_LINE
,
1369 (i
& 0x40) ? "UDMA" : "MDMA",
1372 #endif /* HAVE_ATA_DMA */
1375 #else /* No SD, MMC or ATA */
1376 static int disk_callback(int btn
, struct gui_synclist
*lists
)
1380 struct storage_info info
;
1381 storage_get_info(0,&info
);
1382 simplelist_addline(SIMPLELIST_ADD_LINE
, "Vendor: %s", info
.vendor
);
1383 simplelist_addline(SIMPLELIST_ADD_LINE
, "Model: %s", info
.product
);
1384 simplelist_addline(SIMPLELIST_ADD_LINE
, "Firmware: %s", info
.revision
);
1385 simplelist_addline(SIMPLELIST_ADD_LINE
,
1386 "Size: %ld MB", info
.num_sectors
*(info
.sector_size
/512)/2024);
1388 fat_size( IF_MV2(0,) NULL
, &free
);
1389 simplelist_addline(SIMPLELIST_ADD_LINE
,
1390 "Free: %ld MB", free
/ 1024);
1391 simplelist_addline(SIMPLELIST_ADD_LINE
,
1392 "Cluster size: %d bytes", fat_get_cluster_size(IF_MV(0)));
1397 #if (CONFIG_STORAGE & STORAGE_ATA)
1398 static bool dbg_identify_info(void)
1400 int fd
= creat("/identify_info.bin", 0666);
1403 #ifdef ROCKBOX_LITTLE_ENDIAN
1404 ecwrite(fd
, ata_get_identify(), SECTOR_SIZE
/2, "s", true);
1406 write(fd
, ata_get_identify(), SECTOR_SIZE
);
1414 static bool dbg_disk_info(void)
1416 struct simplelist_info info
;
1417 simplelist_info_init(&info
, "Disk Info", 1, NULL
);
1418 #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
1421 info
.callback_data
= (void*)&card
;
1424 info
.action_callback
= disk_callback
;
1425 info
.hide_selection
= true;
1426 info
.scroll_all
= true;
1427 return simplelist_show_list(&info
);
1429 #endif /* PLATFORM_NATIVE */
1431 #ifdef HAVE_DIRCACHE
1432 static int dircache_callback(int btn
, struct gui_synclist
*lists
)
1434 (void)btn
; (void)lists
;
1435 simplelist_set_line_count(0);
1436 simplelist_addline(SIMPLELIST_ADD_LINE
, "Cache initialized: %s",
1437 dircache_is_enabled() ? "Yes" : "No");
1438 simplelist_addline(SIMPLELIST_ADD_LINE
, "Cache size: %d B",
1439 dircache_get_cache_size());
1440 simplelist_addline(SIMPLELIST_ADD_LINE
, "Last size: %d B",
1441 global_status
.dircache_size
);
1442 simplelist_addline(SIMPLELIST_ADD_LINE
, "Limit: %d B",
1444 simplelist_addline(SIMPLELIST_ADD_LINE
, "Reserve: %d/%d B",
1445 dircache_get_reserve_used(), DIRCACHE_RESERVE
);
1446 simplelist_addline(SIMPLELIST_ADD_LINE
, "Scanning took: %d s",
1447 dircache_get_build_ticks() / HZ
);
1448 simplelist_addline(SIMPLELIST_ADD_LINE
, "Entry count: %d",
1449 dircache_get_entry_count());
1453 static bool dbg_dircache_info(void)
1455 struct simplelist_info info
;
1456 simplelist_info_init(&info
, "Dircache Info", 7, NULL
);
1457 info
.action_callback
= dircache_callback
;
1458 info
.hide_selection
= true;
1459 info
.scroll_all
= true;
1460 return simplelist_show_list(&info
);
1463 #endif /* HAVE_DIRCACHE */
1465 #ifdef HAVE_TAGCACHE
1466 static int database_callback(int btn
, struct gui_synclist
*lists
)
1469 struct tagcache_stat
*stat
= tagcache_get_stat();
1470 static bool synced
= false;
1472 simplelist_set_line_count(0);
1474 simplelist_addline(SIMPLELIST_ADD_LINE
, "Initialized: %s",
1475 stat
->initialized
? "Yes" : "No");
1476 simplelist_addline(SIMPLELIST_ADD_LINE
, "DB Ready: %s",
1477 stat
->ready
? "Yes" : "No");
1478 simplelist_addline(SIMPLELIST_ADD_LINE
, "RAM Cache: %s",
1479 stat
->ramcache
? "Yes" : "No");
1480 simplelist_addline(SIMPLELIST_ADD_LINE
, "RAM: %d/%d B",
1481 stat
->ramcache_used
, stat
->ramcache_allocated
);
1482 simplelist_addline(SIMPLELIST_ADD_LINE
, "Progress: %d%% (%d entries)",
1483 stat
->progress
, stat
->processed_entries
);
1484 simplelist_addline(SIMPLELIST_ADD_LINE
, "Curfile: %s",
1485 stat
->curentry
? stat
->curentry
: "---");
1486 simplelist_addline(SIMPLELIST_ADD_LINE
, "Commit step: %d",
1488 simplelist_addline(SIMPLELIST_ADD_LINE
, "Commit delayed: %s",
1489 stat
->commit_delayed
? "Yes" : "No");
1491 simplelist_addline(SIMPLELIST_ADD_LINE
, "Queue length: %d",
1492 stat
->queue_length
);
1497 tagcache_screensync_event();
1500 if (!btn
&& stat
->curentry
)
1503 return ACTION_REDRAW
;
1506 if (btn
== ACTION_STD_CANCEL
)
1507 tagcache_screensync_enable(false);
1511 static bool dbg_tagcache_info(void)
1513 struct simplelist_info info
;
1514 simplelist_info_init(&info
, "Database Info", 8, NULL
);
1515 info
.action_callback
= database_callback
;
1516 info
.hide_selection
= true;
1517 info
.scroll_all
= true;
1519 /* Don't do nonblock here, must give enough processing time
1520 for tagcache thread. */
1521 /* info.timeout = TIMEOUT_NOBLOCK; */
1523 tagcache_screensync_enable(true);
1524 return simplelist_show_list(&info
);
1528 #if CONFIG_CPU == SH7034
1529 static bool dbg_save_roms(void)
1532 int oldmode
= system_memory_guard(MEMGUARD_NONE
);
1534 fd
= creat("/internal_rom_0000-FFFF.bin", 0666);
1537 write(fd
, (void *)0, 0x10000);
1541 fd
= creat("/internal_rom_2000000-203FFFF.bin", 0666);
1544 write(fd
, (void *)0x2000000, 0x40000);
1548 system_memory_guard(oldmode
);
1551 #elif defined CPU_COLDFIRE
1552 static bool dbg_save_roms(void)
1555 int oldmode
= system_memory_guard(MEMGUARD_NONE
);
1557 #if defined(IRIVER_H100_SERIES)
1558 fd
= creat("/internal_rom_000000-1FFFFF.bin", 0666);
1559 #elif defined(IRIVER_H300_SERIES)
1560 fd
= creat("/internal_rom_000000-3FFFFF.bin", 0666);
1561 #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IAUDIO_M3)
1562 fd
= creat("/internal_rom_000000-3FFFFF.bin", 0666);
1563 #elif defined(MPIO_HD200) || defined(MPIO_HD300)
1564 fd
= creat("/internal_rom_000000-1FFFFF.bin", 0666);
1568 write(fd
, (void *)0, FLASH_SIZE
);
1571 system_memory_guard(oldmode
);
1574 fd
= creat("/internal_eeprom.bin", 0666);
1578 char buf
[EEPROM_SIZE
];
1581 old_irq_level
= disable_irq_save();
1583 err
= eeprom_24cxx_read(0, buf
, sizeof buf
);
1585 restore_irq(old_irq_level
);
1588 splashf(HZ
*3, "Eeprom read failure (%d)", err
);
1591 write(fd
, buf
, sizeof buf
);
1600 #elif defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)
1601 static bool dbg_save_roms(void)
1605 fd
= creat("/internal_rom_000000-0FFFFF.bin", 0666);
1608 write(fd
, (void *)0x20000000, FLASH_SIZE
);
1614 #elif CONFIG_CPU == IMX31L
1615 static bool dbg_save_roms(void)
1619 fd
= creat("/flash_rom_A0000000-A01FFFFF.bin", 0666);
1622 write(fd
, (void*)0xa0000000, FLASH_SIZE
);
1628 #elif defined(CPU_TCC780X)
1629 static bool dbg_save_roms(void)
1633 fd
= creat("/eeprom_E0000000-E0001FFF.bin", 0666);
1636 write(fd
, (void*)0xe0000000, 0x2000);
1647 #ifdef CONFIG_TUNER_MULTI
1648 static int tuner_type
= 0;
1649 #define IF_TUNER_TYPE(type) if(tuner_type==type)
1651 #define IF_TUNER_TYPE(type)
1654 static int radio_callback(int btn
, struct gui_synclist
*lists
)
1657 if (btn
== ACTION_STD_CANCEL
)
1659 simplelist_set_line_count(1);
1661 #if (CONFIG_TUNER & LV24020LP)
1662 simplelist_addline(SIMPLELIST_ADD_LINE
,
1663 "CTRL_STAT: %02X", lv24020lp_get(LV24020LP_CTRL_STAT
) );
1664 simplelist_addline(SIMPLELIST_ADD_LINE
,
1665 "RADIO_STAT: %02X", lv24020lp_get(LV24020LP_REG_STAT
) );
1666 simplelist_addline(SIMPLELIST_ADD_LINE
,
1667 "MSS_FM: %d kHz", lv24020lp_get(LV24020LP_MSS_FM
) );
1668 simplelist_addline(SIMPLELIST_ADD_LINE
,
1669 "MSS_IF: %d Hz", lv24020lp_get(LV24020LP_MSS_IF
) );
1670 simplelist_addline(SIMPLELIST_ADD_LINE
,
1671 "MSS_SD: %d Hz", lv24020lp_get(LV24020LP_MSS_SD
) );
1672 simplelist_addline(SIMPLELIST_ADD_LINE
,
1673 "if_set: %d Hz", lv24020lp_get(LV24020LP_IF_SET
) );
1674 simplelist_addline(SIMPLELIST_ADD_LINE
,
1675 "sd_set: %d Hz", lv24020lp_get(LV24020LP_SD_SET
) );
1676 #endif /* LV24020LP */
1677 #if (CONFIG_TUNER & S1A0903X01)
1678 simplelist_addline(SIMPLELIST_ADD_LINE
,
1679 "Samsung regs: %08X", s1a0903x01_get(RADIO_ALL
));
1680 /* This one doesn't return dynamic data atm */
1681 #endif /* S1A0903X01 */
1682 #if (CONFIG_TUNER & TEA5767)
1683 struct tea5767_dbg_info nfo
;
1684 tea5767_dbg_info(&nfo
);
1685 simplelist_addline(SIMPLELIST_ADD_LINE
, "Philips regs:");
1686 simplelist_addline(SIMPLELIST_ADD_LINE
,
1687 " Read: %02X %02X %02X %02X %02X",
1688 (unsigned)nfo
.read_regs
[0], (unsigned)nfo
.read_regs
[1],
1689 (unsigned)nfo
.read_regs
[2], (unsigned)nfo
.read_regs
[3],
1690 (unsigned)nfo
.read_regs
[4]);
1691 simplelist_addline(SIMPLELIST_ADD_LINE
,
1692 " Write: %02X %02X %02X %02X %02X",
1693 (unsigned)nfo
.write_regs
[0], (unsigned)nfo
.write_regs
[1],
1694 (unsigned)nfo
.write_regs
[2], (unsigned)nfo
.write_regs
[3],
1695 (unsigned)nfo
.write_regs
[4]);
1696 #endif /* TEA5767 */
1697 #if (CONFIG_TUNER & SI4700)
1698 IF_TUNER_TYPE(SI4700
)
1700 struct si4700_dbg_info nfo
;
1702 si4700_dbg_info(&nfo
);
1703 simplelist_addline(SIMPLELIST_ADD_LINE
, "SI4700 regs:");
1704 for (i
= 0; i
< 16; i
+= 4) {
1705 simplelist_addline(SIMPLELIST_ADD_LINE
,"%02X: %04X %04X %04X %04X",
1706 i
, nfo
.regs
[i
], nfo
.regs
[i
+1], nfo
.regs
[i
+2], nfo
.regs
[i
+3]);
1710 #if (CONFIG_TUNER & RDA5802)
1711 IF_TUNER_TYPE(RDA5802
)
1713 struct rda5802_dbg_info nfo
;
1715 rda5802_dbg_info(&nfo
);
1716 simplelist_addline(SIMPLELIST_ADD_LINE
, "RDA5802 regs:");
1717 for (i
= 0; i
< 16; i
+= 4) {
1718 simplelist_addline(SIMPLELIST_ADD_LINE
,"%02X: %04X %04X %04X %04X",
1719 i
, nfo
.regs
[i
], nfo
.regs
[i
+1], nfo
.regs
[i
+2], nfo
.regs
[i
+3]);
1722 #endif /* RDA55802 */
1723 return ACTION_REDRAW
;
1725 static bool dbg_fm_radio(void)
1727 struct simplelist_info info
;
1728 #ifdef CONFIG_TUNER_MULTI
1729 tuner_type
= tuner_detect_type();
1731 info
.scroll_all
= true;
1732 simplelist_info_init(&info
, "FM Radio", 1, NULL
);
1733 simplelist_set_line_count(0);
1734 simplelist_addline(SIMPLELIST_ADD_LINE
, "HW detected: %s",
1735 radio_hardware_present() ? "yes" : "no");
1737 info
.action_callback
= radio_hardware_present()?radio_callback
: NULL
;
1738 info
.hide_selection
= true;
1739 return simplelist_show_list(&info
);
1741 #endif /* CONFIG_TUNER */
1742 #endif /* !SIMULATOR */
1744 #ifdef HAVE_LCD_BITMAP
1745 extern bool do_screendump_instead_of_usb
;
1747 static bool dbg_screendump(void)
1749 do_screendump_instead_of_usb
= !do_screendump_instead_of_usb
;
1750 splashf(HZ
, "Screendump %s",
1751 do_screendump_instead_of_usb
?"enabled":"disabled");
1754 #endif /* HAVE_LCD_BITMAP */
1756 extern bool write_metadata_log
;
1758 static bool dbg_metadatalog(void)
1760 write_metadata_log
= !write_metadata_log
;
1761 splashf(HZ
, "Metadata log %s",
1762 write_metadata_log
?"enabled":"disabled");
1766 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
1767 static bool dbg_set_memory_guard(void)
1769 static const struct opt_items names
[MAXMEMGUARD
] = {
1771 { "Flash ROM writes", -1 },
1772 { "Zero area (all)", -1 }
1774 int mode
= system_memory_guard(MEMGUARD_KEEP
);
1776 set_option( "Catch mem accesses", &mode
, INT
, names
, MAXMEMGUARD
, NULL
);
1777 system_memory_guard(mode
);
1781 #endif /* CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) */
1783 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
1784 static bool dbg_write_eeprom(void)
1789 char buf
[EEPROM_SIZE
];
1792 fd
= open("/internal_eeprom.bin", O_RDONLY
);
1796 rc
= read(fd
, buf
, EEPROM_SIZE
);
1798 if(rc
== EEPROM_SIZE
)
1800 old_irq_level
= disable_irq_save();
1802 err
= eeprom_24cxx_write(0, buf
, sizeof buf
);
1804 splashf(HZ
*3, "Eeprom write failure (%d)", err
);
1806 splash(HZ
*3, "Eeprom written successfully");
1808 restore_irq(old_irq_level
);
1812 splashf(HZ
*3, "File read error (%d)",rc
);
1818 splash(HZ
*3, "Failed to open 'internal_eeprom.bin'");
1823 #endif /* defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS) */
1824 #ifdef CPU_BOOST_LOGGING
1825 static bool cpu_boost_log(void)
1828 int count
= cpu_boost_log_getcount();
1829 int lines
= LCD_HEIGHT
/SYSFONT_HEIGHT
;
1832 lcd_setfont(FONT_SYSFIXED
);
1833 str
= cpu_boost_log_getlog_first();
1836 lcd_clear_display();
1837 for(j
=0; j
<lines
; j
++,i
++)
1840 str
= cpu_boost_log_getlog_next();
1843 if(strlen(str
) > LCD_WIDTH
/SYSFONT_WIDTH
)
1844 lcd_puts_scroll(0, j
, str
);
1854 switch(get_action(CONTEXT_STD
,TIMEOUT_BLOCK
))
1857 case ACTION_STD_PREV
:
1858 case ACTION_STD_NEXT
:
1861 case ACTION_STD_CANCEL
:
1869 get_action(CONTEXT_STD
,TIMEOUT_BLOCK
);
1870 lcd_setfont(FONT_UI
);
1875 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) \
1876 && !defined(IPOD_MINI) && !defined(SIMULATOR))
1877 extern bool wheel_is_touched
;
1878 extern int old_wheel_value
;
1879 extern int new_wheel_value
;
1880 extern int wheel_delta
;
1881 extern unsigned int accumulated_wheel_delta
;
1882 extern unsigned int wheel_velocity
;
1884 static bool dbg_scrollwheel(void)
1888 lcd_setfont(FONT_SYSFIXED
);
1892 if (action_userabort(HZ
/10))
1895 lcd_clear_display();
1897 /* show internal variables of scrollwheel driver */
1898 lcd_putsf(0, 0, "wheel touched: %s", (wheel_is_touched
) ? "true" : "false");
1899 lcd_putsf(0, 1, "new position: %2d", new_wheel_value
);
1900 lcd_putsf(0, 2, "old position: %2d", old_wheel_value
);
1901 lcd_putsf(0, 3, "wheel delta: %2d", wheel_delta
);
1902 lcd_putsf(0, 4, "accumulated delta: %2d", accumulated_wheel_delta
);
1903 lcd_putsf(0, 5, "velo [deg/s]: %4d", (int)wheel_velocity
);
1905 /* show effective accelerated scrollspeed */
1906 speed
= button_apply_acceleration( (1<<31)|(1<<24)|wheel_velocity
);
1907 lcd_putsf(0, 6, "accel. speed: %4d", speed
);
1911 lcd_setfont(FONT_UI
);
1916 #if defined (HAVE_USBSTACK)
1918 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
1919 static bool toggle_usb_core_driver(int driver
, char *msg
)
1921 bool enabled
= !usb_core_driver_enabled(driver
);
1923 usb_core_enable_driver(driver
,enabled
);
1924 splashf(HZ
, "%s %s", msg
, enabled
?"enabled":"disabled");
1929 static bool toggle_usb_serial(void)
1931 return toggle_usb_core_driver(USB_DRIVER_SERIAL
,"USB Serial");
1937 #if CONFIG_USBOTG == USBOTG_ISP1583
1938 extern int dbg_usb_num_items(void);
1939 extern const char* dbg_usb_item(int selected_item
, void *data
,
1940 char *buffer
, size_t buffer_len
);
1942 static int isp1583_action_callback(int action
, struct gui_synclist
*lists
)
1945 if (action
== ACTION_NONE
)
1946 action
= ACTION_REDRAW
;
1950 static bool dbg_isp1583(void)
1952 struct simplelist_info isp1583
;
1953 isp1583
.scroll_all
= true;
1954 simplelist_info_init(&isp1583
, "ISP1583", dbg_usb_num_items(), NULL
);
1955 isp1583
.timeout
= HZ
/100;
1956 isp1583
.hide_selection
= true;
1957 isp1583
.get_name
= dbg_usb_item
;
1958 isp1583
.action_callback
= isp1583_action_callback
;
1959 return simplelist_show_list(&isp1583
);
1963 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
1964 extern int pic_dbg_num_items(void);
1965 extern const char* pic_dbg_item(int selected_item
, void *data
,
1966 char *buffer
, size_t buffer_len
);
1968 static int pic_action_callback(int action
, struct gui_synclist
*lists
)
1971 if (action
== ACTION_NONE
)
1972 action
= ACTION_REDRAW
;
1976 static bool dbg_pic(void)
1978 struct simplelist_info pic
;
1979 pic
.scroll_all
= true;
1980 simplelist_info_init(&pic
, "PIC", pic_dbg_num_items(), NULL
);
1981 pic
.timeout
= HZ
/100;
1982 pic
.hide_selection
= true;
1983 pic
.get_name
= pic_dbg_item
;
1984 pic
.action_callback
= pic_action_callback
;
1985 return simplelist_show_list(&pic
);
1990 /****** The menu *********/
1991 struct the_menu_item
{
1992 unsigned char *desc
; /* string or ID */
1993 bool (*function
) (void); /* return true if USB was connected */
1995 static const struct the_menu_item menuitems
[] = {
1996 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || \
1997 (defined(CPU_PP) && !(CONFIG_STORAGE & STORAGE_SD)) || \
1998 CONFIG_CPU == IMX31L || defined(CPU_TCC780X)
1999 { "Dump ROM contents", dbg_save_roms
},
2001 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) || defined(CPU_PP) \
2002 || CONFIG_CPU == S3C2440 || CONFIG_CPU == IMX31L || CONFIG_CPU == AS3525 \
2003 || CONFIG_CPU == DM320 || defined(CPU_S5L870X) || CONFIG_CPU == AS3525v2
2004 { "View I/O ports", dbg_ports
},
2006 #if (CONFIG_RTC == RTC_PCF50605) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
2007 { "View PCF registers", dbg_pcf
},
2009 #if defined(HAVE_TSC2100) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
2010 { "TSC2100 debug", tsc2100_debug
},
2012 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
2013 { "CPU frequency", dbg_cpufreq
},
2015 #if CONFIG_CPU == IMX31L
2016 { "DVFS/DPTC", __dbg_dvfs_dptc
},
2018 #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
2019 { "S/PDIF analyzer", dbg_spdif
},
2021 #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
2022 { "Catch mem accesses", dbg_set_memory_guard
},
2024 { "View OS stacks", dbg_os
},
2025 #ifdef HAVE_LCD_BITMAP
2026 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2027 { "View battery", view_battery
},
2029 { "Screendump", dbg_screendump
},
2031 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2032 { "View HW info", dbg_hw_info
},
2034 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2035 { "View partitions", dbg_partitions
},
2037 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
2038 { "View disk info", dbg_disk_info
},
2039 #if (CONFIG_STORAGE & STORAGE_ATA)
2040 { "Dump ATA identify info", dbg_identify_info
},
2043 { "Metadata log", dbg_metadatalog
},
2044 #ifdef HAVE_DIRCACHE
2045 { "View dircache info", dbg_dircache_info
},
2047 #ifdef HAVE_TAGCACHE
2048 { "View database info", dbg_tagcache_info
},
2050 #ifdef HAVE_LCD_BITMAP
2051 #if CONFIG_CODEC == SWCODEC
2052 { "View buffering thread", dbg_buffering_thread
},
2053 #elif !defined(SIMULATOR)
2054 { "View audio thread", dbg_audio_thread
},
2057 { "pm histogram", peak_meter_histogram
},
2058 #endif /* PM_DEBUG */
2059 #endif /* HAVE_LCD_BITMAP */
2060 { "View buflib allocs", dbg_buflib_allocs
},
2063 { "FM Radio", dbg_fm_radio
},
2066 #if defined(HAVE_EEPROM) && !defined(HAVE_EEPROM_SETTINGS)
2067 { "Write back EEPROM", dbg_write_eeprom
},
2069 #if CONFIG_USBOTG == USBOTG_ISP1583
2070 { "View ISP1583 info", dbg_isp1583
},
2072 #if defined(CREATIVE_ZVx) && !defined(SIMULATOR)
2073 { "View PIC info", dbg_pic
},
2075 #ifdef ROCKBOX_HAS_LOGF
2076 {"Show Log File", logfdisplay
},
2077 {"Dump Log File", logfdump
},
2079 #if defined(HAVE_USBSTACK)
2080 #if defined(ROCKBOX_HAS_LOGF) && defined(USB_ENABLE_SERIAL)
2081 {"USB Serial driver (logf)", toggle_usb_serial
},
2083 #endif /* HAVE_USBSTACK */
2084 #ifdef CPU_BOOST_LOGGING
2085 {"cpu_boost log",cpu_boost_log
},
2087 #if (defined(HAVE_WHEEL_ACCELERATION) && (CONFIG_KEYPAD==IPOD_4G_PAD) \
2088 && !defined(IPOD_MINI) && !defined(SIMULATOR))
2089 {"Debug scrollwheel", dbg_scrollwheel
},
2092 static int menu_action_callback(int btn
, struct gui_synclist
*lists
)
2095 if (btn
== ACTION_STD_OK
)
2098 viewportmanager_theme_enable(i
, false, NULL
);
2099 menuitems
[gui_synclist_get_sel_pos(lists
)].function();
2100 btn
= ACTION_REDRAW
;
2102 viewportmanager_theme_undo(i
, false);
2107 static const char* dbg_menu_getname(int item
, void * data
,
2108 char *buffer
, size_t buffer_len
)
2110 (void)data
; (void)buffer
; (void)buffer_len
;
2111 return menuitems
[item
].desc
;
2114 bool debug_menu(void)
2116 struct simplelist_info info
;
2118 simplelist_info_init(&info
, "Debug Menu", ARRAYLEN(menuitems
), NULL
);
2119 info
.action_callback
= menu_action_callback
;
2120 info
.get_name
= dbg_menu_getname
;
2121 return simplelist_show_list(&info
);