Skip to content

Update Timer HAL to use new autogen interface#385

Open
ziuziakowska wants to merge 1 commit intolowRISC:mainfrom
ziuziakowska:hal-autogen-rework-timer
Open

Update Timer HAL to use new autogen interface#385
ziuziakowska wants to merge 1 commit intolowRISC:mainfrom
ziuziakowska:hal-autogen-rework-timer

Conversation

@ziuziakowska
Copy link
Copy Markdown
Contributor

Split off from #299.

@ziuziakowska ziuziakowska force-pushed the hal-autogen-rework-timer branch 2 times, most recently from 5d8fcc3 to 7706761 Compare March 26, 2026 16:49
@ziuziakowska ziuziakowska force-pushed the hal-autogen-rework-timer branch 2 times, most recently from a01fd9a to 501d512 Compare March 30, 2026 09:12
}

uint64_t timer_get_value(timer_t timer)
void timer_enable(timer_t timer)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit. I would prefer timer_set_enabled(timer_t timer, bool enable)

}

void timer_enable_interrupt(timer_t timer)
uint64_t timer_value_read_us(timer_t timer)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
uint64_t timer_value_read_us(timer_t timer)
uint64_t timer_value_read(timer_t timer)

This function can't garantee the value unit. If a test change the cfg0 reg, this function name would be inconsistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is true, but in practice I think we should have convenience functionality like this in the library instead of relying on everyone to calculate times themselves which could be much more error prone. All usages of the timer so far have used one us per tick so this was meant to simplify that for future tests.

I could add documentation to those functions in particular to notify users that if they are initialising the timer outside of timer_init then these functions shouldn't be used.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In Opentitan this higher level functions live in a library called testutils, I'm not against having these utilities in the hal, but there should also have functions to read the raw timer value, because tests would want to use it.


typedef void *timer_t;
/* interrupts */
bool timer_interrupt_enable_read(timer_t timer);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No need to change in this PR, just a heads up, in OT these functions are auto generated, because all IPs follow the same spec.

Signed-off-by: Alice Ziuziakowska <a.ziuziakowska@lowrisc.org>
@ziuziakowska ziuziakowska force-pushed the hal-autogen-rework-timer branch from 501d512 to 2edd6f4 Compare March 30, 2026 18:52
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.

3 participants