⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fpgaconf.vhd

📁 介绍了各种cpld的配置和下载方法
💻 VHD
字号:
--声明:
--本VHDL描述版权属作者(Dick Hou)个人所以,任何人可以以此作学习之用,也可以散发传播,但必须注明出处(可编程逻辑器件与单片机网站)。
--任何人可以将此作为以学习为目的的设计中,但不能用于商业产品中以谋取利益。


--	Spartan II FPGA Configuration use slave serial mode
--	FpgaConf.vhd
--	Dick Hou	2001/12/27
--	采用从串模式

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity fpgaconf is
	port (	resetin	:in std_logic;		--接Spartan II 的/PROG脚,此脚通过上拉电阻接到VCC,并通过按键接GND,按下此键后开始配置
			init	:in std_logic;	--接Spartan II 的INIT脚
			done	:in std_logic;	--接Spartan II 的DONE脚
			clk	:in std_logic;	--系统时钟输入
			done_ok	:out std_logic;	--驱动LED指示灯,接LED阳极,指示配置成功与否
			din	:out std_logic;	--接Spartan II DIN脚
			cclk	:out std_logic;	--接Spartan II CCLK脚
			poe	:out std_logic;	--接配置ROM的/OE端,也可直接将/OE接地
			pce	:out std_logic;	--接配置ROM的/CE端,也可直接将/CE接地
			cdata	:in std_logic_vector(7 downto 0);	--接ROM的数据线
			caddr	:out std_logic_vector(18 downto 0)	--接ROM的地址线
		);
end fpgaconf;

architecture behav of fpgaconf is
signal	acnt	:std_logic_vector(21 downto 0);
signal	dreg	:std_logic_vector(8 downto 0);
signal	st0,st1,st2,st3,st4	:std_logic;
signal	en_cclk	:std_logic;
signal	clkdiv	:std_logic_vector(2 downto 0);
signal	clkin	:std_logic;

begin
	process(clk)
	begin
		if clk'event and clk='0' then
			clkdiv	<=clkdiv + 1;
		end if;
	end process;
	clkin	<=clkdiv(2);
	
	process(clkin,init,done,resetin)
	begin
		if clkin'event and clkin='0' then
			if resetin='0' then
				acnt<="0000000000000000000000";
				st0<='1';
				st1<='1';
				st2<='0';
				st3<='0';
				st4<='0';
				en_cclk<='1';
			elsif st1='1' then
				if init='0' then
					st0<='0';
					st1<='1';
					st2<='0';
					st3<='0';
					st4<='0';
					en_cclk<='1';
				else
					st0<='0';
					st1<='0';
					st2<='1';
					st3<='0';
					st4<='0';
					en_cclk<='0';
				end if;
			elsif st2='1' then
				if acnt(2 downto 0)<="000" then
					if done='1' then	--Configuration secucess;
						st0<='0';
						st1<='0';
						st2<='0';
						st3<='1';
						st4<='0';
						en_cclk<='0';
					elsif acnt(21 downto 3)="111111111111111111" then
						st0<='0';
						st1<='0';
						st2<='0';
						st3<='0';
						st4<='1';		--Configuration failure
						en_cclk<='1';
					else
						dreg(8 downto 1)<=cdata(7 downto 0);
						dreg(0)<=dreg(1);
						st0<='0';
						st1<='0';
						st2<='1';
						st3<='0';
						st4<='0';
						en_cclk<='0';
					end if;
				else
					dreg(8 downto 0)<='0'&dreg(8 downto 1);
					st0<='0';
					st1<='0';
					st2<='1';
					st3<='0';
					st4<='0';
					en_cclk<='0';
				end if;
				acnt<=acnt+1;
			elsif st3='1' then
				if acnt(2 downto 0)="111" then
					st0<='0';
					st1<='0';
					st2<='0';
					st3<='0';
					st4<='1';
					en_cclk<='1';	--End
				else
					st0<='0';
					st1<='0';
					st2<='0';
					st3<='1';
					st4<='0';
					en_cclk<='0';	--Continue
				end if;
				acnt<=acnt + 1;
			elsif st4='1' then
				st0<='0';
				st1<='0';
				st2<='0';
				st3<='0';
				st4<='1';
				en_cclk<='1';
			end if;
		end if;
	end process;
	done_ok<=not done;
	din<=dreg(0);
	cclk<=clkin or en_cclk;
	pce<=en_cclk;
	poe<=en_cclk;
	caddr<=acnt(21 downto 3);
end behav;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -