diff --git a/arch/arm/src/stm32/stm32_1wire.c b/arch/arm/src/stm32/stm32_1wire.c index 06f970c08ef..3c34fbae92e 100644 --- a/arch/arm/src/stm32/stm32_1wire.c +++ b/arch/arm/src/stm32/stm32_1wire.c @@ -56,7 +56,7 @@ #include #include #include -#include +#include #include diff --git a/arch/arm/src/stm32l4/stm32l4_1wire.c b/arch/arm/src/stm32l4/stm32l4_1wire.c index af521282d12..14938c2a5c8 100644 --- a/arch/arm/src/stm32l4/stm32l4_1wire.c +++ b/arch/arm/src/stm32l4/stm32l4_1wire.c @@ -58,7 +58,7 @@ #include #include #include -#include +#include #include diff --git a/drivers/1wire/1wire.c b/drivers/1wire/1wire.c index eb3cad28b22..b29d5df66ca 100644 --- a/drivers/1wire/1wire.c +++ b/drivers/1wire/1wire.c @@ -44,8 +44,8 @@ #include #include -#include -#include +#include +#include #include "1wire_internal.h" @@ -729,7 +729,7 @@ int onewire_removeslave(FAR struct onewire_master_s *master, ****************************************************************************/ FAR struct onewire_master_s * - onewire_initialize(FAR struct onewire_dev_s *dev, int maxslaves) +onewire_initialize(FAR struct onewire_dev_s *dev, int maxslaves) { FAR struct onewire_master_s *master; diff --git a/drivers/1wire/1wire_crc.c b/drivers/1wire/1wire_crc.c index 71a5766ae41..b16a738ef74 100644 --- a/drivers/1wire/1wire_crc.c +++ b/drivers/1wire/1wire_crc.c @@ -41,6 +41,7 @@ #include #include +#include #include "1wire_internal.h" /**************************************************************************** diff --git a/drivers/1wire/1wire_internal.h b/drivers/1wire/1wire_internal.h index 63668e52214..25b07497d90 100644 --- a/drivers/1wire/1wire_internal.h +++ b/drivers/1wire/1wire_internal.h @@ -81,14 +81,9 @@ struct onewire_slave_s * Public Function Prototypes ****************************************************************************/ -/* CRC helpers from 1wire_crc.c */ +/* Aditional CRC helpers from 1wire_crc.c */ -uint8_t onewire_crc8(FAR const uint8_t *input, uint8_t len); -uint16_t onewire_crc16(FAR const uint8_t *input, uint16_t len, - uint16_t initial_crc); bool onewire_valid_rom(uint64_t rom); -bool onewire_check_crc16(FAR const uint8_t *input, uint16_t len, - FAR const uint8_t *inverted_crc); /* Rest are from 1wire.c */ @@ -146,7 +141,9 @@ int onewire_triplet(FAR struct onewire_master_s *master, * * Description: * Search all devices from a 1-wire network. This is the 1-wire search - * algorithm from Maxim Application Note 187. + * algorithm from Maxim Application Note 187. Note! This is an atomic + * operation. The callback 'cb_search' can't execute any function that will + * lock this bus, because of the locked state as long the search is active. * * Input Parameters: * master - Pointer to the allocated 1-wire interface @@ -166,34 +163,6 @@ int onewire_search(FAR struct onewire_master_s *master, CODE void (*cb_search)(int family, uint64_t romcode, FAR void *arg), - FAR void *arg); - -/**************************************************************************** - * Name: onewire_initialize - * - * Description: - * Return 1-wire bus master from 1-wire lower half device. - * - * Input Parameters: - * dev - Pointer to the allocated 1-wire lower half - * maxslaves - Maximum number of 1-wire slave devices - * - ****************************************************************************/ - -FAR struct onewire_master_s * - onewire_initialize(FAR struct onewire_dev_s *dev, int maxslaves); - -/**************************************************************************** - * Name: onewire_uninitialize - * - * Description: - * Release 1-wire bus master. - * - * Input Parameters: - * master - Pointer to the allocated 1-wire master - * - ****************************************************************************/ - -int onewire_uninitialize(FAR struct onewire_master_s *master); + FAR void *arg); #endif /* __DRIVERS_1WIRE_1WIRE_INTERNAL_H */ diff --git a/drivers/1wire/ds28e17.c b/drivers/1wire/ds28e17.c index 8e92ad37878..0f3bae8a288 100644 --- a/drivers/1wire/ds28e17.c +++ b/drivers/1wire/ds28e17.c @@ -45,7 +45,9 @@ #include #include -#include +#include +#include +#include #include diff --git a/include/nuttx/drivers/1wire.h b/include/nuttx/1wire/1wire.h similarity index 97% rename from include/nuttx/drivers/1wire.h rename to include/nuttx/1wire/1wire.h index bdf97e28819..d1bf69057ac 100644 --- a/include/nuttx/drivers/1wire.h +++ b/include/nuttx/1wire/1wire.h @@ -1,5 +1,5 @@ /**************************************************************************** - * include/nuttx/drivers/1wire.h + * include/nuttx/1wire/1wire.h * * Copyright (C) 2016 Aleksandr Vyhovanec. All rights reserved. * Author: Aleksandr Vyhovanec @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __INCLUDE_NUTTX_DRIVERS_1WIRE_H -#define __INCLUDE_NUTTX_DRIVERS_1WIRE_H +#ifndef __INCLUDE_NUTTX_1WIRE_1WIRE_H +#define __INCLUDE_NUTTX_1WIRE_1WIRE_H /**************************************************************************** * Included Files @@ -43,6 +43,7 @@ #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -217,4 +218,4 @@ struct onewire_dev_s * Public Functions Definitions ****************************************************************************/ -#endif /* __INCLUDE_NUTTX_DRIVERS_1WIRE_H */ +#endif /* __INCLUDE_NUTTX_1WIRE_1WIRE_H */ diff --git a/include/nuttx/1wire/1wire_crc.h b/include/nuttx/1wire/1wire_crc.h new file mode 100644 index 00000000000..481a915c338 --- /dev/null +++ b/include/nuttx/1wire/1wire_crc.h @@ -0,0 +1,102 @@ +/**************************************************************************** + * include/nuttx/1wire/1wire_crc.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_1WIRE_1WIRE_CRC_H +#define __INCLUDE_NUTTX_1WIRE_1WIRE_CRC_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: onewire_crc8 + * + * Description: + * Compute a Dallas Semiconductor 8 bit CRC. + * + * Input Parameters: + * input - Input buffer for crc calculation + * len - Buffer len + * + * Returned Value: + * Calculated crc8 + * + ****************************************************************************/ + +uint8_t onewire_crc8(FAR const uint8_t *input, uint8_t len); + +/**************************************************************************** + * Name: onewire_crc16 + * + * Description: + * Compute a Dallas Semiconductor 16 bit CRC. This is used to check + * the integrity of received data from many 1-wire devices. + * + * Note: the CRC-16 computed here is not what you'll get from the 1-wire + * network, because: + * - The CRC-16 is transmitted bitwise inverted. + * - The binary representation of the return value may have a different + * byte order than the two bytes you get from 1-wire due to endian-ness. + * + * Input Parameters: + * input - Input buffer for crc calculation + * len - Buffer len + * initial_crc - Initial crc for calculation + * + * Returned Value: + * Calculated crc16 + * + ****************************************************************************/ + +uint16_t onewire_crc16(FAR const uint8_t *input, uint16_t len, + uint16_t initial_crc); + +/**************************************************************************** + * Name: onewire_check_crc16 + * + * Description: + * Check CRC-16 of received input + * + * Input Parameters: + * input - Array of bytes to checksum + * len - Length of input + * inverted_crc - The two CRC16 bytes in the received data + * + * Returned Value: + * true if CRC-16 matches + * + ****************************************************************************/ + +bool onewire_check_crc16(FAR const uint8_t *input, uint16_t len, + FAR const uint8_t *inverted_crc); + +#endif /* __INCLUDE_NUTTX_1WIRE_1WIRE_CRC_H */ diff --git a/include/nuttx/1wire/ds28e17.h b/include/nuttx/1wire/ds28e17.h index 10a5a321442..25c38251bf1 100644 --- a/include/nuttx/1wire/ds28e17.h +++ b/include/nuttx/1wire/ds28e17.h @@ -43,7 +43,7 @@ #include #include -#include +#include /**************************************************************************** * Pre-processor Definitions