-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathone_step_tx_oper_setting_sm.c
191 lines (171 loc) · 5.79 KB
/
one_step_tx_oper_setting_sm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* Excelfore gptp - Implementation of gPTP(IEEE 802.1AS)
* Copyright (C) 2019 Excelfore Corporation (https://excelfore.com)
*
* This file is part of Excelfore-gptp.
*
* Excelfore-gptp 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.
*
* Excelfore-gptp 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.
*
* You should have received a copy of the GNU General Public License
* along with Excelfore-gptp. If not, see
* <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>.
*/
#include "mind.h"
#include "mdeth.h"
#include "gptpnet.h"
#include "gptpclock.h"
#include "one_step_tx_oper_setting_sm.h"
typedef enum {
INIT,
NOT_ENABLED,
INITIALIZE,
SET_ONE_STEP_TX_OPER,
REACTION,
}one_step_tx_oper_setting_state_t;
struct one_step_tx_oper_setting_data{
PerTimeAwareSystemGlobal *ptasg;
PerPortGlobal *ppg;
MDEntityGlobal *mdeg;
one_step_tx_oper_setting_state_t state;
one_step_tx_oper_setting_state_t last_state;
OneStepTxOperSettingSM *thisSM;
int domainIndex;
int portIndex;
};
#define PORT_OPER sm->ppg->forAllDomain->portOper
#define PTP_PORT_ENABLED sm->ppg->ptpPortEnabled
#define USE_MGT_SETTABLE_ONE_STEP_TX_OPER sm->ppg->useMgtSettableOneStepTxOper
#define MGT_SETTABLE_ONE_STEP_TX_OPER sm->ppg->mgtSettableOneStepTxOper
#define CURRENT_ONE_STEP_TX_OPER sm->ppg->currentOneStepTxOper
#define INITIAL_ONE_STEP_TX_OPER sm->ppg->initialOneStepTxOper
#define ONE_STEP_TX_OPER sm->mdeg->oneStepTxOper
#define ONE_STEP_TRANSMIT sm->mdeg->oneStepTransmit
static one_step_tx_oper_setting_state_t allstate_condition(one_step_tx_oper_setting_data_t *sm)
{
if(sm->ptasg->BEGIN || !sm->ptasg->instanceEnable ||
!PORT_OPER || !PTP_PORT_ENABLED || USE_MGT_SETTABLE_ONE_STEP_TX_OPER )
return NOT_ENABLED;
return sm->state;
}
static void *not_enabled_proc(one_step_tx_oper_setting_data_t *sm)
{
UB_LOG(UBL_DEBUGV, "one_step_tx_oper_setting:%s:domainIndex=%d, portIndex=%d\n",
__func__, sm->domainIndex, sm->portIndex);
if(USE_MGT_SETTABLE_ONE_STEP_TX_OPER){
CURRENT_ONE_STEP_TX_OPER = MGT_SETTABLE_ONE_STEP_TX_OPER;
ONE_STEP_TX_OPER = CURRENT_ONE_STEP_TX_OPER && ONE_STEP_TRANSMIT;
}
return NULL;
}
static one_step_tx_oper_setting_state_t not_enabled_condition(one_step_tx_oper_setting_data_t *sm)
{
if(PORT_OPER && PTP_PORT_ENABLED && !USE_MGT_SETTABLE_ONE_STEP_TX_OPER)
return INITIALIZE;
return NOT_ENABLED;
}
static void *initialize_proc(one_step_tx_oper_setting_data_t *sm)
{
UB_LOG(UBL_DEBUGV, "one_step_tx_oper_setting:%s:domainIndex=%d, portIndex=%d\n",
__func__, sm->domainIndex, sm->portIndex);
CURRENT_ONE_STEP_TX_OPER = INITIAL_ONE_STEP_TX_OPER;
ONE_STEP_TX_OPER = CURRENT_ONE_STEP_TX_OPER && ONE_STEP_TRANSMIT;
return NULL;
}
static one_step_tx_oper_setting_state_t initialize_condition(one_step_tx_oper_setting_data_t *sm)
{
if(sm->thisSM->rcvdSignalingMsg4) return SET_ONE_STEP_TX_OPER;
return INITIALIZE;
}
static void *set_one_step_tx_oper_proc(one_step_tx_oper_setting_data_t *sm)
{
UB_LOG(UBL_DEBUGV, "one_step_tx_oper_setting:%s:domainIndex=%d, portIndex=%d\n",
__func__, sm->domainIndex, sm->portIndex);
CURRENT_ONE_STEP_TX_OPER =
GET_FLAG_BIT(sm->thisSM->rcvdSignalingPtr->flags,
ONE_STEP_RECEIVE_CAPABLE_BIT)?true:false;
ONE_STEP_TX_OPER = CURRENT_ONE_STEP_TX_OPER && ONE_STEP_TRANSMIT;
sm->thisSM->rcvdSignalingMsg4 = false;
return NULL;
}
static one_step_tx_oper_setting_state_t set_one_step_tx_oper_condition(
one_step_tx_oper_setting_data_t *sm)
{
if(sm->thisSM->rcvdSignalingMsg4) sm->last_state=REACTION;
return SET_ONE_STEP_TX_OPER;
}
void *one_step_tx_oper_setting_sm(one_step_tx_oper_setting_data_t *sm, uint64_t cts64)
{
bool state_change;
void *retp=NULL;
if(!sm) return NULL;
sm->state = allstate_condition(sm);
while(true){
state_change=(sm->last_state != sm->state);
sm->last_state = sm->state;
switch(sm->state){
case INIT:
sm->state = NOT_ENABLED;
break;
case NOT_ENABLED:
if(state_change)
retp=not_enabled_proc(sm);
sm->state = not_enabled_condition(sm);
break;
case INITIALIZE:
if(state_change)
retp=initialize_proc(sm);
sm->state = initialize_condition(sm);
break;
case SET_ONE_STEP_TX_OPER:
if(state_change)
retp=set_one_step_tx_oper_proc(sm);
sm->state = set_one_step_tx_oper_condition(sm);
break;
case REACTION:
break;
}
if(retp) return retp;
if(sm->last_state == sm->state) break;
}
return retp;
}
void one_step_tx_oper_setting_sm_init(one_step_tx_oper_setting_data_t **sm,
int domainIndex, int portIndex,
PerTimeAwareSystemGlobal *ptasg,
PerPortGlobal *ppg,
MDEntityGlobal *mdeg)
{
UB_LOG(UBL_DEBUGV, "%s:domainIndex=%d, portIndex=%d\n",
__func__, domainIndex, portIndex);
INIT_SM_DATA(one_step_tx_oper_setting_data_t, OneStepTxOperSettingSM, sm);
(*sm)->ptasg = ptasg;
(*sm)->ppg = ppg;
(*sm)->mdeg = mdeg;
(*sm)->domainIndex = domainIndex;
(*sm)->portIndex = portIndex;
}
int one_step_tx_oper_setting_sm_close(one_step_tx_oper_setting_data_t **sm)
{
UB_LOG(UBL_DEBUGV, "%s:domainIndex=%d, portIndex=%d\n",
__func__, (*sm)->domainIndex, (*sm)->portIndex);
CLOSE_SM_DATA(sm);
return 0;
}
void *one_step_tx_oper_setting_SignalingMsg4(one_step_tx_oper_setting_data_t *sm,
PTPMsgIntervalRequestTLV *rcvdSignalingPtr,
uint64_t cts64)
{
UB_LOG(UBL_DEBUGV, "%s:domainIndex=%d, portIndex=%d\n",
__func__, sm->domainIndex, sm->portIndex);
sm->thisSM->rcvdSignalingMsg4 = true;
sm->thisSM->rcvdSignalingPtr = rcvdSignalingPtr;
return one_step_tx_oper_setting_sm(sm, cts64);
}