Sleep time for threads extended
Fix for ActiveBus check (thread did not run)
This commit is contained in:
parent
974fa25a3c
commit
e64d3edbd8
8 changed files with 46 additions and 14 deletions
37
src/bus.rs
37
src/bus.rs
|
|
@ -303,7 +303,7 @@ impl Component for ActiveBus {
|
|||
|
||||
while self.is_running() {
|
||||
self.update();
|
||||
thread::sleep(Duration::from_micros(1));
|
||||
thread::sleep(Duration::from_micros(10));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -389,13 +389,44 @@ mod tests {
|
|||
#[test]
|
||||
fn test_active_bus_pattern() {
|
||||
let mut active_bus = ActiveBus::new("ACTIVE_BUS".to_string());
|
||||
|
||||
// Start the bus in a new thread
|
||||
let bus_arc = std::sync::Arc::new(std::sync::Mutex::new(bus));
|
||||
let bus_clone = bus_arc.clone();
|
||||
|
||||
let handle = std::thread::spawn(move || {
|
||||
let mut bus = bus_clone.lock().unwrap();
|
||||
bus.start().unwrap();
|
||||
// Bus runs in this thread
|
||||
});
|
||||
|
||||
// Give the thread a moment to start
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
|
||||
// Check if bus is running
|
||||
{
|
||||
let bus = bus_arc.lock().unwrap();
|
||||
assert!(bus.is_running());
|
||||
}
|
||||
|
||||
let pattern = vec![PinValue::High, PinValue::Low, PinValue::High, PinValue::Low];
|
||||
|
||||
active_bus.set_test_pattern(pattern);
|
||||
active_bus.set_test_pattern(pattern.clone());
|
||||
active_bus.set_pattern_interval(Duration::from_millis(10));
|
||||
|
||||
// Give the thread a moment to start
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
|
||||
// Test that active bus can drive patterns
|
||||
active_bus.drive_pattern();
|
||||
assert!(active_bus.is_running());
|
||||
assert!(active_bus.test_pattern.eq(&pattern));
|
||||
|
||||
// Clean up - stop the bus and join the thread
|
||||
{
|
||||
let mut bus = bus_arc.lock().unwrap();
|
||||
bus.stop().unwrap();
|
||||
}
|
||||
|
||||
handle.join().unwrap();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::component::Component;
|
||||
use crate::components::cpu::cmos_65c02::CMOS65C02;
|
||||
use crate::components::cpu::mos_6502::{Registers, MOS6502};
|
||||
use crate::components::cpu::mos_6502::MOS6502;
|
||||
use crate::components::cpu::WDC65C02;
|
||||
|
||||
pub trait CPU: Component {
|
||||
fn reset(&mut self);
|
||||
|
|
@ -71,7 +71,7 @@ impl MOS6502Family for MOS6502 {
|
|||
// Implement other methods...
|
||||
}
|
||||
|
||||
impl CPU for CMOS65C02 {
|
||||
impl CPU for WDC65C02 {
|
||||
fn reset(&mut self) {
|
||||
todo!()
|
||||
}
|
||||
|
|
@ -97,9 +97,9 @@ impl CPU for CMOS65C02 {
|
|||
}
|
||||
}
|
||||
|
||||
impl MOS6502Family for CMOS65C02 {
|
||||
impl MOS6502Family for WDC65C02 {
|
||||
fn lda(&mut self, value: u8) {
|
||||
self.base_6502.lda(value)
|
||||
self.base.lda(value)
|
||||
}
|
||||
|
||||
fn sta(&mut self, address: u16) {
|
||||
|
|
@ -113,7 +113,7 @@ impl MOS6502Family for CMOS65C02 {
|
|||
// Implement other methods...
|
||||
}
|
||||
|
||||
impl CMOS65C02Extensions for CMOS65C02 {
|
||||
impl CMOS65C02Extensions for WDC65C02 {
|
||||
fn bra(&mut self, address: u16) {
|
||||
self.bra(address)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
pub mod mos_6502;
|
||||
pub mod wdc_65c02;
|
||||
pub mod intel_4004;
|
||||
mod cpu_traits;
|
||||
|
||||
// Re-export the CPU types
|
||||
pub use mos_6502::MOS6502;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::pin::Pin;
|
|||
|
||||
/// WDC 65C02 - CMOS version of 6502 with additional instructions
|
||||
pub struct WDC65C02 {
|
||||
base: MOS6502,
|
||||
pub(crate) base: MOS6502,
|
||||
// 65C02-specific state
|
||||
stop_mode: bool,
|
||||
wait_mode: bool,
|
||||
|
|
|
|||
|
|
@ -289,7 +289,7 @@ impl Component for GenericRam {
|
|||
|
||||
while self.is_running() {
|
||||
self.update();
|
||||
thread::sleep(Duration::from_micros(1));
|
||||
thread::sleep(Duration::from_micros(10));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ impl Component for GenericRom {
|
|||
|
||||
while self.base.is_running() {
|
||||
self.update();
|
||||
thread::sleep(Duration::from_micros(1)); // Small delay to prevent busy waiting
|
||||
thread::sleep(Duration::from_micros(10)); // Small delay to prevent busy waiting
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -313,7 +313,7 @@ impl Component for Intel4001 {
|
|||
|
||||
while self.is_running() {
|
||||
self.update();
|
||||
thread::sleep(Duration::from_micros(1));
|
||||
thread::sleep(Duration::from_micros(10));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ impl Component for Intel4002 {
|
|||
|
||||
while self.is_running() {
|
||||
self.update();
|
||||
thread::sleep(Duration::from_micros(1));
|
||||
thread::sleep(Duration::from_micros(10));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue