1 /*****************************************************************************/
5 /* Serial communication API */
9 /* (C) 2003 Ullrich von Bassewitz */
10 /* Römerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
41 /*****************************************************************************/
43 /*****************************************************************************/
47 /* Baudrate settings */
48 #define SER_BAUD_45_5 0x00
49 #define SER_BAUD_50 0x01
50 #define SER_BAUD_75 0x02
51 #define SER_BAUD_110 0x03
52 #define SER_BAUD_134_5 0x04
53 #define SER_BAUD_150 0x05
54 #define SER_BAUD_300 0x06
55 #define SER_BAUD_600 0x07
56 #define SER_BAUD_1200 0x08
57 #define SER_BAUD_1800 0x09
58 #define SER_BAUD_2400 0x0A
59 #define SER_BAUD_4800 0x0B
60 #define SER_BAUD_9600 0x0C
61 #define SER_BAUD_19200 0x0D
62 #define SER_BAUD_38400 0x0E
63 #define SER_BAUD_57600 0x0F
64 #define SER_BAUD_115200 0x10
65 #define SER_BAUD_230400 0x11
67 /* Data bit settings */
68 #define SER_BITS_5 0x00
69 #define SER_BITS_6 0x01
70 #define SER_BITS_7 0x02
71 #define SER_BITS_8 0x03
73 /* Stop bit settings */
74 #define SER_STOP_1 0x00 /* One stop bit */
75 #define SER_STOP_2 0x01 /* Two stop bits */
78 #define SER_PAR_NONE 0x00
79 #define SER_PAR_ODD 0x01
80 #define SER_PAR_EVEN 0x02
81 #define SER_PAR_MARK 0x03
82 #define SER_PAR_SPACE 0x04
84 /* Handshake settings. The latter two may be combined. */
85 #define SER_HS_NONE 0x00 /* No handshake */
86 #define SER_HS_HW 0x01 /* Hardware (RTS/CTS) handshake */
87 #define SER_HS_SW 0x02 /* Software handshake */
89 /* Bit masks to mask out things from the status returned by rs232_status */
90 #define SER_STATUS_PE 0x01 /* Parity error */
91 #define SER_STATUS_FE 0x02 /* Framing error */
92 #define SER_STATUS_OE 0x04 /* Overrun error */
93 #define SER_STATUS_DCD 0x20 /* NOT data carrier detect */
94 #define SER_STATUS_DSR 0x40 /* NOT data set ready */
96 /* Error codes returned by all functions */
97 #define SER_ERR_OK 0x00 /* Not an error - relax */
98 #define SER_ERR_NO_DRIVER 0x01 /* No driver available */
99 #define SER_ERR_CANNOT_LOAD 0x02 /* Error loading driver */
100 #define SER_ERR_INV_DRIVER 0x03 /* Invalid driver */
101 #define SER_ERR_NO_DEVICE 0x04 /* Device (hardware) not found */
102 #define SER_ERR_BAUD_UNAVAIL 0x05 /* Baud rate not available */
103 #define SER_ERR_NO_DATA 0x06 /* Nothing to read */
104 #define SER_ERR_OVERFLOW 0x07 /* No room in send buffer */
105 #define SER_ERR_INIT_FAILED 0x08 /* Initialization failed */
106 #define SER_ERR_INV_IOCTL 0x09 /* IOCTL not supported */
108 /* Struct containing parameters for the serial port */
110 unsigned char baudrate; /* Baudrate */
111 unsigned char databits; /* Number of data bits */
112 unsigned char stopbits; /* Number of stop bits */
113 unsigned char parity; /* Parity setting */
114 unsigned char handshake; /* Type of handshake to use */
118 /*****************************************************************************/
120 /*****************************************************************************/
124 unsigned char __fastcall__ ser_load_driver (const char* driver);
125 /* Load and install a serial driver. Return an error code. */
127 unsigned char __fastcall__ ser_unload (void);
128 /* Uninstall, then unload the currently loaded driver. */
130 unsigned char __fastcall__ ser_install (void* driver);
131 /* Install an already loaded driver. Return an error code. */
133 unsigned char __fastcall__ ser_uninstall (void);
134 /* Uninstall the currently loaded driver and return an error code.
135 * Note: This call does not free allocated memory.
138 unsigned char __fastcall__ ser_params (const struct ser_params* params);
139 /* Set the port parameters. This will also enable the port. */
141 unsigned char __fastcall__ ser_get (char* b);
142 /* Get a character from the serial port. If no characters are available, the
143 * function will return SER_ERR_NO_DATA, so this is not a fatal error.
146 unsigned char __fastcall__ ser_put (char b);
147 /* Send a character via the serial port. There is a transmit buffer, but
148 * transmitting is not done via interrupt. The function returns
149 * SER_ERR_OVERFLOW if there is no space left in the transmit buffer.
152 unsigned char __fastcall__ ser_pause (void);
153 /* Assert flow control and disable interrupts. */
155 unsigned char __fastcall__ ser_unpause (void);
156 /* Re-enable interrupts and release flow control */
158 unsigned char __fastcall__ ser_status (unsigned char* status);
159 /* Return the serial port status. */
161 unsigned char __fastcall__ ser_ioctl (unsigned char code, void* data);
162 /* Driver specific entry. */
166 /* End of serial.h */