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.

131 lines
5.0 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. // module src_ttl_parser #(
  2. // parameter REG_START_ADD = 0
  3. // ) (
  4. // input clk, //clock input
  5. // input rst_n, //asynchronous reset input, low active
  6. // //regbus interface
  7. // output reg [31:0] addr,
  8. // input [31:0] wr_data,
  9. // input wr_en,
  10. // inout wire [31:0] rd_data, //received serial data
  11. // // 输入
  12. // input ttlin,
  13. // //输出
  14. // output wire ttl_output //ttl原始数据
  15. // );
  16. // //
  17. // // @功能:
  18. // // 1. 计算ttl频率
  19. // // 2. 转发ttl信号
  20. // // 3. 分频倍频
  21. // //
  22. // // @寄存器列表:
  23. // // 地址 读写 默认 描述
  24. // // 0x00 r 0x0 function 0:原始信号输出 1:频率信号源
  25. // // 0x01 r 0x0 freq //一个周期的计数单位为 1/50M s
  26. // // 0x02 wr 0x0 pll_mul //暂不支持
  27. // // 0x03 wr 0x0 pll_div
  28. // // 0x04 wr 0x0 [0]:信号源是上升沿触发还是下降沿触发
  29. // //
  30. // reg ttl_origin_output; //ttl原始信号输出
  31. // reg ttl_after_process_output; //ttl处理后信号输出
  32. // /*******************************************************************************
  33. // * 寄存器读写 *
  34. // *******************************************************************************/
  35. // parameter ADD_NUM = 5; //寄存器数量
  36. // parameter REG_END_ADD = REG_START_ADD + ADD_NUM - 1; //寄存器结束地址
  37. // reg [31:0] register[REG_START_ADD:REG_END_ADD];
  38. // integer i;
  39. // always @(posedge clk or negedge rst_n) begin
  40. // if (!rst_n) begin
  41. // for (i = 0; i < ADD_NUM; i = i + 1) begin
  42. // register[i] <= 0;
  43. // end
  44. // end else begin
  45. // if (wr_en && addr >= REG_START_ADD && addr <= REG_END_ADD) register[addr] <= wr_data;
  46. // end
  47. // end
  48. // assign rd_data = (addr >= REG_START_ADD && addr <= REG_END_ADD) ? register[addr] : 31'bz;
  49. // parameter REG_FUNC_ADD = REG_START_ADD + 0;
  50. // parameter REG_FREQ_ADD = REG_START_ADD + 1;
  51. // parameter REG_PLL_MUL_ADD = REG_START_ADD + 2;
  52. // parameter REG_PLL_DIV_ADD = REG_START_ADD + 3;
  53. // parameter REG_TTL_EDGE_ADD = REG_START_ADD + 4;
  54. // /*******************************************************************************
  55. // * ttl输出路径选择 *
  56. // *******************************************************************************/
  57. // assign ttl_output = (register[REG_FUNC_ADD] == 0) ? ttl_origin_output : ttl_after_process_output;
  58. // /*******************************************************************************
  59. // * 原始信号输出 *
  60. // *******************************************************************************/
  61. // always @(posedge clk or negedge rst_n) begin
  62. // if (!rst_n) begin
  63. // ttl_origin_output <= 0;
  64. // end else begin
  65. // ttl_origin_output <= ttlin;
  66. // end
  67. // end
  68. // /*******************************************************************************
  69. // * ttl_in_last信号捕获 *
  70. // *******************************************************************************/
  71. // reg ttl_in_last;
  72. // always @(posedge clk or negedge rst_n) begin
  73. // if (!rst_n) begin
  74. // ttl_in_last <= 0;
  75. // end else begin
  76. // ttl_in_last <= ttlin;
  77. // end
  78. // end
  79. // /*******************************************************************************
  80. // * 频率探测 *
  81. // *******************************************************************************/
  82. // reg [31:0] ttl_freq_cnt;
  83. // always @(posedge clk or negedge rst_n) begin
  84. // if (!rst_n) begin
  85. // ttl_freq_cnt <= 0;
  86. // end else begin
  87. // if (ttlin && !ttl_in_last) begin
  88. // register[REG_FREQ_ADD] <= ttl_freq_cnt;
  89. // ttl_freq_cnt <= 0;
  90. // end
  91. // if (ttl_freq_cnt != 32'hffff_ffff_ffff_ffff) begin
  92. // ttl_freq_cnt <= ttl_freq_cnt + 1;
  93. // end
  94. // end
  95. // end
  96. // /*******************************************************************************
  97. // * 分频 *
  98. // *******************************************************************************/
  99. // reg [31:0] ttl_in_cnt;
  100. // always @(posedge clk or negedge rst_n) begin
  101. // if (!rst_n) begin
  102. // ttl_in_cnt <= 0;
  103. // end else begin
  104. // if (ttlin && !ttl_in_last) begin
  105. // if (ttl_in_cnt <= register[REG_PLL_MUL_ADD]) begin
  106. // ttl_in_cnt <= ttl_in_cnt + 1;
  107. // end else begin
  108. // ttl_in_cnt <= 0;
  109. // ttl_after_process_output <= 1;
  110. // end
  111. // end else begin
  112. // ttl_after_process_output <= 0;
  113. // end
  114. // end
  115. // end
  116. // endmodule