Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 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 Sidhu | 9513236 | 2003-08-01 16:05:40 +0000 | [diff] [blame] | 24 | #include <string.h> |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 25 | #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 Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 36 | #include "thread.h" |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 37 | #include "powermgmt.h" |
| 38 | #include "system.h" |
Linus Nielsen Feltzing | 91b26f2 | 2002-10-08 10:52:46 +0000 | [diff] [blame] | 39 | #include "font.h" |
Björn Stenberg | 4d55c2f | 2002-10-10 12:01:58 +0000 | [diff] [blame] | 40 | #include "disk.h" |
Linus Nielsen Feltzing | 8a237a8 | 2005-04-04 12:06:29 +0000 | [diff] [blame] | 41 | #include "audio.h" |
Linus Nielsen Feltzing | f1f7bbe | 2004-03-22 11:48:13 +0000 | [diff] [blame] | 42 | #include "mp3_playback.h" |
Björn Stenberg | ae22de2 | 2002-12-02 16:07:56 +0000 | [diff] [blame] | 43 | #include "settings.h" |
Björn Stenberg | 45d32ce | 2002-12-03 13:12:55 +0000 | [diff] [blame] | 44 | #include "ata.h" |
Björn Stenberg | b17fe5a | 2002-12-09 15:39:32 +0000 | [diff] [blame] | 45 | #include "fat.h" |
Linus Nielsen Feltzing | f3ad619 | 2004-02-16 12:04:55 +0000 | [diff] [blame] | 46 | #include "dir.h" |
| 47 | #include "panic.h" |
Linus Nielsen Feltzing | b81a3c5 | 2004-03-25 12:29:34 +0000 | [diff] [blame] | 48 | #include "screens.h" |
Linus Nielsen Feltzing | ade5d7b | 2004-07-26 16:06:59 +0000 | [diff] [blame] | 49 | #include "misc.h" |
Linus Nielsen Feltzing | 875bf5e | 2002-10-15 08:08:35 +0000 | [diff] [blame] | 50 | #ifdef HAVE_LCD_BITMAP |
Linus Nielsen Feltzing | bf303de | 2002-10-15 07:23:18 +0000 | [diff] [blame] | 51 | #include "widgets.h" |
Linus Nielsen Feltzing | fd0cc3b | 2002-10-29 12:09:15 +0000 | [diff] [blame] | 52 | #include "peakmeter.h" |
Linus Nielsen Feltzing | 875bf5e | 2002-10-15 08:08:35 +0000 | [diff] [blame] | 53 | #endif |
Jörg Hohensohn | 593cc00 | 2004-09-28 22:13:26 +0000 | [diff] [blame] | 54 | #ifdef CONFIG_TUNER |
Linus Nielsen Feltzing | 0579667 | 2004-02-05 10:59:51 +0000 | [diff] [blame] | 55 | #include "radio.h" |
| 56 | #endif |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 57 | #ifdef HAVE_MMC |
| 58 | #include "ata_mmc.h" |
| 59 | #endif |
Daniel Stenberg | edc0792 | 2005-05-30 13:00:43 +0000 | [diff] [blame] | 60 | #include "logfdisp.h" |
Linus Nielsen Feltzing | b6242daf | 2005-07-11 12:09:01 +0000 | [diff] [blame] | 61 | #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR) |
Andy | e5d0872 | 2005-06-19 03:05:53 +0000 | [diff] [blame] | 62 | extern bool pcm_rec_screen(void); |
| 63 | #endif |
Linus Nielsen Feltzing | b5a0f70 | 2005-06-22 14:03:04 +0000 | [diff] [blame] | 64 | #if CONFIG_HWCODEC == MASNONE |
Miika Pekkarinen | b0e78a4 | 2005-07-13 13:13:10 +0000 | [diff] [blame] | 65 | #include "pcmbuf.h" |
Linus Nielsen Feltzing | b5a0f70 | 2005-06-22 14:03:04 +0000 | [diff] [blame] | 66 | #include "pcm_playback.h" |
| 67 | #endif |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 68 | |
| 69 | /*---------------------------------------------------*/ |
| 70 | /* SPECIAL DEBUG STUFF */ |
| 71 | /*---------------------------------------------------*/ |
Jens Arnold | 4ddb320 | 2005-05-06 21:55:34 +0000 | [diff] [blame] | 72 | extern char ata_device; |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 73 | extern int ata_io_address; |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 74 | extern int num_threads; |
Jens Arnold | 0830339 | 2004-08-03 20:52:31 +0000 | [diff] [blame] | 75 | extern const char *thread_name[]; |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 76 | |
Björn Stenberg | b47e64e | 2002-08-08 20:44:25 +0000 | [diff] [blame] | 77 | #ifdef HAVE_LCD_BITMAP |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 78 | /* Test code!!! */ |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 79 | bool dbg_os(void) |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 80 | { |
| 81 | char buf[32]; |
| 82 | int button; |
| 83 | int i; |
| 84 | int usage; |
| 85 | |
Markus Braun | a0300f5 | 2002-08-20 22:13:20 +0000 | [diff] [blame] | 86 | #ifdef HAVE_LCD_BITMAP |
| 87 | lcd_setmargins(0, 0); |
Linus Nielsen Feltzing | 57d8e8f | 2005-08-18 07:16:53 +0000 | [diff] [blame] | 88 | lcd_setfont(FONT_SYSFIXED); |
Markus Braun | a0300f5 | 2002-08-20 22:13:20 +0000 | [diff] [blame] | 89 | #endif |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 90 | lcd_clear_display(); |
| 91 | |
| 92 | while(1) |
| 93 | { |
Robert Hak | 50fc3ce | 2002-08-10 08:52:11 +0000 | [diff] [blame] | 94 | lcd_puts(0, 0, "Stack usage:"); |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 95 | for(i = 0; i < num_threads;i++) |
| 96 | { |
| 97 | usage = thread_stack_usage(i); |
Robert Hak | 50fc3ce | 2002-08-10 08:52:11 +0000 | [diff] [blame] | 98 | snprintf(buf, 32, "%s: %d%%", thread_name[i], usage); |
| 99 | lcd_puts(0, 1+i, buf); |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | lcd_update(); |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 103 | |
Björn Stenberg | f09c5f4 | 2002-12-03 14:18:51 +0000 | [diff] [blame] | 104 | button = button_get_w_tmo(HZ/10); |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 105 | |
| 106 | switch(button) |
| 107 | { |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 108 | case SETTINGS_CANCEL: |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 109 | return false; |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 110 | } |
| 111 | } |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 112 | return false; |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 113 | } |
| 114 | #else |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 115 | bool dbg_os(void) |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 116 | { |
| 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 Hak | 50fc3ce | 2002-08-10 08:52:11 +0000 | [diff] [blame] | 126 | lcd_puts(0, 0, "Stack usage"); |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 127 | |
Robert Hak | 50fc3ce | 2002-08-10 08:52:11 +0000 | [diff] [blame] | 128 | usage = thread_stack_usage(currval); |
| 129 | snprintf(buf, 32, "%d: %d%% ", currval, usage); |
| 130 | lcd_puts(0, 1, buf); |
Jens Arnold | 06cb237 | 2004-08-30 19:52:45 +0000 | [diff] [blame] | 131 | |
Björn Stenberg | f09c5f4 | 2002-12-03 14:18:51 +0000 | [diff] [blame] | 132 | button = button_get_w_tmo(HZ/10); |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 133 | |
| 134 | switch(button) |
| 135 | { |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 136 | case SETTINGS_CANCEL: |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 137 | return false; |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 138 | |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 139 | case SETTINGS_DEC: |
Robert Hak | 50fc3ce | 2002-08-10 08:52:11 +0000 | [diff] [blame] | 140 | currval--; |
| 141 | if(currval < 0) |
| 142 | currval = num_threads-1; |
| 143 | break; |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 144 | |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 145 | case SETTINGS_INC: |
Robert Hak | 50fc3ce | 2002-08-10 08:52:11 +0000 | [diff] [blame] | 146 | currval++; |
| 147 | if(currval > num_threads-1) |
| 148 | currval = 0; |
| 149 | break; |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 150 | } |
| 151 | } |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 152 | return false; |
Linus Nielsen Feltzing | 7fef58a | 2002-07-15 22:25:45 +0000 | [diff] [blame] | 153 | } |
| 154 | #endif |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 155 | |
Linus Nielsen Feltzing | b5a0f70 | 2005-06-22 14:03:04 +0000 | [diff] [blame] | 156 | #ifdef HAVE_LCD_BITMAP |
| 157 | #if CONFIG_HWCODEC != MASNONE |
Linus Nielsen Feltzing | 8a237a8 | 2005-04-04 12:06:29 +0000 | [diff] [blame] | 158 | bool dbg_audio_thread(void) |
Linus Nielsen Feltzing | 2f74eaa | 2002-10-14 14:13:48 +0000 | [diff] [blame] | 159 | { |
| 160 | char buf[32]; |
| 161 | int button; |
Linus Nielsen Feltzing | 8a237a8 | 2005-04-04 12:06:29 +0000 | [diff] [blame] | 162 | struct audio_debug d; |
Linus Nielsen Feltzing | 2f74eaa | 2002-10-14 14:13:48 +0000 | [diff] [blame] | 163 | |
Linus Nielsen Feltzing | bf303de | 2002-10-15 07:23:18 +0000 | [diff] [blame] | 164 | lcd_setmargins(0, 0); |
Linus Nielsen Feltzing | 44bba0f | 2005-06-22 21:37:00 +0000 | [diff] [blame] | 165 | lcd_setfont(FONT_SYSFIXED); |
Linus Nielsen Feltzing | bf303de | 2002-10-15 07:23:18 +0000 | [diff] [blame] | 166 | |
Linus Nielsen Feltzing | 2f74eaa | 2002-10-14 14:13:48 +0000 | [diff] [blame] | 167 | while(1) |
| 168 | { |
| 169 | button = button_get_w_tmo(HZ/5); |
| 170 | switch(button) |
| 171 | { |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 172 | case SETTINGS_CANCEL: |
Linus Nielsen Feltzing | 2f74eaa | 2002-10-14 14:13:48 +0000 | [diff] [blame] | 173 | return false; |
| 174 | } |
| 175 | |
Linus Nielsen Feltzing | 8a237a8 | 2005-04-04 12:06:29 +0000 | [diff] [blame] | 176 | audio_get_debugdata(&d); |
Linus Nielsen Feltzing | 2f74eaa | 2002-10-14 14:13:48 +0000 | [diff] [blame] | 177 | |
| 178 | lcd_clear_display(); |
| 179 | |
Linus Nielsen Feltzing | d34865a | 2005-04-05 11:33:58 +0000 | [diff] [blame] | 180 | snprintf(buf, sizeof(buf), "read: %x", d.audiobuf_read); |
Linus Nielsen Feltzing | 2f74eaa | 2002-10-14 14:13:48 +0000 | [diff] [blame] | 181 | lcd_puts(0, 0, buf); |
Linus Nielsen Feltzing | d34865a | 2005-04-05 11:33:58 +0000 | [diff] [blame] | 182 | snprintf(buf, sizeof(buf), "write: %x", d.audiobuf_write); |
Linus Nielsen Feltzing | 2f74eaa | 2002-10-14 14:13:48 +0000 | [diff] [blame] | 183 | lcd_puts(0, 1, buf); |
Linus Nielsen Feltzing | d34865a | 2005-04-05 11:33:58 +0000 | [diff] [blame] | 184 | snprintf(buf, sizeof(buf), "swap: %x", d.audiobuf_swapwrite); |
Linus Nielsen Feltzing | 2f74eaa | 2002-10-14 14:13:48 +0000 | [diff] [blame] | 185 | lcd_puts(0, 2, buf); |
| 186 | snprintf(buf, sizeof(buf), "playing: %d", d.playing); |
| 187 | lcd_puts(0, 3, buf); |
Linus Nielsen Feltzing | d29248d | 2002-12-05 14:11:48 +0000 | [diff] [blame] | 188 | snprintf(buf, sizeof(buf), "playable: %x", d.playable_space); |
Linus Nielsen Feltzing | 2f74eaa | 2002-10-14 14:13:48 +0000 | [diff] [blame] | 189 | lcd_puts(0, 4, buf); |
| 190 | snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space); |
| 191 | lcd_puts(0, 5, buf); |
Linus Nielsen Feltzing | bf303de | 2002-10-15 07:23:18 +0000 | [diff] [blame] | 192 | |
Linus Nielsen Feltzing | 2441061 | 2004-07-08 13:14:44 +0000 | [diff] [blame] | 193 | /* Playable space left */ |
Linus Nielsen Feltzing | d34865a | 2005-04-05 11:33:58 +0000 | [diff] [blame] | 194 | scrollbar(0, 6*8, 112, 4, d.audiobuflen, 0, |
Linus Nielsen Feltzing | 2441061 | 2004-07-08 13:14:44 +0000 | [diff] [blame] | 195 | d.playable_space, HORIZONTAL); |
Linus Nielsen Feltzing | bf303de | 2002-10-15 07:23:18 +0000 | [diff] [blame] | 196 | |
Linus Nielsen Feltzing | 2441061 | 2004-07-08 13:14:44 +0000 | [diff] [blame] | 197 | /* Show the watermark limit */ |
Linus Nielsen Feltzing | d34865a | 2005-04-05 11:33:58 +0000 | [diff] [blame] | 198 | scrollbar(0, 6*8+4, 112, 4, d.audiobuflen, 0, |
Linus Nielsen Feltzing | 2441061 | 2004-07-08 13:14:44 +0000 | [diff] [blame] | 199 | d.low_watermark_level, HORIZONTAL); |
Linus Nielsen Feltzing | bf303de | 2002-10-15 07:23:18 +0000 | [diff] [blame] | 200 | |
Linus Nielsen Feltzing | b8ff5f8 | 2002-12-05 13:09:51 +0000 | [diff] [blame] | 201 | snprintf(buf, sizeof(buf), "wm: %x - %x", |
| 202 | d.low_watermark_level, d.lowest_watermark_level); |
Linus Nielsen Feltzing | bf303de | 2002-10-15 07:23:18 +0000 | [diff] [blame] | 203 | lcd_puts(0, 7, buf); |
Linus Nielsen Feltzing | 2f74eaa | 2002-10-14 14:13:48 +0000 | [diff] [blame] | 204 | |
| 205 | lcd_update(); |
| 206 | } |
| 207 | return false; |
| 208 | } |
Linus Nielsen Feltzing | b5a0f70 | 2005-06-22 14:03:04 +0000 | [diff] [blame] | 209 | #else |
| 210 | extern size_t audiobuffer_free; |
Miika Pekkarinen | 159c52d | 2005-08-20 11:13:19 +0000 | [diff] [blame^] | 211 | extern int filebuflen; |
| 212 | extern int filebufused; |
Linus Nielsen Feltzing | 17098e1 | 2005-06-22 20:37:31 +0000 | [diff] [blame] | 213 | extern int track_count; |
Linus Nielsen Feltzing | 2f74eaa | 2002-10-14 14:13:48 +0000 | [diff] [blame] | 214 | |
Linus Nielsen Feltzing | b5a0f70 | 2005-06-22 14:03:04 +0000 | [diff] [blame] | 215 | static int ticks, boost_ticks; |
| 216 | |
| 217 | void dbg_audio_task(void) |
| 218 | { |
| 219 | if(FREQ > CPUFREQ_NORMAL) |
| 220 | boost_ticks++; |
| 221 | |
| 222 | ticks++; |
| 223 | } |
| 224 | |
| 225 | bool dbg_audio_thread(void) |
| 226 | { |
| 227 | char buf[32]; |
| 228 | int button; |
| 229 | int line; |
Linus Nielsen Feltzing | fcc282c | 2005-06-22 14:09:07 +0000 | [diff] [blame] | 230 | bool done = false; |
Miika Pekkarinen | f090dc3 | 2005-07-21 11:44:00 +0000 | [diff] [blame] | 231 | int bufsize = pcmbuf_get_bufsize(); |
Linus Nielsen Feltzing | b5a0f70 | 2005-06-22 14:03:04 +0000 | [diff] [blame] | 232 | |
| 233 | ticks = boost_ticks = 0; |
| 234 | |
| 235 | tick_add_task(dbg_audio_task); |
| 236 | |
| 237 | lcd_setmargins(0, 0); |
Linus Nielsen Feltzing | 44bba0f | 2005-06-22 21:37:00 +0000 | [diff] [blame] | 238 | lcd_setfont(FONT_SYSFIXED); |
Linus Nielsen Feltzing | b5a0f70 | 2005-06-22 14:03:04 +0000 | [diff] [blame] | 239 | |
Linus Nielsen Feltzing | fcc282c | 2005-06-22 14:09:07 +0000 | [diff] [blame] | 240 | while(!done) |
Linus Nielsen Feltzing | b5a0f70 | 2005-06-22 14:03:04 +0000 | [diff] [blame] | 241 | { |
| 242 | button = button_get_w_tmo(HZ/5); |
| 243 | switch(button) |
| 244 | { |
| 245 | case SETTINGS_CANCEL: |
Linus Nielsen Feltzing | fcc282c | 2005-06-22 14:09:07 +0000 | [diff] [blame] | 246 | done = true; |
| 247 | break; |
Linus Nielsen Feltzing | b5a0f70 | 2005-06-22 14:03:04 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | line = 0; |
| 251 | |
| 252 | lcd_clear_display(); |
| 253 | |
Linus Nielsen Feltzing | 17098e1 | 2005-06-22 20:37:31 +0000 | [diff] [blame] | 254 | snprintf(buf, sizeof(buf), "pcm: %d/%d", |
Miika Pekkarinen | f090dc3 | 2005-07-21 11:44:00 +0000 | [diff] [blame] | 255 | bufsize-(int)audiobuffer_free, bufsize); |
Linus Nielsen Feltzing | b5a0f70 | 2005-06-22 14:03:04 +0000 | [diff] [blame] | 256 | lcd_puts(0, line++, buf); |
| 257 | |
| 258 | /* Playable space left */ |
Miika Pekkarinen | f090dc3 | 2005-07-21 11:44:00 +0000 | [diff] [blame] | 259 | scrollbar(0, line*8, LCD_WIDTH, 6, bufsize, 0, |
| 260 | bufsize-audiobuffer_free, HORIZONTAL); |
Linus Nielsen Feltzing | b5a0f70 | 2005-06-22 14:03:04 +0000 | [diff] [blame] | 261 | line++; |
| 262 | |
Miika Pekkarinen | 159c52d | 2005-08-20 11:13:19 +0000 | [diff] [blame^] | 263 | snprintf(buf, sizeof(buf), "codec: %d/%d", filebufused, filebuflen); |
Linus Nielsen Feltzing | b5a0f70 | 2005-06-22 14:03:04 +0000 | [diff] [blame] | 264 | lcd_puts(0, line++, buf); |
| 265 | |
| 266 | /* Playable space left */ |
Miika Pekkarinen | 159c52d | 2005-08-20 11:13:19 +0000 | [diff] [blame^] | 267 | scrollbar(0, line*8, LCD_WIDTH, 6, filebuflen, 0, |
| 268 | filebufused, HORIZONTAL); |
Linus Nielsen Feltzing | b5a0f70 | 2005-06-22 14:03:04 +0000 | [diff] [blame] | 269 | line++; |
| 270 | |
Linus Nielsen Feltzing | 17098e1 | 2005-06-22 20:37:31 +0000 | [diff] [blame] | 271 | snprintf(buf, sizeof(buf), "track count: %d", track_count); |
| 272 | lcd_puts(0, line++, buf); |
| 273 | |
Linus Nielsen Feltzing | b5a0f70 | 2005-06-22 14:03:04 +0000 | [diff] [blame] | 274 | 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 Hohensohn | b218882 | 2003-08-01 08:00:54 +0000 | [diff] [blame] | 290 | |
| 291 | /* Tool function to calculate a CRC16 across some buffer */ |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 292 | unsigned short crc_16(const unsigned char* buf, unsigned len) |
Jörg Hohensohn | b218882 | 2003-08-01 08:00:54 +0000 | [diff] [blame] | 293 | { |
Jörg Hohensohn | f80505c | 2003-08-02 12:53:57 +0000 | [diff] [blame] | 294 | /* CCITT standard polynomial 0x1021 */ |
Jörg Hohensohn | b218882 | 2003-08-01 08:00:54 +0000 | [diff] [blame] | 295 | 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 Arnold | 90cbd3b | 2004-09-28 06:23:57 +0000 | [diff] [blame] | 322 | |
Jörg Hohensohn | b218882 | 2003-08-01 08:00:54 +0000 | [diff] [blame] | 323 | return crc16; |
| 324 | } |
| 325 | |
| 326 | |
Jean-Philippe Bernardy | ed7c635 | 2005-02-08 15:12:25 +0000 | [diff] [blame] | 327 | #if CONFIG_CPU == TCC730 |
Jean-Philippe Bernardy | ed7c635 | 2005-02-08 15:12:25 +0000 | [diff] [blame] | 328 | static unsigned flash_word_temp __attribute__ ((section (".idata"))); |
| 329 | |
| 330 | static void flash_write_word(unsigned addr, unsigned value) __attribute__ ((section(".icode"))); |
| 331 | static void flash_write_word(unsigned addr, unsigned value) { |
| 332 | flash_word_temp = value; |
| 333 | |
| 334 | long extAddr = (long)addr << 1; |
Jean-Philippe Bernardy | 234489a | 2005-02-25 09:19:44 +0000 | [diff] [blame] | 335 | ddma_transfer(1, 1, &flash_word_temp, extAddr, 2); |
Jean-Philippe Bernardy | ed7c635 | 2005-02-08 15:12:25 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | static unsigned flash_read_word(unsigned addr) __attribute__ ((section(".icode"))); |
| 339 | static unsigned flash_read_word(unsigned addr) { |
| 340 | long extAddr = (long)addr << 1; |
Jean-Philippe Bernardy | 234489a | 2005-02-25 09:19:44 +0000 | [diff] [blame] | 341 | ddma_transfer(1, 1, &flash_word_temp, extAddr, 2); |
Jean-Philippe Bernardy | ed7c635 | 2005-02-08 15:12:25 +0000 | [diff] [blame] | 342 | return flash_word_temp; |
| 343 | } |
| 344 | |
| 345 | #endif |
| 346 | |
Jörg Hohensohn | b218882 | 2003-08-01 08:00:54 +0000 | [diff] [blame] | 347 | |
Jörg Hohensohn | ceba6f8 | 2003-05-17 20:40:30 +0000 | [diff] [blame] | 348 | /* 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 Hohensohn | 5846aab | 2004-07-19 21:21:34 +0000 | [diff] [blame] | 351 | /* In IRAM to avoid problems when running directly from Flash */ |
Jens Arnold | 4c7da88 | 2005-06-18 01:25:47 +0000 | [diff] [blame] | 352 | bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device, |
Jörg Hohensohn | 5846aab | 2004-07-19 21:21:34 +0000 | [diff] [blame] | 353 | unsigned addr1, unsigned addr2) |
| 354 | __attribute__ ((section (".icode"))); |
| 355 | bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device, |
| 356 | unsigned addr1, unsigned addr2) |
| 357 | |
Jörg Hohensohn | ceba6f8 | 2003-05-17 20:40:30 +0000 | [diff] [blame] | 358 | { |
| 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 Bernardy | ed7c635 | 2005-02-08 15:12:25 +0000 | [diff] [blame] | 361 | #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 Hohensohn | ceba6f8 | 2003-05-17 20:40:30 +0000 | [diff] [blame] | 365 | volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */ |
Jean-Philippe Bernardy | ed7c635 | 2005-02-08 15:12:25 +0000 | [diff] [blame] | 366 | #define FLASH(addr) (flash[addr]) |
| 367 | #define SET_FLASH(addr, val) (flash[addr] = val) |
| 368 | |
| 369 | #endif |
Jörg Hohensohn | 5846aab | 2004-07-19 21:21:34 +0000 | [diff] [blame] | 370 | int old_level; /* saved interrupt level */ |
Jörg Hohensohn | ceba6f8 | 2003-05-17 20:40:30 +0000 | [diff] [blame] | 371 | |
Jean-Philippe Bernardy | ed7c635 | 2005-02-08 15:12:25 +0000 | [diff] [blame] | 372 | 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 Hohensohn | ceba6f8 | 2003-05-17 20:40:30 +0000 | [diff] [blame] | 374 | |
Jörg Hohensohn | 5846aab | 2004-07-19 21:21:34 +0000 | [diff] [blame] | 375 | /* disable interrupts, prevent any stray flash access */ |
| 376 | old_level = set_irq_level(HIGHEST_IRQ_LEVEL); |
| 377 | |
Jean-Philippe Bernardy | ed7c635 | 2005-02-08 15:12:25 +0000 | [diff] [blame] | 378 | SET_FLASH(addr1, 0xAA); /* enter command mode */ |
| 379 | SET_FLASH(addr2, 0x55); |
| 380 | SET_FLASH(addr1, 0x90); /* ID command */ |
Jörg Hohensohn | 5846aab | 2004-07-19 21:21:34 +0000 | [diff] [blame] | 381 | /* Atmel wants 20ms pause here */ |
| 382 | /* sleep(HZ/50); no sleeping possible while interrupts are disabled */ |
Jörg Hohensohn | ceba6f8 | 2003-05-17 20:40:30 +0000 | [diff] [blame] | 383 | |
Jean-Philippe Bernardy | ed7c635 | 2005-02-08 15:12:25 +0000 | [diff] [blame] | 384 | manu = FLASH(0); /* read the IDs */ |
| 385 | id = FLASH(1); |
Jörg Hohensohn | ceba6f8 | 2003-05-17 20:40:30 +0000 | [diff] [blame] | 386 | |
Jean-Philippe Bernardy | ed7c635 | 2005-02-08 15:12:25 +0000 | [diff] [blame] | 387 | SET_FLASH(0, 0xF0); /* reset flash (back to normal read mode) */ |
Jörg Hohensohn | 5846aab | 2004-07-19 21:21:34 +0000 | [diff] [blame] | 388 | /* 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 Hohensohn | ceba6f8 | 2003-05-17 20:40:30 +0000 | [diff] [blame] | 392 | |
| 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 Feltzing | 2f74eaa | 2002-10-14 14:13:48 +0000 | [diff] [blame] | 406 | #ifdef HAVE_LCD_BITMAP |
Linus Nielsen Feltzing | 91b26f2 | 2002-10-08 10:52:46 +0000 | [diff] [blame] | 407 | bool dbg_hw_info(void) |
| 408 | { |
Daniel Stenberg | 1d395ae | 2005-02-02 21:57:40 +0000 | [diff] [blame] | 409 | #if CONFIG_CPU == SH7034 |
Linus Nielsen Feltzing | 91b26f2 | 2002-10-08 10:52:46 +0000 | [diff] [blame] | 410 | char buf[32]; |
| 411 | int button; |
| 412 | int usb_polarity; |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 413 | int pr_polarity; |
Linus Nielsen Feltzing | 3cfc6ec | 2002-10-08 11:15:00 +0000 | [diff] [blame] | 414 | int bitmask = *(unsigned short*)0x20000fc; |
Linus Nielsen Feltzing | 91b26f2 | 2002-10-08 10:52:46 +0000 | [diff] [blame] | 415 | int rom_version = *(unsigned short*)0x20000fe; |
Jörg Hohensohn | ceba6f8 | 2003-05-17 20:40:30 +0000 | [diff] [blame] | 416 | unsigned manu, id; /* flash IDs */ |
| 417 | bool got_id; /* flag if we managed to get the flash IDs */ |
Jörg Hohensohn | d8b3181 | 2003-10-29 22:10:13 +0000 | [diff] [blame] | 418 | unsigned rom_crc = 0xFFFF; /* CRC16 of the boot ROM */ |
| 419 | bool has_bootrom; /* flag for boot ROM present */ |
Jens Arnold | 06cb237 | 2004-08-30 19:52:45 +0000 | [diff] [blame] | 420 | int oldmode; /* saved memory guard mode */ |
Linus Nielsen Feltzing | 91b26f2 | 2002-10-08 10:52:46 +0000 | [diff] [blame] | 421 | |
Jens Arnold | 4c428e0 | 2004-10-01 20:21:17 +0000 | [diff] [blame] | 422 | #ifdef USB_ENABLE_ONDIOSTYLE |
Jens Arnold | d89b75b | 2005-05-08 12:16:46 +0000 | [diff] [blame] | 423 | if(PADRL & 0x20) |
Jens Arnold | 4c428e0 | 2004-10-01 20:21:17 +0000 | [diff] [blame] | 424 | #else |
Jens Arnold | d89b75b | 2005-05-08 12:16:46 +0000 | [diff] [blame] | 425 | if(PADRH & 0x04) |
Jens Arnold | 4c428e0 | 2004-10-01 20:21:17 +0000 | [diff] [blame] | 426 | #endif |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 427 | usb_polarity = 0; /* Negative */ |
Linus Nielsen Feltzing | 91b26f2 | 2002-10-08 10:52:46 +0000 | [diff] [blame] | 428 | else |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 429 | usb_polarity = 1; /* Positive */ |
Linus Nielsen Feltzing | 91b26f2 | 2002-10-08 10:52:46 +0000 | [diff] [blame] | 430 | |
Jens Arnold | d89b75b | 2005-05-08 12:16:46 +0000 | [diff] [blame] | 431 | if(PADRH & 0x08) |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 432 | pr_polarity = 0; /* Negative */ |
| 433 | else |
| 434 | pr_polarity = 1; /* Positive */ |
Linus Nielsen Feltzing | 07083fb | 2002-10-09 06:36:32 +0000 | [diff] [blame] | 435 | |
Jens Arnold | 06cb237 | 2004-08-30 19:52:45 +0000 | [diff] [blame] | 436 | oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */ |
| 437 | |
Jörg Hohensohn | ceba6f8 | 2003-05-17 20:40:30 +0000 | [diff] [blame] | 438 | /* 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 Hohensohn | d8b3181 | 2003-10-29 22:10:13 +0000 | [diff] [blame] | 443 | /* 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 Hohensohn | b218882 | 2003-08-01 08:00:54 +0000 | [diff] [blame] | 450 | |
Jens Arnold | 06cb237 | 2004-08-30 19:52:45 +0000 | [diff] [blame] | 451 | system_memory_guard(oldmode); /* re-enable memory guard */ |
| 452 | |
Linus Nielsen Feltzing | 91b26f2 | 2002-10-08 10:52:46 +0000 | [diff] [blame] | 453 | lcd_setmargins(0, 0); |
| 454 | lcd_setfont(FONT_SYSFIXED); |
| 455 | lcd_clear_display(); |
| 456 | |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 457 | lcd_puts(0, 0, "[Hardware info]"); |
| 458 | |
Linus Nielsen Feltzing | 91b26f2 | 2002-10-08 10:52:46 +0000 | [diff] [blame] | 459 | snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100); |
| 460 | lcd_puts(0, 1, buf); |
| 461 | |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 462 | snprintf(buf, 32, "Mask: 0x%04x", bitmask); |
Linus Nielsen Feltzing | 91b26f2 | 2002-10-08 10:52:46 +0000 | [diff] [blame] | 463 | lcd_puts(0, 2, buf); |
| 464 | |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 465 | snprintf(buf, 32, "USB: %s", usb_polarity?"positive":"negative"); |
Linus Nielsen Feltzing | 91b26f2 | 2002-10-08 10:52:46 +0000 | [diff] [blame] | 466 | lcd_puts(0, 3, buf); |
| 467 | |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 468 | snprintf(buf, 32, "PR: %s", pr_polarity?"positive":"negative"); |
Jörg Hohensohn | 099ef22 | 2004-10-22 20:44:26 +0000 | [diff] [blame] | 469 | lcd_puts(0, 4, buf); |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 470 | |
Jörg Hohensohn | ceba6f8 | 2003-05-17 20:40:30 +0000 | [diff] [blame] | 471 | 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 Hohensohn | 099ef22 | 2004-10-22 20:44:26 +0000 | [diff] [blame] | 475 | lcd_puts(0, 5, buf); |
Jörg Hohensohn | b218882 | 2003-08-01 08:00:54 +0000 | [diff] [blame] | 476 | |
Jörg Hohensohn | d8b3181 | 2003-10-29 22:10:13 +0000 | [diff] [blame] | 477 | 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 Hohensohn | 099ef22 | 2004-10-22 20:44:26 +0000 | [diff] [blame] | 487 | 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 Hohensohn | b218882 | 2003-08-01 08:00:54 +0000 | [diff] [blame] | 492 | lcd_puts(0, 7, buf); |
Jörg Hohensohn | 099ef22 | 2004-10-22 20:44:26 +0000 | [diff] [blame] | 493 | #endif |
Linus Nielsen Feltzing | 91b26f2 | 2002-10-08 10:52:46 +0000 | [diff] [blame] | 494 | lcd_update(); |
Linus Nielsen Feltzing | 46a94be | 2002-10-14 14:25:25 +0000 | [diff] [blame] | 495 | |
| 496 | while(1) |
| 497 | { |
| 498 | button = button_get(true); |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 499 | if(button == SETTINGS_CANCEL) |
Linus Nielsen Feltzing | 46a94be | 2002-10-14 14:25:25 +0000 | [diff] [blame] | 500 | return false; |
| 501 | } |
Daniel Stenberg | 1d395ae | 2005-02-02 21:57:40 +0000 | [diff] [blame] | 502 | #endif /* CONFIG_CPU == SH7034 */ |
Linus Nielsen Feltzing | 91b26f2 | 2002-10-08 10:52:46 +0000 | [diff] [blame] | 503 | return false; |
| 504 | } |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 505 | #else |
| 506 | bool 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 Hohensohn | 09d1a73 | 2003-05-20 21:30:53 +0000 | [diff] [blame] | 514 | unsigned manu, id; /* flash IDs */ |
| 515 | bool got_id; /* flag if we managed to get the flash IDs */ |
Jörg Hohensohn | d8b3181 | 2003-10-29 22:10:13 +0000 | [diff] [blame] | 516 | unsigned rom_crc = 0xFFFF; /* CRC16 of the boot ROM */ |
| 517 | bool has_bootrom; /* flag for boot ROM present */ |
Jens Arnold | 06cb237 | 2004-08-30 19:52:45 +0000 | [diff] [blame] | 518 | int oldmode; /* saved memory guard mode */ |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 519 | |
Jens Arnold | d89b75b | 2005-05-08 12:16:46 +0000 | [diff] [blame] | 520 | if(PADRH & 0x04) |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 521 | usb_polarity = 0; /* Negative */ |
| 522 | else |
| 523 | usb_polarity = 1; /* Positive */ |
| 524 | |
Jens Arnold | 06cb237 | 2004-08-30 19:52:45 +0000 | [diff] [blame] | 525 | oldmode = system_memory_guard(MEMGUARD_NONE); /* disable memory guard */ |
| 526 | |
Jörg Hohensohn | 09d1a73 | 2003-05-20 21:30:53 +0000 | [diff] [blame] | 527 | /* 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 Hohensohn | d8b3181 | 2003-10-29 22:10:13 +0000 | [diff] [blame] | 532 | /* 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 Arnold | 06cb237 | 2004-08-30 19:52:45 +0000 | [diff] [blame] | 539 | |
| 540 | system_memory_guard(oldmode); /* re-enable memory guard */ |
Jörg Hohensohn | b218882 | 2003-08-01 08:00:54 +0000 | [diff] [blame] | 541 | |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 542 | 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 Stenberg | ee192fb | 2003-08-05 13:39:38 +0000 | [diff] [blame] | 558 | snprintf(buf, 32, "ATA: 0x%x%s", |
Björn Stenberg | 8abc9d4 | 2003-08-05 13:41:00 +0000 | [diff] [blame] | 559 | ata_io_address, ata_device ? "s":"m"); |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 560 | break; |
| 561 | case 3: |
| 562 | snprintf(buf, 32, "Mask: %04x", bitmask); |
| 563 | break; |
Jörg Hohensohn | 09d1a73 | 2003-05-20 21:30:53 +0000 | [diff] [blame] | 564 | 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 Hohensohn | b218882 | 2003-08-01 08:00:54 +0000 | [diff] [blame] | 570 | case 5: |
Jörg Hohensohn | d8b3181 | 2003-10-29 22:10:13 +0000 | [diff] [blame] | 571 | if (has_bootrom) |
| 572 | snprintf(buf, 32, "RomCRC:%04x", rom_crc); |
| 573 | else |
| 574 | snprintf(buf, 32, "BootROM: no"); |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Linus Nielsen Feltzing | 07083fb | 2002-10-09 06:36:32 +0000 | [diff] [blame] | 577 | lcd_puts(0, 1, buf); |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 578 | lcd_update(); |
| 579 | |
| 580 | button = button_get(true); |
| 581 | |
| 582 | switch(button) |
| 583 | { |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 584 | case SETTINGS_CANCEL: |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 585 | return false; |
| 586 | |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 587 | case SETTINGS_DEC: |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 588 | currval--; |
| 589 | if(currval < 0) |
Jörg Hohensohn | b218882 | 2003-08-01 08:00:54 +0000 | [diff] [blame] | 590 | currval = 5; |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 591 | break; |
| 592 | |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 593 | case SETTINGS_INC: |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 594 | currval++; |
Jörg Hohensohn | b218882 | 2003-08-01 08:00:54 +0000 | [diff] [blame] | 595 | if(currval > 5) |
Linus Nielsen Feltzing | 1e972b5 | 2002-10-08 12:08:30 +0000 | [diff] [blame] | 596 | currval = 0; |
| 597 | break; |
| 598 | } |
| 599 | } |
| 600 | return false; |
| 601 | } |
Linus Nielsen Feltzing | 91b26f2 | 2002-10-08 10:52:46 +0000 | [diff] [blame] | 602 | #endif |
| 603 | |
Björn Stenberg | 4d55c2f | 2002-10-10 12:01:58 +0000 | [diff] [blame] | 604 | bool 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 Stenberg | f09c5f4 | 2002-12-03 14:18:51 +0000 | [diff] [blame] | 612 | sleep(HZ/2); |
Björn Stenberg | 4d55c2f | 2002-10-10 12:01:58 +0000 | [diff] [blame] | 613 | |
| 614 | while(1) |
| 615 | { |
| 616 | char buf[32]; |
| 617 | int button; |
| 618 | struct partinfo* p = disk_partinfo(partition); |
| 619 | |
| 620 | lcd_clear_display(); |
Jens Arnold | 6baa55a | 2005-01-24 01:39:24 +0000 | [diff] [blame] | 621 | snprintf(buf, sizeof buf, "P%d: S:%lx", partition, p->start); |
Björn Stenberg | 4d55c2f | 2002-10-10 12:01:58 +0000 | [diff] [blame] | 622 | lcd_puts(0, 0, buf); |
Jens Arnold | 6baa55a | 2005-01-24 01:39:24 +0000 | [diff] [blame] | 623 | snprintf(buf, sizeof buf, "T:%x %ld MB", p->type, p->size / 2048); |
Björn Stenberg | 4d55c2f | 2002-10-10 12:01:58 +0000 | [diff] [blame] | 624 | lcd_puts(0, 1, buf); |
| 625 | lcd_update(); |
| 626 | |
| 627 | button = button_get(true); |
| 628 | |
| 629 | switch(button) |
| 630 | { |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 631 | case SETTINGS_OK: |
| 632 | case SETTINGS_CANCEL: |
Björn Stenberg | 4d55c2f | 2002-10-10 12:01:58 +0000 | [diff] [blame] | 633 | return false; |
| 634 | |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 635 | case SETTINGS_DEC: |
Björn Stenberg | 4d55c2f | 2002-10-10 12:01:58 +0000 | [diff] [blame] | 636 | partition--; |
| 637 | if (partition < 0) |
| 638 | partition = 3; |
| 639 | break; |
| 640 | |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 641 | case SETTINGS_INC: |
Björn Stenberg | 4d55c2f | 2002-10-10 12:01:58 +0000 | [diff] [blame] | 642 | partition++; |
| 643 | if (partition > 3) |
| 644 | partition = 0; |
| 645 | break; |
Linus Nielsen Feltzing | ade5d7b | 2004-07-26 16:06:59 +0000 | [diff] [blame] | 646 | |
| 647 | default: |
| 648 | if(default_event_handler(button) == SYS_USB_CONNECTED) |
| 649 | return true; |
| 650 | break; |
Björn Stenberg | 4d55c2f | 2002-10-10 12:01:58 +0000 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | return false; |
| 654 | } |
| 655 | |
Linus Nielsen Feltzing | 3c82b84 | 2005-07-18 18:28:49 +0000 | [diff] [blame] | 656 | #ifdef CPU_COLDFIRE |
| 657 | bool 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 Feltzing | 91b26f2 | 2002-10-08 10:52:46 +0000 | [diff] [blame] | 817 | #ifdef HAVE_LCD_BITMAP |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 818 | /* Test code!!! */ |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 819 | bool dbg_ports(void) |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 820 | { |
Daniel Stenberg | 1d395ae | 2005-02-02 21:57:40 +0000 | [diff] [blame] | 821 | #if CONFIG_CPU == SH7034 |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 822 | 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 Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 829 | |
Markus Braun | a0300f5 | 2002-08-20 22:13:20 +0000 | [diff] [blame] | 830 | #ifdef HAVE_LCD_BITMAP |
Linus Nielsen Feltzing | f22eeee | 2005-08-14 08:43:05 +0000 | [diff] [blame] | 831 | lcd_setfont(FONT_SYSFIXED); |
Markus Braun | a0300f5 | 2002-08-20 22:13:20 +0000 | [diff] [blame] | 832 | lcd_setmargins(0, 0); |
| 833 | #endif |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 834 | 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 Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 856 | battery_voltage = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000; |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 857 | 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 Hohensohn | 099ef22 | 2004-10-22 20:44:26 +0000 | [diff] [blame] | 863 | #ifndef HAVE_MMC /* have ATA */ |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 864 | snprintf(buf, 32, "ATA: %s, 0x%x", |
| 865 | ata_device?"slave":"master", ata_io_address); |
| 866 | lcd_puts(0, 7, buf); |
Jörg Hohensohn | 099ef22 | 2004-10-22 20:44:26 +0000 | [diff] [blame] | 867 | #endif |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 868 | lcd_update(); |
Linus Nielsen Feltzing | 0a74476 | 2003-04-09 23:17:35 +0000 | [diff] [blame] | 869 | button = button_get_w_tmo(HZ/10); |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 870 | |
| 871 | switch(button) |
| 872 | { |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 873 | case SETTINGS_CANCEL: |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 874 | return false; |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 875 | } |
| 876 | } |
Christian Gmeiner | c6ff1f5 | 2005-07-18 12:40:29 +0000 | [diff] [blame] | 877 | #elif defined(CPU_COLDFIRE) |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 878 | 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 Feltzing | aceef07 | 2005-03-01 14:40:27 +0000 | [diff] [blame] | 887 | char buf[128]; |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 888 | int button; |
| 889 | int line; |
Linus Nielsen Feltzing | 43bf39e | 2005-04-06 23:53:19 +0000 | [diff] [blame] | 890 | int battery_voltage; |
| 891 | int batt_int, batt_frac; |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 892 | |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 893 | lcd_setmargins(0, 0); |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 894 | 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 Feltzing | aceef07 | 2005-03-01 14:40:27 +0000 | [diff] [blame] | 909 | snprintf(buf, sizeof(buf), "GPIO_READ: %08x", gpio_read); |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 910 | lcd_puts(0, line++, buf); |
Linus Nielsen Feltzing | aceef07 | 2005-03-01 14:40:27 +0000 | [diff] [blame] | 911 | snprintf(buf, sizeof(buf), "GPIO_OUT: %08x", gpio_out); |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 912 | lcd_puts(0, line++, buf); |
Linus Nielsen Feltzing | aceef07 | 2005-03-01 14:40:27 +0000 | [diff] [blame] | 913 | snprintf(buf, sizeof(buf), "GPIO_FUNCTION: %08x", gpio_function); |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 914 | lcd_puts(0, line++, buf); |
Linus Nielsen Feltzing | aceef07 | 2005-03-01 14:40:27 +0000 | [diff] [blame] | 915 | snprintf(buf, sizeof(buf), "GPIO_ENABLE: %08x", gpio_enable); |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 916 | lcd_puts(0, line++, buf); |
| 917 | |
Linus Nielsen Feltzing | aceef07 | 2005-03-01 14:40:27 +0000 | [diff] [blame] | 918 | snprintf(buf, sizeof(buf), "GPIO1_READ: %08x", gpio1_read); |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 919 | lcd_puts(0, line++, buf); |
Linus Nielsen Feltzing | aceef07 | 2005-03-01 14:40:27 +0000 | [diff] [blame] | 920 | snprintf(buf, sizeof(buf), "GPIO1_OUT: %08x", gpio1_out); |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 921 | lcd_puts(0, line++, buf); |
Linus Nielsen Feltzing | aceef07 | 2005-03-01 14:40:27 +0000 | [diff] [blame] | 922 | snprintf(buf, sizeof(buf), "GPIO1_FUNCTION: %08x", gpio1_function); |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 923 | lcd_puts(0, line++, buf); |
Linus Nielsen Feltzing | aceef07 | 2005-03-01 14:40:27 +0000 | [diff] [blame] | 924 | snprintf(buf, sizeof(buf), "GPIO1_ENABLE: %08x", gpio1_enable); |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 925 | 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 Feltzing | aceef07 | 2005-03-01 14:40:27 +0000 | [diff] [blame] | 931 | snprintf(buf, sizeof(buf), "ADC_BUTTONS: %02x", adc_buttons); |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 932 | lcd_puts(0, line++, buf); |
Linus Nielsen Feltzing | aceef07 | 2005-03-01 14:40:27 +0000 | [diff] [blame] | 933 | snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote); |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 934 | lcd_puts(0, line++, buf); |
Linus Nielsen Feltzing | aceef07 | 2005-03-01 14:40:27 +0000 | [diff] [blame] | 935 | snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_battery); |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 936 | lcd_puts(0, line++, buf); |
| 937 | |
Linus Nielsen Feltzing | 43bf39e | 2005-04-06 23:53:19 +0000 | [diff] [blame] | 938 | 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 Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 946 | 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 Stenberg | 1d395ae | 2005-02-02 21:57:40 +0000 | [diff] [blame] | 956 | #endif /* CONFIG_CPU == SH7034 */ |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 957 | return false; |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 958 | } |
| 959 | #else |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 960 | bool dbg_ports(void) |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 961 | { |
| 962 | unsigned short porta; |
| 963 | unsigned short portb; |
| 964 | unsigned char portc; |
| 965 | char buf[32]; |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 966 | 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 Hak | 50fc3ce | 2002-08-10 08:52:11 +0000 | [diff] [blame] | 981 | 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 Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 1015 | } |
| 1016 | lcd_puts(0, 0, buf); |
| 1017 | |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1018 | battery_voltage = (adc_read(ADC_UNREG_POWER) * |
| 1019 | BATTERY_SCALE_FACTOR) / 10000; |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 1020 | 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 Stenberg | f09c5f4 | 2002-12-03 14:18:51 +0000 | [diff] [blame] | 1026 | button = button_get_w_tmo(HZ/5); |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 1027 | |
| 1028 | switch(button) |
| 1029 | { |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 1030 | case SETTINGS_CANCEL: |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 1031 | return false; |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 1032 | |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 1033 | case SETTINGS_DEC: |
Robert Hak | 50fc3ce | 2002-08-10 08:52:11 +0000 | [diff] [blame] | 1034 | currval--; |
| 1035 | if(currval < 0) |
Linus Nielsen Feltzing | 41977da | 2002-08-14 08:04:42 +0000 | [diff] [blame] | 1036 | currval = 10; |
Robert Hak | 50fc3ce | 2002-08-10 08:52:11 +0000 | [diff] [blame] | 1037 | break; |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 1038 | |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 1039 | case SETTINGS_INC: |
Robert Hak | 50fc3ce | 2002-08-10 08:52:11 +0000 | [diff] [blame] | 1040 | currval++; |
Linus Nielsen Feltzing | 41977da | 2002-08-14 08:04:42 +0000 | [diff] [blame] | 1041 | if(currval > 10) |
Robert Hak | 50fc3ce | 2002-08-10 08:52:11 +0000 | [diff] [blame] | 1042 | currval = 0; |
| 1043 | break; |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 1044 | } |
| 1045 | } |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 1046 | return false; |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 1047 | } |
| 1048 | #endif |
| 1049 | |
Linus Nielsen Feltzing | 213d34e | 2005-03-07 10:51:43 +0000 | [diff] [blame] | 1050 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
| 1051 | extern int boost_counter; |
| 1052 | bool 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 Feltzing | 57d8e8f | 2005-08-18 07:16:53 +0000 | [diff] [blame] | 1060 | lcd_setfont(FONT_SYSFIXED); |
Linus Nielsen Feltzing | 213d34e | 2005-03-07 10:51:43 +0000 | [diff] [blame] | 1061 | #endif |
| 1062 | lcd_clear_display(); |
Linus Nielsen Feltzing | 213d34e | 2005-03-07 10:51:43 +0000 | [diff] [blame] | 1063 | |
| 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 Feltzing | c71db25 | 2005-03-07 13:02:06 +0000 | [diff] [blame] | 1086 | |
Daniel Stenberg | 01377e2 | 2005-06-29 12:47:24 +0000 | [diff] [blame] | 1087 | #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ |
| 1088 | (CONFIG_KEYPAD == IRIVER_H300_PAD) |
Linus Nielsen Feltzing | 213d34e | 2005-03-07 10:51:43 +0000 | [diff] [blame] | 1089 | case BUTTON_SELECT: |
Linus Nielsen Feltzing | c71db25 | 2005-03-07 13:02:06 +0000 | [diff] [blame] | 1090 | #else |
| 1091 | case BUTTON_PLAY: |
| 1092 | #endif |
Linus Nielsen Feltzing | 213d34e | 2005-03-07 10:51:43 +0000 | [diff] [blame] | 1093 | set_cpu_frequency(CPUFREQ_DEFAULT); |
| 1094 | boost_counter = 0; |
| 1095 | break; |
| 1096 | |
| 1097 | case SETTINGS_CANCEL: |
Linus Nielsen Feltzing | 3c82b84 | 2005-07-18 18:28:49 +0000 | [diff] [blame] | 1098 | case SETTINGS_OK2: |
Linus Nielsen Feltzing | 213d34e | 2005-03-07 10:51:43 +0000 | [diff] [blame] | 1099 | return false; |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | return false; |
| 1104 | } |
| 1105 | #endif |
Jens Arnold | 4ddb320 | 2005-05-06 21:55:34 +0000 | [diff] [blame] | 1106 | |
Björn Stenberg | b47e64e | 2002-08-08 20:44:25 +0000 | [diff] [blame] | 1107 | #ifdef HAVE_LCD_BITMAP |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1108 | /* |
| 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 Hohensohn | 2584896 | 2005-03-03 07:25:43 +0000 | [diff] [blame] | 1114 | #define BAT_LAST_VAL MIN(LCD_WIDTH, POWER_HISTORY_LEN) |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1115 | #define BAT_YSPACE (LCD_HEIGHT - 20) |
| 1116 | |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 1117 | bool view_battery(void) |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1118 | { |
| 1119 | int view = 0; |
| 1120 | int i, x, y; |
Jean-Philippe Bernardy | ed7c635 | 2005-02-08 15:12:25 +0000 | [diff] [blame] | 1121 | unsigned short maxv, minv; |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1122 | char buf[32]; |
| 1123 | |
Markus Braun | a0300f5 | 2002-08-20 22:13:20 +0000 | [diff] [blame] | 1124 | #ifdef HAVE_LCD_BITMAP |
| 1125 | lcd_setmargins(0, 0); |
Linus Nielsen Feltzing | f22eeee | 2005-08-14 08:43:05 +0000 | [diff] [blame] | 1126 | lcd_setfont(FONT_SYSFIXED); |
Markus Braun | a0300f5 | 2002-08-20 22:13:20 +0000 | [diff] [blame] | 1127 | #endif |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1128 | while(1) |
| 1129 | { |
| 1130 | switch (view) { |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1131 | case 0: /* voltage history graph */ |
| 1132 | /* Find maximum and minimum voltage for scaling */ |
Jörg Hohensohn | 2584896 | 2005-03-03 07:25:43 +0000 | [diff] [blame] | 1133 | maxv = 0; |
| 1134 | minv = 65535; |
| 1135 | for (i = 0; i < BAT_LAST_VAL; i++) { |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1136 | if (power_history[i] > maxv) |
| 1137 | maxv = power_history[i]; |
Jörg Hohensohn | 2584896 | 2005-03-03 07:25:43 +0000 | [diff] [blame] | 1138 | if (power_history[i] && (power_history[i] < minv)) |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1139 | { |
| 1140 | minv = power_history[i]; |
| 1141 | } |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
Jörg Hohensohn | 2584896 | 2005-03-03 07:25:43 +0000 | [diff] [blame] | 1144 | if ((minv < 1) || (minv >= 65535)) |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1145 | minv = 1; |
| 1146 | if (maxv < 2) |
| 1147 | maxv = 2; |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1148 | |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1149 | lcd_clear_display(); |
Jörg Hohensohn | 2584896 | 2005-03-03 07:25:43 +0000 | [diff] [blame] | 1150 | snprintf(buf, 30, "Battery %d.%02d", power_history[0] / 100, |
| 1151 | power_history[0] % 100); |
| 1152 | lcd_puts(0, 0, buf); |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1153 | 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 Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1156 | |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1157 | x = 0; |
Jörg Hohensohn | 2584896 | 2005-03-03 07:25:43 +0000 | [diff] [blame] | 1158 | for (i = BAT_LAST_VAL - 1; i >= 0; i--) { |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1159 | y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv); |
Jens Arnold | 04daef1 | 2005-06-24 22:33:21 +0000 | [diff] [blame] | 1160 | lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); |
Jens Arnold | 9349412 | 2005-06-25 00:28:09 +0000 | [diff] [blame] | 1161 | lcd_vline(x, LCD_HEIGHT-1, 20); |
Jens Arnold | 04daef1 | 2005-06-24 22:33:21 +0000 | [diff] [blame] | 1162 | lcd_set_drawmode(DRMODE_SOLID); |
Jens Arnold | 9349412 | 2005-06-25 00:28:09 +0000 | [diff] [blame] | 1163 | lcd_vline(x, LCD_HEIGHT-1, |
| 1164 | MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1)); |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1165 | x++; |
| 1166 | } |
| 1167 | |
| 1168 | break; |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1169 | |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1170 | case 1: /* status: */ |
| 1171 | lcd_clear_display(); |
| 1172 | lcd_puts(0, 0, "Power status:"); |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1173 | |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1174 | 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 Arnold | 303b4ab | 2004-12-01 00:33:18 +0000 | [diff] [blame] | 1177 | #ifdef ADC_EXT_POWER |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1178 | 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 Arnold | 303b4ab | 2004-12-01 00:33:18 +0000 | [diff] [blame] | 1181 | #endif |
| 1182 | #ifdef HAVE_CHARGING |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1183 | snprintf(buf, 30, "Charger: %s", |
| 1184 | charger_inserted() ? "present" : "absent"); |
| 1185 | lcd_puts(0, 3, buf); |
Jörg Hohensohn | 2584896 | 2005-03-03 07:25:43 +0000 | [diff] [blame] | 1186 | #endif |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1187 | #ifdef HAVE_CHARGE_CTRL |
Michiel Van Der Kolk | 9d2531a | 2005-03-28 00:47:09 +0000 | [diff] [blame] | 1188 | snprintf(buf, 30, "Chgr: %s %s", |
| 1189 | charger_inserted() ? "present" : "absent", |
| 1190 | charger_enabled ? "on" : "off"); |
| 1191 | lcd_puts(0, 3, buf); |
Jörg Hohensohn | 2584896 | 2005-03-03 07:25:43 +0000 | [diff] [blame] | 1192 | snprintf(buf, 30, "short delta: %d", short_delta); |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1193 | lcd_puts(0, 5, buf); |
Jörg Hohensohn | 2584896 | 2005-03-03 07:25:43 +0000 | [diff] [blame] | 1194 | snprintf(buf, 30, "long delta: %d", long_delta); |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1195 | lcd_puts(0, 6, buf); |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1196 | lcd_puts(0, 7, power_message); |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1197 | #endif |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1198 | break; |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1199 | |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1200 | case 2: /* voltage deltas: */ |
| 1201 | lcd_clear_display(); |
| 1202 | lcd_puts(0, 0, "Voltage deltas:"); |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1203 | |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1204 | for (i = 0; i <= 6; i++) { |
Jörg Hohensohn | 2584896 | 2005-03-03 07:25:43 +0000 | [diff] [blame] | 1205 | y = power_history[i] - power_history[i+i]; |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1206 | 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 Stenberg | f09c5f4 | 2002-12-03 14:18:51 +0000 | [diff] [blame] | 1212 | |
Michiel Van Der Kolk | 9d2531a | 2005-03-28 00:47:09 +0000 | [diff] [blame] | 1213 | case 3: /* remaining time estimation: */ |
Björn Stenberg | f09c5f4 | 2002-12-03 14:18:51 +0000 | [diff] [blame] | 1214 | lcd_clear_display(); |
Uwe Freese | c83374b | 2002-12-15 18:10:19 +0000 | [diff] [blame] | 1215 | |
Uwe Freese | 5e44a56 | 2003-02-12 22:21:07 +0000 | [diff] [blame] | 1216 | #ifdef HAVE_CHARGE_CTRL |
Uwe Freese | c83374b | 2002-12-15 18:10:19 +0000 | [diff] [blame] | 1217 | snprintf(buf, 30, "charge_state: %d", charge_state); |
| 1218 | lcd_puts(0, 0, buf); |
| 1219 | |
Björn Stenberg | f09c5f4 | 2002-12-03 14:18:51 +0000 | [diff] [blame] | 1220 | snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min); |
| 1221 | lcd_puts(0, 1, buf); |
| 1222 | |
Jörg Hohensohn | 2584896 | 2005-03-03 07:25:43 +0000 | [diff] [blame] | 1223 | snprintf(buf, 30, "Lvl@cyc st: %d%%", powermgmt_last_cycle_level); |
Björn Stenberg | f09c5f4 | 2002-12-03 14:18:51 +0000 | [diff] [blame] | 1224 | lcd_puts(0, 2, buf); |
Michiel Van Der Kolk | 9d2531a | 2005-03-28 00:47:09 +0000 | [diff] [blame] | 1225 | |
| 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 Freese | 5e44a56 | 2003-02-12 22:21:07 +0000 | [diff] [blame] | 1231 | #endif |
Björn Stenberg | f09c5f4 | 2002-12-03 14:18:51 +0000 | [diff] [blame] | 1232 | |
Jörg Hohensohn | 2584896 | 2005-03-03 07:25:43 +0000 | [diff] [blame] | 1233 | snprintf(buf, 30, "Last PwrHist: %d.%02d V", |
| 1234 | power_history[0] / 100, |
| 1235 | power_history[0] % 100); |
Michiel Van Der Kolk | 451dd48 | 2005-03-28 00:00:24 +0000 | [diff] [blame] | 1236 | lcd_puts(0, 5, buf); |
Björn Stenberg | f09c5f4 | 2002-12-03 14:18:51 +0000 | [diff] [blame] | 1237 | |
Michiel Van Der Kolk | 9d2531a | 2005-03-28 00:47:09 +0000 | [diff] [blame] | 1238 | snprintf(buf, 30, "battery level: %d%%", battery_level()); |
Michiel Van Der Kolk | 451dd48 | 2005-03-28 00:00:24 +0000 | [diff] [blame] | 1239 | lcd_puts(0, 6, buf); |
| 1240 | |
Michiel Van Der Kolk | 9d2531a | 2005-03-28 00:47:09 +0000 | [diff] [blame] | 1241 | snprintf(buf, 30, "Est. remain: %d m", battery_time()); |
Uwe Freese | 5f02797 | 2002-12-14 12:10:29 +0000 | [diff] [blame] | 1242 | lcd_puts(0, 7, buf); |
Björn Stenberg | f09c5f4 | 2002-12-03 14:18:51 +0000 | [diff] [blame] | 1243 | break; |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | lcd_update(); |
Heikki Hannikainen | cccb8d0 | 2002-08-12 12:21:22 +0000 | [diff] [blame] | 1247 | |
Björn Stenberg | f09c5f4 | 2002-12-03 14:18:51 +0000 | [diff] [blame] | 1248 | switch(button_get_w_tmo(HZ/2)) |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1249 | { |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 1250 | case SETTINGS_DEC: |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1251 | if (view) |
| 1252 | view--; |
| 1253 | break; |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1254 | |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 1255 | case SETTINGS_INC: |
Björn Stenberg | f09c5f4 | 2002-12-03 14:18:51 +0000 | [diff] [blame] | 1256 | if (view < 3) |
Björn Stenberg | fe97b57 | 2002-08-10 08:57:47 +0000 | [diff] [blame] | 1257 | view++; |
| 1258 | break; |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1259 | |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 1260 | case SETTINGS_OK: |
| 1261 | case SETTINGS_CANCEL: |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 1262 | return false; |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1263 | } |
| 1264 | } |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 1265 | return false; |
Heikki Hannikainen | 6eb4254 | 2002-08-06 10:52:51 +0000 | [diff] [blame] | 1266 | } |
| 1267 | |
Linus Nielsen Feltzing | c132c48 | 2002-07-22 16:39:17 +0000 | [diff] [blame] | 1268 | #endif |
Jens Arnold | 4ddb320 | 2005-05-06 21:55:34 +0000 | [diff] [blame] | 1269 | |
Björn Stenberg | ae22de2 | 2002-12-02 16:07:56 +0000 | [diff] [blame] | 1270 | static 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 Stenberg | fb06748 | 2003-10-17 13:54:48 +0000 | [diff] [blame] | 1288 | 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 Stenberg | ae22de2 | 2002-12-02 16:07:56 +0000 | [diff] [blame] | 1298 | 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 Stenberg | fb06748 | 2003-10-17 13:54:48 +0000 | [diff] [blame] | 1312 | key = button_get_w_tmo(HZ); |
Björn Stenberg | ae22de2 | 2002-12-02 16:07:56 +0000 | [diff] [blame] | 1313 | switch(key) { |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 1314 | case SETTINGS_CANCEL: |
Björn Stenberg | ae22de2 | 2002-12-02 16:07:56 +0000 | [diff] [blame] | 1315 | done = true; |
| 1316 | break; |
| 1317 | |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 1318 | case SETTINGS_INC: |
| 1319 | case SETTINGS_DEC: |
Björn Stenberg | ae22de2 | 2002-12-02 16:07:56 +0000 | [diff] [blame] | 1320 | if (state == 1) |
| 1321 | state = 2; |
| 1322 | else |
| 1323 | state = 1; |
| 1324 | break; |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 1325 | |
| 1326 | case SETTINGS_OK: |
Björn Stenberg | ae22de2 | 2002-12-02 16:07:56 +0000 | [diff] [blame] | 1327 | lcd_clear_display(); |
| 1328 | lcd_puts(0,0,"Clear time?"); |
| 1329 | lcd_puts(0,1,"PLAY = Yes"); |
| 1330 | lcd_update(); |
| 1331 | while (1) { |
Jens Arnold | dcd4883 | 2004-10-16 07:49:57 +0000 | [diff] [blame] | 1332 | key = button_get(true); |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 1333 | if ( key == SETTINGS_OK ) { |
Björn Stenberg | ae22de2 | 2002-12-02 16:07:56 +0000 | [diff] [blame] | 1334 | if ( state == 1 ) |
| 1335 | global_settings.runtime = 0; |
| 1336 | else |
| 1337 | global_settings.topruntime = 0; |
Henrik Backe | d00beba | 2004-09-23 19:38:59 +0000 | [diff] [blame] | 1338 | break; |
Björn Stenberg | ae22de2 | 2002-12-02 16:07:56 +0000 | [diff] [blame] | 1339 | } |
Jens Arnold | dcd4883 | 2004-10-16 07:49:57 +0000 | [diff] [blame] | 1340 | if (!(key & BUTTON_REL)) /* ignore button releases */ |
Henrik Backe | d00beba | 2004-09-23 19:38:59 +0000 | [diff] [blame] | 1341 | break; |
Björn Stenberg | ae22de2 | 2002-12-02 16:07:56 +0000 | [diff] [blame] | 1342 | } |
| 1343 | break; |
| 1344 | } |
| 1345 | } |
| 1346 | |
| 1347 | return false; |
| 1348 | } |
| 1349 | |
Jens Arnold | 90cbd3b | 2004-09-28 06:23:57 +0000 | [diff] [blame] | 1350 | #ifdef HAVE_MMC |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1351 | bool dbg_mmc_info(void) |
| 1352 | { |
| 1353 | bool done = false; |
| 1354 | int currval = 0; |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1355 | tCardInfo *card; |
Jens Arnold | 2116bba | 2005-01-31 00:39:20 +0000 | [diff] [blame] | 1356 | unsigned char pbuf[32], pbuf2[32]; |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1357 | unsigned char card_name[7]; |
Jens Arnold | 2116bba | 2005-01-31 00:39:20 +0000 | [diff] [blame] | 1358 | |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1359 | 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 Arnold | 2116bba | 2005-01-31 00:39:20 +0000 | [diff] [blame] | 1361 | static const unsigned char *kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" }; |
| 1362 | static const unsigned char *nsec_units[] = { "ns", "µs", "ms" }; |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1363 | |
| 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 Arnold | 6baa55a | 2005-01-24 01:39:24 +0000 | [diff] [blame] | 1384 | (int) mmc_extract_bits(card->cid, 72, 4), |
| 1385 | (int) mmc_extract_bits(card->cid, 76, 4)); |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1386 | lcd_puts(0, 1, pbuf); |
| 1387 | snprintf(pbuf, sizeof(pbuf), "Prod: %d/%d", |
Jens Arnold | 6baa55a | 2005-01-24 01:39:24 +0000 | [diff] [blame] | 1388 | (int) mmc_extract_bits(card->cid, 112, 4), |
| 1389 | (int) mmc_extract_bits(card->cid, 116, 4) + 1997); |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1390 | lcd_puts(0, 2, pbuf); |
Jens Arnold | 6baa55a | 2005-01-24 01:39:24 +0000 | [diff] [blame] | 1391 | snprintf(pbuf, sizeof(pbuf), "Ser#: 0x%08lx", |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1392 | mmc_extract_bits(card->cid, 80, 32)); |
| 1393 | lcd_puts(0, 3, pbuf); |
| 1394 | snprintf(pbuf, sizeof(pbuf), "M=%02x, O=%04x", |
Jens Arnold | 6baa55a | 2005-01-24 01:39:24 +0000 | [diff] [blame] | 1395 | (int) mmc_extract_bits(card->cid, 0, 8), |
| 1396 | (int) mmc_extract_bits(card->cid, 8, 16)); |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1397 | lcd_puts(0, 4, pbuf); |
Jens Arnold | 8ca1831 | 2005-05-27 21:47:50 +0000 | [diff] [blame] | 1398 | snprintf(pbuf, sizeof(pbuf), "Blocks: 0x%06lx", card->numblocks); |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1399 | lcd_puts(0, 5, pbuf); |
Jens Arnold | 8ca1831 | 2005-05-27 21:47:50 +0000 | [diff] [blame] | 1400 | snprintf(pbuf, sizeof(pbuf), "Blksz.: %d", card->blocksize); |
Jens Arnold | a7f7781 | 2005-04-28 01:11:21 +0000 | [diff] [blame] | 1401 | lcd_puts(0, 6, pbuf); |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1402 | } |
| 1403 | else /* Technical details */ |
| 1404 | { |
Jens Arnold | 2116bba | 2005-01-31 00:39:20 +0000 | [diff] [blame] | 1405 | output_dyn_value(pbuf2, sizeof pbuf2, card->speed / 1000, |
| 1406 | kbit_units, false); |
| 1407 | snprintf(pbuf, sizeof pbuf, "Speed: %s", pbuf2); |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1408 | lcd_puts(0, 1, pbuf); |
| 1409 | |
Jens Arnold | 2116bba | 2005-01-31 00:39:20 +0000 | [diff] [blame] | 1410 | output_dyn_value(pbuf2, sizeof pbuf2, card->tsac, |
| 1411 | nsec_units, false); |
| 1412 | snprintf(pbuf, sizeof pbuf, "Tsac: %s", pbuf2); |
Jens Arnold | 8886adb | 2004-10-07 01:23:44 +0000 | [diff] [blame] | 1413 | lcd_puts(0, 2, pbuf); |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1414 | |
| 1415 | snprintf(pbuf, sizeof(pbuf), "Nsac: %d clk", card->nsac); |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1416 | lcd_puts(0, 3, pbuf); |
Jens Arnold | 8886adb | 2004-10-07 01:23:44 +0000 | [diff] [blame] | 1417 | snprintf(pbuf, sizeof(pbuf), "R2W: *%d", card->r2w_factor); |
| 1418 | lcd_puts(0, 4, pbuf); |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1419 | 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 Arnold | 8886adb | 2004-10-07 01:23:44 +0000 | [diff] [blame] | 1422 | lcd_puts(0, 5, pbuf); |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1423 | 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 Arnold | 8886adb | 2004-10-07 01:23:44 +0000 | [diff] [blame] | 1426 | lcd_puts(0, 6, pbuf); |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1427 | } |
| 1428 | } |
| 1429 | else |
| 1430 | lcd_puts(0, 1, "Not found!"); |
| 1431 | |
| 1432 | lcd_update(); |
| 1433 | |
Jens Arnold | f5bdf69 | 2004-10-10 00:35:19 +0000 | [diff] [blame] | 1434 | switch (button_get_w_tmo(HZ/2)) |
Jens Arnold | 6f9a7eb | 2004-10-06 20:43:12 +0000 | [diff] [blame] | 1435 | { |
| 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 Arnold | 90cbd3b | 2004-09-28 06:23:57 +0000 | [diff] [blame] | 1454 | |
| 1455 | return false; |
| 1456 | } |
| 1457 | #else /* Disk-based jukebox */ |
Björn Stenberg | 45d32ce | 2002-12-03 13:12:55 +0000 | [diff] [blame] | 1458 | static bool dbg_disk_info(void) |
| 1459 | { |
| 1460 | char buf[128]; |
| 1461 | bool done = false; |
| 1462 | int i; |
| 1463 | int page = 0; |
Linus Nielsen Feltzing | ef1698e | 2004-04-06 00:17:02 +0000 | [diff] [blame] | 1464 | const int max_page = 11; |
Björn Stenberg | 45d32ce | 2002-12-03 13:12:55 +0000 | [diff] [blame] | 1465 | unsigned short* identify_info = ata_get_identify(); |
Linus Nielsen Feltzing | f3ad619 | 2004-02-16 12:04:55 +0000 | [diff] [blame] | 1466 | bool timing_info_present = false; |
| 1467 | char pio3[2], pio4[2]; |
Björn Stenberg | 45d32ce | 2002-12-03 13:12:55 +0000 | [diff] [blame] | 1468 | |
Linus Nielsen Feltzing | ae6e33e | 2004-02-16 12:21:07 +0000 | [diff] [blame] | 1469 | #ifdef HAVE_LCD_BITMAP |
Linus Nielsen Feltzing | f3ad619 | 2004-02-16 12:04:55 +0000 | [diff] [blame] | 1470 | lcd_setmargins(0, 0); |
Linus Nielsen Feltzing | ae6e33e | 2004-02-16 12:21:07 +0000 | [diff] [blame] | 1471 | #endif |
Linus Nielsen Feltzing | f3ad619 | 2004-02-16 12:04:55 +0000 | [diff] [blame] | 1472 | |
Björn Stenberg | 45d32ce | 2002-12-03 13:12:55 +0000 | [diff] [blame] | 1473 | 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 Stenberg | ee192fb | 2003-08-05 13:39:38 +0000 | [diff] [blame] | 1484 | 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 Stenberg | 45d32ce | 2002-12-03 13:12:55 +0000 | [diff] [blame] | 1494 | |
Björn Stenberg | ee192fb | 2003-08-05 13:39:38 +0000 | [diff] [blame] | 1495 | 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 Stenberg | 45d32ce | 2002-12-03 13:12:55 +0000 | [diff] [blame] | 1502 | |
Björn Stenberg | ee192fb | 2003-08-05 13:39:38 +0000 | [diff] [blame] | 1503 | case 2: |
Jean-Philippe Bernardy | ed7c635 | 2005-02-08 15:12:25 +0000 | [diff] [blame] | 1504 | snprintf(buf, sizeof buf, "%ld MB", |
| 1505 | ((unsigned long)identify_info[61] << 16 | |
| 1506 | (unsigned long)identify_info[60]) / 2048 ); |
Björn Stenberg | ee192fb | 2003-08-05 13:39:38 +0000 | [diff] [blame] | 1507 | lcd_puts(0, y++, "Size"); |
| 1508 | lcd_puts(0, y++, buf); |
| 1509 | break; |
Björn Stenberg | b070dd5 | 2002-12-04 14:58:48 +0000 | [diff] [blame] | 1510 | |
Björn Stenberg | ee192fb | 2003-08-05 13:39:38 +0000 | [diff] [blame] | 1511 | case 3: { |
Jens Arnold | 6baa55a | 2005-01-24 01:39:24 +0000 | [diff] [blame] | 1512 | unsigned long free; |
Jörg Hohensohn | 575c904 | 2004-12-29 22:37:31 +0000 | [diff] [blame] | 1513 | fat_size( IF_MV2(0,) NULL, &free ); |
Jens Arnold | 6baa55a | 2005-01-24 01:39:24 +0000 | [diff] [blame] | 1514 | snprintf(buf, sizeof buf, "%ld MB", free / 1024 ); |
Björn Stenberg | ee192fb | 2003-08-05 13:39:38 +0000 | [diff] [blame] | 1515 | lcd_puts(0, y++, "Free"); |
| 1516 | lcd_puts(0, y++, buf); |
| 1517 | break; |
| 1518 | } |
Björn Stenberg | b17fe5a | 2002-12-09 15:39:32 +0000 | [diff] [blame] | 1519 | |
Björn Stenberg | ee192fb | 2003-08-05 13:39:38 +0000 | [diff] [blame] | 1520 | 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 Stenberg | 218754a | 2004-01-14 15:08:55 +0000 | [diff] [blame] | 1525 | |
| 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 Stenberg | ef1ecad | 2004-01-14 15:10:17 +0000 | [diff] [blame] | 1539 | i = identify_info[82] & (1<<6); |
Björn Stenberg | 218754a | 2004-01-14 15:08:55 +0000 | [diff] [blame] | 1540 | lcd_puts(0, y++, "Read-ahead:"); |
| 1541 | lcd_puts(0, y++, i ? "enabled" : "unsupported"); |
| 1542 | break; |
Linus Nielsen Feltzing | f3ad619 | 2004-02-16 12:04:55 +0000 | [diff] [blame] | 1543 | |
| 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 Feltzing | 50c2261 | 2004-03-01 09:42:47 +0000 | [diff] [blame] | 1562 | lcd_puts(0, y++, "Cycle times"); |
| 1563 | snprintf(buf, 128, "%dns/%dns", |
| 1564 | identify_info[67], |
| 1565 | identify_info[68]); |
Linus Nielsen Feltzing | f3ad619 | 2004-02-16 12:04:55 +0000 | [diff] [blame] | 1566 | 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 Feltzing | ef1698e | 2004-04-06 00:17:02 +0000 | [diff] [blame] | 1585 | |
| 1586 | case 11: |
| 1587 | lcd_puts(0, y++, "Cluster size"); |
Jörg Hohensohn | 575c904 | 2004-12-29 22:37:31 +0000 | [diff] [blame] | 1588 | snprintf(buf, 128, "%d bytes", fat_get_cluster_size(IF_MV(0))); |
Linus Nielsen Feltzing | ef1698e | 2004-04-06 00:17:02 +0000 | [diff] [blame] | 1589 | lcd_puts(0, y++, buf); |
| 1590 | break; |
Björn Stenberg | 45d32ce | 2002-12-03 13:12:55 +0000 | [diff] [blame] | 1591 | } |
| 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 Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 1597 | case SETTINGS_CANCEL: |
Björn Stenberg | 45d32ce | 2002-12-03 13:12:55 +0000 | [diff] [blame] | 1598 | done = true; |
| 1599 | break; |
| 1600 | |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 1601 | case SETTINGS_DEC: |
Björn Stenberg | 45d32ce | 2002-12-03 13:12:55 +0000 | [diff] [blame] | 1602 | if (--page < 0) |
| 1603 | page = max_page; |
| 1604 | break; |
| 1605 | |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 1606 | case SETTINGS_INC: |
Björn Stenberg | 45d32ce | 2002-12-03 13:12:55 +0000 | [diff] [blame] | 1607 | if (++page > max_page) |
| 1608 | page = 0; |
| 1609 | break; |
Björn Stenberg | b17fe5a | 2002-12-09 15:39:32 +0000 | [diff] [blame] | 1610 | |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 1611 | case SETTINGS_OK: |
Björn Stenberg | b17fe5a | 2002-12-09 15:39:32 +0000 | [diff] [blame] | 1612 | if (page == 3) { |
Linus Nielsen Feltzing | 8a237a8 | 2005-04-04 12:06:29 +0000 | [diff] [blame] | 1613 | audio_stop(); /* stop playback, to avoid disk access */ |
Björn Stenberg | b17fe5a | 2002-12-09 15:39:32 +0000 | [diff] [blame] | 1614 | lcd_clear_display(); |
| 1615 | lcd_puts(0,0,"Scanning"); |
| 1616 | lcd_puts(0,1,"disk..."); |
| 1617 | lcd_update(); |
Jörg Hohensohn | 575c904 | 2004-12-29 22:37:31 +0000 | [diff] [blame] | 1618 | fat_recalc_free(IF_MV(0)); |
Björn Stenberg | b17fe5a | 2002-12-09 15:39:32 +0000 | [diff] [blame] | 1619 | } |
| 1620 | break; |
Björn Stenberg | 45d32ce | 2002-12-03 13:12:55 +0000 | [diff] [blame] | 1621 | } |
| 1622 | lcd_stop_scroll(); |
| 1623 | } |
| 1624 | |
| 1625 | return false; |
| 1626 | } |
Jens Arnold | 90cbd3b | 2004-09-28 06:23:57 +0000 | [diff] [blame] | 1627 | #endif |
Björn Stenberg | 45d32ce | 2002-12-03 13:12:55 +0000 | [diff] [blame] | 1628 | |
Daniel Stenberg | 1d395ae | 2005-02-02 21:57:40 +0000 | [diff] [blame] | 1629 | #if CONFIG_CPU == SH7034 |
Linus Nielsen Feltzing | 5a5c869 | 2003-05-17 21:24:13 +0000 | [diff] [blame] | 1630 | bool dbg_save_roms(void) |
| 1631 | { |
| 1632 | int fd; |
Jens Arnold | 06cb237 | 2004-08-30 19:52:45 +0000 | [diff] [blame] | 1633 | int oldmode = system_memory_guard(MEMGUARD_NONE); |
Linus Nielsen Feltzing | 5a5c869 | 2003-05-17 21:24:13 +0000 | [diff] [blame] | 1634 | |
| 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 Arnold | 7ec8aa2 | 2005-06-22 22:38:52 +0000 | [diff] [blame] | 1641 | |
Linus Nielsen Feltzing | 5a5c869 | 2003-05-17 21:24:13 +0000 | [diff] [blame] | 1642 | 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 Arnold | 06cb237 | 2004-08-30 19:52:45 +0000 | [diff] [blame] | 1649 | system_memory_guard(oldmode); |
Linus Nielsen Feltzing | 5a5c869 | 2003-05-17 21:24:13 +0000 | [diff] [blame] | 1650 | return false; |
| 1651 | } |
Daniel Stenberg | 1d395ae | 2005-02-02 21:57:40 +0000 | [diff] [blame] | 1652 | #endif /* CONFIG_CPU == SH7034 */ |
Linus Nielsen Feltzing | 5a5c869 | 2003-05-17 21:24:13 +0000 | [diff] [blame] | 1653 | |
Jörg Hohensohn | 593cc00 | 2004-09-28 22:13:26 +0000 | [diff] [blame] | 1654 | #ifdef CONFIG_TUNER |
Linus Nielsen Feltzing | 04f9cc7 | 2004-02-04 09:53:22 +0000 | [diff] [blame] | 1655 | bool 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 Feltzing | 04f9cc7 | 2004-02-04 09:53:22 +0000 | [diff] [blame] | 1672 | lcd_update(); |
| 1673 | |
| 1674 | button = button_get(true); |
| 1675 | |
| 1676 | switch(button) |
| 1677 | { |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 1678 | case SETTINGS_CANCEL: |
Linus Nielsen Feltzing | 04f9cc7 | 2004-02-04 09:53:22 +0000 | [diff] [blame] | 1679 | return false; |
| 1680 | } |
| 1681 | } |
| 1682 | return false; |
| 1683 | } |
| 1684 | #endif |
| 1685 | |
Linus Nielsen Feltzing | a8dab4c | 2004-06-30 13:31:14 +0000 | [diff] [blame] | 1686 | #ifdef HAVE_LCD_BITMAP |
| 1687 | extern bool do_screendump_instead_of_usb; |
| 1688 | |
| 1689 | bool 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 Stenberg | 1d395ae | 2005-02-02 21:57:40 +0000 | [diff] [blame] | 1698 | #if CONFIG_CPU == SH7034 |
Jens Arnold | 06cb237 | 2004-08-30 19:52:45 +0000 | [diff] [blame] | 1699 | bool 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 Stenberg | 1d395ae | 2005-02-02 21:57:40 +0000 | [diff] [blame] | 1713 | #endif /* CONFIG_CPU == SH7034 */ |
Jens Arnold | 06cb237 | 2004-08-30 19:52:45 +0000 | [diff] [blame] | 1714 | |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 1715 | bool debug_menu(void) |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 1716 | { |
| 1717 | int m; |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 1718 | bool result; |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 1719 | |
Jörg Hohensohn | b1403ee | 2004-07-23 23:01:20 +0000 | [diff] [blame] | 1720 | static const struct menu_item items[] = { |
Daniel Stenberg | 1d395ae | 2005-02-02 21:57:40 +0000 | [diff] [blame] | 1721 | #if CONFIG_CPU == SH7034 |
Jörg Hohensohn | b1403ee | 2004-07-23 23:01:20 +0000 | [diff] [blame] | 1722 | { "Dump ROM contents", dbg_save_roms }, |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 1723 | #endif |
Christian Gmeiner | c6ff1f5 | 2005-07-18 12:40:29 +0000 | [diff] [blame] | 1724 | #if CONFIG_CPU == SH7034 || defined(CPU_COLDFIRE) |
Jörg Hohensohn | b1403ee | 2004-07-23 23:01:20 +0000 | [diff] [blame] | 1725 | { "View I/O ports", dbg_ports }, |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 1726 | #endif |
Linus Nielsen Feltzing | 213d34e | 2005-03-07 10:51:43 +0000 | [diff] [blame] | 1727 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
| 1728 | { "CPU frequency", dbg_cpufreq }, |
Linus Nielsen Feltzing | 1bba84f | 2005-03-18 12:47:06 +0000 | [diff] [blame] | 1729 | #endif |
Linus Nielsen Feltzing | b6242daf | 2005-07-11 12:09:01 +0000 | [diff] [blame] | 1730 | #if defined(IRIVER_H100_SERIES) && !defined(SIMULATOR) |
Andy | e5d0872 | 2005-06-19 03:05:53 +0000 | [diff] [blame] | 1731 | { "PCM recording", pcm_rec_screen }, |
Linus Nielsen Feltzing | 3c82b84 | 2005-07-18 18:28:49 +0000 | [diff] [blame] | 1732 | { "S/PDIF analyzer", dbg_spdif }, |
Andy | e5d0872 | 2005-06-19 03:05:53 +0000 | [diff] [blame] | 1733 | #endif |
Linus Nielsen Feltzing | 6805475 | 2005-02-11 13:16:09 +0000 | [diff] [blame] | 1734 | #if CONFIG_CPU == SH7034 |
Jens Arnold | 06cb237 | 2004-08-30 19:52:45 +0000 | [diff] [blame] | 1735 | { "Catch mem accesses", dbg_set_memory_guard }, |
Daniel Stenberg | 1d395ae | 2005-02-02 21:57:40 +0000 | [diff] [blame] | 1736 | #endif /* CONFIG_CPU == SH7034 */ |
| 1737 | { "View OS stacks", dbg_os }, |
Björn Stenberg | b47e64e | 2002-08-08 20:44:25 +0000 | [diff] [blame] | 1738 | #ifdef HAVE_LCD_BITMAP |
Jörg Hohensohn | b1403ee | 2004-07-23 23:01:20 +0000 | [diff] [blame] | 1739 | { "View battery", view_battery }, |
| 1740 | { "Screendump", dbg_screendump }, |
Linus Nielsen Feltzing | c132c48 | 2002-07-22 16:39:17 +0000 | [diff] [blame] | 1741 | #endif |
Jörg Hohensohn | b1403ee | 2004-07-23 23:01:20 +0000 | [diff] [blame] | 1742 | { "View HW info", dbg_hw_info }, |
| 1743 | { "View partitions", dbg_partitions }, |
Jens Arnold | 90cbd3b | 2004-09-28 06:23:57 +0000 | [diff] [blame] | 1744 | #ifdef HAVE_MMC |
| 1745 | { "View MMC info", dbg_mmc_info }, |
| 1746 | #else |
Jörg Hohensohn | b1403ee | 2004-07-23 23:01:20 +0000 | [diff] [blame] | 1747 | { "View disk info", dbg_disk_info }, |
Jens Arnold | 90cbd3b | 2004-09-28 06:23:57 +0000 | [diff] [blame] | 1748 | #endif |
Linus Nielsen Feltzing | b5a0f70 | 2005-06-22 14:03:04 +0000 | [diff] [blame] | 1749 | #ifdef HAVE_LCD_BITMAP |
Linus Nielsen Feltzing | 8a237a8 | 2005-04-04 12:06:29 +0000 | [diff] [blame] | 1750 | { "View audio thread", dbg_audio_thread }, |
Linus Nielsen Feltzing | fd0cc3b | 2002-10-29 12:09:15 +0000 | [diff] [blame] | 1751 | #ifdef PM_DEBUG |
Jörg Hohensohn | b1403ee | 2004-07-23 23:01:20 +0000 | [diff] [blame] | 1752 | { "pm histogram", peak_meter_histogram}, |
Linus Nielsen Feltzing | fd0cc3b | 2002-10-29 12:09:15 +0000 | [diff] [blame] | 1753 | #endif /* PM_DEBUG */ |
| 1754 | #endif /* HAVE_LCD_BITMAP */ |
Jörg Hohensohn | b1403ee | 2004-07-23 23:01:20 +0000 | [diff] [blame] | 1755 | { "View runtime", view_runtime }, |
Jörg Hohensohn | 593cc00 | 2004-09-28 22:13:26 +0000 | [diff] [blame] | 1756 | #ifdef CONFIG_TUNER |
Jörg Hohensohn | b1403ee | 2004-07-23 23:01:20 +0000 | [diff] [blame] | 1757 | { "FM Radio", dbg_fm_radio }, |
Linus Nielsen Feltzing | 04f9cc7 | 2004-02-04 09:53:22 +0000 | [diff] [blame] | 1758 | #endif |
Daniel Stenberg | edc0792 | 2005-05-30 13:00:43 +0000 | [diff] [blame] | 1759 | #ifdef ROCKBOX_HAS_LOGF |
| 1760 | {"logf", logfdisplay }, |
Daniel Stenberg | c95319f | 2005-06-01 13:07:37 +0000 | [diff] [blame] | 1761 | {"logfdump", logfdump }, |
Daniel Stenberg | edc0792 | 2005-05-30 13:00:43 +0000 | [diff] [blame] | 1762 | #endif |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 1763 | }; |
| 1764 | |
Linus Nielsen Feltzing | 77936e6 | 2004-03-16 13:44:56 +0000 | [diff] [blame] | 1765 | m=menu_init( items, sizeof items / sizeof(struct menu_item), NULL, |
| 1766 | NULL, NULL, NULL); |
Daniel Stenberg | b285076 | 2002-08-23 12:32:52 +0000 | [diff] [blame] | 1767 | result = menu_run(m); |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 1768 | menu_exit(m); |
Daniel Stenberg | b285076 | 2002-08-23 12:32:52 +0000 | [diff] [blame] | 1769 | |
| 1770 | return result; |
Björn Stenberg | 803f47b | 2002-07-15 11:23:24 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | #endif /* SIMULATOR */ |