From cc8315d482ccda828b33aa76eee555835a5e94d3 Mon Sep 17 00:00:00 2001 From: jesusc Date: Wed, 25 Oct 2006 02:37:36 +0000 Subject: [PATCH] device/lib/_putchar.c,_getchar.c, inituart.c replacements for serial_io.c git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4435 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 6 +++++ device/lib/Makefile.in | 2 +- device/lib/_getchar.c | 37 ++++++++++++++++++++++++++ device/lib/{serial_io.c => _putchar.c} | 29 +++----------------- device/lib/inituart.c | 36 +++++++++++++++++++++++++ device/lib/libsdcc.lib | 4 ++- 6 files changed, 87 insertions(+), 27 deletions(-) create mode 100644 device/lib/_getchar.c rename device/lib/{serial_io.c => _putchar.c} (67%) create mode 100644 device/lib/inituart.c diff --git a/ChangeLog b/ChangeLog index db580e71..58c525e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-10-24 Jesus Calvino-Fraga + + * device/lib/serial_io.c: removed + * device/lib/_putchar.c, device/lib/_getchar.c, device/lib/inituart.c + replacements for serial_io.c + 2006-10-24 Maarten Brock * src/z80/main.c (_process_pragma, _parseOptions): fixed bug 1583318 diff --git a/device/lib/Makefile.in b/device/lib/Makefile.in index 6a0ab9c1..74a9e490 100644 --- a/device/lib/Makefile.in +++ b/device/lib/Makefile.in @@ -69,7 +69,7 @@ OPT_DISABLE_Z80 = @OPT_DISABLE_Z80@ SOURCES = _autobaud.c _bp.c _decdptr.c \ _gptrget.c _gptrgetc.c _gptrput.c \ _ser.c _setjmp.c \ - serial.c serial_io.c ser_ir.c \ + serial.c inituart.c _putchar.c _getchar.c ser_ir.c \ _atof.c _atoi.c _atol.c _itoa.c _ltoa.c \ _schar2fs.c _sint2fs.c _slong2fs.c \ _uchar2fs.c _uint2fs.c _ulong2fs.c \ diff --git a/device/lib/_getchar.c b/device/lib/_getchar.c new file mode 100644 index 00000000..2cbf71da --- /dev/null +++ b/device/lib/_getchar.c @@ -0,0 +1,37 @@ +/* Default getchar() using the serial port + + Written By - Jesus Calvino-Fraga (October/2006) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifdef SDCC_mcs51 +#include <8051.h> + +extern bit uart_init_flag; +void inituart(unsigned char t1_reload); + +char getchar (void) +{ + char c; + + if(!uart_init_flag) inituart(0xff); + + while (!RI); + RI=0; + c=SBUF; + return c; +} +#endif diff --git a/device/lib/serial_io.c b/device/lib/_putchar.c similarity index 67% rename from device/lib/serial_io.c rename to device/lib/_putchar.c index 29ad7460..dec4601c 100644 --- a/device/lib/serial_io.c +++ b/device/lib/_putchar.c @@ -1,4 +1,4 @@ -/* Default putchar and getchar to the serial port +/* Default polling putchar() using to the serial port Written By - Jesus Calvino-Fraga (October/2006) @@ -20,22 +20,12 @@ #ifdef SDCC_mcs51 #include <8051.h> -bit serial_init_flag=0; - -void init_serial (void) -{ - TR1=0; - TMOD=(TMOD&0x0f)|0x20; - PCON|=0x80; - TH1=TL1=0xff; //115200 baud with a 22MHz crystal - TR1=1; - SCON=0x52; - serial_init_flag=1; -} +extern bit uart_init_flag; +void inituart(unsigned char t1_reload); void putchar (char c) { - if(!serial_init_flag) init_serial(); + if(!uart_init_flag) inituart(0xff); if (c=='\n') { while (!TI); @@ -47,15 +37,4 @@ void putchar (char c) SBUF=c; } -char getchar (void) -{ - char c; - - if(!serial_init_flag) init_serial(); - - while (!RI); - RI=0; - c=SBUF; - return c; -} #endif diff --git a/device/lib/inituart.c b/device/lib/inituart.c new file mode 100644 index 00000000..9a41c3d3 --- /dev/null +++ b/device/lib/inituart.c @@ -0,0 +1,36 @@ +/* Uart initialization for putchar() and getchar() + + Written By - Jesus Calvino-Fraga (October/2006) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifdef SDCC_mcs51 +#include <8051.h> + +bit uart_init_flag=0; + +void inituart (unsigned char t1_reload) +{ + TR1=0; + TMOD=(TMOD&0x0f)|0x20; + PCON|=0x80; + TH1=TL1=t1_reload; + TR1=1; + SCON=0x52; + uart_init_flag=1; +} + +#endif diff --git a/device/lib/libsdcc.lib b/device/lib/libsdcc.lib index fc6cf879..68e52a10 100644 --- a/device/lib/libsdcc.lib +++ b/device/lib/libsdcc.lib @@ -44,7 +44,9 @@ malloc realloc free serial -serial_io +inituart +_putchar +_getchar _autobaud _startup _ser -- 2.30.2