1981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
2981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * WspiBusDrv.c
3981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
4981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.
5981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * All rights reserved.
6981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
7981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Redistribution and use in source and binary forms, with or without
8981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * modification, are permitted provided that the following conditions
9981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * are met:
10981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
11981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Redistributions of source code must retain the above copyright
12981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    notice, this list of conditions and the following disclaimer.
13981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Redistributions in binary form must reproduce the above copyright
14981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    notice, this list of conditions and the following disclaimer in
15981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    the documentation and/or other materials provided with the
16981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    distribution.
17981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Neither the name Texas Instruments nor the names of its
18981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    contributors may be used to endorse or promote products derived
19981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    from this software without specific prior written permission.
20981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
21981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
33981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
34981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
35981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/** \file   WspiBusDrv.c
36981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  \brief  The WSPI bus driver upper layer. Platform independent.
37981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *          Uses the SpiAdapter API.
38981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *          Introduces a generic bus-independent API upwards.
39981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
40981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  \see    BusDrv.h, SpiAdapter.h, SpiAdapter.c
41981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
42981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
43981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "tidef.h"
44981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "report.h"
45981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "osApi.h"
46981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "wspi.h"
47981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "BusDrv.h"
48981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "TxnDefs.h"
49981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define __FILE_ID__		FILE_ID_124
50981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
51981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/************************************************************************
52981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Defines
53981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ************************************************************************/
54981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define WSPI_FIXED_BUSY_LEN     1
55981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define WSPI_INIT_CMD_MASK      0
56981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
57981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
58981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/************************************************************************
59981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Types
60981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ************************************************************************/
61981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
62981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* The busDrv module Object */
63981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidttypedef struct _TBusDrvObj
64981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
65981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_HANDLE	    hOs;
66981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_HANDLE	    hReport;
67981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	TI_HANDLE	    hDriver;
68981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	TI_HANDLE	    hWspi;
69981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
70981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	TTxnDoneCb      fTxnDoneCb;         /* The callback to call upon full transaction completion. */
71981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	TI_HANDLE       hCbHandle;          /* The callback handle */
72981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TTxnStruct *    pCurrTxn;           /* The transaction currently being processed */
73981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS       eCurrTxnStatus;     /* COMPLETE, PENDING or ERROR */
74981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32       uCurrTxnBufsCount;
75981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_BOOL         bPendingByte;
76981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TTxnDoneCb      fTxnConnectDoneCb;         /* The callback to call upon full transaction completion. */
77981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
78981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
79981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} TBusDrvObj;
80981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
81981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
82981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/************************************************************************
83981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Internal functions prototypes
84981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ************************************************************************/
85981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
86981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void asyncEnded_CB(TI_HANDLE hBusTxn, int status);
87981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void ConnectDone_CB(TI_HANDLE hBusDrv, int status);
88981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
89981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/************************************************************************
90981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
91981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *   Module functions implementation
92981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
93981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ************************************************************************/
94981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
95981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
96981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     busDrv_Create
97981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Create the module
98981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
99981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Allocate and clear the module's object.
100981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
101981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
102981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hOs - Handle to Os Abstraction Layer
103981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return Handle of the allocated object, NULL if allocation failed
104981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     busDrv_Destroy
105981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
106981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_HANDLE busDrv_Create (TI_HANDLE hOs)
107981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
108981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_HANDLE   hBusDrv;
109981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TBusDrvObj *pBusDrv;
110981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
111981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    hBusDrv = os_memoryAlloc(hOs, sizeof(TBusDrvObj));
112981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (hBusDrv == NULL)
113981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return NULL;
114981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
115981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pBusDrv = (TBusDrvObj *)hBusDrv;
116981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
117981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    os_memoryZero(hOs, hBusDrv, sizeof(TBusDrvObj));
118981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
119981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pBusDrv->hOs = hOs;
120981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
121981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    // addapt to WSPI
122981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
123981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pBusDrv->hWspi= WSPI_Open(hOs);
124981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
125981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return pBusDrv;
126981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
127981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
128981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
129981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
130981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     busDrv_Destroy
131981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Destroy the module.
132981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
133981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Close SPI lower bus driver and free the module's object.
134981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
135981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
136981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  The module's object
137981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return TI_OK on success or TI_NOK on failure
138981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     busDrv_Create
139981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
140981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS busDrv_Destroy (TI_HANDLE hBusDrv)
141981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
142981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TBusDrvObj *pBusDrv = (TBusDrvObj*)hBusDrv;
143981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
144981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pBusDrv)
145981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
146981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        // addapt to WSPI
147981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        WSPI_Close(pBusDrv->hWspi);
148981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        os_memoryFree (pBusDrv->hOs, pBusDrv, sizeof(TBusDrvObj));
149981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
150981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TI_OK;
151981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
152981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
153981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
154981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/****************************************************************************
155981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                      busDrv_Init
156981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************
157981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DESCRIPTION: config the module.
158981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
159981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * INPUTS:  hBusDrv - handle to the module context
160981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *          hReport - handle to report module context that is used when we output debug messages
161981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *          CBFunc  - The callback to call upon transaction complete (calls the tasklet).
162981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *          CBArg   - The handle for the CBFunc.
163981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
164981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OUTPUT:  none.
165981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
166981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * RETURNS: one of the error codes (0 => TI_OK)
167981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************/
168981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid busDrv_Init (TI_HANDLE    hBusDrv,
169981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                       TI_HANDLE    hReport)
170981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
171981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TBusDrvObj *pBusDrv = (TBusDrvObj*) hBusDrv;
172981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
173981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
174981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
175981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pBusDrv->hReport    = hReport;
176981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
177981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
178981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
179981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
180981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
181981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
182981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
183981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
184981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
185981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
186981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
187981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     busDrv_ConnectBus
188981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Configure bus driver
189981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
190981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Called by TxnQ.
191981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Configure the bus driver with its connection configuration (such as baud-rate, bus width etc)
192981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *     and establish the physical connection.
193981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Done once upon init (and not per functional driver startup).
194981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
195981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
196981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hBusDrv    - The module's object
197981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pBusDrvCfg - A union used for per-bus specific configuration.
198981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  fCbFunc    - CB function for Async transaction completion (after all txn parts are completed).
199981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hCbArg     - The CB function handle
200981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return TI_OK / TI_NOK
201981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa
202981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
203981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS busDrv_ConnectBus (TI_HANDLE        hBusDrv,
204981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                             TBusDrvCfg       *pBusDrvCfg,
205981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                             TBusDrvTxnDoneCb fCbFunc,
206981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                             TI_HANDLE        hCbArg,
207981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                             TBusDrvTxnDoneCb fConnectCbFunc
208981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                             )
209981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
210981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TBusDrvObj *pBusDrv = (TBusDrvObj*)hBusDrv;
211981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    int         iStatus;
212981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    WSPIConfig_t wspi_config;
213981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    WSPI_CB_T cb;
214981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
215981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Save the parameters (TxnQ callback for TxnDone events) */
216981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pBusDrv->fTxnDoneCb    = fCbFunc;
217981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pBusDrv->hCbHandle     = hCbArg;
218981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pBusDrv->fTxnConnectDoneCb = fConnectCbFunc;
219981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
220981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Configure the WSPI driver parameters  */
221981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
222981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    wspi_config.isFixedAddress = TI_FALSE;
223981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    wspi_config.fixedBusyLength = WSPI_FIXED_BUSY_LEN;
224981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    wspi_config.mask = WSPI_INIT_CMD_MASK;
225981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
226981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    cb.CBFunc = ConnectDone_CB;/* The BusTxn callback called upon Async transaction end. */
227981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    cb.CBArg  = hBusDrv;   /* The handle for the BusDrv. */
228981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
229981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Configure the WSPI module */
230981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    iStatus = WSPI_Configure(pBusDrv->hWspi, pBusDrv->hReport, &wspi_config, &cb);
231981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
232981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
233981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if ((iStatus == 0) || (iStatus == 1))
234981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
235981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE1 (pBusDrv->hReport, REPORT_SEVERITY_INIT, "busDrv_ConnectBus: called Status %d\n",iStatus);
236981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
237981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
238981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE2 (pBusDrv->hReport, REPORT_SEVERITY_INFORMATION, "busDrv_ConnectBus: Successful Status %d\n",iStatus);
239981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_OK;
240981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
241981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    else
242981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
243981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE2(pBusDrv->hReport, REPORT_SEVERITY_ERROR, "busDrv_ConnectBus: Status = %d,\n", iStatus);
244981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
245981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
246981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
247981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
248981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     busDrv_DisconnectBus
249981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Disconnect SDIO driver
250981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
251981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Called by TxnQ. Disconnect the SDIO driver.
252981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
253981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note
254981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hBusDrv - The module's object
255981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return TI_OK / TI_NOK
256981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa
257981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
258981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS   busDrv_DisconnectBus   (TI_HANDLE hBusDrv)
259981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
260981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TI_OK;
261981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
262981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
263981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
264981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
265981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     busDrv_Transact
266981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Process transaction
267981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
268981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Called by the TxnQ module to initiate a new transaction.
269981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Call either write or read functions according to Txn direction field.
270981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
271981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \note   It's assumed that this function is called only when idle (i.e. previous Txn is done).
272981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hBusDrv - The module's object
273981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  pTxn    - The transaction object
274981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return COMPLETE if Txn completed in this context, PENDING if not, ERROR if failed
275981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     busDrv_PrepareTxnParts, busDrv_SendTxnParts
276981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
277981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtETxnStatus busDrv_Transact (TI_HANDLE hBusDrv, TTxnStruct *pTxn)
278981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
279981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TBusDrvObj *pBusDrv = (TBusDrvObj*)hBusDrv;
280981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    WSPI_CB_T cb;
281981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT8 * tempReadBuff;
282981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT8 * tempWriteBuff;
283981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pBusDrv->pCurrTxn       = pTxn;
284981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pBusDrv->eCurrTxnStatus = TXN_STATUS_COMPLETE;  /* The Txn is Sync as long as it continues in this context */
285981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    cb.CBFunc = asyncEnded_CB;  /* The BusTxn callback called upon Async transaction end. */
286981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    cb.CBArg  = hBusDrv;   /* The handle for the BusTxnCB. */
287981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
288981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* If write command */
289981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (TXN_PARAM_GET_DIRECTION(pTxn) == TXN_DIRECTION_WRITE)
290981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
291981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
292981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        //WLAN_REPORT_INIT(pBusDrv->hReport, TNETW_DRV_MODULE_LOG,
293981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        //    ("busDrv_Transact:  Write to pTxn->uHwAddr %x\n", pTxn->uHwAddr ));
294981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
295981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
296981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         /*WLAN_REPORT_ERROR(pBusDrv->hReport, BUS_DRV_MODULE_LOG,
297981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            ("busDrv_Transact: Buff= %x, Len=%d\n", pTxn->aBuf[0], pTxn->aLen[0]));*/
298981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*1.write memory*/
299981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt          /* Decrease the data pointer to the beginning of the WSPI padding */
300981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt          tempWriteBuff = pTxn->aBuf[0];
301981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt          tempWriteBuff -= WSPI_PAD_LEN_WRITE;
302981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
303981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt          /* Write the data to the WSPI in Aync mode (not completed in the current context). */
304981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt          pBusDrv->eCurrTxnStatus = WSPI_WriteAsync(pBusDrv->hWspi, pTxn->uHwAddr,tempWriteBuff,pTxn->aLen[0], &cb, TI_TRUE, TI_TRUE,TXN_PARAM_GET_FIXED_ADDR(pTxn));
305981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
306981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
307981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
308981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* If read command */
309981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    else
310981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
311981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        //WLAN_REPORT_INIT(pBusDrv->hReport, TNETW_DRV_MODULE_LOG,
312981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        //    ("busDrv_Transact:  Read from pTxn->uHwAddr %x pTxn %x \n", pTxn->uHwAddr,pTxn));
313981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
314981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*1. Read mem */
315981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         /* Decrease the tempReadBuff pointer to the beginning of the WSPI padding */
316981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        tempReadBuff = pTxn->aBuf[0];
317981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        tempReadBuff -= WSPI_PAD_LEN_READ;
318981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Read the required data from the WSPI in Aync mode (not completed in the current context). */
319981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pBusDrv->eCurrTxnStatus  = WSPI_ReadAsync(pBusDrv->hWspi, pTxn->uHwAddr,tempReadBuff,pTxn->aLen[0], &cb, TI_TRUE, TI_TRUE,TXN_PARAM_GET_FIXED_ADDR(pTxn));
320981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
321981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
322981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
323981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
324981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* return transaction status - COMPLETE, PENDING or ERROR */
325981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return (pBusDrv->eCurrTxnStatus == WSPI_TXN_COMPLETE ? TXN_STATUS_COMPLETE :
326981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt			(pBusDrv->eCurrTxnStatus == WSPI_TXN_PENDING ? TXN_STATUS_PENDING : TXN_STATUS_ERROR));
327981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
328981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
329981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
330981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
331981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
332981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/****************************************************************************
333981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                      asyncEnded_CB()
334981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************
335981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DESCRIPTION:
336981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *      Called back by the WSPI driver from Async transaction end interrupt (ISR context).
337981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *      Calls the upper layers callback.
338981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
339981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * INPUTS:  status -
340981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
341981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OUTPUT:  None
342981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
343981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * RETURNS: None
344981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************/
345981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void asyncEnded_CB(TI_HANDLE hBusDrv, int status)
346981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
347981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TBusDrvObj *pBusDrv = (TBusDrvObj*)hBusDrv;
348981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* If the last transaction failed, call failure CB and exit. */
349981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (status != 0)
350981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
351981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE2(pBusDrv->hReport, REPORT_SEVERITY_ERROR, "asyncEnded_CB : Status = %d, fTxnDoneCb = 0x%x\n", status,pBusDrv->fTxnDoneCb);
352981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
353981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TXN_PARAM_SET_STATUS(pBusDrv->pCurrTxn, TXN_PARAM_STATUS_ERROR);
354981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
355981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	else
356981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	{
357981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		TRACE2(pBusDrv->hReport, REPORT_SEVERITY_INFORMATION,"asyncEnded_CB: Successful async cb done pBusDrv->pCurrTxn %x\n", pBusDrv->pCurrTxn);
358981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	}
359981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
360981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Call the upper layer CB */
361981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
362981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pBusDrv->fTxnDoneCb(pBusDrv->hCbHandle,pBusDrv->pCurrTxn);
363981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
364981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
365981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
366981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/****************************************************************************
367981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                      ConnectDone_CB()
368981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************
369981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DESCRIPTION:
370981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *      Called back by the WSPI driver from Async transaction end interrupt (ISR context).
371981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *      Calls the upper layers callback.
372981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
373981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * INPUTS:  status -
374981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
375981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OUTPUT:  None
376981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
377981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * RETURNS: None
378981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************/
379981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void ConnectDone_CB(TI_HANDLE hBusDrv, int status)
380981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
381981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TBusDrvObj *pBusDrv = (TBusDrvObj*)hBusDrv;
382981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* If the last transaction failed, call failure CB and exit. */
383981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (status != 0)
384981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
385981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE2(pBusDrv->hReport, REPORT_SEVERITY_ERROR, "ConnectDone_CB : Status = %d, fTxnConnectDoneCb = 0x%x\n", status,pBusDrv->fTxnConnectDoneCb);
386981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
387981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TXN_PARAM_SET_STATUS(pBusDrv->pCurrTxn, TXN_PARAM_STATUS_ERROR);
388981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
389981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	else
390981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	{
391981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		TRACE1 (pBusDrv->hReport, REPORT_SEVERITY_INIT, "ConnectDone_CB: Successful Connect Async cb done \n");
392981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	}
393981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
394981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Call the upper layer CB */
395981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
396981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pBusDrv->fTxnConnectDoneCb(pBusDrv->hCbHandle,pBusDrv->pCurrTxn);
397981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
398981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
399981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
400