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
| always @(posedge clk_25M) begin
if(!RST) begin
read_cnt <= 1;
WR2_flash_Addr_cnt <= WR2_Start_Addr;
WR1_flash_Addr_cnt <= WR1_Start_Addr;
state <= `idle;
flash_ctrl_cmd <= 0;
FLASH_data_direction <= 0;
delay_start <= 0;
end
else begin
case(state)
`idle: begin
flash_ctrl_cmd <= 0;
state <= `flash_write;
end
`flash_write: begin
if ((!flash_busy) || flash_ack_o) begin //checks if the flash is in idle state or in acknowledge from write process
FLASH_data_direction <= 0; //for read/write bus address switching
flash_ctrl_cmd <= `flash_ctrl_cmd_WRITE;
if ( ( WR2_flash_Addr_cnt < WR2_Max_Addr ) && flash_dat_i_req) begin //flash_dat_i_req to tell when to send the address to avoid jumping over address 0
WR2_flash_Addr_cnt <= WR2_flash_Addr_cnt + 1 ;
end else begin
WR2_flash_Addr_cnt <= WR2_Start_Addr;
state <= `flash_read;
end
end
end
`flash_read: begin
if ((!flash_busy)|| flash_ack_o ) begin
flash_ctrl_cmd <= `flash_ctrl_cmd_READ;
FLASH_data_direction <= 1;
if ( ( WR1_flash_Addr_cnt < (WR1_Max_Addr) ) && get_read_address ) begin
end else begin
WR1_flash_Addr_cnt <= WR1_Start_Addr;1;
end
end
if (dat_o_rdy ) begin
LED_out <= LED_out_o;
state <= `read_delay;
end
end
`read_delay: begin
if (!delay_busy) begin
delay_start <= 1;
end else if (delay_finish) begin
delay_start <= 0;
state <= `flash_read;
end
end
default:
state <= `idle;
endcase
end // end else
end // end always
assign flash_adr_i = FLASH_data_direction? WR1_flash_Addr_cnt: WR2_flash_Addr_cnt;
assign flash_dat_i = flash_adr_i[15:0];
cfi_ctrl flash1(
.sys_rst(oRST_0),
.flash_clk(clk_25M),
.ctrl_bus_adr_i(flash_adr_i),
.ctrl_bus_dat_i(flash_dat_i),
.ctrl_bus_dat_o(flash_dat_o),
.ctrl_cmd_i(flash_ctrl_cmd),
.req_done_o(flash_ack_o),
.busy_o(flash_busy),
.data_in_clk(flash_dat_i_req),
.flash_dq_io(flash_dq_io),
.flash_adr_o(flash_adr_o),
.flash_ce_n_o(flash_ce_n_o),
.flash_oe_n_o(flash_oe_n_o),
.flash_rst_n_o(flash_rst_n_o),
.flash_we_n_o(flash_we_n_o),
.buffer_write_complete(buffer_write_complete_o),
.LED_out (LED_out_o),
.data_o_ready(dat_o_rdy),
.get_read_addr(get_read_address)
); |