[realtek-ambz2] Add initial SDK fixups and API layer

This commit is contained in:
Kuba Szczodrzyński
2023-05-23 12:11:17 +02:00
parent 07e9aa1ded
commit 8c636e44f7
14 changed files with 91 additions and 41 deletions

View File

@@ -92,6 +92,7 @@ queue.AppendPublic(
"-Wl,-wrap,memset",
# TODO remove this if possible
"-Wl,-wrap,putc",
# rt_printf wrappers are not here, as they're just changing code using #defines
],
)
@@ -104,17 +105,6 @@ queue.AddLibrary(
# cmsis
"+<soc/realtek/8710c/cmsis/rtl8710c/source/ram/*.c>",
"+<soc/realtek/8710c/cmsis/rtl8710c/source/ram_s/app_start.c>",
# console
"+<common/api/at_cmd/atcmd_bt.c>",
"+<common/api/at_cmd/atcmd_lwip.c>",
"+<common/api/at_cmd/atcmd_mp_ext2.c>",
"+<common/api/at_cmd/atcmd_mp.c>",
"+<common/api/at_cmd/atcmd_sys.c>",
"+<common/api/at_cmd/atcmd_wifi.c>",
"+<common/api/at_cmd/log_service.c>",
"+<soc/realtek/8710c/app/shell/cmd_shell.c>",
"+<soc/realtek/8710c/app/shell/ram_s/consol_cmds.c>",
"+<soc/realtek/8710c/misc/driver/rtl_console.c>",
# utilities
"+<common/utilities/cJSON.c>",
"+<common/utilities/http_client.c>",
@@ -147,13 +137,9 @@ queue.AddLibrary(
"+<common/file_system/fatfs/r0.10c/src/ff.c>",
"+<common/file_system/fatfs/r0.10c/src/option/ccsbcs.c>",
"+<common/file_system/ftl/ftl.c>",
# TODO remove this
"+<common/example/example_entry.c>",
"+<common/example/wlan_fast_connect/example_wlan_fast_connect.c>",
],
includes=[
"+<$SDK_DIR/project/realtek_amebaz2_v0_example/inc>",
"+<common/api/at_cmd>",
"+<common/api/platform>",
"+<common/api>",
"+<common/application>",
@@ -175,7 +161,6 @@ queue.AddLibrary(
"+<os/freertos/freertos_v10.0.1/Source/portable/GCC/ARM_RTL8710C>",
"+<os/os_dep/include>",
"+<soc/realtek/8710c/app/rtl_printf/include>",
"+<soc/realtek/8710c/app/shell>",
"+<soc/realtek/8710c/app/stdio_port>",
"+<soc/realtek/8710c/cmsis/cmsis-core/include>",
"+<soc/realtek/8710c/cmsis/rtl8710c/include>",
@@ -286,6 +271,7 @@ queue.AddLibrary(
# "+<src/ble/profile/server/hids_rmc.c>",
"+<src/ble/profile/server/simple_ble_service.c>",
"+<src/mcu/module/data_uart_cmd/user_cmd_parse.c>",
"-<board/common/src/bt_uart_bridge.c>",
],
includes=[
"+<.>",

View File

@@ -16,7 +16,9 @@
#include <string.h>
#include "basic_types.h" // fixup: replaces typedef boolean for Arduino compatibility
#include "memproc.h" // fixup: redirects to stdlib
#include "strproc.h" // fixup: redirects to stdlib
#ifdef LT_RTL8710B
#include "memproc.h" // fixup: redirects to stdlib
#endif
#include "strproc.h" // fixup: redirects to stdlib
#include "diag.h"

View File

@@ -7,24 +7,26 @@
#define FLASH_ERASE_MIN_SIZE (4 * 1024)
static flash_t flash_obj;
static int init() {
flash_get_status(NULL);
flash_get_status(&flash_obj);
return 0;
}
static int read(long offset, uint8_t *buf, size_t size) {
return size * flash_stream_read(NULL, offset, size, buf);
return size * flash_stream_read(&flash_obj, offset, size, buf);
}
static int write(long offset, const uint8_t *buf, size_t size) {
return size * flash_stream_write(NULL, offset, size, (uint8_t *)buf);
return size * flash_stream_write(&flash_obj, offset, size, (uint8_t *)buf);
}
static int erase(long offset, size_t size) {
offset &= ~(FLASH_ERASE_MIN_SIZE - 1);
size = ((size - 1) / FLASH_ERASE_MIN_SIZE) + 1;
for (uint16_t i = 0; i < size; i++) {
flash_erase_sector(NULL, offset + i * FLASH_ERASE_MIN_SIZE);
flash_erase_sector(&flash_obj, offset + i * FLASH_ERASE_MIN_SIZE);
}
return size * FLASH_ERASE_MIN_SIZE;
}

View File

@@ -0,0 +1,19 @@
/* Copyright (c) Kuba Szczodrzyński 2023-05-23. */
#pragma once
#include_next "platform_conf.h"
#undef CONFIG_DEBUG_LOG
#undef CONFIG_DEBUG_ERROR
#undef CONFIG_DEBUG_WARN
#undef CONFIG_DEBUG_INFO
#define CONFIG_DEBUG_LOG 0
#define CONFIG_DEBUG_ERROR 0
#define CONFIG_DEBUG_WARN 0
#define CONFIG_DEBUG_INFO 0
// diag.h doesn't define this if CONFIG_DEBUG_LOG is 0
#define DBG_SCE_ERR(...)
#define DBG_SCE_WARN(...)
#define DBG_SCE_INFO(...)

View File

@@ -1,3 +1,7 @@
/* Copyright (c) Kuba Szczodrzyński 2023-04-12. */
void shell_cmd_init() {}
extern void lt_main();
void shell_cmd_init() {
lt_main();
}

View File

@@ -0,0 +1,10 @@
/* Copyright (c) Kuba Szczodrzyński 2023-05-23. */
// use platform_conf.h from realtek-ambz2/base/config
#include <platform_conf.h>
// use basic_types.h from realtek-amb/base/fixups
#include <basic_types.h>
// use basic_types.h from realtek-ambz2/base/fixups
#include "diag.h"
#include_next "cmsis.h"

View File

@@ -0,0 +1,19 @@
/* Copyright (c) Kuba Szczodrzyński 2023-05-23. */
// remove component/soc/realtek/8710c/app/rtl_printf/include/rt_printf.h
// replace with #defines below
#ifndef _RT_PRINTF__H
#define _RT_PRINTF__H
#endif
#undef log_printf
#include_next "diag.h"
#undef log_printf
#define rt_printf(...) __wrap_rt_printf(__VA_ARGS__)
#define rt_printfl(...) __wrap_rt_printf(__VA_ARGS__)
#define rt_sprintf(...) __wrap_rt_sprintf(__VA_ARGS__)
#define rt_sprintfl(...) __wrap_rt_sprintf(__VA_ARGS__)
#define rt_snprintf(...) __wrap_rt_snprintf(__VA_ARGS__)
#define rt_snprintfl(...) __wrap_rt_snprintf(__VA_ARGS__)
#define rt_log_printf(...) __wrap_rt_log_printf(__VA_ARGS__)

View File

@@ -0,0 +1,19 @@
/* Copyright (c) Kuba Szczodrzyński 2023-05-22. */
#include <libretiny.h>
#include <sdk_private.h>
extern uint8_t lt_uart_port;
void lt_init_family() {
// make the SDK less verbose by default
ConfigDebugErr = 0;
ConfigDebugWarn = 0;
ConfigDebugInfo = 0;
lt_uart_port = LT_UART_DEFAULT_PORT;
}
lt_reboot_reason_t lt_get_reboot_reason() {
// TODO
return REBOOT_REASON_UNKNOWN;
}

View File

@@ -19,20 +19,11 @@ void putchar_(char c) {
}
void putchar_p(char c, unsigned long port) {
// while (UART_Writable(uart_dev[port]) == 0) {}
while (uart_dev[port]->lsr_b.txfifo_empty == 0) {}
uart_dev[port]->thr = c;
}
WRAP_PRINTF(rtl_printf);
WRAP_SPRINTF(rtl_sprintf);
WRAP_SNPRINTF(rtl_snprintf);
WRAP_VSNPRINTF(rtl_vsnprintf);
WRAP_VSNPRINTF(rtl_vsnprintf_r);
WRAP_VPRINTF(rtl_vprintf);
WRAP_PRINTF(DiagPrintf);
WRAP_SPRINTF(DiagSPrintf);
WRAP_SNPRINTF(DiagSnPrintf);
WRAP_PRINTF(prvDiagPrintf);
WRAP_SPRINTF(prvDiagSPrintf);
WRAP_VSPRINTF(VSprintf);
WRAP_PRINTF(LOG_PRINTF);
WRAP_PRINTF(rt_printf);
WRAP_SPRINTF(rt_sprintf);
WRAP_SNPRINTF(rt_snprintf);
WRAP_PRINTF(rt_log_printf);

View File

@@ -8,10 +8,8 @@
extern "C" {
#endif // __cplusplus
WRAP_DISABLE_DEF(rtl_printf);
WRAP_DISABLE_DEF(DiagPrintf);
WRAP_DISABLE_DEF(prvDiagPrintf);
WRAP_DISABLE_DEF(LOG_PRINTF);
WRAP_DISABLE_DEF(rt_printf);
WRAP_DISABLE_DEF(rt_log_printf);
#ifdef __cplusplus
} // extern "C"