diff --git a/bacnet-stack/ports/at91sam7s/h_rp.c b/bacnet-stack/ports/at91sam7s/h_rp.c index a0ee4eab..eb3c1080 100644 --- a/bacnet-stack/ports/at91sam7s/h_rp.c +++ b/bacnet-stack/ports/at91sam7s/h_rp.c @@ -31,6 +31,7 @@ #include "txbuf.h" #include "bacdef.h" #include "bacdcode.h" +#include "bacerror.h" #include "apdu.h" #include "npdu.h" #include "abort.h" diff --git a/bacnet-stack/ports/at91sam7s/h_wp.c b/bacnet-stack/ports/at91sam7s/h_wp.c index b3099a46..59e9ecfc 100644 --- a/bacnet-stack/ports/at91sam7s/h_wp.c +++ b/bacnet-stack/ports/at91sam7s/h_wp.c @@ -31,6 +31,7 @@ #include "txbuf.h" #include "bacdef.h" #include "bacdcode.h" +#include "bacerror.h" #include "apdu.h" #include "npdu.h" #include "abort.h" diff --git a/bacnet-stack/ports/at91sam7s/makefile b/bacnet-stack/ports/at91sam7s/makefile index 861cac85..36a03320 100644 --- a/bacnet-stack/ports/at91sam7s/makefile +++ b/bacnet-stack/ports/at91sam7s/makefile @@ -44,10 +44,10 @@ DEMOSRC = ai.c \ h_rp.c \ h_wp.c \ device.c \ - ../../demo\handler\txbuf.c \ - ../../demo\handler\h_whois.c \ - ../../demo\handler\h_rd.c \ - ../../demo\handler\h_dcc.c + ../../demo/handler/txbuf.c \ + ../../demo/handler/h_whois.c \ + ../../demo/handler/h_rd.c \ + ../../demo/handler/h_dcc.c CORESRC = ../../npdu.c \ ../../bacint.c \ diff --git a/bacnet-stack/ports/atmega168/Makefile b/bacnet-stack/ports/atmega168/Makefile index d7d33a45..97cf86ad 100644 --- a/bacnet-stack/ports/atmega168/Makefile +++ b/bacnet-stack/ports/atmega168/Makefile @@ -6,18 +6,29 @@ PROJECT = bacnet MCU = atmega168 TARGET = bacnet +## Tools CC = avr-gcc AR = avr-ar +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size CSRC = main.c \ timer.c \ rs485.c \ dlmstp.c \ - ..\..\mstp.c \ - ..\..\crc.c + ../../mstp.c \ + ../../crc.c -CORESRC = device.c \ - ../../npdu.c \ +DEMOSRC = h_rp.c \ + h_wp.c \ + device.c \ + ../../demo/handler/txbuf.c \ + ../../demo/handler/h_whois.c \ + ../../demo/handler/h_rd.c \ + ../../demo/handler/h_dcc.c + +CORESRC = ../../npdu.c \ ../../bacint.c \ ../../apdu.c \ ../../bacdcode.c \ @@ -36,24 +47,26 @@ CORESRC = device.c \ ../../version.c ## Include Directories -INCLUDES = -I. -I../.. -I../../demo/object +INCLUDES = -I. -I../.. -I../../demo/object -I../../demo/handler # Source to Object conversion COBJ = $(CSRC:.c=.o) +DEMOOBJ = $(DEMOSRC:.c=.o) COREOBJ = $(CORESRC:.c=.o) LIBRARY = lib$(TARGET).a ## Options common to compile, link and assembly rules COMMON = -mmcu=$(MCU) -OPTIMIZATION = -O0 +#OPTIMIZATION = -O0 #OPTIMIZATION = -Os +OPTIMIZATION = -Os -mcall-prologues ## Compile options common for all C compilation units. BFLAGS = -DBACDL_MSTP -DMAX_APDU=50 -DBIG_ENDIAN=0 CFLAGS = $(COMMON) CFLAGS += -Wall -gdwarf-2 $(BFLAGS) $(OPTIMIZATION) -fsigned-char -CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d +CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d ## Assembly specific flags ASMFLAGS = $(COMMON) @@ -62,7 +75,7 @@ ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2 ## Linker flags LDFLAGS = $(COMMON) -LDFLAGS += -Wl,-Map=$(TARGET).map +LDFLAGS += -Wl,-Map=$(TARGET).map,-L=.,-l$(TARGET) ## Intel Hex file production flags HEX_FLASH_FLAGS = -R .eeprom @@ -71,45 +84,47 @@ 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) +OBJECTS = $(COBJ) $(DEMOOBJ) ## Build TARGET_ELF=$(TARGET).elf -all: $(TARGET_ELF) $(TARGET).hex $(TARGET).eep size $(LIBRARY) Makefile +all: $(LIBRARY) $(TARGET_ELF) $(TARGET).hex $(TARGET).eep $(TARGET).lst \ + size Makefile ##Link -$(TARGET_ELF): $(OBJECTS) - $(CC) $(LDFLAGS) $(OBJECTS) $(LIBDIRS) $(LIBS) -o $@ +$(TARGET_ELF): $(OBJECTS) $(LIBRARY) + $(CC) $(OBJECTS) $(LDFLAGS) -o $@ %.hex: $(TARGET_ELF) - avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@ + $(OBJCOPY) -O ihex $(HEX_FLASH_FLAGS) $< $@ %.eep: $(TARGET_ELF) - -avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0 + -$(OBJCOPY) $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0 -%.lss: $(TARGET_ELF) - avr-objdump -h -S $< > $@ +%.lst: $(TARGET_ELF) + $(OBJDUMP) -h -S $< > $@ lib: $(LIBRARY) $(LIBRARY): $(COREOBJ) Makefile $(AR) rcs $@ $(COREOBJ) + $(OBJDUMP) --syms $@ > $(LIBRARY:.a=.lst) .c.o: $(CC) -c $(INCLUDES) $(CFLAGS) $*.c -o $@ size: ${TARGET_ELF} @echo - @avr-size -C --mcu=${MCU} ${TARGET_ELF} + @${SIZE} -C --mcu=${MCU} ${TARGET_ELF} ## Clean target .PHONY: clean clean: touch Makefile - -rm -rf $(OBJECTS) $(TARGET_ELF) dep/* - -rm -rf $(LIBRARY) $(COREOBJ) - -rm -rf $(TARGET).hex $(TARGET).eep $(TARGET).lss $(TARGET).map + -rm -rf $(OBJECTS) $(TARGET_ELF) dep/* + -rm -rf $(LIBRARY) $(COREOBJ) $(LIBRARY:.a=.lst) + -rm -rf $(TARGET).hex $(TARGET).eep $(TARGET).lst $(TARGET).map ## Other dependencies -include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*) diff --git a/bacnet-stack/ports/atmega168/h_rp.c b/bacnet-stack/ports/atmega168/h_rp.c index a0ee4eab..42a0c9a6 100644 --- a/bacnet-stack/ports/atmega168/h_rp.c +++ b/bacnet-stack/ports/atmega168/h_rp.c @@ -31,16 +31,19 @@ #include "txbuf.h" #include "bacdef.h" #include "bacdcode.h" +#include "bacerror.h" #include "apdu.h" #include "npdu.h" #include "abort.h" #include "rp.h" /* demo objects */ #include "device.h" +#if 0 #include "ai.h" #include "av.h" #include "bi.h" #include "bv.h" +#endif static uint8_t Temp_Buf[MAX_APDU] = { 0 }; @@ -72,7 +75,8 @@ int Encode_Property_APDU( error_class, error_code); } break; - case OBJECT_ANALOG_INPUT: +#if 0 + case OBJECT_ANALOG_INPUT: if (Analog_Input_Valid_Instance(object_instance)) { apdu_len = Analog_Input_Encode_Property_APDU( &apdu[0], @@ -110,7 +114,8 @@ int Encode_Property_APDU( error_class, error_code); } break; - default: +#endif + default: *error_class = ERROR_CLASS_OBJECT; *error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE; break; diff --git a/bacnet-stack/ports/atmega168/h_wp.c b/bacnet-stack/ports/atmega168/h_wp.c index b3099a46..88cf2f1f 100644 --- a/bacnet-stack/ports/atmega168/h_wp.c +++ b/bacnet-stack/ports/atmega168/h_wp.c @@ -31,16 +31,19 @@ #include "txbuf.h" #include "bacdef.h" #include "bacdcode.h" +#include "bacerror.h" #include "apdu.h" #include "npdu.h" #include "abort.h" #include "wp.h" /* demo objects */ #include "device.h" +#if 0 #include "ai.h" #include "av.h" #include "bi.h" #include "bv.h" +#endif /* too big to reside on stack frame for PIC */ static BACNET_WRITE_PROPERTY_DATA wp_data; @@ -89,7 +92,8 @@ void handler_write_property(uint8_t * service_request, error_code); } break; - case OBJECT_ANALOG_INPUT: +#if 0 + case OBJECT_ANALOG_INPUT: case OBJECT_BINARY_INPUT: error_class = ERROR_CLASS_PROPERTY; error_code = ERROR_CODE_WRITE_ACCESS_DENIED; @@ -128,7 +132,8 @@ void handler_write_property(uint8_t * service_request, error_code); } break; - default: +#endif + default: len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, diff --git a/bacnet-stack/ports/atmega168/main.c b/bacnet-stack/ports/atmega168/main.c index 4909a0bf..7e703ecc 100644 --- a/bacnet-stack/ports/atmega168/main.c +++ b/bacnet-stack/ports/atmega168/main.c @@ -29,14 +29,11 @@ #include "timer.h" #include "rs485.h" #include "datalink.h" +#include "npdu.h" /* For porting to IAR, see: http://www.avrfreaks.net/wiki/index.php/Documentation:AVR_GCC/IarToAvrgcc*/ -static uint16_t Transmit_Timer = 0; -#define MAX_FRAME 5 -static uint8_t Transmit_Frame[MAX_FRAME] = {0xAA, 0x55, 0x01, 0x45, 0xAB }; - void init(void) { /* Initialize I/O ports */ @@ -69,7 +66,6 @@ void task_milliseconds(void) while (Timer_Milliseconds) { Timer_Milliseconds--; /* add other millisecond timer tasks here */ - Transmit_Timer++; dlmstp_millisecond_timer(); } } @@ -94,7 +90,7 @@ int main(void) /* BACnet handling */ pdu_len = datalink_receive(&src, &PDUBuffer[0], MAX_MPDU, 0); if (pdu_len) { - //npdu_handler(&src, &pdu[0], pdu_len); + npdu_handler(&src, &PDUBuffer[0], pdu_len); } }