Merge pull request #615 from ourairquality/os_delay_us

sdk_os_delay_us: rewrite to avoid hal.h
This commit is contained in:
Ruslan V. Uss 2018-04-27 01:20:30 +05:00 committed by GitHub
commit 61d3f5b445
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,7 +11,7 @@
#include "esp/gpio_regs.h" #include "esp/gpio_regs.h"
#include "esp/rtc_regs.h" #include "esp/rtc_regs.h"
#include "sdk_internal.h" #include "sdk_internal.h"
#include "xtensa/hal.h" #include "xtensa_ops.h"
static int cpu_freq = 80; static int cpu_freq = 80;
@ -28,9 +28,14 @@ void sdk_os_update_cpu_frequency(int freq) {
void sdk_ets_update_cpu_frequency(int freq) __attribute__ (( alias ("sdk_os_update_cpu_frequency") )); void sdk_ets_update_cpu_frequency(int freq) __attribute__ (( alias ("sdk_os_update_cpu_frequency") ));
void sdk_os_delay_us(uint16_t us) { void sdk_os_delay_us(uint16_t us) {
uint32_t start_ccount = xthal_get_ccount(); uint32_t start_ccount, ccount;
uint32_t delay_ccount = cpu_freq * us; uint32_t delay_ccount = cpu_freq * us;
while (xthal_get_ccount() - start_ccount < delay_ccount) {}
RSR(start_ccount, ccount);
do {
RSR(ccount, ccount);
} while (ccount - start_ccount < delay_ccount);
} }
void sdk_ets_delay_us(uint16_t us) __attribute__ (( alias ("sdk_os_delay_us") )); void sdk_ets_delay_us(uint16_t us) __attribute__ (( alias ("sdk_os_delay_us") ));