Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Max32630_One_Wire_Interface
RomId.cpp@49:36954b62f503, 2016-04-08 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Fri Apr 08 16:11:16 2016 -0500
- Revision:
- 49:36954b62f503
- Parent:
- 21:00c94aeb533e
- Child:
- 73:2cecc1372acc
Added a Read Scratchpad operation for DS28E15/22/25. Added comments for various classes.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| j3 | 17:b646b1e3970b | 1 | /******************************************************************//** |
| j3 | 17:b646b1e3970b | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
| j3 | 17:b646b1e3970b | 3 | * |
| j3 | 17:b646b1e3970b | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| j3 | 17:b646b1e3970b | 5 | * copy of this software and associated documentation files (the "Software"), |
| j3 | 17:b646b1e3970b | 6 | * to deal in the Software without restriction, including without limitation |
| j3 | 17:b646b1e3970b | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| j3 | 17:b646b1e3970b | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| j3 | 17:b646b1e3970b | 9 | * Software is furnished to do so, subject to the following conditions: |
| j3 | 17:b646b1e3970b | 10 | * |
| j3 | 17:b646b1e3970b | 11 | * The above copyright notice and this permission notice shall be included |
| j3 | 17:b646b1e3970b | 12 | * in all copies or substantial portions of the Software. |
| j3 | 17:b646b1e3970b | 13 | * |
| j3 | 17:b646b1e3970b | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| j3 | 17:b646b1e3970b | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| j3 | 17:b646b1e3970b | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| j3 | 17:b646b1e3970b | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
| j3 | 17:b646b1e3970b | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| j3 | 17:b646b1e3970b | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| j3 | 17:b646b1e3970b | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| j3 | 17:b646b1e3970b | 21 | * |
| j3 | 17:b646b1e3970b | 22 | * Except as contained in this notice, the name of Maxim Integrated |
| j3 | 17:b646b1e3970b | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
| j3 | 17:b646b1e3970b | 24 | * Products, Inc. Branding Policy. |
| j3 | 17:b646b1e3970b | 25 | * |
| j3 | 17:b646b1e3970b | 26 | * The mere transfer of this software does not imply any licenses |
| j3 | 17:b646b1e3970b | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
| j3 | 17:b646b1e3970b | 28 | * trademarks, maskwork rights, or any other form of intellectual |
| j3 | 17:b646b1e3970b | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
| j3 | 17:b646b1e3970b | 30 | * ownership rights. |
| j3 | 17:b646b1e3970b | 31 | **********************************************************************/ |
| j3 | 17:b646b1e3970b | 32 | |
| j3 | 17:b646b1e3970b | 33 | #include "RomId.hpp" |
| j3 | 17:b646b1e3970b | 34 | |
| IanBenzMaxim | 21:00c94aeb533e | 35 | std::uint8_t RomId::calculateCRC8(std::uint8_t crc8, std::uint8_t data) |
| j3 | 17:b646b1e3970b | 36 | { |
| j3 | 17:b646b1e3970b | 37 | int i; |
| j3 | 17:b646b1e3970b | 38 | |
| j3 | 17:b646b1e3970b | 39 | // See Application Note 27 |
| j3 | 17:b646b1e3970b | 40 | crc8 = crc8 ^ data; |
| j3 | 17:b646b1e3970b | 41 | for (i = 0; i < 8; ++i) |
| j3 | 17:b646b1e3970b | 42 | { |
| j3 | 17:b646b1e3970b | 43 | if (crc8 & 1) |
| j3 | 17:b646b1e3970b | 44 | crc8 = (crc8 >> 1) ^ 0x8c; |
| j3 | 17:b646b1e3970b | 45 | else |
| j3 | 17:b646b1e3970b | 46 | crc8 = (crc8 >> 1); |
| j3 | 17:b646b1e3970b | 47 | } |
| j3 | 17:b646b1e3970b | 48 | |
| j3 | 17:b646b1e3970b | 49 | return crc8; |
| j3 | 17:b646b1e3970b | 50 | } |
| j3 | 17:b646b1e3970b | 51 | |
| IanBenzMaxim | 21:00c94aeb533e | 52 | std::uint8_t RomId::calculateCRC8(const std::uint8_t * data, std::size_t data_len, std::uint8_t crc) |
| j3 | 17:b646b1e3970b | 53 | { |
| IanBenzMaxim | 21:00c94aeb533e | 54 | for (std::size_t i = 0; i < data_len; i++) |
| j3 | 17:b646b1e3970b | 55 | crc = calculateCRC8(crc, data[i]); |
| j3 | 17:b646b1e3970b | 56 | return crc; |
| j3 | 17:b646b1e3970b | 57 | } |