MCPcopy Create free account
hub / github.com/facebook/time / ActivatePPSSource

Function ActivatePPSSource

phc/pps_source.go:113–160  ·  view source on GitHub ↗

ActivatePPSSource configures the PHC device to be a PPS timestamp source

(dev DeviceController, pinIndex uint)

Source from the content-addressed store, hash-verified

111
112// ActivatePPSSource configures the PHC device to be a PPS timestamp source
113func ActivatePPSSource(dev DeviceController, pinIndex uint) (*PPSSource, error) {
114 err := dev.setPinFunc(pinIndex, unix.PTP_PF_PEROUT, defaultTs2PhcChannel)
115 if err != nil {
116 log.Printf("Failed to set PPS Perout on pin index %d, channel %d, PHC %s. Error: %s. Continuing bravely on...",
117 pinIndex, defaultTs2PhcChannel, dev.File().Name(), err)
118 }
119
120 ts, err := dev.Time()
121 if err != nil {
122 return nil, fmt.Errorf("failed (clock_gettime) on %s", dev.File().Name())
123 }
124
125 // Initialize the PTPPeroutRequest struct
126 peroutRequest := &PtpPeroutRequest{}
127 peroutRequest.Index = uint32(defaultTs2PhcChannel)
128 peroutRequest.Period = PtpClockTime{Sec: 1, Nsec: 0}
129
130 // Set flags and pulse width
131 pulsewidth := defaultPulseWidth
132
133 // TODO: skip this block if pulsewidth unset once pulsewidth is configurable
134 peroutRequest.Flags |= ptpPeroutDutyCycle
135 peroutRequest.On = PtpClockTime{
136 Sec: int64(pulsewidth / 1e9),
137 Nsec: pulsewidth % 1e9,
138 }
139
140 // Set phase or start time
141 // TODO: reintroduce peroutPhase != -1 condition once peroutPhase is configurable
142 peroutRequest.StartOrPhase = PtpClockTime{
143 Sec: ts.Unix() + ppsStartDelay,
144 Nsec: 0,
145 }
146
147 err = dev.setPTPPerout(peroutRequest)
148
149 if err != nil {
150 peroutRequest.Flags &^= ptpPeroutDutyCycle
151 peroutRequest.On = PtpClockTime{}
152 err = dev.setPTPPerout(peroutRequest)
153
154 if err != nil {
155 return nil, fmt.Errorf("error retrying PTP_PEROUT_REQUEST2 with DUTY_CYCLE flag unset for backwards compatibility, %w", err)
156 }
157 }
158
159 return &PPSSource{PHCDevice: dev, state: PPSSet, PPSPinIndex: pinIndex}, nil
160}
161
162// Timestamp returns the timestamp of the last PPS output edge from the given PPS source
163func (ppsSource *PPSSource) Timestamp() (time.Time, error) {

Calls 7

UnixMethod · 0.80
setPinFuncMethod · 0.65
PrintfMethod · 0.65
NameMethod · 0.65
FileMethod · 0.65
TimeMethod · 0.65
setPTPPeroutMethod · 0.65

Used in the wild real call sites across dependent graphs

searching dependent graphs…