OpenCores
URL https://opencores.org/ocsvn/ssbcc/ssbcc/trunk

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [example/] [i2c/] [TMP100/] [tb/] [tb.v] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sinclairrf
/*******************************************************************************
2
 *
3
 * Copyright 2012, Sinclair R.F., Inc.
4
 *
5
 * Test bench for examples/i2c_tmp100
6
 *
7
 ******************************************************************************/
8
 
9
`timescale 1ns/1ps
10
 
11
module tb;
12
 
13
// 97 MHz clock
14
reg s_clk = 1'b1;
15
always @ (s_clk) s_clk <= #5.155 ~s_clk;
16
 
17
reg s_rst = 1'b1;
18
initial begin
19
  repeat (5) @ (posedge s_clk);
20
  s_rst <= 1'b0;
21
end
22
 
23
tri1 s_SCL;
24
tri1 s_SDA;
25
wire s_UART_Tx;
26
i2c_tmp100 it_inst(
27
  // synchronous reset and processor clock
28
  .i_rst        (s_rst),
29
  .i_clk        (s_clk),
30
  // I2C ports
31
  .io_scl       (s_SCL),
32
  .io_sda       (s_SDA),
33
  // UART_Tx ports
34
  .o_UART_Tx    (s_UART_Tx)
35
);
36
 
37
integer ix_i2c;
38
reg [0:26] i2c_out = 27'b111111110_101010101_010100001;
39
reg s_sensor_sda = 1'b1;
40
initial begin
41
  @ (negedge s_SDA);
42
  if (s_SCL == 1'b0) begin
43
    $display("%13d : Malformed I2C start signal");
44
    $finish;
45
  end
46
  ix_i2c = 0;
47
  repeat (27) begin
48
    @ (negedge s_SCL);
49
    #700;
50
    s_sensor_sda = i2c_out[ix_i2c];
51
    ix_i2c = ix_i2c + 1;
52
  end
53
  s_sensor_sda = 1'b1;
54
end
55
assign s_SDA = (s_sensor_sda) ? 1'bz : 1'b0;
56
 
57
localparam baud = 9600;
58
localparam dt_baud = 1.0e9/baud;
59
reg [8:0] deser = 9'h1FF;
60
initial forever begin
61
  @ (negedge s_UART_Tx);
62
  #(dt_baud/2.0);
63
  repeat (9) begin
64
    #dt_baud;
65
    deser = { s_UART_Tx, deser[1+:8] };
66
  end
67
  if (deser[8] != 1'b1)
68
    $display("%13d : Malformed UART transmition, $time");
69
  else if ((8'h20 <= deser[0+:8]) && (deser[0+:8]<=8'h80))
70
    $display("%13d : Sent 0x%02H : %c", $time, deser[0+:8], deser[0+:8]);
71
  else
72
    $display("%13d : Sent 0x%02H", $time, deser[0+:8]);
73
end
74
 
75
// Progress meter
76
initial forever begin #100_000_000; $display("%13d : progress report", $time); end
77
 
78
// terminate after 10 msec (use 2.1e9 for 2.1 sec)
79
initial begin
80
  while ($realtime < 1.0e7) @ (posedge s_clk);
81
  $finish;
82
end
83
 
84
initial begin
85
  $dumpfile("tb.lxt");
86
  $dumpvars();
87
end
88
 
89
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.