[core] Rename CPU and memory APIs

This commit is contained in:
Kuba Szczodrzyński
2023-03-12 14:11:16 +01:00
parent dfcb36361e
commit c3f12ab247
7 changed files with 80 additions and 80 deletions

View File

@@ -24,22 +24,22 @@ void lt_init_family() {
| | | ___/| | | |
| |____| | | |__| |
\_____|_| \____*/
lt_cpu_model_t lt_get_cpu_model() {
lt_cpu_model_t lt_cpu_get_model() {
uint8_t chipId = *(uint8_t *)(SCTRL_CHIP_ID);
return CPU_MODEL_ENUM(FAMILY, chipId);
}
uint32_t lt_get_cpu_unique_id() {
return lt_get_cpu_mac_id();
uint32_t lt_cpu_get_unique_id() {
return lt_cpu_get_mac_id();
}
uint32_t lt_get_cpu_mac_id() {
uint32_t lt_cpu_get_mac_id() {
uint8_t mac[6];
cfg_load_mac(mac); // force loading MAC from TLV (ignore user-set WiFi MAC)
return (mac[3]) | (mac[4] << 8) | (mac[5] << 16);
}
const char *lt_get_cpu_core_type() {
const char *lt_cpu_get_core_type() {
return "ARM968E-S";
}
@@ -108,11 +108,11 @@ lt_flash_id_t lt_flash_get_id() {
|_| |_|\___|_| |_| |_|\___/|_| \__, |
__/ |
|__*/
uint32_t lt_get_ram_size() {
uint32_t lt_ram_get_size() {
return 256 * 1024;
}
uint32_t lt_get_heap_size() {
uint32_t lt_heap_get_size() {
#if configDYNAMIC_HEAP_SIZE
extern unsigned char _empty_ram;
#if CFG_SOC_NAME == SOC_BK7231N

View File

@@ -24,35 +24,35 @@
*/
class LibreTuya {
public: /* lt_cpu.h */
/** @copydoc lt_get_cpu_family() */
inline ChipFamily getChipFamily() { return lt_get_cpu_family(); }
/** @copydoc lt_cpu_get_family() */
inline ChipFamily getChipFamily() { return lt_cpu_get_family(); }
/** @copydoc lt_get_cpu_family_name() */
inline const char *getChipFamilyName() { return lt_get_cpu_family_name(); }
/** @copydoc lt_cpu_get_family_name() */
inline const char *getChipFamilyName() { return lt_cpu_get_family_name(); }
/** @copydoc lt_get_cpu_model() */
inline ChipType getChipType() { return lt_get_cpu_model(); }
/** @copydoc lt_cpu_get_model() */
inline ChipType getChipType() { return lt_cpu_get_model(); }
/** @copydoc lt_get_cpu_model_name() */
inline const char *getChipModel() { return lt_get_cpu_model_name(); }
/** @copydoc lt_cpu_get_model_name() */
inline const char *getChipModel() { return lt_cpu_get_model_name(); }
/** @copydoc lt_get_cpu_mac_id() */
inline uint32_t getChipId() { return lt_get_cpu_mac_id(); }
/** @copydoc lt_cpu_get_mac_id() */
inline uint32_t getChipId() { return lt_cpu_get_mac_id(); }
/** @copydoc lt_get_cpu_core_count() */
inline uint8_t getChipCores() { return lt_get_cpu_core_count(); }
/** @copydoc lt_cpu_get_core_count() */
inline uint8_t getChipCores() { return lt_cpu_get_core_count(); }
/** @copydoc lt_get_cpu_core_type() */
inline const char *getChipCoreType() { return lt_get_cpu_core_type(); }
/** @copydoc lt_cpu_get_core_type() */
inline const char *getChipCoreType() { return lt_cpu_get_core_type(); }
/** @copydoc lt_get_cpu_freq() */
inline uint32_t getCpuFreq() { return lt_get_cpu_freq(); }
/** @copydoc lt_cpu_get_freq() */
inline uint32_t getCpuFreq() { return lt_cpu_get_freq(); }
/** @copydoc lt_get_cpu_freq_mhz() */
inline uint32_t getCpuFreqMHz() { return lt_get_cpu_freq_mhz(); }
/** @copydoc lt_cpu_get_freq_mhz() */
inline uint32_t getCpuFreqMHz() { return lt_cpu_get_freq_mhz(); }
/** @copydoc lt_get_cpu_cycle_count() */
inline uint32_t getCycleCount() { return lt_get_cpu_cycle_count(); }
/** @copydoc lt_cpu_get_cycle_count() */
inline uint32_t getCycleCount() { return lt_cpu_get_cycle_count(); }
public: /* lt_device.h */
/** @copydoc lt_get_version() */
@@ -89,23 +89,23 @@ class LibreTuya {
inline uint32_t getFlashChipSize() { return lt_flash_get_size(); }
public: /* lt_mem.h */
/** @copydoc lt_get_ram_size() */
inline uint32_t getRamSize() { return lt_get_ram_size(); }
/** @copydoc lt_ram_get_size() */
inline uint32_t getRamSize() { return lt_ram_get_size(); }
/** @copydoc lt_get_heap_size() */
inline uint32_t getHeapSize() { return lt_get_heap_size(); }
/** @copydoc lt_heap_get_size() */
inline uint32_t getHeapSize() { return lt_heap_get_size(); }
/** @copydoc lt_get_heap_free() */
inline uint32_t getFreeHeap() { return lt_get_heap_free(); }
/** @copydoc lt_heap_get_free() */
inline uint32_t getFreeHeap() { return lt_heap_get_free(); }
/** @copydoc lt_get_heap_min_free() */
inline uint32_t getMinFreeHeap() { return lt_get_heap_min_free(); }
/** @copydoc lt_heap_get_min_free() */
inline uint32_t getMinFreeHeap() { return lt_heap_get_min_free(); }
/** @copydoc lt_get_heap_max_alloc() */
inline uint32_t getMaxAllocHeap() { return lt_get_heap_max_alloc(); }
/** @copydoc lt_heap_get_max_alloc() */
inline uint32_t getMaxAllocHeap() { return lt_heap_get_max_alloc(); }
/** @copydoc lt_get_heap_max_alloc() */
inline uint32_t getMaxFreeBlockSize() { return lt_get_heap_max_alloc(); }
/** @copydoc lt_heap_get_max_alloc() */
inline uint32_t getMaxFreeBlockSize() { return lt_heap_get_max_alloc(); }
};
extern LibreTuya LT;

View File

@@ -7,61 +7,61 @@
/**
* @brief Get CPU family ID (as lt_cpu_family_t enum member).
*/
lt_cpu_family_t lt_get_cpu_family();
lt_cpu_family_t lt_cpu_get_family();
/**
* @brief Get CPU family name as string.
*/
const char *lt_get_cpu_family_name();
const char *lt_cpu_get_family_name();
/**
* @brief Get CPU model ID (as lt_cpu_model_t enum member).
*/
lt_cpu_model_t lt_get_cpu_model();
lt_cpu_model_t lt_cpu_get_model();
/**
* @brief Get CPU model name as string (uppercase).
*/
const char *lt_get_cpu_model_name();
const char *lt_cpu_get_model_name();
/**
* @brief Get CPU model name as string (lowercase).
*/
const char *lt_get_cpu_model_code();
const char *lt_cpu_get_model_code();
/**
* @brief Get CPU unique ID. This may be based on MAC, eFuse, etc. (family-specific).
* Note: the number is 24-bit (with the MSB being zero).
*/
uint32_t lt_get_cpu_unique_id();
uint32_t lt_cpu_get_unique_id();
/**
* @brief Get CPU ID based on the last three octets of MAC address.
* Note: the number is 24-bit (with the MSB being zero).
*/
uint32_t lt_get_cpu_mac_id();
uint32_t lt_cpu_get_mac_id();
/**
* @brief Get CPU core count.
*/
uint8_t lt_get_cpu_core_count();
uint8_t lt_cpu_get_core_count();
/**
* @brief Get CPU core type name as string.
*/
const char *lt_get_cpu_core_type();
const char *lt_cpu_get_core_type();
/**
* @brief Get CPU frequency in Hz.
*/
uint32_t lt_get_cpu_freq();
uint32_t lt_cpu_get_freq();
/**
* @brief Get CPU frequency in MHz.
*/
uint32_t lt_get_cpu_freq_mhz();
uint32_t lt_cpu_get_freq_mhz();
/**
* @brief Get CPU cycle count.
*/
uint32_t lt_get_cpu_cycle_count();
uint32_t lt_cpu_get_cycle_count();

View File

@@ -7,24 +7,24 @@
/**
* @brief Get total RAM size.
*/
uint32_t lt_get_ram_size();
uint32_t lt_ram_get_size();
/**
* @brief Get total heap size.
*/
uint32_t lt_get_heap_size();
uint32_t lt_heap_get_size();
/**
* @brief Get free heap size.
*/
uint32_t lt_get_heap_free();
uint32_t lt_heap_get_free();
/**
* @brief Get lowest level of free heap memory.
*/
uint32_t lt_get_heap_min_free();
uint32_t lt_heap_get_min_free();
/**
* @brief Get largest block of heap that can be allocated at once.
*/
uint32_t lt_get_heap_max_alloc();
uint32_t lt_heap_get_max_alloc();

View File

@@ -15,42 +15,42 @@
| | | ___/| | | |
| |____| | | |__| |
\_____|_| \____*/
lt_cpu_family_t lt_get_cpu_family() {
lt_cpu_family_t lt_cpu_get_family() {
return FAMILY;
}
const char *lt_get_cpu_family_name() {
const char *lt_cpu_get_family_name() {
return STRINGIFY_MACRO(FAMILY) + 2;
}
__attribute__((weak)) lt_cpu_model_t lt_get_cpu_model() {
__attribute__((weak)) lt_cpu_model_t lt_cpu_get_model() {
return MCU;
}
const char *lt_get_cpu_model_name() {
const char *lt_cpu_get_model_name() {
return STRINGIFY_MACRO(MCU);
}
const char *lt_get_cpu_model_code() {
const char *lt_cpu_get_model_code() {
return STRINGIFY_MACRO(MCULC);
}
__attribute__((weak)) uint8_t lt_get_cpu_core_count() {
__attribute__((weak)) uint8_t lt_cpu_get_core_count() {
return 1;
}
#if LT_HAS_FREERTOS
__attribute__((weak)) uint32_t lt_get_cpu_freq() {
__attribute__((weak)) uint32_t lt_cpu_get_freq() {
return configCPU_CLOCK_HZ;
}
#endif
uint32_t lt_get_cpu_freq_mhz() {
return lt_get_cpu_freq() / 1000000;
uint32_t lt_cpu_get_freq_mhz() {
return lt_cpu_get_freq() / 1000000;
}
#if LT_HAS_FREERTOS
__attribute__((weak)) uint32_t lt_get_cpu_cycle_count() {
__attribute__((weak)) uint32_t lt_cpu_get_cycle_count() {
return xTaskGetTickCount() * (configCPU_CLOCK_HZ / configTICK_RATE_HZ);
}
#endif
@@ -74,10 +74,10 @@ const char *lt_get_board_code() {
const char *lt_get_device_name() {
if (device_name)
return device_name;
uint32_t chip_id = lt_get_cpu_mac_id();
uint32_t chip_id = lt_cpu_get_mac_id();
uint8_t *id = (uint8_t *)&chip_id;
const char *model = lt_get_cpu_model_code();
const char *model = lt_cpu_get_model_code();
uint8_t model_len = strlen(model);
device_name = (char *)malloc(3 + model_len + 1 + 6 + 1);
@@ -165,20 +165,20 @@ bool lt_flash_write(uint32_t offset, uint8_t *data, size_t length) {
__/ |
|__*/
#if LT_HAS_FREERTOS
__attribute__((weak)) uint32_t lt_get_heap_size() {
__attribute__((weak)) uint32_t lt_heap_get_size() {
return configTOTAL_HEAP_SIZE;
}
__attribute__((weak)) uint32_t lt_get_heap_free() {
__attribute__((weak)) uint32_t lt_heap_get_free() {
return xPortGetFreeHeapSize();
}
__attribute__((weak)) uint32_t lt_get_heap_min_free() {
__attribute__((weak)) uint32_t lt_heap_get_min_free() {
return xPortGetMinimumEverFreeHeapSize();
}
#endif
__attribute__((weak)) uint32_t lt_get_heap_max_alloc() {
__attribute__((weak)) uint32_t lt_heap_get_max_alloc() {
return 0;
}

View File

@@ -3,6 +3,6 @@
#include <Arduino.h>
#include <sdk_private.h>
uint32_t lt_get_cpu_cycle_count() {
uint32_t lt_cpu_get_cycle_count() {
return microsecondsToClockCycles(micros());
}

View File

@@ -21,17 +21,17 @@ void lt_init_family() {
| | | ___/| | | |
| |____| | | |__| |
\_____|_| \____*/
lt_cpu_model_t lt_get_cpu_model() {
lt_cpu_model_t lt_cpu_get_model() {
uint8_t chipId;
EFUSE_OneByteReadROM(9902, 0xF8, &chipId, L25EOUTVOLTAGE);
return CPU_MODEL_ENUM(FAMILY, chipId);
}
uint32_t lt_get_cpu_unique_id() {
return lt_get_cpu_mac_id();
uint32_t lt_cpu_get_unique_id() {
return lt_cpu_get_mac_id();
}
uint32_t lt_get_cpu_mac_id() {
uint32_t lt_cpu_get_mac_id() {
uint32_t chipId = 0;
uint8_t *id = (uint8_t *)&chipId;
// 9902 was extracted from ROM disassembly, probably not needed
@@ -47,11 +47,11 @@ uint32_t lt_get_cpu_mac_id() {
return chipId;
}
const char *lt_get_cpu_core_type() {
const char *lt_cpu_get_core_type() {
return "ARM Cortex-M4F";
}
uint32_t lt_get_cpu_freq() {
uint32_t lt_cpu_get_freq() {
return CPU_ClkGet(false);
}
@@ -112,7 +112,7 @@ lt_flash_id_t lt_flash_get_id() {
|_| |_|\___|_| |_| |_|\___/|_| \__, |
__/ |
|__*/
uint32_t lt_get_ram_size() {
uint32_t lt_ram_get_size() {
return 256 * 1024;
}