Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions software/glasgow/applet/interface/freq_counter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def elaborate(self, platform):
rst=trigger,
clk=self.pads.i_t.i,
clk_en=self.running,
width=64,
width=32,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gateware doesn't care about the register width at all, a 1-bit one is as atomic as a 128-bit. The reads are always atomic. The writes are never atomic, they are shifted in in 8-bit chunks. (This is probably a bug.)

)
m.d.comb += self.edge_count.eq(m.submodules.ripple.count)

Expand All @@ -63,7 +63,7 @@ async def configure(self, duration=2.0):
ctr = int(self.applet.sys_clk_freq * duration)

# this is broken (see comment below)
#await self.device.write_register(self.applet.__reg_clk_count, ctr, width=8)
#await self.device.write_register(self.applet.__reg_clk_count, ctr, width=4)

await self.applet.set_clk_count(ctr)

Expand Down Expand Up @@ -115,8 +115,8 @@ def add_build_arguments(cls, parser, access):
def build(self, target, args):
self.mux_interface = iface = target.multiplexer.claim_interface(self, args)

reg_clk_count, self.__reg_clk_count = target.registers.add_rw(64)
reg_edge_count, self.__reg_edge_count = target.registers.add_ro(64)
reg_clk_count, self.__reg_clk_count = target.registers.add_rw(32)
reg_edge_count, self.__reg_edge_count = target.registers.add_ro(32)
reg_running, self.__reg_running = target.registers.add_ro(1)

subtarget = iface.add_subtarget(FrequencyCounterSubtarget(
Expand Down Expand Up @@ -174,16 +174,19 @@ async def interact(self, device, args, freq_ctr):
# File "/home/attie/proj_local/glasgow/glasgow/software/glasgow/applet/interface/freq_counter/__init__.py", line 85, in measure
# await self.configure(duration)
# File "/home/attie/proj_local/glasgow/glasgow/software/glasgow/applet/interface/freq_counter/__init__.py", line 60, in configure
# await self.device.write_register(self.applet.__reg_clk_count, ctr, width=8)
# await self.device.write_register(self.applet.__reg_clk_count, ctr, width=4)
# AttributeError: 'FrequencyCounterApplet' object has no attribute '_FrequencyCounterInterface__reg_clk_count'

async def get_clk_count(self):
return await self.device.read_register(self.__reg_clk_count, width=8)
return await self.device.read_register(self.__reg_clk_count, width=4)
async def set_clk_count(self, value):
await self.device.write_register(self.__reg_clk_count, value, width=8)
await self.device.write_register(self.__reg_clk_count, value, width=4)

async def get_ctr(self):
return await self.device.read_register(self.__reg_ctr, width=4)

async def get_edge_count(self):
return await self.device.read_register(self.__reg_edge_count, width=8)
return await self.device.read_register(self.__reg_edge_count, width=4)

async def get_running(self):
return bool(await self.device.read_register(self.__reg_running, width=1))