/*-------------------------------------------------------------------------- * SDCC serial line routines based on ROM routines provided with * Texas Intruments MSC12xx MCU family chips * * Written By - Philippe Latu / philippe.latu(at)linux-france.org * $Id: ser_msc1210.h 1133 2007-05-10 09:09:46Z latu $ * * Copyright (C) 2006,2007 Philippe Latu * * 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 FITNES0S 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * *---------------------------------------------------------------------------*/ #ifndef __SER_MSC1210_H #define __SER_MSC1210_H #include "rom1210.h" /* ROM routine based ser_putc * put a signle character on serial line */ void ser_putc(unsigned char c) { // tx_byte(c); c; _asm; mov r7,dpl ljmp _tx_byte _endasm; } /* Custom made ser_puts * put a string on serial line character by character */ void ser_puts(char code * data s) { while (*s != 0) ser_putc((unsigned char) *s++); } /* Custom made ser_getc * grab a single character on serial line */ /*unsigned char ser_getc(void) { __idata unsigned char c; while(!RI) ; c = SBUF; RI = 0; return c; }*/ // ROM routine based ser_getc unsigned char ser_getc(void) __naked { // return rx_byte(); _asm; lcall _rx_byte mov dpl,r7 ret _endasm; } /* Custom made ser_getc_echo * grab a single character on serial line with echo */ /* unsigned char ser_getc_echo(void) { __idata unsigned char c; c = ser_getc(); ser_putc(c); return c; }*/ // ROM routine based ser_getc_echo unsigned char ser_getc_echo(void) __naked { // c = rx_byte_echo(); _asm; lcall _rx_byte_echo mov dpl,r7 ret _endasm; } /* Custom made ser_gets * grab a string from serial line character by character * until '\r' is hit or maximum 'len'gth is reached */ void ser_gets(unsigned char *s, unsigned char len) { while (((*s++ = ser_getc()) != '\r') && (len-- > 0)) ; if (*(s-1) == '\r') s--; *s = '\0'; } /* Custom made ser_gets_echo * grab a string from serial line character by character * until '\r' is hit or maximum 'len'gth is reached. * Each character is echoed */ void ser_gets_echo(unsigned char *s, unsigned char len) { while (((*s++ = ser_getc_echo()) != '\r') && (len-- > 0)) ; if (*(s-1) == '\r') s--; *s = '\0'; } #endif