TWD/Ctrl/CmdQueue.h
changeset 0 10c42ec6c05f
equal deleted inserted replaced
-1:000000000000 0:10c42ec6c05f
       
     1 /*
       
     2  * CmdQueue.h
       
     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 CmdQueue.h
       
    41  *  \brief CmdQueue internal defenitions
       
    42  *
       
    43  *  \see CmdQueue.c
       
    44  */
       
    45 
       
    46 #ifndef _CMDQUEUE_H_
       
    47 #define _CMDQUEUE_H_
       
    48 
       
    49 
       
    50 
       
    51 
       
    52 /*****************************************************************************
       
    53  **         Defines                                                         **
       
    54  *****************************************************************************/
       
    55 #define CMDQUEUE_QUEUE_DEPTH          30
       
    56 #define CMDQUEUE_HISTORY_DEPTH        5
       
    57 #define CMDQUEUE_INFO_ELEM_HEADER_LEN 4
       
    58 
       
    59 
       
    60 #define RC_CONVERT(rc) \
       
    61     (rc == TXN_STATUS_OK || rc == TXN_STATUS_COMPLETE || rc == TXN_STATUS_PENDING || rc == TI_OK) ? TI_OK : TI_NOK
       
    62 
       
    63 
       
    64 /*****************************************************************************
       
    65  **         Enums                                                           **
       
    66  *****************************************************************************/
       
    67 typedef enum 
       
    68 {
       
    69     CMDQUEUE_EVENT_RUN,
       
    70     CMDQUEUE_EVENT_COMPLETE,
       
    71     CMDQUEUE_EVENT_NUM
       
    72 
       
    73 } ECmdQueueSmEvents;
       
    74 
       
    75 
       
    76 typedef enum 
       
    77 {
       
    78     CMDQUEUE_STATE_IDLE,
       
    79     CMDQUEUE_STATE_WAIT_FOR_COMPLETION
       
    80 
       
    81 } ECmdQueueSmStates;
       
    82 
       
    83 
       
    84 /*****************************************************************************
       
    85  **         Structures                                                      **
       
    86  *****************************************************************************/
       
    87 /*  CmdQueue Node */
       
    88 typedef struct 
       
    89 {
       
    90     /* Command Type Config/interrogat ... */
       
    91     Command_e               cmdType;        
       
    92     TI_UINT32               uParamsLen; 
       
    93     void*                   fCb;
       
    94     TI_HANDLE               hCb;
       
    95     /* Param for config */
       
    96     TI_UINT8                aParamsBuf[MAX_CMD_PARAMS]; 
       
    97     /* A returned value buffer */ 
       
    98     TI_UINT8*               pInterrogateBuf; 
       
    99 
       
   100 } TCmdQueueNode;
       
   101 
       
   102 
       
   103 /*  Saved CallBack Node In case of Recovery*/
       
   104 typedef struct 
       
   105 {
       
   106     void*                   fCb;
       
   107     TI_HANDLE               hCb;
       
   108     /* A returned value buffer */
       
   109     TI_UINT8*               pInterrogateBuf; 
       
   110 
       
   111 } TCmdQueueRecoveryNode;
       
   112 
       
   113 
       
   114 typedef void (*TCmdQueueCb) (TI_HANDLE handle, TI_UINT16 uMboxStatus);
       
   115 
       
   116 
       
   117 typedef void (*TCmdQueueGenericCb)(TI_HANDLE handle, TI_UINT16 uCmdType, TI_UINT16 uCmdID, TI_UINT32 status);
       
   118 
       
   119 
       
   120 /** \struct TCmdQueue
       
   121  * \brief CmdQueue structure
       
   122  * 
       
   123  * \par Description
       
   124  * 
       
   125  * \sa	
       
   126  */ 
       
   127 typedef struct
       
   128 {   
       
   129     /* Handles */
       
   130     TI_HANDLE               hOs;
       
   131     TI_HANDLE               hReport;
       
   132     TI_HANDLE               hCmdMBox;
       
   133     TI_HANDLE               hTwIf;
       
   134 
       
   135     /* SM */
       
   136     ECmdQueueSmStates       state;
       
   137     TCmdQueueGenericCb      fCmdCompleteCb;
       
   138     TI_HANDLE               hCmdCompleteCb;
       
   139     TCmdQueueCb             fFailureCb;
       
   140     TI_HANDLE               hFailureCb;
       
   141 
       
   142     /* Queues */
       
   143     TCmdQueueNode           aCmdQueue [CMDQUEUE_QUEUE_DEPTH]; 
       
   144     TCmdQueueRecoveryNode   aRecoveryQueue [CMDQUEUE_QUEUE_DEPTH];
       
   145 
       
   146     /* Indexes & counters */
       
   147     TI_UINT32               head;
       
   148     TI_UINT32               tail;
       
   149     TI_UINT32               uNumberOfCommandInQueue;
       
   150     TI_UINT32               uMaxNumberOfCommandInQueue;
       
   151     TI_UINT32               uNumberOfRecoveryNodes;  
       
   152     #ifdef TI_DBG
       
   153         TI_UINT32               uCmdSendCounter;
       
   154         TI_UINT32               uCmdCompltCounter;
       
   155     #endif
       
   156 
       
   157     /* Error handling */
       
   158     TI_BOOL                 bErrorFlag;
       
   159     /* Mbox status */
       
   160     TI_BOOL                 bMboxEnabled;
       
   161     /* Notify that we have already awaken the chip */
       
   162     TI_BOOL                 bAwake;
       
   163 
       
   164 } TCmdQueue; 
       
   165 
       
   166 #endif
       
   167