FreeCalypso > hg > fc-selenite
comparison src/g23m-fad/rlp/rlp_sbm.c @ 1:d393cd9bb723
src/g23m-*: initial import from Magnetite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 15 Jul 2018 04:40:46 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:b6a5e36de839 | 1:d393cd9bb723 |
---|---|
1 /* | |
2 +----------------------------------------------------------------------------- | |
3 | Project : CSD (8411) | |
4 | Modul : Rlp_sbm.c | |
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 Radio Link Protocol of the mobile station | |
19 +----------------------------------------------------------------------------- | |
20 */ | |
21 | |
22 #ifndef RLP_SBM_C | |
23 #define RLP_SBM_C | |
24 #endif | |
25 | |
26 #define ENTITY_RLP | |
27 | |
28 /*==== INCLUDES ===================================================*/ | |
29 | |
30 #include <string.h> | |
31 #include "typedefs.h" | |
32 #include "vsi.h" | |
33 #include "custom.h" | |
34 #include "gsm.h" | |
35 #include "cus_rlp.h" | |
36 #include "prim.h" | |
37 #include "tok.h" | |
38 #include "rlp.h" | |
39 | |
40 /*==== CONST =======================================================*/ | |
41 | |
42 /*==== TYPES =======================================================*/ | |
43 | |
44 /*==== VAR EXPORT ==================================================*/ | |
45 | |
46 /*==== VAR LOCAL ===================================================*/ | |
47 | |
48 /*==== FUNCTIONS ===================================================*/ | |
49 | |
50 /* | |
51 +------------------------------------------------------------------------------ | |
52 | Function : sbmi_srej_list_delete | |
53 +------------------------------------------------------------------------------ | |
54 | Description : | |
55 | | |
56 | Parameters : lo - | |
57 | hi - | |
58 | | |
59 | Return : - | |
60 +------------------------------------------------------------------------------ | |
61 */ | |
62 | |
63 | |
64 LOCAL void sbmi_srej_list_delete | |
65 ( | |
66 T_SBM_BUFFER_INDEX lo, | |
67 T_SBM_BUFFER_INDEX hi | |
68 ) | |
69 { | |
70 T_SBM_BUFFER_EXTIDX p, p_last; | |
71 | |
72 TRACE_FUNCTION ("sbmi_srej_list_delete()"); | |
73 | |
74 p = rlp_data->sbm.SREJ_List; | |
75 p_last = SBM_INVALID_IDX; | |
76 | |
77 if (lo <= hi) | |
78 { | |
79 while (p NEQ SBM_INVALID_IDX) | |
80 { | |
81 if (p >= lo AND p < hi) | |
82 { | |
83 if (p_last EQ SBM_INVALID_IDX) | |
84 rlp_data->sbm.SREJ_List = rlp_data->sbm.Frame[p].NextSREJ; | |
85 else | |
86 rlp_data->sbm.Frame[p_last].NextSREJ | |
87 = rlp_data->sbm.Frame[p].NextSREJ; | |
88 } | |
89 p_last = p; | |
90 p = rlp_data->sbm.Frame[p].NextSREJ; | |
91 } | |
92 } | |
93 else | |
94 { | |
95 while (p NEQ SBM_INVALID_IDX) | |
96 { | |
97 if (p >= lo OR p < hi) | |
98 { | |
99 if (p_last EQ SBM_INVALID_IDX) | |
100 rlp_data->sbm.SREJ_List = rlp_data->sbm.Frame[p].NextSREJ; | |
101 else | |
102 rlp_data->sbm.Frame[p_last].NextSREJ | |
103 = rlp_data->sbm.Frame[p].NextSREJ; | |
104 } | |
105 p_last = p; | |
106 p = rlp_data->sbm.Frame[p].NextSREJ; | |
107 } | |
108 } | |
109 } | |
110 | |
111 | |
112 /* | |
113 +------------------------------------------------------------------------------ | |
114 | Function : sbmi_srej_list_put | |
115 +------------------------------------------------------------------------------ | |
116 | Description : | |
117 | | |
118 | Parameters : p - | |
119 | | |
120 | | |
121 | Return : - | |
122 +------------------------------------------------------------------------------ | |
123 */ | |
124 | |
125 | |
126 LOCAL void sbmi_srej_list_put | |
127 ( | |
128 T_SBM_BUFFER_EXTIDX p | |
129 ) | |
130 { | |
131 TRACE_FUNCTION ("sbmi_srej_list_put()"); | |
132 | |
133 rlp_data->sbm.Frame[p].NextSREJ = rlp_data->sbm.SREJ_List; | |
134 | |
135 rlp_data->sbm.SREJ_List = p; | |
136 } | |
137 | |
138 /* | |
139 +------------------------------------------------------------------------------ | |
140 | Function : sbmi_srej_list_get | |
141 +------------------------------------------------------------------------------ | |
142 | Description : | |
143 | | |
144 | Parameters : p | |
145 | | |
146 | | |
147 | Return : - | |
148 +------------------------------------------------------------------------------ | |
149 */ | |
150 | |
151 | |
152 LOCAL void sbmi_srej_list_get | |
153 ( | |
154 T_SBM_BUFFER_EXTIDX *p | |
155 ) | |
156 { | |
157 TRACE_FUNCTION ("sbmi_srej_list_get()"); | |
158 | |
159 if ((*p = rlp_data->sbm.SREJ_List) NEQ SBM_INVALID_IDX) | |
160 rlp_data->sbm.SREJ_List = rlp_data->sbm.Frame[*p].NextSREJ; | |
161 } | |
162 | |
163 /* | |
164 +------------------------------------------------------------------------------ | |
165 | Function : sbmi_get_frame_desc | |
166 +------------------------------------------------------------------------------ | |
167 | Description : | |
168 | | |
169 | Parameters : p - | |
170 | frameDesc - | |
171 | | |
172 | Return : - | |
173 +------------------------------------------------------------------------------ | |
174 */ | |
175 | |
176 | |
177 LOCAL void sbmi_get_frame_desc | |
178 ( | |
179 T_SBM_BUFFER_EXTIDX p, | |
180 T_FRAME_DESC *frameDesc | |
181 ) | |
182 { | |
183 TRACE_FUNCTION ("sbmi_get_frame_desc()"); | |
184 | |
185 if (rlp_data->sbm.Frame[p].PrimSlot1 NEQ SBM_INVALID_IDX) | |
186 { | |
187 frameDesc->Adr[0] | |
188 = rlp_data->sbm.Prim[rlp_data->sbm.Frame[p].PrimSlot1].Prim->sdu.buf | |
189 + rlp_data->sbm.Frame[p].Offset1; | |
190 | |
191 frameDesc->Len[0] = rlp_data->sbm.Frame[p].Len1; | |
192 | |
193 if (rlp_data->sbm.Frame[p].PrimSlot2 NEQ SBM_INVALID_IDX) | |
194 { | |
195 frameDesc->Adr[1] | |
196 = rlp_data->sbm.Prim[rlp_data->sbm.Frame[p].PrimSlot2].Prim->sdu.buf | |
197 + rlp_data->sbm.Frame[p].Offset2; | |
198 | |
199 frameDesc->Len[1] = rlp_data->sbm.Frame[p].Len2; | |
200 } | |
201 else | |
202 { | |
203 frameDesc->Adr[1] = (UBYTE *) NULL; | |
204 frameDesc->Len[1] = 0; | |
205 } | |
206 } | |
207 else | |
208 if (rlp_data->sbm.Frame[p].PrimSlot2 NEQ SBM_INVALID_IDX) | |
209 { | |
210 frameDesc->Adr[0] | |
211 = rlp_data->sbm.Prim[rlp_data->sbm.Frame[p].PrimSlot2].Prim->sdu.buf | |
212 + rlp_data->sbm.Frame[p].Offset2; | |
213 | |
214 frameDesc->Len[0] = rlp_data->sbm.Frame[p].Len2; | |
215 | |
216 frameDesc->Adr[1] = (UBYTE *) NULL; | |
217 frameDesc->Len[1] = 0; | |
218 } | |
219 } | |
220 | |
221 /* | |
222 +------------------------------------------------------------------------------ | |
223 | Function : sbmi_dec_ref_count | |
224 +------------------------------------------------------------------------------ | |
225 | Description : | |
226 | | |
227 | Parameters : slot - | |
228 | | |
229 | | |
230 | Return : - | |
231 +------------------------------------------------------------------------------ | |
232 */ | |
233 | |
234 | |
235 LOCAL void sbmi_dec_ref_count | |
236 ( | |
237 T_SBM_PRIM_EXTIDX slot | |
238 ) | |
239 { | |
240 TRACE_FUNCTION ("sbmi_dec_ref_count()"); | |
241 | |
242 if (slot NEQ SBM_INVALID_IDX) | |
243 { | |
244 if (--rlp_data->sbm.Prim[slot].RefCount EQ 0) | |
245 { | |
246 PFREE (rlp_data->sbm.Prim[slot].Prim); | |
247 rlp_data->sbm.Prim[slot].Prim = NULL; | |
248 } | |
249 } | |
250 } | |
251 | |
252 /* | |
253 +------------------------------------------------------------------------------ | |
254 | Function : sbmi_data_to_transmit | |
255 +------------------------------------------------------------------------------ | |
256 | Description : | |
257 | | |
258 | Parameters : p - | |
259 | framesCouldBeSent - | |
260 | | |
261 | Return : - | |
262 +------------------------------------------------------------------------------ | |
263 */ | |
264 | |
265 | |
266 LOCAL void sbmi_data_to_transmit | |
267 ( | |
268 T_SBM_BUFFER_EXTIDX *p, | |
269 BOOL *framesCouldBeSent | |
270 ) | |
271 { | |
272 TRACE_FUNCTION ("sbmi_data_to_transmit()"); | |
273 | |
274 *framesCouldBeSent = FALSE; | |
275 sbmi_srej_list_get (p); | |
276 | |
277 /* | |
278 * SREJ slot found ? | |
279 */ | |
280 if (*p EQ SBM_INVALID_IDX) | |
281 { | |
282 /* | |
283 * No! - Is window open ? | |
284 */ | |
285 if (rlp_data->sbm.VS NEQ (rlp_data->sbm.VA+rlp_data->sbm.K) | |
286 % SBM_BUF_SIZE) | |
287 { | |
288 *framesCouldBeSent = TRUE; | |
289 /* | |
290 * regular slot to send ? | |
291 */ | |
292 if (rlp_data->sbm.VD NEQ rlp_data->sbm.VS) | |
293 { | |
294 *p = rlp_data->sbm.VS; | |
295 rlp_data->sbm.VS = (rlp_data->sbm.VS+1) % SBM_BUF_SIZE; | |
296 | |
297 } | |
298 } | |
299 } | |
300 } | |
301 | |
302 /* | |
303 +------------------------------------------------------------------------------ | |
304 | Function : sbm_set_wind_size | |
305 +------------------------------------------------------------------------------ | |
306 | Description : | |
307 | | |
308 | Parameters : windSize | |
309 | | |
310 | | |
311 | Return : - | |
312 +------------------------------------------------------------------------------ | |
313 */ | |
314 | |
315 | |
316 GLOBAL void sbm_set_wind_size | |
317 ( | |
318 T_SBM_BUFFER_INDEX windSize | |
319 ) | |
320 { | |
321 T_RBM_BUFFER_INDEX n; | |
322 T_RBM_BUFFER_INDEX nEnd; | |
323 T_RBM_BUFFER_INDEX oldSize; | |
324 | |
325 TRACE_FUNCTION ("sbm_set_wind_size()"); | |
326 | |
327 oldSize = rlp_data->sbm.K; | |
328 rlp_data->sbm.K = windSize; | |
329 | |
330 if (windSize < oldSize) | |
331 { | |
332 n = rlp_data->sbm.VA + windSize; | |
333 if (n >= SBM_BUF_SIZE) | |
334 { | |
335 n -= SBM_BUF_SIZE; | |
336 } | |
337 nEnd = rlp_data->sbm.VA + oldSize; | |
338 if (nEnd >= SBM_BUF_SIZE) | |
339 { | |
340 nEnd -= SBM_BUF_SIZE; | |
341 } | |
342 sbmi_srej_list_delete (n, nEnd); | |
343 } | |
344 } | |
345 | |
346 /* | |
347 +------------------------------------------------------------------------------ | |
348 | Function : sbm_init | |
349 +------------------------------------------------------------------------------ | |
350 | Description : | |
351 | | |
352 | Parameters : windSize - | |
353 | frameSize - | |
354 | n2 - | |
355 | | |
356 | Return : - | |
357 +------------------------------------------------------------------------------ | |
358 */ | |
359 | |
360 GLOBAL void sbm_init | |
361 ( | |
362 T_SBM_BUFFER_INDEX windSize, | |
363 USHORT frameSize, | |
364 UBYTE n2 | |
365 ) | |
366 { | |
367 USHORT n; | |
368 | |
369 TRACE_FUNCTION ("sbm_init()"); | |
370 | |
371 for (n = 0; n < SBM_BUF_SIZE; n++) | |
372 { | |
373 rlp_data->sbm.Frame[n].S_State = SBM_IDLE; | |
374 rlp_data->sbm.Frame[n].NextSREJ = SBM_INVALID_IDX; | |
375 rlp_data->sbm.Frame[n].PrimSlot1 = 0; | |
376 rlp_data->sbm.Frame[n].PrimSlot2 = 0; | |
377 rlp_data->sbm.Frame[n].Offset1 = 0; | |
378 rlp_data->sbm.Frame[n].Offset2 = 0; | |
379 rlp_data->sbm.Frame[n].Len1 = 0; | |
380 rlp_data->sbm.Frame[n].Len2 = 0; | |
381 } | |
382 | |
383 for (n=0; n < SBM_PRIMBUF_SIZE; n++) | |
384 { | |
385 rlp_data->sbm.Prim[n].Prim = NULL; | |
386 rlp_data->sbm.Prim[n].RefCount = 0; | |
387 } | |
388 | |
389 rlp_data->sbm.VA = 0; | |
390 rlp_data->sbm.VS = 0; | |
391 rlp_data->sbm.VD = 0; | |
392 rlp_data->sbm.LastSentFrame = SBM_INVALID_IDX; | |
393 rlp_data->sbm.CurrPrimSlot = 0; | |
394 rlp_data->sbm.CurrPrimOff = 0; | |
395 rlp_data->sbm.CurrPrimLen = 0; | |
396 rlp_data->sbm.SREJ_List = SBM_INVALID_IDX; | |
397 rlp_data->sbm.FrameSize = frameSize; | |
398 | |
399 sbm_set_wind_size (windSize); | |
400 sbm_set_retrans (n2); | |
401 } | |
402 | |
403 /* | |
404 +------------------------------------------------------------------------------ | |
405 | Function : sbm_store_prim | |
406 +------------------------------------------------------------------------------ | |
407 | Description : | |
408 | | |
409 | Parameters : sendPrim - | |
410 | | |
411 | | |
412 | Return : - | |
413 +------------------------------------------------------------------------------ | |
414 */ | |
415 | |
416 | |
417 GLOBAL void sbm_store_prim | |
418 ( | |
419 T_SBM_PRIM *sendPrim | |
420 ) | |
421 { | |
422 | |
423 TRACE_FUNCTION ("sbm_store_prim()"); | |
424 | |
425 | |
426 if (rlp_data->sbm.CurrPrimLen EQ 0) | |
427 { | |
428 rlp_data->sbm.Prim[rlp_data->sbm.CurrPrimSlot].Prim = sendPrim; | |
429 rlp_data->sbm.CurrPrimOff = sendPrim->sdu.o_buf >> 3; | |
430 rlp_data->sbm.CurrPrimLen = sendPrim->sdu.l_buf >> 3; | |
431 } | |
432 else if (rlp_data->sbm.CurrPrimLen > 0) | |
433 { | |
434 rlp_data->sbm.Frame[rlp_data->sbm.VD].PrimSlot1 = rlp_data->sbm.CurrPrimSlot; | |
435 rlp_data->sbm.Frame[rlp_data->sbm.VD].Offset1 = rlp_data->sbm.CurrPrimOff; | |
436 rlp_data->sbm.Frame[rlp_data->sbm.VD].Len1 = rlp_data->sbm.CurrPrimLen; | |
437 | |
438 rlp_data->sbm.CurrPrimSlot = (rlp_data->sbm.CurrPrimSlot+1) | |
439 % SBM_PRIMBUF_SIZE; | |
440 | |
441 rlp_data->sbm.Prim[rlp_data->sbm.CurrPrimSlot].RefCount++; | |
442 | |
443 rlp_data->sbm.Prim[rlp_data->sbm.CurrPrimSlot].Prim = sendPrim; | |
444 rlp_data->sbm.CurrPrimOff = sendPrim->sdu.o_buf >> 3; | |
445 rlp_data->sbm.CurrPrimLen = sendPrim->sdu.l_buf >> 3; | |
446 | |
447 | |
448 | |
449 rlp_data->sbm.Frame[rlp_data->sbm.VD].PrimSlot2 = rlp_data->sbm.CurrPrimSlot; | |
450 rlp_data->sbm.Frame[rlp_data->sbm.VD].Offset2 = rlp_data->sbm.CurrPrimOff; | |
451 | |
452 rlp_data->sbm.Frame[rlp_data->sbm.VD].Len2 | |
453 = (rlp_data->sbm.FrameSize - rlp_data->sbm.Frame[rlp_data->sbm.VD].Len1); | |
454 | |
455 if (rlp_data->sbm.Frame[rlp_data->sbm.VD].Len2 > rlp_data->sbm.CurrPrimLen) | |
456 { | |
457 rlp_data->sbm.Frame[rlp_data->sbm.VD].Len2 = rlp_data->sbm.CurrPrimLen; | |
458 } | |
459 | |
460 rlp_data->sbm.Frame[rlp_data->sbm.VD].S_State = SBM_SEND; | |
461 | |
462 rlp_data->sbm.CurrPrimOff += rlp_data->sbm.Frame[rlp_data->sbm.VD].Len2; | |
463 | |
464 rlp_data->sbm.CurrPrimLen -= rlp_data->sbm.Frame[rlp_data->sbm.VD].Len2; | |
465 | |
466 rlp_data->sbm.VD = (rlp_data->sbm.VD+1) % SBM_BUF_SIZE; | |
467 | |
468 } | |
469 | |
470 | |
471 while (rlp_data->sbm.CurrPrimLen >= rlp_data->sbm.FrameSize) | |
472 { | |
473 rlp_data->sbm.Frame[rlp_data->sbm.VD].PrimSlot1 | |
474 = rlp_data->sbm.CurrPrimSlot; | |
475 | |
476 rlp_data->sbm.Frame[rlp_data->sbm.VD].Offset1 | |
477 = rlp_data->sbm.CurrPrimOff; | |
478 | |
479 rlp_data->sbm.Frame[rlp_data->sbm.VD].Len1 | |
480 = rlp_data->sbm.FrameSize; | |
481 | |
482 rlp_data->sbm.CurrPrimOff += rlp_data->sbm.FrameSize; | |
483 rlp_data->sbm.CurrPrimLen -= rlp_data->sbm.FrameSize; | |
484 | |
485 rlp_data->sbm.Prim[rlp_data->sbm.CurrPrimSlot].RefCount++; | |
486 | |
487 /* | |
488 * the frame resides only in the first primitive | |
489 * -> the seconds description is set to invalid | |
490 */ | |
491 rlp_data->sbm.Frame[rlp_data->sbm.VD].Len2 = 0; | |
492 rlp_data->sbm.Frame[rlp_data->sbm.VD].Offset2 = 0; | |
493 rlp_data->sbm.Frame[rlp_data->sbm.VD].PrimSlot2 = SBM_INVALID_IDX; | |
494 | |
495 rlp_data->sbm.Frame[rlp_data->sbm.VD].S_State = SBM_SEND; | |
496 | |
497 rlp_data->sbm.VD = (rlp_data->sbm.VD+1) % SBM_BUF_SIZE; | |
498 } | |
499 | |
500 if (rlp_data->sbm.CurrPrimLen > 0) | |
501 rlp_data->sbm.Prim[rlp_data->sbm.CurrPrimSlot].RefCount++; | |
502 | |
503 else if (rlp_data->sbm.CurrPrimLen EQ 0) | |
504 { | |
505 rlp_data->sbm.CurrPrimSlot = (rlp_data->sbm.CurrPrimSlot+1) | |
506 % SBM_PRIMBUF_SIZE; | |
507 } | |
508 } | |
509 | |
510 /* | |
511 +------------------------------------------------------------------------------ | |
512 | Function : sbm_ack_upto_n | |
513 +------------------------------------------------------------------------------ | |
514 | Description : | |
515 | | |
516 | Parameters : n - | |
517 | allFramesAck - | |
518 | | |
519 | Return : - | |
520 +------------------------------------------------------------------------------ | |
521 */ | |
522 | |
523 | |
524 GLOBAL BOOL sbm_ack_upto_n(T_SBM_BUFFER_EXTIDX n) | |
525 { | |
526 TRACE_FUNCTION ("sbm_ack_upto_n()"); | |
527 | |
528 if (n EQ SBM_INVALID_IDX) | |
529 { | |
530 if (rlp_data->sbm.LastSentFrame NEQ SBM_INVALID_IDX) | |
531 { | |
532 n = rlp_data->sbm.LastSentFrame; | |
533 rlp_data->sbm.LastSentFrame = SBM_INVALID_IDX; | |
534 } | |
535 else | |
536 { | |
537 return (rlp_data->sbm.VA EQ rlp_data->sbm.VS); | |
538 } | |
539 } | |
540 | |
541 sbmi_srej_list_delete (rlp_data->sbm.VA, n); | |
542 | |
543 while (rlp_data->sbm.VA NEQ n) | |
544 { | |
545 rlp_data->sbm.Frame[rlp_data->sbm.VA].S_State = SBM_IDLE; | |
546 sbmi_dec_ref_count (rlp_data->sbm.Frame [rlp_data->sbm.VA].PrimSlot1); | |
547 sbmi_dec_ref_count (rlp_data->sbm.Frame [rlp_data->sbm.VA].PrimSlot2); | |
548 rlp_data->sbm.VA = (rlp_data->sbm.VA+1) % SBM_BUF_SIZE; | |
549 } | |
550 | |
551 return (rlp_data->sbm.VA EQ rlp_data->sbm.VS); | |
552 } | |
553 | |
554 /* | |
555 +------------------------------------------------------------------------------ | |
556 | Function : sbm_srej_frame | |
557 +------------------------------------------------------------------------------ | |
558 | Description : | |
559 | | |
560 | Parameters : n - | |
561 | | |
562 | | |
563 | Return : - | |
564 +------------------------------------------------------------------------------ | |
565 */ | |
566 | |
567 | |
568 GLOBAL void sbm_srej_frame | |
569 ( | |
570 T_SBM_BUFFER_INDEX n | |
571 ) | |
572 { | |
573 TRACE_FUNCTION ("sbm_srej_frame()"); | |
574 | |
575 rlp_data->sbm.Frame[n].S_State = SBM_SEND; | |
576 sbmi_srej_list_put (n); | |
577 } | |
578 | |
579 /* | |
580 +------------------------------------------------------------------------------ | |
581 | Function : sbm_get_frame | |
582 +------------------------------------------------------------------------------ | |
583 | Description : | |
584 | | |
585 | Parameters : frameDesc - | |
586 | frameNo - | |
587 | framesCouldBeSent - | |
588 | ok - | |
589 | | |
590 | | |
591 | Return : - | |
592 +------------------------------------------------------------------------------ | |
593 */ | |
594 | |
595 | |
596 GLOBAL void sbm_get_frame | |
597 ( | |
598 T_FRAME_DESC *frameDesc, | |
599 T_SBM_BUFFER_INDEX *frameNo, | |
600 BOOL *framesCouldBeSent, | |
601 BOOL *ok | |
602 ) | |
603 { | |
604 T_SBM_BUFFER_EXTIDX p; | |
605 | |
606 TRACE_FUNCTION ("sbm_get_frame()"); | |
607 | |
608 sbmi_data_to_transmit (&p, framesCouldBeSent); | |
609 | |
610 if (p NEQ SBM_INVALID_IDX) | |
611 { | |
612 sbmi_get_frame_desc (p, frameDesc); | |
613 rlp_data->sbm.Frame[p].S_State = SBM_WAIT; | |
614 *frameNo = rlp_data->sbm.LastSentFrame = p; | |
615 | |
616 *ok = TRUE; | |
617 } | |
618 else | |
619 *ok = FALSE; | |
620 } | |
621 | |
622 /* | |
623 +------------------------------------------------------------------------------ | |
624 | Function : sbm_rej_from_n | |
625 +------------------------------------------------------------------------------ | |
626 | Description : | |
627 | | |
628 | Parameters : n - | |
629 | retransError - | |
630 | | |
631 | Return : | |
632 +------------------------------------------------------------------------------ | |
633 */ | |
634 | |
635 | |
636 GLOBAL void sbm_rej_from_n | |
637 ( | |
638 T_SBM_BUFFER_INDEX n, | |
639 BOOL *retransError | |
640 ) | |
641 { | |
642 | |
643 T_SBM_BUFFER_INDEX ind; | |
644 | |
645 TRACE_FUNCTION ("sbm_rej_from_n()"); | |
646 | |
647 while ( rlp_data->sbm.REJ_BufLo NEQ rlp_data->sbm.REJ_BufHi AND | |
648 !( | |
649 XOR | |
650 ( | |
651 XOR ( | |
652 rlp_data->sbm.REJ_BufLastN > rlp_data->sbm.REJ_Buf[rlp_data->sbm.REJ_BufLo], | |
653 rlp_data->sbm.REJ_Buf[rlp_data->sbm.REJ_BufLo] > n | |
654 ), | |
655 rlp_data->sbm.REJ_BufLastN > n | |
656 ) | |
657 ) | |
658 ) | |
659 rlp_data->sbm.REJ_BufLo = (rlp_data->sbm.REJ_BufLo +1) % rlp_data->sbm.REJ_BufSize; | |
660 | |
661 | |
662 ind = rlp_data->sbm.REJ_BufHi; | |
663 | |
664 while (ind NEQ rlp_data->sbm.REJ_BufLo) | |
665 { | |
666 if(ind EQ 0) | |
667 ind = rlp_data->sbm.REJ_BufSize; | |
668 | |
669 ind--; | |
670 | |
671 if (! XOR( | |
672 XOR( | |
673 n > rlp_data->sbm.REJ_Buf[ind], | |
674 rlp_data->sbm.REJ_Buf[ind] > rlp_data->sbm.VS | |
675 ), | |
676 n > rlp_data->sbm.VS | |
677 ) | |
678 ) | |
679 break; | |
680 | |
681 rlp_data->sbm.REJ_Buf[ind] = rlp_data->sbm.VS; | |
682 } | |
683 | |
684 rlp_data->sbm.REJ_Buf[rlp_data->sbm.REJ_BufHi] = rlp_data->sbm.VS; | |
685 | |
686 rlp_data->sbm.REJ_BufHi = (rlp_data->sbm.REJ_BufHi + 1) % rlp_data->sbm.REJ_BufSize; | |
687 | |
688 rlp_data->sbm.REJ_BufLastN = n; | |
689 | |
690 | |
691 if (rlp_data->sbm.REJ_BufLo EQ rlp_data->sbm.REJ_BufHi) | |
692 { | |
693 *retransError = TRUE; | |
694 return; | |
695 } | |
696 | |
697 *retransError = FALSE; | |
698 | |
699 sbmi_srej_list_delete (n, rlp_data->sbm.VS); | |
700 | |
701 while (rlp_data->sbm.VS NEQ n) | |
702 { | |
703 if (rlp_data->sbm.VS > 0) | |
704 rlp_data->sbm.VS--; | |
705 else | |
706 rlp_data->sbm.VS = SBM_BUF_SIZE-1; | |
707 | |
708 rlp_data->sbm.Frame[rlp_data->sbm.VS].S_State = SBM_SEND; | |
709 } | |
710 } | |
711 | |
712 /* | |
713 +------------------------------------------------------------------------------ | |
714 | Function : sbm_frame_in_range | |
715 +------------------------------------------------------------------------------ | |
716 | Description : | |
717 | | |
718 | Parameters : n - | |
719 | | |
720 | | |
721 | Return : TRUE - | |
722 | FALSE - | |
723 +------------------------------------------------------------------------------ | |
724 */ | |
725 | |
726 | |
727 GLOBAL BOOL sbm_frame_in_range | |
728 ( | |
729 T_SBM_BUFFER_INDEX n | |
730 ) | |
731 { | |
732 TRACE_FUNCTION ("sbm_frame_in_range()"); | |
733 | |
734 return !( XOR | |
735 ( | |
736 XOR | |
737 ( | |
738 rlp_data->sbm.VA > n, | |
739 n > rlp_data->sbm.VS | |
740 ), | |
741 rlp_data->sbm.VA > rlp_data->sbm.VS | |
742 ) | |
743 ); | |
744 } | |
745 | |
746 /* | |
747 +------------------------------------------------------------------------------ | |
748 | Function : sbm_space_in_buf | |
749 +------------------------------------------------------------------------------ | |
750 | Description : | |
751 | | |
752 | Parameters : - | |
753 | | |
754 | | |
755 | Return : ret | |
756 +------------------------------------------------------------------------------ | |
757 */ | |
758 | |
759 | |
760 GLOBAL USHORT sbm_space_in_buf | |
761 ( | |
762 void | |
763 ) | |
764 { | |
765 SHORT ret; | |
766 | |
767 TRACE_FUNCTION ("sbm_space_in_buf()"); | |
768 | |
769 ret = rlp_data->sbm.VA - rlp_data->sbm.VD - 1; | |
770 | |
771 if (ret < 0) | |
772 return (USHORT) (ret + SBM_BUF_SIZE); | |
773 else | |
774 return (USHORT) ret; | |
775 } | |
776 | |
777 /* | |
778 +------------------------------------------------------------------------------ | |
779 | Function : sbm_deinit | |
780 +------------------------------------------------------------------------------ | |
781 | Description : | |
782 | | |
783 | Parameters : - | |
784 | | |
785 | | |
786 | Return : - | |
787 +------------------------------------------------------------------------------ | |
788 */ | |
789 | |
790 | |
791 GLOBAL void sbm_deinit | |
792 ( | |
793 void | |
794 ) | |
795 { | |
796 SHORT n; | |
797 | |
798 TRACE_FUNCTION ("sbm_deinit()"); | |
799 | |
800 n = 0; | |
801 | |
802 while (n < SBM_PRIMBUF_SIZE) | |
803 { | |
804 if (rlp_data->sbm.Prim[n].Prim NEQ NULL) | |
805 { | |
806 PFREE(rlp_data->sbm.Prim[n].Prim); | |
807 rlp_data->sbm.Prim[n].Prim = NULL; | |
808 } | |
809 n++; | |
810 } | |
811 } | |
812 | |
813 /* | |
814 +------------------------------------------------------------------------------ | |
815 | Function : sbm_set_retrans | |
816 +------------------------------------------------------------------------------ | |
817 | Description : | |
818 | | |
819 | Parameters : n2 - | |
820 | | |
821 | | |
822 | Return : - | |
823 +------------------------------------------------------------------------------ | |
824 */ | |
825 | |
826 | |
827 GLOBAL void sbm_set_retrans | |
828 ( | |
829 UBYTE n2 | |
830 ) | |
831 { | |
832 TRACE_FUNCTION ("sbm_set_retrans()"); | |
833 | |
834 rlp_data->sbm.REJ_BufSize = n2 + 1; | |
835 rlp_data->sbm.REJ_BufLo = 0; | |
836 rlp_data->sbm.REJ_BufHi = 0; | |
837 } | |
838 | |
839 /* | |
840 +------------------------------------------------------------------------------ | |
841 | Function : sbm_check_rej_count | |
842 +------------------------------------------------------------------------------ | |
843 | Description : | |
844 | | |
845 | Parameters : retransError | |
846 | | |
847 | | |
848 | Return : - | |
849 +------------------------------------------------------------------------------ | |
850 */ | |
851 | |
852 | |
853 GLOBAL void sbm_check_rej_count | |
854 ( | |
855 BOOL *retransError | |
856 ) | |
857 { | |
858 | |
859 T_SBM_BUFFER_INDEX n; | |
860 | |
861 TRACE_FUNCTION ("sbm_check_rej_count()"); | |
862 | |
863 n = rlp_data->sbm.REJ_BufHi +1; | |
864 | |
865 if (rlp_data->sbm.REJ_BufLo NEQ n) | |
866 { | |
867 if (n NEQ rlp_data->sbm.REJ_BufSize OR | |
868 rlp_data->sbm.REJ_BufLo NEQ 0) | |
869 *retransError = FALSE; | |
870 else | |
871 *retransError = TRUE; | |
872 } | |
873 else | |
874 *retransError = TRUE; | |
875 } | |
876 | |
877 /* | |
878 +------------------------------------------------------------------------------ | |
879 | Function : sbm_recall_prim | |
880 +------------------------------------------------------------------------------ | |
881 | Description : | |
882 | | |
883 | Parameters : prim - | |
884 | | |
885 | | |
886 | Return : TRUE - | |
887 | FALSE - | |
888 +------------------------------------------------------------------------------ | |
889 */ | |
890 | |
891 | |
892 GLOBAL BOOL sbm_recall_prim | |
893 ( | |
894 T_SBM_PRIM **prim | |
895 ) | |
896 { | |
897 T_SBM_PRIM_EXTIDX primSlot; | |
898 T_SBM_PRIM_EXTIDX endPrimSlot; | |
899 T_SBM_PRIM_EXTIDX firstPrimSlot; | |
900 T_SBM_BUFFER_INDEX vend; | |
901 | |
902 TRACE_FUNCTION ("sbm_recall_prim()"); | |
903 | |
904 if (rlp_data->sbm.VA EQ rlp_data->sbm.VD) | |
905 { | |
906 return FALSE; | |
907 } | |
908 | |
909 primSlot = rlp_data->sbm.Frame[rlp_data->sbm.VA].PrimSlot1; | |
910 firstPrimSlot = primSlot; | |
911 | |
912 if (rlp_data->sbm.VD EQ 0) | |
913 { | |
914 vend = SBM_BUF_SIZE - 1; | |
915 } | |
916 else | |
917 { | |
918 vend = rlp_data->sbm.VD - 1; | |
919 } | |
920 | |
921 if (rlp_data->sbm.Frame[vend].Len2 EQ 0) | |
922 { | |
923 endPrimSlot = rlp_data->sbm.Frame[vend].PrimSlot1 + 1; | |
924 } | |
925 else | |
926 { | |
927 endPrimSlot = rlp_data->sbm.Frame[vend].PrimSlot2 + 1; | |
928 } | |
929 | |
930 if (endPrimSlot >= SBM_PRIMBUF_SIZE) | |
931 { | |
932 endPrimSlot = 0; | |
933 } | |
934 | |
935 while ((primSlot NEQ endPrimSlot) AND | |
936 (rlp_data->sbm.Prim[primSlot].Prim EQ NULL)) | |
937 { | |
938 primSlot += 1; | |
939 if (primSlot >= SBM_PRIMBUF_SIZE) | |
940 { | |
941 primSlot = 0; | |
942 } | |
943 } | |
944 | |
945 if (primSlot EQ endPrimSlot) | |
946 { | |
947 return FALSE; | |
948 } | |
949 | |
950 if (primSlot EQ firstPrimSlot) | |
951 { | |
952 /* in the first primitive there may be some frames sent already */ | |
953 rlp_data->sbm.Prim[primSlot].Prim->sdu.l_buf = | |
954 rlp_data->sbm.Prim[primSlot].Prim->sdu.l_buf | |
955 - rlp_data->sbm.Frame[rlp_data->sbm.VA].Offset1 * 8 | |
956 + rlp_data->sbm.Prim[primSlot].Prim->sdu.o_buf; | |
957 | |
958 rlp_data->sbm.Prim[primSlot].Prim->sdu.o_buf = | |
959 rlp_data->sbm.Frame[rlp_data->sbm.VA].Offset1 * 8; | |
960 } | |
961 *prim = rlp_data->sbm.Prim[primSlot].Prim; | |
962 rlp_data->sbm.Prim[primSlot].Prim = NULL; | |
963 rlp_data->sbm.Prim[primSlot].RefCount = 0; | |
964 return TRUE; | |
965 | |
966 } | |
967 | |
968 /* | |
969 +------------------------------------------------------------------------------ | |
970 | Function : sbm_reset_after_remap | |
971 +------------------------------------------------------------------------------ | |
972 | Description : | |
973 | | |
974 | Parameters : newFrameSize - | |
975 | new_vs - | |
976 | | |
977 | Return : - | |
978 +------------------------------------------------------------------------------ | |
979 */ | |
980 | |
981 | |
982 GLOBAL void sbm_reset_after_remap | |
983 ( | |
984 USHORT newFrameSize, | |
985 T_SBM_BUFFER_INDEX new_vs | |
986 ) | |
987 { | |
988 | |
989 | |
990 TRACE_FUNCTION ("sbm_reset_after_remap()"); | |
991 sbmi_srej_list_delete (0, SBM_BUF_SIZE); | |
992 sbm_init | |
993 ( | |
994 rlp_data->sbm.K, | |
995 newFrameSize, | |
996 (UBYTE)(rlp_data->sbm.REJ_BufSize - 1) | |
997 ); | |
998 rlp_data->sbm.VA = new_vs; | |
999 rlp_data->sbm.VS = new_vs; | |
1000 rlp_data->sbm.VD = new_vs; | |
1001 } |