1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
use crate::core::prelude::*;

#[derive(LogicBlock, Default)]
pub struct OpalKellySystemClock7 {
    pub clock_p: Signal<In, Clock>,
    pub clock_n: Signal<In, Clock>,
    pub sys_clock: Signal<Out, Clock>,
}

impl Logic for OpalKellySystemClock7 {
    fn update(&mut self) {}
    fn connect(&mut self) {
        self.sys_clock.connect();
    }
    fn hdl(&self) -> Verilog {
        Verilog::Blackbox(BlackBox {
            code: r#"
module opal_kelly_system_clock_7 (
            clock_p,
            clock_n,
            sys_clock
            );

input wire clock_p;
input wire clock_n;
output wire sys_clock;

wire clock_single_ended;

// Buffer the input
IBUFDS clk_ibufgds
    (.O  (clock_single_ended),
     .I  (clock_p),
     .IB (clock_n));


  // Clocking PRIMITIVE
  //------------------------------------

  // Instantiation of the MMCM PRIMITIVE
  //    * Unused inputs are tied off
  //    * Unused outputs are labeled unused

  wire        clk_out1_cdiv;

  wire        locked_int;
  wire        clkfbout_cdiv;
  wire        clkfbout_buf_cdiv;

  MMCME2_BASE
  #(.CLKFBOUT_MULT_F      (5.000),
    .CLKOUT0_DIVIDE_F     (10.000),
    .CLKIN1_PERIOD        (5.000))
  mmcm_base_inst
    // Output clocks
   (
    .CLKFBOUT            (clkfbout_cdiv),
    .CLKOUT0             (clk_out1_cdiv),
     // Input clock control
    .CLKFBIN             (clkfbout_buf_cdiv),
    .CLKIN1              (clock_single_ended),
    // Other control and status signals
    .LOCKED              (locked_int),
    .PWRDWN              (1'b0),
    .RST                 (1'b0));

// Clock Monitor clock assigning
//--------------------------------------
 // Output buffering
  //-----------------------------------

  BUFG clkf_buf
   (.O (clkfbout_buf_cdiv),
    .I (clkfbout_cdiv));

  BUFG clkout1_buf
   (.O   (sys_clock),
    .I   (clk_out1_cdiv));
endmodule

(* blackbox *)
module BUFG(I, O);
  input wire I;
  output wire O;
endmodule

(* blackbox *)
module IBUFDS(I, IB, O);
  input wire I;
  input wire IB;
  output wire O;
endmodule

(* blackbox *)
module MMCME2_BASE (
  CLKFBOUT,
  CLKFBOUTB,
  CLKOUT0,
  CLKOUT0B,
  CLKOUT1,
  CLKOUT1B,
  CLKOUT2,
  CLKOUT2B,
  CLKOUT3,
  CLKOUT3B,
  CLKOUT4,
  CLKOUT5,
  CLKOUT6,
  LOCKED,
  CLKFBIN,
  CLKIN1,
  PWRDWN,
  RST
);
  parameter BANDWIDTH = "OPTIMIZED";
  parameter real CLKFBOUT_MULT_F = 5.000;
  parameter real CLKFBOUT_PHASE = 0.000;
  parameter real CLKIN1_PERIOD = 0.000;
  parameter real CLKOUT0_DIVIDE_F = 1.000;
  parameter real CLKOUT0_DUTY_CYCLE = 0.500;
  parameter real CLKOUT0_PHASE = 0.000;
  parameter integer CLKOUT1_DIVIDE = 1;
  parameter real CLKOUT1_DUTY_CYCLE = 0.500;
  parameter real CLKOUT1_PHASE = 0.000;
  parameter integer CLKOUT2_DIVIDE = 1;
  parameter real CLKOUT2_DUTY_CYCLE = 0.500;
  parameter real CLKOUT2_PHASE = 0.000;
  parameter integer CLKOUT3_DIVIDE = 1;
  parameter real CLKOUT3_DUTY_CYCLE = 0.500;
  parameter real CLKOUT3_PHASE = 0.000;
  parameter CLKOUT4_CASCADE = "FALSE";
  parameter integer CLKOUT4_DIVIDE = 1;
  parameter real CLKOUT4_DUTY_CYCLE = 0.500;
  parameter real CLKOUT4_PHASE = 0.000;
  parameter integer CLKOUT5_DIVIDE = 1;
  parameter real CLKOUT5_DUTY_CYCLE = 0.500;
  parameter real CLKOUT5_PHASE = 0.000;
  parameter integer CLKOUT6_DIVIDE = 1;
  parameter real CLKOUT6_DUTY_CYCLE = 0.500;
  parameter real CLKOUT6_PHASE = 0.000;
  parameter integer DIVCLK_DIVIDE = 1;
  parameter real REF_JITTER1 = 0.010;
  parameter STARTUP_WAIT = "FALSE";
   output CLKFBOUT;
   output CLKFBOUTB;
   output CLKOUT0;
   output CLKOUT0B;
   output CLKOUT1;
   output CLKOUT1B;
   output CLKOUT2;
   output CLKOUT2B;
   output CLKOUT3;
   output CLKOUT3B;
   output CLKOUT4;
   output CLKOUT5;
   output CLKOUT6;
   output LOCKED;
   input CLKFBIN;
   input CLKIN1;
   input PWRDWN;
   input RST;
endmodule

        "#
            .into(),
            name: "opal_kelly_system_clock_7".to_string(),
        })
    }
}

#[test]
fn test_synth() {
    let mut uut = TopWrap::new(OpalKellySystemClock7::default());
    uut.uut.clock_n.connect();
    uut.uut.clock_p.connect();
    uut.connect_all();
    println!("vlog: {}", generate_verilog(&uut));
    yosys_validate("ok_sys_clock7", &generate_verilog(&uut)).unwrap();
}