Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc / device / lib / _ser.c
blob460c07486ef83b5df60842a079cc84a5569033ec
1 /*-------------------------------------------------------------------------
2 _ser.c - this file contains a simple interrupt driven serial driver with
3 buffer (no check for overflow!!!).
5 Copyright (C) 1999, Sandeep Dutta <sandeep.dutta AT ieee.org>
7 This library is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this library; see the file COPYING. If not, write to the
19 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
20 MA 02110-1301, USA.
22 As a special exception, if you link this library with other files,
23 some of which are compiled with SDCC, to produce an executable,
24 this library does not by itself cause the resulting executable to
25 be covered by the GNU General Public License. This exception does
26 not however invalidate any other reasons why the executable file
27 might be covered by the GNU General Public License.
28 -------------------------------------------------------------------------*/
30 /*KA******************************************************************
31 * PROJECT: PL-One/8052
32 **********************************************************************
33 * FILE: ser.c
34 **********************************************************************
35 * CHANGES:
36 * date author description
37 * --------------------------------------------------------------------
38 * 04/26/99 we final
39 * 04/27/99 we comments
40 **********************************************************************
41 * DESCRIPTION:
42 * This file contains a simple interrupt driven serial driver with
43 * buffer (no check for overflow!!!).
44 **********************************************************************
45 * FUNCTIONS DECLARED:
46 * ser_init Initialization; must be called first
47 * ser_putc output one char on the serial line
48 * ser_getc return a char if one has been received, else 0
49 * ser_printString print a 0-terminated string
50 * ser_charAvail return 1 if a char arrived on serial line
51 **********************************************************************
52 * NOTE:
53 * Remember to enable all interrupts (EA=1) outside of this module!!
54 **********************************************************************
55 * COMPILE TIME OPTIONS: -
56 * DEBUG OPTIONS: -
57 ******************************************************************KE*/
59 #include <8052.h>
61 #include "ser.h"
63 #define NON_BLOCKING
65 unsigned char __xdata ser_txIndexIn;
66 unsigned char __xdata ser_txIndexOut;
67 unsigned char __xdata ser_rxIndexIn;
68 unsigned char __xdata ser_rxIndexOut;
70 unsigned char __xdata ser_txBuffer[0x100];
71 unsigned char __xdata ser_rxBuffer[0x100];
73 static __bit ser_txBusy;
75 void
76 ser_init(void)
78 ES = 0;
80 ser_txBusy = 0;
82 ser_txIndexIn = 0;
83 ser_txIndexOut = 0;
84 ser_rxIndexIn = 0;
85 ser_rxIndexOut = 0;
87 T2CON = 0x30;
89 /* Baudrate = 19200, oscillator frq. of my processor is 21.4772 MHz */
90 RCAP2H = 0xFF;
91 RCAP2L = 0xDD;
93 /* enable counter */
94 T2CON = 0x34;
96 SCON = 0x50;
98 if (TI) {
99 TI = 0;
101 if (RI) {
102 RI = 0;
105 ES=1;
108 void
109 ser_interrupt_handler(void) __interrupt (4) __using (1)
111 ES=0;
113 if (RI) {
114 RI = 0;
115 ser_rxBuffer[ser_rxIndexIn++] = SBUF;
118 if (TI) {
119 TI = 0;
120 if (ser_txIndexIn == ser_txIndexOut) {
121 ser_txBusy = 0;
123 else {
124 SBUF = ser_txBuffer[ser_txIndexOut++];
128 ES=1;
131 void
132 ser_putc(unsigned char c)
134 ES=0;
136 if (ser_txBusy) {
137 ser_txBuffer[ser_txIndexIn++] = c;
139 else {
140 ser_txBusy = 1;
141 SBUF = c;
144 ES=1;
147 unsigned char
148 ser_getc(void)
150 char tmp;
152 #ifdef NON_BLOCKING
153 if (ser_rxIndexIn != ser_rxIndexOut) {
154 tmp = ser_rxBuffer[ser_rxIndexOut++];
156 else {
157 tmp = 0;
159 #endif
161 return(tmp);
164 void
165 ser_printString(char *String)
167 while (*String) {
168 ser_putc(*String++);
172 char
173 ser_charAvail(void)
175 char ret = 0;
177 if (ser_rxIndexIn != ser_rxIndexOut) {
178 ret = 1;
181 return(ret);
184 /*********************End of File************************************/