]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blobdiff - linux/src/api/Ipc.c
SDOCM00115093 Multiple heap support for MessageQ
[ipc/ipcdev.git] / linux / src / api / Ipc.c
index 42ac0cbe415ad0a8d75f71e7fd5dc3a81d60cbbd..44b4816a6e981c839977d5253aaae27eb6c0a6d9 100644 (file)
@@ -48,6 +48,8 @@
 #include <ti/ipc/Std.h>
 #include <ti/ipc/Ipc.h>
 #include <ti/ipc/NameServer.h>
+#include <ti/ipc/heaps/HeapStd.h>
+#include <ti/ipc/interfaces/IHeap.h>
 
 /* User side headers */
 #include <ladclient.h>
@@ -88,7 +90,8 @@ static Ipc_Module Ipc_module = {
     .gate               = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,
 #endif
     .transportFactory   = NULL,
-    .config.procSync    = Ipc_ProcSync_NONE
+    .config.procSync    = Ipc_ProcSync_NONE,
+    .config.idHeapStd   = 0
 };
 
 GateHWSpinlock_Config _GateHWSpinlock_cfgParams;
@@ -122,6 +125,8 @@ Int Ipc_start(Void)
     UInt16      baseId;
     UInt16      clusterId;
     Int         i;
+    HeapStd_Handle heap;
+    IHeap_Handle iheap;
 
     /* function must be serialized */
     pthread_mutex_lock(&Ipc_module.gate);
@@ -186,7 +191,7 @@ Int Ipc_start(Void)
     ladStatus = LAD_connect(&ladHandle);
 
     if (ladStatus != LAD_SUCCESS) {
-        printf("Ipc_start: LAD_connect() failed: %d\n", ladStatus);
+        fprintf(stderr, "Ipc_start: LAD_connect() failed: %d\n", ladStatus);
         status = Ipc_E_FAIL;
         goto exit;
     }
@@ -202,7 +207,7 @@ Int Ipc_start(Void)
     status = NameServer_setup();
 
     if (status < 0) {
-        printf("Ipc_start: NameServer_setup() failed: %d\n", status);
+        fprintf(stderr, "Ipc_start: NameServer_setup() failed: %d\n", status);
         status = Ipc_E_FAIL;
         goto exit;
     }
@@ -211,6 +216,11 @@ Int Ipc_start(Void)
     MessageQ_getConfig(&msgqCfg);
     MessageQ_setup(&msgqCfg);
 
+    /* register the standard heap */
+    heap = HeapStd_handle();
+    iheap = HeapStd_upCast(heap);
+    MessageQ_registerHeap((Ptr)iheap, Ipc_module.config.idHeapStd);
+
     /* invoke the transport factory create method */
     status = Ipc_module.transportFactory->createFxn();
 
@@ -254,14 +264,15 @@ Int Ipc_start(Void)
 
         status = GateHWSpinlock_start();
         if (status < 0) {
-            printf("Ipc_start: GateHWSpinlock_start failed: %d\n", status);
+            fprintf(stderr, "Ipc_start: GateHWSpinlock_start failed: %d\n",
+                    status);
             status = Ipc_E_FAIL;
             goto exit;
         }
 
         status = GateMP_start();
         if (status < 0) {
-            printf("Ipc_start: GateMP_start failed: %d\n", status);
+            fprintf(stderr, "Ipc_start: GateMP_start failed: %d\n", status);
             status = Ipc_E_FAIL;
             GateHWSpinlock_stop();
             goto exit;
@@ -332,23 +343,26 @@ Int Ipc_stop(Void)
 
     Ipc_module.transportFactory->deleteFxn();
 
+    /* unregister the standard heap */
+    MessageQ_unregisterHeap(Ipc_module.config.idHeapStd);
+
     status = MessageQ_destroy();
     if (status < 0) {
-        printf("Ipc_stop: MessageQ_destroy() failed: %d\n", status);
+        fprintf(stderr, "Ipc_stop: MessageQ_destroy() failed: %d\n", status);
         status = Ipc_E_FAIL;
         goto exit;
     }
 
     status = NameServer_destroy();
     if (status < 0) {
-        printf("Ipc_stop: NameServer_destroy() failed: %d\n", status);
+        fprintf(stderr, "Ipc_stop: NameServer_destroy() failed: %d\n", status);
         status = Ipc_E_FAIL;
         goto exit;
     }
 
     ladStatus = LAD_disconnect(ladHandle);
     if (ladStatus != LAD_SUCCESS) {
-        printf("LAD_disconnect() failed: %d\n", ladStatus);
+        fprintf(stderr, "LAD_disconnect() failed: %d\n", ladStatus);
         status = Ipc_E_FAIL;
         goto exit;
     }
@@ -400,6 +414,9 @@ Int Ipc_attach(UInt16 procId)
 {
     Int status = Ipc_S_SUCCESS;
     UInt16 clusterId;
+#if defined(GATEMP_SUPPORT)
+    Int ret;
+#endif
 
     /* cannot attach to yourself */
     if (MultiProc_self() == procId) {
@@ -443,6 +460,18 @@ Int Ipc_attach(UInt16 procId)
     /* hack: bind all existing message queues to remote processor */
     MessageQ_bind(procId);
 
+#if defined(GATEMP_SUPPORT)
+    if (GateMP_isSetup()) {
+        /* establish GateMP connection to remote processor */
+        ret = GateMP_attach(procId);
+
+        if (ret < 0) {
+            PRINTVERBOSE1("Ipc_attach: failed to GateMP_attach to procId %d\n",
+                          procId);
+        }
+    }
+#endif
+
     /* getting here means we have successfully attached */
     Ipc_module.attached[clusterId]++;
 
@@ -459,6 +488,9 @@ Int Ipc_detach(UInt16 procId)
 {
     Int status = Ipc_S_SUCCESS;
     UInt16 clusterId;
+#if defined(GATEMP_SUPPORT)
+    Int ret;
+#endif
 
     /* cannot detach from yourself */
     if (MultiProc_self() == procId) {
@@ -486,6 +518,18 @@ Int Ipc_detach(UInt16 procId)
         goto done;
     }
 
+#if defined(GATEMP_SUPPORT)
+    if (GateMP_isSetup()) {
+        /* establish GateMP connection to remote processor */
+        ret = GateMP_detach(procId);
+
+        if (ret < 0) {
+            PRINTVERBOSE1("Ipc_detach: failed to GateMP_detach from procId %d\n",
+                          procId);
+        }
+    }
+#endif
+
     /* hack: unbind all existing message queues from remote processor */
     MessageQ_unbind(procId);
 
@@ -510,7 +554,7 @@ Int Ipc_detach(UInt16 procId)
 done:
     if (status < 0) {
         /* report error */
-        printf("Ipc_detach: Error %d, procId %d\n", status, procId);
+        fprintf(stderr, "Ipc_detach: Error %d, procId %d\n", status, procId);
     }
     pthread_mutex_unlock(&Ipc_module.gate);