Skip to main content

leodos_libcfs/psp/
cds.rs

1//! CDS (Critical Data Store) interface.
2
3use crate::error::Result;
4use crate::ffi;
5use crate::status::check;
6use core::mem::MaybeUninit;
7
8/// Gets the size of the CDS memory area from the PSP.
9pub fn get_cds_size() -> Result<usize> {
10    let mut size = MaybeUninit::uninit();
11    check(unsafe { ffi::CFE_PSP_GetCDSSize(size.as_mut_ptr()) })?;
12    Ok(unsafe { size.assume_init() } as usize)
13}
14
15/// Writes a block of data to the CDS at a specified offset.
16///
17/// # Safety
18/// This is a raw memory write. The caller must ensure that `offset + data.len()`
19/// does not exceed the total size of the CDS.
20pub unsafe fn write_to_cds(data: &[u8], offset: usize) -> Result<()> {
21    check(ffi::CFE_PSP_WriteToCDS(
22        data.as_ptr() as *const _,
23        offset as u32,
24        data.len() as u32,
25    ))?;
26    Ok(())
27}
28
29/// Reads a block of data from the CDS at a specified offset.
30///
31/// # Safety
32/// This is a raw memory read. The caller must ensure that `offset + buf.len()`
33/// does not exceed the total size of the CDS.
34pub unsafe fn read_from_cds(buf: &mut [u8], offset: usize) -> Result<()> {
35    check(ffi::CFE_PSP_ReadFromCDS(
36        buf.as_mut_ptr() as *mut _,
37        offset as u32,
38        buf.len() as u32,
39    ))?;
40    Ok(())
41}