-- Uncomment the following lines to use the declarations that are
-- provided for instantiating Xilinx primitive components.
--library UNISIM;
--use UNISIM.VComponents.all;
--Describe:
-- sclk : in std_logic; --__|--|__|--|__...|--|_______|--|__|--|_...
-- 0 1 7 0 1
--
entity getinfo is
Port (
wraddr : in std_logic; -- 1us
sclk : in std_logic; -- from board
framehead : in std_logic; --___|-|______..._______|-|________.._______
sdin : in std_logic; -- from board
read_en : in std_logic; --from 860
byte : out std_logic_vector(5 downto 0); --just test
shift : out std_logic;
dinout : inout std_logic_vector(7 downto 0);
rdy : out std_logic -- 0 active
);
end getinfo;
architecture Behavioral of getinfo is
signal reg : std_logic_vector(7 downto 0);
signal cnt : std_logic_vector(8 downto 0); -- 6 bit as bytenum 3 bit as bit select
-- signal bitcnt : std_logic_vector(2 downto 0); --
signal bytenum : std_logic_vector(5 downto 0); -- 6 bit register of byte number
signal bytenum_set : std_logic;
signal shift_en : std_logic;
signal ready : std_logic;
signal data_valid: std_logic;
begin
process(wraddr,shift_en)
begin
if shift_en='1' then -- 1 enable shift
bytenum_set <='0';
elsif (wraddr'event and wraddr ='1') then
bytenum <=dinout(5 downto 0);
bytenum_set <='1'; -- bytenum has been set
end if;
end process;
byte <=bytenum; --test
shift <=shift_en;
process(sclk,framehead)
begin
if framehead='0' then
cnt <="111111111";
elsif sclk'event and sclk='0' then
cnt <=cnt+1;
end if;
end process;
process(sclk,bytenum_set)
begin
if sclk'event and sclk='0' then
if bytenum_set='1' and cnt(2 downto 0)="111" then
shift_en <='1';
elsif cnt(8 downto 3)=bytenum and cnt(2 downto 0)="111" and bytenum_set='0'then
shift_en <='0';
end if;
end if;
end process;
process(sclk,shift_en)
begin
if sclk'event and sclk='0' then --rising latch,falling sample
if shift_en='1' then
reg <=sdin®(7 downto 1);
end if;
end if;
end process;
-- dinout <=reg when read_en='0' else "ZZZZZZZZ"; -- 0 active
process(read_en,shift_en)
begin
if read_en='0'then
dinout <=reg;
rdy <='1';
elsif shift_en'event and shift_en='0' then
rdy <='0';
end if;
end process;
-- process(shift_en)
-- begin
-- if shift_en'event and shift_en='0' then
-- rdy <='0';
-- end if;
-- end process;
end Behavioral;