mbed library sources. Supersedes mbed-src.
Fork of mbed-dev by
targets/TARGET_Maxim/TARGET_MAX32630/mxc/crc.c@157:ff67d9f36b67, 2017-02-02 (annotated)
- Committer:
- <>
- Date:
- Thu Feb 02 17:01:33 2017 +0000
- Revision:
- 157:ff67d9f36b67
This updates the lib to the mbed lib v135
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 157:ff67d9f36b67 | 1 | /** |
<> | 157:ff67d9f36b67 | 2 | * @file |
<> | 157:ff67d9f36b67 | 3 | * @brief This file contains the function implementations for the Cyclic |
<> | 157:ff67d9f36b67 | 4 | * Redundency Check (CRC) peripheral module. |
<> | 157:ff67d9f36b67 | 5 | */ |
<> | 157:ff67d9f36b67 | 6 | |
<> | 157:ff67d9f36b67 | 7 | /* **************************************************************************** |
<> | 157:ff67d9f36b67 | 8 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
<> | 157:ff67d9f36b67 | 9 | * |
<> | 157:ff67d9f36b67 | 10 | * Permission is hereby granted, free of charge, to any person obtaining a |
<> | 157:ff67d9f36b67 | 11 | * copy of this software and associated documentation files (the "Software"), |
<> | 157:ff67d9f36b67 | 12 | * to deal in the Software without restriction, including without limitation |
<> | 157:ff67d9f36b67 | 13 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
<> | 157:ff67d9f36b67 | 14 | * and/or sell copies of the Software, and to permit persons to whom the |
<> | 157:ff67d9f36b67 | 15 | * Software is furnished to do so, subject to the following conditions: |
<> | 157:ff67d9f36b67 | 16 | * |
<> | 157:ff67d9f36b67 | 17 | * The above copyright notice and this permission notice shall be included |
<> | 157:ff67d9f36b67 | 18 | * in all copies or substantial portions of the Software. |
<> | 157:ff67d9f36b67 | 19 | * |
<> | 157:ff67d9f36b67 | 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
<> | 157:ff67d9f36b67 | 21 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
<> | 157:ff67d9f36b67 | 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
<> | 157:ff67d9f36b67 | 23 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
<> | 157:ff67d9f36b67 | 24 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
<> | 157:ff67d9f36b67 | 25 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
<> | 157:ff67d9f36b67 | 26 | * OTHER DEALINGS IN THE SOFTWARE. |
<> | 157:ff67d9f36b67 | 27 | * |
<> | 157:ff67d9f36b67 | 28 | * Except as contained in this notice, the name of Maxim Integrated |
<> | 157:ff67d9f36b67 | 29 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
<> | 157:ff67d9f36b67 | 30 | * Products, Inc. Branding Policy. |
<> | 157:ff67d9f36b67 | 31 | * |
<> | 157:ff67d9f36b67 | 32 | * The mere transfer of this software does not imply any licenses |
<> | 157:ff67d9f36b67 | 33 | * of trade secrets, proprietary technology, copyrights, patents, |
<> | 157:ff67d9f36b67 | 34 | * trademarks, maskwork rights, or any other form of intellectual |
<> | 157:ff67d9f36b67 | 35 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
<> | 157:ff67d9f36b67 | 36 | * ownership rights. |
<> | 157:ff67d9f36b67 | 37 | * |
<> | 157:ff67d9f36b67 | 38 | * $Date: 2016-09-09 11:49:04 -0500 (Fri, 09 Sep 2016) $ |
<> | 157:ff67d9f36b67 | 39 | * $Revision: 24339 $ |
<> | 157:ff67d9f36b67 | 40 | * |
<> | 157:ff67d9f36b67 | 41 | *************************************************************************** */ |
<> | 157:ff67d9f36b67 | 42 | |
<> | 157:ff67d9f36b67 | 43 | /* **** Includes **** */ |
<> | 157:ff67d9f36b67 | 44 | #include "crc.h" |
<> | 157:ff67d9f36b67 | 45 | |
<> | 157:ff67d9f36b67 | 46 | /** |
<> | 157:ff67d9f36b67 | 47 | * @ingroup crc |
<> | 157:ff67d9f36b67 | 48 | * @{ |
<> | 157:ff67d9f36b67 | 49 | */ |
<> | 157:ff67d9f36b67 | 50 | |
<> | 157:ff67d9f36b67 | 51 | /* **** Definitions **** */ |
<> | 157:ff67d9f36b67 | 52 | |
<> | 157:ff67d9f36b67 | 53 | /* **** Globals **** */ |
<> | 157:ff67d9f36b67 | 54 | |
<> | 157:ff67d9f36b67 | 55 | /* **** Functions **** */ |
<> | 157:ff67d9f36b67 | 56 | |
<> | 157:ff67d9f36b67 | 57 | /* ************************************************************************* */ |
<> | 157:ff67d9f36b67 | 58 | void CRC16_Init(uint8_t CCITT_TRUE, uint8_t lilEndian) |
<> | 157:ff67d9f36b67 | 59 | { |
<> | 157:ff67d9f36b67 | 60 | if(CCITT_TRUE) |
<> | 157:ff67d9f36b67 | 61 | MXC_CRC->reseed |= MXC_F_CRC_RESEED_CCITT_MODE; |
<> | 157:ff67d9f36b67 | 62 | else |
<> | 157:ff67d9f36b67 | 63 | MXC_CRC->reseed &= ~MXC_F_CRC_RESEED_CCITT_MODE; |
<> | 157:ff67d9f36b67 | 64 | |
<> | 157:ff67d9f36b67 | 65 | if(lilEndian) |
<> | 157:ff67d9f36b67 | 66 | MXC_CRC->reseed |= MXC_F_CRC_RESEED_REV_ENDIAN16; |
<> | 157:ff67d9f36b67 | 67 | else |
<> | 157:ff67d9f36b67 | 68 | MXC_CRC->reseed &= ~MXC_F_CRC_RESEED_REV_ENDIAN16; |
<> | 157:ff67d9f36b67 | 69 | } |
<> | 157:ff67d9f36b67 | 70 | |
<> | 157:ff67d9f36b67 | 71 | /* ************************************************************************* */ |
<> | 157:ff67d9f36b67 | 72 | void CRC32_Init(uint8_t lilEndian) |
<> | 157:ff67d9f36b67 | 73 | { |
<> | 157:ff67d9f36b67 | 74 | if(lilEndian) |
<> | 157:ff67d9f36b67 | 75 | MXC_CRC->reseed |= MXC_F_CRC_RESEED_REV_ENDIAN32; |
<> | 157:ff67d9f36b67 | 76 | else |
<> | 157:ff67d9f36b67 | 77 | MXC_CRC->reseed &= ~MXC_F_CRC_RESEED_REV_ENDIAN32; |
<> | 157:ff67d9f36b67 | 78 | } |
<> | 157:ff67d9f36b67 | 79 | |
<> | 157:ff67d9f36b67 | 80 | /* ************************************************************************* */ |
<> | 157:ff67d9f36b67 | 81 | |
<> | 157:ff67d9f36b67 | 82 | void CRC16_Reseed(uint16_t initData) |
<> | 157:ff67d9f36b67 | 83 | { |
<> | 157:ff67d9f36b67 | 84 | //set initial value |
<> | 157:ff67d9f36b67 | 85 | MXC_CRC->seed16 = initData; |
<> | 157:ff67d9f36b67 | 86 | |
<> | 157:ff67d9f36b67 | 87 | //reseed the CRC16 generator |
<> | 157:ff67d9f36b67 | 88 | MXC_CRC->reseed |= MXC_F_CRC_RESEED_CRC16; |
<> | 157:ff67d9f36b67 | 89 | |
<> | 157:ff67d9f36b67 | 90 | //wait for reseed to clear itself |
<> | 157:ff67d9f36b67 | 91 | while(MXC_CRC->reseed & MXC_F_CRC_RESEED_CRC16); |
<> | 157:ff67d9f36b67 | 92 | |
<> | 157:ff67d9f36b67 | 93 | } |
<> | 157:ff67d9f36b67 | 94 | |
<> | 157:ff67d9f36b67 | 95 | /* ************************************************************************* */ |
<> | 157:ff67d9f36b67 | 96 | void CRC32_Reseed(uint32_t initData) |
<> | 157:ff67d9f36b67 | 97 | { |
<> | 157:ff67d9f36b67 | 98 | //set initial value |
<> | 157:ff67d9f36b67 | 99 | MXC_CRC->seed32 = initData; |
<> | 157:ff67d9f36b67 | 100 | |
<> | 157:ff67d9f36b67 | 101 | //reseed the CRC16 generator |
<> | 157:ff67d9f36b67 | 102 | MXC_CRC->reseed |= MXC_F_CRC_RESEED_CRC32; |
<> | 157:ff67d9f36b67 | 103 | |
<> | 157:ff67d9f36b67 | 104 | //wait for reseed to clear itself |
<> | 157:ff67d9f36b67 | 105 | while(MXC_CRC->reseed & MXC_F_CRC_RESEED_CRC32); |
<> | 157:ff67d9f36b67 | 106 | } |
<> | 157:ff67d9f36b67 | 107 | |
<> | 157:ff67d9f36b67 | 108 | /**@} end of group crc */ |