Question about the period of timer.
minjiexm opened this issue · 3 comments
hi, Dear expert:
I am trying to use timer interrupt.
So first I need to set the timer period.
There are two functions for this purpose.
int or1k_timer_init (unsigned int hz)
void or1k_timer_set_period (uint32_t hz)
My question is why this function does not need the input of clock cycles?
if my clock freq is 100Mhz, I think the value should different to clock freq 50Hz.
Thanks.
I suggest this question is best asked on the LibreCores OpenRISC mailing list. Details here:
Marking as closed here.
Hi,
I think I can answer it here, as it directly relates to newlib and I can directly point to the code.
The period of the timer is actually Hz as you describe and it is hence platform-independent on a C level. Anyhow, as you describe correctly the actually value written to the hardware timer depends on the clock.
This happens here: https://github.com/openrisc/newlib/blob/or1k/libgloss/or1k/timer.c#L58
So, the magic value you are asking for is _or1k_board_clk_freq
.
It is set for each board in its board support files: https://github.com/openrisc/newlib/tree/or1k/libgloss/or1k/boards
The board is selected with the -mboard=<board>
switch.
You have two options now:
- Write your own board file based on
tmpl.c
, or - Use the default board file (I think its
or1ksim
in GCC) and overwrite this specific value in your own software. The_or1k_board_clk_freq
symbol is defined as weak, so GCC will pick your own definition.
I would prefer the second one, as long as there is nothing else you may get from writing your own board support file.
So, just define your frequency in your software:
uint32_t _or1k_board_clk_freq = <yourfreqinhz>
I hope this helps.
Cheers,
Stefan
hi, Wallento:
That is exactly what I want!
Thanks a lot.