Skip to main content

leodos_libcfs/psp/
eeprom.rs

1//! EEPROM (Electrically Erasable Programmable Read-Only Memory) interface.
2//!
3//! These functions are highly platform-specific and should only be used by
4//! applications that need to directly interact with non-volatile memory hardware.
5//! All functions in this module are `unsafe`.
6
7use crate::error::Result;
8use crate::ffi;
9use crate::status::check;
10
11/// Writes one byte to an EEPROM address.
12///
13/// May return `TIMEOUT` (write did not complete),
14/// `ADDRESS_MISALIGNED`, or `NOT_IMPLEMENTED`.
15pub unsafe fn write_u8(address: usize, value: u8) -> Result<()> {
16    check(ffi::CFE_PSP_EepromWrite8(address, value))?;
17    Ok(())
18}
19
20/// Writes two bytes to an EEPROM address.
21///
22/// May return `TIMEOUT`, `ADDRESS_MISALIGNED`, or
23/// `NOT_IMPLEMENTED`.
24pub unsafe fn write_u16(address: usize, value: u16) -> Result<()> {
25    check(ffi::CFE_PSP_EepromWrite16(address, value))?;
26    Ok(())
27}
28
29/// Writes four bytes to an EEPROM address.
30///
31/// May return `TIMEOUT`, `ADDRESS_MISALIGNED`, or
32/// `NOT_IMPLEMENTED`.
33pub unsafe fn write_u32(address: usize, value: u32) -> Result<()> {
34    check(ffi::CFE_PSP_EepromWrite32(address, value))?;
35    Ok(())
36}
37
38/// Enables write operations for a specific bank of EEPROM.
39///
40/// May return `NOT_IMPLEMENTED` on platforms without EEPROM.
41pub unsafe fn write_enable(bank: u32) -> Result<()> {
42    check(ffi::CFE_PSP_EepromWriteEnable(bank))?;
43    Ok(())
44}
45
46/// Disables write operations for a specific bank of EEPROM.
47///
48/// May return `NOT_IMPLEMENTED` on platforms without EEPROM.
49pub unsafe fn write_disable(bank: u32) -> Result<()> {
50    check(ffi::CFE_PSP_EepromWriteDisable(bank))?;
51    Ok(())
52}
53
54/// Powers up a specific bank of EEPROM.
55///
56/// May return `NOT_IMPLEMENTED` on platforms without EEPROM.
57pub unsafe fn power_up(bank: u32) -> Result<()> {
58    check(ffi::CFE_PSP_EepromPowerUp(bank))?;
59    Ok(())
60}
61
62/// Powers down a specific bank of EEPROM.
63///
64/// May return `NOT_IMPLEMENTED` on platforms without EEPROM.
65pub unsafe fn power_down(bank: u32) -> Result<()> {
66    check(ffi::CFE_PSP_EepromPowerDown(bank))?;
67    Ok(())
68}