00001
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include "dsp.h"
00046 #include "dsp_debug.h"
00047 #include "dsp_debug_shared.h"
00048
00050 char dsp_debug_buffer[DSP_DEBUG_BUFFER_SIZE];
00051
00052 char *dsp_debug_print_ui(unsigned int n);
00053 char *dsp_debug_print_si(int n);
00054
00055
00056 void dsp_debug_print_fct(char *str)
00057 {
00058 while(*str)
00059 dsp_debug_write_fct(*str++);
00060 }
00061
00062
00063 char *dsp_debug_print_ui(unsigned int n)
00064 {
00065 int i = sizeof(dsp_debug_buffer)-1;
00066
00067
00068 dsp_debug_buffer[i] = '\0';
00069 do
00070 {
00071
00072 dsp_debug_buffer[--i] = '0' + n%10;
00073
00074 n /= 10;
00075
00076 }while(n);
00077
00078
00079 return &dsp_debug_buffer[i];
00080 }
00081
00082
00083 char *dsp_debug_print_si(int n)
00084 {
00085 char *pdsp_debug_buffer;
00086
00087
00088 if (n < 0)
00089 {
00090
00091 pdsp_debug_buffer = dsp_debug_print_ui((unsigned int) (-n));
00092
00093 pdsp_debug_buffer--;
00094 *pdsp_debug_buffer = '-';
00095 }
00096
00097 else
00098
00099 pdsp_debug_buffer = dsp_debug_print_ui((unsigned int) n);
00100
00101 return pdsp_debug_buffer;
00102 }
00103
00104
00105 void dsp_debug_initialization__(char *date, char *time, int fosc)
00106 {
00107
00108 dsp_debug_init(fosc);
00109 }
00110
00111
00112 void dsp16_debug_print(dsp16_t n)
00113 {
00114 dsp_debug_print(16, DSP16_QA, (int) n);
00115 }
00116
00117
00118 void dsp32_debug_print(dsp32_t n)
00119 {
00120 dsp_debug_print(32, DSP32_QA, (int) n);
00121 }
00122
00123
00124 void dsp16_debug_print_complex(dsp16_complex_t *n)
00125 {
00126 dsp_debug_print_complex(16, DSP16_QA, n->real, n->imag);
00127 }
00128
00129
00130 void dsp32_debug_print_complex(dsp32_complex_t *n)
00131 {
00132 dsp_debug_print_complex(32, DSP32_QA, n->real, n->imag);
00133 }
00134
00135
00136 void dsp16_debug_print_vect(dsp16_t *vect, int size)
00137 {
00138 int i;
00139 char *pdsp_debug_buffer;
00140
00141
00142 for(i=0; i<size; i++)
00143 {
00144
00145 pdsp_debug_buffer = dsp_debug_print_ui(i+1);
00146 dsp_debug_print_fct(pdsp_debug_buffer);
00147 dsp_debug_print_fct("\t");
00148
00149 dsp16_debug_print(vect[i]);
00150 dsp_debug_print_fct("\n");
00151 }
00152 }
00153
00154
00155 void dsp32_debug_print_vect(dsp32_t *vect, int size)
00156 {
00157 int i;
00158 char *pdsp_debug_buffer;
00159
00160
00161 for(i=0; i<size; i++)
00162 {
00163
00164 pdsp_debug_buffer = dsp_debug_print_ui(i+1);
00165 dsp_debug_print_fct(pdsp_debug_buffer);
00166 dsp_debug_print_fct("\t");
00167
00168 dsp32_debug_print(vect[i]);
00169 dsp_debug_print_fct("\n");
00170 }
00171 }
00172
00173
00174 void dsp16_debug_print_complex_vect(dsp16_complex_t *vect, int size)
00175 {
00176 int i;
00177 char *pdsp_debug_buffer;
00178
00179
00180 for(i=0; i<size; i++)
00181 {
00182
00183 pdsp_debug_buffer = dsp_debug_print_ui(i+1);
00184 dsp_debug_print_fct(pdsp_debug_buffer);
00185 dsp_debug_print_fct("\t");
00186
00187 dsp16_debug_print_complex(&vect[i]);
00188 dsp_debug_print_fct("\n");
00189 }
00190 }
00191
00192
00193 void dsp32_debug_print_complex_vect(dsp32_complex_t *vect, int size)
00194 {
00195 int i;
00196 char *pdsp_debug_buffer;
00197
00198
00199 for(i=0; i<size; i++)
00200 {
00201
00202 pdsp_debug_buffer = dsp_debug_print_ui(i+1);
00203 dsp_debug_print_fct(pdsp_debug_buffer);
00204 dsp_debug_print_fct("\t");
00205
00206 dsp32_debug_print_complex(&vect[i]);
00207 dsp_debug_print_fct("\n");
00208 }
00209 }
00210
00211
00212 int dsp_debug_sprint_after_radix(char **out, unsigned int num, unsigned int den, int nb_digits)
00213 {
00214 unsigned int i;
00215 char temp[2];
00216 int n = 0;
00217
00218 temp[1] = '\0';
00219
00220
00221 i = num/den;
00222 num -= i*den;
00223
00224
00225 while(nb_digits-- && num)
00226 {
00227
00228
00229
00230 if (num <= 0xFFFFFFFF/10)
00231 num *= 10;
00232 else
00233 den /= 10;
00234
00235
00236 i = num/den;
00237
00238 if (i > 9)
00239 i = 9;
00240
00241
00242 temp[0] = (char) i + '0';
00243 n += dsp_debug_sprint_fct(out, temp);
00244
00245 num -= i*den;
00246 }
00247
00248
00249 **out = '\0';
00250
00251 return n;
00252 }
00253
00254
00255
00256
00257 void dsp_debug_print_complex(int nb_bits, int q, int real, int imag)
00258 {
00259
00260 dsp_debug_print(nb_bits, q, real);
00261 dsp_debug_print_fct(" + ");
00262
00263 dsp_debug_print(nb_bits, q, imag);
00264 dsp_debug_print_fct("i");
00265 }
00266
00267
00268 int dsp_debug_sprint_fct(char **out, char *str)
00269 {
00270 int n = 0;
00271
00272
00273 while(*str)
00274 {
00275 n++;
00276 *(*out)++ = *str++;
00277 }
00278 **out = '\0';
00279
00280
00281 return n;
00282 }
00283
00284
00285 int dsp_debug_sprint(char **out, int nb_bits, int q, int i)
00286 {
00287 int range;
00288 int n = 0;
00289 char *pdsp_debug_buffer;
00290
00291 int precision[33] = { 0 , 2, 2, 2, 3, 3 , 3, 3, 4, 4, 5 , 5, 5, 5, 6, 6 , 6,
00292 7, 7, 7, 8 , 8, 8, 9, 9, 9 , 10, 10, 10, 11, 11 , 11, 12 };
00293
00294
00295 if (i < 0)
00296 {
00297
00298 if (i == 0x80000000)
00299 {
00300 i = 0;
00301 range = 1;
00302 }
00303 else
00304 {
00305
00306 i = -i;
00307
00308 range = i >> (nb_bits-q);
00309 }
00310
00311 n += dsp_debug_sprint_fct(out, "-");
00312 }
00313 else
00314
00315 range = i >> (nb_bits-q);
00316
00317
00318 pdsp_debug_buffer = dsp_debug_print_ui(range);
00319 n += dsp_debug_sprint_fct(out, pdsp_debug_buffer);
00320
00321 n += dsp_debug_sprint_fct(out, ".");
00322
00323 n += dsp_debug_sprint_after_radix(out, i, 1 << (nb_bits-q), precision[nb_bits-q]);
00324
00325
00326 return n;
00327 }
00328
00329
00330 void dsp_debug_print(int nb_bits, int q, int n)
00331 {
00332 char *pdsp_debug_buffer;
00333
00334
00335 pdsp_debug_buffer = dsp_debug_buffer;
00336
00337 dsp_debug_sprint(&pdsp_debug_buffer, nb_bits, q, n);
00338
00339 dsp_debug_print_fct(dsp_debug_buffer);
00340 }
00341
00342