motor_axis_bank_tb.v 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. `timescale 1ns/1ps
  2. module axis_bank_case #(parameter integer N=3)(output reg done=0);
  3. reg clk=0;always #20 clk=~clk;
  4. reg rst_n=0;
  5. localparam AW=(N<=1)?1:$clog2(N);
  6. reg [AW-1:0] axis=0;
  7. reg [321:0] data=0;
  8. wire [321:0] selected;
  9. wire [N*322-1:0] diagnostic;
  10. reg [321:0] reference[0:N-1];
  11. motor_axis_state_bank #(.AXIS_COUNT(N),.PARALLEL_TELEMETRY(1)) dut(
  12. .clk(clk),.rst_n(rst_n),.axis(axis),.write_data(data),.read_data(selected),.diagnostic_data(diagnostic));
  13. integer i,checks=0,cycle;
  14. reg [31:0] random_state=32'h5EEDBEEF;
  15. reg [351:0] random_word;
  16. always @(posedge clk)begin
  17. if(!rst_n)begin
  18. axis<=0;for(i=0;i<N;i=i+1)reference[i]<=322'd1;
  19. end else begin
  20. if(selected!==reference[axis])$fatal(1,"%0d-axis rotating read is not logical axis %0d",N,axis);
  21. reference[axis]<=data;axis<=axis==N-1 ? 0 : axis+1'b1;checks=checks+1;
  22. end
  23. #1;
  24. if(selected!==reference[axis])$fatal(1,"%0d-axis post-clock rotation mismatch",N);
  25. for(i=0;i<N;i=i+1)if(diagnostic[i*322+:322]!==reference[i])$fatal(1,"%0d-axis diagnostic ordering/reset mismatch",N);
  26. end
  27. initial begin
  28. repeat(3)@(negedge clk);
  29. for(cycle=0;cycle<1200;cycle=cycle+1)begin
  30. //37 is coprime to3/12, exercising reset at every rotation position.
  31. rst_n=(cycle%37)!=0;
  32. for(i=0;i<11;i=i+1)begin
  33. random_state={random_state[30:0],random_state[31]^random_state[21]^random_state[1]^random_state[0]};
  34. random_word[i*32+:32]=random_state;
  35. end
  36. data=random_word[321:0];
  37. @(negedge clk);
  38. end
  39. if(checks<1000)$fatal(1,"rotation test was empty");
  40. $display("AXIS_BANK_%0d_CHECKS=%0d",N,checks);done=1;
  41. end
  42. endmodule
  43. module motor_axis_bank_tb;
  44. wire one,two,three,twelve;
  45. axis_bank_case #(.N(1)) a(one);
  46. axis_bank_case #(.N(2)) d(two);
  47. axis_bank_case #(.N(3)) b(three);
  48. axis_bank_case #(.N(12)) c(twelve);
  49. initial begin wait(one && two && three && twelve);$display("motor_axis_bank_tb PASS");$finish;end
  50. initial begin #100000;$fatal(1,"axis bank test deadline");end
  51. endmodule