]> git.sur5r.net Git - cc65/blob - include/serial.h
Support for self explanatory KBCODE values
[cc65] / include / serial.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 serial.h                                  */
4 /*                                                                           */
5 /*                         Serial communication API                          */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2003-2012, Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 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 #define SER_BAUD_56_875         0x16
71
72 /* Data bit settings */
73 #define SER_BITS_5              0x00
74 #define SER_BITS_6              0x01
75 #define SER_BITS_7              0x02
76 #define SER_BITS_8              0x03
77
78 /* Stop bit settings */
79 #define SER_STOP_1              0x00    /* One stop bit */
80 #define SER_STOP_2              0x01    /* Two stop bits */
81
82 /* Parity settings */
83 #define SER_PAR_NONE            0x00
84 #define SER_PAR_ODD             0x01
85 #define SER_PAR_EVEN            0x02
86 #define SER_PAR_MARK            0x03
87 #define SER_PAR_SPACE           0x04
88
89 /* Handshake settings. The latter two may be combined. */
90 #define SER_HS_NONE             0x00    /* No handshake */
91 #define SER_HS_HW               0x01    /* Hardware (RTS/CTS) handshake */
92 #define SER_HS_SW               0x02    /* Software handshake */
93
94 /* Bit masks to mask out things from the status returned by ser_status.
95 ** These are 6551 specific and must be mapped by drivers for other chips.
96 */
97 #define SER_STATUS_PE           0x01    /* Parity error */
98 #define SER_STATUS_FE           0x02    /* Framing error */
99 #define SER_STATUS_OE           0x04    /* Overrun error */
100 #define SER_STATUS_DCD          0x20    /* NOT data carrier detect */
101 #define SER_STATUS_DSR          0x40    /* NOT data set ready */
102
103 /* Error codes returned by all functions */
104 #define SER_ERR_OK              0x00    /* Not an error - relax */
105 #define SER_ERR_NO_DRIVER       0x01    /* No driver available */
106 #define SER_ERR_CANNOT_LOAD     0x02    /* Error loading driver */
107 #define SER_ERR_INV_DRIVER      0x03    /* Invalid driver */
108 #define SER_ERR_NO_DEVICE       0x04    /* Device (hardware) not found */
109 #define SER_ERR_BAUD_UNAVAIL    0x05    /* Baud rate not available */
110 #define SER_ERR_NO_DATA         0x06    /* Nothing to read */
111 #define SER_ERR_OVERFLOW        0x07    /* No room in send buffer */
112 #define SER_ERR_INIT_FAILED     0x08    /* Initialization failed */
113 #define SER_ERR_INV_IOCTL       0x09    /* IOCTL not supported */
114 #define SER_ERR_INSTALLED       0x0A    /* A driver is already installed */
115 #define SER_ERR_NOT_OPEN        0x0B    /* Driver is not open */
116
117 /* Struct containing parameters for the serial port */
118 struct ser_params {
119     unsigned char       baudrate;       /* Baudrate */
120     unsigned char       databits;       /* Number of data bits */
121     unsigned char       stopbits;       /* Number of stop bits */
122     unsigned char       parity;         /* Parity setting */
123     unsigned char       handshake;      /* Type of handshake to use */
124 };
125
126
127 /*****************************************************************************/
128 /*                                   Code                                    */
129 /*****************************************************************************/
130
131
132
133 unsigned char __fastcall__ ser_load_driver (const char* driver);
134 /* Load and install a serial driver. Return an error code. */
135
136 unsigned char ser_unload (void);
137 /* Uninstall, then unload the currently loaded driver. */
138
139 unsigned char __fastcall__ ser_install (void* driver);
140 /* Install an already loaded driver. Return an error code. */
141
142 unsigned char ser_uninstall (void);
143 /* Uninstall the currently loaded driver and return an error code.
144 ** Note: This call does not free allocated memory.
145 */
146
147 unsigned char __fastcall__ ser_open (const struct ser_params* params);
148 /* "Open" the port by setting the port parameters and enable interrupts. */
149
150 unsigned char ser_close (void);
151 /* "Close" the port. Clear buffers and and disable interrupts. */
152
153 unsigned char __fastcall__ ser_get (char* b);
154 /* Get a character from the serial port. If no characters are available, the
155 ** function will return SER_ERR_NO_DATA, so this is not a fatal error.
156 */
157
158 unsigned char __fastcall__ ser_put (char b);
159 /* Send a character via the serial port. There is a transmit buffer, but
160 ** transmitting is not done via interrupt. The function returns
161 ** SER_ERR_OVERFLOW if there is no space left in the transmit buffer.
162 */
163
164 unsigned char __fastcall__ ser_status (unsigned char* status);
165 /* Return the serial port status. */
166
167 unsigned char __fastcall__ ser_ioctl (unsigned char code, void* data);
168 /* Driver specific entry. */
169
170
171
172 /* End of serial.h */
173 #endif
174
175
176