diff --git a/bacnet-stack/mstp.h b/bacnet-stack/mstp.h index df95c34e..03269bf6 100644 --- a/bacnet-stack/mstp.h +++ b/bacnet-stack/mstp.h @@ -107,6 +107,17 @@ typedef enum { /* larger values for this timeout, not to exceed 100 milliseconds.) */ #define Tusage_timeout 25 +/* The minimum time after the end of the stop bit of the final octet of a */ +/* received frame before a node may enable its EIA-485 driver: 40 bit times. */ +/* At 9600 baud, 40 bit times would be about 4.166 milliseconds */ +/* At 19200 baud, 40 bit times would be about 2.083 milliseconds */ +/* At 38400 baud, 40 bit times would be about 1.041 milliseconds */ +/* At 57600 baud, 40 bit times would be about 0.694 milliseconds */ +/* At 76800 baud, 40 bit times would be about 0.520 milliseconds */ +/* At 115200 baud, 40 bit times would be about 0.347 milliseconds */ +/* 40 bits is 4 octets including a start and stop bit with each octet */ +#define Tturnaround (40UL) +/* turnaround_time_milliseconds = (Tturnaround*1000UL)/RS485_Baud; */ struct mstp_port_struct_t { MSTP_RECEIVE_STATE receive_state; @@ -240,17 +251,6 @@ struct mstp_port_struct_t { #define DEFAULT_MAX_MASTER 127 #define DEFAULT_MAC_ADDRESS 127 -/* The minimum time after the end of the stop bit of the final octet of a */ -/* received frame before a node may enable its EIA-485 driver: 40 bit times. */ -/* At 9600 baud, 40 bit times would be about 4.166 milliseconds */ -/* At 19200 baud, 40 bit times would be about 2.083 milliseconds */ -/* At 38400 baud, 40 bit times would be about 1.041 milliseconds */ -/* At 57600 baud, 40 bit times would be about 0.694 milliseconds */ -/* At 76800 baud, 40 bit times would be about 0.520 milliseconds */ -/* At 115200 baud, 40 bit times would be about 0.347 milliseconds */ -/* 40 bits is 4 octets including a start and stop bit with each octet */ -#define Tturnaround 40 - #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ diff --git a/bacnet-stack/ports/atmega168/Makefile b/bacnet-stack/ports/atmega168/Makefile index 97cf86ad..a97ce2e0 100644 --- a/bacnet-stack/ports/atmega168/Makefile +++ b/bacnet-stack/ports/atmega168/Makefile @@ -75,7 +75,8 @@ ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2 ## Linker flags LDFLAGS = $(COMMON) -LDFLAGS += -Wl,-Map=$(TARGET).map,-L=.,-l$(TARGET) +#LDFLAGS += -Wl,-Map=$(TARGET).map,-L=.,-l$(TARGET) +LDFLAGS += -Wl,-Map=$(TARGET).map ## Intel Hex file production flags HEX_FLASH_FLAGS = -R .eeprom @@ -84,7 +85,8 @@ HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load" HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings ## Objects that must be built in order to link -OBJECTS = $(COBJ) $(DEMOOBJ) +#OBJECTS = $(COBJ) $(DEMOOBJ) +OBJECTS = $(COBJ) ## Build TARGET_ELF=$(TARGET).elf diff --git a/bacnet-stack/ports/atmega168/bacnet.aps b/bacnet-stack/ports/atmega168/bacnet.aps index 2b49780b..323c60b9 100644 --- a/bacnet-stack/ports/atmega168/bacnet.aps +++ b/bacnet-stack/ports/atmega168/bacnet.aps @@ -1 +1 @@ -13-Aug-2007 15:08:2715-Aug-2007 14:52:49013-Aug-2007 15:08:2744, 13, 0, 528AVR GCC241bacnet13-Aug-2007 15:11:0713-Aug-2007 15:11:07241013-Aug-2007 15:11:0744, 13, 0, 528AVR GCCdefault\bacnet.elfC:\code\bacnet-stack\ports\atmega168\ATmega168falseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31AVR SimulatorAVR SimulatorATmega168.xmlAuto000main.crs485.ctimer.cavr035.hhardware.hrs485.htimer.hdefaultNOatmega168100bacnet.elfdefault\0.\..\..\-Wall -gdwarf-2 -DF_CPU=7372800UL -O0 -fsigned-chardefault1C:\WinAVR-20070525\bin\avr-gcc.exeC:\WinAVR-20070525\utils\bin\make.exe0282161937372800011C:\code\bacnet-stack\ports\atmega168\avr035.hC:\code\bacnet-stack\ports\atmega168\hardware.hC:\code\bacnet-stack\ports\atmega168\rs485.hC:\code\bacnet-stack\ports\atmega168\timer.hC:\code\bacnet-stack\ports\atmega168\main.cC:\code\bacnet-stack\ports\atmega168\rs485.cC:\code\bacnet-stack\ports\atmega168\timer.c00000C:\WinAVR-20070525\avr\include\avr\eeprom.h100001C:\WinAVR-20070525\avr\include\avr\iomx8.h100002C:\WinAVR-20070525\examples\stdiodemo\uart.c100003main.c25800004timer.c25800005C:\WinAVR-20070525\avr\include\avr\interrupt.h100006C:\WinAVR-20070525\avr\include\avr\io.h100007rs485.c1749 695 909 7190 0589 695 749 7198 0909 695 1069 7190 0429 695 589 7196 51269 695 429 7194 65291 119 1091 6740 0 +13-Aug-2007 15:08:2716-Aug-2007 14:41:22013-Aug-2007 15:08:2744, 13, 0, 528AVR GCC241bacnet13-Aug-2007 15:11:0713-Aug-2007 15:11:07241013-Aug-2007 15:11:0744, 13, 0, 528AVR GCCdefault\bacnet.elfC:\code\bacnet-stack\ports\atmega168\ATmega168falseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31AVR SimulatorAVR SimulatorATmega168.xmlAuto000main.crs485.ctimer.cdlmstp.cC:\code\bacnet-stack\crc.cC:\code\bacnet-stack\mstp.cavr035.hhardware.hrs485.htimer.hC:\code\bacnet-stack\mstp.hC:\code\bacnet-stack\crc.hC:\code\bacnet-stack\dlmstp.hdefaultNOatmega168100bacnet.elfdefault\1..\..\.\-Wall -gdwarf-2 -O0 -fsigned-char -DMAX_APDU=50 -DBACDL_MSTP -DBIG_ENDIAN=0 default1C:\WinAVR-20070525\bin\avr-gcc.exeC:\WinAVR-20070525\utils\bin\make.exe028216193737280001100000C:\WinAVR-20070525\avr\include\avr\eeprom.h100001C:\WinAVR-20070525\avr\include\avr\iomx8.h100002C:\WinAVR-20070525\examples\stdiodemo\uart.c100003main.c25900004timer.c25800005C:\WinAVR-20070525\avr\include\avr\interrupt.h100006C:\WinAVR-20070525\avr\include\avr\io.h100007rs485.c25700008C:\code\bacnet-stack\mstp.c25900009dlmstp.c257751 698 911 7250 0269 695 429 7190 0908 695 1068 7220 0401 229 1255 653109 0428 695 588 7220 0429 695 589 7190 0290 119 1090 6740 0423 251 1223 675638 0467 295 1267 7190 0 diff --git a/bacnet-stack/ports/atmega168/dlmstp.c b/bacnet-stack/ports/atmega168/dlmstp.c index d10af54d..2800fa31 100644 --- a/bacnet-stack/ports/atmega168/dlmstp.c +++ b/bacnet-stack/ports/atmega168/dlmstp.c @@ -40,12 +40,12 @@ uint16_t MSTP_Packets = 0; /* local MS/TP port data - shared with RS-485 */ static volatile struct mstp_port_struct_t MSTP_Port; -/* receive buffer */ -static DLMSTP_PACKET Receive_Packet; -static DLMSTP_PACKET Transmit_Packet; /* buffers needed by mstp port struct */ static uint8_t TxBuffer[MAX_MPDU]; static uint8_t RxBuffer[MAX_MPDU]; +/* buffers used by the datalink layer */ +static DLMSTP_PACKET Receive_Packet; +static DLMSTP_PACKET Transmit_Packet; #define INCREMENT_AND_LIMIT_UINT16(x) {if (x < 0xFFFF) x++;} diff --git a/bacnet-stack/ports/atmega168/hardware.ods b/bacnet-stack/ports/atmega168/hardware.ods new file mode 100644 index 00000000..6d06047c Binary files /dev/null and b/bacnet-stack/ports/atmega168/hardware.ods differ diff --git a/bacnet-stack/ports/atmega168/main.c b/bacnet-stack/ports/atmega168/main.c index 7e703ecc..6afd295c 100644 --- a/bacnet-stack/ports/atmega168/main.c +++ b/bacnet-stack/ports/atmega168/main.c @@ -36,6 +36,26 @@ void init(void) { + /* Initialize the Clock Prescaler for ATmega48/88/168 */ + /* The device is shipped with the CKDIV8 Fuse programmed */ + /* The default CLKPSx bits are factory set to 0011 */ + /* Enbable the Clock Prescaler */ + CLKPR = _BV(CLKPCE); + /* CLKPS3 CLKPS2 CLKPS1 CLKPS0 Clock Division Factor + ------ ------ ------ ------ --------------------- + 0 0 0 0 1 + 0 0 0 1 2 + 0 0 1 0 4 + 0 0 1 1 8 + 0 1 0 0 16 + 0 1 0 1 32 + 0 1 1 0 64 + 0 1 1 1 128 + 1 0 0 0 256 + 1 x x x Reserved + */ + /* Set the CLKPS3..0 bits to Prescaler of 1 */ + CLKPR = 0; /* Initialize I/O ports */ /* For Port DDRx (Data Direction) Input=1, Output=1 */ /* For Port PORTx (Bit Value) TriState=0, High=1 */ @@ -66,7 +86,9 @@ void task_milliseconds(void) while (Timer_Milliseconds) { Timer_Milliseconds--; /* add other millisecond timer tasks here */ +#if defined(BACDL_MSTP) dlmstp_millisecond_timer(); +#endif } } @@ -90,7 +112,7 @@ int main(void) /* BACnet handling */ pdu_len = datalink_receive(&src, &PDUBuffer[0], MAX_MPDU, 0); if (pdu_len) { - npdu_handler(&src, &PDUBuffer[0], pdu_len); + //npdu_handler(&src, &PDUBuffer[0], pdu_len); } } diff --git a/bacnet-stack/ports/atmega168/rs485.c b/bacnet-stack/ports/atmega168/rs485.c index 58d47b84..23e7ec92 100644 --- a/bacnet-stack/ports/atmega168/rs485.c +++ b/bacnet-stack/ports/atmega168/rs485.c @@ -124,7 +124,7 @@ void RS485_Send_Frame( /* delay after reception - per MS/TP spec */ if (mstp_port) { /* wait about 40 bit times since reception */ - turnaround_time = (40UL*1000UL)/RS485_Baud; + turnaround_time = (Tturnaround*1000UL)/RS485_Baud; if (!turnaround_time) { turnaround_time = 1; } diff --git a/bacnet-stack/ports/atmega168/timer1.ods b/bacnet-stack/ports/atmega168/timer1.ods deleted file mode 100644 index 5896796e..00000000 Binary files a/bacnet-stack/ports/atmega168/timer1.ods and /dev/null differ