Skip to content
This repository was archived by the owner on Mar 11, 2019. It is now read-only.

Commit 9eb57a0

Browse files
committed
esp32: Add time.Now() support
1 parent 5cafb9c commit 9eb57a0

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

ports/esp32/main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,11 @@ void tinygo_fatal() {
8383
// TODO: this only resets the CPUs, not the peripherals
8484
esp_restart();
8585
}
86+
87+
struct tinygo_now tinygo_now() {
88+
struct tinygo_now ret;
89+
int64_t micros = esp_timer_get_time();
90+
ret.sec = micros / 1000 / 1000;
91+
ret.nsec = (micros - (uint64_t)ret.sec * 1000ULL * 1000ULL) * 1000;
92+
return ret;
93+
}

src/runtime/tinygo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ void tinygo_fatal(); // exit process or reset chip
6363

6464
__attribute__((noreturn))
6565
void runtime_Panic(struct __go_empty_interface msg, bool fatal) __asm__("runtime.Panic");
66+
struct tinygo_now { uint64_t sec; uint64_t nsec; };
67+
struct tinygo_now tinygo_now() __asm__("time.now");
6668
void tinygo_sleep(int64_t sleeptime) __asm__("time.Sleep");
6769
void tinygo_semacquire(volatile uint32_t *addr, bool profile) __asm__("sync.runtime_Semacquire");
6870
void tinygo_semrelease(volatile uint32_t *addr) __asm__("sync.runtime_Semrelease");

0 commit comments

Comments
 (0)