From 3ad0ecea659e337ce468fc653b92e1b67cc47755 Mon Sep 17 00:00:00 2001 From: Jaya Satish Date: Mon, 1 May 2023 20:40:13 +0530 Subject: [PATCH] Improved performance By adding functions using IRAM and cache --- components/utils/include/utils.h | 8 ++++++++ components/utils/initialization.c | 2 +- components/web_server/response_handler.c | 4 ++-- components/wifi_handler/wifi_handler.c | 4 ++-- components/wifi_handler/wifi_init.c | 4 ++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/components/utils/include/utils.h b/components/utils/include/utils.h index 0f0bba8..ea28f46 100644 --- a/components/utils/include/utils.h +++ b/components/utils/include/utils.h @@ -17,6 +17,14 @@ extern "C" #include #include +#ifdef ICACHE_FLASH +#define ICACHE_FLASH_ATTR __attribute__((section(".irom0.text"))) +#define ICACHE_RODATA_ATTR __attribute__((section(".irom.text"))) +#else +#define ICACHE_FLASH_ATTR +#define ICACHE_RODATA_ATTR +#endif /* ICACHE_FLASH */ + float system_uptime_s(void); void restart(void); diff --git a/components/utils/initialization.c b/components/utils/initialization.c index 065dcf4..c4b3f63 100644 --- a/components/utils/initialization.c +++ b/components/utils/initialization.c @@ -26,7 +26,7 @@ char *ssid, *ent_username, *ent_identity, char currentMAC[18]; //----------------------------------------------------------------------------- -esp_err_t parms_init() +esp_err_t IRAM_ATTR parms_init() { int webServer = 1, ledEnable = 1, customDnsEnable = 0, darkModeEnable = 0, randomizeMac = 0; diff --git a/components/web_server/response_handler.c b/components/web_server/response_handler.c index c59dc2a..84db4dc 100644 --- a/components/web_server/response_handler.c +++ b/components/web_server/response_handler.c @@ -63,7 +63,7 @@ url_handler_t handlers[] = { //----------------------------------------------------------------------------- -esp_err_t common_page_response_handler(httpd_req_t *req, int req_id) +esp_err_t ICACHE_FLASH_ATTR common_page_response_handler(httpd_req_t *req, int req_id) { for (int i = 0; i < sizeof(handlers) / sizeof(handlers[0]); i++) { @@ -108,7 +108,7 @@ const size_t num_js_files = sizeof(js_files) / sizeof(js_files[0]); //----------------------------------------------------------------------------- -esp_err_t common_js_response(httpd_req_t *req) +esp_err_t ICACHE_FLASH_ATTR common_js_response(httpd_req_t *req) { for (int i = 0; i < num_js_files; i++) { diff --git a/components/wifi_handler/wifi_handler.c b/components/wifi_handler/wifi_handler.c index 2c3f8c4..a223c3b 100644 --- a/components/wifi_handler/wifi_handler.c +++ b/components/wifi_handler/wifi_handler.c @@ -19,7 +19,7 @@ //----------------------------------------------------------------------------- // Handles wifi scan and return AP records in json string format -char *wifi_scan_handler(void) +char* IRAM_ATTR wifi_scan_handler(void) { // Disconnect from the current access point if not already connected if (!ap_connect) @@ -84,7 +84,7 @@ char *wifi_scan_handler(void) //----------------------------------------------------------------------------- // Handles wifi information and return in json format -char *wifi_info_handler(void) +char* IRAM_ATTR wifi_info_handler(void) { wifi_ap_record_t ap_info; wifi_sta_list_t wifi_sta_list; diff --git a/components/wifi_handler/wifi_init.c b/components/wifi_handler/wifi_init.c index 2f70cd6..a92d5dc 100644 --- a/components/wifi_handler/wifi_init.c +++ b/components/wifi_handler/wifi_init.c @@ -34,7 +34,7 @@ bool has_static_ip = false; // initiating wifi setup void wifi_init() { - + esp_log_level_set("wifi", ESP_LOG_NONE); wifi_event_group = xEventGroupCreate(); esp_netif_init(); ESP_ERROR_CHECK(esp_event_loop_create_default()); @@ -127,7 +127,7 @@ void wifi_init() // Enable DNS (offer) for dhcp server dhcps_offer_t dhcps_dns_value = OFFER_DNS; dhcps_set_option_info(6, &dhcps_dns_value, sizeof(dhcps_dns_value)); - + ESP_ERROR_CHECK(esp_wifi_start()); if (strlen(ssid) > 0)