You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fram.sv.bak 1.8KB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. module spi(bus.spi_port b, fram_if.fram_port_top i);
  2. parameter ringbuffer_size = 256;
  3. logic [19:0] FRAM_Adr;
  4. logic [7:0] FRAM_DATA_OUT;
  5. logic [7:0] FRAM_DATA_IN;
  6. logic FRAM_RW;
  7. logic FRAM_RSTATUS;
  8. logic FRAM_hbn;
  9. logic FRAM_go;
  10. logic FRAM_busy;
  11. logic [7:0] clk_cntr;
  12. initial begin
  13. FRAM_Adr <= 20'h0;
  14. FRAM_DATA_IN <= 8'h0;
  15. FRAM_RW = 0;
  16. FRAM_RSTATUS = 0;
  17. FRAM_hbn = 0;
  18. FRAM_go = 0;
  19. clk_cntr = 0;
  20. end
  21. always @ (posedge b.timer) begin
  22. if(b.dip[0] == 0) begin //Reset
  23. FRAM_Adr <= 20'h0;
  24. FRAM_DATA_IN <= 8'h0;
  25. FRAM_RW = 0;
  26. FRAM_RSTATUS = 0;
  27. FRAM_hbn = 0;
  28. FRAM_go = 0;
  29. clk_cntr = 0;
  30. end
  31. else if(b.dip[1] == 1) begin //Read
  32. FRAM_Adr <= (FRAM_Adr - 1) % (ringbuffer_size - 1);
  33. FRAM_RW <= 1'h1; //Read
  34. FRAM_go <= 1'h1; //Go
  35. end
  36. else if(b.dip[1] == 0) begin //Write
  37. FRAM_Adr <= (FRAM_Adr + 1) % (ringbuffer_size - 1);
  38. FRAM_DATA_IN <= {6'h0, b.dip[3:2]};
  39. FRAM_RW <= 1'h0; //Write Operation
  40. FRAM_go <= 1'h1; //Go
  41. end
  42. end
  43. always @ (posedge b.clk) begin
  44. if(FRAM_go == 1)
  45. clk_cntr <= clk_cntr + 1;
  46. if(clk_cntr > 50 && FRAM_RW == 1'h1) begin
  47. b.spi_read <= FRAM_DATA_OUT[1:0];
  48. FRAM_go <= 1'h0;
  49. FRAM_RW <= 1'h0;
  50. clk_cntr <= 0;
  51. end
  52. else if(clk_cntr > 50 && FRAM_RW == 1'h0) begin
  53. FRAM_go <= 1'h0;
  54. clk_cntr <= 0;
  55. end
  56. end
  57. FRAM FRAM_ut(
  58. .i_clk(b.clk),
  59. .i_nreset(b.dip[0]),
  60. .i_adr(FRAM_Adr),
  61. .i_data(FRAM_DATA_IN),
  62. .o_data(FRAM_DATA_OUT),
  63. .i_rw(FRAM_RW),
  64. .i_status(FRAM_RSTATUS),
  65. .i_hbn(FRAM_hbn),
  66. .i_cready(FRAM_go),
  67. .o_busy(FRAM_busy),
  68. .o_SPI_Clk(i.sclk),
  69. .i_SPI_MISO(i.mosi),
  70. .o_SPI_MOSI(i.mosi),
  71. .o_SPI_CS_n(i.ss)
  72. );
  73. endmodule