comparison l476rg-hal-test/src/main.cpp @ 6:ca42336826bd default tip

working on clock sources
author cin
date Mon, 23 Jan 2017 02:40:17 +0300
parents 0d3eea2dd7ea
children
comparison
equal deleted inserted replaced
5:0d3eea2dd7ea 6:ca42336826bd
47 47
48 template<typename TDev, typename TCounter = uint32_t> class TTimerBase { 48 template<typename TDev, typename TCounter = uint32_t> class TTimerBase {
49 public: 49 public:
50 typedef TCounter counter_t; 50 typedef TCounter counter_t;
51 51
52 static void Init() { 52 static void init() {
53 TDev::instance()->EGR = TIM_EGR_UG; 53 TDev::instance()->EGR = TIM_EGR_UG;
54 } 54 }
55 55
56 static void period(counter_t value) { 56 static void period(counter_t value) {
57 TDev::instance()->ARR = value; 57 TDev::instance()->ARR = value;
109 } 109 }
110 }; 110 };
111 111
112 class AHB2Bus { 112 class AHB2Bus {
113 public: 113 public:
114 static void Enable(unsigned int flag) { 114 static void enable(unsigned int flag) {
115 RCC->AHB2ENR |= flag; 115 RCC->AHB2ENR |= flag;
116 } 116 }
117
118 static uint32_t clock() {
119
120 }
117 }; 121 };
118 122
119 class APB1Bus { 123 class APB1Bus {
120 public: 124 public:
121 static void Enable(unsigned int flag) { 125 static void enable(unsigned int flag) {
122 RCC->APB1ENR1 |= flag; 126 RCC->APB1ENR1 |= flag;
123 } 127 }
124 }; 128 };
125 129
126 class APB1Bus2 { 130 class APB1Bus2 {
127 static void Enable(uint32_t flag) { 131 static void enable(uint32_t flag) {
128 RCC->APB1ENR2 |= flag; 132 RCC->APB1ENR2 |= flag;
129 } 133 }
130 }; 134 };
131 135
132 template<typename TRegs, typename TBus, uint32_t BASE, uint32_t ENF> class TDevice { 136 template <typename TRegs, typename TBus, uint32_t BASE, uint32_t ENF> class TDevice {
133 public: 137 public:
138 typedef TBus bus_t;
139
134 static TRegs* instance() { 140 static TRegs* instance() {
135 return (TRegs*) BASE; 141 return (TRegs*) BASE;
136 } 142 }
137 143
138 static void Enable() { 144 static void enable() {
139 TBus::Enable(ENF); 145 TBus::enable(ENF);
140 } 146 }
141 147
142 static uint32_t frequency() { 148 static uint32_t frequency() {
143 return 80000000; 149 return 80000000;
144 } 150 }
145 }; 151 };
152
153 class OscMsi {
154 };
155
156 class OscHsi {
157 };
158
159 class OscHse {
160 };
161
162 class OscLsi {
163 };
164
165 class OscLse {
166 };
167
168 class Pll {
169 };
170
171 class Pclk1 {
172 public:
173 uint32_t clock() {
174 return APB1Bus::clock();
175 }
176 };
177
178 class Rcc {
179 public:
180 typedef enum {
181 PClk1,
182 Apb1TimerClk,
183 PClk2,
184 Apb2TimerClk,
185 HClk,
186 SysClk,
187 HsiClk,
188 HseClk,
189 LsiClk,
190 LseClk,
191 MsiClk,
192 PllClk,
193 PllQClk,
194 PllPClk,
195 PllSai1P,
196 PllSai1Q,
197 PllSai1R,
198 PllSai2P,
199 PllSai2R
200 } ClockSource;
201
202 template <ClockSource clk> unit32_t clock();
203 };
204
205 class SysClk {
206 public:
207 uint32_t clock() {
208 }
209 };
210
211 class UartClockMux {
212 public:
213 template <typename TClk> void select_clock_source();
214 };
215
216 template<> void UartClockMux::select_clock_source<Pclk1>() {
217 }
218
219 template<> void UartClockMux::select_clock_source<SysClk>() {
220 }
146 221
147 class Hardware { 222 class Hardware {
148 public: 223 public:
149 typedef TDevice<GPIO_TypeDef, GPIOA_BASE, AHB2Bus, RCC_AHB2ENR_GPIOAEN> GpioA; 224 typedef TDevice<GPIO_TypeDef, GPIOA_BASE, AHB2Bus, RCC_AHB2ENR_GPIOAEN> GpioA;
150 typedef TDevice<TIM_TypeDef, TIM3_BASE, APB1Bus, RCC_APB1ENR1_TIM3EN> Tim3; 225 typedef TDevice<TIM_TypeDef, TIM3_BASE, APB1Bus, RCC_APB1ENR1_TIM3EN> Tim3;