OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / system / wlan / ti / wilink_6_1 / utils / freq.c
1 /*
2  * freq.c
3  *
4  * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.      
5  * All rights reserved.                                                  
6  *                                                                       
7  * Redistribution and use in source and binary forms, with or without    
8  * modification, are permitted provided that the following conditions    
9  * are met:                                                              
10  *                                                                       
11  *  * Redistributions of source code must retain the above copyright     
12  *    notice, this list of conditions and the following disclaimer.      
13  *  * Redistributions in binary form must reproduce the above copyright  
14  *    notice, this list of conditions and the following disclaimer in    
15  *    the documentation and/or other materials provided with the         
16  *    distribution.                                                      
17  *  * Neither the name Texas Instruments nor the names of its            
18  *    contributors may be used to endorse or promote products derived    
19  *    from this software without specific prior written permission.      
20  *                                                                       
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 /** \file  freq.c
35  *  \brief frequency to channel (and vice versa) conversion implementation
36  *
37  *  \see   freq.h
38  */
39
40
41 #define __FILE_ID__  FILE_ID_126
42 #include "osTIType.h"
43
44 #define     CHAN_FREQ_TABLE_SIZE        (sizeof(ChanFreq) / sizeof(CHAN_FREQ))
45
46 typedef struct {
47     TI_UINT8       chan;
48     TI_UINT32      freq;
49 } CHAN_FREQ;
50
51 static CHAN_FREQ ChanFreq[] = {
52     {1,  2412000},
53     {2,  2417000},
54     {3,  2422000},
55     {4,  2427000},
56     {5,  2432000},
57     {6,  2437000},
58     {7,  2442000},
59     {8,  2447000},
60     {9,  2452000},
61     {10, 2457000},
62     {11, 2462000},
63     {12, 2467000},
64     {13, 2472000}, 
65     {14, 2484000}, 
66     {34, 5170000},
67     {36, 5180000},
68     {38, 5190000},
69     {40, 5200000},
70     {42, 5210000},
71     {44, 5220000},
72     {46, 5230000}, 
73     {48, 5240000},
74     {52, 5260000},
75     {56, 5280000},
76     {60, 5300000},
77     {64, 5320000},
78     {100,5500000},
79     {104,5520000},
80     {108,5540000},
81     {112,5560000},
82     {116,5580000},
83     {120,5600000},
84     {124,5620000},
85     {128,5640000},
86     {132,5660000},
87     {136,5680000},
88     {140,5700000},
89     {149,5745000},
90     {153,5765000},
91     {157,5785000},
92     {161,5805000}
93   };
94
95 TI_UINT8 Freq2Chan (TI_UINT32 freq)
96 {
97     TI_UINT32   i;
98
99     for (i = 0; i < CHAN_FREQ_TABLE_SIZE; i++)
100     {
101         if (ChanFreq[ i ].freq == freq)
102         {
103             return ChanFreq[ i ].chan;
104         }
105     }
106
107     return 0;
108 }
109
110
111 TI_UINT32 Chan2Freq (TI_UINT8 chan)
112 {
113     TI_UINT32   i;
114
115     for (i = 0; i < CHAN_FREQ_TABLE_SIZE; i++)
116     {
117         if (ChanFreq[ i ].chan == chan)
118         {
119             return ChanFreq[ i ].freq;
120         }
121     }
122
123     return 0;
124 }
125