Skip to content

Commit

Permalink
Merge pull request #88 from Glamhoth/ros-190/requirements
Browse files Browse the repository at this point in the history
ROS#190 - Requirements coverage
  • Loading branch information
Glamhoth committed Dec 12, 2023
2 parents 3d7c986 + 4ac74b6 commit 4c82a5e
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 15 deletions.
11 changes: 11 additions & 0 deletions demos/samv71-spi-accelerometer/mission_scenario.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1. Configure data output rate
2. Configure accelerometer scale to +/- 2
3. Configure gyroscope scale to +/- 500
4. Start continuous measurements
5. Observe measurements on the plot
7. Reconfigure accelerometer scale to +/- 16
8. Reconfigure gyroscope scale to +/- 2000
9. Observe measurements on the plot
10. Stop continuous measurements
11. Send request for execution statistics
12. Observe execution statistics
4 changes: 4 additions & 0 deletions src/aerugo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,10 @@ impl RuntimeApi for Aerugo {
self.time_source.system_time()
}

fn get_elapsed_time(&'static self) -> Duration {
self.time_source.elapsed_time()
}

fn set_system_time_offset(&'static self, offset: Duration) -> Result<(), RuntimeError> {
// SAFETY: This is safe, because it's called from non-IRQ context, and
// system time cannot be accessed from IRQ context
Expand Down
3 changes: 3 additions & 0 deletions src/api/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ pub trait RuntimeApi {
/// Gets current system time timestamp.
fn get_system_time(&'static self) -> Instant;

/// Gets time elapsed since execution started.
fn get_elapsed_time(&'static self) -> Duration;

/// Sets system time offset.
///
/// # Parameters
Expand Down
4 changes: 4 additions & 0 deletions src/tests/mock_runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ impl RuntimeApi for MockRuntimeApi {
todo!()
}

fn get_elapsed_time(&'static self) -> Duration {
todo!()
}

fn set_system_time_offset(&'static self, _offset: Duration) -> Result<(), RuntimeError> {
todo!()
}
Expand Down
48 changes: 39 additions & 9 deletions src/time_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::time::{Duration, Instant};
pub(crate) struct TimeSource {
/// Time when system scheduler started.
system_start: OnceCell<Instant>,
/// Time since system's scheduler start.
/// Time it took to start the system scheduler.
system_start_offset: OnceCell<Duration>,
/// User-defined offset.
user_offset: OnceCell<Duration>,
Expand Down Expand Up @@ -58,9 +58,9 @@ impl TimeSource {
/// Return system time with offset if it was defined.
///
/// # Safety
/// This is safe as long as it's used in single-core context, and `TimeSource` does not pass interrupt boundary.
/// Calling [`TimeSource::set_user_offset`] in parallel with this function (interrupt is treated as different
/// thread) is an undefined behavior.
/// This is safe as long as it's used in single-core context, and `TimeSource` does not pass
/// interrupt boundary. Calling [`TimeSource::set_user_offset`] in parallel with this function
/// (interrupt is treated as different thread) is an undefined behavior.
pub(crate) fn system_time(&self) -> Instant {
let start_time = self
.time_since_start()
Expand All @@ -72,16 +72,27 @@ impl TimeSource {
}
}

/// Saves current timestamp as the moment of system start. Should be called by `Aerugo` right before starting
/// the scheduler.
/// Return time elapsed since scheduler start.
///
/// # Safety
/// This is safe as long as it's used in single-core context, and `TimeSource` does not pass
/// interrupt boundary. Calling [`TimeSource::set_system_start`] in parallel with this function
/// (interrupt is treated as different thread) is an undefined behavior.
pub(crate) fn elapsed_time(&self) -> Duration {
Hal::get_system_time() - *self.system_start.get().expect("System not started")
}

/// Saves current timestamp as the moment of system start. Should be called by `Aerugo` right
/// before starting the scheduler.
///
/// # Return
/// `()` is was set for the first time, `RuntimeError` otherwise.
///
/// # Safety
/// This is safe as long as it's used in single-core context, and `TimeSource` does not pass interrupt boundary.
/// Calling [`TimeSource::startup_duration`], [`TimeSource::calculate_absolute_time`] in parallel with this
/// function (interrupt is treated as different thread) is an undefined behavior.
/// This is safe as long as it's used in single-core context, and `TimeSource` does not pass
/// interrupt boundary. Calling [`TimeSource::startup_duration`],
/// [`TimeSource::calculate_absolute_time`], [`TimeSource::elapsed_time`] in parallel with
/// this function (interrupt is treated as different thread) is an undefined behavior.
pub(crate) unsafe fn set_system_start(&self) {
let current_time = Hal::get_system_time();

Expand Down Expand Up @@ -180,3 +191,22 @@ impl TimeSource {
})
}
}

#[cfg(any(doc, test))]
mod tests {
use super::*;

/// @SRS{ROS-FUN-RTOS-6010}
#[cfg_attr(not(doc), test)]
#[allow(non_upper_case_globals)]
fn req_query_elapsed_time() {
let time_source = TimeSource::new();

unsafe {
time_source.set_system_start();
}

let elapsed_time = time_source.elapsed_time();
assert!(elapsed_time.ticks() > 0);
}
}
52 changes: 50 additions & 2 deletions tests/requirements/design.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ fn des_tasklet_persistent_context_data() {}

/// @SRS{ROS-FUN-RTOS-030}
///
/// Design Analysis is described in N7S-ROS-SVSR-001, chapter 6.2.
/// Analysis is described in N7S-ROS-SVSR-001, chapter 6.2.
#[cfg_attr(not(doc), test)]
fn des_tasklet_user_data_safe_access() {}

/// @SRS{ROS-FUN-RTOS-040}
///
/// Design Analysis is described in N7S-ROS-SVSR-001, chapter 6.2.
/// Analysis is described in N7S-ROS-SVSR-001, chapter 6.2.
#[cfg_attr(not(doc), test)]
fn des_safe_access_to_shared_data() {}

Expand All @@ -40,6 +40,18 @@ fn des_ros_provide_driver_nvic() {}
#[cfg_attr(not(doc), test)]
fn des_ros_provide_driver_scb() {}

/// @SRS{ROS-FUN-BSP-SCB-060}
///
/// Design Analysis is described in N7S-ROS-SVSR-001, chapter 6.2.
#[cfg_attr(not(doc), test)]
fn des_ros_provide_scb_dcache_invalidation() {}

/// @SRS{ROS-FUN-BSP-SCB-070}
///
/// Design Analysis is described in N7S-ROS-SVSR-001, chapter 6.2.
#[cfg_attr(not(doc), test)]
fn des_ros_provide_scb_dcache_clean() {}

/// @SRS{ROS-FUN-BSP-SYST-010}
///
/// Design Analysis is described in N7S-ROS-SVSR-001, chapter 6.2.
Expand Down Expand Up @@ -88,12 +100,48 @@ fn des_ros_provide_driver_xdmac() {}
#[cfg_attr(not(doc), test)]
fn des_ros_provide_driver_fpu() {}

/// @SRS{ROS-IF-010}
///
/// Design Analysis is described in N7S-ROS-SVSR-001, chapter 6.2.
#[cfg_attr(not(doc), test)]
fn des_ros_demo_exposes_cnc_interface() {}

/// @SRS{ROS-IF-020}
///
/// Design Analysis is described in N7S-ROS-SVSR-001, chapter 6.2.
#[cfg_attr(not(doc), test)]
fn des_ros_demo_uses_ccsds_encapsulation() {}

/// @SRS{ROS-IF-040}
///
/// Design Analysis is described in N7S-ROS-SVSR-001, chapter 6.2.
#[cfg_attr(not(doc), test)]
fn des_ros_uart_driver_implements_embedded_hal() {}

/// @SRS{ROS-IF-050}
///
/// Design Analysis is described in N7S-ROS-SVSR-001, chapter 6.2.
#[cfg_attr(not(doc), test)]
fn des_ros_pio_driver_implements_embedded_hal() {}

/// @SRS{ROS-IF-060}
///
/// Design Analysis is described in N7S-ROS-SVSR-001, chapter 6.2.
#[cfg_attr(not(doc), test)]
fn des_ros_spi_driver_implements_embedded_hal() {}

/// @SRS{ROS-RES-010}
///
/// Design Analysis is described in N7S-ROS-SVSR-001, chapter 6.2.
#[cfg_attr(not(doc), test)]
fn des_bsp_target_samv71() {}

/// @SRS{ROS-RES-020}
///
/// Design Analysis is described in N7S-ROS-SVSR-001, chapter 6.2.
#[cfg_attr(not(doc), test)]
fn des_demo_target_samv71() {}

/// @SRS{ROS-DES-010}
///
/// Design Analysis is described in N7S-ROS-SVSR-001, chapter 6.2.
Expand Down
24 changes: 24 additions & 0 deletions tests/requirements/inspection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@
#[cfg_attr(not(doc), test)]
fn insp_english_documentation() {}

/// @SRS{ROS-OPER-010}
///
/// Inspection is described in N7S-ROS-SVSR-001, chapter 7.2.
#[cfg_attr(not(doc), test)]
fn insp_mission_scenario_established() {}

/// @SRS{ROS-OPER-020}
///
/// Inspection is described in N7S-ROS-SVSR-001, chapter 7.2.
#[cfg_attr(not(doc), test)]
fn insp_mission_scenario_exercises_uart() {}

/// @SRS{ROS-OPER-030}
///
/// Inspection is described in N7S-ROS-SVSR-001, chapter 7.2.
#[cfg_attr(not(doc), test)]
fn insp_mission_scenario_exercises_spi() {}

/// @SRS{ROS-OPER-040}
///
/// Inspection is described in N7S-ROS-SVSR-001, chapter 7.2.
#[cfg_attr(not(doc), test)]
fn insp_mission_scenario_exercises_execution_stats() {}

/// @SRS{ROS-DES-030}
///
/// Inspection is described in N7S-ROS-SVSR-001, chapter 7.2.
Expand Down
4 changes: 2 additions & 2 deletions tests/requirements/test/test_cyclic_execution.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// @SRS{ROS-FUN-RTOS-5010}
/// @SRS{ROS-FUN-RTOS-5020}
/// @SRS{ROS-FUN-RTOS-4010}
/// @SRS{ROS-FUN-RTOS-4020}
#[cfg_attr(not(doc), test)]
#[cfg(feature = "test-aerugo-cortex-m")]
fn req_test_cyclic_execution() {
Expand Down
2 changes: 0 additions & 2 deletions tests/requirements/test/test_hal_scb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
/// @SRS{ROS-FUN-BSP-SCB-030}
/// @SRS{ROS-FUN-BSP-SCB-040}
/// @SRS{ROS-FUN-BSP-SCB-050}
/// @SRS{ROS-FUN-BSP-SCB-060}
/// @SRS{ROS-FUN-BSP-SCB-070}
/// @SRS{ROS-FUN-BSP-SCB-080}
/// @SRS{ROS-FUN-BSP-SCB-090}
#[cfg_attr(not(doc), test)]
Expand Down
2 changes: 2 additions & 0 deletions tests/requirements/test/test_hal_xdmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// 40, 50, 70, 80, 110)
// * Check if per2mem transfer can be suspended and disabled using UART in loopback mode (90, 100)

/// @SRS{ROS-FUN-BSP-UART-100}
/// @SRS{ROS-FUN-BSP-UART-110}
/// @SRS{ROS-FUN-BSP-XDMAC-020}
/// @SRS{ROS-FUN-BSP-XDMAC-030}
/// @SRS{ROS-FUN-BSP-XDMAC-040}
Expand Down

0 comments on commit 4c82a5e

Please sign in to comment.