[realtek-ambz2] Implement base C API

This commit is contained in:
Kuba Szczodrzyński
2023-05-23 19:54:00 +02:00
parent 43c9d0db10
commit b073290989
16 changed files with 246 additions and 52 deletions

View File

@@ -15,7 +15,7 @@ const char *lt_get_version();
const char *lt_get_board_code();
/**
* @brief Get device friendly name in format "LT-<family code>-<MAC ID>".
* @brief Get device friendly name in format "LT-<chip model>-<MAC ID>".
* Can be used as hostname.
*/
const char *lt_get_device_name();

View File

@@ -35,6 +35,10 @@ const char *lt_cpu_get_model_code() {
return STRINGIFY_MACRO(MCULC);
}
__attribute__((weak)) uint32_t lt_cpu_get_unique_id() {
return lt_cpu_get_mac_id();
}
__attribute__((weak)) uint8_t lt_cpu_get_core_count() {
return 1;
}
@@ -85,6 +89,12 @@ const char *lt_get_device_name() {
return device_name;
}
__attribute__((weak)) void lt_reboot() {
// The Watchdog Way
lt_wdt_enable(1L);
while (1) {}
}
__attribute__((weak)) bool lt_reboot_wdt() {
if (!lt_wdt_enable(1L))
return false;
@@ -95,24 +105,30 @@ __attribute__((weak)) bool lt_reboot_download_mode() {
return false;
}
__attribute__((weak)) lt_reboot_reason_t lt_get_reboot_reason() {
return REBOOT_REASON_UNKNOWN;
}
const char *lt_get_reboot_reason_name(lt_reboot_reason_t reason) {
if (!reason)
reason = lt_get_reboot_reason();
switch (reason) {
case RESET_REASON_POWER:
case REBOOT_REASON_POWER:
return "Power-On";
case RESET_REASON_BROWNOUT:
case REBOOT_REASON_BROWNOUT:
return "Brownout";
case RESET_REASON_HARDWARE:
case REBOOT_REASON_HARDWARE:
return "HW Reboot";
case RESET_REASON_SOFTWARE:
case REBOOT_REASON_SOFTWARE:
return "SW Reboot";
case RESET_REASON_WATCHDOG:
case REBOOT_REASON_WATCHDOG:
return "WDT Reset";
case RESET_REASON_CRASH:
case REBOOT_REASON_CRASH:
return "Crash";
case RESET_REASON_SLEEP:
case REBOOT_REASON_SLEEP:
return "Sleep Wakeup";
case REBOOT_REASON_DEBUGGER:
return "Debugger";
default:
return "Unknown";
}

View File

@@ -20,7 +20,7 @@ int lt_main(void) {
// initialize C library
__libc_init_array();
// inform about the reset reason
LT_I("Reset reason: %u", lt_get_reboot_reason());
LT_I("Reset reason: %s", lt_get_reboot_reason_name(0));
// initialize FAL
fal_init();
// provide root partition

View File

@@ -40,8 +40,10 @@ typedef enum {
RTL8711BU = CPU_MODEL(F_RTL8710B, 0xFC), // CHIPID_8711BG / QFN68
MX1290 = RTL8710BN,
MX1290V2 = RTL8710BX,
// Realtek AmebaZ2
RTL8720CF = CPU_MODEL(F_RTL8720C, 0x00), // TODO
// Realtek AmebaZ2 (chip_id << 2 | flash_mode)
RTL8720CM = CPU_MODEL(F_RTL8720C, 0xEC), // 0xFB << 2 | 0
RTL8720CF = CPU_MODEL(F_RTL8720C, 0xED), // 0xFB << 2 | 1
RTL8720CX = RTL8720CM,
// Beken 72XX
BK7231T = CPU_MODEL(F_BK7231U, 0x1A), // *SCTRL_CHIP_ID = 0x7231a
BK7231N = CPU_MODEL(F_BK7231N, 0x1C), // *SCTRL_CHIP_ID = 0x7231c
@@ -63,7 +65,8 @@ typedef enum {
REBOOT_REASON_WATCHDOG = 6,
REBOOT_REASON_CRASH = 7,
REBOOT_REASON_SLEEP = 8,
REBOOT_REASON_MAX = 9,
REBOOT_REASON_DEBUGGER = 9,
REBOOT_REASON_MAX = 10,
} lt_reboot_reason_t;
/**