source: svn/newcon3bcm2_21bu/dst/dlib/src/si/DLIB_SDDS_Monitor.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 12.0 KB
Line 
1/**
2        @file
3                DLIB_SDDS_Monitor.c
4
5        @brief
6*/
7
8
9#include "DHL_DBG.h"
10#include "DHL_PSI.h"
11
12#include "DLIB_SDDS.h"
13#include "DLIB_SDDS_Monitor.h"
14
15
16DHL_MODULE("sdm", 0);
17
18
19
20
21#if COMMENT
22____Config____(){}
23#endif
24
25
26
27
28#if COMMENT
29____Types____(){}
30#endif
31
32//#define psi_section_length(ptr) ((((ptr[1])<<8)+(ptr[2]))&0x0FFF)
33
34
35#if COMMENT
36____Variables____(){}
37#endif
38
39
40#if COMMENT
41____Misc____(){}
42#endif
43
44#if 0
45char *psi_event_string(tDHL_PSI_Event event)
46{
47        switch(event) {
48                case ePSIEVENT_NOEVENT:                 return("psiNoEvent");
49                case ePSIEVENT_DUP3PACKET:                      return("psiDup3Packet");
50                case ePSIEVENT_LOSTPACKET:                      return("psiLostPacket");
51                case ePSIEVENT_DISCONTINUITY:           return("psiDiscontinuity");
52                case ePSIEVENT_SPLICINGPOINT:           return("psiSplicingPoint");
53                case ePSIEVENT_SYNCERR:                 return("psiSyncErr");
54                case ePSIEVENT_SCRAMBLEDERROR:          return("psiScrambledErr");
55                // case ePSIEVENT_SECTIONRECEIVED:      return("psiSectionReceived"); not used
56                case ePSIEVENT_DATARECEIVED:            return("psiDataReceived");
57                case ePSIEVENT_MEMORYERROR:             return("psiMemoryError");
58                case ePSIEVENT_SECTIONTOOBIG:           return("psiSectionTooBig");
59                case ePSIEVENT_CRCERROR:                        return("psiCRCError");
60                case ePSIEVENT_CRCUNCHANGED:            return("psiCRCUnchanged");
61                case ePSIEVENT_VERSIONCHANGED:          return("psiVersionChanged");
62                case ePSIEVENT_MAXSECTIONOVERFLOW:      return("psiMaxSectionOverflow");
63                case ePSIEVENT_LASTSECTIONOVERFLOW:return("psiLastSectionOverflow");
64                case ePSIEVENT_KILLUSRTASK:                     return("killUserTask");
65        case ePSIEVENT_FIFOFULLEVENT:      return("psiFifoFullEvent");
66
67
68                default:                                        return("unknown DHL_PSIEvent");
69
70        }
71        /*!PRM unreachable TLASSERT(0,"PSIEventString: bad DHL_PSIEvent");
72        return("???");*/
73       
74}
75#endif
76
77
78#if COMMENT
79____Monitor____(){}
80#endif
81
82
83void DLIB_SDDS_StopMonitor(tDHL_PSI_ControlHandle psiCtl)
84{
85        DHL_PSI_StopMonitor(psiCtl);
86}
87
88
89/** DSI ¸Þ½ÃÁö ¸ð´ÏÅ͸¦ ½ÃÀÛÇÑ´Ù.
90
91        dsmcc ¼½¼Ç ±¸Á¶»ó, oneshot ¸ðµå¿Í continuous ¸ðµå¸¸ »ç¿ëÀÌ °¡´ÉÇÏ´Ù.
92
93        tableIdExtension ÀÌ (UINT32)-1 À̸é ÇÊÅÍ¿¡ »ç¿ëÇÏÁö ¾Ê´Â´Ù´Â ÀǹÌÀÌ´Ù.
94        tableIdExtension Àº version change update mode¸¦ emulation Çϱâ À§ÇØ »ç¿ëµÈ´Ù.
95*/
96DHL_RESULT DLIB_SDDS_MonitorDsi (
97                        tDHL_TSD tsd, 
98                        UINT16 pid,
99                        UINT32 tableIdExtension,
100                        tDHL_PSI_Update updateMode, 
101                        tDHL_PSI_EventProc eventProc, UINT32 userParam, 
102                        tDHL_PSI_ControlHandle *ppsiCtl)
103{
104        tDHL_PSI_Filter *pref;
105        DHL_RESULT              err;
106
107        /* sanity check */
108        if (updateMode != ePSIUPDATE_ONESHOT &&
109                updateMode != ePSIUPDATE_CONTINEOUS) {
110                DHL_OS_Printf("!! %s: updateMode %d invalid\n", __FUNCTION__, updateMode);
111                return DHL_FAIL_INVALID_PARAM;
112        }
113        /* Set up the Table ID filter */
114        if ((err = DHL_PSI_AllocFilterWithTid(&pref,SDDS_Table_ID_Msg,TRUE))) {
115                DHL_OS_Printf("!! %s: get filter err\n", __FUNCTION__);
116                return(err);
117        }
118
119        // Ç÷§Æû¿¡ µû¶ó transaction id ±îÁö hardware filter°¡ µ¿ÀÛÇÏÁö ¾ÊÀ» ¼ö ÀÖÀ¸¹Ç·Î
120        // table_id_extensionÀ» ÀÌ¿ëÇϵµ·Ï ÇÑ´Ù.
121#if 1//BRCM
122        if (tableIdExtension != (UINT32)-1) {
123                pref->mask[3] = pref->mask[4] = 0;
124                pref->coef[3] = (tableIdExtension >> 8) & 0xff;
125                pref->coef[4] = (tableIdExtension & 0xff);
126        }
127
128        // ---- [10:11]Àº messageId.
129        pref->mask[10] = pref->mask[11] = 0;
130        pref->coef[10] = (SDDS_Message_ID_DSI >> 8);
131        pref->coef[11] = (SDDS_Message_ID_DSI & 0xff);
132#else
133        if (tableIdExtension != (UINT32)-1) {
134                pref->mask[3] = pref->mask[4] = 0xff;
135                pref->mode[3] = pref->mode[4] = 0xff; // ÀÏÄ¡ ¸ðµå
136                pref->data[3] = (tableIdExtension >> 8) & 0xff;
137                pref->data[4] = (tableIdExtension & 0xff);
138        }
139
140        // ---- [10:11]Àº messageId.
141        pref->mask[10] = pref->mask[11] = 0xff;
142        pref->mode[10] = pref->mode[11] = 0xff; // ÀÏÄ¡ ¸ðµå
143        pref->data[10] = (SDDS_Message_ID_DSI >> 8);
144        pref->data[11] = (SDDS_Message_ID_DSI & 0xff);
145#endif
146        /* Set up PID Filter */
147        if ((err = DHL_PSI_StartMonitor(tsd, pid, ePSIMODE_SECTION, // section only
148                                                updateMode, pref, 4096, 1,
149                                                eventProc, userParam, ppsiCtl))) {
150                DHL_OS_Printf("!! %s: DHL_PSI_StartMonitor err %d\n", __FUNCTION__, err);
151                DHL_PSI_FreeFilter(pref);
152        }
153
154        return(err);
155}
156
157
158DHL_RESULT DLIB_SDDS_MonitorDii (
159                        tDHL_TSD tsd, 
160                        UINT16 pid,
161                        UINT32 transactionId,
162                        tDHL_PSI_Update updateMode, 
163                        tDHL_PSI_EventProc eventProc, UINT32 userParam, 
164                        tDHL_PSI_ControlHandle *ppsiCtl)
165{
166        tDHL_PSI_Filter *pref;
167        DHL_RESULT              err;
168       
169        /* Set up the Table ID filter */
170        if ((err = DHL_PSI_AllocFilterWithTid(&pref,SDDS_Table_ID_Msg,TRUE))) {
171                DHL_OS_Printf("!! %s: get filter err\n", __FUNCTION__);
172                return(err);
173        }
174#if 1//BRCM
175        // ---- [3:4]´Â table_id_extension À̰í, transactionIdÀÇ ÇÏÀ§ µÎ¹ÙÀÌÆ®.
176        pref->mask[3] = pref->mask[4] = 0;
177        pref->coef[3] = (transactionId >> 8) & 0xff;
178        pref->coef[4] = (transactionId & 0xff);
179
180        // ---- [10:11]Àº messageId.
181        pref->mask[10] = pref->mask[11] = 0;
182        pref->coef[10] = (SDDS_Message_ID_DII >> 8);
183        pref->coef[11] = (SDDS_Message_ID_DII & 0xff);
184
185#else
186        // ---- [3:4]´Â table_id_extension À̰í, transactionIdÀÇ ÇÏÀ§ µÎ¹ÙÀÌÆ®.
187        pref->mask[3] = pref->mask[4] = 0xff;
188        pref->mode[3] = pref->mode[4] = 0xff; // ÀÏÄ¡ ¸ðµå
189        pref->data[3] = (transactionId >> 8) & 0xff;
190        pref->data[4] = (transactionId & 0xff);
191
192        // ---- [10:11]Àº messageId.
193        pref->mask[10] = pref->mask[11] = 0xff;
194        pref->mode[10] = pref->mode[11] = 0xff; // ÀÏÄ¡ ¸ðµå
195        pref->data[10] = (SDDS_Message_ID_DII >> 8);
196        pref->data[11] = (SDDS_Message_ID_DII & 0xff);
197#endif
198        /* Set up PID Filter */
199        if ((err = DHL_PSI_StartMonitor(tsd, pid, ePSIMODE_SECTION, // section only
200                                                updateMode, pref, 4096, 1, // 1 section max 4K
201                                                eventProc, userParam, ppsiCtl))) {
202                DHL_OS_Printf("!! %s: DHL_PSI_StartMonitor err %d\n", __FUNCTION__, err);
203                DHL_PSI_FreeFilter(pref);
204        }
205
206        return(err);
207}
208
209
210DHL_RESULT DLIB_SDDS_MonitorDdb (
211                        tDHL_TSD tsd, 
212                        UINT16 pid,
213                        UINT32 moduleId,
214                        E_DDB_RX_INTERLEAVED_MODE interleavingMode,
215                        tDHL_PSI_Update updateMode, 
216                        tDHL_PSI_EventProc eventProc, UINT32 userParam, 
217                        tDHL_PSI_ControlHandle *ppsiCtl)
218{
219        tDHL_PSI_Filter *pref;
220        DHL_RESULT              err;
221        //tDHL_PSI_Update updateMode = ePSIUPDATE_CONTINEOUS;
222       
223        /* Set up the Table ID filter */
224        if ((err = DHL_PSI_AllocFilterWithTid(&pref,SDDS_Table_ID_Data,TRUE))) {
225                DHL_OS_Printf("!! %s: get filter err\n", __FUNCTION__);
226                return(err);
227        }
228#if 1//BRCM
229        if (moduleId != (UINT32)-1) {
230                // ---- [3:4]´Â table_id_extension À̰í, transactionIdÀÇ ÇÏÀ§ µÎ¹ÙÀÌÆ®.
231                pref->mask[3] = pref->mask[4] = 0;
232                pref->coef[3] = (moduleId >> 8) & 0xff;
233                pref->coef[4] = (moduleId & 0xff);
234        }
235
236        if (interleavingMode == eDDB_RIM_Even || interleavingMode == eDDB_RIM_Odd) {
237                pref->mask[6] = ~0x01; // use LSB bit only..
238                pref->coef[6] = interleavingMode == eDDB_RIM_Even ? 0 : 1;
239        }
240#else
241        if (moduleId != (UINT32)-1) {
242                // ---- [3:4]´Â table_id_extension À̰í, transactionIdÀÇ ÇÏÀ§ µÎ¹ÙÀÌÆ®.
243                pref->mask[3] = pref->mask[4] = 0xff;
244                pref->mode[3] = pref->mode[4] = 0xff; // ÀÏÄ¡ ¸ðµå
245                pref->data[3] = (moduleId >> 8) & 0xff;
246                pref->data[4] = (moduleId & 0xff);
247        }
248
249        if (interleavingMode == eDDB_RIM_Even || interleavingMode == eDDB_RIM_Odd) {
250                pref->mask[6] = 0x01; // use LSB bit only..
251                pref->data[6] = interleavingMode == eDDB_RIM_Even ? 0 : 1;
252                pref->mode[6] = 0x01; // ÀÏÄ¡ ¸ðµå
253        }
254#endif
255#if 0 // todo
256        else if (interleavingMode == eDDB_RIM_Quarter0) {
257
258        }
259#endif
260#if 1//BRCM
261        // ---- [10:11]Àº messageId.
262        pref->mask[10] = pref->mask[11] = 0;
263        pref->coef[10] = (SDDS_Message_ID_DDB >> 8);
264        pref->coef[11] = (SDDS_Message_ID_DDB & 0xff);
265#else
266        // ---- [10:11]Àº messageId.
267        pref->mask[10] = pref->mask[11] = 0xff;
268        pref->mode[10] = pref->mode[11] = 0xff; // ÀÏÄ¡ ¸ðµå
269        pref->data[10] = (SDDS_Message_ID_DDB >> 8);
270        pref->data[11] = (SDDS_Message_ID_DDB & 0xff);
271#endif
272        /* Set up PID Filter */
273        if ((err = DHL_PSI_StartMonitor(tsd, pid, ePSIMODE_SECTION, // section only
274                                                updateMode, pref, 4096, 1, // 1 section max 4K
275                                                eventProc, userParam, ppsiCtl))) {
276                DHL_OS_Printf("!! %s: DHL_PSI_StartMonitor err %d\n", __FUNCTION__, err);
277                DHL_PSI_FreeFilter(pref);
278        }
279
280        return(err);
281}
282
283
284
285
286
287#if COMMENT
288____Debug____(){}
289#endif
290
291#define USE_TEST_CODE 1
292
293#if USE_TEST_CODE
294
295#include "DLIB_SDDS_Parser.h"
296
297#define get_section_length(p)                   (((p[1] & 0x0F) << 8) | p[2])
298
299void test_callback(tDHL_PSI_Event event, tDHL_PSI_ControlHandle psiCtl, UINT32 userParam)
300{
301        DHL_RESULT dhr;
302        tDHL_PSI_DataArray *desc;
303        int len;
304       
305        if (event != ePSIEVENT_DATARECEIVED) {
306                dprint(0, "!! psicallback err %d\n", event);
307                return;
308        }
309
310        if (userParam == SDDS_Message_ID_DSI || userParam == SDDS_Message_ID_DII ||
311                userParam == SDDS_Message_ID_DDB || userParam == SDDS_Message_ID_DC) 
312        {
313                dprint(2, "sdds psi rx, cmd 0x%x, psictl %x\n", userParam, psiCtl);
314               
315                // race condition À¸·ÎºÎÅÍÀÇ º¸È£°¡ ¾ÆÁ÷ ¿Ïº®ÇÏÁö ¾ÊÀ¸¹Ç·Î,
316                // desc detach ÀÛ¾÷À» ÀÌ callback task¿¡¼­ ¼öÇàÇϵµ·Ï ÇÏÀÚ.
317                //
318                dhr = DHL_PSI_ReadPSIData(psiCtl, &desc);
319                if (dhr) {
320                        dprint(0, "!! %s: DHL_PSI_ReadPSIData err %x\n", __FUNCTION__, dhr);
321                        return;
322                }
323
324                if (userParam == SDDS_Message_ID_DSI) {
325                        sddsDsiPtr_t dsi;
326                        dhr = DLIB_SDDS_ParseDsiSection(desc->sectPtr[0], &dsi);
327                        if (dhr)
328                                dprint(0, "!! dsi parse err %x\n", dhr);
329                        else
330                                DLIB_SDDS_PrintDsiSection(dsi, 0);
331                        DLIB_SDDS_FreeSection(dsi);
332                }
333                else if (userParam == SDDS_Message_ID_DII) {
334                        sddsDiiPtr_t dii;
335                        dhr = DLIB_SDDS_ParseDiiSection(desc->sectPtr[0], &dii);
336                        if (dhr)
337                                dprint(0, "!! dii parse err %x\n", dhr);
338                        else
339                                DLIB_SDDS_PrintDiiSection(dii, 0);
340                        DLIB_SDDS_FreeSection(dii);
341                }
342                else if (userParam == SDDS_Message_ID_DDB) {
343                        sddsDdbPtr_t ddb;
344                        dhr = DLIB_SDDS_ParseDdbSection(desc->sectPtr[0], &ddb);
345                        if (dhr)
346                                dprint(0, "!! ddb parse err %x\n", dhr);
347                        else
348                                DLIB_SDDS_PrintDdbSection(ddb, 0);
349                        DLIB_SDDS_FreeSection(ddb);
350                }
351                else
352                        dhr = DHL_FAIL;
353
354                if (dhr) {
355                        len = get_section_length(desc->sectPtr[0]) + 3;
356                        memdump(desc->sectPtr[0], len, "");
357                }
358               
359                DHL_PSI_FreePSIData(desc);
360        }
361}
362
363tDHL_PSI_ControlHandle g_dsi, g_dii, g_ddb0, g_ddb1;
364
365void test_dsi(int pid, int mode)
366{
367        DHL_RESULT dhr;
368        if (g_dsi == (tDHL_PSI_ControlHandle)0) {
369                dprint(0, "----------- start dsi monitor..\n");
370                dhr = DLIB_SDDS_MonitorDsi(DHL_DMX_GetTsd(), pid, (UINT32)-1, (tDHL_PSI_Update)mode, //ePSIUPDATE_ONESHOT,
371                        test_callback, SDDS_Message_ID_DSI, &g_dsi);
372                if (dhr)
373                        dprint(0, "!!!! monitor fail %x\n", dhr);
374        }
375        else {
376                dprint(0, "************ stop dsi monitor..\n");
377                DLIB_SDDS_StopMonitor(g_dsi);
378                g_dsi = (tDHL_PSI_ControlHandle)0;
379        }
380}
381
382void test_dii(int pid, UINT32 trid, int mode)
383{
384        DHL_RESULT dhr;
385        if (g_dii == (tDHL_PSI_ControlHandle)0) {
386                dprint(0, "----------- start dii monitor..\n");
387                dhr = DLIB_SDDS_MonitorDii(DHL_DMX_GetTsd(), pid, trid, (tDHL_PSI_Update)mode, //ePSIUPDATE_ONESHOT,
388                        test_callback, SDDS_Message_ID_DII, &g_dii);
389                if (dhr)
390                        dprint(0, "!!!! monitor fail %x\n", dhr);
391        }
392        else {
393                dprint(0, "************ stop dii monitor..\n");
394                DLIB_SDDS_StopMonitor(g_dii);
395                g_dii = (tDHL_PSI_ControlHandle)0;
396        }
397}
398
399void test_ddb(int pid, UINT32 modid, int mode)
400{
401        DHL_RESULT dhr;
402        if (g_ddb0 == (tDHL_PSI_ControlHandle)0 && g_ddb1 == (tDHL_PSI_ControlHandle)0) {
403                dprint(0, "----------- start ddb monitor..\n");
404                dhr = DLIB_SDDS_MonitorDdb(DHL_DMX_GetTsd(), pid, modid, eDDB_RIM_Even,
405                        (tDHL_PSI_Update)mode, //ePSIUPDATE_ONESHOT,
406                        test_callback, SDDS_Message_ID_DDB, &g_ddb0);
407                if (dhr)
408                        dprint(0, "!!!! ddb0 monitor fail %x\n", dhr);
409                dhr = DLIB_SDDS_MonitorDdb(DHL_DMX_GetTsd(), pid, modid, eDDB_RIM_Odd,
410                        (tDHL_PSI_Update)mode, //ePSIUPDATE_ONESHOT,
411                        test_callback, SDDS_Message_ID_DDB, &g_ddb1);
412                if (dhr)
413                        dprint(0, "!!!! ddb1 monitor fail %x\n", dhr);
414        }
415        else {
416                dprint(0, "************ stop ddb monitor..\n");
417                DLIB_SDDS_StopMonitor(g_ddb0);
418                DLIB_SDDS_StopMonitor(g_ddb1);
419                g_ddb0 = g_ddb1 = (tDHL_PSI_ControlHandle)0;
420        }
421}
422
423#endif // USE_TEST_CODE
424
425
426#if COMMENT
427____Symbol____(){}
428#endif
429
430
431
432
433#if COMMENT
434____Init____(){}
435#endif
436
437
438
439/* end of file */
440
Note: See TracBrowser for help on using the repository browser.