/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 Heikki Hannikainen
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include "lcd.h"
#include "lang.h"
#include "menu.h"
#include "debug_menu.h"
#include "kernel.h"
#include "structec.h"
#include "action.h"
#include "debug.h"
#include "thread.h"
#include "powermgmt.h"
#include "system.h"
#include "font.h"
#include "audio.h"
#include "mp3_playback.h"
#include "settings.h"
#include "list.h"
#include "statusbar.h"
#include "dir.h"
#include "panic.h"
#include "screens.h"
#include "misc.h"
#include "splash.h"
#include "shortcuts.h"
#include "dircache.h"
#include "viewport.h"
#ifdef HAVE_TAGCACHE
#include "tagcache.h"
#endif
#ifdef HAVE_REMOTE_LCD
#include "lcd-remote.h"
#endif
#include "crc32.h"
#include "logf.h"
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
#include "disk.h"
#include "adc.h"
#include "usb.h"
#include "rtc.h"
#include "storage.h"
#include "fat.h"
#include "eeprom_24cxx.h"
#if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
#include "sdmmc.h"
#endif
#if (CONFIG_STORAGE & STORAGE_ATA)
#include "ata.h"
#endif
#if CONFIG_TUNER
#include "tuner.h"
#include "radio.h"
#endif
#endif /* CONFIG_PLATFORM & PLATFORM_NATIVE */
#include "power.h"
#if (defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1)) && defined(CONFIG_TUNER)
#include "tuner.h"
#include "radio.h"
#endif
#ifdef HAVE_LCD_BITMAP
#include "scrollbar.h"
#include "peakmeter.h"
#include "skin_engine/skin_engine.h"
#endif
#include "logfdisp.h"
#include "core_alloc.h"
#if CONFIG_CODEC == SWCODEC
#include "pcmbuf.h"
#include "buffering.h"
#include "playback.h"
#if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
#include "spdif.h"
#endif
#endif
#ifdef IRIVER_H300_SERIES
#include "pcf50606.h" /* for pcf50606_read */
#endif
#ifdef IAUDIO_X5
#include "ds2411.h"
#endif
#include "hwcompat.h"
#include "button.h"
#if CONFIG_RTC == RTC_PCF50605
#include "pcf50605.h"
#endif
#include "appevents.h"
#if defined(HAVE_AS3514) && defined(CONFIG_CHARGING)
#include "ascodec.h"
#endif
#ifdef IPOD_NANO2G
#include "pmu-target.h"
#endif
#ifdef HAVE_USBSTACK
#include "usb_core.h"
#endif
#if defined(IPOD_ACCESSORY_PROTOCOL)
#include "iap.h"
#endif
#ifdef HAVE_RDS_CAP
#include "rds.h"
#endif
#include "talk.h"
static const char* threads_getname(int selected_item, void *data,
char *buffer, size_t buffer_len)
{
(void)data;
#if NUM_CORES > 1
if (selected_item < (int)NUM_CORES)
{
struct core_debug_info coreinfo;
core_get_debug_info(selected_item, &coreinfo);
snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
coreinfo.idle_stack_usage);
return buffer;
}
selected_item -= NUM_CORES;
#endif
const char *fmtstr = "%2d: ---";
struct thread_debug_info threadinfo;
if (thread_get_debug_info(selected_item, &threadinfo) > 0)
{
fmtstr = "%2d:" IF_COP(" (%d)") " %s" IF_PRIO(" %d %d")
IFN_SDL(" %2d%%") " %s";
}
snprintf(buffer, buffer_len, fmtstr,
selected_item,
IF_COP(threadinfo.core,)
threadinfo.statusstr,
IF_PRIO(threadinfo.base_priority, threadinfo.current_priority,)
IFN_SDL(threadinfo.stack_usage,)
threadinfo.name);
return buffer;
}
static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
{
(void)lists;
if (action == ACTION_NONE)
action = ACTION_REDRAW;
return action;
}
/* Test code!!! */
static bool dbg_os(void)
{
struct simplelist_info info;
simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
MAXTHREADS IF_COP( + NUM_CORES ), NULL);
info.hide_selection = true;
info.scroll_all = true;
info.action_callback = dbg_threads_action_callback;
info.get_name = threads_getname;
return simplelist_show_list(&info);
}
#ifdef __linux__
#include "cpuinfo-linux.h"
#define MAX_STATES 16
static struct time_state states[MAX_STATES];
static const char* get_cpuinfo(int selected_item, void *data,
char *buffer, size_t buffer_len)
{
(void)data;(void)buffer_len;
const char* text;
long time, diff;
struct cpuusage us;
static struct cpuusage last_us;
int state_count = *(int*)data;
if (cpuusage_linux(&us) != 0)
return NULL;
switch(selected_item)
{
case 0:
diff = abs(last_us.usage - us.usage);
sprintf(buffer, "Usage: %ld.%02ld%% (%c %ld.%02ld)",
us.usage/100, us.usage%100,
(us.usage >= last_us.usage) ? '+':'-',
diff/100, diff%100);
last_us.usage = us.usage;
return buffer;
case 1:
text = "User";
time = us.utime;
diff = us.utime - last_us.utime;
last_us.utime = us.utime;
break;
case 2:
text = "Sys";
time = us.stime;
diff = us.stime - last_us.stime;
last_us.stime = us.stime;
break;
case 3:
text = "Real";
time = us.rtime;
diff = us.rtime - last_us.rtime;
last_us.rtime = us.rtime;
break;
case 4:
return "*** Per CPU freq stats ***";
default:
{
int cpu = (selected_item - 5) / (state_count + 1);
int cpu_line = (selected_item - 5) % (state_count + 1);
int freq1 = frequency_linux(cpu, false);
int freq2 = frequency_linux(cpu, true);
if (cpu_line == 0)
{
sprintf(buffer, " CPU%d: Cur/Scal freq: %d/%d MHz", cpu,
freq1 > 0 ? freq1/1000 : -1,
freq2 > 0 ? freq2/1000 : -1);
}
else
{
cpustatetimes_linux(cpu, states, ARRAYLEN(states));
snprintf(buffer, buffer_len, " %ld %ld",
states[cpu_line-1].frequency,
states[cpu_line-1].time);
}
return buffer;
}
}
sprintf(buffer, "%s: %ld.%02lds (+ %ld.%02ld)", text,
time / us.hz, time % us.hz,
diff / us.hz, diff % us.hz);
return buffer;
}
static int cpuinfo_cb(int action, struct gui_synclist *lists)
{
(void)lists;
if (action == ACTION_NONE)
action = ACTION_REDRAW;
return action;
}
static bool dbg_cpuinfo(void)
{
struct simplelist_info info;
int cpu_count = MAX(cpucount_linux(), 1);
int state_count = cpustatetimes_linux(0, states, ARRAYLEN(states));
printf("%s(): %d %d\n", __func__, cpu_count, state_count);
simplelist_info_init(&info, "CPU info:", 5 + cpu_count*(state_count+1), &state_count);
info.get_name = get_cpuinfo;
info.action_callback = cpuinfo_cb;
info.timeout = HZ;
info.hide_selection = true;
info.scroll_all = true;
return simplelist_show_list(&info);
}
#endif
#ifdef HAVE_LCD_BITMAP
#if CONFIG_CODEC != SWCODEC
#ifndef SIMULATOR
static bool dbg_audio_thread(void)
{
struct audio_debug d;
lcd_setfont(FONT_SYSFIXED);
while(1)
{
if (action_userabort(HZ/5))
return false;
audio_get_debugdata(&d);
lcd_clear_display();
lcd_putsf(0, 0, "read: %x", d.audiobuf_read);
lcd_putsf(0, 1, "write: %x", d.audiobuf_write);
lcd_putsf(0, 2, "swap: %x", d.audiobuf_swapwrite);
lcd_putsf(0, 3, "playing: %d", d.playing);
lcd_putsf(0, 4, "playable: %x", d.playable_space);
lcd_putsf(0, 5, "unswapped: %x", d.unswapped_space);
/* Playable space left */
gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
d.playable_space, HORIZONTAL);
/* Show the watermark limit */
gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
d.low_watermark_level, HORIZONTAL);
lcd_putsf(0, 7, "wm: %x - %x",
d.low_watermark_level, d.lowest_watermark_level);
lcd_update();
}
lcd_setfont(FONT_UI);
return false;
}
#endif /* !SIMULATOR */
#else /* CONFIG_CODEC == SWCODEC */
static unsigned int ticks, freq_sum;
#ifndef CPU_MULTI_FREQUENCY
static unsigned int boost_ticks;
#endif
static void dbg_audio_task(void)
{
#ifdef CPUFREQ_NORMAL
#ifndef CPU_MULTI_FREQUENCY
if(FREQ > CPUFREQ_NORMAL)
boost_ticks++;
#endif
freq_sum += FREQ/1000000; /* in MHz */
#endif
ticks++;
}
static bool dbg_buffering_thread(void)
{
int button;
int line;
bool done = false;
size_t bufused;
size_t bufsize = pcmbuf_get_bufsize();
int pcmbufdescs = pcmbuf_descs();
struct buffering_debug d;
size_t filebuflen = audio_get_filebuflen();
/* This is a size_t, but call it a long so it puts a - when it's bad. */
#ifndef CPU_MULTI_FREQUENCY
boost_ticks = 0;
#endif
ticks = freq_sum = 0;
tick_add_task(dbg_audio_task);
FOR_NB_SCREENS(i)
screens[i].setfont(FONT_SYSFIXED);
while(!done)
{
button = get_action(CONTEXT_STD,HZ/5);
switch(button)
{
case ACTION_STD_NEXT:
audio_next();
break;
case ACTION_STD_PREV:
audio_prev();
break;
case ACTION_STD_CANCEL:
done = true;
break;
}
buffering_get_debugdata(&d);
bufused = bufsize - pcmbuf_free();
FOR_NB_SCREENS(i)
{
line = 0;
screens[i].clear_display();
screens[i].putsf(0, line++, "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
bufsize, 0, bufused, HORIZONTAL);
line++;
screens[i].putsf(0, line++, "alloc: %6ld/%ld", audio_filebufused(),
(long) filebuflen);
#if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
if (screens[i].lcdheight > 80)
{
gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
filebuflen, 0, audio_filebufused(), HORIZONTAL);
line++;
screens[i].putsf(0, line++, "real: %6ld/%ld", (long)d.buffered_data,
(long)filebuflen);
gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
line++;
}
#endif
screens[i].putsf(0, line++, "usefl: %6ld/%ld", (long)(d.useful_data),
(long)filebuflen);
#if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
if (screens[i].lcdheight > 80)
{
gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
filebuflen, 0, d.useful_data, HORIZONTAL);
line++;
}
#endif
screens[i].putsf(0, line++, "data_rem: %ld", (long)d.data_rem);
screens[i].putsf(0, line++, "track count: %2d", audio_track_count());
screens[i].putsf(0, line++, "handle count: %d", (int)d.num_handles);
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
screens[i].putsf(0, line++, "cpu freq: %3dMHz",
(int)((FREQ + 500000) / 1000000));
#endif
if (ticks > 0)
{
int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
#ifdef CPU_MULTI_FREQUENCY
int boostquota = (avgclock * 100 - CPUFREQ_NORMAL/1000) /
((CPUFREQ_MAX - CPUFREQ_NORMAL) / 1000000); /* in 0.1 % */
#else
int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
#endif
screens[i].putsf(0, line++, "boost:%3d.%d%% (%d.%dMHz)",
boostquota/10, boostquota%10, avgclock/10, avgclock%10);
}
screens[i].putsf(0, line++, "pcmbufdesc: %2d/%2d",
pcmbuf_used_descs(), pcmbufdescs);
screens[i].putsf(0, line++, "watermark: %6d",
(int)(d.watermark));
screens[i].update();
}
}
tick_remove_task(dbg_audio_task);
FOR_NB_SCREENS(i)
screens[i].setfont(FONT_UI);
return false;
}
#endif /* CONFIG_CODEC */
#endif /* HAVE_LCD_BITMAP */
static const char* bf_getname(int selected_item, void *data,
char *buffer, size_t buffer_len)
{
(void)data;
core_print_block_at(selected_item, buffer, buffer_len);
return buffer;
}
static int bf_action_cb(int action, struct gui_synclist* list)
{
if (action == ACTION_STD_OK)
{
if (gui_synclist_get_sel_pos(list) == 0 && core_test_free())
{
splash(HZ, "Freed test handle. New alloc should trigger compact");
}
else
{
splash(HZ/1, "Attempting a 64k allocation");
int handle = core_alloc("test", 64<<10);
splash(HZ/2, (handle > 0) ? "Success":"Fail");
/* for some reason simplelist doesn't allow adding items here if
* info.get_name is given, so use normal list api */
gui_synclist_set_nb_items(list, core_get_num_blocks());
if (handle > 0)
core_free(handle);
}
action = ACTION_REDRAW;
}
return action;
}
static bool dbg_buflib_allocs(void)
{
struct simplelist_info info;
simplelist_info_init(&info, "mem allocs", core_get_num_blocks(), NULL);
info.get_name = bf_getname;
info.action_callback = bf_action_cb;
info.timeout = HZ;
return simplelist_show_list(&info);
}
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
static const char* dbg_partitions_getname(int selected_item, void *data,
char *buffer, size_t buffer_len)
{
(void)data;
int partition = selected_item/2;
struct partinfo* p = disk_partinfo(partition);
if (selected_item%2)
{
snprintf(buffer, buffer_len, " T:%x %ld MB", p->type, p->size / ( 2048 / ( SECTOR_SIZE / 512 )));
}
else
{
snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p->start);
}
return buffer;
}
static bool dbg_partitions(void)
{
struct simplelist_info info;
simplelist_info_init(&info, "Partition Info", 4, NULL);
info.selection_size = 2;
info.hide_selection = true;
info.scroll_all = true;
info.get_name = dbg_partitions_getname;
return simplelist_show_list(&info);
}
#endif /* PLATFORM_NATIVE */
#if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
static bool dbg_spdif(void)
{
int line;
unsigned int control;
int x;
char *s;
int category;
int generation;
unsigned int interruptstat;
bool valnogood, symbolerr, parityerr;
bool done = false;
bool spdif_src_on;
int spdif_source = spdif_get_output_source(&spdif_src_on);
spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
lcd_clear_display();
lcd_setfont(FONT_SYSFIXED);
#ifdef HAVE_SPDIF_POWER
spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
#endif
while (!done)
{
line = 0;
control = EBU1RCVCCHANNEL1;
interruptstat = INTERRUPTSTAT;
INTERRUPTCLEAR = 0x03c00000;
valnogood = (interruptstat & 0x01000000)?true:false;
symbolerr = (interruptstat & 0x00800000)?true:false;
parityerr = (interruptstat & 0x00400000)?true:false;
lcd_putsf(0, line++, "Val: %s Sym: %s Par: %s",
valnogood?"--":"OK",
symbolerr?"--":"OK",
parityerr?"--":"OK");
lcd_putsf(0, line++, "Status word: %08x", (int)control);
line++;
x = control >> 31;
lcd_putsf(0, line++, "PRO: %d (%s)",
x, x?"Professional":"Consumer");
x = (control >> 30) & 1;
lcd_putsf(0, line++, "Audio: %d (%s)",
x, x?"Non-PCM":"PCM");
x = (control >> 29) & 1;
lcd_putsf(0, line++, "Copy: %d (%s)",
x, x?"Permitted":"Inhibited");
x = (control >> 27) & 7;
switch(x)
{
case 0:
s = "None";
break;
case 1:
s = "50/15us";
break;
default:
s = "Reserved";
break;
}
|