aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2019-06-09 13:12:55 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2019-06-09 13:12:55 +0000
commitd6fa47c7fdda2f4d616deb30a168d041bcb58947 (patch)
tree7bb68b4ff6cc62d002a9974c12f928076629f303
parente767b31b5e95901f36b6b630238a7e70944967a2 (diff)
downloadChibiOS-d6fa47c7fdda2f4d616deb30a168d041bcb58947.tar.gz
ChibiOS-d6fa47c7fdda2f4d616deb30a168d041bcb58947.tar.bz2
ChibiOS-d6fa47c7fdda2f4d616deb30a168d041bcb58947.zip
Added a "library generator" project for RT,
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/stable_19.1.x@12837 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
-rw-r--r--demos/various/RT-ARMCM4-MAKELIB/.cproject89
-rw-r--r--demos/various/RT-ARMCM4-MAKELIB/.project90
-rw-r--r--demos/various/RT-ARMCM4-MAKELIB/Makefile204
-rw-r--r--demos/various/RT-ARMCM4-MAKELIB/cfg/chconf.h714
-rw-r--r--demos/various/RT-ARMCM4-MAKELIB/dummy/_delimiter.h1
-rw-r--r--demos/various/RT-ARMCM4-MAKELIB/dummy/_header.h25
-rw-r--r--demos/various/RT-ARMCM4-MAKELIB/dummy/stdbool.h0
-rw-r--r--demos/various/RT-ARMCM4-MAKELIB/dummy/stddef.h0
-rw-r--r--demos/various/RT-ARMCM4-MAKELIB/dummy/stdint.h0
-rw-r--r--demos/various/RT-ARMCM4-MAKELIB/readme.txt15
-rw-r--r--demos/various/RT-ARMCM4-USELIB/.cproject52
-rw-r--r--demos/various/RT-ARMCM4-USELIB/.project90
-rw-r--r--demos/various/RT-ARMCM4-USELIB/Makefile189
-rw-r--r--demos/various/RT-ARMCM4-USELIB/debug/RT-ARMCM4-USELIB (OpenOCD, Flash and Run).launch52
-rw-r--r--demos/various/RT-ARMCM4-USELIB/main.c93
-rw-r--r--demos/various/RT-ARMCM4-USELIB/readme.txt18
-rw-r--r--demos/various/RT-ARMCM4-USELIB/rt/ch.h1632
-rw-r--r--readme.txt4
18 files changed, 3268 insertions, 0 deletions
diff --git a/demos/various/RT-ARMCM4-MAKELIB/.cproject b/demos/various/RT-ARMCM4-MAKELIB/.cproject
new file mode 100644
index 000000000..743c3490e
--- /dev/null
+++ b/demos/various/RT-ARMCM4-MAKELIB/.cproject
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+ <storageModule moduleId="org.eclipse.cdt.core.settings">
+ <cconfiguration id="0.114656749">
+ <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.114656749" moduleId="org.eclipse.cdt.core.settings" name="Make Library">
+ <externalSettings/>
+ <extensions>
+ <extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ </extensions>
+ </storageModule>
+ <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+ <configuration artifactName="${ProjName}" buildProperties="" description="" id="0.114656749" name="Make Library" parent="org.eclipse.cdt.build.core.prefbase.cfg">
+ <folderInfo id="0.114656749." name="/" resourcePath="">
+ <toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.1182750861" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
+ <targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.1182750861.169007201" name=""/>
+ <builder autoBuildTarget="all" cleanBuildTarget="clean" enableAutoBuild="false" enableCleanBuild="true" enabledIncrementalBuild="true" id="org.eclipse.cdt.build.core.settings.default.builder.579570726" incrementalBuildTarget="lib" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.libs.2143276802" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.1873650595" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1337802279" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+ </tool>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.1707090075" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.338985256" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+ </tool>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.1165165914" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.714476670" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+ </tool>
+ </toolChain>
+ </folderInfo>
+ </configuration>
+ </storageModule>
+ <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+ </cconfiguration>
+ <cconfiguration id="0.114656749.1713185331">
+ <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.114656749.1713185331" moduleId="org.eclipse.cdt.core.settings" name="Make Header">
+ <externalSettings/>
+ <extensions>
+ <extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ </extensions>
+ </storageModule>
+ <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+ <configuration artifactName="${ProjName}" buildProperties="" description="" id="0.114656749.1713185331" name="Make Header" parent="org.eclipse.cdt.build.core.prefbase.cfg">
+ <folderInfo id="0.114656749.1713185331." name="/" resourcePath="">
+ <toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.396396848" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
+ <targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.396396848.904396264" name=""/>
+ <builder autoBuildTarget="all" cleanBuildTarget="clean" enableAutoBuild="false" enableCleanBuild="true" enabledIncrementalBuild="true" id="org.eclipse.cdt.build.core.settings.default.builder.588055389" incrementalBuildTarget="header" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.libs.314614561" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.1404936766" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.553498795" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+ </tool>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.21924696" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.338253632" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+ </tool>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.1527148871" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.277780344" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+ </tool>
+ </toolChain>
+ </folderInfo>
+ </configuration>
+ </storageModule>
+ <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+ </cconfiguration>
+ </storageModule>
+ <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+ <project id="RT-ARMCM4-MAKELIB.null.1703860681" name="RT-ARMCM4-MAKELIB"/>
+ </storageModule>
+ <storageModule moduleId="scannerConfiguration">
+ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+ <scannerConfigBuildInfo instanceId="0.114656749">
+ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"/>
+ </scannerConfigBuildInfo>
+ </storageModule>
+ <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
+ <storageModule moduleId="refreshScope" versionNumber="2">
+ <configuration configurationName="Default">
+ <resource resourceType="PROJECT" workspacePath="/RT-ARMCM4-MAKELIB"/>
+ </configuration>
+ </storageModule>
+ <storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
+</cproject>
diff --git a/demos/various/RT-ARMCM4-MAKELIB/.project b/demos/various/RT-ARMCM4-MAKELIB/.project
new file mode 100644
index 000000000..bb8330c5f
--- /dev/null
+++ b/demos/various/RT-ARMCM4-MAKELIB/.project
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>RT-ARMCM4-MAKELIB</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+ <triggers>clean,full,incremental,</triggers>
+ <arguments>
+ <dictionary>
+ <key>?name?</key>
+ <value></value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.append_environment</key>
+ <value>true</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.autoBuildTarget</key>
+ <value>all</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.buildArguments</key>
+ <value>-j1</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.buildCommand</key>
+ <value>make</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
+ <value>clean</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.contents</key>
+ <value>org.eclipse.cdt.make.core.activeConfigSettings</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.enableAutoBuild</key>
+ <value>false</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.enableCleanBuild</key>
+ <value>true</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.enableFullBuild</key>
+ <value>true</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.fullBuildTarget</key>
+ <value>all</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.stopOnError</key>
+ <value>true</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
+ <value>true</value>
+ </dictionary>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
+ <triggers>full,incremental,</triggers>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.cdt.core.cnature</nature>
+ <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
+ <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
+ </natures>
+ <linkedResources>
+ <link>
+ <name>os</name>
+ <type>2</type>
+ <locationURI>CHIBIOS/os</locationURI>
+ </link>
+ <link>
+ <name>test</name>
+ <type>2</type>
+ <locationURI>CHIBIOS/test</locationURI>
+ </link>
+ </linkedResources>
+</projectDescription>
diff --git a/demos/various/RT-ARMCM4-MAKELIB/Makefile b/demos/various/RT-ARMCM4-MAKELIB/Makefile
new file mode 100644
index 000000000..3bce85b0e
--- /dev/null
+++ b/demos/various/RT-ARMCM4-MAKELIB/Makefile
@@ -0,0 +1,204 @@
+##############################################################################
+# Build global options
+# NOTE: Can be overridden externally.
+#
+
+# Compiler options here.
+ifeq ($(USE_OPT),)
+ USE_OPT = -O2 -fomit-frame-pointer -falign-functions=16
+endif
+
+# C specific options here (added to USE_OPT).
+ifeq ($(USE_COPT),)
+ USE_COPT =
+endif
+
+# C++ specific options here (added to USE_OPT).
+ifeq ($(USE_CPPOPT),)
+ USE_CPPOPT = -fno-rtti
+endif
+
+# Enable this if you want the linker to remove unused code and data.
+ifeq ($(USE_LINK_GC),)
+ USE_LINK_GC = yes
+endif
+
+# Linker extra options here.
+ifeq ($(USE_LDOPT),)
+ USE_LDOPT =
+endif
+
+# Enable this if you want link time optimizations (LTO).
+ifeq ($(USE_LTO),)
+ USE_LTO = no
+endif
+
+# Enable this if you want to see the full log while compiling.
+ifeq ($(USE_VERBOSE_COMPILE),)
+ USE_VERBOSE_COMPILE = no
+endif
+
+# If enabled, this option makes the build process faster by not compiling
+# modules not used in the current configuration.
+ifeq ($(USE_SMART_BUILD),)
+ USE_SMART_BUILD = yes
+endif
+
+#
+# Build global options
+##############################################################################
+
+##############################################################################
+# Architecture or project specific options
+#
+
+# Stack size to be allocated to the Cortex-M process stack. This stack is
+# the stack used by the main() thread.
+ifeq ($(USE_PROCESS_STACKSIZE),)
+ USE_PROCESS_STACKSIZE = 0x400
+endif
+
+# Stack size to the allocated to the Cortex-M main/exceptions stack. This
+# stack is used for processing interrupts and exceptions.
+ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
+ USE_EXCEPTIONS_STACKSIZE = 0x400
+endif
+
+# Enables the use of FPU (no, softfp, hard).
+ifeq ($(USE_FPU),)
+ USE_FPU = no
+endif
+
+# FPU-related options.
+ifeq ($(USE_FPU_OPT),)
+ USE_FPU_OPT = -mfloat-abi=$(USE_FPU) -mfpu=fpv4-sp-d16
+endif
+
+#
+# Architecture or project specific options
+##############################################################################
+
+##############################################################################
+# Project, target, sources and paths
+#
+
+# Define project name here
+PROJECT = ch
+
+# Target settings.
+MCU = cortex-m4
+
+# Device.
+DEVICE = STM32F407xx
+
+# Imported source files and paths.
+CHIBIOS := ../../..
+CONFDIR := ./cfg
+BUILDDIR := ./build
+DEPDIR := ./.dep
+
+# Licensing files.
+include $(CHIBIOS)/os/license/license.mk
+# Startup files.
+#include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk
+# HAL-OSAL files (optional).
+#include $(CHIBIOS)/os/hal/hal.mk
+#include $(CHIBIOS)/os/hal/ports/STM32/STM32F4xx/platform.mk
+#include $(CHIBIOS)/os/hal/boards/ST_STM32F4_DISCOVERY/board.mk
+#include $(CHIBIOS)/os/hal/osal/rt-nil/osal.mk
+# RTOS files (optional).
+include $(CHIBIOS)/os/rt/rt.mk
+include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
+# Auto-build files in ./source recursively.
+include $(CHIBIOS)/tools/mk/autobuild.mk
+# Other files (optional).
+#include $(CHIBIOS)/test/lib/test.mk
+#include $(CHIBIOS)/test/rt/rt_test.mk
+#include $(CHIBIOS)/test/oslib/oslib_test.mk
+
+# Define linker script file here
+LDSCRIPT= $(STARTUPLD)/STM32F407xG.ld
+
+# C sources that can be compiled in ARM or THUMB mode depending on the global
+# setting.
+CSRC = $(ALLCSRC) \
+ $(TESTSRC)
+
+# C++ sources that can be compiled in ARM or THUMB mode depending on the global
+# setting.
+CPPSRC = $(ALLCPPSRC)
+
+# List ASM source files here.
+ASMSRC = $(ALLASMSRC)
+
+# List ASM with preprocessor source files here.
+ASMXSRC = $(ALLXASMSRC)
+
+# Inclusion directories.
+INCDIR = $(CONFDIR) $(ALLINC) $(TESTINC) \
+ $(CHIBIOS)/os/common/ext/ARM/CMSIS/Core/Include \
+ $(CHIBIOS)/os/common/ext/ST/STM32F4xx \
+ $(CHIBIOS)/os/common/startup/ARMCMx/devices/STM32F4xx # Replace with your own.
+
+# Define C warning options here.
+CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes
+
+# Define C++ warning options here.
+CPPWARN = -Wall -Wextra -Wundef
+
+#
+# Project, target, sources and paths
+##############################################################################
+
+##############################################################################
+# Start of user section
+#
+
+# List all user C define here, like -D_DEBUG=1
+UDEFS = -D$(DEVICE)
+
+# Define ASM defines here
+UADEFS = -D$(DEVICE)
+
+# List all user directories here
+UINCDIR =
+
+# List the user directory to look for the libraries here
+ULIBDIR =
+
+# List all user libraries here
+ULIBS =
+
+#
+# End of user section
+##############################################################################
+
+##############################################################################
+# Common rules
+#
+
+RULESPATH = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk
+include $(RULESPATH)/arm-none-eabi.mk
+include $(RULESPATH)/rules.mk
+
+#
+# Common rules
+##############################################################################
+
+##############################################################################
+# Custom rules
+#
+
+header:
+ @echo Merging headers
+ @$(CC) -I./dummy $(IINCDIR) -D$(DEVICE) $(DEFS) -nostdinc -include cmparams.h -include _delimiter.h -fdirectives-only -dD -E -P ../../../os/rt/include/ch.h -o tmpch1.h
+ @$(CC) -fpreprocessed -dD -E -P tmpch1.h -o tmpch2.h
+ @sed -e '1,/___HEADER_BEGIN___/d' tmpch2.h > tmpch3.h
+ @cat ./dummy/_header.h > unified_ch.h
+ @cat tmpch3.h >> unified_ch.h
+ @rm tmpch*.h
+ @echo Done
+
+#
+# Custom rules
+##############################################################################
diff --git a/demos/various/RT-ARMCM4-MAKELIB/cfg/chconf.h b/demos/various/RT-ARMCM4-MAKELIB/cfg/chconf.h
new file mode 100644
index 000000000..78698eb78
--- /dev/null
+++ b/demos/various/RT-ARMCM4-MAKELIB/cfg/chconf.h
@@ -0,0 +1,714 @@
+/*
+ ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+/**
+ * @file rt/templates/chconf.h
+ * @brief Configuration file template.
+ * @details A copy of this file must be placed in each project directory, it
+ * contains the application specific kernel settings.
+ *
+ * @addtogroup config
+ * @details Kernel related settings and hooks.
+ * @{
+ */
+
+#ifndef CHCONF_H
+#define CHCONF_H
+
+#define _CHIBIOS_RT_CONF_
+#define _CHIBIOS_RT_CONF_VER_6_0_
+
+/*===========================================================================*/
+/**
+ * @name System timers settings
+ * @{
+ */
+/*===========================================================================*/
+
+/**
+ * @brief System time counter resolution.
+ * @note Allowed values are 16 or 32 bits.
+ */
+#if !defined(CH_CFG_ST_RESOLUTION)
+#define CH_CFG_ST_RESOLUTION 32
+#endif
+
+/**
+ * @brief System tick frequency.
+ * @details Frequency of the system timer that drives the system ticks. This
+ * setting also defines the system tick time unit.
+ */
+#if !defined(CH_CFG_ST_FREQUENCY)
+#define CH_CFG_ST_FREQUENCY 1000
+#endif
+
+/**
+ * @brief Time intervals data size.
+ * @note Allowed values are 16, 32 or 64 bits.
+ */
+#if !defined(CH_CFG_INTERVALS_SIZE)
+#define CH_CFG_INTERVALS_SIZE 32
+#endif
+
+/**
+ * @brief Time types data size.
+ * @note Allowed values are 16 or 32 bits.
+ */
+#if !defined(CH_CFG_TIME_TYPES_SIZE)
+#define CH_CFG_TIME_TYPES_SIZE 32
+#endif
+
+/**
+ * @brief Time delta constant for the tick-less mode.
+ * @note If this value is zero then the system uses the classic
+ * periodic tick. This value represents the minimum number
+ * of ticks that is safe to specify in a timeout directive.
+ * The value one is not valid, timeouts are rounded up to
+ * this value.
+ */
+#if !defined(CH_CFG_ST_TIMEDELTA)
+#define CH_CFG_ST_TIMEDELTA 0
+#endif
+
+/** @} */
+
+/*===========================================================================*/
+/**
+ * @name Kernel parameters and options
+ * @{
+ */
+/*===========================================================================*/
+
+/**
+ * @brief Round robin interval.
+ * @details This constant is the number of system ticks allowed for the
+ * threads before preemption occurs. Setting this value to zero
+ * disables the preemption for threads with equal priority and the
+ * round robin becomes cooperative. Note that higher priority
+ * threads can still preempt, the kernel is always preemptive.
+ * @note Disabling the round robin preemption makes the kernel more compact
+ * and generally faster.
+ * @note The round robin preemption is not supported in tickless mode and
+ * must be set to zero in that case.
+ */
+#if !defined(CH_CFG_TIME_QUANTUM)
+#define CH_CFG_TIME_QUANTUM 0
+#endif
+
+/**
+ * @brief Managed RAM size.
+ * @details Size of the RAM area to be managed by the OS. If set to zero
+ * then the whole available RAM is used. The core memory is made
+ * available to the heap allocator and/or can be used directly through
+ * the simplified core memory allocator.
+ *
+ * @note In order to let the OS manage the whole RAM the linker script must
+ * provide the @p __heap_base__ and @p __heap_end__ symbols.
+ * @note Requires @p CH_CFG_USE_MEMCORE.
+ */
+#if !defined(CH_CFG_MEMCORE_SIZE)
+#define CH_CFG_MEMCORE_SIZE 0
+#endif
+
+/**
+ * @brief Idle thread automatic spawn suppression.
+ * @details When this option is activated the function @p chSysInit()
+ * does not spawn the idle thread. The application @p main()
+ * function becomes the idle thread and must implement an
+ * infinite loop.
+ */
+#if !defined(CH_CFG_NO_IDLE_THREAD)
+#define CH_CFG_NO_IDLE_THREAD FALSE
+#endif
+
+/** @} */
+
+/*===========================================================================*/
+/**
+ * @name Performance options
+ * @{
+ */
+/*===========================================================================*/
+
+/**
+ * @brief OS optimization.
+ * @details If enabled then time efficient rather than space efficient code
+ * is used when two possible implementations exist.
+ *
+ * @note This is not related to the compiler optimization options.
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_CFG_OPTIMIZE_SPEED)
+#define CH_CFG_OPTIMIZE_SPEED TRUE
+#endif
+
+/** @} */
+
+/*===========================================================================*/
+/**
+ * @name Subsystem options
+ * @{
+ */
+/*===========================================================================*/
+
+/**
+ * @brief Time Measurement APIs.
+ * @details If enabled then the time measurement APIs are included in
+ * the kernel.
+ *
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_CFG_USE_TM)
+#define CH_CFG_USE_TM TRUE
+#endif
+
+/**
+ * @brief Threads registry APIs.
+ * @details If enabled then the registry APIs are included in the kernel.
+ *
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_CFG_USE_REGISTRY)
+#define CH_CFG_USE_REGISTRY TRUE
+#endif
+
+/**
+ * @brief Threads synchronization APIs.
+ * @details If enabled then the @p chThdWait() function is included in
+ * the kernel.
+ *
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_CFG_USE_WAITEXIT)
+#define CH_CFG_USE_WAITEXIT TRUE
+#endif
+
+/**
+ * @brief Semaphores APIs.
+ * @details If enabled then the Semaphores APIs are included in the kernel.
+ *
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_CFG_USE_SEMAPHORES)
+#define CH_CFG_USE_SEMAPHORES TRUE
+#endif
+
+/**
+ * @brief Semaphores queuing mode.
+ * @details If enabled then the threads are enqueued on semaphores by
+ * priority rather than in FIFO order.
+ *
+ * @note The default is @p FALSE. Enable this if you have special
+ * requirements.
+ * @note Requires @p CH_CFG_USE_SEMAPHORES.
+ */
+#if !defined(CH_CFG_USE_SEMAPHORES_PRIORITY)
+#define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE
+#endif
+
+/**
+ * @brief Mutexes APIs.
+ * @details If enabled then the mutexes APIs are included in the kernel.
+ *
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_CFG_USE_MUTEXES)
+#define CH_CFG_USE_MUTEXES TRUE
+#endif
+
+/**
+ * @brief Enables recursive behavior on mutexes.
+ * @note Recursive mutexes are heavier and have an increased
+ * memory footprint.
+ *
+ * @note The default is @p FALSE.
+ * @note Requires @p CH_CFG_USE_MUTEXES.
+ */
+#if !defined(CH_CFG_USE_MUTEXES_RECURSIVE)
+#define CH_CFG_USE_MUTEXES_RECURSIVE FALSE
+#endif
+
+/**
+ * @brief Conditional Variables APIs.
+ * @details If enabled then the conditional variables APIs are included
+ * in the kernel.
+ *
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_CFG_USE_MUTEXES.
+ */
+#if !defined(CH_CFG_USE_CONDVARS)
+#define CH_CFG_USE_CONDVARS TRUE
+#endif
+
+/**
+ * @brief Conditional Variables APIs with timeout.
+ * @details If enabled then the conditional variables APIs with timeout
+ * specification are included in the kernel.
+ *
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_CFG_USE_CONDVARS.
+ */
+#if !defined(CH_CFG_USE_CONDVARS_TIMEOUT)
+#define CH_CFG_USE_CONDVARS_TIMEOUT TRUE
+#endif
+
+/**
+ * @brief Events Flags APIs.
+ * @details If enabled then the event flags APIs are included in the kernel.
+ *
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_CFG_USE_EVENTS)
+#define CH_CFG_USE_EVENTS TRUE
+#endif
+
+/**
+ * @brief Events Flags APIs with timeout.
+ * @details If enabled then the events APIs with timeout specification
+ * are included in the kernel.
+ *
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_CFG_USE_EVENTS.
+ */
+#if !defined(CH_CFG_USE_EVENTS_TIMEOUT)
+#define CH_CFG_USE_EVENTS_TIMEOUT TRUE
+#endif
+
+/**
+ * @brief Synchronous Messages APIs.
+ * @details If enabled then the synchronous messages APIs are included
+ * in the kernel.
+ *
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_CFG_USE_MESSAGES)
+#define CH_CFG_USE_MESSAGES TRUE
+#endif
+
+/**
+ * @brief Synchronous Messages queuing mode.
+ * @details If enabled then messages are served by priority rather than in
+ * FIFO order.
+ *
+ * @note The default is @p FALSE. Enable this if you have special
+ * requirements.
+ * @note Requires @p CH_CFG_USE_MESSAGES.
+ */
+#if !defined(CH_CFG_USE_MESSAGES_PRIORITY)
+#define CH_CFG_USE_MESSAGES_PRIORITY FALSE
+#endif
+
+/**
+ * @brief Mailboxes APIs.
+ * @details If enabled then the asynchronous messages (mailboxes) APIs are
+ * included in the kernel.
+ *
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_CFG_USE_SEMAPHORES.
+ */
+#if !defined(CH_CFG_USE_MAILBOXES)
+#define CH_CFG_USE_MAILBOXES TRUE
+#endif
+
+/**
+ * @brief Core Memory Manager APIs.
+ * @details If enabled then the core memory manager APIs are included
+ * in the kernel.
+ *
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_CFG_USE_MEMCORE)
+#define CH_CFG_USE_MEMCORE TRUE
+#endif
+
+/**
+ * @brief Heap Allocator APIs.
+ * @details If enabled then the memory heap allocator APIs are included
+ * in the kernel.
+ *
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_CFG_USE_MEMCORE and either @p CH_CFG_USE_MUTEXES or
+ * @p CH_CFG_USE_SEMAPHORES.
+ * @note Mutexes are recommended.
+ */
+#if !defined(CH_CFG_USE_HEAP)
+#define CH_CFG_USE_HEAP TRUE
+#endif
+
+/**
+ * @brief Memory Pools Allocator APIs.
+ * @details If enabled then the memory pools allocator APIs are included
+ * in the kernel.
+ *
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_CFG_USE_MEMPOOLS)
+#define CH_CFG_USE_MEMPOOLS TRUE
+#endif
+
+/**
+ * @brief Objects FIFOs APIs.
+ * @details If enabled then the objects FIFOs APIs are included
+ * in the kernel.
+ *
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_CFG_USE_OBJ_FIFOS)
+#define CH_CFG_USE_OBJ_FIFOS TRUE
+#endif
+
+/**
+ * @brief Pipes APIs.
+ * @details If enabled then the pipes APIs are included
+ * in the kernel.
+ *
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_CFG_USE_PIPES)
+#define CH_CFG_USE_PIPES TRUE
+#endif
+
+/**
+ * @brief Dynamic Threads APIs.
+ * @details If enabled then the dynamic threads creation APIs are included
+ * in the kernel.
+ *
+ * @note The default is @p TRUE.
+ * @note Requires @p CH_CFG_USE_WAITEXIT.
+ * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS.
+ */
+#if !defined(CH_CFG_USE_DYNAMIC)
+#define CH_CFG_USE_DYNAMIC TRUE
+#endif
+
+/** @} */
+
+/*===========================================================================*/
+/**
+ * @name Objects factory options
+ * @{
+ */
+/*===========================================================================*/
+
+/**
+ * @brief Objects Factory APIs.
+ * @details If enabled then the objects factory APIs are included in the
+ * kernel.
+ *
+ * @note The default is @p FALSE.
+ */
+#if !defined(CH_CFG_USE_FACTORY)
+#define CH_CFG_USE_FACTORY TRUE
+#endif
+
+/**
+ * @brief Maximum length for object names.
+ * @details If the specified length is zero then the name is stored by
+ * pointer but this could have unintended side effects.
+ */
+#if !defined(CH_CFG_FACTORY_MAX_NAMES_LENGTH)
+#define CH_CFG_FACTORY_MAX_NAMES_LENGTH 8
+#endif
+
+/**
+ * @brief Enables the registry of generic objects.
+ */
+#if !defined(CH_CFG_FACTORY_OBJECTS_REGISTRY)
+#define CH_CFG_FACTORY_OBJECTS_REGISTRY TRUE
+#endif
+
+/**
+ * @brief Enables factory for generic buffers.
+ */
+#if !defined(CH_CFG_FACTORY_GENERIC_BUFFERS)
+#define CH_CFG_FACTORY_GENERIC_BUFFERS TRUE
+#endif
+
+/**
+ * @brief Enables factory for semaphores.
+ */
+#if !defined(CH_CFG_FACTORY_SEMAPHORES)
+#define CH_CFG_FACTORY_SEMAPHORES TRUE
+#endif
+
+/**
+ * @brief Enables factory for mailboxes.
+ */
+#if !defined(CH_CFG_FACTORY_MAILBOXES)
+#define CH_CFG_FACTORY_MAILBOXES TRUE
+#endif
+
+/**
+ * @brief Enables factory for objects FIFOs.
+ */
+#if !defined(CH_CFG_FACTORY_OBJ_FIFOS)
+#define CH_CFG_FACTORY_OBJ_FIFOS TRUE
+#endif
+
+/**
+ * @brief Enables factory for Pipes.
+ */
+#if !defined(CH_CFG_FACTORY_PIPES) || defined(__DOXYGEN__)
+#define CH_CFG_FACTORY_PIPES TRUE
+#endif
+
+/** @} */
+
+/*===========================================================================*/
+/**
+ * @name Debug options
+ * @{
+ */
+/*===========================================================================*/
+
+/**
+ * @brief Debug option, kernel statistics.
+ *
+ * @note The default is @p FALSE.
+ */
+#if !defined(CH_DBG_STATISTICS)
+#define CH_DBG_STATISTICS FALSE
+#endif
+
+/**
+ * @brief Debug option, system state check.
+ * @details If enabled the correct call protocol for system APIs is checked
+ * at runtime.
+ *
+ * @note The default is @p FALSE.
+ */
+#if !defined(CH_DBG_SYSTEM_STATE_CHECK)
+#define CH_DBG_SYSTEM_STATE_CHECK FALSE
+#endif
+
+/**
+ * @brief Debug option, parameters checks.
+ * @details If enabled then the checks on the API functions input
+ * parameters are activated.
+ *
+ * @note The default is @p FALSE.
+ */
+#if !defined(CH_DBG_ENABLE_CHECKS)
+#define CH_DBG_ENABLE_CHECKS FALSE
+#endif
+
+/**
+ * @brief Debug option, consistency checks.
+ * @details If enabled then all the assertions in the kernel code are
+ * activated. This includes consistency checks inside the kernel,
+ * runtime anomalies and port-defined checks.
+ *
+ * @note The default is @p FALSE.
+ */
+#if !defined(CH_DBG_ENABLE_ASSERTS)
+#define CH_DBG_ENABLE_ASSERTS FALSE
+#endif
+
+/**
+ * @brief Debug option, trace buffer.
+ * @details If enabled then the trace buffer is activated.
+ *
+ * @note The default is @p CH_DBG_TRACE_MASK_DISABLED.
+ */
+#if !defined(CH_DBG_TRACE_MASK)
+#define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED
+#endif
+
+/**
+ * @brief Trace buffer entries.
+ * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is
+ * different from @p CH_DBG_TRACE_MASK_DISABLED.
+ */
+#if !defined(CH_DBG_TRACE_BUFFER_SIZE)
+#define CH_DBG_TRACE_BUFFER_SIZE 128
+#endif
+
+/**
+ * @brief Debug option, stack checks.
+ * @details If enabled then a runtime stack check is performed.
+ *
+ * @note The default is @p FALSE.
+ * @note The stack check is performed in a architecture/port dependent way.
+ * It may not be implemented or some ports.
+ * @note The default failure mode is to halt the system with the global
+ * @p panic_msg variable set to @p NULL.
+ */
+#if !defined(CH_DBG_ENABLE_STACK_CHECK)
+#define CH_DBG_ENABLE_STACK_CHECK FALSE
+#endif
+
+/**
+ * @brief Debug option, stacks initialization.
+ * @details If enabled then the threads working area is filled with a byte
+ * value when a thread is created. This can be useful for the
+ * runtime measurement of the used stack.
+ *
+ * @note The default is @p FALSE.
+ */
+#if !defined(CH_DBG_FILL_THREADS)
+#define CH_DBG_FILL_THREADS FALSE
+#endif
+
+/**
+ * @brief Debug option, threads profiling.
+ * @details If enabled then a field is added to the @p thread_t structure that
+ * counts the system ticks occurred while executing the thread.
+ *
+ * @note The default is @p FALSE.
+ * @note This debug option is not currently compatible with the
+ * tickless mode.
+ */
+#if !defined(CH_DBG_THREADS_PROFILING)
+#define CH_DBG_THREADS_PROFILING FALSE
+#endif
+
+/** @} */
+
+/*===========================================================================*/
+/**
+ * @name Kernel hooks
+ * @{
+ */
+/*===========================================================================*/
+
+/**
+ * @brief System structure extension.
+ * @details User fields added to the end of the @p ch_system_t structure.
+ */
+#define CH_CFG_SYSTEM_EXTRA_FIELDS \
+ /* Add threads custom fields here.*/
+
+/**
+ * @brief System initialization hook.
+ * @details User initialization code added to the @p chSysInit() function
+ * just before interrupts are enabled globally.
+ */
+#define CH_CFG_SYSTEM_INIT_HOOK() { \
+ /* Add threads initialization code here.*/ \
+}
+
+/**
+ * @brief Threads descriptor structure extension.
+ * @details User fields added to the end of the @p thread_t structure.
+ */
+#define CH_CFG_THREAD_EXTRA_FIELDS \
+ /* Add threads custom fields here.*/
+
+/**
+ * @brief Threads initialization hook.
+ * @details User initialization code added to the @p _thread_init() function.
+ *
+ * @note It is invoked from within @p _thread_init() and implicitly from all
+ * the threads creation APIs.
+ */
+#define CH_CFG_THREAD_INIT_HOOK(tp) { \
+ /* Add threads initialization code here.*/ \
+}
+
+/**
+ * @brief Threads finalization hook.
+ * @details User finalization code added to the @p chThdExit() API.
+ */
+#define CH_CFG_THREAD_EXIT_HOOK(tp) { \
+ /* Add threads finalization code here.*/ \
+}
+
+/**
+ * @brief Context switch hook.
+ * @details This hook is invoked just before switching between threads.
+ */
+#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \
+ /* Context switch code here.*/ \
+}
+
+/**
+ * @brief ISR enter hook.
+ */
+#define CH_CFG_IRQ_PROLOGUE_HOOK() { \
+ /* IRQ prologue code here.*/ \
+}
+
+/**
+ * @brief ISR exit hook.
+ */
+#define CH_CFG_IRQ_EPILOGUE_HOOK() { \
+ /* IRQ epilogue code here.*/ \
+}
+
+/**
+ * @brief Idle thread enter hook.
+ * @note This hook is invoked within a critical zone, no OS functions
+ * should be invoked from here.
+ * @note This macro can be used to activate a power saving mode.
+ */
+#define CH_CFG_IDLE_ENTER_HOOK() { \
+ /* Idle-enter code here.*/ \
+}
+
+/**
+ * @brief Idle thread leave hook.
+ * @note This hook is invoked within a critical zone, no OS functions
+ * should be invoked from here.
+ * @note This macro can be used to deactivate a power saving mode.
+ */
+#define CH_CFG_IDLE_LEAVE_HOOK() { \
+ /* Idle-leave code here.*/ \
+}
+
+/**
+ * @brief Idle Loop hook.
+ * @details This hook is continuously invoked by the idle thread loop.
+ */
+#define CH_CFG_IDLE_LOOP_HOOK() { \
+ /* Idle loop code here.*/ \
+}
+
+/**
+ * @brief System tick event hook.
+ * @details This hook is invoked in the system tick handler immediately
+ * after processing the virtual timers queue.
+ */
+#define CH_CFG_SYSTEM_TICK_HOOK() { \
+ /* System tick event code here.*/ \
+}
+
+/**
+ * @brief System halt hook.
+ * @details This hook is invoked in case to a system halting error before
+ * the system is halted.
+ */
+#define CH_CFG_SYSTEM_HALT_HOOK(reason) { \
+ /* System halt code here.*/ \
+}
+
+/**
+ * @brief Trace hook.
+ * @details This hook is invoked each time a new record is written in the
+ * trace buffer.
+ */
+#define CH_CFG_TRACE_HOOK(tep) { \
+ /* Trace code here.*/ \
+}
+
+/** @} */
+
+/*===========================================================================*/
+/* Port-specific settings (override port settings defaulted in chcore.h). */
+/*===========================================================================*/
+
+#endif /* CHCONF_H */
+
+/** @} */
diff --git a/demos/various/RT-ARMCM4-MAKELIB/dummy/_delimiter.h b/demos/various/RT-ARMCM4-MAKELIB/dummy/_delimiter.h
new file mode 100644
index 000000000..98b67de9b
--- /dev/null
+++ b/demos/various/RT-ARMCM4-MAKELIB/dummy/_delimiter.h
@@ -0,0 +1 @@
+#define ___HEADER_BEGIN___
diff --git a/demos/various/RT-ARMCM4-MAKELIB/dummy/_header.h b/demos/various/RT-ARMCM4-MAKELIB/dummy/_header.h
new file mode 100644
index 000000000..b38d0d3bd
--- /dev/null
+++ b/demos/various/RT-ARMCM4-MAKELIB/dummy/_header.h
@@ -0,0 +1,25 @@
+/*
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "cmparams.h"
+
diff --git a/demos/various/RT-ARMCM4-MAKELIB/dummy/stdbool.h b/demos/various/RT-ARMCM4-MAKELIB/dummy/stdbool.h
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/demos/various/RT-ARMCM4-MAKELIB/dummy/stdbool.h
diff --git a/demos/various/RT-ARMCM4-MAKELIB/dummy/stddef.h b/demos/various/RT-ARMCM4-MAKELIB/dummy/stddef.h
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/demos/various/RT-ARMCM4-MAKELIB/dummy/stddef.h
diff --git a/demos/various/RT-ARMCM4-MAKELIB/dummy/stdint.h b/demos/various/RT-ARMCM4-MAKELIB/dummy/stdint.h
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/demos/various/RT-ARMCM4-MAKELIB/dummy/stdint.h
diff --git a/demos/various/RT-ARMCM4-MAKELIB/readme.txt b/demos/various/RT-ARMCM4-MAKELIB/readme.txt
new file mode 100644
index 000000000..f1ee8f052
--- /dev/null
+++ b/demos/various/RT-ARMCM4-MAKELIB/readme.txt
@@ -0,0 +1,15 @@
+*****************************************************************************
+** ChibiOS/RT port for ARM-Cortex-M4. **
+*****************************************************************************
+
+** TARGET **
+
+The demo builds a library containing a pre-configured RT kernel.
+
+** The Demo **
+
+** Build Procedure **
+
+** Notes **
+
+You need to customize Makefile for your target device, instructions are inside.
diff --git a/demos/various/RT-ARMCM4-USELIB/.cproject b/demos/various/RT-ARMCM4-USELIB/.cproject
new file mode 100644
index 000000000..0e1ea4fa7
--- /dev/null
+++ b/demos/various/RT-ARMCM4-USELIB/.cproject
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?>
+
+<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+ <storageModule moduleId="org.eclipse.cdt.core.settings">
+ <cconfiguration id="0.114656749">
+ <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.114656749" moduleId="org.eclipse.cdt.core.settings" name="Default">
+ <externalSettings/>
+ <extensions>
+ <extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+ </extensions>
+ </storageModule>
+ <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+ <configuration artifactName="${ProjName}" buildProperties="" description="" id="0.114656749" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
+ <folderInfo id="0.114656749." name="/" resourcePath="">
+ <toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.1182750861" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
+ <targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.1182750861.169007201" name=""/>
+ <builder autoBuildTarget="all" cleanBuildTarget="clean" enableAutoBuild="false" enableCleanBuild="true" enabledIncrementalBuild="true" id="org.eclipse.cdt.build.core.settings.default.builder.579570726" incrementalBuildTarget="all" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.libs.2143276802" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.1873650595" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1337802279" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+ </tool>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.1707090075" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.338985256" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+ </tool>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.1165165914" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.714476670" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+ </tool>
+ </toolChain>
+ </folderInfo>
+ </configuration>
+ </storageModule>
+ <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+ </cconfiguration>
+ </storageModule>
+ <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+ <project id="RT-ARMCM4-USELIB.null.1703860681" name="RT-ARMCM4-USELIB"/>
+ </storageModule>
+ <storageModule moduleId="scannerConfiguration">
+ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+ <scannerConfigBuildInfo instanceId="0.114656749">
+ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"/>
+ </scannerConfigBuildInfo>
+ </storageModule>
+ <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
+ <storageModule moduleId="refreshScope"/>
+</cproject>
diff --git a/demos/various/RT-ARMCM4-USELIB/.project b/demos/various/RT-ARMCM4-USELIB/.project
new file mode 100644
index 000000000..8b0565da7
--- /dev/null
+++ b/demos/various/RT-ARMCM4-USELIB/.project
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>RT-ARMCM4-USELIB</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+ <triggers>clean,full,incremental,</triggers>
+ <arguments>
+ <dictionary>
+ <key>?name?</key>
+ <value></value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.append_environment</key>
+ <value>true</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.autoBuildTarget</key>
+ <value>all</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.buildArguments</key>
+ <value>-j1</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.buildCommand</key>
+ <value>make</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
+ <value>clean</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.contents</key>
+ <value>org.eclipse.cdt.make.core.activeConfigSettings</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.enableAutoBuild</key>
+ <value>false</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.enableCleanBuild</key>
+ <value>true</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.enableFullBuild</key>
+ <value>true</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.fullBuildTarget</key>
+ <value>all</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.stopOnError</key>
+ <value>true</value>
+ </dictionary>
+ <dictionary>
+ <key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
+ <value>true</value>
+ </dictionary>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
+ <triggers>full,incremental,</triggers>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.cdt.core.cnature</nature>
+ <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
+ <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
+ </natures>
+ <linkedResources>
+ <link>
+ <name>os</name>
+ <type>2</type>
+ <locationURI>CHIBIOS/os</locationURI>
+ </link>
+ <link>
+ <name>test</name>
+ <type>2</type>
+ <locationURI>CHIBIOS/test</locationURI>
+ </link>
+ </linkedResources>
+</projectDescription>
diff --git a/demos/various/RT-ARMCM4-USELIB/Makefile b/demos/various/RT-ARMCM4-USELIB/Makefile
new file mode 100644
index 000000000..c8c006145
--- /dev/null
+++ b/demos/various/RT-ARMCM4-USELIB/Makefile
@@ -0,0 +1,189 @@
+##############################################################################
+# Build global options
+# NOTE: Can be overridden externally.
+#
+
+# Compiler options here.
+ifeq ($(USE_OPT),)
+ USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16
+endif
+
+# C specific options here (added to USE_OPT).
+ifeq ($(USE_COPT),)
+ USE_COPT =
+endif
+
+# C++ specific options here (added to USE_OPT).
+ifeq ($(USE_CPPOPT),)
+ USE_CPPOPT = -fno-rtti
+endif
+
+# Enable this if you want the linker to remove unused code and data.
+ifeq ($(USE_LINK_GC),)
+ USE_LINK_GC = yes
+endif
+
+# Linker extra options here.
+ifeq ($(USE_LDOPT),)
+ USE_LDOPT =
+endif
+
+# Enable this if you want link time optimizations (LTO).
+ifeq ($(USE_LTO),)
+ USE_LTO = yes
+endif
+
+# Enable this if you want to see the full log while compiling.
+ifeq ($(USE_VERBOSE_COMPILE),)
+ USE_VERBOSE_COMPILE = no
+endif
+
+# If enabled, this option makes the build process faster by not compiling
+# modules not used in the current configuration.
+ifeq ($(USE_SMART_BUILD),)
+ USE_SMART_BUILD = yes
+endif
+
+#
+# Build global options
+##############################################################################
+
+##############################################################################
+# Architecture or project specific options
+#
+
+# Stack size to be allocated to the Cortex-M process stack. This stack is
+# the stack used by the main() thread.
+ifeq ($(USE_PROCESS_STACKSIZE),)
+ USE_PROCESS_STACKSIZE = 0x400
+endif
+
+# Stack size to the allocated to the Cortex-M main/exceptions stack. This
+# stack is used for processing interrupts and exceptions.
+ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
+ USE_EXCEPTIONS_STACKSIZE = 0x400
+endif
+
+# Enables the use of FPU (no, softfp, hard).
+ifeq ($(USE_FPU),)
+ USE_FPU = no
+endif
+
+# FPU-related options.
+ifeq ($(USE_FPU_OPT),)
+ USE_FPU_OPT = -mfloat-abi=$(USE_FPU) -mfpu=fpv4-sp-d16
+endif
+
+#
+# Architecture or project specific options
+##############################################################################
+
+##############################################################################
+# Project, target, sources and paths
+#
+
+# Define project name here
+PROJECT = ch
+
+# Target settings.
+MCU = cortex-m4
+
+# Imported source files and paths.
+CHIBIOS := ../../..
+CONFDIR := ./cfg
+BUILDDIR := ./build
+DEPDIR := ./.dep
+
+# Licensing files.
+include $(CHIBIOS)/os/license/license.mk
+# Startup files.
+include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk
+# HAL-OSAL files (optional).
+#include $(CHIBIOS)/os/hal/hal.mk
+#include $(CHIBIOS)/os/hal/ports/STM32/STM32F4xx/platform.mk
+#include $(CHIBIOS)/os/hal/boards/ST_STM32F4_DISCOVERY/board.mk
+#include $(CHIBIOS)/os/hal/osal/rt-nil/osal.mk
+# RTOS files (optional).
+#include $(CHIBIOS)/os/rt/rt.mk
+#include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
+# Auto-build files in ./source recursively.
+include $(CHIBIOS)/tools/mk/autobuild.mk
+# Other files (optional).
+#include $(CHIBIOS)/test/lib/test.mk
+#include $(CHIBIOS)/test/rt/rt_test.mk
+#include $(CHIBIOS)/test/oslib/oslib_test.mk
+
+# Define linker script file here
+LDSCRIPT= $(STARTUPLD)/STM32F407xG.ld
+
+# C sources that can be compiled in ARM or THUMB mode depending on the global
+# setting.
+CSRC = $(ALLCSRC) \
+ $(TESTSRC) \
+ main.c
+
+# C++ sources that can be compiled in ARM or THUMB mode depending on the global
+# setting.
+CPPSRC = $(ALLCPPSRC)
+
+# List ASM source files here.
+ASMSRC = $(ALLASMSRC)
+
+# List ASM with preprocessor source files here.
+ASMXSRC = $(ALLXASMSRC)
+
+# Inclusion directories.
+INCDIR = $(CONFDIR) $(ALLINC) $(TESTINC)
+
+# Define C warning options here.
+CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes
+
+# Define C++ warning options here.
+CPPWARN = -Wall -Wextra -Wundef
+
+#
+# Project, target, sources and paths
+##############################################################################
+
+##############################################################################
+# Start of user section
+#
+
+# List all user C define here, like -D_DEBUG=1
+UDEFS = -DSTM32F407xx
+
+# Define ASM defines here
+UADEFS = -DSTM32F407xx
+
+# List all user directories here
+UINCDIR = ./rt
+
+# List the user directory to look for the libraries here
+ULIBDIR = ./rt
+
+# List all user libraries here
+ULIBS = -lch
+
+#
+# End of user section
+##############################################################################
+
+##############################################################################
+# Common rules
+#
+
+RULESPATH = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk
+include $(RULESPATH)/arm-none-eabi.mk
+include $(RULESPATH)/rules.mk
+
+#
+# Common rules
+##############################################################################
+
+##############################################################################
+# Custom rules
+#
+
+#
+# Custom rules
+##############################################################################
diff --git a/demos/various/RT-ARMCM4-USELIB/debug/RT-ARMCM4-USELIB (OpenOCD, Flash and Run).launch b/demos/various/RT-ARMCM4-USELIB/debug/RT-ARMCM4-USELIB (OpenOCD, Flash and Run).launch
new file mode 100644
index 000000000..81ac45316
--- /dev/null
+++ b/demos/various/RT-ARMCM4-USELIB/debug/RT-ARMCM4-USELIB (OpenOCD, Flash and Run).launch
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.cdt.debug.gdbjtag.launchConfigurationType">
+<stringAttribute key="bad_container_name" value="\RT-ARMCM4-USELIB\debug"/>
+<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.delay" value="1"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doHalt" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.doReset" value="true"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageFileName" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageOffset" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.initCommands" value="set remotetimeout 20&#13;&#10;monitor reset init&#13;&#10;monitor sleep 50&#13;&#10;"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="Generic TCP/IP"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="true"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
+<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="3333"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.runCommands" value=""/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value=""/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForImage" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForSymbols" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForImage" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForSymbols" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useRemoteTarget" value="true"/>
+<stringAttribute key="org.eclipse.cdt.debug.mi.core.DEBUG_NAME" value="arm-none-eabi-gdb"/>
+<stringAttribute key="org.eclipse.cdt.debug.mi.core.commandFactory" value="Standard"/>
+<stringAttribute key="org.eclipse.cdt.debug.mi.core.protocol" value="mi"/>
+<booleanAttribute key="org.eclipse.cdt.debug.mi.core.verboseMode" value="false"/>
+<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="arm-none-eabi-gdb"/>
+<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
+<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
+<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
+<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList/&gt;"/>
+<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;globalVariableList/&gt;&#13;&#10;"/>
+<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList/&gt;&#13;&#10;"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="RT-ARMCM4-USELIB"/>
+<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="true"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="0.114656749"/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/RT-ARMCM4-USELIB"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="4"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
+<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
+</listAttribute>
+</launchConfiguration>
diff --git a/demos/various/RT-ARMCM4-USELIB/main.c b/demos/various/RT-ARMCM4-USELIB/main.c
new file mode 100644
index 000000000..976da585c
--- /dev/null
+++ b/demos/various/RT-ARMCM4-USELIB/main.c
@@ -0,0 +1,93 @@
+/*
+ ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include "ch.h"
+
+#if !defined(SYSTEM_CLOCK)
+#define SYSTEM_CLOCK 8000000U
+#endif
+
+/*
+ * @brief System Timer handler.
+ */
+CH_IRQ_HANDLER(SysTick_Handler) {
+
+ CH_IRQ_PROLOGUE();
+
+ chSysLockFromISR();
+ chSysTimerHandlerI();
+ chSysUnlockFromISR();
+
+ CH_IRQ_EPILOGUE();
+}
+
+static uint32_t seconds_counter;
+static uint32_t minutes_counter;
+
+/*
+ * Seconds counter thread.
+ */
+static THD_WORKING_AREA(waThread1, 128);
+static THD_FUNCTION(Thread1, arg) {
+
+ (void)arg;
+
+ chRegSetThreadName("counter");
+
+ while (true) {
+ chThdSleepMilliseconds(1000);
+ seconds_counter++;
+ }
+}
+
+/*
+ * Application entry point.
+ */
+int main(void) {
+
+ /*
+ * Hardware initialization, in this simple demo just the systick timer is
+ * initialized.
+ */
+ SysTick->LOAD = SYSTEM_CLOCK / CH_CFG_ST_FREQUENCY - (systime_t)1;
+ SysTick->VAL = (uint32_t)0;
+ SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk |
+ SysTick_CTRL_TICKINT_Msk;
+
+ /* IRQ enabled.*/
+ NVIC_SetPriority(SysTick_IRQn, 8);
+
+ /*
+ * System initializations.
+ * - Kernel initialization, the main() function becomes a thread and the
+ * RTOS is active.
+ */
+ chSysInit();
+
+ /*
+ * Creates the example thread.
+ */
+ (void) chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
+
+ /*
+ * Normal main() thread activity, in this demo it does nothing except
+ * increasing the minutes counter.
+ */
+ while (true) {
+ chThdSleepSeconds(60);
+ minutes_counter++;
+ }
+}
diff --git a/demos/various/RT-ARMCM4-USELIB/readme.txt b/demos/various/RT-ARMCM4-USELIB/readme.txt
new file mode 100644
index 000000000..b7ae04dd8
--- /dev/null
+++ b/demos/various/RT-ARMCM4-USELIB/readme.txt
@@ -0,0 +1,18 @@
+*****************************************************************************
+** ChibiOS/RT port for ARM-Cortex-M4. **
+*****************************************************************************
+
+** TARGET **
+
+The demo targets a generic ARM Cortex-M4 device without HAL support. RT is
+included as a library and an header generated by RT-ARMCM4-MAKELIB.
+
+** The Demo **
+
+** Build Procedure **
+
+** Notes **
+
+The files ch.ld and cmparams.h must be customized for your device. You also
+need to provide the CMSIS compliant device header from your vendor, it this
+demo an ST header is used.
diff --git a/demos/various/RT-ARMCM4-USELIB/rt/ch.h b/demos/various/RT-ARMCM4-USELIB/rt/ch.h
new file mode 100644
index 000000000..d258b5578
--- /dev/null
+++ b/demos/various/RT-ARMCM4-USELIB/rt/ch.h
@@ -0,0 +1,1632 @@
+/*
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "cmparams.h"
+
+#define CH_H
+#define _CHIBIOS_RT_
+#define CH_KERNEL_STABLE 1
+#define CH_KERNEL_VERSION "6.0.2"
+#define CH_KERNEL_MAJOR 6
+#define CH_KERNEL_MINOR 0
+#define CH_KERNEL_PATCH 2
+#define FALSE 0
+#define TRUE 1
+#define CHCONF_H
+#define _CHIBIOS_RT_CONF_
+#define _CHIBIOS_RT_CONF_VER_6_0_
+#define CH_CFG_ST_RESOLUTION 32
+#define CH_CFG_ST_FREQUENCY 1000
+#define CH_CFG_INTERVALS_SIZE 32
+#define CH_CFG_TIME_TYPES_SIZE 32
+#define CH_CFG_ST_TIMEDELTA 0
+#define CH_CFG_TIME_QUANTUM 0
+#define CH_CFG_MEMCORE_SIZE 0
+#define CH_CFG_NO_IDLE_THREAD FALSE
+#define CH_CFG_OPTIMIZE_SPEED TRUE
+#define CH_CFG_USE_TM TRUE
+#define CH_CFG_USE_REGISTRY TRUE
+#define CH_CFG_USE_WAITEXIT TRUE
+#define CH_CFG_USE_SEMAPHORES TRUE
+#define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE
+#define CH_CFG_USE_MUTEXES TRUE
+#define CH_CFG_USE_MUTEXES_RECURSIVE FALSE
+#define CH_CFG_USE_CONDVARS TRUE
+#define CH_CFG_USE_CONDVARS_TIMEOUT TRUE
+#define CH_CFG_USE_EVENTS TRUE
+#define CH_CFG_USE_EVENTS_TIMEOUT TRUE
+#define CH_CFG_USE_MESSAGES TRUE
+#define CH_CFG_USE_MESSAGES_PRIORITY FALSE
+#define CH_CFG_USE_MAILBOXES TRUE
+#define CH_CFG_USE_MEMCORE TRUE
+#define CH_CFG_USE_HEAP TRUE
+#define CH_CFG_USE_MEMPOOLS TRUE
+#define CH_CFG_USE_OBJ_FIFOS TRUE
+#define CH_CFG_USE_PIPES TRUE
+#define CH_CFG_USE_DYNAMIC TRUE
+#define CH_CFG_USE_FACTORY TRUE
+#define CH_CFG_FACTORY_MAX_NAMES_LENGTH 8
+#define CH_CFG_FACTORY_OBJECTS_REGISTRY TRUE
+#define CH_CFG_FACTORY_GENERIC_BUFFERS TRUE
+#define CH_CFG_FACTORY_SEMAPHORES TRUE
+#define CH_CFG_FACTORY_MAILBOXES TRUE
+#define CH_CFG_FACTORY_OBJ_FIFOS TRUE
+#define CH_CFG_FACTORY_PIPES TRUE
+#define CH_DBG_STATISTICS FALSE
+#define CH_DBG_SYSTEM_STATE_CHECK FALSE
+#define CH_DBG_ENABLE_CHECKS FALSE
+#define CH_DBG_ENABLE_ASSERTS FALSE
+#define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED
+#define CH_DBG_TRACE_BUFFER_SIZE 128
+#define CH_DBG_ENABLE_STACK_CHECK FALSE
+#define CH_DBG_FILL_THREADS FALSE
+#define CH_DBG_THREADS_PROFILING FALSE
+#define CH_CFG_SYSTEM_EXTRA_FIELDS
+#define CH_CFG_SYSTEM_INIT_HOOK() { }
+#define CH_CFG_THREAD_EXTRA_FIELDS
+#define CH_CFG_THREAD_INIT_HOOK(tp) { }
+#define CH_CFG_THREAD_EXIT_HOOK(tp) { }
+#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp,otp) { }
+#define CH_CFG_IRQ_PROLOGUE_HOOK() { }
+#define CH_CFG_IRQ_EPILOGUE_HOOK() { }
+#define CH_CFG_IDLE_ENTER_HOOK() { }
+#define CH_CFG_IDLE_LEAVE_HOOK() { }
+#define CH_CFG_IDLE_LOOP_HOOK() { }
+#define CH_CFG_SYSTEM_TICK_HOOK() { }
+#define CH_CFG_SYSTEM_HALT_HOOK(reason) { }
+#define CH_CFG_TRACE_HOOK(tep) { }
+#define CHCHECKS_H
+#define CHLICENSE_H
+#define CH_FEATURES_BASIC 0
+#define CH_FEATURES_INTERMEDIATE 1
+#define CH_FEATURES_FULL 2
+#define CH_DEPLOY_UNLIMITED -1
+#define CH_DEPLOY_NONE 0
+#define CH_LICENSE_GPL 0
+#define CH_LICENSE_GPL_EXCEPTION 1
+#define CH_LICENSE_COMMERCIAL_FREE 2
+#define CH_LICENSE_COMMERCIAL_DEV_1000 3
+#define CH_LICENSE_COMMERCIAL_DEV_5000 4
+#define CH_LICENSE_COMMERCIAL_FULL 5
+#define CH_LICENSE_COMMERCIAL_RUNTIME 6
+#define CH_LICENSE_PARTNER 7
+#define CHCUSTOMER_H
+#define CH_CUSTOMER_ID_STRING "Santa, North Pole"
+#define CH_CUSTOMER_ID_CODE "xxxx-yyyy"
+#define CH_LICENSE CH_LICENSE_GPL
+#define CH_CUSTOMER_LIC_RT TRUE
+#define CH_CUSTOMER_LIC_NIL TRUE
+#define CH_CUSTOMER_LIC_OSLIB TRUE
+#define CH_CUSTOMER_LIC_EX TRUE
+#define CH_CUSTOMER_LIC_PORT_CM0 TRUE
+#define CH_CUSTOMER_LIC_PORT_CM3 TRUE
+#define CH_CUSTOMER_LIC_PORT_CM4 TRUE
+#define CH_CUSTOMER_LIC_PORT_CM7 TRUE
+#define CH_CUSTOMER_LIC_PORT_ARM79 TRUE
+#define CH_CUSTOMER_LIC_PORT_E200Z0 TRUE
+#define CH_CUSTOMER_LIC_PORT_E200Z2 TRUE
+#define CH_CUSTOMER_LIC_PORT_E200Z3 TRUE
+#define CH_CUSTOMER_LIC_PORT_E200Z4 TRUE
+#define CH_LICENSE_TYPE_STRING "GNU General Public License 3 (GPL3)"
+#define CH_LICENSE_ID_STRING "N/A"
+#define CH_LICENSE_ID_CODE "N/A"
+#define CH_LICENSE_MODIFIABLE_CODE TRUE
+#define CH_LICENSE_FEATURES CH_FEATURES_FULL
+#define CH_LICENSE_MAX_DEPLOY CH_DEPLOY_UNLIMITED
+#define CHRESTRICTIONS_H
+ void chSysHalt(const char *reason);
+#define CHTYPES_H
+typedef uint32_t rtcnt_t;
+typedef uint64_t rttime_t;
+typedef uint32_t syssts_t;
+typedef uint8_t tmode_t;
+typedef uint8_t tstate_t;
+typedef uint8_t trefs_t;
+typedef uint8_t tslices_t;
+typedef uint32_t tprio_t;
+typedef int32_t msg_t;
+typedef int32_t eventid_t;
+typedef uint32_t eventmask_t;
+typedef uint32_t eventflags_t;
+typedef int32_t cnt_t;
+typedef uint32_t ucnt_t;
+#define ROMCONST const
+#define NOINLINE __attribute__((noinline))
+#define PORT_THD_FUNCTION(tname,arg) void tname(void *arg)
+#define PACKED_VAR __attribute__((packed))
+#define ALIGNED_VAR(n) __attribute__((aligned(n)))
+#define SIZEOF_PTR 4
+#define REVERSE_ORDER 1
+#define CHSYSTYPES_H
+typedef struct ch_thread thread_t;
+typedef thread_t * thread_reference_t;
+typedef struct ch_threads_list threads_list_t;
+typedef struct ch_threads_queue threads_queue_t;
+typedef struct ch_ready_list ready_list_t;
+typedef void (*vtfunc_t)(void *p);
+typedef struct ch_virtual_timer virtual_timer_t;
+typedef struct ch_virtual_timers_list virtual_timers_list_t;
+typedef struct ch_system_debug system_debug_t;
+typedef struct ch_system ch_system_t;
+#define __CH_STRINGIFY(a) #a
+#define CHDEBUG_H
+#define CH_DBG_STACK_FILL_VALUE 0x55
+#define _dbg_enter_lock()
+#define _dbg_leave_lock()
+#define _dbg_check_disable()
+#define _dbg_check_suspend()
+#define _dbg_check_enable()
+#define _dbg_check_lock()
+#define _dbg_check_unlock()
+#define _dbg_check_lock_from_isr()
+#define _dbg_check_unlock_from_isr()
+#define _dbg_check_enter_isr()
+#define _dbg_check_leave_isr()
+#define chDbgCheckClassI()
+#define chDbgCheckClassS()
+#define chDbgCheck(c) do { if (CH_DBG_ENABLE_CHECKS != FALSE) { if (!(c)) { chSysHalt(__func__); } } } while (false)
+#define chDbgAssert(c,r) do { if (CH_DBG_ENABLE_ASSERTS != FALSE) { if (!(c)) { chSysHalt(__func__); } } } while (false)
+#define CHTIME_H
+#define TIME_IMMEDIATE ((sysinterval_t)0)
+#define TIME_INFINITE ((sysinterval_t)-1)
+#define TIME_MAX_INTERVAL ((sysinterval_t)-2)
+#define TIME_MAX_SYSTIME ((systime_t)-1)
+typedef uint32_t systime_t;
+typedef uint32_t sysinterval_t;
+typedef uint32_t time_secs_t;
+typedef uint32_t time_msecs_t;
+typedef uint32_t time_usecs_t;
+typedef uint64_t time_conv_t;
+#define TIME_S2I(secs) ((sysinterval_t)((time_conv_t)(secs) * (time_conv_t)CH_CFG_ST_FREQUENCY))
+#define TIME_MS2I(msecs) ((sysinterval_t)((((time_conv_t)(msecs) * (time_conv_t)CH_CFG_ST_FREQUENCY) + (time_conv_t)999) / (time_conv_t)1000))
+#define TIME_US2I(usecs) ((sysinterval_t)((((time_conv_t)(usecs) * (time_conv_t)CH_CFG_ST_FREQUENCY) + (time_conv_t)999999) / (time_conv_t)1000000))
+#define TIME_I2S(interval) (time_secs_t)(((time_conv_t)(interval) + (time_conv_t)CH_CFG_ST_FREQUENCY - (time_conv_t)1) / (time_conv_t)CH_CFG_ST_FREQUENCY)
+#define TIME_I2MS(interval) (time_msecs_t)((((time_conv_t)(interval) * (time_conv_t)1000) + (time_conv_t)CH_CFG_ST_FREQUENCY - (time_conv_t)1) / (time_conv_t)CH_CFG_ST_FREQUENCY)
+#define TIME_I2US(interval) (time_msecs_t)((((time_conv_t)(interval) * (time_conv_t)1000000) + (time_conv_t)CH_CFG_ST_FREQUENCY - (time_conv_t)1) / (time_conv_t)CH_CFG_ST_FREQUENCY)
+static inline sysinterval_t chTimeS2I(time_secs_t secs) {
+ time_conv_t ticks;
+ ticks = (time_conv_t)secs * (time_conv_t)CH_CFG_ST_FREQUENCY;
+ chDbgAssert(ticks <= (time_conv_t)TIME_MAX_INTERVAL,
+ "conversion overflow");
+ return (sysinterval_t)ticks;
+}
+static inline sysinterval_t chTimeMS2I(time_msecs_t msec) {
+ time_conv_t ticks;
+ ticks = (((time_conv_t)msec * (time_conv_t)CH_CFG_ST_FREQUENCY) +
+ (time_conv_t)999) / (time_conv_t)1000;
+ chDbgAssert(ticks <= (time_conv_t)TIME_MAX_INTERVAL,
+ "conversion overflow");
+ return (sysinterval_t)ticks;
+}
+static inline sysinterval_t chTimeUS2I(time_usecs_t usec) {
+ time_conv_t ticks;
+ ticks = (((time_conv_t)usec * (time_conv_t)CH_CFG_ST_FREQUENCY) +
+ (time_conv_t)999999) / (time_conv_t)1000000;
+ chDbgAssert(ticks <= (time_conv_t)TIME_MAX_INTERVAL,
+ "conversion overflow");
+ return (sysinterval_t)ticks;
+}
+static inline time_secs_t chTimeI2S(sysinterval_t interval) {
+ time_conv_t secs;
+ secs = ((time_conv_t)interval +
+ (time_conv_t)CH_CFG_ST_FREQUENCY -
+ (time_conv_t)1) / (time_conv_t)CH_CFG_ST_FREQUENCY;
+ chDbgAssert(secs < (time_conv_t)((time_secs_t)-1),
+ "conversion overflow");
+ return (time_secs_t)secs;
+}
+static inline time_msecs_t chTimeI2MS(sysinterval_t interval) {
+ time_conv_t msecs;
+ msecs = (((time_conv_t)interval * (time_conv_t)1000) +
+ (time_conv_t)CH_CFG_ST_FREQUENCY - (time_conv_t)1) /
+ (time_conv_t)CH_CFG_ST_FREQUENCY;
+ chDbgAssert(msecs < (time_conv_t)((time_msecs_t)-1),
+ "conversion overflow");
+ return (time_msecs_t)msecs;
+}
+static inline time_usecs_t chTimeI2US(sysinterval_t interval) {
+ time_conv_t usecs;
+ usecs = (((time_conv_t)interval * (time_conv_t)1000000) +
+ (time_conv_t)CH_CFG_ST_FREQUENCY - (time_conv_t)1) /
+ (time_conv_t)CH_CFG_ST_FREQUENCY;
+ chDbgAssert(usecs <= (time_conv_t)((time_usecs_t)-1),
+ "conversion overflow");
+ return (time_usecs_t)usecs;
+}
+static inline systime_t chTimeAddX(systime_t systime,
+ sysinterval_t interval) {
+ return systime + (systime_t)interval;
+}
+static inline sysinterval_t chTimeDiffX(systime_t start, systime_t end) {
+ return (sysinterval_t)((systime_t)(end - start));
+}
+static inline bool chTimeIsInRangeX(systime_t time,
+ systime_t start,
+ systime_t end) {
+ return (bool)((time - start) < (end - start));
+}
+#define CHALIGN_H
+#define MEM_ALIGN_MASK(a) ((size_t)(a) - 1U)
+#define MEM_ALIGN_PREV(p,a) ((size_t)(p) & ~MEM_ALIGN_MASK(a))
+#define MEM_ALIGN_NEXT(p,a) MEM_ALIGN_PREV((size_t)(p) + MEM_ALIGN_MASK(a), (a))
+#define MEM_IS_ALIGNED(p,a) (((size_t)(p) & MEM_ALIGN_MASK(a)) == 0U)
+#define MEM_IS_VALID_ALIGNMENT(a) (((size_t)(a) != 0U) && (((size_t)(a) & ((size_t)(a) - 1U)) == 0U))
+#define CHCORE_H
+#define PORT_ARCHITECTURE_ARM
+#define PORT_COMPILER_NAME "GCC " __VERSION__
+#define PORT_USE_ALT_TIMER FALSE
+typedef void *regarm_t;
+typedef uint64_t stkalign_t;
+struct port_context {
+ struct port_intctx *sp;
+};
+#define CORTEX_PRIORITY_LEVELS (1U << CORTEX_PRIORITY_BITS)
+#define CORTEX_MINIMUM_PRIORITY (CORTEX_PRIORITY_LEVELS - 1)
+#define CORTEX_MAXIMUM_PRIORITY 0U
+#define CORTEX_PRIO_MASK(n) ((n) << (8U - (unsigned)CORTEX_PRIORITY_BITS))
+#define PORT_IRQ_IS_VALID_PRIORITY(n) (((n) >= 0U) && ((n) < CORTEX_PRIORITY_LEVELS))
+#define PORT_IRQ_IS_VALID_KERNEL_PRIORITY(n) (((n) >= CORTEX_MAX_KERNEL_PRIORITY) && ((n) < CORTEX_PRIORITY_LEVELS))
+#define MPU_H
+#define MPU_TYPE_SEPARATED (1U << 0U)
+#define MPU_TYPE_DREGION(n) (((n) >> 8U) & 255U)
+#define MPU_TYPE_IREGION(n) (((n) >> 16U) & 255U)
+#define MPU_CTRL_ENABLE (1U << 0U)
+#define MPU_CTRL_HFNMIENA (1U << 1U)
+#define MPU_CTRL_PRIVDEFENA (1U << 2U)
+#define MPU_RNR_REGION_MASK (255U << 0U)
+#define MPU_RNR_REGION(n) ((n) << 0U)
+#define MPU_RBAR_REGION_MASK (15U << 0U)
+#define MPU_RBAR_REGION(n) ((n) << 0U)
+#define MPU_RBAR_VALID (1U << 4U)
+#define MPU_RBAR_ADDR_MASK 0xFFFFFFE0U
+#define MPU_RBAR_ADDR(n) ((n) << 5U)
+#define MPU_RASR_ENABLE (1U << 0U)
+#define MPU_RASR_SIZE_MASK (31U << 1U)
+#define MPU_RASR_SIZE(n) ((n) << 1U)
+#define MPU_RASR_SIZE_32 MPU_RASR_SIZE(4U)
+#define MPU_RASR_SIZE_64 MPU_RASR_SIZE(5U)
+#define MPU_RASR_SIZE_128 MPU_RASR_SIZE(6U)
+#define MPU_RASR_SIZE_256 MPU_RASR_SIZE(7U)
+#define MPU_RASR_SIZE_512 MPU_RASR_SIZE(8U)
+#define MPU_RASR_SIZE_1K MPU_RASR_SIZE(9U)
+#define MPU_RASR_SIZE_2K MPU_RASR_SIZE(10U)
+#define MPU_RASR_SIZE_4K MPU_RASR_SIZE(11U)
+#define MPU_RASR_SIZE_8K MPU_RASR_SIZE(12U)
+#define MPU_RASR_SIZE_16K MPU_RASR_SIZE(13U)
+#define MPU_RASR_SIZE_32K MPU_RASR_SIZE(14U)
+#define MPU_RASR_SIZE_64K MPU_RASR_SIZE(15U)
+#define MPU_RASR_SIZE_128K MPU_RASR_SIZE(16U)
+#define MPU_RASR_SIZE_256K MPU_RASR_SIZE(17U)
+#define MPU_RASR_SIZE_512K MPU_RASR_SIZE(18U)
+#define MPU_RASR_SIZE_1M MPU_RASR_SIZE(19U)
+#define MPU_RASR_SIZE_2M MPU_RASR_SIZE(20U)
+#define MPU_RASR_SIZE_4M MPU_RASR_SIZE(21U)
+#define MPU_RASR_SIZE_8M MPU_RASR_SIZE(22U)
+#define MPU_RASR_SIZE_16M MPU_RASR_SIZE(23U)
+#define MPU_RASR_SIZE_32M MPU_RASR_SIZE(24U)
+#define MPU_RASR_SIZE_64M MPU_RASR_SIZE(25U)
+#define MPU_RASR_SIZE_128M MPU_RASR_SIZE(26U)
+#define MPU_RASR_SIZE_256M MPU_RASR_SIZE(27U)
+#define MPU_RASR_SIZE_512M MPU_RASR_SIZE(28U)
+#define MPU_RASR_SIZE_1G MPU_RASR_SIZE(29U)
+#define MPU_RASR_SIZE_2G MPU_RASR_SIZE(30U)
+#define MPU_RASR_SIZE_4G MPU_RASR_SIZE(31U)
+#define MPU_RASR_SRD_MASK (255U << 8U)
+#define MPU_RASR_SRD(n) ((n) << 8U)
+#define MPU_RASR_SRD_ALL (0U << 8U)
+#define MPU_RASR_SRD_DISABLE_SUB0 (1U << 8U)
+#define MPU_RASR_SRD_DISABLE_SUB1 (2U << 8U)
+#define MPU_RASR_SRD_DISABLE_SUB2 (4U << 8U)
+#define MPU_RASR_SRD_DISABLE_SUB3 (8U << 8U)
+#define MPU_RASR_SRD_DISABLE_SUB4 (16U << 8U)
+#define MPU_RASR_SRD_DISABLE_SUB5 (32U << 8U)
+#define MPU_RASR_SRD_DISABLE_SUB6 (64U << 8U)
+#define MPU_RASR_SRD_DISABLE_SUB7 (128U << 8U)
+#define MPU_RASR_ATTR_B (1U << 16U)
+#define MPU_RASR_ATTR_C (1U << 17U)
+#define MPU_RASR_ATTR_S (1U << 18U)
+#define MPU_RASR_ATTR_TEX_MASK (7U << 19U)
+#define MPU_RASR_ATTR_TEX(n) ((n) << 19U)
+#define MPU_RASR_ATTR_AP_MASK (7U << 24U)
+#define MPU_RASR_ATTR_AP(n) ((n) << 24U)
+#define MPU_RASR_ATTR_AP_NA_NA (0U << 24U)
+#define MPU_RASR_ATTR_AP_RW_NA (1U << 24U)
+#define MPU_RASR_ATTR_AP_RW_RO (2U << 24U)
+#define MPU_RASR_ATTR_AP_RW_RW (3U << 24U)
+#define MPU_RASR_ATTR_AP_RO_NA (5U << 24U)
+#define MPU_RASR_ATTR_AP_RO_RO (6U << 24U)
+#define MPU_RASR_ATTR_XN (1U << 28U)
+#define MPU_RASR_ATTR_STRONGLY_ORDERED (MPU_RASR_ATTR_TEX(0))
+#define MPU_RASR_ATTR_SHARED_DEVICE (MPU_RASR_ATTR_TEX(0) | MPU_RASR_ATTR_B)
+#define MPU_RASR_ATTR_CACHEABLE_WT_NWA (MPU_RASR_ATTR_TEX(0) | MPU_RASR_ATTR_C)
+#define MPU_RASR_ATTR_CACHEABLE_WB_NWA (MPU_RASR_ATTR_TEX(0) | MPU_RASR_ATTR_B | MPU_RASR_ATTR_C)
+#define MPU_RASR_ATTR_NON_CACHEABLE (MPU_RASR_ATTR_TEX(1))
+#define MPU_RASR_ATTR_CACHEABLE_WB_WA (MPU_RASR_ATTR_TEX(1) | MPU_RASR_ATTR_B | MPU_RASR_ATTR_C)
+#define MPU_RASR_ATTR_NON_SHARED_DEVICE (MPU_RASR_ATTR_TEX(2))
+#define MPU_REGION_0 0U
+#define MPU_REGION_1 1U
+#define MPU_REGION_2 2U
+#define MPU_REGION_3 3U
+#define MPU_REGION_4 4U
+#define MPU_REGION_5 5U
+#define MPU_REGION_6 6U
+#define MPU_REGION_7 7U
+#define mpuEnable(ctrl) { MPU->CTRL = ((uint32_t)ctrl) | MPU_CTRL_ENABLE; SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; }
+#define mpuDisable() { SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; MPU->CTRL = 0; }
+#define mpuConfigureRegion(region,addr,attribs) { MPU->RNR = ((uint32_t)region); MPU->RBAR = ((uint32_t)addr); MPU->RASR = ((uint32_t)attribs); }
+#define mpuSetRegionAddress(region,addr) { MPU->RNR = ((uint32_t)region); MPU->RBAR = ((uint32_t)addr); }
+#define CHCORE_V7M_H
+#define PORT_SUPPORTS_RT TRUE
+#define PORT_NATURAL_ALIGN sizeof (void *)
+#define PORT_STACK_ALIGN sizeof (stkalign_t)
+#define PORT_WORKING_AREA_ALIGN (PORT_ENABLE_GUARD_PAGES == TRUE ? 32U : PORT_STACK_ALIGN)
+#define CORTEX_BASEPRI_DISABLED 0U
+#define PORT_ENABLE_GUARD_PAGES FALSE
+#define PORT_USE_MPU_REGION MPU_REGION_7
+#define PORT_IDLE_THREAD_STACK_SIZE 16
+#define PORT_INT_REQUIRED_STACK 64
+#define CORTEX_ENABLE_WFI_IDLE FALSE
+#define CORTEX_SIMPLIFIED_PRIORITY FALSE
+#define CORTEX_PRIORITY_SVCALL (CORTEX_MAXIMUM_PRIORITY + 1U)
+#define CORTEX_PRIGROUP_INIT (7 - CORTEX_PRIORITY_BITS)
+ #define PORT_GUARD_PAGE_SIZE 0U
+ #define PORT_ARCHITECTURE_ARM_v7ME
+ #define PORT_ARCHITECTURE_NAME "ARMv7E-M"
+ #define PORT_CORE_VARIANT_NAME "Cortex-M4"
+#define PORT_INFO "Advanced kernel mode"
+#define CORTEX_MAX_KERNEL_PRIORITY (CORTEX_PRIORITY_SVCALL + 1U)
+#define CORTEX_BASEPRI_KERNEL CORTEX_PRIO_MASK(CORTEX_MAX_KERNEL_PRIORITY)
+#define CORTEX_PRIORITY_PENDSV CORTEX_MAX_KERNEL_PRIORITY
+struct port_extctx {
+ regarm_t r0;
+ regarm_t r1;
+ regarm_t r2;
+ regarm_t r3;
+ regarm_t r12;
+ regarm_t lr_thd;
+ regarm_t pc;
+ regarm_t xpsr;
+};
+struct port_intctx {
+ regarm_t r4;
+ regarm_t r5;
+ regarm_t r6;
+ regarm_t r7;
+ regarm_t r8;
+ regarm_t r9;
+ regarm_t r10;
+ regarm_t r11;
+ regarm_t lr;
+};
+#define PORT_SETUP_CONTEXT(tp,wbase,wtop,pf,arg) { (tp)->ctx.sp = (struct port_intctx *)((uint8_t *)(wtop) - sizeof (struct port_intctx)); (tp)->ctx.sp->r4 = (regarm_t)(pf); (tp)->ctx.sp->r5 = (regarm_t)(arg); (tp)->ctx.sp->lr = (regarm_t)_port_thread_start; }
+#define PORT_WA_SIZE(n) ((size_t)PORT_GUARD_PAGE_SIZE + sizeof (struct port_intctx) + sizeof (struct port_extctx) + (size_t)(n) + (size_t)PORT_INT_REQUIRED_STACK)
+#define PORT_WORKING_AREA(s,n) stkalign_t s[THD_WORKING_AREA_SIZE(n) / sizeof (stkalign_t)]
+#define PORT_IRQ_PROLOGUE()
+#define PORT_IRQ_EPILOGUE() _port_irq_epilogue()
+#define PORT_IRQ_HANDLER(id) void id(void)
+#define PORT_FAST_IRQ_HANDLER(id) void id(void)
+#define port_switch(ntp,otp) _port_switch(ntp, otp)
+ void _port_irq_epilogue(void);
+ void _port_switch(thread_t *ntp, thread_t *otp);
+ void _port_thread_start(void);
+ void _port_switch_from_isr(void);
+ void _port_exit_from_isr(void);
+static inline void port_init(void) {
+ NVIC_SetPriorityGrouping(CORTEX_PRIGROUP_INIT);
+ CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
+ DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
+ NVIC_SetPriority(SVCall_IRQn, CORTEX_PRIORITY_SVCALL);
+ NVIC_SetPriority(PendSV_IRQn, CORTEX_PRIORITY_PENDSV);
+}
+static inline syssts_t port_get_irq_status(void) {
+ syssts_t sts;
+ sts = (syssts_t)__get_BASEPRI();
+ return sts;
+}
+static inline bool port_irq_enabled(syssts_t sts) {
+ return sts == (syssts_t)CORTEX_BASEPRI_DISABLED;
+}
+static inline bool port_is_isr_context(void) {
+ return (bool)((__get_IPSR() & 0x1FFU) != 0U);
+}
+static inline void port_lock(void) {
+ __set_BASEPRI(CORTEX_BASEPRI_KERNEL);
+}
+static inline void port_unlock(void) {
+ __set_BASEPRI(CORTEX_BASEPRI_DISABLED);
+}
+static inline void port_lock_from_isr(void) {
+ port_lock();
+}
+static inline void port_unlock_from_isr(void) {
+ port_unlock();
+}
+static inline void port_disable(void) {
+ __disable_irq();
+}
+static inline void port_suspend(void) {
+ __set_BASEPRI(CORTEX_BASEPRI_KERNEL);
+ __enable_irq();
+}
+static inline void port_enable(void) {
+ __set_BASEPRI(CORTEX_BASEPRI_DISABLED);
+ __enable_irq();
+}
+static inline void port_wait_for_interrupt(void) {
+}
+static inline rtcnt_t port_rt_get_counter_value(void) {
+ return DWT->CYCCNT;
+}
+#define CHTRACE_H
+#define CH_TRACE_TYPE_UNUSED 0U
+#define CH_TRACE_TYPE_SWITCH 1U
+#define CH_TRACE_TYPE_ISR_ENTER 2U
+#define CH_TRACE_TYPE_ISR_LEAVE 3U
+#define CH_TRACE_TYPE_HALT 4U
+#define CH_TRACE_TYPE_USER 5U
+#define CH_DBG_TRACE_MASK_DISABLED 255U
+#define CH_DBG_TRACE_MASK_NONE 0U
+#define CH_DBG_TRACE_MASK_SWITCH 1U
+#define CH_DBG_TRACE_MASK_ISR 2U
+#define CH_DBG_TRACE_MASK_HALT 4U
+#define CH_DBG_TRACE_MASK_USER 8U
+#define CH_DBG_TRACE_MASK_SLOW (CH_DBG_TRACE_MASK_SWITCH | CH_DBG_TRACE_MASK_HALT | CH_DBG_TRACE_MASK_USER)
+#define CH_DBG_TRACE_MASK_ALL (CH_DBG_TRACE_MASK_SWITCH | CH_DBG_TRACE_MASK_ISR | CH_DBG_TRACE_MASK_HALT | CH_DBG_TRACE_MASK_USER)
+#define _trace_init()
+#define _trace_switch(ntp,otp)
+#define _trace_isr_enter(isr)
+#define _trace_isr_leave(isr)
+#define _trace_halt(reason)
+#define chDbgWriteTraceI(up1,up2)
+#define chDbgWriteTrace(up1,up2)
+#define CHTM_H
+typedef struct {
+ rtcnt_t offset;
+} tm_calibration_t;
+typedef struct {
+ rtcnt_t best;
+ rtcnt_t worst;
+ rtcnt_t last;
+ ucnt_t n;
+ rttime_t cumulative;
+} time_measurement_t;
+ void _tm_init(void);
+ void chTMObjectInit(time_measurement_t *tmp);
+ NOINLINE void chTMStartMeasurementX(time_measurement_t *tmp);
+ NOINLINE void chTMStopMeasurementX(time_measurement_t *tmp);
+ NOINLINE void chTMChainMeasurementToX(time_measurement_t *tmp1,
+ time_measurement_t *tmp2);
+#define CHSTATS_H
+#define _stats_increase_irq()
+#define _stats_ctxswc(old,new)
+#define _stats_start_measure_crit_thd()
+#define _stats_stop_measure_crit_thd()
+#define _stats_start_measure_crit_isr()
+#define _stats_stop_measure_crit_isr()
+#define CHSCHD_H
+#define MSG_OK (msg_t)0
+#define MSG_TIMEOUT (msg_t)-1
+#define MSG_RESET (msg_t)-2
+#define NOPRIO (tprio_t)0
+#define IDLEPRIO (tprio_t)1
+#define LOWPRIO (tprio_t)2
+#define NORMALPRIO (tprio_t)128
+#define HIGHPRIO (tprio_t)255
+#define CH_STATE_READY (tstate_t)0
+#define CH_STATE_CURRENT (tstate_t)1
+#define CH_STATE_WTSTART (tstate_t)2
+#define CH_STATE_SUSPENDED (tstate_t)3
+#define CH_STATE_QUEUED (tstate_t)4
+#define CH_STATE_WTSEM (tstate_t)5
+#define CH_STATE_WTMTX (tstate_t)6
+#define CH_STATE_WTCOND (tstate_t)7
+#define CH_STATE_SLEEPING (tstate_t)8
+#define CH_STATE_WTEXIT (tstate_t)9
+#define CH_STATE_WTOREVT (tstate_t)10
+#define CH_STATE_WTANDEVT (tstate_t)11
+#define CH_STATE_SNDMSGQ (tstate_t)12
+#define CH_STATE_SNDMSG (tstate_t)13
+#define CH_STATE_WTMSG (tstate_t)14
+#define CH_STATE_FINAL (tstate_t)15
+#define CH_STATE_NAMES "READY", "CURRENT", "WTSTART", "SUSPENDED", "QUEUED", "WTSEM", "WTMTX", "WTCOND", "SLEEPING", "WTEXIT", "WTOREVT", "WTANDEVT", "SNDMSGQ", "SNDMSG", "WTMSG", "FINAL"
+#define CH_FLAG_MODE_MASK (tmode_t)3U
+#define CH_FLAG_MODE_STATIC (tmode_t)0U
+#define CH_FLAG_MODE_HEAP (tmode_t)1U
+#define CH_FLAG_MODE_MPOOL (tmode_t)2U
+#define CH_FLAG_TERMINATE (tmode_t)4U
+struct ch_threads_list {
+ thread_t *next;
+};
+struct ch_threads_queue {
+ thread_t *next;
+ thread_t *prev;
+};
+struct ch_thread {
+ threads_queue_t queue;
+ tprio_t prio;
+ struct port_context ctx;
+ thread_t *newer;
+ thread_t *older;
+ const char *name;
+ stkalign_t *wabase;
+ tstate_t state;
+ tmode_t flags;
+ trefs_t refs;
+ union {
+ msg_t rdymsg;
+ msg_t exitcode;
+ void *wtobjp;
+ thread_reference_t *wttrp;
+ msg_t sentmsg;
+ struct ch_semaphore *wtsemp;
+ struct ch_mutex *wtmtxp;
+ eventmask_t ewmask;
+ } u;
+ threads_list_t waiting;
+ threads_queue_t msgqueue;
+ eventmask_t epending;
+ struct ch_mutex *mtxlist;
+ tprio_t realprio;
+ void *mpool;
+ CH_CFG_THREAD_EXTRA_FIELDS
+};
+struct ch_virtual_timer {
+ virtual_timer_t *next;
+ virtual_timer_t *prev;
+ sysinterval_t delta;
+ vtfunc_t func;
+ void *par;
+};
+struct ch_virtual_timers_list {
+ virtual_timer_t *next;
+ virtual_timer_t *prev;
+ sysinterval_t delta;
+ volatile systime_t systime;
+};
+struct ch_ready_list {
+ threads_queue_t queue;
+ tprio_t prio;
+ struct port_context ctx;
+ thread_t *newer;
+ thread_t *older;
+ thread_t *current;
+};
+struct ch_system_debug {
+ const char * volatile panic_msg;
+};
+struct ch_system {
+ ready_list_t rlist;
+ virtual_timers_list_t vtlist;
+ system_debug_t dbg;
+ thread_t mainthread;
+ tm_calibration_t tm;
+ CH_CFG_SYSTEM_EXTRA_FIELDS
+};
+#define firstprio(rlp) ((rlp)->next->prio)
+#define currp ch.rlist.current
+extern ch_system_t ch;
+ void _scheduler_init(void);
+ thread_t *chSchReadyI(thread_t *tp);
+ thread_t *chSchReadyAheadI(thread_t *tp);
+ void chSchGoSleepS(tstate_t newstate);
+ msg_t chSchGoSleepTimeoutS(tstate_t newstate, sysinterval_t timeout);
+ void chSchWakeupS(thread_t *ntp, msg_t msg);
+ void chSchRescheduleS(void);
+ bool chSchIsPreemptionRequired(void);
+ void chSchDoRescheduleBehind(void);
+ void chSchDoRescheduleAhead(void);
+ void chSchDoReschedule(void);
+static inline void list_init(threads_list_t *tlp) {
+ tlp->next = (thread_t *)tlp;
+}
+static inline bool list_isempty(threads_list_t *tlp) {
+ return (bool)(tlp->next == (thread_t *)tlp);
+}
+static inline bool list_notempty(threads_list_t *tlp) {
+ return (bool)(tlp->next != (thread_t *)tlp);
+}
+static inline void queue_init(threads_queue_t *tqp) {
+ tqp->next = (thread_t *)tqp;
+ tqp->prev = (thread_t *)tqp;
+}
+static inline bool queue_isempty(const threads_queue_t *tqp) {
+ return (bool)(tqp->next == (const thread_t *)tqp);
+}
+static inline bool queue_notempty(const threads_queue_t *tqp) {
+ return (bool)(tqp->next != (const thread_t *)tqp);
+}
+static inline void list_insert(thread_t *tp, threads_list_t *tlp) {
+ tp->queue.next = tlp->next;
+ tlp->next = tp;
+}
+static inline thread_t *list_remove(threads_list_t *tlp) {
+ thread_t *tp = tlp->next;
+ tlp->next = tp->queue.next;
+ return tp;
+}
+static inline void queue_prio_insert(thread_t *tp, threads_queue_t *tqp) {
+ thread_t *cp = (thread_t *)tqp;
+ do {
+ cp = cp->queue.next;
+ } while ((cp != (thread_t *)tqp) && (cp->prio >= tp->prio));
+ tp->queue.next = cp;
+ tp->queue.prev = cp->queue.prev;
+ tp->queue.prev->queue.next = tp;
+ cp->queue.prev = tp;
+}
+static inline void queue_insert(thread_t *tp, threads_queue_t *tqp) {
+ tp->queue.next = (thread_t *)tqp;
+ tp->queue.prev = tqp->prev;
+ tp->queue.prev->queue.next = tp;
+ tqp->prev = tp;
+}
+static inline thread_t *queue_fifo_remove(threads_queue_t *tqp) {
+ thread_t *tp = tqp->next;
+ tqp->next = tp->queue.next;
+ tqp->next->queue.prev = (thread_t *)tqp;
+ return tp;
+}
+static inline thread_t *queue_lifo_remove(threads_queue_t *tqp) {
+ thread_t *tp = tqp->prev;
+ tqp->prev = tp->queue.prev;
+ tqp->prev->queue.next = (thread_t *)tqp;
+ return tp;
+}
+static inline thread_t *queue_dequeue(thread_t *tp) {
+ tp->queue.prev->queue.next = tp->queue.next;
+ tp->queue.next->queue.prev = tp->queue.prev;
+ return tp;
+}
+static inline bool chSchIsRescRequiredI(void) {
+ chDbgCheckClassI();
+ return firstprio(&ch.rlist.queue) > currp->prio;
+}
+static inline bool chSchCanYieldS(void) {
+ chDbgCheckClassS();
+ return firstprio(&ch.rlist.queue) >= currp->prio;
+}
+static inline void chSchDoYieldS(void) {
+ chDbgCheckClassS();
+ if (chSchCanYieldS()) {
+ chSchDoRescheduleBehind();
+ }
+}
+static inline void chSchPreemption(void) {
+ tprio_t p1 = firstprio(&ch.rlist.queue);
+ tprio_t p2 = currp->prio;
+ if (p1 > p2) {
+ chSchDoRescheduleAhead();
+ }
+}
+#define CHSYS_H
+#define CH_INTEGRITY_RLIST 1U
+#define CH_INTEGRITY_VTLIST 2U
+#define CH_INTEGRITY_REGISTRY 4U
+#define CH_INTEGRITY_PORT 8U
+#define CH_IRQ_IS_VALID_PRIORITY(prio) PORT_IRQ_IS_VALID_PRIORITY(prio)
+#define CH_IRQ_IS_VALID_KERNEL_PRIORITY(prio) PORT_IRQ_IS_VALID_KERNEL_PRIORITY(prio)
+#define CH_IRQ_PROLOGUE() PORT_IRQ_PROLOGUE(); CH_CFG_IRQ_PROLOGUE_HOOK(); _stats_increase_irq(); _trace_isr_enter(__func__); _dbg_check_enter_isr()
+#define CH_IRQ_EPILOGUE() _dbg_check_leave_isr(); _trace_isr_leave(__func__); CH_CFG_IRQ_EPILOGUE_HOOK(); PORT_IRQ_EPILOGUE()
+#define CH_IRQ_HANDLER(id) PORT_IRQ_HANDLER(id)
+#define CH_FAST_IRQ_HANDLER(id) PORT_FAST_IRQ_HANDLER(id)
+#define S2RTC(freq,sec) ((freq) * (sec))
+#define MS2RTC(freq,msec) (rtcnt_t)((((freq) + 999UL) / 1000UL) * (msec))
+#define US2RTC(freq,usec) (rtcnt_t)((((freq) + 999999UL) / 1000000UL) * (usec))
+#define RTC2S(freq,n) ((((n) - 1UL) / (freq)) + 1UL)
+#define RTC2MS(freq,n) ((((n) - 1UL) / ((freq) / 1000UL)) + 1UL)
+#define RTC2US(freq,n) ((((n) - 1UL) / ((freq) / 1000000UL)) + 1UL)
+#define chSysGetRealtimeCounterX() (rtcnt_t)port_rt_get_counter_value()
+#define chSysSwitch(ntp,otp) { _trace_switch(ntp, otp); _stats_ctxswc(ntp, otp); CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp); port_switch(ntp, otp); }
+extern stkalign_t ch_idle_thread_wa[];
+ void chSysInit(void);
+ bool chSysIntegrityCheckI(unsigned testmask);
+ void chSysTimerHandlerI(void);
+ syssts_t chSysGetStatusAndLockX(void);
+ void chSysRestoreStatusX(syssts_t sts);
+ bool chSysIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end);
+ void chSysPolledDelayX(rtcnt_t cycles);
+static inline void chSysDisable(void) {
+ port_disable();
+ _dbg_check_disable();
+}
+static inline void chSysSuspend(void) {
+ port_suspend();
+ _dbg_check_suspend();
+}
+static inline void chSysEnable(void) {
+ _dbg_check_enable();
+ port_enable();
+}
+static inline void chSysLock(void) {
+ port_lock();
+ _stats_start_measure_crit_thd();
+ _dbg_check_lock();
+}
+static inline void chSysUnlock(void) {
+ _dbg_check_unlock();
+ _stats_stop_measure_crit_thd();
+ chDbgAssert((ch.rlist.queue.next == (thread_t *)&ch.rlist.queue) ||
+ (ch.rlist.current->prio >= ch.rlist.queue.next->prio),
+ "priority order violation");
+ port_unlock();
+}
+static inline void chSysLockFromISR(void) {
+ port_lock_from_isr();
+ _stats_start_measure_crit_isr();
+ _dbg_check_lock_from_isr();
+}
+static inline void chSysUnlockFromISR(void) {
+ _dbg_check_unlock_from_isr();
+ _stats_stop_measure_crit_isr();
+ port_unlock_from_isr();
+}
+static inline void chSysUnconditionalLock(void) {
+ if (port_irq_enabled(port_get_irq_status())) {
+ chSysLock();
+ }
+}
+static inline void chSysUnconditionalUnlock(void) {
+ if (!port_irq_enabled(port_get_irq_status())) {
+ chSysUnlock();
+ }
+}
+static inline thread_t *chSysGetIdleThreadX(void) {
+ return ch.rlist.queue.prev;
+}
+#define CHVT_H
+ void _vt_init(void);
+ void chVTDoSetI(virtual_timer_t *vtp, sysinterval_t delay,
+ vtfunc_t vtfunc, void *par);
+ void chVTDoResetI(virtual_timer_t *vtp);
+static inline void chVTObjectInit(virtual_timer_t *vtp) {
+ vtp->func = NULL;
+}
+static inline systime_t chVTGetSystemTimeX(void) {
+ return ch.vtlist.systime;
+}
+static inline systime_t chVTGetSystemTime(void) {
+ systime_t systime;
+ chSysLock();
+ systime = chVTGetSystemTimeX();
+ chSysUnlock();
+ return systime;
+}
+static inline sysinterval_t chVTTimeElapsedSinceX(systime_t start) {
+ return chTimeDiffX(start, chVTGetSystemTimeX());
+}
+static inline bool chVTIsSystemTimeWithinX(systime_t start, systime_t end) {
+ return chTimeIsInRangeX(chVTGetSystemTimeX(), start, end);
+}
+static inline bool chVTIsSystemTimeWithin(systime_t start, systime_t end) {
+ return chTimeIsInRangeX(chVTGetSystemTime(), start, end);
+}
+static inline bool chVTGetTimersStateI(sysinterval_t *timep) {
+ chDbgCheckClassI();
+ if (&ch.vtlist == (virtual_timers_list_t *)ch.vtlist.next) {
+ return false;
+ }
+ if (timep != NULL) {
+ *timep = ch.vtlist.next->delta;
+ }
+ return true;
+}
+static inline bool chVTIsArmedI(const virtual_timer_t *vtp) {
+ chDbgCheckClassI();
+ return (bool)(vtp->func != NULL);
+}
+static inline bool chVTIsArmed(const virtual_timer_t *vtp) {
+ bool b;
+ chSysLock();
+ b = chVTIsArmedI(vtp);
+ chSysUnlock();
+ return b;
+}
+static inline void chVTResetI(virtual_timer_t *vtp) {
+ if (chVTIsArmedI(vtp)) {
+ chVTDoResetI(vtp);
+ }
+}
+static inline void chVTReset(virtual_timer_t *vtp) {
+ chSysLock();
+ chVTResetI(vtp);
+ chSysUnlock();
+}
+static inline void chVTSetI(virtual_timer_t *vtp, sysinterval_t delay,
+ vtfunc_t vtfunc, void *par) {
+ chVTResetI(vtp);
+ chVTDoSetI(vtp, delay, vtfunc, par);
+}
+static inline void chVTSet(virtual_timer_t *vtp, sysinterval_t delay,
+ vtfunc_t vtfunc, void *par) {
+ chSysLock();
+ chVTSetI(vtp, delay, vtfunc, par);
+ chSysUnlock();
+}
+static inline void chVTDoTickI(void) {
+ chDbgCheckClassI();
+ ch.vtlist.systime++;
+ if (&ch.vtlist != (virtual_timers_list_t *)ch.vtlist.next) {
+ --ch.vtlist.next->delta;
+ while (ch.vtlist.next->delta == (sysinterval_t)0) {
+ virtual_timer_t *vtp;
+ vtfunc_t fn;
+ vtp = ch.vtlist.next;
+ fn = vtp->func;
+ vtp->func = NULL;
+ vtp->next->prev = (virtual_timer_t *)&ch.vtlist;
+ ch.vtlist.next = vtp->next;
+ chSysUnlockFromISR();
+ fn(vtp->par);
+ chSysLockFromISR();
+ }
+ }
+}
+#define CHTHREADS_H
+typedef void (*tfunc_t)(void *p);
+typedef struct {
+ const char *name;
+ stkalign_t *wbase;
+ stkalign_t *wend;
+ tprio_t prio;
+ tfunc_t funcp;
+ void *arg;
+} thread_descriptor_t;
+#define _THREADS_QUEUE_DATA(name) {(thread_t *)&name, (thread_t *)&name}
+#define _THREADS_QUEUE_DECL(name) threads_queue_t name = _THREADS_QUEUE_DATA(name)
+#define THD_WORKING_AREA_SIZE(n) MEM_ALIGN_NEXT(sizeof(thread_t) + PORT_WA_SIZE(n), PORT_STACK_ALIGN)
+#define THD_WORKING_AREA(s,n) PORT_WORKING_AREA(s, n)
+#define THD_WORKING_AREA_BASE(s) ((stkalign_t *)(s))
+#define THD_WORKING_AREA_END(s) (THD_WORKING_AREA_BASE(s) + (sizeof (s) / sizeof (stkalign_t)))
+#define THD_FUNCTION(tname,arg) PORT_THD_FUNCTION(tname, arg)
+#define chThdSleepSeconds(sec) chThdSleep(TIME_S2I(sec))
+#define chThdSleepMilliseconds(msec) chThdSleep(TIME_MS2I(msec))
+#define chThdSleepMicroseconds(usec) chThdSleep(TIME_US2I(usec))
+ thread_t *_thread_init(thread_t *tp, const char *name, tprio_t prio);
+ thread_t *chThdCreateSuspendedI(const thread_descriptor_t *tdp);
+ thread_t *chThdCreateSuspended(const thread_descriptor_t *tdp);
+ thread_t *chThdCreateI(const thread_descriptor_t *tdp);
+ thread_t *chThdCreate(const thread_descriptor_t *tdp);
+ thread_t *chThdCreateStatic(void *wsp, size_t size,
+ tprio_t prio, tfunc_t pf, void *arg);
+ thread_t *chThdStart(thread_t *tp);
+ thread_t *chThdAddRef(thread_t *tp);
+ void chThdRelease(thread_t *tp);
+ void chThdExit(msg_t msg);
+ void chThdExitS(msg_t msg);
+ msg_t chThdWait(thread_t *tp);
+ tprio_t chThdSetPriority(tprio_t newprio);
+ void chThdTerminate(thread_t *tp);
+ msg_t chThdSuspendS(thread_reference_t *trp);
+ msg_t chThdSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout);
+ void chThdResumeI(thread_reference_t *trp, msg_t msg);
+ void chThdResumeS(thread_reference_t *trp, msg_t msg);
+ void chThdResume(thread_reference_t *trp, msg_t msg);
+ msg_t chThdEnqueueTimeoutS(threads_queue_t *tqp, sysinterval_t timeout);
+ void chThdDequeueNextI(threads_queue_t *tqp, msg_t msg);
+ void chThdDequeueAllI(threads_queue_t *tqp, msg_t msg);
+ void chThdSleep(sysinterval_t time);
+ void chThdSleepUntil(systime_t time);
+ systime_t chThdSleepUntilWindowed(systime_t prev, systime_t next);
+ void chThdYield(void);
+static inline thread_t *chThdGetSelfX(void) {
+ return ch.rlist.current;
+}
+static inline tprio_t chThdGetPriorityX(void) {
+ return chThdGetSelfX()->prio;
+}
+static inline stkalign_t *chThdGetWorkingAreaX(thread_t *tp) {
+ return tp->wabase;
+}
+static inline bool chThdTerminatedX(thread_t *tp) {
+ return (bool)(tp->state == CH_STATE_FINAL);
+}
+static inline bool chThdShouldTerminateX(void) {
+ return (bool)((chThdGetSelfX()->flags & CH_FLAG_TERMINATE) != (tmode_t)0);
+}
+static inline thread_t *chThdStartI(thread_t *tp) {
+ chDbgAssert(tp->state == CH_STATE_WTSTART, "wrong state");
+ return chSchReadyI(tp);
+}
+static inline void chThdSleepS(sysinterval_t ticks) {
+ chDbgCheck(ticks != TIME_IMMEDIATE);
+ (void) chSchGoSleepTimeoutS(CH_STATE_SLEEPING, ticks);
+}
+static inline void chThdQueueObjectInit(threads_queue_t *tqp) {
+ queue_init(tqp);
+}
+static inline bool chThdQueueIsEmptyI(threads_queue_t *tqp) {
+ chDbgCheckClassI();
+ return queue_isempty(tqp);
+}
+static inline void chThdDoDequeueNextI(threads_queue_t *tqp, msg_t msg) {
+ thread_t *tp;
+ chDbgAssert(queue_notempty(tqp), "empty queue");
+ tp = queue_fifo_remove(tqp);
+ chDbgAssert(tp->state == CH_STATE_QUEUED, "invalid state");
+ tp->u.rdymsg = msg;
+ (void) chSchReadyI(tp);
+}
+#define CHREGISTRY_H
+typedef struct {
+ char identifier[4];
+ uint8_t zero;
+ uint8_t size;
+ uint16_t version;
+ uint8_t ptrsize;
+ uint8_t timesize;
+ uint8_t threadsize;
+ uint8_t off_prio;
+ uint8_t off_ctx;
+ uint8_t off_newer;
+ uint8_t off_older;
+ uint8_t off_name;
+ uint8_t off_stklimit;
+ uint8_t off_state;
+ uint8_t off_flags;
+ uint8_t off_refs;
+ uint8_t off_preempt;
+ uint8_t off_time;
+} chdebug_t;
+#define REG_REMOVE(tp) { (tp)->older->newer = (tp)->newer; (tp)->newer->older = (tp)->older; }
+#define REG_INSERT(tp) { (tp)->newer = (thread_t *)&ch.rlist; (tp)->older = ch.rlist.older; (tp)->older->newer = (tp); ch.rlist.older = (tp); }
+ extern ROMCONST chdebug_t ch_debug;
+ thread_t *chRegFirstThread(void);
+ thread_t *chRegNextThread(thread_t *tp);
+ thread_t *chRegFindThreadByName(const char *name);
+ thread_t *chRegFindThreadByPointer(thread_t *tp);
+ thread_t *chRegFindThreadByWorkingArea(stkalign_t *wa);
+static inline void chRegSetThreadName(const char *name) {
+ ch.rlist.current->name = name;
+}
+static inline const char *chRegGetThreadNameX(thread_t *tp) {
+ return tp->name;
+}
+static inline void chRegSetThreadNameX(thread_t *tp, const char *name) {
+ tp->name = name;
+}
+#define CHSEM_H
+typedef struct ch_semaphore {
+ threads_queue_t queue;
+ cnt_t cnt;
+} semaphore_t;
+#define _SEMAPHORE_DATA(name,n) {_THREADS_QUEUE_DATA(name.queue), n}
+#define SEMAPHORE_DECL(name,n) semaphore_t name = _SEMAPHORE_DATA(name, n)
+ void chSemObjectInit(semaphore_t *sp, cnt_t n);
+ void chSemReset(semaphore_t *sp, cnt_t n);
+ void chSemResetI(semaphore_t *sp, cnt_t n);
+ msg_t chSemWait(semaphore_t *sp);
+ msg_t chSemWaitS(semaphore_t *sp);
+ msg_t chSemWaitTimeout(semaphore_t *sp, sysinterval_t timeout);
+ msg_t chSemWaitTimeoutS(semaphore_t *sp, sysinterval_t timeout);
+ void chSemSignal(semaphore_t *sp);
+ void chSemSignalI(semaphore_t *sp);
+ void chSemAddCounterI(semaphore_t *sp, cnt_t n);
+ msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw);
+static inline void chSemFastWaitI(semaphore_t *sp) {
+ chDbgCheckClassI();
+ sp->cnt--;
+}
+static inline void chSemFastSignalI(semaphore_t *sp) {
+ chDbgCheckClassI();
+ sp->cnt++;
+}
+static inline cnt_t chSemGetCounterI(const semaphore_t *sp) {
+ chDbgCheckClassI();
+ return sp->cnt;
+}
+#define CHMTX_H
+typedef struct ch_mutex mutex_t;
+struct ch_mutex {
+ threads_queue_t queue;
+ thread_t *owner;
+ mutex_t *next;
+};
+#define _MUTEX_DATA(name) {_THREADS_QUEUE_DATA(name.queue), NULL, NULL}
+#define MUTEX_DECL(name) mutex_t name = _MUTEX_DATA(name)
+ void chMtxObjectInit(mutex_t *mp);
+ void chMtxLock(mutex_t *mp);
+ void chMtxLockS(mutex_t *mp);
+ bool chMtxTryLock(mutex_t *mp);
+ bool chMtxTryLockS(mutex_t *mp);
+ void chMtxUnlock(mutex_t *mp);
+ void chMtxUnlockS(mutex_t *mp);
+ void chMtxUnlockAll(void);
+ void chMtxUnlockAllS(void);
+static inline bool chMtxQueueNotEmptyS(mutex_t *mp) {
+ chDbgCheckClassS();
+ return queue_notempty(&mp->queue);
+}
+static inline thread_t *chMtxGetOwnerI(mutex_t *mp) {
+ chDbgCheckClassI();
+ return mp->owner;
+}
+static inline mutex_t *chMtxGetNextMutexX(void) {
+ return chThdGetSelfX()->mtxlist;
+}
+#define CHCOND_H
+typedef struct condition_variable {
+ threads_queue_t queue;
+} condition_variable_t;
+#define _CONDVAR_DATA(name) {_THREADS_QUEUE_DATA(name.queue)}
+#define CONDVAR_DECL(name) condition_variable_t name = _CONDVAR_DATA(name)
+ void chCondObjectInit(condition_variable_t *cp);
+ void chCondSignal(condition_variable_t *cp);
+ void chCondSignalI(condition_variable_t *cp);
+ void chCondBroadcast(condition_variable_t *cp);
+ void chCondBroadcastI(condition_variable_t *cp);
+ msg_t chCondWait(condition_variable_t *cp);
+ msg_t chCondWaitS(condition_variable_t *cp);
+ msg_t chCondWaitTimeout(condition_variable_t *cp, sysinterval_t timeout);
+ msg_t chCondWaitTimeoutS(condition_variable_t *cp, sysinterval_t timeout);
+#define CHEVENTS_H
+typedef struct event_listener event_listener_t;
+struct event_listener {
+ event_listener_t *next;
+ thread_t *listener;
+ eventmask_t events;
+ eventflags_t flags;
+ eventflags_t wflags;
+};
+typedef struct event_source {
+ event_listener_t *next;
+} event_source_t;
+typedef void (*evhandler_t)(eventid_t id);
+#define ALL_EVENTS ((eventmask_t)-1)
+#define EVENT_MASK(eid) ((eventmask_t)1 << (eventmask_t)(eid))
+#define _EVENTSOURCE_DATA(name) {(event_listener_t *)(&name)}
+#define EVENTSOURCE_DECL(name) event_source_t name = _EVENTSOURCE_DATA(name)
+ void chEvtRegisterMaskWithFlags(event_source_t *esp,
+ event_listener_t *elp,
+ eventmask_t events,
+ eventflags_t wflags);
+ void chEvtUnregister(event_source_t *esp, event_listener_t *elp);
+ eventmask_t chEvtGetAndClearEventsI(eventmask_t events);
+ eventmask_t chEvtGetAndClearEvents(eventmask_t events);
+ eventmask_t chEvtAddEvents(eventmask_t events);
+ eventflags_t chEvtGetAndClearFlags(event_listener_t *elp);
+ eventflags_t chEvtGetAndClearFlagsI(event_listener_t *elp);
+ void chEvtSignal(thread_t *tp, eventmask_t events);
+ void chEvtSignalI(thread_t *tp, eventmask_t events);
+ void chEvtBroadcastFlags(event_source_t *esp, eventflags_t flags);
+ void chEvtBroadcastFlagsI(event_source_t *esp, eventflags_t flags);
+ void chEvtDispatch(const evhandler_t *handlers, eventmask_t events);
+ eventmask_t chEvtWaitOne(eventmask_t events);
+ eventmask_t chEvtWaitAny(eventmask_t events);
+ eventmask_t chEvtWaitAll(eventmask_t events);
+ eventmask_t chEvtWaitOneTimeout(eventmask_t events, sysinterval_t timeout);
+ eventmask_t chEvtWaitAnyTimeout(eventmask_t events, sysinterval_t timeout);
+ eventmask_t chEvtWaitAllTimeout(eventmask_t events, sysinterval_t timeout);
+static inline void chEvtObjectInit(event_source_t *esp) {
+ esp->next = (event_listener_t *)esp;
+}
+static inline void chEvtRegisterMask(event_source_t *esp,
+ event_listener_t *elp,
+ eventmask_t events) {
+ chEvtRegisterMaskWithFlags(esp, elp, events, (eventflags_t)-1);
+}
+static inline void chEvtRegister(event_source_t *esp,
+ event_listener_t *elp,
+ eventid_t event) {
+ chEvtRegisterMask(esp, elp, EVENT_MASK(event));
+}
+static inline bool chEvtIsListeningI(event_source_t *esp) {
+ return (bool)(esp != (event_source_t *)esp->next);
+}
+static inline void chEvtBroadcast(event_source_t *esp) {
+ chEvtBroadcastFlags(esp, (eventflags_t)0);
+}
+static inline void chEvtBroadcastI(event_source_t *esp) {
+ chEvtBroadcastFlagsI(esp, (eventflags_t)0);
+}
+static inline eventmask_t chEvtAddEventsI(eventmask_t events) {
+ return currp->epending |= events;
+}
+static inline eventmask_t chEvtGetEventsX(void) {
+ return currp->epending;
+}
+#define CHMSG_H
+ msg_t chMsgSend(thread_t *tp, msg_t msg);
+ thread_t * chMsgWait(void);
+ void chMsgRelease(thread_t *tp, msg_t msg);
+static inline bool chMsgIsPendingI(thread_t *tp) {
+ chDbgCheckClassI();
+ return (bool)(tp->msgqueue.next != (thread_t *)&tp->msgqueue);
+}
+static inline msg_t chMsgGet(thread_t *tp) {
+ chDbgAssert(tp->state == CH_STATE_SNDMSG, "invalid state");
+ return tp->u.sentmsg;
+}
+static inline void chMsgReleaseS(thread_t *tp, msg_t msg) {
+ chDbgCheckClassS();
+ chSchWakeupS(tp, msg);
+}
+#define CHLIB_H
+#define _CHIBIOS_OSLIB_
+#define CH_OSLIB_STABLE 1
+#define CH_OSLIB_VERSION "1.1.2"
+#define CH_OSLIB_MAJOR 1
+#define CH_OSLIB_MINOR 1
+#define CH_OSLIB_PATCH 2
+#define CHBSEM_H
+typedef struct ch_binary_semaphore {
+ semaphore_t sem;
+} binary_semaphore_t;
+#define _BSEMAPHORE_DATA(name,taken) {_SEMAPHORE_DATA(name.sem, ((taken) ? 0 : 1))}
+#define BSEMAPHORE_DECL(name,taken) binary_semaphore_t name = _BSEMAPHORE_DATA(name, taken)
+static inline void chBSemObjectInit(binary_semaphore_t *bsp, bool taken) {
+ chSemObjectInit(&bsp->sem, taken ? (cnt_t)0 : (cnt_t)1);
+}
+static inline msg_t chBSemWait(binary_semaphore_t *bsp) {
+ return chSemWait(&bsp->sem);
+}
+static inline msg_t chBSemWaitS(binary_semaphore_t *bsp) {
+ chDbgCheckClassS();
+ return chSemWaitS(&bsp->sem);
+}
+static inline msg_t chBSemWaitTimeoutS(binary_semaphore_t *bsp,
+ sysinterval_t timeout) {
+ chDbgCheckClassS();
+ return chSemWaitTimeoutS(&bsp->sem, timeout);
+}
+static inline msg_t chBSemWaitTimeout(binary_semaphore_t *bsp,
+ sysinterval_t timeout) {
+ return chSemWaitTimeout(&bsp->sem, timeout);
+}
+static inline void chBSemResetI(binary_semaphore_t *bsp, bool taken) {
+ chDbgCheckClassI();
+ chSemResetI(&bsp->sem, taken ? (cnt_t)0 : (cnt_t)1);
+}
+static inline void chBSemReset(binary_semaphore_t *bsp, bool taken) {
+ chSemReset(&bsp->sem, taken ? (cnt_t)0 : (cnt_t)1);
+}
+static inline void chBSemSignalI(binary_semaphore_t *bsp) {
+ chDbgCheckClassI();
+ if (bsp->sem.cnt < (cnt_t)1) {
+ chSemSignalI(&bsp->sem);
+ }
+}
+static inline void chBSemSignal(binary_semaphore_t *bsp) {
+ chSysLock();
+ chBSemSignalI(bsp);
+ chSchRescheduleS();
+ chSysUnlock();
+}
+static inline bool chBSemGetStateI(const binary_semaphore_t *bsp) {
+ chDbgCheckClassI();
+ return (bsp->sem.cnt > (cnt_t)0) ? false : true;
+}
+#define CHMBOXES_H
+typedef struct {
+ msg_t *buffer;
+ msg_t *top;
+ msg_t *wrptr;
+ msg_t *rdptr;
+ size_t cnt;
+ bool reset;
+ threads_queue_t qw;
+ threads_queue_t qr;
+} mailbox_t;
+#define _MAILBOX_DATA(name,buffer,size) { (msg_t *)(buffer), (msg_t *)(buffer) + size, (msg_t *)(buffer), (msg_t *)(buffer), (size_t)0, false, _THREADS_QUEUE_DATA(name.qw), _THREADS_QUEUE_DATA(name.qr), }
+#define MAILBOX_DECL(name,buffer,size) mailbox_t name = _MAILBOX_DATA(name, buffer, size)
+ void chMBObjectInit(mailbox_t *mbp, msg_t *buf, size_t n);
+ void chMBReset(mailbox_t *mbp);
+ void chMBResetI(mailbox_t *mbp);
+ msg_t chMBPostTimeout(mailbox_t *mbp, msg_t msg, sysinterval_t timeout);
+ msg_t chMBPostTimeoutS(mailbox_t *mbp, msg_t msg, sysinterval_t timeout);
+ msg_t chMBPostI(mailbox_t *mbp, msg_t msg);
+ msg_t chMBPostAheadTimeout(mailbox_t *mbp, msg_t msg, sysinterval_t timeout);
+ msg_t chMBPostAheadTimeoutS(mailbox_t *mbp, msg_t msg, sysinterval_t timeout);
+ msg_t chMBPostAheadI(mailbox_t *mbp, msg_t msg);
+ msg_t chMBFetchTimeout(mailbox_t *mbp, msg_t *msgp, sysinterval_t timeout);
+ msg_t chMBFetchTimeoutS(mailbox_t *mbp, msg_t *msgp, sysinterval_t timeout);
+ msg_t chMBFetchI(mailbox_t *mbp, msg_t *msgp);
+static inline size_t chMBGetSizeI(const mailbox_t *mbp) {
+ return (size_t)(mbp->top - mbp->buffer);
+}
+static inline size_t chMBGetUsedCountI(const mailbox_t *mbp) {
+ chDbgCheckClassI();
+ return mbp->cnt;
+}
+static inline size_t chMBGetFreeCountI(const mailbox_t *mbp) {
+ chDbgCheckClassI();
+ return chMBGetSizeI(mbp) - chMBGetUsedCountI(mbp);
+}
+static inline msg_t chMBPeekI(const mailbox_t *mbp) {
+ chDbgCheckClassI();
+ return *mbp->rdptr;
+}
+static inline void chMBResumeX(mailbox_t *mbp) {
+ mbp->reset = false;
+}
+#define CHMEMCORE_H
+typedef void *(*memgetfunc_t)(size_t size, unsigned align);
+typedef void *(*memgetfunc2_t)(size_t size, unsigned align, size_t offset);
+typedef struct {
+ uint8_t *nextmem;
+ uint8_t *endmem;
+} memcore_t;
+extern memcore_t ch_memcore;
+ void _core_init(void);
+ void *chCoreAllocAlignedWithOffsetI(size_t size,
+ unsigned align,
+ size_t offset);
+ void *chCoreAllocAlignedWithOffset(size_t size,
+ unsigned align,
+ size_t offset);
+ size_t chCoreGetStatusX(void);
+static inline void *chCoreAllocAlignedI(size_t size, unsigned align) {
+ return chCoreAllocAlignedWithOffsetI(size, align, 0U);
+}
+static inline void *chCoreAllocAligned(size_t size, unsigned align) {
+ void *p;
+ chSysLock();
+ p = chCoreAllocAlignedWithOffsetI(size, align, 0U);
+ chSysUnlock();
+ return p;
+}
+static inline void *chCoreAllocI(size_t size) {
+ return chCoreAllocAlignedWithOffsetI(size, PORT_NATURAL_ALIGN, 0U);
+}
+static inline void *chCoreAlloc(size_t size) {
+ return chCoreAllocAlignedWithOffset(size, PORT_NATURAL_ALIGN, 0U);
+}
+#define CHMEMHEAPS_H
+#define CH_HEAP_ALIGNMENT 8U
+typedef struct memory_heap memory_heap_t;
+typedef union heap_header heap_header_t;
+union heap_header {
+ struct {
+ heap_header_t *next;
+ size_t pages;
+ } free;
+ struct {
+ memory_heap_t *heap;
+ size_t size;
+ } used;
+};
+struct memory_heap {
+ memgetfunc2_t provider;
+ heap_header_t header;
+ mutex_t mtx;
+};
+#define CH_HEAP_AREA(name,size) ALIGNED_VAR(CH_HEAP_ALIGNMENT) uint8_t name[MEM_ALIGN_NEXT((size), CH_HEAP_ALIGNMENT)]
+ void _heap_init(void);
+ void chHeapObjectInit(memory_heap_t *heapp, void *buf, size_t size);
+ void *chHeapAllocAligned(memory_heap_t *heapp, size_t size, unsigned align);
+ void chHeapFree(void *p);
+ size_t chHeapStatus(memory_heap_t *heapp, size_t *totalp, size_t *largestp);
+static inline void *chHeapAlloc(memory_heap_t *heapp, size_t size) {
+ return chHeapAllocAligned(heapp, size, CH_HEAP_ALIGNMENT);
+}
+static inline size_t chHeapGetSize(const void *p) {
+ return ((heap_header_t *)p - 1U)->used.size;
+}
+#define CHMEMPOOLS_H
+struct pool_header {
+ struct pool_header *next;
+};
+typedef struct {
+ struct pool_header *next;
+ size_t object_size;
+ unsigned align;
+ memgetfunc_t provider;
+} memory_pool_t;
+typedef struct {
+ semaphore_t sem;
+ memory_pool_t pool;
+} guarded_memory_pool_t;
+#define _MEMORYPOOL_DATA(name,size,align,provider) {NULL, size, align, provider}
+#define MEMORYPOOL_DECL(name,size,align,provider) memory_pool_t name = _MEMORYPOOL_DATA(name, size, align, provider)
+#define _GUARDEDMEMORYPOOL_DATA(name,size,align) { _SEMAPHORE_DATA(name.sem, (cnt_t)0), _MEMORYPOOL_DATA(NULL, size, align, NULL) }
+#define GUARDEDMEMORYPOOL_DECL(name,size,align) guarded_memory_pool_t name = _GUARDEDMEMORYPOOL_DATA(name, size, align)
+ void chPoolObjectInitAligned(memory_pool_t *mp, size_t size,
+ unsigned align, memgetfunc_t provider);
+ void chPoolLoadArray(memory_pool_t *mp, void *p, size_t n);
+ void *chPoolAllocI(memory_pool_t *mp);
+ void *chPoolAlloc(memory_pool_t *mp);
+ void chPoolFreeI(memory_pool_t *mp, void *objp);
+ void chPoolFree(memory_pool_t *mp, void *objp);
+ void chGuardedPoolObjectInitAligned(guarded_memory_pool_t *gmp,
+ size_t size,
+ unsigned align);
+ void chGuardedPoolLoadArray(guarded_memory_pool_t *gmp, void *p, size_t n);
+ void *chGuardedPoolAllocTimeoutS(guarded_memory_pool_t *gmp,
+ sysinterval_t timeout);
+ void *chGuardedPoolAllocTimeout(guarded_memory_pool_t *gmp,
+ sysinterval_t timeout);
+ void chGuardedPoolFree(guarded_memory_pool_t *gmp, void *objp);
+static inline void chPoolObjectInit(memory_pool_t *mp,
+ size_t size,
+ memgetfunc_t provider) {
+ chPoolObjectInitAligned(mp, size, PORT_NATURAL_ALIGN, provider);
+}
+static inline void chPoolAdd(memory_pool_t *mp, void *objp) {
+ chPoolFree(mp, objp);
+}
+static inline void chPoolAddI(memory_pool_t *mp, void *objp) {
+ chPoolFreeI(mp, objp);
+}
+static inline void chGuardedPoolObjectInit(guarded_memory_pool_t *gmp,
+ size_t size) {
+ chGuardedPoolObjectInitAligned(gmp, size, PORT_NATURAL_ALIGN);
+}
+static inline cnt_t chGuardedPoolGetCounterI(guarded_memory_pool_t *gmp) {
+ return chSemGetCounterI(&gmp->sem);
+}
+static inline void *chGuardedPoolAllocI(guarded_memory_pool_t *gmp) {
+ void *p;
+ p = chPoolAllocI(&gmp->pool);
+ if (p != NULL) {
+ chSemFastWaitI(&gmp->sem);
+ chDbgAssert(chSemGetCounterI(&gmp->sem) >= (cnt_t)0,
+ "semaphore out of sync");
+ }
+ return p;
+}
+static inline void chGuardedPoolFreeI(guarded_memory_pool_t *gmp, void *objp) {
+ chPoolFreeI(&gmp->pool, objp);
+ chSemSignalI(&gmp->sem);
+}
+static inline void chGuardedPoolFreeS(guarded_memory_pool_t *gmp, void *objp) {
+ chGuardedPoolFreeI(gmp, objp);
+ chSchRescheduleS();
+}
+static inline void chGuardedPoolAdd(guarded_memory_pool_t *gmp, void *objp) {
+ chGuardedPoolFree(gmp, objp);
+}
+static inline void chGuardedPoolAddI(guarded_memory_pool_t *gmp, void *objp) {
+ chGuardedPoolFreeI(gmp, objp);
+}
+static inline void chGuardedPoolAddS(guarded_memory_pool_t *gmp, void *objp) {
+ chGuardedPoolFreeS(gmp, objp);
+}
+#define CHOBJFIFOS_H
+typedef struct ch_objects_fifo {
+ guarded_memory_pool_t free;
+ mailbox_t mbx;
+} objects_fifo_t;
+static inline void chFifoObjectInitAligned(objects_fifo_t *ofp, size_t objsize,
+ size_t objn, unsigned objalign,
+ void *objbuf, msg_t *msgbuf) {
+ chDbgCheck((objsize >= objalign) && ((objsize % objalign) == 0U));
+ chGuardedPoolObjectInitAligned(&ofp->free, objsize, objalign);
+ chGuardedPoolLoadArray(&ofp->free, objbuf, objn);
+ chMBObjectInit(&ofp->mbx, msgbuf, objn);
+}
+static inline void chFifoObjectInit(objects_fifo_t *ofp, size_t objsize,
+ size_t objn, void *objbuf,
+ msg_t *msgbuf) {
+ chFifoObjectInitAligned(ofp, objsize, objn,
+ PORT_NATURAL_ALIGN,
+ objbuf, msgbuf);
+}
+static inline void *chFifoTakeObjectI(objects_fifo_t *ofp) {
+ return chGuardedPoolAllocI(&ofp->free);
+}
+static inline void *chFifoTakeObjectTimeoutS(objects_fifo_t *ofp,
+ sysinterval_t timeout) {
+ return chGuardedPoolAllocTimeoutS(&ofp->free, timeout);
+}
+static inline void *chFifoTakeObjectTimeout(objects_fifo_t *ofp,
+ sysinterval_t timeout) {
+ return chGuardedPoolAllocTimeout(&ofp->free, timeout);
+}
+static inline void chFifoReturnObjectI(objects_fifo_t *ofp,
+ void *objp) {
+ chGuardedPoolFreeI(&ofp->free, objp);
+}
+static inline void chFifoReturnObjectS(objects_fifo_t *ofp,
+ void *objp) {
+ chGuardedPoolFreeS(&ofp->free, objp);
+}
+static inline void chFifoReturnObject(objects_fifo_t *ofp,
+ void *objp) {
+ chGuardedPoolFree(&ofp->free, objp);
+}
+static inline void chFifoSendObjectI(objects_fifo_t *ofp,
+ void *objp) {
+ msg_t msg;
+ msg = chMBPostI(&ofp->mbx, (msg_t)objp);
+ chDbgAssert(msg == MSG_OK, "post failed");
+}
+static inline void chFifoSendObjectS(objects_fifo_t *ofp,
+ void *objp) {
+ msg_t msg;
+ msg = chMBPostTimeoutS(&ofp->mbx, (msg_t)objp, TIME_IMMEDIATE);
+ chDbgAssert(msg == MSG_OK, "post failed");
+}
+static inline void chFifoSendObject(objects_fifo_t *ofp, void *objp) {
+ msg_t msg;
+ msg = chMBPostTimeout(&ofp->mbx, (msg_t)objp, TIME_IMMEDIATE);
+ chDbgAssert(msg == MSG_OK, "post failed");
+}
+static inline void chFifoSendObjectAheadI(objects_fifo_t *ofp,
+ void *objp) {
+ msg_t msg;
+ msg = chMBPostAheadI(&ofp->mbx, (msg_t)objp);
+ chDbgAssert(msg == MSG_OK, "post failed");
+}
+static inline void chFifoSendObjectAheadS(objects_fifo_t *ofp,
+ void *objp) {
+ msg_t msg;
+ msg = chMBPostAheadTimeoutS(&ofp->mbx, (msg_t)objp, TIME_IMMEDIATE);
+ chDbgAssert(msg == MSG_OK, "post failed");
+}
+static inline void chFifoSendObjectAhead(objects_fifo_t *ofp, void *objp) {
+ msg_t msg;
+ msg = chMBPostAheadTimeout(&ofp->mbx, (msg_t)objp, TIME_IMMEDIATE);
+ chDbgAssert(msg == MSG_OK, "post failed");
+}
+static inline msg_t chFifoReceiveObjectI(objects_fifo_t *ofp,
+ void **objpp) {
+ return chMBFetchI(&ofp->mbx, (msg_t *)objpp);
+}
+static inline msg_t chFifoReceiveObjectTimeoutS(objects_fifo_t *ofp,
+ void **objpp,
+ sysinterval_t timeout) {
+ return chMBFetchTimeoutS(&ofp->mbx, (msg_t *)objpp, timeout);
+}
+static inline msg_t chFifoReceiveObjectTimeout(objects_fifo_t *ofp,
+ void **objpp,
+ sysinterval_t timeout) {
+ return chMBFetchTimeout(&ofp->mbx, (msg_t *)objpp, timeout);
+}
+#define CHPIPES_H
+typedef struct {
+ uint8_t *buffer;
+ uint8_t *top;
+ uint8_t *wrptr;
+ uint8_t *rdptr;
+ size_t cnt;
+ bool reset;
+ thread_reference_t wtr;
+ thread_reference_t rtr;
+ mutex_t cmtx;
+ mutex_t wmtx;
+ mutex_t rmtx;
+} pipe_t;
+#define _PIPE_DATA(name,buffer,size) { (uint8_t *)(buffer), (uint8_t *)(buffer) + size, (uint8_t *)(buffer), (uint8_t *)(buffer), (size_t)0, false, NULL, NULL, _MUTEX_DATA(name.cmtx), _MUTEX_DATA(name.wmtx), _MUTEX_DATA(name.rmtx), }
+#define PIPE_DECL(name,buffer,size) pipe_t name = _PIPE_DATA(name, buffer, size)
+ void chPipeObjectInit(pipe_t *pp, uint8_t *buf, size_t n);
+ void chPipeReset(pipe_t *pp);
+ size_t chPipeWriteTimeout(pipe_t *pp, const uint8_t *bp,
+ size_t n, sysinterval_t timeout);
+ size_t chPipeReadTimeout(pipe_t *pp, uint8_t *bp,
+ size_t n, sysinterval_t timeout);
+static inline size_t chPipeGetSize(const pipe_t *pp) {
+ return (size_t)(pp->top - pp->buffer);
+}
+static inline size_t chPipeGetUsedCount(const pipe_t *pp) {
+ return pp->cnt;
+}
+static inline size_t chPipeGetFreeCount(const pipe_t *pp) {
+ return chPipeGetSize(pp) - chPipeGetUsedCount(pp);
+}
+static inline void chPipeResume(pipe_t *pp) {
+ pp->reset = false;
+}
+#define CHFACTORY_H
+#define CH_FACTORY_REQUIRES_POOLS ((CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE) || (CH_CFG_FACTORY_SEMAPHORES == TRUE))
+#define CH_FACTORY_REQUIRES_HEAP ((CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE) || (CH_CFG_FACTORY_MAILBOXES == TRUE) || (CH_CFG_FACTORY_OBJ_FIFOS == TRUE) || (CH_CFG_FACTORY_PIPES == TRUE))
+typedef struct ch_dyn_element {
+ struct ch_dyn_element *next;
+ ucnt_t refs;
+ char name[CH_CFG_FACTORY_MAX_NAMES_LENGTH];
+} dyn_element_t;
+typedef struct ch_dyn_list {
+ dyn_element_t *next;
+} dyn_list_t;
+typedef struct ch_registered_static_object {
+ dyn_element_t element;
+ void *objp;
+} registered_object_t;
+typedef struct ch_dyn_object {
+ dyn_element_t element;
+ uint8_t buffer[];
+} dyn_buffer_t;
+typedef struct ch_dyn_semaphore {
+ dyn_element_t element;
+ semaphore_t sem;
+} dyn_semaphore_t;
+typedef struct ch_dyn_mailbox {
+ dyn_element_t element;
+ mailbox_t mbx;
+ msg_t msgbuf[];
+} dyn_mailbox_t;
+typedef struct ch_dyn_objects_fifo {
+ dyn_element_t element;
+ objects_fifo_t fifo;
+ msg_t msgbuf[];
+} dyn_objects_fifo_t;
+typedef struct ch_dyn_pipe {
+ dyn_element_t element;
+ pipe_t pipe;
+ uint8_t buffer[];
+} dyn_pipe_t;
+typedef struct ch_objects_factory {
+ mutex_t mtx;
+ dyn_list_t obj_list;
+ memory_pool_t obj_pool;
+ dyn_list_t buf_list;
+ dyn_list_t sem_list;
+ memory_pool_t sem_pool;
+ dyn_list_t mbx_list;
+ dyn_list_t fifo_list;
+ dyn_list_t pipe_list;
+} objects_factory_t;
+extern objects_factory_t ch_factory;
+ void _factory_init(void);
+ registered_object_t *chFactoryRegisterObject(const char *name,
+ void *objp);
+ registered_object_t *chFactoryFindObject(const char *name);
+ registered_object_t *chFactoryFindObjectByPointer(void *objp);
+ void chFactoryReleaseObject(registered_object_t *rop);
+ dyn_buffer_t *chFactoryCreateBuffer(const char *name, size_t size);
+ dyn_buffer_t *chFactoryFindBuffer(const char *name);
+ void chFactoryReleaseBuffer(dyn_buffer_t *dbp);
+ dyn_semaphore_t *chFactoryCreateSemaphore(const char *name, cnt_t n);
+ dyn_semaphore_t *chFactoryFindSemaphore(const char *name);
+ void chFactoryReleaseSemaphore(dyn_semaphore_t *dsp);
+ dyn_mailbox_t *chFactoryCreateMailbox(const char *name, size_t n);
+ dyn_mailbox_t *chFactoryFindMailbox(const char *name);
+ void chFactoryReleaseMailbox(dyn_mailbox_t *dmp);
+ dyn_objects_fifo_t *chFactoryCreateObjectsFIFO(const char *name,
+ size_t objsize,
+ size_t objn,
+ unsigned objalign);
+ dyn_objects_fifo_t *chFactoryFindObjectsFIFO(const char *name);
+ void chFactoryReleaseObjectsFIFO(dyn_objects_fifo_t *dofp);
+ dyn_pipe_t *chFactoryCreatePipe(const char *name, size_t size);
+ dyn_pipe_t *chFactoryFindPipe(const char *name);
+ void chFactoryReleasePipe(dyn_pipe_t *dpp);
+static inline dyn_element_t *chFactoryDuplicateReference(dyn_element_t *dep) {
+ dep->refs++;
+ return dep;
+}
+static inline void *chFactoryGetObject(registered_object_t *rop) {
+ return rop->objp;
+}
+static inline size_t chFactoryGetBufferSize(dyn_buffer_t *dbp) {
+ return chHeapGetSize(dbp) - sizeof (dyn_element_t);
+}
+static inline uint8_t *chFactoryGetBuffer(dyn_buffer_t *dbp) {
+ return dbp->buffer;
+}
+static inline semaphore_t *chFactoryGetSemaphore(dyn_semaphore_t *dsp) {
+ return &dsp->sem;
+}
+static inline mailbox_t *chFactoryGetMailbox(dyn_mailbox_t *dmp) {
+ return &dmp->mbx;
+}
+static inline objects_fifo_t *chFactoryGetObjectsFIFO(dyn_objects_fifo_t *dofp) {
+ return &dofp->fifo;
+}
+static inline pipe_t *chFactoryGetPipe(dyn_pipe_t *dpp) {
+ return &dpp->pipe;
+}
+#define CHDYNAMIC_H
+ thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size,
+ const char *name, tprio_t prio,
+ tfunc_t pf, void *arg);
+ thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, const char *name,
+ tprio_t prio, tfunc_t pf, void *arg);
diff --git a/readme.txt b/readme.txt
index 707753ce6..b1ffc7e16 100644
--- a/readme.txt
+++ b/readme.txt
@@ -74,6 +74,10 @@
*****************************************************************************
*** 19.1.3 ***
+- NEW: Added a "library generator" project for RT, it allows to
+ generate a library with a pre-configured RT. It also includes
+ an "header generator" able to generate an unified "ch.h" with
+ all options resolved.
- FIX: Fixed long intervals fail when interval type is larger than time type
(bug #1031).
- FIX: Fixed Round Robin check missing when in tick-less mode (bug #1030).