Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Software for White Rabbit PTP Core
Manage
Activity
Members
Labels
Plan
Issues
39
Issue boards
Milestones
Wiki
Code
Merge requests
5
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
Projects
Software for White Rabbit PTP Core
Commits
120e952a
Commit
120e952a
authored
9 years ago
by
Alessandro Rubini
Browse files
Options
Downloads
Patches
Plain Diff
wrc_main: turn uptime updating into a task
Signed-off-by:
Alessandro Rubini
<
rubini@gnudd.com
>
parent
f0575e73
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wrc_main.c
+27
-12
27 additions, 12 deletions
wrc_main.c
with
27 additions
and
12 deletions
wrc_main.c
+
27
−
12
View file @
120e952a
...
...
@@ -156,10 +156,37 @@ void init_hw_after_reset(void)
timer_init
(
1
);
}
/* count uptime, in seconds, for remote polling */
static
uint32_t
uptime_lastj
;
static
void
init_uptime
(
void
)
{
uptime_lastj
=
timer_get_tics
();
}
static
int
update_uptime
(
void
)
{
extern
uint32_t
uptime_sec
;
uint32_t
j
;
static
uint32_t
fraction
=
0
;
j
=
timer_get_tics
();
fraction
+=
j
-
uptime_lastj
;
uptime_lastj
=
j
;
if
(
fraction
>
TICS_PER_SECOND
)
{
fraction
-=
TICS_PER_SECOND
;
uptime_sec
++
;
return
1
;
}
return
0
;
}
struct
wrc_task
wrc_tasks
[]
=
{
{
.
name
=
"idle"
,
.
init
=
wrc_initialize
,
},
{
.
name
=
"uptime"
,
.
init
=
init_uptime
,
.
job
=
update_uptime
,
},
{
.
name
=
"check-link"
,
.
job
=
wrc_check_link
,
...
...
@@ -208,8 +235,6 @@ static void wrc_run_task(struct wrc_task *t)
int
main
(
void
)
{
extern
uint32_t
uptime_sec
;
uint32_t
j
,
lastj
,
fraction
=
0
;
int
i
;
check_reset
();
...
...
@@ -219,17 +244,7 @@ int main(void)
if
(
wrc_tasks
[
i
].
init
)
wrc_tasks
[
i
].
init
();
lastj
=
timer_get_tics
();
for
(;;)
{
/* count uptime, in seconds, for remote polling */
j
=
timer_get_tics
();
fraction
+=
j
-
lastj
;
lastj
=
j
;
while
(
fraction
>
TICS_PER_SECOND
)
{
fraction
-=
TICS_PER_SECOND
;
uptime_sec
++
;
}
/* run your tasks */
for
(
i
=
0
;
i
<
wrc_n_tasks
;
i
++
)
wrc_run_task
(
wrc_tasks
+
i
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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