comparison packages/hal/i386/pc/current/src/hal_diag.c @ 76:435cced73e2f ecos-v1_3_1-release

eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
author jlarmour
date Tue, 28 Mar 2000 14:10:45 +0000
parents
children ac086aa3217e
comparison
equal deleted inserted replaced
75:41bf073c0c32 76:435cced73e2f
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 Red Hat eCos Public License
12 // Version 1.1 (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://www.redhat.com/
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 Configurable Operating System,
22 // released September 30, 1998.
23 //
24 // The Initial Developer of the Original Code is Red Hat.
25 // Portions created by Red Hat are
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
27 // All Rights Reserved.
28 // -------------------------------------------
29 //
30 //####COPYRIGHTEND####
31 //=============================================================================
32 //#####DESCRIPTIONBEGIN####
33 //
34 // Author(s): proven
35 // Contributors:proven
36 // Date: 1998-10-05
37 // Purpose: HAL diagnostic output
38 // Description: Implementations of HAL diagnostic output support.
39 //
40 //####DESCRIPTIONEND####
41 //
42 //=============================================================================
43
44 #include <pkgconf/hal.h>
45
46 #include <cyg/infra/cyg_type.h> // base types
47
48 #include <cyg/hal/hal_diag.h>
49
50
51 #include <cyg/hal/plf_misc.h>
52
53 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
55
56 #if defined(CYGSEM_HAL_I386_PC_DIAG_SCREEN)
57
58 //-----------------------------------------------------------------------------
59 // Screen output definitions...
60
61 static short *DisplayBuffer = (short *)0xB8000;
62 static short DisplayAttr = 0x0700;
63
64 static short DisplayPort = 0x03d4;
65
66 static int XPos;
67 static int YPos;
68
69 static int ScreenWidth = 80;
70 static int ScreenLength = 25;
71
72 //-----------------------------------------------------------------------------
73
74 static void MoveLine
75 (
76 short *dest,
77 short *src,
78 int count
79 )
80 {
81
82 while( count-- ) *dest++ = *src++;
83
84 } /* MoveLine */
85
86 //-----------------------------------------------------------------------------
87
88 static void FillLine
89 (
90 short *dest,
91 short val,
92 int count
93 )
94 {
95 while( count-- ) *dest++ = val;
96
97 } /* FillLine */
98
99 //-----------------------------------------------------------------------------
100
101 void ClearScreen(void)
102 {
103 FillLine(DisplayBuffer, ' ' | DisplayAttr, ScreenWidth*ScreenLength);
104
105 } /* ClearScreen */
106
107 void MoveCursor
108 (
109 void
110 )
111 {
112 int pos = XPos + YPos * ScreenWidth;
113
114 pc_outb(DisplayPort, 0x0e );
115 pc_outb(DisplayPort+1, pos >> 8 );
116
117 pc_outb(DisplayPort, 0x0f );
118 pc_outb(DisplayPort+1, pos & 0xFF );
119
120 } /* MoveCursor */
121
122 //-----------------------------------------------------------------------------
123
124 void ScrollUp
125 (
126 int lines
127 )
128 {
129 // Report_Function(ScrollUp)
130
131 int rest = ScreenLength - lines;
132
133 MoveLine
134 (
135 DisplayBuffer,
136 DisplayBuffer+(lines*ScreenWidth),
137 rest*ScreenWidth
138 );
139
140 FillLine
141 (
142 DisplayBuffer+(rest*ScreenWidth),
143 ' ' | DisplayAttr,
144 lines*ScreenWidth
145 );
146
147 } /* ScrollUp */
148
149 //-----------------------------------------------------------------------------
150
151 void ScrollDown
152 (
153 int lines
154 )
155 {
156 // Report_Function(ScrollDown)
157
158 int rest = ScreenLength - lines;
159 short *db = DisplayBuffer+(ScreenWidth*(ScreenLength-1));
160
161 while( rest )
162 {
163 MoveLine
164 (
165 db,
166 db-ScreenWidth,
167 ScreenWidth
168 );
169
170 rest--;
171 db -= ScreenWidth;
172 }
173
174 FillLine
175 (
176 DisplayBuffer,
177 ' ' | DisplayAttr,
178 lines*ScreenWidth
179 );
180
181 } /* ScrollDown */
182
183 //-----------------------------------------------------------------------------
184
185 void NewLine
186 (
187 void
188 )
189 {
190
191 XPos = 0;
192 YPos++;
193
194 if( YPos >= ScreenLength )
195 {
196 YPos = ScreenLength-1;
197 ScrollUp(1);
198 }
199
200 MoveCursor();
201
202 } /* NewLine */
203
204 //-----------------------------------------------------------------------------
205
206 void DisplayChar
207 (
208 char ch
209 )
210 {
211
212 DisplayBuffer[XPos + YPos*ScreenWidth] = ch | DisplayAttr;
213
214 XPos++;
215
216 if( XPos >= ScreenWidth )
217 {
218 XPos = 0;
219 YPos++;
220 if( YPos >= ScreenLength )
221 {
222 YPos = ScreenLength-1;
223 ScrollUp(1);
224 }
225 }
226
227 MoveCursor();
228
229 } /* DisplayChar */
230
231 //-----------------------------------------------------------------------------
232 // Keyboard definitions
233
234 #define KBDATAPORT 0x0060 // data I/O port
235 #define KBCMDPORT 0x0064 // command port (write)
236 #define KBSTATPORT 0x0064 // status port (read)
237
238 // Scan codes
239
240 #define LSHIFT 0x2a
241 #define RSHIFT 0x36
242 #define CTRL 0x1d
243 #define ALT 0x38
244 #define CAPS 0x3a
245 #define NUMS 0x45
246
247 #define BREAK 0x80
248
249 // Bits for KBFlags
250
251 #define KBNormal 0x0000
252 #define KBShift 0x0001
253 #define KBCtrl 0x0002
254 #define KBAlt 0x0004
255 #define KBIndex 0x0007 // mask for the above
256
257 #define KBExtend 0x0010
258 #define KBAck 0x0020
259 #define KBResend 0x0040
260 #define KBShiftL (0x0080 | KBShift)
261 #define KBShiftR (0x0100 | KBShift)
262 #define KBCtrlL (0x0200 | KBCtrl)
263 #define KBCtrlR (0x0400 | KBCtrl)
264 #define KBAltL (0x0800 | KBAlt)
265 #define KBAltR (0x1000 | KBAlt)
266 #define KBCapsLock 0x2000
267 #define KBNumLock 0x4000
268
269 //-----------------------------------------------------------------------------
270 // Keyboard Variables
271
272 static int KBFlags = 0;
273
274 static CYG_BYTE KBPending = 0xFF;
275
276 static CYG_BYTE KBScanTable[128][4] =
277 {
278 // Normal Shift Control Alt
279 // 0x00
280 { 0xFF, 0xFF, 0xFF, 0xFF, },
281 { 0x1b, 0x1b, 0x1b, 0xFF, },
282 { '1', '!', 0xFF, 0xFF, },
283 { '2', '"', 0xFF, 0xFF, },
284 { '3', '#', 0xFF, 0xFF, },
285 { '4', '$', 0xFF, 0xFF, },
286 { '5', '%', 0xFF, 0xFF, },
287 { '6', '^', 0xFF, 0xFF, },
288 { '7', '&', 0xFF, 0xFF, },
289 { '8', '*', 0xFF, 0xFF, },
290 { '9', '(', 0xFF, 0xFF, },
291 { '0', ')', 0xFF, 0xFF, },
292 { '-', '_', 0xFF, 0xFF, },
293 { '=', '+', 0xFF, 0xFF, },
294 { '\b', '\b', 0xFF, 0xFF, },
295 { '\t', '\t', 0xFF, 0xFF, },
296 // 0x10
297 { 'q', 'Q', 0x11, 0xFF, },
298 { 'w', 'W', 0x17, 0xFF, },
299 { 'e', 'E', 0x05, 0xFF, },
300 { 'r', 'R', 0x12, 0xFF, },
301 { 't', 'T', 0x14, 0xFF, },
302 { 'y', 'Y', 0x19, 0xFF, },
303 { 'u', 'U', 0x15, 0xFF, },
304 { 'i', 'I', 0x09, 0xFF, },
305 { 'o', 'O', 0x0F, 0xFF, },
306 { 'p', 'P', 0x10, 0xFF, },
307 { '[', '{', 0x1b, 0xFF, },
308 { ']', '}', 0x1d, 0xFF, },
309 { '\r', '\r', '\n', 0xFF, },
310 { 0xFF, 0xFF, 0xFF, 0xFF, },
311 { 'a', 'A', 0x01, 0xFF, },
312 { 's', 'S', 0x13, 0xFF, },
313 // 0x20
314 { 'd', 'D', 0x04, 0xFF, },
315 { 'f', 'F', 0x06, 0xFF, },
316 { 'g', 'G', 0x07, 0xFF, },
317 { 'h', 'H', 0x08, 0xFF, },
318 { 'j', 'J', 0x0a, 0xFF, },
319 { 'k', 'K', 0x0b, 0xFF, },
320 { 'l', 'L', 0x0c, 0xFF, },
321 { ';', ':', 0xFF, 0xFF, },
322 { 0x27, '@', 0xFF, 0xFF, },
323 { '#', '~', 0xFF, 0xFF, },
324 { '`', '~', 0xFF, 0xFF, },
325 { '\\', '|', 0x1C, 0xFF, },
326 { 'z', 'Z', 0x1A, 0xFF, },
327 { 'x', 'X', 0x18, 0xFF, },
328 { 'c', 'C', 0x03, 0xFF, },
329 { 'v', 'V', 0x16, 0xFF, },
330 // 0x30
331 { 'b', 'B', 0x02, 0xFF, },
332 { 'n', 'N', 0x0E, 0xFF, },
333 { 'm', 'M', 0x0D, 0xFF, },
334 { ',', '<', 0xFF, 0xFF, },
335 { '.', '>', 0xFF, 0xFF, },
336 { '/', '?', 0xFF, 0xFF, },
337 { 0xFF, 0xFF, 0xFF, 0xFF, },
338 { 0xFF, 0xFF, 0xFF, 0xFF, },
339 { 0xFF, 0xFF, 0xFF, 0xFF, },
340 { ' ', ' ', ' ', ' ', },
341 { 0xFF, 0xFF, 0xFF, 0xFF, },
342 { 0xF1, 0xE1, 0xFF, 0xFF, },
343 { 0xF2, 0xE2, 0xFF, 0xFF, },
344 { 0xF3, 0xE3, 0xFF, 0xFF, },
345 { 0xF4, 0xE4, 0xFF, 0xFF, },
346 { 0xF5, 0xE5, 0xFF, 0xFF, },
347 // 0x40
348 { 0xFF, 0xFF, 0xFF, 0xFF, },
349 { 0xFF, 0xFF, 0xFF, 0xFF, },
350 { 0xFF, 0xFF, 0xFF, 0xFF, },
351 { 0xFF, 0xFF, 0xFF, 0xFF, },
352 { 0xFF, 0xFF, 0xFF, 0xFF, },
353 { 0xFF, 0xFF, 0xFF, 0xFF, },
354 { 0xFF, 0xFF, 0xFF, 0xFF, },
355 { 0xFF, 0xFF, 0xFF, 0xFF, },
356
357 { 0x15, 0x15, 0x15, 0x15, },
358 { 0x10, 0x10, 0x10, 0x10, },
359 { 0xFF, 0xFF, 0xFF, 0xFF, },
360 { 0xFF, 0xFF, 0xFF, 0xFF, },
361 { 0xFF, 0xFF, 0xFF, 0xFF, },
362 { 0xFF, 0xFF, 0xFF, 0xFF, },
363 { 0xFF, 0xFF, 0xFF, 0xFF, },
364 { 0xFF, 0xFF, 0xFF, 0xFF, },
365 // 0x50
366 { 0x04, 0x04, 0x04, 0x04, },
367 { 0x0e, 0x0e, 0x0e, 0x0e, },
368 { 0xFF, 0xFF, 0xFF, 0xFF, },
369 { 0xFF, 0xFF, 0xFF, 0xFF, },
370 { 0xFF, 0xFF, 0xFF, 0xFF, },
371 { 0xFF, 0xFF, 0xFF, 0xFF, },
372 { 0xFF, 0xFF, 0xFF, 0xFF, },
373 { 0xFF, 0xFF, 0xFF, 0xFF, },
374 { 0xFF, 0xFF, 0xFF, 0xFF, },
375 { 0xFF, 0xFF, 0xFF, 0xFF, },
376 { 0xFF, 0xFF, 0xFF, 0xFF, },
377 { 0xFF, 0xFF, 0xFF, 0xFF, },
378 { 0xFF, 0xFF, 0xFF, 0xFF, },
379 { 0xFF, 0xFF, 0xFF, 0xFF, },
380 { 0xFF, 0xFF, 0xFF, 0xFF, },
381 { 0xFF, 0xFF, 0xFF, 0xFF, },
382 // 0x60
383 { 0xFF, 0xFF, 0xFF, 0xFF, },
384 { 0xFF, 0xFF, 0xFF, 0xFF, },
385 { 0xFF, 0xFF, 0xFF, 0xFF, },
386 { 0xFF, 0xFF, 0xFF, 0xFF, },
387 { 0xFF, 0xFF, 0xFF, 0xFF, },
388 { 0xFF, 0xFF, 0xFF, 0xFF, },
389 { 0xFF, 0xFF, 0xFF, 0xFF, },
390 { 0xFF, 0xFF, 0xFF, 0xFF, },
391 { 0xFF, 0xFF, 0xFF, 0xFF, },
392 { 0xFF, 0xFF, 0xFF, 0xFF, },
393 { 0xFF, 0xFF, 0xFF, 0xFF, },
394 { 0xFF, 0xFF, 0xFF, 0xFF, },
395 { 0xFF, 0xFF, 0xFF, 0xFF, },
396 { 0xFF, 0xFF, 0xFF, 0xFF, },
397 { 0xFF, 0xFF, 0xFF, 0xFF, },
398 { 0xFF, 0xFF, 0xFF, 0xFF, },
399 // 0x70
400 { 0xFF, 0xFF, 0xFF, 0xFF, },
401 { 0xFF, 0xFF, 0xFF, 0xFF, },
402 { 0xFF, 0xFF, 0xFF, 0xFF, },
403 { 0xFF, 0xFF, 0xFF, 0xFF, },
404 { 0xFF, 0xFF, 0xFF, 0xFF, },
405 { 0xFF, 0xFF, 0xFF, 0xFF, },
406 { 0xFF, 0xFF, 0xFF, 0xFF, },
407 { 0xFF, 0xFF, 0xFF, 0xFF, },
408 { 0xFF, 0xFF, 0xFF, 0xFF, },
409 { 0xFF, 0xFF, 0xFF, 0xFF, },
410 { 0xFF, 0xFF, 0xFF, 0xFF, },
411 { 0xFF, 0xFF, 0xFF, 0xFF, },
412 { 0xFF, 0xFF, 0xFF, 0xFF, },
413 { 0xFF, 0xFF, 0xFF, 0xFF, },
414 { 0xFF, 0xFF, 0xFF, 0xFF, },
415 { 0xFF, 0xFF, 0xFF, 0xFF, },
416
417 };
418
419 static int KBIndexTab[8] = { 0, 1, 2, 2, 3, 3, 3, 3 };
420
421 //-----------------------------------------------------------------------------
422
423 static void KeyboardInit
424 (
425 void
426 )
427 {
428 KBFlags = 0;
429
430 } /* KeyboardInit */
431
432 //-----------------------------------------------------------------------------
433
434 static CYG_BYTE KeyboardAscii
435 (
436 CYG_BYTE scancode
437 )
438 {
439 CYG_BYTE ascii = 0xFF;
440
441 // Start by handling all shift/ctl keys:
442
443 switch( scancode )
444 {
445 case 0xe0:
446 KBFlags |= KBExtend;
447 return 0xFF;
448
449 case 0xfa:
450 KBFlags |= KBAck;
451 return 0xFF;
452
453 case 0xfe:
454 KBFlags |= KBResend;
455 return 0xFF;
456
457 case LSHIFT:
458 KBFlags |= KBShiftL;
459 return 0xFF;
460
461 case LSHIFT | BREAK:
462 KBFlags &= ~KBShiftL;
463 return 0xFF;
464
465 case RSHIFT:
466 KBFlags |= KBShiftR;
467 return 0xFF;
468
469 case RSHIFT | BREAK:
470 KBFlags &= ~KBShiftR;
471 return 0xFF;
472
473 case CTRL:
474 if( KBFlags & KBExtend )
475 {
476 KBFlags |= KBCtrlR;
477 KBFlags &= ~KBExtend;
478 }
479 else KBFlags |= KBCtrlL;
480 return 0xFF;
481
482 case CTRL | BREAK:
483 if( KBFlags & KBExtend )
484 {
485 KBFlags &= ~KBCtrlR;
486 KBFlags &= ~KBExtend;
487 }
488 else KBFlags &= ~KBCtrlL;
489 return 0xFF;
490
491
492 case ALT:
493 if( KBFlags & KBExtend )
494 {
495 KBFlags |= KBAltR;
496 KBFlags &= ~KBExtend;
497 }
498 else KBFlags |= KBAltL;
499 return 0xFF;
500
501 case ALT | BREAK:
502 if( KBFlags & KBExtend )
503 {
504 KBFlags &= ~KBAltR;
505 KBFlags &= ~KBExtend;
506 }
507 else KBFlags &= ~KBAltL;
508 return 0xFF;
509
510 case CAPS:
511 KBFlags ^= KBCapsLock;
512 case CAPS | BREAK:
513 return 0xFF;
514
515 case NUMS:
516 KBFlags ^= KBNumLock;
517 case NUMS | BREAK:
518 return 0xFF;
519
520 }
521
522 // Clear Extend flag if set
523 KBFlags &= ~KBExtend;
524
525 // Ignore all other BREAK codes
526 if( scancode & 0x80 ) return 0xFF;
527
528 // Here the scancode is for something we can turn
529 // into an ASCII value
530
531 ascii = KBScanTable[scancode & 0x7F][KBIndexTab[KBFlags & KBIndex]];
532
533 return ascii;
534
535 } /* KeyboardAscii */
536
537 //-----------------------------------------------------------------------------
538
539 static int KeyboardTest
540 (
541 void
542 )
543 {
544 // If there is a pending character, return True
545 if( KBPending != 0xFF ) return true;
546
547
548 // If there is something waiting at the port, get it
549 while( pc_inb(KBSTATPORT) & 0x01 )
550 {
551 CYG_BYTE code = pc_inb(KBDATAPORT);
552
553 // Translate to ASCII
554 CYG_BYTE c = KeyboardAscii(code);
555
556 // if it is a real ASCII char, save it and
557 // return True.
558 if( c != 0xFF )
559 {
560 KBPending = c;
561 return true;
562 }
563
564 }
565
566 // Otherwise return False
567 return false;
568
569 } /* KeyboardTest */
570
571 //-----------------------------------------------------------------------------
572
573 static CYG_BYTE KeyboardRead
574 (
575 void
576 )
577 {
578 CYG_BYTE c;
579
580 // Loop until a character is ready
581 while( !KeyboardTest() ) continue;
582
583 // get it
584 c = KBPending;
585 KBPending = 0xFF;
586
587 // and return it
588 return c;
589
590
591 } /* KeyboardRead */
592
593
594 //-----------------------------------------------------------------------------
595
596 void hal_diag_init(void)
597 {
598 KeyboardInit();
599
600 XPos = 0;
601 YPos = 0;
602
603 ClearScreen();
604 MoveCursor();
605
606 }
607
608 //-----------------------------------------------------------------------------
609
610 void hal_diag_write_char(char ch)
611 {
612 switch( ch )
613 {
614 case '\n':
615 NewLine();
616 return;
617
618 case '\r':
619 XPos = 0;
620 MoveCursor();
621 return;
622
623 case '\b':
624 if( XPos == 0 ) return;
625 XPos--;
626 MoveCursor();
627 return;
628
629 case '\t':
630 do
631 {
632 DisplayChar(' ');
633 } while( (XPos % 8) != 0 );
634 return;
635
636 case 0x0c:
637 ClearScreen();
638 XPos = YPos = 0;
639 MoveCursor();
640 return;
641
642 case 1:
643 ScrollUp(1);
644 XPos = 0;
645 YPos = ScreenLength-1;
646 return;
647
648 case 2:
649 ScrollDown(1);
650 XPos = 0;
651 YPos = 0;
652 return;
653
654
655 default:
656 DisplayChar(ch);
657 return;
658 }
659 }
660
661 //-----------------------------------------------------------------------------
662
663 void hal_diag_read_char(char *c)
664 {
665 *c = KeyboardRead();
666 }
667
668 #endif
669
670 //-----------------------------------------------------------------------------
671 //-----------------------------------------------------------------------------
672
673 # define SERIAL_COM1 (0x3F8)
674 # define SERIAL_COM2 (0x2F8)
675
676
677 #if defined(CYGSEM_HAL_I386_PC_DIAG_SERIAL1)
678 # define SERIAL_COM SERIAL_COM1
679 #define CYG_KERNEL_DIAG_GDB // turn on GDB debug packets
680 #elif defined(CYGSEM_HAL_I386_PC_DIAG_SERIAL2)
681 # define SERIAL_COM SERIAL_COM2
682 #endif
683
684 #ifdef SERIAL_COM
685
686 # define TBR (0x00)
687 # define RBR (0x00)
688 # define IER (0x01)
689 # define LCR (0x03)
690 # define MCR (0x04)
691 # define LSR (0x05)
692 # define DLL (0x00)
693 # define DLH (0x01)
694 # define FCR (0x02)
695
696 /* Configuration for 38400 baud, N81. */
697 # define BAUD_LOW (3)
698 #if 0
699 /* Configuration for 19200 baud, N81. */
700 # undef BAUD_LOW
701 # define BAUD_LOW (6)
702 /* Configuration for 9600 baud, N81. */
703 # undef BAUD_LOW
704 # define BAUD_LOW (12)
705 #endif
706 # define BAUD_HIGH (0)
707 # define WM_N81 (3)
708
709 //-----------------------------------------------------------------------------
710
711
712 int com1 ;
713
714 //-----------------------------------------------------------------------------
715
716 void hal_diag_init(void)
717 {
718 com1 = SERIAL_COM ;
719
720 /* Initialize the serial port: don't send interrupts; don't go into test mode. */
721 pc_outb(com1 + IER, 0);
722 pc_outb(com1 + IER, 0);
723 pc_outb(com1 + MCR, 0) ;
724
725 /* Configure the baud rate & word mode. */
726 pc_outb(com1 + LCR, 0x80) ;
727 pc_outb(com1 + DLL, BAUD_LOW);
728 pc_outb(com1 + DLH, BAUD_HIGH);
729 pc_outb(com1 + LCR, WM_N81) ;
730 }
731
732 //-----------------------------------------------------------------------------
733 /* Send out a character via debugger output. */
734
735 void hal_diag_write_char_serial(char __c)
736 {
737 int x;
738
739 do
740 { x = pc_inb(com1 + LSR) ;
741 } while (!(x & 0x60)) ;
742
743 pc_outb(com1 + TBR, __c) ;
744 }
745
746 //-----------------------------------------------------------------------------
747 /* read and return a single char */
748
749 void hal_diag_read_char_serial(char *c)
750 {
751 int x;
752
753 do
754 { x = pc_inb(com1 + LSR) ;
755 } while (!(x & 0x01)) ;
756
757 c[0] = pc_inb(com1 + RBR) ;
758 }
759
760 //-----------------------------------------------------------------------------
761
762 void hal_diag_write_char(char c)
763 {
764 #ifdef CYG_KERNEL_DIAG_GDB
765 static char line[100];
766 static int pos = 0;
767
768 // No need to send CRs
769 if( c == '\r' ) return;
770
771 line[pos++] = c;
772
773 if( c == '\n' || pos == sizeof(line) )
774 {
775
776 // Disable interrupts. This prevents GDB trying to interrupt us
777 // while we are in the middle of sending a packet. The serial
778 // receive interrupt will be seen when we re-enable interrupts
779 // later.
780 CYG_INTERRUPT_STATE oldstate;
781 HAL_DISABLE_INTERRUPTS(oldstate);
782
783 while(1)
784 {
785 static char hex[] = "0123456789ABCDEF";
786 cyg_uint8 csum = 0;
787 int i;
788 char c1;
789
790 hal_diag_write_char_serial('$');
791 hal_diag_write_char_serial('O');
792 csum += 'O';
793 for( i = 0; i < pos; i++ )
794 {
795 char ch = line[i];
796 char h = hex[(ch>>4)&0xF];
797 char l = hex[ch&0xF];
798 hal_diag_write_char_serial(h);
799 hal_diag_write_char_serial(l);
800 csum += h;
801 csum += l;
802 }
803 hal_diag_write_char_serial('#');
804 hal_diag_write_char_serial(hex[(csum>>4)&0xF]);
805 hal_diag_write_char_serial(hex[csum&0xF]);
806
807 hal_diag_read_char_serial( &c1 );
808
809 if( c1 == '+' ) break;
810
811 // if( cyg_hal_is_break( &c1 , 1 ) )
812 // cyg_hal_user_break( NULL );
813
814 }
815
816 pos = 0;
817
818 // Wait for all data from serial line to drain
819 // and clear ready-to-send indication.
820 // hal_diag_drain_serial0();
821
822 // And re-enable interrupts
823 HAL_RESTORE_INTERRUPTS( oldstate );
824
825 }
826 #else
827 hal_diag_write_char_serial(c);
828 #endif
829 }
830
831 //-----------------------------------------------------------------------------
832
833 void hal_diag_read_char(char *c)
834 {
835 hal_diag_read_char_serial(c);
836 }
837
838 #endif
839
840 //-----------------------------------------------------------------------------
841 // End of hal_diag.c
842