Added MS/TP automatic baudrate detection option into the core MS/TP state machine. (#900)
This commit is contained in:
@@ -417,7 +417,7 @@ uint16_t dlmstp_receive(
|
||||
MSTP_Slave_Node_FSM(MSTP_Port);
|
||||
} else if (
|
||||
(MSTP_Port->This_Station <= DEFAULT_MAX_MASTER) ||
|
||||
MSTP_Port->ZeroConfigEnabled) {
|
||||
MSTP_Port->ZeroConfigEnabled || MSTP_Port->CheckAutoBaud) {
|
||||
while (MSTP_Master_Node_FSM(MSTP_Port)) {
|
||||
/* do nothing while some states fast transition */
|
||||
};
|
||||
@@ -700,6 +700,39 @@ bool dlmstp_zero_config_enabled_set(bool flag)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the MSTP port AutoBaudEnabled status
|
||||
* @return true if the MSTP port has AutoBaudEnabled
|
||||
*/
|
||||
bool dlmstp_check_auto_baud(void)
|
||||
{
|
||||
if (!MSTP_Port) {
|
||||
return false;
|
||||
}
|
||||
return MSTP_Port->CheckAutoBaud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the MSTP port AutoBaudEnabled flag
|
||||
* @param flag - true if the MSTP port has AutoBaudEnabled
|
||||
* @return true if the MSTP port AutoBaudEnabled was set
|
||||
* @note This flag is used to enable the Zero Configuration state machine
|
||||
* for the MSTP port. The Zero Configuration state machine is used to
|
||||
* automatically assign a MAC address to the MSTP port.
|
||||
*/
|
||||
bool dlmstp_check_auto_baud_set(bool flag)
|
||||
{
|
||||
if (!MSTP_Port) {
|
||||
return false;
|
||||
}
|
||||
MSTP_Port->CheckAutoBaud = flag;
|
||||
if (flag) {
|
||||
MSTP_Port->Auto_Baud_State = MSTP_AUTO_BAUD_STATE_INIT;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the MSTP port MAC address that this node prefers to use.
|
||||
* @return ZeroConfigStation value, or an out-of-range value if invalid
|
||||
@@ -961,6 +994,46 @@ uint32_t dlmstp_silence_milliseconds(void *arg)
|
||||
return milliseconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the valid frame time in milliseconds
|
||||
* @param arg - pointer to MSTP port structure
|
||||
* @return valid frame time in milliseconds
|
||||
*/
|
||||
uint32_t dlmstp_valid_frame_milliseconds(void *arg)
|
||||
{
|
||||
uint32_t milliseconds = 0, now = 0;
|
||||
struct mstp_port_struct_t *port = arg;
|
||||
struct dlmstp_user_data_t *user = NULL;
|
||||
|
||||
if (port) {
|
||||
user = port->UserData;
|
||||
}
|
||||
if (user) {
|
||||
now = mstimer_now();
|
||||
milliseconds = now - user->Valid_Frame_Milliseconds;
|
||||
}
|
||||
|
||||
return milliseconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset the valid frame timer
|
||||
* @param arg - pointer to MSTP port structure
|
||||
* @return valid frame time in milliseconds
|
||||
*/
|
||||
void dlmstp_valid_frame_milliseconds_reset(void *arg)
|
||||
{
|
||||
struct mstp_port_struct_t *port = arg;
|
||||
struct dlmstp_user_data_t *user = NULL;
|
||||
|
||||
if (port) {
|
||||
user = port->UserData;
|
||||
}
|
||||
if (user) {
|
||||
user->Valid_Frame_Milliseconds = mstimer_now();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset the RS-485 silence time to zero
|
||||
* @param arg - pointer to MSTP port structure
|
||||
@@ -994,6 +1067,10 @@ bool dlmstp_init(char *ifname)
|
||||
if (MSTP_Port) {
|
||||
MSTP_Port->SilenceTimer = dlmstp_silence_milliseconds;
|
||||
MSTP_Port->SilenceTimerReset = dlmstp_silence_reset;
|
||||
MSTP_Port->ValidFrameTimer = dlmstp_valid_frame_milliseconds;
|
||||
MSTP_Port->ValidFrameTimerReset = dlmstp_valid_frame_milliseconds_reset;
|
||||
MSTP_Port->BaudRate = dlmstp_baud_rate;
|
||||
MSTP_Port->BaudRateSet = dlmstp_set_baud_rate;
|
||||
user = (struct dlmstp_user_data_t *)MSTP_Port->UserData;
|
||||
if (user && !user->Initialized) {
|
||||
Ringbuf_Initialize(
|
||||
|
||||
Reference in New Issue
Block a user