From eb2eec94a44db6e17f2e411d315e29dc50ae345a Mon Sep 17 00:00:00 2001 From: RavenSystem Date: Mon, 23 Oct 2023 18:13:44 +0200 Subject: [PATCH] Home Accessory Architect v12.9.1 Merlin --- HAA/HAA_Installer/main/Makefile | 3 +- HAA/HAA_Installer/main/header.h | 2 +- HAA/HAA_Installer/main/main.c.lcm | 4 +- HAA/HAA_Installer/main/setup.c | 4 +- HAA/HAA_Main/main/Makefile | 4 +- HAA/HAA_Main/main/header.h | 13 +- HAA/HAA_Main/main/main.c | 253 +++++++++--------- HAA/HAA_Main/main/setup.c | 2 +- libs/adv_button/adv_button.c | 10 +- libs/adv_logger/adv_logger.c | 12 +- libs/adv_logger_ntp/adv_logger_ntp.c | 10 +- libs/homekit-rsf/src/mdnsresponder.c | 2 +- libs/new_dht/dht.c | 4 +- libs/timers_helper/timers_helper.c | 18 +- libs/timers_helper/timers_helper.h | 2 +- sdk/esp-open-rtos-rsf/core/app_main.c | 2 +- sdk/esp-open-rtos-rsf/lwip/include/arch/cc.h | 1 + sdk/esp-open-rtos-rsf/lwip/include/lwipopts.h | 2 +- .../lwip/lwip/src/apps/lwiperf/lwiperf.c | 6 + .../lwip/lwip/src/core/ipv4/dhcp.c | 66 ++--- sdk/esp-open-rtos-rsf/lwip/sys_arch.c | 8 + .../open_esplibs/libmain/ets_timer.c | 6 +- .../open_esplibs/libmain/user_interface.c | 4 +- .../open_esplibs/libwpa/wpa_main.c | 6 +- 24 files changed, 234 insertions(+), 210 deletions(-) diff --git a/HAA/HAA_Installer/main/Makefile b/HAA/HAA_Installer/main/Makefile index 78932d1b..966ed1e0 100644 --- a/HAA/HAA_Installer/main/Makefile +++ b/HAA/HAA_Installer/main/Makefile @@ -103,8 +103,7 @@ EXTRA_CFLAGS += -DWIFI_PARAM_SAVE=0 EXTRA_CFLAGS += -DconfigMAX_TASK_NAME_LEN=7 EXTRA_CFLAGS += -DconfigCHECK_FOR_STACK_OVERFLOW=2 EXTRA_CFLAGS += -DconfigMINIMAL_STACK_SIZE=256 -#EXTRA_CFLAGS += -DconfigTIMER_TASK_PRIORITY=\(configMAX_PRIORITIES-1\) -EXTRA_CFLAGS += -DconfigTIMER_TASK_PRIORITY=\(tskIDLE_PRIORITY+3\) +EXTRA_CFLAGS += -DconfigTIMER_TASK_PRIORITY=\(configMAX_PRIORITIES-3\) EXTRA_CFLAGS += -DconfigTIMER_QUEUE_LENGTH=10 EXTRA_CFLAGS += -DconfigTIMER_TASK_STACK_DEPTH=600 diff --git a/HAA/HAA_Installer/main/header.h b/HAA/HAA_Installer/main/header.h index 503b356d..900c2531 100644 --- a/HAA/HAA_Installer/main/header.h +++ b/HAA/HAA_Installer/main/header.h @@ -11,6 +11,6 @@ #include "../../common/common_headers.h" #define INSTALLER_BETA_REVISION "" -#define INSTALLER_VERSION "7.7.0"INSTALLER_BETA_REVISION +#define INSTALLER_VERSION "7.7.1"INSTALLER_BETA_REVISION #endif // __HAA_OTA_HEADER_H__ diff --git a/HAA/HAA_Installer/main/main.c.lcm b/HAA/HAA_Installer/main/main.c.lcm index 7861b2b9..d0c1e603 100644 --- a/HAA/HAA_Installer/main/main.c.lcm +++ b/HAA/HAA_Installer/main/main.c.lcm @@ -628,7 +628,7 @@ void ota_task(void *arg) { ota_init(user_repo, is_ssl); - vTaskDelay(pdMS_TO_TICKS(2000)); + vTaskDelay(2000 / portTICK_PERIOD_MS); sysparam_set_int8(HAA_SETUP_MODE_SYSPARAM, 0); @@ -745,7 +745,7 @@ void ota_task(void *arg) { break; } - vTaskDelay(pdMS_TO_TICKS(5000)); + vTaskDelay(5000 / portTICK_PERIOD_MS); } } else { printf("\n! Reading HAAMAIN Version, fixing\n\n"); diff --git a/HAA/HAA_Installer/main/setup.c b/HAA/HAA_Installer/main/setup.c index 35c9b4f7..3c3daa90 100644 --- a/HAA/HAA_Installer/main/setup.c +++ b/HAA/HAA_Installer/main/setup.c @@ -1243,7 +1243,7 @@ static void wifi_config_sta_connect_timeout_task() { wifi_config_context_free(context); - rs_esp_timer_start_forced(rs_esp_timer_create(AUTO_REBOOT_ON_HANG_OTA_TIMEOUT, false, NULL, auto_reboot_run)); + rs_esp_timer_start_forced(rs_esp_timer_create(AUTO_REBOOT_ON_HANG_OTA_TIMEOUT, pdFALSE, NULL, auto_reboot_run)); break; @@ -1457,7 +1457,7 @@ static void wifi_config_station_connect() { sysparam_set_int8(HAA_SETUP_MODE_SYSPARAM, 0); if (setup_mode == 1) { - context->auto_reboot_timer = rs_esp_timer_create(AUTO_REBOOT_TIMEOUT, false, NULL, auto_reboot_run); + context->auto_reboot_timer = rs_esp_timer_create(AUTO_REBOOT_TIMEOUT, pdFALSE, NULL, auto_reboot_run); rs_esp_timer_start_forced(context->auto_reboot_timer); } } diff --git a/HAA/HAA_Main/main/Makefile b/HAA/HAA_Main/main/Makefile index 8406665a..b96610c8 100644 --- a/HAA/HAA_Main/main/Makefile +++ b/HAA/HAA_Main/main/Makefile @@ -69,6 +69,7 @@ EXTRA_CFLAGS += -DARP_TABLE_SIZE=10 EXTRA_CFLAGS += -DDNS_MAX_RETRIES=2 EXTRA_CFLAGS += -DDHCP_DOES_ARP_CHECK=0 EXTRA_CFLAGS += -DLWIP_DHCP_AGGRESSIVE +EXTRA_CFLAGS += -DLWIP_DHCP_RANDOMIZE_COARSE_TIME_SECS=10 EXTRA_CFLAGS += -DDEFAULT_RAW_RECVMBOX_SIZE=5 EXTRA_CFLAGS += -DMEMP_NUM_NETCONN=16 #EXTRA_CFLAGS += -DCHECKSUM_CHECK_UDP=0 @@ -84,8 +85,7 @@ EXTRA_CFLAGS += -DWIFI_PARAM_SAVE=0 EXTRA_CFLAGS += -DconfigMAX_TASK_NAME_LEN=7 EXTRA_CFLAGS += -DconfigCHECK_FOR_STACK_OVERFLOW=2 EXTRA_CFLAGS += -DconfigMINIMAL_STACK_SIZE=256 -#EXTRA_CFLAGS += -DconfigTIMER_TASK_PRIORITY=\(configMAX_PRIORITIES-1\) -EXTRA_CFLAGS += -DconfigTIMER_TASK_PRIORITY=\(tskIDLE_PRIORITY+3\) +EXTRA_CFLAGS += -DconfigTIMER_TASK_PRIORITY=\(configMAX_PRIORITIES-3\) EXTRA_CFLAGS += -DconfigTIMER_QUEUE_LENGTH=15 EXTRA_CFLAGS += -DconfigTIMER_TASK_STACK_DEPTH=736 diff --git a/HAA/HAA_Main/main/header.h b/HAA/HAA_Main/main/header.h index 0535065a..ee6219d1 100644 --- a/HAA/HAA_Main/main/header.h +++ b/HAA/HAA_Main/main/header.h @@ -11,7 +11,7 @@ #include "../../common/common_headers.h" // Version -#define HAA_FIRMWARE_VERSION "12.9.0" +#define HAA_FIRMWARE_VERSION "12.9.1" #define HAA_FIRMWARE_BETA_REVISION "" #define HAA_FIRMWARE_CODENAME "Merlin" @@ -555,11 +555,12 @@ #define FM_MATHS_GET_TIME_DAYYEAR (-7) #define FM_MATHS_GET_TIME_YEAR (-8) #define FM_MATHS_GET_TIME_IS_SAVING (-9) -#define FM_MATHS_GEN_RANDOM_NUMBER (-10) -#define FM_MATHS_GET_UPTIME (-11) -#define FM_MATHS_GET_WIFI_RSSI (-12) -#define FM_MATHS_GET_HK_CLIENT_IPADDR (-13) -#define FM_MATHS_GET_HK_CLIENT_COUNT (-14) +#define FM_MATHS_GET_TIME_UNIX (-10) +#define FM_MATHS_GEN_RANDOM_NUMBER (-11) +#define FM_MATHS_GET_UPTIME (-12) +#define FM_MATHS_GET_WIFI_RSSI (-13) +#define FM_MATHS_GET_HK_CLIENT_IPADDR (-14) +#define FM_MATHS_GET_HK_CLIENT_COUNT (-15) #define FM_MATHS_OPERATIONS ch_group->num_i[1] #define FM_MATHS_FIRST_OPERATION (2) #define FM_MATHS_INT ch_group->num_i diff --git a/HAA/HAA_Main/main/main.c b/HAA/HAA_Main/main/main.c index b84cbf6e..f3e87765 100644 --- a/HAA/HAA_Main/main/main.c +++ b/HAA/HAA_Main/main/main.c @@ -176,16 +176,14 @@ static void show_freeheap() { // ESP-IDF ADC #ifdef ESP_PLATFORM int haa_adc_oneshot_read_by_gpio(int gpio) { - int adc_int; + int adc_int = -1; adc_channel_t adc_channel; adc_unit_t adc_unit; // Needed to make adc_oneshot_io_to_channel() happy if (adc_oneshot_io_to_channel(gpio, &adc_unit, &adc_channel) == ESP_OK) { - if (adc_oneshot_read(main_config.adc_dac_data->adc_oneshot_handle, adc_channel, &adc_int) == ESP_OK) { - return adc_int; - } + adc_oneshot_read(main_config.adc_dac_data->adc_oneshot_handle, adc_channel, &adc_int); } - return -1; + return adc_int; } #endif @@ -416,7 +414,7 @@ void led_create(const uint16_t gpio, const bool inverted) { main_config.status_led = malloc(sizeof(led_t)); memset(main_config.status_led, 0, sizeof(*main_config.status_led)); - main_config.status_led->timer = rs_esp_timer_create(10, false, NULL, led_code_run); + main_config.status_led->timer = rs_esp_timer_create(10, pdFALSE, NULL, led_code_run); main_config.status_led->gpio = gpio; @@ -1329,7 +1327,7 @@ void hkc_custom_setup_setter(homekit_characteristic_t* ch, const homekit_value_t case '3': // WiFi Reconnection main_config.wifi_status = WIFI_STATUS_DISCONNECTED; - rs_esp_timer_start_forced(rs_esp_timer_create(1000, false, NULL, wifi_config_reset)); + rs_esp_timer_start_forced(rs_esp_timer_create(1000, pdFALSE, NULL, wifi_config_reset)); break; default: @@ -2918,7 +2916,7 @@ void temperature_task(void* args) { /* * Only for tests. Keep comment for releases */ - //get_temp = true; temperature_value = 23; humidity_value = 68; + //get_temp = true; temperature_value = (((float) (hwrand() % 51)) / 10.0f) + 20; humidity_value = 68; if (get_temp) { TH_SENSOR_ERROR_COUNT = 0; @@ -2943,10 +2941,10 @@ void temperature_task(void* args) { if (ch_group->chs > 4) { hkc_th_setter(ch_group->ch[0], ch_group->ch[0]->value); } - - if (ch_group->main_enabled) { - do_wildcard_actions(ch_group, 0, temperature_value); - } + } + + if (ch_group->main_enabled) { + do_wildcard_actions(ch_group, 0, temperature_value); } } @@ -2969,10 +2967,10 @@ void temperature_task(void* args) { if (ch_group->chs > 4) { hkc_humidif_setter(ch_group->ch[1], ch_group->ch[1]->value); } - - if (ch_group->main_enabled) { - do_wildcard_actions(ch_group, 1, humidity_value_int); - } + } + + if (ch_group->main_enabled) { + do_wildcard_actions(ch_group, 1, humidity_value_int); } } @@ -4563,10 +4561,10 @@ void light_sensor_task(void* args) { if ((uint32_t) ch_group->ch[0]->value.float_value != (uint32_t) luxes) { ch_group->ch[0]->value.float_value = luxes; homekit_characteristic_notify_safe(ch_group->ch[0]); - - if (ch_group->main_enabled) { - do_wildcard_actions(ch_group, 0, luxes); - } + } + + if (ch_group->main_enabled) { + do_wildcard_actions(ch_group, 0, luxes); } ch_group->is_working = false; @@ -4824,8 +4822,6 @@ void battery_manager(homekit_characteristic_t* ch, int value, bool is_free_monit homekit_characteristic_notify_safe(ch); } - do_wildcard_actions(ch_group, 0, value); - int status_low_changed = false; if (value <= BATTERY_LOW_THRESHOLD && BATTERY_STATUS_LOW_CH_INT == 0) { @@ -4848,6 +4844,8 @@ void battery_manager(homekit_characteristic_t* ch, int value, bool is_free_monit do_actions(ch_group, BATTERY_STATUS_LOW_CH_INT); } } + + do_wildcard_actions(ch_group, 0, value); } } @@ -5240,75 +5238,85 @@ void free_monitor_task(void* args) { read_value = get_hkch_value(ch_group_find_by_serv(read_service)->ch[(uint8_t) FM_MATHS_FLOAT[float_index]]); } else { - if (!main_config.clock_ready && read_service >= FM_MATHS_GET_TIME_IS_SAVING) { - get_value = false; - break; - } - - struct tm* timeinfo; - time_t time = raven_ntp_get_time(); - timeinfo = localtime(&time); - - switch (read_service) { - case FM_MATHS_GET_TIME_HOUR: - read_value = timeinfo->tm_hour; - break; - - case FM_MATHS_GET_TIME_MINUTE: - read_value = timeinfo->tm_min; - break; - - case FM_MATHS_GET_TIME_SECOND: - read_value = timeinfo->tm_sec; - break; - - case FM_MATHS_GET_TIME_DAYWEEK: - read_value = timeinfo->tm_wday; - break; - - case FM_MATHS_GET_TIME_DAYMONTH: - read_value = timeinfo->tm_mday; - break; - - case FM_MATHS_GET_TIME_MONTH: - read_value = timeinfo->tm_mon; - break; + if (read_service >= FM_MATHS_GET_TIME_UNIX) { + if (main_config.clock_ready) { + struct tm* timeinfo; + time_t time = raven_ntp_get_time(); + timeinfo = localtime(&time); - case FM_MATHS_GET_TIME_YEAR: - read_value = timeinfo->tm_year; - break; - - case FM_MATHS_GET_TIME_DAYYEAR: - read_value = timeinfo->tm_yday; - break; - - case FM_MATHS_GET_TIME_IS_SAVING: - read_value = timeinfo->tm_isdst; - break; + switch (read_service) { + case FM_MATHS_GET_TIME_HOUR: + read_value = timeinfo->tm_hour; + break; + + case FM_MATHS_GET_TIME_MINUTE: + read_value = timeinfo->tm_min; + break; + + case FM_MATHS_GET_TIME_SECOND: + read_value = timeinfo->tm_sec; + break; + + case FM_MATHS_GET_TIME_DAYWEEK: + read_value = timeinfo->tm_wday; + break; + + case FM_MATHS_GET_TIME_DAYMONTH: + read_value = timeinfo->tm_mday; + break; + + case FM_MATHS_GET_TIME_MONTH: + read_value = timeinfo->tm_mon; + break; + + case FM_MATHS_GET_TIME_YEAR: + read_value = timeinfo->tm_year; + break; + + case FM_MATHS_GET_TIME_DAYYEAR: + read_value = timeinfo->tm_yday; + break; + + case FM_MATHS_GET_TIME_IS_SAVING: + read_value = timeinfo->tm_isdst; + break; + + default: // case FM_MATHS_GET_TIME_UNIX: + read_value = time; + break; + } - case FM_MATHS_GEN_RANDOM_NUMBER: - read_value = hwrand() % (((uint32_t) FM_MATHS_FLOAT[float_index]) + 1); + } else { + get_value = false; break; + } + + } else { + switch (read_service) { + case FM_MATHS_GEN_RANDOM_NUMBER: + read_value = hwrand() % (((uint32_t) FM_MATHS_FLOAT[float_index]) + 1); + break; #ifdef ESP_PLATFORM - case FM_MATHS_GET_WIFI_RSSI: - int wifi_rssi = 0; - if (esp_wifi_sta_get_rssi(&wifi_rssi) != ESP_OK) { - get_value = false; - } - read_value = wifi_rssi; - break; + case FM_MATHS_GET_WIFI_RSSI: + int wifi_rssi = 0; + if (esp_wifi_sta_get_rssi(&wifi_rssi) != ESP_OK) { + get_value = false; + } + read_value = wifi_rssi; + break; #endif - case FM_MATHS_GET_UPTIME: - read_value = xTaskGetTickCount() / (1000 / portTICK_PERIOD_MS); - break; - - case FM_MATHS_GET_HK_CLIENT_IPADDR: - read_value = homekit_get_unique_client_ipaddr(); - break; - - default: // case FM_MATHS_GET_HK_CLIENT_COUNT: - read_value = homekit_get_client_count(); - break; + case FM_MATHS_GET_UPTIME: + read_value = xTaskGetTickCount() / (1000 / portTICK_PERIOD_MS); + break; + + case FM_MATHS_GET_HK_CLIENT_IPADDR: + read_value = homekit_get_unique_client_ipaddr(); + break; + + default: // case FM_MATHS_GET_HK_CLIENT_COUNT: + read_value = homekit_get_client_count(); + break; + } } } @@ -5705,7 +5713,10 @@ void free_monitor_task(void* args) { set_hkch_value(ch_target, value); } - do_wildcard_actions(ch_group, 0, value); + // Actions + if (ch_group->child_enabled) { + do_wildcard_actions(ch_group, 0, value); + } } } } @@ -6904,7 +6915,7 @@ void do_actions(ch_group_t* ch_group, uint8_t action) { INFO("<%i> DigO %i->%i (%"HAA_LONGINT_F")", ch_group->serv_index, action_binary_output->gpio, action_binary_output->value, action_binary_output->inching); if (action_binary_output->inching > 0) { - rs_esp_timer_start(rs_esp_timer_create(action_binary_output->inching, false, (void*) action_binary_output, autoswitch_timer)); + rs_esp_timer_start(rs_esp_timer_create(action_binary_output->inching, pdFALSE, (void*) action_binary_output, autoswitch_timer)); } } @@ -7366,9 +7377,9 @@ void do_actions(ch_group_t* ch_group, uint8_t action) { action_task->type = type; action_task->ch_group = ch_group; - timer_delay += portTICK_PERIOD_MS * 2; + timer_delay += portTICK_PERIOD_MS * 8; - TimerHandle_t xTimer = rs_esp_timer_create(timer_delay, true, action_task, action_task_timer); + TimerHandle_t xTimer = rs_esp_timer_create(timer_delay, pdTRUE, action_task, action_task_timer); if (rs_esp_timer_start(xTimer) != pdPASS) { free(action_task); rs_esp_timer_delete(xTimer); @@ -7508,10 +7519,10 @@ void run_homekit_server() { if (main_config.ntp_host && strcmp(main_config.ntp_host, NTP_DISABLE_STRING) == 0) { free(main_config.ntp_host); } else { - rs_esp_timer_start_forced(rs_esp_timer_create(NTP_POLL_PERIOD_MS, true, NULL, ntp_timer_worker)); + rs_esp_timer_start_forced(rs_esp_timer_create(NTP_POLL_PERIOD_MS, pdTRUE, NULL, ntp_timer_worker)); if (main_config.timetable_actions) { - rs_esp_timer_start_forced(rs_esp_timer_create(1000, true, NULL, timetable_actions_timer_worker)); + rs_esp_timer_start_forced(rs_esp_timer_create(1000, pdTRUE, NULL, timetable_actions_timer_worker)); } vTaskDelay(MS_TO_TICKS(500)); @@ -7527,11 +7538,11 @@ void run_homekit_server() { led_blink(4); - WIFI_WATCHDOG_TIMER = rs_esp_timer_create(WIFI_WATCHDOG_POLL_PERIOD_MS, true, NULL, wifi_watchdog); + WIFI_WATCHDOG_TIMER = rs_esp_timer_create(WIFI_WATCHDOG_POLL_PERIOD_MS, pdTRUE, NULL, wifi_watchdog); rs_esp_timer_start_forced(WIFI_WATCHDOG_TIMER); if (main_config.ping_inputs) { - rs_esp_timer_start_forced(rs_esp_timer_create(main_config.ping_poll_period * 1000.00f, true, NULL, ping_task_timer_worker)); + rs_esp_timer_start_forced(rs_esp_timer_create(main_config.ping_poll_period * 1000.00f, pdTRUE, NULL, ping_task_timer_worker)); } } @@ -8366,7 +8377,7 @@ void normal_mode_init() { if (cJSON_rsf_GetObjectItemCaseSensitive(json_accessory, AUTOSWITCH_TIME) != NULL) { const uint32_t time = cJSON_rsf_GetObjectItemCaseSensitive(json_accessory, AUTOSWITCH_TIME)->valuefloat * 1000.f; if (time > 0) { - return rs_esp_timer_create(time, false, (void*) ch_group, hkc_autooff_setter_task); + return rs_esp_timer_create(time, pdFALSE, (void*) ch_group, hkc_autooff_setter_task); } } return NULL; @@ -8461,7 +8472,7 @@ void normal_mode_init() { } void th_sensor_starter(ch_group_t* ch_group, float poll_period) { - ch_group->timer = rs_esp_timer_create(poll_period * 1000, true, (void*) ch_group, temperature_timer_worker); + ch_group->timer = rs_esp_timer_create(poll_period * 1000, pdTRUE, (void*) ch_group, temperature_timer_worker); } int virtual_stop(cJSON_rsf* json_accessory) { @@ -9403,7 +9414,7 @@ void normal_mode_init() { } if (main_config.setup_mode_toggle_counter_max > 0) { - main_config.setup_mode_toggle_timer = rs_esp_timer_create(SETUP_MODE_TOGGLE_TIME_MS, false, NULL, setup_mode_toggle); + main_config.setup_mode_toggle_timer = rs_esp_timer_create(SETUP_MODE_TOGGLE_TIME_MS, pdFALSE, NULL, setup_mode_toggle); } // Buttons to enter setup mode @@ -9723,7 +9734,7 @@ void normal_mode_init() { ch_group->ch[1]->value.int_value = initial_time; } - ch_group->timer = rs_esp_timer_create(1000, true, (void*) ch_group, on_timer_worker); + ch_group->timer = rs_esp_timer_create(1000, pdTRUE, (void*) ch_group, on_timer_worker); } diginput_register(cJSON_rsf_GetObjectItemCaseSensitive(json_context, BUTTONS_ARRAY), diginput, ch_group, 2); @@ -10052,8 +10063,6 @@ void normal_mode_init() { ping_register(cJSON_rsf_GetObjectItemCaseSensitive(json_context, FIXED_PINGS_STATUS_ARRAY_0), binary_sensor, ch_group, 2); ping_register(cJSON_rsf_GetObjectItemCaseSensitive(json_context, FIXED_PINGS_STATUS_ARRAY_1), binary_sensor, ch_group, 3); - const unsigned int exec_actions_on_boot = get_exec_actions_on_boot(json_context); - unsigned int initial_state = 4; if (diginput_register(cJSON_rsf_GetObjectItemCaseSensitive(json_context, FIXED_BUTTONS_ARRAY_0), binary_sensor, ch_group, 0)) { @@ -10071,7 +10080,7 @@ void normal_mode_init() { } if (initial_state < 4) { - if (!exec_actions_on_boot) { + if (!get_exec_actions_on_boot(json_context)) { initial_state += 2; } @@ -10252,7 +10261,7 @@ void normal_mode_init() { ch_group->ch[2]->value.int_value = initial_time; } - ch_group->timer = rs_esp_timer_create(1000, true, (void*) ch_group, valve_timer_worker); + ch_group->timer = rs_esp_timer_create(1000, pdTRUE, (void*) ch_group, valve_timer_worker); } if (ch_group->homekit_enabled) { @@ -10497,7 +10506,7 @@ void normal_mode_init() { TH_IAIRZONING_CONTROLLER = (uint8_t) cJSON_rsf_GetObjectItemCaseSensitive(json_context, THERMOSTAT_IAIRZONING_CONTROLLER)->valuefloat; } - ch_group->timer2 = rs_esp_timer_create(th_update_delay(json_context) * 1000, false, (void*) ch_group, process_th_timer); + ch_group->timer2 = rs_esp_timer_create(th_update_delay(json_context) * 1000, pdFALSE, (void*) ch_group, process_th_timer); const int sensor_gpio = TH_SENSOR_GPIO; @@ -10594,7 +10603,7 @@ void normal_mode_init() { IAIRZONING_DELAY_AFT_CLOSE_CH_GROUP = cJSON_rsf_GetObjectItemCaseSensitive(json_context, IAIRZONING_DELAY_AFT_CLOSE_SET)->valuefloat * MS_TO_TICKS(1000); } - ch_group->timer2 = rs_esp_timer_create(th_update_delay(json_context) * 1000, false, (void*) ch_group, set_zones_timer_worker); + ch_group->timer2 = rs_esp_timer_create(th_update_delay(json_context) * 1000, pdFALSE, (void*) ch_group, set_zones_timer_worker); th_sensor_starter(ch_group, sensor_poll_period(json_context, TH_SENSOR_POLL_PERIOD_DEFAULT)); } @@ -10918,7 +10927,7 @@ void normal_mode_init() { register_wildcard_actions(ch_group, json_context); const float poll_period = th_sensor(ch_group, json_context); - ch_group->timer2 = rs_esp_timer_create(th_update_delay(json_context) * 1000, false, (void*) ch_group, process_humidif_timer); + ch_group->timer2 = rs_esp_timer_create(th_update_delay(json_context) * 1000, pdFALSE, (void*) ch_group, process_humidif_timer); const int sensor_gpio = TH_SENSOR_GPIO; @@ -11062,7 +11071,7 @@ void normal_mode_init() { lightbulb_group->next = main_config.lightbulb_groups; main_config.lightbulb_groups = lightbulb_group; - LIGHTBULB_SET_DELAY_TIMER = rs_esp_timer_create(LIGHTBULB_SET_DELAY_MS, false, (void*) ch_group, lightbulb_task_timer); + LIGHTBULB_SET_DELAY_TIMER = rs_esp_timer_create(LIGHTBULB_SET_DELAY_MS, pdFALSE, (void*) ch_group, lightbulb_task_timer); LIGHTBULB_TYPE = LIGHTBULB_TYPE_PWM; if (cJSON_rsf_GetObjectItemCaseSensitive(json_context, LIGHTBULB_TYPE_SET) != NULL) { @@ -11083,7 +11092,7 @@ void normal_mode_init() { if (LIGHTBULB_TYPE != LIGHTBULB_TYPE_VIRTUAL) { if (!main_config.set_lightbulb_timer) { - main_config.set_lightbulb_timer = rs_esp_timer_create(RGBW_PERIOD, true, NULL, rgbw_set_timer_worker); + main_config.set_lightbulb_timer = rs_esp_timer_create(RGBW_PERIOD, pdTRUE, NULL, rgbw_set_timer_worker); } } @@ -11327,7 +11336,7 @@ void normal_mode_init() { ping_register(cJSON_rsf_GetObjectItemCaseSensitive(json_context, FIXED_PINGS_ARRAY_0), diginput, ch_group, 0); if (lightbulb_group->autodimmer_task_step > 0) { - LIGHTBULB_AUTODIMMER_TIMER = rs_esp_timer_create(AUTODIMMER_DELAY, false, (void*) ch_group->ch[0], no_autodimmer_called); + LIGHTBULB_AUTODIMMER_TIMER = rs_esp_timer_create(AUTODIMMER_DELAY, pdFALSE, (void*) ch_group->ch[0], no_autodimmer_called); } if (get_initial_state(json_context) != INIT_STATE_FIXED_INPUT) { @@ -11401,7 +11410,7 @@ void normal_mode_init() { GARAGE_DOOR_CLOSE_TIME_FACTOR = 1; GARAGE_DOOR_VIRTUAL_STOP = virtual_stop(json_context); - GARAGE_DOOR_WORKER_TIMER = rs_esp_timer_create(1000, true, (void*) ch_group, garage_door_timer_worker); + GARAGE_DOOR_WORKER_TIMER = rs_esp_timer_create(1000, pdTRUE, (void*) ch_group, garage_door_timer_worker); AUTOOFF_TIMER = autoswitch_time(json_context, ch_group); @@ -11566,9 +11575,9 @@ void normal_mode_init() { set_accessory_ir_protocol(ch_group, json_context); register_wildcard_actions(ch_group, json_context); - ch_group->timer = rs_esp_timer_create(WINDOW_COVER_TIMER_WORKER_PERIOD_MS, true, (void*) ch_group, window_cover_timer_worker); + ch_group->timer = rs_esp_timer_create(WINDOW_COVER_TIMER_WORKER_PERIOD_MS, pdTRUE, (void*) ch_group, window_cover_timer_worker); - ch_group->timer2 = rs_esp_timer_create(WINDOW_COVER_STOP_ENABLE_DELAY_MS, false, (void*) ch_group, window_cover_timer_rearm_stop); + ch_group->timer2 = rs_esp_timer_create(WINDOW_COVER_STOP_ENABLE_DELAY_MS, pdFALSE, (void*) ch_group, window_cover_timer_rearm_stop); if (cJSON_rsf_GetObjectItemCaseSensitive(json_context, WINDOW_COVER_TIME_OPEN_SET) != NULL) { WINDOW_COVER_TIME_OPEN = cJSON_rsf_GetObjectItemCaseSensitive(json_context, WINDOW_COVER_TIME_OPEN_SET)->valuefloat; @@ -11708,7 +11717,7 @@ void normal_mode_init() { } const float poll_period = sensor_poll_period(json_context, LIGHT_SENSOR_POLL_PERIOD_DEFAULT); - rs_esp_timer_start_forced(rs_esp_timer_create(poll_period * 1000, true, (void*) ch_group, light_sensor_timer_worker)); + rs_esp_timer_start_forced(rs_esp_timer_create(poll_period * 1000, pdTRUE, (void*) ch_group, light_sensor_timer_worker)); set_killswitch(ch_group, json_context); } @@ -11755,7 +11764,7 @@ void normal_mode_init() { SEC_SYSTEM_CH_CURRENT_STATE = NEW_HOMEKIT_CHARACTERISTIC(SECURITY_SYSTEM_CURRENT_STATE, target_valid_values[valid_values_len - 1], .min_value=(float[]) {current_valid_values[0]}, .valid_values={.count=valid_values_len + 1, .values=current_valid_values}); SEC_SYSTEM_CH_TARGET_STATE = NEW_HOMEKIT_CHARACTERISTIC(SECURITY_SYSTEM_TARGET_STATE, target_valid_values[valid_values_len - 1], .min_value=(float[]) {target_valid_values[0]}, .max_value=(float[]) {target_valid_values[valid_values_len - 1]}, .valid_values={.count=valid_values_len, .values=target_valid_values}, .setter_ex=hkc_sec_system); - SEC_SYSTEM_REC_ALARM_TIMER = rs_esp_timer_create(SEC_SYSTEM_REC_ALARM_PERIOD_MS, true, (void*) ch_group, sec_system_recurrent_alarm); + SEC_SYSTEM_REC_ALARM_TIMER = rs_esp_timer_create(SEC_SYSTEM_REC_ALARM_PERIOD_MS, pdTRUE, (void*) ch_group, sec_system_recurrent_alarm); register_actions(ch_group, json_context, 0); set_accessory_ir_protocol(ch_group, json_context); @@ -12014,7 +12023,7 @@ void normal_mode_init() { AUTOOFF_TIMER = autoswitch_time(json_context, ch_group); if (ch_group->homekit_enabled) { - FAN_SET_DELAY_TIMER = rs_esp_timer_create(FAN_SET_DELAY_MS, false, (void*) ch_group, process_fan_timer); // Only used with HomeKit + FAN_SET_DELAY_TIMER = rs_esp_timer_create(FAN_SET_DELAY_MS, pdFALSE, (void*) ch_group, process_fan_timer); // Only used with HomeKit accessories[accessory]->services[service] = calloc(1, sizeof(homekit_service_t)); accessories[accessory]->services[service]->id = ((service - 1) * 50) + 8; @@ -12265,7 +12274,7 @@ void normal_mode_init() { if (pm_sensor_type <= 4) { PM_POLL_PERIOD = sensor_poll_period(json_context, PM_POLL_PERIOD_DEFAULT); - rs_esp_timer_start_forced(rs_esp_timer_create(PM_POLL_PERIOD * 1000, true, (void*) ch_group, power_monitor_timer_worker)); + rs_esp_timer_start_forced(rs_esp_timer_create(PM_POLL_PERIOD * 1000, pdTRUE, (void*) ch_group, power_monitor_timer_worker)); } set_killswitch(ch_group, json_context); @@ -12595,7 +12604,7 @@ void normal_mode_init() { fm_sensor_type < FM_SENSOR_TYPE_UART) { const float poll_period = sensor_poll_period(json_context, FM_POLL_PERIOD_DEFAULT); if (poll_period > 0) { - rs_esp_timer_start_forced(rs_esp_timer_create(poll_period * 1000, true, (void*) ch_group, free_monitor_timer_worker)); + rs_esp_timer_start_forced(rs_esp_timer_create(poll_period * 1000, pdTRUE, (void*) ch_group, free_monitor_timer_worker)); } } @@ -12663,7 +12672,7 @@ void normal_mode_init() { const float poll_period = sensor_poll_period(json_context, 0); if (poll_period > 0.00f) { - rs_esp_timer_start_forced(rs_esp_timer_create(poll_period * 1000, true, (void*) ch_group->ch[hist_size], data_history_timer_worker)); + rs_esp_timer_start_forced(rs_esp_timer_create(poll_period * 1000, pdTRUE, (void*) ch_group->ch[hist_size], data_history_timer_worker)); } set_killswitch(ch_group, json_context); @@ -12680,7 +12689,7 @@ void normal_mode_init() { set_killswitch(root_device_ch_group, json_config); // Saved States Timer Function - root_device_ch_group->timer = rs_esp_timer_create(SAVE_STATES_DELAY_MS, false, NULL, save_states); + root_device_ch_group->timer = rs_esp_timer_create(SAVE_STATES_DELAY_MS, pdFALSE, NULL, save_states); // Run action 0 from root device do_actions(root_device_ch_group, 0); @@ -12939,7 +12948,7 @@ void normal_mode_init() { if (re_pair == 1) { config.re_pair = true; sysparam_erase(HOMEKIT_RE_PAIR_SYSPARAM); - rs_esp_timer_start_forced(rs_esp_timer_create(HOMEKIT_RE_PAIR_TIME_MS, false, NULL, homekit_re_pair_timer)); + rs_esp_timer_start_forced(rs_esp_timer_create(HOMEKIT_RE_PAIR_TIME_MS, pdFALSE, NULL, homekit_re_pair_timer)); } main_config.setup_mode_toggle_counter = 0; @@ -12954,7 +12963,7 @@ void normal_mode_init() { #else uart_flush_rxfifo(0); #endif - rs_esp_timer_start_forced(rs_esp_timer_create(RECV_UART_POLL_PERIOD_MS, true, NULL, recv_uart_timer_worker)); + rs_esp_timer_start_forced(rs_esp_timer_create(RECV_UART_POLL_PERIOD_MS, pdTRUE, NULL, recv_uart_timer_worker)); } int8_t wifi_mode = 0; @@ -13199,11 +13208,11 @@ void init_task() { if (haa_setup == 1) { #ifdef HAA_DEBUG free_heap_watchdog(); - rs_esp_timer_start_forced(rs_esp_timer_create(1000, true, NULL, free_heap_watchdog)); + rs_esp_timer_start_forced(rs_esp_timer_create(1000, pdTRUE, NULL, free_heap_watchdog)); #endif // HAA_DEBUG // Arming emergency Setup Mode - rs_esp_timer_start_forced(rs_esp_timer_create(EXIT_EMERGENCY_SETUP_MODE_TIME, false, NULL, disable_emergency_setup)); + rs_esp_timer_start_forced(rs_esp_timer_create(EXIT_EMERGENCY_SETUP_MODE_TIME, pdFALSE, NULL, disable_emergency_setup)); name.value = HOMEKIT_STRING(main_config.name_value, .is_static=true); diff --git a/HAA/HAA_Main/main/setup.c b/HAA/HAA_Main/main/setup.c index fb722041..c8a49f8d 100644 --- a/HAA/HAA_Main/main/setup.c +++ b/HAA/HAA_Main/main/setup.c @@ -1597,7 +1597,7 @@ static void wifi_config_station_connect() { if (setup_mode == 1) { INFO("Auto reboot"); - context->auto_reboot_timer = rs_esp_timer_create(AUTO_REBOOT_TIMEOUT, false, NULL, auto_reboot_run); + context->auto_reboot_timer = rs_esp_timer_create(AUTO_REBOOT_TIMEOUT, pdFALSE, NULL, auto_reboot_run); rs_esp_timer_start_forced(context->auto_reboot_timer); } else if (setup_mode == 2) { ERROR("Script"); diff --git a/libs/adv_button/adv_button.c b/libs/adv_button/adv_button.c index b1dfeea3..e2f52fa5 100644 --- a/libs/adv_button/adv_button.c +++ b/libs/adv_button/adv_button.c @@ -37,7 +37,7 @@ #include #include "adv_button.h" -#define ADV_BUTTON_DEFAULT_EVAL (5) +#define ADV_BUTTON_DEFAULT_EVAL (4) #define DOUBLEPRESS_TIME (450) #define LONGPRESS_TIME (DOUBLEPRESS_TIME + 10) @@ -330,6 +330,8 @@ static void IRAM adv_button_interrupt_normal(const uint8_t gpio) { if (xHigherPriorityTaskWoken != pdFALSE) { portYIELD_FROM_ISR(); } +#else + portEND_SWITCHING_ISR(xHigherPriorityTaskWoken); #endif } @@ -447,7 +449,7 @@ void adv_button_init(const uint16_t new_delay_ms, const bool continuos_mode) { } adv_button_main_config->button_evaluate_sleep_time = ((HOLDPRESS_TIME + 1000) / portTICK_PERIOD_MS) / adv_button_main_config->button_evaluate_delay; - adv_button_main_config->button_evaluate_timer = rs_esp_timer_create(adv_button_main_config->button_evaluate_delay * portTICK_PERIOD_MS, true, NULL, button_evaluate_fn); + adv_button_main_config->button_evaluate_timer = rs_esp_timer_create(adv_button_main_config->button_evaluate_delay * portTICK_PERIOD_MS, pdTRUE, NULL, button_evaluate_fn); adv_button_main_config->continuos_mode = continuos_mode; @@ -633,7 +635,7 @@ int adv_button_register_callback_fn(const uint16_t gpio, const button_callback_f case DOUBLEPRESS_TYPE: if (!button->press_timer) { - button->press_timer = rs_esp_timer_create(DOUBLEPRESS_TIME, false, (void*) button, adv_button_single_callback); + button->press_timer = rs_esp_timer_create(DOUBLEPRESS_TIME, pdFALSE, (void*) button, adv_button_single_callback); } adv_button_callback_fn->next = button->doublepress_callback_fn; button->doublepress_callback_fn = adv_button_callback_fn; @@ -651,7 +653,7 @@ int adv_button_register_callback_fn(const uint16_t gpio, const button_callback_f case HOLDPRESS_TYPE: if (!button->hold_timer) { - button->hold_timer = rs_esp_timer_create(HOLDPRESS_TIME, false, (void*) button, adv_button_hold_callback); + button->hold_timer = rs_esp_timer_create(HOLDPRESS_TIME, pdFALSE, (void*) button, adv_button_hold_callback); } adv_button_callback_fn->next = button->holdpress_callback_fn; button->holdpress_callback_fn = adv_button_callback_fn; diff --git a/libs/adv_logger/adv_logger.c b/libs/adv_logger/adv_logger.c index 63c0f2e0..3dd11eca 100644 --- a/libs/adv_logger/adv_logger.c +++ b/libs/adv_logger/adv_logger.c @@ -176,11 +176,11 @@ static void adv_logger_buffered_task() { i = 0; } - vTaskDelay(pdMS_TO_TICKS(10)); + vTaskDelay(10 / portTICK_PERIOD_MS); if (adv_logger_data->close_buffered_task #ifdef ESP_PLATFORM - && xSemaphoreTake(adv_logger_data->log_sender_semaphore, pdMS_TO_TICKS(100)) == pdTRUE + && xSemaphoreTake(adv_logger_data->log_sender_semaphore, 100 / portTICK_PERIOD_MS) == pdTRUE #endif ) { @@ -201,7 +201,7 @@ static void adv_logger_init_task(void* args) { #ifdef ESP_PLATFORM while (!adv_logger_data->ip_address) { - vTaskDelay(pdMS_TO_TICKS(200)); + vTaskDelay(200 / portTICK_PERIOD_MS); } esp_wifi_get_mac(WIFI_IF_STA, macaddr); @@ -209,7 +209,7 @@ static void adv_logger_init_task(void* args) { free(adv_logger_data->ip_address); #else while (sdk_wifi_station_get_connect_status() != STATION_GOT_IP) { - vTaskDelay(pdMS_TO_TICKS(200)); + vTaskDelay(200 / portTICK_PERIOD_MS); } struct ip_info info; @@ -225,11 +225,11 @@ static void adv_logger_init_task(void* args) { }; while (getaddrinfo(ADV_LOGGER_ADDRESS, ADV_LOGGER_PORT, &hints, &adv_logger_data->res) != 0) { - vTaskDelay(pdMS_TO_TICKS(200)); + vTaskDelay(200 / portTICK_PERIOD_MS); } while ((adv_logger_data->socket = lwip_socket(adv_logger_data->res->ai_family, adv_logger_data->res->ai_socktype, 0)) < 0) { - vTaskDelay(pdMS_TO_TICKS(200)); + vTaskDelay(200 / portTICK_PERIOD_MS); } adv_logger_data->udplogstring = malloc(UDP_LOG_LEN); diff --git a/libs/adv_logger_ntp/adv_logger_ntp.c b/libs/adv_logger_ntp/adv_logger_ntp.c index 7dc4f233..4a7981f1 100644 --- a/libs/adv_logger_ntp/adv_logger_ntp.c +++ b/libs/adv_logger_ntp/adv_logger_ntp.c @@ -262,7 +262,7 @@ static void adv_logger_buffered_task() { i = 0; } - vTaskDelay(pdMS_TO_TICKS(10)); + vTaskDelay(10 / portTICK_PERIOD_MS); } } @@ -271,11 +271,11 @@ static void adv_logger_init_task(void* args) { #ifdef ESP_PLATFORM while (!adv_logger_data->ip_address) { - vTaskDelay(pdMS_TO_TICKS(200)); + vTaskDelay(200 / portTICK_PERIOD_MS); } #else while (sdk_wifi_station_get_connect_status() != STATION_GOT_IP) { - vTaskDelay(pdMS_TO_TICKS(200)); + vTaskDelay(200 / portTICK_PERIOD_MS); } #endif @@ -306,13 +306,13 @@ static void adv_logger_init_task(void* args) { dest_port += 1; while (getaddrinfo(destination, dest_port, &hints, &adv_logger_data->res) != 0) { - vTaskDelay(pdMS_TO_TICKS(200)); + vTaskDelay(200 / portTICK_PERIOD_MS); } free(args); // destination and port while ((adv_logger_data->socket = lwip_socket(adv_logger_data->res->ai_family, adv_logger_data->res->ai_socktype, 0)) < 0) { - vTaskDelay(pdMS_TO_TICKS(200)); + vTaskDelay(200 / portTICK_PERIOD_MS); } if (adv_logger_data->is_buffered) { diff --git a/libs/homekit-rsf/src/mdnsresponder.c b/libs/homekit-rsf/src/mdnsresponder.c index 977c58be..2dc9f994 100644 --- a/libs/homekit-rsf/src/mdnsresponder.c +++ b/libs/homekit-rsf/src/mdnsresponder.c @@ -720,7 +720,7 @@ void mdns_add_facility_work(const char* instanceName, // Friendly name, need n free(fullName); free(devName); - mdns_announce_timer = rs_esp_timer_create((MDNS_TTL_SAFE_MARGIN * MDNS_TTL_MULTIPLIER_MS), true, NULL, mdns_announce); + mdns_announce_timer = rs_esp_timer_create((MDNS_TTL_SAFE_MARGIN * MDNS_TTL_MULTIPLIER_MS), pdTRUE, NULL, mdns_announce); mdns_announce_start(); } diff --git a/libs/new_dht/dht.c b/libs/new_dht/dht.c index 69a89271..8949fdd0 100644 --- a/libs/new_dht/dht.c +++ b/libs/new_dht/dht.c @@ -191,7 +191,7 @@ bool dht_read_data(dht_sensor_type_t sensor_type, uint8_t pin, int16_t *humidity uint8_t data[DHT_DATA_BITS / 8] = { 0 }; bool result = false; - if (xSemaphoreTake(dht_lock, pdMS_TO_TICKS(DHT_TIMEOUT_MS)) == pdTRUE) { + if (xSemaphoreTake(dht_lock, DHT_TIMEOUT_MS / portTICK_PERIOD_MS) == pdTRUE) { #ifdef ESP_PLATFORM gpio_set_direction(pin, GPIO_MODE_OUTPUT_OD); @@ -217,7 +217,7 @@ bool dht_read_data(dht_sensor_type_t sensor_type, uint8_t pin, int16_t *humidity gpio_enable(pin, GPIO_INPUT); #endif - vTaskDelay(pdMS_TO_TICKS(20)); + vTaskDelay(20 / portTICK_PERIOD_MS); xSemaphoreGive(dht_lock); } diff --git a/libs/timers_helper/timers_helper.c b/libs/timers_helper/timers_helper.c index b90f8fb8..ddfa2906 100644 --- a/libs/timers_helper/timers_helper.c +++ b/libs/timers_helper/timers_helper.c @@ -37,7 +37,7 @@ BaseType_t rs_esp_timer_manager(const uint8_t option, TimerHandle_t xTimer, Tick BaseType_t rs_esp_timer_change_period_manager(TimerHandle_t xTimer, const uint32_t new_period_ms, TickType_t xBlockTime) { if (xTimer) { - return xTimerChangePeriod(xTimer, pdMS_TO_TICKS(new_period_ms), xBlockTime); + return xTimerChangePeriod(xTimer, new_period_ms / portTICK_PERIOD_MS, xBlockTime); } return pdFALSE; @@ -59,23 +59,17 @@ BaseType_t IRAM rs_esp_timer_manager_from_ISR(const uint8_t option, TimerHandle_ return pdFALSE; } -TimerHandle_t rs_esp_timer_create(const uint32_t period_ms, const bool auto_reload, void* pvTimerID, TimerCallbackFunction_t pxCallbackFunction) { - UBaseType_t uxAutoReload = pdFALSE; - if (auto_reload) { - uxAutoReload = pdTRUE; - } - - uint8_t tries = 0; +TimerHandle_t rs_esp_timer_create(const uint32_t period_ms, const UBaseType_t auto_reload, void* pvTimerID, TimerCallbackFunction_t pxCallbackFunction) { + unsigned int tries = 0; - TimerHandle_t result = xTimerCreate(0, pdMS_TO_TICKS(period_ms), uxAutoReload, pvTimerID, pxCallbackFunction); - while (!result) { + TimerHandle_t result; + while (!(result = xTimerCreate(NULL, period_ms / portTICK_PERIOD_MS, auto_reload, pvTimerID, pxCallbackFunction))) { tries++; - printf("! Timer Create Failed (%i/%i)\n", tries, XTIMER_MAX_TRIES); + //printf("! Timer Create Failed (%i/%i)\n", tries, XTIMER_MAX_TRIES); if (tries == XTIMER_MAX_TRIES) { break; } vTaskDelay(tries); - result = xTimerCreate(0, pdMS_TO_TICKS(period_ms), uxAutoReload, pvTimerID, pxCallbackFunction); } return result; diff --git a/libs/timers_helper/timers_helper.h b/libs/timers_helper/timers_helper.h index ce92bbc9..6dc4df5e 100644 --- a/libs/timers_helper/timers_helper.h +++ b/libs/timers_helper/timers_helper.h @@ -47,7 +47,7 @@ BaseType_t rs_esp_timer_manager(const uint8_t option, TimerHandle_t xTimer, Tick BaseType_t rs_esp_timer_change_period_manager(TimerHandle_t xTimer, const uint32_t new_period_ms, TickType_t xBlockTime); BaseType_t rs_esp_timer_manager_from_ISR(const uint8_t option, TimerHandle_t xTimer); -TimerHandle_t rs_esp_timer_create(const uint32_t period_ms, const bool auto_reload, void* pvTimerID, TimerCallbackFunction_t pxCallbackFunction); +TimerHandle_t rs_esp_timer_create(const uint32_t period_ms, const UBaseType_t auto_reload, void* pvTimerID, TimerCallbackFunction_t pxCallbackFunction); #ifdef __cplusplus } diff --git a/sdk/esp-open-rtos-rsf/core/app_main.c b/sdk/esp-open-rtos-rsf/core/app_main.c index 45f3cf51..c968387e 100644 --- a/sdk/esp-open-rtos-rsf/core/app_main.c +++ b/sdk/esp-open-rtos-rsf/core/app_main.c @@ -492,7 +492,7 @@ static __attribute__((noinline)) void user_start_phase2(void) { tcpip_init(NULL, NULL); sdk_wdt_init(); - xTaskCreate(sdk_user_init_task, NULL, configMINIMAL_STACK_SIZE, NULL, 14, &sdk_xUserTaskHandle); + xTaskCreate(sdk_user_init_task, NULL, configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, &sdk_xUserTaskHandle); vTaskStartScheduler(); } /* diff --git a/sdk/esp-open-rtos-rsf/lwip/include/arch/cc.h b/sdk/esp-open-rtos-rsf/lwip/include/arch/cc.h index a88c4139..c9c5db8a 100644 --- a/sdk/esp-open-rtos-rsf/lwip/include/arch/cc.h +++ b/sdk/esp-open-rtos-rsf/lwip/include/arch/cc.h @@ -90,6 +90,7 @@ typedef int sys_prot_t; #else #define LWIP_PLATFORM_DIAG(x) #define LWIP_PLATFORM_ASSERT(x) +#define LWIP_NOASSERT 1 #endif #define LWIP_PLATFORM_BYTESWAP 1 diff --git a/sdk/esp-open-rtos-rsf/lwip/include/lwipopts.h b/sdk/esp-open-rtos-rsf/lwip/include/lwipopts.h index 57c6f051..e5981f7b 100644 --- a/sdk/esp-open-rtos-rsf/lwip/include/lwipopts.h +++ b/sdk/esp-open-rtos-rsf/lwip/include/lwipopts.h @@ -582,7 +582,7 @@ void sys_unlock_tcpip_core(void); * The priority value itself is platform-dependent, but is passed to * sys_thread_new() when the thread is created. */ -#define TCPIP_THREAD_PRIO (configMAX_PRIORITIES-5) +#define TCPIP_THREAD_PRIO (configMAX_PRIORITIES-7) /** * TCPIP_MBOX_SIZE: The mailbox size for the tcpip thread messages diff --git a/sdk/esp-open-rtos-rsf/lwip/lwip/src/apps/lwiperf/lwiperf.c b/sdk/esp-open-rtos-rsf/lwip/lwip/src/apps/lwiperf/lwiperf.c index 274a78ec..f6a0511f 100644 --- a/sdk/esp-open-rtos-rsf/lwip/lwip/src/apps/lwiperf/lwiperf.c +++ b/sdk/esp-open-rtos-rsf/lwip/lwip/src/apps/lwiperf/lwiperf.c @@ -407,7 +407,9 @@ lwiperf_tx_start(lwiperf_state_tcp_t *conn) static err_t lwiperf_tcp_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) { +#ifndef LWIP_NOASSERT u8_t tmp; +#endif u16_t tot_len; u32_t packet_idx; struct pbuf *q; @@ -477,8 +479,12 @@ lwiperf_tcp_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) return ERR_OK; } conn->next_num = 4; /* 24 bytes received... */ +#ifndef LWIP_NOASSERT tmp = pbuf_remove_header(p, 24); LWIP_ASSERT("pbuf_remove_header failed", tmp == 0); +#else + pbuf_remove_header(p, 24); +#endif } packet_idx = 0; diff --git a/sdk/esp-open-rtos-rsf/lwip/lwip/src/core/ipv4/dhcp.c b/sdk/esp-open-rtos-rsf/lwip/lwip/src/core/ipv4/dhcp.c index 991ea473..26da21e0 100644 --- a/sdk/esp-open-rtos-rsf/lwip/lwip/src/core/ipv4/dhcp.c +++ b/sdk/esp-open-rtos-rsf/lwip/lwip/src/core/ipv4/dhcp.c @@ -227,6 +227,30 @@ static u16_t dhcp_option_hostname(u16_t options_out_len, u8_t *options, struct n /* always add the DHCP options trailer to end and pad */ static void dhcp_option_trailer(u16_t options_out_len, u8_t *options, struct pbuf *p_out); +static u16_t dhcp_calculated_fine_time(const u32_t msecs) { + return (u16_t) ((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS); +} + +static u16_t dhcp_calculated_coarse_time(const u32_t secs) { +#if LWIP_DHCP_RANDOMIZE_COARSE_TIME_SECS + int timeout = ((secs + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS) - (hwrand() % (LWIP_DHCP_RANDOMIZE_COARSE_TIME_SECS + 1)); +#else + u32_t timeout = (secs + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS; +#endif + + if (timeout > 0xffff) { + timeout = 0xffff; +#if LWIP_DHCP_RANDOMIZE_COARSE_TIME_SECS + } else if (timeout <= 0) { +#else + } else if (timeout == 0) { +#endif + timeout = 1; + } + + return (u16_t) timeout; +} + /** Ensure DHCP PCB is allocated and bound */ static err_t dhcp_inc_pcb_refcount(void) @@ -324,7 +348,7 @@ dhcp_check(struct netif *netif) dhcp->tries++; } msecs = 500; - dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS); + dhcp->request_timeout = dhcp_calculated_fine_time(msecs); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_check(): set request timeout %"U16_F" msecs\n", msecs)); } #endif /* DHCP_DOES_ARP_CHECK */ @@ -422,7 +446,7 @@ dhcp_select(struct netif *netif) dhcp->tries++; } msecs = (u16_t)((dhcp->tries < 6 ? 1 << dhcp->tries : 60) * 1000); - dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS); + dhcp->request_timeout = dhcp_calculated_fine_time(msecs); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_select(): set request timeout %"U16_F" msecs\n", msecs)); return result; } @@ -973,7 +997,7 @@ dhcp_decline(struct netif *netif) dhcp->tries++; } msecs = 10 * 1000; - dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS); + dhcp->request_timeout = dhcp_calculated_fine_time(msecs); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_decline(): set request timeout %"U16_F" msecs\n", msecs)); return result; } @@ -1033,7 +1057,7 @@ dhcp_discover(struct netif *netif) } #endif /* LWIP_DHCP_AUTOIP_COOP */ msecs = (u16_t)((dhcp->tries < 6 ? 1 << dhcp->tries : 60) * LWIP_DHCP_RETRY_TIMEOUT); - dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS); + dhcp->request_timeout = dhcp_calculated_fine_time(msecs); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_discover(): set request timeout %"U16_F" msecs\n", msecs)); return result; } @@ -1047,7 +1071,6 @@ dhcp_discover(struct netif *netif) static void dhcp_bind(struct netif *netif) { - u32_t timeout; struct dhcp *dhcp; ip4_addr_t sn_mask, gw_addr; LWIP_ERROR("dhcp_bind: netif != NULL", (netif != NULL), return;); @@ -1061,14 +1084,7 @@ dhcp_bind(struct netif *netif) if (dhcp->offered_t0_lease != 0xffffffffUL) { /* set renewal period timer */ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_bind(): t0 renewal timer %"U32_F" secs\n", dhcp->offered_t0_lease)); - timeout = (dhcp->offered_t0_lease + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS; - if (timeout > 0xffff) { - timeout = 0xffff; - } - dhcp->t0_timeout = (u16_t)timeout; - if (dhcp->t0_timeout == 0) { - dhcp->t0_timeout = 1; - } + dhcp->t0_timeout = dhcp_calculated_coarse_time(dhcp->offered_t0_lease); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_bind(): set request timeout %"U32_F" msecs\n", dhcp->offered_t0_lease * 1000)); } @@ -1076,28 +1092,14 @@ dhcp_bind(struct netif *netif) if (dhcp->offered_t1_renew != 0xffffffffUL) { /* set renewal period timer */ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_bind(): t1 renewal timer %"U32_F" secs\n", dhcp->offered_t1_renew)); - timeout = (dhcp->offered_t1_renew + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS; - if (timeout > 0xffff) { - timeout = 0xffff; - } - dhcp->t1_timeout = (u16_t)timeout; - if (dhcp->t1_timeout == 0) { - dhcp->t1_timeout = 1; - } + dhcp->t1_timeout = dhcp_calculated_coarse_time(dhcp->offered_t1_renew); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_bind(): set request timeout %"U32_F" msecs\n", dhcp->offered_t1_renew * 1000)); dhcp->t1_renew_time = dhcp->t1_timeout; } /* set renewal period timer */ if (dhcp->offered_t2_rebind != 0xffffffffUL) { LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_bind(): t2 rebind timer %"U32_F" secs\n", dhcp->offered_t2_rebind)); - timeout = (dhcp->offered_t2_rebind + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS; - if (timeout > 0xffff) { - timeout = 0xffff; - } - dhcp->t2_timeout = (u16_t)timeout; - if (dhcp->t2_timeout == 0) { - dhcp->t2_timeout = 1; - } + dhcp->t2_timeout = dhcp_calculated_coarse_time(dhcp->offered_t2_rebind); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_bind(): set request timeout %"U32_F" msecs\n", dhcp->offered_t2_rebind * 1000)); dhcp->t2_rebind_time = dhcp->t2_timeout; } @@ -1204,7 +1206,7 @@ dhcp_renew(struct netif *netif) } /* back-off on retries, but to a maximum of 20 seconds */ msecs = (u16_t)(dhcp->tries < 10 ? dhcp->tries * 2000 : 20 * 1000); - dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS); + dhcp->request_timeout = dhcp_calculated_fine_time(msecs); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_renew(): set request timeout %"U16_F" msecs\n", msecs)); return result; } @@ -1258,7 +1260,7 @@ dhcp_rebind(struct netif *netif) dhcp->tries++; } msecs = (u16_t)(dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000); - dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS); + dhcp->request_timeout = dhcp_calculated_fine_time(msecs); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_rebind(): set request timeout %"U16_F" msecs\n", msecs)); return result; } @@ -1310,7 +1312,7 @@ dhcp_reboot(struct netif *netif) dhcp->tries++; } msecs = (u16_t)(dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000); - dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS); + dhcp->request_timeout = dhcp_calculated_fine_time(msecs); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_reboot(): set request timeout %"U16_F" msecs\n", msecs)); return result; } diff --git a/sdk/esp-open-rtos-rsf/lwip/sys_arch.c b/sdk/esp-open-rtos-rsf/lwip/sys_arch.c index 52f53302..2cb3619b 100644 --- a/sdk/esp-open-rtos-rsf/lwip/sys_arch.c +++ b/sdk/esp-open-rtos-rsf/lwip/sys_arch.c @@ -80,8 +80,12 @@ err_t sys_sem_new(sys_sem_t *pxSemaphore, u8_t initial_count) SYS_STATS_INC_USED(sem); if (initial_count == 1) { +#ifndef LWIP_NOASSERT BaseType_t ret = xSemaphoreGive(*pxSemaphore); LWIP_ASSERT("sys_sem_new: initial give failed", ret == pdTRUE); +#else + xSemaphoreGive(*pxSemaphore); +#endif } return ERR_OK; } @@ -178,8 +182,12 @@ void sys_mutex_lock(sys_mutex_t *pxMutex) * @param mutex the mutex to unlock */ void sys_mutex_unlock(sys_mutex_t *pxMutex) { +#ifndef LWIP_NOASSERT BaseType_t ret = xSemaphoreGiveRecursive(*pxMutex); LWIP_ASSERT("failed to give the mutex", ret == pdTRUE); +#else + xSemaphoreGiveRecursive(*pxMutex); +#endif } diff --git a/sdk/esp-open-rtos-rsf/open_esplibs/libmain/ets_timer.c b/sdk/esp-open-rtos-rsf/open_esplibs/libmain/ets_timer.c index 7b3ca362..57e7a5e4 100644 --- a/sdk/esp-open-rtos-rsf/open_esplibs/libmain/ets_timer.c +++ b/sdk/esp-open-rtos-rsf/open_esplibs/libmain/ets_timer.c @@ -322,8 +322,10 @@ void sdk_ets_timer_init() * xTaskGenericCreate(task_handle, "rtc_timer_task", 200, 0, 12, &handle, * NULL, NULL); */ - xTaskCreate(timer_task, "rtc_timer_task", 200, 0, 12, &task_handle); - printf("frc2_timer_task_hdl:%p, prio:%d, stack:%d\n", task_handle, 12, 200); + //xTaskCreate(timer_task, "rtc_timer_task", 200, 0, 12, &task_handle); + //printf("frc2_timer_task_hdl:%p, prio:%d, stack:%d\n", task_handle, 12, 200); + + xTaskCreate(timer_task, "rtc", configMINIMAL_STACK_SIZE, 0, configMAX_PRIORITIES - 3, &task_handle); TIMER_FRC2.ALARM = 0; TIMER_FRC2.CTRL = VAL2FIELD(TIMER_CTRL_CLKDIV, TIMER_CLKDIV_16) diff --git a/sdk/esp-open-rtos-rsf/open_esplibs/libmain/user_interface.c b/sdk/esp-open-rtos-rsf/open_esplibs/libmain/user_interface.c index 48377d8a..4bc97f5f 100644 --- a/sdk/esp-open-rtos-rsf/open_esplibs/libmain/user_interface.c +++ b/sdk/esp-open-rtos-rsf/open_esplibs/libmain/user_interface.c @@ -479,8 +479,8 @@ void sdk_system_station_got_ip_set(struct ip4_addr *ip, struct ip4_addr *mask, s uint32_t gpio_mask; sdk_g_ic.v.station_netif_info->connect_status = STATION_GOT_IP; - printf("IP:%d.%d.%d.%d/%d.%d.%d.%d GW:%d.%d.%d.%d", ip_bytes[0], ip_bytes[1], ip_bytes[2], ip_bytes[3], mask_bytes[0], mask_bytes[1], mask_bytes[2], mask_bytes[3], gw_bytes[0], gw_bytes[1], gw_bytes[2], gw_bytes[3]); - printf("\n"); + printf("IP:%d.%d.%d.%d/%d.%d.%d.%d GW:%d.%d.%d.%d\n", ip_bytes[0], ip_bytes[1], ip_bytes[2], ip_bytes[3], mask_bytes[0], mask_bytes[1], mask_bytes[2], mask_bytes[3], gw_bytes[0], gw_bytes[1], gw_bytes[2], gw_bytes[3]); + if ((sdk_g_ic.s.wifi_led_enable == 1) && (sdk_g_ic.s.wifi_mode == 1)) { sdk_os_timer_disarm(&sdk_sta_con_timer); gpio_mask = 1 << sdk_g_ic.s.wifi_led_gpio; diff --git a/sdk/esp-open-rtos-rsf/open_esplibs/libwpa/wpa_main.c b/sdk/esp-open-rtos-rsf/open_esplibs/libwpa/wpa_main.c index 8ca4de4a..8b3d6f72 100644 --- a/sdk/esp-open-rtos-rsf/open_esplibs/libwpa/wpa_main.c +++ b/sdk/esp-open-rtos-rsf/open_esplibs/libwpa/wpa_main.c @@ -79,7 +79,7 @@ void sdk_eagle_auth_done() { uint32_t channel = cnx_node->channel->num; char *ssid = (char *)sdk_g_ic.s.sta_ssid.ssid; - printf("Connected to %s Ch%d\n", ssid, channel); + printf("Connected %s Ch%d\n", ssid, channel); RTCMEM_SYSTEM[61] = 0x00010000 | channel; @@ -94,9 +94,9 @@ void sdk_eagle_auth_done() { if (dhcp_supplied_address(netif)) return; - + if (sdk_dhcpc_flag != DHCP_STOPPED) { - printf("DHCP client start\n"); + printf("DHCP start\n"); LOCK_TCPIP_CORE(); netif_set_up(netif); dhcp_start(netif);