1 /****************************************************************************** 2 * $Id: AKFS_Common.h 580 2012-03-29 09:56:21Z yamada.rj $ 3 ****************************************************************************** 4 * 5 * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 #ifndef AKFS_INC_COMMON_H 20 #define AKFS_INC_COMMON_H 21 22 #ifdef WIN32 23 #ifndef _WIN32_WINNT 24 #define _WIN32_WINNT 0x0501 25 #endif 26 27 #include <windows.h> 28 #include <stdio.h> 29 #include <stdlib.h> 30 #include <conio.h> 31 #include <stdarg.h> 32 #include <crtdbg.h> 33 #include "Android.h" 34 35 #define DBG_LEVEL DBG_LEVEL4 36 #define ENABLE_AKMDEBUG 1 37 38 #else 39 #include <stdio.h> /* frpintf */ 40 #include <stdlib.h> /* atoi */ 41 #include <string.h> /* memset */ 42 #include <unistd.h> 43 #include <stdarg.h> /* va_list */ 44 #include <utils/Log.h> /* LOGV */ 45 #include <errno.h> /* errno */ 46 47 #endif 48 49 /*** Constant definition ******************************************************/ 50 #define AKM_TRUE 1 /*!< Represents true */ 51 #define AKM_FALSE 0 /*!< Represents false */ 52 #define AKM_SUCCESS 1 /*!< Represents success */ 53 #define AKM_FAIL 0 /*!< Represents fail */ 54 55 #undef LOG_TAG 56 #define LOG_TAG "AKMD_FS" 57 58 #define DBG_LEVEL0 0 /* Critical */ 59 #define DBG_LEVEL1 1 /* Notice */ 60 #define DBG_LEVEL2 2 /* Information */ 61 #define DBG_LEVEL3 3 /* Debug */ 62 #define DBG_LEVEL4 4 /* Verbose */ 63 64 #ifndef DBG_LEVEL 65 #define DBG_LEVEL DBG_LEVEL0 66 #endif 67 68 #define DATA_AREA01 0x0001 69 #define DATA_AREA02 0x0002 70 #define DATA_AREA03 0x0004 71 #define DATA_AREA04 0x0008 72 #define DATA_AREA05 0x0010 73 #define DATA_AREA06 0x0020 74 #define DATA_AREA07 0x0040 75 #define DATA_AREA08 0x0080 76 #define DATA_AREA09 0x0100 77 #define DATA_AREA10 0x0200 78 #define DATA_AREA11 0x0400 79 #define DATA_AREA12 0x0800 80 #define DATA_AREA13 0x1000 81 #define DATA_AREA14 0x2000 82 #define DATA_AREA15 0x4000 83 #define DATA_AREA16 0x8000 84 85 86 /* Debug area definition */ 87 #define AKMDATA_DUMP DATA_AREA01 /*<! Dump data */ 88 #define AKMDATA_BDATA DATA_AREA02 /*<! BDATA */ 89 #define AKMDATA_MAG DATA_AREA03 /*<! Magnetic Field */ 90 #define AKMDATA_ACC DATA_AREA04 /*<! Accelerometer */ 91 #define AKMDATA_ORI DATA_AREA05 /*<! Orientation */ 92 #define AKMDATA_GETINTERVAL DATA_AREA06 93 #define AKMDATA_LOOP DATA_AREA07 94 #define AKMDATA_DRV DATA_AREA08 95 96 #ifndef ENABLE_AKMDEBUG 97 #define ENABLE_AKMDEBUG 0 /* Eanble debug output when it is 1. */ 98 #endif 99 100 #define OPMODE_CONSOLE 0x01 101 #define OPMODE_FST 0x02 102 103 /***** Debug Level Output *************************************/ 104 #if ENABLE_AKMDEBUG 105 #define AKMDEBUG(level, format, ...) \ 106 (((level) <= DBG_LEVEL) \ 107 ? (fprintf(stdout, (format), ##__VA_ARGS__)) \ 108 : ((void)0)) 109 #else 110 #define AKMDEBUG(level, format, ...) 111 #endif 112 113 /***** Dbg Zone Output ***************************************/ 114 #if ENABLE_AKMDEBUG 115 #define AKMDATA(flag, format, ...) \ 116 ((((int)(flag)) & g_dbgzone) \ 117 ? (fprintf(stdout, (format), ##__VA_ARGS__)) \ 118 : ((void)0)) 119 #else 120 #define AKMDATA(flag, format, ...) 121 #endif 122 123 /***** Log output ********************************************/ 124 #ifdef AKM_LOG_ENABLE 125 #define AKM_LOG(format, ...) ALOGD((format), ##__VA_ARGS__) 126 #else 127 #define AKM_LOG(format, ...) 128 #endif 129 130 /***** Error output *******************************************/ 131 #define AKMERROR \ 132 ((g_opmode & OPMODE_CONSOLE) \ 133 ? (fprintf(stderr, "%s:%d Error.\n", __FUNCTION__, __LINE__)) \ 134 : (ALOGE("%s:%d Error.", __FUNCTION__, __LINE__))) 135 136 #define AKMERROR_STR(api) \ 137 ((g_opmode & OPMODE_CONSOLE) \ 138 ? (fprintf(stderr, "%s:%d %s Error (%s).\n", \ 139 __FUNCTION__, __LINE__, (api), strerror(errno))) \ 140 : (ALOGE("%s:%d %s Error (%s).", \ 141 __FUNCTION__, __LINE__, (api), strerror(errno)))) 142 143 /*** Type declaration *********************************************************/ 144 145 /*** Global variables *********************************************************/ 146 extern int g_stopRequest; /*!< 0:Not stop, 1:Stop */ 147 extern int g_opmode; /*!< 0:Daemon mode, 1:Console mode. */ 148 extern int g_dbgzone; /*!< Debug zone. */ 149 150 /*** Prototype of function ****************************************************/ 151 152 #endif /* AKMD_INC_AKCOMMON_H */ 153 154