Chinaunix首页 | 论坛 | 博客
  • 博客访问: 104951
  • 博文数量: 11
  • 博客积分: 2520
  • 博客等级: 少校
  • 技术积分: 172
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-17 09:26
文章分类
文章存档

2009年(11)

我的朋友

分类:

2009-05-25 08:30:50

下面代码中初始化串口控制器。用于底层调试。
下面初始化串口控制器:

124 /*
125 *initilize UART for debug
126 */
127 uart_init:
128 ldr r1, =rUFCON0
129 mov r2, #0x0
130 str r2, [r1]
131
132 ldr r1, =rUMCON0
133 mov r2, #0x0
134 str r2, [r1]
135
136 ldr r1, =rULCON0
137 mov r2, #0x03
138 str r2, [r1]
139
140 ldr r1, =rUCON0
141 ldr r2, =0x245
142 str r2, [r1]
143
144 ldr r1, =rUBRDIV0
145 ldr r2, =vUBRDIV0
146 str r2, [r1]
147
148 @loop 100
149 mov r3, #100
150 mov r2, #0x0
151 1: sub r3, r3, #0x1
152 tst r2, r3
153 bne 1b
154
155 mov pc, lr

下面是打印函数:

157 /*
158 *PrintFaultAddr: Print fault address
159 *r12: contains address of instruction +4
160 */
161 PrintFaultAddr:
162 mov r0, r12
163 bl PrintHexWord
164 mrc p15, 0, r0, c6, c0, 0
165 bl PrintHexWord
166 mov pc, lr
167 /*
168 *PrintHexNibble:print the least-significant nibble in r0 as
169 *a hex digit
170 *r0:contains nibble to write as Hex
171 *write to with XXX, modifies r0,r2
172 *TODO:write to with reg ro error handling
173 *Falls through to PrintChar
174 */
175 PrintHexNibble:
176 adr r2, HEX_TO_ASCII_TABLE
177 and r0, r0, #0xf
178 ldr r0, [r2, r0]
179 b PrintChar
180
181 /*
182 *PrintChar: prints the character in r0
183 *r0 contains the character
184 *writes r0 with XXX, modifies r0,r2
185 *TODO:write r0 with XXX reg ro error hangling
186 */
187 PrintChar:
188 TXBusy:
189 ldr r2, =rUTRSTAT0
190 ldr r2, [r2]
191 and r2, r2, #(1<<2)
192 tst r2, #(1<<2)
193 beq TXBusy
194 ldr r1, =rUTXH0
195 str r0, [r1]
196 mov pc, lr
197 /*
198 *PrintWord: print the 4 characters in r0
199 *r0 contains the character
200 *writes r0 with XXX, modifies r0,r2
201 *TODO:write r0 with XXX reg ro error hangling
202 */
203 PrintWord:
204 mov r3, r0
205 mov r4, lr
206 bl PrintChar
207
208 mov r0, r3, lsr #8
209 bl PrintChar
210
211 mov r0, r3, lsr #16
212 bl PrintChar
213
214 mov r0, r3, lsr #24
215 bl PrintChar
216
217 mov r0, #'\r'
218 bl PrintChar
219
220 mov pc, r4
221
222 /*
223 *PrintHexWord : prints the 4 bytes in R0 as 8 hex ascii characters
224 *followed by a newline
225 *r0 contains the binary word
226 *r1 contains the base of the serial port
227 *writes ro with XXX, modifies r0,r2
228 *TODO : write ro with XXX reg to error handling
229 */
230 PrintHexWord:
231 mov r4, lr
232 mov r3, r0
233 mov r0, r3, LSR #28
234 bl PrintHexNibble
235 mov r0, r3, LSR #24
236 bl PrintHexNibble
237 mov r0, r3, LSR #20
238 bl PrintHexNibble
239 mov r0, r3, LSR #16
240 bl PrintHexNibble
241 mov r0, r3, LSR #12
242 bl PrintHexNibble
243 mov r0, r3, LSR #8
244 bl PrintHexNibble
245 mov r0, r3, LSR #4
246 bl PrintHexNibble
247 mov r0, r3
248 bl PrintHexNibble
249 mov r0, #'\r'
250 bl PrintChar
251 mov r0, #'\n'
252 bl PrintChar
253 mov pc, r4
254
255 .align 2
256 HEX_TO_ASCII_TABLE:
257 .ascii "0123456789ABCDEF"
258 STR_STACK:
259 .ascii "STKP"
260 STR_UNDEF:
261 .ascii "UNDF"
262 STR_SWI:
263 .ascii "SWI "
264 STR_PREFETCH_ABORT:
265 .ascii "PABT"
266 STR_DATA_ABORT:
267 .ascii "DABT"
268 STR_IRQ:
269 .ascii "IRQ "
270 STR_FIQ:
271 .ascii "FIQ"
272 STR_NOT_USED:
273 .ascii "NUSD"
274 .align 2
275 STR_OK:
276 .ascii "OK "
277 STR_FAIL:
278 .ascii "FAIL"
279 STR_CR:
280 .ascii "\r\n"

 

文件: uart4debug.tar.bz2
大小: 4KB
下载: 下载
阅读(1444) | 评论(0) | 转发(0) |
0

上一篇:memory controller 试验

下一篇:printk函数实现

给主人留下些什么吧!~~