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 drvOTV.c
98 /// @brief OTV Driver Interface
99 /// @author MStar Semiconductor,Inc.
100 /// @attention
101 ////////////////////////////////////////////////////////////////////////////////////////////////////
102
103 // Common Definition
104
105 #include "MsCommon.h"
106 #include "MsVersion.h"
107
108
109 #include "drvOTV.h"
110 #include "drvMMIO.h"
111 #include "regOTV.h"
112 #include "halOTV.h"
113
114
115 #include "asmCPU.h"
116
117 #ifdef MSOS_TYPE_LINUX
118 #include <sys/ioctl.h>
119 #include <unistd.h>
120 #include <fcntl.h> // O_RDWR
121 #endif
122
123 //--------------------------------------------------------------------------------------------------
124 // Debug Macro
125 //--------------------------------------------------------------------------------------------------
126
127 #define DRV_OTV_DBGMSG(_level,_model,_fmt,_args...) if(_u32DrvOtvDbgLevel >= (_level)&&((_u32DrvOtvDbgModel&_model)!=0)) { printf("[%s][%d]",__FUNCTION__,__LINE__); printf(_fmt,##_args);}
128 static MS_U32 _u32DrvOtvDbgLevel = E_DRV_OTV_DBG_LEVEL_ERR;
129 static MS_U32 _u32DrvOtvDbgModel = E_DRV_OTV_DBG_MODEL_ALL;
130
131
132 //--------------------------------------------------------------------------------------------------
133 // Driver Compiler Option
134 //--------------------------------------------------------------------------------------------------
135
136
137 //--------------------------------------------------------------------------------------------------
138 // Local Defines
139 //--------------------------------------------------------------------------------------------------
140
141 #define _OTV_ENTRY() if (!MsOS_ObtainMutex(_pDrvOTV_Res->_s32MutexId, MSOS_WAIT_FOREVER)) \
142 { \
143 _pDrvOTV_Res->_u32LastErr = DRVOTV_FUNC_ERROR; \
144 return DRVOTV_FUNC_ERROR; \
145 } \
146 if (_pDrvOTV_Res->_bSuspend) \
147 { \
148 _OTV_RETURN(DRVOTV_FAIL); \
149 }
150
151 #define _OTV_RETURN(_ret) if(MsOS_ReleaseMutex(_pDrvOTV_Res->_s32MutexId)) {return _ret;} \
152 else \
153 { \
154 _pDrvOTV_Res->_u32LastErr = DRVOTV_FUNC_ERROR; \
155 return DRVOTV_FUNC_ERROR; \
156 }
157
158
159
160 #define _OTV_CHECK(idx) if( (MS_U32)idx >= (MS_U32)OTV_ENG_NUM ) \
161 { printf("[OTV][ERR] OTV Engine [%u] not exist ! \n",(unsigned int)idx); \
162 _OTV_RETURN(FALSE); }
163
164
165 //--------------------------------------------------------------------------------------------------
166 // Local variable
167 //--------------------------------------------------------------------------------------------------
168
169 typedef struct _DrvOTV_State
170 {
171 MS_U32 _OTV_init;
172 DrvOTV_FltState _OTV_FltState;
173 } DrvOTV_State;
174
175 typedef struct _DrvOTV_RESOURCE_PRIVATE
176 {
177 MS_S32 _s32TaskId;
178 MS_S32 _s32MutexId;
179 MS_U32 _u32LastErr;
180 MS_BOOL _bSuspend;
181 MS_BOOL _bISRTaskEn;
182 DrvOTV_State _OTVState[OTV_ENG_NUM][OTV_PIDFLT_NUM_ALL];
183 DrvOTV_NotifyCb _pNotifyCb[OTV_ENG_NUM]; ///< OTV Event Array Callback
184
185 MS_BOOL _bInitReady;
186 }DrvOTV_RESOURCE_PRIVATE;
187
188
189 //static MSIF_Version _drv_OTV_version = {
190 // .DDI = { OTV_DRV_VERSION, },
191 //};
192
193 #ifndef OTV_UTOPIA_20
194 static DrvOTV_RESOURCE_PRIVATE _DrvOTV_Res = {
195
196 ._s32TaskId = -1,
197 ._s32MutexId = -1,
198 ._u32LastErr = DRVOTV_OK,
199 ._bSuspend = FALSE,
200 ._bISRTaskEn = FALSE,
201 ._bInitReady = FALSE,
202 };
203
204 static DrvOTV_RESOURCE_PRIVATE* _pDrvOTV_Res = &_DrvOTV_Res;
205 #else
206 static DrvOTV_RESOURCE_PRIVATE* _pDrvOTV_Res = NULL;
207 #endif
208
209
210 //------------------------------------------------------------------------//
211 // OTV Task Variable declaration
212 //------------------------------------------------------------------------//
213
214 #define OTV_TASK_STACK_SIZE (1024 * 16 )
215 #define OTV_POLLING_TASK_DELAY 50
216
217 static MS_S32 _s32OTV_EventId = -1 ;
218 static MS_BOOL _s32OTV_IsrTaskReturn = FALSE;
219
220
221 #if defined (MSOS_TYPE_ECOS) || defined(MSOS_TYPE_UCOS)
222 static MS_U32 _OTV_Stack[OTV_TASK_STACK_SIZE/sizeof(MS_U32)];
223 #endif
224
225 static DrvOTV_EventArray _EventDataArray[OTV_ENG_NUM][OTV_EVENT_FIFO_DEPTH];
226
227 //--------------------------------------------------------------------------------------------------
228 // Forward declaration
229 //--------------------------------------------------------------------------------------------------
230
_OTV_InitResource(DrvOTV_RESOURCE_PRIVATE * presource)231 static MS_BOOL _OTV_InitResource(DrvOTV_RESOURCE_PRIVATE* presource)
232 {
233 if(presource == NULL)
234 return FALSE;
235
236 presource->_s32TaskId = -1;
237 presource->_s32MutexId = -1;
238 presource->_bSuspend = FALSE;
239 presource->_bInitReady = FALSE;
240 presource->_u32LastErr = DRVOTV_OK;
241
242 return TRUE;
243 }
244
_OTV_IsrTask(void)245 static void _OTV_IsrTask(void)
246 {
247
248 MS_U32 u32Events;
249 MS_U32 u32OTV_Eng;
250 MS_U32 u32EventNum;
251
252 DrvOTV_NotifyCb _Event_CallBackFun;
253
254 while(_pDrvOTV_Res->_bISRTaskEn)
255 {
256 MsOS_WaitEvent(_s32OTV_EventId, 0xFFFFFFFF, &u32Events, E_OR_CLEAR, MSOS_WAIT_FOREVER);
257
258 if(u32Events & E_DRVOTV_HWINT_TASKEND)
259 {
260 break;
261 }
262
263 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_INFO, E_DRV_OTV_DBG_MODEL_ALL, "_OTV_IsrTask!!----- u32Events = %08x \n",(unsigned int)u32Events);
264
265 u32OTV_Eng = (u32Events & E_DRVOTV_ENG_MASK) >> E_DRVOTV_ENG_MASK_SHIFT;
266 u32EventNum = (u32Events & E_DRVOTV_EVENT_NUM_MASK)>> E_DRVOTV_EVENT_NUM_MASK_SHIFT;
267
268 if(u32OTV_Eng >= OTV_ENG_NUM)
269 {
270 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_ERR, E_DRV_OTV_DBG_MODEL_ALL, "Invalid OTV Eng %u \n",(unsigned int)u32OTV_Eng);
271 continue;
272 }
273
274 if( u32Events & E_DRVOTV_HWINT_EVENT )
275 {
276 _Event_CallBackFun = _pDrvOTV_Res->_pNotifyCb[u32OTV_Eng];
277 _Event_CallBackFun(u32OTV_Eng, E_DRVOTV_HWINT_EVENT, u32EventNum, _EventDataArray[u32OTV_Eng], NULL);
278 }
279
280 if( u32Events & E_DRVOTV_HWINT_TIMER )
281 {
282 _Event_CallBackFun = _pDrvOTV_Res->_pNotifyCb[u32OTV_Eng];
283 _Event_CallBackFun(u32OTV_Eng, E_DRVOTV_HWINT_TIMER, u32EventNum, _EventDataArray[u32OTV_Eng], NULL);
284 }
285
286 MsOS_DelayTask(OTV_POLLING_TASK_DELAY);
287
288 }// end while
289
290 _s32OTV_IsrTaskReturn = TRUE;
291 }
292
_OTV_SwStateReset(void)293 static void _OTV_SwStateReset(void)
294 {
295 MS_U32 _u32OTVnum = 0;
296 MS_U32 i = 0;
297 for (_u32OTVnum = 0 ; _u32OTVnum < OTV_ENG_NUM ; _u32OTVnum++)
298 {
299 for (i = OTV_PIDFLT_START_NUM; i < OTV_PIDFLT_END_NUM; i++)
300 {
301 _pDrvOTV_Res->_OTVState[_u32OTVnum][i]._OTV_init = 0;
302 _pDrvOTV_Res->_OTVState[_u32OTVnum][i]._OTV_FltState = E_DRVOTV_FLT_STATE_FREE;
303 }
304 }
305 }
306
_OTV_RegStateReset(void)307 static void _OTV_RegStateReset(void)
308 {
309 MS_U32 _u32fltnum = 0;
310 MS_U32 _u32OTVnum = 0;
311
312 for (_u32OTVnum = 0 ; _u32OTVnum < OTV_ENG_NUM ; _u32OTVnum++)
313 {
314
315 for (_u32fltnum = OTV_PIDFLT_START_NUM ; _u32fltnum < OTV_PIDFLT_END_NUM ; _u32fltnum++)
316 {
317 HAL_OTV_SetFltPid(_u32OTVnum, _u32fltnum, OTV_PID_NULL);
318 HAL_OTV_SetFltEvent(_u32OTVnum, _u32fltnum, ~OTV_EVENT_MASK);
319 }
320 }
321 }
322
_OTV_Init(void)323 static DrvOTV_Result _OTV_Init(void)
324 {
325 MS_U32 u32Idx;
326 MS_VIRT u32Bank;
327 MS_PHY u32BankSize;
328
329 if (FALSE == MDrv_MMIO_GetBASE(&u32Bank, &u32BankSize, MS_MODULE_HW))
330 {
331 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_ERR, E_DRV_OTV_DBG_MODEL_ALL, "MDrv_MMIO_GetBASE fail \n");
332 MS_ASSERT(0);
333 }
334
335 HAL_OTV_SetBank(u32Bank);
336
337 for(u32Idx = 0; u32Idx < OTV_ENG_NUM; u32Idx++)
338 {
339 _pDrvOTV_Res->_pNotifyCb[u32Idx] = NULL;
340
341 //HAL_OTV_PowerCtrl(u8ii, ENABLE);
342 HAL_OTV_Init(u32Idx);
343
344 HAL_OTV_INT_Event_Enable(u32Idx,FALSE);
345 HAL_OTV_INT_Timer_Enable(u32Idx,FALSE);
346 HAL_OTV_INT_ClrEventHW(u32Idx);
347 HAL_OTV_INT_ClrTimerHW(u32Idx);
348
349 // OTV Config Setting
350 HAL_OTV_PktTimerSrcFromPVR_Enable(u32Idx, TRUE);
351 HAL_OTV_PktNumSrcFromPktDemux_Enable(u32Idx, TRUE);
352
353 }
354
355 _OTV_RegStateReset();
356 _OTV_SwStateReset();
357
358 if (-1 == _pDrvOTV_Res->_s32MutexId)
359 {
360 _pDrvOTV_Res->_s32MutexId = MsOS_CreateMutex(E_MSOS_FIFO , "OTV_Mutex" , MSOS_PROCESS_SHARED);
361 }
362 else
363 {
364 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_ERR, E_DRV_OTV_DBG_MODEL_ALL, "Create _s32MutexId more than once \n");
365 }
366
367 return DRVOTV_OK;
368 }
369
_OTV_Close(void)370 static void _OTV_Close(void)
371 {
372 MS_U32 u32Idx;
373
374 for(u32Idx = 0; u32Idx < OTV_ENG_NUM; u32Idx++)
375 {
376 HAL_OTV_Init(u32Idx);
377 }
378
379 }
380
381 // General API
382 //-------------------------------------------------------------------------------------------------
383 /// Initialize lib resource API
384 /// @param pResMemAddr \b IN: Pointer to store resource memory address
385 /// @return MMFI_Result
386 /// @note
387 //-------------------------------------------------------------------------------------------------
MDrv_OTV_InitLibResource(void * pResMemAddr)388 DrvOTV_Result MDrv_OTV_InitLibResource(void* pResMemAddr)
389 {
390 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, " ");
391
392 if(pResMemAddr == 0)
393 return DRVOTV_FAIL;
394
395 _pDrvOTV_Res = (DrvOTV_RESOURCE_PRIVATE*)pResMemAddr;
396
397 if(_pDrvOTV_Res->_bInitReady != TRUE)
398 {
399 if(_OTV_InitResource(_pDrvOTV_Res) == FALSE)
400 {
401 _pDrvOTV_Res->_u32LastErr = DRVOTV_FAIL;
402 }
403 else
404 _pDrvOTV_Res->_u32LastErr = DRVOTV_OK;
405 }
406
407 return (_pDrvOTV_Res->_u32LastErr);
408 }
409
410 //--------------------------------------------------------------------------------------------------
411 /// Initialize OTV driver and OTV engine
412 /// @return DrvOTV_Result
413 /// @note
414 /// It should be called before calling any other OTV DDI functions.
415 /// Driver task is in @ref E_TASK_PRI_SYS level.
416 //--------------------------------------------------------------------------------------------------
MDrv_OTV_Init(void)417 DrvOTV_Result MDrv_OTV_Init(void)
418 {
419 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, " ");
420
421 DrvOTV_Result bRet;
422
423 bRet = _OTV_Init();
424
425
426 if (-1 == _s32OTV_EventId)
427 {
428 _s32OTV_EventId = MsOS_CreateEventGroup("OTV_Event");
429 }
430
431 _OTV_ENTRY();
432
433 if (-1 == _pDrvOTV_Res->_s32TaskId)
434 {
435 #if defined (MSOS_TYPE_ECOS) || defined(MSOS_TYPE_UCOS)
436
437 _pDrvOTV_Res->_s32TaskId = MsOS_CreateTask( (TaskEntry) _OTV_IsrTask,
438 (MS_U32)NULL,
439 (TaskPriority) E_TASK_PRI_SYS,
440 TRUE,
441 _OTV_Stack,
442 OTV_TASK_STACK_SIZE,
443 "OTV_IsrTask");
444 #else
445 _pDrvOTV_Res->_s32TaskId = MsOS_CreateTask( (TaskEntry) _OTV_IsrTask,
446 (MS_U32)NULL,
447 (TaskPriority) E_TASK_PRI_SYS,
448 TRUE,
449 NULL,
450 0,
451 "OTV_IsrTask");
452 #endif
453 }
454
455 _pDrvOTV_Res->_bInitReady = TRUE;
456 _pDrvOTV_Res->_bISRTaskEn = TRUE;
457 _OTV_RETURN(bRet);
458 }
459
460 //--------------------------------------------------------------------------------------------------
461 /// Poweroff OTV driver and OTV engine
462 /// @return DrvOTV_Result
463 /// @note
464 //--------------------------------------------------------------------------------------------------
465 #if 0
466 DrvOTV_Result MDrv_DrvOTV_Reset(void)
467 {
468 _OTV_ENTRY();
469 _OTV_SwStateReset();
470 _OTV_RegStateReset();
471 _OTV_RETURN(DRVOTV_OK);
472 }
473 #endif
474 //--------------------------------------------------------------------------------------------------
475 /// Close OTV driver and reset software/register state
476 /// @return DrvOTV_Result
477 /// @note
478 //--------------------------------------------------------------------------------------------------
MDrv_OTV_Exit(void)479 DrvOTV_Result MDrv_OTV_Exit(void)
480 {
481 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, " ");
482
483 if(_pDrvOTV_Res->_s32TaskId != -1)
484 {
485 while(!_s32OTV_IsrTaskReturn)
486 {
487 MsOS_SetEvent(_s32OTV_EventId, E_DRVOTV_HWINT_TASKEND);
488 MsOS_DelayTask(OTV_POLLING_TASK_DELAY);
489 }
490
491 _s32OTV_IsrTaskReturn = FALSE;
492
493 _pDrvOTV_Res->_s32TaskId = -1;
494 _pDrvOTV_Res->_bISRTaskEn = FALSE;
495 }
496
497 if (_pDrvOTV_Res->_s32MutexId != -1)
498 {
499 _OTV_ENTRY();
500 MsOS_ReleaseMutex(_pDrvOTV_Res->_s32MutexId);
501 MsOS_DeleteMutex(_pDrvOTV_Res->_s32MutexId);
502 _pDrvOTV_Res->_s32MutexId = -1;
503 }
504
505 if(_pDrvOTV_Res->_bInitReady == TRUE)
506 {
507 _OTV_SwStateReset();
508 _OTV_RegStateReset();
509 _OTV_Close();
510 _pDrvOTV_Res->_bInitReady = FALSE;
511 }
512
513 return DRVOTV_OK;
514 }
515
MDrv_OTV_ISR(MS_U32 u32OTVEng,DRVOTV_HWINT_TYPE HWINT_TYPE)516 DrvOTV_Result MDrv_OTV_ISR(MS_U32 u32OTVEng, DRVOTV_HWINT_TYPE HWINT_TYPE)
517 {
518 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, "OTV_Eng = %u, HWINT_TYPE = %x \n",(unsigned int)u32OTVEng, (unsigned int)HWINT_TYPE);
519
520 _OTV_CHECK(u32OTVEng);
521
522 MS_U32 u32OTV_IntStatus = 0;
523 MS_U32 u32EventNum;
524 MS_U32 u32EventIdx = 0;
525 MS_U32 u32Idx;
526
527 HAL_OTV_EventQ_GetEventNum(u32OTVEng, &u32EventNum);
528
529 while( u32EventNum )
530 {
531 for(u32Idx=0; u32Idx <u32EventNum; u32Idx++)
532 {
533 if( HAL_OTV_EventQ_PopEvent(u32OTVEng) )
534 {
535 HAL_OTV_EventQ_GetEventDesciptor(u32OTVEng, &_EventDataArray[u32OTVEng][u32EventIdx].Event_Descriptor);
536 HAL_OTV_EventQ_GetEventPktPID( u32OTVEng, &_EventDataArray[u32OTVEng][u32EventIdx].Pid);
537 HAL_OTV_EventQ_GetEventPktNum( u32OTVEng, &_EventDataArray[u32OTVEng][u32EventIdx].PacketNum);
538 HAL_OTV_EventQ_GetEventPktTimer( u32OTVEng, &_EventDataArray[u32OTVEng][u32EventIdx].Timer);
539 HAL_OTV_EventQ_GetEventPktPCR( u32OTVEng, &_EventDataArray[u32OTVEng][u32EventIdx].PCR);
540 }
541 u32EventIdx++;
542 }
543
544 HAL_OTV_EventQ_GetEventNum(u32OTVEng, &u32EventNum);
545 }// end while
546
547 u32OTV_IntStatus |= (( u32OTVEng << E_DRVOTV_ENG_MASK_SHIFT) & E_DRVOTV_ENG_MASK);
548 u32OTV_IntStatus |= ((u32EventIdx << E_DRVOTV_EVENT_NUM_MASK_SHIFT) & E_DRVOTV_EVENT_NUM_MASK);
549 u32OTV_IntStatus |= (( HWINT_TYPE << E_DRVOTV_HWINT_MASK_SHIFT) & E_DRVOTV_HWINT_MASK);
550
551 if(u32OTV_IntStatus == 0)
552 {
553 return DRVOTV_FAIL;
554 }
555 else
556 {
557 MsOS_SetEvent(_s32OTV_EventId, u32OTV_IntStatus);
558 }
559
560 return DRVOTV_OK;
561 }
562
MDrv_OTV_AllocFlt(MS_U32 u32OTVEng,MS_U32 * pu32FltId)563 DrvOTV_Result MDrv_OTV_AllocFlt(MS_U32 u32OTVEng, MS_U32 *pu32FltId)
564 {
565 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, "OTV_Eng = %u \n",(unsigned int)u32OTVEng);
566
567 _OTV_ENTRY();
568 _OTV_CHECK(u32OTVEng);
569
570 MS_U32 i = 0;
571
572 for (i = OTV_PIDFLT_START_NUM ; i < OTV_PIDFLT_END_NUM ; i++)
573 {
574 if (_pDrvOTV_Res->_OTVState[u32OTVEng][i]._OTV_FltState == E_DRVOTV_FLT_STATE_FREE)
575 {
576 _pDrvOTV_Res->_OTVState[u32OTVEng][i]._OTV_FltState = E_DRVOTV_FLT_STATE_ALLOC;
577 *pu32FltId = i;
578 break;
579 }
580 }
581
582 if (i == OTV_PIDFLT_END_NUM)
583 {
584 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_ERR, E_DRV_OTV_DBG_MODEL_ALL, "No free fitler found 0x%02x \n", (unsigned int)i);
585 _OTV_RETURN(DRVOTV_FAIL);
586 }
587
588 _OTV_RETURN(DRVOTV_OK);
589 }
590
MDrv_OTV_SetFltPid(MS_U32 u32OTVEng,MS_U32 u32FltId,MS_U16 u16Pid)591 DrvOTV_Result MDrv_OTV_SetFltPid(MS_U32 u32OTVEng, MS_U32 u32FltId, MS_U16 u16Pid)
592 {
593 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, "OTV_Eng = %u, FltId = %u, Pid = 0x%x\n",(unsigned int)u32OTVEng, (unsigned int)u32FltId, u16Pid);
594
595 _OTV_ENTRY();
596 _OTV_CHECK(u32OTVEng);
597
598 HAL_OTV_SetFltPid(u32OTVEng, u32FltId, u16Pid);
599
600 _OTV_RETURN(DRVOTV_OK);
601 }
602
MDrv_OTV_GetFltPid(MS_U32 u32OTVEng,MS_U32 u32FltId,MS_U16 * pu16Pid)603 DrvOTV_Result MDrv_OTV_GetFltPid(MS_U32 u32OTVEng, MS_U32 u32FltId, MS_U16 *pu16Pid)
604 {
605 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, "OTV_Eng = %u, FltId = %u\n",(unsigned int)u32OTVEng, (unsigned int)u32FltId);
606
607 _OTV_ENTRY();
608 _OTV_CHECK(u32OTVEng);
609
610 HAL_OTV_GetFltPid(u32OTVEng, u32FltId, pu16Pid);
611
612 _OTV_RETURN(DRVOTV_OK);
613 }
614
MDrv_OTV_SetFltEvent(MS_U32 u32OTVEng,MS_U32 u32FltId,DRVOTV_EVENT_TYPE eEvent)615 DrvOTV_Result MDrv_OTV_SetFltEvent(MS_U32 u32OTVEng, MS_U32 u32FltId, DRVOTV_EVENT_TYPE eEvent)
616 {
617 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, "OTV_Eng = %u, FltId = %u, eEvent = %x\n",(unsigned int)u32OTVEng, (unsigned int)u32FltId, (unsigned int)eEvent);
618
619 _OTV_ENTRY();
620 _OTV_CHECK(u32OTVEng);
621
622 HAL_OTV_SetFltEvent(u32OTVEng, u32FltId, eEvent);
623
624 _OTV_RETURN(DRVOTV_OK);
625 }
626
MDrv_OTV_GetFltEvent(MS_U32 u32OTVEng,MS_U32 u32FltId,DRVOTV_EVENT_TYPE * pEvent)627 DrvOTV_Result MDrv_OTV_GetFltEvent(MS_U32 u32OTVEng, MS_U32 u32FltId, DRVOTV_EVENT_TYPE* pEvent)
628 {
629 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, "OTV_Eng = %u, FltId = %u \n",(unsigned int)u32OTVEng, (unsigned int)u32FltId);
630
631 _OTV_ENTRY();
632 _OTV_CHECK(u32OTVEng);
633
634 HAL_OTV_GetFltEvent(u32OTVEng, u32FltId, pEvent);
635
636 _OTV_RETURN(DRVOTV_OK);
637 }
638
MDrv_OTV_ReleaseFlt(MS_U32 u32OTVEng,MS_U32 u32FltId)639 DrvOTV_Result MDrv_OTV_ReleaseFlt(MS_U32 u32OTVEng, MS_U32 u32FltId)
640 {
641 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, "OTV_Eng = %u, FltId = %u \n",(unsigned int)u32OTVEng, (unsigned int)u32FltId);
642
643 _OTV_ENTRY();
644 _OTV_CHECK(u32OTVEng);
645
646 _pDrvOTV_Res->_OTVState[u32OTVEng][u32FltId]._OTV_FltState = E_DRVOTV_FLT_STATE_FREE;
647 HAL_OTV_SetFltPid(u32OTVEng, u32FltId, OTV_PID_NULL);
648
649 _OTV_RETURN(DRVOTV_OK);
650 }
651
MDrv_OTV_GetCurPktStatus(MS_U32 u32OTVEng,MS_U32 * u32PktStamp,MS_U32 * u32PktNumber)652 DrvOTV_Result MDrv_OTV_GetCurPktStatus(MS_U32 u32OTVEng, MS_U32* u32PktStamp, MS_U32* u32PktNumber)
653 {
654 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, "OTV_Eng = %u \n",(unsigned int)u32OTVEng);
655
656 HAL_OTV_GetCurPktTimer(u32OTVEng, u32PktStamp);
657 HAL_OTV_GetCurPktNum(u32OTVEng, u32PktNumber);
658
659 return TRUE;
660 }
661
MDrv_OTV_SetNotifyCb(MS_U32 u32OTVEng,DrvOTV_NotifyCb pfCallback)662 DrvOTV_Result MDrv_OTV_SetNotifyCb(MS_U32 u32OTVEng, DrvOTV_NotifyCb pfCallback)
663 {
664 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, "OTV_Eng = %u \n",(unsigned int)u32OTVEng);
665
666 _OTV_ENTRY();
667 _OTV_CHECK(u32OTVEng);
668
669 if (pfCallback)
670 {
671 _pDrvOTV_Res->_pNotifyCb[u32OTVEng] = pfCallback;
672 }
673 else
674 {
675 _pDrvOTV_Res->_pNotifyCb[u32OTVEng] = NULL;
676 }
677
678 _OTV_RETURN(DRVOTV_OK);
679 }
680
MDrv_OTV_HWINT_Enable(MS_U32 u32OTVEng,DRVOTV_HWINT_TYPE HWINT_TYPE,MS_BOOL bEnable)681 DrvOTV_Result MDrv_OTV_HWINT_Enable(MS_U32 u32OTVEng, DRVOTV_HWINT_TYPE HWINT_TYPE, MS_BOOL bEnable)
682 {
683 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, "OTV_Eng = %u, HWINT_TYPE = %x, bEnable = %d\n",(unsigned int)u32OTVEng, (unsigned int)HWINT_TYPE, bEnable);
684
685 _OTV_ENTRY();
686 _OTV_CHECK(u32OTVEng);
687
688 if(HWINT_TYPE == E_DRVOTV_HWINT_EVENT)
689 {
690 HAL_OTV_EventQ_Enable(u32OTVEng, bEnable);
691 HAL_OTV_INT_Event_Enable(u32OTVEng, bEnable);
692 }
693 else if(HWINT_TYPE == E_DRVOTV_HWINT_TIMER)
694 {
695 HAL_OTV_EventQ_Enable(u32OTVEng, bEnable);
696 HAL_OTV_INT_Timer_Enable(u32OTVEng, bEnable);
697 }
698
699 _OTV_RETURN(DRVOTV_OK);
700 }
701
702
MDrv_OTV_HWINT_Get(MS_U32 u32OTVEng,DRVOTV_HWINT_TYPE HWINT_TYPE,MS_BOOL * bInterrupted)703 DrvOTV_Result MDrv_OTV_HWINT_Get(MS_U32 u32OTVEng, DRVOTV_HWINT_TYPE HWINT_TYPE, MS_BOOL* bInterrupted)
704 {
705 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, "OTV_Eng = %u, HWINT_TYPE = %x \n",(unsigned int)u32OTVEng, (unsigned int)HWINT_TYPE);
706
707 if(!bInterrupted)
708 return DRVOTV_FAIL;
709
710 _OTV_CHECK(u32OTVEng);
711
712 switch (HWINT_TYPE)
713 {
714 case E_DRVOTV_HWINT_EVENT:
715 if(HAL_OTV_INT_GetEventHW(u32OTVEng))
716 *bInterrupted = TRUE;
717 else
718 *bInterrupted = FALSE;
719 break;
720
721 case E_DRVOTV_HWINT_TIMER:
722 if(HAL_OTV_INT_GetTimerHW(u32OTVEng))
723 *bInterrupted = TRUE;
724 else
725 *bInterrupted = FALSE;
726 break;
727
728 default:
729 return DRVOTV_FAIL;
730 }
731
732 return DRVOTV_OK;
733 }
734
MDrv_OTV_HWINT_Clear(MS_U32 u32OTVEng,DRVOTV_HWINT_TYPE HWINT_TYPE)735 DrvOTV_Result MDrv_OTV_HWINT_Clear(MS_U32 u32OTVEng, DRVOTV_HWINT_TYPE HWINT_TYPE)
736 {
737 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, "OTV_Eng = %u, HWINT_TYPE = %x \n",(unsigned int)u32OTVEng, (unsigned int)HWINT_TYPE);
738
739 _OTV_CHECK(u32OTVEng);
740
741 switch (HWINT_TYPE)
742 {
743 case E_DRVOTV_HWINT_EVENT:
744 HAL_OTV_INT_ClrEventHW(u32OTVEng);
745 break;
746
747 case E_DRVOTV_HWINT_TIMER:
748 HAL_OTV_INT_ClrTimerHW(u32OTVEng);
749 break;
750
751 default:
752 return DRVOTV_FAIL;
753 }
754
755 return DRVOTV_OK;
756 }
757
MDrv_OTV_HWINT_SetEvent_Threshold(MS_U32 u32OTVEng,MS_U32 u32Threshold)758 DrvOTV_Result MDrv_OTV_HWINT_SetEvent_Threshold(MS_U32 u32OTVEng, MS_U32 u32Threshold /*Maximum value is 31*/)
759 {
760 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, "OTV_Eng = %u, Event Threshold = %u \n",(unsigned int)u32OTVEng, (unsigned int)u32Threshold);
761
762 _OTV_CHECK(u32OTVEng);
763
764 if (u32Threshold <= 31 )
765 {
766 HAL_OTV_INT_SetEventWaterLevel(u32OTVEng, u32Threshold);
767 return DRVOTV_OK;
768 }
769 else
770 {
771 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_ERR, E_DRV_OTV_DBG_MODEL_ALL, "OTV_Eng = %u Event Threshold Exceeds \n",(unsigned int)u32OTVEng);
772 return DRVOTV_FAIL;
773 }
774
775 }
776
MDrv_OTV_HWINT_SetTimer_Timeout(MS_U32 u32OTVEng,DrvOTV_Time_Watermark Timeout)777 DrvOTV_Result MDrv_OTV_HWINT_SetTimer_Timeout(MS_U32 u32OTVEng, DrvOTV_Time_Watermark Timeout)
778 {
779 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, "OTV_Eng = %u, Timeout = %x \n",(unsigned int)u32OTVEng, (unsigned int)Timeout);
780
781 _OTV_CHECK(u32OTVEng);
782
783 if ( Timeout>=E_DRVOTV_TIME_WATERMARK_50MS && Timeout<=E_DRVOTV_TIME_WATERMARK_500MS )
784 {
785 HAL_OTV_INT_SetTimerWaterLevel(u32OTVEng, (MS_U32)Timeout );
786 return DRVOTV_OK;
787 }
788 else
789 {
790 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_ERR, E_DRV_OTV_DBG_MODEL_ALL, "OTV_Eng = %u Timer Threshold Exceeds \n",(unsigned int)u32OTVEng);
791 return DRVOTV_FAIL;
792 }
793 }
794
MDrv_OTV_SetDbgLevel(DRV_OTV_DBGMSG_LEVEL level,DRV_OTV_DBGMSG_MODEL model)795 DrvOTV_Result MDrv_OTV_SetDbgLevel(DRV_OTV_DBGMSG_LEVEL level, DRV_OTV_DBGMSG_MODEL model)
796 {
797 DRV_OTV_DBGMSG(E_DRV_OTV_DBG_LEVEL_FUNC, E_DRV_OTV_DBG_MODEL_ALL, "OTV_DBG_Level = %u, OTV_DBG_Model = %u \n", (unsigned int)level, (unsigned int)model);
798
799 _u32DrvOtvDbgLevel = level;
800 _u32DrvOtvDbgModel = model;
801
802 return DRVOTV_OK;
803 }
804
805
806 // [ToDo]
807 #if 0
808 DrvOTV_Result MDrv_OTV_GetCap(DrvOTV_Cap eCap, void* pOutput)
809 {
810 *((MS_U32*)pOutput) = 0;
811
812 switch (eCap)
813 {
814 case E_DRVOTV_CAP_RESOURCE_SIZE:
815 *((MS_U32*)pOutput) = sizeof(DrvOTV_RESOURCE_PRIVATE);
816 return DRVOTV_OK;
817 case E_DRVOTV_CAP_FILTER_NUM:
818 case E_DRVOTV_CAP_FILTER_PVR_NUM:
819 *((MS_U32*)pOutput) = OTV_PIDFLT_NUM_ALL;
820 return DRVOTV_OK;
821 case E_DRVOTV_CAP_PVR_ALIGN:
822 *((MS_U32*)pOutput) = 16;
823 return DRVOTV_OK;
824 case E_DRVOTV_CAP_OTV_ENG_NUM:
825 *((MS_U32*)pOutput) = OTV_ENG_NUM;
826 return DRVOTV_OK;
827 default:
828 return DRVOTV_INVALID_PARAM;
829 }
830 }
831
832
833 #endif
834