Commit 14b8e467 authored by Christian Eichler's avatar Christian Eichler
Browse files

Make sure timer_{start,stop} are inlined

Otherwise returns from/calls to these functions will
influence the reported cycles
parent 724c610e
......@@ -107,11 +107,13 @@ static void command_bch(char *arg) {
// flush instruction cache prior to executing the benchmark to
// ensure a "clean" system state
XMC_PREFETCH_InvalidateInstructionBuffer();
timer_reset();
timer_start();
gene_main(val);
uint64_t cycles = timer_stop();
timer_stop();
uint64_t cycles = timer_get();
__set_BASEPRI(old_basepri);
P1_0_toggle();
......
#include "timer.h"
#include <XMC4500.h>
#define CYCCNT_LIMIT (UINT32_MAX)
#define CYCCNT_INT_COST 40
......@@ -37,17 +35,13 @@ void timer_init() {
DWT->CTRL &= ~DWT_CTRL_PCSAMPLENA_Msk;
}
inline void timer_start() {
void timer_reset() {
DWT->CTRL &= ~DWT_CTRL_CYCCNTENA_Msk; // disable CYCCNT
overflow_counter = 0;
DWT->CYCCNT = 0; // reset the counter
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; // enable CYCCNT
}
inline uint64_t timer_stop() {
DWT->CTRL &= ~DWT_CTRL_CYCCNTENA_Msk; // disable CYCCNT
uint64_t timer_get() {
uint64_t cycles = DWT->CYCCNT;
cycles += overflow_counter * ((uint64_t)CYCCNT_LIMIT + 1);
cycles -= overflow_counter * CYCCNT_INT_COST;
......
......@@ -4,9 +4,16 @@
#include <stdbool.h>
#include <stdint.h>
void timer_init();
bool timer_enable_overflow_detection();
bool timer_has_overflow_detection();
void timer_start();
uint64_t timer_stop();
#include <XMC4500.h>
void timer_init();
bool timer_enable_overflow_detection();
bool timer_has_overflow_detection();
#define timer_start() { DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; }
#define timer_stop() { DWT->CTRL &= ~DWT_CTRL_CYCCNTENA_Msk; }
void timer_reset();
uint64_t timer_get();
#endif /* __TIMER_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment