Skip to content

Commit

Permalink
tools/litex_client: Display size on Bytes/KB/MB/GB in Memory Regions.
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-digital committed Jan 6, 2025
1 parent 3875a4c commit 5c156b4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion litex/tools/litex_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ def gen_xadc_data(get_cls, n):
# Memory.
# -------

def convert_size(size_bytes):
"""
Convert the size from bytes to a more human-readable format.
"""
if size_bytes < 1024:
return f"{size_bytes} Bytes"
elif size_bytes < 1024**2:
return f"{size_bytes / 1024:.2f} KB"
elif size_bytes < 1024**3:
return f"{size_bytes / (1024 ** 2):.2f} MB"
else:
return f"{size_bytes / (1024 ** 3):.2f} GB"

def read_memory_chunk(base, length):
"""Reads `length` bytes from `base` address (word-aligned)."""
if length <= 0:
Expand Down Expand Up @@ -412,7 +425,7 @@ def led_callback(sender):
with dpg.table_row():
dpg.add_text(f"{region_name}")
dpg.add_text(f"0x{region_obj.base:08X}")
dpg.add_text(f"{region_obj.size}")
dpg.add_text(f"{convert_size(region_obj.size)}")
dpg.add_text(f"{region_obj.type}")

# Memory Read.
Expand Down

0 comments on commit 5c156b4

Please sign in to comment.