#include #include #include #include #include #include #define _NANOSECS_PER_SEC 1000000000 static long long _TimeSpecDiffNs(const struct timespec *pts1, const struct timespec *pts2) { long long ns1 = (long long)pts1->tv_sec * _NANOSECS_PER_SEC + pts1->tv_nsec; long long ns2 = (long long)pts2->tv_sec * _NANOSECS_PER_SEC + pts2->tv_nsec; return ns2 - ns1; } int main(int argc, char **argv) { long long elps1, elps2; int tnum1 = 3, tnum2 = 14, nPulse, nOldPulse = 0; unsigned long tw1 = 1, tw2 = 1; struct timespec tsRes, tsStart, tsEnd1, tsEnd2; memset(&tsEnd1, 0, sizeof(tsEnd1)); memset(&tsEnd2, 0, sizeof(tsEnd2)); if(!GfaTimerInit(32, GTR_25ms)) { printf("GfaTimerInit failed!\n"); return 1; } tf_set(tnum1); tf_set(tnum2); tw_set(tnum1, 15000); tw_set(tnum2, 10000); clock_gettime(CLOCK_MONOTONIC, &tsStart); do { nPulse = cp_test(GTCP_750ms); if(nOldPulse != nPulse) { nOldPulse = nPulse; printf("Pulse 750ms %d\n", nPulse); } if(tw1) { if(!(tw1 = tw_read(tnum1))) { clock_gettime(CLOCK_MONOTONIC, &tsEnd1); printf("T%d expired.\n", tnum1); } } if(tw2) { if(!(tw2 = tw_read(tnum2))) { clock_gettime(CLOCK_MONOTONIC, &tsEnd2); printf("T%d expired.\n", tnum2); } } usleep(25000); // printf("T%d: %3lu, T%d: %3lu\n", tnum1, tw1, tnum2, tw2); } while(tw1 || tw2); elps1 = _TimeSpecDiffNs(&tsStart, &tsEnd1); elps2 = _TimeSpecDiffNs(&tsStart, &tsEnd2); printf("\nT%d effective: %lld ms.\n", tnum1, elps1 / 1000000); printf("T%d effective: %lld ms.\n", tnum2, elps2 / 1000000); return 0; }