]> git.sur5r.net Git - cc65/blob - include/serial.h
Remove this copy of the apple include file - a copy was added to asminc
[cc65] / include / serial.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 serial.h                                  */
4 /*                                                                           */
5 /*                         Serial communication API                          */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2003      Ullrich von Bassewitz                                       */
10 /*               Römerstrasse 52                                             */
11 /*               D-70794 Filderstadt                                         */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
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.                                    */
18 /*                                                                           */
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:                            */
22 /*                                                                           */
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              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef _SERIAL_H
37 #define _SERIAL_H
38
39
40
41 /*****************************************************************************/
42 /*                                   Data                                    */
43 /*****************************************************************************/
44
45
46
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_3600           0x0B
60 #define SER_BAUD_4800           0x0C
61 #define SER_BAUD_7200           0x0D
62 #define SER_BAUD_9600           0x0E
63 #define SER_BAUD_19200          0x0F
64 #define SER_BAUD_38400          0x10
65 #define SER_BAUD_57600          0x11
66 #define SER_BAUD_115200         0x12
67 #define SER_BAUD_230400         0x13
68 #define SER_BAUD_31250          0x14
69 #define SER_BAUD_62500          0x15
70
71 /* Data bit settings */
72 #define SER_BITS_5              0x00
73 #define SER_BITS_6              0x01
74 #define SER_BITS_7              0x02
75 #define SER_BITS_8              0x03
76
77 /* Stop bit settings */
78 #define SER_STOP_1              0x00    /* One stop bit */
79 #define SER_STOP_2              0x01    /* Two stop bits */
80
81 /* Parity settings */
82 #define SER_PAR_NONE            0x00
83 #define SER_PAR_ODD             0x01
84 #define SER_PAR_EVEN            0x02
85 #define SER_PAR_MARK            0x03
86 #define SER_PAR_SPACE           0x04
87
88 /* Handshake settings. The latter two may be combined. */
89 #define SER_HS_NONE             0x00    /* No handshake */
90 #define SER_HS_HW               0x01    /* Hardware (RTS/CTS) handshake */
91 #define SER_HS_SW               0x02    /* Software handshake */
92
93 /* Bit masks to mask out things from the status returned by ser_status.
94  * These are 6551 specific and must be mapped by drivers for other chips.
95  */
96 #define SER_STATUS_PE           0x01    /* Parity error */
97 #define SER_STATUS_FE           0x02    /* Framing error */
98 #define SER_STATUS_OE           0x04    /* Overrun error */
99 #define SER_STATUS_DCD          0x20    /* NOT data carrier detect */
100 #define SER_STATUS_DSR          0x40    /* NOT data set ready */
101
102 /* Error codes returned by all functions */
103 #define SER_ERR_OK              0x00    /* Not an error - relax */
104 #define SER_ERR_NO_DRIVER       0x01    /* No driver available */
105 #define SER_ERR_CANNOT_LOAD     0x02    /* Error loading driver */
106 #define SER_ERR_INV_DRIVER      0x03    /* Invalid driver */
107 #define SER_ERR_NO_DEVICE       0x04    /* Device (hardware) not found */
108 #define SER_ERR_BAUD_UNAVAIL    0x05    /* Baud rate not available */
109 #define SER_ERR_NO_DATA         0x06    /* Nothing to read */
110 #define SER_ERR_OVERFLOW        0x07    /* No room in send buffer */
111 #define SER_ERR_INIT_FAILED     0x08    /* Initialization failed */
112 #define SER_ERR_INV_IOCTL       0x09    /* IOCTL not supported */
113
114 /* Struct containing parameters for the serial port */
115 struct ser_params {
116     unsigned char       baudrate;       /* Baudrate */
117     unsigned char       databits;       /* Number of data bits */
118     unsigned char       stopbits;       /* Number of stop bits */
119     unsigned char       parity;         /* Parity setting */
120     unsigned char       handshake;      /* Type of handshake to use */
121 };
122
123
124 /*****************************************************************************/
125 /*                                   Code                                    */
126 /*****************************************************************************/
127
128
129
130 unsigned char __fastcall__ ser_load_driver (const char* driver);
131 /* Load and install a serial driver. Return an error code. */
132
133 unsigned char __fastcall__ ser_unload (void);
134 /* Uninstall, then unload the currently loaded driver. */
135
136 unsigned char __fastcall__ ser_install (void* driver);
137 /* Install an already loaded driver. Return an error code. */
138
139 unsigned char __fastcall__ ser_uninstall (void);
140 /* Uninstall the currently loaded driver and return an error code.
141  * Note: This call does not free allocated memory.
142  */
143
144 unsigned char __fastcall__ ser_open (const struct ser_params* params);
145 /* "Open" the port by setting the port parameters and enable interrupts. */
146
147 unsigned char __fastcall__ ser_close (void);
148 /* "Close" the port. Clear buffers and and disable interrupts. */
149
150 unsigned char __fastcall__ ser_get (char* b);
151 /* Get a character from the serial port. If no characters are available, the
152  * function will return SER_ERR_NO_DATA, so this is not a fatal error.
153  */
154
155 unsigned char __fastcall__ ser_put (char b);
156 /* Send a character via the serial port. There is a transmit buffer, but
157  * transmitting is not done via interrupt. The function returns
158  * SER_ERR_OVERFLOW if there is no space left in the transmit buffer.
159  */
160
161 unsigned char __fastcall__ ser_status (unsigned char* status);
162 /* Return the serial port status. */
163
164 unsigned char __fastcall__ ser_ioctl (unsigned char code, void* data);
165 /* Driver specific entry. */
166
167
168
169 /* End of serial.h */
170 #endif
171
172
173