• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  $License:
3    Copyright 2011 InvenSense, Inc.
4 
5  Licensed under the Apache License, Version 2.0 (the "License");
6  you may not use this file except in compliance with the License.
7  You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11  Unless required by applicable law or agreed to in writing, software
12  distributed under the License is distributed on an "AS IS" BASIS,
13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  See the License for the specific language governing permissions and
15  limitations under the License.
16   $
17  */
18 
19 #ifndef _MLOS_H
20 #define _MLOS_H
21 
22 #ifndef __KERNEL__
23 #include <stdio.h>
24 #endif
25 
26 #include "mltypes.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #if defined(LINUX) || defined(__KERNEL__)
33 #include <stdint.h>
34 typedef uintptr_t HANDLE;
35 #endif
36 
37 	/* ------------ */
38 	/* - Defines. - */
39 	/* ------------ */
40 
41 	/* - MLOSCreateFile defines. - */
42 
43 #define MLOS_GENERIC_READ         ((unsigned int)0x80000000)
44 #define MLOS_GENERIC_WRITE        ((unsigned int)0x40000000)
45 #define MLOS_FILE_SHARE_READ      ((unsigned int)0x00000001)
46 #define MLOS_FILE_SHARE_WRITE     ((unsigned int)0x00000002)
47 #define MLOS_OPEN_EXISTING        ((unsigned int)0x00000003)
48 
49 	/* ---------- */
50 	/* - Enums. - */
51 	/* ---------- */
52 
53 	/* --------------- */
54 	/* - Structures. - */
55 	/* --------------- */
56 
57 	/* --------------------- */
58 	/* - Function p-types. - */
59 	/* --------------------- */
60 
61 #ifndef __KERNEL__
62 #include <string.h>
63 	void *inv_malloc(unsigned int numBytes);
64 	inv_error_t inv_free(void *ptr);
65 	inv_error_t inv_create_mutex(HANDLE *mutex);
66 	inv_error_t inv_lock_mutex(HANDLE mutex);
67 	inv_error_t inv_unlock_mutex(HANDLE mutex);
68 	FILE *inv_fopen(char *filename);
69 	void inv_fclose(FILE *fp);
70 
71 	inv_error_t inv_destroy_mutex(HANDLE handle);
72 
73 	void inv_sleep(int mSecs);
74 	unsigned long inv_get_tick_count(void);
75 
76 	/* Kernel implmentations */
77 #define GFP_KERNEL (0x70)
kmalloc(size_t size,unsigned int gfp_flags)78 	static inline void *kmalloc(size_t size,
79 				    unsigned int gfp_flags)
80 	{
81 		return inv_malloc((unsigned int)size);
82 	}
kzalloc(size_t size,unsigned int gfp_flags)83 	static inline void *kzalloc(size_t size, unsigned int gfp_flags)
84 	{
85 		void *tmp = inv_malloc((unsigned int)size);
86 		if (tmp)
87 			memset(tmp, 0, size);
88 		return tmp;
89 	}
kfree(void * ptr)90 	static inline void kfree(void *ptr)
91 	{
92 		inv_free(ptr);
93 	}
msleep(long msecs)94 	static inline void msleep(long msecs)
95 	{
96 		inv_sleep(msecs);
97 	}
udelay(unsigned long usecs)98 	static inline void udelay(unsigned long usecs)
99 	{
100 		inv_sleep((usecs + 999) / 1000);
101 	}
102 #else
103 #include <linux/delay.h>
104 #endif
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 #endif				/* _MLOS_H */
110