@@ -4,14 +4,13 @@ use core::mem;
4
4
5
5
use kernel;
6
6
use kernel:: screen:: * ;
7
- use kernel:: sgash:: SGASH ;
8
7
use core:: mem:: transmute;
9
8
10
9
/* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0225d/BBABEGGE.html */
11
10
/* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0225d/BBABEGGE.html */
12
- static VIC_INT : * mut u32 = ( 0x10140000 ) as * mut u32 ;
13
- static VIC_INT_ENABLE : * mut u32 = ( 0x10140000 + 0x10 ) as * mut u32 ;
14
- static VIC_INT_DISABLE : * mut u32 = ( 0x10140000 + 0x14 ) as * mut u32 ; // "enable clear"
11
+ pub static VIC_INT : * mut u32 = ( 0x10140000 ) as * mut u32 ;
12
+ pub static VIC_INT_ENABLE : * mut u32 = ( 0x10140000 + 0x10 ) as * mut u32 ;
13
+ pub static VIC_INT_DISABLE : * mut u32 = ( 0x10140000 + 0x14 ) as * mut u32 ; // "enable clear"
15
14
16
15
pub mod screen
17
16
{
@@ -311,7 +310,7 @@ pub unsafe fn init(r : Resolution)
311
310
cv. fill_bg ( ) ;
312
311
}
313
312
314
- static UART_CLK : uint = 24000000 ; // 24 MHz
313
+ pub static UART_CLK : uint = 24_000_000 ; // 24 MHz
315
314
316
315
pub mod serial
317
316
{
@@ -320,168 +319,20 @@ pub mod serial
320
319
use platform:: cpu:: interrupt;
321
320
use core:: mem:: { volatile_load, volatile_store} ;
322
321
use platform:: io;
322
+ use platform:: drivers:: pl011_uart:: PL011 ;
323
+ use platform:: drivers:: pl011_uart:: UART_BUFF_SZ ;
323
324
324
- // TODO Use resizable buffers
325
- static UART_BUF_SZ : uint = 1024 ;
326
-
327
- // See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0224i/Bbabegge.html
328
-
329
-
330
- struct UART {
331
- priv base : * mut u32 ,
332
- priv IMSC : * mut u32 ,
333
- priv IRQ : u8 ,
334
- priv rate : baud ,
335
- priv buffer : [ u8 , .. UART_BUF_SZ ] ,
336
- priv buf_head : uint ,
337
- priv buf_count : uint ,
338
- }
339
-
340
- // See http://infocenter.arm.com/help/topic/com.arm.doc.ddi0183f/DDI0183.pdf
341
-
342
- pub static mut UART0 : UART = UART {
343
- base : 0x101f1000 as * mut u32 ,
344
- IMSC : ( 0x101f1000 + 0x038 ) as * mut u32 ,
325
+ pub static mut UART0 : PL011 = PL011 {
326
+ base : 0x101f1000 ,
345
327
IRQ : 12 ,
346
- /* TODO receive handlers */
328
+ receiver : UART0_receiveInterrupt ,
329
+
347
330
rate : 0 ,
348
- buffer : [ 0 , .. UART_BUF_SZ ] ,
331
+ buffer : [ 0 , .. UART_BUFF_SZ ] ,
349
332
buf_head : 0 ,
350
333
buf_count : 0 ,
351
334
} ;
352
335
353
- impl Serial for UART {
354
-
355
- /// Initialize device and begin transmission. Returns true if device successfully opened.
356
- // TODO allow for multiple baud rates
357
- #[ allow( unused_variable) ]
358
- fn open ( & mut self , r : u32 ) -> bool
359
- {
360
- unsafe {
361
- // enable UART0 IRQ [4]
362
- * super :: VIC_INT_ENABLE = 1 << self . IRQ ;
363
- // enable RXIM interrupt (interrupt on receive)
364
- /*
365
- * See
366
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0183f/I54603.html
367
- */
368
- * self . IMSC = 1 << 4 ;
369
- kernel:: int_table. map ( |t| {
370
- t. enable ( interrupt:: IRQ , UART0_receiveInterrupt ) ;
371
- } ) ;
372
- }
373
- self . buf_head = 0 ;
374
- self . buf_count = 0 ;
375
- false
376
- }
377
-
378
- fn isOpen ( & self ) -> bool
379
- {
380
- self . rate == 0
381
- }
382
-
383
- /// End transmission, close device. Returns true if device is closed after operation.
384
- fn close ( & mut self ) -> bool
385
- {
386
- self . rate = 0 ;
387
- self . buf_head = 0 ;
388
- self . buf_count = 0 ;
389
- true
390
- }
391
-
392
- /// Number of bytes available to read
393
- fn available ( & self ) -> uint
394
- {
395
- self . buf_count
396
- }
397
-
398
- /// Read up to length bytes into buffer. Return number of bytes read.
399
- fn readBuf ( & mut self , buffer : & mut [ u8 ] , length : uint ) -> uint
400
- {
401
- let mut i = 0 ;
402
- while ( i < length && self . buf_count > 0 )
403
- {
404
- self . read ( & mut buffer[ i] ) ;
405
- i += 1 ;
406
- }
407
- i
408
- }
409
-
410
- /// Read one character into buffer. Return number of bytes read.
411
- fn read ( & mut self , c : & mut u8 ) -> uint
412
- {
413
- if self . buf_count == 0
414
- {
415
- return 0 ;
416
- }
417
- else
418
- {
419
- * c = self . buffer [ self . buf_head ] ;
420
- self . buf_head += 1 ;
421
- self . buf_count -= 1 ;
422
- return 1 ;
423
- }
424
- }
425
-
426
- /// Write a single byte. Return number of bytes written.
427
- fn write ( & self , c : u8 ) -> uint
428
- {
429
- unsafe {
430
- /*
431
- * We need to include a blank asm call to prevent rustc
432
- * from optimizing this part out
433
- */
434
- asm ! ( "" ) ;
435
- volatile_store ( self . base , c as u32 ) ;
436
- }
437
- 1
438
- }
439
-
440
- /// Write a buffer of bytes. Return number of bytes written.
441
- fn writeBuf ( & self , buffer : & [ u8 ] , length : uint ) -> uint
442
- {
443
- let mut i = 0 ;
444
- while ( i < length)
445
- {
446
- self . write ( buffer[ i] ) ;
447
- }
448
- return length;
449
- }
450
-
451
- fn flush ( & self ) -> uint
452
- {
453
- 0
454
- }
455
-
456
- /// Callback on new data available.
457
- fn addReceiveHandler ( & self , newHandler : serialReceiveHandler ) -> bool
458
- {
459
- false
460
- }
461
-
462
- /// Remove all receive handlers
463
- fn clearReceiveHandlers ( & self )
464
- {
465
- ( )
466
- }
467
- }
468
-
469
- impl UART
470
- {
471
- fn receive ( & mut self , c : u8 ) -> bool
472
- {
473
- if ( self . buf_count == UART_BUF_SZ )
474
- {
475
- false
476
- } else
477
- {
478
- self . buffer [ ( self . buf_head + self . buf_count ) % UART_BUF_SZ ] = c;
479
- self . buf_count += 1 ;
480
- true
481
- }
482
- }
483
- }
484
-
485
336
#[ no_mangle]
486
337
unsafe fn UART0_receiveInterrupt ( )
487
338
{
0 commit comments