comparison src/g23m-fad/rlp/rlp_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 : CSD (8411)
4 | Modul : Rlp_rbm.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 receive buffer manager for
18 | the component Radio Link Protocol of the base station
19 +-----------------------------------------------------------------------------
20 */
21
22 #ifndef RLP_RBM_C
23 #define RLP_RBM_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 : rbmi_alloc_curr_prim
53 +------------------------------------------------------------------------------
54 | Description :
55 |
56 | Parameters : -
57 |
58 |
59 | Return : -
60 +------------------------------------------------------------------------------
61 */
62
63
64 LOCAL void rbmi_alloc_curr_prim
65 (
66 void
67 )
68 {
69 USHORT sduSize = rlp_data->rbm.FramesPerPrim
70 * rlp_data->rbm.FrameSize * 8;
71
72 PALLOC_SDU
73 (
74 rlp_data_ind,
75 RLP_DATA_IND,
76 sduSize
77 );
78
79 TRACE_FUNCTION ("rbmi_alloc_curr_prim()");
80
81 rlp_data_ind->sdu.l_buf
82 = rlp_data->rbm.FramesPerPrim * rlp_data->rbm.FrameSize * 8;
83
84 rlp_data_ind->data_size = rlp_data->rbm.FrameSize - HEADER_LEN - TRAILER_LEN;
85
86 rlp_data->rbm.CurrPrim = rlp_data_ind;
87 rlp_data->rbm.CurrPrimCou = 0;
88 }
89
90 /*
91 +------------------------------------------------------------------------------
92 | Function : rbmi_pq_enq
93 +------------------------------------------------------------------------------
94 | Description : A primitive is put into the primitive queue. This is done
95 | in rbm_buffer_all_in_sequence_frames when the current
96 | primitive is filled up.
97 |
98 |
99 | Parameters : prim -
100 |
101 |
102 | Return : -
103 +------------------------------------------------------------------------------
104 */
105
106
107 LOCAL void rbmi_pq_enq
108 (
109 T_RBM_PRIM *prim
110 )
111 {
112 TRACE_FUNCTION ("rbmi_pq_enq()");
113
114 rlp_data->rbm.PQ_Array[rlp_data->rbm.PQ_Write] = prim;
115
116 rlp_data->rbm.PQ_Write = (rlp_data->rbm.PQ_Write+1) % RBM_PQ_SIZE;
117 }
118
119 /*
120 +------------------------------------------------------------------------------
121 | Function : rbmi_copy_frame_to_sdu
122 +------------------------------------------------------------------------------
123 | Description :
124 |
125 | Parameters : frame -
126 | sdu -
127 |
128 |
129 | Return : -
130 +------------------------------------------------------------------------------
131 */
132
133
134 LOCAL void rbmi_copy_frame_to_sdu(T_RBM_FRAMEPTR frame, T_sdu *sdu)
135 {
136 TRACE_FUNCTION ("rbmi_copy_frame_to_sdu()");
137
138 memcpy(sdu->buf+(sdu->o_buf>>3), frame, rlp_data->rbm.FrameSize);
139
140 sdu->o_buf += rlp_data->rbm.FrameSize * 8;
141 }
142
143 /*
144 +------------------------------------------------------------------------------
145 | Function : rbmi_buffer_frame
146 +------------------------------------------------------------------------------
147 | Description :
148 |
149 | Parameters : fromSlot -
150 | primIsReady -
151 |
152 | Return : -
153 +------------------------------------------------------------------------------
154 */
155
156
157 LOCAL void rbmi_buffer_frame
158 (
159 T_RBM_BUFFER_EXTIDX fromSlot,
160 BOOL *primIsReady
161 )
162 {
163 TRACE_FUNCTION ("rbmi_buffer_frame()");
164
165 rbmi_copy_frame_to_sdu
166 (
167 rlp_data->rbm.Slot[fromSlot].Frame,
168 &rlp_data->rbm.CurrPrim->sdu
169 );
170
171 if (++rlp_data->rbm.CurrPrimCou EQ rlp_data->rbm.FramesPerPrim)
172 {
173 rlp_data->rbm.CurrPrim->sdu.o_buf = 0;
174 rbmi_pq_enq (rlp_data->rbm.CurrPrim);
175 rbmi_alloc_curr_prim ();
176 *primIsReady = TRUE;
177 }
178 }
179
180
181 /*
182 +------------------------------------------------------------------------------
183 | Function : rbmi_pq_deq
184 +------------------------------------------------------------------------------
185 | Description : A rlp_data_ind primitive is taken from the queue. This
186 | is done when the queue is not empty and a RLP_GETDATA_REQ
187 | is executed. Of after storing a primitive in the queue,
188 | when the upper layer is waiting for data.
189 |
190 | Parameters : prim -
191 |
192 |
193 | Return : TRUE -
194 | FALSE -
195 +------------------------------------------------------------------------------
196 */
197
198
199 LOCAL BOOL rbmi_pq_deq
200 (
201 T_RBM_PRIM **prim
202 )
203 {
204 TRACE_FUNCTION ("rbmi_pq_deq()");
205
206 if (rlp_data->rbm.PQ_Read NEQ rlp_data->rbm.PQ_Write)
207 {
208 *prim = rlp_data->rbm.PQ_Array[rlp_data->rbm.PQ_Read];
209 rlp_data->rbm.PQ_Array[rlp_data->rbm.PQ_Read] = (T_RBM_PRIM *) NULL;
210
211 rlp_data->rbm.PQ_Read = (rlp_data->rbm.PQ_Read+1) % RBM_PQ_SIZE;
212 return TRUE;
213 }
214 else
215 {
216 /*
217 * prim buffer is empty
218 */
219 return FALSE;
220 }
221 }
222
223 /*
224 +------------------------------------------------------------------------------
225 | Function : rbmi_pq_check
226 +------------------------------------------------------------------------------
227 | Description : The prim queue is checked.
228 | rcvReady indicates that there is still more than the
229 | minimum space in the queue.
230 | rcvFull indicates that the queue is completeley full.
231 |
232 |
233 | Parameters : rcvReady -
234 | rcvFull -
235 |
236 | Return : -
237 +------------------------------------------------------------------------------
238 */
239
240
241 LOCAL void rbmi_pq_check
242 (
243 BOOL *rcvReady,
244 BOOL *rcvFull
245 )
246 {
247 T_RBM_PQ_INDEX writeMax, writeThresh;
248
249 TRACE_FUNCTION ("rbmi_pq_check()");
250
251 writeMax = (rlp_data->rbm.PQ_Read + RBM_PQ_MAX_PRIM)
252 % RBM_PQ_SIZE;
253
254 writeThresh = (rlp_data->rbm.PQ_Read + RBM_PQ_THRE_RNR)
255 % RBM_PQ_SIZE;
256
257 /*
258 * prim queue filled upto threshold?
259 */
260
261 if (!(XOR
262 (
263 XOR
264 (
265 writeThresh > rlp_data->rbm.PQ_Write,
266 rlp_data->rbm.PQ_Write > writeMax
267 ),
268 writeThresh > writeMax
269 )
270 )
271 )
272 {
273 *rcvReady = FALSE;
274
275 *rcvFull = (rlp_data->rbm.PQ_Write EQ writeMax);
276 }
277 else
278 {
279 *rcvFull = FALSE;
280 *rcvReady = TRUE;
281 }
282 }
283
284 /*
285 +------------------------------------------------------------------------------
286 | Function : rbm_set_wind_size
287 +------------------------------------------------------------------------------
288 | Description :
289 |
290 | Parameters : windSize -
291 |
292 |
293 | Return : TRUE -
294 | FALSE -
295 +------------------------------------------------------------------------------
296 */
297
298
299 GLOBAL BOOL rbm_set_wind_size
300 (
301 T_RBM_BUFFER_INDEX windSize
302 )
303 {
304 BOOL resetTimers;
305 T_RBM_BUFFER_INDEX n;
306 T_RBM_BUFFER_INDEX nEnd;
307 T_RBM_BUFFER_INDEX oldSize;
308
309 TRACE_FUNCTION ("rbm_set_wind_size()");
310
311 resetTimers = FALSE;
312 oldSize = rlp_data->rbm.K;
313 rlp_data->rbm.K = windSize;
314
315 if (windSize < oldSize)
316 {
317 n = rlp_data->rbm.VR + windSize;
318 if (n >= RBM_BUF_SIZE)
319 {
320 n -= RBM_BUF_SIZE;
321 }
322 nEnd = rlp_data->rbm.VR + oldSize;
323 if (nEnd >= RBM_BUF_SIZE)
324 {
325 nEnd -= RBM_BUF_SIZE;
326 }
327 do
328 {
329 switch (rlp_data->rbm.Slot[n].R_State)
330 {
331 case RBM_SREJ:
332 case RBM_WAIT:
333 resetTimers = TRUE;
334 rlp_data->rbm.Slot[n].R_State = RBM_IDLE;
335 break;
336 default:
337 break;
338 }
339 n += 1;
340 if (n >= RBM_BUF_SIZE)
341 {
342 n = 0;
343 }
344
345 } while (n NEQ nEnd);
346 }
347 return (resetTimers);
348 }
349
350 /*
351 +------------------------------------------------------------------------------
352 | Function : rbm_init
353 +------------------------------------------------------------------------------
354 | Description :
355 |
356 | Parameters : windSize -
357 | frameSize -
358 | framesPerPrim -
359 |
360 | Return : -
361 +------------------------------------------------------------------------------
362 */
363
364
365 GLOBAL void rbm_init
366 (
367 T_RBM_BUFFER_INDEX windSize,
368 USHORT frameSize,
369 USHORT framesPerPrim
370 )
371 {
372 USHORT n;
373
374 TRACE_FUNCTION ("rbm_init()");
375
376 n = 0;
377
378 rlp_data->rbm.FramesPerPrim = framesPerPrim;
379 rlp_data->rbm.FrameSize = frameSize;
380
381 for (n = 0; n < RBM_BUF_SIZE; n++)
382 {
383 rlp_data->rbm.Slot[n].R_State = RBM_IDLE;
384
385 memset
386 (
387 rlp_data->rbm.Slot[n].Frame,
388 0,
389 rlp_data->rbm.FrameSize
390 );
391 }
392
393 rlp_data->rbm.VR = 0;
394 rlp_data->rbm.FrameInRiBu = FALSE;
395
396 memset
397 (
398 rlp_data->rbm.Frame,
399 0,
400 rlp_data->rbm.FrameSize
401 );
402
403 for (n = 0; n < RBM_PQ_SIZE; n++)
404 rlp_data->rbm.PQ_Array[n] = (T_RBM_PRIM *) NULL;
405
406
407 rlp_data->rbm.PQ_Read = 0;
408 rlp_data->rbm.PQ_Write = 0;
409
410 rbmi_alloc_curr_prim ();
411 rlp_data->rbm.K = windSize;
412
413 rlp_data->rbm.Initialised = TRUE;
414 }
415
416 /*
417 +------------------------------------------------------------------------------
418 | Function : rbm_deinit
419 +------------------------------------------------------------------------------
420 | Description : This function frees all allocated T_RBM_PRIM primitives
421 | of the receive buffer manager.
422 |
423 | Parameters :
424 |
425 |
426 | Return :
427 +------------------------------------------------------------------------------
428 */
429
430
431 GLOBAL void rbm_deinit
432 (
433 void
434 )
435 {
436 TRACE_FUNCTION ("rbm_deinit()");
437
438 rlp_data->rbm.Initialised = FALSE;
439
440 if (rlp_data->rbm.CurrPrim NEQ (T_RBM_PRIM *) NULL)
441 {
442 PFREE (rlp_data->rbm.CurrPrim)
443 rlp_data->rbm.CurrPrim = (T_RBM_PRIM *) NULL;
444 }
445
446 while (rlp_data->rbm.PQ_Read NEQ rlp_data->rbm.PQ_Write)
447 {
448 if (rlp_data->rbm.PQ_Array[rlp_data->rbm.PQ_Read]
449 NEQ (T_RBM_PRIM *) NULL)
450 {
451 PFREE (rlp_data->rbm.PQ_Array[rlp_data->rbm.PQ_Read])
452 rlp_data->rbm.PQ_Array[rlp_data->rbm.PQ_Read]
453 = (T_RBM_PRIM *) NULL;
454 }
455 rlp_data->rbm.PQ_Read = (rlp_data->rbm.PQ_Read+1) % RBM_PQ_SIZE;
456 }
457
458 }
459
460 /*
461 +------------------------------------------------------------------------------
462 | Function : rbm_reset
463 +------------------------------------------------------------------------------
464 | Description : This function must be called once at startup before any
465 | other procedures of the RBM is invoked. (Coldstart)
466 |
467 |
468 | Parameters : rlp_data_ptr -
469 |
470 |
471 | Return : -
472 +------------------------------------------------------------------------------
473 */
474
475
476 GLOBAL void rbm_reset(T_RBM *rbm)
477 {
478 TRACE_FUNCTION ("rbm_reset()");
479
480 rbm->CurrPrim = (T_RBM_PRIM *) NULL;
481 rbm->CurrPrimCou = 0;
482 rbm->K = 0;
483 rbm->FrameInRiBu = FALSE;
484 rbm->FrameSize = FRAME_SIZE_SHORT;
485 rbm->PQ_Read = 0;
486 rbm->PQ_Write = 0;
487 rbm->Initialised = FALSE;
488 }
489
490 /*
491 +------------------------------------------------------------------------------
492 | Function : rbm_reset_srej_slots
493 +------------------------------------------------------------------------------
494 | Description :
495 |
496 | Parameters : -
497 |
498 |
499 | Return : -
500 +------------------------------------------------------------------------------
501 */
502
503
504 GLOBAL void rbm_reset_srej_slots
505 (
506 void
507 )
508 {
509 T_RBM_BUFFER_INDEX n;
510
511 TRACE_FUNCTION ("rbm_reset_srej_slots()");
512
513 for (n = 0; n < RBM_BUF_SIZE; n++)
514 {
515 switch (rlp_data->rbm.Slot[n].R_State)
516 {
517 case RBM_WAIT:
518 case RBM_SREJ:
519 rlp_data->rbm.Slot[n].R_State = RBM_IDLE;
520 return;
521
522 default:
523 break;
524 }
525 }
526 }
527
528 /*
529 +------------------------------------------------------------------------------
530 | Function : rbm_reset_all_r_states
531 +------------------------------------------------------------------------------
532 | Description :
533 |
534 | Parameters : -
535 |
536 |
537 | Return : -
538 +------------------------------------------------------------------------------
539 */
540
541
542 GLOBAL void rbm_reset_all_r_states
543 (
544 void
545 )
546 {
547 T_RBM_BUFFER_INDEX n;
548
549 TRACE_FUNCTION ("rbm_reset_all_r_states()");
550
551 for (n = 0; n < RBM_BUF_SIZE; n++)
552 rlp_data->rbm.Slot[n].R_State = RBM_IDLE;
553 }
554
555 /*
556 +------------------------------------------------------------------------------
557 | Function : rbm_check_slots_srej
558 +------------------------------------------------------------------------------
559 | Description : Checks wheter a received slot is to be SREJted.
560 | Returns RBM_INVALID: IDX if No SREJ pending
561 | 0..n : Slot num to be SREJted
562 |
563 | Parameters : -
564 |
565 |
566 | Return : n -
567 | RBM_INVALID_IDX -
568 +------------------------------------------------------------------------------
569 */
570
571
572 GLOBAL T_RBM_BUFFER_EXTIDX rbm_check_slots_srej(void)
573 {
574 T_RBM_BUFFER_INDEX n;
575
576 TRACE_FUNCTION ("rbm_check_slots_srej()");
577
578 n = rlp_data->rbm.VR;
579
580 do
581 {
582 switch (rlp_data->rbm.Slot[n].R_State)
583 {
584 case RBM_IDLE:
585 return RBM_INVALID_IDX;
586
587 case RBM_SREJ:
588 return n;
589
590 default:
591 n = (n+1) % RBM_BUF_SIZE;
592 break;
593 }
594 }
595 while (n NEQ rlp_data->rbm.VR);
596
597 return RBM_INVALID_IDX;
598 }
599
600 /*
601 +------------------------------------------------------------------------------
602 | Function : rbm_set_rslot_wait
603 +------------------------------------------------------------------------------
604 | Description :
605 |
606 | Parameters : slot -
607 |
608 |
609 | Return : -
610 +------------------------------------------------------------------------------
611 */
612
613
614 GLOBAL void rbm_set_rslot_wait
615 (
616 T_RBM_BUFFER_INDEX slot
617 )
618 {
619 TRACE_FUNCTION ("rbm_set_rslot_wait()");
620
621 rlp_data->rbm.Slot[slot].R_State = RBM_WAIT;
622 }
623
624 /*
625 +------------------------------------------------------------------------------
626 | Function : rbm_set_rslot_wait2srej
627 +------------------------------------------------------------------------------
628 | Description :
629 |
630 | Parameters : slot -
631 |
632 |
633 | Return : -
634 +------------------------------------------------------------------------------
635 */
636
637
638 GLOBAL void rbm_set_rslot_wait2srej
639 (
640 T_RBM_BUFFER_INDEX slot
641 )
642 {
643 TRACE_FUNCTION ("rbm_set_rslot_wait2srej()");
644
645 rlp_data->rbm.Slot[slot].R_State = RBM_SREJ;
646 }
647
648 /*
649 +------------------------------------------------------------------------------
650 | Function : rbm_set_rslot_rcvd
651 +------------------------------------------------------------------------------
652 | Description :
653 |
654 | Parameters : slot -
655 | resetTimer -
656 |
657 | Return : -
658 +------------------------------------------------------------------------------
659 */
660
661
662 GLOBAL void rbm_set_rslot_rcvd
663 (
664 T_RBM_BUFFER_EXTIDX slot,
665 BOOL *resetTimer
666 )
667 {
668 TRACE_FUNCTION ("rbm_set_rslot_rcvd()");
669
670 if(slot EQ RBM_INVALID_IDX)
671 slot = rlp_data->rbm.LastVR;
672
673 switch (rlp_data->rbm.Slot[slot].R_State)
674 {
675 case RBM_WAIT:
676 *resetTimer = TRUE;
677 break;
678
679 default:
680 *resetTimer = FALSE;
681 break;
682 }
683
684 rlp_data->rbm.Slot[slot].R_State = RBM_RCVD;
685 }
686
687 /*
688 +------------------------------------------------------------------------------
689 | Function : rbm_get_current_frame
690 +------------------------------------------------------------------------------
691 | Description : This function returns the current - i.e. last stored -
692 | frame of the receive buffer. The frame may be in the ring
693 | buffer or in the static buffer.
694 |
695 | Parameters : -
696 |
697 |
698 | Return : -
699 +------------------------------------------------------------------------------
700 */
701
702
703 GLOBAL T_RBM_FRAMEPTR rbm_get_current_frame
704 (
705 void
706 )
707 {
708
709 T_RBM_FRAMEPTR frame;
710
711 TRACE_FUNCTION ("rbm_get_current_frame()");
712
713 if (rlp_data->rbm.FrameInRiBu)
714 frame = rlp_data->rbm.Slot[rlp_data->rbm.VR].Frame;
715 else
716 frame = rlp_data->rbm.Frame;
717
718 return frame;
719 }
720
721 /*
722 +------------------------------------------------------------------------------
723 | Function : rbm_accept_current_frame
724 +------------------------------------------------------------------------------
725 | Description : This function advances VR to make sure, that the next
726 | frame is stored in the next free slot.
727 |
728 | Parameters : -
729 |
730 |
731 | Return : -
732 +------------------------------------------------------------------------------
733 */
734
735
736 GLOBAL void rbm_accept_current_frame
737 (
738 void
739 )
740 {
741 TRACE_FUNCTION ("rbm_accept_current_frame()");
742
743 rlp_data->rbm.LastVR = rlp_data->rbm.VR;
744
745 do
746 {
747 rlp_data->rbm.VR = (rlp_data->rbm.VR +1) % RBM_BUF_SIZE;
748 } while (rlp_data->rbm.Slot[rlp_data->rbm.VR].R_State EQ RBM_RCVD);
749 }
750
751 /*
752 +------------------------------------------------------------------------------
753 | Function : rbm_mark_missing_i_frames_srej
754 +------------------------------------------------------------------------------
755 | Description :
756 |
757 | Parameters : ns -
758 |
759 |
760 | Return : -
761 +------------------------------------------------------------------------------
762 */
763
764
765 GLOBAL void rbm_mark_missing_i_frames_srej
766 (
767 T_RBM_BUFFER_INDEX ns
768 )
769 {
770 T_RBM_BUFFER_INDEX n;
771
772 TRACE_FUNCTION ("rbm_mark_missing_i_frames_srej()");
773
774 n = rlp_data->rbm.VR;
775
776 do
777 {
778 switch (rlp_data->rbm.Slot[n].R_State)
779 {
780 case RBM_IDLE:
781 rlp_data->rbm.Slot[n].R_State = RBM_SREJ;
782 break;
783
784 default:
785 break;
786 }
787
788 n = (n+1) % RBM_BUF_SIZE;
789 }
790 while (n NEQ ns);
791 }
792
793 /*
794 +------------------------------------------------------------------------------
795 | Function : rbm_count_missing_i_frames
796 +------------------------------------------------------------------------------
797 | Description : Counts all slots in R buffer, which will be marked by
798 | rbm_mark_missing_i_frames_srej
799 |
800 | Parameters : ns -
801 | count -
802 |
803 | Return : -
804 +------------------------------------------------------------------------------
805 */
806
807
808 GLOBAL void rbm_count_missing_i_frames
809 (
810 T_RBM_BUFFER_INDEX ns,
811 T_RBM_BUFFER_INDEX *count
812 )
813 {
814 T_RBM_BUFFER_INDEX n;
815
816 TRACE_FUNCTION ("rbm_count_missing_i_frames()");
817
818 *count = 0;
819 n = rlp_data->rbm.VR;
820
821 do
822 {
823 switch (rlp_data->rbm.Slot[n].R_State)
824 {
825 case RBM_IDLE:
826 (*count)++;
827 break;
828
829 default:
830 break;
831 }
832
833 n = (n+1) % RBM_BUF_SIZE;
834 }
835 while (n NEQ ns);
836 }
837
838 /*
839 +------------------------------------------------------------------------------
840 | Function : rbm_buffer_all_in_sequence_frames
841 +------------------------------------------------------------------------------
842 | Description :
843 |
844 | Parameters : fromSlot -
845 | primIsReady -
846 | rcvReady -
847 | rcvFull -
848 |
849 | Return : -
850 +------------------------------------------------------------------------------
851 */
852
853
854 GLOBAL void rbm_buffer_all_in_sequence_frames
855 (
856 T_RBM_BUFFER_EXTIDX fromSlot,
857 BOOL *primIsReady,
858 BOOL *rcvReady,
859 BOOL *rcvFull
860 )
861 {
862 TRACE_FUNCTION ("rbm_buffer_all_in_sequence_frames()");
863
864 if(fromSlot EQ RBM_INVALID_IDX)
865 fromSlot = rlp_data->rbm.LastVR;
866
867 *primIsReady = FALSE;
868
869 do
870 {
871 rbmi_buffer_frame (fromSlot, primIsReady);
872 rlp_data->rbm.Slot[fromSlot].R_State = RBM_IDLE;
873 fromSlot = (fromSlot + 1) % RBM_BUF_SIZE;
874 } while (rlp_data->rbm.Slot[fromSlot].R_State EQ RBM_RCVD);
875
876 rbmi_pq_check (rcvReady, rcvFull);
877 }
878
879 /*
880 +------------------------------------------------------------------------------
881 | Function : rbm_ns_check
882 +------------------------------------------------------------------------------
883 | Description :
884 |
885 | Parameters : ns -
886 | valid -
887 | expected -
888 |
889 | Return : -
890 +------------------------------------------------------------------------------
891 */
892
893
894 GLOBAL void rbm_ns_check
895 (
896 T_RBM_BUFFER_INDEX ns,
897 BOOL *valid,
898 BOOL *expected
899 )
900 {
901 USHORT max_ns;
902
903 TRACE_FUNCTION ("rbm_ns_check()");
904
905 if(rlp_data->rbm.K EQ 0)
906 {
907 *valid = FALSE;
908 *expected = FALSE;
909 return;
910 }
911
912
913 max_ns = (rlp_data->rbm.VR + rlp_data->rbm.K -1) % RBM_BUF_SIZE;
914 /*
915 * ns within Window?
916 */
917 if (!(XOR
918 (
919 XOR
920 (
921 rlp_data->rbm.VR > ns,
922 ns > max_ns
923 ),
924 rlp_data->rbm.VR > max_ns
925 )
926 )
927 )
928 {
929 *valid = TRUE;
930 *expected = (ns EQ rlp_data->rbm.VR);
931 }
932 else
933 {
934 *valid = FALSE;
935 *expected = FALSE;
936 }
937 }
938
939 /*
940 +------------------------------------------------------------------------------
941 | Function : rbm_get_vr
942 +------------------------------------------------------------------------------
943 | Description :
944 |
945 | Parameters : -
946 |
947 |
948 | Return : VR
949 +------------------------------------------------------------------------------
950 */
951
952
953 GLOBAL T_RBM_BUFFER_INDEX rbm_get_vr
954 (
955 void
956 )
957 {
958 TRACE_FUNCTION ("rbm_get_vr()");
959
960 return rlp_data->rbm.VR;
961 }
962
963 /*
964 +------------------------------------------------------------------------------
965 | Function : rbm_get_prim
966 +------------------------------------------------------------------------------
967 | Description : This is just a wrapper for rbmi_pq_deq. The queu is an
968 | internal matter of the RBM, therefore the function
969 | rbmi_pq_deq should not be used directly by the user.
970 |
971 | Parameters : prim -
972 | rcvReady -
973 | rcvFull -
974 |
975 | Return : -
976 +------------------------------------------------------------------------------
977 */
978
979
980 GLOBAL BOOL rbm_get_prim
981 (
982 T_RBM_PRIM **prim,
983 BOOL *rcvReady,
984 BOOL *rcvFull
985 )
986 {
987 BOOL primFound;
988 TRACE_FUNCTION ("rbm_get_prim()");
989
990 primFound = rbmi_pq_deq (prim);
991 if (primFound)
992 {
993 rbmi_pq_check(rcvReady, rcvFull);
994 }
995 return primFound;
996 }
997
998 /*
999 +------------------------------------------------------------------------------
1000 | Function : rbm_get_curr_prim
1001 +------------------------------------------------------------------------------
1002 | Description :
1003 |
1004 | Parameters : -
1005 |
1006 |
1007 | Return : prim
1008 +------------------------------------------------------------------------------
1009 */
1010
1011
1012 GLOBAL T_RBM_PRIM *rbm_get_curr_prim
1013 (
1014 void
1015 )
1016 {
1017 T_RBM_PRIM *prim;
1018
1019 TRACE_FUNCTION ("rbm_get_curr_prim()");
1020
1021 rlp_data->rbm.CurrPrim->sdu.l_buf
1022 = rlp_data->rbm.CurrPrimCou * rlp_data->rbm.FrameSize * 8;
1023
1024 rlp_data->rbm.CurrPrim->sdu.o_buf = 0;
1025
1026 prim = rlp_data->rbm.CurrPrim;
1027
1028 rbmi_alloc_curr_prim ();
1029
1030 return prim;
1031 }
1032
1033 /*
1034 +------------------------------------------------------------------------------
1035 | Function : rbm_move_current_frame
1036 +------------------------------------------------------------------------------
1037 | Description :
1038 |
1039 | Parameters :
1040 |
1041 |
1042 | Return :
1043 +------------------------------------------------------------------------------
1044 */
1045
1046
1047
1048 GLOBAL void rbm_move_current_frame
1049 (
1050 T_RBM_BUFFER_INDEX slot
1051 )
1052 {
1053 TRACE_FUNCTION ("rbm_move_current_frame()");
1054
1055 memcpy
1056 (
1057 rlp_data->rbm.Slot[slot].Frame,
1058 rlp_data->rbm.Slot[rlp_data->rbm.VR].Frame,
1059 rlp_data->rbm.FrameSize
1060 );
1061 }
1062
1063 /*
1064 +------------------------------------------------------------------------------
1065 | Function : rbm_is_state_wait
1066 +------------------------------------------------------------------------------
1067 | Description : This function is called from the HISR. It returns the
1068 | frame descriptor for the buffer, in which the HISR has to
1069 | write the received frame.
1070 |
1071 |
1072 | Parameters : slot -
1073 |
1074 |
1075 | Return : TRUE -
1076 | FALSE -
1077 +------------------------------------------------------------------------------
1078 */
1079
1080
1081 GLOBAL BOOL rbm_is_state_wait
1082 (
1083 T_RBM_BUFFER_INDEX slot
1084 )
1085 {
1086 TRACE_FUNCTION ("rbm_is_state_wait()");
1087
1088 if (rlp_data->rbm.Slot[slot].R_State EQ RBM_WAIT)
1089 return TRUE;
1090 else
1091 return FALSE;
1092 }
1093
1094 /*
1095 +------------------------------------------------------------------------------
1096 | Function : rbm_prepare_remap
1097 +------------------------------------------------------------------------------
1098 | Description :
1099 |
1100 | Parameters : frameSize -
1101 |
1102 |
1103 | Return :
1104 +------------------------------------------------------------------------------
1105 */
1106
1107
1108 GLOBAL T_FRAME_NUM rbm_prepare_remap
1109 (
1110 USHORT frameSize
1111 )
1112 {
1113 T_RBM_PRIM *prim;
1114 USHORT oldFrameSize;
1115 USHORT currPrimCou;
1116
1117 TRACE_FUNCTION ("rbm_prepare_remap()");
1118
1119 oldFrameSize = rlp_data->rbm.FrameSize;
1120 currPrimCou = rlp_data->rbm.CurrPrimCou;
1121
1122 rlp_data->rbm.FrameSize = frameSize;
1123
1124 prim = rbm_get_curr_prim ();
1125
1126 prim->sdu.l_buf = currPrimCou * oldFrameSize * 8;
1127
1128 rbmi_pq_enq (prim);
1129
1130 return (rbm_get_vr());
1131 }
1132
1133 #ifdef _SIMULATION_
1134 /*
1135 +------------------------------------------------------------------------------
1136 | Function : rbm_store_frame
1137 +------------------------------------------------------------------------------
1138 | Description : This procedure is only used in the simulation environment
1139 | to store a frame in the receive buffer.
1140 | In the implementation the copy is performed
1141 | by the RA adaptation layer
1142 | which has access to the shared memory area of the DSP.
1143 |
1144 | Parameters : frame -
1145 |
1146 | Return : -
1147 +------------------------------------------------------------------------------
1148 */
1149
1150 GLOBAL void rbm_store_frame(T_RBM_FRAMEPTR frame)
1151 {
1152 TRACE_FUNCTION ("rbm_store_frame()");
1153
1154 if (rlp_data->rbm.Initialised)
1155 {
1156 memcpy
1157 (
1158 rlp_data->rbm.Slot[rlp_data->rbm.VR].Frame,
1159 frame,
1160 rlp_data->rbm.FrameSize
1161 );
1162
1163 rlp_data->rbm.FrameInRiBu = TRUE;
1164 }
1165 else
1166 {
1167 memcpy
1168 (
1169 rlp_data->rbm.Frame,
1170 frame,
1171 rlp_data->rbm.FrameSize
1172 );
1173
1174 rlp_data->rbm.FrameInRiBu = FALSE;
1175 }
1176 }
1177 #endif
1178
1179 #ifdef _TARGET_
1180 /*
1181 +------------------------------------------------------------------------------
1182 | Function : rlp_rbm_get_next_buffer
1183 +------------------------------------------------------------------------------
1184 | Description : This function is called from the HISR. It returns the
1185 | frame descriptor for the buffer, in which the HISR has to
1186 | write the received frame.
1187 |
1188 |
1189 | Parameters : frameDesc -
1190 |
1191 |
1192 | Return : -
1193 +------------------------------------------------------------------------------
1194 */
1195
1196
1197 GLOBAL void rlp_rbm_get_next_buffer(T_FRAME_DESC *frameDesc)
1198 {
1199 TRACE_FUNCTION ("rbm_get_next_buffer()");
1200
1201 if (rlp_data->rbm.Initialised)
1202 {
1203 frameDesc->Adr[0] = rlp_data->rbm.Slot[rlp_data->rbm.VR].Frame;
1204 rlp_data->rbm.FrameInRiBu = TRUE;
1205 }
1206 else
1207 {
1208 frameDesc->Adr[0] = rlp_data->rbm.Frame;
1209 rlp_data->rbm.FrameInRiBu = FALSE;
1210 }
1211
1212 frameDesc->Len[0] = rlp_data->rbm.FrameSize;
1213 frameDesc->Adr[1] = (UBYTE *) NULL;
1214 frameDesc->Len[1] = 0;
1215 }
1216 #endif
1217