Home | History | Annotate | Download | only in Cmd_Queue
      1 /****************************************************************************
      2 **+-----------------------------------------------------------------------+**
      3 **|                                                                       |**
      4 **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved.      |**
      5 **| All rights reserved.                                                  |**
      6 **|                                                                       |**
      7 **| Redistribution and use in source and binary forms, with or without    |**
      8 **| modification, are permitted provided that the following conditions    |**
      9 **| are met:                                                              |**
     10 **|                                                                       |**
     11 **|  * Redistributions of source code must retain the above copyright     |**
     12 **|    notice, this list of conditions and the following disclaimer.      |**
     13 **|  * Redistributions in binary form must reproduce the above copyright  |**
     14 **|    notice, this list of conditions and the following disclaimer in    |**
     15 **|    the documentation and/or other materials provided with the         |**
     16 **|    distribution.                                                      |**
     17 **|  * Neither the name Texas Instruments nor the names of its            |**
     18 **|    contributors may be used to endorse or promote products derived    |**
     19 **|    from this software without specific prior written permission.      |**
     20 **|                                                                       |**
     21 **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |**
     22 **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |**
     23 **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
     24 **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |**
     25 **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
     26 **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |**
     27 **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
     28 **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
     29 **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |**
     30 **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
     31 **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |**
     32 **|                                                                       |**
     33 **+-----------------------------------------------------------------------+**
     34 ****************************************************************************/
     35 
     36 
     37 /*********************************************************************************/
     38 /*                                                                                */
     39 /*   MODULE:  CmdQueue.h                                                */
     40 /*   PURPOSE: CmdQueue internal H file											  */
     41 /*                                                                                */
     42 /**********************************************************************************/
     43 #ifndef _CMDQUEUE_H_
     44 #define _CMDQUEUE_H_
     45 
     46 #include "whalCommon.h"
     47 #include "whalHwDefs.h"
     48 
     49 /*****************************************************************************
     50  **         Defines	                                                       **
     51  *****************************************************************************/
     52 #define CMDQUEUE_QUEUE_DEPTH          50
     53 #define CMDQUEUE_HISTORY_DEPTH        5
     54 #define CMDQUEUE_INFO_ELEM_HEADER_LEN 4
     55 
     56 #define CMDQUEUE_CONVERT_RC(rc) \
     57 	if((rc == TNETWIF_OK)||(rc == TNETWIF_COMPLETE)||(rc == TNETWIF_PENDING)||(rc == OK)) \
     58 		return OK; \
     59 	else \
     60 		return NOK \
     61 
     62 #define CHECK_ERROR_FLAG(flag) \
     63 	if(flag == TRUE) \
     64 		return OK; \
     65 
     66 /*****************************************************************************
     67  **         Enums                                                    **
     68  *****************************************************************************/
     69 typedef enum
     70 {
     71 	CMDQUEUE_EVENT_RUN,
     72 	CMDQUEUE_EVENT_SEND_CMPLT,
     73 	CMDQUEUE_EVENT_RESULT_RECEIVED,
     74 	CMDQUEUE_EVENT_NUM,
     75 } CmdQueue_SMEvents_e;
     76 
     77 typedef enum
     78 {
     79 	CMDQUEUE_STATE_IDLE,
     80 	CMDQUEUE_STATE_SEND_CMD_v,
     81 	CMDQUEUE_STATE_WAIT_SEND_CMPLT,
     82 	CMDQUEUE_STATE_INTERROGATE_v,
     83 	CMDQUEUE_STATE_WAIT_RESULT,
     84 	CMDQUEUE_STATE_FINISH_v,
     85 	CMDQUEUE_STATE_NUM,
     86 } CmdQueue_SMStates_e;
     87 
     88 
     89 /*****************************************************************************
     90  **         Structures                                                      **
     91  *****************************************************************************/
     92 
     93 /*  CmdQueue Node */
     94 typedef struct
     95 {
     96 	Command_e    		cmdType;		/* Command Type Config/interrogat ... */
     97 	UINT32				paramsLen;
     98 	void*				CB_Func;
     99 	TI_HANDLE			CB_Arg;
    100 	UINT8				paramsBuf[MAX_CMD_PARAMS]; /* param for config */
    101 	UINT8*				interrogateParamsBuf; /* A returned value Buffer */
    102 }CmdQueue_CmdNode_T;
    103 
    104 /*  Saved CallBack Node In case of Recovery*/
    105 typedef struct
    106 {
    107 	void*				CB_Func;
    108 	TI_HANDLE			CB_Arg;
    109 	UINT8*				interrogateParamsBuf; /* A returned value Buffer */
    110 }CmdQueue_RecoveryNode_T;
    111 
    112 /* MailBox Queue */
    113 
    114 typedef struct _CmdQueue_T
    115 {
    116 	/* handles */
    117 	TI_HANDLE		    		hOs;
    118 	TI_HANDLE	        		hReport;
    119 	TI_HANDLE           			hCmdMBox;
    120 
    121 	/* SM */
    122 	CmdQueue_SMStates_e		State;
    123 	CmdQueue_GenericCB_t 	CmdCompleteGenericCB_Func;
    124 	TI_HANDLE				CmdCompleteGenericCB_Arg;
    125 	CmdQueue_CB_t			FailureCB;
    126 	TI_HANDLE				FailureCbHandle;
    127 
    128 	/* queues */
    129 	CmdQueue_CmdNode_T		CmdQueue[CMDQUEUE_QUEUE_DEPTH];
    130 	CmdQueue_RecoveryNode_T	RecoveryQueue[CMDQUEUE_QUEUE_DEPTH];
    131 
    132 	/* CmdQueue indexes & counters */
    133 	int  						Head;
    134 	int		    	  			Tail;
    135 	int				    		NumberOfCommandInQueue;
    136 	int						MaxNumberOfCommandInQueue;
    137 	int						NumberOfRecoveryNodes;
    138 #ifdef TI_DBG
    139 	UINT32					CmdSendCounter;
    140 	UINT32					CmdCompltCounter;
    141 #endif
    142 
    143 	int 						SM_RC;
    144 	/* error handling */
    145 	int 						ErrorFlag;
    146 }CmdQueue_T;
    147 
    148 /*****************************************************************************
    149  **         Internal functions definitions                                  **
    150  *****************************************************************************/
    151 int				CmdQueue_SM(CmdQueue_T* pCmdQueue,CmdQueue_SMEvents_e event);
    152 int				CmdQueue_Push(CmdQueue_T  *pCmdQueue, Command_e  cmdType,
    153                        							UINT8* pParamsBuf, UINT32 paramsLen,
    154 					   					void *CB_Func, TI_HANDLE CB_Arg, UINT8* pCB_Buf);
    155 void			CmdQueue_PrintQueue(CmdQueue_T  *pCmdQueue);
    156 
    157 #endif
    158