-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a61e7eb
commit 74bc3ee
Showing
19 changed files
with
1,937 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-- This Source Code Form is subject to the terms of the Mozilla Public | ||
-- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
-- file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
-- | ||
-- Copyright 2024 Oxide Computer Company | ||
|
||
-- This package relies on the VHDL 2019 feature for "interfaces" | ||
|
||
library ieee; | ||
use ieee.std_logic_1164.all; | ||
|
||
package tristate_if_pkg is | ||
|
||
type tristate is record | ||
i : std_logic; | ||
o : std_logic; | ||
oe : std_logic; | ||
end record; | ||
|
||
view tristate_if of tristate is | ||
i : in; | ||
o, oe : out; | ||
end view; | ||
|
||
end package; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
load("//tools:hdl.bzl", "vhdl_unit", "vunit_sim") | ||
|
||
vhdl_unit( | ||
name = "i2c_txn_layer", | ||
srcs = glob([ | ||
"link_layer/*.vhd", | ||
"txn_layer/*.vhd", | ||
"i2c_common_pkg.vhd"]), | ||
deps = [ | ||
"//hdl/ip/vhd/common:countdown", | ||
"//hdl/ip/vhd/common:strobe", | ||
"//hdl/ip/vhd/common:streaming_if_pkg", | ||
"//hdl/ip/vhd/common:tristate_if_pkg", | ||
"//hdl/ip/vhd/common:time_pkg", | ||
"//hdl/ip/vhd/synchronizers:meta_sync" | ||
], | ||
standard = "2019", | ||
visibility = ['PUBLIC'] | ||
) | ||
|
||
vunit_sim( | ||
name = "i2c_txn_layer_tb", | ||
srcs = glob(["sims/txn_layer/*.vhd", "sims/*.vhd"]), | ||
deps = [ | ||
":i2c_txn_layer", | ||
"//hdl/ip/vhd/vunit_components:basic_stream" | ||
], | ||
visibility = ['PUBLIC'], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
-- This Source Code Form is subject to the terms of the Mozilla Public | ||
-- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
-- file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
-- | ||
-- Copyright 2024 Oxide Computer Company | ||
|
||
library ieee; | ||
use ieee.std_logic_1164.all; | ||
use ieee.numeric_std.all; | ||
|
||
package i2c_common_pkg is | ||
|
||
-- | ||
-- Link Layer | ||
-- | ||
|
||
type mode_t is ( | ||
STANDARD, -- up to 100 Kbps | ||
FAST, -- up to 400 Kbps | ||
FAST_PLUS -- up to 1 Mbps | ||
); | ||
|
||
-- A group of settings for generics to generate constants | ||
-- all times in nanoseconds (ns) | ||
type settings_t is record | ||
fscl_period_ns : positive; -- SCL clock period | ||
sda_su_ns : positive; -- data set-up time | ||
sta_su_hd_ns : positive; -- START set-up/hold time | ||
sto_su_ns : positive; -- STOP set-up time | ||
sto_sta_buf_ns : positive; -- bus free time between STOP and START | ||
end record; | ||
|
||
function get_i2c_settings (constant mode : mode_t) return settings_t; | ||
|
||
-- | ||
-- Transaction Layer | ||
-- | ||
|
||
type op_t is ( | ||
READ, | ||
WRITE, | ||
-- RANDOM_READ will write an address byte and one more byte (intended to set an internal | ||
-- address register on a peripheral) before issuing a repeated start for a read. | ||
RANDOM_READ | ||
); | ||
|
||
type cmd_t is record | ||
op : op_t; | ||
addr : std_logic_vector(6 downto 0); | ||
reg : std_logic_vector(7 downto 0); | ||
len : unsigned(7 downto 0); | ||
end record; | ||
constant CMD_RESET : cmd_t := (READ, (others => '0'), (others => '0'), (others => '0')); | ||
|
||
end package; | ||
|
||
package body i2c_common_pkg is | ||
|
||
function get_i2c_settings (constant mode : mode_t) return settings_t is | ||
variable r : settings_t; | ||
begin | ||
case mode is | ||
when STANDARD => | ||
r := ( | ||
10_000, -- 10^9 / 100_000Hz | ||
250, | ||
4700, | ||
4000, | ||
4700 | ||
); | ||
when FAST => | ||
r := ( | ||
2500, -- 10^9 / 400_000Hz | ||
100, | ||
600, | ||
600, | ||
1300 | ||
); | ||
when FAST_PLUS => | ||
r := ( | ||
1000, -- 10^9 / 1_000_000Hz | ||
50, | ||
260, | ||
260, | ||
500 | ||
); | ||
end case; | ||
|
||
return r; | ||
end; | ||
|
||
end package body; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
-- This Source Code Form is subject to the terms of the Mozilla Public | ||
-- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
-- file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
-- | ||
-- Copyright 2024 Oxide Computer Company | ||
|
||
library ieee; | ||
use ieee.std_logic_1164.all; | ||
|
||
use work.tristate_if_pkg; | ||
|
||
use work.i2c_common_pkg; | ||
|
||
entity i2c_core is | ||
generic ( | ||
CLK_PER_NS : positive; | ||
MODE : mode_t; | ||
); | ||
port ( | ||
clk : in std_logic; | ||
reset : in std_logic; | ||
|
||
-- Tri-state signals to I2C interface | ||
scl_if : view tristate_if; | ||
sda_if : view tristate_if; | ||
|
||
-- AXI register interface | ||
); | ||
end entity; | ||
|
||
architecture rtl of i2c_core is | ||
|
||
begin | ||
|
||
i2c_txn_layer_inst: entity work.i2c_txn_layer | ||
generic map( | ||
CLK_PER_NS => CLK_PER_NS, | ||
MODE => MODE | ||
) | ||
port map( | ||
clk => clk, | ||
reset => reset, | ||
scl_if => scl_if, | ||
sda_if => sda_if, | ||
cmd => cmd, | ||
cmd_valid => cmd_valid, | ||
core_ready => core_ready, | ||
tx_st_if => tx_st_if, | ||
rx_st_if => rx_st_if | ||
); | ||
|
||
end architecture; |
Oops, something went wrong.