comparison src/g23m-fad/fad/fad_sbm.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_SBM
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 send buffer manager for
18 | the component Fax Adaptation 3.45 of the mobile station
19 +-----------------------------------------------------------------------------
20 */
21
22 #ifndef FAD_SBM_C
23 #define FAD_SBM_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 "cl_ribu.h"
43 #include "fad.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_SBM |
58 | STATE : code ROUTINE : sbm_init |
59 +--------------------------------------------------------------------+
60
61 PURPOSE :
62
63 */
64 GLOBAL void sbm_init(USHORT frameSize)
65 {
66 T_SBM *sbm = &fad_data->sbm;
67 USHORT n;
68
69 TRACE_FUNCTION ("sbm_init()");
70
71 cl_ribu_init(&sbm->ribu, SBM_PRIMBUF_SIZE);
72
73 for (n = 0; n < sbm->ribu.depth; n++)
74 sbm->Prim[n].Prim = NULL;
75
76 sbm->PA = 0;
77 sbm->CurrPrimOff = 0;
78 sbm->CurrPrimLen = 0;
79 sbm->FrameSize = frameSize;
80
81 fad_data->snd.FD.buf = fad_data->snd.FD_buf;
82 }
83
84 /*
85 +--------------------------------------------------------------------+
86 | PROJECT : GSM-F&D (8411) MODULE : FAD_SBM |
87 | STATE : code ROUTINE : sbm_store_prim |
88 +--------------------------------------------------------------------+
89
90 PURPOSE :
91
92 */
93
94 GLOBAL void sbm_store_prim(T_SBM_PRIM *sendPrim)
95 {
96 T_SBM *sbm = &fad_data->sbm;
97
98 #ifdef _SIMULATION_
99 TRACE_FUNCTION ("sbm_store_prim()");
100 #endif
101
102 sbm->Prim[sbm->ribu.wi].Prim = sendPrim;
103
104 if (!sbm->ribu.filled) /* Initialize new primitive for read out */
105 {
106 sbm->CurrPrimOff = sendPrim->sdu.o_buf >> 3;
107 sbm->CurrPrimLen = sendPrim->sdu.l_buf >> 3;
108 }
109 cl_ribu_write_index(&sbm->ribu);
110 }
111
112 /*
113 +--------------------------------------------------------------------+
114 | PROJECT : GSM-F&D (8411) MODULE : FAD_SBM |
115 | STATE : code ROUTINE : sbm_free_empty_prims|
116 +--------------------------------------------------------------------+
117
118 PURPOSE :
119
120 */
121
122 GLOBAL void sbm_free_empty_prims(void)
123 {
124 T_SBM *sbm = &fad_data->sbm;
125
126 #ifdef _SIMULATION_
127 TRACE_FUNCTION ("sbm_free_empty_prims()");
128 #endif
129
130 while (sbm->PA NEQ sbm->ribu.ri)
131 {
132 PFREE (sbm->Prim[sbm->PA].Prim);
133 sbm->PA++;
134 if (sbm->PA EQ sbm->ribu.depth)
135 sbm->PA = 0;
136 }
137 }
138
139 /*
140 +--------------------------------------------------------------------+
141 | PROJECT : GSM-F&D (8411) MODULE : FAD_SBM |
142 | STATE : code ROUTINE : sbm_get_frame |
143 +--------------------------------------------------------------------+
144
145 PURPOSE :
146
147 */
148
149 GLOBAL BOOL sbm_get_frame(T_FRAME_DESC *ul_FD, UBYTE reqFrames)
150 {
151 T_SBM *sbm = &fad_data->sbm;
152
153 USHORT requiredData;
154 BOOL insertSync;
155
156 #ifdef _SIMULATION_
157 TRACE_FUNCTION ("sbm_get_frame()");
158 #endif
159
160 cl_set_frame_desc_0(ul_FD, NULL, 0);
161
162 if (!sbm->ribu.filled) /* There is no primitive */
163 {
164 return FALSE;
165 }
166
167 insertSync = FALSE;
168
169 if (sbm->syncCycle NEQ SYNC_CYCLE_NONE)
170 {
171 if (reqFrames > sbm->framesUntilSync)
172 {
173 insertSync = TRUE;
174 reqFrames--;
175 }
176 else
177 sbm->framesUntilSync -= reqFrames;
178 }
179
180 requiredData = sbm->FrameSize * (USHORT)reqFrames;
181
182 if (sbm->CurrPrimLen > requiredData)
183 {
184 /* Current primitive holds more than enough data */
185 cl_set_frame_desc_0(ul_FD, sbm->Prim[sbm->ribu.ri].Prim->sdu.buf + sbm->CurrPrimOff, requiredData);
186
187 sbm->CurrPrimOff += requiredData;
188 sbm->CurrPrimLen -= requiredData;
189 }
190 else
191 {
192 /*
193 * Current primitive doesn't hold enough data
194 * or just the right amount of data.
195 * -> Switch to next primitive
196 */
197
198 /* Take all data from first primitive */
199 cl_set_frame_desc_0(ul_FD, sbm->Prim[sbm->ribu.ri].Prim->sdu.buf + sbm->CurrPrimOff, sbm->CurrPrimLen);
200
201 cl_ribu_read_index(&sbm->ribu); /* Switch to next primitive */
202
203 if (!sbm->ribu.filled) /* There is no second primitive */
204 {
205 ul_FD->Adr[1] = (UBYTE *) NULL;
206 ul_FD->Len[1] = 0;
207 sbm->CurrPrimOff = 0;
208 sbm->CurrPrimLen = 0;
209 }
210 else /* Second primitive is available */
211 {
212 requiredData -= sbm->CurrPrimLen;
213
214 sbm->CurrPrimOff = sbm->Prim[sbm->ribu.ri].Prim->sdu.o_buf >> 3;
215 sbm->CurrPrimLen = sbm->Prim[sbm->ribu.ri].Prim->sdu.l_buf >> 3;
216
217 if (requiredData EQ 0)
218 {
219 /*
220 * First primitive was just used up.
221 * We had to switch to next primitive, but don't need data.
222 */
223 ul_FD->Adr[1] = (UBYTE *) NULL;
224 ul_FD->Len[1] = 0;
225 }
226 else
227 {
228 /* Data from next primitive is required */
229 ul_FD->Adr[1] = sbm->Prim[sbm->ribu.ri].Prim->sdu.buf + sbm->CurrPrimOff;
230
231 if (sbm->CurrPrimLen > requiredData)
232 {
233 /* Enough data found in second primitive */
234 ul_FD->Len[1] = requiredData;
235 sbm->CurrPrimOff += requiredData;
236 sbm->CurrPrimLen -= requiredData;
237 }
238 else
239 {
240 /* Even with the second primitive there are not enough data! */
241 ul_FD->Len[1] = sbm->CurrPrimLen;
242
243 /* Second primitive is also emptied, switch to next primitve */
244 cl_ribu_read_index(&sbm->ribu);
245
246 if (sbm->ribu.filled)
247 {
248 sbm->CurrPrimOff = sbm->Prim[sbm->ribu.ri].Prim->sdu.o_buf >> 3;
249 sbm->CurrPrimLen = sbm->Prim[sbm->ribu.ri].Prim->sdu.l_buf >> 3;
250
251 }
252 else
253 {
254 sbm->CurrPrimOff = 0;
255 sbm->CurrPrimLen = 0;
256 }
257 }
258 }
259 }
260 }
261
262 if ((ul_FD->Len[0]+ul_FD->Len[1]) < requiredData)
263 {
264 /*
265 * If there are not enough data available align the length to 64 bit
266 * align the length to 64 bit boundaries.
267 * This alignment should normally occur at the end of the message phase.
268 * The required data are always a multiple of 64 bits.
269 */
270 int i, k = 0;
271 int diff = requiredData - (ul_FD->Len[0]+ul_FD->Len[1]);
272
273 if (ul_FD->Len[1] > 0)
274 k = 1;
275
276 for (i = 0; i < ul_FD->Len[k]; i++)
277 fad_data->snd.ul_FD_align[i] = ul_FD->Adr[k][i];
278
279 for (i = ul_FD->Len[k]; i < ul_FD->Len[k] + diff; i++)
280 fad_data->snd.ul_FD_align[i] = 0;
281
282 ul_FD->Len[k] += diff;
283 ul_FD->Adr[k] = fad_data->snd.ul_FD_align;
284 }
285
286 if (insertSync)
287 {
288 USHORT framesUntilSync = sbm->framesUntilSync;
289 USHORT frame_off = 0, i, j;
290
291 for (i=0; i<2; i++)
292 {
293 for (j=0; j<ul_FD->Len[i]; j+=FRAME_SIZE)
294 {
295 if (framesUntilSync-- EQ 0)
296 {
297 memcpy((char*)&sbm->frames[frame_off], (char*)FR_SEQ_SYNC, FRAME_SIZE);
298 frame_off+=FRAME_SIZE;
299 }
300 memcpy((char*)&sbm->frames[frame_off], (char*)ul_FD->Adr[i], FRAME_SIZE);
301 frame_off+=FRAME_SIZE;
302
303 sbm->framesUntilSync = sbm->syncCycle - reqFrames + framesUntilSync;
304 }
305 }
306 cl_set_frame_desc_0(ul_FD, sbm->frames, (USHORT)((reqFrames+1)*FRAME_SIZE));
307 }
308 return TRUE;
309 }
310