2015-11-22 10:33:43 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation.
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-11-22 10:33:43 +08:00
|
|
|
*/
|
|
|
|
|
2018-09-15 01:43:44 +08:00
|
|
|
#ifndef ZEPHYR_INCLUDE_AIO_COMPARATOR_H_
|
|
|
|
#define ZEPHYR_INCLUDE_AIO_COMPARATOR_H_
|
2015-11-22 10:33:43 +08:00
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-11-22 10:33:43 +08:00
|
|
|
enum aio_cmp_ref {
|
|
|
|
AIO_CMP_REF_A, /**< Use reference A. */
|
|
|
|
AIO_CMP_REF_B, /**< Use reference B. */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum aio_cmp_polarity {
|
|
|
|
AIO_CMP_POL_RISE, /**< Match on rising edge. */
|
|
|
|
AIO_CMP_POL_FALL, /**< Match on falling edge. */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (*aio_cmp_cb)(void *);
|
|
|
|
|
2017-04-21 23:55:34 +08:00
|
|
|
typedef int (*aio_cmp_api_disable)(struct device *dev, u8_t index);
|
2015-11-22 10:33:43 +08:00
|
|
|
|
2017-04-21 23:55:34 +08:00
|
|
|
typedef int (*aio_cmp_api_configure)(struct device *dev, u8_t index,
|
2015-11-22 10:33:43 +08:00
|
|
|
enum aio_cmp_polarity polarity, enum aio_cmp_ref refsel,
|
|
|
|
aio_cmp_cb cb, void *param);
|
2017-04-21 23:55:34 +08:00
|
|
|
typedef u32_t (*aio_cmp_api_get_pending_int)(struct device *dev);
|
2015-11-22 10:33:43 +08:00
|
|
|
|
|
|
|
struct aio_cmp_driver_api {
|
|
|
|
aio_cmp_api_disable disable;
|
|
|
|
aio_cmp_api_configure configure;
|
2016-10-27 21:31:19 +08:00
|
|
|
aio_cmp_api_get_pending_int get_pending_int;
|
2015-11-22 10:33:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disable a particular comparator.
|
|
|
|
*
|
|
|
|
* This disables a comparator so that it no longer triggers interrupts.
|
|
|
|
*
|
|
|
|
* @param dev Device struct
|
|
|
|
* @param index The index of the comparator to disable
|
|
|
|
*
|
|
|
|
* @return 0 if successful, otherwise failed.
|
|
|
|
*/
|
2017-10-26 02:55:36 +08:00
|
|
|
__syscall int aio_cmp_disable(struct device *dev, u8_t index);
|
|
|
|
|
|
|
|
static inline int _impl_aio_cmp_disable(struct device *dev, u8_t index)
|
2015-11-22 10:33:43 +08:00
|
|
|
{
|
2016-10-22 16:56:02 +08:00
|
|
|
const struct aio_cmp_driver_api *api = dev->driver_api;
|
2015-11-22 10:33:43 +08:00
|
|
|
|
|
|
|
return api->disable(dev, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Configure and enable a particular comparator.
|
|
|
|
*
|
|
|
|
* This performs configuration and enable a comparator, so that it will
|
|
|
|
* generate interrupts when conditions are met.
|
|
|
|
*
|
|
|
|
* @param dev Device struct
|
|
|
|
* @param index The index of the comparator to disable
|
|
|
|
* @param polarity Match polarity (e.g. rising or falling)
|
|
|
|
* @param refsel Reference for trigger
|
|
|
|
* @param cb Function callback (aio_cmp_cb)
|
|
|
|
* @param param Parameters to be passed to callback
|
|
|
|
*
|
|
|
|
* @return 0 if successful, otherwise failed.
|
|
|
|
*/
|
2017-04-21 23:55:34 +08:00
|
|
|
static inline int aio_cmp_configure(struct device *dev, u8_t index,
|
2016-10-21 16:06:33 +08:00
|
|
|
enum aio_cmp_polarity polarity,
|
|
|
|
enum aio_cmp_ref refsel,
|
|
|
|
aio_cmp_cb cb, void *param)
|
2015-11-22 10:33:43 +08:00
|
|
|
{
|
2016-10-22 16:56:02 +08:00
|
|
|
const struct aio_cmp_driver_api *api = dev->driver_api;
|
2015-11-22 10:33:43 +08:00
|
|
|
|
|
|
|
return api->configure(dev, index, polarity, refsel, cb, param);
|
|
|
|
}
|
|
|
|
|
2016-10-27 21:31:19 +08:00
|
|
|
/**
|
|
|
|
* @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 status != 0 if at least one aio_cmp interrupt is pending.
|
|
|
|
* @retval 0 if no aio_cmp interrupt is pending.
|
|
|
|
*/
|
2017-10-26 02:55:36 +08:00
|
|
|
__syscall int aio_cmp_get_pending_int(struct device *dev);
|
|
|
|
|
|
|
|
static inline int _impl_aio_cmp_get_pending_int(struct device *dev)
|
2016-10-27 21:31:19 +08:00
|
|
|
{
|
|
|
|
struct aio_cmp_driver_api *api;
|
|
|
|
|
|
|
|
api = (struct aio_cmp_driver_api *)dev->driver_api;
|
|
|
|
return api->get_pending_int(dev);
|
|
|
|
}
|
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-10-26 02:55:36 +08:00
|
|
|
#include <syscalls/aio_comparator.h>
|
|
|
|
|
2018-09-15 01:43:44 +08:00
|
|
|
#endif /* ZEPHYR_INCLUDE_AIO_COMPARATOR_H_ */
|