Golem  v0.1.1
Generic Operating system Libraries for Embedded Multitasking
 All Data Structures Files Functions Variables Pages
/home/ruud/Engineering/software/projects/golem-project-code/trunk/glm_tick.c
1 
11 /* INCLUDES **********************************************************/
12 #include <stdlib.h>
13 #include "glm_tick.h"
14 
15 
16 /* PRIVATE VARIABLES *************************************************/
17 static uint_base_t m_tick = 0;
18 
19 
20 /* PRIVATE FUNCTION DECLARATIONS *************************************/
21 uint_base_t tick_subvalue();
22 
23 
24 /* PUBLIC FUNCTIONS **************************************************/
25 
26 void
27 tick_inc()
28 {
29  // Increment internal tick count
30  m_tick++;
31 }
32 
33 
34 void
35 tick_current(tickstamp_t *ts)
36 {
37  ts->tick = m_tick;
38  ts->subtick = tick_subvalue();
39 }
40 
41 
42 void
43 tick_diff(tickstamp_t *begin, tickstamp_t *end, tickstamp_t *result)
44 {
45  result->tick = abs(end->tick - begin->tick);
46  result->subtick = abs(end->subtick - begin->subtick);
47 }
48 
49 
50 float
51 tick_time(const tickstamp_t *ts)
52 {
53  float time = 0.0;
54 
55  time = (float) ts->tick / CORE_TICK_FREQ_HZ;
56 
57  // Take into account sub-tick only if one is available.
58  #ifdef CORE_SUBTICK_FUNC
59  time += (float) ts->subtick / CORE_TMR_FREQ_HZ;
60  #endif
61 
62  return time;
63 }
64 
65 
66 /* PRIVATE FUNCTIONS *************************************************/
67 
68 uint_base_t
69 tick_subvalue()
70 {
71  #ifdef CORE_SUBTICK_FUNC
72  return (uint_base_t) CORE_SUBTICK_FUNC();
73  #else
74  return 0;
75  #endif
76 }