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