Skip to content

Commit

Permalink
mem bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
perlindgren committed Aug 7, 2023
1 parent d02fbef commit acf7a04
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 34 deletions.
6 changes: 5 additions & 1 deletion riscv/examples/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,11 @@ fn fern_setup_riscv() {
})
// Add blanket level filter -
// .level(log::LevelFilter::Debug);
.level(log::LevelFilter::Warn);
.level_for(
"syncrim::gui_vizia::components::mem",
log::LevelFilter::Trace,
)
.level(log::LevelFilter::Error);

// - and per-module overrides
#[cfg(feature = "gui-vizia")]
Expand Down
74 changes: 41 additions & 33 deletions src/gui_vizia/components/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ impl ViziaComponent for Mem {
V::new(cx, self, |cx| {
trace!("---- Create Mem View ");
Label::new(cx, "DataMemory")
.hoverable(false)
.left(Pixels(10.0))
.top(Pixels(10.0))
.hoverable(false)
Expand All @@ -30,14 +29,17 @@ impl ViziaComponent for Mem {
//We initialize data_slice with the initial state of the memory.
//from now on, data_slice only gets updated over
//the relevant (visible) data interval, and when needed (so only on clock)
//so as to not trigger unneccessary redraws.
//so as to not trigger unnecessary redraws.
let data_slice = {
let mut data_slice = vec![];
let mem = self.memory.clone();
for idx in self.range.start as usize..self.range.end as usize {
trace!("range {:x?}", self.range);
for idx in (self.range.start as usize..self.range.end as usize).step_by(4) {
trace!("idx {:x?}", idx);

data_slice.push(format!(
"0x{:08x}: {:02x}{:02x}{:02x}{:02x}",
idx,
idx * 4,
mem.0.borrow().get(&idx).copied().unwrap_or_else(|| 0u8),
mem.0
.borrow()
Expand Down Expand Up @@ -73,7 +75,7 @@ impl ViziaComponent for Mem {
VirtualList::new(cx, DataMemView::data_slice, 20.0, |cx, idx, item| {
HStack::new(cx, |cx| {
//if a value comes into view, update it with fresh data from memory
cx.emit(DataEvent::UpdateVal(idx));
// cx.emit(DataEvent::UpdateVal(idx));
Label::new(cx, item);
})
.child_left(Pixels(10.0))
Expand Down Expand Up @@ -109,34 +111,40 @@ impl View for DataMemView {
fn event(&mut self, _cx: &mut EventContext, event: &mut Event) {
event.map(|event, _| match event {
DataEvent::UpdateVal(idx) => {
self.data_slice[*idx] = format!(
"0x{:08x}: {:02x}{:02x}{:02x}{:02x}",
idx,
self.data
.0
.borrow()
.get(&(self.start + idx * 4))
.copied()
.unwrap_or_else(|| 0u8),
self.data
.0
.borrow()
.get(&(self.start + idx * 4 + 1))
.copied()
.unwrap_or_else(|| 0u8),
self.data
.0
.borrow()
.get(&(self.start + idx * 4 + 2))
.copied()
.unwrap_or_else(|| 0u8),
self.data
.0
.borrow()
.get(&(self.start + idx * 4 + 3))
.copied()
.unwrap_or_else(|| 0u8)
);
trace!("idx {:x}", idx);
if let Some(data_fmt) = self.data_slice.get_mut(*idx) {
*data_fmt = format!(
"0x{:08x}: {:02x}{:02x}{:02x}{:02x}",
idx * 4 + self.start,
self.data
.0
.borrow()
.get(&(self.start + idx * 4))
.copied()
.unwrap_or_else(|| 0u8),
self.data
.0
.borrow()
.get(&(self.start + idx * 4 + 1))
.copied()
.unwrap_or_else(|| 0u8),
self.data
.0
.borrow()
.get(&(self.start + idx * 4 + 2))
.copied()
.unwrap_or_else(|| 0u8),
self.data
.0
.borrow()
.get(&(self.start + idx * 4 + 3))
.copied()
.unwrap_or_else(|| 0u8)
);
} else {
// Why do we end up here, seems wrong
// panic!("Internal error, lookup should always succeed.")
}
}
})
}
Expand Down

0 comments on commit acf7a04

Please sign in to comment.