Skip to content

Conversation

@schnittchen
Copy link

I hope this addition is welcome. It's incomplete because I would like to get early feedback.

Originally I wanted to simply expose esp_timer_get_time, but integer size restrictions make this tricky, so I decided to divide by 10^6 to be able to get the seconds since boot (or wakeup from sleep). This function should be useful at least for monitoring purposes.

If you suggest a nice way to expose the full int64_t precision, I'll happily change the implementation (and name).

This is my first contribution and my first NIF code. Next up I would like to add support for ESP32's DAC, but let's start simple.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

@pguyot
Copy link
Collaborator

pguyot commented Nov 13, 2025

Thank you. I am confused by the division. AtomVM has been supporting signed int64_t for a while, but you need to box them with term_make_maybe_box_int64. term_from_int64 is bad and should be removed (see #1897).

@schnittchen
Copy link
Author

You mean term_make_maybe_boxed_int64 I suppose. I overlooked that, will change accordingly.

I see a number of SUPPORT ifdefs, would my addition be right outside any?

@petermm
Copy link
Contributor

petermm commented Nov 13, 2025

This is a nice addition, for the DCO CI you need to signoff your commits - https://docs.pi-hole.net/guides/github/how-to-signoff/ eg git commit --amend --signoff

I'm fine with this not being tested, but you could add a test similar to https://github.com/atomvm/AtomVM/blob/main/src/platforms/esp32/test/main/test_erl_sources/test_monotonic_time.erl - maybe even just to that file..

@schnittchen schnittchen force-pushed the esp-uptime branch 2 times, most recently from 8ec45cd to 8804e11 Compare November 13, 2025 21:37
@petermm
Copy link
Contributor

petermm commented Nov 14, 2025

Looks good, add a line to the changelog and squash commits - then it's should be ready!

@schnittchen schnittchen marked this pull request as ready for review November 14, 2025 10:26
@schnittchen schnittchen changed the title [wip] add esp.timer_get_time_seconds add esp.timer_get_time_seconds Nov 14, 2025
@petermm
Copy link
Contributor

petermm commented Nov 14, 2025

complete nitpicks:
Can the return type not be narrowed to non_neg_integer() ?
And the test_pos_int function name in test should be test_non_neg_int, test_pos_int is technically incorrect.
Capitalize commit message

Great work landing first PR! - not entirely easy;-)

@schnittchen
Copy link
Author

Thank you, the next one will be much harder...

Can the return type not be narrowed to non_neg_integer() ?

I went with the original type... which overflows after ~300k years 😂

I made changes for the rest of the nitpicks. Thank you!

@schnittchen
Copy link
Author

It looks like the final commit message change did not make it over to this PR :/
Maybe the PR update is queuing.

@petermm
Copy link
Contributor

petermm commented Nov 14, 2025

Looks like you forgot to push the last nitpick fixes?

@schnittchen
Copy link
Author

I pushed to the source branch where this PR is from: https://github.com/schnittchen/AtomVM/tree/esp-dac

I think it's just GH being stuck. I'll add a bogus commit, push, reset back, push again.

@schnittchen
Copy link
Author

There we go!

I was on the wrong branch.

@schnittchen
Copy link
Author

I'm not 100% sure the code is correct at this stage. I'm struggling with the build system and making sure all my changes get onto the device.

For upcoming work, I added another Erlang module, added it to libs/eavmlib/src/CMakeLists.txt, rebuilt and re-flashed AtomVM, but the module could not be found.

What steps do I need to take to make sure that Erlang code changes are picked up when creating and flashing AtomVM on ESP32?

@petermm
Copy link
Contributor

petermm commented Nov 14, 2025

maybe join the telegram (most active) or the discord to get help - https://atomvm.org/contact/

you need to build in the AtomVM/build folder first to compile the erlang code and stdlibs - then complete the (esp32) build in the esp32 folder..

@pguyot pguyot changed the title add esp.timer_get_time_seconds add esp.timer_get_time Nov 16, 2025
@schnittchen
Copy link
Author

I'm not 100% sure the code is correct at this stage. I'm struggling with the build system and making sure all my changes get onto the device.

I'm currently iterating by building everything from scratch. So far, the new functionality seems to work.

Signed-off-by: schnittchen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants