105def print_bram_content(dut):
106 """Printing contents of Block RAM and saving them to a file"""
107
108
109
110
111 print("===================================================================")
112
113
114
115
116
117
118
119
120
121
122
123 items_inside_bram_emulator = dir(dut.dataOut_initRegMemFromFileModule)
124 mem_items = []
125
126 for item in items_inside_bram_emulator:
127 if item.startswith("mem_"):
128 mem_items.append(item)
129
130
131
132
133 sorted_list = sorted(mem_items, key=extract_number)
134
135 with open("script_buffer_response.txt", "w") as file:
136
137 file.write("Content of BRAM after emulation:\n")
138 print("Content of BRAM after emulation:")
139
140
141
142
143 address_of_ps_to_pl_communication = "mem_0"
144 address_of_ps_to_pl_communication_checksum1 = "mem_0"
145 address_of_ps_to_pl_communication_checksum2 = "mem_1"
146 address_of_ps_to_pl_communication_indicator1 = "mem_2"
147 address_of_ps_to_pl_communication_indicator2 = "mem_3"
148 address_of_ps_to_pl_communication_type_of_packet = "mem_4"
149 address_of_ps_to_pl_communication_requested_action_of_the_packet = "mem_5"
150 address_of_ps_to_pl_communication_start_of_data = "mem_6"
151
152 len_of_sorted_list_div_by_2 = int(len(sorted_list) / 2)
153 address_of_pl_to_ps_communication = "mem_" + str(len_of_sorted_list_div_by_2)
154 address_of_pl_to_ps_communication_checksum1 = "mem_" + str(len_of_sorted_list_div_by_2 + 0)
155 address_of_pl_to_ps_communication_checksum2 = "mem_" + str(len_of_sorted_list_div_by_2 + 1)
156 address_of_pl_to_ps_communication_indicator1 = "mem_" + str(len_of_sorted_list_div_by_2 + 2)
157 address_of_pl_to_ps_communication_indicator2 = "mem_" + str(len_of_sorted_list_div_by_2 + 3)
158 address_of_pl_to_ps_communication_type_of_packet = "mem_" + str(len_of_sorted_list_div_by_2 + 4)
159 address_of_pl_to_ps_communication_requested_action_of_the_packet = "mem_" + str(len_of_sorted_list_div_by_2 + 5)
160 address_of_pl_to_ps_communication_start_of_data = "mem_" + str(len_of_sorted_list_div_by_2 + 6)
161
162 print("Address of PL to PS communication: " + address_of_pl_to_ps_communication)
163
164 for item in sorted_list:
165 element = getattr(dut.dataOut_initRegMemFromFileModule, item)
166
167
168
169
170
171
172
173
174
175 int_content = int(str(element.value), 2)
176
177
178
179
180 hex_string = f'{int_content:08x}'
181
182 final_string = ""
183 if len(item) == 5:
184 final_string = item + ": " + hex_string
185 elif len(item) == 6:
186 final_string = item + ": " + hex_string
187 else:
188 final_string = item + ": " + hex_string
189
190
191
192
193 if item == address_of_ps_to_pl_communication:
194 file.write("\nPS to PL area:\n")
195 print("\nPS to PL area:")
196 elif item == address_of_pl_to_ps_communication:
197 file.write("\nPL to PS area:\n")
198 print("\nPL to PS area:")
199
200 if item == address_of_ps_to_pl_communication_checksum1 or \
201 item == address_of_ps_to_pl_communication_checksum2 or \
202 item == address_of_pl_to_ps_communication_checksum1 or \
203 item == address_of_pl_to_ps_communication_checksum2:
204 final_string = final_string + " | Checksum"
205 elif item == address_of_ps_to_pl_communication_indicator1 or \
206 item == address_of_ps_to_pl_communication_indicator2 or \
207 item == address_of_pl_to_ps_communication_indicator1 or \
208 item == address_of_pl_to_ps_communication_indicator2:
209 final_string = final_string + " | Indicator"
210 elif item == address_of_ps_to_pl_communication_type_of_packet or \
211 item == address_of_pl_to_ps_communication_type_of_packet:
212 final_string = final_string + " | TypeOfThePacket"
213 elif item == address_of_ps_to_pl_communication_requested_action_of_the_packet or \
214 item == address_of_pl_to_ps_communication_requested_action_of_the_packet:
215 final_string = final_string + " | RequestedActionOfThePacket"
216 elif item == address_of_ps_to_pl_communication_start_of_data or \
217 item == address_of_pl_to_ps_communication_start_of_data:
218 final_string = final_string + " | Start of Optional Data"
219
220
221
222
223 file.write(final_string + "\n")
224 print(final_string)
225
226 print("\n===================================================================\n")
227
228
229
230
231