1 | /* |
2 | Copyright (c) 2012, Broadcom Europe Ltd |
3 | All rights reserved. |
4 | |
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the following conditions are met: |
7 | * Redistributions of source code must retain the above copyright |
8 | notice, this list of conditions and the following disclaimer. |
9 | * Redistributions in binary form must reproduce the above copyright |
10 | notice, this list of conditions and the following disclaimer in the |
11 | documentation and/or other materials provided with the distribution. |
12 | * Neither the name of the copyright holder nor the |
13 | names of its contributors may be used to endorse or promote products |
14 | derived from this software without specific prior written permission. |
15 | |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ |
27 | |
28 | #ifndef __VC_INCLUDE_COMMON_H__ |
29 | #define __VC_INCLUDE_COMMON_H__ |
30 | |
31 | #include "interface/vcos/vcos_stdint.h" |
32 | #include "interface/vctypes/vc_image_types.h" |
33 | |
34 | #if defined(__HIGHC__) && defined(_VIDEOCORE) && !defined(_I386) |
35 | // __HIGHC__ is only available with MW |
36 | // The scvc plugins are compiled (bizarrely) on an x86 with _VIDEOCORE set! |
37 | #include <vc/intrinsics.h> |
38 | #endif |
39 | |
40 | #ifdef __COVERITY__ |
41 | #ifndef _Rarely |
42 | #define _Rarely(x) (x) |
43 | #endif |
44 | #ifndef _Usually |
45 | #define _Usually(x) (x) |
46 | #endif |
47 | #endif |
48 | |
49 | #ifdef __cplusplus |
50 | extern "C" { |
51 | #endif |
52 | |
53 | #ifdef __SYMBIAN32__ |
54 | # ifndef INLINE |
55 | # define INLINE __inline |
56 | # endif |
57 | |
58 | /* Align a pointer/integer by rounding up/down */ |
59 | #define ALIGN_DOWN(p, n) ((uint32_t)(p) - ( (uint32_t)(p) % (uint32_t)(n) )) |
60 | #define ALIGN_UP(p, n) ALIGN_DOWN((uint32_t)(p) + (uint32_t)(n) - 1, (n)) |
61 | |
62 | #elif defined (VCMODS_LCC) |
63 | #include <limits.h> |
64 | |
65 | |
66 | #elif !defined(__KERNEL__) |
67 | #include <limits.h> |
68 | |
69 | #endif |
70 | |
71 | |
72 | /*}}}*/ |
73 | |
74 | /* Fixed-point types */ |
75 | typedef unsigned short uint8p8_t; |
76 | typedef signed short sint8p8_t; |
77 | typedef unsigned short uint4p12_t; |
78 | typedef signed short sint4p12_t; |
79 | typedef signed short sint0p16_t; |
80 | typedef signed char sint8p0_t; |
81 | typedef unsigned char uint0p8_t; |
82 | typedef signed long int24p8_t; |
83 | |
84 | /*{{{ Common typedefs */ |
85 | |
86 | typedef enum bool_e |
87 | { |
88 | VC_FALSE = 0, |
89 | VC_TRUE = 1, |
90 | } VC_BOOL_T; |
91 | |
92 | #ifndef bool_t |
93 | #define bool_t VC_BOOL_T |
94 | #endif |
95 | |
96 | /*}}}*/ |
97 | |
98 | /*{{{ Common macros */ |
99 | |
100 | |
101 | /* Align a pointer/integer by rounding up/down */ |
102 | #define ALIGN_DOWN(p, n) ((uintptr_t)(p) - ( (uintptr_t)(p) % (uintptr_t)(n) )) |
103 | #define ALIGN_UP(p, n) ALIGN_DOWN((uintptr_t)(p) + (uintptr_t)(n) - 1, (n)) |
104 | |
105 | #define CLIP(lower, n, upper) _min((upper), _max((lower), (n))) |
106 | |
107 | /*}}}*/ |
108 | |
109 | /*{{{ Debugging and profiling macros */ |
110 | |
111 | #if 0 |
112 | /* There's already an assert_once in <logging/logging.h> */ |
113 | #ifdef DEBUG |
114 | #define assert_once(x) \ |
115 | { \ |
116 | static uint8_t ignore = 0; \ |
117 | if(!ignore) \ |
118 | { \ |
119 | assert(x); \ |
120 | ignore++; \ |
121 | } \ |
122 | } |
123 | #else |
124 | #define assert_once(x) (void)0 |
125 | #endif |
126 | #endif /* 0 */ |
127 | |
128 | #if defined(__HIGHC__) && !defined(NDEBUG) |
129 | /* HighC lacks a __FUNCTION__ preproc symbol... :( */ |
130 | #define profile_rename(name) _ASM(".global " name "\n" name ":\n") |
131 | #else |
132 | #define profile_rename(name) (void)0 |
133 | #endif |
134 | |
135 | /*}}}*/ |
136 | #ifdef __cplusplus |
137 | } |
138 | #endif |
139 | #endif /* __VCINCLUDE_COMMON_H__ */ |
140 | |
141 | |