csi_timer.c File Reference

Timer implementation form timeouts and time measuring. More...

#include "csi_timer.h"
+ Include dependency graph for csi_timer.c:

Functions

uint32_t CsiTimerGetExpirationTime (TCsiTimer *pTimer)
 This function returns the absolut expiration time in millisecoonds. More...
 
uint32_t CsiTimerGetMilliSec (void)
 Returns actual value of global millisecond timer. More...
 
void CsiTimerInit (TCsiTimer *pTimer, uint32_t Period)
 Function CsiTimerInit() initialiszes a timer object. More...
 
uint8_t CsiTimerIsExpired (TCsiTimer *pTimer)
 Check if a certain timer is expired or if it is still active. More...
 
void CsiTimerRestart (TCsiTimer *pTimer)
 Initializes the timer with a new timestamp value. More...
 
void CsiTimerSetTimestamp (TCsiTimer *pTimer, const uint32_t Period)
 Set timestamp value (expiration timer) of certain timer. More...
 
void CsiTimerSetTimestampAndStartTime (TCsiTimer *pTimer, const uint32_t StartTime, const uint32_t Period)
 This function calculates the expiration time from a start time value and the timer period (expiration time = start time + period) More...
 

Detailed Description

Timer implementation form timeouts and time measuring.

Author
Uwe Kindler (UK)
Date
2009/08/27 The file implements a polling timer. The polling timer is intialized with a specific millisecond value and a timeout period. After this initialisation the application can check (poll) the timer for timeout.

Function Documentation

uint32_t CsiTimerGetExpirationTime ( TCsiTimer pTimer)

This function returns the absolut expiration time in millisecoonds.

Parameters
[in]pTimerThe timer to query for expiration time
Returns
Timer expiration time in milliseconds
48 {
49  return pTimer->Timestamp;
50 }
uint32_t Timestamp
absolut expiration timestamp of this timer
Definition: csi_timer.h:37
uint32_t CsiTimerGetMilliSec ( void  )

Returns actual value of global millisecond timer.

Returns
An absolut time value in milliseconds

Referenced by CsiTimerIsExpired(), and CsiTimerSetTimestamp().

25 {
26  //
27  // CSI_HW_GET_TICK_COUNT is a macro that shouldbe defined by hardware
28  // platform in Csi_plfabstr.h. The macro returns the actual value of
29  // the global tick counter
30  //
31  return CSI_HW_GET_TICK_COUNT();
32 }
void CsiTimerInit ( TCsiTimer pTimer,
uint32_t  Period 
)

Function CsiTimerInit() initialiszes a timer object.

The function stores the dwPeriod value into the timer object pTimer.

Parameters
[in]pTimerThe timer object to initialize
[in]PeriodThe period of the timer
38 {
39  pTimer->Timestamp = 0;
40  pTimer->Period = Period;
41 }
uint32_t Timestamp
absolut expiration timestamp of this timer
Definition: csi_timer.h:37
uint32_t Period
expiration period of this timer
Definition: csi_timer.h:38
uint8_t CsiTimerIsExpired ( TCsiTimer pTimer)

Check if a certain timer is expired or if it is still active.

The function checks if the current time value is larger then the timer timestamp value. If the current time value is larger, then the timer is expired.

Parameters
[in]pTimerThe timer to query
Return values
1Timer expired
0Timer not expired - active
57 {
58  uint32_t TimeNow = CsiTimerGetMilliSec();
59  uint32_t Timestamp = (pTimer->Timestamp + 1);
60 
61  if (TimeNow > Timestamp)
62  {
63  if ((TimeNow - Timestamp) < 0x80000000)
64  {
65  return 1;
66  }
67  else
68  {
69  return 0;
70  }
71  }
72  else // if (dwTimeNow <= dwTimestamp)
73  {
74  if ((Timestamp - TimeNow) > 0x80000000)
75  {
76  return 1;
77  }
78  else
79  {
80  return 0;
81  }
82  } // if (time_now <= timestamp)
83 }
uint32_t Timestamp
absolut expiration timestamp of this timer
Definition: csi_timer.h:37
uint32_t CsiTimerGetMilliSec(void)
Returns actual value of global millisecond timer.
Definition: csi_timer.c:24

+ Here is the call graph for this function:

void CsiTimerRestart ( TCsiTimer pTimer)

Initializes the timer with a new timestamp value.

The function calculates a new timestamp value. It uses the pTimer period for this calculation. The new timestamp value is the current timer plus the timer period.

Parameters
[in]pTimerTimer to restart
90 {
91  CsiTimerSetTimestamp(pTimer, pTimer->Period);
92 }
void CsiTimerSetTimestamp(TCsiTimer *pTimer, const uint32_t Period)
Set timestamp value (expiration timer) of certain timer.
Definition: csi_timer.c:98
uint32_t Period
expiration period of this timer
Definition: csi_timer.h:38

+ Here is the call graph for this function:

void CsiTimerSetTimestamp ( TCsiTimer pTimer,
const uint32_t  Period 
)

Set timestamp value (expiration timer) of certain timer.

The expiration time is the current time + the value in dwPeriod.

Parameters
[in]pTimerTimer to change
[in]PeriodThe timer period (timestamp = current time + dwPeriod)

Referenced by CsiTimerRestart().

99 {
100  uint32_t StartTime = CsiTimerGetMilliSec();
101 
102  CsiTimerSetTimestampAndStartTime(pTimer, StartTime, Period);
103 }
void CsiTimerSetTimestampAndStartTime(TCsiTimer *pTimer, const uint32_t StartTime, const uint32_t Period)
This function calculates the expiration time from a start time value and the timer period (expiration...
Definition: csi_timer.c:109
uint32_t CsiTimerGetMilliSec(void)
Returns actual value of global millisecond timer.
Definition: csi_timer.c:24

+ Here is the call graph for this function:

void CsiTimerSetTimestampAndStartTime ( TCsiTimer pTimer,
const uint32_t  StartTime,
const uint32_t  Period 
)

This function calculates the expiration time from a start time value and the timer period (expiration time = start time + period)

Parameters
[in]pTimerTimer to change
[in]StartTimeThe start time in milliseconds
[in]PeriodThe timeout period of this timer in milliseconds

Referenced by CsiTimerSetTimestamp().

112 {
113  pTimer->Timestamp = StartTime + Period;
114  pTimer->Period = Period;
115 }
uint32_t Timestamp
absolut expiration timestamp of this timer
Definition: csi_timer.h:37
uint32_t Period
expiration period of this timer
Definition: csi_timer.h:38