Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module cacheline_adaptor
  2. (
  3.     input clk,
  4.     input reset_n,
  5.  
  6.     // Port to LLC (Lowest Level Cache)
  7.     input logic [255:0] line_i,
  8.     output logic [255:0] line_o,
  9.     input logic [31:0] address_i,
  10.     input read_i,
  11.     input write_i,
  12.     output logic resp_o,
  13.  
  14.     // Port to memory
  15.     input logic [63:0] burst_i,
  16.     output logic [63:0] burst_o,
  17.     output logic [31:0] address_o,
  18.     output logic read_o,
  19.     output logic write_o,
  20.     input resp_i
  21. );
  22.  
  23. logic [63:0] burst0;
  24. logic [63:0] burst1;
  25. logic [63:0] burst2;
  26. logic [63:0] burst3;
  27.  
  28. enum int unsigned{
  29.   idle,
  30.   start_r,
  31.   start_w,
  32.   r_burst0,
  33.   r_burst1,
  34.   r_burst2,
  35.   r_burst3,
  36.   w_burst0,
  37.   w_burst1,
  38.   w_burst2,
  39.   w_burst3,
  40.   finish,
  41.   winish
  42. } state, next_state;
  43.  
  44. always_comb
  45. begin : state_actions
  46.   if(reset_n) begin
  47.     read_o = 0;
  48.     write_o = 0;
  49.     resp_o = 0;
  50.   end
  51.   case(state)
  52.     idle: begin
  53.       read_o = 0;
  54.       write_o = 0;
  55.       resp_o = 0;
  56.     end
  57.     start_r: begin
  58.       address_o = address_i;
  59.       read_o = 1;
  60.     end
  61.     start_w: begin
  62.       address_o = address_i;
  63.       write_o = 1;
  64.     end
  65.     r_burst0: begin
  66.       burst0 = burst_i;
  67.       //$display("Burst 0 is: %h", burst0);
  68.       end
  69.     r_burst1: begin
  70.       burst1 = burst_i;
  71.       //$display("Burst 1 is: %h", burst1);
  72.       end
  73.     r_burst2: begin
  74.       burst2 = burst_i;
  75.       //$display("Burst 2 is: %h", burst2);
  76.       end
  77.     r_burst3: begin
  78.       burst3 = burst_i;
  79.       //$display("Burst 3 is: %h", burst3);
  80.       end
  81.     w_burst0: begin
  82.       burst_o = line_i[63:0];
  83.       //$display("Write 0 is: %h", burst_o);
  84.     end
  85.     w_burst1: begin
  86.       burst_o = line_i[127:64];
  87.       //$display("Write 1 is: %h", burst_o);
  88.     end
  89.     w_burst2: begin
  90.       burst_o = line_i[191:128];
  91.       //$display("Write 2 is: %h", burst_o);
  92.     end
  93.     w_burst3: begin
  94.       burst_o = line_i[255:192];
  95.       //$display("Write 0 is: %h", burst_o);
  96.     end
  97.     winish: begin
  98.       write_o = 0;
  99.       resp_o = 1;
  100.     end
  101.     finish: begin
  102.       line_o = {burst3, burst2, burst1, burst0};
  103.       read_o = 0;
  104.       resp_o = 1;
  105.     end
  106.     default: ;
  107.   endcase
  108. end
  109.  
  110. always_comb
  111. begin : next_state_logic
  112.   next_state = state;
  113.   case(state)
  114.     idle: begin
  115.       if(read_i == 1) next_state = start_r;
  116.       else if(write_i == 1) next_state = start_w;
  117.     end
  118.     start_r: begin
  119.       next_state = r_burst0;
  120.     end
  121.     start_w: begin
  122.       next_state = w_burst0;
  123.     end
  124.     r_burst0: begin
  125.       if(resp_i == 1 && read_i == 0) next_state = r_burst1;
  126.     end
  127.     r_burst1: begin
  128.       next_state = r_burst2;
  129.     end
  130.     r_burst2: begin
  131.       next_state = r_burst3;
  132.     end
  133.     r_burst3: begin
  134.       if(resp_i == 0) next_state = finish;
  135.     end
  136.     w_burst0: begin
  137.       if(resp_i == 1 && read_i == 0) next_state = w_burst1;
  138.     end
  139.     w_burst1: begin
  140.       next_state = w_burst2;
  141.     end
  142.     w_burst2: begin
  143.       next_state = w_burst3;
  144.     end
  145.     w_burst3: begin
  146.       if(resp_i==0) next_state = winish;
  147.     end
  148.     finish: next_state = idle;
  149.     winish: next_state = idle;
  150.     default: ;
  151.   endcase
  152. end
  153.  
  154. always_ff @(posedge clk)
  155. begin: next_state_assignment
  156.     /* Assignment of next state on clock edge */
  157.     state <= next_state;
  158. end
  159.  
  160. endmodule : cacheline_adaptor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement