comparison gsm-fw/ccd/hl_flag.c @ 648:970d6199f2c5

gsm-fw/ccd/*.[ch]: initial import from the LoCosto source
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 04 Sep 2014 05:48:57 +0000
parents
children
comparison
equal deleted inserted replaced
647:a60b375014e3 648:970d6199f2c5
1 /*
2 +-----------------------------------------------------------------------------
3 | Project :
4 | Modul : hl_flag.c
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Inc.
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : Definition of encoding and decoding functions for HL_FLAG elements
18 +-----------------------------------------------------------------------------
19 */
20
21
22 /*
23 * standard definitions like GLOBAL, UCHAR, ERROR etc.
24 */
25 #include "typedefs.h"
26 #include "header.h"
27
28 /*
29 * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only
30 * look at ccdapi.h
31 */
32 #undef USE_DRIVER
33 #include "ccdapi.h"
34
35 /*
36 * Types and functions for bit access and manipulation
37 */
38 #include "ccd_globs.h"
39 #include "bitfun.h"
40
41 /*
42 * Prototypes of ccd internal functions
43 */
44 #include "ccd.h"
45
46 /*
47 * Declaration of coder/decoder tables
48 */
49 #include "ccdtable.h"
50 #include "ccddata.h"
51
52
53 #ifndef RUN_INT_RAM
54 /*
55 +--------------------------------------------------------------------+
56 | PROJECT : CCD (6144) MODULE : CDC_GSM |
57 | STATE : code ROUTINE : cdc_hl_flag_decode |
58 +--------------------------------------------------------------------+
59
60 PURPOSE : Decoding of the GSM Type HL_FLAG element. This element
61 consists of a single bit only. The decoded value will be 0
62 if the encoded value is L respectively 1 if the encoded
63 value is H.
64
65 */
66
67 SHORT cdc_hl_flag_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs)
68 {
69 ULONG repeat, max_rep;
70 BOOL is_variable = FALSE;
71 ULONG cix_ref, num_prolog_steps, prolog_step_ref;
72
73 #ifdef DEBUG_CCD
74 #ifndef CCD_SYMBOLS
75 TRACE_CCD (globs, "cdc_hl_flag_decode()");
76 #else
77 TRACE_CCD (globs, "cdc_hl_flag_decode() %s", ccddata_get_alias((USHORT) e_ref, 1));
78 #endif
79 #endif
80
81 globs->SeekTLVExt = FALSE;
82 cix_ref = melem[e_ref].calcIdxRef;
83 num_prolog_steps = calcidx[cix_ref].numPrologSteps;
84 prolog_step_ref = calcidx[cix_ref].prologStepRef;
85 repeat = 1;
86
87 if (cix_ref != 0)
88 {
89 /*
90 * if this element is conditional, check the condition
91 */
92 if (calcidx[cix_ref].numCondCalcs NEQ 0
93 AND ! ccd_conditionOK (e_ref, globs))
94 return 1;
95
96 /*
97 * if this element have a defined Prolog
98 * we have to process it before decoding the bitstream
99 */
100 if (num_prolog_steps)
101 {
102 ccd_performOperations (num_prolog_steps, prolog_step_ref, globs);
103 }
104 if (melem[e_ref].repType NEQ ' ')
105 {
106 is_variable = ccd_calculateRep (e_ref, &repeat, &max_rep, globs);
107 }
108 }
109 /*
110 * Element is not a SPARE. Setup the struct pointer
111 */
112 globs->pstructOffs = melem[e_ref].structOffs;
113
114
115 if (melem[e_ref].optional)
116 {
117 /*
118 * for optional elements we must set the valid-flag
119 * ??.
120 * Therefore we store the address of the valid flag.
121 */
122 *(globs->pstruct + globs->pstructOffs++) = TRUE;
123
124 }
125
126 globs->pstruct[globs->pstructOffs++] = (UBYTE) (bf_readBit(globs) == GET_HL_PREV(1));
127 #ifdef DEBUG_CCD
128 #ifdef CCD_SYMBOLS
129 TRACE_CCD (globs, "decoding var %s",ccddata_get_alias((USHORT) e_ref, 1));
130 #else
131 TRACE_CCD (globs, "decoding var %d", melem[e_ref].elemRef);
132 #endif
133 #endif
134
135 return 1;
136 }
137 #endif /* !RUN_INT_RAM */
138
139 #ifndef RUN_INT_RAM
140 /*
141 +--------------------------------------------------------------------+
142 | PROJECT : CCD (6144) MODULE : CDC_GSM |
143 | STATE : code ROUTINE : cdc_hl_flag_encode |
144 +--------------------------------------------------------------------+
145
146 PURPOSE : Encoding of the GSM Type HL_FLAG element. This element
147 consists of a single bit only. If the element is set to 1
148 a H bit will be coded. Otherwise a L bit will be coded if
149 the element value to encode is set to 0.
150
151 */
152
153 SHORT cdc_hl_flag_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs)
154 {
155 ULONG repeat=1, amount=1;
156 USHORT cSize = 0, startOffset;
157 ULONG i;
158 ULONG cix_ref, num_prolog_steps, prolog_step_ref;
159
160 #ifdef DEBUG_CCD
161 #ifndef CCD_SYMBOLS
162 TRACE_CCD (globs, "cdc_hl_flag_encode()");
163 #else
164 TRACE_CCD (globs, "cdc_hl_flag_encode() %s", ccddata_get_alias((USHORT) e_ref, 1));
165 #endif
166 #endif
167
168 cix_ref = melem[e_ref].calcIdxRef;
169 num_prolog_steps = calcidx[cix_ref].numPrologSteps;
170 prolog_step_ref = calcidx[cix_ref].prologStepRef;
171
172 if (cix_ref != 0)
173 {
174 /*
175 * if this element is conditional, check the condition
176 */
177 if (calcidx[cix_ref].numCondCalcs NEQ 0
178 AND ! ccd_conditionOK (e_ref, globs))
179 return 1;
180
181 /*
182 * if this element have a defined Prolog
183 * we have to process it before decoding the bitstream
184 */
185 if (num_prolog_steps)
186 {
187 ccd_performOperations (num_prolog_steps, prolog_step_ref, globs);
188 }
189 }
190
191 if (melem[e_ref].elemType NEQ 'S')
192 {
193 /*
194 * Element is not a SPARE.
195 * Setup the offset into the C-structure for this element
196 */
197 globs->pstructOffs = melem[e_ref].structOffs;
198
199 if (melem[e_ref].optional)
200 {
201 /*
202 * for optional elements check the valid-flag in the C-struct.
203 * Spare elements does not have a corresponding valid flag.
204 */
205 if (globs->pstruct[globs->pstructOffs++] == FALSE)
206 {
207 /*
208 * element is invalid so we must code a 0 bit
209 */
210 bf_writeBit (GET_HL(0), globs);
211
212 return 1;
213 }
214
215 else
216 {
217 #ifdef DEBUG_CCD
218 if (globs->pstruct [melem[e_ref].structOffs] != TRUE)
219 {
220 TRACE_CCD (globs, "Ambiguous value for valid flag!\n...assumed 1 for ccdID=%d",
221 e_ref);
222 }
223 #endif
224 /*
225 * element is valid so we must code a 1 bit
226 */
227 bf_writeBit (GET_HL(1), globs);
228 }
229 }
230
231 if (melem[e_ref].repType NEQ ' ')
232 {
233 /* As a default amount =1 due to initialization. */
234 if (melem[e_ref].repType EQ 'i')
235 {
236 /*
237 * for variable repeatable elements read the amount
238 * of repeats out of the C-Structure (c_xxx).
239 * If the number of repeats given by the C-Structure
240 * exceeds the allowed value CCD gives a warning!
241 */
242 if (melem[e_ref].maxRepeat > 255)
243 {
244 ULONG count = (ULONG) (* (USHORT *)(globs->pstruct + globs->pstructOffs++));
245 repeat = MINIMUM (count, (ULONG) melem[e_ref].maxRepeat);
246 if (repeat < count)
247 ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE,
248 (USHORT) e_ref, globs->pstruct + globs->pstructOffs);
249 }
250 else
251 {
252 repeat = (ULONG) MINIMUM (globs->pstruct[globs->pstructOffs],
253 melem[e_ref].maxRepeat);
254 if ( repeat < (ULONG)(globs->pstruct[globs->pstructOffs]) )
255 ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE,
256 (USHORT) e_ref, globs->pstruct + globs->pstructOffs);
257 }
258 globs->pstructOffs++;
259 }
260 else
261 if (melem[e_ref].repType EQ 'v')
262 {
263 /*
264 * for variable repeatable elements read the amount
265 * of repeats out of the C-Structure (c_xxx).
266 * If the number of repetitions given by the C-Structure
267 * exceeds the allowed value (maxRepeat) CCD gives a warning!
268 */
269 if (melem[e_ref].maxRepeat > 255)
270 {
271 ULONG count = (ULONG) (* (USHORT *)(globs->pstruct + globs->pstructOffs++));
272 amount = MINIMUM (count, (ULONG) melem[e_ref].maxRepeat);
273 if (amount < count)
274 ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE,
275 (USHORT) e_ref, globs->pstruct + globs->pstructOffs);
276 }
277 else
278 {
279 amount = (ULONG) MINIMUM (globs->pstruct[globs->pstructOffs],
280 melem[e_ref].maxRepeat);
281 if ( amount < (ULONG) (globs->pstruct[globs->pstructOffs]) )
282 ccd_recordFault (globs, ERR_MAX_REPEAT, CONTINUE,
283 (USHORT) e_ref, globs->pstruct + globs->pstructOffs);
284 }
285 globs->pstructOffs++;
286 }
287 else
288 if (melem[e_ref].repType EQ 'c')
289 {
290 amount = (ULONG) melem[e_ref].maxRepeat;
291 }
292
293 if (melem[e_ref].repType EQ 'v' OR melem[e_ref].repType EQ 'i')
294 {
295 cSize = (USHORT)(((melem[e_ref].elemType EQ 'V')
296 ? mvar[melem[e_ref].elemRef].cSize
297 : mcomp[melem[e_ref].elemRef].cSize
298 ));
299 startOffset = (USHORT) globs->pstructOffs;
300 }
301 }
302
303 for (i=0; i < repeat; i++)
304 {
305 if (cSize)
306 {
307 /*
308 * calculate the offset if it is an array
309 */
310 globs->pstructOffs = (USHORT)(startOffset + (i * cSize));
311 }
312 /*
313 * encode the value
314 */
315 if (globs->pstruct[globs->pstructOffs++] EQ FALSE)
316 {
317 /*
318 * element is 0 so we must signalize L
319 */
320 bf_writeBit (GET_HL(0), globs);
321 }
322 else
323 {
324 /*
325 * element is 1 so we must signalize H
326 */
327 bf_writeBit (GET_HL(1), globs);
328 }
329
330 globs->pstructOffs += mvar[melem[e_ref].elemRef].cSize;
331 }
332
333 if (melem[e_ref].repType EQ 'i')
334 {
335 /*
336 * for variable CNS1 fields we code a 0 flag to mark the end of the
337 * arrays
338 */
339 bf_writeBit (GET_HL(0), globs);
340 }
341 }
342
343 return 1;
344 }
345 #endif /* !RUN_INT_RAM */