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