├── .gitignore ├── .gitmodules ├── COPYING ├── README.md ├── TODO ├── arch └── arm │ └── cortex │ ├── common │ ├── bitband.hpp │ ├── core.hpp │ ├── dwt.hpp │ ├── nvic.hpp │ ├── reg │ │ ├── debug.hpp │ │ ├── dwt.hpp │ │ ├── mpu.hpp │ │ ├── nvic.hpp │ │ └── scb.hpp │ ├── scb.hpp │ ├── systick.hpp │ └── vector_table.hpp │ └── stm32 │ ├── common │ ├── reg │ │ ├── STM_License.html │ │ ├── spi.hpp │ │ ├── tim.hpp │ │ └── usart.hpp │ ├── spi.hpp │ ├── usart.hpp │ └── usart_stream.hpp │ ├── f1 │ └── include │ │ └── arch │ │ ├── adc.hpp │ │ ├── bitband.hpp │ │ ├── core.hpp │ │ ├── dwt.hpp │ │ ├── flash.hpp │ │ ├── gpio.hpp │ │ ├── nvic.hpp │ │ ├── pwr.hpp │ │ ├── rcc.hpp │ │ ├── reg │ │ ├── STM_License.html │ │ ├── adc.hpp │ │ ├── address_map.hpp │ │ ├── flash.hpp │ │ ├── gpio.hpp │ │ ├── pwr.hpp │ │ ├── rcc.hpp │ │ ├── rtc.hpp │ │ ├── spi.hpp │ │ ├── tim.hpp │ │ └── usart.hpp │ │ ├── rtc.hpp │ │ ├── scb.hpp │ │ ├── spi.hpp │ │ ├── systick.hpp │ │ ├── usart.hpp │ │ ├── usart_stream.hpp │ │ └── vector_table.hpp │ └── f4 │ └── include │ └── arch │ ├── bitband.hpp │ ├── core.hpp │ ├── dwt.hpp │ ├── flash.hpp │ ├── gpio.hpp │ ├── nvic.hpp │ ├── pwr.hpp │ ├── rcc.hpp │ ├── reg │ ├── STM_License.html │ ├── address_map.hpp │ ├── flash.hpp │ ├── gpio.hpp │ ├── pwr.hpp │ ├── rcc.hpp │ ├── spi.hpp │ ├── tim.hpp │ └── usart.hpp │ ├── scb.hpp │ ├── spi.hpp │ ├── systick.hpp │ ├── usart.hpp │ ├── usart_stream.hpp │ └── vector_table.hpp ├── bin └── sim_terminal.sh ├── config ├── boost.mk ├── clang.mk ├── doxygen.mk ├── gcc.mk ├── gdb-target.xml ├── openmptl.mk ├── openocd.mk ├── simulation.mk └── system.mk ├── doc ├── .gitignore ├── Makefile ├── arm_cortex_common.conf ├── doxygen.conf ├── drivers.conf ├── lib.conf ├── mainpage.md ├── openmptl.conf ├── stm32_common.conf ├── stm32f10x.conf └── stm32f4.conf ├── drivers ├── joystick │ └── stm32f103stk │ │ └── joystick.hpp ├── lcd │ └── nokia3310 │ │ ├── lcd.hpp │ │ └── lcd_font_5x8.cpp └── rf │ └── nrf24l01 │ └── nrf24l01.hpp ├── include ├── compiler.h ├── crt.hpp ├── fifo.hpp ├── freq.hpp ├── gpio_base.hpp ├── isr.hpp ├── register.hpp ├── register_access.hpp ├── register_manip.hpp ├── register_mpl.hpp ├── register_sim.hpp ├── register_type.hpp ├── simulation.hpp ├── typelist.hpp ├── typelist_mpl.hpp └── voltage.hpp ├── lib └── include │ ├── debouncer.hpp │ ├── fifo_stream.hpp │ ├── poorman_cstring.hpp │ ├── poorman_ostream.hpp │ ├── terminal.hpp │ └── terminal_sim.hpp ├── projects ├── stm32f103stk-demo │ ├── .gitignore │ ├── Makefile │ ├── resources │ │ ├── README.md │ │ └── tinyfsm-0.2.0 │ │ │ ├── COPYING │ │ │ ├── README.md │ │ │ └── include │ │ │ └── tinyfsm.hpp │ ├── src │ │ ├── debug.hpp │ │ ├── events.hpp │ │ ├── fsmlist.hpp │ │ ├── heap_eater.cpp │ │ ├── kernel.cpp │ │ ├── kernel.hpp │ │ ├── nrftest.cpp │ │ ├── screen.cpp │ │ ├── screen.hpp │ │ ├── screen_item.cpp │ │ ├── screen_item.hpp │ │ ├── sim_reactions.cpp │ │ ├── startup.cpp │ │ ├── syscalls.cpp │ │ ├── terminal_hooks.hpp │ │ ├── time.cpp │ │ ├── time.hpp │ │ └── timepoint.hpp │ └── stm32f10x_flash_md.ld ├── stm32f4discovery-ledtest │ ├── .gitignore │ ├── Makefile │ ├── src │ │ └── ledtest.cpp │ └── stm32f40x_flash.ld ├── stm32f4discovery │ ├── .gitignore │ ├── Makefile │ ├── src │ │ ├── kernel.cpp │ │ ├── kernel.hpp │ │ ├── sim_reactions.cpp │ │ ├── startup.cpp │ │ └── terminal_hooks.hpp │ └── stm32f40x_flash.ld └── unittest │ ├── .gitignore │ ├── Makefile │ ├── create_fail_src.pl │ └── src │ ├── register.cpp │ ├── reglist.cpp │ ├── tuple_test.cpp │ ├── typelist.cpp │ └── vector_table.cpp └── sim └── register_sim.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | /compiler-rt 2 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "projects/stm32f103stk-demo/resources/tinyfsm-git"] 2 | path = projects/stm32f103stk-demo/resources/tinyfsm-git 3 | url = https://dev.tty0.ch/tinyfsm.git 4 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | - implement compile-time sorting of reglist<> (by addr), which can produce speedup in reset_to() 2 | 3 | - scb priority grouping 4 | - nvic priority grouping 5 | -------------------------------------------------------------------------------- /arch/arm/cortex/common/bitband.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARM_CORTEX_COMMON_BITBAND_HPP_INCLUDED 22 | #define ARM_CORTEX_COMMON_BITBAND_HPP_INCLUDED 23 | 24 | #include 25 | 26 | namespace mptl { 27 | 28 | struct bitband_periph 29 | { 30 | static constexpr reg_addr_t region_start = 0x40000000; 31 | static constexpr reg_addr_t region_end = 0x40100000; 32 | static constexpr reg_addr_t alias_base = 0x42000000; 33 | 34 | using value_type = uint32_t; 35 | 36 | static constexpr bool covered(reg_addr_t addr) { 37 | return (addr >= region_start) && (addr < region_end); 38 | } 39 | 40 | template 41 | static __always_inline void bitset(void) { 42 | // static_assert(covered(addr), "addr is not covered by the bit-band region"); 43 | static constexpr reg_addr_t addr_bb = alias_base + ((addr - region_start) * 32) + (bit_no * 4); 44 | *reinterpret_cast(addr_bb) = 1; 45 | } 46 | 47 | template 48 | static __always_inline void bitclear(void) { 49 | // static_assert(covered(addr), "addr is not covered by the bit-band region"); 50 | static constexpr reg_addr_t addr_bb = alias_base + ((addr - region_start) * 32) + (bit_no * 4); 51 | *reinterpret_cast(addr_bb) = 0; 52 | } 53 | 54 | template 55 | static __always_inline bool bittest(void) { 56 | // static_assert(covered(addr), "addr is not covered by the bit-band region"); 57 | static constexpr reg_addr_t addr_bb = alias_base + ((addr - region_start) * 32) + (bit_no * 4); 58 | return *reinterpret_cast(addr_bb); 59 | } 60 | }; 61 | 62 | 63 | 64 | } // namespace mptl 65 | 66 | #endif // ARM_CORTEX_COMMON_BITBAND_HPP_INCLUDED 67 | -------------------------------------------------------------------------------- /arch/arm/cortex/common/core.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARM_CORTEX_COMMON_CORE_HPP_INCLUDED 22 | #define ARM_CORTEX_COMMON_CORE_HPP_INCLUDED 23 | 24 | #include 25 | #include 26 | 27 | namespace mptl { 28 | 29 | struct core_base 30 | { 31 | static void enable_irq() { __asm volatile ("cpsie i"); } /**< global interrupt enable */ 32 | static void disable_irq() { __asm volatile ("cpsid i"); } /**< global interrupt disable */ 33 | 34 | static void enable_fault_irq() { __asm volatile ("cpsie f"); } 35 | static void disable_fault_irq() { __asm volatile ("cpsid f"); } 36 | 37 | static void nop() { __asm volatile ("nop"); } 38 | static void wfi() { __asm volatile ("wfi"); } 39 | static void wfe() { __asm volatile ("wfe"); } 40 | static void sev() { __asm volatile ("sev"); } 41 | static void isb() { __asm volatile ("isb"); } 42 | static void dsb() { __asm volatile ("dsb"); } 43 | static void dmb() { __asm volatile ("dmb"); } 44 | static void clrex() { __asm volatile ("clrex"); } 45 | 46 | static void nop(unsigned value) { while(value--) nop(); } 47 | 48 | /* Startup code. 49 | * 50 | * - Initialize data and bss section 51 | * - Set early-config registers 52 | * - Set system clock 53 | * 54 | * Template arguments: 55 | * 56 | * - system_clock_type: class providing init() and configure() 57 | * static member functions. 58 | * 59 | * - early_cfg_list: list of regmask<> or reglist<> type traits to 60 | * be set before the system clock is configured. 61 | */ 62 | template< 63 | typename system_clock_type, 64 | typename... early_cfg_list 65 | > 66 | static void startup(void) { 67 | crt::init_data_section(); 68 | crt::init_bss_section(); 69 | 70 | system_clock_type::init(); 71 | reglist< early_cfg_list... >::reset_to(); 72 | system_clock_type::configure(); 73 | 74 | crt::run_preinit_array(); 75 | crt::run_init_array(); /* call ctors */ 76 | } 77 | }; 78 | 79 | } // namespace mptl 80 | 81 | #endif // ARM_CORTEX_COMMON_CORE_HPP_INCLUDED 82 | -------------------------------------------------------------------------------- /arch/arm/cortex/common/dwt.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARM_CORTEX_COMMON_DWT_HPP_INCLUDED 22 | #define ARM_CORTEX_COMMON_DWT_HPP_INCLUDED 23 | 24 | #include "reg/dwt.hpp" 25 | #include "reg/debug.hpp" 26 | 27 | namespace mptl { 28 | 29 | class dwt 30 | { 31 | public: 32 | 33 | static void enable(void) { 34 | DEBUG::DEMCR::TRCENA::set(); 35 | } 36 | 37 | static void disable(void) { 38 | DEBUG::DEMCR::TRCENA::clear(); 39 | } 40 | 41 | static void cycle_counter_enable(void) { 42 | DWT::CYCCNT::store(0); // reset counter 43 | DWT::CTRL::set(1); // enable counter 44 | } 45 | 46 | static DWT::CYCCNT::value_type cycle_counter_load(void) { 47 | return DWT::CYCCNT::load(); 48 | } 49 | }; 50 | 51 | 52 | /** 53 | * Cycle counter: Count processor clock cycles 54 | */ 55 | class cycle_counter 56 | { 57 | using value_type = decltype(dwt::cycle_counter_load()); 58 | 59 | value_type value; 60 | 61 | public: 62 | 63 | cycle_counter(void) : value(0) { 64 | dwt::enable(); 65 | dwt::cycle_counter_enable(); 66 | } 67 | 68 | ~cycle_counter(void) { 69 | dwt::disable(); 70 | } 71 | 72 | void start(void) { 73 | value = dwt::cycle_counter_load(); 74 | } 75 | 76 | void stop(void) { 77 | value = dwt::cycle_counter_load() - value; 78 | } 79 | 80 | value_type get(void) { 81 | return value; 82 | } 83 | }; 84 | 85 | } // namespace mptl 86 | 87 | #endif // ARM_CORTEX_COMMON_DWT_HPP_INCLUDED 88 | -------------------------------------------------------------------------------- /arch/arm/cortex/common/reg/debug.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARM_CORTEX_COMMON_REG_DEBUG_HPP_INCLUDED 22 | #define ARM_CORTEX_COMMON_REG_DEBUG_HPP_INCLUDED 23 | 24 | #include 25 | 26 | namespace mptl { 27 | 28 | /** 29 | * Debug Register 30 | * 31 | * For details, see "Cortex-M3 Technical Reference Manual": 32 | * 33 | */ 34 | struct DEBUG 35 | { 36 | using DFSR = reg; /**< Debug Fault Status Register */ 37 | using DHCSR = reg; /**< Debug Halting Control and Status Register */ 38 | using DCRSR = reg; /**< Debug Core Register Selector Register */ 39 | using DCRDR = reg; /**< Debug Core Register Data Register */ 40 | 41 | /** 42 | * Debug Exception and Monitor Control Register 43 | */ 44 | struct DEMCR 45 | : public reg 46 | { 47 | using TRCENA = regbits< type, 24, 1 >; /**< Enable DWT */ 48 | }; 49 | }; 50 | 51 | } // namespace mptl 52 | 53 | #endif // ARM_CORTEX_COMMON_REG_DEBUG_HPP_INCLUDED 54 | -------------------------------------------------------------------------------- /arch/arm/cortex/common/reg/dwt.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARM_CORTEX_COMMON_REG_DWT_HPP_INCLUDED 22 | #define ARM_CORTEX_COMMON_REG_DWT_HPP_INCLUDED 23 | 24 | #include 25 | 26 | namespace mptl { 27 | 28 | /** 29 | * DWT Register 30 | * 31 | * For details, see "Cortex-M3 Technical Reference Manual": 32 | * 33 | */ 34 | struct DWT 35 | { 36 | using CTRL = reg; /**< Control Register */ 37 | using CYCCNT = reg; /**< Cycle Count Register */ 38 | using CPICNT = reg; /**< CPI Count Register */ 39 | using EXCCNT = reg; /**< Exception Overhead Count Register */ 40 | using SLEEPCNT = reg; /**< Sleep Count Register */ 41 | using LSUCNT = reg; /**< LSU Count Register */ 42 | using FOLDCNT = reg; /**< Folded-instruction Count Register */ 43 | using PCSR = reg; /**< Program Counter Sample Register */ 44 | using COMP0 = reg; /**< Comparator Register0 */ 45 | using MASK0 = reg; /**< Mask Register0 */ 46 | using FUNCTION0 = reg; /**< Function Register0 */ 47 | using COMP1 = reg; /**< Comparator Register1 */ 48 | using MASK1 = reg; /**< Mask Register1 */ 49 | using FUNCTION1 = reg; /**< Function Register1 */ 50 | using COMP2 = reg; /**< Comparator Register2 */ 51 | using MASK2 = reg; /**< Mask Register2 */ 52 | using FUNCTION2 = reg; /**< Function Register2 */ 53 | using COMP3 = reg; /**< Comparator Register3 */ 54 | using MASK3 = reg; /**< Mask Register3 */ 55 | using FUNCTION3 = reg; /**< Function Register3 */ 56 | using PID4 = reg; /**< Peripheral identification registers */ 57 | using PID5 = reg; 58 | using PID6 = reg; 59 | using PID7 = reg; 60 | using PID0 = reg; 61 | using PID1 = reg; 62 | using PID2 = reg; 63 | using PID3 = reg; 64 | using CID0 = reg; /**< Component identification registers */ 65 | using CID1 = reg; 66 | using CID2 = reg; 67 | using CID3 = reg; 68 | }; 69 | 70 | } // namespace mptl 71 | 72 | #endif // ARM_CORTEX_COMMON_REG_DWT_HPP_INCLUDED 73 | -------------------------------------------------------------------------------- /arch/arm/cortex/common/reg/mpu.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARM_CORTEX_COMMON_REG_MPU_HPP_INCLUDED 22 | #define ARM_CORTEX_COMMON_REG_MPU_HPP_INCLUDED 23 | 24 | #include 25 | 26 | namespace mptl { 27 | 28 | /** 29 | * MPU (Memory Protection Unit) Register 30 | * 31 | * For details, see "Cortex-M3 Technical Reference Manual": 32 | * 33 | */ 34 | struct MPU 35 | { 36 | using TYPE = reg< uint32_t, 0xE000ED90, ro, 0x00000800 >; /**< MPU Type Register */ 37 | using CTRL = reg< uint32_t, 0xE000ED94, rw >; /**< MPU Control Register */ 38 | using RNR = reg< uint32_t, 0xE000ED98, rw >; /**< MPU Region Number Register */ 39 | using RBAR = reg< uint32_t, 0xE000ED9C, rw >; /**< MPU Region Base Address Register */ 40 | using RASR = reg< uint32_t, 0xE000EDA0, rw >; /**< MPU Region Attribute and Size Register */ 41 | using RBAR_A1 = reg< uint32_t, 0xE000EDA4, rw >; /**< MPU alias registers */ 42 | using RASR_A1 = reg< uint32_t, 0xE000EDA8, rw >; /**< */ 43 | using RBAR_A2 = reg< uint32_t, 0xE000EDAC, rw >; /**< */ 44 | using RASR_A2 = reg< uint32_t, 0xE000EDB0, rw >; /**< */ 45 | using RBAR_A3 = reg< uint32_t, 0xE000EDB4, rw >; /**< */ 46 | using RASR_A3 = reg< uint32_t, 0xE000EDB8, rw >; /**< */ 47 | }; 48 | 49 | } // namespace mptl 50 | 51 | #endif // ARM_CORTEX_COMMON_REG_MPU_HPP_INCLUDED 52 | -------------------------------------------------------------------------------- /arch/arm/cortex/common/reg/nvic.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARM_CORTEX_COMMON_REG_NVIC_HPP_INCLUDED 22 | #define ARM_CORTEX_COMMON_REG_NVIC_HPP_INCLUDED 23 | 24 | #include 25 | 26 | namespace mptl { 27 | 28 | /** 29 | * NVIC (Nested Vectored Interrupt Controller) Register 30 | * 31 | * For details, see "Cortex-M3 Technical Reference Manual": 32 | * 33 | */ 34 | struct NVIC 35 | { 36 | /** Interrupt Controller Type Register */ 37 | using ICTR = reg< uint32_t, 0xE000E004, ro >; 38 | 39 | // TODO: The following registers are actually only 8bit wide. 40 | // Check if access is better using 32bit or 8bit pointer 41 | 42 | /** Interrupt Set-Enable Registers */ 43 | template 44 | class ISER : public reg 45 | { static_assert(reg_index < 8, "invalid index for register"); }; 46 | 47 | /** Interrupt Set-Enable Registers */ 48 | template 49 | class ICER : public reg 50 | { static_assert(reg_index < 8, "invalid index for register"); }; 51 | 52 | /** Interrupt Set-Pending Registers */ 53 | template 54 | class ISPR : public reg 55 | { static_assert(reg_index < 8, "invalid index for register"); }; 56 | 57 | /** Interrupt Clear-Pending Registers */ 58 | template 59 | class ICPR : public reg 60 | { static_assert(reg_index < 8, "invalid index for register"); }; 61 | 62 | /** Interrupt Active Bit Register */ 63 | template 64 | class IABR : public reg 65 | { static_assert(reg_index < 8, "invalid index for register"); }; 66 | 67 | /** Interrupt Priority Register */ 68 | template 69 | class IPR : public reg 70 | { static_assert(reg_index < 60, "invalid index for register"); }; 71 | }; 72 | 73 | } // namespace mptl 74 | 75 | #endif // ARM_CORTEX_COMMON_REG_NVIC_HPP_INCLUDED 76 | -------------------------------------------------------------------------------- /arch/arm/cortex/common/scb.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARM_CORTEX_COMMON_SCB_HPP_INCLUDED 22 | #define ARM_CORTEX_COMMON_SCB_HPP_INCLUDED 23 | 24 | #include "reg/scb.hpp" 25 | 26 | #if 0 // TODO: fixme 27 | 28 | namespace mptl { 29 | 30 | template 31 | class scb 32 | { 33 | public: 34 | 35 | static void set_priority_group(uint32_t group) { 36 | // assert(group == (group & 0x07)); 37 | 38 | SCB::AIRCR::set 39 | ( SCB::AIRCR::VECTKEY ::shifted_value(0x5FA) | 40 | SCB::AIRCR::PRIGROUP::shifted_value(group) ); 41 | } 42 | 43 | static uint32_t get_priority_group(void) { 44 | return SCB::AIRCR::PRIGROUP::test_and_shift(); 45 | } 46 | 47 | template 48 | static void set_priority(uint32_t priority) { 49 | static_assert(irqn < 0 && irqn > -13, "illegal core exception interrupt number"); 50 | SCB::SHPR<((uint32_t)irqn & 0xf)-4>::store((priority << (8 - priority_bits)) & 0xff); 51 | } 52 | 53 | template 54 | static uint32_t get_priority(void) { 55 | static_assert(irqn < 0 && irqn > -13, "illegal core exception interrupt number"); 56 | return((uint32_t)(SCB::SHPR<((uint32_t)irqn & 0xf)-4>::load() >> (8 - priority_bits))); 57 | } 58 | }; 59 | 60 | } // namespace mptl 61 | 62 | #endif 63 | 64 | #endif // ARM_CORTEX_COMMON_SCB_HPP_INCLUDED 65 | -------------------------------------------------------------------------------- /arch/arm/cortex/common/systick.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARM_CORTEX_COMMON_SYSTICK_HPP_INCLUDED 22 | #define ARM_CORTEX_COMMON_SYSTICK_HPP_INCLUDED 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | namespace mptl { 30 | 31 | 32 | struct systick_clock 33 | { 34 | /** Select external clock (HCLK_DIV8) as systick clock source */ 35 | template< typename system_clock_type, freq_t _freq > 36 | struct external { 37 | static constexpr freq_t freq = _freq; 38 | static constexpr freq_t counter_freq = system_clock_type::hclk_freq / 8; 39 | 40 | using resources = reglist< 41 | regval< SCB::STCSR::CLKSOURCE, 0 >, 42 | regval< SCB::STRVR::regbits_type, (system_clock_type::hclk_freq / (freq * 8)) > 43 | >; 44 | }; 45 | 46 | /** Select core clock (HCLK) as systick clock source */ 47 | template< typename system_clock_type, freq_t _freq > 48 | struct core { 49 | static constexpr freq_t freq = _freq; 50 | static constexpr freq_t counter_freq = system_clock_type::hclk_freq; 51 | 52 | using resources = reglist< 53 | regval< SCB::STCSR::CLKSOURCE, 1 >, 54 | regval< SCB::STRVR::regbits_type, (system_clock_type::hclk_freq / freq) > 55 | >; 56 | }; 57 | }; 58 | 59 | 60 | template< typename clock_source_type > 61 | class systick 62 | { 63 | public: 64 | static constexpr freq_t freq = clock_source_type::freq; 65 | static constexpr freq_t counter_freq = clock_source_type::counter_freq; 66 | static constexpr uint32_t reload_value = counter_freq / freq; 67 | 68 | /** picoseconds per counter tick 69 | * 70 | * min: 72MHz, hclk: 13'888 71 | * max: 24MHz, hclk/8: 333'333 72 | */ 73 | static constexpr uint32_t ps_per_tick = (1000 * 1000 * 1000) / (counter_freq / 1000); 74 | 75 | using resources = typename clock_source_type::resources; 76 | 77 | using irq = mptl::irq::systick; /**< System Tick Interrupt */ 78 | 79 | static void set_reload(SCB::STRVR::value_type reload) { 80 | // assert((reload >= 1) && (reload <= 0xFFFFFF)); 81 | SCB::STRVR::store(reload); 82 | } 83 | 84 | static void enable_counter(void) { 85 | SCB::STCSR::ENABLE::set(); 86 | } 87 | static void disable_counter(void) { 88 | SCB::STCSR::ENABLE::clear(); 89 | } 90 | static void clear_counter(void) { 91 | SCB::STCVR::store(0); 92 | } 93 | static SCB::STCVR::value_type get_counter(void) { 94 | return SCB::STCVR::load(); 95 | } 96 | 97 | static void enable_interrupt(void) { 98 | SCB::STCSR::TICKINT::set(); 99 | } 100 | static void disable_interrupt(void) { 101 | SCB::STCSR::TICKINT::clear(); 102 | } 103 | 104 | static bool get_count_flag(void) { 105 | return SCB::STCSR::COUNTFLAG::test(); 106 | } 107 | static bool get_skew_flag(void) { 108 | return SCB::STCR::SKEW::test(); 109 | } 110 | static bool get_no_ref_flag(void) { 111 | return SCB::STCR::NOREF::test(); 112 | } 113 | 114 | static void enable(void) { 115 | clear_counter(); 116 | enable_counter(); 117 | } 118 | }; 119 | 120 | } // namespace mptl 121 | 122 | #endif // ARM_CORTEX_COMMON_SYSTICK_HPP_INCLUDED 123 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/common/reg/STM_License.html: -------------------------------------------------------------------------------- 1 |

End User License Agreement for STMicroelectronics (Version 1.0)

2 | Licence Terms

3 |

4 | STMicroelectronics International N.V.,   (“LICENSOR”) hereby grants and you (“LICENSEE”) hereby accept a non transferable, non-exclusive licence to use and copy the deliverables (“Deliverables”) solely for the purpose of; (i) developing LICENSEE’s development tools and distributing such development tools to third parties; (ii) generating derivative representations of the Deliverables to develop and debug software for LICENSOR’s targeted devices or device series identified within the Deliverables, (together the “Purpose”) under the following terms and conditions:

5 |

6 | 1.         Ownership.  The Deliverables are the property of LICENSOR. LICENSEE acquires no right, title or interest in the Deliverables other than the licence rights granted herein. 

7 |

8 | 2.         Use.  LICENSEE shall only be permitted to use the Deliverables for the Purpose.  LICENSEE shall not reverse engineer, decompile or disassemble the Deliverables, in whole or in part.

9 |

10 | 3.         Copies.  All copies of the Deliverables must bear the same notice(s) contained on the original copies of the Deliverables.

11 |

12 | 4.         No Warranty. THE DELIVERABLES ARE PROVIDED “AS IS” AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY QUALITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
13 |
14 | IN NO EVENT SHALL LICENSOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE DELIVERABLES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 |
16 | LICENSEE EXPRESSLY ASSUMES ALL LIABILITIES AND RISKS, FOR USE OR OPERATION OF THE DELIVERABLES.

17 |

18 | 5.         In the event that LICENSEE receives early access to the Deliverables, LICENSEE acknowledges and agrees that; (a) notwithstanding the licence grants above, LICENSEE shall only be permitted to use the Deliverables solely internally for evaluation and providing feedback to LICENSOR; (b) except with respect to the limited licence grants in 5(a), LICENSEE shall be subject to all of the terms and conditions set out above; and (c) the Deliverables are confidential information and LICENSEE shall maintain in confidence the Deliverables and apply security measures no less stringent than the measures that LICENSEE applies to its own like information, but not less than a reasonable degree of care, to prevent unauthorised disclosure and use of the Deliverables.

-------------------------------------------------------------------------------- /arch/arm/cortex/stm32/common/usart_stream.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARM_CORTEX_STM32_COMMON_USART_STREAM_HPP_INCLUDED 22 | #define ARM_CORTEX_STM32_COMMON_USART_STREAM_HPP_INCLUDED 23 | 24 | #include 25 | #include 26 | 27 | namespace mptl { 28 | 29 | template< 30 | typename usart_type, 31 | typename _fifo_type, // = ring_buffer, 32 | bool _crlf = true, 33 | bool debug_irqs = false 34 | > 35 | class usart_irq_stream 36 | { 37 | public: 38 | static constexpr bool crlf = _crlf; 39 | using fifo_type = _fifo_type; 40 | using char_type = char; 41 | 42 | static fifo_type rx_fifo; 43 | static fifo_type tx_fifo; 44 | 45 | static volatile unsigned int irq_count; 46 | static volatile unsigned int irq_errors; 47 | 48 | private: 49 | 50 | using SR = typename usart_type::USARTx::SR; 51 | 52 | static void isr(void) { 53 | auto flags = SR::load(); 54 | 55 | if(debug_irqs) { 56 | irq_count++; 57 | if(flags & (SR::ORE::value | SR::FE::value | SR::NE::value | SR::PE::value)) 58 | irq_errors++; 59 | } 60 | 61 | if(flags & SR::RXNE::value) { 62 | uint32_t data = usart_type::receive(); /* implicitely clears RXNE flag */ 63 | rx_fifo.push(data); 64 | } 65 | if(flags & SR::TXE::value) { 66 | char c; 67 | if(tx_fifo.pop(c)) { 68 | usart_type::send(c); /* implicitely clears TXE flag */ 69 | } 70 | else { 71 | usart_type::disable_tx_interrupt(); 72 | } 73 | } 74 | } 75 | 76 | public: 77 | 78 | using irq_resources = typelist< 79 | irq_handler< typename usart_type::irq, isr > 80 | >; 81 | 82 | using resources = typelist< 83 | typename usart_type::resources, 84 | irq_resources 85 | >; 86 | 87 | static void flush() { 88 | usart_type::enable_tx_interrupt(); 89 | } 90 | 91 | /** 92 | * open the stream 93 | * 94 | * - enable USARTx 95 | * - enable usart irq channel 96 | * - enable RXNE and PE interrupts 97 | * 98 | * NOTE: Make sure the device is correctly setup before calling this 99 | * function. e.g. by calling usart_device.configure() 100 | */ 101 | static void open(void) { 102 | tx_fifo.reset(); 103 | rx_fifo.reset(); 104 | 105 | usart_type::enable(); 106 | usart_type::irq::enable(); 107 | usart_type::enable_interrupt(true, false, true, false, false); 108 | } 109 | 110 | /** 111 | * close the stream 112 | * 113 | * - disable interrupts enabled by open() 114 | * - disable the usartX irq 115 | * - disable USARTx 116 | */ 117 | static void close(void) { 118 | usart_type::disable_interrupt(true, false, true, false, false); 119 | usart_type::irq::disable(); 120 | usart_type::disable(); 121 | } 122 | }; 123 | 124 | template 125 | fifo_type usart_irq_stream::rx_fifo; 126 | 127 | template 128 | fifo_type usart_irq_stream::tx_fifo; 129 | 130 | template 131 | volatile unsigned int usart_irq_stream::irq_count; 132 | 133 | template 134 | volatile unsigned int usart_irq_stream::irq_errors; 135 | 136 | 137 | } // namespace mptl 138 | 139 | #endif // ARM_CORTEX_STM32_COMMON_USART_STREAM_HPP_INCLUDED 140 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/bitband.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_BITBAND_HPP_INCLUDED 22 | #define ARCH_BITBAND_HPP_INCLUDED 23 | 24 | #include "../../../../common/bitband.hpp" 25 | 26 | #endif // ARCH_BITBAND_HPP_INCLUDED 27 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/core.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_CORE_HPP_INCLUDED 22 | #define ARCH_CORE_HPP_INCLUDED 23 | 24 | #include "../../../../common/core.hpp" 25 | 26 | namespace mptl { 27 | 28 | using core = core_base; 29 | 30 | } // namespace mptl 31 | 32 | #endif // ARCH_CORE_HPP_INCLUDED 33 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/dwt.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_DWT_HPP_INCLUDED 22 | #define ARCH_DWT_HPP_INCLUDED 23 | 24 | #include "../../../../common/dwt.hpp" 25 | 26 | #endif // ARCH_DWT_HPP_INCLUDED 27 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/flash.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_FLASH_HPP_INCLUDED 22 | #define ARCH_FLASH_HPP_INCLUDED 23 | 24 | #include 25 | #include 26 | 27 | namespace mptl { 28 | 29 | class flash 30 | { 31 | static constexpr FLASH::ACR::LATENCY::value_type min_latency(freq_t hclk_freq) 32 | { 33 | return 34 | ((hclk_freq <= mhz(24)) ? 0 : 35 | (hclk_freq <= mhz(48)) ? 1 : 36 | (hclk_freq <= mhz(72)) ? 2 : 37 | 0xff ); 38 | }; 39 | 40 | public: /* ------ configuration traits ------ */ 41 | 42 | using prefetch_buffer_enable = regval< FLASH::ACR::PRFTBE, 1>; 43 | using prefetch_buffer_disable = regval< FLASH::ACR::PRFTBE, 0>; 44 | 45 | struct latency { 46 | template< typename system_clock_type > 47 | using minimum = regval< 48 | FLASH::ACR::LATENCY, 49 | min_latency(system_clock_type::hclk_freq) 50 | >; 51 | 52 | template< unsigned ws > 53 | using wait_states = regval< FLASH::ACR::LATENCY, ws >; 54 | }; 55 | 56 | public: /* ------ static member functions ------ */ 57 | 58 | /** 59 | * Configure FLASH register using configuration traits (Tp). 60 | */ 61 | template< typename... Tp > 62 | static void configure(void) { 63 | reglist< Tp... >::template strict_reset_to< FLASH::ACR >(); 64 | } 65 | }; 66 | 67 | } // namespace mptl 68 | 69 | #endif // ARCH_FLASH_HPP_INCLUDED 70 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/pwr.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_PWR_HPP_INCLUDED 22 | #define ARCH_PWR_HPP_INCLUDED 23 | 24 | #include 25 | 26 | namespace mptl { 27 | 28 | class pwr 29 | { 30 | public: 31 | 32 | static void disable_backup_domain_write_protection(void) { 33 | PWR::CR::DBP::set(); 34 | } 35 | }; 36 | 37 | } // namespace mptl 38 | 39 | #endif // ARCH_PWR_HPP_INCLUDED 40 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/reg/STM_License.html: -------------------------------------------------------------------------------- 1 |

End User License Agreement for STMicroelectronics (Version 1.0)

2 | Licence Terms

3 |

4 | STMicroelectronics International N.V.,   (“LICENSOR”) hereby grants and you (“LICENSEE”) hereby accept a non transferable, non-exclusive licence to use and copy the deliverables (“Deliverables”) solely for the purpose of; (i) developing LICENSEE’s development tools and distributing such development tools to third parties; (ii) generating derivative representations of the Deliverables to develop and debug software for LICENSOR’s targeted devices or device series identified within the Deliverables, (together the “Purpose”) under the following terms and conditions:

5 |

6 | 1.         Ownership.  The Deliverables are the property of LICENSOR. LICENSEE acquires no right, title or interest in the Deliverables other than the licence rights granted herein. 

7 |

8 | 2.         Use.  LICENSEE shall only be permitted to use the Deliverables for the Purpose.  LICENSEE shall not reverse engineer, decompile or disassemble the Deliverables, in whole or in part.

9 |

10 | 3.         Copies.  All copies of the Deliverables must bear the same notice(s) contained on the original copies of the Deliverables.

11 |

12 | 4.         No Warranty. THE DELIVERABLES ARE PROVIDED “AS IS” AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY QUALITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
13 |
14 | IN NO EVENT SHALL LICENSOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE DELIVERABLES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 |
16 | LICENSEE EXPRESSLY ASSUMES ALL LIABILITIES AND RISKS, FOR USE OR OPERATION OF THE DELIVERABLES.

17 |

18 | 5.         In the event that LICENSEE receives early access to the Deliverables, LICENSEE acknowledges and agrees that; (a) notwithstanding the licence grants above, LICENSEE shall only be permitted to use the Deliverables solely internally for evaluation and providing feedback to LICENSOR; (b) except with respect to the limited licence grants in 5(a), LICENSEE shall be subject to all of the terms and conditions set out above; and (c) the Deliverables are confidential information and LICENSEE shall maintain in confidence the Deliverables and apply security measures no less stringent than the measures that LICENSEE applies to its own like information, but not less than a reasonable degree of care, to prevent unauthorised disclosure and use of the Deliverables.

-------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/reg/gpio.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | /* 22 | * This program contains derivative representations of CMSIS System 23 | * View Description (SVD) files, and is subject to the "End User 24 | * License Agreement for STMicroelectronics" (see "STM_License.html" 25 | * in the containing directory). 26 | */ 27 | 28 | #ifndef ARCH_REG_GPIO_HPP_INCLUDED 29 | #define ARCH_REG_GPIO_HPP_INCLUDED 30 | 31 | #include 32 | 33 | namespace mptl { 34 | 35 | /** 36 | * General-purpose and alternate-function I/Os (GPIOs and AFIOs) 37 | */ 38 | template< char port > 39 | struct GPIO 40 | { 41 | static_assert((port >= 'A') && (port <= 'G'), "invalid index for register"); 42 | 43 | static constexpr unsigned gpio_no = port - 'A'; 44 | static constexpr reg_addr_t base_addr = 0x40010800 + gpio_no * 0x0400; 45 | 46 | using CRL = reg< uint32_t, base_addr + 0x00, rw, 0x44444444 >; /**< Port configuration register low */ 47 | using CRH = reg< uint32_t, base_addr + 0x04, rw, 0x44444444 >; /**< Port configuration register high */ 48 | using IDR = reg< uint32_t, base_addr + 0x08, ro, 0x00000000 >; /**< Port input data register */ 49 | using ODR = reg< uint32_t, base_addr + 0x0c, rw, 0x00000000 >; /**< Port output data register */ 50 | using BSRR = reg< uint32_t, base_addr + 0x10, wo, 0x00000000 >; /**< Port bit set/reset register */ 51 | using BRR = reg< uint32_t, base_addr + 0x14, wo, 0x00000000 >; /**< Port bit reset register */ 52 | using LCKR = reg< uint32_t, base_addr + 0x18, rw, 0x00000000 >; /**< Port configuration lock register */ 53 | 54 | /** 55 | * GPIO port configuration register: returns CRL or CRH type dependent on pin_no. 56 | * 57 | * NOTE: this is not from the reference manual 58 | */ 59 | template 60 | struct CRx 61 | : public std::conditional< (pin_no < 8), CRL, CRH >::type 62 | { 63 | using type = typename std::conditional< (pin_no < 8), CRL, CRH >::type; 64 | 65 | using CNF = regbits< type, (pin_no % 8) * 4 + 2, 2 >; 66 | using MODE = regbits< type, (pin_no % 8) * 4 , 2 >; 67 | }; 68 | }; 69 | 70 | } // namespace mptl 71 | 72 | #endif // ARCH_REG_GPIO_HPP_INCLUDED 73 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/reg/pwr.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | /* 22 | * This program contains derivative representations of CMSIS System 23 | * View Description (SVD) files, and is subject to the "End User 24 | * License Agreement for STMicroelectronics" (see "STM_License.html" 25 | * in the containing directory). 26 | */ 27 | 28 | #ifndef ARCH_REG_PWR_HPP_INCLUDED 29 | #define ARCH_REG_PWR_HPP_INCLUDED 30 | 31 | #include 32 | 33 | namespace mptl { 34 | 35 | /** 36 | * Power control 37 | */ 38 | struct PWR 39 | { 40 | static constexpr reg_addr_t base_addr = 0x40007000; 41 | 42 | /** 43 | * Power control register (PWR_CR) 44 | */ 45 | struct CR 46 | : public reg< uint32_t, base_addr + 0x0, rw, 0x00000000 > 47 | { 48 | using type = reg< uint32_t, base_addr + 0x0, rw, 0x00000000 >; 49 | 50 | using LPDS = regbits< type, 0, 1 >; /**< Low Power Deep Sleep */ 51 | using PDDS = regbits< type, 1, 1 >; /**< Power Down Deep Sleep */ 52 | using CWUF = regbits< type, 2, 1 >; /**< Clear Wake-up Flag */ 53 | using CSBF = regbits< type, 3, 1 >; /**< Clear STANDBY Flag */ 54 | using PVDE = regbits< type, 4, 1 >; /**< Power Voltage Detector Enable */ 55 | 56 | /** PVD Level Selection */ 57 | struct PLS : public regbits< type, 5, 3 > 58 | { 59 | template 60 | struct voltage_threshold 61 | : public regval< regbits_type, fraction - 2 > 62 | { static_assert((fraction >= 2) && (fraction <= 9), "invalid fraction"); }; 63 | }; 64 | 65 | using DBP = regbits< type, 8, 1 >; /**< Disable Backup Domain write protection */ 66 | }; 67 | 68 | /** 69 | * Power control register (PWR_CR) 70 | */ 71 | struct CSR 72 | : public reg< uint32_t, base_addr + 0x4, rw, 0x00000000 > 73 | { 74 | using type = reg< uint32_t, base_addr + 0x4, rw, 0x00000000 >; 75 | 76 | using WUF = regbits< type, 0, 1 >; /**< Wake-Up Flag */ 77 | using SBF = regbits< type, 1, 1 >; /**< STANDBY Flag */ 78 | using PVDO = regbits< type, 2, 1 >; /**< PVD Output */ 79 | using EWUP = regbits< type, 8, 1 >; /**< Enable WKUP pin */ 80 | }; 81 | }; 82 | 83 | } // namespace mptl 84 | 85 | #endif // ARCH_REG_PWR_HPP_INCLUDED 86 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/reg/spi.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | /* 22 | * This program contains derivative representations of CMSIS System 23 | * View Description (SVD) files, and is subject to the "End User 24 | * License Agreement for STMicroelectronics" (see "STM_License.html" 25 | * in the containing directory). 26 | */ 27 | 28 | #ifndef ARCH_REG_SPI_HPP_INCLUDED 29 | #define ARCH_REG_SPI_HPP_INCLUDED 30 | 31 | #include "../../../../common/reg/spi.hpp" 32 | 33 | namespace mptl { 34 | 35 | template 36 | class SPI 37 | { 38 | /* See available template specialisations below if the compiler asserts here! */ 39 | static_assert(spi_no == !spi_no, "unsupported SPI number"); // assertion needs to be dependent of template parameter 40 | }; 41 | 42 | template<> class SPI<1> : public SPI_Common< 0x40013000 > { }; 43 | #if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) 44 | template<> class SPI<2> : public SPI_Common< 0x40003800 > { }; 45 | #endif 46 | #if defined (STM32F10X_HD) || defined (STM32F10X_CL) 47 | template<> class SPI<3> : public SPI_Common< 0x40003C00 > { }; 48 | #endif 49 | 50 | } // namespace mptl 51 | 52 | #endif // ARCH_REG_SPI_HPP_INCLUDED 53 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/reg/tim.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | /* 22 | * This program contains derivative representations of CMSIS System 23 | * View Description (SVD) files, and is subject to the "End User 24 | * License Agreement for STMicroelectronics" (see "STM_License.html" 25 | * in the containing directory). 26 | */ 27 | 28 | #ifndef ARCH_REG_TIM_HPP_INCLUDED 29 | #define ARCH_REG_TIM_HPP_INCLUDED 30 | 31 | #include "../../../../common/reg/tim.hpp" 32 | 33 | namespace mptl { 34 | 35 | template 36 | class TIM 37 | { 38 | /* See available template specialisations below if the compiler asserts here! */ 39 | static_assert(tim_no == !tim_no, "unsupported TIM number"); // assertion needs to be dependent of template parameter 40 | }; 41 | 42 | template<> class TIM< 1 > : public TIM_common< 0x40012c00 > { }; 43 | template<> class TIM< 2 > : public TIM_common< 0x40000000 > { }; 44 | template<> class TIM< 3 > : public TIM_common< 0x40000400 > { }; 45 | template<> class TIM< 4 > : public TIM_common< 0x40000800 > { }; 46 | template<> class TIM< 5 > : public TIM_common< 0x40000c00 > { }; 47 | template<> class TIM< 6 > : public TIM_common< 0x40001000 > { }; 48 | template<> class TIM< 7 > : public TIM_common< 0x40001400 > { }; 49 | template<> class TIM< 8 > : public TIM_common< 0x40013400 > { }; 50 | template<> class TIM< 9 > : public TIM_common< 0x40014c00 > { }; 51 | template<> class TIM< 10 > : public TIM_common< 0x40015000 > { }; 52 | template<> class TIM< 11 > : public TIM_common< 0x40015400 > { }; 53 | template<> class TIM< 12 > : public TIM_common< 0x40001800 > { }; 54 | template<> class TIM< 13 > : public TIM_common< 0x40001c00 > { }; 55 | template<> class TIM< 14 > : public TIM_common< 0x40002000 > { }; 56 | 57 | } // namespace mptl 58 | 59 | #endif // ARCH_REG_TIM_HPP_INCLUDED 60 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/reg/usart.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | /* 22 | * This program contains derivative representations of CMSIS System 23 | * View Description (SVD) files, and is subject to the "End User 24 | * License Agreement for STMicroelectronics" (see "STM_License.html" 25 | * in the containing directory). 26 | */ 27 | 28 | #ifndef ARCH_REG_USART_HPP_INCLUDED 29 | #define ARCH_REG_USART_HPP_INCLUDED 30 | 31 | #include "../../../../common/reg/usart.hpp" 32 | 33 | namespace mptl { 34 | 35 | template 36 | class USART 37 | { 38 | /* See available template specialisations below if the compiler asserts here! */ 39 | static_assert(usart_no == !usart_no, "unsupported USART number"); // assertion needs to be dependent of template parameter 40 | }; 41 | 42 | template<> class USART<1> : public USART_common< 0x40013800 > { }; 43 | template<> class USART<2> : public USART_common< 0x40004400 > { }; 44 | #if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) 45 | template<> class USART<3> : public USART_common< 0x40004800 > { }; 46 | #endif 47 | 48 | } // namespace mptl 49 | 50 | #endif // ARCH_REG_USART_HPP_INCLUDED 51 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/scb.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_SCB_HPP_INCLUDED 22 | #define ARCH_SCB_HPP_INCLUDED 23 | 24 | #include "../../../../common/scb.hpp" 25 | 26 | #endif // ARCH_SCB_HPP_INCLUDED 27 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/spi.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_SPI_HPP_INCLUDED 22 | #define ARCH_SPI_HPP_INCLUDED 23 | 24 | #include "../../../common/spi.hpp" 25 | 26 | namespace mptl { 27 | 28 | namespace mpl 29 | { 30 | template< typename gpio_type, freq_t gpio_speed > 31 | struct spi_gpio_output_resources { 32 | using type = typelist< 33 | typename gpio_type::resources, 34 | typename gpio_type::mode::template output< gpio_speed >, 35 | typename gpio_type::output_type::af_push_pull 36 | >; 37 | }; 38 | template< freq_t gpio_speed > 39 | struct spi_gpio_output_resources< void, gpio_speed > { 40 | using type = void; 41 | }; 42 | 43 | template< typename gpio_type > 44 | struct spi_gpio_input_resources { 45 | using type = typelist< 46 | typename gpio_type::resources, 47 | typename gpio_type::mode::input, 48 | typename gpio_type::input_type::pull_up_down 49 | >; 50 | }; 51 | template<> 52 | struct spi_gpio_input_resources< void > { 53 | using type = void; 54 | }; 55 | } // namespace mpl 56 | 57 | 58 | template< 59 | unsigned spi_no, 60 | typename system_clock_type, 61 | typename gpio_sck_type = void, 62 | typename gpio_miso_type = void, 63 | typename gpio_mosi_type = void, 64 | freq_t gpio_output_speed = mhz(50) 65 | > 66 | class spi : public spi_stm32_common< spi_no, system_clock_type > 67 | { 68 | using base_type = spi_stm32_common< spi_no, system_clock_type >; 69 | 70 | public: 71 | 72 | using resources = typelist< 73 | typename base_type::resources, 74 | typename mpl::spi_gpio_output_resources< gpio_sck_type, gpio_output_speed >::type, 75 | typename mpl::spi_gpio_input_resources< gpio_miso_type >::type, 76 | typename mpl::spi_gpio_output_resources< gpio_mosi_type, gpio_output_speed >::type 77 | >; 78 | }; 79 | 80 | } // namespace mptl 81 | 82 | #endif // ARCH_SPI_HPP_INCLUDED 83 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/systick.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_SYSTICK_HPP_INCLUDED 22 | #define ARCH_SYSTICK_HPP_INCLUDED 23 | 24 | #include "../../../../common/systick.hpp" 25 | 26 | #endif // ARCH_SYSTICK_HPP_INCLUDED 27 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/usart.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_USART_HPP_INCLUDED 22 | #define ARCH_USART_HPP_INCLUDED 23 | 24 | #include "../../../common/usart.hpp" 25 | 26 | namespace mptl { 27 | 28 | namespace mpl 29 | { 30 | template< typename gpio_type > 31 | struct usart_gpio_rx_resources { 32 | using type = typelist< 33 | typename gpio_type::resources, 34 | typename gpio_type::mode::input, 35 | typename gpio_type::input_type::floating 36 | >; 37 | }; 38 | template<> 39 | struct usart_gpio_rx_resources< void > { 40 | using type = void; 41 | }; 42 | 43 | template< typename gpio_type, freq_t gpio_speed > 44 | struct usart_gpio_tx_resources { 45 | using type = typelist< 46 | typename gpio_type::resources, 47 | typename gpio_type::mode::template output< gpio_speed >, 48 | typename gpio_type::output_type::af_push_pull 49 | >; 50 | }; 51 | template< freq_t gpio_speed > 52 | struct usart_gpio_tx_resources< void, gpio_speed > { 53 | using type = void; 54 | }; 55 | } // namespace mpl 56 | 57 | 58 | template< 59 | unsigned usart_no, 60 | typename system_clock_type, 61 | typename gpio_rx_type = void, 62 | typename gpio_tx_type = void, 63 | freq_t gpio_tx_speed = mhz(50) 64 | > 65 | class usart : public usart_stm32_common< usart_no, system_clock_type > 66 | { 67 | using base_type = usart_stm32_common< usart_no, system_clock_type >; 68 | 69 | public: 70 | 71 | using resources = typelist< 72 | typename base_type::resources, 73 | typename mpl::usart_gpio_rx_resources< gpio_rx_type >::type, 74 | typename mpl::usart_gpio_tx_resources< gpio_tx_type, gpio_tx_speed >::type 75 | >; 76 | }; 77 | 78 | } // namespace mptl 79 | 80 | #endif // ARCH_USART_HPP_INCLUDED 81 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/usart_stream.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_USART_STREAM_HPP_INCLUDED 22 | #define ARCH_USART_STREAM_HPP_INCLUDED 23 | 24 | #include "../../../common/usart_stream.hpp" 25 | 26 | #endif // ARCH_USART_STREAM_HPP_INCLUDED 27 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f1/include/arch/vector_table.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_VECTOR_TABLE_HPP_INCLUDED 22 | #define ARCH_VECTOR_TABLE_HPP_INCLUDED 23 | 24 | #include "../../../../common/vector_table.hpp" 25 | 26 | #endif // ARCH_VECTOR_TABLE_HPP_INCLUDED 27 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f4/include/arch/bitband.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_BITBAND_HPP_INCLUDED 22 | #define ARCH_BITBAND_HPP_INCLUDED 23 | 24 | #include "../../../../common/bitband.hpp" 25 | 26 | #endif // ARCH_BITBAND_HPP_INCLUDED 27 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f4/include/arch/core.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_CORE_HPP_INCLUDED 22 | #define ARCH_CORE_HPP_INCLUDED 23 | 24 | #include "../../../../common/core.hpp" 25 | 26 | namespace mptl { 27 | 28 | using core = core_base; 29 | 30 | } // namespace mptl 31 | 32 | #endif // ARCH_CORE_HPP_INCLUDED 33 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f4/include/arch/dwt.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_DWT_HPP_INCLUDED 22 | #define ARCH_DWT_HPP_INCLUDED 23 | 24 | #include "../../../../common/dwt.hpp" 25 | 26 | #endif // ARCH_DWT_HPP_INCLUDED 27 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f4/include/arch/flash.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_FLASH_HPP_INCLUDED 22 | #define ARCH_FLASH_HPP_INCLUDED 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | namespace mptl { 29 | 30 | class flash 31 | { 32 | template< typename pwr_type > 33 | struct prefetch_buffer_enable_impl { 34 | static_assert(pwr_type::system_voltage >= volt(2.1), "prefetch buffer must be disabled when the supply voltage is below 2.1V"); 35 | using type = regval< FLASH::ACR::PRFTEN, 1>; 36 | }; 37 | 38 | static constexpr FLASH::ACR::LATENCY::value_type min_latency(freq_t hclk_freq, voltage_t system_voltage) 39 | { 40 | return 41 | (system_voltage <= volt(2.1)) ? 42 | ((hclk_freq <= mhz(20)) ? 0 : 43 | (hclk_freq <= mhz(40)) ? 1 : 44 | (hclk_freq <= mhz(60)) ? 2 : 45 | (hclk_freq <= mhz(80)) ? 3 : 46 | (hclk_freq <= mhz(100)) ? 4 : 47 | (hclk_freq <= mhz(120)) ? 5 : 48 | (hclk_freq <= mhz(140)) ? 6 : 49 | (hclk_freq <= mhz(160)) ? 7 : 50 | 0xff ) : 51 | (system_voltage <= volt(2.4)) ? 52 | ((hclk_freq <= mhz(22)) ? 0 : 53 | (hclk_freq <= mhz(44)) ? 1 : 54 | (hclk_freq <= mhz(66)) ? 2 : 55 | (hclk_freq <= mhz(88)) ? 3 : 56 | (hclk_freq <= mhz(110)) ? 4 : 57 | (hclk_freq <= mhz(132)) ? 5 : 58 | (hclk_freq <= mhz(154)) ? 6 : 59 | (hclk_freq <= mhz(168)) ? 7 : 60 | 0xff ) : 61 | (system_voltage <= volt(2.7)) ? 62 | ((hclk_freq <= mhz(24)) ? 0 : 63 | (hclk_freq <= mhz(48)) ? 1 : 64 | (hclk_freq <= mhz(72)) ? 2 : 65 | (hclk_freq <= mhz(96)) ? 3 : 66 | (hclk_freq <= mhz(120)) ? 4 : 67 | (hclk_freq <= mhz(144)) ? 5 : 68 | (hclk_freq <= mhz(168)) ? 6 : 69 | 0xff ) : 70 | (system_voltage <= volt(3.6)) ? 71 | ((hclk_freq <= mhz(30)) ? 0 : 72 | (hclk_freq <= mhz(60)) ? 1 : 73 | (hclk_freq <= mhz(90)) ? 2 : 74 | (hclk_freq <= mhz(120)) ? 3 : 75 | (hclk_freq <= mhz(150)) ? 4 : 76 | (hclk_freq <= mhz(168)) ? 5 : 77 | 0xff ) : 0xff; 78 | }; 79 | 80 | public: /* ------ configuration traits ------ */ 81 | 82 | template< typename pwr_type > 83 | using prefetch_buffer_enable = typename prefetch_buffer_enable_impl< pwr_type >::type; 84 | 85 | using prefetch_buffer_disable = regval< FLASH::ACR::PRFTEN, 0>; 86 | 87 | using instruction_cache_enable = regval< FLASH::ACR::ICEN, 1>; 88 | using instruction_cache_disable = regval< FLASH::ACR::ICEN, 0>; 89 | 90 | using data_cache_enable = regval< FLASH::ACR::DCEN, 1>; 91 | using data_cache_disable = regval< FLASH::ACR::DCEN, 0>; 92 | 93 | struct latency { 94 | template< typename system_clock_type, typename pwr_type > 95 | using minimum = regval< 96 | FLASH::ACR::LATENCY, 97 | min_latency(system_clock_type::hclk_freq, pwr_type::system_voltage) 98 | >; 99 | 100 | template< unsigned ws > 101 | using wait_states = regval< FLASH::ACR::LATENCY, ws >; 102 | }; 103 | 104 | public: /* ------ static member functions ------ */ 105 | 106 | /** 107 | * Configure FLASH register using configuration traits (Tp). 108 | */ 109 | template< typename... Tp > 110 | static void configure(void) { 111 | reglist< Tp... >::template strict_reset_to< FLASH::ACR >(); 112 | } 113 | }; 114 | 115 | } // namespace mptl 116 | 117 | #endif // ARCH_FLASH_HPP_INCLUDED 118 | 119 | 120 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f4/include/arch/pwr.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_PWR_HPP_INCLUDED 22 | #define ARCH_PWR_HPP_INCLUDED 23 | 24 | #include 25 | #include 26 | 27 | namespace mptl { 28 | 29 | template< voltage_t _system_voltage = volt(3.3) > 30 | class pwr 31 | { 32 | static_assert(_system_voltage >= volt(1.8) && _system_voltage <= volt(3.6), "unsupported system voltage"); 33 | 34 | template< typename system_clock_type > 35 | struct power_save_enable_impl { 36 | static_assert(system_clock_type::hclk_freq <= mhz(144), "system clock frequency too high for power save feature"); 37 | using type = regval< PWR::CR::VOS, 0 >; 38 | }; 39 | 40 | public: 41 | 42 | static constexpr voltage_t system_voltage = _system_voltage; 43 | 44 | public: /* ------ configuration traits ------ */ 45 | 46 | /** disable high performance mode */ 47 | template< typename system_clock_type > 48 | using power_save_enable = typename power_save_enable_impl::type; 49 | 50 | public: /* ------ static member functions ------ */ 51 | 52 | static void disable_backup_domain_write_protection(void) { 53 | PWR::CR::DBP::set(); 54 | } 55 | }; 56 | 57 | } // namespace mptl 58 | 59 | #endif // ARCH_PWR_HPP_INCLUDED 60 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f4/include/arch/reg/STM_License.html: -------------------------------------------------------------------------------- 1 |

End User License Agreement for STMicroelectronics (Version 1.0)

2 | Licence Terms

3 |

4 | STMicroelectronics International N.V.,   (“LICENSOR”) hereby grants and you (“LICENSEE”) hereby accept a non transferable, non-exclusive licence to use and copy the deliverables (“Deliverables”) solely for the purpose of; (i) developing LICENSEE’s development tools and distributing such development tools to third parties; (ii) generating derivative representations of the Deliverables to develop and debug software for LICENSOR’s targeted devices or device series identified within the Deliverables, (together the “Purpose”) under the following terms and conditions:

5 |

6 | 1.         Ownership.  The Deliverables are the property of LICENSOR. LICENSEE acquires no right, title or interest in the Deliverables other than the licence rights granted herein. 

7 |

8 | 2.         Use.  LICENSEE shall only be permitted to use the Deliverables for the Purpose.  LICENSEE shall not reverse engineer, decompile or disassemble the Deliverables, in whole or in part.

9 |

10 | 3.         Copies.  All copies of the Deliverables must bear the same notice(s) contained on the original copies of the Deliverables.

11 |

12 | 4.         No Warranty. THE DELIVERABLES ARE PROVIDED “AS IS” AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY QUALITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
13 |
14 | IN NO EVENT SHALL LICENSOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE DELIVERABLES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 |
16 | LICENSEE EXPRESSLY ASSUMES ALL LIABILITIES AND RISKS, FOR USE OR OPERATION OF THE DELIVERABLES.

17 |

18 | 5.         In the event that LICENSEE receives early access to the Deliverables, LICENSEE acknowledges and agrees that; (a) notwithstanding the licence grants above, LICENSEE shall only be permitted to use the Deliverables solely internally for evaluation and providing feedback to LICENSOR; (b) except with respect to the limited licence grants in 5(a), LICENSEE shall be subject to all of the terms and conditions set out above; and (c) the Deliverables are confidential information and LICENSEE shall maintain in confidence the Deliverables and apply security measures no less stringent than the measures that LICENSEE applies to its own like information, but not less than a reasonable degree of care, to prevent unauthorised disclosure and use of the Deliverables.

-------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f4/include/arch/reg/pwr.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | /* 22 | * This program contains derivative representations of CMSIS System 23 | * View Description (SVD) files, and is subject to the "End User 24 | * License Agreement for STMicroelectronics" (see "STM_License.html" 25 | * in the containing directory). 26 | */ 27 | 28 | #ifndef ARCH_REG_PWR_HPP_INCLUDED 29 | #define ARCH_REG_PWR_HPP_INCLUDED 30 | 31 | #include 32 | 33 | namespace mptl { 34 | /** 35 | * Power control 36 | */ 37 | struct PWR 38 | { 39 | static constexpr reg_addr_t base_addr = 0x40007000; 40 | 41 | /** 42 | * Power control register 43 | */ 44 | struct CR 45 | : public reg< uint32_t, base_addr + 0x0, rw, 0x00004000 > 46 | { 47 | using VOS = regbits< type, 14, 1 >; /**< Regulator voltage scaling output selection */ 48 | using FPDS = regbits< type, 9, 1 >; /**< Flash power down in Stop mode */ 49 | using DBP = regbits< type, 8, 1 >; /**< Disable backup domain write protection */ 50 | using PLS = regbits< type, 5, 3 >; /**< PVD level selection */ 51 | using PVDE = regbits< type, 4, 1 >; /**< Power voltage detector enable */ 52 | using CSBF = regbits< type, 3, 1 >; /**< Clear standby flag */ 53 | using CWUF = regbits< type, 2, 1 >; /**< Clear wakeup flag */ 54 | using PDDS = regbits< type, 1, 1 >; /**< Power down deepsleep */ 55 | using LPDS = regbits< type, 0, 1 >; /**< Low-power deep sleep */ 56 | }; 57 | 58 | /** 59 | * Power control/status register 60 | */ 61 | struct CSR 62 | : public reg< uint32_t, base_addr + 0x4, rw, 0x00000000 > 63 | { 64 | using VOSRDY = regbits< type, 14, 1 >; /**< Regulator voltage scaling output selection ready bit */ 65 | using BRE = regbits< type, 9, 1 >; /**< Backup regulator enable */ 66 | using EWUP = regbits< type, 8, 1 >; /**< Enable WKUP pin */ 67 | using BRR = regbits< type, 3, 1 >; /**< Backup regulator ready */ 68 | using PVDO = regbits< type, 2, 1 >; /**< PVD output */ 69 | using SBF = regbits< type, 1, 1 >; /**< Standby flag */ 70 | using WUF = regbits< type, 0, 1 >; /**< Wakeup flag */ 71 | }; 72 | }; 73 | 74 | } // namespace mptl 75 | 76 | #endif // ARCH_REG_PWR_HPP_INCLUDED 77 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f4/include/arch/reg/spi.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | /* 22 | * This program contains derivative representations of CMSIS System 23 | * View Description (SVD) files, and is subject to the "End User 24 | * License Agreement for STMicroelectronics" (see "STM_License.html" 25 | * in the containing directory). 26 | */ 27 | 28 | #ifndef ARCH_REG_SPI_HPP_INCLUDED 29 | #define ARCH_REG_SPI_HPP_INCLUDED 30 | 31 | #include "../../../../common/reg/spi.hpp" 32 | 33 | namespace mptl { 34 | 35 | template 36 | class SPI 37 | { 38 | /* See available template specialisations below if the compiler asserts here! */ 39 | static_assert(spi_no == !spi_no, "unsupported SPI number"); // assertion needs to be dependent of template parameter 40 | }; 41 | 42 | /* NOTE: available SPI depends on cpu sub-arch */ 43 | template<> class SPI<1> : public SPI_Common_Ext< 0x40013000 > { }; 44 | template<> class SPI<2> : public SPI_Common_Ext< 0x40003800 > { }; 45 | template<> class SPI<3> : public SPI_Common_Ext< 0x40003C00 > { }; 46 | template<> class SPI<4> : public SPI_Common_Ext< 0x40013400 > { }; 47 | template<> class SPI<5> : public SPI_Common_Ext< 0x40015000 > { }; 48 | template<> class SPI<6> : public SPI_Common_Ext< 0x40015400 > { }; 49 | 50 | } // namespace mptl 51 | 52 | #endif // ARCH_REG_SPI_HPP_INCLUDED 53 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f4/include/arch/reg/tim.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | /* 22 | * This program contains derivative representations of CMSIS System 23 | * View Description (SVD) files, and is subject to the "End User 24 | * License Agreement for STMicroelectronics" (see "STM_License.html" 25 | * in the containing directory). 26 | */ 27 | 28 | #ifndef ARCH_REG_TIM_HPP_INCLUDED 29 | #define ARCH_REG_TIM_HPP_INCLUDED 30 | 31 | #include "../../../../common/reg/tim.hpp" 32 | 33 | namespace mptl { 34 | 35 | template 36 | class TIM 37 | { 38 | /* See available template specialisations below if the compiler asserts here! */ 39 | static_assert(tim_no == !tim_no, "unsupported TIM number"); // assertion needs to be dependent of template parameter 40 | }; 41 | 42 | template<> class TIM< 1 > : public TIM_common< 0x40010000 > { }; 43 | template<> class TIM< 2 > : public TIM_common< 0x40000000 > { }; 44 | template<> class TIM< 3 > : public TIM_common< 0x40000400 > { }; 45 | template<> class TIM< 4 > : public TIM_common< 0x40000800 > { }; 46 | template<> class TIM< 5 > : public TIM_common< 0x40000c00 > { }; 47 | template<> class TIM< 6 > : public TIM_common< 0x40001000 > { }; 48 | template<> class TIM< 7 > : public TIM_common< 0x40001400 > { }; 49 | template<> class TIM< 8 > : public TIM_common< 0x40010400 > { }; 50 | template<> class TIM< 9 > : public TIM_common< 0x40014000 > { }; 51 | template<> class TIM< 10 > : public TIM_common< 0x40014400 > { }; 52 | template<> class TIM< 11 > : public TIM_common< 0x40014800 > { }; 53 | template<> class TIM< 12 > : public TIM_common< 0x40001800 > { }; 54 | template<> class TIM< 13 > : public TIM_common< 0x40001c00 > { }; 55 | template<> class TIM< 14 > : public TIM_common< 0x40002000 > { }; 56 | 57 | } // namespace mptl 58 | 59 | #endif // ARCH_REG_TIM_HPP_INCLUDED 60 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f4/include/arch/reg/usart.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | /* 22 | * This program contains derivative representations of CMSIS System 23 | * View Description (SVD) files, and is subject to the "End User 24 | * License Agreement for STMicroelectronics" (see "STM_License.html" 25 | * in the containing directory). 26 | */ 27 | 28 | #ifndef ARCH_REG_USART_HPP_INCLUDED 29 | #define ARCH_REG_USART_HPP_INCLUDED 30 | 31 | #include "../../../../common/reg/usart.hpp" 32 | 33 | namespace mptl { 34 | 35 | template 36 | class USART 37 | { 38 | /* See available template specialisations below if the compiler asserts here! */ 39 | static_assert(usart_no == !usart_no, "unsupported USART number"); // assertion needs to be dependent of template parameter 40 | }; 41 | 42 | template<> class USART<1> : public USART_common_ext< 0x40011000 > { }; 43 | template<> class USART<2> : public USART_common_ext< 0x40004400 > { }; 44 | template<> class USART<3> : public USART_common_ext< 0x40004800 > { }; 45 | template<> class USART<6> : public USART_common_ext< 0x40011400 > { }; 46 | 47 | } // namespace mptl 48 | 49 | #endif // ARCH_REG_USART_HPP_INCLUDED 50 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f4/include/arch/scb.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_SCB_HPP_INCLUDED 22 | #define ARCH_SCB_HPP_INCLUDED 23 | 24 | #include "../../../../common/scb.hpp" 25 | 26 | #endif // ARCH_SCB_HPP_INCLUDED 27 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f4/include/arch/spi.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_SPI_HPP_INCLUDED 22 | #define ARCH_SPI_HPP_INCLUDED 23 | 24 | #include "../../../common/spi.hpp" 25 | 26 | #endif // ARCH_SPI_HPP_INCLUDED 27 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f4/include/arch/systick.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_SYSTICK_HPP_INCLUDED 22 | #define ARCH_SYSTICK_HPP_INCLUDED 23 | 24 | #include "../../../../common/systick.hpp" 25 | 26 | #endif // ARCH_SYSTICK_HPP_INCLUDED 27 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f4/include/arch/usart.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_USART_HPP_INCLUDED 22 | #define ARCH_USART_HPP_INCLUDED 23 | 24 | #include 25 | #include "../../../common/usart.hpp" 26 | 27 | namespace mptl { 28 | 29 | namespace mpl 30 | { 31 | template< typename gpio_type, unsigned gpio_alt_func_num > 32 | struct usart_gpio_rx_resources { 33 | using type = typelist< 34 | typename gpio_type::resources, 35 | typename gpio_type::resistor::floating, 36 | typename gpio_type::mode::alternate_function, // implicitely set by alt_func_num, but does not harm 37 | typename gpio_type::template alt_func_num< gpio_alt_func_num > 38 | >; 39 | }; 40 | template< unsigned gpio_alt_func_num > 41 | struct usart_gpio_rx_resources< void, gpio_alt_func_num > { 42 | using type = void; 43 | }; 44 | 45 | template< typename gpio_type, freq_t gpio_speed, unsigned gpio_alt_func_num > 46 | struct usart_gpio_tx_resources { 47 | using type = typelist< 48 | typename gpio_type::resources, 49 | typename gpio_type::output_type::push_pull, 50 | typename gpio_type::resistor::floating, 51 | typename gpio_type::template speed< gpio_speed >, 52 | typename gpio_type::mode::alternate_function, // implicitely set by alt_func_num, but does not harm 53 | typename gpio_type::template alt_func_num< gpio_alt_func_num > 54 | >; 55 | }; 56 | template< freq_t gpio_speed, unsigned gpio_alt_func_num > 57 | struct usart_gpio_tx_resources< void, gpio_speed, gpio_alt_func_num > { 58 | using type = void; 59 | }; 60 | } // namespace mpl 61 | 62 | 63 | template< 64 | unsigned usart_no, 65 | typename system_clock_type, 66 | typename gpio_rx_type, 67 | typename gpio_tx_type, 68 | freq_t gpio_tx_speed = mhz(50) 69 | > 70 | class usart : public usart_stm32_common< usart_no, system_clock_type > 71 | { 72 | using base_type = usart_stm32_common< usart_no, system_clock_type >; 73 | 74 | static constexpr unsigned gpio_alt_func_num = (usart_no <= 3) ? 7 : 8; 75 | 76 | public: 77 | 78 | using resources = typelist< 79 | typename base_type::resources, 80 | typename mpl::usart_gpio_rx_resources< gpio_rx_type, gpio_alt_func_num >::type, 81 | typename mpl::usart_gpio_tx_resources< gpio_tx_type, gpio_tx_speed, gpio_alt_func_num >::type 82 | >; 83 | }; 84 | 85 | } // namespace mptl 86 | 87 | 88 | #endif // ARCH_USART_HPP_INCLUDED 89 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f4/include/arch/usart_stream.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_USART_STREAM_HPP_INCLUDED 22 | #define ARCH_USART_STREAM_HPP_INCLUDED 23 | 24 | #include "../../../common/usart_stream.hpp" 25 | 26 | #endif // ARCH_USART_STREAM_HPP_INCLUDED 27 | -------------------------------------------------------------------------------- /arch/arm/cortex/stm32/f4/include/arch/vector_table.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ARCH_VECTOR_TABLE_HPP_INCLUDED 22 | #define ARCH_VECTOR_TABLE_HPP_INCLUDED 23 | 24 | #include "../../../../common/vector_table.hpp" 25 | 26 | #endif // ARCH_VECTOR_TABLE_HPP_INCLUDED 27 | -------------------------------------------------------------------------------- /bin/sim_terminal.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cleanup() { 4 | echo -e '\n+++ restoring terminal settings' 5 | stty $OLDCONFIG || echo '!!! failed to reset terminal settings' 6 | exit 0 7 | } 8 | 9 | SIM_EXE=$1 10 | 11 | if [ -z $SIM_EXE ] ; then 12 | echo "usage: $0 " 13 | exit 1 14 | fi 15 | 16 | # save configuration 17 | OLDCONFIG=`stty -g` 18 | 19 | trap cleanup SIGINT SIGTERM 20 | 21 | echo '+++ setting terminal: char-buffer, echo-off' 22 | stty -echo -icanon line 1 23 | 24 | $SIM_EXE 2> /dev/null 25 | 26 | cleanup 27 | -------------------------------------------------------------------------------- /config/boost.mk: -------------------------------------------------------------------------------- 1 | BOOST_DIR = /usr/include/boost-1_49 2 | 3 | BOOST_INCLUDE = -I $(BOOST_DIR) 4 | BOOST_FLAGS = -DBOOST_DISABLE_ASSERTS -DBOOST_NO_EXCEPTIONS 5 | -------------------------------------------------------------------------------- /config/clang.mk: -------------------------------------------------------------------------------- 1 | ifdef CLANG 2 | 3 | ifndef SIMULATION 4 | 5 | # Consider defining CROSS_CLANG if you have an architecture dependent 6 | # llvm/clang build: 7 | # 8 | # --with-gcc-toolchain 9 | # --with-default-sysroot 10 | # --with-c-include-dirs 11 | 12 | ifndef CROSS_CLANG 13 | 14 | # NOTE: llvm/clang support is very experimental, and may or may not work for your compiler. 15 | 16 | # NOTE: llvm linker needs compiler-rt, which is not available for our platforms. 17 | # see: https://github.com/ReservedField/arm-compiler-rt 18 | 19 | #GCC_VERSION=7.2.0 20 | #TRIPLE=armv7m-none-eabi 21 | #TOOLCHAIN_DIR=/opt/toolchain/$(TRIPLE)-$(GCC_VERSION) 22 | 23 | GCC_VERSION := $(shell $(CC) -dumpversion) 24 | TRIPLE := $(shell $(CC) -dumpmachine) 25 | TOOLCHAIN_DIR := $(shell which $(CC)) 26 | TOOLCHAIN_DIR := $(shell dirname $(TOOLCHAIN_DIR)) 27 | TOOLCHAIN_DIR := $(shell dirname $(TOOLCHAIN_DIR)) 28 | 29 | # NOTE: these flags seem to change on each major llvm revision. Leave them all for now. 30 | CLANG_SYSROOT += -resource-dir $(TOOLCHAIN_DIR) 31 | CLANG_SYSROOT += -isysroot $(TOOLCHAIN_DIR)/$(TRIPLE) 32 | CLANG_SYSROOT += -nostdinc++ 33 | CLANG_SYSROOT += -nostdlibinc 34 | 35 | CLANG_SYSROOT += -cxx-isystem $(TOOLCHAIN_DIR)/$(TRIPLE)/include/c++/$(GCC_VERSION) 36 | CLANG_SYSROOT += -cxx-isystem $(TOOLCHAIN_DIR)/$(TRIPLE)/include/c++/$(GCC_VERSION)/$(TRIPLE) 37 | CLANG_SYSROOT += -cxx-isystem $(TOOLCHAIN_DIR)/$(TRIPLE)/include/c++/$(GCC_VERSION)/backward 38 | 39 | CLANG_SYSROOT += -isystem $(TOOLCHAIN_DIR)/include 40 | CLANG_SYSROOT += -isystem $(TOOLCHAIN_DIR)/$(TRIPLE)/include 41 | 42 | # we also want to use standard include from gcc-toolchain: 43 | CLANG_SYSROOT += -nostdinc 44 | CLANG_SYSROOT += -isystem $(TOOLCHAIN_DIR)/lib/gcc/$(TRIPLE)/$(GCC_VERSION)/include 45 | 46 | LDFLAGS += -L$(TOOLCHAIN_DIR)/$(TRIPLE)/lib 47 | LDFLAGS += -L$(TOOLCHAIN_DIR)/lib/gcc/$(TRIPLE)/$(GCC_VERSION) 48 | 49 | # NOTE: as of clang-5.0.0, the default linker is ld.lld, which does not seem to work correctly 50 | LDFLAGS += -fuse-ld=bfd 51 | #LDFLAGS += -fuse-ld=gold -static -Wl,-plugin=/usr/lib64/llvm/4/lib64/LLVMgold.so -L${TOOLCHAIN_DIR}/${TRIPLE}/lib 52 | 53 | # we dont have compiler-rt build for armv7em. projects which depend on it will not work. 54 | LDFLAGS += -nostdlib 55 | #LDFLAGS += -lstdc++ 56 | 57 | CLANG_TARGET += -target $(TRIPLE) 58 | CLANG_TARGET += -ccc-gcc-name $(TRIPLE)-gcc 59 | 60 | # NOTE: clang-4 does not need this any more (and issues a warning) 61 | CLANG_TARGET += -gcc-toolchain $(TOOLCHAIN_DIR) 62 | 63 | CLANG_VERBOSE = -v 64 | endif 65 | 66 | else # SIMULATION 67 | 68 | ifdef CLANG_LIBSTDCPP 69 | CXXFLAGS += -stdlib=libstdc++ 70 | else 71 | # use libcxx by default (llvm's c++ standard library implementation, yum!) 72 | CXXFLAGS += -stdlib=libc++ 73 | LDFLAGS += -lc++ 74 | #LDFLAGS += -lc++abi 75 | endif 76 | 77 | endif # SIMULATION 78 | 79 | CC = $(CROSS_CLANG)clang $(CLANG_VERBOSE) $(CLANG_SYSROOT) $(CLANG_TARGET) 80 | CXX = $(CROSS_CLANG)clang++ $(CLANG_VERBOSE) $(CLANG_SYSROOT) $(CLANG_TARGET) 81 | AS = $(CROSS)gcc -x assembler-with-cpp 82 | LD = $(CROSS_CLANG)clang $(CLANG_VERBOSE) $(CLANG_TARGET) 83 | #LD = $(CROSS)ld.gold --verbose -static -plugin $(TOOLCHAIN_DIR)/lib/LLVMgold.so -L${TOOLCHAIN_DIR}/${TRIPLE}/lib -lc 84 | OBJCOPY = $(CROSS)objcopy 85 | OBJDUMP = $(CROSS)objdump 86 | SIZE = $(CROSS)size -B -d 87 | 88 | FLAGS += -DCONFIG_CLANG 89 | 90 | # emit llvm bytecode by default 91 | CLANG_EMIT_LLVM = 1 92 | 93 | endif # CLANG 94 | -------------------------------------------------------------------------------- /config/doxygen.mk: -------------------------------------------------------------------------------- 1 | DOXYGEN = doxygen 2 | 3 | 4 | .PHONY: doxygen 5 | 6 | doxygen: 7 | $(DOXYGEN) $(DOCDIR)/doxygen.conf 8 | 9 | -------------------------------------------------------------------------------- /config/gcc.mk: -------------------------------------------------------------------------------- 1 | CC = $(CROSS)gcc 2 | CXX = $(CROSS)g++ 3 | AS = $(CROSS)gcc -x assembler-with-cpp 4 | LD = $(CROSS)g++ 5 | OBJCOPY = $(CROSS)objcopy 6 | OBJDUMP = $(CROSS)objdump 7 | SIZE = $(CROSS)size -B -d 8 | -------------------------------------------------------------------------------- /config/gdb-target.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /config/openmptl.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Input variables: 3 | # 4 | # - OPENMPTL_TOP : OpenMPTL top directory 5 | # - OPENMPTL_ARCH : Architecture (e.g. "stm32f10x") 6 | # 7 | # 8 | # Output variables: 9 | # 10 | # - OPENMPTL_INCLUDE : compiler include flags 11 | # 12 | 13 | OPENMPTL_DOC_DIR = $(OPENMPTL_TOP)/doc 14 | OPENMPTL_ARCH_DIR = $(OPENMPTL_TOP)/arch 15 | OPENMPTL_DRIVERS_DIR = $(OPENMPTL_TOP)/drivers 16 | OPENMPTL_LIB_DIR = $(OPENMPTL_TOP)/lib 17 | OPENMPTL_INCLUDE_DIR = $(OPENMPTL_TOP)/include 18 | 19 | OPENMPTL_INCLUDE = -I $(OPENMPTL_INCLUDE_DIR) 20 | OPENMPTL_INCLUDE += -I $(OPENMPTL_DRIVERS_DIR) 21 | OPENMPTL_INCLUDE += -I $(OPENMPTL_LIB_DIR)/include 22 | OPENMPTL_INCLUDE += -I $(OPENMPTL_ARCH_DIR)/$(OPENMPTL_ARCH)/include 23 | -------------------------------------------------------------------------------- /config/openocd.mk: -------------------------------------------------------------------------------- 1 | OPENOCD = openocd 2 | 3 | oocd_gdb_port = 3333 4 | 5 | oocd_params = -d1 # debug level (d0..d3) 6 | # oocd_params += -c "fast enable" 7 | oocd_params += $(OPENOCD_CONFIG) 8 | oocd_params += -c init -c targets 9 | 10 | oocd_params_program = $(oocd_params) 11 | oocd_params_program += -c "reset halt" 12 | oocd_params_program += -c "flash write_image erase $(ELF)" -c "verify_image $(ELF)" 13 | oocd_params_program += -c "reset run" 14 | oocd_params_program += -c "shutdown" # terminate OOCD after programming 15 | 16 | oocd_params_reset = $(oocd_params) 17 | oocd_params_reset += -c "reset run" 18 | oocd_params_reset += -c "shutdown" 19 | 20 | oocd_params_debug = -c "gdb_port $(oocd_gdb_port)" 21 | oocd_params_debug += $(oocd_params) 22 | oocd_params_debug += -c "reset halt" 23 | 24 | 25 | .PHONY: program flash reset debug 26 | 27 | program: $(ELF) 28 | @echo "--- Programming with OPENOCD" 29 | $(OPENOCD) $(oocd_params_program) 30 | 31 | flash: program 32 | 33 | reset: 34 | @echo "--- Resetting device" 35 | $(OPENOCD) $(oocd_params_reset) 36 | 37 | debug: 38 | # Note on gdb-target.xml: 39 | # OpenOCD does not provide an XML target description 40 | # (qXfer:features:read) to GDB, resulting in an error: "Remote 'g' 41 | # packet reply is too long". As a workaround, we provide a target 42 | # description XML file directly to GDB using the following GDB 43 | # command: set tdesc filename 44 | @echo Starting OpenOCD debugger 45 | @echo "*" 46 | 47 | # gdb-target.xml is not needed anymore with recent versions 48 | # @echo "* $(CROSS)gdb -ex \"set tdesc filename gdb-target.xml\" -ex \"target remote localhost:$(oocd_gdb_port)\" $(ELF)" 49 | @echo "* $(CROSS)gdb -ex \"target remote localhost:$(oocd_gdb_port)\" $(ELF)" 50 | @echo "*" 51 | $(OPENOCD) $(oocd_params_debug) 52 | -------------------------------------------------------------------------------- /config/simulation.mk: -------------------------------------------------------------------------------- 1 | ifdef SIMULATION 2 | SIM_SRC_DIR = $(OPENMPTL_TOP)/sim 3 | 4 | SRCS += $(wildcard $(addsuffix /*.cpp, $(SIM_SRC_DIR))) 5 | 6 | vpath %.cpp $(SIM_SRC_DIR) 7 | endif 8 | -------------------------------------------------------------------------------- /config/system.mk: -------------------------------------------------------------------------------- 1 | RM = rm -f 2 | RM_R = rm -rf 3 | CP = cp 4 | MKDIR_P = mkdir -p 5 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | /*.tag 2 | /openmptl 3 | /lib 4 | /drivers 5 | /arm_cortex_common 6 | /stm32_common 7 | /stm32f10x 8 | /stm32f4 9 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | #OUTPUT_DIRECTORY = /tmp/doxygen 2 | OUTPUT_DIRECTORY = 3 | 4 | DOCS = openmptl \ 5 | lib \ 6 | drivers \ 7 | arm_cortex_common \ 8 | stm32_common \ 9 | stm32f10x \ 10 | stm32f4 11 | 12 | DOXYGEN = doxygen 13 | 14 | all: $(DOCS) 15 | 16 | $(DOCS): 17 | @echo "*** Checking $@.conf" 18 | grep -q -e "^HTML_OUTPUT\s*=\s*$@" $@.conf 19 | @echo "*** Building $@" 20 | ( cat $@.conf ; echo "OUTPUT_DIRECTORY=$(OUTPUT_DIRECTORY)" ) | $(DOXYGEN) - 21 | 22 | clean: 23 | rm -f *.tag 24 | -------------------------------------------------------------------------------- /doc/arm_cortex_common.conf: -------------------------------------------------------------------------------- 1 | @INCLUDE = doxygen.conf 2 | PROJECT_NAME = "OpenMPTL - ARM Cortex (common)" 3 | INPUT = mainpage.md \ 4 | ../arch/arm/cortex/common 5 | HTML_OUTPUT = arm_cortex_common 6 | GENERATE_TAGFILE = arm_cortex_common.tag 7 | TAGFILES = openmptl.tag=../openmptl 8 | ALLEXTERNALS = YES 9 | -------------------------------------------------------------------------------- /doc/drivers.conf: -------------------------------------------------------------------------------- 1 | @INCLUDE = doxygen.conf 2 | PROJECT_NAME = "OpenMPTL - Drivers" 3 | INPUT = mainpage.md \ 4 | ../drivers 5 | HTML_OUTPUT = drivers 6 | TAGFILES = openmptl.tag=../openmptl \ 7 | arm_cortex_common.tag=../arm_cortex_common \ 8 | stm32_common.tag=../stm32_common 9 | ALLEXTERNALS = NO 10 | -------------------------------------------------------------------------------- /doc/lib.conf: -------------------------------------------------------------------------------- 1 | @INCLUDE = doxygen.conf 2 | PROJECT_NAME = "OpenMPTL - Helper Library" 3 | INPUT = mainpage.md \ 4 | ../lib 5 | HTML_OUTPUT = lib 6 | TAGFILES = openmptl.tag=../openmptl \ 7 | arm_cortex_common.tag=../arm_cortex_common \ 8 | stm32_common.tag=../stm32_common 9 | ALLEXTERNALS = NO 10 | -------------------------------------------------------------------------------- /doc/mainpage.md: -------------------------------------------------------------------------------- 1 | The OpenMPTL API reference documentation is split into multiple sub-documents: 2 | 3 | * [OpenMPTL Core Library](../openmptl/index.html) 4 | * [OpenMPTL Helper Library](../lib/index.html) 5 | * [OpenMPTL Drivers](../drivers/index.html) 6 | * [ARM Cortex (common)](../arm_cortex_common/index.html) 7 | * [STM32 (common)](../stm32_common/index.html) 8 | * [STM32F10x](../stm32f10x/index.html) 9 | * [STM32F4](../stm32f4/index.html) 10 | 11 | Official home page: 12 | -------------------------------------------------------------------------------- /doc/openmptl.conf: -------------------------------------------------------------------------------- 1 | @INCLUDE = doxygen.conf 2 | PROJECT_NAME = OpenMPTL 3 | INPUT = mainpage.md \ 4 | ../include 5 | HTML_OUTPUT = openmptl 6 | GENERATE_TAGFILE = openmptl.tag 7 | -------------------------------------------------------------------------------- /doc/stm32_common.conf: -------------------------------------------------------------------------------- 1 | @INCLUDE = doxygen.conf 2 | PROJECT_NAME = "OpenMPTL - STM32 (common)" 3 | INPUT = mainpage.md \ 4 | ../arch/arm/cortex/stm32/common 5 | HTML_OUTPUT = stm32_common 6 | GENERATE_TAGFILE = stm32_common.tag 7 | TAGFILES = openmptl.tag=../openmptl \ 8 | arm_cortex_common.tag=../arm_cortex_common 9 | ALLEXTERNALS = YES 10 | -------------------------------------------------------------------------------- /doc/stm32f10x.conf: -------------------------------------------------------------------------------- 1 | @INCLUDE = doxygen.conf 2 | PROJECT_NAME = "OpenMPTL - STM32F10X" 3 | INPUT = mainpage.md \ 4 | ../arch/arm/cortex/stm32/f1 5 | EXCLUDE_PATTERNS = */address_map.hpp 6 | PREDEFINED = STM32F10X_CL 7 | HTML_OUTPUT = stm32f10x 8 | TAGFILES = openmptl.tag=../openmptl \ 9 | arm_cortex_common.tag=../arm_cortex_common \ 10 | stm32_common.tag=../stm32_common 11 | ALLEXTERNALS = YES 12 | -------------------------------------------------------------------------------- /doc/stm32f4.conf: -------------------------------------------------------------------------------- 1 | @INCLUDE = doxygen.conf 2 | PROJECT_NAME = "OpenMPTL - STM32F4" 3 | INPUT = mainpage.md \ 4 | ../arch/arm/cortex/stm32/f4 5 | EXCLUDE_PATTERNS = */address_map.hpp 6 | #PREDEFINED = STM32F10X_CL 7 | HTML_OUTPUT = stm32f4 8 | TAGFILES = openmptl.tag=../openmptl \ 9 | arm_cortex_common.tag=../arm_cortex_common \ 10 | stm32_common.tag=../stm32_common 11 | ALLEXTERNALS = YES 12 | -------------------------------------------------------------------------------- /drivers/joystick/stm32f103stk/joystick.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef JOYSTICK_HPP_INCLUDED 22 | #define JOYSTICK_HPP_INCLUDED 23 | 24 | #include 25 | 26 | namespace mptl { namespace device { 27 | 28 | class joystick 29 | { 30 | using button = mptl::gpio_input< 'C', 6, gpio_active_state::high >; 31 | 32 | using adc = mptl::adc< 1 >; 33 | using adc_cfg = mptl::reglist< 34 | adc::external_trigger_conversion::software_start, 35 | adc::regular_channel_sequence_length< 1 >, 36 | adc::regular_channel_config< 15, 1, adc::sample_time::cycles_55_5 > 37 | >; 38 | 39 | static int adc_convert_blocking(void) { 40 | adc::enable_software_start_conversion(); 41 | adc::wait_eoc(); 42 | return adc::get_conversion_value(); 43 | } 44 | 45 | public: 46 | 47 | using resources = mptl::typelist< 48 | typename adc::resources, 49 | adc_cfg, 50 | typename button::resources, 51 | 52 | /* configure GPIO's */ 53 | typename button::input_type::floating 54 | >; 55 | 56 | enum class position { center, up, down, left, right }; 57 | 58 | static void enable(void) { 59 | adc::enable(); 60 | } 61 | 62 | static void configure(void) { 63 | adc::template configure< adc_cfg >(); 64 | } 65 | 66 | static position get_position_blocking(void) { 67 | int value = adc_convert_blocking(); 68 | 69 | int up_value = 960; 70 | int down_value = 190; 71 | int left_value = 1990; 72 | int right_value = 470; 73 | int threshold = 30; 74 | 75 | if((value > (up_value - threshold)) && (value < (up_value + threshold)) ) { return position::up; } 76 | if((value > (down_value - threshold)) && (value < (down_value + threshold)) ) { return position::down; } 77 | if((value > (left_value - threshold)) && (value < (left_value + threshold)) ) { return position::left; } 78 | if((value > (right_value - threshold)) && (value < (right_value + threshold)) ) { return position::right; } 79 | 80 | return position::center; 81 | } 82 | 83 | static bool button_pressed(void) { 84 | return button::active(); 85 | } 86 | }; 87 | 88 | } } // namespace mptl::device 89 | 90 | #endif // JOYSTICK_HPP_INCLUDED 91 | -------------------------------------------------------------------------------- /include/compiler.h: -------------------------------------------------------------------------------- 1 | #ifndef COMPILER_H_INCLUDED 2 | #define COMPILER_H_INCLUDED 3 | 4 | #define __weak __attribute__((weak)) 5 | 6 | /* Function attributes */ 7 | #ifndef __always_inline 8 | # define __always_inline inline __attribute__((always_inline)) 9 | #endif 10 | 11 | // NOTE: While non-ASM statement in naked function is not supported, 12 | // it works fine in our projects (arm). Use with care! 13 | #ifdef CONFIG_CLANG 14 | # define __naked __attribute__((noinline)) 15 | #else 16 | # define __naked __attribute__((naked)) __attribute__((noinline)) 17 | #endif // CONFIG_CLANG 18 | 19 | #define __noreturn __attribute__((noreturn)) 20 | 21 | /* Variable attributes */ 22 | #ifndef __used 23 | # define __used __attribute__((used)) 24 | #endif 25 | 26 | #endif // COMPILER_H_INCLUDED 27 | -------------------------------------------------------------------------------- /include/crt.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | /* 22 | * NOTE: In order to use global objects, you need to define (somewhere in your code): 23 | * 24 | * void *__dso_handle; 25 | */ 26 | 27 | #ifndef CRT_HPP_INCLUDED 28 | #define CRT_HPP_INCLUDED 29 | 30 | #ifndef OPENMPTL_SIMULATION 31 | 32 | #include 33 | 34 | /* Make sure your linker script provides these: */ 35 | extern uint32_t _data_lma; /* load address of data section */ 36 | extern uint32_t _sdata; 37 | extern uint32_t _edata; 38 | extern uint32_t _sbss; 39 | extern uint32_t _ebss; 40 | extern void (*__preinit_array_start []) (void); 41 | extern void (*__preinit_array_end []) (void); 42 | extern void (*__init_array_start []) (void); 43 | extern void (*__init_array_end []) (void); 44 | extern void (*__fini_array_start []) (void); 45 | extern void (*__fini_array_end []) (void); 46 | 47 | namespace crt 48 | { 49 | static inline void init_data_section(void) { 50 | uint32_t *src = &_data_lma; 51 | uint32_t *dst = &_sdata; 52 | while(dst < &_edata) 53 | *(dst++) = *(src++); 54 | } 55 | 56 | static inline void init_bss_section(void) { 57 | uint32_t *dst = &_sbss; 58 | while(dst < &_ebss) 59 | *(dst++) = 0; 60 | } 61 | 62 | /** call functions in preinit_array */ 63 | static inline void run_preinit_array(void) { 64 | uintptr_t n = __preinit_array_end - __preinit_array_start; 65 | uintptr_t i = 0; 66 | while(i < n) 67 | __preinit_array_start[i++](); 68 | } 69 | 70 | /** call functions in init_array (constructors) */ 71 | static inline void run_init_array(void) { 72 | uintptr_t n = __init_array_end - __init_array_start; 73 | uintptr_t i = 0; 74 | while(i < n) 75 | __init_array_start[i++](); 76 | } 77 | 78 | /** call functions in fini_array (destructors) */ 79 | static inline void run_fini_array(void) { 80 | uintptr_t n = __fini_array_end - __fini_array_start; 81 | uintptr_t i = 0; 82 | while(i < n) 83 | __fini_array_start[i++](); 84 | } 85 | } // namespace crt 86 | 87 | #else // OPENMPTL_SIMULATION 88 | 89 | namespace crt 90 | { 91 | static inline void init_data_section(void) { } 92 | static inline void init_bss_section(void) { } 93 | static inline void run_preinit_array(void) { } 94 | static inline void run_init_array(void) { } 95 | static inline void run_fini_array(void) { } 96 | } // namespace crt 97 | 98 | #endif //OPENMPTL_SIMULATION 99 | 100 | #endif // CRT_HPP_INCLUDED 101 | -------------------------------------------------------------------------------- /include/freq.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef FREQ_HPP_INCLUDED 22 | #define FREQ_HPP_INCLUDED 23 | 24 | namespace mptl { 25 | 26 | typedef unsigned int freq_t; 27 | 28 | #if 0 // literals don't like namespaces... 29 | 30 | static constexpr freq_t operator"" _hz (unsigned long long x) { return x; } 31 | static constexpr freq_t operator"" _khz(unsigned long long x) { return x * 1000; } 32 | static constexpr freq_t operator"" _mhz(unsigned long long x) { return x * 1000 * 1000; } 33 | 34 | static constexpr freq_t operator"" _khz(long double x) { return x * 1000; } 35 | static constexpr freq_t operator"" _mhz(long double x) { return x * 1000 * 1000; } 36 | 37 | //static_assert(1.0009_khz == 1000, "doubles are always rounded down"); 38 | 39 | #endif 40 | 41 | static inline constexpr freq_t hz (unsigned long long x) { return x; } 42 | static inline constexpr freq_t khz(unsigned long long x) { return x * 1000; } 43 | static inline constexpr freq_t mhz(unsigned long long x) { return x * 1000 * 1000; } 44 | 45 | } // namespace mptl 46 | 47 | #endif // FREQ_HPP_INCLUDED 48 | -------------------------------------------------------------------------------- /include/gpio_base.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef COMMON_GPIO_BASE_HPP_INCLUDED 22 | #define COMMON_GPIO_BASE_HPP_INCLUDED 23 | 24 | namespace mptl { 25 | 26 | enum class gpio_active_state { low, high }; 27 | 28 | //////////////////// gpio_input //////////////////// 29 | 30 | 31 | template< typename base_type, gpio_active_state active_state > 32 | class gpio_input_base 33 | : public base_type 34 | { 35 | public: 36 | static bool active(void) { 37 | bool input = base_type::read_input_bit(); 38 | return active_state == gpio_active_state::low ? !input : input; 39 | } 40 | }; 41 | 42 | 43 | //////////////////// gpio_output //////////////////// 44 | 45 | 46 | template< typename base_type, gpio_active_state active_state > 47 | class gpio_output_base 48 | : public base_type 49 | { 50 | public: 51 | static void enable() { 52 | if(active_state == gpio_active_state::low) { 53 | base_type::reset(); 54 | } else { 55 | base_type::set(); 56 | } 57 | } 58 | 59 | static void disable() { 60 | if(active_state == gpio_active_state::low) { 61 | base_type::set(); 62 | } else { 63 | base_type::reset(); 64 | } 65 | } 66 | 67 | static bool active() { 68 | bool input = base_type::read_input_bit(); 69 | return active_state == gpio_active_state::low ? !input : input; 70 | } 71 | 72 | static void toggle() { 73 | if(base_type::read_input_bit()) { 74 | base_type::reset(); 75 | } 76 | else { 77 | base_type::set(); 78 | } 79 | } 80 | 81 | static bool latched() { 82 | bool output = base_type::read_output_bit(); 83 | return active_state == gpio_active_state::low ? !output : output; 84 | } 85 | }; 86 | 87 | 88 | //////////////////// gpio_analog_io //////////////////// 89 | 90 | 91 | template< typename base_type > 92 | class gpio_analog_io_base 93 | : public base_type 94 | { 95 | // TODO: get/set analog value 96 | }; 97 | 98 | 99 | //////////////////// gpio_led //////////////////// 100 | 101 | 102 | /** NOTE: needs class derived from gpio_output_base<> as base type */ 103 | template< typename base_type > 104 | class gpio_led_base 105 | : public base_type 106 | { 107 | public: 108 | static void on() { 109 | base_type::enable(); 110 | } 111 | static void off() { 112 | base_type::disable(); 113 | } 114 | }; 115 | 116 | } // namespace mptl 117 | 118 | 119 | #endif // COMMON_GPIO_BASE_HPP_INCLUDED 120 | -------------------------------------------------------------------------------- /include/isr.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef ISR_HPP_INCLUDED 22 | #define ISR_HPP_INCLUDED 23 | 24 | #include 25 | #include 26 | 27 | namespace mptl { 28 | 29 | typedef void( *const isr_t )( void ); 30 | 31 | struct irq_handler_base 32 | : public typelist_unique_element< irq_handler_base > 33 | { }; 34 | 35 | template 36 | struct irq_handler : irq_handler_base 37 | { 38 | using irq_type = Tp; 39 | static constexpr isr_t value = isr; 40 | 41 | #ifdef OPENMPTL_SIMULATION 42 | static void dump_type(void) { 43 | std::string s = __PRETTY_FUNCTION__; 44 | std::cout << "irq_handler " << s.substr(s.find('['), s.rfind(']')) << std::endl; 45 | } 46 | #endif 47 | }; 48 | 49 | 50 | namespace mpl 51 | { 52 | template 53 | struct filter_irqn { 54 | template 55 | using filter = std::integral_constant< bool, (T::irq_type::irqn == _irqn) >; 56 | }; 57 | 58 | /** typelist, filtered to only hold irq_handler_base type */ 59 | template 60 | using irq_handler_list = typename typelist_type::template filter_type< irq_handler_base >; 61 | 62 | /** typelist, filtered to only hold irq_handler with given irq number (int irqn) */ 63 | template 64 | using irqn_list = typename irq_handler_list::template filter< filter_irqn< irqn > >; 65 | 66 | 67 | /** 68 | * Provides the mptl::irq_handler<> element type from a given typelist<> and 69 | * irq number (int irqn). 70 | * 71 | * NOTE: Asserts at compile-time (static_assert) that the returned 72 | * irq_handler is unique in the typelist. 73 | */ 74 | template 75 | using unique_irq_handler = typename irqn_list::unique_element::type; 76 | 77 | #ifdef OPENMPTL_SIMULATION 78 | template 79 | struct dump_irq_types { 80 | void operator()() { }; 81 | }; 82 | 83 | template 84 | struct dump_irq_types { 85 | void operator()() { 86 | std::cout << std::setw(3) << Head::irq_type::irqn << " : "; 87 | Head::dump_type(); 88 | dump_irq_types()(); 89 | }; 90 | }; 91 | #endif // OPENMPTL_SIMULATION 92 | 93 | } // namespace mpl 94 | 95 | } // namespace mptl 96 | 97 | #endif // ISR_HPP_INCLUDED 98 | -------------------------------------------------------------------------------- /include/register_manip.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | // TODO: implement make_reg<> class, analog to 22 | // std::make_tuple<>. This way we can put them into a std::tuple<> 23 | // class and perform the merge as instances 24 | // 25 | // ^^^ allows to mix compile-time traits with reg_manip<> types ! 26 | 27 | 28 | #ifndef REGISTER_MANIP_HPP_INCLUDED 29 | #define REGISTER_MANIP_HPP_INCLUDED 30 | 31 | #warning "This is experimental code!" 32 | 33 | #include 34 | 35 | namespace mptl { 36 | namespace experimental { 37 | 38 | // TODO: rename reg<> 39 | template 40 | class reg_manip 41 | { 42 | public: 43 | using value_type = typename T::value_type; 44 | 45 | // TODO: wrong. only construct from known regmask<> traits, or 46 | // set/clear mask tuple. NEVER do load() magic in constructors! 47 | reg_manip() : reg(T::load()) { } 48 | reg_manip(value_type val) : reg(val) { } 49 | 50 | reg_manip operator|(const T & rhs) { return reg_manip(reg | rhs); } 51 | 52 | reg_manip & operator=(const reg_manip &) { return *this; } 53 | reg_manip & operator|=(value_type rhs) { this->reg |= rhs; return *this; } 54 | reg_manip & operator&=(value_type rhs) { this->reg &= rhs; return *this; } 55 | 56 | constexpr operator value_type() { return reg; } 57 | 58 | void __always_inline load(void) { reg = T::load(); } 59 | void __always_inline store(void) const { T::store(reg); } 60 | 61 | void __always_inline set(value_type const set_mask) { reg |= set_mask; } 62 | void __always_inline set(value_type const set_mask, value_type const clear_mask) { reg = (reg & ~clear_mask) | set_mask; } 63 | void __always_inline clear(value_type const value) { reg &= ~value; } 64 | 65 | template 66 | void __always_inline clear(void) { 67 | clear(T::template merge::type::clear_mask); 68 | } 69 | 70 | template 71 | void __always_inline set(void) { 72 | using merged_type = typename T::template merge::type; 73 | set( merged_type::set_mask, merged_type::cropped_clear_mask ); 74 | } 75 | 76 | private: 77 | value_type reg; 78 | }; 79 | 80 | } // namespace experimental 81 | } // namespace mptl 82 | 83 | #endif // REGISTER_MANIP_HPP_INCLUDED 84 | -------------------------------------------------------------------------------- /include/register_type.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef REGISTER_TYPE_HPP_INCLUDED 22 | #define REGISTER_TYPE_HPP_INCLUDED 23 | 24 | #include 25 | 26 | namespace mptl { 27 | 28 | /** Register access permission */ 29 | enum reg_perm { ro, wo, rw }; 30 | 31 | #ifndef OPENMPTL_SIMULATION 32 | /** Register address type (uintptr_t: unsigned integer type capable of holding a pointer) */ 33 | using reg_addr_t = uintptr_t; 34 | #else 35 | using reg_addr_t = uint32_t; 36 | #endif 37 | 38 | } // namespace mptl 39 | 40 | #endif // REGISTER_TYPE_HPP_INCLUDED 41 | -------------------------------------------------------------------------------- /include/simulation.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef SIMULATION_HPP_INCLUDED 22 | #define SIMULATION_HPP_INCLUDED 23 | 24 | #ifdef OPENMPTL_SIMULATION 25 | # include 26 | # include 27 | # define SIM_DEBUG(msg) std::clog << msg << std::endl 28 | # define SIM_TRACE(msg) std::clog << msg << " - " << __PRETTY_FUNCTION__ << std::endl 29 | # define SIM_RELAX std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) ) 30 | #else 31 | # define SIM_DEBUG(msg) 32 | # define SIM_TRACE(msg) 33 | # define SIM_RELAX 34 | #endif // OPENMPTL_SIMULATION 35 | 36 | 37 | #endif // SIMULATION_HPP_INCLUDED 38 | -------------------------------------------------------------------------------- /include/voltage.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef VOLTAGE_HPP_INCLUDED 22 | #define VOLTAGE_HPP_INCLUDED 23 | 24 | namespace mptl { 25 | 26 | typedef unsigned int voltage_t; 27 | 28 | #if 0 // literals don't like namespaces... 29 | 30 | static constexpr voltage_t operator"" _volt(long double x) { return x * 1000; } 31 | 32 | //static_assert(1.0009_volt == 1000, "doubles are always rounded down"); 33 | 34 | #endif 35 | 36 | static constexpr voltage_t volt(long double x) { return x * 1000; } 37 | 38 | static_assert(volt(1.0009) == 1000, "doubles are always rounded down"); 39 | 40 | } // namespace mptl 41 | 42 | #endif // VOLTAGE_HPP_INCLUDED 43 | -------------------------------------------------------------------------------- /lib/include/debouncer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef DEBOUNCER_HPP_INCLUDED 22 | #define DEBOUNCER_HPP_INCLUDED 23 | 24 | /** 25 | * Debounce a value on a given time base 26 | * 27 | * NOTE: time_func() must return a growing value! 28 | */ 29 | template< typename T, 30 | T (*poll_func)(void), // polling function 31 | unsigned (*time_func)(void), // timer get function (must return a growing value) 32 | unsigned int time_freq, // time_func frequency in hz 33 | unsigned wait_time_ms = 50 // debounce time in milliseconds 34 | > 35 | class debouncer 36 | { 37 | T value; 38 | T current; 39 | unsigned hold_time; 40 | 41 | static constexpr unsigned wait_time_ticks = (((unsigned long long)time_freq * (unsigned long long)wait_time_ms) / 1000L); 42 | 43 | public: 44 | 45 | debouncer(T _value) : value(_value), current(_value), hold_time(0) { }; 46 | 47 | /** 48 | * Feed debouncer with a new value. 49 | * Returns true if the value has changed. 50 | */ 51 | bool poll(void) { 52 | T new_value = poll_func(); 53 | unsigned now = time_func(); 54 | if(current != new_value) { 55 | current = new_value; 56 | hold_time = now + wait_time_ticks; 57 | } 58 | 59 | if((hold_time > now) || (value == current)) 60 | return false; 61 | 62 | value = current; 63 | return true; 64 | } 65 | 66 | T get(void) const { 67 | return value; 68 | } 69 | 70 | operator T() const { 71 | return get(); 72 | } 73 | }; 74 | 75 | #endif // DEBOUNCER_HPP_INCLUDED 76 | -------------------------------------------------------------------------------- /lib/include/fifo_stream.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef FIFO_STREAM_HPP_INCLUDED 22 | #define FIFO_STREAM_HPP_INCLUDED 23 | 24 | #include 25 | 26 | namespace mptl { 27 | 28 | template 29 | class fifo_stream 30 | : public poorman::ostream 31 | { 32 | fifoT & fifo; 33 | 34 | public: 35 | 36 | fifo_stream(fifoT & f) : fifo(f) { }; 37 | 38 | using char_type = typename fifoT::char_type; 39 | 40 | poorman::ostream & put(char_type c) { 41 | fifo.push(c); 42 | return *this; 43 | } 44 | 45 | poorman::ostream & write(const char_type* s, unsigned int count) { 46 | fifo.pushs(s, count); 47 | return *this; 48 | } 49 | 50 | poorman::ostream & puts(const char_type* s) { 51 | fifo.pushs(s); 52 | return *this; 53 | } 54 | 55 | poorman::ostream & flush() { 56 | deviceT::flush(); 57 | return *this; 58 | } 59 | 60 | poorman::ostream & endl() { 61 | if(deviceT::crlf) 62 | fifo.push('\r'); 63 | fifo.push('\n'); 64 | deviceT::flush(); 65 | return *this; 66 | } 67 | }; 68 | 69 | } // namespace mptl 70 | 71 | #endif // FIFO_STREAM_HPP_INCLUDED 72 | -------------------------------------------------------------------------------- /lib/include/poorman_cstring.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef POORMAN_CSTRING_HPP_INCLUDED 22 | #define POORMAN_CSTRING_HPP_INCLUDED 23 | 24 | #include 25 | 26 | namespace poorman { 27 | 28 | /** 29 | * Prints "value" as hexadecimal number to buf, '0'-padded, zero 30 | * terminated. 31 | * 32 | * Negative values are printed as two's complement. 33 | * 34 | * NOTE: sizeof(buf) must be at least n+1 35 | */ 36 | template 37 | void itoa_hex(char * buf, Tp value, int n = sizeof(Tp)*2, char padding = '0') { 38 | using value_type = typename std::make_unsigned::type; 39 | value_type val = (value_type)value; 40 | unsigned v; 41 | 42 | buf[n--] = 0; 43 | if(val == 0) 44 | buf[n--] = '0'; 45 | while(n >= 0 && val) { 46 | v = val & 0xf; 47 | buf[n--] = v < 10 ? '0' + v : 'a' + v - 10; 48 | val >>= 4; 49 | }; 50 | while(n >= 0) { 51 | buf[n--] = padding; 52 | } 53 | if(val) { 54 | buf[0] = '~'; 55 | } 56 | } 57 | 58 | /** 59 | * Prints n digits of "value" to buf, right aligned, "padding"-padded, 60 | * zero terminated. 61 | * 62 | * Prints '~' as first character if "value" has more digits than n. 63 | * 64 | * NOTE: sizeof(buf) must be at least n+1 65 | */ 66 | template 67 | typename std::enable_if< std::is_unsigned< Tp >::value >::type 68 | itoa(char * buf, Tp value, int n, char padding = '0') { 69 | buf[n--] = 0; 70 | if(value == 0) 71 | buf[n--] = '0'; 72 | else { 73 | while(n >= 0 && value > 0) { 74 | buf[n--] = '0' + (value % 10); 75 | value /= 10; 76 | } 77 | } 78 | while(n >= 0) { 79 | buf[n--] = padding; 80 | } 81 | if(value > 0) { 82 | buf[0] = '~'; 83 | } 84 | } 85 | template 86 | typename std::enable_if< std::is_signed< Tp >::value >::type 87 | itoa(char * buf, Tp value, int n, char padding = '0') { 88 | *buf++ = '-'; 89 | itoa(buf, (unsigned)(-value), n-1, padding); 90 | } 91 | 92 | } // namespace poorman 93 | 94 | #endif // POORMAN_CSTRING_HPP_INCLUDED 95 | -------------------------------------------------------------------------------- /lib/include/poorman_ostream.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef POORMAN_OSTREAM_HPP_INCLUDED 22 | #define POORMAN_OSTREAM_HPP_INCLUDED 23 | 24 | #include 25 | 26 | namespace poorman { 27 | 28 | template 29 | class ostream 30 | { 31 | static char nibble(unsigned val) { 32 | val &= 0xf; 33 | return val < 10 ? '0' + val : 'a' + val - 10; 34 | } 35 | 36 | public: 37 | using char_type = Tp; 38 | 39 | virtual ostream & put(char_type c) = 0; 40 | virtual ostream & puts(const char_type* s) = 0; 41 | virtual ostream & write(const char_type* s, unsigned int count) = 0; 42 | virtual ostream & flush() = 0; 43 | virtual ostream & endl() = 0; 44 | // virtual ostream & widen(char_type c) { }; // TODO: implement in terminal_ostream 45 | 46 | /** hexadecimal output of any integral type */ 47 | template 48 | typename std::enable_if::value, ostream &>::type 49 | friend operator <<(ostream & st, valT val) 50 | { 51 | for(int i = sizeof(valT) * 8 - 4; i >= 0; i -= 4) { 52 | st.put(nibble(val >> i)); 53 | } 54 | return st; 55 | } 56 | 57 | friend ostream & operator<<(ostream & st, const char * s) { 58 | st.puts(s); 59 | return st; 60 | } 61 | 62 | ostream& operator<<(ostream& (*func)(ostream&)) { 63 | return func(*this); 64 | } 65 | }; 66 | 67 | /** manipulator, flushes the output stream */ 68 | template 69 | inline ostream & flush(ostream & st) { 70 | return st.flush(); 71 | } 72 | 73 | /** manipulator, outputs newline and flushes the output stream */ 74 | template 75 | inline ostream & endl(ostream & st) { 76 | return st.endl(); 77 | } 78 | 79 | } // namespace poorman 80 | 81 | #endif // POORMAN_OSTREAM_HPP_INCLUDED 82 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/.gitignore: -------------------------------------------------------------------------------- 1 | /obj/ 2 | /*.elf 3 | /*.map 4 | /stm32f103stk-demo 5 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/resources/README.md: -------------------------------------------------------------------------------- 1 | List of resources: 2 | ================== 3 | 4 | === filewiki-0.2.0 5 | 6 | Copy of [tinyfsm] v0.2.0 package (include and license information). 7 | 8 | === filewiki-git 9 | 10 | Git subvolume for [tinyfsm] master branch. Update using: 11 | 12 | git submodule init 13 | git submodule update 14 | 15 | 16 | [tinyfsm]: https://digint.ch/tinyfsm/ 17 | [tinyfsm-git]: https://dev.tty0.ch/tinyfsm.git 18 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/resources/tinyfsm-0.2.0/COPYING: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2012-2017 Axel Burri 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/resources/tinyfsm-0.2.0/README.md: -------------------------------------------------------------------------------- 1 | TinyFSM 2 | ======= 3 | 4 | TinyFSM is a simple finite state machine library for C++, designed for 5 | optimal performance and low memory footprint. This makes it ideal for 6 | real-time operating systems. The concept is very simple, allowing the 7 | programmer to fully understand what is happening behind the scenes. It 8 | provides a straightforward way of mapping your state machine charts 9 | into source code. 10 | 11 | TinyFSM basically wraps event dispatching into method calls, making 12 | event dispatching equally fast to calling (or even inlining) a 13 | function. Even in the worst case, dispatching leads to nothing more 14 | than a single vtable lookup and function call! 15 | 16 | Key Features: 17 | 18 | - Entry/exit actions 19 | - Event actions 20 | - Transition functions 21 | - Transition conditions 22 | - Event payload (classes) 23 | - Inheritance of states and action functions 24 | 25 | TinyFSM benefits from the C++11 template metaprogramming features like 26 | variadic templates, and does not depend on RTTI, exceptions or any 27 | external library. 28 | 29 | 30 | Official home page: 31 | 32 | Current version: `0.2.0` 33 | 34 | 35 | Documentation 36 | ------------- 37 | 38 | You can find the main documentation in the `doc/` directory of the 39 | TinyFSM project. The latest version is also available 40 | [online](http://digint.ch/tinyfsm/doc/introduction.html). 41 | 42 | 43 | Installation 44 | ------------ 45 | 46 | TinyFSM is a header-only library, no special installation steps are 47 | needed. Just point your compiler to the "include" directory. 48 | 49 | 50 | Donate 51 | ------ 52 | 53 | So TinyFSM has proven useful for you? 54 | 55 | I will definitively continue developing TinyFSM for free, but if you 56 | want to support me you can do so: 57 | 58 | [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QZQE9HY6QHDHS) 59 | 60 | 61 | Development 62 | ----------- 63 | 64 | The source code for TinyFSM is managed using Git. Check out the 65 | source repository like this: 66 | 67 | git clone git://dev.tty0.ch/tinyfsm.git 68 | 69 | If you would like to contribute or have found bugs, visit the [TinyFSM 70 | project page on GitHub] and use the [issues tracker] there. 71 | 72 | [TinyFSM project page on GitHub]: http://github.com/digint/tinyfsm 73 | [issues tracker]: http://github.com/digint/tinyfsm/issues 74 | 75 | 76 | Contact 77 | ------- 78 | 79 | For questions and suggestions regarding TinyFSM, success or failure 80 | stories, and any other kind of feedback, please feel free to contact 81 | the author (the email address can be found in the sources). 82 | 83 | 84 | License 85 | ------- 86 | 87 | TinyFSM is [Open Source] software. It may be used for any purpose, 88 | including commercial purposes, at absolutely no cost. It is 89 | distributed under the terms of the [MIT license]. 90 | 91 | [Open Source]: http://www.opensource.org/docs/definition.html 92 | [MIT license]: http://www.opensource.org/licenses/mit-license.html 93 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/debug.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef DEBUG_HPP_INCLUDED 22 | #define DEBUG_HPP_INCLUDED 23 | 24 | 25 | #ifdef DEBUG 26 | #include 27 | #define DBG(str) do { std::cout << str << std::endl; } while( false ) 28 | #else 29 | #define DBG(str) do { } while ( false ) 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/events.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef EVENTS_HPP_INCLUDED 22 | #define EVENTS_HPP_INCLUDED 23 | 24 | #include 25 | 26 | struct EvJoystickButton : public tinyfsm::Event { }; 27 | struct EvJoystickUp : public tinyfsm::Event { }; 28 | struct EvJoystickDown : public tinyfsm::Event { }; 29 | struct EvJoystickLeft : public tinyfsm::Event { }; 30 | struct EvJoystickRight : public tinyfsm::Event { }; 31 | struct EvJoystickCenter : public tinyfsm::Event { }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/fsmlist.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef FSMLIST_HPP_INCLUDED 22 | #define FSMLIST_HPP_INCLUDED 23 | 24 | #include 25 | #include "kernel.hpp" 26 | #include "screen.hpp" 27 | 28 | 29 | using fsm_list = tinyfsm::FsmList; 30 | 31 | 32 | /* wrapper to fsm_list::dispatch() */ 33 | template 34 | inline void send_event(E const & event) 35 | { 36 | fsm_list::template dispatch(event); 37 | } 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/heap_eater.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include "terminal_hooks.hpp" 22 | 23 | #ifndef OPENMPTL_SIMULATION 24 | 25 | #include // memset 26 | 27 | extern char *heap_ptr; 28 | #ifdef HEAP_FIXED_SIZE 29 | extern char *heap_end; 30 | #else 31 | register char *heap_end asm ("sp"); /* heap_end is current stack pointer */ 32 | #endif 33 | 34 | template 35 | struct adams_buf { 36 | char buf[size]; 37 | adams_buf() { std::memset(buf, 42, sizeof(buf)); } 38 | }; 39 | 40 | using buf = adams_buf<1024>; 41 | 42 | buf *buf_p; 43 | 44 | void terminal_hooks::heap_eater::run(poorman::ostream & cout) { 45 | cout << "new buf(): size=" << sizeof(buf) << poorman::endl; 46 | cout << "heap_ptr: old=" << (unsigned)heap_ptr << " end=" << (unsigned)heap_end << poorman::endl; 47 | buf_p = new buf(); 48 | cout << "heap_ptr: new=" << (unsigned)heap_ptr << " end=" << (unsigned)heap_end << poorman::endl; 49 | } 50 | 51 | #else ///// OPENMPTL_SIMULATION ///// 52 | 53 | void terminal_hooks::heap_eater::run(poorman::ostream & cout) { 54 | cout << "OpenMPTL simulation: HeapEater dummy" << poorman::endl; 55 | } 56 | 57 | #endif // OPENMPTL_SIMULATION 58 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/kernel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef KERNEL_HPP_INCLUDED 22 | #define KERNEL_HPP_INCLUDED 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "time.hpp" 37 | 38 | struct Kernel 39 | { 40 | using sysclk = mptl::system_clock_hse< mptl::mhz(72) >; 41 | 42 | using flash_cfg = mptl::reglist< 43 | mptl::flash::latency::minimum< sysclk >, 44 | mptl::flash::prefetch_buffer_enable 45 | >; 46 | 47 | using systick = mptl::systick< 48 | mptl::systick_clock::external< sysclk, mptl::hz(100) > 49 | >; 50 | 51 | using usart = mptl::usart< 2, sysclk, mptl::gpio< 'A', 3 >, mptl::gpio< 'A', 2 > >; 52 | using usart_cfg = mptl::reglist< 53 | usart::baud_rate< 115200 >, 54 | usart::enable_rx, 55 | usart::enable_tx 56 | >; 57 | 58 | using usart_stream_device = mptl::usart_irq_stream< usart, mptl::ring_buffer, true, true >; /* irq debug enabled */ 59 | using terminal_type = mptl::terminal< usart_stream_device >; 60 | 61 | using spi = mptl::spi< 1, sysclk, mptl::gpio< 'A', 5 >, mptl::gpio< 'A', 6 >, mptl::gpio< 'A', 7 > >; 62 | 63 | using lcd = mptl::device::nokia3310< 64 | spi, 65 | mptl::gpio_output< 'B', 2 >, /* lcd_ds */ 66 | mptl::gpio_output< 'C', 7 >, /* lcd_reset */ 67 | mptl::gpio_output< 'C', 10 > /* lcd_e */ 68 | >; 69 | 70 | using nrf = mptl::device::nrf24l01< 71 | spi, 72 | mptl::gpio_output< 'C', 8 >, /* nrf_ce */ 73 | mptl::gpio_output< 'A', 4 >, /* nrf_csn */ 74 | mptl::gpio_input < 'C', 9 > /* nrf_irq */ 75 | >; 76 | 77 | using joy = mptl::device::joystick; 78 | 79 | using led = mptl::gpio_led< 'C', 12, mptl::gpio_active_state::low >; 80 | 81 | using rtc = mptl::rtc< mptl::hz(0x8000) >; /* 32.768 kHz LSE clock */ 82 | using time = Time< systick, rtc >; 83 | 84 | static terminal_type terminal; 85 | 86 | /* Reset core exception: triggered on system startup (system entry point). */ 87 | static void __naked reset_isr(void); 88 | 89 | static void null_isr(void) { } 90 | static void warn_isr(void) { Kernel::led::on(); } 91 | static void error_isr(void) { while(1) { Kernel::led::on(); } } 92 | 93 | static void init(void); 94 | static void __noreturn run(void); 95 | 96 | using early_cfg = mptl::reglist< 97 | flash_cfg 98 | >; 99 | 100 | using resources = mptl::typelist< 101 | mptl::irq_handler< typename mptl::irq::reset, reset_isr >, 102 | 103 | time::resources, 104 | joy::resources, 105 | led::resources, 106 | spi::resources, 107 | lcd::resources, 108 | nrf::resources, 109 | 110 | usart::resources, 111 | usart_cfg, 112 | terminal_type::resources 113 | >; 114 | }; 115 | 116 | #endif // KERNEL_HPP_INCLUDED 117 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/nrftest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include "kernel.hpp" 22 | #include "terminal_hooks.hpp" 23 | 24 | namespace terminal_hooks { 25 | 26 | void nrf_test::run(poorman::ostream & cout) { 27 | unsigned char c; 28 | 29 | using namespace poorman; 30 | using nrf = Kernel::nrf; 31 | 32 | nrf::enable(); 33 | 34 | c = nrf::read_register(nrf::dev_register::status); 35 | cout << "status=0x" << c << endl; 36 | 37 | nrf::write_register(nrf::dev_register::config, 0x0B); 38 | c = nrf::read_register(nrf::dev_register::config); 39 | cout << "c=0x" << c << endl; 40 | 41 | nrf::dev_address addr(5, 6, 7, 8, 9); 42 | nrf::write_address_register(nrf::dev_register::rx_addr_p0, addr); 43 | 44 | nrf::dev_address r_addr; 45 | nrf::read_address_register(nrf::dev_register::rx_addr_p0, r_addr); 46 | cout << "rx_addr_p0=0x" << r_addr.buf[0] << r_addr.buf[1] << r_addr.buf[2] << r_addr.buf[3] << r_addr.buf[4] << endl; 47 | } 48 | 49 | } // namespace terminal_hooks 50 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/screen.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include "screen.hpp" 23 | 24 | // ---------------------------------------------------------------------------- 25 | // States 26 | // 27 | 28 | class Main 29 | : public Screen 30 | { 31 | virtual void react(EvJoystickUp const &) { 32 | if(item_top == item_list->begin()) 33 | item_top = item_list->end(); 34 | item_top--; 35 | } 36 | 37 | virtual void react(EvJoystickDown const &) { 38 | item_top++; 39 | if(item_top == item_list->end()) 40 | item_top = item_list->begin(); 41 | } 42 | }; 43 | 44 | 45 | // ---------------------------------------------------------------------------- 46 | // Base State: default implementations 47 | // 48 | 49 | void Screen::update(void) { 50 | ScreenItemList::iterator item(item_top); 51 | lcd.clear(); 52 | 53 | unsigned i = 0; 54 | while((item != item_list->end()) && (i < lcd.rows)) { 55 | #ifdef OPENMPTL_USE_BOOST 56 | lcd.print_line(i, item->c_str(), item->get_inverted()); 57 | #else 58 | lcd.print_line(i, (*item)->c_str(), (*item)->get_inverted()); 59 | #endif 60 | i++; 61 | item++; 62 | } 63 | 64 | lcd.update(); 65 | } 66 | 67 | void Screen::set_item_list(ScreenItemList & list) { 68 | item_list = &list; 69 | item_top = item_list->begin(); 70 | } 71 | 72 | Kernel::lcd Screen::lcd; 73 | 74 | ScreenItemList *Screen::item_list; 75 | ScreenItemList::iterator Screen::item_top; 76 | 77 | 78 | // ---------------------------------------------------------------------------- 79 | // Initial state definition 80 | // 81 | FSM_INITIAL_STATE(Screen, Main) 82 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/screen.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef FSM_SCREEN_HPP_INCLUDED 22 | #define FSM_SCREEN_HPP_INCLUDED 23 | 24 | #include 25 | #include "kernel.hpp" 26 | #include "events.hpp" 27 | #include "screen_item.hpp" 28 | 29 | 30 | // ---------------------------------------------------------------------------- 31 | // FSM base class declaration 32 | // 33 | 34 | class Screen 35 | : public tinyfsm::Fsm 36 | { 37 | friend class Fsm; 38 | 39 | void react(tinyfsm::Event const &) { }; /* default reaction (unhandled events) */ 40 | 41 | virtual void react(EvJoystickUp const &); 42 | virtual void react(EvJoystickDown const &); 43 | 44 | void entry(void) { }; 45 | void exit(void) { }; 46 | 47 | protected: 48 | 49 | static Kernel::lcd lcd; 50 | 51 | static ScreenItemList::iterator item_top; 52 | static ScreenItemList *item_list; 53 | 54 | public: 55 | 56 | static void set_item_list(ScreenItemList & list); 57 | static void update(void); 58 | }; 59 | 60 | #endif // FSM_SCREEN_HPP_INCLUDED 61 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/screen_item.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include "screen_item.hpp" 22 | 23 | void DataRow::init_buf(const char * name) { 24 | unsigned i = 0; 25 | 26 | while(*name) 27 | buf[i++] = *name++; 28 | while(i < name_width) 29 | buf[i++] = ' '; 30 | buf[i++] = ':'; 31 | buf[i++] = ' '; 32 | 33 | print_value(); 34 | } 35 | 36 | DataRow::DataRow(const char * name, uint32_t _value, NumberBase _numbase, bool _inverted) 37 | : ScreenItem(_inverted), value(_value), numbase(_numbase) 38 | { 39 | init_buf(name); 40 | } 41 | 42 | DataRow::DataRow(ScreenItemList & item_list, const char * name, uint32_t _value, NumberBase _numbase, bool _inverted) 43 | : ScreenItem(item_list, _inverted), value(_value), numbase(_numbase) 44 | { 45 | init_buf(name); 46 | } 47 | 48 | void DataRow::print_value(void) { 49 | if(numbase == NumberBase::decimal) 50 | poorman::itoa(&buf[name_width + colon_width], value, value_width, padding_dec); 51 | else 52 | poorman::itoa_hex(&buf[name_width + colon_width], value, value_width, padding_hex); 53 | } 54 | 55 | void DataRow::set(uint32_t _value) { 56 | if(value != _value) { 57 | value = _value; 58 | print_value(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/screen_item.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef SCREENITEM_HPP_INCLUDED 22 | #define SCREENITEM_HPP_INCLUDED 23 | 24 | #include 25 | #include 26 | 27 | class ScreenItem; 28 | 29 | #ifdef OPENMPTL_USE_BOOST 30 | # include 31 | using ScreenItemList = boost::intrusive::list< 32 | ScreenItem, 33 | boost::intrusive::link_mode 34 | >; 35 | #else 36 | # include 37 | using ScreenItemList = std::list; 38 | #endif // OPENMPTL_USE_BOOST 39 | 40 | 41 | 42 | class ScreenItem 43 | #ifdef OPENMPTL_USE_BOOST 44 | : public boost::intrusive::list_base_hook<> /* doubly linked list */ 45 | #endif 46 | { 47 | bool inverted = false; 48 | 49 | public: 50 | #ifdef OPENMPTL_USE_BOOST 51 | boost::intrusive::list_member_hook<> member_hook_; 52 | #endif 53 | 54 | ScreenItem(bool _inverted = false) : inverted(_inverted) { } 55 | ScreenItem(ScreenItemList & item_list, bool _inverted = false) : ScreenItem(_inverted) { 56 | #ifdef OPENMPTL_USE_BOOST 57 | item_list.push_back(*this); 58 | #else 59 | item_list.push_back(this); 60 | #endif 61 | } 62 | 63 | void set_inverted(bool inv = true) { inverted = inv; } 64 | bool get_inverted(void) const { return inverted; } 65 | 66 | virtual const char * c_str(void) const { return "base"; } 67 | }; 68 | 69 | class TextRow 70 | : public ScreenItem 71 | { 72 | const char * text; 73 | 74 | public: 75 | TextRow(const char * _text, bool _inverted = false) 76 | : ScreenItem(_inverted), text(_text) 77 | { } 78 | 79 | TextRow(ScreenItemList & item_list, const char * _text, bool _inverted = false) 80 | : ScreenItem(item_list, _inverted), text(_text) 81 | { } 82 | 83 | virtual const char * c_str(void) const { 84 | return text; 85 | } 86 | }; 87 | 88 | 89 | enum class NumberBase { hex, decimal }; 90 | 91 | class DataRow 92 | : public ScreenItem 93 | { 94 | protected: 95 | static constexpr unsigned name_width = 4; 96 | static constexpr unsigned colon_width = 2; 97 | static constexpr unsigned value_width = 8; 98 | 99 | static constexpr char padding_dec = '0'; 100 | static constexpr char padding_hex = '0'; 101 | 102 | uint32_t value; 103 | char buf[name_width + colon_width + value_width + 1]; 104 | 105 | NumberBase numbase; 106 | 107 | void init_buf(const char * name); 108 | void print_value(void); 109 | 110 | public: 111 | DataRow(const char * name, uint32_t _value = 0, NumberBase _numbase = NumberBase::decimal, bool _inverted = false); 112 | DataRow(ScreenItemList & item_list, const char * name, uint32_t _value = 0, NumberBase _numbase = NumberBase::decimal, bool _inverted = false); 113 | 114 | virtual const char * c_str(void) const final { return buf; }; 115 | 116 | void set(uint32_t _value); 117 | void operator=(uint32_t _value) { set(_value); } 118 | }; 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/sim_reactions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifdef OPENMPTL_SIMULATION 22 | 23 | #include 24 | #include 25 | #include 26 | #include "kernel.hpp" 27 | 28 | void mptl::sim::reg_reaction::react() 29 | { 30 | /* RCC: simulate the system clock setup */ 31 | if(bits_set< RCC::CR::HSEON >()) { 32 | info("reacting to RCC::CR::HSEON, by setting RCC::CR::HSERDY"); 33 | RCC::CR::HSERDY::set(); 34 | } 35 | if(bits_set< RCC::CR::PLLON >()) { 36 | info("reacting to RCC::CR::PLLON, by setting RCC::CR::PLLRDY"); 37 | RCC::CR::PLLRDY::set(); 38 | } 39 | if(bits_set< RCC::CFGR::SW::PLL >()) { 40 | info("reacting to RCC::CFGR::SW::PLL, by setting RCC::CFGR::SWS::PLL"); 41 | RCC::CFGR::SWS::PLL::set(); 42 | } 43 | 44 | /* RTC: simulate synchronisation */ 45 | if(bits_set< RCC::BDCR::RTCEN >()) { 46 | RCC::BDCR::LSERDY::set(); 47 | RTC::CRL::RSF::set(); 48 | } 49 | if(bits_cleared< RTC::CRL::RSF >()) 50 | RTC::CRL::RSF::set(); 51 | 52 | 53 | /* ADC: set "end of conversion" on SWSTART */ 54 | if(bits_set< ADC<1>::CR2::SWSTART >()) 55 | ADC<1>::SR::EOC::set(); 56 | 57 | /* SPI: always ready to send / receive */ 58 | if(bits_set< Kernel::spi::SPIx::CR1::SPE >()) { // spi enable 59 | Kernel::spi::SPIx::SR::TXE::set(); 60 | Kernel::spi::SPIx::SR::RXNE::set(); 61 | } 62 | 63 | /* provide a terminal on stdin/stdout */ 64 | stdio_terminal< Kernel::terminal_type >(*this).react< 65 | Kernel::usart::USARTx::CR1::RXNEIE, /* start/stop terminal rx thread on RXNEIE */ 66 | Kernel::usart::USARTx::CR1::TXEIE /* start/stop terminal tx thread on TXEIE */ 67 | >(); 68 | } 69 | 70 | #endif // OPENMPTL_SIMULATION 71 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/startup.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include "kernel.hpp" 25 | 26 | extern const uint32_t _stack_top; /* provided by linker script */ 27 | 28 | /* Reset exception: triggered on system startup (system entry point). */ 29 | void Kernel::reset_isr(void) { 30 | mptl::core::startup< sysclk, early_cfg >(); 31 | 32 | Kernel::init(); 33 | Kernel::run(); 34 | } 35 | 36 | /* Build the vector table: 37 | * - use irq handler from irq_handler<> traits in Kernel::resources 38 | * - use Kernel::error_isr as default isr 39 | */ 40 | using vector_table = mptl::vector_table<&_stack_top, Kernel::resources, Kernel::error_isr>; 41 | const auto isr_vector __used __attribute__((section(".isr_vector"))) = vector_table::value; 42 | 43 | 44 | #ifdef OPENMPTL_SIMULATION 45 | 46 | const uint32_t _stack_top = 0; 47 | 48 | //int main(int argc, char *argv[]) 49 | int main(void) 50 | { 51 | #ifdef DUMP_VECTOR_TABLE 52 | vector_table::dump_size(); 53 | vector_table::dump_types(); 54 | // vector_table::dump_vector(); 55 | #endif 56 | 57 | std::cout << "*** stm32f103stk demo: starting simulation..." << std::endl; 58 | Kernel::reset_isr(); 59 | } 60 | 61 | #endif // OPENMPTL_SIMULATION 62 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/syscalls.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef OPENMPTL_SIMULATION 22 | 23 | #include "kernel.hpp" 24 | #include "screen.hpp" 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | /* define a fixed heap size for tesing purposes */ 31 | //#define HEAP_FIXED_SIZE (1024 * 8) 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | #ifdef HEAP_FIXED_SIZE 38 | char heap[HEAP_FIXED_SIZE]; 39 | char *heap_ptr = heap; 40 | char *heap_end = heap + HEAP_FIXED_SIZE; 41 | #else 42 | /* NOTE: This assumes that the stack is growing down towards the heap */ 43 | extern char end[]; 44 | char *heap_ptr = end; 45 | register char *heap_end asm ("sp"); /* heap_end is current stack pointer */ 46 | #endif 47 | 48 | caddr_t _sbrk(ptrdiff_t incr) 49 | { 50 | char *chunk_start = heap_ptr; 51 | 52 | if(heap_ptr + incr > heap_end) 53 | { 54 | errno = ENOMEM; 55 | return (caddr_t) -1; 56 | } 57 | heap_ptr += incr; 58 | return (caddr_t)chunk_start; 59 | } 60 | 61 | int _kill(int pid, int sig) 62 | { 63 | (void)pid; (void)sig; 64 | errno = ENOTSUP; 65 | return -1; 66 | } 67 | 68 | void _exit(int status) 69 | { 70 | _kill(status, -1); 71 | 72 | Kernel::led::on(); 73 | 74 | /* Try to print out-of-memory message to LCD */ 75 | Kernel::lcd lcd; 76 | 77 | lcd.enable(); 78 | lcd.clear(); 79 | lcd.print_line(0, "oops..."); 80 | lcd.print_line_inv(1, "out of memory!"); 81 | lcd.print_line(2, DataRow("stat", status , NumberBase::hex).c_str()); 82 | lcd.print_line(3, DataRow("err#", errno , NumberBase::hex).c_str()); 83 | lcd.print_line(4, DataRow("heap", (uint32_t)heap_ptr, NumberBase::hex).c_str()); 84 | lcd.print_line(5, DataRow("hend", (uint32_t)heap_end, NumberBase::hex).c_str()); 85 | lcd.update(); 86 | 87 | while(1); 88 | } 89 | 90 | int _getpid(int n) 91 | { 92 | (void)n; 93 | return 1; 94 | } 95 | 96 | #ifdef __cplusplus 97 | } 98 | #endif 99 | 100 | #endif // OPENMPTL_SIMULATION 101 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/terminal_hooks.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef TERMINAL_HOOKS_HPP_INCLUDED 22 | #define TERMINAL_HOOKS_HPP_INCLUDED 23 | 24 | #include 25 | #include 26 | 27 | namespace terminal_hooks { 28 | 29 | struct cpuid 30 | : public mptl::terminal_hook 31 | { 32 | static constexpr const char * cmd = "cpuid"; 33 | static constexpr const char * desc = "prints SCB::CPUID register hexadecimal value"; 34 | void run(poorman::ostream & cout) { 35 | cout << mptl::SCB::CPUID::load() << poorman::endl; 36 | } 37 | }; 38 | 39 | struct heap_eater 40 | : public mptl::terminal_hook 41 | { 42 | static constexpr const char * cmd = "heap"; 43 | static constexpr const char * desc = "allocate (leak) 1k on heap"; 44 | void run(poorman::ostream &); 45 | }; 46 | 47 | struct nrf_test 48 | : public mptl::terminal_hook 49 | { 50 | static constexpr const char * cmd = "nrf"; 51 | static constexpr const char * desc = "test the NRF24L01 chip (spi)"; 52 | void run(poorman::ostream &); 53 | }; 54 | 55 | 56 | // ---------------------------------------------------------------------------- 57 | // Terminal Commands 58 | // 59 | 60 | using commands = mptl::terminal_hook_list< 61 | cpuid, 62 | heap_eater, 63 | nrf_test 64 | >; 65 | 66 | } // namespace terminal_hooks 67 | 68 | #endif // TERMINAL_HOOKS_HPP_INCLUDED 69 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/time.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include "timepoint.hpp" 22 | #include "time.hpp" 23 | #include "kernel.hpp" 24 | 25 | std::atomic SystemTime::systick_count; 26 | 27 | void SystemTime::systick_isr(void) { 28 | systick_count.fetch_add(1, std::memory_order_relaxed); 29 | } 30 | 31 | void SystemTime::rtc_isr() { 32 | Kernel::rtc::clear_second_flag(); 33 | Kernel::led::toggle(); 34 | } 35 | 36 | void SystemTime::nanosleep(unsigned int ns) { 37 | TimePoint end; 38 | end.set(); 39 | end.add_ns(ns); 40 | TimePoint now; 41 | now.set(); 42 | while(now < end) 43 | now.set(); 44 | } 45 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/time.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef TIME_HPP_INCLUDED 22 | #define TIME_HPP_INCLUDED 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | typedef unsigned int systick_t; 31 | 32 | class SystemTime 33 | { 34 | protected: 35 | static std::atomic systick_count; 36 | 37 | static void systick_isr(void); 38 | static void rtc_isr(void); 39 | 40 | public: 41 | // static constexpr long long nop_s = 11999940; // nop's per second when using Core::nop(n) (-Os, 72Mhz) 42 | static void nanosleep(unsigned int ns); 43 | 44 | }; 45 | 46 | 47 | template< typename _systick, typename _rtc > 48 | class Time : public SystemTime 49 | { 50 | 51 | public: 52 | using rtc = _rtc; 53 | using systick = _systick; 54 | 55 | static constexpr mptl::freq_t rtc_freq = mptl::hz(1); /* 1sec signal period */ 56 | 57 | using resources = mptl::typelist< 58 | mptl::irq_handler< typename systick::irq, systick_isr >, 59 | mptl::irq_handler< typename rtc::irq_global, rtc_isr >, 60 | typename systick::resources, 61 | typename rtc::resources 62 | >; 63 | 64 | static void init(void) { 65 | systick::enable(); 66 | rtc::template init< rtc_freq >(); 67 | rtc::set_counter(0); 68 | } 69 | 70 | static void enable(void) { 71 | systick::enable_interrupt(); 72 | rtc::enable_second_interrupt(); 73 | rtc::irq_global::enable(); 74 | } 75 | 76 | static unsigned int get_rtc_seconds(void) { 77 | return rtc::get_counter(); 78 | } 79 | 80 | static systick_t get_systick() { 81 | return systick_count.load(std::memory_order_relaxed); 82 | } 83 | }; 84 | 85 | #endif // TIME_HPP_INCLUDED 86 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/src/timepoint.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef TIMEPOINT_HPP_INCLUDED 22 | #define TIMEPOINT_HPP_INCLUDED 23 | 24 | #include "time.hpp" 25 | #include "kernel.hpp" 26 | 27 | class TimePoint 28 | { 29 | using time = Kernel::time; 30 | protected: 31 | 32 | using counter_type = decltype(time::systick::get_counter()); 33 | 34 | systick_t systick; 35 | counter_type counter; // note: counter decreases in time 36 | 37 | public: 38 | 39 | static constexpr auto counter_base = time::systick::reload_value; 40 | static constexpr auto ps_per_tick = time::systick::ps_per_tick; 41 | 42 | void set() volatile { 43 | systick = time::get_systick(); 44 | counter = time::systick::get_counter(); 45 | } 46 | 47 | systick_t get_systick() const { return systick; } 48 | counter_type get_counter() const { return counter; } 49 | 50 | /** add nanoseconds */ 51 | void add_ns(unsigned int ns) { 52 | counter_type counter_ticks = (ns * 1000) / time::systick::ps_per_tick + 1; // always rounded up 53 | systick += counter_ticks / counter_base; 54 | counter_type wait_frac = counter_ticks % counter_base; 55 | if(wait_frac > counter) { 56 | systick++; 57 | counter += counter_base; 58 | } 59 | counter -= wait_frac; 60 | } 61 | 62 | unsigned int get_ns(void) { 63 | unsigned int t = systick * counter_base - counter + counter_base; 64 | t = t * 1000 / Kernel::systick::ps_per_tick; 65 | return t; 66 | }; 67 | 68 | bool operator<(TimePoint & tp) const { 69 | if(systick < tp.systick) 70 | return true; 71 | if(systick > tp.systick) 72 | return false; 73 | if(counter > tp.counter) 74 | return true; 75 | return false; 76 | } 77 | }; 78 | 79 | class TimePointDiff 80 | : public TimePoint 81 | { 82 | public: 83 | /** creates a TimePoint from tp1 - tp2. 84 | * if tp2 > tp1, the result is undefined. 85 | */ 86 | TimePointDiff(const TimePoint & tp1, const TimePoint & tp2) { 87 | systick = tp1.get_systick() - tp2.get_systick(); 88 | counter = 0; 89 | counter_type c1 = counter_base - tp1.get_counter(); 90 | counter_type c2 = counter_base - tp2.get_counter(); 91 | if(c1 > c2) { 92 | counter = counter_base - (c1 - c2); 93 | } 94 | else { 95 | // counter = counter_base - (c2 - c1); 96 | counter = (c2 - c1); 97 | systick--; 98 | } 99 | } 100 | }; 101 | 102 | class TimeMeasurement 103 | { 104 | public: 105 | 106 | TimePoint tp_start; 107 | TimePoint tp_end; 108 | 109 | void start() volatile { tp_start.set(); } 110 | void stop() volatile { tp_end.set(); } 111 | 112 | /** diff time in nanoseconds */ 113 | unsigned int diff(void) { 114 | TimePointDiff tp(tp_end, tp_start); 115 | return tp.get_ns(); 116 | } 117 | }; 118 | 119 | #endif // TIMEPOINT_HPP_INCLUDED 120 | -------------------------------------------------------------------------------- /projects/stm32f103stk-demo/stm32f10x_flash_md.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") 2 | OUTPUT_ARCH(arm) 3 | 4 | MEMORY 5 | { 6 | RAM(xrw) : ORIGIN = 0x20000000, LENGTH = 20K 7 | FLASH(rx) : ORIGIN = 0x08000000, LENGTH = 128K 8 | } 9 | 10 | PROVIDE(_sram = ORIGIN(RAM)); 11 | PROVIDE(_eram = ORIGIN(RAM) + LENGTH(RAM)); 12 | 13 | PROVIDE(_stack_top = _eram); 14 | 15 | SECTIONS 16 | { 17 | .isr_vector : 18 | { 19 | . = ALIGN(4); 20 | KEEP(*(.isr_vector)) 21 | } > FLASH 22 | 23 | .text : { 24 | . = ALIGN(4); 25 | __preinit_array_start = .; 26 | KEEP(*(.preinit_array)) 27 | __preinit_array_end = .; 28 | 29 | __init_array_start = .; 30 | KEEP(*(.init_array)) 31 | __init_array_end = .; 32 | 33 | __fini_array_start = .; 34 | KEEP(*(.fini_array)) 35 | __fini_array_end = .; 36 | 37 | *(.text) 38 | *(.text.*) 39 | *(.rodata) 40 | *(.rodata*) 41 | 42 | *(.eh_frame_hdr) /* call frame information (exception handling) */ 43 | *(.eh_frame) /* call frame information (exception handling) */ 44 | *(.gcc_except_table) 45 | 46 | *(.glue_7) /* ARM code calling Thumb code */ 47 | *(.glue_7t) /* Thumb code calling ARM code */ 48 | . = ALIGN(4); 49 | } > FLASH 50 | 51 | 52 | /* exception handling/unwind - some Newlib functions (in common with C++ and STDC++) use this. */ 53 | .ARM.extab : 54 | { 55 | *(.ARM.extab* .gnu.linkonce.armextab.*) 56 | } > FLASH 57 | __exidx_start = .; 58 | .ARM.exidx : 59 | { 60 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 61 | } > FLASH 62 | __exidx_end = .; 63 | 64 | _etext = .; 65 | 66 | .data : AT(_etext) 67 | { 68 | _data_lma = LOADADDR(.data); /* load memory address */ 69 | . = ALIGN(4); 70 | _sdata = .; 71 | /* KEEP( *(.data) ) 72 | KEEP( *(.data.*) ) */ 73 | *(.data) 74 | *(.data.*) 75 | . = ALIGN(4); 76 | _edata = .; 77 | } > RAM 78 | 79 | .bss : 80 | { 81 | . = ALIGN(4); 82 | _sbss = .; 83 | *(.bss) 84 | *(.bss.*) 85 | *(COMMON) 86 | . = ALIGN(4); 87 | _ebss = .; 88 | _end = .; 89 | PROVIDE(end = .); 90 | } > RAM 91 | 92 | 93 | /* 94 | PROVIDE(_sheap = _ebss); 95 | PROVIDE(_eheap = ALIGN(ORIGIN(RAM) + LENGTH(RAM) - 8 ,8) ); 96 | */ 97 | 98 | /* Remove information from the standard libraries */ 99 | /DISCARD/ : 100 | { 101 | libc.a ( * ) 102 | libm.a ( * ) 103 | libgcc.a ( * ) 104 | } 105 | 106 | /* Stabs debugging sections. */ 107 | .stab 0 : { *(.stab) } 108 | .stabstr 0 : { *(.stabstr) } 109 | .stab.excl 0 : { *(.stab.excl) } 110 | .stab.exclstr 0 : { *(.stab.exclstr) } 111 | .stab.index 0 : { *(.stab.index) } 112 | .stab.indexstr 0 : { *(.stab.indexstr) } 113 | .comment 0 : { *(.comment) } 114 | /* DWARF debug sections. 115 | Symbols in the DWARF debugging sections are relative to the beginning 116 | of the section so we begin them at 0. */ 117 | /* DWARF 1 */ 118 | .debug 0 : { *(.debug) } 119 | .line 0 : { *(.line) } 120 | /* GNU DWARF 1 extensions */ 121 | .debug_srcinfo 0 : { *(.debug_srcinfo) } 122 | .debug_sfnames 0 : { *(.debug_sfnames) } 123 | /* DWARF 1.1 and DWARF 2 */ 124 | .debug_aranges 0 : { *(.debug_aranges) } 125 | .debug_pubnames 0 : { *(.debug_pubnames) } 126 | /* DWARF 2 */ 127 | .debug_info 0 : { *(.debug_info) } 128 | .debug_abbrev 0 : { *(.debug_abbrev) } 129 | .debug_line 0 : { *(.debug_line) } 130 | .debug_frame 0 : { *(.debug_frame) } 131 | .debug_str 0 : { *(.debug_str) } 132 | .debug_loc 0 : { *(.debug_loc) } 133 | .debug_macinfo 0 : { *(.debug_macinfo) } 134 | .debug_ranges 0 : { *(.debug_ranges) } 135 | /* SGI/MIPS DWARF 2 extensions */ 136 | .debug_weaknames 0 : { *(.debug_weaknames) } 137 | .debug_funcnames 0 : { *(.debug_funcnames) } 138 | .debug_typenames 0 : { *(.debug_typenames) } 139 | .debug_varnames 0 : { *(.debug_varnames) } 140 | } 141 | -------------------------------------------------------------------------------- /projects/stm32f4discovery-ledtest/.gitignore: -------------------------------------------------------------------------------- 1 | /obj/ 2 | /*.elf 3 | /*.map 4 | /stm32f4discovery-ledtest 5 | -------------------------------------------------------------------------------- /projects/stm32f4discovery-ledtest/src/ledtest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | extern const uint32_t _stack_top; /* provided by linker script */ 32 | 33 | static constexpr char led_port = 'D'; 34 | static constexpr unsigned led_pin = 12; 35 | 36 | using sysclk = mptl::system_clock_hse< mptl::mhz(168) >; 37 | using pwr = mptl::pwr< mptl::volt(3.3) >; 38 | 39 | using early_cfg = mptl::flash::latency::minimum< sysclk, pwr >; 40 | 41 | #ifdef HIGH_LEVEL 42 | #include 43 | using led_green = mptl::gpio_led< led_port, led_pin >; 44 | #endif 45 | 46 | void __naked reset_isr(void); 47 | void null_isr(void) { } 48 | 49 | using resources = mptl::typelist< 50 | mptl::irq_handler< typename mptl::irq::reset, reset_isr > 51 | #ifdef HIGH_LEVEL 52 | , led_green::resources 53 | #endif 54 | >; 55 | 56 | 57 | /* Reset exception: triggered on system startup (system entry point). */ 58 | void __naked reset_isr(void) { 59 | mptl::core::startup< sysclk, early_cfg >(); 60 | 61 | /* set all register from our resources<> typelist */ 62 | mptl::make_reglist< resources >::reset_to(); 63 | 64 | #ifdef HIGH_LEVEL 65 | led_green::on(); 66 | #else 67 | static constexpr uint32_t pin_mask = (uint32_t)0x1 << led_pin; 68 | mptl::RCC::AHB1ENR::GPIODEN::set(); // enable AHB1 clock for GPIO D 69 | mptl::regval< mptl::GPIO< led_port >::MODERx< led_pin >, 1 >::set(); // configure GPIOD::MODERx (set GPIOD12 to output mode) 70 | mptl::GPIO< led_port >::BSRR::store(pin_mask); // enable led 71 | #endif 72 | 73 | while(1) { 74 | mptl::core::nop(); 75 | 76 | SIM_RELAX; // sleep a bit (don't eat up all cpu power) 77 | } 78 | } 79 | 80 | /* Build the vector table: 81 | * - use irq handler from irq_handler<> traits in "resources" 82 | * - use null_isr as default isr (useful for debugging) 83 | */ 84 | using vector_table = mptl::vector_table<&_stack_top, resources, null_isr>; 85 | const auto isr_vector __attribute__((used,section(".isr_vector"))) = vector_table::value; 86 | 87 | 88 | #ifdef OPENMPTL_SIMULATION 89 | 90 | const uint32_t _stack_top = 0; 91 | 92 | void mptl::sim::reg_reaction::react() { 93 | /* simulate the system clock setup */ 94 | if(bits_set< RCC::CR::HSEON >()) { 95 | info("reacting to RCC::CR::HSEON, by setting RCC::CR::HSERDY"); 96 | RCC::CR::HSERDY::set(); 97 | } 98 | if(bits_set< RCC::CR::PLLON >()) { 99 | info("reacting to RCC::CR::PLLON, by setting RCC::CR::PLLRDY"); 100 | RCC::CR::PLLRDY::set(); 101 | } 102 | if(bits_set< RCC::CFGR::SW::PLL >()) { 103 | info("reacting to RCC::CFGR::SW::PLL, by setting RCC::CFGR::SWS::PLL"); 104 | RCC::CFGR::SWS::PLL::set(); 105 | } 106 | } 107 | 108 | //int main(int argc, char *argv[]) 109 | int main(void) 110 | { 111 | #ifdef DUMP_VECTOR_TABLE 112 | vector_table::dump_size(); 113 | vector_table::dump_types(); 114 | // vector_table::dump_vector(); 115 | #endif 116 | 117 | std::cout << "*** stm32f4discovery ledtest: starting simulation..." << std::endl; 118 | reset_isr(); 119 | } 120 | 121 | #endif // OPENMPTL_SIMULATION 122 | -------------------------------------------------------------------------------- /projects/stm32f4discovery/.gitignore: -------------------------------------------------------------------------------- 1 | /obj/ 2 | /*.elf 3 | /*.map 4 | /stm32f4discovery-demo 5 | -------------------------------------------------------------------------------- /projects/stm32f4discovery/src/kernel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include "terminal_hooks.hpp" 25 | #include "kernel.hpp" 26 | 27 | Kernel::terminal_type Kernel::terminal; 28 | 29 | void Kernel::systick_isr() { 30 | static constexpr int toggle_interval = systick::freq / 2; /* 0.5 seconds interval */ 31 | static int systick_count = toggle_interval; 32 | 33 | systick_count--; 34 | if(systick_count == 0) { 35 | systick_count = toggle_interval; 36 | 37 | /* Demonstrate the impact of the active_state configuration (in 38 | * kernel.hpp, typedef led_blue): faking active_state::low for 39 | * Kernel::led_blue<> has the effect of green/blue leds toggling 40 | * alternately. 41 | */ 42 | led_green::toggle(); 43 | led_blue::toggle(); 44 | } 45 | } 46 | 47 | void Kernel::init(void) 48 | { 49 | /* set all register from Kernel::resources<> */ 50 | mptl::make_reglist< resources >::reset_to(); 51 | 52 | /* turn all leds off */ 53 | led_green ::off(); 54 | led_orange::off(); 55 | led_red ::off(); 56 | led_blue ::off(); 57 | 58 | #ifdef DYNAMIC_BAUD_RATE 59 | /* set the baud rate, since it is not set in usart<> peripheral 60 | * configuration (and thus was NOT set by 61 | * "mptl::make_reglist::reset_to()" above). 62 | */ 63 | usart::set_baudrate(115200); 64 | #endif 65 | 66 | /* finally start systick */ 67 | systick::enable(); 68 | systick::enable_interrupt(); 69 | } 70 | 71 | void Kernel::run(void) 72 | { 73 | /* open terminal and print welcome message */ 74 | terminal.open(); 75 | terminal.tx_stream << "\r\n\r\nWelcome to OpenMPTL terminal console!\r\n# " << poorman::flush; 76 | 77 | while(1) 78 | { 79 | /* poll terminal */ 80 | terminal.process_input< terminal_hooks::commands >(); 81 | 82 | SIM_RELAX; // sleep a bit (don't eat up all cpu power) 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /projects/stm32f4discovery/src/sim_reactions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifdef OPENMPTL_SIMULATION 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "kernel.hpp" 31 | 32 | std::atomic systick_thread_terminate; // TODO: make static (bug in clang-3.3 ?) 33 | 34 | /** run Kernel::systick_isr() in intervals defined by Kernel::systick::freq */ 35 | static void systick_thread() { 36 | using systick_interval = std::chrono::duration< int, std::ratio<1, Kernel::systick::freq> >; 37 | while(!systick_thread_terminate) 38 | { 39 | Kernel::systick_isr(); 40 | std::this_thread::sleep_for( systick_interval(1) ); 41 | } 42 | } 43 | 44 | void mptl::sim::reg_reaction::react() 45 | { 46 | /* simulate the system clock setup */ 47 | if(bits_set< RCC::CR::HSEON >()) { 48 | info("reacting to RCC::CR::HSEON, by setting RCC::CR::HSERDY"); 49 | RCC::CR::HSERDY::set(); 50 | } 51 | if(bits_set< RCC::CR::PLLON >()) { 52 | info("reacting to RCC::CR::PLLON, by setting RCC::CR::PLLRDY"); 53 | RCC::CR::PLLRDY::set(); 54 | } 55 | if(bits_set< RCC::CFGR::SW::PLL >()) { 56 | info("reacting to RCC::CFGR::SW::PLL, by setting RCC::CFGR::SWS::PLL"); 57 | RCC::CFGR::SWS::PLL::set(); 58 | } 59 | 60 | /* start/stop systick thread on SCB::STCSR::TICKINT */ 61 | if(bits_set< SCB::STCSR::TICKINT >()) { 62 | systick_thread_terminate = false; 63 | std::thread(systick_thread).detach(); 64 | } 65 | else if(bits_cleared< SCB::STCSR::TICKINT >()) { 66 | systick_thread_terminate = true; 67 | } 68 | 69 | /* provide a terminal on stdin/stdout */ 70 | stdio_terminal< Kernel::terminal_type >(*this).react< 71 | Kernel::usart::USARTx::CR1::RXNEIE, /* start/stop terminal rx thread on RXNEIE */ 72 | Kernel::usart::USARTx::CR1::TXEIE /* start/stop terminal tx thread on TXEIE */ 73 | >(); 74 | } 75 | 76 | #endif // OPENMPTL_SIMULATION 77 | -------------------------------------------------------------------------------- /projects/stm32f4discovery/src/startup.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include "kernel.hpp" 25 | 26 | extern const uint32_t _stack_top; /* provided by linker script */ 27 | 28 | /* Reset exception: triggered on system startup (system entry point). */ 29 | void Kernel::reset_isr(void) { 30 | mptl::core::startup< sysclk, early_cfg >(); 31 | 32 | Kernel::init(); 33 | Kernel::run(); 34 | } 35 | 36 | /* Build the vector table: 37 | * - use irq handler from irq_handler<> traits in Kernel::resources 38 | * - use Kernel::error_isr as default isr 39 | */ 40 | using vector_table = mptl::vector_table<&_stack_top, Kernel::resources, Kernel::error_isr>; 41 | const auto isr_vector __attribute__((used,section(".isr_vector"))) = vector_table::value; 42 | 43 | 44 | #ifdef OPENMPTL_SIMULATION 45 | 46 | const uint32_t _stack_top = 0; 47 | 48 | //int main(int argc, char *argv[]) 49 | int main(void) 50 | { 51 | #ifdef DUMP_VECTOR_TABLE 52 | vector_table::dump_size(); 53 | vector_table::dump_types(); 54 | // vector_table::dump_vector(); 55 | #endif 56 | 57 | std::cout << "*** stm32f4discovery demo: starting simulation..." << std::endl; 58 | Kernel::reset_isr(); 59 | } 60 | 61 | #endif // OPENMPTL_SIMULATION 62 | -------------------------------------------------------------------------------- /projects/stm32f4discovery/src/terminal_hooks.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #ifndef TERMINAL_HOOKS_HPP_INCLUDED 22 | #define TERMINAL_HOOKS_HPP_INCLUDED 23 | 24 | #include 25 | #include 26 | #include "kernel.hpp" 27 | 28 | namespace terminal_hooks 29 | { 30 | 31 | struct cpuid 32 | : public mptl::terminal_hook 33 | { 34 | static constexpr const char * cmd = "cpuid"; 35 | static constexpr const char * desc = "prints SCB::CPUID register hexadecimal value"; 36 | void run(poorman::ostream & cout) { 37 | cout << mptl::SCB::CPUID::load() << poorman::endl; 38 | } 39 | }; 40 | 41 | #ifdef DYNAMIC_BAUD_RATE 42 | struct baudrate 43 | : public mptl::terminal_hook 44 | { 45 | static constexpr const char * cmd = "baudrate"; 46 | static constexpr const char * desc = "set the terminal baudrate to 460.8 KBps"; 47 | void run(poorman::ostream &) { 48 | Kernel::terminal.close(); 49 | Kernel::usart::set_baudrate(460800); 50 | Kernel::terminal.open(); 51 | } 52 | }; 53 | #endif // DYNAMIC_BAUD_RATE 54 | 55 | // ---------------------------------------------------------------------------- 56 | // Terminal Commands 57 | // 58 | 59 | using commands = mptl::terminal_hook_list< 60 | cpuid 61 | #ifdef DYNAMIC_BAUD_RATE 62 | , baudrate 63 | #endif 64 | >; 65 | 66 | } // namespace terminal_hooks 67 | 68 | #endif // TERMINAL_HOOKS_HPP_INCLUDED 69 | -------------------------------------------------------------------------------- /projects/unittest/.gitignore: -------------------------------------------------------------------------------- 1 | /obj 2 | /var 3 | -------------------------------------------------------------------------------- /projects/unittest/create_fail_src.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # 4 | # creates sources which should fail at compile-time by succesively 5 | # enabling all UNITTEST_STATIC_ASSERT. 6 | # 7 | # usage: create_fail_src.pl -o ... 8 | # 9 | 10 | use Getopt::Std; 11 | use File::Spec::Functions qw(splitpath); 12 | use strict; 13 | use warnings FATAL => qw( all ); 14 | 15 | my @outfiles; 16 | 17 | my %opts; 18 | getopts('o:', \%opts); 19 | my $outdir = $opts{o}; 20 | 21 | die unless(-d $outdir); 22 | 23 | while (my $infile = shift @ARGV) { 24 | my (undef, $dir, $file) = splitpath($infile); 25 | my $fileext = $& if($file =~ s/\.\w+$//); 26 | my $outfile_prefix = $outdir . '/' . $file . '_'; 27 | 28 | print STDERR "Reading file: $infile\n"; 29 | 30 | my $text; 31 | 32 | open(INFILE, "<$infile") || die; 33 | { 34 | local $/; # slurp the file 35 | $text = ; 36 | } 37 | close(INFILE); 38 | 39 | my $pre = ''; 40 | my $count = 0; 41 | 42 | while ($text =~ /^\s*#ifdef\s+UNITTEST_MUST_FAIL/ms) { 43 | my $m = $&; 44 | $pre = $pre . $`; 45 | $text = $'; 46 | my $mm = $m; 47 | $mm =~ s/UNITTEST_MUST_FAIL/UNITTEST_MUST_FAIL_ENABLED/; 48 | 49 | $count++; 50 | my $outfile = $outfile_prefix . $count . $fileext; 51 | 52 | print STDERR "Creating output file: $outfile\n"; 53 | open(OUTFILE, ">$outfile") || die; 54 | print OUTFILE $pre . $mm . $text; 55 | close(OUTFILE); 56 | push @outfiles, $outfile; 57 | 58 | $pre = $pre . $m; 59 | } 60 | } 61 | 62 | 63 | print join(' ', @outfiles); 64 | -------------------------------------------------------------------------------- /projects/unittest/src/tuple_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #define CONFIG_USE_STD_TUPLE 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | std::ostream & mptl::sim::regdump_ostream = std::cout; 32 | 33 | using namespace mptl; 34 | 35 | // helper function to print a tuple of any size 36 | template 37 | struct tuple_regmask_reset_to { 38 | static void command(const Tp& t) 39 | { 40 | tuple_regmask_reset_to::command(t); 41 | // std::cout << "# " << std::get(t).value << std::endl; 42 | std::get(t).reset_to(); 43 | } 44 | }; 45 | 46 | template 47 | struct tuple_regmask_reset_to { 48 | static void command(const Tp& t) 49 | { 50 | // std::cout << std::get<0>(t).value << std::endl; 51 | std::get<0>(t).reset_to(); 52 | } 53 | }; 54 | 55 | template 56 | void reset_all(const std::tuple & t) 57 | { 58 | tuple_regmask_reset_to::command(t); 59 | } 60 | 61 | 62 | int main() 63 | { 64 | using list = typelist< 65 | RCC::AHB2ENR::OTGFSEN, 66 | RCC::PLLCFGR::PLLSRC, 67 | RCC::CFGR::PPRE1::DIV4 68 | >; 69 | 70 | std::cout << "****** for_each ******" << std::endl; 71 | 72 | auto tup = list::tuple_type(); 73 | mpl::for_each(tup); 74 | 75 | std::cout << "****** for_each (directy) ******" << std::endl; 76 | 77 | list::for_each(); 78 | 79 | std::cout << "****** reset_all ******" << std::endl; 80 | 81 | reset_all(tup); 82 | } 83 | -------------------------------------------------------------------------------- /projects/unittest/src/typelist.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | std::ostream & mptl::sim::regdump_ostream = std::cout; 30 | 31 | using namespace mptl; 32 | 33 | struct A : reg< uint32_t, 0x1000, rw, 0 > {}; 34 | struct B : reg< uint32_t, 0x2000, rw, 0x44444444 > {}; 35 | struct C : reg< uint8_t, 0x3000, rw, 0 > {}; 36 | struct D : reg< uint32_t, 0x4000, rw, 0x55555555 > {}; 37 | 38 | using test_a_0 = regmask< A, 0x00000011, 0x000000ff >; 39 | using test_a_1 = regmask< A, 0x00001100, 0x0000ff00 >; 40 | using test_b = regmask< B, 0x00110000, 0x00ff0000 >; 41 | using test_a_2 = regmask< A, 0x11000000, 0xff000000 >; 42 | using test_c = regmask< C, 0x10, 0xff >; 43 | 44 | using anti_test_a_0 = regmask< A, 0x00000000, 0x00000010 >; /* clears a bit which is set by test_a_0 */ 45 | 46 | using uniq_a = typelist_unique_element< A >; 47 | using uniq_b = typelist_unique_element< B >; 48 | using uniq_c = typelist_unique_element< C >; 49 | using uniq_d = typelist_unique_element< D >; 50 | 51 | using list = typelist < 52 | void, 53 | uniq_a, 54 | typelist< 55 | typelist< 56 | test_a_0, 57 | test_a_1, 58 | test_b 59 | > 60 | >, 61 | test_a_1, 62 | typelist< 63 | uniq_b 64 | >, 65 | uniq_c, 66 | uniq_d, 67 | void, 68 | typelist< 69 | void 70 | >, 71 | typelist< 72 | test_b, 73 | typelist< 74 | test_a_2 75 | >, 76 | void, 77 | test_a_0 78 | >, 79 | test_c, 80 | void 81 | >; 82 | 83 | using uniq_fail_list = typelist < list, uniq_c >; 84 | using bitmask_fail_list = typelist < anti_test_a_0, list >; 85 | 86 | int main() 87 | { 88 | #ifdef UNITTEST_MUST_FAIL 89 | #warning UNITTEST_MUST_FAIL: set/clear check failed: setting a bit which was previously cleared 90 | make_reglist< bitmask_fail_list >::reset_to(); 91 | #endif 92 | 93 | assert(A::load() == 0); 94 | assert(B::load() == 0x44444444); 95 | assert(C::load() == 0); 96 | assert(D::load() == 0x55555555); 97 | 98 | /* set all shared register from list */ 99 | make_reglist< list >::reset_to(); 100 | 101 | assert(A::load() == 0x11001111); 102 | assert(B::load() == 0x44114444); 103 | assert(C::load() == 0x10); 104 | assert(D::load() == 0x55555555); 105 | 106 | return 0; 107 | } 108 | -------------------------------------------------------------------------------- /projects/unittest/src/vector_table.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | using namespace mptl; 26 | 27 | static unsigned int stack_top = 0; 28 | static int isr_test = 0; 29 | 30 | static void default_isr(void) { isr_test = 0; } 31 | static void isr_42(void) { isr_test = 42; } 32 | 33 | /* Handler for irq number = 42 */ 34 | using irq42 = irq_handler< irq_base<42>, isr_42 >; 35 | 36 | using resource_list = mptl::typelist < irq42 >; 37 | using resource_fail_list = mptl::typelist < irq42, irq42 >; 38 | 39 | int main() 40 | { 41 | #ifdef UNITTEST_MUST_FAIL 42 | #warning UNITTEST_MUST_FAIL: list contains more than one element 43 | using vt_fail = vector_table<&stack_top, resource_fail_list, default_isr>; 44 | auto arm_vector_table_fail = vt_fail::value; 45 | #endif 46 | 47 | // resource_list::check(); 48 | // resource_list::configure(); 49 | 50 | using vt = vector_table<&stack_top, resource_list, default_isr>; 51 | mptl::arm_cortex_vector_table arm_vector_table = vt::value; 52 | 53 | assert((unsigned long)arm_vector_table.stack_top == (unsigned long)&stack_top); 54 | assert((unsigned long)arm_vector_table.isr_vector[vt::irq_channel_offset + 41] == (unsigned long)default_isr); 55 | assert((unsigned long)arm_vector_table.isr_vector[vt::irq_channel_offset + 42] == (unsigned long)isr_42); 56 | 57 | vt::dump_size(); 58 | vt::dump_types(); 59 | vt::dump_vector(); 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /sim/register_sim.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenMPTL - C++ Microprocessor Template Library 3 | * 4 | * Copyright (C) 2012-2017 Axel Burri 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | namespace mptl { namespace sim { 26 | 27 | __weak std::ostream & regdump_ostream = std::clog; /**< defaults to std::clog (weak symbol, can be overridden) */ 28 | thread_local int regdump_reaction_running = 0; 29 | 30 | #ifdef CONFIG_SIM_THREADED 31 | std::mutex regdump_mutex; 32 | #endif 33 | 34 | } } // namespace mptl::sim 35 | --------------------------------------------------------------------------------