2012-05-21 16:56:21 -04:00
|
|
|
#include <hw/timer.h>
|
2013-03-10 14:32:38 -04:00
|
|
|
#include <hw/identifier.h>
|
2012-05-21 16:56:21 -04:00
|
|
|
|
|
|
|
#include "timer.h"
|
|
|
|
|
|
|
|
unsigned int get_system_frequency(void)
|
|
|
|
{
|
2013-03-10 14:32:38 -04:00
|
|
|
return (CSR_IDENTIFIER_FREQ3 << 24)
|
|
|
|
|(CSR_IDENTIFIER_FREQ2 << 16)
|
|
|
|
|(CSR_IDENTIFIER_FREQ1 << 8)
|
|
|
|
|CSR_IDENTIFIER_FREQ0;
|
2012-05-21 16:56:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void timer_enable(int en)
|
|
|
|
{
|
|
|
|
CSR_TIMER0_EN = en;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int timer_get(void)
|
|
|
|
{
|
|
|
|
return (CSR_TIMER0_COUNT3 << 24)
|
|
|
|
|(CSR_TIMER0_COUNT2 << 16)
|
|
|
|
|(CSR_TIMER0_COUNT1 << 8)
|
|
|
|
|CSR_TIMER0_COUNT0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void timer_set_counter(unsigned int value)
|
|
|
|
{
|
|
|
|
CSR_TIMER0_COUNT3 = (value & 0xff000000) >> 24;
|
|
|
|
CSR_TIMER0_COUNT2 = (value & 0x00ff0000) >> 16;
|
|
|
|
CSR_TIMER0_COUNT1 = (value & 0x0000ff00) >> 8;
|
|
|
|
CSR_TIMER0_COUNT0 = value & 0x000000ff;
|
|
|
|
}
|
|
|
|
|
|
|
|
void timer_set_reload(unsigned int value)
|
|
|
|
{
|
|
|
|
CSR_TIMER0_RELOAD3 = (value & 0xff000000) >> 24;
|
|
|
|
CSR_TIMER0_RELOAD2 = (value & 0x00ff0000) >> 16;
|
|
|
|
CSR_TIMER0_RELOAD1 = (value & 0x0000ff00) >> 8;
|
|
|
|
CSR_TIMER0_RELOAD0 = value & 0x000000ff;
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|