]> git.sur5r.net Git - cc65/blob - include/rs232.h
Stefan Haubenthal fixed a few typos.
[cc65] / include / rs232.h
1 /*
2  * rs232.h
3  *
4  * Ullrich von Bassewitz, 19.3.1999
5  *
6  * This module is based upon the public domain swiftlink module written by
7  * Craig Bruce. Thanks a lot!
8  *
9  */
10
11
12
13 #ifndef _RS232_H
14 #define _RS232_h
15
16
17
18 /*****************************************************************************/
19 /*                                   Data                                    */
20 /*****************************************************************************/
21
22
23 #if defined(__C64__) || defined(__C128__)
24
25 /* Baudrate settings */
26 #define RS_BAUD_50                      0x00
27 #define RS_BAUD_110                     0x01
28 #define RS_BAUD_134_5                   0x02
29 #define RS_BAUD_300                     0x03
30 #define RS_BAUD_600                     0x04
31 #define RS_BAUD_1200                    0x05
32 #define RS_BAUD_2400                    0x06
33 #define RS_BAUD_4800                    0x07
34 #define RS_BAUD_9600                    0x08
35 #define RS_BAUD_19200                   0x09
36 #define RS_BAUD_38400                   0x0A
37 #define RS_BAUD_57600                   0x0B
38 #define RS_BAUD_115200                  0x0C
39 #define RS_BAUD_230400                  0x0D
40
41 /* Data bit settings */
42 #define RS_BITS_5                       0x60
43 #define RS_BITS_6                       0x40
44 #define RS_BITS_7                       0x20
45 #define RS_BITS_8                       0x00
46
47 /* Parity settings */
48 #define RS_PAR_NONE                     0x00
49 #define RS_PAR_ODD                      0x20
50 #define RS_PAR_EVEN                     0x60
51 #define RS_PAR_MARK                     0xA0
52 #define RS_PAR_SPACE                    0xE0
53
54 /* Bit masks to mask out things from the status returned by rs232_status */
55 #define RS_STATUS_PE                    0x01    /* Parity error */
56 #define RS_STATUS_FE                    0x02    /* Framing error */
57 #define RS_STATUS_OVERRUN               0x04    /* Overrun error */
58 #define RS_STATUS_RDRF                  0x08    /* Receiver data register full */
59 #define RS_STATUS_THRE                  0x10    /* Transmit holding reg. empty */
60 #define RS_STATUS_DCD                   0x20    /* NOT data carrier detect */
61 #define RS_STATUS_DSR                   0x40    /* NOT data set ready */
62 #define RS_STATUS_IRQ                   0x80    /* IRQ condition */
63
64 #elif defined(__ATARI__)
65
66 /* Baudrate settings */
67 #define RS_BAUD_300                     0x00
68 #define RS_BAUD_45_5                    0x01
69 #define RS_BAUD_50                      0x02
70 #define RS_BAUD_56_875                  0x03
71 #define RS_BAUD_75                      0x04
72 #define RS_BAUD_110                     0x05
73 #define RS_BAUD_134_5                   0x06
74 #define RS_BAUD_150                     0x07
75 /*#define RS_BAUD_300                   0x08  alternative */
76 #define RS_BAUD_600                     0x09
77 #define RS_BAUD_1200                    0x0A
78 #define RS_BAUD_1800                    0x0B
79 #define RS_BAUD_2400                    0x0C
80 #define RS_BAUD_4800                    0x0D
81 #define RS_BAUD_9600                    0x0E
82
83 /* Data bit settings */
84 #define RS_BITS_5                       0x30
85 #define RS_BITS_6                       0x20
86 #define RS_BITS_7                       0x10
87 #define RS_BITS_8                       0x00
88
89 /* Parity settings */
90 #define RS_PAR_NONE                     0x00
91 #define RS_PAR_ODD                      0x05
92 #define RS_PAR_EVEN                     0x0A
93 #define RS_PAR_MARK                     0x03
94 #define RS_PAR_SPACE                    0x0C
95
96 /* Bit masks to mask out things from the status returned by rs232_status */
97 #define RS_STATUS_PE                    0x20    /* Parity error */
98 #define RS_STATUS_FE                    0x80    /* Framing error */
99 #define RS_STATUS_OVERRUN               0x40    /* Overrun error */
100 #define RS_STATUS_RDRF                  0x10    /* Receiver data register full */
101
102 #endif /* __ATARI__ section */
103
104 /* Stop bit settings */
105 #define RS_STOP_1                       0x00
106 #define RS_STOP_2                       0x80
107
108 /* Error codes returned by all functions */
109 #define RS_ERR_OK                       0x00    /* Not an error - relax */
110 #define RS_ERR_NOT_INITIALIZED          0x01    /* Module not initialized */
111 #define RS_ERR_BAUD_TOO_FAST            0x02    /* Cannot handle baud rate */
112 #define RS_ERR_BAUD_NOT_AVAIL           0x03    /* Baud rate not available */
113 #define RS_ERR_NO_DATA                  0x04    /* Nothing to read */
114 #define RS_ERR_OVERFLOW                 0x05    /* No room in send buffer */
115 #define RS_ERR_INIT_FAILED              0x06    /* Initialization of RS232 routines failed */
116
117
118
119 /*****************************************************************************/
120 /*                                   Code                                    */
121 /*****************************************************************************/
122
123
124
125 unsigned char __fastcall__ rs232_init (char hacked);
126 /* Initialize the serial port, install the interrupt handler. The parameter
127  * must be true (non zero) for a hacked swiftlink and false (zero) otherwise.
128  */
129
130 unsigned char __fastcall__ rs232_params (unsigned char params, unsigned char parity);
131 /* Set the port parameters. Use a combination of the #defined values above. */
132
133 unsigned char __fastcall__ rs232_done (void);
134 /* Close the port, deinstall the interrupt hander. You MUST call this function
135  * before terminating the program, otherwise the machine may crash later. If
136  * in doubt, install an exit handler using atexit(). The function will do
137  * nothing, if it was already called.
138  */
139
140 unsigned char __fastcall__ rs232_get (char* b);
141 /* Get a character from the serial port. If no characters are available, the
142  * function will return RS_ERR_NO_DATA, so this is not a fatal error.
143  */
144
145 unsigned char __fastcall__ rs232_put (char b);
146 /* Send a character via the serial port. There is a transmit buffer, but
147  * transmitting is not done via interrupt. The function returns
148  * RS_ERR_OVERFLOW if there is no space left in the transmit buffer.
149  */
150
151 unsigned char __fastcall__ rs232_pause (void);
152 /* Assert flow control and disable interrupts. */
153
154 unsigned char __fastcall__ rs232_unpause (void);
155 /* Re-enable interrupts and release flow control */
156
157 unsigned char __fastcall__ rs232_status (unsigned char* status,
158                                          unsigned char* errors);
159 /* Return the serial port status. */
160
161
162
163 /* End of rs232.h */
164 #endif
165
166
167