diff options
author | 2017-06-13 20:41:15 +0100 | |
---|---|---|
committer | 2017-06-13 20:41:15 +0100 | |
commit | bd0a100ebf0a012a95e12d3070fa01e7a5b3658c (patch) | |
tree | c8b34ce35f3cc3c89511e45cd60eba7538949066 /src | |
parent | c442c1cb2bfdef634d24a6b00cd4d559f2dfb7fa (diff) | |
download | cortex-m-bd0a100ebf0a012a95e12d3070fa01e7a5b3658c.tar.gz cortex-m-bd0a100ebf0a012a95e12d3070fa01e7a5b3658c.tar.zst cortex-m-bd0a100ebf0a012a95e12d3070fa01e7a5b3658c.zip |
Add icache_enabled and dcache_enabled methods to SCB
Diffstat (limited to 'src')
-rw-r--r-- | src/peripheral/mod.rs | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/src/peripheral/mod.rs b/src/peripheral/mod.rs index 2dcfa30..b85f699 100644 --- a/src/peripheral/mod.rs +++ b/src/peripheral/mod.rs @@ -541,15 +541,17 @@ impl Scb { #[cfg(armv7m)] impl Scb { - /// Enables I-Cache + /// Enables I-Cache if currently disabled #[inline] pub fn enable_icache(&self) { + // Don't do anything if ICache is already enabled + if self.icache_enabled() { + return; + } + // All of CBP is write-only so no data races are possible let cbp = unsafe { &mut *CBP.get() }; - ::asm::dsb(); - ::asm::isb(); - // Invalidate I-Cache cbp.iciallu(); @@ -560,15 +562,17 @@ impl Scb { ::asm::isb(); } - /// Disables I-Cache + /// Disables I-Cache if currently enabled #[inline] pub fn disable_icache(&self) { + // Don't do anything if ICache is already disabled + if !self.icache_enabled() { + return; + } + // All of CBP is write-only so no data races are possible let cbp = unsafe { &mut *CBP.get() }; - ::asm::dsb(); - ::asm::isb(); - // Disable I-Cache unsafe { self.ccr.modify(|r| r & !SCB_CCR_IC_MASK) }; @@ -579,15 +583,20 @@ impl Scb { ::asm::isb(); } + /// Returns whether the I-Cache is currently enabled + #[inline] + pub fn icache_enabled(&self) -> bool { + ::asm::dsb(); + ::asm::isb(); + self.ccr.read() & SCB_CCR_IC_MASK == SCB_CCR_IC_MASK + } + /// Invalidates I-Cache #[inline] pub fn invalidate_icache(&self) { // All of CBP is write-only so no data races are possible let cbp = unsafe { &mut *CBP.get() }; - ::asm::dsb(); - ::asm::isb(); - // Invalidate I-Cache cbp.iciallu(); @@ -595,9 +604,14 @@ impl Scb { ::asm::isb(); } - /// Enables D-cache + /// Enables D-cache if currently disabled #[inline] pub fn enable_dcache(&self, cpuid: &Cpuid) { + // Don't do anything if DCache is already enabled + if self.dcache_enabled() { + return; + } + // Invalidate anything currently in the DCache self.invalidate_dcache(cpuid); @@ -608,9 +622,14 @@ impl Scb { ::asm::isb(); } - /// Disables D-cache + /// Disables D-cache if currently enabled #[inline] pub fn disable_dcache(&self, cpuid: &Cpuid) { + // Don't do anything if DCache is already disabled + if !self.dcache_enabled() { + return; + } + // Turn off the DCache unsafe { self.ccr.modify(|r| r & !SCB_CCR_DC_MASK) }; @@ -618,6 +637,14 @@ impl Scb { self.clean_invalidate_dcache(cpuid); } + /// Returns whether the D-Cache is currently enabled + #[inline] + pub fn dcache_enabled(&self) -> bool { + ::asm::dsb(); + ::asm::isb(); + self.ccr.read() & SCB_CCR_DC_MASK == SCB_CCR_DC_MASK + } + /// Invalidates D-cache /// /// Note that calling this while the dcache is enabled will probably wipe out your |