OpenMPTL - ARM Cortex (common)
C++ Microprocessor Template Library
scb.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_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<unsigned priority_bits>
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<SCB::AIRCR::VECTKEY, SCB::AIRCR::PRIGROUP>
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<int irqn>
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<int irqn>
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