blob: 48ebec2279061ea8dbce0cb7d9f2aaf7d81163c0 [file] [log] [blame]
Björn Stenberg803f47b2002-07-15 11:23:24 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Heikki Hannikainen
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Björn Stenberg803f47b2002-07-15 11:23:24 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "config.h"
Michael Sevakisd8922142008-05-25 01:38:08 +000023#include <stdlib.h>
Björn Stenberg803f47b2002-07-15 11:23:24 +000024#include <stdio.h>
25#include <stdbool.h>
Hardeep Sidhu95132362003-08-01 16:05:40 +000026#include <string.h>
Björn Stenberg803f47b2002-07-15 11:23:24 +000027#include "lcd.h"
Jonathan Gordon101693f2011-11-15 13:22:02 +000028#include "lang.h"
Björn Stenberg803f47b2002-07-15 11:23:24 +000029#include "menu.h"
30#include "debug_menu.h"
31#include "kernel.h"
Jens Arnolddfac61e2008-03-01 10:47:21 +000032#include "structec.h"
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +000033#include "action.h"
Björn Stenberg803f47b2002-07-15 11:23:24 +000034#include "debug.h"
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +000035#include "thread.h"
Heikki Hannikainen6eb42542002-08-06 10:52:51 +000036#include "powermgmt.h"
37#include "system.h"
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +000038#include "font.h"
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +000039#include "audio.h"
Linus Nielsen Feltzingf1f7bbe2004-03-22 11:48:13 +000040#include "mp3_playback.h"
Björn Stenbergae22de22002-12-02 16:07:56 +000041#include "settings.h"
Jonathan Gordoncd1ccad2007-03-26 12:09:08 +000042#include "list.h"
43#include "statusbar.h"
Linus Nielsen Feltzingf3ad6192004-02-16 12:04:55 +000044#include "dir.h"
45#include "panic.h"
Linus Nielsen Feltzingb81a3c52004-03-25 12:29:34 +000046#include "screens.h"
Linus Nielsen Feltzingade5d7b2004-07-26 16:06:59 +000047#include "misc.h"
Kevin Ferraree991bee2005-11-16 15:12:15 +000048#include "splash.h"
Jonathan Gordon101693f2011-11-15 13:22:02 +000049#include "shortcuts.h"
Miika Pekkarinen7c4e0c82006-03-26 11:33:42 +000050#include "dircache.h"
Jonathan Gordone385ee12008-12-31 05:59:26 +000051#include "viewport.h"
Jonathan Gordon710ccb72006-10-25 10:17:57 +000052#ifdef HAVE_TAGCACHE
Miika Pekkarinen7c4e0c82006-03-26 11:33:42 +000053#include "tagcache.h"
Jonathan Gordon710ccb72006-10-25 10:17:57 +000054#endif
Rafaël Carréb6122632012-01-07 19:35:46 +000055#ifdef HAVE_REMOTE_LCD
Linus Nielsen Feltzing00811842006-02-17 22:38:38 +000056#include "lcd-remote.h"
Rafaël Carréb6122632012-01-07 19:35:46 +000057#endif
Jens Arnold106f7732006-05-07 22:19:29 +000058#include "crc32.h"
Miika Pekkarinen954b7322006-08-05 20:19:10 +000059#include "logf.h"
Thomas Martitz35e8b142010-06-21 16:53:00 +000060#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
Steve Bavin2c2b50a2006-10-04 07:29:50 +000061#include "disk.h"
62#include "adc.h"
Steve Bavin2c2b50a2006-10-04 07:29:50 +000063#include "usb.h"
64#include "rtc.h"
Frank Gevaerts2f8a0082008-11-01 16:14:28 +000065#include "storage.h"
Michael Sevakis6db80022017-03-12 22:05:44 -040066#include "fs_defines.h"
Steve Bavin2c2b50a2006-10-04 07:29:50 +000067#include "eeprom_24cxx.h"
Frank Gevaerts19d1cac2008-10-31 21:25:04 +000068#if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
Frank Gevaertsa0557b22010-06-05 21:12:16 +000069#include "sdmmc.h"
Linus Nielsen Feltzing875bf5e2002-10-15 08:08:35 +000070#endif
Frank Gevaerts2f8a0082008-11-01 16:14:28 +000071#if (CONFIG_STORAGE & STORAGE_ATA)
72#include "ata.h"
73#endif
Thomas Martitz77f19f72014-02-07 18:12:31 +010074#endif /* CONFIG_PLATFORM & PLATFORM_NATIVE */
Thomas Martitz05f12e02011-12-31 13:34:56 +000075#include "power.h"
Steve Bavin2c2b50a2006-10-04 07:29:50 +000076
Amaury Pouly0fe7b8b2017-11-03 20:14:01 +010077#if ((CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) \
78 || defined(SONY_NWZ_LINUX)) \
Amaury Pouly1015e1f2017-11-06 21:53:03 +010079 && CONFIG_TUNER != 0
Lorenzo Miori3cad5572012-04-07 10:30:23 +020080#include "tuner.h"
81#include "radio.h"
82#endif
83
Steve Bavin2c2b50a2006-10-04 07:29:50 +000084#ifdef HAVE_LCD_BITMAP
Jonathan Gordon62885232006-11-19 14:11:42 +000085#include "scrollbar.h"
Steve Bavin2c2b50a2006-10-04 07:29:50 +000086#include "peakmeter.h"
Jonathan Gordonaaf30652013-02-12 21:00:05 +110087#include "skin_engine/skin_engine.h"
Jens Arnold6f9a7eb2004-10-06 20:43:12 +000088#endif
Daniel Stenbergedc07922005-05-30 13:00:43 +000089#include "logfdisp.h"
Thomas Martitzd0b72e22011-08-30 14:01:33 +000090#include "core_alloc.h"
Jens Arnoldd6c05452005-08-29 21:15:27 +000091#if CONFIG_CODEC == SWCODEC
Miika Pekkarinenb0e78a42005-07-13 13:13:10 +000092#include "pcmbuf.h"
Nicolas Pennequin3e3c43c2007-10-25 21:27:45 +000093#include "buffering.h"
Steve Bavinc9df8fd2008-03-28 11:24:24 +000094#include "playback.h"
Michael Sevakiscc50c142006-11-13 23:21:54 +000095#if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
96#include "spdif.h"
97#endif
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +000098#endif
Steve Bavin338d94f2007-02-01 10:47:22 +000099#ifdef IRIVER_H300_SERIES
100#include "pcf50606.h" /* for pcf50606_read */
101#endif
Michael Sevakis89a38d42007-03-11 13:59:31 +0000102#ifdef IAUDIO_X5
103#include "ds2411.h"
104#endif
Jens Arnold8636e692007-04-11 23:51:00 +0000105#include "hwcompat.h"
Michael Giacomelli054447f2008-02-10 05:39:20 +0000106#include "button.h"
107#if CONFIG_RTC == RTC_PCF50605
108#include "pcf50605.h"
109#endif
Thomas Martitz4c48b592009-08-16 22:20:11 +0000110#include "appevents.h"
Karl Kurbjund3c0a7f2007-11-10 22:12:54 +0000111
Mihail Zenkovce90c042016-03-30 12:50:40 +0000112#if defined(HAVE_AS3514) && CONFIG_CHARGING
Dave Chapman42f77d42008-10-31 00:16:42 +0000113#include "ascodec.h"
Barry Wardell46973f72008-03-04 14:36:22 +0000114#endif
Barry Wardell0449c0e2008-03-04 14:31:14 +0000115
Michael Sparmann30d664b2009-10-10 22:02:23 +0000116#ifdef IPOD_NANO2G
117#include "pmu-target.h"
118#endif
119
Mihail Zenkovce90c042016-03-30 12:50:40 +0000120#ifdef HAVE_USBSTACK
121#include "usb_core.h"
Frank Gevaerts49bca7f2009-07-18 13:27:41 +0000122#endif
123
Bertrik Sikkenc0edce82010-09-20 19:37:17 +0000124#if defined(IPOD_ACCESSORY_PROTOCOL)
125#include "iap.h"
126#endif
127
Thomas Martitzdac40fd2013-07-02 08:24:00 +0200128#include "talk.h"
129
William Wilgus41869a62017-02-05 21:07:20 +0100130#if defined(HAVE_BOOTDATA) && !defined(SIMULATOR)
131#include "bootdata.h"
132#endif
133
Nils Wallménius3200d042009-08-20 16:47:44 +0000134static const char* threads_getname(int selected_item, void *data,
135 char *buffer, size_t buffer_len)
Jonathan Gordoncd1ccad2007-03-26 12:09:08 +0000136{
137 (void)data;
Michael Sevakis7914e902007-09-28 10:20:02 +0000138
139#if NUM_CORES > 1
140 if (selected_item < (int)NUM_CORES)
141 {
Michael Sevakis981d0282014-08-08 01:39:29 -0400142 struct core_debug_info coreinfo;
143 core_get_debug_info(selected_item, &coreinfo);
Nils Wallménius68489612008-04-09 15:25:17 +0000144 snprintf(buffer, buffer_len, "Idle (%d): %2d%%", selected_item,
Michael Sevakis981d0282014-08-08 01:39:29 -0400145 coreinfo.idle_stack_usage);
Michael Sevakis7914e902007-09-28 10:20:02 +0000146 return buffer;
147 }
148
149 selected_item -= NUM_CORES;
150#endif
151
Michael Sevakis6ed00872014-08-08 06:33:51 -0400152 const char *fmtstr = "%2d: ---";
153
Michael Sevakis981d0282014-08-08 01:39:29 -0400154 struct thread_debug_info threadinfo;
Michael Sevakis6ed00872014-08-08 06:33:51 -0400155 if (thread_get_debug_info(selected_item, &threadinfo) > 0)
Miika Pekkarinen66258a32007-03-26 16:55:17 +0000156 {
Michael Sevakis6ed00872014-08-08 06:33:51 -0400157 fmtstr = "%2d:" IF_COP(" (%d)") " %s" IF_PRIO(" %d %d")
158 IFN_SDL(" %2d%%") " %s";
Miika Pekkarinen66258a32007-03-26 16:55:17 +0000159 }
Michael Sevakis7914e902007-09-28 10:20:02 +0000160
Michael Sevakis6ed00872014-08-08 06:33:51 -0400161 snprintf(buffer, buffer_len, fmtstr,
Miika Pekkarinen66258a32007-03-26 16:55:17 +0000162 selected_item,
Michael Sevakis6ed00872014-08-08 06:33:51 -0400163 IF_COP(threadinfo.core,)
Michael Sevakis981d0282014-08-08 01:39:29 -0400164 threadinfo.statusstr,
Michael Sevakis6ed00872014-08-08 06:33:51 -0400165 IF_PRIO(threadinfo.base_priority, threadinfo.current_priority,)
166 IFN_SDL(threadinfo.stack_usage,)
Michael Sevakis981d0282014-08-08 01:39:29 -0400167 threadinfo.name);
Michael Sevakis7914e902007-09-28 10:20:02 +0000168
Jonathan Gordoncd1ccad2007-03-26 12:09:08 +0000169 return buffer;
170}
Nils Wallménius3200d042009-08-20 16:47:44 +0000171
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000172static int dbg_threads_action_callback(int action, struct gui_synclist *lists)
Jonathan Gordoncd41bfa2007-04-05 04:52:53 +0000173{
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000174 (void)lists;
Michael Sevakis7cbf70c2008-02-28 16:48:18 +0000175 if (action == ACTION_NONE)
176 action = ACTION_REDRAW;
Jonathan Gordoncd41bfa2007-04-05 04:52:53 +0000177 return action;
178}
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000179/* Test code!!! */
Jens Arnold314f3b52006-12-12 22:22:21 +0000180static bool dbg_os(void)
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000181{
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000182 struct simplelist_info info;
Jonathan Gordon616971c2007-10-21 06:42:52 +0000183 simplelist_info_init(&info, IF_COP("Core and ") "Stack usage:",
Michael Sevakis6ed00872014-08-08 06:33:51 -0400184 MAXTHREADS IF_COP( + NUM_CORES ), NULL);
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000185 info.hide_selection = true;
Jonathan Gordon82c1aa82008-05-05 07:11:27 +0000186 info.scroll_all = true;
Michael Sevakisa16035d2007-07-15 18:25:39 +0000187 info.action_callback = dbg_threads_action_callback;
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000188 info.get_name = threads_getname;
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000189 return simplelist_show_list(&info);
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000190}
Jonathan Gordoncd1ccad2007-03-26 12:09:08 +0000191
Thomas Martitz287454d2011-12-19 15:42:04 +0000192#ifdef __linux__
193#include "cpuinfo-linux.h"
194
195#define MAX_STATES 16
196static struct time_state states[MAX_STATES];
197
198static const char* get_cpuinfo(int selected_item, void *data,
199 char *buffer, size_t buffer_len)
200{
201 (void)data;(void)buffer_len;
202 const char* text;
203 long time, diff;
204 struct cpuusage us;
205 static struct cpuusage last_us;
206 int state_count = *(int*)data;
207
208 if (cpuusage_linux(&us) != 0)
209 return NULL;
210
211 switch(selected_item)
212 {
213 case 0:
214 diff = abs(last_us.usage - us.usage);
215 sprintf(buffer, "Usage: %ld.%02ld%% (%c %ld.%02ld)",
216 us.usage/100, us.usage%100,
217 (us.usage >= last_us.usage) ? '+':'-',
218 diff/100, diff%100);
219 last_us.usage = us.usage;
220 return buffer;
221 case 1:
222 text = "User";
223 time = us.utime;
224 diff = us.utime - last_us.utime;
225 last_us.utime = us.utime;
226 break;
227 case 2:
228 text = "Sys";
229 time = us.stime;
230 diff = us.stime - last_us.stime;
231 last_us.stime = us.stime;
232 break;
233 case 3:
234 text = "Real";
235 time = us.rtime;
236 diff = us.rtime - last_us.rtime;
237 last_us.rtime = us.rtime;
238 break;
239 case 4:
240 return "*** Per CPU freq stats ***";
241 default:
242 {
243 int cpu = (selected_item - 5) / (state_count + 1);
244 int cpu_line = (selected_item - 5) % (state_count + 1);
Amaury Pouly4382f872017-10-06 18:31:35 +0200245
246 /* scaling info */
Udo Schläpfer6d3dc8f2014-12-13 20:45:03 +0100247 int min_freq = min_scaling_frequency(cpu);
248 int cur_freq = current_scaling_frequency(cpu);
Amaury Pouly4382f872017-10-06 18:31:35 +0200249 /* fallback if scaling frequency is not available */
250 if(cur_freq <= 0)
251 cur_freq = frequency_linux(cpu);
Udo Schläpfer6d3dc8f2014-12-13 20:45:03 +0100252 int max_freq = max_scaling_frequency(cpu);
253 char governor[20];
254 bool have_governor = current_scaling_governor(cpu, governor, sizeof(governor));
255 if(cpu_line == 0)
256 {
257 sprintf(buffer,
258 " CPU%d: %s: %d/%d/%d MHz",
259 cpu,
260 have_governor ? governor : "Min/Cur/Max freq",
261 min_freq > 0 ? min_freq/1000 : -1,
262 cur_freq > 0 ? cur_freq/1000 : -1,
263 max_freq > 0 ? max_freq/1000 : -1);
264 }
Thomas Martitz287454d2011-12-19 15:42:04 +0000265 else
266 {
267 cpustatetimes_linux(cpu, states, ARRAYLEN(states));
268 snprintf(buffer, buffer_len, " %ld %ld",
269 states[cpu_line-1].frequency,
270 states[cpu_line-1].time);
271 }
272 return buffer;
273 }
274 }
275 sprintf(buffer, "%s: %ld.%02lds (+ %ld.%02ld)", text,
276 time / us.hz, time % us.hz,
277 diff / us.hz, diff % us.hz);
278 return buffer;
279}
280
281static int cpuinfo_cb(int action, struct gui_synclist *lists)
282{
283 (void)lists;
284 if (action == ACTION_NONE)
285 action = ACTION_REDRAW;
286 return action;
287}
288
289static bool dbg_cpuinfo(void)
290{
291 struct simplelist_info info;
292 int cpu_count = MAX(cpucount_linux(), 1);
293 int state_count = cpustatetimes_linux(0, states, ARRAYLEN(states));
294 printf("%s(): %d %d\n", __func__, cpu_count, state_count);
295 simplelist_info_init(&info, "CPU info:", 5 + cpu_count*(state_count+1), &state_count);
296 info.get_name = get_cpuinfo;
297 info.action_callback = cpuinfo_cb;
298 info.timeout = HZ;
299 info.hide_selection = true;
300 info.scroll_all = true;
301 return simplelist_show_list(&info);
302}
303
304#endif
305
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000306#ifdef HAVE_LCD_BITMAP
Jens Arnoldd6c05452005-08-29 21:15:27 +0000307#if CONFIG_CODEC != SWCODEC
Steve Bavin2c2b50a2006-10-04 07:29:50 +0000308#ifndef SIMULATOR
Jens Arnold314f3b52006-12-12 22:22:21 +0000309static bool dbg_audio_thread(void)
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000310{
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +0000311 struct audio_debug d;
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000312
Linus Nielsen Feltzing44bba0f2005-06-22 21:37:00 +0000313 lcd_setfont(FONT_SYSFIXED);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000314
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000315 while(1)
316 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000317 if (action_userabort(HZ/5))
318 return false;
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000319
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +0000320 audio_get_debugdata(&d);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000321
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000322 lcd_clear_display();
323
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000324 lcd_putsf(0, 0, "read: %x", d.audiobuf_read);
325 lcd_putsf(0, 1, "write: %x", d.audiobuf_write);
326 lcd_putsf(0, 2, "swap: %x", d.audiobuf_swapwrite);
327 lcd_putsf(0, 3, "playing: %d", d.playing);
328 lcd_putsf(0, 4, "playable: %x", d.playable_space);
329 lcd_putsf(0, 5, "unswapped: %x", d.unswapped_space);
Linus Nielsen Feltzingbf303de2002-10-15 07:23:18 +0000330
Linus Nielsen Feltzing24410612004-07-08 13:14:44 +0000331 /* Playable space left */
Jonathan Gordon62885232006-11-19 14:11:42 +0000332 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
Linus Nielsen Feltzing24410612004-07-08 13:14:44 +0000333 d.playable_space, HORIZONTAL);
Linus Nielsen Feltzingbf303de2002-10-15 07:23:18 +0000334
Linus Nielsen Feltzing24410612004-07-08 13:14:44 +0000335 /* Show the watermark limit */
Jonathan Gordon62885232006-11-19 14:11:42 +0000336 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
Linus Nielsen Feltzing24410612004-07-08 13:14:44 +0000337 d.low_watermark_level, HORIZONTAL);
Linus Nielsen Feltzingbf303de2002-10-15 07:23:18 +0000338
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000339 lcd_putsf(0, 7, "wm: %x - %x",
Nils Wallméniusa9713342009-10-17 13:00:58 +0000340 d.low_watermark_level, d.lowest_watermark_level);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000341
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000342 lcd_update();
343 }
Jonathan Gordon8b9fdb52009-01-05 09:59:11 +0000344 lcd_setfont(FONT_UI);
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000345 return false;
346}
Steve Bavin2c2b50a2006-10-04 07:29:50 +0000347#endif /* !SIMULATOR */
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000348#else /* CONFIG_CODEC == SWCODEC */
Michael Sevakis6d2e7762011-01-22 18:30:24 +0000349static unsigned int ticks, freq_sum;
350#ifndef CPU_MULTI_FREQUENCY
351static unsigned int boost_ticks;
352#endif
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000353
Jens Arnold314f3b52006-12-12 22:22:21 +0000354static void dbg_audio_task(void)
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000355{
Thomas Martitz35e8b142010-06-21 16:53:00 +0000356#ifdef CPUFREQ_NORMAL
Michael Sevakis6d2e7762011-01-22 18:30:24 +0000357#ifndef CPU_MULTI_FREQUENCY
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000358 if(FREQ > CPUFREQ_NORMAL)
359 boost_ticks++;
Michael Sevakis6d2e7762011-01-22 18:30:24 +0000360#endif
Andree Buschmann23ee7742008-04-19 10:43:00 +0000361 freq_sum += FREQ/1000000; /* in MHz */
Andree Buschmann6592f942008-04-19 11:17:06 +0000362#endif
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000363 ticks++;
364}
365
Nicolas Pennequin3e3c43c2007-10-25 21:27:45 +0000366static bool dbg_buffering_thread(void)
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000367{
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000368 int button;
Mihail Zenkovce90c042016-03-30 12:50:40 +0000369 int line;
Linus Nielsen Feltzingfcc282c2005-06-22 14:09:07 +0000370 bool done = false;
Brandon Low75de60b2006-04-25 20:32:38 +0000371 size_t bufused;
Brandon Low413da2a2006-02-07 20:38:55 +0000372 size_t bufsize = pcmbuf_get_bufsize();
373 int pcmbufdescs = pcmbuf_descs();
Nicolas Pennequin3e3c43c2007-10-25 21:27:45 +0000374 struct buffering_debug d;
Jeffrey Goode9a4420b2009-10-31 19:17:36 +0000375 size_t filebuflen = audio_get_filebuflen();
376 /* This is a size_t, but call it a long so it puts a - when it's bad. */
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000377
Michael Sevakis6d2e7762011-01-22 18:30:24 +0000378#ifndef CPU_MULTI_FREQUENCY
379 boost_ticks = 0;
380#endif
381 ticks = freq_sum = 0;
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000382
383 tick_add_task(dbg_audio_task);
Mihail Zenkovce90c042016-03-30 12:50:40 +0000384
Jonathan Gordon341cb852010-04-25 12:01:25 +0000385 FOR_NB_SCREENS(i)
386 screens[i].setfont(FONT_SYSFIXED);
Mihail Zenkovce90c042016-03-30 12:50:40 +0000387
Linus Nielsen Feltzingfcc282c2005-06-22 14:09:07 +0000388 while(!done)
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000389 {
Michael Giacomellib9eb1822008-07-17 18:36:47 +0000390 button = get_action(CONTEXT_STD,HZ/5);
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000391 switch(button)
392 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000393 case ACTION_STD_NEXT:
Brandon Low413da2a2006-02-07 20:38:55 +0000394 audio_next();
395 break;
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000396 case ACTION_STD_PREV:
Brandon Low413da2a2006-02-07 20:38:55 +0000397 audio_prev();
398 break;
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000399 case ACTION_STD_CANCEL:
Linus Nielsen Feltzingfcc282c2005-06-22 14:09:07 +0000400 done = true;
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000401 break;
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000402 }
Nicolas Pennequin3e3c43c2007-10-25 21:27:45 +0000403
404 buffering_get_debugdata(&d);
Brandon Low75de60b2006-04-25 20:32:38 +0000405 bufused = bufsize - pcmbuf_free();
406
Mihail Zenkovce90c042016-03-30 12:50:40 +0000407 FOR_NB_SCREENS(i)
Jonathan Gordon341cb852010-04-25 12:01:25 +0000408 {
409 line = 0;
410 screens[i].clear_display();
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000411
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000412
Jonathan Gordon341cb852010-04-25 12:01:25 +0000413 screens[i].putsf(0, line++, "pcm: %6ld/%ld", (long) bufused, (long) bufsize);
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000414
Jonathan Gordon341cb852010-04-25 12:01:25 +0000415 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
416 bufsize, 0, bufused, HORIZONTAL);
417 line++;
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000418
Jonathan Gordon341cb852010-04-25 12:01:25 +0000419 screens[i].putsf(0, line++, "alloc: %6ld/%ld", audio_filebufused(),
420 (long) filebuflen);
Nicolas Pennequin3e3c43c2007-10-25 21:27:45 +0000421
Jonathan Gordon44e51ce2010-04-25 12:14:28 +0000422#if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
Jonathan Gordon341cb852010-04-25 12:01:25 +0000423 if (screens[i].lcdheight > 80)
424 {
425 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
426 filebuflen, 0, audio_filebufused(), HORIZONTAL);
427 line++;
428
429 screens[i].putsf(0, line++, "real: %6ld/%ld", (long)d.buffered_data,
430 (long)filebuflen);
431
432 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
433 filebuflen, 0, (long)d.buffered_data, HORIZONTAL);
434 line++;
435 }
Nicolas Pennequin3e3c43c2007-10-25 21:27:45 +0000436#endif
437
Jonathan Gordon341cb852010-04-25 12:01:25 +0000438 screens[i].putsf(0, line++, "usefl: %6ld/%ld", (long)(d.useful_data),
Nicolas Pennequin3e3c43c2007-10-25 21:27:45 +0000439 (long)filebuflen);
Nicolas Pennequin3e3c43c2007-10-25 21:27:45 +0000440
Jonathan Gordon44e51ce2010-04-25 12:14:28 +0000441#if LCD_HEIGHT > 80 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_HEIGHT > 80)
Jonathan Gordon341cb852010-04-25 12:01:25 +0000442 if (screens[i].lcdheight > 80)
443 {
444 gui_scrollbar_draw(&screens[i],0, line*8, screens[i].lcdwidth, 6,
445 filebuflen, 0, d.useful_data, HORIZONTAL);
446 line++;
447 }
Nicolas Pennequin3e3c43c2007-10-25 21:27:45 +0000448#endif
449
Jonathan Gordon341cb852010-04-25 12:01:25 +0000450 screens[i].putsf(0, line++, "data_rem: %ld", (long)d.data_rem);
Nicolas Pennequin3e3c43c2007-10-25 21:27:45 +0000451
William Wilgus7a132a22018-10-18 09:57:20 -0400452 screens[i].putsf(0, line++, "track count: %2u", audio_track_count());
Nicolas Pennequin3e3c43c2007-10-25 21:27:45 +0000453
Jonathan Gordon341cb852010-04-25 12:01:25 +0000454 screens[i].putsf(0, line++, "handle count: %d", (int)d.num_handles);
Linus Nielsen Feltzing17098e12005-06-22 20:37:31 +0000455
Thomas Martitz35e8b142010-06-21 16:53:00 +0000456#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
Jonathan Gordon341cb852010-04-25 12:01:25 +0000457 screens[i].putsf(0, line++, "cpu freq: %3dMHz",
458 (int)((FREQ + 500000) / 1000000));
Steve Bavin2c2b50a2006-10-04 07:29:50 +0000459#endif
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000460
Jonathan Gordon341cb852010-04-25 12:01:25 +0000461 if (ticks > 0)
462 {
Jonathan Gordon341cb852010-04-25 12:01:25 +0000463 int avgclock = freq_sum * 10 / ticks; /* in 100 kHz */
Michael Sevakis6d2e7762011-01-22 18:30:24 +0000464#ifdef CPU_MULTI_FREQUENCY
465 int boostquota = (avgclock * 100 - CPUFREQ_NORMAL/1000) /
466 ((CPUFREQ_MAX - CPUFREQ_NORMAL) / 1000000); /* in 0.1 % */
467#else
468 int boostquota = boost_ticks * 1000 / ticks; /* in 0.1 % */
469#endif
Jonathan Gordon341cb852010-04-25 12:01:25 +0000470 screens[i].putsf(0, line++, "boost:%3d.%d%% (%d.%dMHz)",
471 boostquota/10, boostquota%10, avgclock/10, avgclock%10);
472 }
473
474 screens[i].putsf(0, line++, "pcmbufdesc: %2d/%2d",
475 pcmbuf_used_descs(), pcmbufdescs);
476 screens[i].putsf(0, line++, "watermark: %6d",
477 (int)(d.watermark));
478
479 screens[i].update();
Steve Bavin21d538b2007-05-14 09:56:55 +0000480 }
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000481 }
482
483 tick_remove_task(dbg_audio_task);
Mihail Zenkovce90c042016-03-30 12:50:40 +0000484
Jonathan Gordon341cb852010-04-25 12:01:25 +0000485 FOR_NB_SCREENS(i)
486 screens[i].setfont(FONT_UI);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000487
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000488 return false;
489}
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000490#endif /* CONFIG_CODEC */
491#endif /* HAVE_LCD_BITMAP */
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000492
Thomas Martitzd0b72e22011-08-30 14:01:33 +0000493static const char* bf_getname(int selected_item, void *data,
494 char *buffer, size_t buffer_len)
495{
496 (void)data;
497 core_print_block_at(selected_item, buffer, buffer_len);
498 return buffer;
499}
500
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000501static int bf_action_cb(int action, struct gui_synclist* list)
502{
503 if (action == ACTION_STD_OK)
504 {
Thomas Martitz4478b252011-10-05 18:32:19 +0000505 if (gui_synclist_get_sel_pos(list) == 0 && core_test_free())
506 {
507 splash(HZ, "Freed test handle. New alloc should trigger compact");
508 }
509 else
510 {
511 splash(HZ/1, "Attempting a 64k allocation");
512 int handle = core_alloc("test", 64<<10);
513 splash(HZ/2, (handle > 0) ? "Success":"Fail");
514 /* for some reason simplelist doesn't allow adding items here if
515 * info.get_name is given, so use normal list api */
516 gui_synclist_set_nb_items(list, core_get_num_blocks());
517 if (handle > 0)
518 core_free(handle);
519 }
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000520 action = ACTION_REDRAW;
521 }
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000522 return action;
523}
524
Thomas Martitzd0b72e22011-08-30 14:01:33 +0000525static bool dbg_buflib_allocs(void)
526{
527 struct simplelist_info info;
528 simplelist_info_init(&info, "mem allocs", core_get_num_blocks(), NULL);
529 info.get_name = bf_getname;
Thomas Martitzbaa070c2011-08-30 14:01:45 +0000530 info.action_callback = bf_action_cb;
Jonathan Gordonaaf30652013-02-12 21:00:05 +1100531 info.timeout = HZ;
Thomas Martitzd0b72e22011-08-30 14:01:33 +0000532 return simplelist_show_list(&info);
533}
534
Thomas Martitz35e8b142010-06-21 16:53:00 +0000535#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
Nils Wallménius3200d042009-08-20 16:47:44 +0000536static const char* dbg_partitions_getname(int selected_item, void *data,
537 char *buffer, size_t buffer_len)
Jonathan Gordoncd41bfa2007-04-05 04:52:53 +0000538{
539 (void)data;
540 int partition = selected_item/2;
Michael Sevakis7d1a47c2013-08-05 22:02:45 -0400541
542 struct partinfo p;
543 if (!disk_partinfo(partition, &p))
544 return buffer;
545
Jonathan Gordoncd41bfa2007-04-05 04:52:53 +0000546 if (selected_item%2)
547 {
Michael Sevakis7d1a47c2013-08-05 22:02:45 -0400548 snprintf(buffer, buffer_len, " T:%x %ld MB", p.type,
549 p.size / ( 2048 / ( SECTOR_SIZE / 512 )));
Jonathan Gordoncd41bfa2007-04-05 04:52:53 +0000550 }
551 else
552 {
Michael Sevakis7d1a47c2013-08-05 22:02:45 -0400553 snprintf(buffer, buffer_len, "P%d: S:%lx", partition, p.start);
Jonathan Gordoncd41bfa2007-04-05 04:52:53 +0000554 }
555 return buffer;
556}
557
Rafaël Carréaf760672012-01-04 05:21:31 +0000558static bool dbg_partitions(void)
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000559{
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000560 struct simplelist_info info;
Solomon Peachy4f469e92019-07-29 21:25:37 -0400561 simplelist_info_init(&info, "Partition Info", NUM_DRIVES * 4, NULL);
Jonathan Gordon616971c2007-10-21 06:42:52 +0000562 info.selection_size = 2;
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000563 info.hide_selection = true;
Jonathan Gordon82c1aa82008-05-05 07:11:27 +0000564 info.scroll_all = true;
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000565 info.get_name = dbg_partitions_getname;
Jonathan Gordon5f893be2007-10-20 12:32:55 +0000566 return simplelist_show_list(&info);
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000567}
Thomas Martitz35e8b142010-06-21 16:53:00 +0000568#endif /* PLATFORM_NATIVE */
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000569
Linus Nielsen Feltzinga6fb3932006-03-18 23:42:34 +0000570#if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
Jens Arnold314f3b52006-12-12 22:22:21 +0000571static bool dbg_spdif(void)
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000572{
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000573 int line;
574 unsigned int control;
575 int x;
576 char *s;
577 int category;
578 int generation;
579 unsigned int interruptstat;
580 bool valnogood, symbolerr, parityerr;
Jens Arnold073f1972006-05-12 01:10:18 +0000581 bool done = false;
Michael Sevakiscc50c142006-11-13 23:21:54 +0000582 bool spdif_src_on;
583 int spdif_source = spdif_get_output_source(&spdif_src_on);
Michael Sevakis2d48d0f2007-06-08 23:42:04 +0000584 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000585
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000586 lcd_clear_display();
587 lcd_setfont(FONT_SYSFIXED);
Michael Sevakiscc50c142006-11-13 23:21:54 +0000588
Jens Arnold073f1972006-05-12 01:10:18 +0000589#ifdef HAVE_SPDIF_POWER
590 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
591#endif
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000592
Jens Arnold073f1972006-05-12 01:10:18 +0000593 while (!done)
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000594 {
595 line = 0;
596
597 control = EBU1RCVCCHANNEL1;
598 interruptstat = INTERRUPTSTAT;
599 INTERRUPTCLEAR = 0x03c00000;
600
601 valnogood = (interruptstat & 0x01000000)?true:false;
602 symbolerr = (interruptstat & 0x00800000)?true:false;
603 parityerr = (interruptstat & 0x00400000)?true:false;
Jens Arnoldcfb073c2005-10-03 09:24:36 +0000604
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000605 lcd_putsf(0, line++, "Val: %s Sym: %s Par: %s",
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000606 valnogood?"--":"OK",
607 symbolerr?"--":"OK",
608 parityerr?"--":"OK");
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000609
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000610 lcd_putsf(0, line++, "Status word: %08x", (int)control);
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000611
612 line++;
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000613
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000614 x = control >> 31;
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000615 lcd_putsf(0, line++, "PRO: %d (%s)",
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000616 x, x?"Professional":"Consumer");
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000617
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000618 x = (control >> 30) & 1;
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000619 lcd_putsf(0, line++, "Audio: %d (%s)",
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000620 x, x?"Non-PCM":"PCM");
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000621
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000622 x = (control >> 29) & 1;
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000623 lcd_putsf(0, line++, "Copy: %d (%s)",
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000624 x, x?"Permitted":"Inhibited");
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000625
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000626 x = (control >> 27) & 7;
627 switch(x)
628 {
629 case 0:
630 s = "None";
631 break;
632 case 1:
633 s = "50/15us";
634 break;
635 default:
636 s = "Reserved";
637 break;
638 }
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000639 lcd_putsf(0, line++, "Preemphasis: %d (%s)", x, s);
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000640
641 x = (control >> 24) & 3;
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000642 lcd_putsf(0, line++, "Mode: %d", x);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000643
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000644 category = (control >> 17) & 127;
645 switch(category)
646 {
647 case 0x00:
648 s = "General";
649 break;
650 case 0x40:
651 s = "Audio CD";
652 break;
653 default:
654 s = "Unknown";
655 }
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000656 lcd_putsf(0, line++, "Category: 0x%02x (%s)", category, s);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000657
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000658 x = (control >> 16) & 1;
659 generation = x;
660 if(((category & 0x70) == 0x10) ||
661 ((category & 0x70) == 0x40) ||
662 ((category & 0x78) == 0x38))
663 {
664 generation = !generation;
665 }
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000666 lcd_putsf(0, line++, "Generation: %d (%s)",
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000667 x, generation?"Original":"No ind.");
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000668
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000669 x = (control >> 12) & 15;
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000670 lcd_putsf(0, line++, "Source: %d", x);
Nils Wallméniusa9713342009-10-17 13:00:58 +0000671
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000672
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000673 x = (control >> 8) & 15;
674 switch(x)
675 {
676 case 0:
677 s = "Unspecified";
678 break;
679 case 8:
680 s = "A (Left)";
681 break;
682 case 4:
683 s = "B (Right)";
684 break;
685 default:
686 s = "";
687 break;
688 }
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000689 lcd_putsf(0, line++, "Channel: %d (%s)", x, s);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000690
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000691 x = (control >> 4) & 15;
692 switch(x)
693 {
694 case 0:
695 s = "44.1kHz";
696 break;
697 case 0x4:
698 s = "48kHz";
699 break;
700 case 0xc:
701 s = "32kHz";
702 break;
703 }
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000704 lcd_putsf(0, line++, "Frequency: %d (%s)", x, s);
Jens Arnold073f1972006-05-12 01:10:18 +0000705
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000706 x = (control >> 2) & 3;
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000707 lcd_putsf(0, line++, "Clock accuracy: %d", x);
Jens Arnold073f1972006-05-12 01:10:18 +0000708 line++;
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000709
Thomas Martitz35e8b142010-06-21 16:53:00 +0000710#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000711 lcd_putsf(0, line++, "Measured freq: %ldHz",
Michael Sevakiscc50c142006-11-13 23:21:54 +0000712 spdif_measure_frequency());
Steve Bavin2c2b50a2006-10-04 07:29:50 +0000713#endif
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000714
Jens Arnold073f1972006-05-12 01:10:18 +0000715 lcd_update();
716
Jonathan Gordon475be662006-08-16 04:27:33 +0000717 if (action_userabort(HZ/10))
Michael Sevakiscc50c142006-11-13 23:21:54 +0000718 break;
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000719 }
Michael Sevakiscc50c142006-11-13 23:21:54 +0000720
Michael Sevakis2d48d0f2007-06-08 23:42:04 +0000721 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
Michael Sevakiscc50c142006-11-13 23:21:54 +0000722
Jens Arnold073f1972006-05-12 01:10:18 +0000723#ifdef HAVE_SPDIF_POWER
724 spdif_power_enable(global_settings.spdif_enable);
725#endif
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000726
Jonathan Gordon8b9fdb52009-01-05 09:59:11 +0000727 lcd_setfont(FONT_UI);
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000728 return false;
729}
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000730#endif /* CPU_COLDFIRE */
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000731
Thomas Martitz35e8b142010-06-21 16:53:00 +0000732#if (CONFIG_RTC == RTC_PCF50605) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
Michael Giacomelli054447f2008-02-10 05:39:20 +0000733static bool dbg_pcf(void)
734{
Michael Giacomelli054447f2008-02-10 05:39:20 +0000735 int line;
736
737#ifdef HAVE_LCD_BITMAP
Michael Giacomelli054447f2008-02-10 05:39:20 +0000738 lcd_setfont(FONT_SYSFIXED);
739#endif
740 lcd_clear_display();
741
742 while(1)
743 {
744 line = 0;
745
Nils Wallméniusf34a8412009-10-17 18:02:48 +0000746 lcd_putsf(0, line++, "DCDC1: %02x", pcf50605_read(0x1b));
747 lcd_putsf(0, line++, "DCDC2: %02x", pcf50605_read(0x1c));
748 lcd_putsf(0, line++, "DCDC3: %02x", pcf50605_read(0x1d));
749 lcd_putsf(0, line++, "DCDC4: %02x", pcf50605_read(0x1e));
750 lcd_putsf(0, line++, "DCDEC1: %02x", pcf50605_read(0x1f));
751 lcd_putsf(0, line++, "DCDEC2: %02x", pcf50605_read(0x20));
752 lcd_putsf(0, line++, "DCUDC1: %02x", pcf50605_read(0x21));
753 lcd_putsf(0, line++, "DCUDC2: %02x", pcf50605_read(0x22));
754 lcd_putsf(0, line++, "IOREGC: %02x", pcf50605_read(0x23));
755 lcd_putsf(0, line++, "D1REGC: %02x", pcf50605_read(0x24));
756 lcd_putsf(0, line++, "D2REGC: %02x", pcf50605_read(0x25));
757 lcd_putsf(0, line++, "D3REGC: %02x", pcf50605_read(0x26));
758 lcd_putsf(0, line++, "LPREG1: %02x", pcf50605_read(0x27));
Michael Giacomelli054447f2008-02-10 05:39:20 +0000759 lcd_update();
Rafaël Carré02c79d32012-01-04 06:21:16 +0000760 if (action_userabort(HZ/10))
Michael Giacomelli054447f2008-02-10 05:39:20 +0000761 {
Jonathan Gordon8b9fdb52009-01-05 09:59:11 +0000762 lcd_setfont(FONT_UI);
Michael Giacomelli054447f2008-02-10 05:39:20 +0000763 return false;
764 }
765 }
766
Jonathan Gordon8b9fdb52009-01-05 09:59:11 +0000767 lcd_setfont(FONT_UI);
Michael Giacomelli054447f2008-02-10 05:39:20 +0000768 return false;
769}
770#endif
771
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +0000772#ifdef HAVE_ADJUSTABLE_CPU_FREQ
Jens Arnold314f3b52006-12-12 22:22:21 +0000773static bool dbg_cpufreq(void)
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +0000774{
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +0000775 int line;
776 int button;
William Wilgus056d4b02017-11-14 05:17:02 +0100777 int x = 0;
778 bool done = false;
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +0000779
780#ifdef HAVE_LCD_BITMAP
Linus Nielsen Feltzing57d8e8f2005-08-18 07:16:53 +0000781 lcd_setfont(FONT_SYSFIXED);
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +0000782#endif
783 lcd_clear_display();
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +0000784
William Wilgus056d4b02017-11-14 05:17:02 +0100785 while(!done)
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +0000786 {
787 line = 0;
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000788
William Wilgus056d4b02017-11-14 05:17:02 +0100789 int temp = FREQ / 1000;
790 lcd_putsf(x, line++, "Frequency: %ld.%ld MHz", temp / 1000, temp % 1000);
791 lcd_putsf(x, line++, "boost_counter: %d", get_cpu_boost_counter());
Michael Giacomelli46c0c3a2008-02-10 05:56:35 +0000792
Michael Sevakis783c7752017-01-21 08:04:43 -0500793#ifdef HAVE_ADJUSTABLE_CPU_VOLTAGE
794 extern int get_cpu_voltage_setting(void);
795 temp = get_cpu_voltage_setting();
William Wilgus056d4b02017-11-14 05:17:02 +0100796 lcd_putsf(x, line++, "CPU voltage: %d.%03dV", temp / 1000, temp % 1000);
Michael Sevakis783c7752017-01-21 08:04:43 -0500797#endif
798
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +0000799 lcd_update();
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000800 button = get_action(CONTEXT_STD,HZ/10);
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +0000801
802 switch(button)
803 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000804 case ACTION_STD_PREV:
Miika Pekkarinenc5d57f02006-12-05 20:01:48 +0000805 cpu_boost(true);
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000806 break;
Steve Bavind49c8102006-10-05 10:07:03 +0000807
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000808 case ACTION_STD_NEXT:
Miika Pekkarinenc5d57f02006-12-05 20:01:48 +0000809 cpu_boost(false);
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000810 break;
William Wilgus056d4b02017-11-14 05:17:02 +0100811 case ACTION_STD_MENU:
812 x--;
813 break;
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000814 case ACTION_STD_OK:
William Wilgus056d4b02017-11-14 05:17:02 +0100815 x = 0;
Steve Bavind49c8102006-10-05 10:07:03 +0000816 while (get_cpu_boost_counter() > 0)
Miika Pekkarinenc5d57f02006-12-05 20:01:48 +0000817 cpu_boost(false);
Steve Bavin3ad89d22006-11-01 11:12:21 +0000818 set_cpu_frequency(CPUFREQ_DEFAULT);
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000819 break;
Thom Johansenf6e85672006-03-17 02:02:13 +0000820
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000821 case ACTION_STD_CANCEL:
William Wilgus056d4b02017-11-14 05:17:02 +0100822 done = true;;
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +0000823 }
William Wilgus056d4b02017-11-14 05:17:02 +0100824 lcd_clear_display();
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +0000825 }
Jonathan Gordon8b9fdb52009-01-05 09:59:11 +0000826 lcd_setfont(FONT_UI);
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +0000827 return false;
828}
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000829#endif /* HAVE_ADJUSTABLE_CPU_FREQ */
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000830
Thomas Martitz35e8b142010-06-21 16:53:00 +0000831#if defined(HAVE_TSC2100) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
Jonathan Gordon13343c02007-11-02 06:17:53 +0000832#include "tsc2100.h"
Nils Wallméniusc9d09612009-08-20 17:03:50 +0000833static const char* tsc2100_debug_getname(int selected_item, void * data,
834 char *buffer, size_t buffer_len)
Jonathan Gordon13343c02007-11-02 06:17:53 +0000835{
836 int *page = (int*)data;
837 bool reserved = false;
838 switch (*page)
839 {
840 case 0:
841 if ((selected_item > 0x0a) ||
842 (selected_item == 0x04) ||
843 (selected_item == 0x08))
844 reserved = true;
845 break;
846 case 1:
847 if ((selected_item > 0x05) ||
848 (selected_item == 0x02))
849 reserved = true;
850 break;
851 case 2:
852 if (selected_item > 0x1e)
853 reserved = true;
854 break;
855 }
856 if (reserved)
Karl Kurbjun243aede2011-02-06 19:11:29 +0000857 snprintf(buffer, buffer_len, "%02x: RSVD", selected_item);
Jonathan Gordon13343c02007-11-02 06:17:53 +0000858 else
Karl Kurbjun243aede2011-02-06 19:11:29 +0000859 snprintf(buffer, buffer_len, "%02x: %04x", selected_item,
860 tsc2100_readreg(*page, selected_item)&0xffff);
Jonathan Gordon13343c02007-11-02 06:17:53 +0000861 return buffer;
862}
863static int tsc2100debug_action_callback(int action, struct gui_synclist *lists)
864{
Jonathan Gordonf5ec3e42007-12-17 02:37:21 +0000865 int *page = (int*)lists->data;
Jonathan Gordon13343c02007-11-02 06:17:53 +0000866 if (action == ACTION_STD_OK)
867 {
868 *page = (*page+1)%3;
Michael Giacomelli46c0c3a2008-02-10 05:56:35 +0000869 snprintf(lists->title, 32,
Jonathan Gordon13343c02007-11-02 06:17:53 +0000870 "tsc2100 registers - Page %d", *page);
871 return ACTION_REDRAW;
872 }
873 return action;
874}
Bertrik Sikken37a384c2008-09-10 20:14:22 +0000875static bool tsc2100_debug(void)
Jonathan Gordon13343c02007-11-02 06:17:53 +0000876{
877 int page = 0;
878 char title[32] = "tsc2100 registers - Page 0";
879 struct simplelist_info info;
880 simplelist_info_init(&info, title, 32, &page);
881 info.timeout = HZ/100;
882 info.get_name = tsc2100_debug_getname;
883 info.action_callback= tsc2100debug_action_callback;
884 return simplelist_show_list(&info);
885}
886#endif
Thomas Martitzc1bd9b02012-01-03 23:44:38 +0000887#if (CONFIG_BATTERY_MEASURE != 0) && defined(HAVE_LCD_BITMAP) && !defined(SIMULATOR)
Heikki Hannikainen6eb42542002-08-06 10:52:51 +0000888/*
889 * view_battery() shows a automatically scaled graph of the battery voltage
890 * over time. Usable for estimating battery life / charging rate.
891 * The power_history array is updated in power_thread of powermgmt.c.
892 */
893
Jörg Hohensohn25848962005-03-03 07:25:43 +0000894#define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
Thomas Martitzc1bd9b02012-01-03 23:44:38 +0000895#define BAT_TSPACE 20
896#define BAT_YSPACE (LCD_HEIGHT - BAT_TSPACE)
Heikki Hannikainen6eb42542002-08-06 10:52:51 +0000897
Marcin Bukat47d7be52010-07-17 11:29:06 +0000898
Jens Arnold314f3b52006-12-12 22:22:21 +0000899static bool view_battery(void)
Heikki Hannikainen6eb42542002-08-06 10:52:51 +0000900{
901 int view = 0;
Thomas Martitzc1bd9b02012-01-03 23:44:38 +0000902 int i, x, y, z, y1, y2, grid, graph;
Jean-Philippe Bernardyed7c6352005-02-08 15:12:25 +0000903 unsigned short maxv, minv;
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000904
Linus Nielsen Feltzingf22eeee2005-08-14 08:43:05 +0000905 lcd_setfont(FONT_SYSFIXED);
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000906
Heikki Hannikainen6eb42542002-08-06 10:52:51 +0000907 while(1)
908 {
Jens Arnoldf9b90e92007-04-06 22:55:00 +0000909 lcd_clear_display();
Heikki Hannikainen6eb42542002-08-06 10:52:51 +0000910 switch (view) {
Björn Stenbergfe97b572002-08-10 08:57:47 +0000911 case 0: /* voltage history graph */
912 /* Find maximum and minimum voltage for scaling */
Jens Arnold1d1d9a82007-08-15 23:57:27 +0000913 minv = power_history[0];
914 maxv = minv + 1;
915 for (i = 1; i < BAT_LAST_VAL && power_history[i]; i++) {
Björn Stenbergfe97b572002-08-10 08:57:47 +0000916 if (power_history[i] > maxv)
917 maxv = power_history[i];
Jens Arnold1d1d9a82007-08-15 23:57:27 +0000918 if (power_history[i] < minv)
Björn Stenbergfe97b572002-08-10 08:57:47 +0000919 minv = power_history[i];
Heikki Hannikainen6eb42542002-08-06 10:52:51 +0000920 }
Thomas Martitzc1bd9b02012-01-03 23:44:38 +0000921 /* print header */
922#if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
Mihail Zenkovce90c042016-03-30 12:50:40 +0000923 /* adjust grid scale */
Marcin Bukat47d7be52010-07-17 11:29:06 +0000924 if ((maxv - minv) > 50)
925 grid = 50;
926 else
927 grid = 5;
Thomas Martitzc1bd9b02012-01-03 23:44:38 +0000928
Marcin Bukat47d7be52010-07-17 11:29:06 +0000929 lcd_putsf(0, 0, "battery %d.%03dV", power_history[0] / 1000,
Jens Arnold1d1d9a82007-08-15 23:57:27 +0000930 power_history[0] % 1000);
Marcin Bukat47d7be52010-07-17 11:29:06 +0000931 lcd_putsf(0, 1, "%d.%03d-%d.%03dV (%2dmV)",
932 minv / 1000, minv % 1000, maxv / 1000, maxv % 1000,
933 grid);
Thomas Martitzc1bd9b02012-01-03 23:44:38 +0000934#elif (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE)
Mihail Zenkovce90c042016-03-30 12:50:40 +0000935 /* adjust grid scale */
Thomas Martitzc1bd9b02012-01-03 23:44:38 +0000936 if ((maxv - minv) > 10)
937 grid = 10;
938 else
939 grid = 1;
940 lcd_putsf(0, 0, "battery %d%%", power_history[0]);
941 lcd_putsf(0, 1, "%d%%-%d%% (%d %%)", minv, maxv, grid);
942#endif
Mihail Zenkovce90c042016-03-30 12:50:40 +0000943
Marcin Bukat47d7be52010-07-17 11:29:06 +0000944 i = 1;
945 while ((y = (minv - (minv % grid)+i*grid)) < maxv)
946 {
947 graph = ((y-minv)*BAT_YSPACE)/(maxv-minv);
948 graph = LCD_HEIGHT-1 - graph;
Mihail Zenkovce90c042016-03-30 12:50:40 +0000949
950 /* draw dotted horizontal grid line */
Marcin Bukat47d7be52010-07-17 11:29:06 +0000951 for (x=0; x<LCD_WIDTH;x=x+2)
952 lcd_drawpixel(x,graph);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000953
Marcin Bukat47d7be52010-07-17 11:29:06 +0000954 i++;
Björn Stenbergfe97b572002-08-10 08:57:47 +0000955 }
Mihail Zenkovce90c042016-03-30 12:50:40 +0000956
Marcin Bukat47d7be52010-07-17 11:29:06 +0000957 x = 0;
958 /* draw plot of power history
959 * skip empty entries
960 */
Mihail Zenkovce90c042016-03-30 12:50:40 +0000961 for (i = BAT_LAST_VAL - 1; i > 0; i--)
Marcin Bukat47d7be52010-07-17 11:29:06 +0000962 {
963 if (power_history[i] && power_history[i-1])
964 {
Mihail Zenkovce90c042016-03-30 12:50:40 +0000965 y1 = (power_history[i] - minv) * BAT_YSPACE /
Marcin Bukat47d7be52010-07-17 11:29:06 +0000966 (maxv - minv);
Mihail Zenkovce90c042016-03-30 12:50:40 +0000967 y1 = MIN(MAX(LCD_HEIGHT-1 - y1, BAT_TSPACE),
Marcin Bukat47d7be52010-07-17 11:29:06 +0000968 LCD_HEIGHT-1);
969 y2 = (power_history[i-1] - minv) * BAT_YSPACE /
970 (maxv - minv);
Thomas Martitzc1bd9b02012-01-03 23:44:38 +0000971 y2 = MIN(MAX(LCD_HEIGHT-1 - y2, BAT_TSPACE),
Marcin Bukat47d7be52010-07-17 11:29:06 +0000972 LCD_HEIGHT-1);
Björn Stenbergfe97b572002-08-10 08:57:47 +0000973
Marcin Bukat47d7be52010-07-17 11:29:06 +0000974 lcd_set_drawmode(DRMODE_SOLID);
975
976 /* make line thicker */
Mihail Zenkovce90c042016-03-30 12:50:40 +0000977 lcd_drawline(((x*LCD_WIDTH)/(BAT_LAST_VAL)),
978 y1,
979 (((x+1)*LCD_WIDTH)/(BAT_LAST_VAL)),
Marcin Bukat47d7be52010-07-17 11:29:06 +0000980 y2);
Mihail Zenkovce90c042016-03-30 12:50:40 +0000981 lcd_drawline(((x*LCD_WIDTH)/(BAT_LAST_VAL))+1,
982 y1+1,
983 (((x+1)*LCD_WIDTH)/(BAT_LAST_VAL))+1,
Marcin Bukat47d7be52010-07-17 11:29:06 +0000984 y2+1);
985 x++;
986 }
987 }
Björn Stenbergfe97b572002-08-10 08:57:47 +0000988 break;
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000989
Björn Stenbergfe97b572002-08-10 08:57:47 +0000990 case 1: /* status: */
Marcin Bukatdd8e8a72010-05-19 13:24:18 +0000991#if CONFIG_CHARGING >= CHARGING_MONITOR
992 lcd_putsf(0, 0, "Pwr status: %s",
993 charging_state() ? "charging" : "discharging");
Mihail Zenkovce90c042016-03-30 12:50:40 +0000994#else
Thomas Martitzc1bd9b02012-01-03 23:44:38 +0000995 lcd_puts(0, 0, "Power status: unknown");
Marcin Bukatdd8e8a72010-05-19 13:24:18 +0000996#endif
Thomas Martitzc1bd9b02012-01-03 23:44:38 +0000997 battery_read_info(&y, &z);
998 if (y > 0)
999 lcd_putsf(0, 1, "Battery: %d.%03d V (%d %%)", y / 1000, y % 1000, z);
1000 else if (z > 0)
1001 lcd_putsf(0, 1, "Battery: %d %%", z);
Jens Arnold303b4ab2004-12-01 00:33:18 +00001002#ifdef ADC_EXT_POWER
Jens Arnold1d1d9a82007-08-15 23:57:27 +00001003 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 1000;
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001004 lcd_putsf(0, 2, "External: %d.%03d V", y / 1000, y % 1000);
Jens Arnold303b4ab2004-12-01 00:33:18 +00001005#endif
Jonathan Gordon9a6f4192007-02-18 05:32:06 +00001006#if CONFIG_CHARGING
Michael Sevakis3157e132008-12-24 16:58:41 +00001007#if defined ARCHOS_RECORDER
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001008 lcd_putsf(0, 3, "Chgr: %s %s",
Michiel Van Der Kolk9d2531a2005-03-28 00:47:09 +00001009 charger_inserted() ? "present" : "absent",
Michael Sevakis3157e132008-12-24 16:58:41 +00001010 charger_enabled() ? "on" : "off");
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001011 lcd_putsf(0, 5, "short delta: %d", short_delta);
1012 lcd_putsf(0, 6, "long delta: %d", long_delta);
Björn Stenbergfe97b572002-08-10 08:57:47 +00001013 lcd_puts(0, 7, power_message);
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001014 lcd_putsf(0, 8, "USB Inserted: %s",
Steve Bavin338d94f2007-02-01 10:47:22 +00001015 usb_inserted() ? "yes" : "no");
Michael Sevakis3157e132008-12-24 16:58:41 +00001016#elif defined IPOD_NANO || defined IPOD_VIDEO
Brandon Lowd00d5882006-03-18 09:13:55 +00001017 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1018 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1019 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1020 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1021 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1022
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001023 lcd_putsf(0, 3, "USB pwr: %s",
Nils Wallméniusa9713342009-10-17 13:00:58 +00001024 usb_pwr ? "present" : "absent");
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001025 lcd_putsf(0, 4, "EXT pwr: %s",
Nils Wallméniusa9713342009-10-17 13:00:58 +00001026 ext_pwr ? "present" : "absent");
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001027 lcd_putsf(0, 5, "Battery: %s",
Michael Sevakis1d4a9c62006-10-27 05:31:28 +00001028 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001029 lcd_putsf(0, 6, "Dock mode: %s",
Brandon Lowd00d5882006-03-18 09:13:55 +00001030 dock ? "enabled" : "disabled");
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001031 lcd_putsf(0, 7, "Headphone: %s",
Brandon Lowd00d5882006-03-18 09:13:55 +00001032 headphone ? "connected" : "disconnected");
Torne Wuff2d0af6f2009-11-03 20:35:04 +00001033#ifdef IPOD_VIDEO
Frank Gevaertsa1cf4ce2010-08-31 19:06:04 +00001034 if(probed_ramsize == 64)
1035 x = (adc_read(ADC_4066_ISTAT) * 2400) / (1024 * 2);
1036 else
Bertrik Sikken0157c622011-07-24 17:32:50 +00001037#endif
Frank Gevaertsa1cf4ce2010-08-31 19:06:04 +00001038 x = (adc_read(ADC_4066_ISTAT) * 2400) / (1024 * 3);
Torne Wuff2d0af6f2009-11-03 20:35:04 +00001039 lcd_putsf(0, 8, "Ibat: %d mA", x);
1040 lcd_putsf(0, 9, "Vbat * Ibat: %d mW", x * y / 1000);
Michael Sevakis3157e132008-12-24 16:58:41 +00001041#elif defined TOSHIBA_GIGABEAT_S
1042 int line = 3;
Michael Sevakis56676822008-12-21 18:10:36 +00001043 unsigned int st;
1044
1045 static const unsigned char * const chrgstate_strings[] =
1046 {
1047 "Disabled",
1048 "Error",
1049 "Discharging",
1050 "Precharge",
1051 "Constant Voltage",
1052 "Constant Current",
1053 "<unknown>",
1054 };
1055
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001056 lcd_putsf(0, line++, "Charger: %s",
Michael Sevakis3157e132008-12-24 16:58:41 +00001057 charger_inserted() ? "present" : "absent");
Michael Sevakis3157e132008-12-24 16:58:41 +00001058
Michael Sevakis56676822008-12-21 18:10:36 +00001059 st = power_input_status() &
1060 (POWER_INPUT_CHARGER | POWER_INPUT_BATTERY);
Michael Sevakisaced6672017-09-18 06:00:05 -04001061
1062 lcd_putsf(0, line++, "%.*s%.*s",
1063 !!(st & POWER_INPUT_MAIN_CHARGER)*5, " Main",
1064 !!(st & POWER_INPUT_USB_CHARGER)*4, " USB");
Michael Sevakis56676822008-12-21 18:10:36 +00001065
Michael Sevakis56676822008-12-21 18:10:36 +00001066 y = ARRAYLEN(chrgstate_strings) - 1;
1067
1068 switch (charge_state)
1069 {
1070 case CHARGE_STATE_DISABLED: y--;
1071 case CHARGE_STATE_ERROR: y--;
1072 case DISCHARGING: y--;
1073 case TRICKLE: y--;
1074 case TOPOFF: y--;
1075 case CHARGING: y--;
1076 default:;
1077 }
1078
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001079 lcd_putsf(0, line++, "State: %s", chrgstate_strings[y]);
Michael Sevakis56676822008-12-21 18:10:36 +00001080
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001081 lcd_putsf(0, line++, "Battery Switch: %s",
Michael Sevakis56676822008-12-21 18:10:36 +00001082 (st & POWER_INPUT_BATTERY) ? "On" : "Off");
Michael Sevakis56676822008-12-21 18:10:36 +00001083
1084 y = chrgraw_adc_voltage();
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001085 lcd_putsf(0, line++, "CHRGRAW: %d.%03d V",
Michael Sevakis56676822008-12-21 18:10:36 +00001086 y / 1000, y % 1000);
Michael Sevakis56676822008-12-21 18:10:36 +00001087
1088 y = application_supply_adc_voltage();
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001089 lcd_putsf(0, line++, "BP : %d.%03d V",
Michael Sevakis56676822008-12-21 18:10:36 +00001090 y / 1000, y % 1000);
Michael Sevakis56676822008-12-21 18:10:36 +00001091
Michael Sevakisd8922142008-05-25 01:38:08 +00001092 y = battery_adc_charge_current();
Michael Sevakisaced6672017-09-18 06:00:05 -04001093 lcd_putsf(0, line++, "CHRGISN:% d mA", y);
Michael Sevakis56676822008-12-21 18:10:36 +00001094
1095 y = cccv_regulator_dissipation();
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001096 lcd_putsf(0, line++, "P CCCV : %d mW", y);
Michael Sevakis56676822008-12-21 18:10:36 +00001097
1098 y = battery_charge_current();
Michael Sevakisaced6672017-09-18 06:00:05 -04001099 lcd_putsf(0, line++, "I Charge:% d mA", y);
Michael Sevakisd8922142008-05-25 01:38:08 +00001100
1101 y = battery_adc_temp();
Michael Sevakis56676822008-12-21 18:10:36 +00001102
1103 if (y != INT_MIN) {
Michael Sevakisaced6672017-09-18 06:00:05 -04001104 lcd_putsf(0, line++, "T Battery: %d\u00b0C (%d\u00b0F)", y,
Nils Wallméniusa9713342009-10-17 13:00:58 +00001105 (9*y + 160) / 5);
Michael Sevakis56676822008-12-21 18:10:36 +00001106 } else {
1107 /* Conversion disabled */
Nils Wallméniusa9713342009-10-17 13:00:58 +00001108 lcd_puts(0, line++, "T Battery: ?");
Michael Sevakis56676822008-12-21 18:10:36 +00001109 }
Mihail Zenkovce90c042016-03-30 12:50:40 +00001110#elif defined(HAVE_AS3514) && CONFIG_CHARGING
Michael Sevakis7d796912009-01-11 10:07:22 +00001111 static const char * const chrgstate_strings[] =
1112 {
Rafaël Carréa2ab7192010-06-21 00:03:15 +00001113 [CHARGE_STATE_DISABLED - CHARGE_STATE_DISABLED]= "Disabled",
1114 [CHARGE_STATE_ERROR - CHARGE_STATE_DISABLED] = "Error",
1115 [DISCHARGING - CHARGE_STATE_DISABLED] = "Discharging",
1116 [CHARGING - CHARGE_STATE_DISABLED] = "Charging",
Michael Sevakis7d796912009-01-11 10:07:22 +00001117 };
1118 const char *str = NULL;
1119
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001120 lcd_putsf(0, 3, "Charger: %s",
Michael Sevakis7d796912009-01-11 10:07:22 +00001121 charger_inserted() ? "present" : "absent");
Michael Sevakis7d796912009-01-11 10:07:22 +00001122
Rafaël Carréa2ab7192010-06-21 00:03:15 +00001123 y = charge_state - CHARGE_STATE_DISABLED;
Michael Sevakis7d796912009-01-11 10:07:22 +00001124 if ((unsigned)y < ARRAYLEN(chrgstate_strings))
1125 str = chrgstate_strings[y];
1126
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001127 lcd_putsf(0, 4, "State: %s",
Michael Sevakis7d796912009-01-11 10:07:22 +00001128 str ? str : "<unknown>");
Michael Sevakis7d796912009-01-11 10:07:22 +00001129
Rafaël Carré88c55d72010-05-17 20:53:25 +00001130 lcd_putsf(0, 5, "CHARGER: %02X", ascodec_read_charger());
Michael Sparmann30d664b2009-10-10 22:02:23 +00001131#elif defined(IPOD_NANO2G)
Michael Sparmannf61fb372010-03-10 03:18:58 +00001132 y = pmu_read_battery_voltage();
1133 lcd_putsf(17, 1, "RAW: %d.%03d V", y / 1000, y % 1000);
Michael Sparmann30d664b2009-10-10 22:02:23 +00001134 y = pmu_read_battery_current();
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001135 lcd_putsf(0, 2, "Battery current: %d mA", y);
Michael Sparmann59d93612010-11-14 15:08:38 +00001136 lcd_putsf(0, 3, "PWRCON: %08x %08x", PWRCON, PWRCONEXT);
1137 lcd_putsf(0, 4, "CLKCON: %08x %03x %03x", CLKCON, CLKCON2, CLKCON3);
1138 lcd_putsf(0, 5, "PLL: %06x %06x %06x", PLL0PMS, PLL1PMS, PLL2PMS);
Michael Sparmanne5c81522010-02-17 15:57:53 +00001139 x = pmu_read(0x1b) & 0xf;
1140 y = pmu_read(0x1a) * 25 + 625;
Michael Sparmann59d93612010-11-14 15:08:38 +00001141 lcd_putsf(0, 6, "AUTO: %x / %d mV", x, y);
Michael Sparmanne5c81522010-02-17 15:57:53 +00001142 x = pmu_read(0x1f) & 0xf;
1143 y = pmu_read(0x1e) * 25 + 625;
Michael Sparmann59d93612010-11-14 15:08:38 +00001144 lcd_putsf(0, 7, "DOWN1: %x / %d mV", x, y);
Michael Sparmanne5c81522010-02-17 15:57:53 +00001145 x = pmu_read(0x23) & 0xf;
1146 y = pmu_read(0x22) * 25 + 625;
Michael Sparmann59d93612010-11-14 15:08:38 +00001147 lcd_putsf(0, 8, "DOWN2: %x / %d mV", x, y);
Michael Sparmanne5c81522010-02-17 15:57:53 +00001148 x = pmu_read(0x27) & 0xf;
1149 y = pmu_read(0x26) * 100 + 900;
Michael Sparmann59d93612010-11-14 15:08:38 +00001150 lcd_putsf(0, 9, "MEMLDO: %x / %d mV", x, y);
Michael Sparmanne5c81522010-02-17 15:57:53 +00001151 for (i = 0; i < 6; i++)
1152 {
1153 x = pmu_read(0x2e + (i << 1)) & 0xf;
1154 y = pmu_read(0x2d + (i << 1)) * 100 + 900;
Michael Sparmann59d93612010-11-14 15:08:38 +00001155 lcd_putsf(0, 10 + i, "LDO%d: %x / %d mV", i + 1, x, y);
Michael Sparmanne5c81522010-02-17 15:57:53 +00001156 }
Michael Sevakis3157e132008-12-24 16:58:41 +00001157#else
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001158 lcd_putsf(0, 3, "Charger: %s",
Michael Sevakis3157e132008-12-24 16:58:41 +00001159 charger_inserted() ? "present" : "absent");
Michael Sevakis3157e132008-12-24 16:58:41 +00001160#endif /* target type */
Jens Arnold0dd1f8e2006-06-06 22:23:52 +00001161#endif /* CONFIG_CHARGING */
Björn Stenbergfe97b572002-08-10 08:57:47 +00001162 break;
Björn Stenbergfe97b572002-08-10 08:57:47 +00001163 case 2: /* voltage deltas: */
Thomas Martitzc1bd9b02012-01-03 23:44:38 +00001164#if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
Björn Stenbergfe97b572002-08-10 08:57:47 +00001165 lcd_puts(0, 0, "Voltage deltas:");
Thomas Martitzc1bd9b02012-01-03 23:44:38 +00001166 for (i = 0; i < POWER_HISTORY_LEN-1; i++) {
Jens Arnold1d1d9a82007-08-15 23:57:27 +00001167 y = power_history[i] - power_history[i+1];
Thomas Martitzc1bd9b02012-01-03 23:44:38 +00001168 lcd_putsf(0, i+1, "-%d min: %c%d.%03d V", i,
1169 (y < 0) ? '-' : ' ', ((y < 0) ? y * -1 : y) / 1000,
Jens Arnold1d1d9a82007-08-15 23:57:27 +00001170 ((y < 0) ? y * -1 : y ) % 1000);
Björn Stenbergfe97b572002-08-10 08:57:47 +00001171 }
Thomas Martitzc1bd9b02012-01-03 23:44:38 +00001172#elif (CONFIG_BATTERY_MEASURE & PERCENTAGE_MEASURE)
1173 lcd_puts(0, 0, "Percentage deltas:");
1174 for (i = 0; i < POWER_HISTORY_LEN-1; i++) {
1175 y = power_history[i] - power_history[i+1];
1176 lcd_putsf(0, i+1, "-%d min: %c%d%%", i,
1177 (y < 0) ? '-' : ' ', ((y < 0) ? y * -1 : y));
1178 }
1179#endif
Björn Stenbergfe97b572002-08-10 08:57:47 +00001180 break;
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001181
Michiel Van Der Kolk9d2531a2005-03-28 00:47:09 +00001182 case 3: /* remaining time estimation: */
Uwe Freesec83374b2002-12-15 18:10:19 +00001183
Michael Sevakis3157e132008-12-24 16:58:41 +00001184#ifdef ARCHOS_RECORDER
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001185 lcd_putsf(0, 0, "charge_state: %d", charge_state);
Uwe Freesec83374b2002-12-15 18:10:19 +00001186
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001187 lcd_putsf(0, 1, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001188
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001189 lcd_putsf(0, 2, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
Michiel Van Der Kolk9d2531a2005-03-28 00:47:09 +00001190
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001191 lcd_putsf(0, 3, "P=%2d I=%2d", pid_p, pid_i);
Michiel Van Der Kolk9d2531a2005-03-28 00:47:09 +00001192
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001193 lcd_putsf(0, 4, "Trickle sec: %d/60", trickle_sec);
Michael Sevakis3157e132008-12-24 16:58:41 +00001194#endif /* ARCHOS_RECORDER */
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001195
Thomas Martitzc1bd9b02012-01-03 23:44:38 +00001196#if (CONFIG_BATTERY_MEASURE & VOLTAGE_MEASURE)
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001197 lcd_putsf(0, 5, "Last PwrHist: %d.%03dV",
Jens Arnold1d1d9a82007-08-15 23:57:27 +00001198 power_history[0] / 1000,
1199 power_history[0] % 1000);
Thomas Martitzc1bd9b02012-01-03 23:44:38 +00001200#endif
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001201
Nils Wallméniusf34a8412009-10-17 18:02:48 +00001202 lcd_putsf(0, 6, "battery level: %d%%", battery_level());
Michiel Van Der Kolk451dd482005-03-28 00:00:24 +00001203
Thomas Martitzc1bd9b02012-01-03 23:44:38 +00001204 int time_left = battery_time();
1205 if (time_left >= 0)
1206 lcd_putsf(0, 7, "Est. remain: %d m", time_left);
1207 else
1208 lcd_puts(0, 7, "Estimation n/a");
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001209 break;
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001210 }
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001211
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001212 lcd_update();
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001213
Bertrik Sikken53816472008-04-19 17:54:12 +00001214 switch(get_action(CONTEXT_STD,HZ/2))
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001215 {
Bertrik Sikken53816472008-04-19 17:54:12 +00001216 case ACTION_STD_PREV:
Björn Stenbergfe97b572002-08-10 08:57:47 +00001217 if (view)
1218 view--;
1219 break;
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001220
Bertrik Sikken53816472008-04-19 17:54:12 +00001221 case ACTION_STD_NEXT:
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001222 if (view < 3)
Björn Stenbergfe97b572002-08-10 08:57:47 +00001223 view++;
1224 break;
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001225
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001226 case ACTION_STD_CANCEL:
Jonathan Gordon8b9fdb52009-01-05 09:59:11 +00001227 lcd_setfont(FONT_UI);
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001228 return false;
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001229 }
1230 }
Jonathan Gordon8b9fdb52009-01-05 09:59:11 +00001231 lcd_setfont(FONT_UI);
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001232 return false;
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001233}
1234
Thomas Martitzc1bd9b02012-01-03 23:44:38 +00001235#endif /* (CONFIG_BATTERY_MEASURE != 0) && HAVE_LCD_BITMAP */
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001236
Thomas Martitz35e8b142010-06-21 16:53:00 +00001237#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
Frank Gevaerts19d1cac2008-10-31 21:25:04 +00001238#if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD)
Frank Gevaerts2f8a0082008-11-01 16:14:28 +00001239
Frank Gevaerts19d1cac2008-10-31 21:25:04 +00001240#if (CONFIG_STORAGE & STORAGE_MMC)
Jonathan Gordon5890f602007-07-14 08:55:47 +00001241#define CARDTYPE "MMC"
Frank Gevaerts2f8a0082008-11-01 16:14:28 +00001242#elif (CONFIG_STORAGE & STORAGE_SD)
Jonathan Gordon5890f602007-07-14 08:55:47 +00001243#define CARDTYPE "microSD"
1244#endif
Frank Gevaerts2f8a0082008-11-01 16:14:28 +00001245
Jonathan Gordon5f893be2007-10-20 12:32:55 +00001246static int disk_callback(int btn, struct gui_synclist *lists)
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001247{
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001248 tCardInfo *card;
Jonathan Gordonf5ec3e42007-12-17 02:37:21 +00001249 int *cardnum = (int*)lists->data;
Michael Chicoine887d8182009-12-09 15:32:22 +00001250 unsigned char card_name[6];
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001251 unsigned char pbuf[32];
Jonathan Gordonf5ec3e42007-12-17 02:37:21 +00001252 char *title = lists->title;
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001253 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1254 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
Nils Wallménius79f19b92009-10-17 13:40:42 +00001255 static const unsigned char * const kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1256 static const unsigned char * const nsec_units[] = { "ns", "µs", "ms" };
Rafaël Carréc0eb9ae2009-07-01 21:49:13 +00001257#if (CONFIG_STORAGE & STORAGE_MMC)
Nils Wallméniusa9713342009-10-17 13:00:58 +00001258 static const char * const mmc_spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001259 "3.1-3.31", "4.0" };
Rafaël Carréc0eb9ae2009-07-01 21:49:13 +00001260#endif
1261
Michael Sevakisa16035d2007-07-15 18:25:39 +00001262 if ((btn == ACTION_STD_OK) || (btn == SYS_FS_CHANGED) || (btn == ACTION_REDRAW))
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001263 {
Mark Arigo3e743ec2008-05-13 02:50:31 +00001264#ifdef HAVE_HOTSWAP
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001265 if (btn == ACTION_STD_OK)
Jonathan Gordon5f893be2007-10-20 12:32:55 +00001266 {
1267 *cardnum ^= 0x1; /* change cards */
1268 }
Mark Arigo3e743ec2008-05-13 02:50:31 +00001269#endif
Michael Sevakisa16035d2007-07-15 18:25:39 +00001270
Jonathan Gordon5f893be2007-10-20 12:32:55 +00001271 simplelist_set_line_count(0);
Michael Sevakisa16035d2007-07-15 18:25:39 +00001272
Jonathan Gordon5f893be2007-10-20 12:32:55 +00001273 card = card_get_info(*cardnum);
Michael Sevakisa16035d2007-07-15 18:25:39 +00001274
Michael Sevakisea0d2cf2007-07-25 06:15:07 +00001275 if (card->initialized > 0)
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001276 {
Michael Chicoine887d8182009-12-09 15:32:22 +00001277 unsigned i;
1278 for (i=0; i<sizeof(card_name); i++)
1279 {
Michael Chicoinea47601a2009-12-09 17:10:48 +00001280 card_name[i] = card_extract_bits(card->cid, (103-8*i), 8);
Michael Chicoine887d8182009-12-09 15:32:22 +00001281 }
Michael Chicoinea47601a2009-12-09 17:10:48 +00001282 strlcpy(card_name, card_name, sizeof(card_name));
Jonathan Gordon69228f92013-02-12 20:35:11 +11001283 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001284 "%s Rev %d.%d", card_name,
Michael Chicoine887d8182009-12-09 15:32:22 +00001285 (int) card_extract_bits(card->cid, 63, 4),
1286 (int) card_extract_bits(card->cid, 59, 4));
Jonathan Gordon69228f92013-02-12 20:35:11 +11001287 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001288 "Prod: %d/%d",
Rafaël Carréc0eb9ae2009-07-01 21:49:13 +00001289#if (CONFIG_STORAGE & STORAGE_SD)
Michael Chicoine887d8182009-12-09 15:32:22 +00001290 (int) card_extract_bits(card->cid, 11, 4),
Rafaël Carréc0eb9ae2009-07-01 21:49:13 +00001291 (int) card_extract_bits(card->cid, 19, 8) + 2000
1292#elif (CONFIG_STORAGE & STORAGE_MMC)
Rafaël Carré93f6e3d2009-07-01 19:13:01 +00001293 (int) card_extract_bits(card->cid, 15, 4),
Rafaël Carréc0eb9ae2009-07-01 21:49:13 +00001294 (int) card_extract_bits(card->cid, 11, 4) + 1997
1295#endif
1296 );
Jonathan Gordon69228f92013-02-12 20:35:11 +11001297 simplelist_addline(
Rafaël Carréc0eb9ae2009-07-01 21:49:13 +00001298#if (CONFIG_STORAGE & STORAGE_SD)
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001299 "Ser#: 0x%08lx",
Rafaël Carréc0eb9ae2009-07-01 21:49:13 +00001300 card_extract_bits(card->cid, 55, 32)
1301#elif (CONFIG_STORAGE & STORAGE_MMC)
1302 "Ser#: 0x%04lx",
1303 card_extract_bits(card->cid, 47, 16)
1304#endif
1305 );
1306
Jonathan Gordon69228f92013-02-12 20:35:11 +11001307 simplelist_addline("M=%02x, "
Rafaël Carréc0eb9ae2009-07-01 21:49:13 +00001308#if (CONFIG_STORAGE & STORAGE_SD)
1309 "O=%c%c",
Rafaël Carré93f6e3d2009-07-01 19:13:01 +00001310 (int) card_extract_bits(card->cid, 127, 8),
Rafaël Carréc0eb9ae2009-07-01 21:49:13 +00001311 card_extract_bits(card->cid, 119, 8),
1312 card_extract_bits(card->cid, 111, 8)
1313#elif (CONFIG_STORAGE & STORAGE_MMC)
1314 "O=%04x",
1315 (int) card_extract_bits(card->cid, 127, 8),
1316 (int) card_extract_bits(card->cid, 119, 16)
1317#endif
1318 );
1319
1320#if (CONFIG_STORAGE & STORAGE_MMC)
Rafaël Carré93f6e3d2009-07-01 19:13:01 +00001321 int temp = card_extract_bits(card->csd, 125, 4);
Jonathan Gordon69228f92013-02-12 20:35:11 +11001322 simplelist_addline(
Rafaël Carréc0eb9ae2009-07-01 21:49:13 +00001323 "MMC v%s", temp < 5 ?
1324 mmc_spec_vers[temp] : "?.?");
1325#endif
Jonathan Gordon69228f92013-02-12 20:35:11 +11001326 simplelist_addline(
Jens Arnoldb1a584a2008-09-14 20:33:24 +00001327 "Blocks: 0x%08lx", card->numblocks);
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001328 output_dyn_value(pbuf, sizeof pbuf, card->speed / 1000,
William Wilgus62a5ed42018-12-09 12:09:40 -06001329 kbit_units, 3, false);
Jonathan Gordon69228f92013-02-12 20:35:11 +11001330 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001331 "Speed: %s", pbuf);
Rafaël Carrée0e24cb2009-07-01 10:07:22 +00001332 output_dyn_value(pbuf, sizeof pbuf, card->taac,
William Wilgus62a5ed42018-12-09 12:09:40 -06001333 nsec_units, 3, false);
Jonathan Gordon69228f92013-02-12 20:35:11 +11001334 simplelist_addline(
Rafaël Carrée0e24cb2009-07-01 10:07:22 +00001335 "Taac: %s", pbuf);
Jonathan Gordon69228f92013-02-12 20:35:11 +11001336 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001337 "Nsac: %d clk", card->nsac);
Jonathan Gordon69228f92013-02-12 20:35:11 +11001338 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001339 "R2W: *%d", card->r2w_factor);
Bertrik Sikkenfa068bb2011-04-11 19:11:39 +00001340#if (CONFIG_STORAGE & STORAGE_SD)
1341 int csd_structure = card_extract_bits(card->csd, 127, 2);
1342 if (csd_structure == 0) /* CSD version 1.0 */
1343#endif
1344 {
Jonathan Gordon69228f92013-02-12 20:35:11 +11001345 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001346 "IRmax: %d..%d mA",
Rafaël Carré93f6e3d2009-07-01 19:13:01 +00001347 i_vmin[card_extract_bits(card->csd, 61, 3)],
1348 i_vmax[card_extract_bits(card->csd, 58, 3)]);
Jonathan Gordon69228f92013-02-12 20:35:11 +11001349 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001350 "IWmax: %d..%d mA",
Rafaël Carré93f6e3d2009-07-01 19:13:01 +00001351 i_vmin[card_extract_bits(card->csd, 55, 3)],
1352 i_vmax[card_extract_bits(card->csd, 52, 3)]);
Bertrik Sikkenfa068bb2011-04-11 19:11:39 +00001353 }
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001354 }
Michael Sevakisea0d2cf2007-07-25 06:15:07 +00001355 else if (card->initialized == 0)
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001356 {
Jonathan Gordon69228f92013-02-12 20:35:11 +11001357 simplelist_addline("Not Found!");
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001358 }
Frank Gevaerts19d1cac2008-10-31 21:25:04 +00001359#if (CONFIG_STORAGE & STORAGE_SD)
Michael Sevakisea0d2cf2007-07-25 06:15:07 +00001360 else /* card->initialized < 0 */
1361 {
Jonathan Gordon69228f92013-02-12 20:35:11 +11001362 simplelist_addline("Init Error! (%d)", card->initialized);
Michael Sevakisea0d2cf2007-07-25 06:15:07 +00001363 }
1364#endif
Jonathan Gordon5f893be2007-10-20 12:32:55 +00001365 snprintf(title, 16, "[" CARDTYPE " %d]", *cardnum);
1366 gui_synclist_set_title(lists, title, Icon_NOICON);
1367 gui_synclist_set_nb_items(lists, simplelist_get_line_count());
1368 gui_synclist_select_item(lists, 0);
Jonathan Gordon7d04c812007-07-14 15:08:46 +00001369 btn = ACTION_REDRAW;
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001370 }
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001371 return btn;
1372}
Mihail Zenkovce90c042016-03-30 12:50:40 +00001373#elif (CONFIG_STORAGE & STORAGE_ATA)
Jonathan Gordon5f893be2007-10-20 12:32:55 +00001374static int disk_callback(int btn, struct gui_synclist *lists)
Björn Stenberg45d32ce2002-12-03 13:12:55 +00001375{
Michael Sevakisaced6672017-09-18 06:00:05 -04001376 static const char atanums[] = { " 0 1 2 3 4 5 6" };
1377
Jonathan Gordon5f893be2007-10-20 12:32:55 +00001378 (void)lists;
Björn Stenberg45d32ce2002-12-03 13:12:55 +00001379 int i;
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001380 char buf[128];
Björn Stenberg45d32ce2002-12-03 13:12:55 +00001381 unsigned short* identify_info = ata_get_identify();
Linus Nielsen Feltzingf3ad6192004-02-16 12:04:55 +00001382 bool timing_info_present = false;
Michael Sevakisa16035d2007-07-15 18:25:39 +00001383 (void)btn;
1384
Jonathan Gordon5f893be2007-10-20 12:32:55 +00001385 simplelist_set_line_count(0);
Michael Sevakisa16035d2007-07-15 18:25:39 +00001386
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001387 for (i=0; i < 20; i++)
1388 ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
1389 buf[40]=0;
1390 /* kill trailing space */
1391 for (i=39; i && buf[i]==' '; i--)
1392 buf[i] = 0;
Jonathan Gordon69228f92013-02-12 20:35:11 +11001393 simplelist_addline("Model: %s", buf);
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001394 for (i=0; i < 4; i++)
1395 ((unsigned short*)buf)[i]=htobe16(identify_info[i+23]);
1396 buf[8]=0;
Jonathan Gordon69228f92013-02-12 20:35:11 +11001397 simplelist_addline(
Robert Keevil227a7332007-07-14 12:32:37 +00001398 "Firmware: %s", buf);
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001399 snprintf(buf, sizeof buf, "%ld MB",
1400 ((unsigned long)identify_info[61] << 16 |
1401 (unsigned long)identify_info[60]) / 2048 );
Jonathan Gordon69228f92013-02-12 20:35:11 +11001402 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001403 "Size: %s", buf);
1404 unsigned long free;
Michael Sevakis7d1a47c2013-08-05 22:02:45 -04001405 volume_size( IF_MV(0,) NULL, &free );
Jonathan Gordon69228f92013-02-12 20:35:11 +11001406 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001407 "Free: %ld MB", free / 1024);
Jonathan Gordon69228f92013-02-12 20:35:11 +11001408 simplelist_addline(
Frank Gevaerts2f8a0082008-11-01 16:14:28 +00001409 "Spinup time: %d ms", storage_spinup_time() * (1000/HZ));
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001410 i = identify_info[83] & (1<<3);
Jonathan Gordon69228f92013-02-12 20:35:11 +11001411 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001412 "Power mgmt: %s", i ? "enabled" : "unsupported");
1413 i = identify_info[83] & (1<<9);
Jonathan Gordon69228f92013-02-12 20:35:11 +11001414 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001415 "Noise mgmt: %s", i ? "enabled" : "unsupported");
1416 i = identify_info[82] & (1<<6);
Jonathan Gordon69228f92013-02-12 20:35:11 +11001417 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001418 "Read-ahead: %s", i ? "enabled" : "unsupported");
1419 timing_info_present = identify_info[53] & (1<<1);
1420 if(timing_info_present) {
Jonathan Gordon69228f92013-02-12 20:35:11 +11001421 simplelist_addline(
Michael Sevakisaced6672017-09-18 06:00:05 -04001422 "PIO modes: 0 1 2%.*s%.*s",
1423 (identify_info[64] & (1<<0)) << 1, &atanums[3*2],
1424 (identify_info[64] & (1<<1)) , &atanums[4*2]);
Björn Stenberg45d32ce2002-12-03 13:12:55 +00001425 }
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001426 else {
Jonathan Gordon69228f92013-02-12 20:35:11 +11001427 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001428 "No PIO mode info");
1429 }
1430 timing_info_present = identify_info[53] & (1<<1);
1431 if(timing_info_present) {
Jonathan Gordon69228f92013-02-12 20:35:11 +11001432 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001433 "Cycle times %dns/%dns",
1434 identify_info[67],
1435 identify_info[68] );
1436 } else {
Jonathan Gordon69228f92013-02-12 20:35:11 +11001437 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001438 "No timing info");
1439 }
Torne Wuff42900512010-04-09 11:55:57 +00001440 int sector_size = 512;
1441 if((identify_info[106] & 0xe000) == 0x6000)
1442 sector_size *= BIT_N(identify_info[106] & 0x000f);
Jonathan Gordon69228f92013-02-12 20:35:11 +11001443 simplelist_addline(
Torne Wuff42900512010-04-09 11:55:57 +00001444 "Physical sector size: %d", sector_size);
Michael Sevakisbc8cab42009-03-12 02:01:25 +00001445#ifdef HAVE_ATA_DMA
Michael Sevakis6dd14d42008-05-04 15:27:10 +00001446 if (identify_info[63] & (1<<0)) {
Jonathan Gordon69228f92013-02-12 20:35:11 +11001447 simplelist_addline(
Michael Sevakisaced6672017-09-18 06:00:05 -04001448 "MDMA modes:%.*s%.*s%.*s",
1449 (identify_info[63] & (1<<0)) << 1, &atanums[0*2],
1450 (identify_info[63] & (1<<1)) , &atanums[1*2],
1451 (identify_info[63] & (1<<2)) >> 1, &atanums[2*2]);
Jonathan Gordon69228f92013-02-12 20:35:11 +11001452 simplelist_addline(
Michael Sevakis6dd14d42008-05-04 15:27:10 +00001453 "MDMA Cycle times %dns/%dns",
1454 identify_info[65],
1455 identify_info[66] );
1456 }
1457 else {
Jonathan Gordon69228f92013-02-12 20:35:11 +11001458 simplelist_addline(
Michael Sevakis6dd14d42008-05-04 15:27:10 +00001459 "No MDMA mode info");
1460 }
Michael Sevakisbc8cab42009-03-12 02:01:25 +00001461 if (identify_info[53] & (1<<2)) {
Jonathan Gordon69228f92013-02-12 20:35:11 +11001462 simplelist_addline(
Michael Sevakisaced6672017-09-18 06:00:05 -04001463 "UDMA modes:%.*s%.*s%.*s%.*s%.*s%.*s%.*s",
1464 (identify_info[88] & (1<<0)) << 1, &atanums[0*2],
1465 (identify_info[88] & (1<<1)) , &atanums[1*2],
1466 (identify_info[88] & (1<<2)) >> 1, &atanums[2*2],
1467 (identify_info[88] & (1<<3)) >> 2, &atanums[3*2],
1468 (identify_info[88] & (1<<4)) >> 3, &atanums[4*2],
1469 (identify_info[88] & (1<<5)) >> 4, &atanums[5*2],
1470 (identify_info[88] & (1<<6)) >> 5, &atanums[6*2]);
Michael Sevakis6dd14d42008-05-04 15:27:10 +00001471 }
1472 else {
Jonathan Gordon69228f92013-02-12 20:35:11 +11001473 simplelist_addline(
Michael Sevakis6dd14d42008-05-04 15:27:10 +00001474 "No UDMA mode info");
1475 }
Michael Sevakisbc8cab42009-03-12 02:01:25 +00001476#endif /* HAVE_ATA_DMA */
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001477 timing_info_present = identify_info[53] & (1<<1);
1478 if(timing_info_present) {
1479 i = identify_info[49] & (1<<11);
Jonathan Gordon69228f92013-02-12 20:35:11 +11001480 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001481 "IORDY support: %s", i ? "yes" : "no");
1482 i = identify_info[49] & (1<<10);
Jonathan Gordon69228f92013-02-12 20:35:11 +11001483 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001484 "IORDY disable: %s", i ? "yes" : "no");
1485 } else {
Jonathan Gordon69228f92013-02-12 20:35:11 +11001486 simplelist_addline(
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001487 "No timing info");
1488 }
Jonathan Gordon69228f92013-02-12 20:35:11 +11001489 simplelist_addline(
Michael Sevakis7d1a47c2013-08-05 22:02:45 -04001490 "Cluster size: %d bytes", volume_get_cluster_size(IF_MV(0)));
Michael Sevakisbc8cab42009-03-12 02:01:25 +00001491#ifdef HAVE_ATA_DMA
1492 i = ata_get_dma_mode();
1493 if (i == 0) {
Jonathan Gordon69228f92013-02-12 20:35:11 +11001494 simplelist_addline(
Michael Sevakisbc8cab42009-03-12 02:01:25 +00001495 "DMA not enabled");
1496 } else {
Jonathan Gordon69228f92013-02-12 20:35:11 +11001497 simplelist_addline(
Michael Sevakisbc8cab42009-03-12 02:01:25 +00001498 "DMA mode: %s %c",
1499 (i & 0x40) ? "UDMA" : "MDMA",
1500 '0' + (i & 7));
1501 }
1502#endif /* HAVE_ATA_DMA */
Jonathan Gordond7dd2392007-07-12 09:58:54 +00001503 return btn;
1504}
Cástor Muñozd20185a2014-12-09 19:38:47 +01001505
1506#ifdef HAVE_ATA_SMART
Cástor Muñoze9497db2016-02-13 18:28:46 +01001507static struct ata_smart_values smart_data STORAGE_ALIGN_ATTR;
Cástor Muñozd20185a2014-12-09 19:38:47 +01001508
1509static const char * ata_smart_get_attr_name(unsigned char id)
1510{
Cástor Muñozff637c72016-02-16 20:42:42 +01001511 if (id == 1) return "Raw Read Error Rate";
1512 if (id == 2) return "Throughput Performance";
1513 if (id == 3) return "Spin-Up Time";
1514 if (id == 4) return "Start/Stop Count";
1515 if (id == 5) return "Reallocated Sector Count";
1516 if (id == 7) return "Seek Error Rate";
1517 if (id == 8) return "Seek Time Performance";
1518 if (id == 9) return "Power-On Hours Count";
1519 if (id == 10) return "Spin-Up Retry Count";
1520 if (id == 12) return "Power Cycle Count";
1521 if (id == 191) return "G-Sense Error Rate";
1522 if (id == 192) return "Power-Off Retract Count";
1523 if (id == 193) return "Load/Unload Cycle Count";
1524 if (id == 194) return "HDA Temperature";
1525 if (id == 195) return "Hardware ECC Recovered";
1526 if (id == 196) return "Reallocated Event Count";
1527 if (id == 197) return "Current Pending Sector Count";
1528 if (id == 198) return "Uncorrectable Sector Count";
1529 if (id == 199) return "UDMA CRC Error Count";
1530 if (id == 200) return "Write Error Rate";
1531 if (id == 201) return "TA Counter Detected";
1532 if (id == 220) return "Disk Shift";
1533 if (id == 222) return "Loaded Hours";
1534 if (id == 223) return "Load/Unload Retry Count";
1535 if (id == 224) return "Load Friction";
1536 if (id == 225) return "Load Cycle Count";
1537 if (id == 226) return "Load-In Time";
1538 if (id == 240) return "Transfer Error Rate"; /* Fujitsu */
1539 return "Unknown Attribute";
Cástor Muñozd20185a2014-12-09 19:38:47 +01001540};
1541
1542static int ata_smart_get_attr_rawfmt(unsigned char id)
1543{
Cástor Muñozff637c72016-02-16 20:42:42 +01001544 if (id == 3) /* Spin-up time */
1545 return RAWFMT_RAW16_OPT_AVG16;
Cástor Muñozd20185a2014-12-09 19:38:47 +01001546
Cástor Muñozff637c72016-02-16 20:42:42 +01001547 if (id == 5 || /* Reallocated sector count */
1548 id == 196) /* Reallocated event count */
1549 return RAWFMT_RAW16_OPT_RAW16;
Cástor Muñozd20185a2014-12-09 19:38:47 +01001550
Cástor Muñozff637c72016-02-16 20:42:42 +01001551 if (id == 190 || /* Airflow Temperature */
1552 id == 194) /* HDA Temperature */
1553 return RAWFMT_TEMPMINMAX;
Cástor Muñozd20185a2014-12-09 19:38:47 +01001554
Cástor Muñozff637c72016-02-16 20:42:42 +01001555 return RAWFMT_RAW48;
Cástor Muñozd20185a2014-12-09 19:38:47 +01001556};
1557
1558static int ata_smart_attr_to_string(
1559 struct ata_smart_attribute *attr, char *str, int size)
1560{
1561 uint16_t w[3]; /* 3 words to store 6 bytes of raw data */
1562 char buf[size]; /* temp string to store attribute data */
1563 int len, slen;
1564 int id = attr->id;
1565
1566 if (id == 0)
1567 return 0; /* null attribute */
1568
1569 /* align and convert raw data */
1570 memcpy(w, attr->raw, 6);
1571 w[0] = letoh16(w[0]);
1572 w[1] = letoh16(w[1]);
1573 w[2] = letoh16(w[2]);
1574
1575 len = snprintf(buf, size, ": %u,%u ", attr->current, attr->worst);
1576
1577 switch (ata_smart_get_attr_rawfmt(id))
1578 {
1579 case RAWFMT_RAW16_OPT_RAW16:
1580 len += snprintf(buf+len, size-len, "%u", w[0]);
1581 if ((w[1] || w[2]) && (len < size))
1582 len += snprintf(buf+len, size-len, " %u %u", w[1],w[2]);
1583 break;
1584
1585 case RAWFMT_RAW16_OPT_AVG16:
1586 len += snprintf(buf+len, size-len, "%u", w[0]);
1587 if (w[1] && (len < size))
1588 len += snprintf(buf+len, size-len, " Avg: %u", w[1]);
1589 break;
1590