Fixed a few more bugs in MS/TP, and leaned it out some more.

This commit is contained in:
skarg
2006-08-29 20:42:26 +00:00
parent 0e2585e044
commit 42e0033c98
7 changed files with 156 additions and 108 deletions
+11 -14
View File
@@ -107,19 +107,6 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
return bytes_sent;
}
void dlmstp_task(void)
{
RS485_Check_UART_Data(&MSTP_Port);
/* only do receive state machine while we don't have a frame */
if ((MSTP_Port.ReceivedValidFrame == false) &&
(MSTP_Port.ReceivedInvalidFrame == false)) {
MSTP_Receive_Frame_FSM(&MSTP_Port);
}
/* only do master state machine while rx is idle */
if (MSTP_Port.receive_state == MSTP_RECEIVE_STATE_IDLE)
MSTP_Master_Node_FSM(&MSTP_Port);
}
/* called about once a millisecond */
void dlmstp_millisecond_timer(void)
{
@@ -135,7 +122,17 @@ uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
{
uint16_t pdu_len = 0;
(void) timeout;
(void) timeout;
/* only do receive state machine while we don't have a frame */
if ((MSTP_Port.ReceivedValidFrame == false) &&
(MSTP_Port.ReceivedInvalidFrame == false)) {
RS485_Check_UART_Data(&MSTP_Port);
MSTP_Receive_Frame_FSM(&MSTP_Port);
}
/* only do master state machine while rx is idle */
if (MSTP_Port.receive_state == MSTP_RECEIVE_STATE_IDLE) {
while (MSTP_Master_Node_FSM(&MSTP_Port)) {};
}
/* see if there is a packet available */
if (Receive_Buffer.ready) {
memmove(src, &Receive_Buffer.address,
+3 -5
View File
@@ -90,7 +90,7 @@ void RTOS_Initialize(void)
{
/* allow OS to setup IRQ 1 by using a dummy call */
(void) kbhit();
RTKernelInit(0); /* get the kernel going */
RTKernelInit(5); /* get the kernel going */
RTKeybrdInit();
//(void)CPUMoniInit(); /* not needed - just monitor idle task */
RTComInit();
@@ -125,7 +125,7 @@ void RTOS_Initialize(void)
RTCMOSSetSystemTime(); /* get the right time-of-day */
/* create timer tick task */
RTKCreateTask(millisecond_task, 1, 1024 * 8, "millisec task");
RTKCreateTask(millisecond_task, 16, 1024 * 8, "millisec task");
}
int main(int argc, char *argv[])
@@ -156,9 +156,7 @@ int main(int argc, char *argv[])
/* loop forever */
for (;;) {
/* input */
#ifdef BACDL_MSTP
dlmstp_task();
#endif
/* returns 0 bytes on timeout */
pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
/* process */
+1 -1
View File
@@ -25,7 +25,7 @@ PRODUCT_EXE = $(PRODUCT).exe
#DEFINES = -DDOC;BIG_ENDIAN=0;TSM_ENABLED=1;PRINT_ENABLED=1;BACDL_BIP=1
#DEFINES = -DDOC;BIG_ENDIAN=0;TSM_ENABLED=1;PRINT_ENABLED=1;BACDL_ETHERNET=1
#DEFINES = -DDOC;BIG_ENDIAN=0;TSM_ENABLED=1;PRINT_ENABLED=1;BACDL_ARCNET=1
DEFINES = -DDOC;BIG_ENDIAN=0;TSM_ENABLED=1;PRINT_ENABLED=1;BACDL_MSTP=1
DEFINES = -DDOC;BIG_ENDIAN=0;TSM_ENABLED=1;PRINT_ENABLED=0;BACDL_MSTP=1
SRCS = main.c \
ethernet.c \
+42 -12
View File
@@ -22,7 +22,7 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#define PRINT_ENABLED_RS485 1
#define PRINT_ENABLED_RS485 0
#include <stdint.h>
#include <rtkernel.h>
@@ -48,6 +48,36 @@ static long RS485_Base = 0;
/* hardware IRQ number */
static long RS485_IRQ_Number = 0;
#if PRINT_ENABLED_RS485
static FineTime RS485_Debug_Transmit_Timer;
#endif
#if PRINT_ENABLED_RS485
void RS485_Print_Frame(int port,
FineTime timer,
uint8_t * buffer, /* frame to send (up to 501 bytes of data) */
uint16_t nbytes)
{
uint16_t i; // byte counter
unsigned long duration; // measures the time from last output to this one
unsigned long seconds;
unsigned long milliseconds;
duration = ElapsedMilliSecs(timer);
seconds = duration / 1000U;
milliseconds = duration - (seconds * 1000U);
fprintf(stderr,"%0lu.%03lu: COM%d:",seconds,milliseconds,port+1);
for (i = 0; i < nbytes; i++)
{
unsigned value;
value = buffer[i];
fprintf(stderr," %02X",value);
}
fprintf(stderr,"\n");
fflush(stderr);
}
#endif
static void RS485_Standard_Port_Settings(long port, long *pIRQ,
long *pBase)
{
@@ -119,6 +149,9 @@ static RS485_Open_Port(int port, /* COM port number - COM1 = 0 */
void RS485_Initialize(void)
{
#if PRINT_ENABLED_RS485
MarkTime(&RS485_Debug_Transmit_Timer);
#endif
RS485_Standard_Port_Settings(RS485_Port, &RS485_IRQ_Number,
&RS485_Base);
RS485_Open_Port(RS485_Port, RS485_Baud, RS485_Base, RS485_IRQ_Number);
@@ -137,19 +170,16 @@ void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port
while (!(LineStatus(RS485_Port) & TX_SHIFT_EMPTY))
RTKScheduler();
RS485_RECEIVE_ENABLE(RS485_Port);
/* SilenceTimer is cleared by the Receive State Machine when
activity is detected and by the SendFrame procedure as each
octet is transmitted. */
mstp_port->SilenceTimer = 0;
#if PRINT_ENABLED_RS485
{
int i = 0;
fprintf(stderr, "RS485 Tx:");
for (i = 0; i < nbytes; i++) {
fprintf(stderr, " %02X", buffer[i]);
if ((!(i % 20)) && (i != 0)) {
fprintf(stderr, "\r\n ");
}
}
fprintf(stderr, "\r\n");
}
RS485_Print_Frame(RS485_Port,
RS485_Debug_Transmit_Timer,
buffer, /* frame to send (up to 501 bytes of data) */
nbytes);
MarkTime(&RS485_Debug_Transmit_Timer);
#endif
return;