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: onewire_mstr.vhd
|
20 |
|
|
-- description: reading and writing devies on a one wire bus
|
21 |
|
|
--
|
22 |
|
|
-- To simplify the design, there is a low level entity, ow_bit, that handles the
|
23 |
|
|
-- read/write/init bit patterns. There is also a byte level entity,
|
24 |
|
|
-- ow_byte, that operates on bytes by controlling the ow_bit entity.
|
25 |
|
|
-- Controllers of this module can use bit or byte accesses to the one wire bus.
|
26 |
|
|
-- to execute both byte and bit level operations, it is necessary to mux the control
|
27 |
|
|
-- to the ow_bit interface to the various higher level functions.
|
28 |
|
|
-----------------------------
|
29 |
|
|
|
30 |
|
|
library IEEE;
|
31 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
32 |
|
|
use IEEE.numeric_std.all;
|
33 |
|
|
|
34 |
|
|
-------------------------------------------------------------------------------------
|
35 |
|
|
-- Entity declaration
|
36 |
|
|
-------------------------------------------------------------------------------------
|
37 |
|
|
entity ow_mstr is
|
38 |
|
|
port (
|
39 |
|
|
--global signals
|
40 |
|
|
clk : in std_logic;
|
41 |
|
|
srst : in std_logic; --synchronous reset
|
42 |
|
|
stb1us : in std_logic; --1us strobe, used to time transactions
|
43 |
|
|
busy : out std_logic; --device is in middle of read,write or init
|
44 |
|
|
--low level interfaces, used for micro processor control of bus
|
45 |
|
|
init_stb : in std_logic; --sends an init/reset pulse to bus
|
46 |
|
|
wrbyte : in std_logic; --write a byte to the bus
|
47 |
|
|
inbyte : in std_logic_vector(7 downto 0); --data byte to write
|
48 |
|
|
wrbit : in std_logic; --write a single bit to the bus
|
49 |
|
|
inbit : in std_logic; --data bit to write
|
50 |
|
|
rdbyte : in std_logic; --read a byte from the bus
|
51 |
|
|
outbyte : out std_logic_vector(7 downto 0); --read byte
|
52 |
|
|
rdbit : in std_logic; --read a single bit from the bus
|
53 |
|
|
outbit : out std_logic; --read bit
|
54 |
|
|
--one wire bus interface, requires external 5k resistor on bus
|
55 |
|
|
owin : in std_logic; --one wire input
|
56 |
|
|
owout : out std_logic --one wire output
|
57 |
|
|
);
|
58 |
|
|
end ow_mstr;
|
59 |
|
|
|
60 |
|
|
-------------------------------------------------------------------------------------
|
61 |
|
|
-- Architecture declaration
|
62 |
|
|
-------------------------------------------------------------------------------------
|
63 |
|
|
architecture rtl of ow_mstr is
|
64 |
|
|
|
65 |
|
|
signal busyout : std_logic;
|
66 |
|
|
|
67 |
|
|
--bit module signals
|
68 |
|
|
signal ow1_rbit : std_logic;
|
69 |
|
|
signal ow1_obit : std_logic;
|
70 |
|
|
signal ow1_wbit : std_logic;
|
71 |
|
|
signal ow1_ibit : std_logic;
|
72 |
|
|
signal ow1_zbit : std_logic;
|
73 |
|
|
signal ow1_busy : std_logic;
|
74 |
|
|
|
75 |
|
|
--byte module signals
|
76 |
|
|
signal ow8_rbit : std_logic;
|
77 |
|
|
signal ow8_wbit : std_logic;
|
78 |
|
|
signal ow8_obit : std_logic;
|
79 |
|
|
signal ow8_busy : std_logic;
|
80 |
|
|
|
81 |
|
|
begin
|
82 |
|
|
-------------------------------------
|
83 |
|
|
-- signal decoding ---
|
84 |
|
|
-------------------------------------
|
85 |
|
|
-- the following signals are muxed with priorities, allowing ow8 or external control of the bit interface
|
86 |
|
|
ow1_rbit <= ow8_rbit when ow8_busy = '1' else rdbit;
|
87 |
|
|
ow1_wbit <= ow8_wbit when ow8_busy = '1' else wrbit;
|
88 |
|
|
ow1_ibit <= ow8_obit when ow8_busy = '1' else inbit;
|
89 |
|
|
ow1_zbit <= init_stb;
|
90 |
|
|
|
91 |
|
|
-------------------------------------
|
92 |
|
|
-- u_ow1 ---
|
93 |
|
|
-------------------------------------
|
94 |
|
|
--handles single bit read/write/reset of the one wire bus
|
95 |
|
|
u_ow1 : entity work.ow_bit(rtl)
|
96 |
|
|
port map(
|
97 |
|
|
--globals
|
98 |
|
|
clk => clk,
|
99 |
|
|
srst => srst,
|
100 |
|
|
clken => stb1us,
|
101 |
|
|
--interface to higher level
|
102 |
|
|
rstb => ow1_rbit,
|
103 |
|
|
wstb => ow1_wbit,
|
104 |
|
|
istb => ow1_zbit,
|
105 |
|
|
din => ow1_ibit,
|
106 |
|
|
dout => ow1_obit,
|
107 |
|
|
busy => ow1_busy,
|
108 |
|
|
--one wire bus
|
109 |
|
|
owin => owin, --one wire input
|
110 |
|
|
owout => owout --one wire output
|
111 |
|
|
);
|
112 |
|
|
|
113 |
|
|
-------------------------------------
|
114 |
|
|
-- u_ow8 ---
|
115 |
|
|
-------------------------------------
|
116 |
|
|
u_ow8 : entity work.ow_byte(rtl)
|
117 |
|
|
port map(
|
118 |
|
|
--globals
|
119 |
|
|
clk => clk,
|
120 |
|
|
srst => srst,
|
121 |
|
|
--ow1 interface
|
122 |
|
|
rdbit => ow8_rbit,
|
123 |
|
|
wrbit => ow8_wbit,
|
124 |
|
|
ibit => ow1_obit,
|
125 |
|
|
obit => ow8_obit,
|
126 |
|
|
busyin => ow1_busy,
|
127 |
|
|
--high level interface to owt,owi, or external
|
128 |
|
|
rdbyte => rdbyte,
|
129 |
|
|
obyte => outbyte,
|
130 |
|
|
wrbyte => wrbyte,
|
131 |
|
|
ibyte => inbyte,
|
132 |
|
|
busy => ow8_busy
|
133 |
|
|
);
|
134 |
|
|
|
135 |
|
|
outbit <= ow1_obit;
|
136 |
|
|
busy <= ow8_busy or ow1_busy;
|
137 |
|
|
|
138 |
|
|
end rtl;
|