Updated for ATmega port.

This commit is contained in:
skarg
2007-08-16 18:52:12 +00:00
parent a99bbea376
commit 2722f8c008
7 changed files with 57 additions and 34 deletions
+1
View File
@@ -31,6 +31,7 @@
#include "txbuf.h" #include "txbuf.h"
#include "bacdef.h" #include "bacdef.h"
#include "bacdcode.h" #include "bacdcode.h"
#include "bacerror.h"
#include "apdu.h" #include "apdu.h"
#include "npdu.h" #include "npdu.h"
#include "abort.h" #include "abort.h"
+1
View File
@@ -31,6 +31,7 @@
#include "txbuf.h" #include "txbuf.h"
#include "bacdef.h" #include "bacdef.h"
#include "bacdcode.h" #include "bacdcode.h"
#include "bacerror.h"
#include "apdu.h" #include "apdu.h"
#include "npdu.h" #include "npdu.h"
#include "abort.h" #include "abort.h"
+4 -4
View File
@@ -44,10 +44,10 @@ DEMOSRC = ai.c \
h_rp.c \ h_rp.c \
h_wp.c \ h_wp.c \
device.c \ device.c \
../../demo\handler\txbuf.c \ ../../demo/handler/txbuf.c \
../../demo\handler\h_whois.c \ ../../demo/handler/h_whois.c \
../../demo\handler\h_rd.c \ ../../demo/handler/h_rd.c \
../../demo\handler\h_dcc.c ../../demo/handler/h_dcc.c
CORESRC = ../../npdu.c \ CORESRC = ../../npdu.c \
../../bacint.c \ ../../bacint.c \
+33 -18
View File
@@ -6,18 +6,29 @@
PROJECT = bacnet PROJECT = bacnet
MCU = atmega168 MCU = atmega168
TARGET = bacnet TARGET = bacnet
## Tools
CC = avr-gcc CC = avr-gcc
AR = avr-ar AR = avr-ar
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
CSRC = main.c \ CSRC = main.c \
timer.c \ timer.c \
rs485.c \ rs485.c \
dlmstp.c \ dlmstp.c \
..\..\mstp.c \ ../../mstp.c \
..\..\crc.c ../../crc.c
CORESRC = device.c \ DEMOSRC = h_rp.c \
../../npdu.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 \ ../../bacint.c \
../../apdu.c \ ../../apdu.c \
../../bacdcode.c \ ../../bacdcode.c \
@@ -36,18 +47,20 @@ CORESRC = device.c \
../../version.c ../../version.c
## Include Directories ## Include Directories
INCLUDES = -I. -I../.. -I../../demo/object INCLUDES = -I. -I../.. -I../../demo/object -I../../demo/handler
# Source to Object conversion # Source to Object conversion
COBJ = $(CSRC:.c=.o) COBJ = $(CSRC:.c=.o)
DEMOOBJ = $(DEMOSRC:.c=.o)
COREOBJ = $(CORESRC:.c=.o) COREOBJ = $(CORESRC:.c=.o)
LIBRARY = lib$(TARGET).a LIBRARY = lib$(TARGET).a
## Options common to compile, link and assembly rules ## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU) COMMON = -mmcu=$(MCU)
OPTIMIZATION = -O0 #OPTIMIZATION = -O0
#OPTIMIZATION = -Os #OPTIMIZATION = -Os
OPTIMIZATION = -Os -mcall-prologues
## Compile options common for all C compilation units. ## Compile options common for all C compilation units.
BFLAGS = -DBACDL_MSTP -DMAX_APDU=50 -DBIG_ENDIAN=0 BFLAGS = -DBACDL_MSTP -DMAX_APDU=50 -DBIG_ENDIAN=0
@@ -62,7 +75,7 @@ ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
## Linker flags ## Linker flags
LDFLAGS = $(COMMON) LDFLAGS = $(COMMON)
LDFLAGS += -Wl,-Map=$(TARGET).map LDFLAGS += -Wl,-Map=$(TARGET).map,-L=.,-l$(TARGET)
## Intel Hex file production flags ## Intel Hex file production flags
HEX_FLASH_FLAGS = -R .eeprom 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 HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
## Objects that must be built in order to link ## Objects that must be built in order to link
OBJECTS = $(COBJ) OBJECTS = $(COBJ) $(DEMOOBJ)
## Build ## Build
TARGET_ELF=$(TARGET).elf 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 ##Link
$(TARGET_ELF): $(OBJECTS) $(TARGET_ELF): $(OBJECTS) $(LIBRARY)
$(CC) $(LDFLAGS) $(OBJECTS) $(LIBDIRS) $(LIBS) -o $@ $(CC) $(OBJECTS) $(LDFLAGS) -o $@
%.hex: $(TARGET_ELF) %.hex: $(TARGET_ELF)
avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@ $(OBJCOPY) -O ihex $(HEX_FLASH_FLAGS) $< $@
%.eep: $(TARGET_ELF) %.eep: $(TARGET_ELF)
-avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0 -$(OBJCOPY) $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0
%.lss: $(TARGET_ELF) %.lst: $(TARGET_ELF)
avr-objdump -h -S $< > $@ $(OBJDUMP) -h -S $< > $@
lib: $(LIBRARY) lib: $(LIBRARY)
$(LIBRARY): $(COREOBJ) Makefile $(LIBRARY): $(COREOBJ) Makefile
$(AR) rcs $@ $(COREOBJ) $(AR) rcs $@ $(COREOBJ)
$(OBJDUMP) --syms $@ > $(LIBRARY:.a=.lst)
.c.o: .c.o:
$(CC) -c $(INCLUDES) $(CFLAGS) $*.c -o $@ $(CC) -c $(INCLUDES) $(CFLAGS) $*.c -o $@
size: ${TARGET_ELF} size: ${TARGET_ELF}
@echo @echo
@avr-size -C --mcu=${MCU} ${TARGET_ELF} @${SIZE} -C --mcu=${MCU} ${TARGET_ELF}
## Clean target ## Clean target
.PHONY: clean .PHONY: clean
clean: clean:
touch Makefile touch Makefile
-rm -rf $(OBJECTS) $(TARGET_ELF) dep/* -rm -rf $(OBJECTS) $(TARGET_ELF) dep/*
-rm -rf $(LIBRARY) $(COREOBJ) -rm -rf $(LIBRARY) $(COREOBJ) $(LIBRARY:.a=.lst)
-rm -rf $(TARGET).hex $(TARGET).eep $(TARGET).lss $(TARGET).map -rm -rf $(TARGET).hex $(TARGET).eep $(TARGET).lst $(TARGET).map
## Other dependencies ## Other dependencies
-include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*) -include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*)
+7 -2
View File
@@ -31,16 +31,19 @@
#include "txbuf.h" #include "txbuf.h"
#include "bacdef.h" #include "bacdef.h"
#include "bacdcode.h" #include "bacdcode.h"
#include "bacerror.h"
#include "apdu.h" #include "apdu.h"
#include "npdu.h" #include "npdu.h"
#include "abort.h" #include "abort.h"
#include "rp.h" #include "rp.h"
/* demo objects */ /* demo objects */
#include "device.h" #include "device.h"
#if 0
#include "ai.h" #include "ai.h"
#include "av.h" #include "av.h"
#include "bi.h" #include "bi.h"
#include "bv.h" #include "bv.h"
#endif
static uint8_t Temp_Buf[MAX_APDU] = { 0 }; static uint8_t Temp_Buf[MAX_APDU] = { 0 };
@@ -72,7 +75,8 @@ int Encode_Property_APDU(
error_class, error_code); error_class, error_code);
} }
break; break;
case OBJECT_ANALOG_INPUT: #if 0
case OBJECT_ANALOG_INPUT:
if (Analog_Input_Valid_Instance(object_instance)) { if (Analog_Input_Valid_Instance(object_instance)) {
apdu_len = Analog_Input_Encode_Property_APDU( apdu_len = Analog_Input_Encode_Property_APDU(
&apdu[0], &apdu[0],
@@ -110,7 +114,8 @@ int Encode_Property_APDU(
error_class, error_code); error_class, error_code);
} }
break; break;
default: #endif
default:
*error_class = ERROR_CLASS_OBJECT; *error_class = ERROR_CLASS_OBJECT;
*error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE; *error_code = ERROR_CODE_UNSUPPORTED_OBJECT_TYPE;
break; break;
+7 -2
View File
@@ -31,16 +31,19 @@
#include "txbuf.h" #include "txbuf.h"
#include "bacdef.h" #include "bacdef.h"
#include "bacdcode.h" #include "bacdcode.h"
#include "bacerror.h"
#include "apdu.h" #include "apdu.h"
#include "npdu.h" #include "npdu.h"
#include "abort.h" #include "abort.h"
#include "wp.h" #include "wp.h"
/* demo objects */ /* demo objects */
#include "device.h" #include "device.h"
#if 0
#include "ai.h" #include "ai.h"
#include "av.h" #include "av.h"
#include "bi.h" #include "bi.h"
#include "bv.h" #include "bv.h"
#endif
/* too big to reside on stack frame for PIC */ /* too big to reside on stack frame for PIC */
static BACNET_WRITE_PROPERTY_DATA wp_data; static BACNET_WRITE_PROPERTY_DATA wp_data;
@@ -89,7 +92,8 @@ void handler_write_property(uint8_t * service_request,
error_code); error_code);
} }
break; break;
case OBJECT_ANALOG_INPUT: #if 0
case OBJECT_ANALOG_INPUT:
case OBJECT_BINARY_INPUT: case OBJECT_BINARY_INPUT:
error_class = ERROR_CLASS_PROPERTY; error_class = ERROR_CLASS_PROPERTY;
error_code = ERROR_CODE_WRITE_ACCESS_DENIED; error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
@@ -128,7 +132,8 @@ void handler_write_property(uint8_t * service_request,
error_code); error_code);
} }
break; break;
default: #endif
default:
len = len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
+2 -6
View File
@@ -29,14 +29,11 @@
#include "timer.h" #include "timer.h"
#include "rs485.h" #include "rs485.h"
#include "datalink.h" #include "datalink.h"
#include "npdu.h"
/* For porting to IAR, see: /* For porting to IAR, see:
http://www.avrfreaks.net/wiki/index.php/Documentation:AVR_GCC/IarToAvrgcc*/ 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) void init(void)
{ {
/* Initialize I/O ports */ /* Initialize I/O ports */
@@ -69,7 +66,6 @@ void task_milliseconds(void)
while (Timer_Milliseconds) { while (Timer_Milliseconds) {
Timer_Milliseconds--; Timer_Milliseconds--;
/* add other millisecond timer tasks here */ /* add other millisecond timer tasks here */
Transmit_Timer++;
dlmstp_millisecond_timer(); dlmstp_millisecond_timer();
} }
} }
@@ -94,7 +90,7 @@ int main(void)
/* BACnet handling */ /* BACnet handling */
pdu_len = datalink_receive(&src, &PDUBuffer[0], MAX_MPDU, 0); pdu_len = datalink_receive(&src, &PDUBuffer[0], MAX_MPDU, 0);
if (pdu_len) { if (pdu_len) {
//npdu_handler(&src, &pdu[0], pdu_len); npdu_handler(&src, &PDUBuffer[0], pdu_len);
} }
} }