From a6f44c4d894dff68362673724e565d45dcc9146c Mon Sep 17 00:00:00 2001
From: Daniela Genius <genius@debussy.soc.lip6.fr>
Date: Thu, 26 Jan 2017 13:39:37 +0100
Subject: [PATCH] bugfix channel generation for MPSoC

---
 src/avatartranslator/AvatarRelation.java      | 18 ++++--
 .../toSoclib/TasksAndMainGenerator.java       | 56 +++++++++++++------
 2 files changed, 52 insertions(+), 22 deletions(-)

diff --git a/src/avatartranslator/AvatarRelation.java b/src/avatartranslator/AvatarRelation.java
index 537419744a..b79ded3215 100644
--- a/src/avatartranslator/AvatarRelation.java
+++ b/src/avatartranslator/AvatarRelation.java
@@ -58,7 +58,7 @@ public class AvatarRelation extends AvatarElement {
     private LinkedList<AvatarSignal> signals1, signals2;
     private boolean blocking, asynchronous, isPrivate, isBroadcast, isLossy;
     private int sizeOfFIFO; // -1 means infinite
-
+    public int id;//DG
 
     public AvatarRelation(String _name, AvatarBlock _block1, AvatarBlock _block2, Object _referenceObject) {
         super(_name, _referenceObject);
@@ -70,9 +70,18 @@ public class AvatarRelation extends AvatarElement {
         sizeOfFIFO = 1024;
         asynchronous = false;
         isBroadcast = false;
+	id = 0;//DG
+    }
+  
+    public void setId(int newid) {//DG
+        id=newid;
+    }
 
+    public int getId() {//DG
+        return id;
     }
 
+
     public boolean containsSignal(AvatarSignal _as) {
         return (signals1.contains(_as) || signals2.contains(_as));
     }
@@ -264,13 +273,12 @@ public class AvatarRelation extends AvatarElement {
 	    AvatarSignal ns2 = b2.getSignalByName(s2.getName());
 	    if ((ns1 == null) || (ns2 == null)) {
 		continue;
-	    }
-	    
+	    }	   	
 	    ar.addSignals(ns1, ns2);
 	}
 
-	cloneLinkToReferenceObjects(ar);
-	
+	cloneLinkToReferenceObjects(ar);	
+
 	return ar;
     }
 
diff --git a/src/ddtranslatorSoclib/toSoclib/TasksAndMainGenerator.java b/src/ddtranslatorSoclib/toSoclib/TasksAndMainGenerator.java
index 3e8d4d3061..92c68c0921 100755
--- a/src/ddtranslatorSoclib/toSoclib/TasksAndMainGenerator.java
+++ b/src/ddtranslatorSoclib/toSoclib/TasksAndMainGenerator.java
@@ -74,6 +74,9 @@ import myutil.Conversion;
 import myutil.FileException;
 import myutil.FileUtils;
 import myutil.TraceManager;
+import ddtranslatorSoclib.toTopCell.TopCellGenerator;
+import ddtranslatorSoclib.AvatarRAM;
+import ddtranslatorSoclib.AvatarChannel;
 
 public class TasksAndMainGenerator {
 
@@ -192,11 +195,14 @@ public class TasksAndMainGenerator {
                
 	int d=0;
 
-	for(AvatarRelation ar: avspec.getRelations()) {
-	    mainFile.appendToBeforeMainCode("#define CHANNEL"+d+" __attribute__((section(\"section_channel"+d+"\")))" + CR ); 
-
-	mainFile.appendToBeforeMainCode("#define LOCK"+d+" __attribute__((section(\"section_lock"+d+"\")))" + CR );//one lock per channel
+	//for(AvatarRelation ar: avspec.getRelations()) {
+	for (AvatarRAM ram : TopCellGenerator.avatardd.getAllRAM()) { 
+	//for(AvatarChannel ar: avspec.getChannels()) {
+	    for(AvatarChannel channel: ram.getChannels()){ 
+		mainFile.appendToBeforeMainCode("#define CHANNEL"+d+" __attribute__((section(\"section_channel"+d+"\")))" + CR ); 	
+		mainFile.appendToBeforeMainCode("#define LOCK"+d+" __attribute__((section(\"section_lock"+d+"\")))" + CR );//one lock per channel
 	    d++;
+	    }
 	}
 
 
@@ -214,14 +220,15 @@ public class TasksAndMainGenerator {
     }
   
     public void makeSynchronousChannels() {
-	int i=0;        
-        // Create a synchronous channel per relation/signal
+	int i=0;   int j=0;     
+        // Create synchronous channel signals
         mainFile.appendToHCode("/* Synchronous channels */" + CR);
         mainFile.appendToBeforeMainCode("/* Synchronous channels */" + CR);
         mainFile.appendToMainCode("/* Synchronous channels */" + CR);
         for(AvatarRelation ar: avspec.getRelations()) {
-	    int j=0;
+	    
 	if (!ar.isAsynchronous()) {
+	ar.setId(j); j++;
 		    for(i=0; i<ar.nbOfSignals() ; i++) {
 			mainFile.appendToHCode("extern syncchannel __" + getChannelName(ar, i) + ";" + CR);
 
@@ -250,17 +257,24 @@ public class TasksAndMainGenerator {
 			mainFile.appendToMainCode(getChannelName(ar, i)+".status->usage=0;" + CR);
 			mainFile.appendToMainCode(getChannelName(ar, i) + ".status->wptr =0;" + CR);
 
-			mainFile.appendToBeforeMainCode("uint32_t const "+ getChannelName(ar, i)+"_lock LOCK"+i+";" + CR); 
+			//mainFile.appendToBeforeMainCode("uint32_t const "+ getChannelName(ar, i)+"_lock LOCK"+i+";" + CR); 
 
-			mainFile.appendToBeforeMainCode("struct mwmr_status_s "+ getChannelName(ar, i) +"_status CHANNEL"+j+";" + CR); 		
+	//DG 26.01.2017 corrected gros bug i remplace
+			/*	mainFile.appendToBeforeMainCode("uint32_t const "+ getChannelName(ar, i)+"_lock LOCK"+i+";" + CR); 
+	mainFile.appendToBeforeMainCode("struct mwmr_status_s "+ getChannelName(ar, i) +"_status CHANNEL"+j+";" + CR); 		
 	       
-			mainFile.appendToBeforeMainCode("uint8_t "+getChannelName(ar, i) +"_data[32] CHANNEL"+i+";" + CR);
+	mainFile.appendToBeforeMainCode("uint8_t "+getChannelName(ar, i) +"_data[32] CHANNEL"+i+";" + CR);
 		
-			mainFile.appendToBeforeMainCode("struct mwmr_s "+getChannelName(ar, i) +" CHANNEL"+i+";" + CR2);		
-			j++;	
-	  }
+	mainFile.appendToBeforeMainCode("struct mwmr_s "+getChannelName(ar, i) +" CHANNEL"+i+";" + CR2);*/		     
+			mainFile.appendToBeforeMainCode("uint32_t const "+ getChannelName(ar, i)+"_lock LOCK"+ar.getId()+";" + CR); 
+	mainFile.appendToBeforeMainCode("struct mwmr_status_s "+ getChannelName(ar, i) +"_status CHANNEL"+ar.getId()+";" + CR); 		
+	       
+	mainFile.appendToBeforeMainCode("uint8_t "+getChannelName(ar, i) +"_data[32] CHANNEL"+ar.getId()+";" + CR);
+		
+	mainFile.appendToBeforeMainCode("struct mwmr_s "+getChannelName(ar, i) +" CHANNEL"+ar.getId()+";" + CR2);					
+		    }
 	}
-      }
+      }	
     }
 
     public void makeAsynchronousChannels() {
@@ -269,8 +283,9 @@ public class TasksAndMainGenerator {
 	    mainFile.appendToHCode("/* Asynchronous channels */" + CR);
 	    mainFile.appendToBeforeMainCode("/* Asynchronous channels */" + CR);
 	    mainFile.appendToMainCode("/* Asynchronous channels */" + CR);
-  //          int j=0;
+            int j=0;
 	    for(AvatarRelation ar: avspec.getRelations()) {
+		ar.setId(j); j++;//DG
 		if (ar.isAsynchronous()) {
 		    for(int i=0; i<ar.nbOfSignals() ; i++) {
 			mainFile.appendToHCode("extern asyncchannel __" + getChannelName(ar, i) + ";" + CR);
@@ -308,12 +323,19 @@ public class TasksAndMainGenerator {
 		mainFile.appendToMainCode(getChannelName(ar, i)+".status->usage=0;" + CR);
 	    mainFile.appendToMainCode(getChannelName(ar, i)+".status->wptr=0;" + CR);
 	    
-	    mainFile.appendToBeforeMainCode("uint32_t const "+ getChannelName(ar, i)+"_lock LOCK"+i+";" + CR); 
+	    /* mainFile.appendToBeforeMainCode("uint32_t const "+ getChannelName(ar, i)+"_lock LOCK"+i+";" + CR); 
 
 
 			mainFile.appendToBeforeMainCode("struct mwmr_status_s "+ getChannelName(ar, i) +"_status CHANNEL"+i+";" + CR);								
 			mainFile.appendToBeforeMainCode("uint8_t "+getChannelName(ar, i) +"_data[32] CHANNEL"+i+";" + CR);
-	mainFile.appendToBeforeMainCode("struct mwmr_s "+getChannelName(ar, i) + " CHANNEL"+i+";" + CR2);
+			mainFile.appendToBeforeMainCode("struct mwmr_s "+getChannelName(ar, i) + " CHANNEL"+i+";" + CR2);*/
+  int seg_no=0;
+        mainFile.appendToBeforeMainCode("uint32_t const "+ getChannelName(ar, i)+"_lock LOCK"+ar.getId()+";" + CR); 
+	mainFile.appendToBeforeMainCode("struct mwmr_status_s "+ getChannelName(ar, i) +"_status CHANNEL"+ar.getId()+";" + CR); 		
+	       
+	mainFile.appendToBeforeMainCode("uint8_t "+getChannelName(ar, i) +"_data[32] CHANNEL"+ar.getId()+";" + CR);
+		
+	mainFile.appendToBeforeMainCode("struct mwmr_s "+getChannelName(ar, i) +" CHANNEL"+ar.getId()+";" + CR2);		
 			//j++;		
 		    }
 		}
-- 
GitLab