0
|
1 |
/*
|
|
2 |
* fwDebug.c
|
|
3 |
*
|
|
4 |
* Copyright(c) 1998 - 2010 Texas Instruments. All rights reserved.
|
|
5 |
* All rights reserved.
|
|
6 |
*
|
|
7 |
* This program and the accompanying materials are made available under the
|
|
8 |
* terms of the Eclipse Public License v1.0 or BSD License which accompanies
|
|
9 |
* this distribution. The Eclipse Public License is available at
|
|
10 |
* http://www.eclipse.org/legal/epl-v10.html and the BSD License is as below.
|
|
11 |
*
|
|
12 |
* Redistribution and use in source and binary forms, with or without
|
|
13 |
* modification, are permitted provided that the following conditions
|
|
14 |
* are met:
|
|
15 |
*
|
|
16 |
* * Redistributions of source code must retain the above copyright
|
|
17 |
* notice, this list of conditions and the following disclaimer.
|
|
18 |
* * Redistributions in binary form must reproduce the above copyright
|
|
19 |
* notice, this list of conditions and the following disclaimer in
|
|
20 |
* the documentation and/or other materials provided with the
|
|
21 |
* distribution.
|
|
22 |
* * Neither the name Texas Instruments nor the names of its
|
|
23 |
* contributors may be used to endorse or promote products derived
|
|
24 |
* from this software without specific prior written permission.
|
|
25 |
*
|
|
26 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
27 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
28 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
29 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
30 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
31 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
32 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
33 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
34 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
35 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
36 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
37 |
*/
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
/** \file FWDebug.c
|
|
42 |
*
|
|
43 |
* \see FWDebug.h
|
|
44 |
*/
|
|
45 |
|
|
46 |
#define __FILE_ID__ FILE_ID_103
|
|
47 |
#include "tidef.h"
|
|
48 |
#include "fwDebug_api.h"
|
|
49 |
#include "osApi.h"
|
|
50 |
#include "report.h"
|
|
51 |
#include "BusDrv.h"
|
|
52 |
#include "TwIf.h"
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
#define DMA_SIZE_BUF 256
|
|
57 |
|
|
58 |
typedef struct
|
|
59 |
{
|
|
60 |
TI_HANDLE hOs;
|
|
61 |
TI_HANDLE hReport;
|
|
62 |
TI_HANDLE hTwif;
|
|
63 |
|
|
64 |
TFwDubCallback fCb;
|
|
65 |
TI_HANDLE hCb;
|
|
66 |
|
|
67 |
TI_UINT8* pReadBuf;
|
|
68 |
|
|
69 |
TTxnStruct tTxn;
|
|
70 |
TI_UINT8* pDMABuf;
|
|
71 |
|
|
72 |
}TFwDebug;
|
|
73 |
|
|
74 |
/* Local functions */
|
|
75 |
static void fwDbg_WriteAddrCb (TI_HANDLE hFwDebug,TTxnStruct* pTxn);
|
|
76 |
static void fwDbg_ReadAddrCb (TI_HANDLE hFwDebug,TTxnStruct* pTxn);
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
/*
|
|
81 |
* \brief Create the FW Debug module
|
|
82 |
*
|
|
83 |
* \param hOs - Handle to OS
|
|
84 |
* \return The created object
|
|
85 |
*
|
|
86 |
* \par Description
|
|
87 |
* This function will allocate memory to FW Debug module.
|
|
88 |
*
|
|
89 |
* \sa
|
|
90 |
*/
|
|
91 |
TI_HANDLE fwDbg_Create (TI_HANDLE hOs)
|
|
92 |
{
|
|
93 |
TFwDebug* pFwDebug = (TFwDebug*)os_memoryAlloc(hOs,sizeof(TFwDebug),MemoryNormal);
|
|
94 |
if (pFwDebug == NULL)
|
|
95 |
{
|
|
96 |
return NULL;
|
|
97 |
}
|
|
98 |
os_memoryZero (hOs, pFwDebug, sizeof(TFwDebug));
|
|
99 |
pFwDebug->hOs = hOs;
|
|
100 |
|
|
101 |
/* Allocate DMA memory for read write transact */
|
|
102 |
pFwDebug->pDMABuf = (TI_UINT8*)os_memoryAlloc(pFwDebug->hOs,DMA_SIZE_BUF + WSPI_PAD_LEN_READ,MemoryDMA);
|
|
103 |
if (pFwDebug->pDMABuf == NULL)
|
|
104 |
{
|
|
105 |
return NULL;
|
|
106 |
}
|
|
107 |
os_memoryZero (hOs, pFwDebug->pDMABuf, DMA_SIZE_BUF + WSPI_PAD_LEN_READ);
|
|
108 |
pFwDebug->pDMABuf += WSPI_PAD_LEN_READ;
|
|
109 |
|
|
110 |
return pFwDebug;
|
|
111 |
}
|
|
112 |
|
|
113 |
|
|
114 |
/*
|
|
115 |
* \brief Initialize the module
|
|
116 |
*
|
|
117 |
* \param hFwDebug - Handle to FW Debug
|
|
118 |
* \param hReport - Handle to report
|
|
119 |
* \param hTwif - Handle to TWIF
|
|
120 |
* \return none
|
|
121 |
*
|
|
122 |
* \par Description
|
|
123 |
*
|
|
124 |
*
|
|
125 |
* \sa
|
|
126 |
*/
|
|
127 |
void fwDbg_Init (TI_HANDLE hFwDebug,
|
|
128 |
TI_HANDLE hReport,
|
|
129 |
TI_HANDLE hTwif)
|
|
130 |
{
|
|
131 |
TFwDebug* pFwDebug = (TFwDebug*)hFwDebug;
|
|
132 |
pFwDebug->hReport = hReport;
|
|
133 |
pFwDebug->hTwif = hTwif;
|
|
134 |
}
|
|
135 |
|
|
136 |
|
|
137 |
/*
|
|
138 |
* \brief Destroy the object
|
|
139 |
*
|
|
140 |
* \param hFwDebug - Handle to FW Debug
|
|
141 |
* \return none
|
|
142 |
*
|
|
143 |
* \par Description
|
|
144 |
* Deallocate the object memory
|
|
145 |
*
|
|
146 |
* \sa
|
|
147 |
*/
|
|
148 |
void fwDbg_Destroy (TI_HANDLE hFwDebug)
|
|
149 |
{
|
|
150 |
TFwDebug* pFwDebug = (TFwDebug*)hFwDebug;
|
|
151 |
|
|
152 |
if (pFwDebug)
|
|
153 |
{
|
|
154 |
if (pFwDebug->pDMABuf)
|
|
155 |
{
|
|
156 |
os_memoryFree(pFwDebug->hOs,pFwDebug->pDMABuf - WSPI_PAD_LEN_READ,DMA_SIZE_BUF + WSPI_PAD_LEN_READ);
|
|
157 |
}
|
|
158 |
os_memoryFree(pFwDebug->hOs,pFwDebug,sizeof(pFwDebug));
|
|
159 |
}
|
|
160 |
}
|
|
161 |
|
|
162 |
|
|
163 |
/*
|
|
164 |
* \brief Write Address to FW
|
|
165 |
*
|
|
166 |
* \param hFwDebug - Handle to FW Debug
|
|
167 |
* \param Address - Absolute HW address
|
|
168 |
* \param Length - Length in byte to write
|
|
169 |
* \param Buffer - Buffer to copy to FW
|
|
170 |
* \param fCb - CB function
|
|
171 |
* \param hCb - CB Handle
|
|
172 |
* \return none
|
|
173 |
*
|
|
174 |
* \par Description
|
|
175 |
* Write buffer to HW must receive length in byte max size 256 bytes
|
|
176 |
* address must be absolute HW address.
|
|
177 |
*
|
|
178 |
* \sa
|
|
179 |
*/
|
|
180 |
TI_STATUS fwDbg_WriteAddr (TI_HANDLE hFwDebug,
|
|
181 |
TI_UINT32 Address,
|
|
182 |
TI_UINT32 Length,
|
|
183 |
TI_UINT8* Buffer,
|
|
184 |
TFwDubCallback fCb,
|
|
185 |
TI_HANDLE hCb)
|
|
186 |
{
|
|
187 |
TI_STATUS rc;
|
|
188 |
TTxnStruct *pTxn;
|
|
189 |
TFwDebug* pFwDebug = (TFwDebug*)hFwDebug;
|
|
190 |
|
|
191 |
pTxn = &pFwDebug->tTxn;
|
|
192 |
|
|
193 |
/* check if length is large than default threshold */
|
|
194 |
if (Length > DMA_SIZE_BUF)
|
|
195 |
{
|
|
196 |
TRACE1(pFwDebug->hOs, REPORT_SEVERITY_ERROR, "fwDbg_WriteAddr : Buffer Length too large -- %d",Length);
|
|
197 |
return TXN_STATUS_ERROR;
|
|
198 |
}
|
|
199 |
|
|
200 |
pFwDebug->fCb = fCb;
|
|
201 |
pFwDebug->hCb = hCb;
|
|
202 |
/* copy the given buffer to DMA buffer */
|
|
203 |
os_memoryCopy(pFwDebug->hOs,pFwDebug->pDMABuf,Buffer,Length);
|
|
204 |
/* Build the command TxnStruct */
|
|
205 |
TXN_PARAM_SET(pTxn, TXN_LOW_PRIORITY, TXN_FUNC_ID_WLAN, TXN_DIRECTION_WRITE, TXN_INC_ADDR)
|
|
206 |
/* Applying a CB in case of an async read */
|
|
207 |
BUILD_TTxnStruct(pTxn, Address, pFwDebug->pDMABuf, Length,(TTxnDoneCb)fwDbg_WriteAddrCb, pFwDebug)
|
|
208 |
rc = twIf_Transact(pFwDebug->hTwif,pTxn);
|
|
209 |
|
|
210 |
return rc;
|
|
211 |
}
|
|
212 |
|
|
213 |
|
|
214 |
/*
|
|
215 |
* \brief Read Address to FW
|
|
216 |
*
|
|
217 |
* \param hFwDebug - Handle to FW Debug
|
|
218 |
* \param Address - Absolute HW address
|
|
219 |
* \param Length - Length in byte to write
|
|
220 |
* \param Buffer - Buffer to copy to FW
|
|
221 |
* \param fCb - CB function
|
|
222 |
* \param hCb - CB Handle
|
|
223 |
* \return none
|
|
224 |
*
|
|
225 |
* \par Description
|
|
226 |
* Read from HW, must receive length in byte max size 256 bytes
|
|
227 |
* address must be absolute HW address.
|
|
228 |
*
|
|
229 |
* \sa
|
|
230 |
*/
|
|
231 |
TI_STATUS fwDbg_ReadAddr (TI_HANDLE hFwDebug,
|
|
232 |
TI_UINT32 Address,
|
|
233 |
TI_UINT32 Length,
|
|
234 |
TI_UINT8* Buffer,
|
|
235 |
TFwDubCallback fCb,
|
|
236 |
TI_HANDLE hCb)
|
|
237 |
{
|
|
238 |
TI_STATUS rc;
|
|
239 |
TTxnStruct *pTxn;
|
|
240 |
TFwDebug *pFwDebug = (TFwDebug*)hFwDebug;
|
|
241 |
pTxn = &pFwDebug->tTxn;
|
|
242 |
/* check if length is large than default threshold */
|
|
243 |
if (Length > DMA_SIZE_BUF)
|
|
244 |
{
|
|
245 |
TRACE1(pFwDebug->hOs, REPORT_SEVERITY_ERROR, "fwDbg_ReadAddr : Buffer Length too large -- %d",Length);
|
|
246 |
return TXN_STATUS_ERROR;
|
|
247 |
}
|
|
248 |
|
|
249 |
pFwDebug->fCb = fCb;
|
|
250 |
pFwDebug->hCb = hCb;
|
|
251 |
pFwDebug->pReadBuf = Buffer;
|
|
252 |
|
|
253 |
/* Build the command TxnStruct */
|
|
254 |
TXN_PARAM_SET(pTxn, TXN_LOW_PRIORITY, TXN_FUNC_ID_WLAN, TXN_DIRECTION_READ, TXN_INC_ADDR)
|
|
255 |
/* Applying a CB in case of an async read */
|
|
256 |
BUILD_TTxnStruct(pTxn, Address, pFwDebug->pDMABuf, Length,(TTxnDoneCb)fwDbg_ReadAddrCb, pFwDebug)
|
|
257 |
rc = twIf_Transact(pFwDebug->hTwif,pTxn);
|
|
258 |
if (rc == TXN_STATUS_COMPLETE)
|
|
259 |
{
|
|
260 |
/* copy from DMA buufer to given buffer */
|
|
261 |
os_memoryCopy(pFwDebug->hOs,pFwDebug->pReadBuf,pFwDebug->pDMABuf,Length);
|
|
262 |
}
|
|
263 |
return rc;
|
|
264 |
}
|
|
265 |
|
|
266 |
|
|
267 |
/*
|
|
268 |
* \brief Write CB function
|
|
269 |
*
|
|
270 |
* \param hFwDebug - Handle to FW Debug
|
|
271 |
* \param pTxn - pointer ti Transact
|
|
272 |
* \return none
|
|
273 |
*
|
|
274 |
* \par Description
|
|
275 |
* This function called from TWIF upon Async Write
|
|
276 |
*
|
|
277 |
* \sa
|
|
278 |
*/
|
|
279 |
static void fwDbg_WriteAddrCb (TI_HANDLE hFwDebug,TTxnStruct* pTxn)
|
|
280 |
{
|
|
281 |
TFwDebug *pFwDebug = (TFwDebug*)hFwDebug;
|
|
282 |
|
|
283 |
if (pFwDebug->fCb && pFwDebug->hCb)
|
|
284 |
{
|
|
285 |
pFwDebug->fCb(pFwDebug->hCb);
|
|
286 |
}
|
|
287 |
}
|
|
288 |
|
|
289 |
|
|
290 |
/*
|
|
291 |
* \brief Read CB function
|
|
292 |
*
|
|
293 |
* \param hFwDebug - Handle to FW Debug
|
|
294 |
* \param pTxn - pointer ti Transact
|
|
295 |
* \return none
|
|
296 |
*
|
|
297 |
* \par Description
|
|
298 |
* This function called from TWIF upon Async Read
|
|
299 |
*
|
|
300 |
* \sa
|
|
301 |
*/
|
|
302 |
static void fwDbg_ReadAddrCb (TI_HANDLE hFwDebug,TTxnStruct* pTxn)
|
|
303 |
{
|
|
304 |
TFwDebug *pFwDebug = (TFwDebug*)hFwDebug;
|
|
305 |
/* copy from DMA buufer to given buffer */
|
|
306 |
os_memoryCopy(pFwDebug->hOs,pFwDebug->pReadBuf,pFwDebug->pDMABuf,pTxn->aLen[0]);
|
|
307 |
|
|
308 |
if (pFwDebug->fCb && pFwDebug->hCb)
|
|
309 |
{
|
|
310 |
pFwDebug->fCb(pFwDebug->hCb);
|
|
311 |
}
|
|
312 |
}
|
|
313 |
|
|
314 |
|
|
315 |
/*
|
|
316 |
* \brief Check HW address
|
|
317 |
*
|
|
318 |
* \param hFwDebug - Handle to FW Debug
|
|
319 |
* \return TI_TRUE, TI_FALSE
|
|
320 |
*
|
|
321 |
* \par Description
|
|
322 |
* This function called to check the given address to be a valid memory address.
|
|
323 |
*
|
|
324 |
* \sa
|
|
325 |
*/
|
|
326 |
TI_BOOL fwDbg_isValidMemoryAddr (TI_HANDLE hFwDebug, TI_UINT32 Address, TI_UINT32 Length)
|
|
327 |
{
|
|
328 |
TFwDebug *pFwDebug = (TFwDebug*)hFwDebug;
|
|
329 |
|
|
330 |
return twIf_isValidMemoryAddr(pFwDebug->hTwif, Address, Length);
|
|
331 |
}
|
|
332 |
|
|
333 |
|
|
334 |
/*
|
|
335 |
* \brief Check HW address
|
|
336 |
*
|
|
337 |
* \param hFwDebug - Handle to FW Debug
|
|
338 |
* \return TI_TRUE, TI_FALSE
|
|
339 |
*
|
|
340 |
* \par Description
|
|
341 |
* This function called to check the given address to be a valid register address.
|
|
342 |
*
|
|
343 |
* \sa
|
|
344 |
*/
|
|
345 |
TI_BOOL fwDbg_isValidRegAddr (TI_HANDLE hFwDebug, TI_UINT32 Address, TI_UINT32 Length)
|
|
346 |
{
|
|
347 |
TFwDebug *pFwDebug = (TFwDebug*)hFwDebug;
|
|
348 |
|
|
349 |
return twIf_isValidRegAddr(pFwDebug->hTwif, Address, Length);
|
|
350 |
}
|
|
351 |
|