Skip to content

Commit f3147a9

Browse files
committed
PrimeCell UART impl, updated to rust-master
Updated the UART implementation and modified the 926 to use it. Also have updated to use rust's master branch, will try to maintain compatibilty therewith. Some odd fixes to do so (instance: extracting core.bc from libcore*.rlib doesn't work, so compiling core.bc on its own.)
1 parent d26fbc3 commit f3147a9

File tree

10 files changed

+166
-216
lines changed

10 files changed

+166
-216
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
arch=arm
2-
RUST_ROOT := /usr
2+
RUST_ROOT := /home/cceckman/rust-master
33
LLVM_ROOT := /usr
44
GCC_PREFIX := /usr/bin/
55

arch/arm/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ $(LCORE):
5151
$(RUSTC) $(RUSTCFLAGS) --dep-info $(@D)/core.d $(CORE_LIB) --out-dir $(BDIR)
5252

5353
$(BDIR)/core.bc: $(LCORE)
54-
cd $(@D); $(AR) -x $(<F) $(@F)
54+
$(RUSTC) $(RUSTCFLAGS) --dep-info $(@D)/core.d $(CORE_LIB) --emit bc --out-dir $(BDIR)
55+
#$(BDIR)/core.bc: $(LCORE)
56+
# cd $(@D); ar -x $(<F) $(@F)
5557

5658
# Compile rustboot
5759
$(BDIR)/main.bc: ../../lib.rs $(MODS) $(LCORE)
58-
$(RUSTC) $(RUSTCFLAGS) --dep-info $(@D)/main.d -L $(BDIR) --emit-llvm ../../lib.rs --out-dir $(BDIR)
60+
$(RUSTC) $(RUSTCFLAGS) --dep-info $(@D)/main.d -L $(BDIR) --emit bc ../../lib.rs --out-dir $(BDIR)
5961
# $(RUSTC) $(RUSTCFLAGS) --dep-info $(@D)/main.d -L $(BDIR) --emit-llvm ../../lib.rs --out-dir $(BDIR)
6062

6163
%.s: %.bc

arch/arm/drivers/arm926ej_s.rs

Lines changed: 11 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ use core::mem;
44

55
use kernel;
66
use kernel::screen::*;
7-
use kernel::sgash::SGASH;
87
use core::mem::transmute;
98

109
/* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0225d/BBABEGGE.html */
1110
/* 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"
1514

1615
pub mod screen
1716
{
@@ -311,7 +310,7 @@ pub unsafe fn init(r : Resolution)
311310
cv.fill_bg();
312311
}
313312

314-
static UART_CLK : uint = 24000000; // 24 MHz
313+
pub static UART_CLK : uint = 24_000_000; // 24 MHz
315314

316315
pub mod serial
317316
{
@@ -320,168 +319,20 @@ pub mod serial
320319
use platform::cpu::interrupt;
321320
use core::mem::{volatile_load, volatile_store};
322321
use platform::io;
322+
use platform::drivers::pl011_uart::PL011;
323+
use platform::drivers::pl011_uart::UART_BUFF_SZ;
323324

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,
345327
IRQ : 12,
346-
/* TODO receive handlers */
328+
receiver : UART0_receiveInterrupt,
329+
347330
rate : 0,
348-
buffer : [0, .. UART_BUF_SZ],
331+
buffer : [0, .. UART_BUFF_SZ],
349332
buf_head : 0,
350333
buf_count : 0,
351334
};
352335

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-
485336
#[no_mangle]
486337
unsafe fn UART0_receiveInterrupt()
487338
{

arch/arm/drivers/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ mod arm926ej_s;
2020
mod arm1176jzf_s;
2121

2222

23+
#[cfg(target_chip = "arm926ej-s")]
24+
#[cfg(target_chip = "arm1176jzf-s")]
25+
mod pl011_uart;
2326

2427
pub fn init() {
2528
// removed 926-specific initialization

0 commit comments

Comments
 (0)