API: Add public counter API
Add the public API for counter devices and the drivers infrastructure. Origin: Original Change-Id: If100fbc9b3d119ce2be6c131bd64dbeb4fe346f2 Signed-off-by: Baohong Liu <baohong.liu@intel.com>
This commit is contained in:
parent
33ee2052b1
commit
ea5b4e4943
4 changed files with 167 additions and 0 deletions
|
@ -71,4 +71,6 @@ source "drivers/flash/Kconfig"
|
||||||
|
|
||||||
source "drivers/sensor/Kconfig"
|
source "drivers/sensor/Kconfig"
|
||||||
|
|
||||||
|
source "drivers/counter/Kconfig"
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
|
@ -11,6 +11,7 @@ obj-$(CONFIG_BLUETOOTH) += bluetooth/
|
||||||
obj-$(CONFIG_SHARED_IRQ) += shared_irq/
|
obj-$(CONFIG_SHARED_IRQ) += shared_irq/
|
||||||
obj-$(CONFIG_SPI) += spi/
|
obj-$(CONFIG_SPI) += spi/
|
||||||
obj-$(CONFIG_FLASH) += flash/
|
obj-$(CONFIG_FLASH) += flash/
|
||||||
|
obj-$(CONFIG_COUNTER) += counter/
|
||||||
obj-$(CONFIG_GPIO) += gpio/
|
obj-$(CONFIG_GPIO) += gpio/
|
||||||
obj-$(CONFIG_I2C) += i2c/
|
obj-$(CONFIG_I2C) += i2c/
|
||||||
obj-$(CONFIG_PWM) += pwm/
|
obj-$(CONFIG_PWM) += pwm/
|
||||||
|
|
23
drivers/counter/Kconfig
Normal file
23
drivers/counter/Kconfig
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Kconfig - counter configuration options
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright (c) 2016 Intel Corporation
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
menuconfig COUNTER
|
||||||
|
bool "Counter Drivers"
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
Enable support for counter and timer.
|
141
include/counter.h
Normal file
141
include/counter.h
Normal file
|
@ -0,0 +1,141 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Intel Corporation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Public API for counter and timer drivers
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __COUNTER_H__
|
||||||
|
#define __COUNTER_H__
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief COUNTER Interface
|
||||||
|
* @defgroup counter_interface COUNTER Interface
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <device.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef void (*counter_callback_t)(struct device *dev, void *user_data);
|
||||||
|
|
||||||
|
typedef int (*counter_api_start)(struct device *dev);
|
||||||
|
typedef int (*counter_api_stop)(struct device *dev);
|
||||||
|
typedef uint32_t (*counter_api_read)(void);
|
||||||
|
typedef int (*counter_api_set_alarm)(struct device *dev,
|
||||||
|
counter_callback_t callback,
|
||||||
|
uint32_t count, void *user_data);
|
||||||
|
|
||||||
|
struct counter_driver_api {
|
||||||
|
counter_api_start start;
|
||||||
|
counter_api_stop stop;
|
||||||
|
counter_api_read read;
|
||||||
|
counter_api_set_alarm set_alarm;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Start counter device in free running mode.
|
||||||
|
*
|
||||||
|
* Start the counter device. If the device is a 'countup' counter, the
|
||||||
|
* counter initial value is set to zero. If it is a 'countdown' counter,
|
||||||
|
* the initial value is set to the maximum value supported by the device.
|
||||||
|
*
|
||||||
|
* @param dev Pointer to the device structure for the driver instance.
|
||||||
|
*
|
||||||
|
* @retval DEV_OK If successful.
|
||||||
|
* @retval DEV_* Code otherwise.
|
||||||
|
*/
|
||||||
|
static inline int counter_start(struct device *dev)
|
||||||
|
{
|
||||||
|
struct counter_driver_api *api;
|
||||||
|
|
||||||
|
api = (struct counter_driver_api *)dev->driver_api;
|
||||||
|
|
||||||
|
return api->start(dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Stop counter device.
|
||||||
|
* @param dev Pointer to the device structure for the driver instance.
|
||||||
|
*
|
||||||
|
* @retval DEV_OK If successful.
|
||||||
|
* @retval DEV_NO_SUPPORT if the device doesn't support stopping the
|
||||||
|
* counter.
|
||||||
|
*/
|
||||||
|
static inline int counter_stop(struct device *dev)
|
||||||
|
{
|
||||||
|
struct counter_driver_api *api;
|
||||||
|
|
||||||
|
api = (struct counter_driver_api *)dev->driver_api;
|
||||||
|
|
||||||
|
return api->stop(dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read current counter value.
|
||||||
|
* @param dev Pointer to the device structure for the driver instance.
|
||||||
|
*
|
||||||
|
* @return 32-bit value
|
||||||
|
*/
|
||||||
|
static inline uint32_t counter_read(struct device *dev)
|
||||||
|
{
|
||||||
|
struct counter_driver_api *api;
|
||||||
|
|
||||||
|
api = (struct counter_driver_api *)dev->driver_api;
|
||||||
|
|
||||||
|
return api->read();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set an alarm.
|
||||||
|
* @param dev Pointer to the device structure for the driver instance.
|
||||||
|
* @param callback Pointer to the callback function. if this is NULL,
|
||||||
|
* this function unsets the alarm.
|
||||||
|
* @param count Number of counter ticks.
|
||||||
|
* @param user_data Pointer to user data.
|
||||||
|
*
|
||||||
|
* @retval DEV_OK If successful.
|
||||||
|
* @retval DEV_INVALID_OP if the counter was not started yet.
|
||||||
|
* @retval DEV_NO_SUPPORT if the device doesn't support interrupt (e.g. free
|
||||||
|
* running counters).
|
||||||
|
* @retval DEV_* Code otherwise.
|
||||||
|
*/
|
||||||
|
static inline int counter_set_alarm(struct device *dev,
|
||||||
|
counter_callback_t callback,
|
||||||
|
uint32_t count, void *user_data)
|
||||||
|
{
|
||||||
|
struct counter_driver_api *api;
|
||||||
|
|
||||||
|
api = (struct counter_driver_api *)dev->driver_api;
|
||||||
|
|
||||||
|
return api->set_alarm(dev, callback, count, user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* __COUNTER_H__ */
|
Loading…
Add table
Add a link
Reference in a new issue