diff --git a/bacnet-stack/ports/atmega168/Makefile b/bacnet-stack/ports/atmega168/Makefile index e87f13a7..3322f456 100644 --- a/bacnet-stack/ports/atmega168/Makefile +++ b/bacnet-stack/ports/atmega168/Makefile @@ -1,19 +1,27 @@ ############################################################################### -# Makefile for the project bacnet +# Makefile for BACnet ############################################################################### ## General Flags PROJECT = bacnet MCU = atmega168 -TARGET = bacnet.elf +TARGET = bacnet CC = avr-gcc.exe +CSRC = main.c \ + timer.c \ + rs485.c + +COBJ = $(CSRC:.c=.o) + ## Options common to compile, link and assembly rules COMMON = -mmcu=$(MCU) +OPTIMIZATION = -O0 +#OPTIMIZATION = -Os ## Compile options common for all C compilation units. CFLAGS = $(COMMON) -CFLAGS += -Wall -gdwarf-2 -O0 +CFLAGS += -Wall -gdwarf-2 -DF_CPU=7372800UL $(OPTIMIZATION) -fsigned-char CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d ## Assembly specific flags @@ -23,61 +31,51 @@ ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2 ## Linker flags LDFLAGS = $(COMMON) -LDFLAGS += - +LDFLAGS += -Wl,-Map=$(TARGET).map ## Intel Hex file production flags HEX_FLASH_FLAGS = -R .eeprom - HEX_EEPROM_FLAGS = -j .eeprom HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load" HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings - ## Include Directories -INCLUDES = -I"C:\code\bacnet-stack\ports\atmega168\..\.." +INCLUDES = -I. -I..\.. ## Objects that must be built in order to link -OBJECTS = main.o rs485.o timer.o - -## Objects explicitly added by the user -LINKONLYOBJECTS = +OBJECTS = $(COBJ) ## Build -all: $(TARGET) bacnet.hex bacnet.eep size +TARGET_ELF=$(TARGET).elf -## Compile -main.o: ../main.c - $(CC) $(INCLUDES) $(CFLAGS) -c $< - -rs485.o: ../rs485.c - $(CC) $(INCLUDES) $(CFLAGS) -c $< - -timer.o: ../timer.c - $(CC) $(INCLUDES) $(CFLAGS) -c $< +all: $(TARGET_ELF) $(TARGET).hex $(TARGET).eep size ##Link -$(TARGET): $(OBJECTS) - $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET) +$(TARGET_ELF): $(OBJECTS) + $(CC) $(LDFLAGS) $(OBJECTS) $(LIBDIRS) $(LIBS) -o $@ -%.hex: $(TARGET) +%.hex: $(TARGET_ELF) avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@ -%.eep: $(TARGET) +%.eep: $(TARGET_ELF) -avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0 -%.lss: $(TARGET) +%.lss: $(TARGET_ELF) avr-objdump -h -S $< > $@ -size: ${TARGET} +$(COBJ): %.o : %.c Makefile + $(CC) -c $(INCLUDES) $(CFLAGS) $< -o $@ + +size: ${TARGET_ELF} @echo - @avr-size -C --mcu=${MCU} ${TARGET} + @avr-size -C --mcu=${MCU} ${TARGET_ELF} ## Clean target .PHONY: clean clean: - -rm -rf $(OBJECTS) bacnet.elf dep/* bacnet.hex bacnet.eep + touch Makefile + -rm -rf $(OBJECTS) $(TARGET_ELF) dep/* + -rm -rf $(TARGET).hex $(TARGET).eep $(TARGET).lss $(TARGET).map ## Other dependencies -include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*) - diff --git a/bacnet-stack/ports/atmega168/bacnet.aps b/bacnet-stack/ports/atmega168/bacnet.aps index b55ef2a5..2b49780b 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 11:27:19013-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\1..\..\-Wall -gdwarf-2 -DF_CPU=7372800UL -O0 -fsigned-chardefault1C:\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.h100003C:\WinAVR-20070525\examples\stdiodemo\uart.c100004main.c25900005timer.c25900006rs485.c25700007hardware.h100008C:\WinAVR-20070525\avr\include\avr\interrupt.h1429 695 589 7190 0269 97 1069 497670 23589 695 749 7190 0269 695 429 7190 0313 141 1113 54185 13335 163 1135 56338 26291 119 1091 5190 0357 185 1157 58532 27445 273 1245 697101 0 +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 diff --git a/bacnet-stack/ports/atmega168/timer.c b/bacnet-stack/ports/atmega168/timer.c index 7710a005..d2ce820c 100644 --- a/bacnet-stack/ports/atmega168/timer.c +++ b/bacnet-stack/ports/atmega168/timer.c @@ -32,7 +32,7 @@ /* Count: Timer0 counts up to 0xFF and then signals overflow */ #define TIMER_TICKS (FREQ_CPU/TIMER_PRESCALER/1000) #if (TIMER_TICKS > 0xFF) -#error Timer Prescaler value too small +#error Timer Prescaler value is too small #endif #define TIMER_COUNT (0xFF-TIMER_TICKS) /* Global variable millisecond timer - used by main.c for timers task */ @@ -65,13 +65,15 @@ void timer_initialize(void) BIT_CLEAR(PRR,PRTIM0); } - +/* Timer interupt */ +/* note: Global interupts must be enabled - sei() */ /* Timer Overflowed! Increment the time. */ ISR(TIMER0_OVF_vect) { /* Set the counter for the next interrupt */ TCNT0 = TIMER_COUNT; /* Overflow Flag is automatically cleared */ + /* Update the global timer */ if (Timer_Milliseconds < 0xFF) Timer_Milliseconds++; } diff --git a/bacnet-stack/ports/linux/rs485.c b/bacnet-stack/ports/linux/rs485.c index 0693c6dd..164f24b6 100644 --- a/bacnet-stack/ports/linux/rs485.c +++ b/bacnet-stack/ports/linux/rs485.c @@ -63,7 +63,7 @@ static int RS485_Handle = -1; included by */ static unsigned int RS485_Baud = B38400; /* serial port name, /dev/ttyS0, - /dev/ttyUSB0 for USB->RS485 from SerialGear or USBGear */ + /dev/ttyUSB0 for USB->RS485 from B&B Electronics USOPTL4 */ static char *RS485_Port_Name = "/dev/ttyUSB0"; /* serial I/O settings */ static struct termios RS485_oldtio;