-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0e42a7
commit 79d59a5
Showing
10 changed files
with
148 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
build/ | ||
.vscode/ | ||
*.bak |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "os-timer-port.h" | ||
#include "os-timer.h" | ||
#include "pt-os.h" | ||
#include <stdio.h> | ||
|
||
#if __linux__ | ||
|
||
#include <signal.h> | ||
#include <time.h> | ||
#include <sys/time.h> | ||
|
||
static void (*TimerCallback_)(); | ||
static long TimerBaseUs_ = 0; | ||
|
||
static void TimerRoutine(int signo) | ||
{ | ||
struct itimerval value, ovalue; | ||
switch (signo){ | ||
case SIGALRM: | ||
portTimerStop(); | ||
TimerCallback_(); | ||
break; | ||
} | ||
} | ||
|
||
void portTimerInit( void (*callback)()) | ||
{ | ||
struct timeval tv; | ||
gettimeofday(&tv,NULL); | ||
TimerBaseUs_ = tv.tv_sec*1000000 + tv.tv_usec; | ||
TimerCallback_ = callback; | ||
signal(SIGALRM, TimerRoutine); | ||
} | ||
|
||
void portTimerStop() | ||
{ | ||
struct itimerval value, ovalue; | ||
value.it_value.tv_sec = 0; | ||
value.it_value.tv_usec = 0; | ||
value.it_interval.tv_sec = 0; | ||
value.it_interval.tv_usec = 0; | ||
setitimer(ITIMER_REAL, &value, &ovalue); | ||
} | ||
|
||
long portTimerGetUs() | ||
{ | ||
struct timeval tv; | ||
gettimeofday(&tv,NULL); | ||
return (tv.tv_sec*1000000 + tv.tv_usec - TimerBaseUs_); | ||
} | ||
|
||
void portTimerStart(long end_us) | ||
{ | ||
struct itimerval value, ovalue; | ||
long offset = end_us - portTimerGetUs(); | ||
if (offset > 5) | ||
{ | ||
value.it_value.tv_sec = offset/1000000; | ||
value.it_value.tv_usec = offset%1000000; | ||
value.it_interval.tv_sec = value.it_value.tv_sec; | ||
value.it_interval.tv_usec = value.it_value.tv_usec; | ||
setitimer(ITIMER_REAL, &value, &ovalue); | ||
} | ||
else TimerCallback_(); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,6 @@ | |
#include <cassert> | ||
#define OS_ASSERT assert | ||
|
||
#define OS_PRINT printf | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters