xref: /utopia/UTPA2-700.0.x/modules/dmx/api/dmx/Internal_DMX_debug.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94 
95 ////////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file   apiDMX.c
98 /// @brief  Demux API
99 /// @author MStar Semiconductor,Inc.
100 ////////////////////////////////////////////////////////////////////////////////////////////////////
101 
102 #ifdef MSOS_TYPE_LINUX_KERNEL
103 #else
104 #include <string.h>
105 #include <stdlib.h>
106 #include <stdio.h>
107 #endif
108 #include "MsCommon.h"
109 #include "MsVersion.h"
110 #include "MsOS.h"
111 #include "drvWDT.h"
112 #include "drvTSP.h"
113 #include "apiDMX.h"
114 #include "drvMMIO.h"
115 #include "Internal_DMX_debug.h"
116 
117 #if DMX_DEBUG
118 #if defined(CHIP_NAPOLI)
119 #include "../../hal/napoli/tsp/halTSP.h"
120 #elif defined(CHIP_CLIPPERS)
121 #include "../../hal/clippers/tsp/halTSP.h"
122 #elif defined(CHIP_EIFFEL)
123 #include "../../hal/eiffel/tsp/halTSP.h"
124 #elif defined(CHIP_MADISON)
125 #include "../../hal/madison/tsp/halTSP.h"
126 #elif defined(CHIP_MIAMI)
127 #include "../../hal/miami/tsp/halTSP.h"
128 #elif defined(CHIP_MONACO)
129 #include "../../hal/monaco/tsp/halTSP.h"
130 #elif defined(CHIP_NIKE)
131 #include "../../hal/nike/tsp/halTSP.h"
132 #elif defined(CHIP_MUNICH)
133 #include "../../hal/munich/tsp/halTSP.h"
134 #else
135 #error "no tsp path specify\n"
136 #endif
137 
138 //------------------------------------------------------------------------------
139 // Compile options
140 //------------------------------------------------------------------------------
141 static int _DMX_DBG_Log(char* param1);
142 static int _DMX_DBG_Pvr(char* param1);
143 static int _DMX_DBG_Flt(char* param1);
144 static int _DMX_DBG_Misc(char* param1);
145 
146 //------------------------------------------------------------------------------
147 // Debug Macros
148 //------------------------------------------------------------------------------
149 //------------------------------------------------------------------------------
150 // Constant definition
151 //------------------------------------------------------------------------------
152 #define DMX_DBG_STACK_SIZE 4096
153 #define DMX_DBG_TASK_DELAY 100
154 #define MAX_NUM_PID_MONITOR 16
155 #define DMX_DBG_PVR_TASK_NAME "DMX_DBG_Task"
156 #define DMX_DBG_TASK_NAME "DMX_DBG_Task"
157 #define DMX_DBG_FILE_NAME "DMXDBG"
158 
159 #define DMX_DBG_FILE_PATH_ENV "ENV_DMX_DBG"
160 //------------------------------------------------------------------------------
161 // Internal data structure
162 //------------------------------------------------------------------------------
163 typedef int (*dbg_func)(char* param1);
164 typedef struct
165 {
166     dbg_func  pfun;
167     const char *cmd_str;
168     const char *cmd_help;
169 } DMX_DBG_CMD;
170 
171 //------------------------------------------------------------------------------
172 // Helper Macros
173 //------------------------------------------------------------------------------
174 #define GET_NUM(pCh, u32x)                          \
175     if(strncmp(pCh, "0x", 2) == 0)                  \
176     {sscanf(pCh, "%x", (unsigned int*)&u32x);}else  \
177     {sscanf(pCh, "%d", (unsigned int*)&u32x);}
178 
179 #define GET_PARAM32(_pCh_, _id_, _bFound_, _u32x_)        \
180     {                                                       \
181      strncpy(_u8Tmp, _pCh_, 128);                           \
182      char* _pc_ = strstr(_u8Tmp, _id_);                     \
183      if(_pc_)                                               \
184         {_bFound_ = TRUE;}else{_bFound_ = FALSE;}           \
185      if(_pc_ && strtok(_pc_+2, " "))                        \
186      {                                                      \
187         _pc_ = strtok(_pc_+2, " ");                         \
188         GET_NUM(_pc_, _u32x_);                              \
189      }                                                      \
190     }
191 
192 #define GET_PARAM_STR(_pCh_, _id_, _bFound_, _path_)        \
193     {                                                       \
194      strncpy(_u8Tmp, _pCh_, 128);                           \
195      char* _pc_ = strstr(_u8Tmp, _id_);                     \
196      if(_pc_)                                               \
197         {_bFound_ = TRUE;}else{_bFound_ = FALSE;}           \
198      if(_pc_ && strtok(_pc_+2, " "))                        \
199      {                                                      \
200         _pc_ = strtok(_pc_+2, " ");                         \
201         if(strlen(_pc_) > 128)                              \
202         {dmx_dbg_print("[%s][%d] file path overflow %d\n", __FUNCTION__, __LINE__, (int)strlen(_pc_));break;} \
203         memset(_path_, 0x0, 128);                           \
204         sscanf(_pc_, "%s", (char*)_path_);                  \
205      }                                                      \
206     }
207 
208 #define GET_PARAM_CH(_pCh_, _id_, _bFound_, _ch_)           \
209     {                                                       \
210      strncpy(_u8Tmp, _pCh_, 128);                           \
211      char* _pc_ = strstr(_u8Tmp, _id_);                     \
212      if(_pc_)                                               \
213         {_bFound_ = TRUE;}else{_bFound_ = FALSE;}           \
214      if(_pc_ && strtok(_pc_+2, " "))                        \
215      {                                                      \
216         _pc_ = strtok(_pc_+2, " ");                         \
217         sscanf(_pc_, "%c", (char*)&_ch_);                   \
218      }                                                      \
219     }
220 
221 #if defined(TSP_VERSION) && (TSP_VERSION == TSP_VER_3_0)
222     #define PID_FLT_P(_p_, _id_)                                \
223         _p_ = &(_TspPid[0].Flt[_id_]);                              // low half of the pid filter for eiffel~
224 
225     #define SEC_FLT_P(_p_, _id_)                                \
226         _p_ = (REG_SecFlt*)&(_TspSec1[0].Flt[i]);
227 #else
228     #define PID_FLT_P(_p_, _id_)                                \
229         _p_ = HAL_TSP_GetPidFltReg(0, _id_);
230 
231     #define SEC_FLT_P(_p_, _id_)                                \
232         _p_ = (REG_SecFlt*)&(_TspSec[0].Flt[i]);
233 #endif
234 
235 
236 //------------------------------------------------------------------------------
237 // Local Variable
238 //------------------------------------------------------------------------------
239 #define DMX_DBG_CMD_LOG  0
240 #define DMX_DBG_CMD_PVR  1
241 #define DMX_DBG_CMD_FLT  2
242 #define DMX_DBG_CMD_MISC 3
243 
244 #define DMX_DBG_LOG_OPT_TYPE    "-s" // what kind of info to show
245 #define DMX_DBG_LOG_OPT_PERIOD  "-t" // the period of time to show info
246 #define DMX_DBG_LOG_OPT_PID     "-p" // PIDs to be monitor
247 #define DMX_DBG_LOG_OPT_RESET   "-r" // reset the log
248 #define DMX_DBG_LOG_OPT_LV      "-l" // debug level
249 #define DMX_DBG_LOG_OPT_FILE    "-F" // file path to store dump section data
250 #define DMX_DBG_LOG_OPT_FLTID   "-f" // DMX filter id to monitor
251 
252 #define DMX_DBG_PVR_OPT_PID     "-p" // PIDs to record
253 
254 #define DMX_DBG_FLT_OPT_FLTTYPE "-t" // DMX filter type to open
255 #define DMX_DBG_FLT_OPT_FLTID   "-f" // DMX filter id
256 #define DMX_DBG_FLT_OPT_PID     "-p" // PID
257 #define DMX_DBG_FLT_OPT_BUFADDR "-a" // physical address of section buffer
258 #define DMX_DBG_FLT_OPT_BUFSIZE "-s" // size of section buffer
259 //#define DMX_DBG_FLT_OPT_PATTERN "-m" // match pattern
260 
261 #define DMX_DBG_MISC_OPT_ADDR   "-a" // physical address of memory to dump
262 #define DMX_DBG_MISC_OPT_SIZE   "-s" // size to dump
263 #define DMX_DBG_MISC_OPT_BANK   "-b" // bank number
264 #define DMX_DBG_MISC_OPT_OFSET  "-o" // address offset (16bit)
265 #define DMX_DBG_MISC_OPT_VALUE  "-v" // value write to register
266 #define DMX_DBG_MISC_OPT_FILE   "-f" // file path
267 static    DMX_DBG_CMD _stCmd[] = {
268           {_DMX_DBG_Log, "log", "[0]"COLOR_BROWN" DMX log selection\n\t"COLOR_DBG
269                                 "Usage : "COLOR_BROWN"log"COLOR_DBG" [options]\n"
270                                 "\tOptions   :\n"
271                                 "\t\t"DMX_DBG_LOG_OPT_TYPE": bit field of log selection\n"
272                                     "\t\t\t0x00000001 : filter open\n"
273                                     "\t\t\t0x00000002 : filter set PID\n"
274                                     "\t\t\t0x00000004 : filter close\n"
275                                     "\t\t\t0x00000008 : filter enable / disable\n"
276                                     "\t\t\t0x00000010 : filter info\n"
277                                     "\t\t\t0x00000020 : filter callback\n"
278                                     "\t\t\t0x00000080 : file in operation\n"
279 
280                                     "\t\t\t0x00000100 : copy data\n"
281                                     "\t\t\t0x00000200 : dump copied data\n"
282                                     "\t\t\t0x00000400 : DMX flow setting\n"
283                                     "\t\t\t0x00000800 : section overflow\n"
284                                     "\t\t\t0x00001000 : section arrival\n"
285                                     "\t\t\t0x00002000 : STC change\n"
286                                     "\t\t\t0x00004000 : PCR\n"
287 
288                                     "\t\t\t0x00080000 : show DMX interrupt counter\n"
289                                     "\t\t\t0x00100000 : show file in read address\n"
290                                     "\t\t\t0x00200000 : show PVR write address\n"
291                                     "\t\t\t0x00400000 : a/v fifo reset and status\n"
292                                     "\t\t\t0x02000000 : a/v discontinuity packet count\n"
293                                     "\t\t\t0x04000000 : a/v drop packet count\n"
294                                     "\t\t\t0x08000000 : lock packet count\n"
295                                     "\t\t\t0x10000000 : STC\n"
296                                     "\t\t\t0x20000000 : a/v packet count\n"
297                                     "\t\t\t0x40000000 : a/v overflow\n"
298                                     "\t\t\t0x80000000 : check AEON alive\n"
299                                 "\t\t"DMX_DBG_LOG_OPT_LV": debug level\n"
300                                 "\t\t"DMX_DBG_LOG_OPT_PERIOD": period of time(ms) to show info, default is 100ms\n"
301                                 "\t\t"DMX_DBG_LOG_OPT_PID": PID to monitor("DMX_DBG_LOG_OPT_PID"0x100,...)\n"
302                                 "\t\t"DMX_DBG_LOG_OPT_RESET": reset log to default\n"
303                                 "\t\t"DMX_DBG_LOG_OPT_FILE": file path to store dump section data\n\n"
304                                 "\tex. log "DMX_DBG_LOG_OPT_TYPE"0x00000001\t(show filter open event)\n"
305                                 "\tex. log "DMX_DBG_LOG_OPT_LV"5\t(show all the API call event)\n"
306                                 "\tex. log "DMX_DBG_LOG_OPT_TYPE"0x00000200\t"DMX_DBG_LOG_OPT_PID"0x0\t"DMX_DBG_LOG_OPT_FILE"/temp/pat.bin (dump pat to /temp/pat.bin)\n"
307                                 "\tex. log "DMX_DBG_LOG_OPT_TYPE"0x0000000F "DMX_DBG_LOG_OPT_PID"0x0 0x100 0x200\n"
308                                 "\tex. log "DMX_DBG_LOG_OPT_TYPE"0x00004000 "DMX_DBG_LOG_OPT_PERIOD"10\t(show PCR every 10 ms)\n\n\n"
309                                 },
310 
311           {_DMX_DBG_Pvr, "pvr", "[1]"COLOR_BROWN" Record stream\n\t"COLOR_DBG
312                                 "Usage : "COLOR_BROWN"pvr"COLOR_DBG" file RecordAll CA address size [options]\n"
313                                 "\t\tfile      : writable file path to store recorded data\n"
314                                 "\t\tRecordAll : record all stream\n"
315                                 "\t\tCA        : record stream through dscmb engine\n"
316                                 "\t\taddress   : physical address of record buffer\n"
317                                 "\t\tsize      : size of record buffer\n\n"
318                                 "\t\tOptions   : \n"
319                                 "\t\t"DMX_DBG_PVR_OPT_PID": PIDs to record\n\n"
320                                 "\tex. pvr /temp/pvr.bin 0 0 0x12345678 0x10000\t(record current a/v PID)\n"
321                                 "\tex. pvr /temp/pvr.bin 0 0 0x12345678 0x10000 "DMX_DBG_PVR_OPT_PID"0x0"
322                                 "\t(record pid 0x0 to /temp/pvr.bin)\n\n"
323                                 "\tps. fire again to stop pvr\n\n\n"},
324 
325           {_DMX_DBG_Flt, "flt", "[2]"COLOR_BROWN" DMX filter operation\n\t"COLOR_DBG
326                                 "Usage : "COLOR_BROWN"flt"COLOR_DBG" s/o/c [options]\n"
327                                 "\t\ts : show filter information\n"
328                                 "\t\to : open filter\n"
329                                 "\t\tc : close filter\n\n"
330                                 "\t\tOptions   : \n"
331                                 "\t\t"DMX_DBG_FLT_OPT_FLTTYPE": DMX filter type to open\n"
332                                 "\t\t\ta : audio filter\n"
333                                 "\t\t\tv : video filter\n"
334                                 "\t\t\ts : section filter\n"
335                                 "\t\t\tp : packet filter\n"
336                                 "\t\t"DMX_DBG_FLT_OPT_FLTID": DMX filter index\n"
337                                 "\t\t"DMX_DBG_FLT_OPT_PID": PID to open / close\n"
338                                 "\t\t"DMX_DBG_FLT_OPT_BUFADDR": physicall address section buffer\n\n"
339                                 "\t\t"DMX_DBG_FLT_OPT_BUFSIZE": size of section buffer\n\n"
340 
341 //                                "\t\t"DMX_DBG_FLT_OPT_PATTERN": match/mask/nmask\n"
342                                 "\tex. flt c "DMX_DBG_FLT_OPT_FLTID"10\t(close filter 10)\n"
343                                 "\tex. flt c "DMX_DBG_FLT_OPT_PID"0x100\t(close filters which PID = 0x100)\n"
344                                 "\tex. flt o "DMX_DBG_FLT_OPT_FLTTYPE"v "DMX_DBG_FLT_OPT_PID"0x100\t(open PID = 0x100 video filter)\n"
345                                 "\tex. flt o "DMX_DBG_FLT_OPT_FLTTYPE"s "DMX_DBG_FLT_OPT_PID"0x0 "DMX_DBG_FLT_OPT_BUFADDR"0x800000 "DMX_DBG_FLT_OPT_BUFADDR"0x10000\n"
346                                 "\tex. flt s "DMX_DBG_FLT_OPT_FLTID"10\t(show filter 10 info)\n"
347                                 "\tex. flt s "DMX_DBG_FLT_OPT_PID"0x100\t(show filter info which PID = 0x100)\n\n\n"
348                                                                 },
349           {_DMX_DBG_Misc, "misc", "[3]"COLOR_BROWN" Miscellaneous\n\t"COLOR_DBG
350                                   "Usage : "COLOR_BROWN"misc"COLOR_DBG" d/c/b/m [options]\n"
351                                   "\t\td : show DMX interface configuration\n"
352                                   "\t\tc : show DMX capability(TODO)\n"
353                                   "\t\tb : dump bank register\n"
354                                   "\t\tm : dump memory(physical) [to file]\n\n"
355                                   "\t\tOptions   : \n"
356                                   "\t\t"DMX_DBG_MISC_OPT_FILE": file path\n"
357                                   "\t\t"DMX_DBG_MISC_OPT_ADDR": physical address to dump\n"
358                                   "\t\t"DMX_DBG_MISC_OPT_SIZE": length to dump\n"
359                                   "\t\t"DMX_DBG_MISC_OPT_BANK": bank address\n\n"
360                                   "\tex. misc d\n"
361                                   "\tex. misc m "DMX_DBG_MISC_OPT_ADDR"0x100000 "DMX_DBG_MISC_OPT_SIZE"0x1000 -f/Customer/driver/dump\t(dump address 0x100000~0x101000 to /Customer/driver/dump)\n"
362                                   "\tex. misc b "DMX_DBG_MISC_OPT_BANK"0x101E\t(dump register bank 0x101E)\n"
363                                   "\tex. misc b "DMX_DBG_MISC_OPT_BANK"0x101E "DMX_DBG_MISC_OPT_OFSET"0x20 "DMX_DBG_MISC_OPT_VALUE"0x5A\t(write 0x5A to bank 0x101E, offset 0x20)\n\n\n"
364                                                                 },
365           {NULL, NULL, NULL}
366           };
367 
368 static    DMX_DMX_INPUT_STR _stDmxInput[] = {
369           {DMX_FLOW_INPUT_DEMOD,        "Int. DEMOD"},
370           {DMX_FLOW_INPUT_MEM,          "MEM"},
371           {DMX_FLOW_INPUT_EXT_INPUT0,   "Ext. Input0"},
372           {DMX_FLOW_INPUT_EXT_INPUT1,   "Ext. Input1"},
373           {DMX_FLOW_INPUT_EXT_INPUT2,   "Ext. Input2"},
374           {DMX_FLOW_INPUT_EXT_INPUT3,   "Ext. Input3"},
375           {DMX_FLOW_INPUT_MEM_NOPASSCA, "MEM, not through CA"},
376           {DMX_FLOW_INPUT_DEMOD1,       "DEMOD1"},
377           {DMX_FLOW_INPUT_TSO,          "TSO_0"},
378           {DMX_FLOW_INPUT_TSO1,         "TSO_1"},
379           {DMX_FLOW_INPUT_MEM_PASSCA1,  "MEM, through CA1"},
380           {DMX_FLOW_INPUT_DISABLE,      "no Input"}};
381 
382           DMX_AV_FIFO_STR stDmxType[] = {
383           {DMX_FILTER_TYPE_VIDEO,       "VID"},
384           {DMX_FILTER_TYPE_AUDIO,       "AUD"},
385           {DMX_FILTER_TYPE_AUDIO2,      "AUD2"},
386           {DMX_FILTER_TYPE_SECTION,     "SEC"},
387           {DMX_FILTER_TYPE_PES,         "PES"},
388           {DMX_FILTER_TYPE_PACKET,      "PKT"},
389           {DMX_FILTER_TYPE_PCR,         "PCR"},
390           {DMX_FILTER_TYPE_TELETEXT,    "TTX"},
391           {DMX_FILTER_TYPE_AUDIO3,      "AUD3"},
392           {DMX_FILTER_TYPE_AUDIO4,      "AUD4"},
393           {DMX_FILTER_TYPE_REC,         "PVR"},
394           {DMX_FILTER_TYPE_SCMBCHK,     "SCMBCHK"},
395           {DMX_FILTER_TYPE_SECTION_VER, "VER"}};
396 
397 static    MS_U8 _u8PvrStack[DMX_DBG_STACK_SIZE];
398 static    MS_U8 _u8DbgStack[DMX_DBG_STACK_SIZE];
399 static    FILE* pfPVR = NULL;
400 FILE*     pfSEC = NULL;
401 static    FILE* pfDmxDbg = NULL;
402 static    MS_U8 u8PvrIdx[16] = {0};
403 
404 static    MS_U32 u32PhyWirte = 0;
405 static    MS_U32 u32VirWrite = 0;
406 static    MS_U32 u32VirRead = 0;
407 static    MS_U32 u32VirStart = 0;
408 static    MS_U32 u32VirEnd = 0;
409 
410 static    MS_S32 s32DmxDbgPvrTaskId = -1;
411 static    MS_S32 s32DmxDbgTaskId = -1;
412 
413 static    MS_BOOL bPvrCA = FALSE;
414 static    MS_U32 u32DmxDbgTaskDelay = DMX_DBG_TASK_DELAY;
415 
416 static    MS_U32 u32PrevPCR, u32PrevSTC, u32PrevTime;
417 
418 static    MS_U32 u32TimeStartPvr;
419 static    MS_U32 u32SizeRec;
420 static    MS_BOOL bMonitorAV = FALSE;
421 static    MS_U8 u8PvrIdxVid = 0;
422 static    MS_U8 u8PvrIdxAud = 0;
423 static    MS_U16 u16PvrPidAud = 0;
424 static    MS_U16 u16PvrPidVid = 0;
425 static    char _u8Tmp[128];
426 //------------------------------------------------------------------------------
427 // Global Variable
428 //------------------------------------------------------------------------------
429 MS_U32      u32PidMonitor[MAX_NUM_PID_MONITOR] = {-1UL};
430 MS_U32      u32NumFltMonitor = 0;
431 MS_U32      u32DbgLogFlag = 0;
432 MS_S32      s32DmxDbgMutex = -1;
433 MS_U32      u32DmxDbgFltId = 0xFFFFFFFF;
434 DMX_FLT_DBG_INFO    stDmxDbgInfo[TSP_SECFLT_NUM];
435 
436 //------------------------------------------------------------------------------
437 // Internal implementation
438 //------------------------------------------------------------------------------
_DMX_DBG_LogSel(MS_U32 u32Flag)439 void _DMX_DBG_LogSel(MS_U32 u32Flag)
440 {
441     u32DbgLogFlag = u32Flag;
442 }
443 
_DMX_DBG_PidMonitor(MS_U32 * u32Pids,MS_U32 u32Num)444 void _DMX_DBG_PidMonitor(MS_U32 *u32Pids, MS_U32 u32Num)
445 {
446     if(u32Num > MAX_NUM_PID_MONITOR)
447     {
448         dmx_dbg_print("[%s] monitor number exceed limitation\n", __FUNCTION__);
449         return;
450     }
451 
452     DMX_DBG_ENTRY();
453     u32NumFltMonitor = u32Num;
454     memcpy(u32PidMonitor, u32Pids, sizeof(MS_U32) * u32Num);
455 
456     DMX_DBG_EXIT();
457 
458 }
459 
_DMX_DBG_GetPID(DMX_FILTER_TYPE FltType,MS_U16 * u16Pid)460 MS_U32 _DMX_DBG_GetPID(DMX_FILTER_TYPE FltType, MS_U16* u16Pid)
461 {
462     int i;
463     MS_U32 u32MaxFlt = 0;
464     DMX_Flt_info info;
465     DMX_FILTER_TYPE type;
466 
467     *u16Pid = 0x1FFF;
468 
469     MApi_DMX_GetCap(DMX_CAP_PID_FILTER_NUM, &u32MaxFlt);
470 
471     for(i = 0; i< u32MaxFlt; i++)
472     {
473         MApi_DMX_Info(i, &info, &type, FALSE);
474         if(type == FltType)
475         {
476             MApi_DMX_Pid(i, u16Pid, FALSE);
477             return i;
478         }
479     }
480     return 0xFFFFFFFF;
481 }
482 
_DMX_DBG_Log(char * param1)483 static int _DMX_DBG_Log(char* param1)
484 {
485     char *pCh;
486     int i = 0;
487     MS_U32 u32DbgLv = 0, u32dummy;
488     MS_BOOL bWrongParam = FALSE;
489     MS_BOOL bFound, bRst;
490     char path[128] = {0x0};
491 
492     if(strlen(param1) > 128)
493     {
494         dmx_dbg_print("[%s][%d] buffer overflow \n", __FUNCTION__, __LINE__);
495         return 0;
496     }
497 
498     do
499     {
500         DMX_DBG_ENTRY();
501         u32DmxDbgTaskDelay = DMX_DBG_TASK_DELAY;
502         u32NumFltMonitor = 0;
503         memset(u32PidMonitor, 0x0, sizeof(MS_U32)*MAX_NUM_PID_MONITOR);
504         DMX_DBG_EXIT();
505 
506         GET_PARAM32(param1, DMX_DBG_LOG_OPT_TYPE, bFound, u32DbgLogFlag);
507 
508         if(bFound)
509             ULOGD("DMX", "u32DbgLogFlag = 0x%x\n", (unsigned int)u32DbgLogFlag);
510 
511         GET_PARAM32(param1, DMX_DBG_LOG_OPT_PERIOD, bFound, u32DmxDbgTaskDelay);
512 
513         if(bFound)
514             ULOGD("DMX", "u32DmxDbgTaskDelay = %d ms\n", (unsigned int)u32DmxDbgTaskDelay);
515 
516         if((!(u32DbgLogFlag & DMX_DBG_LOG_COPYDATA1)) && (pfSEC != NULL))
517         {
518             fclose(pfSEC);
519             pfSEC = NULL;
520         }
521 
522         GET_PARAM32(param1, DMX_DBG_LOG_OPT_FLTID, bFound, u32DmxDbgFltId);
523         if(bFound)
524         {
525            dmx_dbg_print("\tmonitor flt %d\n", (int)u32DmxDbgFltId);
526         }
527         else
528         {
529             u32DmxDbgFltId = 0xFFFFFFFF;
530         }
531         GET_PARAM32(param1, DMX_DBG_LOG_OPT_RESET, bRst, u32dummy);
532         if(bRst)
533         {
534             u32DbgLogFlag = 0x0;
535             u32DmxDbgTaskDelay = DMX_DBG_TASK_DELAY;
536 
537             DMX_DBG_ENTRY();
538             u32NumFltMonitor = 0;
539             memset(u32PidMonitor, 0x0, sizeof(MS_U32)*MAX_NUM_PID_MONITOR);
540             DMX_DBG_EXIT();
541 
542             if(pfSEC != NULL)
543             {
544                 fclose(pfSEC);
545                 pfSEC = NULL;
546             }
547         }
548 
549 
550         GET_PARAM32(param1, DMX_DBG_LOG_OPT_LV, bFound, u32DbgLv);
551         if(bFound)
552         {
553             ULOGD("DMX", "u32DbgLv = %d ms\n", (unsigned int)u32DbgLv);
554             if(u32DbgLv > DMX_DBG_FUNC)
555             {
556                 dmx_dbg_print("wrong parameter [DEBUG log level %d]\n", (int)u32DbgLv);
557                 bWrongParam = TRUE;
558                 break;
559             }
560             else
561             {
562                 MApi_DMX_SetDbgLevel((DMX_DBGMSG_LEVEL)u32DbgLv);
563             }
564         }
565 
566         GET_PARAM_STR(param1, DMX_DBG_LOG_OPT_FILE, bFound, path);
567         if(bFound && (u32DbgLogFlag & DMX_DBG_LOG_COPYDATA1))
568         {
569             if(pfSEC != NULL)
570             {
571                 fclose(pfSEC);
572                 pfSEC = NULL;
573             }
574 
575             pfSEC = fopen(path, "wb");
576             if(pfSEC == NULL)
577             {
578                 dmx_dbg_print("[%s] open file %s failed\n", __FUNCTION__, path);
579                 break;
580             }
581             else
582             {
583                 dmx_dbg_print("dump section data to %s\n", path);
584             }
585         }
586 
587         strncpy(_u8Tmp, param1, 128);
588         pCh = strstr(_u8Tmp, DMX_DBG_LOG_OPT_PID);
589         if(pCh && strtok(pCh+2, " "))
590         {
591             dmx_dbg_print("PIDs to monitor\n");
592             pCh+=2;
593             pCh = strtok(pCh, "-\n");
594             pCh = strtok(pCh, " ,");
595             for(i = 0; i < MAX_NUM_PID_MONITOR; i++)
596             {
597                 GET_NUM(pCh, u32PidMonitor[i]);
598                 dmx_dbg_print("PID[0x%x]\n", (unsigned int)u32PidMonitor[i]);
599                 if(u32PidMonitor[i] > 0x1FFF)
600                 {
601                     dmx_dbg_print("wrong parameter [PID 0x%x]\n", (unsigned int)u32PidMonitor[i]);
602                     bWrongParam = TRUE;
603                     break;
604                 }
605 
606                 u32NumFltMonitor++;
607                 pCh = strtok(NULL, ", ");
608                 if(pCh == NULL)
609                     break;
610             }
611         }
612     }while(0);
613     // show command help information
614     if(bWrongParam)
615     {
616         DMX_DBG_ENTRY();
617         u32NumFltMonitor = 0;
618         memset(u32PidMonitor, 0x0, sizeof(MS_U32)*MAX_NUM_PID_MONITOR);
619         DMX_DBG_EXIT();
620 
621         u32DmxDbgTaskDelay = DMX_DBG_TASK_DELAY;
622 
623         dmx_dbg_print("%s\n", _stCmd[DMX_DBG_CMD_LOG].cmd_help);
624     }
625     return 0;
626 }
627 
628 // [file path] [RecordAll] [CA] [buffer address] [size] [PIDs]
_DMX_DBG_Pvr(char * param1)629 static int _DMX_DBG_Pvr(char* param1)
630 {
631     char* pch = NULL;
632     char* pfRecord = NULL;
633     MS_U32 u32NumPids = 0;
634     unsigned int u32Pids[16] = {0};
635     unsigned int u32Addr, u32Size, bRecordAll, bCA;
636     MS_BOOL bWrongParam = FALSE;
637     int i = 0;
638     char tmp[128] = {0x0};
639 
640     if(strlen(param1) > 128)
641     {
642         dmx_dbg_print("[%s][%d] buffer overflow \n", __FUNCTION__, __LINE__);
643         return 0;
644     }
645 
646     do
647     {
648         strncpy(tmp, param1, 128);
649 
650         pfRecord = strtok(param1, " ,");
651         if(pfRecord == NULL)
652         {
653             dmx_dbg_print("wrong parameter [file path]\n");
654             bWrongParam = TRUE;
655             break;
656         }
657 
658         pch = strtok(NULL, " ,");
659         if(pch == NULL)
660         {
661             dmx_dbg_print("wrong parameter [RecordAll]\n");
662             bWrongParam = TRUE;
663             break;
664         }
665         GET_NUM(pch, bRecordAll);
666     //    bRecordAll = (MS_BOOL)atoi(pch);
667 
668         pch = strtok(NULL, " ,");
669         if(pch == NULL)
670         {
671             dmx_dbg_print("wrong parameter [CA]\n");
672             bWrongParam = TRUE;
673             break;
674         }
675         GET_NUM(pch, bCA);
676     //    bCA = (MS_BOOL)atoi(pch);
677 
678         pch = strtok(NULL, " ,");
679         if(pch == NULL)
680         {
681             dmx_dbg_print("wrong parameter [buffer address]\n");
682             bWrongParam = TRUE;
683             break;
684         }
685         GET_NUM(pch, u32Addr);
686         //u32Addr = (MS_BOOL)atoi(pch);
687 
688         pch = strtok(NULL, " ,");
689         if(pch == NULL)
690         {
691             dmx_dbg_print("wrong parameter [buffer size]\n");
692             //bWrongParam = TRUE;
693             break;
694         }
695         GET_NUM(pch, u32Size);
696     //    u32Size = (MS_BOOL)atoi(pch);
697 
698         pch = strstr(tmp, DMX_DBG_LOG_OPT_PID);
699 
700         if(pch && strtok(pch+2, " "))
701         {
702 
703             u32NumPids = 0;
704             memset(u32Pids, 0x0, sizeof(MS_U32)*16);
705 
706             //ULOGD("DMX", "1 pch = %s\n", pch);
707             pch+=2;
708             pch = strtok(pch, " ,");
709 
710             //ULOGD("DMX", "2 pch = %s\n", pch);
711             for(i = 0; i < MAX_NUM_PID_MONITOR; i++)
712             {
713                 GET_NUM(pch, u32Pids[i]);
714                 dmx_dbg_print("record PID = 0x%x\n", (unsigned int)u32Pids[i]);
715 
716                 if(u32Pids[i] > 0x1FFF)
717                     break;
718 
719                 u32NumPids++;
720                 pch = strtok(NULL, ", ");
721                 if(pch == NULL)
722                     break;
723             }
724         }
725 
726     }while(0);
727     dmx_dbg_print("pfRecord        = %s\n", pfRecord);
728     dmx_dbg_print("bRecordAll      = %d\n", (int)bRecordAll);
729     dmx_dbg_print("bCA             = %d\n", (int)bCA);
730     dmx_dbg_print("buffer address  = 0x%x\n", (unsigned int)u32Addr);
731     dmx_dbg_print("buffer size     = 0x%x\n", (unsigned int)u32Size);
732     dmx_dbg_print("# PID to record = %d\n",(int)u32NumPids);
733     if(!bRecordAll)
734     {
735         if(u32NumPids == 0)
736         {
737             _DMX_DBG_GetPID(DMX_FILTER_TYPE_VIDEO, &u16PvrPidVid);
738             _DMX_DBG_GetPID(DMX_FILTER_TYPE_AUDIO, &u16PvrPidAud);
739             dmx_dbg_print("PID not specify, record current Video[0x%x] Audio[0x%x]\n",
740                             (unsigned int)u16PvrPidVid, (unsigned int)u16PvrPidAud);
741 
742             if(u16PvrPidVid != 0x1FFF)
743             {
744                 u32Pids[u32NumPids] = u16PvrPidVid;
745                 u32NumPids++;
746             }
747 
748             if(u16PvrPidAud != 0x1FFF)
749             {
750                 u32Pids[u32NumPids] = u16PvrPidAud;
751                 u32NumPids++;
752             }
753             bMonitorAV = TRUE;
754          }
755     }
756 
757     if(bWrongParam == TRUE)
758     {
759         dmx_dbg_print("%s\n", _stCmd[DMX_DBG_CMD_PVR].cmd_help);
760     }
761 
762     //ULOGD("DMX", "pfPVR = 0x%x\n", (unsigned int)pfPVR);
763     //ULOGD("DMX", "bWrongParam = 0x%x\n", (int)bWrongParam);
764     //ULOGD("DMX", "u32NumPids = 0x%x\n", (unsigned int)u32NumPids);
765     if((u32TimeStartPvr == 0) && (bWrongParam == FALSE))
766     {
767         ULOGD("DMX", "_DMX_DBG_Record_Start\n");
768         _DMX_DBG_Record_Start(pfRecord, (MS_U32*)u32Pids, u32NumPids, u32Addr, u32Size, bCA, bRecordAll);
769         if(bMonitorAV == TRUE)
770         {
771             u8PvrIdxVid = u8PvrIdx[0];
772             u8PvrIdxAud = u8PvrIdx[1];
773         }
774     }
775     else if(u32TimeStartPvr != 0)
776     {
777         dmx_dbg_print("stop recording\n");
778         _DMX_DBG_Record_Stop();
779     }
780     return 0;
781 }
782 
783 static MS_U8 u8TmpSecBuf[4096];
_DMX_DbgCb(MS_U8 u8DmxId,DMX_EVENT enEvent)784 void _DMX_DbgCb(MS_U8 u8DmxId, DMX_EVENT enEvent)
785 {
786     MS_U32 u32Read = 0;
787     MS_U32 u32Rmn = 0;
788     if(enEvent == DMX_EVENT_DATA_READY)
789     {
790         dmx_dbg_print("[%s] Flt[%d] data ready\n", __FUNCTION__, (int)u8DmxId);
791         if(DMX_FILTER_STATUS_OK != MApi_DMX_CopyData(u8DmxId, u8TmpSecBuf, 4096, &u32Read, &u32Rmn, NULL))
792         {
793             dmx_dbg_print("Flt[%d] copy data error\n", (int)u8DmxId);
794         }
795     }
796 
797     if(enEvent == DMX_EVENT_BUF_OVERFLOW)
798     {
799         dmx_dbg_print("[%s] Flt[%d] buffer overflow\n", __FUNCTION__, (int)u8DmxId);
800         MApi_DMX_Stop(u8DmxId);
801         MApi_DMX_Start(u8DmxId);
802     }
803 }
804 
_DMX_DBG_Flt(char * param1)805 static int _DMX_DBG_Flt(char* param1)
806 {
807     char* pch = NULL;
808     MS_U32 u32FltOp = 0;// 1 : show, 2 : close, 3 : open
809     MS_BOOL bWrongParam = FALSE, bFound;
810     MS_U32 u32Pid   = 0xFFFFFFFF;
811     MS_U32 u32FltId = 0xFFFFFFFF;
812     MS_U32 u32Addr = 0;
813     MS_U32 u32Size = 0;
814 //    MS_U32 u32Match, u32Mask, u32NMask;
815     MS_U8 u8FltType = 0;
816     MS_U32 u32MaxFlt = 0;
817     int i;
818 
819     if(strlen(param1) > 128)
820     {
821         dmx_dbg_print("[%s][%d] buffer overflow \n", __FUNCTION__, __LINE__);
822         return 0;
823     }
824 
825     MApi_DMX_GetCap(DMX_CAP_PID_FILTER_NUM, &u32MaxFlt);
826     do
827     {
828         GET_PARAM_CH(param1, DMX_DBG_FLT_OPT_FLTTYPE, bFound, u8FltType);
829         if(bFound && (u8FltType!= 'a') && (u8FltType != 'v') && (u8FltType != 's') && (u8FltType != 'p'))
830         {
831             dmx_dbg_print("wrong parameter [DMX filter type %c]\n", (char)u8FltType);
832             bWrongParam = TRUE;
833             break;
834         }
835 
836         GET_PARAM32(param1, DMX_DBG_FLT_OPT_PID, bFound, u32Pid);
837         if(bFound)
838         {
839             ULOGD("DMX", "PID = 0x%x\n", (unsigned int)u32Pid);
840             if(u32Pid > 0x1FFF)
841             {
842                 dmx_dbg_print("wrong parameter [PID 0x%x]\n", (unsigned int)u32Pid);
843                 bWrongParam = TRUE;
844                 break;
845             }
846         }
847 
848         GET_PARAM32(param1, DMX_DBG_FLT_OPT_BUFADDR, bFound, u32Addr);
849         GET_PARAM32(param1, DMX_DBG_FLT_OPT_BUFSIZE, bFound, u32Size);
850 
851 
852 #if 0
853         strncpy(tmp, param1, 128);
854         pch = strstr(tmp, DMX_DBG_FLT_OPT_PATTERN);
855         if(pch)
856         {
857             ULOGD("DMX", "-m pch = %s\n", pch);
858             GET_NUM(pch+2, u32Match);
859             ULOGD("DMX", "u32Mask = 0x%x\n", (unsigned int)u32Match);
860             pch = strtok(pch+2, "-\n");
861             pch = strtok(pch+2, " ,");
862             ULOGD("DMX", "1 pch = %s\n", pch);
863             pch = strtok(NULL, " ,");
864             ULOGD("DMX", "2 pch = %s\n", pch);
865             GET_NUM(pch, u32Mask);
866             ULOGD("DMX", "u32Ptn = 0x%x\n", (unsigned int)u32Mask);
867             pch = strtok(NULL, " ,");
868             ULOGD("DMX", "3 pch = %s\n", pch);
869             GET_NUM(pch, u32NMask);
870             ULOGD("DMX", "u32Ptn = 0x%x\n", (unsigned int)u32NMask);
871         }
872 #endif
873 
874         GET_PARAM32(param1, DMX_DBG_FLT_OPT_FLTID, bFound, u32FltId);
875         if(bFound && (u32FltId >= u32MaxFlt))
876         {
877             ULOGD("DMX", "u32FltId = %d\n", (int)u32FltId);
878             dmx_dbg_print("wrong parameter [DMX filter index %d]\n", (int)u32FltId);
879             bWrongParam = TRUE;
880             break;
881         }
882 
883         pch = strtok(param1, " ,");
884         if(pch[0] == 's')
885         {
886             u32FltOp = 1;
887         }
888         else if(pch[0] == 'c')
889         {
890             u32FltOp = 2;
891         }
892         else if(pch[0] == 'o')
893         {
894             u32FltOp = 3;
895         }
896         else
897         {
898             dmx_dbg_print("\n\nwrong parameter [unknown operation %c]\n\n", (char)pch[0]);
899             bWrongParam = TRUE;
900             break;
901         }
902 
903         if(u32FltOp == 1) // show filter information
904         {
905             DMX_Flt_info info;
906             DMX_FILTER_TYPE type;
907 
908             dmx_dbg_print("======== DMX filters ========\n");
909             if((u32FltId != 0xFFFFFFFF) || (u32Pid != 0xFFFFFFFF))
910             {
911                 REG_SecFlt *pSecFilter;
912 
913                 for(i = 0; i < u32MaxFlt; i++)
914                 {
915                     REG_PidFlt* pPidFilter;
916                     PID_FLT_P(pPidFilter, i);
917 
918                     if((i == u32FltId) ||
919                        ((u32Pid != 0xFFFFFFFF) &&
920                        (u32Pid == (HAL_REG32_IndR((REG32 *)pPidFilter) & DMX_PID_NULL))))
921                     {
922                         SEC_FLT_P(pSecFilter, i);
923                         dmx_dbg_print("[DMX filter %d] 0x%08X\n", (int)i,
924                                 (unsigned int)HAL_REG32_IndR((REG32 *)pPidFilter));
925                         dmx_dbg_print("[CTRL  ]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->Ctrl));
926                         dmx_dbg_print("[MATCH0]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->Match[0]));
927                         dmx_dbg_print("[MATCH1]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->Match[1]));
928                         dmx_dbg_print("[MATCH2]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->Match[2]));
929                         dmx_dbg_print("[MATCH3]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->Match[3]));
930                         dmx_dbg_print("[MASK0 ]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->Mask[0]));
931                         dmx_dbg_print("[MASK1 ]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->Mask[1]));
932                         dmx_dbg_print("[MASK2 ]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->Mask[2]));
933                         dmx_dbg_print("[MASK3 ]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->Mask[3]));
934                         dmx_dbg_print("[START ]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->BufStart));
935                         dmx_dbg_print("[END   ]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->BufEnd));
936                         dmx_dbg_print("[READ  ]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->BufRead));
937                         dmx_dbg_print("[WRITE ]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->BufWrite));
938                         dmx_dbg_print("[CURENT]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->BufCur));
939                         dmx_dbg_print("[REMAIN]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->RmnReqCnt));
940                         dmx_dbg_print("[CRC32 ]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->CRC32));
941 #if defined(TSP_VERSION) && (TSP_VERSION == TSP_VER_3_0)
942                         dmx_dbg_print("[NMASK0]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->_x50[0]));
943                         dmx_dbg_print("[NMASK1]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->_x50[1]));
944                         dmx_dbg_print("[NMASK2]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->_x50[2]));
945                         dmx_dbg_print("[NMASK3]\t0x%08X\n\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->_x50[3]));
946 #else
947                         dmx_dbg_print("[NMASK0]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->NMatch[0]));
948                         dmx_dbg_print("[NMASK1]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->NMatch[1]));
949                         dmx_dbg_print("[NMASK2]\t0x%08X\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->NMatch[2]));
950                         dmx_dbg_print("[NMASK3]\t0x%08X\n\n", (unsigned int)HAL_REG32_IndR((REG32 *)&pSecFilter->NMatch[3]));
951 #endif
952                     }
953                 }
954             }
955             else // not specified, show all filters
956             {
957                 REG_PidFlt *pPidFlt;
958                 for(i = 0; i < u32MaxFlt; i++)
959                 {
960                     PID_FLT_P(pPidFlt, i);
961                     dmx_dbg_print("[%03d][0x%06x]\t0x%08X ", (int)i, (unsigned int)((MS_U32)pPidFlt >> 1),
962                         (unsigned int)HAL_REG32_IndR((REG32 *)pPidFlt));
963 
964                     MApi_DMX_Info(i, &info, &type, FALSE);
965 
966                     if(type != 0xFF)
967                     {
968                         if(type == DMX_FILTER_TYPE_SECTION ||
969                            type == DMX_FILTER_TYPE_PES     ||
970                            type == DMX_FILTER_TYPE_PACKET  ||
971                            type == DMX_FILTER_TYPE_TELETEXT||
972                            type == DMX_FILTER_TYPE_SECTION_VER)
973                         {
974 //                            MS_U32 u32Time = MsOS_GetSystemTime();
975 //                            MS_U32 u32Active = (stDmxDbgInfo[i].u32TimeLastDisable == u32Time)?
976 //                                    stDmxDbgInfo[i].u32TimeActive :
977 //                                    stDmxDbgInfo[i].u32TimeActive + (u32Time - stDmxDbgInfo[i].u32TimeLastEnable);
978 
979                             dmx_dbg_print("[%s] SecMode[0x%02X] Life[%04d s] Intr(r/o/c)[%06d/%02d/%02d] CB(r/o)[%06d/%02d]\n",
980                             stDmxType[type].str,
981                             (unsigned int)info.Info.SectInfo.SectMode,
982                             (unsigned int)(((MsOS_GetSystemTime() - stDmxDbgInfo[i].u32TimeCreate)/1000)),
983                             (unsigned int)stDmxDbgInfo[i].u32Int_rdy,
984                             (unsigned int)stDmxDbgInfo[i].u32Int_ovf,
985                             (unsigned int)stDmxDbgInfo[i].u32Int_crc,
986                             (unsigned int)stDmxDbgInfo[i].u32CB_rdy,
987                             (unsigned int)stDmxDbgInfo[i].u32CB_ovf);
988                         }
989                         else
990                         {
991                             dmx_dbg_print("[%s]\n", stDmxType[type].str);
992                         }
993                     }
994                     else
995                     {
996                         dmx_dbg_print("\n");
997                     }
998 
999                 }
1000             }
1001             dmx_dbg_print("====== DMX filters End ======\n");
1002         }
1003         else if(u32FltOp == 2) // close filter
1004         {
1005             if(u32FltId == 0xFFFFFFFF && u32Pid == 0xFFFFFFFF)
1006             {
1007                 dmx_dbg_print("wrong parameter [unknown DMX filter index/PID to close]\n");
1008                 bWrongParam = TRUE;
1009                 break;
1010             }
1011             else
1012             {
1013                 if(u32FltId < u32MaxFlt)
1014                 {
1015                     if(DMX_FILTER_STATUS_ERROR != MApi_DMX_Close(u32FltId))
1016                         dmx_dbg_print("close DMX filter %d\n", (int)u32FltId);
1017                     else
1018                         dmx_dbg_print("close DMX filter %d failed\n", (int)u32FltId);
1019                 }
1020 
1021                 if(u32Pid != 0xFFFFFFFF)
1022                 {
1023                     REG_PidFlt *pPidFlt;
1024                     for(i = 0; i < u32MaxFlt; i++)
1025                     {
1026                         PID_FLT_P(pPidFlt, i);
1027                         if(u32Pid == (HAL_REG32_IndR((REG32 *)pPidFlt) & DMX_PID_NULL))
1028                         {
1029                             if(DMX_FILTER_STATUS_ERROR != MApi_DMX_Close(i))
1030                                 dmx_dbg_print("close DMX filter %d\n", (int)i);
1031                             else
1032                                 dmx_dbg_print("close DMX filter %d failed\n", (int)i);
1033                         }
1034                     }
1035                 }
1036             }
1037         }
1038         else if(u32FltOp == 3) // open filter
1039         {
1040             MS_U8 u8FltOpen = 0;
1041             MS_U32 u32FltType = 0;
1042             DMX_Flt_info info;
1043             memset(&info, 0x0, sizeof(DMX_Flt_info));
1044             if((u8FltType == 0) || (u32Pid == 0xFFFFFFFF) ||
1045                 ((u8FltType == 's' || u8FltType == 'p') &&
1046                    (u32Addr == 0 || u32Size == 0)))
1047             {
1048                 dmx_dbg_print("wrong parameter type[%c] PID[0x%x] addr[0x%x] size[0x%x]\n",
1049                 (unsigned int)u8FltType,
1050                 (unsigned int)u32Pid,
1051                 (unsigned int)u32Addr,
1052                 (unsigned int)u32Size);
1053 
1054                 bWrongParam = TRUE;
1055                 break;
1056             }
1057 
1058             switch(u8FltType)
1059             {
1060                 case 'v':
1061                     u32FltType = DMX_FILTER_TYPE_VIDEO;
1062                     break;
1063                 case 'a':
1064                     u32FltType = DMX_FILTER_TYPE_AUDIO;
1065                     break;
1066                 case 's':
1067                     u32FltType = DMX_FILTER_TYPE_SECTION;
1068                     info.Info.SectInfo.SectBufAddr = (MS_PHYADDR)u32Addr;
1069                     info.Info.SectInfo.SectBufSize = (MS_U32)u32Size;
1070                     info.Info.SectInfo.SectMode    = (DMX_SECT_MODE)(DMX_SECT_MODE_CONTI | DMX_SECT_MODE_CRCCHK);
1071                     info.Info.SectInfo.Event       = (DMX_EVENT)(DMX_EVENT_DATA_READY | DMX_EVENT_BUF_OVERFLOW | DMX_EVENT_SEC_CRCERROR | DMX_EVENT_CB_SELF);
1072                     info.Info.SectInfo.pNotify     = _DMX_DbgCb;
1073                     break;
1074                 case 'p':
1075                     u32FltType = DMX_FILTER_TYPE_PACKET;
1076                     info.Info.SectInfo.SectBufAddr = (MS_PHYADDR)u32Addr;
1077                     info.Info.SectInfo.SectBufSize = (MS_U32)u32Size;
1078                     info.Info.SectInfo.SectMode    = (DMX_SECT_MODE)(DMX_SECT_MODE_CONTI | DMX_SECT_MODE_CRCCHK);
1079                     info.Info.SectInfo.Event       = (DMX_EVENT)(DMX_EVENT_DATA_READY | DMX_EVENT_BUF_OVERFLOW | DMX_EVENT_CB_SELF);
1080                     info.Info.SectInfo.pNotify     = _DMX_DbgCb;
1081                     break;
1082                 default:
1083                     dmx_dbg_print("Wrong parameter [DMX filter type %c]\n", (char)u8FltType);
1084                     bWrongParam = TRUE;
1085                     break;
1086             }
1087 
1088             if(DMX_FILTER_STATUS_OK == MApi_DMX_Open((DMX_FILTER_TYPE)u32FltType, &u8FltOpen))
1089             {
1090                 dmx_dbg_print("Open DMX filter %d\n", (int)u8FltOpen);
1091             }
1092             else
1093             {
1094                 dmx_dbg_print("Open DMX filter failed\n");
1095                 break;
1096             }
1097 
1098             MApi_DMX_Pid(u8FltOpen, (MS_U16*)&u32Pid, TRUE);
1099 
1100             MApi_DMX_Info(u8FltOpen, &info, NULL, TRUE);
1101 
1102             MApi_DMX_Start(u8FltOpen);
1103         }
1104     }while(0);
1105 
1106     if(bWrongParam)
1107     {
1108         dmx_dbg_print("%s\n", _stCmd[DMX_DBG_CMD_FLT].cmd_help);
1109     }
1110 
1111     return 0;
1112 }
1113 
_DMX_DBG_Misc(char * param1)1114 static int _DMX_DBG_Misc(char* param1)
1115 {
1116     MS_U32 u32Bank = 0xFFFFFFFF;
1117     MS_U32 u32Addr = 0xFFFFFFFF;
1118     MS_U32 u32Size = 0xFFFFFFFF;
1119     MS_U32 u32Ofset = 0xFFFFFFFF;
1120     MS_U32 u32Value = 0xFFFFFFFF;
1121 
1122     MS_U32 u32Addr1 = 0;
1123     MS_U32 u32Addr2 = 0;
1124     MS_BOOL bWrongParam = FALSE, bFound, bFile;
1125     char* pch;
1126     char path[128];
1127     int i;
1128     FILE* pfile = NULL;
1129 
1130     if(strlen(param1) > 128)
1131     {
1132         dmx_dbg_print("[%s][%d] buffer overflow \n", __FUNCTION__, __LINE__);
1133         return 0;
1134     }
1135 
1136     do
1137     {
1138         GET_PARAM32(param1, DMX_DBG_MISC_OPT_ADDR, bFound, u32Addr);
1139 
1140         GET_PARAM32(param1, DMX_DBG_MISC_OPT_SIZE, bFound, u32Size);
1141 
1142         GET_PARAM32(param1, DMX_DBG_MISC_OPT_BANK, bFound, u32Bank);
1143 
1144         GET_PARAM32(param1, DMX_DBG_MISC_OPT_OFSET, bFound, u32Ofset);
1145 
1146         GET_PARAM32(param1, DMX_DBG_MISC_OPT_VALUE, bFound, u32Value);
1147 
1148         GET_PARAM_STR(param1, DMX_DBG_MISC_OPT_FILE, bFile, path);
1149 /*
1150         if(bFound)
1151         {
1152             pfile = fopen(path, "wb");
1153             if(pfile == NULL)
1154             {
1155                 dmx_dbg_print("[%s] open file %s failed\n", __FUNCTION__, path);
1156                 break;
1157             }
1158         }
1159 */
1160         pch = strtok(param1, " ,");
1161         if(pch[0] == 'd')
1162         {
1163             DMX_FLOW_INPUT input;
1164             MS_BOOL bInv, bExt, bPara;
1165             if(DMX_FILTER_STATUS_OK == MApi_DMX_Get_FlowInput_Status(DMX_FLOW_PLAYBACK, &input, &bInv, &bExt, &bPara))
1166             {
1167                 dmx_dbg_print("[TS Playback]\tInput[%s]\tInver[%d]\tExt Sync[%d]\tParallel[%d]\n",
1168                 _stDmxInput[input].str,
1169                 (int)bInv, (int)bExt, (int)bPara);
1170             }
1171             else
1172             {
1173                 dmx_dbg_print("[TS Playback] can't get configuration\n");
1174             }
1175 
1176             if(DMX_FILTER_STATUS_OK == MApi_DMX_Get_FlowInput_Status(DMX_FLOW_PVR, &input, &bInv, &bExt, &bPara))
1177             {
1178                 dmx_dbg_print("[TS PVR]\tInput[%s]\tInver[%d]\tExt Sync[%d]\tParallel[%d]\n",
1179                 _stDmxInput[input].str,
1180                 (int)bInv, (int)bExt, (int)bPara);
1181             }
1182             else
1183             {
1184                 dmx_dbg_print("[TS PVR] can't get configuration\n");
1185             }
1186 
1187         }
1188         else if(pch[0] == 'c')
1189         {
1190             // @ TODO
1191         }
1192         else if(pch[0] == 'b')
1193         {
1194             typedef struct {
1195                 MS_U16 L;
1196                 MS_U16 dummy;
1197                 MS_U16 H;
1198                 MS_U16 dummy1;
1199             } MSTAR_REG;
1200 
1201             volatile MSTAR_REG* reg;
1202 
1203             if(u32Bank > 0x2000)
1204             {
1205                 dmx_dbg_print("wrong parameter [Bank address 0x%x]\n", (unsigned int)u32Bank);
1206                 bWrongParam = TRUE;
1207                 break;
1208             }
1209 
1210             MDrv_MMIO_GetBASE(&u32Addr, &u32Size, MS_MODULE_PM);
1211             u32Addr += (u32Bank << 9);
1212 
1213 
1214             reg = (volatile MSTAR_REG*)u32Addr;
1215 
1216             if(u32Ofset != 0xFFFFFFFF)
1217             {
1218                 reg += (u32Ofset >> 1);
1219                 if(u32Ofset & 0x1)
1220                 {
1221                     reg->H = u32Value & 0xFFFF;
1222                 }
1223                 else
1224                 {
1225                     reg->L = u32Value & 0xFFFF;
1226                 }
1227 
1228                 dmx_dbg_print("\twrite 0x%x to bank 0x%x, offset 0x%x\n",
1229                 (unsigned int)u32Value, (unsigned int)u32Bank, (unsigned int)u32Ofset);
1230             }
1231 
1232             dmx_dbg_print("\t[register dump 0x%x]\n", (unsigned int)u32Bank);
1233 
1234             ULOGD("DMX", "\t0/8  1/9  2/A  3/B  4/C  5/D  6/E  7/F\n");
1235             for(i = 0; i < 64; i++)
1236             {
1237                 if(i%4 == 0)
1238                 {
1239                     ULOGD("DMX", "\n%02X\t", (int)i*2);
1240                 }
1241 
1242                 ULOGD("DMX", "%04X %04X ", reg->L, reg->H);
1243                 reg++;
1244             }
1245             ULOGD("DMX", "\n");
1246 
1247         }
1248         else if(pch[0] == 'm')
1249         {
1250             if(u32Addr == 0xFFFFFFFF || u32Size == 0xFFFFFFFF)
1251             {
1252                 dmx_dbg_print("wrong parameter address[0x%x], size[0x%x]\n",
1253                                 (unsigned int)u32Addr, (unsigned int)u32Size);
1254                 bWrongParam = TRUE;
1255                 break;
1256             }
1257             else
1258             {
1259                 dmx_dbg_print("\t[memory dump 0x%x ~ 0x%x(physical)]\n", (unsigned int)u32Addr, (unsigned int)(u32Addr + u32Size));
1260                 u32Addr1    = (MS_U32)MS_PA2KSEG1(u32Addr);
1261                 u32Addr2    = (MS_U32)MS_PA2KSEG1(u32Addr + u32Size);
1262                 if((u32Addr1 == NULL) || (u32Addr2 == NULL))
1263                 {
1264                     dmx_dbg_print("address can't convert to virtual PA[0x%x - 0x%x] size[0x%x]\n",
1265                                     (unsigned int)u32Addr,
1266                                     (unsigned int)(u32Addr + u32Size),
1267                                     (unsigned int)u32Size);
1268                     bWrongParam = TRUE;
1269                     break;
1270                 }
1271 
1272                 if(bFile)
1273                 {
1274                     pfile = fopen(path, "wb");
1275                     if(pfile == NULL)
1276                     {
1277                         dmx_dbg_print("[%s] open file %s failed\n", __FUNCTION__, path);
1278                         break;
1279                     }
1280                 }
1281 
1282                 if(pfile)
1283                 {
1284                     if(u32Size != fwrite((char*)u32Addr1, 1, u32Size, pfile))
1285                     {
1286                         dmx_dbg_print("write file error, length %d\n", (int)u32Size);
1287                         fclose(pfile);
1288                         break;
1289                     }
1290                     else
1291                     {
1292                         dmx_dbg_print("write %d bytes to file %s succeed\n", (int)u32Size, path);
1293                     }
1294                     fclose(pfile);
1295                 }
1296                 else
1297                 {
1298                     for(u32Addr = u32Addr1; u32Addr < u32Addr2; u32Addr++)
1299                     {
1300                         if(u32Addr % 16 ==0)
1301                             ULOGD("DMX", "\n0x%08X : ", (unsigned int)MS_VA2PA((MS_U32)u32Addr));
1302 
1303                         ULOGD("DMX", "%02X ", *(volatile unsigned char*)u32Addr);
1304                     }
1305                 }
1306                 ULOGD("DMX", "\n");
1307             }
1308         }
1309         else
1310         {
1311             dmx_dbg_print("\n\nwrong parameter [unknown operation %c]\n\n", (char)pch[0]);
1312             bWrongParam = TRUE;
1313             break;
1314         }
1315     }while(0);
1316 
1317     if(bWrongParam)
1318     {
1319         dmx_dbg_print("%s\n", _stCmd[DMX_DBG_CMD_MISC].cmd_help);
1320     }
1321     return 0;
1322 }
1323 
_DMX_DBG_CmdHandle(char * cmd,MS_U32 size)1324 static void _DMX_DBG_CmdHandle(char* cmd, MS_U32 size)
1325 {
1326 
1327     int i=0;
1328     char* pP0;
1329 
1330     char *pch = strtok(cmd, " ,");
1331     if(pch != NULL)
1332     {
1333         while(_stCmd[i].pfun != NULL)
1334         {
1335             //dmx_dbg_print("%s", _stCmd[i].cmd_str);
1336             if(strcmp(_stCmd[i].cmd_str, pch) == 0)
1337             {
1338                 pP0 = (char*)strtok(NULL, "\n");
1339 
1340                 _stCmd[i].pfun(pP0);
1341                 return;
1342             }
1343             i++;
1344         }
1345 
1346         i=0;
1347         dmx_dbg_print("===================== DMX debug menu =====================\n");
1348         while(_stCmd[i].pfun != NULL)
1349         {
1350             dmx_dbg_print("%s", _stCmd[i].cmd_help);
1351             i++;
1352         }
1353         dmx_dbg_print("=================== DMX debug menu end ===================\n");
1354 
1355     }
1356 }
1357 
_DMX_DBG_Task(MS_U32 argc,MS_U32 * argv)1358 static void _DMX_DBG_Task(MS_U32 argc, MS_U32* argv)
1359 {
1360 #define STRING_LENGTH 256
1361     char cmd[STRING_LENGTH];
1362     char time[STRING_LENGTH];
1363     char *pCmd, *pTime;
1364     int CmdSize, TimeSize;
1365 
1366     do
1367     {
1368         MsOS_DelayTask(u32DmxDbgTaskDelay);
1369         if(pfDmxDbg == NULL)
1370         {
1371             //dmx_dbg_print("[%s] no dbg file exist\n", __FUNCTION__);
1372             //return;
1373         }
1374         else
1375         {
1376         #if 0
1377             char* ps = gets(cmd);
1378             dmx_dbg_print("%s\n", ps);
1379             _DMX_DBG_CmdHandle(ps, STRING_LENGTH);
1380 
1381         #else
1382 
1383             memset(cmd, 0x0, STRING_LENGTH);
1384             cmd[STRING_LENGTH-2] = '\r';
1385             cmd[STRING_LENGTH-1] = '\n';
1386 
1387             if(fgets(cmd, STRING_LENGTH, pfDmxDbg))
1388             {
1389                 dmx_dbg_print("%s\n", cmd);
1390                 _DMX_DBG_CmdHandle(cmd, STRING_LENGTH);
1391             }
1392 
1393             if(ferror(pfDmxDbg))
1394             {
1395                 dmx_dbg_print("[%s] error reading DMX command file\n", __FUNCTION__);
1396             }
1397         #endif
1398         }
1399 
1400 // ========= debug information ============================================================
1401 
1402         memset(cmd, 0x0, STRING_LENGTH);
1403         memset(time, 0x0, STRING_LENGTH);
1404         pCmd = cmd;
1405         pTime = time;
1406         CmdSize = TimeSize = STRING_LENGTH;
1407 
1408         if(u32DbgLogFlag & DMX_DBG_LOG_AV_OVF)
1409         {
1410             // no function call yet
1411         }
1412 
1413         if(u32DbgLogFlag & DMX_DBG_LOG_FI_READ)
1414         {
1415             MS_U32 u32Read;
1416             MApi_DMX_Filein_GetReadAddr(&u32Read);
1417             dmx_dbg_print("File in read [0x%x]\n", (unsigned int)u32Read);
1418         }
1419 
1420         if(u32DbgLogFlag & DMX_DBG_LOG_PVR_WRITE)
1421         {
1422             MS_U32 u32Write;
1423             MApi_DMX_Pvr_Eng_WriteGet(DMX_PVR_EGN0, &u32Write);
1424             dmx_dbg_print("PVR write [0x%x\n]\n", (unsigned int)u32Write);
1425         }
1426 
1427         if(u32DbgLogFlag & DMX_DBG_LOG_AVFIFO)
1428         {
1429             MS_U32 u32StatusA;
1430             MS_U32 u32StatusV;
1431             MS_U32 u32StatusA2;
1432             MS_U32 u32StatusV3D;
1433 
1434             MApi_DMX_AVFifo_Status(DMX_FILTER_TYPE_VIDEO, &u32StatusV);
1435             MApi_DMX_AVFifo_Status(DMX_FILTER_TYPE_AUDIO, &u32StatusA);
1436             MApi_DMX_AVFifo_Status(DMX_FILTER_TYPE_AUDIO2, &u32StatusA2);
1437             MApi_DMX_AVFifo_Status(DMX_FILTER_TYPE_VIDEO3D, &u32StatusV3D);
1438             dmx_dbg_print("FIFO Status V[%02d] A[%02d] A2[%02d] V3D[%02d]\n",
1439             (int)u32StatusV, (int)u32StatusA, (int)u32StatusA2, (int)u32StatusV3D);
1440         }
1441 
1442         if(u32DbgLogFlag & DMX_DBG_LOG_AV_DISCONTI)
1443         {
1444             MS_U32 u32DisContiV, u32DisContiA;
1445             DMX_DisContiCnt_info info;
1446             info.TspCmd = DMX_DEBUG_CMD_NONE;
1447             info.TspSrc = DMX_DEBUG_SRC_TS0;
1448             info.TspFifo = DMX_DEBUG_FIFO_VIDEO;
1449             MApi_DMX_Get_DisContiCnt(&info, &u32DisContiV);
1450             info.TspFifo = DMX_DEBUG_FIFO_AUDIO;
1451             MApi_DMX_Get_DisContiCnt(&info, &u32DisContiA);
1452 
1453             snprintf(cmd, STRING_LENGTH, "TS0 DisContiCC [V(%02d) A(%02d)]\t", (int)u32DisContiV, (int)u32DisContiA);
1454             //dmx_dbg_print("TS0 discontinuity video[%d] audio[%d]\n", (int)u32DisContiV, (int)u32DisContiA);
1455             pCmd = cmd + strlen(cmd);
1456         }
1457 
1458         if(u32DbgLogFlag & DMX_DBG_LOG_AV_DROP)
1459         {
1460             MS_U32 u32DropV, u32DropA;
1461             DMX_DropPktCnt_info info;
1462             info.TspCmd = DMX_DEBUG_CMD_NONE;
1463             info.TspSrc = DMX_DEBUG_SRC_TS0;
1464             info.TspFifo = DMX_DEBUG_FIFO_VIDEO;
1465             MApi_DMX_Get_DropPktCnt(&info, &u32DropV);
1466             info.TspFifo = DMX_DEBUG_FIFO_AUDIO;
1467             MApi_DMX_Get_DropPktCnt(&info, &u32DropA);
1468             //dmx_dbg_print("TS0 video drop[%d], audio drop[%d]\n", (int)u32DropV, (int)u32DropA);
1469             snprintf(pCmd, STRING_LENGTH - (pCmd - cmd), "Drop [V(%02d) A(%02d)]\t", (int)u32DropV, (int)u32DropA);
1470             pCmd = cmd + strlen(cmd);
1471         }
1472 
1473         if(u32DbgLogFlag & DMX_DBG_LOG_LOCK)
1474         {
1475             MS_U32 u32LockCnt = 0;
1476 
1477             DMX_LockPktCnt_info info;
1478             info.TspCmd = DMX_DEBUG_CMD_NONE;
1479             info.TspTsif = DMX_DEBUG_TSIF_TS0;
1480             MApi_DMX_Get_LockPktCnt(&info, &u32LockCnt);
1481             //dmx_dbg_print("TS0 Lock packet cnt[%d]\n", (int)u32LockCnt);
1482             snprintf(pCmd, STRING_LENGTH - (pCmd - cmd), "Lock [%02d]\t", (int)u32LockCnt);
1483             pCmd = cmd + strlen(cmd);
1484         }
1485 
1486         if(u32DbgLogFlag & (DMX_DBG_LOG_PCR | DMX_DBG_LOG_STC))
1487         {
1488             MS_U32 u32Tmp = MsOS_GetSystemTime();
1489             snprintf(time, STRING_LENGTH, "%sTime [0x%08X, diff(0x%08X)]\t", time, (int)u32Tmp, (int)(u32Tmp - u32PrevTime));
1490             pTime = time + strlen(time);
1491             u32PrevTime = u32Tmp;
1492         }
1493 
1494         if(u32DbgLogFlag & DMX_DBG_LOG_PCR)
1495         {
1496             MS_U32 u32Pcr, u32Pcr32;
1497             MApi_DMX_Pcr_Get(&u32Pcr32, &u32Pcr);
1498             //dmx_dbg_print("PCR[0x%X]\n", (unsigned int)u32Pcr);
1499             snprintf(pTime, STRING_LENGTH - (pTime - time), "PCR [0x%08X, diff(0x%08X)]\t", (int)u32Pcr, (int)(u32Pcr - u32PrevPCR));
1500             pTime = time + strlen(time);
1501             u32PrevPCR = u32Pcr;
1502         }
1503 
1504         if(u32DbgLogFlag & DMX_DBG_LOG_STC)
1505         {
1506             MS_U32 u32Stc, u32Stc32;
1507             MApi_DMX_Stc_Get(&u32Stc32, &u32Stc);
1508             //dmx_dbg_print("STC[0x%X]\n", (unsigned int)u32Stc);
1509             snprintf(pTime, STRING_LENGTH, "STC [0x%08X, diff(0x%08X)]\t", (int)u32Stc, (int)(u32Stc - u32PrevSTC));
1510             pTime = time + strlen(time);
1511             u32PrevSTC = u32Stc;
1512         }
1513 
1514         if(u32DbgLogFlag & DMX_DBG_LOG_AV_PKT)
1515         {
1516             DMX_AVPktCnt_info info;
1517             MS_U32 u32CntA = 0;
1518             MS_U32 u32CntV = 0;
1519 
1520             info.TspCmd = DMX_DEBUG_CMD_NONE;
1521             info.TspFifo = DMX_DEBUG_FIFO_VIDEO;
1522             info.TspFifoSrc = DMX_DEBUG_PKT_DEMUX_0;
1523 
1524             MApi_DMX_Get_AVPktCnt(&info, &u32CntV);
1525             info.TspFifo = DMX_DEBUG_FIFO_AUDIO;
1526             MApi_DMX_Get_AVPktCnt(&info, &u32CntA);
1527             snprintf(pCmd, STRING_LENGTH - (pCmd - cmd), "AV Pkt[V(%02d) A(%02d)]\t", (int)u32CntV, (int)u32CntA);
1528             pCmd = cmd + strlen(cmd);
1529         }
1530 
1531         if(u32DbgLogFlag & DMX_DBG_LOG_AEON_ALIVE)
1532         {
1533             if(MApi_DMX_ChkAlive() == DMX_FILTER_STATUS_ERROR)
1534                 dmx_dbg_print("DMX AEON dead\n");
1535             else
1536                 dmx_dbg_print("DMX AEON alive\n");
1537         }
1538 
1539         if(u32DbgLogFlag & DMX_DBG_LOG_INTR)
1540         {
1541             MS_U32 u32IntrCnt = 0;
1542             MApi_DMX_Get_Intr_Count(&u32IntrCnt);
1543             dmx_dbg_print("[DMX INTR]\tCounter[%d]\n", (int)u32IntrCnt);
1544         }
1545 
1546 
1547         if(cmd[0])
1548             dmx_dbg_print("%s\n", cmd);
1549 
1550         if(time[0])
1551             dmx_dbg_print("%s\n", time);
1552 
1553 // ========= debug information ============================================================
1554 
1555     }while(1);
1556 }
1557 
_DMX_DBG_Pvr_Task(MS_U32 argc,MS_U32 * argv)1558 static void _DMX_DBG_Pvr_Task(MS_U32 argc, MS_U32* argv)
1559 {
1560     MS_U32 u32WriteSiz = 0;
1561     u32TimeStartPvr = MsOS_GetSystemTime();
1562     ULOGD("DMX", "u32TimeStartPvr = %d\n", (int)u32TimeStartPvr);
1563     u32SizeRec = 0;
1564     do
1565     {
1566         MsOS_DelayTask(100);
1567 
1568         if(pfPVR != NULL)
1569         {
1570             if(bMonitorAV == TRUE)
1571             {
1572                 MS_U16 u16VPid, u16APid;
1573                 _DMX_DBG_GetPID(DMX_FILTER_TYPE_VIDEO, &u16VPid);
1574                 _DMX_DBG_GetPID(DMX_FILTER_TYPE_AUDIO, &u16APid);
1575 
1576                 if((u16VPid != u16PvrPidVid) || (u16APid != u16PvrPidAud))
1577                 {
1578                     dmx_dbg_print("Change PID to Video(0x%x), Audio(0x%x)\n",
1579                     (unsigned int)u16VPid,
1580                     (unsigned int)u16APid);
1581 
1582                     MApi_DMX_Pvr_Eng_Pid_Close(DMX_PVR_EGN0, u8PvrIdxVid);
1583                     MApi_DMX_Pvr_Eng_Pid_Close(DMX_PVR_EGN0, u8PvrIdxAud);
1584                     if(DMX_FILTER_STATUS_OK == MApi_DMX_Pvr_Eng_Pid_Open(DMX_PVR_EGN0, (MS_U32)u16VPid, &u8PvrIdxVid))
1585                     {
1586                         ULOGD("DMX", "[%s], open PVR filter %d for pid 0x%x\n", __FUNCTION__, (int)u8PvrIdxVid, (unsigned int)u16VPid);
1587                     }
1588 
1589                     if(DMX_FILTER_STATUS_OK == MApi_DMX_Pvr_Eng_Pid_Open(DMX_PVR_EGN0, (MS_U32)u16APid, &u8PvrIdxAud))
1590                     {
1591                         ULOGD("DMX", "[%s], open PVR filter %d for pid 0x%x\n", __FUNCTION__, (int)u8PvrIdxAud, (unsigned int)u16APid);
1592                     }
1593 
1594                     u16PvrPidVid = u16VPid;
1595                     u16PvrPidAud = u16APid;
1596                 }
1597             }
1598             MApi_DMX_Pvr_Eng_WriteGet(DMX_PVR_EGN0, &u32PhyWirte);
1599             //ULOGD("DMX", "PVR write(phy) = 0x%08x\n", (unsigned int)u32PhyWirte);
1600 
1601             u32VirWrite = (MS_U32)MS_PA2KSEG1(u32PhyWirte);
1602             if(u32VirWrite == 0)
1603             {
1604                 dmx_dbg_print("[%s] ERROR : can't convert physical 0x%x to virtual\n", __FUNCTION__, (unsigned int)u32PhyWirte);
1605             }
1606             //ULOGD("DMX", "PVR write = 0x%x\n", (unsigned int)u32VirWrite);
1607             //ULOGD("DMX", "PVR read  = 0x%x\n", (unsigned int)u32VirRead);
1608             //ULOGD("DMX", "u32SizeRec = %d\n", (unsigned int)(u32SizeRec << 3));
1609             //ULOGD("DMX", "time = %d\n", (unsigned int)(((u32Time - u32TimeStart)/1000)));
1610             //if(((u32Time - u32TimeStart)/1000) != 0)
1611             //    ULOGD("DMX", "BitRate[%08d bps]\n", (int)((u32SizeRec << 3) / ((u32Time - u32TimeStart)/1000)));
1612 
1613             if(u32VirWrite > u32VirRead)
1614             {
1615                 u32WriteSiz = u32VirWrite - u32VirRead;
1616                 if(u32WriteSiz != fwrite((char*)u32VirRead, 1, u32WriteSiz, pfPVR))
1617                 {
1618                     dmx_dbg_print("[%s] ERROR : write %d bytes to file failed\n", __FUNCTION__, (int)u32WriteSiz);
1619                     fclose(pfPVR);
1620                     pfPVR = NULL;
1621                 }
1622                 u32SizeRec += u32WriteSiz;
1623             }
1624             else if(u32VirWrite < u32VirRead)
1625             {
1626                 u32WriteSiz = u32VirEnd - u32VirRead;
1627                 if(u32WriteSiz != fwrite((char*)u32VirRead, 1, u32WriteSiz, pfPVR))
1628                 {
1629                     dmx_dbg_print("[%s] ERROR : write %d bytes to file failed\n", __FUNCTION__, (int)u32WriteSiz);
1630                     fclose(pfPVR);
1631                     pfPVR = NULL;
1632                 }
1633                 u32SizeRec += u32WriteSiz;
1634 
1635                 u32WriteSiz = u32VirWrite - u32VirStart;
1636                 if(u32WriteSiz != fwrite((char*)u32VirStart, 1, u32WriteSiz, pfPVR))
1637                 {
1638                     dmx_dbg_print("[%s] ERROR : write %d bytes to file failed\n", __FUNCTION__, (int)u32WriteSiz);
1639                     fclose(pfPVR);
1640                     pfPVR = NULL;
1641                 }
1642                 u32SizeRec += u32WriteSiz;
1643             }
1644 
1645             u32VirRead = u32VirWrite;
1646 
1647         }
1648         else
1649         {
1650             dmx_dbg_print("pfPVR = NULL\n");
1651             return;
1652         }
1653     }while(1);
1654 }
1655 //-------------------------------------------------------------------------------------------------
1656 // Record BitStream from DMX driver
1657 // param path                \b IN: file path to write record data
1658 // param source              \b IN: source of the record
1659 // param bRecordAll          \b IN: true to record all
1660 // return DMX_FILTER_STATUS_OK - Success
1661 // return DMX_FILTER_STATUS_ERROR - Failure
1662 //-------------------------------------------------------------------------------------------------
_DMX_DBG_Record_Start(const char path[],MS_U32 * u32Pid,MS_U32 u32NumPids,MS_PHYADDR pBuf,MS_U32 u32Size,MS_BOOL bCA,MS_BOOL bRecordAll)1663 MS_BOOL _DMX_DBG_Record_Start(const char path[],
1664                                             MS_U32* u32Pid,
1665                                             MS_U32 u32NumPids,
1666                                             MS_PHYADDR pBuf,
1667                                             MS_U32 u32Size,
1668                                             MS_BOOL bCA,
1669                                             MS_BOOL bRecordAll)
1670 {
1671     DMX_FLOW_INPUT dmxInput = DMX_FLOW_PLAYBACK;
1672     MS_BOOL bClkInv = FALSE;
1673     MS_BOOL bExtSync = FALSE;
1674     MS_BOOL bParallel = FALSE;
1675     DMX_Pvr_info pvrInfo;
1676     bPvrCA = bCA;
1677     int idx = 0;
1678     if((pBuf == NULL) || (u32Size == 0) || (pBuf & 0xf) || (u32Size & 0xf))
1679     {
1680         dmx_dbg_print("%s, buffer[0x%x], size[0x%x] illegal !!!\n", __FUNCTION__, (unsigned int)pBuf, (unsigned int)u32Size);
1681         return FALSE;
1682     }
1683 
1684     if((!bRecordAll) && (u32NumPids == 0))
1685     {
1686         dmx_dbg_print("%s, nothing to record !!!\n", __FUNCTION__);
1687         return FALSE;
1688     }
1689 
1690 
1691     s32DmxDbgPvrTaskId = MsOS_CreateTask((TaskEntry)_DMX_DBG_Pvr_Task,
1692                                       (MS_U32)NULL,
1693                                       E_TASK_PRI_MEDIUM,
1694                                       TRUE,
1695                                       _u8PvrStack,
1696                                       DMX_DBG_STACK_SIZE,
1697                                       DMX_DBG_PVR_TASK_NAME);
1698 
1699     if(s32DmxDbgPvrTaskId == -1)
1700     {
1701         dmx_dbg_print("[%s] Create Task failed\n", __FUNCTION__);
1702         return FALSE;
1703     }
1704 
1705     pfPVR = fopen(path, "wb");
1706     if(pfPVR == NULL)
1707     {
1708         dmx_dbg_print("[%s] ERROR, Open file %s failed\n", __FUNCTION__, path);
1709         return FALSE;
1710     }
1711 
1712     MApi_DMX_Get_FlowInput_Status(DMX_FLOW_PLAYBACK, &dmxInput, &bClkInv, &bExtSync, &bParallel);
1713 
1714     if(bCA)
1715         MApi_DMX_FlowSet(DMX_FLOW_PVRCA, dmxInput, bClkInv, bExtSync, bParallel);
1716     else
1717         MApi_DMX_FlowSet(DMX_FLOW_PVR, dmxInput, bClkInv, bExtSync, bParallel);
1718 
1719     #define PVR_ALIGNMENT (188 * 16)
1720     u32Size = ( u32Size / PVR_ALIGNMENT ) * PVR_ALIGNMENT;
1721 
1722     pvrInfo.pPvrBuf0        = pBuf;
1723     pvrInfo.PvrBufSize0     = u32Size / 2;
1724     pvrInfo.pPvrBuf1        = pBuf + (u32Size / 2);
1725     pvrInfo.PvrBufSize1     = u32Size / 2;
1726 
1727     MApi_DMX_Pvr_Eng_Open(DMX_PVR_EGN0, &pvrInfo);
1728 
1729     u32VirRead  = (MS_U32)MS_PA2KSEG1((MS_U32)pBuf);
1730     u32VirStart = (MS_U32)MS_PA2KSEG1((MS_U32)pBuf);
1731     u32VirEnd   = (u32VirStart + u32Size); // the last address of MIU block can't be converted to virtual address
1732 
1733     /*
1734     ULOGD("DMX", "pPvrBuf0    = 0x%08x(0x%08x)\n", (unsigned int)pvrInfo.pPvrBuf0, (unsigned int)MS_PA2KSEG1((MS_U32)pvrInfo.pPvrBuf0));
1735     ULOGD("DMX", "PvrBufSize0 = 0x%08x\n", (unsigned int)pvrInfo.PvrBufSize0);
1736     ULOGD("DMX", "pPvrBuf1    = 0x%08x\n", (unsigned int)pvrInfo.pPvrBuf1);
1737     ULOGD("DMX", "PvrBufSize1 = 0x%08x\n", (unsigned int)pvrInfo.PvrBufSize1);
1738     ULOGD("DMX", "Read  = 0x%x\n", (unsigned int)u32VirRead);
1739     ULOGD("DMX", "Start = 0x%x\n", (unsigned int)u32VirStart);
1740     ULOGD("DMX", "End   = 0x%x\n", (unsigned int)u32VirEnd);
1741     */
1742 
1743     if(bRecordAll)
1744     {
1745         MApi_DMX_Pvr_Eng_Start(DMX_PVR_EGN0, TRUE);
1746     }
1747     else
1748     {
1749         for(idx = 0; idx < u32NumPids; idx++)
1750         {
1751             if(bCA)
1752             {
1753 #if defined(TSP_VERSION) && (TSP_VERSION == TSP_VER_3_0)
1754                 if(DMX_FILTER_STATUS_OK == MApi_DMX_PvrCA_Eng_Pid_Open(DMX_PVR_EGN0, u32Pid[idx], &u8PvrIdx[idx], FALSE))
1755                 {
1756                     ULOGD("DMX", "[%s], open PVR CA filter %d for pid 0x%x\n", __FUNCTION__, (int)u8PvrIdx[idx], (unsigned int)u32Pid[idx]);
1757                 }
1758                 else
1759                 {
1760                     dmx_dbg_print("[%s], open PVR filter failed\n", __FUNCTION__);
1761                 }
1762 #endif
1763             }
1764             else
1765             {
1766                 if(DMX_FILTER_STATUS_OK == MApi_DMX_Pvr_Eng_Pid_Open(DMX_PVR_EGN0, u32Pid[idx], &u8PvrIdx[idx]))
1767                 {
1768                     ULOGD("DMX", "[%s], open PVR filter %d for pid 0x%x\n", __FUNCTION__, (int)u8PvrIdx[idx], (unsigned int)u32Pid[idx]);
1769                 }
1770                 else
1771                 {
1772                     dmx_dbg_print("[%s], open PVR filter failed\n", __FUNCTION__);
1773                 }
1774             }
1775         }
1776 
1777         MApi_DMX_Pvr_Eng_Start(DMX_PVR_EGN0, FALSE);
1778     }
1779     return TRUE;
1780 }
1781 
_DMX_DBG_Record_Stop(void)1782 MS_BOOL _DMX_DBG_Record_Stop(void)
1783 {
1784     if(bPvrCA)
1785         MApi_DMX_PvrCA_Eng_Stop(DMX_PVR_EGN0);
1786 
1787     if(pfPVR != NULL)
1788     {
1789         MS_U32 u32Time = MsOS_GetSystemTime();
1790 
1791         dmx_dbg_print("\tRecord %d bytes\n", (int)u32SizeRec);
1792         dmx_dbg_print("\tRecord %d s\n", (int)((u32Time - u32TimeStartPvr)/1000));
1793 
1794         if(((u32Time - u32TimeStartPvr)/1000) != 0)
1795         {
1796             dmx_dbg_print("\tBitRate[%08d bps]\n", (int)((u32SizeRec << 3) / ((u32Time - u32TimeStartPvr)/1000)));
1797         }
1798 
1799        fclose(pfPVR);
1800        pfPVR = NULL;
1801     }
1802 
1803     if(s32DmxDbgPvrTaskId > 0)
1804     {
1805         MsOS_DeleteTask(s32DmxDbgPvrTaskId);
1806         s32DmxDbgPvrTaskId = -1;
1807     }
1808     u32TimeStartPvr = 0;
1809     bMonitorAV = FALSE;
1810     return TRUE;
1811 }
1812 
_DMX_Debug(char path[])1813 void _DMX_Debug(char path[])
1814 {
1815     char filename[128];
1816     char* pch = path;
1817 
1818     if(pch == NULL)
1819     {
1820         pch = getenv(DMX_DBG_FILE_PATH_ENV);
1821         dmx_dbg_print("DMX debug file path = %s\n", pch);
1822         if(pch == NULL)
1823             return;
1824     }
1825 
1826     sprintf(filename, "%s/%s", pch, DMX_DBG_FILE_NAME);
1827     dmx_dbg_print("path = %s\n", filename);
1828     pfDmxDbg = fopen(filename, "w+");
1829     //pfDmxDbg = fopen(filename, "a+"); // append
1830     if(pfDmxDbg == NULL)
1831     {
1832         dmx_dbg_print("[%s] ERROR, Open file %s failed\n", __FUNCTION__, filename);
1833     }
1834 
1835     s32DmxDbgTaskId = MsOS_CreateTask((TaskEntry)_DMX_DBG_Task,
1836                                       (MS_U32)NULL,
1837                                       E_TASK_PRI_MEDIUM,
1838                                       TRUE,
1839                                       _u8DbgStack,
1840                                       DMX_DBG_STACK_SIZE,
1841                                       DMX_DBG_TASK_NAME);
1842 
1843     if(s32DmxDbgTaskId == -1)
1844     {
1845         dmx_dbg_print("[%s] Create Task failed\n", __FUNCTION__);
1846         return;
1847     }
1848 
1849     // disable WDT
1850 //    dmx_dbg_print("[%s] stop watch dog\n", __FUNCTION__);
1851 //    MDrv_WDT_Stop(0);
1852 
1853     s32DmxDbgMutex = MsOS_CreateMutex(E_MSOS_FIFO, "DMX DEBUG", MSOS_PROCESS_SHARED);
1854 
1855     memset(stDmxDbgInfo, 0x0, sizeof(DMX_FLT_DBG_INFO) * TSP_SECFLT_NUM);
1856 }
1857 
1858 #endif // DMX_DEBUG
1859