Merge "Added new API for SHM and DSHM access changed deployment script to dynamic arguments"
diff --git a/RTFParallella/.cproject b/RTFParallella/.cproject
index d09a4a3..29dcf8c 100755
--- a/RTFParallella/.cproject
+++ b/RTFParallella/.cproject
@@ -14,14 +14,19 @@
 				</extensions>
 			</storageModule>
 			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
-				<configuration buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.cross.base.1605716264" name="Default" optionalBuildProperties="" parent="org.eclipse.cdt.build.core.emptycfg">
+				<configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.cross.base.1605716264" name="Default" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=" parent="org.eclipse.cdt.build.core.emptycfg">
 					<folderInfo id="cdt.managedbuild.toolchain.gnu.cross.base.1605716264.813184079" name="/" resourcePath="">
 						<toolChain id="cdt.managedbuild.toolchain.gnu.cross.base.1547314808" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.base">
 							<option id="cdt.managedbuild.option.gnu.cross.prefix.429924673" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix"/>
 							<option id="cdt.managedbuild.option.gnu.cross.path.1993404401" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path"/>
 							<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.1813206941" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
-							<builder buildPath="${workspace_loc:/org.eclipse.app4mc.examples.rtfp/src/parallella}" enabledIncrementalBuild="true" id="cdt.managedbuild.builder.gnu.cross.65220641" incrementalBuildTarget="example1" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/>
+							<builder buildPath="${workspace_loc:/org.eclipse.app4mc.examples.rtfp/src/parallella}" enabledIncrementalBuild="true" id="cdt.managedbuild.builder.gnu.cross.65220641" incrementalBuildTarget="" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/>
 							<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.175109054" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
+								<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.c.compiler.option.include.paths.487911336" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/org.eclipse.app4mc.examples.rtfp}&quot;"/>
+									<listOptionValue builtIn="false" value="/opt/adapteva/esdk"/>
+									<listOptionValue builtIn="false" value="/opt/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf"/>
+								</option>
 								<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1925296426" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
 							</tool>
 							<tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.2040290889" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler"/>
diff --git a/RTFParallella/.settings/language.settings.xml b/RTFParallella/.settings/language.settings.xml
index 73ec64b..b8a5e4c 100755
--- a/RTFParallella/.settings/language.settings.xml
+++ b/RTFParallella/.settings/language.settings.xml
@@ -5,7 +5,7 @@
 			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(g?cc)|([gc]\+\+)|(clang)" prefer-non-shared="true"/>
-			<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-1378115495018860532" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+			<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-1811452639180198582" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 				<language-scope id="org.eclipse.cdt.core.gcc"/>
 				<language-scope id="org.eclipse.cdt.core.g++"/>
 			</provider>
diff --git a/RTFParallella/parallellaDeploy.sh b/RTFParallella/parallellaDeploy.sh
index e0c84da..ae20781 100755
--- a/RTFParallella/parallellaDeploy.sh
+++ b/RTFParallella/parallellaDeploy.sh
@@ -25,26 +25,30 @@
 #path and file name inputs
 DEPOLYMENT_BINARY=${1?Error: no host binary given}
 
+echo "---------------------------------------"
+echo "copying binaries to remote board..."
+
+#transfer host and device binaries to parallella board
+
+for DEPLOYMENT_BINARY_INDEXED in "$@"
+
+do
+
+ scp -4 -C -P $PORT -i $KEY $DEPLOYMENT_BINARY_INDEXED $HOST_USER@$HOST_NAME:$HOST_OFFLOAD_PATH
+ if [ $? != 0 ]; then
+	echo "Transfer failed!"
+  	exit 1
+ else
+	echo "Transfer complete."
+ fi
+done
+echo "---------------------------------------"
+
 #proper ssh, use this to open an ssh connection to parallella for execution
-#sudo ssh parallella@idial.institute -p 32767 -i ~/.ssh/key
+#sudo ssh $HOST_USER@$HOST_NAME -p $PORT -i ~/.ssh/key
 
 #clear hostOfflad path before copying new files
 #ssh $HOST_NAME -p$PORT -l$HOST_USER -i$KEY "cd $HOST_OFFLOAD_PATH "
-
-#transfer host and device binaries to parallella board
-echo "---------------------------------------"
-echo "copying binaries to remote board..."
-scp -4 -C -P $PORT -i $KEY $DEPOLYMENT_BINARY $HOST_USER@$HOST_NAME:$HOST_OFFLOAD_PATH
-if [[ $? != 0 ]]; then
-  echo "Transfer failed!"
-  exit 1
-else
-  echo "Transfer complete."
-fi
-echo "---------------------------------------"
-echo "Running program $HOST_BINARY"
-echo "***************************************"
-#run the binaries remotely on parallella
-#ssh $HOST_NAME -p$PORT -l$HOST_USER -i$KEY "EPIPHANY_HOME=/opt/adapteva/esdk && . $EPIPHANY_HOME/setup.sh && cd $HOST_OFFLOAD_PATH && ./$DEPOLYMENT_BINARY"
-echo "***************************************"
 echo "done"
+
+
diff --git a/RTFParallella/src/parallella/Makefile b/RTFParallella/src/parallella/Makefile
index 15c1fba..db1f694 100755
--- a/RTFParallella/src/parallella/Makefile
+++ b/RTFParallella/src/parallella/Makefile
@@ -29,7 +29,7 @@
 	@echo build status : successful
 
 #rule for every device target
-%.elf: $(ELDF) tasks.o queue.o list.o portasm.o port.o heap_1.o c2c.o debugFlags.o AmaltheaConverter.o taskCode.o ParallellaUtils.o shared_comms.o %.o
+%.elf: $(ELDF) tasks.o queue.o list.o portasm.o port.o heap_1.o c2c.o debugFlags.o AmaltheaConverter.o taskCode.o ParallellaUtils.o shared_comms.o label_man_core0.o %.o
 	$(CC) -g -T$< -Wl,--gc-sections -o $@ $(filter-out $<,$^) -le-lib
 
 #host target
diff --git a/RTFParallella/src/parallella/armcode.c b/RTFParallella/src/parallella/armcode.c
index e7d3b1c..5f9cbd4 100755
--- a/RTFParallella/src/parallella/armcode.c
+++ b/RTFParallella/src/parallella/armcode.c
@@ -127,7 +127,7 @@
 		e_read(&dev,0,0,dstr_mem_offset_sec_1, &shared_label_core_00, sizeof(shared_label_core_00));
 		e_read(&dev,1,0,addr, &message2, sizeof(message2));
 		e_read(&dev,1,0,dstr_mem_offset_sec_1, &shared_label_core_10, sizeof(shared_label_core_10));
-		e_read(&emem,0,0,0x00, &shared_label_to_read, sizeof(shared_label_to_read));
+		e_read(&emem,0,0,0x00, &shared_label_to_read, 10*sizeof(unsigned int));
 		if (message[8]!= message2[8] ){
 			//fprintf(stderr,"NIS->");
 		}
diff --git a/RTFParallella/src/parallella/c2c.c b/RTFParallella/src/parallella/c2c.c
index 3045c04..28122d4 100755
--- a/RTFParallella/src/parallella/c2c.c
+++ b/RTFParallella/src/parallella/c2c.c
@@ -52,12 +52,44 @@
 	*addr = payload;
 }
 
+
+void DSHM_section_init(DSHM_section sec){
+	unsigned int *addr;
+	unsigned int* addr_base;
+	addr_base = get_base_address_core(sec.row,sec.col);
+	addr = (unsigned int*) ((unsigned ) addr_base | (unsigned)sec.base_addr);
+	for (int i = 0;i<sec.label_count;i++){
+		addr[i] = 256;
+	}
+}
+
+
+uint8_t write_DSHM_section	(DSHM_section sec,int label_indx,int payload){
+	unsigned int *addr;
+	unsigned int* addr_base;
+	addr_base = get_base_address_core(sec.row,sec.col);
+	addr = (unsigned int*) ((unsigned ) addr_base | (unsigned)sec.base_addr);
+	addr[label_indx] = payload;
+}
+
+unsigned int read_DSHM_section (DSHM_section sec, int label_indx){
+	unsigned int *addr;
+	unsigned int* addr_base;
+	addr_base = get_base_address_core(sec.row,sec.col);
+	addr = (unsigned int*) ((unsigned ) addr_base | (unsigned)sec.base_addr);
+	return addr[label_indx];
+}
+
+
+
+
+
 unsigned int shared_label_read_core (unsigned row, unsigned col, int label_indx){
 	unsigned int *addr;
 	unsigned int* addr_base;
 	addr_base = get_base_address_core(row,col);
 	addr = (unsigned int*) ((unsigned ) addr_base | (unsigned)outbuf_dstr_shared[label_indx]);
-	return *addr;
+	return addr;
 }
 
 
diff --git a/RTFParallella/src/parallella/c2c.h b/RTFParallella/src/parallella/c2c.h
index 7b44987..4477816 100755
--- a/RTFParallella/src/parallella/c2c.h
+++ b/RTFParallella/src/parallella/c2c.h
@@ -16,10 +16,32 @@
 
 
 #include <stdint.h>
+#include "shared_comms.h"
 #define dstr_mem_offset_sec_1 			0x4000
 #define dstr_mem_sec_1_label_count		10
 #define dstr_mem_sec_1_label_type		unsigned int
 
+
+
+/**
+ * defines a distributed shared memory section
+ *
+ * Fields:
+ * row		: the row of target core on Epi chip
+ * col		: the column of target core on Epi chip
+ * base_addr: address of the first label in the section
+ * label_count: number of labels in the section
+ * sec_type: data type of the section (size of labels in the section)
+ *
+ */
+struct{
+	unsigned 		row;
+	unsigned 		col;
+	unsigned int 	base_addr;
+	unsigned 		label_count;
+	TYPE			sec_type;
+}typedef DSHM_section;
+
 /**
  * Initiate the shared label section, this funcion will assign addresses to labels in a section,
  * and initialize those labels to 0
@@ -41,6 +63,7 @@
  */
 uint8_t shared_label_write_core	(unsigned row,unsigned col,int label_indx,int payload);
 
+
 /**
  * read a value of a label in a distributed shared memory section
  *
@@ -64,4 +87,51 @@
 
 
 
+/**
+ * Initiate the distributed shared label section, this function will assign addresses to labels in a section,
+ * and initialize those labels to the value of 256
+ *
+ * Arguments:
+ * sec	:	structure of type DSHM_section containing
+ * 			details of the the distributed shared memory section to be initiated
+ *
+ */
+void DSHM_section_init(DSHM_section sec);
+
+/**
+ * Read data from a specific label in a ditributed shared memory section
+ * This function will read one full label but the result will
+ * be cast into unsigned int (4 bytes on this platform)
+ *
+ * Segmentation fault will occur for addresses outside the shared_dram section of the system
+ * check RTFP documentation for details.
+ *
+ * Arguments:
+ * sec			:	struct of the section to be read
+ * label_indx	:	index of requested label
+ *
+ * Return:
+ * value of requested label in a distributed shared memory section
+ *
+ *
+ */
+unsigned int read_DSHM_section (DSHM_section sec, int label_indx);
+
+/**
+ * Write data to a specific label in a distributed shared memory section
+ * This function will write one full label but the value will
+ * be given as int (4 bytes on this platform) to avoid overflow issues
+ *
+ * Segmentation fault will occur for addresses outside the shared_dram section of the system
+ * check RTFP documentation for details.
+ *
+ * Arguments:
+ * sec			:	struct of the section to be written to
+ * label_indx	:	index of requested label
+ * payload		:	value to be written (will be cast into data type of target label)
+ *
+ */
+uint8_t write_DSHM_section	(DSHM_section sec,int label_indx,int payload);
+
+
 #endif
diff --git a/RTFParallella/src/parallella/core0_main.c b/RTFParallella/src/parallella/core0_main.c
index 8a58f9d..8b60191 100755
--- a/RTFParallella/src/parallella/core0_main.c
+++ b/RTFParallella/src/parallella/core0_main.c
@@ -19,19 +19,29 @@
 #include "debugFlags.h"
 #include "shared_comms.h"
 #include "taskCode.h"
+#include "label_man_core0.h"
 #include "e_lib.h"
 //freeRTOS imports
 #include "FreeRTOS.h"
 #include "task.h"
 #include "queue.h"
 //utility imports
+unsigned int* global_shm_sec_ptr;
 
 //---------------------------------------------
 int main(void) {
 	//initialize output buffer for debug messages
 	outbuf_init();
-	shared_labels_init();
+	//shared_labels_init();
+	init_mem_sections();
 	shared_labels_init_core();
+	//SHM_section sec1 = {0x01001000,4};
+	/*unsigned int *x;
+	x = shm_section_init(sec1);
+	global_shm_sec_ptr = x;
+	int y;
+	y = read_shm_section(global_shm_sec_ptr,0);
+	write_shm_section(global_shm_sec_ptr,5,y + 10);*/
 	//create Amalthea task objects
 	AmaltheaTask t5ms =  createAmaltheaTask(handler5ms,cIn5ms,cOut5ms,5,5,2);
 	AmaltheaTask t10ms = createAmaltheaTask(handler10ms,cIn10ms,cOut10ms,10,10,3);
diff --git a/RTFParallella/src/parallella/core1_main.c b/RTFParallella/src/parallella/core1_main.c
index 82a1009..da8c2f4 100755
--- a/RTFParallella/src/parallella/core1_main.c
+++ b/RTFParallella/src/parallella/core1_main.c
@@ -20,6 +20,7 @@
 #include "shared_comms.h"
 #include "taskCode.h"
 #include "e_lib.h"
+#include "label_man_core0.h"
 //freeRTOS imports
 #include "FreeRTOS.h"
 #include "task.h"
@@ -29,7 +30,7 @@
 int main(void) {
 	//initialize output buffer for debug messages
 	outbuf_init();
-	shared_labels_init();
+	init_mem_sections();
 	shared_labels_init_core();
 	//create Amalthea task objects
 	AmaltheaTask t20ms = createAmaltheaTask(handler10msCore2,cIn10msCore2,cOut10msCore2,10,10,7);
diff --git a/RTFParallella/src/parallella/debugFlags.c b/RTFParallella/src/parallella/debugFlags.c
index 9172a6e..bcafe14 100755
--- a/RTFParallella/src/parallella/debugFlags.c
+++ b/RTFParallella/src/parallella/debugFlags.c
@@ -70,3 +70,4 @@
 
 
 
+
diff --git a/RTFParallella/src/parallella/host_main_example1.c b/RTFParallella/src/parallella/host_main_example1.c
index 595211b..060b795 100644
--- a/RTFParallella/src/parallella/host_main_example1.c
+++ b/RTFParallella/src/parallella/host_main_example1.c
@@ -110,7 +110,7 @@
 		e_read(&dev,0,0,dstr_mem_offset_sec_1, &shared_label_core[0], sizeof(shared_label_core_00));
 		e_read(&dev,1,0,addr, &message2, sizeof(message2));
 		e_read(&dev,1,0,dstr_mem_offset_sec_1, &shared_label_core[1], sizeof(shared_label_core_10));
-		e_read(&emem,0,0,0x00, &shared_label_to_read, sizeof(shared_label_core_10));
+		e_read(&emem,0,0,0x00, &shared_label_to_read, sizeof(unsigned int));
 		if (message[8]!= message2[8] ){
 			//fprintf(stderr,"NIS->");
 		}
@@ -120,7 +120,11 @@
 		for (int i=0;i<core_count;i++){
 			user_config_print_values_auto(DSHM_visible_label_count,labelVisual_perCore[i],shared_label_core[i],prv_val_preCore[i]);
 		}
-		user_config_print_values_auto(SHM_visible_label_count,labelVisual_SHM,shared_label_to_read,prv_val_SHM);
+		for (int i=0;i<10;i++){
+			fprintf(stderr," %3d |",shared_label_to_read[i]);
+		}
+
+		//user_config_print_values_auto(SHM_visible_label_count,labelVisual_SHM,shared_label_to_read,prv_val_SHM);
 		fprintf(stderr,"\n");
 		nsleep(1);
 	}
diff --git a/RTFParallella/src/parallella/host_utils.c b/RTFParallella/src/parallella/host_utils.c
index d827db5..031cd96 100755
--- a/RTFParallella/src/parallella/host_utils.c
+++ b/RTFParallella/src/parallella/host_utils.c
@@ -93,7 +93,7 @@
 void print_legend_enum (unsigned label_count,unsigned label_positions[], unsigned memory_type){
 	char buf[label_count*label_str_len];
 	for (int i=0;i<label_str_len;i++){
-		buf[i] = "";
+		buf[i] = " ";
 	}
 	char small_buf[label_str_len];
 	//array_init(buf,label_str_len);
diff --git a/RTFParallella/src/parallella/label_man_core0.c b/RTFParallella/src/parallella/label_man_core0.c
new file mode 100644
index 0000000..08bdbc2
--- /dev/null
+++ b/RTFParallella/src/parallella/label_man_core0.c
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ *     Copyright (c) 2019 Dortmund University of Applied Sciences and Arts and others.
+ *    
+ *     This program and the accompanying materials are made
+ *     available under the terms of the Eclipse Public License 2.0
+ *     which is available at https://www.eclipse.org/legal/epl-2.0/
+ *    
+ *     SPDX-License-Identifier: EPL-2.0
+ *    
+ *     Contributors:
+ *          Dortmund University of Applied Sciences and Arts - initial API and implementation
+ *******************************************************************************/
+
+#include "label_man_core0.h"
+
+//create shm sections' structs
+SHM_section sec1 = {0x01001000,10};
+DSHM_section sec1_core_00 = {0,0,0x4000,10};
+DSHM_section sec1_core_10 = {1,0,0x4000,10};
+
+
+//pointer declarations for shm sections accessed by this core
+unsigned int* sec1_global_pointer;
+unsigned int* sec2_global_pointer;
+
+//initialize shm sections and assign pointers
+
+void init_mem_sections(void){
+	sec1_global_pointer = shm_section_init(sec1);
+}
+
+
+void init_DSHM_sections(void){
+	DSHM_section_init(sec1_core_00);
+	DSHM_section_init(sec1_core_10);
+}
+
+
+
+//extern unsigned int shared_label1;
+
+int label5_10_00;
+
+int label5_10_00_copy1;
+
+int shared_label_1;
+int shared_label_2 = 97;
+int shared_label_10 = 0;
+
+extern int passes1;
+
+//-------
+void cIn5ms(){
+	label5_10_00_copy1 = label5_10_00;
+	shared_label_2 = 97 + passes1;
+}
+void cIn10ms(){
+
+}
+void cIn20ms(){
+
+}
+
+void cIn10msCore2(){
+	shared_label_1 = read_DSHM_section(sec1_core_00,0);
+	//shared_label_1 = shared_label_read_core(1,0,0);
+}
+void cIn20msCore2(){
+	shared_label_10 = read_shm_section(sec1_global_pointer,0);
+}
+
+//-------
+void cOut5ms(){
+	label5_10_00 = label5_10_00_copy1;
+	write_DSHM_section(sec1_core_10,0,shared_label_2);
+	//shared_label_write_core(1,0,0,shared_label_2);
+}
+void cOut10ms(){
+	write_shm_section(sec1_global_pointer,0,2);
+	//shared_label_write(0,2);
+}
+void cOut20ms(){
+
+}
+void cOut10msCore2(){
+	shared_label_1++;
+	write_shm_section(sec1_global_pointer,1,shared_label_1);
+	//shared_label_write(1,shared_label_1);
+}
+void cOut20msCore2(){
+	write_shm_section(sec1_global_pointer,3,shared_label_10 + 1);
+	//shared_label_write(3,shared_label_10 + 1);
+}
diff --git a/RTFParallella/src/parallella/label_man_core0.h b/RTFParallella/src/parallella/label_man_core0.h
new file mode 100644
index 0000000..54f6f11
--- /dev/null
+++ b/RTFParallella/src/parallella/label_man_core0.h
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ *     Copyright (c) 2019 Dortmund University of Applied Sciences and Arts and others.
+ *    
+ *     This program and the accompanying materials are made
+ *     available under the terms of the Eclipse Public License 2.0
+ *     which is available at https://www.eclipse.org/legal/epl-2.0/
+ *    
+ *     SPDX-License-Identifier: EPL-2.0
+ *    
+ *     Contributors:
+ *          Dortmund University of Applied Sciences and Arts - initial API and implementation
+ *******************************************************************************/
+
+#ifndef SRC_PARALLELLA_LABEL_MAN_CORE0_H_
+#define SRC_PARALLELLA_LABEL_MAN_CORE0_H_
+
+#include "shared_comms.h"
+#include "c2c.h"
+
+#define num_unique_sections 1
+
+void init_mem_sections(void);
+
+void init_DSHM_sections(void);
+
+//declare cIn/Out operations
+//to be set up from the amalthea model during
+//code generation
+void cIn5ms();
+void cIn10ms();
+void cIn20ms();
+void cIn10msCore2();
+void cIn20msCore2();
+//-------
+void cOut5ms();
+void cOut10ms();
+void cOut20ms();
+void cOut10msCore2();
+void cOut20msCore2();
+
+
+
+
+
+
+#endif /* SRC_PARALLELLA_LABEL_MAN_CORE0_H_ */
diff --git a/RTFParallella/src/parallella/shared_comms.c b/RTFParallella/src/parallella/shared_comms.c
index b400623..e6e6a75 100755
--- a/RTFParallella/src/parallella/shared_comms.c
+++ b/RTFParallella/src/parallella/shared_comms.c
@@ -12,33 +12,90 @@
  *******************************************************************************/
 
 #include "shared_comms.h"
+#include "e-lib.h"
 
-unsigned int *outbuf_shared[shared_mem_section1_label_count];
+typedef unsigned int e_label_size; // one word = 4 bytes = unsigned int
+
+unsigned int *outbuf_shared[SHM_DEFINED_SPACE]; //array for global section access API
+
+//The current SHM access API
+void* shm_section_init (SHM_section sec){
+	unsigned size_in_bytes = 0;
+	typedef unsigned int* cast_type;
+	if (sec.sec_type == UINT_8){
+		typedef uint8_t* cast_type;
+		size_in_bytes = sec.label_count * sizeof(uint8_t);
+	}else if (sec.sec_type == UINT_16){
+		typedef uint16_t* cast_type;
+		size_in_bytes = sec.label_count * sizeof(uint16_t);
+	}else if (sec.sec_type == UINT_32){
+		typedef uint32_t* cast_type;
+		size_in_bytes = sec.label_count * sizeof(uint32_t);
+	}else{
+		size_in_bytes = sec.label_count * sizeof(unsigned int);
+	}
+	//check if section fits in shm_dram section of the memory
+	if ((sec.base_addr | size_in_bytes)<0x01000000 || (sec.base_addr | size_in_bytes)>=0x02000000){
+		//will cause segmentation fault in Epi!
+		updateDebugFlag(404);
+		return NULL;
+	}
+	cast_type retval;
+	retval = (cast_type ) (0x8e000000 | sec.base_addr);// assign to  the ABSOLUTE address of memory section
+	int i = 0;
+	for (i = 0;i<sec.label_count;i++){
+		retval[i] = 256;
+	}
+	return retval;
+}
+
+int read_shm_section ( unsigned int* x, unsigned indx){
+	return (int) x[indx];
+}
+
+void write_shm_section (unsigned int* x, unsigned indx, int payload){
+	x[indx] = payload;
+}
+
+/**
+ * TODO use e_write/ e_read functions and DMA to constrain contention from different cores.
+ */
+unsigned int shm_section_init_read (SHM_section sec,int index){
+	typedef unsigned int cast_type;
+	if (sec.sec_type == UINT_8){
+		typedef uint8_t cast_type;
+	}else if (sec.sec_type == UINT_16){
+		typedef uint16_t cast_type;
+	}else if (sec.sec_type == UINT_32){
+		typedef uint32_t cast_type;
+	}
+	unsigned int *retval;
+	e_write((void*)&e_emem_config, retval, 0, 0, (void *)0x01000000, sizeof(unsigned int));
+	return (unsigned int) retval;
+}
+
+
+
+/**
+ * obsolete utility functions
+ * specific for global section access.
+ *
+ */
+
 
 void shared_labels_init(){
-	outbuf_shared[0] = (unsigned int *) shared_mem_section;
-	outbuf_shared[1] = outbuf_shared[0] + 1;
-	outbuf_shared[2] = outbuf_shared[1] + 1;
-	outbuf_shared[3] = outbuf_shared[2] + 1;
-	outbuf_shared[4] = outbuf_shared[3] + 1;
-	outbuf_shared[5] = outbuf_shared[4] + 1;
-	outbuf_shared[6] = outbuf_shared[5] + 1;
-	outbuf_shared[7] = outbuf_shared[6] + 1;
-	outbuf_shared[8] = outbuf_shared[7] + 1;
+	outbuf_shared[0] = (unsigned int *) (0x8e000000 | shared_mem_section);
+	for (int j = 1;j<SHM_DEFINED_SPACE;j++){
+		outbuf_shared[j] = outbuf_shared[j-1] + 1;
+	}
 	//initialize buffer
 	int i;
 	//timer1init();
-	for (i=0;i<shared_mem_section1_label_count;i++){
-		*outbuf_shared[i] =0;
+	for (i=0;i<SHM_DEFINED_SPACE;i++){
+		*outbuf_shared[i] =0x10000;
 	}
 }
 
-/*void shared_labels_init_multi(){
-
-}*/
-
-
-
 uint8_t shared_label_write(int label_indx,int payload){
 	uint8_t retval=NULL;
 	*outbuf_shared[label_indx] = payload;
diff --git a/RTFParallella/src/parallella/shared_comms.h b/RTFParallella/src/parallella/shared_comms.h
index 39eb8d7..b91bc92 100755
--- a/RTFParallella/src/parallella/shared_comms.h
+++ b/RTFParallella/src/parallella/shared_comms.h
@@ -18,15 +18,48 @@
 #include <stdint.h>
 
 
-#define shared_mem_section	0x01000000
+#define shared_mem_section	0x01001000
 
 #define shared_mem_section_2	0x01001000
 
 #define shared_mem_section1_label_count 10
 
+#define SHM_DEFINED_SPACE	256 //number of words in the shared memory section
 
 /**
- * Initiate the shared label section, this funcion will assign addresses to labels in a section,
+ * allowable sizes of labels to be used i shared memory
+ *
+ * If the label is of larger size declare it as multiple labels
+ *
+ * TODO
+ * add support for larger labels as combination of smaller ones
+ */
+typedef enum {
+    UINT_8,
+    UINT_16,
+    UINT_32
+} TYPE;
+
+
+/**
+ * defines a shared memory section
+ *
+ * Fields:
+ * base_addr: address of the first label in the section
+ * label_count: number of labels in the section
+ * sec_type: data type of the section (size of labels in the section)
+ *
+ */
+struct{
+	unsigned int 	base_addr;
+	unsigned 		label_count;
+	TYPE			sec_type;
+}typedef SHM_section;
+
+
+
+/**
+ * Initiate the shared label section, this function will assign addresses to labels in a section,
  * and initialize those labels to 0
  *
  * Arguments:
@@ -50,8 +83,70 @@
  * Arguments:
  * label_indx	:	index of the target shared label
  *
+ * Return:
+ * value of requested shared memory label
  */
 unsigned int shared_label_read(int label_indx);
 
 
+
+/**
+ * Initiate the shared label section, this function will assign addresses to labels in a section,
+ * and initialize those labels to the value of 256
+ * If the requested section does not fit in the system's shared_dram, a null
+ * pointer will be returned
+ *
+ * Arguments:
+ * sec	:	structure of type SHM_section containing
+ * 			details of the the shared memory section to be initiated
+ *
+ * Return:
+ * pointer to the initiated shared memory label
+ *
+ *
+ */
+void* shm_section_init (SHM_section sec);
+
+/**
+ * Read data from a specific label in a shared memory section
+ * This function will read one full label but the result will
+ * be cast into int (4 bytes on this platform)
+ *
+ * Segmentation fault will occur for addresses outside the shared_dram section of the system
+ * check RTFP documentation for details.
+ *
+ * Arguments:
+ * x	:	pointer to the section to be read
+ * indx	:	index of requested label
+ *
+ * Return:
+ * value of requested label in a shared memory section
+ *
+ *
+ */
+int read_shm_section ( unsigned int* x, unsigned indx);
+
+/**
+ * Write data to a specific label in a shared memory section
+ * This function will write one full label but the value will
+ * be given as int (4 bytes on this platform) to avoid overflow issues
+ *
+ * Segmentation fault will occur for addresses outside the shared_dram section of the system
+ * check RTFP documentation for details.
+ *
+ * Arguments:
+ * x		:	pointer to the section to be written to
+ * indx		:	index of requested label
+ * payload	:	value to be written (will be cast into data type of target label)
+ *
+ */
+void write_shm_section (unsigned int* x, unsigned indx, int payload);
+
+/**
+ * TODO
+ * expand this function to use DMA engine of the Epi chip
+ */
+unsigned int shm_section_init_read (SHM_section sec,int index);
+
+
 #endif /* SRC_PARALLELLA_SHARED_COMMS_H_ */
diff --git a/RTFParallella/src/parallella/taskCode.c b/RTFParallella/src/parallella/taskCode.c
index 06c4ae0..61ad00f 100755
--- a/RTFParallella/src/parallella/taskCode.c
+++ b/RTFParallella/src/parallella/taskCode.c
@@ -23,14 +23,7 @@
 int passes4 = 0;
 int passes5 = 0;
 
-//extern unsigned int shared_label1;
 
-int label5_10_00;
-
-int label5_10_00_copy1;
-
-int shared_label_1;
-int shared_label_2 = 97;
 
 //define tasks and copy operations here
 //-------
@@ -82,40 +75,4 @@
 
 
 
-//-------
-void cIn5ms(){
-	label5_10_00_copy1 = label5_10_00;
-	shared_label_2 = 97 + passes1;
-}
-void cIn10ms(){
 
-}
-void cIn20ms(){
-
-}
-
-void cIn10msCore2(){
-	shared_label_1 = shared_label_read_core(1,0,0);
-}
-void cIn20msCore2(){
-
-}
-
-//-------
-void cOut5ms(){
-	label5_10_00 = label5_10_00_copy1;
-	shared_label_write_core(1,0,0,shared_label_2);
-}
-void cOut10ms(){
-	shared_label_write(0,2);
-}
-void cOut20ms(){
-
-}
-void cOut10msCore2(){
-	shared_label_1++;
-	shared_label_write(1,shared_label_1);
-}
-void cOut20msCore2(){
-
-}
diff --git a/RTFParallella/src/parallella/taskCode.h b/RTFParallella/src/parallella/taskCode.h
index 817adff..c8001da 100755
--- a/RTFParallella/src/parallella/taskCode.h
+++ b/RTFParallella/src/parallella/taskCode.h
@@ -29,19 +29,6 @@
 void handler10msCore2();
 void handler20msCore2();
 //-------
-//declare cIn/Out operations
-//to be set up from the amalthea model during
-//code generation
-void cIn5ms();
-void cIn10ms();
-void cIn20ms();
-void cIn10msCore2();
-void cIn20msCore2();
-//-------
-void cOut5ms();
-void cOut10ms();
-void cOut20ms();
-void cOut10msCore2();
-void cOut20msCore2();
+
 
 #endif /* SRC_PARALLELLA_TASKCODE_H_ */