![]() |
Synergy Software Package User's Manual
|
The PTP HAL Module provides high-level APIs for the time synchronization using the PTP function of the EPTPC peripheral module (EPTPC) on the synergy MCU. A user callback can be created to indicate the occurrence of pulse output timer event or the state change of Synchronous Frame Processing units(SYNFP0 and SYNFP1), Statistical Time Correction Algorithm(STCA), or Packet Relation Controller unit(PRC-TC).
The PTP HAL module configures the PTP for time synchronization functionality.
The PTP HAL allows the user to perform the following operations:
The following hardware features are, or are not, supported by SSP for PTP.
Legend:
| Symbol | Meaning |
|---|---|
| ✓ | Available (Tested) |
| ⌧ | Not Available (Not tested/not functional or both) |
| N/A | Not supported by MCU |
| MCU Group | Ordinary clock | Boundary clock | Transparent clock | E2E delay mechanism | P2P delay mechanism | Pulse output timer operation |
|---|---|---|---|---|---|---|
| S124 | N/A | N/A | N/A | N/A | N/A | N/A |
| S128 | N/A | N/A | N/A | N/A | N/A | N/A |
| S1JA | N/A | N/A | N/A | N/A | N/A | N/A |
| S3A1 | N/A | N/A | N/A | N/A | N/A | N/A |
| S3A3 | N/A | N/A | N/A | N/A | N/A | N/A |
| S3A6 | N/A | N/A | N/A | N/A | N/A | N/A |
| S3A7 | N/A | N/A | N/A | N/A | N/A | N/A |
| S5D3 | N/A | N/A | N/A | N/A | N/A | N/A |
| S5D5 | N/A | N/A | N/A | N/A | N/A | N/A |
| S5D9 | ✓ | N/A | N/A | ✓ | ✓ | ✓ |
| S7G2 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
The PTP HAL module interface defines APIs for key features such as initializing, starting, stopping, getting and setting of synchronous information, setting start time for pulse output timer, setting ELC event indication, and updating PTP message flags. A complete list of the available APIs, an example API call and a short description of each can be found in the following table. A table of status return values follows the API summary table.
PTP HAL Module API Summary
PTP API functions
| Function Name | Example API Call and Description |
|---|---|
| open | g_ptp.p_api->open(g_ptp.p_ctrl, g_ptp.p_cfg);Open the PTP driver module. |
| close | g_ptp.p_api->close(g_ptp.p_ctrl);Close the PTP driver module. |
| configure | g_ptp.p_api->configure(g_ptp.p_ctrl, ip_address, physical_address_msw, physical_address_lsw);Configures the PTP driver module. |
| setExtPromiscuous | g_ptp.p_api->setExtPromiscuous(g_ptp.p_ctrl, 1, false);Sets or clears the extended promiscuous mode |
| setLocalClock | g_ptp.p_api->setLocalClock(g_ptp.p_ctrl, &lc_clk);Sets local clock counter |
| getLocalClock | g_ptp.p_api->getLocalClock(g_ptp.p_ctrl, &lc_clk, 20);Gets local clock counter. |
| getMasterPortID | g_ptp.p_api->getMasterPortID(g_ptp.p_ctrl, 1, curClkId, &curPortId);Gets master port ID. |
| setMasterPortID | g_ptp.p_api->setMasterPortID(g_ptp.p_ctrl, 1, curClkId, &curPortId);Sets master port ID. |
| getSyncInfo | g_ptp.p_api->getSyncInfo(g_ptp.p_ctrl, 1, &master_offset, &path_delay);Get current offsetFromMaster and meanPathDelay. |
| start | g_ptp.p_api->start(g_ptp.p_ctrl, 100);Starts the time synchronization. |
| stop | g_ptp.p_api->stop(g_ptp.p_ctrl, 100);Stops the time synchronization. |
| checkWorst10Values | g_ptp.p_api->checkWorst10Values(g_ptp.p_ctrl, 40000);Checks worst 10 values acquired by hardware and set as gradient limits. |
| setWorst10Values | g_ptp.p_api->setWorst10Values(g_ptp.p_ctrl, 32);Sets the time interval for collecting worst 10 values. |
| getWorst10Values | g_ptp.p_api->getWorst10Values(g_ptp.p_ctrl, p_lim, m_lim, 40000);Gets the worst 10 values acquired by software. |
| setGradientLimit | g_ptp.p_api->setGradientLimit(g_ptp.p_ctrl, p_lim, m_lim);Sets the gradient limits for positive and negative worst 10 values. |
| updateClockID | g_ptp.p_api->updateClockID(g_ptp.p_ctrl, 1, clock_id);Updates clock identity field. |
| updateDomainNumber | g_ptp.p_api->updateDomainNumber(g_ptp.p_ctrl, 1, domain_num);Updates domain number field in the message header. |
| updateAnnounceFlags | g_ptp.p_api->updateAnnounceFlags(g_ptp.p_ctrl, 1, &p_flag);Updates announce message's flag field. |
| updateAnnounceMsgs | g_ptp.p_api->updateAnnounceMsgs(g_ptp.p_ctrl, 1, &p_message);Updates announce message's message field. |
| updateSyncAnnounceMsgInterval | g_ptp.p_api->updateSyncAnnounceMsgInterval(g_ptp.p_ctrl, 1, &p_sync_interval, &p_ance_interval);Updates transmission interval and logMessageInterval of Sync and Announce messages. |
| updateDelayMsgInterval | g_ptp.p_api->updateDelayMsgInterval(g_ptp.p_ctrl, 1, &p_interval, &p_timeout);Updates transmission interval, logMessageInterval and timeout values of Delay message. |
| getMessageReceptionConfig | g_ptp.p_api->getMessageReceptionConfig(g_ptp.p_ctrl, 1, &p_ptp_message_reception);Gets PTP message reception synchronous configuration. |
| setMessageReceptionConfig | g_ptp.p_api->setMessageReceptionConfig(g_ptp.p_ctrl, PTP_TEST_CHANNEL, &p_ptp_message_reception);Sets PTP message reception synchronous configuration. |
| disableTimer | g_ptp.p_api->disableTimer(g_ptp.p_ctrl, PTP_STCA_TIMER_CHANNEL_0));Disables the specified timer event interrupt. |
| indicateEvent | g_ptp.p_api->indicateEvent(g_ptp.p_ctrl, cyc_ch, PTP_STCA_TIMER_PULSE_EDGE_RISING, true);Sets or clears ELC interrupt indication. |
| autoClearEvent | g_ptp.p_api->autoClearEvent(g_ptp.p_ctrl, cyc_ch, PTP_STCA_TIMER_PULSE_EDGE_RISING, true);Sets or clears ELC interrupt auto clear mode. |
| setTimer | g_ptp.p_api->setTimer(g_ptp.p_ctrl, 0U, start_time, 200000, 100000);Sets start time, pulse period and pulse width for the pulse output timer. |
| setMINTevent | g_ptp.p_api->setMINTevent(g_ptp.p_ctrl, PTP_EVENT_STCA, 0x03, false);Sets EPTPC MINT interrupt event. |
| enableINFABTnotification | g_ptp.p_api->enableINFABTnotification(g_ptp.p_ctrl, 1);Enables EPTPC INFABT notification of the specified PTP channel. |
| disableINFABTnotification | g_ptp.p_api->disableINFABTnotification(g_ptp.p_ctrl, 1); Disables EPTPC INFABT notification of the specified PTP channel. |
| checkINFABTstatus | g_ptp.p_api->checkINFABTstatus(g_ptp.p_ctrl, &status);Checks the status of INFABT flag of the specified PTP channel. |
| clearINFABTstatus | g_ptp.p_api->clearINFABTstatus(g_ptp.p_ctrl, 1);Clears INFABT interrupt occurrence flag of the specified PTP channel. |
| versionGet | g_ptp.p_api->versionGet(&ptp_version);Get the driver version based on compile time macros. |
PTP HAL Module Status Return Values
| Name | Description |
|---|---|
| SSP_SUCCESS | API Call Successful. |
| SSP_ERR_INVALID_CHANNEL | Attempt to use invalid PTP channel |
| SSP_ERR_NOT_OPEN | Unit is not open. |
| SSP_ERR_ASSERTION | An input pointer is NULL. |
| SSP_ERR_IRQ_BSP_DISABLED | A required interrupt does not exist in the vector table. |
| SSP_ERR_TIMEOUT | Timeout error. |
| SSP_ERR_INVALID_MODE | Attempt to use unsupported or incorrect mode. |
| SSP_ERR_IN_USE | Unit is already opened. |
The PTP driver on r_ptp HAL module controls the on-chip Precision Time Protocol (PTP) module for the Ethernet Controller (EPTPC) on a Synergy microcontroller, as configured by the user. It directly controls the EPTPC hardware without using any RTOS elements. It provides convenient API functions to simplify development.
PTP HAL module can be used for the synchronization of clocks.
Clock state
Clock mode
Delay correction mechanism
Statistical time correction algorithm (STCA): When configured as a slave, the synchronized state can be identified by the offset from master value staying below a threshold specified in advance or calculated statistically from collected positive and negative gradient values by hardware or software (worst-10 acquisition).
STCA clock can be used as the clock source for generating pulse signals from pulse output timer m (m = 0 to 5). PCLKA is used as a source clock at a frequency of 20 MHz.
The generated pulse signals can be linked through event link (ELC) to get triggered when a rising or falling edge is detected.
Interrupts and callback: The user callback must be registered to handle pulse output timer event or state change of SYNFP0, SYNFP1, STCA or PRC-TC. If the user callback is registered then the PTP driver will invoke the callback (ptp_cfg_t::p_callback) with argument ptp_callback_args_t, indicating the event ptp_event_t.
PTPEDMAC supports the following interrupts:
Initialization: Ethernet initialization should be done and Ethernet link should be up before calling PTP APIs.
PTP HAL module limitations:
EPTPC hardware limitations:
This section describes how to include the PTP HAL Module in an application using the SSP configurator.
PTP HAL driver is used as a lower level module for Ethernet and is not available to add as a separate stack. It is available as optional driver under sf_el_nx. PTPEDMAC is added as a lower level module for PTP automatically. An example is illustrated in the following figure where a module must be selected to Add PTP Driver. The following figure shows the selection of the PTP driver to complete the stack for the module.
When the PTP Driver on r_ptp is added to the thread stack as shown in the following figure, the configurator automatically adds any needed lower‑level modules. Any modules needing additional configuration information have the box text highlighted in Red. Modules with a Gray band are individual modules that stand alone. Modules with a Blue band are shared or common; they need only be added once and can be used by multiple stacks. Modules with a Pink band can require the selection of lower-level modules; these are either optional or recommended. (This is indicated in the block with the inclusion of this text.) If the addition of lower-level modules is required, the module description include Add in the text. Clicking on any Pink banded modules brings up the New icon and displays possible choices.
The PTP HAL Module must be configured by the user for the desired operation. The available configuration settings and defaults for all the user-accessible properties are given in the properties tab within the SSP configurator and are shown in the following tables for easy reference. Only properties that can be changed without causing conflicts are available for modification. Other properties are locked and not available for changes and are identified with a lock icon for the locked property in the Properties window in the ISDE. This approach simplifies the configuration process and makes it much less error-prone than previous manual approaches to configuration. The available configuration settings and defaults for all the user-accessible properties are given in the Properties tab within the SSP Configurator and are shown in the following tables for easy reference.
Configuration Settings for the PTP HAL Module on r_ptp
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Selects if code for parameter checking is to be included in the build. |
| Name | g_ptp | Module name. |
| Clock mode | Ordinary clock 0, Ordinary clock 1, Boundary clock, Transparent clock Default: Ordinary clock 0 | PTP clock mode selection. |
| STCA synchronous mode | Mode 1- No gradient collection, Mode 2- Gradient collection by hardware, Mode 2- Gradient collection by software Default: Mode 2- Gradient collection by hardware | STCA synchronous mode selection. |
| MINT callback | Default: NULL | PTP MINT interrupt callback selection. |
| MINT interrupt priority | Priority 0 (highest), Priority 1:14, Priority 15 (lowest - not valid if using ThreadX) Default: Priority 12 | Select the MINT interrupt priority. |
| Clock state | Slave, Master Default: Slave | PTP clock state selection. |
| Delay correction mechanism | E2E (End to end), P2P (Peer to peer) Default: End to end delay correction mechanism | Delay correction mechanism selection. |
| Frame format | Ethernet II, Ethernet 802.3, Ethernet II over UDP4, Ethernet 802.3 over UDP4 Default: Ethernet II | PTP message frame format selection. |
Other MCUs may have different default values and available configuration settings.
No specific clock configurations are required for the PTP HAL Module.
No specific pin configurations are required for the PTP HAL Module.
The typical steps in using the PTP HAL module in an application are:
PTP master application:
1. Initialize the PTP HAL module using ptp_api_t::open, ptp_api_t::configure, ptpedmac_api_t::open APIs.
2. Set PTP host interface for PTP message transfer using the ptpedmac_api_t::linkProcess API.
3. Set the local clock value using the ptp_api_t::setLocalClock API.
4. Start time synchronization using the ptp_api_t::start API.
5. Stop synchronization using the ptp_api_t::stop API.
6. Use the ptp_api_t::close call to close the peripheral.
PTP slave application:
Application for setting pulse output timer: