diff --git a/components/esp_timer/include/esp_timer.h b/components/esp_timer/include/esp_timer.h index 8d91e261a1..171aba979c 100644 --- a/components/esp_timer/include/esp_timer.h +++ b/components/esp_timer/include/esp_timer.h @@ -52,7 +52,6 @@ typedef struct esp_timer* esp_timer_handle_t; */ typedef void (*esp_timer_cb_t)(void* arg); - /** * @brief Method for dispatching timer callback */ @@ -75,7 +74,6 @@ typedef struct { bool skip_unhandled_events; //!< Skip unhandled events for periodic timers } esp_timer_create_args_t; - /** * @brief Minimal initialization of esp_timer * diff --git a/components/esp_timer/private_include/esp_timer_impl.h b/components/esp_timer/private_include/esp_timer_impl.h index 3977d6719f..d6484cbb95 100644 --- a/components/esp_timer/private_include/esp_timer_impl.h +++ b/components/esp_timer/private_include/esp_timer_impl.h @@ -112,7 +112,6 @@ uint64_t esp_timer_impl_get_min_period_us(void); */ void esp_timer_impl_lock(void); - /** * @brief counterpart of esp_timer_impl_lock */ diff --git a/components/esp_timer/src/esp_timer.c b/components/esp_timer/src/esp_timer.c index 7440a2c935..9308a12f8c 100644 --- a/components/esp_timer/src/esp_timer.c +++ b/components/esp_timer/src/esp_timer.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -62,8 +62,8 @@ typedef enum { struct esp_timer { uint64_t alarm; - uint64_t period:56; - flags_t flags:8; + uint64_t period: 56; + flags_t flags: 8; union { esp_timer_cb_t callback; uint32_t event_id; @@ -95,13 +95,13 @@ __attribute__((unused)) static const char* TAG = "esp_timer"; // lists of currently armed timers for two dispatch methods: ISR and TASK static LIST_HEAD(esp_timer_list, esp_timer) s_timers[ESP_TIMER_MAX] = { - [0 ... (ESP_TIMER_MAX - 1)] = LIST_HEAD_INITIALIZER(s_timers) + [0 ...(ESP_TIMER_MAX - 1)] = LIST_HEAD_INITIALIZER(s_timers) }; #if WITH_PROFILING // lists of unarmed timers for two dispatch methods: ISR and TASK, // used only to be able to dump statistics about all the timers static LIST_HEAD(esp_inactive_timer_list, esp_timer) s_inactive_timers[ESP_TIMER_MAX] = { - [0 ... (ESP_TIMER_MAX - 1)] = LIST_HEAD_INITIALIZER(s_timers) + [0 ...(ESP_TIMER_MAX - 1)] = LIST_HEAD_INITIALIZER(s_timers) }; #endif // task used to dispatch timer callbacks @@ -109,7 +109,7 @@ static TaskHandle_t s_timer_task; // lock protecting s_timers, s_inactive_timers static portMUX_TYPE s_timer_lock[ESP_TIMER_MAX] = { - [0 ... (ESP_TIMER_MAX - 1)] = portMUX_INITIALIZER_UNLOCKED + [0 ...(ESP_TIMER_MAX - 1)] = portMUX_INITIALIZER_UNLOCKED }; #ifdef CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD @@ -124,7 +124,7 @@ esp_err_t esp_timer_create(const esp_timer_create_args_t* args, return ESP_ERR_INVALID_STATE; } if (args == NULL || args->callback == NULL || out_handle == NULL || - args->dispatch_method < 0 || args->dispatch_method >= ESP_TIMER_MAX) { + args->dispatch_method < 0 || args->dispatch_method >= ESP_TIMER_MAX) { return ESP_ERR_INVALID_ARG; } esp_timer_handle_t result = (esp_timer_handle_t) heap_caps_calloc(1, sizeof(*result), MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); @@ -473,7 +473,7 @@ static bool timer_process_alarm(esp_timer_dispatch_t dispatch_method) static void timer_task(void* arg) { - while (true){ + while (true) { ulTaskNotifyTake(pdTRUE, portMAX_DELAY); // all deferred events are processed at a time timer_process_alarm(ESP_TIMER_TASK); @@ -531,9 +531,9 @@ static esp_err_t init_timer_task(void) err = ESP_ERR_INVALID_STATE; } else { int ret = xTaskCreatePinnedToCore( - &timer_task, "esp_timer", - ESP_TASK_TIMER_STACK, NULL, ESP_TASK_TIMER_PRIO, - &s_timer_task, CONFIG_ESP_TIMER_TASK_AFFINITY); + &timer_task, "esp_timer", + ESP_TASK_TIMER_STACK, NULL, ESP_TASK_TIMER_PRIO, + &s_timer_task, CONFIG_ESP_TIMER_TASK_AFFINITY); if (ret != pdPASS) { ESP_EARLY_LOGE(TAG, "Not enough memory to create timer task"); err = ESP_ERR_NO_MEM; @@ -582,7 +582,6 @@ esp_err_t esp_timer_init(void) #define ESP_TIMER_INIT_MASK ESP_SYSTEM_INIT_ALL_CORES #endif // CONFIG_ESP_TIMER_ISR_AFFINITY_* - ESP_SYSTEM_INIT_FN(esp_timer_startup_init, SECONDARY, ESP_TIMER_INIT_MASK, 100) { return esp_timer_init(); @@ -628,8 +627,8 @@ static void print_timer_info(esp_timer_handle_t t, char** dst, size_t* dst_size) cb = snprintf(*dst, *dst_size, "timer@%-10p ", t); } cb += snprintf(*dst + cb, *dst_size + cb, "%-10lld %-12lld %-12d %-12d %-12d %-12lld\n", - (uint64_t)t->period, t->alarm, t->times_armed, - t->times_triggered, t->times_skipped, t->total_callback_run_time); + (uint64_t)t->period, t->alarm, t->times_armed, + t->times_triggered, t->times_skipped, t->total_callback_run_time); /* keep this in sync with the format string, used in esp_timer_dump */ #define TIMER_INFO_LINE_LEN 90 #else @@ -640,7 +639,6 @@ static void print_timer_info(esp_timer_handle_t t, char** dst, size_t* dst_size) *dst_size -= cb; } - esp_err_t esp_timer_dump(FILE* stream) { /* Since timer lock is a critical section, we don't want to print directly diff --git a/components/esp_timer/src/esp_timer_impl_common.c b/components/esp_timer/src/esp_timer_impl_common.c index d0c86f685d..eb31d75d01 100644 --- a/components/esp_timer/src/esp_timer_impl_common.c +++ b/components/esp_timer/src/esp_timer_impl_common.c @@ -38,7 +38,8 @@ void IRAM_ATTR esp_timer_impl_set_alarm(uint64_t timestamp) } #ifdef CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD -void IRAM_ATTR esp_timer_impl_try_to_set_next_alarm(void) { +void IRAM_ATTR esp_timer_impl_try_to_set_next_alarm(void) +{ portENTER_CRITICAL_ISR(&s_time_update_lock); unsigned now_alarm_idx; // ISR is called due to this current alarm unsigned next_alarm_idx; // The following alarm after now_alarm_idx diff --git a/components/esp_timer/src/esp_timer_impl_lac.c b/components/esp_timer/src/esp_timer_impl_lac.c index 294c6b5662..f3e6f60a1d 100644 --- a/components/esp_timer/src/esp_timer_impl_lac.c +++ b/components/esp_timer/src/esp_timer_impl_lac.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -168,7 +168,7 @@ void IRAM_ATTR esp_timer_impl_set_alarm_id(uint64_t timestamp, unsigned alarm_id // finish if either (alarm > counter) or the interrupt flag is already set. break; } - } while(1); + } while (1); } portEXIT_CRITICAL_SAFE(&s_time_update_lock); } @@ -202,10 +202,10 @@ static void IRAM_ATTR timer_alarm_isr(void *arg) (*s_alarm_handler)(arg); portENTER_CRITICAL_ISR(&s_time_update_lock); - // Another alarm could have occurred while were handling the previous alarm. - // Check if we need to call the s_alarm_handler again: - // 1) if the alarm has already been fired, it helps to handle it immediately without an additional ISR call. - // 2) handle pending alarm that was cleared by the other core in time when this core worked with the current alarm. + // Another alarm could have occurred while were handling the previous alarm. + // Check if we need to call the s_alarm_handler again: + // 1) if the alarm has already been fired, it helps to handle it immediately without an additional ISR call. + // 2) handle pending alarm that was cleared by the other core in time when this core worked with the current alarm. } while (REG_GET_FIELD(INT_ST_REG, TIMG_LACT_INT_ST) || pending_alarm); processed_by = NOT_USED; } else { @@ -262,8 +262,8 @@ esp_err_t esp_timer_impl_early_init(void) REG_SET_BIT(INT_CLR_REG, TIMG_LACT_INT_CLR); REG_SET_FIELD(CONFIG_REG, TIMG_LACT_DIVIDER, APB_CLK_FREQ / 1000000 / TICKS_PER_US); REG_SET_BIT(CONFIG_REG, TIMG_LACT_INCREASE | - TIMG_LACT_LEVEL_INT_EN | - TIMG_LACT_EN); + TIMG_LACT_LEVEL_INT_EN | + TIMG_LACT_EN); return ESP_OK; } diff --git a/components/esp_timer/src/esp_timer_impl_systimer.c b/components/esp_timer/src/esp_timer_impl_systimer.c index 2c1a9362d7..ac7dc19396 100644 --- a/components/esp_timer/src/esp_timer_impl_systimer.c +++ b/components/esp_timer/src/esp_timer_impl_systimer.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -112,10 +112,10 @@ static void IRAM_ATTR timer_alarm_isr(void *arg) (*s_alarm_handler)(arg); portENTER_CRITICAL_ISR(&s_time_update_lock); - // Another alarm could have occurred while were handling the previous alarm. - // Check if we need to call the s_alarm_handler again: - // 1) if the alarm has already been fired, it helps to handle it immediately without an additional ISR call. - // 2) handle pending alarm that was cleared by the other core in time when this core worked with the current alarm. + // Another alarm could have occurred while were handling the previous alarm. + // Check if we need to call the s_alarm_handler again: + // 1) if the alarm has already been fired, it helps to handle it immediately without an additional ISR call. + // 2) handle pending alarm that was cleared by the other core in time when this core worked with the current alarm. } while (systimer_ll_is_alarm_int_fired(systimer_hal.dev, SYSTIMER_ALARM_ESPTIMER) || pending_alarm); processed_by = NOT_USED; } else { diff --git a/components/esp_timer/src/ets_timer_legacy.c b/components/esp_timer/src/ets_timer_legacy.c index a37b88f253..85ebb5bac4 100644 --- a/components/esp_timer/src/ets_timer_legacy.c +++ b/components/esp_timer/src/ets_timer_legacy.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -65,25 +65,24 @@ void ets_timer_setfn(ETSTimer *ptimer, ETSTimerFunc *pfunction, void *parg) if (ESP_TIMER(ptimer) == NULL) { const esp_timer_create_args_t create_args = { - .callback = pfunction, - .arg = parg, - .name = "ETSTimer", - .dispatch_method = ESP_TIMER_TASK + .callback = pfunction, + .arg = parg, + .name = "ETSTimer", + .dispatch_method = ESP_TIMER_TASK }; - ESP_ERROR_CHECK( esp_timer_create(&create_args, (esp_timer_handle_t*)&(ptimer->timer_arg)) ); + ESP_ERROR_CHECK(esp_timer_create(&create_args, (esp_timer_handle_t*) & (ptimer->timer_arg))); } } - void IRAM_ATTR ets_timer_arm_us(ETSTimer *ptimer, uint32_t time_us, bool repeat_flag) { assert(timer_initialized(ptimer)); esp_timer_stop(ESP_TIMER(ptimer)); // no error check if (!repeat_flag) { - ESP_ERROR_CHECK( esp_timer_start_once(ESP_TIMER(ptimer), time_us) ); + ESP_ERROR_CHECK(esp_timer_start_once(ESP_TIMER(ptimer), time_us)); } else { - ESP_ERROR_CHECK( esp_timer_start_periodic(ESP_TIMER(ptimer), time_us) ); + ESP_ERROR_CHECK(esp_timer_start_periodic(ESP_TIMER(ptimer), time_us)); } } @@ -93,9 +92,9 @@ void IRAM_ATTR ets_timer_arm(ETSTimer *ptimer, uint32_t time_ms, bool repeat_fla assert(timer_initialized(ptimer)); esp_timer_stop(ESP_TIMER(ptimer)); // no error check if (!repeat_flag) { - ESP_ERROR_CHECK( esp_timer_start_once(ESP_TIMER(ptimer), time_us) ); + ESP_ERROR_CHECK(esp_timer_start_once(ESP_TIMER(ptimer), time_us)); } else { - ESP_ERROR_CHECK( esp_timer_start_periodic(ESP_TIMER(ptimer), time_us) ); + ESP_ERROR_CHECK(esp_timer_start_periodic(ESP_TIMER(ptimer), time_us)); } } @@ -115,7 +114,6 @@ void IRAM_ATTR ets_timer_disarm(ETSTimer *ptimer) } } - void ets_timer_init(void) { @@ -128,6 +126,6 @@ void ets_timer_deinit(void) void os_timer_setfn(ETSTimer *ptimer, ETSTimerFunc *pfunction, void *parg) __attribute__((alias("ets_timer_setfn"))); void os_timer_disarm(ETSTimer *ptimer) __attribute__((alias("ets_timer_disarm"))); -void os_timer_arm_us(ETSTimer *ptimer,uint32_t u_seconds,bool repeat_flag) __attribute__((alias("ets_timer_arm_us"))); -void os_timer_arm(ETSTimer *ptimer,uint32_t milliseconds,bool repeat_flag) __attribute__((alias("ets_timer_arm"))); +void os_timer_arm_us(ETSTimer *ptimer, uint32_t u_seconds, bool repeat_flag) __attribute__((alias("ets_timer_arm_us"))); +void os_timer_arm(ETSTimer *ptimer, uint32_t milliseconds, bool repeat_flag) __attribute__((alias("ets_timer_arm"))); void os_timer_done(ETSTimer *ptimer) __attribute__((alias("ets_timer_done"))); diff --git a/components/esp_timer/test_apps/main/test_esp_timer.c b/components/esp_timer/test_apps/main/test_esp_timer.c index 55a380ea0d..0e635c9413 100644 --- a/components/esp_timer/test_apps/main/test_esp_timer.c +++ b/components/esp_timer/test_apps/main/test_esp_timer.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -23,12 +23,10 @@ #define SEC (1000000) - #ifdef CONFIG_ESP_TIMER_PROFILING #define WITH_PROFILING 1 #endif - static void dummy_cb(void* arg) { } @@ -37,14 +35,14 @@ TEST_CASE("esp_timer orders timers correctly", "[esp_timer]") { uint64_t timeouts[] = { 10000, 1000, 10000, 5000, 20000, 1000 }; size_t indices[] = { 3, 0, 4, 2, 5, 1 }; - const size_t num_timers = sizeof(timeouts)/sizeof(timeouts[0]); + const size_t num_timers = sizeof(timeouts) / sizeof(timeouts[0]); esp_timer_handle_t handles[num_timers]; char* names[num_timers]; for (size_t i = 0; i < num_timers; ++i) { asprintf(&names[i], "timer%d", i); esp_timer_create_args_t args = { - .callback = &dummy_cb, - .name = names[i] + .callback = &dummy_cb, + .name = names[i] }; TEST_ESP_OK(esp_timer_create(&args, &handles[i])); TEST_ESP_OK(esp_timer_start_once(handles[i], timeouts[i] * 100)); @@ -96,7 +94,7 @@ static void set_alarm_task(void* arg) int64_t now = start; int count = 0; const int delays[] = {50, 5000, 10000000}; - const int delays_count = sizeof(delays)/sizeof(delays[0]); + const int delays_count = sizeof(delays) / sizeof(delays[0]); while (now - start < test_time_sec * 1000000) { now = esp_timer_impl_get_time(); esp_timer_impl_set_alarm(now + delays[count % delays_count]); @@ -132,14 +130,14 @@ TEST_CASE("esp_timer produces correct delay", "[esp_timer]") int64_t t_end; esp_timer_handle_t timer1; esp_timer_create_args_t args = { - .callback = &test_correct_delay_timer_func, - .arg = &t_end, - .name = "timer1" + .callback = &test_correct_delay_timer_func, + .arg = &t_end, + .name = "timer1" }; TEST_ESP_OK(esp_timer_create(&args, &timer1)); const int delays_ms[] = {20, 100, 200, 250}; - const size_t delays_count = sizeof(delays_ms)/sizeof(delays_ms[0]); + const size_t delays_count = sizeof(delays_ms) / sizeof(delays_ms[0]); ref_clock_init(); for (size_t i = 0; i < delays_count; ++i) { @@ -157,7 +155,7 @@ TEST_CASE("esp_timer produces correct delay", "[esp_timer]") } ref_clock_deinit(); - TEST_ESP_OK( esp_timer_dump(stdout) ); + TEST_ESP_OK(esp_timer_dump(stdout)); esp_timer_delete(timer1); } @@ -182,7 +180,7 @@ static void test_periodic_correct_delays_timer_func(void* arg) p_args->intervals[p_args->cur_interval++] = ms_diff; // Deliberately make timer handler run longer. // We check that this doesn't affect the result. - esp_rom_delay_us(10*1000); + esp_rom_delay_us(10 * 1000); if (p_args->cur_interval == NUM_INTERVALS) { printf("done\n"); TEST_ESP_OK(esp_timer_stop(p_args->timer)); @@ -196,9 +194,9 @@ TEST_CASE("periodic esp_timer produces correct delays", "[esp_timer]") test_periodic_correct_delays_args_t args = {0}; esp_timer_handle_t timer1; esp_timer_create_args_t create_args = { - .callback = &test_periodic_correct_delays_timer_func, - .arg = &args, - .name = "timer1", + .callback = &test_periodic_correct_delays_timer_func, + .arg = &args, + .name = "timer1", }; TEST_ESP_OK(esp_timer_create(&create_args, &timer1)); ref_clock_init(); @@ -214,14 +212,13 @@ TEST_CASE("periodic esp_timer produces correct delays", "[esp_timer]") TEST_ASSERT_INT32_WITHIN(portTICK_PERIOD_MS, (i + 1) * delay_ms, args.intervals[i]); } ref_clock_deinit(); - TEST_ESP_OK( esp_timer_dump(stdout) ); + TEST_ESP_OK(esp_timer_dump(stdout)); - TEST_ESP_OK( esp_timer_delete(timer1) ); + TEST_ESP_OK(esp_timer_delete(timer1)); vSemaphoreDelete(args.done); } #undef NUM_INTERVALS - #define N 5 typedef struct { @@ -248,7 +245,7 @@ static void test_timers_ordered_correctly_timer_func(void* arg) int expected_index = p_args->common->order[count]; int ms_since_start = (ref_clock_get() - p_args->t_start) / 1000; printf("Time %dms, at count %d, expected timer %d, got timer %d\n", - ms_since_start, count, expected_index, p_args->timer_index); + ms_since_start, count, expected_index, p_args->timer_index); if (expected_index != p_args->timer_index) { p_args->pass = false; esp_timer_stop(p_args->timer); @@ -263,7 +260,7 @@ static void test_timers_ordered_correctly_timer_func(void* arg) } int next_interval = p_args->intervals[p_args->intervals_count]; printf("starting timer %d interval #%d, %d ms\n", - p_args->timer_index, p_args->intervals_count, next_interval); + p_args->timer_index, p_args->intervals_count, next_interval); esp_timer_start_once(p_args->timer, next_interval * 1000); } @@ -280,37 +277,36 @@ TEST_CASE("multiple timers are ordered correctly", "[esp_timer]") int64_t now = ref_clock_get(); test_timers_ordered_correctly_args_t args1 = { - .timer_index = 1, - .intervals = {10, 40, 20, 40, 30}, - .common = &common, - .pass = true, - .done = done, - .t_start = now + .timer_index = 1, + .intervals = {10, 40, 20, 40, 30}, + .common = &common, + .pass = true, + .done = done, + .t_start = now }; test_timers_ordered_correctly_args_t args2 = { - .timer_index = 2, - .intervals = {20, 20, 60, 30, 40}, - .common = &common, - .pass = true, - .done = done, - .t_start = now + .timer_index = 2, + .intervals = {20, 20, 60, 30, 40}, + .common = &common, + .pass = true, + .done = done, + .t_start = now }; test_timers_ordered_correctly_args_t args3 = { - .timer_index = 3, - .intervals = {30, 30, 60, 30, 10}, - .common = &common, - .pass = true, - .done = done, - .t_start = now + .timer_index = 3, + .intervals = {30, 30, 60, 30, 10}, + .common = &common, + .pass = true, + .done = done, + .t_start = now }; - esp_timer_create_args_t create_args = { - .callback = &test_timers_ordered_correctly_timer_func, - .arg = &args1, - .name = "1" + .callback = &test_timers_ordered_correctly_timer_func, + .arg = &args1, + .name = "1" }; TEST_ESP_OK(esp_timer_create(&create_args, &args1.timer)); @@ -337,16 +333,16 @@ TEST_CASE("multiple timers are ordered correctly", "[esp_timer]") ref_clock_deinit(); - TEST_ESP_OK( esp_timer_dump(stdout) ); + TEST_ESP_OK(esp_timer_dump(stdout)); - TEST_ESP_OK( esp_timer_delete(args1.timer) ); - TEST_ESP_OK( esp_timer_delete(args2.timer) ); - TEST_ESP_OK( esp_timer_delete(args3.timer) ); + TEST_ESP_OK(esp_timer_delete(args1.timer)); + TEST_ESP_OK(esp_timer_delete(args2.timer)); + TEST_ESP_OK(esp_timer_delete(args3.timer)); } #undef N - -static void test_short_intervals_timer_func(void* arg) { +static void test_short_intervals_timer_func(void* arg) +{ SemaphoreHandle_t done = (SemaphoreHandle_t) arg; xSemaphoreGive(done); printf("."); @@ -361,19 +357,19 @@ TEST_CASE("esp_timer for very short intervals", "[esp_timer]") SemaphoreHandle_t semaphore = xSemaphoreCreateCounting(2, 0); esp_timer_create_args_t timer_args = { - .callback = &test_short_intervals_timer_func, - .arg = (void*) semaphore, - .name = "foo" + .callback = &test_short_intervals_timer_func, + .arg = (void*) semaphore, + .name = "foo" }; esp_timer_handle_t timer1, timer2; - ESP_ERROR_CHECK( esp_timer_create(&timer_args, &timer1) ); - ESP_ERROR_CHECK( esp_timer_create(&timer_args, &timer2) ); + ESP_ERROR_CHECK(esp_timer_create(&timer_args, &timer1)); + ESP_ERROR_CHECK(esp_timer_create(&timer_args, &timer2)); const int timeout_ms = 10; for (int timeout_delta_us = -150; timeout_delta_us < 150; timeout_delta_us++) { printf("delta=%d", timeout_delta_us); - ESP_ERROR_CHECK( esp_timer_start_once(timer1, timeout_ms * 1000) ); - ESP_ERROR_CHECK( esp_timer_start_once(timer2, timeout_ms * 1000 + timeout_delta_us) ); + ESP_ERROR_CHECK(esp_timer_start_once(timer1, timeout_ms * 1000)); + ESP_ERROR_CHECK(esp_timer_start_once(timer2, timeout_ms * 1000 + timeout_delta_us)); TEST_ASSERT_EQUAL(pdPASS, xSemaphoreTake(semaphore, timeout_ms * 2)); TEST_ASSERT_EQUAL(pdPASS, xSemaphoreTake(semaphore, timeout_ms * 2)); printf("\n"); @@ -394,7 +390,7 @@ TEST_CASE("esp_timer_get_time call takes less than 1us", "[esp_timer]") for (int i = 0; i < iter_count; ++i) { end = esp_timer_get_time(); } - int ns_per_call = (int) ((end - begin) * 1000 / iter_count); + int ns_per_call = (int)((end - begin) * 1000 / iter_count); TEST_PERFORMANCE_LESS_THAN(ESP_TIMER_GET_TIME_PER_CALL, "%dns", ns_per_call); } @@ -415,7 +411,8 @@ typedef struct { int64_t dummy; } test_monotonic_values_state_t; -static void timer_test_monotonic_values_task(void* arg) { +static void timer_test_monotonic_values_task(void* arg) +{ test_monotonic_values_state_t* state = (test_monotonic_values_state_t*) arg; state->pass = true; @@ -455,7 +452,7 @@ static void timer_test_monotonic_values_task(void* arg) { state->avg_diff /= state->test_cnt; xSemaphoreGive(state->done); vTaskDelete(NULL); - } +} TEST_CASE("esp_timer_get_time returns monotonic values", "[esp_timer]") { @@ -469,11 +466,11 @@ TEST_CASE("esp_timer_get_time returns monotonic values", "[esp_timer]") } for (int i = 0; i < portNUM_PROCESSORS; ++i) { - TEST_ASSERT_TRUE( xSemaphoreTake(done, portMAX_DELAY) ); + TEST_ASSERT_TRUE(xSemaphoreTake(done, portMAX_DELAY)); printf("CPU%d: %s test_cnt=%d error_cnt=%d avg_diff=%d |max_error|=%d\n", - i, states[i].pass ? "PASS" : "FAIL", - states[i].test_cnt, states[i].error_cnt, - (int) states[i].avg_diff, (int) states[i].max_error); + i, states[i].pass ? "PASS" : "FAIL", + states[i].test_cnt, states[i].error_cnt, + (int) states[i].avg_diff, (int) states[i].max_error); } vSemaphoreDelete(done); @@ -505,13 +502,13 @@ static void test_delete_from_callback_timer_func(void* varg) TEST_CASE("Can delete timer from callback", "[esp_timer]") { test_delete_from_callback_arg_t args = { - .notify_from_timer_cb = xSemaphoreCreateBinary(), + .notify_from_timer_cb = xSemaphoreCreateBinary(), }; esp_timer_create_args_t timer_args = { - .callback = &test_delete_from_callback_timer_func, - .arg = &args, - .name = "self_deleter" + .callback = &test_delete_from_callback_timer_func, + .arg = &args, + .name = "self_deleter" }; esp_timer_create(&timer_args, &args.timer); esp_timer_start_once(args.timer, 10000); @@ -523,7 +520,6 @@ TEST_CASE("Can delete timer from callback", "[esp_timer]") vSemaphoreDelete(args.notify_from_timer_cb); } - typedef struct { SemaphoreHandle_t delete_start; SemaphoreHandle_t delete_done; @@ -561,8 +557,8 @@ TEST_CASE("Can delete timer from a separate task, triggered from callback", "[es }; esp_timer_create_args_t timer_args = { - .callback = &timer_delete_test_callback, - .arg = &args + .callback = &timer_delete_test_callback, + .arg = &args }; esp_timer_handle_t timer; TEST_ESP_OK(esp_timer_create(&timer_args, &timer)); @@ -593,7 +589,8 @@ typedef struct { int64_t cb_time; } test_run_when_expected_state_t; -static void test_run_when_expected_timer_func(void* varg) { +static void test_run_when_expected_timer_func(void* varg) +{ test_run_when_expected_state_t* arg = (test_run_when_expected_state_t*) varg; arg->cb_time = ref_clock_get(); } @@ -605,8 +602,8 @@ TEST_CASE("after esp_timer_impl_advance, timers run when expected", "[esp_timer] test_run_when_expected_state_t state = { 0 }; esp_timer_create_args_t timer_args = { - .callback = &test_run_when_expected_timer_func, - .arg = &state + .callback = &test_run_when_expected_timer_func, + .arg = &state }; esp_timer_handle_t timer; TEST_ESP_OK(esp_timer_create(&timer_args, &timer)); @@ -668,7 +665,7 @@ TEST_CASE("Can start/stop timer from ISR context", "[esp_timer]") esp_register_freertos_tick_hook(test_tick_hook); TEST_ASSERT(xSemaphoreTake(sem, portMAX_DELAY)); esp_deregister_freertos_tick_hook(test_tick_hook); - TEST_ESP_OK( esp_timer_delete(timer1) ); + TEST_ESP_OK(esp_timer_delete(timer1)); vSemaphoreDelete(sem); } @@ -750,7 +747,6 @@ TEST_CASE("esp_timer_impl_set_alarm does not set an alarm below the current time TEST_ASSERT(time_jumped == false); } - static esp_timer_handle_t oneshot_timer; static void oneshot_timer_callback(void* arg) @@ -820,7 +816,6 @@ TEST_CASE("Test case when esp_timer_impl_set_alarm needs set timer < now_time", TEST_ASSERT(alarm_reg <= (count_reg + offset)); } - static void timer_callback5(void* arg) { *(int64_t *)arg = esp_timer_get_time(); @@ -875,9 +870,9 @@ TEST_CASE("periodic esp_timer can be restarted", "[esp_timer]") int timer_trig = 0; esp_timer_handle_t timer1; esp_timer_create_args_t create_args = { - .callback = &test_timer_triggered, - .arg = &timer_trig, - .name = "timer1", + .callback = &test_timer_triggered, + .arg = &timer_trig, + .name = "timer1", }; TEST_ESP_OK(esp_timer_create(&create_args, &timer1)); TEST_ESP_OK(esp_timer_start_periodic(timer1, delay_ms * 1000)); @@ -907,8 +902,8 @@ TEST_CASE("periodic esp_timer can be restarted", "[esp_timer]") /* Check that the alarm was triggered twice */ TEST_ASSERT_EQUAL(2, timer_trig); - TEST_ESP_OK( esp_timer_stop(timer1) ); - TEST_ESP_OK( esp_timer_delete(timer1) ); + TEST_ESP_OK(esp_timer_stop(timer1)); + TEST_ESP_OK(esp_timer_delete(timer1)); } TEST_CASE("one-shot esp_timer can be restarted", "[esp_timer]") @@ -917,9 +912,9 @@ TEST_CASE("one-shot esp_timer can be restarted", "[esp_timer]") int timer_trig = 0; esp_timer_handle_t timer1; esp_timer_create_args_t create_args = { - .callback = &test_timer_triggered, - .arg = &timer_trig, - .name = "timer1", + .callback = &test_timer_triggered, + .arg = &timer_trig, + .name = "timer1", }; TEST_ESP_OK(esp_timer_create(&create_args, &timer1)); TEST_ESP_OK(esp_timer_start_once(timer1, delay_ms * 1000)); @@ -942,10 +937,9 @@ TEST_CASE("one-shot esp_timer can be restarted", "[esp_timer]") /* Make sure the timer was triggered */ TEST_ASSERT_EQUAL(0, timer_trig); - TEST_ESP_OK( esp_timer_delete(timer1) ); + TEST_ESP_OK(esp_timer_delete(timer1)); } - #ifdef CONFIG_ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD static int64_t old_time[2]; @@ -967,7 +961,7 @@ static void timer_isr_callback(void* arg) TEST_CASE("Test ESP_TIMER_ISR dispatch method", "[esp_timer]") { TEST_ESP_OK(esp_timer_dump(stdout)); - int timer[2]= {0, 1}; + int timer[2] = {0, 1}; const esp_timer_create_args_t periodic_timer1_args = { .callback = &timer_isr_callback, .dispatch_method = ESP_TIMER_ISR, @@ -1222,7 +1216,8 @@ volatile uint64_t isr_t1; const uint64_t period_task_ms = 200; const uint64_t period_isr_ms = 20; -void task_timer_cb(void *arg) { +void task_timer_cb(void *arg) +{ uint64_t t2 = esp_timer_get_time(); uint64_t dt_task_ms = (t2 - task_t1) / 1000; task_t1 = t2; @@ -1236,7 +1231,8 @@ void task_timer_cb(void *arg) { } } -void IRAM_ATTR isr_timer_cb(void *arg) { +void IRAM_ATTR isr_timer_cb(void *arg) +{ uint64_t t2 = esp_timer_get_time(); uint64_t dt_isr_ms = (t2 - isr_t1) / 1000; isr_t1 = t2; diff --git a/components/esp_timer/test_apps/main/test_esp_timer_light_sleep.c b/components/esp_timer/test_apps/main/test_esp_timer_light_sleep.c index 471a5504b9..bf17e569cc 100644 --- a/components/esp_timer/test_apps/main/test_esp_timer_light_sleep.c +++ b/components/esp_timer/test_apps/main/test_esp_timer_light_sleep.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -25,10 +25,10 @@ TEST_CASE("Test the periodic timer does not handle lost events during light slee int count_calls; const esp_timer_create_args_t timer_args = { - .name = "timer_cb1", - .arg = &count_calls, - .callback = &timer_cb1, - .skip_unhandled_events = true, + .name = "timer_cb1", + .arg = &count_calls, + .callback = &timer_cb1, + .skip_unhandled_events = true, }; esp_timer_handle_t periodic_timer; esp_timer_create(&timer_args, &periodic_timer); diff --git a/components/esp_timer/test_apps/main/test_ets_timer.c b/components/esp_timer/test_apps/main/test_ets_timer.c index ee7230a10c..22ab9ef56e 100644 --- a/components/esp_timer/test_apps/main/test_ets_timer.c +++ b/components/esp_timer/test_apps/main/test_ets_timer.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -123,7 +123,7 @@ static void test_timers_ordered_correctly_timer_func(void* arg) size_t count = p_args->common->count; int expected_index = p_args->common->order[count]; printf("At count %d, expected timer %d, got timer %d\n", - count, expected_index, p_args->timer_index); + count, expected_index, p_args->timer_index); if (expected_index != p_args->timer_index) { p_args->pass = false; ets_timer_disarm(p_args->timer); @@ -138,7 +138,7 @@ static void test_timers_ordered_correctly_timer_func(void* arg) } int next_interval = p_args->intervals[p_args->intervals_count]; printf("timer %d interval #%d, %d ms\n", - p_args->timer_index, p_args->intervals_count, next_interval); + p_args->timer_index, p_args->intervals_count, next_interval); ets_timer_arm(p_args->timer, next_interval, false); } @@ -156,30 +156,30 @@ TEST_CASE("multiple ETSTimers are ordered correctly", "[ets_timer]") SemaphoreHandle_t done = xSemaphoreCreateCounting(3, 0); test_timers_ordered_correctly_args_t args1 = { - .timer_index = 1, - .intervals = {10, 40, 20, 40, 30}, - .timer = &timer1, - .common = &common, - .pass = true, - .done = done + .timer_index = 1, + .intervals = {10, 40, 20, 40, 30}, + .timer = &timer1, + .common = &common, + .pass = true, + .done = done }; test_timers_ordered_correctly_args_t args2 = { - .timer_index = 2, - .intervals = {20, 20, 60, 30, 40}, - .timer = &timer2, - .common = &common, - .pass = true, - .done = done + .timer_index = 2, + .intervals = {20, 20, 60, 30, 40}, + .timer = &timer2, + .common = &common, + .pass = true, + .done = done }; test_timers_ordered_correctly_args_t args3 = { - .timer_index = 3, - .intervals = {30, 30, 60, 30, 10}, - .timer = &timer3, - .common = &common, - .pass = true, - .done = done + .timer_index = 3, + .intervals = {30, 30, 60, 30, 10}, + .timer = &timer3, + .common = &common, + .pass = true, + .done = done }; ets_timer_setfn(&timer1, &test_timers_ordered_correctly_timer_func, &args1); diff --git a/components/linux/getrandom.c b/components/linux/getrandom.c index 5f068ee3fd..e64c90c376 100644 --- a/components/linux/getrandom.c +++ b/components/linux/getrandom.c @@ -10,7 +10,6 @@ #include #include - // getrandom() is not available on macOS, so we read from /dev/urandom instead. int getrandom(void *buf, size_t buflen, unsigned int flags) diff --git a/components/linux/include/sys/lock.h b/components/linux/include/sys/lock.h index 71d2f7654a..a2930d26c2 100644 --- a/components/linux/include/sys/lock.h +++ b/components/linux/include/sys/lock.h @@ -12,13 +12,11 @@ extern "C" { #endif - /* newlib locks implementation for CONFIG_IDF_TARGET_LINUX, single threaded. * Note, currently this doesn't implement the functions required * when _RETARGETABLE_LOCKING is defined. They should be added. */ - /* Compatibility definitions for legacy newlib locking functions */ typedef int _lock_t; @@ -39,7 +37,6 @@ static inline int _lock_try_acquire_recursive(_lock_t *plock) static inline void _lock_release(_lock_t *plock) {} static inline void _lock_release_recursive(_lock_t *plock) {} - #ifdef __cplusplus } #endif diff --git a/components/log/include/esp_log.h b/components/log/include/esp_log.h index 6d18ff41f5..51c474937b 100644 --- a/components/log/include/esp_log.h +++ b/components/log/include/esp_log.h @@ -159,7 +159,7 @@ uint32_t esp_log_early_timestamp(void); * * This function or these macros should not be used from an interrupt. */ -void esp_log_write(esp_log_level_t level, const char* tag, const char* format, ...) __attribute__ ((format (printf, 3, 4))); +void esp_log_write(esp_log_level_t level, const char* tag, const char* format, ...) __attribute__((format(printf, 3, 4))); /** * @brief Write message into the log, va_list variant @@ -279,7 +279,6 @@ void esp_log_writev(esp_log_level_t level, const char* tag, const char* format, #define esp_log_buffer_hex ESP_LOG_BUFFER_HEX #define esp_log_buffer_char ESP_LOG_BUFFER_CHAR - #if CONFIG_LOG_COLORS #define LOG_COLOR_BLACK "30" #define LOG_COLOR_RED "31" @@ -523,5 +522,4 @@ void esp_log_writev(esp_log_level_t level, const char* tag, const char* format, } #endif - #endif /* __ESP_LOG_H__ */ diff --git a/components/log/include/esp_log_internal.h b/components/log/include/esp_log_internal.h index 732f949c83..cbdb2db731 100644 --- a/components/log/include/esp_log_internal.h +++ b/components/log/include/esp_log_internal.h @@ -10,6 +10,6 @@ //these functions do not check level versus ESP_LOCAL_LEVEL, this should be done in esp_log.h void esp_log_buffer_hex_internal(const char *tag, const void *buffer, uint16_t buff_len, esp_log_level_t level); void esp_log_buffer_char_internal(const char *tag, const void *buffer, uint16_t buff_len, esp_log_level_t level); -void esp_log_buffer_hexdump_internal( const char *tag, const void *buffer, uint16_t buff_len, esp_log_level_t log_level); +void esp_log_buffer_hexdump_internal(const char *tag, const void *buffer, uint16_t buff_len, esp_log_level_t log_level); #endif diff --git a/components/log/log.c b/components/log/log.c index 39de66ebde..9610dfbf0d 100644 --- a/components/log/log.c +++ b/components/log/log.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -76,7 +76,6 @@ static vprintf_like_t s_log_print_func = &vprintf; static uint32_t s_log_cache_misses = 0; #endif - static inline bool get_cached_log_level(const char *tag, esp_log_level_t *level); static inline bool get_uncached_log_level(const char *tag, esp_log_level_t *level); static inline void add_to_cache(const char *tag, esp_log_level_t level); @@ -156,7 +155,6 @@ void esp_log_level_set(const char *tag, esp_log_level_t level) esp_log_impl_unlock(); } - /* Common code for getting the log level from cache, esp_log_impl_lock() should be called before calling this function. The function unlocks, as indicated in the name. @@ -200,9 +198,9 @@ void clear_log_level_list(void) } void esp_log_writev(esp_log_level_t level, - const char *tag, - const char *format, - va_list args) + const char *tag, + const char *format, + va_list args) { if (!esp_log_impl_lock_timeout()) { return; diff --git a/components/log/log_buffers.c b/components/log/log_buffers.c index 2fcef1b2b6..bdbb1437c6 100644 --- a/components/log/log_buffers.c +++ b/components/log/log_buffers.c @@ -13,7 +13,8 @@ #ifndef CONFIG_IDF_TARGET_LINUX #include "esp_memory_utils.h" // for esp_ptr_byte_accessible #else -static inline bool esp_ptr_byte_accessible(const void* ptr) { +static inline bool esp_ptr_byte_accessible(const void* ptr) +{ (void) ptr; return true; } diff --git a/components/log/log_freertos.c b/components/log/log_freertos.c index 26ea34a3d4..f40af5ca65 100644 --- a/components/log/log_freertos.c +++ b/components/log/log_freertos.c @@ -15,7 +15,6 @@ #include "esp_log.h" #include "esp_log_private.h" - // Maximum time to wait for the mutex in a logging statement. // // We don't expect this to happen in most cases, as contention is low. The most likely case is if a diff --git a/components/log/test_apps/main/test_log.c b/components/log/test_apps/main/test_log.c index 0c00e50599..37b3597e54 100644 --- a/components/log/test_apps/main/test_log.c +++ b/components/log/test_apps/main/test_log.c @@ -13,7 +13,6 @@ #include "esp_timer.h" #include "sdkconfig.h" - static const char * TAG = "log_test"; static int calc_time_of_logging(int iterations) diff --git a/tools/ci/astyle-rules.yml b/tools/ci/astyle-rules.yml index 21b758a283..c790aec6bf 100644 --- a/tools/ci/astyle-rules.yml +++ b/tools/ci/astyle-rules.yml @@ -68,7 +68,6 @@ components_not_formatted_temporary: - "/components/esp_phy/" - "/components/esp_pm/" - "/components/esp_rom/" - - "/components/esp_timer/" - "/components/esp_wifi/" - "/components/esp-tls/" - "/components/espcoredump/" @@ -80,8 +79,6 @@ components_not_formatted_temporary: - "/components/idf_test/" - "/components/ieee802154/" - "/components/json/" - - "/components/linux/" - - "/components/log/" - "/components/lwip/" - "/components/mbedtls/" - "/components/mqtt/"