blob: bc2ba7a28adf4b667770759a543ef57a719208e3 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2005
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/*******************************************************************************
37 *
38 * Filename:
39 * ---------
40 * l1ctm.c
41 *
42 * Project:
43 * --------
44 * MAUI
45 *
46 * Description:
47 * ------------
48 * L1Ctm interface
49 *
50 * Author:
51 * -------
52 * -------
53 *
54 *==============================================================================
55 * HISTORY
56 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
57 *------------------------------------------------------------------------------
58 * removed!
59 * removed!
60 * removed!
61 *
62 * removed!
63 * removed!
64 * removed!
65 * removed!
66 *
67 * removed!
68 * removed!
69 * removed!
70 *
71 * removed!
72 * removed!
73 * removed!
74 *
75 * removed!
76 * removed!
77 * removed!
78 *
79 * removed!
80 * removed!
81 * removed!
82 * removed!
83 * removed!
84 *
85 * removed!
86 * removed!
87 * removed!
88 *
89 * removed!
90 * removed!
91 * removed!
92 *
93 * removed!
94 * removed!
95 * removed!
96 *
97 * removed!
98 * removed!
99 * removed!
100 *
101 * removed!
102 * removed!
103 * removed!
104 *
105 * removed!
106 * removed!
107 * removed!
108 *
109 * removed!
110 * removed!
111 * removed!
112 *
113 * removed!
114 * removed!
115 * removed!
116 *
117 * removed!
118 * removed!
119 * removed!
120 *
121 * removed!
122 * removed!
123 * removed!
124 *
125 * removed!
126 * removed!
127 * removed!
128 *
129 * removed!
130 * removed!
131 * removed!
132 *
133 * removed!
134 * removed!
135 * removed!
136 *
137 * removed!
138 * removed!
139 * removed!
140 *
141 * removed!
142 * removed!
143 * removed!
144 *
145 * removed!
146 * removed!
147 *
148 * removed!
149 * removed!
150 * removed!
151 *
152 * removed!
153 * removed!
154 * removed!
155 *
156 * removed!
157 * removed!
158 * removed!
159 *
160 * removed!
161 * removed!
162 * removed!
163 *
164 * removed!
165 * removed!
166 * removed!
167 *
168 * removed!
169 * removed!
170 * removed!
171 * removed!
172 * removed!
173 * removed!
174 * removed!
175 * removed!
176 * removed!
177 * removed!
178 * removed!
179 * removed!
180 * removed!
181 *
182 * removed!
183 * removed!
184 * removed!
185 *
186 * removed!
187 * removed!
188 * removed!
189 * removed!
190 * removed!
191 * removed!
192 * removed!
193 * removed!
194 * removed!
195 * removed!
196 * removed!
197 * removed!
198 * removed!
199 * removed!
200 * removed!
201 * removed!
202 * removed!
203 * removed!
204 * removed!
205 * removed!
206 * removed!
207 * removed!
208 * removed!
209 *
210 * removed!
211 * removed!
212 * removed!
213 *
214 * removed!
215 * removed!
216 * removed!
217 *
218 * removed!
219 * removed!
220 * removed!
221 *
222 * removed!
223 * removed!
224 * removed!
225 *
226 * removed!
227 * removed!
228 * removed!
229 * removed!
230 *------------------------------------------------------------------------------
231 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
232 *==============================================================================
233 *******************************************************************************/
234
235#ifdef __CTM_SUPPORT__
236
237int dsp_tch_bfi; // temp solution
238#include "kal_public_api.h"
239#include "kal_trace.h"
240#include "reg_base.h"
241#include "sync_data.h"
242
243#include "l1audio.h"
244#include "speech_def.h"
245#include "pcm4way.h"
246#include "l1sp_trc.h"
247#include "am.h"
248#include "ctm_drv.h"
249#include "ctm_params.h"
250#include "ctm_modem.h"
251#include "afe_def.h"
252
253#include "sal_def.h"
254#include "sal_exp.h"
255
256#include "bli_exp.h"
257#include "sp_enhance.h"
258
259#include "sp_drv.h"
260#include "audio_msgid.h"
261#include "drv_sap.h"
262#include "audio_ringbuf.h" // "audio_def.h" // for ring buffer
263#include "media.h"
264#include "spc_io.h"
265
266// Catcher trace
267/*#define L1CTM_TRACE_FUNC(X) kal_trace(TRACE_FUNC, X)
268*/
269/*#define L1CTM_TRACE_STATE(X) kal_trace(TRACE_STATE, X)
270*/
271/*#define L1CTM_TRACE_INFO(X,Y) kal_trace(TRACE_INFO, X, Y)
272*/
273
274//4g TTY
275#define TTY_QUEUE_SIZE 512
276#define NUM_DELAY_FRAME 10
277#define NUM_UL_SEND_FRAME 10
278
279int ctm_hco_vco_state = 0; // 0 - disable; 1 - HCO enable; 2 - VCO enable;
280
281__attribute__((aligned(4)))
282static uint16 zero_dl_pcm[160] =
283{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
284 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
285 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
286 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
287 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
288 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
289 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
290 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
291};
292
293
294#define MORE_ENQUIRY 8
295static uint32 more_enquiry_times;
296static int16 cprm_debug_flag = 0;
297
298#ifdef __SMART_PHONE_MODEM__
299
300#define UL_IN_PCM_RECORD_MD
301#define UL_OUT_PCM_RECORD_MD
302#define DL_IN_PCM_RECORD_MD
303#define DL_OUT_PCM_RECORD_MD
304
305#endif // __SMART_PHONE_MODEM__
306
307
308#define UL_TTY_BUF_LEN 64
309#define UL_CTM_BUF_LEN 256
310#define DL_TTY_BUF_LEN 1024
311#define DL_CTM_BUF_LEN 256
312
313#define PCM_FIFO_LEN 2 // could be 1 ~ N
314#define CTM_SWB_BUF_LEN 640 // 32k*20ms = 640
315#define CTM_WB_BUF_LEN 320 // 16k*20ms = 320
316#define CTM_NB_BUF_LEN 160 // 8k*20ms = 160
317
318#define BLI_SRC_BUFFER_SIZE 2184 // fixed value
319typedef struct{
320 void (*callback_handler)(L1Ctm_Event event, void *data);
321#if defined(__SMART_PHONE_MODEM__)
322 void (*debugCallback)(uint16 pos, uint16 *buffer, uint16 len, bool isDone);
323#endif
324 // speech-channel PCM buffer
325 uint16 ul_pcm_fifo[PCM_FIFO_LEN][CTM_NB_BUF_LEN]; // input buffer size = 160
326 uint16 dl_pcm_fifo[PCM_FIFO_LEN][CTM_NB_BUF_LEN];
327 uint16 ul_pcm_input[PCM_FIFO_LEN][CTM_SWB_BUF_LEN]; // input buffer size = 640
328 uint16 dl_pcm_input[PCM_FIFO_LEN][CTM_SWB_BUF_LEN];
329
330 uint16 ul_pcm_input2[PCM_FIFO_LEN][CTM_SWB_BUF_LEN]; // input buffer size = 640
331 uint16 ul_pcm_output2[PCM_FIFO_LEN][CTM_SWB_BUF_LEN]; // output buffer size = 640
332
333 uint16 ul_pcm_output[PCM_FIFO_LEN][CTM_NB_BUF_LEN]; //160
334 uint16 ul_pcm_output_wb[PCM_FIFO_LEN][CTM_WB_BUF_LEN]; //320
335 uint16 ul_pcm_output_swb[PCM_FIFO_LEN][CTM_SWB_BUF_LEN]; //640
336
337 uint16 dl_pcm_output[PCM_FIFO_LEN][CTM_NB_BUF_LEN]; //160
338 uint16 dl_pcm_output_wb[PCM_FIFO_LEN][CTM_WB_BUF_LEN]; //320
339 uint16 dl_pcm_output_swb[PCM_FIFO_LEN][CTM_SWB_BUF_LEN]; //640
340
341 uint16 ul_pcm_input_len[PCM_FIFO_LEN];
342 uint16 dl_pcm_input_len[PCM_FIFO_LEN];
343
344 uint8 internal_buf_ul_in[2184]; // internal buffer for src
345 uint8 internal_buf_ul_out[2184]; // internal buffer for src
346 uint8 internal_buf_dl_in[2184]; // internal buffer for src
347 uint8 internal_buf_dl_out[2184]; // internal buffer for src
348
349 uint8 internal_buf_ul_in2[2184]; // internal buffer for src
350 uint8 internal_buf_ul_out2[2184]; // internal buffer for src
351 uint8 internal_buf_dl_in2[2184]; // internal buffer for src
352 uint8 internal_buf_dl_out2[2184]; // internal buffer for src
353
354 BLI_HANDLE * ul_downsample_16_8;
355 BLI_HANDLE * dl_downsample_16_8;
356 BLI_HANDLE * ul_downsample_32_8;
357 BLI_HANDLE * dl_downsample_32_8;
358 BLI_HANDLE * ul_upsample_8_16;
359 BLI_HANDLE * dl_upsample_8_16;
360 BLI_HANDLE * ul_upsample_8_32;
361 BLI_HANDLE * dl_upsample_8_32;
362
363
364 // text buffer
365 uint8 ul_tty_buf[UL_TTY_BUF_LEN];
366 uint8 ul_ctm_buf[UL_CTM_BUF_LEN];
367 uint8 dl_tty_buf[DL_TTY_BUF_LEN];
368 uint8 dl_ctm_buf[DL_CTM_BUF_LEN];
369 // buffer read write pointer
370 uint16 ul_tty_buf_read; // buf_read == buf_write , means buffer empty
371 uint16 ul_tty_buf_write; // buffer could be filled at most (BUF_LEN - 1) data
372 uint16 ul_ctm_buf_read;
373 uint16 ul_ctm_buf_write;
374 uint16 dl_tty_buf_read;
375 uint16 dl_tty_buf_write;
376 uint16 dl_ctm_buf_read;
377 uint16 dl_ctm_buf_write;
378 // control relative
379 uint16 next_to_process;
380 uint16 pcm_fifo_write;
381 uint16 pcm_fifo_read;
382 uint16 aud_id;
383 uint16 FLAGS;
384 uint16 ul_mute_flags;
385 uint16 dl_mute_flags;
386 uint8 bfi_info[PCM_FIFO_LEN];
387 uint8 l1d_bfi_info[PCM_FIFO_LEN];
388 uint8 interface;
389 uint8 state;
390 uint8 next_ack_timeout;
391 int8 enquiry_count;
392 uint8 enquiry_timeout1;
393 uint8 enquiry_timeout2;
394 uint8 transition_mute;
395 uint8 debug_function;
396
397 // 2g/3g TTY variables
398 bool dl_isTTY;
399 bool ul_isTTY;
400 bool ul_isSending;
401 uint16 ul_send_count;
402
403 // 4g TTY variables
404 uint16 dl_put_count;
405
406 kal_spinlockid lockId;
407 bool skip_hisr;
408 bool stop;
409
410}L1Ctm_Module;
411
412static L1Ctm_Module *l1ctm;
413static RTT_Module rtt;
414
415//extern UNSIGNED TMD_System_Clock;
416
417
418//***** UTF8 special character
419#define ENQUIRY_CHAR 0x5
420#define IDLE_CHAR 0x16
421#define NON_UTF8_CHAR 0xFF
422#define NO_CHAR 0xFF
423
424//***** LCF : L1CTM Control Flag
425// CTM Negotiation relative
426#define LCF_NEGOTIATION_REQ 0x1
427#define LCF_NEGOTIATION 0x2
428#define LCF_SEND_ENQUIRY 0x4
429#define LCF_SEND_ACK 0x8
430#define LCF_FAR_END_DETECTED 0x10
431// speech-channel output relative
432#define LCF_UL_CTM_TRANSMITTING 0x20
433#define LCF_UL_MUTE 0x40
434#define LCF_DL_CTM_RECEIVING 0x80
435#define LCF_DL_BAUDOT_TRANSMITTING 0x100
436#define LCF_DL_MUTE 0x200
437#define LCF_ACKING 0x400
438#define LCF_DL_ACKING 0x800
439
440//***** time-out setting
441#define ENQUIRY_TIMEOUT1 21 // 20 (400 ms) + 1
442#define ENQUIRY_TIMEOUT2 67 // 66 (1320 ms) + 1
443#define NEXT_ACK_TIMEOUT 26 // 25 (500 ms) + 1
444#define DL_TRANSITION_MUTE_TIMEOUT 2 // 40 ms
445
446//***** L1CTM state
447#define L1CTM_READY_STATE 0xAB
448#define L1CTM_CONNECTED_STATE 0xCD
449
450//***** text buffer operation used in l1ctm_in_task
451
452#define UL_TTY_BUF_CHAR_READY() (l1ctm->ul_tty_buf_read != l1ctm->ul_tty_buf_write)
453
454#define UL_TTY_BUF_GET_CHAR(tty_code) { \
455 tty_code = l1ctm->ul_tty_buf[l1ctm->ul_tty_buf_read ++]; \
456 l1ctm->ul_tty_buf_read &= (UL_TTY_BUF_LEN-1); \
457 }
458
459#define UL_TTY_BUF_PUT_CHAR(tty_code) \
460 { \
461 l1ctm->ul_tty_buf[l1ctm->ul_tty_buf_write ++] = tty_code; \
462 l1ctm->ul_tty_buf_write &= (UL_TTY_BUF_LEN-1); \
463 if(l1ctm->ul_tty_buf_write == l1ctm->ul_tty_buf_read) \
464 { \
465 l1ctm->ul_tty_buf_read ++; \
466 l1ctm->ul_tty_buf_read &= (UL_TTY_BUF_LEN-1); \
467 } \
468 }
469
470
471#define DL_TTY_BUF_CHAR_READY() (l1ctm->dl_tty_buf_read != l1ctm->dl_tty_buf_write)
472
473#define DL_TTY_BUF_GET_CHAR(tty_code) { \
474 tty_code = l1ctm->dl_tty_buf[l1ctm->dl_tty_buf_read++]; \
475 l1ctm->dl_tty_buf_read &= (DL_TTY_BUF_LEN-1); \
476 }
477
478#define DL_TTY_BUF_PUT_CHAR(tty_code) \
479 { \
480 l1ctm->dl_tty_buf[l1ctm->dl_tty_buf_write ++] = tty_code; \
481 l1ctm->dl_tty_buf_write &= (DL_TTY_BUF_LEN-1); \
482 if(l1ctm->dl_tty_buf_write == l1ctm->dl_tty_buf_read) \
483 { \
484 l1ctm->dl_tty_buf_read ++; \
485 l1ctm->dl_tty_buf_read &= (DL_TTY_BUF_LEN-1); \
486 } \
487 }
488
489
490#define UL_CTM_BUF_CHAR_READY() (l1ctm->ul_ctm_buf_read != l1ctm->ul_ctm_buf_write)
491
492#define UL_CTM_BUF_GET_CHAR(ctm_code) { \
493 ctm_code = l1ctm->ul_ctm_buf[l1ctm->ul_ctm_buf_read++]; \
494 l1ctm->ul_ctm_buf_read &= (UL_CTM_BUF_LEN - 1); \
495 }
496
497
498#define DL_CTM_BUF_PUT_CHAR(ctm_code) { \
499 l1ctm->dl_ctm_buf[l1ctm->dl_ctm_buf_write++] = ctm_code; \
500 l1ctm->dl_ctm_buf_write &= (DL_CTM_BUF_LEN - 1); \
501 ASSERT(l1ctm->dl_ctm_buf_write != l1ctm->dl_ctm_buf_read);\
502 }
503
504/*==============================================================================*/
505
506/*==== begin of 4G TTY Queue====*/
507
508RINGBUFFER_T(kal_uint8, TTY_QUEUE_SIZE) ul_tty_queue;
509RINGBUFFER_T(kal_uint8, TTY_QUEUE_SIZE) dl_tty_queue;
510
511RINGBUFFER_T(kal_uint8, TTY_QUEUE_SIZE) ul_rtt_queue[8]; // cid: 0~7
512RINGBUFFER_T(kal_uint8, TTY_QUEUE_SIZE) dl_rtt_queue[8]; // cid: 0~7
513
514void ctm_init(void)
515{
516 int i;
517
518 for(i = 0; i < 8; i++){
519 RB_INIT(ul_rtt_queue[i]);
520 RB_INIT(dl_rtt_queue[i]);
521 }
522
523 rtt.isRttOn = false;
524}
525
526
527/* TTY Queue*/
528
529void TTY_LTE_PSR_UL_Queue_Init(void)
530{
531 RB_INIT(ul_tty_queue);
532}
533
534kal_uint8 TTY_LTE_PSR_UL_Get(void)
535{
536 kal_uint8 tty_char;
537 RB_GET(ul_tty_queue, tty_char);
538
539 MD_TRC_L1CTM_TTY_LTE_UL_GET(tty_char);
540
541 return tty_char;
542}
543
544kal_uint16 TTY_LTE_PSR_UL_GetChar(kal_uint8 call_id, kal_uint8 *buf){
545 uint8 ch;
546 kal_prompt_trace(MOD_L1SP, "[TTY_LTE_PSR_UL_GetChar] Enter");
547 if(getRttStatus()==true){
548 if(!RB_EMPTY(ul_rtt_queue[call_id])){
549 RB_GET(ul_rtt_queue[call_id], ch);
550 *buf = ch;
551 kal_prompt_trace(MOD_L1SP, "[TTY_LTE_PSR_UL_GetChar] ch = %x", ch);
552 return 1;
553 }
554 }
555 else{
556 if(!TTY_LTE_PSR_UL_isEmpty()){
557 *buf = TTY_LTE_PSR_UL_Get();
558 kal_prompt_trace(MOD_L1SP, "[TTY_LTE_PSR_UL_GetChar] ch = %x", *buf);
559 return 1;
560 }
561 }
562 return 0;
563
564}
565
566
567kal_uint16 TTY_LTE_PSR_UL_GetString(kal_uint8 call_id, kal_uint8 *buf, kal_uint16 *length)
568{
569 return 0;
570}
571
572
573void TTY_LTE_PSR_UL_Put(kal_uint8 tty_char)
574{
575 RB_PUT(ul_tty_queue, tty_char);
576 MD_TRC_L1CTM_TTY_LTE_UL_PUT(tty_char);
577}
578
579kal_bool TTY_LTE_PSR_UL_isEmpty(void)
580{
581 return RB_EMPTY(ul_tty_queue);
582}
583
584kal_bool TTY_LTE_PSR_UL_isFull(void)
585{
586 return RB_FULL(ul_tty_queue);
587}
588
589kal_uint16 TTY_LTE_PSR_UL_Queue_Size(void)
590{
591 kal_uint16 size = RB_COUNT(ul_tty_queue);
592 MD_TRC_L1CTM_TTY_LTE_UL_QUEUE_SIZE(size);
593 return size;
594}
595
596
597void TTY_LTE_PSR_DL_Queue_Init(void)
598{
599 RB_INIT(dl_tty_queue);
600}
601
602void TTY_LTE_PSR_DL_Put(kal_uint8 tty_char)
603{
604 RB_PUT(dl_tty_queue, tty_char);
605 MD_TRC_L1CTM_TTY_LTE_DL_PUT(tty_char);
606
607}
608
609void TTY_LTE_PSR_DL_PutString(kal_uint8 call_id, kal_uint8 string[256], kal_uint16 length)
610{
611 int i;
612
613 if(getRttStatus()==true){
614 for(i = 0; i < length; i++){
615 if(!RB_FULL(dl_rtt_queue[call_id])){
616 RB_PUT(dl_rtt_queue[call_id], string[i]);
617
618 kal_prompt_trace(MOD_L1SP, "[TTY_LTE_PSR_DL_PutString] cid = %d, ch = %x", call_id, string[i]);
619 }
620 else{
621 break;
622 }
623 }
624
625 SP_L4C_SendERTTSTR(call_id);
626 }
627 else{
628 for(i = 0; i < length; i++){
629 if(!TTY_LTE_PSR_DL_isFull()){
630 TTY_LTE_PSR_DL_Put(string[i]);
631 }
632 else{
633 break;
634 }
635 }
636 }
637 kal_prompt_trace(MOD_L1SP, "[TTY_LTE_PSR_DL_PutString] call_id= %d, length = %d", call_id, length);
638}
639
640
641kal_uint8 TTY_LTE_PSR_DL_Get()
642{
643 kal_uint8 tty_char;
644 RB_GET(dl_tty_queue, tty_char);
645
646 MD_TRC_L1CTM_TTY_LTE_DL_GET(tty_char);
647
648 return tty_char;
649}
650
651kal_uint16 TTY_LTE_PSR_DL_Queue_Size(void)
652{
653 kal_uint16 size = RB_COUNT(dl_tty_queue);
654 MD_TRC_L1CTM_TTY_LTE_DL_QUEUE_SIZE(size);
655 return size;
656
657}
658
659kal_bool TTY_LTE_PSR_DL_isEmpty(void)
660{
661 return RB_EMPTY(dl_tty_queue);
662}
663
664kal_bool TTY_LTE_PSR_DL_isFull(void)
665{
666 return RB_FULL(dl_tty_queue);
667}
668
669/*=====end of 4G TTY queue=====*/
670
671
672void SP_L4C_SetERTTSTR(kal_uint8 call_id, kal_uint8 string[256], kal_uint16 length){
673 int i;
674 for(i = 0; i < length; i++){
675 if(!RB_FULL(ul_rtt_queue[call_id])){
676 RB_PUT(ul_rtt_queue[call_id], string[i]);
677 kal_prompt_trace(MOD_L1SP, "[SP_L4C_SetERTTSTR] call_id = %d, char = %x ", call_id, string[i]);
678 }
679 }
680
681 kal_prompt_trace(MOD_L1SP, "[SP_L4C_SetERTTSTR] call_id = %d, length = %d ", call_id, length);
682
683}
684
685void SP_L4C_SendERTTSTR(uint8 call_id){
686
687 ilm_L4C_ERTT_STRING_t *local_para;
688
689 int i;
690 uint8 ch;
691 uint16 len = RB_COUNT(dl_rtt_queue[call_id]);
692
693 local_para = (ilm_L4C_ERTT_STRING_t *) construct_local_para( sizeof(ilm_L4C_ERTT_STRING_t), TD_CTRL);
694 local_para -> call_id = call_id;
695 local_para -> length = len;
696
697 for(i = 0; i < len; i++){
698 if(!RB_EMPTY(dl_rtt_queue[call_id])){
699 RB_GET(dl_rtt_queue[call_id], ch);
700 local_para -> string[i] = ch;
701
702 kal_prompt_trace(MOD_L1SP, "[SP_L4C_SendERTTSTR] cid = %d, ch = %x", call_id, ch);
703 }
704
705 }
706
707 msg_send6(MOD_MED, MOD_L4C, AUDIO_SAP, MSG_ID_AUDIO_L4C_ERTTSTR, (local_para_struct *)local_para, NULL);
708
709 kal_prompt_trace(MOD_L1SP, "[SP_L4C_SendERTTSTR] cid = %d, length = %d", call_id, local_para -> length);
710
711}
712
713
714void l1ctm_init(void)
715{
716 l1ctm = (L1Ctm_Module*) 0;
717}
718
719
720#define PCM_BFI_SHIFT 1
721void l1ctm_in_hisr()
722{
723 MD_TRC_L1CTM_IN_HISR_ENTER();
724
725 if(l1ctm->skip_hisr)
726 return;
727 uint16 buf_idx, bfi_data, bfi_rec, bfi_store_idx;
728
729 buf_idx = l1ctm->pcm_fifo_read;
730 if(buf_idx >= PCM_FIFO_LEN)
731 buf_idx -= PCM_FIFO_LEN;
732
733 bfi_store_idx = buf_idx + PCM_BFI_SHIFT;
734 if(bfi_store_idx >= PCM_FIFO_LEN)
735 bfi_store_idx -= PCM_FIFO_LEN;
736
737
738 if(l1ctm->pcm_fifo_read == l1ctm->next_to_process){
739 MD_TRC_L1CTM_BUF_OVFLOW();
740 if(l1ctm->stop){
741 l1ctm->skip_hisr = true;
742 SpcIO_MsgQueuePut(SPC_ID_AUDIO_CONTROL_CTM_CLOSE, 0, 0, SPC_MSG_FROM_AUDHISR);
743 }
744 return;
745 }
746
747 // uplink-path
748 if(l1ctm->ul_mute_flags & (1 << l1ctm->pcm_fifo_read))
749 PCM4WAY_FillSE(0);
750 else
751 {
752 uint16 bufLen = SAL_PcmEx_GetBufLen(SAL_PCMEX_PNW_BUF_M2D_UL1);
753 PCM4WAY_PutToSE2((const uint16*)(l1ctm->ul_pcm_output2[buf_idx]));
754
755 if(CTM_NB_BUF_LEN == bufLen){
756 PCM4WAY_PutToSE((const uint16*)(l1ctm->ul_pcm_output[buf_idx]));
757 }
758 else if(CTM_WB_BUF_LEN == bufLen){
759 PCM4WAY_PutToSE((const uint16*)(l1ctm->ul_pcm_output_wb[buf_idx]));
760 }
761 else{
762 PCM4WAY_PutToSE((const uint16*)(l1ctm->ul_pcm_output_swb[buf_idx]));
763 }
764 }
765
766 l1ctm->ul_pcm_input_len[buf_idx] = PCM4WAY_GetFromMic((uint16*)(l1ctm->ul_pcm_input[buf_idx]));
767 PCM4WAY_GetFromMic2((uint16*)(l1ctm->ul_pcm_input2[buf_idx]));
768 kal_prompt_trace(MOD_L1SP, "l1ctm->ul_pcm_input_len[buf_idx] = %d", l1ctm->ul_pcm_input_len[buf_idx]);
769
770 // downlink-path
771 if(l1ctm->dl_mute_flags & (1 << l1ctm->pcm_fifo_read))
772 PCM4WAY_FillSpk(0);
773 else{
774 uint16 bufLen = SAL_PcmEx_GetBufLen(SAL_PCMEX_PNW_BUF_M2D_DL1);
775 if(CTM_NB_BUF_LEN == bufLen){
776 PCM4WAY_PutToSpk((const uint16*)(l1ctm->dl_pcm_output[buf_idx]));
777 }
778 else if(CTM_WB_BUF_LEN == bufLen){
779 PCM4WAY_PutToSpk((const uint16*)(l1ctm->dl_pcm_output_wb[buf_idx]));
780 }
781 else{
782 PCM4WAY_PutToSpk((const uint16*)(l1ctm->dl_pcm_output_swb[buf_idx]));
783 }
784
785 }
786
787 l1ctm->dl_pcm_input_len[buf_idx] = PCM4WAY_GetFromSD((uint16*)(l1ctm->dl_pcm_input[buf_idx]));
788
789
790 bfi_data = SAL_CTM_GetValue(SAL_CTM_VALUE_TYPE_FACCH_REPORT);
791
792 bfi_rec = (bfi_data&0x1)|(((bfi_data&0x10)>>4)<<1)|(((bfi_data&0x100)>>8)<<2)|(((bfi_data&0x1000)>>12)<<3)|(((bfi_data&0x4000)>>14)<<4);
793
794
795 l1ctm->bfi_info[buf_idx] = bfi_rec;
796
797 if(dsp_tch_bfi > 0)
798 l1ctm->l1d_bfi_info[bfi_store_idx] = 1;
799 else
800 l1ctm->l1d_bfi_info[bfi_store_idx] = 0;
801
802 l1ctm->pcm_fifo_write++;
803 if(l1ctm->pcm_fifo_write == 2 * PCM_FIFO_LEN)
804 l1ctm->pcm_fifo_write = 0;
805 l1ctm->pcm_fifo_read++;
806 if(l1ctm->pcm_fifo_read == 2 * PCM_FIFO_LEN)
807 l1ctm->pcm_fifo_read = 0;
808
809 if(l1ctm->stop){
810 l1ctm->skip_hisr = true;
811 SpcIO_MsgQueuePut(SPC_ID_AUDIO_CONTROL_CTM_CLOSE, 0, 0, SPC_MSG_FROM_AUDHISR);
812
813 }
814 else{
815 L1Audio_SetEvent(l1ctm->aud_id, (void*)0); // involve L1Audio task to run CTM modem
816 }
817 MD_TRC_L1CTM_IN_HISR_LEAVE();
818}
819
820//uint8 A[20]={'A','B', 'C','D','E','F','G','H','I','J','1','2','3','4','5','6','7','8','9','0'};
821//uint8 B[20]={'1','2', '3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0'};
822int ind = 0;
823int indA = 0;
824int indB = 0;
825int wc = 0;
826int sz = 0;
827
828void l1ctm_in_task_2g_3g()
829{
830 uint16 l1ctmFlags, ctmFlags, interface, buf_idx;
831
832
833 uint32 ul_ds_inLen, ul_ds_outLen, dl_ds_inLen, dl_ds_outLen;
834 uint32 ul_us_inLen, ul_us_outLen, dl_us_inLen, dl_us_outLen;
835
836 uint16 *p_ul_ds_inBuf, *p_ul_ds_outBuf;
837 uint16 *p_dl_ds_inBuf, *p_dl_ds_outBuf;
838
839 uint16 *p_ul_us_inBuf, *p_ul_us_outBuf;
840 uint16 *p_dl_us_inBuf, *p_dl_us_outBuf;
841 uint8 utf8_code;
842 kal_bool bfi_flag;
843
844
845 if(l1ctm == (L1Ctm_Module*) 0)
846 return;
847
848 while(l1ctm->next_to_process != l1ctm->pcm_fifo_write)
849 {
850 buf_idx = l1ctm->next_to_process;
851 if(buf_idx >= PCM_FIFO_LEN)
852 buf_idx -= PCM_FIFO_LEN;
853
854 /******************************************************
855 * ul_pcm_input -> ul_pcm_fifo -> ul_pcm_output *
856 * 32k 8k 32k *
857 * [BAUDOT] -> [CTM] *
858 ******************************************************/
859
860
861 /*[CTM blisrc] UL downsample start*/
862
863
864
865 p_ul_ds_inBuf = l1ctm->ul_pcm_input[buf_idx];
866 p_ul_ds_outBuf = l1ctm->ul_pcm_fifo[buf_idx];
867
868 if(CTM_WB_BUF_LEN == l1ctm->ul_pcm_input_len[buf_idx]){
869 ul_ds_inLen = CTM_WB_BUF_LEN << 1;
870 ul_ds_outLen = CTM_NB_BUF_LEN << 1;
871 BLI_Convert(l1ctm->ul_downsample_16_8, (short *)p_ul_ds_inBuf, &ul_ds_inLen, (short *)p_ul_ds_outBuf, &ul_ds_outLen);
872 }
873 else if(CTM_SWB_BUF_LEN ==l1ctm->ul_pcm_input_len[buf_idx]){
874 ul_ds_inLen = CTM_SWB_BUF_LEN << 1;
875 ul_ds_outLen = CTM_NB_BUF_LEN << 1;
876 BLI_Convert(l1ctm->ul_downsample_32_8, (short *)p_ul_ds_inBuf, &ul_ds_inLen, (short *)p_ul_ds_outBuf, &ul_ds_outLen);
877 }
878 else{
879 memcpy(p_ul_ds_outBuf, p_ul_ds_inBuf, CTM_NB_BUF_LEN << 1);
880 }
881
882 /*[CTM blisrc] UL downsample end*/
883
884
885 /*[CTM blisrc] DL downsample start*/
886
887
888 p_dl_ds_inBuf = l1ctm->dl_pcm_input[buf_idx];
889 p_dl_ds_outBuf = l1ctm->dl_pcm_fifo[buf_idx];
890
891 if(CTM_WB_BUF_LEN == l1ctm->dl_pcm_input_len[buf_idx]){
892 dl_ds_inLen = CTM_WB_BUF_LEN << 1;
893 dl_ds_outLen = CTM_NB_BUF_LEN << 1;
894 BLI_Convert(l1ctm->dl_downsample_16_8, (short *)p_dl_ds_inBuf, &dl_ds_inLen, (short *)p_dl_ds_outBuf, &dl_ds_outLen);
895 }
896 else if(CTM_SWB_BUF_LEN ==l1ctm->dl_pcm_input_len[buf_idx]){
897 dl_ds_inLen = CTM_SWB_BUF_LEN << 1;
898 dl_ds_outLen = CTM_NB_BUF_LEN << 1;
899 BLI_Convert(l1ctm->dl_downsample_32_8, (short *)p_dl_ds_inBuf, &dl_ds_inLen, (short *)p_dl_ds_outBuf, &dl_ds_outLen);
900 }
901 else{
902 memcpy(p_dl_ds_outBuf, p_dl_ds_inBuf, CTM_NB_BUF_LEN << 1);
903 }
904
905
906 /*[CTM blisrc] DL downsample end*/
907
908
909 bfi_flag = (kal_bool)(l1ctm->l1d_bfi_info[buf_idx]);
910
911
912 #ifdef UL_IN_PCM_RECORD_MD
913 if( l1ctm->debugCallback != NULL ){
914 l1ctm->debugCallback(UL_IN_WRITE_FILE_REQUEST, l1ctm->ul_pcm_fifo[buf_idx], CTM_NB_BUF_LEN, false);
915
916 }
917 #endif
918
919 #ifdef DL_IN_PCM_RECORD_MD
920 if( l1ctm->debugCallback != NULL ){
921 l1ctm->debugCallback(DL_IN_WRITE_FILE_REQUEST, l1ctm->dl_pcm_fifo[buf_idx], CTM_NB_BUF_LEN, false);
922 }
923 #endif
924
925
926 l1ctmFlags = l1ctm->FLAGS;
927 interface = l1ctm->interface;
928
929 ctmFlags = ctm_modem_get_flags();
930
931
932 // up-link path input : Baudot Demodulator
933 if(interface != DIRECT_MODE)
934 {
935 #if !defined(DUPLEX_BAUDOT)
936 if(ctmFlags & CMF_BAUDOT_OUT_BITS_READY && l1ctm->enquiry_count != -2)
937 l1ctmFlags |= LCF_UL_MUTE;
938 else
939 #endif
940 {
941 baudot_demod((const uint16*)l1ctm->ul_pcm_fifo[buf_idx],&ctmFlags, &utf8_code);
942
943 if(ctmFlags & CMF_BAUDOT_IN_DETECTED && l1ctm->enquiry_count != -2)
944 l1ctmFlags |= LCF_UL_MUTE;
945 else if(ctmFlags & CMF_BAUDOT_IN_CHAR)
946 {
947 UL_TTY_BUF_PUT_CHAR(utf8_code);
948 MD_TRC_L1CTM_UL_GET_DECODED_TTY_CHAR(utf8_code);
949 }
950 }
951 }
952
953 // down-link path input : CTM receiver
954 if( l1ctm->interface != DIRECT_MODE ) // Half-duplex CTM for BAUDOT_MODE //mtk01407, 2006-05-22
955 {
956 if( (!(ctmFlags & CMF_CTM_TX_BITS_READY)) || (l1ctmFlags & (LCF_NEGOTIATION | LCF_ACKING)) )
957 { ctm_receiver((const uint16*)l1ctm->dl_pcm_fifo[buf_idx], bfi_flag, &ctmFlags, &utf8_code); }
958 else
959 { // If CTM is transmitting, dump zero patter to CTM receiver that means disable receiving function of CTM
960 // Set bfi = 0 to avoid const zero_dl_pcm[] being modified //mtk01407, 2006-05-17
961 ctm_receiver((const uint16*)zero_dl_pcm, 0, &ctmFlags, &utf8_code);
962 }
963
964 }else // Full-duplex CTM for DIRECT_MODE
965 {
966 ctm_receiver((const uint16*)l1ctm->dl_pcm_fifo[buf_idx], bfi_flag, &ctmFlags, &utf8_code);
967 }
968
969 if(ctmFlags & CMF_CTM_RX_DETECTED)
970 {
971 if(!(l1ctmFlags & LCF_DL_CTM_RECEIVING))
972 {
973 l1ctmFlags |= LCF_DL_CTM_RECEIVING;
974
975 MD_TRC_L1CTM_DL_DETECT_CTM_SYNC();
976
977 SAL_CTM_Switch(true);
978 l1ctm->dl_isTTY = 1;
979
980 if(!(l1ctmFlags & LCF_FAR_END_DETECTED))
981 {
982 l1ctmFlags |= LCF_FAR_END_DETECTED;
983 MD_TRC_L1CTM_FAR_END_CTM_DETECTED();
984 l1ctm->state = L1CTM_CONNECTED_STATE;
985 // first detect far-end CTM
986 if(l1ctmFlags & LCF_NEGOTIATION)
987 {
988 MD_TRC_L1CTM_NEGOTIATION_SUCCESS();
989 l1ctmFlags &= ~LCF_NEGOTIATION;
990 l1ctmFlags |= LCF_DL_ACKING;
991 l1ctm->enquiry_timeout1 = 0;
992 l1ctm->enquiry_timeout2 = 0;
993 if(interface != DIRECT_MODE)
994 l1ctm->enquiry_count = -1; //0;
995 else if(interface == DIRECT_MODE)
996 {
997 l1ctm->callback_handler(CTM_MO_SUCCESS, (void*) 0);
998 l1ctm->enquiry_count = 3;
999 }
1000 }
1001 else
1002 {
1003 MD_TRC_L1CTM_DEMAND_CTM_ACK();
1004 l1ctmFlags |= LCF_SEND_ACK;
1005 l1ctm->next_ack_timeout = NEXT_ACK_TIMEOUT;
1006 if(interface == DIRECT_MODE)
1007 l1ctm->callback_handler(CTM_MT_DETECTED, (void*) 0);
1008 }
1009 }
1010 } // end of if(!(l1ctmFlags & LCF_DL_CTM_RECEIVING))
1011
1012 if(ctmFlags & CMF_CTM_RX_CHAR)
1013 {
1014 MD_TRC_L1CTM_DL_GET_RECEIVED_CTM_CHAR(utf8_code);
1015 if(l1ctmFlags & LCF_DL_ACKING)
1016 {
1017 }
1018 else if(utf8_code == ENQUIRY_CHAR)
1019 {
1020 if(l1ctm->next_ack_timeout == 0)
1021 {
1022 l1ctmFlags |= LCF_SEND_ACK;
1023 l1ctm->next_ack_timeout = NEXT_ACK_TIMEOUT;
1024 }
1025 }
1026 else // receive a normal character
1027 {
1028
1029 if(interface !=DIRECT_MODE)
1030 {
1031 DL_TTY_BUF_PUT_CHAR(utf8_code);
1032 }
1033 else if(interface == DIRECT_MODE)
1034 {
1035 DL_CTM_BUF_PUT_CHAR(utf8_code);
1036 l1ctm->callback_handler(CTM_CHAR_RECEIVED, (void *)(uint32)utf8_code);
1037 }
1038 }
1039 } // end of if(ctmFlags & CMF_CTM_RX_CHAR)
1040 }
1041 else
1042 {
1043 if(l1ctmFlags & LCF_DL_CTM_RECEIVING)
1044 {
1045 MD_TRC_L1CTM_DL_CTM_BURST_END();
1046
1047 l1ctmFlags &= ~LCF_DL_CTM_RECEIVING;
1048 l1ctmFlags &= ~LCF_DL_ACKING;
1049
1050
1051 // command DSP to change to normal speech codec
1052 SAL_CTM_Switch(false);
1053 l1ctm->dl_isTTY = 0;
1054
1055 l1ctm->transition_mute = DL_TRANSITION_MUTE_TIMEOUT;
1056 }
1057 }
1058
1059
1060 // judge RX mute case
1061 if(ctmFlags & CMF_CTM_RX_EARLY_MUTE || l1ctmFlags & LCF_DL_CTM_RECEIVING)
1062 l1ctmFlags |= LCF_DL_MUTE;
1063
1064 if(SAL_CTM_IsOff())
1065 l1ctmFlags |= LCF_DL_MUTE;
1066
1067 if(SAL_CTM_IsIdle() && l1ctm->transition_mute > 0)
1068 {
1069 l1ctm->transition_mute --;
1070 l1ctmFlags |= LCF_DL_MUTE;
1071 }
1072
1073
1074 // down-link path output
1075 if(interface !=DIRECT_MODE)
1076 {
1077 if(ctmFlags & CMF_BAUDOT_OUT_BITS_READY)
1078 {
1079 utf8_code = NON_UTF8_CHAR;
1080
1081 if(ctmFlags & CMF_BAUDOT_OUT_NEAR_EMPTY)
1082 if(DL_TTY_BUF_CHAR_READY())
1083 {
1084 DL_TTY_BUF_GET_CHAR(utf8_code);
1085 MD_TRC_L1CTM_DL_SEND_TTY_CHAR(utf8_code);
1086 }
1087
1088 baudot_mod(utf8_code, l1ctm->dl_pcm_fifo[buf_idx], &ctmFlags);
1089 }
1090 else
1091 {
1092 if(l1ctmFlags & LCF_DL_BAUDOT_TRANSMITTING)
1093 l1ctmFlags &= ~LCF_DL_BAUDOT_TRANSMITTING;
1094
1095 if(DL_TTY_BUF_CHAR_READY())
1096 {
1097 DL_TTY_BUF_GET_CHAR(utf8_code);
1098 MD_TRC_L1CTM_DL_SEND_TTY_CHAR(utf8_code);
1099 baudot_mod(utf8_code, l1ctm->dl_pcm_fifo[buf_idx], &ctmFlags);
1100 #if !defined(DUPLEX_BAUDOT)
1101 baudot_demod_reset();
1102 l1ctmFlags |= LCF_UL_MUTE; // mute for baudot_out is modulating
1103 #endif
1104 l1ctmFlags |= LCF_DL_BAUDOT_TRANSMITTING;
1105 }
1106 }
1107 }
1108
1109 // up-link path output
1110 if(ctmFlags & CMF_CTM_TX_BITS_READY)
1111 {
1112 utf8_code = NON_UTF8_CHAR;
1113
1114 l1ctmFlags &= ~LCF_SEND_ACK;
1115
1116 if(ctmFlags & CMF_CTM_TX_NEAR_EMPTY)
1117 {
1118 utf8_code = IDLE_CHAR;
1119
1120 if(l1ctmFlags & LCF_NEGOTIATION)
1121 {
1122 // Yuan comment out to test the ul nego fail problem in LA.
1123 //if(interface !=DIRECT_MODE && l1ctm->enquiry_timeout1 > 0)
1124 // if(UL_TTY_BUF_CHAR_READY())
1125 // UL_TTY_BUF_GET_CHAR(utf8_code);
1126 //if(interface !=DIRECT_MODE && l1ctm->enquiry_timeout1 > 0)
1127 //utf8_code = ENQUIRY_CHAR;
1128 }
1129 else
1130 {
1131 if(interface !=DIRECT_MODE && UL_TTY_BUF_CHAR_READY())
1132 {
1133 UL_TTY_BUF_GET_CHAR(utf8_code);
1134 }
1135 else if(interface == DIRECT_MODE && UL_CTM_BUF_CHAR_READY())
1136 {
1137 UL_CTM_BUF_GET_CHAR(utf8_code);
1138 l1ctm->callback_handler(CTM_CHAR_SENT, (void *)(uint32)utf8_code);
1139 }
1140 }
1141 MD_TRC_L1CTM_UL_SEND_CTM_CHAR(utf8_code);
1142 l1ctm->ul_send_count = NUM_UL_SEND_FRAME;
1143 l1ctm->ul_isSending = 1;
1144 }
1145 ctm_transmitter(utf8_code, l1ctm->ul_pcm_fifo[buf_idx], &ctmFlags);
1146 }
1147 else
1148 {
1149 if(l1ctmFlags & LCF_UL_CTM_TRANSMITTING)
1150 {
1151 l1ctmFlags &= ~LCF_UL_CTM_TRANSMITTING;
1152 if(l1ctmFlags & LCF_ACKING){
1153 l1ctmFlags &= ~LCF_ACKING;
1154 l1ctm->ul_isTTY = 0;
1155 }
1156
1157 if(interface == DIRECT_MODE)
1158 l1ctm->callback_handler(CTM_TX_BURST_END, (void*) 0);
1159 }
1160
1161 if(l1ctm->enquiry_timeout2 == 0 && l1ctm->enquiry_count == 0)
1162 {
1163 l1ctmFlags &= ~LCF_NEGOTIATION;
1164
1165 MD_TRC_L1CTM_NEGOTIATION_FAIL();
1166 if(interface == DIRECT_MODE)
1167 {
1168 l1ctm->callback_handler(CTM_MO_FAIL, (void*)0);
1169 l1ctm->enquiry_count = 3; // reset enquiry_count to allow next negotiation
1170 }
1171 else // BAUDOT_MODE
1172 l1ctm->enquiry_count = -2;
1173
1174 }
1175
1176 // judge if has character to send
1177 if(l1ctmFlags & LCF_FAR_END_DETECTED)
1178 {
1179 utf8_code = NO_CHAR;
1180
1181 if(interface !=DIRECT_MODE && UL_TTY_BUF_CHAR_READY())
1182 {
1183 UL_TTY_BUF_GET_CHAR(utf8_code);
1184 }
1185 else if(interface == DIRECT_MODE && UL_CTM_BUF_CHAR_READY())
1186 {
1187 UL_CTM_BUF_GET_CHAR(utf8_code);
1188 l1ctm->callback_handler(CTM_CHAR_SENT, (void *)(uint32)utf8_code);
1189 }
1190 else if(l1ctmFlags & LCF_SEND_ACK)
1191 {
1192 MD_TRC_L1CTM_UL_SEND_IDLE_AS_ACK();
1193 utf8_code = IDLE_CHAR;
1194 }
1195
1196 if(utf8_code != NO_CHAR)
1197 {
1198 if(l1ctmFlags & LCF_SEND_ACK)
1199 {
1200 l1ctmFlags &= ~LCF_SEND_ACK;
1201 l1ctmFlags |= LCF_ACKING;
1202 }
1203 MD_TRC_L1CTM_UL_SEND_CTM_CHAR(utf8_code);
1204 ctm_transmitter(utf8_code, l1ctm->ul_pcm_fifo[buf_idx], &ctmFlags);
1205 l1ctmFlags |= LCF_UL_CTM_TRANSMITTING;
1206 l1ctm->ul_send_count = NUM_UL_SEND_FRAME;
1207 l1ctm->ul_isSending = 1;
1208 }
1209 }
1210 else
1211 {
1212 if(l1ctm->enquiry_count > 0)
1213 {
1214 //if(l1ctm->enquiry_count == 3) // Adam : mark for more enquiry
1215 if(l1ctm->enquiry_count == more_enquiry_times)
1216 {
1217 if((interface !=DIRECT_MODE && UL_TTY_BUF_CHAR_READY()) ||
1218 (interface == DIRECT_MODE && (l1ctmFlags & LCF_NEGOTIATION_REQ)))
1219 l1ctmFlags |= (LCF_SEND_ENQUIRY + LCF_NEGOTIATION);
1220 }
1221 else
1222 {
1223 if(l1ctm->enquiry_timeout2 == 0)
1224 l1ctmFlags |= LCF_SEND_ENQUIRY;
1225 }
1226
1227 if(l1ctmFlags & LCF_SEND_ENQUIRY)
1228 {
1229 l1ctm->enquiry_count --;
1230 l1ctm->enquiry_timeout1 = ENQUIRY_TIMEOUT1;
1231 l1ctm->enquiry_timeout2 = ENQUIRY_TIMEOUT2;
1232 MD_TRC_L1CTM_UL_SEND_ENQUIRY_CHAR(3 - l1ctm->enquiry_count);
1233 ctm_transmitter(ENQUIRY_CHAR, l1ctm->ul_pcm_fifo[buf_idx], &ctmFlags);
1234 l1ctmFlags |= LCF_UL_CTM_TRANSMITTING;
1235 l1ctmFlags &= ~(LCF_SEND_ENQUIRY + LCF_NEGOTIATION_REQ);
1236 }
1237 }
1238 }
1239 }
1240
1241 // calculate time out
1242 if(l1ctm->next_ack_timeout > 0)
1243 l1ctm->next_ack_timeout --;
1244 if(l1ctm->enquiry_timeout1 > 0)
1245 l1ctm->enquiry_timeout1 --;
1246 if(l1ctm->enquiry_timeout2 > 0)
1247 l1ctm->enquiry_timeout2 --;
1248
1249
1250 // process output for MUTE case
1251 if(!(l1ctmFlags & LCF_UL_CTM_TRANSMITTING) && (l1ctmFlags & LCF_UL_MUTE))
1252 l1ctm->ul_mute_flags |= 1 << l1ctm->next_to_process;
1253 else
1254 l1ctm->ul_mute_flags &= ~(1 << l1ctm->next_to_process);
1255
1256
1257 if(!(l1ctmFlags & LCF_DL_BAUDOT_TRANSMITTING) && (l1ctmFlags & LCF_DL_MUTE))
1258 l1ctm->dl_mute_flags |= 1 << l1ctm->next_to_process;
1259 else
1260 l1ctm->dl_mute_flags &= ~(1 << l1ctm->next_to_process);
1261
1262 l1ctmFlags &= ~(LCF_UL_MUTE + LCF_DL_MUTE);
1263 l1ctm->FLAGS = l1ctmFlags;
1264
1265
1266
1267 #ifdef UL_OUT_PCM_RECORD_MD
1268 if( l1ctm->debugCallback != NULL ){
1269 if(l1ctm->ul_mute_flags & (1 << l1ctm->next_to_process)) {
1270 l1ctm->debugCallback(UL_OUT_WRITE_FILE_REQUEST, zero_dl_pcm, CTM_NB_BUF_LEN, false);
1271 } else {
1272 l1ctm->debugCallback(UL_OUT_WRITE_FILE_REQUEST, l1ctm->ul_pcm_fifo[buf_idx], CTM_NB_BUF_LEN, false);
1273 }
1274 }
1275 #endif
1276
1277 #ifdef DL_OUT_PCM_RECORD_MD
1278 if( l1ctm->debugCallback != NULL ){
1279 if(l1ctm->dl_mute_flags & (1 << l1ctm->next_to_process)) {
1280 l1ctm->debugCallback(DL_OUT_WRITE_FILE_REQUEST, zero_dl_pcm, CTM_NB_BUF_LEN, false);
1281 } else {
1282 l1ctm->debugCallback(DL_OUT_WRITE_FILE_REQUEST, l1ctm->dl_pcm_fifo[buf_idx], CTM_NB_BUF_LEN, false);
1283 }
1284 }
1285 #endif
1286
1287
1288#if defined(UL_IN_PCM_RECORD_MD) || defined(DL_IN_PCM_RECORD_MD) || defined(UL_OUT_PCM_RECORD_MD) || defined(DL_OUT_PCM_RECORD_MD)
1289 {
1290 if( l1ctm->debugCallback != NULL ){
1291 l1ctm->debugCallback(0, NULL, 0, true);
1292 }
1293 }
1294#endif
1295
1296 l1ctm->next_to_process ++;
1297 if(l1ctm->next_to_process == 2 * PCM_FIFO_LEN)
1298 l1ctm->next_to_process = 0;
1299
1300 /*****************************************************
1301 * dl_pcm_output <- dl_pcm_fifo <- dl_pcm_input *
1302 * 32k 8k 32k *
1303 * [CTM] <- [BAUDOT] *
1304 *****************************************************/
1305
1306
1307 /*[CTM blisrc] UL up sampling start*/
1308
1309 p_ul_us_inBuf = l1ctm->ul_pcm_fifo[buf_idx];
1310 p_ul_us_outBuf = l1ctm->ul_pcm_output[buf_idx];
1311
1312 memcpy(p_ul_us_outBuf, p_ul_us_inBuf, CTM_NB_BUF_LEN << 1);
1313
1314 ul_us_inLen = CTM_NB_BUF_LEN << 1;
1315 ul_us_outLen = CTM_WB_BUF_LEN << 1;
1316 p_ul_us_outBuf = l1ctm->ul_pcm_output_wb[buf_idx];
1317 BLI_Convert(l1ctm -> ul_upsample_8_16, (short *)p_ul_us_inBuf, &ul_us_inLen, (short *)p_ul_us_outBuf, &ul_us_outLen);
1318
1319 ul_us_inLen = CTM_NB_BUF_LEN << 1;
1320 ul_us_outLen = CTM_SWB_BUF_LEN << 1;
1321 p_ul_us_outBuf = l1ctm->ul_pcm_output_swb[buf_idx];
1322 BLI_Convert(l1ctm -> ul_upsample_8_32, (short *)p_ul_us_inBuf, &ul_us_inLen, (short *)p_ul_us_outBuf, &ul_us_outLen);
1323
1324
1325 /*[CTM blisrc] UL up sampling end*/
1326
1327
1328
1329 /*[CTM blisrc] DL up sampling start*/
1330
1331
1332 p_dl_us_inBuf = l1ctm->dl_pcm_fifo[buf_idx];
1333 p_dl_us_outBuf = l1ctm->dl_pcm_output[buf_idx];
1334
1335
1336 memcpy(p_dl_us_outBuf, p_dl_us_inBuf, CTM_NB_BUF_LEN << 1);
1337
1338 dl_us_inLen = CTM_NB_BUF_LEN << 1;
1339 dl_us_outLen = CTM_WB_BUF_LEN << 1;
1340 p_dl_us_outBuf = l1ctm->dl_pcm_output_wb[buf_idx];
1341 BLI_Convert(l1ctm -> dl_upsample_8_16, (short *)p_dl_us_inBuf, &dl_us_inLen, (short *)p_dl_us_outBuf, &dl_us_outLen);
1342
1343 dl_us_inLen = CTM_NB_BUF_LEN << 1;
1344 dl_us_outLen = CTM_SWB_BUF_LEN << 1;
1345 p_dl_us_outBuf = l1ctm->dl_pcm_output_swb[buf_idx];
1346 BLI_Convert(l1ctm -> dl_upsample_8_32, (short *)p_dl_us_inBuf, &dl_us_inLen, (short *)p_dl_us_outBuf, &dl_us_outLen);
1347
1348 /*[CTM blisrc] DL up sampling end*/
1349
1350 if(l1ctm->ul_isSending){
1351 l1ctm->ul_isTTY = 1;
1352 l1ctm->ul_send_count --;
1353 }
1354
1355 if(l1ctm->ul_send_count == 0){
1356 l1ctm->ul_isTTY = 0;
1357 l1ctm->ul_isSending = 0;
1358 }
1359 uint16 *ptrSrc;
1360 uint16 *ptrDest;
1361 if(VCO_MODE == l1ctm->interface && (!l1ctm->ul_isTTY)){
1362 ptrSrc = l1ctm->ul_pcm_input[buf_idx];
1363 if(CTM_SWB_BUF_LEN == l1ctm->ul_pcm_input_len[buf_idx]){
1364 ptrDest = l1ctm->ul_pcm_output_swb[buf_idx];
1365 }
1366 else if(CTM_WB_BUF_LEN == l1ctm->ul_pcm_input_len[buf_idx]){
1367 ptrDest = l1ctm->ul_pcm_output_wb[buf_idx];
1368 }
1369 else{
1370 ptrDest = l1ctm->ul_pcm_output[buf_idx];
1371 }
1372
1373 memcpy(ptrDest, ptrSrc, l1ctm->ul_pcm_input_len[buf_idx] * sizeof(uint16));
1374 }
1375 if(HCO_MODE == l1ctm->interface && (!l1ctm->dl_isTTY)){
1376 ptrSrc = l1ctm->dl_pcm_input[buf_idx];
1377 if(CTM_SWB_BUF_LEN == l1ctm->dl_pcm_input_len[buf_idx]){
1378 ptrDest = l1ctm->dl_pcm_output_swb[buf_idx];
1379 }
1380 else if(CTM_WB_BUF_LEN == l1ctm->dl_pcm_input_len[buf_idx]){
1381 ptrDest = l1ctm->dl_pcm_output_wb[buf_idx];
1382 }
1383 else{
1384 ptrDest = l1ctm->dl_pcm_output[buf_idx];
1385 }
1386
1387 memcpy(ptrDest, ptrSrc, l1ctm->dl_pcm_input_len[buf_idx] * sizeof(uint16));
1388 }
1389
1390 //copy 2nd mic data directly
1391 ptrSrc = l1ctm->ul_pcm_input2[buf_idx];
1392 ptrDest = l1ctm->ul_pcm_output2[buf_idx];
1393 memcpy(ptrDest, ptrSrc, l1ctm->ul_pcm_input_len[buf_idx] * sizeof(uint16));
1394
1395 }
1396
1397}
1398
1399void l1ctm_in_task_4g()
1400{
1401 uint16 l1ctmFlags, ctmFlags, interface, buf_idx;
1402
1403
1404 uint32 ul_ds_inLen, ul_ds_outLen, dl_ds_inLen, dl_ds_outLen;
1405 uint32 ul_us_inLen, ul_us_outLen, dl_us_inLen, dl_us_outLen;
1406
1407 uint16 *p_ul_ds_inBuf, *p_ul_ds_outBuf;
1408 uint16 *p_dl_ds_inBuf, *p_dl_ds_outBuf;
1409
1410 uint16 *p_ul_us_inBuf, *p_ul_us_outBuf;
1411 uint16 *p_dl_us_inBuf, *p_dl_us_outBuf;
1412
1413 uint8 utf8_code;
1414
1415
1416 if(l1ctm == (L1Ctm_Module*) 0)
1417 return;
1418
1419 while(l1ctm->next_to_process != l1ctm->pcm_fifo_write)
1420 {
1421 buf_idx = l1ctm->next_to_process;
1422 if(buf_idx >= PCM_FIFO_LEN)
1423 buf_idx -= PCM_FIFO_LEN;
1424
1425
1426 /******************************************************
1427 * ul_pcm_input -> ul_pcm_fifo -> ul_pcm_output *
1428 * 32k 8k 32k *
1429 * [BAUDOT] -> [CTM] *
1430 ******************************************************/
1431
1432
1433
1434 /*[CTM blisrc] UL downsample start*/
1435
1436 p_ul_ds_inBuf = l1ctm->ul_pcm_input[buf_idx];
1437 p_ul_ds_outBuf = l1ctm->ul_pcm_fifo[buf_idx];
1438
1439 if(CTM_WB_BUF_LEN == l1ctm->ul_pcm_input_len[buf_idx]){
1440 ul_ds_inLen = CTM_WB_BUF_LEN << 1;
1441 ul_ds_outLen = CTM_NB_BUF_LEN << 1;
1442 BLI_Convert(l1ctm->ul_downsample_16_8, (short *)p_ul_ds_inBuf, &ul_ds_inLen, (short *)p_ul_ds_outBuf, &ul_ds_outLen);
1443 }
1444 else if(CTM_SWB_BUF_LEN ==l1ctm->ul_pcm_input_len[buf_idx]){
1445 ul_ds_inLen = CTM_SWB_BUF_LEN << 1;
1446 ul_ds_outLen = CTM_NB_BUF_LEN << 1;
1447 BLI_Convert(l1ctm->ul_downsample_32_8, (short *)p_ul_ds_inBuf, &ul_ds_inLen, (short *)p_ul_ds_outBuf, &ul_ds_outLen);
1448 }
1449 else{
1450 memcpy(p_ul_ds_outBuf, p_ul_ds_inBuf, CTM_NB_BUF_LEN << 1);
1451 }
1452
1453 /*[CTM blisrc] UL downsample end*/
1454
1455
1456 /*[CTM blisrc] DL downsample start*/
1457
1458 p_dl_ds_inBuf = l1ctm->dl_pcm_input[buf_idx];
1459 p_dl_ds_outBuf = l1ctm->dl_pcm_fifo[buf_idx];
1460
1461
1462 if(CTM_WB_BUF_LEN == l1ctm->dl_pcm_input_len[buf_idx]){
1463 dl_ds_inLen = CTM_WB_BUF_LEN << 1;
1464 dl_ds_outLen = CTM_NB_BUF_LEN << 1;
1465 BLI_Convert(l1ctm->dl_downsample_16_8, (short *)p_dl_ds_inBuf, &dl_ds_inLen, (short *)p_dl_ds_outBuf, &dl_ds_outLen);
1466 }
1467 else if(CTM_SWB_BUF_LEN ==l1ctm->dl_pcm_input_len[buf_idx]){
1468 dl_ds_inLen = CTM_SWB_BUF_LEN << 1;
1469 dl_ds_outLen = CTM_NB_BUF_LEN << 1;
1470 BLI_Convert(l1ctm->dl_downsample_32_8, (short *)p_dl_ds_inBuf, &dl_ds_inLen, (short *)p_dl_ds_outBuf, &dl_ds_outLen);
1471 }
1472 else{
1473 memcpy(p_dl_ds_outBuf, p_dl_ds_inBuf, CTM_NB_BUF_LEN << 1);
1474 }
1475 /*[CTM blisrc] DL downsample end*/
1476
1477
1478 l1ctmFlags = l1ctm->FLAGS;
1479 interface = l1ctm->interface;
1480
1481 ctmFlags = ctm_modem_get_flags();
1482
1483
1484 // up-link path input : Baudot Demodulator
1485 if(interface != DIRECT_MODE)
1486 {
1487 #if !defined(DUPLEX_BAUDOT)
1488 if(ctmFlags & CMF_BAUDOT_OUT_BITS_READY && l1ctm->enquiry_count != -2){
1489 l1ctmFlags |= LCF_UL_MUTE;
1490
1491 }
1492 else
1493 #endif
1494 {
1495 baudot_demod((const uint16*)l1ctm->ul_pcm_fifo[buf_idx],&ctmFlags, &utf8_code);
1496
1497 if(ctmFlags & CMF_BAUDOT_IN_DETECTED && l1ctm->enquiry_count != -2)
1498 l1ctmFlags |= LCF_UL_MUTE;
1499 else if(ctmFlags & CMF_BAUDOT_IN_CHAR)
1500 {
1501 //UL_TTY_BUF_PUT_CHAR(utf8_code);
1502
1503 if(!TTY_LTE_PSR_UL_isFull())
1504 TTY_LTE_PSR_UL_Put(utf8_code);
1505
1506 MD_TRC_L1CTM_4G_PUT_UL(utf8_code);
1507 MD_TRC_L1CTM_UL_GET_DECODED_TTY_CHAR(utf8_code);
1508
1509
1510 }
1511 }
1512 }
1513
1514 if(l1ctm->dl_put_count == 0){
1515 if(!TTY_LTE_PSR_DL_isEmpty()){
1516 uint8 ch = TTY_LTE_PSR_DL_Get();
1517 DL_TTY_BUF_PUT_CHAR(ch);
1518
1519 MD_TRC_L1CTM_4G_GET_DL(ch);
1520
1521 }
1522 l1ctm->dl_put_count = NUM_DELAY_FRAME;
1523 }
1524 l1ctm->dl_put_count--;
1525
1526
1527 // down-link path output
1528 if(interface !=DIRECT_MODE)
1529 {
1530 if(ctmFlags & CMF_BAUDOT_OUT_BITS_READY)
1531 {
1532 utf8_code = NON_UTF8_CHAR;
1533
1534 if(ctmFlags & CMF_BAUDOT_OUT_NEAR_EMPTY)
1535 if(DL_TTY_BUF_CHAR_READY())
1536 {
1537 DL_TTY_BUF_GET_CHAR(utf8_code);
1538 MD_TRC_L1CTM_DL_SEND_TTY_CHAR(utf8_code);
1539 }
1540
1541 baudot_mod(utf8_code, l1ctm->dl_pcm_fifo[buf_idx], &ctmFlags);
1542 }
1543 else
1544 {
1545 if(l1ctmFlags & LCF_DL_BAUDOT_TRANSMITTING)
1546 l1ctmFlags &= ~LCF_DL_BAUDOT_TRANSMITTING;
1547
1548 if(DL_TTY_BUF_CHAR_READY())
1549 {
1550 DL_TTY_BUF_GET_CHAR(utf8_code);
1551 MD_TRC_L1CTM_DL_SEND_TTY_CHAR(utf8_code);
1552 baudot_mod(utf8_code, l1ctm->dl_pcm_fifo[buf_idx], &ctmFlags);
1553 #if !defined(DUPLEX_BAUDOT)
1554 baudot_demod_reset();
1555 l1ctmFlags |= LCF_UL_MUTE; // mute for baudot_out is modulating
1556 #endif
1557 l1ctmFlags |= LCF_DL_BAUDOT_TRANSMITTING;
1558 }
1559 }
1560 }
1561
1562
1563 // calculate time out
1564 if(l1ctm->next_ack_timeout > 0)
1565 l1ctm->next_ack_timeout --;
1566 if(l1ctm->enquiry_timeout1 > 0)
1567 l1ctm->enquiry_timeout1 --;
1568 if(l1ctm->enquiry_timeout2 > 0)
1569 l1ctm->enquiry_timeout2 --;
1570
1571 // process output for MUTE case
1572 if(!(l1ctmFlags & LCF_UL_CTM_TRANSMITTING) && (l1ctmFlags & LCF_UL_MUTE))
1573 l1ctm->ul_mute_flags |= 1 << l1ctm->next_to_process;
1574 else
1575 l1ctm->ul_mute_flags &= ~(1 << l1ctm->next_to_process);
1576
1577
1578 if(!(l1ctmFlags & LCF_DL_BAUDOT_TRANSMITTING) && (l1ctmFlags & LCF_DL_MUTE))
1579 l1ctm->dl_mute_flags |= 1 << l1ctm->next_to_process;
1580 else
1581 l1ctm->dl_mute_flags &= ~(1 << l1ctm->next_to_process);
1582
1583 l1ctmFlags &= ~(LCF_UL_MUTE + LCF_DL_MUTE);
1584 l1ctm->FLAGS = l1ctmFlags;
1585
1586
1587 l1ctm->next_to_process ++;
1588 if(l1ctm->next_to_process == 2 * PCM_FIFO_LEN)
1589 l1ctm->next_to_process = 0;
1590
1591
1592 /*****************************************************
1593 * dl_pcm_output <- dl_pcm_fifo <- dl_pcm_input *
1594 * 32k 8k 32k *
1595 * [CTM] <- [BAUDOT] *
1596 *****************************************************/
1597
1598
1599 /*[CTM blisrc] UL up sampling start*/
1600
1601 p_ul_us_inBuf = l1ctm->ul_pcm_fifo[buf_idx];
1602 p_ul_us_outBuf = l1ctm->ul_pcm_output[buf_idx];
1603
1604
1605 memcpy(p_ul_us_outBuf, p_ul_us_inBuf, 160 << 1);
1606
1607 ul_us_inLen = CTM_NB_BUF_LEN << 1;
1608 ul_us_outLen = CTM_WB_BUF_LEN << 1;
1609 p_ul_us_outBuf = l1ctm->ul_pcm_output_wb[buf_idx];
1610 BLI_Convert(l1ctm -> ul_upsample_8_16, (short *)p_ul_us_inBuf, &ul_us_inLen, (short *)p_ul_us_outBuf, &ul_us_outLen);
1611
1612 ul_us_inLen = CTM_NB_BUF_LEN << 1;
1613 ul_us_outLen = CTM_SWB_BUF_LEN << 1;
1614 p_ul_us_outBuf = l1ctm->ul_pcm_output_swb[buf_idx];
1615 BLI_Convert(l1ctm -> ul_upsample_8_32, (short *)p_ul_us_inBuf, &ul_us_inLen, (short *)p_ul_us_outBuf, &ul_us_outLen);
1616
1617 /*[CTM blisrc] UL up sampling end*/
1618
1619
1620
1621 /*[CTM blisrc] DL up sampling start*/
1622
1623 p_dl_us_inBuf = l1ctm->dl_pcm_fifo[buf_idx];
1624 p_dl_us_outBuf = l1ctm->dl_pcm_output[buf_idx];
1625
1626
1627 memcpy(p_dl_us_outBuf, p_dl_us_inBuf, 160 << 1);
1628
1629 dl_us_inLen = CTM_NB_BUF_LEN << 1;
1630 dl_us_outLen = CTM_WB_BUF_LEN << 1;
1631 p_dl_us_outBuf = l1ctm->dl_pcm_output_wb[buf_idx];
1632 BLI_Convert(l1ctm -> dl_upsample_8_16, (short *)p_dl_us_inBuf, &dl_us_inLen, (short *)p_dl_us_outBuf, &dl_us_outLen);
1633
1634 dl_us_inLen = CTM_NB_BUF_LEN << 1;
1635 dl_us_outLen = CTM_SWB_BUF_LEN << 1;
1636 p_dl_us_outBuf = l1ctm->dl_pcm_output_swb[buf_idx];
1637 BLI_Convert(l1ctm -> dl_upsample_8_32, (short *)p_dl_us_inBuf, &dl_us_inLen, (short *)p_dl_us_outBuf, &dl_us_outLen);
1638
1639
1640 /*[CTM blisrc] DL up sampling end*/
1641
1642 uint16 *ptrSrc;
1643 uint16 *ptrDest;
1644 if(VCO_MODE == l1ctm->interface){
1645 ptrSrc = l1ctm->ul_pcm_input[buf_idx];
1646
1647 if(CTM_SWB_BUF_LEN == l1ctm->ul_pcm_input_len[buf_idx]){
1648 ptrDest = l1ctm->ul_pcm_output_swb[buf_idx];
1649 }
1650 else if(CTM_WB_BUF_LEN == l1ctm->ul_pcm_input_len[buf_idx]){
1651 ptrDest = l1ctm->ul_pcm_output_wb[buf_idx];
1652 }
1653 else{
1654 ptrDest = l1ctm->ul_pcm_output[buf_idx];
1655 }
1656 memcpy(ptrDest, ptrSrc, l1ctm->ul_pcm_input_len[buf_idx] * sizeof(uint16));
1657
1658 }
1659 else if(HCO_MODE == l1ctm->interface){
1660 ptrSrc = l1ctm->dl_pcm_input[buf_idx];
1661
1662 if(CTM_SWB_BUF_LEN == l1ctm->dl_pcm_input_len[buf_idx]){
1663 ptrDest = l1ctm->dl_pcm_output_swb[buf_idx];
1664 }
1665 else if(CTM_WB_BUF_LEN == l1ctm->dl_pcm_input_len[buf_idx]){
1666 ptrDest = l1ctm->dl_pcm_output_wb[buf_idx];
1667 }
1668 else{
1669 ptrDest = l1ctm->dl_pcm_output[buf_idx];
1670 }
1671
1672 memcpy(ptrDest, ptrSrc, l1ctm->dl_pcm_input_len[buf_idx] * sizeof(uint16));
1673 }
1674 else{
1675 memset(l1ctm->ul_pcm_output[buf_idx], 0, CTM_NB_BUF_LEN << 1);
1676 memset(l1ctm->ul_pcm_output_wb[buf_idx], 0, CTM_WB_BUF_LEN << 1);
1677 memset(l1ctm->ul_pcm_output_swb[buf_idx], 0, CTM_SWB_BUF_LEN << 1);
1678 }
1679 }
1680}
1681
1682void l1ctm_in_task(void *data){
1683 if(L1SP_STATE_4G_SPEECH_ON == L1SP_GetState()){
1684 l1ctm_in_task_4g();
1685 }
1686 else{
1687 l1ctm_in_task_2g_3g();
1688 }
1689}
1690
1691/*============================== L1Ctm APIs ====================================*/
1692
1693uint32 L1Ctm_GetMemReq(void)
1694{
1695 uint32 mem_size = 0;
1696
1697 mem_size = sizeof(L1Ctm_Module) + ctm_modem_mem_req();
1698
1699 return mem_size;
1700}
1701
1702
1703void L1Ctm_Open(L1Ctm_Interface a, L1Ctm_Callback handler, uint8 *buf, uint32 buf_len, L1Ctm_DebugCallback debugCallback)
1704{
1705 uint8 *buf_ptr;
1706
1707 CTM_Param *ctm_param, CTM_param;
1708 #if defined(__DSP_FCORE4__)
1709 CTM_param.cprm_tone_demod_down_samp = 0x7D;
1710 #else
1711 CTM_param.cprm_tone_demod_down_samp = 0x05;
1712 #endif
1713 ctm_param = &CTM_param;
1714
1715 MD_TRC_L1CTM_OPEN();
1716
1717 ASSERT(buf_len >= L1Ctm_GetMemReq());
1718
1719
1720 // allocate memory to L1CTM and CTM modem , and init CTM modem
1721 l1ctm = (L1Ctm_Module*) buf;
1722 buf_ptr = buf + sizeof(L1Ctm_Module);
1723 buf_len -= sizeof(L1Ctm_Module);
1724
1725 ctm_modem_init(buf_ptr, buf_len, ctm_param);
1726
1727 if(ctm_param != NULL)
1728 {
1729 cprm_debug_flag = ctm_param->cprm_tone_demod_down_samp;
1730 MD_TRC_L1CTM_OPEN_PARAM(cprm_debug_flag);
1731 }
1732 else
1733 {
1734 cprm_debug_flag = CPRM_MASK_DOWN_SAMP | CPRM_MASK_REC_DL_PCM_IN | CPRM_MASK_REC_DL_PCM_OUT | CPRM_MASK_REC_UL_PCM_IN | CPRM_MASK_REC_UL_PCM_OUT;
1735 }
1736
1737
1738 l1ctm->interface = a;
1739
1740
1741 {
1742 uint16 bit;
1743 for(bit=0; bit<PCM_FIFO_LEN; bit++) {
1744 l1ctm->ul_mute_flags |= (1<<bit);
1745 l1ctm->dl_mute_flags |= (1<<bit);
1746 }
1747 }
1748
1749 // open BLI Src for ctm
1750 l1ctm -> ul_downsample_32_8 = BLI_Open( 32000, 1, 8000, 1, (signed char*)l1ctm -> internal_buf_ul_in, 0); // open UL down sampling src
1751 l1ctm -> dl_downsample_32_8 = BLI_Open( 32000, 1, 8000, 1, (signed char*)l1ctm -> internal_buf_dl_in, 0); // open DL down sampling src
1752 l1ctm -> ul_upsample_8_32 = BLI_Open( 8000, 1, 32000, 1, (signed char*)l1ctm -> internal_buf_ul_out, 0); // open UL up sampling src
1753 l1ctm -> dl_upsample_8_32 = BLI_Open( 8000, 1, 32000, 1, (signed char*)l1ctm -> internal_buf_dl_out, 0); // open DL up sampling src
1754
1755
1756 l1ctm -> ul_downsample_16_8 = BLI_Open( 16000, 1, 8000, 1, (signed char*)l1ctm -> internal_buf_ul_in2, 0); // open UL down sampling src
1757 l1ctm -> dl_downsample_16_8 = BLI_Open( 16000, 1, 8000, 1, (signed char*)l1ctm -> internal_buf_dl_in2, 0); // open DL down sampling src
1758 l1ctm -> ul_upsample_8_16 = BLI_Open( 8000, 1, 16000, 1, (signed char*)l1ctm -> internal_buf_ul_out2, 0); // open UL up sampling src
1759 l1ctm -> dl_upsample_8_16 = BLI_Open( 8000, 1, 16000, 1, (signed char*)l1ctm -> internal_buf_dl_out2, 0); // open DL up sampling src
1760 // init l1ctm variables
1761
1762 l1ctm -> aud_id = L1Audio_GetAudioID();
1763
1764 // init 2g_3g tty variables
1765 l1ctm->ul_isTTY = 0;
1766 l1ctm->dl_isTTY = 0;
1767 l1ctm->ul_isSending = 0;
1768 l1ctm->ul_send_count = NUM_UL_SEND_FRAME;
1769
1770 // init 4g tty variables
1771 TTY_LTE_PSR_UL_Queue_Init();
1772 TTY_LTE_PSR_DL_Queue_Init();
1773
1774
1775 l1ctm->dl_put_count = NUM_DELAY_FRAME;
1776
1777 L1Audio_SetEventHandler(l1ctm->aud_id , l1ctm_in_task);
1778 L1Audio_SetFlag(l1ctm->aud_id);
1779
1780 l1ctm->callback_handler = handler;
1781#if defined(__SMART_PHONE_MODEM__)
1782 l1ctm->debugCallback = debugCallback;
1783#endif
1784 l1ctm->next_to_process = PCM_FIFO_LEN;
1785 l1ctm->pcm_fifo_write = PCM_FIFO_LEN;
1786 l1ctm->pcm_fifo_read = 0;
1787 l1ctm->ul_tty_buf_read = 0;
1788 l1ctm->ul_tty_buf_write = 0;
1789 l1ctm->ul_ctm_buf_read = 0;
1790 l1ctm->ul_ctm_buf_write = 0;
1791 l1ctm->dl_tty_buf_read = 0;
1792 l1ctm->dl_tty_buf_write = 0;
1793 l1ctm->dl_ctm_buf_read = 0;
1794 l1ctm->dl_ctm_buf_write = 0;
1795 l1ctm->FLAGS = 0;
1796 l1ctm->state = L1CTM_READY_STATE;
1797 l1ctm->next_ack_timeout = 0;
1798 l1ctm->enquiry_count = 3;
1799 l1ctm->debug_function = 0;
1800
1801
1802 if(cprm_debug_flag & CPRM_MASK_MORE_ENQUIRY) // Adam : for more enquiry
1803 {
1804 l1ctm->enquiry_count = MORE_ENQUIRY;
1805 more_enquiry_times = MORE_ENQUIRY;
1806 }
1807 else
1808 more_enquiry_times = 3; // the same setting as Spec
1809
1810 if(cprm_debug_flag & CPRM_MASK_ALWAYS_NEGO_SUC) // Adam : for non-Negotiation test
1811 {
1812 l1ctm->FLAGS = LCF_FAR_END_DETECTED;
1813 if(l1ctm->interface !=DIRECT_MODE)
1814 l1ctm->enquiry_count = -1;
1815 }
1816
1817 l1ctm->enquiry_timeout1 = 0;
1818 l1ctm->enquiry_timeout2 = 0;
1819 l1ctm->transition_mute = 0;
1820
1821 l1ctm->l1d_bfi_info[0] = 0;
1822
1823
1824 SAL_CTM_Switch(false);
1825 l1ctm->dl_isTTY = 0;
1826 SAL_CTM_SetGain(CPRM_CODEBOOK_GAIN_THRESHOLD, CPRM_CODEBOOK_GAIN_VALUE);
1827
1828
1829 l1ctm->interface = a;
1830
1831 if(VCO_MODE == l1ctm->interface){
1832 l1sp_setCtmSpeStatus(1);
1833 SetSPEnhancePath(SpeechEnh_UL);
1834 }
1835 else if(HCO_MODE == l1ctm->interface){
1836 l1sp_setCtmSpeStatus(1);
1837 SetSPEnhancePath(SpeechEnh_DL);
1838 }
1839 else{
1840 l1sp_setCtmSpeStatus(1);
1841 SetSpeechEnhancement(false);
1842 l1sp_setCtmSpeStatus(0);
1843 }
1844 MD_TRC_L1CTM_TTY_MODE((int)l1ctm->interface);
1845
1846
1847 if(DIRECT_MODE != l1ctm->interface)
1848 PCM4WAY_Start(l1ctm_in_hisr, P4W_APP_CTM);
1849
1850 l1ctm->skip_hisr = false;
1851 l1ctm->stop = false;
1852} // End of L1Ctm_open(~)
1853
1854void L1Ctm_Stop(void){
1855 MD_TRC_L1CTM_STOP_ENTER();
1856 l1ctm-> stop = true;
1857 MD_TRC_L1CTM_STOP_LEAVE();
1858}
1859
1860void L1Ctm_Close(void)
1861{
1862 MD_TRC_L1CTM_CLOSE();
1863
1864 ASSERT(l1ctm != (L1Ctm_Module*) 0);
1865 PCM4WAY_Stop(0);
1866
1867
1868 L1Audio_ClearFlag(l1ctm->aud_id);
1869 L1Audio_FreeAudioID(l1ctm->aud_id);
1870
1871 l1sp_setCtmSpeStatus(1);
1872 SetSPEnhancePath(SpeechEnh_All); // remember to turn on SPE while TTY off
1873
1874 BLI_Close( l1ctm->ul_downsample_16_8, 0); // Close UL down sampling src
1875 BLI_Close( l1ctm->dl_downsample_16_8, 0); // Close DL down sampling src
1876 BLI_Close( l1ctm->ul_downsample_32_8, 0); // Close UL down sampling src
1877 BLI_Close( l1ctm->dl_downsample_32_8, 0); // Close DL down sampling src
1878 BLI_Close( l1ctm->ul_upsample_8_16, 0); // Close UL up sampling src
1879 BLI_Close( l1ctm->dl_upsample_8_16, 0); // Close DL up sampling src
1880 BLI_Close( l1ctm->ul_upsample_8_32, 0); // Close UL up sampling src
1881 BLI_Close( l1ctm->dl_upsample_8_32, 0); // Close DL up sampling src
1882 // l1ctm = (L1Ctm_Module*) 0;
1883
1884} // end of L1Ctm_Close(~)
1885
1886void L1Ctm_RTTOpen(){
1887 kal_prompt_trace(MOD_L1SP, "[L1Ctm_RTTOpen] Enter");
1888
1889 TTY_LTE_PSR_UL_Queue_Init();
1890 TTY_LTE_PSR_DL_Queue_Init();
1891
1892 rtt.isRttOn = true;
1893
1894 kal_prompt_trace(MOD_L1SP, "[L1Ctm_RTTOpen] Leave");
1895}
1896
1897void L1Ctm_RTTClose(){
1898
1899 if(rtt.isRttOn) {
1900 ctm_init();
1901 }
1902}
1903
1904bool getRttStatus(){
1905 return rtt.isRttOn;
1906}
1907
1908
1909/*===========================MED_L1Audio_Integrate_Handler===========================================*/
1910
1911
1912#else
1913char dummy_l1ctm_c; /* define a dummy variable to avoid warning message */
1914#endif // __CTM_SUPPORT__