亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? usb2mem.vhd

?? USB在FPGA上的實(shí)現(xiàn)
?? VHD
字號:
--COMMAND STRUCTURE OF SERAL USB PROTOCOL

-- MSBYTE   LSBYTE

-- DATA     CODE

--Dongle internal command codes
-- 0x--     0xC5  		--Get Status data is don't care (must return) 0x3210 (3 is the MSNibble)
-- 0xNN     0xCD        --Get Data from flash (performs read from current address) NN count of words auto increment address
-- 0xAA     0xA0		--Addr LSByte write
-- 0xAA     0xA1        --Addr Byte write
-- 0xAA     0xA2		--Addr MSByte write
-- 0x--     0x3F		--NOP

--Flash operations codes
-- 0xNN     0xE8        --Write to buffer returns extended satus NN is word count for USB machine
-- 0x--     0xD0			-- 0xD0 is flash confirm command



--write buffer sequence
--      ???					-- set address if needed               
-- 0xNN     0xE8        --Write to buffer returns extended satus NN is word count for USB machine
-- 0x--     0xNN 			--0xNN is word count for flash ges directly to flash and is wordCount - 1
-- 0xDD     0xDD        --N+1 times data expected 0xF + 1 is the maximum
--      ...
-- 0x--     0xD0			-- 0xD0 is flash confirm command



library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.std_logic_arith.all;

entity usb2mem is
  port (
    clk25     : in  std_logic;
    reset_n   : in  std_logic;
	dongle_ver: in std_logic_vector(15 downto 0);
    -- mem Bus
	mem_busy_n : in std_logic;
	mem_idle  : out std_logic; -- '1' if controller is idle (flash is safe for LPC reads)
    mem_addr  : out std_logic_vector(23 downto 0);
    mem_do    : out std_logic_vector(15 downto 0);
    mem_di    : in std_logic_vector(15 downto 0);
    mem_wr    : out std_logic;
    mem_val   : out std_logic;
    mem_ack   : in  std_logic;
    mem_cmd   : out std_logic;
    -- USB port
	usb_mode_en: in   std_logic;  -- enable this block 
    usb_rd_n   : out  std_logic;  -- enables out data if low (next byte detected by edge / in usb chip)
    usb_wr     : out  std_logic;  -- write performed on edge \ of signal
    usb_txe_n  : in   std_logic;  -- tx fifo empty (redy for new data if low)
    usb_rxf_n  : in   std_logic;  -- rx fifo empty (data redy if low)
    usb_bd     : inout  std_logic_vector(7 downto 0) --bus data
    ); 
end usb2mem;

		
architecture RTL of usb2mem is



  
  type state_type is (RESETs,RXCMD0s,RXCMD1s,DECODEs,INTERNs,VCIRDs,VCIWRs,TXCMD0s,TXCMD1s,STS_WAITs);
  signal CS : state_type;

  signal data_reg_i : std_logic_vector(15 downto 0);
  signal data_reg_o : std_logic_vector(15 downto 0);
  signal data_oe    : std_logic;  -- rx fifo empty (data redy if low)
  signal usb_wr_d   : std_logic;  -- internal readable output state for write
  signal addr_reg: std_logic_vector(23 downto 0);  

  --State machine
  signal cmd_cnt   : std_logic_vector(15 downto 0);
  signal state_cnt : std_logic_vector(3 downto 0);
  --shyncro to USB
  signal usb_txe_nd  :    std_logic;  -- tx fifo empty (redy for new data if low)
  signal usb_rxf_nd  :    std_logic;  -- rx fifo empty (data redy if low)
  signal internal_cmd  :    std_logic;  -- rx fifo empty (data redy if low)

  signal read_mode   : std_logic;
  signal write_mode  : std_logic;
  signal write_count : std_logic;
  signal first_word : std_logic;
  signal mem_busy_nd : std_logic;


  
begin

--define internal command codes
internal_cmd <='1' when data_reg_i(7 downto 0) = x"C5" else
					'1' when data_reg_i(7 downto 0) = x"CD" else
					'1' when data_reg_i(7 downto 0) = x"A0" else
					'1' when data_reg_i(7 downto 0) = x"A1" else
					'1' when data_reg_i(7 downto 0) = x"A2" else
					'1' when data_reg_i(7 downto 0) = x"3F" else
					--These are spechial attention Flash commands
					'1' when data_reg_i(7 downto 0) = x"E8" else
					'0';


usb_wr <= usb_wr_d when usb_mode_en='1' else
		  'Z';


-- this goes to byte buffer for that reason send LSB first and MSB second
usb_bd <=data_reg_o(7 downto 0)when data_oe='1' and CS=TXCMD0s and usb_mode_en='1' else --LSB byte first
			data_reg_o(15 downto 8) when data_oe='1' and CS=TXCMD1s and usb_mode_en='1' else --MSB byte second
			(others=>'Z');


process (clk25,reset_n)  --enable the scanning while in reset (simulation will be incorrect)
begin  -- process
  if reset_n='0' then
	CS <= RESETs;
	usb_rd_n <= '1';
	usb_wr_d <= '0';
	usb_txe_nd <= '1';
	usb_rxf_nd <= '1';
	data_oe <='0';
	state_cnt <=(others=>'0'); --init command counter
	mem_do <= (others=>'Z');
	mem_addr <= (others=>'Z');
	addr_reg <= (others=>'0');
	mem_val <= '0';
	mem_wr <='0';
	mem_cmd <='0';
	cmd_cnt <= (others=>'0');
	read_mode <='0';
	write_mode <='0';
 	write_count <='0';
  	first_word <='0';
	mem_idle <='1'; --set idle
	mem_busy_nd <='1';
  elsif clk25'event and clk25 = '1' then    -- rising clock edge
	usb_txe_nd <= usb_txe_n; --syncronize
	usb_rxf_nd <= usb_rxf_n; --syncronize
	mem_busy_nd <=mem_busy_n; --syncronize
  	case CS is
    	when RESETs =>
			if usb_rxf_nd='0' and usb_mode_en='1' and mem_busy_nd='1' then
				state_cnt <=(others=>'0'); --init command counter
				data_oe <='0'; --we will read command in
				mem_idle <='0'; --set busy untill return here
				CS <= RXCMD0s;
			elsif mem_busy_nd='1' then
				mem_idle <='1'; --set idle when here
			end if;
		when RXCMD0s =>
			if state_cnt="0000" then
				usb_rd_n <='0'; -- set read low
				state_cnt <= state_cnt + 1;-- must be min 50ns long (two cycles)
			elsif state_cnt="0001" then 
				state_cnt <= state_cnt + 1;-- one wait cycle
			elsif state_cnt="0010" then
				state_cnt <= state_cnt + 1;-- now is ok
				data_reg_i(15 downto 8) <= usb_bd; --get data form bus MSByte must come first
			elsif state_cnt="0011" then
				usb_rd_n <='1'; -- set read back to high
				state_cnt <= state_cnt + 1;-- start wait	
			elsif state_cnt="0100" then
				state_cnt <= state_cnt + 1;-- wait	(the usb_rxf_n toggles after each read and next data is not ready)
			elsif state_cnt="0101" then
 				state_cnt <= state_cnt + 1;-- wait	
			elsif state_cnt="0110" then
				state_cnt <= state_cnt + 1;-- now is ok prob.														
			else
				if usb_rxf_nd='0' then	--wait untill next byte is available
					state_cnt <=(others=>'0'); --init command counter
					CS <= RXCMD1s;					
				end if;		
			end if;  
		when RXCMD1s =>
			if state_cnt="0000" then
				usb_rd_n <='0'; -- set read low
				state_cnt <= state_cnt + 1;-- must be min 50ns long (two cycles)
			elsif state_cnt="0001" then 
				state_cnt <= state_cnt + 1;-- one wait cycle
			elsif state_cnt="0010" then
				state_cnt <= state_cnt + 1;-- now is ok
				data_reg_i(7 downto 0) <= usb_bd; --get data form bus LSByte must come last
			elsif state_cnt="0011" then
				state_cnt <= state_cnt + 1;-- now is ok
				usb_rd_n <='1'; -- set read back to high	
			elsif state_cnt="0100" then
				state_cnt <= state_cnt + 1;-- wait (the usb_rxf_n toggles after each read and next data is not ready)
			elsif state_cnt="0101" then
				state_cnt <= state_cnt + 1;-- wait
			elsif state_cnt="0110" then
				state_cnt <= state_cnt + 1;-- now is ok prob.												
			else
				state_cnt <=(others=>'0'); --init command counter
				CS <= INTERNs;					
			end if;  			
		when INTERNs =>
		if 	cmd_cnt=x"0000" then
			if data_reg_i(7 downto 0)=x"A0" then
				addr_reg(7 downto 0)<= data_reg_i(15 downto 8);
				CS <= RESETs; --go back to resets
			elsif data_reg_i(7 downto 0)=x"A1" then
				addr_reg(15 downto 8)<= data_reg_i(15 downto 8);
				CS <= RESETs; --go back to resets
			elsif data_reg_i(7 downto 0)=x"A2" then
				addr_reg(23 downto 16)<= data_reg_i(15 downto 8);
				CS <= RESETs; --go back to resets
			elsif data_reg_i(7 downto 0)=x"3F" then
				CS <= RESETs; --go back to resets		--NOP command		
			elsif data_reg_i(7 downto 0)=x"C5" then
				if (data_reg_i(15 downto 8))=x"00" then
					data_reg_o <=x"3210";
				else
					data_reg_o <=dongle_ver;	
				end if;
				CS <= TXCMD0s;	
			elsif data_reg_i(7 downto 0)=x"CD" then
				if (data_reg_i(15 downto 8))=x"00" then --64K word read coming
					cmd_cnt <= (others=>'1'); --64K word count
				else
					cmd_cnt <= x"00"&data_reg_i(15 downto 8) - 1; -- -1 as one read will be done right now (cmd_cnt words)
				end if;
				CS <= VCIRDs; --go perform a read
				read_mode <='1';
			elsif data_reg_i(7 downto 0)=x"E8" then
			    --write_mode <='1';
				write_count <='0';
			  	first_word <='0';			
				cmd_cnt <= x"00"&data_reg_i(15 downto 8) + 1;  --+2 for direct count write +1
				data_reg_i(15 downto 8)<=(others=>'0');
				CS <= VCIWRs; --go perform a write
			else 
				CS <= VCIWRs;
			end if;
		else
			if cmd_cnt>x"0000" then
				cmd_cnt<= cmd_cnt - 1;
				if write_count='0' then
					write_count<='1';
				elsif write_count='1' and  first_word ='0' then
					first_word <='1';
				elsif write_count='1' and  first_word ='1' then
					addr_reg <= addr_reg + 1; --autoincrement address in in block mode
				end if;
				--if cmd_cnt>x"02" then --so not to increase too many times on write buffer
				--	addr_reg <= addr_reg + 1; --autoincrement address in in block mode
				--end if;
			end if;
			CS <= VCIWRs;		
		end if;
		when VCIRDs =>		--flash read
			mem_wr <='0';  			--this is VCI write_not_read
			mem_cmd <='0';
			mem_addr <= addr_reg(22 downto 0)&'0'; --translate byte address to word address
			mem_val <= '1';   	
			if mem_ack='1' then
				data_reg_o <= mem_di;
				mem_wr <='0';  			--this is VCI write_not_read
				mem_cmd <='0';
				mem_val <= '0';
				CS <= TXCMD0s;
			end if;		
		when VCIWRs =>		--flash write
			mem_addr <= addr_reg(22 downto 0)&'0'; --translate byte address to word address
			mem_do <= data_reg_i; 	--USB data in will go to mem_out
			mem_wr <='1';  			--this is VCI write_not_read
			mem_cmd <='1';
			mem_val <= '1';  	
			if mem_ack='1' then
				mem_do <= (others=>'Z');
				mem_wr <='0';  			--this is VCI write_not_read
				mem_cmd <='0';
				mem_val <= '0'; 
				--if write_mode='0' then
					
					if cmd_cnt=x"0000" then --if flash command and not data
						state_cnt <=(others=>'0'); --init command counter
						CS <= STS_WAITs;
					else
						CS <= RESETs;
					end if;
				--else  --else if was 0xE8 must read and return XSR
				--	write_mode <='0'; --XSR return will no follow clear this bit
				--	CS <= VCIRDs;
				--end if;
			end if;
		when TXCMD0s =>  --transmit over USB what ever is in data_reg_o MSB first
			
				if state_cnt="0000" then
					if usb_txe_nd='0' then
						usb_wr_d<='1'; -- data is mux'ed by state and data_oe in the beginning of arch
						state_cnt <= state_cnt + 1;-- now is ok
					end if;		
				elsif state_cnt="0010" then
				    data_oe<='1'; --this is to put data on bus befora falling edge of wr (max 20ns before)
					state_cnt <= state_cnt + 1;-- now is ok
				elsif state_cnt="0011" then
				    usb_wr_d<='0'; --falling edge performs write  must be high for atleast 50ns
					state_cnt <= state_cnt + 1;-- now is ok
				elsif state_cnt="0100" then
					state_cnt <= state_cnt + 1;-- now is ok		
					data_oe<='0';	
				elsif state_cnt="0111" then	  --must stay low at least 50ns
					CS <= TXCMD1s;
					state_cnt <= (others=>'0');
				else 
					state_cnt <= state_cnt + 1;-- if intermediate cnt then count
				end if;
			
		when TXCMD1s => 
			
				if state_cnt="0000" then
				    if usb_txe_nd='0' then
						usb_wr_d<='1'; -- data is mux'ed by state and data_oe in the beginning of arch
						state_cnt <= state_cnt + 1;-- now is ok
		   			end if;		
				elsif state_cnt="0010" then
				    data_oe<='1'; --this is to put data on bus befora falling edge of wr (max 20ns before)
					state_cnt <= state_cnt + 1;-- now is ok
				elsif state_cnt="0011" then
				    usb_wr_d<='0'; --falling edge performs write  must be high for atleast 50ns
					state_cnt <= state_cnt + 1;-- now is ok
				elsif state_cnt="0100" then
					state_cnt <= state_cnt + 1;-- now is ok		
					data_oe<='0';			
				elsif state_cnt="0111" then	  --must stay low at least 50ns
					if read_mode='0' then
						CS <= RESETs;
					elsif cmd_cnt="0000" then --last word sent
						addr_reg <= addr_reg + 1; --autoincrement address in read mode
						read_mode <='0';
						CS <= RESETs;
					else
						cmd_cnt<= cmd_cnt - 1;
						addr_reg <= addr_reg + 1; --autoincrement address in read mode
						CS <= VCIRDs;	--more data to be read
					end if;
					state_cnt <= (others=>'0');
				else 
					state_cnt <= state_cnt + 1;-- if intermediate cnt then count
				end if;
		when STS_WAITs => 
				if mem_busy_nd='0' then
					CS <= RESETs; --now it's ok to go here
				else
					state_cnt <= state_cnt + 1;
					if state_cnt="1111" then
						--sts cant take longer than 500 ns to go low
						CS <= RESETs; --time out go to resets anyway
					end if;
				end if;		
    	when others => null;
  	end case;
  end if;
end process;



end RTL;

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲h动漫在线| 免费看黄色91| 日韩欧美一区二区免费| 成人午夜精品在线| 日韩av在线免费观看不卡| 国产欧美va欧美不卡在线| 欧美在线观看禁18| 成人免费看片app下载| 日韩成人dvd| 亚洲一区在线视频| 国产精品久久久久久久久免费相片 | 欧美成人午夜电影| 欧美亚洲综合久久| 成人午夜看片网址| 国产在线精品免费| 日韩va亚洲va欧美va久久| 一区av在线播放| 亚洲婷婷国产精品电影人久久| 久久综合久久综合亚洲| 欧美日韩中文另类| 色系网站成人免费| 99久久久国产精品免费蜜臀| 国产东北露脸精品视频| 蜜桃在线一区二区三区| 午夜精品在线看| 亚洲一区二区黄色| 亚洲一卡二卡三卡四卡| 一区二区视频免费在线观看| 亚洲视频图片小说| 最近日韩中文字幕| 亚洲色图第一区| 亚洲女厕所小便bbb| 亚洲天堂成人在线观看| 中文字幕一区二区不卡| 国产欧美1区2区3区| 国产日韩欧美精品综合| 国产夜色精品一区二区av| 久久夜色精品一区| 久久精品夜色噜噜亚洲a∨| 久久免费精品国产久精品久久久久| 在线成人免费视频| 日韩一区二区三区四区| 欧美成人vps| www成人在线观看| 国产日韩精品一区二区三区| 国产欧美在线观看一区| 国产精品国产自产拍高清av王其| 国产精品丝袜一区| 亚洲六月丁香色婷婷综合久久| 亚洲另类中文字| 亚洲高清免费观看高清完整版在线观看| 亚洲综合在线观看视频| 亚洲成人午夜电影| 裸体歌舞表演一区二区| 美女视频黄久久| 丁香啪啪综合成人亚洲小说| av电影在线不卡| 欧美亚洲动漫精品| 日韩欧美一级二级三级| 国产亚洲精品aa| 亚洲日本乱码在线观看| 天天做天天摸天天爽国产一区| 日本一区中文字幕| 国产91清纯白嫩初高中在线观看| 成人久久视频在线观看| 欧美性猛交xxxx乱大交退制版| 7777精品伊人久久久大香线蕉| 精品福利视频一区二区三区| 国产欧美一区二区三区网站| 一区二区三区在线免费视频| 免费在线观看一区| 粉嫩av一区二区三区| 在线观看成人小视频| 日韩美女视频在线| 国产精品嫩草99a| 亚洲电影你懂得| 国产一区二区三区四区在线观看 | 91蜜桃网址入口| 欧美精品777| 国产女人水真多18毛片18精品视频| 亚洲欧美一区二区不卡| 美国毛片一区二区| av激情亚洲男人天堂| 欧美伦理影视网| 国产日本欧美一区二区| 亚洲一区在线看| 国产精品99久久久久久久vr| 在线看国产一区二区| 久久免费视频色| 五月激情综合网| 91免费看`日韩一区二区| 日韩欧美色综合网站| 日韩美女视频19| 韩国v欧美v日本v亚洲v| 久久久久久久免费视频了| 一区二区三区四区在线播放| 国内精品免费在线观看| 欧美日韩国产首页在线观看| 国产精品丝袜久久久久久app| 五月天亚洲精品| jiyouzz国产精品久久| 欧美成人精品1314www| 一区二区三区中文免费| 国产精品资源在线观看| 91精品一区二区三区在线观看| 一色屋精品亚洲香蕉网站| 精品一区二区三区免费毛片爱| 欧美主播一区二区三区| 国产精品久久久久久户外露出| 久久99国内精品| 3d成人h动漫网站入口| 亚洲自拍偷拍图区| 成人福利视频在线看| 日韩精品自拍偷拍| 日韩av电影免费观看高清完整版 | 九九**精品视频免费播放| 在线观看91视频| 中文字幕日韩av资源站| 成人免费看视频| 国产精品国产三级国产aⅴ原创| 久久av资源网| 欧美大尺度电影在线| 日韩成人午夜电影| 91精品国产一区二区三区香蕉| 一区二区三区日本| 在线看日韩精品电影| 一个色综合网站| 色综合久久88色综合天天免费| 国产精品久久一卡二卡| 国产激情一区二区三区四区 | 精品在线亚洲视频| 91精品国产乱码久久蜜臀| 日韩精品乱码av一区二区| 欧美日本韩国一区| 三级久久三级久久久| 欧美精选午夜久久久乱码6080| 亚洲品质自拍视频网站| 色88888久久久久久影院按摩| 亚洲精品国产一区二区三区四区在线| 成人国产精品免费网站| 国产精品福利一区| 91成人免费电影| 亚洲第一成人在线| 91精品国产入口| 久久av资源站| 国产欧美久久久精品影院| 成人黄页在线观看| 综合久久久久久| 欧美视频一区二区三区| 亚洲不卡在线观看| 日韩欧美的一区| 成人在线一区二区三区| 亚洲免费在线播放| 欧美人与性动xxxx| 激情六月婷婷综合| 日本一区二区视频在线观看| 成人a免费在线看| 亚洲最大的成人av| 日韩欧美在线一区二区三区| 国产在线播放一区二区三区| 欧美韩国日本不卡| 日本高清无吗v一区| 亚洲国产另类精品专区| 欧美videos大乳护士334| 国产成人在线免费观看| 亚洲久本草在线中文字幕| 欧美日韩精品二区第二页| 激情六月婷婷久久| 综合自拍亚洲综合图不卡区| 欧美日韩国产首页| 国产白丝精品91爽爽久久 | 免费视频一区二区| 中文字幕va一区二区三区| 欧美亚洲国产怡红院影院| 狠狠色狠狠色综合系列| 亚洲色图在线播放| 日韩精品专区在线| 91在线视频官网| 美女脱光内衣内裤视频久久网站 | 欧美片网站yy| 粉嫩av一区二区三区在线播放| 亚洲第四色夜色| 国产欧美日本一区二区三区| 欧美综合久久久| 国产成人在线影院 | 成人免费视频免费观看| 香港成人在线视频| 国产精品视频麻豆| 日韩免费一区二区三区在线播放| 成人app在线观看| 精品在线播放免费| 亚洲一区二区综合| 国产精品福利一区| 久久婷婷一区二区三区| 欧美无砖专区一中文字| 成人永久aaa| 国内外成人在线| 日韩av中文字幕一区二区三区| 综合久久一区二区三区| 久久久不卡影院|