• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
15 
16 #ifndef _HI_BOOT_TYPES_H_
17 #define _HI_BOOT_TYPES_H_
18 
19 /* Basic data type definition */
20 typedef unsigned char           hi_uchar;
21 typedef unsigned char           hi_u8;
22 typedef unsigned short          hi_u16;
23 typedef unsigned int            hi_u32;
24 typedef unsigned long long      hi_u64;
25 typedef unsigned long           hi_ulong;
26 typedef char                    hi_char;
27 typedef signed char             hi_s8;
28 typedef short                   hi_s16;
29 typedef int                     hi_s32;
30 typedef long long               hi_s64;
31 typedef long                    hi_slong;
32 typedef float                   hi_float;
33 typedef double                  hi_double;
34 typedef unsigned long           hi_size_t;
35 typedef unsigned long           hi_length_t;
36 typedef hi_u32                  hi_handle;
37 typedef hi_u8                   hi_bool;
38 typedef unsigned int            uintptr_t;
39 typedef void                    hi_void;
40 typedef void*                   hi_pvoid;
41 
42 typedef hi_u8                   hi_byte;
43 typedef hi_byte*                hi_pbyte;
44 typedef hi_u32                  size_t;
45 typedef unsigned long long      uint64_t;
46 
47 typedef hi_void  (*hi_void_callback_f)(hi_void);
48 
49 #define HI_PRV    static
50 #define HI_PRVL   static inline
51 #define HI_INLINE inline
52 #define HI_EXTERN extern
53 #define HI_CONST  const
54 #define HI_ALWAYS_INLINE __attribute__((always_inline)) inline
55 
56 #define HI_OUT
57 #define HI_IN
58 #define HI_INOUT
59 
60 #define HI_FALSE 0
61 #define HI_TRUE  1
62 
63 
64 #ifdef __cplusplus
65 #define HI_NULL 0
66 #else
67 #define HI_NULL ((void*)0)
68 #endif
69 
70 #ifndef NULL
71 #define NULL (void*)0
72 #endif
73 
74 #define SZ_1KB 1024
75 #define SZ_1MB (SZ_1KB * SZ_1KB)
76 #define SZ_4KB 4096
77 
78 #define hi_array_count(x) (sizeof(x) / sizeof((x)[0]))
79 
80 #define hi_align_4(x)        ((unsigned int)((x) + 0x3) & (~0x3))
81 #define hi_is_align_u32(x)   (!((x) & 3))
82 #define hi_is_unalign_u32(x) ((x) & 3)
83 #if defined(HAVE_PCLINT_CHECK)
84 #define hi_fieldoffset(s, m) (0)
85 #else
86 #define hi_fieldoffset(s, m) ((hi_u32) & (((s*)0)->m))
87 #endif
88 #define HI_CHAR_CR '\r' /* 0x0D */
89 #define HI_CHAR_LF '\n' /* 0x0A */
90 
91 #define hi_makeu16(a, b) ((hi_u16)(((hi_u8)(a)) | ((hi_u16)((hi_u8)(b))) << 8))
92 #define hi_makeu32(a, b) ((hi_u32)(((hi_u16)(a)) | ((hi_u32)((hi_u16)(b))) << 16))
93 #define hi_hiu16(l)      ((hi_u16)(((hi_u32)(l) >> 16) & 0xFFFF))
94 #define hi_lou16(l)      ((hi_u16)(l))
95 #define hi_hiu8(l)       ((hi_u8)(((hi_u16)(l) >> 8) & 0xFF))
96 #define hi_lou8(l)       ((hi_u8)(l))
97 
98 #define hi_max(a, b) (((a) > (b)) ? (a) : (b))
99 #define hi_min(a, b) (((a) < (b)) ? (a) : (b))
100 
101 #define hi_set_bit_i(val, n)                          ((val) |= (1 << (n)))
102 #define hi_clr_bit_i(val, n)                          ((val) &= ~(1 << (n)))
103 #define hi_is_bit_set_i(val, n)                       ((val) & (1 << (n)))
104 #define hi_is_bit_clr_i(val, n)                       (~((val) & (1 << (n))))
105 #define hi_switch_bit_i(val, n)                       ((val) ^= (1 << (n)))
106 #define hi_get_bit_i(val, n)                          (((val) >> (n)) & 1)
107 #define hi_u8_bit_val(b7, b6, b5, b4, b3, b2, b1, b0) \
108     (((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | ((b0) << 0))
109 
110 #define hi_u16_bit_val(b12, b11, b10, b9, b8, b7, b6, b5, b4, b3, b2, b1, b0) \
111     (hi_u16)(((b12) << 12) | ((b11) << 11) | ((b10) << 10) | ((b9) << 9) | ((b8) << 8) | ((b7) << 7) | \
112     ((b6) << 6) | ((b5) << 5) | ((b4) << 4) | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | ((b0) << 0))
113 
114 #define ALIGNTYPE_1BYTE             1
115 #define ALIGNTYPE_2BYTE             2
116 #define ALIGNTYPE_4BYTE             4
117 #define ALIGNTYPE_8BYTE             8
118 #define ALIGNTYPE_64BYTE            64
119 #define ALIGNTYPE_32BYTE            32
120 #define ALIGNTYPE_4K                4096
121 #define align_next(val, a)          ((((val) + ((a)-1)) & (~((a)-1))))
122 #define align_length(val, a)        align_next(val, a)
123 #define HI_ALL_F_32                 0xFFFFFFFF
124 #define HI_ALL_F_16                 0xFFFF
125 
126 #define BYTE_WIDTH                  1
127 #define HALF_WIDTH                  2
128 #define WORD_WIDTH                  4
129 
130 #define BITS_PER_BYTE               8
131 #define HEXADECIMAL                 16
132 #define DECIMAL                     10
133 
134 #define HALFWORD_BIT_WIDTH          16
135 
136 #if !defined(hi_unref_param) && !defined(HI_HAVE_CROSS_COMPILER_DIAB)
137 #define hi_unref_param(P)  P = P
138 #else
139 #define hi_unref_param(P)
140 #endif
141 
142 #ifndef __ROM_ADDITION
143 #define __ROM_ADDITION __attribute__((section(".rom_addition.text")))
144 #endif
145 
146 #endif
147