From 554b9c85507d2a3612695925a466f92b2feeacff Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 4 Dec 2021 21:54:22 +0100 Subject: [PATCH] Added EDAC API --- CHANGELOG.md | 4 ++++ src/lib.rs | 1 + src/utility.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 src/utility.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index a47d46e..adeb7e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [unreleased] +### Added + +- Basic API for EDAC functionality + ## [0.2.2] ### Added diff --git a/src/lib.rs b/src/lib.rs index 0db37a5..9a138f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,7 @@ pub mod time; pub mod timer; pub mod typelevel; pub mod uart; +pub mod utility; mod private { /// Super trait used to mark traits with an exhaustive set of diff --git a/src/utility.rs b/src/utility.rs new file mode 100644 index 0000000..558128c --- /dev/null +++ b/src/utility.rs @@ -0,0 +1,43 @@ +//! # API for utility functions like the Error Detection and Correction (EDAC) block +//! +//! Some more information about the recommended scrub rates can be found on the +//! [Vorago White Paper website](https://www.voragotech.com/resources) in the +//! application note AN1212 +use va108xx::SYSCONFIG; + +#[derive(PartialEq, Debug)] +pub enum UtilityError { + InvalidCounterResetVal, +} + +/// Enable scrubbing for the ROM +/// +/// Returns [`UtilityError::InvalidCounterResetVal`] if the scrub rate is 0 +/// (equivalent to disabling) or larger than 24 bits +pub fn enable_rom_scrubbing(syscfg: &mut SYSCONFIG, scrub_rate: u32) -> Result<(), UtilityError> { + if scrub_rate == 0 || scrub_rate > u32::pow(2, 24) { + return Err(UtilityError::InvalidCounterResetVal); + } + syscfg.rom_scrub.write(|w| unsafe { w.bits(scrub_rate) }); + Ok(()) +} + +pub fn disable_rom_scrubbing(syscfg: &mut SYSCONFIG) { + syscfg.rom_scrub.write(|w| unsafe { w.bits(0) }) +} + +/// Enable scrubbing for the RAM +/// +/// Returns [`UtilityError::InvalidCounterResetVal`] if the scrub rate is 0 +/// (equivalent to disabling) or larger than 24 bits +pub fn enable_ram_scrubbing(syscfg: &mut SYSCONFIG, scrub_rate: u32) -> Result<(), UtilityError> { + if scrub_rate == 0 || scrub_rate > u32::pow(2, 24) { + return Err(UtilityError::InvalidCounterResetVal); + } + syscfg.ram_scrub.write(|w| unsafe { w.bits(scrub_rate) }); + Ok(()) +} + +pub fn disable_ram_scrubbing(syscfg: &mut SYSCONFIG) { + syscfg.ram_scrub.write(|w| unsafe { w.bits(0) }) +}