Updated files for PIC18F port.

This commit is contained in:
skarg
2006-08-29 20:57:30 +00:00
parent 6e67d7388d
commit 19a823350e
2 changed files with 53 additions and 19 deletions
+53 -17
View File
@@ -26,6 +26,9 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#if PRINT_ENABLED
#include <stdio.h>
#endif
#include "bacdef.h" #include "bacdef.h"
#include "mstp.h" #include "mstp.h"
#include "dlmstp.h" #include "dlmstp.h"
@@ -60,9 +63,8 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
uint8_t * pdu, /* any data to be sent - may be null */ uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len) unsigned pdu_len)
{ /* number of bytes of data */ { /* number of bytes of data */
bool status;
int bytes_sent = 0; int bytes_sent = 0;
int npdu_len = 0; unsigned npdu_len = 0;
uint8_t frame_type = 0; uint8_t frame_type = 0;
uint8_t destination = 0; /* destination address */ uint8_t destination = 0; /* destination address */
BACNET_ADDRESS src; BACNET_ADDRESS src;
@@ -92,7 +94,8 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
return -4; return -4;
} }
memmove(&PDU_Buffer[npdu_len], pdu, pdu_len); memmove(&PDU_Buffer[npdu_len], pdu, pdu_len);
bytes_sent = MSTP_Create_Frame(&MSTP_Port.TxBuffer[0], bytes_sent = MSTP_Create_Frame(
(uint8_t *) & MSTP_Port.TxBuffer[0],
sizeof(MSTP_Port.TxBuffer), sizeof(MSTP_Port.TxBuffer),
MSTP_Port.TxFrameType, MSTP_Port.TxFrameType,
destination, destination,
@@ -104,15 +107,6 @@ int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
return bytes_sent; return bytes_sent;
} }
void dlmstp_task(void)
{
RS485_Check_UART_Data(&MSTP_Port);
MSTP_Receive_Frame_FSM(&MSTP_Port);
RS485_Process_Tx_Message();
MSTP_Master_Node_FSM(&MSTP_Port);
}
/* called about once a millisecond */ /* called about once a millisecond */
void dlmstp_millisecond_timer(void) void dlmstp_millisecond_timer(void)
{ {
@@ -128,7 +122,17 @@ uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
{ {
uint16_t pdu_len = 0; 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 */ /* see if there is a packet available */
if (Receive_Buffer.ready) { if (Receive_Buffer.ready) {
memmove(src, &Receive_Buffer.address, memmove(src, &Receive_Buffer.address,
@@ -141,14 +145,46 @@ uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */
return pdu_len; return pdu_len;
} }
void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src, uint8_t mstp_address)
{
int i = 0;
if (mstp_address == MSTP_BROADCAST_ADDRESS) {
/* mac_len = 0 if broadcast address */
src->mac_len = 0;
src->mac[0] = 0;
} else {
src->mac_len = 1;
src->mac[0] = mstp_address;
}
/* fill with 0's starting with index 1; index 0 filled above */
for (i = 1; i < MAX_MAC_LEN; i++) {
src->mac[i] = 0;
}
src->net = 0;
src->len = 0;
for (i = 0; i < MAX_MAC_LEN; i++) {
src->adr[i] = 0;
}
}
/* for the MS/TP state machine to use for putting received data */ /* for the MS/TP state machine to use for putting received data */
uint16_t dlmstp_put_receive(BACNET_ADDRESS * src, /* source address */ uint16_t dlmstp_put_receive(uint8_t src, /* source MS/TP address */
uint8_t * pdu, /* PDU data */ uint8_t * pdu, /* PDU data */
uint16_t pdu_len) uint16_t pdu_len)
{ {
memmove(&Receive_Buffer.address, src, sizeof(Receive_Buffer.address)); if (Receive_Buffer.ready) {
Receive_Buffer.pdu_len = pdu_len; /* FIXME: what to do when we miss a message? */
memmove(Receive_Buffer.pdu, pdu, sizeof(Receive_Buffer.pdu)); pdu_len = 0;
} else if (pdu_len < sizeof(Receive_Buffer.pdu)) {
dlmstp_fill_bacnet_address(&Receive_Buffer.address, src);
Receive_Buffer.pdu_len = pdu_len;
memmove(Receive_Buffer.pdu, pdu, pdu_len);
Receive_Buffer.ready = true;
} else {
/* FIXME: message too large? */
pdu_len = 0;
}
return pdu_len; return pdu_len;
} }
-2
View File
@@ -172,9 +172,7 @@ void main(void)
/* input */ /* input */
Check_Timer_Milliseconds(); Check_Timer_Milliseconds();
dlmstp_task();
pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout); pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout);
/* process */ /* process */
if (pdu_len) { if (pdu_len) {
npdu_handler(&src, &Rx_Buf[0], pdu_len); npdu_handler(&src, &Rx_Buf[0], pdu_len);