00001 #ifndef __MK_dsp_H___
00002 #define __MK_dsp_H___
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef DSP_H
00011 #define DSP_H
00012
00013 #include "MKDSPDefines.h"
00014
00015 #define DSP_SYS_VER_C 65
00016 #define DSP_SYS_REV_C 41
00017
00018
00019 #define DSP_PLI_USR_C 0x96
00020
00021 #define DSPMK_I_NTICK 0x10
00022
00023 #define DSP_EXT_RAM_SIZE_MIN 8192
00024 #define DSP_CLOCK_RATE (25.0E6)
00025 #define DSP_CLOCK_PERIOD (40.0E-9)
00026
00027 #import "dsp_types.h"
00028
00029
00030
00031
00032 #define DSP_WORD_MASK 0x00FFFFFF
00033 #define DSP_SOUND_MASK 0x0000FFFF
00034 #define DSP_ADDRESS_MASK 0x0000FFFF
00035
00036
00037
00038 #define DSP_ICR 0
00039 #define DSP_ICR_RREQ 0x00000001
00040 #define DSP_ICR_TREQ 0x00000002
00041 #define DSP_ICR_UNUSED 0x00000004
00042 #define DSP_ICR_HF0 0x00000008
00043 #define DSP_ICR_HF1 0x00000010
00044 #define DSP_ICR_HM0 0x00000020
00045 #define DSP_ICR_HM1 0x00000040
00046 #define DSP_ICR_INIT 0x00000080
00047
00048 #define DSP_ICR_REGS_MASK 0xFF000000
00049 #define DSP_ICR_RREQ_REGS_MASK 0x01000000
00050 #define DSP_ICR_TREQ_REGS_MASK 0x02000000
00051 #define DSP_ICR_HF0_REGS_MASK 0x08000000
00052 #define DSP_ICR_HF1_REGS_MASK 0x10000000
00053 #define DSP_ICR_HM0_REGS_MASK 0x20000000
00054 #define DSP_ICR_HM1_REGS_MASK 0x40000000
00055 #define DSP_ICR_INIT_REGS_MASK 0x80000000
00056
00057
00058
00059 #define DSP_CVR 1
00060 #define DSP_CVR_HV_MASK 0x0000001F
00061 #define DSP_CVR_HC_MASK 0x00000080
00062
00063 #define DSP_CVR_REGS_MASK 0x00FF0000
00064 #define DSP_CVR_HV_REGS_MASK 0x001F0000
00065 #define DSP_CVR_HC_REGS_MASK 0x00800000
00066
00067
00068
00069 #define DSP_ISR 2
00070 #define DSP_ISR_RXDF 0x00000001
00071 #define DSP_ISR_TXDE 0x00000002
00072 #define DSP_ISR_TRDY 0x00000004
00073 #define DSP_ISR_HF2 0x00000008
00074 #define DSP_BUSY 0x00000008
00075 #define DSP_ISR_HF3 0x00000010
00076 #define DSP_ISR_UNUSED 0x00000020
00077 #define DSP_ISR_DMA 0x00000040
00078 #define DSP_ISR_HREQ 0x00000080
00079
00080 #define DSP_ISR_REGS_MASK 0x0000FF00
00081 #define DSP_ISR_RXDF_REGS_MASK 0x00000100
00082 #define DSP_ISR_TXDE_REGS_MASK 0x00000200
00083 #define DSP_ISR_TRDY_REGS_MASK 0x00000400
00084 #define DSP_ISR_HF2_REGS_MASK 0x00000800
00085 #define DSP_BUSY_REGS_MASK 0x00000800
00086 #define DSP_ISR_HF3_REGS_MASK 0x00001000
00087 #define DSP_ISR_DMA_REGS_MASK 0x00004000
00088 #define DSP_ISR_HREQ_REGS_MASK 0x00008000
00089
00090
00091 #define DSP_IVR 3
00092
00093 #define DSP_UNUSED 4
00094
00095
00096 #define DSP_RXH 5
00097 #define DSP_RXM 6
00098 #define DSP_RXL 7
00099
00100
00101 #define DSP_TXH 5
00102 #define DSP_TXM 6
00103 #define DSP_TXL 7
00104
00105
00106 #define DSP_MULAW_SPACE 1
00107 #define DSP_MULAW_TABLE 256
00108 #define DSP_MULAW_LENGTH 128
00109
00110 #define DSP_ALAW_SPACE 1
00111 #define DSP_ALAW_TABLE 384
00112 #define DSP_ALAW_LENGTH 128
00113
00114 #define DSP_SINE_SPACE 2
00115 #define DSP_SINE_TABLE 256
00116 #define DSP_SINE_LENGTH 256
00117
00118
00119
00120
00121 #define DSP_HC_RESET (0x0)
00122 #define DSP_HC_TRACE (0x4>>1)
00123 #define DSP_HC_SWI (0x6>>1)
00124 #define DSP_HC_SOFTWARE_INTERRUPT (0x6>>1)
00125 #define DSP_HC_ABORT (0x8>>1)
00126 #define DSP_HC_HOST_RD (0x24>>1)
00127 #define DSP_HC_HOST_R_DONE (0x24>>1)
00128 #define DSP_HC_EXECUTE_HOST_MESSAGE (0x26>>1)
00129 #define DSP_HC_XHM (0x26>>1)
00130 #define DSP_HC_DMAWT (0x28>>1)
00131 #define DSP_HC_DMA_HOST_W_DONE (0x28>>1)
00132 #define DSP_HC_HOST_W_DONE (0x28>>1)
00133 #define DSP_HC_KERNEL_ACK (0x2A>>1)
00134 #define DSP_HC_SYS_CALL (0x2C>>1)
00135
00136 #import "dsp_messages.h"
00137
00138 #define DSP_MESSAGE_OPCODE(x) (((x)>>16)&0xFF)
00139 #define DSP_MESSAGE_SIGNED_DATUM(x) \
00140 ((int)((x)&0x8000?0xFFFF0000|((x)&0xFFFF):((x)&0xFFFF)))
00141 #define DSP_MESSAGE_UNSIGNED_DATUM(x) ((x)&0xFFFF)
00142 #define DSP_MESSAGE_ADDRESS(x) DSP_MESSAGE_UNSIGNED_DATUM(x)
00143 #define DSP_ERROR_OPCODE_INDEX(x) ((x) & 0x7F)
00144 #define DSP_IS_ERROR_MESSAGE(x) ((x) & 0x800000)
00145 #define DSP_IS_ERROR_OPCODE(x) ((x) & 0x80)
00146
00147 #define DSP_START_ADDRESS DSP_PLI_USR
00148
00149
00150 #define DSP_UNTIL_ERROR(x) if ((DSPErrorNo=(x))) \
00151 return(_DSPError(DSPErrorNo,"Aborting"))
00152
00153 #define NOT_YET 1
00154
00155
00156
00157 #include "dsp_structs.h"
00158 #include "dsp_errno.h"
00159 #include "libdsp.h"
00160
00161 #if defined(WIN32) && !defined(__MINGW32__)
00162
00163
00164
00165 typedef unsigned int u_int;
00166
00167
00168
00169 struct timeval {
00170 long tv_sec;
00171 long tv_usec;
00172 };
00173 #else // WIN32
00174 #include <unistd.h>
00175 #endif
00176
00177 #include <sys/types.h>
00178 #include <stdio.h>
00179 #include <math.h>
00180
00181 #ifndef GNUSTEP
00182 # import <mach/mach.h>
00183 #endif
00184
00185 #define DSP_MAX_HM (DSP_NB_HMS-2)
00186
00187 #define DSPMK_UNTIMED NULL
00188
00189
00190 MKDSP_API int DSPErrorNo;
00191 MKDSP_API DSPTimeStamp DSPMKTimeStamp0;
00192
00193
00194 #define DSP_TWO_TO_24 ((double)16777216.0)
00195 #define DSP_TWO_TO_M_24 ((double)5.960464477539063e-08)
00196 #define DSP_TWO_TO_23 ((double)8388608.0)
00197 #define DSP_TWO_TO_M_23 ((double)1.192092895507813e-7)
00198 #define DSP_TWO_TO_48 ((double)281474976710656.0)
00199 #define DSP_TWO_TO_M_48 ((double)3.552713678800501e-15)
00200 #define DSP_TWO_TO_15 ((double)32768.0)
00201 #define DSP_TWO_TO_M_15 ((double)3.0517578125e-05)
00202
00203 #define DSP_INT_TO_FLOAT(x) ((((float)(x))*((float)DSP_TWO_TO_M_23)))
00204 #define DSP_SHORT_TO_FLOAT(x) ((((float)(x))*((float)DSP_TWO_TO_M_15)))
00205 #define DSP_FIX24_TO_FLOAT(x) ((((float)(x))*((float)DSP_TWO_TO_M_23)))
00206 #define DSP_INT_TO_DOUBLE(x) ((((double)(x))*(DSP_TWO_TO_M_23)))
00207 #define DSP_SHORT_TO_DOUBLE(x) ((((double)(x))*((float)DSP_TWO_TO_M_15)))
00208 #define DSP_FIX48_TO_DOUBLE(x) ((double)((x)->high24)*(DSP_TWO_TO_24) + ((double) (x)->low24))
00209 #define DSP_FLOAT_TO_INT(x) ((int)(((double)(x))*((double)DSP_TWO_TO_23)+0.5))
00210 #define DSP_FLOAT_TO_SHORT(x) ((int)(((double)(x))*((double)DSP_TWO_TO_15)+0.5))
00211 #define DSP_DOUBLE_TO_INT(x) ((int)(((double)(x))*(DSP_TWO_TO_23)+0.5))
00212 #define DSP_DOUBLE_TO_SHORT(x) ((int)(((double)(x))*((double)DSP_TWO_TO_15)+0.5))
00213
00214
00215 #define DSP_F_MAXPOS ((double)(1.0-DSP_TWO_TO_M_23))
00216 #define DSP_ONE DSP_F_MAXPOS
00217
00218
00219 #define DSP_F_MAXNEG (float) -1.0
00220
00221 #define DSP_FIX24_CLIP(_x) (((int)_x) & 0xFFFFFF)
00222
00223 #define DSPMK_LOW_SAMPLING_RATE 22050.0
00224 #define DSPMK_HIGH_SAMPLING_RATE 44100.0
00225
00226 #ifndef REMEMBER
00227 #define REMEMBER(x)
00228 #endif
00229
00230 #define DSPMK_NTICK DSPMK_I_NTICK
00231
00232
00233
00234
00235 #define DSP_SYSTEM_DIRECTORY @"/usr/local/lib/dsp/"
00236 #define DSP_FALLBACK_SYSTEM_DIRECTORY @"/usr/lib/dsp/"
00237 #define DSP_BIN_DIRECTORY "/usr/local/bin/"
00238 #define DSP_AP_BIN_DIRECTORY "/apbin/"
00239 #define DSP_INSTALL_ROOT "/usr/local/lib/dsp/"
00240 #define DSP_ERRORS_FILE "/tmp/dsperrors"
00241 #define DSP_WHO_FILE "/tmp/dsp.who"
00242
00243 MKDSP_API const char *DSPGetDSPDirectory();
00244 MKDSP_API char *DSPGetSystemDirectory();
00245 MKDSP_API char *DSPGetImgDirectory();
00246 MKDSP_API char *DSPGetAPDirectory();
00247 MKDSP_API char *DSPGetMusicDirectory();
00248 MKDSP_API char *DSPGetLocalBinDirectory();
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 #define DSPMapPMemY(ya) ((int) ((ya) & 0x7FFF))
00259
00260
00261
00262
00263
00264
00265
00266 #define DSPMapPMemX(xa) ((int) (((xa)|0x1000) & 0x7FFF))
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 #define DSP_MUSIC_SYSTEM_MEM "/mkmon8k.mem"
00281 #define DSP_AP_SYSTEM_MEM "/apmon8k.mem"
00282
00283
00284 #define DSP_MUSIC_SYSTEM_BINARY_0 "/mkmon_A_8k.dsp"
00285 #define DSP_MUSIC_SYSTEM_0 "/mkmon_A_8k.lod"
00286
00287 #define DSP_AP_SYSTEM_BINARY_0 "/apmon_8k.dsp"
00288 #define DSP_AP_SYSTEM_0 "/apmon_8k.lod"
00289
00290
00291 #define DSP_32K_MUSIC_SYSTEM_BINARY_0 @"/mkmon_A_32k.dsp"
00292 #define DSP_32K_MUSIC_SYSTEM_0 @"/mkmon_A_32k.lod"
00293
00294
00295 #define DSP_32K_AP_SYSTEM_BINARY_0 @"/apmon_32k.dsp"
00296 #define DSP_32K_AP_SYSTEM_0 @"/apmon_32k.lod"
00297
00298
00299 #define DSP_192K_MUSIC_SYSTEM_BINARY_0 @"/mkmon_A_192k.dsp"
00300 #define DSP_192K_MUSIC_SYSTEM_0 @"/mkmon_A_192k.lod"
00301
00302
00303 #define DSP_64K_SPLIT_MUSIC_SYSTEM_BINARY_0 @"/mkmon_A_192k.dsp"
00304 #define DSP_64K_SPLIT_MUSIC_SYSTEM_0 @"/mkmon_A_192k.lod"
00305
00306
00307 #define DSP_MIN_DMA_READ_SIZE 0
00308
00309
00310 #define DSP_MIN_DMA_WRITE_SIZE 128
00311
00312
00313 #define DSP_MODE32_LEFT_JUSTIFIED 6
00314
00315 #ifndef MAX
00316 #define MAX(A,B) ((A) > (B) ? (A) : (B))
00317 #endif
00318
00319 #ifndef MIN
00320 #define MIN(A,B) ((A) < (B) ? (A) : (B))
00321 #endif
00322
00323 #ifndef ABS
00324 #define ABS(A) ((A) < 0 ? (-(A)) : (A))
00325 #endif
00326
00327 #define DSP_MALLOC( VAR, TYPE, NUM ) ((VAR) = (TYPE *) malloc( (unsigned)(NUM)*sizeof(TYPE)))
00328
00329 #define DSP_REALLOC( VAR, TYPE, NUM ) \
00330 ((VAR) = (TYPE *) realloc((char *)(VAR), (unsigned)(NUM)*sizeof(TYPE)))
00331
00332 #define DSP_FREE( PTR ) free( (char *) (PTR) );
00333
00334
00335
00336
00337
00338 MKDSP_API int DSPDefaultTimeLimit;
00339 MKDSP_API int DSPAPTimeLimit;
00340
00341
00342
00343 #define DSP_ATOMIC 1
00344 #define DSP_NON_ATOMIC 0
00345 #define DSP_TIMEOUT_FOREVER 0
00346 #define _DSP_MSG_READER_TIMEOUT 30
00347
00348 #endif
00349
00350 #endif
00351