indenting.
This commit is contained in:
+179
-223
@@ -204,13 +204,10 @@ void MSTP_Create_And_Send_Frame(
|
|||||||
{ /* number of bytes of data (up to 501) */
|
{ /* number of bytes of data (up to 501) */
|
||||||
uint16_t len = 0; /* number of bytes to send */
|
uint16_t len = 0; /* number of bytes to send */
|
||||||
|
|
||||||
len = MSTP_Create_Frame((uint8_t *) & mstp_port->OutputBuffer[0], /* where frame is loaded */
|
len =
|
||||||
mstp_port->OutputBufferSize, /* amount of space available */
|
MSTP_Create_Frame((uint8_t *) & mstp_port->OutputBuffer[0],
|
||||||
frame_type, /* type of frame to send - see defines */
|
mstp_port->OutputBufferSize, frame_type, destination, source, data,
|
||||||
destination, /* destination address */
|
data_len);
|
||||||
source, /* source address */
|
|
||||||
data, /* any data to be sent - may be null */
|
|
||||||
data_len); /* number of bytes of data (up to 501) */
|
|
||||||
|
|
||||||
RS485_Send_Frame(mstp_port, (uint8_t *) & mstp_port->OutputBuffer[0], len);
|
RS485_Send_Frame(mstp_port, (uint8_t *) & mstp_port->OutputBuffer[0], len);
|
||||||
/* FIXME: be sure to reset SilenceTimer() after each octet is sent! */
|
/* FIXME: be sure to reset SilenceTimer() after each octet is sent! */
|
||||||
@@ -245,8 +242,8 @@ case MSTP_RECEIVE_STATE_IDLE:
|
|||||||
#if PRINT_ENABLED_RECEIVE_DATA
|
#if PRINT_ENABLED_RECEIVE_DATA
|
||||||
#if (defined(_WIN32) && defined(TEST_DLMSTP))
|
#if (defined(_WIN32) && defined(TEST_DLMSTP))
|
||||||
extern uint32_t timestamp_ms(void);
|
extern uint32_t timestamp_ms(void);
|
||||||
fprintf(stderr, "MSTP Rx %03u: %02X ",
|
fprintf(stderr, "MSTP Rx %03u: %02X ", (unsigned) timestamp_ms(),
|
||||||
(unsigned) timestamp_ms(), mstp_port->DataRegister);
|
mstp_port->DataRegister);
|
||||||
#else
|
#else
|
||||||
fprintf(stderr, "MSTP Rx: %02X ", mstp_port->DataRegister);
|
fprintf(stderr, "MSTP Rx: %02X ", mstp_port->DataRegister);
|
||||||
#endif
|
#endif
|
||||||
@@ -262,8 +259,7 @@ case MSTP_RECEIVE_STATE_IDLE:
|
|||||||
#endif
|
#endif
|
||||||
/* wait for the start of a frame. */
|
/* wait for the start of a frame. */
|
||||||
}
|
}
|
||||||
mstp_port->DataAvailable = false;
|
mstp_port->DataAvailable = false; mstp_port->SilenceTimerReset();
|
||||||
mstp_port->SilenceTimerReset();
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);}
|
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);}
|
||||||
break;
|
break;
|
||||||
/* In the PREAMBLE state, the node waits for the second octet of the preamble. */
|
/* In the PREAMBLE state, the node waits for the second octet of the preamble. */
|
||||||
@@ -276,8 +272,7 @@ case MSTP_RECEIVE_STATE_PREAMBLE:
|
|||||||
/* Error */
|
/* Error */
|
||||||
else
|
else
|
||||||
if (mstp_port->ReceiveError == true) {
|
if (mstp_port->ReceiveError == true) {
|
||||||
mstp_port->ReceiveError = false;
|
mstp_port->ReceiveError = false; mstp_port->SilenceTimerReset();
|
||||||
mstp_port->SilenceTimerReset();
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);
|
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);
|
||||||
/* wait for the start of a frame. */
|
/* wait for the start of a frame. */
|
||||||
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;}
|
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;}
|
||||||
@@ -300,8 +295,7 @@ if (mstp_port->DataRegister == 0x55) {
|
|||||||
else {
|
else {
|
||||||
/* wait for the start of a frame. */
|
/* wait for the start of a frame. */
|
||||||
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;}
|
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;}
|
||||||
mstp_port->DataAvailable = false;
|
mstp_port->DataAvailable = false; mstp_port->SilenceTimerReset();
|
||||||
mstp_port->SilenceTimerReset();
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);}
|
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);}
|
||||||
break;
|
break;
|
||||||
/* In the HEADER state, the node waits for the fixed message header. */
|
/* In the HEADER state, the node waits for the fixed message header. */
|
||||||
@@ -320,8 +314,7 @@ if (mstp_port->SilenceTimer() > Tframe_abort) {
|
|||||||
/* Error */
|
/* Error */
|
||||||
else
|
else
|
||||||
if (mstp_port->ReceiveError == true) {
|
if (mstp_port->ReceiveError == true) {
|
||||||
mstp_port->ReceiveError = false;
|
mstp_port->ReceiveError = false; mstp_port->SilenceTimerReset();
|
||||||
mstp_port->SilenceTimerReset();
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);
|
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);
|
||||||
/* indicate that an error has occurred during the reception of a frame */
|
/* indicate that an error has occurred during the reception of a frame */
|
||||||
mstp_port->ReceivedInvalidFrame = true;
|
mstp_port->ReceivedInvalidFrame = true;
|
||||||
@@ -340,41 +333,42 @@ if (mstp_port->Index == 0) {
|
|||||||
mstp_port->HeaderCRC =
|
mstp_port->HeaderCRC =
|
||||||
CRC_Calc_Header(mstp_port->DataRegister,
|
CRC_Calc_Header(mstp_port->DataRegister,
|
||||||
mstp_port->HeaderCRC);
|
mstp_port->HeaderCRC);
|
||||||
mstp_port->FrameType = mstp_port->DataRegister; mstp_port->Index = 1;}
|
mstp_port->FrameType = mstp_port->DataRegister;
|
||||||
|
mstp_port->Index = 1;}
|
||||||
/* Destination */
|
/* Destination */
|
||||||
else
|
else
|
||||||
if (mstp_port->Index == 1) {
|
if (mstp_port->Index == 1) {
|
||||||
mstp_port->HeaderCRC =
|
mstp_port->HeaderCRC =
|
||||||
CRC_Calc_Header(mstp_port->DataRegister,
|
CRC_Calc_Header(mstp_port->DataRegister, mstp_port->HeaderCRC);
|
||||||
mstp_port->HeaderCRC);
|
mstp_port->DestinationAddress = mstp_port->DataRegister;
|
||||||
mstp_port->DestinationAddress = mstp_port->DataRegister; mstp_port->Index = 2;}
|
mstp_port->Index = 2;}
|
||||||
/* Source */
|
/* Source */
|
||||||
else
|
else
|
||||||
if (mstp_port->Index == 2) {
|
if (mstp_port->Index == 2) {
|
||||||
mstp_port->HeaderCRC =
|
mstp_port->HeaderCRC =
|
||||||
CRC_Calc_Header(mstp_port->DataRegister,
|
CRC_Calc_Header(mstp_port->DataRegister, mstp_port->HeaderCRC);
|
||||||
mstp_port->HeaderCRC);
|
mstp_port->SourceAddress = mstp_port->DataRegister;
|
||||||
mstp_port->SourceAddress = mstp_port->DataRegister; mstp_port->Index = 3;}
|
mstp_port->Index = 3;}
|
||||||
/* Length1 */
|
/* Length1 */
|
||||||
else
|
else
|
||||||
if (mstp_port->Index == 3) {
|
if (mstp_port->Index == 3) {
|
||||||
mstp_port->HeaderCRC =
|
mstp_port->HeaderCRC =
|
||||||
CRC_Calc_Header(mstp_port->DataRegister,
|
CRC_Calc_Header(mstp_port->DataRegister, mstp_port->HeaderCRC);
|
||||||
mstp_port->HeaderCRC);
|
mstp_port->DataLength = mstp_port->DataRegister * 256;
|
||||||
mstp_port->DataLength = mstp_port->DataRegister * 256; mstp_port->Index = 4;}
|
mstp_port->Index = 4;}
|
||||||
/* Length2 */
|
/* Length2 */
|
||||||
else
|
else
|
||||||
if (mstp_port->Index == 4) {
|
if (mstp_port->Index == 4) {
|
||||||
mstp_port->HeaderCRC =
|
mstp_port->HeaderCRC =
|
||||||
CRC_Calc_Header(mstp_port->DataRegister,
|
CRC_Calc_Header(mstp_port->DataRegister, mstp_port->HeaderCRC);
|
||||||
mstp_port->HeaderCRC);
|
mstp_port->DataLength += mstp_port->DataRegister;
|
||||||
mstp_port->DataLength += mstp_port->DataRegister; mstp_port->Index = 5;}
|
mstp_port->Index = 5;}
|
||||||
/* HeaderCRC */
|
/* HeaderCRC */
|
||||||
else
|
else
|
||||||
if (mstp_port->Index == 5) {
|
if (mstp_port->Index == 5) {
|
||||||
mstp_port->HeaderCRC =
|
mstp_port->HeaderCRC =
|
||||||
CRC_Calc_Header(mstp_port->DataRegister,
|
CRC_Calc_Header(mstp_port->DataRegister, mstp_port->HeaderCRC);
|
||||||
mstp_port->HeaderCRC); mstp_port->HeaderCRCActual = mstp_port->DataRegister;
|
mstp_port->HeaderCRCActual = mstp_port->DataRegister;
|
||||||
/* don't wait for next state - do it here */
|
/* don't wait for next state - do it here */
|
||||||
/* MSTP_RECEIVE_STATE_HEADER_CRC */
|
/* MSTP_RECEIVE_STATE_HEADER_CRC */
|
||||||
if (mstp_port->HeaderCRC != 0x55) {
|
if (mstp_port->HeaderCRC != 0x55) {
|
||||||
@@ -383,7 +377,8 @@ if (mstp_port->HeaderCRC != 0x55) {
|
|||||||
the reception of a frame */
|
the reception of a frame */
|
||||||
mstp_port->ReceivedInvalidFrame = true;
|
mstp_port->ReceivedInvalidFrame = true;
|
||||||
#if PRINT_ENABLED_RECEIVE_ERRORS
|
#if PRINT_ENABLED_RECEIVE_ERRORS
|
||||||
fprintf(stderr, "MSTP: Rx Header: BadCRC [%02X]\n", mstp_port->DataRegister);
|
fprintf(stderr, "MSTP: Rx Header: BadCRC [%02X]\n",
|
||||||
|
mstp_port->DataRegister);
|
||||||
#endif
|
#endif
|
||||||
/* wait for the start of the next frame. */
|
/* wait for the start of the next frame. */
|
||||||
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;}
|
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;}
|
||||||
@@ -393,7 +388,8 @@ else {
|
|||||||
get confused about the start if the Preamble 55 FF
|
get confused about the start if the Preamble 55 FF
|
||||||
is part of the data. */
|
is part of the data. */
|
||||||
/* Data */
|
/* Data */
|
||||||
if ((mstp_port->DataLength) && (mstp_port->DataLength <= mstp_port->InputBufferSize)) {
|
if ((mstp_port->DataLength) &&
|
||||||
|
(mstp_port->DataLength <= mstp_port->InputBufferSize)) {
|
||||||
/* Data - decode anyway to keep from false */
|
/* Data - decode anyway to keep from false */
|
||||||
mstp_port->Index = 0; mstp_port->DataCRC = 0xFFFF;
|
mstp_port->Index = 0; mstp_port->DataCRC = 0xFFFF;
|
||||||
/* receive the data portion of the frame. */
|
/* receive the data portion of the frame. */
|
||||||
@@ -402,7 +398,8 @@ else {
|
|||||||
/* FrameTooLong */
|
/* FrameTooLong */
|
||||||
if (mstp_port->DataLength) {
|
if (mstp_port->DataLength) {
|
||||||
#if PRINT_ENABLED_RECEIVE_ERRORS
|
#if PRINT_ENABLED_RECEIVE_ERRORS
|
||||||
fprintf(stderr, "MSTP: Rx Header: FrameTooLong %d\n", mstp_port->DataLength);
|
fprintf(stderr, "MSTP: Rx Header: FrameTooLong %d\n",
|
||||||
|
mstp_port->DataLength);
|
||||||
#endif
|
#endif
|
||||||
/* indicate that a frame with an illegal or */
|
/* indicate that a frame with an illegal or */
|
||||||
/* unacceptable data length has been received */
|
/* unacceptable data length has been received */
|
||||||
@@ -411,10 +408,13 @@ mstp_port->ReceivedInvalidFrame = true;}
|
|||||||
else
|
else
|
||||||
if (mstp_port->DataLength == 0) {
|
if (mstp_port->DataLength == 0) {
|
||||||
#if PRINT_ENABLED_RECEIVE_DATA
|
#if PRINT_ENABLED_RECEIVE_DATA
|
||||||
fprintf(stderr, "%s", mstptext_frame_type(mstp_port->FrameType));
|
fprintf(stderr, "%s",
|
||||||
|
mstptext_frame_type(mstp_port->FrameType));
|
||||||
#endif
|
#endif
|
||||||
if ((mstp_port->DestinationAddress == mstp_port->This_Station)
|
if ((mstp_port->DestinationAddress ==
|
||||||
|| (mstp_port->DestinationAddress == MSTP_BROADCAST_ADDRESS)
|
mstp_port->This_Station)
|
||||||
|
|| (mstp_port->DestinationAddress ==
|
||||||
|
MSTP_BROADCAST_ADDRESS)
|
||||||
|| (mstp_port->Lurking)) {
|
|| (mstp_port->Lurking)) {
|
||||||
/* ForUs */
|
/* ForUs */
|
||||||
/* indicate that a frame with no data has been received */
|
/* indicate that a frame with no data has been received */
|
||||||
@@ -434,12 +434,14 @@ mstp_port->ReceiveError = false;
|
|||||||
/* the reception of a frame */
|
/* the reception of a frame */
|
||||||
mstp_port->ReceivedInvalidFrame = true;
|
mstp_port->ReceivedInvalidFrame = true;
|
||||||
#if PRINT_ENABLED_RECEIVE_ERRORS
|
#if PRINT_ENABLED_RECEIVE_ERRORS
|
||||||
fprintf(stderr, "MSTP: Rx Data: BadIndex %d\n", mstp_port->Index);
|
fprintf(stderr, "MSTP: Rx Data: BadIndex %d\n",
|
||||||
|
mstp_port->Index);
|
||||||
#endif
|
#endif
|
||||||
/* wait for the start of a frame. */
|
/* wait for the start of a frame. */
|
||||||
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;}
|
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;}
|
||||||
mstp_port->SilenceTimerReset();
|
mstp_port->SilenceTimerReset();
|
||||||
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); mstp_port->DataAvailable = false;}
|
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);
|
||||||
|
mstp_port->DataAvailable = false;}
|
||||||
break;
|
break;
|
||||||
/* In the HEADER_CRC state, the node validates the CRC on the fixed */
|
/* In the HEADER_CRC state, the node validates the CRC on the fixed */
|
||||||
/* message header. */
|
/* message header. */
|
||||||
@@ -477,23 +479,25 @@ fprintf(stderr, "%02X ", mstp_port->DataRegister);
|
|||||||
#endif
|
#endif
|
||||||
/* DataOctet */
|
/* DataOctet */
|
||||||
if (mstp_port->Index < mstp_port->DataLength) {
|
if (mstp_port->Index < mstp_port->DataLength) {
|
||||||
mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister,
|
mstp_port->DataCRC =
|
||||||
mstp_port->DataCRC);
|
CRC_Calc_Data(mstp_port->DataRegister, mstp_port->DataCRC);
|
||||||
mstp_port->InputBuffer[mstp_port->Index] =
|
mstp_port->InputBuffer[mstp_port->Index] =
|
||||||
mstp_port->DataRegister;
|
mstp_port->DataRegister; mstp_port->Index++;
|
||||||
mstp_port->Index++; mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA;}
|
mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA;}
|
||||||
/* CRC1 */
|
/* CRC1 */
|
||||||
else
|
else
|
||||||
if (mstp_port->Index == mstp_port->DataLength) {
|
if (mstp_port->Index == mstp_port->DataLength) {
|
||||||
mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister,
|
mstp_port->DataCRC =
|
||||||
mstp_port->DataCRC);
|
CRC_Calc_Data(mstp_port->DataRegister, mstp_port->DataCRC);
|
||||||
mstp_port->DataCRCActualMSB = mstp_port->DataRegister;
|
mstp_port->DataCRCActualMSB = mstp_port->DataRegister;
|
||||||
mstp_port->Index++; mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA;}
|
mstp_port->Index++;
|
||||||
|
mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA;}
|
||||||
/* CRC2 */
|
/* CRC2 */
|
||||||
else
|
else
|
||||||
if (mstp_port->Index == (mstp_port->DataLength + 1)) {
|
if (mstp_port->Index == (mstp_port->DataLength + 1)) {
|
||||||
mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister,
|
mstp_port->DataCRC =
|
||||||
mstp_port->DataCRC); mstp_port->DataCRCActualLSB = mstp_port->DataRegister;
|
CRC_Calc_Data(mstp_port->DataRegister, mstp_port->DataCRC);
|
||||||
|
mstp_port->DataCRCActualLSB = mstp_port->DataRegister;
|
||||||
#if PRINT_ENABLED_RECEIVE_DATA
|
#if PRINT_ENABLED_RECEIVE_DATA
|
||||||
fprintf(stderr, "%s", mstptext_frame_type(mstp_port->FrameType));
|
fprintf(stderr, "%s", mstptext_frame_type(mstp_port->FrameType));
|
||||||
#endif
|
#endif
|
||||||
@@ -501,7 +505,8 @@ fprintf(stderr, "%s", mstptext_frame_type(mstp_port->FrameType));
|
|||||||
/* indicate the complete reception of a valid frame */
|
/* indicate the complete reception of a valid frame */
|
||||||
if (mstp_port->DataCRC == 0xF0B8) {
|
if (mstp_port->DataCRC == 0xF0B8) {
|
||||||
if ((mstp_port->DestinationAddress == mstp_port->This_Station)
|
if ((mstp_port->DestinationAddress == mstp_port->This_Station)
|
||||||
|| (mstp_port->DestinationAddress == MSTP_BROADCAST_ADDRESS)
|
|| (mstp_port->DestinationAddress ==
|
||||||
|
MSTP_BROADCAST_ADDRESS)
|
||||||
|| (mstp_port->Lurking)) {
|
|| (mstp_port->Lurking)) {
|
||||||
/* ForUs */
|
/* ForUs */
|
||||||
/* indicate that a frame with no data has been received */
|
/* indicate that a frame with no data has been received */
|
||||||
@@ -513,7 +518,8 @@ else {
|
|||||||
else {
|
else {
|
||||||
mstp_port->ReceivedInvalidFrame = true;
|
mstp_port->ReceivedInvalidFrame = true;
|
||||||
#if PRINT_ENABLED_RECEIVE_ERRORS
|
#if PRINT_ENABLED_RECEIVE_ERRORS
|
||||||
fprintf(stderr, "MSTP: Rx Data: BadCRC [%02X]\n", mstp_port->DataRegister);
|
fprintf(stderr, "MSTP: Rx Data: BadCRC [%02X]\n",
|
||||||
|
mstp_port->DataRegister);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;}
|
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;}
|
||||||
@@ -531,10 +537,8 @@ break; default:
|
|||||||
|
|
||||||
/* returns true if we need to transition immediately */
|
/* returns true if we need to transition immediately */
|
||||||
bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port) {
|
bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port) {
|
||||||
unsigned length = 0;
|
unsigned length = 0; uint8_t next_poll_station = 0;
|
||||||
uint8_t next_poll_station = 0;
|
uint8_t next_this_station = 0; uint8_t next_next_station = 0;
|
||||||
uint8_t next_this_station = 0;
|
|
||||||
uint8_t next_next_station = 0;
|
|
||||||
uint16_t my_timeout = 10, ns_timeout = 0;
|
uint16_t my_timeout = 10, ns_timeout = 0;
|
||||||
/* transition immediately to the next state */
|
/* transition immediately to the next state */
|
||||||
bool transition_now = false;
|
bool transition_now = false;
|
||||||
@@ -542,25 +546,21 @@ break; default:
|
|||||||
static MSTP_MASTER_STATE master_state = MSTP_MASTER_STATE_INITIALIZE;
|
static MSTP_MASTER_STATE master_state = MSTP_MASTER_STATE_INITIALIZE;
|
||||||
#endif
|
#endif
|
||||||
/* some calculations that several states need */
|
/* some calculations that several states need */
|
||||||
next_poll_station = (mstp_port->Poll_Station + 1) %
|
next_poll_station =
|
||||||
(mstp_port->Nmax_master + 1);
|
(mstp_port->Poll_Station + 1) % (mstp_port->Nmax_master + 1);
|
||||||
next_this_station = (mstp_port->This_Station + 1) %
|
next_this_station =
|
||||||
(mstp_port->Nmax_master + 1);
|
(mstp_port->This_Station + 1) % (mstp_port->Nmax_master + 1);
|
||||||
next_next_station = (mstp_port->Next_Station + 1) %
|
next_next_station =
|
||||||
(mstp_port->Nmax_master + 1);
|
(mstp_port->Next_Station + 1) % (mstp_port->Nmax_master + 1);
|
||||||
#if PRINT_ENABLED_MASTER
|
#if PRINT_ENABLED_MASTER
|
||||||
if (mstp_port->master_state != master_state) {
|
if (mstp_port->master_state != master_state) {
|
||||||
master_state = mstp_port->master_state;
|
master_state = mstp_port->master_state;
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"MSTP: TS=%02X[%02X] NS=%02X[%02X] PS=%02X[%02X] EC=%u TC=%u ST=%u %s\n",
|
"MSTP: TS=%02X[%02X] NS=%02X[%02X] PS=%02X[%02X] EC=%u TC=%u ST=%u %s\n",
|
||||||
mstp_port->This_Station,
|
mstp_port->This_Station, next_this_station,
|
||||||
next_this_station,
|
mstp_port->Next_Station, next_next_station,
|
||||||
mstp_port->Next_Station,
|
mstp_port->Poll_Station, next_poll_station,
|
||||||
next_next_station,
|
mstp_port->EventCount, mstp_port->TokenCount,
|
||||||
mstp_port->Poll_Station,
|
|
||||||
next_poll_station,
|
|
||||||
mstp_port->EventCount,
|
|
||||||
mstp_port->TokenCount,
|
|
||||||
mstp_port->SilenceTimer(),
|
mstp_port->SilenceTimer(),
|
||||||
mstptext_master_state(mstp_port->master_state));}
|
mstptext_master_state(mstp_port->master_state));}
|
||||||
#endif
|
#endif
|
||||||
@@ -573,8 +573,7 @@ case MSTP_MASTER_STATE_INITIALIZE:
|
|||||||
mstp_port->Poll_Station = mstp_port->This_Station;
|
mstp_port->Poll_Station = mstp_port->This_Station;
|
||||||
/* cause a Poll For Master to be sent when this node first */
|
/* cause a Poll For Master to be sent when this node first */
|
||||||
/* receives the token */
|
/* receives the token */
|
||||||
mstp_port->TokenCount = Npoll;
|
mstp_port->TokenCount = Npoll; mstp_port->SoleMaster = false;
|
||||||
mstp_port->SoleMaster = false;
|
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
|
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
|
||||||
transition_now = true; break;
|
transition_now = true; break;
|
||||||
/* In the IDLE state, the node waits for a frame. */
|
/* In the IDLE state, the node waits for a frame. */
|
||||||
@@ -597,26 +596,22 @@ case MSTP_MASTER_STATE_IDLE:
|
|||||||
#if PRINT_ENABLED_MASTER
|
#if PRINT_ENABLED_MASTER
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"MSTP: ReceivedValidFrame Src=%02X Dest=%02X DataLen=%u FC=%u ST=%u Type=%s\n",
|
"MSTP: ReceivedValidFrame Src=%02X Dest=%02X DataLen=%u FC=%u ST=%u Type=%s\n",
|
||||||
mstp_port->SourceAddress,
|
mstp_port->SourceAddress, mstp_port->DestinationAddress,
|
||||||
mstp_port->DestinationAddress,
|
mstp_port->DataLength, mstp_port->FrameCount,
|
||||||
mstp_port->DataLength,
|
|
||||||
mstp_port->FrameCount,
|
|
||||||
mstp_port->SilenceTimer(),
|
mstp_port->SilenceTimer(),
|
||||||
mstptext_frame_type(mstp_port->FrameType));
|
mstptext_frame_type(mstp_port->FrameType));
|
||||||
#endif
|
#endif
|
||||||
/* destined for me! */
|
/* destined for me! */
|
||||||
if ((mstp_port->DestinationAddress ==
|
if ((mstp_port->DestinationAddress == mstp_port->This_Station) ||
|
||||||
mstp_port->This_Station) ||
|
|
||||||
(mstp_port->DestinationAddress == MSTP_BROADCAST_ADDRESS)) {
|
(mstp_port->DestinationAddress == MSTP_BROADCAST_ADDRESS)) {
|
||||||
switch (mstp_port->FrameType) {
|
switch (mstp_port->FrameType) {
|
||||||
/* ReceivedToken */
|
/* ReceivedToken */
|
||||||
case FRAME_TYPE_TOKEN:
|
case FRAME_TYPE_TOKEN:
|
||||||
/* tokens can't be broadcast */
|
/* tokens can't be broadcast */
|
||||||
if (mstp_port->DestinationAddress == MSTP_BROADCAST_ADDRESS)
|
if (mstp_port->DestinationAddress ==
|
||||||
break;
|
MSTP_BROADCAST_ADDRESS)
|
||||||
mstp_port->ReceivedValidFrame = false;
|
break; mstp_port->ReceivedValidFrame = false;
|
||||||
mstp_port->FrameCount = 0;
|
mstp_port->FrameCount = 0; mstp_port->SoleMaster = false;
|
||||||
mstp_port->SoleMaster = false;
|
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_USE_TOKEN;
|
mstp_port->master_state = MSTP_MASTER_STATE_USE_TOKEN;
|
||||||
transition_now = true; break;
|
transition_now = true; break;
|
||||||
/* ReceivedPFM */
|
/* ReceivedPFM */
|
||||||
@@ -628,7 +623,8 @@ MSTP_Put_Receive(mstp_port); break; case FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY:
|
|||||||
/* indicate successful reception to the higher layers */
|
/* indicate successful reception to the higher layers */
|
||||||
MSTP_Put_Receive(mstp_port);
|
MSTP_Put_Receive(mstp_port);
|
||||||
/* broadcast DER just remains IDLE */
|
/* broadcast DER just remains IDLE */
|
||||||
if (mstp_port->DestinationAddress != MSTP_BROADCAST_ADDRESS) {
|
if (mstp_port->DestinationAddress !=
|
||||||
|
MSTP_BROADCAST_ADDRESS) {
|
||||||
mstp_port->master_state =
|
mstp_port->master_state =
|
||||||
MSTP_MASTER_STATE_ANSWER_DATA_REQUEST;}
|
MSTP_MASTER_STATE_ANSWER_DATA_REQUEST;}
|
||||||
break; case FRAME_TYPE_TEST_REQUEST:
|
break; case FRAME_TYPE_TEST_REQUEST:
|
||||||
@@ -638,7 +634,8 @@ default:
|
|||||||
}
|
}
|
||||||
/* For DATA_EXPECTING_REPLY, we will keep the Rx Frame for
|
/* For DATA_EXPECTING_REPLY, we will keep the Rx Frame for
|
||||||
reference, and the flag will be cleared in the next state */
|
reference, and the flag will be cleared in the next state */
|
||||||
if (mstp_port->master_state != MSTP_MASTER_STATE_ANSWER_DATA_REQUEST) {
|
if (mstp_port->master_state !=
|
||||||
|
MSTP_MASTER_STATE_ANSWER_DATA_REQUEST) {
|
||||||
mstp_port->ReceivedValidFrame = false;}
|
mstp_port->ReceivedValidFrame = false;}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -650,8 +647,8 @@ case MSTP_MASTER_STATE_USE_TOKEN:
|
|||||||
length = MSTP_Get_Send(mstp_port, 0); if (length < 1) {
|
length = MSTP_Get_Send(mstp_port, 0); if (length < 1) {
|
||||||
/* NothingToSend */
|
/* NothingToSend */
|
||||||
mstp_port->FrameCount = mstp_port->Nmax_info_frames;
|
mstp_port->FrameCount = mstp_port->Nmax_info_frames;
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN;
|
mstp_port->master_state =
|
||||||
transition_now = true;}
|
MSTP_MASTER_STATE_DONE_WITH_TOKEN; transition_now = true;}
|
||||||
else {
|
else {
|
||||||
uint8_t frame_type = mstp_port->OutputBuffer[2];
|
uint8_t frame_type = mstp_port->OutputBuffer[2];
|
||||||
uint8_t destination = mstp_port->OutputBuffer[3];
|
uint8_t destination = mstp_port->OutputBuffer[3];
|
||||||
@@ -661,14 +658,16 @@ case MSTP_MASTER_STATE_USE_TOKEN:
|
|||||||
case FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY:
|
case FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY:
|
||||||
/* SendAndWait */
|
/* SendAndWait */
|
||||||
if (destination == MSTP_BROADCAST_ADDRESS)
|
if (destination == MSTP_BROADCAST_ADDRESS)
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN;
|
mstp_port->master_state =
|
||||||
|
MSTP_MASTER_STATE_DONE_WITH_TOKEN;
|
||||||
else
|
else
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_WAIT_FOR_REPLY; break; case FRAME_TYPE_TEST_REQUEST:
|
mstp_port->master_state = MSTP_MASTER_STATE_WAIT_FOR_REPLY; break; case FRAME_TYPE_TEST_REQUEST:
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_WAIT_FOR_REPLY; break; case FRAME_TYPE_TEST_RESPONSE:
|
mstp_port->master_state = MSTP_MASTER_STATE_WAIT_FOR_REPLY; break; case FRAME_TYPE_TEST_RESPONSE:
|
||||||
case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY:
|
case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY:
|
||||||
default:
|
default:
|
||||||
/* SendNoWait */
|
/* SendNoWait */
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN; break;}
|
mstp_port->master_state =
|
||||||
|
MSTP_MASTER_STATE_DONE_WITH_TOKEN; break;}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
/* In the WAIT_FOR_REPLY state, the node waits for */
|
/* In the WAIT_FOR_REPLY state, the node waits for */
|
||||||
@@ -705,7 +704,8 @@ mstp_port->master_state = MSTP_MASTER_STATE_IDLE; break; case FRAME_TYPE_BACNET_
|
|||||||
MSTP_Put_Receive(mstp_port); mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN; break; default:
|
MSTP_Put_Receive(mstp_port); mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN; break; default:
|
||||||
/* if proprietary frame was expected, you might
|
/* if proprietary frame was expected, you might
|
||||||
need to transition to DONE WITH TOKEN */
|
need to transition to DONE WITH TOKEN */
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_IDLE; break;}
|
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
|
||||||
|
break;}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* ReceivedUnexpectedFrame */
|
/* ReceivedUnexpectedFrame */
|
||||||
@@ -734,8 +734,7 @@ if (mstp_port->TokenCount < (Npoll - 1)) {
|
|||||||
/* SoleMaster */
|
/* SoleMaster */
|
||||||
/* there are no other known master nodes to */
|
/* there are no other known master nodes to */
|
||||||
/* which the token may be sent (true master-slave operation). */
|
/* which the token may be sent (true master-slave operation). */
|
||||||
mstp_port->FrameCount = 0;
|
mstp_port->FrameCount = 0; mstp_port->TokenCount++;
|
||||||
mstp_port->TokenCount++;
|
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_USE_TOKEN;
|
mstp_port->master_state = MSTP_MASTER_STATE_USE_TOKEN;
|
||||||
transition_now = true;}
|
transition_now = true;}
|
||||||
else {
|
else {
|
||||||
@@ -746,11 +745,9 @@ if (mstp_port->TokenCount < (Npoll - 1)) {
|
|||||||
/* address at which a new master node may be found in that case. */
|
/* address at which a new master node may be found in that case. */
|
||||||
mstp_port->TokenCount++;
|
mstp_port->TokenCount++;
|
||||||
/* transmit a Token frame to NS */
|
/* transmit a Token frame to NS */
|
||||||
MSTP_Create_And_Send_Frame(mstp_port,
|
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
|
||||||
FRAME_TYPE_TOKEN,
|
mstp_port->Next_Station, mstp_port->This_Station, NULL,
|
||||||
mstp_port->Next_Station,
|
0); mstp_port->RetryCount = 0;
|
||||||
mstp_port->This_Station, NULL, 0);
|
|
||||||
mstp_port->RetryCount = 0;
|
|
||||||
mstp_port->EventCount = 0;
|
mstp_port->EventCount = 0;
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN;}
|
mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN;}
|
||||||
}
|
}
|
||||||
@@ -779,8 +776,8 @@ else {
|
|||||||
/* SendMaintenancePFM */
|
/* SendMaintenancePFM */
|
||||||
mstp_port->Poll_Station = next_poll_station;
|
mstp_port->Poll_Station = next_poll_station;
|
||||||
MSTP_Create_And_Send_Frame(mstp_port,
|
MSTP_Create_And_Send_Frame(mstp_port,
|
||||||
FRAME_TYPE_POLL_FOR_MASTER,
|
FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
|
||||||
mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0);
|
mstp_port->This_Station, NULL, 0);
|
||||||
mstp_port->RetryCount = 0;
|
mstp_port->RetryCount = 0;
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER;}
|
mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER;}
|
||||||
break;
|
break;
|
||||||
@@ -792,15 +789,15 @@ if (mstp_port->EventCount > Nmin_octets) {
|
|||||||
/* SawTokenUser */
|
/* SawTokenUser */
|
||||||
/* Assume that a frame has been sent by the new token user. */
|
/* Assume that a frame has been sent by the new token user. */
|
||||||
/* Enter the IDLE state to process the frame. */
|
/* Enter the IDLE state to process the frame. */
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_IDLE; transition_now = true;}
|
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
|
||||||
|
transition_now = true;}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (mstp_port->RetryCount < Nretry_token) {
|
if (mstp_port->RetryCount < Nretry_token) {
|
||||||
/* RetrySendToken */
|
/* RetrySendToken */
|
||||||
mstp_port->RetryCount++;
|
mstp_port->RetryCount++;
|
||||||
/* Transmit a Token frame to NS */
|
/* Transmit a Token frame to NS */
|
||||||
MSTP_Create_And_Send_Frame(mstp_port,
|
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
|
||||||
FRAME_TYPE_TOKEN,
|
|
||||||
mstp_port->Next_Station, mstp_port->This_Station, NULL,
|
mstp_port->Next_Station, mstp_port->This_Station, NULL,
|
||||||
0); mstp_port->EventCount = 0;
|
0); mstp_port->EventCount = 0;
|
||||||
/* re-enter the current state to listen for NS */
|
/* re-enter the current state to listen for NS */
|
||||||
@@ -812,14 +809,15 @@ else {
|
|||||||
mstp_port->Poll_Station = next_next_station;
|
mstp_port->Poll_Station = next_next_station;
|
||||||
/* Transmit a Poll For Master frame to PS. */
|
/* Transmit a Poll For Master frame to PS. */
|
||||||
MSTP_Create_And_Send_Frame(mstp_port,
|
MSTP_Create_And_Send_Frame(mstp_port,
|
||||||
FRAME_TYPE_POLL_FOR_MASTER,
|
FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
|
||||||
mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0);
|
mstp_port->This_Station, NULL, 0);
|
||||||
/* no known successor node */
|
/* no known successor node */
|
||||||
mstp_port->Next_Station = mstp_port->This_Station;
|
mstp_port->Next_Station = mstp_port->This_Station;
|
||||||
mstp_port->RetryCount = 0; mstp_port->TokenCount = 0;
|
mstp_port->RetryCount = 0; mstp_port->TokenCount = 0;
|
||||||
/* mstp_port->EventCount = 0; removed in Addendum 135-2004d-8 */
|
/* mstp_port->EventCount = 0; removed in Addendum 135-2004d-8 */
|
||||||
/* find a new successor to TS */
|
/* find a new successor to TS */
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER;}
|
mstp_port->master_state =
|
||||||
|
MSTP_MASTER_STATE_POLL_FOR_MASTER;}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
/* The NO_TOKEN state is entered if mstp_port->SilenceTimer() becomes greater */
|
/* The NO_TOKEN state is entered if mstp_port->SilenceTimer() becomes greater */
|
||||||
@@ -833,7 +831,8 @@ if (mstp_port->EventCount > Nmin_octets) {
|
|||||||
/* SawFrame */
|
/* SawFrame */
|
||||||
/* Some other node exists at a lower address. */
|
/* Some other node exists at a lower address. */
|
||||||
/* Enter the IDLE state to receive and process the incoming frame. */
|
/* Enter the IDLE state to receive and process the incoming frame. */
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_IDLE; transition_now = true;}
|
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
|
||||||
|
transition_now = true;}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ns_timeout =
|
ns_timeout =
|
||||||
@@ -845,14 +844,15 @@ if (mstp_port->SilenceTimer() < ns_timeout) {
|
|||||||
mstp_port->Poll_Station = next_this_station;
|
mstp_port->Poll_Station = next_this_station;
|
||||||
/* Transmit a Poll For Master frame to PS. */
|
/* Transmit a Poll For Master frame to PS. */
|
||||||
MSTP_Create_And_Send_Frame(mstp_port,
|
MSTP_Create_And_Send_Frame(mstp_port,
|
||||||
FRAME_TYPE_POLL_FOR_MASTER,
|
FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station,
|
||||||
mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0);
|
mstp_port->This_Station, NULL, 0);
|
||||||
/* indicate that the next station is unknown */
|
/* indicate that the next station is unknown */
|
||||||
mstp_port->Next_Station = mstp_port->This_Station;
|
mstp_port->Next_Station = mstp_port->This_Station;
|
||||||
mstp_port->RetryCount = 0; mstp_port->TokenCount = 0;
|
mstp_port->RetryCount = 0; mstp_port->TokenCount = 0;
|
||||||
/* mstp_port->EventCount = 0; removed Addendum 135-2004d-8 */
|
/* mstp_port->EventCount = 0; removed Addendum 135-2004d-8 */
|
||||||
/* enter the POLL_FOR_MASTER state to find a new successor to TS. */
|
/* enter the POLL_FOR_MASTER state to find a new successor to TS. */
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER;}
|
mstp_port->master_state =
|
||||||
|
MSTP_MASTER_STATE_POLL_FOR_MASTER;}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
/* In the POLL_FOR_MASTER state, the node listens for a reply to */
|
/* In the POLL_FOR_MASTER state, the node listens for a reply to */
|
||||||
@@ -861,19 +861,18 @@ break;
|
|||||||
case MSTP_MASTER_STATE_POLL_FOR_MASTER:
|
case MSTP_MASTER_STATE_POLL_FOR_MASTER:
|
||||||
if (mstp_port->ReceivedValidFrame == true) {
|
if (mstp_port->ReceivedValidFrame == true) {
|
||||||
if ((mstp_port->DestinationAddress == mstp_port->This_Station)
|
if ((mstp_port->DestinationAddress == mstp_port->This_Station)
|
||||||
&& (mstp_port->FrameType == FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER)) {
|
&& (mstp_port->FrameType ==
|
||||||
|
FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER)) {
|
||||||
/* ReceivedReplyToPFM */
|
/* ReceivedReplyToPFM */
|
||||||
mstp_port->SoleMaster = false;
|
mstp_port->SoleMaster = false;
|
||||||
mstp_port->Next_Station = mstp_port->SourceAddress;
|
mstp_port->Next_Station = mstp_port->SourceAddress;
|
||||||
mstp_port->EventCount = 0;
|
mstp_port->EventCount = 0;
|
||||||
/* Transmit a Token frame to NS */
|
/* Transmit a Token frame to NS */
|
||||||
MSTP_Create_And_Send_Frame(mstp_port,
|
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
|
||||||
FRAME_TYPE_TOKEN,
|
mstp_port->Next_Station, mstp_port->This_Station,
|
||||||
mstp_port->Next_Station, mstp_port->This_Station, NULL,
|
NULL, 0);
|
||||||
0);
|
|
||||||
mstp_port->Poll_Station = mstp_port->This_Station;
|
mstp_port->Poll_Station = mstp_port->This_Station;
|
||||||
mstp_port->TokenCount = 0;
|
mstp_port->TokenCount = 0; mstp_port->RetryCount = 0;
|
||||||
mstp_port->RetryCount = 0;
|
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN;}
|
mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN;}
|
||||||
else {
|
else {
|
||||||
/* ReceivedUnexpectedFrame */
|
/* ReceivedUnexpectedFrame */
|
||||||
@@ -881,7 +880,8 @@ else {
|
|||||||
/* This may indicate the presence of multiple tokens. */
|
/* This may indicate the presence of multiple tokens. */
|
||||||
/* enter the IDLE state to synchronize with the network. */
|
/* enter the IDLE state to synchronize with the network. */
|
||||||
/* This action drops the token. */
|
/* This action drops the token. */
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_IDLE; transition_now = true;}
|
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;
|
||||||
|
transition_now = true;}
|
||||||
mstp_port->ReceivedValidFrame = false;}
|
mstp_port->ReceivedValidFrame = false;}
|
||||||
else
|
else
|
||||||
if ((mstp_port->SilenceTimer() > Tusage_timeout) ||
|
if ((mstp_port->SilenceTimer() > Tusage_timeout) ||
|
||||||
@@ -892,7 +892,8 @@ if (mstp_port->SoleMaster == true) {
|
|||||||
/* by the sole known master for other masters. */
|
/* by the sole known master for other masters. */
|
||||||
mstp_port->FrameCount = 0;
|
mstp_port->FrameCount = 0;
|
||||||
/* mstp_port->TokenCount++; removed in 2004 */
|
/* mstp_port->TokenCount++; removed in 2004 */
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_USE_TOKEN; transition_now = true;}
|
mstp_port->master_state = MSTP_MASTER_STATE_USE_TOKEN;
|
||||||
|
transition_now = true;}
|
||||||
else {
|
else {
|
||||||
if (mstp_port->Next_Station != mstp_port->This_Station) {
|
if (mstp_port->Next_Station != mstp_port->This_Station) {
|
||||||
/* DoneWithPFM */
|
/* DoneWithPFM */
|
||||||
@@ -900,11 +901,9 @@ if (mstp_port->Next_Station != mstp_port->This_Station) {
|
|||||||
/* poll for a master at address PS. */
|
/* poll for a master at address PS. */
|
||||||
mstp_port->EventCount = 0;
|
mstp_port->EventCount = 0;
|
||||||
/* transmit a Token frame to NS */
|
/* transmit a Token frame to NS */
|
||||||
MSTP_Create_And_Send_Frame(mstp_port,
|
MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN,
|
||||||
FRAME_TYPE_TOKEN,
|
|
||||||
mstp_port->Next_Station, mstp_port->This_Station,
|
mstp_port->Next_Station, mstp_port->This_Station,
|
||||||
NULL, 0);
|
NULL, 0); mstp_port->RetryCount = 0;
|
||||||
mstp_port->RetryCount = 0;
|
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN;}
|
mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN;}
|
||||||
else {
|
else {
|
||||||
if (next_poll_station != mstp_port->This_Station) {
|
if (next_poll_station != mstp_port->This_Station) {
|
||||||
@@ -913,8 +912,8 @@ else {
|
|||||||
/* Transmit a Poll For Master frame to PS. */
|
/* Transmit a Poll For Master frame to PS. */
|
||||||
MSTP_Create_And_Send_Frame(mstp_port,
|
MSTP_Create_And_Send_Frame(mstp_port,
|
||||||
FRAME_TYPE_POLL_FOR_MASTER,
|
FRAME_TYPE_POLL_FOR_MASTER,
|
||||||
mstp_port->Poll_Station,
|
mstp_port->Poll_Station, mstp_port->This_Station,
|
||||||
mstp_port->This_Station, NULL, 0); mstp_port->RetryCount = 0;
|
NULL, 0); mstp_port->RetryCount = 0;
|
||||||
/* Re-enter the current state. */
|
/* Re-enter the current state. */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -942,8 +941,8 @@ length = MSTP_Get_Reply(mstp_port, 0); if (length > 0) {
|
|||||||
/* then call MSTP_Create_And_Send_Frame to transmit the reply frame */
|
/* then call MSTP_Create_And_Send_Frame to transmit the reply frame */
|
||||||
/* and enter the IDLE state to wait for the next frame. */
|
/* and enter the IDLE state to wait for the next frame. */
|
||||||
RS485_Send_Frame(mstp_port,
|
RS485_Send_Frame(mstp_port,
|
||||||
(uint8_t *) & mstp_port->OutputBuffer[0],
|
(uint8_t *) & mstp_port->OutputBuffer[0], length);
|
||||||
length); mstp_port->master_state = MSTP_MASTER_STATE_IDLE;}
|
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;}
|
||||||
else {
|
else {
|
||||||
/* DeferredReply */
|
/* DeferredReply */
|
||||||
/* If no reply will be available from the higher layers */
|
/* If no reply will be available from the higher layers */
|
||||||
@@ -955,8 +954,7 @@ else {
|
|||||||
/* Call MSTP_Create_And_Send_Frame to transmit a Reply Postponed frame, */
|
/* Call MSTP_Create_And_Send_Frame to transmit a Reply Postponed frame, */
|
||||||
/* and enter the IDLE state. */
|
/* and enter the IDLE state. */
|
||||||
MSTP_Create_And_Send_Frame(mstp_port,
|
MSTP_Create_And_Send_Frame(mstp_port,
|
||||||
FRAME_TYPE_REPLY_POSTPONED,
|
FRAME_TYPE_REPLY_POSTPONED, mstp_port->SourceAddress,
|
||||||
mstp_port->SourceAddress,
|
|
||||||
mstp_port->This_Station, NULL, 0);
|
mstp_port->This_Station, NULL, 0);
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;}
|
mstp_port->master_state = MSTP_MASTER_STATE_IDLE;}
|
||||||
/* clear our flag we were holding for comparison */
|
/* clear our flag we were holding for comparison */
|
||||||
@@ -975,28 +973,20 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
if (mstp_port) {
|
if (mstp_port) {
|
||||||
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;
|
mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE;
|
||||||
mstp_port->master_state = MSTP_MASTER_STATE_INITIALIZE;
|
mstp_port->master_state = MSTP_MASTER_STATE_INITIALIZE;
|
||||||
mstp_port->ReceiveError = false;
|
mstp_port->ReceiveError = false; mstp_port->DataAvailable = false;
|
||||||
mstp_port->DataAvailable = false;
|
mstp_port->DataRegister = 0; mstp_port->DataCRC = 0;
|
||||||
mstp_port->DataRegister = 0;
|
mstp_port->DataCRC = 0; mstp_port->DataLength = 0;
|
||||||
mstp_port->DataCRC = 0;
|
mstp_port->DestinationAddress = 0; mstp_port->EventCount = 0;
|
||||||
mstp_port->DataCRC = 0;
|
mstp_port->FrameType = FRAME_TYPE_TOKEN; mstp_port->FrameCount = 0;
|
||||||
mstp_port->DataLength = 0;
|
mstp_port->HeaderCRC = 0; mstp_port->Index = 0;
|
||||||
mstp_port->DestinationAddress = 0;
|
|
||||||
mstp_port->EventCount = 0;
|
|
||||||
mstp_port->FrameType = FRAME_TYPE_TOKEN;
|
|
||||||
mstp_port->FrameCount = 0;
|
|
||||||
mstp_port->HeaderCRC = 0;
|
|
||||||
mstp_port->Index = 0;
|
|
||||||
mstp_port->Index = 0;
|
mstp_port->Index = 0;
|
||||||
mstp_port->Next_Station = mstp_port->This_Station;
|
mstp_port->Next_Station = mstp_port->This_Station;
|
||||||
mstp_port->Poll_Station = mstp_port->This_Station;
|
mstp_port->Poll_Station = mstp_port->This_Station;
|
||||||
mstp_port->ReceivedInvalidFrame = false;
|
mstp_port->ReceivedInvalidFrame = false;
|
||||||
mstp_port->ReceivedValidFrame = false;
|
mstp_port->ReceivedValidFrame = false; mstp_port->RetryCount = 0;
|
||||||
mstp_port->RetryCount = 0;
|
mstp_port->SilenceTimerReset(); mstp_port->SoleMaster = false;
|
||||||
mstp_port->SilenceTimerReset();
|
mstp_port->SourceAddress = 0; mstp_port->TokenCount = 0;
|
||||||
mstp_port->SoleMaster = false;
|
mstp_port->Lurking = false;
|
||||||
mstp_port->SourceAddress = 0;
|
|
||||||
mstp_port->TokenCount = 0; mstp_port->Lurking = false;
|
|
||||||
#if 0
|
#if 0
|
||||||
/* FIXME: you must point these buffers to actual byte buckets
|
/* FIXME: you must point these buffers to actual byte buckets
|
||||||
in the dlmstp function before or after calling this init. */
|
in the dlmstp function before or after calling this init. */
|
||||||
@@ -1036,8 +1026,7 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
static bool initialized = false; /* tracks our init */
|
static bool initialized = false; /* tracks our init */
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
initialized = true;
|
initialized = true;
|
||||||
Ringbuf_Init(&Test_Buffer,
|
Ringbuf_Init(&Test_Buffer, (char *) Test_Buffer_Data,
|
||||||
(char *) Test_Buffer_Data,
|
|
||||||
RING_BUFFER_DATA_SIZE, RING_BUFFER_SIZE);}
|
RING_BUFFER_DATA_SIZE, RING_BUFFER_SIZE);}
|
||||||
/* empty any the existing data */
|
/* empty any the existing data */
|
||||||
while (!Ringbuf_Empty(&Test_Buffer)) {
|
while (!Ringbuf_Empty(&Test_Buffer)) {
|
||||||
@@ -1045,8 +1034,8 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
|
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
while (len) {
|
while (len) {
|
||||||
(void) Ringbuf_Put(&Test_Buffer, (char *) buffer);
|
(void) Ringbuf_Put(&Test_Buffer, (char *) buffer); len--;
|
||||||
len--; buffer++;}
|
buffer++;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1086,30 +1075,25 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
size_t i; /* used to loop through the message bytes */
|
size_t i; /* used to loop through the message bytes */
|
||||||
uint8_t buffer[MAX_MPDU] = {
|
uint8_t buffer[MAX_MPDU] = {
|
||||||
0}; uint8_t data[MAX_PDU] = {
|
0}; uint8_t data[MAX_PDU] = {
|
||||||
0};
|
0}; mstp_port.InputBuffer = &RxBuffer[0];
|
||||||
mstp_port.InputBuffer = &RxBuffer[0];
|
|
||||||
mstp_port.InputBufferSize = sizeof(RxBuffer);
|
mstp_port.InputBufferSize = sizeof(RxBuffer);
|
||||||
mstp_port.OutputBuffer = &TxBuffer[0];
|
mstp_port.OutputBuffer = &TxBuffer[0];
|
||||||
mstp_port.OutputBufferSize = sizeof(TxBuffer);
|
mstp_port.OutputBufferSize = sizeof(TxBuffer);
|
||||||
mstp_port.SilenceTimer = Timer_Silence;
|
mstp_port.SilenceTimer = Timer_Silence;
|
||||||
mstp_port.SilenceTimerReset = Timer_Silence_Reset;
|
mstp_port.SilenceTimerReset = Timer_Silence_Reset;
|
||||||
mstp_port.This_Station = my_mac;
|
mstp_port.This_Station = my_mac; mstp_port.Nmax_info_frames = 1;
|
||||||
mstp_port.Nmax_info_frames = 1;
|
|
||||||
mstp_port.Nmax_master = 127; MSTP_Init(&mstp_port);
|
mstp_port.Nmax_master = 127; MSTP_Init(&mstp_port);
|
||||||
/* check the receive error during idle */
|
/* check the receive error during idle */
|
||||||
mstp_port.receive_state = MSTP_RECEIVE_STATE_IDLE;
|
mstp_port.receive_state = MSTP_RECEIVE_STATE_IDLE;
|
||||||
mstp_port.ReceiveError = true;
|
mstp_port.ReceiveError = true; SilenceTime = 255;
|
||||||
SilenceTime = 255;
|
mstp_port.EventCount = 0; INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
mstp_port.EventCount = 0;
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||||
ct_test(pTest, mstp_port.ReceiveError == false);
|
ct_test(pTest, mstp_port.ReceiveError == false);
|
||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||||
/* check for bad packet header */
|
/* check for bad packet header */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x11;
|
||||||
mstp_port.DataRegister = 0x11;
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||||
@@ -1117,8 +1101,7 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||||
/* check for good packet header, but timeout */
|
/* check for good packet header, but timeout */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x55;
|
||||||
mstp_port.DataRegister = 0x55;
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||||
@@ -1126,12 +1109,10 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||||
/* force the timeout */
|
/* force the timeout */
|
||||||
SilenceTime = Tframe_abort + 1;
|
SilenceTime = Tframe_abort + 1; MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
|
||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||||
/* check for good packet header preamble, but receive error */
|
/* check for good packet header preamble, but receive error */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x55;
|
||||||
mstp_port.DataRegister = 0x55;
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||||
@@ -1139,16 +1120,14 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||||
/* force the error */
|
/* force the error */
|
||||||
mstp_port.ReceiveError = true;
|
mstp_port.ReceiveError = true; INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.ReceiveError == false);
|
ct_test(pTest, mstp_port.ReceiveError == false);
|
||||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||||
/* check for good packet header preamble1, but bad preamble2 */
|
/* check for good packet header preamble1, but bad preamble2 */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x55;
|
||||||
mstp_port.DataRegister = 0x55;
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||||
@@ -1162,8 +1141,7 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||||
/* repeated preamble1 */
|
/* repeated preamble1 */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x55;
|
||||||
mstp_port.DataRegister = 0x55;
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||||
@@ -1171,8 +1149,7 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||||
/* repeated preamble1 */
|
/* repeated preamble1 */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x55;
|
||||||
mstp_port.DataRegister = 0x55;
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||||
@@ -1180,8 +1157,7 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||||
/* bad data */
|
/* bad data */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x11;
|
||||||
mstp_port.DataRegister = 0x11;
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.ReceiveError == false);
|
ct_test(pTest, mstp_port.ReceiveError == false);
|
||||||
@@ -1189,8 +1165,7 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||||
/* check for good packet header preamble, but timeout in packet */
|
/* check for good packet header preamble, but timeout in packet */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x55;
|
||||||
mstp_port.DataRegister = 0x55;
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||||
@@ -1199,8 +1174,7 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
/* preamble2 */
|
/* preamble2 */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = 0xFF;
|
||||||
mstp_port.DataRegister = 0xFF;
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||||
@@ -1210,13 +1184,11 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
ct_test(pTest, mstp_port.HeaderCRC == 0xFF);
|
ct_test(pTest, mstp_port.HeaderCRC == 0xFF);
|
||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
||||||
/* force the timeout */
|
/* force the timeout */
|
||||||
SilenceTime = Tframe_abort + 1;
|
SilenceTime = Tframe_abort + 1; MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
|
||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||||
ct_test(pTest, mstp_port.ReceivedInvalidFrame == true);
|
ct_test(pTest, mstp_port.ReceivedInvalidFrame == true);
|
||||||
/* check for good packet header preamble, but error in packet */
|
/* check for good packet header preamble, but error in packet */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x55;
|
||||||
mstp_port.DataRegister = 0x55;
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||||
@@ -1225,8 +1197,7 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
/* preamble2 */
|
/* preamble2 */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = 0xFF;
|
||||||
mstp_port.DataRegister = 0xFF;
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||||
@@ -1236,16 +1207,14 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
ct_test(pTest, mstp_port.HeaderCRC == 0xFF);
|
ct_test(pTest, mstp_port.HeaderCRC == 0xFF);
|
||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
||||||
/* force the error */
|
/* force the error */
|
||||||
mstp_port.ReceiveError = true;
|
mstp_port.ReceiveError = true; INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.ReceiveError == false);
|
ct_test(pTest, mstp_port.ReceiveError == false);
|
||||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||||
/* check for good packet header preamble */
|
/* check for good packet header preamble */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x55;
|
||||||
mstp_port.DataRegister = 0x55;
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||||
@@ -1254,8 +1223,7 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
/* preamble2 */
|
/* preamble2 */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = 0xFF;
|
||||||
mstp_port.DataRegister = 0xFF;
|
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
ct_test(pTest, mstp_port.DataAvailable == false);
|
ct_test(pTest, mstp_port.DataAvailable == false);
|
||||||
@@ -1272,8 +1240,7 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
/* Data is received - index is incremented */
|
/* Data is received - index is incremented */
|
||||||
/* FrameType */
|
/* FrameType */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true;
|
||||||
mstp_port.DataRegister = FRAME_TYPE_TOKEN;
|
mstp_port.DataRegister = FRAME_TYPE_TOKEN; HeaderCRC = 0xFF;
|
||||||
HeaderCRC = 0xFF;
|
|
||||||
HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC);
|
HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC);
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
@@ -1284,8 +1251,7 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
||||||
ct_test(pTest, FrameType == FRAME_TYPE_TOKEN);
|
ct_test(pTest, FrameType == FRAME_TYPE_TOKEN);
|
||||||
/* Destination */
|
/* Destination */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = 0x10;
|
||||||
mstp_port.DataRegister = 0x10;
|
|
||||||
HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC);
|
HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC);
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
@@ -1296,8 +1262,7 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
||||||
ct_test(pTest, mstp_port.DestinationAddress == 0x10);
|
ct_test(pTest, mstp_port.DestinationAddress == 0x10);
|
||||||
/* Source */
|
/* Source */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = my_mac;
|
||||||
mstp_port.DataRegister = my_mac;
|
|
||||||
HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC);
|
HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC);
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
@@ -1308,8 +1273,7 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
||||||
ct_test(pTest, mstp_port.SourceAddress == my_mac);
|
ct_test(pTest, mstp_port.SourceAddress == my_mac);
|
||||||
/* Length1 = length*256 */
|
/* Length1 = length*256 */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = 0;
|
||||||
mstp_port.DataRegister = 0;
|
|
||||||
HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC);
|
HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC);
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
@@ -1320,8 +1284,7 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
|
||||||
ct_test(pTest, mstp_port.DataLength == 0);
|
ct_test(pTest, mstp_port.DataLength == 0);
|
||||||
/* Length2 */
|
/* Length2 */
|
||||||
mstp_port.DataAvailable = true;
|
mstp_port.DataAvailable = true; mstp_port.DataRegister = 0;
|
||||||
mstp_port.DataRegister = 0;
|
|
||||||
HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC);
|
HeaderCRC = CRC_Calc_Header(mstp_port.DataRegister, HeaderCRC);
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
@@ -1340,8 +1303,7 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
ct_test(pTest, mstp_port.SilenceTimer() == 0);
|
||||||
ct_test(pTest, mstp_port.EventCount == EventCount);
|
ct_test(pTest, mstp_port.EventCount == EventCount);
|
||||||
ct_test(pTest, mstp_port.Index == 5);
|
ct_test(pTest, mstp_port.Index == 5);
|
||||||
ct_test(pTest,
|
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
||||||
mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
|
|
||||||
ct_test(pTest, mstp_port.HeaderCRC == 0x55);
|
ct_test(pTest, mstp_port.HeaderCRC == 0x55);
|
||||||
/* BadCRC in header check */
|
/* BadCRC in header check */
|
||||||
mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedValidFrame = false; len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, 0x10, /* destination */
|
mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedValidFrame = false; len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, 0x10, /* destination */
|
||||||
@@ -1350,8 +1312,8 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
0); /* data size */
|
0); /* data size */
|
||||||
ct_test(pTest, len > 0);
|
ct_test(pTest, len > 0);
|
||||||
/* make the header CRC bad */
|
/* make the header CRC bad */
|
||||||
buffer[7] = 0x00;
|
buffer[7] = 0x00; Load_Input_Buffer(buffer, len); for (i = 0; i < len;
|
||||||
Load_Input_Buffer(buffer, len); for (i = 0; i < len; i++) {
|
i++) {
|
||||||
RS485_Check_UART_Data(&mstp_port);
|
RS485_Check_UART_Data(&mstp_port);
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
@@ -1366,8 +1328,8 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
my_mac, /* source */
|
my_mac, /* source */
|
||||||
NULL, /* data */
|
NULL, /* data */
|
||||||
0); /* data size */
|
0); /* data size */
|
||||||
ct_test(pTest, len > 0);
|
ct_test(pTest, len > 0); Load_Input_Buffer(buffer, len); for (i = 0;
|
||||||
Load_Input_Buffer(buffer, len); for (i = 0; i < len; i++) {
|
i < len; i++) {
|
||||||
RS485_Check_UART_Data(&mstp_port);
|
RS485_Check_UART_Data(&mstp_port);
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
@@ -1384,8 +1346,8 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
0); /* data size */
|
0); /* data size */
|
||||||
ct_test(pTest, len > 0);
|
ct_test(pTest, len > 0);
|
||||||
/* make the header data length bad */
|
/* make the header data length bad */
|
||||||
buffer[5] = 0x02;
|
buffer[5] = 0x02; Load_Input_Buffer(buffer, len); for (i = 0; i < len;
|
||||||
Load_Input_Buffer(buffer, len); for (i = 0; i < len; i++) {
|
i++) {
|
||||||
RS485_Check_UART_Data(&mstp_port);
|
RS485_Check_UART_Data(&mstp_port);
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
@@ -1400,10 +1362,8 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
my_mac, /* source */
|
my_mac, /* source */
|
||||||
data, /* data */
|
data, /* data */
|
||||||
sizeof(data)); /* data size */
|
sizeof(data)); /* data size */
|
||||||
ct_test(pTest, len > 0);
|
ct_test(pTest, len > 0); Load_Input_Buffer(buffer, len);
|
||||||
Load_Input_Buffer(buffer, len);
|
RS485_Check_UART_Data(&mstp_port); MSTP_Receive_Frame_FSM(&mstp_port);
|
||||||
RS485_Check_UART_Data(&mstp_port);
|
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);
|
|
||||||
while (mstp_port.receive_state != MSTP_RECEIVE_STATE_IDLE) {
|
while (mstp_port.receive_state != MSTP_RECEIVE_STATE_IDLE) {
|
||||||
RS485_Check_UART_Data(&mstp_port);
|
RS485_Check_UART_Data(&mstp_port);
|
||||||
MSTP_Receive_Frame_FSM(&mstp_port);}
|
MSTP_Receive_Frame_FSM(&mstp_port);}
|
||||||
@@ -1420,10 +1380,8 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
MSTP_Port.InputBufferSize = sizeof(RxBuffer);
|
MSTP_Port.InputBufferSize = sizeof(RxBuffer);
|
||||||
MSTP_Port.OutputBuffer = &TxBuffer[0];
|
MSTP_Port.OutputBuffer = &TxBuffer[0];
|
||||||
MSTP_Port.OutputBufferSize = sizeof(TxBuffer);
|
MSTP_Port.OutputBufferSize = sizeof(TxBuffer);
|
||||||
MSTP_Port.This_Station = my_mac;
|
MSTP_Port.This_Station = my_mac; MSTP_Port.Nmax_info_frames = 1;
|
||||||
MSTP_Port.Nmax_info_frames = 1;
|
MSTP_Port.Nmax_master = 127; MSTP_Port.SilenceTimer = Timer_Silence;
|
||||||
MSTP_Port.Nmax_master = 127;
|
|
||||||
MSTP_Port.SilenceTimer = Timer_Silence;
|
|
||||||
MSTP_Port.SilenceTimerReset = Timer_Silence_Reset;
|
MSTP_Port.SilenceTimerReset = Timer_Silence_Reset;
|
||||||
MSTP_Init(&MSTP_Port);
|
MSTP_Init(&MSTP_Port);
|
||||||
ct_test(pTest, MSTP_Port.master_state == MSTP_MASTER_STATE_INITIALIZE);
|
ct_test(pTest, MSTP_Port.master_state == MSTP_MASTER_STATE_INITIALIZE);
|
||||||
@@ -1436,10 +1394,8 @@ mstp_port->ReceivedValidFrame = false; break; default:
|
|||||||
int main(void) {
|
int main(void) {
|
||||||
Test * pTest; bool rc; pTest = ct_create("mstp", NULL);
|
Test * pTest; bool rc; pTest = ct_create("mstp", NULL);
|
||||||
/* individual tests */
|
/* individual tests */
|
||||||
rc = ct_addTestFunction(pTest, testReceiveNodeFSM);
|
rc = ct_addTestFunction(pTest, testReceiveNodeFSM); assert(rc);
|
||||||
assert(rc);
|
rc = ct_addTestFunction(pTest, testMasterNodeFSM); assert(rc);
|
||||||
rc = ct_addTestFunction(pTest, testMasterNodeFSM);
|
ct_setStream(pTest, stdout); ct_run(pTest);
|
||||||
assert(rc);
|
(void) ct_report(pTest); ct_destroy(pTest); return 0;}
|
||||||
ct_setStream(pTest, stdout);
|
|
||||||
ct_run(pTest); (void) ct_report(pTest); ct_destroy(pTest); return 0;}
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user