یsphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget"/translations/zh_CN/driver-api/ppsmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/zh_TW/driver-api/ppsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/it_IT/driver-api/ppsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/ja_JP/driver-api/ppsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/ko_KR/driver-api/ppsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/sp_SP/driver-api/ppsmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h SPDX-License-Identifier: GPL-2.0h]h SPDX-License-Identifier: GPL-2.0}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhhh](h%Copyright (C) 2007 Rodolfo Giometti <}(hhhhhNhNubh reference)}(hgiometti@enneenne.comh]hgiometti@enneenne.com}(hhhhhNhNubah}(h]h ]h"]h$]h&]refurimailto:giometti@enneenne.comuh1hhhubh>}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.h]hThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh)}(hThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.h]hThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hhh](h)}(hOverviewh]hOverview}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhKubh)}(h\LinuxPPS provides a programming interface (API) to define in the system several PPS sources.h]h\LinuxPPS provides a programming interface (API) to define in the system several PPS sources.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj hhubh)}(hPPS means "pulse per second" and a PPS source is just a device which provides a high precision signal each second so that an application can use it to adjust system clock time.h]hPPS means “pulse per second” and a PPS source is just a device which provides a high precision signal each second so that an application can use it to adjust system clock time.}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj hhubh)}(hX/A PPS source can be connected to a serial port (usually to the Data Carrier Detect pin) or to a parallel port (ACK-pin) or to a special CPU's GPIOs (this is the common case in embedded systems) but in each case when a new pulse arrives the system must apply to it a timestamp and record it for userland.h]hX1A PPS source can be connected to a serial port (usually to the Data Carrier Detect pin) or to a parallel port (ACK-pin) or to a special CPU’s GPIOs (this is the common case in embedded systems) but in each case when a new pulse arrives the system must apply to it a timestamp and record it for userland.}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj hhubh)}(hCommon use is the combination of the NTPD as userland program, with a GPS receiver as PPS source, to obtain a wallclock-time with sub-millisecond synchronisation to UTC.h]hCommon use is the combination of the NTPD as userland program, with a GPS receiver as PPS source, to obtain a wallclock-time with sub-millisecond synchronisation to UTC.}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK%hj hhubeh}(h]overviewah ]h"]overviewah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hRFC considerationsh]hRFC considerations}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj\hhhhhK+ubh)}(hWhile implementing a PPS API as RFC 2783 defines and using an embedded CPU GPIO-Pin as physical link to the signal, I encountered a deeper problem:h]hWhile implementing a PPS API as RFC 2783 defines and using an embedded CPU GPIO-Pin as physical link to the signal, I encountered a deeper problem:}(hjmhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK-hj\hhubh block_quote)}(hVAt startup it needs a file descriptor as argument for the function time_pps_create(). h]h)}(hUAt startup it needs a file descriptor as argument for the function time_pps_create().h]hUAt startup it needs a file descriptor as argument for the function time_pps_create().}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK1hj}ubah}(h]h ]h"]h$]h&]uh1j{hhhK1hj\hhubh)}(hXThis implies that the source has a /dev/... entry. This assumption is OK for the serial and parallel port, where you can do something useful besides(!) the gathering of timestamps as it is the central task for a PPS API. But this assumption does not work for a single purpose GPIO line. In this case even basic file-related functionality (like read() and write()) makes no sense at all and should not be a precondition for the use of a PPS API.h]hXThis implies that the source has a /dev/... entry. This assumption is OK for the serial and parallel port, where you can do something useful besides(!) the gathering of timestamps as it is the central task for a PPS API. But this assumption does not work for a single purpose GPIO line. In this case even basic file-related functionality (like read() and write()) makes no sense at all and should not be a precondition for the use of a PPS API.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK4hj\hhubh)}(hrThe problem can be simply solved if you consider that a PPS source is not always connected with a GPS data source.h]hrThe problem can be simply solved if you consider that a PPS source is not always connected with a GPS data source.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKsbah}(h]h ]h"]h$]h&]hhuh1j7hhhKhjhhubh)}(hPlease note that to compile userland programs, you need the file timepps.h. This is available in the pps-tools repository mentioned above.h]hPlease note that to compile userland programs, you need the file timepps.h. This is available in the pps-tools repository mentioned above.}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]testing-the-pps-supportah ]h"]testing the pps supportah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Generatorsh]h Generators}(hjehhhNhNubah}(h]h ]h"]h$]h&]uh1hhjbhhhhhKubh)}(hSometimes one needs to be able not only to catch PPS signals but to produce them also. For example, running a distributed simulation, which requires computers' clock to be synchronized very tightly.h]hSometimes one needs to be able not only to catch PPS signals but to produce them also. For example, running a distributed simulation, which requires computers’ clock to be synchronized very tightly.}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjbhhubh)}(hTo do so the class pps-gen has been added. PPS generators can be registered in the kernel by defining a struct pps_gen_source_info as follows::h]hTo do so the class pps-gen has been added. PPS generators can be registered in the kernel by defining a struct pps_gen_source_info as follows:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjbhhubj8)}(hstatic const struct pps_gen_source_info pps_gen_dummy_info = { .use_system_clock = true, .get_time = pps_gen_dummy_get_time, .enable = pps_gen_dummy_enable, };h]hstatic const struct pps_gen_source_info pps_gen_dummy_info = { .use_system_clock = true, .get_time = pps_gen_dummy_get_time, .enable = pps_gen_dummy_enable, };}hjsbah}(h]h ]h"]h$]h&]hhuh1j7hhhKhjbhhubh)}(hX*Where the use_system_clock states if the generator uses the system clock to generate its pulses, or they are from a peripheral device clock. Method get_time() is used to query the time stored into the generator clock, while the method enable() is used to enable or disable the PPS pulse generation.h]hX*Where the use_system_clock states if the generator uses the system clock to generate its pulses, or they are from a peripheral device clock. Method get_time() is used to query the time stored into the generator clock, while the method enable() is used to enable or disable the PPS pulse generation.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjbhhubh)}(hThen calling the function pps_gen_register_source() in your initialization routine as follows creates a new generator in the system::h]hThen calling the function pps_gen_register_source() in your initialization routine as follows creates a new generator in the system:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjbhhubj8)}(h7pps_gen = pps_gen_register_source(&pps_gen_dummy_info);h]h7pps_gen = pps_gen_register_source(&pps_gen_dummy_info);}hjsbah}(h]h ]h"]h$]h&]hhuh1j7hhhKhjbhhubeh}(h] generatorsah ]h"] generatorsah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hGenerators SYSFS supporth]hGenerators SYSFS support}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hJIf the SYSFS filesystem is enabled in the kernel it provides a new class::h]hIIf the SYSFS filesystem is enabled in the kernel it provides a new class:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj8)}(h8$ ls /sys/class/pps-gen/ pps-gen0/ pps-gen1/ pps-gen2/h]h8$ ls /sys/class/pps-gen/ pps-gen0/ pps-gen1/ pps-gen2/}hjsbah}(h]h ]h"]h$]h&]hhuh1j7hhhKhjhhubh)}(hlEvery directory is the ID of a PPS generator defined in the system and inside of it you find several files::h]hkEvery directory is the ID of a PPS generator defined in the system and inside of it you find several files:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj8)}(h`$ ls -F /sys/class/pps-gen/pps-gen0/ dev enable name power/ subsystem@ system time ueventh]h`$ ls -F /sys/class/pps-gen/pps-gen0/ dev enable name power/ subsystem@ system time uevent}hj sbah}(h]h ]h"]h$]h&]hhuh1j7hhhKhjhhubh)}(hCTo enable the PPS signal generation you can use the command below::h]hBTo enable the PPS signal generation you can use the command below:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj8)}(h-$ echo 1 > /sys/class/pps-gen/pps-gen0/enableh]h-$ echo 1 > /sys/class/pps-gen/pps-gen0/enable}hj&sbah}(h]h ]h"]h$]h&]hhuh1j7hhhKhjhhubeh}(h]generators-sysfs-supportah ]h"]generators sysfs supportah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hParallel port generatorh]hParallel port generator}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj<hhhhhKubh)}(hX2One way to do this is to invent some complicated hardware solutions but it may be neither necessary nor affordable. The cheap way is to load a PPS generator on one of the computers (master) and PPS clients on others (slaves), and use very simple cables to deliver signals using parallel ports, for example.h]hX2One way to do this is to invent some complicated hardware solutions but it may be neither necessary nor affordable. The cheap way is to load a PPS generator on one of the computers (master) and PPS clients on others (slaves), and use very simple cables to deliver signals using parallel ports, for example.}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj<hhubh)}(hParallel port cable pinout::h]hParallel port cable pinout:}(hj[hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj<hhubj8)}(hXapin name master slave 1 STROBE *------ * 2 D0 * | * 3 D1 * | * 4 D2 * | * 5 D3 * | * 6 D4 * | * 7 D5 * | * 8 D6 * | * 9 D7 * | * 10 ACK * ------* 11 BUSY * * 12 PE * * 13 SEL * * 14 AUTOFD * * 15 ERROR * * 16 INIT * * 17 SELIN * * 18-25 GND *-----------*h]hXapin name master slave 1 STROBE *------ * 2 D0 * | * 3 D1 * | * 4 D2 * | * 5 D3 * | * 6 D4 * | * 7 D5 * | * 8 D6 * | * 9 D7 * | * 10 ACK * ------* 11 BUSY * * 12 PE * * 13 SEL * * 14 AUTOFD * * 15 ERROR * * 16 INIT * * 17 SELIN * * 18-25 GND *-----------*}hjisbah}(h]h ]h"]h$]h&]hhuh1j7hhhMhj<hhubh)}(hXPlease note that parallel port interrupt occurs only on high->low transition, so it is used for PPS assert edge. PPS clear edge can be determined only using polling in the interrupt handler which actually can be done way more precisely because interrupt handling delays can be quite big and random. So current parport PPS generator implementation (pps_gen_parport module) is geared towards using the clear edge for time synchronization.h]hXPlease note that parallel port interrupt occurs only on high->low transition, so it is used for PPS assert edge. PPS clear edge can be determined only using polling in the interrupt handler which actually can be done way more precisely because interrupt handling delays can be quite big and random. So current parport PPS generator implementation (pps_gen_parport module) is geared towards using the clear edge for time synchronization.}(hjwhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj<hhubh)}(hXvClear edge polling is done with disabled interrupts so it's better to select delay between assert and clear edge as small as possible to reduce system latencies. But if it is too small slave won't be able to capture clear edge transition. The default of 30us should be good enough in most situations. The delay can be selected using 'delay' pps_gen_parport module parameter.h]hX~Clear edge polling is done with disabled interrupts so it’s better to select delay between assert and clear edge as small as possible to reduce system latencies. But if it is too small slave won’t be able to capture clear edge transition. The default of 30us should be good enough in most situations. The delay can be selected using ‘delay’ pps_gen_parport module parameter.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj<hhubeh}(h]parallel-port-generatorah ]h"]parallel port generatorah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h$Intel Timed I/O PPS signal generatorh]h$Intel Timed I/O PPS signal generator}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhM#ubh)}(hpIntel Timed I/O is a high precision device, present on 2019 and newer Intel CPUs, that can generate PPS signals.h]hpIntel Timed I/O is a high precision device, present on 2019 and newer Intel CPUs, that can generate PPS signals.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM%hjhhubh)}(hXTimed I/O and system time are both driven by same hardware clock. The signal is generated with a precision of ~20 nanoseconds. The generated PPS signal is used to synchronize an external device with system clock. For example, it can be used to share your clock with a device that receives PPS signal, generated by Timed I/O device. There are dedicated Timed I/O pins to deliver the PPS signal to an external device.h]hXTimed I/O and system time are both driven by same hardware clock. The signal is generated with a precision of ~20 nanoseconds. The generated PPS signal is used to synchronize an external device with system clock. For example, it can be used to share your clock with a device that receives PPS signal, generated by Timed I/O device. There are dedicated Timed I/O pins to deliver the PPS signal to an external device.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM(hjhhubh)}(h*Usage of Intel Timed I/O as PPS generator:h]h*Usage of Intel Timed I/O as PPS generator:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM/hjhhubh)}(hStart generating PPS signal::h]hStart generating PPS signal:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM1hjhhubj8)}(h,$echo 1 > /sys/class/pps-gen/pps-genx/enableh]h,$echo 1 > /sys/class/pps-gen/pps-genx/enable}hjsbah}(h]h ]h"]h$]h&]hhuh1j7hhhM3hjhhubh)}(hStop generating PPS signal::h]hStop generating PPS signal:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM5hjhhubj8)}(h,$echo 0 > /sys/class/pps-gen/pps-genx/enableh]h,$echo 0 > /sys/class/pps-gen/pps-genx/enable}hjsbah}(h]h ]h"]h$]h&]hhuh1j7hhhM7hjhhubeh}(h]$intel-timed-i-o-pps-signal-generatorah ]h"]$intel timed i/o pps signal generatorah$]h&]uh1hhhhhhhhM#ubeh}(h]pps-pulse-per-secondah ]h"]pps - pulse per secondah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjAerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(jjjYjVjjjjjjjjj_j\jjj9j6jjjju nametypes}(jjYjjjjj_jj9jjuh}(jhjVj jj\jjjjjjj\jjjbj6jjj<jju footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.