Untitled
unknown
plain_text
7 months ago
4.4 kB
6
Indexable
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.common_pack.all;
entity cmdProc is
port (
clk: in std_logic;
reset: in std_logic;
rxnow: in std_logic;
rxData: in std_logic_vector (7 downto 0);
txData: out std_logic_vector (7 downto 0);
rxdone: out std_logic;
ovErr: in std_logic;
framErr: in std_logic;
txnow: out std_logic;
txdone: in std_logic;
start: out std_logic;
numWords_bcd: out BCD_ARRAY_TYPE(2 downto 0);
byte_hex_list: inout CHAR_ARRAY_TYPE(13 downto 0);
dataReady: in std_logic;
byte: in std_logic_vector(7 downto 0);
maxIndex: in BCD_ARRAY_TYPE(2 downto 0);
dataResults: in CHAR_ARRAY_TYPE(0 to RESULT_BYTE_NUM-1);
seqDone: in std_logic );
END cmdProc;
ARCHITECTURE arch OF cmdProc IS
type state_type is (IDLE, SEND, cmdA_proc, cmdP_proc, cmdL_proc, startProcess);
signal curState, nextState: state_type;
SIGNAL numWords_reg: BCD_ARRAY_TYPE(2 downto 0) := (OTHERS => (OTHERS => '0'));
SIGNAL rxData_reg: std_logic_vector (7 downto 0);
SIGNAL counter: integer range 0 to 3 := 0;
SIGNAL counter1: integer range 0 to 2 := 0;
begin
process (clk, reset)
begin
if reset = '1' then
curState <= IDLE;
else
curState <= nextState;
end if;
END process;
process (IDLE, seqDone, dataReady, txdone)
WHEN IDLE =>
if (rxNow = '1' and txdone = '1') then
rxData_reg <= rxData;
txData <= rxData_reg;
rxdone <= '1';
if rxData_reg = "01100001" or rxData_reg = "01000001" then -- CMD ANNN or aNNN
curState <= cmdA_proc;
else if (seqDone = '1') and (rxData_reg = "01010000" or rxData_reg = "01110000") then -- CMD P or p
curState <= cmdP_proc;
else if (seqDone = '1') and (rxData_reg = "01001100" or rxData_reg = "01101100") then -- CMD L or l
curState <= cmdL_proc;
else
curState <= IDLE;
end if;
WHEN cmdA_proc =>
if counter = 3 then
start <= '1';
curState <= startProcess;
else if rxNow = '1' and txdone = '1' then
rxData_reg <= rxData;
txData <= rxData_reg;
rxdone <= '1';
if rxData_reg(7 downto 4) = "0011" then
numWords_reg(counter) <= rxData_reg(3 downto 0);
counter <= counter + 1;
curState <= cmdA_proc;
else if
curSate <= IDLE; -- Invalid start command, the first N is not a decimal from 0-9
else
curState <= cmdA_proc
END if;
WHEN startProcess =>
if (dataReady = '1' and txDone = '1' and seqDone = '0') then
if counter = 2 then
txData <= "00100000";
txNow;
counter <= 0;
else
txData <= byte;
txNow <= '1';
counter <= counter + 1;
end if;
if seqDone = '1' then
curState <= IDLE;
else
curState <= startProcess;
END if;
WHEN cmdP_proc
WHEN cmdL_proc
WHEN OTHERS =>
curState <= IDLE;
END arch;
seq_process: PROCESS(clk)
BEGIN
IF rising_edge(clk) THEN
IF reset = '1' THEN
current_state <= IDLE;
ELSE
curState <= nextState;
END IF;
END IF;
END PROCESS;
BEGIN
-- Default values to prevent latches
next_state <= current_state;
txData <= (others => '0');
txnow <= '0';
rx_acknowledge <= '0';
start_pulse <= '0';
echo_data <= rxData;
process (rxNow, txDone ... etc)
begin
next_state <= current_state;
txData <= (others => '0');
txnow <= '0';
rx_acknowledge <= '0';
start_pulse <= '0';
echo_data <= rxData;
WHEN curState =>
IDLE
nextState <= print
WHEN print
ETC
Editor is loading...
Leave a Comment