Commit 5f1e3cb3 authored by Alessandro Rubini's avatar Alessandro Rubini

general: define CLASS names and rename a global structure

This defines PP_CLASS_SLAVE_ONLY and similar names, and uses them properly.

Also, the global "struct default_rt_opts" was not following the
conventions about naming, so rename it to be a "pp" thing.  Moreover,
since we put all globals in ppg and we have ppg->rt_opts, try to use
that instead of a separate global.  Unfortunately the initialization
sequence is not well ordered, so __pp_default_rt_opts still remains
as a global variable, double-underscored to show it's not meant to be used.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 0b73a727
...@@ -45,7 +45,7 @@ int main(int argc, char **argv) ...@@ -45,7 +45,7 @@ int main(int argc, char **argv)
ppg->parentDS = &parentDS; ppg->parentDS = &parentDS;
ppg->timePropertiesDS = &timePropertiesDS; ppg->timePropertiesDS = &timePropertiesDS;
ppg->servo = &servo; ppg->servo = &servo;
ppg->rt_opts = &default_rt_opts; ppg->rt_opts = &__pp_default_rt_opts;
/* We are hosted, so we can allocate */ /* We are hosted, so we can allocate */
ppg->max_links = PP_MAX_LINKS; ppg->max_links = PP_MAX_LINKS;
......
...@@ -79,10 +79,14 @@ int wrc_ptp_set_mode(int mode) ...@@ -79,10 +79,14 @@ int wrc_ptp_set_mode(int mode)
{ {
uint32_t start_tics, lock_timeout = 0; uint32_t start_tics, lock_timeout = 0;
struct pp_instance *ppi = &ppi_static; struct pp_instance *ppi = &ppi_static;
typeof(default_rt_opts.clock_quality.clockClass) *class_ptr; struct pp_globals *ppg = ppi->glbs;
typeof(ppg->rt_opts->clock_quality.clockClass) *class_ptr;
/* We need to change the class in the default options */
class_ptr = &default_rt_opts.clock_quality.clockClass; /*
* We need to change the class in the default options.
* Unfortunately, ppg->rt_opts may be yet unassigned when this runs
*/
class_ptr = &__pp_default_rt_opts.clock_quality.clockClass;
ptp_mode = 0; ptp_mode = 0;
......
...@@ -66,7 +66,7 @@ int main(int argc, char **argv) ...@@ -66,7 +66,7 @@ int main(int argc, char **argv)
ppg->parentDS = &parentDS; ppg->parentDS = &parentDS;
ppg->timePropertiesDS = &timePropertiesDS; ppg->timePropertiesDS = &timePropertiesDS;
ppg->servo = &servo; ppg->servo = &servo;
ppg->rt_opts = &default_rt_opts; ppg->rt_opts = &__pp_default_rt_opts;
/* We are hosted, so we can allocate */ /* We are hosted, so we can allocate */
ppg->max_links = PP_MAX_LINKS; ppg->max_links = PP_MAX_LINKS;
......
...@@ -29,8 +29,13 @@ ...@@ -29,8 +29,13 @@
#define PP_DEFAULT_SYNC_INTERVAL 0 /* -7 in 802.1AS */ #define PP_DEFAULT_SYNC_INTERVAL 0 /* -7 in 802.1AS */
#define PP_DEFAULT_SYNC_RECEIPT_TIMEOUT 3 #define PP_DEFAULT_SYNC_RECEIPT_TIMEOUT 3
#define PP_DEFAULT_ANNOUNCE_RECEIPT_TIMEOUT 6 /* 3 by default */ #define PP_DEFAULT_ANNOUNCE_RECEIPT_TIMEOUT 6 /* 3 by default */
#define PP_DEFAULT_CLOCK_CLASS 187
#define PP_WRMASTER_CLOCK_CLASS 68 /* WR is better */ /* Clock classes (pag 55, PTP-2008) */
#define PP_CLASS_SLAVE_ONLY 255
#define PP_CLASS_DEFAULT 187
#define PP_CLASS_WR_GM_LOCKED 6
#define PP_CLASS_WR_GM_UNLOCKED 7
#define PP_DEFAULT_CLOCK_ACCURACY 0xFE #define PP_DEFAULT_CLOCK_ACCURACY 0xFE
#define PP_DEFAULT_PRIORITY1 128 #define PP_DEFAULT_PRIORITY1 128
#define PP_DEFAULT_PRIORITY2 128 #define PP_DEFAULT_PRIORITY2 128
......
...@@ -36,7 +36,9 @@ struct pp_runtime_opts { ...@@ -36,7 +36,9 @@ struct pp_runtime_opts {
UInteger8 domain_number; UInteger8 domain_number;
void *arch_opts; void *arch_opts;
}; };
extern struct pp_runtime_opts default_rt_opts; /* preinited with defaults */
/* We need a globally-accessible structure with preset defaults */
extern struct pp_runtime_opts __pp_default_rt_opts;
/* /*
* Communication channel. Is the abstraction of a unix socket, so that * Communication channel. Is the abstraction of a unix socket, so that
......
...@@ -55,7 +55,7 @@ int ppsi_main(int argc, char **argv) ...@@ -55,7 +55,7 @@ int ppsi_main(int argc, char **argv)
ppi->ethernet_mode = PP_DEFAULT_ETHERNET_MODE; ppi->ethernet_mode = PP_DEFAULT_ETHERNET_MODE;
ppi->iface_name = "eth0"; ppi->iface_name = "eth0";
ppg->rt_opts = &default_rt_opts; ppg->rt_opts = &__pp_default_rt_opts;
if (sys_adjtimex(&t) >= 0) if (sys_adjtimex(&t) >= 0)
timePropertiesDS.currentUtcOffset = t.tai; timePropertiesDS.currentUtcOffset = t.tai;
......
...@@ -191,6 +191,8 @@ int pp_parse_cmdline(struct pp_globals *ppg, int argc, char **argv) ...@@ -191,6 +191,8 @@ int pp_parse_cmdline(struct pp_globals *ppg, int argc, char **argv)
GOPTS(ppg)->announce_intvl = 4; GOPTS(ppg)->announce_intvl = 4;
break; break;
case 'g': case 'g':
GOPTS(ppg)->clock_quality.clockClass
= PP_CLASS_SLAVE_ONLY;
/* Apply -g option globally, to each configured link */ /* Apply -g option globally, to each configured link */
for (j = 0; j < ppg->nlinks; j++) for (j = 0; j < ppg->nlinks; j++)
ppg->pp_instances[j].slave_only = 1; ppg->pp_instances[j].slave_only = 1;
......
...@@ -50,8 +50,8 @@ int st_com_execute_slave(struct pp_instance *ppi) ...@@ -50,8 +50,8 @@ int st_com_execute_slave(struct pp_instance *ppi)
if (pp_timeout_z(ppi, PP_TO_ANN_RECEIPT)) { if (pp_timeout_z(ppi, PP_TO_ANN_RECEIPT)) {
ppi->frgn_rec_num = 0; ppi->frgn_rec_num = 0;
ppi->frgn_rec_i = 0; ppi->frgn_rec_i = 0;
if (!ppi->slave_only && if (DSDEF(ppi)->clockQuality.clockClass != PP_CLASS_SLAVE_ONLY
DSDEF(ppi)->clockQuality.clockClass != 255) { && !ppi->slave_only) {
m1(ppi); m1(ppi);
ppi->next_state = PPS_MASTER; ppi->next_state = PPS_MASTER;
} else { } else {
......
...@@ -8,14 +8,12 @@ ...@@ -8,14 +8,12 @@
#include <ppsi/ppsi.h> #include <ppsi/ppsi.h>
/* /*
* This file deals with opening and closing an instance. The channel * This is a global structure, because commandline and other config places
* must already have been created. In practice, this initializes the * need to change some values in there.
* state machine to the first state.
*/ */
struct pp_runtime_opts __pp_default_rt_opts = {
struct pp_runtime_opts default_rt_opts = {
.clock_quality = { .clock_quality = {
.clockClass = PP_DEFAULT_CLOCK_CLASS, .clockClass = PP_CLASS_DEFAULT,
.clockAccuracy = PP_DEFAULT_CLOCK_ACCURACY, .clockAccuracy = PP_DEFAULT_CLOCK_ACCURACY,
.offsetScaledLogVariance = PP_DEFAULT_CLOCK_VARIANCE, .offsetScaledLogVariance = PP_DEFAULT_CLOCK_VARIANCE,
}, },
...@@ -36,6 +34,12 @@ struct pp_runtime_opts default_rt_opts = { ...@@ -36,6 +34,12 @@ struct pp_runtime_opts default_rt_opts = {
.ttl = PP_DEFAULT_TTL, .ttl = PP_DEFAULT_TTL,
}; };
/*
* This file deals with opening and closing an instance. The channel
* must already have been created. In practice, this initializes the
* state machine to the first state.
*/
int pp_open_globals(struct pp_globals *ppg) int pp_open_globals(struct pp_globals *ppg)
{ {
/* /*
...@@ -51,7 +55,7 @@ int pp_open_globals(struct pp_globals *ppg) ...@@ -51,7 +55,7 @@ int pp_open_globals(struct pp_globals *ppg)
struct pp_runtime_opts *rt_opts; struct pp_runtime_opts *rt_opts;
if (!ppg->rt_opts) if (!ppg->rt_opts)
ppg->rt_opts = &default_rt_opts; ppg->rt_opts = &__pp_default_rt_opts;
rt_opts = ppg->rt_opts; rt_opts = ppg->rt_opts;
...@@ -81,7 +85,7 @@ int pp_open_globals(struct pp_globals *ppg) ...@@ -81,7 +85,7 @@ int pp_open_globals(struct pp_globals *ppg)
if (def->slaveOnly) { if (def->slaveOnly) {
pp_printf("Slave Only, clock class set to 255\n"); pp_printf("Slave Only, clock class set to 255\n");
def->clockQuality.clockClass = 255; def->clockQuality.clockClass = PP_CLASS_SLAVE_ONLY;
} }
if (pp_hooks.open) if (pp_hooks.open)
......
...@@ -97,8 +97,8 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -97,8 +97,8 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
out: out:
if (e == 0) { if (e == 0) {
if (ppi->slave_only || if (DSDEF(ppi)->clockQuality.clockClass == PP_CLASS_SLAVE_ONLY
DSDEF(ppi)->clockQuality.clockClass == 255) || ppi->slave_only)
ppi->next_state = PPS_LISTENING; ppi->next_state = PPS_LISTENING;
} else { } else {
ppi->next_state = PPS_FAULTY; ppi->next_state = PPS_FAULTY;
......
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