Skip to content

Conversation

ta10g22
Copy link

@ta10g22 ta10g22 commented Aug 7, 2025

Created GPTimer and a testbench for it. Currently it works as intended and all tests pass.
For testing you can run "pytest tests/test_gptimer.py"

Copy link
Contributor

@gatecat gatecat left a comment

Choose a reason for hiding this comment

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

Looking good, a few comments left


class GPTimer(Component):
class Ctrl(csr.Register, access="rw"):
"""CTRL: [0]=EN, [1]=RST, [2]=AR, [3]=IRQ_EN"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you make this documentation a bit more verbose as to the purpose of the bits?

Copy link
Author

Choose a reason for hiding this comment

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

ok


# immediately clear our local pulse next cycle so it's one-hot
with m.If(mflag):
m.d.sync += mflag.eq(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Amaranth follows a last-assignment-first approach, so you can just do m.d.sync += mflag.eq(0) before the If statement where you set it to 1 and this will work just the same.


# clear the match bit
await self._write_reg(ctx, bus, self.REG_STATUS, 1, 1)
status2 = await self._read_reg(ctx, bus, self.REG_STATUS, 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

it'd be fine just to reassign status here instead of calling this status2

self.bus.memory_map = self._bridge.bus.memory_map

# Internal timer signals:
self._prescaler_cnt = Signal(8)
Copy link
Contributor

Choose a reason for hiding this comment

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

These don't need to be fields on self - they can just be created as signals in elaborate

Copy link
Author

Choose a reason for hiding this comment

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

yes true only used internally

# compare & auto-reload, set match-flag
with m.If((cnt_r == cmp_.val.data) & ctrl.en.data):
m.d.sync += mflag.eq(1)
with m.If(ctrl.ar.data):
Copy link
Contributor

Choose a reason for hiding this comment

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

is it intended if auto-reset isn't enabled, the counter will just roll around? (either way, this behaviour should be documented too)

Copy link
Author

Choose a reason for hiding this comment

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

yeah the counter just keeps incrementing past the match value. i will document this functionality clearly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants