Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /****************************************************************************** |
2 | |||
3 | MRF24WB0M Driver RAW driver |
||
4 | Module for Microchip TCP/IP Stack |
||
5 | -Provides access to MRF24WB0M WiFi controller |
||
6 | -Reference: MRF24WB0M Data sheet, IEEE 802.11 Standard |
||
7 | |||
8 | ******************************************************************************* |
||
9 | FileName: WFDriverRaw.c |
||
10 | Dependencies: TCP/IP Stack header files |
||
11 | Processor: PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F, PIC32 |
||
12 | Compiler: Microchip C32 v1.10b or higher |
||
13 | Microchip C30 v3.22 or higher |
||
14 | Microchip C18 v3.34 or higher |
||
15 | Company: Microchip Technology, Inc. |
||
16 | |||
17 | Software License Agreement |
||
18 | |||
19 | Copyright (C) 2002-2010 Microchip Technology Inc. All rights reserved. |
||
20 | |||
21 | Microchip licenses to you the right to use, modify, copy, and distribute: |
||
22 | (i) the Software when embedded on a Microchip microcontroller or digital |
||
23 | signal controller product ("Device") which is integrated into |
||
24 | Licensee's product; or |
||
25 | (ii) ONLY the Software driver source files ENC28J60.c, ENC28J60.h, |
||
26 | ENCX24J600.c and ENCX24J600.h ported to a non-Microchip device used in |
||
27 | conjunction with a Microchip ethernet controller for the sole purpose |
||
28 | of interfacing with the ethernet controller. |
||
29 | |||
30 | You should refer to the license agreement accompanying this Software for |
||
31 | additional information regarding your rights and obligations. |
||
32 | |||
33 | THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY |
||
34 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY |
||
35 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND |
||
36 | NON-INFRINGEMENT. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR ANY INCIDENTAL, |
||
37 | SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST |
||
38 | OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS BY |
||
39 | THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS |
||
40 | FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON |
||
41 | THE BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR |
||
42 | OTHERWISE. |
||
43 | |||
44 | |||
45 | Author Date Comment |
||
46 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
47 | KH 27 Jan 2010 Updated for MRF24WB0M |
||
48 | ******************************************************************************/ |
||
49 | |||
50 | /* |
||
51 | ********************************************************************************************************* |
||
52 | * INCLUDES |
||
53 | ********************************************************************************************************* |
||
54 | */ |
||
55 | |||
56 | #include "TCPIP Stack/WFMac.h" |
||
57 | #include "TCPIP Stack/TCPIP.h" |
||
58 | #if defined(WF_CS_TRIS) |
||
59 | |||
60 | |||
61 | /* used for assertions */ |
||
62 | #ifdef WF_DEBUG |
||
63 | #define WF_MODULE_NUMBER WF_MODULE_WF_DRIVER_RAW |
||
64 | #endif |
||
65 | |||
66 | |||
67 | /* |
||
68 | ********************************************************************************************************* |
||
69 | * DEFINES |
||
70 | ********************************************************************************************************* |
||
71 | */ |
||
72 | |||
73 | // RAW register masks |
||
74 | #define WF_RAW_STATUS_REG_ERROR_MASK ((UINT16)(0x0002)) |
||
75 | #define WF_RAW_STATUS_REG_BUSY_MASK ((UINT16)(0x0001)) |
||
76 | |||
77 | /* |
||
78 | ********************************************************************************************************* |
||
79 | * LOCAL DATA TYPES |
||
80 | ********************************************************************************************************* |
||
81 | */ |
||
82 | |||
83 | |||
84 | /* |
||
85 | ********************************************************************************************************* |
||
86 | * LOCAL GLOBAL VARIABLES |
||
87 | ********************************************************************************************************* |
||
88 | */ |
||
89 | |||
90 | BOOL g_HostRAWDataPacketReceived = FALSE; // set TRUE by state machine in WFDriverCom.c |
||
91 | extern BOOL g_rxIndexSetBeyondBuffer; // debug -- remove after test |
||
92 | |||
93 | BOOL RawWindowReady[2]; /* for Tx and Rx, TRUE = ready for use, FALSE = not ready for use */ |
||
94 | UINT8 RawWindowState[2]; |
||
95 | |||
96 | |||
97 | |||
98 | /* |
||
99 | ********************************************************************************************************* |
||
100 | * LOCAL FUNCTION PROTOTYPES |
||
101 | ********************************************************************************************************* |
||
102 | */ |
||
103 | static UINT16 RawMove(UINT16 rawId, UINT16 srcDest, BOOL rawIsDestination, UINT16 size); |
||
104 | static UINT16 WaitForRawMoveComplete(UINT8 rawId); |
||
105 | |||
106 | |||
107 | BOOL AllocateMgmtTxBuffer(UINT16 bytesNeeded) |
||
108 | { |
||
109 | UINT16 bufAvail; |
||
110 | UINT16 byteCount; |
||
111 | |||
112 | /* get total bytes available for MGMT tx memory pool */ |
||
113 | bufAvail = Read16BitWFRegister(WF_HOST_WFIFO_BCNT1_REG) & 0x0fff; /* LS 12 bits contain length */ |
||
114 | |||
115 | /* if enough bytes available to allocate */ |
||
116 | if ( bufAvail >= bytesNeeded ) |
||
117 | { |
||
118 | /* allocate and create the new Tx buffer (mgmt or data) */ |
||
119 | byteCount = RawMove(RAW_TX_ID, RAW_MGMT_POOL, TRUE, bytesNeeded); |
||
120 | WF_ASSERT(byteCount != 0); |
||
121 | } |
||
122 | /* else not enough bytes available at this time to satisfy request */ |
||
123 | else |
||
124 | { |
||
125 | return FALSE; |
||
126 | } |
||
127 | |||
128 | RawWindowReady[RAW_TX_ID] = TRUE; |
||
129 | SetRawWindowState(RAW_TX_ID, WF_RAW_MGMT_MOUNTED); |
||
130 | |||
131 | return TRUE; |
||
132 | } |
||
133 | |||
134 | void DeallocateMgmtRxBuffer(void) |
||
135 | { |
||
136 | /* Unmount (release) mgmt packet now that we are done with it */ |
||
137 | RawMove(RAW_RX_ID, RAW_MGMT_POOL, FALSE, 0); |
||
138 | SetRawRxMgmtInProgress(FALSE); |
||
139 | } |
||
140 | |||
141 | BOOL AllocateDataTxBuffer(UINT16 bytesNeeded) |
||
142 | { |
||
143 | UINT16 bufAvail; |
||
144 | UINT16 byteCount; |
||
145 | |||
146 | /* get total bytes available for DATA tx memory pool */ |
||
147 | bufAvail = Read16BitWFRegister(WF_HOST_WFIFO_BCNT0_REG) & 0x0fff; /* LS 12 bits contain length */ |
||
148 | |||
149 | /* if enough bytes available to allocate */ |
||
150 | if ( bufAvail >= bytesNeeded ) |
||
151 | { |
||
152 | /* allocate and create the new Tx buffer (mgmt or data) */ |
||
153 | byteCount = RawMove(RAW_TX_ID, RAW_DATA_POOL, TRUE, bytesNeeded); |
||
154 | WF_ASSERT(byteCount != 0); |
||
155 | } |
||
156 | /* else not enough bytes available at this time to satisfy request */ |
||
157 | else |
||
158 | { |
||
159 | return FALSE; |
||
160 | } |
||
161 | |||
162 | RawWindowReady[RAW_TX_ID] = TRUE; |
||
163 | SetRawWindowState(RAW_TX_ID, WF_RAW_DATA_MOUNTED); |
||
164 | return TRUE; |
||
165 | |||
166 | } |
||
167 | |||
168 | void DeallocateDataTxBuffer(void) |
||
169 | { |
||
170 | RawMove(RAW_TX_ID, RAW_DATA_POOL, FALSE, 0); |
||
171 | RawWindowReady[RAW_TX_ID] = FALSE; |
||
172 | SetRawWindowState(RAW_TX_ID, WF_RAW_UNMOUNTED); |
||
173 | } |
||
174 | |||
175 | void DeallocateDataRxBuffer(void) |
||
176 | { |
||
177 | RawMove(RAW_RX_ID, RAW_DATA_POOL, FALSE, 0); |
||
178 | } |
||
179 | |||
180 | /* if a mgmt msg mounted in RAW window then message handled by MRF24WB0M. */ |
||
181 | /* If a data message mounted in RAW window then will be transmitted to 802.11 network */ |
||
182 | void RawSendTxBuffer(UINT16 len) |
||
183 | { |
||
184 | RawMove(RAW_TX_ID, RAW_MAC, FALSE, len); |
||
185 | RawWindowReady[RAW_TX_ID] = FALSE; |
||
186 | SetRawWindowState(RAW_TX_ID, WF_RAW_UNMOUNTED); |
||
187 | |||
188 | } |
||
189 | |||
190 | /* mounts the most recent Rx message. Could be a management or data message. */ |
||
191 | UINT16 RawMountRxBuffer(void) |
||
192 | { |
||
193 | UINT16 length; |
||
194 | |||
195 | length = RawMove(RAW_RX_ID, RAW_MAC, TRUE, 0); |
||
196 | |||
197 | RawWindowReady[RAW_RX_ID] = TRUE; |
||
198 | SetRawWindowState(RAW_RX_ID, WF_RAW_DATA_MOUNTED); |
||
199 | |||
200 | |||
201 | return length; |
||
202 | } |
||
203 | |||
204 | /* Copies from source raw window to destination raw window, each from their current indexes. */ |
||
205 | void RawToRawCopy(UINT8 rawSourceId, UINT16 length) |
||
206 | { |
||
207 | RawMove(rawSourceId, RAW_COPY, TRUE, length); |
||
208 | } |
||
209 | |||
210 | |||
211 | /* |
||
212 | ********************************************************************************************************* |
||
213 | * PushRawWindow() |
||
214 | * |
||
215 | * Description : Pushes a RAW window onto the 1-level deep RAW stack. The RAW window state is preserved |
||
216 | * and is restored when PopRawWindow() is called. |
||
217 | * |
||
218 | * Argument(s) : rawId -- RAW window ID that is being pushed. |
||
219 | * |
||
220 | * Return(s) : None |
||
221 | * |
||
222 | * Caller(s) : WF Driver |
||
223 | * |
||
224 | * Notes: : (1) The RAW architecture supports a 1-level deep stack. Each time this function is called |
||
225 | * any state that had been previously saved is lost. |
||
226 | * |
||
227 | ********************************************************************************************************* |
||
228 | */ |
||
229 | void PushRawWindow(UINT8 rawId) |
||
230 | { |
||
231 | RawMove(rawId, RAW_STACK_MEM, FALSE, 0); |
||
232 | } |
||
233 | |||
234 | /* |
||
235 | ********************************************************************************************************* |
||
236 | * PopRawWindow() |
||
237 | * |
||
238 | * Description : Pops a RAW window state from the 1-level deep RAW stack. The RAW window state that was |
||
239 | * mounted prior to this call is lost. |
||
240 | * |
||
241 | * Argument(s) : rawId -- RAW window ID that is being popped. |
||
242 | * |
||
243 | * Return(s) : byte count of the RAW window state that was saved and is now restored. In other words, the |
||
244 | * size, in bytes, of the RAW window when it was first created. |
||
245 | * of the o |
||
246 | * |
||
247 | * Caller(s) : WF Driver |
||
248 | * |
||
249 | * Notes: : (1) The RAW architecture supports a 1-level deep stack. When this fucntion is called the |
||
250 | * RAW window state that had been mounted is lost. If trying to pop a non-existent RAW |
||
251 | * window state (no push has taken place), the the returned byte count is 0. |
||
252 | * |
||
253 | ********************************************************************************************************* |
||
254 | */ |
||
255 | UINT16 PopRawWindow(UINT8 rawId) |
||
256 | { |
||
257 | UINT16 byteCount; |
||
258 | |||
259 | byteCount = RawMove(rawId, RAW_STACK_MEM, TRUE, 0); |
||
260 | |||
261 | return byteCount; |
||
262 | } |
||
263 | |||
264 | |||
265 | |||
266 | /* |
||
267 | ********************************************************************************************************* |
||
268 | * ScratchMount() |
||
269 | * |
||
270 | * Description : Mounts Scratch using the specified RAW window. |
||
271 | * |
||
272 | * Argument(s) : rawId -- desired RAW window to mount Scratch to. |
||
273 | * |
||
274 | * Return(s) : None |
||
275 | * |
||
276 | * Caller(s) : WF Driver |
||
277 | * |
||
278 | * Notes: : None |
||
279 | * |
||
280 | ********************************************************************************************************* |
||
281 | */ |
||
282 | UINT16 ScratchMount(UINT8 rawId) |
||
283 | { |
||
284 | UINT16 byteCount; |
||
285 | |||
286 | byteCount = RawMove(rawId, RAW_SCRATCH_POOL, TRUE, 0); |
||
287 | WF_ASSERT(byteCount > 0); /* scratch mount should always return value > 0 */ |
||
288 | |||
289 | SetRawWindowState(rawId, WF_SCRATCH_MOUNTED); |
||
290 | return byteCount; |
||
291 | } |
||
292 | |||
293 | /* |
||
294 | ********************************************************************************************************* |
||
295 | * ScratchUnmount() |
||
296 | * |
||
297 | * Description : Unmounts Scratch from the specified RAW window. |
||
298 | * |
||
299 | * Argument(s) : rawId -- RAW window ID that scratch had been mounted to. |
||
300 | * |
||
301 | * Return(s) : None |
||
302 | * |
||
303 | * Caller(s) : WF Driver |
||
304 | * |
||
305 | * Notes: : None |
||
306 | * |
||
307 | ********************************************************************************************************* |
||
308 | */ |
||
309 | void ScratchUnmount(UINT8 rawId) |
||
310 | { |
||
311 | RawMove(rawId, RAW_SCRATCH_POOL, FALSE, 0); |
||
312 | if (rawId == RAW_RX_ID) |
||
313 | { |
||
314 | SetRawWindowState(RAW_RX_ID, WF_RAW_UNMOUNTED); |
||
315 | } |
||
316 | else |
||
317 | { |
||
318 | SetRawWindowState(RAW_TX_ID, WF_RAW_UNMOUNTED); |
||
319 | } |
||
320 | |||
321 | } |
||
322 | |||
323 | |||
324 | /* |
||
325 | ********************************************************************************************************* |
||
326 | * RawRead() |
||
327 | * |
||
328 | * Description : Reads the specified number of bytes from a mounted RAW window from the specified starting |
||
329 | * index; |
||
330 | * |
||
331 | * Argument(s) : rawId -- RAW window ID being read from |
||
332 | * startIndex -- start index within RAW window to read from |
||
333 | * length -- number of bytes to read from the RAW window |
||
334 | * p_dest -- pointer to Host buffer where read data is copied |
||
335 | * |
||
336 | * Return(s) : error code |
||
337 | * |
||
338 | * Caller(s) : WF Driver |
||
339 | * |
||
340 | * Notes: : None |
||
341 | * |
||
342 | ********************************************************************************************************* |
||
343 | */ |
||
344 | void RawRead(UINT8 rawId, UINT16 startIndex, UINT16 length, UINT8 *p_dest) |
||
345 | { |
||
346 | RawSetIndex(rawId, startIndex); |
||
347 | RawGetByte(rawId, p_dest, length); |
||
348 | } |
||
349 | |||
350 | /* |
||
351 | ********************************************************************************************************* |
||
352 | * RawWrite() |
||
353 | * |
||
354 | * Description : Writes the specified number of bytes to a mounted RAW window at the specified starting |
||
355 | * index |
||
356 | * |
||
357 | * Argument(s) : rawId -- RAW window ID being written to |
||
358 | * startIndex -- start index within RAW window to write to |
||
359 | * length -- number of bytes to write to RAW window |
||
360 | * p_src -- pointer to Host buffer write data |
||
361 | * |
||
362 | * Return(s) : None |
||
363 | * |
||
364 | * Caller(s) : WF Driver |
||
365 | * |
||
366 | * Notes: : None |
||
367 | * |
||
368 | ********************************************************************************************************* |
||
369 | */ |
||
370 | void RawWrite(UINT8 rawId, UINT16 startIndex, UINT16 length, UINT8 *p_src) |
||
371 | { |
||
372 | /*set raw index in dest memory */ |
||
373 | RawSetIndex(rawId, startIndex); |
||
374 | |||
375 | /* write data to RAW window */ |
||
376 | RawSetByte(rawId, p_src, length); |
||
377 | } |
||
378 | |||
379 | /***************************************************************************** |
||
380 | * FUNCTION: RawMove |
||
381 | * |
||
382 | * RETURNS: Number of bytes that were overlayed (not always applicable) |
||
383 | * |
||
384 | * PARAMS: |
||
385 | * rawId - RAW ID |
||
386 | * srcDest - MRF24WB0M object that will either source or destination of move |
||
387 | * rawIsDestination - TRUE if RAW engine is the destination, FALSE if its the source |
||
388 | * size - number of bytes to overlay (not always applicable) |
||
389 | * |
||
390 | * NOTES: Performs a RAW move operation between a RAW engine and a MRF24WB0M object |
||
391 | *****************************************************************************/ |
||
392 | static UINT16 RawMove(UINT16 rawId, |
||
393 | UINT16 srcDest, |
||
394 | BOOL rawIsDestination, |
||
395 | UINT16 size) |
||
396 | { |
||
397 | UINT16 byteCount; |
||
398 | UINT8 regId; |
||
399 | UINT8 regValue8; |
||
400 | UINT16 ctrlVal = 0; |
||
401 | |||
402 | if (rawIsDestination) |
||
403 | { |
||
404 | ctrlVal |= 0x8000; |
||
405 | } |
||
406 | |||
407 | /* fix later, simply need to ensure that size is 12 bits are less */ |
||
408 | ctrlVal |= (srcDest << 8); /* defines are already shifted by 4 bits */ |
||
409 | ctrlVal |= ((size >> 8) & 0x0f) << 8; /* MS 4 bits of size (bits 11:8) */ |
||
410 | ctrlVal |= (size & 0x00ff); /* LS 8 bits of size (bits 7:0) */ |
||
411 | |||
412 | /* Clear the interrupt bit in the register */ |
||
413 | regValue8 = (rawId == RAW_ID_0)?WF_HOST_INT_MASK_RAW_0_INT_0:WF_HOST_INT_MASK_RAW_1_INT_0; |
||
414 | Write8BitWFRegister(WF_HOST_INTR_REG, regValue8); |
||
415 | |||
416 | /* write update control value to register to control register */ |
||
417 | regId = (rawId==RAW_ID_0)?RAW_0_CTRL_0_REG:RAW_1_CTRL_0_REG; |
||
418 | Write16BitWFRegister(regId, ctrlVal); |
||
419 | |||
420 | // Wait for the RAW move operation to complete, and read back the number of bytes, if any, that were overlayed |
||
421 | byteCount = WaitForRawMoveComplete(rawId); |
||
422 | |||
423 | return byteCount; |
||
424 | } |
||
425 | |||
426 | /***************************************************************************** |
||
427 | * FUNCTION: RawSetIndex |
||
428 | * |
||
429 | * RETURNS: True is success, false if timed out, which means attempted to set |
||
430 | * raw index past end of raw window. Not a problem as long as no read |
||
431 | * or write occurs. |
||
432 | * |
||
433 | * PARAMS: |
||
434 | * rawId - RAW ID |
||
435 | * index - desired index |
||
436 | * |
||
437 | * NOTES: Sets the RAW index for the specified RAW engine. If attempt to set RAW |
||
438 | * index outside boundaries of RAW window this function will time out. |
||
439 | *****************************************************************************/ |
||
440 | BOOL RawSetIndex(UINT16 rawId, UINT16 index) |
||
441 | { |
||
442 | UINT8 regId; |
||
443 | UINT16 regValue; |
||
444 | UINT32 startTickCount; |
||
445 | UINT32 maxAllowedTicks; |
||
446 | |||
447 | // set the RAW index |
||
448 | regId = (rawId==RAW_ID_0)?RAW_0_INDEX_REG:RAW_1_INDEX_REG; |
||
449 | Write16BitWFRegister(regId, index); |
||
450 | |||
451 | startTickCount = (UINT32)TickGet(); |
||
452 | maxAllowedTicks = TICKS_PER_SECOND / 200; /* 5ms */ |
||
453 | |||
454 | regId = (rawId==RAW_ID_0)?RAW_0_STATUS_REG:RAW_1_STATUS_REG; |
||
455 | |||
456 | while (1) |
||
457 | { |
||
458 | regValue = Read16BitWFRegister(regId); |
||
459 | if ((regValue & WF_RAW_STATUS_REG_BUSY_MASK) == 0) |
||
460 | { |
||
461 | return TRUE; |
||
462 | } |
||
463 | |||
464 | /* if timed out then trying to set index past end of raw window, which is OK so long as the app */ |
||
465 | /* doesn't try to access it */ |
||
466 | if (TickGet() - startTickCount >= maxAllowedTicks) |
||
467 | { |
||
468 | return FALSE; /* timed out waiting for Raw set index to complete */ |
||
469 | } |
||
470 | } |
||
471 | } |
||
472 | |||
473 | /***************************************************************************** |
||
474 | * FUNCTION: RawGetIndex |
||
475 | * |
||
476 | * RETURNS: Returns the current RAW index for the specified RAW engine. |
||
477 | * |
||
478 | * PARAMS: |
||
479 | * rawId - RAW ID |
||
480 | * |
||
481 | * NOTES: None |
||
482 | *****************************************************************************/ |
||
483 | UINT16 RawGetIndex(UINT16 rawId) |
||
484 | { |
||
485 | UINT8 regId; |
||
486 | UINT16 index; |
||
487 | |||
488 | regId = (rawId==RAW_ID_0)?RAW_0_INDEX_REG:RAW_1_INDEX_REG; |
||
489 | index = Read16BitWFRegister(regId); |
||
490 | |||
491 | return index; |
||
492 | } |
||
493 | |||
494 | |||
495 | //#define OUTPUT_RAW_TX_RX |
||
496 | |||
497 | /***************************************************************************** |
||
498 | * FUNCTION: RawGetByte |
||
499 | * |
||
500 | * RETURNS: error code |
||
501 | * |
||
502 | * PARAMS: |
||
503 | * rawId - RAW ID |
||
504 | * pBuffer - Buffer to read bytes into |
||
505 | * length - number of bytes to read |
||
506 | * |
||
507 | * NOTES: Reads bytes from the RAW engine |
||
508 | *****************************************************************************/ |
||
509 | void RawGetByte(UINT16 rawId, UINT8 *pBuffer, UINT16 length) |
||
510 | { |
||
511 | UINT8 regId; |
||
512 | #if defined(OUTPUT_RAW_TX_RX) |
||
513 | UINT16 i; |
||
514 | #endif |
||
515 | |||
516 | // if RAW index previously set out of range and caller is trying to do illegal read |
||
517 | if ( (rawId==RAW_RX_ID) && |
||
518 | g_rxIndexSetBeyondBuffer && |
||
519 | (GetRawWindowState(RAW_RX_ID) == WF_RAW_DATA_MOUNTED) ) |
||
520 | { |
||
521 | WF_ASSERT(FALSE); /* attempting to read past end of RAW buffer */ |
||
522 | } |
||
523 | |||
524 | regId = (rawId==RAW_ID_0)?RAW_0_DATA_REG:RAW_1_DATA_REG; |
||
525 | ReadWFArray(regId, pBuffer, length); |
||
526 | |||
527 | #if defined(OUTPUT_RAW_TX_RX) |
||
528 | for (i = 0; i < length; ++i) |
||
529 | { |
||
530 | char buf[16]; |
||
531 | sprintf(buf,"R: %#x\r\n", pBuffer[i]); |
||
532 | putsUART(buf); |
||
533 | } |
||
534 | #endif |
||
535 | |||
536 | } |
||
537 | |||
538 | |||
539 | /***************************************************************************** |
||
540 | * FUNCTION: RawSetByte |
||
541 | * |
||
542 | * RETURNS: None |
||
543 | * |
||
544 | * PARAMS: |
||
545 | * rawId - RAW ID |
||
546 | * pBuffer - Buffer containing bytes to write |
||
547 | * length - number of bytes to read |
||
548 | * |
||
549 | * NOTES: Writes bytes to RAW window |
||
550 | *****************************************************************************/ |
||
551 | void RawSetByte(UINT16 rawId, UINT8 *pBuffer, UINT16 length) |
||
552 | { |
||
553 | UINT8 regId; |
||
554 | #if defined(OUTPUT_RAW_TX_RX) |
||
555 | UINT16 i; |
||
556 | #endif |
||
557 | |||
558 | |||
559 | /* if previously set index past legal range and now trying to write to RAW engine */ |
||
560 | if ( (rawId == 0) && g_rxIndexSetBeyondBuffer && (GetRawWindowState(RAW_TX_ID) == WF_RAW_DATA_MOUNTED) ) |
||
561 | { |
||
562 | WF_ASSERT(FALSE); /* attempting to write past end of RAW window */ |
||
563 | } |
||
564 | |||
565 | /* write RAW data to chip */ |
||
566 | regId = (rawId==RAW_ID_0)?RAW_0_DATA_REG:RAW_1_DATA_REG; |
||
567 | WriteWFArray(regId, pBuffer, length); |
||
568 | |||
569 | #if defined(OUTPUT_RAW_TX_RX) |
||
570 | for (i = 0; i < length; ++i) |
||
571 | { |
||
572 | char buf[16]; |
||
573 | sprintf(buf,"T: %#x\r\n", pBuffer[i]); |
||
574 | putsUART(buf); |
||
575 | } |
||
576 | #endif |
||
577 | |||
578 | } |
||
579 | |||
580 | #if defined (__18CXX) |
||
581 | /***************************************************************************** |
||
582 | * FUNCTION: RawSetByteROM |
||
583 | * |
||
584 | * RETURNS: True if successful, else FALSE |
||
585 | * |
||
586 | * PARAMS: |
||
587 | * rawId - RAW ID |
||
588 | * pBuffer - Buffer containing bytes to write |
||
589 | * length - number of bytes to read |
||
590 | * |
||
591 | * NOTES: Reads bytes from the RAW engine. Same as RawSetByte except |
||
592 | * using a ROM pointer instead of RAM pointer |
||
593 | *****************************************************************************/ |
||
594 | void RawSetByteROM(UINT16 rawId, ROM UINT8 *pBuffer, UINT16 length) |
||
595 | { |
||
596 | UINT8 regId; |
||
597 | |||
598 | regId = (rawId==RAW_ID_0)?RAW_0_DATA_REG:RAW_1_DATA_REG; |
||
599 | WriteWFROMArray(regId, pBuffer, length); |
||
600 | } |
||
601 | #endif |
||
602 | |||
603 | /***************************************************************************** |
||
604 | * FUNCTION: WaitForRawMoveComplete |
||
605 | * |
||
606 | * RETURNS: Number of bytes that were overlayed (not always applicable) |
||
607 | * |
||
608 | * PARAMS: |
||
609 | * rawId - RAW ID |
||
610 | * |
||
611 | * NOTES: Waits for a RAW move to complete. |
||
612 | *****************************************************************************/ |
||
613 | static UINT16 WaitForRawMoveComplete(UINT8 rawId) |
||
614 | |||
615 | { |
||
616 | UINT8 rawIntMask; |
||
617 | UINT16 byteCount; |
||
618 | UINT8 regId; |
||
619 | BOOL intDisabled; |
||
620 | UINT32 startTickCount; |
||
621 | UINT32 maxAllowedTicks; |
||
622 | |||
623 | /* create mask to check against for Raw Move complete interrupt for either RAW0 or RAW1 */ |
||
624 | rawIntMask = (rawId == RAW_ID_0)?WF_HOST_INT_MASK_RAW_0_INT_0:WF_HOST_INT_MASK_RAW_1_INT_0; |
||
625 | |||
626 | /* |
||
627 | These variables are shared with the ISR so need to be careful when setting them. |
||
628 | the WFEintHandler() is the isr that will touch these variables but will only touch |
||
629 | them if RawMoveState.waitingForRawMoveCompleteInterrupt is set to TRUE. |
||
630 | RawMoveState.waitingForRawMoveCompleteInterrupt is only set TRUE here and only here. |
||
631 | so as long as we set RawMoveState.rawInterrupt first and then set RawMoveState.waitingForRawMoveCompleteInterrupt |
||
632 | to TRUE, we are guranteed that the ISR won't touch RawMoveState.rawInterrupt and |
||
633 | RawMoveState.waitingForRawMoveCompleteInterrupt. |
||
634 | */ |
||
635 | RawMoveState.rawInterrupt = 0; |
||
636 | RawMoveState.waitingForRawMoveCompleteInterrupt = TRUE; |
||
637 | |||
638 | // save state of external interrupt here |
||
639 | intDisabled = WF_EintIsDisabled(); |
||
640 | // if external interrupt is disabled, enable it because we need it for the while(1) loop to exit |
||
641 | if(intDisabled) |
||
642 | { |
||
643 | WF_EintEnable(); |
||
644 | } |
||
645 | else if(WF_EintIsPending()) |
||
646 | { |
||
647 | WF_EintEnable(); |
||
648 | } |
||
649 | |||
650 | |||
651 | // Before we enter the while loop, get the tick timer count and save it |
||
652 | maxAllowedTicks = TICKS_PER_SECOND / 2; /* 500 ms timeout */ |
||
653 | startTickCount = (UINT32)TickGet(); |
||
654 | while (1) |
||
655 | { |
||
656 | /* if received an external interrupt that signalled the RAW Move */ |
||
657 | /* completed then break out of this loop */ |
||
658 | if(RawMoveState.rawInterrupt & rawIntMask) |
||
659 | { |
||
660 | break; |
||
661 | } |
||
662 | |||
663 | /* If timed out waiting for RAW Move complete than lock up */ |
||
664 | if (TickGet() - startTickCount >= maxAllowedTicks) |
||
665 | { |
||
666 | WF_ASSERT(FALSE); |
||
667 | } |
||
668 | } /* end while */ |
||
669 | |||
670 | /* if interrupt was enabled by us here, we should disable it now that we're finished */ |
||
671 | if(intDisabled) |
||
672 | { |
||
673 | WF_EintDisable(); |
||
674 | } |
||
675 | |||
676 | /* read the byte count and return it */ |
||
677 | regId = (rawId == RAW_ID_0)?WF_HOST_RAW0_CTRL1_REG:WF_HOST_RAW1_CTRL1_REG; |
||
678 | byteCount = Read16BitWFRegister(regId); |
||
679 | |||
680 | return ( byteCount ); |
||
681 | } |
||
682 | |||
683 | |||
684 | |||
685 | |||
686 | /***************************************************************************** |
||
687 | * FUNCTION: SendRAWDataFrame |
||
688 | * |
||
689 | * RETURNS: TRUE or FALSE |
||
690 | * |
||
691 | * PARAMS: |
||
692 | * UINT8* pBuf -> pointer to the command buffer. |
||
693 | * UINT16 bufLen -> length in bytes of the buffer (pBuf). |
||
694 | * |
||
695 | * |
||
696 | * NOTES: SendRAWDataFrame sends a Data Transmit request to the WF chip |
||
697 | * using the Random Access Window (RAW) interface. The pre-buffer |
||
698 | * is used by the WF MAC to send routing information for the packet |
||
699 | * while pBuf is the request that was submitted by the application. |
||
700 | * The order of operations are |
||
701 | * 1) reserve a memory buffer of sufficient length on the WF chip |
||
702 | * using RawMove. |
||
703 | * 2) Write the bytes for the pre-buffer and then the buffer |
||
704 | * using the RawSetByte. Because the bytes are written |
||
705 | * sequentially there is no need to call WFRawSetIndex |
||
706 | * to adjust the write position. |
||
707 | * 3) instruct the WF chip that the command is ready for |
||
708 | * processing. |
||
709 | * 4) perform any necessary cleanup. |
||
710 | *****************************************************************************/ |
||
711 | void SendRAWDataFrame(UINT16 bufLen) |
||
712 | { |
||
713 | UINT8 txDataPreamble[4] = { WF_DATA_REQUEST_TYPE, WF_STD_DATA_MSG_SUBTYPE, 1, 0}; |
||
714 | |||
715 | RawWrite(RAW_TX_ID, 0, sizeof(txDataPreamble), txDataPreamble); |
||
716 | |||
717 | RawSendTxBuffer(bufLen); |
||
718 | } |
||
719 | |||
720 | |||
721 | |||
722 | #else |
||
723 | // dummy func to keep compiler happy when module has no executeable code |
||
724 | void DriverRaw_EmptyFunc(void) |
||
725 | { |
||
726 | } |
||
727 | #endif /* WF_CS_TRIS */ |
||
728 | |||
729 | |||
730 | /* EOF */ |
Powered by WebSVN v2.8.3