<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- permission is obtained from the copyright holder. -->
|
<!-- permission is obtained from the copyright holder. -->
|
<HTML
|
<HTML
|
><HEAD
|
><HEAD
|
><TITLE
|
><TITLE
|
>CRC Functions</TITLE
|
>CRC Functions</TITLE
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
<META
|
<META
|
NAME="GENERATOR"
|
NAME="GENERATOR"
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
"><LINK
|
"><LINK
|
REL="HOME"
|
REL="HOME"
|
TITLE="eCos Reference Manual"
|
TITLE="eCos Reference Manual"
|
HREF="ecos-ref.html"><LINK
|
HREF="ecos-ref.html"><LINK
|
REL="UP"
|
REL="UP"
|
TITLE="CRC Algorithms"
|
TITLE="CRC Algorithms"
|
HREF="services-crc.html"><LINK
|
HREF="services-crc.html"><LINK
|
REL="PREVIOUS"
|
REL="PREVIOUS"
|
TITLE="CRC Algorithms"
|
TITLE="CRC Algorithms"
|
HREF="services-crc.html"><LINK
|
HREF="services-crc.html"><LINK
|
REL="NEXT"
|
REL="NEXT"
|
TITLE="CPU load measurements"
|
TITLE="CPU load measurements"
|
HREF="services-cpuload.html"></HEAD
|
HREF="services-cpuload.html"></HEAD
|
><BODY
|
><BODY
|
CLASS="CHAPTER"
|
CLASS="CHAPTER"
|
BGCOLOR="#FFFFFF"
|
BGCOLOR="#FFFFFF"
|
TEXT="#000000"
|
TEXT="#000000"
|
LINK="#0000FF"
|
LINK="#0000FF"
|
VLINK="#840084"
|
VLINK="#840084"
|
ALINK="#0000FF"
|
ALINK="#0000FF"
|
><DIV
|
><DIV
|
CLASS="NAVHEADER"
|
CLASS="NAVHEADER"
|
><TABLE
|
><TABLE
|
SUMMARY="Header navigation table"
|
SUMMARY="Header navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TH
|
><TH
|
COLSPAN="3"
|
COLSPAN="3"
|
ALIGN="center"
|
ALIGN="center"
|
>eCos Reference Manual</TH
|
>eCos Reference Manual</TH
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="services-crc.html"
|
HREF="services-crc.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="80%"
|
WIDTH="80%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="services-cpuload.html"
|
HREF="services-cpuload.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"></DIV
|
WIDTH="100%"></DIV
|
><DIV
|
><DIV
|
CLASS="CHAPTER"
|
CLASS="CHAPTER"
|
><H1
|
><H1
|
><A
|
><A
|
NAME="CRC-FUNCTIONS">Chapter 50. CRC Functions</H1
|
NAME="CRC-FUNCTIONS">Chapter 50. CRC Functions</H1
|
><DIV
|
><DIV
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><H1
|
><H1
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><A
|
><A
|
NAME="SERVICES-CRC-API">CRC API</H1
|
NAME="SERVICES-CRC-API">CRC API</H1
|
><P
|
><P
|
>The package implements a number of CRC functions as described below.
|
>The package implements a number of CRC functions as described below.
|
The API to these functions is in the include file
|
The API to these functions is in the include file
|
<TT
|
<TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>cyg/crc/crc.h</TT
|
>cyg/crc/crc.h</TT
|
>.</P
|
>.</P
|
><DIV
|
><DIV
|
CLASS="SECT2"
|
CLASS="SECT2"
|
><H2
|
><H2
|
CLASS="SECT2"
|
CLASS="SECT2"
|
><A
|
><A
|
NAME="SERVICES-CRC-API-CYG-POSIX-CRC32">cyg_posix_crc32</H2
|
NAME="SERVICES-CRC-API-CYG-POSIX-CRC32">cyg_posix_crc32</H2
|
><P
|
><P
|
>This function implements a 32 bit CRC which is compliant to the POSIX
|
>This function implements a 32 bit CRC which is compliant to the POSIX
|
1008.2 Standard. This is the same as the Linux cksum program.</P
|
1008.2 Standard. This is the same as the Linux cksum program.</P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="PROGRAMLISTING"
|
CLASS="PROGRAMLISTING"
|
>cyg_uint32 cyg_posix_crc32(unsigned char * s, int len);</PRE
|
>cyg_uint32 cyg_posix_crc32(unsigned char * s, int len);</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
>The CRC calculation is run over the data pointed to by
|
>The CRC calculation is run over the data pointed to by
|
<TT
|
<TT
|
CLASS="PARAMETER"
|
CLASS="PARAMETER"
|
><I
|
><I
|
>s</I
|
>s</I
|
></TT
|
></TT
|
>, of length <TT
|
>, of length <TT
|
CLASS="PARAMETER"
|
CLASS="PARAMETER"
|
><I
|
><I
|
>len</I
|
>len</I
|
></TT
|
></TT
|
>. The
|
>. The
|
CRC is returned as an unsigned long.</P
|
CRC is returned as an unsigned long.</P
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="SECT2"
|
CLASS="SECT2"
|
><H2
|
><H2
|
CLASS="SECT2"
|
CLASS="SECT2"
|
><A
|
><A
|
NAME="SERVICES-CRC-API-CYG-CRC32">cyg_crc32</H2
|
NAME="SERVICES-CRC-API-CYG-CRC32">cyg_crc32</H2
|
><P
|
><P
|
>These functions implement a 32 bit CRC by Gary S. Brown. They use the
|
>These functions implement a 32 bit CRC by Gary S. Brown. They use the
|
polynomial
|
polynomial
|
X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0.</P
|
X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0.</P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="PROGRAMLISTING"
|
CLASS="PROGRAMLISTING"
|
>cyg_uint32 cyg_crc32(unsigned char * s, int len);
|
>cyg_uint32 cyg_crc32(unsigned char * s, int len);
|
cyg_uint32 cyg_crc32_accumulate(cyg_uint32 crc, unsigned char * s, int len);</PRE
|
cyg_uint32 cyg_crc32_accumulate(cyg_uint32 crc, unsigned char * s, int len);</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
>The CRC calculation is run over the data pointed to by
|
>The CRC calculation is run over the data pointed to by
|
<TT
|
<TT
|
CLASS="PARAMETER"
|
CLASS="PARAMETER"
|
><I
|
><I
|
>s</I
|
>s</I
|
></TT
|
></TT
|
>, of length <TT
|
>, of length <TT
|
CLASS="PARAMETER"
|
CLASS="PARAMETER"
|
><I
|
><I
|
>len</I
|
>len</I
|
></TT
|
></TT
|
>. The
|
>. The
|
CRC is returned as an unsigned long.</P
|
CRC is returned as an unsigned long.</P
|
><P
|
><P
|
> The CRC can be calculated over data separated into multiple
|
> The CRC can be calculated over data separated into multiple
|
buffers by using the function <TT
|
buffers by using the function <TT
|
CLASS="PARAMETER"
|
CLASS="PARAMETER"
|
><I
|
><I
|
> cyg_crc32_accumulate()</I
|
> cyg_crc32_accumulate()</I
|
></TT
|
></TT
|
>. The parameter <TT
|
>. The parameter <TT
|
CLASS="PARAMETER"
|
CLASS="PARAMETER"
|
><I
|
><I
|
>crc</I
|
>crc</I
|
></TT
|
></TT
|
> should be the
|
> should be the
|
result from the previous CRC calculation.</P
|
result from the previous CRC calculation.</P
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="SECT2"
|
CLASS="SECT2"
|
><H2
|
><H2
|
CLASS="SECT2"
|
CLASS="SECT2"
|
><A
|
><A
|
NAME="SERVICES-CRC-API-CYG-ETHER-CRC32">cyg_ether_crc32</H2
|
NAME="SERVICES-CRC-API-CYG-ETHER-CRC32">cyg_ether_crc32</H2
|
><P
|
><P
|
>These functions implement the 32 bit CRC used by the Ethernet FCS word.</P
|
>These functions implement the 32 bit CRC used by the Ethernet FCS word.</P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="PROGRAMLISTING"
|
CLASS="PROGRAMLISTING"
|
>cyg_uint32 cyg_ether_crc32(unsigned char * s, int len);
|
>cyg_uint32 cyg_ether_crc32(unsigned char * s, int len);
|
cyg_uint32 cyg_ether_crc32_accumulate(cyg_uint32 crc, unsigned char * s, int len);</PRE
|
cyg_uint32 cyg_ether_crc32_accumulate(cyg_uint32 crc, unsigned char * s, int len);</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
>The CRC calculation is run over the data pointed to by
|
>The CRC calculation is run over the data pointed to by
|
<TT
|
<TT
|
CLASS="PARAMETER"
|
CLASS="PARAMETER"
|
><I
|
><I
|
>s</I
|
>s</I
|
></TT
|
></TT
|
>, of length <TT
|
>, of length <TT
|
CLASS="PARAMETER"
|
CLASS="PARAMETER"
|
><I
|
><I
|
>len</I
|
>len</I
|
></TT
|
></TT
|
>. The
|
>. The
|
CRC is returned as an unsigned long.</P
|
CRC is returned as an unsigned long.</P
|
><P
|
><P
|
> The CRC can be calculated over data separated into multiple
|
> The CRC can be calculated over data separated into multiple
|
buffers by using the function <TT
|
buffers by using the function <TT
|
CLASS="PARAMETER"
|
CLASS="PARAMETER"
|
><I
|
><I
|
> cyg_ether_crc32_accumulate()</I
|
> cyg_ether_crc32_accumulate()</I
|
></TT
|
></TT
|
>. The parameter <TT
|
>. The parameter <TT
|
CLASS="PARAMETER"
|
CLASS="PARAMETER"
|
><I
|
><I
|
>crc</I
|
>crc</I
|
></TT
|
></TT
|
> should be the
|
> should be the
|
result from the previous CRC calculation.</P
|
result from the previous CRC calculation.</P
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="SECT2"
|
CLASS="SECT2"
|
><H2
|
><H2
|
CLASS="SECT2"
|
CLASS="SECT2"
|
><A
|
><A
|
NAME="SERVICES-CRC-API-CYG-CRC16">cyg_crc16</H2
|
NAME="SERVICES-CRC-API-CYG-CRC16">cyg_crc16</H2
|
><P
|
><P
|
>This function implements a 16 bit CRC. It uses the polynomial
|
>This function implements a 16 bit CRC. It uses the polynomial
|
x^16+x^12+x^5+1.</P
|
x^16+x^12+x^5+1.</P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="PROGRAMLISTING"
|
CLASS="PROGRAMLISTING"
|
>cyg_uint16 cyg_crc16(unsigned char * s, int len);</PRE
|
>cyg_uint16 cyg_crc16(unsigned char * s, int len);</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
>The CRC calculation is run over the data pointed to by
|
>The CRC calculation is run over the data pointed to by
|
<TT
|
<TT
|
CLASS="PARAMETER"
|
CLASS="PARAMETER"
|
><I
|
><I
|
>s</I
|
>s</I
|
></TT
|
></TT
|
>, of length <TT
|
>, of length <TT
|
CLASS="PARAMETER"
|
CLASS="PARAMETER"
|
><I
|
><I
|
>len</I
|
>len</I
|
></TT
|
></TT
|
>. The
|
>. The
|
CRC is returned as an unsigned short.</P
|
CRC is returned as an unsigned short.</P
|
></DIV
|
></DIV
|
></DIV
|
></DIV
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="NAVFOOTER"
|
CLASS="NAVFOOTER"
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"><TABLE
|
WIDTH="100%"><TABLE
|
SUMMARY="Footer navigation table"
|
SUMMARY="Footer navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="services-crc.html"
|
HREF="services-crc.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="ecos-ref.html"
|
HREF="ecos-ref.html"
|
ACCESSKEY="H"
|
ACCESSKEY="H"
|
>Home</A
|
>Home</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="services-cpuload.html"
|
HREF="services-cpuload.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
>CRC Algorithms</TD
|
>CRC Algorithms</TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="services-crc.html"
|
HREF="services-crc.html"
|
ACCESSKEY="U"
|
ACCESSKEY="U"
|
>Up</A
|
>Up</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
>CPU load measurements</TD
|
>CPU load measurements</TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
></BODY
|
></BODY
|
></HTML
|
></HTML
|
|
|