SZSPTP ez430-RF2480 1.0

ZigBee Sensor Network with synchronized time and time-stamped measurements.
ptp_clock.c
Go to the documentation of this file.
1 /*
2  * ptp_clock.c
3  *
4  * Date: 19/06/2014
5  * Author: Fernando Biazi Nascimento
6  * Copyright © 2014 Fernando Biazi Nascimento. All rights reserved.
7  *
8  * License of use and copy on file license.txt
9  *
10  */
11 
21 /*
22  * ======== Includes ========
23  */
24 #include <stdlib.h>
25 #include "ptp_cfg.h"
26 #include "ptp_clock.h"
27 #include "ptp.h"
28 
29 /*
30  * ======== Constants ========
31  */
32 
33 /*
34  * ======== Macros ========
35  */
36 
37 /*
38  * ======== Types ========
39  */
40 
41 /*
42  * ======== Global Variables ========
43  */
44 
45 /*
46  * ======== Local Variables ========
47  */
48 
49 /*
50  * ======== Local Functions ========
51  */
52 
53 /*
54  * ================
55  */
56 
65  ptp_uinteger8 portIndex;
66 
67 #if (PTP_CLOCK_TYPE == PTP_CLOCK_TYPE_BOUNDARY) || (PTP_CLOCK_TYPE == PTP_CLOCK_TYPE_ORDINARY)
68 
69  // default values from J.4 (Annex J), besides not default BMC algorithm
70 
71  ptpClock.defaultDS.twoStepFlag = PTP_FALSE; // 8.2.1.2.1
72  ptpClock.defaultDS.clockIdentity = (ptp_clockIdentity *) PTP_ZEROSEQ64; // 8.2.1.2.2
73  ptpClock.defaultDS.numberPorts = 0; // 8.2.1.2.3 - redefined after initializing ports below
74  ptpClock.defaultDS.slaveOnly = PTP_FALSE; // 8.2.1.4.4
75  ptpClock.defaultDS.clockQuality.clockClass = 248; // 8.2.1.3.1.1 - Table 5 at 7.6.2.4
76  ptpClock.defaultDS.clockQuality.clockAccuracy = PTP_CA_Unknown; // 8.2.1.3.1.2
77  ptpClock.defaultDS.clockQuality.offsetScaledLogVariance = 0xFFFF; // 8.2.1.3.1.3, 7.6.3.3 - not computed
78  ptpClock.defaultDS.priority1 = 0; // 8.2.1.4.1
79  ptpClock.defaultDS.priority2 = 0; // 8.2.1.4.2
80  ptpClock.defaultDS.domainNumber = 0; // 8.2.1.4.3
81 
82  ptpClock.currentDS.stepsRemoved = 0; // 8.2.2.2
83  ptpClock.currentDS.offsetFromMaster.scalatedNanoseconds = 0; // 8.2.2.3 - Could be kept in NV storage
84  ptpClock.currentDS.meanPathDelay.scalatedNanoseconds = 0; // 8.2.2.4 - Could be kept in NV storage
85 
86  ptpClock.parentDS.parentPortIdentity.clockIdentity =
87  ptpClock.defaultDS.clockIdentity; // 8.2.3.2
88  ptpClock.parentDS.parentPortIdentity.portNumber = 0; // 8.2.3.2
89  ptpClock.parentDS.parentStats = PTP_FALSE; // 8.2.3.3
90  ptpClock.parentDS.observedParentOffsetScaledLogVariance = 0xFFFF; // 8.2.3.4
91  ptpClock.parentDS.observedParentClockPhaseChangeRate = 0x7FFFFFFF; // 8.2.3.5
92  ptpClock.parentDS.grandMasterIdentity = ptpClock.defaultDS.clockIdentity; // 8.2.3.6
93  ptpClock.parentDS.grandMasterclockQuality = ptpClock.defaultDS.clockQuality; // 8.2.3.7
94  ptpClock.parentDS.grandMasterPriority1 = ptpClock.defaultDS.priority1; // 8.2.3.8
95  ptpClock.parentDS.grandMasterPriority2 = ptpClock.defaultDS.priority2; // 8.2.3.9
96 
97  ptpClock.timePropertiesDS.currentUtcOffset = PTP_DESIGNTIME_UTCOFFSET; // 8.2.4.2 - b), 7.2.3
98  ptpClock.timePropertiesDS.currentUtcOffsetValid = PTP_FALSE; // 8.2.4.3
99  ptpClock.timePropertiesDS.leap59 = PTP_FALSE; // 8.2.4.4
100  ptpClock.timePropertiesDS.leap61 = PTP_FALSE; // 8.2.4.5
101  ptpClock.timePropertiesDS.timeTraceable = PTP_FALSE; // 8.2.4.6
102  ptpClock.timePropertiesDS.frequencyTraceable = PTP_FALSE; // 8.2.4.7
103  ptpClock.timePropertiesDS.ptpTimescale = PTP_FALSE; // 8.2.4.8
104  ptpClock.timePropertiesDS.timeSource = PTP_TS_INTERNAL_OSCILLATOR; // 8.2.4.9
105 
106  // initialize ports
107  portIndex = PTP_NUMBERPORTS;
108  do {
109  portIndex--;
110 // ptpClock.portDS[i].portIdentity.clockIdentity = ptpClock.defaultDS.clockIdentity; // read ptpClock.defaultDS.clockIdentity directly
111 // ptpClock.portDS[i].portIdentity.portNumber = i + 1; // 8.2.5.2 - by port index
112  ptpClock.portDS[portIndex].portState = PTP_PS_INITIALIZING; // 8.2.5.3.1
113  ptpClock.portDS[portIndex].logMinDelayReqInterval = 0; // 8.2.5.3.2, 7.7.2.4 - min: ptpClock.portDS[i].logSyncInterval, max: ptpClock.portDS[i].logSyncInterval + 5
114  ptpClock.portDS[portIndex].peerMeanPathDelay.scalatedNanoseconds = 0; // 8.2.5.3.3
115  ptpClock.portDS[portIndex].logAnnounceInterval = PTP_LOG2ANNOUNCESYNCPDELEREQ; // 8.2.5.4.1
116  ptpClock.portDS[portIndex].announceReceiptTimeout = PTP_ANNOUNCERECEIPTTIMEOUT; // 8.2.5.4.2
117  ptpClock.portDS[portIndex].logSyncInterval = PTP_LOG2ANNOUNCESYNCPDELEREQ; // 8.2.5.4.3
118  ptpClock.portDS[portIndex].delayMechanism = PTP_DELAY_MECANISM; // 8.2.5.4.4
119  ptpClock.portDS[portIndex].logMinPdelayReqInterval = PTP_LOG2ANNOUNCESYNCPDELEREQ; // 8.2.5.4.5
120  ptpClock.portDS[portIndex].versionNumber = 2; // J.4
121  } while (portIndex);
122 
123  ptpClock.defaultDS.numberPorts = PTP_NUMBERPORTS;
124 
125 #elif PTP_CLOCK_TYPE == PTP_CLOCK_TYPE_TRANSPARENT
126  ptpClock.transparentClockDefaultDS.clockIdentity = cId;
127  ptpClock.transparentClockDefaultDS.numberPorts = 0;
128  ptpClock.transparentClockDefaultDS.delayMechanism = PTP_DELAY_MECANISM;
129  ptpClock.transparentClockDefaultDS.primaryDomain = 0;
130 #endif
131 
132 }
133 
void ptp_clock_initialize()
PTP clock initialization.
Definition: ptp_clock.c:64
PTP interface.
#define PTP_DELAY_MECANISM
Definition: ptp_cfg.h:95
#define PTP_DESIGNTIME_UTCOFFSET
Definition: ptp_cfg.h:77
#define PTP_NUMBERPORTS
Definition: ptp_cfg.h:100
ptp_octet ptp_clockIdentity[8]
Definition: ptp_types.h:322
#define PTP_LOG2ANNOUNCESYNCPDELEREQ
Definition: ptp_cfg.h:67
unsigned char ptp_uinteger8
Definition: ptp_types.h:90
PTP configuration values to compile.
PTP clock object for synchronization.
#define PTP_ZEROSEQ64
Definition: ptp_const.h:58
#define PTP_ANNOUNCERECEIPTTIMEOUT
Definition: ptp_cfg.h:72