omap3530/beagle_drivers/wb/api/src/cyasdevice.h
changeset 27 117faf51deac
equal deleted inserted replaced
26:b7e488c49d0d 27:117faf51deac
       
     1 /* Cypress West Bridge API header file (cyasdevice.h)
       
     2  ## ===========================
       
     3  ##
       
     4  ##  Copyright Cypress Semiconductor Corporation, 2006-2009,
       
     5  ##  All Rights Reserved
       
     6  ##  UNPUBLISHED, LICENSED SOFTWARE.
       
     7  ##
       
     8  ##  CONFIDENTIAL AND PROPRIETARY INFORMATION
       
     9  ##  WHICH IS THE PROPERTY OF CYPRESS.
       
    10  ##
       
    11  ##  Use of this file is governed
       
    12  ##  by the license agreement included in the file
       
    13  ##
       
    14  ##     <install>/license/license.txt
       
    15  ##
       
    16  ##  where <install> is the Cypress software
       
    17  ##  installation root directory path.
       
    18  ##
       
    19  ## ===========================
       
    20 */
       
    21 
       
    22 #ifndef __INCLUDED_CYASDEVICE_H__
       
    23 #define __INCLUDED_CYASDEVICE_H__
       
    24 
       
    25 #include "cyashal.h"
       
    26 #include "cyasprotocol.h"
       
    27 #include "cyasusb.h"
       
    28 #include "cyasstorage.h"
       
    29 #include "cyasmtp.h"
       
    30 #include "cyas_cplus_start.h"
       
    31 
       
    32 /*****************************************************************************
       
    33  * West Bridge Constants
       
    34  ****************************************************************************/
       
    35 
       
    36 /* The endpoints used by West Bridge for the P port to S port path */
       
    37 #define CY_AS_P2S_WRITE_ENDPOINT                        (0x04)
       
    38 #define CY_AS_P2S_READ_ENDPOINT                         (0x08)
       
    39 
       
    40 /* The endpoint to use for firmware download */
       
    41 #define CY_AS_FIRMWARE_ENDPOINT                         (0x02)
       
    42 
       
    43 /* The maximum size of the firmware image West Bridge can accept */
       
    44 #define CY_AS_MAXIMUM_FIRMWARE_SIZE                     (24 * 1024)
       
    45 
       
    46 /* The maximum size of a write for EP0 and EP1 */
       
    47 #define CY_AS_EP0_MAX_WRITE_SIZE                        (128)
       
    48 #define CY_AS_EP1_MAX_WRITE_SIZE                        (64)
       
    49 
       
    50 /* The bitfields for the device state value */
       
    51 #define CY_AS_DEVICE_STATE_PIN_STANDBY                  (0x00000001)            /* The device is in StandBy mode */
       
    52 #define CY_AS_DEVICE_STATE_CONFIGURED                   (0x00000002)            /* The device has been configured */
       
    53 #define CY_AS_DEVICE_STATE_FIRMWARE_LOADED              (0x00000004)            /* The firmware has been loaded into the device */
       
    54 #define CY_AS_DEVICE_STATE_LOWLEVEL_MODULE              (0x00000008)            /* The interrupt module has been initialized */
       
    55 #define CY_AS_DEVICE_STATE_DMA_MODULE                   (0x00000010)            /* The DMA module has been initialized */
       
    56 #define CY_AS_DEVICE_STATE_INTR_MODULE                  (0x00000020)            /* The interrupt module has been initialized */
       
    57 #define CY_AS_DEVICE_STATE_STORAGE_MODULE               (0x00000040)            /* The storage module has been initialized */
       
    58 #define CY_AS_DEVICE_STATE_USB_MODULE                   (0x00000080)            /* The USB module has been initialized */
       
    59 #define CY_AS_DEVICE_STATE_STORAGE_SCSIMSG              (0x00000100)            /* If set, the API wants SCSI messages */
       
    60 #define CY_AS_DEVICE_STATE_STORAGE_ASYNC_PENDING        (0x00000200)            /* If set, an ASYNC storage operation is pending */
       
    61 #define CY_AS_DEVICE_STATE_USB_CONNECTED                (0x00000400)            /* If set, the USB port is connected */
       
    62 #define CY_AS_DEVICE_STATE_USB_HIGHSPEED                (0x00000800)            /* If set and USB is connected, it is high speed */
       
    63 #define CY_AS_DEVICE_STATE_IN_CALLBACK                  (0x00001000)            /* If set, we are in a callback */
       
    64 #define CY_AS_DEVICE_STATE_IN_SETUP_PACKET              (0x00004000)            /* If set, we are processing a setup packet */
       
    65 #define CY_AS_DEVICE_STATE_REGISTER_STANDBY             (0x00008000)            /* The device was placed in standby via register */
       
    66 #define CY_AS_DEVICE_STATE_CRYSTAL                      (0x00010000)            /* If set, the device is using a crystal */
       
    67 #define CY_AS_DEVICE_STATE_WAKING                       (0x00020000)            /* If set, wakeup has been called */
       
    68 #define CY_AS_DEVICE_STATE_EP0_STALLED                  (0x00040000)            /* If set, EP0 has been stalled. */
       
    69 #define CY_AS_DEVICE_STATE_SUSPEND                      (0x00080000)            /* If set, device is in suspend mode. */
       
    70 #define CY_AS_DEVICE_STATE_RESETP                       (0x00100000)            /* If set, device is a reset is pending. */
       
    71 #define CY_AS_DEVICE_STATE_STANDP                       (0x00200000)            /* If set, device is a standby is pending. */
       
    72 #define CY_AS_DEVICE_STATE_SSSP                         (0x00400000)            /* If set, device has a storage start or stop pending. */
       
    73 #define CY_AS_DEVICE_STATE_USSP                         (0x00800000)            /* If set, device has a usb start or stop pending. */
       
    74 #define CY_AS_DEVICE_STATE_MSSP                         (0x01000000)            /* If set, device has a mtp start or stop pending. */
       
    75 
       
    76 
       
    77 /* The bitfields for the endpoint state value */
       
    78 #define CY_AS_DMA_ENDPOINT_STATE_ENABLED                (0x0001)                /* DMA requests are accepted into the queue */
       
    79 #define CY_AS_DMA_ENDPOINT_STATE_SLEEPING               (0x0002)                /* The endpoint has a sleeping client, waiting on a queue drain */
       
    80 #define CY_AS_DMA_ENDPOINT_STATE_DMA_RUNNING            (0x0004)                /* The DMA backend to hardware is running */
       
    81 #define CY_AS_DMA_ENDPOINT_STATE_IN_TRANSIT             (0x0008)                /* There is an outstanding DMA entry deployed to the HAL */
       
    82 #define CY_AS_DMA_ENDPOINT_STATE_DIRECTION              (0x0010)                /* 0 = OUT (West Bridge -> P Port), 1 = IN (P Port -> West Bridge) */
       
    83 
       
    84 /* The state values for the request list */
       
    85 #define CY_AS_REQUEST_LIST_STATE_MASK                   (0x0f)                  /* Mask for getting the state information */
       
    86 #define CY_AS_REQUEST_LIST_STATE_QUEUED                 (0x00)                  /* The request is queued, nothing further */
       
    87 #define CY_AS_REQUEST_LIST_STATE_WAITING                (0x01)                  /* The request is sent, waiting for response */
       
    88 #define CY_AS_REQUEST_LIST_STATE_RECEIVED               (0x02)                  /* The response has been received, processing reponse */
       
    89 #define CY_AS_REQUEST_LIST_STATE_CANCELING              (0x03)                  /* The request/response is being canceled */
       
    90 #define CY_AS_REQUEST_LIST_STATE_SYNC                   (0x80)                  /* The request is synchronous */
       
    91 
       
    92 /* The flag values for a LL RequestResponse */
       
    93 #define CY_AS_REQUEST_RESPONSE_DELAY_ACK                (0x01)                  /* This request requires an ACK to be sent after it is completed */
       
    94 #define CY_AS_REQUEST_RESPONSE_EX                       (0x02)                  /* This request originated from a version V1.1 function call */
       
    95 #define CY_AS_REQUEST_RESPONSE_MS                       (0x04)                  /* This request originated from a version V1.2 function call */
       
    96 
       
    97 
       
    98 #define CY_AS_DEVICE_HANDLE_SIGNATURE                   (0x01211219)
       
    99 
       
   100 /*
       
   101  * This macro returns the endpoint pointer given the device pointer and an endpoint number
       
   102  */
       
   103 #define CY_AS_NUM_EP(dev_p, num) ((dev_p)->endp[(num)])
       
   104 
       
   105 /*****************************************************************************
       
   106  * West Bridge Data Structures
       
   107  ****************************************************************************/
       
   108 
       
   109 typedef struct CyAsDevice CyAsDevice ;
       
   110 
       
   111 /* Summary
       
   112    This type defines a callback function that will be called on completion of a DMA operation.
       
   113 
       
   114    Description
       
   115    This function definition is for a function that is called when the DMA operation is complete.  This
       
   116    function is called with the endpoint number, operation type, buffer pointer and size.
       
   117 
       
   118    See Also
       
   119    * CyAsDmaOper
       
   120    * CyAsDmaQueueWrite
       
   121  */
       
   122 typedef void (*CyAsDmaCallback)(
       
   123         CyAsDevice *                dev_p,                  /* The device that completed DMA */
       
   124         CyAsEndPointNumber_t        ep,                     /* The endpoint that completed DMA */
       
   125         void *                      mem_p,                  /* The pointer to the buffer that completed DMA */
       
   126         uint32_t                    size,                   /* The amount of data transferred */
       
   127         CyAsReturnStatus_t          error                   /* The error code for this DMA xfer */
       
   128         ) ;
       
   129 
       
   130 /* Summary
       
   131    This structure defines a DMA request that is queued
       
   132 
       
   133    Description
       
   134    This structure contains the information about a DMA request that is queued and is to
       
   135    be sent when possible.
       
   136 */
       
   137 typedef struct CyAsDmaQueueEntry
       
   138 {
       
   139     void *                          buf_p ;                 /* Pointer to memory buffer for this request */
       
   140     uint32_t                        size ;                  /* Size of the memory buffer for DMA operation */
       
   141     uint32_t                        offset ;                /* Offset into memory buffer for next DMA operation */
       
   142     CyBool                          packet ;                /* If TRUE and IN request */
       
   143     CyBool                          readreq ;               /* If TRUE, this is a read request */
       
   144     CyAsDmaCallback                 cb ;                    /* Callback function for when DMA is complete */
       
   145     struct CyAsDmaQueueEntry *      next_p ;                /* Pointer to next entry in queue */
       
   146 } CyAsDmaQueueEntry ;
       
   147 
       
   148 /* Summary
       
   149    This structure defines the endpoint data for a given
       
   150 
       
   151    Description
       
   152    This structure defines all of the information required to manage DMA for a given
       
   153    endpoint.
       
   154 */
       
   155 typedef struct CyAsDmaEndPoint
       
   156 {
       
   157     CyAsEndPointNumber_t            ep ;                    /* The endpoint number */
       
   158     uint8_t                         state ;                 /* The state of this endpoint */
       
   159     uint16_t                        maxhwdata ;             /* The maximum amount of data accepted in a packet by the hw */
       
   160     uint32_t                        maxhaldata ;            /* The maximum amount of data accepted by the HAL layer */
       
   161     CyAsDmaQueueEntry *             queue_p ;               /* The queue for DMA operations */
       
   162     CyAsDmaQueueEntry *             last_p ;                /* The last entry in the DMA queue */
       
   163     CyAsHalSleepChannel             channel ;               /* This sleep channel is used to wait while the DMA queue drains for a given endpoint */
       
   164 } CyAsDmaEndPoint ;
       
   165 
       
   166 #define CyAsEndPointNumberIsUsb(n) ((n) != 2 && (n) != 4 && (n) != 6 && (n) != 8)
       
   167 #define CyAsEndPointNumberIsStorage(n) ((n) == 2 || (n) == 4 || (n) == 6 || (n) == 8)
       
   168 
       
   169 #define CyAsDmaEndPointIsEnabled(ep) ((ep)->state & CY_AS_DMA_ENDPOINT_STATE_ENABLED)
       
   170 #define CyAsDmaEndPointEnable(ep) ((ep)->state |= CY_AS_DMA_ENDPOINT_STATE_ENABLED)
       
   171 #define CyAsDmaEndPointDisable(ep) ((ep)->state &= ~CY_AS_DMA_ENDPOINT_STATE_ENABLED)
       
   172 
       
   173 #define CyAsDmaEndPointIsSleeping(ep) ((ep)->state & CY_AS_DMA_ENDPOINT_STATE_SLEEPING)
       
   174 #define CyAsDmaEndPointSetSleepState(ep) ((ep)->state |= CY_AS_DMA_ENDPOINT_STATE_SLEEPING)
       
   175 #define CyAsDmaEndPointSetWakeState(ep) ((ep)->state &= ~CY_AS_DMA_ENDPOINT_STATE_SLEEPING)
       
   176 
       
   177 #define CyAsDmaEndPointIsRunning(ep) ((ep)->state & CY_AS_DMA_ENDPOINT_STATE_DMA_RUNNING)
       
   178 #define CyAsDmaEndPointSetRunning(ep) ((ep)->state |= CY_AS_DMA_ENDPOINT_STATE_DMA_RUNNING)
       
   179 #define CyAsDmaEndPointSetStopped(ep) ((ep)->state &= ~CY_AS_DMA_ENDPOINT_STATE_DMA_RUNNING)
       
   180 
       
   181 #define CyAsDmaEndPointInTransit(ep) ((ep)->state & CY_AS_DMA_ENDPOINT_STATE_IN_TRANSIT)
       
   182 #define CyAsDmaEndPointSetInTransit(ep) ((ep)->state |= CY_AS_DMA_ENDPOINT_STATE_IN_TRANSIT)
       
   183 #define CyAsDmaEndPointClearInTransit(ep) ((ep)->state &= ~CY_AS_DMA_ENDPOINT_STATE_IN_TRANSIT)
       
   184 
       
   185 #define CyAsDmaEndPointIsDirectionIn(ep) (((ep)->state & CY_AS_DMA_ENDPOINT_STATE_DIRECTION) == CY_AS_DMA_ENDPOINT_STATE_DIRECTION)
       
   186 #define CyAsDmaEndPointIsDirectionOut(ep) (((ep)->state & CY_AS_DMA_ENDPOINT_STATE_DIRECTION) == 0)
       
   187 #define CyAsDmaEndPointSetDirectionIn(ep) ((ep)->state |= CY_AS_DMA_ENDPOINT_STATE_DIRECTION)
       
   188 #define CyAsDmaEndPointSetDirectionOut(ep) ((ep)->state &= ~CY_AS_DMA_ENDPOINT_STATE_DIRECTION)
       
   189 
       
   190 #define CyAsDmaEndPointIsUsb(p) CyAsEndPointNumberIsUsb((p)->ep)
       
   191 #define CyAsDmaEndPointIsStorage(p) CyAsEndPointNumberIsStorage((p)->ep)
       
   192 
       
   193 typedef struct CyAsLLRequestResponse
       
   194 {
       
   195     uint16_t                        box0 ;                  /* The mbox[0] contents - see low level comm section of API doc */
       
   196     uint16_t                        stored ;                /* The amount of data stored in this request/response in bytes */
       
   197     uint16_t                        length ;                /* Length of this request in words */
       
   198     uint16_t                        flags ;                 /* Additional status information about the request */
       
   199     uint16_t                        data[1] ;               /* Note: This is over indexed and contains the request/response data */
       
   200 } CyAsLLRequestResponse ;
       
   201 
       
   202 /*
       
   203  * The callback function for responses
       
   204  */
       
   205 typedef void (*CyAsResponseCallback)(
       
   206     CyAsDevice *                    dev_p,                  /* The device that had the response */
       
   207     uint8_t                         context,                /* The context receiving a response */
       
   208     CyAsLLRequestResponse *         rqt,                    /* The request data */
       
   209     CyAsLLRequestResponse *         resp,                   /* The response data */
       
   210     CyAsReturnStatus_t              status                  /* The status of the request */
       
   211     ) ;
       
   212 
       
   213 typedef struct CyAsLLRequestListNode
       
   214 {
       
   215     CyAsLLRequestResponse *         rqt ;                   /* The request to send */
       
   216     CyAsLLRequestResponse *         resp ;                  /* The associated response for the request */
       
   217     uint16_t                        length ;                /* Length of the response */
       
   218     CyAsResponseCallback            callback ;              /* The callback to call when done */
       
   219     uint8_t                         state ;                 /* The state of the request */
       
   220     struct CyAsLLRequestListNode *  next ;                  /* The next request in the list */
       
   221 } CyAsLLRequestListNode ;
       
   222 
       
   223 #define CyAsRequestGetNodeState(node_p) ((node_p)->state & CY_AS_REQUEST_LIST_STATE_MASK)
       
   224 #define CyAsRequestSetNodeState(node_p, st) ((node_p)->state = ((node_p)->state & ~CY_AS_REQUEST_LIST_STATE_MASK) | (st))
       
   225 
       
   226 #define CyAsRequestNodeIsSync(node_p) ((node_p)->state & CY_AS_REQUEST_LIST_STATE_SYNC)
       
   227 #define CyAsRequestNodeSetSync(node_p) ((node_p)->state |= CY_AS_REQUEST_LIST_STATE_SYNC)
       
   228 #define CyAsRequestNodeClearSync(node_p) ((node_p)->state &= ~CY_AS_REQUEST_LIST_STATE_SYNC)
       
   229 
       
   230 #ifndef __doxygen__
       
   231 typedef enum CyAsCBNodeType
       
   232 {
       
   233     CYAS_INVALID,
       
   234     CYAS_USB_FUNC_CB,
       
   235     CYAS_USB_IO_CB,
       
   236     CYAS_STORAGE_IO_CB,
       
   237     CYAS_FUNC_CB
       
   238 } CyAsCBNodeType ;
       
   239 
       
   240 typedef struct CyAsFuncCBNode
       
   241 {
       
   242     CyAsCBNodeType              nodeType ;
       
   243     CyAsFunctionCallback        cb_p ;
       
   244     uint32_t                    client_data ;
       
   245     /*CyAsFunctCBType             dataType ; nxz */
       
   246     uint32_t					dataType ;
       
   247     void*                       data ;
       
   248     struct CyAsFuncCBNode *     next_p ;
       
   249 } CyAsFuncCBNode;
       
   250 
       
   251 extern CyAsFuncCBNode*
       
   252 CyAsCreateFuncCBNodeData(CyAsFunctionCallback cb, uint32_t client, CyAsFunctCBType type, void* data) ;
       
   253 
       
   254 extern CyAsFuncCBNode*
       
   255 CyAsCreateFuncCBNode(CyAsFunctionCallback cb, uint32_t client) ;
       
   256 
       
   257 extern void
       
   258 CyAsDestroyFuncCBNode(CyAsFuncCBNode* node) ;
       
   259 
       
   260 typedef struct CyAsMTPFuncCBNode
       
   261 {
       
   262     CyAsCBNodeType              type ;
       
   263     CyAsMTPFunctionCallback     cb_p ;
       
   264     uint32_t                    client_data;
       
   265     struct CyAsMTPFuncCBNode *  next_p ;
       
   266 } CyAsMTPFuncCBNode;
       
   267 
       
   268 extern CyAsMTPFuncCBNode*
       
   269 CyAsCreateMTPFuncCBNode(CyAsMTPFunctionCallback cb, uint32_t client) ;
       
   270 
       
   271 extern void
       
   272 CyAsDestroyMTPFuncCBNode(CyAsMTPFuncCBNode* node) ;
       
   273 
       
   274 typedef struct CyAsUsbFuncCBNode
       
   275 {
       
   276     CyAsCBNodeType              type ;
       
   277     CyAsUsbFunctionCallback     cb_p ;
       
   278     uint32_t                    client_data;
       
   279     struct CyAsUsbFuncCBNode *  next_p ;
       
   280 } CyAsUsbFuncCBNode;
       
   281 
       
   282 extern CyAsUsbFuncCBNode*
       
   283 CyAsCreateUsbFuncCBNode(CyAsUsbFunctionCallback cb, uint32_t client) ;
       
   284 
       
   285 extern void
       
   286 CyAsDestroyUsbFuncCBNode(CyAsUsbFuncCBNode* node) ;
       
   287 
       
   288 typedef struct CyAsUsbIoCBNode
       
   289 {
       
   290     CyAsCBNodeType              type ;
       
   291     CyAsUsbIoCallback           cb_p ;
       
   292     struct CyAsUsbIoCBNode *    next_p ;
       
   293 } CyAsUsbIoCBNode;
       
   294 
       
   295 extern CyAsUsbIoCBNode*
       
   296 CyAsCreateUsbIoCBNode(CyAsUsbIoCallback cb) ;
       
   297 
       
   298 extern void
       
   299 CyAsDestroyUsbIoCBNode(CyAsUsbIoCBNode* node) ;
       
   300 
       
   301 typedef struct CyAsStorageIoCBNode
       
   302 {
       
   303     CyAsCBNodeType              type ;
       
   304     CyAsStorageCallback         cb_p ;
       
   305     CyAsMediaType               media ;             /* The media for the currently outstanding async storage request */
       
   306     uint32_t                    device_index ;      /* The device index for the currently outstanding async storage request */
       
   307     uint32_t                    unit ;              /* The unit index for the currently outstanding async storage request */
       
   308     uint32_t                    block_addr ;        /* The block address for the currently outstanding async storage request */
       
   309     CyAsOperType                oper ;              /* The operation for the currently outstanding async storage request */
       
   310     CyAsLLRequestResponse*      req_p ;
       
   311     CyAsLLRequestResponse*      reply_p ;
       
   312     struct CyAsStorageIoCBNode* next_p ;
       
   313 } CyAsStorageIoCBNode;
       
   314 
       
   315 extern CyAsStorageIoCBNode*
       
   316 CyAsCreateStorageIoCBNode(CyAsStorageCallback cb, CyAsMediaType media, uint32_t device_index,
       
   317                           uint32_t unit, uint32_t block_addr, CyAsOperType oper,
       
   318                           CyAsLLRequestResponse* req_p, CyAsLLRequestResponse* reply_p) ;
       
   319 
       
   320 extern void
       
   321 CyAsDestroyStorageIoCBNode(CyAsStorageIoCBNode* node) ;
       
   322 
       
   323 typedef struct CyAsCBQueue
       
   324 {
       
   325     void *              head_p;
       
   326     void *              tail_p;
       
   327     uint32_t            count ;
       
   328     CyAsCBNodeType      type ;
       
   329 } CyAsCBQueue ;
       
   330 
       
   331 extern CyAsCBQueue *
       
   332 CyAsCreateCBQueue(CyAsCBNodeType type) ;
       
   333 
       
   334 extern void
       
   335 CyAsDestroyCBQueue(CyAsCBQueue* queue) ;
       
   336 
       
   337 /* Allocates a new CyAsCBNode */
       
   338 extern void
       
   339 CyAsInsertCBNode(CyAsCBQueue * queue_p, void* cbnode) ;
       
   340 
       
   341 /* Removes the first CyAsCBNode from the queue and frees it */
       
   342 extern void
       
   343 CyAsRemoveCBNode(CyAsCBQueue * queue_p) ;
       
   344 
       
   345 /* Remove the last CyAsCBNode from the queue and frees it */
       
   346 extern void
       
   347 CyAsRemoveCBTailNode(CyAsCBQueue *queue_p) ;
       
   348 
       
   349 /* Removes and frees all pending callbacks */
       
   350 extern void
       
   351 CyAsClearCBQueue(CyAsCBQueue * queue_p) ;
       
   352 
       
   353 extern CyAsReturnStatus_t
       
   354 CyAsMiscSendRequest(CyAsDevice* dev_p,
       
   355                       CyAsFunctionCallback cb,
       
   356                       uint32_t client,
       
   357                       CyAsFunctCBType type,
       
   358                       void* data,
       
   359                       CyAsCBQueue* queue,
       
   360                       uint16_t req_type,
       
   361                       CyAsLLRequestResponse *req_p,
       
   362                       CyAsLLRequestResponse *reply_p,
       
   363                       CyAsResponseCallback rcb) ;
       
   364 
       
   365 extern void
       
   366 CyAsMiscCancelExRequests(CyAsDevice* dev_p) ;
       
   367 
       
   368 /* Summary
       
   369    Free all memory allocated by and zero all structures initialized
       
   370    by CyAsUsbStart.
       
   371  */
       
   372 extern void
       
   373 CyAsUsbCleanup (
       
   374         CyAsDevice *dev_p) ;
       
   375 
       
   376 /* Summary
       
   377    Free all memory allocated and zero all structures initialized
       
   378    by CyAsStorageStart.
       
   379  */
       
   380 extern void
       
   381 CyAsStorageCleanup (
       
   382         CyAsDevice *dev_p) ;
       
   383 #endif
       
   384 
       
   385 /* Summary
       
   386    This structure defines the data structure to support a given command context
       
   387 
       
   388    Description
       
   389    All commands send to the West Bridge device via the mailbox registers are sent via a context.
       
   390    Each context is independent and there can be a parallel stream of requests and responses on
       
   391    each context.  This structure is used to manage a single context.
       
   392 */
       
   393 typedef struct CyAsContext
       
   394 {
       
   395     uint8_t                         number ;                /* The context number for this context */
       
   396     CyAsHalSleepChannel             channel ;               /* This sleep channel is used to sleep while waiting on a response from the
       
   397                                                                West Bridge device for a request. */
       
   398     CyAsLLRequestResponse *         req_p ;                 /* The buffer for received requests */
       
   399     uint16_t                        request_length ;        /* The length of the request being received */
       
   400     CyAsResponseCallback            request_callback ;      /* The callback for the next request received */
       
   401 
       
   402     CyAsLLRequestListNode *         request_queue_p ;       /* A list of low level requests to go to the firmware */
       
   403     CyAsLLRequestListNode *         last_node_p ;           /* The list node in the request queue */
       
   404 
       
   405     uint16_t                        queue_index ;           /* Index upto which data is stored. */
       
   406     uint16_t                        rqt_index ;             /* Index to the next request in the queue. */
       
   407     uint16_t                        data_queue[128] ;       /* Queue of data stored */
       
   408 
       
   409 } CyAsContext ;
       
   410 
       
   411 #define CyAsContextIsWaiting(ctxt) ((ctxt)->state & CY_AS_CTXT_STATE_WAITING_RESPONSE)
       
   412 #define CyAsContextSetWaiting(ctxt) ((ctxt)->state |= CY_AS_CTXT_STATE_WAITING_RESPONSE)
       
   413 #define CyAsContextClearWaiting(ctxt) ((ctxt)->state &= ~CY_AS_CTXT_STATE_WAITING_RESPONSE)
       
   414 
       
   415 
       
   416 
       
   417 /* Summary
       
   418    This data structure stores SDIO function parameters for a SDIO card
       
   419 
       
   420    Description
       
   421 */
       
   422 typedef struct CyAsSDIODevice
       
   423 {
       
   424     uint8_t     function_init_map; /* Keeps track of IO functions initialized*/
       
   425     uint8_t     function_suspended_map;
       
   426     CyAsSDIOCard card;            /* Function 0 (Card Common) properties*/
       
   427     CyAsSDIOFunc function[7];   /* Function 1-7 (Mapped to array element 0-6) properties.*/
       
   428 
       
   429 }CyAsSDIODevice;
       
   430 
       
   431 /* Summary
       
   432 Macros to access the SDIO card properties
       
   433 */
       
   434 //GetFunction Code
       
   435 #define CyAsSdioGetFunctionCode(handle,bus,i)       ((CyAsDevice *)handle)->sdiocard[bus].function[i-1].function_code
       
   436 
       
   437 //Get Function Extended Code
       
   438 #define CyAsSdioGetFunctionExtCode(handle,bus,i)    ((CyAsDevice *)handle)->sdiocard[bus].function[i-1].extended_func_code
       
   439 
       
   440 //Get Function Product Serial number
       
   441 #define CyAsSdioGetFunctionPSN(handle,bus,i)        ((CyAsDevice *)handle)->sdiocard[bus].function[i-1].card_psn
       
   442 
       
   443 //Get Function Block Size
       
   444 #define CyAsSdioGetFunctionBlocksize(handle,bus,i)  ((CyAsDevice *)handle)->sdiocard[bus].function[i-1].blocksize
       
   445 
       
   446 //Get Function Max Block Size
       
   447 #define CyAsSdioGetFunctionMaxBlocksize(handle,bus,i)  ((CyAsDevice *)handle)->sdiocard[bus].function[i-1].maxblocksize
       
   448 
       
   449 //Get Function CSA support
       
   450 #define CyAsSdioGetFunctionCsaSupport(handle,bus,i) ((CyAsDevice *)handle)->sdiocard[bus].function[i-1].csa_bits
       
   451 
       
   452 //Get Function Wakeup Support
       
   453 #define CyAsSdioGetFunctionWakeupSupport(handle,bus,i) ((CyAsDevice *)handle)->sdiocard[bus].function[i-1]. wakeup_support
       
   454 
       
   455 #define CyAsSdioSetFunctionBlockSize(handle,bus,i,blocksize) (((CyAsDevice *)handle)->sdiocard[bus].function[i-1].blocksize = blocksize)
       
   456 
       
   457 //Get Number of funtions on card
       
   458 #define CyAsSdioGetCardNumFunctions(handle,bus)     ((CyAsDevice *)handle)->sdiocard[bus].card.num_functions
       
   459 
       
   460 //Check if memory is present on the card
       
   461 #define CyAsSdioGetCardMemPresent(handle,bus)       ((CyAsDevice *)handle)->sdiocard[bus].card.memory_present
       
   462 
       
   463 //Get Card manufaturer ID
       
   464 #define CyAsSdioGetCardManfId(handle,bus)           ((CyAsDevice *)handle)->sdiocard[bus].card.manufacturer_Id
       
   465 
       
   466 //Get Card manufacturer Information
       
   467 #define CyAsSdioGetCardManfInfo(handle,bus)         ((CyAsDevice *)handle)->sdiocard[bus].card.manufacturer_info
       
   468 
       
   469 //Get Card Block Size
       
   470 #define CyAsSdioGetCardBlocksize(handle,bus)        ((CyAsDevice *)handle)->sdiocard[bus].card.blocksize
       
   471 
       
   472 //Get Card max Block Size
       
   473 #define CyAsSdioGetCardMaxBlocksize(handle,bus)        ((CyAsDevice *)handle)->sdiocard[bus].card.maxblocksize
       
   474 
       
   475 //Get SDIO version supported by card
       
   476 #define CyAsSdioGetCardSDIOVersion(handle,bus)      ((CyAsDevice *)handle)->sdiocard[bus].card.sdio_version
       
   477 
       
   478 //Get Card capabillity register
       
   479 #define CyAsSdioGetCardCapability(handle,bus)       ((CyAsDevice *)handle)->sdiocard[bus].card.card_capability
       
   480 
       
   481 //Get function initialization map
       
   482 #define CyAsSdioGetFunctionInitMap(handle,bus)      ((CyAsDevice *)handle)->sdiocard[bus].function_init_map
       
   483 
       
   484 //Check if function i has been initialized
       
   485 #define CyAsSdioCheckFunctionInitialized(handle,bus,i) (((CyAsSdioGetFunctionInitMap(handle,bus))& (0x01<<i))?1:0)
       
   486 
       
   487 //Set the Card functio 0 block size
       
   488 #define CyAsSdioSetCardBlockSize(handle,bus,blocksize) (((CyAsDevice *)handle)->sdiocard[bus].card.blocksize = blocksize)
       
   489 
       
   490 //Check if the Card supports Bus suspend.
       
   491 #define CyAsSdioCheckSupportBusSuspend(handle,bus)      ((CyAsSdioGetCardCapability(handle,bus) & CY_SDIO_SBS)?1:0)
       
   492 
       
   493 //Check if a fuction is in suspended state
       
   494 #define CyAsSdioCheckFunctionSuspended(handle,bus,i)    ((((CyAsDevice *)handle)->sdiocard[bus].function_suspended_map & (0x01<<i))?1:0)
       
   495 
       
   496 //Set a function state to suspended
       
   497 #define CyAsSdioSetFunctionSuspended(handle,bus,i)      ((((CyAsDevice *)handle)->sdiocard[bus].function_suspended_map) |= (0x01<<i))
       
   498 
       
   499 //Clear a function suspended state
       
   500 #define CyAsSdioClearFunctionSuspended(handle,bus,i)      ((((CyAsDevice *)handle)->sdiocard[bus].function_suspended_map) &= (~(0x01<<i)))
       
   501 
       
   502 /* Summary
       
   503    This data structure represents a single device.
       
   504 
       
   505    Description
       
   506 */
       
   507 struct CyAsDevice
       
   508 {
       
   509     /* General stuff */
       
   510     uint32_t                    sig ;                       /* A signature to insure we have a valid handle */
       
   511     uint16_t                    silicon_id ;                /* The ID of the silicon */
       
   512     struct CyAsDevice *         next_p ;                    /* Pointer to the next device */
       
   513     CyAsHalDeviceTag            tag ;                       /* This is the client specific tag for this device */
       
   514     uint32_t                    state ;                     /* This contains various state information about the device */
       
   515     CyBool                      use_int_drq ;               /* Flag indicating whether INT# pin is used for DRQ */
       
   516 
       
   517     /* DMA related */
       
   518     CyAsDmaEndPoint     *       endp[16] ;                  /* The endpoint pointers associated with this device */
       
   519     CyAsDmaQueueEntry *         dma_freelist_p ;            /* List of queue entries that can be used for xfers */
       
   520 
       
   521     /* Low level comm related */
       
   522     CyAsContext *               context[CY_RQT_CONTEXT_COUNT] ; /* The contexts available in this device */
       
   523     CyAsReturnStatus_t          ll_error ;                  /* The low level error returned from sending an async request */
       
   524     CyBool                      ll_sending_rqt ;            /* A request is currently being sent to West Bridge. */
       
   525     CyBool                      ll_abort_curr_rqt ;         /* The current mailbox request should be aborted. */
       
   526     CyBool                      ll_queued_data ;            /* Indicates that the LL layer has queued mailbox data. */
       
   527 
       
   528     /* MISC API related */
       
   529     CyAsMiscEventCallback       misc_event_cb ;             /* Misc callback */
       
   530 
       
   531     /* Storage Related */
       
   532     uint32_t                    storage_count ;             /* The reference count for the Storage API */
       
   533     CyAsStorageEventCallback_dep    storage_event_cb ;      /* Callback for storage events */
       
   534     CyAsStorageEventCallback  storage_event_cb_ms ;         /* V1.2+ callback for storage events */
       
   535     CyAsReturnStatus_t          storage_error ;             /* The error for a sleeping storage operation */
       
   536     CyBool                      storage_wait ;              /* Flag indicating that the storage stack is waiting for an operation */
       
   537     CyAsLLRequestResponse *     storage_rw_req_p ;          /* Request used for storage read/writes. */
       
   538     CyAsLLRequestResponse *     storage_rw_resp_p ;         /* Response used for storage read/writes. */
       
   539     CyAsStorageCallback_dep     storage_cb ;                /* The storage callback */
       
   540     CyAsStorageCallback         storage_cb_ms ;             /* The V1.2+ storage callback */
       
   541     CyAsBusNumber_t             storage_bus_index ;         /* The bus index for the currently outstanding async storage request */
       
   542     uint32_t                    storage_device_index ;      /* The device index for the currently outstanding async storage request */
       
   543     uint32_t                    storage_unit ;              /* The unit index for the currently outstanding async storage request */
       
   544     uint32_t                    storage_block_addr ;        /* The block address for the currently outstanding async storage request */
       
   545     CyAsOperType                storage_oper ;              /* The operation for the currently outstanding async storage request */
       
   546     CyAsEndPointNumber_t        storage_read_endpoint ;     /* The endpoint used to read Storage data */
       
   547     CyAsEndPointNumber_t        storage_write_endpoint ;    /* The endpoint used to write endpoint data */
       
   548     CyAsDeviceDesc              storage_device_info[CY_AS_MAX_BUSES][CY_AS_MAX_STORAGE_DEVICES] ;
       
   549     /* The information on each device on each bus */
       
   550 
       
   551     /* USB Related */
       
   552     uint16_t                    epasync ;                   /* This conatins the endpoint async state */
       
   553     uint32_t                    usb_count ;                 /* The reference count for the USB API */
       
   554     uint8_t                     usb_phy_config ;            /* The physical endpoint configuration */
       
   555     CyAsCBQueue *               usb_func_cbs ;              /* The callbacks for async func calls */
       
   556     CyAsUsbEndPointConfig       usb_config[16] ;            /* Endpoint configuration information */
       
   557     CyAsUsbEventCallback_dep    usb_event_cb ;              /* The USB callback */
       
   558     CyAsUsbEventCallback        usb_event_cb_ms ;           /* The V1.2+ USB callback */
       
   559     CyAsReturnStatus_t          usb_error ;                 /* The error for a sleeping usb operation */
       
   560     CyAsUsbIoCallback           usb_cb[16] ;                /* The USB callback for a pending storage operation */
       
   561     void *                      usb_pending_buffer ;        /* The buffer pending from a USB operation */
       
   562     uint32_t                    usb_pending_size ;          /* The size of the buffer pending from a USB operation */
       
   563     CyBool                      usb_spacket[16] ;           /* If true, send a short packet */
       
   564     uint32_t                    usb_actual_cnt ;            /* The amount of data actually xferred */
       
   565     uint8_t                     usb_ep1cfg[2] ;             /* EP1OUT and EP1IN config register contents */
       
   566     uint16_t                    usb_lepcfg[10] ;            /* LEP config register contents */
       
   567     uint16_t                    usb_pepcfg[4] ;             /* PEP config register contents */
       
   568     uint8_t *                   usb_ep_data ;               /* Buffer for EP0 and EP1 data sent via mailboxes */
       
   569     uint32_t                    usb_delay_ack_count ;       /* Used to track how many ack requests are pending */
       
   570     uint32_t                    usb_max_tx_size ;           /* Maximum transfer size for USB endpoints. */
       
   571 
       
   572     CyAsLLRequestResponse *     usb_ep0_dma_req ;           /* Request for sending EP0 data to West Bridge */
       
   573     CyAsLLRequestResponse *     usb_ep0_dma_resp ;          /* Response for EP0 data sent to West Bridge */
       
   574     CyAsLLRequestResponse *     usb_ep1_dma_req ;           /* Request for sending EP1 data to West Bridge */
       
   575     CyAsLLRequestResponse *     usb_ep1_dma_resp ;          /* Response for EP1 data sent to West Bridge */
       
   576 
       
   577     CyAsLLRequestResponse *     usb_ep0_dma_req_save ;
       
   578     CyAsLLRequestResponse *     usb_ep0_dma_resp_save ;
       
   579 
       
   580     /* MTP Related */
       
   581     uint32_t                    mtp_count ;                 /* The reference count for the MTP API */
       
   582     CyAsMTPEventCallback        mtp_event_cb ;              /* The MTP event callback supplied by the client */
       
   583     CyAsMTPBlockTable*          mtp_blk_tbl ;               /* The current block table to be transfered */
       
   584 
       
   585     CyAsCBQueue *               func_cbs_mtp ;
       
   586     CyAsCBQueue *               func_cbs_usb ;
       
   587     CyAsCBQueue *               func_cbs_stor ;
       
   588     CyAsCBQueue *               func_cbs_misc ;
       
   589     CyAsCBQueue *               func_cbs_res ;
       
   590 
       
   591     CyAsUsbEvent                usb_last_event ;                     /* The last USB event that was received */
       
   592     uint8_t                     media_supported[CY_AS_MAX_BUSES] ;   /* Types of storage media supported by the firmware */
       
   593 
       
   594     CyAsSDIODevice   sdiocard[CY_AS_MAX_BUSES];                      /* SDIO card parameters*/
       
   595     CyBool                      is_mtp_firmware ;                    /* if true, MTP enabled Firmware. */
       
   596     CyBool                      is_mtp_data_pending ;                /* if true, mailbox message has come already */
       
   597     CyBool                      mtp_turbo_active ;                   /* True between the time an Init was called and the complete event is generated */
       
   598     uint16_t                    mtp_data_len ;                       /* mbox reported EP 2 data len */
       
   599     CyAsReturnStatus_t          mtp_error ;                          /* The error for mtp EP4 write operation */
       
   600     CyAsFunctionCallback        mtp_cb ;                             /* mtp send/get operation callback */
       
   601     uint32_t                    mtp_client ;                         /* mtp send/get operation client id */
       
   602     CyAsFunctCBType             mtp_op ;                             /* mtp operation type. To be used in callback */
       
   603 
       
   604     CyBool                      is_storage_only_mode ;               /* Firmware is running in P2S only mode. */
       
   605     uint32_t                    stby_int_mask ;                      /* Interrupt mask value during device standby. */
       
   606 } ;
       
   607 
       
   608 #define CyAsDeviceIsConfigured(dp) ((dp)->state & CY_AS_DEVICE_STATE_CONFIGURED)
       
   609 #define CyAsDeviceSetConfigured(dp) ((dp)->state |= CY_AS_DEVICE_STATE_CONFIGURED)
       
   610 #define CyAsDeviceSetUnconfigured(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_CONFIGURED)
       
   611 
       
   612 #define CyAsDeviceIsDmaRunning(dp)      ((dp)->state & CY_AS_DEVICE_STATE_DMA_MODULE)
       
   613 #define CyAsDeviceSetDmaRunning(dp)     ((dp)->state |= CY_AS_DEVICE_STATE_DMA_MODULE)
       
   614 #define CyAsDeviceSetDmaStopped(dp)     ((dp)->state &= ~CY_AS_DEVICE_STATE_DMA_MODULE)
       
   615 
       
   616 #define CyAsDeviceIsLowLevelRunning(dp) ((dp)->state & CY_AS_DEVICE_STATE_LOWLEVEL_MODULE)
       
   617 #define CyAsDeviceSetLowLevelRunning(dp) ((dp)->state |= CY_AS_DEVICE_STATE_LOWLEVEL_MODULE)
       
   618 #define CyAsDeviceSetLowLevelStopped(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_LOWLEVEL_MODULE)
       
   619 
       
   620 #define CyAsDeviceIsIntrRunning(dp) ((dp)->state & CY_AS_DEVICE_STATE_INTR_MODULE)
       
   621 #define CyAsDeviceSetIntrRunning(dp) ((dp)->state |= CY_AS_DEVICE_STATE_INTR_MODULE)
       
   622 #define CyAsDeviceSetIntrStopped(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_INTR_MODULE)
       
   623 
       
   624 #define CyAsDeviceIsFirmwareLoaded(dp) ((dp)->state & CY_AS_DEVICE_STATE_FIRMWARE_LOADED)
       
   625 #define CyAsDeviceSetFirmwareLoaded(dp) ((dp)->state |= CY_AS_DEVICE_STATE_FIRMWARE_LOADED)
       
   626 #define CyAsDeviceSetFirmwareNotLoaded(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_FIRMWARE_LOADED)
       
   627 
       
   628 #define CyAsDeviceIsStorageRunning(dp) ((dp)->state & CY_AS_DEVICE_STATE_STORAGE_MODULE)
       
   629 #define CyAsDeviceSetStorageRunning(dp) ((dp)->state |= CY_AS_DEVICE_STATE_STORAGE_MODULE)
       
   630 #define CyAsDeviceSetStorageStopped(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_STORAGE_MODULE)
       
   631 
       
   632 #define CyAsDeviceIsUsbRunning(dp) ((dp)->state & CY_AS_DEVICE_STATE_USB_MODULE)
       
   633 #define CyAsDeviceSetUsbRunning(dp) ((dp)->state |= CY_AS_DEVICE_STATE_USB_MODULE)
       
   634 #define CyAsDeviceSetUsbStopped(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_USB_MODULE)
       
   635 
       
   636 #define CyAsDeviceWantsScsiMessages(dp) (((dp)->state & CY_AS_DEVICE_STATE_STORAGE_SCSIMSG) ? CyTrue : CyFalse)
       
   637 #define CyAsDeviceSetScsiMessages(dp) ((dp)->state |= CY_AS_DEVICE_STATE_STORAGE_SCSIMSG)
       
   638 #define CyAsDeviceClearScsiMessages(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_STORAGE_SCSIMSG)
       
   639 
       
   640 #define CyAsDeviceIsStorageAsyncPending(dp) ((dp)->state & CY_AS_DEVICE_STATE_STORAGE_ASYNC_PENDING)
       
   641 #define CyAsDeviceSetStorageAsyncPending(dp) ((dp)->state |= CY_AS_DEVICE_STATE_STORAGE_ASYNC_PENDING)
       
   642 #define CyAsDeviceClearStorageAsyncPending(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_STORAGE_ASYNC_PENDING)
       
   643 
       
   644 #define CyAsDeviceIsUsbConnected(dp) ((dp)->state & CY_AS_DEVICE_STATE_USB_CONNECTED)
       
   645 #define CyAsDeviceSetUsbConnected(dp) ((dp)->state |= CY_AS_DEVICE_STATE_USB_CONNECTED)
       
   646 #define CyAsDeviceClearUsbConnected(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_USB_CONNECTED)
       
   647 
       
   648 #define CyAsDeviceIsUsbHighSpeed(dp) ((dp)->state & CY_AS_DEVICE_STATE_USB_HIGHSPEED)
       
   649 #define CyAsDeviceSetUsbHighSpeed(dp) ((dp)->state |= CY_AS_DEVICE_STATE_USB_HIGHSPEED)
       
   650 #define CyAsDeviceClearUsbHighSpeed(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_USB_HIGHSPEED)
       
   651 
       
   652 #define CyAsDeviceIsInCallback(dp) ((dp)->state & CY_AS_DEVICE_STATE_IN_CALLBACK)
       
   653 #define CyAsDeviceSetInCallback(dp) ((dp)->state |= CY_AS_DEVICE_STATE_IN_CALLBACK)
       
   654 #define CyAsDeviceClearInCallback(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_IN_CALLBACK)
       
   655 
       
   656 #define CyAsDeviceIsSetupIOPerformed(dp) ((dp)->state & CY_AS_DEVICE_STATE_SETUP_IO_PERFORMED)
       
   657 #define CyAsDeviceSetSetupIOPerformed(dp) ((dp)->state |= CY_AS_DEVICE_STATE_SETUP_IO_PERFORMED)
       
   658 #define CyAsDeviceClearSetupIOPerformed(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_SETUP_IO_PERFORMED)
       
   659 
       
   660 #define CyAsDeviceIsAckDelayed(dp) ((dp)->usb_delay_ack_count > 0)
       
   661 #define CyAsDeviceSetAckDelayed(dp) ((dp)->usb_delay_ack_count++)
       
   662 #define CyAsDeviceRemAckDelayed(dp) ((dp)->usb_delay_ack_count--)
       
   663 #define CyAsDeviceClearAckDelayed(dp) ((dp)->usb_delay_ack_count = 0)
       
   664 
       
   665 #define CyAsDeviceIsSetupPacket(dp) ((dp)->state & CY_AS_DEVICE_STATE_IN_SETUP_PACKET)
       
   666 #define CyAsDeviceSetSetupPacket(dp) ((dp)->state |= CY_AS_DEVICE_STATE_IN_SETUP_PACKET)
       
   667 #define CyAsDeviceClearSetupPacket(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_IN_SETUP_PACKET)
       
   668 
       
   669 #define CyAsDeviceIsEp0Stalled(dp) ((dp)->state & CY_AS_DEVICE_STATE_EP0_STALLED)
       
   670 #define CyAsDeviceSetEp0Stalled(dp) ((dp)->state |= CY_AS_DEVICE_STATE_EP0_STALLED)
       
   671 #define CyAsDeviceClearEp0Stalled(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_EP0_STALLED)
       
   672 
       
   673 #define CyAsDeviceIsRegisterStandby(dp) ((dp)->state & CY_AS_DEVICE_STATE_REGISTER_STANDBY)
       
   674 #define CyAsDeviceSetRegisterStandby(dp) ((dp)->state |= CY_AS_DEVICE_STATE_REGISTER_STANDBY)
       
   675 #define CyAsDeviceClearRegisterStandby(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_REGISTER_STANDBY)
       
   676 
       
   677 #define CyAsDeviceIsPinStandby(dp) ((dp)->state & CY_AS_DEVICE_STATE_PIN_STANDBY)
       
   678 #define CyAsDeviceSetPinStandby(dp) ((dp)->state |= CY_AS_DEVICE_STATE_PIN_STANDBY)
       
   679 #define CyAsDeviceClearPinStandby(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_PIN_STANDBY)
       
   680 
       
   681 #define CyAsDeviceIsCrystal(dp) ((dp)->state & CY_AS_DEVICE_STATE_CRYSTAL)
       
   682 #define CyAsDeviceIsExternalClock(dp) (!((dp)->state & CY_AS_DEVICE_STATE_CRYSTAL))
       
   683 #define CyAsDeviceSetCrystal(dp) ((dp)->state |= CY_AS_DEVICE_STATE_CRYSTAL)
       
   684 #define CyAsDeviceSetExternalClock(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_CRYSTAL)
       
   685 
       
   686 #define CyAsDeviceIsWaking(dp) ((dp)->state & CY_AS_DEVICE_STATE_WAKING)
       
   687 #define CyAsDeviceSetWaking(dp) ((dp)->state |= CY_AS_DEVICE_STATE_WAKING)
       
   688 #define CyAsDeviceClearWaking(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_WAKING)
       
   689 
       
   690 #define CyAsDeviceIsInSuspendMode(dp) ((dp)->state & CY_AS_DEVICE_STATE_SUSPEND)
       
   691 #define CyAsDeviceSetSuspendMode(dp) ((dp)->state |= CY_AS_DEVICE_STATE_SUSPEND)
       
   692 #define CyAsDeviceClearSuspendMode(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_SUSPEND)
       
   693 
       
   694 #define CyAsDeviceIsResetPending(dp) ((dp)->state & CY_AS_DEVICE_STATE_RESETP)
       
   695 #define CyAsDeviceSetResetPending(dp) ((dp)->state |= CY_AS_DEVICE_STATE_RESETP)
       
   696 #define CyAsDeviceClearResetPending(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_RESETP)
       
   697 
       
   698 #define CyAsDeviceIsStandbyPending(dp) ((dp)->state & CY_AS_DEVICE_STATE_STANDP)
       
   699 #define CyAsDeviceSetStandbyPending(dp) ((dp)->state |= CY_AS_DEVICE_STATE_STANDP)
       
   700 #define CyAsDeviceClearStandbyPending(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_STANDP)
       
   701 
       
   702 #define CyAsDeviceIsSSSPending(dp) ((dp)->state & CY_AS_DEVICE_STATE_SSSP)
       
   703 #define CyAsDeviceSetSSSPending(dp) ((dp)->state |= CY_AS_DEVICE_STATE_SSSP)
       
   704 #define CyAsDeviceClearSSSPending(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_SSSP)
       
   705 
       
   706 #define CyAsDeviceIsUSSPending(dp) ((dp)->state & CY_AS_DEVICE_STATE_USSP)
       
   707 #define CyAsDeviceSetUSSPending(dp) ((dp)->state |= CY_AS_DEVICE_STATE_USSP)
       
   708 #define CyAsDeviceClearUSSPending(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_USSP)
       
   709 
       
   710 #define CyAsDeviceIsMSSPending(dp) ((dp)->state & CY_AS_DEVICE_STATE_MSSP)
       
   711 #define CyAsDeviceSetMSSPending(dp) ((dp)->state |= CY_AS_DEVICE_STATE_MSSP)
       
   712 #define CyAsDeviceClearMSSPending(dp) ((dp)->state &= ~CY_AS_DEVICE_STATE_MSSP)
       
   713 
       
   714 #define CyAsDeviceIsUsbAsyncPending(dp, ep) ((dp)->epasync & (1 << ep))
       
   715 #define CyAsDeviceSetUsbAsyncPending(dp, ep) ((dp)->epasync |= (1 << ep))
       
   716 #define CyAsDeviceClearUsbAsyncPending(dp, ep) ((dp)->epasync &= ~(1 << ep))
       
   717 
       
   718 #define CyAsDeviceIsNandStorageSupported(dp) ((dp)->media_supported[0] & 1)
       
   719 
       
   720 /* Macros to check the type of West Bridge device. */
       
   721 #define CyAsDeviceIsAstoriaDev(dp) (((dp)->silicon_id == CY_AS_MEM_CM_WB_CFG_ID_HDID_ASTORIA_VALUE) || \
       
   722         ((dp)->silicon_id == CY_AS_MEM_CM_WB_CFG_ID_HDID_ASTORIA_FPGA_VALUE))
       
   723 #define CyAsDeviceIsAntiochDev(dp) ((dp)->silicon_id == CY_AS_MEM_CM_WB_CFG_ID_HDID_ANTIOCH_VALUE)
       
   724 
       
   725 #ifdef CY_AS_LOG_SUPPORT
       
   726 extern void CyAsLogDebugMessage(int value, const char *msg) ;
       
   727 #else
       
   728 #define CyAsLogDebugMessage(value, msg)
       
   729 #endif
       
   730 
       
   731 /* Summary
       
   732    This function finds the device object given the HAL tag
       
   733 
       
   734    Description
       
   735    The user associats a device TAG with each West Bridge device created.  This tag is passed from the
       
   736    API functions to and HAL functions that need to ID a specific West Bridge device.  This tag is also
       
   737    passed in from the user back into the API via interrupt functions.  This function allows the API
       
   738    to find the device structure associated with a given tag.
       
   739 
       
   740    Notes
       
   741    This function does a simple linear search for the device based on the TAG.  This function is
       
   742    called each time an West Bridge interrupt handler is called.  Therefore this works fine for a small
       
   743    number of West Bridge devices (e.g. less than five).  Anything more than this and this methodology
       
   744    will need to be updated.
       
   745 
       
   746    Returns
       
   747    Pointer to a CyAsDevice associated with the tag
       
   748 */
       
   749 extern CyAsDevice *
       
   750 CyAsDeviceFindFromTag(
       
   751         CyAsHalDeviceTag tag
       
   752         ) ;
       
   753 
       
   754 #include "cyas_cplus_end.h"
       
   755 
       
   756 #endif          /* __INCLUDED_CYASDEVICE_H__ */