📄 hostmot5-4e.vhd
字号:
----------------------------------------------------------------------------------- Copyright (C) 2005 Peter C. Wallace <pcw AT mesanet DOT com>---- $RCSfile: hostmot5-4e.vhd,v $-- $Author: petev $-- $Locker: $-- $Revision: 1.2 $-- $State: Exp $-- $Date: 2005/11/20 02:36:49 $------------------------------------------------------------------------------------- This program is free software; you can redistribute it and/or-- modify it under the terms of version 2.1 of the GNU General-- Public License as published by the Free Software Foundation.-- This library is distributed in the hope that it will be useful,-- but WITHOUT ANY WARRANTY; without even the implied warranty of-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-- GNU General Public License for more details.---- You should have received a copy of the GNU General Public-- License along with this library; if not, write to the Free Software-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA---- THE AUTHORS OF THIS LIBRARY ACCEPT ABSOLUTELY NO LIABILITY FOR-- ANY HARM OR LOSS RESULTING FROM ITS USE. IT IS _EXTREMELY_ UNWISE-- TO RELY ON SOFTWARE ALONE FOR SAFETY. Any machinery capable of-- harming persons must have provisions for completely removing power-- from all motors, etc, before persons enter any danger area. All-- machinery must be designed to comply with local and national safety-- codes, and the authors of this software can not, and do not, take-- any responsibility for such compliance.---- This code was written as part of the EMC HAL project. For more-- information, go to www.linuxcnc.org.---------------------------------------------------------------------------------library IEEE;use IEEE.std_logic_1164.all; -- defines std_logic types-- 4 axis version with 48 I/O bitsentity HostMot5_4 is port ( LRD: in STD_LOGIC; LWR: in STD_LOGIC; LW_R: in STD_LOGIC; ALE: in STD_LOGIC; ADS: in STD_LOGIC; BLAST: in STD_LOGIC; WAITO: in STD_LOGIC; LOCKO: in STD_LOGIC; CS0: in STD_LOGIC; CS1: in STD_LOGIC; READY: out STD_LOGIC; INT: out STD_LOGIC; LAD: inout STD_LOGIC_VECTOR (31 downto 0); -- data/address bus LA: in STD_LOGIC_VECTOR (8 downto 2); -- non-muxed address bus lBE: in STD_LOGIC_VECTOR (3 downto 0); -- byte enables SYNCLK: in STD_LOGIC; LCLK: in STD_LOGIC; -- I/O signals A: in STD_LOGIC_VECTOR (3 downto 0); B: in STD_LOGIC_VECTOR (3 downto 0); IDX: in STD_LOGIC_VECTOR (3 downto 0); PWM: inout STD_LOGIC_VECTOR (3 downto 0); ENA: out STD_LOGIC_VECTOR (3 downto 0); DIR: inout STD_LOGIC_VECTOR (3 downto 0); IOBITSA: inout STD_LOGIC_VECTOR (23 downto 0); IOBITSB: inout STD_LOGIC_VECTOR (23 downto 0); -- led bits LEDS: out STD_LOGIC_VECTOR(7 downto 0) );end HostMot5_4; -- for 5I20 or 4I65architecture dataflow of Hostmot5_4 is alias BLE: STD_LOGIC is LBE(0); -- 16 bit mode alias BHE: STD_LOGIC is LBE(3); -- 16 bit mode alias LA1: STD_LOGIC is LBE(1); -- 8/16 bit mode alias LA0: STD_LOGIC is LBE(0); -- 8 bit mode-- misc global signals -- signal D: STD_LOGIC_VECTOR (31 downto 0); -- internal data bus signal LatchedA: STD_LOGIC_VECTOR (15 downto 0); signal LatchedLBE: STD_LOGIC_VECTOR (3 downto 0); signal PreFastRead: STD_LOGIC; signal FastRead: STD_LOGIC; -- per channel I/O signals -- constant counters :integer := 4;-- misc global signals -- signal CardSelect: STD_LOGIC; -- card select decode signal LEDView: STD_LOGIC_VECTOR (7 downto 0); -- index register-- irq related signals signal IRQSource: STD_LOGIC; signal IRQLatch: STD_LOGIC; signal IRQMask: STD_LOGIC; signal MissedIRQ: STD_LOGIC; signal StopOnMissedIRQ: STD_LOGIC; signal ClearMissedIRQ: STD_LOGIC; signal LatchOnInterrupt: STD_LOGIC;-- timeout related signals signal ReloadWDCmd: STD_LOGIC; signal StopOnTimeout: STD_LOGIC; signal WDTimeOut: STD_LOGIC; -- LEDView reg signals signal LoadLEDViewCmd: STD_LOGIC; signal ReadLEDViewCmd: STD_LOGIC; signal Enasigs :STD_LOGIC_VECTOR (counters-1 downto 0);-- irqdiv reg signals signal ReadIRQDivCmd: STD_LOGIC; signal LoadIRQDivCmd: STD_LOGIC; signal ClearIRQCmd: STD_LOGIC;-- irq sel reg signals signal loadGCRCmd: STD_LOGIC; signal LoadGMRCmd: STD_LOGIC; signal ReadGMRCmd: STD_LOGIC;-- timeout reg signals signal loadTimeoutCmd: STD_LOGIC; signal ReadTimeoutCmd: STD_LOGIC; signal ReadTimerCmd: STD_LOGIC;-- phase accumulator signals signal ReadPhaseCmd: STD_LOGIC; signal LoadPhaseCmd: STD_LOGIC; -- counter signals -- signal CounterRead: STD_LOGIC_VECTOR (counters-1 downto 0); -- read counter signal GlobalCounterEnable: STD_LOGIC; -- enable counting signal GlobalCountLatchcmd: STD_LOGIC; -- command to latch counter value signal GlobalCountLatch: STD_LOGIC; -- command + irq generated latch count signal CountLatchEdge1: STD_LOGIC; signal CountLatchEdge2: STD_LOGIC; signal CCRLoadCmds: STD_LOGIC_VECTOR (counters-1 downto 0); -- counter control reg loads signal CCRReadCmds: STD_LOGIC_VECTOR (counters-1 downto 0); -- counter control reg reads signal GlobalCounterClear: STD_LOGIC; -- clear counter-- secondary counter signals -- signal SCounterRead: STD_LOGIC_VECTOR (counters-1 downto 0); -- read counter signal SCCRLoadCmds: STD_LOGIC_VECTOR (counters-1 downto 0); -- counter control reg loads signal SCCRReadCmds: STD_LOGIC_VECTOR (counters-1 downto 0); -- counter control reg reads-- pwm generator signals -- signal RefCountBus: STD_LOGIC_VECTOR (9 downto 0); signal LoadPWM: STD_LOGIC_VECTOR (counters-1 downto 0); signal ReadPWM: STD_LOGIC_VECTOR (counters-1 downto 0); signal PCRLoadCmds: STD_LOGIC_VECTOR (counters-1 downto 0); signal PCRReadCmds: STD_LOGIC_VECTOR (counters-1 downto 0); signal GlobalPWMEnable: STD_LOGIC; signal GlobalClearPWM: STD_LOGIC; signal GlobalClearPWMCmd: STD_LOGIC; signal StopPWM: STD_LOGIC;-- misc i/o signals signal PortASel: STD_LOGIC; signal DDRASel: STD_LOGIC; signal LoadPortA: STD_LOGIC; signal LoadDDRA: STD_LOGIC; signal ReadDDRA: STD_LOGIC; signal ReadPortA: STD_LOGIC; signal PortBSel: STD_LOGIC; signal DDRBSel: STD_LOGIC; signal LoadPortB: STD_LOGIC; signal LoadDDRB: STD_LOGIC; signal ReadDDRB: STD_LOGIC; signal ReadPortB: STD_LOGIC;-- decodes -- signal LEDViewSel: STD_LOGIC; signal IndexSel: STD_LOGIC; signal GCRSel: STD_LOGIC; signal GMRSel: STD_LOGIC; signal CCRSel: STD_LOGIC; signal SCCRSel: STD_LOGIC; signal PCRSel: STD_LOGIC; signal TimeOutSel: STD_LOGIC; signal TimerSel: STD_LOGIC; signal IRQDIVSel: STD_LOGIC; signal PWMValSel: STD_LOGIC; signal PhaseSel: STD_LOGIC; signal CounterSel: STD_LOGIC; signal SCounterSel: STD_LOGIC; function OneOfFourDecode(ena : std_logic; dec : std_logic_vector(1 downto 0)) return std_logic_vector is variable result : std_logic_vector(counters-1 downto 0); begin if ena = '1' then case dec is when "00" => result := "0001"; when "01" => result := "0010"; when "10" => result := "0100"; when "11" => result := "1000"; when others => result := "0000"; end case; else result := "0000"; end if; return result; end OneOfFourDecode; function OneOfFourMux(sel: std_logic_vector (1 downto 0); input: std_logic_vector(counters-1 downto 0)) return std_logic is variable result : std_logic; begin case sel is when "00" => result := input(0); when "01" => result := input(1); when "10" => result := input(2); when "11" => result := input(3); when others => result := '0'; end case; return result; end OneOfFourMux; component indexreg port ( clk: in STD_LOGIC; ibus: in STD_LOGIC_VECTOR (15 downto 0); obus: out STD_LOGIC_VECTOR (15 downto 0); loadindex: in STD_LOGIC; readindex: in STD_LOGIC; index: out STD_LOGIC_VECTOR (7 downto 0) ); end component; component counter port ( obus: out STD_LOGIC_VECTOR (31 downto 0); ibus: in STD_LOGIC_VECTOR (31 downto 0); quada: in STD_LOGIC; quadb: in STD_LOGIC; index: in STD_LOGIC; ccrloadcmd: in STD_LOGIC; ccrreadcmd: in STD_LOGIC; countoutreadcmd: in STD_LOGIC; countlatchcmd: in STD_LOGIC; countclearcmd: in STD_LOGIC; countenable: in STD_LOGIC; indexmask: in STD_LOGIC; nads: in STD_LOGIC; clk: in STD_LOGIC ); end component; component pwmgen port ( clk: in STD_LOGIC; refcount: in STD_LOGIC_VECTOR (9 downto 0); ibus: in STD_LOGIC_VECTOR (15 downto 0); obus: out STD_LOGIC_VECTOR (15 downto 0); loadpwmval: in STD_LOGIC; readpwmval: in STD_LOGIC; clearpwmval: in STD_LOGIC; pcrloadcmd: STD_LOGIC; pcrreadcmd: STD_LOGIC; pwmout: out STD_LOGIC; dirio: inout STD_LOGIC; enablein: in STD_LOGIC; enableout: out STD_LOGIC ); end component pwmgen; component pwmref is port ( clk: in STD_LOGIC; refcount: out STD_LOGIC_VECTOR (9 downto 0); irqgen: out STD_LOGIC; ibus: in STD_LOGIC_VECTOR (15 downto 0); obus: out STD_LOGIC_VECTOR (15 downto 0); irqdivload: in STD_LOGIC; irqdivread: in STD_LOGIC; phaseload: in STD_LOGIC; phaseread: in STD_LOGIC ); end component pwmref; component globalcontrolreg is port ( clk: in STD_LOGIC; ibus: in STD_LOGIC_VECTOR (15 downto 0); reset: in STD_LOGIC; loadgcr: in STD_LOGIC; ctrclear: out STD_LOGIC; ctrlatch: out STD_LOGIC; pwmclear: out STD_LOGIC; irqclear: out STD_LOGIC; reloadwd: out STD_LOGIC ); end component globalcontrolreg; component globalmodereg is port ( clk: in STD_LOGIC; ibus: in STD_LOGIC_VECTOR (15 downto 0); obus: out STD_LOGIC_VECTOR (15 downto 0); reset: in STD_LOGIC; loadglobalmode: in STD_LOGIC; readglobalmode: in STD_LOGIC; ctrena: out STD_LOGIC; pwmena: out STD_LOGIC; clearpwmena: in STD_LOGIC; loi: out STD_LOGIC; som: out STD_LOGIC; sot: out STD_LOGIC; miout: out STD_LOGIC; miin: in STD_LOGIC; irqmask: out STD_LOGIC; irqstatus: in STD_LOGIC ); end component globalmodereg; component WordPR24 is port ( clear: in STD_LOGIC; clk: in STD_LOGIC; ibus: in STD_LOGIC_VECTOR (23 downto 0); obus: out STD_LOGIC_VECTOR (23 downto 0); loadport: in STD_LOGIC; loadddr: in STD_LOGIC; readddr: in STD_LOGIC; portdata: out STD_LOGIC_VECTOR (23 downto 0) ); end component WordPR24; component Word24RB is Port ( obus: out STD_LOGIC_VECTOR (23 downto 0); readport: in STD_LOGIC; portdata: in STD_LOGIC_VECTOR (23 downto 0) ); end component Word24RB; component Timeout is Port ( clk : in std_logic; ibus : in std_logic_vector(15 downto 0); obus : out std_logic_vector(15 downto 0); timeoutload : in std_logic; timeoutread : in std_logic; timerread : in std_logic; reload : in std_logic; timerz : out std_logic); end component Timeout; begin makecounters: for i in 0 to (counters -1) generate counterx: counter port map ( obus => D, ibus => LAD, quada => A(i), quadb => B(i), index => Idx(i), ccrloadcmd => CCRLoadCmds(i), ccrreadcmd => CCRReadCmds(i), countoutreadcmd => CounterRead(i), countlatchcmd => GlobalCountLatch, countclearcmd => GlobalCounterClear, countenable => GlobalCounterEnable, indexmask => IOBITSB(i), nads => ADS, clk => LClk ); end generate; makescounters: for i in 0 to (counters -1) generate counterx: counter port map ( obus => D, ibus => LAD, quada => IOBITSA(i), quadb => IOBITSA(i+1), index => IOBITSA(i+2), ccrloadcmd => SCCRLoadCmds(i), ccrreadcmd => SCCRReadCmds(i), countoutreadcmd => SCounterRead(i), countlatchcmd => GlobalCountLatch, countclearcmd => GlobalCounterClear, countenable => GlobalCounterEnable, indexmask => IOBITSB(i+8), nads => ADS, clk => LClk ); end generate; makepwmgen: for i in 0 to (counters -1) generate pwmgenx: pwmgen port map ( clk => LClk, refcount => RefCountBus, ibus => LAD(15 downto 0), obus => D(15 downto 0), loadpwmval => LoadPWM(i), readpwmval => ReadPWM(i), clearpwmval => GlobalClearPWM, pcrloadcmd => PCRLoadCmds(i), pcrreadcmd => PCRReadCmds(i), pwmout => PWM(i), dirio => Dir(i), enablein => GlobalPWMEnable, enableout =>EnaSigs(i) ); end generate; oporta: WordPR24 port map ( clear => '0', clk => LClk, ibus => LAD(23 downto 0), obus => D(23 downto 0), loadport => LoadPortA, loadddr => LoadDDRA, readddr => ReadDDRA, portdata => IOBITSA ); iporta: Word24RB port map ( obus => D(23 downto 0), readport => ReadPortA, portdata => IOBITSA ); oportb: WordPR24 port map ( clear => '0', clk => LClk, ibus => LAD(23 downto 0), obus => D(23 downto 0), loadport => LoadPortB, loadddr => LoadDDRB, readddr => ReadDDRB, portdata => IOBITSB ); iportb: Word24RB port map ( obus => D(23 downto 0), readport => ReadPortB, portdata => IOBitsB ); pwmrefcount: pwmref port map ( clk => LClk, refcount => RefCountBus, irqgen => IRQSource, ibus => LAD(15 downto 0), obus => D(15 downto 0), irqdivload => LoadIRQDivCmd, irqdivread => ReadIRQDivCmd, phaseload => LoadPhaseCmd, phaseread => ReadPhaseCmd ); gLedreg: indexreg port map ( clk => LClk, ibus => LAD(15 downto 0), obus => D(15 downto 0), loadindex => LoadLEDViewCmd, readindex => ReadLEDViewCmd, index => LEDView ); ggcontrolreg: globalcontrolreg port map ( clk => LClk, ibus => LAD(15 downto 0),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -