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. //! # 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
pub mod event_man; pub mod event_man;
pub mod events; pub mod events;
pub mod executable; 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 crate::core::events::{Event, EventRaw, GroupId};
use std::collections::HashMap; use std::collections::HashMap;

View File

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

View File

@ -1,3 +1,4 @@
//! Task scheduling module
use bus::BusReader; use bus::BusReader;
use std::error::Error; use std::error::Error;
use std::sync::mpsc::TryRecvError; 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 //! 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 //! configuration. After the pre-allocation, no dynamic memory allocation will be performed
@ -85,7 +85,6 @@ pub struct PoolCfg {
cfg: Vec<(NumBlocks, usize)>, cfg: Vec<(NumBlocks, usize)>,
} }
impl PoolCfg { impl PoolCfg {
pub fn new(cfg: Vec<(NumBlocks, usize)>) -> Self { pub fn new(cfg: Vec<(NumBlocks, usize)>) -> Self {
PoolCfg { cfg } PoolCfg { cfg }
@ -128,7 +127,7 @@ impl StoreAddr {
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub enum StoreIdError { pub enum StoreIdError {
InvalidSubpool(u16), InvalidSubpool(u16),
InvalidPacketIdx(u16) InvalidPacketIdx(u16),
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
@ -226,10 +225,16 @@ impl LocalPool {
fn addr_check(&self, addr: &StoreAddr) -> Result<usize, StoreError> { fn addr_check(&self, addr: &StoreAddr) -> Result<usize, StoreError> {
let pool_idx = addr.pool_idx as usize; let pool_idx = addr.pool_idx as usize;
if pool_idx as usize >= self.pool_cfg.cfg.len() { 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 { 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 size_list = self.sizes_lists.get(pool_idx).unwrap();
let curr_size = size_list[addr.packet_idx as usize]; let curr_size = size_list[addr.packet_idx as usize];
@ -287,7 +292,10 @@ impl LocalPool {
} }
} }
} else { } else {
return Err(StoreError::InvalidStoreId(StoreIdError::InvalidSubpool(subpool),None)); return Err(StoreError::InvalidStoreId(
StoreIdError::InvalidSubpool(subpool),
None,
));
} }
Err(StoreError::StoreFull(subpool)) Err(StoreError::StoreFull(subpool))
} }
@ -327,12 +335,15 @@ mod tests {
let pool_cfg = PoolCfg::new(vec![(4, 4), (2, 8), (1, 16)]); let pool_cfg = PoolCfg::new(vec![(4, 4), (2, 8), (1, 16)]);
let mut local_pool = LocalPool::new(pool_cfg); let mut local_pool = LocalPool::new(pool_cfg);
// Try to access data which does not exist // Try to access data which does not exist
let res = local_pool.read(&StoreAddr{ let res = local_pool.read(&StoreAddr {
packet_idx: 0, packet_idx: 0,
pool_idx: 0 pool_idx: 0,
}); });
assert!(res.is_err()); 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]; let mut test_buf: [u8; 16] = [0; 16];
for (i, val) in test_buf.iter_mut().enumerate() { for (i, val) in test_buf.iter_mut().enumerate() {
*val = i as u8; *val = i as u8;
@ -341,16 +352,19 @@ mod tests {
assert!(res.is_ok()); assert!(res.is_ok());
let addr = res.unwrap(); let addr = res.unwrap();
// Only the second subpool has enough storage and only one bucket // Only the second subpool has enough storage and only one bucket
assert_eq!(addr, StoreAddr { assert_eq!(
pool_idx: 2, addr,
packet_idx: 0 StoreAddr {
}); pool_idx: 2,
packet_idx: 0
}
);
// The subpool is now full and the call should fail accordingly // The subpool is now full and the call should fail accordingly
let res = local_pool.add(test_buf); let res = local_pool.add(test_buf);
assert!(res.is_err()); assert!(res.is_err());
let err = res.unwrap_err(); let err = res.unwrap_err();
assert!(matches!(err, StoreError::StoreFull {..})); assert!(matches!(err, StoreError::StoreFull { .. }));
if let StoreError::StoreFull(subpool) = err { if let StoreError::StoreFull(subpool) = err {
assert_eq!(subpool, 2); assert_eq!(subpool, 2);
} }
@ -361,7 +375,7 @@ mod tests {
let buf_read_back = res.unwrap(); let buf_read_back = res.unwrap();
assert_eq!(buf_read_back.len(), 16); assert_eq!(buf_read_back.len(), 16);
for (i, &val) in buf_read_back.iter().enumerate() { for (i, &val) in buf_read_back.iter().enumerate() {
assert_eq!(val , i as u8); assert_eq!(val, i as u8);
} }
// Delete the data // Delete the data
@ -373,7 +387,13 @@ mod tests {
let res = local_pool.free_element(12); let res = local_pool.free_element(12);
assert!(res.is_ok()); assert!(res.is_ok());
let (addr, buf_ref) = res.unwrap(); 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.len(), 12);
assert_eq!(buf_ref, [0; 12]); assert_eq!(buf_ref, [0; 12]);
buf_ref[0] = 5; 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); let res = local_pool.read(&addr);
assert!(res.is_err()); assert!(res.is_err());
let err = res.unwrap_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); assert_eq!(addr.raw(), 0x00020001);
let res = local_pool.read(&addr); let res = local_pool.read(&addr);
assert!(res.is_err()); assert!(res.is_err());
let err = res.unwrap_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 data_too_large = [0; 20];
let res = local_pool.add(data_too_large); let res = local_pool.add(data_too_large);
@ -420,7 +452,10 @@ mod tests {
let res = local_pool.free_element(LocalPool::MAX_SIZE + 1); let res = local_pool.free_element(LocalPool::MAX_SIZE + 1);
assert!(res.is_err()); 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() {
}