File Operations are inevitable in ModelSim. Check the code operations in the window. Below is a piece of test code in my own M sequence experiment.
1 integer I, J, K, M; 2 3 integer m_datafile, 4 indatafile, 5 oudatafile; 6 7 Reg [] I _data [0: 9999]; 8 9 10 initial 11 begin 12 m_datafile = $ fopen (". /m_data.dat "); // M sequence storage file 13 indatafile = $ fopen (". /indata. dat "); // random number (data used for sending) storage file 14 oudatafile = $ fopen (". /oudata. dat "); // The storage file for receiving data 15 for (I = 0; I <10000; I = I + 1) 16 begin 17 I _data [I] = $ random % 16; 18 $ fdisplay (indatafile, "% B", I _data [I]); 19 end 20 $ fclose (indatafile ); 21 End 22 23 always @ (posedge clock) 24 if (reset) 25 begin: wirte_file26 $ fdisplay (m_datafile, "% B", my_m.m_sequ); // The M sequence stores 27 end
The following section shows the validation output. If an error occurs in the received or sent data, an error message is displayed.
1 Reg [] decode_data [0: 9999]; 2 3 always @ (posedge clk1) 4 If (! Reset1) 5 begin 6 K <= 0; 7 m <= 0; 8 end 9 else if (reset) & (fi_flag )) 10 begin 11 // decode_data [k] <= my_encode.ana_sign; 12 k <= k + 1; 13 $ fdisplay (oudatafile, "% B", my_encode.ana_sign ); // Save the received data for 14 15 16 if (I _data [K-2] = my_encode.ana_sign) 17 $ display ("% B OK! % B ", I _data [K-2], my_encode.ana_sign); 18 else 19 begin 20 m <= m + 1; 21 $ display (" % B error! % B ", I _data [K-2], my_encode.ana_sign); 22 end
As for I _data [K-2], why is this-2 because the data failover period is 2 clock