OpenMPTL - ARM Cortex (common)
C++ Microprocessor Template Library
core.hpp
Go to the documentation of this file.
1 /*
2  * OpenMPTL - C++ Microprocessor Template Library
3  *
4  * Copyright (C) 2012-2017 Axel Burri <axel@tty0.ch>
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 <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef ARM_CORTEX_COMMON_CORE_HPP_INCLUDED
22 #define ARM_CORTEX_COMMON_CORE_HPP_INCLUDED
23 
24 #include <register.hpp>
25 #include <crt.hpp>
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) {
69 
70  system_clock_type::init();
72  system_clock_type::configure();
73 
75  crt::run_init_array(); /* call ctors */
76  }
77 };
78 
79 } // namespace mptl
80 
81 #endif // ARM_CORTEX_COMMON_CORE_HPP_INCLUDED
static void nop(unsigned value)
Definition: core.hpp:46
Definition: core.hpp:29
static void init_bss_section(void)
static void isb()
Definition: core.hpp:41
static void dmb()
Definition: core.hpp:43
static void init_data_section(void)
static void disable_irq()
global interrupt disable
Definition: core.hpp:32
static void enable_fault_irq()
Definition: core.hpp:34
static void enable_irq()
global interrupt enable
Definition: core.hpp:31
static void startup(void)
Definition: core.hpp:66
static __always_inline void reset_to(void)
static void dsb()
Definition: core.hpp:42
static void run_preinit_array(void)
static void disable_fault_irq()
Definition: core.hpp:35
static void wfi()
Definition: core.hpp:38
static void run_init_array(void)
static void wfe()
Definition: core.hpp:39
static void sev()
Definition: core.hpp:40
static void clrex()
Definition: core.hpp:44
static void nop()
Definition: core.hpp:37