#*******************************************************************************
#                                                                              *
# Copyright (c) 2022 Texas Instruments Incorporated - http://www.ti.com/       *
#                        ALL RIGHTS RESERVED                                   *
#                                                                              *
#*******************************************************************************

# File: component.mk
#       This file is component include make file of MCAL.
# List of variables set in this file and their purpose:
# <mod>_RELPATH        - This is the relative path of the module, typically from
#                        top-level directory of the package
# <mod>_PATH           - This is the absolute path of the module. It derives from
#                        absolute path of the top-level directory (set in env.mk)
#                        and relative path set above
# <mod>_INCLUDE        - This is the path that has interface header files of the
#                        module. This can be multiple directories (space separated)
# <mod>_PKG_LIST       - Names of the modules (and sub-modules) that are a part
#                        part of this module, including itself.
# <mod>_PLATFORM_DEPENDENCY - "yes": means the code for this module depends on
#                             platform and the compiled obj/lib has to be kept
#                             under <platform> directory
#                             "no" or "" or if this variable is not defined: means
#                             this module has no platform dependent code and hence
#                             the obj/libs are not kept under <platform> dir.
# <mod>_CORE_DEPENDENCY     - "yes": means the code for this module depends on
#                             core and the compiled obj/lib has to be kept
#                             under <core> directory
#                             "no" or "" or if this variable is not defined: means
#                             this module has no core dependent code and hence
#                             the obj/libs are not kept under <core> dir.
# <mod>_APP_STAGE_FILES     - List of source files that belongs to the module
#                             <mod>, but that needs to be compiled at application
#                             build stage (in the context of the app). This is
#                             primarily for link time configurations or if the
#                             source file is dependent on options/defines that are
#                             application dependent. This can be left blank or
#                             not defined at all, in which case, it means there
#                             no source files in the module <mod> that are required
#                             to be compiled in the application build stage.
#
ifeq ($(component_make_include), )

ifeq ($(PLATFORM),$(filter $(PLATFORM), am263))
DEFAULT_SOCLIST = am263
endif

############################
# device mcal package
# List of components included under mcal lib
# The components included here are built and will be part of mcal lib
# mcal HW files will be included in this order :
# 1. SOC specific HW file - $(mcal_PATH)/include/$(SOCFAMILY)/$(SOC)/hw
# 2. SOC Family specific HW file - $(mcal_PATH)/include/$(SOCFAMILY)/hw
# 3. Common HW file - $(mcal_PATH)/include/hw
############################

mcal_LIB_LIST = mcu port gpt spi can wdg eth ethtrcv fls cdd_i2c

############################
# mcu mcal lib
############################
mcu_COMP_LIST = mcu
mcu_RELPATH = Mcu
mcu_PATH = $(mcal_PATH)/$(mcu_RELPATH)
mcu_PLATFORM_DEPENDENCY = yes
export mcu_COMP_LIST
export mcu_PLATFORM_DEPENDENCY
mcu_PKG_LIST = mcu
mcu_INCLUDE = $(mcu_PATH)/include
mcu_SOCLIST = $(DEFAULT_SOCLIST)
export mcu_SOCLIST

############################
# Dio mcal lib
############################
dio_COMP_LIST = dio
dio_RELPATH = dio
dio_PATH = $(mcal_PATH)/$(dio_RELPATH)
dio_PLATFORM_DEPENDENCY = yes
export dio_COMP_LIST
export dio_PLATFORM_DEPENDENCY
dio_PKG_LIST = dio
dio_INCLUDE = $(dio_PATH)/include
dio_SOCLIST = $(DEFAULT_SOCLIST)
export dio_SOCLIST

############################
# port mcal lib
############################
port_COMP_LIST = port
port_RELPATH = Port
port_PATH = $(mcal_PATH)/$(port_RELPATH)
port_PLATFORM_DEPENDENCY = yes
export port_COMP_LIST
export port_PLATFORM_DEPENDENCY
port_PKG_LIST = port
port_INCLUDE = $(port_PATH)/include
port_SOCLIST = $(DEFAULT_SOCLIST)
export port_SOCLIST

############################
# gpt mcal lib
############################
gpt_COMP_LIST = gpt
gpt_RELPATH = Gpt
gpt_PATH = $(mcal_PATH)/$(gpt_RELPATH)
gpt_PLATFORM_DEPENDENCY = yes
export gpt_COMP_LIST
export gpt_PLATFORM_DEPENDENCY
gpt_PKG_LIST = gpt
gpt_INCLUDE = $(gpt_PATH)/include
gpt_SOCLIST = $(DEFAULT_SOCLIST)
export gpt_SOCLIST

############################
# dio mcal lib
############################
dio_COMP_LIST = dio
dio_RELPATH = Dio
dio_PATH = $(mcal_PATH)/$(dio_RELPATH)
dio_PLATFORM_DEPENDENCY = yes
export dio_COMP_LIST
export dio_PLATFORM_DEPENDENCY
dio_PKG_LIST = dio
dio_INCLUDE = $(dio_PATH)/include
dio_SOCLIST = $(DEFAULT_SOCLIST)
export dio_SOCLIST

############################
# wdg mcal lib
############################
wdg_COMP_LIST = wdg
wdg_RELPATH = Wdg
wdg_PATH = $(mcal_PATH)/$(wdg_RELPATH)
wdg_PLATFORM_DEPENDENCY = yes
export wdg_COMP_LIST
export wdg_PLATFORM_DEPENDENCY
wdg_PKG_LIST = wdg
wdg_INCLUDE = $(wdg_PATH)/include
wdg_SOCLIST = $(DEFAULT_SOCLIST)
export wdg_SOCLIST

############################
# spi mcal lib
############################
spi_COMP_LIST = spi
spi_RELPATH = Spi
spi_PATH = $(mcal_PATH)/$(spi_RELPATH)
spi_PLATFORM_DEPENDENCY = yes
export spi_COMP_LIST
export spi_PLATFORM_DEPENDENCY
spi_PKG_LIST = spi
spi_INCLUDE = $(spi_PATH)/include
spi_SOCLIST = $(DEFAULT_SOCLIST)
export spi_SOCLIST

############################
# can mcal lib
############################
can_COMP_LIST = can
can_RELPATH = Can
can_PATH = $(mcal_PATH)/$(can_RELPATH)
can_PLATFORM_DEPENDENCY = yes
export can_COMP_LIST
export can_PLATFORM_DEPENDENCY
can_PKG_LIST = can
can_INCLUDE = $(can_PATH)/include
can_SOCLIST = $(DEFAULT_SOCLIST)
export can_SOCLIST

############################
# fls mcal lib
############################
fls_COMP_LIST = fls
fls_RELPATH = Fls
fls_PATH = $(mcal_PATH)/$(fls_RELPATH)
fls_PLATFORM_DEPENDENCY = yes
export fls_COMP_LIST
export fls_PLATFORM_DEPENDENCY
fls_PKG_LIST = fls
fls_INCLUDE = $(fls_PATH)/include
fls_SOCLIST = $(DEFAULT_SOCLIST)
export fls_SOCLIST

############################
# eth mcal lib
############################
eth_COMP_LIST = eth
eth_RELPATH = Eth
eth_PATH = $(mcal_PATH)/$(eth_RELPATH)
eth_PLATFORM_DEPENDENCY = yes
export eth_COMP_LIST
export eth_PLATFORM_DEPENDENCY
eth_PKG_LIST = eth
eth_INCLUDE = $(eth_PATH)/include
eth_SOCLIST = $(DEFAULT_SOCLIST)
export eth_SOCLIST

############################
# ethtrcv mcal lib
############################
ethtrcv_COMP_LIST = ethtrcv
ethtrcv_RELPATH = EthTrcv
ethtrcv_PATH = $(mcal_PATH)/$(ethtrcv_RELPATH)
ethtrcv_PLATFORM_DEPENDENCY = yes
export ethtrcv_COMP_LIST
export ethtrcv_PLATFORM_DEPENDENCY
ethtrcv_PKG_LIST = ethtrcv
ethtrcv_INCLUDE = $(ethtrcv_PATH)/include
ethtrcv_SOCLIST = $(DEFAULT_SOCLIST)
export ethtrcv_SOCLIST

############################
# cdd_i2c mcal lib
############################
cdd_i2c_COMP_LIST = cdd_i2c
cdd_i2c_RELPATH = CDD_I2C
cdd_i2c_PATH = $(mcal_PATH)/$(cdd_i2c_RELPATH)
cdd_i2c_PLATFORM_DEPENDENCY = yes
export cdd_i2c_COMP_LIST
export cdd_i2c_PLATFORM_DEPENDENCY
cdd_i2c_PKG_LIST = cdd_i2c
cdd_i2c_INCLUDE = $(cdd_i2c_PATH)/include
cdd_i2c_SOCLIST = $(DEFAULT_SOCLIST)
export cdd_i2c_SOCLIST

############################
#device mcal examples
# List of examples under mcal
# All the tests mentioned in list are built when test target is called
# List below all examples for allowed values
############################
mcal_EXAMPLE_LIST = mcu_app gpt_app mcspi_app can_app app_utils port_app dio_app wdg_app eth_app fls_app cdd_i2c_app
##############################
mcu_app_RELPATH = examples/Mcu
mcu_app_PATH = $(mcal_PATH)/$(mcu_app_RELPATH)
mcu_app_PLATFORM_DEPENDENCY = yes
mcu_app_SOCLIST = $(DEFAULT_SOCLIST)
export mcu_app_SOCLIST
export mcu_app_PLATFORM_DEPENDENCY

gpt_app_RELPATH = examples/Gpt
gpt_app_PATH = $(mcal_PATH)/$(gpt_app_RELPATH)
gpt_app_PLATFORM_DEPENDENCY = yes
gpt_app_SOCLIST = $(DEFAULT_SOCLIST)
export gpt_app_SOCLIST
export gpt_app_PLATFORM_DEPENDENCY

dio_app_RELPATH = examples/Dio
dio_app_PATH = $(mcal_PATH)/$(dio_app_RELPATH)
dio_app_PLATFORM_DEPENDENCY = yes
dio_app_SOCLIST = $(DEFAULT_SOCLIST)
export dio_app_SOCLIST
export dio_app_PLATFORM_DEPENDENCY

wdg_app_RELPATH = examples/Wdg
wdg_app_PATH = $(mcal_PATH)/$(wdg_app_RELPATH)
wdg_app_PLATFORM_DEPENDENCY = yes
wdg_app_SOCLIST = $(DEFAULT_SOCLIST)
export wdg_app_SOCLIST
export wdg_app_PLATFORM_DEPENDENCY

fls_app_RELPATH = examples/Fls
fls_app_PATH = $(mcal_PATH)/$(fls_app_RELPATH)
fls_app_PLATFORM_DEPENDENCY = yes
fls_app_SOCLIST = $(DEFAULT_SOCLIST)
export fls_app_SOCLIST
export fls_app_PLATFORM_DEPENDENCY

mcspi_app_RELPATH = examples/spi/mcspi_app
mcspi_app_PATH = $(mcal_PATH)/$(mcspi_app_RELPATH)
mcspi_app_PLATFORM_DEPENDENCY = yes
mcspi_app_SOCLIST = $(DEFAULT_SOCLIST)
export mcspi_app_SOCLIST
export mcspi_app_PLATFORM_DEPENDENCY

qspi_flash_app_RELPATH = examples/Spi/qspi_flash_app
qspi_flash_app_PATH = $(mcal_PATH)/$(qspi_flash_app_RELPATH)
qspi_flash_app_PLATFORM_DEPENDENCY = yes
qspi_flash_app_SOCLIST = $(DEFAULT_SOCLIST)
export qspi_flash_app_SOCLIST
export qspi_flash_app_PLATFORM_DEPENDENCY
mibspi_app_RELPATH = examples/Spi/mibspi_app
mibspi_app_PATH = $(mcal_PATH)/$(mibspi_app_RELPATH)
mibspi_app_PLATFORM_DEPENDENCY = yes
mibspi_app_SOCLIST = $(DEFAULT_SOCLIST)
export mibspi_app_SOCLIST
export mibspi_app_PLATFORM_DEPENDENCY




can_app_RELPATH = examples/Can
can_app_PATH = $(mcal_PATH)/$(can_app_RELPATH)
can_app_PLATFORM_DEPENDENCY = yes
can_app_SOCLIST = $(DEFAULT_SOCLIST)
export can_app_SOCLIST
export can_app_PLATFORM_DEPENDENCY

port_app_RELPATH = examples/port
port_app_PATH = $(mcal_PATH)/$(port_app_RELPATH)
port_app_PLATFORM_DEPENDENCY = yes
port_app_SOCLIST = $(DEFAULT_SOCLIST)
export port_app_SOCLIST
export port_app_PLATFORM_DEPENDENCY

dio_app_RELPATH = examples/Dio
dio_app_PATH = $(mcal_PATH)/$(dio_app_RELPATH)
dio_app_PLATFORM_DEPENDENCY = yes
dio_app_SOCLIST = $(DEFAULT_SOCLIST)
export dio_app_SOCLIST
export dio_app_PLATFORM_DEPENDENCY

eth_app_RELPATH = examples/Eth/eth_app
eth_app_PATH = $(mcal_PATH)/$(eth_app_RELPATH)
eth_app_PLATFORM_DEPENDENCY = yes
eth_app_SOCLIST = $(DEFAULT_SOCLIST)
export eth_app_SOCLIST
export eth_app_PLATFORM_DEPENDENCY

cdd_i2c_app_RELPATH = examples/CDD_I2C
cdd_i2c_app_PATH = $(mcal_PATH)/$(cdd_i2c_app_RELPATH)
cdd_i2c_app_PLATFORM_DEPENDENCY = yes
cdd_i2c_app_SOCLIST = $(DEFAULT_SOCLIST)
export cdd_i2c_app_SOCLIST
export cdd_i2c_app_PLATFORM_DEPENDENCY

##################################

app_utils_COMP_LIST = app_utils
app_utils_RELPATH = examples/Utils
app_utils_PATH = $(mcal_PATH)/$(app_utils_RELPATH)
app_utils_PLATFORM_DEPENDENCY = yes
app_utils_SOCLIST = $(DEFAULT_SOCLIST)
export app_utils_SOCLIST
export app_utils_PLATFORM_DEPENDENCY
export app_utils_COMP_LIST
app_utils_PKG_LIST = app_utils
app_utils_INCLUDE = $(app_utils_PATH)
###$(app_utils_PATH)/Intc/$(ARCH)

mcal_PKG_LIST_ALL = $(mcal_EXAMPLE_LIST) $(mcal_LIB_LIST)

# Component specific CFLAGS
#CFLAGS_COMP_COMMON
MCAL_CFLAGS =
MCAL_LNKFLAGS =

MCAL_LNKFLAGS += --define=-define=ENABLE_ASILB_CHECK

ifeq ($(CORE),$(filter $(CORE), r4))
  MCAL_CFLAGS += -DBUILD_R4
  MCAL_LNKFLAGS += --define=BUILD_R4
endif

ifeq ($(CORE),$(filter $(CORE), r5f))
  MCAL_CFLAGS += -DBUILD_R5F
  MCAL_LNKFLAGS += --define=BUILD_R5F
endif

#Added CFLAG for gcc tool chain, other toolchain cflags can be added here if required

ifeq ($(TOOLCHAIN_$(ISA)),gcc)
MCAL_CFLAGS += -DBUILD_GCC
endif

#Enable trace only for non-Klockwork build and for all profiles
ifeq ($(KW_BUILD),no)
  MCAL_CFLAGS += -DTRACE_ENABLE
endif

# Enable standard asserts for klockwork build
ifeq ($(KW_BUILD),yes)
  MCAL_CFLAGS += -DUSE_STD_ASSERT -DASSERT_ENABLE -DTRACE_ENABLE
endif

ifeq ($(PROFILE_$(CORE)),debug)
  MCAL_CFLAGS += -DDEBUG_BUILD
# Enable asserts for debug build
  MCAL_CFLAGS += -DASSERT_ENABLE
endif

ifeq ($(PROFILE_$(CORE)),release)
  MCAL_CFLAGS += -DRELEASE_BUILD
# Enable asserts for release build
  MCAL_CFLAGS += -DASSERT_ENABLE
endif

ifeq ($(PROFILE_$(CORE)),prod_release)
  MCAL_CFLAGS += -DPROD_RELEASE_BUILD
# Disable asserts for production release
#  MCAL_CFLAGS += -DASSERT_ENABLE
endif

# Add c++ build macro, required to comment out #pragma in library to just check the build,
# This should not be used in actual build
ifeq ($(CPLUSPLUS_BUILD), yes)
  MCAL_CFLAGS += -DMCAL_CPLUSPLUS_BUILD
endif

ifeq ($(MCAL_DYNAMIC_BUILD),TRUE)
  MCAL_CFLAGS += -DMCAL_DYNAMIC_BUILD
endif

ifeq ($(AUTOSAR_VERSION),431)
  MCAL_CFLAGS += -DAUTOSAR_431
endif

export MCAL_LIBS
export MCAL_EXAMPLE_LIBS
export MCAL_CFLAGS
export MCAL_LNKFLAGS

component_make_include := 1
endif

# Nothing beyond this point
