Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
32
Issues
32
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
120e952a
Commit
120e952a
authored
Feb 15, 2016
by
Alessandro Rubini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrc_main: turn uptime updating into a task
Signed-off-by:
Alessandro Rubini
<
rubini@gnudd.com
>
parent
f0575e73
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
12 deletions
+27
-12
wrc_main.c
wrc_main.c
+27
-12
No files found.
wrc_main.c
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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment