• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * tidef.h
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 #ifndef TIDEF_H
35 #define TIDEF_H
36 
37 #include "osTIType.h"
38 
39 /** \file  tidef.h
40  * \brief TI User Definitions APIs
41  * \n\n
42  * Note: TI_ prefix implies TI wrapping of primitives which is used for partability.
43  * E.g. using these interfaces enables porting between different OS under these
44  * interfaces without user notice.
45  * \n\n
46  */
47 
48 /**********************
49  *	Definitions
50  **********************/
51 
52 /**
53  * \def TI_FALSE
54  * \brief False value
55  */
56 #define TI_FALSE                    0
57 /**
58  * \def TI_TRUE
59  * \brief True value
60  */
61 #define TI_TRUE                     1
62 
63 /**
64  * \def TI_OK
65  * \brief OK return value
66  */
67 #define TI_OK                       0
68 /**
69  * \def TI_NOK
70  * \brief NOT OK return value
71  */
72 #define TI_NOK                      1
73 /**
74  * \def TI_PENDING
75  * \brief Pending return value
76  */
77 #define TI_PENDING					2
78 /**
79  * \def MAC_ADDR_LEN
80  * \brief Length of Standart MAC address
81  */
82 #define MAC_ADDR_LEN                6
83 /**
84  * \def IP_V4_ADDR_LEN
85  * \brief Length of Standart IP V4 address
86  */
87 #define REGISTER_SIZE		        4
88 #define IP_V4_ADDR_LEN              4
89 /**
90  * \def IP_V4_ADDR_LEN
91  * \brief Length of Standart IP V6 address
92  */
93 #define IP_V6_ADDR_LEN              6
94 
95 /**********************
96  *	Macros
97  **********************/
98 
99 
100 #ifndef TI_MAX
101 /**
102  * \def TI_MAX
103  * \brief Macro which returns the maximum of two values
104  */
105 #define TI_MAX(a,b)                 (((a) > (b)) ? (a) : (b))
106 #endif
107 
108 #ifndef TI_MIN
109 /**
110  * \def TI_MAX
111  * \brief Macro which returns the minimum of two values
112  */
113 #define TI_MIN(a,b)                 (((a) < (b)) ? (a) : (b))
114 #endif
115 
116 #ifndef NULL
117 /**
118  * \def NULL
119  * \brief Macro which returns NULL
120  */
121 #define NULL                        ((void *)0)
122 #endif
123 
124 /**
125  * \def TI_VOIDCAST
126  * \brief Macro which Casts to void
127  */
128 #ifndef TI_VOIDCAST
129 #define TI_VOIDCAST(p)             ((void)p)
130 #endif
131 
132 
133 #ifndef SIZE_ARR
134 /**
135  * \def SIZE_ARR
136  * \brief Macro which returns number of elements in array a
137  */
138 #define SIZE_ARR(a)                 (sizeof(a)/sizeof(a[0]))
139 #endif
140 
141 
142 #ifndef TI_FIELD_OFFSET
143 /**
144  * \def TI_FIELD_OFFSET
145  * \brief Macro which returns a field offset from structure begine
146  */
147 #define TI_FIELD_OFFSET(type,field)    ((TI_UINT32)(&(((type*)0)->field)))
148 #endif
149 
150 
151 #ifndef TI_BIT
152 #define TI_BIT(x)                   (1 << (x))
153 #endif
154 
155 
156 #ifndef IS_MASK_ON
157 /**
158  * \def IS_MASK_ON
159  * \brief Macro which returns True if bitmask in field is on (==1) \n
160  * Otherwise returns False
161  */
162 #define IS_MASK_ON(  field, bitmask ) (  (bitmask) == ( (field) &  (bitmask) ) )
163 #endif
164 
165 #ifndef IS_MASK_OFF
166 /**
167  * \def IS_MASK_OFF
168  * \brief Macro which returns True if bitmask in field is off (==0) \n
169  * Otherwise returns False
170  */
171 #define IS_MASK_OFF( field, bitmask ) ( ~(bitmask) == ( (field) | ~(bitmask) ) )
172 #endif
173 
174 
175 #ifndef INRANGE
176 /**
177  * \def INRANGE
178  * \brief Macro which returns True if value (x) in range (law <= x <= high) \n
179  * Otherwise returns False
180  */
181 #define INRANGE(x,low,high)         (((x) >= (low)) && ((x) <= (high)))
182 #endif
183 
184 #ifndef OUTRANGE
185 /**
186  * \def OUTRANGE
187  * \brief Macro which returns True if value (x) out of range (x < law | x > high) \n
188  * Otherwise returns False
189  */
190 #define OUTRANGE(x,low,high)        (((x) < (low)) || ((x) > (high)))
191 #endif
192 
193 /* Due to alignment exceptions MAC_COPY and MAC_EQUAL are done byte by byte */
194 
195 /**
196  * \def MAC_COPY
197  * \brief Macro which copies 6 bytes source to 6 bytes destination \n
198  * Due to alignment exceptions MAC_COPY is done byte by byte
199  */
200 #define MAC_COPY(dst,src)           *((TI_UINT8*)&((dst)[0])) = *((TI_UINT8*)&((src)[0])); \
201                                     *((TI_UINT8*)&((dst)[1])) = *((TI_UINT8*)&((src)[1])); \
202                                     *((TI_UINT8*)&((dst)[2])) = *((TI_UINT8*)&((src)[2])); \
203                                     *((TI_UINT8*)&((dst)[3])) = *((TI_UINT8*)&((src)[3])); \
204                                     *((TI_UINT8*)&((dst)[4])) = *((TI_UINT8*)&((src)[4])); \
205                                     *((TI_UINT8*)&((dst)[5])) = *((TI_UINT8*)&((src)[5]))
206 /**
207  * \def MAC_EQUAL
208  * \brief Macro which compares 6 bytes ofmac1 to 6 bytes of mac2 and returns True if all are equall \n
209  * Otherwise returns False \n
210  * Due to alignment exceptions MAC_EQUAL is done byte by byte
211  */
212 #define MAC_EQUAL(mac1,mac2)        (*((TI_UINT8*)&((mac1)[0])) == *((TI_UINT8*)&((mac2)[0])) && \
213                                      *((TI_UINT8*)&((mac1)[1])) == *((TI_UINT8*)&((mac2)[1])) && \
214                                      *((TI_UINT8*)&((mac1)[2])) == *((TI_UINT8*)&((mac2)[2])) && \
215                                      *((TI_UINT8*)&((mac1)[3])) == *((TI_UINT8*)&((mac2)[3])) && \
216                                      *((TI_UINT8*)&((mac1)[4])) == *((TI_UINT8*)&((mac2)[4])) && \
217                                      *((TI_UINT8*)&((mac1)[5])) == *((TI_UINT8*)&((mac2)[5])))
218 /**
219  * \def MAC_BROADCAST
220  * \brief Macro which returns True if MAC address is broadcast (equals "\xff\xff\xff\xff\xff\xff") \n
221  * Otherwise returns False
222  */
223 #define MAC_BROADCAST(mac)          MAC_EQUAL (mac, "\xff\xff\xff\xff\xff\xff")
224 /**
225  * \def MAC_NULL
226  * \brief Macro which returns True if MAC address is Null (equals "\x0\x0\x0\x0\x0\x0") \n
227  * Otherwise returns False
228  */
229 #define MAC_NULL(mac)               MAC_EQUAL (mac, "\x0\x0\x0\x0\x0\x0")
230 /**
231  * \def MAC_MULTICAST
232  * \brief Macro which returns True if MAC address is Multicast\n
233  * Otherwise returns False
234  */
235 #define MAC_MULTICAST(mac)          ((mac)[0] & 0x01)
236 /**
237  * \def IP_COPY
238  * \brief Macro which copies IP V4 source to IP V4 destination
239  */
240 #define IP_COPY(dst,src)            *((TI_UINT32*)(dst)) = *((TI_UINT32*)(src))
241 /**
242  * \def BYTE_SWAP_WORD
243  * \brief Macro which swaps Word's bytes. Used for Endian handling
244  */
245 #define BYTE_SWAP_WORD(x)           ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
246 /**
247  * \def BYTE_SWAP_LONG
248  * \brief Macro which swaps Long's bytes. Used for Endian handling
249  */
250 #define BYTE_SWAP_LONG(x)           ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) | \
251                                      (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24))
252 
253 
254 /* TI always supports Little Endian */
255 #if defined (__BYTE_ORDER_BIG_ENDIAN)
256 
257 #define WLANTOHL(x)                 (x)
258 #define WLANTOHS(x)                 (x)
259 #define HTOWLANL(x)                 (x)
260 #define HTOWLANS(x)                 (x)
261 
262 #define ENDIAN_HANDLE_WORD(x)       BYTE_SWAP_WORD (x)
263 #define ENDIAN_HANDLE_LONG(x)       BYTE_SWAP_LONG (x)
264 
265 #define INT64_LOWER(x)              *(((TI_UINT32*)&(x))+1)
266 #define INT64_HIGHER(x)             *((TI_UINT32*)&(x))
267 
268 #define COPY_WLAN_WORD(dst,src)     ((TI_UINT8 *)(dst))[0] = ((TI_UINT8 *)(src))[1]; \
269                                     ((TI_UINT8 *)(dst))[1] = ((TI_UINT8 *)(src))[0]
270 #define COPY_WLAN_LONG(dst,src)     ((TI_UINT8 *)(dst))[0] = ((TI_UINT8 *)(src))[3]; \
271                                     ((TI_UINT8 *)(dst))[1] = ((TI_UINT8 *)(src))[2]; \
272                                     ((TI_UINT8 *)(dst))[2] = ((TI_UINT8 *)(src))[1]; \
273                                     ((TI_UINT8 *)(dst))[3] = ((TI_UINT8 *)(src))[0]
274 
275 #define SET_WLAN_WORD(dst,val)      ((TI_UINT8 *)(dst))[1] =  (val)        & 0xff; \
276                                     ((TI_UINT8 *)(dst))[0] = ((val) >> 8)  & 0xff
277 
278 #define SET_WLAN_LONG(dst,val)      ((TI_UINT8 *)(dst))[3] =  (val)        & 0xff; \
279                                     ((TI_UINT8 *)(dst))[2] = ((val) >> 8)  & 0xff; \
280                                     ((TI_UINT8 *)(dst))[1] = ((val) >> 16) & 0xff; \
281                                     ((TI_UINT8 *)(dst))[0] = ((val) >> 24) & 0xff
282 
283 #define WLAN_WORD(src)              (((TI_UINT8 *)(src))[1]) | (((TI_UINT8 *)(src))[0] << 8)
284 #define WLAN_LONG(src)              (((TI_UINT8 *)(src))[3]) | (((TI_UINT8 *)(src))[2] << 8) | (((TI_UINT8 *)(src))[1] << 16) | (((TI_UINT8 *)(src))[0] << 24)
285 
286 #elif defined (__BYTE_ORDER_LITTLE_ENDIAN)
287 
288 /**
289  * \def WLANTOHL
290  * \brief Macro which performs bytes swap of Long in Little Endian
291  */
292 #define WLANTOHL(x)                 BYTE_SWAP_LONG (x)
293 /**
294  * \def WLANTOHS
295  * \brief Macro which performs bytes swap of Word in Little Endian
296  */
297 #define WLANTOHS(x)                 BYTE_SWAP_WORD (x)
298 /**
299  * \def HTOWLANL
300  * \brief Macro which performs bytes swap of Long in Little Endian
301  */
302 #define HTOWLANL(x)                 BYTE_SWAP_LONG (x)
303 /**
304  * \def HTOWLANL
305  * \brief Macro which performs bytes swap of Word in Little Endian
306  */
307 #define HTOWLANS(x)                 BYTE_SWAP_WORD (x)
308 
309 /**
310  * \def ENDIAN_HANDLE_WORD
311  * \brief Macro which handles Word in Little Endian
312  */
313 #define ENDIAN_HANDLE_WORD(x)       (x)
314 /**
315  * \def ENDIAN_HANDLE_WORD
316  * \brief Macro which handles Long in Little Endian
317  */
318 #define ENDIAN_HANDLE_LONG(x)       (x)
319 
320 /**
321  * \def INT64_HIGHER
322  * \brief Macro which returns the content of higher address of INT64 variable in Little Endian
323  */
324 #define INT64_HIGHER(x)             *(((TI_UINT32*)&(x))+1)
325 /**
326  * \def INT64_LOWER
327  * \brief Macro which returns the content of lower address of INT64 variable in Little Endian
328  */
329 #define INT64_LOWER(x)              *((TI_UINT32*)&(x))
330 
331 /**
332  * \def COPY_WLAN_WORD
333  * \brief Macro which copies word source to word destination byte by byte in Little Endian
334  */
335 #define COPY_WLAN_WORD(dst,src)     ((TI_UINT8 *)(dst))[0] = ((TI_UINT8 *)(src))[0]; \
336                                     ((TI_UINT8 *)(dst))[1] = ((TI_UINT8 *)(src))[1]
337 /**
338  * \def COPY_WLAN_LONG
339  * \brief Macro which copies long source to long destination byte by byte in Little Endian
340  */
341 #define COPY_WLAN_LONG(dst,src)     ((TI_UINT8 *)(dst))[0] = ((TI_UINT8 *)(src))[0]; \
342                                     ((TI_UINT8 *)(dst))[1] = ((TI_UINT8 *)(src))[1]; \
343                                     ((TI_UINT8 *)(dst))[2] = ((TI_UINT8 *)(src))[2]; \
344                                     ((TI_UINT8 *)(dst))[3] = ((TI_UINT8 *)(src))[3]
345 /**
346  * \def SET_WLAN_WORD
347  * \brief Macro which copies Word from val source to desrination in Little Endian
348  */
349 #define SET_WLAN_WORD(dst,val)      ((TI_UINT8 *)(dst))[0] =  (val)        & 0xff; \
350                                     ((TI_UINT8 *)(dst))[1] = ((val) >> 8)  & 0xff
351 /**
352  * \def SET_WLAN_LONG
353  * \brief Macro which copies Long from val source to desrination in Little Endian
354  */
355 #define SET_WLAN_LONG(dst,val)      ((TI_UINT8 *)(dst))[0] =  (val)        & 0xff; \
356                                     ((TI_UINT8 *)(dst))[1] = ((val) >> 8)  & 0xff; \
357                                     ((TI_UINT8 *)(dst))[2] = ((val) >> 16) & 0xff; \
358                                     ((TI_UINT8 *)(dst))[3] = ((val) >> 24) & 0xff
359 /**
360  * \def WLAN_WORD
361  * \brief Macro which returns Word value from source address in Little Endian
362  */
363 #define WLAN_WORD(src)              (((TI_UINT8 *)(src))[0]) | (((TI_UINT8 *)(src))[1] << 8)
364 /**
365  * \def WLAN_LONG
366  * \brief Macro which returns Long value from source address in Little Endian
367  */
368 #define WLAN_LONG(src)              (((TI_UINT8 *)(src))[0]) | (((TI_UINT8 *)(src))[1] << 8) | (((TI_UINT8 *)(src))[2] << 16) | (((TI_UINT8 *)(src))[3] << 24)
369 #else
370 
371 #error "Must define byte order (BIG/LITTLE ENDIAN)"
372 
373 #endif
374 
375 
376 /**********************
377  *	types
378  **********************/
379 
380 /**
381  * \typedef TI_HANDLE
382  * \brief Handle type - Pointer to void
383  */
384 typedef void*                       TI_HANDLE;
385 /**
386  * \typedef TI_BOOL
387  * \brief Boolean type
388  * \n
389  * Used for indicating True or False ( TI_TRUE | TI_FALSE )
390  */
391 typedef TI_UINT32                   TI_BOOL;
392 /**
393  * \typedef TI_STATUS
394  * \brief Return Status type
395  * \n
396  * Used as return status ( TI_OK | TI_NOK | TI_PENDING )
397  */
398 typedef TI_UINT32                   TI_STATUS;
399 /**
400  * \typedef TMacAddr
401  * \brief MAC Address Type
402  * \n
403  * A buffer (size of Standart MAC Address Length in bytes) which holds a MAC address
404  */
405 typedef TI_UINT8                    TMacAddr [MAC_ADDR_LEN];
406 /**
407  * \typedef TIpAddr
408  * \brief IP V4 Address Type
409  * \n
410  * A buffer (size of Standart IP V4 Address Length in bytes) which holds IP V4 address
411  */
412 typedef TI_UINT8                    TIpAddr [IP_V4_ADDR_LEN];
413 
414 #endif /* TIDEF_H */
415 
416 
417