zephyr/include/rtc.h
Kumar Gala cc334c7273 Convert remaining code to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.  This handles the remaining includes and kernel, plus
touching up various points that we skipped because of include
dependancies.  We also convert the PRI printf formatters in the arch
code over to normal formatters.

Jira: ZEP-2051

Change-Id: Iecbb12601a3ee4ea936fd7ddea37788a645b08b0
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-21 11:38:23 -05:00

145 lines
3.1 KiB
C

/*
* Copyright (c) 2015 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _RTC_H_
#define _RTC_H_
#include <zephyr/types.h>
#include <device.h>
#include <misc/util.h>
#ifdef __cplusplus
extern "C" {
#endif
enum clk_rtc_div {
RTC_CLK_DIV_1,
RTC_CLK_DIV_2,
RTC_CLK_DIV_4,
RTC_CLK_DIV_8,
RTC_CLK_DIV_16,
RTC_CLK_DIV_32,
RTC_CLK_DIV_64,
RTC_CLK_DIV_128,
RTC_CLK_DIV_256,
RTC_CLK_DIV_512,
RTC_CLK_DIV_1024,
RTC_CLK_DIV_2048,
RTC_CLK_DIV_4096,
RTC_CLK_DIV_8192,
RTC_CLK_DIV_16384,
RTC_CLK_DIV_32768
};
#define RTC_DIVIDER RTC_CLK_DIV_1
/** Number of RTC ticks in a second */
#define RTC_ALARM_SECOND (32768 / (1UL << RTC_DIVIDER))
/** Number of RTC ticks in a minute */
#define RTC_ALARM_MINUTE (RTC_ALARM_SECOND * 60)
/** Number of RTC ticks in an hour */
#define RTC_ALARM_HOUR (RTC_ALARM_MINUTE * 60)
/** Number of RTC ticks in a day */
#define RTC_ALARM_DAY (RTC_ALARM_HOUR * 24)
struct rtc_config {
u32_t init_val;
/*!< enable/disable alarm */
u8_t alarm_enable;
/*!< initial configuration value for the 32bit RTC alarm value */
u32_t alarm_val;
/*!< Pointer to function to call when alarm value
* matches current RTC value */
void (*cb_fn)(struct device *dev);
};
typedef void (*rtc_api_enable)(struct device *dev);
typedef void (*rtc_api_disable)(struct device *dev);
typedef int (*rtc_api_set_config)(struct device *dev,
struct rtc_config *config);
typedef int (*rtc_api_set_alarm)(struct device *dev,
const u32_t alarm_val);
typedef u32_t (*rtc_api_read)(struct device *dev);
typedef u32_t (*rtc_api_get_pending_int)(struct device *dev);
struct rtc_driver_api {
rtc_api_enable enable;
rtc_api_disable disable;
rtc_api_read read;
rtc_api_set_config set_config;
rtc_api_set_alarm set_alarm;
rtc_api_get_pending_int get_pending_int;
};
static inline u32_t rtc_read(struct device *dev)
{
const struct rtc_driver_api *api = dev->driver_api;
return api->read(dev);
}
static inline void rtc_enable(struct device *dev)
{
const struct rtc_driver_api *api = dev->driver_api;
api->enable(dev);
}
static inline void rtc_disable(struct device *dev)
{
const struct rtc_driver_api *api = dev->driver_api;
api->disable(dev);
}
static inline int rtc_set_config(struct device *dev,
struct rtc_config *cfg)
{
const struct rtc_driver_api *api = dev->driver_api;
return api->set_config(dev, cfg);
}
static inline int 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);
}
/**
* @brief Function to get pending interrupts
*
* The purpose of this function is to return the interrupt
* status register for the device.
* This is especially useful when waking up from
* low power states to check the wake up source.
*
* @param dev Pointer to the device structure for the driver instance.
*
* @retval 1 if the rtc interrupt is pending.
* @retval 0 if no rtc interrupt is pending.
*/
static inline int 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);
}
#ifdef __cplusplus
}
#endif
#endif