diff options
Diffstat (limited to 'cpukit/include/dev/i2c/i2c.h')
-rw-r--r-- | cpukit/include/dev/i2c/i2c.h | 79 |
1 files changed, 67 insertions, 12 deletions
diff --git a/cpukit/include/dev/i2c/i2c.h b/cpukit/include/dev/i2c/i2c.h index ac2c369785..82cc11130c 100644 --- a/cpukit/include/dev/i2c/i2c.h +++ b/cpukit/include/dev/i2c/i2c.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -7,17 +9,28 @@ */ /* - * Copyright (c) 2014, 2017 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * <rtems@embedded-brains.de> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. + * Copyright (C) 2014, 2017 embedded brains GmbH & Co. KG + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #ifndef _DEV_I2C_I2C_H @@ -243,6 +256,16 @@ int i2c_bus_register( ); /** + * @brief Try to obtain the bus. + * + * @param[in] bus The bus control. + * + * @retval 0 Successful operation. + * @retval EBUSY if mutex is already locked. + */ +int i2c_bus_try_obtain(i2c_bus *bus); + +/** * @brief Obtains the bus. * * @param[in] bus The bus control. @@ -259,7 +282,8 @@ void i2c_bus_release(i2c_bus *bus); /** * @brief Transfers I2C messages. * - * The bus is obtained before the transfer and released afterwards. + * The bus is obtained before the transfer and released afterwards. This is the + * same like calling @ref i2c_bus_do_transfer with flags set to 0. * * @param[in] bus The bus control. * @param[in] msgs The messages to transfer. @@ -271,6 +295,37 @@ void i2c_bus_release(i2c_bus *bus); */ int i2c_bus_transfer(i2c_bus *bus, i2c_msg *msgs, uint32_t msg_count); +/** + * @brief Transfers I2C messages with optional flags. + * + * The bus is obtained before the transfer and released afterwards. If the flag + * I2C_BUS_NOBLOCK is set and the bus is already obtained, nothing will be + * transfered and the function returns with an -EAGAIN. + * + * @param[in] bus The bus control. + * @param[in] msgs The messages to transfer. + * @param[in] msg_count The count of messages to transfer. It must be + * positive. + * @param[in] flags Options for the whole transfer. + * + * @retval 0 Successful operation. + * @retval -EAGAIN if @ref I2C_BUS_NOBLOCK is set and the bus is already + * obtained. + * @retval negative Negative error number in case of an error. + */ +int i2c_bus_do_transfer( + i2c_bus *bus, + i2c_msg *msgs, + uint32_t msg_count, + uint32_t flags +); + +/** + * @brief I2C bus transfer flag to indicate that the task should not block if + * the bus is busy on a new transfer. + */ +#define I2C_BUS_NOBLOCK (1u << 0) + /** @} */ /** |