home *** CD-ROM | disk | FTP | other *** search
- rsdrv.doc : last update 1.3. 1990
-
- Rsdrv.c contains the source code for the basic functions needed
- to perform interrupt driven io on the serial ports of the ibm pc
- and compatibles. It is written in Borland turbo C, but it should
- be relatively easy to port the code for other compilers, as long
- as they have the interrupt function type and a way to access the
- i/o-address space similar to those in turbo C. The code should run
- in all memory models. It has been tested with turbo C 1.0, small
- memory modell.
-
- While the package can be used 'as is', my intention was also to
- provide a template for anyone in need of interrupt driven serial
- io in order to reduce the need to 're-invent the wheel'. So, feel
- free to use and modify the code as appropriate for your purposes.
- If you'd like to give me credit, you can mention the origin of
- the code. This is not required, however. Also, I'd like to point
- out that the code can be used even for commercial purposes (or
- whatever) without any fee.
-
- The code and documentation of rsdrv are provided 'as is' with no
- warranty of any kind. Comments, suggestions and bug-fixes are
- wellcome.
-
-
- J. Leppäjärvi / so-jml@stekt.oulu.fi
-
-
-
-
-
- General overview
- ------------------------------------------------------------------------------
-
- The package is initialized with rsinit() for a certain port
- and communication parameters. The subsequent operations use
- these settings in their operation. When the program using
- the package is about to terminate and return to dos, it
- should call rsend(), which disables the interrupts from the
- serial interface, otherwize some part of the subsequently
- loaded programs might be called as an interrupt service routine
- ( = system crash).
-
- rsgetc() is used to read the arriving characters. rsputc()
- writes charaters to the port. Actually, the read/write
- operations are buffered : rsgetc() reads characters from a
- buffer filled by the an interrupt routine invoked by the rs
- interface every time a character arrives, while rsputc()
- places characters in a buffer emptied by the interrupt
- routine as the interface is ready to transmit them.
-
- Input buffer overflow causes the oldest character to be lost,
- while output buffer does not actually overflow : rsputc() just
- returns an error condition when the buffer is full. In this case
- the call to rsputc() can be repeated as long as the buffer full
- condition presists.
-
- The input/output buffers are staticly defined in rsdrv.c. By
- default there is a 128 byte buffer both for incoming and outgoing
- data. This can be changed by editing the defines for RXBUF (input
- buffer size) and TXBUF (output buffer size). Optimum buffer sizes
- depend on the nature of the rs-interaction : bigger buffers should
- be allocated if the program spends long times in other actions than
- reading / writing the rs-ports, such as performing disk operations.
- On the other hand, the default sizes are quite sufficent (if not
- overkill) for a terminal program that doesn't have other activities
- than copying the incoming data on the display and sending the keyboard
- input out via the rs-line. (In fact the output buffer is rarely, if
- ever needed in this particular case.)
-
- The header file rsdrv.h should be included in modules using the
- the functions of the package to provide appropriate definitions
- and function prototypes.
-
-
-
- Compiling
- ------------------------------------------------------------------------------
-
- The code is written in a fashion that should enable using it in
- all memory modells. If the package is to be used 'as is' it could
- be compliled with the command line version of turbo C as follows :
-
- tcc -c -Z -O rsdrv.c
-
- This produces the small model object file rsdrv.obj, which can be
- linked in your programs e.g. by placing it with it's complete path
- in the .prj file used in the integrated environment. (Refer to compiler
- documentation for other memory models and other details.)
-
-
-
-
- Function descriptions
- ------------------------------------------------------------------------------
-
-
- rsbreak
- ------------------------------------------------------------------------------
-
- void rsbreak(int isbreak);
-
- rsbreak is used to send a break. It sets/resets the transmit break
- bit in the line control register of the 8250. In practice breaks
- of various lengths can be send by first calling rsbreak with 1,
- waiting the desired time and calling rsbreak with 0.
-
-
-
- rsgetc
- ------------------------------------------------------------------------------
-
- int rsgetc(void);
-
- rsgetc reads one character from serial port and returns it. If
- none is available rsgetc returns -1. The character codes for
- actual characters vary from 0 - 255.
-
-
-
- rsinit
- ------------------------------------------------------------------------------
-
- int rsinit(int port,int speed,unsigned char pbyte);
-
- rsinit initializes the package. It must be called before
- using the other functions in the package. port is the com
- port number to be used (1 - 4), speed is the communication
- speed (baud rate) and pbyte is a value defining the rest of
- the communication parameters, constructed by bitwize ORing
- the following flags :
-
- BITS_7 : 7 data bits
- BITS_8 : 8 data bits
-
- PARITY_NONE : no parity
- PARITY_ODD : odd parity
- PARITY_EVEN : even parity
-
- STOP_1 : one stop bit
- STOP_2 : two stop bits
-
-
- In its present state rsinit returns -1 if the port number is
- out of range, zero otherwize.
-
-
-
- rsend
- ------------------------------------------------------------------------------
-
- void rsend(void);
-
- rsend terminates the use of interrupt driven rs input/output.
- It must be called before returning to DOS to disable interrupts
- from the serial interface. Doing otherwize is likely to cause
- a system crash.
-
-
-
- rsputc
- ------------------------------------------------------------------------------
-
- int rsputc(unsigned char c);
-
- rsputc writes one character to the rs-port. If the character is
- successfully written rsputc returns zero. If the character cannot
- be written for the moment (output buffer full) rsputc returns -1.
-
-
- ------------------------------------------------------------------------------
- rsdrv.c was written in Turbo C by J. Lepp{j{rvi (so-jml@stekt.oulu.fi)
- (C) 1990. It and the related documentation may be used, copied and modified
- freely for any purpose. The code and the documentation are provided 'as is'
- without a warranty of any kind.
- ------------------------------------------------------------------------------