#-----------------------------------------------
# Make command:
# mingw32-make build=<build> target=<target> entry=main stack=0x400 heap=0x1000
# <build>: debug or release, release by default.
# <target>: sram or flash, flash by default.
#-----------------------------------------------

#-----------------------------------------------
# setup variables
# ----------------------------------------------

SDK_ROOT := $(abspath ../../../..)

#-----------------------------------------------
# set board infomation
# The CHIP must be set correctly, otherwise the
# platform_lib cannot be linked.
#-----------------------------------------------
BOARD := twrk64f120m
CHIP := K64F12

APP_NAME = gpio_uart
#-----------------------------------------------
# Debug or Release
# Release by default
#-----------------------------------------------
build ?= release

#-----------------------------------------------
# Sram target or flash target
# flash target by defult.
#-----------------------------------------------
target ?= flash

#-----------------------------------------------
# Choose the float point method.
# K22F51212 can use: NO_FP, SOFT_FP and HARD_FP.
# Application's float point configuration must
# be the same with the libraries it linked.
#-----------------------------------------------
CHOOSE_FLOAT ?= NO_FP

include $(SDK_ROOT)/mk/common.mk

#-----------------------------------------------
# include library. Only the name of the lib is 
# needed here, the targets.mk will convert it
# to correct library file. e.g. if platform_lib
# is added here, targets.mk will convert it to
# $(OUTPUT_ROOT)/lib/<CHIP>/platform.a
#-----------------------------------------------
LINK_LIB_NAME := platform_lib

#-----------------------------------------------
# Include path. Add the include paths like this:
# INCLUDES += ./include/
#-----------------------------------------------
INCLUDES += $(SDK_LIB_ROOT)/drivers/adc   \
            $(SDK_LIB_ROOT)/drivers/can   \
            $(SDK_LIB_ROOT)/drivers/clock \
            $(SDK_LIB_ROOT)/drivers/dspi/dspi_master  \
            $(SDK_LIB_ROOT)/drivers/dspi/dspi_slave \
            $(SDK_LIB_ROOT)/drivers/edma  \
            $(SDK_LIB_ROOT)/drivers/enet  \
            $(SDK_LIB_ROOT)/drivers/flash \
            $(SDK_LIB_ROOT)/drivers/flextimer \
            $(SDK_LIB_ROOT)/drivers/gpio \
            $(SDK_LIB_ROOT)/drivers/i2c/i2c_master \
            $(SDK_LIB_ROOT)/drivers/i2c/i2c_slave \
            $(SDK_LIB_ROOT)/drivers/interrupt \
            $(SDK_LIB_ROOT)/drivers/khci \
            $(SDK_LIB_ROOT)/drivers/pit \
            $(SDK_LIB_ROOT)/drivers/rtc \
            $(SDK_LIB_ROOT)/drivers/sai \
            $(SDK_LIB_ROOT)/drivers/sdhc \
            $(SDK_LIB_ROOT)/drivers/smc \
            $(SDK_LIB_ROOT)/drivers/spi \
            $(SDK_LIB_ROOT)/drivers/uart  \
            $(SDK_LIB_ROOT)/drivers/wdog \
            $(SDK_LIB_ROOT)/hal/adc \
            $(SDK_LIB_ROOT)/hal/can \
            $(SDK_LIB_ROOT)/hal/dmamux \
            $(SDK_LIB_ROOT)/hal/dspi \
            $(SDK_LIB_ROOT)/hal/edma \
            $(SDK_LIB_ROOT)/hal/enet \
            $(SDK_LIB_ROOT)/hal/flextimer \
            $(SDK_LIB_ROOT)/hal/gpio \
            $(SDK_LIB_ROOT)/hal/i2c \
            $(SDK_LIB_ROOT)/hal/mcg \
            $(SDK_LIB_ROOT)/hal/osc \
            $(SDK_LIB_ROOT)/hal/pit \
            $(SDK_LIB_ROOT)/hal/pmc \
            $(SDK_LIB_ROOT)/hal/port      \
            $(SDK_LIB_ROOT)/hal/rtc \
            $(SDK_LIB_ROOT)/hal/sai \
            $(SDK_LIB_ROOT)/hal/sdhc \
            $(SDK_LIB_ROOT)/hal/sim \
            $(SDK_LIB_ROOT)/hal/smc \
            $(SDK_LIB_ROOT)/hal/uart      \
            $(SDK_LIB_ROOT)/hal/wdog \
            $(BOARD_ROOT)


#-----------------------------------------------
# Startup files
#-----------------------------------------------
STARTUP_ROOT := $(SDK_LIB_ROOT)/startup
STARTUP_SOURCES := $(STARTUP_ROOT)/startup.c \
                   $(STARTUP_ROOT)/M$(CHIP)/system_M$(CHIP).c \
                   $(STARTUP_ROOT)/M$(CHIP)/gcc/startup_M$(CHIP).S

#-----------------------------------------------
# Application files
#------------------------------------------------------------------
APP_SOURCES  := $(wildcard $(APPS_ROOT)/$(APP_NAME)/src/*.c)

#-----------------------------------------------
# Board related files, e.g. platform_pins.c
#-----------------------------------------------
BOARD_SOURCES := $(wildcard $(BOARD_ROOT)/*.c)

#-----------------------------------------------
# Add all sources needed here
#-----------------------------------------------
SOURCES = $(STARTUP_SOURCES) $(APP_SOURCES) $(BOARD_SOURCES)

#-----------------------------------------------
# Link file
# Input only the name of the link file here,
# the targets.mk will convert it to
# platform/linker/gcc/<CHIP>/$(LD_FILE_NAME)
# e.g, if LD_FILE_NAME is set to K22FN512xxx12_flash.ld
# the link file platform/linker/gcc/K22FN51212/K22FN512xxx12#_flash.ld
# will be used
#-----------------------------------------------
ifeq "$(target)" "sram"
LD_FILE_NAME := K64FN1Mxxx12_ram.ld
else
LD_FILE_NAME := K64FN1Mxxx12_flash.ld
endif

#-----------------------------------------------
# The start entry, if entry is not defined,
# _start of gcc library will be used by default.
#-----------------------------------------------
entry ?=
ifneq "$(entry)" ""
DEFINES += -D__START=$(entry)
endif

#-----------------------------------------------
# Define the stack size and heap size.
#-----------------------------------------------
stack ?= 0x400
heap  ?= 0x1000
DEFINES += -D__STACK_SIZE=$(stack) \
           -D__HEAP_SIZE=$(heap)

#----------------------------------------------------
# This project requires the platform to be defined in 
# order for platform dependent pins to be used.  
#-----------------------------------------------------
DEFINES += -Dtwrk64f120m

include $(SDK_ROOT)/mk/targets.mk 

