Skip to content

Commit

Permalink
drivers: counter: rtc: Deprecating legacy counter and rtc API
Browse files Browse the repository at this point in the history
Deprecating counter legacy API and renaming new counter_set_alarm
to coutner_set_ch_alarm. Deprecating rtc API and modifying rtc
API to call new counter API (compatibility layer).

Signed-off-by: Krzysztof Chruscinski <[email protected]>
  • Loading branch information
nordic-krch committed Dec 4, 2018
1 parent 063c782 commit 215f872
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 30 deletions.
40 changes: 36 additions & 4 deletions include/counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
};


Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
/**
* @}
*/
Expand Down
65 changes: 39 additions & 26 deletions include/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <zephyr/types.h>
#include <device.h>
#include <misc/util.h>
#include <counter.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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));
}

/**
Expand All @@ -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
Expand Down

0 comments on commit 215f872

Please sign in to comment.