diff --git a/generic_ip/common/0/src/stretch_pulse.vhd b/generic_ip/common/0/src/stretch_pulse.vhd new file mode 100644 index 0000000..83089dd --- /dev/null +++ b/generic_ip/common/0/src/stretch_pulse.vhd @@ -0,0 +1,70 @@ +------------------------------------------------------------------------------- +-- Title : stretch pulse +-- Project : EMB-1 +------------------------------------------------------------------------------- +-- File : stretch_pulse.vhd +-- Author : Gianmarco Girau +-- Company : Global Inkjet Systems +-- Created : 2016-05-27 +-- Last update: 2018-05-18 +-- SVN ID : Git +-- Standard : VHDL'93 +------------------------------------------------------------------------------- +-- Description: +-- Stretch pulse to a programmable width +------------------------------------------------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +library work; +use work.common_pkg.all; + +entity stretch_pulse is + generic( + pulse_polarity : natural := 0; -- 0 => strecth on rising edge, 1 => strecth on falling edge + ext_pulse_width : natural := 100); + port( + rstN : in std_logic; + clk : in std_logic; + pulse_in : in std_logic; + pulse_out : out std_logic); +end stretch_pulse; + +architecture RTL of stretch_pulse is + + signal pulse, pulse_d : std_logic; + signal not_zero_cnt_flag : std_logic; + signal pulse_cnt : std_logic_vector(log2(ext_pulse_width)-1 downto 0); + +begin -- RTL + + gDetect_Pos_Pulse: if pulse_polarity = 0 generate + pulse <= pulse_in and not pulse_d; + end generate gDetect_Pos_Pulse; + + gDetect_Neg_Pulse: if pulse_polarity = 1 generate + pulse <= not pulse_in and pulse_d; + end generate gDetect_Neg_Pulse; + + pStretchPulse : process(rstN, clk) + begin + if(rstN = '0') then + pulse_d <= '0'; + pulse_out <= '0'; + pulse_cnt <= (others => '0'); + elsif(clk = '1' and clk'event) then + pulse_d <= pulse_in; + pulse_out <= not_zero_cnt_flag; + if(pulse = '1') then + pulse_cnt <= std_logic_vector(to_unsigned(ext_pulse_width, log2(ext_pulse_width))); + elsif(not_zero_cnt_flag = '1') then + pulse_cnt <= std_logic_vector(unsigned(pulse_cnt)-1); + end if; + end if; + end process pStretchPulse; + + not_zero_cnt_flag <= '1' when unsigned(pulse_cnt) /= 0 else '0'; + +end RTL; diff --git a/generic_ip/som_ctrl/1/doc/som_ctrl_1.json b/generic_ip/som_ctrl/1/doc/som_ctrl_1.json new file mode 100644 index 0000000..5e83ddb --- /dev/null +++ b/generic_ip/som_ctrl/1/doc/som_ctrl_1.json @@ -0,0 +1,231 @@ +[{ + "ip_name": "som_ctrl_1", + "bus": "csr", + "description": "SOM Controller IP", + "addr_hi_bit" : "6", + "addr_lo_bit" : "5", + "sub_blocks": { + "local": { + "instance": "", + "process": "enabled", + "offset": "0x0" + }, + "swim_2": { + "instance": "iSWIM_MNG", + "process": "enabled", + "offset": "0x20" + } + }, + "registers": { + "ip_id" : { + "address" : "0", + "width" : "32", + "description" : "Unique ID for this IP block", + "fields": { + "ip_number" : { + "type" : "c", + "bit_len" : "8", + "reset" : "0x0F", + "description" : "IP identifier number" + }, + "mfr_number" : { + "type" : "c", + "bit_len" : "8", + "reset" : "0xff", + "description" : "Manufacturer number" + + }, + "reserved" : { + "type" : "rsv", + "bit_len" : "16", + "description" : "Reserved bits" + } + } + }, + "ip_ver" : { + "address" : "1", + "width" : "32", + "description" : "Bits[7:0] = Minor version number, Bits[15:8] = Major version number, etc.", + "fields": { + "minor_number" : { + "type" : "c", + "bit_len" : "8", + "reset" : "0x00", + "description" : "Minor number" + }, + "major_number" : { + "type" : "c", + "bit_len" : "8", + "reset" : "0x01", + "description" : "Major number" + + }, + "reserved" : { + "type" : "rsv", + "bit_len" : "16", + "description" : "Reserved bits" + } + } + }, + "power_good_status": { + "address": "2", + "width": "3", + "description": "", + "fields": { + "p_good": { + "type": "r", + "bit_len": "1", + "reset": "U", + "description": "p_good pin status" + }, + "p_in_good": { + "type": "r", + "bit_len": "1", + "reset": "U", + "description": "p_in_good pin status" + }, + "p_host_good": { + "type": "r", + "bit_len": "1", + "reset": "U", + "description": "p_host_good pin status" + } + } + }, + "host_power_control": { + "address": "3", + "width": "7", + "description": "", + "fields": { + "host_pwr_en": { + "type": "w", + "bit_len": "1", + "reset": "0x0", + "description": "drives host_pwr_en pin" + }, + "host_5v_en": { + "type": "w", + "bit_len": "1", + "reset": "0x0", + "description": "drives host_5v_en pin" + }, + "host_3v3_en": { + "type": "w", + "bit_len": "1", + "reset": "0x0", + "description": "drives host_3v3_en pin" + }, + "host_2v5_en": { + "type": "w", + "bit_len": "1", + "reset": "0x0", + "description": "drives host_2v5_en pin" + }, + "host_1v5_en": { + "type": "w", + "bit_len": "1", + "reset": "0x0", + "description": "drives host_1v5_en pin" + }, + "host_1v2_en": { + "type": "w", + "bit_len": "1", + "reset": "0x0", + "description": "drives host_1v2_en pin" + }, + "host_1v1_en": { + "type": "w", + "bit_len": "1", + "reset": "0x0", + "description": "drives host_1v1_en pin" + } + } + }, + "mon_pt_sel": { + "address": "4", + "width": "32", + "description": "Monitoring Points selection", + "fields": { + "mp_0_sel": { + "type": "w", + "bit_len": "7", + "reset": "0x0", + "description": "source selection for MP-0" + }, + "mp_0_drive_n": { + "type": "w", + "bit_len": "1", + "reset": "0x1", + "description": "0 => Driving MP-0, 1 => MP-0 output three-stated" + }, + "mp_1_sel": { + "type": "w", + "bit_len": "7", + "reset": "0x0", + "description": "source selection for MP-1" + }, + "mp_1_drive_n": { + "type": "w", + "bit_len": "1", + "reset": "0x1", + "description": "0 => Driving MP-1, 1 => MP-1 output three-stated" + }, + "mp_2_sel": { + "type": "w", + "bit_len": "7", + "reset": "0x0", + "description": "source selection for MP-2" + }, + "mp_2_drive_n": { + "type": "w", + "bit_len": "1", + "reset": "0x1", + "description": "0 => Driving MP-2, 1 => MP-2 output three-stated" + }, + "mp_3_sel": { + "type": "w", + "bit_len": "7", + "reset": "0x0", + "description": "source selection for MP-3" + }, + "mp_3_drive_n": { + "type": "w", + "bit_len": "1", + "reset": "0x1", + "description": "0 => Driving MP-3, 1 => MP-3 output three-stated" + } + } + }, + "som_led": { + "type": "w", + "address": "5", + "reset": "0x00", + "width": "5", + "description": "SOM LEDs value" + }, + "stm8_ift": { + "address": "6", + "width": "9", + "description": "STM8 interface", + "fields": { + "stm8_trigger_rx": { + "type": "w", + "bit_len": "1", + "reset": "0x0", + "description": "stm8_trigger_rx" + }, + "reserved": { + "type": "rsv", + "bit_len": "7", + "description": "Reserved bits" + }, + "stm8_alert_tx": { + "type": "r", + "bit_len": "1", + "reset": "0x0", + "description": "stm8_alert_tx" + } + } + } + } +}] \ No newline at end of file diff --git a/generic_ip/som_ctrl/1/sim/comp.do b/generic_ip/som_ctrl/1/sim/comp.do new file mode 100644 index 0000000..8bc0e0b --- /dev/null +++ b/generic_ip/som_ctrl/1/sim/comp.do @@ -0,0 +1,32 @@ +# Modelsim compilation macro + +#.main clear + +# Cleanup libraries +foreach lib [list work OSVVM] { + file delete -force -- $lib + vlib $lib +} + +vlib ./work +vmap work ./work + +set COMMON_PATH ../../../common/0/src +set SWIM_PATH ../../../swim/2/src +set SRC_PATH ../src + +set WORKLIB work + +# Compile the design files + +vcom -2008 -work $WORKLIB $COMMON_PATH/common_pkg.vhd +vcom -2008 -work $WORKLIB $COMMON_PATH/stretch_pulse.vhd +vcom -2008 -work $WORKLIB $SWIM_PATH/swim_2_pkg_auto.vhd +vcom -2008 -work $WORKLIB $SWIM_PATH/swim_2_csr_regs_auto.vhd +vcom -2008 -work $WORKLIB $SWIM_PATH/swim_2.vhd +vcom -2008 -work $WORKLIB $SRC_PATH/som_ctrl_1_pkg.vhd +vcom -2008 -work $WORKLIB $SRC_PATH/som_ctrl_1.vhd + + + + diff --git a/generic_ip/som_ctrl/1/src/som_ctrl_1.vhd b/generic_ip/som_ctrl/1/src/som_ctrl_1.vhd new file mode 100644 index 0000000..8fc2107 --- /dev/null +++ b/generic_ip/som_ctrl/1/src/som_ctrl_1.vhd @@ -0,0 +1,240 @@ +------------------------------------------------------------------------------- +-- Title : som ctrl_1 +-- Project : SMB +------------------------------------------------------------------------------- +-- File : som_ctrl.vhd +-- Author : Gianmarco Girau +-- Company : Global Inkjet Systems +-- Created : 2018-05-15 +-- Last update: 2018-12-20 +-- SVN ID : Git +-- Standard : VHDL 2008 +------------------------------------------------------------------------------- +-- Description: +-- som_ctrl block: this block gathers together SOM specific functionalies, such +-- as the SWIM interface, power-good input signals, host-power enable signals etc. +------------------------------------------------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +library work; +use work.som_ctrl_1_pkg.all; + + +entity som_ctrl_1 is + port ( + clk : in std_logic; + reset_n : in std_logic := '1'; + -- Avalon-MM I/F + avs_address : in std_logic_vector( 5 downto 0); + avs_write : in std_logic; + avs_writedata : in std_logic_vector(31 downto 0); + avs_read : in std_logic; + avs_readdatavalid : out std_logic; + avs_readdata : out std_logic_vector(31 downto 0); + -- SOM Specific I/Fs: + som_mon_pt_en : out std_logic_vector( 3 downto 0); -- SOM Timing Output enable + som_mon_pt : out std_logic_vector( 3 downto 0); -- SOM Timing I/Os + mon_pt_src : in std_logic_vector(31 downto 0); -- Source signals for the SOM monitoring points + -- STM8 & swim + stm8_alert_tx : in std_logic; + stm8_trigger_rx : out std_logic; + swim_tx : out std_logic; + swim_rx : in std_logic; + -- SOM Miscellaneous I/Os + p_good : in std_logic; + p_in_good : in std_logic; + p_host_good : in std_logic; + host_pwr_en : out std_logic; + host_5v_en : out std_logic; + host_3v3_en : out std_logic; + host_2v5_en : out std_logic; + host_1v5_en : out std_logic; + host_1v2_en : out std_logic; + host_1v1_en : out std_logic; + -- SOM LEDs + som_led : out std_logic_vector(5 downto 1)); + +end entity som_ctrl_1; + +architecture rtl of som_ctrl_1 is + + constant CSR_IP_ID : std_logic_vector(31 downto 0) := x"0000FF0F"; + constant CSR_IP_VER : std_logic_vector(31 downto 0) := x"00000100"; + + signal swim_write, swim_read, swim_read_d : std_logic; + signal avs_read_d : std_logic; + signal avs_addr : std_logic_vector( 2 downto 0); + signal swim_addr, mp_stretch_en : std_logic_vector( 3 downto 0); + signal mon_pt_i, mon_pt_ii : std_logic_vector( 3 downto 0); + signal mon_pt_sel_0, mon_pt_sel_1 : std_logic_vector( 7 downto 0); + signal mon_pt_sel_2, mon_pt_sel_3 : std_logic_vector( 7 downto 0); + signal swim_writedata, swim_readdata : std_logic_vector(31 downto 0); + signal avs_readdata_i : std_logic_vector(31 downto 0); + +begin + + ----------------------------------------------------------------------------- + -- SWIM I/F + ----------------------------------------------------------------------------- + + iSWIM_MNG: entity work.swim_2 + generic map ( + CLK_FREQ_MHZ => 100) + port map ( + clk => clk, + reset_n => reset_n, + avs_address => swim_addr, + avs_write => swim_write, + avs_writedata => swim_writedata, + avs_read => swim_read, + avs_readdata => swim_readdata, + swim_out => swim_tx, + swim_in => swim_rx, + dbg_port => open); + + ----------------------------------------------------------------------------- + -- MOnitoring Points + ----------------------------------------------------------------------------- + + -- + som_mon_pt_en(0) <= not mon_pt_sel_0(7); + som_mon_pt_en(1) <= not mon_pt_sel_1(7); + som_mon_pt_en(2) <= not mon_pt_sel_2(7); + som_mon_pt_en(3) <= not mon_pt_sel_3(7); + + -- Monitoring Point selection + mon_pt_ii(0) <= mon_pt_src(to_integer(unsigned(mon_pt_sel_0(4 downto 0)))); + mon_pt_ii(1) <= mon_pt_src(to_integer(unsigned(mon_pt_sel_1(4 downto 0)))); + mon_pt_ii(2) <= mon_pt_src(to_integer(unsigned(mon_pt_sel_2(4 downto 0)))); + mon_pt_ii(3) <= mon_pt_src(to_integer(unsigned(mon_pt_sel_3(4 downto 0)))); + + -- Pulse stretching + gMP_STRETCH : for n in 0 to 3 generate + + iSTRETCH: entity work.stretch_pulse + generic map ( + pulse_polarity => 0, + ext_pulse_width => 25) + port map ( + rstN => reset_n, + clk => clk, + pulse_in => mon_pt_ii(n), + pulse_out => mon_pt_i(n)); + + end generate gMP_STRETCH; + + som_mon_pt(0) <= mon_pt_ii(0) when mp_stretch_en(0) = '0' else mon_pt_i(0); + som_mon_pt(1) <= mon_pt_ii(1) when mp_stretch_en(1) = '0' else mon_pt_i(1); + som_mon_pt(2) <= mon_pt_ii(2) when mp_stretch_en(2) = '0' else mon_pt_i(2); + som_mon_pt(3) <= mon_pt_ii(3) when mp_stretch_en(3) = '0' else mon_pt_i(3); + + ----------------------------------------------------------------------------- + -- C&S registers (Avalon-MM I/F) + ----------------------------------------------------------------------------- + + swim_addr <= avs_address(swim_addr'range); + + swim_writedata <= avs_writedata; + + swim_write <= '1' when avs_write = '1' and avs_address(5) = '1' else '0'; + swim_read <= '1' when avs_read = '1' and avs_address(5) = '1' else '0'; + + avs_addr <= avs_address(2 downto 0); + + pCTRL_STATUS : process(reset_n, clk) + begin + if(reset_n = '0') then + avs_readdatavalid <= '0'; + -- + host_pwr_en <= '0'; + host_5v_en <= '0'; + host_3v3_en <= '0'; + host_2v5_en <= '0'; + host_1v5_en <= '0'; + host_1v2_en <= '0'; + host_1v1_en <= '0'; + -- + stm8_trigger_rx <= '0'; + -- + mon_pt_sel_0 <= (7 => '1', others => '0'); + mon_pt_sel_1 <= (7 => '1', others => '0'); + mon_pt_sel_2 <= (7 => '1', others => '0'); + mon_pt_sel_3 <= (7 => '1', others => '0'); + mp_stretch_en <= (others => '0'); + -- + som_led <= (others => '0'); + elsif(clk = '1' and clk'event) then + -- CTRL registers + if(avs_write = '1') then + case avs_addr is + when CSR_HOST_PWR_ADDR => + host_pwr_en <= avs_writedata(0); + host_5v_en <= avs_writedata(1); + host_3v3_en <= avs_writedata(2); + host_2v5_en <= avs_writedata(3); + host_1v5_en <= avs_writedata(4); + host_1v2_en <= avs_writedata(5); + host_1v1_en <= avs_writedata(6); + when CSR_MON_PT_SEL_ADDR => + mon_pt_sel_0 <= avs_writedata( 7 downto 0); + mon_pt_sel_1 <= avs_writedata(15 downto 8); + mon_pt_sel_2 <= avs_writedata(23 downto 16); + mon_pt_sel_3 <= avs_writedata(31 downto 24); + when CSR_MON_PT_STRETCH_ADDR => + mp_stretch_en <= avs_writedata( 3 downto 0); + when CSR_SOM_LED_ADDR => + som_led <= avs_writedata( 4 downto 0); + when CSR_STM8_ADDR => + stm8_trigger_rx <= avs_writedata(0); + when others => null; + end case; + end if; + + -- Read Ctrl & Status registers + if(avs_read = '1') then + case avs_addr is + when CSR_IP_ID_ADDR => + avs_readdata_i <= CSR_IP_ID; + when CSR_IP_VER_ADDR => + avs_readdata_i <= CSR_IP_VER; + when CSR_PWR_GOOD_ADDR => + avs_readdata_i <= (0 => p_good, 1 => p_in_good, 2 => p_host_good, others => '0'); + when CSR_HOST_PWR_ADDR => + avs_readdata_i(0) <= host_pwr_en; + avs_readdata_i(1) <= host_5v_en; + avs_readdata_i(2) <= host_3v3_en; + avs_readdata_i(3) <= host_2v5_en; + avs_readdata_i(4) <= host_1v5_en; + avs_readdata_i(5) <= host_1v2_en; + avs_readdata_i(6) <= host_1v1_en; + avs_readdata_i(31 downto 7) <= (others => '0'); + when CSR_MON_PT_SEL_ADDR => + avs_readdata_i <= mon_pt_sel_3 & mon_pt_sel_2 & mon_pt_sel_1 & mon_pt_sel_0; + when CSR_MON_PT_STRETCH_ADDR => + avs_readdata_i <= 28x"0" & mp_stretch_en; + when CSR_SOM_LED_ADDR => + avs_readdata_i <= 27x"0" & som_led; + when CSR_STM8_ADDR => + avs_readdata_i <= (0 => stm8_trigger_rx, 8 => stm8_alert_tx, others => '0'); + when others => + avs_readdata <= X"BAD1BAD0"; + end case; + end if; + -- Output mux between local status registers and the swim if. Adjust + -- latency for the read-valid. + swim_read_d <= swim_read; + if(swim_read_d = '1') then + avs_readdata <= swim_readdata; + else + avs_readdata <= avs_readdata_i; + end if; + avs_read_d <= avs_read; + avs_readdatavalid <= avs_read_d; + end if; + end process pCTRL_STATUS; + +end architecture rtl; + diff --git a/generic_ip/som_ctrl/1/src/som_ctrl_1_pkg.vhd b/generic_ip/som_ctrl/1/src/som_ctrl_1_pkg.vhd new file mode 100644 index 0000000..560755f --- /dev/null +++ b/generic_ip/som_ctrl/1/src/som_ctrl_1_pkg.vhd @@ -0,0 +1,35 @@ +------------------------------------------------------------------------------- +-- Title : som_ctrl_1_pkg +-- Project : SOM/SMB +------------------------------------------------------------------------------- +-- File : som_ctrl_1_pkg.vhd +-- Author : GMG +-- Company : Global Inkjet Systems +-- Created : 2018-05-21 +-- Last update: 2018-12-20 +-- SVN ID : Git +-- Standard : VHDL'2008 +------------------------------------------------------------------------------- +-- Description: +-- Package defining common constants for the som_ctrl, block +------------------------------------------------------------------------------- + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +package som_ctrl_1_pkg is + + constant CSR_IP_ID_ADDR : std_logic_vector(2 downto 0) := 3x"0"; + constant CSR_IP_VER_ADDR : std_logic_vector(2 downto 0) := 3x"1"; + constant CSR_PWR_GOOD_ADDR : std_logic_vector(2 downto 0) := 3x"2"; + constant CSR_HOST_PWR_ADDR : std_logic_vector(2 downto 0) := 3x"3"; + constant CSR_MON_PT_SEL_ADDR : std_logic_vector(2 downto 0) := 3x"4"; + constant CSR_MON_PT_STRETCH_ADDR : std_logic_vector(2 downto 0) := 3x"5"; + constant CSR_SOM_LED_ADDR : std_logic_vector(2 downto 0) := 3x"6"; + constant CSR_STM8_ADDR : std_logic_vector(2 downto 0) := 3x"7"; + + -- offset for the SWIM interface subblock + constant CSR_SWIM_IF_OFFSET : std_logic_vector(5 downto 0) := 6x"20"; + +end package som_ctrl_1_pkg;