⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oc8051_memory_interface.v

📁 verilog code,about oc8051
💻 V
📖 第 1 页 / 共 3 页
字号:
    bit_out = bit_in;  endend///////////////////////////////// ram_adr_sel///////////////////////////////always @(rd_sel or sp or ri or rn or imm or dadr_o[15:0] or bank)begin  case (rd_sel) /* synopsys full_case parallel_case */    `OC8051_RRS_RN   : rd_addr = {3'h0, rn};    `OC8051_RRS_I    : rd_addr = ri;    `OC8051_RRS_D    : rd_addr = imm;    `OC8051_RRS_SP   : rd_addr = sp;    `OC8051_RRS_B    : rd_addr = `OC8051_SFR_B;    `OC8051_RRS_DPTR : rd_addr = `OC8051_SFR_DPTR_LO;    `OC8051_RRS_PSW  : rd_addr = `OC8051_SFR_PSW;    `OC8051_RRS_ACC  : rd_addr = `OC8051_SFR_ACC;//    default          : rd_addr = 2'bxx;  endcaseend////always @(wr_sel or sp_w or rn_r or imm_r or ri_r or imm2_r or op1_r or dadr_o[15:0])begin  case (wr_sel) /* synopsys full_case parallel_case */    `OC8051_RWS_RN : wr_addr = {3'h0, rn_r};    `OC8051_RWS_I  : wr_addr = ri_r;    `OC8051_RWS_D  : wr_addr = imm_r;    `OC8051_RWS_SP : wr_addr = sp_w;    `OC8051_RWS_D3 : wr_addr = imm2_r;    `OC8051_RWS_B  : wr_addr = `OC8051_SFR_B;//    default        : wr_addr = 2'bxx;  endcaseendalways @(posedge clk or posedge rst)  if (rst)    rd_ind <= #1 1'b0;  else if ((rd_sel==`OC8051_RRS_I) || (rd_sel==`OC8051_RRS_SP))    rd_ind <= #1 1'b1;  else    rd_ind <= #1 1'b0;always @(wr_sel)  if ((wr_sel==`OC8051_RWS_I) || (wr_sel==`OC8051_RWS_SP))    wr_ind = 1'b1;  else    wr_ind = 1'b0;/////////////////////////////////  rom_addr_sel/////////////////////////////////// output address is alu destination// (instructions MOVC)//assign iadr_o = (istb_t & !iack_i) ? iadr_t : pc_out;assign iadr_o = (istb_t) ? iadr_t : pc_out;always @(posedge clk or posedge rst)begin  if (rst) begin    iadr_t <= #1 23'h0;    istb_t <= #1 1'b0;    imem_wait <= #1 1'b0;    idat_ir <= #1 24'h0;  end else if (mem_act==`OC8051_MAS_CODE) begin    iadr_t <= #1 alu;    istb_t <= #1 1'b1;    imem_wait <= #1 1'b1;  end else if (ea_rom_sel && imem_wait) begin    imem_wait <= #1 1'b0;  end else if (!imem_wait && istb_t) begin    istb_t <= #1 1'b0;  end else if (iack_i) begin    imem_wait <= #1 1'b0;    idat_ir <= #1 idat_i [23:0];  endend///////////////////////////////// ext_addr_sel///////////////////////////////assign dadr_o = dadr_ot;always @(posedge clk or posedge rst)begin  if (rst) begin    dwe_o <= #1 1'b0;    dmem_wait <= #1 1'b0;    dstb_o <= #1 1'b0;    ddat_o <= #1 8'h00;    dadr_ot <= #1 23'h0;  end else if (dack_i) begin    dwe_o <= #1 1'b0;    dstb_o <= #1 1'b0;    dmem_wait <= #1 1'b0;  end else begin    case (mem_act) /* synopsys full_case parallel_case */      `OC8051_MAS_DPTR_R: begin  // read from external rom: acc=(dptr)        dwe_o <= #1 1'b0;        dstb_o <= #1 1'b1;        ddat_o <= #1 8'h00;        dadr_ot <= #1 {7'h0, dptr};        dmem_wait <= #1 1'b1;      end      `OC8051_MAS_DPTR_W: begin  // write to external rom: (dptr)=acc        dwe_o <= #1 1'b1;        dstb_o <= #1 1'b1;        ddat_o <= #1 acc;        dadr_ot <= #1 {7'h0, dptr};        dmem_wait <= #1 1'b1;      end      `OC8051_MAS_RI_R:   begin  // read from external rom: acc=(Ri)        dwe_o <= #1 1'b0;        dstb_o <= #1 1'b1;        ddat_o <= #1 8'h00;        dadr_ot <= #1 {15'h0, ri};        dmem_wait <= #1 1'b1;      end      `OC8051_MAS_RI_W: begin    // write to external rom: (Ri)=acc        dwe_o <= #1 1'b1;        dstb_o <= #1 1'b1;        ddat_o <= #1 acc;        dadr_ot <= #1 {15'h0, ri};        dmem_wait <= #1 1'b1;      end    endcase  endend///////////////////////////////// op_select///////////////////////////////always @(posedge clk or posedge rst)begin  if (rst) begin    idat_cur <= #1 32'h0;    idat_old <= #1 32'h0;  end else if ((iack_i | ea_rom_sel) & (inc_pc | pc_wr_r2)) begin    idat_cur <= #1 ea_rom_sel ? idat_onchip : idat_i;    idat_old <= #1 idat_cur;  endendalways @(posedge clk or posedge rst)begin  if (rst) begin    cdata <= #1 8'h00;    cdone <= #1 1'b0;  end else if (istb_t) begin    cdata <= #1 ea_rom_sel ? idat_onchip[7:0] : idat_i[7:0];    cdone <= #1 1'b1;  end else begin    cdone <= #1 1'b0;  endendalways @(op_pos or idat_cur or idat_old)begin  case (op_pos)  /* synopsys parallel_case */    3'b000: begin       op1 = idat_old[7:0]  ;       op2 = idat_old[15:8] ;       op3 = idat_old[23:16];      end    3'b001: begin       op1 = idat_old[15:8] ;       op2 = idat_old[23:16];       op3 = idat_old[31:24];      end    3'b010: begin       op1 = idat_old[23:16];       op2 = idat_old[31:24];       op3 = idat_cur[7:0]  ;      end    3'b011: begin       op1 = idat_old[31:24];       op2 = idat_cur[7:0]  ;       op3 = idat_cur[15:8] ;      end    3'b100: begin       op1 = idat_cur[7:0]  ;       op2 = idat_cur[15:8] ;       op3 = idat_cur[23:16];      end    default: begin       op1 = idat_cur[15:8] ;       op2 = idat_cur[23:16];       op3 = idat_cur[31:24];      end  endcaseend/*assign op1 = ea_rom_sel ? idat_onchip[7:0]   : op1_xt;assign op2 = ea_rom_sel ? idat_onchip[15:8]  : op2_xt;assign op3 = ea_rom_sel ? idat_onchip[23:16] : op3_xt;*/always @(dack_ir or ddat_ir or op1_o or iram_out or cdone or cdata)  if (dack_ir)    op1_out = ddat_ir;  else if (cdone)    op1_out = cdata;  else    op1_out = op1_o;assign op3_out = (rd) ? op3_o : op3_buff;assign op2_out = (rd) ? op2_o : op2_buff;always @(idat_i or iack_i or idat_ir or rd)begin  if (iack_i) begin    op1_xt = idat_i[7:0];    op2_xt = idat_i[15:8];    op3_xt = idat_i[23:16];  end else if (!rd) begin    op1_xt = idat_ir[7:0];    op2_xt = idat_ir[15:8];    op3_xt = idat_ir[23:16];  end else begin    op1_xt = 8'h00;    op2_xt = 8'h00;    op3_xt = 8'h00;  endend//// in case of interruptsalways @(op1 or op2 or op3 or int_ack_t or int_vec_buff or iack_i or ea_rom_sel)begin  if (int_ack_t && (iack_i || ea_rom_sel)) begin    op1_o = `OC8051_LCALL;    op2_o = 8'h00;    op3_o = int_vec_buff;  end else begin    op1_o = op1;    op2_o = op2;    op3_o = op3;  endend////in case of retialways @(posedge clk or posedge rst)  if (rst) reti <= #1 1'b0;  else if ((op1_o==`OC8051_RETI) & rd & !mem_wait) reti <= #1 1'b1;  else reti <= #1 1'b0;//// remember inputsalways @(posedge clk or posedge rst)begin  if (rst) begin    op2_buff <= #1 8'h0;    op3_buff <= #1 8'h0;  end else if (rd) begin    op2_buff <= #1 op2_o;    op3_buff <= #1 op3_o;  endend/////////////////////////////////  pc///////////////////////////////always @(op1_out)begin        casex (op1_out) /* synopsys parallel_case */          `OC8051_ACALL :  op_length = 2'h2;          `OC8051_AJMP :   op_length = 2'h2;        //op_code [7:3]          `OC8051_CJNE_R : op_length = 2'h3;          `OC8051_DJNZ_R : op_length = 2'h2;          `OC8051_MOV_DR : op_length = 2'h2;          `OC8051_MOV_CR : op_length = 2'h2;          `OC8051_MOV_RD : op_length = 2'h2;        //op_code [7:1]          `OC8051_CJNE_I : op_length = 2'h3;          `OC8051_MOV_ID : op_length = 2'h2;          `OC8051_MOV_DI : op_length = 2'h2;          `OC8051_MOV_CI : op_length = 2'h2;        //op_code [7:0]          `OC8051_ADD_D :  op_length = 2'h2;          `OC8051_ADD_C :  op_length = 2'h2;          `OC8051_ADDC_D : op_length = 2'h2;          `OC8051_ADDC_C : op_length = 2'h2;          `OC8051_ANL_D :  op_length = 2'h2;          `OC8051_ANL_C :  op_length = 2'h2;          `OC8051_ANL_DD : op_length = 2'h2;          `OC8051_ANL_DC : op_length = 2'h3;          `OC8051_ANL_B :  op_length = 2'h2;          `OC8051_ANL_NB : op_length = 2'h2;          `OC8051_CJNE_D : op_length = 2'h3;          `OC8051_CJNE_C : op_length = 2'h3;          `OC8051_CLR_B :  op_length = 2'h2;          `OC8051_CPL_B :  op_length = 2'h2;          `OC8051_DEC_D :  op_length = 2'h2;          `OC8051_DJNZ_D : op_length = 2'h3;          `OC8051_INC_D :  op_length = 2'h2;          `OC8051_JB :     op_length = 2'h3;          `OC8051_JBC :    op_length = 2'h3;          `OC8051_JC :     op_length = 2'h2;          `OC8051_JNB :    op_length = 2'h3;          `OC8051_JNC :    op_length = 2'h2;          `OC8051_JNZ :    op_length = 2'h2;          `OC8051_JZ :     op_length = 2'h2;          `OC8051_LCALL :  op_length = 2'h3;          `OC8051_LJMP :   op_length = 2'h3;          `OC8051_MOV_D :  op_length = 2'h2;          `OC8051_MOV_C :  op_length = 2'h2;          `OC8051_MOV_DA : op_length = 2'h2;          `OC8051_MOV_DD : op_length = 2'h3;          `OC8051_MOV_CD : op_length = 2'h3;          `OC8051_MOV_BC : op_length = 2'h2;          `OC8051_MOV_CB : op_length = 2'h2;          `OC8051_MOV_DP : op_length = 2'h3;          `OC8051_ORL_D :  op_length = 2'h2;          `OC8051_ORL_C :  op_length = 2'h2;          `OC8051_ORL_AD : op_length = 2'h2;          `OC8051_ORL_CD : op_length = 2'h3;          `OC8051_ORL_B :  op_length = 2'h2;          `OC8051_ORL_NB : op_length = 2'h2;          `OC8051_POP :    op_length = 2'h2;          `OC8051_PUSH :   op_length = 2'h2;          `OC8051_SETB_B : op_length = 2'h2;          `OC8051_SJMP :   op_length = 2'h2;          `OC8051_SUBB_D : op_length = 2'h2;          `OC8051_SUBB_C : op_length = 2'h2;          `OC8051_XCH_D :  op_length = 2'h2;          `OC8051_XRL_D :  op_length = 2'h2;          `OC8051_XRL_C :  op_length = 2'h2;          `OC8051_XRL_AD : op_length = 2'h2;          `OC8051_XRL_CD : op_length = 2'h3;          default:         op_length = 2'h1;        endcaseend/*always @(posedge clk or posedge rst)begin    if (rst) begin      op_length = 2'h2;//    end else if (pc_wait) begin    end else begin        casex (op1_out)          `OC8051_ACALL :  op_length <= #1 2'h2;          `OC8051_AJMP :   op_length <= #1 2'h2;        //op_code [7:3]          `OC8051_CJNE_R : op_length <= #1 2'h3;          `OC8051_DJNZ_R : op_length <= #1 2'h2;          `OC8051_MOV_DR : op_length <= #1 2'h2;          `OC8051_MOV_CR : op_length <= #1 2'h2;          `OC8051_MOV_RD : op_length <= #1 2'h2;        //op_code [7:1]          `OC8051_CJNE_I : op_length <= #1 2'h3;          `OC8051_MOV_ID : op_length <= #1 2'h2;          `OC8051_MOV_DI : op_length <= #1 2'h2;          `OC8051_MOV_CI : op_length <= #1 2'h2;        //op_code [7:0]          `OC8051_ADD_D :  op_length <= #1 2'h2;          `OC8051_ADD_C :  op_length <= #1 2'h2;          `OC8051_ADDC_D : op_length <= #1 2'h2;          `OC8051_ADDC_C : op_length <= #1 2'h2;          `OC8051_ANL_D :  op_length <= #1 2'h2;          `OC8051_ANL_C :  op_length <= #1 2'h2;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -