# Hey Emacs, this is a -*- makefile -*-

bl:
	cd $(AIRBORNE)/arch/lpc21/test/bootloader; $(MAKE) clean; $(MAKE)

BOOTLOADER_DEV ?= /dev/ttyUSB0
upload_bl bl.upload: bl
	lpc21isp -control $(AIRBORNE)/arch/lpc21/test/bootloader/bl.hex $(BOOTLOADER_DEV) 38400 12000

JTAG_INTERFACE ?= olimex-jtag-tiny.cfg
#JTAG_INTERFACE = olimex-arm-usb-ocd.cfg

upload_jtag: bl
	openocd -f interface/$(JTAG_INTERFACE)  -f board/olimex_lpc_h2148.cfg -c init -c halt -c "flash write_image erase $(AIRBORNE)/arch/lpc21/test/bootloader/bl.hex"  -c reset -c shutdown


lpc21iap:
	$(MAKE) -C sw/ground_segment/lpc21iap

upgrade_bl bl.upgrade: bl lpc21iap
	$(PAPARAZZI_SRC)/sw/ground_segment/lpc21iap/lpc21iap $(AIRBORNE)/arch/lpc21/test/bootloader/bl_ram.elf
	$(PAPARAZZI_SRC)/sw/ground_segment/lpc21iap/lpc21iap $(AIRBORNE)/arch/lpc21/test/bootloader/bl.elf

ms:
	$(MAKE) -C $(AIRBORNE)/arch/lpc21/lpcusb
	$(MAKE) -C $(AIRBORNE)/arch/lpc21/lpcusb/examples

upload_ms ms.upload: ms
	$(PAPARAZZI_SRC)/sw/ground_segment/lpc21iap/lpc21iap $(AIRBORNE)/arch/lpc21/lpcusb/examples/msc.elf

.PHONY: bl upload_bl upload_jtag ms upload_ms lpc21iap upgrade_bl
