2016-07-25 09:04:22 +02:00
|
|
|
#include <internals/timer.h>
|
2016-07-06 11:28:51 +02:00
|
|
|
#include <timer.h>
|
|
|
|
|
|
|
|
/*
|
2016-12-22 19:47:05 +01:00
|
|
|
timer_start2()
|
|
|
|
Configures and starts a time using a clock count and a prescaler.
|
2016-07-06 11:28:51 +02:00
|
|
|
*/
|
2017-02-25 23:19:35 +01:00
|
|
|
void timer_start2(int timer, int delay, int prescaler, void *callback,
|
|
|
|
void *data, int repeats)
|
2016-07-06 11:28:51 +02:00
|
|
|
{
|
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.
|
2017-02-25 23:19:35 +01:00
|
|
|
timers[timer].callback = callback;
|
|
|
|
timers[timer].data = data;
|
|
|
|
timers[timer].repeats = repeats;
|
2016-07-06 11:28:51 +02:00
|
|
|
|
2016-08-02 07:51:44 +02:00
|
|
|
// Starting the timer.
|
2016-07-06 11:28:51 +02:00
|
|
|
*tstr |= byte;
|
|
|
|
}
|
2016-12-22 19:47:05 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
timer_start()
|
|
|
|
Configures and starts a timer using a delay, or a frequency, and the
|
|
|
|
associated unit.
|
|
|
|
*/
|
2017-02-25 23:19:35 +01:00
|
|
|
void timer_start(int timer, int delay, enum ClockUnit unit, void *callback,
|
|
|
|
void *data, int repeats)
|
2016-12-22 19:47:05 +01:00
|
|
|
{
|
|
|
|
timer_start2(timer, clock_setting(delay, unit), TIMER_Po_4, callback,
|
2017-02-25 23:19:35 +01:00
|
|
|
data, repeats);
|
2016-12-22 19:47:05 +01:00
|
|
|
}
|