comparison src/g23m-fad/ra/ra_fax.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 : GSM-F&D (8411)
4 | Modul : RA_FAX
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 functions for the faxnsparent
18 | data model for the component RA of the mobile station
19 +-----------------------------------------------------------------------------
20 */
21
22 #ifndef RA_FAX_C
23 #define RA_FAX_C
24 #endif
25
26 #define ENTITY_RA
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_ra.h"
38 #include "prim.h"
39 #include "pei.h"
40 #include "tok.h"
41 #include "ccdapi.h"
42 #include "ra.h"
43
44 /*==== CONST ======================================================*/
45
46 LOCAL const T_SKIP skip_F14400 [4] =
47 {
48 /* T4DATA same */ {{0, 0, 0, 0, 0, 0, 0, 0},
49 /* T4DATA other */ {0, 1, 0, 1, 0, 1, 0, 1}},
50 /* STATUS same */ {{0, 0, 1, 0, 0, 0, 1, 0},
51 /* STATUS other */ {1, 1, 1, 0, 1, 1, 1, 0}},
52 /* SYNC same */ {{0, 0, 0, 0, 0, 0, 0, 0},
53 /* SYNC other */ {1, 0, 1, 0, 1, 0, 1, 0}},
54 /* TRAIN same */ {{0, 0, 0, 0, 0, 0, 0, 0},
55 /* TRAIN other */ {1, 1, 1, 0, 1, 1, 1, 0}}
56 };
57
58 LOCAL const UBYTE request_F14400 [4] =
59 {
60 5,4,5,4
61 };
62
63 LOCAL const T_SKIP skip_F9600 [4] =
64 {
65 /* T4DATA same */ {{0, 0, 0, 0, 0, 0, 0, 0},
66 /* T4DATA other */ {0, 0, 0, 0, 0, 0, 0, 0}},
67 /* STATUS same */ {{0, 0, 0, 1, 0, 0, 0, 1},
68 /* STATUS other */ {0, 1, 1, 1, 0, 1, 1, 1}},
69 /* SYNC same */ {{0, 0, 0, 0, 0, 0, 0, 0},
70 /* SYNC other */ {0, 0, 0, 0, 0, 0, 0, 0}},
71 /* TRAIN same */ {{0, 0, 0, 0, 0, 0, 0, 0},
72 /* TRAIN other */ {0, 1, 0, 1, 0, 1, 0, 1}}
73 };
74
75 LOCAL const UBYTE request_F9600 [4] =
76 {
77 3,3,3,3
78 };
79
80 LOCAL const T_SKIP skip_F4800 [4] =
81 {
82 /* T4DATA same */ {{0, 0, 0, 0, 0, 0, 0, 0},
83 /* T4DATA other */ {0, 1, 0, 1, 0, 1, 0, 1}},
84 /* STATUS same */ {{0, 0, 0, 1, 0, 0, 0, 1},
85 /* STATUS other */ {0, 1, 1, 1, 0, 1, 1, 1}},
86 /* SYNC same */ {{0, 0, 0, 0, 0, 0, 0, 0},
87 /* SYNC other */ {0, 1, 0, 1, 0, 1, 0, 1}},
88 /* TRAIN same */ {{0, 0, 0, 0, 0, 0, 0, 0},
89 /* TRAIN other */ {0, 1, 1, 1, 0, 1, 1, 1}}
90 };
91
92 LOCAL const UBYTE request_F4800 [4] =
93 {
94 2,1,2,1
95 };
96
97 LOCAL const T_SKIP skip_F2400 [4] =
98 {
99 /* T4DATA same */ {{0, 0, 0, 1, 0, 0, 0, 1},
100 /* T4DATA other */ {0, 1, 1, 1, 0, 1, 1, 1}},
101 /* STATUS same */ {{0, 0, 0, 1, 0, 0, 0, 1},
102 /* STATUS other */ {0, 1, 1, 1, 0, 1, 1, 1}},
103 /* SYNC same */ {{0, 0, 0, 0, 0, 0, 0, 0},
104 /* SYNC other */ {0, 1, 1, 1, 0, 1, 1, 1}},
105 /* TRAIN same */ {{0, 0, 0, 0, 0, 0, 0, 0},
106 /* TRAIN other */ {0, 1, 1, 1, 1, 1, 1, 1}}
107 };
108
109 LOCAL const UBYTE request_F2400 [4] =
110 {
111 1,1,1,1
112 };
113
114 LOCAL const T_SKIP skip_H4800 [4] =
115 {
116 /* T4DATA same */ {{0, 0, 0, 0, 0, 0, 0, 0},
117 /* T4DATA other */ {0, 1, 0, 1, 0, 1, 0, 1}},
118 /* STATUS same */ {{0, 0, 0, 1, 0, 0, 0, 1},
119 /* STATUS other */ {0, 1, 1, 1, 0, 1, 1, 1}},
120 /* SYNC same */ {{0, 0, 0, 0, 0, 0, 0, 0},
121 /* SYNC other */ {0, 1, 0, 1, 0, 1, 0, 1}},
122 /* TRAIN same */ {{0, 0, 0, 0, 0, 0, 0, 0},
123 /* TRAIN other */ {0, 1, 1, 1, 0, 1, 1, 1}}
124 };
125
126 LOCAL const UBYTE request_H4800 [4] =
127 {
128 2,1,2,1
129 };
130
131 LOCAL const T_SKIP skip_H2400 [4] =
132 {
133 /* T4DATA same */ {{0, 0, 0, 1, 0, 0, 0, 1},
134 /* T4DATA other */ {0, 1, 1, 1, 0, 1, 1, 1}},
135 /* STATUS same */ {{0, 0, 0, 1, 0, 0, 0, 1},
136 /* STATUS other */ {0, 1, 1, 1, 0, 1, 1, 1}},
137 /* SYNC same */ {{0, 0, 0, 0, 0, 0, 0, 0},
138 /* SYNC other */ {0, 1, 1, 1, 0, 1, 1, 1}},
139 /* TRAIN same */ {{0, 0, 0, 0, 0, 0, 0, 0},
140 /* TRAIN other */ {0, 1, 1, 1, 1, 1, 1, 1}}
141 };
142
143 LOCAL const UBYTE request_H2400 [4] =
144 {
145 1,1,1,1
146 };
147
148 /*==== TYPES ======================================================*/
149 /*==== VARIABLES ==================================================*/
150 /*==== FUNCTIONS ==================================================*/
151
152 #if defined TRACE_RA_FAX_UL_FRAME_TYPE || defined _SIMULATION_
153
154 LOCAL void trace_ra_fax_ul_frame_type(USHORT cus_frame_type, UBYTE* buf1, USHORT bytes_to_write)
155 {
156 const char type[5] = "DSYT";
157 char buf[15] = "TISx:0x00-0x00";
158
159 if (cus_frame_type < 4)
160 buf[3] = type[cus_frame_type];
161
162 if (buf1)
163 BYTE2HEXSTR(*(buf1+1), &buf[7]);
164
165 BYTE2HEXSTR((UBYTE)bytes_to_write, &buf[12]);
166 TRACE_EVENT (buf);
167 }
168
169 #endif
170
171 #if defined TRACE_RA_FAX_DL_FRAME_TYPE || defined _SIMULATION_
172
173 LOCAL void trace_ra_fax_dl_frame_type(U8 *last, U8 current, USHORT bytes_read)
174 {
175 void t30_ker_debug(CHAR *header, UBYTE *buf, USHORT len);
176
177 const char type[5] = "DSYT";
178 char buf[15] = "TIRx:0x00-0x__";
179
180 if (*last NEQ current)
181 {
182 if (current < 4)
183 buf[3] = type[current];
184
185 TRACE_EVENT (buf);
186
187 *last = current;
188 }
189 else if (bytes_read)
190 {
191 if (current EQ 0)
192 {
193 t30_ker_debug("TIRD", ra_data->fax->dl_pFD->buf, bytes_read);
194 }
195 else
196 {
197 if (current < 4)
198 buf[3] = type[current];
199
200 BYTE2HEXSTR((UBYTE)bytes_read, &buf[7]);
201
202 if (current EQ 1)
203 BYTE2HEXSTR(ra_data->fax->dl_pFD->buf[1], &buf[12]);
204
205 TRACE_EVENT (buf);
206 }
207 }
208 }
209
210 #endif
211
212 LOCAL void fax_init_data(BOOL CMM_flag)
213 {
214 T_FAX *dfax = ra_data->fax;
215 /*
216 * initialize the fax mode data
217 */
218 ra_data->sync_timer = 0L;
219 ra_data->cycle_time = 0L;
220
221 dfax->CMM_flag = CMM_flag;
222 dfax->ul_frame_type_last = FR_SYNC;
223 dfax->ul_frame_type = FR_SYNC;
224 dfax->ul_pFD = NULL;
225
226 cl_ribu_init(&dfax->ul_ribu->idx, RA_FIFO_DEPTH);
227
228 #if defined TRACE_RA_FAX_DL_FRAME_TYPE || defined _SIMULATION_
229 dfax->dl_frame_type_last = 0xFF;
230 dfax->dl_state_last = 0xFF;
231 #endif
232
233 dfax->req_idx = 0;
234 dfax->seq_idx = 0;
235
236 dfax->ul_train_FD.buf = dfax->train_seq;
237 dfax->ul_train_FD.len = 2;
238
239 ra_data->ra_data_ind.fr_type = FR_INVALID;
240 ra_data->ra_data_ind.sdu.o_buf = 0;
241 ra_data->ra_data_ind.sdu.l_buf = 0;
242 ra_data->ra_ready_ind[0].req_frames = 0;
243 }
244
245 /*
246 +--------------------------------------------------------------------+
247 | PROJECT : GSM-F&D (8411) MODULE : RA_FAX |
248 | STATE : code ROUTINE : fax_init |
249 +--------------------------------------------------------------------+
250
251 PURPOSE :
252 */
253
254 GLOBAL void fax_init(void)
255 {
256 TRACE_FUNCTION("fax_init");
257
258 fax_init_data(FALSE); /* no CMM */
259
260 hCommFAD = vsi_c_open ( VSI_CALLER FAD_NAME );
261 hCommMMI = vsi_c_open ( VSI_CALLER ACI_NAME );
262 }
263
264 /*
265 +--------------------------------------------------------------------+
266 | PROJECT : GSM-F&D (8411) MODULE : RA_FAX |
267 | STATE : code ROUTINE : fax_ul_modify |
268 +--------------------------------------------------------------------+
269
270 PURPOSE :
271 */
272
273 GLOBAL void fax_ul_modify(void)
274 {
275 TRACE_EVENT("fax_ul_modify()");
276
277 fax_init_data(TRUE); /* CMM */
278 fax_ul_null();
279 return;
280 }
281 /*
282 +--------------------------------------------------------------------+
283 | PROJECT : GSM-F&D (8411) MODULE : RA_FAX |
284 | STATE : code ROUTINE : fax_idle |
285 +--------------------------------------------------------------------+
286
287 PURPOSE : IDLE processing for uplink and downlink fax mode
288 */
289
290 GLOBAL void fax_idle(void)
291 {
292 }
293
294 /*
295 +--------------------------------------------------------------------+
296 | PROJECT : GSM-F&D (8411) MODULE : RA_FAX |
297 | STATE : code ROUTINE : fax_ul_null |
298 +--------------------------------------------------------------------+
299
300 PURPOSE :
301 */
302
303 GLOBAL void fax_ul_null(void)
304 {
305 T_FAX *dfax = ra_data->fax;
306
307 TRACE_FUNCTION("fax_ul_null");
308
309 if (ra_data->activated)
310 {
311 /*
312 * setup the communication parameters
313 */
314 shm_set_dsp_value (conf_b_itc, V_ITC_FAX);
315
316 switch (ra_data->nsb)
317 {
318 case 1:
319 shm_set_dsp_value (conf_b_nsb, V_NSB_ONE_STOP);
320 break;
321 case 2:
322 shm_set_dsp_value (conf_b_nsb, V_NSB_TWO_STOP);
323 break;
324 default:
325 break;
326 }
327
328 switch (ra_data->ndb)
329 {
330 case 7:
331 shm_set_dsp_value (conf_b_ndb, V_NDMSK_B_7_DBITS);
332 break;
333 case 8:
334 shm_set_dsp_value (conf_b_ndb, V_NDMSK_B_8_DBITS);
335 break;
336 default:
337 break;
338 }
339
340 shm_set_dsp_value (conf_b_ce, V_CE_TRANSP);
341
342 switch (ra_data->tra_rate)
343 {
344 case TRA_FULLRATE_14400:
345 dfax->skip_seq = &skip_F14400[0];
346 dfax->req_seq = &request_F14400[0];
347 shm_set_dsp_value (conf_b_ct, V_CT_FR);
348 shm_set_dsp_value (conf_b_ur, V_UR_14400);
349 ra_data->cycle_time = 20;
350 break;
351
352 case TRA_FULLRATE_9600:
353 dfax->skip_seq = &skip_F9600[0];
354 dfax->req_seq = &request_F9600[0];
355 shm_set_dsp_value (conf_b_ur, V_UR_9600);
356 shm_set_dsp_value (conf_b_ct, V_CT_FR);
357 ra_data->cycle_time = 20;
358 break;
359
360 case TRA_FULLRATE_4800:
361 dfax->skip_seq = &skip_F4800[0];
362 dfax->req_seq = &request_F4800[0];
363 shm_set_dsp_value (conf_b_ur, V_UR_4800);
364 shm_set_dsp_value (conf_b_ct, V_CT_FR);
365 ra_data->cycle_time = 20;
366 break;
367
368 case TRA_FULLRATE_2400:
369 dfax->skip_seq = &skip_F2400[0];
370 dfax->req_seq = &request_F2400[0];
371 shm_set_dsp_value (conf_b_ur, V_UR_2400);
372 shm_set_dsp_value (conf_b_ct, V_CT_FR);
373 ra_data->cycle_time = 20;
374 break;
375
376 case TRA_HALFRATE_4800:
377 dfax->skip_seq = &skip_H4800[0];
378 dfax->req_seq = &request_H4800[0];
379 shm_set_dsp_value (conf_b_ur, V_UR_4800);
380 shm_set_dsp_value (conf_b_ct, V_CT_HR);
381 ra_data->cycle_time = 40;
382 break;
383
384 case TRA_HALFRATE_2400:
385 dfax->skip_seq = &skip_H2400[0];
386 dfax->req_seq = &request_H2400[0];
387 shm_set_dsp_value (conf_b_ur, V_UR_2400);
388 shm_set_dsp_value (conf_b_ct, V_CT_HR);
389 ra_data->cycle_time = 40;
390 break;
391
392 default:
393 TRACE_EVENT ("Unknown transmission rate");
394
395 ra_data->cycle_time = 20;
396 break;
397 }
398
399 shm_set_dsp_value (fax_b_data_receive, 1);
400
401 /*
402 * set uplink buffer to empty values
403 */
404 shm_set_dsp_value (faxd_byte_cnt, 0);
405 shm_set_dsp_value (faxu_byte_cnt, 0);
406 shm_set_dsp_value (faxu_control, V_CTRL_SYNC);
407
408 /*
409 * start initialisation process in F&D L1
410 */
411
412 /*
413 * enable status frame detection in L1
414 * and set the biterror thresholds for the status frame detection
415 */
416 shm_set_dsp_value (fax_b_status_stop, 0);
417 shm_set_dsp_value (fax_b_status_detect, 1);
418 shm_set_dsp_value (fax_b_ident_thres, 3);
419 shm_set_dsp_value (fax_b_info_thres, 3);
420 shm_set_dsp_value (fax_b_status_receive, 0);
421 shm_set_dsp_value (fax_b_byte_interface, 1);
422 shm_set_dsp_value (faxu_byte_cnt, 0);
423
424 shm_set_dsp_value (act_b_init, 1);
425 shm_set_dsp_value (act_b_syncul, 1);
426 shm_set_dsp_value (act_b_syncdl, 1);
427
428 INIT_STATE (KER, FAX_INIT_L1);
429
430 #if defined TRACE_RA_FAX_DL_FRAME_TYPE || defined _SIMULATION_
431 if (dfax->dl_state_last NEQ ra_data->ker.state)
432 {
433 TRACE_EVENT_P2("KER:FAX_%d -> FAX_%d", dfax->dl_state_last, ra_data->ker.state);
434 dfax->dl_state_last = ra_data->ker.state;
435 }
436 #endif
437
438 #ifdef HO_WORKAROUND /* fax_ul_null */
439 _act_d_ra_conf = *ra_data->shm.shm_addr[d_ra_conf];
440 TRACE_EVENT_P1("d_ra_conf saved; rate=%d", ra_data->tra_rate);
441 #endif
442 }
443 }
444
445 /*
446 +--------------------------------------------------------------------+
447 | PROJECT : GSM-F&D (8411) MODULE : RA_FAX |
448 | STATE : code ROUTINE : fax_ul_init_l1 |
449 +--------------------------------------------------------------------+
450
451 PURPOSE :
452 */
453
454 GLOBAL void fax_ul_init_l1(void)
455 {
456 TRACE_FUNCTION("fax_ul_init_l1");
457
458 if (shm_get_dsp_value(act_b_init) EQ 0) /* Indicates initialization of IDS module */
459 {
460 /*
461 * L1 F&D initialized; start ul/dl synchronisation
462 */
463 SET_STATE (KER, FAX_SYNCH_TCH_START);
464
465 #if defined TRACE_RA_FAX_DL_FRAME_TYPE || defined _SIMULATION_
466 if (ra_data->fax->dl_state_last NEQ ra_data->ker.state)
467 {
468 TRACE_EVENT_P2("KER:FAX_%d -> FAX_%d", ra_data->fax->dl_state_last, ra_data->ker.state);
469 ra_data->fax->dl_state_last = ra_data->ker.state;
470 }
471 #endif
472 }
473 }
474
475 /*
476 +--------------------------------------------------------------------+
477 | PROJECT : GSM-F&D (8411) MODULE : RA_FAX |
478 | STATE : code ROUTINE : fax_dl_sync_tch_start |
479 +--------------------------------------------------------------------+
480
481 PURPOSE :
482 */
483
484 GLOBAL void fax_dl_sync_tch_start(void)
485 {
486 TRACE_FUNCTION("fax_dl_sync_tch_start");
487
488 if (shm_get_dsp_value (statd_b_syncdet) EQ 1)
489 {
490 /*
491 * Detection of sync frames, synchro. on M1 sequence.
492 * Start a pseudo timer with 500 ms.
493 * The value is decremented by cycle_time
494 * each time the L1 calls the dll_data_ul function
495 */
496 ra_data->sync_timer = 500L;
497
498 SET_STATE (KER, FAX_SYNCH_TCH_FOUND);
499
500 #if defined TRACE_RA_FAX_DL_FRAME_TYPE || defined _SIMULATION_
501 if (ra_data->fax->dl_state_last NEQ ra_data->ker.state)
502 {
503 TRACE_EVENT_P2("KER:FAX_%d -> FAX_%d", ra_data->fax->dl_state_last, ra_data->ker.state);
504 ra_data->fax->dl_state_last = ra_data->ker.state;
505 }
506 #endif
507
508 }
509 }
510
511 /*
512 +--------------------------------------------------------------------+
513 | PROJECT : GSM-F&D (8411) MODULE : RA_FAX |
514 | STATE : code ROUTINE : fax_ul_sync_tch_found |
515 +--------------------------------------------------------------------+
516
517 PURPOSE :
518 */
519
520 GLOBAL void fax_ul_sync_tch_found(void)
521 {
522 T_FAX *dfax = ra_data->fax;
523
524 TRACE_FUNCTION("fax_ul_sync_tch_found");
525
526 if (TimeOut(&ra_data->sync_timer) NEQ TRUE)
527 return;
528
529 /*
530 * timeout of the sync timer - reset the sync-detection flags
531 */
532 shm_set_dsp_value (act_b_syncul, 0);
533 shm_set_dsp_value (act_b_syncdl, 0);
534
535 if (ra_data->tra_rate NEQ TRA_FULLRATE_14400)
536 {
537 /*
538 * setup uplink buffer to send SYNC frames
539 */
540 shm_set_dsp_value (faxu_byte_cnt, 0);
541 shm_set_dsp_value (faxu_control, V_CTRL_SYNC);
542 dfax->seq_idx = 0;
543 SET_STATE (KER, FAX_WAIT_SYNC_LOST);
544
545 #if defined TRACE_RA_FAX_DL_FRAME_TYPE || defined _SIMULATION_
546 if (dfax->dl_state_last NEQ ra_data->ker.state)
547 {
548 TRACE_EVENT_P2("KER:FAX_%d -> FAX_%d", dfax->dl_state_last, ra_data->ker.state);
549 dfax->dl_state_last = ra_data->ker.state;
550 }
551 #endif
552
553 }
554 else /* ra_data->tra_rate EQ TRA_FULLRATE_14400 */
555 {
556 /*
557 * sync detection finished -> enter the data transmission (pre-) state
558 */
559 if (dfax->CMM_flag)
560 {
561 l1i_ra_modify_cnf();
562 SET_STATE (KER, FAX_DATA_TRANS);
563 }
564 else
565 {
566 l1i_ra_activate_cnf();
567 SET_STATE (KER, FAX_DATA_TRANS_PRE);
568 }
569
570 #if defined TRACE_RA_FAX_DL_FRAME_TYPE || defined _SIMULATION_
571 if (dfax->dl_state_last NEQ ra_data->ker.state)
572 {
573 TRACE_EVENT_P2("KER:FAX_%d -> FAX_%d", dfax->dl_state_last, ra_data->ker.state);
574 dfax->dl_state_last = ra_data->ker.state;
575 }
576 #endif
577
578 #ifdef HO_WORKAROUND /* fax_ul_sync_tch_found */
579 if (*ra_data->shm.shm_addr[d_ra_conf] NEQ _act_d_ra_conf)
580 {
581 *ra_data->shm.shm_addr[d_ra_conf] = _act_d_ra_conf;
582 TRACE_EVENT("HO_REFRESH fax_ul_sync_tch_found");
583 }
584 #endif
585
586 }
587 }
588
589 LOCAL void IncIndex(UBYTE *idx, UBYTE idxMax)
590 {
591 if (++(*idx) EQ idxMax)
592 *idx = 0;
593 }
594
595 /*
596 +--------------------------------------------------------------------+
597 | PROJECT : GSM-F&D (8411) MODULE : RA_FAX |
598 | STATE : code ROUTINE : fax_dl_wait_sync_lost |
599 +--------------------------------------------------------------------+
600
601 PURPOSE :
602 */
603
604 GLOBAL void fax_dl_wait_sync_lost(void)
605 {
606 T_FAX *dfax = ra_data->fax;
607
608 TRACE_FUNCTION("fax_dl_wait_sync_lost");
609
610 IncIndex(&dfax->seq_idx, 8);
611
612 if (shm_get_dsp_value (statd_b_syncdet) EQ 0)
613 {
614 /*
615 * sync detection finished -> enter the data transmission (pre-) state
616 */
617 if (dfax->CMM_flag)
618 {
619 l1i_ra_modify_cnf();
620 SET_STATE (KER, FAX_DATA_TRANS);
621 }
622 else
623 {
624 l1i_ra_activate_cnf();
625 SET_STATE (KER, FAX_DATA_TRANS_PRE);
626 }
627
628 #if defined TRACE_RA_FAX_DL_FRAME_TYPE || defined _SIMULATION_
629 if (dfax->dl_state_last NEQ ra_data->ker.state)
630 {
631 TRACE_EVENT_P2("KER:FAX_%d -> FAX_%d", dfax->dl_state_last, ra_data->ker.state);
632 dfax->dl_state_last = ra_data->ker.state;
633 }
634 #endif
635
636 #ifdef HO_WORKAROUND /* fax_dl_wait_sync_lost */
637 if (*ra_data->shm.shm_addr[d_ra_conf] NEQ _act_d_ra_conf)
638 {
639 *ra_data->shm.shm_addr[d_ra_conf] = _act_d_ra_conf;
640 TRACE_EVENT("HO_REFRESH fax_dl_wait_sync_lost");
641 }
642 #endif
643
644 }
645 }
646
647 #ifndef _SIMULATION_
648 LOCAL void check_skip(USHORT fed_ul, BOOL *skip)
649 {
650 if (*skip AND !fed_ul)
651 {
652 *skip = FALSE;
653 #ifdef TRACE_RA_FAX_UL_SKIP
654 TRACE_EVENT_P1("fed_ul=%d -> skip -> FALSE", fed_ul);
655 #endif
656 }
657 else if (!*skip AND fed_ul)
658 {
659 *skip = TRUE;
660 #ifdef TRACE_RA_FAX_UL_SKIP
661 TRACE_EVENT_P1("fed_ul=%d-> skip -> TRUE", fed_ul);
662 #endif
663 }
664 }
665 #endif
666
667 /*
668 +--------------------------------------------------------------------+
669 | PROJECT : GSM-F&D (8411) MODULE : RA_FAX |
670 | STATE : code ROUTINE : fax_ul_data_trans |
671 +--------------------------------------------------------------------+
672
673 PURPOSE :
674 */
675
676 GLOBAL void fax_ul_data_trans(void)
677 {
678 T_FAX *dfax = ra_data->fax;
679 USHORT bytes_used_after = 0;
680 BOOL skip;
681
682 USHORT fed_ul = shm_get_dsp_value(statu_b_fed_ul);
683
684 TRACE_FUNCTION ("fax_ul_data_trans");
685
686 #if defined TRACE_RA_FAX_UL_FRAME_TYPE || defined _SIMULATION_
687 if (dfax->ul_ribu->idx.filled > 1)
688 TRACE_EVENT_P1("dfax->ul_ribu->idx.filled=%d", dfax->ul_ribu->idx.filled);
689 #endif
690
691 if (dfax->ul_ribu->idx.filled)
692 {
693 dfax->ul_pFD = cl_ribu_get(dfax->ul_ribu);
694 dfax->ul_frame_type = dfax->ul_pFD->type;
695 }
696
697 #if defined TRACE_RA_FAX_UL_FRAME_TYPE || defined _SIMULATION_
698 else
699 {
700 TRACE_EVENT_P1("dfax->ul_ribu->idx.filled=%d", dfax->ul_ribu->idx.filled);
701 }
702 #endif
703
704 /*
705 * Check if we must skip this cycle.
706 * For status frames this is done every third status frame,
707 * because L1 sends more data (1,2,4,6) * 64 bit status frames.
708 * for T4DATA frames this also happens in 2400 bps mode
709 */
710 /*
711 * check if the frame type has changed
712 */
713 if (dfax->ul_frame_type_last NEQ dfax->ul_frame_type)
714 {
715 skip = (dfax->skip_seq[dfax->ul_frame_type_last].skip_seq_other[dfax->seq_idx] NEQ 0);
716
717 #ifndef _SIMULATION_
718 check_skip(fed_ul, &skip);
719 #endif
720
721 if ((dfax->ul_frame_type_last EQ FR_TRAIN) AND (dfax->train_len > 0))
722 {
723 /* Training is stopped only after a minimum length */
724 dfax->train_len--;
725 skip = TRUE;
726 }
727
728 if (!skip)
729 {
730 /*
731 * we are on a 64 bit boundary so we can write into the new frame. Reset all sequencers.
732 */
733 dfax->ul_frame_type_last = dfax->ul_frame_type;
734 dfax->seq_idx = 1;
735
736 /*
737 * start the request sequencer for T4DATA
738 */
739 if (dfax->ul_frame_type EQ FR_T4DATA)
740 {
741 dfax->req_idx = 1;
742 }
743 else
744 {
745 dfax->req_idx = 0;
746
747 /*
748 * Store training sequence. It will be used later, when changing
749 * to T4 data, in order to avoid insertion of sync frames.
750 */
751 if (dfax->ul_frame_type EQ FR_TRAIN)
752 {
753 dfax->train_seq[0] = dfax->ul_pFD->buf[0];
754 dfax->train_seq[1] = dfax->ul_pFD->buf[1];
755 dfax->train_len = MIN_FR_TRAIN_LEN - 1; /* Minimum length of training */
756 }
757 }
758 }
759 else /* skip */
760 {
761 IncIndex(&dfax->seq_idx, 8);
762
763 if (dfax->ul_frame_type_last EQ FR_T4DATA)
764 {
765 IncIndex(&dfax->req_idx, 4);
766 }
767 }
768 }
769 else /* frame type not changed */
770 {
771 skip = (dfax->skip_seq[dfax->ul_frame_type_last].skip_seq_same[dfax->seq_idx] NEQ 0);
772
773 #ifndef _SIMULATION_
774 check_skip(fed_ul, &skip);
775 #endif
776
777 IncIndex(&dfax->seq_idx, 8);
778
779 if (dfax->ul_frame_type EQ FR_T4DATA)
780 {
781 IncIndex(&dfax->req_idx, 4);
782 }
783 else if ((dfax->ul_frame_type_last EQ FR_TRAIN) AND (dfax->train_len > 0))
784 {
785 /* Training is stopped only after a minimum length */
786 dfax->train_len--;
787 }
788 }
789
790 if (!skip)
791 {
792 switch (dfax->ul_frame_type)
793 {
794 case FR_T4DATA:
795 shm_set_dsp_value (faxu_control, V_CTRL_DATA);
796 break;
797
798 case FR_STATUS:
799 shm_set_dsp_value (faxu_control, V_CTRL_STATUS);
800 break;
801
802 case FR_TRAIN:
803 shm_set_dsp_value (faxu_control, V_CTRL_TRAIN);
804 break;
805
806 case FR_SYNC:
807 shm_set_dsp_value (faxu_control, V_CTRL_SYNC);
808 shm_set_dsp_value (faxu_byte_cnt, 0);
809 break;
810 }
811 if (dfax->ul_frame_type NEQ FR_SYNC)
812 {
813 bytes_used_after = shm_set_dsp_buffer_new(dfax->ul_pFD, ra_data->shm.shm_addr[adr_faxu_data]+wof_faxu_data, 0, (USHORT)MAX_FAX_BUFFER_UL);
814 shm_set_dsp_value (faxu_byte_cnt, bytes_used_after);
815 }
816
817 #if defined TRACE_RA_FAX_UL_FRAME_TYPE || defined _SIMULATION_
818 if (dfax->ul_pFD)
819 trace_ra_fax_ul_frame_type(dfax->ul_frame_type, dfax->ul_pFD->buf, bytes_used_after);
820 #endif
821
822 ra_data->ra_ready_ind[0].req_frames = dfax->req_seq[dfax->req_idx];
823 l1i_ra_ready_ind(hCommFAD, 0);
824 }
825 else if (dfax->ul_frame_type_last EQ FR_TRAIN) /* skip AND train*/
826 {
827 shm_set_dsp_value (faxu_control, V_CTRL_TRAIN);
828 bytes_used_after = shm_set_dsp_buffer_new(&dfax->ul_train_FD, ra_data->shm.shm_addr[adr_faxu_data]+wof_faxu_data, 0, (USHORT)MAX_FAX_BUFFER_UL);
829 shm_set_dsp_value (faxu_byte_cnt, bytes_used_after);
830
831 #if defined TRACE_RA_FAX_UL_FRAME_TYPE || defined _SIMULATION_
832 trace_ra_fax_ul_frame_type(V_CTRL_TRAIN, dfax->ul_train_FD.buf, bytes_used_after);
833 #endif
834
835 }
836 else /* skip */
837 {
838 shm_set_dsp_value (faxu_byte_cnt, 0);
839
840 #if defined TRACE_RA_FAX_UL_FRAME_TYPE || defined _SIMULATION_
841 trace_ra_fax_ul_frame_type(4, NULL, 0);
842 #endif
843
844 }
845 }
846
847 LOCAL U8 get_frame_descriptor(U8 bytes_to_read)
848 {
849 T_FAX *dfax = ra_data->fax;
850
851 U8 bytes_read;
852
853 #ifdef _SIMULATION_
854 dfax->dl_pFD = cl_ribu_get_new_frame_desc(ra_data->dl_ribu);
855 #else
856 dfax->dl_pFD = fad_rbm_get_next_FrameDesc();
857 #endif
858
859 dfax->dl_pFD->len = FAD_DESCBUF_LEN;
860 bytes_read = shm_get_dsp_buffer_new(ra_data->shm.shm_addr[adr_faxd_data]+wof_faxd_data, bytes_to_read, dfax->dl_pFD);
861
862 return bytes_read;
863 }
864
865 /*
866 +--------------------------------------------------------------------+
867 | PROJECT : GSM-F&D (8411) MODULE : RA_FAX |
868 | STATE : code ROUTINE : fax_dl_data_trans |
869 +--------------------------------------------------------------------+
870
871 PURPOSE :
872 */
873
874 GLOBAL void fax_dl_data_trans(void)
875 {
876 UBYTE bytes_to_read, bytes_read = 0;
877 UBYTE dl_frame_type;
878
879 T_FAX *dfax = ra_data->fax;
880
881 TRACE_FUNCTION ("fax_dl_data_trans");
882
883 #ifdef HO_WORKAROUND /* fax_dl_data_trans */
884 if (*ra_data->shm.shm_addr[d_ra_conf] NEQ _act_d_ra_conf)
885 {
886 *ra_data->shm.shm_addr[d_ra_conf] = _act_d_ra_conf;
887 TRACE_EVENT("HO_REFRESH fax_dl_data_trans");
888 }
889 #endif
890
891 dl_frame_type = shm_get_dsp_value (faxd_control);
892
893 if (dl_frame_type EQ V_CTRL_SYNC)
894 {
895 bytes_read = get_frame_descriptor(0);
896 dfax->dl_pFD->len = bytes_read;
897 dfax->dl_pFD->type = dl_frame_type;
898 l1i_ra_data_ind(hCommFAD);
899
900 #if defined TRACE_RA_FAX_DL_FRAME_TYPE || defined _SIMULATION_
901 trace_ra_fax_dl_frame_type(&dfax->dl_frame_type_last, dl_frame_type, bytes_read);
902 #endif
903
904 }
905 else
906 {
907 bytes_to_read = shm_get_dsp_value (faxd_byte_cnt);
908
909 if (bytes_to_read > 0)
910 {
911 bytes_read = get_frame_descriptor(bytes_to_read);
912 shm_set_dsp_value (faxd_byte_cnt, 0);
913 }
914
915 if (bytes_read)
916 {
917 dfax->dl_pFD->len = bytes_read;
918 dfax->dl_pFD->type = dl_frame_type;
919 l1i_ra_data_ind(hCommFAD);
920
921 #if defined TRACE_RA_FAX_DL_FRAME_TYPE || defined _SIMULATION_
922 trace_ra_fax_dl_frame_type(&dfax->dl_frame_type_last, dl_frame_type, bytes_read);
923 #endif
924
925 }
926 }
927 #if defined TRACE_RA_FAX_DL_FRAME_TYPE || defined _SIMULATION_
928 dfax->dl_frame_type_last = dl_frame_type;
929 #endif
930 }