summaryrefslogtreecommitdiffstats
path: root/60xx/libsensors_iio/software/core/mllite/linux/mlos_linux.c
diff options
context:
space:
mode:
authorVineeta Srivastava <vsrivastava@google.com>2013-06-04 14:28:40 -0700
committerVineeta Srivastava <vsrivastava@google.com>2013-06-04 16:03:11 -0700
commit501aae5c0464eab71924aa4e382e5f3c8885aece (patch)
tree8c7f402a6bfe9d18c75efdb73a919b915e9ddb35 /60xx/libsensors_iio/software/core/mllite/linux/mlos_linux.c
parent60c042a376b34a7f4343752b96c1bc0bf4da31cc (diff)
downloadandroid_hardware_invensense-501aae5c0464eab71924aa4e382e5f3c8885aece.tar.gz
android_hardware_invensense-501aae5c0464eab71924aa4e382e5f3c8885aece.tar.bz2
android_hardware_invensense-501aae5c0464eab71924aa4e382e5f3c8885aece.zip
Prepare for commiting 6515 chip specifc drop.
Split /hardware/invensesnse code to chip specific 60xx and 65xx directories. Moved 6050 chip specific stuff into 60xx directory. Manta uses that. This will allow 6515 chip specific stuff go in 65xx directoryi which will be used by hammerhead. Change-Id: If7ae097cba5376bbc68c644f14fdb2689dee2da5
Diffstat (limited to '60xx/libsensors_iio/software/core/mllite/linux/mlos_linux.c')
-rw-r--r--60xx/libsensors_iio/software/core/mllite/linux/mlos_linux.c190
1 files changed, 190 insertions, 0 deletions
diff --git a/60xx/libsensors_iio/software/core/mllite/linux/mlos_linux.c b/60xx/libsensors_iio/software/core/mllite/linux/mlos_linux.c
new file mode 100644
index 0000000..5424508
--- /dev/null
+++ b/60xx/libsensors_iio/software/core/mllite/linux/mlos_linux.c
@@ -0,0 +1,190 @@
+/*
+ $License:
+ Copyright (C) 2012 InvenSense Corporation, All Rights Reserved.
+ $
+ */
+
+/*******************************************************************************
+ *
+ * $Id: mlos_linux.c 5629 2011-06-11 03:13:08Z mcaramello $
+ *
+ ******************************************************************************/
+
+/**
+ * @defgroup MLOS
+ * @brief OS Interface.
+ *
+ * @{
+ * @file mlos.c
+ * @brief OS Interface.
+ */
+
+/* ------------- */
+/* - Includes. - */
+/* ------------- */
+
+#include <sys/time.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include "stdint_invensense.h"
+#include "mlos.h"
+
+
+/* -------------- */
+/* - Functions. - */
+/* -------------- */
+
+/**
+ * @brief Allocate space
+ * @param num_bytes number of bytes
+ * @return pointer to allocated space
+ */
+void *inv_malloc(unsigned int num_bytes)
+{
+ // Allocate space.
+ void *alloc_ptr = malloc(num_bytes);
+ return alloc_ptr;
+}
+
+
+/**
+ * @brief Free allocated space
+ * @param ptr pointer to space to deallocate
+ * @return error code.
+ */
+inv_error_t inv_free(void *ptr)
+{
+ if (ptr)
+ free(ptr);
+ return INV_SUCCESS;
+}
+
+
+/**
+ * @brief Mutex create function
+ * @param mutex pointer to mutex handle
+ * @return error code.
+ */
+inv_error_t inv_create_mutex(HANDLE *mutex)
+{
+ int res;
+ pthread_mutex_t *pm = malloc(sizeof(pthread_mutex_t));
+ if(pm == NULL)
+ return INV_ERROR;
+
+ res = pthread_mutex_init(pm, NULL);
+ if(res == -1) {
+ free(pm);
+ return INV_ERROR_OS_CREATE_FAILED;
+ }
+
+ *mutex = (HANDLE)pm;
+
+ return INV_SUCCESS;
+}
+
+
+/**
+ * @brief Mutex lock function
+ * @param mutex Mutex handle
+ * @return error code.
+ */
+inv_error_t inv_lock_mutex(HANDLE mutex)
+{
+ int res;
+ pthread_mutex_t *pm = (pthread_mutex_t *)mutex;
+
+ res = pthread_mutex_lock(pm);
+ if(res == -1)
+ return INV_ERROR_OS_LOCK_FAILED;
+
+ return INV_SUCCESS;
+}
+
+
+/**
+ * @brief Mutex unlock function
+ * @param mutex mutex handle
+ * @return error code.
+ */
+inv_error_t inv_unlock_mutex(HANDLE mutex)
+{
+ int res;
+ pthread_mutex_t *pm = (pthread_mutex_t *)mutex;
+
+ res = pthread_mutex_unlock(pm);
+ if(res == -1)
+ return INV_ERROR_OS_LOCK_FAILED;
+
+ return INV_SUCCESS;
+}
+
+
+/**
+ * @brief open file
+ * @param filename name of the file to open.
+ * @return error code.
+ */
+FILE *inv_fopen(char *filename)
+{
+ FILE *fp = fopen(filename, "r");
+ return fp;
+}
+
+
+/**
+ * @brief close the file.
+ * @param fp handle to file to close.
+ * @return error code.
+ */
+void inv_fclose(FILE *fp)
+{
+ fclose(fp);
+}
+
+/**
+ * @brief Close Handle
+ * @param handle handle to the resource.
+ * @return Zero if success, an error code otherwise.
+ */
+inv_error_t inv_destroy_mutex(HANDLE handle)
+{
+ int error;
+ pthread_mutex_t *pm = (pthread_mutex_t *)handle;
+ error = pthread_mutex_destroy(pm);
+ if (error)
+ return errno;
+ free((void*) handle);
+
+ return INV_SUCCESS;}
+
+
+/**
+ * @brief Sleep function.
+ */
+void inv_sleep(int m_secs)
+{
+ usleep(m_secs * 1000);
+}
+
+
+/**
+ * @brief get system's internal tick count.
+ * Used for time reference.
+ * @return current tick count.
+ */
+unsigned long inv_get_tick_count()
+{
+ struct timeval tv;
+
+ if (gettimeofday(&tv, NULL) != 0)
+ return 0;
+
+ return (long)((tv.tv_sec * 1000000LL + tv.tv_usec) / 1000LL);
+}
+
+/** @} */
+