]> git.sur5r.net Git - cc65/blob - include/rs232.h
This commit was generated by cvs2svn to compensate for changes in r2,
[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
24 /* Baudrate settings */
25 #define RS_BAUD_50                      0x00
26 #define RS_BAUD_110                     0x01
27 #define RS_BAUD_134_5                   0x02
28 #define RS_BAUD_300                     0x03
29 #define RS_BAUD_600                     0x04
30 #define RS_BAUD_1200                    0x05
31 #define RS_BAUD_2400                    0x06
32 #define RS_BAUD_4800                    0x07
33 #define RS_BAUD_9600                    0x08
34 #define RS_BAUD_19200                   0x09
35 #define RS_BAUD_38400                   0x0A
36 #define RS_BAUD_57600                   0x0B
37 #define RS_BAUD_115200                  0x0C
38 #define RS_BAUD_230400                  0x0D
39
40 /* Stop bit settings */
41 #define RS_STOP_1                       0x00
42 #define RS_STOP_2                       0x80
43
44 /* Data bit settings */
45 #define RS_BITS_5                       0x60
46 #define RS_BITS_6                       0x40
47 #define RS_BITS_7                       0x20
48 #define RS_BITS_8                       0x00
49
50 /* Parity settings */
51 #define RS_PAR_NONE                     0x00
52 #define RS_PAR_ODD                      0x20
53 #define RS_PAR_EVEN                     0x60
54 #define RS_PAR_MARK                     0xA0
55 #define RS_PAR_SPACE                    0xE0
56
57 /* Bit masks to mask out things from the status returned by rs232_status */
58 #define RS_STATUS_PE                    0x01    /* Parity error */
59 #define RS_STATUS_FE                    0x02    /* Framing error */
60 #define RS_STATUS_OVERRUN               0x04    /* Overrun error */
61 #define RS_STATUS_RDRF                  0x08    /* Receiver data register full */
62 #define RS_STATUS_THRE                  0x10    /* Transmit holding reg. empty */
63 #define RS_STATUS_DCD                   0x20    /* NOT data carrier detect */
64 #define RS_STATUS_DSR                   0x40    /* NOT data set ready */
65 #define RS_STATUS_IRQ                   0x80    /* IRQ condition */
66
67 /* Error codes returned by all functions */
68 #define RS_ERR_OK                       0x00    /* Not an error - relax */
69 #define RS_ERR_NOT_INITIALIZED          0x01    /* Module not initialized */
70 #define RS_ERR_BAUD_TOO_FAST            0x02    /* Cannot handle baud rate */
71 #define RS_ERR_BAUD_NOT_AVAIL           0x03    /* Baud rate not available */
72 #define RS_ERR_NO_DATA                  0x04    /* Nothing to read */
73 #define RS_ERR_OVERFLOW                 0x05    /* No room in send buffer */
74
75
76
77 /*****************************************************************************/
78 /*                                   Code                                    */
79 /*****************************************************************************/
80
81
82
83 unsigned char __fastcall__ rs232_init (char hacked);
84 /* Initialize the serial port, install the interrupt handler. The parameter
85  * must be true (non zero) for a hacked swiftlink and false (zero) otherwise.
86  */
87
88 unsigned char __fastcall__ rs232_params (unsigned char params, unsigned char parity);
89 /* Set the port parameters. Use a combination of the #defined values above. */
90
91 unsigned char __fastcall__ rs232_done (void);
92 /* Close the port, deinstall the interrupt hander. You MUST call this function
93  * before terminating the program, otherwise the machine may crash later. If
94  * in doubt, install an exit handler using atexit(). The function will do
95  * nothing, if it was already called.
96  */
97
98 unsigned char __fastcall__ rs232_get (char* b);
99 /* Get a character from the serial port. If no characters are available, the
100  * function will return RS_ERR_NO_DATA, so this is not a fatal error.
101  */
102
103 unsigned char __fastcall__ rs232_put (char b);
104 /* Send a character via the serial port. There is a transmit buffer, but
105  * transmitting is not done via interrupt. The function returns
106  * RS_ERR_OVERFLOW if there is no space left in the transmit buffer.
107  */
108
109 unsigned char __fastcall__ rs232_pause (void);
110 /* Assert flow control and disable interrupts. */
111
112 unsigned char __fastcall__ rs232_unpause (void);
113 /* Re-enable interrupts and release flow control */
114
115 unsigned char __fastcall__ rs232_status (unsigned char* status, 
116                                          unsigned char* errors);
117 /* Return the serial port status. */
118
119
120
121 /* End of rs232.h */
122 #endif
123
124
125