Commit 39ed260c authored by Aurelio Colosimo's avatar Aurelio Colosimo

runtime opts and initializing state mostly implemented

parent 8f51b53c
......@@ -8,7 +8,8 @@ LIBARCH := $A/libarch.a
OBJ-libarch := $A/posix-startup.o \
$A/main-loop.o \
$A/posix-socket.o \
$A/posix-io.o
$A/posix-io.o \
$A/posix-timer.o \
$(LIBARCH): $(OBJ-libarch)
$(AR) r $@ $^
......
......@@ -91,3 +91,16 @@ int posix_net_init(struct pp_instance *ppi)
int pp_net_init(struct pp_instance *ppi)
__attribute__((alias("posix_net_init")));
/*
* Shutdown all the network stuff
* TODO
*/
int posix_net_shutdown(struct pp_instance *ppi)
{
return 0;
}
int pp_net_shutdown(struct pp_instance *ppi)
__attribute__((alias("posix_net_shutdown")));
......@@ -31,6 +31,16 @@ int main(int argc, char **argv)
if (!ppi)
exit(__LINE__);
ppi->defaultDS = calloc(1, sizeof(*ppi->defaultDS));
ppi->currentDS = calloc(1, sizeof(*ppi->currentDS));
ppi->parentDS = calloc(1, sizeof(*ppi->parentDS));
ppi->portDS = calloc(1, sizeof(*ppi->portDS));
ppi->timePropertiesDS = calloc(1, sizeof(*ppi->timePropertiesDS));
if ((!ppi->defaultDS) || (!ppi->currentDS) || (!ppi->parentDS)
|| (!ppi->portDS) || (!ppi->timePropertiesDS))
exit(__LINE__);
if (posix_open_ch(ppi, ifname)) {
pp_diag_fatal(ppi, "open_ch", strerror(errno));
}
......
/*
* FIXME header
*/
/* Timer interface for GNU/Linux (and most likely other posix systems */
#include <sys/time.h>
#include <unistd.h>
#include <errno.h>
#include <pproto/pproto.h>
#include <pproto/diag.h>
#include "posix.h"
extern int posix_timer_init(struct pp_timer *tm)
{
/* TODO */
return 0;
}
extern int posix_timer_start(struct pp_timer *tm)
{
/* TODO */
return 0;
}
extern int posix_timer_stop(struct pp_timer *tm)
{
/* TODO */
return 0;
}
extern int posix_timer_update(struct pp_timer *tm)
{
/* TODO */
return 0;
}
extern int posix_timer_expired(struct pp_timer *tm)
{
/* TODO */
return 0;
}
int pp_timer_init(struct pp_timer *tm)
__attribute__((alias("posix_timer_init")));
int pp_timer_start(struct pp_timer *tm)
__attribute__((alias("posix_timer_start")));
int pp_timer_stop(struct pp_timer *tm)
__attribute__((alias("posix_timer_stop")));
int pp_timer_update(struct pp_timer *tm)
__attribute__((alias("posix_timer_update")));
int pp_timer_expired(struct pp_timer *tm)
__attribute__((alias("posix_timer_expired")));
......@@ -39,4 +39,7 @@
#define PP_TIMER_ANNOUNCE_RECEIPT 3
#define PP_TIMER_ANNOUNCE_INTERVAL 4
#define PP_TWO_STEP_FLAG 2
#define PP_VERSION_PTP 2
#endif /* __PTP_CONSTANTS_H__ */
......@@ -24,6 +24,10 @@ typedef uint8_t Enumeration4;
typedef uint8_t UInteger4;
typedef uint8_t Nibble;
#define PP_CLOCK_IDENTITY_LENGTH 8
/* FIXME: each struct must be aligned for lower memory usage */
typedef struct {
uint32_t lsb;
uint16_t msb;
......@@ -48,7 +52,7 @@ typedef struct {
Integer32 nanoseconds;
} TimeInternal;
typedef Octet *ClockIdentity; /*FIXME: allocate CLOCK_IDENTITY_LENGTH = 8 */
typedef Octet ClockIdentity[PP_CLOCK_IDENTITY_LENGTH];
typedef struct {
ClockIdentity clockIdentity;
......
/*
* Alessandro Rubini for CERN, 2011 -- public domain
* FIXME: header
*/
#ifndef __PTP_PROTO_H__
#define __PTP_PROTO_H__
......@@ -8,15 +8,47 @@
#include <stdarg.h>
#include <arch/arch.h> /* ntohs and so on */
#include <pproto/ieee1588_types.h>
#include <pproto/constants.h>
/*
* Runtime options. Default values can be overridden by command line.
*/
struct pp_runtime_opts {
/* TODO */
ClockQuality clock_quality;
TimeInternal inboundLatency, outboundLatency;
Integer32 max_rst; /* Maximum number of nanoseconds to reset */
Integer32 max_dly; /* Maximum number of nanoseconds of delay */
Integer32 ttl;
char *unicast_addr;
UInteger32 slave_only:1,
no_adjust:1,
display_stats:1,
csv_stats:1,
ethernet_mode:1,
e2e_mode:1,
ofst_first_updated:1,
no_rst_clk:1,
use_syslog:1;
Integer16 ap, ai;
Integer16 s;
Integer16 max_foreign_records;
Integer16 cur_utc_ofst;
Integer8 announce_intvl;
Integer8 sync_intvl;
UInteger8 prio1;
UInteger8 prio2;
UInteger8 domain_number;
char *iface_name;
void *arch_opts;
/*TODO ARCH: arch_opts, for arch-gnu-linux, might include the following:
* int log_fd;
* char *record_file; [PP_PATH_MAX]
* FILE *record_fp;
* char *file; [PP_PATH_MAX]
*/
};
extern struct pp_runtime_opts default_rt_opts; /* preinitialized
* with default values */
......@@ -64,14 +96,26 @@ extern int pp_parse_cmdline(struct pp_instance *ppi, int argc, char **argv);
/* Network stuff */
extern int pp_net_init(struct pp_instance *ppi);
extern int pp_net_shutdown(struct pp_instance *ppi);
extern int pp_recv_packet(struct pp_instance *ppi, void *pkt, int len);
extern int pp_send_packet(struct pp_instance *ppi, void *pkt, int len);
/* Timer stuff */
struct pp_timer
{
int dummy; /* FIXME */
};
extern int pp_timer_init(struct pp_timer *tm);
extern int pp_timer_start(struct pp_timer *tm);
extern int pp_timer_stop(struct pp_timer *tm);
extern int pp_timer_update(struct pp_timer *tm);
extern int pp_timer_expired(struct pp_timer *tm);
/* Get a timestamp */
extern void pp_get_stamp(uint32_t *sptr);
/*
* The state machine itself is an array of these structures.
*/
......
......@@ -12,7 +12,31 @@
*/
struct pp_runtime_opts default_rt_opts = {
/* TODO */
.max_rst = FALSE,
.max_dly = FALSE,
.slave_only = FALSE,
.no_adjust = TRUE,
.display_stats = FALSE,
.csv_stats = FALSE,
.ethernet_mode = FALSE,
.e2e_mode = FALSE,
.ofst_first_updated = FALSE,
.no_rst_clk = PP_DEFAULT_NO_RESET_CLOCK,
.use_syslog = FALSE,
.ap = PP_DEFAULT_AP,
.ai = PP_DEFAULT_AI,
.s = PP_DEFAULT_DELAY_S,
.max_foreign_records = PP_DEFAULT_MAX_FOREIGN_RECORDS,
.cur_utc_ofst = PP_DEFAULT_UTC_OFFSET,
.announce_intvl = PP_DEFAULT_ANNOUNCE_INTERVAL,
.sync_intvl = PP_DEFAULT_SYNC_INTERVAL,
.prio1 = PP_DEFAULT_PRIORITY1,
.prio2 = PP_DEFAULT_PRIORITY2,
.domain_number = PP_DEFAULT_DOMAIN_NUMBER,
.unicast_addr = 0,
.iface_name = 0,
.ttl = 1,
.arch_opts = 0,
};
......
......@@ -10,24 +10,58 @@
int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
struct pp_runtime_opts *rt_opts = ppi->rt_opts;
pp_net_shutdown(ppi);
/* FIXME
if (pp_net_init(ppi) < 0)
goto failure;
*/
/* TODO initialize other stuff */
/* TODO copy &ppi->rt_opts to &ppi->ppc. Do it here, no real need for a
initData function */
/* TODO ARCH initTimer(); define a "timer" abstract object, define it for
all the archs and initialize it here */
/* TODO CHECK initClock(rtOpts, ptpClock); check what is it for */
/* TODO CHECK m1(ptpClock);*/
/* TODO initializes header of a packet msgPackHeader(ptpClock->msgObuf,
ptpClock); */
if (1) /* FIXME: implement above */
/* Initialize default data set */
ppi->defaultDS->twoStepFlag = PP_TWO_STEP_FLAG;
/* TODO initialize clockIdentity with MAC address */
ppi->defaultDS->clockIdentity[3] = 0xff;
ppi->defaultDS->clockIdentity[4] = 0xfe;
ppi->defaultDS->numberPorts = 1;
pp_memcpy(&ppi->defaultDS->clockQuality, &rt_opts->clock_quality,
sizeof(ClockQuality));
ppi->defaultDS->priority1 = rt_opts->prio1;
ppi->defaultDS->priority2 = rt_opts->prio2;
ppi->defaultDS->domainNumber = rt_opts->domain_number;
ppi->defaultDS->slaveOnly = rt_opts->slave_only;
if (rt_opts->slave_only)
ppi->defaultDS->clockQuality.clockClass = 255;
/* Initialize port data set */
pp_memcpy(ppi->portDS->portIdentity.clockIdentity,
ppi->defaultDS->clockIdentity, PP_CLOCK_IDENTITY_LENGTH);
ppi->portDS->portIdentity.portNumber = 1;
ppi->portDS->logMinDelayReqInterval = PP_DEFAULT_DELAYREQ_INTERVAL;
ppi->portDS->peerMeanPathDelay.seconds = 0;
ppi->portDS->peerMeanPathDelay.nanoseconds = 0;
ppi->portDS->logAnnounceInterval = rt_opts->announce_intvl;
ppi->portDS->announceReceiptTimeout =
PP_DEFAULT_ANNOUNCE_RECEIPT_TIMEOUT;
ppi->portDS->logSyncInterval = rt_opts->sync_intvl;
ppi->portDS->delayMechanism = PP_DEFAULT_DELAY_MECHANISM;
ppi->portDS->logMinPdelayReqInterval = PP_DEFAULT_PDELAYREQ_INTERVAL;
ppi->portDS->versionNumber = PP_VERSION_PTP;
if (pp_timer_init(0)) /* FIXME */
goto failure;
/* TODO Check the following code coming from ptpd.
*
* Init all remaining stuff:
* initClock(rtOpts, ptpClock);
*
* Set myself as master (in case will not receive any announce):
* m1(ptpClock);
*
* Prepare a message:
* msgPackHeader(ptpClock->msgObuf,ptpClock);
*/
ppi->next_state = PPS_LISTENING;
return 0;
......
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