6 #include "stg/common.h"
9 static pthread_t thrStgTimer;
10 static bool isTimerRunning = false;
11 volatile time_t stgTime;
13 const int TIME_SPEED = 1;
21 const int START_TIME = 0;
24 1 - start before new day (3 min before) 29.11.2005 23:57:00
25 2 - start before new month (3 min before) 30.11.2005 23:57:00
28 //-----------------------------------------------------------------------------
29 void * StgTimer(void *)
31 #ifdef STG_TIMER_DEBUG
33 memset(<, 0, sizeof(lt));
35 lt.tm_year = 2007 - 1900; // 2005
36 lt.tm_mon = 11 - 1; // Nov
37 lt.tm_hour = 23; // 23 h
38 lt.tm_min = 57; // 50 min
39 lt.tm_sec = 0; // 00 sec
49 stgTime = mktime(<);
54 stgTime = mktime(<);
62 isTimerRunning = true;
65 #ifdef STG_TIMER_DEBUG
66 struct timespec ts = {0, 1000000000 / TIME_SPEED};
68 //usleep(1000000 / TIME_SPEED);
71 struct timespec ts = {0, 500000000};
77 isTimerRunning = false;
81 //-----------------------------------------------------------------------------
85 isTimerRunning = false;
88 if (pthread_create(&thrStgTimer, NULL, StgTimer, NULL))
90 isTimerRunning = false;
97 //-----------------------------------------------------------------------------
101 pthread_join(thrStgTimer, NULL); // Cleanup thread resources
102 printfd(__FILE__, "STG_TIMER stopped\n");
104 //-----------------------------------------------------------------------------
105 bool IsStgTimerRunning()
107 return isTimerRunning;
109 //-----------------------------------------------------------------------------
110 int stgUsleep(unsigned long t)
112 #ifdef STG_TIMER_DEBUG
113 struct timespec ts = {(t / TIME_SPEED) / 1000000, ((t / TIME_SPEED) % 1000000) * 1000};
114 return nanosleep(&ts, NULL);
115 //return usleep(t / TIME_SPEED);
117 struct timespec ts = {t / 1000000, (t % 1000000) * 1000};
118 return nanosleep(&ts, NULL);
122 //-----------------------------------------------------------------------------
125 for (int i = 0; i < 5 && !isTimerRunning; i++)
128 //-----------------------------------------------------------------------------