欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

dsata.vhd

Vhdl cod for a bus.For sp2e
VHD
第 1 页 / 共 5 页
字号:
            rd4 := rd6;        END IF;                 RETURN rd4;    END new_rd;        PROCEDURE lsfr (SIGNAL state    : INOUT  std_logic_vector(15 DOWNTO 0);                    VARIABLE rnd_data : OUT    std_logic_vector(31 DOWNTO 0)) IS    VARIABLE new_bit   : std_logic;    VARIABLE lsfr_reg  : std_logic_vector(15 DOWNTO 0);     BEGIN           lsfr_reg := state;        FOR i IN 0 TO 31 LOOP            rnd_data(i) := lsfr_reg(15);              lsfr_reg := (lsfr_reg(15) XOR lsfr_reg(14))                         & lsfr_reg(13)                          & (lsfr_reg(15) XOR lsfr_reg(12))                         & lsfr_reg(11 DOWNTO 4)                          & (lsfr_reg(15) XOR lsfr_reg(3))                          & lsfr_reg(2 DOWNTO 0) & lsfr_reg(15);            END LOOP;                                     state <= lsfr_reg;    END lsfr;        PROCEDURE get_crc (VARIABLE crc_accum : INOUT std_logic_vector(31 DOWNTO 0);                       VARIABLE code      : IN std_logic_vector(31 DOWNTO 0)) IS    VARIABLE i           : INTEGER;    BEGIN              i := to_nat (crc_accum(31 DOWNTO 24) XOR code(31 DOWNTO 24));                crc_accum := (crc_accum(23 DOWNTO 0) & "00000000") XOR crc_table(i);        i := to_nat (crc_accum(31 DOWNTO 24) XOR code(23 DOWNTO 16));                crc_accum := (crc_accum(23 DOWNTO 0) & "00000000") XOR crc_table(i);        i := to_nat (crc_accum(31 DOWNTO 24) XOR code(15 DOWNTO 8));                crc_accum := (crc_accum(23 DOWNTO 0) & "00000000") XOR crc_table(i);        i := to_nat (crc_accum(31 DOWNTO 24) XOR code(7 DOWNTO 0));                crc_accum := (crc_accum(23 DOWNTO 0) & "00000000") XOR crc_table(i);    END get_crc;        -- PHYSICAL PLANT INTERFACE    SIGNAL DATAIN             : std_logic_vector(PHYDATAWIDTH-1 DOWNTO 0);    SIGNAL SLUMBER            : std_logic    := '0';    SIGNAL PARTIAL            : std_logic    := '0';    SIGNAL NEARAFELB          : std_logic    := '0';    SIGNAL FARAFELB           : std_logic    := '0';    SIGNAL SPDSEL             : std_logic    := '0';    SIGNAL SYSTEMCLOCK        : std_logic    := '1';      SIGNAL COMMA              : std_logic    := '0';      SIGNAL DATAOUT            : std_logic_vector(PHYDATAWIDTH-1 DOWNTO 0);    SIGNAL RXCLOCK            : std_logic    := '0';      SIGNAL COMRESET           : std_logic    := '0';      SIGNAL COMWAKE            : std_logic    := '0';         SIGNAL PHYRDY             : std_logic    := '0';    SIGNAL PHYRESET           : std_logic    := '1';            -- TRANSMITTER           SIGNAL TX_int             : std_logic := 'Z';         SIGNAL TX_shift_reg       : std_logic_vector(9 DOWNTO 0) := "0000000000";    SIGNAL TX_reg             : std_logic_vector(9 DOWNTO 0) := "0000000000";    SIGNAL TX_shift_rdy       : std_logic;    SIGNAL TX_shift_reg_empty : std_logic := '1';    SIGNAL TX_ld              : std_logic := '0';        -- RECEIVER                           SIGNAL RX_int             : std_logic := 'Z';    SIGNAL rx_idle            : std_logic := 'Z';     SIGNAL RX_data_rdy        : std_logic;        SIGNAL cominit_space_ok   : std_logic := '0';           SIGNAL comwake_space_ok   : std_logic := '0';    SIGNAL align              : std_logic := '0'; -- ALIGN pattern detected       SIGNAL align_ctrl         : std_logic := '0'; -- ALIGN pattern detected           -- RX clock generator    SIGNAL RXclk_timeout      : std_logic := '0';    SIGNAL RXclk              : std_logic := '0';     SIGNAL RXclk_edge         : std_logic := '0';    -- TX clock generator    SIGNAL TXclk              : std_logic := '1';     -- PHY control    SIGNAL init_state           : phy_init := DR_Reset;     SIGNAL resume               : std_logic := '0';    SIGNAL speed                : INTEGER := 1;            SIGNAL transmit_comwake     : std_logic := '0';    SIGNAL transmit_cominit     : std_logic := '0';      SIGNAL transmit_align       : std_logic := '0';        SIGNAL transmit_comwake_end : std_logic := '0';    SIGNAL transmit_cominit_end : std_logic := '0';      SIGNAL transmit_align_end   : std_logic := '0';    SIGNAL calibration_end      : std_logic := '0';      SIGNAL power_on             : std_logic := '1';       SIGNAL send_align_cnt       : INTEGER;    SIGNAL reset_align_cnt      : std_logic := '0';    SIGNAL transmit_link_data   : std_logic := '0';    -- LINK LAYER--    SIGNAL RX_rd              : std_logic := '0'; -- receiver running disparity, start with negative   --    SIGNAL TX_rd              : std_logic := '0'; -- transmitter running disparity, start with negative    -- Control     SIGNAL link_state, next_link_state : link_state_type;             -- primitives    SIGNAL CONTp                : std_logic := '0';    SIGNAL DMATp                : std_logic := '0';    SIGNAL EOFp                     : std_logic := '0';    SIGNAL HOLDp                : std_logic := '0';    SIGNAL HOLDAp                : std_logic := '0';    SIGNAL PMACKp                : std_logic := '0';    SIGNAL PMNAKp                : std_logic := '0';    SIGNAL PMREQ_Pp                : std_logic := '0';    SIGNAL PMREQ_Sp                : std_logic := '0';    SIGNAL R_ERRp                : std_logic := '0';    SIGNAL R_IPp                : std_logic := '0';    SIGNAL R_OKp                : std_logic := '0';    SIGNAL R_RDYp                : std_logic := '0';    SIGNAL SOFp                    : std_logic := '0';    SIGNAL SYNCp                : std_logic := '0';    SIGNAL WTRMp                : std_logic := '0';    SIGNAL X_RDYp                : std_logic := '0';    SIGNAL lsfr_state_scramble    : std_logic_vector(15 DOWNTO 0) := "1111111111111111";    SIGNAL lsfr_state_descramble  : std_logic_vector(15 DOWNTO 0) := "1111111111111111";    SIGNAL lsfr_state_cont        : std_logic_vector(15 DOWNTO 0) := "1111111111111111";            SIGNAL crc_check            : std_logic := '0';      SIGNAL link_data            : std_logic_vector(31 DOWNTO 0);     SIGNAL link_err             : std_logic_vector(3 DOWNTO 0);    SIGNAL link_ctrl            : std_logic_vector(3 DOWNTO 0);    SIGNAL link_crc             : std_logic_vector(31 DOWNTO 0);    SIGNAL link_FIS_data        : std_logic_vector(31 DOWNTO 0);     SIGNAL link_FIS_state       : std_logic_vector(1 DOWNTO 0);         SIGNAL rcv_fifo_read        : std_logic := '0';    SIGNAL rcv_fifo_write       : std_logic := '0';        SIGNAL tr_fifo_read        : std_logic := '0';    SIGNAL tr_fifo_write       : std_logic := '0';    SIGNAL RX_fifo_empty        : std_logic := '1';    SIGNAL RX_fifo_full         : std_logic := '0';        SIGNAL TX_fifo_empty        : std_logic := '1';    SIGNAL TX_fifo_full         : std_logic := '0';            SIGNAL RX_rd_ptr            : INTEGER := 0;    SIGNAL RX_wr_ptr            : INTEGER := 0;        SIGNAL TX_rd_ptr            : INTEGER := 0;    SIGNAL TX_wr_ptr            : INTEGER := 0;    SIGNAL RX_fifo              : rx_fifo_buffer_type;    SIGNAL TX_fifo              : tx_fifo_buffer_type;        -- TRANSPORT LAYER         SIGNAL TP_state             : TP_state_type;       SIGNAL next_TP_state        : TP_state_type;       SIGNAL TP_transmission_status   : std_logic := '0';    SIGNAL TP_Frame_Rdy         : std_logic := '0';    SIGNAL TP_no_data           : std_logic := '0';    SIGNAL TP_Fifo_Space_Avail  : std_logic := '1';    SIGNAL TP_result            : TP_result_type;        SIGNAL TP_dataout           : std_logic_vector(31 DOWNTO 0);    SIGNAL TP_datain            : std_logic_vector(37 DOWNTO 0);    SIGNAL TP_FIS_end           : std_logic := '0';    SIGNAL TP_FIS_OK            : std_logic := '0';    SIGNAL TP_RDH_req           : std_logic := '0';    SIGNAL TP_RDH_end           : std_logic := '0';    SIGNAL TP_PIOSetup_req      : std_logic := '0';    SIGNAL TP_PIOSetup_end      : std_logic := '0';    SIGNAL TP_TXData_req        : std_logic := '0';-- Register block    SHARED VARIABLE DataPortReg         : std_logic_vector(15 DOWNTO 0);    SHARED VARIABLE ErrorReg            : std_logic_vector(7 DOWNTO 0);    SHARED VARIABLE FeaturesReg            : std_logic_vector(15 DOWNTO 0);    SHARED VARIABLE SectorCountReg        : std_logic_vector(15 DOWNTO 0);    SHARED VARIABLE SectorNumberReg        : std_logic_vector(15 DOWNTO 0);    SHARED VARIABLE CylinderLowReg        : std_logic_vector(15 DOWNTO 0);    SHARED VARIABLE CylinderHighReg        : std_logic_vector(15 DOWNTO 0);    SHARED VARIABLE DeviceHeadReg        : std_logic_vector(7 DOWNTO 0);    SHARED VARIABLE StatusReg            : std_logic_vector(7 DOWNTO 0);    SHARED VARIABLE CommandReg            : std_logic_vector(7 DOWNTO 0);    SHARED VARIABLE AlternateStatusReg    : std_logic_vector(15 DOWNTO 0);    SHARED VARIABLE DeviceControlReg    : std_logic_vector(7 DOWNTO 0);    SIGNAL Ibit                   : std_logic := '0';    SIGNAL Cbit                   : std_logic := '0';        SIGNAL CMD_rcvd            : std_logic := '0';    BEGIN    CRC_INIT : PROCESS        VARIABLE crc_accum : std_logic_vector(31 DOWNTO 0);    BEGIN                FOR i IN 0 TO 255 LOOP            crc_accum := (others => '0');            crc_accum(31 DOWNTO 24) := to_slv(i,8);            FOR j IN 0 TO 7 LOOP                IF crc_accum(31) = '1' THEN                       crc_accum := crc_accum(30 DOWNTO 0) & '0';                    crc_accum := crc_accum XOR POLYNOMIAL;                ELSE                       crc_accum := crc_accum(30 DOWNTO 0) & '0';                                                    END IF;            END LOOP;             crc_table(i) <= crc_accum;        END LOOP;         WAIT;    END PROCESS CRC_INIT;        ----------------------------------------------------------------------------    ----------------------------------------------------------------------------    --                 PHYSICAL PLANT                                         --    ----------------------------------------------------------------------------    ----------------------------------------------------------------------------    ----------------------------------------------------------------------------    -- Hardware reset                                                         --    ----------------------------------------------------------------------------    PHYRESET <= RESET;    ----------------------------------------------------------------------------    -- Recived data                                                           --    ----------------------------------------------------------------------------           RX_int <= (RXp AND NOT RXn) AFTER 1 ps;    rx_idle <= NOT (RXp XOR RXn); -- line is idle if both lines have same value    ----------------------------------------------------------------------------    -- Clock extractor                                                        --    ----------------------------------------------------------------------------                       RX_CLK_timeout : PROCESS(RXclk, rx_idle)                         VARIABLE TmpPer         : Time := 0 ps;    BEGIN          IF (RXclk'EVENT AND (rx_idle = '0'))  THEN                  RXclk_timeout <= '0', '1' AFTER RXPERIOD/2;        END IF;                                    IF rising_edge(rx_idle) THEN--            RXclk_timeout <= '0', '1' AFTER RXPERIOD/2;            RXclk_timeout <= '0';        END IF;    END PROCESS RX_CLK_timeout;    RX_CLK : PROCESS(RX_int, RXclk_timeout, rx_idle)                         VARIABLE TmpPer         : Time := 0 ps;    VARIABLE Last_clk_edge  : Time := 0 ps;    BEGIN                       TmpPer := NOW - Last_clk_edge;                IF falling_edge(rx_idle) OR ((RX_int'EVENT AND TmpPer > RXPERIOD/4) AND (rx_idle = '0')) OR rising_edge(RXclk_timeout) THEN              RXclk <= not(RXclk);                  Last_clk_edge := NOW;                                 RXclk_edge <= '1', '0' AFTER 1 ps;        END IF;    END PROCESS RX_CLK;            ----------------------------------------------------------------------------    -- Space duration check                                                   --    ----------------------------------------------------------------------------                       SPACE_CHECK : PROCESS(rx_idle)                         VARIABLE burst_start         : Time := 0 ps;    VARIABLE space_start         : Time := 0 ps;    VARIABLE tmp_time            : Time := 0 ps;    BEGIN                 IF falling_edge(rx_idle) THEN            burst_start := NOW;            tmp_time := NOW - space_start;            IF (tmp_time > MIN_COMINIT_SPACE) AND (tmp_time < MAX_COMINIT_SPACE) THEN                cominit_space_ok <= '1';            END IF;

⌨️ 快捷键说明

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