]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/commitdiff
Added transport factory to remove circular dependency
authorRamsey Harris <ramsey@ti.com>
Wed, 21 Jan 2015 01:14:27 +0000 (17:14 -0800)
committerRobert Tivy <rtivy@ti.com>
Wed, 21 Jan 2015 22:24:40 +0000 (14:24 -0800)
There was a circular dependency between the ipc and transport
libraries. To break this circle, moved the transport create
method into a factory. Ipc invokes the factory methods through
a function table configured with a new Ipc_transportConfig
method called by the application. Renamed transport library to
follow our naming conventions: libtitransportrpmsg.

13 files changed:
linux/include/TransportRpmsg.h
linux/src/api/Ipc.c
linux/src/tests/Makefile.am
linux/src/tests/MessageQApp.c
linux/src/tests/MessageQBench.c
linux/src/tests/MessageQMulti.c
linux/src/tests/MessageQMultiMulti.c
linux/src/tests/Msgq100.c
linux/src/tests/main_host.c
linux/src/tests/nano_test.c
linux/src/transport/Makefile.am
linux/src/transport/TransportRpmsg.c
packages/ti/ipc/Ipc.h

index ed2aa7d27ce4c1f76965dc01b898c7a52f0d7c70..83a5050037b59d38e077e5b140d887747ce0b7c1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Texas Instruments Incorporated
+ * Copyright (c) 2014-2015 Texas Instruments Incorporated - http://www.ti.com
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -50,8 +50,11 @@ extern "C" {
 #endif
 
 #include <ti/ipc/Std.h>
+#include <ti/ipc/Ipc.h>
 #include <IMessageQTransport.h>
 
+extern Ipc_TransportFactoryFxns TransportRpmsg_Factory;
+
 struct TransportRpmsg_Params {
     UInt16 rprocId;
 };
index f2c9457b03b4e90b4805e2ef596811126035a6f2..9dfb176879a3c344c92e152ac189af726b1f00ed 100644 (file)
@@ -47,8 +47,6 @@
 #include <ti/ipc/Std.h>
 #include <ti/ipc/Ipc.h>
 #include <ti/ipc/NameServer.h>
-#include <IMessageQTransport.h>
-#include <TransportRpmsg.h>
 
 /* User side headers */
 #include <ladclient.h>
@@ -63,8 +61,9 @@
 
 /* module definition */
 typedef struct {
-    Int                 refCount;
-    pthread_mutex_t     gate;
+    Int                         refCount;
+    pthread_mutex_t             gate;
+    Ipc_TransportFactoryFxns   *transportFactory;
 } Ipc_Module;
 
 
@@ -73,8 +72,9 @@ typedef struct {
  * =============================================================================
  */
 static Ipc_Module Ipc_module = {
-    .refCount   = 0,
-    .gate       = PTHREAD_MUTEX_INITIALIZER
+    .refCount           = 0,
+    .gate               = PTHREAD_MUTEX_INITIALIZER,
+    .transportFactory   = NULL
 };
 
 GateHWSpinlock_Config _GateHWSpinlock_cfgParams;
@@ -93,22 +93,13 @@ static void cleanup(int arg);
  */
 Int Ipc_start(Void)
 {
-    TransportRpmsg_Handle  transport;
-    TransportRpmsg_Params  params;
-    IMessageQTransport_Handle iMsgQTrans;
-    MessageQ_Config        msgqCfg;
-    MultiProc_Config       mpCfg;
+    MessageQ_Config         msgqCfg;
+    MultiProc_Config        mpCfg;
 #if defined(GATEMP_SUPPORT)
-    GateHWSpinlock_Config  gateHWCfg;
+    GateHWSpinlock_Config   gateHWCfg;
 #endif
-    Int                    attachStatus;
-    Int32                  status;
-    LAD_Status             ladStatus;
-    Int                    i;
-    UInt16                 procId;
-    Int32                  attachedAny;
-    UInt16                 clusterSize;
-    UInt16                 clusterBase;
+    Int         status;
+    LAD_Status  ladStatus;
 
     /* function must be serialized */
     pthread_mutex_lock(&Ipc_module.gate);
@@ -119,6 +110,12 @@ Int Ipc_start(Void)
         goto exit;
     }
 
+    /* make sure transport factory has been configured */
+    if (Ipc_module.transportFactory == NULL) {
+        status = Ipc_E_INVALIDSTATE;
+        goto exit;
+    }
+
     /* Catch ctrl-C, and cleanup: */
     (void) signal(SIGINT, cleanup);
 
@@ -176,42 +173,11 @@ Int Ipc_start(Void)
         MessageQ_getConfig(&msgqCfg);
         MessageQ_setup(&msgqCfg);
 
-        /*  Attach to all remote processors. For now, must attach to
-         *  at least one to tolerate MessageQ_E_RESOURCE failures.
-         */
-        status = Ipc_S_SUCCESS;
-        attachedAny = FALSE;
-
-        /* needed to enumerate processors in cluster */
-        clusterSize = MultiProc_getNumProcsInCluster();
-        clusterBase = MultiProc_getBaseIdOfCluster();
-
-        for (i = 0, procId = clusterBase; i < clusterSize; i++, procId++) {
-
-            if (MultiProc_self() == procId) {
-                continue;
-            }
+        /* invoke the transport factory create method */
+        status = Ipc_module.transportFactory->createFxn();
 
-            params.rprocId = procId;
-            transport = TransportRpmsg_create(&params, &attachStatus);
-
-            if (transport) {
-                iMsgQTrans = TransportRpmsg_upCast(transport);
-                MessageQ_registerTransport(iMsgQTrans, procId, 0);
-                attachedAny = TRUE;
-            }
-            else {
-                if (attachStatus == MessageQ_E_RESOURCE) {
-                    continue;
-                }
-                printf("Ipc_start: failed to attach to procId=%d status=%d\n",
-                       procId, attachStatus);
-                status = Ipc_E_FAIL;
-                break;
-            }
-        }
-        if (!attachedAny) {
-            status = Ipc_E_FAIL;
+        if (status < 0) {
+            goto exit;
         }
     }
     else {
@@ -291,6 +257,9 @@ Int Ipc_stop(Void)
         goto exit;
     }
 
+    /* invoke the transport factory delete method */
+    Ipc_module.transportFactory->deleteFxn();
+
     /* needed to enumerate processors in cluster */
     clusterSize = MultiProc_getNumProcsInCluster();
     clusterBase = MultiProc_getBaseIdOfCluster();
@@ -340,6 +309,31 @@ exit:
     return (status);
 }
 
+/*
+ *  ======== Ipc_transportConfig ========
+ */
+Int Ipc_transportConfig(Ipc_TransportFactoryFxns *factory)
+{
+    Int status;
+
+    pthread_mutex_lock(&Ipc_module.gate);
+    status = Ipc_S_SUCCESS;
+
+    /* transport configuration must happen before start phase */
+    if (Ipc_module.refCount != 0) {
+        status = Ipc_E_INVALIDSTATE;
+        goto exit;
+    }
+
+    /* store factory address in module state */
+    Ipc_module.transportFactory = factory;
+
+exit:
+    pthread_mutex_unlock(&Ipc_module.gate);
+
+    return (status);
+}
+
 static void cleanup(int arg)
 {
     printf("Ipc: Caught SIGINT, calling Ipc_stop...\n");
index fdae9cb3d787bd0266cecb3d6381b9a7a9a5ed7c..f2c927c6beb556e38f793c576734fbe7e76ec7e5 100644 (file)
@@ -1,5 +1,5 @@
 ##
-##  Copyright (c) 2013-2014, Texas Instruments Incorporated
+##  Copyright (c) 2013-2015 Texas Instruments Incorporated - http://www.ti.com
 ##
 ##  Redistribution and use in source and binary forms, with or without
 ##  modification, are permitted provided that the following conditions
@@ -179,7 +179,7 @@ GateMPApp_SOURCES = $(common_sources) \
 
 common_libraries = -lpthread $(top_builddir)/linux/src/api/libtiipc.la \
                 $(top_builddir)/linux/src/utils/libtiipcutils.la \
-                $(top_builddir)/linux/src/transport/libtransport.la
+                $(top_builddir)/linux/src/transport/libtitransportrpmsg.la
 
 
 # the additional libraries to link ping_rpmsg
index 1f5bb5fc30202554a1b4fd9f426fba27c72a68a0..addfb11e130741eb19b9c86f95a13bfdbc78d71d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2014, Texas Instruments Incorporated
+ * Copyright (c) 2012-2015 Texas Instruments Incorporated - http://www.ti.com
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -45,6 +45,7 @@
 #include <ti/ipc/Std.h>
 #include <ti/ipc/Ipc.h>
 #include <ti/ipc/MessageQ.h>
+#include <TransportRpmsg.h>
 
 /* App defines:  Must match on remote proc side: */
 #define HEAPID              0u
@@ -181,8 +182,8 @@ exit:
 
 int main (int argc, char ** argv)
 {
-    Int32 status = 0;
-    UInt32 numLoops = NUM_LOOPS_DFLT;
+    Int status = 0;
+    UInt numLoops = NUM_LOOPS_DFLT;
     UInt16 procId = PROC_ID_DFLT;
 
     /* Parse Args: */
@@ -204,8 +205,17 @@ int main (int argc, char ** argv)
            exit(0);
     }
 
+    /* configure the transport factory */
+    Ipc_transportConfig(&TransportRpmsg_Factory);
+
+    /* IPC initialization */
     status = Ipc_start();
 
+    if (status < 0) {
+        printf("Error: Ipc_start failed, error=%d\n", status);
+        goto exit;
+    }
+
     if ((procId == 0) || (procId >= MultiProc_getNumProcessors())) {
         printf("ProcId (%d) must be nonzero and less than %d\n",
                 procId, MultiProc_getNumProcessors());
@@ -222,5 +232,6 @@ int main (int argc, char ** argv)
         printf("Ipc_start failed: status = %d\n", status);
     }
 
-    return(0);
+exit:
+    return (status);
 }
index edbfc34e39ceaba4f8125ae26d6135987edb169f..ded204fdee9652c90ec7ebb929c7e73be4d2a9e1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2014, Texas Instruments Incorporated
+ * Copyright (c) 2012-2015 Texas Instruments Incorporated - http://www.ti.com
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -47,6 +47,7 @@
 #include <ti/ipc/Std.h>
 #include <ti/ipc/Ipc.h>
 #include <ti/ipc/MessageQ.h>
+#include <TransportRpmsg.h>
 
 #define MINPAYLOADSIZE      (2 * sizeof(UInt32))
 
@@ -229,8 +230,17 @@ int main (int argc, char * argv[])
         exit(0);
     }
 
+    /* configure the transport factory */
+    Ipc_transportConfig(&TransportRpmsg_Factory);
+
+    /* IPC initialization */
     status = Ipc_start();
 
+    if (status < 0) {
+        printf("Error: Ipc_start failed, error=%d\n", status);
+        goto exit;
+    }
+
     if (procId >= MultiProc_getNumProcessors()) {
         printf("ProcId must be less than %d\n", MultiProc_getNumProcessors());
         Ipc_stop();
@@ -247,5 +257,6 @@ int main (int argc, char * argv[])
         printf("Ipc_start failed: status = %d\n", status);
     }
 
+exit:
     return (status);
 }
index a2c41d465cf620061dee34001b2474de073ade63..d123f175cc9a3919834a949069df21aa352cced0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2014, Texas Instruments Incorporated
+ * Copyright (c) 2012-2015 Texas Instruments Incorporated - http://www.ti.com
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -30,7 +30,7 @@
  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 /* =============================================================================
- *  @file   MessageQApp.c
+ *  @file   MessageQMulti.c
  *
  *  @brief  Sample application for MessageQ module between MPU and Remote Proc
  *
@@ -48,6 +48,7 @@
 #include <ti/ipc/Std.h>
 #include <ti/ipc/Ipc.h>
 #include <ti/ipc/MessageQ.h>
+#include <TransportRpmsg.h>
 
 /* App defines: Must match on remote proc side: */
 #define MSGSIZE                     64u
@@ -232,7 +233,12 @@ int main (int argc, char ** argv)
         printf("ProcNum: %d\n", procNum);
     }
 
+    /* configure the transport factory */
+    Ipc_transportConfig(&TransportRpmsg_Factory);
+
+    /* IPC initialization */
     status = Ipc_start();
+
     if (status < 0) {
         printf ("Ipc_start failed: status = 0x%x\n", status);
         goto exit;
@@ -264,6 +270,5 @@ int main (int argc, char ** argv)
     Ipc_stop();
 
 exit:
-
-    return (0);
+    return (status);
 }
index 8ca5075b93edc32f25b5e4382a7cf2f25a1998f8..446b9021832b5bce091f86dcec624a81de4163fe 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2014, Texas Instruments Incorporated
+ * Copyright (c) 2012-2015 Texas Instruments Incorporated - http://www.ti.com
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -30,7 +30,7 @@
  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 /* =============================================================================
- *  @file   MessageQApp.c
+ *  @file   MessageQMultiMulti.c
  *
  *  @brief  Sample application for MessageQ module between MPU and Remote Proc
  *
@@ -48,6 +48,7 @@
 #include <ti/ipc/Std.h>
 #include <ti/ipc/Ipc.h>
 #include <ti/ipc/MessageQ.h>
+#include <TransportRpmsg.h>
 
 /* App defines: Must match on remote proc side: */
 #define MSGSIZE                     64u
@@ -232,7 +233,12 @@ int main (int argc, char ** argv)
         printf("ProcNum: %d\n", procNum);
     }
 
+    /* configure the transport factory */
+    Ipc_transportConfig(&TransportRpmsg_Factory);
+
+    /* IPC initialization */
     status = Ipc_start();
+
     if (status < 0) {
         printf ("Ipc_start failed: status = 0x%x\n", status);
         goto exit;
@@ -264,6 +270,5 @@ int main (int argc, char ** argv)
     Ipc_stop();
 
 exit:
-
-    return (0);
+    return (status);
 }
index 1d6e11df1b9d6e21343a86cc1029c8fbbc3470ae..69b86af49f5fd4a928698856ec0da123535cf9a4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2013, Texas Instruments Incorporated
+ * Copyright (c) 2012-2015 Texas Instruments Incorporated - http://www.ti.com
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -45,6 +45,7 @@
 #include <ti/ipc/Std.h>
 #include <ti/ipc/Ipc.h>
 #include <ti/ipc/MessageQ.h>
+#include <TransportRpmsg.h>
 
 #define HEAPID                  0               /* not actually used */
 #define SLAVE_MSGQNAME          "SLAVE"
@@ -95,6 +96,9 @@ int main(int argc, char *argv[])
     UInt16 numProcs;
     String name;
 
+    /* configure the transport factory */
+    Ipc_transportConfig(&TransportRpmsg_Factory);
+
     /* parse the command line options (e.g. -h) */
     for (arg = 1; (arg < argc) && (argv[arg][0] == '-'); arg++) {
 
index 3c5525c4003439c9b1768c19fa57034f31e03258..d650ea0d2400885989fcd02d8e9a7e58690f995d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2014, Texas Instruments Incorporated
+ * Copyright (c) 2013-2015 Texas Instruments Incorporated - http://www.ti.com
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -42,8 +42,8 @@
 /* package header files */
 #include <ti/ipc/Std.h>
 #include <ti/ipc/Ipc.h>
-
 #include <ti/ipc/MultiProc.h>
+#include <TransportRpmsg.h>
 
 #include <ti/cmem.h>
 
@@ -93,7 +93,10 @@ Int main(Int argc, Char* argv[])
         printf("CMEM_init success\n");
     }
 
-    /* Ipc initialization */
+    /* configure the transport factory */
+    Ipc_transportConfig(&TransportRpmsg_Factory);
+
+    /* IPC initialization */
     status = Ipc_start();
 
     if (status >= 0) {
index 8d8492db2ccbd4e678d5fd43cc7d4ea7dc4d29a4..7425962c0721864e78751ecabc3369b579230be1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2013, Texas Instruments Incorporated
+ * Copyright (c) 2012-2015 Texas Instruments Incorporated - http://www.ti.com
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -52,6 +52,7 @@
 #include <ti/ipc/Std.h>
 #include <ti/ipc/Ipc.h>
 #include <ti/ipc/MessageQ.h>
+#include <TransportRpmsg.h>
 
 #include <ti/cmem.h>
 
@@ -227,6 +228,10 @@ int main (int argc, char ** argv)
         return(-1);
     }
 
+    /* configure the transport factory */
+    Ipc_transportConfig(&TransportRpmsg_Factory);
+
+    /* IPC initialization */
     status = Ipc_start();
 
     if (status >= 0) {
@@ -237,5 +242,5 @@ int main (int argc, char ** argv)
         printf ("Ipc_start failed: status = 0x%x\n", status);
     }
 
-    return(0);
+    return (status);
 }
index 121bdc3606bc7eef9601f8d0b12465d60bd45247..656e009f8840f92cfd188b7b89886fd5e0b0bab0 100644 (file)
@@ -1,5 +1,5 @@
 ##
-##  Copyright (c) 2013-2014, Texas Instruments Incorporated
+##  Copyright (c) 2013-2015 Texas Instruments Incorporated - http://www.ti.com
 ##
 ##  Redistribution and use in source and binary forms, with or without
 ##  modification, are permitted provided that the following conditions
@@ -45,20 +45,20 @@ AM_CFLAGS = -I$(top_srcdir)/linux/include -I$(top_srcdir)/hlos_common/include \
 ###############################################################################
 
 # the library names to build (note we are building shared libs)
-lib_LTLIBRARIES = libtransport.la
+lib_LTLIBRARIES = libtitransportrpmsg.la
 
 # where to install the headers on the system
-libtransport_ladir = $(includedir)/ti/ipc
+libtitransportrpmsg_ladir = $(includedir)/ti/ipc
 
 # the list of header files that belong to the library (to be installed later)
-libtransport_la_HEADERS = $(top_srcdir)/linux/include/ti/ipc/Std.h
+libtitransportrpmsg_la_HEADERS = $(top_srcdir)/linux/include/ti/ipc/Std.h
 
 # the sources to add to the library and to add to the source distribution
-libtransport_la_SOURCES =    \
+libtitransportrpmsg_la_SOURCES =    \
                         TransportRpmsg.c
 
 # Add version info to the shared library
-libtransport_la_LDFLAGS = -version-info 1:0:0
+libtitransportrpmsg_la_LDFLAGS = -version-info 1:0:0
 
 #pkgconfig_DATA          = libtiipc.pc
 #pkgconfigdir            = $(libdir)/pkgconfig
index 52c275e8379c90014686af17e63d107162650b3b..8c3d902a9f36fe891aedecca64a60ac9a72f312a 100644 (file)
@@ -36,6 +36,7 @@
 
 #include <ti/ipc/Std.h>
 
+#include <ti/ipc/Ipc.h>
 #include <ti/ipc/MessageQ.h>
 #include <ti/ipc/MultiProc.h>
 #include <_MessageQ.h>
@@ -87,12 +88,14 @@ typedef struct TransportRpmsg_Module {
     int             unblockEvent;    /* eventFd for unblocking socket */
     pthread_t       threadId;        /* ID returned by pthread_create() */
     Bool            threadStarted;
+
+    TransportRpmsg_Handle *inst;    /* array of instances */
 } TransportRpmsg_Module;
 
 IMessageQTransport_Fxns TransportRpmsg_fxns = {
     .bind    = TransportRpmsg_bind,
     .unbind  = TransportRpmsg_unbind,
-    .put     = TransportRpmsg_put,
+    .put     = TransportRpmsg_put
 };
 
 typedef struct TransportRpmsg_Object {
@@ -106,6 +109,7 @@ typedef struct TransportRpmsg_Object {
 TransportRpmsg_Module TransportRpmsg_state = {
     .sock = {0},
     .threadStarted = FALSE,
+    .inst = NULL
 };
 TransportRpmsg_Module *TransportRpmsg_module = &TransportRpmsg_state;
 
@@ -119,6 +123,14 @@ static Void bindFdToQueueIndex(TransportRpmsg_Object *obj,
 static Void unbindQueueIndex(TransportRpmsg_Object *obj, UInt16 qIndex);
 static Int queueIndexToFd(TransportRpmsg_Object *obj, UInt16 qIndex);
 
+Int TransportRpmsg_Factory_create(Void);
+Void TransportRpmsg_Factory_delete(Void);
+
+Ipc_TransportFactoryFxns TransportRpmsg_Factory = {
+    .createFxn = TransportRpmsg_Factory_create,
+    .deleteFxn = TransportRpmsg_Factory_delete
+};
+
 /* -------------------------------------------------------------------------- */
 
 /* instance convertors */
@@ -647,3 +659,113 @@ Int queueIndexToFd(TransportRpmsg_Object *obj, UInt16 qIndex)
     return obj->qIndexToFd[qIndex];
 }
 
+/*
+ *  ======== TransportRpmsg_Factory_create ========
+ *  Create the transport instances
+ *
+ *  Attach to all remote processors. For now, must attach to
+ *  at least one to tolerate MessageQ_E_RESOURCE failures.
+ *
+ *  This function implements the IPC Factory interface, so it
+ *  returns Ipc status codes.
+ */
+Int TransportRpmsg_Factory_create(Void)
+{
+    Int     status;
+    Int     attachStatus;
+    Int     i;
+    UInt16  procId;
+    Int32   attachedAny;
+    UInt16  clusterSize;
+    UInt16  clusterBase;
+
+    TransportRpmsg_Handle      *inst;
+    TransportRpmsg_Handle       transport;
+    TransportRpmsg_Params       params;
+    IMessageQTransport_Handle   iMsgQTrans;
+
+
+    status = Ipc_S_SUCCESS;
+    attachedAny = FALSE;
+
+    /* needed to enumerate processors in cluster */
+    clusterSize = MultiProc_getNumProcsInCluster();
+    clusterBase = MultiProc_getBaseIdOfCluster();
+
+    /* allocate the instance array */
+    inst = calloc(clusterSize, sizeof(TransportRpmsg_Handle));
+
+    if (inst == NULL) {
+        printf("Error: TransportRpmsg_Factory_create failed, no memory\n");
+        status = Ipc_E_MEMORY;
+        goto exit;
+    }
+
+    TransportRpmsg_module->inst = inst;
+
+    /* create transport instance for all processors in cluster */
+    for (i = 0, procId = clusterBase; i < clusterSize; i++, procId++) {
+
+        if (MultiProc_self() == procId) {
+            continue;
+        }
+
+        params.rprocId = procId;
+        transport = TransportRpmsg_create(&params, &attachStatus);
+
+        if (transport != NULL) {
+            iMsgQTrans = TransportRpmsg_upCast(transport);
+            MessageQ_registerTransport(iMsgQTrans, procId, 0);
+            attachedAny = TRUE;
+        }
+        else {
+            if (attachStatus == MessageQ_E_RESOURCE) {
+                continue;
+            }
+            printf("TransportRpmsg_Factory_create: failed to attach to "
+                    "procId=%d status=%d\n", procId, attachStatus);
+            status = Ipc_E_FAIL;
+            break;
+        }
+
+        TransportRpmsg_module->inst[i] = transport;
+    }
+
+    if (!attachedAny) {
+        status = Ipc_E_FAIL;
+    }
+
+exit:
+    return (status);
+}
+
+/*
+ *  ======== TransportRpmsg_Factory_delete ========
+ *  Finalize the transport instances
+ */
+Void TransportRpmsg_Factory_delete(Void)
+{
+    Int     i;
+    UInt16  procId;
+    UInt16  clusterSize;
+    UInt16  clusterBase;
+
+    /* needed to enumerate processors in cluster */
+    clusterSize = MultiProc_getNumProcsInCluster();
+    clusterBase = MultiProc_getBaseIdOfCluster();
+
+    /* detach from all remote processors, assuming they are up */
+    for (i = 0, procId = clusterBase; i < clusterSize; i++, procId++) {
+
+        if (MultiProc_self() == procId) {
+            continue;
+        }
+
+        if (TransportRpmsg_module->inst[i] != NULL) {
+            MessageQ_unregisterTransport(procId, 0);
+            TransportRpmsg_delete(&(TransportRpmsg_module->inst[i]));
+        }
+    }
+
+    return;
+}
index 445a7476764a488418a56a30ee9990c2b211bb6e..d2a7dc192a334d5880170b15358bd9a14177eca2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2013, Texas Instruments Incorporated
+ * Copyright (c) 2012-2015 Texas Instruments Incorporated - http://www.ti.com
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -130,6 +130,26 @@ extern "C" {
 #define Ipc_E_NOTREADY         (-11)
 
 
+/* =============================================================================
+ *  Structures & Enums
+ * =============================================================================
+ */
+
+/*!
+ *  @brief  Factory virtual function table
+ *
+ *  This virtual function table defines the interface which must
+ *  be implemented by the transport factory. The Ipc module will
+ *  use this factory to create and delete this transport. The
+ *  factory is responsible for managing the details of creation
+ *  and deletion.
+ */
+typedef struct {
+    Int (*createFxn)(Void);             /*!< factory create method      */
+    Void (*deleteFxn)(Void);            /*!< factory finalize method    */
+} Ipc_TransportFactoryFxns;
+
+
 /* =============================================================================
  *  Ipc Module-wide Functions
  * =============================================================================
@@ -304,6 +324,7 @@ Int Ipc_readConfig(UInt16 remoteProcId, UInt32 tag, Ptr cfg, SizeT size);
  *              - #Ipc_S_ALREADYSETUP: already successfully called
  *              - #Ipc_E_NOTREADY: shared memory is not ready
  *              - #Ipc_E_FAIL: operation failed
+ *              - #Ipc_E_INVALIDSTATE: transport factory not configured
  *
  *  @sa         Ipc_stop()
  */
@@ -323,6 +344,28 @@ Int Ipc_start(Void);
  */
 Int Ipc_stop(Void);
 
+/*!
+ *  @brief      Configure the primary transport factory
+ *
+ *  Configure IPC with the factory to use for the primary transport
+ *  The transport factory will be invoked by IPC during the start
+ *  phase (i.e. Ipc_start()) to create the transport instances. IPC
+ *  will also use the factory during the stop phase (i.e. Ipc_stop())
+ *  to finalize the transport instances.
+ *
+ *  By configuring the transport factory at run-time, the application
+ *  is able to pick which transport implementation will be used. It is
+ *  expected that each transport implementation provides a suitable
+ *  factory for use by the application.
+ *
+ *  This function is only available on Linux systems.
+ *
+ *  @return     Status
+ *              - #Ipc_S_SUCCESS: operation was successful
+ *              - #Ipc_E_INVALIDSTATE: IPC already running, must be stopped
+ */
+Int Ipc_transportConfig(Ipc_TransportFactoryFxns *factory);
+
 /*!
  *  @brief      Writes the config entry to the config area.
  *