diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
commit | fcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch) | |
tree | a57612d1888735a2ec7972891b68c1ac5ec8faea /drivers/misc/mpu3050/log.h | |
parent | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff) |
Diffstat (limited to 'drivers/misc/mpu3050/log.h')
-rw-r--r-- | drivers/misc/mpu3050/log.h | 306 |
1 files changed, 306 insertions, 0 deletions
diff --git a/drivers/misc/mpu3050/log.h b/drivers/misc/mpu3050/log.h new file mode 100644 index 00000000000..f2f9ea7ece8 --- /dev/null +++ b/drivers/misc/mpu3050/log.h | |||
@@ -0,0 +1,306 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2010 InvenSense Inc | ||
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 | /* | ||
18 | * C/C++ logging functions. See the logging documentation for API details. | ||
19 | * | ||
20 | * We'd like these to be available from C code (in case we import some from | ||
21 | * somewhere), so this has a C interface. | ||
22 | * | ||
23 | * The output will be correct when the log file is shared between multiple | ||
24 | * threads and/or multiple processes so long as the operating system | ||
25 | * supports O_APPEND. These calls have mutex-protected data structures | ||
26 | * and so are NOT reentrant. Do not use MPL_LOG in a signal handler. | ||
27 | */ | ||
28 | #ifndef _LIBS_CUTILS_MPL_LOG_H | ||
29 | #define _LIBS_CUTILS_MPL_LOG_H | ||
30 | |||
31 | #include <stdarg.h> | ||
32 | |||
33 | #ifdef ANDROID | ||
34 | #include <utils/Log.h> /* For the LOG macro */ | ||
35 | #endif | ||
36 | |||
37 | #ifdef __KERNEL__ | ||
38 | #include <linux/kernel.h> | ||
39 | #endif | ||
40 | |||
41 | #ifdef __cplusplus | ||
42 | extern "C" { | ||
43 | #endif | ||
44 | |||
45 | /* --------------------------------------------------------------------- */ | ||
46 | |||
47 | /* | ||
48 | * Normally we strip MPL_LOGV (VERBOSE messages) from release builds. | ||
49 | * You can modify this (for example with "#define MPL_LOG_NDEBUG 0" | ||
50 | * at the top of your source file) to change that behavior. | ||
51 | */ | ||
52 | #ifndef MPL_LOG_NDEBUG | ||
53 | #ifdef NDEBUG | ||
54 | #define MPL_LOG_NDEBUG 1 | ||
55 | #else | ||
56 | #define MPL_LOG_NDEBUG 0 | ||
57 | #endif | ||
58 | #endif | ||
59 | |||
60 | #ifdef __KERNEL__ | ||
61 | #define MPL_LOG_UNKNOWN MPL_LOG_VERBOSE | ||
62 | #define MPL_LOG_DEFAULT KERN_DEFAULT | ||
63 | #define MPL_LOG_VERBOSE KERN_CONT | ||
64 | #define MPL_LOG_DEBUG KERN_NOTICE | ||
65 | #define MPL_LOG_INFO KERN_INFO | ||
66 | #define MPL_LOG_WARN KERN_WARNING | ||
67 | #define MPL_LOG_ERROR KERN_ERR | ||
68 | #define MPL_LOG_SILENT MPL_LOG_VERBOSE | ||
69 | |||
70 | #else | ||
71 | /* Based off the log priorities in android | ||
72 | /system/core/include/android/log.h */ | ||
73 | #define MPL_LOG_UNKNOWN (0) | ||
74 | #define MPL_LOG_DEFAULT (1) | ||
75 | #define MPL_LOG_VERBOSE (2) | ||
76 | #define MPL_LOG_DEBUG (3) | ||
77 | #define MPL_LOG_INFO (4) | ||
78 | #define MPL_LOG_WARN (5) | ||
79 | #define MPL_LOG_ERROR (6) | ||
80 | #define MPL_LOG_SILENT (8) | ||
81 | #endif | ||
82 | |||
83 | |||
84 | /* | ||
85 | * This is the local tag used for the following simplified | ||
86 | * logging macros. You can change this preprocessor definition | ||
87 | * before using the other macros to change the tag. | ||
88 | */ | ||
89 | #ifndef MPL_LOG_TAG | ||
90 | #ifdef __KERNEL__ | ||
91 | #define MPL_LOG_TAG | ||
92 | #else | ||
93 | #define MPL_LOG_TAG NULL | ||
94 | #endif | ||
95 | #endif | ||
96 | |||
97 | /* --------------------------------------------------------------------- */ | ||
98 | |||
99 | /* | ||
100 | * Simplified macro to send a verbose log message using the current MPL_LOG_TAG. | ||
101 | */ | ||
102 | #ifndef MPL_LOGV | ||
103 | #if MPL_LOG_NDEBUG | ||
104 | #define MPL_LOGV(fmt, ...) \ | ||
105 | do { \ | ||
106 | if (0) \ | ||
107 | MPL_LOG(LOG_VERBOSE, MPL_LOG_TAG, fmt, ##__VA_ARGS__);\ | ||
108 | } while (0) | ||
109 | #else | ||
110 | #define MPL_LOGV(fmt, ...) MPL_LOG(LOG_VERBOSE, MPL_LOG_TAG, fmt, ##__VA_ARGS__) | ||
111 | #endif | ||
112 | #endif | ||
113 | |||
114 | #ifndef CONDITION | ||
115 | #define CONDITION(cond) ((cond) != 0) | ||
116 | #endif | ||
117 | |||
118 | #ifndef MPL_LOGV_IF | ||
119 | #if MPL_LOG_NDEBUG | ||
120 | #define MPL_LOGV_IF(cond, fmt, ...) \ | ||
121 | do { if (0) MPL_LOG(fmt, ##__VA_ARGS__); } while (0) | ||
122 | #else | ||
123 | #define MPL_LOGV_IF(cond, fmt, ...) \ | ||
124 | ((CONDITION(cond)) \ | ||
125 | ? MPL_LOG(LOG_VERBOSE, MPL_LOG_TAG, fmt, ##__VA_ARGS__) \ | ||
126 | : (void)0) | ||
127 | #endif | ||
128 | #endif | ||
129 | |||
130 | /* | ||
131 | * Simplified macro to send a debug log message using the current MPL_LOG_TAG. | ||
132 | */ | ||
133 | #ifndef MPL_LOGD | ||
134 | #define MPL_LOGD(fmt, ...) MPL_LOG(LOG_DEBUG, MPL_LOG_TAG, fmt, ##__VA_ARGS__) | ||
135 | #endif | ||
136 | |||
137 | #ifndef MPL_LOGD_IF | ||
138 | #define MPL_LOGD_IF(cond, fmt, ...) \ | ||
139 | ((CONDITION(cond)) \ | ||
140 | ? MPL_LOG(LOG_DEBUG, MPL_LOG_TAG, fmt, ##__VA_ARGS__) \ | ||
141 | : (void)0) | ||
142 | #endif | ||
143 | |||
144 | /* | ||
145 | * Simplified macro to send an info log message using the current MPL_LOG_TAG. | ||
146 | */ | ||
147 | #ifndef MPL_LOGI | ||
148 | #define MPL_LOGI(fmt, ...) MPL_LOG(LOG_INFO, MPL_LOG_TAG, fmt, ##__VA_ARGS__) | ||
149 | #endif | ||
150 | |||
151 | #ifndef MPL_LOGI_IF | ||
152 | #define MPL_LOGI_IF(cond, fmt, ...) \ | ||
153 | ((CONDITION(cond)) \ | ||
154 | ? MPL_LOG(LOG_INFO, MPL_LOG_TAG, fmt, ##__VA_ARGS__) \ | ||
155 | : (void)0) | ||
156 | #endif | ||
157 | |||
158 | /* | ||
159 | * Simplified macro to send a warning log message using the current MPL_LOG_TAG. | ||
160 | */ | ||
161 | #ifndef MPL_LOGW | ||
162 | #ifdef __KERNEL__ | ||
163 | #define MPL_LOGW(fmt, ...) printk(KERN_WARNING MPL_LOG_TAG fmt, ##__VA_ARGS__) | ||
164 | #else | ||
165 | #define MPL_LOGW(fmt, ...) MPL_LOG(LOG_WARN, MPL_LOG_TAG, fmt, ##__VA_ARGS__) | ||
166 | #endif | ||
167 | #endif | ||
168 | |||
169 | #ifndef MPL_LOGW_IF | ||
170 | #define MPL_LOGW_IF(cond, fmt, ...) \ | ||
171 | ((CONDITION(cond)) \ | ||
172 | ? MPL_LOG(LOG_WARN, MPL_LOG_TAG, fmt, ##__VA_ARGS__) \ | ||
173 | : (void)0) | ||
174 | #endif | ||
175 | |||
176 | /* | ||
177 | * Simplified macro to send an error log message using the current MPL_LOG_TAG. | ||
178 | */ | ||
179 | #ifndef MPL_LOGE | ||
180 | #ifdef __KERNEL__ | ||
181 | #define MPL_LOGE(fmt, ...) printk(KERN_ERR MPL_LOG_TAG fmt, ##__VA_ARGS__) | ||
182 | #else | ||
183 | #define MPL_LOGE(fmt, ...) MPL_LOG(LOG_ERROR, MPL_LOG_TAG, fmt, ##__VA_ARGS__) | ||
184 | #endif | ||
185 | #endif | ||
186 | |||
187 | #ifndef MPL_LOGE_IF | ||
188 | #define MPL_LOGE_IF(cond, fmt, ...) \ | ||
189 | ((CONDITION(cond)) \ | ||
190 | ? MPL_LOG(LOG_ERROR, MPL_LOG_TAG, fmt, ##__VA_ARGS__) \ | ||
191 | : (void)0) | ||
192 | #endif | ||
193 | |||
194 | /* --------------------------------------------------------------------- */ | ||
195 | |||
196 | /* | ||
197 | * Log a fatal error. If the given condition fails, this stops program | ||
198 | * execution like a normal assertion, but also generating the given message. | ||
199 | * It is NOT stripped from release builds. Note that the condition test | ||
200 | * is -inverted- from the normal assert() semantics. | ||
201 | */ | ||
202 | #define MPL_LOG_ALWAYS_FATAL_IF(cond, fmt, ...) \ | ||
203 | ((CONDITION(cond)) \ | ||
204 | ? ((void)android_printAssert(#cond, MPL_LOG_TAG, \ | ||
205 | fmt, ##__VA_ARGS__)) \ | ||
206 | : (void)0) | ||
207 | |||
208 | #define MPL_LOG_ALWAYS_FATAL(fmt, ...) \ | ||
209 | (((void)android_printAssert(NULL, MPL_LOG_TAG, fmt, ##__VA_ARGS__))) | ||
210 | |||
211 | /* | ||
212 | * Versions of MPL_LOG_ALWAYS_FATAL_IF and MPL_LOG_ALWAYS_FATAL that | ||
213 | * are stripped out of release builds. | ||
214 | */ | ||
215 | #if MPL_LOG_NDEBUG | ||
216 | #define MPL_LOG_FATAL_IF(cond, fmt, ...) \ | ||
217 | do { \ | ||
218 | if (0) \ | ||
219 | MPL_LOG_ALWAYS_FATAL_IF(cond, fmt, ##__VA_ARGS__); \ | ||
220 | } while (0) | ||
221 | #define MPL_LOG_FATAL(fmt, ...) \ | ||
222 | do { \ | ||
223 | if (0) \ | ||
224 | MPL_LOG_ALWAYS_FATAL(fmt, ##__VA_ARGS__) \ | ||
225 | } while (0) | ||
226 | #else | ||
227 | #define MPL_LOG_FATAL_IF(cond, fmt, ...) \ | ||
228 | MPL_LOG_ALWAYS_FATAL_IF(cond, fmt, ##__VA_ARGS__) | ||
229 | #define MPL_LOG_FATAL(fmt, ...) \ | ||
230 | MPL_LOG_ALWAYS_FATAL(fmt, ##__VA_ARGS__) | ||
231 | #endif | ||
232 | |||
233 | /* | ||
234 | * Assertion that generates a log message when the assertion fails. | ||
235 | * Stripped out of release builds. Uses the current MPL_LOG_TAG. | ||
236 | */ | ||
237 | #define MPL_LOG_ASSERT(cond, fmt, ...) \ | ||
238 | MPL_LOG_FATAL_IF(!(cond), fmt, ##__VA_ARGS__) | ||
239 | |||
240 | /* --------------------------------------------------------------------- */ | ||
241 | |||
242 | /* | ||
243 | * Basic log message macro. | ||
244 | * | ||
245 | * Example: | ||
246 | * MPL_LOG(MPL_LOG_WARN, NULL, "Failed with error %d", errno); | ||
247 | * | ||
248 | * The second argument may be NULL or "" to indicate the "global" tag. | ||
249 | */ | ||
250 | #ifndef MPL_LOG | ||
251 | #define MPL_LOG(priority, tag, fmt, ...) \ | ||
252 | MPL_LOG_PRI(priority, tag, fmt, ##__VA_ARGS__) | ||
253 | #endif | ||
254 | |||
255 | /* | ||
256 | * Log macro that allows you to specify a number for the priority. | ||
257 | */ | ||
258 | #ifndef MPL_LOG_PRI | ||
259 | #ifdef ANDROID | ||
260 | #define MPL_LOG_PRI(priority, tag, fmt, ...) \ | ||
261 | LOG(priority, tag, fmt, ##__VA_ARGS__) | ||
262 | #elif defined __KERNEL__ | ||
263 | #define MPL_LOG_PRI(priority, tag, fmt, ...) \ | ||
264 | pr_debug(MPL_##priority tag fmt, ##__VA_ARGS__) | ||
265 | #else | ||
266 | #define MPL_LOG_PRI(priority, tag, fmt, ...) \ | ||
267 | _MLPrintLog(MPL_##priority, tag, fmt, ##__VA_ARGS__) | ||
268 | #endif | ||
269 | #endif | ||
270 | |||
271 | /* | ||
272 | * Log macro that allows you to pass in a varargs ("args" is a va_list). | ||
273 | */ | ||
274 | #ifndef MPL_LOG_PRI_VA | ||
275 | #ifdef ANDROID | ||
276 | #define MPL_LOG_PRI_VA(priority, tag, fmt, args) \ | ||
277 | android_vprintLog(priority, NULL, tag, fmt, args) | ||
278 | #elif defined __KERNEL__ | ||
279 | /* not allowed in the Kernel because there is no dev_dbg that takes a va_list */ | ||
280 | #else | ||
281 | #define MPL_LOG_PRI_VA(priority, tag, fmt, args) \ | ||
282 | _MLPrintVaLog(priority, NULL, tag, fmt, args) | ||
283 | #endif | ||
284 | #endif | ||
285 | |||
286 | /* --------------------------------------------------------------------- */ | ||
287 | |||
288 | /* | ||
289 | * =========================================================================== | ||
290 | * | ||
291 | * The stuff in the rest of this file should not be used directly. | ||
292 | */ | ||
293 | |||
294 | #ifndef ANDROID | ||
295 | int _MLPrintLog(int priority, const char *tag, const char *fmt, | ||
296 | ...); | ||
297 | int _MLPrintVaLog(int priority, const char *tag, const char *fmt, | ||
298 | va_list args); | ||
299 | /* Final implementation of actual writing to a character device */ | ||
300 | int _MLWriteLog(const char *buf, int buflen); | ||
301 | #endif | ||
302 | |||
303 | #ifdef __cplusplus | ||
304 | } | ||
305 | #endif | ||
306 | #endif /* _LIBS_CUTILS_MPL_LOG_H */ | ||