📄 adv_bb.v
字号:
last_Internal_RE_time = 0 ; curr_Internal_RE_time = 0 ; InternalOutput = `MaxOutputs'hx ; last_Internal_WE_time = 0 ; curr_Internal_WE_time = 0 ; Program_Time_Word = `AC_ProgramTime_Word_27_12; Param_Erase_Time = `AC_EraseTime_Param_27_12; Main_Erase_Time = `AC_EraseTime_Main_27_12; Program_Suspend_Time = `AC_Program_Suspend_27_12; Erase_Suspend_Time = `AC_Erase_Suspend_27_12; $readmemh(`BlockFileBegin,BlocksBegin); $readmemh(`BlockFileEnd,BlocksEnd); $readmemh(`BlockFileType,BlocksType,0,`NumberOfBlocks-1); for (LoopCntr = 0; LoopCntr <= `NumberOfBlocks; LoopCntr = LoopCntr + 1) begin BlocksEraseCount [LoopCntr] = 0 ; end//------------------------------------------------------------------------// Array Init//------------------------------------------------------------------------//Constant condition expression: LoadOnPowerup == 1'b1 if (LoadOnPowerup) LoadFromFile; else begin //$display("Initializing Memory to 'hFFFF"); //for (LoopCntr = 0; LoopCntr <= `MaxAddr; LoopCntr = LoopCntr + 1) begin // MainArray [LoopCntr] = 16'hFFFF ; $display("FLASH: Initializing Memory data to address value (0, 1, 2 ...)"); for (LoopCntr = 0; LoopCntr <= 1024; LoopCntr = LoopCntr + 1) begin MainArray [LoopCntr] = LoopCntr ; end endend//------------------------------------------------------------------------// LoadFromFile// This is used when the LoadOnPowerup parameter is set so that the Main // array contains code at startup. Basically it loads the array from // data in a file (LoadFileName).//------------------------------------------------------------------------task LoadFromFile ;begin $display("FLASH: Loading from file %s",LoadFileName); $readmemh(LoadFileName,MainArray);endendtask //------------------------------------------------------------------------// StoreToFile// This is used when the SaveOnPowerDown flag is set so that the Main // Array stores code at powerdown. Basically it stores the array into// a file (SaveFileName).//-----------------------------------------------------------------task StoreToFile; reg [31:0] ArrayAddr ; reg [31:0] outfile ;begin outfile = $fopen(SaveFileName) ; if (outfile == 0) $display("FLASH: Error, cannot open output file %s",SaveFileName) ; else $display("FLASH: Saving data to file %s",SaveFileName); for (ArrayAddr = 0 ; ArrayAddr <= `MaxAddr; ArrayAddr = ArrayAddr + 1) begin $fdisplay(outfile,"%h",MainArray[ArrayAddr]); endend endtask//------------------------------------------------------------------------// Program // -- Description: Programs new values in to the array --//------------------------------------------------------------------------task Program ; inout [`Word] TheArrayValue ; input [`Word] DataIn; reg [`Word] OldData; begin OldData = TheArrayValue; TheArrayValue = DataIn & OldData; end endtaskassign Internal_OE = !(ceb | oeb | !rpb) ;assign Internal_OE2 = Internal_OE ;assign Internal_OE3 = Internal_OE2 ;assign Internal_RE = (((ReadyBusy == `Ready) || (ReadMode != `rdARRAY)) && !ceb && !Reset) ;assign Internal_WE = !(ceb | web | !rpb) ;assign InternalBoot = wpb ;//******************************************************************// Determine if the algorithm engine is operating//assign ReadyBusy = (RunningAlgorithm & !Suspended) ? `Busy : `Ready;//******************************************************************// register definitions //// Compatible Status Registerassign CSR [7] = ReadyBusy;assign CSR [6] = EraseSuspended ;assign CSR [5] = EraseError ;assign CSR [4] = ProgramError ;assign CSR [3] = VppError ;assign CSR [2] = WriteSuspended;assign CSR [1] = BlockLockStatus;assign CSR [0] = 1'b0;// Output Drivers //assign dq = (DriveOutputs == `TRUE) ? InternalOutput : 16'hz;always @(Reset) begin : Reset_process if (Reset) begin ClearVppFlag <= #1 `TRUE ; ClearVppFlag <= #9 `FALSE ; AlgDone = `FALSE ; VppError = `FALSE ; ReadMode = `rdARRAY; ReadyBusy = `Ready ; WriteSuspended = `FALSE ; EraseSuspended = `FALSE ; Suspend = `FALSE ; EraseError = `FALSE ; ProgramError = `FALSE ; BlockLockStatus = `FALSE ; AlgTime = 0 ; CmdValid = `FALSE ; WriteToPtr = `NewCmd ; CSROut = 0 ; IDOut = 0 ; endendalways @(Internal_RE or ReadMode or addr) begin : array_read if (Internal_RE && ReadMode == `rdARRAY) begin ArrayOut = MainArray[addr] ; // x16 outputs endendalways @(Internal_RE or ReadMode or addr or Internal_OE2 or ArrayOut) begin // output mux // Determine and generate the access time . ToOut = 0; if ($time > TAVQV) begin last_addr_time = $time - curr_addr_time; if ((last_addr_time < TAVQV) && ((TAVQV - last_addr_time) > ToOut)) ToOut = TAVQV - last_addr_time ; last_oe_time = $time - curr_oe_time; if ((last_oe_time < TGLQV) && ((TGLQV - last_oe_time) > ToOut)) ToOut = TGLQV - last_oe_time ; last_ce_time = $time - curr_ce_time; if ((last_ce_time < TELQV) && ((TELQV - last_ce_time) > ToOut)) ToOut = TELQV - last_ce_time ; last_rp_time = $time - curr_rp_time; if ((last_rp_time < TPHQV) && ((TPHQV - last_rp_time) > ToOut)) ToOut = TPHQV - last_rp_time ; last_ReadMode_time = $time - curr_ReadMode_time; if ((last_ReadMode_time < TAVQV) && ((TAVQV - last_ReadMode_time) > ToOut)) ToOut = TAVQV - last_ReadMode_time ; last_Internal_RE_time = $time - curr_Internal_RE_time ; if ((last_Internal_RE_time < TAVQV) && ((TAVQV - last_Internal_RE_time) > ToOut)) begin ToOut = TAVQV - last_Internal_RE_time ; end end// Output Mux with timing if (!StartUpFlag) begin case (ReadMode) `rdARRAY : begin if ( (EraseSuspended == `TRUE) && (WriteSuspended == `FALSE) && (addr >= BlocksBegin[Algorithm[`OpBlock]]) && (addr <= BlocksEnd[Algorithm[`OpBlock]]) && (oeb == `VIL) ) begin $display("FLASH: Error: Attempting to read from erase suspended block"); InternalOutput <= `MaxOutputs'hxxxx; end else if ( (WriteSuspended == `TRUE) && (EraseSuspended == `TRUE) && (addr >= BlocksBegin[SuspendedAlg[`OpBlock]]) && (addr <= BlocksEnd[SuspendedAlg[`OpBlock]]) && (oeb == `VIL)) begin $display("FLASH: Error: Attempting to read from erase suspended block"); InternalOutput <= `MaxOutputs'hxxxx; end else if ( (WriteSuspended == `TRUE) && (addr == Algorithm[`CmdAdd_1]) && (oeb == `VIL) ) begin $display("FLASH: Error: Attempting to read from write suspended address"); InternalOutput = `MaxOutputs'hxxxx; end else InternalOutput <= #ToOut ArrayOut ; end `rdCSR : begin InternalOutput <= #ToOut CSROut ; end `rdID : begin InternalOutput <= #ToOut IDOut ; end default : begin $display("FLASH: Error: illegal readmode"); end endcase endend//// other reads //always @(Internal_OE or addr) begin : other_read if (!Reset) begin if (ReadMode != `rdARRAY) begin CSROut = {8'h00,CSR} ; if (addr[0] == 1'b0) IDOut = `ID_ManufacturerB ; else IDOut = `ID_DeviceCodeB ; end endend// Handle Write to Partalways @(negedge Internal_WE) begin : handle_write reg [`Word] temp ; // temporary variable needed for double // indexing CmdData. if (!Reset) begin case (WriteToPtr) // Where are we writting to ? `NewCmd : begin // This is a new command. Cmd[`Cmd] = dq[7:0]; Cmd[`Add] = addr[`AddrSize-1:0]; //by 16 word index CmdValid <= `TRUE ; // CmdValid sends it to the Predecode section DataPtr <= -1; end `CmdField : begin // This is data used by another command if (DataPtr == 1) begin Cmd[`CmdData_1] = dq[`Word]; Cmd[`CmdAdd_1] = addr[`AddrSize-1:0]; end else if (DataPtr == 2) begin Cmd[`CmdData_2] = dq[`Word]; Cmd[`CmdAdd_2] = addr[`AddrSize-1:0]; end else $display("FLASH: DataPtr out of range"); DataPtr <= #1 DataPtr - 1 ; // When DataPtr = 0 the command goes to Decode section end default : begin $display("FLASH: Error: Write To ? Cmd"); end endcase endend//// Predecode Command//always @(posedge CmdValid) begin : predecode reg [`Byte] temp; // temporary variable needed for double // indexing BSR. if (!Reset) begin // Set Defaults Cmd [`OpType] = `Program ; WriteToPtr = `NewCmd ; DataPtr <= 0 ; case (Cmd [`Cmd]) // Handle the basic read mode commands // READ ARRAY COMMAND -- `ReadArrayCmd : begin // Read Flash Array CmdValid <= `FALSE ; if (ReadyBusy == `Busy) // Can not read array when running an algorithm ReadMode <= `rdCSR ; else ReadMode <= `rdARRAY ; end // READ INTELLIGENT IDENTIFIER COMMAND -- `ReadIDCmd : begin // Read Intelligent ID if ((WriteSuspended == `TRUE) || (EraseSuspended == `TRUE)) $display("FLASH: Invalid read ID command during suspend"); else ReadMode <= `rdID ; CmdValid <= `FALSE ; end // READ COMPATIBLE STATUS REGISTER COMMAND -- `ReadCSRCmd : begin // Read CSR ReadMode <= `rdCSR ; CmdValid <= `FALSE ; end default : begin Other = `TRUE ; // Other flag marks commands that are algorithms Cmd [`Confirm] = `FALSE ; // Defaults case (Cmd [`Cmd]) // PROGRAM WORD COMMAND -- `ProgramCmd : begin // Program Word if (WriteSuspended == `TRUE) begin $display("FLASH: Error: Program Command during Write Suspend"); CmdValid <= `FALSE; end else begin WriteToPtr = `CmdField; DataPtr <= 1; if (EraseSuspended == `TRUE) begin TimeLeft = AlgTime; SuspendedAlg = Algorithm; end ToBeSuspended = `Program; Cmd [`Time] = Program_Time_Word; end end // PROGRAM WORD COMMAND -- `Program2Cmd : begin // Program Word if (WriteSuspended == `TRUE) begin $display("FLASH: Error: Program Command during Write Suspend"); CmdValid <= `FALSE; end else begin Cmd [`Cmd] = `ProgramCmd; WriteToPtr = `CmdField; DataPtr <= 1; if (EraseSuspended == `TRUE) begin TimeLeft = AlgTime; SuspendedAlg = Algorithm; end ToBeSuspended = `Program; Cmd [`Time] = Program_Time_Word ; end end // ERASE BLOCK COMMAND -- `EraseBlockCmd : begin // Single Block Erase if ((WriteSuspended == `TRUE) || (EraseSuspended == `TRUE)) begin $display("FLASH: Attempted to erase block while suspended"); CmdValid <= `FALSE; end else begin WriteToPtr = `CmdField; DataPtr <= 1;// Cmd [`Time] = `AC_EraseTime ; Cmd [`OpType] = `Erase; Cmd [`Confirm] = `TRUE; ToBeSuspended = `Erase; end end default : begin // The remaining commands are complex non-algorithm commands Other = `FALSE ; CmdValid = `FALSE ; // CLEAR STATUS REGISTER COMMAND if (Cmd [`Cmd] == `ClearCSRCmd) begin if (WriteSuspended | EraseSuspended) ReadMode <= `rdARRAY; else if (ReadyBusy == `Busy) ReadMode <= `rdCSR; else begin EraseError <= `FALSE; ProgramError <= `FALSE; VppError <= `FALSE; BlockLockStatus <= `FALSE; ReadMode <= `rdCSR; end end // RESUME COMMAND -- else if (Cmd [`Cmd] == `ResumeCmd) begin if (WriteSuspended | EraseSuspended) ReadMode <= `rdCSR; Suspend = `FALSE; if (ToBeSuspended == `Program) WriteSuspended <= `FALSE; else EraseSuspended <= `FALSE; ReadyBusy = `Busy; end // SUSPEND COMMAND -- else if (Cmd [`Cmd] == `SuspendCmd) begin if (ReadyBusy == `Ready) begin ReadMode <= `rdARRAY; $display("FLASH: Algorithm finished; nothing to suspend"); end else begin ReadMode <= `rdCSR; Suspend = `TRUE; end CmdValid <= `FALSE; end else begin CmdValid <= `FALSE; $display("FLASH: Warning:Illegal Command (%h)", Cmd [`Cmd]); // Added displaying command code,--- RU 9/10/99 end end //default
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -