?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{FILE START}

library

?curdirlinks? - Rev 6

?prevdifflink? - Blame - ?getfile?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Procyon AVRlib: fixedpt.c Source File</title>
<link href="dox.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.2 -->
<div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<h1>fixedpt.c</h1><a href="fixedpt_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file fixedpt.c \brief Fixed-point math function library. */</span>
00002 <span class="comment">//*****************************************************************************</span>
00003 <span class="comment">//</span>
00004 <span class="comment">// File Name    : 'fixedpt.c'</span>
00005 <span class="comment">// Title        : Fixed-point math function library</span>
00006 <span class="comment">// Author       : Pascal Stang - Copyright (C) 2003</span>
00007 <span class="comment">// Created      : 2003.01.26</span>
00008 <span class="comment">// Revised      : 2003.02.02</span>
00009 <span class="comment">// Version      : 0.1</span>
00010 <span class="comment">// Target MCU   : Atmel AVR Series</span>
00011 <span class="comment">// Editor Tabs  : 4</span>
00012 <span class="comment">//</span>
00013 <span class="comment">// NOTE: This code is currently below version 1.0, and therefore is considered</span>
00014 <span class="comment">// to be lacking in some functionality or documentation, or may not be fully</span>
00015 <span class="comment">// tested.  Nonetheless, you can expect most functions to work.</span>
00016 <span class="comment">//</span>
00017 <span class="comment">// This code is distributed under the GNU Public License</span>
00018 <span class="comment">//      which can be found at http://www.gnu.org/licenses/gpl.txt</span>
00019 <span class="comment">//</span>
00020 <span class="comment">//*****************************************************************************</span>
00021 
00022 
00023 <span class="preprocessor">#include "<a class="code" href="fixedpt_8h.html">fixedpt.h</a>"</span>
00024 
00025 <span class="comment">// Program ROM constants</span>
00026 
00027 <span class="comment">// Global variables</span>
00028 u08 FixedPtBits;
00029 
00030 <span class="comment">// Functions</span>
00031 
00032 <span class="comment">// fixedptInit() initializes fixed-point math function library</span>
<a name="l00033"></a><a class="code" href="fixedpt_8h.html#a0">00033</a> <span class="keywordtype">void</span> <a class="code" href="fixedpt_8c.html#a1">fixedptInit</a>(u08 fixedPtBits)
00034 {
00035     <span class="comment">// set the number of bits to use behind the point</span>
00036     FixedPtBits = fixedPtBits;
00037 }
00038 
<a name="l00039"></a><a class="code" href="fixedpt_8h.html#a1">00039</a> s32 <a class="code" href="fixedpt_8c.html#a2">fixedptConvertFromInt</a>(s32 int_number)
00040 {
00041     <span class="comment">// convert integer to fixed-point number</span>
00042     <span class="keywordflow">return</span> (int_number&lt;&lt;FixedPtBits);
00043 }
00044 
<a name="l00045"></a><a class="code" href="fixedpt_8h.html#a2">00045</a> s32 <a class="code" href="fixedpt_8c.html#a3">fixedptConvertToInt</a>(s32 fp_number)
00046 {
00047     <span class="comment">// convert fixed-point number to integer</span>
00048     <span class="comment">// do rounding</span>
00049     <span class="keywordflow">if</span>( fp_number &amp; 1&lt;&lt;(FixedPtBits-1) )
00050     {
00051         <span class="comment">// bit behind the point was a '1'</span>
00052         <span class="comment">// round up to next higher integer</span>
00053         <span class="keywordflow">return</span> (fp_number&gt;&gt;FixedPtBits)+1;
00054     }
00055     <span class="keywordflow">else</span>
00056     {
00057         <span class="comment">// bit behind the point was a '0'</span>
00058         <span class="comment">// round down (truncate) to next lower integer</span>
00059         <span class="keywordflow">return</span> (fp_number&gt;&gt;FixedPtBits);
00060     }
00061 }
00062 
<a name="l00063"></a><a class="code" href="fixedpt_8h.html#a3">00063</a> s32 <a class="code" href="fixedpt_8c.html#a4">fixedptAdd</a>(s32 a, s32 b)
00064 {
00065     <span class="comment">// add a and b (a+b) with fixed-point math</span>
00066     <span class="keywordflow">return</span> a+b;
00067 }
00068 
<a name="l00069"></a><a class="code" href="fixedpt_8h.html#a4">00069</a> s32 <a class="code" href="fixedpt_8c.html#a5">fixedptSubtract</a>(s32 a, s32 b)
00070 {
00071     <span class="comment">// subtract a and b (a-b) with fixed-point math</span>
00072     <span class="keywordflow">return</span> a-b;
00073 }
00074 
<a name="l00075"></a><a class="code" href="fixedpt_8h.html#a5">00075</a> s32 <a class="code" href="fixedpt_8c.html#a6">fixedptMultiply</a>(s32 a, s32 b)
00076 {
00077     <span class="comment">// multiply a and b (a*b) with fixed-point math</span>
00078     <span class="keywordflow">return</span> (a*b)&gt;&gt;FixedPtBits;
00079 }
00080 
<a name="l00081"></a><a class="code" href="fixedpt_8h.html#a6">00081</a> s32 <a class="code" href="fixedpt_8c.html#a7">fixedptDivide</a>(s32 numer, s32 denom)
00082 {
00083     <span class="comment">// divide numer by denom (numer/denom) with fixed-point math</span>
00084     <span class="keywordflow">return</span> (numer&lt;&lt;FixedPtBits)/denom;
00085 }
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:06 2006 for Procyon AVRlib by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
</body>
</html>
{FILE END}
{FOOTER START}

Powered by WebSVN v2.8.3