2019-07-17 19:00:20 +02:00
|
|
|
#include <gint/timer.h>
|
2019-07-17 19:00:49 +02:00
|
|
|
#include <gint/clock.h>
|
2019-07-17 19:00:20 +02:00
|
|
|
#include <gint/mpu/tmu.h>
|
2019-07-17 19:00:49 +02:00
|
|
|
#include <gint/hardware.h>
|
|
|
|
|
|
|
|
#include <libprof.h>
|
|
|
|
|
|
|
|
/* Timer counter */
|
|
|
|
uint32_t volatile *prof_tcnt = NULL;
|
|
|
|
/* Timer ID */
|
2020-07-20 20:22:09 +02:00
|
|
|
static int prof_timer = -1;
|
2019-07-17 19:00:49 +02:00
|
|
|
|
2020-10-13 19:30:45 +02:00
|
|
|
/* prof_init(): Initialize the profiler's timer */
|
|
|
|
int prof_init(void)
|
2019-07-17 19:00:49 +02:00
|
|
|
{
|
2020-06-20 23:20:20 +02:00
|
|
|
/* Get a TMU with the exact constant 0xffffffff */
|
|
|
|
int timer = -1;
|
|
|
|
for(int t = 2; t >= 0 && timer == -1; t--)
|
|
|
|
{
|
2020-10-20 15:12:28 +02:00
|
|
|
timer = timer_setup(t | TIMER_Pphi_4, 0xffffffff, NULL);
|
2020-06-20 23:20:20 +02:00
|
|
|
}
|
2020-10-13 19:30:45 +02:00
|
|
|
if(timer == -1)
|
2019-07-17 19:00:49 +02:00
|
|
|
{
|
|
|
|
prof_quit();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-10-13 19:30:45 +02:00
|
|
|
/* Keep the address of the TCNT register */
|
|
|
|
prof_tcnt = isSH3()
|
|
|
|
? &SH7705_TMU.TMU[timer].TCNT
|
|
|
|
: &SH7305_TMU.TMU[timer].TCNT;
|
2019-07-17 19:00:49 +02:00
|
|
|
|
|
|
|
timer_start(timer);
|
|
|
|
prof_timer = timer;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-13 19:30:45 +02:00
|
|
|
/* prof_quit(): Free the profiler's timer */
|
2019-07-17 19:00:49 +02:00
|
|
|
void prof_quit(void)
|
|
|
|
{
|
2020-07-20 20:22:09 +02:00
|
|
|
if(prof_timer >= 0) timer_stop(prof_timer);
|
|
|
|
prof_timer = -1;
|
2019-07-17 19:00:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* prof_time(): Time spent in a given context, in microseconds */
|
2020-10-13 19:30:45 +02:00
|
|
|
uint32_t prof_time(prof_t prof)
|
2019-07-17 19:00:49 +02:00
|
|
|
{
|
|
|
|
int Pphi = clock_freq()->Pphi_f;
|
2020-10-13 19:30:45 +02:00
|
|
|
return ((uint64_t)prof.elapsed * 4 * 1000000) / Pphi;
|
2019-07-17 19:00:49 +02:00
|
|
|
}
|