Clocks.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * Clocks.h
8  *
9  * @author mikee47 <mike@sillyhouse.net>
10  *
11  ****/
12 
13 #pragma once
14 
15 #include <NanoTime.h>
16 #include <driver/hw_timer.h>
17 #include <esp_clk.h>
18 #include "System.h"
19 
28 template <hw_timer_clkdiv_t clkdiv>
30  : public NanoTime::Clock<Timer1Clock<clkdiv>, HW_TIMER_BASE_CLK / (1 << clkdiv), uint32_t, MAX_HW_TIMER1_INTERVAL> {
31  static constexpr uint32_t prescale()
32  {
33  return 1 << clkdiv;
34  }
35 
36  static constexpr const char* typeName()
37  {
38  return "Timer1Clock";
39  }
40 
41  /*
42  * As Timer1 is a down-counter, when active this will indicate remaining ticks until the next interrupt.
43  */
44  static uint32_t __forceinline ticks()
45  {
46  return hw_timer1_read();
47  }
48 };
49 
55 struct Timer2Clock : public NanoTime::Clock<Timer2Clock, HW_TIMER2_CLK, uint32_t, 0xFFFFFFFFU> {
56  static constexpr const char* typeName()
57  {
58  return "Timer2Clock";
59  }
60 
61  static uint32_t __forceinline ticks()
62  {
63  return hw_timer2_read();
64  }
65 };
66 
81 template <CpuFrequency cpuFreq>
82 struct CpuCycleClock
83  : public NanoTime::Clock<CpuCycleClock<cpuFreq>, uint32_t(cpuFreq) * 1000000, uint32_t, 0xFFFFFFFF> {
84  static constexpr const char* typeName()
85  {
86  return "CpuCycleClock";
87  }
88 
89  static uint32_t __forceinline ticks()
90  {
91  return esp_get_ccount();
92  }
93 
94  static constexpr CpuFrequency cpuFrequency()
95  {
96  return cpuFreq;
97  }
98 };
99 
100 #include_next <Platform/Clocks.h>
101 
Class template representing a physical Clock with fixed timing characteristics.
Definition: NanoTime.h:131
Clock implementation for Hardware Timer 1.
Definition: Clocks.h:30