diff --git a/drivers/counter/counter_handlers.c b/drivers/counter/counter_handlers.c index cca16156347972..4d4c6cf91612ba 100644 --- a/drivers/counter/counter_handlers.c +++ b/drivers/counter/counter_handlers.c @@ -21,5 +21,5 @@ COUNTER_HANDLER(get_pending_int) COUNTER_HANDLER(read) COUNTER_HANDLER(stop) COUNTER_HANDLER(start) -COUNTER_HANDLER(get_wrap) +COUNTER_HANDLER(get_top_value) COUNTER_HANDLER(get_max_relative_alarm) diff --git a/drivers/counter/counter_nrfx_rtc.c b/drivers/counter/counter_nrfx_rtc.c index 8de475b5bb709e..f7b11f1eac991e 100644 --- a/drivers/counter/counter_nrfx_rtc.c +++ b/drivers/counter/counter_nrfx_rtc.c @@ -14,18 +14,18 @@ LOG_MODULE_REGISTER(); #define RTC_CLOCK 32768 -#define COUNTER_MAX_WRAP RTC_COUNTER_COUNTER_Msk +#define COUNTER_MAX_TOP_VALUE RTC_COUNTER_COUNTER_Msk #define CC_TO_ID(cc) ((cc) - 1) #define ID_TO_CC(id) ((id) + 1) -#define WRAP_CH 0 -#define COUNTER_WRAP_INT NRFX_RTC_INT_COMPARE0 +#define TOP_CH 0 +#define COUNTER_TOP_INT NRFX_RTC_INT_COMPARE0 struct counter_nrfx_data { - counter_wrap_callback_t wrap_cb; - void *wrap_user_data; - u32_t wrap; + counter_top_callback_t top_cb; + void *top_user_data; + u32_t top; }; struct counter_nrfx_ch_data { @@ -79,7 +79,7 @@ static int counter_nrfx_set_alarm(struct device *dev, u8_t chan_id, const nrfx_rtc_t *rtc = &nrfx_config->rtc; u32_t cc_val; - if (alarm_cfg->ticks > get_dev_data(dev)->wrap) { + if (alarm_cfg->ticks > get_dev_data(dev)->top) { return -EINVAL; } @@ -89,8 +89,8 @@ static int counter_nrfx_set_alarm(struct device *dev, u8_t chan_id, cc_val = alarm_cfg->ticks + (alarm_cfg->absolute ? 0 : nrfx_rtc_counter_get(rtc)); - cc_val = (cc_val > get_dev_data(dev)->wrap) ? - (cc_val - get_dev_data(dev)->wrap) : cc_val; + cc_val = (cc_val > get_dev_data(dev)->top) ? + (cc_val - get_dev_data(dev)->top) : cc_val; nrfx_config->ch_data[chan_id].callback = alarm_cfg->callback; nrfx_config->ch_data[chan_id].user_data = alarm_cfg->user_data; @@ -114,9 +114,9 @@ static int counter_nrfx_disable_alarm(struct device *dev, u8_t chan_id) return 0; } -static int counter_nrfx_set_wrap(struct device *dev, u32_t ticks, - counter_wrap_callback_t callback, - void *user_data) +static int counter_nrfx_set_top_value(struct device *dev, u32_t ticks, + counter_top_callback_t callback, + void *user_data) { const struct counter_nrfx_config *nrfx_config = get_nrfx_config(dev); const nrfx_rtc_t *rtc = &nrfx_config->rtc; @@ -131,13 +131,13 @@ static int counter_nrfx_set_wrap(struct device *dev, u32_t ticks, } } - nrfx_rtc_cc_disable(rtc, WRAP_CH); + nrfx_rtc_cc_disable(rtc, TOP_CH); nrfx_rtc_counter_clear(rtc); - dev_data->wrap_cb = callback; - dev_data->wrap_user_data = user_data; - dev_data->wrap = ticks; - nrfx_rtc_cc_set(rtc, WRAP_CH, ticks, callback ? true : false); + dev_data->top_cb = callback; + dev_data->top_user_data = user_data; + dev_data->top = ticks; + nrfx_rtc_cc_set(rtc, TOP_CH, ticks, callback ? true : false); return 0; } @@ -168,18 +168,18 @@ static void event_handler(nrfx_rtc_int_type_t int_type, void *p_context) struct device *dev = p_context; struct counter_nrfx_data *data = get_dev_data(dev); - if (int_type == COUNTER_WRAP_INT) { - /* Manually reset counter when wrap is different than max wrap*/ - if (data->wrap != COUNTER_MAX_WRAP) { + if (int_type == COUNTER_TOP_INT) { + /* Manually reset counter if top value is different than max. */ + if (data->top != COUNTER_MAX_TOP_VALUE) { nrfx_rtc_counter_clear(&get_nrfx_config(dev)->rtc); nrfx_rtc_cc_set(&get_nrfx_config(dev)->rtc, - WRAP_CH, data->wrap, true); + TOP_CH, data->top, true); } - if (data->wrap_cb) { - data->wrap_cb(dev, data->wrap_user_data); + if (data->top_cb) { + data->top_cb(dev, data->top_user_data); } - } else if (int_type > COUNTER_WRAP_INT) { + } else if (int_type > COUNTER_TOP_INT) { alarm_event_handler(dev, CC_TO_ID(int_type)); } @@ -207,21 +207,21 @@ static int init_rtc(struct device *dev, return -EBUSY; } - get_dev_data(dev)->wrap = COUNTER_MAX_WRAP; + get_dev_data(dev)->top = COUNTER_MAX_TOP_VALUE; LOG_INST_DBG(nrfx_config->log, "Initialized"); return 0; } -static u32_t counter_nrfx_get_wrap(struct device *dev) +static u32_t counter_nrfx_get_top_value(struct device *dev) { - return get_dev_data(dev)->wrap; + return get_dev_data(dev)->top; } static u32_t counter_nrfx_get_max_relative_alarm(struct device *dev) { /* Maybe decreased. */ - return get_dev_data(dev)->wrap; + return get_dev_data(dev)->top; } static const struct counter_driver_api counter_nrfx_driver_api = { @@ -230,9 +230,9 @@ static const struct counter_driver_api counter_nrfx_driver_api = { .read = counter_nrfx_read, .set_alarm = counter_nrfx_set_alarm, .disable_alarm = counter_nrfx_disable_alarm, - .set_wrap = counter_nrfx_set_wrap, + .set_top_value = counter_nrfx_set_top_value, .get_pending_int = counter_nrfx_get_pending_int, - .get_wrap = counter_nrfx_get_wrap, + .get_top_value = counter_nrfx_get_top_value, .get_max_relative_alarm = counter_nrfx_get_max_relative_alarm, }; @@ -258,7 +258,7 @@ static const struct counter_driver_api counter_nrfx_driver_api = { LOG_INSTANCE_REGISTER(LOG_MODULE_NAME, idx, CONFIG_COUNTER_LOG_LEVEL); \ static const struct counter_nrfx_config nrfx_counter_##idx##_config = {\ .info = { \ - .max_wrap = COUNTER_MAX_WRAP, \ + .max_top_value = COUNTER_MAX_TOP_VALUE, \ .freq = RTC_CLOCK / \ (CONFIG_COUNTER_RTC##idx##_PRESCALER + 1), \ .count_up = true, \ diff --git a/drivers/counter/counter_nrfx_timer.c b/drivers/counter/counter_nrfx_timer.c index bb17c9a2659373..791de4b69d43e4 100644 --- a/drivers/counter/counter_nrfx_timer.c +++ b/drivers/counter/counter_nrfx_timer.c @@ -20,14 +20,14 @@ LOG_MODULE_REGISTER(); #define COUNTER_EVENT_TO_ID(evt) \ (evt - NRF_TIMER_EVENT_COMPARE2)/sizeof(u32_t) -#define WRAP_CH NRF_TIMER_CC_CHANNEL0 -#define COUNTER_WRAP_INT NRF_TIMER_EVENT_COMPARE0 +#define TOP_CH NRF_TIMER_CC_CHANNEL0 +#define COUNTER_TOP_INT NRF_TIMER_EVENT_COMPARE0 #define COUNTER_OVERFLOW_SHORT NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK #define COUNTER_READ_CC NRF_TIMER_CC_CHANNEL1 struct counter_nrfx_data { - counter_wrap_callback_t wrap_cb; - void *wrap_user_data; + counter_top_callback_t top_cb; + void *top_user_data; }; struct counter_nrfx_ch_data { @@ -82,7 +82,7 @@ static int counter_nrfx_set_alarm(struct device *dev, u8_t chan_id, const nrfx_timer_t *timer = &nrfx_config->timer; u32_t cc_val; - if (alarm_cfg->ticks > nrfx_timer_capture_get(timer, WRAP_CH)) { + if (alarm_cfg->ticks > nrfx_timer_capture_get(timer, TOP_CH)) { return -EINVAL; } @@ -108,7 +108,7 @@ static void _disable(struct device *dev, u8_t id) config->ch_data[id].callback = NULL; } -static int counter_nrfx_disable_alarm(struct device *dev,u8_t chan_id) +static int counter_nrfx_disable_alarm(struct device *dev, u8_t chan_id) { _disable(dev, chan_id); @@ -116,9 +116,9 @@ static int counter_nrfx_disable_alarm(struct device *dev,u8_t chan_id) } -static int counter_nrfx_set_wrap(struct device *dev, u32_t ticks, - counter_wrap_callback_t callback, - void *user_data) +static int counter_nrfx_set_top_value(struct device *dev, u32_t ticks, + counter_top_callback_t callback, + void *user_data) { const struct counter_nrfx_config *nrfx_config = get_nrfx_config(dev); const nrfx_timer_t *timer = &nrfx_config->timer; @@ -133,12 +133,12 @@ static int counter_nrfx_set_wrap(struct device *dev, u32_t ticks, } } - nrfx_timer_compare_int_disable(timer, WRAP_CH); + nrfx_timer_compare_int_disable(timer, TOP_CH); nrfx_timer_clear(timer); - data->wrap_cb = callback; - data->wrap_user_data = user_data; - nrfx_timer_extended_compare(timer, WRAP_CH, + data->top_cb = callback; + data->top_user_data = user_data; + nrfx_timer_extended_compare(timer, TOP_CH, ticks, COUNTER_OVERFLOW_SHORT, callback ? true : false); @@ -170,9 +170,9 @@ static void event_handler(nrf_timer_event_t event_type, void *p_context) struct device *dev = p_context; struct counter_nrfx_data *dev_data = get_dev_data(dev); - if (event_type == COUNTER_WRAP_INT) { - if (dev_data->wrap_cb) { - dev_data->wrap_cb(dev, dev_data->wrap_user_data); + if (event_type == COUNTER_TOP_INT) { + if (dev_data->top_cb) { + dev_data->top_cb(dev, dev_data->top_user_data); } } else if (event_type > NRF_TIMER_EVENT_COMPARE1) { alarm_event_handler(dev, COUNTER_EVENT_TO_ID(event_type)); @@ -192,21 +192,21 @@ static int init_timer(struct device *dev, const nrfx_timer_config_t *config) return -EBUSY; } - nrfx_timer_compare(timer, WRAP_CH, UINT32_MAX, false); + nrfx_timer_compare(timer, TOP_CH, UINT32_MAX, false); LOG_INST_DBG(nrfx_config->log, "Initialized"); return 0; } -static u32_t counter_nrfx_get_wrap(struct device *dev) +static u32_t counter_nrfx_get_top_value(struct device *dev) { - return nrfx_timer_capture_get(&get_nrfx_config(dev)->timer, WRAP_CH); + return nrfx_timer_capture_get(&get_nrfx_config(dev)->timer, TOP_CH); } static u32_t counter_nrfx_get_max_relative_alarm(struct device *dev) { - return nrfx_timer_capture_get(&get_nrfx_config(dev)->timer, WRAP_CH); + return nrfx_timer_capture_get(&get_nrfx_config(dev)->timer, TOP_CH); } static const struct counter_driver_api counter_nrfx_driver_api = { @@ -215,9 +215,9 @@ static const struct counter_driver_api counter_nrfx_driver_api = { .read = counter_nrfx_read, .set_alarm = counter_nrfx_set_alarm, .disable_alarm = counter_nrfx_disable_alarm, - .set_wrap = counter_nrfx_set_wrap, + .set_top_value = counter_nrfx_set_top_value, .get_pending_int = counter_nrfx_get_pending_int, - .get_wrap = counter_nrfx_get_wrap, + .get_top_value = counter_nrfx_get_top_value, .get_max_relative_alarm = counter_nrfx_get_max_relative_alarm, }; @@ -243,7 +243,7 @@ static const struct counter_driver_api counter_nrfx_driver_api = { LOG_INSTANCE_REGISTER(LOG_MODULE_NAME, idx, CONFIG_COUNTER_LOG_LEVEL); \ static const struct counter_nrfx_config nrfx_counter_##idx##_config = {\ .info = { \ - .max_wrap = (TIMER##idx##_MAX_SIZE == 32) ? \ + .max_top_value = (TIMER##idx##_MAX_SIZE == 32) ? \ 0xffffffff : 0x0000ffff, \ .freq = TIMER_CLOCK / \ (1 << CONFIG_COUNTER_TIMER##idx##_PRESCALER), \ diff --git a/include/counter.h b/include/counter.h index 3bb5cf37d17557..be3a7d6eeb8e3e 100644 --- a/include/counter.h +++ b/include/counter.h @@ -44,12 +44,13 @@ typedef void (*counter_alarm_callback_t)(struct device *dev, * * @param callback Callback called on alarm (cannot be NULL). * @param ticks Ticks that triggers the alarm. In case of absolute flag is set, - * maximal value that can be set equals wrap value - * (counter_get_wrap). Otherwise counter_get_max_relative_alarm() - * returns maximal value that can be set. If counter is clock - * driven then ticks can be converted to microseconds (see @ref - * counter_ticks_to_us). Alternatively, counter implementation may - * count asynchronous events. + * maximal value that can be set equals top value + * (@ref counter_get_top_value). Otherwise + * @ref counter_get_max_relative_alarm() returns maximal value that + * can be set. If counter is clock driven then ticks can be + * converted to microseconds (see @ref counter_ticks_to_us). + * Alternatively, counter implementation may count asynchronous + * events. * @param user_data User data returned in callback. * @param absolute Ticks relation to counter value. If true ticks are treated as * absolute value, else it is relative to the counter reading @@ -62,25 +63,26 @@ struct counter_alarm_cfg { bool absolute; }; -/** @brief Wrap callback +/** @brief Callback called when counter turns around. * * @param dev Pointer to the device structure for the driver instance. - * @param user_data User data provided in counter_set_wrap_alarm. + * @param user_data User data provided in @ref counter_set_top_value. */ -typedef void (*counter_wrap_callback_t)(struct device *dev, void *user_data); +typedef void (*counter_top_callback_t)(struct device *dev, void *user_data); /** @brief Structure with generic counter features. * - * @param max_wrap Maximal (default) wrap value on which counter is reset - * (cleared or reloaded). - * @param freq Frequency of the source clock if synchronous events are counted. - * @param count_up Flag indicating direction of the counter. If true counter is - * counting up else counting down. - * @param channels Number of channels that can be used for setting alarm, - * see @ref counter_set_alarm. + * @param max_top_value Maximal (default) top value on which counter is reset + * (cleared or reloaded). + * @param freq Frequency of the source clock if synchronous events are + * counted. + * @param count_up Flag indicating direction of the counter. If true + * counter is counting up else counting down. + * @param channels Number of channels that can be used for setting alarm, + * see @ref counter_set_alarm. */ struct counter_config_info { - u32_t max_wrap; + u32_t max_top_value; u32_t freq; bool count_up; u8_t channels; @@ -92,11 +94,11 @@ typedef u32_t (*counter_api_read)(struct device *dev); typedef int (*counter_api_set_alarm)(struct device *dev, u8_t chan_id, const struct counter_alarm_cfg *alarm_cfg); typedef int (*counter_api_disable_alarm)(struct device *dev, u8_t chan_id); -typedef int (*counter_api_set_wrap)(struct device *dev, u32_t ticks, - counter_wrap_callback_t callback, +typedef int (*counter_api_set_top_value)(struct device *dev, u32_t ticks, + counter_top_callback_t callback, void *user_data); typedef u32_t (*counter_api_get_pending_int)(struct device *dev); -typedef u32_t (*counter_api_get_wrap)(struct device *dev); +typedef u32_t (*counter_api_get_top_value)(struct device *dev); typedef u32_t (*counter_api_get_max_relative_alarm)(struct device *dev); typedef void *(*counter_api_get_user_data)(struct device *dev); @@ -106,9 +108,9 @@ struct counter_driver_api { counter_api_read read; counter_api_set_alarm set_alarm; counter_api_disable_alarm disable_alarm; - counter_api_set_wrap set_wrap; + counter_api_set_top_value set_top_value; counter_api_get_pending_int get_pending_int; - counter_api_get_wrap get_wrap; + counter_api_get_top_value get_top_value; counter_api_get_max_relative_alarm get_max_relative_alarm; counter_api_get_user_data get_user_data; }; @@ -190,17 +192,17 @@ static inline u64_t counter_ticks_to_us(const struct device *dev, u32_t ticks) } /** - * @brief Function to retrieve maximum wrap value that can be set. + * @brief Function to retrieve maximum top value that can be set. * * @param[in] dev Pointer to the device structure for the driver instance. * - * @return Max wrap value. + * @return Max top value. */ -static inline u32_t counter_get_max_wrap(const struct device *dev) +static inline u32_t counter_get_max_top_value(const struct device *dev) { const struct counter_config_info *config = dev->config->config_info; - return config->max_wrap; + return config->max_top_value; } /** @@ -257,9 +259,9 @@ static inline u32_t _impl_counter_read(struct device *dev) * @brief Set an alarm on a channel. * * In case of absolute request, maximal value that can be set is equal to - * wrap value set by counter_set_wrap call or default, maximal one. in case of - * relative request, Maximal value can be retrieved using - * counter_get_max_relative_alarm. + * top value set by @ref counter_set_top_value call or default, maximal one. In + * case of relative request, maximal value can be retrieved using + * @ref counter_get_max_relative_alarm. * * @param dev Pointer to the device structure for the driver instance. * @param chan_id Channel ID. @@ -305,35 +307,35 @@ static inline int counter_disable_channel_alarm(struct device *dev, } /** - * @brief Set counter wrap. + * @brief Set counter top value. * - * Function sets wrap value and resets the counter to 0 or wrap value - * depending on counter direction. On wrap, counter is reset and optinal - * callback is periodically called. Wrap value can only be changed when there - * is no active alarm. + * Function sets top value and resets the counter to 0 or top value + * depending on counter direction. On turnaround, counter is reset and optional + * callback is periodically called. Top value can only be changed when there + * is no active channel alarm. * * @param dev Pointer to the device structure for the driver instance. - * @param ticks Wrap value. + * @param ticks Top value. * @param callback Callback function. Can be NULL. * @param user_data User data passed to callback function. Not valid if * callback is NULL. * * @retval 0 If successful. - * @retval -ENOTSUP if request is not supported (e.g. wrap value cannot be + * @retval -ENOTSUP if request is not supported (e.g. top value cannot be * changed). * @retval -EBUSY if any alarm is active. */ -static inline int counter_set_wrap(struct device *dev, u32_t ticks, - counter_wrap_callback_t callback, - void *user_data) +static inline int counter_set_top_value(struct device *dev, u32_t ticks, + counter_top_callback_t callback, + void *user_data) { const struct counter_driver_api *api = dev->driver_api; - if (ticks > counter_get_max_wrap(dev)) { + if (ticks > counter_get_max_top_value(dev)) { return -EINVAL; } - return api->set_wrap(dev, ticks, callback, user_data); + return api->set_top_value(dev, ticks, callback, user_data); } /** @@ -359,19 +361,19 @@ static inline int _impl_counter_get_pending_int(struct device *dev) } /** - * @brief Function to retrieve current wrap value. + * @brief Function to retrieve current top value. * * @param[in] dev Pointer to the device structure for the driver instance. * - * @return Wrap value. + * @return Top value. */ -__syscall u32_t counter_get_wrap(struct device *dev); +__syscall u32_t counter_get_top_value(struct device *dev); -static inline u32_t _impl_counter_get_wrap(struct device *dev) +static inline u32_t _impl_counter_get_top_value(struct device *dev) { const struct counter_driver_api *api = dev->driver_api; - return api->get_wrap(dev); + return api->get_top_value(dev); } /** @@ -401,11 +403,11 @@ __deprecated static inline int counter_set_alarm(struct device *dev, counter_callback_t callback, u32_t count, void *user_data) { - return counter_set_wrap(dev, count, callback, user_data); + return counter_set_top_value(dev, count, callback, user_data); } /** - * @brief Get user data set for wrap alarm. + * @brief Get user data set for top alarm. * * @note Function intended to be used only by deprecated RTC driver API to * provide backward compatibility. diff --git a/tests/drivers/counter/counter_basic_api/src/test_counter.c b/tests/drivers/counter/counter_basic_api/src/test_counter.c index 9a287e388909d7..8f510b27fceec2 100644 --- a/tests/drivers/counter/counter_basic_api/src/test_counter.c +++ b/tests/drivers/counter/counter_basic_api/src/test_counter.c @@ -8,14 +8,14 @@ #include #include -static volatile u32_t wrap_cnt; +static volatile u32_t top_cnt; static volatile u32_t alarm_cnt; -static void wrap_handler(struct device *dev, void *user_data); +static void top_handler(struct device *dev, void *user_data); void *exp_user_data = (void *)199; -#define WRAP_PERIOD_US 20000 +#define COUNTER_PERIOD_US 20000 struct counter_alarm_cfg alarm_cfg; struct counter_alarm_cfg alarm_cfg2; @@ -57,8 +57,9 @@ static void counter_tear_down_instance(const char *dev_name) dev = device_get_binding(dev_name); - err = counter_set_wrap(dev, counter_get_max_wrap(dev), NULL, NULL); - zassert_equal(0, err, "Counter wrap to default failed\n"); + err = counter_set_top_value(dev, counter_get_max_top_value(dev), + NULL, NULL); + zassert_equal(0, err, "Setting top value to default failed\n"); err = counter_stop(dev); zassert_equal(0, err, "Counter failed to stop\n"); @@ -77,23 +78,23 @@ void counter_tear_down(void) } -static void wrap_handler(struct device *dev, void *user_data) +static void top_handler(struct device *dev, void *user_data) { zassert_true(user_data == exp_user_data, "Unexpected callback\n"); - wrap_cnt++; + top_cnt++; } -void test_wrap_alarm_instance(const char *dev_name) +void test_set_top_value_with_alarm_instance(const char *dev_name) { struct device *dev; int err; u32_t cnt; u32_t ticks; - wrap_cnt = 0; + top_cnt = 0; dev = device_get_binding(dev_name); - ticks = counter_us_to_ticks(dev, WRAP_PERIOD_US); + ticks = counter_us_to_ticks(dev, COUNTER_PERIOD_US); err = counter_start(dev); zassert_equal(0, err, "Counter failed to start\n"); @@ -103,20 +104,20 @@ void test_wrap_alarm_instance(const char *dev_name) cnt = counter_read(dev); zassert_true(cnt > 0, "Counter should progress (dev:%s)\n", dev_name); - err = counter_set_wrap(dev, ticks, wrap_handler, exp_user_data); - zassert_equal(0, err, "Counter failed to set wrap (dev:%s)\n", + err = counter_set_top_value(dev, ticks, top_handler, exp_user_data); + zassert_equal(0, err, "Counter failed to set top value (dev:%s)\n", dev_name); - k_busy_wait(5.2*WRAP_PERIOD_US); + k_busy_wait(5.2*COUNTER_PERIOD_US); - zassert_true(wrap_cnt == 5, - "Unexpected number of wraps (%d) (dev: %s).\n", - wrap_cnt, dev_name); + zassert_true(top_cnt == 5, + "Unexpected number of turnarounds (%d) (dev: %s).\n", + top_cnt, dev_name); } -void test_wrap_alarm(void) +void test_set_top_value_with_alarm(void) { - test_all_instances(test_wrap_alarm_instance); + test_all_instances(test_set_top_value_with_alarm_instance); } static void alarm_handler(struct device *dev, u8_t chan_id, u32_t counter, @@ -133,7 +134,7 @@ void test_single_shot_alarm_instance(const char *dev_name) u32_t ticks; dev = device_get_binding(dev_name); - ticks = counter_us_to_ticks(dev, WRAP_PERIOD_US); + ticks = counter_us_to_ticks(dev, COUNTER_PERIOD_US); alarm_cfg.absolute = true; alarm_cfg.ticks = ticks + 1; @@ -145,11 +146,12 @@ void test_single_shot_alarm_instance(const char *dev_name) err = counter_start(dev); zassert_equal(0, err, "Counter failed to start\n"); - err = counter_set_wrap(dev, ticks, wrap_handler, exp_user_data); - zassert_equal(0, err, "Counter failed to set wrap\n"); + err = counter_set_top_value(dev, ticks, top_handler, exp_user_data); + zassert_equal(0, err, "Counter failed to set top value\n"); err = counter_set_channel_alarm(dev, 0, &alarm_cfg); - zassert_equal(-EINVAL, err, "Counter should return error because ticks exceeded the limit set alarm\n"); + zassert_equal(-EINVAL, err, "Counter should return error because ticks" + " exceeded the limit set alarm\n"); alarm_cfg.ticks = ticks - 100; err = counter_set_channel_alarm(dev, 0, &alarm_cfg); @@ -165,8 +167,9 @@ void test_single_shot_alarm_instance(const char *dev_name) err = counter_disable_channel_alarm(dev, 0); zassert_equal(0, err, "Counter disabling alarm failed\n"); - err = counter_set_wrap(dev, counter_get_max_wrap(dev), NULL, NULL); - zassert_equal(0, err, "Counter wrap to default failed\n"); + err = counter_set_top_value(dev, counter_get_max_top_value(dev), + NULL, NULL); + zassert_equal(0, err, "Setting top value to default failed\n"); err = counter_stop(dev); zassert_equal(0, err, "Counter failed to stop\n"); @@ -190,7 +193,7 @@ static void alarm_handler2(struct device *dev, u8_t chan_id, u32_t counter, * Two alarms set. First alarm is absolute, second relative. Because * setting of both alarms is delayed it is expected that second alarm * will expire first (relative to the time called) while first alarm - * will expire after next wrap. + * will expire after next wrap around. */ void test_multiple_alarms_instance(const char *dev_name) { @@ -199,7 +202,7 @@ void test_multiple_alarms_instance(const char *dev_name) u32_t ticks; dev = device_get_binding(dev_name); - ticks = counter_us_to_ticks(dev, WRAP_PERIOD_US); + ticks = counter_us_to_ticks(dev, COUNTER_PERIOD_US); alarm_cfg.absolute = true; alarm_cfg.ticks = counter_us_to_ticks(dev, 2000); @@ -216,8 +219,8 @@ void test_multiple_alarms_instance(const char *dev_name) err = counter_start(dev); zassert_equal(0, err, "Counter failed to start\n"); - err = counter_set_wrap(dev, ticks, wrap_handler, exp_user_data); - zassert_equal(0, err, "Counter failed to set wrap\n"); + err = counter_set_top_value(dev, ticks, top_handler, exp_user_data); + zassert_equal(0, err, "Counter failed to set top value\n"); k_busy_wait(1.4*counter_ticks_to_us(dev, alarm_cfg.ticks)); @@ -258,7 +261,7 @@ void test_all_channels_instance(const char *str) u32_t ticks; dev = device_get_binding(str); - ticks = counter_us_to_ticks(dev, WRAP_PERIOD_US); + ticks = counter_us_to_ticks(dev, COUNTER_PERIOD_US); for (int i = 0; i < n; i++) { alarm_cfgs[i].absolute = false; @@ -276,7 +279,8 @@ void test_all_channels_instance(const char *str) } else if (err == -ENOTSUP) { limit_reached = true; } else { - zassert_equal(0, 1, "Unexpected error on setting alarm"); + zassert_equal(0, 1, + "Unexpected error on setting alarm"); } } @@ -287,7 +291,8 @@ void test_all_channels_instance(const char *str) for (int i = nchan; i < n; i++) { err = counter_disable_channel_alarm(dev, i); - zassert_equal(-ENOTSUP, err, "Unexpected error on disabling alarm\n"); + zassert_equal(-ENOTSUP, err, + "Unexpected error on disabling alarm\n"); } } @@ -299,7 +304,7 @@ void test_all_channels(void) void test_main(void) { ztest_test_suite(test_counter, - ztest_unit_test_setup_teardown(test_wrap_alarm, + ztest_unit_test_setup_teardown(test_set_top_value_with_alarm, unit_test_noop, counter_tear_down), ztest_unit_test_setup_teardown(test_single_shot_alarm,