comparison src/g23m-fad/fad/fad_sndf.c @ 1:fa8dc04885d8

src/g23m-*: import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:25:50 +0000
parents
children
comparison
equal deleted inserted replaced
0:4e78acac3d88 1:fa8dc04885d8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-F&D (8411)
4 | Modul : FAD_SNDF
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 procedures and functions for
18 | the SND subcomponent SEQ (sequencer)
19 +-----------------------------------------------------------------------------
20 */
21
22 #ifndef FAD_SNDF_C
23 #define FAD_SNDF_C
24 #endif
25
26 #define ENTITY_FAD
27
28 /*==== INCLUDES ===================================================*/
29
30 #include <string.h>
31 #include "typedefs.h"
32 #include "vsi.h"
33 #include "macdef.h"
34 #include "pconst.cdg"
35 #include "custom.h"
36 #include "gsm.h"
37 #include "cnf_fad.h"
38 #include "mon_fad.h"
39 #include "prim.h"
40 #include "pei.h"
41 #include "tok.h"
42 #include "ccdapi.h"
43 #include "fad.h"
44 #include "ra_l1int.h"
45
46 /*==== CONST =======================================================*/
47
48 /*==== TYPES =======================================================*/
49
50 /*==== VAR EXPORT ==================================================*/
51
52 /*==== VAR LOCAL ===================================================*/
53
54 /*==== FUNCTIONS ===================================================*/
55
56 /*
57 +--------------------------------------------------------------------+
58 | PROJECT : GSM-F&D (8411) MODULE : FAD_SNDF |
59 | STATE : code ROUTINE : snd_init |
60 +--------------------------------------------------------------------+
61
62 PURPOSE : initialise the sequencer
63
64 */
65
66 GLOBAL void snd_init (void)
67 {
68 T_SND *snd = &fad_data->snd;
69 T_SBM *sbm = &fad_data->sbm;
70
71 TRACE_FUNCTION ("snd_init()");
72
73 snd->bytes_to_send = REPEAT_FOREVER;
74 snd->ra_req_frames = 0;
75 snd->reset = SYNC_RESET;
76 snd->send_ready_to_t30 = FALSE;
77 snd->seq_buflen = 0;
78 snd->seq_bufpos = 0;
79 snd->data_bufpos = 0;
80 snd->fad_data_req = NULL;
81
82 sbm->FrameSize = FRAME_SIZE;
83 sbm->syncCycle = SYNC_CYCLE_NONE;
84 sbm->framesUntilSync = 0;
85
86 snd_SetSequence (snd->seq_buf, &snd->seq_buflen, (UBYTE*)FR_SEQ_SYNC, LEN_SEQ_SYNC, 3);
87 }
88
89
90 /*
91 +--------------------------------------------------------------------+
92 | PROJECT : GSM-F&D (8411) MODULE : FAD_SNDF |
93 | STATE : code ROUTINE : snd_setupTCF |
94 +--------------------------------------------------------------------+
95
96 PURPOSE : initialise the sequencer for TCF
97
98 */
99
100 LOCAL void snd_setupTCF (void)
101 {
102 T_SND *snd = &fad_data->snd;
103
104 snd->seq_buflen = 0;
105
106 switch (snd->trans_rate)
107 {
108 case R_12000: /* 5 Data frames + 1 SYNC frame */
109 snd_SetSequence(snd->seq_buf, &snd->seq_buflen, (UBYTE*)FR_SEQ_TCF, LEN_SEQ_TCF, 5);
110 snd_SetSequence(&snd->seq_buf [snd->seq_buflen], &snd->seq_buflen, (UBYTE*)FR_SEQ_SYNC, LEN_SEQ_SYNC, 1);
111 TRACE_EVENT ("setup TCF 12kbps");
112 break;
113
114 case R_7200: /* 3 Data frames + 1 SYNC frame */
115 snd_SetSequence(snd->seq_buf, &snd->seq_buflen, (UBYTE*)FR_SEQ_TCF, LEN_SEQ_TCF, 3);
116 snd_SetSequence(&snd->seq_buf [snd->seq_buflen], &snd->seq_buflen, (UBYTE*)FR_SEQ_SYNC, LEN_SEQ_SYNC, 1);
117 TRACE_EVENT ("setup TCF 7.2kbps");
118 break;
119
120 case R_14400: /* 5 Data frames */
121 case R_9600:
122 case R_4800:
123 case R_2400:
124 default:
125 snd_SetSequence (snd->seq_buf, &snd->seq_buflen, (UBYTE *)FR_SEQ_TCF, LEN_SEQ_TCF, 5);
126 TRACE_EVENT ("setup norm TCF");
127 break;
128 }
129 }
130
131 /*
132 +-------------------------------------------------------------------------+
133 | PROJECT : GSM-F&D (8411) MODULE : FAD_SNDS |
134 | STATE : code ROUTINE : snd_SendReset |
135 +-------------------------------------------------------------------------+
136
137 PURPOSE : Send SYNC frames following return to IDLE state
138
139 */
140
141 GLOBAL void snd_SendReset (USHORT bytes_to_send)
142 {
143 T_SND *snd = &fad_data->snd;
144
145 TRACE_FUNCTION ("snd_SendReset()");
146
147 if (snd->reset)
148 {
149 snd->reset--;
150 snd_SendSequence (bytes_to_send, FR_SYNC);
151 }
152
153 if (!snd->reset)
154 {
155 snd->seq_buflen = 0;
156 snd->seq_bufpos = 0;
157
158 switch (GET_STATE (SND))
159 {
160 case PREAM_SND:
161 snd->bytes_to_send = PREAMBLE_BYTES_TI_SND;
162 snd_SetSequence (snd->seq_buf, &snd->seq_buflen, (UBYTE*)FR_SEQ_PREAMBLE, LEN_SEQ_PREAMBLE, 12);
163 break;
164
165 case TCF_SND:
166 snd->bytes_to_send = snd_DurationToBytes (snd->trans_rate, TIME_TCF_SND);
167 snd_setupTCF(); /* set the sequencer for the TCF pattern */
168 break;
169
170 case TRAIN_SND:
171 #ifdef _SIMULATION_
172 snd_SetSequence (snd->seq_buf, &snd->seq_buflen, (UBYTE*)FR_SEQ_TRAIN_SND, LEN_SEQ_TRAIN, 4);
173 snd_SetSequence (&snd->seq_buf [snd->seq_buflen], &snd->seq_buflen, (UBYTE*)FR_SEQ_SYNC, LEN_SEQ_SYNC, 1);
174 #else /* TI: only 2 bytes set - no SYNCs */
175 snd_SetSequence (snd->seq_buf, &snd->seq_buflen, (UBYTE*)FR_SEQ_TRAIN_SND, LEN_SEQ_TRAIN, 1);
176 #endif
177 break;
178
179 case TRAIN_CNF_SND:
180 #ifdef _SIMULATION_
181 snd_SetSequence (snd->seq_buf, &snd->seq_buflen, (UBYTE*)FR_SEQ_TRAIN_RCV, LEN_SEQ_TRAIN, 4);
182 snd_SetSequence (&snd->seq_buf [snd->seq_buflen], &snd->seq_buflen, (UBYTE*)FR_SEQ_SYNC, LEN_SEQ_SYNC, 1);
183 #else /* TI: only 2 bytes set - no SYNCs */
184 snd_SetSequence (snd->seq_buf, &snd->seq_buflen, (UBYTE*)FR_SEQ_TRAIN_RCV, LEN_SEQ_TRAIN, 1);
185 #endif
186 break;
187 }
188 }
189 }
190
191
192 /*
193 +--------------------------------------------------------------------+
194 | PROJECT : GSM-F&D (8411) MODULE : FAD_SNDF |
195 | STATE : code ROUTINE : snd_SetSequence |
196 +--------------------------------------------------------------------+
197
198 PURPOSE : set frame
199
200 */
201
202 GLOBAL void snd_SetSequence (UBYTE *seq_buf, USHORT *seq_buflen,
203 UBYTE *sequence, USHORT seq_len, USHORT repeat)
204 {
205 TRACE_FUNCTION ("snd_SetSequence()");
206
207 *seq_buflen += (seq_len * repeat);
208
209 while (repeat--)
210 {
211 memcpy (seq_buf, sequence, seq_len);
212 seq_buf += seq_len;
213 }
214 }
215
216 #if defined TRACE_FAD_UL_STATUS || defined _SIMULATION_
217
218 LOCAL void trace_fad_ul_frame_type(USHORT cus_frame_type, UBYTE* buf1, USHORT bytes_to_write)
219 {
220 const char type[5] = "DSYT";
221 char buf[15] = "TISx:0x00-0x00";
222
223 if (cus_frame_type < 4)
224 buf[3] = type[cus_frame_type];
225
226 if (buf1)
227 BYTE2HEXSTR(*(buf1+1), &buf[7]);
228
229 BYTE2HEXSTR((UBYTE)bytes_to_write, &buf[12]);
230 TRACE_EVENT (buf);
231 }
232
233 #endif
234
235 /*
236 +--------------------------------------------------------------------+
237 | PROJECT : GSM-F&D (8411) MODULE : FAD_SNDF |
238 | STATE : code ROUTINE : snd_ra_data_req |
239 +--------------------------------------------------------------------+
240
241 PURPOSE : Converts contents of frame descriptor to primitive
242
243 */
244 LOCAL void snd_ra_data_req(T_FD *pFD)
245 {
246
247 #if defined TRACE_FAD_UL_STATUS || defined _SIMULATION_
248
249 if (pFD->type EQ FR_STATUS)
250 {
251 trace_fad_ul_frame_type(FR_STATUS, pFD->buf, pFD->len);
252 }
253 /*
254 void t30_ker_debug(CHAR *header, UBYTE *buf, USHORT len);
255
256 if (pFD->type EQ FR_STATUS)
257 {
258 t30_ker_debug("BCS-RCV", pFD->buf, pFD->len);
259 }
260 */
261 #endif
262
263 #ifdef _SIMULATION_
264 {
265 PALLOC_SDU (ra_data_req, RA_DATA_REQ, (USHORT)(pFD->len<<3));
266
267 TRACE_FUNCTION ("snd_ra_data_req()");
268
269 ra_data_req->sdu.l_buf = pFD->len<<3;
270 memcpy (&ra_data_req->sdu.buf, pFD->buf, pFD->len);
271 ra_data_req->fr_type = pFD->type;
272 ra_data_req->dtx_flg = DTX_DIS;
273 ra_data_req->status = ST_SA;
274 PSENDX (RA, ra_data_req);
275 }
276 #else
277
278 l1i_ra_data_req_new(pFD);
279
280 #endif
281 }
282
283
284 /*
285 +--------------------------------------------------------------------+
286 | PROJECT : GSM-F&D (8411) MODULE : FAD_SNDF |
287 | STATE : code ROUTINE : snd_SendSequence |
288 +--------------------------------------------------------------------+
289
290 PURPOSE :
291
292 */
293
294 GLOBAL USHORT snd_SendSequence (USHORT bytes_to_send, UBYTE fr_type)
295 {
296 T_SND *snd = &fad_data->snd;
297 USHORT sdu_buf_pos = 0;
298
299 #ifdef _SIMULATION_
300 TRACE_FUNCTION ("snd_SendSequence()");
301 #endif
302
303 #ifdef _TARGET_
304 switch (fr_type)
305 {
306 case FR_SYNC:
307 break;
308
309 case FR_STATUS:
310 case FR_TRAIN:
311 bytes_to_send = 2;
312 break;
313
314 default:
315 break;
316 }
317 #endif
318
319 if (snd->bytes_to_send NEQ REPEAT_FOREVER)
320 {
321 if (snd->bytes_to_send > bytes_to_send)
322 snd->bytes_to_send -= bytes_to_send;
323 else
324 snd->bytes_to_send = 0;
325 }
326
327 snd->FD.type = fr_type;
328 snd->FD.len = (U8)bytes_to_send;
329
330 while (bytes_to_send)
331 {
332 UBYTE bytes_to_read = MINIMUM(snd->seq_buflen - snd->seq_bufpos, bytes_to_send);
333
334 memcpy(&snd->FD.buf[sdu_buf_pos], &snd->seq_buf[snd->seq_bufpos], bytes_to_read);
335 sdu_buf_pos += bytes_to_read;
336 snd->seq_bufpos += bytes_to_read; /* reset pos. in sequence */
337
338 if (bytes_to_send > bytes_to_read)
339 bytes_to_send -= bytes_to_read;
340 else
341 bytes_to_send = 0;
342
343 if (snd->seq_bufpos >= snd->seq_buflen) /* check sequence boundary */
344 snd->seq_bufpos -= snd->seq_buflen;
345 }
346
347 snd_ra_data_req(&snd->FD);
348
349 return (snd->bytes_to_send);
350 }
351
352 /*
353 +--------------------------------------------------------------------+
354 | PROJECT : GSM-F&D (8411) MODULE : FAD_SNDF |
355 | STATE : code ROUTINE : snd_DurationToBytes |
356 +--------------------------------------------------------------------+
357
358 PURPOSE : convert duration of sequence to be sent to bytes, taking
359 account of the transmission rate set
360
361 */
362
363 GLOBAL USHORT snd_DurationToBytes (USHORT trans_rate, USHORT duration)
364 {
365
366 TRACE_FUNCTION ("snd_DurationToBytes()");
367
368 return (trans_rate * duration / (8 * 1000));
369
370 }
371
372 #ifdef _SIMULATION_
373 /*
374 +--------------------------------------------------------------------+
375 | PROJECT : GSM-F&D (8411) MODULE : FAD_SNDF |
376 | STATE : code ROUTINE : SetBcsFrameBuffer |
377 +--------------------------------------------------------------------+
378
379 PURPOSE : copy HDLC data for buffer sending - add BCS-REC ident & repeats
380
381 */
382
383 LOCAL void SetBcsFrameBuffer (UBYTE *bcs_buf, UBYTE *hdlc_buf, USHORT len, USHORT repeat)
384 {
385 USHORT i, j, k;
386
387 TRACE_FUNCTION ("SetBcsFrameBuffer()");
388
389 for (i = 0; i < len; hdlc_buf++)
390 {
391 for (j = 0; j < repeat; j++)
392 for (k = 0; k < HDLC_REPEAT; i++, k++, bcs_buf++)
393 if (i & 0x0001)
394 *bcs_buf = *hdlc_buf;
395 else
396 *bcs_buf = IDENT_BCS_REC;
397 }
398
399 }
400
401 #endif
402
403 /*
404 +-----------------------------------------------------------------------+
405 | PROJECT : GSM-F&D (8411) MODULE : FAD_SNDF |
406 | STATE : code ROUTINE : snd_BuildStatusFrames |
407 +-----------------------------------------------------------------------+
408
409 PURPOSE : build BCS frames from HDLC data received from T30
410 pass to SBM buffer
411
412 */
413
414 #ifdef _SIMULATION_
415 GLOBAL void snd_BuildStatusFrames(T_FAD_DATA_REQ *fad_data_req, USHORT max_bytes)
416 #else
417 GLOBAL void snd_BuildStatusFrames(T_FAD_DATA_REQ *fad_data_req)
418 #endif
419 {
420 T_SND *snd = &fad_data->snd;
421
422 #ifdef _SIMULATION_
423 USHORT repeat;
424
425 TRACE_FUNCTION ("snd_BuildStatusFrames()");
426
427 snd->final = fad_data_req->final;
428
429 /* set total bytes to be sent */
430
431 repeat = (USHORT)(snd->trans_rate / (BCS_RATE << 3));
432 snd->data_to_send = fad_data_req->sdu.l_buf * HDLC_REPEAT * repeat;
433
434 if (snd->data_to_send <= max_bytes)
435 fad_data_req->sdu.l_buf = 0;
436 else
437 {
438 snd->data_to_send = max_bytes;
439 fad_data_req->sdu.l_buf -= (snd->data_to_send / HDLC_REPEAT / repeat);
440 }
441
442 SetBcsFrameBuffer (&snd->seq_buf [0], &fad_data_req->sdu.buf [fad_data_req->sdu.o_buf], snd->data_to_send, repeat);
443
444 snd->data_bufpos = 0;
445 if (fad_data_req->sdu.l_buf)
446 fad_data_req->sdu.o_buf += (snd->data_to_send / HDLC_REPEAT / repeat);
447
448 #else /* _TARGET_ */
449
450 snd->data_to_send = fad_data_req->sdu.l_buf >> 3;
451 fad_data_req->sdu.l_buf = 0;
452 snd->data_bufpos = 0;
453
454 #endif
455 }
456
457 /*
458 +--------------------------------------------------------------------+
459 | PROJECT : GSM-F&D (8411) MODULE : FAD_SNDF |
460 | STATE : code ROUTINE : snd_StoreMsgData |
461 +--------------------------------------------------------------------+
462
463 PURPOSE : store MSG data and pass to SBM buffer
464
465 */
466
467 GLOBAL void snd_StoreMsgData (T_FAD_DATA_REQ *fad_data_req)
468 {
469 T_SND *snd = &fad_data->snd;
470
471 TRACE_FUNCTION ("snd_StoreMsgData()");
472
473 snd->final = fad_data_req->final;
474
475 if (fad_data_req->sdu.l_buf)
476 {
477 snd->data_bufpos += (fad_data_req->sdu.l_buf >> 3);
478 sbm_store_prim (fad_data_req); /* pass primitive to send buffer */
479 }
480 if (!snd->final)
481 {
482 if (snd->data_to_send < snd->threshold)
483 sig_snd_ker_ready_ind ();
484 else
485 snd->send_ready_to_t30 = TRUE;
486 }
487 }
488
489
490 /*
491 +--------------------------------------------------------------------+
492 | PROJECT : GSM-F&D (8411) MODULE : FAD_SNDF |
493 | STATE : code ROUTINE : snd_SendMsgData |
494 +--------------------------------------------------------------------+
495
496 PURPOSE :
497
498 */
499
500 GLOBAL BOOL snd_SendMsgData (UBYTE req_frames)
501 {
502 T_SND *snd = &fad_data->snd;
503 T_FRAME_DESC ul_FD;
504
505 #ifdef _SIMULATION_
506 TRACE_FUNCTION ("snd_SendMsgData()");
507 #endif
508
509 if (sbm_get_frame(&ul_FD, req_frames) EQ TRUE)
510 {
511 U8 sdu_len = (U8)(ul_FD.Len[0] + ul_FD.Len[1]);
512
513 snd->data_to_send -= sdu_len;
514 snd->FD.type = FR_T4DATA;
515 snd->FD.len = sdu_len;
516 memcpy(snd->FD.buf, ul_FD.Adr[0], ul_FD.Len[0]);
517 memcpy(&snd->FD.buf[ul_FD.Len[0]], ul_FD.Adr[1], ul_FD.Len[1]);
518 snd_ra_data_req(&snd->FD);
519 return TRUE;
520 }
521 else
522 {
523 return FALSE;
524 }
525 }
526
527 /*
528 +--------------------------------------------------------------------+
529 | PROJECT : GSM-F&D (8411) MODULE : FAD_SNDF |
530 | STATE : code ROUTINE : snd_SendBcsData |
531 +--------------------------------------------------------------------+
532
533 PURPOSE :
534
535 */
536 #ifdef _SIMULATION_
537 GLOBAL void snd_SendBcsData (USHORT bytes_to_send)
538 #else
539 GLOBAL void snd_SendBcsData (void)
540 #endif
541 {
542 T_SND *snd = &fad_data->snd;
543
544 TRACE_FUNCTION ("snd_SendBcsData()");
545
546 if (!snd->data_to_send)
547 return;
548
549 snd->FD.type = FR_STATUS;
550
551 #ifdef _SIMULATION_
552
553 if (snd->data_to_send >= bytes_to_send)
554 snd->data_to_send -= bytes_to_send;
555 else
556 {
557 bytes_to_send = snd->data_to_send;
558 snd->data_to_send = 0;
559 }
560 snd->FD.len = (U8)bytes_to_send;
561 memcpy(snd->FD.buf, &snd->seq_buf[snd->data_bufpos], snd->FD.len);
562 snd->data_bufpos += bytes_to_send;
563
564 #else /* _TARGET_ */
565 snd->FD.buf[0] = IDENT_BCS_REC;
566 snd->FD.buf[1] = snd->fad_data_req->sdu.buf[snd->data_bufpos++];
567 snd->FD.len = 2;
568 snd->data_to_send--;
569
570 #endif /* _TARGET_ */
571
572 snd_ra_data_req(&snd->FD);
573 }
574