You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
392 lines
22 KiB
HTML
392 lines
22 KiB
HTML
4 years ago
|
<!-- HTML header for doxygen 1.8.7-->
|
||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
||
|
<meta name="generator" content="Doxygen 1.6.3"/>
|
||
|
<!--BEGIN PROJECT_NAME--><title>avr-libc: avr-libc: <util/crc16.h>: CRC Computations</title><!--END PROJECT_NAME-->
|
||
|
<!--BEGIN !PROJECT_NAME--><title>avr-libc: <util/crc16.h>: CRC Computations</title><!--END !PROJECT_NAME-->
|
||
|
<link href="$relpath^tabs.css" rel="stylesheet" type="text/css"/>
|
||
|
<script type="text/javascript" src="$relpath^jquery.js"></script>
|
||
|
<script type="text/javascript" src="$relpath^dynsections.js"></script>
|
||
|
$treeview
|
||
|
$search
|
||
|
$mathjax
|
||
|
<link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
|
||
|
$extrastylesheet
|
||
|
</head>
|
||
|
<body>
|
||
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
||
|
|
||
|
<!--BEGIN TITLEAREA-->
|
||
|
<div id="titlearea">
|
||
|
<table cellspacing="0" cellpadding="0">
|
||
|
<tbody>
|
||
|
<tr style="height: 56px;">
|
||
|
<!--BEGIN PROJECT_LOGO-->
|
||
|
<td id="projectlogo"><img alt="Logo" src="$relpath^$projectlogo"/></td>
|
||
|
<!--END PROJECT_LOGO-->
|
||
|
<!--BEGIN PROJECT_NAME-->
|
||
|
<td style="padding-left: 0.5em;">
|
||
|
<div id="projectname">avr-libc
|
||
|
<!--BEGIN PROJECT_NUMBER--> <span id="projectnumber">2.0.0</span><!--END PROJECT_NUMBER-->
|
||
|
</div>
|
||
|
<!--BEGIN PROJECT_BRIEF--><div id="projectbrief">$projectbrief</div><!--END PROJECT_BRIEF-->
|
||
|
</td>
|
||
|
<!--END PROJECT_NAME-->
|
||
|
<!--BEGIN !PROJECT_NAME-->
|
||
|
<!--BEGIN PROJECT_BRIEF-->
|
||
|
<td style="padding-left: 0.5em;">
|
||
|
<div id="projectbrief">$projectbrief</div>
|
||
|
</td>
|
||
|
<!--END PROJECT_BRIEF-->
|
||
|
<!--END !PROJECT_NAME-->
|
||
|
<!--BEGIN DISABLE_INDEX-->
|
||
|
<!--BEGIN SEARCHENGINE-->
|
||
|
<td>$searchbox</td>
|
||
|
<!--END SEARCHENGINE-->
|
||
|
<!--END DISABLE_INDEX-->
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
<table>
|
||
|
<tr>
|
||
|
<td align="left"><a href="http://www.nongnu.org/avr-libc/"><h2>AVR Libc Home Page</h2></a></td>
|
||
|
<td align="center" colspan=4><img src="avrs.png" alt="AVRs" align="middle" border="0"></td>
|
||
|
<td align="right"><a href="https://savannah.nongnu.org/projects/avr-libc/"><h2>AVR Libc Development Pages</h2></a></td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td align="center" width="20%"><a href="index.html"><h2>Main Page</h2></a></td>
|
||
|
<td align="center" width="20%"><a href="pages.html"><h2>User Manual</h2></a></td>
|
||
|
<td align="center" width="20%"><a href="modules.html"><h2>Library Reference</h2></a></td>
|
||
|
<td align="center" width="20%"><a href="FAQ.html"><h2>FAQ</h2></a></td>
|
||
|
<td align="center" width="20%"><a href="group__demos.html"><h2>Example Projects</h2></a></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div>
|
||
|
<!--END TITLEAREA-->
|
||
|
<!-- end header part -->
|
||
|
<!-- Generated by Doxygen 1.6.3 -->
|
||
|
<script type="text/javascript"><!--
|
||
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||
|
--></script>
|
||
|
<div class="contents">
|
||
|
<h1><util/crc16.h>: CRC Computations</h1><table border="0" cellpadding="0" cellspacing="0">
|
||
|
<tr><td colspan="2"><h2>Functions</h2></td></tr>
|
||
|
<tr><td class="memItemLeft" align="right" valign="top">static __inline__ <a class="el" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__util__crc.html#ga95371c87f25b0a2497d9cba13190847f">_crc16_update</a> (<a class="el" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a> __crc, <a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> __data)</td></tr>
|
||
|
<tr><td class="memItemLeft" align="right" valign="top">static __inline__ <a class="el" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__util__crc.html#gaca726c22a1900f9bad52594c8846115f">_crc_xmodem_update</a> (<a class="el" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a> __crc, <a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> __data)</td></tr>
|
||
|
<tr><td class="memItemLeft" align="right" valign="top">static __inline__ <a class="el" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__util__crc.html#ga1c1d3ad875310cbc58000e24d981ad20">_crc_ccitt_update</a> (<a class="el" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a> __crc, <a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> __data)</td></tr>
|
||
|
<tr><td class="memItemLeft" align="right" valign="top">static __inline__ <a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__util__crc.html#ga37b2f691ebbd917e36e40b096f78d996">_crc_ibutton_update</a> (<a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> __crc, <a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> __data)</td></tr>
|
||
|
<tr><td class="memItemLeft" align="right" valign="top">static __inline__ <a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__util__crc.html#gab27eaaef6d7fd096bd7d57bf3f9ba083">_crc8_ccitt_update</a> (<a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> __crc, <a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> __data)</td></tr>
|
||
|
</table>
|
||
|
<hr/><a name="_details"></a><h2>Detailed Description</h2>
|
||
|
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <<a class="code" href="crc16_8h.html">util/crc16.h</a>></span>
|
||
|
</pre></div><p>This header file provides a optimized inline functions for calculating cyclic redundancy checks (CRC) using common polynomials.</p>
|
||
|
<dl class="user"><dt><b>References:</b></dt><dd></dd></dl>
|
||
|
<dl class="user"><dt><b></b></dt><dd></dd></dl>
|
||
|
<p>See the Dallas Semiconductor app note 27 for 8051 assembler example and general CRC optimization suggestions. The table on the last page of the app note is the key to understanding these implementations.</p>
|
||
|
<dl class="user"><dt><b></b></dt><dd></dd></dl>
|
||
|
<p>Jack Crenshaw's "Implementing CRCs" article in the January 1992 isue of <em>Embedded</em> <em>Systems</em> <em>Programming</em>. This may be difficult to find, but it explains CRC's in very clear and concise terms. Well worth the effort to obtain a copy.</p>
|
||
|
<p>A typical application would look like:</p>
|
||
|
<div class="fragment"><pre class="fragment"> <span class="comment">// Dallas iButton test vector.</span>
|
||
|
<a class="code" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> serno[] = { 0x02, 0x1c, 0xb8, 0x01, 0, 0, 0, 0xa2 };
|
||
|
|
||
|
<span class="keywordtype">int</span>
|
||
|
checkcrc(<span class="keywordtype">void</span>)
|
||
|
{
|
||
|
<a class="code" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> crc = 0, i;
|
||
|
|
||
|
<span class="keywordflow">for</span> (i = 0; i < <span class="keyword">sizeof</span> serno / <span class="keyword">sizeof</span> serno[0]; i++)
|
||
|
crc = <a class="code" href="group__util__crc.html#ga37b2f691ebbd917e36e40b096f78d996">_crc_ibutton_update</a>(crc, serno[i]);
|
||
|
|
||
|
<span class="keywordflow">return</span> crc; <span class="comment">// must be 0</span>
|
||
|
}
|
||
|
</pre></div> <hr/><h2>Function Documentation</h2>
|
||
|
<a class="anchor" id="ga95371c87f25b0a2497d9cba13190847f"></a><!-- doxytag: member="crc16.h::_crc16_update" ref="ga95371c87f25b0a2497d9cba13190847f" args="(uint16_t __crc, uint8_t __data)" -->
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">static __inline__ <a class="el" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a> _crc16_update </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype"><a class="el" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a> </td>
|
||
|
<td class="paramname"> <em>__crc</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype"><a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> </td>
|
||
|
<td class="paramname"> <em>__data</em></td><td> </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td></td>
|
||
|
<td>)</td>
|
||
|
<td></td><td></td><td><code> [static]</code></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div>
|
||
|
<div class="memdoc">
|
||
|
<p>Optimized CRC-16 calculation.</p>
|
||
|
<p>Polynomial: x^16 + x^15 + x^2 + 1 (0xa001)<br/>
|
||
|
Initial value: 0xffff</p>
|
||
|
<p>This CRC is normally used in disk-drive controllers.</p>
|
||
|
<p>The following is the equivalent functionality written in C.</p>
|
||
|
<div class="fragment"><pre class="fragment"> <a class="code" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a>
|
||
|
crc16_update(<a class="code" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a> crc, <a class="code" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> a)
|
||
|
{
|
||
|
<span class="keywordtype">int</span> i;
|
||
|
|
||
|
crc ^= a;
|
||
|
<span class="keywordflow">for</span> (i = 0; i < 8; ++i)
|
||
|
{
|
||
|
<span class="keywordflow">if</span> (crc & 1)
|
||
|
crc = (crc >> 1) ^ 0xA001;
|
||
|
<span class="keywordflow">else</span>
|
||
|
crc = (crc >> 1);
|
||
|
}
|
||
|
|
||
|
<span class="keywordflow">return</span> crc;
|
||
|
}
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<a class="anchor" id="gab27eaaef6d7fd096bd7d57bf3f9ba083"></a><!-- doxytag: member="crc16.h::_crc8_ccitt_update" ref="gab27eaaef6d7fd096bd7d57bf3f9ba083" args="(uint8_t __crc, uint8_t __data)" -->
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">static __inline__ <a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> _crc8_ccitt_update </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype"><a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> </td>
|
||
|
<td class="paramname"> <em>__crc</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype"><a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> </td>
|
||
|
<td class="paramname"> <em>__data</em></td><td> </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td></td>
|
||
|
<td>)</td>
|
||
|
<td></td><td></td><td><code> [static]</code></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div>
|
||
|
<div class="memdoc">
|
||
|
<p>Optimized CRC-8-CCITT calculation.</p>
|
||
|
<p>Polynomial: x^8 + x^2 + x + 1 (0xE0)<br/>
|
||
|
</p>
|
||
|
<p>For use with simple CRC-8<br/>
|
||
|
Initial value: 0x0</p>
|
||
|
<p>For use with CRC-8-ROHC<br/>
|
||
|
Initial value: 0xff<br/>
|
||
|
Reference: <a href="http://tools.ietf.org/html/rfc3095#section-5.9.1">http://tools.ietf.org/html/rfc3095#section-5.9.1</a></p>
|
||
|
<p>For use with CRC-8-ATM/ITU<br/>
|
||
|
Initial value: 0xff<br/>
|
||
|
Final XOR value: 0x55<br/>
|
||
|
Reference: <a href="http://www.itu.int/rec/T-REC-I.432.1-199902-I/en">http://www.itu.int/rec/T-REC-I.432.1-199902-I/en</a></p>
|
||
|
<p>The C equivalent has been originally written by Dave Hylands. Assembly code is based on _crc_ibutton_update optimization.</p>
|
||
|
<p>The following is the equivalent functionality written in C.</p>
|
||
|
<div class="fragment"><pre class="fragment"> <a class="code" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a>
|
||
|
<a class="code" href="group__util__crc.html#gab27eaaef6d7fd096bd7d57bf3f9ba083">_crc8_ccitt_update</a> (<a class="code" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> inCrc, <a class="code" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> inData)
|
||
|
{
|
||
|
<a class="code" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> i;
|
||
|
<a class="code" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> data;
|
||
|
|
||
|
data = inCrc ^ inData;
|
||
|
|
||
|
<span class="keywordflow">for</span> ( i = 0; i < 8; i++ )
|
||
|
{
|
||
|
<span class="keywordflow">if</span> (( data & 0x80 ) != 0 )
|
||
|
{
|
||
|
data <<= 1;
|
||
|
data ^= 0x07;
|
||
|
}
|
||
|
<span class="keywordflow">else</span>
|
||
|
{
|
||
|
data <<= 1;
|
||
|
}
|
||
|
}
|
||
|
<span class="keywordflow">return</span> data;
|
||
|
}
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<a class="anchor" id="ga1c1d3ad875310cbc58000e24d981ad20"></a><!-- doxytag: member="crc16.h::_crc_ccitt_update" ref="ga1c1d3ad875310cbc58000e24d981ad20" args="(uint16_t __crc, uint8_t __data)" -->
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">static __inline__ <a class="el" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a> _crc_ccitt_update </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype"><a class="el" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a> </td>
|
||
|
<td class="paramname"> <em>__crc</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype"><a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> </td>
|
||
|
<td class="paramname"> <em>__data</em></td><td> </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td></td>
|
||
|
<td>)</td>
|
||
|
<td></td><td></td><td><code> [static]</code></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div>
|
||
|
<div class="memdoc">
|
||
|
<p>Optimized CRC-CCITT calculation.</p>
|
||
|
<p>Polynomial: x^16 + x^12 + x^5 + 1 (0x8408)<br/>
|
||
|
Initial value: 0xffff</p>
|
||
|
<p>This is the CRC used by PPP and IrDA.</p>
|
||
|
<p>See RFC1171 (PPP protocol) and IrDA IrLAP 1.1</p>
|
||
|
<dl class="note"><dt><b>Note:</b></dt><dd>Although the CCITT polynomial is the same as that used by the Xmodem protocol, they are quite different. The difference is in how the bits are shifted through the alorgithm. Xmodem shifts the MSB of the CRC and the input first, while CCITT shifts the LSB of the CRC and the input first.</dd></dl>
|
||
|
<p>The following is the equivalent functionality written in C.</p>
|
||
|
<div class="fragment"><pre class="fragment"> <a class="code" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a>
|
||
|
crc_ccitt_update (<a class="code" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a> crc, <a class="code" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> data)
|
||
|
{
|
||
|
data ^= lo8 (crc);
|
||
|
data ^= data << 4;
|
||
|
|
||
|
<span class="keywordflow">return</span> ((((<a class="code" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a>)data << 8) | hi8 (crc)) ^ (<a class="code" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a>)(data >> 4)
|
||
|
^ ((<a class="code" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a>)data << 3));
|
||
|
}
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<a class="anchor" id="ga37b2f691ebbd917e36e40b096f78d996"></a><!-- doxytag: member="crc16.h::_crc_ibutton_update" ref="ga37b2f691ebbd917e36e40b096f78d996" args="(uint8_t __crc, uint8_t __data)" -->
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">static __inline__ <a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> _crc_ibutton_update </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype"><a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> </td>
|
||
|
<td class="paramname"> <em>__crc</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype"><a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> </td>
|
||
|
<td class="paramname"> <em>__data</em></td><td> </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td></td>
|
||
|
<td>)</td>
|
||
|
<td></td><td></td><td><code> [static]</code></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div>
|
||
|
<div class="memdoc">
|
||
|
<p>Optimized Dallas (now Maxim) iButton 8-bit CRC calculation.</p>
|
||
|
<p>Polynomial: x^8 + x^5 + x^4 + 1 (0x8C)<br/>
|
||
|
Initial value: 0x0</p>
|
||
|
<p>See <a href="http://www.maxim-ic.com/appnotes.cfm/appnote_number/27">http://www.maxim-ic.com/appnotes.cfm/appnote_number/27</a></p>
|
||
|
<p>The following is the equivalent functionality written in C.</p>
|
||
|
<div class="fragment"><pre class="fragment"> <a class="code" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a>
|
||
|
<a class="code" href="group__util__crc.html#ga37b2f691ebbd917e36e40b096f78d996">_crc_ibutton_update</a>(<a class="code" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> crc, <a class="code" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> data)
|
||
|
{
|
||
|
<a class="code" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> i;
|
||
|
|
||
|
crc = crc ^ data;
|
||
|
<span class="keywordflow">for</span> (i = 0; i < 8; i++)
|
||
|
{
|
||
|
<span class="keywordflow">if</span> (crc & 0x01)
|
||
|
crc = (crc >> 1) ^ 0x8C;
|
||
|
<span class="keywordflow">else</span>
|
||
|
crc >>= 1;
|
||
|
}
|
||
|
|
||
|
<span class="keywordflow">return</span> crc;
|
||
|
}
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<a class="anchor" id="gaca726c22a1900f9bad52594c8846115f"></a><!-- doxytag: member="crc16.h::_crc_xmodem_update" ref="gaca726c22a1900f9bad52594c8846115f" args="(uint16_t __crc, uint8_t __data)" -->
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">static __inline__ <a class="el" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a> _crc_xmodem_update </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype"><a class="el" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a> </td>
|
||
|
<td class="paramname"> <em>__crc</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype"><a class="el" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> </td>
|
||
|
<td class="paramname"> <em>__data</em></td><td> </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td></td>
|
||
|
<td>)</td>
|
||
|
<td></td><td></td><td><code> [static]</code></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div>
|
||
|
<div class="memdoc">
|
||
|
<p>Optimized CRC-XMODEM calculation.</p>
|
||
|
<p>Polynomial: x^16 + x^12 + x^5 + 1 (0x1021)<br/>
|
||
|
Initial value: 0x0</p>
|
||
|
<p>This is the CRC used by the Xmodem-CRC protocol.</p>
|
||
|
<p>The following is the equivalent functionality written in C.</p>
|
||
|
<div class="fragment"><pre class="fragment"> <a class="code" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a>
|
||
|
crc_xmodem_update (<a class="code" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a> crc, <a class="code" href="group__avr__stdint.html#gaba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> data)
|
||
|
{
|
||
|
<span class="keywordtype">int</span> i;
|
||
|
|
||
|
crc = crc ^ ((<a class="code" href="group__avr__stdint.html#ga1f1825b69244eb3ad2c7165ddc99c956">uint16_t</a>)data << 8);
|
||
|
<span class="keywordflow">for</span> (i=0; i<8; i++)
|
||
|
{
|
||
|
<span class="keywordflow">if</span> (crc & 0x8000)
|
||
|
crc = (crc << 1) ^ 0x1021;
|
||
|
<span class="keywordflow">else</span>
|
||
|
crc <<= 1;
|
||
|
}
|
||
|
|
||
|
<span class="keywordflow">return</span> crc;
|
||
|
}
|
||
|
</pre></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<!--- window showing the filter options -->
|
||
|
<div id="MSearchSelectWindow"
|
||
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
||
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
||
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
||
|
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Defines</a></div>
|
||
|
|
||
|
<!-- iframe showing the search results (closed by default) -->
|
||
|
<div id="MSearchResultsWindow">
|
||
|
<iframe src="" frameborder="0"
|
||
|
name="MSearchResults" id="MSearchResults">
|
||
|
</iframe>
|
||
|
</div>
|
||
|
|
||
|
<!-- HTML footer for doxygen 1.8.7-->
|
||
|
<!-- start footer part -->
|
||
|
<!--BEGIN GENERATE_TREEVIEW-->
|
||
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
||
|
<ul>
|
||
|
$navpath
|
||
|
<li class="footer">$generatedby
|
||
|
<a href="http://www.doxygen.org/index.html">
|
||
|
<img class="footer" src="$relpath^doxygen.png" alt="doxygen"/></a> 1.6.3 </li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
<!--END GENERATE_TREEVIEW-->
|
||
|
<!--BEGIN !GENERATE_TREEVIEW-->
|
||
|
<hr class="footer"/><address class="footer"><small>
|
||
|
$generatedby  <a href="http://www.doxygen.org/index.html">
|
||
|
<img class="footer" src="$relpath^doxygen.png" alt="doxygen"/>
|
||
|
</a> 1.6.3
|
||
|
</small></address>
|
||
|
<!--END !GENERATE_TREEVIEW-->
|
||
|
</body>
|
||
|
</html>
|