From 2ab0dd77de5cde2ca04944cd03b894034a5c9f8e Mon Sep 17 00:00:00 2001 From: Hedara Date: Thu, 29 Aug 2024 15:36:05 +0200 Subject: [PATCH] Added performance counter --- include/global.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/global.h b/include/global.h index f5ada78360..783a913106 100644 --- a/include/global.h +++ b/include/global.h @@ -131,6 +131,31 @@ #define FEATURE_FLAG_ASSERT(flag, id) STATIC_ASSERT(flag > TEMP_FLAGS_END || flag == 0, id) +#ifndef NDEBUG +static inline void CycleCountStart() +{ + REG_TM2CNT_H = 0; + REG_TM3CNT_H = 0; + + REG_TM2CNT_L = 0; + REG_TM3CNT_L = 0; + + // init timers (tim3 count up mode, tim2 every clock cycle) + REG_TM3CNT_H = TIMER_ENABLE | TIMER_COUNTUP; + REG_TM2CNT_H = TIMER_1CLK | TIMER_ENABLE; +} + +static inline u32 CycleCountEnd() +{ + // stop timers + REG_TM2CNT_H = 0; + REG_TM3CNT_H = 0; + + // return result + return REG_TM2CNT_L | (REG_TM3CNT_L << 16u); +} +#endif + struct Coords8 { s8 x;