diff options
| author | Scott Shawcroft <scott@adafruit.com> | 2020-11-17 17:11:41 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-17 17:11:41 -0800 |
| commit | 18513dedd14303289ccfa104f344a746a303376d (patch) | |
| tree | 2b126fdb6ed551261e67385d45e99b13d8065e42 | |
| parent | 226715b147464ce38bf7c2a9e9d6734a348c79eb (diff) | |
| parent | 9206925bf8d2e3d8220b59200ee50c3e4c8a64d2 (diff) | |
Merge pull request #3710 from jepler/esp32-i2c-crash
esp32: Two random changes that also fixed the I2C crash for me
| -rw-r--r-- | ports/esp32s2/common-hal/pulseio/PulseIn.c | 8 | ||||
| -rw-r--r-- | ports/esp32s2/supervisor/port.c | 10 |
2 files changed, 11 insertions, 7 deletions
diff --git a/ports/esp32s2/common-hal/pulseio/PulseIn.c b/ports/esp32s2/common-hal/pulseio/PulseIn.c index f7429ec12..9feeea147 100644 --- a/ports/esp32s2/common-hal/pulseio/PulseIn.c +++ b/ports/esp32s2/common-hal/pulseio/PulseIn.c @@ -77,7 +77,9 @@ void pulsein_reset(void) { for (size_t i = 0; i < RMT_CHANNEL_MAX; i++) { handles[i] = NULL; } - supervisor_disable_tick(); + if (refcount != 0) { + supervisor_disable_tick(); + } refcount = 0; } @@ -122,8 +124,10 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, const mcu // start RMT RX, and enable ticks so the core doesn't turn off. rmt_rx_start(channel, true); - supervisor_enable_tick(); refcount++; + if (refcount == 1) { + supervisor_enable_tick(); + } } bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) { diff --git a/ports/esp32s2/supervisor/port.c b/ports/esp32s2/supervisor/port.c index 47d0c7f46..876ad739d 100644 --- a/ports/esp32s2/supervisor/port.c +++ b/ports/esp32s2/supervisor/port.c @@ -191,14 +191,14 @@ uint32_t port_get_saved_word(void) { } uint64_t port_get_raw_ticks(uint8_t* subticks) { - struct timeval tv_now; - gettimeofday(&tv_now, NULL); - // convert usec back to ticks - uint64_t all_subticks = (uint64_t)(tv_now.tv_usec * 2) / 71; + // Convert microseconds to subticks of 1/32768 seconds + // 32768/1000000 = 64/15625 in lowest terms + // this arithmetic overflows after 570 years + int64_t all_subticks = esp_timer_get_time() * 512 / 15625; if (subticks != NULL) { *subticks = all_subticks % 32; } - return (uint64_t)tv_now.tv_sec * 1024L + all_subticks / 32; + return all_subticks / 32; } // Enable 1/1024 second tick. |
