1 ;;; Serial
- simple serial I
/O
3 ;;; Copyright
2009 Christopher Hall
<hsw@openmoko.com
>
5 ;;; Redistribution
and use in source
and binary forms
, with
or without
6 ;;; modification
, are permitted provided that the following conditions are
9 ;;;
1. Redistributions of source code must retain the above copyright
10 ;;; notice
, this list of conditions
and the following disclaimer.
12 ;;;
2. Redistributions in binary form must reproduce the above copyright
13 ;;; notice
, this list of conditions
and the following disclaimer in
14 ;;; the documentation
and/or other materials provided with the
17 ;;; THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS
'' AND ANY
18 ;;; EXPRESS
OR IMPLIED WARRANTIES
, INCLUDING
, BUT
NOT LIMITED TO
, THE
19 ;;; IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR
A PARTICULAR
20 ;;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS
BE LIABLE
21 ;;; FOR ANY DIRECT
, INDIRECT
, INCIDENTAL
, SPECIAL
, EXEMPLARY
, OR
22 ;;; CONSEQUENTIAL DAMAGES
(INCLUDING
, BUT
NOT LIMITED TO
, PROCUREMENT OF
23 ;;; SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE
, DATA
, OR PROFITS;
OR
24 ;;; BUSINESS INTERRUPTION
) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY
,
25 ;;; WHETHER IN CONTRACT
, STRICT LIABILITY
, OR TORT
(INCLUDING NEGLIGENCE
26 ;;;
OR OTHERWISE
) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE
, EVEN
27 ;;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 ;;; macro for regs.inc
30 .macro REGDEF, address, bits, name
31 R
\bits\
()_
\name
= \address
34 .include "c33regs.inc"
37 ;;;
r0 .. r3 must be preserved
40 ;;;
r6 .. r9 arguments 1..4
41 ;;;
r10 ..r14 reserved
47 ;;; Bits for
: REG_EFSIFx_STATUS
61 .global Serial_PutCRLF
72 .global Serial_PutSpace
82 .global Serial_PutChar
84 xld.w
%r4, R8_EFSIF0_STATUS
88 jreq Serial_PutChar_wait
90 xld.w
%r5, R8_EFSIF0_TXD
96 ;;;
r6 = address of
'\0' terminated string
99 ;;;
r9 = address during loop
100 .global Serial_PutString
103 Serial_PutString_loop
:
106 jreq Serial_PutString_done
108 jreq Serial_PutString_crlf
110 jp Serial_PutString_loop
111 Serial_PutString_crlf
:
113 jp Serial_PutString_loop
114 Serial_PutString_done
:
118 ;;; print
a hex nibble
120 ;;;
r6 = 4 bit number to print
122 .global Serial_PutNibble
127 jrle Serial_PutNibble_l1
128 xadd
%r6, 'a' - '9' - 1
136 ;;;
r6 = 32 bit number to print
139 ;;;
r9 = thet word being output
140 .global Serial_PutHex
144 xcall Serial_PutNibble
148 xcall Serial_PutNibble
152 xcall Serial_PutNibble
156 xcall Serial_PutNibble
160 xcall Serial_PutNibble
164 xcall Serial_PutNibble
168 xcall Serial_PutNibble
171 xcall Serial_PutNibble
180 .global Serial_GetChar
182 call Serial_InputAvailable
185 xld.w
%r4, R8_EFSIF0_RXD
190 ;;; see if input is available
193 ;;;
r4 = 0 => not ready
195 .global Serial_InputAvailable
196 Serial_InputAvailable
:
197 xld.w
%r4, R8_EFSIF0_STATUS
200 jreq Serial_InputAvailable_done
202 Serial_InputAvailable_done
: