1 /* 2 * rs232.h 3 * 4 * RS232 prototypes for z88dk - not all machines supported! 5 * 6 * Based on the API from cc65 7 * 8 * $Id: rs232.h,v 1.4 2014-12-11 20:04:51 stefano Exp $ 9 */ 10 11 12 #ifndef __RS232_H__ 13 #define __RS232_H__ 14 15 #include <sys/compiler.h> 16 #include <stdint.h> 17 18 /* Baudrate settings */ 19 #define RS_BAUD_50 0x00 20 #define RS_BAUD_75 0x01 21 #define RS_BAUD_110 0x02 22 #define RS_BAUD_134_5 0x03 23 #define RS_BAUD_150 0x04 24 #define RS_BAUD_300 0x05 25 #define RS_BAUD_600 0x06 26 #define RS_BAUD_1200 0x07 27 #define RS_BAUD_2400 0x08 28 #define RS_BAUD_4800 0x09 29 #define RS_BAUD_9600 0x0A 30 #define RS_BAUD_19200 0x0B 31 #define RS_BAUD_38400 0x0C 32 #define RS_BAUD_57600 0x0D 33 #define RS_BAUD_115200 0x0E 34 #define RS_BAUD_230400 0x0F 35 36 /* Stop bit settings */ 37 #define RS_STOP_1 0x00 38 #define RS_STOP_2 0x80 39 40 /* Data bit settings */ 41 #define RS_BITS_5 0x60 42 #define RS_BITS_6 0x40 43 #define RS_BITS_7 0x20 44 #define RS_BITS_8 0x00 45 46 /* Parity settings */ 47 #define RS_PAR_NONE 0x00 48 #define RS_PAR_ODD 0x20 49 #define RS_PAR_EVEN 0x60 50 #define RS_PAR_MARK 0xA0 51 #define RS_PAR_SPACE 0xE0 52 53 54 /* Error codes returned by all functions */ 55 #define RS_ERR_OK 0x00 /* Not an error - relax */ 56 #define RS_ERR_NOT_INITIALIZED 0x01 /* Module not initialized */ 57 #define RS_ERR_BAUD_TOO_FAST 0x02 /* Cannot handle baud rate */ 58 #define RS_ERR_BAUD_NOT_AVAIL 0x03 /* Baud rate not available */ 59 #define RS_ERR_NO_DATA 0x04 /* Nothing to read */ 60 #define RS_ERR_OVERFLOW 0x05 /* No room in send buffer */ 61 62 63 /* Handshaking codes used in XMODEM and its derivatives */ 64 65 #define SOH 1 66 #define EOT 4 67 #define ACK 6 68 #define DLE 16 69 #define DC1 17 /* X-On */ 70 #define DC3 19 /* X-Off */ 71 #define NAK 21 72 #define SYN 22 73 #define CAN 24 74 75 76 /* The functions: Call params, then init then put/get finally close */ 77 78 79 /* Set up the parameters for the serial interface use | of parameters above */ 80 extern uint8_t __LIB__ rs232_params(uint8_t params,uint8_t parity) __smallc; 81 82 /* Initialise the serial interface */ 83 extern uint8_t __LIB__ rs232_init(void); 84 85 /* Close the interface */ 86 extern uint8_t __LIB__ rs232_close(void); 87 88 89 /* Write a byte to the serial interface */ 90 extern uint8_t __LIB__ rs232_put(uint8_t) __z88dk_fastcall; 91 92 93 /* Read a byte from the serial, returns RS_ERR_NO_DATA if an error, places 94 data in the pointer supplied 95 */ 96 extern uint8_t __LIB__ rs232_get(uint8_t *) __z88dk_fastcall; 97 98 99 100 #endif 101