1/* M68HC11/M68HC12 serial line operations
2 * Copyright (C) 1999, 2001 Stephane Carrez (stcarrez@nerim.fr)
3 *
4 * The authors hereby grant permission to use, copy, modify, distribute,
5 * and license this software and its documentation for any purpose, provided
6 * that existing copyright notices are retained in all copies and that this
7 * notice is included verbatim in any distributions. No written agreement,
8 * license, or royalty fee is required for any of the authorized uses.
9 * Modifications to this software may be copyrighted by their authors
10 * and need not follow the licensing terms described here, provided that
11 * the new terms are clearly indicated on the first page of each file where
12 * they apply.
13 */
14
15#ifdef mc68hc12
16	SC0CR1 = 0xC2
17	SC0CR2 = 0xC3
18	SC0SR1 = 0xC4
19	SC0DRL = 0xC7
20	SC0BD  = 0xC0
21
22	.sect .data
23	.globl _m68hc12_ports
24_m68hc12_ports:	.word	0
25
26	.sect .text
27	.globl outbyte
28;;;
29;;; int outbyte(char c);
30;;;
31;;; B :	Character to send
32;;;
33outbyte:
34	bsr	_sci_init
35L1:
36	ldaa	SC0SR1,x
37	bge	L1
38	stab	SC0DRL,x
39	ldab	SC0CR2,x
40	orab	#0x8
41	stab	SC0CR2,x
42	rts
43
44	.sect .text
45	.globl inbyte
46;;;
47;;; char inbyte(void);
48;;;
49inbyte:
50	bsr	_sci_init
51	ldaa	SC0SR1,x
52	bita	#0x20
53	beq	inbyte
54	ldab	SC0CR2,x
55	rts
56
57	.globl _sci_init
58	.sect .text
59_sci_init:
60	ldx	_m68hc12_ports
61	beq	do_init
62	dex
63	rts
64do_init:
65	ldx	#0x1
66	stx	_m68hc12_ports
67	dex
68	ldd	#26
69	std	SC0BD,x
70	ldaa	#0
71	staa	SC0CR1,x
72	ldaa	#0xC
73	staa	SC0CR2,x
74	rts
75#else
76	BAUD = 0x2b
77	SCCR1= 0x2c
78	SCCR2= 0x2d
79	SCSR = 0x2e
80	SCDR = 0x2f
81
82	.sect .data
83	.globl _m68hc11_ports
84_m68hc11_ports:	.word	0
85
86	.sect .text
87	.globl outbyte
88;;;
89;;; int outbyte(char c);
90;;;
91;;; B :	Character to send
92;;;
93outbyte:
94	bsr	_sci_init
95L1:
96	ldaa	SCSR,x
97	bge	L1
98	stab	SCDR,x
99	ldab	SCCR2,x
100	orab	#0x8
101	stab	SCCR2,x
102	rts
103
104	.sect .text
105	.globl inbyte
106;;;
107;;; char inbyte(void);
108;;;
109inbyte:
110	bsr	_sci_init
111	ldaa	SCSR,x
112	bita	#0x20
113	beq	inbyte
114	ldab	SCDR,x
115	rts
116
117	.globl _sci_init
118	.sect .text
119_sci_init:
120	ldx	_m68hc11_ports
121	beq	do_init
122	rts
123do_init:
124	ldx	#0x1000
125	stx	_m68hc11_ports
126	ldaa	#0x30
127	staa	BAUD,x
128	clra
129	staa	SCCR1,x
130	ldaa	#0xC
131	staa	SCCR2,x
132	rts
133
134#endif
135