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)
ppg->parentDS = &parentDS;
ppg->timePropertiesDS = &timePropertiesDS;
ppg->servo = &servo;
ppg->rt_opts = &default_rt_opts;
ppg->rt_opts = &__pp_default_rt_opts;
/* We are hosted, so we can allocate */
ppg->max_links = PP_MAX_LINKS;
......
......@@ -79,10 +79,14 @@ int wrc_ptp_set_mode(int mode)
{
uint32_t start_tics, lock_timeout = 0;
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;
......
......@@ -66,7 +66,7 @@ int main(int argc, char **argv)
ppg->parentDS = &parentDS;
ppg->timePropertiesDS = &timePropertiesDS;
ppg->servo = &servo;
ppg->rt_opts = &default_rt_opts;
ppg->rt_opts = &__pp_default_rt_opts;
/* We are hosted, so we can allocate */
ppg->max_links = PP_MAX_LINKS;
......
......@@ -29,8 +29,13 @@
#define PP_DEFAULT_SYNC_INTERVAL 0 /* -7 in 802.1AS */
#define PP_DEFAULT_SYNC_RECEIPT_TIMEOUT 3
#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_PRIORITY1 128
#define PP_DEFAULT_PRIORITY2 128
......
......@@ -36,7 +36,9 @@ struct pp_runtime_opts {
UInteger8 domain_number;
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
......
......@@ -55,7 +55,7 @@ int ppsi_main(int argc, char **argv)
ppi->ethernet_mode = PP_DEFAULT_ETHERNET_MODE;
ppi->iface_name = "eth0";
ppg->rt_opts = &default_rt_opts;
ppg->rt_opts = &__pp_default_rt_opts;
if (sys_adjtimex(&t) >= 0)
timePropertiesDS.currentUtcOffset = t.tai;
......
......@@ -191,6 +191,8 @@ int pp_parse_cmdline(struct pp_globals *ppg, int argc, char **argv)
GOPTS(ppg)->announce_intvl = 4;
break;
case 'g':
GOPTS(ppg)->clock_quality.clockClass
= PP_CLASS_SLAVE_ONLY;
/* Apply -g option globally, to each configured link */
for (j = 0; j < ppg->nlinks; j++)
ppg->pp_instances[j].slave_only = 1;
......
......@@ -50,8 +50,8 @@ int st_com_execute_slave(struct pp_instance *ppi)
if (pp_timeout_z(ppi, PP_TO_ANN_RECEIPT)) {
ppi->frgn_rec_num = 0;
ppi->frgn_rec_i = 0;
if (!ppi->slave_only &&
DSDEF(ppi)->clockQuality.clockClass != 255) {
if (DSDEF(ppi)->clockQuality.clockClass != PP_CLASS_SLAVE_ONLY
&& !ppi->slave_only) {
m1(ppi);
ppi->next_state = PPS_MASTER;
} else {
......
......@@ -8,14 +8,12 @@
#include <ppsi/ppsi.h>
/*
* 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.
* This is a global structure, because commandline and other config places
* need to change some values in there.
*/
struct pp_runtime_opts default_rt_opts = {
struct pp_runtime_opts __pp_default_rt_opts = {
.clock_quality = {
.clockClass = PP_DEFAULT_CLOCK_CLASS,
.clockClass = PP_CLASS_DEFAULT,
.clockAccuracy = PP_DEFAULT_CLOCK_ACCURACY,
.offsetScaledLogVariance = PP_DEFAULT_CLOCK_VARIANCE,
},
......@@ -36,6 +34,12 @@ struct pp_runtime_opts default_rt_opts = {
.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)
{
/*
......@@ -51,7 +55,7 @@ int pp_open_globals(struct pp_globals *ppg)
struct pp_runtime_opts *rt_opts;
if (!ppg->rt_opts)
ppg->rt_opts = &default_rt_opts;
ppg->rt_opts = &__pp_default_rt_opts;
rt_opts = ppg->rt_opts;
......@@ -81,7 +85,7 @@ int pp_open_globals(struct pp_globals *ppg)
if (def->slaveOnly) {
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)
......
......@@ -97,8 +97,8 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
out:
if (e == 0) {
if (ppi->slave_only ||
DSDEF(ppi)->clockQuality.clockClass == 255)
if (DSDEF(ppi)->clockQuality.clockClass == PP_CLASS_SLAVE_ONLY
|| ppi->slave_only)
ppi->next_state = PPS_LISTENING;
} else {
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