Changed the data type of the MS/TP index for the receiving byte to allow an APDU of 480 bytes.
This commit is contained in:
@@ -165,7 +165,7 @@ struct mstp_port_struct_t {
|
|||||||
uint8_t HeaderCRCActual;
|
uint8_t HeaderCRCActual;
|
||||||
/* Used as an index by the Receive State Machine, up to a maximum value of */
|
/* Used as an index by the Receive State Machine, up to a maximum value of */
|
||||||
/* InputBufferSize. */
|
/* InputBufferSize. */
|
||||||
unsigned Index;
|
uint16_t Index;
|
||||||
/* An array of octets, used to store octets as they are received. */
|
/* An array of octets, used to store octets as they are received. */
|
||||||
/* InputBuffer is indexed from 0 to InputBufferSize-1. */
|
/* InputBuffer is indexed from 0 to InputBufferSize-1. */
|
||||||
/* The maximum size of a frame is 501 octets. */
|
/* The maximum size of a frame is 501 octets. */
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
#include "bacaddr.h"
|
#include "bacaddr.h"
|
||||||
|
|
||||||
/* This file has been customized for use with small microprocessors */
|
/* This file has been customized for use with small microprocessors */
|
||||||
/* Assumptions:
|
/* Assumptions:
|
||||||
Only one MS/TP datalink layer
|
Only one MS/TP datalink layer
|
||||||
*/
|
*/
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
@@ -121,7 +121,7 @@ static struct mstp_flag_t {
|
|||||||
/* A Boolean flag set TRUE by the datalink transmit if a
|
/* A Boolean flag set TRUE by the datalink transmit if a
|
||||||
pending packet is DataExpectingReply */
|
pending packet is DataExpectingReply */
|
||||||
unsigned TransmitPacketDER:1;
|
unsigned TransmitPacketDER:1;
|
||||||
/* A Boolean flag set TRUE by the datalink if a
|
/* A Boolean flag set TRUE by the datalink if a
|
||||||
packet has been received, but not processed. */
|
packet has been received, but not processed. */
|
||||||
unsigned ReceivePacketPending:1;
|
unsigned ReceivePacketPending:1;
|
||||||
} MSTP_Flag;
|
} MSTP_Flag;
|
||||||
@@ -287,8 +287,8 @@ static bool dlmstp_compare_data_expecting_reply(
|
|||||||
uint8_t dest_address)
|
uint8_t dest_address)
|
||||||
{
|
{
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
/* One way to check the message is to compare NPDU
|
/* One way to check the message is to compare NPDU
|
||||||
src, dest, along with the APDU type, invoke id.
|
src, dest, along with the APDU type, invoke id.
|
||||||
Seems a bit overkill */
|
Seems a bit overkill */
|
||||||
struct DER_compare_t {
|
struct DER_compare_t {
|
||||||
BACNET_NPDU_DATA npdu_data;
|
BACNET_NPDU_DATA npdu_data;
|
||||||
@@ -327,7 +327,7 @@ static bool dlmstp_compare_data_expecting_reply(
|
|||||||
if (reply.npdu_data.network_layer_message) {
|
if (reply.npdu_data.network_layer_message) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/* reply could be a lot of things:
|
/* reply could be a lot of things:
|
||||||
confirmed, simple ack, abort, reject, error */
|
confirmed, simple ack, abort, reject, error */
|
||||||
reply.pdu_type = reply_pdu[offset] & 0xF0;
|
reply.pdu_type = reply_pdu[offset] & 0xF0;
|
||||||
switch (reply.pdu_type) {
|
switch (reply.pdu_type) {
|
||||||
@@ -451,13 +451,13 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
static uint16_t DataCRC = 0;
|
static uint16_t DataCRC = 0;
|
||||||
/* Used to accumulate the CRC on the header of a frame. */
|
/* Used to accumulate the CRC on the header of a frame. */
|
||||||
static uint8_t HeaderCRC = 0;
|
static uint8_t HeaderCRC = 0;
|
||||||
/* Used as an index by the Receive State Machine,
|
/* Used as an index by the Receive State Machine,
|
||||||
up to a maximum value of the MPDU */
|
up to a maximum value of the MPDU */
|
||||||
static uint8_t Index = 0;
|
static uint16_t Index = 0;
|
||||||
|
|
||||||
switch (Receive_State) {
|
switch (Receive_State) {
|
||||||
case MSTP_RECEIVE_STATE_IDLE:
|
case MSTP_RECEIVE_STATE_IDLE:
|
||||||
/* In the IDLE state, the node waits
|
/* In the IDLE state, the node waits
|
||||||
for the beginning of a frame. */
|
for the beginning of a frame. */
|
||||||
if (RS485_ReceiveError()) {
|
if (RS485_ReceiveError()) {
|
||||||
/* EatAnError */
|
/* EatAnError */
|
||||||
@@ -474,7 +474,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MSTP_RECEIVE_STATE_PREAMBLE:
|
case MSTP_RECEIVE_STATE_PREAMBLE:
|
||||||
/* In the PREAMBLE state, the node waits for the
|
/* In the PREAMBLE state, the node waits for the
|
||||||
second octet of the preamble. */
|
second octet of the preamble. */
|
||||||
if (Timer_Silence() > Tframe_abort) {
|
if (Timer_Silence() > Tframe_abort) {
|
||||||
/* Timeout */
|
/* Timeout */
|
||||||
@@ -508,11 +508,11 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MSTP_RECEIVE_STATE_HEADER:
|
case MSTP_RECEIVE_STATE_HEADER:
|
||||||
/* In the HEADER state, the node waits
|
/* In the HEADER state, the node waits
|
||||||
for the fixed message header. */
|
for the fixed message header. */
|
||||||
if (Timer_Silence() > Tframe_abort) {
|
if (Timer_Silence() > Tframe_abort) {
|
||||||
/* Timeout */
|
/* Timeout */
|
||||||
/* indicate that an error has occurred
|
/* indicate that an error has occurred
|
||||||
during the reception of a frame */
|
during the reception of a frame */
|
||||||
MSTP_Flag.ReceivedInvalidFrame = true;
|
MSTP_Flag.ReceivedInvalidFrame = true;
|
||||||
/* wait for the start of a frame. */
|
/* wait for the start of a frame. */
|
||||||
@@ -521,7 +521,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
/* Error */
|
/* Error */
|
||||||
Timer_Silence_Reset();
|
Timer_Silence_Reset();
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
/* indicate that an error has occurred
|
/* indicate that an error has occurred
|
||||||
during the reception of a frame */
|
during the reception of a frame */
|
||||||
MSTP_Flag.ReceivedInvalidFrame = true;
|
MSTP_Flag.ReceivedInvalidFrame = true;
|
||||||
/* wait for the start of a frame. */
|
/* wait for the start of a frame. */
|
||||||
@@ -557,7 +557,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
} else if (Index == 5) {
|
} else if (Index == 5) {
|
||||||
/* HeaderCRC */
|
/* HeaderCRC */
|
||||||
HeaderCRC = CRC_Calc_Header(DataRegister, HeaderCRC);
|
HeaderCRC = CRC_Calc_Header(DataRegister, HeaderCRC);
|
||||||
/* In the HEADER_CRC state, the node validates the CRC
|
/* In the HEADER_CRC state, the node validates the CRC
|
||||||
on the fixed message header. */
|
on the fixed message header. */
|
||||||
if (HeaderCRC != 0x55) {
|
if (HeaderCRC != 0x55) {
|
||||||
/* BadCRC */
|
/* BadCRC */
|
||||||
@@ -569,7 +569,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
} else {
|
} else {
|
||||||
/* Note: proposed change to BACnet MSTP state machine!
|
/* Note: proposed change to BACnet MSTP state machine!
|
||||||
If we don't decode data that is not for us, we could
|
If we don't decode data that is not for us, we could
|
||||||
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. */
|
||||||
if ((DataLength) && (DataLength <= InputBufferSize)) {
|
if ((DataLength) && (DataLength <= InputBufferSize)) {
|
||||||
/* Data */
|
/* Data */
|
||||||
@@ -584,7 +584,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
(DestinationAddress ==
|
(DestinationAddress ==
|
||||||
MSTP_BROADCAST_ADDRESS)) {
|
MSTP_BROADCAST_ADDRESS)) {
|
||||||
/* ForUs */
|
/* ForUs */
|
||||||
/* indicate that a frame with
|
/* indicate that a frame with
|
||||||
no data has been received */
|
no data has been received */
|
||||||
MSTP_Flag.ReceivedValidFrame = true;
|
MSTP_Flag.ReceivedValidFrame = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -610,11 +610,11 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MSTP_RECEIVE_STATE_DATA:
|
case MSTP_RECEIVE_STATE_DATA:
|
||||||
/* In the DATA state, the node waits
|
/* In the DATA state, the node waits
|
||||||
for the data portion of a frame. */
|
for the data portion of a frame. */
|
||||||
if (Timer_Silence() > Tframe_abort) {
|
if (Timer_Silence() > Tframe_abort) {
|
||||||
/* Timeout */
|
/* Timeout */
|
||||||
/* indicate that an error has occurred
|
/* indicate that an error has occurred
|
||||||
during the reception of a frame */
|
during the reception of a frame */
|
||||||
MSTP_Flag.ReceivedInvalidFrame = true;
|
MSTP_Flag.ReceivedInvalidFrame = true;
|
||||||
/* wait for the start of the next frame. */
|
/* wait for the start of the next frame. */
|
||||||
@@ -623,7 +623,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
/* Error */
|
/* Error */
|
||||||
Timer_Silence_Reset();
|
Timer_Silence_Reset();
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
/* indicate that an error has occurred during
|
/* indicate that an error has occurred during
|
||||||
the reception of a frame */
|
the reception of a frame */
|
||||||
MSTP_Flag.ReceivedInvalidFrame = true;
|
MSTP_Flag.ReceivedInvalidFrame = true;
|
||||||
/* wait for the start of the next frame. */
|
/* wait for the start of the next frame. */
|
||||||
@@ -649,7 +649,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
if ((DestinationAddress == This_Station) ||
|
if ((DestinationAddress == This_Station) ||
|
||||||
(DestinationAddress == MSTP_BROADCAST_ADDRESS)) {
|
(DestinationAddress == MSTP_BROADCAST_ADDRESS)) {
|
||||||
/* ForUs */
|
/* ForUs */
|
||||||
/* indicate that a frame with no data
|
/* indicate that a frame with no data
|
||||||
has been received */
|
has been received */
|
||||||
MSTP_Flag.ReceivedValidFrame = true;
|
MSTP_Flag.ReceivedValidFrame = true;
|
||||||
}
|
}
|
||||||
@@ -677,8 +677,8 @@ static bool MSTP_Master_Node_FSM(
|
|||||||
/* When this counter reaches the value Nmax_info_frames, the node must */
|
/* When this counter reaches the value Nmax_info_frames, the node must */
|
||||||
/* pass the token. */
|
/* pass the token. */
|
||||||
static uint8_t FrameCount;
|
static uint8_t FrameCount;
|
||||||
/* "Next Station," the MAC address of the node to which This Station
|
/* "Next Station," the MAC address of the node to which This Station
|
||||||
passes the token. If the Next_Station is unknown, Next_Station shall
|
passes the token. If the Next_Station is unknown, Next_Station shall
|
||||||
be equal to This_Station. */
|
be equal to This_Station. */
|
||||||
static uint8_t Next_Station;
|
static uint8_t Next_Station;
|
||||||
/* "Poll Station," the MAC address of the node to which This Station last */
|
/* "Poll Station," the MAC address of the node to which This Station last */
|
||||||
@@ -772,7 +772,7 @@ static bool MSTP_Master_Node_FSM(
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* 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 (Master_State != MSTP_MASTER_STATE_ANSWER_DATA_REQUEST) {
|
if (Master_State != MSTP_MASTER_STATE_ANSWER_DATA_REQUEST) {
|
||||||
MSTP_Flag.ReceivedValidFrame = false;
|
MSTP_Flag.ReceivedValidFrame = false;
|
||||||
@@ -858,7 +858,7 @@ static bool MSTP_Master_Node_FSM(
|
|||||||
/* ReceivedReply */
|
/* ReceivedReply */
|
||||||
/* or a proprietary type that indicates
|
/* or a proprietary type that indicates
|
||||||
a reply */
|
a reply */
|
||||||
/* indicate successful reception to
|
/* indicate successful reception to
|
||||||
the higher layers */
|
the higher layers */
|
||||||
MSTP_Flag.ReceivePacketPending = true;
|
MSTP_Flag.ReceivePacketPending = true;
|
||||||
Master_State =
|
Master_State =
|
||||||
@@ -901,7 +901,7 @@ static bool MSTP_Master_Node_FSM(
|
|||||||
(Next_Station != next_this_station)) {
|
(Next_Station != next_this_station)) {
|
||||||
/* SoleMaster */
|
/* SoleMaster */
|
||||||
/* there are no other known master nodes to */
|
/* there are no other known master nodes to */
|
||||||
/* which the token may be sent
|
/* which the token may be sent
|
||||||
(true master-slave operation). */
|
(true master-slave operation). */
|
||||||
FrameCount = 0;
|
FrameCount = 0;
|
||||||
TokenCount++;
|
TokenCount++;
|
||||||
@@ -910,11 +910,11 @@ static bool MSTP_Master_Node_FSM(
|
|||||||
} else {
|
} else {
|
||||||
/* SendToken */
|
/* SendToken */
|
||||||
/* Npoll changed in Errata SSPC-135-2004 */
|
/* Npoll changed in Errata SSPC-135-2004 */
|
||||||
/* The comparison of NS and TS+1
|
/* The comparison of NS and TS+1
|
||||||
eliminates the Poll For Master
|
eliminates the Poll For Master
|
||||||
if there are no addresses between
|
if there are no addresses between
|
||||||
TS and NS, since there is no
|
TS and NS, since there is no
|
||||||
address at which a new master node
|
address at which a new master node
|
||||||
may be found in that case. */
|
may be found in that case. */
|
||||||
TokenCount++;
|
TokenCount++;
|
||||||
/* transmit a Token frame to NS */
|
/* transmit a Token frame to NS */
|
||||||
@@ -963,7 +963,7 @@ static bool MSTP_Master_Node_FSM(
|
|||||||
if (Timer_Silence() <= Tusage_timeout) {
|
if (Timer_Silence() <= Tusage_timeout) {
|
||||||
if (EventCount > Nmin_octets) {
|
if (EventCount > Nmin_octets) {
|
||||||
/* SawTokenUser */
|
/* SawTokenUser */
|
||||||
/* Assume that a frame has been sent by
|
/* Assume that a frame has been sent by
|
||||||
the new token user. */
|
the new token user. */
|
||||||
/* Enter the IDLE state to process the frame. */
|
/* Enter the IDLE state to process the frame. */
|
||||||
Master_State = MSTP_MASTER_STATE_IDLE;
|
Master_State = MSTP_MASTER_STATE_IDLE;
|
||||||
@@ -996,10 +996,10 @@ static bool MSTP_Master_Node_FSM(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
/* The NO_TOKEN state is entered if Timer_Silence()
|
/* The NO_TOKEN state is entered if Timer_Silence()
|
||||||
becomes greater than Tno_token, indicating that
|
becomes greater than Tno_token, indicating that
|
||||||
there has been no network activity for that period
|
there has been no network activity for that period
|
||||||
of time. The timeout is continued to determine
|
of time. The timeout is continued to determine
|
||||||
whether or not this node may create a token. */
|
whether or not this node may create a token. */
|
||||||
case MSTP_MASTER_STATE_NO_TOKEN:
|
case MSTP_MASTER_STATE_NO_TOKEN:
|
||||||
my_timeout = Tno_token + (Tslot * This_Station);
|
my_timeout = Tno_token + (Tslot * This_Station);
|
||||||
@@ -1007,7 +1007,7 @@ static bool MSTP_Master_Node_FSM(
|
|||||||
if (EventCount > Nmin_octets) {
|
if (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
|
/* Enter the IDLE state to receive and
|
||||||
process the incoming frame. */
|
process the incoming frame. */
|
||||||
Master_State = MSTP_MASTER_STATE_IDLE;
|
Master_State = MSTP_MASTER_STATE_IDLE;
|
||||||
transition_now = true;
|
transition_now = true;
|
||||||
@@ -1027,7 +1027,7 @@ static bool MSTP_Master_Node_FSM(
|
|||||||
RetryCount = 0;
|
RetryCount = 0;
|
||||||
TokenCount = 0;
|
TokenCount = 0;
|
||||||
/* EventCount = 0; removed Addendum 135-2004d-8 */
|
/* EventCount = 0; removed Addendum 135-2004d-8 */
|
||||||
/* enter the POLL_FOR_MASTER state
|
/* enter the POLL_FOR_MASTER state
|
||||||
to find a new successor to TS. */
|
to find a new successor to TS. */
|
||||||
Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER;
|
Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER;
|
||||||
}
|
}
|
||||||
@@ -1093,7 +1093,7 @@ static bool MSTP_Master_Node_FSM(
|
|||||||
/* Re-enter the current state. */
|
/* Re-enter the current state. */
|
||||||
} else {
|
} else {
|
||||||
/* DeclareSoleMaster */
|
/* DeclareSoleMaster */
|
||||||
/* to indicate that this station
|
/* to indicate that this station
|
||||||
is the only master */
|
is the only master */
|
||||||
MSTP_Flag.SoleMaster = true;
|
MSTP_Flag.SoleMaster = true;
|
||||||
FrameCount = 0;
|
FrameCount = 0;
|
||||||
@@ -1201,7 +1201,7 @@ uint16_t dlmstp_receive(
|
|||||||
MSTP_Receive_Frame_FSM();
|
MSTP_Receive_Frame_FSM();
|
||||||
if (MSTP_Flag.ReceivedValidFrame || MSTP_Flag.ReceivedInvalidFrame)
|
if (MSTP_Flag.ReceivedValidFrame || MSTP_Flag.ReceivedInvalidFrame)
|
||||||
break;
|
break;
|
||||||
/* if we are not idle, then we are
|
/* if we are not idle, then we are
|
||||||
receiving a frame or timing out */
|
receiving a frame or timing out */
|
||||||
if (Receive_State == MSTP_RECEIVE_STATE_IDLE)
|
if (Receive_State == MSTP_RECEIVE_STATE_IDLE)
|
||||||
break;
|
break;
|
||||||
@@ -1233,7 +1233,7 @@ void dlmstp_set_mac_address(
|
|||||||
This_Station = mac_address;
|
This_Station = mac_address;
|
||||||
/* FIXME: implement your data storage */
|
/* FIXME: implement your data storage */
|
||||||
/* I2C_Write_Byte(
|
/* I2C_Write_Byte(
|
||||||
EEPROM_DEVICE_ADDRESS,
|
EEPROM_DEVICE_ADDRESS,
|
||||||
mac_address,
|
mac_address,
|
||||||
EEPROM_MSTP_MAC_ADDR); */
|
EEPROM_MSTP_MAC_ADDR); */
|
||||||
if (mac_address > Nmax_master)
|
if (mac_address > Nmax_master)
|
||||||
@@ -1262,8 +1262,8 @@ void dlmstp_set_max_info_frames(
|
|||||||
if (max_info_frames >= 1) {
|
if (max_info_frames >= 1) {
|
||||||
Nmax_info_frames = max_info_frames;
|
Nmax_info_frames = max_info_frames;
|
||||||
/* FIXME: implement your data storage */
|
/* FIXME: implement your data storage */
|
||||||
/* I2C_Write_Byte(
|
/* I2C_Write_Byte(
|
||||||
EEPROM_DEVICE_ADDRESS,
|
EEPROM_DEVICE_ADDRESS,
|
||||||
(uint8_t)max_info_frames,
|
(uint8_t)max_info_frames,
|
||||||
EEPROM_MSTP_MAX_INFO_FRAMES_ADDR); */
|
EEPROM_MSTP_MAX_INFO_FRAMES_ADDR); */
|
||||||
}
|
}
|
||||||
@@ -1290,7 +1290,7 @@ void dlmstp_set_max_master(
|
|||||||
Nmax_master = max_master;
|
Nmax_master = max_master;
|
||||||
/* FIXME: implement your data storage */
|
/* FIXME: implement your data storage */
|
||||||
/* I2C_Write_Byte(
|
/* I2C_Write_Byte(
|
||||||
EEPROM_DEVICE_ADDRESS,
|
EEPROM_DEVICE_ADDRESS,
|
||||||
max_master,
|
max_master,
|
||||||
EEPROM_MSTP_MAX_MASTER_ADDR); */
|
EEPROM_MSTP_MAX_MASTER_ADDR); */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
#include "txbuf.h"
|
#include "txbuf.h"
|
||||||
|
|
||||||
/* This file has been customized for use with small microprocessors */
|
/* This file has been customized for use with small microprocessors */
|
||||||
/* Assumptions:
|
/* Assumptions:
|
||||||
Only one MS/TP datalink layer
|
Only one MS/TP datalink layer
|
||||||
*/
|
*/
|
||||||
#include "hardware.h"
|
#include "hardware.h"
|
||||||
@@ -124,7 +124,7 @@ static struct mstp_flag_t {
|
|||||||
/* A Boolean flag set TRUE by the datalink transmit if a
|
/* A Boolean flag set TRUE by the datalink transmit if a
|
||||||
pending packet is DataExpectingReply */
|
pending packet is DataExpectingReply */
|
||||||
unsigned TransmitPacketDER:1;
|
unsigned TransmitPacketDER:1;
|
||||||
/* A Boolean flag set TRUE by the datalink if a
|
/* A Boolean flag set TRUE by the datalink if a
|
||||||
packet has been received, but not processed. */
|
packet has been received, but not processed. */
|
||||||
unsigned ReceivePacketPending:1;
|
unsigned ReceivePacketPending:1;
|
||||||
} MSTP_Flag;
|
} MSTP_Flag;
|
||||||
@@ -366,9 +366,9 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
static uint16_t DataCRC = 0;
|
static uint16_t DataCRC = 0;
|
||||||
/* Used to accumulate the CRC on the header of a frame. */
|
/* Used to accumulate the CRC on the header of a frame. */
|
||||||
static uint8_t HeaderCRC = 0;
|
static uint8_t HeaderCRC = 0;
|
||||||
/* Used as an index by the Receive State Machine,
|
/* Used as an index by the Receive State Machine,
|
||||||
up to a maximum value of the MPDU */
|
up to a maximum value of the MPDU */
|
||||||
static uint8_t Index = 0;
|
static uint16_t Index = 0;
|
||||||
|
|
||||||
switch (Receive_State) {
|
switch (Receive_State) {
|
||||||
case MSTP_RECEIVE_STATE_IDLE:
|
case MSTP_RECEIVE_STATE_IDLE:
|
||||||
@@ -388,7 +388,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MSTP_RECEIVE_STATE_PREAMBLE:
|
case MSTP_RECEIVE_STATE_PREAMBLE:
|
||||||
/* In the PREAMBLE state, the node waits for the
|
/* In the PREAMBLE state, the node waits for the
|
||||||
second octet of the preamble. */
|
second octet of the preamble. */
|
||||||
if (Timer_Silence() > Tframe_abort) {
|
if (Timer_Silence() > Tframe_abort) {
|
||||||
/* Timeout */
|
/* Timeout */
|
||||||
@@ -468,7 +468,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
} else if (Index == 5) {
|
} else if (Index == 5) {
|
||||||
/* HeaderCRC */
|
/* HeaderCRC */
|
||||||
HeaderCRC = CRC_Calc_Header(DataRegister, HeaderCRC);
|
HeaderCRC = CRC_Calc_Header(DataRegister, HeaderCRC);
|
||||||
/* In the HEADER_CRC state, the node validates the CRC
|
/* In the HEADER_CRC state, the node validates the CRC
|
||||||
on the fixed message header. */
|
on the fixed message header. */
|
||||||
if (HeaderCRC != 0x55) {
|
if (HeaderCRC != 0x55) {
|
||||||
/* BadCRC */
|
/* BadCRC */
|
||||||
@@ -480,7 +480,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
} else {
|
} else {
|
||||||
/* Note: proposed change to BACnet MSTP state machine!
|
/* Note: proposed change to BACnet MSTP state machine!
|
||||||
If we don't decode data that is not for us, we could
|
If we don't decode data that is not for us, we could
|
||||||
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. */
|
||||||
if ((DataLength) && (DataLength <= InputBufferSize)) {
|
if ((DataLength) && (DataLength <= InputBufferSize)) {
|
||||||
/* Data */
|
/* Data */
|
||||||
@@ -495,7 +495,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
(DestinationAddress ==
|
(DestinationAddress ==
|
||||||
MSTP_BROADCAST_ADDRESS)) {
|
MSTP_BROADCAST_ADDRESS)) {
|
||||||
/* ForUs */
|
/* ForUs */
|
||||||
/* indicate that a frame with
|
/* indicate that a frame with
|
||||||
no data has been received */
|
no data has been received */
|
||||||
MSTP_Flag.ReceivedValidFrame = true;
|
MSTP_Flag.ReceivedValidFrame = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -532,7 +532,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
/* Error */
|
/* Error */
|
||||||
Timer_Silence_Reset();
|
Timer_Silence_Reset();
|
||||||
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
INCREMENT_AND_LIMIT_UINT8(EventCount);
|
||||||
/* indicate that an error has occurred during
|
/* indicate that an error has occurred during
|
||||||
the reception of a frame */
|
the reception of a frame */
|
||||||
MSTP_Flag.ReceivedInvalidFrame = true;
|
MSTP_Flag.ReceivedInvalidFrame = true;
|
||||||
/* wait for the start of the next frame. */
|
/* wait for the start of the next frame. */
|
||||||
@@ -558,7 +558,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
if ((DestinationAddress == This_Station) ||
|
if ((DestinationAddress == This_Station) ||
|
||||||
(DestinationAddress == MSTP_BROADCAST_ADDRESS)) {
|
(DestinationAddress == MSTP_BROADCAST_ADDRESS)) {
|
||||||
/* ForUs */
|
/* ForUs */
|
||||||
/* indicate that a frame with no data
|
/* indicate that a frame with no data
|
||||||
has been received */
|
has been received */
|
||||||
MSTP_Flag.ReceivedValidFrame = true;
|
MSTP_Flag.ReceivedValidFrame = true;
|
||||||
}
|
}
|
||||||
@@ -680,7 +680,7 @@ static bool MSTP_Master_Node_FSM(
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* 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 (Master_State != MSTP_MASTER_STATE_ANSWER_DATA_REQUEST) {
|
if (Master_State != MSTP_MASTER_STATE_ANSWER_DATA_REQUEST) {
|
||||||
MSTP_Flag.ReceivedValidFrame = false;
|
MSTP_Flag.ReceivedValidFrame = false;
|
||||||
@@ -1068,7 +1068,7 @@ uint16_t dlmstp_receive(
|
|||||||
MSTP_Receive_Frame_FSM();
|
MSTP_Receive_Frame_FSM();
|
||||||
if (MSTP_Flag.ReceivedValidFrame || MSTP_Flag.ReceivedInvalidFrame)
|
if (MSTP_Flag.ReceivedValidFrame || MSTP_Flag.ReceivedInvalidFrame)
|
||||||
break;
|
break;
|
||||||
/* if we are not idle, then we are
|
/* if we are not idle, then we are
|
||||||
receiving a frame or timing out */
|
receiving a frame or timing out */
|
||||||
if (Receive_State == MSTP_RECEIVE_STATE_IDLE)
|
if (Receive_State == MSTP_RECEIVE_STATE_IDLE)
|
||||||
break;
|
break;
|
||||||
@@ -1100,7 +1100,7 @@ void dlmstp_set_mac_address(
|
|||||||
This_Station = mac_address;
|
This_Station = mac_address;
|
||||||
/* FIXME: implement your data storage */
|
/* FIXME: implement your data storage */
|
||||||
/* I2C_Write_Byte(
|
/* I2C_Write_Byte(
|
||||||
EEPROM_DEVICE_ADDRESS,
|
EEPROM_DEVICE_ADDRESS,
|
||||||
mac_address,
|
mac_address,
|
||||||
EEPROM_MSTP_MAC_ADDR); */
|
EEPROM_MSTP_MAC_ADDR); */
|
||||||
if (mac_address > Nmax_master)
|
if (mac_address > Nmax_master)
|
||||||
@@ -1129,8 +1129,8 @@ void dlmstp_set_max_info_frames(
|
|||||||
if (max_info_frames >= 1) {
|
if (max_info_frames >= 1) {
|
||||||
Nmax_info_frames = max_info_frames;
|
Nmax_info_frames = max_info_frames;
|
||||||
/* FIXME: implement your data storage */
|
/* FIXME: implement your data storage */
|
||||||
/* I2C_Write_Byte(
|
/* I2C_Write_Byte(
|
||||||
EEPROM_DEVICE_ADDRESS,
|
EEPROM_DEVICE_ADDRESS,
|
||||||
(uint8_t)max_info_frames,
|
(uint8_t)max_info_frames,
|
||||||
EEPROM_MSTP_MAX_INFO_FRAMES_ADDR); */
|
EEPROM_MSTP_MAX_INFO_FRAMES_ADDR); */
|
||||||
}
|
}
|
||||||
@@ -1157,7 +1157,7 @@ void dlmstp_set_max_master(
|
|||||||
Nmax_master = max_master;
|
Nmax_master = max_master;
|
||||||
/* FIXME: implement your data storage */
|
/* FIXME: implement your data storage */
|
||||||
/* I2C_Write_Byte(
|
/* I2C_Write_Byte(
|
||||||
EEPROM_DEVICE_ADDRESS,
|
EEPROM_DEVICE_ADDRESS,
|
||||||
max_master,
|
max_master,
|
||||||
EEPROM_MSTP_MAX_MASTER_ADDR); */
|
EEPROM_MSTP_MAX_MASTER_ADDR); */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
#include "txbuf.h"
|
#include "txbuf.h"
|
||||||
|
|
||||||
/* This file has been customized for use with small microprocessors */
|
/* This file has been customized for use with small microprocessors */
|
||||||
/* Assumptions:
|
/* Assumptions:
|
||||||
Only one slave node MS/TP datalink layer
|
Only one slave node MS/TP datalink layer
|
||||||
*/
|
*/
|
||||||
#include "hardware.h"
|
#include "hardware.h"
|
||||||
@@ -99,7 +99,7 @@ static struct mstp_flag_t {
|
|||||||
/* A Boolean flag set TRUE by the datalink transmit if a
|
/* A Boolean flag set TRUE by the datalink transmit if a
|
||||||
pending packet is DataExpectingReply */
|
pending packet is DataExpectingReply */
|
||||||
unsigned TransmitPacketDER:1;
|
unsigned TransmitPacketDER:1;
|
||||||
/* A Boolean flag set TRUE by the datalink if a
|
/* A Boolean flag set TRUE by the datalink if a
|
||||||
packet has been received, but not processed. */
|
packet has been received, but not processed. */
|
||||||
unsigned ReceivePacketPending:1;
|
unsigned ReceivePacketPending:1;
|
||||||
} MSTP_Flag;
|
} MSTP_Flag;
|
||||||
@@ -401,9 +401,9 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
static uint16_t DataCRC = 0;
|
static uint16_t DataCRC = 0;
|
||||||
/* Used to accumulate the CRC on the header of a frame. */
|
/* Used to accumulate the CRC on the header of a frame. */
|
||||||
static uint8_t HeaderCRC = 0;
|
static uint8_t HeaderCRC = 0;
|
||||||
/* Used as an index by the Receive State Machine,
|
/* Used as an index by the Receive State Machine,
|
||||||
up to a maximum value of the MPDU */
|
up to a maximum value of the MPDU */
|
||||||
static uint8_t Index = 0;
|
static uint16_t Index = 0;
|
||||||
|
|
||||||
switch (Receive_State) {
|
switch (Receive_State) {
|
||||||
case MSTP_RECEIVE_STATE_IDLE:
|
case MSTP_RECEIVE_STATE_IDLE:
|
||||||
@@ -421,7 +421,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MSTP_RECEIVE_STATE_PREAMBLE:
|
case MSTP_RECEIVE_STATE_PREAMBLE:
|
||||||
/* In the PREAMBLE state, the node waits for the
|
/* In the PREAMBLE state, the node waits for the
|
||||||
second octet of the preamble. */
|
second octet of the preamble. */
|
||||||
if (timer_silence_elapsed(Tframe_abort)) {
|
if (timer_silence_elapsed(Tframe_abort)) {
|
||||||
/* Timeout */
|
/* Timeout */
|
||||||
@@ -497,7 +497,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
} else if (Index == 5) {
|
} else if (Index == 5) {
|
||||||
/* HeaderCRC */
|
/* HeaderCRC */
|
||||||
HeaderCRC = CRC_Calc_Header(DataRegister, HeaderCRC);
|
HeaderCRC = CRC_Calc_Header(DataRegister, HeaderCRC);
|
||||||
/* In the HEADER_CRC state, the node validates the CRC
|
/* In the HEADER_CRC state, the node validates the CRC
|
||||||
on the fixed message header. */
|
on the fixed message header. */
|
||||||
if (HeaderCRC != 0x55) {
|
if (HeaderCRC != 0x55) {
|
||||||
/* BadCRC */
|
/* BadCRC */
|
||||||
@@ -509,7 +509,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
} else {
|
} else {
|
||||||
/* Note: proposed change to BACnet MSTP state machine!
|
/* Note: proposed change to BACnet MSTP state machine!
|
||||||
If we don't decode data that is not for us, we could
|
If we don't decode data that is not for us, we could
|
||||||
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. */
|
||||||
if ((DataLength) && (DataLength <= InputBufferSize)) {
|
if ((DataLength) && (DataLength <= InputBufferSize)) {
|
||||||
/* Data */
|
/* Data */
|
||||||
@@ -524,7 +524,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
(DestinationAddress ==
|
(DestinationAddress ==
|
||||||
MSTP_BROADCAST_ADDRESS)) {
|
MSTP_BROADCAST_ADDRESS)) {
|
||||||
/* ForUs */
|
/* ForUs */
|
||||||
/* indicate that a frame with
|
/* indicate that a frame with
|
||||||
no data has been received */
|
no data has been received */
|
||||||
MSTP_Flag.ReceivedValidFrame = true;
|
MSTP_Flag.ReceivedValidFrame = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -560,7 +560,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
} else if (RS485_ReceiveError()) {
|
} else if (RS485_ReceiveError()) {
|
||||||
/* Error */
|
/* Error */
|
||||||
timer_silence_reset();
|
timer_silence_reset();
|
||||||
/* indicate that an error has occurred during
|
/* indicate that an error has occurred during
|
||||||
the reception of a frame */
|
the reception of a frame */
|
||||||
MSTP_Flag.ReceivedInvalidFrame = true;
|
MSTP_Flag.ReceivedInvalidFrame = true;
|
||||||
/* wait for the start of the next frame. */
|
/* wait for the start of the next frame. */
|
||||||
@@ -585,7 +585,7 @@ static void MSTP_Receive_Frame_FSM(
|
|||||||
if ((DestinationAddress == This_Station) ||
|
if ((DestinationAddress == This_Station) ||
|
||||||
(DestinationAddress == MSTP_BROADCAST_ADDRESS)) {
|
(DestinationAddress == MSTP_BROADCAST_ADDRESS)) {
|
||||||
/* ForUs */
|
/* ForUs */
|
||||||
/* indicate that a frame with no data
|
/* indicate that a frame with no data
|
||||||
has been received */
|
has been received */
|
||||||
MSTP_Flag.ReceivedValidFrame = true;
|
MSTP_Flag.ReceivedValidFrame = true;
|
||||||
}
|
}
|
||||||
@@ -691,7 +691,7 @@ uint16_t dlmstp_receive(
|
|||||||
MSTP_Receive_Frame_FSM();
|
MSTP_Receive_Frame_FSM();
|
||||||
if (MSTP_Flag.ReceivedValidFrame || MSTP_Flag.ReceivedInvalidFrame)
|
if (MSTP_Flag.ReceivedValidFrame || MSTP_Flag.ReceivedInvalidFrame)
|
||||||
break;
|
break;
|
||||||
/* if we are not idle, then we are
|
/* if we are not idle, then we are
|
||||||
receiving a frame or timing out */
|
receiving a frame or timing out */
|
||||||
if (Receive_State == MSTP_RECEIVE_STATE_IDLE)
|
if (Receive_State == MSTP_RECEIVE_STATE_IDLE)
|
||||||
break;
|
break;
|
||||||
@@ -721,7 +721,7 @@ void dlmstp_set_mac_address(
|
|||||||
This_Station = mac_address;
|
This_Station = mac_address;
|
||||||
/* FIXME: implement your data storage */
|
/* FIXME: implement your data storage */
|
||||||
/* I2C_Write_Byte(
|
/* I2C_Write_Byte(
|
||||||
EEPROM_DEVICE_ADDRESS,
|
EEPROM_DEVICE_ADDRESS,
|
||||||
mac_address,
|
mac_address,
|
||||||
EEPROM_MSTP_MAC_ADDR); */
|
EEPROM_MSTP_MAC_ADDR); */
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user