Home | History | Annotate | Download | only in BusTxn
      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 #ifndef _WSPI_H_
     37 #define _WSPI_H_
     38 
     39 
     40 /*
     41  * Define this flag to use write-read SPI driver API
     42  */
     43 #define USE_WRITE_READ_API
     44 
     45 /*
     46  * Define this flag to use sync-over-async mode
     47  */
     48 #undef  USE_SYNC_OVER_ASYNC
     49 
     50 
     51 /* Return codes */
     52 typedef enum
     53 {
     54     WSPI_OK                =  0,
     55     WSPI_TXN_COMPLETE      =  0,
     56     WSPI_TXN_PENDING       =  1,
     57     WSPI_ERR_UNKNOWN       = -1,
     58     WSPI_ERR_BUS_BUSY      = -2,
     59     WSPI_ERR_QUEUE_FULL    = -3,
     60     WSPI_ERR_ALLOC_MEM     = -4,
     61     WSPI_ERR_ASYNC_TIMEOUT = -5,
     62     WSPI_ERR_WRONG_LENGTH  = -6,
     63 
     64 } WSPI_Status_e;
     65 
     66 
     67 typedef struct _WSPI_CB_t
     68 {
     69     void (*CBFunc) (void *data, int status);
     70 	void  *CBArg;
     71 
     72 } WSPI_CB_T;
     73 
     74 
     75 typedef struct _WSPIConfig_t
     76 {
     77 	int isFixedAddress;
     78 	int fixedBusyLength;
     79 	UINT8 mask;
     80 
     81 } WSPIConfig_t;
     82 
     83 
     84 /* WSPI API */
     85 TI_HANDLE WSPI_Open       (TI_HANDLE hOs);
     86 int       WSPI_Close      (TI_HANDLE hWSPI);
     87 int       WSPI_Configure  (TI_HANDLE hWSPI, TI_HANDLE hReport, const WSPIConfig_t* aConfig, WSPI_CB_T* CB);
     88 int       WSPI_ReadAsync  (TI_HANDLE hWSPI, UINT32 address, UINT8* data, UINT32 length, WSPI_CB_T* CB, BOOL bMore, BOOL bSpaceReserved);
     89 int       WSPI_WriteAsync (TI_HANDLE hWSPI, UINT32 address, UINT8* data, UINT32 length, WSPI_CB_T* CB, BOOL bMore, BOOL bSpaceReserved);
     90 void 	  WSPI_HandleFixedBusy(TI_HANDLE hWSPI, UINT32 *pRbuf);
     91 #ifdef USE_SYNC_API
     92 int       WSPI_ReadSync   (TI_HANDLE hWSPI, UINT32 address, UINT8* data, UINT32 length);
     93 int       WSPI_WriteSync  (TI_HANDLE hWSPI, UINT32 address, UINT8* data, UINT32 length);
     94 #endif
     95 void WSPI_SetErrLog (void* hWSPI, void (*fErr)(void));
     96 
     97 
     98 
     99 /* Size of WSPI command */
    100 #define WSPI_SIZEOF_CMD             4
    101 
    102 /* Used to decide whether we want to use the temp buffer in order to read/write the data */
    103 #define WSPI_NO_EXTRA_ALLOC_SIZE    4
    104 
    105 /* Init command length */
    106 #define WSPI_INIT_CMD_LEN           8
    107 
    108 /* Size of extra buffer size : 																			*/
    109 /* NumOfExtraFixedBusy * WordLen + DataLost(beacuse of fixed busy) * WordLen  = 10 * 4 + 10 * 4  = 80	*/
    110 #define WSPI_EXTRA_BUFFER_ALLOC_SIZE    80
    111 
    112 /* Define the number of bytes to be read after FIXED BUSY error without the ~Busy word */
    113 #define WSPI_EXTRA_READ_AFTER_NO_RESPONSE (28 - WSPI_NO_EXTRA_ALLOC_SIZE)
    114 
    115 /* WSPI handle */
    116 typedef struct _WSPI_t
    117 {
    118     TI_HANDLE           hOs;              /* OS wrapper */
    119     TI_HANDLE           hReport;          /* Report handler */
    120     TI_HANDLE           hSPI;             /* SPI driver handle */
    121     BOOL                bFixedAddr;       /* use fixed address */
    122     UINT32              uFixedBusyLen;    /* number of fixed busy cycles */
    123     UINT32              uFixedBusyBytes;  /* number of fixed busy bytes */
    124     UINT32              uFixedBusy;       /* fixed busy buffer */
    125     UINT8               uConfigMask;      /* configurable Mask for the Init CMD */
    126     UINT32              uCmd;             /* command word */
    127     UINT8               auInitCmd [WSPI_INIT_CMD_LEN];
    128                                           /* init command buffer */
    129     UINT8*              pTempBuf;         /* used for buffers with no extra room for command/fixed busy */
    130     UINT8*              data;             /* save the pointer to the data for read */
    131     UINT32              length;           /* save length of the buffer to be read */
    132     void              (*fCb) (void *data, int status);
    133                                           /* callback function */
    134     void               *pCb;              /* callback argument */
    135     WSPI_Status_e       status;           /* holds the current status */
    136     BOOL                bSpaceReserved;   /* extra room was saved for the fixed busy or command */
    137     BOOL                bMore;            /* indicate whether more use of the SPI is about to take place */
    138     BOOL                bUseTempBuf;      /* use temporary buffer */
    139     void              (*fErr) (void);     /* user debug error handler */
    140 
    141 	UINT8*              pExtraFixedBusyBuf;
    142 										  /* used for a seconed SPI read */
    143 										  /* for calls that returend with more FixedBusy words than allowed */
    144 	UINT32              ExtraBufLength;   /* save length of the extra buffer to be read */
    145 	int					returnStatus;	  /* return status for SPI_XXX functions. Note that return status is from type int */
    146 
    147   #ifdef USE_SYNC_OVER_ASYNC
    148     /*
    149      * NOTE: This flag MUST be volatile because its value is changed
    150      *       in the context of ISR. So, the compiler is prohibited
    151      *       to make register optimization inside the routine it polls for
    152      */
    153     volatile int        bSyncFlag;
    154   #endif
    155 
    156 } WSPI_t;
    157 
    158 
    159 #endif /* _WSPI_H_ */
    160 
    161