comparison services/pcm/pcmcode.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
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 #include <string.h>
12 #include "pcm.h"
13 #include "../ffs/ffs.h"
14 #include "../ffs/ffstrace.h"
15
16 extern const T_PCM_DESCRIPTION pcm_table[];
17 extern const UBYTE pcm_default_values[];
18 extern UBYTE pcm_mem [];
19
20
21 /******************************************************************************
22 *
23 ******************************************************************************/
24
25 // pcm_Init() has been renamed to pcm_init() so that it is not called
26 // anywhere else than it should. The old pcm_Init() is now empty. This new
27 // pcm_init() scans through the pcm file table and attempts to read each
28 // file from ffs into the pcm RAM image.
29
30 drv_Return_Type pcm_Init(void)
31 {
32 return PCM_INITIALIZED;
33 }
34
35
36 // Note that PCM file data chunks start with one byte for the file data
37 // checksum, followed by another byte for the version. The third byte
38 // (offset 2) is the start of the actual filedata. We ignore these first two
39 // bytes e.g. we only read/write the actual file data!
40
41
42 // look up a PCM file
43 int pcm_lookup(char *pcm_name)
44 {
45 int i = 0;
46
47 while (pcm_table[i].identifier != NULL)
48 {
49 if (!strcmp((char *) pcm_name, pcm_table[i].identifier + 5))
50 return i;
51 i++;
52 }
53 return -1; // not found.
54 }
55
56 drv_Return_Type pcm_init(void)
57 {
58 int i = 0;
59 effs_t error;
60
61 ttw(ttr(TTrInit, "pcm_init" NL));
62
63 while (pcm_table[i].identifier != NULL)
64 {
65 error = ffs_fread(pcm_table[i].identifier,
66 &pcm_mem[pcm_table[i].start + 2],
67 (pcm_table[i].length - 2) * pcm_table[i].records);
68
69 if (error < EFFS_OK) {
70 // copy defaults to pcm_mem
71 memcpy (&pcm_mem[pcm_table[i].start] + 2,
72 &pcm_default_values[pcm_table[i].start - 2*i],
73 pcm_table[i].records * (pcm_table[i].length - 2));
74 }
75 pcm_mem[pcm_table[i].start + 1] = 1; // file version
76 i++;
77 }
78
79 return PCM_INITIALIZED;
80 }
81
82 drv_Return_Type pcm_GetFileInfo(UBYTE * in_FileName,
83 pcm_FileInfo_Type * out_FileInfoPtr)
84 {
85 int i = pcm_lookup((char*)in_FileName);
86
87 ttw(ttr(TTrPcmRead, "pcm_gfi(%s)" NL, in_FileName));
88
89 if (i == -1)
90 return PCM_INVALID_FILE;
91
92 out_FileInfoPtr->FileLocation = &pcm_mem [pcm_table[i].start+2];
93 out_FileInfoPtr->FileSize = pcm_table[i].length -2;
94 // As Condat has determined that all files is version 1, we just
95 // hardwire exactly that!
96 // out_FileInfoPtr->Version = pcm_mem [pcm_table[i].start + 1];
97 out_FileInfoPtr->Version = 1;
98
99 return PCM_OK;
100 }
101
102
103 /******************************************************************************
104 * Normal read/write functions
105 ******************************************************************************/
106
107 drv_Return_Type pcm_ReadFile(UBYTE * in_FileName,
108 USHORT in_BufferSize,
109 UBYTE * out_BufferPtr,
110 UBYTE * out_VersionPtr)
111 {
112 int i = pcm_lookup((char*)in_FileName);
113
114 ttw(ttr(TTrPcmRead, "pcm_rf(%s)" NL, in_FileName));
115
116 if (i == -1)
117 return PCM_INVALID_FILE;
118
119 if (in_BufferSize + 2 != pcm_table[i].length)
120 return PCM_INVALID_SIZE;
121
122 // checksum check removed --- it is redundant!
123
124 memcpy (out_BufferPtr, &pcm_mem[pcm_table[i].start+2], in_BufferSize);
125 *out_VersionPtr = pcm_mem[pcm_table[i].start+1];
126
127 return PCM_OK;
128 }
129
130 drv_Return_Type pcm_WriteFile(UBYTE * in_FileName,
131 USHORT in_FileSize,
132 UBYTE * in_BufferPtr)
133 {
134 int i = pcm_lookup((char*)in_FileName);
135
136 ttw(ttr(TTrPcmWrite, "pcm_wf(%s)" NL, in_FileName));
137
138 if (i == -1)
139 return PCM_INVALID_FILE;
140
141 if (in_FileSize + 2 != pcm_table[i].length)
142 return PCM_INVALID_SIZE;
143
144 memcpy (&pcm_mem[pcm_table[i].start+2], in_BufferPtr, in_FileSize);
145
146 // write the whole file to ffs! (ignoring errors)
147 ffs_fwrite(pcm_table[i].identifier,
148 &pcm_mem[pcm_table[i].start + 2],
149 in_FileSize);
150
151 return PCM_OK;
152 }
153
154
155 /******************************************************************************
156 * Record read/write functions
157 ******************************************************************************/
158
159 /* Record files are implemented by having the first two bytes of a
160 * file be equal to the record size. */
161
162 drv_Return_Type pcm_ReadRecord(UBYTE * in_FileName,
163 USHORT in_Record,
164 USHORT in_BufferSize,
165 UBYTE * out_BufferPtr,
166 UBYTE * out_VersionPtr,
167 USHORT * out_MaxRecordsPtr)
168 {
169 int i = pcm_lookup((char*)in_FileName);
170
171 ttw(ttr(TTrPcmRead, "pcm_rr(%s)" NL, in_FileName));
172
173 if (i == -1)
174 return PCM_INVALID_FILE;
175
176 if (in_BufferSize + 2 != pcm_table[i].length)
177 return PCM_INVALID_SIZE;
178
179 if (in_Record == 0 || in_Record > pcm_table[i].records)
180 return PCM_INVALID_RECORD;
181
182 memcpy (out_BufferPtr,
183 &pcm_mem[pcm_table[i].start + 2 + (in_Record-1) * in_BufferSize],
184 in_BufferSize);
185 *out_MaxRecordsPtr = pcm_table[i].records;
186 *out_VersionPtr = pcm_mem [pcm_table[i].start + 1];
187
188 return PCM_OK;
189 }
190
191 drv_Return_Type pcm_WriteRecord(UBYTE * in_FileName,
192 USHORT in_Record,
193 USHORT in_BufferSize,
194 UBYTE * in_BufferPtr)
195 {
196 int i = pcm_lookup((char*)in_FileName);
197
198 ttw(ttr(TTrPcmWrite, "pcm_wr(%s)" NL, in_FileName));
199
200 if (i == -1)
201 return PCM_INVALID_FILE;
202
203 if (in_BufferSize + 2 != pcm_table[i].length)
204 return PCM_INVALID_SIZE;
205
206 if (in_Record == 0 || in_Record > pcm_table[i].records)
207 return PCM_INVALID_RECORD;
208
209 memcpy (&pcm_mem [pcm_table[i].start + 2 + (in_Record-1) * in_BufferSize],
210 in_BufferPtr,
211 in_BufferSize);
212
213 // write the whole file to ffs! (ignoring errors)
214 ffs_fwrite(pcm_table[i].identifier,
215 &pcm_mem [pcm_table[i].start + 2],
216 pcm_table[i].records * (pcm_table[i].length - 2));
217
218 return PCM_OK;
219 }