Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
Masters/DS2480B/DS2480B.h@73:2cecc1372acc, 2016-05-12 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Thu May 12 14:38:16 2016 -0500
- Revision:
- 73:2cecc1372acc
- Parent:
- OneWire_Masters/DS2480B/ds2480b.h@72:6892702709ee
- Child:
- 74:23be10c32fa3
Added namespaces. Renamed files and directories for consistency. Use <stdint.h> instead of <cstdint> since it is not supported by C++98.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 3:644fc630f958 | 1 | /******************************************************************//** |
j3 | 3:644fc630f958 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 3:644fc630f958 | 3 | * |
j3 | 3:644fc630f958 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 3:644fc630f958 | 5 | * copy of this software and associated documentation files (the "Software"), |
j3 | 3:644fc630f958 | 6 | * to deal in the Software without restriction, including without limitation |
j3 | 3:644fc630f958 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 3:644fc630f958 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 3:644fc630f958 | 9 | * Software is furnished to do so, subject to the following conditions: |
j3 | 3:644fc630f958 | 10 | * |
j3 | 3:644fc630f958 | 11 | * The above copyright notice and this permission notice shall be included |
j3 | 3:644fc630f958 | 12 | * in all copies or substantial portions of the Software. |
j3 | 3:644fc630f958 | 13 | * |
j3 | 3:644fc630f958 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 3:644fc630f958 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 3:644fc630f958 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 3:644fc630f958 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 3:644fc630f958 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 3:644fc630f958 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 3:644fc630f958 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 3:644fc630f958 | 21 | * |
j3 | 3:644fc630f958 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 3:644fc630f958 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 3:644fc630f958 | 24 | * Products, Inc. Branding Policy. |
j3 | 3:644fc630f958 | 25 | * |
j3 | 3:644fc630f958 | 26 | * The mere transfer of this software does not imply any licenses |
j3 | 3:644fc630f958 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 3:644fc630f958 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 3:644fc630f958 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 3:644fc630f958 | 30 | * ownership rights. |
j3 | 3:644fc630f958 | 31 | **********************************************************************/ |
j3 | 3:644fc630f958 | 32 | |
IanBenzMaxim | 73:2cecc1372acc | 33 | #ifndef OneWire_Masters_DS2480B |
IanBenzMaxim | 73:2cecc1372acc | 34 | #define OneWire_Masters_DS2480B |
j3 | 3:644fc630f958 | 35 | |
IanBenzMaxim | 73:2cecc1372acc | 36 | #include "PinNames.h" |
IanBenzMaxim | 73:2cecc1372acc | 37 | #include "Masters/OneWireMaster.h" |
j3 | 3:644fc630f958 | 38 | |
IanBenzMaxim | 73:2cecc1372acc | 39 | namespace mbed { class Serial; } |
j3 | 3:644fc630f958 | 40 | |
IanBenzMaxim | 73:2cecc1372acc | 41 | namespace OneWire |
j3 | 3:644fc630f958 | 42 | { |
IanBenzMaxim | 73:2cecc1372acc | 43 | namespace Masters |
j3 | 63:422be898443a | 44 | { |
IanBenzMaxim | 73:2cecc1372acc | 45 | class DS2480B : public OneWireMaster |
IanBenzMaxim | 73:2cecc1372acc | 46 | { |
IanBenzMaxim | 73:2cecc1372acc | 47 | public: |
IanBenzMaxim | 73:2cecc1372acc | 48 | |
IanBenzMaxim | 73:2cecc1372acc | 49 | enum DS2480B_BPS |
IanBenzMaxim | 73:2cecc1372acc | 50 | { |
IanBenzMaxim | 73:2cecc1372acc | 51 | BPS_9600 = 0, |
IanBenzMaxim | 73:2cecc1372acc | 52 | BPS_19200 = 2, |
IanBenzMaxim | 73:2cecc1372acc | 53 | BPS_57600 = 4, |
IanBenzMaxim | 73:2cecc1372acc | 54 | BPS_115200 = 6 |
IanBenzMaxim | 73:2cecc1372acc | 55 | }; |
IanBenzMaxim | 73:2cecc1372acc | 56 | |
IanBenzMaxim | 73:2cecc1372acc | 57 | /**********************************************************//** |
IanBenzMaxim | 73:2cecc1372acc | 58 | * @brief DS2480B constructor |
IanBenzMaxim | 73:2cecc1372acc | 59 | * |
IanBenzMaxim | 73:2cecc1372acc | 60 | * @details allows user to use existing Serial object |
IanBenzMaxim | 73:2cecc1372acc | 61 | * |
IanBenzMaxim | 73:2cecc1372acc | 62 | * On Entry: |
IanBenzMaxim | 73:2cecc1372acc | 63 | * @param[in] p_serial - pointer to existing serial object |
IanBenzMaxim | 73:2cecc1372acc | 64 | * |
IanBenzMaxim | 73:2cecc1372acc | 65 | * On Exit: |
IanBenzMaxim | 73:2cecc1372acc | 66 | * @return |
IanBenzMaxim | 73:2cecc1372acc | 67 | **************************************************************/ |
IanBenzMaxim | 73:2cecc1372acc | 68 | DS2480B(mbed::Serial &p_serial); |
IanBenzMaxim | 73:2cecc1372acc | 69 | |
IanBenzMaxim | 73:2cecc1372acc | 70 | |
IanBenzMaxim | 73:2cecc1372acc | 71 | /**********************************************************//** |
IanBenzMaxim | 73:2cecc1372acc | 72 | * @brief DS2480B constructor |
IanBenzMaxim | 73:2cecc1372acc | 73 | * |
IanBenzMaxim | 73:2cecc1372acc | 74 | * @details Object instantiates a new serial object with no |
IanBenzMaxim | 73:2cecc1372acc | 75 | * public access |
IanBenzMaxim | 73:2cecc1372acc | 76 | * |
IanBenzMaxim | 73:2cecc1372acc | 77 | * On Entry: |
IanBenzMaxim | 73:2cecc1372acc | 78 | * @param[in] tx - tx pin of uart to be used |
IanBenzMaxim | 73:2cecc1372acc | 79 | * @param[in] rx - rx pin of uart to be used |
IanBenzMaxim | 73:2cecc1372acc | 80 | * @param[in] baud - baudrate for uart |
IanBenzMaxim | 73:2cecc1372acc | 81 | * |
IanBenzMaxim | 73:2cecc1372acc | 82 | * On Exit: |
IanBenzMaxim | 73:2cecc1372acc | 83 | * @return |
IanBenzMaxim | 73:2cecc1372acc | 84 | **************************************************************/ |
IanBenzMaxim | 73:2cecc1372acc | 85 | DS2480B(PinName tx, PinName rx); |
IanBenzMaxim | 73:2cecc1372acc | 86 | |
IanBenzMaxim | 73:2cecc1372acc | 87 | |
IanBenzMaxim | 73:2cecc1372acc | 88 | /**********************************************************//** |
IanBenzMaxim | 73:2cecc1372acc | 89 | * @brief DS2480B destructor |
IanBenzMaxim | 73:2cecc1372acc | 90 | * |
IanBenzMaxim | 73:2cecc1372acc | 91 | * @details deletes serial object if owner |
IanBenzMaxim | 73:2cecc1372acc | 92 | * |
IanBenzMaxim | 73:2cecc1372acc | 93 | * On Entry: |
IanBenzMaxim | 73:2cecc1372acc | 94 | * |
IanBenzMaxim | 73:2cecc1372acc | 95 | * On Exit: |
IanBenzMaxim | 73:2cecc1372acc | 96 | * @return |
IanBenzMaxim | 73:2cecc1372acc | 97 | **************************************************************/ |
IanBenzMaxim | 73:2cecc1372acc | 98 | virtual ~DS2480B(); |
IanBenzMaxim | 73:2cecc1372acc | 99 | |
IanBenzMaxim | 73:2cecc1372acc | 100 | OneWireMaster::CmdResult DS2480B_ChangeBaud(DS2480B_BPS newbaud); |
IanBenzMaxim | 73:2cecc1372acc | 101 | |
IanBenzMaxim | 73:2cecc1372acc | 102 | |
IanBenzMaxim | 73:2cecc1372acc | 103 | //Part of OneWireMaster that should be implemented for each master |
IanBenzMaxim | 73:2cecc1372acc | 104 | //See OneWireMaster.h for documentation |
IanBenzMaxim | 73:2cecc1372acc | 105 | |
IanBenzMaxim | 73:2cecc1372acc | 106 | virtual OneWireMaster::CmdResult OWInitMaster(void); |
IanBenzMaxim | 73:2cecc1372acc | 107 | |
IanBenzMaxim | 73:2cecc1372acc | 108 | virtual OneWireMaster::CmdResult OWReset(void); |
IanBenzMaxim | 73:2cecc1372acc | 109 | |
IanBenzMaxim | 73:2cecc1372acc | 110 | virtual OneWireMaster::CmdResult OWTouchBitSetLevel(uint8_t & sendrecvbit, OWLevel after_level); |
j3 | 17:b646b1e3970b | 111 | |
IanBenzMaxim | 73:2cecc1372acc | 112 | virtual OneWireMaster::CmdResult OWWriteByteSetLevel(uint8_t sendbyte, OWLevel after_level); |
j3 | 3:644fc630f958 | 113 | |
IanBenzMaxim | 73:2cecc1372acc | 114 | virtual OneWireMaster::CmdResult OWReadByteSetLevel(uint8_t & recvbyte, OWLevel after_level); |
j3 | 23:e8e403d61359 | 115 | |
IanBenzMaxim | 73:2cecc1372acc | 116 | virtual OneWireMaster::CmdResult OWSetSpeed(OWSpeed new_speed); |
j3 | 3:644fc630f958 | 117 | |
IanBenzMaxim | 73:2cecc1372acc | 118 | virtual OneWireMaster::CmdResult OWSetLevel(OWLevel new_level); |
IanBenzMaxim | 73:2cecc1372acc | 119 | |
IanBenzMaxim | 73:2cecc1372acc | 120 | private: |
IanBenzMaxim | 73:2cecc1372acc | 121 | |
IanBenzMaxim | 73:2cecc1372acc | 122 | void rx_callback(void); |
IanBenzMaxim | 73:2cecc1372acc | 123 | |
IanBenzMaxim | 73:2cecc1372acc | 124 | OneWireMaster::CmdResult DS2480B_Detect(void); |
IanBenzMaxim | 73:2cecc1372acc | 125 | OneWireMaster::CmdResult WriteCOM(uint32_t outlen, uint8_t *outbuf); |
IanBenzMaxim | 73:2cecc1372acc | 126 | OneWireMaster::CmdResult ReadCOM(uint32_t inlen, uint8_t *inbuf); |
IanBenzMaxim | 73:2cecc1372acc | 127 | void BreakCOM(void); |
IanBenzMaxim | 73:2cecc1372acc | 128 | void FlushCOM(void); |
IanBenzMaxim | 73:2cecc1372acc | 129 | void SetBaudCOM(uint8_t new_baud); |
IanBenzMaxim | 73:2cecc1372acc | 130 | int32_t bitacc(uint32_t op, uint32_t state, uint32_t loc, uint8_t *buf); |
IanBenzMaxim | 73:2cecc1372acc | 131 | |
IanBenzMaxim | 73:2cecc1372acc | 132 | mbed::Serial *_p_serial; |
IanBenzMaxim | 73:2cecc1372acc | 133 | bool _serial_owner; |
IanBenzMaxim | 73:2cecc1372acc | 134 | |
IanBenzMaxim | 73:2cecc1372acc | 135 | // DS2480B state |
IanBenzMaxim | 73:2cecc1372acc | 136 | OWLevel _ULevel; // 1-Wire level |
IanBenzMaxim | 73:2cecc1372acc | 137 | DS2480B_BPS _UBaud; // baud rate |
IanBenzMaxim | 73:2cecc1372acc | 138 | uint8_t _UMode; // command or data mode state |
IanBenzMaxim | 73:2cecc1372acc | 139 | uint8_t _USpeed; // 1-Wire communication speed |
IanBenzMaxim | 73:2cecc1372acc | 140 | |
IanBenzMaxim | 73:2cecc1372acc | 141 | static const size_t MAX_RX_BUFFER_LEN = 256; |
IanBenzMaxim | 73:2cecc1372acc | 142 | volatile struct ds2480b_circular_buff_s |
IanBenzMaxim | 73:2cecc1372acc | 143 | { |
IanBenzMaxim | 73:2cecc1372acc | 144 | uint8_t w_idx; |
IanBenzMaxim | 73:2cecc1372acc | 145 | uint8_t r_idx; |
IanBenzMaxim | 73:2cecc1372acc | 146 | uint8_t rx_bytes_available; |
IanBenzMaxim | 73:2cecc1372acc | 147 | bool wrap_error; |
IanBenzMaxim | 73:2cecc1372acc | 148 | uint8_t buff[MAX_RX_BUFFER_LEN]; |
IanBenzMaxim | 73:2cecc1372acc | 149 | }rx_buffer; |
IanBenzMaxim | 73:2cecc1372acc | 150 | }; |
IanBenzMaxim | 73:2cecc1372acc | 151 | } |
IanBenzMaxim | 73:2cecc1372acc | 152 | } |
j3 | 3:644fc630f958 | 153 | |
j3 | 3:644fc630f958 | 154 | #endif /*DS2480B_H*/ |
j3 | 3:644fc630f958 | 155 |