-
Notifications
You must be signed in to change notification settings - Fork 0
/
flash_bfm.sv.bak
executable file
·205 lines (172 loc) · 6.09 KB
/
flash_bfm.sv.bak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/************************************************************************************************************************************************
* *
* FLASH MEMORY CONTROLLER - BFM * *
* *
************************************************************************************************************************************************/
`timescale 1 ns / 1 fs
parameter clk_cycle = 16;
parameter clk_width = clk_cycle/2;
import flash_pkg::*;
interface flash_bfm;
/********************************* Interface variables *****************************************/
bit clk,rst;
wire [7:0] DIO;
logic CLE; // -- CLE
logic ALE; // -- ALE
logic WE_n; // -- ~WE
logic RE_n; //-- ~RE
logic CE_n; //-- ~CE
logic R_nB; //-- R/~B
logic BF_sel;
logic [10:0] BF_ad;
logic [7:0] BF_din;
logic BF_we;
logic [15:0] RWA; //-- row addr
logic [7:0] BF_dou;
logic PErr ; // -- progr err
logic EErr ; // -- erase err
logic RErr ;
bit [2:0] nfc_cmd; // -- command see below
logic nfc_strt; // -- pos edge (pulse) to start
logic nfc_done; // -- operation finished if '1'
/***********************************************************************************************/
/********************************* Internal variables ******************************************/
bit check_start;
int check_counter;
bit sb_checkstart1,sb_checkstart2,sb_checkstart3,sb_checkstart4;
int sb_counter1, sb_counter2,sb_counter3,sb_counter4;
bit sb_checkstart;
/************************************** System clock *******************************************/
initial clk = 0;
always #clk_width clk = ~clk;
/***********************************************************************************************/
/************************************ Checker Counter ******************************************/
always@ (posedge clk or posedge check_start) begin
if(check_start)
check_counter = check_counter + 1;
else begin
check_counter = 0;
check_start = 0;
end
end
/***********************************************************************************************/
/********************************* Scoreboard Counters *****************************************/
always@(posedge clk or posedge sb_checkstart1) begin
if(sb_checkstart1)
sb_counter1 =sb_counter1+1;
else
sb_counter1=0;
end
always@(posedge clk or posedge sb_checkstart2) begin
if(sb_checkstart2)
sb_counter2 =sb_counter2+1;
else
sb_counter2=0;
end
always@(posedge clk or posedge sb_checkstart3) begin
if(sb_checkstart3)
sb_counter3 =sb_counter3+1;
else
sb_counter3=0;
end
always@(posedge clk or posedge sb_checkstart4 ) begin
if(sb_checkstart4)
sb_counter4 =sb_counter4+1;
else
sb_counter4=0;
end
/***********************************************************************************************/
/************************************** Send task **********************************************/
task send(input int cmd, input logic [15:0] address);
case(cmd)
program_page : begin
@(posedge clk) ;
#3;
RWA=address;
nfc_cmd=3'b001;
nfc_strt=1'b1;
BF_sel=1'b1;
@(posedge clk) ;
#3;
nfc_strt=1'b0;
BF_ad=0;
end
read_page : begin
@(posedge clk) ;
#3;
RWA=address;
nfc_cmd=3'b010;
nfc_strt=1'b1;
BF_sel=1'b1;
BF_we=1'b0;
BF_ad=#3 0;
@(posedge clk) ;
#3;
nfc_strt=1'b0;
BF_ad=0;
end
erase : begin
@(posedge clk) ;
#3;
RWA=address;
nfc_cmd=3'b100;
nfc_strt=1'b1;
@(posedge clk) ;
#3;
nfc_strt=1'b0;
end
reset : begin
@(posedge clk) ;
nfc_cmd=3'b011;
nfc_strt=1'b1;
@(posedge clk) ;
nfc_strt=1'b0;
end
read_id : begin
@(posedge clk) ;
#3;
RWA=address;
nfc_cmd=3'b101;
nfc_strt=1'b1;
BF_sel=1'b1;
@(posedge clk) ;
#3;
nfc_strt=1'b0;
end
endcase
endtask : send
/***********************************************************************************************/
/******************************** write buffer task ********************************************/
task write_buffer(input bit bf_we, input bit[7:0] bf_din, input int i);
@(posedge clk);
#3;
BF_we = bf_we;
BF_din <= bf_din;
BF_ad <= #3 i;
endtask : write_buffer
task read_buffer(input int i);
@(posedge clk);
BF_ad<=#3 i;
endtask : read_buffer
/***********************************************************************************************/
/********************************* System reset task *******************************************/
task system_reset(input int count);
@(posedge clk)
rst <= 1'b1;
$display($time,"Entered reset block to check if it is entering in same clk");
#200;//repeat (count) @(posedge clk);
rst <= 1'b0;
endtask : system_reset
/***********************************************************************************************/
/************************************ Kill time task *******************************************/
task kill_time;
begin
@(posedge clk);
@(posedge clk);
@(posedge clk);
@(posedge clk);
@(posedge clk);
end
endtask : kill_time
/***********************************************************************************************/
endinterface : flash_bfm