1 /*
2 * Copyright (c) 2016, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33 \r
34 /* \r
35 * fil.h: Definitions for file handling functions (file stored in memory!)\r
36 */\r
37 #ifndef _FIL_H\r
38 #define _FIL_H\r
39 \r
40 #include <xdc/std.h> /* required for types.h */\r
41 #include <ti/mas/types/types.h>\r
42 \r
43 #include "sys.h" /* for eampling rate, etc. */\r
44 \r
45 /*======================================================================\r
46 * File related constants\r
47 *======================================================================*/\r
48 \r
49 #define FIL_MAX SYS_MICS_MAX /* Maximum number of files */\r
50 \r
51 #define FIL_L_ENDIAN (FALSE) /* Little endian byte ordering in file */\r
52 #define FIL_B_ENDIAN (TRUE)1 /* Big endian byte ordering in file */\r
53 \r
54 #define FIL_DURATION_MAX_MS (60*1000L) /* 1min max duration */\r
55 #define FIL_LENGTH_MAX (SYS_FS_HZ*FIL_DURATION_MAX_MS/1000) /* max length in samples */\r
56 #define FIL_OUTDURATION_MAX_MS (FIL_DURATION_MAX_MS+1*1000L) /* 1s longer than input */\r
57 #define FIL_OUTLEN_MAX (SYS_FS_HZ*FIL_OUTDURATION_MAX_MS/1000) /* in samples */\r
58 \r
59 /*======================================================================\r
60 * Bit masks, byte swapping macros, error codes\r
61 *======================================================================*/\r
62 \r
63 /* Bit masks for byte swapping */\r
64 #define FIL_LOW_BYTE 0x00FFu\r
65 #define FIL_HIGH_BYTE 0xFF00u\r
66 \r
67 /* Macros for bit-mask manipulations */\r
68 #define FIL_GET_LOW(x) ((x)&FIL_LOW_BYTE)\r
69 #define FIL_GET_HIGH(x) (((x)>>8)&FIL_LOW_BYTE)\r
70 #define FIL_SWAP_BYTES(x) ((FIL_GET_LOW(x)<<8)|FIL_GET_HIGH(x))\r
71 \r
72 /*======================================================================\r
73 * File related types\r
74 *======================================================================*/\r
75 \r
76 /* File Configuration Structure */\r
77 struct filConfig_stc {\r
78 tlong length; /* number of samples in the input files */\r
79 tint nfiles; /* number of memory input files to create */\r
80 tbool big; /* TRUE: big endian, FALSE: little endian byte order */\r
81 tbool wrap; /* TRUE: do wrap-around, FALSE: do not wrap-around */\r
82 tlong outlen; /* number of samples in the output file */\r
83 };\r
84 typedef struct filConfig_stc filConfig_t;\r
85 \r
86 /* File Descriptor Structure (handles all files) */\r
87 struct filDescriptor_stc {\r
88 tlong r_idx; /* current read index (sample based) */\r
89 tlong w_idx; /* current write index (sample based) */\r
90 tlong length; /* number of samples in an input file (does not apply to output!) */\r
91 tint nfiles; /* numbner of configured files */\r
92 \r
93 void *filbase[FIL_MAX]; /* base addresses of file buffers */\r
94 \r
95 /* Use 'big' for both R&W */\r
96 tbool big; /* TRUE: big endian, FALSE: little endian byte order */\r
97 tbool wrap; /* TRUE: do wrap-around, FLASE: do not wrap-around (input only) */\r
98 \r
99 /* WRITE Part */\r
100 tlong outlen; /* Output buffer length in samples */\r
101 void *outbuf; /* A pointer to the output buffer */\r
102 };\r
103 typedef struct filDescriptor_stc filDescriptor_t;\r
104 \r
105 /*======================================================================\r
106 * API Prototypes\r
107 *======================================================================*/\r
108 \r
109 extern int filCreate(void**,filConfig_t*); /* Initialize file descriptor */\r
110 extern void *filGetHandle(void); /* Return file handle */\r
111 extern tlong filLoad(char*, tlong, int); /* Load file into memory */\r
112 extern int filRead(void*,int,linSample*,int); /* Read samples from files */\r
113 extern int filWrite(void*, int, linSample*); /* Write sample into file */\r
114 \r
115 #endif\r
116 /* nothing past this point */\r
117 \r