rstp_pti.c
Go to the documentation of this file.
1 /**
2  * @file rstp_pti.c
3  * @brief Port Timers state machine (PTI)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2019-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneSTP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL RSTP_TRACE_LEVEL
33 
34 //Dependencies
35 #include "rstp/rstp.h"
36 #include "rstp/rstp_fsm.h"
37 #include "rstp/rstp_pti.h"
38 #include "rstp/rstp_misc.h"
39 #include "debug.h"
40 
41 //Check TCP/IP stack configuration
42 #if (RSTP_SUPPORT == ENABLED)
43 
44 //PTI state machine's states
46 {
47  {RSTP_PTI_STATE_ONE_SECOND, "ONE_SECOND"},
48  {RSTP_PTI_STATE_TICK, "TICK"}
49 };
50 
51 
52 /**
53  * @brief PTI state machine initialization
54  * @param[in] port Pointer to the bridge port context
55  **/
56 
58 {
59  //During initialization, the state machine enters the ONE_SECOND state
60  //and clears the tick signal
62 }
63 
64 
65 /**
66  * @brief PTI state machine implementation
67  * @param[in] port Pointer to the bridge port context
68  **/
69 
71 {
72  //All conditions for the current state are evaluated continuously until one
73  //of the conditions is met (refer to IEEE Std 802.1D-2004, section 17.16)
74  switch(port->ptiState)
75  {
76  //ONE_SECOND state?
78  //Each tick causes a transition to the TICK state
79  if(port->tick)
80  {
82  }
83 
84  break;
85 
86  //TICK state?
88  //The state machine then unconditionally transitions to the ONE_SECOND
89  //state to clear the tick variable and wait for the next tick
91  break;
92 
93  //Invalid state?
94  default:
95  //Just for sanity
96  rstpFsmError(port->context);
97  break;
98  }
99 }
100 
101 
102 /**
103  * @brief Update PTI state machine state
104  * @param[in] port Pointer to the bridge port context
105  * @param[in] newState New state to switch to
106  **/
107 
109 {
110  //Dump the state transition
111  TRACE_VERBOSE("Port %" PRIu8 ": PTI state machine %s -> %s\r\n",
112  port->portIndex,
115 
116  //Switch to the new state
117  port->ptiState = newState;
118 
119  //On entry to a state, the procedures defined for the state are executed
120  //exactly once (refer to IEEE Std 802.1D-2004, section 17.16)
121  switch(port->ptiState)
122  {
123  //ONE_SECOND state?
125  //Clear tick variable
126  port->tick = FALSE;
127  break;
128 
129  //TICK state?
130  case RSTP_PTI_STATE_TICK:
131  //On entry to TICK, all non-zero timer variables are decremented by one
132  rstpDecrementTimer(&port->helloWhen);
133  rstpDecrementTimer(&port->tcWhile);
134  rstpDecrementTimer(&port->fdWhile);
135  rstpDecrementTimer(&port->rcvdInfoWhile);
136  rstpDecrementTimer(&port->rrWhile);
137  rstpDecrementTimer(&port->rbWhile);
138  rstpDecrementTimer(&port->mdelayWhile);
139  rstpDecrementTimer(&port->edgeDelayWhile);
140  rstpDecrementTimer(&port->txCount);
141  break;
142 
143  //Invalid state?
144  default:
145  //Just for sanity
146  break;
147  }
148 
149  //The RSTP state machine is busy
150  port->context->busy = TRUE;
151 }
152 
153 #endif
Debugging facilities.
#define TRACE_VERBOSE(...)
Definition: debug.h:124
uint16_t port
Definition: dns_common.h:267
#define arraysize(a)
Definition: os_port.h:71
#define TRUE
Definition: os_port.h:50
#define FALSE
Definition: os_port.h:46
RSTP (Rapid Spanning Tree Protocol)
#define RstpBridgePort
Definition: rstp.h:40
void rstpFsmError(RstpBridgeContext *context)
RSTP state machine error handler.
Definition: rstp_fsm.c:226
Rapid Spanning Tree state machines.
void rstpDecrementTimer(uint_t *x)
Decrement timer value.
Definition: rstp_misc.c:910
const char_t * rstpGetParamName(uint_t value, const RstpParamName *paramList, size_t paramListLen)
Convert a parameter to string representation.
Definition: rstp_misc.c:883
RSTP helper functions.
const RstpParamName rstpPtiStates[]
Definition: rstp_pti.c:45
void rstpPtiChangeState(RstpBridgePort *port, RstpPtiState newState)
Update PTI state machine state.
Definition: rstp_pti.c:108
void rstpPtiFsm(RstpBridgePort *port)
PTI state machine implementation.
Definition: rstp_pti.c:70
void rstpPtiInit(RstpBridgePort *port)
PTI state machine initialization.
Definition: rstp_pti.c:57
Port Timers state machine (PTI)
RstpPtiState
Port Timers machine states.
Definition: rstp_pti.h:48
@ RSTP_PTI_STATE_ONE_SECOND
Definition: rstp_pti.h:49
@ RSTP_PTI_STATE_TICK
Definition: rstp_pti.h:50
Parameter value/name binding.
Definition: rstp_misc.h:48