[core] Add lt_get_device_mac() function

This commit is contained in:
Kuba Szczodrzyński
2023-05-25 20:43:00 +02:00
parent 9b7d34fa65
commit 4dae304f51
7 changed files with 30 additions and 16 deletions

View File

@@ -29,12 +29,6 @@ lt_cpu_model_t lt_cpu_get_model() {
return CPU_MODEL_ENUM(FAMILY, chipId);
}
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_cpu_get_core_type() {
return "ARM968E-S";
}
@@ -45,6 +39,10 @@ const char *lt_cpu_get_core_type() {
| | | |/ _ \ \ / / |/ __/ _ \
| |__| | __/\ V /| | (_| __/
|_____/ \___| \_/ |_|\___\__*/
void lt_get_device_mac(uint8_t *mac) {
cfg_load_mac(mac);
}
void lt_reboot() {
bk_reboot();
}

View File

@@ -38,6 +38,7 @@ 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).
* The 3rd-to-last octet is least-significant, the last octet is most-significant.
*/
uint32_t lt_cpu_get_mac_id();

View File

@@ -20,6 +20,13 @@ const char *lt_get_board_code();
*/
const char *lt_get_device_name();
/**
* @brief Read device's *default* MAC address into 'mac' array.
* This can be used even without Wi-Fi enabled, and will ignore
* user-changed Wi-Fi MAC (if changing is possible).
*/
void lt_get_device_mac(uint8_t *mac);
/**
* @brief Reboot the CPU.
*/

View File

@@ -39,6 +39,12 @@ __attribute__((weak)) uint32_t lt_cpu_get_unique_id() {
return lt_cpu_get_mac_id();
}
__attribute__((weak)) uint32_t lt_cpu_get_mac_id() {
uint8_t mac[6];
lt_get_device_mac(mac);
return (mac[3] << 0) | (mac[4] << 8) | (mac[5] << 16);
}
__attribute__((weak)) uint8_t lt_cpu_get_core_count() {
return 1;
}

View File

@@ -158,10 +158,7 @@ IPAddress WiFiClass::localIP() {
uint8_t *WiFiClass::macAddress(uint8_t *mac) {
if ((getMode() & WIFI_MODE_STA) == 0) {
uint8_t *efuse = (uint8_t *)malloc(512);
EFUSE_LogicalMap_Read(efuse);
memcpy(mac, efuse + 0x11A, ETH_ALEN);
free(efuse);
lt_get_device_mac(mac);
return mac;
}
memcpy(mac, NETIF_RTW_STA.hwaddr, ETH_ALEN);

View File

@@ -57,6 +57,13 @@ uint32_t lt_cpu_get_freq() {
| | | |/ _ \ \ / / |/ __/ _ \
| |__| | __/\ V /| | (_| __/
|_____/ \___| \_/ |_|\___\__*/
void lt_get_device_mac(uint8_t *mac) {
uint8_t *efuse = (uint8_t *)malloc(512);
EFUSE_LogicalMap_Read(efuse);
memcpy(mac, efuse + 0x11A, 6);
free(efuse);
}
bool lt_reboot_download_mode() {
// mww 0x40000138 0x8
HAL_WRITE32(SYSTEM_CTRL_BASE, REG_SYS_NORESET_FF, 0x08);

View File

@@ -28,12 +28,6 @@ lt_cpu_model_t lt_cpu_get_model() {
return CPU_MODEL_ENUM(FAMILY, (chip_id & 0xFF) | flash_mode);
}
uint32_t lt_cpu_get_mac_id() {
uint8_t mac[3];
efuse_logical_read(0x11A + 3, 3, mac);
return (mac[0] << 0) | (mac[1] << 8) | (mac[2] << 16);
}
const char *lt_cpu_get_core_type() {
return "ARM Cortex-M4";
}
@@ -48,6 +42,10 @@ uint32_t lt_cpu_get_freq() {
| | | |/ _ \ \ / / |/ __/ _ \
| |__| | __/\ V /| | (_| __/
|_____/ \___| \_/ |_|\___\__*/
void lt_get_device_mac(uint8_t *mac) {
efuse_logical_read(0x11A, 6, mac);
}
void lt_reboot() {
sys_cpu_reset();
while (1) {}