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
28
Issues
28
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
9b6b9b98
Commit
9b6b9b98
authored
Feb 12, 2014
by
Alessandro Rubini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
timer: fix overflow related bugs using time_after()
Signed-off-by:
Alessandro Rubini
<
rubini@gnudd.com
>
parent
9f94bb86
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
39 additions
and
34 deletions
+39
-34
syscon.c
dev/syscon.c
+4
-5
timer-wrs.c
dev/timer-wrs.c
+3
-7
ppsi-wrappers.c
lib/ppsi-wrappers.c
+3
-0
monitor.c
monitor/monitor.c
+8
-4
monitor_ppsi.c
monitor/monitor_ppsi.c
+8
-4
softpll_ng.c
softpll/softpll_ng.c
+4
-4
spll_external.c
softpll/spll_external.c
+5
-6
wrc_ptp_noposix.c
wrc_ptp_noposix.c
+1
-1
wrs_main.c
wrs_main.c
+3
-3
No files found.
dev/syscon.c
View file @
9b6b9b98
...
...
@@ -35,12 +35,11 @@ uint32_t timer_get_tics(void)
void
timer_delay
(
uint32_t
tics
)
{
uint32_t
t_
start
;
uint32_t
t_
end
;
// timer_init(1);
do
{
t_start
=
timer_get_tics
();
}
while
(
t_start
>
UINT32_MAX
-
tics
);
//in case of overflow
while
(
t_start
+
tics
>
timer_get_tics
())
;
t_end
=
timer_get_tics
()
+
tics
;
while
(
time_before
(
timer_get_tics
(),
t_end
))
;
}
dev/timer-wrs.c
View file @
9b6b9b98
...
...
@@ -9,12 +9,8 @@ uint32_t timer_get_tics(void)
void
timer_delay
(
uint32_t
tics
)
{
uint32_t
t_start
;
uint32_t
t_end
=
timer_get_tics
()
+
tics
;
t_start
=
timer_get_tics
();
if
(
t_start
+
tics
<
t_start
)
while
(
t_start
+
tics
<
timer_get_tics
());
while
(
t_start
+
tics
>
timer_get_tics
());
while
(
time_before
(
timer_get_tics
(),
t_end
))
;
}
lib/ppsi-wrappers.c
View file @
9b6b9b98
...
...
@@ -10,6 +10,9 @@
uint64_t
ptpd_netif_get_msec_tics
(
void
)
{
#if TICS_PER_SECOND != 1000
#error "This code assumes 1kHz timer"
#endif
return
timer_get_tics
();
}
...
...
monitor/monitor.c
View file @
9b6b9b98
...
...
@@ -44,7 +44,7 @@ extern int wrc_man_phase;
void
wrc_mon_gui
(
void
)
{
static
uint32_t
last
=
0
;
static
uint32_t
last
;
hexp_port_state_t
ps
;
int
tx
,
rx
;
uint64_t
sec
;
...
...
@@ -53,7 +53,9 @@ void wrc_mon_gui(void)
uint8_t
ip
[
4
];
#endif
if
(
timer_get_tics
()
-
last
<
wrc_ui_refperiod
)
if
(
!
last
)
last
=
timer_get_tics
();
if
(
time_before
(
timer_get_tics
(),
last
+
wrc_ui_refperiod
))
return
;
last
=
timer_get_tics
();
...
...
@@ -191,14 +193,16 @@ void wrc_mon_gui(void)
int
wrc_log_stats
(
uint8_t
onetime
)
{
static
uint32_t
last
=
0
;
static
uint32_t
last
;
hexp_port_state_t
ps
;
int
tx
,
rx
;
int
aux_stat
;
uint64_t
sec
;
uint32_t
nsec
;
if
(
!
onetime
&&
timer_get_tics
()
-
last
<
wrc_ui_refperiod
)
if
(
!
last
)
last
=
timer_get_tics
();
if
(
!
onetime
&&
time_before
(
timer_get_tics
(),
last
+
wrc_ui_refperiod
))
return
0
;
last
=
timer_get_tics
();
...
...
monitor/monitor_ppsi.c
View file @
9b6b9b98
...
...
@@ -74,7 +74,7 @@ int wrc_mon_status()
void
wrc_mon_gui
(
void
)
{
static
uint32_t
last
=
0
;
static
uint32_t
last
;
hexp_port_state_t
ps
;
int
tx
,
rx
;
int
aux_stat
;
...
...
@@ -84,7 +84,9 @@ void wrc_mon_gui(void)
uint8_t
ip
[
4
];
#endif
if
(
timer_get_tics
()
-
last
<
wrc_ui_refperiod
)
if
(
!
last
)
last
=
timer_get_tics
();
if
(
time_before
(
timer_get_tics
(),
last
+
wrc_ui_refperiod
))
return
;
last
=
timer_get_tics
();
...
...
@@ -256,14 +258,16 @@ static void wrc_mon_std_servo(void)
int
wrc_log_stats
(
uint8_t
onetime
)
{
static
uint32_t
last
=
0
;
static
uint32_t
last
;
hexp_port_state_t
ps
;
int
tx
,
rx
;
int
aux_stat
;
uint64_t
sec
;
uint32_t
nsec
;
if
(
!
onetime
&&
timer_get_tics
()
-
last
<
wrc_ui_refperiod
)
if
(
!
last
)
last
=
timer_get_tics
();
if
(
!
onetime
&&
time_before
(
timer_get_tics
(),
wrc_ui_refperiod
+
last
))
return
0
;
last
=
timer_get_tics
();
...
...
softpll/softpll_ng.c
View file @
9b6b9b98
...
...
@@ -114,8 +114,9 @@ static inline void sequencing_fsm(struct softpll_state *s, int tag_value, int ta
/* we need tags from at least one channel, so that the IRQ that calls this function
gets called again */
spll_enable_tagger
(
MAIN_CHANNEL
,
1
);
softpll
.
dac_timeout
=
timer_get_tics
();
softpll
.
dac_timeout
=
timer_get_tics
()
+
TICS_PER_SECOND
/
20
;
softpll
.
seq_state
=
SEQ_WAIT_CLEAR_DACS
;
break
;
...
...
@@ -124,8 +125,7 @@ static inline void sequencing_fsm(struct softpll_state *s, int tag_value, int ta
/* State "Wait until DACs have been cleared". Makes sure the VCO control inputs have stabilized before starting the PLL. */
case
SEQ_WAIT_CLEAR_DACS
:
{
if
(
timer_get_tics
()
-
softpll
.
dac_timeout
>
TICS_PER_SECOND
/
20
)
if
(
time_after
(
timer_get_tics
(),
softpll
.
dac_timeout
))
{
if
(
s
->
mode
==
SPLL_MODE_GRAND_MASTER
)
s
->
seq_state
=
SEQ_START_EXT
;
...
...
softpll/spll_external.c
View file @
9b6b9b98
...
...
@@ -52,15 +52,14 @@ static inline void realign_fsm(struct spll_external_state *s)
SPLL
->
ECCR
|=
SPLL_ECCR_ALIGN_EN
;
s
->
realign_state
=
REALIGN_STAGE1_WAIT
;
s
->
realign_timer
=
timer_get_tics
();
s
->
realign_timer
=
timer_get_tics
()
+
2
*
TICS_PER_SECOND
;
break
;
case
REALIGN_STAGE1_WAIT
:
if
(
SPLL
->
ECCR
&
SPLL_ECCR_ALIGN_DONE
)
s
->
realign_state
=
REALIGN_STAGE2
;
else
if
(
timer_get_tics
()
-
s
->
realign_timer
>
2
*
TICS_PER_SECOND
)
{
else
if
(
time_after
(
timer_get_tics
(),
s
->
realign_timer
))
{
SPLL
->
ECCR
&=
~
SPLL_ECCR_ALIGN_EN
;
s
->
realign_state
=
REALIGN_PPS_INVALID
;
}
...
...
@@ -75,7 +74,8 @@ static inline void realign_fsm(struct spll_external_state *s)
PPSG
->
ESCR
=
PPSG_ESCR_SYNC
;
s
->
realign_state
=
REALIGN_STAGE2_WAIT
;
s
->
realign_timer
=
timer_get_tics
();
s
->
realign_timer
=
timer_get_tics
()
+
2
*
TICS_PER_SECOND
;
}
break
;
...
...
@@ -83,8 +83,7 @@ static inline void realign_fsm(struct spll_external_state *s)
if
(
PPSG
->
ESCR
&
PPSG_ESCR_SYNC
)
{
PPSG
->
ESCR
=
PPSG_ESCR_PPS_VALID
|
PPSG_ESCR_TM_VALID
;
s
->
realign_state
=
REALIGN_DONE
;
}
else
if
(
timer_get_tics
()
-
s
->
realign_timer
>
2
*
TICS_PER_SECOND
)
{
}
else
if
(
time_after
(
timer_get_tics
(),
s
->
realign_timer
))
{
PPSG
->
ESCR
=
0
;
s
->
realign_state
=
REALIGN_PPS_INVALID
;
}
...
...
wrc_ptp_noposix.c
View file @
9b6b9b98
...
...
@@ -128,7 +128,7 @@ int wrc_ptp_set_mode(int mode)
while
(
!
spll_check_lock
(
0
)
&&
lock_timeout
)
{
timer_delay_ms
(
1000
);
mprintf
(
"."
);
if
(
time
r_get_tics
()
-
start_tics
>
lock_timeout
)
{
if
(
time
_after
(
timer_get_tics
(),
start_tics
+
lock_timeout
)
)
{
mprintf
(
"
\n
Lock timeout.
\n
"
);
return
-
ETIMEDOUT
;
}
else
if
(
uart_read_byte
()
==
27
)
{
...
...
wrs_main.c
View file @
9b6b9b98
...
...
@@ -10,7 +10,7 @@ const char *build_date;
int
main
(
void
)
{
uint32_t
start_tics
=
0
;
uint32_t
start_tics
=
timer_get_tics
()
;
uart_init_hw
();
...
...
@@ -25,8 +25,8 @@ int main(void)
for
(;;)
{
uint32_t
tics
=
timer_get_tics
();
if
(
ti
cs
-
start_tics
>
TICS_PER_SECOND
/
5
)
if
(
ti
me_after
(
tics
,
start_tics
+
TICS_PER_SECOND
/
5
)
)
{
// TRACE("tick!\n");
spll_show_stats
();
...
...
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