litex/software/libbase/timer.c

38 lines
556 B
C
Raw Normal View History

#include <hw/csr.h>
2012-05-21 16:56:21 -04:00
#include "timer.h"
unsigned int get_system_frequency(void)
{
return identifier_frequency_read();
2012-05-21 16:56:21 -04:00
}
void timer_enable(int en)
{
timer0_en_write(en);
2012-05-21 16:56:21 -04:00
}
unsigned int timer_get(void)
{
return timer0_value_read();
2012-05-21 16:56:21 -04:00
}
void timer_set_counter(unsigned int value)
{
timer0_value_write(value);
2012-05-21 16:56:21 -04:00
}
void timer_set_reload(unsigned int value)
{
timer0_reload_write(value);
2012-05-21 16:56:21 -04:00
}
void busy_wait(unsigned int ds)
{
timer_enable(0);
timer_set_reload(0);
timer_set_counter(get_system_frequency()/10*ds);
timer_enable(1);
while(timer_get());
}