doc improvements

This commit is contained in:
Robin Müller 2022-06-12 21:22:48 +02:00
parent 4d7b047f11
commit 62bd90ed25
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
6 changed files with 61 additions and 33 deletions

View File

@ -1,11 +1,4 @@
//! # Core components of the Flight Software Rust Crate (FSRC) collection.
//!
//! This includes components to perform the following tasks
//!
//! 1. Object Management with the [objects] module
//! 2. Task scheduling with the [executable] module
//! 3. Events with the [events] module and event management with the [event_man] module
//! 4. Pre-Allocated memory pools with the [pool] module
//! # Core components of the Flight Software Rust Crate (FSRC) collection
pub mod event_man;
pub mod events;
pub mod executable;

View File

@ -1,3 +1,4 @@
//! [Event][crate::core::events::Event] management and forwarding
use crate::core::events::{Event, EventRaw, GroupId};
use std::collections::HashMap;

View File

@ -1,3 +1,4 @@
//! Event support module
use num::pow;
pub type GroupId = u16;

View File

@ -1,3 +1,4 @@
//! Task scheduling module
use bus::BusReader;
use std::error::Error;
use std::sync::mpsc::TryRecvError;

View File

@ -1,4 +1,4 @@
//! # Pool implementation providing sub-pools with fixed size memory blocks
//! # Pool implementation providing pre-allocated sub-pools with fixed size memory blocks
//!
//! This is a simple memory pool implementation which pre-allocates all sub-pools using a given pool
//! configuration. After the pre-allocation, no dynamic memory allocation will be performed
@ -85,7 +85,6 @@ pub struct PoolCfg {
cfg: Vec<(NumBlocks, usize)>,
}
impl PoolCfg {
pub fn new(cfg: Vec<(NumBlocks, usize)>) -> Self {
PoolCfg { cfg }
@ -128,7 +127,7 @@ impl StoreAddr {
#[derive(Debug, Clone, PartialEq)]
pub enum StoreIdError {
InvalidSubpool(u16),
InvalidPacketIdx(u16)
InvalidPacketIdx(u16),
}
#[derive(Debug, Clone, PartialEq)]
@ -226,10 +225,16 @@ impl LocalPool {
fn addr_check(&self, addr: &StoreAddr) -> Result<usize, StoreError> {
let pool_idx = addr.pool_idx as usize;
if pool_idx as usize >= self.pool_cfg.cfg.len() {
return Err(StoreError::InvalidStoreId(StoreIdError::InvalidSubpool(addr.pool_idx), Some(*addr)));
return Err(StoreError::InvalidStoreId(
StoreIdError::InvalidSubpool(addr.pool_idx),
Some(*addr),
));
}
if addr.packet_idx >= self.pool_cfg.cfg[addr.pool_idx as usize].0 {
return Err(StoreError::InvalidStoreId(StoreIdError::InvalidPacketIdx(addr.packet_idx), Some(*addr)));
return Err(StoreError::InvalidStoreId(
StoreIdError::InvalidPacketIdx(addr.packet_idx),
Some(*addr),
));
}
let size_list = self.sizes_lists.get(pool_idx).unwrap();
let curr_size = size_list[addr.packet_idx as usize];
@ -287,7 +292,10 @@ impl LocalPool {
}
}
} else {
return Err(StoreError::InvalidStoreId(StoreIdError::InvalidSubpool(subpool),None));
return Err(StoreError::InvalidStoreId(
StoreIdError::InvalidSubpool(subpool),
None,
));
}
Err(StoreError::StoreFull(subpool))
}
@ -329,10 +337,13 @@ mod tests {
// Try to access data which does not exist
let res = local_pool.read(&StoreAddr {
packet_idx: 0,
pool_idx: 0
pool_idx: 0,
});
assert!(res.is_err());
assert!(matches!(res.unwrap_err(), StoreError::DataDoesNotExist { .. }));
assert!(matches!(
res.unwrap_err(),
StoreError::DataDoesNotExist { .. }
));
let mut test_buf: [u8; 16] = [0; 16];
for (i, val) in test_buf.iter_mut().enumerate() {
*val = i as u8;
@ -341,10 +352,13 @@ mod tests {
assert!(res.is_ok());
let addr = res.unwrap();
// Only the second subpool has enough storage and only one bucket
assert_eq!(addr, StoreAddr {
assert_eq!(
addr,
StoreAddr {
pool_idx: 2,
packet_idx: 0
});
}
);
// The subpool is now full and the call should fail accordingly
let res = local_pool.add(test_buf);
@ -373,7 +387,13 @@ mod tests {
let res = local_pool.free_element(12);
assert!(res.is_ok());
let (addr, buf_ref) = res.unwrap();
assert_eq!(addr, StoreAddr {pool_idx: 2, packet_idx:0});
assert_eq!(
addr,
StoreAddr {
pool_idx: 2,
packet_idx: 0
}
);
assert_eq!(buf_ref.len(), 12);
assert_eq!(buf_ref, [0; 12]);
buf_ref[0] = 5;
@ -397,20 +417,32 @@ mod tests {
}
{
let addr = StoreAddr{pool_idx: 3, packet_idx: 0};
let addr = StoreAddr {
pool_idx: 3,
packet_idx: 0,
};
let res = local_pool.read(&addr);
assert!(res.is_err());
let err = res.unwrap_err();
assert!(matches!(err, StoreError::InvalidStoreId(StoreIdError::InvalidSubpool(3), Some(_))));
assert!(matches!(
err,
StoreError::InvalidStoreId(StoreIdError::InvalidSubpool(3), Some(_))
));
}
{
let addr = StoreAddr{pool_idx: 2, packet_idx: 1};
let addr = StoreAddr {
pool_idx: 2,
packet_idx: 1,
};
assert_eq!(addr.raw(), 0x00020001);
let res = local_pool.read(&addr);
assert!(res.is_err());
let err = res.unwrap_err();
assert!(matches!(err, StoreError::InvalidStoreId(StoreIdError::InvalidPacketIdx(1), Some(_))));
assert!(matches!(
err,
StoreError::InvalidStoreId(StoreIdError::InvalidPacketIdx(1), Some(_))
));
let data_too_large = [0; 20];
let res = local_pool.add(data_too_large);
@ -420,7 +452,10 @@ mod tests {
let res = local_pool.free_element(LocalPool::MAX_SIZE + 1);
assert!(res.is_err());
assert_eq!(res.unwrap_err(), StoreError::DataTooLarge(LocalPool::MAX_SIZE + 1));
assert_eq!(
res.unwrap_err(),
StoreError::DataTooLarge(LocalPool::MAX_SIZE + 1)
);
}
{

View File

@ -1,4 +1 @@
fn main() {
}
fn main() {}