diff options
Diffstat (limited to 'apps/debug_menu.c')
-rw-r--r-- | apps/debug_menu.c | 284 |
1 files changed, 284 insertions, 0 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c new file mode 100644 index 0000000000..44c5c8e181 --- /dev/null +++ b/apps/debug_menu.c | |||
@@ -0,0 +1,284 @@ | |||
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> | ||
24 | #include "lcd.h" | ||
25 | #include "menu.h" | ||
26 | #include "debug_menu.h" | ||
27 | #include "kernel.h" | ||
28 | #include "sprintf.h" | ||
29 | #include "button.h" | ||
30 | #include "adc.h" | ||
31 | #include "mas.h" | ||
32 | #include "power.h" | ||
33 | #include "rtc.h" | ||
34 | #include "debug.h" | ||
35 | |||
36 | /*---------------------------------------------------*/ | ||
37 | /* SPECIAL DEBUG STUFF */ | ||
38 | /*---------------------------------------------------*/ | ||
39 | extern int ata_device; | ||
40 | extern int ata_io_address; | ||
41 | |||
42 | #ifdef ARCHOS_RECORDER | ||
43 | /* Test code!!! */ | ||
44 | void dbg_ports(void) | ||
45 | { | ||
46 | unsigned short porta; | ||
47 | unsigned short portb; | ||
48 | unsigned char portc; | ||
49 | char buf[32]; | ||
50 | int button; | ||
51 | int battery_voltage; | ||
52 | int batt_int, batt_frac; | ||
53 | bool charge_status = false; | ||
54 | bool ide_status = true; | ||
55 | |||
56 | lcd_clear_display(); | ||
57 | |||
58 | while(1) | ||
59 | { | ||
60 | porta = PADR; | ||
61 | portb = PBDR; | ||
62 | portc = PCDR; | ||
63 | |||
64 | snprintf(buf, 32, "PADR: %04x", porta); | ||
65 | lcd_puts(0, 0, buf); | ||
66 | snprintf(buf, 32, "PBDR: %04x", portb); | ||
67 | lcd_puts(0, 1, buf); | ||
68 | |||
69 | snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4)); | ||
70 | lcd_puts(0, 2, buf); | ||
71 | snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5)); | ||
72 | lcd_puts(0, 3, buf); | ||
73 | snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6)); | ||
74 | lcd_puts(0, 4, buf); | ||
75 | snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7)); | ||
76 | lcd_puts(0, 5, buf); | ||
77 | |||
78 | battery_voltage = (adc_read(6) * BATTERY_SCALE_FACTOR) / 10000; | ||
79 | batt_int = battery_voltage / 100; | ||
80 | batt_frac = battery_voltage % 100; | ||
81 | |||
82 | snprintf(buf, 32, "Batt: %d.%02dV %d%% ", batt_int, batt_frac, | ||
83 | battery_level()); | ||
84 | lcd_puts(0, 6, buf); | ||
85 | |||
86 | snprintf(buf, 32, "ATA: %s, 0x%x", | ||
87 | ata_device?"slave":"master", ata_io_address); | ||
88 | lcd_puts(0, 7, buf); | ||
89 | |||
90 | lcd_update(); | ||
91 | sleep(HZ/10); | ||
92 | |||
93 | button = button_get(false); | ||
94 | |||
95 | switch(button) | ||
96 | { | ||
97 | case BUTTON_ON: | ||
98 | charge_status = charge_status?false:true; | ||
99 | charger_enable(charge_status); | ||
100 | break; | ||
101 | |||
102 | case BUTTON_UP: | ||
103 | ide_status = ide_status?false:true; | ||
104 | ide_power_enable(ide_status); | ||
105 | break; | ||
106 | |||
107 | case BUTTON_OFF: | ||
108 | charger_enable(false); | ||
109 | ide_power_enable(true); | ||
110 | return; | ||
111 | } | ||
112 | } | ||
113 | } | ||
114 | #else | ||
115 | void dbg_ports(void) | ||
116 | { | ||
117 | unsigned short porta; | ||
118 | unsigned short portb; | ||
119 | unsigned char portc; | ||
120 | char buf[32]; | ||
121 | unsigned long crc_count; | ||
122 | int button; | ||
123 | int battery_voltage; | ||
124 | int batt_int, batt_frac; | ||
125 | int currval = 0; | ||
126 | |||
127 | lcd_clear_display(); | ||
128 | |||
129 | while(1) | ||
130 | { | ||
131 | porta = PADR; | ||
132 | portb = PBDR; | ||
133 | portc = PCDR; | ||
134 | |||
135 | switch(currval) | ||
136 | { | ||
137 | case 0: | ||
138 | snprintf(buf, 32, "PADR: %04x ", porta); | ||
139 | break; | ||
140 | case 1: | ||
141 | snprintf(buf, 32, "PBDR: %04x ", portb); | ||
142 | break; | ||
143 | case 2: | ||
144 | snprintf(buf, 32, "AN0: %03x ", adc_read(0)); | ||
145 | break; | ||
146 | case 3: | ||
147 | snprintf(buf, 32, "AN1: %03x ", adc_read(1)); | ||
148 | break; | ||
149 | case 4: | ||
150 | snprintf(buf, 32, "AN2: %03x ", adc_read(2)); | ||
151 | break; | ||
152 | case 5: | ||
153 | snprintf(buf, 32, "AN3: %03x ", adc_read(3)); | ||
154 | break; | ||
155 | case 6: | ||
156 | snprintf(buf, 32, "AN4: %03x ", adc_read(4)); | ||
157 | break; | ||
158 | case 7: | ||
159 | snprintf(buf, 32, "AN5: %03x ", adc_read(5)); | ||
160 | break; | ||
161 | case 8: | ||
162 | snprintf(buf, 32, "AN6: %03x ", adc_read(6)); | ||
163 | break; | ||
164 | case 9: | ||
165 | snprintf(buf, 32, "AN7: %03x ", adc_read(7)); | ||
166 | break; | ||
167 | case 10: | ||
168 | snprintf(buf, 32, "%s, 0x%x ", | ||
169 | ata_device?"slv":"mst", ata_io_address); | ||
170 | break; | ||
171 | case 11: | ||
172 | mas_readmem(MAS_BANK_D0, 0x303, &crc_count, 1); | ||
173 | |||
174 | snprintf(buf, 32, "CRC: %d ", crc_count); | ||
175 | break; | ||
176 | } | ||
177 | lcd_puts(0, 0, buf); | ||
178 | |||
179 | battery_voltage = (adc_read(6) * BATTERY_SCALE_FACTOR) / 10000; | ||
180 | batt_int = battery_voltage / 100; | ||
181 | batt_frac = battery_voltage % 100; | ||
182 | |||
183 | snprintf(buf, 32, "Batt: %d.%02dV", batt_int, batt_frac); | ||
184 | lcd_puts(0, 1, buf); | ||
185 | |||
186 | sleep(HZ/5); | ||
187 | |||
188 | button = button_get(false); | ||
189 | |||
190 | switch(button) | ||
191 | { | ||
192 | case BUTTON_STOP: | ||
193 | return; | ||
194 | |||
195 | case BUTTON_LEFT: | ||
196 | currval--; | ||
197 | if(currval < 0) | ||
198 | currval = 11; | ||
199 | break; | ||
200 | |||
201 | case BUTTON_RIGHT: | ||
202 | currval++; | ||
203 | if(currval > 11) | ||
204 | currval = 0; | ||
205 | break; | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | #endif | ||
210 | |||
211 | #ifdef HAVE_RTC | ||
212 | /* Read RTC RAM contents and display them */ | ||
213 | void dbg_rtc(void) | ||
214 | { | ||
215 | char buf[32]; | ||
216 | unsigned char addr = 0, r, c; | ||
217 | int i; | ||
218 | int button; | ||
219 | |||
220 | lcd_clear_display(); | ||
221 | lcd_puts(0, 0, "RTC read:"); | ||
222 | |||
223 | while(1) | ||
224 | { | ||
225 | for (r = 0; r < 4; r++) { | ||
226 | snprintf(buf, 10, "0x%02x: ", addr + r*4); | ||
227 | for (c = 0; c <= 3; c++) { | ||
228 | i = rtc_read(addr + r*4 + c); | ||
229 | snprintf(buf + 6 + c*2, 3, "%02x", i); | ||
230 | } | ||
231 | lcd_puts(1, r+1, buf); | ||
232 | } | ||
233 | |||
234 | lcd_update(); | ||
235 | sleep(HZ/2); | ||
236 | |||
237 | button = button_get(false); | ||
238 | |||
239 | switch(button) | ||
240 | { | ||
241 | case BUTTON_DOWN: | ||
242 | if (addr < 63-16) { addr += 16; } | ||
243 | break; | ||
244 | case BUTTON_UP: | ||
245 | if (addr) { addr -= 16; } | ||
246 | break; | ||
247 | case BUTTON_F2: | ||
248 | /* clear the user RAM space */ | ||
249 | for (c = 0; c <= 43; c++) | ||
250 | rtc_write(0x18 + c, 0); | ||
251 | break; | ||
252 | case BUTTON_OFF: | ||
253 | case BUTTON_LEFT: | ||
254 | return; | ||
255 | } | ||
256 | } | ||
257 | } | ||
258 | #else | ||
259 | void dbg_rtc(void) | ||
260 | { | ||
261 | return; | ||
262 | } | ||
263 | #endif | ||
264 | |||
265 | void debug_menu(void) | ||
266 | { | ||
267 | int m; | ||
268 | |||
269 | struct menu_items items[] = { | ||
270 | #ifdef HAVE_LCD_BITMAP | ||
271 | { "Debug ports", dbg_ports }, | ||
272 | #ifdef HAVE_RTC | ||
273 | { "Debug RTC", dbg_rtc }, | ||
274 | #endif /* HAVE_RTC */ | ||
275 | #endif /* HAVE_LCD_BITMAP */ | ||
276 | }; | ||
277 | |||
278 | m=menu_init( items, sizeof items / sizeof(struct menu_items) ); | ||
279 | menu_run(m); | ||
280 | menu_exit(m); | ||
281 | } | ||
282 | |||
283 | #endif /* SIMULATOR */ | ||
284 | |||