mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by Umar Naeem

Committer:
ranaumarnaeem
Date:
Tue May 23 12:54:50 2017 +0000
Revision:
165:2dd56e6daeec
Parent:
150:02e0a0aed4ec
jhjg

Who changed what in which revision?

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