-
Notifications
You must be signed in to change notification settings - Fork 1
General purpose timer #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
chipflow_digital_ip/base/gptimer.py
Outdated
|
||
class GPTimer(Component): | ||
class Ctrl(csr.Register, access="rw"): | ||
"""CTRL: [0]=EN, [1]=RST, [2]=AR, [3]=IRQ_EN""" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
chipflow_digital_ip/base/gptimer.py
Outdated
|
||
# immediately clear our local pulse next cycle so it's one-hot | ||
with m.If(mflag): | ||
m.d.sync += mflag.eq(0) |
There was a problem hiding this comment.
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.
tests/test_gptimer.py
Outdated
|
||
# 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) |
There was a problem hiding this comment.
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
chipflow_digital_ip/base/gptimer.py
Outdated
self.bus.memory_map = self._bridge.bus.memory_map | ||
|
||
# Internal timer signals: | ||
self._prescaler_cnt = Signal(8) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
chipflow_digital_ip/base/gptimer.py
Outdated
# 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): |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
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"