diff --git a/TODO.md b/TODO.md index f6f7125..8b2d008 100644 --- a/TODO.md +++ b/TODO.md @@ -12,6 +12,7 @@ Explicit is better than implicit. - consider moving to C++17 (GNU)? or any newer than C++11 - wrap all memory management functions (malloc, calloc, free, memset, etc.) and their vendor SDK counterparts to use FreeRTOS instead +- remove all network protocol client/server implementations from SDKs (mDNS, HTTP, DNS, etc.) ### New families diff --git a/builder/family/realtek-ambz2.py b/builder/family/realtek-ambz2.py index b9b1730..73abb27 100644 --- a/builder/family/realtek-ambz2.py +++ b/builder/family/realtek-ambz2.py @@ -2,16 +2,20 @@ from os.path import join +from platformio.platform.base import PlatformBase from platformio.platform.board import PlatformBoardConfig from SCons.Script import DefaultEnvironment, Environment env: Environment = DefaultEnvironment() +platform: PlatformBase = env.PioPlatform() board: PlatformBoardConfig = env.BoardConfig() +queue = env.AddLibraryQueue("realtek-ambz2") +env.ConfigureFamily() COMPONENT_DIR = join("$SDK_DIR", "component") # Flags -env.Append( +queue.AppendPublic( CCFLAGS=[ "-march=armv8-m.main+dsp", "-mthumb", @@ -34,7 +38,6 @@ env.Append( "-std=gnu99", "-Wall", "-Wpointer-arith", - "-Wundef", "-Wno-write-strings", "-Wno-maybe-uninitialized", ], @@ -52,6 +55,14 @@ env.Append( ("CONFIG_BUILD_RAM", "1"), "V8M_STKOVF", ], + CPPPATH=[ + # allow including from GCC instead of RTL SDK + join( + platform.get_package_dir("toolchain-gccarmnoneeabi"), + "arm-none-eabi", + "include", + ), + ], LINKFLAGS=[ "-march=armv8-m.main+dsp", "-mthumb", @@ -68,54 +79,8 @@ env.Append( "-Wl,--cref", "-Wl,--build-id=none", "-Wl,--use-blx", + "-Wl,--undefined=gRamStartFun", "-Wl,-no-enum-size-warning", - # TODO fix wraps - "-Wl,-wrap,strcat", - "-Wl,-wrap,strchr", - "-Wl,-wrap,strcmp", - "-Wl,-wrap,strncmp", - "-Wl,-wrap,strnicmp", - "-Wl,-wrap,strcpy", - "-Wl,-wrap,strncpy", - "-Wl,-wrap,strlcpy", - "-Wl,-wrap,strlen", - "-Wl,-wrap,strnlen", - "-Wl,-wrap,strncat", - "-Wl,-wrap,strpbrk", - "-Wl,-wrap,strspn", - "-Wl,-wrap,strstr", - "-Wl,-wrap,strtok", - "-Wl,-wrap,strxfrm", - "-Wl,-wrap,strsep", - "-Wl,-wrap,strtod", - "-Wl,-wrap,strtof", - "-Wl,-wrap,strtold", - "-Wl,-wrap,strtoll", - "-Wl,-wrap,strtoul", - "-Wl,-wrap,strtoull", - "-Wl,-wrap,atoi", - "-Wl,-wrap,atoui", - "-Wl,-wrap,atol", - "-Wl,-wrap,atoul", - "-Wl,-wrap,atoull", - "-Wl,-wrap,atof", - "-Wl,-wrap,malloc", - "-Wl,-wrap,realloc", - "-Wl,-wrap,calloc", - "-Wl,-wrap,free", - "-Wl,-wrap,_malloc_r", - "-Wl,-wrap,_calloc_r", - "-Wl,-wrap,memcmp", - "-Wl,-wrap,memcpy", - "-Wl,-wrap,memmove", - "-Wl,-wrap,memset", - "-Wl,-wrap,printf", - "-Wl,-wrap,sprintf", - "-Wl,-wrap,puts", - "-Wl,-wrap,putc", - "-Wl,-wrap,putchar", - "-Wl,-wrap,snprintf", - "-Wl,-wrap,vsnprintf", "-Wl,-wrap,aesccmp_construct_mic_iv", "-Wl,-wrap,aesccmp_construct_mic_header1", "-Wl,-wrap,aesccmp_construct_ctr_preload", @@ -123,17 +88,52 @@ env.Append( "-Wl,-wrap,rom_psk_CalcPTK", "-Wl,-wrap,aes_80211_encrypt", "-Wl,-wrap,aes_80211_decrypt", + # stdlib wrappers + "-Wl,-wrap,strcat", + "-Wl,-wrap,strchr", + "-Wl,-wrap,strcmp", + "-Wl,-wrap,strncmp", + "-Wl,-wrap,strcpy", + "-Wl,-wrap,strncpy", + "-Wl,-wrap,strlen", + "-Wl,-wrap,strncat", + "-Wl,-wrap,strpbrk", + "-Wl,-wrap,strspn", + "-Wl,-wrap,strstr", + "-Wl,-wrap,strtok", + "-Wl,-wrap,strxfrm", + "-Wl,-wrap,strtod", + "-Wl,-wrap,strtof", + "-Wl,-wrap,strtold", + "-Wl,-wrap,strtoll", + "-Wl,-wrap,strtoul", + "-Wl,-wrap,strtoull", + "-Wl,-wrap,atoi", + "-Wl,-wrap,atol", + "-Wl,-wrap,atof", + "-Wl,-wrap,malloc", + "-Wl,-wrap,calloc", + "-Wl,-wrap,realloc", + "-Wl,-wrap,free", + "-Wl,-wrap,_malloc_r", + "-Wl,-wrap,_calloc_r", + "-Wl,-wrap,_realloc_r", + "-Wl,-wrap,_free_r", + "-Wl,-wrap,memcmp", + "-Wl,-wrap,memcpy", + "-Wl,-wrap,memmove", + "-Wl,-wrap,memset", + # TODO remove this if possible + "-Wl,-wrap,putc", ], ) # Sources - from SDK project/realtek_amebaz2_v0_example/GCC-RELEASE/application.is.mk # - without "utilities - example", "bluetooth - example" and "network - app - mqtt" -env.AddLibrary( +queue.AddLibrary( name="ambz2_sdk", base_dir=COMPONENT_DIR, srcs=[ - # libc api wrapper - "+", # cmsis "+", "+", @@ -219,14 +219,13 @@ env.AddLibrary( "+", "+", "+", - "+", + "+", ], options=dict( CCFLAGS=[ "-Wno-int-conversion", "-Wno-unused-label", "-Wno-unused-but-set-variable", - "-Wno-undef", "-Wno-pointer-sign", "-Wno-parentheses", "-Wno-implicit-function-declaration", @@ -239,7 +238,7 @@ env.AddLibrary( ) # Sources - network utilities -env.AddLibrary( +queue.AddLibrary( name="ambz2_net", base_dir=COMPONENT_DIR, srcs=[ @@ -305,7 +304,7 @@ env.AddLibrary( ) # Sources - Bluetooth support -env.AddLibrary( +queue.AddLibrary( name="ambz2_bluetooth", base_dir=join(COMPONENT_DIR, "common", "bluetooth", "realtek", "sdk"), srcs=[ @@ -350,7 +349,7 @@ env.AddLibrary( # Sources - lwIP 2.0.2 -env.AddLibrary( +queue.AddLibrary( name="ambz2_lwip", base_dir=join(COMPONENT_DIR, "common", "network", "lwip", "lwip_v2.0.2"), srcs=[ @@ -372,7 +371,7 @@ env.AddLibrary( ) # Sources - mbedTLS -env.AddLibrary( +queue.AddLibrary( name="ambz2_mbedtls", base_dir=join(COMPONENT_DIR, "common", "network", "ssl", "mbedtls-2.4.0"), srcs=[ @@ -428,7 +427,7 @@ env.AddLibrary( ) # Libs & linker config -env.Append( +queue.AppendPublic( LIBPATH=[ # fmt: off join(COMPONENT_DIR, "soc", "realtek", "8710c", "misc", "bsp", "lib", "common", "GCC"), @@ -465,7 +464,7 @@ env.Replace( ) # Build all libraries -env.BuildLibraries() +queue.BuildLibraries() # Main firmware outputs and actions env.Replace( diff --git a/builder/frameworks/base.py b/builder/frameworks/base.py index 2a32870..c8c2928 100644 --- a/builder/frameworks/base.py +++ b/builder/frameworks/base.py @@ -18,6 +18,14 @@ family: Family = env["FAMILY_OBJ"] # Move common core sources (env.AddCoreSources()) and Arduino libs # below per-family sources (to maintain child families taking precedence) +# Global flags (applying to the SDK) +env.Append( + CCFLAGS=[ + # Newer versions of GCC complain about undefined macros in #if + "-Wno-undef", + ], +) + # Include SDK builder scripts # No environment options that follow later will be considered found = False diff --git a/cores/realtek-amb/base/sdk_private.h b/cores/realtek-amb/base/sdk_private.h index 5f2989d..f582d4a 100644 --- a/cores/realtek-amb/base/sdk_private.h +++ b/cores/realtek-amb/base/sdk_private.h @@ -23,7 +23,17 @@ extern "C" { #undef strtol #undef strtoul +#if LT_RTL8710B #include +#include +#include +#include +#include +#endif +#if LT_RTL8720C +#include +#endif + #include #include #include @@ -35,10 +45,6 @@ extern "C" { #include #include #include -#include -#include -#include -#include #include #include #include @@ -57,6 +63,8 @@ extern "C" { #undef vsnprintf #undef vprintf #include +// conflict with lt_logger.h +#undef log_printf // moved from syscalls.h #define _close __rtl_close diff --git a/cores/realtek-ambz2/base/config/platform_opts.h b/cores/realtek-ambz2/base/config/platform_opts.h deleted file mode 100644 index 66e08cc..0000000 --- a/cores/realtek-ambz2/base/config/platform_opts.h +++ /dev/null @@ -1,406 +0,0 @@ -/** - ****************************************************************************** - *This file contains general configurations for ameba platform - ****************************************************************************** - */ - -#ifndef __PLATFORM_OPTS_H__ -#define __PLATFORM_OPTS_H__ - -/*For MP mode setting*/ -#define SUPPORT_MP_MODE 1 - -/** - * For AT cmd Log service configurations - */ -#define SUPPORT_LOG_SERVICE 1 -#if SUPPORT_LOG_SERVICE -#define LOG_SERVICE_BUFLEN 100 // can't larger than UART_LOG_CMD_BUFLEN(127) -#define CONFIG_LOG_HISTORY 0 -#if CONFIG_LOG_HISTORY -#define LOG_HISTORY_LEN 5 -#endif -#define SUPPORT_INTERACTIVE_MODE 0 // on/off wifi_interactive_mode -#define CONFIG_LOG_SERVICE_LOCK 0 -#define CONFIG_ATCMD_MP 0 // support MP AT command -#define USE_MODE 1 // for test -#endif - -/** - * For interactive mode configurations, depends on log service - */ -#if defined(SUPPORT_INTERACTIVE_MODE) && SUPPORT_INTERACTIVE_MODE -#define CONFIG_INTERACTIVE_MODE 1 -#define CONFIG_INTERACTIVE_EXT 0 -#else -#define CONFIG_INTERACTIVE_MODE 0 -#define CONFIG_INTERACTIVE_EXT 0 -#endif - -/** - * For FreeRTOS tickless configurations - */ -#define FREERTOS_PMU_TICKLESS_PLL_RESERVED 0 // In sleep mode, 0: close PLL clock, 1: reserve PLL clock -#define FREERTOS_PMU_TICKLESS_SUSPEND_SDRAM 1 // In sleep mode, 1: suspend SDRAM, 0: no act - -/******************************************************************************/ - -/** - * For common flash usage - */ -#define FLASH_BAKEUP_SECTOR (0x3000) -#define FAST_RECONNECT_DATA (0x200000 - 0x1000) -#define BT_FTL_PHY_ADDR0 (0x200000 - 0x2000) -#define BT_FTL_PHY_ADDR1 (0x200000 - 0x3000) -#define BT_FTL_BKUP_ADDR (0x200000 - 0x4000) -#define UART_SETTING_SECTOR (0x200000 - 0x5000) -#define DCT_BEGIN_ADDR \ - (0x200000 - 0x29000) /*!< DCT begin address of flash, ex: 0x200000 = 2M, the default size of DCT is 24K; ; if \ - backup enabled, the size is 48k; if wear leveling enabled, the size is 144k*/ -#define FLASH_APP_BASE \ - (0x200000 - 0xA9000 \ - ) /*!< FATFS begin address, default size used is 512KB (can be adjusted based on user requirement)*/ -#define BT_WHITELIST_BASE_1 (0x200000 - 0xA000) -#define BT_WHITELIST_PAGE_SIZE (0x1000) -#define BT_WHITELIST_BASE_2 (BT_WHITELIST_BASE_1 + BT_WHITELIST_PAGE_SIZE) -/** - * For Wlan configurations - */ -#define CONFIG_WLAN 1 -#if CONFIG_WLAN -#define CONFIG_LWIP_LAYER 1 -#define CONFIG_INIT_NET 1 // init lwip layer when start up -#define CONFIG_WIFI_IND_USE_THREAD 0 // wifi indicate worker thread -#define CONFIG_ENABLE_AP_POLLING_CLIENT_ALIVE 0 // on or off AP POLLING CLIENT - -// on/off relative commands in log service -#define CONFIG_SSL_CLIENT 0 -#define CONFIG_OTA_UPDATE 1 -#define CONFIG_BSD_TCP 0 // NOTE : Enable CONFIG_BSD_TCP will increase about 11KB code size -#define CONFIG_AIRKISS 0 // on or off tencent airkiss -#define CONFIG_UART_SOCKET 0 -#define CONFIG_JD_SMART 0 // on or off for jdsmart -#define CONFIG_JOYLINK 0 // on or off for jdsmart2.0 -#define CONFIG_QQ_LINK 0 // on or off for qqlink -#define CONFIG_AIRKISS_CLOUD 0 // on or off for weixin hardware cloud -#define CONFIG_UART_YMODEM 0 // support uart ymodem upgrade or not -#define CONFIG_TRANSPORT 0 // on or off the at command for transport socket -#define CONFIG_ALINK 0 // on or off for alibaba alink -#define CONFIG_MIIO 0 // on or off for alibaba alink -#define CONFIG_RIC 0 // on or off for RICloud -#define CONFIG_LINKKIT_AWSS 0 // on or off for ali feiyan cloud - -/* For WPS and P2P */ -#define CONFIG_ENABLE_WPS 0 -#define CONFIG_ENABLE_P2P 0 -#if CONFIG_ENABLE_WPS -#define CONFIG_ENABLE_WPS_DISCOVERY 1 -#endif -#if CONFIG_ENABLE_P2P -#define CONFIG_ENABLE_WPS_AP 1 -#undef CONFIG_WIFI_IND_USE_THREAD -#define CONFIG_WIFI_IND_USE_THREAD 1 -#endif -#if (CONFIG_ENABLE_P2P && ((CONFIG_ENABLE_WPS_AP == 0) || (CONFIG_ENABLE_WPS == 0))) -#error "If CONFIG_ENABLE_P2P, need to define CONFIG_ENABLE_WPS_AP 1" -#endif - -/* For Simple Link */ -#define CONFIG_INCLUDE_SIMPLE_CONFIG 1 -#define CONFIG_INCLUDE_DPP_CONFIG 0 -/*For fast reconnection*/ -#ifdef PLATFORM_OHOS -#define CONFIG_EXAMPLE_WLAN_FAST_CONNECT 0 -#else -#define CONFIG_EXAMPLE_WLAN_FAST_CONNECT 1 -#endif -#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT -#define CONFIG_FAST_DHCP 1 -#else -#define CONFIG_FAST_DHCP 0 -#endif - -/*For wowlan service settings*/ -#define CONFIG_WOWLAN_SERVICE 0 - -#define CONFIG_GAGENT 0 -/*Disable CONFIG_EXAMPLE_WLAN_FAST_CONNECT when CONFIG_GAGENT is enabled,because - reconnect to previous AP is not suitable when re-configuration. -*/ -#if CONFIG_GAGENT -#define CONFIG_EXAMPLE_WLAN_FAST_CONNECT 0 -#endif - -#endif // end of #if CONFIG_WLAN -/*******************************************************************************/ - -/* For SSL/TLS */ -#define CONFIG_USE_POLARSSL 0 // polarssl is no longer suppported for AmebaZ2 -#define CONFIG_USE_MBEDTLS 1 -#if ((CONFIG_USE_POLARSSL == 0) && (CONFIG_USE_MBEDTLS == 0)) || \ - ((CONFIG_USE_POLARSSL == 1) && (CONFIG_USE_MBEDTLS == 1)) -#undef CONFIG_USE_POLARSSL -#define CONFIG_USE_POLARSSL 1 -#undef CONFIG_USE_MBEDTLS -#define CONFIG_USE_MBEDTLS 0 -#endif -#define CONFIG_SSL_CLIENT_PRIVATE_IN_TZ 1 - -/* For LWIP configuration */ -#define CONFIG_LWIP_DHCP_COARSE_TIMER 60 - -/*Enable CONFIG_LWIP_DHCP_FINE_TIMEOUT if lease time is less than or equal to CONFIG_LWIP_DHCP_COARSE_TIMER - * replace dhcp_coarse_tmr with dhcp_fine_tmr to manage and check for lease timeout - */ -#define CONFIG_LWIP_DHCP_FINE_TIMEOUT 0 - -/** - * For Ethernet configurations - */ -#define CONFIG_ETHERNET 0 -#if CONFIG_ETHERNET - -#define CONFIG_LWIP_LAYER 1 -#define CONFIG_INIT_NET 1 // init lwip layer when start up - -// on/off relative commands in log service -#define CONFIG_SSL_CLIENT 0 -#define CONFIG_BSD_TCP 0 // NOTE : Enable CONFIG_BSD_TCP will increase about 11KB code size - -#endif - -/* For Azure Examples */ -#define CONFIG_USE_AZURE_EMBEDDED_C 1 -#if CONFIG_USE_AZURE_EMBEDDED_C -/* For Azure embedded iot examples*/ -#define CONFIG_EXAMPLE_AZURE 0 -#if CONFIG_EXAMPLE_AZURE -#undef WAIT_FOR_ACK -#define WAIT_FOR_ACK -#endif -#else -/* For Azure iot hub telemetry example*/ -#define CONFIG_EXAMPLE_AZURE_IOTHUB_TELEMETRY 0 -/* For Azure iot hub x509 example*/ -#define CONFIG_EXAMPLE_AZURE_IOTHUB_X509 0 -#endif - -/* for CoAP example*/ -#define CONFIG_EXAMPLE_COAP 0 - -/* for lib CoAP example*/ -#define CONFIG_EXAMPLE_COAP_SERVER 0 -#define CONFIG_EXAMPLE_COAP_CLIENT 0 - -/* For WIFI GET BEACON FRAME example */ -#define CONFIG_EXAMPLE_GET_BEACON_FRAME 0 - -/* For WIFI MAC MONITOR example */ -#define CONFIG_EXAMPLE_WIFI_MAC_MONITOR 0 - -/* For HTTP CLIENT example */ -#define CONFIG_EXAMPLE_HTTP_CLIENT 0 - -/* For MQTT example */ -#define CONFIG_EXAMPLE_MQTT 0 - -/* For multicast example */ -#define CONFIG_EXAMPLE_MCAST 0 - -/* For XML example */ -#define CONFIG_EXAMPLE_XML 0 - -/* For JSON example */ -#define CONFIG_EXAMPLE_CJSON 0 - -/* For socket select example */ -#define CONFIG_EXAMPLE_SOCKET_SELECT 0 - -/* For socket nonblocking connect example */ -#define CONFIG_EXAMPLE_NONBLOCK_CONNECT 0 - -/* For socket TCP bidirectional transmission example */ -#define CONFIG_EXAMPLE_SOCKET_TCP_TRX 0 - -/* For ssl download example */ -#define CONFIG_EXAMPLE_SSL_DOWNLOAD 0 - -/* For http download example */ -#define CONFIG_EXAMPLE_HTTP_DOWNLOAD 0 - -/* For httpc example */ -#define CONFIG_EXAMPLE_HTTPC 0 - -/* For Amazon ffs example */ -#define CONFIG_EXAMPLE_FFS 0 -#if CONFIG_EXAMPLE_FFS -#undef CONFIG_EXAMPLE_WLAN_FAST_CONNECT -#define CONFIG_EXAMPLE_WLAN_FAST_CONNECT 0 -#undef CONFIG_FAST_DHCP -#define CONFIG_FAST_DHCP 0 -#endif - -/* For httpd example */ -#define CONFIG_EXAMPLE_HTTPD 0 - -/* For tcp keepalive example */ -#define CONFIG_EXAMPLE_TCP_KEEPALIVE 0 - -/* For sntp show time example */ -#define CONFIG_EXAMPLE_SNTP_SHOWTIME 0 - -/* For websocket client example */ -#define CONFIG_EXAMPLE_WEBSOCKET_CLIENT 0 - -/* For DCT example*/ -#define CONFIG_EXAMPLE_DCT 0 - -/****************** For EAP method example *******************/ -#define CONFIG_EXAMPLE_EAP 0 - -// on/off specified eap method -#define CONFIG_ENABLE_PEAP 0 -#define CONFIG_ENABLE_TLS 0 -#define CONFIG_ENABLE_TTLS 0 - -// optional feature: whether to verify the cert of radius server -#define ENABLE_EAP_SSL_VERIFY_SERVER 0 - -#if CONFIG_ENABLE_PEAP || CONFIG_ENABLE_TLS || CONFIG_ENABLE_TTLS -#define CONFIG_ENABLE_EAP -#undef CONFIG_EXAMPLE_WLAN_FAST_CONNECT -#undef CONFIG_FAST_DHCP -#define CONFIG_EXAMPLE_WLAN_FAST_CONNECT 0 -#define CONFIG_FAST_DHCP 0 -#endif - -#if CONFIG_ENABLE_TLS -#define ENABLE_EAP_SSL_VERIFY_CLIENT 1 -#else -#define ENABLE_EAP_SSL_VERIFY_CLIENT 0 -#endif -/******************End of EAP configurations*******************/ - -/* For FATFS example*/ -#define CONFIG_EXAMPLE_FATFS 0 -#if CONFIG_EXAMPLE_FATFS -#define CONFIG_FATFS_EN 1 -#if CONFIG_FATFS_EN -// fatfs version -#define FATFS_R_10C -// fatfs disk interface -#define FATFS_DISK_USB 0 -#define FATFS_DISK_SD 0 -#define FATFS_DISK_FLASH 1 -#endif -#endif - -/* For iNIC host example*/ -#ifdef CONFIG_INIC_GSPI_HOST // this flag is defined in IAR project -#define CONFIG_EXAMPLE_INIC_GSPI_HOST 1 -#if CONFIG_EXAMPLE_INIC_GSPI_HOST - -#define CONFIG_INIC_HOST 1 - -#undef CONFIG_WLAN -#define CONFIG_WLAN 0 -#undef CONFIG_INCLUDE_SIMPLE_CONFIG -#define CONFIG_INCLUDE_SIMPLE_CONFIG 0 -#undef CONFIG_EXAMPLE_WLAN_FAST_CONNECT -#define CONFIG_EXAMPLE_WLAN_FAST_CONNECT 0 -#undef CONFIG_LWIP_LAYER -#define CONFIG_LWIP_LAYER 1 -#undef CONFIG_BSD_TCP -#define CONFIG_BSD_TCP 1 - -#endif -#endif - -/* For wifi scenarios example (Wi-Fi, WPS enrollee, P2P GO) */ -// also need to enable WPS and P2P -#define CONFIG_EXAMPLE_WLAN_SCENARIO 0 - -/* For broadcast example */ -#define CONFIG_EXAMPLE_BCAST 0 - -/* For high-load memory use case memory usage */ -#define CONFIG_EXAMPLE_HIGH_LOAD_MEMORY_USE 0 - -/* For rarp example */ -#define CONFIG_EXAMPLE_RARP 0 - -/* For ssl server example */ -#define CONFIG_EXAMPLE_SSL_SERVER 0 - -/*For secure boot example */ -#define CONFIG_EXAMPLE_SECURE_BOOT 0 - -/*For secure storage example */ -#define CONFIG_EXAMPLE_SECURE_STORAGE 0 - -/* For ota update http example */ -#define CONFIG_EXAMPLE_OTA_HTTP 0 - -/*For wifi roaming example*/ -#define CONFIG_EXAMPLE_WIFI_ROAMING 0 - -/* for tickless roaming */ -#define CONFIG_EXAMPLE_TICKLESS_WIFI_ROAMING 0 - -/*For ipv6 example*/ -#define CONFIG_EXAMPLE_IPV6 0 - -#if CONFIG_ENABLE_WPS -#define WPS_CONNECT_RETRY_COUNT 4 -#define WPS_CONNECT_RETRY_INTERVAL 5000 // in ms -#endif - -#define AUTO_RECONNECT_COUNT 8 -#define AUTO_RECONNECT_INTERVAL 5 // in sec - -/*For trust zone example */ -#define CONFIG_EXAMPLE_TRUST_ZONE 0 - -/* For Amazon FreeRTOS SDK example */ -#define CONFIG_EXAMPLE_AMAZON_FREERTOS 0 - -#define CONFIG_EXAMPLE_AMAZON_AFQP_TESTS 0 - -#if (defined(CONFIG_EXAMPLE_AMAZON_FREERTOS) && CONFIG_EXAMPLE_AMAZON_FREERTOS) || \ - (defined(CONFIG_EXAMPLE_AMAZON_AFQP_TESTS) && CONFIG_EXAMPLE_AMAZON_AFQP_TESTS) -#undef CONFIG_INCLUDE_SIMPLE_CONFIG -#undef CONFIG_EXAMPLE_WLAN_FAST_CONNECT -#undef CONFIG_FAST_DHCP -#define CONFIG_INCLUDE_SIMPLE_CONFIG 0 -#define CONFIG_EXAMPLE_WLAN_FAST_CONNECT 0 -#define CONFIG_FAST_DHCP 0 -#if defined(CONFIG_BUILD_SECURE) -#define ENABLE_AMAZON_COMMON -#endif -#if defined(CONFIG_BUILD_NONSECURE) && (CONFIG_SSL_CLIENT_PRIVATE_IN_TZ == 0) -#undef SUPPORT_LOG_SERVICE -#define SUPPORT_LOG_SERVICE 0 -#endif -#endif - -/* For UART Module AT command example */ -#define CONFIG_EXAMPLE_UART_ATCMD 0 -#if (defined(CONFIG_EXAMPLE_UART_ATCMD) && CONFIG_EXAMPLE_UART_ATCMD) -#define UART_SETTING_BACKUP_SECTOR (FLASH_BAKEUP_SECTOR) -#undef CONFIG_OTA_UPDATE -#define CONFIG_OTA_UPDATE 1 -#undef CONFIG_TRANSPORT -#define CONFIG_TRANSPORT 1 -#undef LOG_SERVICE_BUFLEN -#define LOG_SERVICE_BUFLEN 1600 -#undef CONFIG_LOG_SERVICE_LOCK -#define CONFIG_LOG_SERVICE_LOCK 1 -#undef CONFIG_EXAMPLE_WLAN_FAST_CONNECT -#define CONFIG_EXAMPLE_WLAN_FAST_CONNECT 0 -#endif - -#if (SUPPORT_MP_MODE && CONFIG_MIIO) -#define CONFIG_MIIO_MP 0 // miio mp test and rw private data -#endif - -#endif diff --git a/cores/realtek-ambz2/base/config/platform_opts_bt.h b/cores/realtek-ambz2/base/config/platform_opts_bt.h deleted file mode 100644 index 06d2278..0000000 --- a/cores/realtek-ambz2/base/config/platform_opts_bt.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef __PLATFORM_OPTS_BT_H__ -#define __PLATFORM_OPTS_BT_H__ - -#define CONFIG_BT 0 - -#if CONFIG_BT -#define CONFIG_FTL_ENABLED -#define CONFIG_BT_CONFIG 0 -#define CONFIG_BT_AIRSYNC_CONFIG 0 -#define CONFIG_BT_PERIPHERAL 0 -#define CONFIG_BT_CENTRAL 0 -#define CONFIG_BT_SCATTERNET 0 -#define CONFIG_BT_BEACON 0 -#define CONFIG_BT_FUZZ_TEST 0 -#define CONFIG_BT_OTA_CENTRAL_CLIENT 0 -#define CONFIG_BT_DATATRANS 0 -#define CONFIG_BT_MESH_PROVISIONER 0 -#define CONFIG_BT_MESH_DEVICE 0 -#define CONFIG_BT_MESH_PROVISIONER_MULTIPLE_PROFILE 0 -#define CONFIG_BT_MESH_DEVICE_MULTIPLE_PROFILE 0 -#define CONFIG_BT_MESH_CENTRAL 0 -#define CONFIG_BT_MESH_PERIPHERAL 0 -#define CONFIG_BT_MESH_SCATTERNET 0 -#define CONFIG_BT_MESH_PROVISIONER_RTK_DEMO 0 -#define CONFIG_BT_MESH_DEVICE_RTK_DEMO 0 -#define CONFIG_BT_MESH_TEST 0 -#define CONFIG_BT_ONLY_WITHOUT_WLAN 0 -#endif // CONFIG_BT - -#if defined CONFIG_BT_SCATTERNET && CONFIG_BT_SCATTERNET -#undef CONFIG_BT_PERIPHERAL -#undef CONFIG_BT_CENTRAL -#define CONFIG_BT_PERIPHERAL 1 -#define CONFIG_BT_CENTRAL 1 -#endif - -#if defined CONFIG_BT_CENTRAL && CONFIG_BT_CENTRAL -#define CONFIG_BT_USER_COMMAND 0 -#define CONFIG_BT_WHITE_LIST_TO_FLASH 0 -#endif - -#if defined CONFIG_BT_OTA_CENTRAL_CLIENT && CONFIG_BT_OTA_CENTRAL_CLIENT -#define CONFIG_BT_OTA_CENTRAL_CLIENT_SPLIT 0 -#endif - -#if ((defined CONFIG_BT_MESH_PROVISIONER && CONFIG_BT_MESH_PROVISIONER) || (defined CONFIG_BT_MESH_DEVICE && CONFIG_BT_MESH_DEVICE) || (defined CONFIG_BT_MESH_PROVISIONER_MULTIPLE_PROFILE && CONFIG_BT_MESH_PROVISIONER_MULTIPLE_PROFILE) || (defined CONFIG_BT_MESH_DEVICE_MULTIPLE_PROFILE && CONFIG_BT_MESH_DEVICE_MULTIPLE_PROFILE)) -#define CONFIG_BT_MESH_USER_API 1 -#define CONFIG_BT_MESH_IDLE_CHECK 0 -#endif - -#if defined CONFIG_BT_MESH_PROVISIONER_RTK_DEMO && CONFIG_BT_MESH_PROVISIONER_RTK_DEMO -#undef CONFIG_BT_CONFIG -#define CONFIG_BT_CONFIG 1 -#endif - -#if ((defined CONFIG_BT_MESH_PROVISIONER && CONFIG_BT_MESH_PROVISIONER) && (defined CONFIG_BT_MESH_DEVICE && CONFIG_BT_MESH_DEVICE)) -#error "CONFIG_BT_MESH_PROVISIONER & CONFIG_BT_MESH_DEVICE can not open at the same time" -#endif - -#if ((defined CONFIG_BT_MESH_PROVISIONER_MULTIPLE_PROFILE && CONFIG_BT_MESH_PROVISIONER_MULTIPLE_PROFILE) && (defined CONFIG_BT_MESH_DEVICE_MULTIPLE_PROFILE && CONFIG_BT_MESH_DEVICE_MULTIPLE_PROFILE)) -#error \ - "CONFIG_BT_MESH_PROVISIONER_MULTIPLE_PROFILE & CONFIG_BT_MESH_DEVICE_MULTIPLE_PROFILE can not open at the same time" -#endif - -#if (((defined CONFIG_BT_MESH_CENTRAL && CONFIG_BT_MESH_CENTRAL) && (defined CONFIG_BT_MESH_PERIPHERAL && CONFIG_BT_MESH_PERIPHERAL)) || ((defined CONFIG_BT_MESH_CENTRAL && CONFIG_BT_MESH_CENTRAL) && (defined CONFIG_BT_MESH_SCATTERNET && CONFIG_BT_MESH_SCATTERNET)) || ((defined CONFIG_BT_MESH_PERIPHERAL && CONFIG_BT_MESH_PERIPHERAL) && (defined CONFIG_BT_MESH_SCATTERNET && CONFIG_BT_MESH_SCATTERNET)) || ((defined CONFIG_BT_MESH_CENTRAL && CONFIG_BT_MESH_CENTRAL) && (defined CONFIG_BT_MESH_PERIPHERAL && CONFIG_BT_MESH_PERIPHERAL) && (defined CONFIG_BT_MESH_SCATTERNET && CONFIG_BT_MESH_SCATTERNET))) -#error "Only one of CONFIG_BT_MESH_CENTRAL, CONFIG_BT_MESH_PERIPHERAL and CONFIG_BT_MESH_SCATTERNET can be enabled" -#endif - -#endif // __PLATFORM_OPTS_BT_H__ diff --git a/cores/realtek-ambz2/base/fixups/memory.c b/cores/realtek-ambz2/base/fixups/memory.c new file mode 100644 index 0000000..373037c --- /dev/null +++ b/cores/realtek-ambz2/base/fixups/memory.c @@ -0,0 +1,32 @@ +/* Copyright (c) Kuba Szczodrzyński 2023-03-03. */ + +#include +#include +#include +#include + +#include +#include +#include + +int __wrap_memcmp(const void *av, const void *bv, size_t len) { + return utility_stubs.memcmp(av, bv, len); +} + +void *__wrap_memcpy(void *s1, const void *s2, size_t n) { + return utility_stubs.memcpy(s1, s2, n); +} + +void *__wrap_memmove(void *destaddr, const void *sourceaddr, unsigned length) { + return utility_stubs.memmove(destaddr, sourceaddr, length); +} + +void *__wrap_memset(void *dst0, int val, size_t length) { + return utility_stubs.memset(dst0, val, length); +} + +#if (CHIP_VER >= CHIP_B_CUT) +int __wrap_memcmp_s(const void *av, const void *bv, size_t len) { + return utility_stubs.memcmp_s(av, bv, len); +} +#endif diff --git a/cores/realtek-ambz2/base/fixups/memory.h b/cores/realtek-ambz2/base/fixups/memory.h new file mode 100644 index 0000000..be63e14 --- /dev/null +++ b/cores/realtek-ambz2/base/fixups/memory.h @@ -0,0 +1,17 @@ +/* Copyright (c) Kuba Szczodrzyński 2023-03-03. */ + +#pragma once + +// Remove SDK definitions of memory utilities. +// Include stdlib versions instead. +// Wrapper functions for the removed prototypes are provided in memory.c. + +#include +#include +#include + +// Map SDK functions so that they point to stdlib again +#define rt_memcmp memcmp +#define rt_memcpy memcpy +#define rt_memmove memmove +#define rt_memset memset diff --git a/cores/realtek-ambz2/base/fixups/strproc.c b/cores/realtek-ambz2/base/fixups/strproc.c new file mode 100644 index 0000000..18d9de8 --- /dev/null +++ b/cores/realtek-ambz2/base/fixups/strproc.c @@ -0,0 +1,168 @@ +/* Copyright (c) Kuba Szczodrzyński 2023-03-03. */ + +#include +#include +#include +#include +#include + +typedef struct strproc_func_stubs_s { + char *(*strcat)(char *dest, const char *src); + char *(*strchr)(const char *s, int c); + int (*strcmp)(const char *cs, const char *ct); + int (*strncmp)(const char *cs, const char *ct, size_t count); + int (*strnicmp)(const char *s1, const char *s2, size_t len); + char *(*strcpy)(char *dest, const char *src); + char *(*strncpy)(char *dest, const char *src, size_t count); + size_t (*strlcpy)(char *dst, const char *src, size_t s); + size_t (*strlen)(const char *s); + size_t (*strnlen)(const char *s, size_t count); + char *(*strncat)(char *dest, const char *src, size_t count); + char *(*strpbrk)(const char *cs, const char *ct); + size_t (*strspn)(const char *s, const char *accept); + char *(*strstr)(const char *s1, const char *s2); + char *(*strtok)(char *s, const char *ct); + size_t (*strxfrm)(char *dest, const char *src, size_t n); + char *(*strsep)(char **s, const char *ct); + double (*strtod)(const char *str, char **endptr); + float (*strtof)(const char *str, char **endptr); + long double (*strtold)(const char *str, char **endptr); + long (*strtol)(const char *nptr, char **endptr, int base); + long long (*strtoll)(const char *nptr, char **endptr, int base); + unsigned long (*strtoul)(const char *nptr, char **endptr, int base); + unsigned long long (*strtoull)(const char *nptr, char **endptr, int base); + int (*atoi)(const char *num); + unsigned int (*atoui)(const char *num); + long (*atol)(const char *num); + unsigned long (*atoul)(const char *num); + unsigned long long (*atoull)(const char *num); + double (*atof)(const char *str); + + uint32_t reserved[16]; // reserved space for next ROM code version function table extending. +} strproc_func_stubs_t; + +extern const strproc_func_stubs_t strproc_stubs; + +// Wrappers + +char *__wrap_strcat(char *dest, const char *src) { + return strproc_stubs.strcat(dest, src); +} + +char *__wrap_strchr(const char *s, int c) { + return strproc_stubs.strchr(s, c); +} + +int __wrap_strcmp(const char *cs, const char *ct) { + return strproc_stubs.strcmp(cs, ct); +} + +int __wrap_strncmp(const char *cs, const char *ct, size_t count) { + return strproc_stubs.strncmp(cs, ct, count); +} + +char *__wrap_strcpy(char *dest, const char *src) { + return strproc_stubs.strcpy(dest, src); +} + +char *__wrap_strncpy(char *dest, const char *src, size_t count) { + return strproc_stubs.strncpy(dest, src, count); +} + +size_t __wrap_strlen(const char *s) { + return strproc_stubs.strlen(s); +} + +char *__wrap_strncat(char *dest, const char *src, size_t count) { + return strproc_stubs.strncat(dest, src, count); +} + +char *__wrap_strpbrk(const char *cs, const char *ct) { + return strproc_stubs.strpbrk(cs, ct); +} + +size_t __wrap_strspn(const char *s, const char *accept) { + return strproc_stubs.strspn(s, accept); +} + +char *__wrap_strstr(const char *s1, const char *s2) { + return strproc_stubs.strstr(s1, s2); +} + +char *__wrap_strtok(char *s, const char *ct) { + return strproc_stubs.strtok(s, ct); +} + +size_t __wrap_strxfrm(char *dest, const char *src, size_t n) { + return strproc_stubs.strxfrm(dest, src, n); +} + +double __wrap_strtod(const char *str, char **endptr) { + return strproc_stubs.strtod(str, endptr); +} + +float __wrap_strtof(const char *str, char **endptr) { + return strproc_stubs.strtof(str, endptr); +} + +long double __wrap_strtold(const char *str, char **endptr) { + return strproc_stubs.strtold(str, endptr); +} + +double __wrap_atof(const char *str) { + return strproc_stubs.atof(str); +} + +long __wrap_strtol(const char *nptr, char **endptr, int base) { + return strproc_stubs.strtol(nptr, endptr, base); +} + +long long __wrap_strtoll(const char *nptr, char **endptr, int base) { + return strproc_stubs.strtoll(nptr, endptr, base); +} + +unsigned long __wrap_strtoul(const char *nptr, char **endptr, int base) { + return strproc_stubs.strtoul(nptr, endptr, base); +} + +unsigned long long __wrap_strtoull(const char *nptr, char **endptr, int base) { + return strproc_stubs.strtoull(nptr, endptr, base); +} + +int __wrap_atoi(const char *num) { + return strproc_stubs.atoi(num); +} + +long __wrap_atol(const char *num) { + return strproc_stubs.atol(num); +} + +// Standalone functions + +unsigned long atoul(const char *num) { + return strproc_stubs.atoul(num); +} + +unsigned long long atoull(const char *num) { + return strproc_stubs.atoull(num); +} + +unsigned int atoui(const char *num) { + return strproc_stubs.atoui(num); +} + +size_t strnlen(const char *s, size_t count) { + return strproc_stubs.strnlen(s, count); +} + +size_t strlcpy(char *dst, const char *src, size_t s) { + return strproc_stubs.strlcpy(dst, src, s); +} + +int strnicmp(const char *s1, const char *s2, size_t len) { + return strproc_stubs.strnicmp(s1, s2, len); +} + +char *strsep(char **s, const char *ct) { + return strproc_stubs.strsep(s, ct); +} diff --git a/cores/realtek-ambz2/base/fixups/strproc.h b/cores/realtek-ambz2/base/fixups/strproc.h new file mode 100644 index 0000000..aaa619f --- /dev/null +++ b/cores/realtek-ambz2/base/fixups/strproc.h @@ -0,0 +1,22 @@ +/* Copyright (c) Kuba Szczodrzyński 2023-03-03. */ + +#pragma once + +// Remove SDK definitions of string processing methods. +// Include stdlib versions instead. +// Wrapper functions for the removed prototypes are provided in strproc.c. + +#include +#include +#include +#include + +// These functions aren't part of stdlib. + +unsigned long atoul(const char *num); +unsigned long long atoull(const char *num); +unsigned int atoui(const char *num); +size_t strnlen(const char *s, size_t count); +size_t strlcpy(char *dst, const char *src, size_t s); +int strnicmp(const char *s1, const char *s2, size_t len); +char *strsep(char **s, const char *ct); diff --git a/cores/realtek-ambz2/base/fixups/utility.h b/cores/realtek-ambz2/base/fixups/utility.h new file mode 100644 index 0000000..f66be93 --- /dev/null +++ b/cores/realtek-ambz2/base/fixups/utility.h @@ -0,0 +1,6 @@ +/* Copyright (c) Kuba Szczodrzyński 2023-03-03. */ + +#pragma once + +// proxy because we're not using soc/realtek/8710c/misc/utilities/include as it contains ctype.h +#include diff --git a/cores/realtek-ambz2/base/lt_family.h b/cores/realtek-ambz2/base/lt_family.h new file mode 100644 index 0000000..b83d559 --- /dev/null +++ b/cores/realtek-ambz2/base/lt_family.h @@ -0,0 +1,18 @@ +/* Copyright (c) Kuba Szczodrzyński 2023-03-02. */ + +#pragma once + +#include + +// Choose the main UART output port +#ifndef LT_UART_DEFAULT_PORT +#if HAS_SERIAL2 +#define LT_UART_DEFAULT_PORT 2 +#elif HAS_SERIAL0 +#define LT_UART_DEFAULT_PORT 0 +#elif HAS_SERIAL1 +#define LT_UART_DEFAULT_PORT 1 +#else +#error "No serial port is available" +#endif +#endif diff --git a/docs/dev/stdlib.md b/docs/dev/stdlib.md new file mode 100644 index 0000000..54184da --- /dev/null +++ b/docs/dev/stdlib.md @@ -0,0 +1,102 @@ +# C stdlib + +Usually, functions available in C standard library should not be defined by the SDK. Instead, they should be included using GCC's headers, and implemented by the libc or wrapped and implemented in the SDK. + +The following functions must not be defined by the SDK. Their presence makes conflicts due to incompatibility with C library, so they should be removed or disabled, and replaced with wrappers. + +Memory management functions should be wrapped and redirected to FreeRTOS (if possible). + +Additionally, if the `printf` library is used in the chip family code, all other vendor-defined printf-like functions should be replaced with it. + +Function prototypes taken from [devdocs.io](https://devdocs.io/c/). + +```cpp +// stdlib.h / Dynamic memory management +void *calloc(size_t num, size_t size); +void *malloc(size_t size); +void *realloc(void *ptr, size_t new_size); +void free(void *ptr); +// stdlib.h / Conversions to numeric formats +double atof(const char *str); +int atoi(const char *str); +long atol(const char *str); +long long atoll(const char *str); +double strtod(const char *str, char **str_end); +float strtof(const char *str, char **str_end); +long strtol(const char *str, char **str_end, int base); +long double strtold(const char *str, char **str_end); +long long strtoll(const char *str, char **str_end, int base); +unsigned long strtoul(const char *str, char **str_end, int base); +unsigned long long strtoull(const char *str, char **str_end, int base); + +// string.h / Character classification +int isalnum(int ch); +int isalpha(int ch); +int islower(int ch); +int isupper(int ch); +int isdigit(int ch); +int isxdigit(int ch); +int iscntrl(int ch); +int isgraph(int ch); +int isspace(int ch); +int isblank(int ch); +int isprint(int ch); +int ispunct(int ch); +int tolower(int ch); +int toupper(int ch); +// string.h / String manipulation +char *strcat(char *dest, const char *src); +char *strcpy(char *dest, const char *src); +char *strncat(char *dest, const char *src, size_t count); +char *strncpy(char *dest, const char *src, size_t count); +size_t strxfrm(char *dest, const char *src, size_t count); +// string.h / String examination +char *strchr(const char *str, int ch); +int strcmp(const char *lhs, const char *rhs); +size_t strcspn(const char *dest, const char *src); +size_t strlen(const char *str); +int strncmp(const char *lhs, const char *rhs, size_t count); +char *strpbrk(const char *dest, const char *breakset); +char *strrchr(const char *str, int ch); +size_t strspn(const char *dest, const char *src); +char *strstr(const char *str, const char *substr); +char *strtok(char *str, const char *delim); +// string.h / Character array manipulation +void *memchr(const void *ptr, int ch, size_t count); +int memcmp(const void *lhs, const void *rhs, size_t count); +void *memcpy(void *dest, const void *src, size_t count); +void *memmove(void *dest, const void *src, size_t count); +void *memset(void *dest, int ch, size_t count); + +// stdio.h / Unformatted input/output +int putc(int ch, FILE *stream); +int putchar(int ch); +int puts(const char *str); + +// stdio.h / Formatted input/output +int printf(const char *format, ...); +int sprintf(char *buffer, const char *format, ...); +int snprintf(char *buffer, size_t bufsz, const char *format, ...); +int vprintf(const char *format, va_list vlist); +int vsprintf(char *buffer, const char *format, va_list vlist); +int vsnprintf(char *buffer, size_t bufsz, const char *format, va_list vlist); + +// Non-stdlib +_calloc_r +_free_r +_malloc_r +_realloc_r +atoui +atoul +atoull +strlcpy +strnicmp +strnlen +strsep +zalloc + +// Additional forbidden macros +#define max(a, b) +#define min(a, b) +typedef bool boolean; +```