00001
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
00046
00081 #ifndef __DSP_TYPES_H__
00082 #define __DSP_TYPES_H__
00083
00084
00085 #if (defined __ICCAVR32__)
00086 # include <intrinsics.h>
00087 #endif
00088 #include "compiler.h"
00089 #include "preprocessor.h"
00090
00091
00092 #ifdef __AVR32_ABI_COMPILER__
00093
00094 #if __ICCAVR32__
00095
00100
00101 #ifndef __asm__
00102 # define __asm__ asm
00103 #endif
00104 #ifndef __inline__
00105 # define __inline__ inline
00106 #endif
00107 #ifndef __volatile__
00108 # define __volatile__
00109 #endif
00111
00112 #endif
00113
00114 #if (defined __GNUC__)
00116 # define A_ALIGNED __attribute__ ((aligned(4)))
00118 # define A_PACKED __attribute__ ((__packed__))
00119 #elif __ICCAVR32__
00121 # define A_ALIGNED _Pragma("data_alignment=4")
00123 # define A_PACKED
00124 #else
00125 # error Unknown compiler
00126 #endif
00127
00128 #endif // __AVR32_ABI_COMPILER__
00129
00135
00136 #ifndef DSP16_FORMAT
00137
00140 # define DSP16_QA 1
00141
00144 # define DSP16_QB 15
00145 #else
00146
00149 # define DSP16_QA (16 - DSP16_FORMAT)
00150
00153 # define DSP16_QB DSP16_FORMAT
00154 #endif
00156 #if (DSP16_QA + DSP16_QB) != 16
00157 # error in the definition of the 16-bit type. The sum of the "Q format" coefficients should be 16.
00158 #endif
00159
00165
00166 #ifndef DSP32_FORMAT
00167
00170 # define DSP32_QA 1
00171
00174 # define DSP32_QB 31
00175 #else
00176
00179 # define DSP32_QA (32 - DSP32_FORMAT)
00180
00183 # define DSP32_QB DSP32_FORMAT
00184 #endif
00186 #if (DSP32_QA + DSP32_QB) != 32
00187 # error in the definition of the 32-bit type. The sum of the "Q format" coefficients should be 32.
00188 #endif
00189
00190 #ifdef __AVR32_ABI_COMPILER__
00191
00195 #define dsp16_t__ S16
00196
00199 typedef dsp16_t__ dsp16_t;
00200
00204 #define dsp32_t__ S32
00205
00208 typedef dsp32_t__ dsp32_t;
00209
00213 #if __ICCAVR32__
00214 # pragma pack(1)
00215 #endif
00216 typedef struct A_PACKED dsp16_complex_t
00217 {
00219 dsp16_t__ real;
00221 dsp16_t__ imag;
00222 }dsp16_complex_t;
00223 #if __ICCAVR32__
00224 # pragma pack()
00225 #endif
00226
00230 #if __ICCAVR32__
00231 # pragma pack(1)
00232 #endif
00233 typedef struct A_PACKED dsp32_complex_t
00234 {
00236 dsp32_t__ real;
00238 dsp32_t__ imag;
00239 }dsp32_complex_t;
00240 #if __ICCAVR32__
00241 # pragma pack()
00242 #endif
00243
00244 #endif // __AVR32_ABI_COMPILER__
00245
00248
00249
00252 #define DSP_FP_MAX(a, b) (((float) (1 << ((a)-1))) - DSP_FP_RES(a, b))
00253
00256 #define DSP_FP_MIN(a, b) (-((float) (1 << ((a)-1))))
00258
00259
00261
00262
00265 #define DSP_Q_MAX(a, b) ((S32) (((U32) -1) >> (32 - ((a)+(b)-1))))
00266
00269 #define DSP_Q_MIN(a, b) ((S32) ((-1) << ((a)+(b)-1)))
00271
00272
00274
00275
00278 #define DSP_FP_RES(a, b) (1./((unsigned) (1 << (b))))
00280
00281
00284
00285
00288 #define DSP_Q(a, b, fnum) (((fnum) >= DSP_FP_MAX(a, b) - DSP_FP_RES(a, b))?\
00289 DSP_Q_MAX(a, b):\
00290 (((fnum) <= DSP_FP_MIN(a, b) + DSP_FP_RES(a, b))?\
00291 DSP_Q_MIN(a, b):\
00292 (((fnum)*(((unsigned) (1 << (b))))))))
00293
00297 #define DSP16_Q(fnum) ((dsp16_t__) DSP_Q(DSP16_QA, DSP16_QB, fnum))
00298
00301 #define DSP32_Q(fnum) ((dsp32_t__) DSP_Q(DSP32_QA, DSP32_QB, fnum))
00303
00304
00305
00306
00307
00308 #ifndef FALSE
00309
00312 # define FALSE 0
00313 #endif
00314 #ifndef TRUE
00315
00318 # define TRUE 1
00319 #endif
00320
00323 #define CST_PI 3.141592653589793238462643383279502884197
00324
00327 #define CST_E 2.718281828459045235360287471352662497757
00328
00332 #define CST_SQUARE_ROOT_2 1.4142135623730950488016887242097
00333
00336 #define CST_INV_SQUARE_ROOT_2 0.70710678118654752440084436210485
00337
00340 #define CST_LN_2 0.69314718055994530941723212145818
00341
00344 #define CST_LN_10 2.3025850929940456840179914546844
00345
00349 #define DSP16_PI_DIV_4 DSP16_Q(CST_PI/4.)
00350
00353 #define DSP32_PI_DIV_4 DSP32_Q(CST_PI/4.)
00354
00355 #endif //__DSP_TYPES_H__