source: svn/trunk/newcon3bcm2_21bu/dta/tests/unit_test/test_a56.c

Last change on this file was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 13.0 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2012, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: $
11 * $brcm_Revision: $
12 * $brcm_Date: $
13 *
14 * Module Description: test A56 message filtering
15 *
16 * Revision History:
17 *
18 * $brcm_Log: $
19 *
20 *
21 ***************************************************************************/
22#include "bstd.h"
23#include "bkni.h"
24#include "bdbg.h"
25
26#include "serial.h"
27#include "input_parser.h"
28#include "bcrc32.h"
29
30#include "bsettop.h"
31#include "bsettop_smessage.h"
32#include "test_tuner.h"
33#include "si.h"
34#include "si_nim.h"
35#include "si_ntm.h"
36#include "si_vcm.h"
37#include "test_a56.h"
38
39BDBG_MODULE(test_a56);
40
41#define MAX_MSG_BUFFERS 0x400
42#define MSG_BUFFER_SIZE 0x1000
43
44static bool initialized = false;
45
46unsigned char a56_msg_buffer[MSG_BUFFER_SIZE];
47
48//static smessage_stream_t   stt_msg = NULL;
49//static smessage_stream_t   rrt_msg = NULL;
50static smessage_stream_t   nim_msg = NULL;
51static smessage_stream_t   ntm_msg = NULL;
52static smessage_stream_t   vcm_msg = NULL;
53static smessage_stream_params_t params;
54
55static SI_NIM_CDT_Callback_t nim_cdt_cb = { NULL, NULL };
56static SI_NIM_MMT_Callback_t nim_mmt_cb = { NULL, NULL };
57static SI_NTM_SNT_Callback_t ntm_snt_cb = { NULL, NULL };
58static SI_VCM_VCT_Callback_t vcm_vct_cb = { NULL, NULL };
59
60/* function prototype */
61void a56_nim_cdt_cb(NIM_CDT_INFO *pCDT, void *data);
62void a56_nim_mmt_cb(NIM_MMT_RECORD *pMMT, void *data);
63void a56_vcm_vct_cb(SI_VCM_VCT_CHANNEL *pChannel, void *data);
64void a56_stop(void);
65
66/* default QAM tuner */
67static int tuner_band = TUNER_BAND;
68
69/*
70 * Summary:
71 *      choose chich tuner to use (QAM tuner or OOB tuner)
72 */
73bool a56_test_choose_tuner(int tuner)
74{
75#ifdef OOB_TUNER_SUPPORT
76        tuner_band = tuner ? OOB_TUNER_BAND : TUNER_BAND;
77#else
78        tuner_band = TUNER_BAND;
79#endif
80}
81
82void *a56_msg_callback(void *context, size_t data_size)
83{
84        uint8_t *msg;
85        SI_RET_CODE rc;
86
87        msg = (uint8_t*)a56_msg_buffer;
88        BDBG_WRN(("table ID=0x%hx, size %u", msg[0], data_size));
89
90        switch (*msg) {
91                case SI_NIM_TABLE_ID:
92                        rc = SI_NIM_parse(msg);
93                        if (SI_SUCCESS != rc)
94                        {
95                                BDBG_WRN(("NIM parse error (rc=0x%x)\n",rc));
96                        }
97                        else {
98                                BDBG_WRN(("SI_NIM_CDT_Complete=%d\n",SI_NIM_CDT_Complete()));
99                                BDBG_WRN(("SI_NIM_MMT_Complete=%d\n",SI_NIM_MMT_Complete()));
100                                /* initialize it so that it can be redisplay again */
101                                SI_NIM_Init((SI_NIM_CDT_Callback_t *)&nim_cdt_cb, (SI_NIM_MMT_Callback_t *)&nim_mmt_cb, 0xFF, 0xFF);
102                        }
103                        break;
104
105                case SI_NTM_TABLE_ID:
106                        rc = SI_NTM_parse(msg);
107                        if (SI_SUCCESS != rc)
108                        {
109                                BDBG_WRN(("NTM parse error (rc=0x%x)\n",rc));
110                        }
111                        else {
112                                BDBG_WRN(("SI_NTM_SNT_Complete=%d\n",SI_NTM_SNT_Complete()));
113                                /* initialize it so that it can be redisplay again */
114                                SI_NTM_Init((SI_NTM_SNT_Callback_t *)&ntm_snt_cb, 0xFF);
115                        }
116                        break;
117
118                case SI_VCM_TABLE_ID:
119                        rc = SI_VCM_parse(msg);
120                        if (SI_SUCCESS != rc)
121                        {
122                                BDBG_WRN(("VCM parse error (rc=0x%x)\n",rc));
123                        }
124                        else
125                        {
126                                BDBG_WRN(("SI_VCM_Complete=%d\n", SI_VCM_Complete()));
127                                SI_VCM_Init((SI_VCM_VCT_Callback_t *)&vcm_vct_cb, 0xFF);
128                        }
129                        break;
130        }
131        return msg;
132}
133
134char *transmission_system_str[16] = 
135{
136        "unknown",
137        "ITU-T annex A",
138        "ITU-T annex B",
139        "ITU-R",
140        "ATSC",
141        "DigiCipher",
142        "ITU-T annex C",
143        "ITU-T annex D",
144        "reserved",
145        "reserved",
146        "reserved",
147        "reserved",
148        "reserved",
149        "reserved",
150        "reserved",
151        "reserved",
152};
153
154char *inner_coding_mode_str[16] = 
155{
156        "rate 5/11 coding",
157        "rate 1/2 coding",
158        "reserved",
159        "rate 3/5 coding",
160        "reserved",
161        "rate 2/3 coding",
162        "reserved",
163        "rate 3/4 coding",
164        "rate 4/5 coding",
165        "rate 5/6 coding",
166        "reserved",
167        "rate 7/8 coding",
168        "reserved",
169        "reserved",
170        "reserved",
171        "none"
172};
173
174char *modulation_format_str[32] = 
175{
176        "unknown",
177        "QPSK",
178        "BPSK",
179        "OQPSK",
180        "VSB 8",
181        "VSB 16",
182        "QAM 16",
183        "QAM 32",
184        "QAM 64",
185        "QAM 80",
186        "QAM 96",
187        "QAM 112",
188        "QAM 128",
189        "QAM 160",
190        "QAM 192",
191        "QAM 224",
192        "QAM 256",
193        "QAM 320",
194        "QAM 384",
195        "QAM 448",
196        "QAM 512",
197        "QAM 640",
198        "QAM 768",
199        "QAM 896",
200        "QAM 1024",
201        "reserved",
202        "reserved",
203        "reserved",
204        "reserved",
205        "reserved",
206        "reserved",
207        "reserved"
208};
209
210/*
211 * Summary:
212 *      A56 Parser NIM MMT Callback.
213 */
214void a56_nim_mmt_cb(NIM_MMT_RECORD *pMMT, void *data)
215{
216        BKNI_Printf("%24s = %d\n", "index", pMMT->idx);
217        BKNI_Printf("%24s = %s\n", "modulation format", modulation_format_str[pMMT->modulation_format % 32]);
218        BKNI_Printf("%24s = %s\n", "transmission system", transmission_system_str[pMMT->transmission_system % 16]);
219        BKNI_Printf("%24s = %s\n", "inner coding mode", inner_coding_mode_str[pMMT->inner_coding_mode % 16]);
220        BKNI_Printf("%24s = %d\n", "symbol rate", pMMT->symbol_rate);
221}
222
223/*
224 * Summary:
225 *      A65 Parser NIM CDT Callback.
226 */
227void a56_nim_cdt_cb(NIM_CDT_INFO *pCDT, void *data)
228{
229        BKNI_Printf("idx                = %d\n", pCDT->idx);
230        BKNI_Printf("freq_khz   = %d\n", pCDT->freq_khz);
231}
232
233/*
234 * Summary:
235 *    Stop NIM filtering
236 */
237void a56_nim_stop()
238{
239        if (NULL != nim_msg)
240        {
241                if (b_ok != smessage_stop(nim_msg))
242                {
243                        BDBG_ERR(("%s:%d",__FILE__, __LINE__));
244                        return;
245                }
246                smessage_close(nim_msg);
247                nim_msg = NULL;
248        }
249}
250
251/*
252 * Summary:
253 *      Start nim filtering
254 */
255int a56_nim_start(unsigned short network_pid)
256{
257        int cerr = 0;
258
259        a56_stop();
260
261        nim_msg = smessage_open(smessage_format_psi);
262        if (NULL == nim_msg)
263        {
264                BDBG_ERR(("%s",__func__));
265                cerr = -1;
266                return cerr;
267        }
268
269        smessage_stream_params_init(&params, nim_msg);
270        params.band = tuner_band;
271        params.pid = (uint16_t)network_pid;
272        params.filter.coef[0] = SI_NIM_TABLE_ID;
273        params.filter.mask[0] = 0x00;
274        params.filter.excl[0] = 0xff;
275        params.filter.coef[3] = 0x00;   /* protocol_version */
276        params.filter.mask[3] = 0x00;
277        params.filter.excl[3] = 0xff;
278
279        params.buffer = a56_msg_buffer;
280        params.buffer_size = sizeof(a56_msg_buffer);
281        /* processing is done in callback */
282        params.data_ready_callback = a56_msg_callback;
283        params.overflow = NULL;
284        /* don't set the callback */
285        params.callback_context = NULL;
286        SI_NIM_Init((SI_NIM_CDT_Callback_t *)&nim_cdt_cb, (SI_NIM_MMT_Callback_t *)&nim_mmt_cb, 0xFF, 0xFF);
287        if (b_ok != smessage_start(&params, nim_msg))
288        {
289                BDBG_ERR(("%s:%d",__FILE__, __LINE__));
290                cerr = -1;
291        }
292
293        return cerr;
294}
295
296/*
297 * Summary:
298 *      A65 Parser NTM SNT Callback.
299 *      */
300void a56_ntm_snt_cb(SI_NTM_SNT_t *snt, void *data)
301{
302        unsigned char code[3];
303
304        code[0] = (unsigned char)((snt->iso639 >> 16) & 0xFF);
305        code[1] = (unsigned char)((snt->iso639 >> 8) & 0xFF);
306        code[2] = (unsigned char)((snt->iso639 >> 0) & 0xFF);
307
308        BKNI_Printf("%18s = %c%c%c\n", "language", code[0], code[1], code[2]);
309        BKNI_Printf("%18s = %d (0x%x)\n", "source ID", snt->source_id, snt->source_id);
310        BKNI_Printf("%18s = %d\n","application type",  snt->application_type);
311        snt->mtt[snt->name_length] = 0;
312        /* it is MMS format, so skip 2 bytes to get string directly */
313        BKNI_Printf("%18s = %s\n", "name", &snt->mtt[2]);
314}
315
316/*
317 * Summary:
318 *      Start ntm filtering
319 */
320int a56_ntm_start(unsigned short network_pid)
321{
322        int cerr = 0;
323
324        a56_stop();
325
326        ntm_msg = smessage_open(smessage_format_psi);
327        if (NULL == ntm_msg)
328        {
329                BDBG_ERR(("%s",__func__));
330                cerr = -1;
331                return cerr;
332        }
333
334        smessage_stream_params_init(&params, ntm_msg);
335        params.band = tuner_band;
336        params.pid = (uint16_t)network_pid;
337        params.filter.coef[0] = SI_NTM_TABLE_ID;
338        params.filter.mask[0] = 0x00;
339        params.filter.excl[0] = 0xff;
340        params.filter.coef[3] = 0x00;   /* protocol_version */
341        params.filter.mask[3] = 0x00;
342        params.filter.excl[3] = 0xff;
343
344        params.buffer = a56_msg_buffer;
345        params.buffer_size = sizeof(a56_msg_buffer);
346        /* processing is done in callback */
347        params.data_ready_callback = a56_msg_callback;
348        params.overflow = NULL;
349        /* don't set the callback */
350        params.callback_context = NULL;
351        SI_NTM_Init((SI_NTM_SNT_Callback_t *)&ntm_snt_cb, 0xFF);
352        if (b_ok != smessage_start(&params, ntm_msg))
353        {
354                BDBG_ERR(("%s:%d",__FILE__, __LINE__));
355                cerr = -1;
356        }
357
358        return cerr;
359}
360
361/*
362 * Summary:
363 *    Stop NTM filtering
364 */
365void a56_ntm_stop()
366{
367        if (NULL != ntm_msg)
368        {
369                if (b_ok != smessage_stop(ntm_msg))
370                {
371                        BDBG_ERR(("%s:%d",__FILE__, __LINE__));
372                        return;
373                }
374                smessage_close(ntm_msg);
375                ntm_msg = NULL;
376        }
377}
378
379/*
380 * Summary:
381 *      Start vcm filtering
382 */
383int a56_vcm_start(unsigned short network_pid)
384{
385        int cerr = 0;
386
387        a56_stop();
388
389        vcm_msg = smessage_open(smessage_format_psi);
390        if (NULL == vcm_msg)
391        {
392                BDBG_ERR(("%s",__func__));
393                cerr = -1;
394                return cerr;
395        }
396
397        smessage_stream_params_init(&params, vcm_msg);
398        params.band = tuner_band;
399        params.pid = (uint16_t)network_pid;
400        params.filter.coef[0] = SI_VCM_TABLE_ID;
401        params.filter.mask[0] = 0x00;
402        params.filter.excl[0] = 0xff;
403        params.filter.coef[3] = 0x00;   /* protocol_version */
404        params.filter.mask[3] = 0x00;
405        params.filter.excl[3] = 0xff;
406
407        params.buffer = a56_msg_buffer;
408        params.buffer_size = sizeof(a56_msg_buffer);
409        /* processing is done in callback */
410        params.data_ready_callback = a56_msg_callback;
411        params.overflow = NULL;
412        /* don't set the callback */
413        params.callback_context = NULL;
414        SI_VCM_Init((SI_VCM_VCT_Callback_t *)&vcm_vct_cb, 0xFF);
415        if (b_ok != smessage_start(&params, vcm_msg))
416        {
417                BDBG_ERR(("%s:%d",__FILE__, __LINE__));
418                cerr = -1;
419        }
420
421        return cerr;
422}
423
424char *transport_type_str[2] = 
425{
426        "MPEG-2 transport",
427        "non-MPEG-2 transport",
428};
429
430char *channel_type_str[16] = 
431{
432        "normal",
433        "hidden",
434        "local access",
435        "NVOD access",
436        "reserved",
437};
438
439#define CHANNEL_TYPE_MAX        4
440
441/*
442 * Summary:
443 *      A65 Parser VCM VCT Callback.
444 *      */
445void a56_vcm_vct_cb(SI_VCM_VCT_CHANNEL *channel, void *data)
446{
447        int tmp;
448        BKNI_Printf("%24s = %d\n", "vcn mode", channel->vcn_mode);
449        BKNI_Printf("%24s = %d (0x%x)\n", "channel num 1", channel->channum1, channel->channum1);
450        BKNI_Printf("%24s = %d (0x%x)\n", "channel num 2", channel->channum2, channel->channum2);
451        BKNI_Printf("%24s = 0x%x\n", "app flag", channel->appflag);
452        BKNI_Printf("%24s = %d (0x%x)\n", "Source ID", channel->source_ID, channel->source_ID);
453        BKNI_Printf("%24s = %d\n", "path select", channel->path_select);
454        BKNI_Printf("%24s = %s\n", "transport type", transport_type_str[channel->transport_type % 2]);
455        tmp = channel->channel_type;
456        if (tmp >= CHANNEL_TYPE_MAX)
457                tmp = CHANNEL_TYPE_MAX;
458        BKNI_Printf("%24s = %s\n", "channel type", channel_type_str[tmp]);
459        BKNI_Printf("%24s = %d (0x%x)\n", "CDT reference", channel->CDT_reference, channel->CDT_reference);
460        BKNI_Printf("%24s = %d\n", "program num", channel->ChanPropUnion.mpeg_prop.prog_num);
461        BKNI_Printf("%24s = %s\n", "more program", channel->more_prop ? "yes" : "no");
462        BKNI_Printf("%24s = %d\n", "TSID", channel->tsid);
463        BKNI_Printf("%24s = %d\n", "service type", channel->serv_type);
464        BKNI_Printf("%24s = 0x%x\n", "channel bits", channel->chanbits);
465        BKNI_Printf("%24s = %d (0x%x)\n", "VCT ID", channel->vct_id, channel->vct_id);
466        BKNI_Printf("%24s = %d\n", "HD flag", channel->hd_flag);
467        BKNI_Printf("%24s = %d\n", "3D flag", channel->threed_flag);
468        BKNI_Printf("%24s = %d\n", "MPEG4 flag", channel->mpeg4_flag);
469        BKNI_Printf("%24s = %d\n", "SDV flag", channel->sdv_flag);
470        BKNI_Printf("%24s = 0x%x\n", "Included", channel->included);
471        if (channel->included & VCM_VCT_FREQ_SPEC_INCLUDED) {
472                BKNI_Printf("%24s = %d\n", "frequency unit", channel->frequency_unit);
473                BKNI_Printf("%24s = %d\n", "frequency", channel->frequency);
474        }
475        if (channel->included & VCM_VCT_SYMBOL_RATE_INCLUDED) {
476                BKNI_Printf("%24s = %d\n", "symbol rate", channel->symbol_rate);
477        }
478}
479
480/*
481 * Summary:
482 *    Stop VCM filtering
483 */
484void a56_vcm_stop()
485{
486        if (NULL != vcm_msg)
487        {
488                if (b_ok != smessage_stop(vcm_msg))
489                {
490                        BDBG_ERR(("%s:%d",__FILE__, __LINE__));
491                        return;
492                }
493                smessage_close(vcm_msg);
494                vcm_msg = NULL;
495        }
496}
497
498/*
499 * Summary:
500 *      Initialize A56 nim module
501 */
502static void a56_nim_init(void)
503{
504        nim_cdt_cb.cb = a56_nim_cdt_cb;
505        nim_cdt_cb.data = NULL;
506
507        nim_mmt_cb.cb = a56_nim_mmt_cb;
508        nim_mmt_cb.data = NULL;
509}
510
511/*
512 * Summary:
513 *      Initialize A56 ntm module
514 */
515static void a56_ntm_init(void)
516{
517        ntm_snt_cb.cb = a56_ntm_snt_cb;
518        ntm_snt_cb.data = NULL;
519}
520
521/*
522 * Summary:
523 *      Initialize A56 vcm module
524 */
525static void a56_vcm_init(void)
526{
527        vcm_vct_cb.cb = a56_vcm_vct_cb;
528        vcm_vct_cb.data = NULL;
529}
530
531/*
532 * Summary:
533 *      Initialize A56 test module
534 *
535 */
536bool a56_init(void)
537{
538        if (initialized)
539                return true;
540
541        initialized = true;
542
543        a56_nim_init();
544        a56_ntm_init();
545        a56_vcm_init();
546        return true;
547}
548
549/*
550 * Summary:
551 *      stop A56 test modules
552 *
553 */
554void a56_stop(void)
555{
556        a56_nim_stop();
557        a56_ntm_stop(); 
558        a56_vcm_stop();
559}
560
561/*
562 * Summary:
563 *      run given test (0 nim, 1 ntm, 2 vcm, 3 stt)
564 */
565bool a56_test_start(int which, unsigned short network_pid)
566{
567        if (!initialized) {
568                BDBG_ERR(("%s: not initialized yet",__func__));
569                return false;
570        }
571
572        switch (which) {
573                case A56_NIM:
574                        a56_nim_start(network_pid);
575                        break;
576                case A56_NTM:
577                        a56_ntm_start(network_pid);
578                        break;
579                case A56_VCM:
580                        a56_vcm_start(network_pid);
581                        break;
582        }
583        return true;
584}
585
586/*
587 * Summary:
588 *      stop the given test
589 */
590bool a56_test_stop(void)
591{
592        if (!initialized) {
593                BDBG_ERR(("%s: not initialized yet",__func__));
594                return false;
595        }
596        a56_stop();
597        return true;
598}
599
Note: See TracBrowser for help on using the repository browser.