00001 /****************************************************************************** 00002 ** Copyright (C) 2007 Pablo Garcia 00003 ** 00004 ** This library is free software; you can redistribute it and/or 00005 ** modify it under the terms of the GNU Lesser General Public 00006 ** License as published by the Free Software Foundation; either 00007 ** version 2.1 of the License, or (at your option) any later version. 00008 00009 ** This library is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 ** Lesser General Public License for more details. 00013 00014 ** You should have received a copy of the GNU Lesser General Public 00015 ** License along with this library; if not, write to the Free Software 00016 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00017 ******************************************************************************/ 00018 00029 //----------------------------------------------------------------------------- 00030 // Define 00031 //----------------------------------------------------------------------------- 00032 00033 #ifndef UTILS_H 00034 #define UTILS_H 00035 00036 // ---------------------------------------------------------------------------- 00037 // Includes 00038 // ---------------------------------------------------------------------------- 00039 00040 #include "IQConstants.h" 00041 00042 00043 //----------------------------------------------------------------------------- 00044 // MACROS declaration 00045 //----------------------------------------------------------------------------- 00046 00047 #ifdef MAX 00048 #undef MAX 00049 #endif 00050 #ifdef MIN 00051 #undef MIN 00052 #endif 00053 #ifdef ABS 00054 #undef ABS 00055 #endif 00056 00057 #define MAX(A, B) ((A) >= (B) ? (A) : (B)) 00058 00059 #define MIN(A, B) ((A) <= (B) ? (A) : (B)) 00060 00061 00063 #define ABS(C) ((C) >= (0) ? (C) : (-C)) 00064 00065 #define LIM(A,L) (A)=MIN(MAX(A,-L),L) 00066 00067 #define WRAPSUP(A,ANG) ((A) > (ANG) ? (A-_IQmpy(ANG,2)) : (A)) 00068 00069 #define WRAPINF(A,ANG) ((A) < (ANG) ? (A+_IQmpy(ANG,2)) : (A)) 00070 00071 #define WRAP(A,ANG) (A) = WRAPINF(WRAPSUP(A,ANG),-ANG) 00072 00074 #define WRAPSUP2PI(A) ((A) > (PI) ? (A-TWOPI) : (A)) 00075 00076 #define WRAPINF2PI(A) ((A) < (-PI) ? (A+TWOPI) : (A)) 00077 00078 #define WRAP2PI(A) (A) = WRAPINF2PI(WRAPSUP2PI(A)) 00079 00080 //----------------------------------------------------------------------------- 00081 // Implemented Functions 00082 //----------------------------------------------------------------------------- 00083 static inline _iq GetMax(volatile _iq* a, volatile _iq* b, volatile _iq** ptrMax); 00084 static inline _iq GetMin(volatile _iq* a, volatile _iq* b, volatile _iq** ptrMin); 00085 00086 //----------------------------------------------------------------------------- 00087 // Inline function implementation 00088 //----------------------------------------------------------------------------- 00089 00097 static inline _iq GetMax(volatile _iq* a, volatile _iq* b, volatile _iq** ptrMax) 00098 { 00099 _iq c; 00100 if(*a >= *b) { 00101 c = *a; 00102 *ptrMax = a; 00103 } 00104 else{ 00105 c = *b; 00106 *ptrMax = b; 00107 } 00108 return c; 00109 } 00110 00111 //----------------------------------------------------------------------------- 00112 00118 static inline _iq GetMin(volatile _iq* a,volatile _iq* b, volatile _iq** ptrMin) 00119 { 00120 _iq c; 00121 if(*a <= *b) { 00122 c = *a; 00123 *ptrMin = a; 00124 } 00125 else{ 00126 c = *b; 00127 *ptrMin = b; 00128 } 00129 return c; 00130 } 00131 00132 //----------------------------------------------------------------------------- 00133 00134 #endif 00135 00136 //----------------------------------------------------------------------------- 00137 // End Of File 00138 //-----------------------------------------------------------------------------