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!�L) 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 #define _DRV_DMX_TTX_C
96
97 // Common Definition
98 #if defined(MSOS_TYPE_LINUX_KERNEL)
99 // #include <linux/slab.h>
100 #include <linux/string.h> //for memcpy, memset
101 #else
102 #include <string.h>
103 #endif
104 #include "MsCommon.h"
105 #include "MsOS.h"
106 #include "ULog.h"
107 // Internal Definition
108 #include "drvDMX_TTX.h"
109 #include "drvMMIO.h"
110
111 #include "utopia.h"
112
113 #if (VBI_TTX_UTOPIA20)
114 #include "drvVBI_v2.h"
115 #endif
116
117 #include "drvVBI_private.h"
118
119 //-------------------------------------------------------------------------------------------------
120 // Driver Compiler Options
121 //-------------------------------------------------------------------------------------------------
122
123
124 //-------------------------------------------------------------------------------------------------
125 // Local Defines
126 //-------------------------------------------------------------------------------------------------
127 #define MAPI_DMX_DMXID_NULL 0xFF
128 #define DEFAULT_WAIT_TIME MSOS_WAIT_FOREVER // 50 ms
129
130 static DMX_CB_FN _pFN = NULL;
131
132 static VBI_RING_BUFFER rb_handle;
133
134 static DMX_TTX_StoreInfo _pStoreInfo = {
135 ._bTTXInit = FALSE,
136 ._bSuspend = FALSE,
137 ._TTXBufAddr = 0xFFFFFFFFUL,
138 ._TTXBufLen = 0,
139 ._FilterID = MAPI_DMX_DMXID_NULL,
140 };
141
142 // Mutex & Lock
143 static MS_S32 _s32DMXMutex = -1;
144
145 #if (VBI_TTX_UTOPIA20)
146 static void* pInstantVbiTTX = NULL;
147 static void* pAttributeVbiTTX = NULL;
148 #endif
149
150 /********************************************************************************/
151 /* external functions */
152 /********************************************************************************/
153
154 //-------------------------------------------------------------------------------------------------
155 // Debug Functions
156 //-------------------------------------------------------------------------------------------------
157
158 //-------------------------------------------------------------------------------------------------
159 // Local Functions
160 //-------------------------------------------------------------------------------------------------
_MDrv_DMX_TTX_UpdateWritePointer(void)161 static MS_BOOL _MDrv_DMX_TTX_UpdateWritePointer(void)
162 {
163 MS_S32 NumberOfFreePackets;
164 MS_U32 addr;
165
166 if(_pStoreInfo._FilterID==MAPI_DMX_DMXID_NULL)
167 {
168 return FALSE;
169 }
170
171 if(_pFN==NULL)
172 {
173 return FALSE;
174 }
175
176 addr = (*_pFN)(_pStoreInfo._FilterID);
177 rb_handle.WritePacketNumber = (addr - _pStoreInfo._TTXBufAddr)/VBI_TTX_DATA_LENGTH;
178 rb_handle.WritePacketNumber = rb_handle.WritePacketNumber%_pStoreInfo._TTXBufLen;
179
180 if(rb_handle.pkt_received==TRUE)
181 {
182 NumberOfFreePackets = (MS_S32)(rb_handle.WritePacketNumber - rb_handle.ReadPacketNumber);
183 if (NumberOfFreePackets < 0)
184 NumberOfFreePackets += _pStoreInfo._TTXBufLen;
185
186 NumberOfFreePackets = (MS_S32)(_pStoreInfo._TTXBufLen - NumberOfFreePackets);
187
188 if (NumberOfFreePackets < 2)
189 {
190 rb_handle.NoOfPacketBufferOverflows++;
191 rb_handle.PacketBufferOverflow = TRUE;
192 return FALSE;
193 }
194 }
195
196 if(rb_handle.WritePacketNumber == 0)
197 {
198 if(rb_handle.pkt_received )
199 {
200 rb_handle.WritePacketNumber = _pStoreInfo._TTXBufLen - 1;
201 }
202 }
203 else if(rb_handle.WritePacketNumber != rb_handle.ReadPacketNumber)
204 {
205 rb_handle.WritePacketNumber--;
206 rb_handle.pkt_received = TRUE;
207 }
208 return TRUE;
209 }
210
211 //-------------------------------------------------------------------------------------------------
212 // Global Functions
213 //-------------------------------------------------------------------------------------------------
_MDrv_DMX_TTX_RingBuffer_Reset(void)214 void _MDrv_DMX_TTX_RingBuffer_Reset(void)
215 {
216 MS_U32 addr =0;
217 memset((MS_U8 *) MS_PA2KSEG1(_pStoreInfo._TTXBufAddr), 0x20, _pStoreInfo._TTXBufLen*VBI_TTX_DATA_LENGTH);
218
219 OS_OBTAIN_MUTEX(_s32DMXMutex, DEFAULT_WAIT_TIME);
220
221 if(_pFN!=NULL)
222 {
223 addr = (*_pFN)(_pStoreInfo._FilterID);
224 rb_handle.ReadPacketNumber = (addr - _pStoreInfo._TTXBufAddr)/VBI_TTX_DATA_LENGTH;
225 }
226 else
227 rb_handle.ReadPacketNumber = 0;
228
229 rb_handle.ReadPacketNumber = rb_handle.ReadPacketNumber%_pStoreInfo._TTXBufLen;
230 rb_handle.WritePacketNumber = rb_handle.ReadPacketNumber;
231 rb_handle.pkt_received = FALSE;
232
233 rb_handle.PacketBufferOverflow = FALSE;
234 rb_handle.NoOfPacketBufferOverflows = 0;
235 OS_RELEASE_MUTEX(_s32DMXMutex);
236
237 }
238
_MDrv_DMX_TTX_Init(EN_DMX_TTX_CMD cmd,MS_PHY bufferAddr,MS_U16 packetCount)239 MS_BOOL _MDrv_DMX_TTX_Init(EN_DMX_TTX_CMD cmd, MS_PHY bufferAddr, MS_U16 packetCount)
240 {
241 static char _dmxTTXSyncMutexName[] = "OS_DMX_TTX_MUTEX";
242
243 if(cmd == DMX_TTX_INIT)
244 {
245 _s32DMXMutex = //OS_CREATE_MUTEX(DMX_TTX);
246 MsOS_CreateMutex(E_MSOS_FIFO, _dmxTTXSyncMutexName, MSOS_PROCESS_PRIVATE);
247
248 _pStoreInfo._TTXBufAddr = bufferAddr;
249 _pStoreInfo._TTXBufLen = packetCount;
250 _pStoreInfo._FilterID = MAPI_DMX_DMXID_NULL;
251
252 _pStoreInfo._bTTXInit = TRUE;
253 }
254
255 _MDrv_DMX_TTX_RingBuffer_Reset();
256
257 return TRUE;
258 }
259
_MDrv_DMX_TTX_Exit(EN_DMX_TTX_CMD cmd)260 MS_BOOL _MDrv_DMX_TTX_Exit(EN_DMX_TTX_CMD cmd)
261 {
262 _pStoreInfo._bTTXInit = FALSE;
263
264 if(cmd == DMX_TTX_EXIT)
265 {
266 if (_s32DMXMutex != -1)
267 {
268 OS_OBTAIN_MUTEX(_s32DMXMutex, DEFAULT_WAIT_TIME);
269 OS_RELEASE_MUTEX(_s32DMXMutex);
270 OS_DELETE_MUTEX(_s32DMXMutex);
271 }
272 }
273
274 return TRUE;
275 }
276
_MDrv_DMX_TTX_SetFilterID(MS_U8 fid)277 void _MDrv_DMX_TTX_SetFilterID(MS_U8 fid)
278 {
279 _pStoreInfo._FilterID = fid;
280 }
281
_MDrv_DMX_TTX_SetCB(DMX_CB_FN fn)282 void _MDrv_DMX_TTX_SetCB(DMX_CB_FN fn)
283 {
284 _pFN = fn;
285 }
286
_MDrv_DMX_TTX_PacketBufferIsEmpty(void)287 MS_BOOL _MDrv_DMX_TTX_PacketBufferIsEmpty(void)
288 {
289 if(_MDrv_DMX_TTX_UpdateWritePointer()==FALSE) // if overflow or slicer is not ready, define it is buffer empty
290 return TRUE;
291 if (rb_handle.WritePacketNumber - rb_handle.ReadPacketNumber) /* no of packets */
292 return FALSE;
293
294 return TRUE;
295 }
296
_MDrv_DMX_TTX_GetPackets(MS_PHY dataAddr,MS_U32 * length)297 MS_BOOL _MDrv_DMX_TTX_GetPackets(MS_PHY dataAddr, MS_U32 *length)
298 {
299 MS_U8 *pData = (MS_U8 *) MS_PA2KSEG1(dataAddr);
300 MS_BOOL ret = FALSE;
301
302 if((*length)==0)
303 return FALSE;
304
305 OS_OBTAIN_MUTEX(_s32DMXMutex, DEFAULT_WAIT_TIME);
306
307 if (_MDrv_DMX_TTX_PacketBufferIsEmpty()==FALSE)
308 {
309 MS_PHY packetAddress;
310 MS_U32 data_length;
311 MS_U32 data_length2;
312
313 packetAddress = _pStoreInfo._TTXBufAddr + (rb_handle.ReadPacketNumber) * VBI_TTX_DATA_LENGTH;
314
315 if(rb_handle.ReadPacketNumber > rb_handle.WritePacketNumber)
316 {
317 // HEAD <--- 2 ---> W ------R <--- 1 ---> TAIL
318
319 // copy region 1
320 data_length = VBI_TTX_DATA_LENGTH*((_pStoreInfo._TTXBufLen - 1) - rb_handle.ReadPacketNumber);
321
322 if(data_length > (*length))
323 data_length = (*length);
324
325 memcpy(pData, (MS_U8 *) MS_PA2KSEG1(packetAddress), data_length);
326
327 // input buffer is full
328 if((*length)==data_length)
329 {
330 rb_handle.ReadPacketNumber += data_length/VBI_TTX_DATA_LENGTH;
331 ret = TRUE;
332 goto GET_PACKETS_EXIT;
333 }
334
335 // copy region 2
336 data_length2 = VBI_TTX_DATA_LENGTH*(rb_handle.WritePacketNumber);
337
338 // calculate the left buffer size
339 if(data_length2 > ((*length) - data_length))
340 data_length2 = ((*length) - data_length);
341
342 memcpy(pData + data_length, (MS_U8 *) MS_PA2KSEG1(_pStoreInfo._TTXBufAddr), data_length2);
343
344 rb_handle.ReadPacketNumber = data_length2/VBI_TTX_DATA_LENGTH;
345 (*length) = data_length + data_length2;
346
347 ret = TRUE;
348 }
349 else
350 {
351 // R <--- 1 ---> W
352
353 // copy region 1
354 data_length = VBI_TTX_DATA_LENGTH*(rb_handle.WritePacketNumber - rb_handle.ReadPacketNumber);
355
356 if(data_length > (*length))
357 data_length = (*length);
358
359 memcpy(pData, (MS_U8 *) MS_PA2KSEG1(packetAddress), data_length);
360
361 rb_handle.ReadPacketNumber += data_length/VBI_TTX_DATA_LENGTH;
362 (*length) = data_length;
363
364 ret = TRUE;
365 }
366 }
367
368 GET_PACKETS_EXIT:
369 OS_RELEASE_MUTEX(_s32DMXMutex);
370 return ret;
371 }
372
_MDrv_DMX_TTX_GetPacket(MS_PHY * packetAddress)373 MS_BOOL _MDrv_DMX_TTX_GetPacket(MS_PHY *packetAddress)
374 {
375 MS_BOOL ret = FALSE;
376
377 OS_OBTAIN_MUTEX(_s32DMXMutex, DEFAULT_WAIT_TIME);
378
379 if (_MDrv_DMX_TTX_PacketBufferIsEmpty()==FALSE)
380 {
381 *packetAddress = _pStoreInfo._TTXBufAddr + rb_handle.ReadPacketNumber*VBI_TTX_DATA_LENGTH;
382
383 rb_handle.ReadPacketNumber++;
384
385 // TSP, 0 -> 1 -> 2 ->3 -> N-1 -> 0 -> 1 ->2 -> 3 ...
386 if ( rb_handle.ReadPacketNumber >= _pStoreInfo._TTXBufLen )
387 {
388 rb_handle.ReadPacketNumber = 0;
389 }
390
391 ret = TRUE;
392 }
393
394 OS_RELEASE_MUTEX(_s32DMXMutex);
395 return ret;
396 }
397
_MDrv_DMX_TTX_PacketBufferIsOverflow(void)398 MS_BOOL _MDrv_DMX_TTX_PacketBufferIsOverflow( void )
399 {
400 return rb_handle.PacketBufferOverflow;
401 }
402
_MDrv_DMX_TTX_PacketBufferGetNoOfOverflows(void)403 MS_U16 _MDrv_DMX_TTX_PacketBufferGetNoOfOverflows( void )
404 {
405 return rb_handle.NoOfPacketBufferOverflows;
406 }
407
_MDrv_DMX_TTX_Suspend(void)408 MS_BOOL _MDrv_DMX_TTX_Suspend(void)
409 {
410 if((_pStoreInfo._bSuspend != FALSE) || (_s32DMXMutex == -1))
411 {
412 return FALSE;
413 }
414
415 _pStoreInfo._bSuspend = TRUE;
416 _MDrv_DMX_TTX_Exit(DMX_TTX_SUSPEND);
417 return TRUE;
418 }
419
_MDrv_DMX_TTX_Resume(void)420 MS_BOOL _MDrv_DMX_TTX_Resume(void)
421 {
422 if((_pStoreInfo._bSuspend != TRUE) || (_s32DMXMutex == -1))
423 {
424 return FALSE;
425 }
426
427 _pStoreInfo._bSuspend = FALSE;
428 _MDrv_DMX_TTX_Init(DMX_TTX_RESUME, _pStoreInfo.bufferAddr, _pStoreInfo.packetCount);
429 return TRUE;
430 }
431
_MDrv_DMX_TTX_SetPowerState(EN_POWER_MODE u16PowerState)432 MS_U32 _MDrv_DMX_TTX_SetPowerState(EN_POWER_MODE u16PowerState)
433 {
434 MS_U16 _ret = FALSE;
435
436 switch (u16PowerState)
437 {
438 case E_POWER_SUSPEND:
439 _ret = MDrv_DMX_TTX_Suspend();
440 break;
441
442 case E_POWER_RESUME:
443 _ret = MDrv_DMX_TTX_Resume();
444 break;
445
446 case E_POWER_MECHANICAL:
447 case E_POWER_SOFT_OFF:
448 default:
449 ULOGE("VBI", "[%s] %d Power state not support!!\n", __FUNCTION__, __LINE__);
450 break;
451 }
452
453 return ((TRUE == _ret)? UTOPIA_STATUS_SUCCESS: UTOPIA_STATUS_FAIL);
454 }
455
456
MDrv_DMX_TTX_RingBuffer_Reset(void)457 void MDrv_DMX_TTX_RingBuffer_Reset(void)
458 {
459 #if (VBI_TTX_UTOPIA20)
460 if (NULL == pInstantVbiTTX)
461 {
462 ULOGE("VBI", "pInstantVbi=NULL fail\n");
463 return;
464 }
465
466 if(UtopiaIoctl(pInstantVbiTTX, MDrv_CMD_DMX_TTX_RingBuffer_Reset,(void*)NULL) != UTOPIA_STATUS_SUCCESS)
467 {
468 ULOGE("VBI", "Ioctl MDrv_DMX_TTX_RingBuffer_Reset fail\n");
469 return;
470 }
471 #else
472 _MDrv_DMX_TTX_RingBuffer_Reset();
473 #endif
474 }
475
MDrv_DMX_TTX_Init(MS_PHY bufferAddr,MS_U16 packetCount)476 MS_BOOL MDrv_DMX_TTX_Init(MS_PHY bufferAddr, MS_U16 packetCount)
477 {
478 #if (VBI_TTX_UTOPIA20)
479 VBI_INITIALIZER_TTX_SLICER InitializerTTXSlicer;
480 memset(&InitializerTTXSlicer, 0 , sizeof(VBI_INITIALIZER_TTX_SLICER));
481
482 if (NULL == pInstantVbiTTX)
483 {
484 if(UTOPIA_STATUS_FAIL == UtopiaOpen(MODULE_VBI, (void**)&pInstantVbiTTX, 0, pAttributeVbiTTX))
485 {
486 ULOGE("VBI", "UtopiaOpen VBI fail\n");
487 return FALSE;
488 }
489 }
490 else
491 {
492 ULOGE("VBI", "VBI_TTX already Opened\n");
493 return FALSE;
494 }
495
496 InitializerTTXSlicer.cmd = DMX_TTX_INIT;
497 InitializerTTXSlicer.bufferAddr = bufferAddr;
498 InitializerTTXSlicer.packetCount = packetCount;
499
500 if(UtopiaIoctl(pInstantVbiTTX, MDrv_CMD_DMX_TTX_Init,(void*)&InitializerTTXSlicer) != UTOPIA_STATUS_SUCCESS)
501 {
502 ULOGE("VBI", "Ioctl MDrv_DMX_TTX_Init fail\n");
503 return FALSE;
504 }
505 return TRUE;
506 #else
507 return _MDrv_DMX_TTX_Init(DMX_TTX_INIT, bufferAddr, packetCount);
508 #endif
509 }
510
MDrv_DMX_TTX_Exit(void)511 MS_BOOL MDrv_DMX_TTX_Exit(void)
512 {
513
514 #if (VBI_TTX_UTOPIA20)
515 DMX_TTX_CMD Cmd;
516 memset(&Cmd, 0 , sizeof(DMX_TTX_CMD));
517
518 if (NULL == pInstantVbiTTX)
519 {
520 ULOGE("VBI", "pInstantVbiTTX=NULL fail\n");
521 return FALSE;
522 }
523
524 if(UtopiaIoctl(pInstantVbiTTX, MDrv_CMD_DMX_TTX_Exit,(void*)&Cmd) != UTOPIA_STATUS_SUCCESS)
525 {
526 ULOGE("VBI", "Ioctl MDrv_CMD_DMX_TTX_Exit fail\n");
527 return FALSE;
528 }
529 return TRUE;
530 #else
531 return _MDrv_DMX_TTX_Exit(DMX_TTX_EXIT);
532 #endif
533
534 }
535
MDrv_DMX_TTX_SetFilterID(MS_U8 fid)536 void MDrv_DMX_TTX_SetFilterID(MS_U8 fid)
537 {
538 #if (VBI_TTX_UTOPIA20)
539 DMX_TTX_SET_FILTERID DMXSetFilterID;
540 memset(&DMXSetFilterID, 0 , sizeof(DMX_TTX_SET_FILTERID));
541
542 if (NULL == pInstantVbiTTX)
543 {
544 ULOGE("VBI", "pInstantVbi=NULL fail\n");
545 return;
546 }
547
548 DMXSetFilterID.fid = fid;
549
550 if(UtopiaIoctl(pInstantVbiTTX, MDrv_CMD_DMX_TTX_SetFilterID,(void*)&DMXSetFilterID) != UTOPIA_STATUS_SUCCESS)
551 {
552 ULOGE("VBI", "Ioctl MDrv_DMX_TTX_SetFilterID fail\n");
553 return;
554 }
555 #else
556 _MDrv_DMX_TTX_SetFilterID(fid);
557 #endif
558 }
559
MDrv_DMX_TTX_SetCB(DMX_CB_FN fn)560 void MDrv_DMX_TTX_SetCB(DMX_CB_FN fn)
561 {
562 #if (VBI_TTX_UTOPIA20)
563 DMX_TTX_SET_CB DMXSetCB;
564 memset(&DMXSetCB, 0 , sizeof(DMX_TTX_SET_CB));
565
566 if (NULL == pInstantVbiTTX)
567 {
568 ULOGE("VBI", "pInstantVbi=NULL fail\n");
569 return;
570 }
571
572 DMXSetCB.fn = fn;
573
574 if(UtopiaIoctl(pInstantVbiTTX, MDrv_CMD_DMX_TTX_SetCB,(void*)&DMXSetCB) != UTOPIA_STATUS_SUCCESS)
575 {
576 ULOGE("VBI", "Ioctl MDrv_DMX_TTX_SetCB fail\n");
577 return;
578 }
579 #else
580 _MDrv_DMX_TTX_SetCB(fn);
581 #endif
582 }
583
MDrv_DMX_TTX_PacketBufferIsEmpty(void)584 MS_BOOL MDrv_DMX_TTX_PacketBufferIsEmpty(void)
585 {
586 #if (VBI_TTX_UTOPIA20)
587 VBI_BOOL CheckTureFalse;
588 memset(&CheckTureFalse, 0 , sizeof(VBI_BOOL));
589
590 if (NULL == pInstantVbiTTX)
591 {
592 ULOGE("VBI", "pInstantVbi=NULL fail\n");
593 return FALSE;
594 }
595
596 if(UtopiaIoctl(pInstantVbiTTX, MDrv_CMD_DMX_TTX_PacketBufferIsEmpty,(void*)&CheckTureFalse) != UTOPIA_STATUS_SUCCESS)
597 {
598 ULOGE("VBI", "Ioctl MDrv_DMX_TTX_PacketBufferIsEmpty fail\n");
599 return FALSE;
600 }
601 return CheckTureFalse.bCheck;
602 #else
603 return _MDrv_DMX_TTX_PacketBufferIsEmpty();
604 #endif
605 }
606
MDrv_DMX_TTX_GetPackets(MS_PHY dataAddr,MS_U32 * length)607 MS_BOOL MDrv_DMX_TTX_GetPackets(MS_PHY dataAddr, MS_U32 *length)
608 {
609 #if (VBI_TTX_UTOPIA20)
610 VBI_TTX_GET_PACKETS GetPackets;
611 memset(&GetPackets, 0 , sizeof(VBI_TTX_GET_PACKETS));
612
613 if (NULL == pInstantVbiTTX)
614 {
615 ULOGE("VBI", "pInstantVbi=NULL fail\n");
616 return FALSE;
617 }
618
619 GetPackets.dataAddr = dataAddr;
620 GetPackets.length = length;
621
622 if(UtopiaIoctl(pInstantVbiTTX, MDrv_CMD_DMX_TTX_GetPackets,(void*)&GetPackets) != UTOPIA_STATUS_SUCCESS)
623 {
624 //ULOGE("VBI", "Ioctl MDrv_DMX_TTX_GetPackets fail\n");
625 return FALSE;
626 }
627 return TRUE;
628 #else
629 return _MDrv_DMX_TTX_GetPackets(dataAddr, length);
630 #endif
631 }
632
MDrv_DMX_TTX_GetPacket(MS_PHY * packetAddress)633 MS_BOOL MDrv_DMX_TTX_GetPacket(MS_PHY *packetAddress)
634 {
635 #if (VBI_TTX_UTOPIA20)
636 VBI_TTX_GET_PACKET GetPacket;
637 memset(&GetPacket, 0 , sizeof(VBI_TTX_GET_PACKET));
638
639 if (NULL == pInstantVbiTTX)
640 {
641 ULOGE("VBI", "pInstantVbi=NULL fail\n");
642 return FALSE;
643 }
644
645 GetPacket.packetAddress = packetAddress;
646
647 if(UtopiaIoctl(pInstantVbiTTX, MDrv_CMD_DMX_TTX_GetPacket,(void*)&GetPacket) != UTOPIA_STATUS_SUCCESS)
648 {
649 //ULOGE("VBI", "Ioctl MDrv_DMX_TTX_GetPacket fail\n");
650 return FALSE;
651 }
652 return TRUE;
653 #else
654 return _MDrv_DMX_TTX_GetPacket(packetAddress);
655 #endif
656 }
657
658 /***********************************************************************
659 * FUNCTION: MDrv_DMX_TTX_PacketBufferIsOverflow
660 *
661 * DESCRIPTION:
662 * Check if there is a packet buffer overflow. If there is an overflow,
663 * the the packet buffer should be cleared from the reading task.
664 *
665 * RETURN:
666 * TRUE if there is packet buffer overflow,
667 * NULL otherwise.
668 ***********************************************************************/
MDrv_DMX_TTX_PacketBufferIsOverflow(void)669 MS_BOOL MDrv_DMX_TTX_PacketBufferIsOverflow( void )
670 {
671 #if (VBI_TTX_UTOPIA20)
672 VBI_BOOL CheckTureFalse;
673 memset(&CheckTureFalse, 0 , sizeof(VBI_BOOL));
674
675 if (NULL == pInstantVbiTTX)
676 {
677 ULOGE("VBI", "pInstantVbi=NULL fail\n");
678 return FALSE;
679 }
680
681 if(UtopiaIoctl(pInstantVbiTTX, MDrv_CMD_DMX_TTX_PacketBufferIsOverflow,(void*)&CheckTureFalse) != UTOPIA_STATUS_SUCCESS)
682 {
683 ULOGE("VBI", "Ioctl MDrv_DMX_TTX_PacketBufferIsOverflow fail\n");
684 return FALSE;
685 }
686 return CheckTureFalse.bCheck;
687 #else
688 return _MDrv_DMX_TTX_PacketBufferIsOverflow();
689 #endif
690 }
691
692 /***********************************************************************
693 * FUNCTION: MDrv_DMX_TTX_PacketBufferGetNoOfOverflows
694 *
695 * DESCRIPTION:
696 * Resuren the nomber of packet buffer overflows since the last reset
697 * or creation.
698 *
699 * RETURN:
700 * The number of packet buffer overflows.
701 ***********************************************************************/
MDrv_DMX_TTX_PacketBufferGetNoOfOverflows(void)702 MS_U16 MDrv_DMX_TTX_PacketBufferGetNoOfOverflows( void )
703 {
704 #if (VBI_TTX_UTOPIA20)
705 VBI_GET_DATA GetData;
706 memset(&GetData, 0 , sizeof(VBI_GET_DATA));
707
708 if (NULL == pInstantVbiTTX)
709 {
710 ULOGE("VBI", "pInstantVbi=NULL fail\n");
711 return FALSE;
712 }
713
714 if(UtopiaIoctl(pInstantVbiTTX, MDrv_CMD_DMX_TTX_PacketBufferGetNoOfOverflows,(void*)&GetData) != UTOPIA_STATUS_SUCCESS)
715 {
716 //ULOGE("VBI", "Ioctl MDrv_DMX_TTX_PacketBufferGetNoOfOverflows fail\n");
717 return FALSE;
718 }
719 return GetData.u16data;
720 #else
721 return _MDrv_DMX_TTX_PacketBufferGetNoOfOverflows();
722 #endif
723 }
724
725 /****************************************************************************
726 *@brief : Suspend DMX_TTX driver
727 *@return TRUE - Success
728 *@return FALSE - Failure
729 *@note
730 *@Save DMX_TTX driver states to DRAM
731 ****************************************************************************/
MDrv_DMX_TTX_Suspend(void)732 MS_BOOL MDrv_DMX_TTX_Suspend(void)
733 {
734 #if (VBI_UTOPIA20)
735 VBI_BOOL CheckTureFalse;
736 memset(&CheckTureFalse, 0 , sizeof(VBI_BOOL));
737
738 if (NULL == pInstantVbiTTX)
739 {
740 ULOGE("VBI", "pInstantVbi=NULL fail\n");
741 return FALSE;
742 }
743
744 if(UtopiaIoctl(pInstantVbiTTX, MDrv_CMD_DMX_TTX_Suspend,(void*)&CheckTureFalse) != UTOPIA_STATUS_SUCCESS)
745 {
746 ULOGE("VBI", "Ioctl MDrv_DMX_TTX_Suspend fail\n");
747 return FALSE;
748 }
749 return CheckTureFalse.bCheck;
750 #else
751 return _MDrv_DMX_TTX_Suspend();
752 #endif
753 }
754
755 /****************************************************************************
756 *@brief : Resume DMX_TTX driver
757 *@return TRUE - Success
758 *@return FALSE - Failure
759 *@note
760 *@Save DMX_TTX driver states to DRAM
761 *@Restore DMX_TTX driver states from DRAM
762 ****************************************************************************/
MDrv_DMX_TTX_Resume(void)763 MS_BOOL MDrv_DMX_TTX_Resume(void)
764 {
765 #if (VBI_UTOPIA20)
766 VBI_BOOL CheckTureFalse;
767 memset(&CheckTureFalse, 0 , sizeof(VBI_BOOL));
768
769 if (NULL == pInstantVbiTTX)
770 {
771 ULOGE("VBI", "pInstantVbi=NULL fail\n");
772 return FALSE;
773 }
774
775 if(UtopiaIoctl(pInstantVbiTTX, MDrv_CMD_DMX_TTX_Resume,(void*)&CheckTureFalse) != UTOPIA_STATUS_SUCCESS)
776 {
777 ULOGE("VBI", "Ioctl MDrv_DMX_TTX_Resume fail\n");
778 return FALSE;
779 }
780 return CheckTureFalse.bCheck;
781 #else
782 return _MDrv_DMX_TTX_Resume();
783 #endif
784 }
785
786 /****************************************************************************
787 *@brief : Set DMX_TTX suspend & resume
788 *@param u16PowerState \b IN: DMX_TTX power state
789 *@return TRUE - Success
790 *@return FALSE - Failure
791 *@note
792 ****************************************************************************/
MDrv_DMX_TTX_SetPowerState(EN_POWER_MODE u16PowerState)793 MS_U32 MDrv_DMX_TTX_SetPowerState(EN_POWER_MODE u16PowerState)
794 {
795 #if (VBI_UTOPIA20)
796 VBI_GET_RESULT GetResult;
797 memset(&GetResult, 0 , sizeof(VBI_GET_RESULT));
798
799 if (NULL == pInstantVbiTTX)
800 {
801 ULOGE("VBI", "pInstantVbi=NULL fail\n");
802 return FALSE;
803 }
804
805 GetResult.u16PowerState = u16PowerState;
806
807 if(UtopiaIoctl(pInstantVbiTTX, MDrv_CMD_DMX_TTX_SetPowerState,(void*)&GetResult) != UTOPIA_STATUS_SUCCESS)
808 {
809 ULOGE("VBI", "Ioctl MDrv_DMX_TTX_SetPowerState fail\n");
810 return FALSE;
811 }
812 return GetResult.u32result;
813 #else
814 return _MDrv_VBI_SetPowerState();
815 #endif
816 }
817
818 #undef _DRV_DMX_TTX_C
819