File tree 2 files changed +29
-3
lines changed
2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 25
25
#include "esp_bt.h"
26
26
#endif //CONFIG_BT_ENABLED
27
27
#include <sys/time.h>
28
+ #include "soc/rtc.h"
28
29
#include "esp32-hal.h"
29
30
30
31
//Undocumented!!! Get chip temperature in Farenheit
@@ -41,19 +42,41 @@ void yield()
41
42
vPortYield ();
42
43
}
43
44
45
+ static uint32_t _cpu_freq_mhz = 240 ;
46
+
47
+ bool cpuFrequencySet (uint32_t cpu_freq_mhz ){
48
+ if (_cpu_freq_mhz == cpu_freq_mhz ){
49
+ return true;
50
+ }
51
+ rtc_cpu_freq_config_t conf ;
52
+ if (!rtc_clk_cpu_freq_mhz_to_config (cpu_freq_mhz , & conf )){
53
+ log_e ("CPU clock could not be set to %u MHz" , cpu_freq_mhz );
54
+ return false;
55
+ }
56
+ rtc_clk_cpu_freq_set_config (& conf );
57
+ _cpu_freq_mhz = conf .freq_mhz ;
58
+ return true;
59
+ }
60
+
61
+ uint32_t cpuFrequencyGet (){
62
+ rtc_cpu_freq_config_t conf ;
63
+ rtc_clk_cpu_freq_get_config (& conf );
64
+ return conf .freq_mhz ;
65
+ }
66
+
44
67
unsigned long IRAM_ATTR micros ()
45
68
{
46
- return (unsigned long ) esp_timer_get_time ();
69
+ return (unsigned long ) ( esp_timer_get_time () * ( 240 / _cpu_freq_mhz ) );
47
70
}
48
71
49
72
unsigned long IRAM_ATTR millis ()
50
73
{
51
- return (unsigned long ) (esp_timer_get_time () / 1000 );
74
+ return (unsigned long ) (micros () / 1000 );
52
75
}
53
76
54
77
void delay (uint32_t ms )
55
78
{
56
- vTaskDelay (ms / portTICK_PERIOD_MS );
79
+ vTaskDelay (ms / portTICK_PERIOD_MS / ( 240 / _cpu_freq_mhz ) );
57
80
}
58
81
59
82
void IRAM_ATTR delayMicroseconds (uint32_t us )
Original file line number Diff line number Diff line change @@ -72,6 +72,9 @@ void yield(void);
72
72
//returns chip temperature in Celsius
73
73
float temperatureRead ();
74
74
75
+ bool cpuFrequencySet (uint32_t cpu_freq_mhz );
76
+ uint32_t cpuFrequencyGet ();
77
+
75
78
unsigned long micros ();
76
79
unsigned long millis ();
77
80
void delay (uint32_t );
You can’t perform that action at this time.
0 commit comments