TWD/FW_Transfer/eventMbox.c
changeset 0 10c42ec6c05f
equal deleted inserted replaced
-1:000000000000 0:10c42ec6c05f
       
     1 /*
       
     2  * eventMbox.c
       
     3  *
       
     4  * Copyright(c) 1998 - 2010 Texas Instruments. All rights reserved.      
       
     5  * All rights reserved.      
       
     6  * 
       
     7  * This program and the accompanying materials are made available under the 
       
     8  * terms of the Eclipse Public License v1.0 or BSD License which accompanies
       
     9  * this distribution. The Eclipse Public License is available at
       
    10  * http://www.eclipse.org/legal/epl-v10.html and the BSD License is as below.                                   
       
    11  *                                                                       
       
    12  * Redistribution and use in source and binary forms, with or without    
       
    13  * modification, are permitted provided that the following conditions    
       
    14  * are met:                                                              
       
    15  *                                                                       
       
    16  *  * Redistributions of source code must retain the above copyright     
       
    17  *    notice, this list of conditions and the following disclaimer.      
       
    18  *  * Redistributions in binary form must reproduce the above copyright  
       
    19  *    notice, this list of conditions and the following disclaimer in    
       
    20  *    the documentation and/or other materials provided with the         
       
    21  *    distribution.                                                      
       
    22  *  * Neither the name Texas Instruments nor the names of its            
       
    23  *    contributors may be used to endorse or promote products derived    
       
    24  *    from this software without specific prior written permission.      
       
    25  *                                                                       
       
    26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   
       
    27  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     
       
    28  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
       
    29  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  
       
    30  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
       
    31  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      
       
    32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
       
    33  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
       
    34  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   
       
    35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
       
    36  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    37  */
       
    38 
       
    39 
       
    40 /** \file  eventMbox.c 
       
    41  *  \brief Handle any event interrupt from the FW
       
    42  *
       
    43  *  \see   
       
    44  */
       
    45 
       
    46 #define __FILE_ID__  FILE_ID_102
       
    47 #include "eventMbox_api.h"
       
    48 #include "TwIf.h"
       
    49 #include "osApi.h"
       
    50 #include "report.h"
       
    51 #include "CmdBld.h"
       
    52 #include "FwEvent_api.h"
       
    53 #include "TWDriver.h"
       
    54 #include "BusDrv.h"
       
    55 
       
    56 
       
    57 
       
    58 #define EVENT_MBOX_BUFFERS 2
       
    59 
       
    60 
       
    61 typedef enum
       
    62 {
       
    63     EVENT_MBOX_STATE_IDLE,
       
    64     EVENT_MBOX_STATE_READING
       
    65 } EEventMboxState;
       
    66 
       
    67 typedef struct {
       
    68 	void*		fCb;            /* Event Callback function */
       
    69 	TI_HANDLE	hCb;            /* Evant handle */
       
    70 	TI_UINT8*	pDataOffset;    /* Event Data Offset */
       
    71 	#ifdef TI_DBG
       
    72 	TI_UINT32	uCount;
       
    73 	#endif
       
    74 
       
    75 }TRegisteredEventCb;
       
    76 
       
    77 typedef struct 
       
    78 {
       
    79     TI_UINT32           bitMask;/* Event bit mask */
       
    80     char*               str;    /* Event trace string */
       
    81     TI_UINT8            dataLen;/* Event data length */  
       
    82 
       
    83 } TEventEntry;
       
    84 
       
    85 
       
    86 typedef struct
       
    87 {
       
    88 	TTxnStruct	tTxnReg;
       
    89 	TI_UINT8 	*pRegBuffer;
       
    90 
       
    91 } tTxnGenReg;
       
    92 
       
    93 
       
    94 typedef struct
       
    95 {
       
    96 	TTxnStruct		tEventMbox;
       
    97 	TI_UINT8    	*pEventMboxBuf;
       
    98 
       
    99 } tTxnEventMbox;
       
   100 
       
   101 
       
   102 
       
   103 typedef struct 
       
   104 {
       
   105 	TI_UINT32		   	EventMboxAddr[EVENT_MBOX_BUFFERS];  /* the Event Mbox addresses in the device */
       
   106 	TI_UINT8		   	ActiveMbox;                         /* The current active Mbox */
       
   107 	EEventMboxState		CurrentState;
       
   108     TRegisteredEventCb  CbTable[TWD_OWN_EVENT_MAX];         /* Callback table */
       
   109 
       
   110     /* Handles */
       
   111 	TI_HANDLE           hTwif;
       
   112     TI_HANDLE           hOs;
       
   113     TI_HANDLE           hReport;
       
   114     TI_HANDLE           hCmdBld;
       
   115 
       
   116 	/* HW params */
       
   117     /* use a struct to read or write register (4 byte size) from the bus */
       
   118 	tTxnGenReg			iTxnGenRegSize;
       
   119 
       
   120 	tTxnEventMbox		iTxnEventMbox;
       
   121 
       
   122 	#ifdef TI_DBG
       
   123 	TI_UINT32           uCompounEvCount;    /* Count the compound event */
       
   124 	TI_UINT32           uTotalEvCount;      /* Count total number of event sending in the compound */
       
   125 	#endif /* TI_DBG */
       
   126 	
       
   127 	fnotify_t			fCb;
       
   128 	TI_HANDLE		   	hCb;
       
   129 
       
   130 }TEventMbox;
       
   131 
       
   132 
       
   133 /********************************************************************************/
       
   134 /*                      Internal functions prototypes.                          */
       
   135 /********************************************************************************/
       
   136 
       
   137 static void eventMbox_ConfigCbTable(TI_HANDLE hEventMbox);
       
   138 static void eventMbox_ReadAddrCb(TI_HANDLE hEventMbox, TI_HANDLE hTxn);
       
   139 static void eventMbox_DummyCb(TI_HANDLE hEventMbox);
       
   140 static void eventMbox_ReadCompleteCB(TI_HANDLE hEventMbox, TTxnStruct *pTxnStruct);
       
   141 
       
   142 
       
   143 static const TEventEntry eventTable [TWD_OWN_EVENT_MAX] =
       
   144 {   
       
   145 /*==================================================================================
       
   146  *                                                                                     
       
   147  *                                    EVENT TABLE    
       
   148  *                                 
       
   149  *  Note that changes here should be reflected also in ETwdOwnEventId in TWDriver.h !!!
       
   150  *
       
   151  ===================================================================================
       
   152 | Id  |     Event Mask Bit                    |   Event String            | Length |
       
   153  ===================================================================================*/
       
   154 
       
   155 /* 0*/{ RSSI_SNR_TRIGGER_0_EVENT_ID,            "RSSI SNR TRIGGER 0 "     		, 1},
       
   156 /* 1*/{ RSSI_SNR_TRIGGER_1_EVENT_ID,            "RSSI SNR TRIGGER 1 "     		, 1},
       
   157 /* 2*/{ RSSI_SNR_TRIGGER_2_EVENT_ID,            "RSSI SNR TRIGGER 2 "     		, 1},
       
   158 /* 3*/{ RSSI_SNR_TRIGGER_3_EVENT_ID,            "RSSI SNR TRIGGER 3 "     		, 1},
       
   159 /* 4*/{ RSSI_SNR_TRIGGER_4_EVENT_ID,            "RSSI SNR TRIGGER 4 "     		, 1},
       
   160 /* 5*/{ RSSI_SNR_TRIGGER_5_EVENT_ID,            "RSSI SNR TRIGGER 5 "     		, 1},
       
   161 /* 6*/{ RSSI_SNR_TRIGGER_6_EVENT_ID,            "RSSI SNR TRIGGER 6 "     		, 1},
       
   162 /* 7*/{ RSSI_SNR_TRIGGER_7_EVENT_ID,            "RSSI SNR TRIGGER 7 "     		, 1},
       
   163 /* 8*/{ MEASUREMENT_START_EVENT_ID,             "MEASUREMENT START "      		, 0},    
       
   164 /* 9*/{ MEASUREMENT_COMPLETE_EVENT_ID,          "BSS LOSE "               		, 0},
       
   165 /*10*/{ SCAN_COMPLETE_EVENT_ID ,                "SCAN CMPLT "             		, 8},    
       
   166 /*11*/{ SCHEDULED_SCAN_COMPLETE_EVENT_ID,       "SPS SCAN CMPLT "         		, 3},
       
   167 /*12*/{ AP_DISCOVERY_COMPLETE_EVENT_ID,         "MAX TX RETRY "           		, 0},
       
   168 /*13*/{ PS_REPORT_EVENT_ID,                     "PS_REPORT "              		, 1},
       
   169 /*14*/{ PSPOLL_DELIVERY_FAILURE_EVENT_ID,       "PS-POLL DELIVERY FAILURE"		, 0},
       
   170 /*15*/{ DISCONNECT_EVENT_COMPLETE_ID,           "DISCONNECT COMPLETE "    		, 0},
       
   171 /*16*/{ JOIN_EVENT_COMPLETE_ID,                 "JOIN CMPLT "             		, 0},
       
   172 /*17*/{ CHANNEL_SWITCH_COMPLETE_EVENT_ID,       "SWITCH CHANNEL CMPLT "   		, 0},
       
   173 /*18*/{ BSS_LOSE_EVENT_ID,                      "BSS LOST "               		, 0},
       
   174 /*19*/{ REGAINED_BSS_EVENT_ID,                  "REGAINED BSS "           		, 0},
       
   175 /*20*/{ ROAMING_TRIGGER_MAX_TX_RETRY_EVENT_ID,  "MAX TX RETRY "           		, 0},
       
   176 /*21*/{ BIT_21,									"RESERVED"				  		, 0},
       
   177 /*22*/{ SOFT_GEMINI_SENSE_EVENT_ID,             "SOFT GEMINI SENSE "      		, 1},
       
   178 /*23*/{ SOFT_GEMINI_PREDICTION_EVENT_ID,        "SOFT GEMINI PREDICTION " 		, 1},
       
   179 /*24*/{ SOFT_GEMINI_AVALANCHE_EVENT_ID,         "SOFT GEMINI AVALANCHE "  		, 0},
       
   180 /*25*/{ PLT_RX_CALIBRATION_COMPLETE_EVENT_ID,   "PLT RX CALIBR. COMPLETE "		, 0},
       
   181 /*26*/{ DBG_EVENT_ID,							"DBG_EVENT_ID "			  		, 16},
       
   182 /*27*/{ HEALTH_CHECK_REPLY_EVENT_ID,			"HEALTH_CHECK_REPLY_EVENT_ID"	, 0},
       
   183 /*28*/{ PERIODIC_SCAN_COMPLETE_EVENT_ID,        "PERIODIC SCAN COMPLETE " 		, 8},
       
   184 /*29*/{ PERIODIC_SCAN_REPORT_EVENT_ID,          "PERIODIC SCAN REPORT "   		, 8},
       
   185 /*30*/{ BA_SESSION_TEAR_DOWN_EVENT_ID,			"BA_SESSION_TEAR_DOWN_EVENT_ID"	, 0},
       
   186 /*31*/{ EVENT_MBOX_ALL_EVENT_ID,                "ALL EVENTS "             		, 0}
       
   187 };
       
   188 
       
   189 
       
   190 /*
       
   191  * \brief	Create the Bus Access mailbox object
       
   192  * 
       
   193  * \param  hOs - OS Handle
       
   194  * \returnThe Created object
       
   195  *
       
   196  * \sa 
       
   197  */
       
   198 
       
   199 TI_HANDLE eventMbox_Create(TI_HANDLE hOs)
       
   200 {
       
   201     TEventMbox *pEventMbox;
       
   202 	pEventMbox = (TEventMbox*)os_memoryAlloc(hOs,sizeof(TEventMbox),MemoryNormal);
       
   203     if (pEventMbox == NULL)
       
   204     {
       
   205         WLAN_OS_REPORT (("eventMbox_Create: Error creating EventMbox object\n"));
       
   206         return NULL;
       
   207     }
       
   208     os_memoryZero (hOs, pEventMbox, sizeof(TEventMbox));
       
   209 
       
   210     /* Allocate the MBOX Buffer */
       
   211     pEventMbox->iTxnEventMbox.pEventMboxBuf = os_memoryAlloc (hOs, sizeof (EventMailBox_t) + WSPI_PAD_LEN_READ,MemoryDMA);
       
   212     if (pEventMbox->iTxnEventMbox.pEventMboxBuf == NULL) 
       
   213     {
       
   214         return NULL;
       
   215     }
       
   216     os_memoryZero (hOs, pEventMbox->iTxnEventMbox.pEventMboxBuf, sizeof (EventMailBox_t) + WSPI_PAD_LEN_READ);
       
   217     pEventMbox->iTxnEventMbox.pEventMboxBuf += WSPI_PAD_LEN_READ;
       
   218 
       
   219     /* Allocate the Register buffer */
       
   220     pEventMbox->iTxnGenRegSize.pRegBuffer = os_memoryAlloc (hOs, sizeof (TI_UINT32) + WSPI_PAD_LEN_READ,MemoryDMA);
       
   221     if (pEventMbox->iTxnGenRegSize.pRegBuffer == NULL) 
       
   222     {
       
   223         return NULL;
       
   224     }
       
   225     os_memoryZero (hOs, pEventMbox->iTxnGenRegSize.pRegBuffer, sizeof (TI_UINT32) + WSPI_PAD_LEN_READ);
       
   226     pEventMbox->iTxnGenRegSize.pRegBuffer += WSPI_PAD_LEN_READ;
       
   227 
       
   228     pEventMbox->hOs = hOs;
       
   229     ((EventMailBox_t*)(pEventMbox->iTxnEventMbox.pEventMboxBuf))->eventsMask = EVENT_MBOX_ALL_EVENT_ID;
       
   230     return (TI_HANDLE)pEventMbox;
       
   231 }
       
   232 
       
   233 
       
   234 /*
       
   235  * \brief	Release all memory resource of EventMbox
       
   236  * 
       
   237  * \param  hEventMbox  - Handle to EventMbox
       
   238  * \return none
       
   239  * 
       
   240  * \par Description
       
   241  * This function should called after all interrupts was disabled.
       
   242  *
       
   243  * \sa 
       
   244  */
       
   245 void eventMbox_Destroy(TI_HANDLE hEventMbox)
       
   246 {
       
   247     TEventMbox *pEventMbox = (TEventMbox *)hEventMbox;
       
   248 
       
   249     if (pEventMbox->iTxnEventMbox.pEventMboxBuf) 
       
   250     {
       
   251         os_memoryFree (pEventMbox->hOs, pEventMbox->iTxnEventMbox.pEventMboxBuf - WSPI_PAD_LEN_READ, sizeof (EventMailBox_t) + WSPI_PAD_LEN_READ);
       
   252     }
       
   253 
       
   254     if (pEventMbox->iTxnGenRegSize.pRegBuffer)
       
   255     {
       
   256         os_memoryFree (pEventMbox->hOs, pEventMbox->iTxnGenRegSize.pRegBuffer - WSPI_PAD_LEN_READ, sizeof (TI_UINT32) + WSPI_PAD_LEN_READ);
       
   257     }
       
   258 
       
   259     if (pEventMbox)
       
   260     {
       
   261         os_memoryFree (pEventMbox->hOs, pEventMbox, sizeof(TEventMbox));
       
   262     }
       
   263 }
       
   264 
       
   265 
       
   266 
       
   267 /*
       
   268  * \brief	Stop the EventMbox clear state and event vector
       
   269  * 
       
   270  * \param  hEventMbox  - Handle to EventMbox
       
   271  * \return none
       
   272  * 
       
   273  * \par Description
       
   274  * This function should called to stop the EventMb.
       
   275  * Do Not clear the mask Event could use us again when restart/recovery!!!!
       
   276  * \sa 
       
   277  */
       
   278 void eventMbox_Stop(TI_HANDLE hEventMbox)
       
   279 {
       
   280 	TEventMbox* pEventMbox 									= (TEventMbox*)hEventMbox;
       
   281 	pEventMbox->ActiveMbox									= 0;
       
   282 	pEventMbox->CurrentState								= EVENT_MBOX_STATE_IDLE;
       
   283 	((EventMailBox_t*)(pEventMbox->iTxnEventMbox.pEventMboxBuf))->eventsVector	= 0;
       
   284 }
       
   285 
       
   286 
       
   287 
       
   288 /*
       
   289  * \brief	Configure the object
       
   290  * 
       
   291  * \param  hEventMbox  - Handle to EventMbox
       
   292  * \param  hTwif	   - Handle to TWIF
       
   293  * \param  hReport	   - Handle to Report module
       
   294  * \param  hFwEvent    - Handle to FW Event module
       
   295  * \param  hCmdBld     - Handle to Command Build module
       
   296  * \return none
       
   297  *
       
   298  * \par Description
       
   299  * This function should called to configure the module.
       
   300  * \sa 
       
   301  */
       
   302 
       
   303 void eventMbox_Config(TI_HANDLE hEventMbox, 
       
   304                             TI_HANDLE hTwif, 
       
   305                             TI_HANDLE hReport,    
       
   306                             TI_HANDLE hFwEvent, 
       
   307                             TI_HANDLE hCmdBld)
       
   308 {
       
   309     TEventMbox *pEventMbox = (TEventMbox *)hEventMbox;
       
   310 	pEventMbox->hTwif			= hTwif;
       
   311     pEventMbox->hReport = hReport;
       
   312     pEventMbox->hCmdBld = hCmdBld;
       
   313 	pEventMbox->ActiveMbox		= 0;
       
   314 	pEventMbox->CurrentState	= EVENT_MBOX_STATE_IDLE;
       
   315 #ifdef TI_DBG
       
   316 	pEventMbox->uCompounEvCount	= 0;
       
   317 	pEventMbox->uTotalEvCount	= 0;
       
   318 #endif
       
   319 	eventMbox_ConfigCbTable(pEventMbox);
       
   320 }
       
   321 
       
   322 
       
   323 
       
   324 /* 
       
   325  * \brief	Initialization of callback table
       
   326  * 
       
   327  * \param  hEventMbox  - Handle to EventMbox
       
   328  * \return none
       
   329  * 
       
   330  * \par Description
       
   331  * This function is called to configure the CB table initialize the
       
   332  * CB functions and handle and set the Data offset.
       
   333  * 
       
   334  * \sa 
       
   335  */
       
   336 static void eventMbox_ConfigCbTable(TI_HANDLE hEventMbox)
       
   337 {
       
   338 	TEventMbox* pEventMbox;
       
   339 	TI_UINT8	EvID;
       
   340 	
       
   341 	pEventMbox = (TEventMbox*)hEventMbox;
       
   342 
       
   343 	/* for all events set a dummy func and data offset */
       
   344 	for (EvID = 0; EvID < TWD_OWN_EVENT_MAX;EvID++)
       
   345 	{
       
   346 		pEventMbox->CbTable[EvID].pDataOffset = pEventMbox->iTxnEventMbox.pEventMboxBuf;
       
   347 		pEventMbox->CbTable[EvID].fCb		  = (void*)eventMbox_DummyCb;
       
   348 		pEventMbox->CbTable[EvID].hCb		  = pEventMbox;
       
   349 	}
       
   350 	/* set the data offset for Events with data only */
       
   351 	for (EvID = 0;EvID < NUM_OF_RSSI_SNR_TRIGGERS;EvID++)
       
   352 	{
       
   353 		pEventMbox->CbTable[EvID].pDataOffset += TI_FIELD_OFFSET (EventMailBox_t, RSSISNRTriggerMetric[EvID]);
       
   354 	}
       
   355 	pEventMbox->CbTable[TWD_DBG_EVENT                       ].pDataOffset += TI_FIELD_OFFSET (EventMailBox_t, dbgEventRep);
       
   356 	pEventMbox->CbTable[TWD_OWN_EVENT_SCAN_CMPLT            ].pDataOffset += TI_FIELD_OFFSET (EventMailBox_t,scanCompleteResults);
       
   357 	pEventMbox->CbTable[TWD_OWN_EVENT_SPS_SCAN_CMPLT        ].pDataOffset += TI_FIELD_OFFSET (EventMailBox_t,scheduledScanAttendedChannels);
       
   358     pEventMbox->CbTable[TWD_OWN_EVENT_PERIODIC_SCAN_COMPLETE].pDataOffset += TI_FIELD_OFFSET (EventMailBox_t, scanCompleteResults);
       
   359     pEventMbox->CbTable[TWD_OWN_EVENT_PERIODIC_SCAN_REPORT  ].pDataOffset += TI_FIELD_OFFSET (EventMailBox_t, scanCompleteResults);
       
   360 	pEventMbox->CbTable[TWD_OWN_EVENT_SOFT_GEMINI_SENSE     ].pDataOffset += TI_FIELD_OFFSET (EventMailBox_t,softGeminiSenseInfo);
       
   361 	pEventMbox->CbTable[TWD_OWN_EVENT_SOFT_GEMINI_PREDIC    ].pDataOffset += TI_FIELD_OFFSET (EventMailBox_t,softGeminiProtectiveInfo);
       
   362 	pEventMbox->CbTable[TWD_OWN_EVENT_SWITCH_CHANNEL_CMPLT  ].pDataOffset += TI_FIELD_OFFSET (EventMailBox_t,channelSwitchStatus);
       
   363 	pEventMbox->CbTable[TWD_OWN_EVENT_PS_REPORT             ].pDataOffset += TI_FIELD_OFFSET (EventMailBox_t,psStatus);
       
   364 }
       
   365     
       
   366 
       
   367 
       
   368 static void eventMbox_DummyCb(TI_HANDLE hEventMbox)
       
   369 {
       
   370 	TEventMbox* pEventMbox = (TEventMbox*)hEventMbox;
       
   371 TRACE0(pEventMbox->hReport, REPORT_SEVERITY_ERROR, "eventMbox_DummyCb : Called for unregistered event");
       
   372 }
       
   373 
       
   374 
       
   375 /*
       
   376  * \brief	Read mailbox address
       
   377  * 
       
   378  * \param  hEventMbox  - Handle to EventMbox
       
   379  * \param  fCb		   - CB function to return in Async mode
       
   380  * \param  hCb		   - CB Habdle 
       
   381  * \return TXN_STATUS_COMPLETE, TXN_STATUS_PENDING, TXN_STATUS_ERROR
       
   382  * 
       
   383  * \par Description
       
   384  * This function is called for initialize the Event MBOX addresses.
       
   385  * It issues a read transaction from the Twif with a CB.
       
   386  * 
       
   387  * \sa 
       
   388  */
       
   389 TI_STATUS eventMbox_InitMboxAddr(TI_HANDLE hEventMbox, fnotify_t fCb, TI_HANDLE hCb)
       
   390 {
       
   391 	TTxnStruct  *pTxn;
       
   392 	TEventMbox* pEventMbox;
       
   393 	ETxnStatus  rc;
       
   394 	pEventMbox = (TEventMbox*)hEventMbox;
       
   395 	pTxn = &pEventMbox->iTxnGenRegSize.tTxnReg;
       
   396 
       
   397 	/* Store the Callabck address of the modules that called us in case of Asynchronuous transaction that will complete later */
       
   398 	pEventMbox->fCb = fCb;
       
   399     pEventMbox->hCb = hCb;
       
   400 
       
   401 	/* Build the command TxnStruct */
       
   402     TXN_PARAM_SET(pTxn, TXN_LOW_PRIORITY, TXN_FUNC_ID_WLAN, TXN_DIRECTION_READ, TXN_INC_ADDR)
       
   403 	/* Applying a CB in case of an async read */
       
   404     BUILD_TTxnStruct(pTxn, REG_EVENT_MAILBOX_PTR, pEventMbox->iTxnGenRegSize.pRegBuffer, REGISTER_SIZE, eventMbox_ReadAddrCb, hEventMbox)
       
   405 	rc = twIf_Transact(pEventMbox->hTwif,pTxn);
       
   406 	if (rc == TXN_STATUS_COMPLETE)
       
   407 	{
       
   408 		pEventMbox->EventMboxAddr[0] = *((TI_UINT32*)(pEventMbox->iTxnGenRegSize.pRegBuffer));
       
   409 		pEventMbox->EventMboxAddr[1] = pEventMbox->EventMboxAddr[0] + sizeof(EventMailBox_t);
       
   410 		
       
   411                 TRACE3(pEventMbox->hReport, REPORT_SEVERITY_INIT , "eventMbox_ConfigHw: event A Address=0x%x, event B Address=0x%x, sizeof=%d\n", pEventMbox->EventMboxAddr[0], pEventMbox->EventMboxAddr[1], sizeof(EventMailBox_t));
       
   412 
       
   413 	}
       
   414 	return rc;
       
   415 }
       
   416 
       
   417 
       
   418 /*
       
   419  * \brief	Save the Event MBOX addresses
       
   420  * 
       
   421  * \param  hEventMbox  - Handle to EventMbox
       
   422  * \param  hTxn		   - Handle to TTxnStruct
       
   423  * \return none
       
   424  * 
       
   425  * \par Description
       
   426  * This function is called upon completion of thr read Event MBOX address register.
       
   427  * It save the addresses in EventMbox.
       
   428  * 
       
   429  * \sa 
       
   430  */
       
   431 static void eventMbox_ReadAddrCb(TI_HANDLE hEventMbox, TI_HANDLE hTxn)
       
   432 {
       
   433     TEventMbox* pEventMbox;
       
   434 	
       
   435 	pEventMbox = (TEventMbox*)hEventMbox;
       
   436 
       
   437 	pEventMbox->EventMboxAddr[0] = *((TI_UINT32*)(pEventMbox->iTxnGenRegSize.pRegBuffer));
       
   438 	pEventMbox->EventMboxAddr[1] = pEventMbox->EventMboxAddr[0] + sizeof(EventMailBox_t);
       
   439  
       
   440     TRACE3(pEventMbox->hReport, REPORT_SEVERITY_INIT , "eventMbox_ConfigHw: event A Address=0x%x, event B Address=0x%x, sizeof=%d\n", pEventMbox->EventMboxAddr[0], pEventMbox->EventMboxAddr[1], sizeof(EventMailBox_t));
       
   441 
       
   442 	/* call back the module that called us before to read our self-address */
       
   443 	pEventMbox->fCb(pEventMbox->hCb,TI_OK);
       
   444 }
       
   445 
       
   446 
       
   447 /*
       
   448  * \brief	confige the Mask vector in FW 
       
   449  * 
       
   450  * \param  hEventMbox  - Handle to EventMbox
       
   451  * \return none
       
   452  * 
       
   453  * \par Description
       
   454  * This function is called upon exit from init it will set the mask vector.
       
   455  * this function is mostly use for recovery
       
   456  * Note that at Init stage the FW is already configured to have all events masked but at Recovery stage 
       
   457  * The driver whishes to just set back previous event mask configuration
       
   458  * 
       
   459  * \sa 
       
   460  */
       
   461 void eventMbox_InitComplete(TI_HANDLE hEventMbox)
       
   462 {
       
   463 
       
   464     TEventMbox* pEventMbox;
       
   465 	pEventMbox = (TEventMbox*)hEventMbox;
       
   466 	
       
   467     TRACE1(pEventMbox->hReport, REPORT_SEVERITY_INFORMATION, "eventMbox_InitComplete: mask = 0x%x\n", ((EventMailBox_t*)(pEventMbox->iTxnEventMbox.pEventMboxBuf))->eventsMask);
       
   468 
       
   469 	cmdBld_CfgEventMask(pEventMbox->hCmdBld,((EventMailBox_t*)(pEventMbox->iTxnEventMbox.pEventMboxBuf))->eventsMask,NULL,NULL);
       
   470 }
       
   471     
       
   472 
       
   473 
       
   474 /*
       
   475  * \brief	Register an event 
       
   476  * 
       
   477  * \param  hEventMbox  - Handle to EventMbox
       
   478  * \param  EvID - the event ID to register
       
   479  * \param  fCb - CB function of the registered event
       
   480  * \param  hCb - CB handle of the registered event
       
   481  * \return TI_OK,TI_NOK
       
   482  *
       
   483  * \par Description
       
   484  * This function is called from the user upon request to register for event.
       
   485  * an Event can only be register to one user.
       
   486  * This function doesn't change the mask vector in FW!!!
       
   487  * 
       
   488  * \sa 
       
   489  */
       
   490 TI_STATUS eventMbox_RegisterEvent(TI_HANDLE hEventMbox,TI_UINT32 EvID,void* fCb,TI_HANDLE hCb)
       
   491 {
       
   492     TEventMbox *pEventMbox = (TEventMbox *)hEventMbox;
       
   493     if (fCb == NULL || hCb == NULL)
       
   494     { 
       
   495 TRACE0(pEventMbox->hReport, REPORT_SEVERITY_ERROR, "eventMbox_RegisterEvent : NULL parameters\n");
       
   496         return TI_NOK;
       
   497     }
       
   498     if (EvID >= TWD_OWN_EVENT_ALL)
       
   499     {
       
   500 TRACE0(pEventMbox->hReport, REPORT_SEVERITY_ERROR, "eventMbox_RegisterEvent : Event ID invalid\n");
       
   501 		return TI_NOK;
       
   502     }
       
   503 	pEventMbox->CbTable[EvID].fCb = fCb;
       
   504 	pEventMbox->CbTable[EvID].hCb = hCb;
       
   505 	return TI_OK;
       
   506 }
       
   507 
       
   508 
       
   509 
       
   510 
       
   511 /*
       
   512  * \brief	Replace event callback 
       
   513  * 
       
   514  * \param  hEventMbox  - Handle to EventMbox
       
   515  * \param  EvID - the event ID to register
       
   516  * \param  fNewCb - the new CB function of the registered event
       
   517  * \param  hNewCb - the new CB handle of the registered event
       
   518  * \param  pPrevCb - the old CB to save
       
   519  * \param  pPrevHndl - the old handle to save
       
   520  * \return TI_OK,TI_NOK
       
   521  * 
       
   522  * \par Description
       
   523  * Replace event callback function by another one.
       
   524  *              Provide the previous CB to the caller.
       
   525  *
       
   526  * \sa 
       
   527  */
       
   528 TI_STATUS eventMbox_ReplaceEvent (TI_HANDLE hEventMbox,
       
   529                                     TI_UINT32   EvID, 
       
   530                                     void       *fNewCb, 
       
   531                                     TI_HANDLE   hNewCb,                                   
       
   532                                     void      **pPrevCb, 
       
   533                                     TI_HANDLE  *pPrevHndl)                                    
       
   534 {
       
   535     TEventMbox *pEventMbox = (TEventMbox *)hEventMbox;
       
   536     if (fNewCb == NULL || hNewCb == NULL)
       
   537     { 
       
   538 TRACE0(pEventMbox->hReport, REPORT_SEVERITY_ERROR , "eventMbox_ReplaceEvent: NULL parameters\n");
       
   539         return TI_NOK;
       
   540     }
       
   541     if (EvID >= TWD_OWN_EVENT_ALL)
       
   542     {
       
   543 TRACE1(pEventMbox->hReport, REPORT_SEVERITY_ERROR, "eventMbox_ReplaceEvent: invalid ID. ID is %d\n", EvID);
       
   544         return TI_NOK;
       
   545     }
       
   546 
       
   547 	/* Save the old CBs */
       
   548 	*pPrevCb   = pEventMbox->CbTable[EvID].fCb;
       
   549 	*pPrevHndl = pEventMbox->CbTable[EvID].hCb;
       
   550 
       
   551 	/* store the new CBs */
       
   552 	pEventMbox->CbTable[EvID].fCb = fNewCb;
       
   553 	pEventMbox->CbTable[EvID].hCb = hNewCb;
       
   554 
       
   555     TRACE0(pEventMbox->hReport, REPORT_SEVERITY_INFORMATION, "eventMbox_ReplaceEvent: EVENT  has registered\n");
       
   556 	return TI_OK;
       
   557 }
       
   558 
       
   559 
       
   560 /*
       
   561  * \brief	Un mask an event
       
   562  * 
       
   563  * \param  hEventMbox  - Handle to EventMbox
       
   564  * \param  EvID - the event ID to un mask
       
   565  * \param  fCb - CB function
       
   566  * \param  hCb - CB handle
       
   567  * \return TI_COMPLETE,TI_PENDING,TI_ERROR
       
   568  *
       
   569  * \par Description
       
   570  * This function is called from the user upon request to un mask an event.
       
   571  * This function change the mask vector in FW but doesn't register for it in the driver and 
       
   572  * doesn't set Cb function and Cb Handle in case of un mask event without registered for it an 
       
   573  * error will be handling!!!
       
   574  * 
       
   575  * \sa 
       
   576  */
       
   577 TI_STATUS eventMbox_UnMaskEvent(TI_HANDLE hEventMbox,TI_UINT32 EvID,void* fCb,TI_HANDLE hCb)
       
   578 {
       
   579 	TI_UINT32*	pEventMask;
       
   580 	TI_STATUS	aStatus;
       
   581     TEventMbox *pEventMbox = (TEventMbox *)hEventMbox;
       
   582 	pEventMask = (TI_UINT32*)&((EventMailBox_t*)(pEventMbox->iTxnEventMbox.pEventMboxBuf))->eventsMask;
       
   583 
       
   584     if (EvID >= TWD_OWN_EVENT_ALL)
       
   585     {
       
   586 TRACE1(pEventMbox->hReport, REPORT_SEVERITY_ERROR, "eventMbox_UnMaskEvent : Un mask an Invalid event = 0x%x\n",EvID);
       
   587 		return TXN_STATUS_ERROR;
       
   588     }
       
   589 TRACE0(pEventMbox->hReport, REPORT_SEVERITY_INFORMATION, "eventMbox_UnMaskEvent : EVENT  is unmasked\n");
       
   590 
       
   591 	*pEventMask &= ~eventTable[EvID].bitMask;
       
   592 
       
   593 	aStatus = cmdBld_CfgEventMask (pEventMbox->hCmdBld, *pEventMask, fCb, hCb);
       
   594 	return aStatus;
       
   595 }
       
   596 
       
   597 
       
   598 /*
       
   599  * \brief	mask an event
       
   600  *
       
   601  * \param  hEventMbox  - Handle to EventMbox
       
   602  * \param  EvID - the event ID to un mask
       
   603  * \param  fCb - CB function
       
   604  * \param  hCb - CB handle
       
   605  * \return TI_COMPLETE,TI_PENDING,TI_ERROR
       
   606  * 
       
   607  * \par Description
       
   608  * This function is called from the user upon request to mask an event.
       
   609  * This function change the mask vector in FW but doesn't unregister it in the driver. 
       
   610  * \sa 
       
   611  */
       
   612 TI_STATUS eventMbox_MaskEvent(TI_HANDLE hEventMbox,TI_UINT32 EvID,void* fCb,TI_HANDLE hCb)
       
   613 {
       
   614 	TI_UINT32*	pEventMask;
       
   615 	TI_STATUS	aStatus;
       
   616     TEventMbox *pEventMbox = (TEventMbox *)hEventMbox;
       
   617 	pEventMask = (TI_UINT32*)&((EventMailBox_t*)(pEventMbox->iTxnEventMbox.pEventMboxBuf))->eventsMask;
       
   618     
       
   619     if (EvID >= TWD_OWN_EVENT_ALL)
       
   620     {
       
   621 TRACE1(pEventMbox->hReport, REPORT_SEVERITY_ERROR, "eventMbox_MaskEvent : Mask an Invalid event = 0x%x\n",EvID);
       
   622 		return TXN_STATUS_ERROR;
       
   623     }
       
   624 
       
   625 	*pEventMask |= eventTable[EvID].bitMask;
       
   626 
       
   627     TRACE0(pEventMbox->hReport, REPORT_SEVERITY_INFORMATION , "eventMbox_MaskEvent : EVENT  is masked\n");
       
   628 
       
   629 	aStatus = cmdBld_CfgEventMask(pEventMbox->hCmdBld,*pEventMask,fCb,hCb);
       
   630 	return aStatus;
       
   631 }
       
   632 
       
   633 
       
   634 
       
   635 /*
       
   636  * \brief	Handle the incoming event read the Mbox data
       
   637  * 
       
   638  * \param  hEventMbox  - Handle to EventMbox
       
   639  * \param  TFwStatus  - FW status
       
   640  * \return none
       
   641  *
       
   642  * \par Description
       
   643  * This function is called from the FW Event upon receiving MBOX event.
       
   644  * \sa 
       
   645  */
       
   646 void eventMbox_Handle(TI_HANDLE hEventMbox,FwStatus_t* pFwStatus)
       
   647 {
       
   648 	ETxnStatus	rc;
       
   649 	TTxnStruct  *pTxn;
       
   650     TEventMbox *pEventMbox = (TEventMbox *)hEventMbox;
       
   651 
       
   652 	pTxn = &pEventMbox->iTxnEventMbox.tEventMbox;
       
   653 
       
   654 TRACE1(pEventMbox->hReport, REPORT_SEVERITY_INFORMATION, "eventMbox_Handle : Reading from MBOX -- %d",pEventMbox->ActiveMbox);
       
   655 
       
   656 #ifdef TI_DBG
       
   657     /* Check if missmatch MBOX */
       
   658 	if (pEventMbox->ActiveMbox == 0)
       
   659     {
       
   660     	if (pFwStatus->intrStatus & ACX_INTR_EVENT_B)
       
   661         {
       
   662         TRACE0(pEventMbox->hReport, REPORT_SEVERITY_ERROR, "eventMbox_Handle : incorrect MBOX SW MBOX -- A FW MBOX -- B");
       
   663         }
       
   664     }
       
   665 	else if (pEventMbox->ActiveMbox == 1)
       
   666     {
       
   667         if (pFwStatus->intrStatus & ACX_INTR_EVENT_A)
       
   668         {
       
   669             TRACE0(pEventMbox->hReport, REPORT_SEVERITY_ERROR, "eventMbox_Handle : incorrect MBOX SW MBOX -- B FW MBOX -- A");
       
   670         }
       
   671     }
       
   672 #endif /* TI_DBG */
       
   673     
       
   674 	if (pEventMbox->CurrentState != EVENT_MBOX_STATE_IDLE)
       
   675 	{
       
   676 TRACE0(pEventMbox->hReport, REPORT_SEVERITY_ERROR, "eventMbox_Handle : Receiving event not in Idle state");
       
   677     }
       
   678 	pEventMbox->CurrentState = EVENT_MBOX_STATE_READING;
       
   679 
       
   680 	/* Build the command TxnStruct */
       
   681     TXN_PARAM_SET(pTxn, TXN_LOW_PRIORITY, TXN_FUNC_ID_WLAN, TXN_DIRECTION_READ, TXN_INC_ADDR)
       
   682 	/* Applying a CB in case of an async read */
       
   683     BUILD_TTxnStruct(pTxn, pEventMbox->EventMboxAddr[pEventMbox->ActiveMbox], pEventMbox->iTxnEventMbox.pEventMboxBuf, sizeof(EventMailBox_t),(TTxnDoneCb)eventMbox_ReadCompleteCB, pEventMbox)
       
   684 	rc = twIf_Transact(pEventMbox->hTwif,pTxn);
       
   685 
       
   686 	pEventMbox->ActiveMbox = 1 - pEventMbox->ActiveMbox;
       
   687 	if (rc == TXN_STATUS_COMPLETE)
       
   688     {   
       
   689 		eventMbox_ReadCompleteCB(pEventMbox,pTxn);
       
   690     }
       
   691 }
       
   692 
       
   693 
       
   694 /*
       
   695  * \brief	Process the event 
       
   696  *
       
   697  * \param  hEventMbox  - Handle to EventMbox
       
   698  * \param  pTxnStruct  - the Txn data
       
   699  * \return none
       
   700  * 
       
   701  * \par Description
       
   702  * This function is called from the upon reading completion of the event MBOX
       
   703  * it will call all registered event according to the pending bits in event MBOX vector.
       
   704  * \sa 
       
   705  */
       
   706 static void eventMbox_ReadCompleteCB(TI_HANDLE hEventMbox, TTxnStruct *pTxnStruct)
       
   707 {
       
   708 	TI_UINT32	EvID;
       
   709 	TTxnStruct*	pTxn;
       
   710     TEventMbox *pEventMbox = (TEventMbox *)hEventMbox;
       
   711 	pTxn = &pEventMbox->iTxnGenRegSize.tTxnReg;
       
   712 
       
   713 TRACE1(pEventMbox->hReport, REPORT_SEVERITY_INFORMATION, "eventMbox_ReadCompleteCB : event vector -- 0x%x\n",((EventMailBox_t*)(pEventMbox->iTxnEventMbox.pEventMboxBuf))->eventsVector);
       
   714     
       
   715 	*((TI_UINT32*)(pEventMbox->iTxnGenRegSize.pRegBuffer)) = INTR_TRIG_EVENT_ACK;
       
   716 
       
   717     for (EvID = 0; EvID < TWD_OWN_EVENT_ALL; EvID++)
       
   718     {
       
   719         if (((EventMailBox_t*)(pEventMbox->iTxnEventMbox.pEventMboxBuf))->eventsVector & eventTable[EvID].bitMask)
       
   720                 {                  
       
   721                     if (eventTable[EvID].dataLen)
       
   722                     {
       
   723                 ((TEventMboxDataCb)pEventMbox->CbTable[EvID].fCb)(pEventMbox->CbTable[EvID].hCb,(TI_CHAR*)pEventMbox->CbTable[EvID].pDataOffset,eventTable[EvID].dataLen);
       
   724             }
       
   725             else
       
   726             {
       
   727                 ((TEventMboxEvCb)pEventMbox->CbTable[EvID].fCb)(pEventMbox->CbTable[EvID].hCb);
       
   728             }
       
   729         }
       
   730     }     
       
   731 
       
   732     /* Check if the state is changed in the context of the event callbacks */
       
   733     if (pEventMbox->CurrentState == EVENT_MBOX_STATE_IDLE)
       
   734     {
       
   735         /*
       
   736          * When eventMbox_stop is called state is changed to IDLE
       
   737          * This is done in the context of the above events callbacks
       
   738          * Don't send the EVENT ACK transaction because the driver stop process includes power off
       
   739          */ 
       
   740         TRACE0(pEventMbox->hReport, REPORT_SEVERITY_WARNING, "eventMbox_ReadCompleteCB : State is IDLE ! don't send the EVENT ACK");
       
   741         return;
       
   742     }
       
   743 
       
   744 	pEventMbox->CurrentState = EVENT_MBOX_STATE_IDLE;
       
   745 
       
   746 	/* Build the command TxnStruct */
       
   747     TXN_PARAM_SET(pTxn, TXN_LOW_PRIORITY, TXN_FUNC_ID_WLAN, TXN_DIRECTION_WRITE, TXN_INC_ADDR)
       
   748 	/* Applying a CB in case of an async read */
       
   749     BUILD_TTxnStruct(pTxn, ACX_REG_INTERRUPT_TRIG, pEventMbox->iTxnGenRegSize.pRegBuffer, sizeof(TI_UINT32), NULL, NULL)
       
   750 	twIf_Transact(pEventMbox->hTwif,pTxn);
       
   751 }    
       
   752 
       
   753 
       
   754 #ifdef TI_DBG
       
   755 
       
   756 /*
       
   757  *  eventMbox_Print: print the Event Mailbox statistic :Number 890
       
   758  */
       
   759 TI_STATUS eventMbox_Print (TI_HANDLE hEventMbox)
       
   760 {
       
   761     TEventMbox *pEventMbox = (TEventMbox *)hEventMbox;
       
   762     TI_UINT32 i;
       
   763     TI_UINT32 EvMask   = ((EventMailBox_t*)(pEventMbox->iTxnEventMbox.pEventMboxBuf))->eventsMask;
       
   764     TI_UINT32 EvVector = ((EventMailBox_t*)(pEventMbox->iTxnEventMbox.pEventMboxBuf))->eventsVector;
       
   765 
       
   766     TRACE0(pEventMbox->hReport, REPORT_SEVERITY_CONSOLE, "------------------------- EventMbox  Print ----------------------------\n");
       
   767 
       
   768     TRACE1(pEventMbox->hReport, REPORT_SEVERITY_INFORMATION, " eventMbox_HandleEvent: Event Vector = 0x%x\n", EvVector);
       
   769     TRACE1(pEventMbox->hReport, REPORT_SEVERITY_INFORMATION, " eventMbox_HandleEvent: Event Mask = 0x%x\n", EvMask);
       
   770     TRACE1(pEventMbox->hReport, REPORT_SEVERITY_CONSOLE, " Total Number Of Compound Event = %d: \n", pEventMbox->uCompounEvCount);
       
   771     TRACE1(pEventMbox->hReport, REPORT_SEVERITY_CONSOLE, " Total Number Of Events = %d: \n", pEventMbox->uTotalEvCount);
       
   772     TRACE0(pEventMbox->hReport, REPORT_SEVERITY_CONSOLE, "\t\t\t\t *** Event Counters *** :\n");
       
   773     for (i = 0; i < TWD_OWN_EVENT_ALL; i++)
       
   774     {
       
   775         TRACE2(pEventMbox->hReport, REPORT_SEVERITY_CONSOLE, " %d) Event Name = EVENT , Number of Event = %d\n", i, pEventMbox->CbTable[i].uCount);
       
   776     }
       
   777 
       
   778     TRACE0(pEventMbox->hReport, REPORT_SEVERITY_CONSOLE, "------------------------- EventMbox  Print End ----------------------------\n");
       
   779 
       
   780     return TI_OK;
       
   781 }
       
   782 
       
   783 
       
   784 #endif /* TI_DBG */
       
   785 
       
   786 
       
   787