comparison src/g23m-fad/fad/fad_rbm.c @ 174:90eb61ecd093

src/g23m-fad: initial import from TCS3.2/LoCosto
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2016 05:40:46 +0000
parents
children
comparison
equal deleted inserted replaced
173:bf64d785238a 174:90eb61ecd093
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-F&D (8411)
4 | Modul : FAD_RBM
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
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 : This Modul defines the receive buffer manager for
18 | the component Fax Adaptation 3.45 of the mobile station
19 +-----------------------------------------------------------------------------
20 */
21
22 #ifndef FAD_RBM_C
23 #define FAD_RBM_C
24 #endif
25
26 #define ENTITY_FAD
27
28 /*==== INCLUDES ===================================================*/
29
30 #include <string.h>
31 #include "typedefs.h"
32 #include "pconst.cdg"
33 #include "vsi.h"
34 #include "custom.h"
35 #include "gsm.h"
36 #include "cnf_fad.h"
37 #include "mon_fad.h"
38 #include "prim.h"
39 #include "pei.h"
40 #include "tok.h"
41 #include "ccdapi.h"
42 #include "fad.h"
43 #include "ra_l1int.h"
44
45 /*==== CONST =======================================================*/
46
47 /*==== TYPES =======================================================*/
48
49 /*==== VAR EXPORT ==================================================*/
50
51 /*==== VAR LOCAL ===================================================*/
52
53 /*==== FUNCTIONS ===================================================*/
54
55 /*
56 +--------------------------------------------------------------------+
57 | PROJECT : GSM-F&D (8411) MODULE : FAD_RBM |
58 | STATE : code ROUTINE : rbmi_alloc_curr_prim |
59 +--------------------------------------------------------------------+
60
61 PURPOSE :
62
63 */
64
65 LOCAL BOOL rbmi_alloc_curr_prim(void)
66 {
67 T_RBM_FAD *rbm = &fad_data->rbm;
68
69 PALLOC_SDU (fad_data_ind, FAD_DATA_IND, (USHORT)(rbm->FramesPerPrim * FRAME_SIZE * 8));
70
71 TRACE_FUNCTION ("rbmi_alloc_curr_prim()");
72
73 fad_data_ind->sdu.l_buf = 0;
74 fad_data_ind->sdu.o_buf = 0;
75
76 rbm->CurrPrim = fad_data_ind;
77 rbm->FramesInCurrPrim = 0;
78
79 return (rbm->CurrPrim NEQ NULL);
80 }
81
82 /*
83 +--------------------------------------------------------------------+
84 | PROJECT : GSM-F&D (8411) MODULE : FAD_RBM |
85 | STATE : code ROUTINE : rbm_init |
86 +--------------------------------------------------------------------+
87
88 PURPOSE :
89
90 */
91
92 GLOBAL void rbm_init(USHORT framesPerPrim)
93 {
94 T_RBM_FAD *rbm = &fad_data->rbm;
95
96 TRACE_FUNCTION ("rbm_init()");
97
98 cl_ribu_create(&rbm->ribu, MAX_SDU_SIZE, DL_RIBU_DEPTH);
99 rbm->FramesPerPrim = framesPerPrim;
100 rbm_deinit(FALSE);
101
102 if (rbmi_alloc_curr_prim())
103 rbm->Initialised = TRUE;
104 }
105
106 /*
107 +--------------------------------------------------------------------+
108 | PROJECT : GSM-F&D (8411) MODULE : FAD_RBM |
109 | STATE : code ROUTINE : rbm_deinit |
110 +--------------------------------------------------------------------+
111
112 PURPOSE : This function frees all allocated T_FAD_DATA_IND primitives
113 of the receive buffer manager.
114
115 */
116
117 GLOBAL void rbm_deinit(BOOL final)
118 {
119 T_RBM_FAD *rbm = &fad_data->rbm;
120 U8 n;
121
122 TRACE_FUNCTION ("rbm_deinit()");
123
124 rbm->Initialised = FALSE;
125
126 if (rbm->CurrPrim NEQ (T_FAD_DATA_IND *)NULL)
127 {
128 PFREE (rbm->CurrPrim)
129 rbm->CurrPrim = (T_FAD_DATA_IND *) NULL;
130 }
131
132 for (n = 0; n < RBM_PQ_SIZE; n++)
133 {
134 if (rbm->PQ_Array[rbm->PQ.ri] NEQ (T_FAD_DATA_IND *)NULL)
135 {
136 PFREE (rbm->PQ_Array[rbm->PQ.ri])
137 rbm->PQ_Array[rbm->PQ.ri] = (T_FAD_DATA_IND *)NULL;
138 }
139 }
140 cl_ribu_init(&rbm->PQ, RBM_PQ_SIZE);
141 rbm->FramesInCurrPrim = 0;
142
143 if (final EQ TRUE) /* during deactivation */
144 {
145 cl_ribu_release(&rbm->ribu); /* frees downlink FIFO */
146 }
147 }
148
149 /*
150 +--------------------------------------------------------------------+
151 | PROJECT : GSM-F&D (8411) MODULE : FAD_RBM |
152 | STATE : code ROUTINE : rbmi_pq_enq |
153 +--------------------------------------------------------------------+
154
155 PURPOSE : A primitive is put into the primitive queue.
156
157 */
158
159 LOCAL BOOL rbmi_pq_enq(T_FAD_DATA_IND *prim)
160 {
161 T_RBM_FAD *rbm = &fad_data->rbm;
162
163 TRACE_FUNCTION ("rbmi_pq_enq()");
164
165 if (rbm->PQ_Array[rbm->PQ.wi] EQ NULL)
166 {
167 /*
168 * empty PQ entry found
169 */
170 prim->sdu.l_buf = rbm->FramesPerPrim * FRAME_SIZE * 8;
171
172 rbm->PQ_Array[cl_ribu_write_index(&rbm->PQ)] = prim;
173 return TRUE;
174 }
175 else
176 return FALSE; /* no available entry in PQ */
177 }
178
179 /*
180 +--------------------------------------------------------------------+
181 | PROJECT : GSM-F&D (8411) MODULE : FAD_RBM |
182 | STATE : code ROUTINE : rbmi_copy_frame_to_curr_prim |
183 +--------------------------------------------------------------------+
184
185 PURPOSE :
186
187 */
188
189 LOCAL BOOL rbmi_copy_frame_to_curr_prim(UBYTE *frame)
190 {
191 T_RBM_FAD *rbm = &fad_data->rbm;
192
193 TRACE_FUNCTION ("rbmi_copy_frame_to_curr_prim()");
194
195 if (rbm->CurrPrim EQ NULL)
196 if (!rbmi_alloc_curr_prim())
197 return FALSE;
198
199 if (rbm->FramesInCurrPrim < rbm->FramesPerPrim)
200 {
201 memcpy(&rbm->CurrPrim->sdu.buf[rbm->FramesInCurrPrim * FRAME_SIZE], frame, FRAME_SIZE);
202 rbm->FramesInCurrPrim++;
203 }
204
205 if (rbm->FramesInCurrPrim >= rbm->FramesPerPrim)
206 {
207 /*
208 * Current primitive is full.
209 * Store it in the PQ and allocate a new current prim
210 */
211 if (rbmi_pq_enq(rbm->CurrPrim))
212 {
213 /*
214 * Current prim is in PQ -> allocate a new current prim
215 */
216 return rbmi_alloc_curr_prim();
217 }
218 else
219 {
220 return FALSE;
221 }
222 }
223 return TRUE;
224 }
225
226 /*
227 +--------------------------------------------------------------------+
228 | PROJECT : GSM-F&D (8411) MODULE : FAD_RBM |
229 | STATE : code ROUTINE : rbmi_pq_deq |
230 +--------------------------------------------------------------------+
231
232 PURPOSE : A fad_data_ind primitive is taken from the queue. This
233 is done when the queue is not empty and a FAD_GETDATA_REQ
234 is executed. Of after storing a primitive in the queue,
235 when the upper layer is waiting for data.
236
237 */
238
239 LOCAL T_FAD_DATA_IND *rbmi_pq_deq(void)
240 {
241 T_RBM_FAD *rbm = &fad_data->rbm;
242 T_FAD_DATA_IND *prim = rbm->PQ_Array[rbm->PQ.ri];
243
244 TRACE_FUNCTION ("rbmi_pq_deq()");
245
246 if (prim NEQ NULL)
247 {
248 rbm->PQ_Array[cl_ribu_read_index(&rbm->PQ)] = NULL;
249 }
250 return prim;
251 }
252
253 /*
254 +--------------------------------------------------------------------+
255 | PROJECT : GSM-F&D (8411) MODULE : FAD_RBM |
256 | STATE : code ROUTINE : rbm_reset |
257 +--------------------------------------------------------------------+
258
259 PURPOSE : This function must be called once at startup before any
260 other procedures of the RBM is invoked. (Coldstart)
261
262 */
263
264 GLOBAL void rbm_reset(void)
265 {
266 T_RBM_FAD *rbm = &fad_data->rbm;
267
268 TRACE_FUNCTION ("rbm_reset()");
269
270 rbm->CurrPrim = (T_FAD_DATA_IND *) NULL;
271 rbm->FramesInCurrPrim = 0;
272 cl_ribu_init(&rbm->PQ, RBM_PQ_SIZE);
273 rbm->FramesPerPrim = 1;
274 rbm->Initialised = FALSE;
275 }
276
277 /*
278 +--------------------------------------------------------------------+
279 | PROJECT : GSM-F&D (8411) MODULE : FAD_RBM |
280 | STATE : code ROUTINE : rbm_store_frames |
281 +--------------------------------------------------------------------+
282
283 PURPOSE : This procedure is only used in the simulation environment
284 to store multiple frames in the receive buffer.
285 In the implementation the copy is performed by the RA layer
286 which have access to the shared memory area of the DSP.
287 */
288
289 GLOBAL BOOL rbm_store_frames(T_FD *pFD, BOOL *primIsReady)
290 {
291 T_RBM_FAD *rbm = &fad_data->rbm;
292
293 if (rbm->Initialised)
294 {
295 USHORT n;
296 BOOL flag = FALSE;
297
298 for (n = 0; n < pFD->len/FRAME_SIZE; n++)
299 {
300 if (!rbmi_copy_frame_to_curr_prim(&pFD->buf[n * FRAME_SIZE]))
301 {
302 flag = TRUE;
303 break;
304 }
305 }
306 if (flag)
307 return FALSE;
308 }
309 *primIsReady = rbm->PQ.filled;
310 return TRUE;
311 }
312
313 /*
314 +--------------------------------------------------------------------+
315 | PROJECT : GSM-F&D (8411) MODULE : FAD_RBM |
316 | STATE : code ROUTINE : rbm_get_prim |
317 +--------------------------------------------------------------------+
318
319 PURPOSE : This is just a wrapper for rbmi_pq_deq. The queu is an
320 internal matter of the RBM, therefore the function
321 rbmi_pq_deq should not be used directly by the user.
322
323 */
324
325 GLOBAL T_FAD_DATA_IND *rbm_get_prim(void)
326 {
327 TRACE_FUNCTION ("rbm_get_prim()");
328
329 return rbmi_pq_deq();
330 }
331
332 /*
333 +--------------------------------------------------------------------+
334 | PROJECT : GSM-F&D (8411) MODULE : FAD_RBM |
335 | STATE : code ROUTINE : rbm_get_curr_prim |
336 +--------------------------------------------------------------------+
337
338 PURPOSE :
339
340 */
341
342 GLOBAL T_FAD_DATA_IND *rbm_get_curr_prim(void)
343 {
344 T_RBM_FAD *rbm = &fad_data->rbm;
345 T_FAD_DATA_IND *prim;
346
347 TRACE_FUNCTION ("rbm_get_curr_prim()");
348
349 prim = rbm->CurrPrim;
350 if (prim NEQ NULL)
351 {
352 rbm->CurrPrim->sdu.l_buf = rbm->FramesInCurrPrim * FRAME_SIZE * 8;
353 rbm->CurrPrim = (T_FAD_DATA_IND *) NULL;
354 }
355 return prim;
356 }
357