home *** CD-ROM | disk | FTP | other *** search
- /*
- compile: Lc -cfistq -j73 $*
- */
-
- #include <exec/types.h>
- #include <devices/serial.h>
- #include <exec/devices.h>
- #include <exec/errors.h>
- #include <exec/exec.h>
- #include <exec/io.h>
- #include <exec/ports.h>
- #include <exec/semaphores.h>
-
- #include <proto/exec.h>
-
- #include "async.h"
-
- static struct MsgPort *MsgPort = NULL;
- static struct IOExtSer *IOExtSer = NULL;
- static long DeviceError = 0x00ff;
- /*
- ;-----------------------------------------------------------------------------
- ; AsyncInit Initalize Serial Port and install ISR
- ;-----------------------------------------------------------------------------
- ; int AsyncInit( int port)
- ;
- ; Where Port is
- ; 0 = COM1
- ; 1 = COM2
- ; 2 = COM3
- ; 3 = COM4
- ;
- ;-----------------------------------------------------------------------------
- */
- int AsyncInit( int port)
- {
- if (MsgPort = CreatePort(NULL, 0L))
- {
- if(IOExtSer = (struct IOExtSer *)CreateExtIO(MsgPort,sizeof(struct IOExtSer)))
- {
- IOExtSer->io_Baud=9600;
- IOExtSer->io_SerFlags=SERF_XDISABLED;
- DeviceError=OpenDevice("serial.device",0L,IOExtSer,0L);
- }
- }
- return DeviceError;
- };
-
- /*
- ;-----------------------------------------------------------------------------
- ; AsyncStop Uninstall ISR
- ;-----------------------------------------------------------------------------
- ; void AsyncStop( void)
- ;-----------------------------------------------------------------------------
- */
- void AsyncStop( void)
- {
- if (DeviceError == 0) CloseDevice(IOExtSer);
- if (IOExtSer) DeleteExtIO(IOExtSer);
- if (MsgPort) DeletePort(MsgPort);
- };
- /*
- ;-----------------------------------------------------------------------------
- ; AsyncIn Gets a byte from the input buffer
- ;-----------------------------------------------------------------------------
- ; int AsyncIn( void)
- ;-----------------------------------------------------------------------------
- */
- int AsyncIn( void)
- {
- char data=0x00;
-
- IOExtSer->IOSer.io_Command=CMD_READ;
- IOExtSer->IOSer.io_Flags=NULL;
- IOExtSer->IOSer.io_Length=1;
- IOExtSer->IOSer.io_Data=&data;
-
- DoIO(IOExtSer);
- return (int)data;
- };
-
- /*
- ;-----------------------------------------------------------------------------
- ; AsyncOut Output a byte
- ;-----------------------------------------------------------------------------
- ; void AsyncOut( int c)
- ;-----------------------------------------------------------------------------
- */
- void AsyncOut(int c)
- {
- char d;
- d = (char)c;
- IOExtSer->IOSer.io_Command=CMD_WRITE;
- IOExtSer->IOSer.io_Flags=NULL;
- IOExtSer->IOSer.io_Length=1;
- IOExtSer->IOSer.io_Data=&d;
- DoIO(IOExtSer);
- };
-
- /*
- ;-----------------------------------------------------------------------------
- ; AsyncSet Set communication paramaters
- ;-----------------------------------------------------------------------------
- ; void AsyncSet( int Baud, int Control)
- ;
- ; Baud = 150, 300, 600, 1200, 2400, 4800, 9600, 19200, 28800, 38400, 57600
- ; Control = The valure to place in the LCR
- ;-----------------------------------------------------------------------------
- */
- void AsyncSet( int Baud, int Control)
-
- {
- IOExtSer->io_Baud=9600;
-
- IOExtSer->io_ReadLen=8;
- IOExtSer->io_WriteLen=8;
- IOExtSer->io_StopBits=2;
-
- if(Control&ODD_PARITY)
- {
- if(Control&0x04)
- {
- IOExtSer->io_SerFlags |= SERF_PARTY_ON;
- IOExtSer->io_SerFlags &= ~SERF_PARTY_ODD;
- }
- else
- {
- IOExtSer->io_SerFlags |= SERF_PARTY_ON;
- IOExtSer->io_SerFlags |= SERF_PARTY_ODD;
- };
- }
- else
- {
- IOExtSer->io_SerFlags &= ~SERF_PARTY_ON;
- };
-
- IOExtSer->IOSer.io_Command=SDCMD_SETPARAMS;
- IOExtSer->io_ExtFlags = NULL;
-
- DoIO(IOExtSer);
- };
-
- /*
- ;-----------------------------------------------------------------------------
- ; AsyncInStat Returns the # of characters in buffer
- ;-----------------------------------------------------------------------------
- ; int AsyncInStat( void)
- ;-----------------------------------------------------------------------------
- */
- int AsyncInStat( void)
- {
- IOExtSer->IOSer.io_Command=SDCMD_QUERY;
- IOExtSer->IOSer.io_Flags=NULL;
- DoIO(IOExtSer);
- return (int)(IOExtSer->IOSer.io_Actual);
- };
-
- /*
- ;-----------------------------------------------------------------------------
- ; AsyncHand Sets various handshaking lines
- ;-----------------------------------------------------------------------------
- ; void AsyncHand( int Hand)
- ;-----------------------------------------------------------------------------
- */
- void AsyncHand( int Hand)
- {
- };
-
- /*
- ;-----------------------------------------------------------------------------
- ; AsyncStat Returns Async/Modem status
- ;-----------------------------------------------------------------------------
- ; unsigned AsyncStat( void)
- ;
- ; MSR is returned in the high byte, LSR in the low byte
- ;-----------------------------------------------------------------------------
- */
- unsigned AsyncStat( void)
-
- {
- IOExtSer->IOSer.io_Command=SDCMD_QUERY;
- IOExtSer->IOSer.io_Flags=NULL;
- DoIO(IOExtSer);
- if(IOExtSer->io_Status & (1<<5))
- {
- return (unsigned)0;
- }
- else
- {
- return (unsigned)DCD;
- };
- };
-
-
- /*
- ;-----------------------------------------------------------------------------
- ; AsyncClear Empty the recieve buffer
- ;-----------------------------------------------------------------------------
- ; void AsyncClear( void);
- ;
- ;
- ;-----------------------------------------------------------------------------
- */
-
- void AsyncClear( void)
- {
- IOExtSer->IOSer.io_Command=CMD_CLEAR;
- IOExtSer->IOSer.io_Flags=NULL;
- DoIO(IOExtSer);
- };
-