首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

新手,高手帮我看看这个子程序。

新手,高手帮我看看这个子程序。

这是个状态机的子程序,不知道它实现了什么功能,请帮我看看,要是能画出状态转换图,那就太感谢了。 process (clk, rst) -- huge state machine begin if rst = '1' then state <= 255 ; lxclkout_d <= '1' ; lxdir <= '0' ; lxdir_int <= '0' ; shift_tx <= '0' ; gcnt <= "0000" ; tx_ack_bad <= '0' ; rxtoen <= '0' ; enablewr <= '0' ; disablewr <= '0' ; mux <= '0' ; pcount <= "000000" ; elsif clk'event and clk = '1' then lxdir <= lxdir_int ; gcnt <= gcnt + 1 ; case state is when 255 => lxdir_int <= '0' ; lxclkout_d <= not rxbp ; pcount <= "000000" ; gcnt <= "0000" ; shift_tx <= '0' ; -- reset state if lxclkintp = '0' and rxbp = '0' then -- goto receiver stuff state <= 100 ; enablewr <= '1' ; elsif txreq = '1' then state <= 2 ; -- goto transmitter stuff else state <= 255 ; end if ; -- else hang around here when 2 => if lxclkintp = '0' then state <= 2 ; lxclkout_d <= '1' ; -- tx requested, wait for lxclkin high elsif gcnt < "1011" then state <= 2 ; lxclkout_d <= '0' ; -- hold lxclkout low for 6 cycles else state <= 3 ; shift_tx <= '1' ; end if ; when 3 => state <= 13 ; lxclkout_d <= '0' ; shift_tx <= '1' ; lxdir_int <= '1' ; gcnt <= "0000" ; when 13 => if gcnt = "0111" then state <= 13 ; tx_ack_bad <= lxclkintp ; if psize = '0' then pcount <= pcount + 1 ; end if ; lxclkout_d <= not gcnt(0) ; shift_tx <= '1' ; elsif gcnt < "1101" then state <= 13 ; lxclkout_d <= not gcnt(0) ; shift_tx <= '1' ; elsif verein = '1' and gcnt = "1101" then state <= 13 ; lxclkout_d <= not gcnt(0) ; shift_tx <= '1' ; elsif verein = '1' and gcnt = "1110" then state <= 13 ; lxclkout_d <= not gcnt(0) ; shift_tx <= '0' ; elsif verein = '0' and gcnt = "1101" then state <= 32 ; lxclkout_d <= not gcnt(0) ; shift_tx <= '1' ; else state <= 32 ; lxclkout_d <= not gcnt(0) ; shift_tx <= '0' ; mux <= '1' ; end if ; when 32 => lxclkout_d <= '1' ; mux <= '0' ; if lxclkintp = '0' then state <= 34 ; shift_tx <= '0' ; -- wait for receiver ready elsif txreq = '1' and psize = '1' then state <= 33 ; shift_tx <= '1' ; elsif txreq = '1' and psize = '0' and pcount > "000000" then state <= 33 ; shift_tx <= '1' ; else state <= 33 ; shift_tx <= '0' ; end if ; when 33 => gcnt <= "0000" ; lxclkout_d <= '0' ; if txreqd = '1' and psize = '1' then state <= 13 ; shift_tx <= '1' ; -- transmit next word elsif txreqd = '1' and psize = '0' and pcount > "000000" then state <= 13 ; shift_tx <= '1' ; -- transmit next word else state <= 45 ; shift_tx <= '0' ; end if ; when 34 => gcnt <= "0000" ; lxclkout_d <= '0' ; if lxclkintp = '0' then state <= 34 ; else state <= 3 ; shift_tx <= '1' ; end if ; when 45 => lxclkout_d <= '1' ; state <= 46 ; lxdir_int <= '0' ; gcnt <= "0000" ; -- no tx request, try to pass token when 46 => if gcnt < "1000" then state <= 46 ; elsif gcnt = "1000" and txreq = '1' -- tx req arrived, service it and (psize = '1' or (psize = '0' and pcount > "000000")) then state <= 47 ; lxclkout_d <= '0' ; gcnt <= "0000" ; elsif gcnt = "1100" then state <= 255 ; enablewr <= '0' ; elsif lxclkintp = '0' then -- request from other end state <= 100 ; enablewr <= '1' ; else state <= 46 ; end if ; when 47 => if gcnt < "0011" then state <= 47 ; elsif lxclkintp = '0' then state <= 47 ; else state <= 3 ; lxclkout_d <= '0' ; shift_tx <= '1' ; -- tx req, regret token end if ; when 100 => gcnt <= "0000" ; pcount <= "000000" ; if localenablewr_rt = '1' then state <= 101 ; lxclkout_d <= '0' ; rxtoen <= '1' ; else state <= 100 ; end if ; when 101 => lxclkout_d <= '0' ; if gcnt = "0010" then state <= 105 ; enablewr <= '0' ; else state <= 101 ; end if ; when 105 => if ackflag_rt = '1' and rxbp = '1' then state <= 106 ; lxclkout_d <= '0' ; elsif lxcounthflag = '1' then state <= 200 ; disablewr <= '1' ; elsif localenablewr_rt = '1' then -- state <= 105 ; lxclkout_d <= not(rxbp or ackflag_rt) ; state <= 105 ; lxclkout_d <= '1' ; --not ackflag_rt ; else state <= 255 ; end if ; when 106 => if lxcounthflag = '1' then state <= 200 ; disablewr <= '1' ; elsif rxbp = '1' then state <= 106 ; lxclkout_d <= '0' ; else state <= 105 ; lxclkout_d <= '1' ; end if ; when 200 => gcnt <= "0000" ; disablewr <= '0' ; rxtoen <= '0' ; if txreq = '0' and lxclkintp = '1' then state <= 255 ; -- no txreq elsif txreq = '0' and lxclkintp = '0' then state <= 100 ; enablewr <= '1' ; -- then go and receive else lxclkout_d <= '0' ; state <= 201 ; -- potential token pass end if ; when 201 => if lxclkintp = '0' then state <= 100 ; lxclkout_d <= '1' ; enablewr <= '1' ; -- regret from other end elsif gcnt < "0110" then state <= 201 ; -- wait else state <= 3 ; shift_tx <= '1' ; -- OK, become transmitter end if ; when others => state <= 255 ; end case ; end if ; end process ;
迷途小书童
返回列表