0
|
1 |
/*
|
|
2 |
* sdioclient.cpp
|
|
3 |
*
|
|
4 |
* Copyright(c) 1998 - 2010 Texas Instruments. All rights reserved.
|
|
5 |
* All rights reserved.
|
|
6 |
*
|
|
7 |
* This program and the accompanying materials are made available under the
|
|
8 |
* terms of the Eclipse Public License v1.0 or BSD License which accompanies
|
|
9 |
* this distribution. The Eclipse Public License is available at
|
|
10 |
* http://www.eclipse.org/legal/epl-v10.html and the BSD License is as below.
|
|
11 |
*
|
|
12 |
* Redistribution and use in source and binary forms, with or without
|
|
13 |
* modification, are permitted provided that the following conditions
|
|
14 |
* are met:
|
|
15 |
*
|
|
16 |
* * Redistributions of source code must retain the above copyright
|
|
17 |
* notice, this list of conditions and the following disclaimer.
|
|
18 |
* * Redistributions in binary form must reproduce the above copyright
|
|
19 |
* notice, this list of conditions and the following disclaimer in
|
|
20 |
* the documentation and/or other materials provided with the
|
|
21 |
* distribution.
|
|
22 |
* * Neither the name Texas Instruments nor the names of its
|
|
23 |
* contributors may be used to endorse or promote products derived
|
|
24 |
* from this software without specific prior written permission.
|
|
25 |
*
|
|
26 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
27 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
28 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
29 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
30 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
31 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
32 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
33 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
34 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
35 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
36 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
37 |
*/
|
|
38 |
|
|
39 |
#include "TxnDefs.h"
|
|
40 |
#include <stdlib.h>
|
|
41 |
#include <regifc.h>
|
|
42 |
|
|
43 |
#include "osApi.h"
|
|
44 |
#include "wlanosa.h"
|
|
45 |
#include "wlanosaext.h"
|
|
46 |
|
|
47 |
#include "SDioClient.h"
|
|
48 |
#include "sdiodrv.h"
|
|
49 |
|
|
50 |
/************************************************************************
|
|
51 |
* Defines
|
|
52 |
************************************************************************/
|
|
53 |
|
|
54 |
/* To debug SdioClient, define some prints here */
|
|
55 |
#define TRACE(msg)
|
|
56 |
#ifndef _SYMBIAN_
|
|
57 |
#define ERROR_TRACE(msg)
|
|
58 |
#else
|
|
59 |
#define ERROR_TRACE(msg) Kern::Printf(msg);
|
|
60 |
#endif
|
|
61 |
|
|
62 |
/* Sync/Async Threshold */
|
|
63 |
#ifdef FULL_ASYNC_MODE
|
|
64 |
#define SYNC_ASYNC_LENGTH_THRESH 0 /* Use Async for all transactions */
|
|
65 |
#else
|
|
66 |
#define SYNC_ASYNC_LENGTH_THRESH 360 /* Use Async for transactions longer than this threshold (in bytes) */
|
|
67 |
#endif
|
|
68 |
|
|
69 |
SDioClient* SDioClient::mSdioClient = NULL;
|
|
70 |
|
|
71 |
/**
|
|
72 |
* \fn SdioClient::SdioClient
|
|
73 |
* \brief Constructor
|
|
74 |
*
|
|
75 |
*
|
|
76 |
*
|
|
77 |
* \note
|
|
78 |
* \param
|
|
79 |
* \return handle to Sdioclient. NULL on failure.
|
|
80 |
* \sa
|
|
81 |
*/
|
|
82 |
SDioClient::SDioClient() : WlanSpia(),
|
|
83 |
iSessionEndCallback(SDioClient::SessionEndCallback, this)
|
|
84 |
|
|
85 |
{
|
|
86 |
iSocketP = static_cast< DSDIOSocket* >(DPBusSocket::SocketFromId(0));
|
|
87 |
iStackP = static_cast< DSDIOStack* >(iSocketP->Stack(0));
|
|
88 |
iCardP = static_cast< TSDIOCard* >(iStackP->CardP(0));
|
|
89 |
|
|
90 |
|
|
91 |
TRACE(("iSocketP 0x%x iStackP 0x%x iCardP 0x%x", iSocketP, iStackP, iCardP))
|
|
92 |
|
|
93 |
}
|
|
94 |
|
|
95 |
|
|
96 |
SDioClient* SDioClient::Create(MWlanOsaExt &aOsaExt)
|
|
97 |
{
|
|
98 |
if (mSdioClient == NULL) {
|
|
99 |
mSdioClient = new SDioClient();
|
|
100 |
}
|
|
101 |
|
|
102 |
mSdioClient->mWlanOsaExt = &aOsaExt;
|
|
103 |
|
|
104 |
return mSdioClient;
|
|
105 |
}
|
|
106 |
|
|
107 |
|
|
108 |
SDioClient* SDioClient::Create()
|
|
109 |
{
|
|
110 |
if (mSdioClient == NULL) {
|
|
111 |
mSdioClient = new SDioClient();
|
|
112 |
}
|
|
113 |
|
|
114 |
return mSdioClient;
|
|
115 |
}
|
|
116 |
|
|
117 |
void SDioClient::Destroy()
|
|
118 |
{
|
|
119 |
if (mSdioClient) {
|
|
120 |
delete mSdioClient;
|
|
121 |
mSdioClient = NULL;
|
|
122 |
}
|
|
123 |
}
|
|
124 |
|
|
125 |
/**
|
|
126 |
* \fn SdioClient::SessionEndCallback
|
|
127 |
* \brief
|
|
128 |
*
|
|
129 |
* CallBack.
|
|
130 |
*
|
|
131 |
* \note
|
|
132 |
* \param
|
|
133 |
* \return No return value.
|
|
134 |
* \sa
|
|
135 |
*/
|
|
136 |
void SDioClient::SessionEndCallback(TAny* ptr)
|
|
137 |
{
|
|
138 |
SDioClient *hClient = (SDioClient *)ptr;
|
|
139 |
|
|
140 |
mSdioClient->mWlanOsaExt->MutexAcquire();
|
|
141 |
|
|
142 |
if (hClient->afCbFunc)
|
|
143 |
{
|
|
144 |
hClient->afCbFunc(hClient->ahCbArg,0);
|
|
145 |
}
|
|
146 |
else
|
|
147 |
{
|
|
148 |
ERROR_TRACE(("SDioClient::SessionEndCallback - NoCallback"))
|
|
149 |
}
|
|
150 |
|
|
151 |
mSdioClient->mWlanOsaExt->MutexRelease();
|
|
152 |
}
|
|
153 |
|
|
154 |
/**
|
|
155 |
* \fn SdioClient::sdioAdapt_ConnectBus
|
|
156 |
* \brief
|
|
157 |
*
|
|
158 |
* Initialize HW.
|
|
159 |
*
|
|
160 |
* \note
|
|
161 |
* \param
|
|
162 |
* \return KErrNone if success otherwise error.
|
|
163 |
* \sa
|
|
164 |
*/
|
|
165 |
int SDioClient::sdioAdapt_ConnectBus (TAny* fCbFunc,
|
|
166 |
TAny* hCbArg,
|
|
167 |
unsigned int uBlkSizeShift,
|
|
168 |
unsigned int uSdioThreadPriority)
|
|
169 |
{
|
|
170 |
afCbFunc = (TTxnDoneCb1)fCbFunc;
|
|
171 |
ahCbArg = hCbArg;
|
|
172 |
|
|
173 |
iSocketP->PowerUp();
|
|
174 |
|
|
175 |
TUint32 regValue = 4;
|
|
176 |
TUint8 reply;
|
|
177 |
TUint8 loopCounter = 0;
|
|
178 |
int iStatus = KErrNone;
|
|
179 |
TUint8 aReadDataP;
|
|
180 |
|
|
181 |
iCardP->CommonRegisterInterface()->SetSync();
|
|
182 |
|
|
183 |
do
|
|
184 |
{
|
|
185 |
iStatus = (iCardP->CommonRegisterInterface())->Write8(0x02, regValue, &aReadDataP );
|
|
186 |
if(iStatus != KErrNone)
|
|
187 |
ERROR_TRACE(("SDioClient::sdioAdapt_ConnectBus Error 1"))
|
|
188 |
|
|
189 |
iStatus = (iCardP->CommonRegisterInterface())->Read8(0x02,&reply);
|
|
190 |
if(iStatus != KErrNone)
|
|
191 |
ERROR_TRACE(("SDioClient::sdioAdapt_ConnectBus Error 2"))
|
|
192 |
|
|
193 |
loopCounter++;
|
|
194 |
|
|
195 |
}while (reply!=regValue && loopCounter < 5);
|
|
196 |
|
|
197 |
|
|
198 |
// Set function number 2
|
|
199 |
(iCardP->CommonRegisterInterface())->SetFunctionNumber(2);
|
|
200 |
|
|
201 |
return iStatus;
|
|
202 |
}
|
|
203 |
|
|
204 |
/**
|
|
205 |
* \fn SdioClient::sdioAdapt_DisconnectBus
|
|
206 |
* \brief
|
|
207 |
*
|
|
208 |
* DeInitialize HW.
|
|
209 |
*
|
|
210 |
* \note
|
|
211 |
* \param
|
|
212 |
* \return KErrNone if success otherwise error.
|
|
213 |
* \sa
|
|
214 |
*/
|
|
215 |
int SDioClient::sdioAdapt_DisconnectBus (void)
|
|
216 |
{
|
|
217 |
int iStatus = KErrNone;
|
|
218 |
return iStatus;
|
|
219 |
}
|
|
220 |
|
|
221 |
/**
|
|
222 |
* \fn SdioClient::sdioAdapt_Transact
|
|
223 |
* \brief
|
|
224 |
*
|
|
225 |
* Transaction of multiple bytes.
|
|
226 |
*
|
|
227 |
* \note
|
|
228 |
* \param
|
|
229 |
* \return TXN_STATUS_COMPLETE if transaction copleted,
|
|
230 |
* TXN_STATUS_PENDING if transaction is pending,
|
|
231 |
* TXN_STATUS_ERROR if error.
|
|
232 |
* \sa
|
|
233 |
*/
|
|
234 |
ETxnStatus SDioClient::sdioAdapt_Transact (unsigned int uFuncId,
|
|
235 |
unsigned int uHwAddr,
|
|
236 |
void * pHostAddr,
|
|
237 |
unsigned int uLength,
|
|
238 |
unsigned int bDirection,
|
|
239 |
unsigned int bBlkMode,
|
|
240 |
unsigned int bFixedAddr,
|
|
241 |
unsigned int bMore)
|
|
242 |
{
|
|
243 |
int iStatus = KErrNone;
|
|
244 |
|
|
245 |
TInt err = KErrNone;
|
|
246 |
|
|
247 |
/* If transction length is below threshold, use Sync methods */
|
|
248 |
if (uLength <= SYNC_ASYNC_LENGTH_THRESH) /* Stating with sunc calls, after this async calls will be enabled*/
|
|
249 |
{
|
|
250 |
iCardP->CommonRegisterInterface()->SetSync();
|
|
251 |
if (bDirection)
|
|
252 |
{
|
|
253 |
iStatus = (iCardP->CommonRegisterInterface())->ReadMultiple8(uHwAddr, (TUint8*)pHostAddr,(TUint32)uLength, bFixedAddr);
|
|
254 |
}
|
|
255 |
else
|
|
256 |
{
|
|
257 |
iStatus = (iCardP->CommonRegisterInterface())->WriteMultiple8(uHwAddr, (TUint8*)pHostAddr, (TUint32)uLength, bFixedAddr );
|
|
258 |
}
|
|
259 |
/* If failed return ERROR, if succeeded return COMPLETE */
|
|
260 |
if (iStatus != KErrNone)
|
|
261 |
{
|
|
262 |
ERROR_TRACE(("SDioClient::sdioAdapt_Transact Error"))
|
|
263 |
return TXN_STATUS_ERROR;
|
|
264 |
}
|
|
265 |
// Using synchronous interface of SDIO stack. Hence complete the request here.
|
|
266 |
Kern::RequestComplete(iClient, iReqStatus, err);
|
|
267 |
}
|
|
268 |
|
|
269 |
/* If transction length is above threshold, use Async methods */
|
|
270 |
else
|
|
271 |
{
|
|
272 |
if ((iCardP->CommonRegisterInterface()->SetAsync(iSessionEndCallback)) != TRUE )
|
|
273 |
{
|
|
274 |
ERROR_TRACE(("SDioClient::sdioAdapt_Transact - SetAsync - Fail"))
|
|
275 |
}
|
|
276 |
|
|
277 |
/* Call read or write Async method */
|
|
278 |
if (bDirection)
|
|
279 |
{
|
|
280 |
iStatus = (iCardP->CommonRegisterInterface())->ReadMultiple8(uHwAddr, (TUint8*)pHostAddr,(TUint32)uLength, bFixedAddr );
|
|
281 |
}
|
|
282 |
else
|
|
283 |
{
|
|
284 |
iStatus = (iCardP->CommonRegisterInterface())->WriteMultiple8(uHwAddr, (TUint8*)pHostAddr,(TUint32)uLength, bFixedAddr );
|
|
285 |
}
|
|
286 |
|
|
287 |
/* If failed return ERROR, if succeeded return PENDING */
|
|
288 |
if (iStatus != KErrNone)
|
|
289 |
{
|
|
290 |
ERROR_TRACE(("SDioClient::sdioAdapt_Transact - ASYNC - ERROR\n"))
|
|
291 |
return TXN_STATUS_ERROR;
|
|
292 |
}
|
|
293 |
return TXN_STATUS_PENDING;
|
|
294 |
}
|
|
295 |
return TXN_STATUS_COMPLETE;
|
|
296 |
}
|
|
297 |
|
|
298 |
/**
|
|
299 |
* \fn SdioClient::sdioAdapt_TransactBytes
|
|
300 |
* \brief
|
|
301 |
*
|
|
302 |
* Transaction of bytes.
|
|
303 |
*
|
|
304 |
* \note
|
|
305 |
* \param
|
|
306 |
* \return TXN_STATUS_COMPLETE if transaction copleted,
|
|
307 |
* TXN_STATUS_ERROR if error.
|
|
308 |
* \sa
|
|
309 |
*/
|
|
310 |
ETxnStatus SDioClient::sdioAdapt_TransactBytes (unsigned int uFuncId,
|
|
311 |
unsigned int uHwAddr,
|
|
312 |
void * pHostAddr,
|
|
313 |
unsigned int uLength,
|
|
314 |
unsigned int bDirection,
|
|
315 |
unsigned int bMore)
|
|
316 |
{
|
|
317 |
|
|
318 |
int iStatus = KErrNone;
|
|
319 |
TInt err = KErrNone;
|
|
320 |
/* Call read or write bytes Sync method */
|
|
321 |
if (bDirection)
|
|
322 |
{
|
|
323 |
iStatus = (iCardP->CommonRegisterInterface())->Read8(uHwAddr, (TUint8*)pHostAddr);
|
|
324 |
}
|
|
325 |
else
|
|
326 |
{
|
|
327 |
iStatus = (iCardP->CommonRegisterInterface())->Write8(uHwAddr, *((TUint8*)pHostAddr), NULL );
|
|
328 |
}
|
|
329 |
|
|
330 |
/* If failed return ERROR, if succeeded return COMPLETE */
|
|
331 |
if (iStatus != KErrNone)
|
|
332 |
{
|
|
333 |
ERROR_TRACE(("SDioClient::sdioAdapt_TransactBytes - ERROR\n"))
|
|
334 |
return TXN_STATUS_ERROR;
|
|
335 |
}
|
|
336 |
|
|
337 |
// Using synchronous interface of SDIO stack. Hence complete the request here.
|
|
338 |
Kern::RequestComplete(iClient, iReqStatus, err);
|
|
339 |
|
|
340 |
return TXN_STATUS_COMPLETE;
|
|
341 |
}
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
/***************************************************************************************/
|
|
347 |
/* Create dummy implamantaion for SPIA pure virtual function
|
|
348 |
Remove all SPIA dependency when SDIOA will be published.
|
|
349 |
*/
|
|
350 |
|
|
351 |
WlanSpia* WlanSpia::Create( MWlanOsaExt& aOsaExt )
|
|
352 |
{
|
|
353 |
return (SDioClient *)SDioClient::Create(aOsaExt);
|
|
354 |
}
|
|
355 |
|
|
356 |
WlanSpia* WlanSpia::Create()
|
|
357 |
{
|
|
358 |
return (SDioClient *)SDioClient::Create();
|
|
359 |
}
|
|
360 |
|
|
361 |
void WlanSpia::Destroy( WlanSpia* aWlanSpia )
|
|
362 |
{
|
|
363 |
SDioClient::Destroy();
|
|
364 |
}
|
|
365 |
|
|
366 |
|