#************************************************
# Monitor LPC2478
# Marcos Augusto Stemmer
#*************************************************/

SERIALDEV = /dev/ttyS0
TERMINAL=ltser
CLOCKFREQ=12000
TARGET=monarm
#MODULOS = main.o monitor.o iap.o pll.o lpc2478stk_lcd.o crt.o
MODULOS = main.o monitor.o iap.o pll.o lcd.o i2c.o smartcard.o crt.o
HEADERS = monarm.h lpc2478stk_lcd.h
BAUDRATE= 19200

CC      = arm-elf-gcc
LD      = arm-elf-gcc
CFLAGS  = -Wall -O2 -mcpu=arm7tdmi-s -D BAUDRATE=$(BAUDRATE)
LFLAGS  = -nostartfiles

all: $(TARGET).hex

%.bin: %.hex
	hex2bin $<

%.hex: %.elf
	arm-elf-objcopy -O ihex $< $@

%.o: %.c $(HEADERS)
	$(CC) -c $(CFLAGS) -o $@ $<

$(TARGET).elf: $(MODULOS)
	$(LD) -Tlpc2478_flash.ld $(LFLAGS) -o $(TARGET).elf $(MODULOS)

ram: monr.hex

# Use 'make isp' para programar a memoria flash
isp: $(TARGET).hex
	lpc21isp $(TARGET).hex $(SERIALDEV) $(BAUDRATE) $(CLOCKFREQ)
isp1: $(TARGET).hex
	lpc21isp $(TARGET).hex com1 $(BAUDRATE) $(CLOCKFREQ)
isp2: $(TARGET).hex
	lpc21isp $(TARGET).hex com2 $(BAUDRATE) $(CLOCKFREQ)
isp3: $(TARGET).hex
	lpc21isp $(TARGET).hex com3 $(BAUDRATE) $(CLOCKFREQ)
isp4: $(TARGET).hex
	lpc21isp $(TARGET).hex com4 $(BAUDRATE) $(CLOCKFREQ)
isp5: $(TARGET).hex
	lpc21isp $(TARGET).hex com5 $(BAUDRATE) $(CLOCKFREQ)

# Use 'make isp' para programar a memoria flash
ispu: $(TARGET).hex
	lpc21isp $(TARGET).hex /dev/ttyUSB0 $(BAUDRATE) $(CLOCKFREQ)

clean:
	-rm -f *.o *.elf *~ *.bin *.map *.hex
