blob: b4cd05699c75115dc740149392ede887d0fdc13a [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"
21#ifndef SIMULATOR
22#include <stdio.h>
23#include <stdbool.h>
Hardeep Sidhu95132362003-08-01 16:05:40 +000024#include <string.h>
Björn Stenberg803f47b2002-07-15 11:23:24 +000025#include "lcd.h"
26#include "menu.h"
27#include "debug_menu.h"
28#include "kernel.h"
29#include "sprintf.h"
30#include "button.h"
31#include "adc.h"
32#include "mas.h"
33#include "power.h"
34#include "rtc.h"
35#include "debug.h"
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +000036#include "thread.h"
Heikki Hannikainen6eb42542002-08-06 10:52:51 +000037#include "powermgmt.h"
38#include "system.h"
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +000039#include "font.h"
Björn Stenberg4d55c2f2002-10-10 12:01:58 +000040#include "disk.h"
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +000041#include "audio.h"
Linus Nielsen Feltzingf1f7bbe2004-03-22 11:48:13 +000042#include "mp3_playback.h"
Björn Stenbergae22de22002-12-02 16:07:56 +000043#include "settings.h"
Björn Stenberg45d32ce2002-12-03 13:12:55 +000044#include "ata.h"
Björn Stenbergb17fe5a2002-12-09 15:39:32 +000045#include "fat.h"
Linus Nielsen Feltzingf3ad6192004-02-16 12:04:55 +000046#include "dir.h"
47#include "panic.h"
Linus Nielsen Feltzingb81a3c52004-03-25 12:29:34 +000048#include "screens.h"
Linus Nielsen Feltzingade5d7b2004-07-26 16:06:59 +000049#include "misc.h"
Linus Nielsen Feltzing875bf5e2002-10-15 08:08:35 +000050#ifdef HAVE_LCD_BITMAP
Linus Nielsen Feltzingbf303de2002-10-15 07:23:18 +000051#include "widgets.h"
Linus Nielsen Feltzingfd0cc3b2002-10-29 12:09:15 +000052#include "peakmeter.h"
Linus Nielsen Feltzing875bf5e2002-10-15 08:08:35 +000053#endif
Jörg Hohensohn593cc002004-09-28 22:13:26 +000054#ifdef CONFIG_TUNER
Linus Nielsen Feltzing05796672004-02-05 10:59:51 +000055#include "radio.h"
56#endif
Jens Arnold6f9a7eb2004-10-06 20:43:12 +000057#ifdef HAVE_MMC
58#include "ata_mmc.h"
59#endif
Daniel Stenbergedc07922005-05-30 13:00:43 +000060#include "logfdisp.h"
Linus Nielsen Feltzingb6242daf2005-07-11 12:09:01 +000061#if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
Andye5d08722005-06-19 03:05:53 +000062extern bool pcm_rec_screen(void);
63#endif
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +000064#if CONFIG_HWCODEC == MASNONE
Miika Pekkarinenb0e78a42005-07-13 13:13:10 +000065#include "pcmbuf.h"
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +000066#include "pcm_playback.h"
67#endif
Björn Stenberg803f47b2002-07-15 11:23:24 +000068
69/*---------------------------------------------------*/
70/* SPECIAL DEBUG STUFF */
71/*---------------------------------------------------*/
Jens Arnold4ddb3202005-05-06 21:55:34 +000072extern char ata_device;
Björn Stenberg803f47b2002-07-15 11:23:24 +000073extern int ata_io_address;
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +000074extern int num_threads;
Jens Arnold08303392004-08-03 20:52:31 +000075extern const char *thread_name[];
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +000076
Björn Stenbergb47e64e2002-08-08 20:44:25 +000077#ifdef HAVE_LCD_BITMAP
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +000078/* Test code!!! */
Björn Stenbergb1b8bd42002-09-24 17:22:12 +000079bool dbg_os(void)
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +000080{
81 char buf[32];
82 int button;
83 int i;
84 int usage;
85
Markus Brauna0300f52002-08-20 22:13:20 +000086#ifdef HAVE_LCD_BITMAP
87 lcd_setmargins(0, 0);
Linus Nielsen Feltzing57d8e8f2005-08-18 07:16:53 +000088 lcd_setfont(FONT_SYSFIXED);
Markus Brauna0300f52002-08-20 22:13:20 +000089#endif
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +000090 lcd_clear_display();
91
92 while(1)
93 {
Robert Hak50fc3ce2002-08-10 08:52:11 +000094 lcd_puts(0, 0, "Stack usage:");
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +000095 for(i = 0; i < num_threads;i++)
96 {
97 usage = thread_stack_usage(i);
Robert Hak50fc3ce2002-08-10 08:52:11 +000098 snprintf(buf, 32, "%s: %d%%", thread_name[i], usage);
99 lcd_puts(0, 1+i, buf);
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000100 }
101
102 lcd_update();
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000103
Björn Stenbergf09c5f42002-12-03 14:18:51 +0000104 button = button_get_w_tmo(HZ/10);
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000105
106 switch(button)
107 {
Björn Stenberg6c33c512004-09-19 21:58:37 +0000108 case SETTINGS_CANCEL:
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000109 return false;
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000110 }
111 }
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000112 return false;
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000113}
114#else
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000115bool dbg_os(void)
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000116{
117 char buf[32];
118 int button;
119 int usage;
120 int currval = 0;
121
122 lcd_clear_display();
123
124 while(1)
125 {
Robert Hak50fc3ce2002-08-10 08:52:11 +0000126 lcd_puts(0, 0, "Stack usage");
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000127
Robert Hak50fc3ce2002-08-10 08:52:11 +0000128 usage = thread_stack_usage(currval);
129 snprintf(buf, 32, "%d: %d%% ", currval, usage);
130 lcd_puts(0, 1, buf);
Jens Arnold06cb2372004-08-30 19:52:45 +0000131
Björn Stenbergf09c5f42002-12-03 14:18:51 +0000132 button = button_get_w_tmo(HZ/10);
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000133
134 switch(button)
135 {
Björn Stenberg6c33c512004-09-19 21:58:37 +0000136 case SETTINGS_CANCEL:
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000137 return false;
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000138
Björn Stenberg6c33c512004-09-19 21:58:37 +0000139 case SETTINGS_DEC:
Robert Hak50fc3ce2002-08-10 08:52:11 +0000140 currval--;
141 if(currval < 0)
142 currval = num_threads-1;
143 break;
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000144
Björn Stenberg6c33c512004-09-19 21:58:37 +0000145 case SETTINGS_INC:
Robert Hak50fc3ce2002-08-10 08:52:11 +0000146 currval++;
147 if(currval > num_threads-1)
148 currval = 0;
149 break;
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000150 }
151 }
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000152 return false;
Linus Nielsen Feltzing7fef58a2002-07-15 22:25:45 +0000153}
154#endif
Björn Stenberg803f47b2002-07-15 11:23:24 +0000155
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000156#ifdef HAVE_LCD_BITMAP
157#if CONFIG_HWCODEC != MASNONE
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +0000158bool dbg_audio_thread(void)
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000159{
160 char buf[32];
161 int button;
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +0000162 struct audio_debug d;
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000163
Linus Nielsen Feltzingbf303de2002-10-15 07:23:18 +0000164 lcd_setmargins(0, 0);
Linus Nielsen Feltzing44bba0f2005-06-22 21:37:00 +0000165 lcd_setfont(FONT_SYSFIXED);
Linus Nielsen Feltzingbf303de2002-10-15 07:23:18 +0000166
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000167 while(1)
168 {
169 button = button_get_w_tmo(HZ/5);
170 switch(button)
171 {
Björn Stenberg6c33c512004-09-19 21:58:37 +0000172 case SETTINGS_CANCEL:
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000173 return false;
174 }
175
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +0000176 audio_get_debugdata(&d);
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000177
178 lcd_clear_display();
179
Linus Nielsen Feltzingd34865a2005-04-05 11:33:58 +0000180 snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read);
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000181 lcd_puts(0, 0, buf);
Linus Nielsen Feltzingd34865a2005-04-05 11:33:58 +0000182 snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write);
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000183 lcd_puts(0, 1, buf);
Linus Nielsen Feltzingd34865a2005-04-05 11:33:58 +0000184 snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite);
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000185 lcd_puts(0, 2, buf);
186 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
187 lcd_puts(0, 3, buf);
Linus Nielsen Feltzingd29248d2002-12-05 14:11:48 +0000188 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000189 lcd_puts(0, 4, buf);
190 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
191 lcd_puts(0, 5, buf);
Linus Nielsen Feltzingbf303de2002-10-15 07:23:18 +0000192
Linus Nielsen Feltzing24410612004-07-08 13:14:44 +0000193 /* Playable space left */
Linus Nielsen Feltzingd34865a2005-04-05 11:33:58 +0000194 scrollbar(0, 6*8, 112, 4, d.audiobuflen, 0,
Linus Nielsen Feltzing24410612004-07-08 13:14:44 +0000195 d.playable_space, HORIZONTAL);
Linus Nielsen Feltzingbf303de2002-10-15 07:23:18 +0000196
Linus Nielsen Feltzing24410612004-07-08 13:14:44 +0000197 /* Show the watermark limit */
Linus Nielsen Feltzingd34865a2005-04-05 11:33:58 +0000198 scrollbar(0, 6*8+4, 112, 4, d.audiobuflen, 0,
Linus Nielsen Feltzing24410612004-07-08 13:14:44 +0000199 d.low_watermark_level, HORIZONTAL);
Linus Nielsen Feltzingbf303de2002-10-15 07:23:18 +0000200
Linus Nielsen Feltzingb8ff5f82002-12-05 13:09:51 +0000201 snprintf(buf, sizeof(buf), "wm: %x - %x",
202 d.low_watermark_level, d.lowest_watermark_level);
Linus Nielsen Feltzingbf303de2002-10-15 07:23:18 +0000203 lcd_puts(0, 7, buf);
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000204
205 lcd_update();
206 }
207 return false;
208}
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000209#else
210extern size_t audiobuffer_free;
Miika Pekkarinen159c52d2005-08-20 11:13:19 +0000211extern int filebuflen;
212extern int filebufused;
Linus Nielsen Feltzing17098e12005-06-22 20:37:31 +0000213extern int track_count;
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000214
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000215static int ticks, boost_ticks;
216
217void dbg_audio_task(void)
218{
219 if(FREQ > CPUFREQ_NORMAL)
220 boost_ticks++;
221
222 ticks++;
223}
224
225bool dbg_audio_thread(void)
226{
227 char buf[32];
228 int button;
229 int line;
Linus Nielsen Feltzingfcc282c2005-06-22 14:09:07 +0000230 bool done = false;
Miika Pekkarinenf090dc32005-07-21 11:44:00 +0000231 int bufsize = pcmbuf_get_bufsize();
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000232
233 ticks = boost_ticks = 0;
234
235 tick_add_task(dbg_audio_task);
236
237 lcd_setmargins(0, 0);
Linus Nielsen Feltzing44bba0f2005-06-22 21:37:00 +0000238 lcd_setfont(FONT_SYSFIXED);
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000239
Linus Nielsen Feltzingfcc282c2005-06-22 14:09:07 +0000240 while(!done)
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000241 {
242 button = button_get_w_tmo(HZ/5);
243 switch(button)
244 {
245 case SETTINGS_CANCEL:
Linus Nielsen Feltzingfcc282c2005-06-22 14:09:07 +0000246 done = true;
247 break;
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000248 }
249
250 line = 0;
251
252 lcd_clear_display();
253
Linus Nielsen Feltzing17098e12005-06-22 20:37:31 +0000254 snprintf(buf, sizeof(buf), "pcm: %d/%d",
Miika Pekkarinenf090dc32005-07-21 11:44:00 +0000255 bufsize-(int)audiobuffer_free, bufsize);
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000256 lcd_puts(0, line++, buf);
257
258 /* Playable space left */
Miika Pekkarinenf090dc32005-07-21 11:44:00 +0000259 scrollbar(0, line*8, LCD_WIDTH, 6, bufsize, 0,
260 bufsize-audiobuffer_free, HORIZONTAL);
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000261 line++;
262
Miika Pekkarinen159c52d2005-08-20 11:13:19 +0000263 snprintf(buf, sizeof(buf), "codec: %d/%d", filebufused, filebuflen);
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000264 lcd_puts(0, line++, buf);
265
266 /* Playable space left */
Miika Pekkarinen159c52d2005-08-20 11:13:19 +0000267 scrollbar(0, line*8, LCD_WIDTH, 6, filebuflen, 0,
268 filebufused, HORIZONTAL);
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000269 line++;
270
Linus Nielsen Feltzing17098e12005-06-22 20:37:31 +0000271 snprintf(buf, sizeof(buf), "track count: %d", track_count);
272 lcd_puts(0, line++, buf);
273
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +0000274 snprintf(buf, sizeof(buf), "cpu freq: %dMHz", (int)FREQ/1000000+1);
275 lcd_puts(0, line++, buf);
276
277 snprintf(buf, sizeof(buf), "boost ratio: %d%%",
278 boost_ticks * 100 / ticks);
279 lcd_puts(0, line++, buf);
280
281 lcd_update();
282 }
283
284 tick_remove_task(dbg_audio_task);
285
286 return false;
287}
288#endif
289#endif
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000290
291/* Tool function to calculate a CRC16 across some buffer */
Jens Arnold8fb33612004-08-18 01:09:31 +0000292unsigned short crc_16(const unsigned char* buf, unsigned len)
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000293{
Jörg Hohensohnf80505c2003-08-02 12:53:57 +0000294 /* CCITT standard polynomial 0x1021 */
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000295 static const unsigned short crc16_lookup[16] =
296 { /* lookup table for 4 bits at a time is affordable */
297 0x0000, 0x1021, 0x2042, 0x3063,
298 0x4084, 0x50A5, 0x60C6, 0x70E7,
299 0x8108, 0x9129, 0xA14A, 0xB16B,
300 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF
301 };
302 unsigned short crc16 = 0xFFFF; /* initialise to 0xFFFF (CCITT specification) */
303 unsigned t;
304 unsigned char byte;
305
306 while (len--)
307 {
308 byte = *buf++; /* get one byte of data */
309
310 /* upper nibble of our data */
311 t = crc16 >> 12; /* extract the 4 most significant bits */
312 t ^= byte >> 4; /* XOR in 4 bits of the data into the extracted bits */
313 crc16 <<= 4; /* shift the CRC Register left 4 bits */
314 crc16 ^= crc16_lookup[t]; /* do the table lookup and XOR the result */
315
316 /* lower nibble of our data */
317 t = crc16 >> 12; /* extract the 4 most significant bits */
318 t ^= byte & 0x0F; /* XOR in 4 bits of the data into the extracted bits */
319 crc16 <<= 4; /* shift the CRC Register left 4 bits */
320 crc16 ^= crc16_lookup[t]; /* do the table lookup and XOR the result */
321 }
Jens Arnold90cbd3b2004-09-28 06:23:57 +0000322
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000323 return crc16;
324}
325
326
Jean-Philippe Bernardyed7c6352005-02-08 15:12:25 +0000327#if CONFIG_CPU == TCC730
Jean-Philippe Bernardyed7c6352005-02-08 15:12:25 +0000328static unsigned flash_word_temp __attribute__ ((section (".idata")));
329
330static void flash_write_word(unsigned addr, unsigned value) __attribute__ ((section(".icode")));
331static void flash_write_word(unsigned addr, unsigned value) {
332 flash_word_temp = value;
333
334 long extAddr = (long)addr << 1;
Jean-Philippe Bernardy234489a2005-02-25 09:19:44 +0000335 ddma_transfer(1, 1, &flash_word_temp, extAddr, 2);
Jean-Philippe Bernardyed7c6352005-02-08 15:12:25 +0000336}
337
338static unsigned flash_read_word(unsigned addr) __attribute__ ((section(".icode")));
339static unsigned flash_read_word(unsigned addr) {
340 long extAddr = (long)addr << 1;
Jean-Philippe Bernardy234489a2005-02-25 09:19:44 +0000341 ddma_transfer(1, 1, &flash_word_temp, extAddr, 2);
Jean-Philippe Bernardyed7c6352005-02-08 15:12:25 +0000342 return flash_word_temp;
343}
344
345#endif
346
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000347
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000348/* Tool function to read the flash manufacturer and type, if available.
349 Only chips which could be reprogrammed in system will return values.
350 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
Jörg Hohensohn5846aab2004-07-19 21:21:34 +0000351 /* In IRAM to avoid problems when running directly from Flash */
Jens Arnold4c7da882005-06-18 01:25:47 +0000352bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
Jörg Hohensohn5846aab2004-07-19 21:21:34 +0000353 unsigned addr1, unsigned addr2)
354 __attribute__ ((section (".icode")));
355bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device,
356 unsigned addr1, unsigned addr2)
357
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000358{
359 unsigned not_manu, not_id; /* read values before switching to ID mode */
360 unsigned manu, id; /* read values when in ID mode */
Jean-Philippe Bernardyed7c6352005-02-08 15:12:25 +0000361#if CONFIG_CPU == TCC730
362#define FLASH(addr) (flash_read_word(addr))
363#define SET_FLASH(addr, val) (flash_write_word((addr), (val)))
364#else
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000365 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
Jean-Philippe Bernardyed7c6352005-02-08 15:12:25 +0000366#define FLASH(addr) (flash[addr])
367#define SET_FLASH(addr, val) (flash[addr] = val)
368
369#endif
Jörg Hohensohn5846aab2004-07-19 21:21:34 +0000370 int old_level; /* saved interrupt level */
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000371
Jean-Philippe Bernardyed7c6352005-02-08 15:12:25 +0000372 not_manu = FLASH(0); /* read the normal content */
373 not_id = FLASH(1); /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000374
Jörg Hohensohn5846aab2004-07-19 21:21:34 +0000375 /* disable interrupts, prevent any stray flash access */
376 old_level = set_irq_level(HIGHEST_IRQ_LEVEL);
377
Jean-Philippe Bernardyed7c6352005-02-08 15:12:25 +0000378 SET_FLASH(addr1, 0xAA); /* enter command mode */
379 SET_FLASH(addr2, 0x55);
380 SET_FLASH(addr1, 0x90); /* ID command */
Jörg Hohensohn5846aab2004-07-19 21:21:34 +0000381 /* Atmel wants 20ms pause here */
382 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000383
Jean-Philippe Bernardyed7c6352005-02-08 15:12:25 +0000384 manu = FLASH(0); /* read the IDs */
385 id = FLASH(1);
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000386
Jean-Philippe Bernardyed7c6352005-02-08 15:12:25 +0000387 SET_FLASH(0, 0xF0); /* reset flash (back to normal read mode) */
Jörg Hohensohn5846aab2004-07-19 21:21:34 +0000388 /* Atmel wants 20ms pause here */
389 /* sleep(HZ/50); no sleeping possible while interrupts are disabled */
390
391 set_irq_level(old_level); /* enable interrupts again */
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000392
393 /* I assume success if the obtained values are different from
394 the normal flash content. This is not perfectly bulletproof, they
395 could theoretically be the same by chance, causing us to fail. */
396 if (not_manu != manu || not_id != id) /* a value has changed */
397 {
398 *p_manufacturer = manu; /* return the results */
399 *p_device = id;
400 return true; /* success */
401 }
402 return false; /* fail */
403}
404
405
Linus Nielsen Feltzing2f74eaa2002-10-14 14:13:48 +0000406#ifdef HAVE_LCD_BITMAP
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000407bool dbg_hw_info(void)
408{
Daniel Stenberg1d395ae2005-02-02 21:57:40 +0000409#if CONFIG_CPU == SH7034
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000410 char buf[32];
411 int button;
412 int usb_polarity;
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000413 int pr_polarity;
Linus Nielsen Feltzing3cfc6ec2002-10-08 11:15:00 +0000414 int bitmask = *(unsigned short*)0x20000fc;
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000415 int rom_version = *(unsigned short*)0x20000fe;
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000416 unsigned manu, id; /* flash IDs */
417 bool got_id; /* flag if we managed to get the flash IDs */
Jörg Hohensohnd8b31812003-10-29 22:10:13 +0000418 unsigned rom_crc = 0xFFFF; /* CRC16 of the boot ROM */
419 bool has_bootrom; /* flag for boot ROM present */
Jens Arnold06cb2372004-08-30 19:52:45 +0000420 int oldmode; /* saved memory guard mode */
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000421
Jens Arnold4c428e02004-10-01 20:21:17 +0000422#ifdef USB_ENABLE_ONDIOSTYLE
Jens Arnoldd89b75b2005-05-08 12:16:46 +0000423 if(PADRL & 0x20)
Jens Arnold4c428e02004-10-01 20:21:17 +0000424#else
Jens Arnoldd89b75b2005-05-08 12:16:46 +0000425 if(PADRH & 0x04)
Jens Arnold4c428e02004-10-01 20:21:17 +0000426#endif
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000427 usb_polarity = 0; /* Negative */
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000428 else
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000429 usb_polarity = 1; /* Positive */
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000430
Jens Arnoldd89b75b2005-05-08 12:16:46 +0000431 if(PADRH & 0x08)
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000432 pr_polarity = 0; /* Negative */
433 else
434 pr_polarity = 1; /* Positive */
Linus Nielsen Feltzing07083fb2002-10-09 06:36:32 +0000435
Jens Arnold06cb2372004-08-30 19:52:45 +0000436 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
437
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000438 /* get flash ROM type */
439 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
440 if (!got_id)
441 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
442
Jörg Hohensohnd8b31812003-10-29 22:10:13 +0000443 /* check if the boot ROM area is a flash mirror */
444 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
445 if (has_bootrom) /* if ROM and Flash different */
446 {
447 /* calculate CRC16 checksum of boot ROM */
448 rom_crc = crc_16((unsigned char*)0x0000, 64*1024);
449 }
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000450
Jens Arnold06cb2372004-08-30 19:52:45 +0000451 system_memory_guard(oldmode); /* re-enable memory guard */
452
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000453 lcd_setmargins(0, 0);
454 lcd_setfont(FONT_SYSFIXED);
455 lcd_clear_display();
456
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000457 lcd_puts(0, 0, "[Hardware info]");
458
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000459 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
460 lcd_puts(0, 1, buf);
461
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000462 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000463 lcd_puts(0, 2, buf);
464
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000465 snprintf(buf, 32, "USB: %s", usb_polarity?"positive":"negative");
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000466 lcd_puts(0, 3, buf);
467
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000468 snprintf(buf, 32, "PR: %s", pr_polarity?"positive":"negative");
Jörg Hohensohn099ef222004-10-22 20:44:26 +0000469 lcd_puts(0, 4, buf);
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000470
Jörg Hohensohnceba6f82003-05-17 20:40:30 +0000471 if (got_id)
472 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
473 else
474 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
Jörg Hohensohn099ef222004-10-22 20:44:26 +0000475 lcd_puts(0, 5, buf);
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000476
Jörg Hohensohnd8b31812003-10-29 22:10:13 +0000477 if (has_bootrom)
478 {
479 snprintf(buf, 32-3, "ROM CRC: 0x%04x", rom_crc);
480 if (rom_crc == 0x222F) /* known Version 1 */
481 strcat(buf, " V1");
482 }
483 else
484 {
485 snprintf(buf, 32, "Boot ROM: none");
486 }
Jörg Hohensohn099ef222004-10-22 20:44:26 +0000487 lcd_puts(0, 6, buf);
488
489#ifndef HAVE_MMC /* have ATA */
490 snprintf(buf, 32, "ATA: 0x%x,%s", ata_io_address,
491 ata_device ? "slave":"master");
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000492 lcd_puts(0, 7, buf);
Jörg Hohensohn099ef222004-10-22 20:44:26 +0000493#endif
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000494 lcd_update();
Linus Nielsen Feltzing46a94be2002-10-14 14:25:25 +0000495
496 while(1)
497 {
498 button = button_get(true);
Björn Stenberg6c33c512004-09-19 21:58:37 +0000499 if(button == SETTINGS_CANCEL)
Linus Nielsen Feltzing46a94be2002-10-14 14:25:25 +0000500 return false;
501 }
Daniel Stenberg1d395ae2005-02-02 21:57:40 +0000502#endif /* CONFIG_CPU == SH7034 */
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000503 return false;
504}
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000505#else
506bool dbg_hw_info(void)
507{
508 char buf[32];
509 int button;
510 int currval = 0;
511 int usb_polarity;
512 int bitmask = *(unsigned short*)0x20000fc;
513 int rom_version = *(unsigned short*)0x20000fe;
Jörg Hohensohn09d1a732003-05-20 21:30:53 +0000514 unsigned manu, id; /* flash IDs */
515 bool got_id; /* flag if we managed to get the flash IDs */
Jörg Hohensohnd8b31812003-10-29 22:10:13 +0000516 unsigned rom_crc = 0xFFFF; /* CRC16 of the boot ROM */
517 bool has_bootrom; /* flag for boot ROM present */
Jens Arnold06cb2372004-08-30 19:52:45 +0000518 int oldmode; /* saved memory guard mode */
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000519
Jens Arnoldd89b75b2005-05-08 12:16:46 +0000520 if(PADRH & 0x04)
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000521 usb_polarity = 0; /* Negative */
522 else
523 usb_polarity = 1; /* Positive */
524
Jens Arnold06cb2372004-08-30 19:52:45 +0000525 oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */
526
Jörg Hohensohn09d1a732003-05-20 21:30:53 +0000527 /* get flash ROM type */
528 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
529 if (!got_id)
530 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
531
Jörg Hohensohnd8b31812003-10-29 22:10:13 +0000532 /* check if the boot ROM area is a flash mirror */
533 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
534 if (has_bootrom) /* if ROM and Flash different */
535 {
536 /* calculate CRC16 checksum of boot ROM */
537 rom_crc = crc_16((unsigned char*)0x0000, 64*1024);
538 }
Jens Arnold06cb2372004-08-30 19:52:45 +0000539
540 system_memory_guard(oldmode); /* re-enable memory guard */
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000541
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000542 lcd_clear_display();
543
544 lcd_puts(0, 0, "[HW Info]");
545 while(1)
546 {
547 switch(currval)
548 {
549 case 0:
550 snprintf(buf, 32, "ROM: %d.%02d",
551 rom_version/100, rom_version%100);
552 break;
553 case 1:
554 snprintf(buf, 32, "USB: %s",
555 usb_polarity?"pos":"neg");
556 break;
557 case 2:
Björn Stenbergee192fb2003-08-05 13:39:38 +0000558 snprintf(buf, 32, "ATA: 0x%x%s",
Björn Stenberg8abc9d42003-08-05 13:41:00 +0000559 ata_io_address, ata_device ? "s":"m");
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000560 break;
561 case 3:
562 snprintf(buf, 32, "Mask: %04x", bitmask);
563 break;
Jörg Hohensohn09d1a732003-05-20 21:30:53 +0000564 case 4:
565 if (got_id)
566 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
567 else
568 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
569 break;
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000570 case 5:
Jörg Hohensohnd8b31812003-10-29 22:10:13 +0000571 if (has_bootrom)
572 snprintf(buf, 32, "RomCRC:%04x", rom_crc);
573 else
574 snprintf(buf, 32, "BootROM: no");
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000575 }
576
Linus Nielsen Feltzing07083fb2002-10-09 06:36:32 +0000577 lcd_puts(0, 1, buf);
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000578 lcd_update();
579
580 button = button_get(true);
581
582 switch(button)
583 {
Björn Stenberg6c33c512004-09-19 21:58:37 +0000584 case SETTINGS_CANCEL:
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000585 return false;
586
Björn Stenberg6c33c512004-09-19 21:58:37 +0000587 case SETTINGS_DEC:
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000588 currval--;
589 if(currval < 0)
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000590 currval = 5;
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000591 break;
592
Björn Stenberg6c33c512004-09-19 21:58:37 +0000593 case SETTINGS_INC:
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000594 currval++;
Jörg Hohensohnb2188822003-08-01 08:00:54 +0000595 if(currval > 5)
Linus Nielsen Feltzing1e972b52002-10-08 12:08:30 +0000596 currval = 0;
597 break;
598 }
599 }
600 return false;
601}
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000602#endif
603
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000604bool dbg_partitions(void)
605{
606 int partition=0;
607
608 lcd_clear_display();
609 lcd_puts(0, 0, "Partition");
610 lcd_puts(0, 1, "list");
611 lcd_update();
Björn Stenbergf09c5f42002-12-03 14:18:51 +0000612 sleep(HZ/2);
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000613
614 while(1)
615 {
616 char buf[32];
617 int button;
618 struct partinfo* p = disk_partinfo(partition);
619
620 lcd_clear_display();
Jens Arnold6baa55a2005-01-24 01:39:24 +0000621 snprintf(buf, sizeof buf, "P%d: S:%lx", partition, p->start);
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000622 lcd_puts(0, 0, buf);
Jens Arnold6baa55a2005-01-24 01:39:24 +0000623 snprintf(buf, sizeof buf, "T:%x %ld MB", p->type, p->size / 2048);
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000624 lcd_puts(0, 1, buf);
625 lcd_update();
626
627 button = button_get(true);
628
629 switch(button)
630 {
Björn Stenberg6c33c512004-09-19 21:58:37 +0000631 case SETTINGS_OK:
632 case SETTINGS_CANCEL:
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000633 return false;
634
Björn Stenberg6c33c512004-09-19 21:58:37 +0000635 case SETTINGS_DEC:
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000636 partition--;
637 if (partition < 0)
638 partition = 3;
639 break;
640
Björn Stenberg6c33c512004-09-19 21:58:37 +0000641 case SETTINGS_INC:
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000642 partition++;
643 if (partition > 3)
644 partition = 0;
645 break;
Linus Nielsen Feltzingade5d7b2004-07-26 16:06:59 +0000646
647 default:
648 if(default_event_handler(button) == SYS_USB_CONNECTED)
649 return true;
650 break;
Björn Stenberg4d55c2f2002-10-10 12:01:58 +0000651 }
652 }
653 return false;
654}
655
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +0000656#ifdef CPU_COLDFIRE
657bool dbg_spdif(void)
658{
659 char buf[128];
660 int button;
661 int line;
662 unsigned int control;
663 int x;
664 char *s;
665 int category;
666 int generation;
667 unsigned int interruptstat;
668 bool valnogood, symbolerr, parityerr;
669
670 lcd_setmargins(0, 0);
671 lcd_clear_display();
672 lcd_setfont(FONT_SYSFIXED);
673
674 while(1)
675 {
676 line = 0;
677
678 control = EBU1RCVCCHANNEL1;
679 interruptstat = INTERRUPTSTAT;
680 INTERRUPTCLEAR = 0x03c00000;
681
682 valnogood = (interruptstat & 0x01000000)?true:false;
683 symbolerr = (interruptstat & 0x00800000)?true:false;
684 parityerr = (interruptstat & 0x00400000)?true:false;
685
686 snprintf(buf, sizeof(buf), "Val: %s Sym: %s Par: %s",
687 valnogood?"--":"OK",
688 symbolerr?"--":"OK",
689 parityerr?"--":"OK");
690 lcd_puts(0, line++, buf);
691
692 snprintf(buf, sizeof(buf), "Status word: %08x", (int)control);
693 lcd_puts(0, line++, buf);
694
695 line++;
696
697 x = control >> 31;
698 snprintf(buf, sizeof(buf), "PRO: %d (%s)",
699 x, x?"Professional":"Consumer");
700 lcd_puts(0, line++, buf);
701
702 x = (control >> 30) & 1;
703 snprintf(buf, sizeof(buf), "Audio: %d (%s)",
704 x, x?"Non-PCM":"PCM");
705 lcd_puts(0, line++, buf);
706
707 x = (control >> 29) & 1;
708 snprintf(buf, sizeof(buf), "Copy: %d (%s)",
709 x, x?"Permitted":"Inhibited");
710 lcd_puts(0, line++, buf);
711
712 x = (control >> 27) & 7;
713 switch(x)
714 {
715 case 0:
716 s = "None";
717 break;
718 case 1:
719 s = "50/15us";
720 break;
721 default:
722 s = "Reserved";
723 break;
724 }
725 snprintf(buf, sizeof(buf), "Preemphasis: %d (%s)", x, s);
726 lcd_puts(0, line++, buf);
727
728 x = (control >> 24) & 3;
729 snprintf(buf, sizeof(buf), "Mode: %d", x);
730 lcd_puts(0, line++, buf);
731
732 category = (control >> 17) & 127;
733 switch(category)
734 {
735 case 0x00:
736 s = "General";
737 break;
738 case 0x40:
739 s = "Audio CD";
740 break;
741 default:
742 s = "Unknown";
743 }
744 snprintf(buf, sizeof(buf), "Category: 0x%02x (%s)", category, s);
745 lcd_puts(0, line++, buf);
746
747 x = (control >> 16) & 1;
748 generation = x;
749 if(((category & 0x70) == 0x10) ||
750 ((category & 0x70) == 0x40) ||
751 ((category & 0x78) == 0x38))
752 {
753 generation = !generation;
754 }
755 snprintf(buf, sizeof(buf), "Generation: %d (%s)",
756 x, generation?"Original":"No ind.");
757 lcd_puts(0, line++, buf);
758
759 x = (control >> 12) & 15;
760 snprintf(buf, sizeof(buf), "Source: %d", x);
761 lcd_puts(0, line++, buf);
762
763 x = (control >> 8) & 15;
764 switch(x)
765 {
766 case 0:
767 s = "Unspecified";
768 break;
769 case 8:
770 s = "A (Left)";
771 break;
772 case 4:
773 s = "B (Right)";
774 break;
775 default:
776 s = "";
777 break;
778 }
779 snprintf(buf, sizeof(buf), "Channel: %d (%s)", x, s);
780 lcd_puts(0, line++, buf);
781
782 x = (control >> 4) & 15;
783 switch(x)
784 {
785 case 0:
786 s = "44.1kHz";
787 break;
788 case 0x4:
789 s = "48kHz";
790 break;
791 case 0xc:
792 s = "32kHz";
793 break;
794 }
795 snprintf(buf, sizeof(buf), "Frequency: %d (%s)", x, s);
796 lcd_puts(0, line++, buf);
797
798 x = (control >> 2) & 3;
799 snprintf(buf, sizeof(buf), "Clock accuracy: %d", x);
800 lcd_puts(0, line++, buf);
801
802 lcd_update();
803 button = button_get_w_tmo(HZ/10);
804
805 switch(button)
806 {
807 case SETTINGS_CANCEL:
808 case SETTINGS_OK2:
809 return false;
810 }
811 }
812
813 return false;
814}
815#endif
816
Linus Nielsen Feltzing91b26f22002-10-08 10:52:46 +0000817#ifdef HAVE_LCD_BITMAP
Björn Stenberg803f47b2002-07-15 11:23:24 +0000818/* Test code!!! */
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000819bool dbg_ports(void)
Björn Stenberg803f47b2002-07-15 11:23:24 +0000820{
Daniel Stenberg1d395ae2005-02-02 21:57:40 +0000821#if CONFIG_CPU == SH7034
Björn Stenberg803f47b2002-07-15 11:23:24 +0000822 unsigned short porta;
823 unsigned short portb;
824 unsigned char portc;
825 char buf[32];
826 int button;
827 int battery_voltage;
828 int batt_int, batt_frac;
Björn Stenberg803f47b2002-07-15 11:23:24 +0000829
Markus Brauna0300f52002-08-20 22:13:20 +0000830#ifdef HAVE_LCD_BITMAP
Linus Nielsen Feltzingf22eeee2005-08-14 08:43:05 +0000831 lcd_setfont(FONT_SYSFIXED);
Markus Brauna0300f52002-08-20 22:13:20 +0000832 lcd_setmargins(0, 0);
833#endif
Björn Stenberg803f47b2002-07-15 11:23:24 +0000834 lcd_clear_display();
835
836 while(1)
837 {
838 porta = PADR;
839 portb = PBDR;
840 portc = PCDR;
841
842 snprintf(buf, 32, "PADR: %04x", porta);
843 lcd_puts(0, 0, buf);
844 snprintf(buf, 32, "PBDR: %04x", portb);
845 lcd_puts(0, 1, buf);
846
847 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
848 lcd_puts(0, 2, buf);
849 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
850 lcd_puts(0, 3, buf);
851 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
852 lcd_puts(0, 4, buf);
853 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
854 lcd_puts(0, 5, buf);
855
Heikki Hannikainen6eb42542002-08-06 10:52:51 +0000856 battery_voltage = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000;
Björn Stenberg803f47b2002-07-15 11:23:24 +0000857 batt_int = battery_voltage / 100;
858 batt_frac = battery_voltage % 100;
859
860 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", batt_int, batt_frac,
861 battery_level());
862 lcd_puts(0, 6, buf);
Jörg Hohensohn099ef222004-10-22 20:44:26 +0000863#ifndef HAVE_MMC /* have ATA */
Björn Stenberg803f47b2002-07-15 11:23:24 +0000864 snprintf(buf, 32, "ATA: %s, 0x%x",
865 ata_device?"slave":"master", ata_io_address);
866 lcd_puts(0, 7, buf);
Jörg Hohensohn099ef222004-10-22 20:44:26 +0000867#endif
Björn Stenberg803f47b2002-07-15 11:23:24 +0000868 lcd_update();
Linus Nielsen Feltzing0a744762003-04-09 23:17:35 +0000869 button = button_get_w_tmo(HZ/10);
Björn Stenberg803f47b2002-07-15 11:23:24 +0000870
871 switch(button)
872 {
Björn Stenberg6c33c512004-09-19 21:58:37 +0000873 case SETTINGS_CANCEL:
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000874 return false;
Björn Stenberg803f47b2002-07-15 11:23:24 +0000875 }
876 }
Christian Gmeinerc6ff1f52005-07-18 12:40:29 +0000877#elif defined(CPU_COLDFIRE)
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000878 unsigned int gpio_out;
879 unsigned int gpio1_out;
880 unsigned int gpio_read;
881 unsigned int gpio1_read;
882 unsigned int gpio_function;
883 unsigned int gpio1_function;
884 unsigned int gpio_enable;
885 unsigned int gpio1_enable;
886 int adc_buttons, adc_remote, adc_battery;
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +0000887 char buf[128];
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000888 int button;
889 int line;
Linus Nielsen Feltzing43bf39e2005-04-06 23:53:19 +0000890 int battery_voltage;
891 int batt_int, batt_frac;
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000892
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000893 lcd_setmargins(0, 0);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000894 lcd_clear_display();
895 lcd_setfont(FONT_SYSFIXED);
896
897 while(1)
898 {
899 line = 0;
900 gpio_read = GPIO_READ;
901 gpio1_read = GPIO1_READ;
902 gpio_out = GPIO_OUT;
903 gpio1_out = GPIO1_OUT;
904 gpio_function = GPIO_FUNCTION;
905 gpio1_function = GPIO1_FUNCTION;
906 gpio_enable = GPIO_ENABLE;
907 gpio1_enable = GPIO1_ENABLE;
908
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +0000909 snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000910 lcd_puts(0, line++, buf);
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +0000911 snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000912 lcd_puts(0, line++, buf);
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +0000913 snprintf(buf, sizeof(buf), "GPIO_FUNCTION: %08x", gpio_function);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000914 lcd_puts(0, line++, buf);
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +0000915 snprintf(buf, sizeof(buf), "GPIO_ENABLE: %08x", gpio_enable);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000916 lcd_puts(0, line++, buf);
917
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +0000918 snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000919 lcd_puts(0, line++, buf);
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +0000920 snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000921 lcd_puts(0, line++, buf);
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +0000922 snprintf(buf, sizeof(buf), "GPIO1_FUNCTION: %08x", gpio1_function);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000923 lcd_puts(0, line++, buf);
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +0000924 snprintf(buf, sizeof(buf), "GPIO1_ENABLE: %08x", gpio1_enable);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000925 lcd_puts(0, line++, buf);
926
927 adc_buttons = adc_read(ADC_BUTTONS);
928 adc_remote = adc_read(ADC_REMOTE);
929 adc_battery = adc_read(ADC_BATTERY);
930
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +0000931 snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000932 lcd_puts(0, line++, buf);
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +0000933 snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000934 lcd_puts(0, line++, buf);
Linus Nielsen Feltzingaceef072005-03-01 14:40:27 +0000935 snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_battery);
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000936 lcd_puts(0, line++, buf);
937
Linus Nielsen Feltzing43bf39e2005-04-06 23:53:19 +0000938 battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000;
939 batt_int = battery_voltage / 100;
940 batt_frac = battery_voltage % 100;
941
942 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", batt_int, batt_frac,
943 battery_level());
944 lcd_puts(0, line++, buf);
945
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +0000946 lcd_update();
947 button = button_get_w_tmo(HZ/10);
948
949 switch(button)
950 {
951 case SETTINGS_CANCEL:
952 return false;
953 }
954 }
955
Daniel Stenberg1d395ae2005-02-02 21:57:40 +0000956#endif /* CONFIG_CPU == SH7034 */
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000957 return false;
Björn Stenberg803f47b2002-07-15 11:23:24 +0000958}
959#else
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000960bool dbg_ports(void)
Björn Stenberg803f47b2002-07-15 11:23:24 +0000961{
962 unsigned short porta;
963 unsigned short portb;
964 unsigned char portc;
965 char buf[32];
Björn Stenberg803f47b2002-07-15 11:23:24 +0000966 int button;
967 int battery_voltage;
968 int batt_int, batt_frac;
969 int currval = 0;
970
971 lcd_clear_display();
972
973 while(1)
974 {
975 porta = PADR;
976 portb = PBDR;
977 portc = PCDR;
978
979 switch(currval)
980 {
Robert Hak50fc3ce2002-08-10 08:52:11 +0000981 case 0:
982 snprintf(buf, 32, "PADR: %04x ", porta);
983 break;
984 case 1:
985 snprintf(buf, 32, "PBDR: %04x ", portb);
986 break;
987 case 2:
988 snprintf(buf, 32, "AN0: %03x ", adc_read(0));
989 break;
990 case 3:
991 snprintf(buf, 32, "AN1: %03x ", adc_read(1));
992 break;
993 case 4:
994 snprintf(buf, 32, "AN2: %03x ", adc_read(2));
995 break;
996 case 5:
997 snprintf(buf, 32, "AN3: %03x ", adc_read(3));
998 break;
999 case 6:
1000 snprintf(buf, 32, "AN4: %03x ", adc_read(4));
1001 break;
1002 case 7:
1003 snprintf(buf, 32, "AN5: %03x ", adc_read(5));
1004 break;
1005 case 8:
1006 snprintf(buf, 32, "AN6: %03x ", adc_read(6));
1007 break;
1008 case 9:
1009 snprintf(buf, 32, "AN7: %03x ", adc_read(7));
1010 break;
1011 case 10:
1012 snprintf(buf, 32, "%s, 0x%x ",
1013 ata_device?"slv":"mst", ata_io_address);
1014 break;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001015 }
1016 lcd_puts(0, 0, buf);
1017
Björn Stenbergfe97b572002-08-10 08:57:47 +00001018 battery_voltage = (adc_read(ADC_UNREG_POWER) *
1019 BATTERY_SCALE_FACTOR) / 10000;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001020 batt_int = battery_voltage / 100;
1021 batt_frac = battery_voltage % 100;
1022
1023 snprintf(buf, 32, "Batt: %d.%02dV", batt_int, batt_frac);
1024 lcd_puts(0, 1, buf);
1025
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001026 button = button_get_w_tmo(HZ/5);
Björn Stenberg803f47b2002-07-15 11:23:24 +00001027
1028 switch(button)
1029 {
Björn Stenberg6c33c512004-09-19 21:58:37 +00001030 case SETTINGS_CANCEL:
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001031 return false;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001032
Björn Stenberg6c33c512004-09-19 21:58:37 +00001033 case SETTINGS_DEC:
Robert Hak50fc3ce2002-08-10 08:52:11 +00001034 currval--;
1035 if(currval < 0)
Linus Nielsen Feltzing41977da2002-08-14 08:04:42 +00001036 currval = 10;
Robert Hak50fc3ce2002-08-10 08:52:11 +00001037 break;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001038
Björn Stenberg6c33c512004-09-19 21:58:37 +00001039 case SETTINGS_INC:
Robert Hak50fc3ce2002-08-10 08:52:11 +00001040 currval++;
Linus Nielsen Feltzing41977da2002-08-14 08:04:42 +00001041 if(currval > 10)
Robert Hak50fc3ce2002-08-10 08:52:11 +00001042 currval = 0;
1043 break;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001044 }
1045 }
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001046 return false;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001047}
1048#endif
1049
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +00001050#ifdef HAVE_ADJUSTABLE_CPU_FREQ
1051extern int boost_counter;
1052bool dbg_cpufreq(void)
1053{
1054 char buf[128];
1055 int line;
1056 int button;
1057
1058#ifdef HAVE_LCD_BITMAP
1059 lcd_setmargins(0, 0);
Linus Nielsen Feltzing57d8e8f2005-08-18 07:16:53 +00001060 lcd_setfont(FONT_SYSFIXED);
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +00001061#endif
1062 lcd_clear_display();
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +00001063
1064 while(1)
1065 {
1066 line = 0;
1067
1068 snprintf(buf, sizeof(buf), "Frequency: %ld", FREQ);
1069 lcd_puts(0, line++, buf);
1070
1071 snprintf(buf, sizeof(buf), "boost_counter: %d", boost_counter);
1072 lcd_puts(0, line++, buf);
1073
1074 lcd_update();
1075 button = button_get_w_tmo(HZ/10);
1076
1077 switch(button)
1078 {
1079 case BUTTON_UP:
1080 cpu_boost(true);
1081 break;
1082
1083 case BUTTON_DOWN:
1084 cpu_boost(false);
1085 break;
Linus Nielsen Feltzingc71db252005-03-07 13:02:06 +00001086
Daniel Stenberg01377e22005-06-29 12:47:24 +00001087#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
1088 (CONFIG_KEYPAD == IRIVER_H300_PAD)
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +00001089 case BUTTON_SELECT:
Linus Nielsen Feltzingc71db252005-03-07 13:02:06 +00001090#else
1091 case BUTTON_PLAY:
1092#endif
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +00001093 set_cpu_frequency(CPUFREQ_DEFAULT);
1094 boost_counter = 0;
1095 break;
1096
1097 case SETTINGS_CANCEL:
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +00001098 case SETTINGS_OK2:
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +00001099 return false;
1100 }
1101 }
1102
1103 return false;
1104}
1105#endif
Jens Arnold4ddb3202005-05-06 21:55:34 +00001106
Björn Stenbergb47e64e2002-08-08 20:44:25 +00001107#ifdef HAVE_LCD_BITMAP
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001108/*
1109 * view_battery() shows a automatically scaled graph of the battery voltage
1110 * over time. Usable for estimating battery life / charging rate.
1111 * The power_history array is updated in power_thread of powermgmt.c.
1112 */
1113
Jörg Hohensohn25848962005-03-03 07:25:43 +00001114#define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN)
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001115#define BAT_YSPACE (LCD_HEIGHT - 20)
1116
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001117bool view_battery(void)
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001118{
1119 int view = 0;
1120 int i, x, y;
Jean-Philippe Bernardyed7c6352005-02-08 15:12:25 +00001121 unsigned short maxv, minv;
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001122 char buf[32];
1123
Markus Brauna0300f52002-08-20 22:13:20 +00001124#ifdef HAVE_LCD_BITMAP
1125 lcd_setmargins(0, 0);
Linus Nielsen Feltzingf22eeee2005-08-14 08:43:05 +00001126 lcd_setfont(FONT_SYSFIXED);
Markus Brauna0300f52002-08-20 22:13:20 +00001127#endif
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001128 while(1)
1129 {
1130 switch (view) {
Björn Stenbergfe97b572002-08-10 08:57:47 +00001131 case 0: /* voltage history graph */
1132 /* Find maximum and minimum voltage for scaling */
Jörg Hohensohn25848962005-03-03 07:25:43 +00001133 maxv = 0;
1134 minv = 65535;
1135 for (i = 0; i < BAT_LAST_VAL; i++) {
Björn Stenbergfe97b572002-08-10 08:57:47 +00001136 if (power_history[i] > maxv)
1137 maxv = power_history[i];
Jörg Hohensohn25848962005-03-03 07:25:43 +00001138 if (power_history[i] && (power_history[i] < minv))
Björn Stenbergfe97b572002-08-10 08:57:47 +00001139 {
1140 minv = power_history[i];
1141 }
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001142 }
1143
Jörg Hohensohn25848962005-03-03 07:25:43 +00001144 if ((minv < 1) || (minv >= 65535))
Björn Stenbergfe97b572002-08-10 08:57:47 +00001145 minv = 1;
1146 if (maxv < 2)
1147 maxv = 2;
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001148
Björn Stenbergfe97b572002-08-10 08:57:47 +00001149 lcd_clear_display();
Jörg Hohensohn25848962005-03-03 07:25:43 +00001150 snprintf(buf, 30, "Battery %d.%02d", power_history[0] / 100,
1151 power_history[0] % 100);
1152 lcd_puts(0, 0, buf);
Björn Stenbergfe97b572002-08-10 08:57:47 +00001153 snprintf(buf, 30, "scale %d.%02d-%d.%02d V",
1154 minv / 100, minv % 100, maxv / 100, maxv % 100);
1155 lcd_puts(0, 1, buf);
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001156
Björn Stenbergfe97b572002-08-10 08:57:47 +00001157 x = 0;
Jörg Hohensohn25848962005-03-03 07:25:43 +00001158 for (i = BAT_LAST_VAL - 1; i >= 0; i--) {
Björn Stenbergfe97b572002-08-10 08:57:47 +00001159 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
Jens Arnold04daef12005-06-24 22:33:21 +00001160 lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
Jens Arnold93494122005-06-25 00:28:09 +00001161 lcd_vline(x, LCD_HEIGHT-1, 20);
Jens Arnold04daef12005-06-24 22:33:21 +00001162 lcd_set_drawmode(DRMODE_SOLID);
Jens Arnold93494122005-06-25 00:28:09 +00001163 lcd_vline(x, LCD_HEIGHT-1,
1164 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
Björn Stenbergfe97b572002-08-10 08:57:47 +00001165 x++;
1166 }
1167
1168 break;
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001169
Björn Stenbergfe97b572002-08-10 08:57:47 +00001170 case 1: /* status: */
1171 lcd_clear_display();
1172 lcd_puts(0, 0, "Power status:");
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001173
Björn Stenbergfe97b572002-08-10 08:57:47 +00001174 y = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000;
1175 snprintf(buf, 30, "Battery: %d.%02d V", y / 100, y % 100);
1176 lcd_puts(0, 1, buf);
Jens Arnold303b4ab2004-12-01 00:33:18 +00001177#ifdef ADC_EXT_POWER
Björn Stenbergfe97b572002-08-10 08:57:47 +00001178 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000;
1179 snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100);
1180 lcd_puts(0, 2, buf);
Jens Arnold303b4ab2004-12-01 00:33:18 +00001181#endif
1182#ifdef HAVE_CHARGING
Björn Stenbergfe97b572002-08-10 08:57:47 +00001183 snprintf(buf, 30, "Charger: %s",
1184 charger_inserted() ? "present" : "absent");
1185 lcd_puts(0, 3, buf);
Jörg Hohensohn25848962005-03-03 07:25:43 +00001186#endif
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001187#ifdef HAVE_CHARGE_CTRL
Michiel Van Der Kolk9d2531a2005-03-28 00:47:09 +00001188 snprintf(buf, 30, "Chgr: %s %s",
1189 charger_inserted() ? "present" : "absent",
1190 charger_enabled ? "on" : "off");
1191 lcd_puts(0, 3, buf);
Jörg Hohensohn25848962005-03-03 07:25:43 +00001192 snprintf(buf, 30, "short delta: %d", short_delta);
Björn Stenbergfe97b572002-08-10 08:57:47 +00001193 lcd_puts(0, 5, buf);
Jörg Hohensohn25848962005-03-03 07:25:43 +00001194 snprintf(buf, 30, "long delta: %d", long_delta);
Björn Stenbergfe97b572002-08-10 08:57:47 +00001195 lcd_puts(0, 6, buf);
Björn Stenbergfe97b572002-08-10 08:57:47 +00001196 lcd_puts(0, 7, power_message);
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001197#endif
Björn Stenbergfe97b572002-08-10 08:57:47 +00001198 break;
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001199
Björn Stenbergfe97b572002-08-10 08:57:47 +00001200 case 2: /* voltage deltas: */
1201 lcd_clear_display();
1202 lcd_puts(0, 0, "Voltage deltas:");
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001203
Björn Stenbergfe97b572002-08-10 08:57:47 +00001204 for (i = 0; i <= 6; i++) {
Jörg Hohensohn25848962005-03-03 07:25:43 +00001205 y = power_history[i] - power_history[i+i];
Björn Stenbergfe97b572002-08-10 08:57:47 +00001206 snprintf(buf, 30, "-%d min: %s%d.%02d V", i,
1207 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 100,
1208 ((y < 0) ? y * -1 : y ) % 100);
1209 lcd_puts(0, i+1, buf);
1210 }
1211 break;
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001212
Michiel Van Der Kolk9d2531a2005-03-28 00:47:09 +00001213 case 3: /* remaining time estimation: */
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001214 lcd_clear_display();
Uwe Freesec83374b2002-12-15 18:10:19 +00001215
Uwe Freese5e44a562003-02-12 22:21:07 +00001216#ifdef HAVE_CHARGE_CTRL
Uwe Freesec83374b2002-12-15 18:10:19 +00001217 snprintf(buf, 30, "charge_state: %d", charge_state);
1218 lcd_puts(0, 0, buf);
1219
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001220 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
1221 lcd_puts(0, 1, buf);
1222
Jörg Hohensohn25848962005-03-03 07:25:43 +00001223 snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level);
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001224 lcd_puts(0, 2, buf);
Michiel Van Der Kolk9d2531a2005-03-28 00:47:09 +00001225
1226 snprintf(buf, 30, "P=%2d I=%2d", pid_p, pid_i);
1227 lcd_puts(0, 3, buf);
1228
1229 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
1230 lcd_puts(0, 4, buf);
Uwe Freese5e44a562003-02-12 22:21:07 +00001231#endif
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001232
Jörg Hohensohn25848962005-03-03 07:25:43 +00001233 snprintf(buf, 30, "Last PwrHist: %d.%02d V",
1234 power_history[0] / 100,
1235 power_history[0] % 100);
Michiel Van Der Kolk451dd482005-03-28 00:00:24 +00001236 lcd_puts(0, 5, buf);
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001237
Michiel Van Der Kolk9d2531a2005-03-28 00:47:09 +00001238 snprintf(buf, 30, "battery level: %d%%", battery_level());
Michiel Van Der Kolk451dd482005-03-28 00:00:24 +00001239 lcd_puts(0, 6, buf);
1240
Michiel Van Der Kolk9d2531a2005-03-28 00:47:09 +00001241 snprintf(buf, 30, "Est. remain: %d m", battery_time());
Uwe Freese5f027972002-12-14 12:10:29 +00001242 lcd_puts(0, 7, buf);
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001243 break;
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001244 }
1245
1246 lcd_update();
Heikki Hannikainencccb8d02002-08-12 12:21:22 +00001247
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001248 switch(button_get_w_tmo(HZ/2))
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001249 {
Björn Stenberg6c33c512004-09-19 21:58:37 +00001250 case SETTINGS_DEC:
Björn Stenbergfe97b572002-08-10 08:57:47 +00001251 if (view)
1252 view--;
1253 break;
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001254
Björn Stenberg6c33c512004-09-19 21:58:37 +00001255 case SETTINGS_INC:
Björn Stenbergf09c5f42002-12-03 14:18:51 +00001256 if (view < 3)
Björn Stenbergfe97b572002-08-10 08:57:47 +00001257 view++;
1258 break;
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001259
Björn Stenberg6c33c512004-09-19 21:58:37 +00001260 case SETTINGS_OK:
1261 case SETTINGS_CANCEL:
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001262 return false;
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001263 }
1264 }
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001265 return false;
Heikki Hannikainen6eb42542002-08-06 10:52:51 +00001266}
1267
Linus Nielsen Feltzingc132c482002-07-22 16:39:17 +00001268#endif
Jens Arnold4ddb3202005-05-06 21:55:34 +00001269
Björn Stenbergae22de22002-12-02 16:07:56 +00001270static bool view_runtime(void)
1271{
1272 char s[32];
1273 bool done = false;
1274 int state = 1;
1275
1276 while(!done)
1277 {
1278 int y=0;
1279 int t;
1280 int key;
1281 lcd_clear_display();
1282#ifdef HAVE_LCD_BITMAP
1283 lcd_puts(0, y++, "Running time:");
1284 y++;
1285#endif
1286
1287 if (state & 1) {
Björn Stenbergfb067482003-10-17 13:54:48 +00001288 if (charger_inserted())
1289 {
1290 global_settings.runtime = 0;
1291 }
1292 else
1293 {
1294 global_settings.runtime += ((current_tick - lasttime) / HZ);
1295 }
1296 lasttime = current_tick;
1297
Björn Stenbergae22de22002-12-02 16:07:56 +00001298 t = global_settings.runtime;
1299 lcd_puts(0, y++, "Current time");
1300 }
1301 else {
1302 t = global_settings.topruntime;
1303 lcd_puts(0, y++, "Top time");
1304 }
1305
1306 snprintf(s, sizeof(s), "%dh %dm %ds",
1307 t / 3600, (t % 3600) / 60, t % 60);
1308 lcd_puts(0, y++, s);
1309 lcd_update();
1310
1311 /* Wait for a key to be pushed */
Björn Stenbergfb067482003-10-17 13:54:48 +00001312 key = button_get_w_tmo(HZ);
Björn Stenbergae22de22002-12-02 16:07:56 +00001313 switch(key) {
Björn Stenberg6c33c512004-09-19 21:58:37 +00001314 case SETTINGS_CANCEL:
Björn Stenbergae22de22002-12-02 16:07:56 +00001315 done = true;
1316 break;
1317
Björn Stenberg6c33c512004-09-19 21:58:37 +00001318 case SETTINGS_INC:
1319 case SETTINGS_DEC:
Björn Stenbergae22de22002-12-02 16:07:56 +00001320 if (state == 1)
1321 state = 2;
1322 else
1323 state = 1;
1324 break;
Björn Stenberg6c33c512004-09-19 21:58:37 +00001325
1326 case SETTINGS_OK:
Björn Stenbergae22de22002-12-02 16:07:56 +00001327 lcd_clear_display();
1328 lcd_puts(0,0,"Clear time?");
1329 lcd_puts(0,1,"PLAY = Yes");
1330 lcd_update();
1331 while (1) {
Jens Arnolddcd48832004-10-16 07:49:57 +00001332 key = button_get(true);
Björn Stenberg6c33c512004-09-19 21:58:37 +00001333 if ( key == SETTINGS_OK ) {
Björn Stenbergae22de22002-12-02 16:07:56 +00001334 if ( state == 1 )
1335 global_settings.runtime = 0;
1336 else
1337 global_settings.topruntime = 0;
Henrik Backed00beba2004-09-23 19:38:59 +00001338 break;
Björn Stenbergae22de22002-12-02 16:07:56 +00001339 }
Jens Arnolddcd48832004-10-16 07:49:57 +00001340 if (!(key & BUTTON_REL)) /* ignore button releases */
Henrik Backed00beba2004-09-23 19:38:59 +00001341 break;
Björn Stenbergae22de22002-12-02 16:07:56 +00001342 }
1343 break;
1344 }
1345 }
1346
1347 return false;
1348}
1349
Jens Arnold90cbd3b2004-09-28 06:23:57 +00001350#ifdef HAVE_MMC
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001351bool dbg_mmc_info(void)
1352{
1353 bool done = false;
1354 int currval = 0;
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001355 tCardInfo *card;
Jens Arnold2116bba2005-01-31 00:39:20 +00001356 unsigned char pbuf[32], pbuf2[32];
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001357 unsigned char card_name[7];
Jens Arnold2116bba2005-01-31 00:39:20 +00001358
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001359 static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
1360 static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
Jens Arnold2116bba2005-01-31 00:39:20 +00001361 static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };
1362 static const unsigned char *nsec_units[] = { "ns", "µs", "ms" };
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001363
1364 card_name[6] = '\0';
1365
1366 lcd_setmargins(0, 0);
1367 lcd_setfont(FONT_SYSFIXED);
1368
1369 while (!done)
1370 {
1371 card = mmc_card_info(currval / 2);
1372
1373 lcd_clear_display();
1374 snprintf(pbuf, sizeof(pbuf), "[MMC%d p%d]", currval / 2,
1375 (currval % 2) + 1);
1376 lcd_puts(0, 0, pbuf);
1377
1378 if (card->initialized)
1379 {
1380 if (!(currval % 2)) /* General info */
1381 {
1382 strncpy(card_name, ((unsigned char*)card->cid) + 3, 6);
1383 snprintf(pbuf, sizeof(pbuf), "%s Rev %d.%d", card_name,
Jens Arnold6baa55a2005-01-24 01:39:24 +00001384 (int) mmc_extract_bits(card->cid, 72, 4),
1385 (int) mmc_extract_bits(card->cid, 76, 4));
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001386 lcd_puts(0, 1, pbuf);
1387 snprintf(pbuf, sizeof(pbuf), "Prod: %d/%d",
Jens Arnold6baa55a2005-01-24 01:39:24 +00001388 (int) mmc_extract_bits(card->cid, 112, 4),
1389 (int) mmc_extract_bits(card->cid, 116, 4) + 1997);
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001390 lcd_puts(0, 2, pbuf);
Jens Arnold6baa55a2005-01-24 01:39:24 +00001391 snprintf(pbuf, sizeof(pbuf), "Ser#: 0x%08lx",
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001392 mmc_extract_bits(card->cid, 80, 32));
1393 lcd_puts(0, 3, pbuf);
1394 snprintf(pbuf, sizeof(pbuf), "M=%02x, O=%04x",
Jens Arnold6baa55a2005-01-24 01:39:24 +00001395 (int) mmc_extract_bits(card->cid, 0, 8),
1396 (int) mmc_extract_bits(card->cid, 8, 16));
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001397 lcd_puts(0, 4, pbuf);
Jens Arnold8ca18312005-05-27 21:47:50 +00001398 snprintf(pbuf, sizeof(pbuf), "Blocks: 0x%06lx", card->numblocks);
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001399 lcd_puts(0, 5, pbuf);
Jens Arnold8ca18312005-05-27 21:47:50 +00001400 snprintf(pbuf, sizeof(pbuf), "Blksz.: %d", card->blocksize);
Jens Arnolda7f77812005-04-28 01:11:21 +00001401 lcd_puts(0, 6, pbuf);
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001402 }
1403 else /* Technical details */
1404 {
Jens Arnold2116bba2005-01-31 00:39:20 +00001405 output_dyn_value(pbuf2, sizeof pbuf2, card->speed / 1000,
1406 kbit_units, false);
1407 snprintf(pbuf, sizeof pbuf, "Speed: %s", pbuf2);
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001408 lcd_puts(0, 1, pbuf);
1409
Jens Arnold2116bba2005-01-31 00:39:20 +00001410 output_dyn_value(pbuf2, sizeof pbuf2, card->tsac,
1411 nsec_units, false);
1412 snprintf(pbuf, sizeof pbuf, "Tsac: %s", pbuf2);
Jens Arnold8886adb2004-10-07 01:23:44 +00001413 lcd_puts(0, 2, pbuf);
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001414
1415 snprintf(pbuf, sizeof(pbuf), "Nsac: %d clk", card->nsac);
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001416 lcd_puts(0, 3, pbuf);
Jens Arnold8886adb2004-10-07 01:23:44 +00001417 snprintf(pbuf, sizeof(pbuf), "R2W: *%d", card->r2w_factor);
1418 lcd_puts(0, 4, pbuf);
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001419 snprintf(pbuf, sizeof(pbuf), "IRmax: %d..%d mA",
1420 i_vmin[mmc_extract_bits(card->csd, 66, 3)],
1421 i_vmax[mmc_extract_bits(card->csd, 69, 3)]);
Jens Arnold8886adb2004-10-07 01:23:44 +00001422 lcd_puts(0, 5, pbuf);
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001423 snprintf(pbuf, sizeof(pbuf), "IWmax: %d..%d mA",
1424 i_vmin[mmc_extract_bits(card->csd, 72, 3)],
1425 i_vmax[mmc_extract_bits(card->csd, 75, 3)]);
Jens Arnold8886adb2004-10-07 01:23:44 +00001426 lcd_puts(0, 6, pbuf);
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001427 }
1428 }
1429 else
1430 lcd_puts(0, 1, "Not found!");
1431
1432 lcd_update();
1433
Jens Arnoldf5bdf692004-10-10 00:35:19 +00001434 switch (button_get_w_tmo(HZ/2))
Jens Arnold6f9a7eb2004-10-06 20:43:12 +00001435 {
1436 case SETTINGS_OK:
1437 case SETTINGS_CANCEL:
1438 done = true;
1439 break;
1440
1441 case SETTINGS_DEC:
1442 currval--;
1443 if (currval < 0)
1444 currval = 3;
1445 break;
1446
1447 case SETTINGS_INC:
1448 currval++;
1449 if (currval > 3)
1450 currval = 0;
1451 break;
1452 }
1453 }
Jens Arnold90cbd3b2004-09-28 06:23:57 +00001454
1455 return false;
1456}
1457#else /* Disk-based jukebox */
Björn Stenberg45d32ce2002-12-03 13:12:55 +00001458static bool dbg_disk_info(void)
1459{
1460 char buf[128];
1461 bool done = false;
1462 int i;
1463 int page = 0;
Linus Nielsen Feltzingef1698e2004-04-06 00:17:02 +00001464 const int max_page = 11;
Björn Stenberg45d32ce2002-12-03 13:12:55 +00001465 unsigned short* identify_info = ata_get_identify();
Linus Nielsen Feltzingf3ad6192004-02-16 12:04:55 +00001466 bool timing_info_present = false;
1467 char pio3[2], pio4[2];
Björn Stenberg45d32ce2002-12-03 13:12:55 +00001468
Linus Nielsen Feltzingae6e33e2004-02-16 12:21:07 +00001469#ifdef HAVE_LCD_BITMAP
Linus Nielsen Feltzingf3ad6192004-02-16 12:04:55 +00001470 lcd_setmargins(0, 0);
Linus Nielsen Feltzingae6e33e2004-02-16 12:21:07 +00001471#endif
Linus Nielsen Feltzingf3ad6192004-02-16 12:04:55 +00001472
Björn Stenberg45d32ce2002-12-03 13:12:55 +00001473 while(!done)
1474 {
1475 int y=0;
1476 int key;
1477 lcd_clear_display();
1478#ifdef HAVE_LCD_BITMAP
1479 lcd_puts(0, y++, "Disk info:");
1480 y++;
1481#endif
1482
1483 switch (page) {
Björn Stenbergee192fb2003-08-05 13:39:38 +00001484 case 0:
1485 for (i=0; i < 20; i++)
1486 ((unsigned short*)buf)[i]=identify_info[i+27];
1487 buf[40]=0;
1488 /* kill trailing space */
1489 for (i=39; i && buf[i]==' '; i--)
1490 buf[i] = 0;
1491 lcd_puts(0, y++, "Model");
1492 lcd_puts_scroll(0, y++, buf);
1493 break;
Björn Stenberg45d32ce2002-12-03 13:12:55 +00001494
Björn Stenbergee192fb2003-08-05 13:39:38 +00001495 case 1:
1496 for (i=0; i < 4; i++)
1497 ((unsigned short*)buf)[i]=identify_info[i+23];
1498 buf[8]=0;
1499 lcd_puts(0, y++, "Firmware");
1500 lcd_puts(0, y++, buf);
1501 break;
Björn Stenberg45d32ce2002-12-03 13:12:55 +00001502
Björn Stenbergee192fb2003-08-05 13:39:38 +00001503 case 2:
Jean-Philippe Bernardyed7c6352005-02-08 15:12:25 +00001504 snprintf(buf, sizeof buf, "%ld MB",
1505 ((unsigned long)identify_info[61] << 16 |
1506 (unsigned long)identify_info[60]) / 2048 );
Björn Stenbergee192fb2003-08-05 13:39:38 +00001507 lcd_puts(0, y++, "Size");
1508 lcd_puts(0, y++, buf);
1509 break;
Björn Stenbergb070dd52002-12-04 14:58:48 +00001510
Björn Stenbergee192fb2003-08-05 13:39:38 +00001511 case 3: {
Jens Arnold6baa55a2005-01-24 01:39:24 +00001512 unsigned long free;
Jörg Hohensohn575c9042004-12-29 22:37:31 +00001513 fat_size( IF_MV2(0,) NULL, &free );
Jens Arnold6baa55a2005-01-24 01:39:24 +00001514 snprintf(buf, sizeof buf, "%ld MB", free / 1024 );
Björn Stenbergee192fb2003-08-05 13:39:38 +00001515 lcd_puts(0, y++, "Free");
1516 lcd_puts(0, y++, buf);
1517 break;
1518 }
Björn Stenbergb17fe5a2002-12-09 15:39:32 +00001519
Björn Stenbergee192fb2003-08-05 13:39:38 +00001520 case 4:
1521 snprintf(buf, sizeof buf, "%d ms", ata_spinup_time * (1000/HZ));
1522 lcd_puts(0, y++, "Spinup time");
1523 lcd_puts(0, y++, buf);
1524 break;
Björn Stenberg218754a2004-01-14 15:08:55 +00001525
1526 case 5:
1527 i = identify_info[83] & (1<<3);
1528 lcd_puts(0, y++, "Power mgmt:");
1529 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1530 break;
1531
1532 case 6:
1533 i = identify_info[83] & (1<<9);
1534 lcd_puts(0, y++, "Noise mgmt:");
1535 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1536 break;
1537
1538 case 7:
Björn Stenbergef1ecad2004-01-14 15:10:17 +00001539 i = identify_info[82] & (1<<6);
Björn Stenberg218754a2004-01-14 15:08:55 +00001540 lcd_puts(0, y++, "Read-ahead:");
1541 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1542 break;
Linus Nielsen Feltzingf3ad6192004-02-16 12:04:55 +00001543
1544 case 8:
1545 timing_info_present = identify_info[53] & (1<<1);
1546 if(timing_info_present) {
1547 pio3[1] = 0;
1548 pio4[1] = 0;
1549 lcd_puts(0, y++, "PIO modes:");
1550 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1551 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1552 snprintf(buf, 128, "0 1 2 %s %s", pio3, pio4);
1553 lcd_puts(0, y++, buf);
1554 } else {
1555 lcd_puts(0, y++, "No PIO mode info");
1556 }
1557 break;
1558
1559 case 9:
1560 timing_info_present = identify_info[53] & (1<<1);
1561 if(timing_info_present) {
Linus Nielsen Feltzing50c22612004-03-01 09:42:47 +00001562 lcd_puts(0, y++, "Cycle times");
1563 snprintf(buf, 128, "%dns/%dns",
1564 identify_info[67],
1565 identify_info[68]);
Linus Nielsen Feltzingf3ad6192004-02-16 12:04:55 +00001566 lcd_puts(0, y++, buf);
1567 } else {
1568 lcd_puts(0, y++, "No timing info");
1569 }
1570 break;
1571
1572 case 10:
1573 timing_info_present = identify_info[53] & (1<<1);
1574 if(timing_info_present) {
1575 i = identify_info[49] & (1<<11);
1576 snprintf(buf, 128, "IORDY support: %s", i ? "yes" : "no");
1577 lcd_puts(0, y++, buf);
1578 i = identify_info[49] & (1<<10);
1579 snprintf(buf, 128, "IORDY disable: %s", i ? "yes" : "no");
1580 lcd_puts(0, y++, buf);
1581 } else {
1582 lcd_puts(0, y++, "No timing info");
1583 }
1584 break;
Linus Nielsen Feltzingef1698e2004-04-06 00:17:02 +00001585
1586 case 11:
1587 lcd_puts(0, y++, "Cluster size");
Jörg Hohensohn575c9042004-12-29 22:37:31 +00001588 snprintf(buf, 128, "%d bytes", fat_get_cluster_size(IF_MV(0)));
Linus Nielsen Feltzingef1698e2004-04-06 00:17:02 +00001589 lcd_puts(0, y++, buf);
1590 break;
Björn Stenberg45d32ce2002-12-03 13:12:55 +00001591 }
1592 lcd_update();
1593
1594 /* Wait for a key to be pushed */
1595 key = button_get_w_tmo(HZ*5);
1596 switch(key) {
Björn Stenberg6c33c512004-09-19 21:58:37 +00001597 case SETTINGS_CANCEL:
Björn Stenberg45d32ce2002-12-03 13:12:55 +00001598 done = true;
1599 break;
1600
Björn Stenberg6c33c512004-09-19 21:58:37 +00001601 case SETTINGS_DEC:
Björn Stenberg45d32ce2002-12-03 13:12:55 +00001602 if (--page < 0)
1603 page = max_page;
1604 break;
1605
Björn Stenberg6c33c512004-09-19 21:58:37 +00001606 case SETTINGS_INC:
Björn Stenberg45d32ce2002-12-03 13:12:55 +00001607 if (++page > max_page)
1608 page = 0;
1609 break;
Björn Stenbergb17fe5a2002-12-09 15:39:32 +00001610
Björn Stenberg6c33c512004-09-19 21:58:37 +00001611 case SETTINGS_OK:
Björn Stenbergb17fe5a2002-12-09 15:39:32 +00001612 if (page == 3) {
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +00001613 audio_stop(); /* stop playback, to avoid disk access */
Björn Stenbergb17fe5a2002-12-09 15:39:32 +00001614 lcd_clear_display();
1615 lcd_puts(0,0,"Scanning");
1616 lcd_puts(0,1,"disk...");
1617 lcd_update();
Jörg Hohensohn575c9042004-12-29 22:37:31 +00001618 fat_recalc_free(IF_MV(0));
Björn Stenbergb17fe5a2002-12-09 15:39:32 +00001619 }
1620 break;
Björn Stenberg45d32ce2002-12-03 13:12:55 +00001621 }
1622 lcd_stop_scroll();
1623 }
1624
1625 return false;
1626}
Jens Arnold90cbd3b2004-09-28 06:23:57 +00001627#endif
Björn Stenberg45d32ce2002-12-03 13:12:55 +00001628
Daniel Stenberg1d395ae2005-02-02 21:57:40 +00001629#if CONFIG_CPU == SH7034
Linus Nielsen Feltzing5a5c8692003-05-17 21:24:13 +00001630bool dbg_save_roms(void)
1631{
1632 int fd;
Jens Arnold06cb2372004-08-30 19:52:45 +00001633 int oldmode = system_memory_guard(MEMGUARD_NONE);
Linus Nielsen Feltzing5a5c8692003-05-17 21:24:13 +00001634
1635 fd = creat("/internal_rom_0000-FFFF.bin", O_WRONLY);
1636 if(fd >= 0)
1637 {
1638 write(fd, (void *)0, 0x10000);
1639 close(fd);
1640 }
Jens Arnold7ec8aa22005-06-22 22:38:52 +00001641
Linus Nielsen Feltzing5a5c8692003-05-17 21:24:13 +00001642 fd = creat("/internal_rom_2000000-203FFFF.bin", O_WRONLY);
1643 if(fd >= 0)
1644 {
1645 write(fd, (void *)0x2000000, 0x40000);
1646 close(fd);
1647 }
1648
Jens Arnold06cb2372004-08-30 19:52:45 +00001649 system_memory_guard(oldmode);
Linus Nielsen Feltzing5a5c8692003-05-17 21:24:13 +00001650 return false;
1651}
Daniel Stenberg1d395ae2005-02-02 21:57:40 +00001652#endif /* CONFIG_CPU == SH7034 */
Linus Nielsen Feltzing5a5c8692003-05-17 21:24:13 +00001653
Jörg Hohensohn593cc002004-09-28 22:13:26 +00001654#ifdef CONFIG_TUNER
Linus Nielsen Feltzing04f9cc72004-02-04 09:53:22 +00001655bool dbg_fm_radio(void)
1656{
1657 char buf[32];
1658 int button;
1659 bool fm_detected;
1660
1661#ifdef HAVE_LCD_BITMAP
1662 lcd_setmargins(0, 0);
1663#endif
1664
1665 while(1)
1666 {
1667 lcd_clear_display();
1668 fm_detected = radio_hardware_present();
1669
1670 snprintf(buf, sizeof buf, "HW detected: %s", fm_detected?"yes":"no");
1671 lcd_puts(0, 0, buf);
Linus Nielsen Feltzing04f9cc72004-02-04 09:53:22 +00001672 lcd_update();
1673
1674 button = button_get(true);
1675
1676 switch(button)
1677 {
Björn Stenberg6c33c512004-09-19 21:58:37 +00001678 case SETTINGS_CANCEL:
Linus Nielsen Feltzing04f9cc72004-02-04 09:53:22 +00001679 return false;
1680 }
1681 }
1682 return false;
1683}
1684#endif
1685
Linus Nielsen Feltzinga8dab4c2004-06-30 13:31:14 +00001686#ifdef HAVE_LCD_BITMAP
1687extern bool do_screendump_instead_of_usb;
1688
1689bool dbg_screendump(void)
1690{
1691 do_screendump_instead_of_usb = !do_screendump_instead_of_usb;
1692 splash(HZ, true, "Screendump %s",
1693 do_screendump_instead_of_usb?"enabled":"disabled");
1694 return false;
1695}
1696#endif
1697
Daniel Stenberg1d395ae2005-02-02 21:57:40 +00001698#if CONFIG_CPU == SH7034
Jens Arnold06cb2372004-08-30 19:52:45 +00001699bool dbg_set_memory_guard(void)
1700{
1701 static const struct opt_items names[MAXMEMGUARD] = {
1702 { "None", -1 },
1703 { "Flash ROM writes", -1 },
1704 { "Zero area (all)", -1 }
1705 };
1706 int mode = system_memory_guard(MEMGUARD_KEEP);
1707
1708 set_option( "Catch mem accesses", &mode, INT, names, MAXMEMGUARD, NULL);
1709 system_memory_guard(mode);
1710
1711 return false;
1712}
Daniel Stenberg1d395ae2005-02-02 21:57:40 +00001713#endif /* CONFIG_CPU == SH7034 */
Jens Arnold06cb2372004-08-30 19:52:45 +00001714
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001715bool debug_menu(void)
Björn Stenberg803f47b2002-07-15 11:23:24 +00001716{
1717 int m;
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001718 bool result;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001719
Jörg Hohensohnb1403ee2004-07-23 23:01:20 +00001720 static const struct menu_item items[] = {
Daniel Stenberg1d395ae2005-02-02 21:57:40 +00001721#if CONFIG_CPU == SH7034
Jörg Hohensohnb1403ee2004-07-23 23:01:20 +00001722 { "Dump ROM contents", dbg_save_roms },
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001723#endif
Christian Gmeinerc6ff1f52005-07-18 12:40:29 +00001724#if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE)
Jörg Hohensohnb1403ee2004-07-23 23:01:20 +00001725 { "View I/O ports", dbg_ports },
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001726#endif
Linus Nielsen Feltzing213d34e2005-03-07 10:51:43 +00001727#ifdef HAVE_ADJUSTABLE_CPU_FREQ
1728 { "CPU frequency", dbg_cpufreq },
Linus Nielsen Feltzing1bba84f2005-03-18 12:47:06 +00001729#endif
Linus Nielsen Feltzingb6242daf2005-07-11 12:09:01 +00001730#if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR)
Andye5d08722005-06-19 03:05:53 +00001731 { "PCM recording", pcm_rec_screen },
Linus Nielsen Feltzing3c82b842005-07-18 18:28:49 +00001732 { "S/PDIF analyzer", dbg_spdif },
Andye5d08722005-06-19 03:05:53 +00001733#endif
Linus Nielsen Feltzing68054752005-02-11 13:16:09 +00001734#if CONFIG_CPU == SH7034
Jens Arnold06cb2372004-08-30 19:52:45 +00001735 { "Catch mem accesses", dbg_set_memory_guard },
Daniel Stenberg1d395ae2005-02-02 21:57:40 +00001736#endif /* CONFIG_CPU == SH7034 */
1737 { "View OS stacks", dbg_os },
Björn Stenbergb47e64e2002-08-08 20:44:25 +00001738#ifdef HAVE_LCD_BITMAP
Jörg Hohensohnb1403ee2004-07-23 23:01:20 +00001739 { "View battery", view_battery },
1740 { "Screendump", dbg_screendump },
Linus Nielsen Feltzingc132c482002-07-22 16:39:17 +00001741#endif
Jörg Hohensohnb1403ee2004-07-23 23:01:20 +00001742 { "View HW info", dbg_hw_info },
1743 { "View partitions", dbg_partitions },
Jens Arnold90cbd3b2004-09-28 06:23:57 +00001744#ifdef HAVE_MMC
1745 { "View MMC info", dbg_mmc_info },
1746#else
Jörg Hohensohnb1403ee2004-07-23 23:01:20 +00001747 { "View disk info", dbg_disk_info },
Jens Arnold90cbd3b2004-09-28 06:23:57 +00001748#endif
Linus Nielsen Feltzingb5a0f702005-06-22 14:03:04 +00001749#ifdef HAVE_LCD_BITMAP
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +00001750 { "View audio thread", dbg_audio_thread },
Linus Nielsen Feltzingfd0cc3b2002-10-29 12:09:15 +00001751#ifdef PM_DEBUG
Jörg Hohensohnb1403ee2004-07-23 23:01:20 +00001752 { "pm histogram", peak_meter_histogram},
Linus Nielsen Feltzingfd0cc3b2002-10-29 12:09:15 +00001753#endif /* PM_DEBUG */
1754#endif /* HAVE_LCD_BITMAP */
Jörg Hohensohnb1403ee2004-07-23 23:01:20 +00001755 { "View runtime", view_runtime },
Jörg Hohensohn593cc002004-09-28 22:13:26 +00001756#ifdef CONFIG_TUNER
Jörg Hohensohnb1403ee2004-07-23 23:01:20 +00001757 { "FM Radio", dbg_fm_radio },
Linus Nielsen Feltzing04f9cc72004-02-04 09:53:22 +00001758#endif
Daniel Stenbergedc07922005-05-30 13:00:43 +00001759#ifdef ROCKBOX_HAS_LOGF
1760 {"logf", logfdisplay },
Daniel Stenbergc95319f2005-06-01 13:07:37 +00001761 {"logfdump", logfdump },
Daniel Stenbergedc07922005-05-30 13:00:43 +00001762#endif
Björn Stenberg803f47b2002-07-15 11:23:24 +00001763 };
1764
Linus Nielsen Feltzing77936e62004-03-16 13:44:56 +00001765 m=menu_init( items, sizeof items / sizeof(struct menu_item), NULL,
1766 NULL, NULL, NULL);
Daniel Stenbergb2850762002-08-23 12:32:52 +00001767 result = menu_run(m);
Björn Stenberg803f47b2002-07-15 11:23:24 +00001768 menu_exit(m);
Daniel Stenbergb2850762002-08-23 12:32:52 +00001769
1770 return result;
Björn Stenberg803f47b2002-07-15 11:23:24 +00001771}
1772
1773#endif /* SIMULATOR */