Mercurial > ecos
comparison packages/cygmon/current/misc/bsp/common/console-io.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 | e0c0827131d1 |
comparison
equal
deleted
inserted
replaced
| 75:41bf073c0c32 | 76:435cced73e2f |
|---|---|
| 1 //========================================================================== | |
| 2 // | |
| 3 // console-io.c | |
| 4 // | |
| 5 // BSP Console Channel Interfaces. | |
| 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): | |
| 35 // Contributors: gthomas | |
| 36 // Date: 1999-10-20 | |
| 37 // Purpose: BSP Console Channel Interfaces. | |
| 38 // Description: | |
| 39 // | |
| 40 // | |
| 41 //####DESCRIPTIONEND#### | |
| 42 // | |
| 43 //========================================================================= | |
| 44 | |
| 45 | |
| 46 #include <stdlib.h> | |
| 47 #include <bsp/bsp.h> | |
| 48 #include "bsp_if.h" | |
| 49 | |
| 50 static unsigned char __console_ungetc; | |
| 51 | |
| 52 void | |
| 53 bsp_console_write(const char *p, int len) | |
| 54 { | |
| 55 struct bsp_comm_procs *com; | |
| 56 | |
| 57 if ((com = bsp_shared_data->__console_procs) != NULL) | |
| 58 com->__write(com->ch_data, p, len); | |
| 59 else | |
| 60 bsp_debug_write(p, len); | |
| 61 } | |
| 62 | |
| 63 | |
| 64 int | |
| 65 bsp_console_read(char *p, int len) | |
| 66 { | |
| 67 struct bsp_comm_procs *com; | |
| 68 | |
| 69 if (len <= 0) | |
| 70 return 0; | |
| 71 | |
| 72 if ((com = bsp_shared_data->__console_procs) != NULL) { | |
| 73 if (__console_ungetc) { | |
| 74 *p = __console_ungetc; | |
| 75 __console_ungetc = 0; | |
| 76 return 1; | |
| 77 } | |
| 78 return com->__read(com->ch_data, p, len); | |
| 79 } else | |
| 80 return bsp_debug_read(p, len); | |
| 81 } | |
| 82 | |
| 83 /*#define PRINTABLE_ONLY*/ | |
| 84 #ifdef PRINTABLE_ONLY | |
| 85 #include <ctype.h> | |
| 86 #endif /* PRINTABLE_ONLY */ | |
| 87 | |
| 88 void | |
| 89 bsp_console_putc(char ch) | |
| 90 { | |
| 91 struct bsp_comm_procs *com; | |
| 92 | |
| 93 #ifdef PRINTABLE_ONLY | |
| 94 if ((!isprint(ch)) && (!isspace(ch))) | |
| 95 ch = '.'; | |
| 96 #endif /* PRINTABLE_ONLY */ | |
| 97 | |
| 98 if ((com = bsp_shared_data->__console_procs) != NULL) | |
| 99 com->__putc(com->ch_data, ch); | |
| 100 else | |
| 101 bsp_debug_putc(ch); | |
| 102 } | |
| 103 | |
| 104 int | |
| 105 bsp_console_getc(void) | |
| 106 { | |
| 107 struct bsp_comm_procs *com; | |
| 108 int ch; | |
| 109 | |
| 110 if ((com = bsp_shared_data->__console_procs) != NULL) { | |
| 111 if (__console_ungetc) { | |
| 112 ch = __console_ungetc; | |
| 113 __console_ungetc = 0; | |
| 114 return ch; | |
| 115 } | |
| 116 return com->__getc(com->ch_data); | |
| 117 } else | |
| 118 return bsp_debug_getc(); | |
| 119 } | |
| 120 | |
| 121 | |
| 122 void | |
| 123 bsp_console_ungetc(char ch) | |
| 124 { | |
| 125 if (bsp_shared_data->__console_procs != NULL) | |
| 126 __console_ungetc = (unsigned char)ch; | |
| 127 else | |
| 128 bsp_debug_ungetc(ch); | |
| 129 } | |
| 130 | |
| 131 |
