• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

Util.c

Go to the documentation of this file.
00001 /****************** COPYRIGHT (C) 2007-2010 RAISONANCE S.A.S. *****************/
00012 /******************************************************************************/
00013 
00014 /* Includes ------------------------------------------------------------------*/
00015 #include "circle.h"
00016 
00018 
00019 /* Private defines -----------------------------------------------------------*/
00020 
00021 /* Private typedef -----------------------------------------------------------*/
00022 enum eSpeed CurrentSpeed;
00023 
00024 /* Private variables ---------------------------------------------------------*/
00025 bool fTemperatureInFahrenheit = 0;  
00027 /* Private function prototypes -----------------------------------------------*/
00028 static void _int2str( u8* ptr, int_t X, len_t digit, bool flagunsigned, bool fillwithzero );
00029 
00030 /* Private functions ---------------------------------------------------------*/
00031 /*******************************************************************************
00032 *
00033 *                                vbattoa
00034 *
00035 *******************************************************************************/
00046 /******************************************************************************/
00047 NODEBUG2 void vbattoa( u8* ptr, u16 X )
00048 {
00049     u8 c;
00050     u16 r = 0;
00051 
00052     /* 1 000 digit*/
00053     c = ( ( X - r ) / 1000 );
00054     r = r + ( c * 1000 );
00055     *ptr++ = c + 0x30;
00056 
00057     /* Dot*/
00058     *ptr++ = '.';
00059 
00060     /* 100 digit*/
00061     c = ( ( X - r ) / 100 );
00062     r = r + ( c * 100 );
00063     *ptr++ = c + 0x30;
00064 
00065     /* 10 digit*/
00066     c = ( ( X - r ) / 10 );
00067     r = r + ( c * 10 );
00068     *ptr++ = c + 0x30;
00069 
00070     /* Volt*/
00071     *ptr++ = 'V';
00072     *ptr++ = 0;
00073 }
00074 
00075 /*******************************************************************************
00076 *
00077 *                    _int2str
00078 *
00079 *******************************************************************************/
00092 /******************************************************************************/
00093 NODEBUG2 static void _int2str( u8* ptr, int_t X, len_t digit, bool flagunsigned, bool fillwithzero )
00094 {
00095     u8      c;
00096     bool    fFirst   = 0;
00097     bool    fNeg     = 0;
00098     uint_t  DIG      = 1;
00099     len_t   i;
00100     int_t   r;
00101 
00102     for ( i = 1; i < digit; i++ )
00103     {
00104         DIG *= 10;
00105     }
00106 
00107     if ( !flagunsigned && ( X < 0 ) )
00108     {
00109         fNeg = 1;
00110         r    = -X;
00111     }
00112     else
00113     {
00114         r = X;
00115     }
00116 
00117     for ( i = 0; i < digit; i++, DIG /= 10 )
00118     {
00119         c  = ( r / DIG );
00120         r -= ( c * DIG );
00121 
00122         if ( fillwithzero || fFirst || c || ( i == ( digit - 1 ) ) )
00123         {
00124             if ( ( fFirst == 0 ) && !flagunsigned )
00125             {
00126                 *ptr++ = fNeg ? '-' : ' ';
00127             }
00128 
00129             *ptr++ = ( c % 10 ) + '0';
00130             fFirst = 1;
00131         }
00132         else
00133         {
00134             *ptr++ = ' ';
00135         }
00136     }
00137 
00138     *ptr++ = '\0';
00139 }
00140 
00141 /* Public functions for CircleOS ---------------------------------------------*/
00142 
00143 
00145 
00146 /* Public functions ----------------------------------------------------------*/
00147 
00148 /*******************************************************************************
00149 *
00150 *                    UTIL_SetTempMode
00151 *
00152 *******************************************************************************/
00160 /******************************************************************************/
00161 void UTIL_SetTempMode( bool mode )
00162 {
00163     fTemperatureInFahrenheit = mode;
00164 
00165     return;
00166 }
00167 
00168 /*******************************************************************************
00169 *
00170 *                   UTIL_uint2str
00171 *
00172 *******************************************************************************/
00186 /********************************************************************************/
00187 void UTIL_uint2str( u8* ptr, uint_t X, len_t digit, bool fillwithzero )
00188 {
00189     _int2str( ptr, X, digit, 1, fillwithzero );
00190 }
00191 
00192 /*******************************************************************************
00193 *
00194 *                   UTIL_int2str
00195 *
00196 *******************************************************************************/
00210 /******************************************************************************/
00211 void UTIL_int2str( u8* ptr, int_t X, len_t digit, bool fillwithzero )
00212 {
00213     _int2str( ptr, X, digit, 0, fillwithzero );
00214 }
00215 
00216 /*******************************************************************************
00217 *
00218 *                                UTIL_GetPll
00219 *
00220 *******************************************************************************/
00228 /******************************************************************************/
00229 enum eSpeed UTIL_GetPll( void )
00230 {
00231     return CurrentSpeed;
00232 }
00233 
00234 /*******************************************************************************
00235 *
00236 *                                UTIL_GetVersion
00237 *
00238 *******************************************************************************/
00246 /******************************************************************************/
00247 const u8* UTIL_GetVersion( void )
00248 {
00249     return STR_OSVERSION;
00250 }
00251 
00252 
00253 /*******************************************************************************
00254 *
00255 *                                UTIL_SetSchHandler
00256 *
00257 *******************************************************************************/
00272 /********************************************************************************/
00273 void UTIL_SetSchHandler( enum eSchHandler Ix, tHandler pHDL )
00274 {
00275     if ( Ix < COUNTOF( SchHandler ) )
00276         SchHandler[Ix] = pHDL;
00277 }
00278 
00279 /*******************************************************************************
00280 *
00281 *                                UTIL_GetSchHandler
00282 *
00283 *******************************************************************************/
00297 /********************************************************************************/
00298 tHandler UTIL_GetSchHandler( enum eSchHandler Ix )
00299 {
00300     if ( Ix < COUNTOF( SchHandler ) )
00301         return SchHandler[Ix];
00302     else
00303         return 0;
00304 }
00305 
00306 /*******************************************************************************
00307 *
00308 *                                UTIL_IsStandAloneMode
00309 *
00310 *******************************************************************************/
00319 /********************************************************************************/
00320 bool UTIL_IsStandAloneMode( void )
00321 {
00322     return fIsStandAlone;
00323 }