Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
f683771f
Commit
f683771f
authored
11 years ago
by
Christian Mehlis
Browse files
Options
Downloads
Plain Diff
Merge pull request #463 from LudwigOrtmann/native_hwtimer_fixup
fix native hwtimer
parents
b0d51d32
751cfe64
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cpu/native/hwtimer_cpu.c
+65
-17
65 additions, 17 deletions
cpu/native/hwtimer_cpu.c
with
65 additions
and
17 deletions
cpu/native/hwtimer_cpu.c
+
65
−
17
View file @
f683771f
...
...
@@ -31,6 +31,7 @@
#include
<signal.h>
#include
<stdint.h>
#include
<stdlib.h>
#include
<string.h>
#include
<err.h>
#include
"hwtimer.h"
...
...
@@ -56,6 +57,41 @@ static int native_hwtimer_isset[ARCH_MAXTIMERS];
static
int
next_timer
=
-
1
;
static
void
(
*
int_handler
)(
int
);
/**
* Subtract the `struct timeval' values x and y, storing the result in
* result.
* Return 1 if the difference is negative, otherwise 0.
*
* Source:
* http://www.gnu.org/software/libc/manual/html_node/Elapsed-Time.html
*/
int
timeval_subtract
(
struct
timeval
*
result
,
struct
timeval
*
x
,
struct
timeval
*
y
)
{
/* Perform the carry for the later subtraction by updating y. */
if
(
x
->
tv_usec
<
y
->
tv_usec
)
{
int
nsec
=
(
y
->
tv_usec
-
x
->
tv_usec
)
/
1000000
+
1
;
y
->
tv_usec
-=
1000000
*
nsec
;
y
->
tv_sec
+=
nsec
;
}
if
(
x
->
tv_usec
-
y
->
tv_usec
>
1000000
)
{
int
nsec
=
(
x
->
tv_usec
-
y
->
tv_usec
)
/
1000000
;
y
->
tv_usec
+=
1000000
*
nsec
;
y
->
tv_sec
-=
nsec
;
}
/**
* Compute the time remaining to wait.
* tv_usec is certainly positive.
*/
result
->
tv_sec
=
x
->
tv_sec
-
y
->
tv_sec
;
result
->
tv_usec
=
x
->
tv_usec
-
y
->
tv_usec
;
/* Return 1 if result is negative. */
return
x
->
tv_sec
<
y
->
tv_sec
;
}
/**
* sets timeval to given ticks
*/
...
...
@@ -114,8 +150,25 @@ void schedule_timer(void)
}
/* next pending timer is in slot next_timer */
if
(
setitimer
(
ITIMER_REAL
,
&
native_hwtimer
[
next_timer
],
NULL
)
==
-
1
)
{
err
(
EXIT_FAILURE
,
"schedule_timer"
);
struct
timeval
now
;
ticks2tv
(
native_hwtimer_now
,
&
now
);
struct
itimerval
result
;
memset
(
&
result
,
0
,
sizeof
(
result
));
int
retval
=
timeval_subtract
(
&
result
.
it_value
,
&
native_hwtimer
[
next_timer
].
it_value
,
&
now
);
if
(
retval
||
(
tv2ticks
(
&
result
.
it_value
)
<
HWTIMERMINOFFSET
))
{
/* the timeout has happened already, schedule an interrupt */
int
sig
=
SIGALRM
;
if
(
real_write
(
_sig_pipefd
[
1
],
&
sig
,
sizeof
(
int
))
==
-
1
)
{
err
(
EXIT_FAILURE
,
"schedule_timer(): real_write()"
);
}
_native_sigpend
++
;
return
;
}
if
(
setitimer
(
ITIMER_REAL
,
&
result
,
NULL
)
==
-
1
)
{
err
(
EXIT_FAILURE
,
"schedule_timer: setitimer"
);
}
else
{
DEBUG
(
"schedule_timer(): set next timer (%i).
\n
"
,
next_timer
);
...
...
@@ -184,19 +237,8 @@ void hwtimer_arch_set(unsigned long offset, short timer)
{
DEBUG
(
"hwtimer_arch_set(%lu,
\033
[31m%i
\033
[0m)
\n
"
,
offset
,
timer
);
if
(
offset
<
HWTIMERMINOFFSET
)
{
offset
=
HWTIMERMINOFFSET
;
DEBUG
(
"hwtimer_arch_set: offset < MIN, set to: %lu
\n
"
,
offset
);
}
native_hwtimer_isset
[
timer
]
=
1
;
ticks2tv
(
offset
,
&
(
native_hwtimer
[
timer
].
it_value
));
DEBUG
(
"hwtimer_arch_set(): that is %lu s %lu us from now
\n
"
,
(
unsigned
long
)
native_hwtimer
[
timer
].
it_value
.
tv_sec
,
(
unsigned
long
)
native_hwtimer
[
timer
].
it_value
.
tv_usec
);
schedule_timer
();
offset
+=
native_hwtimer_now
;
hwtimer_arch_set_absolute
(
offset
,
timer
);
return
;
}
...
...
@@ -204,9 +246,15 @@ void hwtimer_arch_set(unsigned long offset, short timer)
void
hwtimer_arch_set_absolute
(
unsigned
long
value
,
short
timer
)
{
DEBUG
(
"hwtimer_arch_set_absolute(%lu, %i)
\n
"
,
value
,
timer
);
value
-=
native_hwtimer_now
;
hwtimer_arch_set
(
value
,
timer
);
ticks2tv
(
value
,
&
(
native_hwtimer
[
timer
].
it_value
));
DEBUG
(
"hwtimer_arch_set_absolute(): that is %lu s %lu us from now
\n
"
,
(
unsigned
long
)
native_hwtimer
[
timer
].
it_value
.
tv_sec
,
(
unsigned
long
)
native_hwtimer
[
timer
].
it_value
.
tv_usec
);
native_hwtimer_isset
[
timer
]
=
1
;
schedule_timer
();
return
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment