Home | History | Annotate | Download | only in include
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2014 The Android Open Source Project
      4  *  Copyright 2002 - 2004 Open Interface North America, Inc. All rights
      5  *                        reserved.
      6  *
      7  *  Licensed under the Apache License, Version 2.0 (the "License");
      8  *  you may not use this file except in compliance with the License.
      9  *  You may obtain a copy of the License at:
     10  *
     11  *  http://www.apache.org/licenses/LICENSE-2.0
     12  *
     13  *  Unless required by applicable law or agreed to in writing, software
     14  *  distributed under the License is distributed on an "AS IS" BASIS,
     15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16  *  See the License for the specific language governing permissions and
     17  *  limitations under the License.
     18  *
     19  ******************************************************************************/
     20 #ifndef OI_STDDEFS_H
     21 #define OI_STDDEFS_H
     22 /**
     23  * @file
     24  * This file contains BM3 standard type definitions.
     25  *
     26  */
     27 
     28 /*******************************************************************************
     29   $Revision: #1 $
     30  ******************************************************************************/
     31 
     32 #include "oi_cpu_dep.h"
     33 
     34 /** \addtogroup Misc Miscellaneous APIs */
     35 /**@{*/
     36 
     37 #ifdef __cplusplus
     38 extern "C" {
     39 #endif
     40 
     41 #ifndef FALSE
     42 #define FALSE \
     43   0 /**< This define statement sets FALSE as a preprocessor alias for 0. */
     44 #endif
     45 
     46 #ifndef TRUE
     47 #define TRUE                                                                \
     48   (!FALSE) /**< This define statement sets TRUE as a preprocessor alias for \
     49               !FALSE. */
     50 #endif
     51 
     52 #ifdef HEW_TOOLCHAIN
     53 #ifdef NULL
     54 #undef NULL /**< Override HEW toolchain NULL definition */
     55 #endif
     56 #define NULL                                                                 \
     57   0 /**< HEW toolchain does not allow us to compare (void*) type to function \
     58        pointer */
     59 #else
     60 #ifndef NULL
     61 #define NULL                                                              \
     62   ((void*)0) /**< This define statement sets NULL as a preprocessor alias \
     63                 for (void*)0 */
     64 #endif
     65 #endif
     66 
     67 /**
     68  * @name  Maximum and minimum values for basic types
     69  * @{
     70  */
     71 #define OI_INT8_MIN ((int8_t)0x80)     /**< decimal value: -128 */
     72 #define OI_INT8_MAX ((int8_t)0x7F)     /**< decimal value: 127 */
     73 #define OI_INT16_MIN ((int16_t)0x8000) /**< decimal value: -32768 */
     74 #define OI_INT16_MAX ((int16_t)0x7FFF) /**< decimal value: 32767 */
     75 #define OI_INT32_MIN                                       \
     76   ((int32_t)0x80000000) /**< decimal value: -2,147,483,648 \
     77                            */
     78 #define OI_INT32_MAX                                                       \
     79   ((int32_t)0x7FFFFFFF)                  /**< decimal value: 2,147,483,647 \
     80                                             */
     81 #define OI_UINT8_MIN ((uint8_t)0)        /**< decimal value: 0 */
     82 #define OI_UINT8_MAX ((uint8_t)0xFF)     /**< decimal value: 255 */
     83 #define OI_UINT16_MIN ((uint16_t)0)      /**< decimal value: 0 */
     84 #define OI_UINT16_MAX ((uint16_t)0xFFFF) /**< decimal value: 65535 */
     85 #define OI_UINT32_MIN ((uint32_t)0)      /**< decimal value: 0 */
     86 #define OI_UINT32_MAX \
     87   ((uint32_t)0xFFFFFFFF) /**< decimal value: 4,294,967,295 */
     88 
     89 /**
     90  * @}
     91  */
     92 
     93 /**
     94  * @name  Integer types required by the Service Discovery Protocol
     95  * @{
     96  */
     97 
     98 /** unsigned 64-bit integer as a structure of two unsigned 32-bit integers */
     99 typedef struct {
    100   uint32_t I1; /**< most significant 32 bits */
    101   uint32_t I2; /**< least significant 32 bits */
    102 } OI_UINT64;
    103 
    104 #define OI_UINT64_MIN \
    105   { (uint32_t)0x00000000, (uint32_t)0x00000000 }
    106 #define OI_UINT64_MAX \
    107   { (uint32_t)0XFFFFFFFF, (uint32_t)0XFFFFFFFF }
    108 
    109 /* signed 64-bit integer as a structure of one unsigned 32-bit integer and one
    110  * signed 32-bit integer
    111  */
    112 typedef struct {
    113   int32_t I1;  /**< most significant 32 bits  as a signed integer */
    114   uint32_t I2; /**< least significant 32 bits as an unsigned integer */
    115 } OI_INT64;
    116 
    117 #define OI_INT64_MIN \
    118   { (int32_t)0x80000000, (uint32_t)0x00000000 }
    119 #define OI_INT64_MAX \
    120   { (int32_t)0X7FFFFFFF, (uint32_t)0XFFFFFFFF }
    121 
    122 /** unsigned 128-bit integer as a structure of four unsigned 32-bit integers */
    123 typedef struct {
    124   uint32_t I1; /**< most significant 32 bits */
    125   uint32_t I2; /**< second-most significant 32 bits */
    126   uint32_t I3; /**< third-most significant 32 bits */
    127   uint32_t I4; /**< least significant 32 bits */
    128 } OI_UINT128;
    129 
    130 #define OI_UINT128_MIN                                                \
    131   {                                                                   \
    132     (uint32_t)0x00000000, (uint32_t)0x00000000, (uint32_t)0x00000000, \
    133         (uint32_t)0x00000000                                          \
    134   }
    135 #define OI_UINT128_MAX                                                \
    136   {                                                                   \
    137     (uint32_t)0XFFFFFFFF, (uint32_t)0XFFFFFFFF, (uint32_t)0XFFFFFFFF, \
    138         (uint32_t)0XFFFFFFFF                                          \
    139   }
    140 
    141 /* signed 128-bit integer as a structure of three unsigned 32-bit integers and
    142  * one signed 32-bit integer */
    143 typedef struct {
    144   int32_t I1;  /**< most significant 32 bits as a signed integer */
    145   uint32_t I2; /**< second-most significant 32 bits as an unsigned integer */
    146   uint32_t I3; /**< third-most significant 32 bits as an unsigned integer */
    147   uint32_t I4; /**< least significant 32 bits as an unsigned integer */
    148 } OI_INT128;
    149 
    150 #define OI_INT128_MIN                                                 \
    151   {                                                                   \
    152     (uint32_t)0x80000000, (uint32_t)0x00000000, (uint32_t)0x00000000, \
    153         (uint32_t)0x00000000                                          \
    154   }
    155 #define OI_INT128_MAX                                                 \
    156   {                                                                   \
    157     (uint32_t)0X7FFFFFFF, (uint32_t)0XFFFFFFFF, (uint32_t)0XFFFFFFFF, \
    158         (uint32_t)0XFFFFFFFF                                          \
    159   }
    160 
    161 /**
    162  * @}
    163  */
    164 
    165 /**
    166  * type for ASCII character data items
    167  */
    168 typedef char OI_CHAR;
    169 
    170 /**
    171  * type for double-byte character data items
    172  */
    173 typedef uint16_t OI_CHAR16;
    174 
    175 /**
    176  * types for UTF encoded strings.
    177  */
    178 typedef uint8_t OI_UTF8;
    179 typedef uint16_t OI_UTF16;
    180 typedef uint32_t OI_UTF32;
    181 
    182 /**
    183  * @name Single-bit operation macros
    184  * @{
    185  * In these macros, x is the data item for which a bit is to be tested or set
    186  * and y specifies which bit is to be tested or set.
    187  */
    188 
    189 /* This macro's value is true if the bit specified by y is set in data item x.
    190  */
    191 #define OI_BIT_TEST(x, y) ((x) & (y))
    192 
    193 /* This macro's value is true if the bit specified by y is not set in data item
    194  * x.
    195  */
    196 #define OI_BIT_CLEAR_TEST(x, y) (((x) & (y)) == 0)
    197 
    198 /** This macro sets the bit specified by y in data item x. */
    199 #define OI_BIT_SET(x, y) ((x) |= (y))
    200 
    201 /** This macro clears the bit specified by y in data item x. */
    202 #define OI_BIT_CLEAR(x, y) ((x) &= ~(y))
    203 
    204 /** @} */
    205 
    206 /**
    207  * The OI_ARRAYSIZE macro is set to the number of elements in an array
    208  * (instead of the number of bytes, which is returned by sizeof()).
    209  */
    210 
    211 #ifndef OI_ARRAYSIZE
    212 #define OI_ARRAYSIZE(a) (sizeof(a) / sizeof((a)[0]))
    213 #endif
    214 
    215 /**
    216  * @name Preprocessor aliases for individual bit positions
    217  *      Bits are defined here only if they are not already defined.
    218  * @{
    219  */
    220 
    221 #ifndef BIT0
    222 
    223 #define BIT0                                                                  \
    224   0x00000001 /**< preprocessor alias for 32-bit value with bit 0 set, used to \
    225                 specify this single bit */
    226 #define BIT1                                                                  \
    227   0x00000002 /**< preprocessor alias for 32-bit value with bit 1 set, used to \
    228                 specify this single bit */
    229 #define BIT2                                                                  \
    230   0x00000004 /**< preprocessor alias for 32-bit value with bit 2 set, used to \
    231                 specify this single bit */
    232 #define BIT3                                                                  \
    233   0x00000008 /**< preprocessor alias for 32-bit value with bit 3 set, used to \
    234                 specify this single bit */
    235 #define BIT4                                                                  \
    236   0x00000010 /**< preprocessor alias for 32-bit value with bit 4 set, used to \
    237                 specify this single bit */
    238 #define BIT5                                                                  \
    239   0x00000020 /**< preprocessor alias for 32-bit value with bit 5 set, used to \
    240                 specify this single bit */
    241 #define BIT6                                                                  \
    242   0x00000040 /**< preprocessor alias for 32-bit value with bit 6 set, used to \
    243                 specify this single bit */
    244 #define BIT7                                                                  \
    245   0x00000080 /**< preprocessor alias for 32-bit value with bit 7 set, used to \
    246                 specify this single bit */
    247 #define BIT8                                                                  \
    248   0x00000100 /**< preprocessor alias for 32-bit value with bit 8 set, used to \
    249                 specify this single bit */
    250 #define BIT9                                                                  \
    251   0x00000200 /**< preprocessor alias for 32-bit value with bit 9 set, used to \
    252                 specify this single bit */
    253 #define BIT10                                                                  \
    254   0x00000400 /**< preprocessor alias for 32-bit value with bit 10 set, used to \
    255                 specify this single bit */
    256 #define BIT11                                                                  \
    257   0x00000800 /**< preprocessor alias for 32-bit value with bit 11 set, used to \
    258                 specify this single bit */
    259 #define BIT12                                                                  \
    260   0x00001000 /**< preprocessor alias for 32-bit value with bit 12 set, used to \
    261                 specify this single bit */
    262 #define BIT13                                                                  \
    263   0x00002000 /**< preprocessor alias for 32-bit value with bit 13 set, used to \
    264                 specify this single bit */
    265 #define BIT14                                                                  \
    266   0x00004000 /**< preprocessor alias for 32-bit value with bit 14 set, used to \
    267                 specify this single bit */
    268 #define BIT15                                                                  \
    269   0x00008000 /**< preprocessor alias for 32-bit value with bit 15 set, used to \
    270                 specify this single bit */
    271 #define BIT16                                                                  \
    272   0x00010000 /**< preprocessor alias for 32-bit value with bit 16 set, used to \
    273                 specify this single bit */
    274 #define BIT17                                                                  \
    275   0x00020000 /**< preprocessor alias for 32-bit value with bit 17 set, used to \
    276                 specify this single bit */
    277 #define BIT18                                                                  \
    278   0x00040000 /**< preprocessor alias for 32-bit value with bit 18 set, used to \
    279                 specify this single bit */
    280 #define BIT19                                                                  \
    281   0x00080000 /**< preprocessor alias for 32-bit value with bit 19 set, used to \
    282                 specify this single bit */
    283 #define BIT20                                                                  \
    284   0x00100000 /**< preprocessor alias for 32-bit value with bit 20 set, used to \
    285                 specify this single bit */
    286 #define BIT21                                                                  \
    287   0x00200000 /**< preprocessor alias for 32-bit value with bit 21 set, used to \
    288                 specify this single bit */
    289 #define BIT22                                                                  \
    290   0x00400000 /**< preprocessor alias for 32-bit value with bit 22 set, used to \
    291                 specify this single bit */
    292 #define BIT23                                                                  \
    293   0x00800000 /**< preprocessor alias for 32-bit value with bit 23 set, used to \
    294                 specify this single bit */
    295 #define BIT24                                                                  \
    296   0x01000000 /**< preprocessor alias for 32-bit value with bit 24 set, used to \
    297                 specify this single bit */
    298 #define BIT25                                                                  \
    299   0x02000000 /**< preprocessor alias for 32-bit value with bit 25 set, used to \
    300                 specify this single bit */
    301 #define BIT26                                                                  \
    302   0x04000000 /**< preprocessor alias for 32-bit value with bit 26 set, used to \
    303                 specify this single bit */
    304 #define BIT27                                                                  \
    305   0x08000000 /**< preprocessor alias for 32-bit value with bit 27 set, used to \
    306                 specify this single bit */
    307 #define BIT28                                                                  \
    308   0x10000000 /**< preprocessor alias for 32-bit value with bit 28 set, used to \
    309                 specify this single bit */
    310 #define BIT29                                                                  \
    311   0x20000000 /**< preprocessor alias for 32-bit value with bit 29 set, used to \
    312                 specify this single bit */
    313 #define BIT30                                                                  \
    314   0x40000000 /**< preprocessor alias for 32-bit value with bit 30 set, used to \
    315                 specify this single bit */
    316 #define BIT31                                                                  \
    317   0x80000000 /**< preprocessor alias for 32-bit value with bit 31 set, used to \
    318                 specify this single bit */
    319 
    320 #endif /* BIT0 et al */
    321 
    322 /** @} */
    323 
    324 #ifdef __cplusplus
    325 }
    326 #endif
    327 
    328 /**@}*/
    329 
    330 /*****************************************************************************/
    331 #endif /* OI_STDDEFS_H */
    332