diff --git a/bacnet-stack/ports/pic18/BACnet-Server.mcp b/bacnet-stack/ports/pic18/BACnet-Server.mcp index 5c04a9de..1c4173cc 100644 --- a/bacnet-stack/ports/pic18/BACnet-Server.mcp +++ b/bacnet-stack/ports/pic18/BACnet-Server.mcp @@ -88,9 +88,9 @@ file_015=C:\code\bacnet-stack\whois.c file_016=C:\code\bacnet-stack\demo\handler\h_dcc.c file_017=C:\code\bacnet-stack\demo\handler\h_rd.c file_018=main.c -file_019=C:\code\bacnet-stack\demo\object\tiny_dev.c -file_020=dlmstp.c -file_021=rs485.c +file_019=dlmstp.c +file_020=rs485.c +file_021=device.c file_022=C:\code\bacnet-stack\wp.h file_023=C:\code\bacnet-stack\abort.h file_024=C:\code\bacnet-stack\apdu.h diff --git a/bacnet-stack/ports/pic18/BACnet-Server.mcw b/bacnet-stack/ports/pic18/BACnet-Server.mcw index a4e164eb..eb35cf22 100644 Binary files a/bacnet-stack/ports/pic18/BACnet-Server.mcw and b/bacnet-stack/ports/pic18/BACnet-Server.mcw differ diff --git a/bacnet-stack/ports/pic18/bacnet.mcp b/bacnet-stack/ports/pic18/bacnet.mcp index df2429fe..ef4678e7 100644 --- a/bacnet-stack/ports/pic18/bacnet.mcp +++ b/bacnet-stack/ports/pic18/bacnet.mcp @@ -73,6 +73,8 @@ file_053=no file_054=no file_055=no file_056=no +file_057=no +file_058=no [FILE_INFO] file_000=rs485.c file_001=main.c @@ -85,59 +87,61 @@ file_007=C:\code\bacnet-stack\abort.c file_008=C:\code\bacnet-stack\apdu.c file_009=C:\code\bacnet-stack\bacdcode.c file_010=C:\code\bacnet-stack\bacerror.c -file_011=C:\code\bacnet-stack\bigend.c -file_012=C:\code\bacnet-stack\crc.c -file_013=C:\code\bacnet-stack\datalink.c -file_014=C:\code\bacnet-stack\dlmstp.c -file_015=C:\code\bacnet-stack\iam.c -file_016=C:\code\bacnet-stack\mstp.c -file_017=C:\code\bacnet-stack\npdu.c -file_018=C:\code\bacnet-stack\reject.c -file_019=C:\code\bacnet-stack\ringbuf.c -file_020=C:\code\bacnet-stack\wp.c -file_021=C:\code\bacnet-stack\demo\object\ai.c -file_022=C:\code\bacnet-stack\demo\object\ao.c -file_023=C:\code\bacnet-stack\dcc.c -file_024=C:\code\bacnet-stack\bacstr.c -file_025=C:\code\bacnet-stack\bacapp.c -file_026=C:\code\bacnet-stack\demo\object\tiny_dev.c -file_027=stdbool.h -file_028=stdint.h -file_029=init.h -file_030=timer.h -file_031=C:\code\bacnet-stack\whois.h -file_032=C:\code\bacnet-stack\abort.h -file_033=C:\code\bacnet-stack\apdu.h -file_034=C:\code\bacnet-stack\bacdcode.h -file_035=C:\code\bacnet-stack\bacdef.h -file_036=C:\code\bacnet-stack\bacenum.h -file_037=C:\code\bacnet-stack\bacerror.h -file_038=C:\code\bacnet-stack\bigend.h -file_039=C:\code\bacnet-stack\bits.h -file_040=C:\code\bacnet-stack\bytes.h -file_041=C:\code\bacnet-stack\config.h -file_042=C:\code\bacnet-stack\crc.h -file_043=C:\code\bacnet-stack\datalink.h -file_044=C:\code\bacnet-stack\dlmstp.h -file_045=C:\code\bacnet-stack\mstp.h -file_046=C:\code\bacnet-stack\npdu.h -file_047=C:\code\bacnet-stack\reject.h -file_048=C:\code\bacnet-stack\ringbuf.h -file_049=C:\code\bacnet-stack\rs485.h -file_050=C:\code\bacnet-stack\demo\object\ai.h -file_051=C:\code\bacnet-stack\demo\object\ao.h -file_052=C:\code\bacnet-stack\demo\object\device.h -file_053=C:\code\bacnet-stack\dcc.h -file_054=C:\code\bacnet-stack\bacstr.h -file_055=C:\code\bacnet-stack\bacapp.h -file_056=18f252.lkr +file_011=C:\code\bacnet-stack\crc.c +file_012=C:\code\bacnet-stack\datalink.c +file_013=C:\code\bacnet-stack\iam.c +file_014=C:\code\bacnet-stack\mstp.c +file_015=C:\code\bacnet-stack\npdu.c +file_016=C:\code\bacnet-stack\reject.c +file_017=C:\code\bacnet-stack\dcc.c +file_018=C:\code\bacnet-stack\bacstr.c +file_019=C:\code\bacnet-stack\bacapp.c +file_020=device.c +file_021=dlmstp.c +file_022=C:\code\bacnet-stack\demo\handler\h_rd.c +file_023=C:\code\bacnet-stack\demo\handler\h_dcc.c +file_024=C:\code\bacnet-stack\rd.c +file_025=C:\code\bacnet-stack\demo\handler\txbuf.c +file_026=C:\code\bacnet-stack\demo\handler\h_whois.c +file_027=C:\code\bacnet-stack\demo\handler\noserv.c +file_028=stdbool.h +file_029=stdint.h +file_030=init.h +file_031=timer.h +file_032=C:\code\bacnet-stack\whois.h +file_033=C:\code\bacnet-stack\abort.h +file_034=C:\code\bacnet-stack\apdu.h +file_035=C:\code\bacnet-stack\bacdcode.h +file_036=C:\code\bacnet-stack\bacdef.h +file_037=C:\code\bacnet-stack\bacenum.h +file_038=C:\code\bacnet-stack\bacerror.h +file_039=C:\code\bacnet-stack\bigend.h +file_040=C:\code\bacnet-stack\bits.h +file_041=C:\code\bacnet-stack\bytes.h +file_042=C:\code\bacnet-stack\config.h +file_043=C:\code\bacnet-stack\crc.h +file_044=C:\code\bacnet-stack\datalink.h +file_045=C:\code\bacnet-stack\dlmstp.h +file_046=C:\code\bacnet-stack\mstp.h +file_047=C:\code\bacnet-stack\npdu.h +file_048=C:\code\bacnet-stack\reject.h +file_049=C:\code\bacnet-stack\ringbuf.h +file_050=C:\code\bacnet-stack\rs485.h +file_051=C:\code\bacnet-stack\demo\object\ai.h +file_052=C:\code\bacnet-stack\demo\object\ao.h +file_053=C:\code\bacnet-stack\demo\object\device.h +file_054=C:\code\bacnet-stack\dcc.h +file_055=C:\code\bacnet-stack\bacstr.h +file_056=C:\code\bacnet-stack\bacapp.h +file_057=C:\code\bacnet-stack\rd.h +file_058=18f252.lkr [SUITE_INFO] suite_guid={5B7D72DD-9861-47BD-9F60-2BE967BF8416} suite_state= [TOOL_SETTINGS] TS{DD2213A8-6310-47B1-8376-9430CDFC013F}= TS{BFD27FBA-4A02-4C0E-A5E5-B812F3E7707C}=/m"$(BINDIR_)$(TARGETBASE).map" /o"$(TARGETBASE).cof" -TS{C2AF05E7-1416-4625-923D-E114DB6E2B96}=-DBACDL_MSTP -DTSM_ENABLED=0 -DPRINT_ENABLED=0 -mL +TS{C2AF05E7-1416-4625-923D-E114DB6E2B96}=-DTSM_ENABLED=0 -DPRINT_ENABLED=0 -DBACDL_MSTP=1 -mL -pa=1 TS{ADE93A55-C7C7-4D4D-A4BA-59305F7D0391}= TS{DD2213A8-6310-47B1-8376-9430CDFC013F}001= TS{BFD27FBA-4A02-4C0E-A5E5-B812F3E7707C}001=/o"$(TARGETBASE).cof" diff --git a/bacnet-stack/ports/pic18/bacnet.mcw b/bacnet-stack/ports/pic18/bacnet.mcw index fd405142..a7740861 100644 Binary files a/bacnet-stack/ports/pic18/bacnet.mcw and b/bacnet-stack/ports/pic18/bacnet.mcw differ diff --git a/bacnet-stack/ports/pic18/dlmstp.c b/bacnet-stack/ports/pic18/dlmstp.c index 29793470..299da643 100644 --- a/bacnet-stack/ports/pic18/dlmstp.c +++ b/bacnet-stack/ports/pic18/dlmstp.c @@ -36,11 +36,12 @@ #include "npdu.h" /* receive buffer */ +#pragma udata MSTPPortData static DLMSTP_PACKET Receive_Buffer; /* temp buffer for NPDU insertion */ static uint8_t PDU_Buffer[MAX_MPDU]; -/* local MS/TP port data */ -static volatile struct mstp_port_struct_t MSTP_Port; +/* local MS/TP port data - shared with RS-485 */ +volatile struct mstp_port_struct_t MSTP_Port; void dlmstp_init(void) { @@ -132,7 +133,7 @@ uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */ /* 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, @@ -141,6 +142,7 @@ uint16_t dlmstp_receive(BACNET_ADDRESS * src, /* source address */ memmove(&pdu[0], &Receive_Buffer.pdu[0], max_pdu); Receive_Buffer.ready = false; } + RS485_Process_Tx_Message(); return pdu_len; } diff --git a/bacnet-stack/ports/pic18/main.c b/bacnet-stack/ports/pic18/main.c index 5b8b6adb..0df3b53c 100644 --- a/bacnet-stack/ports/pic18/main.c +++ b/bacnet-stack/ports/pic18/main.c @@ -29,7 +29,6 @@ #include "bytes.h" #include "crc.h" #include "rs485.h" -#include "ringbuf.h" #include "init.h" #include "timer.h" #include "datalink.h" @@ -152,7 +151,7 @@ void main(void) (handler_unrecognized_service); /* we must implement read property - it's required! */ apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY, - handler_read_property); + My_Read_Property_Handler); /* handle communication so we can shutup when asked */ apdu_set_confirmed_handler (SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, diff --git a/bacnet-stack/ports/pic18/rs485.c b/bacnet-stack/ports/pic18/rs485.c index 84683be4..529c3e20 100644 --- a/bacnet-stack/ports/pic18/rs485.c +++ b/bacnet-stack/ports/pic18/rs485.c @@ -79,6 +79,37 @@ volatile static enum { RS485_STATE_TX_TEST = 14 } RS485_State; +/**************************************************************************** +* DESCRIPTION: Processes the RS485 message to be sent +* RETURN: none +* ALGORITHM: none +* NOTES: none +*****************************************************************************/ +void RS485_Process_Tx_Message(void) +{ + if (RS485_Flags.TransmitComplete) + RS485_Flags.TransmitComplete = FALSE; + /* start a new transmisstion if we are ready */ + if (RS485_Flags.TransmitStart && (RS485_State == RS485_STATE_IDLE)) { + /* Disable the receiver */ + USART_RX_INT_DISABLE(); + USART_CONTINUOUS_RX_DISABLE(); + /* Enable the transmit line driver and interrupts */ + RS485_TRANSMIT_ENABLE(); + RS485_State = RS485_STATE_TX_DATA; + /* Configure the ISR handler for an outgoing message */ + RS485_Tx_Index = 0; + /* update the flags for beginning a send */ + RS485_Flags.TransmitComplete = FALSE; + RS485_Flags.TransmitStart = FALSE; + /* send the first byte */ + USART_TRANSMIT(RS485_Tx_Buffer[0]); + USART_TX_SETUP(); + } + + return; +} + /**************************************************************************** * DESCRIPTION: Transmits a frame using the UART * RETURN: none @@ -119,6 +150,7 @@ void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, /* port } /* signal the task to start sending when it is ready */ RS485_Flags.TransmitStart = TRUE; + mstp_port->SilenceTimer = 0; return; } @@ -140,6 +172,7 @@ void RS485_Transmit_Interrupt(void) data = RS485_Tx_Buffer[RS485_Tx_Index]; USART_TRANSMIT(data); MSTP_Port.SilenceTimer = 0; + } else { /* wait until the last bit is sent */ while (!USART_TX_EMPTY()); @@ -176,37 +209,6 @@ void RS485_Transmit_Interrupt(void) return; } -/**************************************************************************** -* DESCRIPTION: Processes the RS485 message to be sent -* RETURN: none -* ALGORITHM: none -* NOTES: none -*****************************************************************************/ -void RS485_Process_Tx_Message(void) -{ - if (RS485_Flags.TransmitComplete) - RS485_Flags.TransmitComplete = FALSE; - /* start a new transmisstion if we are ready */ - if (RS485_Flags.TransmitStart && (RS485_State == RS485_STATE_IDLE)) { - /* Disable the receiver */ - USART_RX_INT_DISABLE(); - USART_CONTINUOUS_RX_DISABLE(); - /* Enable the transmit line driver and interrupts */ - RS485_TRANSMIT_ENABLE(); - RS485_State = RS485_STATE_TX_DATA; - /* Configure the ISR handler for an outgoing message */ - RS485_Tx_Index = 0; - /* update the flags for beginning a send */ - RS485_Flags.TransmitComplete = FALSE; - RS485_Flags.TransmitStart = FALSE; - /* send the first byte */ - USART_TRANSMIT(RS485_Tx_Buffer[0]); - USART_TX_SETUP(); - } - - return; -} - /**************************************************************************** * DESCRIPTION: Returns the value of Transmit Complete flag. * RETURN: none