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

Subversion Repositories sockit_owm

[/] [sockit_owm/] [trunk/] [hdl/] [onewire_slave_model.v] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 iztok
//////////////////////////////////////////////////////////////////////////////
2
//                                                                          //
3
//  1-wire (owr) slave model                                                //
4
//                                                                          //
5
//  Copyright (C) 2010  Iztok Jeras                                         //
6
//                                                                          //
7
//////////////////////////////////////////////////////////////////////////////
8
//                                                                          //
9 5 iztok
//  This HDL is free hardware: you can redistribute it and/or modify        //
10 2 iztok
//  it under the terms of the GNU Lesser General Public License             //
11
//  as published by the Free Software Foundation, either                    //
12
//  version 3 of the License, or (at your option) any later version.        //
13
//                                                                          //
14
//  This RTL is distributed in the hope that it will be useful,             //
15
//  but WITHOUT ANY WARRANTY; without even the implied warranty of          //
16
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
17
//  GNU General Public License for more details.                            //
18
//                                                                          //
19
//  You should have received a copy of the GNU General Public License       //
20
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.   //
21
//                                                                          //
22
//////////////////////////////////////////////////////////////////////////////
23
 
24
`timescale 1us / 1ns
25
 
26
module onewire_slave_model #(
27 3 iztok
  // time slot (min=15.0, typ=30.0, max=60.0)
28
  parameter TS = 30.0
29 2 iztok
)(
30 3 iztok
  // configuration
31
  input  wire ena,    // response enable
32
  input  wire ovd,    // overdrive mode select
33
  input  wire dat_r,  // read data
34
  output wire dat_w,  // write data
35
  // 1-wire
36 2 iztok
  inout wire owr
37
);
38
 
39
// IO
40 3 iztok
reg pul;
41
reg dat;
42 2 iztok
 
43
// events
44 3 iztok
event sample_dat;
45
event sample_rst;
46 2 iztok
 
47
//////////////////////////////////////////////////////////////////////////////
48
// IO
49
//////////////////////////////////////////////////////////////////////////////
50
 
51 3 iztok
// onewire open collector signal
52
assign owr = pul & ena ? 1'b0 : 1'bz;
53 2 iztok
 
54 3 iztok
// read data output
55
assign dat_w = ena ? dat : 1'bz;
56
 
57 2 iztok
//////////////////////////////////////////////////////////////////////////////
58
// events inside a cycle
59
//////////////////////////////////////////////////////////////////////////////
60
 
61 3 iztok
// power up state
62
initial pul  <= 1'b0;
63
 
64
always @ (negedge owr)  if (ena)  transfer (ovd, dat_r, dat);
65
 
66
task automatic transfer (
67
  input  ovd,
68
  input  dat_r,
69
  output dat_w
70
); begin
71
  // provide read data response
72
  pul = ~dat_r;
73
  // wait 1 time slot
74
  if (ovd)  #(1*TS/8);
75
  else      #(1*TS);
76
  // write data is sampled here
77
  -> sample_dat;
78
  dat_w = owr;
79
  // release the wire
80
  pul = 1'b0;
81
  // fork into data or reset cycle
82 2 iztok
  fork
83 3 iztok
    // transfer data
84
    begin : transfer_dat
85
      // if cycle ends before reset is detected
86
      if (~owr) @ (posedge owr);
87
      // disable reset path
88
      disable transfer_rst;
89 2 iztok
    end
90 3 iztok
    // transfer reset
91
    begin : transfer_rst
92
      // wait 7 time slots
93
      if (ovd)  #(7*TS/8);
94
      else      #(7*TS);
95
      // reset is sampled here
96
      -> sample_rst;
97
      // if reset is detected disable data path
98
      if (~owr) disable transfer_dat;
99
      // wait for reset low to end
100
      @ (posedge owr)
101
      // wait 1 time slot
102
      if (ovd)  #(1*TS/8);
103
      else      #(1*TS);
104
      // provide presence pulse
105
      pul = 1'b1;
106
      // wait 4 time slot
107
      if (ovd)  #(4*TS/8);
108
      else      #(4*TS);
109
      // release the wire
110
      pul = 1'b0;
111 2 iztok
    end
112
  join
113 3 iztok
end endtask
114 2 iztok
 
115
endmodule

powered by: WebSVN 2.1.0

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