blob: 71094c0dd9b8651eaf932ba58fe17a4d09f4c9be [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 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "config.h"
Björn Stenberg803f47b2002-07-15 11:23:24 +000021#include <stdio.h>
22#include <stdbool.h>
Hardeep Sidhu95132362003-08-01 16:05:40 +000023#include <string.h>
Björn Stenberg803f47b2002-07-15 11:23:24 +000024#include "lcd.h"
25#include "menu.h"
26#include "debug_menu.h"
27#include "kernel.h"
28#include "sprintf.h"
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +000029#include "action.h"
Björn Stenberg803f47b2002-07-15 11:23:24 +000030#include "debug.h"
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +000031#include "thread.h"
Heikki Hannikainen6eb42542002-08-06 10:52:51 +000032#include "powermgmt.h"
33#include "system.h"
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +000034#include "font.h"
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +000035#include "audio.h"
Linus Nielsen Feltzingf1f7bbe2004-03-22 11:48:13 +000036#include "mp3_playback.h"
Björn Stenbergae22de22002-12-02 16:07:56 +000037#include "settings.h"
Linus Nielsen Feltzingf3ad6192004-02-16 12:04:55 +000038#include "dir.h"
39#include "panic.h"
Linus Nielsen Feltzingb81a3c52004-03-25 12:29:34 +000040#include "screens.h"
Linus Nielsen Feltzingade5d7b2004-07-26 16:06:59 +000041#include "misc.h"
Kevin Ferraree991bee2005-11-16 15:12:15 +000042#include "splash.h"
Miika Pekkarinen7c4e0c82006-03-26 11:33:42 +000043#include "dircache.h"
Jonathan Gordon710ccb72006-10-25 10:17:57 +000044#ifdef HAVE_TAGCACHE
Miika Pekkarinen7c4e0c82006-03-26 11:33:42 +000045#include "tagcache.h"
Jonathan Gordon710ccb72006-10-25 10:17:57 +000046#endif
Linus Nielsen Feltzing00811842006-02-17 22:38:38 +000047#include "lcd-remote.h"
Jens Arnold106f7732006-05-07 22:19:29 +000048#include "crc32.h"
Miika Pekkarinen954b7322006-08-05 20:19:10 +000049#include "logf.h"
Steve Bavin2c2b50a2006-10-04 07:29:50 +000050#ifndef SIMULATOR
51#include "disk.h"
52#include "adc.h"
53#include "power.h"
54#include "usb.h"
55#include "rtc.h"
56#include "ata.h"
57#include "fat.h"
58#include "mas.h"
59#include "eeprom_24cxx.h"
60#ifdef HAVE_MMC
61#include "ata_mmc.h"
Linus Nielsen Feltzing875bf5e2002-10-15 08:08:35 +000062#endif
Jonathan Gordon8ff3a652007-02-18 02:04:47 +000063#if CONFIG_TUNER
Rani Hodd159ae52006-08-11 17:39:34 +000064#include "tuner.h"
Linus Nielsen Feltzing05796672004-02-05 10:59:51 +000065#include "radio.h"
66#endif
Steve Bavin2c2b50a2006-10-04 07:29:50 +000067#endif
68
69#ifdef HAVE_LCD_BITMAP
Jonathan Gordon62885232006-11-19 14:11:42 +000070#include "scrollbar.h"
Steve Bavin2c2b50a2006-10-04 07:29:50 +000071#include "peakmeter.h"
Jens Arnold6f9a7eb2004-10-06 20:43:12 +000072#endif
Daniel Stenbergedc07922005-05-30 13:00:43 +000073#include "logfdisp.h"
Jens Arnoldd6c05452005-08-29 21:15:27 +000074#if CONFIG_CODEC == SWCODEC
Miika Pekkarinenb0e78a42005-07-13 13:13:10 +000075#include "pcmbuf.h"
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +000076#include "pcm_playback.h"
Michael Sevakiscc50c142006-11-13 23:21:54 +000077#if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
78#include "spdif.h"
79#endif
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +000080#endif
Steve Bavin338d94f2007-02-01 10:47:22 +000081#ifdef IRIVER_H300_SERIES
82#include "pcf50606.h" /* for pcf50606_read */
83#endif
Michael Sevakis89a38d42007-03-11 13:59:31 +000084#ifdef IAUDIO_X5
85#include "ds2411.h"
86#endif
Björn Stenberg803f47b2002-07-15 11:23:24 +000087
88/*---------------------------------------------------*/
89/* SPECIAL DEBUG STUFF */
90/*---------------------------------------------------*/
Jens Arnold31ffd7b2006-12-03 22:13:44 +000091extern int ata_device;
Björn Stenberg803f47b2002-07-15 11:23:24 +000092extern int ata_io_address;
Miika Pekkarinen36862282006-09-02 07:56:52 +000093extern struct core_entry cores[NUM_CORES];
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +000094
Jens Arnold314f3b52006-12-12 22:22:21 +000095#ifndef SIMULATOR
96#ifdef HAVE_LCD_BITMAP
97static char thread_status_char(int status)
Miika Pekkarinena85044b2006-09-16 16:18:11 +000098{
99 switch (status)
100 {
101 case STATE_RUNNING : return 'R';
102 case STATE_BLOCKED : return 'B';
103 case STATE_SLEEPING : return 'S';
104 case STATE_BLOCKED_W_TMO: return 'T';
105 }
Michael Sevakis1d4a9c62006-10-27 05:31:28 +0000106
Miika Pekkarinena85044b2006-09-16 16:18:11 +0000107 return '?';
108}
Jens Arnold314f3b52006-12-12 22:22:21 +0000109
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000110/* Test code!!! */
Jens Arnold314f3b52006-12-12 22:22:21 +0000111static bool dbg_os(void)
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000112{
Miika Pekkarinena85044b2006-09-16 16:18:11 +0000113 struct thread_entry *thread;
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000114 char buf[32];
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000115 int i;
116 int usage;
Miika Pekkarinena85044b2006-09-16 16:18:11 +0000117 int status;
Daniel Ankersc1e45452006-08-31 20:19:18 +0000118#if NUM_CORES > 1
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000119 unsigned int core;
120 int line;
Daniel Ankersc1e45452006-08-31 20:19:18 +0000121#endif
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000122
Markus Brauna0300f52002-08-20 22:13:20 +0000123 lcd_setmargins(0, 0);
Linus Nielsen Feltzing57d8e8f2005-08-18 07:16:53 +0000124 lcd_setfont(FONT_SYSFIXED);
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000125 lcd_clear_display();
126
127 while(1)
128 {
Miika Pekkarinena85044b2006-09-16 16:18:11 +0000129#if 0 /* Enable to simulate UI lag. */
130 int _x;
131 for (_x = 0; _x < 1000000L; _x++) ;
132#endif
Daniel Ankersc1e45452006-08-31 20:19:18 +0000133#if NUM_CORES > 1
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000134 lcd_puts(0, 0, "Core and stack usage:");
135 line = 0;
136 for(core = 0; core < NUM_CORES; core++)
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000137 {
Miika Pekkarinena85044b2006-09-16 16:18:11 +0000138 for(i = 0; i < MAXTHREADS; i++)
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000139 {
Miika Pekkarinena85044b2006-09-16 16:18:11 +0000140 thread = &cores[core].threads[i];
141 if (thread->name == NULL)
142 continue;
Michael Sevakis1d4a9c62006-10-27 05:31:28 +0000143
Miika Pekkarinena85044b2006-09-16 16:18:11 +0000144 usage = thread_stack_usage(thread);
145 status = thread_get_status(thread);
Michael Sevakis1d4a9c62006-10-27 05:31:28 +0000146
Brandon Lowda7d05d2006-12-25 15:44:35 +0000147# ifdef HAVE_PRIORITY_SCHEDULING
Michael Sevakis1d4a9c62006-10-27 05:31:28 +0000148 snprintf(buf, 32, "(%d) %c%c %d %s: %d%%", core,
149 (status == STATE_RUNNING) ? '*' : ' ',
Miika Pekkarinena85044b2006-09-16 16:18:11 +0000150 thread_status_char(status),
151 cores[CURRENT_CORE].threads[i].priority,
152 cores[core].threads[i].name, usage);
Brandon Lowda7d05d2006-12-25 15:44:35 +0000153# else
154 snprintf(buf, 32, "(%d) %c%c %s: %d%%", core,
155 (status == STATE_RUNNING) ? '*' : ' ',
156 thread_status_char(status),
157 cores[core].threads[i].name, usage);
158# endif
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000159 lcd_puts(0, ++line, buf);
160 }
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000161 }
Daniel Ankersc1e45452006-08-31 20:19:18 +0000162#else
163 lcd_puts(0, 0, "Stack usage:");
Miika Pekkarinena85044b2006-09-16 16:18:11 +0000164 for(i = 0; i < MAXTHREADS; i++)
Daniel Ankersc1e45452006-08-31 20:19:18 +0000165 {
Miika Pekkarinena85044b2006-09-16 16:18:11 +0000166 thread = &cores[CURRENT_CORE].threads[i];
167 if (thread->name == NULL)
168 continue;
Michael Sevakis1d4a9c62006-10-27 05:31:28 +0000169
Miika Pekkarinena85044b2006-09-16 16:18:11 +0000170 usage = thread_stack_usage(thread);
171 status = thread_get_status(thread);
172# ifdef HAVE_PRIORITY_SCHEDULING
173 snprintf(buf, 32, "%c%c %d %s: %d%%",
Michael Sevakis1d4a9c62006-10-27 05:31:28 +0000174 (status == STATE_RUNNING) ? '*' : ' ',
Miika Pekkarinena85044b2006-09-16 16:18:11 +0000175 thread_status_char(status),
176 cores[CURRENT_CORE].threads[i].priority,
177 cores[CURRENT_CORE].threads[i].name, usage);
178# else
179 snprintf(buf, 32, "%c%c %s: %d%%",
Michael Sevakis1d4a9c62006-10-27 05:31:28 +0000180 (status == STATE_RUNNING) ? '*' : ' ',
Jens Arnold314f3b52006-12-12 22:22:21 +0000181 thread_status_char(status),
Miika Pekkarinena85044b2006-09-16 16:18:11 +0000182 cores[CURRENT_CORE].threads[i].name, usage);
183# endif
Daniel Ankersc1e45452006-08-31 20:19:18 +0000184 lcd_puts(0, 1+i, buf);
185 }
186#endif
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000187
188 lcd_update();
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000189
Jonathan Gordon475be662006-08-16 04:27:33 +0000190 if (action_userabort(HZ/10))
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000191 return false;
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000192 }
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000193 return false;
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000194}
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000195#else /* !HAVE_LCD_BITMAP */
Jens Arnold314f3b52006-12-12 22:22:21 +0000196static bool dbg_os(void)
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000197{
198 char buf[32];
199 int button;
200 int usage;
201 int currval = 0;
202
203 lcd_clear_display();
204
205 while(1)
206 {
Robert Hak50fc3ce2002-08-10 08:52:11 +0000207 lcd_puts(0, 0, "Stack usage");
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000208
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000209 /* Only Archos Player uses this - so assume a single core */
Miika Pekkarinen610190a2006-09-16 16:33:42 +0000210 usage = thread_stack_usage(&cores[CPU].threads[currval]);
Robert Hak50fc3ce2002-08-10 08:52:11 +0000211 snprintf(buf, 32, "%d: %d%% ", currval, usage);
212 lcd_puts(0, 1, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000213
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000214 button = get_action(CONTEXT_SETTINGS,HZ/10);
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000215
216 switch(button)
217 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000218 case ACTION_STD_CANCEL:
219 action_signalscreenchange();
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000220 return false;
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000221
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000222 case ACTION_SETTINGS_DEC:
Robert Hak50fc3ce2002-08-10 08:52:11 +0000223 currval--;
224 if(currval < 0)
Miika Pekkarinen610190a2006-09-16 16:33:42 +0000225 currval = MAXTHREADS-1;
Robert Hak50fc3ce2002-08-10 08:52:11 +0000226 break;
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000227
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000228 case ACTION_SETTINGS_INC:
Robert Hak50fc3ce2002-08-10 08:52:11 +0000229 currval++;
Miika Pekkarinen610190a2006-09-16 16:33:42 +0000230 if(currval > MAXTHREADS-1)
Robert Hak50fc3ce2002-08-10 08:52:11 +0000231 currval = 0;
232 break;
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000233 }
234 }
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000235 return false;
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000236}
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000237#endif /* !HAVE_LCD_BITMAP */
Steve Bavin2c2b50a2006-10-04 07:29:50 +0000238#endif /* !SIMULATOR */
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000239#ifdef HAVE_LCD_BITMAP
Jens Arnoldd6c05452005-08-29 21:15:27 +0000240#if CONFIG_CODEC != SWCODEC
Steve Bavin2c2b50a2006-10-04 07:29:50 +0000241#ifndef SIMULATOR
Jens Arnold314f3b52006-12-12 22:22:21 +0000242static bool dbg_audio_thread(void)
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000243{
244 char buf[32];
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +0000245 struct audio_debug d;
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000246
Linus Nielsen Feltzingbf303de2002-10-15 07:23:18 +0000247 lcd_setmargins(0, 0);
Linus Nielsen Feltzing44bba0f2005-06-22 21:37:00 +0000248 lcd_setfont(FONT_SYSFIXED);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000249
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000250 while(1)
251 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000252 if (action_userabort(HZ/5))
253 return false;
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000254
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +0000255 audio_get_debugdata(&d);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000256
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000257 lcd_clear_display();
258
Linus Nielsen Feltzingd34865a2005-04-05 11:33:58 +0000259 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000260 lcd_puts(0, 0, buf);
Linus Nielsen Feltzingd34865a2005-04-05 11:33:58 +0000261 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000262 lcd_puts(0, 1, buf);
Linus Nielsen Feltzingd34865a2005-04-05 11:33:58 +0000263 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000264 lcd_puts(0, 2, buf);
265 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
266 lcd_puts(0, 3, buf);
Linus Nielsen Feltzingd29248d2002-12-05 14:11:48 +0000267 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000268 lcd_puts(0, 4, buf);
269 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
270 lcd_puts(0, 5, buf);
Linus Nielsen Feltzingbf303de2002-10-15 07:23:18 +0000271
Linus Nielsen Feltzing24410612004-07-08 13:14:44 +0000272 /* Playable space left */
Jonathan Gordon62885232006-11-19 14:11:42 +0000273 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8, 112, 4, d.audiobuflen, 0,
Linus Nielsen Feltzing24410612004-07-08 13:14:44 +0000274 d.playable_space, HORIZONTAL);
Linus Nielsen Feltzingbf303de2002-10-15 07:23:18 +0000275
Linus Nielsen Feltzing24410612004-07-08 13:14:44 +0000276 /* Show the watermark limit */
Jonathan Gordon62885232006-11-19 14:11:42 +0000277 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, 6*8+4, 112, 4, d.audiobuflen, 0,
Linus Nielsen Feltzing24410612004-07-08 13:14:44 +0000278 d.low_watermark_level, HORIZONTAL);
Linus Nielsen Feltzingbf303de2002-10-15 07:23:18 +0000279
Linus Nielsen Feltzingb8ff5f82002-12-05 13:09:51 +0000280 snprintf(buf, sizeof(buf), "wm: %x - %x",
281 d.low_watermark_level, d.lowest_watermark_level);
Linus Nielsen Feltzingbf303de2002-10-15 07:23:18 +0000282 lcd_puts(0, 7, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000283
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000284 lcd_update();
285 }
286 return false;
287}
Steve Bavin2c2b50a2006-10-04 07:29:50 +0000288#endif /* !SIMULATOR */
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000289#else /* CONFIG_CODEC == SWCODEC */
Brandon Lowbb2eecb2006-04-14 04:46:05 +0000290extern size_t filebuflen;
291/* This is a size_t, but call it a long so it puts a - when it's bad. */
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000292
Brandon Low413da2a2006-02-07 20:38:55 +0000293static unsigned int ticks, boost_ticks;
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000294
Jens Arnold314f3b52006-12-12 22:22:21 +0000295static void dbg_audio_task(void)
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000296{
Steve Bavin2c2b50a2006-10-04 07:29:50 +0000297#ifndef SIMULATOR
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000298 if(FREQ > CPUFREQ_NORMAL)
299 boost_ticks++;
Steve Bavin2c2b50a2006-10-04 07:29:50 +0000300#endif
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000301
302 ticks++;
303}
304
Jens Arnold314f3b52006-12-12 22:22:21 +0000305static bool dbg_audio_thread(void)
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000306{
307 char buf[32];
308 int button;
309 int line;
Linus Nielsen Feltzingfcc282c2005-06-22 14:09:07 +0000310 bool done = false;
Brandon Low75de60b2006-04-25 20:32:38 +0000311 size_t bufused;
Brandon Low413da2a2006-02-07 20:38:55 +0000312 size_t bufsize = pcmbuf_get_bufsize();
313 int pcmbufdescs = pcmbuf_descs();
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000314
315 ticks = boost_ticks = 0;
316
317 tick_add_task(dbg_audio_task);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000318
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000319 lcd_setmargins(0, 0);
Linus Nielsen Feltzing44bba0f2005-06-22 21:37:00 +0000320 lcd_setfont(FONT_SYSFIXED);
Linus Nielsen Feltzingfcc282c2005-06-22 14:09:07 +0000321 while(!done)
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000322 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000323 button = get_action(CONTEXT_STD,HZ/5);
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000324 switch(button)
325 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000326 case ACTION_STD_NEXT:
Brandon Low413da2a2006-02-07 20:38:55 +0000327 audio_next();
328 break;
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000329 case ACTION_STD_PREV:
Brandon Low413da2a2006-02-07 20:38:55 +0000330 audio_prev();
331 break;
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000332 case ACTION_STD_CANCEL:
Linus Nielsen Feltzingfcc282c2005-06-22 14:09:07 +0000333 done = true;
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000334 break;
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000335 }
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000336 action_signalscreenchange();
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000337 line = 0;
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000338
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000339 lcd_clear_display();
340
Brandon Low75de60b2006-04-25 20:32:38 +0000341 bufused = bufsize - pcmbuf_free();
342
Steve Bavin2c2b50a2006-10-04 07:29:50 +0000343 snprintf(buf, sizeof(buf), "pcm: %7ld/%7ld", (long) bufused, (long) bufsize);
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000344 lcd_puts(0, line++, buf);
345
346 /* Playable space left */
Jonathan Gordon62885232006-11-19 14:11:42 +0000347 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6, bufsize, 0, bufused, HORIZONTAL);
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000348 line++;
349
Steve Bavin73e2f7b2006-10-12 16:51:22 +0000350 snprintf(buf, sizeof(buf), "codec: %8ld/%8ld", audio_filebufused(), (long) filebuflen);
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000351 lcd_puts(0, line++, buf);
352
353 /* Playable space left */
Jonathan Gordon62885232006-11-19 14:11:42 +0000354 gui_scrollbar_draw(&screens[SCREEN_MAIN],0, line*8, LCD_WIDTH, 6, filebuflen, 0,
Steve Bavin73e2f7b2006-10-12 16:51:22 +0000355 audio_filebufused(), HORIZONTAL);
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000356 line++;
357
Brandon Low72232bd2006-04-09 02:15:35 +0000358 snprintf(buf, sizeof(buf), "track count: %2d", audio_track_count());
Linus Nielsen Feltzing17098e12005-06-22 20:37:31 +0000359 lcd_puts(0, line++, buf);
360
Steve Bavin2c2b50a2006-10-04 07:29:50 +0000361#ifndef SIMULATOR
Brandon Low413da2a2006-02-07 20:38:55 +0000362 snprintf(buf, sizeof(buf), "cpu freq: %3dMHz",
Jens Arnoldcfb073c2005-10-03 09:24:36 +0000363 (int)((FREQ + 500000) / 1000000));
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000364 lcd_puts(0, line++, buf);
Steve Bavin2c2b50a2006-10-04 07:29:50 +0000365#endif
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000366
Brandon Low413da2a2006-02-07 20:38:55 +0000367 snprintf(buf, sizeof(buf), "boost ratio: %3d%%",
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000368 boost_ticks * 100 / ticks);
369 lcd_puts(0, line++, buf);
370
Brandon Low413da2a2006-02-07 20:38:55 +0000371 snprintf(buf, sizeof(buf), "pcmbufdesc: %2d/%2d",
372 pcmbuf_used_descs(), pcmbufdescs);
373 lcd_puts(0, line++, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000374
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000375 lcd_update();
376 }
377
378 tick_remove_task(dbg_audio_task);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000379
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000380 return false;
381}
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000382#endif /* CONFIG_CODEC */
383#endif /* HAVE_LCD_BITMAP */
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000384
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000385
Jens Arnold314f3b52006-12-12 22:22:21 +0000386#if (CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)) && !defined(SIMULATOR)
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000387/* Tool function to read the flash manufacturer and type, if available.
388 Only chips which could be reprogrammed in system will return values.
389 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
Jörg Hohensohn5846aab2004-07-19 21:21:34 +0000390 /* In IRAM to avoid problems when running directly from Flash */
Jens Arnold314f3b52006-12-12 22:22:21 +0000391static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
392 unsigned addr1, unsigned addr2)
393 ICODE_ATTR __attribute__((noinline));
394static bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
395 unsigned addr1, unsigned addr2)
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000396
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000397{
398 unsigned not_manu, not_id; /* read values before switching to ID mode */
399 unsigned manu, id; /* read values when in ID mode */
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000400
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000401#if CONFIG_CPU == SH7034
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000402 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
Linus Nielsen Feltzing9ffaa172006-03-18 23:07:34 +0000403#elif defined(CPU_COLDFIRE)
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000404 volatile unsigned short* flash = (unsigned short*)0; /* flash mapping */
405#endif
Jörg Hohensohn5846aab2004-07-19 21:21:34 +0000406 int old_level; /* saved interrupt level */
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000407
Jens Arnold780f79e2006-11-10 20:26:01 +0000408 not_manu = flash[0]; /* read the normal content */
409 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000410
Jörg Hohensohn5846aab2004-07-19 21:21:34 +0000411 /* disable interrupts, prevent any stray flash access */
412 old_level = set_irq_level(HIGHEST_IRQ_LEVEL);
413
Jens Arnold780f79e2006-11-10 20:26:01 +0000414 flash[addr1] = 0xAA; /* enter command mode */
415 flash[addr2] = 0x55;
416 flash[addr1] = 0x90; /* ID command */
Jörg Hohensohn5846aab2004-07-19 21:21:34 +0000417 /* Atmel wants 20ms pause here */
418 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000419
Jens Arnold780f79e2006-11-10 20:26:01 +0000420 manu = flash[0]; /* read the IDs */
421 id = flash[1];
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000422
Jens Arnold780f79e2006-11-10 20:26:01 +0000423 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
Jörg Hohensohn5846aab2004-07-19 21:21:34 +0000424 /* Atmel wants 20ms pause here */
425 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
426
427 set_irq_level(old_level); /* enable interrupts again */
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000428
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000429 /* I assume success if the obtained values are different from
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000430 the normal flash content. This is not perfectly bulletproof, they
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000431 could theoretically be the same by chance, causing us to fail. */
432 if (not_manu != manu || not_id != id) /* a value has changed */
433 {
434 *p_manufacturer = manu; /* return the results */
435 *p_device = id;
436 return true; /* success */
437 }
438 return false; /* fail */
439}
Jens Arnold314f3b52006-12-12 22:22:21 +0000440#endif /* (CONFIG_CPU == SH7034 || CPU_COLDFIRE) && !SIMULATOR */
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000441
Steve Bavin5db6bb12006-10-04 07:42:45 +0000442#ifndef SIMULATOR
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000443#ifdef HAVE_LCD_BITMAP
Jens Arnold314f3b52006-12-12 22:22:21 +0000444static bool dbg_hw_info(void)
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000445{
Daniel Stenberg1d395ae2005-02-02 21:57:40 +0000446#if CONFIG_CPU == SH7034
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000447 char buf[32];
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000448 int usb_polarity;
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000449 int pr_polarity;
Linus Nielsen Feltzing3cfc6ec2002-10-08 11:15:00 +0000450 int bitmask = *(unsigned short*)0x20000fc;
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000451 int rom_version = *(unsigned short*)0x20000fe;
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000452 unsigned manu, id; /* flash IDs */
453 bool got_id; /* flag if we managed to get the flash IDs */
Jens Arnold106f7732006-05-07 22:19:29 +0000454 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
Jörg Hohensohnd8b31812003-10-29 22:10:13 +0000455 bool has_bootrom; /* flag for boot ROM present */
Jens Arnold06cb2372004-08-30 19:52:45 +0000456 int oldmode; /* saved memory guard mode */
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000457
Jens Arnold4c428e02004-10-01 20:21:17 +0000458#ifdef USB_ENABLE_ONDIOSTYLE
Jens Arnoldd89b75b2005-05-08 12:16:46 +0000459 if(PADRL & 0x20)
Jens Arnold4c428e02004-10-01 20:21:17 +0000460#else
Jens Arnoldd89b75b2005-05-08 12:16:46 +0000461 if(PADRH & 0x04)
Jens Arnold4c428e02004-10-01 20:21:17 +0000462#endif
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000463 usb_polarity = 0; /* Negative */
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000464 else
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000465 usb_polarity = 1; /* Positive */
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000466
Jens Arnoldd89b75b2005-05-08 12:16:46 +0000467 if(PADRH & 0x08)
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000468 pr_polarity = 0; /* Negative */
469 else
470 pr_polarity = 1; /* Positive */
Linus Nielsen Feltzing07083fb2002-10-09 06:36:32 +0000471
Jens Arnold06cb2372004-08-30 19:52:45 +0000472 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
473
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000474 /* get flash ROM type */
475 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
476 if (!got_id)
477 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000478
Jörg Hohensohnd8b31812003-10-29 22:10:13 +0000479 /* check if the boot ROM area is a flash mirror */
480 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
481 if (has_bootrom) /* if ROM and Flash different */
482 {
483 /* calculate CRC16 checksum of boot ROM */
Jens Arnold106f7732006-05-07 22:19:29 +0000484 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
Jörg Hohensohnd8b31812003-10-29 22:10:13 +0000485 }
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000486
Jens Arnold06cb2372004-08-30 19:52:45 +0000487 system_memory_guard(oldmode); /* re-enable memory guard */
488
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000489 lcd_setmargins(0, 0);
490 lcd_setfont(FONT_SYSFIXED);
491 lcd_clear_display();
492
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000493 lcd_puts(0, 0, "[Hardware info]");
494
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000495 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
496 lcd_puts(0, 1, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000497
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000498 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000499 lcd_puts(0, 2, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000500
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000501 snprintf(buf, 32, "USB: %s", usb_polarity?"positive":"negative");
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000502 lcd_puts(0, 3, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000503
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000504 snprintf(buf, 32, "PR: %s", pr_polarity?"positive":"negative");
Jörg Hohensohn099ef222004-10-22 20:44:26 +0000505 lcd_puts(0, 4, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000506
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000507 if (got_id)
508 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
509 else
510 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
Jörg Hohensohn099ef222004-10-22 20:44:26 +0000511 lcd_puts(0, 5, buf);
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000512
Jörg Hohensohnd8b31812003-10-29 22:10:13 +0000513 if (has_bootrom)
514 {
Jens Arnold106f7732006-05-07 22:19:29 +0000515 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
516 snprintf(buf, 32, "Boot ROM: V1");
517 else
518 snprintf(buf, 32, "ROMcrc: 0x%08x", rom_crc);
Jörg Hohensohnd8b31812003-10-29 22:10:13 +0000519 }
520 else
521 {
522 snprintf(buf, 32, "Boot ROM: none");
523 }
Jörg Hohensohn099ef222004-10-22 20:44:26 +0000524 lcd_puts(0, 6, buf);
525
526#ifndef HAVE_MMC /* have ATA */
527 snprintf(buf, 32, "ATA: 0x%x,%s", ata_io_address,
528 ata_device ? "slave":"master");
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000529 lcd_puts(0, 7, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000530#endif
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000531 lcd_update();
Linus Nielsen Feltzing46a94be2002-10-14 14:25:25 +0000532
533 while(1)
534 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000535 if (action_userabort(TIMEOUT_BLOCK))
Linus Nielsen Feltzing46a94be2002-10-14 14:25:25 +0000536 return false;
537 }
Rani Hodd159ae52006-08-11 17:39:34 +0000538#elif CONFIG_CPU == MCF5249 || CONFIG_CPU == MCF5250
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000539 char buf[32];
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000540 unsigned manu, id; /* flash IDs */
Michael Sevakis89a38d42007-03-11 13:59:31 +0000541 int got_id; /* flag if we managed to get the flash IDs */
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000542 int oldmode; /* saved memory guard mode */
Michael Sevakis89a38d42007-03-11 13:59:31 +0000543 int line = 0;
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000544
545 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
546
547 /* get flash ROM type */
548 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
549 if (!got_id)
550 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000551
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000552 system_memory_guard(oldmode); /* re-enable memory guard */
553
554 lcd_setmargins(0, 0);
555 lcd_setfont(FONT_SYSFIXED);
556 lcd_clear_display();
557
Michael Sevakis89a38d42007-03-11 13:59:31 +0000558 lcd_puts(0, line++, "[Hardware info]");
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000559
560 if (got_id)
561 snprintf(buf, 32, "Flash: M=%04x D=%04x", manu, id);
562 else
563 snprintf(buf, 32, "Flash: M=???? D=????"); /* unknown, sorry */
Michael Sevakis89a38d42007-03-11 13:59:31 +0000564 lcd_puts(0, line++, buf);
565
566#ifdef IAUDIO_X5
567 {
568 struct ds2411_id id;
569
Michael Sevakisc7954a02007-03-11 15:33:59 +0000570 lcd_puts(0, ++line, "Serial Number:");
Michael Sevakis89a38d42007-03-11 13:59:31 +0000571
572 got_id = ds2411_read_id(&id);
573
574 if (got_id == DS2411_OK)
575 {
576 snprintf(buf, 32, " FC=%02x", (unsigned)id.family_code);
Michael Sevakisc7954a02007-03-11 15:33:59 +0000577 lcd_puts(0, ++line, buf);
Michael Sevakis89a38d42007-03-11 13:59:31 +0000578 snprintf(buf, 32, " ID=%02X %02X %02X %02X %02X %02X",
579 (unsigned)id.uid[0], (unsigned)id.uid[1], (unsigned)id.uid[2],
580 (unsigned)id.uid[3], (unsigned)id.uid[4], (unsigned)id.uid[5]);
Michael Sevakisc7954a02007-03-11 15:33:59 +0000581 lcd_puts(0, ++line, buf);
Michael Sevakis89a38d42007-03-11 13:59:31 +0000582 snprintf(buf, 32, " CRC=%02X", (unsigned)id.crc);
Michael Sevakis89a38d42007-03-11 13:59:31 +0000583 }
584 else
585 {
586 snprintf(buf, 32, "READ ERR=%d", got_id);
Michael Sevakis89a38d42007-03-11 13:59:31 +0000587 }
Michael Sevakisc7954a02007-03-11 15:33:59 +0000588
589 lcd_puts(0, ++line, buf);
Michael Sevakis89a38d42007-03-11 13:59:31 +0000590 }
591#endif
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000592
593 lcd_update();
594
595 while(1)
596 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000597 if (action_userabort(TIMEOUT_BLOCK))
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000598 return false;
599 }
Jens Arnold1d085332006-05-07 22:56:44 +0000600#elif CONFIG_CPU == PP5020
601 char buf[32];
Barry Wardell38b64f72007-03-04 16:06:54 +0000602 char pp_version[] = { (PP_VER2 >> 24) & 0xff, (PP_VER2 >> 16) & 0xff,
603 (PP_VER2 >> 8) & 0xff, (PP_VER2) & 0xff,
604 (PP_VER1 >> 24) & 0xff, (PP_VER1 >> 16) & 0xff,
605 (PP_VER1 >> 8) & 0xff, (PP_VER1) & 0xff, '\0' };
606
Jens Arnold1d085332006-05-07 22:56:44 +0000607 lcd_setmargins(0, 0);
608 lcd_setfont(FONT_SYSFIXED);
609 lcd_clear_display();
610
611 lcd_puts(0, 0, "[Hardware info]");
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000612
Jens Arnold1d085332006-05-07 22:56:44 +0000613 snprintf(buf, sizeof(buf), "HW rev: 0x%08x", ipod_hw_rev);
614 lcd_puts(0, 1, buf);
615
Barry Wardell169ebdb2007-03-03 23:37:17 +0000616 snprintf(buf, sizeof(buf), "PP version: %s", pp_version);
617 lcd_puts(0, 2, buf);
Jens Arnold1d085332006-05-07 22:56:44 +0000618 lcd_update();
619
620 while(1)
621 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000622 if (action_userabort(TIMEOUT_BLOCK))
Jens Arnold1d085332006-05-07 22:56:44 +0000623 return false;
624 }
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000625#endif /* CONFIG_CPU */
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000626 return false;
627}
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000628#else /* !HAVE_LCD_BITMAP */
Jens Arnold314f3b52006-12-12 22:22:21 +0000629static bool dbg_hw_info(void)
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000630{
631 char buf[32];
632 int button;
633 int currval = 0;
634 int usb_polarity;
635 int bitmask = *(unsigned short*)0x20000fc;
636 int rom_version = *(unsigned short*)0x20000fe;
Jörg Hohensohn09d1a732003-05-20 21:30:53 +0000637 unsigned manu, id; /* flash IDs */
638 bool got_id; /* flag if we managed to get the flash IDs */
Jens Arnold106f7732006-05-07 22:19:29 +0000639 unsigned rom_crc = 0xffffffff; /* CRC32 of the boot ROM */
Jörg Hohensohnd8b31812003-10-29 22:10:13 +0000640 bool has_bootrom; /* flag for boot ROM present */
Jens Arnold06cb2372004-08-30 19:52:45 +0000641 int oldmode; /* saved memory guard mode */
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000642
Jens Arnoldd89b75b2005-05-08 12:16:46 +0000643 if(PADRH & 0x04)
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000644 usb_polarity = 0; /* Negative */
645 else
646 usb_polarity = 1; /* Positive */
647
Jens Arnold06cb2372004-08-30 19:52:45 +0000648 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
649
Jörg Hohensohn09d1a732003-05-20 21:30:53 +0000650 /* get flash ROM type */
651 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
652 if (!got_id)
653 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
654
Jörg Hohensohnd8b31812003-10-29 22:10:13 +0000655 /* check if the boot ROM area is a flash mirror */
656 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
657 if (has_bootrom) /* if ROM and Flash different */
658 {
659 /* calculate CRC16 checksum of boot ROM */
Jens Arnold106f7732006-05-07 22:19:29 +0000660 rom_crc = crc_32((unsigned char*)0x0000, 64*1024, 0xffffffff);
Jörg Hohensohnd8b31812003-10-29 22:10:13 +0000661 }
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000662
Jens Arnold06cb2372004-08-30 19:52:45 +0000663 system_memory_guard(oldmode); /* re-enable memory guard */
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000664
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000665 lcd_clear_display();
666
667 lcd_puts(0, 0, "[HW Info]");
668 while(1)
669 {
670 switch(currval)
671 {
672 case 0:
673 snprintf(buf, 32, "ROM: %d.%02d",
674 rom_version/100, rom_version%100);
675 break;
676 case 1:
677 snprintf(buf, 32, "USB: %s",
678 usb_polarity?"pos":"neg");
679 break;
680 case 2:
Björn Stenbergee192fb2003-08-05 13:39:38 +0000681 snprintf(buf, 32, "ATA: 0x%x%s",
Björn Stenberg8abc9d42003-08-05 13:41:00 +0000682 ata_io_address, ata_device ? "s":"m");
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000683 break;
684 case 3:
685 snprintf(buf, 32, "Mask: %04x", bitmask);
686 break;
Jörg Hohensohn09d1a732003-05-20 21:30:53 +0000687 case 4:
688 if (got_id)
689 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
690 else
691 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
692 break;
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000693 case 5:
Jörg Hohensohnd8b31812003-10-29 22:10:13 +0000694 if (has_bootrom)
Jens Arnold106f7732006-05-07 22:19:29 +0000695 {
696 if (rom_crc == 0x56DBA4EE) /* known Version 1 */
697 snprintf(buf, 32, "BootROM: V1");
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000698 else if (rom_crc == 0x358099E8)
Jens Arnold106f7732006-05-07 22:19:29 +0000699 snprintf(buf, 32, "BootROM: V2");
700 /* alternative boot ROM found in one single player so far */
701 else
702 snprintf(buf, 32, "R: %08x", rom_crc);
703 }
Jörg Hohensohnd8b31812003-10-29 22:10:13 +0000704 else
705 snprintf(buf, 32, "BootROM: no");
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000706 }
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000707
Linus Nielsen Feltzing07083fb2002-10-09 06:36:32 +0000708 lcd_puts(0, 1, buf);
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000709 lcd_update();
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000710
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000711 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000712
713 switch(button)
714 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000715 case ACTION_STD_CANCEL:
716 action_signalscreenchange();
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000717 return false;
718
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000719 case ACTION_SETTINGS_DEC:
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000720 currval--;
721 if(currval < 0)
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000722 currval = 5;
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000723 break;
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000724
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000725 case ACTION_SETTINGS_INC:
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000726 currval++;
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000727 if(currval > 5)
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000728 currval = 0;
729 break;
730 }
731 }
732 return false;
733}
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000734#endif /* !HAVE_LCD_BITMAP */
Steve Bavin5db6bb12006-10-04 07:42:45 +0000735#endif /* !SIMULATOR */
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000736
Steve Bavin2c2b50a2006-10-04 07:29:50 +0000737#ifndef SIMULATOR
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000738bool dbg_partitions(void)
739{
740 int partition=0;
741
742 lcd_clear_display();
743 lcd_puts(0, 0, "Partition");
744 lcd_puts(0, 1, "list");
745 lcd_update();
Björn Stenbergf09c5f42002-12-03 14:18:51 +0000746 sleep(HZ/2);
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000747
748 while(1)
749 {
750 char buf[32];
751 int button;
752 struct partinfo* p = disk_partinfo(partition);
753
754 lcd_clear_display();
Jens Arnold6baa55a2005-01-24 01:39:24 +0000755 snprintf(buf, sizeof buf, "P%d: S:%lx", partition, p->start);
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000756 lcd_puts(0, 0, buf);
Jens Arnold6baa55a2005-01-24 01:39:24 +0000757 snprintf(buf, sizeof buf, "T:%x %ld MB", p->type, p->size / 2048);
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000758 lcd_puts(0, 1, buf);
759 lcd_update();
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000760
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000761 button = get_action(CONTEXT_SETTINGS,TIMEOUT_BLOCK);
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000762
763 switch(button)
764 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000765 case ACTION_STD_CANCEL:
766 action_signalscreenchange();
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000767 return false;
768
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000769 case ACTION_SETTINGS_DEC:
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000770 partition--;
771 if (partition < 0)
772 partition = 3;
773 break;
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000774
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000775 case ACTION_SETTINGS_INC:
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000776 partition++;
777 if (partition > 3)
778 partition = 0;
779 break;
Linus Nielsen Feltzingade5d7b2004-07-26 16:06:59 +0000780
781 default:
782 if(default_event_handler(button) == SYS_USB_CONNECTED)
783 return true;
784 break;
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000785 }
786 }
787 return false;
788}
Steve Bavin2c2b50a2006-10-04 07:29:50 +0000789#endif
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000790
Linus Nielsen Feltzinga6fb3932006-03-18 23:42:34 +0000791#if defined(CPU_COLDFIRE) && defined(HAVE_SPDIF_OUT)
Jens Arnold314f3b52006-12-12 22:22:21 +0000792static bool dbg_spdif(void)
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000793{
794 char buf[128];
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000795 int line;
796 unsigned int control;
797 int x;
798 char *s;
799 int category;
800 int generation;
801 unsigned int interruptstat;
802 bool valnogood, symbolerr, parityerr;
Jens Arnold073f1972006-05-12 01:10:18 +0000803 bool done = false;
Michael Sevakiscc50c142006-11-13 23:21:54 +0000804 bool spdif_src_on;
805 int spdif_source = spdif_get_output_source(&spdif_src_on);
806 spdif_set_output_source(AUDIO_SRC_SPDIF, true);
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000807
808 lcd_setmargins(0, 0);
809 lcd_clear_display();
810 lcd_setfont(FONT_SYSFIXED);
Michael Sevakiscc50c142006-11-13 23:21:54 +0000811
Jens Arnold073f1972006-05-12 01:10:18 +0000812#ifdef HAVE_SPDIF_POWER
813 spdif_power_enable(true); /* We need SPDIF power for both sending & receiving */
814#endif
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000815
Jens Arnold073f1972006-05-12 01:10:18 +0000816 while (!done)
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000817 {
818 line = 0;
819
820 control = EBU1RCVCCHANNEL1;
821 interruptstat = INTERRUPTSTAT;
822 INTERRUPTCLEAR = 0x03c00000;
823
824 valnogood = (interruptstat & 0x01000000)?true:false;
825 symbolerr = (interruptstat & 0x00800000)?true:false;
826 parityerr = (interruptstat & 0x00400000)?true:false;
Jens Arnoldcfb073c2005-10-03 09:24:36 +0000827
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000828 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
829 valnogood?"--":"OK",
830 symbolerr?"--":"OK",
831 parityerr?"--":"OK");
832 lcd_puts(0, line++, buf);
833
834 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
835 lcd_puts(0, line++, buf);
836
837 line++;
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000838
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000839 x = control >> 31;
840 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
841 x, x?"Professional":"Consumer");
842 lcd_puts(0, line++, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000843
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000844 x = (control >> 30) & 1;
845 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
846 x, x?"Non-PCM":"PCM");
847 lcd_puts(0, line++, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000848
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000849 x = (control >> 29) & 1;
850 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
851 x, x?"Permitted":"Inhibited");
852 lcd_puts(0, line++, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000853
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000854 x = (control >> 27) & 7;
855 switch(x)
856 {
857 case 0:
858 s = "None";
859 break;
860 case 1:
861 s = "50/15us";
862 break;
863 default:
864 s = "Reserved";
865 break;
866 }
867 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
868 lcd_puts(0, line++, buf);
869
870 x = (control >> 24) & 3;
871 snprintf(buf, sizeof(buf), "Mode: %d", x);
872 lcd_puts(0, line++, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000873
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000874 category = (control >> 17) & 127;
875 switch(category)
876 {
877 case 0x00:
878 s = "General";
879 break;
880 case 0x40:
881 s = "Audio CD";
882 break;
883 default:
884 s = "Unknown";
885 }
886 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
887 lcd_puts(0, line++, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000888
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000889 x = (control >> 16) & 1;
890 generation = x;
891 if(((category & 0x70) == 0x10) ||
892 ((category & 0x70) == 0x40) ||
893 ((category & 0x78) == 0x38))
894 {
895 generation = !generation;
896 }
897 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
898 x, generation?"Original":"No ind.");
899 lcd_puts(0, line++, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000900
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000901 x = (control >> 12) & 15;
902 snprintf(buf, sizeof(buf), "Source: %d", x);
903 lcd_puts(0, line++, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000904
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000905 x = (control >> 8) & 15;
906 switch(x)
907 {
908 case 0:
909 s = "Unspecified";
910 break;
911 case 8:
912 s = "A (Left)";
913 break;
914 case 4:
915 s = "B (Right)";
916 break;
917 default:
918 s = "";
919 break;
920 }
921 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
922 lcd_puts(0, line++, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000923
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000924 x = (control >> 4) & 15;
925 switch(x)
926 {
927 case 0:
928 s = "44.1kHz";
929 break;
930 case 0x4:
931 s = "48kHz";
932 break;
933 case 0xc:
934 s = "32kHz";
935 break;
936 }
937 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
938 lcd_puts(0, line++, buf);
Jens Arnold073f1972006-05-12 01:10:18 +0000939
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000940 x = (control >> 2) & 3;
941 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
942 lcd_puts(0, line++, buf);
Jens Arnold073f1972006-05-12 01:10:18 +0000943 line++;
Daniel Ankers0aec12f2006-08-21 17:35:35 +0000944
Steve Bavin2c2b50a2006-10-04 07:29:50 +0000945#ifndef SIMULATOR
Jens Arnold073f1972006-05-12 01:10:18 +0000946 snprintf(buf, sizeof(buf), "Measured freq: %ldHz",
Michael Sevakiscc50c142006-11-13 23:21:54 +0000947 spdif_measure_frequency());
Jens Arnold073f1972006-05-12 01:10:18 +0000948 lcd_puts(0, line++, buf);
Steve Bavin2c2b50a2006-10-04 07:29:50 +0000949#endif
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000950
Jens Arnold073f1972006-05-12 01:10:18 +0000951 lcd_update();
952
Jonathan Gordon475be662006-08-16 04:27:33 +0000953 if (action_userabort(HZ/10))
Michael Sevakiscc50c142006-11-13 23:21:54 +0000954 break;
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000955 }
Michael Sevakiscc50c142006-11-13 23:21:54 +0000956
957 spdif_set_output_source(spdif_source, spdif_src_on);
958
Jens Arnold073f1972006-05-12 01:10:18 +0000959#ifdef HAVE_SPDIF_POWER
960 spdif_power_enable(global_settings.spdif_enable);
961#endif
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000962
963 return false;
964}
Jens Arnold5fd58dc2005-10-10 19:43:07 +0000965#endif /* CPU_COLDFIRE */
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000966
Steve Bavin5db6bb12006-10-04 07:42:45 +0000967#ifndef SIMULATOR
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000968#ifdef HAVE_LCD_BITMAP
Jonathan Gordonacf73af2006-12-27 07:20:42 +0000969 /* button definitions */
970#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
971 (CONFIG_KEYPAD == IRIVER_H300_PAD)
972# define DEBUG_CANCEL BUTTON_OFF
973
974#elif CONFIG_KEYPAD == RECORDER_PAD
975# define DEBUG_CANCEL BUTTON_OFF
976
977#elif CONFIG_KEYPAD == ONDIO_PAD
978# define DEBUG_CANCEL BUTTON_MENU
979
Jonathan Gordonacf73af2006-12-27 07:20:42 +0000980#elif (CONFIG_KEYPAD == IPOD_3G_PAD) || \
981 (CONFIG_KEYPAD == IPOD_4G_PAD)
982# define DEBUG_CANCEL BUTTON_MENU
983
984#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
985# define DEBUG_CANCEL BUTTON_PLAY
986
987#elif CONFIG_KEYPAD == IAUDIO_X5_PAD
988# define DEBUG_CANCEL BUTTON_REC
989
990#elif CONFIG_KEYPAD == GIGABEAT_PAD
991# define DEBUG_CANCEL BUTTON_A
992
993#elif CONFIG_KEYPAD == IRIVER_H10_PAD
994# define DEBUG_CANCEL BUTTON_REW
995
996#elif CONFIG_KEYPAD == SANSA_E200_PAD
997# define DEBUG_CANCEL BUTTON_LEFT
998#endif /* key definitios */
999
Björn Stenberg803f47b2002-07-15 11:23:24 +00001000/* Test code!!! */
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001001bool dbg_ports(void)
Björn Stenberg803f47b2002-07-15 11:23:24 +00001002{
Daniel Stenberg1d395ae2005-02-02 21:57:40 +00001003#if CONFIG_CPU == SH7034
Björn Stenberg803f47b2002-07-15 11:23:24 +00001004 unsigned short porta;
1005 unsigned short portb;
1006 unsigned char portc;
1007 char buf[32];
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +00001008 int adc_battery_voltage, adc_battery_level;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001009
Linus Nielsen Feltzingf22eeee2005-08-14 08:43:05 +00001010 lcd_setfont(FONT_SYSFIXED);
Markus Brauna0300f52002-08-20 22:13:20 +00001011 lcd_setmargins(0, 0);
Björn Stenberg803f47b2002-07-15 11:23:24 +00001012 lcd_clear_display();
1013
1014 while(1)
1015 {
1016 porta = PADR;
1017 portb = PBDR;
1018 portc = PCDR;
1019
1020 snprintf(buf, 32, "PADR: %04x", porta);
1021 lcd_puts(0, 0, buf);
1022 snprintf(buf, 32, "PBDR: %04x", portb);
1023 lcd_puts(0, 1, buf);
1024
1025 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
1026 lcd_puts(0, 2, buf);
1027 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
1028 lcd_puts(0, 3, buf);
1029 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
1030 lcd_puts(0, 4, buf);
1031 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
1032 lcd_puts(0, 5, buf);
1033
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +00001034 battery_read_info(NULL, &adc_battery_voltage,
1035 &adc_battery_level);
1036 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100,
1037 adc_battery_voltage % 100, adc_battery_level);
Björn Stenberg803f47b2002-07-15 11:23:24 +00001038 lcd_puts(0, 6, buf);
Jörg Hohensohn099ef222004-10-22 20:44:26 +00001039#ifndef HAVE_MMC /* have ATA */
Björn Stenberg803f47b2002-07-15 11:23:24 +00001040 snprintf(buf, 32, "ATA: %s, 0x%x",
1041 ata_device?"slave":"master", ata_io_address);
1042 lcd_puts(0, 7, buf);
Jörg Hohensohn099ef222004-10-22 20:44:26 +00001043#endif
Björn Stenberg803f47b2002-07-15 11:23:24 +00001044 lcd_update();
Jonathan Gordonacf73af2006-12-27 07:20:42 +00001045 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001046 return false;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001047 }
Christian Gmeinerc6ff1f52005-07-18 12:40:29 +00001048#elif defined(CPU_COLDFIRE)
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001049 unsigned int gpio_out;
1050 unsigned int gpio1_out;
1051 unsigned int gpio_read;
1052 unsigned int gpio1_read;
1053 unsigned int gpio_function;
1054 unsigned int gpio1_function;
1055 unsigned int gpio_enable;
1056 unsigned int gpio1_enable;
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +00001057 int adc_buttons, adc_remote;
1058 int adc_battery, adc_battery_voltage, adc_battery_level;
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +00001059 char buf[128];
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001060 int line;
1061
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001062 lcd_setmargins(0, 0);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001063 lcd_clear_display();
1064 lcd_setfont(FONT_SYSFIXED);
1065
1066 while(1)
1067 {
1068 line = 0;
1069 gpio_read = GPIO_READ;
1070 gpio1_read = GPIO1_READ;
1071 gpio_out = GPIO_OUT;
1072 gpio1_out = GPIO1_OUT;
1073 gpio_function = GPIO_FUNCTION;
1074 gpio1_function = GPIO1_FUNCTION;
1075 gpio_enable = GPIO_ENABLE;
1076 gpio1_enable = GPIO1_ENABLE;
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001077
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +00001078 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001079 lcd_puts(0, line++, buf);
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +00001080 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001081 lcd_puts(0, line++, buf);
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +00001082 snprintf(buf, sizeof(buf), "GPIO_FUNCTION: %08x", gpio_function);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001083 lcd_puts(0, line++, buf);
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +00001084 snprintf(buf, sizeof(buf), "GPIO_ENABLE: %08x", gpio_enable);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001085 lcd_puts(0, line++, buf);
1086
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +00001087 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001088 lcd_puts(0, line++, buf);
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +00001089 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001090 lcd_puts(0, line++, buf);
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +00001091 snprintf(buf, sizeof(buf), "GPIO1_FUNCTION: %08x", gpio1_function);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001092 lcd_puts(0, line++, buf);
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +00001093 snprintf(buf, sizeof(buf), "GPIO1_ENABLE: %08x", gpio1_enable);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001094 lcd_puts(0, line++, buf);
1095
1096 adc_buttons = adc_read(ADC_BUTTONS);
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +00001097 adc_remote = adc_read(ADC_REMOTE);
1098 battery_read_info(&adc_battery, &adc_battery_voltage,
1099 &adc_battery_level);
Jens Arnold8d0cd9f2007-03-05 01:31:26 +00001100#if defined(IAUDIO_X5) || defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
Michael Sevakis1d4a9c62006-10-27 05:31:28 +00001101 snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
Michael Sevakisc4a0d452006-10-28 23:10:45 +00001102 button_scan_enabled() ? '+' : '-', adc_buttons);
Jens Arnold85c9a052006-10-29 13:48:57 +00001103#else
1104 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
1105#endif
Michael Sevakis1d4a9c62006-10-27 05:31:28 +00001106 lcd_puts(0, line++, buf);
Jens Arnold88760182007-03-05 00:04:00 +00001107#if defined(IAUDIO_X5) || defined(IAUDIO_M5)
Michael Sevakis1d4a9c62006-10-27 05:31:28 +00001108 snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
1109 remote_detect() ? '+' : '-', adc_remote);
1110#else
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +00001111 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
Michael Sevakis1d4a9c62006-10-27 05:31:28 +00001112#endif
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +00001113
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001114 lcd_puts(0, line++, buf);
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +00001115 snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_battery);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001116 lcd_puts(0, line++, buf);
Jens Arnold62aaf1d2006-04-20 21:05:04 +00001117#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +00001118 snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x",
1119 adc_read(ADC_REMOTEDETECT));
Linus Nielsen Feltzing00811842006-02-17 22:38:38 +00001120 lcd_puts(0, line++, buf);
Linus Nielsen Feltzing9ffaa172006-03-18 23:07:34 +00001121#endif
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001122
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +00001123 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100,
1124 adc_battery_voltage % 100, adc_battery_level);
Linus Nielsen Feltzing43bf39e2005-04-06 23:53:19 +00001125 lcd_puts(0, line++, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001126
Jens Arnold62aaf1d2006-04-20 21:05:04 +00001127#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
Linus Nielsen Feltzing00811842006-02-17 22:38:38 +00001128 snprintf(buf, sizeof(buf), "remotetype:: %d", remote_type());
1129 lcd_puts(0, line++, buf);
Linus Nielsen Feltzing9ffaa172006-03-18 23:07:34 +00001130#endif
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001131
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001132 lcd_update();
Jonathan Gordonacf73af2006-12-27 07:20:42 +00001133 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001134 return false;
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001135 }
1136
Daniel Ankers844d22f2006-11-25 15:57:07 +00001137#elif CONFIG_CPU == PP5020 || CONFIG_CPU == PP5024
Dave Chapman8cd8a952006-01-31 01:50:10 +00001138
1139 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
Brandon Lowd00d5882006-03-18 09:13:55 +00001140 unsigned int gpio_e, gpio_f, gpio_g, gpio_h;
1141 unsigned int gpio_i, gpio_j, gpio_k, gpio_l;
Dave Chapman8cd8a952006-01-31 01:50:10 +00001142
1143 char buf[128];
Dave Chapman8cd8a952006-01-31 01:50:10 +00001144 int line;
1145
1146 lcd_setmargins(0, 0);
1147 lcd_clear_display();
1148 lcd_setfont(FONT_SYSFIXED);
1149
1150 while(1)
1151 {
1152 gpio_a = GPIOA_INPUT_VAL;
1153 gpio_b = GPIOB_INPUT_VAL;
1154 gpio_c = GPIOC_INPUT_VAL;
Dave Chapman8cd8a952006-01-31 01:50:10 +00001155
Brandon Lowd00d5882006-03-18 09:13:55 +00001156 gpio_g = GPIOG_INPUT_VAL;
1157 gpio_h = GPIOH_INPUT_VAL;
Jens Arnold1d085332006-05-07 22:56:44 +00001158 gpio_i = GPIOI_INPUT_VAL;
Brandon Lowd00d5882006-03-18 09:13:55 +00001159
Jens Arnold1d085332006-05-07 22:56:44 +00001160 line = 0;
Barry Wardelld9fe5a72006-09-29 12:20:04 +00001161 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_G: %02x", gpio_a, gpio_g);
Brandon Lowd00d5882006-03-18 09:13:55 +00001162 lcd_puts(0, line++, buf);
Barry Wardelld9fe5a72006-09-29 12:20:04 +00001163 snprintf(buf, sizeof(buf), "GPIO_B: %02x GPIO_H: %02x", gpio_b, gpio_h);
Brandon Lowd00d5882006-03-18 09:13:55 +00001164 lcd_puts(0, line++, buf);
Barry Wardelld9fe5a72006-09-29 12:20:04 +00001165 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_I: %02x", gpio_c, gpio_i);
Brandon Lowd00d5882006-03-18 09:13:55 +00001166 lcd_puts(0, line++, buf);
1167 line++;
1168
Jens Arnold1d085332006-05-07 22:56:44 +00001169 gpio_d = GPIOD_INPUT_VAL;
1170 gpio_e = GPIOE_INPUT_VAL;
1171 gpio_f = GPIOF_INPUT_VAL;
1172
Brandon Lowd00d5882006-03-18 09:13:55 +00001173 gpio_j = GPIOJ_INPUT_VAL;
1174 gpio_k = GPIOK_INPUT_VAL;
1175 gpio_l = GPIOL_INPUT_VAL;
1176
Barry Wardelld9fe5a72006-09-29 12:20:04 +00001177 snprintf(buf, sizeof(buf), "GPIO_D: %02x GPIO_J: %02x", gpio_d, gpio_j);
Brandon Lowd00d5882006-03-18 09:13:55 +00001178 lcd_puts(0, line++, buf);
Barry Wardelld9fe5a72006-09-29 12:20:04 +00001179 snprintf(buf, sizeof(buf), "GPIO_E: %02x GPIO_K: %02x", gpio_e, gpio_k);
Brandon Lowd00d5882006-03-18 09:13:55 +00001180 lcd_puts(0, line++, buf);
Barry Wardelld9fe5a72006-09-29 12:20:04 +00001181 snprintf(buf, sizeof(buf), "GPIO_F: %02x GPIO_L: %02x", gpio_f, gpio_l);
Brandon Lowd00d5882006-03-18 09:13:55 +00001182 lcd_puts(0, line++, buf);
Barry Wardell5a79b4e2006-09-23 17:47:54 +00001183#if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
1184 line++;
Barry Wardellb692fb12006-09-29 15:59:08 +00001185 snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_read(ADC_BATTERY));
Barry Wardell5a79b4e2006-09-23 17:47:54 +00001186 lcd_puts(0, line++, buf);
Barry Wardellb692fb12006-09-29 15:59:08 +00001187 snprintf(buf, sizeof(buf), "ADC_UNKNOWN_1: %02x", adc_read(ADC_UNKNOWN_1));
Barry Wardell5a79b4e2006-09-23 17:47:54 +00001188 lcd_puts(0, line++, buf);
Barry Wardellb692fb12006-09-29 15:59:08 +00001189 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_read(ADC_REMOTE));
Barry Wardell5a79b4e2006-09-23 17:47:54 +00001190 lcd_puts(0, line++, buf);
1191 snprintf(buf, sizeof(buf), "ADC_SCROLLPAD: %02x", adc_read(ADC_SCROLLPAD));
1192 lcd_puts(0, line++, buf);
Barry Wardell7f4f9ae2007-03-13 01:50:13 +00001193#elif defined(SANSA_E200)
1194 line++;
1195 snprintf(buf, sizeof(buf), "ADC_BVDD: %02x", adc_read(ADC_BVDD));
1196 lcd_puts(0, line++, buf);
1197 snprintf(buf, sizeof(buf), "ADC_RTCSUP: %02x", adc_read(ADC_RTCSUP));
1198 lcd_puts(0, line++, buf);
1199 snprintf(buf, sizeof(buf), "ADC_UVDD: %02x", adc_read(ADC_UVDD));
1200 lcd_puts(0, line++, buf);
1201 snprintf(buf, sizeof(buf), "ADC_CHG_IN: %02x", adc_read(ADC_CHG_IN));
1202 lcd_puts(0, line++, buf);
1203 snprintf(buf, sizeof(buf), "ADC_CVDD: %02x", adc_read(ADC_CVDD));
1204 lcd_puts(0, line++, buf);
1205 snprintf(buf, sizeof(buf), "ADC_BATTEMP: %02x", adc_read(ADC_BATTEMP));
1206 lcd_puts(0, line++, buf);
1207 snprintf(buf, sizeof(buf), "ADC_MICSUP1: %02x", adc_read(ADC_MICSUP1));
1208 lcd_puts(0, line++, buf);
1209 snprintf(buf, sizeof(buf), "ADC_MICSUP2: %02x", adc_read(ADC_MICSUP2));
1210 lcd_puts(0, line++, buf);
1211 snprintf(buf, sizeof(buf), "ADC_VBE1: %02x", adc_read(ADC_VBE1));
1212 lcd_puts(0, line++, buf);
1213 snprintf(buf, sizeof(buf), "ADC_VBE2: %02x", adc_read(ADC_VBE2));
1214 lcd_puts(0, line++, buf);
1215 snprintf(buf, sizeof(buf), "ADC_I_MICSUP1: %02x", adc_read(ADC_I_MICSUP1));
1216 lcd_puts(0, line++, buf);
1217 snprintf(buf, sizeof(buf), "ADC_I_MICSUP2: %02x", adc_read(ADC_I_MICSUP2));
1218 lcd_puts(0, line++, buf);
1219 snprintf(buf, sizeof(buf), "ADC_VBAT: %02x", adc_read(ADC_VBAT));
1220 lcd_puts(0, line++, buf);
Barry Wardell5a79b4e2006-09-23 17:47:54 +00001221#endif
Dave Chapman8cd8a952006-01-31 01:50:10 +00001222 lcd_update();
Jonathan Gordonacf73af2006-12-27 07:20:42 +00001223 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001224 return false;
Dave Chapman8cd8a952006-01-31 01:50:10 +00001225 }
1226
Daniel Ankers6dfd6bd2006-10-25 18:34:59 +00001227#elif CONFIG_CPU == PP5002
1228 unsigned int gpio_a, gpio_b, gpio_c, gpio_d;
1229
1230 char buf[128];
1231 int line;
1232
1233 lcd_setmargins(0, 0);
1234 lcd_clear_display();
1235 lcd_setfont(FONT_SYSFIXED);
1236
1237 while(1)
1238 {
1239 gpio_a = GPIOA_INPUT_VAL;
1240 gpio_b = GPIOB_INPUT_VAL;
1241 gpio_c = GPIOC_INPUT_VAL;
1242 gpio_d = GPIOD_INPUT_VAL;
1243
1244 line = 0;
1245 snprintf(buf, sizeof(buf), "GPIO_A: %02x GPIO_B: %02x", gpio_a, gpio_b);
1246 lcd_puts(0, line++, buf);
1247 snprintf(buf, sizeof(buf), "GPIO_C: %02x GPIO_D: %02x", gpio_c, gpio_d);
1248 lcd_puts(0, line++, buf);
1249
1250 lcd_update();
Jonathan Gordonacf73af2006-12-27 07:20:42 +00001251 if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
Daniel Ankers6dfd6bd2006-10-25 18:34:59 +00001252 return false;
1253 }
Jens Arnold5fd58dc2005-10-10 19:43:07 +00001254#endif /* CPU */
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001255 return false;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001256}
Jens Arnold5fd58dc2005-10-10 19:43:07 +00001257#else /* !HAVE_LCD_BITMAP */
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001258bool dbg_ports(void)
Björn Stenberg803f47b2002-07-15 11:23:24 +00001259{
1260 unsigned short porta;
1261 unsigned short portb;
1262 unsigned char portc;
1263 char buf[32];
Björn Stenberg803f47b2002-07-15 11:23:24 +00001264 int button;
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +00001265 int adc_battery_voltage;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001266 int currval = 0;
1267
1268 lcd_clear_display();
1269
1270 while(1)
1271 {
1272 porta = PADR;
1273 portb = PBDR;
1274 portc = PCDR;
1275
1276 switch(currval)
1277 {
Robert Hak50fc3ce2002-08-10 08:52:11 +00001278 case 0:
1279 snprintf(buf, 32, "PADR: %04x ", porta);
1280 break;
1281 case 1:
1282 snprintf(buf, 32, "PBDR: %04x ", portb);
1283 break;
1284 case 2:
1285 snprintf(buf, 32, "AN0: %03x ", adc_read(0));
1286 break;
1287 case 3:
1288 snprintf(buf, 32, "AN1: %03x ", adc_read(1));
1289 break;
1290 case 4:
1291 snprintf(buf, 32, "AN2: %03x ", adc_read(2));
1292 break;
1293 case 5:
1294 snprintf(buf, 32, "AN3: %03x ", adc_read(3));
1295 break;
1296 case 6:
1297 snprintf(buf, 32, "AN4: %03x ", adc_read(4));
1298 break;
1299 case 7:
1300 snprintf(buf, 32, "AN5: %03x ", adc_read(5));
1301 break;
1302 case 8:
1303 snprintf(buf, 32, "AN6: %03x ", adc_read(6));
1304 break;
1305 case 9:
1306 snprintf(buf, 32, "AN7: %03x ", adc_read(7));
1307 break;
1308 case 10:
1309 snprintf(buf, 32, "%s, 0x%x ",
1310 ata_device?"slv":"mst", ata_io_address);
1311 break;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001312 }
1313 lcd_puts(0, 0, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001314
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +00001315 battery_read_info(NULL, &adc_battery_voltage, NULL);
1316 snprintf(buf, 32, "Batt: %d.%02dV", adc_battery_voltage / 100,
1317 adc_battery_voltage % 100);
Björn Stenberg803f47b2002-07-15 11:23:24 +00001318 lcd_puts(0, 1, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001319
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001320 button = get_action(CONTEXT_SETTINGS,HZ/5);
Björn Stenberg803f47b2002-07-15 11:23:24 +00001321
1322 switch(button)
1323 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001324 case ACTION_STD_CANCEL:
1325 action_signalscreenchange();
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001326 return false;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001327
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001328 case ACTION_SETTINGS_DEC:
Robert Hak50fc3ce2002-08-10 08:52:11 +00001329 currval--;
1330 if(currval < 0)
Linus Nielsen Feltzing41977da2002-08-14 08:04:42 +00001331 currval = 10;
Robert Hak50fc3ce2002-08-10 08:52:11 +00001332 break;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001333
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001334 case ACTION_SETTINGS_INC:
Robert Hak50fc3ce2002-08-10 08:52:11 +00001335 currval++;
Linus Nielsen Feltzing41977da2002-08-14 08:04:42 +00001336 if(currval > 10)
Robert Hak50fc3ce2002-08-10 08:52:11 +00001337 currval = 0;
1338 break;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001339 }
1340 }
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001341 return false;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001342}
Jens Arnold5fd58dc2005-10-10 19:43:07 +00001343#endif /* !HAVE_LCD_BITMAP */
Steve Bavin5db6bb12006-10-04 07:42:45 +00001344#endif /* !SIMULATOR */
Björn Stenberg803f47b2002-07-15 11:23:24 +00001345
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +00001346#ifdef HAVE_ADJUSTABLE_CPU_FREQ
Jens Arnold314f3b52006-12-12 22:22:21 +00001347static bool dbg_cpufreq(void)
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +00001348{
1349 char buf[128];
1350 int line;
1351 int button;
1352
1353#ifdef HAVE_LCD_BITMAP
1354 lcd_setmargins(0, 0);
Linus Nielsen Feltzing57d8e8f2005-08-18 07:16:53 +00001355 lcd_setfont(FONT_SYSFIXED);
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +00001356#endif
1357 lcd_clear_display();
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +00001358
1359 while(1)
1360 {
1361 line = 0;
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001362
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +00001363 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1364 lcd_puts(0, line++, buf);
1365
Steve Bavind49c8102006-10-05 10:07:03 +00001366 snprintf(buf, sizeof(buf), "boost_counter: %d", get_cpu_boost_counter());
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +00001367 lcd_puts(0, line++, buf);
1368
1369 lcd_update();
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001370 button = get_action(CONTEXT_STD,HZ/10);
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +00001371
1372 switch(button)
1373 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001374 case ACTION_STD_PREV:
Miika Pekkarinenc5d57f02006-12-05 20:01:48 +00001375 cpu_boost(true);
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001376 break;
Steve Bavind49c8102006-10-05 10:07:03 +00001377
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001378 case ACTION_STD_NEXT:
Miika Pekkarinenc5d57f02006-12-05 20:01:48 +00001379 cpu_boost(false);
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001380 break;
Linus Nielsen Feltzingc71db252005-03-07 13:02:06 +00001381
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001382 case ACTION_STD_OK:
Steve Bavind49c8102006-10-05 10:07:03 +00001383 while (get_cpu_boost_counter() > 0)
Miika Pekkarinenc5d57f02006-12-05 20:01:48 +00001384 cpu_boost(false);
Steve Bavin3ad89d22006-11-01 11:12:21 +00001385 set_cpu_frequency(CPUFREQ_DEFAULT);
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001386 break;
Thom Johansenf6e85672006-03-17 02:02:13 +00001387
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001388 case ACTION_STD_CANCEL:
1389 action_signalscreenchange();
1390 return false;
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +00001391 }
1392 }
1393
1394 return false;
1395}
Jens Arnold5fd58dc2005-10-10 19:43:07 +00001396#endif /* HAVE_ADJUSTABLE_CPU_FREQ */
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001397
Steve Bavin2c2b50a2006-10-04 07:29:50 +00001398#ifndef SIMULATOR
Björn Stenbergb47e64e2002-08-08 20:44:25 +00001399#ifdef HAVE_LCD_BITMAP
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001400/*
1401 * view_battery() shows a automatically scaled graph of the battery voltage
1402 * over time. Usable for estimating battery life / charging rate.
1403 * The power_history array is updated in power_thread of powermgmt.c.
1404 */
1405
Jörg Hohensohn25848962005-03-03 07:25:43 +00001406#define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001407#define BAT_YSPACE (LCD_HEIGHT - 20)
1408
Jens Arnold314f3b52006-12-12 22:22:21 +00001409static bool view_battery(void)
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001410{
1411 int view = 0;
1412 int i, x, y;
Jean-Philippe Bernardyed7c6352005-02-08 15:12:25 +00001413 unsigned short maxv, minv;
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001414 char buf[32];
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001415
Markus Brauna0300f52002-08-20 22:13:20 +00001416 lcd_setmargins(0, 0);
Linus Nielsen Feltzingf22eeee2005-08-14 08:43:05 +00001417 lcd_setfont(FONT_SYSFIXED);
Jens Arnold5fd58dc2005-10-10 19:43:07 +00001418
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001419 while(1)
1420 {
1421 switch (view) {
Björn Stenbergfe97b572002-08-10 08:57:47 +00001422 case 0: /* voltage history graph */
1423 /* Find maximum and minimum voltage for scaling */
Jörg Hohensohn25848962005-03-03 07:25:43 +00001424 maxv = 0;
1425 minv = 65535;
1426 for (i = 0; i < BAT_LAST_VAL; i++) {
Björn Stenbergfe97b572002-08-10 08:57:47 +00001427 if (power_history[i] > maxv)
1428 maxv = power_history[i];
Jörg Hohensohn25848962005-03-03 07:25:43 +00001429 if (power_history[i] && (power_history[i] < minv))
Björn Stenbergfe97b572002-08-10 08:57:47 +00001430 {
1431 minv = power_history[i];
1432 }
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001433 }
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001434
Jörg Hohensohn25848962005-03-03 07:25:43 +00001435 if ((minv < 1) || (minv >= 65535))
Björn Stenbergfe97b572002-08-10 08:57:47 +00001436 minv = 1;
1437 if (maxv < 2)
1438 maxv = 2;
Peter D'Hoye1f760b82006-09-16 19:35:28 +00001439 if (minv == maxv)
1440 maxv < 65535 ? maxv++ : minv--;
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001441
Björn Stenbergfe97b572002-08-10 08:57:47 +00001442 lcd_clear_display();
Jörg Hohensohn25848962005-03-03 07:25:43 +00001443 snprintf(buf, 30, "Battery %d.%02d", power_history[0] / 100,
1444 power_history[0] % 100);
1445 lcd_puts(0, 0, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001446 snprintf(buf, 30, "scale %d.%02d-%d.%02d V",
Björn Stenbergfe97b572002-08-10 08:57:47 +00001447 minv / 100, minv % 100, maxv / 100, maxv % 100);
1448 lcd_puts(0, 1, buf);
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001449
Björn Stenbergfe97b572002-08-10 08:57:47 +00001450 x = 0;
Jörg Hohensohn25848962005-03-03 07:25:43 +00001451 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
Björn Stenbergfe97b572002-08-10 08:57:47 +00001452 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
Jens Arnold04daef12005-06-24 22:33:21 +00001453 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
Jens Arnold93494122005-06-25 00:28:09 +00001454 lcd_vline(x, LCD_HEIGHT-1, 20);
Jens Arnold04daef12005-06-24 22:33:21 +00001455 lcd_set_drawmode(DRMODE_SOLID);
Jens Arnold93494122005-06-25 00:28:09 +00001456 lcd_vline(x, LCD_HEIGHT-1,
1457 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
Björn Stenbergfe97b572002-08-10 08:57:47 +00001458 x++;
1459 }
1460
1461 break;
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001462
Björn Stenbergfe97b572002-08-10 08:57:47 +00001463 case 1: /* status: */
1464 lcd_clear_display();
1465 lcd_puts(0, 0, "Power status:");
Jens Arnoldf2314de2005-11-03 21:21:37 +00001466
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +00001467 battery_read_info(NULL, &y, NULL);
Björn Stenbergfe97b572002-08-10 08:57:47 +00001468 snprintf(buf, 30, "Battery: %d.%02d V", y / 100, y % 100);
1469 lcd_puts(0, 1, buf);
Jens Arnold303b4ab2004-12-01 00:33:18 +00001470#ifdef ADC_EXT_POWER
Björn Stenbergfe97b572002-08-10 08:57:47 +00001471 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000;
1472 snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100);
1473 lcd_puts(0, 2, buf);
Jens Arnold303b4ab2004-12-01 00:33:18 +00001474#endif
Jonathan Gordon9a6f4192007-02-18 05:32:06 +00001475#if CONFIG_CHARGING
Jens Arnold0dd1f8e2006-06-06 22:23:52 +00001476#if CONFIG_CHARGING == CHARGING_CONTROL
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001477 snprintf(buf, 30, "Chgr: %s %s",
Michiel Van Der Kolk9d2531a2005-03-28 00:47:09 +00001478 charger_inserted() ? "present" : "absent",
1479 charger_enabled ? "on" : "off");
1480 lcd_puts(0, 3, buf);
Jörg Hohensohn25848962005-03-03 07:25:43 +00001481 snprintf(buf, 30, "short delta: %d", short_delta);
Björn Stenbergfe97b572002-08-10 08:57:47 +00001482 lcd_puts(0, 5, buf);
Jörg Hohensohn25848962005-03-03 07:25:43 +00001483 snprintf(buf, 30, "long delta: %d", long_delta);
Björn Stenbergfe97b572002-08-10 08:57:47 +00001484 lcd_puts(0, 6, buf);
Björn Stenbergfe97b572002-08-10 08:57:47 +00001485 lcd_puts(0, 7, power_message);
Steve Bavin338d94f2007-02-01 10:47:22 +00001486 snprintf(buf, 30, "USB Inserted: %s",
1487 usb_inserted() ? "yes" : "no");
1488 lcd_puts(0, 8, buf);
1489#if defined IRIVER_H300_SERIES
1490 snprintf(buf, 30, "USB Charging Enabled: %s",
1491 usb_charging_enabled() ? "yes" : "no");
1492 lcd_puts(0, 9, buf);
1493#endif
Jens Arnold0dd1f8e2006-06-06 22:23:52 +00001494#else /* CONFIG_CHARGING != CHARGING_CONTROL */
1495#if defined IPOD_NANO || defined IPOD_VIDEO
Brandon Lowd00d5882006-03-18 09:13:55 +00001496 int usb_pwr = (GPIOL_INPUT_VAL & 0x10)?true:false;
1497 int ext_pwr = (GPIOL_INPUT_VAL & 0x08)?false:true;
1498 int dock = (GPIOA_INPUT_VAL & 0x10)?true:false;
1499 int charging = (GPIOB_INPUT_VAL & 0x01)?false:true;
1500 int headphone= (GPIOA_INPUT_VAL & 0x80)?true:false;
1501
1502 snprintf(buf, 30, "USB pwr: %s",
1503 usb_pwr ? "present" : "absent");
1504 lcd_puts(0, 3, buf);
1505 snprintf(buf, 30, "EXT pwr: %s",
1506 ext_pwr ? "present" : "absent");
1507 lcd_puts(0, 4, buf);
1508 snprintf(buf, 30, "Battery: %s",
Michael Sevakis1d4a9c62006-10-27 05:31:28 +00001509 charging ? "charging" : (usb_pwr||ext_pwr) ? "charged" : "discharging");
Brandon Lowd00d5882006-03-18 09:13:55 +00001510 lcd_puts(0, 5, buf);
1511 snprintf(buf, 30, "Dock mode: %s",
1512 dock ? "enabled" : "disabled");
1513 lcd_puts(0, 6, buf);
1514 snprintf(buf, 30, "Headphone: %s",
1515 headphone ? "connected" : "disconnected");
1516 lcd_puts(0, 7, buf);
Brandon Lowb7c7df72006-03-18 09:34:58 +00001517#else
Brandon Lowd00d5882006-03-18 09:13:55 +00001518 snprintf(buf, 30, "Charger: %s",
1519 charger_inserted() ? "present" : "absent");
1520 lcd_puts(0, 3, buf);
1521#endif
Jens Arnold0dd1f8e2006-06-06 22:23:52 +00001522#endif /* CONFIG_CHARGING != CHARGING_CONTROL */
1523#endif /* CONFIG_CHARGING */
Björn Stenbergfe97b572002-08-10 08:57:47 +00001524 break;
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001525
Björn Stenbergfe97b572002-08-10 08:57:47 +00001526 case 2: /* voltage deltas: */
1527 lcd_clear_display();
1528 lcd_puts(0, 0, "Voltage deltas:");
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001529
Björn Stenbergfe97b572002-08-10 08:57:47 +00001530 for (i = 0; i <= 6; i++) {
Jörg Hohensohn25848962005-03-03 07:25:43 +00001531 y = power_history[i] - power_history[i+i];
Björn Stenbergfe97b572002-08-10 08:57:47 +00001532 snprintf(buf, 30, "-%d min: %s%d.%02d V", i,
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001533 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 100,
Björn Stenbergfe97b572002-08-10 08:57:47 +00001534 ((y < 0) ? y * -1 : y ) % 100);
1535 lcd_puts(0, i+1, buf);
1536 }
1537 break;
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001538
Michiel Van Der Kolk9d2531a2005-03-28 00:47:09 +00001539 case 3: /* remaining time estimation: */
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001540 lcd_clear_display();
Uwe Freesec83374b2002-12-15 18:10:19 +00001541
Jens Arnold0dd1f8e2006-06-06 22:23:52 +00001542#if CONFIG_CHARGING == CHARGING_CONTROL
Uwe Freesec83374b2002-12-15 18:10:19 +00001543 snprintf(buf, 30, "charge_state: %d", charge_state);
1544 lcd_puts(0, 0, buf);
1545
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001546 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1547 lcd_puts(0, 1, buf);
1548
Jörg Hohensohn25848962005-03-03 07:25:43 +00001549 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001550 lcd_puts(0, 2, buf);
Michiel Van Der Kolk9d2531a2005-03-28 00:47:09 +00001551
1552 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1553 lcd_puts(0, 3, buf);
1554
1555 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1556 lcd_puts(0, 4, buf);
Jens Arnold0dd1f8e2006-06-06 22:23:52 +00001557#endif /* CONFIG_CHARGING == CHARGING_CONTROL */
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001558
Jörg Hohensohn25848962005-03-03 07:25:43 +00001559 snprintf(buf, 30, "Last PwrHist: %d.%02d V",
1560 power_history[0] / 100,
1561 power_history[0] % 100);
Michiel Van Der Kolk451dd482005-03-28 00:00:24 +00001562 lcd_puts(0, 5, buf);
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001563
Michiel Van Der Kolk9d2531a2005-03-28 00:47:09 +00001564 snprintf(buf, 30, "battery level: %d%%", battery_level());
Michiel Van Der Kolk451dd482005-03-28 00:00:24 +00001565 lcd_puts(0, 6, buf);
1566
Michiel Van Der Kolk9d2531a2005-03-28 00:47:09 +00001567 snprintf(buf, 30, "Est. remain: %d m", battery_time());
Uwe Freese5f027972002-12-14 12:10:29 +00001568 lcd_puts(0, 7, buf);
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001569 break;
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001570 }
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001571
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001572 lcd_update();
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001573
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001574 switch(get_action(CONTEXT_SETTINGS,HZ/2))
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001575 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001576 case ACTION_SETTINGS_DEC:
Björn Stenbergfe97b572002-08-10 08:57:47 +00001577 if (view)
1578 view--;
1579 break;
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001580
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001581 case ACTION_SETTINGS_INC:
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001582 if (view < 3)
Björn Stenbergfe97b572002-08-10 08:57:47 +00001583 view++;
1584 break;
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001585
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +00001586 case ACTION_STD_CANCEL:
1587 action_signalscreenchange();
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001588 return false;
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001589 }
1590 }
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001591 return false;
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001592}
1593
Jens Arnold5fd58dc2005-10-10 19:43:07 +00001594#endif /* HAVE_LCD_BITMAP */
Steve Bavin2c2b50a2006-10-04 07:29:50 +00001595#endif
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001596
Steve Bavin2c2b50a2006-10-04 07:29:50 +00001597#ifndef SIMULATOR
Jens Arnold90cbd3b2004-09-28 06:23:57 +00001598#ifdef HAVE_MMC
Jens Arnold314f3b52006-12-12 22:22:21 +00001599static bool dbg_mmc_info(void)
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001600{
1601 bool done = false;
1602 int currval = 0;
Jens Arnold450f6192006-10-15 11:51:56 +00001603 int line;
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001604 tCardInfo *card;
Jens Arnold2116bba2005-01-31 00:39:20 +00001605 unsigned char pbuf[32], pbuf2[32];
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001606 unsigned char card_name[7];
Jens Arnold2116bba2005-01-31 00:39:20 +00001607
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001608 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1609 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
Jens Arnold2116bba2005-01-31 00:39:20 +00001610 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
Hristo Kovachev1dc62df2006-08-16 09:15:40 +00001611 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
Jens Arnold450f6192006-10-15 11:51:56 +00001612 static const char *spec_vers[] = { "1.0-1.2", "1.4", "2.0-2.2",
1613 "3.1-3.31", "4.0" };
Daniel Ankers0aec12f2006-08-21 17:35:35 +00001614
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001615 card_name[6] = '\0';
1616
1617 lcd_setmargins(0, 0);
1618 lcd_setfont(FONT_SYSFIXED);
1619
1620 while (!done)
1621 {
1622 card = mmc_card_info(currval / 2);
1623
Jens Arnold450f6192006-10-15 11:51:56 +00001624 line = 0;
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001625 lcd_clear_display();
1626 snprintf(pbuf, sizeof(pbuf), "[MMC%d p%d]", currval / 2,
1627 (currval % 2) + 1);
Jens Arnold450f6192006-10-15 11:51:56 +00001628 lcd_puts(0, line++, pbuf);
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001629
1630 if (card->initialized)
1631 {
1632 if (!(currval % 2)) /* General info */
1633 {
Jens Arnold450f6192006-10-15 11:51:56 +00001634 int temp;
1635
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001636 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1637 snprintf(pbuf, sizeof(pbuf), "%s Rev %d.%d", card_name,
Jens Arnold6baa55a2005-01-24 01:39:24 +00001638 (int) mmc_extract_bits(card->cid, 72, 4),
1639 (int) mmc_extract_bits(card->cid, 76, 4));
Jens Arnold450f6192006-10-15 11:51:56 +00001640 lcd_puts(0, line++, pbuf);
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001641 snprintf(pbuf, sizeof(pbuf), "Prod: %d/%d",
Jens Arnold6baa55a2005-01-24 01:39:24 +00001642 (int) mmc_extract_bits(card->cid, 112, 4),
1643 (int) mmc_extract_bits(card->cid, 116, 4) + 1997);
Jens Arnold450f6192006-10-15 11:51:56 +00001644 lcd_puts(0, line++, pbuf);
Jens Arnold6baa55a2005-01-24 01:39:24 +00001645 snprintf(pbuf, sizeof(pbuf), "Ser#: 0x%08lx",
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001646 mmc_extract_bits(card->cid, 80, 32));
Jens Arnold450f6192006-10-15 11:51:56 +00001647 lcd_puts(0, line++, pbuf);
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001648 snprintf(pbuf, sizeof(pbuf), "M=%02x, O=%04x",
Jens Arnold6baa55a2005-01-24 01:39:24 +00001649 (int) mmc_extract_bits(card->cid, 0, 8),
1650 (int) mmc_extract_bits(card->cid, 8, 16));
Jens Arnold450f6192006-10-15 11:51:56 +00001651 lcd_puts(0, line++, pbuf);
1652 temp = mmc_extract_bits(card->csd, 2, 4);
1653 snprintf(pbuf, sizeof(pbuf), "MMC v%s", temp < 5 ?
1654 spec_vers[temp] : "?.?");
1655 lcd_puts(0, line++, pbuf);
Jens Arnold8ca18312005-05-27 21:47:50 +00001656 snprintf(pbuf, sizeof(pbuf), "Blocks: 0x%06lx", card->numblocks);
Jens Arnold450f6192006-10-15 11:51:56 +0000