blob: 7e98fc932f299b250c489929a034c0f6027b1a7b (
plain) (
blame)
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
|
/*******************************************************************************
* Copyright (c) 2013 protos software gmbh (http://www.protos.de).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* CONTRIBUTORS:
* Thomas Schuetz (initial contribution)
*
*******************************************************************************/
/**
*
* etTimer.c MinGW implementation of etTimer
*
*/
#include "osal/etTimer.h"
#include "helpers/etTimeHelpers.h"
#include "debugging/etLogger.h"
#include "debugging/etMSCLogger.h"
/** global handle for the Windows timer queue */
static HANDLE hTimerQueue = NULL;
void etTimer_construct(etTimer* self, etTime* timerInterval, etTimerFunction timerFunction){
self->osTimerData = NULL;
self->timerInterval.sec = timerInterval->sec;
self->timerInterval.nSec = timerInterval->nSec;
self->timerFunction = timerFunction;
if (hTimerQueue == NULL){
/* the Windows timer queue is only needed once for all timers */
hTimerQueue = CreateTimerQueue();
if (hTimerQueue == NULL){
etLogger_logError("etTimer_construct: CreateTimerQueue failed");
}
}
}
void etTimer_start(etTimer* self){
UINT elapse;
/* calculate the time in milliseconds -> accuracy will of nSec will get lost in windows! */
elapse = etTimeHelpers_convertToMSec(&(self->timerInterval));
if (hTimerQueue == NULL){
etLogger_logError("etTimer_start: no Timer Queue to create timer (NULL)");
}
else {
if (CreateTimerQueueTimer( &(self->osTimerData), hTimerQueue, self->timerFunction, NULL , 0, elapse, 0) == FALSE){
etLogger_logError("etTimer_start: Timer could not be created");
}
}
}
void etTimer_stop(etTimer* self){
if (DeleteTimerQueueTimer(hTimerQueue, self->osTimerData, NULL) == FALSE){
etLogger_logError("etTimer_stop: Timer could not be stopped");
}
}
void etTimer_destruct(etTimer* self){
/* TODO: destroy hTimerQueue if last timer is destroyed */
/* DeleteTimerQueue(hTimerQueue); */
}
|