add Chapter 15 - runtime observer implementation
This commit is contained in:
9
Chapter15/observer/.clang-format
Normal file
9
Chapter15/observer/.clang-format
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
IndentWidth: 4
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
BreakBeforeBraces: Allman
|
||||||
|
ColumnLimit: 80
|
||||||
|
SpaceBeforeParens: Never
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowShortFunctionsOnASingleLine: false
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
27
Chapter15/observer/.clang-tidy
Normal file
27
Chapter15/observer/.clang-tidy
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
Checks: >
|
||||||
|
-*,
|
||||||
|
bugprone-*,
|
||||||
|
misc-*,
|
||||||
|
clang-analyzer-*,
|
||||||
|
modernize-*,
|
||||||
|
-modernize-use-trailing-return-type,
|
||||||
|
performance-*,
|
||||||
|
-performance-no-int-to-ptr,
|
||||||
|
portability-*,
|
||||||
|
readability-*,
|
||||||
|
-readability-identifier-length
|
||||||
|
readability-identifier-naming
|
||||||
|
|
||||||
|
CheckOptions:
|
||||||
|
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
|
||||||
|
- { key: readability-identifier-naming.ClassCase, value: lower_case }
|
||||||
|
- { key: readability-identifier-naming.StructCase, value: lower_case }
|
||||||
|
- { key: readability-identifier-naming.MethodCase, value: lower_case }
|
||||||
|
- { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase }
|
||||||
|
- { key: readability-identifier-naming.FunctionCase, value: lower_case }
|
||||||
|
- { key: readability-identifier-naming.VariableCase, value: lower_case }
|
||||||
|
- { key: readability-identifier-naming.PrivateMemberSuffix, value: _ }
|
||||||
|
- { key: readability-identifier-naming.ConstexprVariablePrefix, value: c_ }
|
||||||
|
|
||||||
|
ExtraArgs:
|
||||||
|
- -std=c++20
|
||||||
162
Chapter15/observer/CMakeLists.txt
Normal file
162
Chapter15/observer/CMakeLists.txt
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.13)
|
||||||
|
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
|
||||||
|
|
||||||
|
set(CMAKE_C_COMPILER "arm-none-eabi-gcc")
|
||||||
|
set(CMAKE_CXX_COMPILER "arm-none-eabi-g++")
|
||||||
|
set(CMAKE_ASM_COMPILER "arm-none-eabi-gcc")
|
||||||
|
set(CMAKE_OBJCOPY "arm-none-eabi-objcopy")
|
||||||
|
set(CMAKE_SIZE "arm-none-eabi-size")
|
||||||
|
|
||||||
|
set(RENODE "renode" CACHE STRING "Path to Renode executable")
|
||||||
|
|
||||||
|
set(MAIN_CPP_PATH "${CMAKE_SOURCE_DIR}/app/src/")
|
||||||
|
set(MAIN_CPP_FILE_NAME "main_observer_rt.cpp" CACHE STRING "main file")
|
||||||
|
list(APPEND LIB_SPECS "-specs=nosys.specs")
|
||||||
|
list(APPEND LIB_SPECS "-specs=nano.specs")
|
||||||
|
|
||||||
|
set(EXCEPTIONS_FLAGS "-fno-exceptions -fno-rtti")
|
||||||
|
|
||||||
|
find_program(CCACHE_FOUND ccache)
|
||||||
|
if(CCACHE_FOUND)
|
||||||
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
|
||||||
|
endif(CCACHE_FOUND)
|
||||||
|
|
||||||
|
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||||
|
|
||||||
|
set(CDEFS "-DUSE_HAL_DRIVER -DSTM32F072xB")
|
||||||
|
set(MCU "-mcpu=cortex-m0 -mthumb")
|
||||||
|
set(COMMON_FLAGS "${MCU} ${CDEFS} -fdata-sections -ffunction-sections -Wno-address-of-packed-member -Wall -Wextra -Wno-unused-parameter")
|
||||||
|
set(CMAKE_C_FLAGS "${COMMON_FLAGS}")
|
||||||
|
set(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -Wno-register ${EXCEPTIONS_FLAGS} -fno-threadsafe-statics")
|
||||||
|
set(CMAKE_ASM_FLAGS "${COMMON_FLAGS} -x assembler-with-cpp")
|
||||||
|
|
||||||
|
set(CMAKE_C_FLAGS_DEBUG "-g -gdwarf-2 -Og")
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "-g -gdwarf-2 -Og")
|
||||||
|
set(CMAKE_C_FLAGS_RELEASE "-O2 -flto")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -flto")
|
||||||
|
set(CMAKE_C_FLAGS_MINSIZEREL "-Os -flto")
|
||||||
|
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -flto")
|
||||||
|
|
||||||
|
if(CMAKE_EXPORT_COMPILE_COMMANDS)
|
||||||
|
# This dreadful mess is to communicate to clang-tidy the C++ system includes.
|
||||||
|
# It seems that CMake doesn't support using its own compile_commands.json
|
||||||
|
# database, and that clang-tidy doesn't pick up non-default system headers.
|
||||||
|
execute_process(
|
||||||
|
COMMAND
|
||||||
|
bash -c
|
||||||
|
"${CMAKE_CXX_COMPILER} -x c++ -Wp,-v /dev/null 2>&1 > /dev/null | grep '^ /' | grep -w 'c++'"
|
||||||
|
OUTPUT_VARIABLE COMPILER_HEADERS
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
string(REGEX REPLACE "[ \n\t]+" ";" INCLUDE_COMPILER_HEADERS
|
||||||
|
${COMPILER_HEADERS})
|
||||||
|
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${INCLUDE_COMPILER_HEADERS})
|
||||||
|
message(STATUS "${CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES}")
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND
|
||||||
|
bash -c
|
||||||
|
"${CMAKE_C_COMPILER} -x c -Wp,-v /dev/null 2>&1 > /dev/null | grep '^ /' "
|
||||||
|
OUTPUT_VARIABLE COMPILER_HEADERS
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
string(REGEX REPLACE "[ \n\t]+" ";" INCLUDE_COMPILER_HEADERS
|
||||||
|
${COMPILER_HEADERS})
|
||||||
|
set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES ${INCLUDE_COMPILER_HEADERS})
|
||||||
|
message(STATUS "${CMAKE_C_STANDARD_INCLUDE_DIRECTORIES}")
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES
|
||||||
|
"${CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES} ${CMAKE_C_STANDARD_INCLUDE_DIRECTORIES}"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
project(bare VERSION 1.0.6)
|
||||||
|
|
||||||
|
enable_language(C CXX ASM)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
|
||||||
|
# global include directories
|
||||||
|
include_directories(
|
||||||
|
${CMAKE_SOURCE_DIR}/platform/inc
|
||||||
|
${CMAKE_SOURCE_DIR}/platform/CMSIS/Device/ST/STM32F0xx/Include
|
||||||
|
${CMAKE_SOURCE_DIR}/platform/CMSIS/Include
|
||||||
|
${CMAKE_SOURCE_DIR}/platform/STM32F0xx_HAL_Driver/Inc
|
||||||
|
${CMAKE_SOURCE_DIR}/app/inc
|
||||||
|
${CMAKE_SOURCE_DIR}/hal/uart/inc
|
||||||
|
${CMAKE_SOURCE_DIR}/hal/inc
|
||||||
|
${CMAKE_SOURCE_DIR}/hal/gpio/inc
|
||||||
|
${CMAKE_SOURCE_DIR}/hal/adc/inc
|
||||||
|
${CMAKE_SOURCE_DIR}/cstdlib_support
|
||||||
|
${CMAKE_SOURCE_DIR}/util/inc
|
||||||
|
)
|
||||||
|
|
||||||
|
set(EXECUTABLE ${PROJECT_NAME}.elf)
|
||||||
|
|
||||||
|
add_executable(
|
||||||
|
${EXECUTABLE}
|
||||||
|
platform/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c
|
||||||
|
platform/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_cortex.c
|
||||||
|
platform/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_gpio.c
|
||||||
|
platform/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc.c
|
||||||
|
platform/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_uart.c
|
||||||
|
platform/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_uart_ex.c
|
||||||
|
platform/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_adc.c
|
||||||
|
platform/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_adc_ex.c
|
||||||
|
platform/startup_stm32f072xb.s
|
||||||
|
platform/src/stm32f0xx_hal_msp.c
|
||||||
|
platform/src/stm32f0xx_it.c
|
||||||
|
platform/src/system_stm32f0xx.c
|
||||||
|
hal/gpio/src/gpio.cpp
|
||||||
|
hal/gpio/src/gpio_interrupt_manager.cpp
|
||||||
|
hal/adc/src/adc_stm32.cpp
|
||||||
|
cstdlib_support/retarget.cpp
|
||||||
|
util/src/units.cpp
|
||||||
|
${MAIN_CPP_PATH}/${MAIN_CPP_FILE_NAME}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${EXECUTABLE} PUBLIC)
|
||||||
|
|
||||||
|
target_include_directories(${EXECUTABLE} PUBLIC ${PROJECT_BINARY_DIR}
|
||||||
|
${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
|
set_target_properties(${EXECUTABLE} PROPERTIES LINKER_LANGUAGE CXX)
|
||||||
|
|
||||||
|
target_link_options(
|
||||||
|
${EXECUTABLE}
|
||||||
|
PUBLIC
|
||||||
|
-T${CMAKE_SOURCE_DIR}/platform/STM32F072C8Tx_FLASH.ld
|
||||||
|
-mcpu=cortex-m0
|
||||||
|
-mthumb
|
||||||
|
${LIB_SPECS}
|
||||||
|
-lnosys
|
||||||
|
-u
|
||||||
|
_printf_float
|
||||||
|
-lc
|
||||||
|
-lm
|
||||||
|
-Wl,--no-warn-rwx-segments
|
||||||
|
-Wl,-Map=${PROJECT_NAME}.map,--cref
|
||||||
|
-Wl,--gc-sections)
|
||||||
|
|
||||||
|
add_subdirectory(libs/etl)
|
||||||
|
target_link_libraries(${EXECUTABLE} PRIVATE etl::etl)
|
||||||
|
|
||||||
|
# Print executable size
|
||||||
|
add_custom_command(
|
||||||
|
TARGET ${EXECUTABLE}
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND arm-none-eabi-size ${EXECUTABLE})
|
||||||
|
|
||||||
|
# Create hex file
|
||||||
|
add_custom_command(
|
||||||
|
TARGET ${EXECUTABLE}
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND arm-none-eabi-objcopy -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex
|
||||||
|
COMMAND arm-none-eabi-objcopy -O binary ${EXECUTABLE} ${PROJECT_NAME}.bin)
|
||||||
|
|
||||||
|
# Run elf in Renode
|
||||||
|
add_custom_target(
|
||||||
|
run_in_renode
|
||||||
|
COMMAND ${RENODE} --console --disable-xwt ${CMAKE_SOURCE_DIR}/renode_scripts/stm32f072.resc -e start
|
||||||
|
DEPENDS ${PROJECT_NAME}.elf)
|
||||||
|
|
||||||
91
Chapter15/observer/app/src/main_observer_rt.cpp
Normal file
91
Chapter15/observer/app/src/main_observer_rt.cpp
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
#include <cstdint>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
#include <stm32f072xb.h>
|
||||||
|
|
||||||
|
#include <hal.hpp>
|
||||||
|
#include <stm32f0xx_hal_uart.hpp>
|
||||||
|
#include <uart_stm32.hpp>
|
||||||
|
|
||||||
|
#include <retarget.hpp>
|
||||||
|
|
||||||
|
#include "etl/vector.h"
|
||||||
|
|
||||||
|
class subscriber {
|
||||||
|
public:
|
||||||
|
virtual void update(float) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class display : public subscriber {
|
||||||
|
public:
|
||||||
|
void update(float temp) override {
|
||||||
|
printf("Displaying temperature %.2f \r\n", temp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class data_sender : public subscriber {
|
||||||
|
public:
|
||||||
|
void update(float temp) override {
|
||||||
|
printf("Sending temperature %.2f \r\n", temp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class logger : public subscriber {
|
||||||
|
public:
|
||||||
|
void update(float temp) override {
|
||||||
|
printf("Logging temperature %.2f \r\n", temp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class publisher {
|
||||||
|
public:
|
||||||
|
void register_sub(subscriber * sub) {
|
||||||
|
if(std::find(subs_.begin(), subs_.end(), sub) == subs_.end()) {
|
||||||
|
subs_.push_back(sub);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void unregister(subscriber * sub) {
|
||||||
|
if(auto it = std::find(subs_.begin(), subs_.end(), sub); it != subs_.end()) {
|
||||||
|
subs_.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void notify(float value) {
|
||||||
|
for(auto sub: subs_) {
|
||||||
|
sub->update(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
etl::vector<subscriber*, 8> subs_;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
hal::init();
|
||||||
|
|
||||||
|
hal::uart_stm32<hal::stm32::uart> uart(USART2);
|
||||||
|
uart.init();
|
||||||
|
|
||||||
|
retarget::set_stdio_uart(&uart);
|
||||||
|
|
||||||
|
logger temp_logger;
|
||||||
|
display temp_display;
|
||||||
|
data_sender temp_data_sender;
|
||||||
|
|
||||||
|
publisher temp_publisher;
|
||||||
|
temp_publisher.register_sub(&temp_logger);
|
||||||
|
temp_publisher.register_sub(&temp_display);
|
||||||
|
temp_publisher.notify(24.02f);
|
||||||
|
|
||||||
|
temp_publisher.unregister(&temp_logger);
|
||||||
|
temp_publisher.register_sub(&temp_data_sender);
|
||||||
|
temp_publisher.notify(44.02f);
|
||||||
|
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
81
Chapter15/observer/cstdlib_support/retarget.cpp
Normal file
81
Chapter15/observer/cstdlib_support/retarget.cpp
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
#include <retarget.hpp>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <span>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
hal::uart *uart_stdio;
|
||||||
|
};
|
||||||
|
|
||||||
|
void retarget::set_stdio_uart(hal::uart *uart)
|
||||||
|
{
|
||||||
|
uart_stdio = uart;
|
||||||
|
|
||||||
|
/* Disable I/O buffering for STDOUT stream, so that
|
||||||
|
* chars are sent out as soon as they are printed. */
|
||||||
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define STDIN_FILENO 0
|
||||||
|
#define STDOUT_FILENO 1
|
||||||
|
#define STDERR_FILENO 2
|
||||||
|
|
||||||
|
extern "C" int _write(int fd, char * ptr, int len)
|
||||||
|
{
|
||||||
|
if(fd == STDOUT_FILENO || fd == STDERR_FILENO)
|
||||||
|
{
|
||||||
|
uart_stdio->write(std::span<const char>(ptr, len));
|
||||||
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" int _isatty(int fd)
|
||||||
|
{
|
||||||
|
if(fd >= STDIN_FILENO && fd <= STDERR_FILENO)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
errno = EBADF;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" int _close(int fd)
|
||||||
|
{
|
||||||
|
if(fd >= STDIN_FILENO && fd <= STDERR_FILENO)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
errno = EBADF;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" int _lseek(int fd, int ptr, int dir)
|
||||||
|
{
|
||||||
|
(void)fd;
|
||||||
|
(void)ptr;
|
||||||
|
(void)dir;
|
||||||
|
|
||||||
|
errno = EBADF;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" int _read(int fd, char *ptr, int len)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _fstat(int fd, struct stat *st)
|
||||||
|
{
|
||||||
|
if(fd >= STDIN_FILENO && fd <= STDERR_FILENO)
|
||||||
|
{
|
||||||
|
st->st_mode = S_IFCHR;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
errno = EBADF;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
10
Chapter15/observer/cstdlib_support/retarget.hpp
Normal file
10
Chapter15/observer/cstdlib_support/retarget.hpp
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <uart.hpp>
|
||||||
|
|
||||||
|
namespace retarget
|
||||||
|
{
|
||||||
|
|
||||||
|
void set_stdio_uart(hal::uart *uart);
|
||||||
|
|
||||||
|
};
|
||||||
18
Chapter15/observer/hal/adc/inc/adc.hpp
Normal file
18
Chapter15/observer/hal/adc/inc/adc.hpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <expected>
|
||||||
|
|
||||||
|
#include <units.hpp>
|
||||||
|
|
||||||
|
namespace hal
|
||||||
|
{
|
||||||
|
class adc {
|
||||||
|
public:
|
||||||
|
enum class error {
|
||||||
|
timeout
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual void init() = 0;
|
||||||
|
virtual std::expected<units::voltage, adc::error> get_reading() = 0;
|
||||||
|
};
|
||||||
|
};
|
||||||
22
Chapter15/observer/hal/adc/inc/adc_stm32.hpp
Normal file
22
Chapter15/observer/hal/adc/inc/adc_stm32.hpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <adc.hpp>
|
||||||
|
#include <units.hpp>
|
||||||
|
|
||||||
|
#include <stm32f0xx_hal.h>
|
||||||
|
#include <stm32f072xb.h>
|
||||||
|
|
||||||
|
namespace hal
|
||||||
|
{
|
||||||
|
|
||||||
|
class adc_stm32 : public adc{
|
||||||
|
public:
|
||||||
|
adc_stm32(units::voltage ref_voltage) : ref_voltage_(ref_voltage) {}
|
||||||
|
|
||||||
|
void init() override;
|
||||||
|
std::expected<units::voltage, adc::error> get_reading() override;
|
||||||
|
private:
|
||||||
|
ADC_HandleTypeDef adc_handle_;
|
||||||
|
units::voltage ref_voltage_;
|
||||||
|
};
|
||||||
|
};
|
||||||
47
Chapter15/observer/hal/adc/src/adc_stm32.cpp
Normal file
47
Chapter15/observer/hal/adc/src/adc_stm32.cpp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#include <adc_stm32.hpp>
|
||||||
|
|
||||||
|
void hal::adc_stm32::init() {
|
||||||
|
ADC_ChannelConfTypeDef sConfig = {0};
|
||||||
|
|
||||||
|
/** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
|
||||||
|
*/
|
||||||
|
adc_handle_.Instance = ADC1;
|
||||||
|
adc_handle_.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
|
||||||
|
adc_handle_.Init.Resolution = ADC_RESOLUTION_12B;
|
||||||
|
adc_handle_.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||||
|
adc_handle_.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
|
||||||
|
adc_handle_.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
|
||||||
|
adc_handle_.Init.LowPowerAutoWait = DISABLE;
|
||||||
|
adc_handle_.Init.LowPowerAutoPowerOff = DISABLE;
|
||||||
|
adc_handle_.Init.ContinuousConvMode = DISABLE;
|
||||||
|
adc_handle_.Init.DiscontinuousConvMode = DISABLE;
|
||||||
|
adc_handle_.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||||
|
adc_handle_.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
||||||
|
adc_handle_.Init.DMAContinuousRequests = DISABLE;
|
||||||
|
adc_handle_.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
||||||
|
if (HAL_ADC_Init(&adc_handle_) != HAL_OK)
|
||||||
|
{
|
||||||
|
//Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Configure for the selected ADC regular channel to be converted.
|
||||||
|
*/
|
||||||
|
sConfig.Channel = ADC_CHANNEL_0;
|
||||||
|
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
|
||||||
|
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
|
||||||
|
if (HAL_ADC_ConfigChannel(&adc_handle_, &sConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
//Error_Handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::expected<units::voltage, hal::adc::error> hal::adc_stm32::get_reading() {
|
||||||
|
HAL_ADC_Start(&adc_handle_);
|
||||||
|
if(HAL_ADC_PollForConversion(&adc_handle_, 1000) != HAL_OK) {
|
||||||
|
return std::unexpected(hal::adc::error::timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto adc_val = HAL_ADC_GetValue(&adc_handle_);
|
||||||
|
|
||||||
|
return ref_voltage_ * adc_val / 4096.f;
|
||||||
|
}
|
||||||
19
Chapter15/observer/hal/gpio/inc/gpio.hpp
Normal file
19
Chapter15/observer/hal/gpio/inc/gpio.hpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
namespace hal
|
||||||
|
{
|
||||||
|
class gpio
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
gpio(const std::function<void()> & on_press = nullptr);
|
||||||
|
void execute_interrupt_handler() const;
|
||||||
|
|
||||||
|
[[nodiscard]] virtual bool is_interrupt_generated() const = 0;
|
||||||
|
virtual void clear_interrupt_flag() const = 0;
|
||||||
|
private:
|
||||||
|
std::function<void()> on_press_;
|
||||||
|
};
|
||||||
|
}; // namespace hal
|
||||||
19
Chapter15/observer/hal/gpio/inc/gpio_interrupt_manager.hpp
Normal file
19
Chapter15/observer/hal/gpio/inc/gpio_interrupt_manager.hpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include <gpio.hpp>
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
|
||||||
|
struct gpio_interrupt_manager {
|
||||||
|
static void register_interrupt_handler(gpio * pin);
|
||||||
|
|
||||||
|
static void execute_interrupt_handlers();
|
||||||
|
|
||||||
|
static constexpr std::size_t c_gpio_handlers_num = 16;
|
||||||
|
static inline std::array<gpio*, c_gpio_handlers_num> gpio_handlers{};
|
||||||
|
static inline std::size_t w_idx = 0;
|
||||||
|
};
|
||||||
|
};
|
||||||
70
Chapter15/observer/hal/gpio/inc/gpio_stm32.hpp
Normal file
70
Chapter15/observer/hal/gpio/inc/gpio_stm32.hpp
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
#include <gpio.hpp>
|
||||||
|
|
||||||
|
#include <stm32f072xb.h>
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
|
||||||
|
enum class pin : uint16_t {
|
||||||
|
p_invalid = 0,
|
||||||
|
p0 = 0x0001U,
|
||||||
|
p1 = 0x0002U,
|
||||||
|
p2 = 0x0004U,
|
||||||
|
p3 = 0x0008U,
|
||||||
|
p4 = 0x0010U,
|
||||||
|
p5 = 0x0020U,
|
||||||
|
p6 = 0x0040U,
|
||||||
|
p7 = 0x0080U,
|
||||||
|
p8 = 0x0100U,
|
||||||
|
p9 = 0x0200U,
|
||||||
|
p10 = 0x0400U,
|
||||||
|
p11 = 0x0800U,
|
||||||
|
p12 = 0x1000U,
|
||||||
|
p13 = 0x2000U,
|
||||||
|
p14 = 0x4000U,
|
||||||
|
p15 = 0x8000U,
|
||||||
|
all = 0xFFFFU
|
||||||
|
};
|
||||||
|
|
||||||
|
struct port_a {
|
||||||
|
static constexpr uint8_t c_pin_num = 16;
|
||||||
|
static inline GPIO_TypeDef * port = reinterpret_cast<GPIO_TypeDef*>(GPIOA);
|
||||||
|
static void init_clock () {
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Port>
|
||||||
|
class gpio_stm32 : public gpio {
|
||||||
|
public:
|
||||||
|
gpio_stm32(pin the_pin, const std::function<void()> & on_press = nullptr)
|
||||||
|
: gpio(on_press), the_pin_(the_pin) {
|
||||||
|
Port::init_clock();
|
||||||
|
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct { static_cast<uint16_t>(the_pin),
|
||||||
|
GPIO_MODE_IT_RISING,
|
||||||
|
GPIO_NOPULL,
|
||||||
|
GPIO_SPEED_FREQ_LOW,
|
||||||
|
0 };
|
||||||
|
HAL_GPIO_Init(Port::port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
if(on_press) {
|
||||||
|
enable_interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool is_interrupt_generated() const override {
|
||||||
|
return __HAL_GPIO_EXTI_GET_IT(static_cast<uint16_t>(the_pin_));
|
||||||
|
}
|
||||||
|
void clear_interrupt_flag() const override {
|
||||||
|
__HAL_GPIO_EXTI_CLEAR_IT(static_cast<uint16_t>(the_pin_));
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
pin the_pin_ = pin::p_invalid;
|
||||||
|
|
||||||
|
void enable_interrupt() {
|
||||||
|
// TODO: check EXTI line macro according to pin used
|
||||||
|
HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
21
Chapter15/observer/hal/gpio/src/gpio.cpp
Normal file
21
Chapter15/observer/hal/gpio/src/gpio.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#include <gpio.hpp>
|
||||||
|
#include <gpio_interrupt_manager.hpp>
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
|
||||||
|
gpio::gpio(const std::function<void()> & on_press) {
|
||||||
|
on_press_ = on_press;
|
||||||
|
gpio_interrupt_manager::register_interrupt_handler(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gpio::execute_interrupt_handler () const {
|
||||||
|
if(is_interrupt_generated())
|
||||||
|
{
|
||||||
|
clear_interrupt_flag();
|
||||||
|
if(on_press_) {
|
||||||
|
on_press_();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
17
Chapter15/observer/hal/gpio/src/gpio_interrupt_manager.cpp
Normal file
17
Chapter15/observer/hal/gpio/src/gpio_interrupt_manager.cpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#include <gpio_interrupt_manager.hpp>
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
|
||||||
|
void gpio_interrupt_manager::register_interrupt_handler(gpio * pin) {
|
||||||
|
gpio_handlers.at(w_idx++) = pin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gpio_interrupt_manager::execute_interrupt_handlers() {
|
||||||
|
for(std::size_t i = 0; i < w_idx; i++) {
|
||||||
|
gpio_handlers[i]->execute_interrupt_handler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
extern "C" void EXTI4_15_IRQHandler(void) {
|
||||||
|
gpio_interrupt_manager::execute_interrupt_handlers();
|
||||||
|
}
|
||||||
|
};
|
||||||
33
Chapter15/observer/hal/inc/hal.hpp
Normal file
33
Chapter15/observer/hal/inc/hal.hpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include <stm32f0xx_hal.h>
|
||||||
|
|
||||||
|
namespace hal
|
||||||
|
{
|
||||||
|
inline void init()
|
||||||
|
{
|
||||||
|
HAL_Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::uint32_t get_pc()
|
||||||
|
{
|
||||||
|
std::uint32_t pc;
|
||||||
|
__asm volatile ("mov %0, pc" : "=r" (pc) );
|
||||||
|
return pc;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct time
|
||||||
|
{
|
||||||
|
static std::uint32_t get_ms()
|
||||||
|
{
|
||||||
|
return HAL_GetTick();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void delay_ms(uint32_t delay)
|
||||||
|
{
|
||||||
|
HAL_Delay(delay);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}; // namespace hal
|
||||||
21
Chapter15/observer/hal/uart/inc/stm32f0xx_hal_uart.hpp
Normal file
21
Chapter15/observer/hal/uart/inc/stm32f0xx_hal_uart.hpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stm32f0xx_hal.h>
|
||||||
|
#include <stm32f072xb.h>
|
||||||
|
|
||||||
|
namespace hal::stm32{
|
||||||
|
struct uart {
|
||||||
|
uart() = delete;
|
||||||
|
|
||||||
|
static inline HAL_StatusTypeDef init(UART_HandleTypeDef *huart) {
|
||||||
|
return HAL_UART_Init(huart);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline HAL_StatusTypeDef transmit(UART_HandleTypeDef *huart,
|
||||||
|
uint8_t *pData,
|
||||||
|
uint16_t Size,
|
||||||
|
uint32_t Timeout) {
|
||||||
|
return HAL_UART_Transmit(huart, pData, Size, Timeout);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
14
Chapter15/observer/hal/uart/inc/uart.hpp
Normal file
14
Chapter15/observer/hal/uart/inc/uart.hpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <span>
|
||||||
|
|
||||||
|
namespace hal
|
||||||
|
{
|
||||||
|
class uart
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void init(std::uint32_t baudrate) = 0;
|
||||||
|
virtual void write(std::span<const char> data) = 0;
|
||||||
|
};
|
||||||
|
}; // namespace hal
|
||||||
46
Chapter15/observer/hal/uart/inc/uart_stm32.hpp
Normal file
46
Chapter15/observer/hal/uart/inc/uart_stm32.hpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <span>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include <uart.hpp>
|
||||||
|
|
||||||
|
#include <stm32f0xx_hal_uart.hpp>
|
||||||
|
|
||||||
|
namespace hal
|
||||||
|
{
|
||||||
|
template <typename HalUart>
|
||||||
|
class uart_stm32 : public uart
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
uart_stm32(USART_TypeDef *inst) : instance_(inst) {}
|
||||||
|
|
||||||
|
void init(std::uint32_t baudrate = c_baudrate_default) override {
|
||||||
|
huart_.Instance = instance_;
|
||||||
|
huart_.Init.BaudRate = baudrate;
|
||||||
|
huart_.Init.WordLength = UART_WORDLENGTH_8B;
|
||||||
|
huart_.Init.StopBits = UART_STOPBITS_1;
|
||||||
|
huart_.Init.Parity = UART_PARITY_NONE;
|
||||||
|
huart_.Init.Mode = UART_MODE_TX_RX;
|
||||||
|
huart_.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||||
|
huart_.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||||
|
huart_.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
||||||
|
huart_.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
||||||
|
// TODO: add GPIO initialization for real hardware
|
||||||
|
huart_.MspInitCallback = nullptr;
|
||||||
|
HalUart::init(&huart_);
|
||||||
|
}
|
||||||
|
void write(std::span<const char> data) override {
|
||||||
|
// we must cast away costness due to ST HAL's API
|
||||||
|
char * data_ptr = const_cast<char *>(data.data());
|
||||||
|
HalUart::transmit(&huart_, reinterpret_cast<uint8_t *>(data_ptr), data.size(),
|
||||||
|
HAL_MAX_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
UART_HandleTypeDef huart_;
|
||||||
|
USART_TypeDef *instance_;
|
||||||
|
std::uint32_t baudrate_;
|
||||||
|
static constexpr std::uint32_t c_baudrate_default = 115200;
|
||||||
|
};
|
||||||
|
}; // namespace hal
|
||||||
34
Chapter15/observer/hal/uart/src/uart_stm32.cpp
Normal file
34
Chapter15/observer/hal/uart/src/uart_stm32.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#include <uart_stm32.hpp>
|
||||||
|
|
||||||
|
template <typename HalUart>
|
||||||
|
hal::uart_stm32<HalUart>::uart_stm32(USART_TypeDef *inst)
|
||||||
|
: instance_(inst)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename HalUart>
|
||||||
|
void hal::uart_stm32<HalUart>::init(std::uint32_t baudrate)
|
||||||
|
{
|
||||||
|
huart_.Instance = instance_;
|
||||||
|
huart_.Init.BaudRate = baudrate;
|
||||||
|
huart_.Init.WordLength = UART_WORDLENGTH_8B;
|
||||||
|
huart_.Init.StopBits = UART_STOPBITS_1;
|
||||||
|
huart_.Init.Parity = UART_PARITY_NONE;
|
||||||
|
huart_.Init.Mode = UART_MODE_TX_RX;
|
||||||
|
huart_.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||||
|
huart_.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||||
|
huart_.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
||||||
|
huart_.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
||||||
|
// TODO: add GPIO initialization for real hardware
|
||||||
|
huart_.MspInitCallback = nullptr;
|
||||||
|
HalUart::init(&huart_);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename HalUart>
|
||||||
|
void hal::uart_stm32<HalUart>::write(std::span<const char> data)
|
||||||
|
{
|
||||||
|
// we must cast away costness due to ST HAL's API
|
||||||
|
char * data_ptr = const_cast<char *>(data.data());
|
||||||
|
HalUart::transmit(&huart_, reinterpret_cast<uint8_t *>(data_ptr), data.size(),
|
||||||
|
HAL_MAX_DELAY);
|
||||||
|
}
|
||||||
51
Chapter15/observer/libs/etl/.clang-format
Normal file
51
Chapter15/observer/libs/etl/.clang-format
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
---
|
||||||
|
#------------------------------------
|
||||||
|
# Configuration for clang-format v12
|
||||||
|
#------------------------------------
|
||||||
|
|
||||||
|
Language: Cpp
|
||||||
|
|
||||||
|
SortIncludes: true
|
||||||
|
|
||||||
|
BasedOnStyle: Chromium
|
||||||
|
|
||||||
|
BinPackParameters: false
|
||||||
|
BitFieldColonSpacing: Both
|
||||||
|
|
||||||
|
BreakBeforeBraces: Allman
|
||||||
|
BreakConstructorInitializers: BeforeComma
|
||||||
|
|
||||||
|
AllowShortBlocksOnASingleLine: false
|
||||||
|
AllowShortCaseLabelsOnASingleLine: true
|
||||||
|
AllowShortFunctionsOnASingleLine: None
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
|
||||||
|
AllowAllArgumentsOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
|
||||||
|
ConstructorInitializerIndentWidth: '2'
|
||||||
|
|
||||||
|
NamespaceIndentation: All
|
||||||
|
IndentPPDirectives: BeforeHash
|
||||||
|
PointerAlignment: Left
|
||||||
|
ColumnLimit: '0'
|
||||||
|
ContinuationIndentWidth: '2'
|
||||||
|
UseTab: Never
|
||||||
|
TabWidth: '2'
|
||||||
|
IndentWidth: '2'
|
||||||
|
AccessModifierOffset : '-2'
|
||||||
|
IndentCaseLabels: false
|
||||||
|
Cpp11BracedListStyle: 'true'
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignConsecutiveDeclarations: true
|
||||||
|
|
||||||
|
#------------------------------------
|
||||||
|
# Configurations not supported by clang-format v12
|
||||||
|
#------------------------------------
|
||||||
|
# BreakInheritanceList: AfterComma
|
||||||
|
# EmptyLineBeforeAccessModifier: Always
|
||||||
|
# EmptyLineAfterAccessModifier: Always
|
||||||
|
# ReferenceAlignment: Left
|
||||||
|
|
||||||
|
...
|
||||||
82
Chapter15/observer/libs/etl/CMakeLists.txt
Normal file
82
Chapter15/observer/libs/etl/CMakeLists.txt
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#######################################################################
|
||||||
|
# The Embedded Template Library (https://www.etlcpp.com/)
|
||||||
|
#######################################################################
|
||||||
|
cmake_minimum_required(VERSION 3.5.0)
|
||||||
|
|
||||||
|
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/helpers.cmake)
|
||||||
|
|
||||||
|
set(MSG_PREFIX "etl |")
|
||||||
|
determine_version_with_git(${GIT_DIR_LOOKUP_POLICY})
|
||||||
|
if(NOT ETL_VERSION)
|
||||||
|
determine_version_with_file("version.txt")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
project(etl VERSION ${ETL_VERSION} LANGUAGES CXX)
|
||||||
|
|
||||||
|
option(BUILD_TESTS "Build unit tests" OFF)
|
||||||
|
option(NO_STL "No STL" OFF)
|
||||||
|
# There is a bug on old gcc versions for some targets that causes all system headers
|
||||||
|
# to be implicitly wrapped with 'extern "C"'
|
||||||
|
# Users can add set(NO_SYSTEM_INCLUDE ON) to their top level CMakeLists.txt to work around this.
|
||||||
|
option(NO_SYSTEM_INCLUDE "Do not include with -isystem" OFF)
|
||||||
|
if (NO_SYSTEM_INCLUDE)
|
||||||
|
set(INCLUDE_SPECIFIER "")
|
||||||
|
else()
|
||||||
|
set(INCLUDE_SPECIFIER "SYSTEM")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_library(${PROJECT_NAME} INTERFACE)
|
||||||
|
# This allows users which use the add_subdirectory or FetchContent
|
||||||
|
# to use the same target as users which use find_package
|
||||||
|
add_library(etl::etl ALIAS ${PROJECT_NAME})
|
||||||
|
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
target_include_directories(${PROJECT_NAME} ${INCLUDE_SPECIFIER} INTERFACE
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${PROJECT_NAME} INTERFACE)
|
||||||
|
|
||||||
|
# only install if top level project
|
||||||
|
if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
|
||||||
|
# Steps here based on excellent guide: https://dominikberner.ch/cmake-interface-lib/
|
||||||
|
# Which also details all steps
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
install(TARGETS ${PROJECT_NAME}
|
||||||
|
EXPORT ${PROJECT_NAME}Targets
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
)
|
||||||
|
if(ETL_VERSION)
|
||||||
|
# Generate the package configuration files using CMake provided macros
|
||||||
|
write_basic_package_version_file(
|
||||||
|
"${PROJECT_NAME}ConfigVersion.cmake"
|
||||||
|
COMPATIBILITY SameMajorVersion
|
||||||
|
ARCH_INDEPENDENT
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
configure_package_config_file(
|
||||||
|
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
|
||||||
|
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||||
|
INSTALL_DESTINATION
|
||||||
|
${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
|
||||||
|
|
||||||
|
# Install target file, then package configuration files, and finally the headers
|
||||||
|
install(EXPORT ${PROJECT_NAME}Targets
|
||||||
|
FILE ${PROJECT_NAME}Targets.cmake
|
||||||
|
NAMESPACE ${PROJECT_NAME}::
|
||||||
|
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
|
||||||
|
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||||
|
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
||||||
|
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
|
||||||
|
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/etl DESTINATION include)
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (BUILD_TESTS)
|
||||||
|
enable_testing()
|
||||||
|
add_subdirectory(test)
|
||||||
|
endif()
|
||||||
2401
Chapter15/observer/libs/etl/Doxyfile
Normal file
2401
Chapter15/observer/libs/etl/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
19
Chapter15/observer/libs/etl/LICENSE
Normal file
19
Chapter15/observer/libs/etl/LICENSE
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
147
Chapter15/observer/libs/etl/README.md
Normal file
147
Chapter15/observer/libs/etl/README.md
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
Embedded Template Library (ETL)
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|

|
||||||
|
[](https://img.shields.io/github/release-date/jwellbelove/etl?color=%231182c3)
|
||||||
|
[](https://en.wikipedia.org/wiki/C%2B%2B#Standardization)
|
||||||
|
[](https://opensource.org/licenses/MIT)
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
[](https://ci.appveyor.com/project/jwellbelove/etl/branch/master)
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
[](https://www.codacy.com/manual/jwellbelove/etl?utm_source=github.com&utm_medium=referral&utm_content=ETLCPP/etl&utm_campaign=Badge_Grade)
|
||||||
|
|
||||||
|
[](https://www.etlcpp.com/sponsor.html)
|
||||||
|
|
||||||
|
[Project documentation](https://www.etlcpp.com/)
|
||||||
|
|
||||||
|
## Motivation
|
||||||
|
|
||||||
|
C++ is a great language to use for embedded applications and templates are a powerful aspect. The standard library can offer a great deal of well tested functionality, but there are some parts of the standard library that do not fit well with deterministic behaviour and limited resource requirements. These limitations usually preclude the use of dynamically allocated memory and containers with open ended sizes.
|
||||||
|
|
||||||
|
What is needed is a template library where the user can declare the size, or maximum size of any object upfront. Most embedded compilers do not currently support the standard beyond C++ 03, therefore excluding the programmer from using the enhanced features of the later library.
|
||||||
|
|
||||||
|
This is what the ETL attempts to achieve.
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
The ETL is not designed to completely replace the STL, but complement it.
|
||||||
|
Its design objective covers three areas.
|
||||||
|
|
||||||
|
- Create a set of containers where the size or maximum size is determined at compile time. These containers are direct equivalents of those supplied in the STL.
|
||||||
|
- Be compatible with C++ 03 but implement as many of the C++ 11/14/17/20 additions as possible.
|
||||||
|
- Add other useful components that are not present in the standard library.
|
||||||
|
|
||||||
|
The embedded template library has been designed for lower resource embedded applications.
|
||||||
|
It contains a set of containers, algorithms and utilities, some of which emulate parts of the STL.
|
||||||
|
There is no dynamic memory allocation. The library makes no use of the heap. All of the containers have a fixed capacity allowing all memory allocation to be determined at compile time.
|
||||||
|
The library is intended for any compiler that supports C++98/03/11/14/17/20.
|
||||||
|
|
||||||
|
## Main features
|
||||||
|
|
||||||
|
- Cross platform. This library is not specific to any processor type.
|
||||||
|
- No dynamic memory allocation
|
||||||
|
- No RTTI required
|
||||||
|
- Very little use of virtual functions. They are used only when they are absolutely necessary for the required functionality
|
||||||
|
- A set of fixed capacity containers. (array, bitset, deque, forward_list, list, queue, stack, vector, map, set, etc.)
|
||||||
|
- As the storage for all of the container types is allocated as a contiguous block, they are extremely cache friendly
|
||||||
|
- Templated compile time constants
|
||||||
|
- Templated design pattern base classes (Visitor, Observer)
|
||||||
|
- Reverse engineered C++ 0x11 features (type traits, algorithms, containers etc.)
|
||||||
|
- Type-safe enumerations
|
||||||
|
- Type-safe typedefs
|
||||||
|
- 8, 16, 32 & 64 bit CRC calculations
|
||||||
|
- Checksums & hash functions
|
||||||
|
- Variants (a type that can store many types in a type-safe interface)
|
||||||
|
- Choice of asserts, exceptions, error handler or no checks on errors
|
||||||
|
- Unit tested (currently over 9400 tests), using VS2022, GCC 12, Clang 14.
|
||||||
|
- Many utilities for template support.
|
||||||
|
- Easy to read and documented source.
|
||||||
|
- Free support via email, GitHub and Slack
|
||||||
|
|
||||||
|
Any help porting the library to work under different platforms and compilers would be gratefully received.
|
||||||
|
I am especially interested in people who are using Keil, IAR, Green Hills, TI Code Composer etc, bare metal or RTOS, and DSPs.
|
||||||
|
|
||||||
|
See (https://www.etlcpp.com) for up-to-date information.
|
||||||
|
|
||||||
|
## Installing this library
|
||||||
|
|
||||||
|
You can find the setup steps [here](https://www.etlcpp.com/setup.html).
|
||||||
|
|
||||||
|
### CMake
|
||||||
|
|
||||||
|
One way to use this library is to drop it somewhere in your project directory
|
||||||
|
and then make the library available by using `add_subdirectory`
|
||||||
|
|
||||||
|
```cmake
|
||||||
|
add_subdirectory(etl)
|
||||||
|
add_executable(foo main.cpp)
|
||||||
|
target_link_libraries(foo PRIVATE etl::etl)
|
||||||
|
```
|
||||||
|
|
||||||
|
If ETL library is used as a Git submodule it may require additional configuration for proper ETL version resolution by allowing the lookup for Git folder outside of the library root directory.
|
||||||
|
|
||||||
|
```cmake
|
||||||
|
set(GIT_DIR_LOOKUP_POLICY ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR)
|
||||||
|
add_subdirectory(etl)
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to install this library with CMake, you can perform the following steps. On Linux,
|
||||||
|
super user rights might be required to install the library, so it might be necessary to add
|
||||||
|
`sudo` before the last command:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git clone https://github.com/ETLCPP/etl.git
|
||||||
|
cd etl
|
||||||
|
git checkout <targetVersion>
|
||||||
|
cmake -B build .
|
||||||
|
cmake --install build/
|
||||||
|
```
|
||||||
|
|
||||||
|
After the library has been installed, you can use
|
||||||
|
[find_package](https://cmake.org/cmake/help/latest/command/find_package.html) to use the library.
|
||||||
|
Replace `<majorVersionRequirement>` with your desired major version:
|
||||||
|
|
||||||
|
```cmake
|
||||||
|
find_package(etl <majorVersionRequirement>)
|
||||||
|
add_executable(foo main.cpp)
|
||||||
|
target_link_libraries(foo PRIVATE etl::etl)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Alternatively you can use [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html),
|
||||||
|
replacing `<targetVersion>` with the version to install based on a git tag:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
Include(FetchContent)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
etl
|
||||||
|
GIT_REPOSITORY https://github.com/ETLCPP/etl
|
||||||
|
GIT_TAG <targetVersion>
|
||||||
|
)
|
||||||
|
|
||||||
|
FetchContent_MakeAvailable(etl)
|
||||||
|
|
||||||
|
add_executable(foo main.cpp)
|
||||||
|
target_link_libraries(foo PRIVATE etl::etl)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Arduino library
|
||||||
|
|
||||||
|
The content of this repo is available as a library in the Arduino IDE (search for the "Embedded Template Library" in the IDE library manager). The Arduino library repository is available at ```https://github.com/ETLCPP/etl-arduino```, see there for more details.
|
||||||
26
Chapter15/observer/libs/etl/appveyor.yml
Normal file
26
Chapter15/observer/libs/etl/appveyor.yml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
version: 1.0.{build}
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
image: Visual Studio 2022
|
||||||
|
configuration:
|
||||||
|
- Debug MSVC C++14
|
||||||
|
- Debug MSVC C++14 - No STL
|
||||||
|
- Debug MSVC C++17
|
||||||
|
- Debug MSVC C++17 - No STL
|
||||||
|
- Debug MSVC C++20
|
||||||
|
- Debug MSVC C++20 - No STL
|
||||||
|
clone_folder: c:\projects\etl
|
||||||
|
install:
|
||||||
|
- cmd: git submodule update --init --recursive
|
||||||
|
build:
|
||||||
|
project: test/vs2022/etl.vcxproj
|
||||||
|
verbosity: minimal
|
||||||
|
notifications:
|
||||||
|
- provider: Webhook
|
||||||
|
url: https://hooks.slack.com/services/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
|
||||||
|
method: POST
|
||||||
|
on_build_success: true
|
||||||
|
on_build_failure: true
|
||||||
|
on_build_status_changed: true
|
||||||
|
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
|
||||||
|
#ifndef ETL_EMBEDDED_TEMPLATE_LIBRARY_INCLUDED
|
||||||
|
#define ETL_EMBEDDED_TEMPLATE_LIBRARY_INCLUDED
|
||||||
|
|
||||||
|
#if defined(TEENSYDUINO)
|
||||||
|
|
||||||
|
#if defined(__AVR_ATmega32U4__)
|
||||||
|
#define ARDUINO_BOARD "Teensy 2.0"
|
||||||
|
#elif defined(__AVR_AT90USB1286__)
|
||||||
|
#define ARDUINO_BOARD "Teensy++ 2.0"
|
||||||
|
#elif defined(__MK20DX128__)
|
||||||
|
#define ARDUINO_BOARD "Teensy 3.0"
|
||||||
|
#elif defined(__MK20DX256__)
|
||||||
|
#define ARDUINO_BOARD "Teensy 3.2" // and Teensy 3.1
|
||||||
|
#elif defined(__MKL26Z64__)
|
||||||
|
#define ARDUINO_BOARD "Teensy LC"
|
||||||
|
#elif defined(__MK64FX512__)
|
||||||
|
#define ARDUINO_BOARD "Teensy 3.5"
|
||||||
|
#elif defined(__MK66FX1M0__)
|
||||||
|
#define ARDUINO_BOARD "Teensy 3.6"
|
||||||
|
#else
|
||||||
|
#define ARDUINO_BOARD "Unknown"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else // --------------- Arduino ------------------
|
||||||
|
|
||||||
|
#if defined(ARDUINO_AVR_ADK)
|
||||||
|
#define ARDUINO_BOARD "Mega Adk"
|
||||||
|
#elif defined(ARDUINO_AVR_BT)
|
||||||
|
#define ARDUINO_BOARD "Bt"
|
||||||
|
#elif defined(ARDUINO_AVR_DUEMILANOVE)
|
||||||
|
#define ARDUINO_BOARD "Duemilanove"
|
||||||
|
#elif defined(ARDUINO_AVR_ESPLORA)
|
||||||
|
#define ARDUINO_BOARD "Esplora"
|
||||||
|
#elif defined(ARDUINO_AVR_ETHERNET)
|
||||||
|
#define ARDUINO_BOARD "Ethernet"
|
||||||
|
#elif defined(ARDUINO_AVR_FIO)
|
||||||
|
#define ARDUINO_BOARD "Fio"
|
||||||
|
#elif defined(ARDUINO_AVR_GEMMA)
|
||||||
|
#define ARDUINO_BOARD "Gemma"
|
||||||
|
#elif defined(ARDUINO_AVR_LEONARDO)
|
||||||
|
#define ARDUINO_BOARD "Leonardo"
|
||||||
|
#elif defined(ARDUINO_AVR_LILYPAD)
|
||||||
|
#define ARDUINO_BOARD "Lilypad"
|
||||||
|
#elif defined(ARDUINO_AVR_LILYPAD_USB)
|
||||||
|
#define ARDUINO_BOARD "Lilypad Usb"
|
||||||
|
#elif defined(ARDUINO_AVR_MEGA)
|
||||||
|
#define ARDUINO_BOARD "Mega"
|
||||||
|
#elif defined(ARDUINO_AVR_MEGA2560)
|
||||||
|
#define ARDUINO_BOARD "Mega 2560"
|
||||||
|
#elif defined(ARDUINO_AVR_MICRO)
|
||||||
|
#define ARDUINO_BOARD "Micro"
|
||||||
|
#elif defined(ARDUINO_AVR_MINI)
|
||||||
|
#define ARDUINO_BOARD "Mini"
|
||||||
|
#elif defined(ARDUINO_AVR_NANO)
|
||||||
|
#define ARDUINO_BOARD "Nano"
|
||||||
|
#elif defined(ARDUINO_AVR_NG)
|
||||||
|
#define ARDUINO_BOARD "NG"
|
||||||
|
#elif defined(ARDUINO_AVR_PRO)
|
||||||
|
#define ARDUINO_BOARD "Pro"
|
||||||
|
#elif defined(ARDUINO_AVR_ROBOT_CONTROL)
|
||||||
|
#define ARDUINO_BOARD "Robot Ctrl"
|
||||||
|
#elif defined(ARDUINO_AVR_ROBOT_MOTOR)
|
||||||
|
#define ARDUINO_BOARD "Robot Motor"
|
||||||
|
#elif defined(ARDUINO_AVR_UNO)
|
||||||
|
#define ARDUINO_BOARD "Uno"
|
||||||
|
#elif defined(ARDUINO_AVR_YUN)
|
||||||
|
#define ARDUINO_BOARD "Yun"
|
||||||
|
#elif defined(ARDUINO_SAM_DUE)
|
||||||
|
#define ARDUINO_BOARD "Due"
|
||||||
|
#elif defined(ARDUINO_SAMD_ZERO)
|
||||||
|
#define ARDUINO_BOARD "Zero"
|
||||||
|
#elif defined(ARDUINO_ARC32_TOOLS)
|
||||||
|
#define ARDUINO_BOARD "101"
|
||||||
|
#else
|
||||||
|
#define ARDUINO_BOARD "Unknown"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#include "Embedded_Template_Library.h" // This is required for any more etl import when using Arduino IDE
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
// make sure that we do not rely on the STL
|
||||||
|
#define ETL_NO_STL
|
||||||
|
|
||||||
|
#include "Embedded_Template_Library.h"
|
||||||
|
#include "etl/vector.h"
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void print_vector(etl::ivector<T> const & vec_in)
|
||||||
|
{
|
||||||
|
Serial.print(F("print vector content | size ")); Serial.print(vec_in.size()); Serial.print(F(" | capacity ")); Serial.println(vec_in.capacity());
|
||||||
|
Serial.print(F("content | "));
|
||||||
|
|
||||||
|
for (T const & elem : vec_in)
|
||||||
|
{
|
||||||
|
Serial.print(elem);
|
||||||
|
Serial.print(F(" | "));
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
delay(100);
|
||||||
|
Serial.println(F("booted"));
|
||||||
|
|
||||||
|
etl::vector<int, 12> vec_int;
|
||||||
|
|
||||||
|
Serial.println(F("initialized vec_int"));
|
||||||
|
print_vector(vec_int);
|
||||||
|
|
||||||
|
vec_int.push_back(1);
|
||||||
|
vec_int.push_back(2);
|
||||||
|
Serial.println(F("pushed to vec_int"));
|
||||||
|
print_vector(vec_int);
|
||||||
|
|
||||||
|
vec_int.pop_back();
|
||||||
|
Serial.println(F("pop from vec_int; returns no value"));
|
||||||
|
print_vector(vec_int);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
39
Chapter15/observer/libs/etl/arduino/library-arduino.json
Normal file
39
Chapter15/observer/libs/etl/arduino/library-arduino.json
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"name": "Embedded Template Library ETL",
|
||||||
|
"version": "20.39.0",
|
||||||
|
"authors": {
|
||||||
|
"name": "John Wellbelove",
|
||||||
|
"email": "john.wellbelove@etlcpp.com"
|
||||||
|
},
|
||||||
|
"homepage": "https://www.etlcpp.com/",
|
||||||
|
"license": "MIT",
|
||||||
|
"description": "ETL. A C++ template library tailored for embedded systems. Directories formatted for Arduino",
|
||||||
|
"keywords": "c-plus-plus, cpp, algorithms, containers, templates",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/ETLCPP/etl-arduino.git"
|
||||||
|
},
|
||||||
|
"build": {
|
||||||
|
"includeDir": "include"
|
||||||
|
},
|
||||||
|
"export": {
|
||||||
|
"include": [
|
||||||
|
"include",
|
||||||
|
"examples",
|
||||||
|
"LICENSE",
|
||||||
|
"README.md"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"include/etl/experimental",
|
||||||
|
"include/etl/deprecated",
|
||||||
|
"**/__vm",
|
||||||
|
"**/.vs",
|
||||||
|
"**/*.filters",
|
||||||
|
"**/*.log",
|
||||||
|
"**/*.tmp"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"platforms": "*",
|
||||||
|
"frameworks": "*"
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
name=Embedded Template Library ETL
|
||||||
|
version=20.39.0
|
||||||
|
author= John Wellbelove <john.wellbelove@etlcpp.com>
|
||||||
|
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
|
||||||
|
license=MIT
|
||||||
|
sentence=ETL. A C++ template library tailored for embedded systems.
|
||||||
|
paragraph=
|
||||||
|
category=Other
|
||||||
|
url=https://www.etlcpp.com/
|
||||||
|
architectures=*
|
||||||
@@ -0,0 +1,284 @@
|
|||||||
|
# - Returns a version string from Git
|
||||||
|
#
|
||||||
|
# These functions force a re-configure on each git commit so that you can
|
||||||
|
# trust the values of the variables in your build system.
|
||||||
|
#
|
||||||
|
# get_git_head_revision(<refspecvar> <hashvar> [ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR])
|
||||||
|
#
|
||||||
|
# Returns the refspec and sha hash of the current head revision
|
||||||
|
#
|
||||||
|
# git_describe(<var> [<additional arguments to git describe> ...])
|
||||||
|
#
|
||||||
|
# Returns the results of git describe on the source tree, and adjusting
|
||||||
|
# the output so that it tests false if an error occurs.
|
||||||
|
#
|
||||||
|
# git_describe_working_tree(<var> [<additional arguments to git describe> ...])
|
||||||
|
#
|
||||||
|
# Returns the results of git describe on the working tree (--dirty option),
|
||||||
|
# and adjusting the output so that it tests false if an error occurs.
|
||||||
|
#
|
||||||
|
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
|
||||||
|
#
|
||||||
|
# Returns the results of git describe --exact-match on the source tree,
|
||||||
|
# and adjusting the output so that it tests false if there was no exact
|
||||||
|
# matching tag.
|
||||||
|
#
|
||||||
|
# git_local_changes(<var>)
|
||||||
|
#
|
||||||
|
# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes.
|
||||||
|
# Uses the return code of "git diff-index --quiet HEAD --".
|
||||||
|
# Does not regard untracked files.
|
||||||
|
#
|
||||||
|
# Requires CMake 2.6 or newer (uses the 'function' command)
|
||||||
|
#
|
||||||
|
# Original Author:
|
||||||
|
# 2009-2020 Ryan Pavlik <ryan.pavlik@gmail.com> <abiryan@ryand.net>
|
||||||
|
# http://academic.cleardefinition.com
|
||||||
|
#
|
||||||
|
# Copyright 2009-2013, Iowa State University.
|
||||||
|
# Copyright 2013-2020, Ryan Pavlik
|
||||||
|
# Copyright 2013-2020, Contributors
|
||||||
|
# SPDX-License-Identifier: BSL-1.0
|
||||||
|
# Distributed under the Boost Software License, Version 1.0.
|
||||||
|
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
# http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
if(__get_git_revision_description)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
set(__get_git_revision_description YES)
|
||||||
|
|
||||||
|
# We must run the following at "include" time, not at function call time,
|
||||||
|
# to find the path to this module rather than the path to a calling list file
|
||||||
|
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
|
||||||
|
|
||||||
|
# Function _git_find_closest_git_dir finds the next closest .git directory
|
||||||
|
# that is part of any directory in the path defined by _start_dir.
|
||||||
|
# The result is returned in the parent scope variable whose name is passed
|
||||||
|
# as variable _git_dir_var. If no .git directory can be found, the
|
||||||
|
# function returns an empty string via _git_dir_var.
|
||||||
|
#
|
||||||
|
# Example: Given a path C:/bla/foo/bar and assuming C:/bla/.git exists and
|
||||||
|
# neither foo nor bar contain a file/directory .git. This will return
|
||||||
|
# C:/bla/.git
|
||||||
|
#
|
||||||
|
function(_git_find_closest_git_dir _start_dir _git_dir_var)
|
||||||
|
set(cur_dir "${_start_dir}")
|
||||||
|
set(git_dir "${_start_dir}/.git")
|
||||||
|
while(NOT EXISTS "${git_dir}")
|
||||||
|
# .git dir not found, search parent directories
|
||||||
|
set(git_previous_parent "${cur_dir}")
|
||||||
|
get_filename_component(cur_dir "${cur_dir}" DIRECTORY)
|
||||||
|
if(cur_dir STREQUAL git_previous_parent)
|
||||||
|
# We have reached the root directory, we are not in git
|
||||||
|
set(${_git_dir_var}
|
||||||
|
""
|
||||||
|
PARENT_SCOPE)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
set(git_dir "${cur_dir}/.git")
|
||||||
|
endwhile()
|
||||||
|
set(${_git_dir_var}
|
||||||
|
"${git_dir}"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(get_git_head_revision _refspecvar _hashvar)
|
||||||
|
_git_find_closest_git_dir("${CMAKE_CURRENT_SOURCE_DIR}" GIT_DIR)
|
||||||
|
|
||||||
|
if("${ARGN}" STREQUAL "ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR")
|
||||||
|
set(ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR TRUE)
|
||||||
|
else()
|
||||||
|
set(ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR FALSE)
|
||||||
|
endif()
|
||||||
|
if(NOT "${GIT_DIR}" STREQUAL "")
|
||||||
|
file(RELATIVE_PATH _relative_to_source_dir "${CMAKE_SOURCE_DIR}"
|
||||||
|
"${GIT_DIR}")
|
||||||
|
if("${_relative_to_source_dir}" MATCHES "[.][.]" AND NOT ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR)
|
||||||
|
# We've gone above the CMake root dir.
|
||||||
|
set(GIT_DIR "")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
if("${GIT_DIR}" STREQUAL "")
|
||||||
|
set(${_refspecvar}
|
||||||
|
"GITDIR-NOTFOUND"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
set(${_hashvar}
|
||||||
|
"GITDIR-NOTFOUND"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Check if the current source dir is a git submodule or a worktree.
|
||||||
|
# In both cases .git is a file instead of a directory.
|
||||||
|
#
|
||||||
|
if(NOT IS_DIRECTORY ${GIT_DIR})
|
||||||
|
# The following git command will return a non empty string that
|
||||||
|
# points to the super project working tree if the current
|
||||||
|
# source dir is inside a git submodule.
|
||||||
|
# Otherwise the command will return an empty string.
|
||||||
|
#
|
||||||
|
execute_process(
|
||||||
|
COMMAND "${GIT_EXECUTABLE}" rev-parse
|
||||||
|
--show-superproject-working-tree
|
||||||
|
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
|
OUTPUT_VARIABLE out
|
||||||
|
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
if(NOT "${out}" STREQUAL "")
|
||||||
|
# If out is empty, GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a submodule
|
||||||
|
file(READ ${GIT_DIR} submodule)
|
||||||
|
string(REGEX REPLACE "gitdir: (.*)$" "\\1" GIT_DIR_RELATIVE
|
||||||
|
${submodule})
|
||||||
|
string(STRIP ${GIT_DIR_RELATIVE} GIT_DIR_RELATIVE)
|
||||||
|
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
|
||||||
|
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE}
|
||||||
|
ABSOLUTE)
|
||||||
|
set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD")
|
||||||
|
else()
|
||||||
|
# GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a worktree
|
||||||
|
file(READ ${GIT_DIR} worktree_ref)
|
||||||
|
# The .git directory contains a path to the worktree information directory
|
||||||
|
# inside the parent git repo of the worktree.
|
||||||
|
#
|
||||||
|
string(REGEX REPLACE "gitdir: (.*)$" "\\1" git_worktree_dir
|
||||||
|
${worktree_ref})
|
||||||
|
string(STRIP ${git_worktree_dir} git_worktree_dir)
|
||||||
|
_git_find_closest_git_dir("${git_worktree_dir}" GIT_DIR)
|
||||||
|
set(HEAD_SOURCE_FILE "${git_worktree_dir}/HEAD")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD")
|
||||||
|
endif()
|
||||||
|
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
|
||||||
|
if(NOT EXISTS "${GIT_DATA}")
|
||||||
|
file(MAKE_DIRECTORY "${GIT_DATA}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT EXISTS "${HEAD_SOURCE_FILE}")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
set(HEAD_FILE "${GIT_DATA}/HEAD")
|
||||||
|
configure_file("${HEAD_SOURCE_FILE}" "${HEAD_FILE}" COPYONLY)
|
||||||
|
|
||||||
|
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
|
||||||
|
"${GIT_DATA}/grabRef.cmake" @ONLY)
|
||||||
|
include("${GIT_DATA}/grabRef.cmake")
|
||||||
|
|
||||||
|
set(${_refspecvar}
|
||||||
|
"${HEAD_REF}"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
set(${_hashvar}
|
||||||
|
"${HEAD_HASH}"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(git_describe _var)
|
||||||
|
if(NOT GIT_FOUND)
|
||||||
|
find_package(Git QUIET)
|
||||||
|
endif()
|
||||||
|
get_git_head_revision(refspec hash ${ARGN})
|
||||||
|
if(NOT GIT_FOUND)
|
||||||
|
set(${_var}
|
||||||
|
"GIT-NOTFOUND"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
if(NOT hash)
|
||||||
|
set(${_var}
|
||||||
|
"HEAD-HASH-NOTFOUND"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# TODO sanitize
|
||||||
|
#if((${ARGN}" MATCHES "&&") OR
|
||||||
|
# (ARGN MATCHES "||") OR
|
||||||
|
# (ARGN MATCHES "\\;"))
|
||||||
|
# message("Please report the following error to the project!")
|
||||||
|
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
|
||||||
|
#endif()
|
||||||
|
|
||||||
|
#message(STATUS "Arguments to execute_process: ${ARGN}")
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND "${GIT_EXECUTABLE}" describe --tags --always ${hash} ${ARGN}
|
||||||
|
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
|
RESULT_VARIABLE res
|
||||||
|
OUTPUT_VARIABLE out
|
||||||
|
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
if(NOT res EQUAL 0)
|
||||||
|
set(out "${out}-${res}-NOTFOUND")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(${_var}
|
||||||
|
"${out}"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(git_describe_working_tree _var)
|
||||||
|
if(NOT GIT_FOUND)
|
||||||
|
find_package(Git QUIET)
|
||||||
|
endif()
|
||||||
|
if(NOT GIT_FOUND)
|
||||||
|
set(${_var}
|
||||||
|
"GIT-NOTFOUND"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND "${GIT_EXECUTABLE}" describe --dirty ${ARGN}
|
||||||
|
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
|
RESULT_VARIABLE res
|
||||||
|
OUTPUT_VARIABLE out
|
||||||
|
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
if(NOT res EQUAL 0)
|
||||||
|
set(out "${out}-${res}-NOTFOUND")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(${_var}
|
||||||
|
"${out}"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(git_get_exact_tag _var)
|
||||||
|
git_describe(out --exact-match ${ARGN})
|
||||||
|
set(${_var}
|
||||||
|
"${out}"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(git_local_changes _var)
|
||||||
|
if(NOT GIT_FOUND)
|
||||||
|
find_package(Git QUIET)
|
||||||
|
endif()
|
||||||
|
get_git_head_revision(refspec hash)
|
||||||
|
if(NOT GIT_FOUND)
|
||||||
|
set(${_var}
|
||||||
|
"GIT-NOTFOUND"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
if(NOT hash)
|
||||||
|
set(${_var}
|
||||||
|
"HEAD-HASH-NOTFOUND"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND "${GIT_EXECUTABLE}" diff-index --quiet HEAD --
|
||||||
|
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
|
RESULT_VARIABLE res
|
||||||
|
OUTPUT_VARIABLE out
|
||||||
|
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
if(res EQUAL 0)
|
||||||
|
set(${_var}
|
||||||
|
"CLEAN"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
else()
|
||||||
|
set(${_var}
|
||||||
|
"DIRTY"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
#
|
||||||
|
# Internal file for GetGitRevisionDescription.cmake
|
||||||
|
#
|
||||||
|
# Requires CMake 2.6 or newer (uses the 'function' command)
|
||||||
|
#
|
||||||
|
# Original Author:
|
||||||
|
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||||
|
# http://academic.cleardefinition.com
|
||||||
|
# Iowa State University HCI Graduate Program/VRAC
|
||||||
|
#
|
||||||
|
# Copyright 2009-2012, Iowa State University
|
||||||
|
# Copyright 2011-2015, Contributors
|
||||||
|
# Distributed under the Boost Software License, Version 1.0.
|
||||||
|
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
# http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
# SPDX-License-Identifier: BSL-1.0
|
||||||
|
|
||||||
|
set(HEAD_HASH)
|
||||||
|
|
||||||
|
file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
|
||||||
|
|
||||||
|
string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
|
||||||
|
if(HEAD_CONTENTS MATCHES "ref")
|
||||||
|
# named branch
|
||||||
|
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
|
||||||
|
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
|
||||||
|
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
|
||||||
|
else()
|
||||||
|
configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
|
||||||
|
file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
|
||||||
|
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
|
||||||
|
set(HEAD_HASH "${CMAKE_MATCH_1}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
# detached HEAD
|
||||||
|
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT HEAD_HASH)
|
||||||
|
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
|
||||||
|
string(STRIP "${HEAD_HASH}" HEAD_HASH)
|
||||||
|
endif()
|
||||||
4
Chapter15/observer/libs/etl/cmake/etlConfig.cmake.in
Normal file
4
Chapter15/observer/libs/etl/cmake/etlConfig.cmake.in
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||||
|
check_required_components("@PROJECT_NAME@")
|
||||||
35
Chapter15/observer/libs/etl/cmake/helpers.cmake
Normal file
35
Chapter15/observer/libs/etl/cmake/helpers.cmake
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
function(determine_version_with_file VER_FILE_NAME)
|
||||||
|
file(READ ${VER_FILE_NAME} ETL_VERSION_RAW)
|
||||||
|
# Remove trailing whitespaces and/or newline
|
||||||
|
string(STRIP ${ETL_VERSION_RAW} ETL_VERSION)
|
||||||
|
set(ETL_VERSION ${ETL_VERSION} CACHE STRING
|
||||||
|
"ETL version determined from version.txt" FORCE
|
||||||
|
)
|
||||||
|
message(STATUS "${MSG_PREFIX} Determined ETL version ${ETL_VERSION} from version.txt file")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(determine_version_with_git)
|
||||||
|
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GetGitRevisionDescription.cmake)
|
||||||
|
git_describe(VERSION ${ARGN})
|
||||||
|
string(FIND ${VERSION} "." VALID_VERSION)
|
||||||
|
if(VALID_VERSION EQUAL -1)
|
||||||
|
if(PROJECT_IS_TOP_LEVEL)
|
||||||
|
# only warn if this is the top-level project, since we may be
|
||||||
|
# building from a tarball as a subproject
|
||||||
|
message(WARNING "Version string ${VERSION} retrieved with git describe is invalid")
|
||||||
|
endif()
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
message(STATUS "${MSG_PREFIX} Version string determined with git describe: ${VERSION}")
|
||||||
|
# Parse the version information into pieces.
|
||||||
|
string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
|
||||||
|
string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
|
||||||
|
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")
|
||||||
|
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+(.*)" "\\1" VERSION_SHA1 "${VERSION}")
|
||||||
|
set(ETL_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||||
|
|
||||||
|
set(ETL_VERSION ${ETL_VERSION} CACHE STRING
|
||||||
|
"ETL version determined with git describe" FORCE
|
||||||
|
)
|
||||||
|
message(STATUS "${MSG_PREFIX} Determined ETL version ${ETL_VERSION} from the git tag")
|
||||||
|
endfunction()
|
||||||
4
Chapter15/observer/libs/etl/examples/ArmTimerCallbacks - C++/.gitignore
vendored
Normal file
4
Chapter15/observer/libs/etl/examples/ArmTimerCallbacks - C++/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
Objects/
|
||||||
|
RTE/
|
||||||
|
Listings/
|
||||||
|
DebugConfig/
|
||||||
@@ -0,0 +1,487 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||||
|
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_projx.xsd">
|
||||||
|
|
||||||
|
<SchemaVersion>2.1</SchemaVersion>
|
||||||
|
|
||||||
|
<Header>### uVision Project, (C) Keil Software</Header>
|
||||||
|
|
||||||
|
<Targets>
|
||||||
|
<Target>
|
||||||
|
<TargetName>Target 1</TargetName>
|
||||||
|
<ToolsetNumber>0x4</ToolsetNumber>
|
||||||
|
<ToolsetName>ARM-ADS</ToolsetName>
|
||||||
|
<pCCUsed>5060750::V5.06 update 6 (build 750)::.\ARMCC</pCCUsed>
|
||||||
|
<uAC6>0</uAC6>
|
||||||
|
<TargetOption>
|
||||||
|
<TargetCommonOption>
|
||||||
|
<Device>STM32F401RETx</Device>
|
||||||
|
<Vendor>STMicroelectronics</Vendor>
|
||||||
|
<PackID>Keil.STM32F4xx_DFP.2.15.0</PackID>
|
||||||
|
<PackURL>http://www.keil.com/pack/</PackURL>
|
||||||
|
<Cpu>IRAM(0x20000000,0x18000) IROM(0x08000000,0x80000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE</Cpu>
|
||||||
|
<FlashUtilSpec></FlashUtilSpec>
|
||||||
|
<StartupFile></StartupFile>
|
||||||
|
<FlashDriverDll>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F4xx_512 -FS08000000 -FL080000 -FP0($$Device:STM32F401RETx$CMSIS\Flash\STM32F4xx_512.FLM))</FlashDriverDll>
|
||||||
|
<DeviceId>0</DeviceId>
|
||||||
|
<RegisterFile>$$Device:STM32F401RETx$Drivers\CMSIS\Device\ST\STM32F4xx\Include\stm32f4xx.h</RegisterFile>
|
||||||
|
<MemoryEnv></MemoryEnv>
|
||||||
|
<Cmp></Cmp>
|
||||||
|
<Asm></Asm>
|
||||||
|
<Linker></Linker>
|
||||||
|
<OHString></OHString>
|
||||||
|
<InfinionOptionDll></InfinionOptionDll>
|
||||||
|
<SLE66CMisc></SLE66CMisc>
|
||||||
|
<SLE66AMisc></SLE66AMisc>
|
||||||
|
<SLE66LinkerMisc></SLE66LinkerMisc>
|
||||||
|
<SFDFile>$$Device:STM32F401RETx$CMSIS\SVD\STM32F401xE.svd</SFDFile>
|
||||||
|
<bCustSvd>0</bCustSvd>
|
||||||
|
<UseEnv>0</UseEnv>
|
||||||
|
<BinPath></BinPath>
|
||||||
|
<IncludePath></IncludePath>
|
||||||
|
<LibPath></LibPath>
|
||||||
|
<RegisterFilePath></RegisterFilePath>
|
||||||
|
<DBRegisterFilePath></DBRegisterFilePath>
|
||||||
|
<TargetStatus>
|
||||||
|
<Error>0</Error>
|
||||||
|
<ExitCodeStop>0</ExitCodeStop>
|
||||||
|
<ButtonStop>0</ButtonStop>
|
||||||
|
<NotGenerated>0</NotGenerated>
|
||||||
|
<InvalidFlash>1</InvalidFlash>
|
||||||
|
</TargetStatus>
|
||||||
|
<OutputDirectory>.\Objects\</OutputDirectory>
|
||||||
|
<OutputName>ArmTimerCallbacks</OutputName>
|
||||||
|
<CreateExecutable>1</CreateExecutable>
|
||||||
|
<CreateLib>0</CreateLib>
|
||||||
|
<CreateHexFile>0</CreateHexFile>
|
||||||
|
<DebugInformation>1</DebugInformation>
|
||||||
|
<BrowseInformation>1</BrowseInformation>
|
||||||
|
<ListingPath>.\Listings\</ListingPath>
|
||||||
|
<HexFormatSelection>1</HexFormatSelection>
|
||||||
|
<Merge32K>0</Merge32K>
|
||||||
|
<CreateBatchFile>0</CreateBatchFile>
|
||||||
|
<BeforeCompile>
|
||||||
|
<RunUserProg1>0</RunUserProg1>
|
||||||
|
<RunUserProg2>0</RunUserProg2>
|
||||||
|
<UserProg1Name></UserProg1Name>
|
||||||
|
<UserProg2Name></UserProg2Name>
|
||||||
|
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
|
||||||
|
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
|
||||||
|
<nStopU1X>0</nStopU1X>
|
||||||
|
<nStopU2X>0</nStopU2X>
|
||||||
|
</BeforeCompile>
|
||||||
|
<BeforeMake>
|
||||||
|
<RunUserProg1>0</RunUserProg1>
|
||||||
|
<RunUserProg2>0</RunUserProg2>
|
||||||
|
<UserProg1Name></UserProg1Name>
|
||||||
|
<UserProg2Name></UserProg2Name>
|
||||||
|
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
|
||||||
|
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
|
||||||
|
<nStopB1X>0</nStopB1X>
|
||||||
|
<nStopB2X>0</nStopB2X>
|
||||||
|
</BeforeMake>
|
||||||
|
<AfterMake>
|
||||||
|
<RunUserProg1>0</RunUserProg1>
|
||||||
|
<RunUserProg2>0</RunUserProg2>
|
||||||
|
<UserProg1Name></UserProg1Name>
|
||||||
|
<UserProg2Name></UserProg2Name>
|
||||||
|
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
|
||||||
|
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
|
||||||
|
<nStopA1X>0</nStopA1X>
|
||||||
|
<nStopA2X>0</nStopA2X>
|
||||||
|
</AfterMake>
|
||||||
|
<SelectedForBatchBuild>0</SelectedForBatchBuild>
|
||||||
|
<SVCSIdString></SVCSIdString>
|
||||||
|
</TargetCommonOption>
|
||||||
|
<CommonProperty>
|
||||||
|
<UseCPPCompiler>0</UseCPPCompiler>
|
||||||
|
<RVCTCodeConst>0</RVCTCodeConst>
|
||||||
|
<RVCTZI>0</RVCTZI>
|
||||||
|
<RVCTOtherData>0</RVCTOtherData>
|
||||||
|
<ModuleSelection>0</ModuleSelection>
|
||||||
|
<IncludeInBuild>1</IncludeInBuild>
|
||||||
|
<AlwaysBuild>0</AlwaysBuild>
|
||||||
|
<GenerateAssemblyFile>0</GenerateAssemblyFile>
|
||||||
|
<AssembleAssemblyFile>0</AssembleAssemblyFile>
|
||||||
|
<PublicsOnly>0</PublicsOnly>
|
||||||
|
<StopOnExitCode>3</StopOnExitCode>
|
||||||
|
<CustomArgument></CustomArgument>
|
||||||
|
<IncludeLibraryModules></IncludeLibraryModules>
|
||||||
|
<ComprImg>1</ComprImg>
|
||||||
|
</CommonProperty>
|
||||||
|
<DllOption>
|
||||||
|
<SimDllName>SARMCM3.DLL</SimDllName>
|
||||||
|
<SimDllArguments> -REMAP -MPU</SimDllArguments>
|
||||||
|
<SimDlgDll>DCM.DLL</SimDlgDll>
|
||||||
|
<SimDlgDllArguments>-pCM4</SimDlgDllArguments>
|
||||||
|
<TargetDllName>SARMCM3.DLL</TargetDllName>
|
||||||
|
<TargetDllArguments> -MPU</TargetDllArguments>
|
||||||
|
<TargetDlgDll>TCM.DLL</TargetDlgDll>
|
||||||
|
<TargetDlgDllArguments>-pCM4</TargetDlgDllArguments>
|
||||||
|
</DllOption>
|
||||||
|
<DebugOption>
|
||||||
|
<OPTHX>
|
||||||
|
<HexSelection>1</HexSelection>
|
||||||
|
<HexRangeLowAddress>0</HexRangeLowAddress>
|
||||||
|
<HexRangeHighAddress>0</HexRangeHighAddress>
|
||||||
|
<HexOffset>0</HexOffset>
|
||||||
|
<Oh166RecLen>16</Oh166RecLen>
|
||||||
|
</OPTHX>
|
||||||
|
</DebugOption>
|
||||||
|
<Utilities>
|
||||||
|
<Flash1>
|
||||||
|
<UseTargetDll>1</UseTargetDll>
|
||||||
|
<UseExternalTool>0</UseExternalTool>
|
||||||
|
<RunIndependent>0</RunIndependent>
|
||||||
|
<UpdateFlashBeforeDebugging>1</UpdateFlashBeforeDebugging>
|
||||||
|
<Capability>1</Capability>
|
||||||
|
<DriverSelection>4096</DriverSelection>
|
||||||
|
</Flash1>
|
||||||
|
<bUseTDR>1</bUseTDR>
|
||||||
|
<Flash2>BIN\UL2CM3.DLL</Flash2>
|
||||||
|
<Flash3>"" ()</Flash3>
|
||||||
|
<Flash4></Flash4>
|
||||||
|
<pFcarmOut></pFcarmOut>
|
||||||
|
<pFcarmGrp></pFcarmGrp>
|
||||||
|
<pFcArmRoot></pFcArmRoot>
|
||||||
|
<FcArmLst>0</FcArmLst>
|
||||||
|
</Utilities>
|
||||||
|
<TargetArmAds>
|
||||||
|
<ArmAdsMisc>
|
||||||
|
<GenerateListings>0</GenerateListings>
|
||||||
|
<asHll>1</asHll>
|
||||||
|
<asAsm>1</asAsm>
|
||||||
|
<asMacX>1</asMacX>
|
||||||
|
<asSyms>1</asSyms>
|
||||||
|
<asFals>1</asFals>
|
||||||
|
<asDbgD>1</asDbgD>
|
||||||
|
<asForm>1</asForm>
|
||||||
|
<ldLst>0</ldLst>
|
||||||
|
<ldmm>1</ldmm>
|
||||||
|
<ldXref>1</ldXref>
|
||||||
|
<BigEnd>0</BigEnd>
|
||||||
|
<AdsALst>1</AdsALst>
|
||||||
|
<AdsACrf>1</AdsACrf>
|
||||||
|
<AdsANop>0</AdsANop>
|
||||||
|
<AdsANot>0</AdsANot>
|
||||||
|
<AdsLLst>1</AdsLLst>
|
||||||
|
<AdsLmap>1</AdsLmap>
|
||||||
|
<AdsLcgr>1</AdsLcgr>
|
||||||
|
<AdsLsym>1</AdsLsym>
|
||||||
|
<AdsLszi>1</AdsLszi>
|
||||||
|
<AdsLtoi>1</AdsLtoi>
|
||||||
|
<AdsLsun>1</AdsLsun>
|
||||||
|
<AdsLven>1</AdsLven>
|
||||||
|
<AdsLsxf>1</AdsLsxf>
|
||||||
|
<RvctClst>0</RvctClst>
|
||||||
|
<GenPPlst>0</GenPPlst>
|
||||||
|
<AdsCpuType>"Cortex-M4"</AdsCpuType>
|
||||||
|
<RvctDeviceName></RvctDeviceName>
|
||||||
|
<mOS>0</mOS>
|
||||||
|
<uocRom>0</uocRom>
|
||||||
|
<uocRam>0</uocRam>
|
||||||
|
<hadIROM>1</hadIROM>
|
||||||
|
<hadIRAM>1</hadIRAM>
|
||||||
|
<hadXRAM>0</hadXRAM>
|
||||||
|
<uocXRam>0</uocXRam>
|
||||||
|
<RvdsVP>2</RvdsVP>
|
||||||
|
<RvdsMve>0</RvdsMve>
|
||||||
|
<RvdsCdeCp>0</RvdsCdeCp>
|
||||||
|
<hadIRAM2>0</hadIRAM2>
|
||||||
|
<hadIROM2>0</hadIROM2>
|
||||||
|
<StupSel>8</StupSel>
|
||||||
|
<useUlib>0</useUlib>
|
||||||
|
<EndSel>0</EndSel>
|
||||||
|
<uLtcg>0</uLtcg>
|
||||||
|
<nSecure>0</nSecure>
|
||||||
|
<RoSelD>3</RoSelD>
|
||||||
|
<RwSelD>3</RwSelD>
|
||||||
|
<CodeSel>0</CodeSel>
|
||||||
|
<OptFeed>0</OptFeed>
|
||||||
|
<NoZi1>0</NoZi1>
|
||||||
|
<NoZi2>0</NoZi2>
|
||||||
|
<NoZi3>0</NoZi3>
|
||||||
|
<NoZi4>0</NoZi4>
|
||||||
|
<NoZi5>0</NoZi5>
|
||||||
|
<Ro1Chk>0</Ro1Chk>
|
||||||
|
<Ro2Chk>0</Ro2Chk>
|
||||||
|
<Ro3Chk>0</Ro3Chk>
|
||||||
|
<Ir1Chk>1</Ir1Chk>
|
||||||
|
<Ir2Chk>0</Ir2Chk>
|
||||||
|
<Ra1Chk>0</Ra1Chk>
|
||||||
|
<Ra2Chk>0</Ra2Chk>
|
||||||
|
<Ra3Chk>0</Ra3Chk>
|
||||||
|
<Im1Chk>1</Im1Chk>
|
||||||
|
<Im2Chk>0</Im2Chk>
|
||||||
|
<OnChipMemories>
|
||||||
|
<Ocm1>
|
||||||
|
<Type>0</Type>
|
||||||
|
<StartAddress>0x0</StartAddress>
|
||||||
|
<Size>0x0</Size>
|
||||||
|
</Ocm1>
|
||||||
|
<Ocm2>
|
||||||
|
<Type>0</Type>
|
||||||
|
<StartAddress>0x0</StartAddress>
|
||||||
|
<Size>0x0</Size>
|
||||||
|
</Ocm2>
|
||||||
|
<Ocm3>
|
||||||
|
<Type>0</Type>
|
||||||
|
<StartAddress>0x0</StartAddress>
|
||||||
|
<Size>0x0</Size>
|
||||||
|
</Ocm3>
|
||||||
|
<Ocm4>
|
||||||
|
<Type>0</Type>
|
||||||
|
<StartAddress>0x0</StartAddress>
|
||||||
|
<Size>0x0</Size>
|
||||||
|
</Ocm4>
|
||||||
|
<Ocm5>
|
||||||
|
<Type>0</Type>
|
||||||
|
<StartAddress>0x0</StartAddress>
|
||||||
|
<Size>0x0</Size>
|
||||||
|
</Ocm5>
|
||||||
|
<Ocm6>
|
||||||
|
<Type>0</Type>
|
||||||
|
<StartAddress>0x0</StartAddress>
|
||||||
|
<Size>0x0</Size>
|
||||||
|
</Ocm6>
|
||||||
|
<IRAM>
|
||||||
|
<Type>0</Type>
|
||||||
|
<StartAddress>0x20000000</StartAddress>
|
||||||
|
<Size>0x18000</Size>
|
||||||
|
</IRAM>
|
||||||
|
<IROM>
|
||||||
|
<Type>1</Type>
|
||||||
|
<StartAddress>0x8000000</StartAddress>
|
||||||
|
<Size>0x80000</Size>
|
||||||
|
</IROM>
|
||||||
|
<XRAM>
|
||||||
|
<Type>0</Type>
|
||||||
|
<StartAddress>0x0</StartAddress>
|
||||||
|
<Size>0x0</Size>
|
||||||
|
</XRAM>
|
||||||
|
<OCR_RVCT1>
|
||||||
|
<Type>1</Type>
|
||||||
|
<StartAddress>0x0</StartAddress>
|
||||||
|
<Size>0x0</Size>
|
||||||
|
</OCR_RVCT1>
|
||||||
|
<OCR_RVCT2>
|
||||||
|
<Type>1</Type>
|
||||||
|
<StartAddress>0x0</StartAddress>
|
||||||
|
<Size>0x0</Size>
|
||||||
|
</OCR_RVCT2>
|
||||||
|
<OCR_RVCT3>
|
||||||
|
<Type>1</Type>
|
||||||
|
<StartAddress>0x0</StartAddress>
|
||||||
|
<Size>0x0</Size>
|
||||||
|
</OCR_RVCT3>
|
||||||
|
<OCR_RVCT4>
|
||||||
|
<Type>1</Type>
|
||||||
|
<StartAddress>0x8000000</StartAddress>
|
||||||
|
<Size>0x80000</Size>
|
||||||
|
</OCR_RVCT4>
|
||||||
|
<OCR_RVCT5>
|
||||||
|
<Type>1</Type>
|
||||||
|
<StartAddress>0x0</StartAddress>
|
||||||
|
<Size>0x0</Size>
|
||||||
|
</OCR_RVCT5>
|
||||||
|
<OCR_RVCT6>
|
||||||
|
<Type>0</Type>
|
||||||
|
<StartAddress>0x0</StartAddress>
|
||||||
|
<Size>0x0</Size>
|
||||||
|
</OCR_RVCT6>
|
||||||
|
<OCR_RVCT7>
|
||||||
|
<Type>0</Type>
|
||||||
|
<StartAddress>0x0</StartAddress>
|
||||||
|
<Size>0x0</Size>
|
||||||
|
</OCR_RVCT7>
|
||||||
|
<OCR_RVCT8>
|
||||||
|
<Type>0</Type>
|
||||||
|
<StartAddress>0x0</StartAddress>
|
||||||
|
<Size>0x0</Size>
|
||||||
|
</OCR_RVCT8>
|
||||||
|
<OCR_RVCT9>
|
||||||
|
<Type>0</Type>
|
||||||
|
<StartAddress>0x20000000</StartAddress>
|
||||||
|
<Size>0x18000</Size>
|
||||||
|
</OCR_RVCT9>
|
||||||
|
<OCR_RVCT10>
|
||||||
|
<Type>0</Type>
|
||||||
|
<StartAddress>0x0</StartAddress>
|
||||||
|
<Size>0x0</Size>
|
||||||
|
</OCR_RVCT10>
|
||||||
|
</OnChipMemories>
|
||||||
|
<RvctStartVector></RvctStartVector>
|
||||||
|
</ArmAdsMisc>
|
||||||
|
<Cads>
|
||||||
|
<interw>1</interw>
|
||||||
|
<Optim>1</Optim>
|
||||||
|
<oTime>0</oTime>
|
||||||
|
<SplitLS>0</SplitLS>
|
||||||
|
<OneElfS>1</OneElfS>
|
||||||
|
<Strict>0</Strict>
|
||||||
|
<EnumInt>0</EnumInt>
|
||||||
|
<PlainCh>1</PlainCh>
|
||||||
|
<Ropi>0</Ropi>
|
||||||
|
<Rwpi>0</Rwpi>
|
||||||
|
<wLevel>2</wLevel>
|
||||||
|
<uThumb>0</uThumb>
|
||||||
|
<uSurpInc>0</uSurpInc>
|
||||||
|
<uC99>1</uC99>
|
||||||
|
<uGnu>0</uGnu>
|
||||||
|
<useXO>0</useXO>
|
||||||
|
<v6Lang>3</v6Lang>
|
||||||
|
<v6LangP>3</v6LangP>
|
||||||
|
<vShortEn>1</vShortEn>
|
||||||
|
<vShortWch>1</vShortWch>
|
||||||
|
<v6Lto>0</v6Lto>
|
||||||
|
<v6WtE>0</v6WtE>
|
||||||
|
<v6Rtti>0</v6Rtti>
|
||||||
|
<VariousControls>
|
||||||
|
<MiscControls></MiscControls>
|
||||||
|
<Define>__STDC_LIMIT_MACROS</Define>
|
||||||
|
<Undefine></Undefine>
|
||||||
|
<IncludePath>..\..\include;..\ArmTimerCallbacks - C++</IncludePath>
|
||||||
|
</VariousControls>
|
||||||
|
</Cads>
|
||||||
|
<Aads>
|
||||||
|
<interw>1</interw>
|
||||||
|
<Ropi>0</Ropi>
|
||||||
|
<Rwpi>0</Rwpi>
|
||||||
|
<thumb>0</thumb>
|
||||||
|
<SplitLS>0</SplitLS>
|
||||||
|
<SwStkChk>0</SwStkChk>
|
||||||
|
<NoWarn>0</NoWarn>
|
||||||
|
<uSurpInc>0</uSurpInc>
|
||||||
|
<useXO>0</useXO>
|
||||||
|
<ClangAsOpt>4</ClangAsOpt>
|
||||||
|
<VariousControls>
|
||||||
|
<MiscControls></MiscControls>
|
||||||
|
<Define></Define>
|
||||||
|
<Undefine></Undefine>
|
||||||
|
<IncludePath></IncludePath>
|
||||||
|
</VariousControls>
|
||||||
|
</Aads>
|
||||||
|
<LDads>
|
||||||
|
<umfTarg>0</umfTarg>
|
||||||
|
<Ropi>0</Ropi>
|
||||||
|
<Rwpi>0</Rwpi>
|
||||||
|
<noStLib>0</noStLib>
|
||||||
|
<RepFail>1</RepFail>
|
||||||
|
<useFile>0</useFile>
|
||||||
|
<TextAddressRange>0x08000000</TextAddressRange>
|
||||||
|
<DataAddressRange>0x20000000</DataAddressRange>
|
||||||
|
<pXoBase></pXoBase>
|
||||||
|
<ScatterFile></ScatterFile>
|
||||||
|
<IncludeLibs></IncludeLibs>
|
||||||
|
<IncludeLibsPath></IncludeLibsPath>
|
||||||
|
<Misc></Misc>
|
||||||
|
<LinkerInputFile></LinkerInputFile>
|
||||||
|
<DisabledWarnings></DisabledWarnings>
|
||||||
|
</LDads>
|
||||||
|
</TargetArmAds>
|
||||||
|
</TargetOption>
|
||||||
|
<Groups>
|
||||||
|
<Group>
|
||||||
|
<GroupName>Source Group 1</GroupName>
|
||||||
|
<Files>
|
||||||
|
<File>
|
||||||
|
<FileName>main.cpp</FileName>
|
||||||
|
<FileType>8</FileType>
|
||||||
|
<FilePath>.\main.cpp</FilePath>
|
||||||
|
</File>
|
||||||
|
<File>
|
||||||
|
<FileName>etl_profile.h</FileName>
|
||||||
|
<FileType>5</FileType>
|
||||||
|
<FilePath>.\etl_profile.h</FilePath>
|
||||||
|
</File>
|
||||||
|
</Files>
|
||||||
|
</Group>
|
||||||
|
<Group>
|
||||||
|
<GroupName>::Board Support</GroupName>
|
||||||
|
</Group>
|
||||||
|
<Group>
|
||||||
|
<GroupName>::CMSIS</GroupName>
|
||||||
|
</Group>
|
||||||
|
<Group>
|
||||||
|
<GroupName>::Device</GroupName>
|
||||||
|
</Group>
|
||||||
|
</Groups>
|
||||||
|
</Target>
|
||||||
|
</Targets>
|
||||||
|
|
||||||
|
<RTE>
|
||||||
|
<apis>
|
||||||
|
<api Capiversion="1.0.0" Cclass="Board Support" Cgroup="Buttons" exclusive="0">
|
||||||
|
<package name="MDK-Middleware" schemaVersion="1.4" url="http://www.keil.com/pack/" vendor="Keil" version="7.4.1"/>
|
||||||
|
<targetInfos>
|
||||||
|
<targetInfo name="Target 1"/>
|
||||||
|
</targetInfos>
|
||||||
|
</api>
|
||||||
|
<api Capiversion="1.0.0" Cclass="Board Support" Cgroup="LED" exclusive="0">
|
||||||
|
<package name="MDK-Middleware" schemaVersion="1.4" url="http://www.keil.com/pack/" vendor="Keil" version="7.4.1"/>
|
||||||
|
<targetInfos>
|
||||||
|
<targetInfo name="Target 1"/>
|
||||||
|
</targetInfos>
|
||||||
|
</api>
|
||||||
|
</apis>
|
||||||
|
<components>
|
||||||
|
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.4.0" condition="ARMv6_7_8-M Device">
|
||||||
|
<package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="5.7.0"/>
|
||||||
|
<targetInfos>
|
||||||
|
<targetInfo name="Target 1"/>
|
||||||
|
</targetInfos>
|
||||||
|
</component>
|
||||||
|
<component Capiversion="1.00" Cbundle="NUCLEO-F401RE" Cclass="Board Support" Cgroup="Buttons" Cvendor="Keil" Cversion="1.1.0" condition="F401RE CMSIS Device">
|
||||||
|
<package name="STM32NUCLEO_BSP" schemaVersion="1.2" url="http://www.keil.com/pack/" vendor="Keil" version="1.6.0"/>
|
||||||
|
<targetInfos>
|
||||||
|
<targetInfo name="Target 1"/>
|
||||||
|
</targetInfos>
|
||||||
|
</component>
|
||||||
|
<component Capiversion="1.00" Cbundle="NUCLEO-F401RE" Cclass="Board Support" Cgroup="LED" Cvendor="Keil" Cversion="1.1.0" condition="F401RE CMSIS Device">
|
||||||
|
<package name="STM32NUCLEO_BSP" schemaVersion="1.2" url="http://www.keil.com/pack/" vendor="Keil" version="1.6.0"/>
|
||||||
|
<targetInfos>
|
||||||
|
<targetInfo name="Target 1"/>
|
||||||
|
</targetInfos>
|
||||||
|
</component>
|
||||||
|
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="2.6.3" condition="STM32F4 CMSIS">
|
||||||
|
<package name="STM32F4xx_DFP" schemaVersion="1.6.3" url="http://www.keil.com/pack/" vendor="Keil" version="2.15.0"/>
|
||||||
|
<targetInfos>
|
||||||
|
<targetInfo name="Target 1"/>
|
||||||
|
</targetInfos>
|
||||||
|
</component>
|
||||||
|
</components>
|
||||||
|
<files>
|
||||||
|
<file attr="config" category="source" condition="STM32F401xE_ARMCC" name="Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates\arm\startup_stm32f401xe.s" version="2.6.0">
|
||||||
|
<instance index="0">RTE\Device\STM32F401RETx\startup_stm32f401xe.s</instance>
|
||||||
|
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="2.6.3" condition="STM32F4 CMSIS"/>
|
||||||
|
<package name="STM32F4xx_DFP" schemaVersion="1.6.3" url="http://www.keil.com/pack/" vendor="Keil" version="2.15.0"/>
|
||||||
|
<targetInfos>
|
||||||
|
<targetInfo name="Target 1"/>
|
||||||
|
</targetInfos>
|
||||||
|
</file>
|
||||||
|
<file attr="config" category="source" name="Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates\system_stm32f4xx.c" version="2.6.0">
|
||||||
|
<instance index="0">RTE\Device\STM32F401RETx\system_stm32f4xx.c</instance>
|
||||||
|
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="2.6.3" condition="STM32F4 CMSIS"/>
|
||||||
|
<package name="STM32F4xx_DFP" schemaVersion="1.6.3" url="http://www.keil.com/pack/" vendor="Keil" version="2.15.0"/>
|
||||||
|
<targetInfos>
|
||||||
|
<targetInfo name="Target 1"/>
|
||||||
|
</targetInfos>
|
||||||
|
</file>
|
||||||
|
</files>
|
||||||
|
</RTE>
|
||||||
|
|
||||||
|
<LayerInfo>
|
||||||
|
<Layers>
|
||||||
|
<Layer>
|
||||||
|
<LayName><Project Info></LayName>
|
||||||
|
<LayDesc></LayDesc>
|
||||||
|
<LayUrl></LayUrl>
|
||||||
|
<LayKeys></LayKeys>
|
||||||
|
<LayCat></LayCat>
|
||||||
|
<LayLic></LayLic>
|
||||||
|
<LayTarg>0</LayTarg>
|
||||||
|
<LayPrjMark>1</LayPrjMark>
|
||||||
|
</Layer>
|
||||||
|
</Layers>
|
||||||
|
</LayerInfo>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
#ifndef __ETL_PROFILE_H__
|
||||||
|
#define __ETL_PROFILE_H__
|
||||||
|
|
||||||
|
#define ETL_VERBOSE_ERRORS
|
||||||
|
#define ETL_CHECK_PUSH_POP
|
||||||
|
#define ETL_ISTRING_REPAIR_ENABLE
|
||||||
|
#define ETL_IVECTOR_REPAIR_ENABLE
|
||||||
|
#define ETL_IDEQUE_REPAIR_ENABLE
|
||||||
|
#define ETL_CALLBACK_TIMER_USE_ATOMIC_LOCK
|
||||||
|
#define ETL_NO_STL
|
||||||
|
|
||||||
|
//#include "etl/profiles/auto.h"
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
//#if (__cplusplus < 201103L)
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
//#endif
|
||||||
|
#include "Board_LED.h" // ::Board Support:LED
|
||||||
|
#include "Board_Buttons.h" // ::Board Support:Buttons
|
||||||
|
//#if (__cplusplus < 201103L)
|
||||||
|
}
|
||||||
|
//#endif
|
||||||
|
|
||||||
|
#include "stm32f4xx.h" // Device header
|
||||||
|
|
||||||
|
#include "etl/function.h"
|
||||||
|
#include "etl/callback_timer.h"
|
||||||
|
#include "etl/vector.h"
|
||||||
|
#include "etl/iterator.h"
|
||||||
|
#include "etl/binary.h"
|
||||||
|
|
||||||
|
struct FP
|
||||||
|
{
|
||||||
|
void (*function)();
|
||||||
|
};
|
||||||
|
|
||||||
|
static etl::vector<FP, 10> power_callbacks;
|
||||||
|
|
||||||
|
void register_poweroff_callback(void (*function)())
|
||||||
|
{
|
||||||
|
FP fp = { function };
|
||||||
|
power_callbacks.push_back(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
const int N_TIMERS = 4;
|
||||||
|
|
||||||
|
etl::callback_timer<N_TIMERS> callback_timer;
|
||||||
|
|
||||||
|
etl::timer::id::type short_toggle;
|
||||||
|
etl::timer::id::type long_toggle;
|
||||||
|
etl::timer::id::type start_timers;
|
||||||
|
etl::timer::id::type swap_timers;
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
* SystemCoreClockConfigure: configure SystemCoreClock using HSI
|
||||||
|
(HSE is not populated on Nucleo board)
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
void SystemCoreClockConfigure(void) {
|
||||||
|
|
||||||
|
RCC->CR |= ((uint32_t)RCC_CR_HSION); // Enable HSI
|
||||||
|
while ((RCC->CR & RCC_CR_HSIRDY) == 0); // Wait for HSI Ready
|
||||||
|
|
||||||
|
RCC->CFGR = RCC_CFGR_SW_HSI; // HSI is system clock
|
||||||
|
while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI); // Wait for HSI used as system clock
|
||||||
|
|
||||||
|
FLASH->ACR = FLASH_ACR_PRFTEN; // Enable Prefetch Buffer
|
||||||
|
FLASH->ACR |= FLASH_ACR_ICEN; // Instruction cache enable
|
||||||
|
FLASH->ACR |= FLASH_ACR_DCEN; // Data cache enable
|
||||||
|
FLASH->ACR |= FLASH_ACR_LATENCY_5WS; // Flash 5 wait state
|
||||||
|
|
||||||
|
RCC->CFGR |= RCC_CFGR_HPRE_DIV1; // HCLK = SYSCLK
|
||||||
|
RCC->CFGR |= RCC_CFGR_PPRE1_DIV4; // APB1 = HCLK/4
|
||||||
|
RCC->CFGR |= RCC_CFGR_PPRE2_DIV2; // APB2 = HCLK/2
|
||||||
|
|
||||||
|
RCC->CR &= ~RCC_CR_PLLON; // Disable PLL
|
||||||
|
|
||||||
|
// PLL configuration: VCO = HSI/M * N, Sysclk = VCO/P
|
||||||
|
RCC->PLLCFGR = ( 16ul | // PLL_M = 16
|
||||||
|
(384ul << 6U) | // PLL_N = 384
|
||||||
|
( 3ul << 16U) | // PLL_P = 8
|
||||||
|
(RCC_PLLCFGR_PLLSRC_HSI) | // PLL_SRC = HSI
|
||||||
|
( 8ul << 24U) ); // PLL_Q = 8
|
||||||
|
|
||||||
|
RCC->CR |= RCC_CR_PLLON; // Enable PLL
|
||||||
|
while((RCC->CR & RCC_CR_PLLRDY) == 0) __NOP(); // Wait till PLL is ready
|
||||||
|
|
||||||
|
RCC->CFGR &= ~RCC_CFGR_SW; // Select PLL as system clock source
|
||||||
|
RCC->CFGR |= RCC_CFGR_SW_PLL;
|
||||||
|
while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL); // Wait till PLL is system clock src
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartTimers()
|
||||||
|
{
|
||||||
|
callback_timer.start(short_toggle);
|
||||||
|
callback_timer.start(swap_timers);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwapTimers()
|
||||||
|
{
|
||||||
|
static bool state = false;
|
||||||
|
|
||||||
|
if (!state)
|
||||||
|
{
|
||||||
|
callback_timer.stop(short_toggle);
|
||||||
|
callback_timer.start(long_toggle);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
callback_timer.start(short_toggle);
|
||||||
|
callback_timer.stop(long_toggle);
|
||||||
|
}
|
||||||
|
|
||||||
|
state = !state;
|
||||||
|
|
||||||
|
callback_timer.start(swap_timers);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LedToggle()
|
||||||
|
{
|
||||||
|
static bool state = false;
|
||||||
|
|
||||||
|
if (state)
|
||||||
|
{
|
||||||
|
LED_On(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LED_Off(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
state = !state;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
SystemCoreClockConfigure(); // configure HSI as System Clock
|
||||||
|
SystemCoreClockUpdate();
|
||||||
|
|
||||||
|
LED_Initialize();
|
||||||
|
Buttons_Initialize();
|
||||||
|
|
||||||
|
// The LEDs will start flashing fast after 2 seconds.
|
||||||
|
// After another 5 seconds they will start flashing slower.
|
||||||
|
short_toggle = callback_timer.register_timer(LedToggle, 50, etl::timer::mode::REPEATING);
|
||||||
|
long_toggle = callback_timer.register_timer(LedToggle, 100, etl::timer::mode::REPEATING);
|
||||||
|
start_timers = callback_timer.register_timer(StartTimers, 2000, etl::timer::mode::SINGLE_SHOT);
|
||||||
|
swap_timers = callback_timer.register_timer(SwapTimers, 1500, etl::timer::mode::SINGLE_SHOT);
|
||||||
|
|
||||||
|
SysTick_Config(SystemCoreClock / 1000);
|
||||||
|
|
||||||
|
callback_timer.enable(true);
|
||||||
|
|
||||||
|
callback_timer.start(start_timers);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
__NOP();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
void SysTick_Handler()
|
||||||
|
{
|
||||||
|
const uint32_t TICK = 1U;
|
||||||
|
static uint32_t nticks = TICK;
|
||||||
|
|
||||||
|
if (callback_timer.tick(nticks))
|
||||||
|
{
|
||||||
|
nticks = TICK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nticks += TICK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Chapter15/observer/libs/etl/examples/Blink/Blink1/__vm/.gitignore
vendored
Normal file
2
Chapter15/observer/libs/etl/examples/Blink/Blink1/__vm/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.vsarduino.h
|
||||||
|
*.vmps.xml
|
||||||
53
Chapter15/observer/libs/etl/examples/BlinkList/BlinkList.ino
Normal file
53
Chapter15/observer/libs/etl/examples/BlinkList/BlinkList.ino
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
//***********************************************************************************
|
||||||
|
// A version of the Blink demo, but with delays stored in two instances of etl::list
|
||||||
|
//***********************************************************************************
|
||||||
|
|
||||||
|
#undef min
|
||||||
|
#undef max
|
||||||
|
|
||||||
|
#include <list.h>
|
||||||
|
#include <container.h>
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
// initialize digital pin 13 as an output.
|
||||||
|
pinMode(13, OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void iterate(const etl::ilist<int>& delays)
|
||||||
|
{
|
||||||
|
etl::ilist<int>::const_iterator itr;
|
||||||
|
|
||||||
|
// Iterate through the list.
|
||||||
|
itr = delays.begin();
|
||||||
|
|
||||||
|
while (itr != delays.end())
|
||||||
|
{
|
||||||
|
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
|
||||||
|
delay(100); // wait
|
||||||
|
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
|
||||||
|
delay(*itr++); // wait
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
int delay_times1[] = { 900, 800, 700, 600, 500, 400, 300, 200, 100 };
|
||||||
|
int delay_times2[] = { 400, 300, 200, 100 };
|
||||||
|
|
||||||
|
// Fill the first delay list, then reverse it.
|
||||||
|
// Notice how we don't have to know the size of the array!
|
||||||
|
const size_t size1 = sizeof(etl::array_size(delay_times1));
|
||||||
|
etl::list<int, size1> delays1(etl::begin(delay_times1), etl::end(delay_times1));
|
||||||
|
delays1.reverse();
|
||||||
|
|
||||||
|
// Fill the second delay list,
|
||||||
|
const size_t size2 = sizeof(etl::array_size(delay_times2));
|
||||||
|
etl::list<int, size2> delays2(etl::begin(delay_times2), etl::end(delay_times2));
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
iterate(delays1);
|
||||||
|
iterate(delays2);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 14
|
||||||
|
VisualStudioVersion = 14.0.24720.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BlinkList", "BlinkList.vcxproj", "{C5F80730-F44F-4478-BDAE-6634EFC2CA88}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="Source Files">
|
||||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
|
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Header Files">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Resource Files">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\BlinkList.ino" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="__vm\.VisualMicro.vsarduino.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="__vm\.BlinkList.vsarduino.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
1
Chapter15/observer/libs/etl/examples/BlinkList/VisualMicro/__vm/.gitignore
vendored
Normal file
1
Chapter15/observer/libs/etl/examples/BlinkList/VisualMicro/__vm/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.vsarduino.h
|
||||||
1
Chapter15/observer/libs/etl/examples/BlinkList/__vm/.gitignore
vendored
Normal file
1
Chapter15/observer/libs/etl/examples/BlinkList/__vm/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.vmps.xml
|
||||||
39
Chapter15/observer/libs/etl/examples/Debounce/Debounce.ino
Normal file
39
Chapter15/observer/libs/etl/examples/Debounce/Debounce.ino
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
//***********************************************************************************
|
||||||
|
// A debounce demo that reads a key and toggles the LED.
|
||||||
|
// Set the pin to the correct one for your key.
|
||||||
|
//***********************************************************************************
|
||||||
|
|
||||||
|
#include <debounce.h>
|
||||||
|
|
||||||
|
const int SAMPLE_TIME = 1; // The sample time in ms.
|
||||||
|
const int DEBOUNCE_COUNT = 50; // The number of samples that must agree before a key state change is recognised. 50 = 50ms for 1ms sample time.
|
||||||
|
const int HOLD_COUNT = 1000; // The number of samples that must agree before a key held state is recognised. 1000 = 1s for 1ms sample time.
|
||||||
|
const int REPEAT_COUNT = 200; // The number of samples that must agree before a key repeat state is recognised. 200 = 200ms for 1ms sample time.
|
||||||
|
const int KEY = XX; // The pin that the key is attached to.
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
// Initialize LED pin as an output and set off.
|
||||||
|
pinMode(LED_BUILTIN , OUTPUT);
|
||||||
|
digitalWrite(LED_BUILTIN, LOW);
|
||||||
|
|
||||||
|
// Initialize KEY pin as an input.
|
||||||
|
pinMode(KEY, INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
static int led_state = LOW;
|
||||||
|
static etl::debounce<DEBOUNCE_COUNT, HOLD_COUNT, REPEAT_COUNT> key_state;
|
||||||
|
|
||||||
|
if (key_state.add(digitalRead(KEY) == HIGH)) // Assumes 'HIGH' is 'pressed' and 'LOW' is 'released'.
|
||||||
|
{
|
||||||
|
if (key_state.is_set())
|
||||||
|
{
|
||||||
|
led_state = (led_state == LOW ? HIGH : LOW); // Toggle the LED state on every validated press or repeat.
|
||||||
|
digitalWrite(LED_BUILTIN, led_state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(SAMPLE_TIME); // Wait 1ms
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5.0)
|
||||||
|
project(FunctionInterruptSimulation)
|
||||||
|
|
||||||
|
add_definitions(-DETL_DEBUG)
|
||||||
|
|
||||||
|
include_directories(${UTPP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/../../include)
|
||||||
|
|
||||||
|
set(SOURCE_FILES FunctionInterruptSimulation.cpp)
|
||||||
|
|
||||||
|
add_executable(FunctionInterruptSimulation ${SOURCE_FILES})
|
||||||
|
target_include_directories(FunctionInterruptSimulation
|
||||||
|
PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
set_property(TARGET FunctionInterruptSimulation PROPERTY CXX_STANDARD 17)
|
||||||
|
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "etl/delegate.h"
|
||||||
|
#include "etl/delegate_service.h"
|
||||||
|
|
||||||
|
enum VectorId
|
||||||
|
{
|
||||||
|
TIM1_CC_IRQ_HANDLER = 42,
|
||||||
|
TIM2_IRQ_HANDLER = 43,
|
||||||
|
TIM3_IRQ_HANDLER = 44,
|
||||||
|
USART1_IRQ_HANDLER = 52,
|
||||||
|
USART2_IRQ_HANDLER = 53,
|
||||||
|
VECTOR_ID_END,
|
||||||
|
VECTOR_ID_OFFSET = TIM1_CC_IRQ_HANDLER,
|
||||||
|
VECTOR_ID_RANGE = VECTOR_ID_END - VECTOR_ID_OFFSET
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef etl::delegate_service<VECTOR_ID_RANGE, VECTOR_ID_OFFSET> InterruptVectors;
|
||||||
|
|
||||||
|
// Ensure that the callback service is initialised before use.
|
||||||
|
InterruptVectors& GetInterruptVectorsInstance()
|
||||||
|
{
|
||||||
|
static InterruptVectors interruptVectors;
|
||||||
|
|
||||||
|
return interruptVectors;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
InterruptVectors& interruptVectors = GetInterruptVectorsInstance();
|
||||||
|
|
||||||
|
// Function called from the timer1 interrupt vector.
|
||||||
|
void TIM1_CC_IRQHandler()
|
||||||
|
{
|
||||||
|
interruptVectors.call<TIM1_CC_IRQ_HANDLER>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function called from the timer2 interrupt vector.
|
||||||
|
void TIM2_IRQHandler()
|
||||||
|
{
|
||||||
|
interruptVectors.call<TIM2_IRQ_HANDLER>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function called from the timer3 interrupt vector.
|
||||||
|
void TIM3_IRQHandler()
|
||||||
|
{
|
||||||
|
interruptVectors.call<TIM3_IRQ_HANDLER>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function called from the usart1 interrupt vector.
|
||||||
|
void USART1_IRQHandler()
|
||||||
|
{
|
||||||
|
interruptVectors.call<USART1_IRQ_HANDLER>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function called from the usart2 interrupt vector.
|
||||||
|
void USART2_IRQHandler()
|
||||||
|
{
|
||||||
|
interruptVectors.call<USART2_IRQ_HANDLER>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//********************************
|
||||||
|
// Timer driver.
|
||||||
|
//********************************
|
||||||
|
class Timer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Handler for interrupts from the timer.
|
||||||
|
void InterruptHandler(const size_t id)
|
||||||
|
{
|
||||||
|
std::cout << "Timer interrupt (member) : ID " << id << "\n";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//********************************
|
||||||
|
// Free function timer driver.
|
||||||
|
//********************************
|
||||||
|
void FreeTimerInterruptHandler(const size_t id)
|
||||||
|
{
|
||||||
|
std::cout << "Timer interrupt (free) : ID " << id << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//********************************
|
||||||
|
// UART driver.
|
||||||
|
//********************************
|
||||||
|
class Uart
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructor.
|
||||||
|
Uart(int port_id, size_t interruptId)
|
||||||
|
: port_id(port_id),
|
||||||
|
callback(etl::delegate<void(size_t)>::create<Uart, &Uart::InterruptHandler>(*this))
|
||||||
|
{
|
||||||
|
GetInterruptVectorsInstance().register_delegate(interruptId, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handler for interrupts from the UART.
|
||||||
|
void InterruptHandler(const size_t id)
|
||||||
|
{
|
||||||
|
std::cout << "UART" << port_id << " : ID " << id << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
etl::delegate<void(size_t)> callback;
|
||||||
|
|
||||||
|
int port_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
void UnhandledInterrupt(const size_t id)
|
||||||
|
{
|
||||||
|
std::cout << "Unhandled Interrupt : ID " << id << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Declare the driver instances.
|
||||||
|
Timer timer;
|
||||||
|
Uart uart1(0, USART1_IRQ_HANDLER);
|
||||||
|
Uart uart2(1, USART2_IRQ_HANDLER);
|
||||||
|
|
||||||
|
// Declare a global callback for the timer.
|
||||||
|
// Uses the most efficient callback type for a class, as everything is known at compile time.
|
||||||
|
etl::delegate<void(size_t)> timer_member_callback = etl::delegate<void(size_t)>::create<Timer, timer, &Timer::InterruptHandler>();
|
||||||
|
|
||||||
|
// Declare the callbacks for the free functions.
|
||||||
|
etl::delegate<void(size_t)> timer_free_callback = etl::delegate<void(size_t)>::create<FreeTimerInterruptHandler>();
|
||||||
|
etl::delegate<void(size_t)> unhandled_callback = etl::delegate<void(size_t)>::create<UnhandledInterrupt>();
|
||||||
|
|
||||||
|
//********************************
|
||||||
|
// Test it out.
|
||||||
|
//********************************
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Setup the callbacks.
|
||||||
|
InterruptVectors& interruptVectors = GetInterruptVectorsInstance();
|
||||||
|
|
||||||
|
interruptVectors.register_delegate<TIM1_CC_IRQ_HANDLER>(timer_member_callback);
|
||||||
|
interruptVectors.register_delegate<TIM2_IRQ_HANDLER>(timer_free_callback);
|
||||||
|
interruptVectors.register_unhandled_delegate(unhandled_callback);
|
||||||
|
|
||||||
|
// Simulate the interrupts.
|
||||||
|
TIM1_CC_IRQHandler();
|
||||||
|
TIM2_IRQHandler();
|
||||||
|
USART1_IRQHandler();
|
||||||
|
USART2_IRQHandler();
|
||||||
|
TIM3_IRQHandler(); // Unhandled!
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
///\file
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
The MIT License(MIT)
|
||||||
|
|
||||||
|
Embedded Template Library.
|
||||||
|
https://github.com/ETLCPP/etl
|
||||||
|
https://www.etlcpp.com
|
||||||
|
|
||||||
|
Copyright(c) 2017 jwellbelove
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files(the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions :
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ETL_PROFILE_H__
|
||||||
|
#define __ETL_PROFILE_H__
|
||||||
|
|
||||||
|
#define ETL_THROW_EXCEPTIONS
|
||||||
|
#define ETL_VERBOSE_ERRORS
|
||||||
|
#define ETL_CHECK_PUSH_POP
|
||||||
|
#define ETL_ISTRING_REPAIR_ENABLE
|
||||||
|
#define ETL_IVECTOR_REPAIR_ENABLE
|
||||||
|
#define ETL_IDEQUE_REPAIR_ENABLE
|
||||||
|
#define ETL_IN_UNIT_TEST
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#include "profiles/msvc_x86.h"
|
||||||
|
#else
|
||||||
|
#include "profiles/gcc_windows_x86.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
*.VC.opendb
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
*.VC.opendb
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.26730.16
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FunctionInterruptSimulation-Delegates", "FunctionInterruptSimulation-Delegates.vcxproj", "{5157DB15-C255-4E47-9FB1-AF388437F90F}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x64.Build.0 = Release|x64
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {260225EB-60CB-44CC-A60C-16A23BBC10EB}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\FunctionInterruptSimulation.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\etl_profile.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>15.0</VCProjectVersion>
|
||||||
|
<ProjectGuid>{5157DB15-C255-4E47-9FB1-AF388437F90F}</ProjectGuid>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<RootNamespace>FunctionInterruptSimulation</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>../../../src</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>../../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.26730.16
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FunctionInterruptSimulation-Delegates", "FunctionInterruptSimulation-Delegates.vcxproj", "{5157DB15-C255-4E47-9FB1-AF388437F90F}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x64.Build.0 = Release|x64
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {260225EB-60CB-44CC-A60C-16A23BBC10EB}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\FunctionInterruptSimulation.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\etl_profile.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>15.0</VCProjectVersion>
|
||||||
|
<ProjectGuid>{5157DB15-C255-4E47-9FB1-AF388437F90F}</ProjectGuid>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<RootNamespace>FunctionInterruptSimulation</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>../../../src</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>../../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5.0)
|
||||||
|
project(FunctionInterruptSimulation)
|
||||||
|
|
||||||
|
add_definitions(-DETL_DEBUG)
|
||||||
|
|
||||||
|
include_directories(${UTPP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/../../include)
|
||||||
|
|
||||||
|
set(SOURCE_FILES FunctionInterruptSimulation.cpp)
|
||||||
|
|
||||||
|
add_executable(FunctionInterruptSimulation ${SOURCE_FILES})
|
||||||
|
target_include_directories(FunctionInterruptSimulation
|
||||||
|
PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
set_property(TARGET FunctionInterruptSimulation PROPERTY CXX_STANDARD 17)
|
||||||
|
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "etl/function.h"
|
||||||
|
#include "etl/callback_service.h"
|
||||||
|
|
||||||
|
enum VectorId
|
||||||
|
{
|
||||||
|
TIM1_CC_IRQ_HANDLER = 42,
|
||||||
|
TIM2_IRQ_HANDLER = 43,
|
||||||
|
TIM3_IRQ_HANDLER = 44,
|
||||||
|
USART1_IRQ_HANDLER = 52,
|
||||||
|
USART2_IRQ_HANDLER = 53,
|
||||||
|
VECTOR_ID_END,
|
||||||
|
VECTOR_ID_OFFSET = TIM1_CC_IRQ_HANDLER,
|
||||||
|
VECTOR_ID_RANGE = VECTOR_ID_END - VECTOR_ID_OFFSET
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef etl::callback_service<VECTOR_ID_RANGE, VECTOR_ID_OFFSET> InterruptVectors;
|
||||||
|
|
||||||
|
// Ensure that the callback service is initialised before use.
|
||||||
|
InterruptVectors& GetInterruptVectorsInstance()
|
||||||
|
{
|
||||||
|
static InterruptVectors interruptVectors;
|
||||||
|
|
||||||
|
return interruptVectors;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
InterruptVectors& interruptVectors = GetInterruptVectorsInstance();
|
||||||
|
|
||||||
|
// Function called from the timer1 interrupt vector.
|
||||||
|
void TIM1_CC_IRQHandler()
|
||||||
|
{
|
||||||
|
interruptVectors.callback<TIM1_CC_IRQ_HANDLER>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function called from the timer2 interrupt vector.
|
||||||
|
void TIM2_IRQHandler()
|
||||||
|
{
|
||||||
|
interruptVectors.callback<TIM2_IRQ_HANDLER>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function called from the timer3 interrupt vector.
|
||||||
|
void TIM3_IRQHandler()
|
||||||
|
{
|
||||||
|
interruptVectors.callback<TIM3_IRQ_HANDLER>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function called from the usart1 interrupt vector.
|
||||||
|
void USART1_IRQHandler()
|
||||||
|
{
|
||||||
|
interruptVectors.callback<USART1_IRQ_HANDLER>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function called from the usart2 interrupt vector.
|
||||||
|
void USART2_IRQHandler()
|
||||||
|
{
|
||||||
|
interruptVectors.callback<USART2_IRQ_HANDLER>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//********************************
|
||||||
|
// Timer driver.
|
||||||
|
//********************************
|
||||||
|
class Timer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Handler for interrupts from the timer.
|
||||||
|
void InterruptHandler(const size_t id)
|
||||||
|
{
|
||||||
|
std::cout << "Timer interrupt (member) : ID " << id << "\n";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//********************************
|
||||||
|
// Free function timer driver.
|
||||||
|
//********************************
|
||||||
|
void FreeTimerInterruptHandler(const size_t id)
|
||||||
|
{
|
||||||
|
std::cout << "Timer interrupt (free) : ID " << id << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//********************************
|
||||||
|
// UART driver.
|
||||||
|
//********************************
|
||||||
|
class Uart
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructor.
|
||||||
|
Uart(int port_id, int interruptId)
|
||||||
|
: port_id(port_id),
|
||||||
|
callback(*this)
|
||||||
|
{
|
||||||
|
GetInterruptVectorsInstance().register_callback(interruptId, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handler for interrupts from the UART.
|
||||||
|
void InterruptHandler(const size_t id)
|
||||||
|
{
|
||||||
|
std::cout << "UART" << port_id << " : ID " << id << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
etl::function_mp<Uart, size_t, &Uart::InterruptHandler> callback;
|
||||||
|
|
||||||
|
int port_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
void UnhandledInterrupt(const size_t id)
|
||||||
|
{
|
||||||
|
std::cout << "Unhandled Interrupt : ID " << id << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Declare the driver instances.
|
||||||
|
Timer timer;
|
||||||
|
Uart uart1(0, USART1_IRQ_HANDLER);
|
||||||
|
Uart uart2(1, USART2_IRQ_HANDLER);
|
||||||
|
|
||||||
|
// Declare a global callback for the timer.
|
||||||
|
// Uses the most efficient callback type for a class, as everything is known at compile time.
|
||||||
|
etl::function_imp<Timer, size_t, timer, &Timer::InterruptHandler> timer_member_callback;
|
||||||
|
|
||||||
|
// Declare the callbacks for the free functions.
|
||||||
|
etl::function_fp<size_t, FreeTimerInterruptHandler> timer_free_callback;
|
||||||
|
etl::function_fp<size_t, UnhandledInterrupt> unhandled_callback;
|
||||||
|
|
||||||
|
//********************************
|
||||||
|
// Test it out.
|
||||||
|
//********************************
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Setup the callbacks.
|
||||||
|
InterruptVectors& interruptVectors = GetInterruptVectorsInstance();
|
||||||
|
|
||||||
|
interruptVectors.register_callback<TIM1_CC_IRQ_HANDLER>(timer_member_callback);
|
||||||
|
interruptVectors.register_callback<TIM2_IRQ_HANDLER>(timer_free_callback);
|
||||||
|
interruptVectors.register_unhandled_callback(unhandled_callback);
|
||||||
|
|
||||||
|
// Simulate the interrupts.
|
||||||
|
TIM1_CC_IRQHandler();
|
||||||
|
TIM2_IRQHandler();
|
||||||
|
USART1_IRQHandler();
|
||||||
|
USART2_IRQHandler();
|
||||||
|
TIM3_IRQHandler(); // Unhandled!
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
///\file
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
The MIT License(MIT)
|
||||||
|
|
||||||
|
Embedded Template Library.
|
||||||
|
https://github.com/ETLCPP/etl
|
||||||
|
https://www.etlcpp.com
|
||||||
|
|
||||||
|
Copyright(c) 2017 jwellbelove
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files(the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions :
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ETL_PROFILE_H__
|
||||||
|
#define __ETL_PROFILE_H__
|
||||||
|
|
||||||
|
#define ETL_THROW_EXCEPTIONS
|
||||||
|
#define ETL_VERBOSE_ERRORS
|
||||||
|
#define ETL_CHECK_PUSH_POP
|
||||||
|
#define ETL_ISTRING_REPAIR_ENABLE
|
||||||
|
#define ETL_IVECTOR_REPAIR_ENABLE
|
||||||
|
#define ETL_IDEQUE_REPAIR_ENABLE
|
||||||
|
#define ETL_IN_UNIT_TEST
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#include "profiles/msvc_x86.h"
|
||||||
|
#else
|
||||||
|
#include "profiles/gcc_windows_x86.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.26730.16
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FunctionInterruptSimulation", "FunctionInterruptSimulation.vcxproj", "{5157DB15-C255-4E47-9FB1-AF388437F90F}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x64.Build.0 = Release|x64
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {260225EB-60CB-44CC-A60C-16A23BBC10EB}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\FunctionInterruptSimulation.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\etl_profile.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>15.0</VCProjectVersion>
|
||||||
|
<ProjectGuid>{5157DB15-C255-4E47-9FB1-AF388437F90F}</ProjectGuid>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<RootNamespace>FunctionInterruptSimulation</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>../../../src</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>../../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="Source Files">
|
||||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
|
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Header Files">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Resource Files">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\FunctionInterruptSimulation.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\etl_profile.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5.0)
|
||||||
|
project(etl_mutex_router LANGUAGES CXX)
|
||||||
|
|
||||||
|
add_executable(etl_mutex_router MutexMessageRouter.cpp)
|
||||||
|
|
||||||
|
target_compile_definitions(etl_mutex_router PRIVATE -DETL_DEBUG)
|
||||||
|
|
||||||
|
target_include_directories(etl_mutex_router
|
||||||
|
PRIVATE
|
||||||
|
${PROJECT_SOURCE_DIR}/../../include)
|
||||||
|
|
||||||
|
set_property(TARGET etl_mutex_router PROPERTY CXX_STANDARD 17)
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <thread>
|
||||||
|
#include <atomic>
|
||||||
|
#include <string>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
#include "etl/mutex.h"
|
||||||
|
#include "etl/message.h"
|
||||||
|
#include "etl/message_router.h"
|
||||||
|
|
||||||
|
//*************************************
|
||||||
|
struct Message1 : public etl::message<1>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
//*************************************
|
||||||
|
struct Message2 : public etl::message<2>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
//*************************************
|
||||||
|
class Router : public etl::message_router<Router, Message1, Message2>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
using base_t = etl::message_router<Router, Message1, Message2>;
|
||||||
|
|
||||||
|
//*****************
|
||||||
|
// Overridden receive that protects access with mutexes
|
||||||
|
void receive(const etl::imessage& msg) override
|
||||||
|
{
|
||||||
|
access.lock();
|
||||||
|
base_t::receive(msg); // Send it to the message_router's receive.
|
||||||
|
access.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
//*****************
|
||||||
|
void on_receive(const Message1&)
|
||||||
|
{
|
||||||
|
result.append("Message1\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
//*****************
|
||||||
|
void on_receive(const Message2&)
|
||||||
|
{
|
||||||
|
result.append("Message2\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
//*****************
|
||||||
|
void on_receive_unknown(const etl::imessage&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string result;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
etl::mutex access;
|
||||||
|
};
|
||||||
|
|
||||||
|
//*************************************
|
||||||
|
etl::atomic<bool> start = false;
|
||||||
|
Router router;
|
||||||
|
|
||||||
|
//*************************************
|
||||||
|
void thread1()
|
||||||
|
{
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
while (!start.load());
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; ++i)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(1ms);
|
||||||
|
router.receive(Message1());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************
|
||||||
|
void thread2()
|
||||||
|
{
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
while (!start.load());
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; ++i)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(1ms);
|
||||||
|
router.receive(Message2());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::thread t1(thread1);
|
||||||
|
std::thread t2(thread2);
|
||||||
|
|
||||||
|
start.store(true);
|
||||||
|
|
||||||
|
t1.join();
|
||||||
|
t2.join();
|
||||||
|
|
||||||
|
std::cout << router.result << "\n";
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.7.34009.444
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MutexMessageRouter", "MutexMessageRouter.vcxproj", "{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}.Release|x64.Build.0 = Release|x64
|
||||||
|
{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {8AA5CBFE-B15F-4262-97AE-C12F7266BD85}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>17.0</VCProjectVersion>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<ProjectGuid>{23ad62d5-c3b6-48b0-bf0d-e349feb3f338}</ProjectGuid>
|
||||||
|
<RootNamespace>MutexMessageRouter</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>../../include;</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="MutexMessageRouter.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Text Include="CMakeLists.txt" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5.0)
|
||||||
|
project(queued_fsm)
|
||||||
|
|
||||||
|
add_definitions(-DETL_DEBUG)
|
||||||
|
|
||||||
|
include_directories(${UTPP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/../../include)
|
||||||
|
|
||||||
|
set(SOURCE_FILES QueuedFSM.cpp)
|
||||||
|
|
||||||
|
add_executable(queued_fsm ${SOURCE_FILES})
|
||||||
|
target_include_directories(queued_fsm
|
||||||
|
PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
set_property(TARGET queued_fsm PROPERTY CXX_STANDARD 17)
|
||||||
|
|
||||||
288
Chapter15/observer/libs/etl/examples/QueuedFSM/QueuedFSM.cpp
Normal file
288
Chapter15/observer/libs/etl/examples/QueuedFSM/QueuedFSM.cpp
Normal file
@@ -0,0 +1,288 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
The MIT License(MIT)
|
||||||
|
|
||||||
|
Embedded Template Library.
|
||||||
|
https://github.com/ETLCPP/etl
|
||||||
|
https://www.etlcpp.com
|
||||||
|
|
||||||
|
Copyright(c) 2020 jwellbelove
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files(the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions :
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// This example demonstrates the basic method to queue messages to an etl::fsm
|
||||||
|
// derived class.
|
||||||
|
//*****************************************************************************
|
||||||
|
|
||||||
|
#include "etl/queue.h"
|
||||||
|
#include "etl/fsm.h"
|
||||||
|
#include "etl/message_packet.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// The messages.
|
||||||
|
//*****************************************************************************
|
||||||
|
struct Message1 : public etl::message<1>
|
||||||
|
{
|
||||||
|
Message1(int i_)
|
||||||
|
: i(i_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int i;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Message2 : public etl::message<2>
|
||||||
|
{
|
||||||
|
Message2(double d_)
|
||||||
|
: d(d_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
double d;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Message3 : public etl::message<3>
|
||||||
|
{
|
||||||
|
Message3(const std::string& s_)
|
||||||
|
: s(s_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string s;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Message4 : public etl::message<4>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
STATE1,
|
||||||
|
STATE2
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// The Finite State Machine.
|
||||||
|
//*****************************************************************************
|
||||||
|
class Fsm : public etl::fsm
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
// Constructor.
|
||||||
|
//***************************************************************************
|
||||||
|
Fsm()
|
||||||
|
: fsm(1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
// The overridden virtual receive function.
|
||||||
|
//***************************************************************************
|
||||||
|
void receive(const etl::imessage& msg_) override
|
||||||
|
{
|
||||||
|
if (accepts(msg_))
|
||||||
|
{
|
||||||
|
// Place in queue.
|
||||||
|
queue.emplace(msg_);
|
||||||
|
|
||||||
|
std::cout << "Queueing message " << int(msg_.get_message_id()) << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Ignoring message " << int(msg_.get_message_id()) << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
// The method to call to handle any queued messages.
|
||||||
|
//***************************************************************************
|
||||||
|
void process_queue()
|
||||||
|
{
|
||||||
|
while (!queue.empty())
|
||||||
|
{
|
||||||
|
message_packet& packet = queue.front();
|
||||||
|
etl::imessage& msg = packet.get();
|
||||||
|
std::cout << "Processing message " << int(msg.get_message_id()) << std::endl;
|
||||||
|
|
||||||
|
// Call the base class's receive function.
|
||||||
|
// This will route it to the correct 'on_event' handler.
|
||||||
|
etl::fsm::receive(msg);
|
||||||
|
|
||||||
|
queue.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
typedef etl::message_packet< Message1, Message2, Message3, Message4> message_packet;
|
||||||
|
|
||||||
|
// The queue of message items.
|
||||||
|
etl::queue<message_packet, 10> queue;
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// State 1.
|
||||||
|
//*****************************************************************************
|
||||||
|
class State1 : public etl::fsm_state<Fsm, State1, STATE1, Message1, Message2, Message3>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
// When we enter this state.
|
||||||
|
//***************************************************************************
|
||||||
|
etl::fsm_state_id_t on_enter_state() override
|
||||||
|
{
|
||||||
|
std::cout << " S1 : Enter state" << std::endl;
|
||||||
|
return STATE1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
void on_exit_state() override
|
||||||
|
{
|
||||||
|
std::cout << " S1 : Exit state" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
etl::fsm_state_id_t on_event(const Message1& msg)
|
||||||
|
{
|
||||||
|
std::cout << " S1 : Received message " << int(msg.get_message_id()) << " : '" << msg.i << "'" << std::endl;
|
||||||
|
std::cout.flush();
|
||||||
|
return STATE1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
etl::fsm_state_id_t on_event(const Message2& msg)
|
||||||
|
{
|
||||||
|
std::cout << " S1 : Received message " << int(msg.get_message_id()) << " : '" << msg.d << "'" << std::endl;
|
||||||
|
std::cout.flush();
|
||||||
|
return STATE1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
etl::fsm_state_id_t on_event(const Message3& msg)
|
||||||
|
{
|
||||||
|
std::cout << " S1 : Received message " << int(msg.get_message_id()) << " : '" << msg.s << "'" << std::endl;
|
||||||
|
std::cout.flush();
|
||||||
|
return STATE1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
etl::fsm_state_id_t on_event_unknown(const etl::imessage& msg)
|
||||||
|
{
|
||||||
|
std::cout << " S1 : Received unknown message " << int(msg.get_message_id()) << std::endl;
|
||||||
|
std::cout.flush();
|
||||||
|
return STATE2;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// State 2.
|
||||||
|
//*****************************************************************************
|
||||||
|
class State2 : public etl::fsm_state<Fsm, State2, STATE2, Message1, Message2, Message3>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
etl::fsm_state_id_t on_enter_state() override
|
||||||
|
{
|
||||||
|
std::cout << " S2 : Enter state" << std::endl;
|
||||||
|
return STATE2;
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
// When we enter this state.
|
||||||
|
//***************************************************************************
|
||||||
|
void on_exit_state() override
|
||||||
|
{
|
||||||
|
std::cout << " S2 : Exit state" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
etl::fsm_state_id_t on_event(const Message1& msg)
|
||||||
|
{
|
||||||
|
std::cout << " S2 : Received message " << int(msg.get_message_id()) << " : '" << msg.i << "'" << std::endl;
|
||||||
|
return STATE2;
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
etl::fsm_state_id_t on_event(const Message2& msg)
|
||||||
|
{
|
||||||
|
std::cout << " S2 : Received message " << int(msg.get_message_id()) << " : '" << msg.d << "'" << std::endl;
|
||||||
|
return STATE2;
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
etl::fsm_state_id_t on_event(const Message3& msg)
|
||||||
|
{
|
||||||
|
std::cout << " S2 : Received message " << int(msg.get_message_id()) << " : '" << msg.s << "'" << std::endl;
|
||||||
|
return STATE2;
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
etl::fsm_state_id_t on_event_unknown(const etl::imessage& msg)
|
||||||
|
{
|
||||||
|
std::cout << " S2 : Received unknown message " << int(msg.get_message_id()) << std::endl;
|
||||||
|
return STATE1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// The test application.
|
||||||
|
//*****************************************************************************
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
Fsm fsm;
|
||||||
|
|
||||||
|
State1 state1;
|
||||||
|
State2 state2;
|
||||||
|
|
||||||
|
// The list of states.
|
||||||
|
etl::ifsm_state* state_list[] = { &state1, &state2 };
|
||||||
|
|
||||||
|
// Define some messages.
|
||||||
|
Message1 m1(1);
|
||||||
|
Message2 m2(1.2);
|
||||||
|
Message3 m3("Hello");
|
||||||
|
|
||||||
|
// Set up the FSM
|
||||||
|
fsm.set_states(state_list, 2);
|
||||||
|
fsm.start();
|
||||||
|
|
||||||
|
// Queue all of the messages.
|
||||||
|
etl::send_message(fsm, m1);
|
||||||
|
etl::send_message(fsm, Message1(2));
|
||||||
|
etl::send_message(fsm, m2);
|
||||||
|
etl::send_message(fsm, Message2(3.4));
|
||||||
|
etl::send_message(fsm, m3);
|
||||||
|
etl::send_message(fsm, Message3("World"));
|
||||||
|
etl::send_message(fsm, Message4());
|
||||||
|
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
// De-queue them
|
||||||
|
fsm.process_queue();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
43
Chapter15/observer/libs/etl/examples/QueuedFSM/etl_profile.h
Normal file
43
Chapter15/observer/libs/etl/examples/QueuedFSM/etl_profile.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
///\file
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
The MIT License(MIT)
|
||||||
|
|
||||||
|
Embedded Template Library.
|
||||||
|
https://github.com/ETLCPP/etl
|
||||||
|
https://www.etlcpp.com
|
||||||
|
|
||||||
|
Copyright(c) 2020 jwellbelove
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files(the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions :
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ETL_PROFILE_H__
|
||||||
|
#define __ETL_PROFILE_H__
|
||||||
|
|
||||||
|
#define ETL_THROW_EXCEPTIONS
|
||||||
|
#define ETL_VERBOSE_ERRORS
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#include "etl/profiles/msvc_x86.h"
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#include "etl/profiles/gcc_generic.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.26730.10
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QueuedFSM", "QueuedFSM.vcxproj", "{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x64.Build.0 = Release|x64
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {98B87835-6672-45D4-95BF-CC5C22C87D2C}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>15.0</VCProjectVersion>
|
||||||
|
<ProjectGuid>{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}</ProjectGuid>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<RootNamespace>QueuedFSM</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>../../../include;../vs2017</AdditionalIncludeDirectories>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>../../../include;../vs2017</AdditionalIncludeDirectories>
|
||||||
|
<PrecompiledHeaderFile />
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\QueuedFSM.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\etl_profile.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="Source Files">
|
||||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
|
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Header Files">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Resource Files">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\QueuedFSM.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\etl_profile.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5.0)
|
||||||
|
project(queued_message_router)
|
||||||
|
|
||||||
|
add_definitions(-DETL_DEBUG)
|
||||||
|
|
||||||
|
include_directories(${UTPP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/../../include)
|
||||||
|
|
||||||
|
set(SOURCE_FILES QueuedMessageRouter.cpp)
|
||||||
|
|
||||||
|
add_executable(queued_message_router ${SOURCE_FILES})
|
||||||
|
target_include_directories(queued_message_router
|
||||||
|
PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
set_property(TARGET queued_message_router PROPERTY CXX_STANDARD 17)
|
||||||
|
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
|
||||||
|
#include "etl/queue.h"
|
||||||
|
#include "etl/message_router.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// The messages.
|
||||||
|
//*****************************************************************************
|
||||||
|
struct Message1 : public etl::message<1>
|
||||||
|
{
|
||||||
|
Message1(int i_)
|
||||||
|
: i(i_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int i;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Message2 : public etl::message<2>
|
||||||
|
{
|
||||||
|
Message2(double d_)
|
||||||
|
: d(d_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
double d;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Message3 : public etl::message<3>
|
||||||
|
{
|
||||||
|
Message3(const std::string& s_)
|
||||||
|
: s(s_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string s;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Message4 : public etl::message<4>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// The message router.
|
||||||
|
// Handles message types Message1, Message2, Message3.
|
||||||
|
//*****************************************************************************
|
||||||
|
class Router : public etl::message_router<Router, Message1, Message2, Message3>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef etl::message_router<Router, Message1, Message2, Message3> Base_t;
|
||||||
|
|
||||||
|
using Base_t::receive;
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
Router()
|
||||||
|
: message_router(1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
// Override the base class's receive function.
|
||||||
|
void receive(const etl::imessage& msg_)
|
||||||
|
{
|
||||||
|
if (accepts(msg_))
|
||||||
|
{
|
||||||
|
// Place in queue.
|
||||||
|
queue.emplace(msg_);
|
||||||
|
|
||||||
|
std::cout << "Queueing message " << int(msg_.get_message_id()) << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Ignoring message " << int(msg_.get_message_id()) << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
void process_queue()
|
||||||
|
{
|
||||||
|
while (!queue.empty())
|
||||||
|
{
|
||||||
|
message_packet& packet = queue.front();
|
||||||
|
etl::imessage& msg = packet.get();
|
||||||
|
std::cout << "Processing message " << int(msg.get_message_id()) << std::endl;
|
||||||
|
|
||||||
|
// Call the base class's receive function.
|
||||||
|
// This will route it to the correct on_receive handler.
|
||||||
|
Base_t::receive(msg);
|
||||||
|
|
||||||
|
queue.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
void on_receive(const Message1& msg)
|
||||||
|
{
|
||||||
|
std::cout << " Received message " << int(msg.get_message_id()) << " : '" << msg.i << "'" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
void on_receive(const Message2& msg)
|
||||||
|
{
|
||||||
|
std::cout << " Received message " << int(msg.get_message_id()) << " : '" << msg.d << "'" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
void on_receive(const Message3& msg)
|
||||||
|
{
|
||||||
|
std::cout << " Received message " << int(msg.get_message_id()) << " : '" << msg.s << "'" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************************************
|
||||||
|
void on_receive_unknown(const etl::imessage& msg)
|
||||||
|
{
|
||||||
|
std::cout << " Received unknown message " << int(msg.get_message_id()) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
etl::queue<message_packet, 10> queue;
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// The test application.
|
||||||
|
//*****************************************************************************
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
Router router;
|
||||||
|
|
||||||
|
Message1 m1(1);
|
||||||
|
Message2 m2(1.2);
|
||||||
|
Message3 m3("Hello");
|
||||||
|
|
||||||
|
etl::send_message(router, m1);
|
||||||
|
etl::send_message(router, Message1(2));
|
||||||
|
etl::send_message(router, m2);
|
||||||
|
etl::send_message(router, Message2(3.4));
|
||||||
|
etl::send_message(router, m3);
|
||||||
|
etl::send_message(router, Message3("World"));
|
||||||
|
etl::send_message(router, Message4());
|
||||||
|
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
router.process_queue();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
///\file
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
The MIT License(MIT)
|
||||||
|
|
||||||
|
Embedded Template Library.
|
||||||
|
https://github.com/ETLCPP/etl
|
||||||
|
https://www.etlcpp.com
|
||||||
|
|
||||||
|
Copyright(c) 2017 jwellbelove
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files(the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions :
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ETL_PROFILE_H__
|
||||||
|
#define __ETL_PROFILE_H__
|
||||||
|
|
||||||
|
#define ETL_THROW_EXCEPTIONS
|
||||||
|
#define ETL_VERBOSE_ERRORS
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#include "etl/profiles/msvc_x86.h"
|
||||||
|
#else
|
||||||
|
#include "etl/profiles/gcc_windows_x86.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.26730.10
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QueuedMessageRouter", "QueuedMessageRouter.vcxproj", "{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x64.Build.0 = Release|x64
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {98B87835-6672-45D4-95BF-CC5C22C87D2C}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>15.0</VCProjectVersion>
|
||||||
|
<ProjectGuid>{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}</ProjectGuid>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<RootNamespace>QueuedMessageRouter</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>../../../include;../vs2017</AdditionalIncludeDirectories>
|
||||||
|
<PrecompiledHeaderFile />
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\QueuedMessageRouter.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\etl_profile.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5.0)
|
||||||
|
project(scheduler)
|
||||||
|
|
||||||
|
add_definitions(-DETL_DEBUG)
|
||||||
|
|
||||||
|
include_directories(${UTPP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/../../include)
|
||||||
|
|
||||||
|
set(SOURCE_FILES Scheduler.cpp)
|
||||||
|
|
||||||
|
add_executable(scheduler ${SOURCE_FILES})
|
||||||
|
target_include_directories(scheduler
|
||||||
|
PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
set_property(TARGET scheduler PROPERTY CXX_STANDARD 17)
|
||||||
|
|
||||||
184
Chapter15/observer/libs/etl/examples/Scheduler/Scheduler.cpp
Normal file
184
Chapter15/observer/libs/etl/examples/Scheduler/Scheduler.cpp
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
The MIT License(MIT)
|
||||||
|
|
||||||
|
Embedded Template Library.
|
||||||
|
https://github.com/ETLCPP/etl
|
||||||
|
https://www.etlcpp.com
|
||||||
|
|
||||||
|
Copyright(c) 2020 jwellbelove
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files(the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions :
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// This example demonstrates the basic method to schedule tasks.
|
||||||
|
// Experiment with the different scheduling policies.
|
||||||
|
//*****************************************************************************
|
||||||
|
|
||||||
|
#include "etl/scheduler.h"
|
||||||
|
#include "etl/task.h"
|
||||||
|
#include "etl/function.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// Task 1. Lowest priority.
|
||||||
|
//*****************************************************************************
|
||||||
|
class Task1 : public etl::task
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//*************************************
|
||||||
|
Task1()
|
||||||
|
: task(1)
|
||||||
|
, work(3)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************
|
||||||
|
uint32_t task_request_work() const
|
||||||
|
{
|
||||||
|
return work; // How much work do we still have to do? This could be a message queue length.
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************
|
||||||
|
void task_process_work()
|
||||||
|
{
|
||||||
|
std::cout << "Task1 : Process work : " << work << std::endl;
|
||||||
|
--work;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
uint32_t work;
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// Task 2. Highest priority.
|
||||||
|
//*****************************************************************************
|
||||||
|
class Task2 : public etl::task
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//*************************************
|
||||||
|
Task2()
|
||||||
|
: task(2)
|
||||||
|
, work(4)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************
|
||||||
|
uint32_t task_request_work() const
|
||||||
|
{
|
||||||
|
return work; // How much work do we still have to do? This could be a message queue length.
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************
|
||||||
|
void task_process_work()
|
||||||
|
{
|
||||||
|
std::cout << "Task2 : Process work : " << work << std::endl;
|
||||||
|
--work;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
uint32_t work;
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// The idle handler.
|
||||||
|
//*****************************************************************************
|
||||||
|
class Idle
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//*************************************
|
||||||
|
Idle(etl::ischeduler& scheduler_)
|
||||||
|
: scheduler(scheduler_)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//*************************************
|
||||||
|
void IdleCallback()
|
||||||
|
{
|
||||||
|
std::cout << "Idle callback" << std::endl;
|
||||||
|
scheduler.exit_scheduler();
|
||||||
|
std::cout << "Exiting the scheduler" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
etl::ischeduler& scheduler;
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// The watchdog handler.
|
||||||
|
//*****************************************************************************
|
||||||
|
void WatchdogCallback()
|
||||||
|
{
|
||||||
|
std::cout << "Watchdog callback" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// The scheduler.
|
||||||
|
// Maximum of two tasks.
|
||||||
|
//
|
||||||
|
// Try the other scheduler policies to see how scheduling differs.
|
||||||
|
// etl::scheduler_policy_sequential_single
|
||||||
|
// etl::scheduler_policy_sequential_multiple
|
||||||
|
// etl::scheduler_policy_highest_priority
|
||||||
|
// etl::scheduler_policy_most_work
|
||||||
|
//*****************************************************************************
|
||||||
|
class Scheduler : public etl::scheduler<etl::scheduler_policy_sequential_single, 2>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// The test application.
|
||||||
|
//*****************************************************************************
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
Scheduler scheduler;
|
||||||
|
|
||||||
|
Task1 task1;
|
||||||
|
Task2 task2;
|
||||||
|
|
||||||
|
Idle idleHandler(scheduler);
|
||||||
|
|
||||||
|
etl::function_mv<Idle, &Idle::IdleCallback> idleCallback(idleHandler); // Member function, no parameters, returning void.
|
||||||
|
etl::function_fv<WatchdogCallback> watchdogCallback; // Global function, no parameters, returning void.
|
||||||
|
|
||||||
|
scheduler.add_task(task1);
|
||||||
|
scheduler.add_task(task2);
|
||||||
|
scheduler.set_idle_callback(idleCallback);
|
||||||
|
scheduler.set_watchdog_callback(watchdogCallback);
|
||||||
|
|
||||||
|
std::cout << "Starting the scheduler" << std::endl;
|
||||||
|
|
||||||
|
scheduler.start();
|
||||||
|
|
||||||
|
std::cout << "Exiting the application" << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
43
Chapter15/observer/libs/etl/examples/Scheduler/etl_profile.h
Normal file
43
Chapter15/observer/libs/etl/examples/Scheduler/etl_profile.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
///\file
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
The MIT License(MIT)
|
||||||
|
|
||||||
|
Embedded Template Library.
|
||||||
|
https://github.com/ETLCPP/etl
|
||||||
|
https://www.etlcpp.com
|
||||||
|
|
||||||
|
Copyright(c) 2020 jwellbelove
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files(the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions :
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ETL_PROFILE_H__
|
||||||
|
#define __ETL_PROFILE_H__
|
||||||
|
|
||||||
|
#define ETL_THROW_EXCEPTIONS
|
||||||
|
#define ETL_VERBOSE_ERRORS
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#include "etl/profiles/msvc_x86.h"
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#include "etl/profiles/gcc_generic.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.26730.10
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Scheduler", "Scheduler.vcxproj", "{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x64.Build.0 = Release|x64
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {98B87835-6672-45D4-95BF-CC5C22C87D2C}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>15.0</VCProjectVersion>
|
||||||
|
<ProjectGuid>{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}</ProjectGuid>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<RootNamespace>Scheduler</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>../../../include;../vs2017</AdditionalIncludeDirectories>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>../../../include;../vs2017</AdditionalIncludeDirectories>
|
||||||
|
<PrecompiledHeaderFile />
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\Scheduler.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\etl_profile.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.26730.10
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Scheduler", "Scheduler.vcxproj", "{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x64.Build.0 = Release|x64
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {98B87835-6672-45D4-95BF-CC5C22C87D2C}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>15.0</VCProjectVersion>
|
||||||
|
<ProjectGuid>{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}</ProjectGuid>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<RootNamespace>Scheduler</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>../../../include;../vs2017</AdditionalIncludeDirectories>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>../../../include;../vs2017</AdditionalIncludeDirectories>
|
||||||
|
<PrecompiledHeaderFile />
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\Scheduler.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\etl_profile.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5.0)
|
||||||
|
project(SharedMessage)
|
||||||
|
|
||||||
|
add_definitions(-DETL_DEBUG)
|
||||||
|
|
||||||
|
include_directories(${UTPP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/../../include)
|
||||||
|
|
||||||
|
set(SOURCE_FILES SharedMessage.cpp)
|
||||||
|
|
||||||
|
add_executable(SharedMessage ${SOURCE_FILES})
|
||||||
|
target_include_directories(SharedMessage
|
||||||
|
PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
set_property(TARGET SharedMessage PROPERTY CXX_STANDARD 17)
|
||||||
|
|
||||||
@@ -0,0 +1,285 @@
|
|||||||
|
//*****************************************************************************
|
||||||
|
// Shared message example
|
||||||
|
//*****************************************************************************
|
||||||
|
|
||||||
|
#include "etl/shared_message.h"
|
||||||
|
#include "etl/message.h"
|
||||||
|
#include "etl/reference_counted_message_pool.h"
|
||||||
|
#include "etl/message_router.h"
|
||||||
|
#include "etl/message_bus.h"
|
||||||
|
#include "etl/fixed_sized_memory_block_allocator.h"
|
||||||
|
#include "etl/queue.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <atomic>
|
||||||
|
#include <string>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
constexpr etl::message_router_id_t RouterId1 = 1U;
|
||||||
|
constexpr etl::message_router_id_t RouterId2 = 2U;
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// Message1
|
||||||
|
//*****************************************************************************
|
||||||
|
struct Message1 : public etl::message<1>
|
||||||
|
{
|
||||||
|
Message1(std::string s_)
|
||||||
|
: s(s_)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string s;
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// Message2
|
||||||
|
//*****************************************************************************
|
||||||
|
struct Message2 : public etl::message<2>
|
||||||
|
{
|
||||||
|
Message2(std::string s_)
|
||||||
|
: s(s_)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string s;
|
||||||
|
char data[100];
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// Message3
|
||||||
|
//*****************************************************************************
|
||||||
|
struct Message3 : public etl::message<3>
|
||||||
|
{
|
||||||
|
Message3(std::string s_)
|
||||||
|
: s(s_)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string s;
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// Prints the shared message
|
||||||
|
//*****************************************************************************
|
||||||
|
void Print(const std::string& prefix, etl::shared_message sm)
|
||||||
|
{
|
||||||
|
std::cout << prefix << " : Message Id = " << int(sm.get_message().get_message_id()) << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// This router accepts Message1, Message2 and Message3 types.
|
||||||
|
// If a shared message it received, it will be processed immediately.
|
||||||
|
//*****************************************************************************
|
||||||
|
class MessageRouter1 : public etl::message_router<MessageRouter1, Message1, Message2, Message3>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//****************************************
|
||||||
|
MessageRouter1()
|
||||||
|
: message_router(RouterId1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//****************************************
|
||||||
|
void on_receive(const Message1& msg)
|
||||||
|
{
|
||||||
|
std::cout << "MessageRouter1 : on_receive Message1 : " << msg.s << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//****************************************
|
||||||
|
void on_receive(const Message2& msg)
|
||||||
|
{
|
||||||
|
std::cout << "MessageRouter1 : on_receive Message2 : " << msg.s << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//****************************************
|
||||||
|
void on_receive(const Message3& msg)
|
||||||
|
{
|
||||||
|
std::cout << "MessageRouter1 : on_receive Message3 : " << msg.s << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//****************************************
|
||||||
|
void on_receive_unknown(const etl::imessage& msg)
|
||||||
|
{
|
||||||
|
std::cout << "MessageRouter1 : on_receive Unknown\n";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// This router accepts Message1, Message2 and Message3 types.
|
||||||
|
// If a shared message it received it will queue them.
|
||||||
|
// The messages will be processed when process_queue() is called.
|
||||||
|
//*****************************************************************************
|
||||||
|
class MessageRouter2 : public etl::message_router<MessageRouter2, Message1, Message2, Message3>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
using base_t = etl::message_router<MessageRouter2, Message1, Message2, Message3>;
|
||||||
|
|
||||||
|
//****************************************
|
||||||
|
MessageRouter2()
|
||||||
|
: message_router(RouterId2)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
using base_t::receive;
|
||||||
|
|
||||||
|
//****************************************
|
||||||
|
// Overridden receive.
|
||||||
|
// Puts the shared messages into a queue.
|
||||||
|
void receive(etl::shared_message shared_msg) override
|
||||||
|
{
|
||||||
|
if (!queue.full())
|
||||||
|
{
|
||||||
|
Print("MessageRouter2 : Queueing shared message", shared_msg);
|
||||||
|
|
||||||
|
queue.push(shared_msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//****************************************
|
||||||
|
// Processes the queued shared messages.
|
||||||
|
void process_queue()
|
||||||
|
{
|
||||||
|
while (!queue.empty())
|
||||||
|
{
|
||||||
|
// Get the shared message from the queue.
|
||||||
|
etl::shared_message shared_msg = queue.front();
|
||||||
|
|
||||||
|
Print("MessageRouter2 : Process queued shared message", shared_msg);
|
||||||
|
|
||||||
|
// Send it to the base implementation for routing.
|
||||||
|
base_t::receive(shared_msg);
|
||||||
|
|
||||||
|
queue.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//****************************************
|
||||||
|
void on_receive(const Message1& msg)
|
||||||
|
{
|
||||||
|
std::cout << "MessageRouter2 : on_receive Message1 : " << msg.s << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//****************************************
|
||||||
|
void on_receive(const Message2& msg)
|
||||||
|
{
|
||||||
|
std::cout << "MessageRouter2 : on_receive Message2 : " << msg.s << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//****************************************
|
||||||
|
void on_receive(const Message3& msg)
|
||||||
|
{
|
||||||
|
std::cout << "MessageRouter2 : on_receive Message3 : " << msg.s << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//****************************************
|
||||||
|
void on_receive_unknown(const etl::imessage& msg)
|
||||||
|
{
|
||||||
|
std::cout << "MessageRouter2 : on_receive Unknown\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
etl::queue<etl::shared_message, 10> queue;
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// A message bus that can accommodate two subscribers.
|
||||||
|
//*****************************************************************************
|
||||||
|
struct Bus : public etl::message_bus<2U>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// Define the routers and bus.
|
||||||
|
//*****************************************************************************
|
||||||
|
MessageRouter1 router1;
|
||||||
|
MessageRouter2 router2;
|
||||||
|
Bus bus;
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// The thread safe message pool. Uses atomic uint32_t for counting.
|
||||||
|
class MessagePool : public etl::reference_counted_message_pool<std::atomic_int32_t>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
MessagePool(etl::imemory_block_allocator& allocator)
|
||||||
|
: reference_counted_message_pool(allocator)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called before the memory block allocator is accessed.
|
||||||
|
void lock() override
|
||||||
|
{
|
||||||
|
mut.lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called after the memory block allocator has been accessed.
|
||||||
|
void unlock() override
|
||||||
|
{
|
||||||
|
mut.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::mutex mut;
|
||||||
|
};
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// The memory block allocator that supplies the pool with memory
|
||||||
|
// to store reference counted messages in.
|
||||||
|
|
||||||
|
// The reference counted message parameters type for the messages we will use.
|
||||||
|
using message_parameters_small = MessagePool::pool_message_parameters<Message1, Message3>;
|
||||||
|
using message_parameters_large = MessagePool::pool_message_parameters<Message2>;
|
||||||
|
|
||||||
|
constexpr size_t max_size_small = message_parameters_small::max_size;
|
||||||
|
constexpr size_t max_alignment_small = message_parameters_small::max_alignment;
|
||||||
|
|
||||||
|
constexpr size_t max_size_large = message_parameters_large::max_size;
|
||||||
|
constexpr size_t max_alignment_large = message_parameters_large::max_alignment;
|
||||||
|
|
||||||
|
// A fixed memory block allocator for 4 items, using the parameters from the smaller messages.
|
||||||
|
etl::fixed_sized_memory_block_allocator<max_size_small, max_alignment_small, 4U> memory_allocator;
|
||||||
|
|
||||||
|
// A fixed memory block allocator for 4 items, using the parameters from the larger message.
|
||||||
|
etl::fixed_sized_memory_block_allocator<max_size_large, max_alignment_large, 4U> memory_allocator_successor;
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// The pool that supplies reference counted messages.
|
||||||
|
// Uses memory_allocator as its allocator.
|
||||||
|
//*****************************************************************************
|
||||||
|
MessagePool message_pool(memory_allocator);
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
// A statically allocated reference counted message that is never allocated or released by a pool.
|
||||||
|
// Contains a copy of Message3("Three").
|
||||||
|
//*****************************************************************************
|
||||||
|
etl::persistent_message<Message3> pm3(Message3("Three"));
|
||||||
|
|
||||||
|
//*****************************************************************************
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// If memory_allocator can't allocate, then try memory_allocator_successor.
|
||||||
|
memory_allocator.set_successor(memory_allocator_successor);
|
||||||
|
|
||||||
|
Message1 m1("One");
|
||||||
|
Message2 m2("Two");
|
||||||
|
|
||||||
|
etl::shared_message sm1(message_pool, m1); // Created a shared message by allocating a reference counted message from message_pool containing a copy of m1.
|
||||||
|
etl::shared_message sm2(message_pool, m2); // Created a shared message by allocating a reference counted message from message_pool containing a copy of m2.
|
||||||
|
etl::shared_message sm3(pm3); // Created a shared message from a statically allocated persistent message.
|
||||||
|
|
||||||
|
bus.subscribe(router1); // Subscribe router1 to the bus.
|
||||||
|
bus.subscribe(router2); // Subscribe router2 to the bus.
|
||||||
|
|
||||||
|
bus.receive(sm1); // Send sm1 to the bus for distribution to the routers.
|
||||||
|
bus.receive(sm2); // Send sm2 to the bus for distribution to the routers.
|
||||||
|
bus.receive(sm3); // Send sm3 to the bus for distribution to the routers.
|
||||||
|
|
||||||
|
router2.process_queue(); // Allow router2 to process its queued messages.
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 16
|
||||||
|
VisualStudioVersion = 16.0.30804.86
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SharedMessage", "SharedMessage.vcxproj", "{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}.Release|x64.Build.0 = Release|x64
|
||||||
|
{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {F7B7515D-19FA-42D4-9BA2-5F85A7FB7779}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>16.0</VCProjectVersion>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<ProjectGuid>{0bdb4f2a-47e7-4105-a66a-6dff8a76587b}</ProjectGuid>
|
||||||
|
<RootNamespace>SharedMessage</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>D:\Users\John\Documents\Programming\GitHub\etl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="SharedMessage.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\..\include\etl\atomic.h" />
|
||||||
|
<ClInclude Include="..\..\include\etl\fixed_sized_memory_block_allocator.h" />
|
||||||
|
<ClInclude Include="..\..\include\etl\imemory_block_allocator.h" />
|
||||||
|
<ClInclude Include="..\..\include\etl\ireference_counted_message_pool.h" />
|
||||||
|
<ClInclude Include="..\..\include\etl\message.h" />
|
||||||
|
<ClInclude Include="..\..\include\etl\message_bus.h" />
|
||||||
|
<ClInclude Include="..\..\include\etl\message_router.h" />
|
||||||
|
<ClInclude Include="..\..\include\etl\message_types.h" />
|
||||||
|
<ClInclude Include="..\..\include\etl\reference_counted_message.h" />
|
||||||
|
<ClInclude Include="..\..\include\etl\reference_counted_message_pool.h" />
|
||||||
|
<ClInclude Include="..\..\include\etl\reference_counted_object.h" />
|
||||||
|
<ClInclude Include="..\..\include\etl\shared_message.h" />
|
||||||
|
<ClInclude Include="..\..\include\etl\successor.h" />
|
||||||
|
<ClInclude Include="etl_profile.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
7
Chapter15/observer/libs/etl/examples/platformio/.gitignore
vendored
Normal file
7
Chapter15/observer/libs/etl/examples/platformio/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
||||||
|
.vscode/settings.json
|
||||||
|
lib/etl
|
||||||
16
Chapter15/observer/libs/etl/examples/platformio/README.md
Normal file
16
Chapter15/observer/libs/etl/examples/platformio/README.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
ETL PlatformIO demo
|
||||||
|
===================
|
||||||
|
|
||||||
|
> Template to demonstrate how to use ETL with PlatformIO.
|
||||||
|
|
||||||
|
1. Open this folder in VSCode and agree if it suggests to install extension.
|
||||||
|
2. Use `Terminal -> Run Build Task... -> PlatformIO: Build` menu to compile.
|
||||||
|
3. Run `.pio/Build/native/program`.
|
||||||
|
|
||||||
|
## Details
|
||||||
|
|
||||||
|
Use `platformio.ini` for example, see comments inside.
|
||||||
|
|
||||||
|
`include` folder contains config, required for `etl`. All is as transparent
|
||||||
|
as possible. Set all additional variables via `build_flags` option in
|
||||||
|
`platform.ini`. Currently only `PROFILE_GCC_GENERIC` set to make things work.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
#include "etl/profiles/etl_profile.h"
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; http://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[platformio]
|
||||||
|
default_envs = native
|
||||||
|
|
||||||
|
[env:native]
|
||||||
|
platform = native
|
||||||
|
build_flags =
|
||||||
|
; ETL configs in `include` folder are minimalistic. Here we can set all
|
||||||
|
; additional definitions to keep everything in one place and customize values
|
||||||
|
; for different target platforms
|
||||||
|
-D PROFILE_GCC_GENERIC
|
||||||
|
lib_deps =
|
||||||
|
; Define ETL dependency for this demo. You can use versions from PIO registry,
|
||||||
|
; or git repository with specific branch, tag or commit. See PIO docs for
|
||||||
|
; details.
|
||||||
|
;Embedded Template Library=https://github.com/ETLCPP/etl/archive/master.zip
|
||||||
|
Embedded Template Library@^14.31.2
|
||||||
|
|
||||||
142
Chapter15/observer/libs/etl/examples/platformio/src/main.cpp
Normal file
142
Chapter15/observer/libs/etl/examples/platformio/src/main.cpp
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "etl/observer.h"
|
||||||
|
|
||||||
|
// Position data.
|
||||||
|
struct Position
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Button data.
|
||||||
|
struct Button
|
||||||
|
{
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
Down,
|
||||||
|
Up
|
||||||
|
};
|
||||||
|
|
||||||
|
int state;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Wheel data.
|
||||||
|
struct Wheel
|
||||||
|
{
|
||||||
|
int delta;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Definition of a mouse observer.
|
||||||
|
typedef etl::observer<const Position&, Button, Wheel> Mouse_Observer;
|
||||||
|
|
||||||
|
// Definition of an event handler for mouse notifications.
|
||||||
|
class Event_Handler1 : public Mouse_Observer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Handle a position notification.
|
||||||
|
void notification(const Position& position)
|
||||||
|
{
|
||||||
|
std::cout << "Event_Handler1 : Position = " << position.x << "," << position.y << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle a button notification.
|
||||||
|
void notification(Button button)
|
||||||
|
{
|
||||||
|
std::cout << "Event_Handler1 : Button = " << ((button.state == Button::Up) ? "Up\n" : "Down\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle a wheel notification.
|
||||||
|
void notification(Wheel wheel)
|
||||||
|
{
|
||||||
|
std::cout << "Event_Handler1 : Wheel delta = " << wheel.delta << "\n";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Definition of a second event handler for mouse notifications.
|
||||||
|
class Event_Handler2 : public Mouse_Observer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Handler a position notification.
|
||||||
|
void notification(const Position& position)
|
||||||
|
{
|
||||||
|
std::cout << "Event_Handler2 : Position = " << position.x << "," << position.y << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle a button notification.
|
||||||
|
void notification(Button button)
|
||||||
|
{
|
||||||
|
std::cout << "Event_Handler2 : Button = " << ((button.state == Button::Up) ? "Up\n" : "Down\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle a wheel notification.
|
||||||
|
void notification(Wheel wheel)
|
||||||
|
{
|
||||||
|
// Not interested in wheel deltas.
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// The observable mouse driver.
|
||||||
|
const int MAX_MOUSE_OBSERVERS = 2;
|
||||||
|
|
||||||
|
class Mouse_Driver : public etl::observable<Mouse_Observer, MAX_MOUSE_OBSERVERS>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Notify observers about a position event.
|
||||||
|
void Position_Event()
|
||||||
|
{
|
||||||
|
Position position = { 100, 200 };
|
||||||
|
notify_observers(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notify observers about a button up event.
|
||||||
|
void Button_Event_Up()
|
||||||
|
{
|
||||||
|
Button button = { Button::Up };
|
||||||
|
notify_observers(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notify observers about a button down event.
|
||||||
|
void Button_Event_Down()
|
||||||
|
{
|
||||||
|
Button button = { Button::Down };
|
||||||
|
notify_observers(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notify observers about a wheel up event.
|
||||||
|
void Wheel_Event_Up()
|
||||||
|
{
|
||||||
|
Wheel wheel = { 50 };
|
||||||
|
notify_observers(wheel);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notify observers about a wheel down event.
|
||||||
|
void Wheel_Event_Down()
|
||||||
|
{
|
||||||
|
Wheel wheel = { -25 };
|
||||||
|
notify_observers(wheel);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
Mouse_Driver mouse_driver;
|
||||||
|
Event_Handler1 event_handler1;
|
||||||
|
Event_Handler2 event_handler2;
|
||||||
|
|
||||||
|
// Tell the mouse driver about the observers.
|
||||||
|
mouse_driver.add_observer(event_handler1);
|
||||||
|
mouse_driver.add_observer(event_handler2);
|
||||||
|
|
||||||
|
// Generate some events.
|
||||||
|
mouse_driver.Button_Event_Down();
|
||||||
|
mouse_driver.Button_Event_Up();
|
||||||
|
mouse_driver.Position_Event();
|
||||||
|
mouse_driver.Wheel_Event_Down();
|
||||||
|
mouse_driver.Wheel_Event_Up();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
Chapter15/observer/libs/etl/images/ArcticCodeVault.png
Normal file
BIN
Chapter15/observer/libs/etl/images/ArcticCodeVault.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
9
Chapter15/observer/libs/etl/images/Coverty Shields.txt
Normal file
9
Chapter15/observer/libs/etl/images/Coverty Shields.txt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<a href="https://scan.coverity.com/projects/embedded-template-library">
|
||||||
|
<img alt="Coverity Scan Build Status"
|
||||||
|
src="https://scan.coverity.com/projects/30565/badge.svg"/>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="https://scan.coverity.com/projects/embedded-template-library">
|
||||||
|
<img alt="Coverity Scan Build Status"
|
||||||
|
src="https://img.shields.io/coverity/scan/30565.svg"/>
|
||||||
|
</a>
|
||||||
BIN
Chapter15/observer/libs/etl/images/etl-round.png
Normal file
BIN
Chapter15/observer/libs/etl/images/etl-round.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 33 KiB |
BIN
Chapter15/observer/libs/etl/images/etl.ico
Normal file
BIN
Chapter15/observer/libs/etl/images/etl.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
Chapter15/observer/libs/etl/images/etl.png
Normal file
BIN
Chapter15/observer/libs/etl/images/etl.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
BIN
Chapter15/observer/libs/etl/images/etl.xar
Normal file
BIN
Chapter15/observer/libs/etl/images/etl.xar
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user