1-wire driver based on U[S]ART in single-wire, half-duplex mode.
This commit is contained in:
parent
d58e4acf17
commit
9a2002a302
1333
arch/arm/src/stm32/stm32_1wire.c
Normal file
1333
arch/arm/src/stm32/stm32_1wire.c
Normal file
File diff suppressed because it is too large
Load Diff
113
arch/arm/src/stm32/stm32_1wire.h
Normal file
113
arch/arm/src/stm32/stm32_1wire.h
Normal file
@ -0,0 +1,113 @@
|
||||
/************************************************************************************
|
||||
* arch/arm/src/stm32/stm32_1wire.h
|
||||
*
|
||||
* Copyright (C) 2016 Aleksandr Vyhovanec. All rights reserved.
|
||||
* Author: Aleksandr Vyhovanec <www.desh@gmail.com>
|
||||
*
|
||||
* 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.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* 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 __ARCH_ARM_SRC_STM32_STM32_1WIRE_H
|
||||
#define __ARCH_ARM_SRC_STM32_STM32_1WIRE_H
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include "chip.h"
|
||||
|
||||
#if defined(CONFIG_STM32_STM32L15XX)
|
||||
# include "chip/stm32l15xxx_uart.h"
|
||||
#elif defined(CONFIG_STM32_STM32F10XX)
|
||||
# include "chip/stm32f10xxx_uart.h"
|
||||
#elif defined(CONFIG_STM32_STM32F20XX)
|
||||
# include "chip/stm32f20xxx_uart.h"
|
||||
#elif defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F37XX)
|
||||
# include "chip/stm32f30xxx_uart.h"
|
||||
#elif defined(CONFIG_STM32_STM32F40XX)
|
||||
# include "chip/stm32f40xxx_uart.h"
|
||||
#else
|
||||
# error "Unsupported STM32 UART"
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
|
||||
/* Check 1-Wire and U(S)ART conflicting */
|
||||
|
||||
#if defined(CONFIG_STM32_1WIRE1) && defined(CONFIG_STM32_USART1)
|
||||
# undef CONFIG_STM32_1WIRE1
|
||||
#endif
|
||||
#if defined(CONFIG_STM32_1WIRE2) && defined(CONFIG_STM32_USART2)
|
||||
# undef CONFIG_STM32_1WIRE2
|
||||
#endif
|
||||
#if defined(CONFIG_STM32_1WIRE3) && defined(CONFIG_STM32_USART3)
|
||||
# undef CONFIG_STM32_1WIRE3
|
||||
#endif
|
||||
#if defined(CONFIG_STM32_1WIRE4) && defined(CONFIG_STM32_UART4)
|
||||
# undef CONFIG_STM32_1WIRE4
|
||||
#endif
|
||||
#if defined(CONFIG_STM32_1WIRE5) && defined(CONFIG_STM32_UART5)
|
||||
# undef CONFIG_STM32_1WIRE5
|
||||
#endif
|
||||
#if defined(CONFIG_STM32_1WIRE6) && defined(CONFIG_STM32_USART6)
|
||||
# undef CONFIG_STM32_1WIRE6
|
||||
#endif
|
||||
#if defined(CONFIG_STM32_1WIRE7) && defined(CONFIG_STM32_UART7)
|
||||
# undef CONFIG_STM32_1WIRE7
|
||||
#endif
|
||||
#if defined(CONFIG_STM32_1WIRE8) && defined(CONFIG_STM32_UART8)
|
||||
# undef CONFIG_STM32_1WIRE8
|
||||
#endif
|
||||
|
||||
/* Is there a 1-Wire enabled? */
|
||||
|
||||
#if defined(CONFIG_STM32_1WIRE1) || defined(CONFIG_STM32_1WIRE2) || \
|
||||
defined(CONFIG_STM32_1WIRE3) || defined(CONFIG_STM32_1WIRE4) || \
|
||||
defined(CONFIG_STM32_1WIRE5) || defined(CONFIG_STM32_1WIRE6) || \
|
||||
defined(CONFIG_STM32_1WIRE7) || defined(CONFIG_STM32_1WIRE8)
|
||||
# define HAVE_1WIRE 1
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* Public Types
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Public Data
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
|
||||
#endif /* __ARCH_ARM_SRC_STM32_STM32_1WIRE_H */
|
215
include/nuttx/1wire.h
Normal file
215
include/nuttx/1wire.h
Normal file
@ -0,0 +1,215 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/1wire.h
|
||||
*
|
||||
* Copyright (C) 2016 Aleksandr Vyhovanec. All rights reserved.
|
||||
* Author: Aleksandr Vyhovanec <www.desh@gmail.com>
|
||||
*
|
||||
* 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.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* 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 __INCLUDE_NUTTX_1WIRE_H
|
||||
#define __INCLUDE_NUTTX_1WIRE_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ONEWIRE_RESET
|
||||
*
|
||||
* Description:
|
||||
* Reset pulse and presence detect. Each write operational will be an 'atomic'
|
||||
* operation in the sense that any other 1-Wire actions will be serialized
|
||||
* and pend until this write completes.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
*
|
||||
* Returned Value:
|
||||
* 0: success, <0: A negated errno
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define ONEWIRE_RESET(d) ((d)->ops->reset(d))
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ONEWIRE_WRITE
|
||||
*
|
||||
* Description:
|
||||
* Send a block of data on 1-Wire. Each write operational will be an 'atomic'
|
||||
* operation in the sense that any other 1-Wire actions will be serialized
|
||||
* and pend until this write completes.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* buffer - A pointer to the read-only buffer of data to be written to device
|
||||
* buflen - The number of bytes to send from the buffer
|
||||
*
|
||||
* Returned Value:
|
||||
* 0: success, <0: A negated errno
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define ONEWIRE_WRITE(d,b,l) ((d)->ops->write(d,b,l))
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ONEWIRE_READ
|
||||
*
|
||||
* Description:
|
||||
* Receive a block of data from 1-Wire. Each read operational will be an 'atomic'
|
||||
* operation in the sense that any other 1-Wire actions will be serialized
|
||||
* and pend until this read completes.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* buffer - A pointer to a buffer of data to receive the data from the device
|
||||
* buflen - The requested number of bytes to be read
|
||||
*
|
||||
* Returned Value:
|
||||
* 0: success, <0: A negated errno
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define ONEWIRE_READ(d,b,l) ((d)->ops->read(d,b,l))
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ONEWIRE_EXCHANGE
|
||||
*
|
||||
* Description:
|
||||
* Reset pulse and presence detect, send a block of data and receive a block
|
||||
* of data from 1-Wir. Each write operational will be an 'atomic'
|
||||
* operation in the sense that any other 1-Wire actions will be serialized
|
||||
* and pend until this write completes.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* reset - Reset pulse and presence detect
|
||||
* txbuffer - A pointer to the read-only buffer of data to be written to device
|
||||
* txbuflen - The number of bytes to send from the buffer
|
||||
* rxbuffer - A pointer to a buffer of data to receive the data from the device
|
||||
* rxbuflen - The requested number of bytes to be read
|
||||
*
|
||||
* Returned Value:
|
||||
* 0: success, <0: A negated errno
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#define ONEWIRE_EXCHANGE(d,r,tx,tl,rx,rl) ((d)->ops->exchange(d,r,tx,tl,rx,rl))
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* The 1-Wire vtable */
|
||||
|
||||
struct onewire_dev_s;
|
||||
struct onewire_ops_s
|
||||
{
|
||||
int (*reset)(FAR struct onewire_dev_s *dev);
|
||||
int (*write)(FAR struct onewire_dev_s *dev, FAR const uint8_t *buffer,
|
||||
int buflen);
|
||||
int (*read)(FAR struct onewire_dev_s *dev, FAR uint8_t *buffer,
|
||||
int buflen);
|
||||
int (*exchange)(FAR struct onewire_dev_s *dev, bool reset,
|
||||
FAR const uint8_t *txbuffer, int txbuflen,
|
||||
FAR uint8_t *rxbuffer, int rxbuflen);
|
||||
};
|
||||
|
||||
/* 1-Wire private data. This structure only defines the initial fields of the
|
||||
* structure visible to the 1-Wire client. The specific implementation may
|
||||
* add additional, device specific fields after the vtable.
|
||||
*/
|
||||
|
||||
struct onewire_dev_s
|
||||
{
|
||||
const struct onewire_ops_s *ops; /* 1-Wire vtable */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_1wireinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the selected 1-Wire port. And return a unique instance of struct
|
||||
* struct onewire_dev_s. This function may be called to obtain multiple
|
||||
* instances of the interface, each of which may be set up with a
|
||||
* different frequency and slave address.
|
||||
*
|
||||
* Input Parameter:
|
||||
* Port number (for hardware that has multiple 1-Wire interfaces)
|
||||
*
|
||||
* Returned Value:
|
||||
* Valid 1-Wire device structure reference on succcess; a NULL on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct onewire_dev_s *up_1wireinitialize(int port);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_1wireuninitialize
|
||||
*
|
||||
* Description:
|
||||
* De-initialize the selected 1-Wire port, and power down the device.
|
||||
*
|
||||
* Input Parameter:
|
||||
* Device structure as returned by the up_1wireinitialize()
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success, ERROR when internal reference count mismatch or dev
|
||||
* points to invalid hardware device.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_1wireuninitialize(FAR struct onewire_dev_s *dev);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_1WIRE_H */
|
Loading…
Reference in New Issue
Block a user