File: uart_echo.s

package info (click to toggle)
tkisem 4.5.12-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 964 kB
  • ctags: 1,372
  • sloc: cpp: 4,844; tcl: 3,047; asm: 1,991; makefile: 335; ansic: 269; sh: 155
file content (70 lines) | stat: -rw-r--r-- 1,007 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
	!
	! 12/31/96
	! A.B. Maccabe
	!
	! read 10 characters from the UART and send them back to the UART
	! -- no buffering, quit if we get an overrun
	!


	UARTSTATUS	= 0X140000 
	UARTCREG	= 0x140000
	UARTTXREG	= 0x140004
	UARTRXREG	= 0x140004

	NCHARS		= 30

	.data
ovr_msg:	.asciz	"Overrun error detected, quit\n"
	
	.text
	.global start
	
start:	
	set	UARTSTATUS, %l0

	! set the UART control register -- disable interrupts and set the
	! rx/tx rate fairly low
	set	0x40, %l2
	st	%l2, [%l0]

	set	NCHARS, %l2
	
top:
	! wait for a character to appear
poll_rcv:	
	ld	[%l0], %l1
	! check for overrun error
	andcc	%l1, 4, %g0
	be	chk_rcv
	nop

	! overrun -- print a message and exit
	set	ovr_msg, %o0
	ta	6
	ta	0

chk_rcv:
	! check for a received character
	andcc	%l1, 2, %g0
	be	top
	nop
		
	! get the character
	ld	[%l0 + 4], %l3

	! wait for transmit reg empty
poll_snd:
	ld	[%l0], %l1
	andcc	%l1, 1, %g0
	be	poll_snd
	nop

	! send the character to the UART
	st	%l3, [%l0+4]

	deccc	%l2
	bne	top
	nop

	ta	0