use crate::lib_bitfield;
use crate::result::Result;
use super::{ExtCsd, ExtCsdIndex};
mod rst_n;
pub use rst_n::*;
lib_bitfield! {
ResetnFunction: u8,
mask: 0x3,
default: 0,
{
rst_n_enable: ResetnEnable, 1, 0;
}
}
impl ExtCsd {
pub const fn rst_n_function(&self) -> Result<ResetnFunction> {
ResetnFunction::try_from_inner(self.0[ExtCsdIndex::RstnFunction.into_inner()])
}
pub fn set_rst_n_function(&mut self, val: ResetnFunction) {
self.0[ExtCsdIndex::RstnFunction.into_inner()] = val.into_inner();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_rst_n_function() {
let mut ext_csd = ExtCsd::new();
let mut rst_n_fn = ResetnFunction::new();
assert_eq!(ext_csd.rst_n_function(), Ok(rst_n_fn));
[
ResetnEnable::TempDisable,
ResetnEnable::PermEnable,
ResetnEnable::PermDisable,
]
.into_iter()
.for_each(|rst_n| {
rst_n_fn.set_rst_n_enable(rst_n);
assert_eq!(rst_n_fn.rst_n_enable(), Ok(rst_n));
ext_csd.set_rst_n_function(rst_n_fn);
assert_eq!(ext_csd.rst_n_function(), Ok(rst_n_fn));
});
}
}