Path: blob/main/sys/contrib/ncsw/inc/Peripherals/crc_mac_addr_ext.h
48375 views
/*1* Copyright 2008-2012 Freescale Semiconductor Inc.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions are met:5* * Redistributions of source code must retain the above copyright6* notice, this list of conditions and the following disclaimer.7* * Redistributions in binary form must reproduce the above copyright8* notice, this list of conditions and the following disclaimer in the9* documentation and/or other materials provided with the distribution.10* * Neither the name of Freescale Semiconductor nor the11* names of its contributors may be used to endorse or promote products12* derived from this software without specific prior written permission.13*14*15* ALTERNATIVELY, this software may be distributed under the terms of the16* GNU General Public License ("GPL") as published by the Free Software17* Foundation, either version 2 of that License or (at your option) any18* later version.19*20* THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY21* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED22* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE23* DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY24* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES25* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;26* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND27* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT28* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS29* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.30*/313233/*------------------------------------------------------*/34/* */35/* File: crc_mac_addr_ext.h */36/* */37/* Description: */38/* Define a macro that calculate the crc value of */39/* an Ethernet MAC address (48 bitd address */40/*------------------------------------------------------*/4142#ifndef __crc_mac_addr_ext_h43#define __crc_mac_addr_ext_h4445#include "std_ext.h"464748static uint32_t crc_table[256] =49{500x00000000,510x77073096,520xee0e612c,530x990951ba,540x076dc419,550x706af48f,560xe963a535,570x9e6495a3,580x0edb8832,590x79dcb8a4,600xe0d5e91e,610x97d2d988,620x09b64c2b,630x7eb17cbd,640xe7b82d07,650x90bf1d91,660x1db71064,670x6ab020f2,680xf3b97148,690x84be41de,700x1adad47d,710x6ddde4eb,720xf4d4b551,730x83d385c7,740x136c9856,750x646ba8c0,760xfd62f97a,770x8a65c9ec,780x14015c4f,790x63066cd9,800xfa0f3d63,810x8d080df5,820x3b6e20c8,830x4c69105e,840xd56041e4,850xa2677172,860x3c03e4d1,870x4b04d447,880xd20d85fd,890xa50ab56b,900x35b5a8fa,910x42b2986c,920xdbbbc9d6,930xacbcf940,940x32d86ce3,950x45df5c75,960xdcd60dcf,970xabd13d59,980x26d930ac,990x51de003a,1000xc8d75180,1010xbfd06116,1020x21b4f4b5,1030x56b3c423,1040xcfba9599,1050xb8bda50f,1060x2802b89e,1070x5f058808,1080xc60cd9b2,1090xb10be924,1100x2f6f7c87,1110x58684c11,1120xc1611dab,1130xb6662d3d,1140x76dc4190,1150x01db7106,1160x98d220bc,1170xefd5102a,1180x71b18589,1190x06b6b51f,1200x9fbfe4a5,1210xe8b8d433,1220x7807c9a2,1230x0f00f934,1240x9609a88e,1250xe10e9818,1260x7f6a0dbb,1270x086d3d2d,1280x91646c97,1290xe6635c01,1300x6b6b51f4,1310x1c6c6162,1320x856530d8,1330xf262004e,1340x6c0695ed,1350x1b01a57b,1360x8208f4c1,1370xf50fc457,1380x65b0d9c6,1390x12b7e950,1400x8bbeb8ea,1410xfcb9887c,1420x62dd1ddf,1430x15da2d49,1440x8cd37cf3,1450xfbd44c65,1460x4db26158,1470x3ab551ce,1480xa3bc0074,1490xd4bb30e2,1500x4adfa541,1510x3dd895d7,1520xa4d1c46d,1530xd3d6f4fb,1540x4369e96a,1550x346ed9fc,1560xad678846,1570xda60b8d0,1580x44042d73,1590x33031de5,1600xaa0a4c5f,1610xdd0d7cc9,1620x5005713c,1630x270241aa,1640xbe0b1010,1650xc90c2086,1660x5768b525,1670x206f85b3,1680xb966d409,1690xce61e49f,1700x5edef90e,1710x29d9c998,1720xb0d09822,1730xc7d7a8b4,1740x59b33d17,1750x2eb40d81,1760xb7bd5c3b,1770xc0ba6cad,1780xedb88320,1790x9abfb3b6,1800x03b6e20c,1810x74b1d29a,1820xead54739,1830x9dd277af,1840x04db2615,1850x73dc1683,1860xe3630b12,1870x94643b84,1880x0d6d6a3e,1890x7a6a5aa8,1900xe40ecf0b,1910x9309ff9d,1920x0a00ae27,1930x7d079eb1,1940xf00f9344,1950x8708a3d2,1960x1e01f268,1970x6906c2fe,1980xf762575d,1990x806567cb,2000x196c3671,2010x6e6b06e7,2020xfed41b76,2030x89d32be0,2040x10da7a5a,2050x67dd4acc,2060xf9b9df6f,2070x8ebeeff9,2080x17b7be43,2090x60b08ed5,2100xd6d6a3e8,2110xa1d1937e,2120x38d8c2c4,2130x4fdff252,2140xd1bb67f1,2150xa6bc5767,2160x3fb506dd,2170x48b2364b,2180xd80d2bda,2190xaf0a1b4c,2200x36034af6,2210x41047a60,2220xdf60efc3,2230xa867df55,2240x316e8eef,2250x4669be79,2260xcb61b38c,2270xbc66831a,2280x256fd2a0,2290x5268e236,2300xcc0c7795,2310xbb0b4703,2320x220216b9,2330x5505262f,2340xc5ba3bbe,2350xb2bd0b28,2360x2bb45a92,2370x5cb36a04,2380xc2d7ffa7,2390xb5d0cf31,2400x2cd99e8b,2410x5bdeae1d,2420x9b64c2b0,2430xec63f226,2440x756aa39c,2450x026d930a,2460x9c0906a9,2470xeb0e363f,2480x72076785,2490x05005713,2500x95bf4a82,2510xe2b87a14,2520x7bb12bae,2530x0cb61b38,2540x92d28e9b,2550xe5d5be0d,2560x7cdcefb7,2570x0bdbdf21,2580x86d3d2d4,2590xf1d4e242,2600x68ddb3f8,2610x1fda836e,2620x81be16cd,2630xf6b9265b,2640x6fb077e1,2650x18b74777,2660x88085ae6,2670xff0f6a70,2680x66063bca,2690x11010b5c,2700x8f659eff,2710xf862ae69,2720x616bffd3,2730x166ccf45,2740xa00ae278,2750xd70dd2ee,2760x4e048354,2770x3903b3c2,2780xa7672661,2790xd06016f7,2800x4969474d,2810x3e6e77db,2820xaed16a4a,2830xd9d65adc,2840x40df0b66,2850x37d83bf0,2860xa9bcae53,2870xdebb9ec5,2880x47b2cf7f,2890x30b5ffe9,2900xbdbdf21c,2910xcabac28a,2920x53b39330,2930x24b4a3a6,2940xbad03605,2950xcdd70693,2960x54de5729,2970x23d967bf,2980xb3667a2e,2990xc4614ab8,3000x5d681b02,3010x2a6f2b94,3020xb40bbe37,3030xc30c8ea1,3040x5a05df1b,3050x2d02ef8d306};307308309#define GET_MAC_ADDR_CRC(addr, crc) \310{ \311uint32_t i; \312uint8_t data; \313\314/* CRC calculation */ \315crc = 0xffffffff; \316for (i=0; i < 6; i++) \317{ \318data = (uint8_t)(addr >> ((5-i)*8)); \319crc = crc^data; \320crc = crc_table[crc&0xff] ^ (crc>>8); \321} \322} \323324/* Define a macro for getting the mirrored value of */325/* a byte size number. (0x11010011 --> 0x11001011) */326/* Sometimes the mirrored value of the CRC is required */327static __inline__ uint8_t GetMirror(uint8_t n)328{329uint8_t mirror[16] =330{3310x00,3320x08,3330x04,3340x0c,3350x02,3360x0a,3370x06,3380x0e,3390x01,3400x09,3410x05,3420x0d,3430x03,3440x0b,3450x07,3460x0f347};348return ((uint8_t)(((mirror[n & 0x0f] << 4) | (mirror[n >> 4]))));349}350351static __inline__ uint32_t GetMirror32(uint32_t n)352{353return (((uint32_t)GetMirror((uint8_t)(n))<<24) |354((uint32_t)GetMirror((uint8_t)(n>>8))<<16) |355((uint32_t)GetMirror((uint8_t)(n>>16))<<8) |356((uint32_t)GetMirror((uint8_t)(n>>24))));357}358359#define MIRROR GetMirror360#define MIRROR_32 GetMirror32361362363#endif /* __crc_mac_addr_ext_h */364365366