Add TickCounter for measuring performance

This commit is contained in:
fincs 2017-02-16 14:35:06 +01:00
parent 97d01a7325
commit 991eb2357b
2 changed files with 41 additions and 0 deletions

View File

@ -3,6 +3,7 @@
* @brief OS related stuff.
*/
#pragma once
#include "svc.h"
/// Packs a system version from its components.
#define SYSTEM_VERSION(major, minor, revision) \
@ -26,6 +27,13 @@ typedef enum
MEMREGION_BASE = 3, ///< BASE memory.
} MemRegion;
/// Tick counter.
typedef struct
{
u64 elapsed; ///< Elapsed CPU ticks between measurements.
u64 reference; ///< Point in time used as reference.
} TickCounter;
/// OS_VersionBin. Format of the system version: "<major>.<minor>.<build>-<nupver><region>"
typedef struct
{
@ -124,6 +132,33 @@ static inline s64 osGetMemRegionFree(MemRegion region)
*/
u64 osGetTime(void);
/**
* @brief Starts a tick counter.
* @param cnt The tick counter.
*/
static inline void osTickCounterStart(TickCounter* cnt)
{
cnt->reference = svcGetSystemTick();
}
/**
* @brief Updates the elapsed time in a tick counter.
* @param cnt The tick counter.
*/
static inline void osTickCounterUpdate(TickCounter* cnt)
{
u64 now = svcGetSystemTick();
cnt->elapsed = now - cnt->reference;
cnt->reference = now;
}
/**
* @brief Reads the elapsed time in a tick counter.
* @param cnt The tick counter.
* @return The number of milliseconds elapsed.
*/
double osTickCounterRead(TickCounter* cnt);
/**
* @brief Gets the current Wifi signal strength.
* @return The current Wifi signal strength.

View File

@ -115,6 +115,12 @@ u64 osGetTime(void) {
return dt.date_time + (u32)(u64_to_double(delta)/TICKS_PER_MSEC);
}
//---------------------------------------------------------------------------------
double osTickCounterRead(TickCounter* cnt) {
//---------------------------------------------------------------------------------
return u64_to_double(cnt->elapsed) / TICKS_PER_MSEC;
}
//---------------------------------------------------------------------------------
const char* osStrError(u32 error) {
//---------------------------------------------------------------------------------