diff --git a/include/counter.h b/include/counter.h index bed4af6fcd2c42..df58b077275a09 100644 --- a/include/counter.h +++ b/include/counter.h @@ -77,6 +77,9 @@ struct counter_alarm_cfg { */ typedef void (*counter_wrap_callback_t)(struct device *dev, void *user_data); +__deprecated typedef void (*counter_callback_t)(struct device *dev, + void *user_data); + /** @brief Structure with generic counter features. */ struct counter_config_info { u32_t max_wrap; /*!< Maximal (default) wrap value on which counter is @@ -109,6 +112,7 @@ typedef int (*counter_api_set_wrap)(struct device *dev, u32_t ticks, 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_max_relative_alarm)(struct device *dev); +typedef void *(*counter_api_get_user_data)(struct device *dev); struct counter_driver_api { counter_api_start start; @@ -120,6 +124,7 @@ struct counter_driver_api { counter_api_get_pending_int get_pending_int; counter_api_get_wrap get_wrap; counter_api_get_max_relative_alarm get_max_relative_alarm; + counter_api_get_user_data get_user_data; }; @@ -248,7 +253,7 @@ static inline u32_t _impl_counter_read(struct device *dev) } /** - * @brief Set an alarm. + * @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 @@ -263,7 +268,7 @@ static inline u32_t _impl_counter_read(struct device *dev) * interrupts or requested channel). * @retval -EINVAL if alarm settings are invalid. */ -static inline int counter_set_alarm(struct device *dev, +static inline int counter_set_ch_alarm(struct device *dev, const struct counter_alarm_cfg *alarm_cfg) { const struct counter_driver_api *api = dev->driver_api; @@ -276,7 +281,7 @@ static inline int counter_set_alarm(struct device *dev, } /** - * @brief Disable an alarm. + * @brief Disable an alarm on a channel. * * @param dev Pointer to the device structure for the driver instance. * @param alarm_cfg Alarm configuration. It must be the same address as the @@ -286,7 +291,7 @@ static inline int counter_set_alarm(struct device *dev, * @retval -ENOTSUP if request is not supported or the counter was not started * yet. */ -static inline int counter_disable_alarm(struct device *dev, +static inline int counter_disable_ch_alarm(struct device *dev, const struct counter_alarm_cfg *alarm_cfg) { const struct counter_driver_api *api = dev->driver_api; @@ -389,6 +394,33 @@ static inline u32_t _impl_counter_get_max_relative_alarm(struct device *dev) } #endif +__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); +} + +/** + * @brief Get user data set for wrap alarm. + * + * @note Function intended to be used only by deprecated RTC driver API to + * provide backward compatibility. + * + * @param dev Pointer to the device structure for the driver instance. + * + * @return User data. + */ +__deprecated static inline void *counter_get_user_data(struct device *dev) +{ + const struct counter_driver_api *api = dev->driver_api; + + if (api->get_user_data) { + return api->get_user_data(dev); + } else { + return NULL; + } +} /** * @} */ diff --git a/include/rtc.h b/include/rtc.h index f72d4e8157abe6..21bfcbd8e17868 100644 --- a/include/rtc.h +++ b/include/rtc.h @@ -9,6 +9,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -26,7 +27,7 @@ extern "C" { /** Number of RTC ticks in a day */ #define RTC_ALARM_DAY (RTC_ALARM_HOUR * 24) - +typedef void (*rtc_callback_t)(struct device *dev); struct rtc_config { u32_t init_val; @@ -36,7 +37,7 @@ struct rtc_config { u32_t alarm_val; /*!< Pointer to function to call when alarm value * matches current RTC value */ - void (*cb_fn)(struct device *dev); + rtc_callback_t cb_fn; }; typedef void (*rtc_api_enable)(struct device *dev); @@ -57,49 +58,64 @@ struct rtc_driver_api { rtc_api_get_pending_int get_pending_int; }; -__syscall u32_t rtc_read(struct device *dev); +__deprecated __syscall u32_t rtc_read(struct device *dev); static inline u32_t _impl_rtc_read(struct device *dev) { - const struct rtc_driver_api *api = dev->driver_api; - - return api->read(dev); + return counter_read(dev); } -__syscall void rtc_enable(struct device *dev); +__deprecated __syscall void rtc_enable(struct device *dev); static inline void _impl_rtc_enable(struct device *dev) { - const struct rtc_driver_api *api = dev->driver_api; - - api->enable(dev); + counter_start(dev); } -__syscall void rtc_disable(struct device *dev); +__deprecated __syscall void rtc_disable(struct device *dev); static inline void _impl_rtc_disable(struct device *dev) { - const struct rtc_driver_api *api = dev->driver_api; + counter_stop(dev); +} + +static inline void rtc_counter_wrap_callback(struct device *dev, + void *user_data) +{ + rtc_callback_t cb_fn = (rtc_callback_t)user_data; - api->disable(dev); + if (cb_fn) { + cb_fn(dev); + } } -static inline int rtc_set_config(struct device *dev, - struct rtc_config *cfg) +__deprecated static inline int rtc_set_config(struct device *dev, + struct rtc_config *cfg) { - const struct rtc_driver_api *api = dev->driver_api; + int err; - return api->set_config(dev, cfg); + if (cfg->init_val) { + return -ENOTSUP; + } + + err = counter_set_wrap(dev, cfg->alarm_val, rtc_counter_wrap_callback, + cfg->cb_fn); + + if (!err && cfg->alarm_enable) { + err = counter_start(dev); + } + + return err; } -__syscall int rtc_set_alarm(struct device *dev, const u32_t alarm_val); +__deprecated __syscall int rtc_set_alarm(struct device *dev, + const u32_t alarm_val); static inline int _impl_rtc_set_alarm(struct device *dev, const u32_t alarm_val) { - const struct rtc_driver_api *api = dev->driver_api; - - return api->set_alarm(dev, alarm_val); + return counter_set_wrap(dev, alarm_val, rtc_counter_wrap_callback, + counter_get_user_data(dev)); } /** @@ -115,14 +131,11 @@ static inline int _impl_rtc_set_alarm(struct device *dev, * @retval 1 if the rtc interrupt is pending. * @retval 0 if no rtc interrupt is pending. */ -__syscall int rtc_get_pending_int(struct device *dev); +__deprecated __syscall int rtc_get_pending_int(struct device *dev); static inline int _impl_rtc_get_pending_int(struct device *dev) { - struct rtc_driver_api *api; - - api = (struct rtc_driver_api *)dev->driver_api; - return api->get_pending_int(dev); + return counter_get_pending_int(dev); } #ifdef __cplusplus