summaryrefslogtreecommitdiff
path: root/third_party/ptpd-1.1.0/src/dep-tiva/ptpd_timer.c
diff options
context:
space:
mode:
authorYuval Adam <yuv.adm@gmail.com>2014-08-08 14:42:07 +0300
committerYuval Adam <yuv.adm@gmail.com>2014-08-08 14:42:07 +0300
commita6163888f3c56123b1db313743c6147ba498732c (patch)
treeff7d15d991d1d09ba6cbc0cec80924f57445bfdd /third_party/ptpd-1.1.0/src/dep-tiva/ptpd_timer.c
parentc3e4c9a25c2910d2d66d52215b3406b13d5b23d5 (diff)
Add third_party libs
Diffstat (limited to 'third_party/ptpd-1.1.0/src/dep-tiva/ptpd_timer.c')
-rw-r--r--third_party/ptpd-1.1.0/src/dep-tiva/ptpd_timer.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/third_party/ptpd-1.1.0/src/dep-tiva/ptpd_timer.c b/third_party/ptpd-1.1.0/src/dep-tiva/ptpd_timer.c
new file mode 100644
index 0000000..47b0bb5
--- /dev/null
+++ b/third_party/ptpd-1.1.0/src/dep-tiva/ptpd_timer.c
@@ -0,0 +1,75 @@
+/* ptpd_timer.c */
+
+#include "../ptpd.h"
+
+static int iElapsedMilliSeconds = 0;
+
+void initTimer(void)
+{
+ DBG("initTimer\n");
+
+ iElapsedMilliSeconds = 0;
+}
+
+void timerTick(int iTickMilliSeconds)
+{
+ iElapsedMilliSeconds += iTickMilliSeconds;
+}
+
+void timerUpdate(IntervalTimer *itimer)
+{
+ int i, delta;
+
+ delta = iElapsedMilliSeconds / 1000;
+
+ if(delta <= 0)
+ return;
+
+ iElapsedMilliSeconds %= 1000;
+
+ for(i = 0; i < TIMER_ARRAY_SIZE; ++i)
+ {
+ if(itimer[i].interval > 0 && (itimer[i].left -= delta) <= 0)
+ {
+ itimer[i].left = itimer[i].interval;
+ itimer[i].expire = TRUE;
+ DBGV("timerUpdate: timer %u expired\n", i);
+ }
+ }
+}
+
+void timerStop(UInteger16 index, IntervalTimer *itimer)
+{
+ if(index >= TIMER_ARRAY_SIZE)
+ return;
+
+ itimer[index].interval = 0;
+}
+
+void timerStart(UInteger16 index, UInteger16 interval, IntervalTimer *itimer)
+{
+ if(index >= TIMER_ARRAY_SIZE)
+ return;
+
+ itimer[index].expire = FALSE;
+ itimer[index].left = interval;
+ itimer[index].interval = itimer[index].left;
+
+ DBGV("timerStart: set timer %d to %d\n", index, interval);
+}
+
+Boolean timerExpired(UInteger16 index, IntervalTimer *itimer)
+{
+ timerUpdate(itimer);
+
+ if(index >= TIMER_ARRAY_SIZE)
+ return FALSE;
+
+ if(!itimer[index].expire)
+ return FALSE;
+
+ itimer[index].expire = FALSE;
+
+ return TRUE;
+}
+