2016-07-25 09:04:22 +02:00
|
|
|
#include <internals/timer.h>
|
2016-07-06 11:28:51 +02:00
|
|
|
#include <timer.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
timer_start()
|
|
|
|
Configures and starts a timer.
|
|
|
|
*/
|
|
|
|
void timer_start(int timer, int delay, int prescaler, void (*callback)(void),
|
|
|
|
int repeats)
|
|
|
|
{
|
2016-08-02 07:51:44 +02:00
|
|
|
volatile struct mod_tmu *tmu;
|
|
|
|
volatile unsigned char *tstr;
|
2016-07-06 11:28:51 +02:00
|
|
|
int byte = (1 << timer);
|
2016-08-02 07:51:44 +02:00
|
|
|
|
2016-07-06 11:28:51 +02:00
|
|
|
timer_get(timer, &tmu, &tstr);
|
|
|
|
|
2016-08-02 07:51:44 +02:00
|
|
|
// Loading the counter, the constant and the prescaler/
|
|
|
|
tmu->TCOR = delay;
|
|
|
|
tmu->TCNT = delay;
|
|
|
|
tmu->TCR.TPSC = prescaler;
|
|
|
|
|
|
|
|
// Resetting underflow flag and enabling interruptions.
|
|
|
|
tmu->TCR.UNF = 0;
|
|
|
|
tmu->TCR.UNIE = 1;
|
2016-07-06 11:28:51 +02:00
|
|
|
|
2016-08-02 07:51:44 +02:00
|
|
|
// Counting on rising edge (ignored on SH7305).
|
|
|
|
tmu->TCR.CKEG = 0;
|
2016-07-06 11:28:51 +02:00
|
|
|
|
|
|
|
// Loading the structure information.
|
|
|
|
timers[timer].callback = callback;
|
|
|
|
timers[timer].repeats = repeats;
|
|
|
|
|
2016-08-02 07:51:44 +02:00
|
|
|
// Starting the timer.
|
2016-07-06 11:28:51 +02:00
|
|
|
*tstr |= byte;
|
|
|
|
}
|