OpenMPTL - STM32F10X
C++ Microprocessor Template Library
flash.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 ARCH_FLASH_HPP_INCLUDED
22 #define ARCH_FLASH_HPP_INCLUDED
23 
24 #include <arch/reg/flash.hpp>
25 #include <freq.hpp>
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 
44 
45  struct latency {
46  template< typename system_clock_type >
47  using minimum = regval<
49  min_latency(system_clock_type::hclk_freq)
50  >;
51 
52  template< unsigned 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
unsigned int freq_t
Definition: flash.hpp:29
typename Tp::value_type value_type
static constexpr freq_t mhz(unsigned long long x)
regbits< type, 0, 3 > LATENCY
Latency.
Definition: flash.hpp:54
static void configure(void)
Configure FLASH register using configuration traits (Tp).
Definition: flash.hpp:62
Definition: flash.hpp:45