summaryrefslogtreecommitdiffstats
path: root/app/abs.c
blob: a91787c79c613e9a0310164c3234e30b269aecf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "project.h"


static uint32_t high_tick;

#define QUARTER (1UL << 29)
#define HALF (1UL << 30)
#define THREE_QUARTERS (HALF+QUARTER)
#define ONE (~(uint32_t)0)

uint64_t abs_extend (uint32_t now)
{
  static int m;
  uint64_t ret;


  if (!m) {
  	ret = high_tick;
  	ret <<= 32;
  	ret |= now;


	if ((now>THREE_QUARTERS) &&( now<=ONE)) {
		high_tick++;
		m=1;
	}


  } else {

    if (now<HALF) {
  	ret = high_tick;
  	ret <<= 32;
  	ret |= now;
    } else {
  	ret = high_tick-1;
  	ret <<= 32;
  	ret |= now;
	}

	if ((now>QUARTER) &&( now<HALF)) 
		m=0;
}

	return ret;
}


void abs_meh(void)
{
printf("HT %d\n",(int) high_tick);
}





uint64_t abs_get (void)
{
  uint32_t now = SCS_DWT_CYCCNT;
  return abs_extend (now);
}


void abs_slow_tick()
{
  abs_get();
}