Skip to content

Commit

Permalink
Adds new keys to erlang:system_info/1 for ESP-IDF semantic version
Browse files Browse the repository at this point in the history
Adds the keys `esp_idf_semantic`, `esp_idf_major`, `esp_idf_minor`, and
`esp_idf_patch` to erlang:system_info/1 to obtain the semantic version of the
ESP-IDF that the current VM was build with.  This is intended to make it easier
for device drivers to know which ESP-IDF API versions to use when there are
breaking changes between ESP-IDF versions.

Signed-off-by: Winford <[email protected]>
  • Loading branch information
UncleGrumpy committed Mar 10, 2024
1 parent b4c4866 commit 103dd70
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.6.1] - Unreleased

### Added

- ESP32: new keys for `erlang:system_info/1` to retrieve esp-idf semantic version info:
* `esp_idf_semantic` returns a tuple `{Major :: integer(), Minor :: integer(), Patch :: integer()}`
* `esp_idf_major`, `esp_idf_minor`, `esp_idf_patch` return individual integers

### Fixed

- Fix bug in `erlang:ref_to_list/1`, the unique integer was truncated on some 32-bit architectures
Expand Down
4 changes: 4 additions & 0 deletions doc/src/programmers-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,10 @@ You can request ESP32-specific information using using the following input atoms
* `esp_get_minimum_free_size` Returns the smallest ever free space available in the ESP32 heap since boot, this will tell you how close you have come to running out of free memory.
* `esp_chip_info` Returns map of the form `#{features := Features, cores := Cores, revision := Revision, model := Model}`, where `Features` is a list of features enabled in the chip, from among the following atoms: `[emb_flash, bgn, ble, bt]`; `Cores` is the number of CPU cores on the chip; `Revision` is the chip version; and `Model` is one of the following atoms: `esp32`, `esp32_s2`, `esp32_s3`, `esp32_c3`.
* `esp_idf_version` Return the IDF SDK version, as a string.
* `esp_idf_semantic` Returns a tuple containing `{Major :: integer(), Minor :: integer(), Patch :: integer()}`.
* `esp_idf_major` Returns the major version number as an integer.
* `esp_idf_minor` Returns the minor version number as an integer.
* `esp_idf_patch` Returns the patch version number as an integer.
For example,
Expand Down
23 changes: 23 additions & 0 deletions src/platforms/esp32/components/avm_sys/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ static const char *const esp_largest_free_block_atom = "\x18" "esp32_largest_fre
static const char *const esp_get_minimum_free_size_atom = "\x17" "esp32_minimum_free_size";
static const char *const esp_chip_info_atom = "\xF" "esp32_chip_info";
static const char *const esp_idf_version_atom = "\xF" "esp_idf_version";
static const char *const esp_idf_semantic_atom = "\xF" "esp_idf_semantic";
static const char *const esp_idf_major_atom = "\xD" "esp_idf_major";
static const char *const esp_idf_minor_atom = "\xD" "esp_idf_minor";
static const char *const esp_idf_patch_atom = "\xD" "esp_idf_patch";
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 2)
static const char *const esp32_atom = "\x5" "esp32";
static const char *const esp32_s2_atom = "\x8" "esp32_s2";
Expand Down Expand Up @@ -544,6 +548,25 @@ term sys_get_info(Context *ctx, term key)
}
return term_from_string((const uint8_t *) str, n, &ctx->heap);
}
if (key == globalcontext_make_atom(glb, esp_idf_semantic_atom)){
if (memory_ensure_free(ctx, TUPLE_SIZE(3)) != MEMORY_GC_OK) {
return OUT_OF_MEMORY_ATOM;
}
term semantic = term_alloc_tuple(3, &ctx->heap);
term_put_tuple_element(semantic, 0, term_from_int32(ESP_IDF_VERSION_MAJOR));
term_put_tuple_element(semantic, 1, term_from_int32(ESP_IDF_VERSION_MINOR));
term_put_tuple_element(semantic, 2, term_from_int32(ESP_IDF_VERSION_PATCH));
return semantic;
}
if (key == globalcontext_make_atom(glb, esp_idf_major_atom)){
return term_from_int32(ESP_IDF_VERSION_MAJOR);
}
if (key == globalcontext_make_atom(glb, esp_idf_minor_atom)){
return term_from_int32(ESP_IDF_VERSION_MINOR);
}
if (key == globalcontext_make_atom(glb, esp_idf_patch_atom)){
return term_from_int32(ESP_IDF_VERSION_PATCH);
}
return UNDEFINED_ATOM;
}

Expand Down

0 comments on commit 103dd70

Please sign in to comment.