?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 32

Line No. Rev Author Line
1 32 kaklik /******************************************************************************
2  
3 MRF24WB0M Driver Tx Power functions
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: WFTxPower.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 #if defined(WF_CS_TRIS) && defined(WF_USE_TX_POWER_CONTROL_FUNCTIONS)
58  
59  
60 /*
61 *********************************************************************************************************
62 * DEFINES
63 *********************************************************************************************************
64 */
65  
66 /* used for assertions */
67 #ifdef WF_DEBUG
68 #define WF_MODULE_NUMBER WF_MODULE_WF_TX_POWER
69 #endif
70  
71 #define TX_THOTTLE_ENABLE_BIT_MASK ((UINT8)0x01)
72  
73  
74 #define WF_ZERO_DB_VALUE (64)
75  
76 #define DEFAULT_MIN_TX_POWER (-10) /* dB */
77  
78  
79 /*
80 *********************************************************************************************************
81 * LOCAL FUNCTION PROTOTYPES
82 *********************************************************************************************************
83 */
84  
85 static INT8 WFPowerToAppPower(UINT8 wfPower);
86 static UINT8 AppPowerToWFPower(INT8 appPower);
87  
88 /*******************************************************************************
89 Function:
90 void WF_ThrottleTableSet(tWFThrottleTable *p_table)
91  
92 Summary:
93 Sets Tx throttle table on MRF24WB0M.
94  
95 Description:
96 Writes out Tx Throttle Table to MRF24WB0M. Each msg byte of the throttle
97 table uses bit 7 as the data rate (0 for 1Mbit, 1 for 2Mbit). Bits 6:0
98 are used for the Tx power level, where 64 corresponds to 0dB and each count
99 is a 0.5dB step up or down. Thus:
100 <table>
101 Value dB
102 ----- --
103 44 -10.0dB
104 ... ...
105 60 -2.0dB
106 61 -1.5dB
107 62 -1.0dB
108 63 -0.5dB
109 64 0.0dB (WF_ZERO_DB_VALUE)
110 65 0.5dB
111 66 1.0dB
112 67 1.5dB
113 68 2.0dB
114 ... ...
115 84 10.0dB
116 </table>
117  
118 Formula is: dB = 64 + (p_table->txPower * 2) [MRF24WB0M value]
119  
120 Precondition:
121 MACInit must be called first.
122  
123 Parameters:
124 p_table -- pointer to Tx Throttle Table structure
125  
126 Returns:
127 None.
128  
129 Remarks:
130 None.
131 *****************************************************************************/
132 void WF_ThrottleTableSet(tWFThrottleTable *p_table)
133 {
134 UINT8 msgBuf[WF_NUM_THROTTLE_TABLE_ROWS];
135 UINT8 i;
136  
137 /* for each row of the throttle table */
138 for (i = 0; i < WF_NUM_THROTTLE_TABLE_ROWS; ++i)
139 {
140 WF_ASSERT( (p_table->dataRate[i] == WF_ONE_MBIT_TX_RATE) || (p_table->dataRate[i] == WF_TWO_MBIT_TX_RATE) )
141 WF_ASSERT( (p_table->txPower[i] >= -10) && (p_table->txPower[i] <= 10) );
142  
143 /* set MSB if 2mbps, else clear msb (indicating 1mbps) */
144 msgBuf[i] = (p_table->dataRate[i] == WF_TWO_MBIT_TX_RATE) ? 0x80:0x00;
145  
146 /* OR in tx power level */
147 msgBuf[i] |= AppPowerToWFPower(p_table->txPower[i]); /* mask in tx power level */
148 }
149  
150 SendSetParamMsg(PARAM_TX_THROTTLE_TABLE, msgBuf, sizeof(msgBuf));
151 }
152  
153 /*******************************************************************************
154 Function:
155 void WF_ThrottleTableGet(tWFThrottleTable *p_table)
156  
157 Summary:
158 Gets Tx throttle table from MRF24WB0M.
159  
160 Description:
161 Reads out Tx Throttle Table from MRF24WB0M. Each msg byte of the throttle
162 table uses bit 7 as the data rate (0 for 1Mbit, 1 for 2Mbit). Bits 6:0
163 are used for the Tx power level, where 64 corresponds to 0dB and each count
164 is a 0.5dB step up or down. Thus:
165 <table>
166 Value dB
167 ----- --
168 44 -10.0dB
169 ... ...
170 60 -2.0dB
171 61 -1.5dB
172 62 -1.0dB
173 63 -0.5dB
174 64 0.0dB (WF_ZERO_DB_VALUE)
175 65 0.5dB
176 66 1.0dB
177 67 1.5dB
178 68 2.0dB
179 ... ...
180 84 10.0dB
181 </table>
182  
183 Formula is: dB = 64 + (p_table->txPower * 2) [MRF24WB0M value]
184  
185 Precondition:
186 MACInit must be called first.
187  
188 Parameters:
189 p_table -- pointer to Tx Throttle Table structure
190  
191 Returns:
192 None.
193  
194 Remarks:
195 None.
196 *****************************************************************************/
197 void WF_ThrottleTableGet(tWFThrottleTable *p_table)
198 {
199 UINT8 msgBuf[WF_NUM_THROTTLE_TABLE_ROWS];
200 int i;
201  
202 memset(p_table, 0x00, sizeof(tWFThrottleTable));
203  
204 SendGetParamMsg(PARAM_TX_THROTTLE_TABLE, msgBuf, sizeof(msgBuf));
205  
206 for (i = 0; i < WF_NUM_THROTTLE_TABLE_ROWS; ++i)
207 {
208 /* strip off data rate bit */
209 if ((msgBuf[i] & 0x80) > 0)
210 {
211 p_table->dataRate[i] = WF_TWO_MBIT_TX_RATE;
212 }
213 else
214 {
215 p_table->dataRate[i] = WF_ONE_MBIT_TX_RATE;
216 }
217  
218 msgBuf[i] &= ~0x80; /* strip off rate bit */
219  
220 /* convert tx power from chip throttle table to user value (in dB) */
221 p_table->txPower[i] = WFPowerToAppPower(msgBuf[i]);
222 }
223 }
224  
225 /*******************************************************************************
226 Function:
227 static INT8 WFPowerToAppPower(UINT8 wfPower)
228  
229 Summary:
230 Converts Tx power value from MRF24WB0M to dB value for Host application.
231  
232 Description:
233  
234 Precondition:
235 MACInit must be called first.
236  
237 Parameters:
238 wfPower - Value from 0-128 indicating the power level from the MRF24WB0M.
239  
240 Returns:
241 A UINT8 of the converted power level.
242  
243 Remarks:
244 None.
245 *****************************************************************************/
246 static INT8 WFPowerToAppPower(UINT8 wfPower)
247 {
248 /* MRF24WB0M returns 0 to 128 where 64 is 0.0 dB and each step is 0.5 dB */
249 return (((INT8)wfPower - WF_ZERO_DB_VALUE) / 2);
250 }
251  
252 /*******************************************************************************
253 Function:
254 static INT8 WFPowerToAppPower(UINT8 wfPower)
255  
256 Summary:
257 Converts application Tx Power value to MRF24WB0M Tx power level.
258  
259 Description:
260  
261 Precondition:
262 MACInit must be called first.
263  
264 Parameters:
265 appPower - Value from the host application indicating the power level.
266 Returns:
267 A UINT8 of the converted power level.
268  
269 Remarks:
270 None.
271 *****************************************************************************/
272 static UINT8 AppPowerToWFPower(INT8 appPower)
273 {
274 return ((WF_ZERO_DB_VALUE + (appPower * 2)));
275 }
276  
277 /*******************************************************************************
278 Function:
279 void WF_ThrottleTableEnable()
280  
281 Summary:
282 Directs the MRF24WB0M to use the Tx Throttle Table.
283  
284 Description:
285  
286 Precondition:
287 MACInit must be called first.
288  
289 Parameters:
290 None.
291  
292 Returns:
293 None.
294  
295 Remarks:
296 None.
297 *****************************************************************************/
298 void WF_ThrottleTableEnable()
299 {
300 UINT8 msgByte;
301  
302 msgByte = TX_THOTTLE_ENABLE_BIT_MASK;
303 SendSetParamMsg(PARAM_TX_THROTTLE_TABLE_ON_OFF, &msgByte, sizeof(msgByte));
304 }
305  
306 /*******************************************************************************
307 Function:
308 void WF_ThrottleTableDisable(UINT8 bitRate)
309  
310 Summary:
311 Directs the MRF24WB0M to not use the Tx Throttle Table, and instead use the
312 input data rate at max Tx power.
313  
314 Description:
315  
316 Precondition:
317 MACInit must be called first.
318  
319 Parameters:
320 bitRate -- Desired bit rate. Can be either:
321 * WF_ONE_MBIT_TX_RATE
322 * WF_TWO_MBIT_TX_RATE
323  
324 Returns:
325 None.
326  
327 Remarks:
328 None.
329 *****************************************************************************/
330 void WF_ThrottleTableDisable(UINT8 bitRate)
331 {
332 UINT8 msgBuf[1];
333  
334 WF_ASSERT( (bitRate == WF_ONE_MBIT_TX_RATE) || (bitRate == WF_TWO_MBIT_TX_RATE) )
335  
336 msgBuf[0] = 0; /* set LSB to 0, disabling throttle table */
337  
338 /* fill in message byte with desired bit rate (in the upper 4 bits) */
339 if (bitRate == WF_ONE_MBIT_TX_RATE)
340 {
341 msgBuf[0] |= (0x02 << 4); /* 0x02 * 500kbps = 1mbps */
342 }
343 else
344 {
345 msgBuf[0] |= (0x04 << 4); /* 0x04 * 500kbps = 2mbps */
346 }
347  
348 SendSetParamMsg(PARAM_TX_THROTTLE_TABLE_ON_OFF, msgBuf, sizeof(msgBuf));
349 }
350  
351 /*******************************************************************************
352 Function:
353 void WF_ThrottleTableGetState(BOOL *p_state, UINT8 *p_bitRate)
354  
355 Summary:
356 Retrieves the current state of the MRF24WB0M Throttle Table.
357  
358 Description:
359  
360 Precondition:
361 MACInit must be called first.
362  
363 Parameters:
364 p_state -- pointer to where state will be written. TRUE if the Tx Throttle
365 Table is enabled, else FALSE.
366 bitRate -- only valid if *p_state is FALSE. Indicates the bit rate being
367 used by the MRF24WB0M (WF_ONE_MBIT_TX_RATE or
368 WF_TWO_MBIT_TX_RATE).
369  
370 Returns:
371 None.
372  
373 Remarks:
374 None.
375 *****************************************************************************/
376 void WF_ThrottleTableGetState(BOOL *p_state, UINT8 *p_bitRate)
377 {
378 UINT8 msgByte;
379  
380 SendGetParamMsg(PARAM_TX_THROTTLE_TABLE_ON_OFF, &msgByte, sizeof(msgByte));
381  
382 /* if throttle table is enabled */
383 if ((msgByte & TX_THOTTLE_ENABLE_BIT_MASK) > 0)
384 {
385 *p_state = TRUE;
386 *p_bitRate = 0xff; /* not applicable, but give it a known value */
387 }
388 /* else throttle table is disabled (upper 4 bits contain bit rate) */
389 else
390 {
391 *p_state = FALSE;
392 /* convert the message bit rate value to the API bit rate value. If upper 4 bits equal to 2 then 1mbps, else upper */
393 /* 4 bits are equal to 4, indicating 2mbps. */
394 if ( (msgByte >> 4) == 0x02)
395 {
396 *p_bitRate = WF_ONE_MBIT_TX_RATE;
397 }
398 else
399 {
400 *p_bitRate = WF_TWO_MBIT_TX_RATE;
401 }
402 }
403 }
404  
405 /*******************************************************************************
406 Function:
407 void WF_TxPowerSetMinMax(INT8 minTxPower, INT8 maxTxPower)
408  
409 Summary:
410 Sets the Tx min and max power on the MRF24WB0M.
411  
412 Description:
413 After initialization the MRF24WB0M max Tx power is determined by a
414 factory-set value. This function can set a different minimum and maximum
415 Tx power levels. However, this function can never set a maximum Tx power
416 greater than the factory-set value, which can be read via
417 WF_TxPowerGetFactoryMax().
418  
419 If the Tx Throttle Table is used, Tx power levels will be clipped, if
420 needed, by the values set in this function. In other words, values set here
421 will override values in the Tx Throttle Table to ensure that Tx power is
422 within the min/max range.
423  
424 Precondition:
425 MACInit must be called first.
426  
427 Parameters:
428 minTxPower -- desired minTxPower (-10 to 10dB)
429 maxTxPower -- desired maxTxPower (-10 to 10dB)
430  
431 Returns:
432 None.
433  
434 Remarks:
435 No conversion of units needed, input to MRF24WB0M is in dB.
436 *****************************************************************************/
437 void WF_TxPowerSetMinMax(INT8 minTxPower, INT8 maxTxPower)
438 {
439 INT8 factoryMaxPower;
440 UINT8 msgData[4]; /* need to input to chip two signed 16-bit values, max power followed by min power */
441 INT16 max = (INT16)maxTxPower;
442 INT16 min = (INT16)minTxPower;
443  
444 WF_ASSERT(minTxPower <= maxTxPower);
445  
446 WF_TxPowerGetFactoryMax(&factoryMaxPower);
447 WF_ASSERT(maxTxPower <= factoryMaxPower); /* cannot set max tx power greater than factor-set max tx power */
448  
449 msgData[0] = (INT8)(max >> 8); /* msb of max power */
450 msgData[1] = (INT8)(max & 0xff); /* lsb of max power */
451  
452 msgData[2] = (INT8)(min >> 8); /* msb of min power */
453 msgData[3] = (INT8)(min & 0xff); /* lsb of min power */
454  
455 SendSetParamMsg(PARAM_TX_POWER, msgData, sizeof(msgData));
456 }
457  
458 /*******************************************************************************
459 Function:
460 void WF_TxPowerGetMinMax(INT8 *p_minTxPower, INT8 *p_maxTxPower)
461  
462 Summary:
463 Gets the Tx min and max power on the MRF24WB0M.
464  
465 Description:
466 After initialization the MRF24WB0M max Tx power is determined by a
467 factory-set value. This function can set a different minimum and maximum
468 Tx power levels. However, this function can never set a maximum Tx power
469 greater than the factory-set value, which can be read via
470 WF_TxPowerGetFactoryMax().
471  
472 If the Tx Throttle Table is used, Tx power levels will be clipped, if
473 needed, by the values set in this function. In other words, values set here
474 will override values in the Tx Throttle Table to ensure that Tx power is
475 within the min/max range.
476  
477 Precondition:
478 MACInit must be called first.
479  
480 Parameters:
481 p_minTxPower -- pointer to location to write the minTxPower
482 p_maxTxPower -- pointer to location to write the maxTxPower
483  
484 Returns:
485 None.
486  
487 Remarks:
488 No conversion of units needed, input to MRF24WB0M is in dB.
489 *****************************************************************************/
490 void WF_TxPowerGetMinMax(INT8 *p_minTxPower, INT8 *p_maxTxPower)
491 {
492 UINT8 msgData[6];
493 INT16 tmp;
494  
495 SendGetParamMsg(PARAM_TX_POWER, msgData, sizeof(msgData));
496  
497 /* max tx power is a signed 16-bit value stored in the [1:0] msg data */
498 tmp = ((INT16)(msgData[0]) << 8);
499 tmp |= (INT16)msgData[1];
500 *p_maxTxPower = (INT8)tmp;
501  
502 /* min tx power is a signed 16-bit value stored in the [3:2] msg data */
503 tmp = ((INT16)(msgData[2]) << 8);
504 tmp |= (INT16)msgData[3];
505 *p_minTxPower = (INT8)tmp;
506  
507 }
508  
509 /*******************************************************************************
510 Function:
511 void WF_TxPowerGetFactoryMax(INT8 *p_factoryMaxTxPower)
512  
513 Summary:
514 Retrieves the factory-set max Tx power from the MRF24WB0M.
515  
516 Description:
517  
518 Precondition:
519 MACInit must be called first.
520  
521 Parameters:
522 p_factoryMaxTxPower -- desired maxTxPower (-10 to 10dB), in 1dB steps
523  
524 Returns:
525 None.
526  
527 Remarks:
528 None.
529 *****************************************************************************/
530 void WF_TxPowerGetFactoryMax(INT8 *p_factoryMaxTxPower)
531 {
532 UINT8 msgData[2];
533  
534 /* read max and min factory-set power levels */
535 SendGetParamMsg(PARAM_FACTORY_SET_TX_MAX_POWER, msgData, sizeof(msgData));
536  
537 /* msgData[0] = max power, msgData[1] = min power */
538 *p_factoryMaxTxPower = msgData[0];
539 }
540  
541  
542  
543 #endif /* WF_CS_TRIS && WF_USE_TX_POWER_CONTROL_FUNCTIONS */
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3