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.

289 lines
9.1 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
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. // SIGNAL_GENERATOR
  2. // 启动方式:
  3. // 1.寄存器控制启动
  4. // 2.外部触发启动
  5. // 3.TIMECODE触发启动
  6. // 帧格式:
  7. // TIMECODE:
  8. // 25/30/...
  9. // GENLOCK:
  10. // ....
  11. // 产生:
  12. // 1.start_state_sig (高电平表示拍照进行中)
  13. // 2.timecode_sig[64]
  14. // 3.timecode_tirgger_sig[1]
  15. // 4.genlock_sig[1] 帧信号,场信号
  16. //
  17. // TIMECODE_FORMAT
  18. // FPS2398Format = 0,
  19. // FPS2400Format = 1,
  20. // FPS2500Format = 2,
  21. // FPS2997Format = 3,
  22. // FPS2997DropFormat = 4,
  23. // FPS3000Format = 5
  24. // GENLCOK_FORMAT
  25. // GENLOCK_FPS2397_FORMAT = 0
  26. // GENLOCK_FPS2398_FORMAT = 1
  27. // GENLOCK_FPS2400_FORMAT = 2
  28. // GENLOCK_FPS2500_FORMAT = 3
  29. // GENLOCK_FPS2997_FORMAT = 4
  30. // GENLOCK_FPS3000_FORMAT = 5
  31. // GENLOCK_FPS5000_FORMAT = 6
  32. // GENLOCK_FPS5994_FORMAT = 7
  33. // GENLOCK_FPS6000_FORMAT = 8
  34. module xsync_internal_generator #(
  35. parameter REG_START_ADD = 0,
  36. parameter SYS_CLOCK_FREQ = 10000000,
  37. parameter TEST = 0,
  38. parameter ID = 1
  39. ) (
  40. input clk, //clock input
  41. input rst_n, //asynchronous reset input, low active
  42. //寄存器读写接口
  43. input [31:0] addr,
  44. input [31:0] wr_data,
  45. input wr_en,
  46. output wire [31:0] rd_data,
  47. input wire ext_ttlin1_module_raw_sig,
  48. input wire ext_ttlin2_module_raw_sig,
  49. input wire ext_ttlin3_module_raw_sig,
  50. input wire ext_ttlin4_module_raw_sig,
  51. input wire ext_timecode_tigger_sig,
  52. input wire [63:0] ext_timecode_data,
  53. input wire ext_genlock_signal, //
  54. /*******************************************************************************
  55. * 内部时码信号输出 *
  56. *******************************************************************************/
  57. output wire out_timecode_tirgger_sig, //输出时码译码有效信号
  58. output wire [63:0] out_timecode_sig, // 输出时间
  59. output wire out_timecode_serial_sig,
  60. /*******************************************************************************
  61. * 内部GENLOCK信号输出 *
  62. *******************************************************************************/
  63. output wire out_genlock_sig,
  64. /*******************************************************************************
  65. * 内部工作状态信号输出 *
  66. *******************************************************************************/
  67. output wire out_en_flag
  68. );
  69. localparam CTRL_REG_INDEX = 4;
  70. reg [31:0] r0_start_control_mode_reg; //控制模式选择寄存器
  71. reg [31:0] r2_genlock_format; //genlock格式寄存器
  72. reg [31:0] r3_timecode_format; //timecode格式寄存器
  73. reg [31:0] r4_control_trigger_reg; // StartSigCtrl[0] TimecodeCtrl[1] GenlockCtrl[2]
  74. wire [31:0] r6_timecode0; //timecode0 belong to timecode_generator_ist
  75. wire [31:0] r7_timecode1; //timecode1 belong to timecode_generator_ist
  76. reg [31:0] r8_timecode_start0; // 时码启动寄存器0
  77. reg [31:0] r9_timecode_start1; // 时码启动寄存器1
  78. reg [31:0] rA_timecode_stop0; // 时码停止寄存器0
  79. reg [31:0] rB_timecode_stop1; // 时码停止寄存器1
  80. reg [31:0] rC_work_state; //工作状态 read only
  81. assign out_en_flag = rC_work_state[0];
  82. //写寄存器标志位
  83. wire [31:0] reg_wr_index;
  84. zutils_register_advanced #(
  85. .REG_START_ADD(REG_START_ADD)
  86. ) _register (
  87. .clk(clk),
  88. .rst_n(rst_n),
  89. .addr(addr),
  90. .wr_data(wr_data),
  91. .wr_en(wr_en),
  92. .rd_data(rd_data),
  93. .reg0(r0_start_control_mode_reg),
  94. .reg2(r2_genlock_format),
  95. .reg3(r3_timecode_format),
  96. .reg4(r4_control_trigger_reg),
  97. .reg6(r6_timecode0),
  98. .reg7(r7_timecode1),
  99. .reg8(r8_timecode_start0),
  100. .reg9(r9_timecode_start1),
  101. .regA(rA_timecode_stop0),
  102. .regB(rB_timecode_stop1),
  103. .regC(rC_work_state),
  104. .reg_wr_sig(reg_wr_sig),
  105. .reg_index (reg_wr_index)
  106. );
  107. always @(posedge clk or negedge rst_n) begin
  108. if (!rst_n) begin
  109. r0_start_control_mode_reg <= 0;
  110. r2_genlock_format <= 0;
  111. r3_timecode_format <= 0;
  112. r4_control_trigger_reg <= 0;
  113. r8_timecode_start0 <= 0;
  114. r9_timecode_start1 <= 0;
  115. rA_timecode_stop0 <= 0;
  116. rB_timecode_stop1 <= 0;
  117. // rC_work_state <= 0;
  118. end else begin
  119. if (reg_wr_sig) begin
  120. case (reg_wr_index)
  121. 31'h0: r0_start_control_mode_reg <= wr_data;
  122. 31'h2: r2_genlock_format <= wr_data;
  123. 31'h3: r3_timecode_format <= wr_data;
  124. 31'h4: r4_control_trigger_reg <= wr_data;
  125. 31'h8: r8_timecode_start0 <= wr_data;
  126. 31'h9: r9_timecode_start1 <= wr_data;
  127. 31'hA: rA_timecode_stop0 <= wr_data;
  128. 31'hB: rB_timecode_stop1 <= wr_data;
  129. // 31'hC: rC_work_state <= wr_data;
  130. default: begin
  131. end
  132. endcase
  133. end
  134. end
  135. end
  136. /*******************************************************************************
  137. * StartSig输出 *
  138. *******************************************************************************/
  139. // 1.寄存器控制启动
  140. // 2.外部触发启动
  141. // 3.TIMECODE触发启动
  142. // 0.寄存器触发,启动停止
  143. // 1.外部TIMECODE触发启动,寄存器控制停止
  144. // 2.外部TTL输入1_高电平触发,低电平停止
  145. // 3.外部TTL输入2_高电平触发,低电平停止
  146. // 4.外部TTL输入3_高电平触发,低电平停止
  147. // 5.外部TTL输入4_高电平触发,低电平停止
  148. //
  149. zutils_multiplexer_32t1_v2 ttlin_level_trigger_multi (
  150. .chooseindex(r0_start_control_mode_reg),
  151. //in
  152. .in2(ext_ttlin1_module_raw_sig),
  153. .in3(ext_ttlin2_module_raw_sig),
  154. .in4(ext_ttlin3_module_raw_sig),
  155. .in5(ext_ttlin4_module_raw_sig),
  156. //out
  157. .out(ext_ttlinx_module_raw_sig)
  158. );
  159. reg start_sig;
  160. always @(posedge clk or negedge rst_n) begin
  161. if (!rst_n) begin
  162. start_sig <= 0;
  163. rC_work_state <= 0;
  164. end else begin
  165. case (r0_start_control_mode_reg[31:0])
  166. 0: begin
  167. //寄存器控制启动
  168. if (reg_wr_sig && reg_wr_index == CTRL_REG_INDEX) begin
  169. if (wr_data[0] == 1) begin
  170. rC_work_state[0] <= 1;
  171. end else begin
  172. rC_work_state[0] <= 0;
  173. end
  174. end
  175. end
  176. 1: begin
  177. //TIMECODE触发
  178. end
  179. 2, 3, 4, 5: begin
  180. //外部电平控制
  181. if (ext_ttlinx_module_raw_sig == 1) begin
  182. rC_work_state[0] <= 1;
  183. end else begin
  184. rC_work_state[0] <= 0;
  185. end
  186. end
  187. default: begin
  188. end
  189. endcase
  190. end
  191. end
  192. /*******************************************************************************
  193. * GENLOCK_时钟输出 *
  194. *******************************************************************************/
  195. wire genlock_sig_output;
  196. zutils_genlock_clk_generator #(
  197. .SYS_CLOCK_FREQ(SYS_CLOCK_FREQ)
  198. ) genlock (
  199. .clk(clk),
  200. .rst_n(rst_n),
  201. .ctrl_sig(out_en_flag),
  202. .genlock_fps2397_clk(genlock_fps2397_clk),
  203. .genlock_fps2398_clk(genlock_fps2398_clk),
  204. .genlock_fps2400_clk(genlock_fps2400_clk),
  205. .genlock_fps2500_clk(genlock_fps2500_clk),
  206. .genlock_fps2997_clk(genlock_fps2997_clk),
  207. .genlock_fps3000_clk(genlock_fps3000_clk),
  208. .genlock_fps5000_clk(genlock_fps5000_clk),
  209. .genlock_fps5994_clk(genlock_fps5994_clk),
  210. .genlock_fps6000_clk(genlock_fps6000_clk)
  211. );
  212. zutils_multiplexer_32t1_v2 genlock_clk_output_mult (
  213. .chooseindex(genlock_format),
  214. //in
  215. .in0(genlock_fps2397_clk),
  216. .in1(genlock_fps2398_clk),
  217. .in2(genlock_fps2400_clk),
  218. .in3(genlock_fps2500_clk),
  219. .in4(genlock_fps2997_clk),
  220. .in5(genlock_fps3000_clk),
  221. .in6(genlock_fps5000_clk),
  222. .in7(genlock_fps5994_clk),
  223. .in8(genlock_fps6000_clk),
  224. //out
  225. .out(genlock_sig_output)
  226. );
  227. assign out_genlock_sig = genlock_sig_output;
  228. /*******************************************************************************
  229. * smpte_timecode_clk_generator *
  230. *******************************************************************************/
  231. timecode_generator #(
  232. .SYS_CLOCK_FREQ(SYS_CLOCK_FREQ)
  233. ) timecode_generator_ist (
  234. .clk (clk),
  235. .rst_n(rst_n),
  236. .timecode_format(r3_timecode_format),
  237. .timecode0_wen(addr == 6),
  238. .timecode0(wr_data),
  239. .timecode1_wen(addr == 7),
  240. .timecode1(wr_data),
  241. .timecode0_export(r6_timecode0),
  242. .timecode1_export(r7_timecode1),
  243. .en(out_en_flag),
  244. .out_timecode_serial_data(out_timecode_serial_sig),
  245. .out_trigger_sig(out_timecode_tirgger_sig),
  246. .out_timecode0(out_timecode_sig[31:0]),
  247. .out_timecode1(out_timecode_sig[63:32])
  248. );
  249. endmodule