1/*
2 $License:
3    Copyright (C) 2011 InvenSense Corporation, All Rights Reserved.
4 $
5 */
6
7/**
8 *  @defgroup MLERROR
9 *  @brief  Motion Library - Error definitions.
10 *          Definition of the error codes used within the MPL and
11 *          returned to the user.
12 *          Every function tries to return a meaningful error code basing
13 *          on the occuring error condition. The error code is numeric.
14 *
15 *          The available error codes and their associated values are:
16 *          - (0)               INV_SUCCESS
17 *          - (32)              INV_ERROR
18 *          - (22 / EINVAL)     INV_ERROR_INVALID_PARAMETER
19 *          - (1  / EPERM)      INV_ERROR_FEATURE_NOT_ENABLED
20 *          - (36)              INV_ERROR_FEATURE_NOT_IMPLEMENTED
21 *          - (38)              INV_ERROR_DMP_NOT_STARTED
22 *          - (39)              INV_ERROR_DMP_STARTED
23 *          - (40)              INV_ERROR_NOT_OPENED
24 *          - (41)              INV_ERROR_OPENED
25 *          - (19 / ENODEV)     INV_ERROR_INVALID_MODULE
26 *          - (12 / ENOMEM)     INV_ERROR_MEMORY_EXAUSTED
27 *          - (44)              INV_ERROR_DIVIDE_BY_ZERO
28 *          - (45)              INV_ERROR_ASSERTION_FAILURE
29 *          - (46)              INV_ERROR_FILE_OPEN
30 *          - (47)              INV_ERROR_FILE_READ
31 *          - (48)              INV_ERROR_FILE_WRITE
32 *          - (49)              INV_ERROR_INVALID_CONFIGURATION
33 *          - (52)              INV_ERROR_SERIAL_CLOSED
34 *          - (53)              INV_ERROR_SERIAL_OPEN_ERROR
35 *          - (54)              INV_ERROR_SERIAL_READ
36 *          - (55)              INV_ERROR_SERIAL_WRITE
37 *          - (56)              INV_ERROR_SERIAL_DEVICE_NOT_RECOGNIZED
38 *          - (57)              INV_ERROR_SM_TRANSITION
39 *          - (58)              INV_ERROR_SM_IMPROPER_STATE
40 *          - (62)              INV_ERROR_FIFO_OVERFLOW
41 *          - (63)              INV_ERROR_FIFO_FOOTER
42 *          - (64)              INV_ERROR_FIFO_READ_COUNT
43 *          - (65)              INV_ERROR_FIFO_READ_DATA
44 *          - (72)              INV_ERROR_MEMORY_SET
45 *          - (82)              INV_ERROR_LOG_MEMORY_ERROR
46 *          - (83)              INV_ERROR_LOG_OUTPUT_ERROR
47 *          - (92)              INV_ERROR_OS_BAD_PTR
48 *          - (93)              INV_ERROR_OS_BAD_HANDLE
49 *          - (94)              INV_ERROR_OS_CREATE_FAILED
50 *          - (95)              INV_ERROR_OS_LOCK_FAILED
51 *          - (102)             INV_ERROR_COMPASS_DATA_OVERFLOW
52 *          - (103)             INV_ERROR_COMPASS_DATA_UNDERFLOW
53 *          - (104)             INV_ERROR_COMPASS_DATA_NOT_READY
54 *          - (105)             INV_ERROR_COMPASS_DATA_ERROR
55 *          - (107)             INV_ERROR_CALIBRATION_LOAD
56 *          - (108)             INV_ERROR_CALIBRATION_STORE
57 *          - (109)             INV_ERROR_CALIBRATION_LEN
58 *          - (110)             INV_ERROR_CALIBRATION_CHECKSUM
59 *          - (111)             INV_ERROR_ACCEL_DATA_OVERFLOW
60 *          - (112)             INV_ERROR_ACCEL_DATA_UNDERFLOW
61 *          - (113)             INV_ERROR_ACCEL_DATA_NOT_READY
62 *          - (114)             INV_ERROR_ACCEL_DATA_ERROR
63 *
64 *          The available warning codes and their associated values are:
65 *          - (115)             INV_WARNING_MOTION_RACE
66 *          - (116)             INV_WARNING_QUAT_TRASHED
67 *
68 *  @{
69 *      @file mltypes.h
70 *  @}
71 */
72
73#ifndef MLTYPES_H
74#define MLTYPES_H
75
76#ifdef __KERNEL__
77#include <linux/types.h>
78#include <asm-generic/errno-base.h>
79#else
80#include "stdint_invensense.h"
81#include <errno.h>
82#endif
83#include <limits.h>
84
85#ifndef REMOVE_INV_ERROR_T
86/*---------------------------
87 *    ML Types
88 *--------------------------*/
89
90/**
91 *  @struct inv_error_t mltypes.h "mltypes"
92 *  @brief  The MPL Error Code return type.
93 *
94 *  @code
95 *      typedef unsigned char inv_error_t;
96 *  @endcode
97 */
98//typedef unsigned char inv_error_t;
99typedef int inv_error_t;
100#endif
101
102typedef long long inv_time_t;
103
104#if !defined __GNUC__ && !defined __KERNEL__
105typedef int8_t   __s8;
106typedef int16_t  __s16;
107typedef int32_t  __s32;
108typedef int32_t  __s64;
109
110typedef uint8_t   __u8;
111typedef uint16_t  __u16;
112typedef uint32_t  __u32;
113typedef uint64_t  __u64;
114#elif !defined __KERNEL__
115#include <sys/types.h>
116#endif
117
118#ifndef __cplusplus
119#ifndef __KERNEL__
120typedef int_fast8_t bool;
121
122#ifndef false
123#define false 0
124#endif
125
126#ifndef true
127#define true 1
128#endif
129
130#endif
131#endif
132
133/*---------------------------
134 *    ML Defines
135 *--------------------------*/
136
137#ifndef NULL
138#define NULL 0
139#endif
140
141#ifndef __KERNEL__
142#ifndef ARRAY_SIZE
143/* Dimension of an array */
144#define ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0]))
145#endif
146#endif
147/* - ML Errors. - */
148#define ERROR_NAME(x)   (#x)
149#define ERROR_CHECK_FIRST(first, x) \
150	{ if (INV_SUCCESS == first) first = x; }
151
152#define INV_SUCCESS                       (0)
153/* Generic Error code.  Proprietary Error Codes only */
154#define INV_ERROR_BASE                    (0x20)
155#define INV_ERROR                         (INV_ERROR_BASE)
156
157/* Compatibility and other generic error codes */
158#define INV_ERROR_INVALID_PARAMETER             (EINVAL)
159#define INV_ERROR_FEATURE_NOT_ENABLED           (EPERM)
160#define INV_ERROR_FEATURE_NOT_IMPLEMENTED       (INV_ERROR_BASE + 4)
161#define INV_ERROR_DMP_NOT_STARTED               (INV_ERROR_BASE + 6)
162#define INV_ERROR_DMP_STARTED                   (INV_ERROR_BASE + 7)
163#define INV_ERROR_NOT_OPENED                    (INV_ERROR_BASE + 8)
164#define INV_ERROR_OPENED                        (INV_ERROR_BASE + 9)
165#define INV_ERROR_INVALID_MODULE                (ENODEV)
166#define INV_ERROR_MEMORY_EXAUSTED               (ENOMEM)
167#define INV_ERROR_DIVIDE_BY_ZERO                (INV_ERROR_BASE + 12)
168#define INV_ERROR_ASSERTION_FAILURE             (INV_ERROR_BASE + 13)
169#define INV_ERROR_FILE_OPEN                     (INV_ERROR_BASE + 14)
170#define INV_ERROR_FILE_READ                     (INV_ERROR_BASE + 15)
171#define INV_ERROR_FILE_WRITE                    (INV_ERROR_BASE + 16)
172#define INV_ERROR_INVALID_CONFIGURATION         (INV_ERROR_BASE + 17)
173#define INV_ERROR_NOT_AUTHORIZED                (INV_ERROR_BASE + 18)
174
175/* Serial Communication */
176#define INV_ERROR_SERIAL_CLOSED                 (INV_ERROR_BASE + 20)
177#define INV_ERROR_SERIAL_OPEN_ERROR             (INV_ERROR_BASE + 21)
178#define INV_ERROR_SERIAL_READ                   (INV_ERROR_BASE + 22)
179#define INV_ERROR_SERIAL_WRITE                  (INV_ERROR_BASE + 23)
180#define INV_ERROR_SERIAL_DEVICE_NOT_RECOGNIZED  (INV_ERROR_BASE + 24)
181
182/* SM = State Machine */
183#define INV_ERROR_SM_TRANSITION                 (INV_ERROR_BASE + 25)
184#define INV_ERROR_SM_IMPROPER_STATE             (INV_ERROR_BASE + 26)
185
186/* Fifo */
187#define INV_ERROR_FIFO_OVERFLOW                 (INV_ERROR_BASE + 30)
188#define INV_ERROR_FIFO_FOOTER                   (INV_ERROR_BASE + 31)
189#define INV_ERROR_FIFO_READ_COUNT               (INV_ERROR_BASE + 32)
190#define INV_ERROR_FIFO_READ_DATA                (INV_ERROR_BASE + 33)
191
192/* Memory & Registers, Set & Get */
193#define INV_ERROR_MEMORY_SET                    (INV_ERROR_BASE + 40)
194
195#define INV_ERROR_LOG_MEMORY_ERROR              (INV_ERROR_BASE + 50)
196#define INV_ERROR_LOG_OUTPUT_ERROR              (INV_ERROR_BASE + 51)
197
198/* OS interface errors */
199#define INV_ERROR_OS_BAD_PTR                    (INV_ERROR_BASE + 60)
200#define INV_ERROR_OS_BAD_HANDLE                 (INV_ERROR_BASE + 61)
201#define INV_ERROR_OS_CREATE_FAILED              (INV_ERROR_BASE + 62)
202#define INV_ERROR_OS_LOCK_FAILED                (INV_ERROR_BASE + 63)
203
204/* Compass errors */
205#define INV_ERROR_COMPASS_DATA_OVERFLOW         (INV_ERROR_BASE + 70)
206#define INV_ERROR_COMPASS_DATA_UNDERFLOW        (INV_ERROR_BASE + 71)
207#define INV_ERROR_COMPASS_DATA_NOT_READY        (INV_ERROR_BASE + 72)
208#define INV_ERROR_COMPASS_DATA_ERROR            (INV_ERROR_BASE + 73)
209
210/* Load/Store calibration */
211#define INV_ERROR_CALIBRATION_LOAD              (INV_ERROR_BASE + 75)
212#define INV_ERROR_CALIBRATION_STORE             (INV_ERROR_BASE + 76)
213#define INV_ERROR_CALIBRATION_LEN               (INV_ERROR_BASE + 77)
214#define INV_ERROR_CALIBRATION_CHECKSUM          (INV_ERROR_BASE + 78)
215
216/* Accel errors */
217#define INV_ERROR_ACCEL_DATA_OVERFLOW           (INV_ERROR_BASE + 79)
218#define INV_ERROR_ACCEL_DATA_UNDERFLOW          (INV_ERROR_BASE + 80)
219#define INV_ERROR_ACCEL_DATA_NOT_READY          (INV_ERROR_BASE + 81)
220#define INV_ERROR_ACCEL_DATA_ERROR              (INV_ERROR_BASE + 82)
221
222/* No Motion Warning States */
223#define INV_WARNING_MOTION_RACE                 (INV_ERROR_BASE + 83)
224#define INV_WARNING_QUAT_TRASHED                (INV_ERROR_BASE + 84)
225#define INV_WARNING_GYRO_MAG                    (INV_ERROR_BASE + 85)
226
227#define INV_WARNING_SEMAPHORE_TIMEOUT           (INV_ERROR_BASE + 86)
228
229
230/* For Linux coding compliance */
231#ifndef __KERNEL__
232#define EXPORT_SYMBOL(x)
233#endif
234
235#endif				/* MLTYPES_H */
236