utility.c
Go to the documentation of this file.00001
00014 #include <includes.h>
00015
00016 #ifndef __VERSION_0_1__
00017 #warning RangerOS mismatch, expected v0.1.
00018 #endif
00019
00020
00026 fixed float_to_fixed(float m){
00027 return ((fixed)((m) * FIXED_ONE));
00028 }
00034 fixed int_to_fixed(int m){
00035 return ((fixed)(m<<16));
00036 }
00042 float fixed_to_float(fixed m){
00043 return ((float)m*FIXED_FLOAT);
00044 }
00051 int fixed_to_int(fixed m){
00052 return (((fixed)(m))>>16);
00053 }
00060 fixed fixed_mult(fixed a, fixed b){
00061 return ((fixed)((((long long int)a)*((long long int)b))>>16));
00062 }
00071 long long int fixed_mult_to_long(fixed a, fixed b){
00072 return (((((long long int)a)*((long long int)b))>>16));
00073 }
00084 fixed linear_to_fixed(int offset, float coeff, int value){
00085 int a, b, c, d, e;
00086 a = value;
00087 b = a - offset;
00088 c = -1 * int_to_fixed(b);
00089 d = float_to_fixed(coeff);
00090 e = fixed_mult(c,d);
00091 return e;
00092 }
00098 fixed fixed_abs(fixed f){
00099 if (f < 0){return -f;}
00100 else{return f;}
00101 }
00102
00103
00104
00109 void voidvoid(void){error_occurred(ERROR_UTIL_DUMMY);}
00111 void voidvoid_noerror(void){;}
00117 void voidint(int a){error_occurred(ERROR_UTIL_DUMMY);}
00119 void voidint_noerror(int a){;}
00124 float floatvoid(void){error_occurred(ERROR_UTIL_DUMMY);return 0.0;}
00126 float floatvoid_noerror(void){return 0.0;}
00131 int intvoid(void){error_occurred(ERROR_UTIL_DUMMY);return 0;}
00133 int intvoid_noerror(void){return 0;}
00134
00135
00136 int tt_time = 0;
00137 VOID_INT_F tt_print = voidint;
00144 void tic_toc_init(VOID_INT_F print_f){
00145 tt_print = print_f;
00146 }
00151 void tic(void){
00152 tt_time = T0TC;
00153 }
00160 void toc(void){
00161 tt_time = (T0TC - tt_time);
00162 tt_print(tt_time);
00163 tt_time = 0;
00164 }
00165