blob: 050fe2ebd94ff9a5dc88f509d7e70ecec29f51df [file] [log] [blame]
Mahmoud Bazzal69a0a242019-08-22 17:36:17 +02001/*******************************************************************************
2 * Copyright (c) 2019 Dortmund University of Applied Sciences and Arts and others.
3 *
4 * This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License 2.0
6 * which is available at https://www.eclipse.org/legal/epl-2.0/
7 *
8 * SPDX-License-Identifier: EPL-2.0
9 *
10 * Contributors:
11 * Dortmund University of Applied Sciences and Arts - initial API and implementation
12 *******************************************************************************/
13
14#include <stdlib.h>
15#include <stdio.h>
16#include <string.h>
17#include <unistd.h>
18#include <e-hal.h> //hardware abstraction library
19#include <time.h> /* Needed for struct timespec */
Anand Prakashf3644672020-08-21 15:11:08 +020020#include <e-loader.h>
Mahmoud Bazzal69a0a242019-08-22 17:36:17 +020021
Anand Prakashf3644672020-08-21 15:11:08 +020022#include "RTFParallellaConfig.h"
Mahmoud Bazzal69a0a242019-08-22 17:36:17 +020023#include "c2c.h"
24#include "debugFlags.h"
25#include "shared_comms.h"
26#include "host_utils.h"
27#include "model_enumerations.h"
28
29unsigned int shared_label_to_read[10];
Anand Prakashf3644672020-08-21 15:11:08 +020030unsigned int shared_label_core_00[DSHM_SEC_LABEL_COUNT];
31unsigned int shared_label_core_10[DSHM_SEC_LABEL_COUNT];
Mahmoud Bazzal69a0a242019-08-22 17:36:17 +020032
33int main()
34{
35 int label_enable_count_core0 = 0;
36 printf("RTFP demo host code\n");
37 //setup visualization config for the first core
Anand Prakashf3644672020-08-21 15:11:08 +020038 unsigned index_array1[DSHM_SEC_LABEL_COUNT];
39 unsigned index_array1_prv_val[DSHM_SEC_LABEL_COUNT];
40 array_init(index_array1,DSHM_SEC_LABEL_COUNT);
41 array_init(index_array1_prv_val,DSHM_SEC_LABEL_COUNT);
Mahmoud Bazzal69a0a242019-08-22 17:36:17 +020042 LabelVisual core1 = get_user_input(index_array1);
43 //setup visualization config for the first core
Anand Prakashf3644672020-08-21 15:11:08 +020044 unsigned index_array2[DSHM_SEC_LABEL_COUNT];
45 unsigned index_array2_prv_val[DSHM_SEC_LABEL_COUNT];
46 array_init(index_array2,DSHM_SEC_LABEL_COUNT);
47 array_init(index_array2_prv_val,DSHM_SEC_LABEL_COUNT);
Mahmoud Bazzal69a0a242019-08-22 17:36:17 +020048 LabelVisual core2 = get_user_input(index_array2);
49 //steup visualization for shared memeory
50 unsigned index_array_DRAM[shared_mem_section1_label_count];
51 unsigned index_array_prv_DRAM[shared_mem_section1_label_count];
52 array_init(index_array_DRAM,shared_mem_section1_label_count);
53 array_init(index_array_prv_DRAM,shared_mem_section1_label_count);
54 unsigned dram_indices = get_user_input_DRAM(index_array_DRAM);
55
56 //counters for row and column, cored id and loop counter
57 unsigned row_loop,col_loop;
58 // this will contain the epiphany platform configuration
59 e_platform_t epiphany;
60 e_epiphany_t dev;
61 e_return_stat_t result;
62 unsigned int message[9];
63 unsigned int message2[9];
64 int loop;
65 int addr;
66 e_mem_t emem;
67 e_init(NULL); // initialise the system establish connection to the Device
68 //initial ecore is set to 0,0
69 /*
70 * reserve shared mem sections
71 * one section for each shared label in the model
72 * shared mem address space starts at 0x0100_0000
73 * and ends at 0x3FFF_FFFF
74 *
75 */
76 e_alloc(&emem, shared_mem_section , sizeof(shared_label_to_read));
77 e_reset_system(); // reset the epiphnay chip
78 e_get_platform_info(&epiphany);//gets the configuration info for the parallella platofrm
79 //debug flag
80 //------------------------------------------------
81 //one core within the parallella work group is 1 x 1 i.e single core
82 e_open(&dev,0,0,2,1); //2 rows one column rectangle size 2*1
83 //reset the group
84 e_reset_group(&dev);
85 e_return_stat_t result1;
86 e_return_stat_t result2;
87 //load the group
88 result1 = e_load("core0_main.elf",&dev,0,0,E_FALSE);
89 result2 = e_load("core1_main.elf",&dev,1,0,E_FALSE);
90 if (result1 != E_OK || result2 != E_OK){
91 fprintf(stderr,"Error Loading the Epiphany Application 1 %i\n", result);
92 }
93 e_start_group(&dev);
94 fprintf(stderr,"Legend: \n");
95 fprintf(stderr,"--------\n");
96 fprintf(stderr," Tick -> RTOS tick \n");
97 fprintf(stderr," Core 1 -> (0,0) \n");
98 fprintf(stderr," Core 2 -> (1,0) \n");
99 fprintf(stderr," THC -> Task Holding Core(row, column) \n");
100 fprintf(stderr," L -> Local core memory \n");
101 fprintf(stderr," F -> Foreign memory (DRAM) \n");
102 fprintf(stderr,"(L,row,column,indx) -> Label of index _indx_ on Local core memory(row, column) \n");
103 fprintf(stderr,"----------------------------------------------\n");
104
105 fprintf(stderr,"RFTP demo started \n");
106 addr = cnt_address;
107 int pollLoopCounter = 0;
108 int taskMessage;
109 int prevtaskMessage;
110 int prevpollLoopCounter = 0;
111 unsigned int chainLatencyEndIndicator = 0;
112 unsigned int chainLatencyStartIndicator = 10e6;
113 unsigned int lat1 = 0;
114 int label_to_feed_in = 97;
115 fprintf(stderr,"===========================================================================\n");
116 fprintf(stderr," | Tasks being executed| Shared labels' values |\n");
117 fprintf(stderr,"tick | Core 1 | Core 2 |");
118 user_config_print_legend(core1,index_array1);
119 user_config_print_legend(core2,index_array2);
120 user_config_print_legend_auto(dram_indices,index_array_DRAM);
121
122 fprintf(stderr,"\n");
123 fprintf(stderr,"===========================================================================\n");
124
125 int prev1,prev2,prev3;
126 for (pollLoopCounter=0;pollLoopCounter<=40;pollLoopCounter++){
127 message[3] = 0;
128 e_read(&dev,0,0,addr, &message, sizeof(message));
Anand Prakashf3644672020-08-21 15:11:08 +0200129 e_read(&dev,0,0,DSHM_LABEL_EPI_CORE_OFFSET, &shared_label_core_00, sizeof(shared_label_core_00));
Mahmoud Bazzal69a0a242019-08-22 17:36:17 +0200130 e_read(&dev,1,0,addr, &message2, sizeof(message2));
Anand Prakashf3644672020-08-21 15:11:08 +0200131 e_read(&dev,1,0,DSHM_LABEL_EPI_CORE_OFFSET, &shared_label_core_10, sizeof(shared_label_core_10));
Mahmoud Bazzal091c21b2019-09-26 15:49:21 +0200132 e_read(&emem,0,0,0x00, &shared_label_to_read, 10*sizeof(unsigned int));
Mahmoud Bazzal69a0a242019-08-22 17:36:17 +0200133 if (message[8]!= message2[8] ){
134 //fprintf(stderr,"NIS->");
135 }
136 fprintf(stderr, "%4d |",message[8]+1);
137 fprintf(stderr," %4u |", message[6]);
138 fprintf(stderr," %4u |", message2[6]);
139 user_config_print_values(core1,index_array1,shared_label_core_00,index_array1_prv_val);
140 user_config_print_values(core2,index_array2,shared_label_core_10,index_array2_prv_val);
141 user_config_print_values_auto(dram_indices,index_array_DRAM,shared_label_to_read,index_array_prv_DRAM);
142 fprintf(stderr,"\n");
143 nsleep(1);
144 }
145 fprintf(stderr,"----------------------------------------------\n");
146 e_close(&dev);
147 e_finalize();
148 //----------------------------------------------------------------------------
149 //----------------------------------------------------------------------------
150 fprintf(stderr,"RFTP demo complete \n ");
151 return 0;
152}
153