File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 2525#include "esp_bt.h"
2626#endif //CONFIG_BT_ENABLED
2727#include <sys/time.h>
28+ #include "soc/rtc.h"
2829#include "esp32-hal.h"
2930
3031//Undocumented!!! Get chip temperature in Farenheit
@@ -41,19 +42,41 @@ void yield()
4142 vPortYield ();
4243}
4344
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+
4467unsigned long IRAM_ATTR micros ()
4568{
46- return (unsigned long ) esp_timer_get_time ();
69+ return (unsigned long ) ( esp_timer_get_time () * ( 240 / _cpu_freq_mhz ) );
4770}
4871
4972unsigned long IRAM_ATTR millis ()
5073{
51- return (unsigned long ) (esp_timer_get_time () / 1000 );
74+ return (unsigned long ) (micros () / 1000 );
5275}
5376
5477void delay (uint32_t ms )
5578{
56- vTaskDelay (ms / portTICK_PERIOD_MS );
79+ vTaskDelay (ms / portTICK_PERIOD_MS / ( 240 / _cpu_freq_mhz ) );
5780}
5881
5982void IRAM_ATTR delayMicroseconds (uint32_t us )
Original file line number Diff line number Diff line change @@ -72,6 +72,9 @@ void yield(void);
7272//returns chip temperature in Celsius
7373float temperatureRead ();
7474
75+ bool cpuFrequencySet (uint32_t cpu_freq_mhz );
76+ uint32_t cpuFrequencyGet ();
77+
7578unsigned long micros ();
7679unsigned long millis ();
7780void delay (uint32_t );
You can’t perform that action at this time.
0 commit comments