--------------------------------------------------------------------- -- Mobile User Frame Builder -- Author : Ai Hua -- Date : March 30, 2001 -- Filename : musr_frame_builder.vhd -- Architecture : Behavioral -- Description : This entity is to build all kinds of frame, and -- maintain the communication channel. It's -- controlled by clock master. -- Total logic cells used: 25/1152 (2%) ---------------------------------------------------------- -- State machine: (drawed by hand, omitted here) -- In request state. -- usr_frame_builder build the request frame in the form of below -- and send it, if no ACK is recieved, then ... ( maybe retry, -- maybe give a "failed" signal to user by lighten a LED. we -- can decide it later ). -- ------------------------------------------------------------- -- |DL header| User 1 segment | User 2 segment | -- ------------------------------------------------------------- -- | 4bits | 1bit | 3bits | 1bit | 3bits | -- ------------------------------------------------------------- -- | Req. | void | void | -- ------------------------------------------------------------- -- Req. = 0011 -- In communication state -- usr_frame_builder recieve user data from upstream modules, -- as well user_online information, build a frame in the form -- of below: -- ------------------------------------------------------------- -- |DL header| User 1 segment | User 2 segment | -- ------------------------------------------------------------- -- | 4bits | 1bit | 3bits | 1bit | 3bits | -- ------------------------------------------------------------- -- | Send | On/Off | user1 data | on/off | user2 data | -- ------------------------------------------------------------- -- Send = 1010 -- if both of two users close their mobile phone (usr1_en & -- usr2_en = '0'), build a close frame to close the communication -- channel between user board and the base station board. -- the close frame is in the form of below: -- ------------------------------------------------------------- -- |DL header| User 1 segment | User 2 segment | -- ------------------------------------------------------------- -- | 4bits | 1bit | 3bits | 1bit | 3bits | -- ------------------------------------------------------------- -- | close | void | void | -- ------------------------------------------------------------- -- close = 0111 !!!!!******** -- The frame_analyzer in base station board have a counter to -- caculate how long the channel kept silent, when the limits -- is reached, base station will close the channel. --------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; library work; use work.CDMA_pkg.all; entity musr_frame_builder is generic ( datawidth : positive := 3; frame_length : positive := 12 ); port ( resetn, clock, clk_en : in std_logic; maintain_cycle : out std_logic; channel_closed : out std_logic; usr1_en, usr2_en : in std_logic; ACK_back : in std_logic; usr1_online, usr2_online : in std_logic; usr1_data, usr2_data : in std_logic_vector(datawidth-1 downto 0); frame_out : out std_logic_vector(frame_length-1 downto 0) ); end entity musr_frame_builder; architecture behavioral of musr_frame_builder is signal channel_needed : std_logic; signal channel_built : std_logic; signal type_of_frame : std_logic_vector(3 downto 0); signal tmp_frame_out : std_logic_vector(frame_length-1 downto 0); TYPE communication_state IS (closed, build_channel, communication); SIGNAL comm_state : communication_state; TYPE ACK_response_state IS (waiting , not_recieved, recieved); SIGNAL ACK_state : ACK_response_state; signal temp_value : std_logic; TYPE channel_needed_state IS (stable, transitted); SIGNAL channel_needed_transitted : channel_needed_state; begin channel_needed <= usr1_en or usr2_en; To_build_frames : PROCESS (clock) BEGIN wait until clock'EVENT AND clock = '1'; IF resetn = '0' THEN comm_state <= closed; else CASE comm_state IS WHEN closed => -- if usr need channel again, then go to build. IF channel_needed = '1' THEN comm_state <= build_channel; else comm_state <= closed; END IF; WHEN build_channel => -- if channel is already built, then go to communication state. IF channel_built = '1' THEN comm_state <= communication; else comm_state <= build_channel; END IF; WHEN communication => -- if channel is not needed any more, then go to close state. IF channel_needed = '0' THEN comm_state <= closed; else comm_state <= communication; END IF; END CASE; END IF; END PROCESS To_build_frames; with comm_state select type_of_frame <= "0111" when closed, "0011" when build_channel, "1010" when communication, "0000" when others; with comm_state select channel_closed <= '1' when closed, '1' when build_channel, '0' when communication, '1' when others; tmp_frame_out <= type_of_frame & usr1_online & usr1_data & usr2_online & usr2_data; Check_ACK_response : process (clock) begin wait until clock'event and clock = '1'; if resetn = '0' then ACK_state <= waiting; else case ACK_state is when waiting => if ACK_back = '0' then ACK_state <= not_recieved; else ACK_state <= waiting; end if; when not_recieved => channel_built <= '0'; if comm_state = build_channel then if ACK_back = '1' then ACK_state <= recieved; else ACK_state <= not_recieved; end if; else if ACK_back = '1' then ACK_state <= waiting; else ACK_state <= not_recieved; end if; end if; when recieved => channel_built <= '1'; ACK_state <= waiting; when others => ACK_state <= waiting; end case; end if; end process Check_ACK_response; Trigger_maintain_cycle : process (clock) begin wait until clock'event and clock ='1'; if resetn = '0' then channel_needed_transitted <= stable; else temp_value <= channel_needed; if temp_value = channel_needed then channel_needed_transitted <= stable; else channel_needed_transitted <= transitted; end if; end if; end process Trigger_maintain_cycle; with channel_needed_transitted select maintain_cycle <= '1' when transitted, '0' when stable, '0' when others; To_send_frame : myflipflops generic map (datawidth => frame_length) port map ( clk => clock, enable => clk_en, -- active high clearn => resetn, -- active high resetn d => tmp_frame_out, q => frame_out ); end behavioral;