⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main_ctrl_state_machine.vhd

📁 MP3 for XPLA3 XILINX.CPLD,必须在XILINX的FPGA芯片下使用,因为IP核是xilinx
💻 VHD
字号:
-- **************************************************************
-- File:  		main_ctrl_state_machine.vhd
--
-- Purpose: 	This file implements the MP3 Main Control State 
--			machine. Based on either a powerdown, the download signal or the 
--			current user interface command, this state machine controls
--			the function of the MP3 Portable Player.
--			The user interface controls are input to this state machine
--			on the PLAY_ST bus which is decoded as follows:
--
--			PLAY_ST		Command
--			-------		-------
--			000			Play
--			001			Pause
--			010			Stop
--			011			Fast Forward
--			100			Rewind
--
--			Download operations take priority over all other functions unless 
--			the power management circuit indicates that a power-down is in order.
--
-- Created:		10/18/99	ALS
--
-- Revised:		11-5-99	ALS
-- Revised:		11-8-99 	ALS
-- Revised:		11-9-99 	ALS
-- Revised:		11-14-99 ALS
-- Revised:		2-22-00 ALS
-- Revised:		2-29-00 ALS
-- **************************************************************

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;

entity main_ctrl_state_machine is
  
  port(
	-- Parallel Port Interface Signals
	downld_mode	: in		std_logic;	-- indicates a download operation is occurring

	-- MPEG Chip Control Interface Signals
	cmd 		: out 	std_logic_vector(1 downto 0); -- encoded command
	cmd_dat	: out		std_logic;	-- command mode (low-pwr,norm)
	mpeg_done	: in		std_logic;	-- I2C command completion
	err		: in		std_logic;  -- I2C or other error
	mas_rst	: out		std_logic;	-- MAS3507D active low reset


	-- User Interface/Display Signals
	play_st	: in		std_logic_vector(2 downto 0); -- encoded play status
	vol_adj	: in		std_logic;	-- indicates that user just adjusted volume
	mute_chg	: in		std_logic;	-- indicates the mute status has changed
	display_err	: inout	std_logic;	-- instructs display to display ERR
	upd_track	: out		std_logic; 	-- instructs display to update track number

	-- Flash Control Logic/Play Logic Interface Signals
	flash_done	: in		std_logic;	-- indicates that the flash operation is completed
	rew		: out		std_logic;	-- signals flash to perform rewind operation
	fwd		: out		std_logic;	-- signals flash to perform fast forward operation
	stop		: out		std_logic;	-- signals flash and play logic to stop
	play		: inout	std_logic;	-- signals flash and play logic to play
	wakeup	: out		std_logic;	-- signals the flash to wakeup
	
      clock		: in		std_logic;	-- 2 MHz system clock
	reset 	: in 		std_logic	-- system reset
);

end main_ctrl_state_machine;

library IEEE;
use IEEE.std_logic_1164.all;

architecture behave of main_ctrl_state_machine is

-- ******************** CONSTANT DECLARATIONS ***********************

-- DAC3550A Register Data Words
constant DO_NOTHING	:	std_logic_vector(1 downto 0) := "00";	-- CMD bus value for do nothing
constant WR_SRREG		:	std_logic_vector(1 downto 0) := "01";	-- CMD bus value for write SR_REG
constant WR_AVOLREG	:	std_logic_vector(1 downto 0) := "10";	-- CMD bus value for write AVOL
constant WR_GCFGREG	:	std_logic_vector(1 downto 0) := "11";	-- CMD bus value for write GCFG

-- PLAY_ST decode
constant PLAY_CODE	:	std_logic_vector(2 downto 0) := "000"; -- play_st code for play
constant RWD_CODE		: 	std_logic_vector(2 downto 0) := "001"; -- play_st code for pause
constant STOP_CODE	:	std_logic_vector(2 downto 0) := "010"; -- play_st code for stop
constant FWD_CODE		: 	std_logic_vector(2 downto 0) := "011"; -- play_st code for fast forward

-- Reset Value
constant RESET_ACTIVE	: 	std_logic := '1';

-- ********************* SIGNAL DECLARATIONS ************************

type state_type is (RESET_ST, INIT_MPEG, LOW_PWR, IDLE, DOWNLD, ENABLE_MPEG, ENABLE_PLAY,
			  DISABLE_MPEG, FLASH_CTRL, WAIT_TRACK, UPDATE_TRACK, ERR_ST, SOUND_ADJ);
signal state, next_state : state_type;

signal play_com		:	std_logic;	-- combinatorial play signal
signal mas_rst_com	:	std_logic;	-- combinatorial mas_rst signal

begin

-- display error is asserted when any error is asserted
-- this will cause the state machine to go to the error state and stay there
-- until a reset or pwrdwn occurs
display_err <= err;

-- ************************  Main Control State Machine Processes ************************
-- This process contains the combinatorial portion of the state machine
-- This state machine monitors the PWRDWN and DOWNLD_MODE signals and
-- decodes the PLAY_ST bus to determine the correct operation

main_ctrl_comb: process (state, play_st, vol_adj, mute_chg, downld_mode,
				 display_err, mpeg_done, play, 
				 flash_done)

begin

-- state machine defaults
	play_com <= '0';
	stop <= '0';
	rew <= '0';
	fwd <= '0';
	wakeup <= '0';
	cmd <= DO_NOTHING;
	cmd_dat <= '0';
	mas_rst_com <= '1'; -- active low reset to MAS chip
	upd_track <= '0';
	
	next_state <= state;

		case state is 
			--******************** RESET_ST State **************
			when RESET_ST =>
				-- reset state
				-- leave this state when reset is negated
				-- assert reset to MAS chip
				mas_rst_com <= '0';
				next_state <= INIT_MPEG;

			--******************** INIT_MPEG State ***************
			when INIT_MPEG =>
				-- this state initializes the DAC3550A chip data format
				-- stay in this state until command is done
				cmd <= WR_SRREG;
				if display_err = '1' then
					next_state <= DISABLE_MPEG;
				elsif mpeg_done = '1' then
					next_state <= LOW_PWR;
				end if;

			--******************** LOW_PWR State ******************
			when LOW_PWR =>
				-- this state puts the DAC3550A in low-power mode
				-- stay in this state until command is done
				cmd <= WR_GCFGREG;
				cmd_dat <= '1'; -- set low-power bit
				if display_err = '1' then
					next_state <= DISABLE_MPEG;
				elsif mpeg_done = '1' then
					next_state <= IDLE;
				end if;				
		
			--******************** IDLE State ******************
			when IDLE =>
				-- play signal and MAS3507D enable maintain previous values
				play_com <= play;

				-- Power-down takes precedence over all other actions
				-- followed by download
				-- any error causes state machine to go to error state
				if display_err = '1' then
					next_state <= DISABLE_MPEG;
				elsif downld_mode = '1' then
					next_state <= DOWNLD;
				elsif play_st = PLAY_CODE and play = '0' then
					next_state <= ENABLE_MPEG;
				elsif play_st = FWD_CODE or
					play_st = RWD_CODE or
					play_st = STOP_CODE then
					next_state <= DISABLE_MPEG;
				elsif vol_adj = '1' or mute_chg = '1' then
					next_state <= SOUND_ADJ;
				end if;

			--******************** DOWNLD State ******************
			when DOWNLD =>
				-- this state is entered when DOWNLD_MODE asserts
				-- wait in this state until DISPLAY_ERR asserts or 
				-- DOWNLD_MODE negates
				if display_err = '1'  then
					next_state <= DISABLE_MPEG;
				elsif downld_mode = '0' then
					next_state <= IDLE;
				end if; 


			--******************** ENABLE_MPEG State ******************
			when ENABLE_MPEG =>
				-- this state is entered if PLAY_ST = PLAY_CODE
				-- the DAC3550A must be taken out of power-down mode and
				-- the MAS3507D is enabled
				cmd <= WR_GCFGREG;
				cmd_dat <= '0'; -- put DAC3550A in normal mode
				wakeup <= '1';  -- wakeup the flash

				if display_err = '1'  then
					next_state <= DISABLE_MPEG;
				elsif mpeg_done = '1'  then
					next_state <= ENABLE_PLAY;
				end if;

				
			--******************** ENABLE_PLAY State ******************
			when ENABLE_PLAY =>
				-- this state is entered after MPEG chips have been enabled
				-- for play operation
				play_com <= '1';
				
				-- next state is always IDLE
				next_state <= IDLE;
				
			--******************** DISABLE_MPEG State ******************
			when DISABLE_MPEG =>
				-- this state is entered when 
				-- the user interface issues a command (STOP, PAUSE, RWD, FWD)
				-- where the play operation has to stop (PLAY_ST = STOP_CODE or
				-- PAUSE_CODE or RWD_CODE or FWD_CODE)
				
				-- put DAC3550A in low-power mode 
				cmd <= WR_GCFGREG;
				cmd_dat <= '1'; -- set low-power bit
				
				-- reset the mas chip
				mas_rst_com <= '0';

				if display_err = '1' then
					next_state <= ERR_ST;
				elsif mpeg_done = '1' then
					next_state <= FLASH_CTRL;
				end if;

			--******************** ERR_ST State ****************
			when ERR_ST =>
				-- this state is entered when there is an error
				-- the state machine stays in this state 
							
			--******************** FLASH_CTRL State ***************
			when FLASH_CTRL =>
				-- this state is entered when the play_st bus indicates
				-- a STOP, REWIND, or FAST FORWARD operation
				-- this state sets the control signal for the FLASH and
				-- waits until the flash is done with the operation
				case play_st is
					when STOP_CODE =>
						stop <= '1';
					when RWD_CODE =>
						rew <= '1';
					when FWD_CODE =>
						fwd <= '1';
					when others =>
				end case;

				if display_err = '1'  then
					next_state <= ERR_ST;
				elsif flash_done = '1' then
					-- wait for track number to be updated, then
					-- go to state that instructs display to update
					next_state <= WAIT_TRACK;
				end if;

			--******************** WAIT_TRACK 	******************
			when WAIT_TRACK =>
				-- this track waits for the track number to be updated
				-- and then moves to the UPDATE_TRACK state to send
				-- a signal to update the display.
				-- this state is entered from the FLASH_CNTRL
				-- states
				next_state <= UPDATE_TRACK;

			--********************* UPDATE_TRACK *********************
			when UPDATE_TRACK =>
				-- this state asserts the signal to update the track number
				-- on the display
				upd_track <= '1';
				next_state <= IDLE;
			
			--******************** SOUND_ADJ State *****************
			when SOUND_ADJ => 
				-- this state is entered when the user operation is 
				-- a volume adjustment or a mute
				-- these operations do not interrupt the play operation
				-- keep the play and MAS3507D signals at their current state
				play_com <= play;

				-- set the command to the MPEG Chip Control logic to write 
				-- the volume register
				cmd <= WR_AVOLREG;

				-- wait for MPEG_DONE to return to IDLE state if not powerdown
				-- or no errors
				if display_err = '1' then
					next_state <= DISABLE_MPEG;
				elsif mpeg_done = '1' then
					next_state <= IDLE;
				end if;
				 
			--******************* DEFAULT *****************************
			when others =>
					next_state <= IDLE;
	
		end case;
end process;

main_ctrl_state_machine_regs: process (clock, reset)
begin
	if reset = RESET_ACTIVE then
		state <= RESET_ST;
		play <= '0';
		mas_rst <= '0';
	elsif clock'event and clock='1' then
		state <= next_state;
		play <= play_com;
		mas_rst <= mas_rst_com;
	end if;
end process;

end behave;

⌨️ 快捷键说明

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