Converted SilenceTimer on MS/TP datalink to be a function so that it can be atomic on 8-bit microcontrollers.

This commit is contained in:
skarg
2007-08-19 12:30:51 +00:00
parent 53f2fc3f35
commit eabe6dee96
17 changed files with 242 additions and 121 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
/* Lon=206, MS/TP=480, ARCNET=480, Ethernet=1476 */ /* Lon=206, MS/TP=480, ARCNET=480, Ethernet=1476 */
#ifndef MAX_APDU #ifndef MAX_APDU
/* #define MAX_APDU 50 */ /* #define MAX_APDU 50 */
#define MAX_APDU 480 #define MAX_APDU 480
/* #define MAX_APDU 1476 */ /* #define MAX_APDU 1476 */
#endif #endif
/* for confirmed messages, this is the number of transactions */ /* for confirmed messages, this is the number of transactions */
-3
View File
@@ -60,9 +60,6 @@ extern "C" {
bool dlmstp_init(char *ifname); bool dlmstp_init(char *ifname);
void dlmstp_cleanup(void); void dlmstp_cleanup(void);
/* address of the 16-bit timer. Update it in an ISR or Task. */
volatile uint16_t *dlmstp_millisecond_timer_address(void);
/* returns number of bytes sent on success, negative on failure */ /* returns number of bytes sent on success, negative on failure */
int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */ BACNET_NPDU_DATA * npdu_data, /* network information */
+93 -82
View File
@@ -213,7 +213,7 @@ void MSTP_Create_And_Send_Frame(volatile struct mstp_port_struct_t *mstp_port,
RS485_Send_Frame(mstp_port, RS485_Send_Frame(mstp_port,
(uint8_t *)&mstp_port->OutputBuffer[0], (uint8_t *)&mstp_port->OutputBuffer[0],
len); len);
/* FIXME: be sure to reset SilenceTimer after each octet is sent! */ /* FIXME: be sure to reset SilenceTimer() after each octet is sent! */
} }
void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port) void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
@@ -227,7 +227,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
mstptext_receive_state(mstp_port->receive_state), mstptext_receive_state(mstp_port->receive_state),
mstp_port->DataRegister, mstp_port->HeaderCRC, mstp_port->Index, mstp_port->DataRegister, mstp_port->HeaderCRC, mstp_port->Index,
mstp_port->EventCount, mstp_port->DataLength, mstp_port->EventCount, mstp_port->DataLength,
mstp_port->SilenceTimer); mstp_port->SilenceTimer();
#endif #endif
switch (mstp_port->receive_state) { switch (mstp_port->receive_state) {
/* In the IDLE state, the node waits for the beginning of a frame. */ /* In the IDLE state, the node waits for the beginning of a frame. */
@@ -235,7 +235,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* EatAnError */ /* EatAnError */
if (mstp_port->ReceiveError == true) { if (mstp_port->ReceiveError == true) {
mstp_port->ReceiveError = false; mstp_port->ReceiveError = false;
mstp_port->SilenceTimer = 0; 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;
@@ -253,7 +253,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* Preamble1 */ /* Preamble1 */
if (mstp_port->DataRegister == 0x55) { if (mstp_port->DataRegister == 0x55) {
mstp_port->DataAvailable = false; mstp_port->DataAvailable = false;
mstp_port->SilenceTimer = 0; mstp_port->SilenceTimerReset();
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);
/* receive the remainder of the frame. */ /* receive the remainder of the frame. */
mstp_port->receive_state = MSTP_RECEIVE_STATE_PREAMBLE; mstp_port->receive_state = MSTP_RECEIVE_STATE_PREAMBLE;
@@ -264,7 +264,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
fprintf(stderr, "\n"); fprintf(stderr, "\n");
#endif #endif
mstp_port->DataAvailable = false; mstp_port->DataAvailable = false;
mstp_port->SilenceTimer = 0; 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;
@@ -274,7 +274,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* 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. */
case MSTP_RECEIVE_STATE_PREAMBLE: case MSTP_RECEIVE_STATE_PREAMBLE:
/* Timeout */ /* Timeout */
if (mstp_port->SilenceTimer > Tframe_abort) { if (mstp_port->SilenceTimer() > Tframe_abort) {
/* a correct preamble has not been received */ /* a correct preamble has not been received */
/* 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;
@@ -282,7 +282,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* Error */ /* Error */
else if (mstp_port->ReceiveError == true) { else if (mstp_port->ReceiveError == true) {
mstp_port->ReceiveError = false; mstp_port->ReceiveError = false;
mstp_port->SilenceTimer = 0; 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;
@@ -293,7 +293,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* Preamble2 */ /* Preamble2 */
if (mstp_port->DataRegister == 0xFF) { if (mstp_port->DataRegister == 0xFF) {
mstp_port->DataAvailable = false; mstp_port->DataAvailable = false;
mstp_port->SilenceTimer = 0; mstp_port->SilenceTimerReset();
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);
mstp_port->Index = 0; mstp_port->Index = 0;
mstp_port->HeaderCRC = 0xFF; mstp_port->HeaderCRC = 0xFF;
@@ -303,7 +303,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* ignore RepeatedPreamble1 */ /* ignore RepeatedPreamble1 */
else if (mstp_port->DataRegister == 0x55) { else if (mstp_port->DataRegister == 0x55) {
mstp_port->DataAvailable = false; mstp_port->DataAvailable = false;
mstp_port->SilenceTimer = 0; mstp_port->SilenceTimerReset();
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);
/* wait for the second preamble octet. */ /* wait for the second preamble octet. */
mstp_port->receive_state = MSTP_RECEIVE_STATE_PREAMBLE; mstp_port->receive_state = MSTP_RECEIVE_STATE_PREAMBLE;
@@ -311,7 +311,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* NotPreamble */ /* NotPreamble */
else { else {
mstp_port->DataAvailable = false; mstp_port->DataAvailable = false;
mstp_port->SilenceTimer = 0; 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;
@@ -321,20 +321,20 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* In the HEADER state, the node waits for the fixed message header. */ /* In the HEADER state, the node waits for the fixed message header. */
case MSTP_RECEIVE_STATE_HEADER: case MSTP_RECEIVE_STATE_HEADER:
/* Timeout */ /* Timeout */
if (mstp_port->SilenceTimer > Tframe_abort) { if (mstp_port->SilenceTimer() > Tframe_abort) {
/* 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;
/* 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;
#if PRINT_ENABLED_RECEIVE_ERRORS #if PRINT_ENABLED_RECEIVE_ERRORS
fprintf(stderr,"MSTP: Rx Header: SilenceTimer %d > %d\n", fprintf(stderr,"MSTP: Rx Header: SilenceTimer %d > %d\n",
mstp_port->SilenceTimer, Tframe_abort); mstp_port->SilenceTimer(), Tframe_abort);
#endif #endif
} }
/* Error */ /* Error */
else if (mstp_port->ReceiveError == true) { else if (mstp_port->ReceiveError == true) {
mstp_port->ReceiveError = false; mstp_port->ReceiveError = false;
mstp_port->SilenceTimer = 0; 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;
@@ -349,7 +349,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
#endif #endif
/* FrameType */ /* FrameType */
if (mstp_port->Index == 0) { if (mstp_port->Index == 0) {
mstp_port->SilenceTimer = 0; mstp_port->SilenceTimerReset();
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);
mstp_port->HeaderCRC = mstp_port->HeaderCRC =
CRC_Calc_Header(mstp_port->DataRegister, CRC_Calc_Header(mstp_port->DataRegister,
@@ -361,7 +361,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
} }
/* Destination */ /* Destination */
else if (mstp_port->Index == 1) { else if (mstp_port->Index == 1) {
mstp_port->SilenceTimer = 0; mstp_port->SilenceTimerReset();
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);
mstp_port->HeaderCRC = mstp_port->HeaderCRC =
CRC_Calc_Header(mstp_port->DataRegister, CRC_Calc_Header(mstp_port->DataRegister,
@@ -373,7 +373,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
} }
/* Source */ /* Source */
else if (mstp_port->Index == 2) { else if (mstp_port->Index == 2) {
mstp_port->SilenceTimer = 0; mstp_port->SilenceTimerReset();
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);
mstp_port->HeaderCRC = mstp_port->HeaderCRC =
CRC_Calc_Header(mstp_port->DataRegister, CRC_Calc_Header(mstp_port->DataRegister,
@@ -385,7 +385,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
} }
/* Length1 */ /* Length1 */
else if (mstp_port->Index == 3) { else if (mstp_port->Index == 3) {
mstp_port->SilenceTimer = 0; mstp_port->SilenceTimerReset();
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);
mstp_port->HeaderCRC = mstp_port->HeaderCRC =
CRC_Calc_Header(mstp_port->DataRegister, CRC_Calc_Header(mstp_port->DataRegister,
@@ -397,7 +397,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
} }
/* Length2 */ /* Length2 */
else if (mstp_port->Index == 4) { else if (mstp_port->Index == 4) {
mstp_port->SilenceTimer = 0; mstp_port->SilenceTimerReset();
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);
mstp_port->HeaderCRC = mstp_port->HeaderCRC =
CRC_Calc_Header(mstp_port->DataRegister, CRC_Calc_Header(mstp_port->DataRegister,
@@ -409,7 +409,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
} }
/* HeaderCRC */ /* HeaderCRC */
else if (mstp_port->Index == 5) { else if (mstp_port->Index == 5) {
mstp_port->SilenceTimer = 0; mstp_port->SilenceTimerReset();
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount);
mstp_port->HeaderCRC = mstp_port->HeaderCRC =
CRC_Calc_Header(mstp_port->DataRegister, CRC_Calc_Header(mstp_port->DataRegister,
@@ -480,7 +480,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* not per MS/TP standard, but it is a case not covered */ /* not per MS/TP standard, but it is a case not covered */
else { else {
mstp_port->ReceiveError = false; mstp_port->ReceiveError = false;
mstp_port->SilenceTimer = 0; mstp_port->SilenceTimerReset();
INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); INCREMENT_AND_LIMIT_UINT8(mstp_port->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 */
@@ -501,12 +501,12 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* In the DATA state, the node waits for the data portion of a frame. */ /* In the DATA state, the node waits for the data portion of a frame. */
case MSTP_RECEIVE_STATE_DATA: case MSTP_RECEIVE_STATE_DATA:
/* Timeout */ /* Timeout */
if (mstp_port->SilenceTimer > Tframe_abort) { if (mstp_port->SilenceTimer() > Tframe_abort) {
/* 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;
#if PRINT_ENABLED_RECEIVE_ERRORS #if PRINT_ENABLED_RECEIVE_ERRORS
fprintf(stderr,"MSTP: Rx Data: SilenceTimer %d > %d\n", fprintf(stderr,"MSTP: Rx Data: SilenceTimer %d > %d\n",
mstp_port->SilenceTimer, Tframe_abort); mstp_port->SilenceTimer(), Tframe_abort);
#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;
@@ -514,7 +514,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
/* Error */ /* Error */
else if (mstp_port->ReceiveError == true) { else if (mstp_port->ReceiveError == true) {
mstp_port->ReceiveError = false; mstp_port->ReceiveError = false;
mstp_port->SilenceTimer = 0; mstp_port->SilenceTimerReset();
/* 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;
#if PRINT_ENABLED_RECEIVE_ERRORS #if PRINT_ENABLED_RECEIVE_ERRORS
@@ -577,7 +577,7 @@ void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port)
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->SilenceTimer = 0; mstp_port->SilenceTimerReset();
} }
break; break;
default: default:
@@ -631,7 +631,7 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
next_poll_station, next_poll_station,
mstp_port->EventCount, mstp_port->EventCount,
mstp_port->TokenCount, 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
@@ -654,7 +654,7 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
/* In the IDLE state, the node waits for a frame. */ /* In the IDLE state, the node waits for a frame. */
case MSTP_MASTER_STATE_IDLE: case MSTP_MASTER_STATE_IDLE:
/* LostToken */ /* LostToken */
if (mstp_port->SilenceTimer >= Tno_token) { if (mstp_port->SilenceTimer() >= Tno_token) {
/* assume that the token has been lost */ /* assume that the token has been lost */
mstp_port->EventCount = 0; /* Addendum 135-2004d-8 */ mstp_port->EventCount = 0; /* Addendum 135-2004d-8 */
mstp_port->master_state = MSTP_MASTER_STATE_NO_TOKEN; mstp_port->master_state = MSTP_MASTER_STATE_NO_TOKEN;
@@ -673,7 +673,7 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
mstp_port->DestinationAddress, mstp_port->DestinationAddress,
mstp_port->DataLength, mstp_port->DataLength,
mstp_port->FrameCount, 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! */
@@ -744,7 +744,7 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
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 = MSTP_MASTER_STATE_DONE_WITH_TOKEN;
transition_now = true; transition_now = true;
} else if (mstp_port->SilenceTimer > Tusage_delay) { } else if (mstp_port->SilenceTimer() > Tusage_delay) {
/* Don't send it if we are too late in getting out. */ /* Don't send it if we are too late in getting out. */
/* Don't worry. If we missed our timing deadline, /* Don't worry. If we missed our timing deadline,
another token will be sent */ another token will be sent */
@@ -781,7 +781,7 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
/* In the WAIT_FOR_REPLY state, the node waits for */ /* In the WAIT_FOR_REPLY state, the node waits for */
/* a reply from another node. */ /* a reply from another node. */
case MSTP_MASTER_STATE_WAIT_FOR_REPLY: case MSTP_MASTER_STATE_WAIT_FOR_REPLY:
if (mstp_port->SilenceTimer >= Treply_timeout) { if (mstp_port->SilenceTimer() >= Treply_timeout) {
/* ReplyTimeout */ /* ReplyTimeout */
/* assume that the request has failed */ /* assume that the request has failed */
mstp_port->FrameCount = mstp_port->Nmax_info_frames; mstp_port->FrameCount = mstp_port->Nmax_info_frames;
@@ -917,7 +917,7 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
/* The PASS_TOKEN state listens for a successor to begin using */ /* The PASS_TOKEN state listens for a successor to begin using */
/* the token that this node has just attempted to pass. */ /* the token that this node has just attempted to pass. */
case MSTP_MASTER_STATE_PASS_TOKEN: case MSTP_MASTER_STATE_PASS_TOKEN:
if (mstp_port->SilenceTimer <= Tusage_timeout) { if (mstp_port->SilenceTimer() <= Tusage_timeout) {
if (mstp_port->EventCount > Nmin_octets) { 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. */
@@ -957,13 +957,13 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
} }
} }
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 */
/* than Tno_token, indicating that there has been no network activity */ /* than Tno_token, indicating that there has been no network activity */
/* for that period of time. The timeout is continued to determine */ /* for that period 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 * mstp_port->This_Station); my_timeout = Tno_token + (Tslot * mstp_port->This_Station);
if (mstp_port->SilenceTimer < my_timeout) { if (mstp_port->SilenceTimer() < my_timeout) {
if (mstp_port->EventCount > Nmin_octets) { if (mstp_port->EventCount > Nmin_octets) {
/* SawFrame */ /* SawFrame */
/* Some other node exists at a lower address. */ /* Some other node exists at a lower address. */
@@ -974,7 +974,7 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
} else { } else {
ns_timeout = ns_timeout =
Tno_token + (Tslot * (mstp_port->This_Station + 1)); Tno_token + (Tslot * (mstp_port->This_Station + 1));
if (mstp_port->SilenceTimer < ns_timeout) { if (mstp_port->SilenceTimer() < ns_timeout) {
/* GenerateToken */ /* GenerateToken */
/* Assume that this node is the lowest numerical address */ /* Assume that this node is the lowest numerical address */
/* on the network and is empowered to create a token. */ /* on the network and is empowered to create a token. */
@@ -1026,7 +1026,7 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
transition_now = true; transition_now = true;
} }
mstp_port->ReceivedValidFrame = false; mstp_port->ReceivedValidFrame = false;
} else if ((mstp_port->SilenceTimer > Tusage_timeout) || } else if ((mstp_port->SilenceTimer() > Tusage_timeout) ||
(mstp_port->ReceivedInvalidFrame == true)) { (mstp_port->ReceivedInvalidFrame == true)) {
if (mstp_port->SoleMaster == true) { if (mstp_port->SoleMaster == true) {
/* SoleMaster */ /* SoleMaster */
@@ -1084,7 +1084,7 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
see if the next message was that same APDU type see if the next message was that same APDU type
along with the matching src/dest and invoke ID */ along with the matching src/dest and invoke ID */
/* FIXME: we could use 2 queues: one for DER and one for non-DER */ /* FIXME: we could use 2 queues: one for DER and one for non-DER */
if ((mstp_port->SilenceTimer <= Treply_delay) && if ((mstp_port->SilenceTimer() <= Treply_delay) &&
mstp_port->TxReady) { mstp_port->TxReady) {
/* Reply */ /* Reply */
/* If a reply is available from the higher layers */ /* If a reply is available from the higher layers */
@@ -1139,6 +1139,7 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
/* note: Nmax_master assumed to be set (default=127) */ /* note: Nmax_master assumed to be set (default=127) */
/* note: InputBuffer and InputBufferSize assumed to be set */ /* note: InputBuffer and InputBufferSize assumed to be set */
/* note: OutputBuffer and OutputBufferSize assumed to be set */ /* note: OutputBuffer and OutputBufferSize assumed to be set */
/* note: SilenceTimer and SilenceTimerReset assumed to be set */
void MSTP_Init(volatile struct mstp_port_struct_t *mstp_port) void MSTP_Init(volatile struct mstp_port_struct_t *mstp_port)
{ {
if (mstp_port) { if (mstp_port) {
@@ -1162,7 +1163,7 @@ void MSTP_Init(volatile struct mstp_port_struct_t *mstp_port)
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->SilenceTimer = 0; mstp_port->SilenceTimerReset();
mstp_port->SoleMaster = false; mstp_port->SoleMaster = false;
mstp_port->SourceAddress = 0; mstp_port->SourceAddress = 0;
mstp_port->TokenCount = 0; mstp_port->TokenCount = 0;
@@ -1174,9 +1175,12 @@ void MSTP_Init(volatile struct mstp_port_struct_t *mstp_port)
mstp_port->InputBufferSize = sizeof(InputBuffer); mstp_port->InputBufferSize = sizeof(InputBuffer);
mstp_port->OutputBuffer = &OutputBuffer[0]; mstp_port->OutputBuffer = &OutputBuffer[0];
mstp_port->OutputBufferSize = sizeof(OutputBuffer); mstp_port->OutputBufferSize = sizeof(OutputBuffer);
/* these are adjustable, so you must set these in dlmstp */ /* FIXME: these are adjustable, so you must set these in dlmstp */
mstp_port->Nmax_info_frames = DEFAULT_MAX_INFO_FRAMES; mstp_port->Nmax_info_frames = DEFAULT_MAX_INFO_FRAMES;
mstp_port->Nmax_master = DEFAULT_MAX_MASTER; mstp_port->Nmax_master = DEFAULT_MAX_MASTER;
/* FIXME: point to functions */
mstp_port->SilenceTimer = Timer_Silence;
mstp_port=>SilenceTimerReset = Timer_Silence_Reset;
#endif #endif
} }
} }
@@ -1259,6 +1263,16 @@ uint16_t MSTP_Get_Send(
return 0; return 0;
} }
uint16_t SilenceTime = 0;
static uint16_t Timer_Silence(void)
{
return SilenceTime;
}
static void Timer_Silence_Reset(void)
{
SilenceTime = 0;
}
void testReceiveNodeFSM(Test * pTest) void testReceiveNodeFSM(Test * pTest)
{ {
volatile struct mstp_port_struct_t mstp_port; /* port data */ volatile struct mstp_port_struct_t mstp_port; /* port data */
@@ -1269,12 +1283,15 @@ void testReceiveNodeFSM(Test * pTest)
unsigned len; /* used for the size of the message packet */ unsigned len; /* used for the size of the message packet */
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] = { 0 }; uint8_t buffer[MAX_MPDU] = { 0 };
uint8_t data[MAX_MPDU - 8 /*header */ - 2 /*CRC*/] = { 0 }; uint8_t data[MAX_PDU] = { 0 };
uint8_t dummy[8] = {1,2,3,4,5,6,7,8};
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.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_port.Nmax_master = 127;
@@ -1283,12 +1300,12 @@ void testReceiveNodeFSM(Test * pTest)
/* 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;
mstp_port.SilenceTimer = 255; SilenceTime = 255;
mstp_port.EventCount = 0; mstp_port.EventCount = 0;
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.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);
@@ -1298,7 +1315,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
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);
@@ -1308,11 +1325,11 @@ void testReceiveNodeFSM(Test * pTest)
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);
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_PREAMBLE); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
/* force the timeout */ /* force the timeout */
mstp_port.SilenceTimer = 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);
@@ -1322,7 +1339,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
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_PREAMBLE); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
/* force the error */ /* force the error */
@@ -1330,7 +1347,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
@@ -1340,7 +1357,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
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_PREAMBLE); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
MSTP_Receive_Frame_FSM(&mstp_port); MSTP_Receive_Frame_FSM(&mstp_port);
@@ -1355,7 +1372,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
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_PREAMBLE); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
/* repeated preamble1 */ /* repeated preamble1 */
@@ -1364,7 +1381,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
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_PREAMBLE); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
/* bad data */ /* bad data */
@@ -1373,7 +1390,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
@@ -1383,7 +1400,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
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_PREAMBLE); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
MSTP_Receive_Frame_FSM(&mstp_port); MSTP_Receive_Frame_FSM(&mstp_port);
@@ -1393,13 +1410,13 @@ void testReceiveNodeFSM(Test * pTest)
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);
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 == 0); ct_test(pTest, mstp_port.Index == 0);
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 */
mstp_port.SilenceTimer = 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);
@@ -1410,7 +1427,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
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_PREAMBLE); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
MSTP_Receive_Frame_FSM(&mstp_port); MSTP_Receive_Frame_FSM(&mstp_port);
@@ -1420,7 +1437,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
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 == 0); ct_test(pTest, mstp_port.Index == 0);
ct_test(pTest, mstp_port.HeaderCRC == 0xFF); ct_test(pTest, mstp_port.HeaderCRC == 0xFF);
@@ -1430,7 +1447,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
@@ -1440,7 +1457,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
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_PREAMBLE); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_PREAMBLE);
MSTP_Receive_Frame_FSM(&mstp_port); MSTP_Receive_Frame_FSM(&mstp_port);
@@ -1450,7 +1467,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
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 == 0); ct_test(pTest, mstp_port.Index == 0);
ct_test(pTest, mstp_port.HeaderCRC == 0xFF); ct_test(pTest, mstp_port.HeaderCRC == 0xFF);
@@ -1469,7 +1486,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
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 == 1); ct_test(pTest, mstp_port.Index == 1);
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
@@ -1481,7 +1498,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
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 == 2); ct_test(pTest, mstp_port.Index == 2);
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
@@ -1493,7 +1510,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
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 == 3); ct_test(pTest, mstp_port.Index == 3);
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
@@ -1505,7 +1522,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
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 == 4); ct_test(pTest, mstp_port.Index == 4);
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
@@ -1517,7 +1534,7 @@ void testReceiveNodeFSM(Test * pTest)
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);
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, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_HEADER);
@@ -1529,16 +1546,12 @@ void testReceiveNodeFSM(Test * pTest)
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);
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_HEADER_CRC); mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
ct_test(pTest, mstp_port.HeaderCRC == 0x55); ct_test(pTest, mstp_port.HeaderCRC == 0x55);
/* NotForUs */
MSTP_Receive_Frame_FSM(&mstp_port);
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
/* BadCRC in header check */ /* BadCRC in header check */
mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedInvalidFrame = false;
mstp_port.ReceivedValidFrame = false; mstp_port.ReceivedValidFrame = false;
@@ -1555,12 +1568,9 @@ void testReceiveNodeFSM(Test * pTest)
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);
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_HEADER_CRC);
MSTP_Receive_Frame_FSM(&mstp_port);
ct_test(pTest, mstp_port.ReceivedInvalidFrame == true); ct_test(pTest, mstp_port.ReceivedInvalidFrame == true);
ct_test(pTest, mstp_port.ReceivedValidFrame == false); ct_test(pTest, mstp_port.ReceivedValidFrame == false);
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
@@ -1579,12 +1589,9 @@ void testReceiveNodeFSM(Test * pTest)
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);
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_HEADER_CRC);
MSTP_Receive_Frame_FSM(&mstp_port);
ct_test(pTest, mstp_port.ReceivedInvalidFrame == false); ct_test(pTest, mstp_port.ReceivedInvalidFrame == false);
ct_test(pTest, mstp_port.ReceivedValidFrame == true); ct_test(pTest, mstp_port.ReceivedValidFrame == true);
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
@@ -1592,7 +1599,9 @@ void testReceiveNodeFSM(Test * pTest)
/* FrameTooLong */ /* FrameTooLong */
mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedInvalidFrame = false;
mstp_port.ReceivedValidFrame = false; mstp_port.ReceivedValidFrame = false;
len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, my_mac, /* destination */ len = MSTP_Create_Frame(buffer, sizeof(buffer),
FRAME_TYPE_TOKEN,
my_mac, /* destination */
my_mac, /* source */ my_mac, /* source */
NULL, /* data */ NULL, /* data */
0); /* data size */ 0); /* data size */
@@ -1605,12 +1614,9 @@ void testReceiveNodeFSM(Test * pTest)
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);
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_HEADER_CRC);
MSTP_Receive_Frame_FSM(&mstp_port);
ct_test(pTest, mstp_port.ReceivedInvalidFrame == true); ct_test(pTest, mstp_port.ReceivedInvalidFrame == true);
ct_test(pTest, mstp_port.ReceivedValidFrame == false); ct_test(pTest, mstp_port.ReceivedValidFrame == false);
ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE); ct_test(pTest, mstp_port.receive_state == MSTP_RECEIVE_STATE_IDLE);
@@ -1619,7 +1625,9 @@ void testReceiveNodeFSM(Test * pTest)
mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedInvalidFrame = false;
mstp_port.ReceivedValidFrame = false; mstp_port.ReceivedValidFrame = false;
memset(data, 0, sizeof(data)); memset(data, 0, sizeof(data));
len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_PROPRIETARY_MIN, my_mac, /* destination */ len = MSTP_Create_Frame(buffer, sizeof(buffer),
FRAME_TYPE_PROPRIETARY_MIN,
my_mac, /* destination */
my_mac, /* source */ my_mac, /* source */
data, /* data */ data, /* data */
sizeof(data)); /* data size */ sizeof(data)); /* data size */
@@ -1651,8 +1659,11 @@ void testMasterNodeFSM(Test * pTest)
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.Nmax_master = 127;
MSTP_Port.SilenceTimer = Timer_Silence;
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);
/* FIXME: write a unit test for the Master Node State Machine */
} }
+4 -1
View File
@@ -192,7 +192,10 @@ struct mstp_port_struct_t {
/* Since the timer resolution is limited and the timer is not necessarily */ /* Since the timer resolution is limited and the timer is not necessarily */
/* synchronized to other machine events, a timer value of N will actually */ /* synchronized to other machine events, a timer value of N will actually */
/* denote intervals between N-1 and N */ /* denote intervals between N-1 and N */
uint16_t SilenceTimer; /* Note: done here as functions - put into timer task or ISR
so that you can be atomic on 8 bit microcontrollers */
uint16_t (*SilenceTimer)(void);
void (*SilenceTimerReset)(void);
/* A timer used to measure and generate Reply Postponed frames. It is */ /* A timer used to measure and generate Reply Postponed frames. It is */
/* incremented by a timer process and is cleared by the Master Node State */ /* incremented by a timer process and is cleared by the Master Node State */
+4 -8
View File
@@ -33,6 +33,7 @@
#include "npdu.h" #include "npdu.h"
/* This file has been customized for use with the AT91SAM7S-EK */ /* This file has been customized for use with the AT91SAM7S-EK */
#include "board.h" #include "board.h"
#include "timer.h"
/* Number of MS/TP Packets Rx/Tx */ /* Number of MS/TP Packets Rx/Tx */
uint16_t MSTP_Packets = 0; uint16_t MSTP_Packets = 0;
@@ -46,13 +47,6 @@ static volatile struct mstp_port_struct_t MSTP_Port;
static uint8_t TxBuffer[MAX_MPDU]; static uint8_t TxBuffer[MAX_MPDU];
static uint8_t RxBuffer[MAX_MPDU]; static uint8_t RxBuffer[MAX_MPDU];
#define INCREMENT_AND_LIMIT_UINT16(x) {if (x < 0xFFFF) x++;}
volatile uint16_t *dlmstp_millisecond_timer_address(void)
{
return &(MSTP_Port.SilenceTimer);
}
void dlmstp_copy_bacnet_address(BACNET_ADDRESS * dest, BACNET_ADDRESS * src) void dlmstp_copy_bacnet_address(BACNET_ADDRESS * dest, BACNET_ADDRESS * src)
{ {
int i = 0; int i = 0;
@@ -83,8 +77,10 @@ bool dlmstp_init(char *ifname)
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_Init.SilenceTimer = Timer_Silence;
MSTP_Init.SilenceTimerReset = Timer_Silence_Reset;
MSTP_Init(&MSTP_Port); MSTP_Init(&MSTP_Port);
return true; return true;
} }
+18 -6
View File
@@ -45,11 +45,12 @@
#include "board.h" #include "board.h"
#include "dlmstp.h" #include "dlmstp.h"
// global variable counts interrupts /* global variable counts interrupts */
volatile unsigned long Timer_Milliseconds; volatile unsigned long Timer_Milliseconds;
volatile uint16_t *pTimer_MSTP_Silence; /* MS/TP Silence Timer */
static volatile uint16_t SilenceTime;
void Timer0_Setup(int milliseconds) { static void Timer0_Setup(int milliseconds) {
// TC Block Control Register TC_BCR (read/write) // TC Block Control Register TC_BCR (read/write)
// //
// |------------------------------------------------------------------|------| // |------------------------------------------------------------------|------|
@@ -296,7 +297,7 @@ void Timer0_Setup(int milliseconds) {
// Modified by Steve Karg // Modified by Steve Karg
// simplified and changed to a millisecond count-up timer // simplified and changed to a millisecond count-up timer
// ***************************************************************************** // *****************************************************************************
void Timer0IrqHandler (void) { static void Timer0IrqHandler (void) {
volatile AT91PS_TC pTC = AT91C_BASE_TC0; // pointer to timer channel 0 register structure volatile AT91PS_TC pTC = AT91C_BASE_TC0; // pointer to timer channel 0 register structure
unsigned int dummy; // temporary unsigned int dummy; // temporary
@@ -305,10 +306,21 @@ void Timer0IrqHandler (void) {
dummy = pTC->TC_SR; dummy = pTC->TC_SR;
// increment the tick count // increment the tick count
Timer_Milliseconds++; Timer_Milliseconds++;
if ((*pTimer_MSTP_Silence) < 0xFFFF) if (SilenceTime < 0xFFFF)
(*pTimer_MSTP_Silence)++; SilenceTime++;
} }
uint16_t Timer_Silence(void)
{
return SilenceTime;
}
void Timer_Silence_Reset(void)
{
SilenceTime = 0;
}
// ***************************************************************************** // *****************************************************************************
// //
// Timer 0 Initialization // Timer 0 Initialization
+44
View File
@@ -0,0 +1,44 @@
/**************************************************************************
*
* Copyright (C) 2007 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#ifndef TIMER_H
#define TIMER_H
#include <stdint.h>
extern volatile unsigned long Timer_Milliseconds;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void TimerInit(void);
uint16_t Timer_Silence(void);
void Timer_Silence_Reset(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+1 -4
View File
@@ -75,7 +75,7 @@ void init(void)
RS485_Set_Baud_Rate(38400); RS485_Set_Baud_Rate(38400);
/* Configure Timer0 for millisecond timer */ /* Configure Timer0 for millisecond timer */
timer_initialize(); Timer_Initialize();
/* Enable global interrupts */ /* Enable global interrupts */
sei(); sei();
@@ -86,9 +86,6 @@ void task_milliseconds(void)
while (Timer_Milliseconds) { while (Timer_Milliseconds) {
Timer_Milliseconds--; Timer_Milliseconds--;
/* add other millisecond timer tasks here */ /* add other millisecond timer tasks here */
#if defined(BACDL_MSTP)
dlmstp_millisecond_timer();
#endif
} }
} }
+2 -2
View File
@@ -128,7 +128,7 @@ void RS485_Send_Frame(
if (!turnaround_time) { if (!turnaround_time) {
turnaround_time = 1; turnaround_time = 1;
} }
while (mstp_port->SilenceTimer < turnaround_time) { while (mstp_port->SilenceTimer() < turnaround_time) {
/* do nothing - wait for timer to increment */ /* do nothing - wait for timer to increment */
}; };
} }
@@ -146,7 +146,7 @@ void RS485_Send_Frame(
} }
/* per MSTP spec */ /* per MSTP spec */
if (mstp_port) { if (mstp_port) {
mstp_port->SilenceTimer = 0; mstp_port->SilenceTimerReset();
} }
return; return;
+30 -1
View File
@@ -37,9 +37,11 @@
#define TIMER_COUNT (0xFF-TIMER_TICKS) #define TIMER_COUNT (0xFF-TIMER_TICKS)
/* Global variable millisecond timer - used by main.c for timers task */ /* Global variable millisecond timer - used by main.c for timers task */
volatile uint8_t Timer_Milliseconds = 0; volatile uint8_t Timer_Milliseconds = 0;
/* MS/TP Silence Timer */
static volatile uint16_t SilenceTime;
/* Configure the Timer */ /* Configure the Timer */
void timer_initialize(void) void Timer_Initialize(void)
{ {
/* Normal Operation */ /* Normal Operation */
TCCR1A = 0; TCCR1A = 0;
@@ -76,4 +78,31 @@ ISR(TIMER0_OVF_vect)
/* Update the global timer */ /* Update the global timer */
if (Timer_Milliseconds < 0xFF) if (Timer_Milliseconds < 0xFF)
Timer_Milliseconds++; Timer_Milliseconds++;
if (SilenceTime < 0xFFFF)
SilenceTime++;
}
/* Public access to the Silence Timer */
uint16_t Timer_Silence(void)
{
uint16_t timer;
uint8_t sreg;
sreg = SREG;
cli();
timer = SilenceTime;
SREG = sreg;
return timer;
}
/* Public reset of the Silence Timer */
void Timer_Silence_Reset(void)
{
uint8_t sreg;
sreg = SREG;
cli();
SilenceTime = 0;
SREG = sreg;
} }
+11 -1
View File
@@ -27,6 +27,16 @@
extern volatile uint8_t Timer_Milliseconds; extern volatile uint8_t Timer_Milliseconds;
void timer_initialize(void); #ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void Timer_Initialize(void);
uint16_t Timer_Silence(void);
void Timer_Silence_Reset(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif #endif
+13 -2
View File
@@ -58,12 +58,21 @@ volatile struct mstp_port_struct_t MSTP_Port;
/* buffers needed by mstp port struct */ /* buffers needed by mstp port struct */
static uint8_t TxBuffer[MAX_MPDU]; static uint8_t TxBuffer[MAX_MPDU];
static uint8_t RxBuffer[MAX_MPDU]; static uint8_t RxBuffer[MAX_MPDU];
/* Timer that indicates line silence - and functions */
static uint16_t SilenceTime;
#define INCREMENT_AND_LIMIT_UINT16(x) {if (x < 0xFFFF) x++;} #define INCREMENT_AND_LIMIT_UINT16(x) {if (x < 0xFFFF) x++;}
static uint16_t Timer_Silence(void)
{
return SilenceTime;
}
static void Timer_Silence_Reset(void)
{
SilenceTime = 0;
}
void dlmstp_millisecond_timer(void) void dlmstp_millisecond_timer(void)
{ {
INCREMENT_AND_LIMIT_UINT16(MSTP_Port.SilenceTimer); INCREMENT_AND_LIMIT_UINT16(SilenceTime);
} }
static void *dlmstp_milliseconds_task(void *pArg) static void *dlmstp_milliseconds_task(void *pArg)
@@ -590,6 +599,8 @@ bool dlmstp_init(char *ifname)
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.SilenceTimerReset = Timer_Silence_Reset;
MSTP_Init(&MSTP_Port); MSTP_Init(&MSTP_Port);
#if 0 #if 0
/* FIXME: implement your data storage */ /* FIXME: implement your data storage */
+2 -2
View File
@@ -157,7 +157,7 @@ void RS485_Send_Frame(
turnaround_time = 2; turnaround_time = 2;
else else
turnaround_time = 1; turnaround_time = 1;
while (mstp_port->SilenceTimer < turnaround_time) { while (mstp_port->SilenceTimer() < turnaround_time) {
/* do nothing - wait for timer to increment */ /* do nothing - wait for timer to increment */
sched_yield(); sched_yield();
}; };
@@ -173,7 +173,7 @@ void RS485_Send_Frame(
/* per MSTP spec, sort of */ /* per MSTP spec, sort of */
if (mstp_port) { if (mstp_port) {
mstp_port->SilenceTimer = 0; mstp_port->SilenceTimerReset();
} }
return; return;
+13 -2
View File
@@ -53,12 +53,21 @@ volatile struct mstp_port_struct_t MSTP_Port;
/* buffers needed by mstp port struct */ /* buffers needed by mstp port struct */
static uint8_t TxBuffer[MAX_MPDU]; static uint8_t TxBuffer[MAX_MPDU];
static uint8_t RxBuffer[MAX_MPDU]; static uint8_t RxBuffer[MAX_MPDU];
/* Timer that indicates line silence - and functions */
static uint16_t SilenceTime;
#define INCREMENT_AND_LIMIT_UINT16(x) {if (x < 0xFFFF) x++;} #define INCREMENT_AND_LIMIT_UINT16(x) {if (x < 0xFFFF) x++;}
static uint16_t Timer_Silence(void)
{
return SilenceTime;
}
static void Timer_Silence_Reset(void)
{
SilenceTime = 0;
}
void dlmstp_millisecond_timer(void) void dlmstp_millisecond_timer(void)
{ {
INCREMENT_AND_LIMIT_UINT16(MSTP_Port.SilenceTimer); INCREMENT_AND_LIMIT_UINT16(SilenceTime);
} }
void dlmstp_reinit(void) void dlmstp_reinit(void)
@@ -435,6 +444,8 @@ bool dlmstp_init(char *ifname)
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_Init.SilenceTimer = Timer_Silence;
MSTP_Init.SilenceTimerReset = Timer_Silence_Reset;
MSTP_Init(&MSTP_Port); MSTP_Init(&MSTP_Port);
#if 0 #if 0
uint8_t data; uint8_t data;
+2 -4
View File
@@ -279,7 +279,6 @@ void RS485_Send_Frame(
{ {
DWORD dwWritten = 0; DWORD dwWritten = 0;
#if 0
if (mstp_port) { if (mstp_port) {
uint32_t baud; uint32_t baud;
uint8_t turnaround_time; uint8_t turnaround_time;
@@ -291,16 +290,15 @@ void RS485_Send_Frame(
turnaround_time = 2; turnaround_time = 2;
else else
turnaround_time = 1; turnaround_time = 1;
while (mstp_port->SilenceTimer < turnaround_time) { while (mstp_port->SilenceTimer() < turnaround_time) {
/* do nothing - wait for timer to increment */ /* do nothing - wait for timer to increment */
}; };
} }
#endif
WriteFile(RS485_Handle, buffer, nbytes, &dwWritten, NULL); WriteFile(RS485_Handle, buffer, nbytes, &dwWritten, NULL);
/* per MSTP spec, reset SilenceTimer after each byte is sent */ /* per MSTP spec, reset SilenceTimer after each byte is sent */
if (mstp_port) { if (mstp_port) {
mstp_port->SilenceTimer = 0; mstp_port->SilenceTimerReset();
} }
return; return;
+1 -1
View File
@@ -33,4 +33,4 @@
####COPYRIGHTEND####*/ ####COPYRIGHTEND####*/
#include "version.h" #include "version.h"
char *BACnet_Version = "0.3.4"; char *BACnet_Version = BACNET_VERSION_TEXT;
+3 -1
View File
@@ -38,7 +38,9 @@
#ifndef BACNET_VERSION #ifndef BACNET_VERSION
#define BACNET_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z)) #define BACNET_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
#endif #endif
#define BACNET_VERSION_CODE BACNET_VERSION(0,3,4)
#define BACNET_VERSION_TEXT "0.3.5"
#define BACNET_VERSION_CODE BACNET_VERSION(0,3,5)
#define BACNET_VERSION_MAJOR ((BACNET_VERSION_CODE>>16)&0xFF) #define BACNET_VERSION_MAJOR ((BACNET_VERSION_CODE>>16)&0xFF)
#define BACNET_VERSION_MINOR ((BACNET_VERSION_CODE>>8)&0xFF) #define BACNET_VERSION_MINOR ((BACNET_VERSION_CODE>>8)&0xFF)
#define BACNET_VERSION_MAINTENANCE (BACNET_VERSION_CODE&0xFF) #define BACNET_VERSION_MAINTENANCE (BACNET_VERSION_CODE&0xFF)