Commit d0de8bbc authored by Alessandro Rubini's avatar Alessandro Rubini

general: introduce pp_can_adjust() for readability

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 3053b3af
......@@ -20,14 +20,7 @@ struct pp_runtime_opts {
Integer32 max_rst; /* Maximum number of nanoseconds to reset */
Integer32 max_dly; /* Maximum number of nanoseconds of delay */
Integer32 ttl;
int flags;
#define PP_FLAG_NO_ADJUST 0x01
#define PP_FLAG_NO_RESET 0x02
/* slave_only:1, -- moved to ppi, no more global */
/* master_only:1, -- moved to ppi, no more global */
/* ethernet_mode:1, -- moved to ppi, no more global */
/* e2e_mode:1, -- no more: we only support e2e */
/* gptp_mode:1, -- no more: peer-to-peer unsupported */
int flags; /* see below */
Integer16 ap, ai;
Integer16 s;
Integer8 announce_intvl;
......@@ -38,6 +31,23 @@ struct pp_runtime_opts {
void *arch_opts;
};
/*
* Flags for the above structure
*/
#define PP_FLAG_NO_ADJUST 0x01
#define PP_FLAG_NO_RESET 0x02
/* I'd love to use inlines, but we still miss some structure at this point*/
#define pp_can_adjust(ppi) (!(OPTS(ppi)->flags & PP_FLAG_NO_ADJUST))
#define pp_can_reset_clock(ppi) (!(OPTS(ppi)->flags & PP_FLAG_NO_RESET))
/* slave_only:1, -- moved to ppi, no more global */
/* master_only:1, -- moved to ppi, no more global */
/* ethernet_mode:1, -- moved to ppi, no more global */
/* e2e_mode:1, -- no more: we only support e2e */
/* gptp_mode:1, -- no more: peer-to-peer unsupported */
/* We need a globally-accessible structure with preset defaults */
extern struct pp_runtime_opts __pp_default_rt_opts;
......
......@@ -26,7 +26,7 @@ void pp_servo_init(struct pp_instance *ppi)
SRV(ppi)->obs_drift = -d << 10; /* note "-" */
} else {
/* level clock */
if (!(OPTS(ppi)->flags & PP_FLAG_NO_ADJUST))
if (pp_can_adjust(ppi))
ppi->t_ops->adjust(ppi, 0, 0);
SRV(ppi)->obs_drift = 0;
}
......@@ -209,8 +209,8 @@ void pp_servo_got_resp(struct pp_instance *ppi)
TimeInternal time_tmp;
/* if secs, reset clock or set freq adjustment to max */
if (!(OPTS(ppi)->flags & PP_FLAG_NO_ADJUST)) {
if (!(OPTS(ppi)->flags & PP_FLAG_NO_RESET)) {
if (pp_can_adjust(ppi)) {
if (pp_can_reset_clock(ppi)) {
/* Can't use adjust, limited to +/- 2s */
time_tmp = ppi->t4;
add_TimeInternal(&time_tmp, &time_tmp,
......@@ -278,7 +278,7 @@ void pp_servo_got_resp(struct pp_instance *ppi)
/* apply controller output as a clock tick rate adjustment, if
* provided by arch, or as a raw offset otherwise */
if (!(OPTS(ppi)->flags & PP_FLAG_NO_ADJUST)) {
if (pp_can_adjust(ppi)) {
if (ppi->t_ops->adjust_freq)
ppi->t_ops->adjust_freq(ppi, -adj);
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment