sio.h

Description | Download | Table of Contents | Modules | Compound List | File List | Functions


Overview
Compiler
Documentation
Examples
Misc
Help
IDE & Tools

Download
Install

Links
Projects






00001 /* asm-m68hc12/sio.h -- Utility methods to read/write the SIO
00002    Copyright 2000 Free Software Foundation, Inc.
00003    Written by Stephane Carrez (stcarrez@worldnet.fr)
00004 
00005 This file is part of GDB, GAS, and the GNU binutils.
00006 
00007 GDB, GAS, and the GNU binutils are free software; you can redistribute
00008 them and/or modify them under the terms of the GNU General Public
00009 License as published by the Free Software Foundation; either version
00010 1, or (at your option) any later version.
00011 
00012 GDB, GAS, and the GNU binutils are distributed in the hope that they
00013 will be useful, but WITHOUT ANY WARRANTY; without even the implied
00014 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
00015 the GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with this file; see the file COPYING.  If not, write to the Free
00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00020 
00021 #ifndef _M68HC12_SIO_H
00022 #define _M68HC12_SIO_H
00023 
00024 #if M6812_STDOUT_PORT == 0
00025 # define M6812_SCBD   M6812_SC0BD
00026 # define M6812_SCCR1  M6812_SC0CR1
00027 # define M6812_SCCR2  M6812_SC0CR2
00028 # define M6812_SCSR1  M6812_SC0SR1
00029 # define M6812_SCDR   M6812_SC0DRL
00030 #elif M6812_STDOUT_PORT == 1
00031 # define M6812_SCBD   M6812_SC1BD
00032 # define M6812_SCCR1  M6812_SC1CR1
00033 # define M6812_SCCR2  M6812_SC1CR2
00034 # define M6812_SCSR1  M6812_SC1SR1
00035 # define M6812_SCDR   M6812_SC1DRL
00036 #else
00037 # error "M6812_STDOUT_PORT must be defined to either 0 or 1"
00038 #endif
00039 
00040 extern inline void
00041 serial_init (void)
00042 {
00043   ((unsigned volatile short*) &_io_ports[M6812_SCBD])[0] = M6812_DEF_BAUD;
00044 
00045   /* Setup character format 1 start, 8-bits, 1 stop.  */
00046   _io_ports[M6812_SCCR1] = 0;
00047 
00048   /* Enable reciever and transmitter.  */
00049   _io_ports[M6812_SCCR2] = 0xc;
00050 }
00051 
00052 /* Return != 0 if there is something to read on the serial line.  */
00053 extern inline unsigned char
00054 serial_receive_pending (void)
00055 {
00056   return _io_ports[M6812_SCSR1] & M6812_RDRF;
00057 }
00058 
00059 /* Wait until the SIO has finished to send the character.  */
00060 extern inline void
00061 serial_flush (void)
00062 {
00063   while (!(_io_ports[M6812_SCSR1] & M6812_TDRE))
00064     cop_optional_reset ();
00065 }
00066 
00067 /* Send the character on the serial line.  */
00068 extern inline void
00069 serial_send (char c)
00070 {
00071   serial_flush ();
00072   _io_ports[M6812_SCDR] = c;
00073   _io_ports[M6812_SCCR2] |= M6812_TE;
00074 }
00075 
00076 /* Wait for a character on the serial line and return it.  */
00077 extern inline unsigned char
00078 serial_recv (void)
00079 {
00080   while (!(_io_ports[M6812_SCSR1] & M6812_RDRF))
00081     cop_optional_reset ();
00082 
00083   return _io_ports[M6812_SCDR];
00084 }
00085 
00086 #endif /* _M68HC12_SIO_H */
00087 

Description | Download | Table of Contents | Modules | Compound List | File List | Functions

    Last modified,
    Apr 16, 2001
[ Copying ]     [ Feedback to Stephane.Carrez@worldnet.fr ]