kthacker | 6de6775 | 2006-04-17 15:02:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2003, Groepaz/Hitmen. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
| 14 | * 3. The name of the author may not be used to endorse or promote |
| 15 | * products derived from this software without specific prior |
| 16 | * written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 19 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 24 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | * |
| 30 | * rs232silversurfer.h |
| 31 | * |
| 32 | * Groepaz/Hitmen, 16.12.2001 |
| 33 | * |
| 34 | * This defines for the SilverSurver (16c550 UART) what Ullrichs rs232 module |
| 35 | * defines for the Swithlink/Turbo232 |
| 36 | * |
| 37 | * this driver operates in polling mode only atm ! |
| 38 | * |
| 39 | */ |
| 40 | |
| 41 | #ifndef _RS232silversurfer_H |
| 42 | #define _RS232silversurfer_H |
| 43 | |
| 44 | /*****************************************************************************/ |
| 45 | /* Data */ |
| 46 | /*****************************************************************************/ |
| 47 | |
| 48 | /* Baudrate settings */ |
| 49 | #define RS_BAUD_50 0x00 |
| 50 | #define RS_BAUD_110 0x10 |
| 51 | #define RS_BAUD_134_5 0x20 |
| 52 | #define RS_BAUD_300 0x30 |
| 53 | #define RS_BAUD_600 0x40 |
| 54 | #define RS_BAUD_1200 0x50 |
| 55 | #define RS_BAUD_2400 0x60 |
| 56 | #define RS_BAUD_4800 0x70 |
| 57 | #define RS_BAUD_9600 0x80 |
| 58 | #define RS_BAUD_19200 0x90 |
| 59 | #define RS_BAUD_38400 0xa0 |
| 60 | #define RS_BAUD_57600 0xb0 |
| 61 | #define RS_BAUD_115200 0xc0 |
| 62 | #define RS_BAUD_230400 0xd0 |
| 63 | |
| 64 | /* Stop bit settings */ |
| 65 | #define RS_STOP_1 0x00 |
| 66 | #define RS_STOP_2 0x04 |
| 67 | |
| 68 | /* Data bit settings */ |
| 69 | #define RS_BITS_5 0x00 |
| 70 | #define RS_BITS_6 0x01 |
| 71 | #define RS_BITS_7 0x02 |
| 72 | #define RS_BITS_8 0x03 |
| 73 | |
| 74 | /* Parity settings */ |
| 75 | #define RS_PAR_NONE 0x00 |
| 76 | #define RS_PAR_ODD 0x28 |
| 77 | #define RS_PAR_EVEN 0x38 |
| 78 | #define RS_PAR_MARK 0x48 |
| 79 | #define RS_PAR_SPACE 0x48 |
| 80 | |
| 81 | /* Bit masks to mask out things from the status returned by rs232_status */ |
| 82 | #define RS_STATUS_IRQ 0x01 /* (iir) IRQ condition */ |
| 83 | #define RS_STATUS_OVERRUN 0x02 /* (lsr) Overrun error */ |
| 84 | #define RS_STATUS_PE 0x04 /* (lsr) Parity error */ |
| 85 | #define RS_STATUS_FE 0x08 /* (lsr) Framing error */ |
| 86 | #define RS_STATUS_DSR 0x10 /* (msr>>1) NOT data set ready */ |
| 87 | #define RS_STATUS_THRE 0x20 /* (lsr) Transmit holding reg. empty */ |
| 88 | #define RS_STATUS_DCD 0x40 /* (msr>>1) NOT data carrier detect */ |
| 89 | #define RS_STATUS_RDRF 0x80 /* Receiver data register full */ |
| 90 | |
| 91 | /* Error codes returned by all functions */ |
| 92 | #define RS_ERR_OK 0x00 /* Not an error - relax */ |
| 93 | #define RS_ERR_NOT_INITIALIZED 0x01 /* Module not initialized */ |
| 94 | #define RS_ERR_BAUD_TOO_FAST 0x02 /* Cannot handle baud rate */ |
| 95 | #define RS_ERR_BAUD_NOT_AVAIL 0x03 /* Baud rate not available */ |
| 96 | #define RS_ERR_NO_DATA 0x04 /* Nothing to read */ |
| 97 | #define RS_ERR_OVERFLOW 0x05 /* No room in send buffer */ |
| 98 | |
| 99 | /*****************************************************************************/ |
| 100 | /* Code */ |
| 101 | /*****************************************************************************/ |
| 102 | |
| 103 | unsigned char __fastcall__ rs232_init (char hacked); |
| 104 | /* Initialize the serial port, install the interrupt handler. The parameter |
| 105 | * has no effect for now and should be set to 0. |
| 106 | */ |
| 107 | |
| 108 | unsigned char __fastcall__ rs232_params (unsigned char params, unsigned char parity); |
| 109 | /* Set the port parameters. Use a combination of the #defined values above. */ |
| 110 | |
| 111 | unsigned char __fastcall__ rs232_done (void); |
| 112 | /* Close the port, deinstall the interrupt hander. You MUST call this function |
| 113 | * before terminating the program, otherwise the machine may crash later. If |
| 114 | * in doubt, install an exit handler using atexit(). The function will do |
| 115 | * nothing, if it was already called. |
| 116 | */ |
| 117 | |
| 118 | unsigned char __fastcall__ rs232_get (char* b); |
| 119 | /* Get a character from the serial port. If no characters are available, the |
| 120 | * function will return RS_ERR_NO_DATA, so this is not a fatal error. |
| 121 | */ |
| 122 | |
| 123 | unsigned char __fastcall__ rs232_put (char b); |
| 124 | /* Send a character via the serial port. There is a transmit buffer, but |
| 125 | * transmitting is not done via interrupt. The function returns |
| 126 | * RS_ERR_OVERFLOW if there is no space left in the transmit buffer. |
| 127 | */ |
| 128 | |
| 129 | unsigned char __fastcall__ rs232_pause (void); |
| 130 | /* Assert flow control and disable interrupts. */ |
| 131 | |
| 132 | unsigned char __fastcall__ rs232_unpause (void); |
| 133 | /* Re-enable interrupts and release flow control */ |
| 134 | |
| 135 | unsigned char __fastcall__ rs232_status (unsigned char* status, |
| 136 | unsigned char* errors); |
| 137 | /* Return the serial port status. */ |
| 138 | |
| 139 | /* End of rs232silversurfer.h */ |
| 140 | #endif |
| 141 | |
| 142 | |
| 143 | |