1 /* 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * Description: his should be #included by every C source file 15 */ 16 17 #ifndef STD_DEF_H 18 #define STD_DEF_H 19 20 /** 21 * @defgroup connectivity_libs_common_types COMMON Types 22 * @ingroup connectivity_libs_common 23 * @{ 24 */ 25 #include <stddef.h> 26 #include <stdbool.h> 27 #include "stdint.h" 28 #ifdef __LITEOS__ 29 #include "los_typedef.h" 30 #endif 31 #include "product.h" 32 33 #ifndef var_segment 34 #if (defined __GNUC__) || (defined __ICCARM__) 35 #define var_segment(seg) __attribute__((section(seg))) 36 #else 37 #if (defined PC_ST) 38 #define var_segment(seg) 39 #else 40 #error "You need to define var_segment for your compiler." 41 #endif // (defined PC_ST) 42 #endif // (defined __GNUC__ ) 43 #endif // var_segment 44 45 #ifndef UNUSED 46 #define UNUSED(var) do { (void)(var); } while (0) 47 #endif 48 49 #ifndef MAX 50 #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 51 #endif 52 53 #ifndef MIN 54 #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 55 #endif 56 57 /** A compile time assertion check. 58 * 59 * Validate at compile time that the predicate is true without 60 * generating code. This can be used at any point in a source file 61 * where typedef is legal. 62 * 63 * On success, compilation proceeds normally. 64 * 65 * On failure, attempts to typedef an array type of negative size. The 66 * offending line will look like 67 * typedef assertion_failed_file_h_42[-1] 68 * where file is the content of the second parameter which should 69 * typically be related in some obvious way to the containing file 70 * name, 42 is the line number in the file on which the assertion 71 * appears, and -1 is the result of a calculation based on the 72 * predicate failing. 73 * 74 * \param predicate The predicate to test. It must evaluate to 75 * something that can be coerced to a normal C boolean. 76 * 77 * \param file A sequence of legal identifier characters that should 78 * uniquely identify the source file in which this condition appears. 79 */ 80 #define cassert(predicate, file) impl_cassert_line(predicate, __LINE__, file) 81 82 #define impl_paste(a, b) a##b 83 #define impl_cassert_line(predicate, line, file) \ 84 typedef char impl_paste(assertion_failed_##file##_, line)[2 * !!(predicate) - 1] 85 86 #ifndef BIT 87 #define BIT(x) (1UL << (uint32_t)(x)) 88 #endif 89 90 // Macro to check at compile time certain expressions not supported by the preprocessor 91 #define ct_assert(e) enum LENGTH_CHECK { ct_assert_value = 1 / ((!(!(e)))) } 92 93 #define __IRQ 94 #define __ISR __IRQ 95 96 enum ERROR_CODE_ENUM { 97 ERR = -1, 98 SUCC = 0 99 }; 100 101 /** 102 * @} 103 */ 104 #endif 105