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

Subversion Repositories onewire

[/] [onewire/] [trunk/] [HDL/] [ow_byte.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 skeptonomi
----------------------------------------------------------------------------------
2
--  <c>2018 william b hunter
3
--    This file is part of ow2rtd.
4
--
5
--    ow2rtd is free software: you can redistribute it and/or modify
6
--    it under the terms of the GNU Lessor General Public License as published by
7
--    the Free Software Foundation, either version 3 of the License, or
8
--    (at your option) any later version.
9
--
10
--    ow2rtd is distributed in the hope that it will be useful,
11
--    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
--    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
--    GNU General Public License for more details.
14
--
15
--    You should have received a copy of the GNU Lessor General Public License
16
--    along with ow2rtd.  If not, see <https://www.gnu.org/licenses/>.
17
-----------------------------------------------------------------------------------  
18
--  Create Date: 5/15/2018
19
--  file: ow_byte.vhd
20
--  description:  handles read and write byte operations on the one wire bus
21
--
22
-----------------------------
23
 
24
library IEEE;
25
use IEEE.STD_LOGIC_1164.ALL;
26
use IEEE.numeric_std.all;
27
library work;
28
 
29
-------------------------------------------------------------------------------------
30
-- Entity declaration
31
-------------------------------------------------------------------------------------
32
entity ow_byte is
33
  port (
34
    --globals
35
    clk              : in    std_logic;
36
    srst             : in    std_logic;
37
    --clken            : in    std_logic;
38
    --ow1 interface
39
    rdbit    : out std_logic; -- rd bit strobe
40
    wrbit    : out std_logic; -- wr bit strobe
41
    ibit     : in  std_logic; -- rd bit data
42
    obit     : out std_logic; -- wr bit data
43
    busyin   : in  std_logic; -- busy from the bit interface
44
    --high level interface to owt,owi, or external
45
    rdbyte   : in  std_logic; -- read byte strobe
46
    obyte    : out std_logic_vector(7 downto 0); -- result of the byte read
47
    wrbyte   : in  std_logic; -- write byte strobe
48
    ibyte    : in  std_logic_vector(7 downto 0); -- write data
49
    busy     : out std_logic -- busy signal the to external modules
50
   );
51
end ow_byte;
52
 
53
-------------------------------------------------------------------------------------
54
-- Architecture declaration
55
-------------------------------------------------------------------------------------
56
architecture rtl of ow_byte is
57
  type state_type is (S_IDLE, S_STROBE, S_SHIFT);
58
  signal state : state_type := S_IDLE;
59
 
60
  signal bitcnt : integer range 0 to 7 := 0; --counts the bytes during the transfer
61
  signal shift : std_logic_vector(7 downto 0); -- used to shift in and out data
62
  signal rdwr_n : std_logic; -- 1 for read, 0 for write
63
  signal irdbit : std_logic; -- internal state of rdbit strobe
64
  signal iwrbit : std_logic; -- internal state of wrbit strobe
65
 
66
  attribute mark_debug : string;
67
  attribute mark_debug of state : signal is "true";
68
  attribute mark_debug of rdwr_n : signal is "true";
69
  attribute mark_debug of shift : signal is "true";
70
  attribute mark_debug of bitcnt : signal is "true";
71
  attribute mark_debug of irdbit : signal is "true";
72
  attribute mark_debug of iwrbit : signal is "true";
73
 
74
begin
75
  -------------------------------------
76
  --           bit shifter          ---
77
  -------------------------------------
78
  -- p_shifty - shifts data in and out the shift register, and counts down bits
79
  p_shifty : process (clk)
80
  begin
81
    if rising_edge(clk) then
82
      if srst = '1' then
83
        shift <= (others => '0');
84
        bitcnt <= 0;
85
                    rdwr_n <= '1';
86
                  irdbit <= '0';
87
        iwrbit<= '0';
88
                    state <= S_IDLE;
89
      else
90
            case state is
91
                    when S_IDLE =>
92
                      --wait for read byte or write byte strobe
93
                      if busyin = '0' and (rdbyte = '1' or wrbyte = '1') then
94
                        rdwr_n <= rdbyte;  --remember whether it was read or write
95
                          shift <= ibyte;    --load the byte to shift out(not needed for read)
96
                          bitcnt <= 0;       --set bit counter
97
                        state <= S_STROBE;
98
                      end if;
99
                    when S_STROBE =>
100
                      if irdbit = '0' and iwrbit = '0' then
101
                        --if we havent started the read or write yet
102
                        irdbit <= rdwr_n;      --read one bit if it is a read
103
                          iwrbit <= not rdwr_n;  --write one bit if its a write
104
                      else
105
                        --if we are the bit operation has already started, clear the strobes
106
                        irdbit <= '0';
107
                          iwrbit<= '0';
108
                          state <= S_SHIFT;
109
                      end if;
110
                    when S_SHIFT =>
111
                      if busyin = '0' then  --wait for the bit operation to finish
112
                        shift <= ibit & shift(7 downto 1); --shift the bit in or out
113
                          if bitcnt = 7 then                 --check for last bit
114
                            state <= S_IDLE;                 --return to idle when finished
115
                          else
116
                            bitcnt <= bitcnt +1;             --more bits to go, count down bits
117
                            state <= S_STROBE;               --strobe the next bit operatoin
118
                          end if;
119
                end if;
120
                    end case;
121
      end if;
122
    end if;
123
  end process p_shifty;
124
 
125
  -------------------------------------
126
  --           IO signals           ---
127
  -------------------------------------
128
 --copy the internal signals to the external ports
129
  rdbit <= irdbit;
130
  wrbit <= iwrbit;
131
  obit <= shift(0);  --the output bit to the ow_bit module
132
  obyte <= shift;    --the read byte after shifting in all bits
133
  busy <= '0' when state = S_IDLE and rdbyte = '0' and wrbyte = '0' else '1'; --if we are not idle we are busy
134
 
135
 
136
end rtl;

powered by: WebSVN 2.1.0

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