1 /*
2  * Copyright (c) 2024 BayLibre SAS
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file state_machine.h
9  * @brief Function and data structures used for state machine of the PTP Port.
10  *
11  * References are to version 2019 of IEEE 1588, ("PTP")
12  */
13 
14 #ifndef ZEPHYR_INCLUDE_PTP_STATE_MACHINE_H_
15 #define ZEPHYR_INCLUDE_PTP_STATE_MACHINE_H_
16 
17 #include <stdbool.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /**
24  * @brief Enumeration of PTP Port States.
25  */
26 enum ptp_port_state {
27 	PTP_PS_INITIALIZING = 1,
28 	PTP_PS_FAULTY,
29 	PTP_PS_DISABLED,
30 	PTP_PS_LISTENING,
31 	PTP_PS_PRE_TIME_TRANSMITTER,
32 	PTP_PS_TIME_TRANSMITTER,
33 	PTP_PS_GRAND_MASTER,
34 	PTP_PS_PASSIVE,
35 	PTP_PS_UNCALIBRATED,
36 	PTP_PS_TIME_RECEIVER,
37 };
38 
39 /**
40  * @brief Enumeration of PTP events.
41  */
42 enum ptp_port_event {
43 	PTP_EVT_NONE,
44 	PTP_EVT_POWERUP,
45 	PTP_EVT_INITIALIZE,
46 	PTP_EVT_INIT_COMPLETE,
47 	PTP_EVT_FAULT_DETECTED,
48 	PTP_EVT_FAULT_CLEARED,
49 	PTP_EVT_STATE_DECISION,
50 	PTP_EVT_ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES,
51 	PTP_EVT_QUALIFICATION_TIMEOUT_EXPIRES,
52 	PTP_EVT_DESIGNATED_ENABLED,
53 	PTP_EVT_DESIGNATED_DISABLED,
54 	PTP_EVT_TIME_TRANSMITTER_CLOCK_SELECTED,
55 	PTP_EVT_SYNCHRONIZATION_FAULT,
56 	PTP_EVT_RS_TIME_TRANSMITTER,
57 	PTP_EVT_RS_GRAND_MASTER,
58 	PTP_EVT_RS_TIME_RECEIVER,
59 	PTP_EVT_RS_PASSIVE,
60 };
61 
62 /**
63  * @brief Finite State Machine for PTP Port.
64  *
65  * @param[in] state   A current state of the Port
66  * @param[in] event   An event that occurred for the port
67  * @param[in] tt_diff True if Time Transmitter Clock has changed
68  *
69  * @return A new PTP Port state
70  */
71 enum ptp_port_state ptp_state_machine(enum ptp_port_state state,
72 				      enum ptp_port_event event,
73 				      bool tt_diff);
74 
75 /**
76  * @brief Finite State Machine for PTP Port that is configured as TimeReceiver-Only instance.
77  *
78  * @param[in] state   A current state of the Port
79  * @param[in] event   An event that occurred for the port
80  * @param[in] tt_diff True if Time Transmitter Clock has changed
81  *
82  * @return A new PTP Port state
83  */
84 enum ptp_port_state ptp_tr_state_machine(enum ptp_port_state state,
85 					 enum ptp_port_event event,
86 					 bool tt_diff);
87 
88 #ifdef __cplusplus
89 }
90 #endif
91 
92 /**
93  * @}
94  */
95 
96 #endif /* ZEPHYR_INCLUDE_PTP_STATE_MACHINE_H_ */
97