1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 // This file contains helper macros and definitions. 18 19 #ifndef LOCATION_LBS_CONTEXTHUB_NANOAPPS_COMMON_MATH_MACROS_H_ 20 #define LOCATION_LBS_CONTEXTHUB_NANOAPPS_COMMON_MATH_MACROS_H_ 21 22 // Mathematical constants. 23 #define NANO_PI (3.14159265359f) 24 25 // Common math operations. 26 #define NANO_ABS(x) ((x) > 0 ? (x) : -(x)) 27 #define NANO_MAX(a, b) ((a) > (b)) ? (a) : (b) 28 #define NANO_MIN(a, b) ((a) < (b)) ? (a) : (b) 29 30 // Timestamp conversion macros. 31 #ifdef __cplusplus 32 #define MSEC_TO_NANOS(x) (static_cast<uint64_t>(x) * 1000000) 33 #else 34 #define MSEC_TO_NANOS(x) ((uint64_t)(x) * 1000000) // NOLINT 35 #endif 36 37 #define SEC_TO_NANOS(x) MSEC_TO_NANOS(x * 1000) 38 #define MIN_TO_NANOS(x) SEC_TO_NANOS(x * 60) 39 #define HRS_TO_NANOS(x) MIN_TO_NANOS(x * 60) 40 #define DAYS_TO_NANOS(x) HRS_TO_NANOS(x * 24) 41 42 // Unit conversion: nanoseconds to seconds. 43 #define NANOS_TO_SEC (1.0e-9f) 44 45 // Unit conversion: milli-degrees to radians. 46 #define MDEG_TO_RAD (NANO_PI / 180.0e3f) 47 48 // Unit conversion: radians to milli-degrees. 49 #define RAD_TO_MDEG (180.0e3f / NANO_PI) 50 51 // Time check helper macro that returns true if: 52 // i. 't1' is equal to or exceeds 't2' plus 't_delta'. 53 // ii. Or, a negative timestamp delta occurred since, 54 // 't1' should always >= 't2'. This prevents potential lockout conditions 55 // if the timer count 't1' rolls over or an erroneously large 56 // timestamp is passed through. 57 #define NANO_TIMER_CHECK_T1_GEQUAL_T2_PLUS_DELTA(t1, t2, t_delta) \ 58 (((t1) >= (t2) + (t_delta)) || ((t1) < (t2))) 59 60 #endif // LOCATION_LBS_CONTEXTHUB_NANOAPPS_COMMON_MATH_MACROS_H_ 61