|
0
|
1 /*============================================================================= |
|
|
2 // |
|
|
3 // hal_diag.c |
|
|
4 // |
|
|
5 // HAL diagnostic output code |
|
|
6 // |
|
|
7 //============================================================================= |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // September 30, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
|
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. |
|
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //============================================================================= |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
|
32 // Author(s): nickg |
|
|
33 // Contributors: nickg |
|
|
34 // Date: 1998-03-02 |
|
|
35 // Purpose: HAL diagnostic output |
|
|
36 // Description: Implementations of HAL diagnostic output support. |
|
|
37 // |
|
|
38 //####DESCRIPTIONEND#### |
|
|
39 // |
|
|
40 //===========================================================================*/ |
|
|
41 |
|
|
42 #include <pkgconf/hal.h> |
|
|
43 |
|
|
44 #include <cyg/infra/cyg_type.h> // base types |
|
|
45 #include <cyg/infra/cyg_trac.h> // tracing macros |
|
|
46 #include <cyg/infra/cyg_ass.h> // assertion macros |
|
|
47 |
|
|
48 #include <cyg/hal/hal_arch.h> |
|
|
49 #include <cyg/hal/hal_diag.h> |
|
|
50 |
|
|
51 #include <cyg/hal/hal_intr.h> |
|
|
52 |
|
|
53 #include <cyg/hal/hal_io.h> |
|
|
54 |
|
|
55 /*---------------------------------------------------------------------------*/ |
|
|
56 |
|
|
57 //#define CYG_KERNEL_DIAG_LCD |
|
|
58 #define CYG_KERNEL_DIAG_SERIAL0 |
|
|
59 |
|
|
60 #if defined(CYG_HAL_USE_ROM_MONITOR) |
|
|
61 |
|
|
62 #define CYG_KERNEL_DIAG_GDB |
|
|
63 |
|
|
64 #endif |
|
|
65 |
|
|
66 /*---------------------------------------------------------------------------*/ |
|
|
67 |
|
|
68 static cyg_uint8 leds = 0; |
|
|
69 |
|
|
70 void hal_diag_led(int x) |
|
|
71 { |
|
|
72 // return; |
|
|
73 leds ^= x; |
|
|
74 |
|
|
75 HAL_WRITE_UINT8( 0xfffff504, leds); |
|
|
76 |
|
|
77 #if 0 |
|
|
78 { |
|
|
79 int i; |
|
|
80 |
|
|
81 for( i = 0; i < 0x00020000; i++ ); |
|
|
82 } |
|
|
83 #endif |
|
|
84 } |
|
|
85 |
|
|
86 /*---------------------------------------------------------------------------*/ |
|
|
87 |
|
|
88 #ifdef CYG_KERNEL_DIAG_SERIAL0 |
|
|
89 |
|
|
90 #define DIAG_BASE 0xfffff300 |
|
|
91 #define DIAG_SLCR (DIAG_BASE+0x00) |
|
|
92 #define DIAG_SLSR (DIAG_BASE+0x04) |
|
|
93 #define DIAG_SLDICR (DIAG_BASE+0x08) |
|
|
94 #define DIAG_SLDISR (DIAG_BASE+0x0C) |
|
|
95 #define DIAG_SFCR (DIAG_BASE+0x10) |
|
|
96 #define DIAG_SBRG (DIAG_BASE+0x14) |
|
|
97 #define DIAG_TFIFO (DIAG_BASE+0x20) |
|
|
98 #define DIAG_RFIFO (DIAG_BASE+0x30) |
|
|
99 |
|
|
100 #define BRG_T0 0x0000 |
|
|
101 #define BRG_T2 0x0100 |
|
|
102 #define BRG_T4 0x0200 |
|
|
103 #define BRG_T5 0x0300 |
|
|
104 |
|
|
105 |
|
|
106 void hal_diag_init() |
|
|
107 { |
|
|
108 #if defined(CYG_HAL_USE_ROM_MONITOR) |
|
|
109 // If we are using the ROM monitor, it has already |
|
|
110 // initialized the serial line. |
|
|
111 #else |
|
|
112 //hal_diag_led(0x10); |
|
|
113 HAL_WRITE_UINT16( DIAG_SLCR , 0x0020 ); |
|
|
114 |
|
|
115 HAL_WRITE_UINT16( DIAG_SLDICR , 0x0000 ); |
|
|
116 |
|
|
117 HAL_WRITE_UINT16( DIAG_SFCR , 0x0000 ); |
|
|
118 |
|
|
119 // HAL_WRITE_UINT16( DIAG_SBRG , BRG_T2 | 20 ); |
|
|
120 HAL_WRITE_UINT16( DIAG_SBRG , BRG_T2 | 10 ); |
|
|
121 // HAL_WRITE_UINT16( DIAG_SBRG , BRG_T2 | 5 ); |
|
|
122 //hal_diag_led(0x10); |
|
|
123 #endif |
|
|
124 } |
|
|
125 |
|
|
126 void hal_diag_write_char_serial0( char c) |
|
|
127 { |
|
|
128 CYG_WORD16 disr; |
|
|
129 |
|
|
130 //hal_diag_led(0x20); |
|
|
131 |
|
|
132 for(;;) |
|
|
133 { |
|
|
134 HAL_READ_UINT16( DIAG_SLDISR , disr ); |
|
|
135 |
|
|
136 if( disr & 0x0002 ) break; |
|
|
137 } |
|
|
138 |
|
|
139 disr = disr & ~0x0002; |
|
|
140 |
|
|
141 HAL_WRITE_UINT8( DIAG_TFIFO, c ); |
|
|
142 |
|
|
143 HAL_WRITE_UINT16( DIAG_SLDISR , disr ); |
|
|
144 |
|
|
145 //hal_diag_led(0x20); |
|
|
146 } |
|
|
147 |
|
|
148 void hal_diag_drain_serial0(void) |
|
|
149 { |
|
|
150 CYG_WORD16 disr; |
|
|
151 |
|
|
152 for(;;) |
|
|
153 { |
|
|
154 HAL_READ_UINT16( DIAG_SLDISR , disr ); |
|
|
155 |
|
|
156 if( disr & 0x0002 ) break; |
|
|
157 } |
|
|
158 |
|
|
159 disr = disr & ~0x0002; |
|
|
160 |
|
|
161 HAL_WRITE_UINT16( DIAG_SLDISR , disr ); |
|
|
162 } |
|
|
163 |
|
|
164 void hal_diag_read_char_serial0(char *c) |
|
|
165 { |
|
|
166 CYG_WORD16 disr; |
|
|
167 |
|
|
168 //hal_diag_led(0x40); |
|
|
169 for(;;) |
|
|
170 { |
|
|
171 |
|
|
172 HAL_READ_UINT16( DIAG_SLDISR , disr ); |
|
|
173 |
|
|
174 if( disr & 0x0001 ) break; |
|
|
175 } |
|
|
176 |
|
|
177 disr = disr & ~0x0001; |
|
|
178 |
|
|
179 HAL_READ_UINT8( DIAG_RFIFO, *c ); |
|
|
180 |
|
|
181 HAL_WRITE_UINT16( DIAG_SLDISR , disr ); |
|
|
182 |
|
|
183 //hal_diag_led(0x40); |
|
|
184 } |
|
|
185 |
|
|
186 |
|
|
187 void hal_diag_write_char(char c) |
|
|
188 { |
|
|
189 #ifdef CYG_KERNEL_DIAG_GDB |
|
|
190 #if 0 //defined(CYG_HAL_USE_ROM_MONITOR) |
|
|
191 |
|
|
192 typedef void rom_write_fn(char c); |
|
|
193 rom_write_fn *fn = ((rom_write_fn **)0x80000100)[63]; |
|
|
194 |
|
|
195 fn(c); |
|
|
196 |
|
|
197 #else |
|
|
198 static char line[100]; |
|
|
199 static int pos = 0; |
|
|
200 // register volatile cyg_uint16 *volatile tty_status = SERIAL1_SR; |
|
|
201 |
|
|
202 // No need to send CRs |
|
|
203 if( c == '\r' ) return; |
|
|
204 |
|
|
205 line[pos++] = c; |
|
|
206 |
|
|
207 if( c == '\n' || pos == sizeof(line) ) |
|
|
208 { |
|
|
209 CYG_INTERRUPT_STATE old; |
|
|
210 // CYG_ADDRWORD old; |
|
|
211 |
|
|
212 // Disable interrupts. This prevents GDB trying to interrupt us |
|
|
213 // while we are in the middle of sending a packet. The serial |
|
|
214 // receive interrupt will be seen when we re-enable interrupts |
|
|
215 // later. |
|
|
216 |
|
|
217 HAL_DISABLE_INTERRUPTS(old); |
|
|
218 |
|
|
219 while(1) |
|
|
220 { |
|
|
221 static char hex[] = "0123456789ABCDEF"; |
|
|
222 cyg_uint8 csum = 0; |
|
|
223 int i; |
|
|
224 char c1; |
|
|
225 |
|
|
226 hal_diag_write_char_serial0('$'); |
|
|
227 hal_diag_write_char_serial0('O'); |
|
|
228 csum += 'O'; |
|
|
229 for( i = 0; i < pos; i++ ) |
|
|
230 { |
|
|
231 char ch = line[i]; |
|
|
232 char h = hex[(ch>>4)&0xF]; |
|
|
233 char l = hex[ch&0xF]; |
|
|
234 hal_diag_write_char_serial0(h); |
|
|
235 hal_diag_write_char_serial0(l); |
|
|
236 csum += h; |
|
|
237 csum += l; |
|
|
238 } |
|
|
239 hal_diag_write_char_serial0('#'); |
|
|
240 hal_diag_write_char_serial0(hex[(csum>>4)&0xF]); |
|
|
241 hal_diag_write_char_serial0(hex[csum&0xF]); |
|
|
242 |
|
|
243 #if 1 |
|
|
244 hal_diag_read_char_serial0( &c1 ); |
|
|
245 |
|
|
246 // We must ack the interrupt caused by that read to avoid |
|
|
247 // confusing the GDB stub ROM. |
|
|
248 // HAL_INTERRUPT_ACKNOWLEDGE( CYG_VECTOR_EXTERNAL_2 ); |
|
|
249 |
|
|
250 if( c1 == '+' ) break; |
|
|
251 |
|
|
252 #if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS) |
|
|
253 if( c1 == 3 ) |
|
|
254 { |
|
|
255 // Ctrl-C: breakpoint. |
|
|
256 extern void breakpoint(); |
|
|
257 breakpoint(); |
|
|
258 break; |
|
|
259 } |
|
|
260 #elif defined(CYG_HAL_USE_ROM_MONITOR) && defined(CYG_HAL_USE_ROM_MONITOR_GDB_STUBS) |
|
|
261 if( c1 == 3 ) |
|
|
262 { |
|
|
263 // Ctrl-C: breakpoint. |
|
|
264 // HAL_BREAKPOINT(_breakinst); |
|
|
265 typedef void bpt_fn(); |
|
|
266 bpt_fn *bfn = ((bpt_fn **)0x80000100)[61]; |
|
|
267 |
|
|
268 bfn(); |
|
|
269 |
|
|
270 break; |
|
|
271 } |
|
|
272 #elif defined(CYG_HAL_USE_ROM_MONITOR) && defined(CYG_HAL_USE_ROM_MONITOR_CYGMON) |
|
|
273 if( c1 == 3 ) |
|
|
274 { |
|
|
275 // Ctrl-C: breakpoint. |
|
|
276 HAL_BREAKPOINT(_breakinst); |
|
|
277 |
|
|
278 break; |
|
|
279 } |
|
|
280 #endif |
|
|
281 |
|
|
282 #else |
|
|
283 break; |
|
|
284 #endif |
|
|
285 } |
|
|
286 |
|
|
287 pos = 0; |
|
|
288 |
|
|
289 // Wait for all data from serial line to drain |
|
|
290 // and clear ready-to-send indication. |
|
|
291 hal_diag_drain_serial0(); |
|
|
292 |
|
|
293 // And re-enable interrupts |
|
|
294 HAL_RESTORE_INTERRUPTS(old); |
|
|
295 |
|
|
296 } |
|
|
297 #endif |
|
|
298 #else |
|
|
299 hal_diag_write_char_serial0(c); |
|
|
300 #endif |
|
|
301 } |
|
|
302 |
|
|
303 void hal_diag_read_char(char *c) |
|
|
304 { |
|
|
305 for(;;) |
|
|
306 { |
|
|
307 #if defined(CYG_KERNEL_DIAG_GDB) && defined(CYG_HAL_USE_ROM_MONITOR) |
|
|
308 |
|
|
309 typedef void rom_read_fn(char *c); |
|
|
310 rom_read_fn *fn = ((rom_read_fn **)0x80000100)[62]; |
|
|
311 |
|
|
312 fn(c); |
|
|
313 |
|
|
314 #else |
|
|
315 hal_diag_read_char_serial0(c); |
|
|
316 |
|
|
317 #endif |
|
|
318 |
|
|
319 #if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS) |
|
|
320 if( *c == 3 ) |
|
|
321 { |
|
|
322 // Ctrl-C: breakpoint. |
|
|
323 extern void breakpoint(void); |
|
|
324 breakpoint(); |
|
|
325 continue; |
|
|
326 } |
|
|
327 #elif defined(CYG_HAL_USE_ROM_MONITOR) |
|
|
328 if( *c == 3 ) |
|
|
329 { |
|
|
330 // Ctrl-C: breakpoint. |
|
|
331 |
|
|
332 // HAL_BREAKPOINT(_breakinst); |
|
|
333 typedef void bpt_fn(void); |
|
|
334 bpt_fn *bfn = ((bpt_fn **)0x80000100)[61]; |
|
|
335 |
|
|
336 bfn(); |
|
|
337 continue; |
|
|
338 } |
|
|
339 #endif |
|
|
340 |
|
|
341 break; |
|
|
342 } |
|
|
343 } |
|
|
344 |
|
|
345 #endif |
|
|
346 |
|
|
347 /*---------------------------------------------------------------------------*/ |
|
|
348 |
|
|
349 #ifdef CYG_KERNEL_DIAG_LCD |
|
|
350 |
|
|
351 /* ----------------------------------------------------------- */ |
|
|
352 #define ISA_BASE 0xA0000000 |
|
|
353 #define LCD_DATA *(volatile unsigned char*)(0x13400000+ISA_BASE) |
|
|
354 #define LCD_CMD *(volatile unsigned char*)(0x13000000+ISA_BASE) |
|
|
355 |
|
|
356 #define DISPCLR 0x01 /* Display Clear */ |
|
|
357 #define ECURINC 0x06 /* Cursor Increment */ |
|
|
358 #define DISPCONT 0x08 /* Display Control */ |
|
|
359 #define BLINK 0x01 /* Blink */ |
|
|
360 #define CURON 0x02 /* Cursor ON */ |
|
|
361 #define DISPON 0x04 /* Display ON */ |
|
|
362 #define INITCMD 0x38 /* Initial Command */ |
|
|
363 #define DDRAM 0x80 /* DDRAM address */ |
|
|
364 #define LCDBUSY 0x80 /* Busy */ |
|
|
365 |
|
|
366 /* ----------------------------------------------------------- */ |
|
|
367 |
|
|
368 /* */ |
|
|
369 /* JMZ-LCD202 LCD Display Unit */ |
|
|
370 /* - Sample Program (for JMR-TX3904) - */ |
|
|
371 /* */ |
|
|
372 |
|
|
373 static void readyLCD(){ |
|
|
374 while(LCD_CMD & LCDBUSY); |
|
|
375 } |
|
|
376 |
|
|
377 static void outLCD(unsigned char d){ |
|
|
378 readyLCD(); |
|
|
379 LCD_DATA = d; |
|
|
380 } |
|
|
381 |
|
|
382 static void outLCD_CMD(unsigned char d){ |
|
|
383 readyLCD(); |
|
|
384 LCD_CMD = d; |
|
|
385 } |
|
|
386 |
|
|
387 static void INIT_LCD(){ |
|
|
388 outLCD_CMD(INITCMD); |
|
|
389 outLCD_CMD(DISPCONT); |
|
|
390 outLCD_CMD(DISPCLR); |
|
|
391 outLCD_CMD(ECURINC); |
|
|
392 outLCD_CMD(DISPCONT|BLINK|CURON|DISPON); |
|
|
393 } |
|
|
394 |
|
|
395 #if 0 |
|
|
396 static void MAIN(){ |
|
|
397 int i; |
|
|
398 static char c[]="JMZ-LCD202 LCD UNIT"; |
|
|
399 static char d[]="Display Test Sample"; |
|
|
400 |
|
|
401 INIT_LCD(); |
|
|
402 outLCD_CMD(DDRAM); |
|
|
403 for (i=0;i<20;i++) outLCD(c[i]); |
|
|
404 outLCD_CMD(DDRAM+0x40); |
|
|
405 for (i=0;i<20;i++) outLCD(d[i]); |
|
|
406 } |
|
|
407 #endif |
|
|
408 |
|
|
409 #define LCD_LINE0 0x00 |
|
|
410 #define LCD_LINE1 0x40 |
|
|
411 |
|
|
412 #define LCD_LINE_LENGTH 20 |
|
|
413 |
|
|
414 static char lcd_line0[LCD_LINE_LENGTH+1]; |
|
|
415 static char lcd_line1[LCD_LINE_LENGTH+1]; |
|
|
416 static char *lcd_line[2] = { lcd_line0, lcd_line1 }; |
|
|
417 static int lcd_curline = 0; |
|
|
418 static int lcd_linepos = 0; |
|
|
419 |
|
|
420 static void lcd_dis(int add, char *string); |
|
|
421 |
|
|
422 void hal_diag_init() |
|
|
423 { |
|
|
424 int i; |
|
|
425 //hal_diag_led(0x10); |
|
|
426 |
|
|
427 INIT_LCD(); |
|
|
428 |
|
|
429 lcd_curline = 0; |
|
|
430 lcd_linepos = 0; |
|
|
431 |
|
|
432 for( i = 0; i < LCD_LINE_LENGTH; i++ ) |
|
|
433 lcd_line[0][i] = lcd_line[1][i] = ' '; |
|
|
434 |
|
|
435 lcd_line[0][LCD_LINE_LENGTH] = lcd_line[1][LCD_LINE_LENGTH] = 0; |
|
|
436 |
|
|
437 lcd_dis( LCD_LINE0, lcd_line[0] ); |
|
|
438 lcd_dis( LCD_LINE1, lcd_line[1] ); |
|
|
439 |
|
|
440 #if 0 |
|
|
441 { |
|
|
442 int i; |
|
|
443 static char c[]="JMZ-LCD202 LCD UNIT"; |
|
|
444 static char d[]="Display Test Sample"; |
|
|
445 |
|
|
446 outLCD_CMD(DDRAM); |
|
|
447 for (i=0;i<20;i++) outLCD(c[i]); |
|
|
448 outLCD_CMD(DDRAM+0x40); |
|
|
449 for (i=0;i<20;i++) outLCD(d[i]); |
|
|
450 } |
|
|
451 #endif |
|
|
452 |
|
|
453 //hal_diag_led(0x10); |
|
|
454 } |
|
|
455 |
|
|
456 /* this routine writes the string to the LCD */ |
|
|
457 /* display after setting the address to add */ |
|
|
458 static void lcd_dis(int add, char *string) |
|
|
459 { |
|
|
460 int i; |
|
|
461 |
|
|
462 outLCD_CMD(DDRAM+add); |
|
|
463 |
|
|
464 for (i=0 ; i<LCD_LINE_LENGTH ; i++) outLCD(string[i]); |
|
|
465 } |
|
|
466 |
|
|
467 void hal_diag_write_char( char c) |
|
|
468 { |
|
|
469 int i; |
|
|
470 |
|
|
471 //hal_diag_led(0x20); |
|
|
472 |
|
|
473 // Truncate long lines |
|
|
474 if( lcd_linepos >= LCD_LINE_LENGTH ) return; |
|
|
475 |
|
|
476 // ignore CR |
|
|
477 if( c == '\r' ) return; |
|
|
478 |
|
|
479 if( c == '\n' ) |
|
|
480 { |
|
|
481 lcd_dis( LCD_LINE0, &lcd_line[lcd_curline^1][0] ); |
|
|
482 lcd_dis( LCD_LINE1, &lcd_line[lcd_curline][0] ); |
|
|
483 |
|
|
484 // Do a line feed |
|
|
485 lcd_curline ^= 1; |
|
|
486 lcd_linepos = 0; |
|
|
487 |
|
|
488 for( i = 0; i < LCD_LINE_LENGTH; i++ ) |
|
|
489 lcd_line[lcd_curline][i] = ' '; |
|
|
490 |
|
|
491 return; |
|
|
492 } |
|
|
493 |
|
|
494 lcd_line[lcd_curline][lcd_linepos++] = c; |
|
|
495 |
|
|
496 //hal_diag_led(0x20); |
|
|
497 } |
|
|
498 |
|
|
499 void hal_diag_read_char(char *c) |
|
|
500 { |
|
|
501 //hal_diag_led(0x40); |
|
|
502 |
|
|
503 //hal_diag_led(0x40); |
|
|
504 } |
|
|
505 |
|
|
506 |
|
|
507 #endif |
|
|
508 |
|
|
509 |
|
|
510 /*---------------------------------------------------------------------------*/ |
|
|
511 /* End of hal_diag.c */ |