PPSSinkFromDevice configures the targetDevice to be a PPS sink and report PPS timestamp events
(targetDevice DeviceController, pinIndex uint)
| 263 | } |
| 264 | |
| 265 | // PPSSinkFromDevice configures the targetDevice to be a PPS sink and report PPS timestamp events |
| 266 | func PPSSinkFromDevice(targetDevice DeviceController, pinIndex uint) (*PPSSink, error) { |
| 267 | pfd := unix.PollFd{ |
| 268 | Events: unix.POLLIN | unix.POLLPRI, |
| 269 | Fd: int32(targetDevice.Fd()), |
| 270 | } |
| 271 | ppsSink := PPSSink{ |
| 272 | InputPin: pinIndex, |
| 273 | Polarity: unix.PTP_RISING_EDGE, |
| 274 | PulseWidth: defaultPulseWidth, |
| 275 | Device: targetDevice, |
| 276 | pollDescriptor: pfd, |
| 277 | } |
| 278 | |
| 279 | req := &PtpExttsRequest{ |
| 280 | Flags: unix.PTP_ENABLE_FEATURE | ppsSink.Polarity, |
| 281 | Index: uint32(ppsSink.InputPin), //nolint:gosec // InputPin is a small pin index that always fits in uint32 |
| 282 | } |
| 283 | |
| 284 | err := targetDevice.setPinFunc(pinIndex, unix.PTP_PF_EXTTS, defaultTs2PhcChannel) |
| 285 | if err != nil { |
| 286 | return nil, fmt.Errorf("error setting extts input pin for device %s: %w", targetDevice.File().Name(), err) |
| 287 | } |
| 288 | |
| 289 | err = targetDevice.extTTSRequest(req) |
| 290 | if err != nil { |
| 291 | return nil, fmt.Errorf("error during extts request for device %s: %w", targetDevice.File().Name(), err) |
| 292 | } |
| 293 | |
| 294 | return &ppsSink, nil |
| 295 | } |
| 296 | |
| 297 | // getPPSEventTimestamp reads the first PPS event from the sink file descriptor and returns the timestamp of the event |
no test coverage detected
searching dependent graphs…