/*
    SCN2681_DUART.h, Copyright  (c) by George Fankhauser,
    Swiss Federal Institute of Technology,
    Computer Engineering and Networks Laboratory.
 
    TOPSY -- A Teachable Operating System.
             Implementation of a tiny and simple
             micro kernel for teaching purposes.
 
    For further information, please visit http://www.tik.ee.ethz.ch/~topsy
 
    This software is provided under the terms of the GNU General Public Licence.
 
    A full copy of the GNU GPL is provided in the file COPYING found in the 
    development root of Topsy.
*/
/*
	File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/IO/mips/Drivers/SCN2681_DUART.h,v $
 	Author(s):             George Fankhauser
 	Affiliation:           ETH Zuerich, TIK
 	Version:               $Revision: 2922 $
 	Creation Date:         
 	Last Date of Change:   $Date: 2007-03-19 17:48:52 +0100 (Mon, 19 Mär 2007) $      by: $Author: baderma $
	
	
	$Log: SCN2681_DUART.h,v $
	Revision 1.1.12.1  2002/02/28 08:24:48  cjeker
	beautified the output of dumpMemory. Fixed a bug in tmGetInfo and removed Boris debug stuff from ioWrite.
	
	Revision 1.1  2000/11/15 10:02:48  ruf
	IO Directory structure change
	
	Revision 1.12  1999/12/13 21:48:26  ruf
	GNU General Public Licence Update
	
	Revision 1.11  1999/10/23 14:19:43  jeker
	first cleanup for R4k support
	
	Revision 1.10  1999/10/21 20:22:24  jeker
	first commit for the R4k support
 
	Revision 1.9  1999/01/06 17:47:34  cjeker
	code cleaning
 
	Revision 1.8  1997/04/14 21:08:16  conrad
	*** empty log message ***
	
 * Revision 1.7  1997/04/07  13:26:00  gfa
 * new version using driver framework
 *
 * Revision 1.6  1997/03/26  10:58:29  gfa
 * added bi-endian switch
 *
 * Revision 1.5  1997/03/23  12:45:53  gfa
 * first crude polling version for simulator, needs to be changed to
 * shared interrupt mode...
 *
 * Revision 1.4  1997/03/19  07:26:05  gfa
 * first hack using ioCOnsole...
 *
 * Revision 1.3  1997/02/24  07:40:03  gfa
 * *** empty log message ***
 *
 * Revision 1.2  1997/02/23  16:15:19  gfa
 * *** empty log message ***
 *
 * driver code for the philips SCN2681 dual universal asynchronous
 * receiver and transmitter (short: serial device chip :-)
*/
#ifndef _SCN2681_DUART_H_
#define _SCN2681_DUART_H_

#include "Topsy.h"
#include "MMHeapMemory.h"
#include "IODevice.h"
#include "Configuration.h"


#define MODE_REGISTER    0x0	/* SCN2681 register layout */
#define STATUS_REGISTER 0x4
#define COMMAND_REGISTER 0x8
#define TX_REGISTER 0x0c
#define RX_REGISTER TX_REGISTER
#define INTERRUPT_REGISTER 0x14

#define READY_TO_SEND 0x04	/* ready to send status */
#define RECV_MASK 0x01		/* a byte has arrived */

#define SCN2681_BUFSIZE 128

#define UART_REGISTER_SET_SIZE 0x20   /* size for one channel */

typedef struct devSCN2681Desc_t
{
  unsigned long in, out;
  ThreadId wait;
  char* waitbuf;
  IODevice otherChannel;
}
devSCN2681Desc;

typedef devSCN2681Desc* devSCN2681;

void devSCN2681_interruptHandler(IODevice this);
Error devSCN2681_init(IODevice this);
Error devSCN2681_read(IODevice this, ThreadId threadId, char* buffer, long int* size);
Error devSCN2681_write(IODevice this, ThreadId threadId, char* buffer, long int* size);
Error devSCN2681_close(IODevice this);

#endif

