diff --git a/include/etl/callback_timer.h b/include/etl/callback_timer.h index c0b4c72d..2547e346 100644 --- a/include/etl/callback_timer.h +++ b/include/etl/callback_timer.h @@ -423,13 +423,13 @@ namespace etl ETL_DISABLE_TIMER_UPDATES; active_list.remove(timer.id, false); ETL_ENABLE_TIMER_UPDATES; - - // Reset in-place. - new (&timer) callback_timer_data(); - --registered_timers; - - result = true; } + + // Reset in-place. + new (&timer) callback_timer_data(); + --registered_timers; + + result = true; } } @@ -588,8 +588,9 @@ namespace etl ETL_DISABLE_TIMER_UPDATES; active_list.remove(timer.id, false); ETL_ENABLE_TIMER_UPDATES; - result = true; } + + result = true; } } @@ -604,7 +605,7 @@ namespace etl if (stop(id_)) { timer_array[id_].period = period_; - return start(id_); + return true; } return false; @@ -618,7 +619,7 @@ namespace etl if (stop(id_)) { timer_array[id_].repeating = repeating_; - return start(id_); + return true; } return false; diff --git a/include/etl/message_timer.h b/include/etl/message_timer.h index 9ec27add..9dab4780 100644 --- a/include/etl/message_timer.h +++ b/include/etl/message_timer.h @@ -392,13 +392,13 @@ namespace etl ETL_DISABLE_TIMER_UPDATES; active_list.remove(timer.id, true); ETL_ENABLE_TIMER_UPDATES; - - // Reset in-place. - new (&timer) message_timer_data(); - --registered_timers; - - result = true; } + + // Reset in-place. + new (&timer) message_timer_data(); + --registered_timers; + + result = true; } } @@ -557,8 +557,9 @@ namespace etl ETL_DISABLE_TIMER_UPDATES; active_list.remove(timer.id, false); ETL_ENABLE_TIMER_UPDATES; - result = true; } + + result = true; } } @@ -573,7 +574,7 @@ namespace etl if (stop(id_)) { timer_array[id_].period = period_; - return start(id_); + return true; } return false; @@ -587,7 +588,7 @@ namespace etl if (stop(id_)) { timer_array[id_].repeating = repeating_; - return start(id_); + return true; } return false; diff --git a/include/etl/version.h b/include/etl/version.h index c00eabc8..21282bce 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -37,10 +37,10 @@ SOFTWARE. /// Definitions of the ETL version ///\ingroup utilities -#define ETL_VERSION "11.8.0" +#define ETL_VERSION "11.9.1" #define ETL_VERSION_MAJOR 11 -#define ETL_VERSION_MINOR 8 -#define ETL_VERSION_PATCH 0 +#define ETL_VERSION_MINOR 9 +#define ETL_VERSION_PATCH 1 #endif diff --git a/src/c/ecl_timer.c b/src/c/ecl_timer.c index 004ee669..145cb3e3 100644 --- a/src/c/ecl_timer.c +++ b/src/c/ecl_timer.c @@ -340,13 +340,13 @@ ecl_timer_result_t ecl_timer_unregister(ecl_timer_id_t id_) ECL_TIMER_DISABLE_PROCESSING; ecl_timer_list_remove(ptimer->id, 0); ECL_TIMER_ENABLE_PROCESSING; - - // Reset in-place. - ecl_timer_data_init_default(ptimer); - --ecl.registered_timers; - - result = ECL_TIMER_PASS; } + + // Reset in-place. + ecl_timer_data_init_default(ptimer); + --ecl.registered_timers; + + result = ECL_TIMER_PASS; } } @@ -506,8 +506,9 @@ ecl_timer_result_t ecl_timer_stop(ecl_timer_id_t id_) ECL_TIMER_DISABLE_PROCESSING; ecl_timer_list_remove(ptimer->id, 0); ECL_TIMER_ENABLE_PROCESSING; - result = ECL_TIMER_PASS; } + + result = ECL_TIMER_PASS; } } @@ -524,7 +525,7 @@ ecl_timer_result_t ecl_timer_set_period(ecl_timer_id_t id_, ecl_timer_time_t per if (ecl_timer_stop(id_)) { ecl.ptimers[id_].period = period_; - return ecl_timer_start(id_, 0); + return ECL_TIMER_PASS; } return ECL_TIMER_FAIL; @@ -540,7 +541,7 @@ ecl_timer_result_t ecl_timer_set_mode(ecl_timer_id_t id_, ecl_timer_mode_t repea if (ecl_timer_stop(id_)) { ecl.ptimers[id_].repeating = repeating_; - return ecl_timer_start(id_, 0); + return ECL_TIMER_PASS; } return ECL_TIMER_FAIL; diff --git a/support/Release notes.txt b/support/Release notes.txt index 26605032..7fec4cc5 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,11 @@ +=============================================================================== +11.9.1 +Fix Github issue #73 (Timers) + +=============================================================================== +11.9.0 +Added CRC32-C (Castagnoli) + =============================================================================== 11.8.0 Added more binary utilities. diff --git a/test/test_c_timer_framework.cpp b/test/test_c_timer_framework.cpp index 47aa0aa9..ec03f140 100644 --- a/test/test_c_timer_framework.cpp +++ b/test/test_c_timer_framework.cpp @@ -149,6 +149,52 @@ namespace CHECK_ARRAY_EQUAL(compare3.data(), callback_list3.data(), compare3.size()); } + //========================================================================= + TEST(message_timer_one_shot_after_timeout) + { + ecl_timer_init(timers, NTIMERS); + + ecl_timer_id_t id1 = ecl_timer_register(callback1, 37, ECL_TIMER_SINGLE_SHOT); + callback_list1.clear(); + + ecl_timer_enable(ECL_TIMER_ENABLED); + ecl_timer_start(id1, ECL_TIMER_START_DELAYED); + + ticks = 0; + + const uint32_t step = 1; + + while (ticks <= 100U) + { + ticks += step; + ecl_timer_tick(step); + } + + // Timer should have timed out. + + CHECK(ecl_timer_set_period(id1, 50)); + ecl_timer_start(id1, ECL_TIMER_START_DELAYED); + + callback_list1.clear(); + + ticks = 0; + + while (ticks <= 100U) + { + ticks += step; + ecl_timer_tick(step); + } + + // Timer should have timed out. + + CHECK_EQUAL(50, *callback_list1.data()); + + CHECK(ecl_timer_unregister(id1)); + CHECK(!ecl_timer_unregister(id1)); + CHECK(!ecl_timer_start(id1, ECL_TIMER_START_DELAYED)); + CHECK(!ecl_timer_stop(id1)); + } + //========================================================================= TEST(ecl_timer_repeating) { diff --git a/test/test_callback_timer.cpp b/test/test_callback_timer.cpp index eed41124..5cf31bb4 100644 --- a/test/test_callback_timer.cpp +++ b/test/test_callback_timer.cpp @@ -169,6 +169,52 @@ namespace CHECK_ARRAY_EQUAL(compare3.data(), free_tick_list2.data(), compare3.size()); } + //========================================================================= + TEST(message_timer_one_shot_after_timeout) + { + etl::callback_timer<1> timer_controller; + + etl::timer::id::type id1 = timer_controller.register_timer(member_callback, 37, etl::timer::mode::SINGLE_SHOT); + test.tick_list.clear(); + + timer_controller.start(id1); + timer_controller.enable(true); + + ticks = 0; + + const uint32_t step = 1; + + while (ticks <= 100U) + { + ticks += step; + timer_controller.tick(step); + } + + // Timer should have timed out. + + CHECK(timer_controller.set_period(id1, 50)); + timer_controller.start(id1); + + test.tick_list.clear(); + + ticks = 0; + + while (ticks <= 100U) + { + ticks += step; + timer_controller.tick(step); + } + + // Timer should have timed out. + + CHECK_EQUAL(50, *test.tick_list.data()); + + CHECK(timer_controller.unregister_timer(id1)); + CHECK(!timer_controller.unregister_timer(id1)); + CHECK(!timer_controller.start(id1)); + CHECK(!timer_controller.stop(id1)); + } + //========================================================================= TEST(callback_timer_repeating) { diff --git a/test/test_message_timer.cpp b/test/test_message_timer.cpp index b8b3488c..e7659d80 100644 --- a/test/test_message_timer.cpp +++ b/test/test_message_timer.cpp @@ -191,6 +191,52 @@ namespace CHECK_ARRAY_EQUAL(compare3.data(), router1.message3.data(), compare3.size()); } + //========================================================================= + TEST(message_timer_one_shot_after_timeout) + { + etl::message_timer<1> timer_controller; + + etl::timer::id::type id1 = timer_controller.register_timer(message1, router1, 37, etl::timer::mode::SINGLE_SHOT); + router1.clear(); + + timer_controller.start(id1); + timer_controller.enable(true); + + ticks = 0; + + const uint32_t step = 1; + + while (ticks <= 100U) + { + ticks += step; + timer_controller.tick(step); + } + + // Timer should have timed out. + + CHECK(timer_controller.set_period(id1, 50)); + timer_controller.start(id1); + + router1.clear(); + + ticks = 0; + + while (ticks <= 100U) + { + ticks += step; + timer_controller.tick(step); + } + + // Timer should have timed out. + + CHECK_EQUAL(50, *router1.message1.data()); + + CHECK(timer_controller.unregister_timer(id1)); + CHECK(!timer_controller.unregister_timer(id1)); + CHECK(!timer_controller.start(id1)); + CHECK(!timer_controller.stop(id1)); + } + //========================================================================= TEST(message_timer_repeating) {