HwSpinLock: Pull in the ti.gates.hwspinlock module from omapzoom sysbios-rpmsg.
authorG Anthony <a0783926@ti.com>
Thu, 28 Feb 2013 02:26:34 +0000 (18:26 -0800)
committerG Anthony <a0783926@ti.com>
Thu, 28 Feb 2013 02:26:34 +0000 (18:26 -0800)
This is custom: can it be merged with the HWSpinLock in IPC tree?

Signed-off-by: G Anthony <a0783926@ti.com>
packages/ti/gates/hwspinlock/HwSpinlock.c [new file with mode: 0644]
packages/ti/gates/hwspinlock/HwSpinlock.h [new file with mode: 0644]
packages/ti/gates/hwspinlock/_HwSpinlock.h [new file with mode: 0644]
packages/ti/gates/hwspinlock/package.bld [new file with mode: 0644]
packages/ti/gates/hwspinlock/package.xdc [new file with mode: 0644]
packages/ti/gates/hwspinlock/package.xs [new file with mode: 0644]

diff --git a/packages/ti/gates/hwspinlock/HwSpinlock.c b/packages/ti/gates/hwspinlock/HwSpinlock.c
new file mode 100644 (file)
index 0000000..d662f83
--- /dev/null
@@ -0,0 +1,286 @@
+/*
+ * Copyright (c) 2011-2013, 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.
+ */
+/*
+ *  ======== HwSpinlock.c ========
+ */
+
+#include <xdc/std.h>
+#include <xdc/runtime/Assert.h>
+#include <xdc/runtime/Error.h>
+#include <xdc/runtime/Memory.h>
+#include <xdc/runtime/IGateProvider.h>
+#include <xdc/runtime/Log.h>
+#include <xdc/runtime/Diags.h>
+#include <xdc/runtime/Gate.h>
+
+#include <ti/sysbios/knl/Task.h>
+#include <ti/sysbios/knl/Clock.h>
+
+#include <ti/gates/hwspinlock/HwSpinlock.h>
+#include "_HwSpinlock.h"
+
+
+static HwSpinlock_Module_State HwSpinlock_module = { 0 };
+
+/* Exposed to the Host side to reset hwspinlock if needed */
+Bits32 ti_gates_HwSpinlock_sharedState
+                            [(HwSpinlock_NUMLOCKS/sizeof(Bits32))] = { 0 };
+const UInt32 ti_gates_HwSpinlock_numLocks = HwSpinlock_NUMLOCKS;
+
+
+/* Helper functions to set and reset status of a lock */
+inline Void _HwSpinlock_set(Int hwlockId)
+{
+    ti_gates_HwSpinlock_sharedState[hwlockId >> 5] |= (1 << (hwlockId % 32));
+}
+
+inline Void _HwSpinlock_clr(Int hwlockId)
+{
+    ti_gates_HwSpinlock_sharedState[hwlockId >> 5] &= ~(1 << (hwlockId % 32));
+}
+
+/*
+ *************************************************************************
+ *                       Instance functions
+ *************************************************************************
+ */
+
+/*
+ *  ======== HwSpinlock_Params_init ========
+ */
+Void HwSpinlock_Params_init(HwSpinlock_Params *params)
+{
+    params->id = HwSpinlock_NO_SPINLOCK;
+    params->reqFxn= NULL;
+    params->relFxn= NULL;
+    params->arg1 = NULL;
+    params->arg2 = NULL;
+}
+
+/*
+ *  ======== HwSpinlock_create ========
+ */
+#define FXNN "HwSpinlock_create"
+HwSpinlock_Handle HwSpinlock_create(HwSpinlock_Params *params)
+{
+    HwSpinlock_Handle handle;
+    Int i;
+    IArg key;
+
+    /* Call request hook fxn, return (NULL handle) if the hook fxn fails */
+    if (params->reqFxn) {
+        if (params->reqFxn(params)) {
+            return NULL;
+        }
+    }
+
+    /* Check for a valid hwspinlock id */
+    if ((params->id < 0) || (params->id >= HwSpinlock_NUMLOCKS)) {
+        Log_error0(FXNN": HwSpinlock Id is not valid");
+        return NULL;
+    }
+
+    /* Return handle if already created */
+    key = Gate_enterSystem();
+    handle = HwSpinlock_module.locks[params->id];
+    if (handle) {
+        handle->refCnt++;
+        Gate_leaveSystem(key);
+        return handle;
+    }
+
+    /* Allocate handle */
+    handle = Memory_alloc(NULL, sizeof(*handle), 0, NULL);
+    if (!handle) {
+        Log_error0(FXNN": Unable to allocate handle");
+        Gate_leaveSystem(key);
+        return NULL;
+    }
+
+    /* Create the preemption gates */
+    for (i = 0; i < HwSpinlock_NUMPREEMPTGATES; i++) {
+        handle->preemptGates[i] = (IGateProvider_Handle)
+                                    HwSpinlock_GateFxns[i].create(NULL, NULL);
+    }
+    /* Create the local gate */
+    handle->mutex = GateMutexPri_create(NULL, NULL);
+
+    /* Store private info in the handle */
+    handle->params = *params;
+    handle->baseAddr = (volatile UInt32 *)HwSpinlock_BASEADDR;
+    handle->refCnt = 1;
+    handle->state = HwSpinlock_STATE_FREE;
+
+    /* Store the created handle */
+    HwSpinlock_module.locks[params->id] = handle;
+    Gate_leaveSystem(key);
+
+    return handle;
+}
+#undef FXNN
+
+/*
+ *  ======== HwSpinlock_delete ========
+ */
+#define FXNN "HwSpinlock_delete"
+Int HwSpinlock_delete(HwSpinlock_Handle handle)
+{
+    Int i;
+    IArg key;
+
+    Assert_isTrue(handle, NULL);
+    key = Gate_enterSystem();
+
+    /* Decrement reference counter */
+    if (handle->refCnt) {
+        handle->refCnt--;
+    }
+
+    if (!handle->refCnt) {
+        /* Return error if trying to delete before unlock */
+        if (handle->state == HwSpinlock_STATE_TAKEN) {
+            Log_error0(FXNN": Error: HwSpinlock still in use");
+            Gate_leaveSystem(key);
+            return HwSpinlock_STILL_IN_USE;
+        }
+        /* Call release hook fxn if exists */
+        if (handle->params.relFxn) {
+            handle->params.relFxn(&handle->params);
+         }
+
+        /* Delete and reset the preemption gates */
+        for (i = 0; i < HwSpinlock_NUMPREEMPTGATES; i++) {
+            HwSpinlock_GateFxns[i].delete(&handle->preemptGates[i]);
+            handle->preemptGates[i] = NULL;
+        }
+        /* Delete and reset the local gate */
+        GateMutexPri_delete(&handle->mutex);
+        handle->mutex = NULL;
+
+        /* Remove the handle from the module */
+        HwSpinlock_module.locks[handle->params.id] = NULL;
+
+        /* Release the allocated memory for the handle */
+        Memory_free(NULL, handle, sizeof(*handle));
+        handle = NULL;
+    }
+    Gate_leaveSystem(key);
+
+    return HwSpinlock_S_SUCCESS;
+}
+#undef FXNN
+
+/*
+ *  ======== HwSpinlock_enter ========
+ */
+Int HwSpinlock_enter(HwSpinlock_Handle handle, HwSpinlock_PreemptGate pType,
+                     UInt timeout, HwSpinlock_Key *hkey)
+{
+    UInt start, elapsed;
+
+    Assert_isTrue(handle, NULL);
+
+    /* Store Start TimeStamp */
+    if (timeout != HwSpinlock_WAIT_FOREVER) {
+        start = Clock_getTicks();
+    }
+
+    while(1) {
+        /* Enter the localGate protection */
+        handle->mkey = GateMutexPri_enter(handle->mutex);
+
+        /* Try to get the hwspinlock */
+        if (handle->baseAddr[handle->params.id] == 0) {
+            handle->state = HwSpinlock_STATE_TAKEN;
+            /* Disable preemption of pType and store the type in handle */
+            hkey->key = IGateProvider_enter(handle->preemptGates[pType]);
+            hkey->valid = TRUE;
+            handle->pType = pType;
+            _HwSpinlock_set(handle->params.id);
+            return (HwSpinlock_S_SUCCESS);
+        }
+
+        /* If is already taken undo localGate protection */
+        GateMutexPri_leave(handle->mutex, handle->mkey);
+
+        /* Check if timeout has elapsed */
+        if (timeout != HwSpinlock_WAIT_FOREVER) {
+            elapsed = Clock_getTicks() - start;
+            if (elapsed > timeout) {
+                /* Mark key as invalid */
+                hkey->valid = FALSE;
+                return (HwSpinlock_E_TIMEOUT);
+            }
+        }
+    }
+}
+
+/*
+ *  ======== HwSpinlock_leave ========
+ */
+Void HwSpinlock_leave(HwSpinlock_Handle handle, HwSpinlock_Key *hkey)
+{
+    Assert_isTrue(handle, NULL);
+
+    /* Only unlock hwspinlock if it was really acquired and isa valid key */
+    if (handle->state == HwSpinlock_STATE_TAKEN && hkey->valid) {
+       /* Leave the spinlock */
+        handle->baseAddr[handle->params.id] = 0;
+        handle->state = HwSpinlock_STATE_FREE;
+        _HwSpinlock_clr(handle->params.id);
+
+        /* Restore Preemption of pType */
+        IGateProvider_leave(handle->preemptGates[handle->pType], hkey->key);
+        hkey->valid = FALSE;
+
+        /* Leave the mutex */
+        GateMutexPri_leave(handle->mutex, handle->mkey);
+    }
+}
+
+/*
+ *  ======== HwSpinlock_getId ========
+ */
+Int HwSpinlock_getId(HwSpinlock_Handle handle)
+{
+    Assert_isTrue(handle, NULL);
+    return (handle->params.id);
+}
+
+/*
+ *  ======== HwSpinlock_getState ========
+ */
+HwSpinlock_State HwSpinlock_getState(HwSpinlock_Handle handle)
+{
+    Assert_isTrue(handle, NULL);
+    return (handle->state);
+}
diff --git a/packages/ti/gates/hwspinlock/HwSpinlock.h b/packages/ti/gates/hwspinlock/HwSpinlock.h
new file mode 100644 (file)
index 0000000..074b32b
--- /dev/null
@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 2011-2013, 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.
+ */
+
+#ifndef ti_gates_HwSpinlock__include
+#define ti_gates_HwSpinlock__include
+
+#if defined (__cplusplus)
+extern "C" {
+#endif
+
+extern UInt32 ti_gates_HwSpinlock_sharedState[];
+extern const UInt32 ti_gates_HwSpinlock_numLocks;
+
+/* =============================================================================
+ *  All success and failure codes for the module
+ * =============================================================================
+ */
+
+/*!
+ *  @def    HwSpinlock_S_SUCCESS
+ *  @brief  Operation is successful.
+ */
+#define HwSpinlock_S_SUCCESS            0
+
+/*!
+ *  @def    HwSpinlock_NO_SPINLOCK
+ *  @brief  Not hwspinlock Id associated to the obj.
+ */
+#define HwSpinlock_NO_SPINLOCK         -1
+
+/*!
+ *  @def    HwSpinlock_E_FAIL
+ *  @brief  Generic failure.
+ */
+#define HwSpinlock_E_FAIL              -2
+
+/*!
+ *  @def    HwSpinlock_E_TIMEOUT
+ *  @brief  Operation timed out.
+ */
+#define HwSpinlock_E_TIMEOUT           -3
+
+/*!
+ *  @def    HwSpinlock_STILL_IN_USE
+ *  @brief  handle is still in use..
+ */
+#define HwSpinlock_STILL_IN_USE        -4
+
+/*!
+ *  @def    HwSpinlock_WAIT_FOREVER
+ *  @brief  Use as a NOT timeout option.
+ */
+#define HwSpinlock_WAIT_FOREVER        0xFFFFFFFF
+
+
+/* =============================================================================
+ *  Structures & Enums
+ * =============================================================================
+ */
+
+/*!
+ *  @brief  HwSpinlock state
+ */
+typedef enum {
+    HwSpinlock_STATE_FREE,
+    HwSpinlock_STATE_TAKEN
+} HwSpinlock_State;
+
+/*!
+ *  @brief  A set of local context protection levels
+ *          - HwSpinlock_PreemptGate_HWI  -> GateHwi: disables interrupts
+ *          - HwSpinlock_PreemptGate_SWI  -> GateSwi: disables Swi's (software interrupts)
+ *          - HwSpinlock_PreemptGate_TASK -> GateTask: disables Task's preemption
+ */
+typedef enum HwSpinlock_PreemptGate {
+    HwSpinlock_PreemptGate_NONE   = 0,  /* Use no local protection */
+    HwSpinlock_PreemptGate_HWI    = 1,  /* Use the INTERRUPT local protection level */
+    HwSpinlock_PreemptGate_SWI    = 2,  /* Use the SWI local protection level */
+    HwSpinlock_PreemptGate_TASK   = 3   /* Use the TASK local protection level */
+} HwSpinlock_PreemptGate;
+
+typedef Void * (*HwSpinlock_hookFxn)(Void *);
+
+/*!
+ *  @brief  HwSpinlock_Params
+ */
+typedef struct HwSpinlock_Params {
+    Int                   id;
+    HwSpinlock_hookFxn    reqFxn;
+    HwSpinlock_hookFxn    relFxn;
+    Void                  *arg1;
+    Void                  *arg2;
+} HwSpinlock_Params;
+
+/*!
+ *  @brief  HwSpinlock_Key
+ */
+typedef struct HwSpinlock_Key {
+    IArg key;
+    Bool valid;
+} HwSpinlock_Key;
+
+/*!
+ *  @brief  HwSpinlock_Handle type
+ */
+typedef struct HwSpinlock_Object *HwSpinlock_Handle;
+
+
+/* =============================================================================
+ *  HwSpinlock Interface Functions
+ * =============================================================================
+ */
+
+/*!
+ *  @brief      HwSpinlock_Params_init
+ *
+ *  @param[in]  HwSpinlock_Params
+ *
+ *  @return     Void
+ */
+Void HwSpinlock_Params_init(HwSpinlock_Params *params);
+
+/*!
+ *  @brief      Create spinlock
+ *
+ *  @param[in]  resourceId, baseAddr
+ *
+ *  @return     HwSpinlock_Handle
+ */
+HwSpinlock_Handle HwSpinlock_create(HwSpinlock_Params *params);
+
+/*!
+*  @brief      HwSpinlock_delete
+*
+*  @param[in]  HwSpinlock_Handle
+*
+*  @return     Status
+*/
+Int HwSpinlock_delete(HwSpinlock_Handle handle);
+
+/*!
+ *  @brief      Enter/Acquire the HwSpinlock
+ *
+ *  @param[in]  timeout, local protecttion option
+ *
+ *  @return     Status
+ */
+Int HwSpinlock_enter(HwSpinlock_Handle handle, HwSpinlock_PreemptGate pType,
+                     UInt timeout, HwSpinlock_Key *key);
+
+/*!
+ *  @brief      Leave the HwSpinlock
+ *
+ *  @param[in]  HwSpinlock handle
+ *
+ *  @return     Void
+ */
+Void HwSpinlock_leave(HwSpinlock_Handle handle, HwSpinlock_Key *key);
+
+/*!
+ *  @brief      HwSpinlock_getId
+ *
+ *  @param[in]  HwSpinlock handle
+ *
+ *  @return     Spinlock Id
+ */
+Int HwSpinlock_getId(HwSpinlock_Handle handle);
+
+/*!
+ *  @brief      HwSpinlock_getState
+ *
+ *  @param[in]  HwSpinlock handle
+ *
+ *  @return     Current State
+ */
+HwSpinlock_State HwSpinlock_getState(HwSpinlock_Handle handle);
+
+#if defined (__cplusplus)
+}
+#endif /* defined (__cplusplus) */
+
+#endif /* ti_gates_HwSpinlock__include */
diff --git a/packages/ti/gates/hwspinlock/_HwSpinlock.h b/packages/ti/gates/hwspinlock/_HwSpinlock.h
new file mode 100644 (file)
index 0000000..579ea25
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2011-2013, 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       _HwSpinlock.h
+ *  ============================================================================
+ */
+
+#ifndef ti_gates__HwSpinlock__include
+#define ti_gates__HwSpinlock__include
+
+#if defined (__cplusplus)
+extern "C" {
+#endif
+
+#include <xdc/runtime/GateNull.h>
+#include <ti/sysbios/gates/GateMutexPri.h>
+#include <ti/sysbios/gates/GateHwi.h>
+#include <ti/sysbios/gates/GateSwi.h>
+#include <ti/sysbios/gates/GateTask.h>
+
+
+/* =============================================================================
+ *  Structures & Definitions
+ * =============================================================================
+ */
+
+typedef Void * (*HwSpinlock_createFxn)(IGateProvider_Params *, Error_Block *);
+typedef Void * (*HwSpinlock_deleteFxn)(IGateProvider_Handle *);
+
+/*!
+ *  @brief  HwSpinlock_PreemptGateFxn
+ */
+typedef struct {
+    HwSpinlock_createFxn create;
+    HwSpinlock_deleteFxn delete;
+} HwSpinlock_PreemptGateFxn;
+
+/*!
+ *  @brief HwSpinlock GateFxns
+ */
+HwSpinlock_PreemptGateFxn HwSpinlock_GateFxns[] = {
+    {(HwSpinlock_createFxn)GateNull_create,
+                                        (HwSpinlock_deleteFxn)GateNull_delete},
+    {(HwSpinlock_createFxn)GateHwi_create,
+                                        (HwSpinlock_deleteFxn)GateHwi_delete},
+    {(HwSpinlock_createFxn)GateSwi_create,
+                                        (HwSpinlock_deleteFxn)GateSwi_delete},
+    {(HwSpinlock_createFxn)GateTask_create,
+                                        (HwSpinlock_deleteFxn)GateTask_delete},
+};
+
+#ifdef DSPC674
+#define HwSpinlock_NUMLOCKS         128
+#define HwSpinlock_BASEADDR         0x480CA800
+#else
+#define HwSpinlock_NUMLOCKS         32
+#ifdef DSP
+#define HwSpinlock_BASEADDR         0x4A0F6800
+#else
+#define HwSpinlock_BASEADDR         0xAA0F6800
+#endif
+#endif
+#define HwSpinlock_NUMPREEMPTGATES  (sizeof(HwSpinlock_GateFxns) / \
+                                        sizeof(HwSpinlock_PreemptGateFxn))
+
+
+/*!
+ *  @brief  HwSpinlock_Module_State type
+ */
+typedef struct {
+    HwSpinlock_Handle        locks[HwSpinlock_NUMLOCKS];
+} HwSpinlock_Module_State;
+
+/*!
+ *  @brief  HwSpinlock_Object type
+ */
+struct HwSpinlock_Object {
+    HwSpinlock_Params        params;
+    volatile UInt32          *baseAddr;
+    Int                      lockNum;   /* The lock number being used */
+    HwSpinlock_PreemptGate   pType;
+    IArg                     mkey;
+    IGateProvider_Handle     preemptGates[HwSpinlock_NUMPREEMPTGATES];
+    GateMutexPri_Handle      mutex;
+    Int                      refCnt;
+    HwSpinlock_State         state;
+};
+
+#if defined (__cplusplus)
+}
+#endif /* defined (__cplusplus) */
+
+#endif /* ti_gates__HwSpinlock__include */
diff --git a/packages/ti/gates/hwspinlock/package.bld b/packages/ti/gates/hwspinlock/package.bld
new file mode 100644 (file)
index 0000000..e78e8b7
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2011-2013, 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.
+ */
+
+/*
+ *  ======== package.bld ========
+ *
+ */
+
+/* explicit references to global objects */
+var Build = xdc.useModule('xdc.bld.BuildEnvironment');
+var Pkg = xdc.useModule('xdc.bld.PackageContents');
+var smpBuild = java.lang.System.getenv("BUILD_SMP");
+
+/* clean lib folder */
+Pkg.generatedFiles.$add("lib/");
+Pkg.libDir = "package/";
+
+/* add custom files to all releases */
+Pkg.attrs.exportSrc = false;
+Pkg.attrs.exportCfg = true;
+
+/* list of libraries to build */
+var libArray = new Array();
+if (smpBuild == "1") {
+    /* ti.gates.hwspinlock library for IPU SMP target */
+    libArray.push(
+        {
+            name: "ti.gates.hwspinlock_smp",
+            sources: [
+                "HwSpinlock"
+            ],
+            libAttrs: {
+                defs: " -DM3_ONLY -DSMP"
+            },
+            isas: [ "v7M" ],
+        }
+    );
+}
+else {
+    /* ti.gates.hwspinlock library for IPU non-SMP target */
+    libArray.push(
+        {
+            name: "ti.gates.hwspinlock",
+            sources: [
+                "HwSpinlock",
+            ],
+            libAttrs: {
+                defs: " -DM3_ONLY"
+            },
+            isas: [ "v7M" ],
+        }
+    );
+
+    /* ti.gates.hwspinlock library for DSP target */
+    libArray.push(
+        {
+            name: "ti.gates.hwspinlock",
+            sources: [
+                "HwSpinlock",
+            ],
+            libAttrs: {
+                defs: " -DDSP"
+            },
+            isas: [ "64T" ],
+        }
+    );
+
+    /* ti.gates.hwspinlock library for DSP target */
+    libArray.push(
+        {
+            name: "ti.gates.hwspinlock",
+            sources: [
+                "HwSpinlock",
+            ],
+            libAttrs: {
+                defs: " -DDSPC674"
+            },
+            isas: [ "674" ],
+        }
+    );
+}
+
+/* generate the package libraries */
+/* check if profile specified in XDCARGS */
+/* XDCARGS="... profile=debug ..." */
+var cmdlProf = (" " + arguments.join(" ") + " ").match(/ profile=([^ ]+) /);
+cmdlProf = cmdlProf != null ? cmdlProf[1] : null;
+
+/* ==== loop over array of libraries ==== */
+for (var i = 0; i < libArray.length; i++) {
+    var lib = libArray[i];
+
+    /* ==== loop over all targets in build array ==== */
+    for (var j = 0; j < Build.targets.length; j++) {
+        var targ = Build.targets[j];
+
+        /* skip target if not compatible with source code */
+        if ("icw" in lib) {
+            var skipTarget = true;
+            var targIsaChain = "/" + targ.getISAChain().join("/") + "/";
+            for (var k = 0; k < lib.icw.length; k++) {
+                if (targIsaChain.match("/" + lib.icw[k] + "/")) {
+                    skipTarget = false;
+                    break;
+                }
+            }
+            if (skipTarget) continue;
+        }
+
+        /* skip target if it does not generate code for the given isa */
+        if ("isas" in lib) {
+            var skipTarget = true;
+            var list = "/" + lib.isas.join("/") + "/";
+            if (list.match("/" + targ.isa + "/")) {
+                skipTarget = false;
+            }
+            if (skipTarget) continue;
+        }
+
+        /* ==== loop over all profiles ==== */
+        for (var profile in targ.profiles) {
+
+            /* skip profile if different than specified on command line */
+            if ((cmdlProf != null) && (profile != cmdlProf)) {
+                continue;
+            }
+
+            /* name = lib/profile/name.a+suffix */
+            var name = "lib/" + profile + "/" + lib.name;
+
+            /* pass along library attributes specified in library array */
+            var libAttrs = "libAttrs" in lib ? lib.libAttrs : {};
+
+            /* must set profile explicitly */
+            libAttrs.profile = profile;
+
+            /* build the library */
+            var library = Pkg.addLibrary(name, targ, libAttrs);
+
+            /* add the source files */
+            library.addObjects(lib.sources);
+        }
+    }
+}
diff --git a/packages/ti/gates/hwspinlock/package.xdc b/packages/ti/gates/hwspinlock/package.xdc
new file mode 100644 (file)
index 0000000..5c873e5
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2011-2013, 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.
+ */
+/*
+ *  ======== package.xdc ========
+ *
+ */
+
+/*!
+ *  ======== ti.gates.hwspinlock ========
+ *  HW SpinLock support
+ *
+ *  Contains modules that are OS independent and support
+ *  using HW Spinlocks between processors.
+ *
+ */
+
+package ti.gates.hwspinlock [1,0,0,0] {
+}
diff --git a/packages/ti/gates/hwspinlock/package.xs b/packages/ti/gates/hwspinlock/package.xs
new file mode 100644 (file)
index 0000000..34a1cc3
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2011-2013, 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.
+ */
+
+/*
+ *  ======== package.xs ========
+ *
+ */
+
+/*
+ *  ======== useModules ========
+ */
+xdc.useModule('xdc.runtime.GateNull');
+xdc.useModule('ti.sysbios.gates.GateTask');
+xdc.useModule('ti.sysbios.gates.GateSwi');
+xdc.useModule('ti.sysbios.gates.GateHwi');
+
+/*
+ *  ======== getLibs ========
+ */
+function getLibs(prog)
+{
+    var suffix;
+    var file;
+    var libAry = [];
+    var profile = this.profile;
+    var smp = "";
+
+    suffix = prog.build.target.findSuffix(this);
+    if (suffix == null) {
+        return "";  /* nothing to contribute */
+    }
+
+    if (prog.platformName.match(/ipu/)) {
+        smp = "_smp";
+    }
+
+    /* make sure the library exists, else fallback to a built library */
+    file = "lib/" + profile + "/ti.gates.hwspinlock" + smp +".a" + suffix;
+    if (java.io.File(this.packageBase + file).exists()) {
+        libAry.push(file);
+    }
+    else {
+        file = "lib/release/ti.gates.hwspinlock" + smp + ".a" + suffix;
+        if (java.io.File(this.packageBase + file).exists()) {
+            libAry.push(file);
+        }
+        else {
+            /* fallback to a compatible library built by this package */
+            for (var p in this.build.libDesc) {
+                if (suffix == this.build.libDesc[p].suffix) {
+                    libAry.push(p);
+                    break;
+                }
+            }
+        }
+    }
+
+    return libAry.join(";");
+}