1 /* 2 $License: 3 Copyright (C) 2011 InvenSense Corporation, All Rights Reserved. 4 $ 5 */ 6 7 #ifndef _MLOS_H 8 #define _MLOS_H 9 10 #ifndef __KERNEL__ 11 #include <stdio.h> 12 #endif 13 #include <pthread.h> 14 15 #include "mltypes.h" 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 #if defined(LINUX) || defined(__KERNEL__) 22 typedef pthread_mutex_t* HANDLE; 23 #endif 24 25 /* ------------ */ 26 /* - Defines. - */ 27 /* ------------ */ 28 29 /* - MLOSCreateFile defines. - */ 30 31 #define MLOS_GENERIC_READ ((unsigned int)0x80000000) 32 #define MLOS_GENERIC_WRITE ((unsigned int)0x40000000) 33 #define MLOS_FILE_SHARE_READ ((unsigned int)0x00000001) 34 #define MLOS_FILE_SHARE_WRITE ((unsigned int)0x00000002) 35 #define MLOS_OPEN_EXISTING ((unsigned int)0x00000003) 36 37 /* ---------- */ 38 /* - Enums. - */ 39 /* ---------- */ 40 41 /* --------------- */ 42 /* - Structures. - */ 43 /* --------------- */ 44 45 /* --------------------- */ 46 /* - Function p-types. - */ 47 /* --------------------- */ 48 49 #ifndef __KERNEL__ 50 #include <string.h> 51 void *inv_malloc(unsigned int numBytes); 52 inv_error_t inv_free(void *ptr); 53 inv_error_t inv_create_mutex(HANDLE *mutex); 54 inv_error_t inv_lock_mutex(HANDLE mutex); 55 inv_error_t inv_unlock_mutex(HANDLE mutex); 56 FILE *inv_fopen(char *filename); 57 void inv_fclose(FILE *fp); 58 59 inv_error_t inv_destroy_mutex(HANDLE handle); 60 61 void inv_sleep(int mSecs); 62 unsigned long inv_get_tick_count(void); 63 64 /* Kernel implmentations */ 65 #define GFP_KERNEL (0x70) 66 static inline void *kmalloc(size_t size, 67 unsigned int gfp_flags) 68 { 69 (void)gfp_flags; 70 return inv_malloc((unsigned int)size); 71 } 72 static inline void *kzalloc(size_t size, unsigned int gfp_flags) 73 { 74 void *tmp = inv_malloc((unsigned int)size); 75 (void)gfp_flags; 76 if (tmp) 77 memset(tmp, 0, size); 78 return tmp; 79 } 80 static inline void kfree(void *ptr) 81 { 82 inv_free(ptr); 83 } 84 static inline void msleep(long msecs) 85 { 86 inv_sleep(msecs); 87 } 88 static inline void udelay(unsigned long usecs) 89 { 90 inv_sleep((usecs + 999) / 1000); 91 } 92 #else 93 #include <linux/delay.h> 94 #endif 95 96 #ifdef __cplusplus 97 } 98 #endif 99 #endif /* _MLOS_H */ 100