M4OSA_Types.h revision 855ec7c4be7ad642721909d5837a8d25a117c22f
1/* 2 * Copyright (C) 2004-2011 NXP Software 3 * Copyright (C) 2011 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17/** 18 ************************************************************************ 19 * @file M4OSA_Types.h 20 * @ingroup OSAL 21 * @brief Abstraction types for Android 22 * @note This file redefines basic types which must be 23 * used to declare any variable. 24************************************************************************ 25*/ 26 27 28#ifndef M4OSA_TYPES_H 29#define M4OSA_TYPES_H 30 31#include <ctype.h> 32#include "M4OSA_Export.h" 33#ifdef __cplusplus 34extern "C" { 35#endif 36 37/*#define M4OSA_64BITS_SUPPORTED */ /* means long long is used */ 38/*#define M4OSA_64BITS_COUPLE_INT */ /* means couple int32 is used */ 39#define M4OSA_64BITS_NOT_SUPPORTED /* means Int32 is used */ 40 41 42typedef signed char M4OSA_Bool; 43typedef unsigned char M4OSA_UInt8; 44typedef signed char M4OSA_Int8; 45typedef unsigned short M4OSA_UInt16; 46typedef signed short M4OSA_Int16; 47typedef unsigned long M4OSA_UInt32; 48typedef signed long M4OSA_Int32; 49 50typedef signed char M4OSA_Char; 51typedef unsigned char M4OSA_UChar; 52 53typedef double M4OSA_Double; 54typedef float M4OSA_Float; 55 56typedef unsigned char M4OSA_WChar; 57 58typedef void M4OSA_Void; 59 60typedef struct 61{ 62 M4OSA_Int32 high; 63 M4OSA_Int32 low; 64} M4OSA_CoupleInt32; 65 66#ifdef M4OSA_64BITS_SUPPORTED 67typedef signed long long M4OSA_Int64; 68typedef unsigned long long M4OSA_UInt64; 69#endif 70 71#ifdef M4OSA_64BITS_COUPLE_INT 72typedef struct 73{ 74 M4OSA_Int32 major; 75 M4OSA_UInt32 minor; 76} M4OSA_Int64; 77typedef struct 78{ 79 M4OSA_UInt32 major; 80 M4OSA_UInt32 minor; 81} M4OSA_UInt64; 82#endif 83 84#ifdef M4OSA_64BITS_NOT_SUPPORTED 85typedef M4OSA_Int32 M4OSA_Int64; 86typedef M4OSA_UInt32 M4OSA_UInt64; 87#endif 88 89/* Min & max definitions*/ 90#define M4OSA_UINT8_MIN 0 91#define M4OSA_UINT8_MAX 255 92 93#define M4OSA_UINT16_MIN 0 94#define M4OSA_UINT16_MAX 65535 95 96#define M4OSA_UINT32_MIN 0 97#define M4OSA_UINT32_MAX 0xFFFFFFFF 98 99#define M4OSA_INT8_MIN -128 100#define M4OSA_INT8_MAX 127 101 102#define M4OSA_INT16_MIN -32768 103#define M4OSA_INT16_MAX 32767 104 105#define M4OSA_INT32_MIN (-0x7FFFFFFF-1) 106#define M4OSA_INT32_MAX 0x7FFFFFFF 107 108#define M4OSA_CHAR_MIN -128 109#define M4OSA_CHAR_MAX 127 110 111#define M4OSA_UCHAR_MIN 0 112#define M4OSA_UCHAR_MAX 255 113 114#ifdef M4OSA_64BITS_NOT_SUPPORTED 115 116#define M4OSA_UINT64_MIN M4OSA_UINT32_MIN 117#define M4OSA_UINT64_MAX M4OSA_UINT32_MAX 118#define M4OSA_INT64_MIN M4OSA_INT32_MIN 119#define M4OSA_INT64_MAX M4OSA_INT32_MAX 120 121#else /* M4OSA_64BITS_NOT_SUPPORTED*/ 122 123#define M4OSA_UINT64_MIN 0 124#define M4OSA_UINT64_MAX 0xFFFFFFFFFFFFFFFFLL 125#define M4OSA_INT64_MIN 0x8000000000000000LL 126#define M4OSA_INT64_MAX 0x7FFFFFFFFFFFFFFFLL 127 128#endif /* M4OSA_64BITS_NOT_SUPPORTED*/ 129 130#define M4OSA_NULL 0x00 131#define M4OSA_TRUE 0x01 132#define M4OSA_FALSE 0x00 133#define M4OSA_WAIT_FOREVER 0xffffffff 134 135#define M4OSA_CONST const 136#define M4OSA_INLINE inline 137 138/* Rollover offset of the clock */ 139/* This value must be the one of M4OSA_clockGetTime */ 140#define M4OSA_CLOCK_ROLLOVER M4OSA_INT32_MAX 141 142typedef void* M4OSA_Context; 143 144 145/** It is a unique ID for each core component*/ 146typedef M4OSA_UInt16 M4OSA_CoreID; 147 148 149/* Macro to support big endian and little endian platform */ 150 151/* to translate a 16 bits to its Big Endian value*/ 152#define M4OSA_INT16_TO_BE(ui16_host) ((((ui16_host) & (M4OSA_UInt16) 0x00ff) << 8) | \ 153 (((ui16_host) & (M4OSA_UInt16) 0xff00) >> 8) ) 154 155/* to translate a 32 bits to its Big Endian value */ 156#define M4OSA_INT32_TO_BE(ui32_host) ((((ui32_host) & (M4OSA_UInt32) 0x000000ff) << 24) | \ 157 (((ui32_host) & (M4OSA_UInt32) 0x0000ff00) << 8) | \ 158 (((ui32_host) & (M4OSA_UInt32) 0x00ff0000) >> 8) | \ 159 (((ui32_host) & (M4OSA_UInt32) 0xff000000) >> 24)) 160 161/* to translate a 64 bits to its Big Endian value */ 162#define M4OSA_INT64_TO_BE(ui64_host) ((((ui64_host) & (M4OSA_UInt64) 0x00000000000000ff) << 56) | \ 163 (((ui64_host) & (M4OSA_UInt64) 0x000000000000ff00) << 40) | \ 164 (((ui64_host) & (M4OSA_UInt64) 0x0000000000ff0000) << 24) | \ 165 (((ui64_host) & (M4OSA_UInt64) 0x00000000ff000000) << 8) | \ 166 (((ui64_host) & (M4OSA_UInt64) 0x000000ff00000000) >> 8) | \ 167 (((ui64_host) & (M4OSA_UInt64) 0x0000ff0000000000) >> 24) | \ 168 (((ui64_host) & (M4OSA_UInt64) 0x00ff000000000000) >> 40) | \ 169 (((ui64_host) & (M4OSA_UInt64) 0xff00000000000000) >> 56)) 170 171/* to translate a Big Endian 16 bits to its host representation */ 172#define M4OSA_BE_TO_INT16(ui16_net) ((((ui16_net) & (M4OSA_UInt16) 0x00ff) << 8) | \ 173 (((ui16_net) & (M4OSA_UInt16) 0xff00) >> 8) ) 174 175/* to translate a Big Endian 32 bits to its host representation*/ 176#define M4OSA_BE_TO_INT32(ui32_net) ((((ui32_net) & (M4OSA_UInt32) 0x000000ff) << 24) | \ 177 (((ui32_net) & (M4OSA_UInt32) 0x0000ff00) << 8) | \ 178 (((ui32_net) & (M4OSA_UInt32) 0x00ff0000) >> 8) | \ 179 (((ui32_net) & (M4OSA_UInt32) 0xff000000) >> 24)) 180 181/* to translate a Big Endian 64 bits to its host representation */ 182#define M4OSA_BE_TO_INT64(ui64_net) ((((ui64_net) & (M4OSA_UInt64) 0x00000000000000ff) << 56) | \ 183 (((ui64_net) & (M4OSA_UInt64) 0x000000000000ff00) << 40) | \ 184 (((ui64_net) & (M4OSA_UInt64) 0x0000000000ff0000) << 24) | \ 185 (((ui64_net) & (M4OSA_UInt64) 0x00000000ff000000) << 8) | \ 186 (((ui64_net) & (M4OSA_UInt64) 0x000000ff00000000) >> 8) | \ 187 (((ui64_net) & (M4OSA_UInt64) 0x0000ff0000000000) >> 24) | \ 188 (((ui64_net) & (M4OSA_UInt64) 0x00ff000000000000) >> 40) | \ 189 (((ui64_net) & (M4OSA_UInt64) 0xff00000000000000) >> 56)) 190 191/* to translate a 16 bits to its Little Endian value*/ 192#define M4OSA_INT16_TO_LE(ui16_host) (ui16_host) 193 194/* to translate a 32 bits to its Little Endian value */ 195#define M4OSA_INT32_TO_LE(ui32_host) (ui32_host) 196 197/* to translate a 64 bits to its Little Endian value */ 198#define M4OSA_INT64_TO_LE(ui64_host) (ui64_host) 199 200/* to translate a Little Endian 16 bits to its host representation */ 201#define M4OSA_LE_TO_INT16(ui16_net) (ui16_net) 202 203/* to translate a Little Endian 32 bits to its host representation*/ 204#define M4OSA_LE_TO_INT32(ui32_net) (ui32_net) 205 206/* to translate a Little Endian 64 bits to its host representation */ 207#define M4OSA_LE_TO_INT64(ui64_net) (ui64_net) 208 209 210/* Macro to manipulate M4OSA_Int32*/ 211#define M4OSA_INT32_SET(i32_out, i32_in)\ 212 { i32_out = i32_in; } 213 214#define M4OSA_INT32_ADD(i32_result, i32_a, i32_b)\ 215 { i32_result = (i32_a) + (i32_b); } 216 217#define M4OSA_INT32_SUB(i32_result, i32_a, i32_b)\ 218 { i32_result = (i32_a) - (i32_b); } 219 220#define M4OSA_INT32_SCALAR_PRODUCT(i32_result, i32_a, i32_value)\ 221 { i32_result = (i32_a) * (i32_value); } 222 223#define M4OSA_INT32_SCALAR_DIVISION(i32_result, i32_a, i32_value)\ 224 { i32_result = (i32_a) / (i32_value); } 225 226#define M4OSA_INT32_COMPARE(i32_a, i32_b)\ 227 ( ((i32_a) == (i32_b)) ? 0 : ( ((i32_a) > (i32_b)) ? 1 : -1) ) 228 229#define M4OSA_INT32_FROM_INT32(i32_result, i32_value)\ 230 { i32_result = (M4OSA_Int32)(i32_value); } 231 232#define M4OSA_INT32_FROM_INT32_UINT32(i32_result, i32_high, ui32_low)\ 233 { i32_result = (M4OSA_Int32)(ui32_low); } 234 235#define M4OSA_INT32_GET_LOW32(i32_value) ((M4OSA_Int32)(i32_value)) 236 237#define M4OSA_INT32_GET_HIGH32(i32_value) (0) 238 239#define M4OSA_INT32_IS_POSITIVE(i32_value) ((i32_value) >= 0) 240 241#define M4OSA_INT32_NEG(i32_result, i32_value)\ 242 { i32_result = -(i32_value); } 243 244#define M4OSA_INT32_ABS(i32_result, i32_value)\ 245 { if ((i32_value) > 0) { i32_result = i32_value; }\ 246 else { i32_result = -(i32_value); } } 247 248#define M4OSA_INT32_LEFT_SHIFT(i32_result, i32_value, ui32_nbPos)\ 249 { i64_result = (((ui32_nbPos)>0x1F)?0:((i64_value)<<(ui32_nbPos))); } 250 251#define M4OSA_INT32_RIGHT_SHIFT(i32_result, i32_value, ui32_nbPos)\ 252 { i64_result = (((ui32_nbPos)>0x1F)?0:((i64_value)>>(ui32_nbPos))); } 253 254#define M4OSA_INT32_TO_DOUBLE(f_result, i32_value)\ 255 { f_result = (M4OSA_Double)(i32_value); } 256 257#define M4OSA_INT32_FROM_DOUBLE(i32_result, f_value)\ 258 { i32_result = (M4OSA_Int32)(f_value); } 259 260 261#ifdef M4OSA_64BITS_SUPPORTED 262 263/* Macro to manipulate M4OSA_Int64*/ 264#define M4OSA_INT64_SET(i64_out, i64_in) { i64_out = i64_in; } 265 266#define M4OSA_INT64_ADD(i64_result, i64_a, i64_b)\ 267 { i64_result = (i64_a) + (i64_b); } 268 269#define M4OSA_INT64_SUB(i64_result, i64_a, i64_b)\ 270 { i64_result = (i64_a) - (i64_b); } 271 272#define M4OSA_INT64_SCALAR_PRODUCT(i64_result, i64_a, i32_value)\ 273 { i64_result = (i64_a) * (i32_value); } 274 275#define M4OSA_INT64_SCALAR_DIVISION(i64_result, i64_a, i32_value)\ 276 { i64_result = (i64_a) / (i32_value); } 277 278#define M4OSA_INT64_COMPARE(i64_a, i64_b)\ 279 ( ((i64_a) == (i64_b)) ? 0 : ( ((i64_a) > (i64_b)) ? 1 : -1) )\ 280 281#define M4OSA_INT64_FROM_INT32(i64_result, i32_value)\ 282 { i64_result = (M4OSA_Int64)(i32_value); } 283 284#define M4OSA_INT64_FROM_INT32_UINT32(i64_result, i32_high, ui32_low)\ 285 { i64_result = (i32_high); i64_result = (i64_result<<32)+(ui32_low); } 286 287#define M4OSA_INT64_GET_LOW32(i64_value)\ 288 ((M4OSA_Int32)((i64_value) & 0xFFFFFFFF)) 289 290#define M4OSA_INT64_GET_HIGH32(i64_value)\ 291 ((M4OSA_Int32)(((i64_value) >> 32) & 0xFFFFFFFF)) 292 293#define M4OSA_INT64_IS_POSITIVE(i64_value) (((i64_value)>=0)?1:0) 294 295#define M4OSA_INT64_NEG(i64_result, i64_value)\ 296 { i64_result = -(i64_value); } 297 298#define M4OSA_INT64_ABS(i64_result, i64_value)\ 299 { if (M4OSA_INT64_IS_POSITIVE(i64_value)) { i64_result = i64_value; }\ 300 else { M4OSA_INT64_NEG(i64_result, i64_value); } } 301 302#define M4OSA_INT64_LEFT_SHIFT(i64_result, i64_value, ui32_nbPos)\ 303 { i64_result = (((ui32_nbPos)>0x3F)?0:((i64_value)<<(ui32_nbPos))); } 304 305#define M4OSA_INT64_RIGHT_SHIFT(i64_result, i64_value, ui32_nbPos)\ 306 { i64_result = (((ui32_nbPos)>0x3F)?0:((i64_value)>>(ui32_nbPos))); } 307 308#define M4OSA_INT64_TO_DOUBLE(f_result, i64_value)\ 309 { f_result = (M4OSA_Double)(i64_value); } 310 311#define M4OSA_INT64_FROM_DOUBLE(i64_result, f_value)\ 312 { i64_result = (M4OSA_Int64)(f_value); } 313 314#endif /*M4OSA_64BITS_SUPPORTED*/ 315 316 317#ifdef M4OSA_64BITS_NOT_SUPPORTED 318 319#define M4OSA_INT64_SET(i64_out, i64_in)\ 320 M4OSA_INT32_SET(i64_out, i64_in) 321 322#define M4OSA_INT64_ADD(i64_result, i64_a, i64_b)\ 323 M4OSA_INT32_ADD(i64_result, i64_a, i64_b) 324 325#define M4OSA_INT64_SUB(i64_result, i64_a, i64_b)\ 326 M4OSA_INT32_SUB(i64_result, i64_a, i64_b) 327 328#define M4OSA_INT64_SCALAR_PRODUCT(i64_result, i64_a, i32_value)\ 329 M4OSA_INT32_SCALAR_PRODUCT(i64_result, i64_a, i32_value) 330 331#define M4OSA_INT64_SCALAR_DIVISION(i64_result, i64_a, i32_value)\ 332 M4OSA_INT32_SCALAR_DIVISION(i64_result, i64_a, i32_value) 333 334#define M4OSA_INT64_COMPARE(i64_a, i64_b)\ 335 M4OSA_INT32_COMPARE(i64_a, i64_b) 336 337#define M4OSA_INT64_FROM_INT32(i64_result, i32_value)\ 338 M4OSA_INT32_FROM_INT32(i64_result, i32_value) 339 340#define M4OSA_INT64_FROM_INT32_UINT32(i64_result, i32_high, ui32_low)\ 341 M4OSA_INT32_FROM_INT32_UINT32(i64_result, i32_high, ui32_low) 342 343#define M4OSA_INT64_GET_LOW32(i64_value)\ 344 M4OSA_INT32_GET_LOW32(i64_value) 345 346#define M4OSA_INT64_GET_HIGH32(i64_value)\ 347 M4OSA_INT32_GET_HIGH32(i64_value) 348 349#define M4OSA_INT64_IS_POSITIVE(i64_value)\ 350 M4OSA_INT32_IS_POSITIVE(i64_value) 351 352#define M4OSA_INT64_NEG(i64_result, i64_value)\ 353 M4OSA_INT32_NEG(i64_result, i64_value) 354 355#define M4OSA_INT64_ABS(i64_result, i64_value)\ 356 M4OSA_INT32_ABS(i64_result, i64_value) 357 358#define M4OSA_INT64_LEFT_SHIFT(i64_result, i64_value, ui32_nbPositions)\ 359 M4OSA_INT32_LEFT_SHIFT(i64_result, i64_value, ui32_nbPositions) 360 361#define M4OSA_INT64_RIGHT_SHIFT(i64_result, i64_value, ui32_nbPositions)\ 362 M4OSA_INT32_RIGHT_SHIFT(i64_result, i64_value, ui32_nbPositions) 363 364#define M4OSA_INT64_TO_DOUBLE(f_result, i64_value)\ 365 M4OSA_INT32_TO_DOUBLE(f_result, i64_value) 366 367#define M4OSA_INT64_FROM_DOUBLE(i64_result, f_value)\ 368 M4OSA_INT32_FROM_DOUBLE(i64_result, f_value) 369 370#endif /*M4OSA_64BITS_NOT_SUPPORTED*/ 371 372 373#ifdef __cplusplus 374} 375#endif 376 377#endif /*M4OSA_TYPES_H*/ 378 379