Skip to content

Commit

Permalink
os/arch/arm/src/amebasmart: Revise logging usage
Browse files Browse the repository at this point in the history
- Optimize some logging to reduce flash memory usage
  • Loading branch information
edwakuwaku committed Jul 15, 2024
1 parent 184763a commit 87df0f6
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 30 deletions.
24 changes: 21 additions & 3 deletions os/arch/arm/src/amebasmart/amebasmart_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions os/arch/arm/src/amebasmart/amebasmart_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion os/arch/arm/src/common/up_initialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
57 changes: 44 additions & 13 deletions os/board/rtl8730e/src/component/os/tizenrt/rtk_netmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,11 @@ 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;

#ifdef CONFIG_PM
bsp_pm_domain_control(BSP_WIFI_DRV, 1);
#endif
rtw_memset(&scan_param, 0, sizeof(rtw_scan_param_t));
scan_param.scan_user_callback = app_scan_result_handler; //print_ssid_scan_result

Expand All @@ -430,8 +434,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
Expand All @@ -445,43 +451,55 @@ 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);
}
}

if(config->ssid_length > 0 || (ch_valid)) {
/* 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;
}
}

nvdbg("[RTK] WIFi Scan success\n");
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;
}
#ifdef CONFIG_PM
bsp_pm_domain_control(BSP_WIFI_DRV, 0);
#endif
return ret;
}

trwifi_result_e wifi_netmgr_utils_scan_multi_ap(struct netdev *dev, trwifi_scan_multi_configs_s *config)
Expand Down Expand Up @@ -579,16 +597,21 @@ trwifi_result_e wifi_netmgr_utils_connect_ap(struct netdev *dev, trwifi_ap_confi
int ret;
uint32_t ap_channel;
wuret = TRWIFI_FAIL;
#ifdef CONFIG_PM
bsp_pm_domain_control(BSP_WIFI_DRV, 1);
#endif

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;
}
}

Expand All @@ -612,13 +635,21 @@ 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:
#ifdef CONFIG_PM
bsp_pm_domain_control(BSP_WIFI_DRV, 1);
#endif
if (wuret != TRWIFI_SUCCESS) {
dbg("WIFI connect AP failed, check line: %d\n", ret);
}
return wuret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 14 additions & 9 deletions os/board/rtl8730e/src/rtl8730e_boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,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
Expand All @@ -336,26 +336,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
Expand Down

0 comments on commit 87df0f6

Please sign in to comment.