Implementation of 1-Wire with added Alarm Search Functionality

Dependents:   Max32630_One_Wire_Interface

Committer:
mfruge
Date:
Tue Aug 13 14:42:37 2019 +0000
Revision:
142:85b71cfd617e
Parent:
139:f0e0a7976846
Added functions to ROMCommands to add Alarm Search functionality

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IanBenzMaxim 75:8b627804927c 1 /******************************************************************//**
IanBenzMaxim 75:8b627804927c 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
IanBenzMaxim 75:8b627804927c 3 *
IanBenzMaxim 75:8b627804927c 4 * Permission is hereby granted, free of charge, to any person obtaining a
IanBenzMaxim 75:8b627804927c 5 * copy of this software and associated documentation files (the "Software"),
IanBenzMaxim 75:8b627804927c 6 * to deal in the Software without restriction, including without limitation
IanBenzMaxim 75:8b627804927c 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
IanBenzMaxim 75:8b627804927c 8 * and/or sell copies of the Software, and to permit persons to whom the
IanBenzMaxim 75:8b627804927c 9 * Software is furnished to do so, subject to the following conditions:
IanBenzMaxim 75:8b627804927c 10 *
IanBenzMaxim 75:8b627804927c 11 * The above copyright notice and this permission notice shall be included
IanBenzMaxim 75:8b627804927c 12 * in all copies or substantial portions of the Software.
IanBenzMaxim 75:8b627804927c 13 *
IanBenzMaxim 75:8b627804927c 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
IanBenzMaxim 75:8b627804927c 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
IanBenzMaxim 75:8b627804927c 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IanBenzMaxim 75:8b627804927c 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
IanBenzMaxim 75:8b627804927c 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
IanBenzMaxim 75:8b627804927c 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
IanBenzMaxim 75:8b627804927c 20 * OTHER DEALINGS IN THE SOFTWARE.
IanBenzMaxim 75:8b627804927c 21 *
IanBenzMaxim 75:8b627804927c 22 * Except as contained in this notice, the name of Maxim Integrated
IanBenzMaxim 75:8b627804927c 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
IanBenzMaxim 75:8b627804927c 24 * Products, Inc. Branding Policy.
IanBenzMaxim 75:8b627804927c 25 *
IanBenzMaxim 75:8b627804927c 26 * The mere transfer of this software does not imply any licenses
IanBenzMaxim 75:8b627804927c 27 * of trade secrets, proprietary technology, copyrights, patents,
IanBenzMaxim 75:8b627804927c 28 * trademarks, maskwork rights, or any other form of intellectual
IanBenzMaxim 75:8b627804927c 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
IanBenzMaxim 75:8b627804927c 30 * ownership rights.
IanBenzMaxim 75:8b627804927c 31 **********************************************************************/
IanBenzMaxim 75:8b627804927c 32
IanBenzMaxim 73:2cecc1372acc 33 #ifndef OneWire_array
IanBenzMaxim 73:2cecc1372acc 34 #define OneWire_array
IanBenzMaxim 33:a4c015046956 35
IanBenzMaxim 73:2cecc1372acc 36 #include <stdint.h>
IanBenzMaxim 73:2cecc1372acc 37 #include <stddef.h>
j3 139:f0e0a7976846 38 #include <iterator>
j3 139:f0e0a7976846 39 #include <algorithm>
IanBenzMaxim 33:a4c015046956 40 #include <cstring>
IanBenzMaxim 33:a4c015046956 41
IanBenzMaxim 73:2cecc1372acc 42 namespace OneWire
IanBenzMaxim 33:a4c015046956 43 {
IanBenzMaxim 74:23be10c32fa3 44 /// Generic array class similar to std::array.
IanBenzMaxim 74:23be10c32fa3 45 template <typename T, size_t N>
IanBenzMaxim 74:23be10c32fa3 46 class array
IanBenzMaxim 73:2cecc1372acc 47 {
IanBenzMaxim 74:23be10c32fa3 48 public:
j3 139:f0e0a7976846 49 typedef T value_type;
j3 139:f0e0a7976846 50 typedef size_t size_type;
j3 139:f0e0a7976846 51 typedef ptrdiff_t difference_type;
j3 139:f0e0a7976846 52 typedef value_type & reference;
j3 139:f0e0a7976846 53 typedef const value_type & const_reference;
j3 139:f0e0a7976846 54 typedef value_type * pointer;
j3 139:f0e0a7976846 55 typedef const value_type * const_pointer;
j3 139:f0e0a7976846 56 typedef pointer iterator;
j3 139:f0e0a7976846 57 typedef const_pointer const_iterator;
j3 139:f0e0a7976846 58 typedef std::reverse_iterator<iterator> reverse_iterator;
j3 139:f0e0a7976846 59 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
j3 139:f0e0a7976846 60
j3 139:f0e0a7976846 61 // Element access
j3 139:f0e0a7976846 62 reference operator[](size_t pos) { return _buffer[pos]; }
j3 139:f0e0a7976846 63 const_reference operator[](size_t pos) const { return _buffer[pos]; }
j3 139:f0e0a7976846 64 reference front() { return const_cast<reference>(static_cast<const array<T, N> &>(*this).front()); }
j3 139:f0e0a7976846 65 const_reference front() const { return _buffer[0]; }
j3 139:f0e0a7976846 66 reference back() { return const_cast<reference>(static_cast<const array<T, N> &>(*this).back()); }
j3 139:f0e0a7976846 67 const_reference back() const { return _buffer[N - 1]; }
j3 139:f0e0a7976846 68 T * data() { return const_cast<T *>(static_cast<const array<T, N> &>(*this).data()); }
j3 139:f0e0a7976846 69 const T * data() const { return _buffer; }
j3 139:f0e0a7976846 70
j3 139:f0e0a7976846 71 // Iterators
j3 139:f0e0a7976846 72 iterator begin() { return const_cast<iterator>(static_cast<const array<T, N> &>(*this).begin()); }
j3 139:f0e0a7976846 73 const_iterator begin() const { return cbegin(); }
j3 139:f0e0a7976846 74 const_iterator cbegin() const { return &front(); }
j3 139:f0e0a7976846 75 iterator end() { return const_cast<iterator>(static_cast<const array<T, N> &>(*this).end()); }
j3 139:f0e0a7976846 76 const_iterator end() const { return cend(); }
j3 139:f0e0a7976846 77 const_iterator cend() const { return &_buffer[N]; }
j3 139:f0e0a7976846 78 reverse_iterator rbegin() { return reverse_iterator(&back()); }
j3 139:f0e0a7976846 79 const_reverse_iterator rbegin() const { return crbegin(); }
j3 139:f0e0a7976846 80 const_reverse_iterator crbegin() const { return const_reverse_iterator(&back()); }
j3 139:f0e0a7976846 81 reverse_iterator rend() { return reverse_iterator(--begin()); }
j3 139:f0e0a7976846 82 const_reverse_iterator rend() const { return crend(); }
j3 139:f0e0a7976846 83 const_reverse_iterator crend() const { return const_reverse_iterator(--begin()); }
j3 139:f0e0a7976846 84
j3 139:f0e0a7976846 85 // Capacity
j3 139:f0e0a7976846 86 static bool empty() { return size() == 0; }
j3 139:f0e0a7976846 87 static size_type size() { return N; }
j3 139:f0e0a7976846 88 static size_type max_size() { return size(); }
j3 139:f0e0a7976846 89 static const size_type csize = N; ///< Alternative to size() when a constant expression is required.
j3 139:f0e0a7976846 90
j3 139:f0e0a7976846 91 // Operations
j3 139:f0e0a7976846 92 void fill(const T & value) { std::fill(begin(), end(), value); }
j3 139:f0e0a7976846 93
j3 139:f0e0a7976846 94 bool operator==(const array<T, N> & rhs) const { return (std::memcmp(this->_buffer, rhs._buffer, N * sizeof(T)) == 0); }
j3 139:f0e0a7976846 95 bool operator!=(const array<T, N> & rhs) const { return !operator==(rhs); }
j3 139:f0e0a7976846 96
j3 139:f0e0a7976846 97 T _buffer[N];
IanBenzMaxim 74:23be10c32fa3 98 };
IanBenzMaxim 73:2cecc1372acc 99 }
IanBenzMaxim 33:a4c015046956 100
IanBenzMaxim 49:36954b62f503 101 #endif