Home | History | Annotate | Download | only in include
      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 typedef unsigned int HANDLE;
     34 #endif
     35 
     36 	/* ------------ */
     37 	/* - Defines. - */
     38 	/* ------------ */
     39 
     40 	/* - MLOSCreateFile defines. - */
     41 
     42 #define MLOS_GENERIC_READ         ((unsigned int)0x80000000)
     43 #define MLOS_GENERIC_WRITE        ((unsigned int)0x40000000)
     44 #define MLOS_FILE_SHARE_READ      ((unsigned int)0x00000001)
     45 #define MLOS_FILE_SHARE_WRITE     ((unsigned int)0x00000002)
     46 #define MLOS_OPEN_EXISTING        ((unsigned int)0x00000003)
     47 
     48 	/* ---------- */
     49 	/* - Enums. - */
     50 	/* ---------- */
     51 
     52 	/* --------------- */
     53 	/* - Structures. - */
     54 	/* --------------- */
     55 
     56 	/* --------------------- */
     57 	/* - Function p-types. - */
     58 	/* --------------------- */
     59 
     60 #ifndef __KERNEL__
     61 #include <string.h>
     62 	void *inv_malloc(unsigned int numBytes);
     63 	inv_error_t inv_free(void *ptr);
     64 	inv_error_t inv_create_mutex(HANDLE *mutex);
     65 	inv_error_t inv_lock_mutex(HANDLE mutex);
     66 	inv_error_t inv_unlock_mutex(HANDLE mutex);
     67 	FILE *inv_fopen(char *filename);
     68 	void inv_fclose(FILE *fp);
     69 
     70 	inv_error_t inv_destroy_mutex(HANDLE handle);
     71 
     72 	void inv_sleep(int mSecs);
     73 	unsigned long inv_get_tick_count(void);
     74 
     75 	/* Kernel implmentations */
     76 #define GFP_KERNEL (0x70)
     77 	static inline void *kmalloc(size_t size,
     78 				    unsigned int gfp_flags)
     79 	{
     80 		return inv_malloc((unsigned int)size);
     81 	}
     82 	static inline void *kzalloc(size_t size, unsigned int gfp_flags)
     83 	{
     84 		void *tmp = inv_malloc((unsigned int)size);
     85 		if (tmp)
     86 			memset(tmp, 0, size);
     87 		return tmp;
     88 	}
     89 	static inline void kfree(void *ptr)
     90 	{
     91 		inv_free(ptr);
     92 	}
     93 	static inline void msleep(long msecs)
     94 	{
     95 		inv_sleep(msecs);
     96 	}
     97 	static inline void udelay(unsigned long usecs)
     98 	{
     99 		inv_sleep((usecs + 999) / 1000);
    100 	}
    101 #else
    102 #include <linux/delay.h>
    103 #endif
    104 
    105 #ifdef __cplusplus
    106 }
    107 #endif
    108 #endif				/* _MLOS_H */
    109