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 #define _DRVEMMFLT_C
94
95 ////////////////////////////////////////////////////////////////////////////////
96 /// file drvEMMFlt.c
97 /// @author MStar Semiconductor Inc.
98 /// @brief to filter EMM packet
99 ////////////////////////////////////////////////////////////////////////////////
100 //------------------------------------------------------------------------------
101 // Header Files
102 //------------------------------------------------------------------------------
103
104 #ifdef MSOS_TYPE_LINUX_KERNEL
105 #include <linux/string.h>
106 #else
107 #include <string.h>
108 #endif
109
110 #include "MsCommon.h"
111 #include "MsOS.h"
112 #include "MsVersion.h"
113 #include "drvEMMFlt.h"
114 #include "halEMMflt.h"
115 #include "drvMMIO.h"
116 #include "asmCPU.h"
117 #include "halCHIP.h"
118 #include "drvNSK2Type.h"
119 #include "MsIRQ.h"
120
121 ////////////////////////////////////////////////////////////////////////////////
122 // Local defines & local structures
123 ////////////////////////////////////////////////////////////////////////////////
124
125 static MS_U32 _g32EMMDbgLv = EMM_DBGLV_DEBUG;
126 static InterruptNum _gEMMFltIntNum = 0;
127
128 #define _EMM_DBG(x, args...) {printf(x, ##args);}
129
130 #define DRVEMM_DBG(lv, x, args...) do { if(lv <= _g32EMMDbgLv) \
131 { \
132 _EMM_DBG("%s(%d): ", __FUNCTION__,__LINE__); _EMM_DBG(x, ##args); \
133 } } while (0)
134
135
136 #define EMM_ENABLE 1
137 #define EMM_DISABLE 0
138
139 #define EMMFLT_TASK_STACK_SIZE 16*1024
140
141 //#define EMM_IRQ_INT E_INT_FIQ_TSP_SPARE_CA2PM_8
142
143 //interrupt control should be modified after checking the correct one.
144 #define EMMFLTIntEnable() MsOS_EnableInterrupt(_gEMMFltIntNum);
145 #define EMMFLTIntDisable() MsOS_DisableInterrupt(_gEMMFltIntNum);
146 #define EMMFLTIntAttach() MsOS_AttachInterrupt(_gEMMFltIntNum, (InterruptCb )_MDrv_EMMDFLT_Isr)
147 #define EMMFLTIntDetach() MsOS_DetachInterrupt (_gEMMFltIntNum)
148
149
150 #define NDS_EMM_EVENT_OVERFLOW_SW 0x00000040
151
152 #define StatusCheck(x) { if(x!=DRV_EMMFLT_OK) \
153 return (x); }
154 //#define CompileWithNSKLib
155 ////////////////////////////////////////////////////////////////////////////////
156 // External funciton
157 ////////////////////////////////////////////////////////////////////////////////
158
159 ////////////////////////////////////////////////////////////////////////////////
160 // Local Variables
161 ////////////////////////////////////////////////////////////////////////////////
162 static MS_S32 _s32EMMFLTMutexId = -1;
163 static MS_S32 _s32EMMFLTEventId = -1;
164 static MS_S32 _s32EMMDFLTTaskId = -1;
165
166 static MS_U8 _u8EmmIsInit = FALSE;
167
168 static void* _pEMMDFLTTaskStack;
169 static MS_U8 _u8EMMDFLT_StackBuffer[EMMFLT_TASK_STACK_SIZE];
170
171 MS_U8 _u8EmmBuf[EMMENG_NUMBER][MAX_EMM_LIST_NUM][NDS_EMMFLT_BUF_SIZE];
172 static MS_U32 _gHWEMMBufAddr[EMMENG_NUMBER][MAX_EMM_LIST_NUM];
173 static MS_BOOL bEmmOverflow[EMMENG_NUMBER];
174 //static MS_BOOL bEmmOverflowReturn[EMMENG_NUMBER];
175
176
177 static MS_U8 _u8EmmRead[EMMENG_NUMBER];
178 static MS_U8 _u8EmmWrite[EMMENG_NUMBER];
179 static MS_U8 _u8EmmHold[EMMENG_NUMBER];
180
181 /* backup address, later used to find connection */
182 static MS_U8 *_pu8BufAddrBackup[EMMENG_NUMBER][MAX_EMM_LIST_NUM];
183
184 static EMMFLT_Notify _gEMMFltNtf = NULL;
185
186 ////////////////////////////////////////////////////////////////////////////////
187 // Global Variables
188 ////////////////////////////////////////////////////////////////////////////////
189
190
191 ////////////////////////////////////////////////////////////////////////////////
192 // Local Function
193 ////////////////////////////////////////////////////////////////////////////////
194 static void _MDrv_EMMDFLT_Isr(void);
195
196 #define EMMFLT_ENTRY() MsOS_ObtainMutex(_s32EMMFLTMutexId, MSOS_WAIT_FOREVER)
197 #define EMMFLT_RETURN(_ret) { MsOS_ReleaseMutex(_s32EMMFLTMutexId); return _ret; }
198 #define EMMFLT_LOCK() MsOS_ObtainMutex(_s32EMMFLTMutexId, MSOS_WAIT_FOREVER)
199 #define EMMFLT_UNLOCK() MsOS_ReleaseMutex(_s32EMMFLTMutexId)
200
201
202 #define emmQueueInc(connection) \
203 { \
204 _u8EmmWrite[connection]++; \
205 if (MAX_EMM_LIST_NUM <= _u8EmmWrite[connection]) \
206 { \
207 _u8EmmWrite[connection] = 0; \
208 } \
209 }
210
211 #define emmQueueDec(connection) \
212 { \
213 _u8EmmRead[connection]++; \
214 if (MAX_EMM_LIST_NUM <= _u8EmmRead[connection]) \
215 { \
216 _u8EmmRead[connection] = 0; \
217 } \
218 }
219
220
221 #define emmQueueIsEmpty(connection) (_u8EmmRead[connection] == _u8EmmWrite[connection])
222 #define emmQueueFreeSize(connection) (MAX_EMM_LIST_NUM - emmQueueUsedSize(connection) - 1)
223 #define emmQueueUsedSize(connection) ((_u8EmmWrite[connection] >= _u8EmmRead[connection]) ? \
224 (_u8EmmWrite[connection] - _u8EmmRead[connection]) : \
225 (MAX_EMM_LIST_NUM - _u8EmmRead[connection] + _u8EmmWrite[connection]))
226 #define emmQueueIsFull(connection) (0 == emmQueueFreeSize(connection))
227 #define emmQueueReset(connection) { _u8EmmRead[connection] = _u8EmmWrite[connection] = _u8EmmHold[connection] = 0 }
228
229 #define CONNECTFLAG_BASE 0x10000
230
231
232
233 #ifdef MSOS_TYPE_LINUX_KERNEL
234 extern irqreturn_t _NDS_RASP_Isr(int irq, void *dev_id);
235 #else
236 extern void _NDS_RASP_Isr(InterruptNum eIntNum);
237 #endif
238
239 static MS_BOOL EMMRASP_En[MAX_ENGINE] = {FALSE, FALSE};
240
_EMMRASP_Isr_(void)241 static void _EMMRASP_Isr_(void)
242 {
243 if( TRUE == EMMRASP_En[EMM_ENGINE] )
244 {
245 _MDrv_EMMDFLT_Isr();
246 }
247
248 if( TRUE == EMMRASP_En[RASP_ENGINE] )
249 {
250 #ifdef MSOS_TYPE_LINUX_KERNEL
251 _NDS_RASP_Isr(E_INT_IRQ_RASP, NULL);
252 #else
253 _NDS_RASP_Isr(E_INT_IRQ_RASP);
254 #endif
255 }
256
257 MsOS_EnableInterrupt(E_INT_IRQ_RASP);
258 }
259
EMMRASP_IntAttach(EMMRASP_e eEng,MS_BOOL Enable)260 void EMMRASP_IntAttach(EMMRASP_e eEng, MS_BOOL Enable)
261 {
262 if(HAL_EMMFLT_GetIntMode())
263 {
264 EMMRASP_En[eEng] = Enable;
265 if(TRUE == Enable)
266 {
267 if( (TRUE == EMMRASP_En[EMM_ENGINE]) && (TRUE == EMMRASP_En[RASP_ENGINE]) )
268 {
269 }
270 else
271 {
272 MsOS_AttachInterrupt(E_INT_IRQ_RASP, (InterruptCb )_EMMRASP_Isr_);
273 MsOS_EnableInterrupt(E_INT_IRQ_RASP);
274 }
275 }
276 else
277 {
278 if( (FALSE == EMMRASP_En[EMM_ENGINE]) && (FALSE == EMMRASP_En[RASP_ENGINE]) )
279 {
280 MsOS_DetachInterrupt(E_INT_IRQ_RASP);
281 MsOS_DisableInterrupt(E_INT_IRQ_RASP);
282 }
283 }
284 }
285 else
286 {
287 if(EMM_ENGINE == eEng)
288 {
289 if(TRUE == Enable)
290 {
291 EMMFLTIntAttach();
292 EMMFLTIntEnable();
293 }
294 else
295 {
296 EMMFLTIntDetach();
297 EMMFLTIntDisable();
298 }
299 }
300 else
301 {
302 if(TRUE == Enable)
303 {
304 MsOS_AttachInterrupt(E_INT_IRQ_RASP, (InterruptCb )_NDS_RASP_Isr);
305 MsOS_EnableInterrupt(E_INT_IRQ_RASP);
306 }
307 else
308 {
309 MsOS_DetachInterrupt(E_INT_IRQ_RASP);
310 MsOS_DisableInterrupt(E_INT_IRQ_RASP);
311 }
312 }
313 }
314
315 }
316
_MDrv_EMMDFLT_Isr(void)317 static void _MDrv_EMMDFLT_Isr(void)
318 {
319 MS_U16 u16EMMInt[EMMENG_NUMBER]; //useless
320 MS_U16 u16EMMBufIndex[EMMENG_NUMBER];
321 MS_U8 connectflag[EMMENG_NUMBER],i;
322 MS_U8 u8EMMBufCnt = 0;
323 MS_U32 u32EventFlag = 0;
324 MS_U16 u16EMMIntStat[EMMENG_NUMBER];
325
326 DRVEMM_DBG(EMM_DBGLV_DEBUG,"\n_MDrv_EMMDFLT_Isr\n");
327
328 //EMMFLTIntDisable();
329
330 HAL_EMMFLT_GetIntStatus(u16EMMInt,u16EMMIntStat,connectflag);
331
332 for( i=0; i<EMMENG_NUMBER; i++)
333 {
334 //HAL_EMMFLT_ResetInt(i);//egi_test_20141211
335
336 if(connectflag[i] == FALSE){ continue; }
337 u32EventFlag = (CONNECTFLAG_BASE<<i);
338
339 //u16EMMBufIndex[i] = HAL_EMMFLT_GetCurrentBufIndex(i); //need to move position
340 HAL_EMMFLT_PacketCount(i,&u8EMMBufCnt);
341 DRVEMM_DBG(EMM_DBGLV_DEBUG, "conn[%x]: u8EMMBufCnt = %x\n",i,u8EMMBufCnt);
342
343 if (u16EMMIntStat[i] & EMMFLT_EMM_OVERFLOW_INT)
344 {
345 DRVEMM_DBG(EMM_DBGLV_ERR, "EMMFLT_EMM_HW_OVERFLOW_INT\n");
346 if (bEmmOverflow[i] == FALSE)
347 {
348 bEmmOverflow[i] = TRUE;
349 u32EventFlag |= u16EMMIntStat[i];
350
351 HAL_EMMFLT_PacketAct(i); //act to clear interrupt....
352 MsOS_SetEvent(_s32EMMFLTEventId, u32EventFlag);
353 }
354 }
355
356 if (u16EMMIntStat[i] & EMMFLT_EMM_INT)
357 {
358 DRVEMM_DBG(EMM_DBGLV_INFO, "EMMFLT_EMM_INT\n");
359 if (bEmmOverflow[i] == FALSE)
360 {
361 if(emmQueueIsFull(i))
362 {
363 DRVEMM_DBG(EMM_DBGLV_ERR, "EMM Queue Is Full\n");
364 bEmmOverflow[i] = TRUE;
365 u32EventFlag |= NDS_EMM_EVENT_OVERFLOW_SW;
366 HAL_EMMFLT_PacketAct(i); //act to clear interrupt....
367
368 }
369 else
370 {
371 MsOS_ReadMemory();
372 while(u8EMMBufCnt>0)
373 {
374 u16EMMBufIndex[i] = HAL_EMMFLT_GetCurrentBufIndex(i);
375 DRVEMM_DBG(EMM_DBGLV_DEBUG, "EMMBufIndex=%x, EMMBufCnt = %x\n",u16EMMBufIndex[i],u8EMMBufCnt);
376 memcpy(_u8EmmBuf[i][_u8EmmWrite[i]], (void*)MS_PA2KSEG1(_gHWEMMBufAddr[i][u16EMMBufIndex[i]]), EMM_COPY_PACKET_SIZE);
377 emmQueueInc(i);
378 u8EMMBufCnt--;
379
380 DRVEMM_DBG(EMM_DBGLV_INFO, "EmmWrite[%x],EmmHold[%x],EmmRead[%x]\n",_u8EmmWrite[i],_u8EmmHold[i],_u8EmmRead[i]);
381 HAL_EMMFLT_PacketAct(i); /*act to clear interrupt...*/
382 }
383 }
384 u32EventFlag |= u16EMMIntStat[i];
385 MsOS_SetEvent(_s32EMMFLTEventId, u32EventFlag);
386
387 }
388 else
389 {
390 #if 0 //test
391 //needs to consider...
392 u32EventFlag |= (u16EMMIntStatus[i] | NDS_EMM_EVENT_OVERFLOW_SW);
393 #endif
394
395 HAL_EMMFLT_PacketAct(i); //act to clear interrupt....
396 //MsOS_SetEvent(_s32EMMFLTEventId, u32EventFlag);
397 }
398 }
399
400 }
401
402 if(FALSE == HAL_EMMFLT_GetIntMode())
403 {
404 EMMFLTIntEnable();
405 }
406
407 }
408
409 MS_U8 bufcnt = 0;
410
_MDrv_EMMDFLT_Isr_Proc(void)411 static void _MDrv_EMMDFLT_Isr_Proc(void)
412 {
413 MS_U32 u32Events;
414 MS_U8 i,connection;
415 MS_U32 u32UsedSize;
416 MS_U8 tmp;
417
418 bufcnt = 0;
419
420 DRVEMM_DBG(EMM_DBGLV_DEBUG,"EMMFlt wait event\n");
421 HAL_EMMFLT_SetDebugMode(0xF);
422
423 while (1)
424 {
425 MsOS_WaitEvent(_s32EMMFLTEventId, 0xFFFFFFFF /*EMMFLT_STATES_GROUP*/, &u32Events, E_OR_CLEAR, MSOS_WAIT_FOREVER /*1000 */ );
426 DRVEMM_DBG(EMM_DBGLV_DEBUG,"u32Event = %x\n",u32Events);
427
428 for( i=0; i<EMMENG_NUMBER; i++)
429 {
430 if( ( u32Events & (CONNECTFLAG_BASE<<i) ) == 0 ) {continue;}
431
432 connection = i;
433 DRVEMM_DBG(EMM_DBGLV_DEBUG,"connection = %x\n",connection);
434
435 if (u32Events & EMMFLT_EMM_INT)
436 {
437 u32UsedSize = ((_u8EmmWrite[i] >= _u8EmmHold[i]) ? (_u8EmmWrite[i] - _u8EmmHold[i]) : (MAX_EMM_LIST_NUM - _u8EmmHold[i] + _u8EmmWrite[i]));
438 for (; u32UsedSize > 0; u32UsedSize--)
439 {
440 if (_u8EmmBuf[i][_u8EmmHold[i]][0] != 0x47)
441 {
442 DRVEMM_DBG(EMM_DBGLV_ERR,"packet %d is DULL _u8EmmBuf[i][_u8EmmHold[i]][0] = %x \n", _u8EmmHold[i], _u8EmmBuf[i][_u8EmmHold[i]][0]); //for dbg [Aug8,14]
443 /*for prevent sw overflow due to dull packet*/
444 emmQueueDec(connection);
445 goto jump_next_emm;
446 }
447 DRVEMM_DBG(EMM_DBGLV_DEBUG,"\nEMM_RECV %d\n\n", MsOS_GetSystemTime());
448
449 /* backup address for release emm later */
450 _pu8BufAddrBackup[i][_u8EmmHold[i]] = &_u8EmmBuf[i][_u8EmmHold[i]][0];
451 DRVEMM_DBG(EMM_DBGLV_INFO,"NSK2HDX_EmmArrived = %p\n",_pu8BufAddrBackup[i][_u8EmmHold[i]]);
452
453 jump_next_emm:
454 tmp = _u8EmmHold[i]++;
455 if ( MAX_EMM_LIST_NUM <= _u8EmmHold[i])
456 {
457 _u8EmmHold[i] = 0;
458 }
459 DRVEMM_DBG(EMM_DBGLV_DEBUG, "EmmWrite[%x],EmmHold[%x],EmmRead[%x]\n",_u8EmmWrite[i],_u8EmmHold[i],_u8EmmRead[i]);
460 if(_gEMMFltNtf) { _gEMMFltNtf(i,EMM_EVENT_ARRIVE, &_u8EmmBuf[i][tmp][0]); }
461
462 }
463 }
464
465 if (u32Events & NDS_EMM_EVENT_OVERFLOW_SW)
466 {
467 DRVEMM_DBG(EMM_DBGLV_ERR,"EMM Buffer SW Overflow\n");
468 if(_gEMMFltNtf) { _gEMMFltNtf(i,EMM_EVENT_OVERFLOW, NULL); }
469 }
470
471 if (u32Events & EMMFLT_EMM_OVERFLOW_INT)
472 {
473 DRVEMM_DBG(EMM_DBGLV_ERR,"EMM Buffer HW Overflow\n");
474 if(_gEMMFltNtf) { _gEMMFltNtf(i,EMM_EVENT_OVERFLOW, NULL); }
475 }
476 }//connection loop
477
478 EMMFLTIntEnable(); //egi_test_20141211
479
480 } // Task while loop
481 }
482
483 ////////////////////////////////////////////////////////////////////////////////
484 // Global Function
485 ////////////////////////////////////////////////////////////////////////////////
MDrv_EMMFLT_Init(EMMFLT_Require_t * pRequire)486 EMMFLT_RESULT MDrv_EMMFLT_Init(EMMFLT_Require_t *pRequire)
487 {
488
489 MS_VIRT u32Bank;
490 MS_PHY u32BankSize;
491 MS_U32 i;
492
493 DRVEMM_DBG(EMM_DBGLV_DEBUG,"enter MDrv_EMMFLT_Init\n");
494 if(_u8EmmIsInit == FALSE)
495 {
496 if (FALSE == MDrv_MMIO_GetBASE(&u32Bank, &u32BankSize, MS_MODULE_PM))
497 {
498 DRVEMM_DBG(EMM_DBGLV_ERR,"MDrv_MMIO_GetBASE (NonPM base)fail\n");
499 MS_ASSERT(0);
500 }
501
502 printf("u32Bank = %X\n",u32Bank);
503 DRVEMM_DBG(EMM_DBGLV_DEBUG, "%s u32Bank: %x\n", __FUNCTION__, u32Bank);
504 HAL_EMMFLT_SetBank(u32Bank); //set non pm bank
505
506 for( i=0 ; i<EMMENG_NUMBER ; i++ )
507 {
508 HAL_EMMFLT_SWReset(i);
509 }
510 HAL_EMMFLT_Init();
511
512 _gEMMFltIntNum = (InterruptNum)HAL_EMMFLT_GetIntNumber();
513
514 EMMRASP_IntAttach(EMM_ENGINE, TRUE);
515 HAL_EMMFLT_Enable_Int();
516
517 _s32EMMFLTEventId = MsOS_CreateEventGroup("EMMFLT_Event");
518 if (_s32EMMFLTEventId < 0)
519 {
520 DRVEMM_DBG(EMM_DBGLV_ERR,"CreateEvent fail\n");
521 return DRV_EMMFLT_FAIL;
522 }
523
524 _s32EMMFLTMutexId = MsOS_CreateMutex(E_MSOS_FIFO, "EMMFLT_Mutex", MSOS_PROCESS_SHARED);
525 if (_s32EMMFLTMutexId < 0)
526 {
527 DRVEMM_DBG(EMM_DBGLV_ERR,"CreateMutex fail\n");
528 MsOS_DeleteEventGroup(_s32EMMFLTEventId);
529 return DRV_EMMFLT_FAIL;
530 }
531
532 _pEMMDFLTTaskStack = _u8EMMDFLT_StackBuffer;
533 _s32EMMDFLTTaskId = MsOS_CreateTask((TaskEntry)_MDrv_EMMDFLT_Isr_Proc,
534 (MS_U32)NULL,
535 E_TASK_PRI_HIGH,
536 TRUE,
537 _pEMMDFLTTaskStack,
538 EMMFLT_TASK_STACK_SIZE,
539 "EMMFLT_ISR_Task");
540 if (_s32EMMDFLTTaskId < 0)
541 {
542 DRVEMM_DBG(EMM_DBGLV_ERR,"CreateTask fail\n");
543 MsOS_DeleteEventGroup(_s32EMMFLTEventId);
544 MsOS_DeleteMutex(_s32EMMFLTMutexId);
545 return DRV_EMMFLT_FAIL;
546 }
547
548 _u8EmmIsInit = TRUE;
549 }
550 else
551 {
552 DRVEMM_DBG(EMM_DBGLV_INFO,"EMMFlt had been initialed\n");
553 }
554
555 for( i=0 ; i<EMMENG_NUMBER ; i++ )
556 {
557 bEmmOverflow[i] = FALSE;
558 }
559
560 HAL_EMMFLT_ReqDstBufSize(&pRequire->u32DstBufSize,&pRequire->u32AlignBytes,&pRequire->u8EMMNumber);
561
562 DRVEMM_DBG(EMM_DBGLV_INFO,"u32DstBufSize = %x , u32AlignBytes = %x\n",pRequire->u32DstBufSize,pRequire->u32AlignBytes);
563
564 return DRV_EMMFLT_OK;
565 }
566
MDrv_EMMFLT_Deinit(void)567 EMMFLT_RESULT MDrv_EMMFLT_Deinit(void)
568 {
569
570 DRVEMM_DBG(EMM_DBGLV_INFO,"MDrv_EMMFLT_Deinit\n");
571
572
573 //mask interrupt ...
574 HAL_EMMFLT_IntCtrl(1);
575
576 EMMFLTIntDetach();
577 EMMFLTIntDisable();
578
579 if (_s32EMMFLTEventId > 0)
580 {
581 MsOS_DeleteEventGroup(_s32EMMFLTEventId);
582 }
583
584 if (_s32EMMFLTMutexId > 0)
585 {
586 MsOS_DeleteMutex(_s32EMMFLTMutexId);
587 }
588
589 if (_s32EMMDFLTTaskId > 0)
590 {
591 MsOS_DeleteTask(_s32EMMDFLTTaskId);
592 }
593
594 return DRV_EMMFLT_OK;
595 }
596
MDrv_EMMFLT_SetNotify(EMMFLT_Notify Notify)597 EMMFLT_RESULT MDrv_EMMFLT_SetNotify(EMMFLT_Notify Notify)
598 {
599 _gEMMFltNtf = Notify;
600 return DRV_EMMFLT_OK;
601 }
602
MDrv_EMMFLT_GetHwBufCnt(MS_U32 * pHwBufCnt)603 EMMFLT_RESULT MDrv_EMMFLT_GetHwBufCnt(MS_U32 *pHwBufCnt)
604 {
605 return HAL_EMMFLT_GetHwBufCnt(pHwBufCnt);
606 }
607
MDrv_EMMFLT_SetDbgLevel(MS_U32 u32Level)608 EMMFLT_RESULT MDrv_EMMFLT_SetDbgLevel(MS_U32 u32Level)
609 {
610 _g32EMMDbgLv = u32Level;
611 DRVEMM_DBG(EMM_DBGLV_DEBUG, "%s level: %x\n", __FUNCTION__, u32Level);
612 HAL_EMMFLT_SetDbgLevel(u32Level);
613 return DRV_EMMFLT_OK;
614 }
615
MDrv_EMMFLT_SetDstBufInfo(MS_U32 x_connection,MS_U32 u32BufAddr,MS_U32 u32BufSize)616 EMMFLT_RESULT MDrv_EMMFLT_SetDstBufInfo(MS_U32 x_connection, MS_U32 u32BufAddr, MS_U32 u32BufSize)
617 {
618 HAL_EMMFLT_SetDstBufInfo(x_connection,u32BufAddr,u32BufSize,_gHWEMMBufAddr[x_connection]);
619 return DRV_EMMFLT_OK;
620 }
621
622
MDrv_EMMFLT_SetEmmPID(MS_U32 connection,MS_U16 u16EmmPID)623 EMMFLT_RESULT MDrv_EMMFLT_SetEmmPID(MS_U32 connection,MS_U16 u16EmmPID)
624 {
625 DRVEMM_DBG(EMM_DBGLV_DEBUG, "%s conn: %x, EmmPID = %x\n", __FUNCTION__, connection,u16EmmPID);
626 bEmmOverflow[connection] = FALSE;
627 return HAL_EMMFLT_SetEmmPID(connection,u16EmmPID);
628 }
629
MDrv_EMMFLT_SetTidMode(MS_U32 connection,MS_U8 u8TidValue,EMMDRV_TIDMODE_e eTIDMODE)630 EMMFLT_RESULT MDrv_EMMFLT_SetTidMode(MS_U32 connection, MS_U8 u8TidValue, EMMDRV_TIDMODE_e eTIDMODE)
631 {
632 DRVEMM_DBG(EMM_DBGLV_DEBUG, "%s conn: %x, TIDMODE = %d\n", __FUNCTION__, connection,eTIDMODE);
633 switch(eTIDMODE)
634 {
635 case EMM_TIDMODE_INGORE:
636 HAL_EMMFLT_SetTidMode(connection,(u8TidValue&0xf),E_TIDMODE_INGORE);
637 break;
638
639 case EMM_TIDMODE_ACCEPT_ALL:
640 HAL_EMMFLT_SetTidMode(connection,(u8TidValue&0xf),E_TIDMODE_ACCEPT_ALL);
641 break;
642
643 case EMM_TIDMODE_ACCEPT_ADDRESS:
644 HAL_EMMFLT_SetTidMode(connection,(u8TidValue&0xf),E_TIDMODE_ACCEPT_ADDRESS);
645 break;
646
647 default :
648 HAL_EMMFLT_SetTidMode(connection,(u8TidValue&0xf),E_TIDMODE_RESERVED);
649 break;
650 }
651
652 return DRV_EMMFLT_OK;
653 }
654
MDrv_EMMFLT_EnableEmmTID(MS_U32 connection,MS_BOOL bEnable)655 EMMFLT_RESULT MDrv_EMMFLT_EnableEmmTID(MS_U32 connection, MS_BOOL bEnable)
656 {
657 DRVEMM_DBG(EMM_DBGLV_DEBUG, "%s conn: %x, bEnable = %x\n", __FUNCTION__, connection,bEnable);
658 HAL_EMMFLT_SetEmmTID(connection,0x82);
659
660 HAL_EMMFLT_EnableEmmTID(connection,bEnable);
661
662 return DRV_EMMFLT_OK;
663 }
664
MDrv_EMMFLT_SetFilterCfg(MS_U32 connection,MS_U8 FilerIndex,EMM_FILTER_DEF_t * pFilter)665 EMMFLT_RESULT MDrv_EMMFLT_SetFilterCfg(MS_U32 connection, MS_U8 FilerIndex, EMM_FILTER_DEF_t *pFilter)
666 {
667 MS_U32 u32Status;
668 DRVEMM_DBG(EMM_DBGLV_DEBUG, "%s conn: %x, FilerIndex = %x\n", __FUNCTION__, connection,FilerIndex);
669
670 u32Status = HAL_EMMFLT_SetIRDMode(connection,FilerIndex,pFilter->filter_type);
671 StatusCheck(u32Status);
672
673 u32Status = HAL_EMMFLT_SetEmmDataIDx(connection,FilerIndex,pFilter->filter_address);
674 StatusCheck(u32Status);
675
676 u32Status = HAL_EMMFLT_SetEmmMaskIDx(connection,FilerIndex,pFilter->filter_address_mask);
677 StatusCheck(u32Status);
678
679 return DRV_EMMFLT_OK;
680 }
681
MDrv_EMMFLT_Fire(MS_U32 connection)682 EMMFLT_RESULT MDrv_EMMFLT_Fire(MS_U32 connection)
683 {
684 //fire EMM filter to wait stream...
685 DRVEMM_DBG(EMM_DBGLV_INFO, "%s conn: %x\n", __FUNCTION__, connection);
686 return HAL_EMMFLT_GeneralCtrl(connection);
687 }
688
689
MDrv_EMMFLT_StopEmm(MS_U32 x_connection)690 EMMFLT_RESULT MDrv_EMMFLT_StopEmm(MS_U32 x_connection)
691 {
692
693 DRVEMM_DBG(EMM_DBGLV_INFO,"MDrv_EMMFLT_StopEmm, x_connection = %x\n",x_connection);
694 HAL_EMMFLT_DisableEMM(x_connection);
695 //MDrv_EMMFLT_Deinit();
696 return DRV_EMMFLT_OK;
697 }
698
MDrv_EMMFLT_EmmProcessingFinished(MS_U8 * emm_buf)699 EMMFLT_RESULT MDrv_EMMFLT_EmmProcessingFinished(MS_U8 *emm_buf/* RPC SIZECONST(256) */)
700 {
701 DRVEMM_DBG(EMM_DBGLV_INFO,"free EMM %x\n", (MS_U32)emm_buf);
702
703 MS_U8 i,j, connection = 0xf;
704 EMMFLT_ENTRY(); // for disable interrupt protection
705
706 if(emm_buf != NULL)
707 {
708 for(j=0; j<EMMENG_NUMBER ; j++)
709 {
710 for(i=0; i<MAX_EMM_LIST_NUM ; i++)
711 {
712 if(_pu8BufAddrBackup[j][i] == emm_buf)
713 {
714 connection = j;
715 break;
716 }
717 }
718 }
719
720 if (connection==0xf)
721 {
722 EMMFLT_RETURN( DRV_EMMFLT_INVALID_REQUEST );
723 }
724
725 EMMFLTIntDisable();
726 //*(emm_buf) = 0;
727 //*(emm_buf-8) = 0;
728
729 if (_u8EmmRead[connection] != _u8EmmWrite[connection]) //patch,test,2014dec11. MDrv_EMMFLT_EmmProcessingFinished being called twice by verif_lib when theres single packet arrived
730 {
731 emmQueueDec(connection);
732 }
733
734 #if 1
735 bEmmOverflow[connection] = FALSE;
736 #else
737 if ( (bEmmOverflow[connection] == TRUE) && (emmQueueIsEmpty(connection)) )
738 {
739 bEmmOverflow[connection] = FALSE;
740 }
741 #endif
742 EMMFLTIntEnable();
743
744 DRVEMM_DBG(EMM_DBGLV_DEBUG,"%d (read, hold, write) = (%02d %02d %02d)\n", connection,_u8EmmRead[connection], _u8EmmHold[connection], _u8EmmWrite[connection]);
745 if (bEmmOverflow[connection] == TRUE)
746 {
747 DRVEMM_DBG(EMM_DBGLV_ERR,"%d o.flow (read, hold, write) = (%02d %02d %02d)\n", connection,_u8EmmRead[connection], _u8EmmHold[connection], _u8EmmWrite[connection]);
748 //DRVEMM_DBG(0,"free Emm %d %02x %02x\n", MsOS_GetSystemTime() - emm_overflow_time, *(emm_buf), *(emm_buf-8));
749 }
750
751 }
752 else
753 {
754 EMMFLT_RETURN( DRV_EMMFLT_INVALID_REQUEST );
755 }
756 EMMFLT_RETURN(DRV_EMMFLT_OK);
757 }
758
MDrv_EMMFLT_SetOutputType(MS_U32 x_connection,EMM_OUTTYPE_e eOutType)759 EMMFLT_RESULT MDrv_EMMFLT_SetOutputType(MS_U32 x_connection, EMM_OUTTYPE_e eOutType)
760 {
761 DRVEMM_DBG(EMM_DBGLV_INFO,"[%s]-[%d], conn = %x, OutType = %d\n", __FUNCTION__, __LINE__, x_connection, eOutType);
762 HAL_EMMFLT_SetOutputType(x_connection, eOutType);
763 return DRV_EMMFLT_OK;
764 }
765
MDrv_EMMFLT_SrcSelect(MS_U32 x_connection,MS_U32 u32SrcFrom,EMM_SRCTYPE_e eSrcType)766 EMMFLT_RESULT MDrv_EMMFLT_SrcSelect(MS_U32 x_connection, MS_U32 u32SrcFrom, EMM_SRCTYPE_e eSrcType)
767 {
768 DRVEMM_DBG(EMM_DBGLV_INFO,"[%s]-[%d], conn = %x, u32SrcFrom = %x, SrcType = %d\n", __FUNCTION__, __LINE__, x_connection, u32SrcFrom,eSrcType);
769 HAL_EMMFLT_SrcSelect(x_connection, u32SrcFrom, eSrcType);
770 return DRV_EMMFLT_OK;
771 }
772
MDrv_EMMFLT_ConnectCheck(MS_U32 connection)773 EMMFLT_RESULT MDrv_EMMFLT_ConnectCheck(MS_U32 connection)
774 {
775 return HAL_EMMFLT_ConnectCheck(connection);
776 }
777
778
MDrv_EMMFLT_SetExtendConfig(MS_U32 x_connection,MS_U16 type,MS_U16 extendbytes,MS_U16 syncbyte)779 EMMFLT_RESULT MDrv_EMMFLT_SetExtendConfig(MS_U32 x_connection, MS_U16 type, MS_U16 extendbytes, MS_U16 syncbyte)
780 {
781
782 printf("MDrv_EMMFLT_SetExtendConfig, x_connection = %x\n",x_connection);
783 HAL_EMMFLT_SetExtendConfig(x_connection, type, extendbytes, syncbyte);
784
785 return DRV_EMMFLT_OK;
786 }
787
MDrv_EMMFLT_InputMode(MS_U32 x_connection,MS_BOOL bSerial)788 EMMFLT_RESULT MDrv_EMMFLT_InputMode(MS_U32 x_connection, MS_BOOL bSerial)
789 {
790 DRVEMM_DBG(EMM_DBGLV_INFO,"[%s]-[%d], conn = %x, bSerial = %d\n", __FUNCTION__, __LINE__, x_connection, bSerial);
791 return HAL_EMMFLT_InputMode(x_connection, bSerial);
792 }
793
794
795