/*******************************/
//FLASH 擦除,Page Program,读取程序
/*******************************/
always @ ( posedge clock20M or negedge RSTn )
if( !RSTn )
begin
i <= 7'd0;
flash_addr <= 8'd0;
flash_data<=16'd0;
cmd_type <= 2'b00;
time_delay<=0;
end
else
case( i )
7'd0://软件复位LMX器件
if( Done_Sig )
begin
i <= 1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b0000_0000;
flash_data<=16'b0010_0010_0001_1110;//16'b0000_0000_0000_0010;//
cmd_type <= 2'b10;
end
7'd1:
if( time_delay<60000 )
begin
time_delay<=time_delay+1'b1;
cmd_type <= 2'b00;
end
else
begin
i <= 2;
time_delay<=0;
end
7'd2://将MUX置为读出功能
if( Done_Sig )
begin
i <= 3;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b0000_0000;
flash_data<=16'b0010_0011_0001_1000;
cmd_type <= 2'b10;
end
7'd3:
if( time_delay<60000 )
begin
time_delay<=time_delay+1'b1;
cmd_type <= 2'b00;
end
else
begin
i <= 4;
time_delay<=0;
end
// 7'd2://读状态寄存器0, 等待idle
// if( Done_Sig )
// begin
// i <= i + 1'b1;
// cmd_type <= 2'b00;
// end
// else
// begin
// flash_addr <= 8'b1000_0000;
// cmd_type <= 2'b11;
// end
//
// 7'd3:
// if( time_delay<8'd100 )
// begin
// time_delay<=time_delay+1'b1;
// cmd_type <= 2'b00;
// end
// else
// begin
// i <= i + 1'b1;
// time_delay<=0;
// end
// if( Done_Sig )
// begin
// i <= i + 1'b1;
// cmd_type <= 2'b00;
// end
// else
// begin
// flash_addr <= 8'b0000_0000;
// flash_data<=16'd0010_0100_0001_0000;
// cmd_type <= 2'b10;
// end
// 7'd3://读状态寄存器1, 等待idle
// if( Done_Sig )
// begin
// i <= i + 1'b1;
// cmd_type <= 2'b00;
// end
// else
// begin
// flash_addr <= 8'b1000_0001;
// cmd_type <= 2'b11;
// end
7'd4://读取寄存器0
if( Done_Sig )
begin
i <= 5;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1000_0000;
cmd_type <= 2'b11;
end
7'd5:
if( time_delay<200 )
begin
time_delay<=time_delay+1'b1;
cmd_type <= 2'b00;
end
else
begin
i <= 6;
time_delay<=0;
end
// 7'd5:
// if( Done_Sig )
// begin
// i <= i + 1'b1;
// cmd_type <= 2'b00;
// end
// else
// begin
// flash_addr <= 8'b1000_0011;
// cmd_type <= 2'b11;
// end
7'd6:
if( Done_Sig )
begin
i <= 7;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1000_0100;
cmd_type <= 2'b11;
end
7'd7:
if( time_delay<200 )
begin
time_delay<=time_delay+1'b1;
cmd_type <= 2'b00;
end
else
begin
i <= 8;//i + 1'b1;
time_delay<=0;
end
// 7'd7://读状态寄存器1, 等待idle
// if( Done_Sig )
// begin
// i <= i + 1'b1;
// cmd_type <= 2'b00;
// end
// else
// begin
// flash_addr <= 8'b1000_0101;
// cmd_type <= 2'b11;
// end
7'd8://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1000_0110;
cmd_type <= 2'b11;
end
7'd9:
if( time_delay<200 )
begin
time_delay<=time_delay+1'b1;
cmd_type <= 2'b00;
end
else
begin
i <= i + 1'b1;
time_delay<=0;
end
// 7'd9://read 256byte
// if( Done_Sig )
// begin
// i <= i + 1'b1;
// cmd_type <= 2'b00;
// end
// else
// begin
// flash_addr <= 8'b1000_0111;
// cmd_type <= 2'b11;
// end
7'd10://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1000_1000;
cmd_type <= 2'b11;
end
7'd11://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1000_1001;
cmd_type <= 2'b11;
end
7'd12://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1000_1010;
cmd_type <= 2'b11;
end
7'd13://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1000_1011;
cmd_type <= 2'b11;
end
7'd14://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1000_1100;
cmd_type <= 2'b11;
end
7'd15://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1000_1101;
cmd_type <= 2'b11;
end
7'd16://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1000_1110;
cmd_type <= 2'b11;
end
7'd17://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1000_1111;
cmd_type <= 2'b11;
end
7'd18://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1001_0000;
cmd_type <= 2'b11;
end
7'd19://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1001_0001;
cmd_type <= 2'b11;
end
7'd20://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1001_0010;
cmd_type <= 2'b11;
end
7'd21://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1001_0011;
cmd_type <= 2'b11;
end
7'd22://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1001_0100;
cmd_type <= 2'b11;
end
7'd23://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1001_0101;
cmd_type <= 2'b11;
end
7'd24://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1001_0110;
cmd_type <= 2'b11;
end
7'd25://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1001_0111;
cmd_type <= 2'b11;
end
7'd26://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1001_1000;
cmd_type <= 2'b11;
end
7'd27://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1001_1001;
cmd_type <= 2'b11;
end
7'd28://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1001_1010;
cmd_type <= 2'b11;
end
7'd29://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1001_1011;
cmd_type <= 2'b11;
end
7'd30://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1001_1100;
cmd_type <= 2'b11;
end
7'd31://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1001_1101;
cmd_type <= 2'b11;
end
7'd32://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1001_1110;
cmd_type <= 2'b11;
end
7'd33://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1001_1111;
cmd_type <= 2'b11;
end
7'd34://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1010_0000;
cmd_type <= 2'b11;
end
7'd35://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1010_0001;
cmd_type <= 2'b11;
end
7'd36://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1010_0010;
cmd_type <= 2'b11;
end
7'd37://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1010_0011;
cmd_type <= 2'b11;
end
7'd38://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1010_0100;
cmd_type <= 2'b11;
end
7'd39://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1010_0101;
cmd_type <= 2'b11;
end
7'd40://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1010_0110;
cmd_type <= 2'b11;
end
7'd41://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1010_0111;
cmd_type <= 2'b11;
end
7'd42://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1010_1000;
cmd_type <= 2'b11;
end
7'd43://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1010_1001;
cmd_type <= 2'b11;
end
7'd44://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1010_1010;
cmd_type <= 2'b11;
end
7'd45://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1010_1011;
cmd_type <= 2'b11;
end
7'd46://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1010_1100;
cmd_type <= 2'b11;
end
7'd47://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1010_1101;
cmd_type <= 2'b11;
end
7'd48://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1010_1110;
cmd_type <= 2'b11;
end
7'd49://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1010_1111;
cmd_type <= 2'b11;
end
7'd50://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1011_0000;
cmd_type <= 2'b11;
end
7'd51://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1011_0001;
cmd_type <= 2'b11;
end
7'd52://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1011_0010;
cmd_type <= 2'b11;
end
7'd53://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1011_0011;
cmd_type <= 2'b11;
end
7'd54://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1011_0100;
cmd_type <= 2'b11;
end
7'd55://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1011_0101;
cmd_type <= 2'b11;
end
7'd56://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1011_0110;
cmd_type <= 2'b11;
end
7'd57://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1011_0111;
cmd_type <= 2'b11;
end
7'd58://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1011_1000;
cmd_type <= 2'b11;
end
7'd59://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1011_1001;
cmd_type <= 2'b11;
end
7'd60://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1011_1010;
cmd_type <= 2'b11;
end
7'd61://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1011_1011;
cmd_type <= 2'b11;
end
7'd62://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1011_1100;
cmd_type <= 2'b11;
end
7'd63://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1011_1101;
cmd_type <= 2'b11;
end
7'd64://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1011_1110;
cmd_type <= 2'b11;
end
7'd65://read 256byte
if( Done_Sig )
begin
i <= i + 1'b1;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1011_1111;
cmd_type <= 2'b11;
end
7'd66://read 256byte
if( Done_Sig )
begin
i <= 67;
cmd_type <= 2'b00;
end
else
begin
flash_addr <= 8'b1100_0000;
cmd_type <= 2'b11;
end
7'd67://waitting
if( time_delay<200 )
begin
time_delay<=time_delay+1'b1;
cmd_type <= 2'b00;
end
else
begin
i <= 68;
time_delay<=0;
end