diff --git a/01_bareminimum/Makefile b/01_bareminimum/Makefile index 3d047753..d963ab87 100644 --- a/01_bareminimum/Makefile +++ b/01_bareminimum/Makefile @@ -55,4 +55,4 @@ qemu: clean: cargo clean - rm -f kernel8 + diff --git a/02_multicore_rust/Makefile b/02_multicore_rust/Makefile index 219b2e2a..9fee70c6 100644 --- a/02_multicore_rust/Makefile +++ b/02_multicore_rust/Makefile @@ -58,4 +58,4 @@ clippy: clean: cargo clean - rm -f kernel8 + diff --git a/03_uart1/Makefile b/03_uart1/Makefile index f8217023..907acb91 100644 --- a/03_uart1/Makefile +++ b/03_uart1/Makefile @@ -58,4 +58,4 @@ clippy: clean: cargo clean - rm -f kernel8 + diff --git a/04_mailboxes/Makefile b/04_mailboxes/Makefile index f8217023..907acb91 100644 --- a/04_mailboxes/Makefile +++ b/04_mailboxes/Makefile @@ -58,4 +58,4 @@ clippy: clean: cargo clean - rm -f kernel8 + diff --git a/05_uart0/Makefile b/05_uart0/Makefile index f8217023..907acb91 100644 --- a/05_uart0/Makefile +++ b/05_uart0/Makefile @@ -58,4 +58,4 @@ clippy: clean: cargo clean - rm -f kernel8 + diff --git a/05_uart0/kernel8 b/05_uart0/kernel8 index f362f079..f1fb241e 100755 Binary files a/05_uart0/kernel8 and b/05_uart0/kernel8 differ diff --git a/06_raspbootin64/Makefile b/06_raspbootin64/Makefile index f8217023..907acb91 100644 --- a/06_raspbootin64/Makefile +++ b/06_raspbootin64/Makefile @@ -58,4 +58,4 @@ clippy: clean: cargo clean - rm -f kernel8 + diff --git a/07_abstraction/Makefile b/07_abstraction/Makefile index e6e69056..cee16687 100644 --- a/07_abstraction/Makefile +++ b/07_abstraction/Makefile @@ -63,4 +63,4 @@ clippy: clean: cargo clean - rm -f kernel8 + diff --git a/07_abstraction/kernel8 b/07_abstraction/kernel8 index e3a34fb1..e2fe8a83 100755 Binary files a/07_abstraction/kernel8 and b/07_abstraction/kernel8 differ diff --git a/08_random/Makefile b/08_random/Makefile index e6e69056..cee16687 100644 --- a/08_random/Makefile +++ b/08_random/Makefile @@ -63,4 +63,4 @@ clippy: clean: cargo clean - rm -f kernel8 + diff --git a/08_random/kernel8 b/08_random/kernel8 index d761c542..ca4f78bc 100755 Binary files a/08_random/kernel8 and b/08_random/kernel8 differ diff --git a/09_delays/Makefile b/09_delays/Makefile index e6e69056..cee16687 100644 --- a/09_delays/Makefile +++ b/09_delays/Makefile @@ -63,4 +63,4 @@ clippy: clean: cargo clean - rm -f kernel8 + diff --git a/09_delays/kernel8 b/09_delays/kernel8 index 03f10292..cf91dc3b 100755 Binary files a/09_delays/kernel8 and b/09_delays/kernel8 differ diff --git a/0A_power/Makefile b/0A_power/Makefile index e6e69056..cee16687 100644 --- a/0A_power/Makefile +++ b/0A_power/Makefile @@ -63,4 +63,4 @@ clippy: clean: cargo clean - rm -f kernel8 + diff --git a/0A_power/kernel8 b/0A_power/kernel8 index de098464..e0d74e74 100755 Binary files a/0A_power/kernel8 and b/0A_power/kernel8 differ diff --git a/0A_power/src/delays.rs b/0A_power/src/delays.rs index a2a46284..63414e4f 100644 --- a/0A_power/src/delays.rs +++ b/0A_power/src/delays.rs @@ -22,110 +22,7 @@ * SOFTWARE. */ -use super::MMIO_BASE; -use core::ops; -use cortex_a::{asm, regs::*}; -use register::mmio::*; - -const DELAY_BASE: u32 = MMIO_BASE + 0x3004; - -/* - * - * Using the RPi3 SoC's system timer peripheral - * - */ -#[allow(non_snake_case)] -#[repr(C)] -pub struct RegisterBlock { - SYSTMR_LO: ReadOnly, // 0x00 - SYSTMR_HI: ReadOnly, // 0x04 -} - -/// Public interface to the BCM System Timer -pub struct SysTmr; - -impl ops::Deref for SysTmr { - type Target = RegisterBlock; - - fn deref(&self) -> &Self::Target { - unsafe { &*Self::ptr() } - } -} - -impl SysTmr { - pub fn new() -> SysTmr { - SysTmr - } - - /// Returns a pointer to the register block - fn ptr() -> *const RegisterBlock { - DELAY_BASE as *const _ - } - - /// Get System Timer's counter - pub fn get_system_timer(&self) -> u64 { - // Since it is MMIO, we must emit two separate 32 bit reads - let mut hi = self.SYSTMR_HI.get(); - let mut lo = self.SYSTMR_LO.get(); - - // We have to repeat if high word changed during read. This - // will emit a clippy warning that needs be ignored, or you - // lose an MMIO read. - if hi != self.SYSTMR_HI.get() { - hi = self.SYSTMR_HI.get(); - lo = self.SYSTMR_LO.get(); - } - - // Compose long int value - (u64::from(hi) << 32) | u64::from(lo) - } - - /// Wait N microsec (with BCM System Timer) - pub fn wait_msec_st(&self, n: u64) { - let t = self.get_system_timer(); - - // We must check if it's non-zero, because qemu does not - // emulate system timer, and returning constant zero would - // mean infinite loop - if t > 0 { - loop { - if self.get_system_timer() < (t + n) { - break; - } - } - } - } -} - -/* - * - * Using the CPU's counter registers - * - */ -/// Wait N microsec (ARM CPU only) -pub fn wait_msec(n: u32) { - // Get the counter frequency - let frq = CNTFRQ_EL0.get(); - - // Calculate number of ticks - let tval = (frq as u32 / 1000) * n; - - // Set the compare value register - CNTP_TVAL_EL0.set(tval); - - // Kick off the counting // Disable timer interrupt - CNTP_CTL_EL0.modify(CNTP_CTL_EL0::ENABLE::SET + CNTP_CTL_EL0::IMASK::SET); - - loop { - // ISTATUS will be one when cval ticks have passed. Continuously check it. - if CNTP_CTL_EL0.is_set(CNTP_CTL_EL0::ISTATUS) { - break; - } - } - - // Disable counting again - CNTP_CTL_EL0.modify(CNTP_CTL_EL0::ENABLE::CLEAR); -} +use cortex_a::asm; /* * diff --git a/0B_exception_levels/Makefile b/0B_exception_levels/Makefile index 26e15973..f1b8db24 100644 --- a/0B_exception_levels/Makefile +++ b/0B_exception_levels/Makefile @@ -63,4 +63,4 @@ clippy: clean: cargo clean - rm -f kernel8 + diff --git a/0B_exception_levels/kernel8 b/0B_exception_levels/kernel8 index 78103882..fd00f989 100755 Binary files a/0B_exception_levels/kernel8 and b/0B_exception_levels/kernel8 differ diff --git a/0C_virtual_memory/Makefile b/0C_virtual_memory/Makefile index 26e15973..f1b8db24 100644 --- a/0C_virtual_memory/Makefile +++ b/0C_virtual_memory/Makefile @@ -63,4 +63,4 @@ clippy: clean: cargo clean - rm -f kernel8 + diff --git a/0C_virtual_memory/kernel8 b/0C_virtual_memory/kernel8 index 727ac409..fa3382f3 100755 Binary files a/0C_virtual_memory/kernel8 and b/0C_virtual_memory/kernel8 differ diff --git a/0D_cache_performance/Makefile b/0D_cache_performance/Makefile index 26e15973..f1b8db24 100644 --- a/0D_cache_performance/Makefile +++ b/0D_cache_performance/Makefile @@ -63,4 +63,4 @@ clippy: clean: cargo clean - rm -f kernel8 + diff --git a/0D_cache_performance/kernel8 b/0D_cache_performance/kernel8 index 8b80d88b..bd542bdf 100755 Binary files a/0D_cache_performance/kernel8 and b/0D_cache_performance/kernel8 differ diff --git a/0D_cache_performance/kernel8.img b/0D_cache_performance/kernel8.img index d68c9481..27af497c 100755 Binary files a/0D_cache_performance/kernel8.img and b/0D_cache_performance/kernel8.img differ