summaryrefslogtreecommitdiffstats
path: root/domx/mm_osal/src
diff options
context:
space:
mode:
Diffstat (limited to 'domx/mm_osal/src')
-rwxr-xr-xdomx/mm_osal/src/timm_osal.c99
-rwxr-xr-xdomx/mm_osal/src/timm_osal_events.c420
-rwxr-xr-xdomx/mm_osal/src/timm_osal_memory.c250
-rwxr-xr-xdomx/mm_osal/src/timm_osal_mutex.c244
-rwxr-xr-xdomx/mm_osal/src/timm_osal_pipes.c415
-rwxr-xr-xdomx/mm_osal/src/timm_osal_semaphores.c297
-rwxr-xr-xdomx/mm_osal/src/timm_osal_task.c262
-rwxr-xr-xdomx/mm_osal/src/timm_osal_trace.c174
8 files changed, 2161 insertions, 0 deletions
diff --git a/domx/mm_osal/src/timm_osal.c b/domx/mm_osal/src/timm_osal.c
new file mode 100755
index 0000000..85fdb66
--- /dev/null
+++ b/domx/mm_osal/src/timm_osal.c
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2010, Texas Instruments Incorporated
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+* @file tiimm_osal.c
+* This file contains methods that provides the functionality
+* initializing/deinitializing the osal.
+*
+* @path \
+*
+*/
+/* -------------------------------------------------------------------------- */
+/* =========================================================================
+ *!
+ *! Revision History
+ *! ===================================
+ *! 20-Oct-2008 Maiya ShreeHarsha:Linux specific changes
+ *! 0.1: Created the first draft version, ksrini@ti.com
+ * ========================================================================= */
+
+/******************************************************************************
+* Includes
+******************************************************************************/
+#include "timm_osal_types.h"
+#include "timm_osal_error.h"
+#include "timm_osal_memory.h"
+/*#include "timm_osal_trace.h"*/
+
+
+/******************************************************************************
+* Function Prototypes
+******************************************************************************/
+
+/****************************************************************
+* PRIVATE DECLARATIONS : only used in this file
+****************************************************************/
+/*--------data declarations -----------------------------------*/
+
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_Init function initilize the osal with initial settings.
+*
+* @return TIMM_OSAL_ERR_NONE if successful
+* !TIMM_OSAL_ERR_NONE if an error occurs
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_Init(void)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_NONE;
+ return bReturnStatus;
+}
+
+
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_Init function de-initilize the osal.
+*
+* @return TIMM_OSAL_ERR_NONE if successful
+* !TIMM_OSAL_ERR_NONE if an error occurs
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_Deinit(void)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_NONE;
+ return bReturnStatus;
+}
diff --git a/domx/mm_osal/src/timm_osal_events.c b/domx/mm_osal/src/timm_osal_events.c
new file mode 100755
index 0000000..96f8e59
--- /dev/null
+++ b/domx/mm_osal/src/timm_osal_events.c
@@ -0,0 +1,420 @@
+/*
+ * Copyright (c) 2010, Texas Instruments Incorporated
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+* @file timm_osal_events.c
+* This file contains methods that provides the functionality
+* for creating/using events.
+*
+* @path \
+*
+*/
+/* -------------------------------------------------------------------------- */
+/* =========================================================================
+ *!
+ *! Revision History
+ *! ===================================
+ *! 06-Nov-2008 Maiya ShreeHarsha: Linux specific changes
+ *! 0.1: Created the first draft version, ksrini@ti.com
+ * ========================================================================= */
+
+/******************************************************************************
+* Includes
+******************************************************************************/
+#include <stdio.h>
+#include <pthread.h> /*for POSIX calls */
+#include <sys/time.h>
+#include <errno.h>
+
+#include "timm_osal_types.h"
+#include "timm_osal_trace.h"
+#include "timm_osal_error.h"
+#include "timm_osal_memory.h"
+#include "timm_osal_events.h"
+
+
+typedef struct
+{
+ TIMM_OSAL_BOOL bSignaled;
+ TIMM_OSAL_U32 eFlags;
+ pthread_mutex_t mutex;
+ pthread_cond_t condition;
+} TIMM_OSAL_THREAD_EVENT;
+
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_EventCreate function
+*
+*
+*/
+/* ========================================================================== */
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_EventCreate(TIMM_OSAL_PTR * pEvents)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ TIMM_OSAL_THREAD_EVENT *plEvent = NULL;
+
+ plEvent =
+ (TIMM_OSAL_THREAD_EVENT *)
+ TIMM_OSAL_Malloc(sizeof(TIMM_OSAL_THREAD_EVENT), 0, 0, 0);
+
+ if (TIMM_OSAL_NULL == plEvent)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_ALLOC;
+ goto EXIT;
+ }
+ plEvent->bSignaled = TIMM_OSAL_FALSE;
+ plEvent->eFlags = 0;
+
+ if (SUCCESS != pthread_mutex_init(&(plEvent->mutex), NULL))
+ {
+ TIMM_OSAL_Error("Event Create:Mutex Init failed !");
+ goto EXIT; /*bReturnStatus = TIMM_OSAL_ERR_UNKNOWN */
+ }
+
+ if (SUCCESS != pthread_cond_init(&(plEvent->condition), NULL))
+ {
+ TIMM_OSAL_Error
+ ("Event Create:Conditional Variable Init failed !");
+ pthread_mutex_destroy(&(plEvent->mutex));
+ /*TIMM_OSAL_Free(plEvent); */
+ } else
+ {
+ *pEvents = (TIMM_OSAL_PTR) plEvent;
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+ }
+ EXIT:
+ if ((TIMM_OSAL_ERR_NONE != bReturnStatus) &&
+ (TIMM_OSAL_NULL != plEvent))
+ {
+ TIMM_OSAL_Free(plEvent);
+ }
+ return bReturnStatus;
+}
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_EventDelete function
+*
+*
+*/
+/* ========================================================================== */
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_EventDelete(TIMM_OSAL_PTR pEvents)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_NONE;
+ TIMM_OSAL_THREAD_EVENT *plEvent = (TIMM_OSAL_THREAD_EVENT *) pEvents;
+
+ if (TIMM_OSAL_NULL == plEvent)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+
+ if (SUCCESS != pthread_mutex_lock(&(plEvent->mutex)))
+ {
+ TIMM_OSAL_Error("Event Delete: Mutex Lock failed !");
+ bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ }
+ if (SUCCESS != pthread_cond_destroy(&(plEvent->condition)))
+ {
+ TIMM_OSAL_Error
+ ("Event Delete: Conditional Variable Destroy failed !");
+ bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ }
+
+ if (SUCCESS != pthread_mutex_unlock(&(plEvent->mutex)))
+ {
+ TIMM_OSAL_Error("Event Delete: Mutex Unlock failed !");
+ bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ }
+
+ if (SUCCESS != pthread_mutex_destroy(&(plEvent->mutex)))
+ {
+ TIMM_OSAL_Error("Event Delete: Mutex Destory failed !");
+ bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ }
+
+ TIMM_OSAL_Free(plEvent);
+ EXIT:
+ return bReturnStatus;
+}
+
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_EventSet function
+*
+*
+*/
+/* ========================================================================== */
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_EventSet(TIMM_OSAL_PTR pEvents,
+ TIMM_OSAL_U32 uEventFlags, TIMM_OSAL_EVENT_OPERATION eOperation)
+{
+
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ TIMM_OSAL_THREAD_EVENT *plEvent = (TIMM_OSAL_THREAD_EVENT *) pEvents;
+
+ if (TIMM_OSAL_NULL == plEvent)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+
+ if (SUCCESS != pthread_mutex_lock(&(plEvent->mutex)))
+ {
+ TIMM_OSAL_Error("Event Set: Mutex Lock failed !");
+ bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ goto EXIT;
+ }
+
+ switch (eOperation)
+ {
+ case TIMM_OSAL_EVENT_AND:
+ plEvent->eFlags = plEvent->eFlags & uEventFlags;
+ break;
+ case TIMM_OSAL_EVENT_OR:
+ plEvent->eFlags = plEvent->eFlags | uEventFlags;
+ break;
+ default:
+ TIMM_OSAL_Error("Event Set: Bad eOperation !");
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ pthread_mutex_unlock(&plEvent->mutex);
+ goto EXIT;
+ }
+
+ plEvent->bSignaled = TIMM_OSAL_TRUE;
+
+ if (SUCCESS != pthread_cond_signal(&plEvent->condition))
+ {
+ TIMM_OSAL_Error
+ ("Event Set: Condition Variable Signal failed !");
+ bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ pthread_mutex_unlock(&plEvent->mutex);
+ goto EXIT;
+ }
+
+ if (SUCCESS != pthread_mutex_unlock(&plEvent->mutex))
+ {
+ TIMM_OSAL_Error("Event Set: Mutex Unlock failed !");
+ bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ } else
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+
+ EXIT:
+ return bReturnStatus;
+
+
+}
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_EventRetrieve function
+*
+*Spurious wakeups from the pthread_cond_timedwait() or pthread_cond_wait() functions may occur.
+*
+*A representative sequence for using condition variables is shown below
+*
+*Thread A (Retrieve Events) |Thread B (Set Events)
+*------------------------------------------------------------------------------------------------------------
+*1) Do work up to the point where a certain condition |1)Do work
+* must occur (such as "count" must reach a specified |2)Lock associated mutex
+* value) |3)Change the value of the global variable
+*2) Lock associated mutex and check value of a global | that Thread-A is waiting upon.
+* variable |4)Check value of the global Thread-A wait
+*3) Call pthread_cond_wait() to perform a blocking wait | variable. If it fulfills the desired
+* for signal from Thread-B. Note that a call to | condition, signal Thread-A.
+* pthread_cond_wait() automatically and atomically |5)Unlock mutex.
+* unlocks the associated mutex variable so that it can |6)Continue
+* be used by Thread-B. |
+*4) When signalled, wake up. Mutex is automatically and |
+* atomically locked. |
+*5) Explicitly unlock mutex |
+*6) Continue |
+*
+*/
+/* ========================================================================== */
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_EventRetrieve(TIMM_OSAL_PTR pEvents,
+ TIMM_OSAL_U32 uRequestedEvents,
+ TIMM_OSAL_EVENT_OPERATION eOperation,
+ TIMM_OSAL_U32 * pRetrievedEvents, TIMM_OSAL_U32 uTimeOutMsec)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ struct timespec timeout;
+ struct timeval now;
+ TIMM_OSAL_U32 timeout_us;
+ TIMM_OSAL_U32 isolatedFlags;
+ int status = -1;
+ int and_operation;
+ TIMM_OSAL_THREAD_EVENT *plEvent = (TIMM_OSAL_THREAD_EVENT *) pEvents;
+
+ if (TIMM_OSAL_NULL == plEvent)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+
+ /* Lock the mutex for access to the eFlags global variable */
+ if (SUCCESS != pthread_mutex_lock(&(plEvent->mutex)))
+ {
+ TIMM_OSAL_Error("Event Retrieve: Mutex Lock failed !");
+ bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ goto EXIT;
+ }
+
+ /*Check the eOperation and put it in a variable */
+ and_operation = ((TIMM_OSAL_EVENT_AND == eOperation) ||
+ (TIMM_OSAL_EVENT_AND_CONSUME == eOperation));
+
+ /* Isolate the flags. The & operation is suffice for an TIMM_OSAL_EVENT_OR eOperation */
+ isolatedFlags = plEvent->eFlags & uRequestedEvents;
+
+ /*Check if it is the AND operation. If yes then, all the flags must match */
+ if (and_operation)
+ {
+ isolatedFlags = (isolatedFlags == uRequestedEvents);
+ }
+
+
+ if (isolatedFlags)
+ {
+
+ /*We have got required combination of the eFlags bits and will return it back */
+ *pRetrievedEvents = plEvent->eFlags;
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+ } else
+ {
+
+ /*Required combination of bits is not yet available */
+ if (TIMM_OSAL_NO_SUSPEND == uTimeOutMsec)
+ {
+ *pRetrievedEvents = 0;
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+ }
+
+ else if (TIMM_OSAL_SUSPEND == uTimeOutMsec)
+ {
+
+ /*Wait till we get the required combination of bits. We we get the required
+ *bits then we go out of the while loop
+ */
+ while (!isolatedFlags)
+ {
+
+ /*Wait on the conditional variable for another thread to set the eFlags and signal */
+ pthread_cond_wait(&(plEvent->condition),
+ &(plEvent->mutex));
+
+ /* eFlags set by some thread. Now, isolate the flags.
+ * The & operation is suffice for an TIMM_OSAL_EVENT_OR eOperation
+ */
+ isolatedFlags =
+ plEvent->eFlags & uRequestedEvents;
+
+ /*Check if it is the AND operation. If yes then, all the flags must match */
+ if (and_operation)
+ {
+ isolatedFlags =
+ (isolatedFlags ==
+ uRequestedEvents);
+ }
+ }
+
+ /* Obtained the requested combination of bits on eFlags */
+ *pRetrievedEvents = plEvent->eFlags;
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+
+ } else
+ {
+
+ /* Calculate uTimeOutMsec in terms of the absolute time. uTimeOutMsec is in milliseconds */
+ gettimeofday(&now, NULL);
+ timeout_us = now.tv_usec + 1000 * uTimeOutMsec;
+ timeout.tv_sec = now.tv_sec + timeout_us / 1000000;
+ timeout.tv_nsec = (timeout_us % 1000000) * 1000;
+
+ while (!isolatedFlags)
+ {
+
+ /* Wait till uTimeOutMsec for a thread to signal on the conditional variable */
+ status =
+ pthread_cond_timedwait(&(plEvent->
+ condition), &(plEvent->mutex),
+ &timeout);
+
+ /*Timedout or error and returned without being signalled */
+ if (SUCCESS != status)
+ {
+ if (ETIMEDOUT == status)
+ bReturnStatus =
+ TIMM_OSAL_ERR_NONE;
+ *pRetrievedEvents = 0;
+ break;
+ }
+
+ /* eFlags set by some thread. Now, isolate the flags.
+ * The & operation is suffice for an TIMM_OSAL_EVENT_OR eOperation
+ */
+ isolatedFlags =
+ plEvent->eFlags & uRequestedEvents;
+
+ /*Check if it is the AND operation. If yes then, all the flags must match */
+ if (and_operation)
+ {
+ isolatedFlags =
+ (isolatedFlags ==
+ uRequestedEvents);
+ }
+
+ }
+ }
+ }
+
+ /*If we have got the required combination of bits, we will have to reset the eFlags if CONSUME is mentioned
+ *in the eOperations
+ */
+ if (isolatedFlags && ((eOperation == TIMM_OSAL_EVENT_AND_CONSUME) ||
+ (eOperation == TIMM_OSAL_EVENT_OR_CONSUME)))
+ {
+ plEvent->eFlags = 0;
+ }
+
+ /*Manually unlock the mutex */
+ if (SUCCESS != pthread_mutex_unlock(&(plEvent->mutex)))
+ {
+ TIMM_OSAL_Error("Event Retrieve: Mutex Unlock failed !");
+ bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ }
+
+ EXIT:
+ return bReturnStatus;
+
+}
diff --git a/domx/mm_osal/src/timm_osal_memory.c b/domx/mm_osal/src/timm_osal_memory.c
new file mode 100755
index 0000000..22eb0a4
--- /dev/null
+++ b/domx/mm_osal/src/timm_osal_memory.c
@@ -0,0 +1,250 @@
+/*
+ * Copyright (c) 2010, Texas Instruments Incorporated
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+* @file timm_osal_memory.c
+* This file contains methods that provides the functionality
+* for allocating/deallocating memory.
+*
+* @path \
+*
+*/
+/* -------------------------------------------------------------------------- */
+/* =========================================================================
+ *!
+ *! Revision History
+ *! ===================================
+ *!23-Oct-2008 Maiya ShreeHarsha: Linux specific changes
+ *!0.1: Created the first draft version, ksrini@ti.com
+ * ========================================================================= */
+
+/******************************************************************************
+* Includes
+******************************************************************************/
+
+#include <string.h>
+#include <malloc.h>
+
+#ifdef __KERNEL__
+#include <linux/types.h>
+#else
+#include <stdint.h>
+#endif
+
+
+#include "timm_osal_types.h"
+#include "timm_osal_trace.h"
+#include "timm_osal_error.h"
+#include "timm_osal_memory.h"
+
+
+
+static TIMM_OSAL_U32 gMallocCounter = 0;
+
+/******************************************************************************
+* Function Prototypes
+******************************************************************************/
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_createMemoryPool function
+*
+* @see
+*/
+/* ========================================================================== */
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_CreateMemoryPool(void)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_NONE;
+ return bReturnStatus;
+}
+
+
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_DeleteMemoryPool function
+*
+* @see
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_DeleteMemoryPool(void)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_NONE;
+ return bReturnStatus;
+
+}
+
+
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_Malloc function
+*
+* @see
+*/
+/* ========================================================================== */
+TIMM_OSAL_PTR TIMM_OSAL_Malloc(TIMM_OSAL_U32 size,
+ TIMM_OSAL_BOOL bBlockContiguous,
+ TIMM_OSAL_U32 unBlockAlignment, TIMMOSAL_MEM_SEGMENTID tMemSegId)
+{
+
+ TIMM_OSAL_PTR pData = TIMM_OSAL_NULL;
+
+#ifdef HAVE_MEMALIGN
+ if (0 == unBlockAlignment)
+ {
+ pData = malloc((size_t) size);
+ } else
+ {
+ pData = memalign((size_t) unBlockAlignment, (size_t) size);
+ }
+#else
+ if (0 != unBlockAlignment)
+ {
+ TIMM_OSAL_Warning
+ ("Memory Allocation:Not done for specified nBufferAlignment. Alignment of 0 will be used");
+
+ }
+ pData = malloc((size_t) size); /*size_t is long long */
+#endif
+ if (TIMM_OSAL_NULL == pData)
+ {
+ TIMM_OSAL_Error("Malloc failed!!!");
+ } else
+ {
+ /* Memory Allocation was successfull */
+ gMallocCounter++;
+ }
+
+
+ return pData;
+}
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_Free function ....
+*
+* @see
+*/
+/* ========================================================================== */
+
+void TIMM_OSAL_Free(TIMM_OSAL_PTR pData)
+{
+ if (TIMM_OSAL_NULL == pData)
+ {
+ /*TIMM_OSAL_Warning("TIMM_OSAL_Free called on NULL pointer"); */
+ goto EXIT;
+ }
+
+ free(pData);
+ pData = NULL;
+ gMallocCounter--;
+ EXIT:
+ return;
+}
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_Memset function ....
+*
+* @see
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_Memset(TIMM_OSAL_PTR pBuffer,
+ TIMM_OSAL_U8 uValue, TIMM_OSAL_U32 uSize)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+
+ memset((void *)pBuffer, (int)uValue, (size_t) uSize);
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+
+ return bReturnStatus;
+}
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_Memcmp function ....
+*
+* @see
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_S32 TIMM_OSAL_Memcmp(TIMM_OSAL_PTR pBuffer1, TIMM_OSAL_PTR pBuffer2,
+ TIMM_OSAL_U32 uSize)
+{
+ TIMM_OSAL_S32 result = memcmp(pBuffer1, pBuffer2, uSize);
+
+ if (result > 0)
+ {
+ return 1;
+ } else if (result < 0)
+ {
+ return -1;
+ }
+
+ return 0;
+}
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_Memcpy function ....
+*
+* @see
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_Memcpy(TIMM_OSAL_PTR pBufDst,
+ TIMM_OSAL_PTR pBufSrc, TIMM_OSAL_U32 uSize)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+
+ memcpy(pBufDst, pBufSrc, uSize);
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+
+ return bReturnStatus;
+}
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_GetMemCounter function ....
+*
+* @see
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_U32 TIMM_OSAL_GetMemCounter(void)
+{
+
+ return gMallocCounter;
+}
diff --git a/domx/mm_osal/src/timm_osal_mutex.c b/domx/mm_osal/src/timm_osal_mutex.c
new file mode 100755
index 0000000..5cfecf8
--- /dev/null
+++ b/domx/mm_osal/src/timm_osal_mutex.c
@@ -0,0 +1,244 @@
+/*
+ * Copyright (c) 2010, Texas Instruments Incorporated
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+* @file timm_osal_Mutexs.c
+* This file contains methods that provides the functionality
+*
+* @path \
+*
+*/
+/* -------------------------------------------------------------------------- */
+/* =========================================================================
+ *!
+ *! Revision History
+ *! ===================================
+ *! 04-Nov-2008 Maiya ShreeHarsha: Linux specific changes
+ *! 0.1: Created the first draft version, ksrini@ti.com
+ * ========================================================================= */
+
+/******************************************************************************
+* Includes
+******************************************************************************/
+
+
+#include "timm_osal_types.h"
+#include "timm_osal_trace.h"
+#include "timm_osal_error.h"
+#include "timm_osal_memory.h"
+#include "timm_osal_semaphores.h"
+
+#include <errno.h>
+
+#include <pthread.h>
+#include <sys/time.h>
+
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_MutexCreate function
+*
+*
+*/
+/* ========================================================================== */
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_MutexCreate(TIMM_OSAL_PTR * pMutex)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ pthread_mutex_t *plMutex = TIMM_OSAL_NULL;
+
+ plMutex =
+ (pthread_mutex_t *) TIMM_OSAL_Malloc(sizeof(pthread_mutex_t), 0,
+ 0, 0);
+ if (TIMM_OSAL_NULL == plMutex)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_ALLOC;
+ goto EXIT;
+ }
+
+ /*if (SUCCESS != pthread_mutex_init(plMutex, pAttr)) */
+ if (SUCCESS != pthread_mutex_init(plMutex, TIMM_OSAL_NULL))
+ {
+ /*TIMM_OSAL_Error ("Mutex Create failed !"); */
+ /*goto EXIT; */
+ } else
+ {
+ /**pMutex = (TIMM_OSAL_PTR *)plMutex;*/
+ *pMutex = (TIMM_OSAL_PTR) plMutex;
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+ }
+ EXIT:
+ /*if((TIMM_OSAL_ERR_NONE != bReturnStatus)) {
+ TIMM_OSAL_Free(plMutex);
+ } */
+ if ((TIMM_OSAL_ERR_NONE != bReturnStatus) &&
+ (TIMM_OSAL_NULL != plMutex))
+ {
+ TIMM_OSAL_Free(plMutex);
+ }
+ return bReturnStatus;
+
+/**********************************************************/
+/*return TIMM_OSAL_SemaphoreCreate(pMutex, 1);*/
+/**********************************************************/
+}
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_MutexDelete function
+*
+*
+*/
+/* ========================================================================== */
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_MutexDelete(TIMM_OSAL_PTR pMutex)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_NONE;
+ pthread_mutex_t *plMutex = (pthread_mutex_t *) pMutex;
+
+ if (plMutex == TIMM_OSAL_NULL)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+ /*can we do away with if or with switch case */
+ if (SUCCESS != pthread_mutex_destroy(plMutex))
+ {
+ /*TIMM_OSAL_Error("Delete Mutex failed !"); */
+ bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;;
+ }
+
+ TIMM_OSAL_Free(plMutex);
+ EXIT:
+ return bReturnStatus;
+/**********************************************************/
+/*return TIMM_OSAL_SemaphoreDelete(pMutex);*/
+/**********************************************************/
+
+}
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_MutexObtain function
+*
+*
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_MutexObtain(TIMM_OSAL_PTR pMutex,
+ TIMM_OSAL_U32 uTimeOut)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ struct timespec abs_timeout;
+ struct timeval ltime_now;
+ TIMM_OSAL_U32 ltimenow_us;
+ pthread_mutex_t *plMutex = (pthread_mutex_t *) pMutex;
+
+ if (plMutex == TIMM_OSAL_NULL)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+
+ if (TIMM_OSAL_SUSPEND == uTimeOut)
+ {
+ if (SUCCESS != pthread_mutex_lock(plMutex))
+ {
+ /*TIMM_OSAL_Error("Lock Mutex failed !"); */
+ goto EXIT;
+ }
+ } else if (TIMM_OSAL_NO_SUSPEND == uTimeOut)
+ {
+ if (SUCCESS != pthread_mutex_trylock(plMutex))
+ {
+ /*TIMM_OSAL_Error("Lock Mutex failed !"); */
+ goto EXIT;
+ }
+ } else
+ {
+ gettimeofday(&ltime_now, NULL);
+ /*uTimeOut is assumed to be in milliseconds */
+ ltimenow_us = ltime_now.tv_usec + 1000 * uTimeOut;
+ abs_timeout.tv_sec = ltime_now.tv_sec + uTimeOut / 1000;
+ abs_timeout.tv_nsec = (ltimenow_us % 1000000) * 1000;
+
+#ifdef _POSIX_VERSION_1_
+ if (SUCCESS != pthread_mutex_lock(plMutex))
+ { //Some Posix versions dont support timeout
+#else
+ if (SUCCESS != pthread_mutex_timedlock(plMutex, &abs_timeout))
+ {
+#endif
+ /*TIMM_OSAL_Error("Lock Mutex failed !"); */
+ goto EXIT;
+ }
+ }
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+
+ EXIT:
+ return bReturnStatus;
+/**********************************************************/
+/*return TIMM_OSAL_SemaphoreObtain(pMutex, uTimeOut);*/
+/**********************************************************/
+}
+
+
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_MutexRelease function
+*
+*
+*/
+/* ========================================================================== */
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_MutexRelease(TIMM_OSAL_PTR pMutex)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ pthread_mutex_t *plMutex = (pthread_mutex_t *) pMutex;
+
+ if (TIMM_OSAL_NULL == plMutex)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+
+ if (SUCCESS != pthread_mutex_unlock(plMutex))
+ {
+ /*TIMM_OSAL_Error("Unlock Mutex failed !"); */
+ } else
+ {
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+ }
+ EXIT:
+ return bReturnStatus;
+/**********************************************************/
+/*return TIMM_OSAL_SemaphoreRelease(pMutex);*/
+/**********************************************************/
+}
diff --git a/domx/mm_osal/src/timm_osal_pipes.c b/domx/mm_osal/src/timm_osal_pipes.c
new file mode 100755
index 0000000..1c38354
--- /dev/null
+++ b/domx/mm_osal/src/timm_osal_pipes.c
@@ -0,0 +1,415 @@
+/*
+ * Copyright (c) 2010, Texas Instruments Incorporated
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+* @file timm_osal_pipes.c
+* This file contains methods that provides the functionality
+* for creating/using Nucleus pipes.
+*
+* @path \
+*
+*/
+/* -------------------------------------------------------------------------- */
+/* =========================================================================
+ *!
+ *! Revision History
+ *! ===================================
+ *! 07-Nov-2008 Maiya ShreeHarsha: Linux specific changes
+ *! 0.1: Created the first draft version, ksrini@ti.com
+ * ========================================================================= */
+
+/******************************************************************************
+* Includes
+******************************************************************************/
+
+#include "timm_osal_types.h"
+#include "timm_osal_error.h"
+#include "timm_osal_memory.h"
+#include "timm_osal_trace.h"
+
+#include <unistd.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+
+/**
+* TIMM_OSAL_PIPE structure define the OSAL pipe
+*/
+typedef struct TIMM_OSAL_PIPE
+{
+ int pfd[2];
+ TIMM_OSAL_U32 pipeSize;
+ TIMM_OSAL_U32 messageSize;
+ TIMM_OSAL_U8 isFixedMessage;
+ int messageCount;
+ int totalBytesInPipe;
+} TIMM_OSAL_PIPE;
+
+
+/******************************************************************************
+* Function Prototypes
+******************************************************************************/
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_CreatePipe function
+*
+*
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_CreatePipe(TIMM_OSAL_PTR * pPipe,
+ TIMM_OSAL_U32 pipeSize,
+ TIMM_OSAL_U32 messageSize, TIMM_OSAL_U8 isFixedMessage)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ TIMM_OSAL_PIPE *pHandle = TIMM_OSAL_NULL;
+
+ pHandle =
+ (TIMM_OSAL_PIPE *) TIMM_OSAL_Malloc(sizeof(TIMM_OSAL_PIPE), 0, 0,
+ 0);
+
+ if (TIMM_OSAL_NULL == pHandle)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_ALLOC;
+ goto EXIT;
+ }
+ TIMM_OSAL_Memset(pHandle, 0x0, sizeof(TIMM_OSAL_PIPE));
+
+ pHandle->pfd[0] = -1;
+ pHandle->pfd[1] = -1;
+ if (SUCCESS != pipe(pHandle->pfd))
+ {
+ TIMM_OSAL_Error("Pipe failed: %s!!!", strerror(errno));
+ goto EXIT;
+ }
+
+ pHandle->pipeSize = pipeSize;
+ pHandle->messageSize = messageSize;
+ pHandle->isFixedMessage = isFixedMessage;
+ pHandle->messageCount = 0;
+ pHandle->totalBytesInPipe = 0;
+
+ *pPipe = (TIMM_OSAL_PTR) pHandle;
+
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+
+
+ return bReturnStatus;
+EXIT:
+ TIMM_OSAL_Free(pHandle);
+ return bReturnStatus;
+}
+
+
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_DeletePipe function
+*
+*
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_DeletePipe(TIMM_OSAL_PTR pPipe)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_NONE;
+
+ TIMM_OSAL_PIPE *pHandle = (TIMM_OSAL_PIPE *) pPipe;
+
+ if (TIMM_OSAL_NULL == pHandle)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+
+ if (SUCCESS != close(pHandle->pfd[0]))
+ {
+ TIMM_OSAL_Error("Delete_Pipe Read fd failed!!!");
+ bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ }
+ if (SUCCESS != close(pHandle->pfd[1]))
+ {
+ TIMM_OSAL_Error("Delete_Pipe Write fd failed!!!");
+ bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ }
+
+ TIMM_OSAL_Free(pHandle);
+EXIT:
+ return bReturnStatus;
+}
+
+
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_WriteToPipe function
+*
+*
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_WriteToPipe(TIMM_OSAL_PTR pPipe,
+ void *pMessage, TIMM_OSAL_U32 size, TIMM_OSAL_S32 timeout)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ TIMM_OSAL_U32 lSizeWritten = -1;
+
+ TIMM_OSAL_PIPE *pHandle = (TIMM_OSAL_PIPE *) pPipe;
+
+ if (size == 0)
+ {
+ TIMM_OSAL_Error("0 size!!!");
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+ lSizeWritten = write(pHandle->pfd[1], pMessage, size);
+
+ if (lSizeWritten != size)
+ {
+ TIMM_OSAL_Error("Write of pipe failed!!!");
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+
+ /*Update message count and size */
+ pHandle->messageCount++;
+ pHandle->totalBytesInPipe += size;
+
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+
+ EXIT:
+ return bReturnStatus;
+}
+
+
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_WriteToFrontOfPipe function
+*
+*
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_WriteToFrontOfPipe(TIMM_OSAL_PTR pPipe,
+ void *pMessage, TIMM_OSAL_U32 size, TIMM_OSAL_S32 timeout)
+{
+
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ TIMM_OSAL_U32 lSizeWritten = -1;
+ TIMM_OSAL_U32 lSizeRead = -1;
+ TIMM_OSAL_PIPE *pHandle = (TIMM_OSAL_PIPE *) pPipe;
+ TIMM_OSAL_U8 *tempPtr = NULL;
+
+
+ /*First write to this pipe */
+ if (size == 0)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+
+ lSizeWritten = write(pHandle->pfd[1], pMessage, size);
+
+ if (lSizeWritten != size)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+
+ /*Update number of messages */
+ pHandle->messageCount++;
+
+
+ if (pHandle->messageCount > 1)
+ {
+ /*First allocate memory */
+ tempPtr =
+ (TIMM_OSAL_U8 *) TIMM_OSAL_Malloc(pHandle->
+ totalBytesInPipe, 0, 0, 0);
+
+ if (tempPtr == NULL)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+
+ /*Read out of pipe */
+ lSizeRead =
+ read(pHandle->pfd[0], tempPtr, pHandle->totalBytesInPipe);
+
+ /*Write back to pipe */
+ lSizeWritten =
+ write(pHandle->pfd[1], tempPtr,
+ pHandle->totalBytesInPipe);
+
+ if (lSizeWritten != size)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+
+ /*Update Total bytes in pipe */
+ pHandle->totalBytesInPipe += size;
+ }
+
+
+ EXIT:
+ TIMM_OSAL_Free(tempPtr);
+
+ return bReturnStatus;
+
+}
+
+
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_ReadFromPipe function
+*
+*
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_ReadFromPipe(TIMM_OSAL_PTR pPipe,
+ void *pMessage,
+ TIMM_OSAL_U32 size, TIMM_OSAL_U32 * actualSize, TIMM_OSAL_S32 timeout)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ TIMM_OSAL_U32 lSizeRead = -1;
+ TIMM_OSAL_PIPE *pHandle = (TIMM_OSAL_PIPE *) pPipe;
+
+ if (size == 0)
+ {
+ TIMM_OSAL_Error("nRead size has error!!!");
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+ if ((pHandle->messageCount == 0) && (timeout == TIMM_OSAL_NO_SUSPEND))
+ {
+ /*If timeout is 0 and pipe is empty, return error */
+ TIMM_OSAL_Error("Pipe is empty!!!");
+ bReturnStatus = TIMM_OSAL_ERR_PIPE_EMPTY;
+ goto EXIT;
+ }
+ if ((timeout !=TIMM_OSAL_NO_SUSPEND) &&
+ (timeout != (TIMM_OSAL_S32)TIMM_OSAL_SUSPEND))
+ {
+ TIMM_OSAL_Warning("Only infinite or no timeouts \
+ supported. Going to read with infinite timeout now");
+ }
+ /*read blocks infinitely until message is available */
+ *actualSize = lSizeRead = read(pHandle->pfd[0], pMessage, size);
+ if (0 == lSizeRead)
+ {
+ TIMM_OSAL_Error("EOF reached or no data in pipe!!!");
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+
+ pHandle->messageCount--;
+ pHandle->totalBytesInPipe -= size;
+
+ EXIT:
+ return bReturnStatus;
+
+}
+
+
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_ClearPipe function
+*
+*
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_ClearPipe(TIMM_OSAL_PTR pPipe)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR;
+
+ TIMM_OSAL_Warning("This function is currently not implemented");
+
+ return bReturnStatus;
+}
+
+
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_IsPipeReady function
+*
+*
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_IsPipeReady(TIMM_OSAL_PTR pPipe)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR;
+ TIMM_OSAL_PIPE *pHandle = (TIMM_OSAL_PIPE *) pPipe;
+
+ if (pHandle->messageCount <= 0)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_NOT_READY;
+ } else
+ {
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+ }
+
+ return bReturnStatus;
+
+}
+
+
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_GetPipeReadyMessageCount function
+*
+*
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_GetPipeReadyMessageCount(TIMM_OSAL_PTR pPipe,
+ TIMM_OSAL_U32 * count)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_NONE;
+ TIMM_OSAL_PIPE *pHandle = (TIMM_OSAL_PIPE *) pPipe;
+
+ *count = pHandle->messageCount;
+ return bReturnStatus;
+
+}
diff --git a/domx/mm_osal/src/timm_osal_semaphores.c b/domx/mm_osal/src/timm_osal_semaphores.c
new file mode 100755
index 0000000..b69ee3c
--- /dev/null
+++ b/domx/mm_osal/src/timm_osal_semaphores.c
@@ -0,0 +1,297 @@
+/*
+ * Copyright (c) 2010, Texas Instruments Incorporated
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+* @file timm_osal_semaphores.c
+* This file contains methods that provides the functionality
+*
+* @path \
+*
+*/
+/* -------------------------------------------------------------------------- */
+/* =========================================================================
+ *!
+ *! Revision History
+ *! ===================================
+ *! 30-Oct-2008 Maiya ShreeHarsha: Linux specific changes
+ *! 0.1: Created the first draft version, ksrini@ti.com
+ * ========================================================================= */
+
+/******************************************************************************
+* Includes
+******************************************************************************/
+
+#include <stdio.h>
+
+#include <semaphore.h>
+#include <sys/time.h>
+
+
+#include "timm_osal_types.h"
+#include "timm_osal_trace.h"
+#include "timm_osal_error.h"
+#include "timm_osal_memory.h"
+
+
+#define SEMNAME_MAX 7
+
+/*
+typedef struct TIMM_OSAL_SEMAPHORE {
+ sem_t sem;
+ CHAR name[SEMNAME_MAX];
+} TIMM_OSAL_SEMAPHORE;
+*/
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_SemaphoreCreate function
+*
+*
+*/
+/* ========================================================================== */
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_SemaphoreCreate(TIMM_OSAL_PTR * pSemaphore,
+ TIMM_OSAL_U32 uInitCount)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ *pSemaphore = TIMM_OSAL_NULL;
+
+ sem_t *psem = (sem_t *) TIMM_OSAL_Malloc(sizeof(sem_t), 0, 0, 0);
+
+ if (TIMM_OSAL_NULL == psem)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_ALLOC;
+ goto EXIT;
+ }
+
+ /*Unnamed semaphore */
+ if (SUCCESS != sem_init(psem, 0, uInitCount))
+ {
+ /*TIMM_OSAL_Error("Semaphore Create failed !"); */
+ /*goto EXIT; */
+ } else
+ {
+ *pSemaphore = (TIMM_OSAL_PTR) psem;
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+ }
+ EXIT:
+ if ((TIMM_OSAL_ERR_NONE != bReturnStatus) && (TIMM_OSAL_NULL != psem))
+ {
+ TIMM_OSAL_Free(psem);
+ }
+ return bReturnStatus;
+}
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_SemaphoreDelete function
+*
+*
+*/
+/* ========================================================================== */
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_SemaphoreDelete(TIMM_OSAL_PTR pSemaphore)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_NONE;
+ sem_t *psem = (sem_t *) pSemaphore;
+
+ if (psem == TIMM_OSAL_NULL)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+ /* Release the semaphore. */
+ if (SUCCESS != sem_destroy(psem))
+ {
+ /*TIMM_OSAL_Error("Semaphore Delete failed !"); */
+ bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ }
+
+ TIMM_OSAL_Free(psem);
+ EXIT:
+ return bReturnStatus;
+}
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_SemaphoreObtain function
+*
+*
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_SemaphoreObtain(TIMM_OSAL_PTR pSemaphore,
+ TIMM_OSAL_U32 uTimeOut)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ struct timeval ltime_now;
+ struct timespec abs_timeout;
+ sem_t *psem = (sem_t *) pSemaphore;
+
+ if (psem == TIMM_OSAL_NULL)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+
+ if (TIMM_OSAL_SUSPEND == uTimeOut)
+ {
+ if (SUCCESS != sem_wait(psem))
+ {
+ /*TIMM_OSAL_Error("Semaphore Wait failed !"); */
+ goto EXIT;
+ }
+
+ } else if (TIMM_OSAL_NO_SUSPEND == uTimeOut)
+ {
+ if (SUCCESS != sem_trywait(psem))
+ {
+ /*TIMM_OSAL_Error("Semaphore blocked !"); */
+ goto EXIT;
+ }
+ } else
+ {
+ /*Some delay in calling gettimeofday and sem_timedwait - cant
+ be avoided. Possibility of thread switch after gettimeofday
+ in which case time out will be less than expected */
+ gettimeofday(&ltime_now, NULL);
+ /*uTimeOut is assumed to be in milliseconds */
+ abs_timeout.tv_sec = ltime_now.tv_sec + (uTimeOut / 1000);
+ abs_timeout.tv_nsec =
+ 1000 * (ltime_now.tv_usec + ((uTimeOut % 1000) * 1000));
+
+ if (SUCCESS != sem_timedwait(psem, &abs_timeout))
+ {
+ /*TIMM_OSAL_Error("Semaphore Timed Wait failed !"); */
+ goto EXIT;
+ }
+ }
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+
+ EXIT:
+ return bReturnStatus;
+}
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_SemaphoreRelease function
+*
+*
+*/
+/* ========================================================================== */
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_SemaphoreRelease(TIMM_OSAL_PTR pSemaphore)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ sem_t *psem = (sem_t *) pSemaphore;
+
+ if (TIMM_OSAL_NULL == psem)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+ /* Release the semaphore. */
+ if (SUCCESS != sem_post(psem))
+ {
+ /*TIMM_OSAL_Error("Release failed !"); */
+ } else
+ {
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+ }
+
+ EXIT:
+ return bReturnStatus;
+}
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_SemaphoreReset function
+*
+*
+*/
+/* ========================================================================== */
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_SemaphoreReset(TIMM_OSAL_PTR pSemaphore,
+ TIMM_OSAL_U32 uInitCount)
+{
+ /* TIMM_OSAL_SEMAPHORE *pHandle = (TIMM_OSAL_SEMAPHORE *)pSemaphore;
+ STATUS status;
+ TIMM_OSAL_ERRORTYPE bReturnStatus; */
+
+
+ /* Release the semaphore. */
+ /*status = NU_Reset_Semaphore(&(pHandle->sem),
+ uInitCount);
+ */
+ /* switch(status)
+ {
+ case NU_SUCCESS:
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+ break;
+ default:
+ bReturnStatus = TIMM_OSAL_ERR_CREATE(TIMM_OSAL_ERR, TIMM_OSAL_COMP_SEMAPHORES, status);
+ break;
+ }
+ */
+ /* return bReturnStatus; */
+ return TIMM_OSAL_ERR_UNKNOWN;
+}
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_GetSemaphoreCount function
+*
+*
+*/
+/* ========================================================================== */
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_GetSemaphoreCount(TIMM_OSAL_PTR pSemaphore,
+ TIMM_OSAL_U32 * count)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ int sval = -2; /*value that is not possible */
+ sem_t *psem = (sem_t *) pSemaphore;
+
+ if (TIMM_OSAL_NULL == psem)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+
+ /* Release the semaphore. */
+ if (SUCCESS != sem_getvalue(psem, &sval))
+ {
+ /*TIMM_OSAL_Error("Get Semaphore Count failed !"); */
+ } else
+ {
+ *count = sval;
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+ }
+
+ EXIT:
+ return bReturnStatus;
+}
diff --git a/domx/mm_osal/src/timm_osal_task.c b/domx/mm_osal/src/timm_osal_task.c
new file mode 100755
index 0000000..7a243a9
--- /dev/null
+++ b/domx/mm_osal/src/timm_osal_task.c
@@ -0,0 +1,262 @@
+/*
+ * Copyright (c) 2010, Texas Instruments Incorporated
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+* @file timm_osal_task.c
+* This file contains methods that provides the functionality
+* for creating/destroying tasks.
+*
+* @path \
+*
+*/
+/* -------------------------------------------------------------------------- */
+/* =========================================================================
+ *!
+ *! Revision History
+ *! ===================================
+ *! 21-Oct-2008 Maiya ShreeHarsha: Linux specific changes
+ *! 0.1: Created the first draft version, ksrini@ti.com
+ * ========================================================================= */
+
+/******************************************************************************
+* Includes
+******************************************************************************/
+
+#include <stdio.h>
+#include <pthread.h> /*for POSIX calls */
+#include <sched.h> /*for sched structure */
+#include <unistd.h>
+
+
+
+#include "timm_osal_types.h"
+#include "timm_osal_trace.h"
+#include "timm_osal_error.h"
+#include "timm_osal_memory.h"
+#include "timm_osal_task.h"
+
+
+
+
+/**
+* TIMM_OSAL_TASK describe the different task information
+*/
+typedef struct TIMM_OSAL_TASK
+{
+ pthread_t threadID; /*SHM check */
+ /* To set the priority and stack size */
+ pthread_attr_t ThreadAttr; /*For setting the priority and stack size */
+ /** Name of the task */
+ /* TIMM_OSAL_S8 name[8];*//* eight character plus null char */
+ /** Pointer to the task stack memory */
+/* TIMM_OSAL_PTR stackPtr;*/
+ /** Size of the task stack */
+/* TIMM_OSAL_S32 stackSize;*/
+ /*parameters to the task */
+ TIMM_OSAL_U32 uArgc;
+ TIMM_OSAL_PTR pArgv;
+ /** task priority */
+/* TIMM_OSAL_S32 priority;*/
+ /** flag to check if task got created */
+ TIMM_OSAL_BOOL isCreated;
+} TIMM_OSAL_TASK;
+
+
+/******************************************************************************
+* Function Prototypes
+******************************************************************************/
+
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_CreateTask function
+*
+* @see
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_CreateTask(TIMM_OSAL_PTR * pTask,
+ TIMM_OSAL_TaskProc pFunc,
+ TIMM_OSAL_U32 uArgc,
+ TIMM_OSAL_PTR pArgv,
+ TIMM_OSAL_U32 uStackSize, TIMM_OSAL_U32 uPriority, TIMM_OSAL_S8 * pName)
+{
+
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+ TIMM_OSAL_TASK *pHandle = TIMM_OSAL_NULL;
+ struct sched_param sched;
+ size_t stackSize;
+ *pTask = TIMM_OSAL_NULL;
+
+
+ /*Task structure allocation */
+ pHandle =
+ (TIMM_OSAL_TASK *) TIMM_OSAL_Malloc(sizeof(TIMM_OSAL_TASK), 0, 0,
+ 0);
+ if (pHandle == TIMM_OSAL_NULL)
+ {
+ bReturnStatus = TIMM_OSAL_ERR_ALLOC;
+ goto EXIT;
+ }
+
+ /* Initial cleaning of the task structure */
+ TIMM_OSAL_Memset((TIMM_OSAL_PTR) pHandle, 0, sizeof(TIMM_OSAL_TASK));
+
+ /*Arguments for task */
+ pHandle->uArgc = uArgc;
+ pHandle->pArgv = pArgv;
+
+ pHandle->isCreated = TIMM_OSAL_FALSE;
+
+
+ if (SUCCESS != pthread_attr_init(&pHandle->ThreadAttr))
+ {
+ /*TIMM_OSAL_Error("Task Init Attr Init failed!"); */
+ goto EXIT;
+ }
+ /* Updation of the priority and the stack size */
+
+ if (SUCCESS != pthread_attr_getschedparam(&pHandle->ThreadAttr,
+ &sched))
+ {
+ /*TIMM_OSAL_Error("Task Init Get Sched Params failed!"); */
+ goto EXIT;
+ }
+
+ sched.sched_priority = uPriority; /* relative to the default priority */
+ if (SUCCESS != pthread_attr_setschedparam(&pHandle->ThreadAttr,
+ &sched))
+ {
+ /*TIMM_OSAL_Error("Task Init Set Sched Paramsfailed!"); */
+ goto EXIT;
+ }
+
+ /*First get the default stack size */
+ if (SUCCESS != pthread_attr_getstacksize(&pHandle->ThreadAttr,
+ &stackSize))
+ {
+ /*TIMM_OSAL_Error("Task Init Set Stack Size failed!"); */
+ goto EXIT;
+ }
+
+ /*Check if requested stack size is larger than the current default stack size */
+ if (uStackSize > stackSize)
+ {
+ stackSize = uStackSize;
+ if (SUCCESS != pthread_attr_setstacksize(&pHandle->ThreadAttr,
+ stackSize))
+ {
+ /*TIMM_OSAL_Error("Task Init Set Stack Size failed!"); */
+ goto EXIT;
+ }
+ }
+
+
+
+ if (SUCCESS != pthread_create(&pHandle->threadID,
+ &pHandle->ThreadAttr, pFunc, pArgv))
+ {
+ /*TIMM_OSAL_Error ("Create_Task failed !"); */
+ goto EXIT;
+ }
+
+
+ /* Task was successfully created */
+ pHandle->isCreated = TIMM_OSAL_TRUE;
+ *pTask = (TIMM_OSAL_PTR) pHandle;
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+ /**pTask = (TIMM_OSAL_PTR *)pHandle;*/
+
+ EXIT:
+/* if((TIMM_OSAL_ERR_NONE != bReturnStatus) && (TIMM_OSAL_NULL != pHandle)) {
+ TIMM_OSAL_Free (pHandle->stackPtr);*/
+ if ((TIMM_OSAL_ERR_NONE != bReturnStatus))
+ {
+ TIMM_OSAL_Free(pHandle);
+ }
+ return bReturnStatus;
+
+}
+
+/* ========================================================================== */
+/**
+* @fn TIMM_OSAL_DeleteTask
+*
+* @see
+*/
+/* ========================================================================== */
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_DeleteTask(TIMM_OSAL_PTR pTask)
+{
+ TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_UNKNOWN;
+
+ TIMM_OSAL_TASK *pHandle = (TIMM_OSAL_TASK *) pTask;
+ void *retVal;
+
+ if ((NULL == pHandle) || (TIMM_OSAL_TRUE != pHandle->isCreated))
+ {
+ /* this task was never created */
+ bReturnStatus = TIMM_OSAL_ERR_PARAMETER;
+ goto EXIT;
+ }
+ if (pthread_attr_destroy(&pHandle->ThreadAttr))
+ {
+ /*TIMM_OSAL_Error("Delete_Task failed !"); */
+ goto EXIT;
+ }
+ if (pthread_join(pHandle->threadID, &retVal))
+ {
+ /*TIMM_OSAL_Error("Delete_Task failed !"); */
+ goto EXIT;
+ /* bReturnStatus = TIMM_OSAL_ERR_CREATE(TIMM_OSAL_ERR, TIMM_OSAL_COMP_TASK, status);*//*shm to be done */
+ }
+ bReturnStatus = TIMM_OSAL_ERR_NONE;
+ TIMM_OSAL_Free(pHandle);
+ EXIT:
+ return bReturnStatus;
+}
+
+
+TIMM_OSAL_ERRORTYPE TIMM_OSAL_SleepTask(TIMM_OSAL_U32 mSec)
+{
+ TIMM_OSAL_S32 nReturn = 0;
+
+#ifdef _POSIX_VERSION_1_
+ usleep(1000 * mSec);
+#else
+ nReturn = usleep(1000 * mSec);
+#endif
+ if (nReturn == 0)
+ return TIMM_OSAL_ERR_NONE;
+ else
+ return TIMM_OSAL_ERR_UNKNOWN;
+}
diff --git a/domx/mm_osal/src/timm_osal_trace.c b/domx/mm_osal/src/timm_osal_trace.c
new file mode 100755
index 0000000..498054f
--- /dev/null
+++ b/domx/mm_osal/src/timm_osal_trace.c
@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) 2010, Texas Instruments Incorporated
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+* @file timm_osal_trace.c
+* This file contains methods that provides the functionality
+* for logging errors/warings/information/etc.
+*
+* @path \
+*
+*/
+/* -------------------------------------------------------------------------- */
+/* =========================================================================
+ *!
+ *! Revision History
+ *! ===================================
+ *!
+ * ========================================================================= */
+
+/******************************************************************************
+* Includes
+******************************************************************************/
+
+/*#include "typedefs.h"*/
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "timm_osal_trace.h"
+
+#ifdef _Android
+#define LOG_TAG "DOMX"
+#include <utils/Log.h>
+#include <cutils/properties.h>
+#endif
+
+/**
+* The OSAL debug trace detail can be set at compile time by defining the flag
+* TIMM_OSAL_DEBUG_TRACE_DETAIL=<Details>
+* detail - 0 - no detail
+* 1 - function name
+* 2 - function name, line number
+* Prefix is added to every debug trace message
+*/
+#ifndef TIMM_OSAL_DEBUG_TRACE_DETAIL
+#define TIMM_OSAL_DEBUG_TRACE_DETAIL 2
+#endif
+
+#define DEFAULT_TRACE_LEVEL TIMM_OSAL_TRACE_LEVEL_ERROR
+
+static int trace_level = -1;
+
+/* strip out leading ../ stuff that happens to __FILE__ for out-of-tree builds */
+static const char *simplify_path(const char *file)
+{
+ while (file)
+ {
+ char c = file[0];
+ if ((c != '.') && (c != '/') && (c != '\\'))
+ break;
+ file++;
+ }
+ return file;
+}
+
+void TIMM_OSAL_UpdateTraceLevel(void)
+{
+ char *val = getenv("TIMM_OSAL_DEBUG_TRACE_LEVEL");
+
+ if (val)
+ {
+ trace_level = strtol(val, NULL, 0);
+ }
+ else
+ {
+#ifdef _Android
+ char value[PROPERTY_VALUE_MAX];
+ int val;
+
+ property_get("debug.domx.trace_level", value, "0");
+ val = atoi(value);
+ if ( (!val) || (val < 0) )
+ {
+ trace_level = DEFAULT_TRACE_LEVEL;
+ }
+ else
+ trace_level = val;
+#else
+ trace_level = DEFAULT_TRACE_LEVEL;
+#endif
+ }
+}
+
+void __TIMM_OSAL_TraceFunction(const __TIMM_OSAL_TRACE_LOCATION * loc,
+ const char *fmt, ...)
+{
+ if (trace_level == -1)
+ {
+ char *val = getenv("TIMM_OSAL_DEBUG_TRACE_LEVEL");
+ trace_level =
+ val ? strtol(val, NULL, 0) : DEFAULT_TRACE_LEVEL;
+ }
+
+ if (trace_level >= loc->level)
+ {
+ va_list ap;
+
+ va_start(ap, fmt); /* make ap point to first arg after 'fmt' */
+
+#ifdef _Android
+
+#if 0 // Original for reference
+#if ( TIMM_OSAL_DEBUG_TRACE_DETAIL > 1 )
+ ALOGD("%s:%d\t%s()\t", simplify_path(loc->file), loc->line,
+ loc->function);
+#endif
+#else // Prints function_name for ERROR, WARNING and ENTRY/EXIT
+ if ( (loc->level == TIMM_OSAL_TRACE_LEVEL_ERROR) || (loc->level == TIMM_OSAL_TRACE_LEVEL_WARNING) || (loc->level == TIMM_OSAL_TRACE_LEVEL_ENTERING) )
+ ALOGD("%s:%d\t%s()\t", simplify_path(loc->file), loc->line,
+ loc->function);
+#endif
+
+ char string[1000];
+ vsprintf(string, fmt, ap);
+ ALOGD("%s",string);
+
+#else
+
+#if 0 // Original for reference
+#if ( TIMM_OSAL_DEBUG_TRACE_DETAIL > 1 )
+ printf("%s:%d\t%s()\t", simplify_path(loc->file), loc->line,
+ loc->function);
+#endif
+#else // Prints function_name for ERROR, WARNING and ENTRY/EXIT
+ if ( (loc->level == 1) || (loc->level == 2) || (loc->level == 5) )
+ printf("%s:%d\t%s()\t", simplify_path(loc->file), loc->line,
+ loc->function);
+#endif
+
+ vprintf(fmt, ap);
+
+#endif
+
+ va_end(ap);
+ }
+}