zephyr/subsys/net/lib/ptp/state_machine.h
Adam Wojasinski 2e7dbf1091 net: ptp: Add TIME_RECEIVER_ONLY feature
Implement possibility to configure PTP stack in TIME_RECEIVER_ONLY mode.
This restrics stack behaviour and doesn't allow for any PTP Port
of the PTP Clock become a TimeTransmitter Clock.

The change includes:
- Kconfig option
- Additional field in `struct ptp_port` structure
- New state machine function for a timeReceiver-only PTP Port.
- Extra steps in PTP Clock and PTP Port initialization.

New finite state machine is based on the figure 31
in section 9.2.5 of the IEEE 1588-2019.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00

97 lines
2.1 KiB
C

/*
* Copyright (c) 2024 BayLibre SAS
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file state_machine.h
* @brief Function and data structures used for state machine of the PTP Port.
*
* References are to version 2019 of IEEE 1588, ("PTP")
*/
#ifndef ZEPHYR_INCLUDE_PTP_STATE_MACHINE_H_
#define ZEPHYR_INCLUDE_PTP_STATE_MACHINE_H_
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Enumeration of PTP Port States.
*/
enum ptp_port_state {
PTP_PS_INITIALIZING = 1,
PTP_PS_FAULTY,
PTP_PS_DISABLED,
PTP_PS_LISTENING,
PTP_PS_PRE_TIME_TRANSMITTER,
PTP_PS_TIME_TRANSMITTER,
PTP_PS_GRAND_MASTER,
PTP_PS_PASSIVE,
PTP_PS_UNCALIBRATED,
PTP_PS_TIME_RECEIVER,
};
/**
* @brief Enumeration of PTP events.
*/
enum ptp_port_event {
PTP_EVT_NONE,
PTP_EVT_POWERUP,
PTP_EVT_INITIALIZE,
PTP_EVT_INIT_COMPLETE,
PTP_EVT_FAULT_DETECTED,
PTP_EVT_FAULT_CLEARED,
PTP_EVT_STATE_DECISION,
PTP_EVT_ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES,
PTP_EVT_QUALIFICATION_TIMEOUT_EXPIRES,
PTP_EVT_DESIGNATED_ENABLED,
PTP_EVT_DESIGNATED_DISABLED,
PTP_EVT_TIME_TRANSMITTER_CLOCK_SELECTED,
PTP_EVT_SYNCHRONIZATION_FAULT,
PTP_EVT_RS_TIME_TRANSMITTER,
PTP_EVT_RS_GRAND_MASTER,
PTP_EVT_RS_TIME_RECEIVER,
PTP_EVT_RS_PASSIVE,
};
/**
* @brief Finite State Machine for PTP Port.
*
* @param[in] state A current state of the Port
* @param[in] event An event that occurred for the port
* @param[in] tt_diff True if Time Transmitter Clock has changed
*
* @return A new PTP Port state
*/
enum ptp_port_state ptp_state_machine(enum ptp_port_state state,
enum ptp_port_event event,
bool tt_diff);
/**
* @brief Finite State Machine for PTP Port that is configured as TimeReceiver-Only instance.
*
* @param[in] state A current state of the Port
* @param[in] event An event that occurred for the port
* @param[in] tt_diff True if Time Transmitter Clock has changed
*
* @return A new PTP Port state
*/
enum ptp_port_state ptp_tr_state_machine(enum ptp_port_state state,
enum ptp_port_event event,
bool tt_diff);
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* ZEPHYR_INCLUDE_PTP_STATE_MACHINE_H_ */