2013-03-25 09:42:48 -04:00
|
|
|
#include <hw/csr.h>
|
2012-05-21 16:56:21 -04:00
|
|
|
|
|
|
|
#include "timer.h"
|
|
|
|
|
|
|
|
unsigned int get_system_frequency(void)
|
|
|
|
{
|
2013-03-25 09:42:48 -04:00
|
|
|
return identifier_frequency_read();
|
2012-05-21 16:56:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void timer_enable(int en)
|
|
|
|
{
|
2013-03-25 09:42:48 -04:00
|
|
|
timer0_en_write(en);
|
2012-05-21 16:56:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int timer_get(void)
|
|
|
|
{
|
2013-03-25 09:42:48 -04:00
|
|
|
return timer0_value_read();
|
2012-05-21 16:56:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void timer_set_counter(unsigned int value)
|
|
|
|
{
|
2013-03-25 09:42:48 -04:00
|
|
|
timer0_value_write(value);
|
2012-05-21 16:56:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void timer_set_reload(unsigned int value)
|
|
|
|
{
|
2013-03-25 09:42:48 -04:00
|
|
|
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());
|
|
|
|
}
|