# $Id: Makefile.z1,v 1.4 2010/11/07 08:40:24 enricmcalvo Exp $
# msp430flasher -n msp430x5437 -w "Firmware.txt" -v -z [VCC]

ifdef IAR
CFLAGS+=-e --vla -Ohz --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40 --core=430X  --data_model small --double=32 -D__MSP430F5438A__=1
#CFLAGS+=--no_cse --no_unroll --no_inline --no_code_motion --no_tbaa --debug -D__MSP430F5438A__ -e --double=32 --dlib_config 'C:\Program Files (x86)\IAR Systems\Embedded Workbench 6.0 Evaluation\430\LIB\DLIB\dl430xsfn.h' --core=430X --data_model=small -Ol --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40
endif

CLEAN += *.exp5438 symbols.c symbols.h

ARCH=msp430.c leds.c watchdog.c \
     spix.c cc2420.c cc2420-arch.c \
     rtimer-arch.c node-id.c leds-arch.c uart1x.c lcd.c \
     hal_lcd.c hal_lcd_fonts.c duty-cycle-scroller.c cfs-ram.c

ifeq ($(WITH_SLIP),1)
ARCH += slip_uart0.c
else
ARCH += uart1-putchar.c
endif

ifdef NODEID
CFLAGS+=-DNODEID=$(NODEID)

ifdef BURN_NODEID
CFLAGS+=-DBURN_NODEID
endif # BURN_NODEID
endif # NODEID

help:
	@echo A few useful make commands:
	@echo make help - shows this help
	@echo make TARGET=exp5438 savetarget - stores selection of target to avoid using TARGET= on every make invokation
	@echo make program.upload - compiles and uploads program to connected board
	@echo make program.upload IAR=1 - uses the IAR compiler instead of mspgcc
	@echo make program.upload NODEID=x - uploads with node_id set to x

CONTIKI_TARGET_DIRS = . dev apps net
ifndef CONTIKI_TARGET_MAIN
CONTIKI_TARGET_MAIN = contiki-exp5438-main.c
endif

ifdef UIP_CONF_IPV6
CFLAGS += -DWITH_UIP6=1
endif

CONTIKI_TARGET_SOURCEFILES += $(ARCH) $(UIPDRIVERS)

ifdef IAR
MCU=msp430f5438a
else
MCU=msp430f5438
endif
include $(CONTIKI)/cpu/msp430/Makefile.msp430

contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o}
#	$(AR) rcf $@ $^


ifdef IAR
STACKSIZE=300
LDFLAGSNO += -B -xm "$(IAR_PATH)/lib/dlib/dl430xsfn.r43" -f "$(IAR_PATH)/config/lnk430f5437.xcl" -l contiki-$(TARGET).map -s __program_start -D_STACK_SIZE=$(STACKSIZE) -D_DATA16_HEAP_SIZE=$(STACKSIZE) -D_DATA20_HEAP_SIZE=$(STACKSIZE)
LDFLAGS += $(LDFLAGSNO) -Felf -yn
endif

%.hex: %.ihex
	mv $< $@

%.upload: %.hex
	msp430flasher -n msp430x5438a -e ERASE_MAIN -w $< -v -z [VCC]

%.upload-clean: %.hex
	msp430flasher -n msp430x5438a -w $< -v -z [VCC]
