/* ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. This file is part of ChibiOS. ChibiOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. ChibiOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /** * @page concepts Kernel Concepts * @brief ChibiOS/RT Kernel Concepts * - @ref naming * - @ref api_suffixes * - @ref interrupt_classes * - @ref system_states * - @ref scheduling * - @ref thread_states * - @ref priority * - @ref warea * . * @section naming Naming Conventions * ChibiOS/RT APIs are all named following this convention: * @a ch\\\(). * The possible groups are: @a Sys, @a Sch, @a Time, @a VT, @a Thd, @a Sem, * @a Mtx, @a Cond, @a Evt, @a Msg, @a Reg, @a SequentialStream, @a IO, @a IQ, * @a OQ, @a Dbg, @a Core, @a Heap, @a Pool. * * @section api_suffixes API Name Suffixes * The suffix can be one of the following: * - None, APIs without any suffix can be invoked only from the user * code in the Normal state unless differently specified. See * @ref system_states. * - @anchor I-Class "I", I-Class APIs are invokable only from the * I-Locked or S-Locked states. See @ref system_states. * - @anchor S-Class "S", S-Class APIs are invokable only from the * S-Locked state. See @ref system_states. * . * Examples: @p chThdCreateStatic(), @p chSemSignalI(), @p chIQGetTimeout(). * * @section interrupt_classes Interrupt Classes * In ChibiOS/RT there are three logical interrupt classes: * - Regular Interrupts. Maskable interrupt sources that cannot * preempt (small parts of) the kernel code and are thus able to invoke * operating system APIs from within their handlers. The interrupt handlers * belonging to this class must be written following some rules. See the * system APIs group and the web article * * How to write interrupt handlers. * - Fast Interrupts. Maskable interrupt sources with the ability * to preempt the kernel code and thus have a lower latency and are less * subject to jitter, see the web article * * Response Time and Jitter. * Such sources are not supported on all the architectures.
* Fast interrupts are not allowed to invoke any operating system API from * within their handlers. Fast interrupt sources may, however, pend a lower * priority regular interrupt where access to the operating system is * possible. * - Non Maskable Interrupts. Non maskable interrupt sources are * totally out of the operating system control and have the lowest latency. * Such sources are not supported on all the architectures. * . * The mapping of the above logical classes into physical interrupts priorities * is, of course, port dependent. See the documentation of the various ports * for details. * * @section system_states System States * When using ChibiOS/RT the system can be in one of the following logical * operating states: * - Init. When the system is in this state all the maskable * interrupt sources are disabled. In this state it is not possible to use * any system API except @p chSysInit(). This state is entered after a * physical reset. * - Normal. All the interrupt sources are enabled and the system APIs * are accessible, threads are running. * - Suspended. In this state the fast interrupt sources are enabled but * the regular interrupt sources are not. In this state it is not possible * to use any system API except @p chSysDisable() or @p chSysEnable() in * order to change state. * - Disabled. When the system is in this state both the maskable * regular and fast interrupt sources are disabled. In this state it is not * possible to use any system API except @p chSysSuspend() or * @p chSysEnable() in order to change state. * - Sleep. Architecture-dependent low power mode, the idle thread * goes in this state and waits for interrupts, after servicing the interrupt * the Normal state is restored and the scheduler has a chance to reschedule. * - S-Locked. Kernel locked and regular interrupt sources disabled. * Fast interrupt sources are enabled. @ref S-Class and @ref I-Class APIs are * invokable in this state. * - I-Locked. Kernel locked and regular interrupt sources disabled. * @ref I-Class APIs are invokable from this state. * - Serving Regular Interrupt. No system APIs are accessible but it is * possible to switch to the I-Locked state using @p chSysLockFromIsr() and * then invoke any @ref I-Class API. Interrupt handlers can be preemptable on * some architectures thus is important to switch to I-Locked state before * invoking system APIs. * - Serving Fast Interrupt. System APIs are not accessible. * - Serving Non-Maskable Interrupt. System APIs are not accessible. * - Halted. All interrupt sources are disabled and system stopped into * an infinite loop. This state can be reached if the debug mode is activated * and an error is detected or after explicitly invoking * @p chSysHalt(). * . * Note that the above states are just Logical States that may have no * real associated machine state on some architectures. The following diagram * shows the possible transitions between the states: * * @if LATEX_PDF * @dot digraph example { size="5, 7"; rankdir="LR"; node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.75", height="0.75"]; edge [fontname=Helvetica, fontsize=8]; init [label="Init", style="bold"]; norm [label="Normal", shape=doublecircle]; susp [label="Suspended"]; disab [label="Disabled"]; slock [label="S-Locked"]; ilock [label="I-Locked"]; slock [label="S-Locked"]; sleep [label="Sleep"]; sri [label="SRI"]; init -> norm [label="chSysInit()"]; norm -> slock [label="chSysLock()", constraint=false]; slock -> norm [label="chSysUnlock()"]; norm -> susp [label="chSysSuspend()"]; susp -> disab [label="chSysDisable()"]; norm -> disab [label="chSysDisable()"]; susp -> norm [label="chSysEnable()"]; disab -> norm [label="chSysEnable()"]; disab -> susp [label="chSysSuspend()"]; slock -> ilock [label="Context Switch", dir="both"]; norm -> sri [label="Regular IRQ", style="dotted"]; sri -> norm [label="Regular IRQ return", fontname=Helvetica, fontsize=8]; sri -> ilock [label="chSysLockFromIsr()", constraint=false]; ilock -> sri [label="chSysUnlockFromIsr()", fontsize=8]; norm -> sleep [label="Idle Thread"]; sleep -> sri [label="Regular IRQ", style="dotted"]; } * @enddot * @else * @dot digraph example { rankdir="LR"; node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.75", height="0.75"]; edge [fontname=Helvetica, fontsize=8]; init [label="Init", style="bold"]; norm [label="Normal", shape=doublecircle]; susp [label="Suspended"]; disab [label="Disabled"]; slock [label="S-Locked"]; ilock [label="I-Locked"]; slock [label="S-Locked"]; sleep [label="Sleep"]; sri [label="SRI"]; init -> norm [label="chSysInit()"]; norm -> slock [label="chSysLock()", constraint=false]; slock -> norm [label="chSysUnlock()"]; norm -> susp [label="chSysSuspend()"]; susp -> disab [label="chSysDisable()"]; norm -> disab [label="chSysDisable()"]; susp -> norm [label="chSysEnable()"]; disab -> norm [label="chSysEnable()"]; disab -> susp [label="chSysSuspend()"]; slock -> ilock [label="Context Switch", dir="both"]; norm -> sri [label="Regular IRQ", style="dotted"]; sri -> norm [label="Regular IRQ return", fontname=Helvetica, fontsize=8]; sri -> ilock [label="chSysLockFromIsr()", constraint=false]; ilock -> sri [label="chSysUnlockFromIsr()", fontsize=8]; norm -> sleep [label="Idle Thread"]; sleep -> sri [label="Regular IRQ", style="dotted"]; } * @enddot * @endif * Note, the SFI, Halted and SNMI states were not shown * because those are reachable from most states: * * @dot digraph example { size="5, 7"; rankdir="LR"; node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.75", height="0.75"]; edge [fontname=Helvetica, fontsize=8]; any1 [label="Any State\nexcept *"]; sfi [label="SFI"]; any1 -> sfi [style="dotted", label="Fast IRQ"]; sfi -> any1 [label="Fast IRQ return"]; } * @enddot * @dot digraph example { size="5, 7"; rankdir="LR"; node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.75", height="0.75"]; edge [fontname=Helvetica, fontsize=8]; any2 [label="Any State"]; halt [label="Halted"]; SNMI [label="SNMI"]; any2 -> halt [label="chSysHalt()"]; any2 -> SNMI [label="Synchronous NMI"]; any2 -> SNMI [label="Asynchronous NMI", style="dotted"]; SNMI -> any2 [label="NMI return"]; halt -> SNMI [label="Asynchronous NMI", style="dotted"]; SNMI -> halt [label="NMI return"]; } * @enddot * @attention * except: Init, Halt, SNMI, Disabled. * * @section scheduling Scheduling * The strategy is very simple the currently ready thread with the highest * priority is executed. If more than one thread with equal priority are * eligible for execution then they are executed in a round-robin way, the * CPU time slice constant is configurable. The ready list is a double linked * list of threads ordered by priority.

* @if LATEX_PDF * @dot digraph example { size="5, 7"; rankdir="LR"; node [shape=square, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.6", height="0.5"]; edge [fontname=Helvetica, fontsize=8]; subgraph cluster_running { node [shape=square, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.6", height="0.5"]; currp [label="'currp'\npointer", style="bold"]; T4 [label="Tuser(4)\nprio=100"]; label = "Currently Running Thread"; penwidth = 0; } subgraph cluster_rlist { node [shape=square, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.6", height="0.5"]; rh [label="ready list\nheader\nprio=0", style="bold"]; Ti [label="Tidle\nprio=1"]; Tm [label="Tmain\nprio=64"]; T1 [label="Tuser(1)\nprio=32"]; T2 [label="Tuser(2)\nprio=32"]; T3 [label="Tuser(3)\nprio=80"]; label = "Threads Ready for Execution"; penwidth = 0; } currp -> T4 rh -> Ti -> T1 -> T2 -> Tm -> T3 -> rh [label="p_next"]; rh -> T3 -> Tm -> T2 -> T1 -> Ti -> rh [label="p_prev"]; } * @enddot * @else * @dot digraph example { rankdir="LR"; node [shape=square, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.6", height="0.5"]; edge [fontname=Helvetica, fontsize=8]; subgraph cluster_running { node [shape=square, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.6", height="0.5"]; currp [label="'currp'\npointer", style="bold"]; T4 [label="Tuser(4)\nprio=100"]; label = "Currently Running Thread"; penwidth = 0; } subgraph cluster_rlist { node [shape=square, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.6", height="0.5"]; rh [label="ready list\nheader\nprio=0", style="bold"]; Ti [label="Tidle\nprio=1"]; Tm [label="Tmain\nprio=64"]; T1 [label="Tuser(1)\nprio=32"]; T2 [label="Tuser(2)\nprio=32"]; T3 [label="Tuser(3)\nprio=80"]; label = "Threads Ready for Execution"; penwidth = 0; } currp -> T4 rh -> Ti -> T1 -> T2 -> Tm -> T3 -> rh [label="p_next"]; rh -> T3 -> Tm -> T2 -> T1 -> Ti -> rh [label="p_prev"]; } * @enddot * @endif *
* Note that the currently running thread is not in the ready list, the list * only contains the threads ready to be executed but still actually waiting. * * @section thread_states Thread States * The image shows how threads can change their state in ChibiOS/RT.
* @if LATEX_PDF * @dot digraph example { rankdir="LR"; node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.75", height="0.75"]; size="5, 7"; edge [fontname=Helvetica, fontsize=8]; start [label="Start", style="bold"]; run [label="Running"]; ready [label="Ready"]; suspend [label="Suspended"]; sleep [label="Sleeping"]; stop [label="Stop", style="bold"]; start -> suspend [label="\n chThdCreateI()", constraint=false, dir=back]; start -> run [label="chThdCreate()"]; start -> ready [label="chThdCreate()"]; run -> ready [label="Reschedule", dir="both"]; suspend -> run [label="chThdResume()"]; suspend -> ready [label="chThdResume()"]; run -> sleep [label="chSchGoSleepS()"]; sleep -> run [label="chSchWakepuS()"]; sleep -> ready [label="chSchWakepuS()"]; run -> stop [label="chThdExit()"]; } * @enddot * @else * @dot digraph example { rankdir="LR"; node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.75", height="0.75"]; edge [fontname=Helvetica, fontsize=8]; start [label="Start", style="bold"]; run [label="Running"]; ready [label="Ready"]; suspend [label="Suspended"]; sleep [label="Sleeping"];
# ARM Cortex-Mx common makefile scripts and rules.

##############################################################################
# Processing options coming from the upper Makefile.
#

# Compiler options
OPT = $(USE_OPT)
COPT = $(USE_COPT)
CPPOPT = $(USE_CPPOPT)

# Garbage collection
ifeq ($(USE_LINK_GC),yes)
  OPT += -ffunction-sections -fdata-sections -fno-common
  LDOPT := ,--gc-sections
else
  LDOPT :=
endif

# Linker extra options
ifneq ($(USE_LDOPT),)
  LDOPT := $(LDOPT),$(USE_LDOPT)
endif

# Link time optimizations
ifeq ($(USE_LTO),yes)
  OPT += -flto
endif

# Undefined state stack size
ifeq ($(USE_UND_STACKSIZE),)
  LDOPT := $(LDOPT),--defsym=__und_stack_size__=8
else
  LDOPT := $(LDOPT),--defsym=__und_stack_size__=$(USE_UND_STACKSIZE)
endif

# Abort stack size
ifeq ($(USE_ABT_STACKSIZE),)
  LDOPT := $(LDOPT),--defsym=__abt_stack_size__=8
else
  LDOPT := $(LDOPT),--defsym=__abt_stack_size__=$(USE_ABT_STACKSIZE)
endif

# FIQ stack size
ifeq ($(USE_FIQ_STACKSIZE),)
  LDOPT := $(LDOPT),--defsym=__fiq_stack_size__=64
else
  LDOPT := $(LDOPT),--defsym=__fiq_stack_size__=$(USE_FIQ_STACKSIZE)
endif

# IRQ stack size
ifeq ($(USE_IRQ_STACKSIZE),)
  LDOPT := $(LDOPT),--defsym=__irq_stack_size__=0x400
else
  LDOPT := $(LDOPT),--defsym=__irq_stack_size__=$(USE_IRQ_STACKSIZE)
endif

# Supervisor stack size
ifeq ($(USE_SUPERVISOR_STACKSIZE),)
  LDOPT := $(LDOPT),--defsym=__svc_stack_size__=8
else
  LDOPT := $(LDOPT),--defsym=__svc_stack_size__=$(USE_SUPERVISOR_STACKSIZE)
endif

# System stack size
ifeq ($(USE_SYSTEM_STACKSIZE),)
  LDOPT := $(LDOPT),--defsym=__sys_stack_size__=0x400
else
  LDOPT := $(LDOPT),--defsym=__sys_stack_size__=$(USE_SYSTEM_STACKSIZE)
endif

# Output directory and files
ifeq ($(BUILDDIR),)
  BUILDDIR = build
endif
ifeq ($(BUILDDIR),.)
  BUILDDIR = build
endif

# Dependencies directory
ifeq ($(DEPDIR),)
  DEPDIR = .dep
endif
ifeq ($(DEPDIR),.)
  DEPDIR = .dep
endif

OUTFILES = $(BUILDDIR)/$(PROJECT).elf $(BUILDDIR)/$(PROJECT).hex \
           $(BUILDDIR)/$(PROJECT).bin $(BUILDDIR)/$(PROJECT).dmp \
           $(BUILDDIR)/$(PROJECT).list

# Source files groups and paths
ifeq ($(USE_THUMB),yes)
  TCSRC += $(CSRC)
  TCPPSRC += $(CPPSRC)
else
  ACSRC += $(CSRC)
  ACPPSRC += $(CPPSRC)
endif
ASRC      = $(ACSRC) $(ACPPSRC)
TSRC      = $(TCSRC) $(TCPPSRC)
SRCPATHS  = $(sort $(dir $(ASMXSRC)) $(dir $(ASMSRC)) $(dir $(ASRC)) $(dir $(TSRC)))

# Various directories
OBJDIR    = $(BUILDDIR)/obj
LSTDIR    = $(BUILDDIR)/lst

# Object files groups
ACOBJS    = $(addprefix $(OBJDIR)/, $(notdir $(ACSRC:.c=.o)))
ACPPOBJS  = $(addprefix $(OBJDIR)/, $(notdir $(ACPPSRC:.cpp=.o)))
TCOBJS    = $(addprefix $(OBJDIR)/, $(notdir $(TCSRC:.c=.o)))
TCPPOBJS  = $(addprefix $(OBJDIR)/, $(notdir $(TCPPSRC:.cpp=.o)))
ASMOBJS   = $(addprefix $(OBJDIR)/, $(notdir $(ASMSRC:.s=.o)))
ASMXOBJS  = $(addprefix $(OBJDIR)/, $(notdir $(ASMXSRC:.S=.o)))
OBJS      = $(ASMXOBJS) $(ASMOBJS) $(ACOBJS) $(TCOBJS) $(ACPPOBJS) $(TCPPOBJS)

# Paths
IINCDIR   = $(patsubst %,-I%,$(INCDIR) $(DINCDIR) $(UINCDIR))
LLIBDIR   = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))

# Macros
DEFS      = $(DDEFS) $(UDEFS)
ADEFS     = $(DADEFS) $(UADEFS)

# Libs
LIBS      = $(DLIBS) $(ULIBS)

# Various settings
MCFLAGS   = -mcpu=$(MCU)
ODFLAGS   = -x --syms
ASFLAGS   = $(MCFLAGS) $(OPT) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.s=.lst)) $(ADEFS)
ASXFLAGS  = $(MCFLAGS) $(OPT) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.S=.lst)) $(ADEFS)
CFLAGS    = $(MCFLAGS) $(OPT) $(COPT) $(CWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.c=.lst)) $(DEFS)
CPPFLAGS  = $(MCFLAGS) $(OPT) $(CPPOPT) $(CPPWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.cpp=.lst)) $(DEFS)
LDFLAGS   = $(MCFLAGS) $(OPT) -nostartfiles $(LLIBDIR) -Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch,--library-path=$(RULESPATH)/ld,--script=$(LDSCRIPT)$(LDOPT)

# Thumb interwork enabled only if needed because it kills performance.
ifneq ($(strip $(TSRC)),)
  CFLAGS   += -DTHUMB_PRESENT
  CPPFLAGS += -DTHUMB_PRESENT
  ASFLAGS  += -DTHUMB_PRESENT
  ASXFLAGS += -DTHUMB_PRESENT
  ifneq ($(strip $(ASRC)),)
    # Mixed ARM and THUMB mode.
    CFLAGS   += -mthumb-interwork
    CPPFLAGS += -mthumb-interwork
    ASFLAGS  += -mthumb-interwork
    ASXFLAGS += -mthumb-interwork
    LDFLAGS  += -mthumb-interwork
  else
    # Pure THUMB mode, THUMB C code cannot be called by ARM asm code directly.
    CFLAGS   += -mno-thumb-interwork -DTHUMB_NO_INTERWORKING
    CPPFLAGS += -mno-thumb-interwork -DTHUMB_NO_INTERWORKING
    ASFLAGS  += -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -mthumb
    ASXFLAGS += -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -mthumb
    LDFLAGS  += -mno-thumb-interwork -mthumb
  endif
else
  # Pure ARM mode
  CFLAGS   += -mno-thumb-interwork
  CPPFLAGS += -mno-thumb-interwork
  ASFLAGS  += -mno-thumb-interwork
  ASXFLAGS += -mno-thumb-interwork
  LDFLAGS  += -mno-thumb-interwork
endif

# Generate dependency information
ASFLAGS  += -MD -MP -MF $(DEPDIR)/$(@F).d
ASXFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d
CFLAGS   += -MD -MP -MF $(DEPDIR)/$(@F).d
CPPFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d

# Paths where to search for sources
VPATH     = $(SRCPATHS)

#
# Makefile rules
#

all: PRE_MAKE_ALL_RULE_HOOK $(OBJS) $(OUTFILES) POST_MAKE_ALL_RULE_HOOK

PRE_MAKE_ALL_RULE_HOOK:

POST_MAKE_ALL_RULE_HOOK:

$(OBJS): | $(BUILDDIR) $(OBJDIR) $(LSTDIR)

$(BUILDDIR):
ifneq ($(USE_VERBOSE_COMPILE),yes)
	@echo Compiler Options
	@echo $(CC) -c $(CFLAGS) -I. $(IINCDIR) main.c -o main.o
	@echo
endif
	@mkdir -p $(BUILDDIR)

$(OBJDIR):
	@mkdir -p $(OBJDIR)

$(LSTDIR):
	@mkdir -p $(LSTDIR)

$(ACPPOBJS) : $(OBJDIR)/%.o : %.cpp $(MAKEFILE_LIST)
ifeq ($(USE_VERBOSE_COMPILE),yes)
	@echo
	$(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
else
	@echo Compiling $(<F)
	@$(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
endif

$(TCPPOBJS) : $(OBJDIR)/%.o : %.cpp $(MAKEFILE_LIST)
ifeq ($(USE_VERBOSE_COMPILE),yes)
	@echo
	$(CPPC) -c $(CPPFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
else
	@echo Compiling $(<F)
	@$(CPPC) -c $(CPPFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
endif

$(ACOBJS) : $(OBJDIR)/%.o : %.c $(MAKEFILE_LIST)
ifeq ($(USE_VERBOSE_COMPILE),yes)
	@echo
	$(CC) -c $(CFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
else
	@echo Compiling $(<F)
	@$(CC) -c $(CFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
endif

$(TCOBJS) : $(OBJDIR)/%.o : %.c $(MAKEFILE_LIST)
ifeq ($(USE_VERBOSE_COMPILE),yes)
	@echo
	$(CC) -c $(CFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
else
	@echo Compiling $(<F)
	@$(CC) -c $(CFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
endif

$(ASMOBJS) : $(OBJDIR)/%.o : %.s $(MAKEFILE_LIST)
ifeq ($(USE_VERBOSE_COMPILE),yes)
	@echo
	$(AS) -c $(ASFLAGS) -I. $(IINCDIR) $< -o $@
else
	@echo Compiling $(<F)
	@$(AS) -c $(ASFLAGS) -I. $(IINCDIR) $< -o $@
endif

$(ASMXOBJS) : $(OBJDIR)/%.o : %.S $(MAKEFILE_LIST)
ifeq ($(USE_VERBOSE_COMPILE),yes)
	@echo
	$(CC) -c $(ASXFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
else
	@echo Compiling $(<F)
	@$(CC) -c $(ASXFLAGS) $(TOPT) -I. $(IINCDIR) $< -o $@
endif

$(BUILDDIR)/$(PROJECT).elf: $(OBJS) $(LDSCRIPT)
ifeq ($(USE_VERBOSE_COMPILE),yes)
	@echo
	$(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
else
	@echo Linking $@
	@$(LD) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
endif

%.hex: %.elf
ifeq ($(USE_VERBOSE_COMPILE),yes)
	$(HEX) $< $@
else
	@echo Creating $@
	@$(HEX) $< $@
endif

%.bin: %.elf
ifeq ($(USE_VERBOSE_COMPILE),yes)
	$(BIN) $< $@
else
	@echo Creating $@
	@$(BIN) $< $@
endif

%.dmp: %.elf
ifeq ($(USE_VERBOSE_COMPILE),yes)
	$(OD) $(ODFLAGS) $< > $@
	$(SZ) $<
else
	@echo Creating $@
	@$(OD) $(ODFLAGS) $< > $@
	@echo
	@$(SZ) $<
endif

%.list: %.elf
ifeq ($(USE_VERBOSE_COMPILE),yes)
	$(OD) -S $< > $@
else
	@echo Creating $@
	@$(OD) -S $< > $@
	@echo
	@echo Done
endif

lib: $(OBJS) $(BUILDDIR)/lib$(PROJECT).a

$(BUILDDIR)/lib$(PROJECT).a: $(OBJS)
	@$(AR) -r $@ $^
	@echo
	@echo Done

clean: CLEAN_RULE_HOOK
	@echo Cleaning
	-rm -fR $(DEPDIR) $(BUILDDIR)
	@echo
	@echo Done

CLEAN_RULE_HOOK:

#
# Include the dependency files, should be the last of the makefile
#
-include $(shell mkdir $(DEPDIR) 2>/dev/null) $(wildcard $(DEPDIR)/*)

# *** EOF ***