From 1cbbe2d694239de46da0916d34d8d3e0e3607121 Mon Sep 17 00:00:00 2001 From: edwakuwaku Date: Tue, 6 Aug 2024 17:22:42 +0800 Subject: [PATCH] os/arch/arm/src/amebasmart: Revise logging usage - Optimize some logging to reduce flash memory usage --- os/arch/arm/src/amebasmart/amebasmart_flash.c | 24 ++++++++-- os/arch/arm/src/amebasmart/amebasmart_spi.c | 4 +- os/arch/arm/src/common/up_initialize.c | 2 +- .../platform/amebad2/hci/hci_platform.c | 1 - .../src/component/os/tizenrt/rtk_netmgr.c | 45 +++++++++++++------ .../soc/amebad2/misc/ameba_tizenrt_pmu.h | 1 + .../soc/amebad2/misc/ameba_wlan_init.c | 3 ++ .../src/component/soc/amebad2/swlib/diag.h | 2 +- .../wifi/api/wifi_intf_drv_to_app_basic.h | 2 +- .../component/wifi/wifi_interactive_mode.c | 2 +- os/board/rtl8730e/src/rtl8730e_boot.c | 23 ++++++---- 11 files changed, 77 insertions(+), 32 deletions(-) diff --git a/os/arch/arm/src/amebasmart/amebasmart_flash.c b/os/arch/arm/src/amebasmart/amebasmart_flash.c index af9cd75693..d56a7f24dd 100644 --- a/os/arch/arm/src/amebasmart/amebasmart_flash.c +++ b/os/arch/arm/src/amebasmart/amebasmart_flash.c @@ -162,6 +162,9 @@ static int amebasmart_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t ssize_t result; startblock += AMEBASMART_START_SECOTR; +#ifdef CONFIG_PM + bsp_pm_domain_control(BSP_FLASH_DRV, 1); +#endif /* Erase the specified blocks and return status (OK or a negated errno) */ while (nblocks > 0) { result = amebasmart_erase_page(startblock); @@ -171,6 +174,9 @@ static int amebasmart_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t startblock++; nblocks--; } +#ifdef CONFIG_PM + bsp_pm_domain_control(BSP_FLASH_DRV, 0); +#endif return OK; } @@ -274,7 +280,13 @@ static ssize_t amebasmart_read(FAR struct mtd_dev_s *dev, off_t offset, size_t n { ssize_t result; DEBUGASSERT(nbytes > 0); +#ifdef CONFIG_PM + bsp_pm_domain_control(BSP_FLASH_DRV, 1); +#endif result = amebasmart_flash_read(CONFIG_AMEBASMART_FLASH_BASE + offset, buffer, nbytes); +#ifdef CONFIG_PM + bsp_pm_domain_control(BSP_FLASH_DRV, 0); +#endif return result < 0 ? result : nbytes; } @@ -289,8 +301,14 @@ static ssize_t amebasmart_write(FAR struct mtd_dev_s *dev, off_t offset, size_t size_t addr; ssize_t result; DEBUGASSERT(nbytes > 0); +#ifdef CONFIG_PM + bsp_pm_domain_control(BSP_FLASH_DRV, 1); +#endif addr = CONFIG_AMEBASMART_FLASH_BASE + offset; result = amebasmart_flash_write(addr, buffer, nbytes); +#ifdef CONFIG_PM + bsp_pm_domain_control(BSP_FLASH_DRV, 0); +#endif return result < 0 ? result : nbytes; } #endif @@ -366,10 +384,10 @@ FAR struct mtd_dev_s *up_flashinitialize(void) #ifdef CONFIG_MTD_REGISTRATION priv->mtd.name = "ameba_flash"; #endif - u8 chip_id[4]; - flash_read_id(NULL, chip_id, 4); - lldbg("Manufacturer : %u memory type : %u capacity : %u\n", chip_id[0], chip_id[1], chip_id[2]); +/* For flash information, it will be printed during KM4 booting phase + For example: [FLASHCLK-I] Flash ID: ef-40-18 +*/ return (FAR struct mtd_dev_s *)priv; } #ifdef CONFIG_PM diff --git a/os/arch/arm/src/amebasmart/amebasmart_spi.c b/os/arch/arm/src/amebasmart/amebasmart_spi.c index 08794c0076..c012f027a9 100644 --- a/os/arch/arm/src/amebasmart/amebasmart_spi.c +++ b/os/arch/arm/src/amebasmart/amebasmart_spi.c @@ -1181,14 +1181,14 @@ static void amebasmart_spi_exchange(FAR struct spi_dev_s *dev, uint8_t *txbuff_aligned = NULL; rxbuff_aligned = (uint8_t *)rtw_zmalloc(SPI_DMA_MAX_BUFFER_SIZE); if(rxbuff_aligned == NULL) { - lldbg("rxbuff_aligned malloc failed\n"); + dbg_noarg("SPI RX malloc failed\n"); return; } if (txbuffer) { txbuff_aligned = (uint8_t *)rtw_zmalloc(SPI_DMA_MAX_BUFFER_SIZE); if(txbuff_aligned == NULL) { rtw_mfree(rxbuff_aligned, 0); - lldbg("txbuff_aligned malloc failed\n"); + dbg_noarg("SPI TX malloc failed\n"); return; } } diff --git a/os/arch/arm/src/common/up_initialize.c b/os/arch/arm/src/common/up_initialize.c index bdfe316a78..c3e48fb421 100644 --- a/os/arch/arm/src/common/up_initialize.c +++ b/os/arch/arm/src/common/up_initialize.c @@ -189,7 +189,7 @@ void up_initialize(void) #ifdef CONFIG_SYSTEM_REBOOT_REASON up_reboot_reason_init(); - lldbg("[Reboot Reason] : %d\n", up_reboot_reason_read()); + lldbg_noarg("[Reboot Reason]: %d\n", up_reboot_reason_read()); #endif /* Calibrate the timing loop */ diff --git a/os/board/rtl8730e/src/component/bluetooth/driver/platform/amebad2/hci/hci_platform.c b/os/board/rtl8730e/src/component/bluetooth/driver/platform/amebad2/hci/hci_platform.c index b3345dc018..8bcace73e6 100644 --- a/os/board/rtl8730e/src/component/bluetooth/driver/platform/amebad2/hci/hci_platform.c +++ b/os/board/rtl8730e/src/component/bluetooth/driver/platform/amebad2/hci/hci_platform.c @@ -972,7 +972,6 @@ static uint8_t* hci_platform_get_btfw_patch(uint32_t *rtlbt_fw_size) /* Below condition is minimal requirement to meet */ /* Address must be starting of the external flash, size shouldn't be larger than 128KB */ if(!((*rtlbt_fw_size > 0 && *rtlbt_fw_size < 0x20000) && (rtlbt_fw_addr == EXT_FLASH_BASE_ADDRESS))) { - dbg("Please check whether RTK data binary is flashed correctly!"); ASSERT(0); } if (rtlbt_fw_hdr_ptr) { diff --git a/os/board/rtl8730e/src/component/os/tizenrt/rtk_netmgr.c b/os/board/rtl8730e/src/component/os/tizenrt/rtk_netmgr.c index 71f94164c0..ec77b46f9c 100644 --- a/os/board/rtl8730e/src/component/os/tizenrt/rtk_netmgr.c +++ b/os/board/rtl8730e/src/component/os/tizenrt/rtk_netmgr.c @@ -416,6 +416,7 @@ trwifi_result_e wifi_netmgr_utils_scan_ap(struct netdev *dev, trwifi_scan_config int i = 0; int ch_valid = 0; rtw_scan_param_t scan_param = {0}; + int ret = TRWIFI_SUCCESS; rtw_memset(&scan_param, 0, sizeof(rtw_scan_param_t)); scan_param.scan_user_callback = app_scan_result_handler; //print_ssid_scan_result @@ -432,8 +433,10 @@ trwifi_result_e wifi_netmgr_utils_scan_ap(struct netdev *dev, trwifi_scan_config /* If Channel Information is given by User */ channel_list = (char *)malloc(1); //only do 1 channel instead of multiple channels for now if (!channel_list) { - printf("[ATWs]ERROR: Can't malloc memory for channel list\n\r"); - return TRWIFI_FAIL; + // printf("[ATWs]ERROR: Can't malloc memory for channel list\n\r"); + // return TRWIFI_FAIL; + ret = __LINE__; + goto errout; } //parse command channel list for (i = 0; i < 1 ; i++) { //This loop should be scalable when multiple channels are required by customer @@ -447,11 +450,11 @@ trwifi_result_e wifi_netmgr_utils_scan_ap(struct netdev *dev, trwifi_scan_config /* Scan with channel Only */ rtw_memset(config->ssid, 0, sizeof(config->ssid)); config->ssid_length = 0; - printf("[ATWs]: _AT_WLAN_SCAN_WITH_CHANNEL_ [%d]\n\r", scan_param.channel_list[0]); + vdbg("WIFI Scan channel: %d\n\r", scan_param.channel_list[0]); } else { /* Scan with SSID and channel */ - printf("[ATWs]: _AT_WLAN_SCAN_WITH_SSID_AND_CHANNEL [%d], [%s]\n\r", scan_param.channel_list[0], (char *)config->ssid); + vdbg("WIFI Scan channel: %d, SSID: %s\n\r", scan_param.channel_list[0], (char *)config->ssid); } } @@ -459,23 +462,27 @@ trwifi_result_e wifi_netmgr_utils_scan_ap(struct netdev *dev, trwifi_scan_config /* Scan with SSID, or Scan with SSID And Channel */ scan_param.ssid[0].ssid = (char *)config->ssid; if(config->ssid_length > 0 && config->channel == 0) { - printf("[ATWs]: _AT_WLAN_SCAN_WITH_SSID_ [%s]\n\r", (char *)config->ssid); + nvdbg("WIFI Scan SSID: %s\n\r", (char *)config->ssid); } } else { - RTW_API_INFO("Invalid channel range\n"); - return TRWIFI_FAIL; + // RTW_API_INFO("Invalid channel range\n"); + // return TRWIFI_FAIL; + ret = __LINE__; + goto errout; } if (wifi_scan_networks(&scan_param, 0) != RTW_SUCCESS) { if (channel_list) { free(channel_list); } - return TRWIFI_FAIL; + ret = __LINE__; + goto errout; } } else { if (wifi_scan_networks(&scan_param, 0) != RTW_SUCCESS) { //ndbg("[RTK] [ERR] WiFi scan fail(%d)\n", ret); - return TRWIFI_FAIL; + ret = __LINE__; + goto errout; } } @@ -483,7 +490,12 @@ trwifi_result_e wifi_netmgr_utils_scan_ap(struct netdev *dev, trwifi_scan_config if (channel_list) { free(channel_list); } - return TRWIFI_SUCCESS; +errout: + if (ret != TRWIFI_SUCCESS) { + dbg("WIFI scan failed, check line: %d\n", ret); + ret = TRWIFI_FAIL; + } + return ret; } trwifi_result_e wifi_netmgr_utils_scan_multi_ap(struct netdev *dev, trwifi_scan_multi_configs_s *config) @@ -585,12 +597,14 @@ trwifi_result_e wifi_netmgr_utils_connect_ap(struct netdev *dev, trwifi_ap_confi if (g_mode == RTK_WIFI_SOFT_AP_IF) { if (wifi_netmgr_utils_deinit(dev)) { ndbg("[RTK] Failed to stop AP mode\n"); - return TRWIFI_FAIL; + ret = __LINE__; + goto errout; } vTaskDelay(20); if (wifi_netmgr_utils_init(dev) < 0) { ndbg("\n\rERROR: Wifi on failed!"); - return TRWIFI_FAIL; + ret = __LINE__; + goto errout; } } @@ -614,13 +628,18 @@ trwifi_result_e wifi_netmgr_utils_connect_ap(struct netdev *dev, trwifi_ap_confi ret = cmd_wifi_connect(ap_connect_config, arg, ap_channel); if (ret != RTK_STATUS_SUCCESS) { ndbg("[RTK] WiFiNetworkJoin failed: %d, %s\n", ret, ap_connect_config->ssid); - return wuret; + ret = __LINE__; + goto errout; } else { wuret = TRWIFI_SUCCESS; nvdbg("[RTK] Successfully joined the network: %s(%d)\n", ap_connect_config->ssid, ap_connect_config->ssid_length); } +errout: + if (wuret != TRWIFI_SUCCESS) { + dbg("WIFI connect AP failed, check line: %d\n", ret); + } return wuret; } diff --git a/os/board/rtl8730e/src/component/soc/amebad2/misc/ameba_tizenrt_pmu.h b/os/board/rtl8730e/src/component/soc/amebad2/misc/ameba_tizenrt_pmu.h index 6ca5230028..ae21ab9119 100644 --- a/os/board/rtl8730e/src/component/soc/amebad2/misc/ameba_tizenrt_pmu.h +++ b/os/board/rtl8730e/src/component/soc/amebad2/misc/ameba_tizenrt_pmu.h @@ -26,6 +26,7 @@ typedef enum { BSP_FLASH_DRV = 3, BSP_UART_DRV = 4, BSP_MIPI_DRV = 5, + BSP_WIFI_DRV = 6, BSP_DOMAIN_MAX, } BSP_DRV_DOMAIN; diff --git a/os/board/rtl8730e/src/component/soc/amebad2/misc/ameba_wlan_init.c b/os/board/rtl8730e/src/component/soc/amebad2/misc/ameba_wlan_init.c index 9478bd2030..a2e095295e 100755 --- a/os/board/rtl8730e/src/component/soc/amebad2/misc/ameba_wlan_init.c +++ b/os/board/rtl8730e/src/component/soc/amebad2/misc/ameba_wlan_init.c @@ -49,6 +49,9 @@ void wlan_initialize(void) { inic_ipc_init_host(); inic_ipc_api_init_host(); +#ifdef CONFIG_PM + bsp_pm_domain_register("WIFI", BSP_WIFI_DRV); +#endif #ifndef CONFIG_MP_INCLUDED #if defined (CONFIG_CLINTWOOD) && CONFIG_CLINTWOOD diff --git a/os/board/rtl8730e/src/component/soc/amebad2/swlib/diag.h b/os/board/rtl8730e/src/component/soc/amebad2/swlib/diag.h index 95d97a192c..6c1b8a8368 100755 --- a/os/board/rtl8730e/src/component/soc/amebad2/swlib/diag.h +++ b/os/board/rtl8730e/src/component/soc/amebad2/swlib/diag.h @@ -154,7 +154,7 @@ extern u32 ConfigDebug[]; #ifdef CONFIG_DEBUG_LOG #define DBG_8195A(...) do {\ if (unlikely(ConfigDebug[LEVEL_ERROR] & BIT(MODULE_MISC))) \ - DiagPrintf("\r" __VA_ARGS__);\ + dbg_noarg("\r" __VA_ARGS__);\ }while(0) #define MONITOR_LOG(...) do {\ diff --git a/os/board/rtl8730e/src/component/wifi/api/wifi_intf_drv_to_app_basic.h b/os/board/rtl8730e/src/component/wifi/api/wifi_intf_drv_to_app_basic.h index c04f15338b..e91568d16d 100644 --- a/os/board/rtl8730e/src/component/wifi/api/wifi_intf_drv_to_app_basic.h +++ b/os/board/rtl8730e/src/component/wifi/api/wifi_intf_drv_to_app_basic.h @@ -59,7 +59,7 @@ extern "C" { * @brief Create RTW_API_INFO */ #if defined RTW_ENABLE_API_INFO || defined __DOXYGEN__ -#define RTW_API_INFO printf +#define RTW_API_INFO dbg_noarg #else #define RTW_API_INFO(args) #endif diff --git a/os/board/rtl8730e/src/component/wifi/wifi_interactive_mode.c b/os/board/rtl8730e/src/component/wifi/wifi_interactive_mode.c index 1fcfeb4a15..15e39e6636 100644 --- a/os/board/rtl8730e/src/component/wifi/wifi_interactive_mode.c +++ b/os/board/rtl8730e/src/component/wifi/wifi_interactive_mode.c @@ -227,7 +227,7 @@ static int _get_ap_security_mode(IN char *ssid, OUT rtw_security_t *security_mod scanned_ap_num = wifi_scan_networks(&scan_param, 1); if (scanned_ap_num <= 0) { - printf("Wifi scan failed!\n"); + ndbg("Wifi scan failed!\n"); ret = 0; } else { _find_ap_from_scan_buf(ssid, (void *)&wifi, scanned_ap_num); diff --git a/os/board/rtl8730e/src/rtl8730e_boot.c b/os/board/rtl8730e/src/rtl8730e_boot.c index 541023f387..61f1954c16 100644 --- a/os/board/rtl8730e/src/rtl8730e_boot.c +++ b/os/board/rtl8730e/src/rtl8730e_boot.c @@ -328,8 +328,8 @@ void amebasmart_mount_partitions(void) /* Configure mtd partitions */ ret = configure_mtd_partitions(mtd, 0, &partinfo); if (ret != OK) { - lldbg("ERROR: configure_mtd_partitions for primary flash failed\n"); - return; + ret = __LINE__; + goto errout; } #ifdef CONFIG_AUTOMOUNT @@ -342,26 +342,31 @@ void amebasmart_mount_partitions(void) #ifdef CONFIG_MTD_JEDEC mtd = jedec_initialize(spi); if (mtd == NULL) { - lldbg("Jedec Init failed\n"); - return; + ret = __LINE__; + goto errout; } #elif defined(CONFIG_MTD_W25) mtd = w25_initialize(spi); if (mtd == NULL) { - lldbg("w25 Init failed\n"); - return; + ret = __LINE__; + goto errout; } #endif ret = configure_mtd_partitions(mtd, 1, &partinfo); if (ret != OK) { - lldbg("ERROR: configure_mtd_partitions for secondary flash failed\n"); - return; + ret = __LINE__; + goto errout; } #ifdef CONFIG_AUTOMOUNT automount_fs_partition(&partinfo); #endif -#endif /* end of CONFIG_SECOND_FLASH_PARTITION */ +#endif /* CONFIG_SECOND_FLASH_PARTITION */ +errout: + if (ret != OK) { + lldbg("Mounting failed, check line: %d\n", ret); + return; + } } #ifdef CONFIG_FTL_ENABLED