comparison chipsetsw/drivers/drv_app/ffs/board/pcmcode.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /******************************************************************************
2 * Flash File System (ffs)
3 * Idea, design and coding by Mads Meisner-Jensen, mmj@ti.com
4 *
5 * Condat PCM Compatibility Support
6 *
7 * $Id: pcmcode.c 1.46 Tue, 06 Nov 2001 11:55:21 +0100 tsj $
8 *
9 ******************************************************************************/
10
11 #ifndef TARGET
12 #include "board.cfg"
13 #include "ffs.cfg"
14 #endif
15
16 #include <string.h>
17 #include "ffs/pcm.h"
18 #include "ffs/ffs.h"
19 #include "ffs/board/ffstrace.h"
20
21 #if (TARGET == 1)
22 #include "sys.cfg"
23 #if (BOARD == 34)
24 #include "ffs/board/ffspcm.h"
25 #endif
26 #else
27 #define STD 6
28 #define NULL 0
29 #endif
30
31
32 extern const T_PCM_DESCRIPTION pcm_table[];
33 extern const UBYTE pcm_default_values[];
34 extern UBYTE pcm_mem [];
35 extern UBYTE std;
36
37
38 /******************************************************************************
39 *
40 ******************************************************************************/
41
42 // pcm_Init() has been renamed to pcm_init() so that it is not called
43 // anywhere else than it should. The old pcm_Init() is now empty. This new
44 // pcm_init() scans through the pcm file table and attempts to read each
45 // file from ffs into the pcm RAM image.
46
47 drv_Return_Type pcm_Init(void)
48 {
49 return PCM_INITIALIZED;
50 }
51
52
53 // Note that PCM file data chunks start with one byte for the file data
54 // checksum, followed by another byte for the version. The third byte
55 // (offset 2) is the start of the actual filedata. We ignore these first two
56 // bytes e.g. we only read/write the actual file data!
57
58
59 // look up a PCM file
60 int pcm_lookup(char *pcm_name)
61 {
62 int i = 0;
63
64 while (pcm_table[i].identifier != NULL)
65 {
66 if (!strcmp((char *) pcm_name, pcm_table[i].identifier + 5))
67 return i;
68 i++;
69 }
70 return -1; // not found.
71 }
72
73 drv_Return_Type pcm_init(void)
74 {
75 int i = 0;
76 effs_t error;
77
78 ttw(ttr(TTrInit, "pcm_init" NL));
79
80 // Avenger 2 tri band radio
81 #if (BOARD==34)
82 std = ffs_GetBand();
83 #else
84 std = STD;
85 #endif
86
87 while (pcm_table[i].identifier != NULL)
88 {
89 error = ffs_fread(pcm_table[i].identifier,
90 &pcm_mem[pcm_table[i].start + 2],
91 (pcm_table[i].length - 2) * pcm_table[i].records);
92
93 if (error < EFFS_OK) {
94 // copy defaults to pcm_mem
95 memcpy (&pcm_mem[pcm_table[i].start] + 2,
96 &pcm_default_values[pcm_table[i].start - 2*i],
97 pcm_table[i].records * (pcm_table[i].length - 2));
98 }
99 pcm_mem[pcm_table[i].start + 1] = 1; // file version
100 i++;
101 }
102
103 return PCM_INITIALIZED;
104 }
105
106 drv_Return_Type pcm_GetFileInfo(UBYTE * in_FileName,
107 pcm_FileInfo_Type * out_FileInfoPtr)
108 {
109 int i = pcm_lookup((char*)in_FileName);
110
111 ttw(ttr(TTrPcmRead, "pcm_gfi(%s)" NL, in_FileName));
112
113 if (i == -1)
114 return PCM_INVALID_FILE;
115
116 out_FileInfoPtr->FileLocation = &pcm_mem [pcm_table[i].start+2];
117 out_FileInfoPtr->FileSize = pcm_table[i].length -2;
118 // As Condat has determined that all files is version 1, we just
119 // hardwire exactly that!
120 // out_FileInfoPtr->Version = pcm_mem [pcm_table[i].start + 1];
121 out_FileInfoPtr->Version = 1;
122
123 return PCM_OK;
124 }
125
126
127 /******************************************************************************
128 * Normal read/write functions
129 ******************************************************************************/
130
131 drv_Return_Type pcm_ReadFile(UBYTE * in_FileName,
132 USHORT in_BufferSize,
133 UBYTE * out_BufferPtr,
134 UBYTE * out_VersionPtr)
135 {
136 int i = pcm_lookup((char*)in_FileName);
137
138 ttw(ttr(TTrPcmRead, "pcm_rf(%s)" NL, in_FileName));
139
140 if (i == -1)
141 return PCM_INVALID_FILE;
142
143 if (in_BufferSize + 2 != pcm_table[i].length)
144 return PCM_INVALID_SIZE;
145
146 // checksum check removed --- it is redundant!
147
148 memcpy (out_BufferPtr, &pcm_mem[pcm_table[i].start+2], in_BufferSize);
149 *out_VersionPtr = pcm_mem[pcm_table[i].start+1];
150
151 return PCM_OK;
152 }
153
154 drv_Return_Type pcm_WriteFile(UBYTE * in_FileName,
155 USHORT in_FileSize,
156 UBYTE * in_BufferPtr)
157 {
158 int i = pcm_lookup((char*)in_FileName);
159
160 ttw(ttr(TTrPcmWrite, "pcm_wf(%s)" NL, in_FileName));
161
162 if (i == -1)
163 return PCM_INVALID_FILE;
164
165 if (in_FileSize + 2 != pcm_table[i].length)
166 return PCM_INVALID_SIZE;
167
168 memcpy (&pcm_mem[pcm_table[i].start+2], in_BufferPtr, in_FileSize);
169
170 // write the whole file to ffs! (ignoring errors)
171 ffs_fwrite(pcm_table[i].identifier,
172 &pcm_mem[pcm_table[i].start + 2],
173 in_FileSize);
174
175 return PCM_OK;
176 }
177
178
179 /******************************************************************************
180 * Record read/write functions
181 ******************************************************************************/
182
183 /* Record files are implemented by having the first two bytes of a
184 * file be equal to the record size. */
185
186 drv_Return_Type pcm_ReadRecord(UBYTE * in_FileName,
187 USHORT in_Record,
188 USHORT in_BufferSize,
189 UBYTE * out_BufferPtr,
190 UBYTE * out_VersionPtr,
191 USHORT * out_MaxRecordsPtr)
192 {
193 int i = pcm_lookup((char*)in_FileName);
194
195 ttw(ttr(TTrPcmRead, "pcm_rr(%s)" NL, in_FileName));
196
197 if (i == -1)
198 return PCM_INVALID_FILE;
199
200 if (in_BufferSize + 2 != pcm_table[i].length)
201 return PCM_INVALID_SIZE;
202
203 if (in_Record == 0 || in_Record > pcm_table[i].records)
204 return PCM_INVALID_RECORD;
205
206 memcpy (out_BufferPtr,
207 &pcm_mem[pcm_table[i].start + 2 + (in_Record-1) * in_BufferSize],
208 in_BufferSize);
209 *out_MaxRecordsPtr = pcm_table[i].records;
210 *out_VersionPtr = pcm_mem [pcm_table[i].start + 1];
211
212 return PCM_OK;
213 }
214
215 drv_Return_Type pcm_WriteRecord(UBYTE * in_FileName,
216 USHORT in_Record,
217 USHORT in_BufferSize,
218 UBYTE * in_BufferPtr)
219 {
220 int i = pcm_lookup((char*)in_FileName);
221
222 ttw(ttr(TTrPcmWrite, "pcm_wr(%s)" NL, in_FileName));
223
224 if (i == -1)
225 return PCM_INVALID_FILE;
226
227 if (in_BufferSize + 2 != pcm_table[i].length)
228 return PCM_INVALID_SIZE;
229
230 if (in_Record == 0 || in_Record > pcm_table[i].records)
231 return PCM_INVALID_RECORD;
232
233 memcpy (&pcm_mem [pcm_table[i].start + 2 + (in_Record-1) * in_BufferSize],
234 in_BufferPtr,
235 in_BufferSize);
236
237 // write the whole file to ffs! (ignoring errors)
238 ffs_fwrite(pcm_table[i].identifier,
239 &pcm_mem [pcm_table[i].start + 2],
240 pcm_table[i].records * (pcm_table[i].length - 2));
241
242 return PCM_OK;
243 }